@docknetwork/wallet-sdk-wasm 1.5.9 → 1.5.11

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 (267) hide show
  1. package/lib/core/format-utils.js +0 -28
  2. package/lib/core/format-utils.mjs +1 -24
  3. package/lib/core/validation.js +1 -24
  4. package/lib/core/validation.mjs +2 -21
  5. package/lib/index.js +13 -23
  6. package/lib/index.mjs +13 -23
  7. package/lib/rpc-server.js +13 -23
  8. package/lib/rpc-server.mjs +13 -23
  9. package/lib/rpc-util.js +14 -0
  10. package/lib/rpc-util.mjs +14 -0
  11. package/lib/services/blockchain/index.js +3 -6
  12. package/lib/services/blockchain/index.mjs +3 -6
  13. package/lib/services/blockchain/service.js +5 -9
  14. package/lib/services/blockchain/service.mjs +5 -9
  15. package/lib/services/credential/bbs-revocation.js +4 -7
  16. package/lib/services/credential/bbs-revocation.mjs +3 -6
  17. package/lib/services/credential/bound-check.js +9 -4
  18. package/lib/services/credential/bound-check.mjs +9 -4
  19. package/lib/services/credential/index.js +11 -13
  20. package/lib/services/credential/index.mjs +11 -13
  21. package/lib/services/credential/service.js +18 -18
  22. package/lib/services/credential/service.mjs +15 -15
  23. package/lib/services/credential/utils.js +59 -28
  24. package/lib/services/credential/utils.mjs +62 -32
  25. package/lib/services/dids/index.js +7 -25
  26. package/lib/services/dids/index.mjs +7 -25
  27. package/lib/services/dids/keypair-utils.js +142 -0
  28. package/lib/services/dids/keypair-utils.mjs +113 -0
  29. package/lib/services/dids/service-rpc.js +0 -3
  30. package/lib/services/dids/service-rpc.mjs +0 -3
  31. package/lib/services/dids/service.js +13 -55
  32. package/lib/services/dids/service.mjs +13 -54
  33. package/lib/services/edv/index.js +4 -25
  34. package/lib/services/edv/index.mjs +4 -25
  35. package/lib/services/edv/service.js +6 -33
  36. package/lib/services/edv/service.mjs +6 -33
  37. package/lib/services/index.js +13 -25
  38. package/lib/services/index.mjs +13 -25
  39. package/lib/services/relay-service/configs.js +0 -1
  40. package/lib/services/relay-service/configs.mjs +0 -1
  41. package/lib/services/relay-service/index.android.js +0 -1
  42. package/lib/services/relay-service/index.android.mjs +0 -1
  43. package/lib/services/relay-service/index.ios.js +0 -1
  44. package/lib/services/relay-service/index.ios.mjs +0 -1
  45. package/lib/services/relay-service/index.js +0 -1
  46. package/lib/services/relay-service/index.mjs +0 -1
  47. package/lib/services/relay-service/service-rpc.js +0 -1
  48. package/lib/services/relay-service/service-rpc.mjs +0 -1
  49. package/lib/services/relay-service/service.js +0 -1
  50. package/lib/services/relay-service/service.mjs +0 -1
  51. package/lib/services/test-utils.js +0 -44
  52. package/lib/services/test-utils.mjs +1 -44
  53. package/lib/services/util-crypto/configs.js +0 -12
  54. package/lib/services/util-crypto/configs.mjs +0 -12
  55. package/lib/services/util-crypto/index.android.js +0 -3
  56. package/lib/services/util-crypto/index.android.mjs +0 -3
  57. package/lib/services/util-crypto/index.ios.js +0 -3
  58. package/lib/services/util-crypto/index.ios.mjs +0 -3
  59. package/lib/services/util-crypto/index.js +4 -7
  60. package/lib/services/util-crypto/index.mjs +4 -7
  61. package/lib/services/util-crypto/service-rpc.js +2 -30
  62. package/lib/services/util-crypto/service-rpc.mjs +2 -30
  63. package/lib/services/util-crypto/service.js +68 -61
  64. package/lib/services/util-crypto/service.mjs +50 -59
  65. package/lib/services/wallet/configs.js +0 -63
  66. package/lib/services/wallet/configs.mjs +1 -64
  67. package/lib/services/wallet/index.android.js +0 -1
  68. package/lib/services/wallet/index.android.mjs +0 -1
  69. package/lib/services/wallet/index.ios.js +0 -1
  70. package/lib/services/wallet/index.ios.mjs +0 -1
  71. package/lib/services/wallet/index.js +2 -12
  72. package/lib/services/wallet/index.mjs +2 -12
  73. package/lib/services/wallet/service-rpc.js +0 -77
  74. package/lib/services/wallet/service-rpc.mjs +0 -77
  75. package/lib/services/wallet/service.js +1 -215
  76. package/lib/services/wallet/service.mjs +1 -211
  77. package/lib/setup-nodejs.js +13 -23
  78. package/lib/setup-nodejs.mjs +13 -23
  79. package/lib/setup-tests.js +13 -23
  80. package/lib/setup-tests.mjs +13 -23
  81. package/lib/src/core/format-utils.d.ts +0 -5
  82. package/lib/src/core/format-utils.d.ts.map +1 -1
  83. package/lib/src/core/validation.d.ts +0 -3
  84. package/lib/src/core/validation.d.ts.map +1 -1
  85. package/lib/src/rpc-util.d.ts.map +1 -1
  86. package/lib/src/services/blockchain/service.d.ts.map +1 -1
  87. package/lib/src/services/credential/bbs-revocation.d.ts.map +1 -1
  88. package/lib/src/services/credential/bound-check.d.ts +1 -1
  89. package/lib/src/services/credential/bound-check.d.ts.map +1 -1
  90. package/lib/src/services/credential/service.d.ts.map +1 -1
  91. package/lib/src/services/credential/utils.d.ts +2 -1
  92. package/lib/src/services/credential/utils.d.ts.map +1 -1
  93. package/lib/src/services/dids/keypair-utils.d.ts +15 -0
  94. package/lib/src/services/dids/keypair-utils.d.ts.map +1 -0
  95. package/lib/src/services/dids/service-rpc.d.ts +0 -1
  96. package/lib/src/services/dids/service-rpc.d.ts.map +1 -1
  97. package/lib/src/services/dids/service.d.ts +11 -8
  98. package/lib/src/services/dids/service.d.ts.map +1 -1
  99. package/lib/src/services/edv/service.d.ts.map +1 -1
  100. package/lib/src/services/util-crypto/configs.d.ts +0 -3
  101. package/lib/src/services/util-crypto/configs.d.ts.map +1 -1
  102. package/lib/src/services/util-crypto/service.d.ts +3 -8
  103. package/lib/src/services/util-crypto/service.d.ts.map +1 -1
  104. package/lib/src/services/wallet/configs.d.ts +13 -0
  105. package/lib/src/services/wallet/configs.d.ts.map +1 -0
  106. package/lib/src/services/wallet/service.d.ts +1 -44
  107. package/lib/src/services/wallet/service.d.ts.map +1 -1
  108. package/lib/test-utils.js +0 -4
  109. package/lib/test-utils.mjs +1 -4
  110. package/lib/tsconfig.tsbuildinfo +1 -1
  111. package/package.json +5 -25
  112. package/readme.md +0 -61
  113. package/src/core/format-utils.test.js +1 -28
  114. package/src/core/format-utils.ts +0 -33
  115. package/src/core/validation.test.js +1 -33
  116. package/src/core/validation.ts +1 -25
  117. package/src/rpc-server.test.js +2 -9
  118. package/src/rpc-util.js +14 -0
  119. package/src/services/blockchain/service.ts +2 -3
  120. package/src/services/credential/bbs-revocation.ts +2 -1
  121. package/src/services/credential/bound-check.test.ts +6 -6
  122. package/src/services/credential/bound-check.ts +4 -4
  123. package/src/services/credential/index.test.js +0 -2
  124. package/src/services/credential/service.ts +5 -2
  125. package/src/services/credential/utils.js +65 -23
  126. package/src/services/dids/index.test.js +45 -33
  127. package/src/services/dids/keypair-utils.js +111 -0
  128. package/src/services/dids/service-rpc.ts +0 -3
  129. package/src/services/dids/service.ts +7 -34
  130. package/src/services/edv/service.ts +2 -9
  131. package/src/services/index.js +0 -4
  132. package/src/services/test-utils.js +0 -29
  133. package/src/services/util-crypto/configs.ts +0 -12
  134. package/src/services/util-crypto/index.test.js +6 -83
  135. package/src/services/util-crypto/service-rpc.js +2 -27
  136. package/src/services/util-crypto/service.ts +62 -75
  137. package/src/services/wallet/configs.ts +1 -113
  138. package/src/services/wallet/index.test.js +0 -159
  139. package/src/services/wallet/service-rpc.js +1 -88
  140. package/src/services/wallet/service.ts +0 -258
  141. package/src/test-utils.js +0 -13
  142. package/lib/account-357ab05d.js +0 -742
  143. package/lib/account-399e6053.js +0 -752
  144. package/lib/core/polkadot-utils.js +0 -119
  145. package/lib/core/polkadot-utils.mjs +0 -94
  146. package/lib/core/realm-schemas.js +0 -50
  147. package/lib/core/realm-schemas.mjs +0 -44
  148. package/lib/core/subscan.js +0 -75
  149. package/lib/core/subscan.mjs +0 -64
  150. package/lib/fixtures.js +0 -56
  151. package/lib/fixtures.mjs +0 -52
  152. package/lib/modules/account.js +0 -48
  153. package/lib/modules/account.mjs +0 -40
  154. package/lib/modules/accounts.js +0 -49
  155. package/lib/modules/accounts.mjs +0 -40
  156. package/lib/modules/data-migration.js +0 -72
  157. package/lib/modules/data-migration.mjs +0 -68
  158. package/lib/modules/wallet-backup.js +0 -82
  159. package/lib/modules/wallet-backup.mjs +0 -71
  160. package/lib/modules/wallet.js +0 -49
  161. package/lib/modules/wallet.mjs +0 -40
  162. package/lib/services/example/configs.js +0 -21
  163. package/lib/services/example/configs.mjs +0 -13
  164. package/lib/services/example/index.js +0 -18
  165. package/lib/services/example/index.mjs +0 -14
  166. package/lib/services/example/service-rpc.js +0 -25
  167. package/lib/services/example/service-rpc.mjs +0 -21
  168. package/lib/services/example/service.js +0 -25
  169. package/lib/services/example/service.mjs +0 -20
  170. package/lib/services/keyring/configs.js +0 -70
  171. package/lib/services/keyring/configs.mjs +0 -61
  172. package/lib/services/keyring/index.android.js +0 -22
  173. package/lib/services/keyring/index.android.mjs +0 -18
  174. package/lib/services/keyring/index.ios.js +0 -22
  175. package/lib/services/keyring/index.ios.mjs +0 -18
  176. package/lib/services/keyring/index.js +0 -16
  177. package/lib/services/keyring/index.mjs +0 -8
  178. package/lib/services/keyring/service-rpc.js +0 -65
  179. package/lib/services/keyring/service-rpc.mjs +0 -61
  180. package/lib/services/keyring/service.js +0 -84
  181. package/lib/services/keyring/service.mjs +0 -74
  182. package/lib/services/polkadot/configs.js +0 -17
  183. package/lib/services/polkadot/configs.mjs +0 -13
  184. package/lib/services/polkadot/index.android.js +0 -22
  185. package/lib/services/polkadot/index.android.mjs +0 -18
  186. package/lib/services/polkadot/index.ios.js +0 -22
  187. package/lib/services/polkadot/index.ios.mjs +0 -18
  188. package/lib/services/polkadot/index.js +0 -15
  189. package/lib/services/polkadot/index.mjs +0 -7
  190. package/lib/services/polkadot/service-rpc.js +0 -30
  191. package/lib/services/polkadot/service-rpc.mjs +0 -26
  192. package/lib/services/polkadot/service.js +0 -28
  193. package/lib/services/polkadot/service.mjs +0 -23
  194. package/lib/src/core/polkadot-utils.d.ts +0 -11
  195. package/lib/src/core/polkadot-utils.d.ts.map +0 -1
  196. package/lib/src/modules/account.d.ts +0 -60
  197. package/lib/src/modules/account.d.ts.map +0 -1
  198. package/lib/src/modules/accounts.d.ts +0 -48
  199. package/lib/src/modules/accounts.d.ts.map +0 -1
  200. package/lib/src/modules/data-migration.d.ts +0 -7
  201. package/lib/src/modules/data-migration.d.ts.map +0 -1
  202. package/lib/src/modules/wallet-backup.d.ts +0 -12
  203. package/lib/src/modules/wallet-backup.d.ts.map +0 -1
  204. package/lib/src/modules/wallet.d.ts +0 -134
  205. package/lib/src/modules/wallet.d.ts.map +0 -1
  206. package/lib/src/services/blockchain/index.d.ts +0 -2
  207. package/lib/src/services/blockchain/index.d.ts.map +0 -1
  208. package/lib/src/services/example/configs.d.ts +0 -9
  209. package/lib/src/services/example/configs.d.ts.map +0 -1
  210. package/lib/src/services/example/service.d.ts +0 -8
  211. package/lib/src/services/example/service.d.ts.map +0 -1
  212. package/lib/src/services/keyring/configs.d.ts +0 -39
  213. package/lib/src/services/keyring/configs.d.ts.map +0 -1
  214. package/lib/src/services/keyring/index.d.ts +0 -2
  215. package/lib/src/services/keyring/index.d.ts.map +0 -1
  216. package/lib/src/services/polkadot/configs.d.ts +0 -8
  217. package/lib/src/services/polkadot/configs.d.ts.map +0 -1
  218. package/lib/src/services/polkadot/index.d.ts +0 -2
  219. package/lib/src/services/polkadot/index.d.ts.map +0 -1
  220. package/lib/src/services/polkadot/service.d.ts +0 -8
  221. package/lib/src/services/polkadot/service.d.ts.map +0 -1
  222. package/lib/src/services/wallet/index.d.ts +0 -2
  223. package/lib/src/services/wallet/index.d.ts.map +0 -1
  224. package/lib/test/axiosMocks.js +0 -431
  225. package/lib/test/axiosMocks.mjs +0 -420
  226. package/lib/test/setup-test-state.js +0 -81
  227. package/lib/test/setup-test-state.mjs +0 -73
  228. package/src/core/polkadot-utils.js +0 -99
  229. package/src/core/realm-schemas.js +0 -42
  230. package/src/core/subscan.js +0 -62
  231. package/src/core/subscan.test.js +0 -56
  232. package/src/fixtures.js +0 -43
  233. package/src/modules/account.test.js +0 -56
  234. package/src/modules/account.ts +0 -128
  235. package/src/modules/accounts.test.js +0 -63
  236. package/src/modules/accounts.ts +0 -231
  237. package/src/modules/data-migration.test.js +0 -61
  238. package/src/modules/data-migration.ts +0 -86
  239. package/src/modules/wallet-backup.test.js +0 -24
  240. package/src/modules/wallet-backup.ts +0 -68
  241. package/src/modules/wallet.test.js +0 -216
  242. package/src/modules/wallet.ts +0 -424
  243. package/src/services/example/configs.js +0 -14
  244. package/src/services/example/index.js +0 -3
  245. package/src/services/example/index.test.js +0 -28
  246. package/src/services/example/service-rpc.js +0 -11
  247. package/src/services/example/service.ts +0 -18
  248. package/src/services/keyring/configs.ts +0 -110
  249. package/src/services/keyring/index.android.js +0 -3
  250. package/src/services/keyring/index.ios.js +0 -3
  251. package/src/services/keyring/index.js +0 -1
  252. package/src/services/keyring/index.test.js +0 -48
  253. package/src/services/keyring/service-rpc.js +0 -56
  254. package/src/services/keyring/service.ts +0 -111
  255. package/src/services/polkadot/configs.ts +0 -13
  256. package/src/services/polkadot/index.android.js +0 -3
  257. package/src/services/polkadot/index.ios.js +0 -3
  258. package/src/services/polkadot/index.js +0 -1
  259. package/src/services/polkadot/index.test.js +0 -52
  260. package/src/services/polkadot/service-rpc.js +0 -13
  261. package/src/services/polkadot/service.ts +0 -21
  262. package/src/test/axiosMocks.js +0 -20
  263. package/src/test/fixtures/subscan-failure.json +0 -5
  264. package/src/test/fixtures/subscan-success.json +0 -370
  265. package/src/test/fixtures/subscan-too-many-requests.json +0 -9
  266. package/src/test/setup-test-state.js +0 -35
  267. package/src/test/test-wallet.test.js +0 -15
