Fork of github.com/did-method-plc/did-method-plc
1
2@did-plc/lib - DID PLC Typescript Client Library
3================================================
4
5[](https://www.npmjs.com/package/@did-plc/lib)
6[](https://github.com/did-method-plc/did-method-plc/actions/workflows/repo.yaml)
7
8This library provides both a simple client for the PLC directory, and an implementation of the PLC method itself (using a cryptographically signed operation log).
9
10## Client Usage
11
12Fetching account data from directory:
13
14```typescript
15import * as plc from '@did-plc/lib'
16
17client = new plc.Client('https://plc.directory')
18
19let exampleDid = 'did:plc:yk4dd2qkboz2yv6tpubpc6co'
20
21// current account data, in terse object format
22const data = await client.getDocumentData(exampleDid)
23
24// or, the full DID Document
25const didDoc = await client.getDocument(exampleDid)
26```
27
28Registering a new DID PLC:
29
30```typescript
31import { Secp256k1Keypair } from '@atproto/crypto'
32import * as plc from '@did-plc/lib'
33
34// please test against a sandbox or local development server
35client = new plc.Client('http://localhost:2582')
36
37let signingKey = await Secp256k1Keypair.create()
38let rotationKey = await Secp256k1Keypair.create()
39
40did = await client.createDid({
41 signingKey: signingKey.did(),
42 handle: 'handle.example.com',
43 pds: 'https://pds.example.com',
44 rotationKeys: [rotationKey.did()],
45 signer: rotationKey,
46})
47```
48
49## License
50
51MIT / Apache 2.0 dual-licensed.