···
import { didForCreateOp, PlcClientError } from '@did-plc/lib'
describe('PLC server', () => {
9
-
let handle = 'at://alice.example.com'
9
+
let handle1 = 'at://alice.example.com'
10
+
let handle2 = 'at://bob.example.com'
let atpPds = 'https://example.com'
···
let signingKey: P256Keypair
let rotationKey1: P256Keypair
let rotationKey2: P256Keypair
20
+
let rotationKey3: P256Keypair
const server = await runTestServer({
···
signingKey = await P256Keypair.create()
rotationKey1 = await P256Keypair.create()
rotationKey2 = await P256Keypair.create()
36
+
rotationKey3 = await P256Keypair.create()
···
throw new Error('expected doc')
45
-
expect(doc.did).toEqual(did)
49
+
expect(doc.did).toEqual(did1)
expect(doc.verificationMethods).toEqual({ atproto: signingKey.did() })
expect(doc.rotationKeys).toEqual([rotationKey1.did(), rotationKey2.did()])
48
-
expect(doc.alsoKnownAs).toEqual([handle])
52
+
expect(doc.alsoKnownAs).toEqual([handle1])
expect(doc.services).toEqual({
type: 'AtprotoPersonalDataServer',
···
it('registers a did', async () => {
58
-
did = await client.createDid({
62
+
did1 = await client.createDid({
signingKey: signingKey.did(),
rotationKeys: [rotationKey1.did(), rotationKey2.did()],
70
+
did2 = await client.createDid({
71
+
signingKey: signingKey.did(),
72
+
rotationKeys: [rotationKey3.did()],
75
+
signer: rotationKey3,
it('retrieves did doc data', async () => {
68
-
const doc = await client.getDocumentData(did)
80
+
const doc = await client.getDocumentData(did1)
it('can perform some updates', async () => {
const newRotationKey = await P256Keypair.create()
signingKey = await P256Keypair.create()
75
-
handle = 'at://ali.example2.com'
87
+
handle1 = 'at://ali.example2.com'
atpPds = 'https://example2.com'
78
-
await client.updateAtprotoKey(did, rotationKey1, signingKey.did())
79
-
await client.updateRotationKeys(did, rotationKey1, [
90
+
await client.updateAtprotoKey(did1, rotationKey1, signingKey.did())
91
+
await client.updateRotationKeys(did1, rotationKey1, [
rotationKey1 = newRotationKey
85
-
await client.updateHandle(did, rotationKey1, handle)
86
-
await client.updatePds(did, rotationKey1, atpPds)
97
+
await client.updateHandle(did1, rotationKey1, handle1)
98
+
await client.updatePds(did1, rotationKey1, atpPds)
88
-
const doc = await client.getDocumentData(did)
100
+
const doc = await client.getDocumentData(did1)
···
'did:key:z6MkjwbBXZnFqL8su24wGL2Fdjti6GSLv9SWdYGswfazUPm9'
97
-
const promise = client.updateRotationKeys(did, rotationKey1, [
109
+
const promise = client.updateRotationKeys(did2, rotationKey3, [
110
+
rotationKey2.did(),
await expect(promise).rejects.toThrow(PlcClientError)
···
// Note: atproto itself does not currently support ed25519 keys, but PLC
// does not have opinions about atproto (or other services!)
111
-
await client.updateAtprotoKey(did, rotationKey1, newSigningKey)
123
+
await client.updateAtprotoKey(did2, rotationKey3, newSigningKey)
const exoticSigningKeyFromTheFuture =
'did:key:zUC7K4ndUaGZgV7Cp2yJy6JtMoUHY6u7tkcSYUvPrEidqBmLCTLmi6d5WvwnUqejscAkERJ3bfjEiSYtdPkRSE8kSa11hFBr4sTgnbZ95SJj19PN2jdvJjyzpSZgxkyyxNnBNnY'
await client.updateAtprotoKey(
exoticSigningKeyFromTheFuture,
122
-
// put the old key back so as not to disrupt the other tests
123
-
await client.updateAtprotoKey(did, rotationKey1, signingKey.did())
it('does not allow syntactically invalid service keys', async () => {
const promise = client.updateAtprotoKey(
'did:banana', // a malformed did:key
await expect(promise).rejects.toThrow(PlcClientError)
const promise2 = client.updateAtprotoKey(
'blah', // an even more malformed did:key
await expect(promise2).rejects.toThrow(PlcClientError)
it('retrieves the operation log', async () => {
142
-
const doc = await client.getDocumentData(did)
143
-
const ops = await client.getOperationLog(did)
144
-
const computedDoc = await plc.validateOperationLog(did, ops)
151
+
const doc = await client.getDocumentData(did1)
152
+
const ops = await client.getOperationLog(did1)
153
+
const computedDoc = await plc.validateOperationLog(did1, ops)
expect(computedDoc).toEqual(doc)
it('rejects on bad updates', async () => {
const newKey = await P256Keypair.create()
150
-
const operation = client.updateAtprotoKey(did, newKey, newKey.did())
159
+
const operation = client.updateAtprotoKey(did1, newKey, newKey.did())
await expect(operation).rejects.toThrow()
it('allows for recovery through a forked history', async () => {
const attackerKey = await P256Keypair.create()
156
-
await client.updateRotationKeys(did, rotationKey2, [attackerKey.did()])
165
+
await client.updateRotationKeys(did1, rotationKey2, [attackerKey.did()])
const newKey = await P256Keypair.create()
159
-
const ops = await client.getOperationLog(did)
168
+
const ops = await client.getOperationLog(did1)
const forkPoint = ops.at(-2)
if (!check.is(forkPoint, plc.def.operation)) {
throw new Error('Could not find fork point')
···
168
-
await client.sendOperation(did, op)
177
+
await client.sendOperation(did1, op)
172
-
const doc = await client.getDocumentData(did)
181
+
const doc = await client.getDocumentData(did1)
it('retrieves the auditable operation log', async () => {
177
-
const log = await client.getOperationLog(did)
178
-
const auditable = await client.getAuditableLog(did)
186
+
const log = await client.getOperationLog(did1)
187
+
const auditable = await client.getAuditableLog(did1)
expect(auditable.length).toBe(log.length + 1)
expect(auditable.filter((op) => op.nullified).length).toBe(1)
···
it('retrieves the did doc', async () => {
189
-
const data = await client.getDocumentData(did)
190
-
const doc = await client.getDocument(did)
198
+
const data = await client.getDocumentData(did1)
199
+
const doc = await client.getDocument(did1)
expect(doc).toEqual(plc.formatDidDoc(data))
···
keys.map(async (key) => {
226
-
await client.updateAtprotoKey(did, rotationKey1, key.did())
235
+
await client.updateAtprotoKey(did1, rotationKey1, key.did())
···
expect(successes).toBe(1)
expect(failures).toBe(19)
236
-
const ops = await client.getOperationLog(did)
237
-
await plc.validateOperationLog(did, ops)
245
+
const ops = await client.getOperationLog(did1)
246
+
await plc.validateOperationLog(did1, ops)
it('tombstones the did', async () => {
241
-
await client.tombstone(did, rotationKey1)
250
+
await client.tombstone(did1, rotationKey1)
243
-
const promise = client.getDocument(did)
252
+
const promise = client.getDocument(did1)
await expect(promise).rejects.toThrow(PlcClientError)
245
-
const promise2 = client.getDocumentData(did)
254
+
const promise2 = client.getDocumentData(did1)
await expect(promise2).rejects.toThrow(PlcClientError)
it('exports the data set', async () => {
const data = await client.export()
expect(data.every((row) => check.is(row, plc.def.exportedOp))).toBeTruthy()
252
-
expect(data.length).toBe(31)
261
+
expect(data.length).toBe(32)
for (let i = 1; i < data.length; i++) {
expect(data[i].createdAt >= data[i - 1].createdAt).toBeTruthy()
···
signingKey: signingKey.did(),
recoveryKey: rotationKey1.did(),