@@ -3,24 +3,14 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var services_wallet_service = require('./service.js');
6
- require('assert');
7
- require('uuid');
8
6
  require('../../wallet/memory-storage-wallet.js');
9
7
  require('@docknetwork/universal-wallet/storage-wallet');
10
8
  require('../../wallet/memory-storage-interface.js');
11
9
  require('@docknetwork/universal-wallet/storage/storage-interface');
12
- require('../../wallet/rpc-storage-wallet.js');
13
- require('../../wallet/rpc-storage-interface.js');
14
- require('../storage/service.js');
15
- require('../../core/logger.js');
16
- require('../keyring/service.js');
17
- require('@polkadot/keyring');
18
- require('@polkadot/util-crypto');
19
- require('../keyring/configs.js');
10
+ require('./configs.js');
11
+ require('assert');
20
12
  require('../../core/validation.js');
21
- require('bignumber.js');
22
13
  require('../../types.js');
23
- require('./configs.js');
24
14
 
25
15
 
26
16
 
@@ -1,19 +1,9 @@
1
1
  export { walletService } from './service.mjs';
2
- import 'assert';
3
- import 'uuid';
4
2
  import '../../wallet/memory-storage-wallet.mjs';
5
3
  import '@docknetwork/universal-wallet/storage-wallet';
