···
-
import { EcdsaKeypair, Secp256k1Keypair } from '@atproto/crypto'
-
import { deprecatedSignCreate, normalizeOp } from '../src'
describe('compatibility', () => {
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(
signingKey: signingKey.did(),
···
-
const normalized = normalizeOp(legacy)
expect(normalized).toEqual({
signingKey: signingKey.did(),
rotationKeys: [recoveryKey.did(), signingKey.did()],
···
···
+
import { cidForCbor, DAY } from '@atproto/common'
+
import { Secp256k1Keypair } from '@atproto/crypto'
describe('compatibility', () => {
+
let signingKey: Secp256k1Keypair
+
let recoveryKey: Secp256k1Keypair
+
const handle = 'alice.test'
+
const service = 'https://example.com'
+
let legacyOp: CreateOpV1
+
beforeAll(async () => {
+
signingKey = await Secp256k1Keypair.create()
+
recoveryKey = await Secp256k1Keypair.create()
it('normalizes legacy create ops', async () => {
+
legacyOp = await deprecatedSignCreate(
signingKey: signingKey.did(),
···
+
did = await didForCreateOp(legacyOp)
+
const normalized = normalizeOp(legacyOp)
expect(normalized).toEqual({
signingKey: signingKey.did(),
rotationKeys: [recoveryKey.did(), signingKey.did()],
···
+
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()],
+
services: { atpPds: service },
+
prev: legacyCid.toString(),
+
await validateOperationLog(did, [legacyOp, nextOp])
+
const indexedLegacy = {
+
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))