Hyperledger Composer 는 만 든 사용자 에 게 새로운 신분 을 발급 하고 지갑 에 새 신분 을 가 져 옵 니 다.
3095 단어 블록 체인
1. NodeJs 를 통 해 만 든 사용자 에 게 새로운 신분 을 발급 하고 지갑 (Wallet) 에 새 신분 을 가 져 옵 니 다. 구체 적 인 코드 는 다음 과 같 습 니 다.
우선 package. json 에 아래 의존 파일 을 추가 합 니 다:
"dependencies": {
........
"composer-common": "latest",
"composer-client": "latest",
"composer-admin": "latest",
"composer-cli": "latest",
"composer-rest-server": "latest",
........
}
npm install 을 실행 하고 의존 파일 을 다운로드 하여 nodemodules 폴 더.
register. js 파일 을 새로 만 들 고 아래 코드 를 붙 여 넣 고 빨간색 글꼴 을 수정 합 니 다.
둘째, coposer 명령 을 통 해 만 든 사용자 에 게 새로운 신분 을 발급 하고 지갑 (Wallet) 을 가 져 옵 니 다. 구체 적 인 코드 는 다음 과 같 습 니 다.
const BusinessNetworkConnection = require('composer-client').BusinessNetworkConnection;
const IdCard = require('composer-common').IdCard;
const AdminConnection = require('composer-admin').AdminConnection;
//const CardExport = require('composer-cli').Card.Export;
//const ParticipantAdd = require('composer-cli').Participant.Add;
class Sample {
// Initialize
init() {
let businessNetworkConnection = new BusinessNetworkConnection();
const adminConnection = new AdminConnection();
var cardName;
// +User( user, )
const participant = namespace + '#' + User;
//CardId( Card userID, )
const userID = CardId;
return businessNetworkConnection.connect(businessNetwork)
.then(() => {
return businessNetworkConnection.issueIdentity(participant, userID)
})
.then((identity) => {
// Create and import card
const metadata = {
userName: identity.userID,
version: 1,
enrollmentSecret: identity.userSecret,
businessNetwork: businessNetwork
};
cardName = metadata.userName + "@" + metadata.businessNetwork
//connection.json
const connectionProfile = {......};
//const connectionProfile = require('./local_connection.json').
//const card = new IdCard(metadata, connectionProfile);
const card = new IdCard(metadata, connectionProfile);
return adminConnection.importCard(cardName, card)
})
.then((result) => {
console.log("Import Card Successed !");
}).catch((error) => {
console.error(error);
});
}
}
var sam = new Sample();
sam.init();
1, 생 성 된 사용자 에 게 새로운 신분 발급
그 중:
ID_CARD_FILE - ID 카드 를 저장 하 는 파일 이름 입 니 다.
IDENTITY - 발급 할 신분 입 니 다.
PARTICIPANT_CLASS - 참여 자 클래스 입 니 다.
PARTICIPANT_ID - 등록 표 에서 실례 화 된 참여 자의 ID 입 니 다.
2, 새 신분 지갑 가 져 오기 (Wallet)
composer card import --file XXXXXXXX.card
발 급 된 카드 를 보 려 면 coposer card list 명령 을 실행 할 수 있 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
자바 오프라인 비트 코 인 주소 생 성만약 에 자신의 데스크 톱 자바 애플 리 케 이 션 이나 핸드폰 안 드 로 이 드 애플 리 케 이 션 에 비트 코 인 결제 지원 을 통합 하고 싶다 면 오프라인 으로 비트 코 인 비밀 키 와 주 소 를 생 성 하고 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.