Skip to content

Commit 601808d

Browse files
authored
Merge pull request #202 from craigmoore1/CLI_Update
Update the Client Library for clarity.
2 parents bc93a75 + bdc444b commit 601808d

1 file changed

Lines changed: 38 additions & 32 deletions

File tree

sol-did/client/packages/core/README.md

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,24 @@ The `sol-did-client` library provides the following features:
4242

4343
## Client library
4444
### Installation
45-
In TS/JS project:
45+
In the command line of the project folder, type the following and then press **Enter**:
4646
```shell
47-
yarn add @identity.com/sol-did-client # or npm install @identity.com/sol-did-client
47+
yarn add @identity.com/sol-did-client #
48+
```
49+
50+
or
51+
52+
```shell
53+
npm install @identity.com/sol-did-client
4854
```
4955

5056
### Usage - Setup and Resolution
5157

58+
Use the following TypeScript code to complete the listed commands.
59+
5260
#### Create a Service
5361

62+
Create a service for a SOL-DID by using the following code snippet:
5463
```ts
5564
const authority = Keypair.generate();
5665
const cluster: ExtendedCluster = 'localnet';
@@ -60,12 +69,14 @@ yarn add @identity.com/sol-did-client # or npm install @identity.com/sol-did-cli
6069
```
6170

6271
### Resolving a DID:
72+
73+
Resolve a SOL-DID with the following code snippet:
6374
```ts
6475
const didDoc = await service.resolve();
6576
console.log(JSON.stringify(didDoc, null, 2));
6677
```
6778

68-
### Information about DID resolution
79+
### DID resolution information
6980
`did:sol` DIDs are resolved in the following way:
7081
1. `Generative` DIDs are DIDs that have no persisted DID data account. (e.g. every valid Solana Account/Wallet is in this state).
7182
This will return a generative DID document where only the public key of the Account is a valid Verification Method.
@@ -76,16 +87,16 @@ on-chain.
7687
## Usage - `did:sol` Manipulation
7788
The following are instructions that can be executed against a DID.
7889

79-
When manipulating a DID one generally needs three authoritative elements:
90+
When manipulating a DID, three elements are generally required:
8091

8192
1. An `authority`, a (native) Verification Method with a `Capability Invocation` flag, that is allowed to manipulate the DID.
8293
2. A `fee payer`, a Solana account that covers the cost of the transaction execution.
8394
3. A `(rent) payer`, a Solana account that covers an (eventual) initialization or resize of the DID data account.
8495

85-
Generally, all these entities are required for successful DID manipulation. Except when increasing the DID account size,
86-
then only a `rent payer` is needed. Often all these accounts are represented by the same account, but this is
87-
not a requirement. For the example, this enables the implementation of a permissionless proxy that satisfies
88-
`2` and `3` to submit an authority-signed instruction/transaction to chain.
96+
Often, all of these entities are required for successful DID manipulation. However, when increasing the DID account size,
97+
then only a `rent payer` is needed. In most cases, all three elements are represented by the same account, but this is
98+
not a requirement. It is possible to implement a permissionless proxy that satisfies the fee payer and the rent payer to submit an authority-signed instruction/transaction to the chain. For example, a dApp might opt to pay fees to encourage user onboarding.
99+
89100

90101
Generally, a manipulative DID operation has the following form:
91102

@@ -138,7 +149,7 @@ Here's a breakdown of all exposed Builder functions:
138149
9. `async instructions(): Promise<TransactionInstruction[]>`: Terminal method that creates and returns the instruction(s) (Eth signing will be applied if applicable).
139150

140151
### Changing of DID Operations
141-
Generally, `DidSolService` allows to chain multiple operations after one another. For example
152+
`DidSolService` allows chaining multiple operations one after another. For example:
142153
```ts
143154
await service
144155
.removeService('service-4', nonAuthoritySigner.publicKey) // remove
@@ -157,12 +168,11 @@ Generally, `DidSolService` allows to chain multiple operations after one another
157168
.withAutomaticAlloc(nonAuthoritySigner.publicKey)
158169
.rpc();
159170
```
160-
This operation chains 1 removeService and 2 addService operations that are signed
171+
This operation chains one(1) `removeService` and two(2) `addService` operations that are signed
161172
by and `ethSigner` and optionally resizes the account.
162173

163174
### Init a DID Account
164-
Generally, all DID operations can be performed with `withAutomaticAlloc(payer: PublicKey)`, which automatically creates a DID data account of the required size. However, the API still supports manually initializing a DID account of any size.
165-
Allocating a sufficiently sized account upfront would allow not to use any payers for subsequent operations.
175+
All DID operations can be performed with `withAutomaticAlloc(payer: PublicKey)`, which automatically creates a DID data account of the required size. However, the API still supports manually initializing a DID account of any size. Allocating an account upfront that is large enough for future modifications might prevent the need to use payers for subsequent operations. However, allocating a larger account increases the rent fees for that account.
166176

167177
```ts
168178
await service.initialize(1_000, payer.publicKey).rpc();
@@ -171,15 +181,15 @@ The `initialize` operation does not support `withAutomaticAlloc` OR `withEthSig
171181
argument will set the default DID authority as `payer` and size it to the minimal initial size required.
172182

173183
### Resize a DID Account
174-
Generally, all DID operations can be performed with `withAutomaticAlloc(payer: PublicKey)`, which automatically creates or resizes a DID data account of the required size. However, the API still supports manually resizing a DID account of any size.
184+
Generally, all DID operations can be performed with `withAutomaticAlloc(payer: PublicKey)`, which automatically creates or resizes a DID data account of the required size. However, the API also supports manually resizing a DID account of any size.
175185

