···
import { EcdsaKeypair } from '@atproto/crypto'
import * as plc from '@did-plc/lib'
import { CloseFn, runTestServer } from './_util'
4
-
import { check, cidForCbor } from '@atproto/common'
4
+
import { check } from '@atproto/common'
import { AxiosError } from 'axios'
import { Database } from '../src'
7
-
import { signOperation } from '@did-plc/lib'
describe('PLC server', () => {
10
-
let handle = 'alice.example.com'
11
-
let atpPds = 'example.com'
9
+
let handle = 'at://alice.example.com'
10
+
let atpPds = 'https://example.com'
···
42
-
it('registers a did', async () => {
43
-
did = await client.create(
45
-
signingKey: signingKey.did(),
46
-
rotationKeys: [rotationKey1.did(), rotationKey2.did()],
41
+
const verifyDoc = (doc: plc.DocumentData | null) => {
43
+
throw new Error('expected doc')
45
+
expect(doc.did).toEqual(did)
46
+
expect(doc.verificationMethods).toEqual({ atproto: signingKey.did() })
47
+
expect(doc.rotationKeys).toEqual([rotationKey1.did(), rotationKey2.did()])
48
+
expect(doc.alsoKnownAs).toEqual([handle])
49
+
expect(doc.services).toEqual({
51
+
type: 'AtprotoPersonalDataServer',
57
+
it('registers a did', async () => {
58
+
did = await client.createDid({
59
+
signingKey: signingKey.did(),
60
+
rotationKeys: [rotationKey1.did(), rotationKey2.did()],
63
+
signer: rotationKey1,
it('retrieves did doc data', async () => {
const doc = await client.getDocumentData(did)
58
-
expect(doc.did).toEqual(did)
59
-
expect(doc.signingKey).toEqual(signingKey.did())
60
-
expect(doc.rotationKeys).toEqual([rotationKey1.did(), rotationKey2.did()])
61
-
expect(doc.handles).toEqual([handle])
62
-
expect(doc.services).toEqual({ atpPds })
it('can perform some updates', async () => {
const newRotationKey = await EcdsaKeypair.create()
signingKey = await EcdsaKeypair.create()
68
-
handle = 'ali.example2.com'
69
-
atpPds = 'example2.com'
75
+
handle = 'at://ali.example2.com'
76
+
atpPds = 'https://example2.com'
71
-
await client.applyPartialOp(
73
-
{ signingKey: signingKey.did() },
77
-
await client.applyPartialOp(
79
-
{ rotationKeys: [newRotationKey.did(), rotationKey2.did()] },
78
+
await client.updateAtprotoKey(did, rotationKey1, signingKey.did())
79
+
await client.updateRotationKeys(did, rotationKey1, [
80
+
newRotationKey.did(),
rotationKey1 = newRotationKey
84
-
await client.applyPartialOp(did, { handles: [handle] }, rotationKey1)
85
-
await client.applyPartialOp(did, { services: { atpPds } }, rotationKey1)
85
+
await client.updateHandle(did, rotationKey1, handle)
86
+
await client.updatePds(did, rotationKey1, atpPds)
const doc = await client.getDocumentData(did)
88
-
expect(doc.did).toEqual(did)
89
-
expect(doc.signingKey).toEqual(signingKey.did())
90
-
expect(doc.rotationKeys).toEqual([rotationKey1.did(), rotationKey2.did()])
91
-
expect(doc.handles).toEqual([handle])
92
-
expect(doc.services).toEqual({ atpPds })
it('does not allow key types that we do not support', async () => {
···
'did:key:z6MkjwbBXZnFqL8su24wGL2Fdjti6GSLv9SWdYGswfazUPm9'
100
-
const promise = client.applyPartialOp(
102
-
{ signingKey: newSigningKey },
97
+
const promise = client.updateAtprotoKey(did, rotationKey1, newSigningKey)
await expect(promise).rejects.toThrow(AxiosError)
100
+
const promise2 = client.updateRotationKeys(did, rotationKey1, [
103
+
await expect(promise2).rejects.toThrow(AxiosError)
it('retrieves the operation log', async () => {
···
it('rejects on bad updates', async () => {
const newKey = await EcdsaKeypair.create()
117
-
const operation = client.applyPartialOp(
119
-
{ signingKey: newKey.did() },
115
+
const operation = client.updateAtprotoKey(did, newKey, newKey.did())
await expect(operation).rejects.toThrow()
it('allows for recovery through a forked history', async () => {
const attackerKey = await EcdsaKeypair.create()
127
-
await client.applyPartialOp(
129
-
{ signingKey: attackerKey.did(), rotationKeys: [attackerKey.did()] },
121
+
await client.updateRotationKeys(did, rotationKey2, [attackerKey.did()])
const newKey = await EcdsaKeypair.create()
const ops = await client.getOperationLog(did)
···
if (!check.is(forkPoint, plc.def.operation)) {
throw new Error('Could not find fork point')
139
-
const forkCid = await cidForCbor(forkPoint)
140
-
const op = await signOperation(
142
-
signingKey: signingKey.did(),
143
-
rotationKeys: [newKey.did()],
144
-
handles: forkPoint.handles,
145
-
services: forkPoint.services,
146
-
prev: forkCid.toString(),
129
+
const op = await plc.updateRotationKeysOp(forkPoint, rotationKey1, [
130
+
rotationKey1.did(),
await client.sendOperation(did, op)
152
-
rotationKey1 = newKey
135
+
rotationKey2 = newKey
const doc = await client.getDocumentData(did)
155
-
expect(doc.did).toEqual(did)
156
-
expect(doc.signingKey).toEqual(signingKey.did())
157
-
expect(doc.rotationKeys).toEqual([newKey.did()])
158
-
expect(doc.handles).toEqual([handle])
159
-
expect(doc.services).toEqual({ atpPds })
it('retrieves the auditable operation log', async () => {
···
keys.map(async (key, index) => {
188
-
await client.create(
190
-
signingKey: key.did(),
191
-
rotationKeys: [key.did()],
192
-
handles: [`user${index}`],
194
-
atpPds: `example.com`,
167
+
await client.createDid({
168
+
signingKey: key.did(),
169
+
rotationKeys: [key.did()],
170
+
handle: `user${index}`,
171
+
pds: `example.com`,
···
keys.map(async (key) => {
216
-
await client.applyPartialOp(
218
-
{ signingKey: key.did() },
191
+
await client.updateAtprotoKey(did, rotationKey1, key.did())