|
| 1 | + # Tell SDK which pool you are going to use. You should have already started |
| 2 | + # this pool using docker compose or similar. Here, we are dumping the config |
| 3 | + # just for demonstration purposes. |
| 4 | + print_log('1. Creates a new local pool ledger configuration that is used ' |
| 5 | + 'later when connecting to ledger.\n') |
| 6 | + pool_config = json.dumps({'genesis_txn': genesis_file_path}) |
| 7 | + await pool.create_pool_ledger_config(config_name=pool_name, config=pool_config) |
| 8 | + |
| 9 | + print_log('\n2. Open pool ledger and get handle from libindy\n') |
| 10 | + pool_handle = await pool.open_pool_ledger(config_name=pool_name, config=None) |
| 11 | + |
| 12 | + print_log('\n3. Creating new secure wallet with the given unique name\n') |
| 13 | + await wallet.create_wallet(pool_name, wallet_name, None, None, None) |
| 14 | + |
| 15 | + print_log('\n4. Open wallet and get handle from libindy to use in methods that require wallet access\n') |
| 16 | + wallet_handle = await wallet.open_wallet(wallet_name, None, None) |
| 17 | + |
| 18 | + # First, put a steward DID and its keypair in the wallet. This doesn't write anything to the ledger, |
| 19 | + # but it gives us a key that we can use to sign a ledger transaction that we're going to submit later. |
| 20 | + print_log('\n5. Generating and storing steward DID and verkey\n') |
| 21 | + |
| 22 | + |
| 23 | + # The DID and public verkey for this steward key are already in the ledger; they were part of the genesis |
| 24 | + # transactions we told the SDK to start with in the previous step. But we have to also put the DID, verkey, |
| 25 | + # and private signing key into our wallet, so we can use the signing key to submit an acceptably signed |
| 26 | + # transaction to the ledger, creating our *next* DID (which is truly new). This is why we use a hard-coded seed |
| 27 | + # when creating this DID--it guarantees that the same DID and key material are created that the genesis txns |
| 28 | + # expect. |
| 29 | + steward_seed = "000000000000000000000000Steward1" |
| 30 | + |
| 31 | + did_json = json.dumps({'seed': steward_seed}) |
| 32 | + |
| 33 | + steward_did, steward_verkey = await signus.create_and_store_my_did(wallet_handle, did_json) |
| 34 | + print_log('Steward DID: ', steward_did) |
| 35 | + |
| 36 | + |
| 37 | + # Now, create a new DID and verkey for a trust anchor, and store it in our wallet as well. Don't use a seed; |
| 38 | + # this DID and its keyas are secure and random. Again, we're not writing to the ledger yet. |
| 39 | + print_log('\n6. Generating and storing trust anchor DID and verkey\n') |
| 40 | + trust_anchor_did, trust_anchor_verkey = await signus.create_and_store_my_did(wallet_handle, "{}") |
| 41 | + print_log('Trust Anchor DID: ', trust_anchor_did) |
| 42 | + print_log('Trust Anchor Verkey: ', trust_anchor_verkey) |
| 43 | + |
| 44 | + # Here, we are building the transaction payload that we'll send to write the Trust Anchor identity to the ledger. |
| 45 | + # We submit this transaction under the authority of the steward DID that the ledger already recognizes. |
| 46 | + # This call will look up the private key of the steward DID in our wallet, and use it to sign the transaction. |
| 47 | + print_log('\n7. Building NYM request to add Trust Anchor to the ledger\n') |
| 48 | + nym_transaction_request = await ledger.build_nym_request(submitter_did=steward_did, |
| 49 | + target_did=trust_anchor_did, |
| 50 | + ver_key=trust_anchor_verkey, |
| 51 | + alias=None, |
| 52 | + role='TRUST_ANCHOR') |
| 53 | + print_log('NYM request: ') |
| 54 | + pprint.pprint(json.loads(nym_transaction_request)) |
| 55 | + |
| 56 | + # Now that we have the transaction ready, send it. The building and the sending are separate steps because some |
| 57 | + # clients may want to prepare transactions in one piece of code (e.g., that has access to privileged backend systems), |
| 58 | + # and communicate with the ledger in a different piece of code (e.g., that lives outside the safe internal |
| 59 | + # network). |
| 60 | + print_log('\n8. Sending NYM request to the ledger\n') |
| 61 | + nym_transaction_response = await ledger.sign_and_submit_request(pool_handle=pool_handle, |
| 62 | + wallet_handle=wallet_handle, |
| 63 | + submitter_did=steward_did, |
| 64 | + request_json=nym_transaction_request) |
| 65 | + print_log('NYM response: ') |
| 66 | + pprint.pprint(json.loads(nym_transaction_response)) |
| 67 | + |
| 68 | + # At this point, we have successfully written a new identity to the ledger. Our next step will be to query it. |
0 commit comments