external partyは、トランザクションを認可する秘密鍵を利用者が自分で持つpartyです。 この頁は、その鍵を持つ利用者の側が、tutorialに沿ってexternal partyをParticipant Nodeへ登録する手順と、複数のParticipant Nodeに載せる手順を追います。 鍵の持ち方と署名の仕組みは、頁「外部署名のparty」が追っています。 登録に渡す欄の一覧は、頁「外部のpartyを登録する」が追っています。

登録は5つの手順と確認の1段で進む

tutorialの操作例は、Ledger APIでexternal partyを登録する手順を、次の5つの順に実行します。 この頁も、操作例が実行する順に並べます。

  1. 使えるSynchronizerのIDを決めます。
  2. opensslで、external partyの秘密鍵を作ります。
  3. 新しいexternal partyを定めるtopology transactionを作らせます。
  4. そのtopology transactionに署名します。
  5. 署名したtopology transactionをLedger APIへ上げて、割り当てを頼みます。

5つの手順を終えた後に、割り当てたpartyをparty IDで問い、Ledger APIに現れる事を確かめます。 図Aは、この5つの手順と確認の1段を、合わせて6つの段で追います。

topology transactionは、頁「topologyの変更に外部の鍵で署名する」で見た、topologyを変えるトランザクションです。 hintは、party IDの::の前の部分になる文字列で、頁「外部のpartyを登録する」が同じ説明を持ちます。 fingerprintは、公開鍵から計算したハッシュ値です。 multi-hashは、作ったtopology transactionの組全体に対するハッシュです。

tutorialは、opensslでファイルシステムの上に鍵を作ります。 これは本番の利用には安全でないので、鍵の管理は本番の鍵の置き場に替えて読みます。

Cantonは、配布物のルートのディレクトリから ./bin/canton -c examples/08-interactive-submission/interactive-submission.conf --bootstrap examples/08-interactive-submission/bootstrap.canton で起動します。 手順をまとめて動かすスクリプトの external_party_onboarding.sh は、配布物の examples/08-interactive-submission に置かれています。

スクリプトは、動かしているCantonのポートの設定を持つ canton_ports.json を、Cantonを起動したディレクトリで探します。 配布物のルートで起動した例では、同じルートから ./examples/08-interactive-submission/external_party_onboarding.sh を実行します。 別のディレクトリから動かす時は、-p1 <host>:<port> で、Ledger APIのホストとポートを自分で渡します。

図Aは、利用者の側とParticipant Nodeの間で、この順を追います。 鍵を作る手順と署名する手順は、利用者の側だけで行うので、線を引かずに処理として示します。 図Aは、生成を頼むParticipant Nodeを信頼できる時の例です。

利用者の側鍵を持ち、署名するParticipant NodeLedger APIで受け付ける112233445566つながる先を問うつながる先を問うSynchronizerのIDSynchronizerのIDSynchronizerとhintと公開鍵Synchronizerとhintと公開鍵topology transactionとparty IDtopology transactionとparty IDtopology transactionと署名topology transactionと署名割り当て済み割り当て済みparty IDで問うparty秘密鍵を作り、公開鍵を取り出す秘密鍵を作り、公開鍵を取り出すmulti-hashに署名するmulti-hashに署名する
  1. Synchronizerを決める

    利用者の側は、Participant Nodeが今つながっているSynchronizerを問い、使えるSynchronizerのIDを得ます。
    tutorialは、つながっているSynchronizerがちょうど1つの場合で進めます。

  2. 鍵を作る

    利用者の側は、opensslでEd25519の秘密鍵を作り、公開鍵をDER形式で取り出してbase64に変えます。
    他の種類の鍵も使えます。

  3. topology transactionを作らせる

    利用者の側は、SynchronizerのIDとhintと公開鍵を渡し、登録に要るtopology transactionを作らせます。
    応答は、作ったtopology transactionと、新しいpartyのparty IDと、公開鍵のfingerprintと、全体のハッシュのmulti-hashです。

  4. multi-hashに署名する

    利用者の側は、multi-hashをbase64から戻し、秘密鍵で署名して、署名をbase64にします。
    topology transactionは、1つずつ署名しても、1つのハッシュとしてまとめて署名しても構いません。

  5. 割り当てを頼む

    利用者の側は、SynchronizerのIDと、topology transactionと、署名を渡して、割り当てを頼みます。
    1つのParticipant Nodeでpartyを割り当てる時、この呼び出しは同期で、partyが割り当てられた時に返ります。

  6. partyを確かめる

    割り当てたpartyは、party IDで絞って問うと、Ledger APIに現れます。

