@cheqd/sdk 2.1.0 → 3.0.0-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.
- package/.github/linters/{.commitlint.rules.js → .commitlint.rules.cjs} +0 -0
- package/.github/workflows/cleanup-cache-manual.yml +1 -1
- package/.github/workflows/pull-request.yml +2 -2
- package/CHANGELOG.md +9 -3
- package/build/cjs/index.d.ts +45 -0
- package/build/cjs/index.d.ts.map +1 -0
- package/build/cjs/index.js +144 -0
- package/build/cjs/index.js.map +1 -0
- package/build/{modules → cjs/modules}/_.d.ts +3 -3
- package/build/cjs/modules/_.d.ts.map +1 -0
- package/build/{modules → cjs/modules}/_.js +0 -0
- package/build/cjs/modules/_.js.map +1 -0
- package/build/{modules → cjs/modules}/did.d.ts +7 -5
- package/build/cjs/modules/did.d.ts.map +1 -0
- package/build/{modules → cjs/modules}/did.js +45 -37
- package/build/cjs/modules/did.js.map +1 -0
- package/build/{modules → cjs/modules}/resource.d.ts +6 -6
- package/build/cjs/modules/resource.d.ts.map +1 -0
- package/build/{modules → cjs/modules}/resource.js +14 -14
- package/build/cjs/modules/resource.js.map +1 -0
- package/build/{querier.d.ts → cjs/querier.d.ts} +1 -1
- package/build/cjs/querier.d.ts.map +1 -0
- package/build/{querier.js → cjs/querier.js} +0 -0
- package/build/cjs/querier.js.map +1 -0
- package/build/{registry.d.ts → cjs/registry.d.ts} +0 -0
- package/build/cjs/registry.d.ts.map +1 -0
- package/build/{registry.js → cjs/registry.js} +0 -0
- package/build/cjs/registry.js.map +1 -0
- package/build/{signer.d.ts → cjs/signer.d.ts} +5 -5
- package/build/cjs/signer.d.ts.map +1 -0
- package/build/{signer.js → cjs/signer.js} +10 -10
- package/build/cjs/signer.js.map +1 -0
- package/build/{types.d.ts → cjs/types.d.ts} +3 -3
- package/build/cjs/types.d.ts.map +1 -0
- package/build/{types.js → cjs/types.js} +0 -0
- package/build/cjs/types.js.map +1 -0
- package/build/{utils.d.ts → cjs/utils.d.ts} +1 -1
- package/build/cjs/utils.d.ts.map +1 -0
- package/build/{utils.js → cjs/utils.js} +18 -21
- package/build/cjs/utils.js.map +1 -0
- package/build/esm/index.d.ts +45 -0
- package/build/esm/index.d.ts.map +1 -0
- package/build/esm/index.js +89 -0
- package/build/esm/index.js.map +1 -0
- package/build/esm/modules/_.d.ts +20 -0
- package/build/esm/modules/_.d.ts.map +1 -0
- package/build/esm/modules/_.js +37 -0
- package/build/esm/modules/_.js.map +1 -0
- package/build/esm/modules/did.d.ts +109 -0
- package/build/esm/modules/did.d.ts.map +1 -0
- package/build/esm/modules/did.js +432 -0
- package/build/esm/modules/did.js.map +1 -0
- package/build/esm/modules/resource.d.ts +62 -0
- package/build/esm/modules/resource.d.ts.map +1 -0
- package/build/esm/modules/resource.js +156 -0
- package/build/esm/modules/resource.js.map +1 -0
- package/build/esm/querier.d.ts +11 -0
- package/build/esm/querier.d.ts.map +1 -0
- package/build/esm/querier.js +27 -0
- package/build/esm/querier.js.map +1 -0
- package/build/esm/registry.d.ts +4 -0
- package/build/esm/registry.d.ts.map +1 -0
- package/build/esm/registry.js +9 -0
- package/build/esm/registry.js.map +1 -0
- package/build/esm/signer.d.ts +36 -0
- package/build/esm/signer.d.ts.map +1 -0
- package/build/esm/signer.js +197 -0
- package/build/esm/signer.js.map +1 -0
- package/build/esm/types.d.ts +80 -0
- package/build/esm/types.d.ts.map +1 -0
- package/build/esm/types.js +22 -0
- package/build/esm/types.js.map +1 -0
- package/build/esm/utils.d.ts +18 -0
- package/build/esm/utils.d.ts.map +1 -0
- package/build/esm/utils.js +196 -0
- package/build/esm/utils.js.map +1 -0
- package/build/types/index.d.ts +45 -0
- package/build/types/index.d.ts.map +1 -0
- package/build/types/modules/_.d.ts +20 -0
- package/build/types/modules/_.d.ts.map +1 -0
- package/build/types/modules/did.d.ts +109 -0
- package/build/types/modules/did.d.ts.map +1 -0
- package/build/types/modules/resource.d.ts +62 -0
- package/build/types/modules/resource.d.ts.map +1 -0
- package/build/types/querier.d.ts +11 -0
- package/build/types/querier.d.ts.map +1 -0
- package/build/types/registry.d.ts +4 -0
- package/build/types/registry.d.ts.map +1 -0
- package/build/types/signer.d.ts +36 -0
- package/build/types/signer.d.ts.map +1 -0
- package/build/types/types.d.ts +80 -0
- package/build/types/types.d.ts.map +1 -0
- package/build/types/utils.d.ts +18 -0
- package/build/types/utils.d.ts.map +1 -0
- package/jest.config.cjs +19 -0
- package/package.json +44 -21
- package/src/index.ts +77 -13
- package/src/modules/_.ts +6 -3
- package/src/modules/did.ts +36 -8
- package/src/modules/resource.ts +34 -9
- package/src/querier.ts +4 -1
- package/src/registry.ts +1 -3
- package/src/signer.ts +50 -11
- package/src/types.ts +14 -5
- package/src/utils.ts +12 -9
- package/tests/index.test.ts +24 -5
- package/tests/modules/did.test.ts +25 -5
- package/tests/modules/resource.test.ts +214 -8
- package/tests/signer.test.ts +29 -6
- package/tests/testutils.test.ts +6 -1
- package/tests/utils.test.ts +14 -3
- package/tsconfig.cjs.json +8 -0
- package/tsconfig.esm.json +8 -0
- package/tsconfig.json +9 -5
- package/tsconfig.types.json +10 -0
- package/build/index.d.ts +0 -40
- package/build/index.d.ts.map +0 -1
- package/build/index.js +0 -97
- package/build/index.js.map +0 -1
- package/build/modules/_.d.ts.map +0 -1
- package/build/modules/_.js.map +0 -1
- package/build/modules/did.d.ts.map +0 -1
- package/build/modules/did.js.map +0 -1
- package/build/modules/resource.d.ts.map +0 -1
- package/build/modules/resource.js.map +0 -1
- package/build/querier.d.ts.map +0 -1
- package/build/querier.js.map +0 -1
- package/build/registry.d.ts.map +0 -1
- package/build/registry.js.map +0 -1
- package/build/signer.d.ts.map +0 -1
- package/build/signer.js.map +0 -1
- package/build/types.d.ts.map +0 -1
- package/build/types.js.map +0 -1
- package/build/utils.d.ts.map +0 -1
- package/build/utils.js.map +0 -1
- package/jest.config.js +0 -6
package/src/types.ts
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
Service as ProtobufService,
|
|
3
|
+
VerificationMethod as ProtobufVerificationMethod
|
|
4
|
+
} from "@cheqd/ts-proto/cheqd/did/v2"
|
|
5
|
+
import { CheqdSDK } from "./index.js"
|
|
3
6
|
import { Coin } from "@cosmjs/proto-signing"
|
|
4
7
|
import { Signer } from "did-jwt"
|
|
5
8
|
import { QueryClient } from "@cosmjs/stargate"
|
|
6
9
|
import { DIDResolutionResult } from "did-resolver"
|
|
7
|
-
import { DidExtension } from "./modules/did"
|
|
8
|
-
import { ResourceExtension } from './modules/resource';
|
|
9
|
-
export {
|
|
10
|
+
import { DidExtension } from "./modules/did.js"
|
|
11
|
+
import { ResourceExtension } from './modules/resource.js';
|
|
12
|
+
export {
|
|
13
|
+
DIDDocument,
|
|
14
|
+
VerificationMethod,
|
|
15
|
+
Service,
|
|
16
|
+
ServiceEndpoint,
|
|
17
|
+
JsonWebKey
|
|
18
|
+
} from "did-resolver"
|
|
10
19
|
|
|
11
20
|
export enum CheqdNetwork {
|
|
12
21
|
Mainnet = 'mainnet',
|
package/src/utils.ts
CHANGED
|
@@ -13,13 +13,20 @@ import {
|
|
|
13
13
|
DIDDocument,
|
|
14
14
|
SpecValidationResult,
|
|
15
15
|
JsonWebKey,
|
|
16
|
-
} from "./types"
|
|
17
|
-
import {
|
|
16
|
+
} from "./types.js"
|
|
17
|
+
import {
|
|
18
|
+
fromString,
|
|
19
|
+
toString
|
|
20
|
+
} from 'uint8arrays'
|
|
18
21
|
import { bases } from "multiformats/basics"
|
|
19
22
|
import { base64ToBytes } from "did-jwt"
|
|
20
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
generateKeyPair,
|
|
25
|
+
generateKeyPairFromSeed,
|
|
26
|
+
KeyPair
|
|
27
|
+
} from '@stablelib/ed25519'
|
|
28
|
+
import { sha256 } from '@cosmjs/crypto'
|
|
21
29
|
import { v4 } from 'uuid'
|
|
22
|
-
import { createHash } from 'crypto'
|
|
23
30
|
import {
|
|
24
31
|
VerificationMethod as ProtoVerificationMethod,
|
|
25
32
|
Service as ProtoService,
|
|
@@ -107,7 +114,7 @@ export function createVerificationKeys(publicKey: string, algo: MethodSpecificId
|
|
|
107
114
|
switch (algo) {
|
|
108
115
|
case MethodSpecificIdAlgo.Base58:
|
|
109
116
|
methodSpecificId = bases['base58btc'].encode(base64ToBytes(publicKey))
|
|
110
|
-
didUrl = `did:cheqd:${network}:${(bases['base58btc'].encode((
|
|
117
|
+
didUrl = `did:cheqd:${network}:${(bases['base58btc'].encode((sha256(base64ToBytes(publicKey))).slice(0,16))).slice(1)}`
|
|
111
118
|
return {
|
|
112
119
|
methodSpecificId,
|
|
113
120
|
didUrl,
|
|
@@ -229,10 +236,6 @@ export function validateSpecCompliantPayload(didDocument: DIDDocument): SpecVali
|
|
|
229
236
|
return { valid: true, protobufVerificationMethod: protoVerificationMethod, protobufService: protoService }
|
|
230
237
|
}
|
|
231
238
|
|
|
232
|
-
function sha256(message: string) {
|
|
233
|
-
return createHash('sha256').update(message).digest('hex')
|
|
234
|
-
}
|
|
235
|
-
|
|
236
239
|
function toMultibaseRaw(key: Uint8Array) {
|
|
237
240
|
const multibase = new Uint8Array(MULTICODEC_ED25519_HEADER.length + key.length);
|
|
238
241
|
|
package/tests/index.test.ts
CHANGED
|
@@ -1,13 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
DirectSecp256k1HdWallet,
|
|
3
|
+
GeneratedType
|
|
4
|
+
} from '@cosmjs/proto-signing'
|
|
5
|
+
import {
|
|
6
|
+
createCheqdSDK,
|
|
7
|
+
DIDModule,
|
|
8
|
+
ICheqdSDKOptions,
|
|
9
|
+
ResourceModule
|
|
10
|
+
} from '../src/index'
|
|
11
|
+
import {
|
|
12
|
+
localnet,
|
|
13
|
+
faucet
|
|
14
|
+
} from './testutils.test'
|
|
4
15
|
import { AbstractCheqdSDKModule } from '../src/modules/_'
|
|
5
16
|
import { CheqdSigningStargateClient } from '../src/signer'
|
|
6
17
|
import { createDefaultCheqdRegistry } from '../src/registry'
|
|
7
18
|
import { CheqdQuerier } from '../src/querier'
|
|
8
|
-
import {
|
|
19
|
+
import {
|
|
20
|
+
setupDidExtension,
|
|
21
|
+
DidExtension,
|
|
22
|
+
defaultDidExtensionKey
|
|
23
|
+
} from '../src/modules/did';
|
|
9
24
|
import { QueryExtensionSetup } from '../src/types'
|
|
10
|
-
import {
|
|
25
|
+
import {
|
|
26
|
+
setupResourceExtension,
|
|
27
|
+
ResourceExtension,
|
|
28
|
+
defaultResourceExtensionKey
|
|
29
|
+
} from '../src/modules/resource';
|
|
11
30
|
|
|
12
31
|
describe(
|
|
13
32
|
'CheqdSDK', () => {
|
|
@@ -1,14 +1,34 @@
|
|
|
1
1
|
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing"
|
|
2
2
|
import { DeliverTxResponse } from "@cosmjs/stargate"
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
fromString,
|
|
5
|
+
toString
|
|
6
|
+
} from 'uint8arrays'
|
|
4
7
|
import { DIDModule } from "../../src"
|
|
5
8
|
import { createDefaultCheqdRegistry } from "../../src/registry"
|
|
6
9
|
import { CheqdSigningStargateClient } from "../../src/signer"
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
import {
|
|
11
|
+
DIDDocument,
|
|
12
|
+
ISignInputs,
|
|
13
|
+
MethodSpecificIdAlgo,
|
|
14
|
+
VerificationMethods
|
|
15
|
+
} from "../../src/types"
|
|
16
|
+
import {
|
|
17
|
+
createDidPayload,
|
|
18
|
+
createDidVerificationMethod,
|
|
19
|
+
createKeyPairBase64,
|
|
20
|
+
createVerificationKeys
|
|
21
|
+
} from "../../src/utils"
|
|
22
|
+
import {
|
|
23
|
+
localnet,
|
|
24
|
+
faucet,
|
|
25
|
+
containsAll
|
|
26
|
+
} from "../testutils.test"
|
|
10
27
|
import { CheqdQuerier } from '../../src/querier';
|
|
11
|
-
import {
|
|
28
|
+
import {
|
|
29
|
+
setupDidExtension,
|
|
30
|
+
DidExtension
|
|
31
|
+
} from '../../src/modules/did';
|
|
12
32
|
import { v4 } from "uuid"
|
|
13
33
|
|
|
14
34
|
const defaultAsyncTxTimeout = 30000
|
|
@@ -1,17 +1,51 @@
|
|
|
1
1
|
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing"
|
|
2
2
|
import { DeliverTxResponse } from "@cosmjs/stargate"
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import {
|
|
4
|
+
fromString,
|
|
5
|
+
toString
|
|
6
|
+
} from 'uint8arrays'
|
|
7
|
+
import {
|
|
8
|
+
DIDModule,
|
|
9
|
+
ResourceModule
|
|
10
|
+
} from "../../src"
|
|
5
11
|
import { createDefaultCheqdRegistry } from "../../src/registry"
|
|
6
12
|
import { CheqdSigningStargateClient } from "../../src/signer"
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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';
|
|
11
39
|
import { v4 } from "uuid"
|
|
12
40
|
import { CheqdQuerier } from "../../src/querier"
|
|
13
|
-
import {
|
|
14
|
-
|
|
41
|
+
import {
|
|
42
|
+
setupResourceExtension,
|
|
43
|
+
ResourceExtension
|
|
44
|
+
} from '../../src/modules/resource';
|
|
45
|
+
import {
|
|
46
|
+
DidExtension,
|
|
47
|
+
setupDidExtension
|
|
48
|
+
} from "../../src/modules/did"
|
|
15
49
|
import { sha256 } from "@cosmjs/crypto"
|
|
16
50
|
|
|
17
51
|
const defaultAsyncTxTimeout = 30000
|
|
@@ -782,4 +816,176 @@ describe('ResourceModule', () => {
|
|
|
782
816
|
expect(metadata?.nextVersionId).toBe('')
|
|
783
817
|
}, defaultAsyncTxTimeout)
|
|
784
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
|
+
})
|
|
785
991
|
})
|
package/tests/signer.test.ts
CHANGED
|
@@ -1,12 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
MsgCreateDidDoc,
|
|
3
|
+
MsgCreateDidDocPayload,
|
|
4
|
+
VerificationMethod
|
|
5
|
+
} from "@cheqd/ts-proto/cheqd/did/v2"
|
|
6
|
+
import {
|
|
7
|
+
DirectSecp256k1HdWallet,
|
|
8
|
+
Registry
|
|
9
|
+
} from "@cosmjs/proto-signing"
|
|
3
10
|
import { EdDSASigner } from "did-jwt"
|
|
4
11
|
import { typeUrlMsgCreateDidDoc } from '../src/modules/did'
|
|
5
12
|
import { CheqdSigningStargateClient } from "../src/signer"
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
13
|
+
import {
|
|
14
|
+
ISignInputs,
|
|
15
|
+
MethodSpecificIdAlgo,
|
|
16
|
+
VerificationMethods
|
|
17
|
+
} from "../src/types"
|
|
18
|
+
import {
|
|
19
|
+
fromString,
|
|
20
|
+
toString
|
|
21
|
+
} from 'uint8arrays'
|
|
22
|
+
import {
|
|
23
|
+
createDidPayload,
|
|
24
|
+
createDidVerificationMethod,
|
|
25
|
+
createKeyPairBase64,
|
|
26
|
+
createVerificationKeys,
|
|
27
|
+
validateSpecCompliantPayload
|
|
28
|
+
} from '../src/utils';
|
|
29
|
+
import {
|
|
30
|
+
localnet,
|
|
31
|
+
faucet
|
|
32
|
+
} from "./testutils.test"
|
|
10
33
|
import { verify } from "@stablelib/ed25519"
|
|
11
34
|
import { v4 } from "uuid"
|
|
12
35
|
|
package/tests/testutils.test.ts
CHANGED
|
@@ -9,7 +9,7 @@ export const faucet = {
|
|
|
9
9
|
|
|
10
10
|
export const localnet = {
|
|
11
11
|
network: 'testnet',
|
|
12
|
-
rpcUrl: '
|
|
12
|
+
rpcUrl: 'http://localhost:26657',
|
|
13
13
|
gasPrice: GasPrice.fromString( `50${faucet.minimalDenom}` )
|
|
14
14
|
}
|
|
15
15
|
|
|
@@ -21,4 +21,9 @@ export const default_content = '<p>Test file content</p>'
|
|
|
21
21
|
|
|
22
22
|
export function containsAll<T>(array: T[], values: T[]): boolean {
|
|
23
23
|
return values.every(value => array.includes(value))
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function containsAllButOmittedFields<T extends Record<string, any>>(array: T[], values: T[], omit: string[]): boolean {
|
|
27
|
+
const replacer = (key: string, value: any) => omit.includes(key) ? undefined : value
|
|
28
|
+
return values.every(value => array.some(item => JSON.stringify(item, replacer) === JSON.stringify(value, replacer)))
|
|
24
29
|
}
|
package/tests/utils.test.ts
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
TImportableEd25519Key,
|
|
3
|
+
createSignInputsFromImportableEd25519Key
|
|
4
|
+
} from '../src/utils'
|
|
5
|
+
import {
|
|
6
|
+
createDidVerificationMethod,
|
|
7
|
+
createVerificationKeys,
|
|
8
|
+
createKeyPairRaw
|
|
9
|
+
} from '../src/utils'
|
|
3
10
|
import { toString } from 'uint8arrays'
|
|
4
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
IKeyPair,
|
|
13
|
+
MethodSpecificIdAlgo,
|
|
14
|
+
VerificationMethods
|
|
15
|
+
} from '../src/types'
|
|
5
16
|
|
|
6
17
|
describe('createSignInputsFromImportableEd25519Key', () => {
|
|
7
18
|
it('should create a sign input from an importable ed25519 key 2020', async () => {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"module": "commonjs", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
|
|
5
|
+
"outDir": "build/cjs", /* Redirect output structure to the directory. */
|
|
6
|
+
"target": "esnext", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
|
|
7
|
+
}
|
|
8
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"module": "esnext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
|
|
5
|
+
"outDir": "build/esm", /* Redirect output structure to the directory. */
|
|
6
|
+
"target": "esnext", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
|
|
7
|
+
}
|
|
8
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
/* Basic Options */
|
|
6
6
|
// "incremental": true, /* Enable incremental compilation */
|
|
7
|
-
"target": "esnext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
|
|
8
|
-
"module": "
|
|
7
|
+
// "target": "esnext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
|
|
8
|
+
// "module": "nodenext", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
|
|
9
9
|
// "lib": [], /* Specify library files to be included in the compilation. */
|
|
10
10
|
// "allowJs": true, /* Allow javascript files to be compiled. */
|
|
11
11
|
// "checkJs": true, /* Report errors in .js files. */
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
|
15
15
|
"sourceMap": true, /* Generates corresponding '.map' file. */
|
|
16
16
|
// "outFile": "./", /* Concatenate and emit output to single file. */
|
|
17
|
-
"outDir": "build", /* Redirect output structure to the directory. */
|
|
17
|
+
// "outDir": "build", /* Redirect output structure to the directory. */
|
|
18
18
|
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
|
19
19
|
// "composite": true, /* Enable project compilation */
|
|
20
20
|
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
|
|
44
44
|
/* Module Resolution Options */
|
|
45
45
|
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
|
46
|
+
"resolveJsonModule": true, /* Include modules imported with '.json' extension. */
|
|
46
47
|
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
|
47
48
|
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
|
48
49
|
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
|
@@ -50,9 +51,8 @@
|
|
|
50
51
|
"types": [
|
|
51
52
|
"@types/node",
|
|
52
53
|
"@types/jest",
|
|
53
|
-
"@types/long"
|
|
54
54
|
], /* Type declaration files to be included in compilation. */
|
|
55
|
-
|
|
55
|
+
"allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
|
56
56
|
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
|
57
57
|
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
|
58
58
|
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
@@ -71,6 +71,10 @@
|
|
|
71
71
|
"skipLibCheck": true, /* Skip type checking of declaration files. */
|
|
72
72
|
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
|
|
73
73
|
},
|
|
74
|
+
"ts-node": {
|
|
75
|
+
"esm": true,
|
|
76
|
+
"experimentalSpecifierResolution": "node"
|
|
77
|
+
},
|
|
74
78
|
"include": [
|
|
75
79
|
"src"
|
|
76
80
|
],
|
package/build/index.d.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { OfflineSigner } from '@cosmjs/proto-signing';
|
|
2
|
-
import { DIDModule, MinimalImportableDIDModule, DidExtension } from './modules/did';
|
|
3
|
-
import { MinimalImportableResourceModule, ResourceModule, ResourceExtension } from './modules/resource';
|
|
4
|
-
import { AbstractCheqdSDKModule } from './modules/_';
|
|
5
|
-
import { CheqdSigningStargateClient } from './signer';
|
|
6
|
-
import { CheqdNetwork, IModuleMethodMap } from './types';
|
|
7
|
-
import { createSignInputsFromImportableEd25519Key } from './utils';
|
|
8
|
-
import { GasPrice } from '@cosmjs/stargate';
|
|
9
|
-
import { CheqdQuerier } from './querier';
|
|
10
|
-
export interface ICheqdSDKOptions {
|
|
11
|
-
modules: AbstractCheqdSDKModule[];
|
|
12
|
-
querierExtensions?: Record<string, any>[];
|
|
13
|
-
rpcUrl: string;
|
|
14
|
-
network?: CheqdNetwork;
|
|
15
|
-
gasPrice?: GasPrice;
|
|
16
|
-
authorizedMethods?: string[];
|
|
17
|
-
readonly wallet: OfflineSigner;
|
|
18
|
-
}
|
|
19
|
-
export type DefaultCheqdSDKModules = MinimalImportableDIDModule & MinimalImportableResourceModule;
|
|
20
|
-
export interface CheqdSDK extends DefaultCheqdSDKModules {
|
|
21
|
-
}
|
|
22
|
-
export declare class CheqdSDK {
|
|
23
|
-
methods: IModuleMethodMap;
|
|
24
|
-
signer: CheqdSigningStargateClient;
|
|
25
|
-
querier: CheqdQuerier & DidExtension & ResourceExtension;
|
|
26
|
-
options: ICheqdSDKOptions;
|
|
27
|
-
private protectedMethods;
|
|
28
|
-
constructor(options: ICheqdSDKOptions);
|
|
29
|
-
execute<P = any, R = any>(method: string, ...params: P[]): Promise<R>;
|
|
30
|
-
private loadModules;
|
|
31
|
-
private loadRegistry;
|
|
32
|
-
private loadQuerierExtensions;
|
|
33
|
-
build(): Promise<CheqdSDK>;
|
|
34
|
-
}
|
|
35
|
-
export declare function filterUnauthorizedMethods(methods: IModuleMethodMap, authorizedMethods: string[], protectedMethods: string[]): IModuleMethodMap;
|
|
36
|
-
export declare function createCheqdSDK(options: ICheqdSDKOptions): Promise<CheqdSDK>;
|
|
37
|
-
export { DIDModule, ResourceModule };
|
|
38
|
-
export { createSignInputsFromImportableEd25519Key };
|
|
39
|
-
export { createKeyPairRaw, createKeyPairBase64, createKeyPairHex, createVerificationKeys, createDidVerificationMethod, createDidPayload } from './utils';
|
|
40
|
-
//# sourceMappingURL=index.d.ts.map
|
package/build/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAY,MAAM,uBAAuB,CAAA;AAC/D,OAAO,EAAE,SAAS,EAAE,0BAA0B,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACpF,OAAO,EAAE,+BAA+B,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACxG,OAAO,EAAE,sBAAsB,EAAkI,MAAM,aAAa,CAAC;AAErL,OAAO,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAA;AACrD,OAAO,EAAE,YAAY,EAAY,gBAAgB,EAAE,MAAM,SAAS,CAAC;AACnE,OAAO,EAAE,wCAAwC,EAAE,MAAM,SAAS,CAAA;AAClE,OAAO,EAAE,QAAQ,EAAe,MAAM,kBAAkB,CAAA;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAGxC,MAAM,WAAW,gBAAgB;IAChC,OAAO,EAAE,sBAAsB,EAAE,CAAA;IACjC,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAA;IACzC,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,YAAY,CAAA;IACtB,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAA;IAC5B,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAA;CAC9B;AAED,MAAM,MAAM,sBAAsB,GAAG,0BAA0B,GAAG,+BAA+B,CAAA;AAEjG,MAAM,WAAW,QAAS,SAAQ,sBAAsB;CAAG;AAE3D,qBAAa,QAAQ;IACpB,OAAO,EAAE,gBAAgB,CAAA;IACzB,MAAM,EAAE,0BAA0B,CAAA;IAClC,OAAO,EAAE,YAAY,GAAG,YAAY,GAAG,iBAAiB,CAAA;IACxD,OAAO,EAAE,gBAAgB,CAAA;IACzB,OAAO,CAAC,gBAAgB,CAAoE;gBAEhF,OAAO,EAAE,gBAAgB;IAgB/B,OAAO,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC;YAO7D,WAAW;IAgBtB,OAAO,CAAC,YAAY;YAOT,qBAAqB;IAM7B,KAAK,IAAI,OAAO,CAAC,QAAQ,CAAC;CAehC;AAED,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,EAAE,EAAE,gBAAgB,EAAE,MAAM,EAAE,GAAG,gBAAgB,CAU9I;AAED,wBAAsB,cAAc,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAEjF;AAED,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,CAAA;AACpC,OAAO,EAAE,wCAAwC,EAAE,CAAA;AACnD,OAAO,EACN,gBAAgB,EAChB,mBAAmB,EACnB,gBAAgB,EAChB,sBAAsB,EACtB,2BAA2B,EAC3B,gBAAgB,EAChB,MAAM,SAAS,CAAA"}
|