176186
```ts
177187
await service.resize(1_500, payer.publicKey).rpc();
178188
```
179-
The `resize` operation does not support `withAutomaticAlloc`. Using `initialize` without an argument will set the default DID authority as `payer`.
189+
The `resize` operation does not support `withAutomaticAlloc`. Using `initialize` without an argument will set the default DID authority as `payer`.
180190

181191
### Add a Verification Method
182-
The operation will add a new Verification Method to the DID. The `keyData` can be a generically size `UInt8Array`, but logically it must match the methodType specified.
192+
This operation adds a new Verification Method to the DID. The `keyData` can be a generically sized `UInt8Array`, but logically it must match the `methodType` specified.
183193

184194
```ts
185195
await service.addVerificationMethod({
@@ -193,8 +203,7 @@ The operation will add a new Verification Method to the DID. The `keyData` can b
193203
```
194204

195205
### Remove a Verification Method
196-
Removes a Verification Method with the given `fragment` from the DID. Note, that at least one valid Verification Method with
197-
a `Capability Invocation` flag must remain to prevent a lockout.
206+
This code removes a Verification Method with the given `fragment` from the DID. It is important to keep at least one valid Verification Method with a Capability Invocation flag to prevent a lockout.
198207

199208
```ts
200209
await service
@@ -211,8 +220,9 @@ that specific VM). `VerificationMethodFlags.OwnershipProof` is supported for the
211220
- `EcdsaSecp256k1RecoveryMethod2020`
212221
- `EcdsaSecp256k1VerificationKey2019`
213222

223+
In this example, the 'default" VM must match the `authority.publicKey`.
224+
214225
```ts
215-
// Note in this example the 'default" VM must match authority.publicKey
216226
await service
217227
.setVerificationMethodFlags('default',
218228
[VerificationMethodFlags.CapabilityInvocation, VerificationMethodFlags.OwnershipProof],
@@ -301,11 +311,10 @@ which are not allowed to be specified within the bulk update.
301311
.withAutomaticAlloc(authority.publicKey)
302312
.rpc();
303313
```
304-
Note, that the `default` Verification Method can never be removed. Therefore not setting it within the update Method will cause all flags to be removed from it.
314+
The `default` Verification Method can never be removed, therefore not setting it within the update Method will cause all flags to be removed from it.
305315

306316
### Update all properties of a DID with a DID Document
307-
This operation allows for bulk updates of all changeable properties of a DID by passing an existing DidSolDocument.
308-
Please note, that this is a more destructive operation and should be handled with care. Furthermore, by overwriting all Verification Methods it removes ANY existing `VerificationMethodFlags.OwnershipProof`,
317+
This operation allows for bulk updates of all changeable properties of a DID by passing an existing DidSolDocument.This is a destructive operation and should be handled with care. Furthermore, by overwriting all Verification Methods it removes ANY existing `VerificationMethodFlags.OwnershipProof`,
309318
which are not allowed to be specified within the bulk update.
310319

311320
```ts
@@ -357,16 +366,16 @@ which are not allowed to be specified within the bulk update.
357366
```
358367

359368
### Close a DID Account
360-
This transaction closes a DID account. With that, it implicitly reverts to its generative state.
369+
This transaction closes a DID account, reverting it to its generative state.
361370

362371
```ts
363372
await service.close(rentDestination.publicKey).rpc();
364373
```
365374

366-
The rent for the DID data account will be return to `rentDestination`.
375+
The rent for the DID data account will be return to `rentDestination`. Closing a DID account requires using an `AuthoritySigner`.
367376

368377
### Migrate a persisted legacy DID to the new Program
369-
Legacy DIDs are resolved fine with the current `did:sol` resolver, however, if you want to migrate a legacy DID (e.g. because you want to make use of all the new features), you can do so in the following way:
378+
Legacy DIDs resolve without issues with the current `did:sol` resolver, however, if you want to migrate a legacy DID (e.g. to use the new features), you can do so with the following code:
370379

371380
In order to migrate a DID the following requirements need to be met:
372381
- Persisted DID data account in the legacy program.
@@ -390,16 +399,13 @@ if (canMigrate) {
390399
}
391400
```
392401
Note, that the migrate function works with a `nonAuthoritySigner`, e.g. that means ANYONE
393-
can migrate any DID to the new program. But don't worry, since the migration keeps the state,
394-
you can be happy if someone else does it for you.
395-
396-
In this example, however, `nonAuthoritySigner` is the `rent payer` for the new account.
402+
can migrate any DID to the new program. However, the migration keeps the state, costs no more rent, and adds functionality, so no harm is done through the DID migration. Since legacy DIDs often automatically allocated a lot of space and new migrated DIDs are optimally space efficient, the migration to a new DID can actually save SOL.
403+
In this example, however,
404+
`nonAuthoritySigner` is the `rent payer` for the new account.
397405

398-
Furthermore, migrate takes an optional `legacyAuthority` argument. If specified, it closes
406+
In this example, migrate takes an optional `legacyAuthority` argument. If specified, it closes
399407
the legacy DID account automatically and recovers the rent to the `rent payer` of the new
400-
account (`nonAuthoritySigner` in this example). Since legacy DIDs often automatically
401-
allocated **a lot** of space and new migrated DIDs are optimally space efficient,
402-
the migration to a new DID can actually make you `SOL` back.
408+
account (`nonAuthoritySigner` in this example). This action can only be done by an AuthoritySigner, which protects the owner’s rent payer fees from being stolen.
403409

404410

405411
## Contributing

0 commit comments

Comments
 (0)