@cheqd/sdk 3.0.2-develop.1 → 3.0.2-develop.2

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