···
1
-
import { check, cidForCbor, DAY, HOUR } from '@atproto/common'
1
+
import { cidForCbor, DAY, HOUR } from '@atproto/common'
import { EcdsaKeypair, Keypair, Secp256k1Keypair } from '@atproto/crypto'
3
-
import { create } from 'domain'
import { CID } from 'multiformats/cid'
7
-
ImproperOperationError,
8
-
InvalidSignatureError,
9
-
MisorderedOperationError,
4
+
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
21
-
let handle = 'alice.example.com'
22
-
let atpPds = 'https://example.com'
15
+
const handle = 'alice.example.com'
16
+
const atpPds = 'https://example.com'
let log: t.IndexedOperation[] = []
27
-
const key3AttackCids: CID[] = []
28
-
const key2AttackCid: CID[] = []
signingKey = await Secp256k1Keypair.create()
···
await expect(data.assureValidNextOp(did, log, rotate.op)).rejects.toThrow(
116
+
it('allows a rotation key with even higher authority to rewrite history', async () => {
117
+
const rotate = await signOpForKeys([rotationKey1], createCid, rotationKey1)
119
+
const res = await data.assureValidNextOp(did, log, rotate.op)
120
+
expect(res.nullified.length).toBe(1)
121
+
expect(res.nullified[0].equals(log[1].cid))
122
+
expect(res.prev?.equals(createCid))
124
+
log = [log[0], rotate.indexed]
127
+
it('does not allow the either invalidated key to take control back', async () => {
128
+
const rotate1 = await signOpForKeys([rotationKey3], createCid, rotationKey3)
129
+
await expect(data.assureValidNextOp(did, log, rotate1.op)).rejects.toThrow(
130
+
InvalidSignatureError,
133
+
const rotate2 = await signOpForKeys([rotationKey2], createCid, rotationKey2)
134
+
await expect(data.assureValidNextOp(did, log, rotate2.op)).rejects.toThrow(
135
+
InvalidSignatureError,
139
+
it('does not allow recovery outside of 72 hrs', async () => {
140
+
const rotate = await signOpForKeys([rotationKey3], createCid, rotationKey3)
141
+
const timeOutOps = [
145
+
createdAt: new Date(Date.now() - 4 * DAY),
148
+
const rotateBack = await signOpForKeys(
154
+
data.assureValidNextOp(did, timeOutOps, rotateBack.op),
155
+
).rejects.toThrow(LateRecoveryError)