@cheqd/sdk 2.1.0-develop.1 → 2.2.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.
Files changed (127) hide show
  1. package/README.md +33 -6
  2. package/build/{index.d.ts → cjs/index.d.ts} +8 -3
  3. package/build/cjs/index.d.ts.map +1 -0
  4. package/build/cjs/index.js +144 -0
  5. package/build/cjs/index.js.map +1 -0
  6. package/build/{modules → cjs/modules}/_.d.ts +1 -1
  7. package/build/cjs/modules/_.d.ts.map +1 -0
  8. package/build/{modules → cjs/modules}/_.js +3 -0
  9. package/build/cjs/modules/_.js.map +1 -0
  10. package/build/{modules → cjs/modules}/did.d.ts +4 -2
  11. package/build/cjs/modules/did.d.ts.map +1 -0
  12. package/build/{modules → cjs/modules}/did.js +42 -25
  13. package/build/cjs/modules/did.js.map +1 -0
  14. package/build/{modules → cjs/modules}/resource.d.ts +2 -2
  15. package/build/cjs/modules/resource.d.ts.map +1 -0
  16. package/build/{modules → cjs/modules}/resource.js +13 -5
  17. package/build/cjs/modules/resource.js.map +1 -0
  18. package/build/cjs/querier.d.ts.map +1 -0
  19. package/build/cjs/querier.js.map +1 -0
  20. package/build/cjs/registry.d.ts.map +1 -0
  21. package/build/cjs/registry.js.map +1 -0
  22. package/build/cjs/signer.d.ts.map +1 -0
  23. package/build/cjs/signer.js.map +1 -0
  24. package/build/{types.d.ts → cjs/types.d.ts} +1 -1
  25. package/build/cjs/types.d.ts.map +1 -0
  26. package/build/cjs/types.js.map +1 -0
  27. package/build/cjs/utils.d.ts.map +1 -0
  28. package/build/{utils.js → cjs/utils.js} +2 -5
  29. package/build/cjs/utils.js.map +1 -0
  30. package/build/types/index.d.ts +45 -0
  31. package/build/types/index.d.ts.map +1 -0
  32. package/build/types/modules/_.d.ts +20 -0
  33. package/build/types/modules/_.d.ts.map +1 -0
  34. package/build/types/modules/did.d.ts +109 -0
  35. package/build/types/modules/did.d.ts.map +1 -0
  36. package/build/types/modules/resource.d.ts +62 -0
  37. package/build/types/modules/resource.d.ts.map +1 -0
  38. package/build/types/querier.d.ts +11 -0
  39. package/build/types/querier.d.ts.map +1 -0
  40. package/build/types/registry.d.ts +4 -0
  41. package/build/types/registry.d.ts.map +1 -0
  42. package/build/types/signer.d.ts +36 -0
  43. package/build/types/signer.d.ts.map +1 -0
  44. package/build/types/types.d.ts +80 -0
  45. package/build/types/types.d.ts.map +1 -0
  46. package/build/types/utils.d.ts +18 -0
  47. package/build/types/utils.d.ts.map +1 -0
  48. package/package.json +48 -25
  49. package/.github/ISSUE_TEMPLATE/bug-report.yml +0 -74
  50. package/.github/ISSUE_TEMPLATE/config.yml +0 -14
  51. package/.github/ISSUE_TEMPLATE/feature-request.yaml +0 -27
  52. package/.github/dependabot.yml +0 -42
  53. package/.github/linters/.commitlint.rules.js +0 -37
  54. package/.github/linters/.eslintrc.json +0 -18
  55. package/.github/linters/.markdown-lint.yml +0 -139
  56. package/.github/linters/mlc_config.json +0 -13
  57. package/.github/workflows/build.yml +0 -30
  58. package/.github/workflows/cleanup-actions.yml +0 -45
  59. package/.github/workflows/cleanup-cache-automatic.yml +0 -24
  60. package/.github/workflows/cleanup-cache-manual.yml +0 -21
  61. package/.github/workflows/codeql.yml +0 -40
  62. package/.github/workflows/dispatch.yml +0 -30
  63. package/.github/workflows/lint.yml +0 -51
  64. package/.github/workflows/pull-request.yml +0 -33
  65. package/.github/workflows/release.yml +0 -42
  66. package/.github/workflows/test.yml +0 -66
  67. package/.releaserc.json +0 -56
  68. package/CHANGELOG.md +0 -256
  69. package/CODE_OF_CONDUCT.md +0 -81
  70. package/NOTICE.md +0 -10
  71. package/SECURITY.md +0 -12
  72. package/build/index.d.ts.map +0 -1
  73. package/build/index.js +0 -97
  74. package/build/index.js.map +0 -1
  75. package/build/modules/_.d.ts.map +0 -1
  76. package/build/modules/_.js.map +0 -1
  77. package/build/modules/did.d.ts.map +0 -1
  78. package/build/modules/did.js.map +0 -1
  79. package/build/modules/resource.d.ts.map +0 -1
  80. package/build/modules/resource.js.map +0 -1
  81. package/build/querier.d.ts.map +0 -1
  82. package/build/querier.js.map +0 -1
  83. package/build/registry.d.ts.map +0 -1
  84. package/build/registry.js.map +0 -1
  85. package/build/signer.d.ts.map +0 -1
  86. package/build/signer.js.map +0 -1
  87. package/build/types.d.ts.map +0 -1
  88. package/build/types.js.map +0 -1
  89. package/build/utils.d.ts.map +0 -1
  90. package/build/utils.js.map +0 -1
  91. package/docker/Dockerfile +0 -55
  92. package/docker/entrypoint.sh +0 -58
  93. package/docker/localnet/build-latest.env +0 -7
  94. package/docker/localnet/container-env/observer-0.env +0 -13
  95. package/docker/localnet/container-env/seed-0.env +0 -17
  96. package/docker/localnet/container-env/validator-0.env +0 -13
  97. package/docker/localnet/container-env/validator-1.env +0 -13
  98. package/docker/localnet/container-env/validator-2.env +0 -13
  99. package/docker/localnet/container-env/validator-3.env +0 -13
  100. package/docker/localnet/docker-compose.yml +0 -281
  101. package/docker/localnet/gen-network-config.sh +0 -259
  102. package/docker/localnet/import-keys.sh +0 -31
  103. package/jest.config.js +0 -6
  104. package/src/index.ts +0 -128
  105. package/src/modules/_.ts +0 -55
  106. package/src/modules/did.ts +0 -564
  107. package/src/modules/resource.ts +0 -213
  108. package/src/querier.ts +0 -33
  109. package/src/registry.ts +0 -15
  110. package/src/signer.ts +0 -258
  111. package/src/types.ts +0 -101
  112. package/src/utils.ts +0 -243
  113. package/tests/index.test.ts +0 -135
  114. package/tests/modules/did.test.ts +0 -965
  115. package/tests/modules/resource.test.ts +0 -785
  116. package/tests/signer.test.ts +0 -179
  117. package/tests/testutils.test.ts +0 -24
  118. package/tests/utils.test.ts +0 -66
  119. package/tsconfig.json +0 -80
  120. /package/build/{querier.d.ts → cjs/querier.d.ts} +0 -0
  121. /package/build/{querier.js → cjs/querier.js} +0 -0
  122. /package/build/{registry.d.ts → cjs/registry.d.ts} +0 -0
  123. /package/build/{registry.js → cjs/registry.js} +0 -0
  124. /package/build/{signer.d.ts → cjs/signer.d.ts} +0 -0
  125. /package/build/{signer.js → cjs/signer.js} +0 -0
  126. /package/build/{types.js → cjs/types.js} +0 -0
  127. /package/build/{utils.d.ts → cjs/utils.d.ts} +0 -0
