Skip to content

Commit

Permalink
chore: updated README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
rado0x54 committed Sep 26, 2023
1 parent fff8eda commit b5c1a77
Showing 1 changed file with 136 additions and 0 deletions.
136 changes: 136 additions & 0 deletions ts-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,142 @@ or
npm install @identity.com/did-bnb-client
```

### Contract Addresses
The BNB DID Registry contract is deployed at the following address (via proxy):
- Testnet: [0x88a05b4370BbB90c9F3EEa72A65c77131a7bc18d](https://testnet.bscscan.com/address/0x88a05b4370BbB90c9F3EEa72A65c77131a7bc18d)
- Mainnet: TODO

### Usage - Setup and Resolution
Create a service for a `did:bnb` by using the following code snippet:

#### Via Provider (read-only)
```typescript
const address = "0x88a05b4370BbB90c9F3EEa72A65c77131a7bc18d";
const provider = getDefaultProvider(process.env.RPC_URL); // e.g. https://bsc-testnet.publicnode.com
const chainEnv: ChainEnviroment = 'tesnet';
const didRegistry = new DidRegistry(provider, address, {chainEnvironment: 'localnet'});
// ... use didRegistry client
const randomDid = DidIdentifier.create(
Wallet.createRandom().address,
didRegistry.getDid().chainEnviroment
);
didRegistry.resolve(randomDid)
.then((didDocument) => {
console.log(didDocument);
})
.catch((error) => {
console.log(error);
});
```

#### Via Wallet
```typescript
const address = "0x88a05b4370BbB90c9F3EEa72A65c77131a7bc18d";
const provider = getDefaultProvider(process.env.RPC_URL); // e.g. https://bsc-testnet.publicnode.com
const randomWallet = Wallet.createRandom().connect(provider);
const chainEnv: ChainEnviroment = 'tesnet';
const didRegistry = new DidRegistry(randomWallet, address, {chainEnvironment: 'localnet'});
// ... use didRegistry client
// not passing a DID will resolve the DID of the wallet address
didRegistry.resolve()
.then((didDocument) => {
console.log(didDocument);
})
.catch((error) => {
console.log(error);
});
```
### DID resolution information
`did:bnb` DIDs are resolved in the following way:
1. `Generative` DIDs are DIDs that have no persisted DID account. (e.g. every valid EOA address is in this state).
This will return a generative DID document where only the public key of the Account is a valid Verification Method.
2. `Persisted` DIDs are DIDs that have a persisted DID account. Here the DID document represents the state that is found
on-chain.

### Check generative state (read-only)
```typescript
// can optionally take a DIDIdentifier as a parameter
const isGenerative: boolean = await didRegistry.isGenerativeDidState();
```

### Init a DID on-chain

```typescript
const tx: ContractTransaction = await didRegistry.initializeDidState();
```

### Add a VerificationMethod
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.

```typescript
const verificationMethod = {
fragment: 'test',
flags: reduceVmFlagArray([
BitwiseVerificationMethodFlag.CapabilityInvocation,
]),
methodType: VerificationMethodType.EcdsaSecp256k1RecoveryMethod2020,
keyData: utils.arrayify(Wallet.createRandom().address),
};
const tx: ContractTransaction = await didRegistry.addVerificationMethod(verificationMethod);
```

### Remove a VerificationMethod
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.

```typescript
const tx: ContractTransaction = await didRegistry.removeVerificationMethod('test');
```

### Add a Service
This operation sets a new service on a DID. `serviceType` are strings, not enums, and can therefore be freely defined.

```typescript
const service = {
fragment: 'test2',
service_type: 'testType',
service_endpoint: 'testEndpoint',
};
const tx: ContractTransaction = await didRegistry.addService(service);
```

### Remove a Service
This operation removes a service with the given `fragment` name from the DID.

```typescript
const tx: ContractTransaction = await didRegistry.removeService('test2');
```

### Set VerificationMethodFlags
This sets/updates the flag on an existing VerificationMethod. **Important** if the flag contains `VerificationMethodFlags.OwnershipProof`
this transaction MUST use the same authority as the Verification Method. (e.g. proving that the owner can sign with
that specific VM).

```typescript
const tx: ContractTransaction = await didRegistry
.setVerificationMethodFlags('test', [
BitwiseVerificationMethodFlag.Authentication,
]);
```

### Add Native Controller (did:bnb - DID)
```typescript
const randomWallet = Wallet.createRandom();
const nativeController = DidIdentifier.create(
randomWallet.address,
didRegistry.getDid().chainEnviroment
);
const tx: ContractTransaction = await didRegistry
.addNativeController(nativeController);
```

### Add External Controller (non-did:bnb DID)
```typescript
const externalController = `did:ethr:${Wallet.createRandom().address}`;

const tx: ContractTransaction = await didRegistry
.addExternalController(externalController);
```

## Local Integration Test Setup
This repository uses `test:integration` to run integration test. These test will run against whatever `RPC_URL` is provided in the `.env` file.

Expand Down

0 comments on commit b5c1a77

Please sign in to comment.