|
| 1 | +--- |
| 2 | +layout: default |
| 3 | +title: Create a Custom Identity |
| 4 | +parent: pages.tutorials |
| 5 | +nav_order: 8 |
| 6 | +--- |
| 7 | + |
| 8 | +# Create a Custom Identity |
| 9 | + |
| 10 | +{: .no_toc } |
| 11 | + |
| 12 | +## Table of contents |
| 13 | + |
| 14 | +{: .no_toc .text-delta } |
| 15 | + |
| 16 | +1. TOC |
| 17 | + {:toc} |
| 18 | + |
| 19 | +--- |
| 20 | + |
| 21 | +## Quick reference |
| 22 | + |
| 23 | +Out of the box, a FireFly Supernode contains both an `org` and a `node` identity. Your use case might demand more granular notions of identity (ex. customers, clients, etc.). Instead of creating a Supernode for each identity, you can create multiple custom identities within a FireFly Supernode. |
| 24 | + |
| 25 | +## Additional info |
| 26 | + |
| 27 | +- Reference: [Identities](../reference//identities.md) |
| 28 | +- Swagger: <a href="../swagger/swagger.html#/Default%20Namespace/postNewIdentity" data-proofer-ignore>POST /api/v1/identities</a> |
| 29 | + |
| 30 | +## Previous steps: Start your environment |
| 31 | + |
| 32 | +If you haven't started a FireFly stack already, please go to the Getting Started guide on how to [Start your environment](../../gettingstarted/setup_env.md) |
| 33 | + |
| 34 | +[← ② Start your environment](../../gettingstarted/setup_env.md){: .btn .btn-purple .mb-5} |
| 35 | + |
| 36 | +## Step 1: Create a new account |
| 37 | + |
| 38 | +The FireFly CLI has a helpful command to create an account in a local development environment for you. |
| 39 | + |
| 40 | +> **NOTE**: In a production environment, key management actions such as creation, encryption, unlocking, etc. may be very different, depending on what type of blockchain node and signer your specific deployment is using. |
| 41 | +
|
| 42 | +To create a new account on your local stack, run: |
| 43 | + |
| 44 | +``` |
| 45 | +ff accounts create <stack_name> |
| 46 | +``` |
| 47 | + |
| 48 | +``` |
| 49 | +{ |
| 50 | + "address": "0xc00109e112e21165c7065da776c75cfbc9cdc5e7", |
| 51 | + "privateKey": "..." |
| 52 | +} |
| 53 | +``` |
| 54 | + |
| 55 | +The FireFly CLI has created a new private key and address for us to be able to use, and it has loaded the encrypted private key into the signing container. However, we haven't told FireFly itself about the new key, or who it belongs to. That's what we'll do in the next steps. |
| 56 | + |
| 57 | +## Step 2: Query the parent org for its UUID |
| 58 | + |
| 59 | +If we want to create a new custom identity under the organizational identity that we're using in a multiparty network, first we will need to look up the UUID for our org identity. We can look that up by making a `GET` request to the status endpoint on the default namespace. |
| 60 | + |
| 61 | +### Request |
| 62 | + |
| 63 | +`GET` `http://localhost:5000/api/v1/status` |
| 64 | + |
| 65 | +### Response |
| 66 | + |
| 67 | +```js |
| 68 | +{ |
| 69 | + "namespace": {...}, |
| 70 | + "node": {...}, |
| 71 | + "org": { |
| 72 | + "name": "org_0", |
| 73 | + "registered": true, |
| 74 | + "did": "did:firefly:org/org_0", |
| 75 | + "id": "1c0abf75-0f3a-40e4-a8cd-5ff926f80aa8", // We need this in Step 3 |
| 76 | + "verifiers": [ |
| 77 | + { |
| 78 | + "type": "ethereum_address", |
| 79 | + "value": "0xd7320c76a2efc1909196dea876c4c7dabe49c0f4" |
| 80 | + } |
| 81 | + ] |
| 82 | + }, |
| 83 | + "plugins": {...}, |
| 84 | + "multiparty": {...} |
| 85 | +} |
| 86 | +``` |
| 87 | + |
| 88 | +## Step 3: Register the new custom identity with FireFly |
| 89 | + |
| 90 | +Now we can `POST` to the identities endpoint to create a new custom identity. We will include the UUID of the organizational identity from the previous step in the `"parent"` field in the request. |
| 91 | + |
| 92 | +### Request |
| 93 | + |
| 94 | +`POST` `http://localhost:5000/api/v1/identities` |
| 95 | + |
| 96 | +```js |
| 97 | +{ |
| 98 | + "name": "myCustomIdentity", |
| 99 | + "key": "0xc00109e112e21165c7065da776c75cfbc9cdc5e7", // Signing Key from Step 1 |
| 100 | + "parent": "1c0abf75-0f3a-40e4-a8cd-5ff926f80aa8" // Org UUID from Step 2 |
| 101 | +} |
| 102 | +``` |
| 103 | + |
| 104 | +### Response |
| 105 | + |
| 106 | +```js |
| 107 | +{ |
| 108 | + "id": "5ea8f770-e004-48b5-af60-01994230ed05", |
| 109 | + "did": "did:firefly:myCustomIdentity", |
| 110 | + "type": "custom", |
| 111 | + "parent": "1c0abf75-0f3a-40e4-a8cd-5ff926f80aa8", |
| 112 | + "namespace": "", |
| 113 | + "name": "myCustomIdentity", |
| 114 | + "messages": { |
| 115 | + "claim": "817b7c79-a934-4936-bbb1-7dcc7c76c1f4", |
| 116 | + "verification": "ae55f998-49b1-4391-bed2-fa5e86dc85a2", |
| 117 | + "update": null |
| 118 | + } |
| 119 | +} |
| 120 | +``` |
| 121 | + |
| 122 | +## Step 4: Query the New Custom Identity |
| 123 | + |
| 124 | +Lastly, if we want to confirm that the new identity has been created, we can query the identities endpoint to see our new custom identity. |
| 125 | + |
| 126 | +### Request |
| 127 | + |
| 128 | +`GET` `http://localhost:5000/api/v1/identities?fetchverifiers=true` |
| 129 | + |
| 130 | +> **NOTE**: Using `fetchverifiers=true` will return the cryptographic verification mechanism for the FireFly identity. |
| 131 | +
|
| 132 | +### Response |
| 133 | + |
| 134 | +```js |
| 135 | +[ |
| 136 | + { |
| 137 | + "id": "5ea8f770-e004-48b5-af60-01994230ed05", |
| 138 | + "did": "did:firefly:myCustomIdentity", |
| 139 | + "type": "custom", |
| 140 | + "parent": "1c0abf75-0f3a-40e4-a8cd-5ff926f80aa8", |
| 141 | + "namespace": "default", |
| 142 | + "name": "myCustomIdentity", |
| 143 | + "messages": { |
| 144 | + "claim": "817b7c79-a934-4936-bbb1-7dcc7c76c1f4", |
| 145 | + "verification": "ae55f998-49b1-4391-bed2-fa5e86dc85a2", |
| 146 | + "update": null |
| 147 | + }, |
| 148 | + "created": "2022-09-19T18:10:47.365068013Z", |
| 149 | + "updated": "2022-09-19T18:10:47.365068013Z", |
| 150 | + "verifiers": [ |
| 151 | + { |
| 152 | + "type": "ethereum_address", |
| 153 | + "value": "0xfe1ea8c8a065a0cda424e2351707c7e8eb4d2b6f" |
| 154 | + } |
| 155 | + ] |
| 156 | + }, |
| 157 | + { ... }, |
| 158 | + { ... } |
| 159 | +] |
| 160 | +``` |
0 commit comments