@atproto/lexicon-resolver 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/LICENSE.txt +7 -0
- package/README.md +79 -0
- package/dist/client/index.d.ts +28 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +118 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/lexicons.d.ts +105 -0
- package/dist/client/lexicons.d.ts.map +1 -0
- package/dist/client/lexicons.js +75 -0
- package/dist/client/lexicons.js.map +1 -0
- package/dist/client/types/com/atproto/sync/getRecord.d.ts +38 -0
- package/dist/client/types/com/atproto/sync/getRecord.d.ts.map +1 -0
- package/dist/client/types/com/atproto/sync/getRecord.js +58 -0
- package/dist/client/types/com/atproto/sync/getRecord.js.map +1 -0
- package/dist/client/util.d.ts +37 -0
- package/dist/client/util.d.ts.map +1 -0
- package/dist/client/util.js +38 -0
- package/dist/client/util.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/lexicon.d.ts +43 -0
- package/dist/lexicon.d.ts.map +1 -0
- package/dist/lexicon.js +98 -0
- package/dist/lexicon.js.map +1 -0
- package/dist/record.d.ts +37 -0
- package/dist/record.d.ts.map +1 -0
- package/dist/record.js +100 -0
- package/dist/record.js.map +1 -0
- package/dist/util.d.ts +2 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +14 -0
- package/dist/util.js.map +1 -0
- package/jest.config.js +7 -0
- package/package.json +46 -0
- package/src/client/index.ts +67 -0
- package/src/client/lexicons.ts +98 -0
- package/src/client/types/com/atproto/sync/getRecord.ts +78 -0
- package/src/client/util.ts +82 -0
- package/src/index.ts +2 -0
- package/src/lexicon.ts +147 -0
- package/src/record.ts +156 -0
- package/src/util.ts +10 -0
- package/tests/lexicon.test.ts +266 -0
- package/tests/record.test.ts +98 -0
- package/tsconfig.build.json +9 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.json +7 -0
- package/tsconfig.tests.json +8 -0
- package/tsconfig.tests.tsbuildinfo +1 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { dataToCborBlock } from '@atproto/common'
|
|
2
|
+
import { SeedClient, TestNetworkNoAppView, usersSeed } from '@atproto/dev-env'
|
|
3
|
+
import { AtprotoRecordResolver, buildRecordResolver } from '../src/index.js'
|
|
4
|
+
|
|
5
|
+
describe('Record resolution', () => {
|
|
6
|
+
let network: TestNetworkNoAppView
|
|
7
|
+
let sc: SeedClient
|
|
8
|
+
let resolveRecord: AtprotoRecordResolver
|
|
9
|
+
|
|
10
|
+
beforeAll(async () => {
|
|
11
|
+
network = await TestNetworkNoAppView.create({
|
|
12
|
+
dbPostgresSchema: 'lex_record_resolution',
|
|
13
|
+
})
|
|
14
|
+
sc = network.getSeedClient()
|
|
15
|
+
await usersSeed(sc)
|
|
16
|
+
resolveRecord = buildRecordResolver({
|
|
17
|
+
rpc: { fetch },
|
|
18
|
+
idResolver: network.pds.ctx.idResolver,
|
|
19
|
+
})
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
afterAll(async () => {
|
|
23
|
+
await network.close()
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('resolves record by AT-URI object.', async () => {
|
|
27
|
+
const post = await sc.post(sc.dids.alice, 'post1')
|
|
28
|
+
const result = await resolveRecord(post.ref.uri, {
|
|
29
|
+
forceRefresh: true,
|
|
30
|
+
})
|
|
31
|
+
expect(result.commit.did).toEqual(sc.dids.alice)
|
|
32
|
+
expect(result.cid.toString()).toEqual(post.ref.cidStr)
|
|
33
|
+
expect(result.uri.toString()).toEqual(post.ref.uriStr)
|
|
34
|
+
expect(result.record.text).toEqual('post1')
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('resolves record by AT-URI string.', async () => {
|
|
38
|
+
const post = await sc.post(sc.dids.alice, 'post2')
|
|
39
|
+
const result = await resolveRecord(post.ref.uriStr, {
|
|
40
|
+
forceRefresh: true,
|
|
41
|
+
})
|
|
42
|
+
expect(result.commit.did).toEqual(sc.dids.alice)
|
|
43
|
+
expect(result.cid.toString()).toEqual(post.ref.cidStr)
|
|
44
|
+
expect(result.uri.toString()).toEqual(post.ref.uriStr)
|
|
45
|
+
expect(result.record.text).toEqual('post2')
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it("does not resolve record that doesn't exist.", async () => {
|
|
49
|
+
await expect(
|
|
50
|
+
resolveRecord(`at://${sc.dids.alice}/app.bsky.feed.post/2222222222222`, {
|
|
51
|
+
forceRefresh: true,
|
|
52
|
+
}),
|
|
53
|
+
).rejects.toThrow('Record not found')
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it('does not resolve record with bad commit signature.', async () => {
|
|
57
|
+
const alicekey = await network.pds.ctx.actorStore.keypair(sc.dids.alice)
|
|
58
|
+
const bobkey = await network.pds.ctx.actorStore.keypair(sc.dids.bob)
|
|
59
|
+
const post = await sc.post(sc.dids.alice, 'post3')
|
|
60
|
+
// switch alice's key away from the one used by her pds
|
|
61
|
+
await network.pds.ctx.plcClient.updateAtprotoKey(
|
|
62
|
+
sc.dids.alice,
|
|
63
|
+
network.pds.ctx.plcRotationKey,
|
|
64
|
+
bobkey.did(),
|
|
65
|
+
)
|
|
66
|
+
await expect(
|
|
67
|
+
resolveRecord(post.ref.uri, {
|
|
68
|
+
forceRefresh: true,
|
|
69
|
+
}),
|
|
70
|
+
).rejects.toThrow('Invalid signature on commit')
|
|
71
|
+
// reset alice's key
|
|
72
|
+
await network.pds.ctx.plcClient.updateAtprotoKey(
|
|
73
|
+
sc.dids.alice,
|
|
74
|
+
network.pds.ctx.plcRotationKey,
|
|
75
|
+
alicekey.did(),
|
|
76
|
+
)
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
it('does not resolve record with corrupted CAR block.', async () => {
|
|
80
|
+
const post = await sc.post(sc.dids.alice, 'post4')
|
|
81
|
+
const badBlock = await dataToCborBlock({})
|
|
82
|
+
await network.pds.ctx.actorStore.transact(sc.dids.alice, (txn) =>
|
|
83
|
+
txn.repo.db.db
|
|
84
|
+
.updateTable('repo_block')
|
|
85
|
+
.set({
|
|
86
|
+
content: badBlock.bytes,
|
|
87
|
+
size: badBlock.bytes.byteLength,
|
|
88
|
+
})
|
|
89
|
+
.where('cid', '=', post.ref.cidStr)
|
|
90
|
+
.execute(),
|
|
91
|
+
)
|
|
92
|
+
await expect(
|
|
93
|
+
resolveRecord(post.ref.uri, {
|
|
94
|
+
forceRefresh: true,
|
|
95
|
+
}),
|
|
96
|
+
).rejects.toThrow('Malformed record proof')
|
|
97
|
+
})
|
|
98
|
+
})
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["./src/index.ts","./src/lexicon.ts","./src/record.ts","./src/util.ts","./src/client/index.ts","./src/client/lexicons.ts","./src/client/util.ts","./src/client/types/com/atproto/sync/getRecord.ts"],"version":"5.8.3"}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["./tests/lexicon.test.ts","./tests/record.test.ts"],"version":"5.8.3"}
|