@docknetwork/wallet-sdk-wasm 1.5.6 → 1.5.9

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 (131) hide show
  1. package/lib/{account-bf00e5c0.js → account-357ab05d.js} +1 -23
  2. package/lib/{account-e48dc9b6.js → account-399e6053.js} +1 -23
  3. package/lib/index.js +0 -9
  4. package/lib/index.mjs +0 -9
  5. package/lib/modules/account.js +5 -12
  6. package/lib/modules/account.mjs +5 -12
  7. package/lib/modules/accounts.js +4 -11
  8. package/lib/modules/accounts.mjs +4 -11
  9. package/lib/modules/network-manager.js +4 -4
  10. package/lib/modules/network-manager.mjs +4 -4
  11. package/lib/modules/wallet.js +1 -8
  12. package/lib/modules/wallet.mjs +1 -8
  13. package/lib/rpc-server.js +0 -9
  14. package/lib/rpc-server.mjs +0 -9
  15. package/lib/services/blockchain/index.js +0 -2
  16. package/lib/services/blockchain/index.mjs +0 -2
  17. package/lib/services/blockchain/service.js +33 -74
  18. package/lib/services/blockchain/service.mjs +34 -75
  19. package/lib/services/credential/bbs-revocation.js +0 -2
  20. package/lib/services/credential/bbs-revocation.mjs +0 -2
  21. package/lib/services/credential/index.js +0 -2
  22. package/lib/services/credential/index.mjs +0 -2
  23. package/lib/services/credential/service.js +0 -2
  24. package/lib/services/credential/service.mjs +0 -2
  25. package/lib/services/dids/index.js +0 -2
  26. package/lib/services/dids/index.mjs +0 -2
  27. package/lib/services/dids/service.js +1 -3
  28. package/lib/services/dids/service.mjs +1 -3
  29. package/lib/services/edv/hmac.js +1 -2
  30. package/lib/services/edv/hmac.mjs +1 -2
  31. package/lib/services/edv/index.js +1 -3
  32. package/lib/services/edv/index.mjs +1 -3
  33. package/lib/services/edv/service-rpc.js +4 -0
  34. package/lib/services/edv/service-rpc.mjs +4 -0
  35. package/lib/services/edv/service.js +9 -6
  36. package/lib/services/edv/service.mjs +9 -5
  37. package/lib/services/index.js +0 -12
  38. package/lib/services/index.mjs +0 -12
  39. package/lib/services/pex/service.js +2 -1
  40. package/lib/services/pex/service.mjs +2 -1
  41. package/lib/services/test-utils.js +3 -198
  42. package/lib/services/test-utils.mjs +4 -194
  43. package/lib/setup-nodejs.js +0 -9
  44. package/lib/setup-nodejs.mjs +0 -9
  45. package/lib/setup-tests.js +0 -9
  46. package/lib/setup-tests.mjs +0 -9
  47. package/lib/src/modules/accounts.d.ts +0 -1
  48. package/lib/src/modules/accounts.d.ts.map +1 -1
  49. package/lib/src/services/blockchain/service.d.ts +7 -3
  50. package/lib/src/services/blockchain/service.d.ts.map +1 -1
  51. package/lib/src/services/edv/hmac.d.ts +1 -1
  52. package/lib/src/services/edv/hmac.d.ts.map +1 -1
  53. package/lib/src/services/edv/service.d.ts +3 -1
  54. package/lib/src/services/edv/service.d.ts.map +1 -1
  55. package/lib/src/services/pex/service.d.ts.map +1 -1
  56. package/lib/test/setup-test-state.js +8 -20
  57. package/lib/test/setup-test-state.mjs +8 -20
  58. package/lib/tsconfig.tsbuildinfo +1 -1
  59. package/package.json +7 -8
  60. package/src/modules/accounts.test.js +0 -25
  61. package/src/modules/accounts.ts +0 -33
  62. package/src/modules/data-migration.test.js +0 -11
  63. package/src/modules/network-manager.ts +4 -4
  64. package/src/modules/wallet.test.js +0 -11
  65. package/src/modules/wallet.ts +1 -1
  66. package/src/services/blockchain/index.test.js +4 -15
  67. package/src/services/blockchain/service.ts +38 -98
  68. package/src/services/dids/index.test.js +1 -1
  69. package/src/services/dids/service.ts +1 -1
  70. package/src/services/edv/hmac.ts +2 -3
  71. package/src/services/edv/index.test.js +7 -2
  72. package/src/services/edv/service-rpc.js +4 -0
  73. package/src/services/edv/service.ts +9 -3
  74. package/src/services/index.js +0 -4
  75. package/src/services/pex/service.ts +7 -1
  76. package/src/services/test-utils.js +0 -178
  77. package/src/test/setup-test-state.js +1 -3
  78. package/lib/services/substrate/api-utils.js +0 -85
  79. package/lib/services/substrate/api-utils.mjs +0 -74
  80. package/lib/services/substrate/configs.js +0 -30
  81. package/lib/services/substrate/configs.mjs +0 -21
  82. package/lib/services/substrate/index.android.js +0 -22
  83. package/lib/services/substrate/index.android.mjs +0 -18
  84. package/lib/services/substrate/index.ios.js +0 -22
  85. package/lib/services/substrate/index.ios.mjs +0 -18
  86. package/lib/services/substrate/index.js +0 -37
  87. package/lib/services/substrate/index.mjs +0 -29
  88. package/lib/services/substrate/service-rpc.js +0 -37
  89. package/lib/services/substrate/service-rpc.mjs +0 -33
  90. package/lib/services/substrate/service.js +0 -115
  91. package/lib/services/substrate/service.mjs +0 -102
  92. package/lib/services/trust-registry/configs.js +0 -25
  93. package/lib/services/trust-registry/configs.mjs +0 -16
  94. package/lib/services/trust-registry/index.android.js +0 -19
  95. package/lib/services/trust-registry/index.android.mjs +0 -15
  96. package/lib/services/trust-registry/index.ios.js +0 -19
  97. package/lib/services/trust-registry/index.ios.mjs +0 -15
  98. package/lib/services/trust-registry/index.js +0 -33
  99. package/lib/services/trust-registry/index.mjs +0 -25
  100. package/lib/services/trust-registry/service-rpc.js +0 -29
  101. package/lib/services/trust-registry/service-rpc.mjs +0 -25
  102. package/lib/services/trust-registry/service.js +0 -89
  103. package/lib/services/trust-registry/service.mjs +0 -85
  104. package/lib/src/services/substrate/api-utils.d.ts +0 -14
  105. package/lib/src/services/substrate/api-utils.d.ts.map +0 -1
  106. package/lib/src/services/substrate/configs.d.ts +0 -16
  107. package/lib/src/services/substrate/configs.d.ts.map +0 -1
  108. package/lib/src/services/substrate/index.d.ts +0 -2
  109. package/lib/src/services/substrate/index.d.ts.map +0 -1
  110. package/lib/src/services/substrate/service.d.ts +0 -13
  111. package/lib/src/services/substrate/service.d.ts.map +0 -1
  112. package/lib/src/services/trust-registry/configs.d.ts +0 -6
  113. package/lib/src/services/trust-registry/configs.d.ts.map +0 -1
  114. package/lib/src/services/trust-registry/service.d.ts +0 -25
  115. package/lib/src/services/trust-registry/service.d.ts.map +0 -1
  116. package/src/services/substrate/api-utils.test.js +0 -73
  117. package/src/services/substrate/api-utils.ts +0 -66
  118. package/src/services/substrate/configs.ts +0 -34
  119. package/src/services/substrate/index.android.js +0 -3
  120. package/src/services/substrate/index.ios.js +0 -3
  121. package/src/services/substrate/index.js +0 -1
  122. package/src/services/substrate/index.test.js +0 -116
  123. package/src/services/substrate/service-rpc.js +0 -24
  124. package/src/services/substrate/service.ts +0 -117
  125. package/src/services/trust-registry/configs.ts +0 -14
  126. package/src/services/trust-registry/index.android.js +0 -3
  127. package/src/services/trust-registry/index.ios.js +0 -3
  128. package/src/services/trust-registry/index.js +0 -1
  129. package/src/services/trust-registry/index.test.js +0 -67
  130. package/src/services/trust-registry/service-rpc.js +0 -15
  131. package/src/services/trust-registry/service.ts +0 -94
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docknetwork/wallet-sdk-wasm",
3
- "version": "1.5.6",
3
+ "version": "1.5.9",
4
4
  "license": "https://github.com/docknetwork/react-native-sdk/LICENSE",
