···
1
-
import { EcdsaKeypair, Secp256k1Keypair } from '@atproto/crypto'
2
-
import { deprecatedSignCreate, normalizeOp } from '../src'
1
+
import { cidForCbor, DAY } from '@atproto/common'
2
+
import { Secp256k1Keypair } from '@atproto/crypto'
6
+
deprecatedSignCreate,
10
+
validateOperationLog,
describe('compatibility', () => {
14
+
let signingKey: Secp256k1Keypair
15
+
let recoveryKey: Secp256k1Keypair
16
+
const handle = 'alice.test'
17
+
const service = 'https://example.com'
20
+
let legacyOp: CreateOpV1
22
+
beforeAll(async () => {
23
+
signingKey = await Secp256k1Keypair.create()
24
+
recoveryKey = await Secp256k1Keypair.create()
it('normalizes legacy create ops', async () => {
6
-
const signingKey = await Secp256k1Keypair.create()
7
-
const recoveryKey = await EcdsaKeypair.create()
8
-
const handle = 'alice.test'
9
-
const service = 'https://example.com'
10
-
const legacy = await deprecatedSignCreate(
28
+
legacyOp = await deprecatedSignCreate(
signingKey: signingKey.did(),
···
22
-
const normalized = normalizeOp(legacy)
40
+
did = await didForCreateOp(legacyOp)
42
+
const normalized = normalizeOp(legacyOp)
expect(normalized).toEqual({
signingKey: signingKey.did(),
rotationKeys: [recoveryKey.did(), signingKey.did()],
···
55
+
it('validates a log with a legacy create op', async () => {
56
+
const legacyCid = await cidForCbor(legacyOp)
57
+
const newSigner = await Secp256k1Keypair.create()
58
+
const newRotater = await Secp256k1Keypair.create()
59
+
const nextOp = await signOperation(
61
+
signingKey: newSigner.did(),
62
+
rotationKeys: [newRotater.did()],
64
+
services: { atpPds: service },
65
+
prev: legacyCid.toString(),
69
+
await validateOperationLog(did, [legacyOp, nextOp])
71
+
const indexedLegacy = {
73
+
operation: legacyOp,
76
+
createdAt: new Date(Date.now() - 7 * DAY),
79
+
const result = await assureValidNextOp(did, [indexedLegacy], nextOp)
80
+
expect(result.nullified.length).toBe(0)
81
+
expect(result.prev?.equals(legacyCid))