使えるSynchronizerの決め方と鍵の作り方

使えるSynchronizerのIDは、Ledger APIの /v2/state/connected-synchronizers で得ます。 このコマンドも、Cantonを起動したディレクトリから実行し、canton_ports.json を読ませます。 partyの割り当ては、partyを載せたいSynchronizerのIDごとに繰り返します。

external partyの鍵は、Ed25519の秘密鍵を作ります。 Ed25519は、EdDSAの署名方式の1つです。 EdDSAは、エドワーズ曲線という楕円曲線を使う署名の方式です。

他の種類の鍵も使えます。 公開鍵は、DER形式で取り出し、base64に変えます。 DERは、鍵や署名のようなデータを、決まった規則でバイト列に符号化する形式です。

base64は、バイト列を英数字と記号の文字に置き換える符号化の方式です。

topology transactionは生成のエンドポイントで作らせる

エンドポイント /v2/parties/external/generate-topology は、登録に要るtopology transactionを、Participant Nodeに作らせます。 生成を頼むParticipant Nodeを信頼できる時は、これで構いません。 信頼できない時は、topology transactionを自分で組むか、署名の前に中身を調べて、ハッシュを計算し直します。 topology transactionの中身を調べる手順は、頁「topologyの変更に外部の鍵で署名する」が追っています。

要求は、この例では次の4つの欄を送ります。 他の欄は、頁「外部のpartyを登録する」の表が持ちます。

欄 tutorialの値
synchronizer 先に決めたSynchronizerのID
partyHint 例は Alice
publicKey format が CRYPTO_KEY_FORMAT_DER_X509_SUBJECT_PUBLIC_KEY_INFO、keyData がbase64にした公開鍵、keySpec が SIGNING_KEY_SPEC_EC_CURVE25519
otherConfirmingParticipantUids 単一のParticipant Nodeの例は空の並び

応答は、この例で使う次の4つの欄を返します。

返る物 中身
topologyTransactions 登録に要るtopology transactionの並び
partyId 新しいpartyのparty ID
publicKeyFingerprint 公開鍵のfingerprint
multiHash topology transactionの組全体に対するハッシュ

エンドポイントが返す登録のtopology transactionの数は変わりうるので、数を前提にしません。

署名して割り当てる

署名は、multi-hashをbase64から戻し、openssl pkeyutl -sign -rawin で秘密鍵により行い、署名をbase64にします。 tutorialは、topology transactionをまとめて1つのハッシュで署名します。 1つずつ署名する形も使えます。

割り当ての呼び出しの /v2/parties/external/allocate は、この例では次の3つの欄を受け取って、登録を終えます。 他の欄は、頁「外部のpartyを登録する」の表が持ちます。

欄 tutorialの値
synchronizer 先に決めたSynchronizerのID
onboardingTransactions 生成で返った topologyTransactions の各要素を、transaction の欄に1つずつ入れた並び
multiHashSignatures 署名を並べる配列。例は要素が1つで、format が SIGNATURE_FORMAT_CONCAT、signature がbase64にした署名、signedBy が公開鍵のfingerprint、signingAlgorithmSpec が SIGNING_ALGORITHM_SPEC_ED25519

割り当てたpartyは、/v2/parties?filter-party=<party-id> で、Ledger APIに現れます。

複数のParticipant Nodeに載せる

複数のParticipant Nodeに載るexternal partyの登録は、単純な拡張です。 tutorialのスクリプトは、--multi-hosted を付けると、既定で2つのParticipant Nodeに登録します。

単一のParticipant Nodeの例と、複数のParticipant Nodeの例で、指定を変える欄は、生成の要求の otherConfirmingParticipantUids です。

