Hyperledger Composer 는 만 든 사용자 에 게 새로운 신분 을 발급 하고 지갑 에 새 신분 을 가 져 옵 니 다.

3095 단어 블록 체인
만 든 사용자 에 게 새로운 신분 을 발급 하고 지갑 (Wallet) 을 가 져 오 는 두 가지 방법 을 소개 합 니 다.
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 명령 을 실행 할 수 있 습 니 다.

좋은 웹페이지 즐겨찾기