Open shohu opened 5 years ago
所有権移転のtransactionが、buyer, sellerの2人の署名があれば実行できるようにしたい
estateの所有者とtransaction実行者が一致すればOKとする条件で色々できるかも。
Does Hyperledger-Fabric provide a way to find out who (msg.sender in Ethereum) called the chaincode?
これをみると、GetCreatorというメソッドで取得できる? 以下がそう。 https://fabric-shim.github.io/master/fabric-shim.ChaincodeStub.html#getCreator__anchor
以下対応を検討してみる。
以下をみると ProposalCreator で返却される。
getCreator() Returns the identity object of the chaincode invocation's submitter Returns: Type ProposalCreator
https://fabric-shim.github.io/master/fabric-shim.ChaincodeStub.html#getCreator__anchor
ただ、ProposalCreator をみると mspid しか持っておらず https://fabric-shim.github.io/master/fabric-shim.ProposalCreator.html#ProposalCreator__anchor
Membership Service Providerインスタンスの一意のID
らしいので、これ現状だと使えない・・・? mspidは以下だよなぁ
name: first-network-org1
version: 1.0.0
client:
organization: Org1
connection:
timeout:
peer:
endorser: '300'
organizations:
Org1:
mspid: Org1MSP
ただ、以下のような形で username指定しているから、contract実行時にとれそうだけどな、ユーザー情報
const userName = 'User1@org1.example.com';
// Load connection profile; will be used to locate a gateway
let connectionProfile = yaml.safeLoad(
fs.readFileSync('./gateway/networkConnection.yaml', 'utf8')
);
// Set connection options; identity and wallet
let connectionOptions = {
identity: userName,
wallet: wallet,
discovery: { enabled: false, asLocalhost: true }
};
// Connect to gateway using application specified parameters
console.log('Connect to Fabric gateway.');
await gateway.connect(connectionProfile, connectionOptions);
これがどこかで取得できればいけそうだ https://fabric-shim.github.io/master/fabric-shim.ClientIdentity.html#getID__anchor
以下で権限チェックしている。この辺り使えそう
const ClientIdentity = require('fabric-shim').ClientIdentity;
let cid = new ClientIdentity(stub); // "stub" is the ChaincodeStub object passed to Init() and Invoke() methods
if (cid.assertAttributeValue('hf.role', 'auditor')) {
// proceed to carry out auditing
}
contractで以下
async clientId(ctx) {
let cid = new ClientIdentity(ctx.stub);
return JSON.stringify(cid.getID());
}
出力した文字列が以下。User1@org1.example.comを一旦見ておけばいいかな。
"\"x509::/C=US/ST=California/L=San Francisco/CN=User1@org1.example.com::/C=US/ST=California/L=San Francisco/O=org1.example.com/CN=ca.org1.example.com\""
ただ、こちらの方法だといずれにしろ秘密鍵がサーバーに残ってしまうため、なるべくclientで管理させたい。
このため、client側で秘密鍵を生成して、それで サーバー側では秘密鍵を扱わずにする 形の方がよいかもしれない。
そもそも、commercial-paperのwalletは既存にあった wallet を使っている。 ということは、これをbrowser側でwalletを作成してそのファイル達を使って、transactionが送信できれば一番良い。
browser側で ca認証局とやりとりをして、ローカル秘密鍵保存。 そのwalletを元に、server側とやりとりをする。
Estate購入時のフロー
以下のフローを実現する
上記は申請したtransactionのオーナーが、所有者と一致していればOKか?