欄 単一のParticipant Nodeの例 複数のParticipant Nodeの例
otherConfirmingParticipantUids 空の並び 2つ目のParticipant NodeのID

2つ目のParticipant NodeのIDを渡すと、作られるtopology transactionのhostingの関係に、そのParticipant Nodeが加わります。 他に observingParticipantUids と confirmationThreshold の欄があります。 confirmationThreshold を設定しない時は、Confirmationを行うParticipant Nodeの数になります。

作ったtopology transactionは、1つ目のParticipant Nodeの割り当てと同じく、SynchronizerのIDと、生成で返ったtopology transactionの一式と、利用者の署名を渡して、2つ目のParticipant NodeのJSON Ledger APIの割り当ての呼び出しにも上げます。 割り当てを受けた各Participant Nodeでは、partyを使う前に、載せる関係を明示的に認可します。 multi-hosted partyは、頁「partyを作り複数のノードに載せる」で見ました。 thresholdは、頁「複数の署名でpartyを守る」が追っています。

JSON

JSONは、データを文字で表すための形式で、Webのプログラムどうしのデータのやり取りに広く使われています。

Canton Consoleでinternal partyの載せる提案を試す

この節の例は、external partyでなくinternal partyの載せる提案です。 external partyを複数のParticipant Nodeに載せる登録は、前の節のJSON Ledger APIの割り当てで行います。

Canton Consoleで、2つのParticipant Nodeが同じSynchronizerにつながっていれば、載せる関係の提案と承認を試せます。 participant1がinternal partyの載せる提案を作り、participant2が承認する形で、topology transactionの署名を外で作らずに済みます。

最初に、participant1で topology.party_to_participant_mappings.propose を呼びます。 partyのAliceを、participant1とparticipant2に、ParticipantPermission.Confirmation で載せる提案を作ります。

text
participant1.topology.party_to_participant_mappings.propose(
  PartyId.tryCreate("Alice", participant1.id.uid.namespace),
  newParticipants = Seq(
    (participant1.id, ParticipantPermission.Confirmation),
    (participant2.id, ParticipantPermission.Confirmation),
  ),
)

返るのは、serialが1で、operationが Replace で、participant1の署名だけを持つ PartyToParticipant の提案です。 次に、participant2で list_hosting_proposals を呼ぶと、txHash とparty、permission、他のParticipant Node、threshold 1を持つ、participant2の署名を待つ提案が出ます。 提案は txHash で特定し、participant2.topology.transactions.authorize(synchronizer_id, txHash) で、participant2の署名を加えます。 全ての署名がそろうと、participant1.parties.hosted("Alice") が、partyが両方のParticipant Nodeに Confirmation の権限で載っていると返します。

図Bは、internal partyの提案の状態を、3つの段で追います。 図の「提案を識別するハッシュ」が、コードの txHash にあたります。

始まり署名1つの提案participant1だけ全署名の提案participant2も署名両方に載ったConfirmationで載る112233提案を作る提案を作る提案を作る承認する承認する承認する載る
  1. 提案を作る

    participant1が提案を作ると、提案はparticipant1の署名だけを持ち、participant2の署名を待ちます。
    participant2で提案の一覧を見ると、提案を識別するハッシュで特定できる提案が出ます。

  2. participant2が承認する

    participant2が、提案を識別するハッシュで特定した提案を承認すると、participant2の署名が加わり、提案は全ての署名をそろえます。

  3. 両方のParticipant Nodeに載る

    提案が全ての署名をそろえると、partyは両方のParticipant Nodeに載っていると、participant1で確かめられます。

次に読む頁

次の頁「外で署名してコントラクトを動かす」は、2つのexternal partyのAliceとBobが、Pingコントラクトを作り、exerciseして、archiveするまでを追います。 次の頁の前に、この頁の登録手順を、AliceとBobのそれぞれに実施します。 前の節のConsoleのAliceはinternal partyなので、次の頁には引き継ぎません。 登録で得た、external partyのIDと、署名に使う秘密鍵と、公開鍵のfingerprintを、次の頁で使います。

出典