···
import { EcdsaKeypair } from '@atproto/crypto'
import * as plc from '@did-plc/lib'
import { CloseFn, runTestServer } from './_util'
-
import { check, cidForCbor } from '@atproto/common'
import { AxiosError } from 'axios'
import { Database } from '../src'
-
import { signOperation } from '@did-plc/lib'
describe('PLC server', () => {
-
let handle = 'alice.example.com'
-
let atpPds = 'example.com'
···
-
it('registers a did', async () => {
-
did = await client.create(
-
signingKey: signingKey.did(),
-
rotationKeys: [rotationKey1.did(), rotationKey2.did()],
it('retrieves did doc data', async () => {
const doc = await client.getDocumentData(did)
-
expect(doc.did).toEqual(did)
-
expect(doc.signingKey).toEqual(signingKey.did())
-
expect(doc.rotationKeys).toEqual([rotationKey1.did(), rotationKey2.did()])
-
expect(doc.handles).toEqual([handle])
-
expect(doc.services).toEqual({ atpPds })
it('can perform some updates', async () => {
const newRotationKey = await EcdsaKeypair.create()
signingKey = await EcdsaKeypair.create()
-
handle = 'ali.example2.com'
-
atpPds = 'example2.com'
-
await client.applyPartialOp(
-
{ signingKey: signingKey.did() },
-
await client.applyPartialOp(
-
{ rotationKeys: [newRotationKey.did(), rotationKey2.did()] },
rotationKey1 = newRotationKey
-
await client.applyPartialOp(did, { handles: [handle] }, rotationKey1)
-
await client.applyPartialOp(did, { services: { atpPds } }, rotationKey1)
const doc = await client.getDocumentData(did)
-
expect(doc.did).toEqual(did)
-
expect(doc.signingKey).toEqual(signingKey.did())
-
expect(doc.rotationKeys).toEqual([rotationKey1.did(), rotationKey2.did()])
-
expect(doc.handles).toEqual([handle])
-
expect(doc.services).toEqual({ atpPds })
it('does not allow key types that we do not support', async () => {
···
'did:key:z6MkjwbBXZnFqL8su24wGL2Fdjti6GSLv9SWdYGswfazUPm9'
-
const promise = client.applyPartialOp(
-
{ signingKey: newSigningKey },
await expect(promise).rejects.toThrow(AxiosError)
it('retrieves the operation log', async () => {
···
it('rejects on bad updates', async () => {
const newKey = await EcdsaKeypair.create()
-
const operation = client.applyPartialOp(
-
{ signingKey: newKey.did() },
await expect(operation).rejects.toThrow()
it('allows for recovery through a forked history', async () => {
const attackerKey = await EcdsaKeypair.create()
-
await client.applyPartialOp(
-
{ signingKey: attackerKey.did(), rotationKeys: [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')
-
const forkCid = await cidForCbor(forkPoint)
-
const op = await signOperation(
-
signingKey: signingKey.did(),
-
rotationKeys: [newKey.did()],
-
handles: forkPoint.handles,
-
services: forkPoint.services,
-
prev: forkCid.toString(),
await client.sendOperation(did, op)
const doc = await client.getDocumentData(did)
-
expect(doc.did).toEqual(did)
-
expect(doc.signingKey).toEqual(signingKey.did())
-
expect(doc.rotationKeys).toEqual([newKey.did()])
-
expect(doc.handles).toEqual([handle])
-
expect(doc.services).toEqual({ atpPds })
it('retrieves the auditable operation log', async () => {
···
keys.map(async (key, index) => {
-
rotationKeys: [key.did()],
-
handles: [`user${index}`],
···
keys.map(async (key) => {
-
await client.applyPartialOp(
-
{ signingKey: key.did() },
···
import { EcdsaKeypair } from '@atproto/crypto'
import * as plc from '@did-plc/lib'
import { CloseFn, runTestServer } from './_util'
+
import { check } from '@atproto/common'
import { AxiosError } from 'axios'
import { Database } from '../src'
describe('PLC server', () => {
+
let handle = 'at://alice.example.com'
+
let atpPds = 'https://example.com'
···
+
const verifyDoc = (doc: plc.DocumentData | null) => {
+
throw new Error('expected doc')
+
expect(doc.did).toEqual(did)
+
expect(doc.verificationMethods).toEqual({ atproto: signingKey.did() })
+
expect(doc.rotationKeys).toEqual([rotationKey1.did(), rotationKey2.did()])
+
expect(doc.alsoKnownAs).toEqual([handle])
+
expect(doc.services).toEqual({
+
type: 'AtprotoPersonalDataServer',
+
it('registers a did', async () => {
+
did = await client.createDid({
+
signingKey: signingKey.did(),
+
rotationKeys: [rotationKey1.did(), rotationKey2.did()],
it('retrieves did doc data', async () => {
const doc = await client.getDocumentData(did)
it('can perform some updates', async () => {
const newRotationKey = await EcdsaKeypair.create()
signingKey = await EcdsaKeypair.create()
+
handle = 'at://ali.example2.com'
+
atpPds = 'https://example2.com'
+
await client.updateAtprotoKey(did, rotationKey1, signingKey.did())
+
await client.updateRotationKeys(did, rotationKey1, [
rotationKey1 = newRotationKey
+
await client.updateHandle(did, rotationKey1, handle)
+
await client.updatePds(did, rotationKey1, atpPds)
const doc = await client.getDocumentData(did)
it('does not allow key types that we do not support', async () => {
···
'did:key:z6MkjwbBXZnFqL8su24wGL2Fdjti6GSLv9SWdYGswfazUPm9'
+
const promise = client.updateAtprotoKey(did, rotationKey1, newSigningKey)
await expect(promise).rejects.toThrow(AxiosError)
+
const promise2 = client.updateRotationKeys(did, rotationKey1, [
+
await expect(promise2).rejects.toThrow(AxiosError)
it('retrieves the operation log', async () => {
···
it('rejects on bad updates', async () => {
const newKey = await EcdsaKeypair.create()
+
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()
+
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')
+
const op = await plc.updateRotationKeysOp(forkPoint, rotationKey1, [
await client.sendOperation(did, op)
const doc = await client.getDocumentData(did)
it('retrieves the auditable operation log', async () => {
···
keys.map(async (key, index) => {
+
await client.createDid({
+
rotationKeys: [key.did()],
+
handle: `user${index}`,
···
keys.map(async (key) => {
+
await client.updateAtprotoKey(did, rotationKey1, key.did())