@docknetwork/wallet-sdk-wasm 0.4.22 → 1.5.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.
Files changed (193) hide show
  1. package/lib/{account-614e6414.js → account-bf00e5c0.js} +5 -5
  2. package/lib/{account-ee524484.js → account-e48dc9b6.js} +5 -5
  3. package/lib/core/polkadot-utils.js +18 -4
  4. package/lib/core/polkadot-utils.mjs +15 -2
  5. package/lib/index.js +16 -19
  6. package/lib/index.mjs +20 -23
  7. package/lib/modules/account.js +10 -5
  8. package/lib/modules/account.mjs +10 -5
  9. package/lib/modules/accounts.js +10 -5
  10. package/lib/modules/accounts.mjs +10 -5
  11. package/lib/modules/network-manager.js +4 -2
  12. package/lib/modules/network-manager.mjs +4 -2
  13. package/lib/modules/wallet.js +13 -8
  14. package/lib/modules/wallet.mjs +13 -8
  15. package/lib/rpc-server.js +16 -19
  16. package/lib/rpc-server.mjs +20 -23
  17. package/lib/services/blockchain/configs.js +7 -0
  18. package/lib/services/blockchain/configs.mjs +3 -0
  19. package/lib/services/{dock → blockchain}/index.android.js +3 -4
  20. package/lib/services/{dock → blockchain}/index.android.mjs +3 -4
  21. package/lib/services/{dock → blockchain}/index.ios.js +3 -4
  22. package/lib/services/{dock → blockchain}/index.ios.mjs +3 -4
  23. package/lib/services/blockchain/index.js +30 -0
  24. package/lib/services/blockchain/index.mjs +22 -0
  25. package/lib/services/{dock → blockchain}/service-rpc.js +5 -7
  26. package/lib/services/{dock → blockchain}/service-rpc.mjs +5 -7
  27. package/lib/services/blockchain/service.js +212 -0
  28. package/lib/services/blockchain/service.mjs +206 -0
  29. package/lib/services/credential/bbs-revocation.js +41 -60
  30. package/lib/services/credential/bbs-revocation.mjs +42 -57
  31. package/lib/services/credential/bound-check.js +0 -8
  32. package/lib/services/credential/bound-check.mjs +1 -5
  33. package/lib/services/credential/index.js +21 -24
  34. package/lib/services/credential/index.mjs +22 -25
  35. package/lib/services/credential/pex-helpers.js +134 -34
  36. package/lib/services/credential/pex-helpers.mjs +133 -35
  37. package/lib/services/credential/service.js +55 -56
  38. package/lib/services/credential/service.mjs +45 -43
  39. package/lib/services/credential/utils.js +12 -18
  40. package/lib/services/credential/utils.mjs +11 -14
  41. package/lib/services/dids/config.js +8 -0
  42. package/lib/services/dids/config.mjs +8 -0
  43. package/lib/services/dids/index.js +11 -10
  44. package/lib/services/dids/index.mjs +12 -11
  45. package/lib/services/dids/service-rpc.js +2 -2
  46. package/lib/services/dids/service-rpc.mjs +2 -2
  47. package/lib/services/dids/service.js +28 -36
  48. package/lib/services/dids/service.mjs +27 -33
  49. package/lib/services/edv/hmac.js +5 -0
  50. package/lib/services/edv/hmac.mjs +5 -0
  51. package/lib/services/edv/index.js +13 -11
  52. package/lib/services/edv/index.mjs +16 -14
  53. package/lib/services/edv/service-rpc.js +4 -0
  54. package/lib/services/edv/service-rpc.mjs +4 -0
  55. package/lib/services/edv/service.js +29 -13
  56. package/lib/services/edv/service.mjs +31 -16
  57. package/lib/services/example/service.js +3 -1
  58. package/lib/services/example/service.mjs +3 -1
  59. package/lib/services/index.js +14 -17
  60. package/lib/services/index.mjs +18 -21
  61. package/lib/services/keyring/configs.js +12 -0
  62. package/lib/services/keyring/configs.mjs +12 -0
  63. package/lib/services/keyring/service.js +5 -0
  64. package/lib/services/keyring/service.mjs +5 -0
  65. package/lib/services/pex/service.js +17 -15
  66. package/lib/services/pex/service.mjs +17 -15
  67. package/lib/services/relay-service/index.mjs +1 -1
  68. package/lib/services/relay-service/service.mjs +2 -2
  69. package/lib/services/substrate/api-utils.js +19 -6
  70. package/lib/services/substrate/api-utils.mjs +19 -6
  71. package/lib/services/substrate/index.js +14 -6
  72. package/lib/services/substrate/index.mjs +14 -6
  73. package/lib/services/substrate/service.js +17 -9
  74. package/lib/services/substrate/service.mjs +17 -9
  75. package/lib/services/test-utils.js +27 -17
  76. package/lib/services/test-utils.mjs +27 -17
  77. package/lib/services/trust-registry/index.js +17 -5
  78. package/lib/services/trust-registry/index.mjs +17 -5
  79. package/lib/services/trust-registry/service.js +27 -10
  80. package/lib/services/trust-registry/service.mjs +27 -10
  81. package/lib/services/util-crypto/configs.js +3 -0
  82. package/lib/services/util-crypto/configs.mjs +3 -0
  83. package/lib/services/util-crypto/service-rpc.js +6 -0
  84. package/lib/services/util-crypto/service-rpc.mjs +6 -0
  85. package/lib/services/util-crypto/service.js +5 -0
  86. package/lib/services/util-crypto/service.mjs +6 -1
  87. package/lib/setup-nodejs.js +16 -19
  88. package/lib/setup-nodejs.mjs +20 -23
  89. package/lib/setup-tests.js +16 -19
  90. package/lib/setup-tests.mjs +20 -23
  91. package/lib/src/core/polkadot-utils.d.ts +1 -0
  92. package/lib/src/core/polkadot-utils.d.ts.map +1 -1
  93. package/lib/src/modules/network-manager.d.ts +1 -0
  94. package/lib/src/modules/network-manager.d.ts.map +1 -1
  95. package/lib/src/services/blockchain/configs.d.ts +8 -0
  96. package/lib/src/services/blockchain/configs.d.ts.map +1 -0
  97. package/lib/src/services/blockchain/index.d.ts +2 -0
  98. package/lib/src/services/blockchain/index.d.ts.map +1 -0
  99. package/lib/src/services/blockchain/service.d.ts +52 -0
  100. package/lib/src/services/blockchain/service.d.ts.map +1 -0
  101. package/lib/src/services/credential/bbs-revocation.d.ts.map +1 -1
  102. package/lib/src/services/credential/bound-check.d.ts +0 -4
  103. package/lib/src/services/credential/bound-check.d.ts.map +1 -1
  104. package/lib/src/services/credential/index.d.ts +2 -7
  105. package/lib/src/services/credential/index.d.ts.map +1 -1
  106. package/lib/src/services/credential/pex-helpers.d.ts +5 -3
  107. package/lib/src/services/credential/pex-helpers.d.ts.map +1 -1
  108. package/lib/src/services/credential/service.d.ts +2 -7
  109. package/lib/src/services/credential/service.d.ts.map +1 -1
  110. package/lib/src/services/credential/utils.d.ts.map +1 -1
  111. package/lib/src/services/dids/config.d.ts +5 -0
  112. package/lib/src/services/dids/config.d.ts.map +1 -1
  113. package/lib/src/services/dids/service-rpc.d.ts +1 -1
  114. package/lib/src/services/dids/service-rpc.d.ts.map +1 -1
  115. package/lib/src/services/dids/service.d.ts +9 -4
  116. package/lib/src/services/dids/service.d.ts.map +1 -1
  117. package/lib/src/services/edv/hmac.d.ts +1 -0
  118. package/lib/src/services/edv/hmac.d.ts.map +1 -1
  119. package/lib/src/services/edv/service.d.ts +5 -0
  120. package/lib/src/services/edv/service.d.ts.map +1 -1
  121. package/lib/src/services/example/service.d.ts.map +1 -1
  122. package/lib/src/services/keyring/configs.d.ts +6 -0
  123. package/lib/src/services/keyring/configs.d.ts.map +1 -1
  124. package/lib/src/services/pex/service.d.ts.map +1 -1
  125. package/lib/src/services/trust-registry/service.d.ts.map +1 -1
  126. package/lib/src/services/util-crypto/configs.d.ts +1 -0
  127. package/lib/src/services/util-crypto/configs.d.ts.map +1 -1
  128. package/lib/src/services/util-crypto/service.d.ts +1 -0
  129. package/lib/src/services/util-crypto/service.d.ts.map +1 -1
  130. package/lib/test/setup-test-state.js +11 -6
  131. package/lib/test/setup-test-state.mjs +11 -6
  132. package/lib/tsconfig.tsbuildinfo +1 -1
  133. package/package.json +7 -4
  134. package/src/core/polkadot-utils.js +14 -3
  135. package/src/modules/network-manager.ts +5 -2
  136. package/src/modules/wallet.ts +5 -5
  137. package/src/services/blockchain/configs.ts +11 -0
  138. package/src/services/blockchain/index.android.js +3 -0
  139. package/src/services/blockchain/index.ios.js +3 -0
  140. package/src/services/blockchain/index.js +1 -0
  141. package/src/services/blockchain/index.test.js +34 -0
  142. package/src/services/{dock → blockchain}/service-rpc.js +5 -6
  143. package/src/services/blockchain/service.ts +261 -0
  144. package/src/services/credential/bbs-revocation.ts +41 -85
  145. package/src/services/credential/bound-check.test.ts +2 -5
  146. package/src/services/credential/bound-check.ts +0 -5
  147. package/src/services/credential/index.test.js +148 -7
  148. package/src/services/credential/pex-helpers.js +132 -34
  149. package/src/services/credential/pex-helpers.test.js +284 -27
  150. package/src/services/credential/service.ts +44 -27
  151. package/src/services/credential/utils.js +5 -14
  152. package/src/services/dids/config.ts +15 -0
  153. package/src/services/dids/index.test.js +5 -23
  154. package/src/services/dids/service-rpc.ts +2 -2
  155. package/src/services/dids/service.ts +34 -44
  156. package/src/services/edv/hmac.ts +13 -0
  157. package/src/services/edv/index.test.js +22 -0
  158. package/src/services/edv/service-rpc.js +4 -0
  159. package/src/services/edv/service.ts +22 -0
  160. package/src/services/example/service.ts +3 -1
  161. package/src/services/index.js +2 -2
  162. package/src/services/keyring/configs.ts +21 -0
  163. package/src/services/keyring/service.ts +13 -0
  164. package/src/services/pex/service.ts +29 -18
  165. package/src/services/pex/tests/pex-service.test.js +163 -6
  166. package/src/services/substrate/api-utils.test.js +7 -7
  167. package/src/services/substrate/api-utils.ts +3 -3
  168. package/src/services/substrate/service.ts +6 -6
  169. package/src/services/test-utils.js +13 -11
  170. package/src/services/trust-registry/index.test.js +6 -4
  171. package/src/services/trust-registry/service.ts +13 -7
  172. package/src/services/util-crypto/configs.ts +4 -0
  173. package/src/services/util-crypto/service-rpc.js +6 -0
  174. package/src/services/util-crypto/service.ts +8 -0
  175. package/src/test/setup-test-state.js +2 -2
  176. package/lib/services/dock/configs.js +0 -18
  177. package/lib/services/dock/configs.mjs +0 -10
  178. package/lib/services/dock/index.js +0 -17
  179. package/lib/services/dock/index.mjs +0 -9
  180. package/lib/services/dock/service.js +0 -138
  181. package/lib/services/dock/service.mjs +0 -126
  182. package/lib/src/services/dock/configs.d.ts +0 -7
  183. package/lib/src/services/dock/configs.d.ts.map +0 -1
  184. package/lib/src/services/dock/index.d.ts +0 -2
  185. package/lib/src/services/dock/index.d.ts.map +0 -1
  186. package/lib/src/services/dock/service.d.ts +0 -44
  187. package/lib/src/services/dock/service.d.ts.map +0 -1
  188. package/src/services/dock/configs.ts +0 -12
  189. package/src/services/dock/index.android.js +0 -3
  190. package/src/services/dock/index.ios.js +0 -3
  191. package/src/services/dock/index.js +0 -1
  192. package/src/services/dock/index.test.js +0 -48
  193. package/src/services/dock/service.ts +0 -154
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docknetwork/wallet-sdk-wasm",
3
- "version": "0.4.22",
3
+ "version": "1.5.0",
4
4
  "license": "https://github.com/docknetwork/react-native-sdk/LICENSE",
