···
-
import { check, cidForCbor, DAY, HOUR } from '@atproto/common'
import { EcdsaKeypair, Keypair, Secp256k1Keypair } from '@atproto/crypto'
-
import { create } from 'domain'
import { CID } from 'multiformats/cid'
-
ImproperOperationError,
-
MisorderedOperationError,
import * as data from '../src/data'
import * as operations from '../src/operations'
import * as t from '../src/types'
···
let rotationKey2: EcdsaKeypair
let rotationKey3: EcdsaKeypair
-
let handle = 'alice.example.com'
-
let atpPds = 'https://example.com'
let log: t.IndexedOperation[] = []
-
const key3AttackCids: CID[] = []
-
const key2AttackCid: CID[] = []
signingKey = await Secp256k1Keypair.create()
···
await expect(data.assureValidNextOp(did, log, rotate.op)).rejects.toThrow(
···
+
import { cidForCbor, DAY, HOUR } from '@atproto/common'
import { EcdsaKeypair, Keypair, Secp256k1Keypair } from '@atproto/crypto'
import { CID } from 'multiformats/cid'
+
import { InvalidSignatureError, LateRecoveryError } from '../src'
import * as data from '../src/data'
import * as operations from '../src/operations'
import * as t from '../src/types'
···
let rotationKey2: EcdsaKeypair
let rotationKey3: EcdsaKeypair
+
const handle = 'alice.example.com'
+
const atpPds = 'https://example.com'
let log: t.IndexedOperation[] = []
signingKey = await Secp256k1Keypair.create()
···
await expect(data.assureValidNextOp(did, log, rotate.op)).rejects.toThrow(
+
it('allows a rotation key with even higher authority to rewrite history', async () => {
+
const rotate = await signOpForKeys([rotationKey1], createCid, rotationKey1)
+
const res = await data.assureValidNextOp(did, log, rotate.op)
+
expect(res.nullified.length).toBe(1)
+
expect(res.nullified[0].equals(log[1].cid))
+
expect(res.prev?.equals(createCid))
+
log = [log[0], rotate.indexed]
+
it('does not allow the either invalidated key to take control back', async () => {
+
const rotate1 = await signOpForKeys([rotationKey3], createCid, rotationKey3)
+
await expect(data.assureValidNextOp(did, log, rotate1.op)).rejects.toThrow(
+
const rotate2 = await signOpForKeys([rotationKey2], createCid, rotationKey2)
+
await expect(data.assureValidNextOp(did, log, rotate2.op)).rejects.toThrow(
+
it('does not allow recovery outside of 72 hrs', async () => {
+
const rotate = await signOpForKeys([rotationKey3], createCid, rotationKey3)
+
createdAt: new Date(Date.now() - 4 * DAY),
+
const rotateBack = await signOpForKeys(
+
data.assureValidNextOp(did, timeOutOps, rotateBack.op),
+
).rejects.toThrow(LateRecoveryError)