6
4
  import '../../wallet/memory-storage-interface.mjs';
7
5
  import '@docknetwork/universal-wallet/storage/storage-interface';
8
- import '../../wallet/rpc-storage-wallet.mjs';
9
- import '../../wallet/rpc-storage-interface.mjs';
10
- import '../storage/service.mjs';
11
- import '../../core/logger.mjs';
12
- import '../keyring/service.mjs';
13
- import '@polkadot/keyring';
14
- import '@polkadot/util-crypto';
15
- import '../keyring/configs.mjs';
6
+ import './configs.mjs';
7
+ import 'assert';
16
8
  import '../../core/validation.mjs';
17
- import 'bignumber.js';
18
9
  import '../../types.mjs';
19
- import './configs.mjs';
@@ -13,7 +13,6 @@ require('../../core/logger.js');
13
13
  require('../../logger.js');
14
14
  require('../../rpc-util.js');
15
15
  require('../../core/validation.js');
16
- require('bignumber.js');
17
16
  require('../../types.js');
18
17
 
19
18
  class WalletServiceRpc extends services_rpcServiceClient.RpcService {
@@ -21,82 +20,6 @@ class WalletServiceRpc extends services_rpcServiceClient.RpcService {
21
20
  super(services_wallet_configs.serviceName);
22
21
  }
23
22
 
24
- getDocumentById(id ) {
25
- services_wallet_configs.validation.getDocumentById(id);
26
- return this.call('getDocumentById', id);
27
- }
28
-
29
- create(params ) {
30
- services_wallet_configs.validation.create(params);
31
- return this.call('create', params);
32
- }
33
- load() {
34
- return this.call('load');
35
- }
36
- sync() {
37
- return this.call('sync');
38
- }
39
- lock(password) {
40
- return this.call('lock');
41
- }
42
- healthCheck(timestamp) {
43
- return this.call('healthCheck', timestamp);
44
- }
45
- unlock(password) {
46
- return this.call('unlock');
47
- }
48
- status() {
49
- return this.call('status');
50
- }
51
- toJSON() {
52
- return this.call('toJSON');
53
- }
54
-
55
- add(params ) {
56
- services_wallet_configs.validation.add(params);
57
- return this.call('add', params);
58
- }
59
-
60
- remove(id ) {
61
- services_wallet_configs.validation.remove(id);
62
- return this.call('remove', id);
63
- }
64
-
65
- update(params ) {
66
- services_wallet_configs.validation.update(params);
67
- return this.call('update', params);
68
- }
69
-
70
- query(params ) {
71
- services_wallet_configs.validation.query(params);
72
- return this.call('query', params);
73
- }
74
-
75
- exportWallet(password ) {
76
- services_wallet_configs.validation.exportWallet(password);
77
- return this.call('exportWallet', password);
78
- }
79
-
80
- importWallet(params ) {
81
- services_wallet_configs.validation.importWallet(params);
82
- return this.call('importWallet', params);
83
- }
84
-
85
- exportAccount(params ) {
86
- services_wallet_configs.validation.exportAccount(params);
87
- return this.call('exportAccount', params);
88
- }
89
-
90
- createAccountDocuments(params ) {
91
- services_wallet_configs.validation.createAccountDocuments(params);
92
- return this.call('createAccountDocuments', params);
93
- }
94
-
95
- resolveCorrelations(address ) {
96
- services_wallet_configs.validation.resolveCorrelations(address);
97
- return this.call('resolveCorrelations', address);
98
- }
99
-
100
23
  getDocumentsFromEncryptedWallet(params ) {
101
24
  services_wallet_configs.validation.getDocumentsFromEncryptedWallet(params);
102
25
  return this.call('getDocumentsFromEncryptedWallet', params);
@@ -9,7 +9,6 @@ import '../../core/logger.mjs';
9
9
  import '../../logger.mjs';
10
10
  import '../../rpc-util.mjs';
11
11
  import '../../core/validation.mjs';
12
- import 'bignumber.js';
13
12
  import '../../types.mjs';
14
13
 
15
14
  class WalletServiceRpc extends RpcService {
@@ -17,82 +16,6 @@ class WalletServiceRpc extends RpcService {
17
16
  super(serviceName);
18
17
  }
19
18
 
20
- getDocumentById(id ) {
21
- validation.getDocumentById(id);
22
- return this.call('getDocumentById', id);
23
- }
24
-
25
- create(params ) {
26
- validation.create(params);
27
- return this.call('create', params);
28
- }
29
- load() {
30
- return this.call('load');
31
- }
32
- sync() {
33
- return this.call('sync');
34
- }
35
- lock(password) {
36
- return this.call('lock');
37
- }
38
- healthCheck(timestamp) {
39
- return this.call('healthCheck', timestamp);
40
- }
41
- unlock(password) {
42
- return this.call('unlock');
43
- }
44
- status() {
45
- return this.call('status');
46
- }
47
- toJSON() {
48
- return this.call('toJSON');
49
- }
50
-
51
- add(params ) {
52
- validation.add(params);
53
- return this.call('add', params);
54
- }
55
-
56
- remove(id ) {
57
- validation.remove(id);
58
- return this.call('remove', id);
59
- }
60
-
61
- update(params ) {
62
- validation.update(params);
63
- return this.call('update', params);
64
- }
65
-
66
- query(params ) {
67
- validation.query(params);
68
- return this.call('query', params);
69
- }
70
-
71
- exportWallet(password ) {
72
- validation.exportWallet(password);
73
- return this.call('exportWallet', password);
74
- }
75
-
76
- importWallet(params ) {
77
- validation.importWallet(params);
78
- return this.call('importWallet', params);
79
- }
80
-
81
- exportAccount(params ) {
82
- validation.exportAccount(params);
83
- return this.call('exportAccount', params);
84
- }
85
-
86
- createAccountDocuments(params ) {
87
- validation.createAccountDocuments(params);
88
- return this.call('createAccountDocuments', params);
89
- }
90
-
91
- resolveCorrelations(address ) {
92
- validation.resolveCorrelations(address);
93
- return this.call('resolveCorrelations', address);
94
- }
95
-
96
19
  getDocumentsFromEncryptedWallet(params ) {
97
20
  validation.getDocumentsFromEncryptedWallet(params);
98
21
  return this.call('getDocumentsFromEncryptedWallet', params);
@@ -2,241 +2,27 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var assert = require('assert');
6
- var uuid = require('uuid');
7
5
  var wallet_memoryStorageWallet = require('../../wallet/memory-storage-wallet.js');
8
- var wallet_rpcStorageWallet = require('../../wallet/rpc-storage-wallet.js');
9
- var services_keyring_service = require('../keyring/service.js');
10
6
  var services_wallet_configs = require('./configs.js');
11
- var core_logger = require('../../core/logger.js');
12
7
  require('@docknetwork/universal-wallet/storage-wallet');
13
8
  require('../../wallet/memory-storage-interface.js');
14
9
  require('@docknetwork/universal-wallet/storage/storage-interface');
15
- require('../../wallet/rpc-storage-interface.js');
16
- require('../storage/service.js');
17
- require('@polkadot/keyring');
18
- require('@polkadot/util-crypto');
19
- require('../keyring/configs.js');
10
+ require('assert');
20
11
  require('../../core/validation.js');
21
- require('bignumber.js');
22
12
  require('../../types.js');
23
13
 
24
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
25
-
26
- var assert__default = /*#__PURE__*/_interopDefaultLegacy(assert);
27
-
28
14
  /**
29
15
  * WalletService
30
16
  */
31
17
  class WalletService {
32
18
  wallet;
33
19
  rpcMethods = [
34
- WalletService.prototype.create,
35
- WalletService.prototype.add,
36
- WalletService.prototype.exportWallet,
37
- WalletService.prototype.importWallet,
38
- WalletService.prototype.resolveCorrelations,
39
- WalletService.prototype.createAccountDocuments,
40
- WalletService.prototype.exportAccount,
41
- WalletService.prototype.getDocumentById,
42
- WalletService.prototype.load,
43
- WalletService.prototype.lock,
44
- WalletService.prototype.query,
45
- WalletService.prototype.remove,
46
- WalletService.prototype.status,
47
- WalletService.prototype.toJSON,
48
- WalletService.prototype.sync,
49
- WalletService.prototype.unlock,
50
- WalletService.prototype.update,
51
- WalletService.prototype.healthCheck,
52
20
  WalletService.prototype.getDocumentsFromEncryptedWallet,
53
21
  WalletService.prototype.exportDocuments,
54
22
  ];
55
23
  constructor() {
56
24
  this.name = services_wallet_configs.serviceName;
57
25
  }
58
- create(params) {
59
- const { walletId, type } = params;
60
- core_logger.Logger.debug('Creating wallet', params);
61
- if (type === 'memory') {
62
- this.wallet = new wallet_memoryStorageWallet(walletId);
63
- }
64
- else {
65
- this.wallet = new wallet_rpcStorageWallet(walletId);
66
- }
67
- }
68
- healthCheck(timestamp) {
69
- return `${this.name}: ${timestamp}`;
70
- }
71
- load() {
72
- this._assertWallet();
73
- return this.wallet.load();
74
- }
75
- sync() {
76
- this._assertWallet();
77
- return this.wallet.sync();
78
- }
79
- lock(password) {
80
- this._assertWallet();
81
- return this.wallet.lock(password);
82
- }
83
- unlock(password) {
84
- this._assertWallet();
85
- return this.wallet.unlock(password);
86
- }
87
- status() {
88
- this._assertWallet();
89
- return this.wallet.status;
90
- }
91
- toJSON() {
92
- this._assertWallet();
93
- return this.wallet.toJSON();
94
- }
95
- add(content) {
96
- this._assertWallet();
97
- services_wallet_configs.validation.add(content);
98
- return this.wallet.add(content);
99
- }
100
- remove(id) {
101
- this._assertWallet();
102
- services_wallet_configs.validation.remove(id);
103
- return this.wallet.remove(id);
104
- }
105
- update(content) {
106
- this._assertWallet();
107
- services_wallet_configs.validation.update(content);
108
- return this.wallet.update(content);
109
- }
110
- query(search) {
111
- this._assertWallet();
112
- services_wallet_configs.validation.query(search);
113
- return this.wallet.query(search);
114
- }
115
- /**
116
- *
117
- * @param {*} password
118
- * @returns
119
- */
120
- exportWallet(password) {
121
- this._assertWallet();
122
- services_wallet_configs.validation.exportWallet(password);
123
- return this.wallet.export(password);
124
- }
125
- /**
126
- *
127
- * @param {*} param0
128
- * @returns
129
- */
130
- importWallet(params) {
131
- this._assertWallet();
132
- services_wallet_configs.validation.importWallet(params);
133
- const { json, password } = params;
134
- return this.wallet.import(json, password);
135
- }
136
- async removeAll() {
137
- this._assertWallet();
138
- const documents = await this.wallet.query({});
139
- for (let doc of documents) {
140
- await this.wallet.remove(doc.id);
141
- }
142
- await this.wallet.sync();
143
- }
144
- /**
145
- *
146
- * @param {*} params
147
- * @returns
148
- */
149
- async exportAccount(params) {
150
- services_wallet_configs.validation.exportAccount(params);
151
- const { address, password, keyPairDocument } = params;
152
- let pair;
153
- if (keyPairDocument) {
154
- pair = services_keyring_service.keyringService.decryptKeyPair({
155
- jsonData: keyPairDocument,
156
- password: '',
157
- });
158
- }
159
- else {
160
- pair = await this.getAccountKeypair(address);
161
- }
162
- return pair.toJson(password);
163
- }
164
- /**
165
- *
166
- * @param {*} params
167
- * @returns
168
- */
169
- async createAccountDocuments(params) {
170
- this._assertWallet();
171
- services_wallet_configs.validation.createAccountDocuments(params);
172
- const { name, type = 'sr25519', derivePath, mnemonic, json, password, hasBackup } = params;
173
- const keyringPair = json
174
- ? services_keyring_service.keyringService.decryptKeyPair({ jsonData: json, password })
175
- : services_keyring_service.keyringService.getKeyringPair({ mnemonic, derivePath, type });
176
- const keyringJson = keyringPair.toJson();
177
- const correlationDocs = [];
178
- correlationDocs.push({
179
- '@context': ['https://w3id.org/wallet/v1'],
180
- id: uuid.v4(),
181
- type: 'KeyringPair',
182
- value: keyringJson,
183
- });
184
- correlationDocs.push({
185
- '@context': ['https://w3id.org/wallet/v1'],
186
- id: uuid.v4(),
187
- type: 'Currency',
188
- value: 0,
189
- symbol: 'DOCK',
190
- });
191
- if (mnemonic) {
192
- correlationDocs.push({
193
- '@context': ['https://w3id.org/wallet/v1'],
194
- id: uuid.v4(),
195
- type: 'Mnemonic',
196
- value: mnemonic,
197
- });
198
- }
199
- core_logger.Logger.info(`Account created: ${keyringPair.address}`);
200
- const addressDocument = {
201
- '@context': ['https://w3id.org/wallet/v1'],
202
- id: keyringPair.address,
203
- type: 'Address',
204
- value: keyringPair.address,
205
- address: keyringPair.address,
206
- name,
207
- correlation: correlationDocs.map(doc => doc.id),
208
- hasBackup,
209
- };
210
- await this.wallet.add(addressDocument);
211
- await Promise.all(correlationDocs.map(doc => this.wallet.add(doc)));
212
- return [addressDocument, ...correlationDocs];
213
- }
214
- async resolveCorrelations(documentId) {
215
- const document = await this.getDocumentById(documentId);
216
- assert__default["default"](!!document, `Document ${documentId} not found`);
217
- const correlation = await Promise.all((document.correlation || []).map(docId => this.getDocumentById(docId)));
218
- const result = [document, ...correlation];
219
- return result;
220
- }
221
- _assertWallet() {
222
- assert__default["default"](!!this.wallet, 'wallet is not created');
223
- }
224
- async getAccountKeypair(accountId) {
225
- const correlations = await this.resolveCorrelations(accountId);
226
- const keyPairDocument = correlations.find(doc => doc.type === 'KeyringPair');
227
- assert__default["default"](!!keyPairDocument, `Keypair document not found for account: ${accountId}`);
228
- const pair = services_keyring_service.keyringService.decryptKeyPair({
229
- jsonData: keyPairDocument.value,
230
- password: '',
231
- });
232
- pair.unlock();
233
- return pair;
234
- }
235
- getDocumentById(id) {
236
- this._assertWallet();
237
- services_wallet_configs.validation.getDocumentById(id);
238
- return this.wallet.getStorageDocument({ id }).then(doc => doc.content);
239
- }
240
26
  async getDocumentsFromEncryptedWallet(params) {
241
27
  services_wallet_configs.validation.getDocumentsFromEncryptedWallet(params);
242
28
  const { encryptedJSONWallet, password } = params;