5
5
  "repository": {
6
6
  "type": "git",
@@ -25,12 +25,13 @@
25
25
  "@polkadot/util-crypto": "10.1.11"
26
26
  },
27
27
  "dependencies": {
28
+ "p-limit": "2.3.0",
28
29
  "@astronautlabs/jsonpath": "^1.1.2",
29
30
  "@docknetwork/universal-wallet": "^2.0.1",
30
- "@docknetwork/wallet-sdk-dids": "^1.5.6",
31
+ "@docknetwork/wallet-sdk-dids": "^1.5.9",
31
32
  "@cosmjs/proto-signing": "^0.32.4",
32
- "@docknetwork/cheqd-blockchain-api": "0.30.2",
33
- "@docknetwork/cheqd-blockchain-modules": "0.30.2",
33
+ "@docknetwork/cheqd-blockchain-api": "0.36.1",
34
+ "@docknetwork/cheqd-blockchain-modules": "0.33.0",
34
35
  "@polkadot/api": "9.7.1",
35
36
  "@polkadot/keyring": "10.1.11",
36
37
  "@polkadot/rpc-core": "9.7.1",
@@ -41,8 +42,7 @@
41
42
  "@polkadot/util": "10.1.11",
42
43
  "@polkadot/util-crypto": "10.1.11",
43
44
  "@polkadot/wasm-crypto": "6.3.1",
44
- "@docknetwork/credential-sdk": "0.44.0",
45
- "@docknetwork/dock-blockchain-modules": "0.26.2",
45
+ "@docknetwork/credential-sdk": "0.50.0",
46
46
  "@sphereon/oid4vci-client": "^0.16.0",
47
47
  "@sphereon/oid4vci-common": "^0.16.0",
48
48
  "axios": "^0.25.0",
@@ -54,8 +54,7 @@
54
54
  "winston": "^3.3.3",
55
55
  "cwait": "1.1.2",
56
56
  "axios-retry": "^3.2.5",
57
- "@sphereon/pex": "^1.1.4",
58
- "@docknetwork/dock-blockchain-api": "0.6.1"
57
+ "@sphereon/pex": "^1.1.4"
59
58
  },