@@ -1,785 +0,0 @@
1
- import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing"
2
- import { DeliverTxResponse } from "@cosmjs/stargate"
3
- import { fromString, toString } from 'uint8arrays'
4
- import { DIDModule, ResourceModule } from "../../src"
5
- import { createDefaultCheqdRegistry } from "../../src/registry"
6
- import { CheqdSigningStargateClient } from "../../src/signer"
7
- import { ISignInputs, MethodSpecificIdAlgo, QueryExtensionSetup, VerificationMethods, CheqdExtensions } from '../../src/types';
8
- import { createDidPayload, createDidVerificationMethod, createKeyPairBase64, createVerificationKeys } from "../../src/utils"
9
- import { localnet, faucet, image_content, default_content, json_content } from "../testutils.test"
10
- import { MsgCreateResourcePayload } from '@cheqd/ts-proto/cheqd/resource/v2';
11
- import { v4 } from "uuid"
12
- import { CheqdQuerier } from "../../src/querier"
13
- import { setupResourceExtension, ResourceExtension } from '../../src/modules/resource';
14
- import { DidExtension, setupDidExtension } from "../../src/modules/did"
15
- import { sha256 } from "@cosmjs/crypto"
16
-
17
- const defaultAsyncTxTimeout = 30000
18
-
19
- describe('ResourceModule', () => {
20
- describe('constructor', () => {
21
- it('should instantiate standalone module', async () => {
22
- const wallet = await DirectSecp256k1HdWallet.fromMnemonic(faucet.mnemonic)
23
- const signer = await CheqdSigningStargateClient.connectWithSigner(localnet.rpcUrl, wallet)
24
- const querier = await CheqdQuerier.connectWithExtension(localnet.rpcUrl, setupResourceExtension) as CheqdQuerier & ResourceExtension
25
- const resourceModule = new ResourceModule(signer, querier)
26
- expect(resourceModule).toBeInstanceOf(ResourceModule)
27
- })
28
- })
29
-
30
- describe('createLinkedResourceTx', () => {
31
- it('should create a new Resource - case: json', async () => {
32
- // create an associated did document
33
- const wallet = await DirectSecp256k1HdWallet.fromMnemonic(faucet.mnemonic, {prefix: faucet.prefix})
34
- const registry = createDefaultCheqdRegistry(Array.from(DIDModule.registryTypes).concat(Array.from(ResourceModule.registryTypes)))
35
- const signer = await CheqdSigningStargateClient.connectWithSigner(localnet.rpcUrl, wallet, { registry })
36
- const querier = await CheqdQuerier.connectWithExtensions(localnet.rpcUrl, ...[setupDidExtension, setupResourceExtension] as unknown as QueryExtensionSetup<CheqdExtensions>[])
37
- const didModule = new DIDModule(signer, querier as CheqdQuerier & DidExtension)
38
-
39
- const keyPair = createKeyPairBase64()
40
- const verificationKeys = createVerificationKeys(keyPair.publicKey, MethodSpecificIdAlgo.Base58, 'key-1')
41
- const verificationMethods = createDidVerificationMethod([VerificationMethods.Ed255192020], [verificationKeys])
42
- const didPayload = createDidPayload(verificationMethods, [verificationKeys])
43
-
44
- const signInputs: ISignInputs[] = [
45
- {
46
- verificationMethodId: didPayload.verificationMethod![0].id,
47
- privateKeyHex: toString(fromString(keyPair.privateKey, 'base64'), 'hex')
48
- }
49
- ]
50
-
51
- const feePayer = (await wallet.getAccounts())[0].address
52
- const fee = await DIDModule.generateCreateDidDocFees(feePayer)
53
- const didTx: DeliverTxResponse = await didModule.createDidDocTx(
54
- signInputs,
55
- didPayload,
56
- feePayer,
57
- fee
58
- )
59
-
60
- console.warn(`Using payload: ${JSON.stringify(didPayload)}`)
61
- console.warn(`DID Tx: ${JSON.stringify(didTx)}`)
62
-
63
- expect(didTx.code).toBe(0)
64
-
65
- // create a did linked resource
66
- const resourceModule = new ResourceModule(signer, querier as CheqdQuerier & ResourceExtension)
67
-
68
- const resourcePayload: MsgCreateResourcePayload = {
69
- collectionId: didPayload.id.split(":").reverse()[0],
70
- id: v4(),
71
- version: "1.0",
72
- alsoKnownAs: [],
73
- name: 'Test Resource',
74
- resourceType: 'test-resource-type',
75
- data: new TextEncoder().encode(json_content)
76
- }
77
-
78
- const resourceSignInputs: ISignInputs[] = [
79
- {
80
- verificationMethodId: didPayload.verificationMethod![0].id,
81
- keyType: 'Ed25519',
82
- privateKeyHex: toString(fromString(keyPair.privateKey, 'base64'), 'hex')
83
- }
84
- ]
85
-
86
- const feeResourceJson = await ResourceModule.generateCreateResourceJsonFees(feePayer)
87
- const resourceTx = await resourceModule.createLinkedResourceTx(
88
- resourceSignInputs,
89
- resourcePayload,
90
- feePayer,
91
- feeResourceJson
92
- )
93
-
94
- console.warn(`Using payload: ${JSON.stringify(resourcePayload)}`)
95
- console.warn(`Resource Tx: ${JSON.stringify(resourceTx)}`)
96
-
97
- expect(resourceTx.code).toBe(0)
98
- }, defaultAsyncTxTimeout)
99
-
100
- it('should create a new Resource - case: image', async () => {
101
- // create an associated did document
102
- const wallet = await DirectSecp256k1HdWallet.fromMnemonic(faucet.mnemonic, {prefix: faucet.prefix})
103
- const registry = createDefaultCheqdRegistry(Array.from(DIDModule.registryTypes).concat(Array.from(ResourceModule.registryTypes)))
104
- const signer = await CheqdSigningStargateClient.connectWithSigner(localnet.rpcUrl, wallet, { registry })
105
- const querier = await CheqdQuerier.connectWithExtensions(localnet.rpcUrl, ...[setupDidExtension, setupResourceExtension] as unknown as QueryExtensionSetup<CheqdExtensions>[])
106
- const didModule = new DIDModule(signer, querier as CheqdQuerier & DidExtension)
107
-
108
- const keyPair = createKeyPairBase64()
109
- const verificationKeys = createVerificationKeys(keyPair.publicKey, MethodSpecificIdAlgo.Base58, 'key-1')
110
- const verificationMethods = createDidVerificationMethod([VerificationMethods.Ed255192020], [verificationKeys])
111
- const didPayload = createDidPayload(verificationMethods, [verificationKeys])
112
-
113
- const signInputs: ISignInputs[] = [
114
- {
115
- verificationMethodId: didPayload.verificationMethod![0].id,
116
- privateKeyHex: toString(fromString(keyPair.privateKey, 'base64'), 'hex')
117
- }
118
- ]
119
-
120
- const feePayer = (await wallet.getAccounts())[0].address
121
- const fee = await DIDModule.generateCreateDidDocFees(feePayer)
122
- const didTx: DeliverTxResponse = await didModule.createDidDocTx(
123
- signInputs,
124
- didPayload,
125
- feePayer,
126
- fee
127
- )
128
-
129
- console.warn(`Using payload: ${JSON.stringify(didPayload)}`)
130
- console.warn(`DID Tx: ${JSON.stringify(didTx)}`)
131
-
132
- expect(didTx.code).toBe(0)
133
-
134
- // create a did linked resource
135
- const resourceModule = new ResourceModule(signer, querier as CheqdQuerier & ResourceExtension)
136
-
137
- const resourcePayload: MsgCreateResourcePayload = {
138
- collectionId: didPayload.id.split(":").reverse()[0],
139
- id: v4(),
140
- version: "1.0",
141
- alsoKnownAs: [],
142
- name: 'Test Resource',
143
- resourceType: 'test-resource-type',
144
- data: fromString(image_content, 'base64')
145
- }
146
-
147
- const resourceSignInputs: ISignInputs[] = [
148
- {
149
- verificationMethodId: didPayload.verificationMethod![0].id,
150
- keyType: 'Ed25519',
151
- privateKeyHex: toString(fromString(keyPair.privateKey, 'base64'), 'hex')
152
- }
153
- ]
154
-
155
- const feeResourceImage = await ResourceModule.generateCreateResourceImageFees(feePayer)
156
- const resourceTx = await resourceModule.createLinkedResourceTx(
157
- resourceSignInputs,
158
- resourcePayload,
159
- feePayer,
160
- feeResourceImage
161
- )
162
-
163
- console.warn(`Using payload: ${JSON.stringify(resourcePayload)}`)
164
- console.warn(`Resource Tx: ${JSON.stringify(resourceTx)}`)
165
-
166
- expect(resourceTx.code).toBe(0)
167
- }, defaultAsyncTxTimeout)
168
-
169
- it('should create a new Resource - case: default', async () => {
170
- // create an associated did document
171
- const wallet = await DirectSecp256k1HdWallet.fromMnemonic(faucet.mnemonic, {prefix: faucet.prefix})
172
- const registry = createDefaultCheqdRegistry(Array.from(DIDModule.registryTypes).concat(Array.from(ResourceModule.registryTypes)))
173
- const signer = await CheqdSigningStargateClient.connectWithSigner(localnet.rpcUrl, wallet, { registry })
174
- const querier = await CheqdQuerier.connectWithExtensions(localnet.rpcUrl, ...[setupDidExtension, setupResourceExtension] as unknown as QueryExtensionSetup<CheqdExtensions>[])
175
- const didModule = new DIDModule(signer, querier as CheqdQuerier & DidExtension)
176
-
177
- const keyPair = createKeyPairBase64()
178
- const verificationKeys = createVerificationKeys(keyPair.publicKey, MethodSpecificIdAlgo.Base58, 'key-1')
179
- const verificationMethods = createDidVerificationMethod([VerificationMethods.Ed255192020], [verificationKeys])
180
- const didPayload = createDidPayload(verificationMethods, [verificationKeys])
181
-
182
- const signInputs: ISignInputs[] = [
183
- {
184
- verificationMethodId: didPayload.verificationMethod![0].id,
185
- privateKeyHex: toString(fromString(keyPair.privateKey, 'base64'), 'hex')
186
- }
187
- ]
188
-
189
- const feePayer = (await wallet.getAccounts())[0].address
190
- const fee = await DIDModule.generateCreateDidDocFees(feePayer)
191
- const didTx: DeliverTxResponse = await didModule.createDidDocTx(
192
- signInputs,
193
- didPayload,
194
- feePayer,
195
- fee
196
- )
197
-
198
- console.warn(`Using payload: ${JSON.stringify(didPayload)}`)
199
- console.warn(`DID Tx: ${JSON.stringify(didTx)}`)
200
-
201
- expect(didTx.code).toBe(0)
202
-
203
- // create a did linked resource
204
- const resourceModule = new ResourceModule(signer, querier as CheqdQuerier & ResourceExtension)
205
-
206
- const resourcePayload: MsgCreateResourcePayload = {
207
- collectionId: didPayload.id.split(":").reverse()[0],
208
- id: v4(),
209
- version: "1.0",
210
- alsoKnownAs: [],
211
- name: 'Test Resource',
212
- resourceType: 'test-resource-type',
213
- data: new TextEncoder().encode(default_content)
214
- }
215
-
216
- const resourceSignInputs: ISignInputs[] = [
217
- {
218
- verificationMethodId: didPayload.verificationMethod![0].id,
219
- keyType: 'Ed25519',
220
- privateKeyHex: toString(fromString(keyPair.privateKey, 'base64'), 'hex')
221
- }
222
- ]
223
-
224
- const feeResourceDefault = await ResourceModule.generateCreateResourceDefaultFees(feePayer)
225
- const resourceTx = await resourceModule.createLinkedResourceTx(
226
- resourceSignInputs,
227
- resourcePayload,
228
- feePayer,
229
- feeResourceDefault
230
- )
231
-
232
- console.warn(`Using payload: ${JSON.stringify(resourcePayload)}`)
233
- console.warn(`Resource Tx: ${JSON.stringify(resourceTx)}`)
234
-
235
- expect(resourceTx.code).toBe(0)
236
- }, defaultAsyncTxTimeout)
237
- })
238
-
239
- describe('queryLinkedResource', () => {
240
- it('should query a linked resource - case: json', async () => {
241
- // create an associated did document
242
- const wallet = await DirectSecp256k1HdWallet.fromMnemonic(faucet.mnemonic, {prefix: faucet.prefix})
243
- const registry = createDefaultCheqdRegistry(Array.from(DIDModule.registryTypes).concat(Array.from(ResourceModule.registryTypes)))
244
- const signer = await CheqdSigningStargateClient.connectWithSigner(localnet.rpcUrl, wallet, { registry })
245
- const querier = await CheqdQuerier.connectWithExtensions(localnet.rpcUrl, ...[setupDidExtension, setupResourceExtension] as unknown as QueryExtensionSetup<CheqdExtensions>[])
246
- const didModule = new DIDModule(signer, querier as CheqdQuerier & DidExtension)
247
-
248
- const keyPair = createKeyPairBase64()
249
- const verificationKeys = createVerificationKeys(keyPair.publicKey, MethodSpecificIdAlgo.Base58, 'key-1')
250
- const verificationMethods = createDidVerificationMethod([VerificationMethods.Ed255192020], [verificationKeys])
251
- const didPayload = createDidPayload(verificationMethods, [verificationKeys])
252
-
253
- const signInputs: ISignInputs[] = [
254
- {
255
- verificationMethodId: didPayload.verificationMethod![0].id,
256
- privateKeyHex: toString(fromString(keyPair.privateKey, 'base64'), 'hex')
257
- }
258
- ]
259
-
260
- const feePayer = (await wallet.getAccounts())[0].address
261
- const fee = await DIDModule.generateCreateDidDocFees(feePayer)
262
- const didTx: DeliverTxResponse = await didModule.createDidDocTx(
263
- signInputs,
264
- didPayload,
265
- feePayer,
266
- fee
267
- )
268
-
269
- console.warn(`Using payload: ${JSON.stringify(didPayload)}`)
270
- console.warn(`DID Tx: ${JSON.stringify(didTx)}`)
271
-
272
- expect(didTx.code).toBe(0)
273
-
274
- // create a did linked resource
275
- const resourceModule = new ResourceModule(signer, querier as CheqdQuerier & ResourceExtension)
276
-
277
- const collectionId = didPayload.id.split(":").reverse()[0]
278
-
279
- const resourcePayload: MsgCreateResourcePayload = {
280
- collectionId: collectionId,
281
- id: v4(),
282
- version: "1.0",
283
- alsoKnownAs: [],
284
- name: 'Test Resource',
285
- resourceType: 'test-resource-type',
286
- data: new TextEncoder().encode(json_content)
287
- }
288
-
289
- const resourceSignInputs: ISignInputs[] = [
290
- {
291
- verificationMethodId: didPayload.verificationMethod![0].id,
292
- keyType: 'Ed25519',
293
- privateKeyHex: toString(fromString(keyPair.privateKey, 'base64'), 'hex')
294
- }
295
- ]
296
-
297
- const feeResourceJson = await ResourceModule.generateCreateResourceJsonFees(feePayer)
298
- const resourceTx = await resourceModule.createLinkedResourceTx(
299
- resourceSignInputs,
300
- resourcePayload,
301
- feePayer,
302
- feeResourceJson,
303
- )
304
-
305
- console.warn(`Using payload: ${JSON.stringify(resourcePayload)}`)
306
- console.warn(`Resource Tx: ${JSON.stringify(resourceTx)}`)
307
-
308
- expect(resourceTx.code).toBe(0)
309
-
310
- // query the resource
311
- const resourceWithMetadata = await resourceModule.queryLinkedResource(collectionId, resourcePayload.id)
312
-
313
- // ledger constructed
314
- const alsoKnownAs = [{ description: 'did-url', uri: `${didPayload.id}/resources/${resourcePayload.id}` }]
315
- const checksum = toString(sha256(resourcePayload.data), 'hex')
316
- const mimeType = 'application/json'
317
-
318
- expect(resourceWithMetadata.metadata?.collectionId).toBe(collectionId)
319
- expect(resourceWithMetadata.metadata?.id).toBe(resourcePayload.id)
320
- expect(resourceWithMetadata.metadata?.name).toBe(resourcePayload.name)
321
- expect(resourceWithMetadata.metadata?.version).toBe(resourcePayload.version)
322
- expect(resourceWithMetadata.metadata?.resourceType).toBe(resourcePayload.resourceType)
323
- expect(resourceWithMetadata.metadata?.alsoKnownAs).toEqual(alsoKnownAs)
324
- expect(resourceWithMetadata.metadata?.mediaType).toBe(mimeType)
325
- expect(resourceWithMetadata.metadata?.checksum).toBe(checksum)
326
- expect(resourceWithMetadata.metadata?.previousVersionId).toBe('')
327
- expect(resourceWithMetadata.metadata?.nextVersionId).toBe('')
328
- expect(resourceWithMetadata.resource?.data).toEqual(resourcePayload.data)
329
- }, defaultAsyncTxTimeout)
330
-
331
- it('should query a linked resource - case: image', async () => {
332
- // create an associated did document
333
- const wallet = await DirectSecp256k1HdWallet.fromMnemonic(faucet.mnemonic, {prefix: faucet.prefix})
334
- const registry = createDefaultCheqdRegistry(Array.from(DIDModule.registryTypes).concat(Array.from(ResourceModule.registryTypes)))
335
- const signer = await CheqdSigningStargateClient.connectWithSigner(localnet.rpcUrl, wallet, { registry })
336
- const querier = await CheqdQuerier.connectWithExtensions(localnet.rpcUrl, ...[setupDidExtension, setupResourceExtension] as unknown as QueryExtensionSetup<CheqdExtensions>[])
337
- const didModule = new DIDModule(signer, querier as CheqdQuerier & DidExtension)
338
-
339
- const keyPair = createKeyPairBase64()
340
- const verificationKeys = createVerificationKeys(keyPair.publicKey, MethodSpecificIdAlgo.Base58, 'key-1')
341
- const verificationMethods = createDidVerificationMethod([VerificationMethods.Ed255192020], [verificationKeys])
342
- const didPayload = createDidPayload(verificationMethods, [verificationKeys])
343
-
344
- const signInputs: ISignInputs[] = [
345
- {
346
- verificationMethodId: didPayload.verificationMethod![0].id,
347
- privateKeyHex: toString(fromString(keyPair.privateKey, 'base64'), 'hex')
348
- }
349
- ]
350
-
351
- const feePayer = (await wallet.getAccounts())[0].address
352
- const fee = await DIDModule.generateCreateDidDocFees(feePayer)
353
- const didTx: DeliverTxResponse = await didModule.createDidDocTx(
354
- signInputs,
355
- didPayload,
356
- feePayer,
357
- fee
358
- )
359
-
360
- console.warn(`Using payload: ${JSON.stringify(didPayload)}`)
361
- console.warn(`DID Tx: ${JSON.stringify(didTx)}`)
362
-
363
- expect(didTx.code).toBe(0)
364
-
365
- // create a did linked resource
366
- const resourceModule = new ResourceModule(signer, querier as CheqdQuerier & ResourceExtension)
367
-
368
- const collectionId = didPayload.id.split(":").reverse()[0]
369
-
370
- const resourcePayload: MsgCreateResourcePayload = {
371
- collectionId: collectionId,
372
- id: v4(),
373
- version: "1.0",
374
- alsoKnownAs: [],
375
- name: 'Test Resource',
376
- resourceType: 'test-resource-type',
377
- data: fromString(image_content, 'base64')
378
- }
379
-
380
- const resourceSignInputs: ISignInputs[] = [
381
- {
382
- verificationMethodId: didPayload.verificationMethod![0].id,
383
- keyType: 'Ed25519',
384
- privateKeyHex: toString(fromString(keyPair.privateKey, 'base64'), 'hex')
385
- }
386
- ]
387
-
388
- const feeResourceImage = await ResourceModule.generateCreateResourceImageFees(feePayer)
389
- const resourceTx = await resourceModule.createLinkedResourceTx(
390
- resourceSignInputs,
391
- resourcePayload,
392
- feePayer,
393
- feeResourceImage,
394
- )
395
-
396
- console.warn(`Using payload: ${JSON.stringify(resourcePayload)}`)
397
- console.warn(`Resource Tx: ${JSON.stringify(resourceTx)}`)
398
-
399
- expect(resourceTx.code).toBe(0)
400
-
401
- // query the resource
402
- const resourceWithMetadata = await resourceModule.queryLinkedResource(collectionId, resourcePayload.id)
403
-
404
- // ledger constructed
405
- const alsoKnownAs = [{ description: 'did-url', uri: `${didPayload.id}/resources/${resourcePayload.id}` }]
406
- const checksum = toString(sha256(resourcePayload.data), 'hex')
407
- const mimeType = 'image/png'
408
-
409
- expect(resourceWithMetadata.metadata?.collectionId).toBe(collectionId)
410
- expect(resourceWithMetadata.metadata?.id).toBe(resourcePayload.id)
411
- expect(resourceWithMetadata.metadata?.name).toBe(resourcePayload.name)
412
- expect(resourceWithMetadata.metadata?.version).toBe(resourcePayload.version)
413
- expect(resourceWithMetadata.metadata?.resourceType).toBe(resourcePayload.resourceType)
414
- expect(resourceWithMetadata.metadata?.alsoKnownAs).toEqual(alsoKnownAs)
415
- expect(resourceWithMetadata.metadata?.mediaType).toBe(mimeType)
416
- expect(resourceWithMetadata.metadata?.checksum).toBe(checksum)
417
- expect(resourceWithMetadata.metadata?.previousVersionId).toBe('')
418
- expect(resourceWithMetadata.metadata?.nextVersionId).toBe('')
419
- expect(resourceWithMetadata.resource?.data).toEqual(resourcePayload.data)
420
- }, defaultAsyncTxTimeout)
421
-
422
- it('should query a linked resource - case: default', async () => {
423
- // create an associated did document
424
- const wallet = await DirectSecp256k1HdWallet.fromMnemonic(faucet.mnemonic, {prefix: faucet.prefix})
425
- const registry = createDefaultCheqdRegistry(Array.from(DIDModule.registryTypes).concat(Array.from(ResourceModule.registryTypes)))
426
- const signer = await CheqdSigningStargateClient.connectWithSigner(localnet.rpcUrl, wallet, { registry })
427
- const querier = await CheqdQuerier.connectWithExtensions(localnet.rpcUrl, ...[setupDidExtension, setupResourceExtension] as unknown as QueryExtensionSetup<CheqdExtensions>[])
428
- const didModule = new DIDModule(signer, querier as CheqdQuerier & DidExtension)
429
-
430
- const keyPair = createKeyPairBase64()
431
- const verificationKeys = createVerificationKeys(keyPair.publicKey, MethodSpecificIdAlgo.Base58, 'key-1')
432
- const verificationMethods = createDidVerificationMethod([VerificationMethods.Ed255192020], [verificationKeys])
433
- const didPayload = createDidPayload(verificationMethods, [verificationKeys])
434
-
435
- const signInputs: ISignInputs[] = [
436
- {
437
- verificationMethodId: didPayload.verificationMethod![0].id,
438
- privateKeyHex: toString(fromString(keyPair.privateKey, 'base64'), 'hex')
439
- }
440
- ]
441
-
442
- const feePayer = (await wallet.getAccounts())[0].address
443
- const fee = await DIDModule.generateCreateDidDocFees(feePayer)
444
- const didTx: DeliverTxResponse = await didModule.createDidDocTx(
445
- signInputs,
446
- didPayload,
447
- feePayer,
448
- fee
449
- )
450
-
451
- console.warn(`Using payload: ${JSON.stringify(didPayload)}`)
452
- console.warn(`DID Tx: ${JSON.stringify(didTx)}`)
453
-
454
- expect(didTx.code).toBe(0)
455
-
456
- // create a did linked resource
457
- const resourceModule = new ResourceModule(signer, querier as CheqdQuerier & ResourceExtension)
458
-
459
- const collectionId = didPayload.id.split(":").reverse()[0]
460
-
461
- const resourcePayload: MsgCreateResourcePayload = {
462
- collectionId: collectionId,
463
- id: v4(),
464
- version: "1.0",
465
- alsoKnownAs: [],
466
- name: 'Test Resource',
467
- resourceType: 'test-resource-type',
468
- data: new TextEncoder().encode(default_content)
469
- }
470
-
471
- const resourceSignInputs: ISignInputs[] = [
472
- {
473
- verificationMethodId: didPayload.verificationMethod![0].id,
474
- keyType: 'Ed25519',
475
- privateKeyHex: toString(fromString(keyPair.privateKey, 'base64'), 'hex')
476
- }
477
- ]
478
-
479
- const feeResourceDefault = await ResourceModule.generateCreateResourceDefaultFees(feePayer)
480
- const resourceTx = await resourceModule.createLinkedResourceTx(
481
- resourceSignInputs,
482
- resourcePayload,
483
- feePayer,
484
- feeResourceDefault,
485
- )
486
-
487
- console.warn(`Using payload: ${JSON.stringify(resourcePayload)}`)
488
- console.warn(`Resource Tx: ${JSON.stringify(resourceTx)}`)
489
-
490
- expect(resourceTx.code).toBe(0)
491
-
492
- // query the resource
493
- const resourceWithMetadata = await resourceModule.queryLinkedResource(collectionId, resourcePayload.id)
494
-
495
- // ledger constructed
496
- const alsoKnownAs = [{ description: 'did-url', uri: `${didPayload.id}/resources/${resourcePayload.id}` }]
497
- const checksum = toString(sha256(resourcePayload.data), 'hex')
498
- const mimeType = 'text/html; charset=utf-8'
499
-
500
- expect(resourceWithMetadata.metadata?.collectionId).toBe(collectionId)
501
- expect(resourceWithMetadata.metadata?.id).toBe(resourcePayload.id)
502
- expect(resourceWithMetadata.metadata?.name).toBe(resourcePayload.name)
503
- expect(resourceWithMetadata.metadata?.version).toBe(resourcePayload.version)
504
- expect(resourceWithMetadata.metadata?.resourceType).toBe(resourcePayload.resourceType)
505
- expect(resourceWithMetadata.metadata?.alsoKnownAs).toEqual(alsoKnownAs)
506
- expect(resourceWithMetadata.metadata?.mediaType).toBe(mimeType)
507
- expect(resourceWithMetadata.metadata?.checksum).toBe(checksum)
508
- expect(resourceWithMetadata.metadata?.previousVersionId).toBe('')
509
- expect(resourceWithMetadata.metadata?.nextVersionId).toBe('')
510
- expect(resourceWithMetadata.resource?.data).toEqual(resourcePayload.data)
511
- }, defaultAsyncTxTimeout)
512
- })
513
-
514
- describe('queryLinkedResourceMetadata', () => {
515
- it('should query a linked resource metadata - case: json', async () => {
516
- // create an associated did document
517
- const wallet = await DirectSecp256k1HdWallet.fromMnemonic(faucet.mnemonic, {prefix: faucet.prefix})
518
- const registry = createDefaultCheqdRegistry(Array.from(DIDModule.registryTypes).concat(Array.from(ResourceModule.registryTypes)))
519
- const signer = await CheqdSigningStargateClient.connectWithSigner(localnet.rpcUrl, wallet, { registry })
520
- const querier = await CheqdQuerier.connectWithExtensions(localnet.rpcUrl, ...[setupDidExtension, setupResourceExtension] as unknown as QueryExtensionSetup<CheqdExtensions>[])
521
- const didModule = new DIDModule(signer, querier as CheqdQuerier & DidExtension)
522
-
523
- const keyPair = createKeyPairBase64()
524
- const verificationKeys = createVerificationKeys(keyPair.publicKey, MethodSpecificIdAlgo.Base58, 'key-1')
525
- const verificationMethods = createDidVerificationMethod([VerificationMethods.Ed255192020], [verificationKeys])
526
- const didPayload = createDidPayload(verificationMethods, [verificationKeys])
527
-
528
- const signInputs: ISignInputs[] = [
529
- {
530
- verificationMethodId: didPayload.verificationMethod![0].id,
531
- privateKeyHex: toString(fromString(keyPair.privateKey, 'base64'), 'hex')
532
- }
533
- ]
534
-
535
- const feePayer = (await wallet.getAccounts())[0].address
536
- const fee = await DIDModule.generateCreateDidDocFees(feePayer)
537
- const didTx: DeliverTxResponse = await didModule.createDidDocTx(
538
- signInputs,
539
- didPayload,
540
- feePayer,
541
- fee
542
- )
543
-
544
- console.warn(`Using payload: ${JSON.stringify(didPayload)}`)
545
- console.warn(`DID Tx: ${JSON.stringify(didTx)}`)
546
-
547
- expect(didTx.code).toBe(0)
548
-
549
- // create a did linked resource
550
- const resourceModule = new ResourceModule(signer, querier as CheqdQuerier & ResourceExtension)
551
-
552
- const collectionId = didPayload.id.split(":").reverse()[0]
553
-
554
- const resourcePayload: MsgCreateResourcePayload = {
555
- collectionId: collectionId,
556
- id: v4(),
557
- version: "1.0",
558
- alsoKnownAs: [],
559
- name: 'Test Resource',
560
- resourceType: 'test-resource-type',
561
- data: new TextEncoder().encode(json_content)
562
- }
563
-
564
- const resourceSignInputs: ISignInputs[] = [
565
- {
566
- verificationMethodId: didPayload.verificationMethod![0].id,
567
- keyType: 'Ed25519',
568
- privateKeyHex: toString(fromString(keyPair.privateKey, 'base64'), 'hex')
569
- }
570
- ]
571
-
572
- const feeResourceJson = await ResourceModule.generateCreateResourceJsonFees(feePayer)
573
- const resourceTx = await resourceModule.createLinkedResourceTx(
574
- resourceSignInputs,
575
- resourcePayload,
576
- feePayer,
577
- feeResourceJson,
578
- )
579
-
580
- console.warn(`Using payload: ${JSON.stringify(resourcePayload)}`)
581
- console.warn(`Resource Tx: ${JSON.stringify(resourceTx)}`)
582
-
583
- expect(resourceTx.code).toBe(0)
584
-
585
- // query the linked resource metadata
586
- const metadata = await resourceModule.queryLinkedResourceMetadata(collectionId, resourcePayload.id)
587
-
588
- // ledger constructed
589
- const alsoKnownAs = [{ description: 'did-url', uri: `${didPayload.id}/resources/${resourcePayload.id}` }]
590
- const checksum = toString(sha256(resourcePayload.data), 'hex')
591
- const mimeType = 'application/json'
592
-
593
- expect(metadata?.collectionId).toBe(collectionId)
594
- expect(metadata?.id).toBe(resourcePayload.id)
595
- expect(metadata?.name).toBe(resourcePayload.name)
596
- expect(metadata?.version).toBe(resourcePayload.version)
597
- expect(metadata?.resourceType).toBe(resourcePayload.resourceType)
598
- expect(metadata?.alsoKnownAs).toEqual(alsoKnownAs)
599
- expect(metadata?.mediaType).toBe(mimeType)
600
- expect(metadata?.checksum).toBe(checksum)
601
- expect(metadata?.previousVersionId).toBe('')
602
- expect(metadata?.nextVersionId).toBe('')
603
- }, defaultAsyncTxTimeout)
604
-
605
- it('should query a linked resource metadata - case: image', async () => {
606
- // create an associated did document
607
- const wallet = await DirectSecp256k1HdWallet.fromMnemonic(faucet.mnemonic, {prefix: faucet.prefix})
608
- const registry = createDefaultCheqdRegistry(Array.from(DIDModule.registryTypes).concat(Array.from(ResourceModule.registryTypes)))
609
- const signer = await CheqdSigningStargateClient.connectWithSigner(localnet.rpcUrl, wallet, { registry })
610
- const querier = await CheqdQuerier.connectWithExtensions(localnet.rpcUrl, ...[setupDidExtension, setupResourceExtension] as unknown as QueryExtensionSetup<CheqdExtensions>[])
611
- const didModule = new DIDModule(signer, querier as CheqdQuerier & DidExtension)
612
-
613
- const keyPair = createKeyPairBase64()
614
- const verificationKeys = createVerificationKeys(keyPair.publicKey, MethodSpecificIdAlgo.Base58, 'key-1')
615
- const verificationMethods = createDidVerificationMethod([VerificationMethods.Ed255192020], [verificationKeys])
616
- const didPayload = createDidPayload(verificationMethods, [verificationKeys])
617
-
618
- const signInputs: ISignInputs[] = [
619
- {
620
- verificationMethodId: didPayload.verificationMethod![0].id,
621
- privateKeyHex: toString(fromString(keyPair.privateKey, 'base64'), 'hex')
622
- }
623
- ]
624
-
625
- const feePayer = (await wallet.getAccounts())[0].address
626
- const fee = await DIDModule.generateCreateDidDocFees(feePayer)
627
- const didTx: DeliverTxResponse = await didModule.createDidDocTx(
628
- signInputs,
629
- didPayload,
630
- feePayer,
631
- fee
632
- )
633
-
634
- console.warn(`Using payload: ${JSON.stringify(didPayload)}`)
635
- console.warn(`DID Tx: ${JSON.stringify(didTx)}`)
636
-
637
- expect(didTx.code).toBe(0)
638
-
639
- // create a did linked resource
640
- const resourceModule = new ResourceModule(signer, querier as CheqdQuerier & ResourceExtension)
641
-
642
- const collectionId = didPayload.id.split(":").reverse()[0]
643
-
644
- const resourcePayload: MsgCreateResourcePayload = {
645
- collectionId: collectionId,
646
- id: v4(),
647
- version: "1.0",
648
- alsoKnownAs: [],
649
- name: 'Test Resource',
650
- resourceType: 'test-resource-type',
651
- data: fromString(image_content, 'base64')
652
- }
653
-
654
- const resourceSignInputs: ISignInputs[] = [
655
- {
656
- verificationMethodId: didPayload.verificationMethod![0].id,
657
- keyType: 'Ed25519',
658
- privateKeyHex: toString(fromString(keyPair.privateKey, 'base64'), 'hex')
659
- }
660
- ]
661
-
662
- const feeResourceImage = await ResourceModule.generateCreateResourceImageFees(feePayer)
663
- const resourceTx = await resourceModule.createLinkedResourceTx(
664
- resourceSignInputs,
665
- resourcePayload,
666
- feePayer,
667
- feeResourceImage,
668
- )
669
-
670
- console.warn(`Using payload: ${JSON.stringify(resourcePayload)}`)
671
- console.warn(`Resource Tx: ${JSON.stringify(resourceTx)}`)
672
-
673
- expect(resourceTx.code).toBe(0)
674
-
675
- // query the linked resource metadata
676
- const metadata = await resourceModule.queryLinkedResourceMetadata(collectionId, resourcePayload.id)
677
-
678
- // ledger constructed
679
- const alsoKnownAs = [{ description: 'did-url', uri: `${didPayload.id}/resources/${resourcePayload.id}` }]
680
- const checksum = toString(sha256(resourcePayload.data), 'hex')
681
- const mimeType = 'image/png'
682
-
683
- expect(metadata?.collectionId).toBe(collectionId)
684
- expect(metadata?.id).toBe(resourcePayload.id)
685
- expect(metadata?.name).toBe(resourcePayload.name)
686
- expect(metadata?.version).toBe(resourcePayload.version)
687
- expect(metadata?.resourceType).toBe(resourcePayload.resourceType)
688
- expect(metadata?.alsoKnownAs).toEqual(alsoKnownAs)
689
- expect(metadata?.mediaType).toBe(mimeType)
690
- expect(metadata?.checksum).toBe(checksum)
691
- expect(metadata?.previousVersionId).toBe('')
692
- expect(metadata?.nextVersionId).toBe('')
693
- }, defaultAsyncTxTimeout)
694
-
695
- it('should query a linked resource metadata - case: default', async () => {
696
- // create an associated did document
697
- const wallet = await DirectSecp256k1HdWallet.fromMnemonic(faucet.mnemonic, {prefix: faucet.prefix})
698
- const registry = createDefaultCheqdRegistry(Array.from(DIDModule.registryTypes).concat(Array.from(ResourceModule.registryTypes)))
699
- const signer = await CheqdSigningStargateClient.connectWithSigner(localnet.rpcUrl, wallet, { registry })
700
- const querier = await CheqdQuerier.connectWithExtensions(localnet.rpcUrl, ...[setupDidExtension, setupResourceExtension] as unknown as QueryExtensionSetup<CheqdExtensions>[])
701
- const didModule = new DIDModule(signer, querier as CheqdQuerier & DidExtension)
702
-
703
- const keyPair = createKeyPairBase64()
704
- const verificationKeys = createVerificationKeys(keyPair.publicKey, MethodSpecificIdAlgo.Base58, 'key-1')
705
- const verificationMethods = createDidVerificationMethod([VerificationMethods.Ed255192020], [verificationKeys])
706
- const didPayload = createDidPayload(verificationMethods, [verificationKeys])
707
-
708
- const signInputs: ISignInputs[] = [
709
- {
710
- verificationMethodId: didPayload.verificationMethod![0].id,
711
- privateKeyHex: toString(fromString(keyPair.privateKey, 'base64'), 'hex')
712
- }
713
- ]
714
-
715
- const feePayer = (await wallet.getAccounts())[0].address
716
- const fee = await DIDModule.generateCreateDidDocFees(feePayer)
717
- const didTx: DeliverTxResponse = await didModule.createDidDocTx(
718
- signInputs,
719
- didPayload,
720
- feePayer,
721
- fee
722
- )
723
-
724
- console.warn(`Using payload: ${JSON.stringify(didPayload)}`)
725
- console.warn(`DID Tx: ${JSON.stringify(didTx)}`)
726
-
727
- expect(didTx.code).toBe(0)
728
-
729
- // create a did linked resource
730
- const resourceModule = new ResourceModule(signer, querier as CheqdQuerier & ResourceExtension)
731
-
732
- const collectionId = didPayload.id.split(":").reverse()[0]
733
-
734
- const resourcePayload: MsgCreateResourcePayload = {
735
- collectionId: collectionId,
736
- id: v4(),
737
- version: "1.0",
738
- alsoKnownAs: [],
739
- name: 'Test Resource',
740
- resourceType: 'test-resource-type',
741
- data: new TextEncoder().encode(default_content)
742
- }
743
-
744
- const resourceSignInputs: ISignInputs[] = [
745
- {
746
- verificationMethodId: didPayload.verificationMethod![0].id,
747
- keyType: 'Ed25519',
748
- privateKeyHex: toString(fromString(keyPair.privateKey, 'base64'), 'hex')
749
- }
750
- ]
751
-
752
- const feeResourceDefault = await ResourceModule.generateCreateResourceDefaultFees(feePayer)
753
- const resourceTx = await resourceModule.createLinkedResourceTx(
754
- resourceSignInputs,
755
- resourcePayload,
756
- feePayer,
757
- feeResourceDefault,
758
- )
759
-
760
- console.warn(`Using payload: ${JSON.stringify(resourcePayload)}`)
761
- console.warn(`Resource Tx: ${JSON.stringify(resourceTx)}`)
762
-
763
- expect(resourceTx.code).toBe(0)
764
-
765
- // query the linked resource metadata
766
- const metadata = await resourceModule.queryLinkedResourceMetadata(collectionId, resourcePayload.id)
767
-
768
- // ledger constructed
769
- const alsoKnownAs = [{ description: 'did-url', uri: `${didPayload.id}/resources/${resourcePayload.id}` }]
770
- const checksum = toString(sha256(resourcePayload.data), 'hex')
771
- const mimeType = 'text/html; charset=utf-8'
772
-
773
- expect(metadata?.collectionId).toBe(collectionId)
774
- expect(metadata?.id).toBe(resourcePayload.id)
775
- expect(metadata?.name).toBe(resourcePayload.name)
776
- expect(metadata?.version).toBe(resourcePayload.version)
777
- expect(metadata?.resourceType).toBe(resourcePayload.resourceType)
778
- expect(metadata?.alsoKnownAs).toEqual(alsoKnownAs)
779
- expect(metadata?.mediaType).toBe(mimeType)
780
- expect(metadata?.checksum).toBe(checksum)
781
- expect(metadata?.previousVersionId).toBe('')
782
- expect(metadata?.nextVersionId).toBe('')
783
- }, defaultAsyncTxTimeout)
784
- })
785
- })