shohu / estate-sample

Read-only mirror of https://gerrit.hyperledger.org/r/#/admin/projects/fabric-samples
https://hyperledger.org
Apache License 2.0
0 stars 0 forks source link

Estate売買実装 #8

Open shohu opened 5 years ago

shohu commented 5 years ago

Estate購入時のフロー

以下のフローを実現する

  1. buyerが買い申請をsellerに通知
  2. sellerが金額を確認してOKをbuyerに通知
  3. コントラクトが所有権を移転

上記は申請したtransactionのオーナーが、所有者と一致していればOKか?

shohu commented 5 years ago

所有権移転のtransactionが、buyer, sellerの2人の署名があれば実行できるようにしたい

shohu commented 5 years ago

transactionのsender取得方法

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

shohu commented 5 years ago

以下対応を検討してみる。

IMG_1906

構造

売買申請データ

メソッド

課題

shohu commented 5 years ago

GetCreatorでcreator id取得試す

以下をみると 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);

ClientIdentity

これがどこかで取得できればいけそうだ 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
}

User id っぽいものが取れた

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\""
shohu commented 5 years ago

ただ、こちらの方法だといずれにしろ秘密鍵がサーバーに残ってしまうため、なるべくclientで管理させたい。

このため、client側で秘密鍵を生成して、それで サーバー側では秘密鍵を扱わずにする 形の方がよいかもしれない。

shohu commented 5 years ago

そもそも、commercial-paperのwalletは既存にあった wallet を使っている。 ということは、これをbrowser側でwalletを作成してそのファイル達を使って、transactionが送信できれば一番良い。

browser側で ca認証局とやりとりをして、ローカル秘密鍵保存。 そのwalletを元に、server側とやりとりをする。