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

Configure Feed

Select the types of activity you want to include in your feed.

allow create v1s still

dholms 650c7520 254f179d

+30 -6
+7 -2
packages/lib/src/data.ts
··· 16 16 export const assureValidNextOp = async ( 17 17 did: string, 18 18 ops: t.IndexedOperation[], 19 - proposed: t.OpOrTombstone, 19 + proposed: t.CompatibleOpOrTombstone, 20 20 ): Promise<{ nullified: CID[]; prev: CID | null }> => { 21 - await assureValidOp(proposed) 21 + if (check.is(proposed, t.def.createOpV1)) { 22 + const normalized = normalizeOp(proposed) 23 + await assureValidOp(normalized) 24 + } else { 25 + await assureValidOp(proposed) 26 + } 22 27 23 28 // special case if account creation 24 29 if (ops.length === 0) {
+1 -1
packages/server/src/db/index.ts
··· 94 94 95 95 async validateAndAddOp( 96 96 did: string, 97 - proposed: plc.OpOrTombstone, 97 + proposed: plc.CompatibleOpOrTombstone, 98 98 ): Promise<void> { 99 99 const ops = await this.indexedOpsForDid(did) 100 100 // throws if invalid
+4 -1
packages/server/src/db/types.ts
··· 4 4 export interface PlcDatabase { 5 5 close(): Promise<void> 6 6 healthCheck(): Promise<void> 7 - validateAndAddOp(did: string, proposed: plc.OpOrTombstone): Promise<void> 7 + validateAndAddOp( 8 + did: string, 9 + proposed: plc.CompatibleOpOrTombstone, 10 + ): Promise<void> 8 11 opsForDid(did: string): Promise<plc.CompatibleOpOrTombstone[]> 9 12 indexedOpsForDid( 10 13 did: string,
+1 -1
packages/server/src/routes.ts
··· 109 109 router.post('/:did', async function (req, res) { 110 110 const { did } = req.params 111 111 const op = req.body 112 - if (!check.is(op, plc.def.opOrTombstone)) { 112 + if (!check.is(op, plc.def.compatibleOpOrTombstone)) { 113 113 throw new ServerError(400, `Not a valid operation: ${JSON.stringify(op)}`) 114 114 } 115 115 await ctx.db.validateAndAddOp(did, op)
+17 -1
packages/server/tests/server.test.ts
··· 3 3 import { CloseFn, runTestServer } from './_util' 4 4 import { check } from '@atproto/common' 5 5 import { Database } from '../src' 6 - import { PlcClientError } from '@did-plc/lib' 6 + import { didForCreateOp, PlcClientError } from '@did-plc/lib' 7 7 8 8 describe('PLC server', () => { 9 9 let handle = 'at://alice.example.com' ··· 218 218 for (let i = 1; i < data.length; i++) { 219 219 expect(data[i].createdAt >= data[i - 1].createdAt).toBeTruthy() 220 220 } 221 + }) 222 + 223 + it('still allows create v1s', async () => { 224 + const createV1 = await plc.deprecatedSignCreate( 225 + { 226 + type: 'create', 227 + signingKey: signingKey.did(), 228 + recoveryKey: rotationKey1.did(), 229 + handle, 230 + service: atpPds, 231 + prev: null, 232 + }, 233 + signingKey, 234 + ) 235 + const did = await didForCreateOp(createV1) 236 + await client.sendOperation(did, createV1 as any) 221 237 }) 222 238 223 239 it('healthcheck succeeds when database is available.', async () => {