@cheqd/sdk 1.4.0-develop.5 → 1.5.0-develop.1
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/build.yml +3 -2
- package/.github/workflows/dispatch.yml +7 -1
- package/.github/workflows/test.yml +62 -0
- package/CHANGELOG.md +23 -0
- package/build/modules/did.d.ts +41 -28
- package/build/modules/did.d.ts.map +1 -1
- package/build/modules/did.js +55 -28
- package/build/modules/did.js.map +1 -1
- package/build/modules/resource.d.ts +1 -2
- package/build/modules/resource.d.ts.map +1 -1
- package/build/modules/resource.js +7 -33
- package/build/modules/resource.js.map +1 -1
- package/build/signer.d.ts +4 -4
- package/build/signer.d.ts.map +1 -1
- package/build/signer.js +22 -11
- package/build/signer.js.map +1 -1
- package/build/types.d.ts +4 -0
- package/build/types.d.ts.map +1 -1
- package/build/types.js.map +1 -1
- package/build/utils.d.ts +4 -8
- package/build/utils.d.ts.map +1 -1
- package/build/utils.js +36 -22
- package/build/utils.js.map +1 -1
- package/docker/Dockerfile +55 -0
- package/docker/entrypoint.sh +58 -0
- package/docker/localnet/build-latest.env +7 -0
- package/docker/localnet/container-env/observer-0.env +13 -0
- package/docker/localnet/container-env/seed-0.env +17 -0
- package/docker/localnet/container-env/validator-0.env +13 -0
- package/docker/localnet/container-env/validator-1.env +13 -0
- package/docker/localnet/container-env/validator-2.env +13 -0
- package/docker/localnet/container-env/validator-3.env +13 -0
- package/docker/localnet/docker-compose.yml +281 -0
- package/docker/localnet/gen-network-config.sh +259 -0
- package/docker/localnet/import-keys.sh +31 -0
- package/package.json +2 -2
- package/src/modules/did.ts +100 -42
- package/src/modules/resource.ts +2 -31
- package/src/signer.ts +23 -10
- package/src/types.ts +5 -0
- package/src/utils.ts +44 -23
- package/tests/modules/did.test.ts +10 -8
- package/tests/modules/resource.test.ts +5 -3
- package/tests/signer.test.ts +9 -10
- package/tests/testutils.test.ts +25 -19
package/tests/testutils.test.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MsgCreateDidDocPayload, VerificationMethod } from "@cheqd/ts-proto/cheqd/did/v2"
|
|
2
2
|
import { CheqdNetwork, IKeyPair, IVerificationKeys, MethodSpecificIdAlgo, TMethodSpecificId, TVerificationKey, TVerificationKeyPrefix, VerificationMethods } from "../src/types"
|
|
3
3
|
import { bases } from 'multiformats/basics'
|
|
4
|
-
import { base64ToBytes } from "did-jwt"
|
|
4
|
+
import { base58ToBytes, base64ToBytes } from "did-jwt"
|
|
5
5
|
import { fromString, toString } from 'uint8arrays'
|
|
6
6
|
import { generateKeyPair, KeyPair } from '@stablelib/ed25519'
|
|
7
7
|
import { GasPrice } from "@cosmjs/stargate"
|
|
8
8
|
import { v4 } from 'uuid'
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
9
|
+
import { createHash } from 'crypto'
|
|
10
|
+
import { convertKeyPairtoTImportableEd25519Key } from "../src/utils"
|
|
11
11
|
|
|
12
12
|
export const faucet = {
|
|
13
13
|
prefix: 'cheqd',
|
|
@@ -18,8 +18,8 @@ export const faucet = {
|
|
|
18
18
|
|
|
19
19
|
export const exampleCheqdNetwork = {
|
|
20
20
|
network: 'testnet',
|
|
21
|
-
rpcUrl: '
|
|
22
|
-
gasPrice: GasPrice.fromString( `
|
|
21
|
+
rpcUrl: 'http://localhost:26657',
|
|
22
|
+
gasPrice: GasPrice.fromString( `50${faucet.minimalDenom}` )
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
/**
|
|
@@ -68,7 +68,7 @@ export function createVerificationKeys(keyPair: IKeyPair, algo: MethodSpecificId
|
|
|
68
68
|
switch (algo) {
|
|
69
69
|
case MethodSpecificIdAlgo.Base58:
|
|
70
70
|
methodSpecificId = bases['base58btc'].encode(base64ToBytes(keyPair.publicKey))
|
|
71
|
-
didUrl = `did:cheqd:${network}:${
|
|
71
|
+
didUrl = `did:cheqd:${network}:${(bases['base58btc'].encode((fromString(sha256(keyPair.publicKey))).slice(0,16))).slice(1)}`
|
|
72
72
|
return {
|
|
73
73
|
methodSpecificId,
|
|
74
74
|
didUrl,
|
|
@@ -100,8 +100,10 @@ export function createDidVerificationMethod(verificationMethodTypes: Verificatio
|
|
|
100
100
|
id: verificationKeys[_].keyId,
|
|
101
101
|
type: type,
|
|
102
102
|
controller: verificationKeys[_].didUrl,
|
|
103
|
-
|
|
104
|
-
|
|
103
|
+
verificationMaterial: JSON.stringify({
|
|
104
|
+
publicKeyMultibase: verificationKeys[_].methodSpecificId,
|
|
105
|
+
publicKeyJwk: []
|
|
106
|
+
})
|
|
105
107
|
}
|
|
106
108
|
|
|
107
109
|
case VerificationMethods.JWK:
|
|
@@ -109,14 +111,14 @@ export function createDidVerificationMethod(verificationMethodTypes: Verificatio
|
|
|
109
111
|
id: verificationKeys[_].keyId,
|
|
110
112
|
type: type,
|
|
111
113
|
controller: verificationKeys[_].didUrl,
|
|
112
|
-
|
|
113
|
-
{
|
|
114
|
+
verificationMaterial: JSON.stringify({
|
|
115
|
+
publicKeyJwk: {
|
|
114
116
|
crv: 'Ed25519',
|
|
115
117
|
kty: 'OKP',
|
|
116
118
|
x: toString( fromString( verificationKeys[_].publicKey, 'base64pad' ), 'base64url' )
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
|
|
119
|
+
},
|
|
120
|
+
publicKeyMultibase: ''
|
|
121
|
+
})
|
|
120
122
|
}
|
|
121
123
|
}
|
|
122
124
|
}) ?? []
|
|
@@ -127,19 +129,23 @@ export function createDidVerificationMethod(verificationMethodTypes: Verificatio
|
|
|
127
129
|
*? Used for testing purposes.
|
|
128
130
|
** NOTE: The following utils are stable but subject to change at any given moment.
|
|
129
131
|
*/
|
|
130
|
-
export function createDidPayload(verificationMethods: VerificationMethod[], verificationKeys: IVerificationKeys[]):
|
|
132
|
+
export function createDidPayload(verificationMethods: VerificationMethod[], verificationKeys: IVerificationKeys[]): MsgCreateDidDocPayload {
|
|
131
133
|
if (!verificationMethods || verificationMethods.length === 0)
|
|
132
134
|
throw new Error('No verification methods provided')
|
|
133
135
|
if (!verificationKeys || verificationKeys.length === 0)
|
|
134
136
|
throw new Error('No verification keys provided')
|
|
135
|
-
|
|
136
137
|
const did = verificationKeys[0].didUrl
|
|
137
|
-
return
|
|
138
|
+
return MsgCreateDidDocPayload.fromPartial(
|
|
138
139
|
{
|
|
139
140
|
id: did,
|
|
140
141
|
controller: verificationKeys.map(key => key.didUrl),
|
|
141
142
|
verificationMethod: verificationMethods,
|
|
142
|
-
authentication: verificationKeys.map(key => key.keyId)
|
|
143
|
+
authentication: verificationKeys.map(key => key.keyId),
|
|
144
|
+
versionId: v4()
|
|
143
145
|
}
|
|
144
146
|
)
|
|
145
|
-
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function sha256(message: string) {
|
|
150
|
+
return createHash('sha256').update(message).digest('hex')
|
|
151
|
+
}
|