@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.
Files changed (45) hide show
  1. package/.github/workflows/build.yml +3 -2
  2. package/.github/workflows/dispatch.yml +7 -1
  3. package/.github/workflows/test.yml +62 -0
  4. package/CHANGELOG.md +23 -0
  5. package/build/modules/did.d.ts +41 -28
  6. package/build/modules/did.d.ts.map +1 -1
  7. package/build/modules/did.js +55 -28
  8. package/build/modules/did.js.map +1 -1
  9. package/build/modules/resource.d.ts +1 -2
  10. package/build/modules/resource.d.ts.map +1 -1
  11. package/build/modules/resource.js +7 -33
  12. package/build/modules/resource.js.map +1 -1
  13. package/build/signer.d.ts +4 -4
  14. package/build/signer.d.ts.map +1 -1
  15. package/build/signer.js +22 -11
  16. package/build/signer.js.map +1 -1
  17. package/build/types.d.ts +4 -0
  18. package/build/types.d.ts.map +1 -1
  19. package/build/types.js.map +1 -1
  20. package/build/utils.d.ts +4 -8
  21. package/build/utils.d.ts.map +1 -1
  22. package/build/utils.js +36 -22
  23. package/build/utils.js.map +1 -1
  24. package/docker/Dockerfile +55 -0
  25. package/docker/entrypoint.sh +58 -0
  26. package/docker/localnet/build-latest.env +7 -0
  27. package/docker/localnet/container-env/observer-0.env +13 -0
  28. package/docker/localnet/container-env/seed-0.env +17 -0
  29. package/docker/localnet/container-env/validator-0.env +13 -0
  30. package/docker/localnet/container-env/validator-1.env +13 -0
  31. package/docker/localnet/container-env/validator-2.env +13 -0
  32. package/docker/localnet/container-env/validator-3.env +13 -0
  33. package/docker/localnet/docker-compose.yml +281 -0
  34. package/docker/localnet/gen-network-config.sh +259 -0
  35. package/docker/localnet/import-keys.sh +31 -0
  36. package/package.json +2 -2
  37. package/src/modules/did.ts +100 -42
  38. package/src/modules/resource.ts +2 -31
  39. package/src/signer.ts +23 -10
  40. package/src/types.ts +5 -0
  41. package/src/utils.ts +44 -23
  42. package/tests/modules/did.test.ts +10 -8
  43. package/tests/modules/resource.test.ts +5 -3
  44. package/tests/signer.test.ts +9 -10
  45. package/tests/testutils.test.ts +25 -19
@@ -1,13 +1,13 @@
1
- import { MsgCreateDidPayload } from "@cheqd/ts-proto/cheqd/v1/tx"
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 { VerificationMethod } from "@cheqd/ts-proto/cheqd/v1/did"
10
- import { parseToKeyValuePair } from '../src/utils'
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: 'https://rpc.cheqd.network',
22
- gasPrice: GasPrice.fromString( `25${faucet.minimalDenom}` )
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}:${methodSpecificId.substring(0, length)}`
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
- publicKeyMultibase: verificationKeys[_].methodSpecificId,
104
- publicKeyJwk: []
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
- publicKeyJwk: parseToKeyValuePair(
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
- publicKeyMultibase: ''
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[]): MsgCreateDidPayload {
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 MsgCreateDidPayload.fromPartial(
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
+ }