-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Client側で秘密鍵&公開鍵を作成してtransaction実行させてみる #9
Comments
Building your first network.手順genesis block作成
network起動
network確認
備考cryptogen tool not found. exitingHow do I resolve the error on hyperledger fabric?
で cryptogen をインストール Failed to reach implicit threshold of 1 sub-policies, required 1 remaining: permission denied以下でnetworkを削除してから
再度
|
How to sign a transaction by an identity's private key以下手順のtestソース 1. unsigned transaction proposalを作成。この PEM encoded certificate content は、pemファイルの文字列をそのまま入れればOK? const certPem = '<PEM encoded certificate content>';
const mspId = 'Org1MSP'; // the msp Id for this org
const transactionProposal = {
fcn: 'move',
args: ['a', 'b', '100'],
chaincodeId: 'mychaincodeId',
channelId: 'mychannel',
};
const { proposal, txId } = channel.generateUnsignedProposal(transactionProposal, mspId, certPem);
// now we have the 'unsigned proposal' for this transaction 2. バイト数計算。 calculate the hash of the transaction proposal bytes.hashFunctionは sha256D とかにしておけばいいだか。 const proposalBytes = proposal.toBuffer(); // the proposal comes from step 1
const hashFunction = xxxx; // A hash function by the user's desire
const digest = hashFunction(proposalBytes); // calculate the hash of the proposal bytes 3. 署名計算 - calculate the signature for this transaction proposal// This is a sample code for signing the digest from step 2 with EC.
// Different signature algorithm may have different interfaces
const elliptic = require('elliptic');
const { KEYUTIL } = require('jsrsasign');
const privateKeyPEM = '<The PEM encoded private key>';
const { prvKeyHex } = KEYUTIL.getKey(privateKeyPEM); // convert the pem encoded key to hex encoded private key
const EC = elliptic.ec;
const ecdsaCurve = elliptic.curves['p256'];
const ecdsa = new EC(ecdsaCurve);
const signKey = ecdsa.keyFromPrivate(prvKeyHex, 'hex');
const sig = ecdsa.sign(Buffer.from(digest, 'hex'), signKey);
// now we have the signature, next we should send the signed transaction proposal to the peer
const signature = Buffer.from(sig.toDER());
const signedProposal = {
signature,
proposal_bytes: proposalBytes,
}; 4. 署名されたProposalをpeerに送信const sendSignedProposalReq = { signedProposal, targets };
const proposalResponses = await channel.sendSignedProposal(sendSignedProposalReq);
// check the proposal responses, if all good, commit the transaction 5. unsigned transactionを作成const commitReq = {
proposalResponses,
proposal,
};
const commitProposal = await channel.generateUnsignedTransaction(commitReq); 6. transactionを署名const signedCommitProposal = signProposal(commitProposal); 7. 署名transactionをcommitするconst response = await channel.sendSignedTransaction({
signedProposal: signedCommitProposal,
request: commitReq,
});
// response.status should be 'SUCCESS' if the commit succeed 8. ChannelEventHub用の eventhub registrationを作成 - generate an unsigned eventhub registration for the ChannelEventHub.const unsignedEvent = eh.generateUnsignedRegistration({
certificate: certPem,
mspId,
}); 9. eventhub registrationを署名 - sign the unsigned eventhub registration with the user's private keyconst signedProposal = signProposal(unsignedEvent);
const signedEvent = {
signature: signedProposal.signature,
payload: signedProposal.proposal_bytes,
}; 10. このChannelEventHubをPeerに登録channelEventHub.connect({signedEvent}); |
Front の Vue を動かす以下ページを参考にした 1. ネットワーク起動しておく2. Dockerコンテナ作成Dockerfile
docker-compose.yaml
3. vue sampleアプリ作成
4. 起動./tutorial_vuejs_todo_management/build/webpack.dev.conf.js
そのあとに起動
5. 確認 |
Vueでjsを呼び出すところまでこれやったら、fabricのjs呼び出せるか試してみる。 Vue.jsで外部jsファイルを読み込んで関数を呼び出す方法 調査以下のようにbrowserのconsoleでエラーが出てしまう。
NodeJS (Webpack): fs.existsSync is not a function 結論Browserifyで"fs.readFileSync is not a function"
node.js ベースのlibは browserでは使えないので、fabric を vue でやるのは無理っぽい。 少なくとも hyperledgerのlib使っているものは api側でやらないといけないようだ。 ただ、
の時点で秘密鍵をAPI側にわたさなければいけない、、、 備考sass install
|
ブラウザから呼び出すのは難しいのでモバイル端末ならOK?Reactnativeならjs使えるっぽいな、、、これならば端末内に 秘密鍵 保持したままCAなどとやりとりできる。 あ、でもFlutterからjsライブラリ呼び出せるんだ。
|
概要
front側をReactNativeでやってみる。必要があればAPIはExpressで。
作業手順
参考
https://fabric-sdk-node.github.io/release-1.4/tutorial-sign-transaction-offline.html
The text was updated successfully, but these errors were encountered: