Closed shohu closed 5 years ago
genesis block作成
$ brew tap hyperledger/fabric
$ brew install fabric-tools@1.3.0
$ cd first-network/
$ ./byfn.sh generate
Generating certs and genesis block for channel 'mychannel' with CLI timeout of '10' seconds and CLI delay of '3' seconds
Continue? [Y/n] Y
proceeding ...
network起動
$ ./byfn.sh up -l node
:
===================== Query successful on peer1.org2 on channel 'mychannel' =====================
========= All GOOD, BYFN execution completed ===========
_____ _ _ ____
| ____| | \ | | | _ \
| _| | \| | | | | |
| |___ | |\ | | |_| |
|_____| |_| \_| |____/
network確認
$ docker network ls
NETWORK ID NAME DRIVER SCOPE
345482a3b516 bridge bridge local
26a5f2507ed8 host host local
4c6dd88934d6 net_byfn bridge local
How do I resolve the error on hyperledger fabric?
$ brew tap hyperledger/fabric
$ brew install fabric-tools@1.3.0
で cryptogen をインストール
以下でnetworkを削除してから
$ ./byfn.sh down
再度
$ ./byfn.sh up -l node
以下手順のtestソース https://github.com/hyperledger/fabric-sdk-node/blob/release-1.4/test/integration/signTransactionOffline.js
この 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
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
// 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,
};
const sendSignedProposalReq = { signedProposal, targets };
const proposalResponses = await channel.sendSignedProposal(sendSignedProposalReq);
// check the proposal responses, if all good, commit the transaction
const commitReq = {
proposalResponses,
proposal,
};
const commitProposal = await channel.generateUnsignedTransaction(commitReq);
const signedCommitProposal = signProposal(commitProposal);
const response = await channel.sendSignedTransaction({
signedProposal: signedCommitProposal,
request: commitReq,
});
// response.status should be 'SUCCESS' if the commit succeed
const unsignedEvent = eh.generateUnsignedRegistration({
certificate: certPem,
mspId,
});
const signedProposal = signProposal(unsignedEvent);
const signedEvent = {
signature: signedProposal.signature,
payload: signedProposal.proposal_bytes,
};
channelEventHub.connect({signedEvent});
以下ページを参考にした https://qiita.com/sin_tanaka/items/6d5d9089eb76dda4ce88
https://github.com/shohu/estate-sample/issues/9#issuecomment-500758798
Dockerfile
FROM node:8.16
COPY . /front
WORKDIR /front
RUN npm install -g vue vue-cli
docker-compose.yaml
version: '2'
networks:
basic:
external:
name: net_byfn
services:
front:
container_name: estatefront
image: estate/front
build:
context: ./front
tty: true
ports:
- 13333:8080
volumes:
- ./front:/front
networks:
- basic
# vue init webpack tutorial_vuejs_todo_management
? Project name todo
? Project description todo
? Author shohu
? Vue build standalone
? Install vue-router? Yes
? Use ESLint to lint your code? Yes
? Pick an ESLint preset Standard
? Set up unit tests Yes
? Pick a test runner jest
? Setup e2e tests with Nightwatch? Yes
? Should we run `npm install` for you after the project has been created? (recommended) npm
./tutorial_vuejs_todo_management/build/webpack.dev.conf.js に以下を追加。macからcontainerにアクセス可能にするため
devServer: {
:
host: '0.0.0.0',
disableHostCheck: true
},
そのあとに起動
$ npm run dev
これやったら、fabricのjs呼び出せるか試してみる。
Vue.jsで外部jsファイルを読み込んで関数を呼び出す方法
以下のようにbrowserのconsoleでエラーが出てしまう。 どうも、fsモジュールが fabric 内で使われていてそれが webpack で読み込めないって言われてるっぽい
file.js?7907:152 Uncaught TypeError: existsSync is not a function
at exports.File.File.loadSync (file.js?7907:152)
at exports.Provider.Provider.add (provider.js?5961:136)
at exports.Provider.Provider.file (provider.js?5961:63)
at Config.reorderFileStores (Config.js?a0b0:71)
at Object.eval (FabricCAServices.js?47f9:25)
at eval (FabricCAServices.js:449)
at Object../node_modules/fabric-ca-client/lib/FabricCAServices.js (app.js:2095)
at __webpack_require__ (app.js:679)
at fn (app.js:89)
at eval (index.js?0171:23)
NodeJS (Webpack): fs.existsSync is not a function
Browserifyで"fs.readFileSync is not a function"
web で fs モジュールはロードできない
node.js ベースのlibは browserでは使えないので、fabric を vue でやるのは無理っぽい。 このため、API側でやる部分とClient側でやる部分をもう少し検討する必要がある。
少なくとも hyperledgerのlib使っているものは api側でやらないといけないようだ。
ただ、
const { proposal, txId } = channel.generateUnsignedProposal(transactionProposal, mspId, certPem);
の時点で秘密鍵をAPI側にわたさなければいけない、、、
sass install
$ npm install sass-loader node-sass --save-dev
Reactnativeならjs使えるっぽいな、、、これならば端末内に 秘密鍵 保持したままCAなどとやりとりできる。 https://qiita.com/takehiro224/items/d60243820b069197e4ba
あ、でもFlutterからjsライブラリ呼び出せるんだ。 Hummingbird: FlutterでWebアプリを作る構想
FlutterからDartライブラリを呼び出すことはもちろん全く問題ない。FlutterからJavaScriptライブラリを呼び出すには、package:jsとdart:jsを利用する。
概要
front側をReactNativeでやってみる。必要があればAPIはExpressで。
作業手順
参考
https://fabric-sdk-node.github.io/release-1.4/tutorial-sign-transaction-offline.html