5
5
  "repository": {
6
6
  "type": "git",
@@ -15,7 +15,6 @@
15
15
  "resolutions": {
16
16
  "@polkadot/wasm-crypto": "6.3.1",
17
17
  "@polkadot/rpc-core": "9.7.1",
18
- "@docknetwork/sdk": "8.6.0",
19
18
  "@polkadot/api": "9.7.1",
20
19
  "@polkadot/keyring": "10.1.11",
21
20
  "@polkadot/rpc-provider": "9.7.1",
@@ -25,7 +24,9 @@
25
24
  "@polkadot/util-crypto": "10.1.11"
26
25
  },
27
26
  "dependencies": {
27
+ "@astronautlabs/jsonpath": "^1.1.2",
28
28
  "@docknetwork/universal-wallet": "^2.0.1",
29
+ "@docknetwork/wallet-sdk-dids": "^1.5.0",
29
30
  "@polkadot/api": "9.7.1",
30
31
  "@polkadot/keyring": "10.1.11",
31
32
  "@polkadot/rpc-core": "9.7.1",
@@ -36,7 +37,8 @@
36
37
  "@polkadot/util": "10.1.11",
37
38
  "@polkadot/util-crypto": "10.1.11",
38
39
  "@polkadot/wasm-crypto": "6.3.1",
39
- "@docknetwork/sdk": "8.6.0",
40
+ "@docknetwork/credential-sdk": "0.44.0",
41
+ "@docknetwork/dock-blockchain-modules": "0.26.2",
40
42
  "@sphereon/oid4vci-client": "^0.16.0",
41
43
  "@sphereon/oid4vci-common": "^0.16.0",
42
44
  "axios": "^0.25.0",
@@ -48,7 +50,8 @@
48
50
  "winston": "^3.3.3",
49
51
  "cwait": "1.1.2",
50
52
  "axios-retry": "^3.2.5",
51
- "@sphereon/pex": "^1.1.4"
53
+ "@sphereon/pex": "^1.1.4",
54
+ "@docknetwork/dock-blockchain-api": "0.6.1"
52
55
  },
53
56
  "devDependencies": {
54
57
  "@babel/node": "^7.16.0",
@@ -5,10 +5,8 @@ import {
5
5
  sr25519PairFromSeed,
6
6
  secp256k1PairFromSeed,
7
7
  } from '@polkadot/util-crypto';
8
-
8
+ import {Ed25519Keypair} from '@docknetwork/credential-sdk/keypairs';
9
9
  import {decodePair} from '@polkadot/keyring/pair/decode';
10
- import {getKeyPairType} from '@docknetwork/sdk/utils/misc';
11
-
12
10
  import * as bs58 from 'base58-universal';
13
11
 
14
12
  import {getKeypairFromDoc} from '@docknetwork/universal-wallet/methods/keypairs';
@@ -20,6 +18,19 @@ const polkadotTypesToKeys = {
20
18
  ecdsa: 'EcdsaSecp256k1VerificationKey2019',
21
19
  };
22
20
 
21
+ export function getKeyPairType(key) {
22
+ const keyType = key.type || key.constructor.VerKeyType;
23
+ if (keyType) {
24
+ return keyType;
25
+ }
26
+
27
+ if (key instanceof Ed25519Keypair) {
28
+ return 'Ed25519VerificationKey2018';
29
+ }
30
+
31
+ throw new Error(`Unknown key type for ${key.constructor.name}`);
32
+ }
33
+
23
34
  const TYPE_FROM_SEED = {
24
35
  ecdsa: secp256k1PairFromSeed,
25
36
  secp256k1: secp256k1PairFromSeed,
@@ -5,6 +5,7 @@ export type NetworkInfo = {
5
5
  name: string,
6
6
  substrateUrl: string | string[],
7
7
  addressPrefix: number,
8
+ cheqdApiUrl: string,
8
9
  };
9
10
 
10
11
  export type NetworkId = 'mainnet' | 'testnet' | 'local' | 'custom';
@@ -12,13 +13,15 @@ export type NetworkId = 'mainnet' | 'testnet' | 'local' | 'custom';
12
13
  export const SUBSTRATE_NETWORKS : Record<NetworkId, NetworkInfo> = {
13
14
  mainnet: {
14
15
  name: 'Dock PoS Mainnet',
15
- substrateUrl: ['wss://mainnet-node.dock.io', 'wss://mainnet-node-2.dock.io'],
16
+ substrateUrl: null,
16
17
  addressPrefix: 22,
18
+ cheqdApiUrl: 'https://mainnet.cheqd.docknode.io/',
17
19
  },
18
20
  testnet: {
19
21
  name: 'Dock PoS Testnet',
20
- substrateUrl: 'wss://knox-1.dock.io',
22
+ substrateUrl: null,
21
23
  addressPrefix: 21,
24
+ cheqdApiUrl: 'https://testnet.cheqd.docknode.io/',
22
25
  },
23
26
  local: {
24
27
  name: 'Local Node',
@@ -2,7 +2,7 @@
2
2
  import assert from 'assert';
3
3
  import {v4 as uuid} from 'uuid';
4
4
  import {getStorage} from '../core/storage';
5
- import {dockService} from '../services/dock';
5
+ import {blockchainService} from '../services/blockchain';
6
6
  import {keyringService} from '../services/keyring';
7
7
  import {utilCryptoService} from '../services/util-crypto';
8
8
  import {walletService} from '../services/wallet';
@@ -165,7 +165,7 @@ class Wallet {
165
165
  * Close wallet
166
166
  */
167
167
  async close() {
168
- await dockService.disconnect();
168
+ await blockchainService.disconnect();
169
169
  this.setStatus('closed');
170
170
  }
171
171
 
@@ -227,13 +227,13 @@ class Wallet {
227
227
  });
228
228
 
229
229
  Logger.debug(`Initializing network ${JSON.stringify(networkInfo)}`);
230
- const isDockConnected = await dockService.isApiConnected();
230
+ const isDockConnected = await blockchainService.isApiConnected();
231
231
 
232
232
  if (isDockConnected) {
233
- await dockService.disconnect();
233
+ await blockchainService.disconnect();
234
234
  }
235
235
 
236
- await dockService.init({
236
+ await blockchainService.init({
237
237
  address: networkInfo.substrateUrl,
238
238
  });
239
239
 
@@ -0,0 +1,11 @@
1
+ // @ts-nocheck
2
+ import assert from 'assert';
3
+
4
+ export const validation = {};
5
+
6
+ export type InitParams = {
7
+ substrateUrl: string,
8
+ cheqdApiUrl?: string,
9
+ networkId?: string,
10
+ cheqdMnemonic?: string,
11
+ };
@@ -0,0 +1,3 @@
1
+ import {BlockchainServiceRpc} from './service-rpc';
2
+
3
+ export const blockchainService = new BlockchainServiceRpc();
@@ -0,0 +1,3 @@
1
+ import {BlockchainServiceRpc} from './service-rpc';
2
+
3
+ export const blockchainService = new BlockchainServiceRpc();
@@ -0,0 +1 @@
1
+ export {blockchainService} from './service';
@@ -0,0 +1,34 @@
1
+ import {NetworkManager} from '../../modules/network-manager';
2
+ import {assertRpcService, mockDockSdkConnection} from '../test-utils';
3
+ import {validation} from './configs';
4
+ import {blockchainService as service} from './service';
5
+ import {BlockchainServiceRpc} from './service-rpc';
6
+
7
+ const doConnect = (
8
+ address = NetworkManager.getInstance().getNetworkInfo().substrateUrl,
9
+ ) =>
10
+ service.init({
11
+ address,
12
+ });
13
+
14
+ describe('DockService', () => {
15
+ it('ServiceRpc', () => {
16
+ assertRpcService(BlockchainServiceRpc, service, validation);
17
+ });
18
+
19
+ describe('init', () => {
20
+ afterEach(async () => {
21
+ await service.disconnect();
22
+ });
23
+
24
+ it('connect and disconnect substrate node', async () => {
25
+ const mock = mockDockSdkConnection();
26
+ const result = await doConnect();
27
+ expect(result).toBe(true);
28
+ expect(service.isBlockchainReady).toBeTruthy();
29
+ await service.disconnect();
30
+ expect(service.isBlockchainReady).toBeFalsy();
31
+ mock.clear();
32
+ });
33
+ });
34
+ });
@@ -1,12 +1,12 @@
1
1
  import {RpcService} from '../rpc-service-client';
2
- import {InitParams, validation} from './configs';
2
+ import {InitParams} from './configs';
3
3
 
4
4
  /**
5
5
  *
6
6
  */
7
- export class DockServiceRpc extends RpcService {
7
+ export class BlockchainServiceRpc extends RpcService {
8
8
  constructor() {
9
- super('dock');
9
+ super('blockchain');
10
10
  }
11
11
 
12
12
  /**
@@ -19,15 +19,14 @@ export class DockServiceRpc extends RpcService {
19
19
  /**
20
20
  *
21
21
  */
22
- ensureDockReady(): Promise<any> {
23
- return this.call('ensureDockReady');
22
+ ensureBlockchainReady(): Promise<any> {
23
+ return this.call('ensureBlockchainReady');
24
24
  }
25
25
 
26
26
  /**
27
27
  *
28
28
  */
29
29
  init(params: InitParams): Promise<any> {
30
- validation.init(params);
31
30
  return this.call('init', params);
32
31
  }
33
32
 
@@ -0,0 +1,261 @@
1
+ // @ts-nocheck
2
+
3
+ import {DirectSecp256k1HdWallet} from '@cosmjs/proto-signing';
4
+ import {CheqdAPI} from '@docknetwork/cheqd-blockchain-api';
5
+ import {CheqdCoreModules} from '@docknetwork/cheqd-blockchain-modules';
6
+ import {MultiApiCoreModules} from '@docknetwork/credential-sdk/modules';
7
+ import {
8
+ CoreResolver,
9
+ DIDKeyResolver,
10
+ ResolverRouter,
11
+ UniversalResolver,
12
+ WILDCARD,
13
+ } from '@docknetwork/credential-sdk/resolver';
14
+ import {initializeWasm} from '@docknetwork/crypto-wasm-ts/lib/index';
15
+
16
+ import {DockAPI} from '@docknetwork/dock-blockchain-api';
17
+ import {
18
+ DockCoreModules,
19
+ DockDIDModule,
20
+ } from '@docknetwork/dock-blockchain-modules';
21
+ import {EventEmitter} from 'events';
22
+ import {Logger} from '../../core/logger';
23
+ import {once} from '../../modules/event-manager';
24
+ import {utilCryptoService} from '../util-crypto';
25
+ import {InitParams} from './configs';
26
+
27
+ export const universalResolverUrl = 'https://uniresolver.truvera.io';
28
+
29
+ import {
30
+ CheqdAccumulatorCommon,
31
+ CheqdAccumulatorId,
32
+ CheqdAccumulatorPublicKey,
33
+ DockAccumulatorCommon,
34
+ DockAccumulatorId,
35
+ DockAccumulatorPublicKey,
36
+ } from '@docknetwork/credential-sdk/types';
37
+
38
+ class AnyDIDResolver extends ResolverRouter {
39
+ method = WILDCARD;
40
+ }
41
+
42
+ const {AccumulatorModule: AccumulatorModuleDock} = DockCoreModules;
43
+ const {AccumulatorModule: AccumulatorModuleCheqd} = CheqdCoreModules;
44
+
45
+ const TYPES_FOR_DID = {
46
+ dock: {
47
+ PublicKey: DockAccumulatorPublicKey,
48
+ AccumulatorId: DockAccumulatorId,
49
+ AccumulatorCommon: DockAccumulatorCommon,
50
+ AccumulatorModule: AccumulatorModuleDock,
51
+ },
52
+ cheqd: {
53
+ PublicKey: CheqdAccumulatorPublicKey,
54
+ AccumulatorId: CheqdAccumulatorId,
55
+ AccumulatorCommon: CheqdAccumulatorCommon,
56
+ AccumulatorModule: AccumulatorModuleCheqd,
57
+ },
58
+ };
59
+
60
+ /**
61
+ *
62
+ */
63
+ export class BlockchainService {
64
+ dock;
65
+ modules;
66
+ didModule;
67
+ cheqdApi;
68
+ isBlockchainReady = false;
69
+ resolver: any;
70
+ dockEnabled: boolean;
71
+ static Events = {
72
+ BLOCKCHAIN_READY: 'blockchain-ready',
73
+ };
74
+
75
+ rpcMethods = [
76
+ BlockchainService.prototype.disconnect,
77
+ BlockchainService.prototype.ensureBlockchainReady,
78
+ BlockchainService.prototype.init,
79
+ BlockchainService.prototype.isApiConnected,
80
+ BlockchainService.prototype.getAddress,
81
+ ];
82
+
83
+ constructor() {
84
+ this.name = 'blockchain';
85
+ this.dock = new DockAPI();
86
+ this.cheqdApi = new CheqdAPI();
87
+ this.didModule = new DockDIDModule(this.dock);
88
+ this.dockModules = new DockCoreModules(this.dock);
89
+ this.cheqdModules = new CheqdCoreModules(this.cheqdApi);
90
+ this.modules = new MultiApiCoreModules(
91
+ this.dockEnabled
92
+ ? [this.dockModules, this.cheqdModules]
93
+ : [this.cheqdModules],
94
+ );
95
+ this.emitter = new EventEmitter();
96
+ this.resolver = this.createDIDResolver();
97
+ }
98
+
99
+ getTypesForDIDOrAccumulator(didOrRegistryId) {
100
+ const didType = didOrRegistryId
101
+ .replace('dock:accumulator:', 'accumulator:dock:')
102
+ .split(':')[1];
103
+ const chainDidType = !this.dock && didType === 'dock' ? 'cheqd' : didType;
104
+ const types = TYPES_FOR_DID[chainDidType];
105
+ if (!types) {
106
+ throw new APIError(
107
+ `Unable to use DID type ${didType} for this operation`,
108
+ );
109
+ }
110
+ return types;
111
+ }
112
+
113
+ /**
114
+ *
115
+ * @returns
116
+ */
117
+ async ensureBlockchainReady() {
118
+ if (this.isBlockchainReady) {
119
+ return;
120
+ }
121
+
122
+ return once(this.emitter, BlockchainService.Events.BLOCKCHAIN_READY);
123
+ }
124
+
125
+ createDIDResolver() {
126
+ return new AnyDIDResolver([
127
+ new DIDKeyResolver(),
128
+ new CoreResolver(this.modules),
129
+ new UniversalResolver(universalResolverUrl),
130
+ ]);
131
+ }
132
+ /**
133
+ *
134
+ * @param {*} params
135
+ * @returns
136
+ */
137
+ async init(params: InitParams) {
138
+ if (this.dock.isConnected) {
139
+ await this.dock.disconnect();
140
+ }
141
+
142
+ if (this.cheqdApi && this.cheqdApi.isInitialized()) {
143
+ await this.cheqdApi.disconnect();
144
+ }
145
+
146
+ Logger.info(`Attempt to initialized substrate at: ${params.address}`);
147
+
148
+ this.dockEnabled = !!params.substrateUrl;
149
+
150
+ if (this.dockEnabled) {
151
+ await this.dock.init({
152
+ address: params.substrateUrl,
153
+ });
154
+ Logger.info(`Substrate initialized at: ${params.address}`);
155
+ }
156
+
157
+ this.modules = new MultiApiCoreModules(
158
+ this.dockEnabled
159
+ ? [this.dockModules, this.cheqdModules]
160
+ : [this.cheqdModules],
161
+ );
162
+
163
+ if (params?.cheqdApiUrl) {
164
+ const checkdApiUrl = params?.cheqdApiUrl;
165
+ const cheqdNetworkId = params?.networkId;
166
+ const cheqdMnemonic =
167
+ params?.cheqdMnemonic || (await utilCryptoService.mnemonicGenerate(12));
168
+
169
+ const wallet = await DirectSecp256k1HdWallet.fromMnemonic(cheqdMnemonic, {
170
+ prefix: 'cheqd',
171
+ });
172
+
173
+ const walletAccounts = await wallet.getAccounts();
174
+ const [{address}] = walletAccounts;
175
+ console.log('Using cheqd account:', address);
176
+
177
+ Logger.info(
178
+ `Attempt to initialized cheqd at: ${checkdApiUrl} with networkId: ${cheqdNetworkId}`,
179
+ );
180
+ Logger.info(`Using cheqd account: ${address}`);
181
+
182
+ try {
183
+ await this.cheqdApi.init({
184
+ wallet,
185
+ url: checkdApiUrl,
186
+ network: cheqdNetworkId,
187
+ });
188
+ Logger.info(`Cheqd initialized at: ${checkdApiUrl}`);
189
+ } catch (err) {
190
+ Logger.error(`Failed to initialize cheqd at: ${checkdApiUrl}`);
191
+ }
192
+ }
193
+
194
+ this.address = params.address;
195
+
196
+ this.resolver = this.createDIDResolver();
197
+
198
+ if (
199
+ process.env.NODE_ENV !== 'test' ||
200
+ process.env.API_MOCK_DISABLED === 'true'
201
+ ) {
202
+ await initializeWasm();
203
+ }
204
+
205
+ this._setBlockchainReady(true);
206
+
207
+ return true;
208
+ }
209
+
210
+ /**
211
+ *
212
+ * @returns
213
+ */
214
+ async disconnect() {
215
+ let result;
216
+
217
+ if (this.dockEnabled) {
218
+ result = await this.dock.disconnect();
219
+ }
220
+
221
+ if (this.cheqdApi && this.cheqdApi.isInitialized()) {
222
+ result = await this.cheqdApi.disconnect();
223
+ }
224
+
225
+ this._setBlockchainReady(false);
226
+
227
+ return result;
228
+ }
229
+
230
+ async waitBlockchainReady() {
231
+ return new Promise(resolve => {
232
+ if (this.isBlockchainReady) {
233
+ resolve();
234
+ } else {
235
+ this.emitter.once(BlockchainService.Events.BLOCKCHAIN_READY, resolve);
236
+ }
237
+ });
238
+ }
239
+
240
+ /**
241
+ *
242
+ * @returns
243
+ */
244
+ async isApiConnected() {
245
+ return this.cheqdApi.isInitialized();
246
+ }
247
+
248
+ async getAddress() {
249
+ return this.dock.address;
250
+ }
251
+
252
+ _setBlockchainReady(isBlockchainReady) {
253
+ this.isBlockchainReady = isBlockchainReady;
254
+
255
+ if (isBlockchainReady) {
256
+ this.emitter.emit(BlockchainService.Events.BLOCKCHAIN_READY);
257
+ }
258
+ }
259
+ }
260
+
261
+ export const blockchainService: BlockchainService = new BlockchainService();
@@ -7,9 +7,11 @@ import {
7
7
  VBWitnessUpdateInfo,
8
8
  Encoder,
9
9
  } from '@docknetwork/crypto-wasm-ts';
10
- import dock from '@docknetwork/sdk';
11
10
 
12
11
  import {hexToU8a} from '@polkadot/util';
12
+ import {
13
+ blockchainService,
14
+ } from '../blockchain/service';
13
15
 
14
16
  const trimHexID = id => {
15
17
  if (id.substr(0, 2) !== '0x') {
@@ -19,120 +21,74 @@ const trimHexID = id => {
19
21
  return id.substr(2);
20
22
  };
21
23
 
22
- // "-32000: Client error: UnknownBlock: State already discarded for BlockId::Hash(<hash>)"
23
- // This means that the node has discarded old blocks to preserve space. This should not happen with a full node
24
- const UnknownBlockErrorCode = -32000;
25
-
26
- async function updateMembershipWitness({
27
- credential,
28
- membershipWitness,
29
- registryId,
30
- blockNo,
31
- }) {
32
- const revocationId = credential.credentialStatus.revocationId;
33
- const member = Accumulator.encodePositiveNumberAsAccumulatorMember(
34
- Number(revocationId),
35
- );
36
-
37
- let updates = [];
38
- try {
39
- updates = await dock.accumulatorModule.getUpdatesFromBlock(
40
- registryId,
41
- blockNo,
42
- );
43
- } catch (err) {
44
- if (err.code === UnknownBlockErrorCode) {
45
- console.error(err);
46
- updates = [];
47
- } else {
48
- throw err;
49
- }
50
- }
51
-
52
- const additions = [];
53
- const removals = [];
54
-
55
- if (updates.length && updates[0].additions !== null) {
56
- for (const a of updates[0].additions) {
57
- additions.push(hexToU8a(a));
58
- }
59
- }
60
-
61
- if (updates.length && updates[0].removals !== null) {
62
- for (const a of updates[0].removals) {
63
- removals.push(hexToU8a(a));
64
- }
65
- }
66
-
67
- const queriedWitnessInfo = new VBWitnessUpdateInfo(
68
- hexToU8a(updates[0].witnessUpdateInfo),
69
- );
70
- const witness = new VBMembershipWitness(hexToU8a(membershipWitness));
71
-
72
- witness.updateUsingPublicInfoPostBatchUpdate(
73
- member,
74
- additions,
75
- removals,
76
- queriedWitnessInfo,
77
- );
78
-
79
- return witness;
80
- }
81
-
82
24
  export const getWitnessDetails = async (credential, _membershipWitness) => {
83
25
  let witness = _membershipWitness;
84
26
  let blockNo;
85
27
 
86
28
  try {
87
- ({blockNo, witness} = JSON.parse(_membershipWitness));
29
+ ({witness, blockNo} = JSON.parse(_membershipWitness));
88
30
  } catch (err) {
89
31
  console.error(err);
90
32
  }
91
-
33
+
92
34
  const {credentialStatus} = credential;
93
- const registryId = credentialStatus?.id.replace('dock:accumulator:', '');
35
+ const registryId = credentialStatus?.id;
94
36
  const revocationIndex = credentialStatus.revocationId;
95
37
 
96
- const queriedAccumulator = await dock.accumulatorModule.getAccumulator(
97
- registryId,
98
- false,
99
- );
38
+ const queriedAccumulator =
39
+ await blockchainService.modules.accumulator.getAccumulator(
40
+ registryId,
41
+ false,
42
+ );
100
43
 
101
44
  if (!queriedAccumulator) {
102
45
  throw new Error('Accumulator not found');
103
46
  }
104
47
 
105
48
  const accumulator = PositiveAccumulator.fromAccumulated(
106
- hexToU8a(queriedAccumulator.accumulated),
49
+ queriedAccumulator.accumulated.bytes,
107
50
  );
108
51
 
109
52
  const encodedRevId = Encoder.defaultEncodeFunc()(revocationIndex.toString());
110
53
 
111
- const publicKey = await dock.accumulatorModule.getPublicKeyByHexDid(
54
+ const publicKey = await blockchainService.modules.accumulator.getPublicKey(
112
55
  queriedAccumulator.keyRef[0],
113
56
  queriedAccumulator.keyRef[1],
114
57
  );
115
58
 
116
59
  const params = dockAccumulatorParams();
117
- const pk = new AccumulatorPublicKey(hexToU8a(publicKey.bytes));
60
+ const pk = new AccumulatorPublicKey(publicKey.bytes);
118
61
 
119
- let membershipWitness = new VBMembershipWitness(
120
- hexToU8a(witness),
121
- );
62
+ const membershipWitness = new VBMembershipWitness(hexToU8a(witness));
122
63
 
123
- if(blockNo){
124
- try {
125
- const updatedWitness = await updateMembershipWitness({
126
- credential,
127
- membershipWitness: witness,
128
- registryId,
129
- blockNo,
130
- });
131
- membershipWitness = updatedWitness;
64
+ try {
65
+ const credentialStatusId = credential.credentialStatus.id;
66
+ const accumulatorId = blockchainService
67
+ .getTypesForDIDOrAccumulator(credentialStatusId)
68
+ .AccumulatorId.from(credentialStatusId);
69
+
70
+ const history =
71
+ await blockchainService.modules.accumulator.accumulatorHistory(
72
+ accumulatorId,
73
+ );
74
+
75
+ const blockNoIndex = history.updates.findIndex(
76
+ update => update.id.toString() === blockNo,
77
+ );
132
78
 
133
- } catch (err) {
134
- console.error(err);
79
+ const nextBlockNo = history.updates[blockNoIndex + 1]?.id?.toString();
80
+
81
+ if (nextBlockNo) {
82
+ await blockchainService.modules.accumulator.updateWitness(
83
+ registryId,
84
+ encodedRevId,
85
+ membershipWitness,
86
+ nextBlockNo,
87
+ queriedAccumulator.lastModified,
88
+ );
135
89
  }
90
+ } catch (err) {
91
+ console.error(err);
136
92
  }
137
93
 
138
94
  return {
@@ -1,16 +1,13 @@
1
1
  import {
2
2
  applyEnforceBounds,
3
- MAX_DATE_PLACEHOLDER,
4
- MIN_DATE_PLACEHOLDER,
5
- MAX_NUMBER,
6
3
  fetchProvingKey,
7
4
  isBase64OrDataUrl,
8
- MIN_INTEGER,
9
5
  } from './bound-check';
10
6
  import {PresentationBuilder} from '@docknetwork/crypto-wasm-ts/lib';
11
7
  import proofRequest from './proof-request.json';
12
8
  import { replaceResponseURL } from '@docknetwork/wallet-sdk-core/src/helpers';
13
9
  import assert from 'assert';
10
+ import { MAX_DATE_PLACEHOLDER, MAX_NUMBER, MIN_DATE_PLACEHOLDER, MIN_NUMBER } from './pex-helpers';
14
11
 
15
12
  const testAPIURL = process.env.TESTING_API_URL || null;
16
13
 
@@ -218,7 +215,7 @@ describe('Bound check', () => {
218
215
 
219
216
  const credIdx = 0;
220
217
  const attributeName = 'credentialSubject.income';
221
- const min = MIN_INTEGER;
218
+ const min = MIN_NUMBER;
222
219
  const max = 20000;
223
220
 
224
221
  expect(builder.enforceBounds).toHaveBeenCalledWith(