Fork of github.com/did-method-plc/did-method-plc

compatibility tests

dholms b0a55dab 7ed6378a

Changed files
+60 -11
packages
+2 -2
packages/lib/src/data.ts
···
export const validateOperationLog = async (
did: string,
-
ops: (t.CreateOpV1 | t.Operation)[],
+
ops: t.CompatibleOp[],
): Promise<t.DocumentData> => {
// make sure they're all validly formatted operations
const [first, ...rest] = ops
···
export const assureValidSig = async (
allowedDids: string[],
-
op: t.CreateOpV1 | t.Operation,
+
op: t.CompatibleOp,
): Promise<string> => {
const { sig, ...opData } = op
const sigBytes = uint8arrays.fromString(sig, 'base64url')
+58 -9
packages/lib/tests/compatibility.test.ts
···
-
import { EcdsaKeypair, Secp256k1Keypair } from '@atproto/crypto'
-
import { deprecatedSignCreate, normalizeOp } from '../src'
+
import { cidForCbor, DAY } from '@atproto/common'
+
import { Secp256k1Keypair } from '@atproto/crypto'
+
import {
+
assureValidNextOp,
+
CreateOpV1,
+
deprecatedSignCreate,
+
didForCreateOp,
+
normalizeOp,
+
signOperation,
+
validateOperationLog,
+
} from '../src'
describe('compatibility', () => {
+
let signingKey: Secp256k1Keypair
+
let recoveryKey: Secp256k1Keypair
+
const handle = 'alice.test'
+
const service = 'https://example.com'
+
let did: string
+
+
let legacyOp: CreateOpV1
+
+
beforeAll(async () => {
+
signingKey = await Secp256k1Keypair.create()
+
recoveryKey = await Secp256k1Keypair.create()
+
})
+
it('normalizes legacy create ops', async () => {
-
const signingKey = await Secp256k1Keypair.create()
-
const recoveryKey = await EcdsaKeypair.create()
-
const handle = 'alice.test'
-
const service = 'https://example.com'
-
const legacy = await deprecatedSignCreate(
+
legacyOp = await deprecatedSignCreate(
{
type: 'create',
signingKey: signingKey.did(),
···
signingKey,
)
-
const normalized = normalizeOp(legacy)
+
did = await didForCreateOp(legacyOp)
+
+
const normalized = normalizeOp(legacyOp)
expect(normalized).toEqual({
signingKey: signingKey.did(),
rotationKeys: [recoveryKey.did(), signingKey.did()],
···
atpPds: service,
},
prev: null,
-
sig: legacy.sig,
+
sig: legacyOp.sig,
})
+
})
+
+
it('validates a log with a legacy create op', async () => {
+
const legacyCid = await cidForCbor(legacyOp)
+
const newSigner = await Secp256k1Keypair.create()
+
const newRotater = await Secp256k1Keypair.create()
+
const nextOp = await signOperation(
+
{
+
signingKey: newSigner.did(),
+
rotationKeys: [newRotater.did()],
+
handles: [handle],
+
services: { atpPds: service },
+
prev: legacyCid.toString(),
+
},
+
signingKey,
+
)
+
await validateOperationLog(did, [legacyOp, nextOp])
+
+
const indexedLegacy = {
+
did,
+
operation: legacyOp,
+
cid: legacyCid,
+
nullified: false,
+
createdAt: new Date(Date.now() - 7 * DAY),
+
}
+
+
const result = await assureValidNextOp(did, [indexedLegacy], nextOp)
+
expect(result.nullified.length).toBe(0)
+
expect(result.prev?.equals(legacyCid))
})
})