@cheqd/sdk 2.0.2-develop.1 → 2.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/.github/workflows/test.yml +2 -2
- package/CHANGELOG.md +14 -0
- package/README.md +1 -1
- package/build/index.d.ts +7 -3
- package/build/index.d.ts.map +1 -1
- package/build/index.js +19 -7
- package/build/index.js.map +1 -1
- package/build/modules/_.d.ts +7 -11
- package/build/modules/_.d.ts.map +1 -1
- package/build/modules/_.js +15 -17
- package/build/modules/_.js.map +1 -1
- package/build/modules/did.d.ts +39 -15
- package/build/modules/did.d.ts.map +1 -1
- package/build/modules/did.js +187 -54
- package/build/modules/did.js.map +1 -1
- package/build/modules/resource.d.ts +23 -7
- package/build/modules/resource.d.ts.map +1 -1
- package/build/modules/resource.js +61 -18
- package/build/modules/resource.js.map +1 -1
- package/build/querier.d.ts +11 -0
- package/build/querier.d.ts.map +1 -0
- package/build/querier.js +31 -0
- package/build/querier.js.map +1 -0
- package/build/signer.d.ts +3 -5
- package/build/signer.d.ts.map +1 -1
- package/build/signer.js +13 -13
- package/build/signer.js.map +1 -1
- package/build/types.d.ts +12 -0
- package/build/types.d.ts.map +1 -1
- package/build/types.js.map +1 -1
- package/build/utils.js +13 -15
- package/build/utils.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +22 -10
- package/src/modules/_.ts +13 -21
- package/src/modules/did.ts +207 -51
- package/src/modules/resource.ts +74 -12
- package/src/querier.ts +33 -0
- package/src/signer.ts +3 -6
- package/src/types.ts +17 -1
- package/src/utils.ts +1 -1
- package/tests/index.test.ts +43 -3
- package/tests/modules/did.test.ts +483 -50
- package/tests/modules/resource.test.ts +576 -30
- package/tests/signer.test.ts +2 -2
- package/tests/testutils.test.ts +8 -2
- package/tsconfig.json +1 -1
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
import { DirectSecp256k1HdWallet
|
|
1
|
+
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing"
|
|
2
2
|
import { DeliverTxResponse } from "@cosmjs/stargate"
|
|
3
3
|
import { fromString, toString } from 'uint8arrays'
|
|
4
4
|
import { DIDModule, ResourceModule } from "../../src"
|
|
5
5
|
import { createDefaultCheqdRegistry } from "../../src/registry"
|
|
6
6
|
import { CheqdSigningStargateClient } from "../../src/signer"
|
|
7
|
-
import { ISignInputs, MethodSpecificIdAlgo, VerificationMethods } from '../../src/types';
|
|
7
|
+
import { ISignInputs, MethodSpecificIdAlgo, QueryExtensionSetup, VerificationMethods, CheqdExtensions } from '../../src/types';
|
|
8
8
|
import { createDidPayload, createDidVerificationMethod, createKeyPairBase64, createVerificationKeys } from "../../src/utils"
|
|
9
|
-
import { localnet, faucet, image_content, default_content } from "../testutils.test"
|
|
9
|
+
import { localnet, faucet, image_content, default_content, json_content } from "../testutils.test"
|
|
10
10
|
import { MsgCreateResourcePayload } from '@cheqd/ts-proto/cheqd/resource/v2';
|
|
11
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"
|
|
12
16
|
|
|
13
17
|
const defaultAsyncTxTimeout = 30000
|
|
14
18
|
|
|
@@ -17,21 +21,20 @@ describe('ResourceModule', () => {
|
|
|
17
21
|
it('should instantiate standalone module', async () => {
|
|
18
22
|
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(faucet.mnemonic)
|
|
19
23
|
const signer = await CheqdSigningStargateClient.connectWithSigner(localnet.rpcUrl, wallet)
|
|
20
|
-
const
|
|
24
|
+
const querier = await CheqdQuerier.connectWithExtension(localnet.rpcUrl, setupResourceExtension) as CheqdQuerier & ResourceExtension
|
|
25
|
+
const resourceModule = new ResourceModule(signer, querier)
|
|
21
26
|
expect(resourceModule).toBeInstanceOf(ResourceModule)
|
|
22
27
|
})
|
|
23
28
|
})
|
|
24
29
|
|
|
25
|
-
describe('
|
|
30
|
+
describe('createLinkedResourceTx', () => {
|
|
26
31
|
it('should create a new Resource - case: json', async () => {
|
|
27
32
|
// create an associated did document
|
|
28
33
|
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(faucet.mnemonic, {prefix: faucet.prefix})
|
|
29
|
-
|
|
30
34
|
const registry = createDefaultCheqdRegistry(Array.from(DIDModule.registryTypes).concat(Array.from(ResourceModule.registryTypes)))
|
|
31
|
-
|
|
32
35
|
const signer = await CheqdSigningStargateClient.connectWithSigner(localnet.rpcUrl, wallet, { registry })
|
|
33
|
-
|
|
34
|
-
const didModule = new DIDModule(signer)
|
|
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)
|
|
35
38
|
|
|
36
39
|
const keyPair = createKeyPairBase64()
|
|
37
40
|
const verificationKeys = createVerificationKeys(keyPair.publicKey, MethodSpecificIdAlgo.Base58, 'key-1')
|
|
@@ -47,7 +50,7 @@ describe('ResourceModule', () => {
|
|
|
47
50
|
|
|
48
51
|
const feePayer = (await wallet.getAccounts())[0].address
|
|
49
52
|
const fee = await DIDModule.generateCreateDidDocFees(feePayer)
|
|
50
|
-
const didTx: DeliverTxResponse = await didModule.
|
|
53
|
+
const didTx: DeliverTxResponse = await didModule.createDidDocTx(
|
|
51
54
|
signInputs,
|
|
52
55
|
didPayload,
|
|
53
56
|
feePayer,
|
|
@@ -60,7 +63,7 @@ describe('ResourceModule', () => {
|
|
|
60
63
|
expect(didTx.code).toBe(0)
|
|
61
64
|
|
|
62
65
|
// create a did linked resource
|
|
63
|
-
const resourceModule = new ResourceModule(signer)
|
|
66
|
+
const resourceModule = new ResourceModule(signer, querier as CheqdQuerier & ResourceExtension)
|
|
64
67
|
|
|
65
68
|
const resourcePayload: MsgCreateResourcePayload = {
|
|
66
69
|
collectionId: didPayload.id.split(":").reverse()[0],
|
|
@@ -69,7 +72,7 @@ describe('ResourceModule', () => {
|
|
|
69
72
|
alsoKnownAs: [],
|
|
70
73
|
name: 'Test Resource',
|
|
71
74
|
resourceType: 'test-resource-type',
|
|
72
|
-
data: new TextEncoder().encode(
|
|
75
|
+
data: new TextEncoder().encode(json_content)
|
|
73
76
|
}
|
|
74
77
|
|
|
75
78
|
const resourceSignInputs: ISignInputs[] = [
|
|
@@ -81,7 +84,7 @@ describe('ResourceModule', () => {
|
|
|
81
84
|
]
|
|
82
85
|
|
|
83
86
|
const feeResourceJson = await ResourceModule.generateCreateResourceJsonFees(feePayer)
|
|
84
|
-
const resourceTx = await resourceModule.
|
|
87
|
+
const resourceTx = await resourceModule.createLinkedResourceTx(
|
|
85
88
|
resourceSignInputs,
|
|
86
89
|
resourcePayload,
|
|
87
90
|
feePayer,
|
|
@@ -89,7 +92,7 @@ describe('ResourceModule', () => {
|
|
|
89
92
|
)
|
|
90
93
|
|
|
91
94
|
console.warn(`Using payload: ${JSON.stringify(resourcePayload)}`)
|
|
92
|
-
console.warn(`
|
|
95
|
+
console.warn(`Resource Tx: ${JSON.stringify(resourceTx)}`)
|
|
93
96
|
|
|
94
97
|
expect(resourceTx.code).toBe(0)
|
|
95
98
|
}, defaultAsyncTxTimeout)
|
|
@@ -97,12 +100,10 @@ describe('ResourceModule', () => {
|
|
|
97
100
|
it('should create a new Resource - case: image', async () => {
|
|
98
101
|
// create an associated did document
|
|
99
102
|
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(faucet.mnemonic, {prefix: faucet.prefix})
|
|
100
|
-
|
|
101
103
|
const registry = createDefaultCheqdRegistry(Array.from(DIDModule.registryTypes).concat(Array.from(ResourceModule.registryTypes)))
|
|
102
|
-
|
|
103
104
|
const signer = await CheqdSigningStargateClient.connectWithSigner(localnet.rpcUrl, wallet, { registry })
|
|
104
|
-
|
|
105
|
-
const didModule = new DIDModule(signer)
|
|
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)
|
|
106
107
|
|
|
107
108
|
const keyPair = createKeyPairBase64()
|
|
108
109
|
const verificationKeys = createVerificationKeys(keyPair.publicKey, MethodSpecificIdAlgo.Base58, 'key-1')
|
|
@@ -118,7 +119,7 @@ describe('ResourceModule', () => {
|
|
|
118
119
|
|
|
119
120
|
const feePayer = (await wallet.getAccounts())[0].address
|
|
120
121
|
const fee = await DIDModule.generateCreateDidDocFees(feePayer)
|
|
121
|
-
const didTx: DeliverTxResponse = await didModule.
|
|
122
|
+
const didTx: DeliverTxResponse = await didModule.createDidDocTx(
|
|
122
123
|
signInputs,
|
|
123
124
|
didPayload,
|
|
124
125
|
feePayer,
|
|
@@ -131,7 +132,7 @@ describe('ResourceModule', () => {
|
|
|
131
132
|
expect(didTx.code).toBe(0)
|
|
132
133
|
|
|
133
134
|
// create a did linked resource
|
|
134
|
-
const resourceModule = new ResourceModule(signer)
|
|
135
|
+
const resourceModule = new ResourceModule(signer, querier as CheqdQuerier & ResourceExtension)
|
|
135
136
|
|
|
136
137
|
const resourcePayload: MsgCreateResourcePayload = {
|
|
137
138
|
collectionId: didPayload.id.split(":").reverse()[0],
|
|
@@ -152,7 +153,7 @@ describe('ResourceModule', () => {
|
|
|
152
153
|
]
|
|
153
154
|
|
|
154
155
|
const feeResourceImage = await ResourceModule.generateCreateResourceImageFees(feePayer)
|
|
155
|
-
const resourceTx = await resourceModule.
|
|
156
|
+
const resourceTx = await resourceModule.createLinkedResourceTx(
|
|
156
157
|
resourceSignInputs,
|
|
157
158
|
resourcePayload,
|
|
158
159
|
feePayer,
|
|
@@ -160,7 +161,7 @@ describe('ResourceModule', () => {
|
|
|
160
161
|
)
|
|
161
162
|
|
|
162
163
|
console.warn(`Using payload: ${JSON.stringify(resourcePayload)}`)
|
|
163
|
-
console.warn(`
|
|
164
|
+
console.warn(`Resource Tx: ${JSON.stringify(resourceTx)}`)
|
|
164
165
|
|
|
165
166
|
expect(resourceTx.code).toBe(0)
|
|
166
167
|
}, defaultAsyncTxTimeout)
|
|
@@ -168,12 +169,10 @@ describe('ResourceModule', () => {
|
|
|
168
169
|
it('should create a new Resource - case: default', async () => {
|
|
169
170
|
// create an associated did document
|
|
170
171
|
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(faucet.mnemonic, {prefix: faucet.prefix})
|
|
171
|
-
|
|
172
172
|
const registry = createDefaultCheqdRegistry(Array.from(DIDModule.registryTypes).concat(Array.from(ResourceModule.registryTypes)))
|
|
173
|
-
|
|
174
173
|
const signer = await CheqdSigningStargateClient.connectWithSigner(localnet.rpcUrl, wallet, { registry })
|
|
175
|
-
|
|
176
|
-
const didModule = new DIDModule(signer)
|
|
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)
|
|
177
176
|
|
|
178
177
|
const keyPair = createKeyPairBase64()
|
|
179
178
|
const verificationKeys = createVerificationKeys(keyPair.publicKey, MethodSpecificIdAlgo.Base58, 'key-1')
|
|
@@ -189,7 +188,7 @@ describe('ResourceModule', () => {
|
|
|
189
188
|
|
|
190
189
|
const feePayer = (await wallet.getAccounts())[0].address
|
|
191
190
|
const fee = await DIDModule.generateCreateDidDocFees(feePayer)
|
|
192
|
-
const didTx: DeliverTxResponse = await didModule.
|
|
191
|
+
const didTx: DeliverTxResponse = await didModule.createDidDocTx(
|
|
193
192
|
signInputs,
|
|
194
193
|
didPayload,
|
|
195
194
|
feePayer,
|
|
@@ -202,7 +201,7 @@ describe('ResourceModule', () => {
|
|
|
202
201
|
expect(didTx.code).toBe(0)
|
|
203
202
|
|
|
204
203
|
// create a did linked resource
|
|
205
|
-
const resourceModule = new ResourceModule(signer)
|
|
204
|
+
const resourceModule = new ResourceModule(signer, querier as CheqdQuerier & ResourceExtension)
|
|
206
205
|
|
|
207
206
|
const resourcePayload: MsgCreateResourcePayload = {
|
|
208
207
|
collectionId: didPayload.id.split(":").reverse()[0],
|
|
@@ -223,7 +222,7 @@ describe('ResourceModule', () => {
|
|
|
223
222
|
]
|
|
224
223
|
|
|
225
224
|
const feeResourceDefault = await ResourceModule.generateCreateResourceDefaultFees(feePayer)
|
|
226
|
-
const resourceTx = await resourceModule.
|
|
225
|
+
const resourceTx = await resourceModule.createLinkedResourceTx(
|
|
227
226
|
resourceSignInputs,
|
|
228
227
|
resourcePayload,
|
|
229
228
|
feePayer,
|
|
@@ -231,9 +230,556 @@ describe('ResourceModule', () => {
|
|
|
231
230
|
)
|
|
232
231
|
|
|
233
232
|
console.warn(`Using payload: ${JSON.stringify(resourcePayload)}`)
|
|
234
|
-
console.warn(`
|
|
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)}`)
|
|
235
489
|
|
|
236
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('')
|
|
237
783
|
}, defaultAsyncTxTimeout)
|
|
238
784
|
})
|
|
239
785
|
})
|