60
59
  "devDependencies": {
61
60
  "@babel/node": "^7.16.0",
@@ -1,4 +1,3 @@
1
- import {substrateService} from '../services/substrate';
2
1
  import {Accounts} from './accounts';
3
2
  import {Wallet} from './wallet';
4
3
  import {getTestWallet} from '../test/setup-test-state';
@@ -43,30 +42,6 @@ describe('Accounts module', () => {
43
42
  expect(account.address).toBe(address);
44
43
  });
45
44
 
46
- it('expect to fetch account balance and update currency document', async () => {
47
- const account = await accounts.create({
48
- name: 'test',
49
- });
50
- const balance = 10;
51
- jest.spyOn(substrateService, 'getAccountBalance').mockReturnValue(balance);
52
-
53
- let result = await accounts.fetchBalance(account.address);
54
-
55
- expect(substrateService.getAccountBalance).toBeCalled();
56
- expect(result).toBe(balance);
57
-
58
- const currency = await accounts.findCorrelationByType(
59
- account.address,
60
- 'Currency',
61
- );
62
-
63
- expect(currency.value).toBe(balance);
64
-
65
- result = await accounts.getBalance(account.address);
66
-
67
- expect(result).toBe(balance);
68
- });
69
-
70
45
  it('Expect to export account and import account', async () => {
71
46
  const account = await accounts.create({
72
47
  name: 'test',
@@ -3,7 +3,6 @@ import assert from 'assert';
3
3
  import {walletService as _walletService} from '../services/wallet';
4
4
  import {utilCryptoService} from '../services/util-crypto';
5
5
  import {keyringService} from '../services/keyring';
6
- import {substrateService} from '../services/substrate';
7
6
  import {polkadotService} from '../services/polkadot';
8
7
  import {Wallet, WalletEvents} from './wallet';
9
8
  import {Errors} from '../errors';
@@ -70,38 +69,6 @@ export class Accounts {
70
69
  });
71
70
  }
72
71
 
73
- async fetchBalance(address) {
74
- assert(isAddressValid(address), 'invalid address');
75
- console.log('fetching balance from substrate');
76
- let balance;
77
-
78
- try {
79
- balance = await substrateService.getAccountBalance({address});
80
-
81
- console.log('balance found', balance.toString());
82
-
83
- console.log('updating cache');
84
- const currency = await this.findCorrelationByType(
85
- address,
86
- 'Currency',
87
- true,
88
- );
89
-
90
- console.log('currency', currency);
91
-
92
- if (currency.value !== balance) {
93
- currency.value = balance;
94
-
95
- await this.wallet.update(currency);
96
- }
97
- } catch(err) {
98
- console.log('Unable to update cache');
99
- console.error(err);
100
- }
101
-
102
- return balance;
103
- }
104
-
105
72
  async getBalance(address, skipFetch?) {
106
73
  assert(isAddressValid(address), 'address is required');
107
74
 
@@ -1,14 +1,7 @@
1
1
  import {Wallet} from './wallet';
2
2
  import walletLegacyData from '../test/fixtures/legacy-wallet-schema.json';
3
- import {mockDockService} from '../services/test-utils';
4
3
 
5
4
  describe('DataMigration', () => {
6
- let unmockDockService;
7
-
8
- beforeAll(async () => {
9
- unmockDockService = await mockDockService();
10
- });
11
-
12
5
  describe('migrate wallet from v0.1 to v0.2 (file1)', () => {
13
6
  let wallet: Wallet;
14
7
 
@@ -65,8 +58,4 @@ describe('DataMigration', () => {
65
58
  const wallet = await Wallet.create({walletId: 'bad-documents'});
66
59
  await wallet.load();
67
60
  });
68
-
69
- afterAll(() => {
70
- return unmockDockService();
71
- });
72
61
  });
@@ -12,16 +12,16 @@ export type NetworkId = 'mainnet' | 'testnet' | 'local' | 'custom';
12
12
 
13
13
  export const SUBSTRATE_NETWORKS : Record<NetworkId, NetworkInfo> = {
14
14
  mainnet: {
15
- name: 'Dock PoS Mainnet',
15
+ name: 'Cheqd Mainnet',
16
16
  substrateUrl: null,
17
17
  addressPrefix: 22,
18
- cheqdApiUrl: 'https://mainnet.cheqd.docknode.io/',
18
+ cheqdApiUrl: 'https://mainnet.cheqd.docknode.io',
19
19
  },
20
20
  testnet: {
21
- name: 'Dock PoS Testnet',
21
+ name: 'Cheqd Testnet',
22
22
  substrateUrl: null,
23
23
  addressPrefix: 21,
24
- cheqdApiUrl: 'https://testnet.cheqd.docknode.io/',
24
+ cheqdApiUrl: 'https://testnet.cheqd.docknode.io',
25
25
  },
26
26
  local: {
27
27
  name: 'Local Node',
@@ -1,15 +1,8 @@
1
1
  import {Wallet, WalletEvents} from './wallet';
2
2
  import walletJson from '../test/fixtures/wallet-backup.json';
3
- import {mockDockService} from '../services/test-utils';
4
3
  import {getTestWallet} from '../test/setup-test-state';
5
4
 
6
5
  describe('ApiModule', () => {
7
- let unmockDockService;
8
-
9
- beforeAll(async () => {
10
- unmockDockService = await mockDockService();
11
- });
12
-
13
6
  describe('new wallet', () => {
14
7
  let wallet: Wallet;
15
8
 
@@ -220,8 +213,4 @@ describe('ApiModule', () => {
220
213
  );
221
214
  });
222
215
  });
223
-
224
- afterAll(async () => {
225
- await unmockDockService();
226
- });
227
216
  });
@@ -234,7 +234,7 @@ class Wallet {
234
234
  }
235
235
 
236
236
  await blockchainService.init({
237
- address: networkInfo.substrateUrl,
237
+ cheqdApiUrl: networkInfo.cheqdApiUrl,
238
238
  });
239
239
 
240
240
  this.eventManager.emit(WalletEvents.networkConnected);
@@ -1,34 +1,23 @@
1
1
  import {NetworkManager} from '../../modules/network-manager';
2
- import {assertRpcService, mockDockSdkConnection} from '../test-utils';
2
+ import {assertRpcService} from '../test-utils';
3
3
  import {validation} from './configs';
4
4
  import {blockchainService as service} from './service';
5
5
  import {BlockchainServiceRpc} from './service-rpc';
6
6
 
7
- const doConnect = (
8
- address = NetworkManager.getInstance().getNetworkInfo().substrateUrl,
9
- ) =>
10
- service.init({
11
- address,
12
- });
13
-
14
7
  describe('DockService', () => {
15
8
  it('ServiceRpc', () => {
16
9
  assertRpcService(BlockchainServiceRpc, service, validation);
17
10
  });
18
11
 
19
12
  describe('init', () => {
20
- afterEach(async () => {
21
- await service.disconnect();
22
- });
23
-
24
13
  it('connect and disconnect substrate node', async () => {
25
- const mock = mockDockSdkConnection();
26
- const result = await doConnect();
14
+ const result = await service.init({
15
+ cheqdApiUrl: NetworkManager.getInstance().getNetworkInfo().cheqdApiUrl,
16
+ });
27
17
  expect(result).toBe(true);
28
18
  expect(service.isBlockchainReady).toBeTruthy();
29
19
  await service.disconnect();
30
20
  expect(service.isBlockchainReady).toBeFalsy();
31
- mock.clear();
32
21
  });
33
22
  });
34
23
  });
@@ -12,12 +12,6 @@ import {
12
12
  WILDCARD,
13
13
  } from '@docknetwork/credential-sdk/resolver';
14
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
15
  import {EventEmitter} from 'events';
22
16
  import {Logger} from '../../core/logger';
23
17
  import {once} from '../../modules/event-manager';
@@ -27,47 +21,25 @@ import {InitParams} from './configs';
27
21
  export const universalResolverUrl = 'https://uniresolver.truvera.io';
28
22
 
29
23
  import {
30
- CheqdAccumulatorCommon,
31
- CheqdAccumulatorId,
32
- CheqdAccumulatorPublicKey,
33
- DockAccumulatorCommon,
34
- DockAccumulatorId,
35
- DockAccumulatorPublicKey,
24
+ AccumulatorCommon,
25
+ AccumulatorId,
26
+ AccumulatorPublicKey,
36
27
  } from '@docknetwork/credential-sdk/types';
37
28
 
38
29
  class AnyDIDResolver extends ResolverRouter {
39
30
  method = WILDCARD;
40
31
  }
41
32
 
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
33
  /**
61
34
  *
62
35
  */
63
36
  export class BlockchainService {
64
37
  dock;
65
38
  modules;
66
- didModule;
67
39
  cheqdApi;
40
+ cheqdApiUrl;
68
41
  isBlockchainReady = false;
69
42
  resolver: any;
70
- dockEnabled: boolean;
71
43
  static Events = {
72
44
  BLOCKCHAIN_READY: 'blockchain-ready',
73
45
  };
@@ -82,32 +54,20 @@ export class BlockchainService {
82
54
 
83
55
  constructor() {
84
56
  this.name = 'blockchain';
85
- this.dock = new DockAPI();
86
57
  this.cheqdApi = new CheqdAPI();
87
- this.didModule = new DockDIDModule(this.dock);
88
- this.dockModules = new DockCoreModules(this.dock);
89
58
  this.cheqdModules = new CheqdCoreModules(this.cheqdApi);
90
- this.modules = new MultiApiCoreModules(
91
- this.dockEnabled
92
- ? [this.dockModules, this.cheqdModules]
93
- : [this.cheqdModules],
94
- );
59
+ this.modules = new MultiApiCoreModules([this.cheqdModules]);
95
60
  this.emitter = new EventEmitter();
96
61
  this.resolver = this.createDIDResolver();
97
62
  }
98
63
 
99
64
  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
- );
65
+ return {
66
+ PublicKey: AccumulatorPublicKey,
67
+ AccumulatorId,
68
+ AccumulatorCommon,
69
+ AccumulatorModule: this.modules.accumulator,
109
70
  }
110
- return types;
111
71
  }
112
72
 
113
73
  /**
@@ -135,63 +95,47 @@ export class BlockchainService {
135
95
  * @returns
136
96
  */
137
97
  async init(params: InitParams) {
138
- if (this.dock.isConnected) {
139
- await this.dock.disconnect();
98
+ if (!params?.cheqdApiUrl) {
99
+ throw new Error('cheqdApiUrl is required');
140
100
  }
141
101
 
142
102
  if (this.cheqdApi && this.cheqdApi.isInitialized()) {
143
103
  await this.cheqdApi.disconnect();
144
104
  }
145
105
 
146
- Logger.info(`Attempt to initialized substrate at: ${params.address}`);
106
+ this.modules = new MultiApiCoreModules([this.cheqdModules]);
147
107
 
148
- this.dockEnabled = !!params.substrateUrl;
108
+ const checkdApiUrl = params?.cheqdApiUrl;
109
+ const cheqdNetworkId = params?.networkId;
110
+ const cheqdMnemonic =
111
+ params?.cheqdMnemonic || (await utilCryptoService.mnemonicGenerate(12));
149
112
 
150
- if (this.dockEnabled) {
151
- await this.dock.init({
152
- address: params.substrateUrl,
153
- });
154
- Logger.info(`Substrate initialized at: ${params.address}`);
155
- }
113
+ const wallet = await DirectSecp256k1HdWallet.fromMnemonic(cheqdMnemonic, {
114
+ prefix: 'cheqd',
115
+ });
156
116
 
157
- this.modules = new MultiApiCoreModules(
158
- this.dockEnabled
159
- ? [this.dockModules, this.cheqdModules]
160
- : [this.cheqdModules],
161
- );
117
+ const walletAccounts = await wallet.getAccounts();
118
+ const [{address}] = walletAccounts;
119
+ console.log('Using cheqd account:', address);
162
120
 
163
- if (params?.cheqdApiUrl) {
164
- const checkdApiUrl = params?.cheqdApiUrl;
165
- const cheqdNetworkId = params?.networkId;
166
- const cheqdMnemonic =
167
- params?.cheqdMnemonic || (await utilCryptoService.mnemonicGenerate(12));
121
+ Logger.info(
122
+ `Attempt to initialized cheqd at: ${checkdApiUrl} with networkId: ${cheqdNetworkId}`,
123
+ );
124
+ Logger.info(`Using cheqd account: ${address}`);
168
125
 
169
- const wallet = await DirectSecp256k1HdWallet.fromMnemonic(cheqdMnemonic, {
170
- prefix: 'cheqd',
126
+ try {
127
+ await this.cheqdApi.init({
128
+ wallet,
129
+ url: checkdApiUrl,
130
+ network: cheqdNetworkId,
171
131
  });
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
- }
132
+ Logger.info(`Cheqd initialized at: ${checkdApiUrl}`);
133
+ } catch (err) {
134
+ console.error(err);
135
+ debugger;
136
+ Logger.error(`Failed to initialize cheqd at: ${checkdApiUrl}`);
192
137
  }
193
138
 
194
- this.address = params.address;
195
139
 
196
140
  this.resolver = this.createDIDResolver();
197
141
 
@@ -214,10 +158,6 @@ export class BlockchainService {
214
158
  async disconnect() {
215
159
  let result;
216
160
 
217
- if (this.dockEnabled) {
218
- result = await this.dock.disconnect();
219
- }
220
-
221
161
  if (this.cheqdApi && this.cheqdApi.isInitialized()) {
222
162
  result = await this.cheqdApi.disconnect();
223
163
  }
@@ -246,7 +186,7 @@ export class BlockchainService {
246
186
  }
247
187
 
248
188
  async getAddress() {
249
- return this.dock.address;
189
+ return this.cheqdApiUrl;
250
190
  }
251
191
 
252
192
  _setBlockchainReady(isBlockchainReady) {
@@ -100,7 +100,7 @@ describe('DID Service', () => {
100
100
  it('expect to get did document', async () => {
101
101
  const document = 'document';
102
102
  jest
103
- .spyOn(blockchainService.didModule, 'getDocument')
103
+ .spyOn(blockchainService.modules.did, 'getDocument')
104
104
  .mockResolvedValue(document);
105
105
 
106
106
  const result = await service.getDidDockDocument(
@@ -137,7 +137,7 @@ class DIDService {
137
137
  async getDidDockDocument(did) {
138
138
  assert(!!did, 'DID is required');
139
139
  const dock = blockchainService.dock;
140
- const result = await blockchainService.didModule.getDocument(did);
140
+ const result = await blockchainService.modules.did.getDocument(did);
141
141
  return result;
142
142
  }
143
143
  }
@@ -1,6 +1,5 @@
1
1
  import * as base64url from 'base64url-universal';
2
2
  import crypto from '@docknetwork/universal-wallet/crypto';
3
- import {hexToU8a} from '@polkadot/util';
4
3
 
5
4
  export default class HMAC {
6
5
  key: CryptoKey;
@@ -38,10 +37,10 @@ export default class HMAC {
38
37
  return key;
39
38
  }
40
39
 
41
- static async deriveKey(baseKey: string) {
40
+ static async deriveKey(baseKey: Uint8Array) {
42
41
  const key = await crypto.subtle.importKey(
43
42
  'raw',
44
- hexToU8a(baseKey),
43
+ baseKey,
45
44
  {name: 'HMAC', hash: {name: 'SHA-256'}},
46
45
  true,
47
46
  ['sign', 'verify'],
@@ -1,3 +1,5 @@
1
+ import base64url from 'base64url-universal';
2
+
1
3
  import {assertRpcService} from '../test-utils';
2
4
  import {validation} from './configs';
3
5
  import {edvService as service} from './service';
@@ -23,10 +25,13 @@ describe('EDVService', () => {
23
25
 
24
26
  describe('deriveKeys', () => {
25
27
  it('should derive EDV keys', async () => {
26
- const testMasterKey = '0O+9vxwb3Zo/9AVcQfVeQ59wvgcYUVH/mTye6islspM=';
28
+ const testMasterKey = new Uint8Array(
29
+ base64url.decode('0O+9vxwb3Zo/9AVcQfVeQ59wvgcYUVH/mTye6islspM='),
30
+ );
27
31
  const derivedTestAgreementKey =
28
32
  '{"id":"did:key:z6Mkt1paLGw6VqRCTmqjpbiP9fxLVHJb8k97zERL6TcWr9Ru#z6LSojEubzYtAGCBE7Mwwks7J3Gttsrd1c9EXcDuNjthwVQj","controller":"did:key:z6Mkt1paLGw6VqRCTmqjpbiP9fxLVHJb8k97zERL6TcWr9Ru","type":"X25519KeyAgreementKey2020","publicKeyMultibase":"z6LSojEubzYtAGCBE7Mwwks7J3Gttsrd1c9EXcDuNjthwVQj","privateKeyMultibase":"z3weoV5H5DppQ7pjABoopaiDFN6zH3SokESte2Jte87YNXgg"}';
29
- const derivedTestHmacKey = 'AAkACzAAmgwPDgWQAMAAAAAOYAAAAA';
33
+ const derivedTestHmacKey =
34
+ '0O-9vxwb3Zo_9AVcQfVeQ59wvgcYUVH_mTye6islspM';
30
35
  const derivedTestVerificationKey =
31
36
  '{"id":"did:key:z6Mkt1paLGw6VqRCTmqjpbiP9fxLVHJb8k97zERL6TcWr9Ru#z6Mkt1paLGw6VqRCTmqjpbiP9fxLVHJb8k97zERL6TcWr9Ru","controller":"did:key:z6Mkt1paLGw6VqRCTmqjpbiP9fxLVHJb8k97zERL6TcWr9Ru","type":"Ed25519VerificationKey2018","publicKeyBase58":"EZZXk2gfAHvjMH1392kYJaQLfi2jirtmJDWQGBeVvveX","privateKeyBase58":"5BHUEjDDbDzQKnveM9qXXXmRqwTtmBvumTY2xZXN61x8dvZHgzsDaTpkVqkE4LSoMLcV6yDRhxcv7mMTzdaJ21pX"}';
32
37
  const {agreementKey, hmacKey, verificationKey} =
@@ -19,6 +19,10 @@ export class EDVServiceRpc extends RpcService {
19
19
  return this.call('deriveKeys');
20
20
  }
21
21
 
22
+ getController() {
23
+ return this.call('getController');
24
+ }
25
+
22
26
  find(params: any) {
23
27
  return this.call('find', params);
24
28
  }
@@ -10,7 +10,6 @@ import {logger} from '@docknetwork/wallet-sdk-data-store/src/logger';
10
10
  import {didService} from '@docknetwork/wallet-sdk-wasm/src/services/dids/service';
11
11
  import {keyringService} from '@docknetwork/wallet-sdk-wasm/src/services/keyring';
12
12
  import {ed25519PairFromSeed} from '@polkadot/util-crypto';
13
- import base64url from 'base64url-universal';
14
13
 
15
14
  /**
16
15
  * EDVService
@@ -19,10 +18,12 @@ export class EDVService {
19
18
  storageInterface: EDVHTTPStorageInterface;
20
19
 
21
20
  private insertQueue: Promise<any> = Promise.resolve();
21
+ public controller: string;
22
22
 
23
23
  rpcMethods = [
24
24
  EDVService.prototype.generateKeys,
25
25
  EDVService.prototype.deriveKeys,
26
+ EDVService.prototype.getController,
26
27
  EDVService.prototype.initialize,
27
28
  EDVService.prototype.find,
28
29
  EDVService.prototype.update,
@@ -51,6 +52,7 @@ export class EDVService {
51
52
  };
52
53
 
53
54
  const {controller} = verificationKey;
55
+ this.controller = controller;
54
56
  const invocationSigner = getKeypairFromDoc(verificationKey);
55
57
  invocationSigner.sign = invocationSigner.signer().sign;
56
58
 
@@ -113,11 +115,11 @@ export class EDVService {
113
115
  return {verificationKey, agreementKey, hmacKey};
114
116
  }
115
117
 
116
- async deriveKeys(masterKey: any) {
118
+ async deriveKeys(masterKey: Uint8Array) {
117
119
  await keyringService.initialize({
118
120
  ss58Format: 22,
119
121
  });
120
- const pair = ed25519PairFromSeed(base64url.decode(masterKey));
122
+ const pair = ed25519PairFromSeed(masterKey);
121
123
 
122
124
  const keyPair = await didService.deriveKeyDoc({ pair });
123
125
 
@@ -131,6 +133,10 @@ export class EDVService {
131
133
  return { verificationKey, agreementKey, hmacKey };
132
134
  }
133
135
 
136
+ async getController() {
137
+ return this.controller;
138
+ }
139
+
134
140
  find(params: any) {
135
141
  return this.storageInterface.find(params);
136
142
  }
@@ -1,6 +1,5 @@
1
1
  import {keyringService} from './keyring/service';
2
2
  import {blockchainService} from './blockchain/service';
3
- import {substrateService} from './substrate/service';
4
3
  import {walletService} from './wallet/service';
5
4
  import {polkadotService} from './polkadot/service';
6
5
  import {utilCryptoService} from './util-crypto/service';
@@ -9,13 +8,11 @@ import {didService} from './dids/service';
9
8
  import {credentialService} from './credential/service';
10
9
  import {relayService} from './relay-service/service';
11
10
  import {pexService} from './pex/service';
12
- import {trustRegistryService} from './trust-registry/service';
13
11
  import {edvService} from './edv/service';
14
12
 
15
13
  export default [
16
14
  keyringService,
17
15
  blockchainService,
18
- substrateService,
19
16
  walletService,
20
17
  polkadotService,
21
18
  utilCryptoService,
@@ -24,6 +21,5 @@ export default [
24
21
  credentialService,
25
22
  relayService,
26
23
  pexService,
27
- trustRegistryService,
28
24
  edvService,
29
25
  ];
@@ -105,12 +105,18 @@ class PEXService {
105
105
 
106
106
  presentationFrom(params: CreatePresentationParams) {
107
107
  const {credentials, presentationDefinition, holderDID} = params;
108
- const result: IPresentation = pex.presentationFrom(
108
+ const evaluateResult = pex.evaluateCredentials(
109
109
  removeOptionalAttribute(presentationDefinition),
110
110
  credentials,
111
111
  holderDID,
112
112
  );
113
113
 
114
+ const result: IPresentation = pex.presentationFrom(
115
+ presentationDefinition,
116
+ evaluateResult.verifiableCredential,
117
+ holderDID,
118
+ );
119
+
114
120
  return result;
115
121
  }
116
122
  }