@docknetwork/wallet-sdk-wasm 1.5.8 → 1.5.10

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 (322) 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 -32
  6. package/lib/index.mjs +13 -32
  7. package/lib/rpc-server.js +13 -32
  8. package/lib/rpc-server.mjs +13 -32
  9. package/lib/rpc-util.js +14 -0
  10. package/lib/rpc-util.mjs +14 -0
  11. package/lib/services/blockchain/index.js +3 -8
  12. package/lib/services/blockchain/index.mjs +3 -8
  13. package/lib/services/blockchain/service.js +37 -80
  14. package/lib/services/blockchain/service.mjs +38 -81
  15. package/lib/services/credential/bbs-revocation.js +4 -9
  16. package/lib/services/credential/bbs-revocation.mjs +3 -8
  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 -15
  20. package/lib/services/credential/index.mjs +11 -15
  21. package/lib/services/credential/service.js +18 -20
  22. package/lib/services/credential/service.mjs +15 -17
  23. package/lib/services/credential/utils.js +65 -28
  24. package/lib/services/credential/utils.mjs +62 -32
  25. package/lib/services/dids/index.js +11 -16
  26. package/lib/services/dids/index.mjs +11 -16
  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.js +16 -37
  30. package/lib/services/dids/service.mjs +16 -37
  31. package/lib/services/edv/index.js +8 -16
  32. package/lib/services/edv/index.mjs +8 -16
  33. package/lib/services/edv/service.js +10 -24
  34. package/lib/services/edv/service.mjs +10 -24
  35. package/lib/services/index.js +13 -37
  36. package/lib/services/index.mjs +13 -37
  37. package/lib/services/pex/service.js +2 -1
  38. package/lib/services/pex/service.mjs +2 -1
  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 -239
  52. package/lib/services/test-utils.mjs +1 -234
  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 +0 -23
  62. package/lib/services/util-crypto/service-rpc.mjs +0 -23
  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 -32
  78. package/lib/setup-nodejs.mjs +13 -32
  79. package/lib/setup-tests.js +13 -32
  80. package/lib/setup-tests.mjs +13 -32
  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 +7 -3
  87. package/lib/src/services/blockchain/service.d.ts.map +1 -1
  88. package/lib/src/services/credential/bbs-revocation.d.ts.map +1 -1
  89. package/lib/src/services/credential/bound-check.d.ts +1 -1
  90. package/lib/src/services/credential/bound-check.d.ts.map +1 -1
  91. package/lib/src/services/credential/service.d.ts.map +1 -1
  92. package/lib/src/services/credential/utils.d.ts +2 -1
  93. package/lib/src/services/credential/utils.d.ts.map +1 -1
  94. package/lib/src/services/dids/keypair-utils.d.ts +15 -0
  95. package/lib/src/services/dids/keypair-utils.d.ts.map +1 -0
  96. package/lib/src/services/dids/service.d.ts +6 -6
  97. package/lib/src/services/dids/service.d.ts.map +1 -1
  98. package/lib/src/services/edv/service.d.ts.map +1 -1
  99. package/lib/src/services/pex/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 +6 -27
  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/index.test.js +4 -15
  120. package/src/services/blockchain/service.ts +39 -98
  121. package/src/services/credential/bbs-revocation.ts +2 -1
  122. package/src/services/credential/bound-check.test.ts +6 -6
  123. package/src/services/credential/bound-check.ts +4 -4
  124. package/src/services/credential/index.test.js +0 -2
  125. package/src/services/credential/service.ts +5 -2
  126. package/src/services/credential/utils.js +65 -23
  127. package/src/services/dids/index.test.js +9 -20
  128. package/src/services/dids/keypair-utils.js +111 -0
  129. package/src/services/dids/service.ts +7 -26
  130. package/src/services/edv/service.ts +2 -9
  131. package/src/services/index.js +0 -8
  132. package/src/services/pex/service.ts +7 -1
  133. package/src/services/test-utils.js +0 -207
  134. package/src/services/util-crypto/configs.ts +0 -12
  135. package/src/services/util-crypto/index.test.js +6 -83
  136. package/src/services/util-crypto/service-rpc.js +0 -20
  137. package/src/services/util-crypto/service.ts +62 -75
  138. package/src/services/wallet/configs.ts +1 -113
  139. package/src/services/wallet/index.test.js +0 -159
  140. package/src/services/wallet/service-rpc.js +1 -88
  141. package/src/services/wallet/service.ts +0 -258
  142. package/src/test-utils.js +0 -13
  143. package/lib/account-8fa95046.js +0 -774
  144. package/lib/account-e7156c51.js +0 -764
  145. package/lib/core/polkadot-utils.js +0 -119
  146. package/lib/core/polkadot-utils.mjs +0 -94
  147. package/lib/core/realm-schemas.js +0 -50
  148. package/lib/core/realm-schemas.mjs +0 -44
  149. package/lib/core/subscan.js +0 -75
  150. package/lib/core/subscan.mjs +0 -64
  151. package/lib/fixtures.js +0 -56
  152. package/lib/fixtures.mjs +0 -52
  153. package/lib/modules/account.js +0 -55
  154. package/lib/modules/account.mjs +0 -47
  155. package/lib/modules/accounts.js +0 -56
  156. package/lib/modules/accounts.mjs +0 -47
  157. package/lib/modules/data-migration.js +0 -72
  158. package/lib/modules/data-migration.mjs +0 -68
  159. package/lib/modules/wallet-backup.js +0 -82
  160. package/lib/modules/wallet-backup.mjs +0 -71
  161. package/lib/modules/wallet.js +0 -56
  162. package/lib/modules/wallet.mjs +0 -47
  163. package/lib/services/example/configs.js +0 -21
  164. package/lib/services/example/configs.mjs +0 -13
  165. package/lib/services/example/index.js +0 -18
  166. package/lib/services/example/index.mjs +0 -14
  167. package/lib/services/example/service-rpc.js +0 -25
  168. package/lib/services/example/service-rpc.mjs +0 -21
  169. package/lib/services/example/service.js +0 -25
  170. package/lib/services/example/service.mjs +0 -20
  171. package/lib/services/keyring/configs.js +0 -70
  172. package/lib/services/keyring/configs.mjs +0 -61
  173. package/lib/services/keyring/index.android.js +0 -22
  174. package/lib/services/keyring/index.android.mjs +0 -18
  175. package/lib/services/keyring/index.ios.js +0 -22
  176. package/lib/services/keyring/index.ios.mjs +0 -18
  177. package/lib/services/keyring/index.js +0 -16
  178. package/lib/services/keyring/index.mjs +0 -8
  179. package/lib/services/keyring/service-rpc.js +0 -65
  180. package/lib/services/keyring/service-rpc.mjs +0 -61
  181. package/lib/services/keyring/service.js +0 -84
  182. package/lib/services/keyring/service.mjs +0 -74
  183. package/lib/services/polkadot/configs.js +0 -17
  184. package/lib/services/polkadot/configs.mjs +0 -13
  185. package/lib/services/polkadot/index.android.js +0 -22
  186. package/lib/services/polkadot/index.android.mjs +0 -18
  187. package/lib/services/polkadot/index.ios.js +0 -22
  188. package/lib/services/polkadot/index.ios.mjs +0 -18
  189. package/lib/services/polkadot/index.js +0 -15
  190. package/lib/services/polkadot/index.mjs +0 -7
  191. package/lib/services/polkadot/service-rpc.js +0 -30
  192. package/lib/services/polkadot/service-rpc.mjs +0 -26
  193. package/lib/services/polkadot/service.js +0 -28
  194. package/lib/services/polkadot/service.mjs +0 -23
  195. package/lib/services/substrate/api-utils.js +0 -85
  196. package/lib/services/substrate/api-utils.mjs +0 -74
  197. package/lib/services/substrate/configs.js +0 -30
  198. package/lib/services/substrate/configs.mjs +0 -21
  199. package/lib/services/substrate/index.android.js +0 -22
  200. package/lib/services/substrate/index.android.mjs +0 -18
  201. package/lib/services/substrate/index.ios.js +0 -22
  202. package/lib/services/substrate/index.ios.mjs +0 -18
  203. package/lib/services/substrate/index.js +0 -37
  204. package/lib/services/substrate/index.mjs +0 -29
  205. package/lib/services/substrate/service-rpc.js +0 -37
  206. package/lib/services/substrate/service-rpc.mjs +0 -33
  207. package/lib/services/substrate/service.js +0 -115
  208. package/lib/services/substrate/service.mjs +0 -102
  209. package/lib/services/trust-registry/configs.js +0 -25
  210. package/lib/services/trust-registry/configs.mjs +0 -16
  211. package/lib/services/trust-registry/index.android.js +0 -19
  212. package/lib/services/trust-registry/index.android.mjs +0 -15
  213. package/lib/services/trust-registry/index.ios.js +0 -19
  214. package/lib/services/trust-registry/index.ios.mjs +0 -15
  215. package/lib/services/trust-registry/index.js +0 -33
  216. package/lib/services/trust-registry/index.mjs +0 -25
  217. package/lib/services/trust-registry/service-rpc.js +0 -29
  218. package/lib/services/trust-registry/service-rpc.mjs +0 -25
  219. package/lib/services/trust-registry/service.js +0 -89
  220. package/lib/services/trust-registry/service.mjs +0 -85
  221. package/lib/src/core/polkadot-utils.d.ts +0 -11
  222. package/lib/src/core/polkadot-utils.d.ts.map +0 -1
  223. package/lib/src/modules/account.d.ts +0 -60
  224. package/lib/src/modules/account.d.ts.map +0 -1
  225. package/lib/src/modules/accounts.d.ts +0 -49
  226. package/lib/src/modules/accounts.d.ts.map +0 -1
  227. package/lib/src/modules/data-migration.d.ts +0 -7
  228. package/lib/src/modules/data-migration.d.ts.map +0 -1
  229. package/lib/src/modules/wallet-backup.d.ts +0 -12
  230. package/lib/src/modules/wallet-backup.d.ts.map +0 -1
  231. package/lib/src/modules/wallet.d.ts +0 -134
  232. package/lib/src/modules/wallet.d.ts.map +0 -1
  233. package/lib/src/services/blockchain/index.d.ts +0 -2
  234. package/lib/src/services/blockchain/index.d.ts.map +0 -1
  235. package/lib/src/services/example/configs.d.ts +0 -9
  236. package/lib/src/services/example/configs.d.ts.map +0 -1
  237. package/lib/src/services/example/service.d.ts +0 -8
  238. package/lib/src/services/example/service.d.ts.map +0 -1
  239. package/lib/src/services/keyring/configs.d.ts +0 -39
  240. package/lib/src/services/keyring/configs.d.ts.map +0 -1
  241. package/lib/src/services/keyring/index.d.ts +0 -2
  242. package/lib/src/services/keyring/index.d.ts.map +0 -1
  243. package/lib/src/services/polkadot/configs.d.ts +0 -8
  244. package/lib/src/services/polkadot/configs.d.ts.map +0 -1
  245. package/lib/src/services/polkadot/index.d.ts +0 -2
  246. package/lib/src/services/polkadot/index.d.ts.map +0 -1
  247. package/lib/src/services/polkadot/service.d.ts +0 -8
  248. package/lib/src/services/polkadot/service.d.ts.map +0 -1
  249. package/lib/src/services/substrate/api-utils.d.ts +0 -14
  250. package/lib/src/services/substrate/api-utils.d.ts.map +0 -1
  251. package/lib/src/services/substrate/configs.d.ts +0 -16
  252. package/lib/src/services/substrate/configs.d.ts.map +0 -1
  253. package/lib/src/services/substrate/index.d.ts +0 -2
  254. package/lib/src/services/substrate/index.d.ts.map +0 -1
  255. package/lib/src/services/substrate/service.d.ts +0 -13
  256. package/lib/src/services/substrate/service.d.ts.map +0 -1
  257. package/lib/src/services/trust-registry/configs.d.ts +0 -6
  258. package/lib/src/services/trust-registry/configs.d.ts.map +0 -1
  259. package/lib/src/services/trust-registry/service.d.ts +0 -25
  260. package/lib/src/services/trust-registry/service.d.ts.map +0 -1
  261. package/lib/src/services/wallet/index.d.ts +0 -2
  262. package/lib/src/services/wallet/index.d.ts.map +0 -1
  263. package/lib/test/axiosMocks.js +0 -431
  264. package/lib/test/axiosMocks.mjs +0 -420
  265. package/lib/test/setup-test-state.js +0 -93
  266. package/lib/test/setup-test-state.mjs +0 -85
  267. package/src/core/polkadot-utils.js +0 -99
  268. package/src/core/realm-schemas.js +0 -42
  269. package/src/core/subscan.js +0 -62
  270. package/src/core/subscan.test.js +0 -56
  271. package/src/fixtures.js +0 -43
  272. package/src/modules/account.test.js +0 -56
  273. package/src/modules/account.ts +0 -128
  274. package/src/modules/accounts.test.js +0 -88
  275. package/src/modules/accounts.ts +0 -264
  276. package/src/modules/data-migration.test.js +0 -72
  277. package/src/modules/data-migration.ts +0 -86
  278. package/src/modules/wallet-backup.test.js +0 -24
  279. package/src/modules/wallet-backup.ts +0 -68
  280. package/src/modules/wallet.test.js +0 -227
  281. package/src/modules/wallet.ts +0 -424
  282. package/src/services/example/configs.js +0 -14
  283. package/src/services/example/index.js +0 -3
  284. package/src/services/example/index.test.js +0 -28
  285. package/src/services/example/service-rpc.js +0 -11
  286. package/src/services/example/service.ts +0 -18
  287. package/src/services/keyring/configs.ts +0 -110
  288. package/src/services/keyring/index.android.js +0 -3
  289. package/src/services/keyring/index.ios.js +0 -3
  290. package/src/services/keyring/index.js +0 -1
  291. package/src/services/keyring/index.test.js +0 -48
  292. package/src/services/keyring/service-rpc.js +0 -56
  293. package/src/services/keyring/service.ts +0 -111
  294. package/src/services/polkadot/configs.ts +0 -13
  295. package/src/services/polkadot/index.android.js +0 -3
  296. package/src/services/polkadot/index.ios.js +0 -3
  297. package/src/services/polkadot/index.js +0 -1
  298. package/src/services/polkadot/index.test.js +0 -52
  299. package/src/services/polkadot/service-rpc.js +0 -13
  300. package/src/services/polkadot/service.ts +0 -21
  301. package/src/services/substrate/api-utils.test.js +0 -73
  302. package/src/services/substrate/api-utils.ts +0 -66
  303. package/src/services/substrate/configs.ts +0 -34
  304. package/src/services/substrate/index.android.js +0 -3
  305. package/src/services/substrate/index.ios.js +0 -3
  306. package/src/services/substrate/index.js +0 -1
  307. package/src/services/substrate/index.test.js +0 -116
  308. package/src/services/substrate/service-rpc.js +0 -24
  309. package/src/services/substrate/service.ts +0 -117
  310. package/src/services/trust-registry/configs.ts +0 -14
  311. package/src/services/trust-registry/index.android.js +0 -3
  312. package/src/services/trust-registry/index.ios.js +0 -3
  313. package/src/services/trust-registry/index.js +0 -1
  314. package/src/services/trust-registry/index.test.js +0 -67
  315. package/src/services/trust-registry/service-rpc.js +0 -15
  316. package/src/services/trust-registry/service.ts +0 -94
  317. package/src/test/axiosMocks.js +0 -20
  318. package/src/test/fixtures/subscan-failure.json +0 -5
  319. package/src/test/fixtures/subscan-success.json +0 -370
  320. package/src/test/fixtures/subscan-too-many-requests.json +0 -9
  321. package/src/test/setup-test-state.js +0 -37
  322. package/src/test/test-wallet.test.js +0 -15
@@ -1,98 +1,11 @@
1
1
  import {RpcService} from '../rpc-service-client';
2
- import {
3
- AddParams,
4
- CreateAccountDocumentsParams,
5
- ExportAccountParams,
6
- ImportWalletParams,
7
- QueryParams,
8
- serviceName,
9
- UpdateParams,
10
- GetDocumentsFromEncryptedWallet,
11
- ExportDocuments,
12
- validation,
13
- } from './configs';
2
+ import {serviceName, ExportDocuments, validation} from './configs';
14
3
 
15
4
  export class WalletServiceRpc extends RpcService {
16
5
  constructor() {
17
6
  super(serviceName);
18
7
  }
19
8
 
20
- getDocumentById(id: string): Promise<any> {
21
- validation.getDocumentById(id);
22
- return this.call('getDocumentById', id);
23
- }
24
-
25
- create(params: CreateParams): Promise<any> {
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: AddParams) {
52
- validation.add(params);
53
- return this.call('add', params);
54
- }
55
-
56
- remove(id: string) {
57
- validation.remove(id);
58
- return this.call('remove', id);
59
- }
60
-
61
- update(params: UpdateParams) {
62
- validation.update(params);
63
- return this.call('update', params);
64
- }
65
-
66
- query(params: QueryParams) {
67
- validation.query(params);
68
- return this.call('query', params);
69
- }
70
-
71
- exportWallet(password: string) {
72
- validation.exportWallet(password);
73
- return this.call('exportWallet', password);
74
- }
75
-
76
- importWallet(params: ImportWalletParams) {
77
- validation.importWallet(params);
78
- return this.call('importWallet', params);
79
- }
80
-
81
- exportAccount(params: ExportAccountParams) {
82
- validation.exportAccount(params);
83
- return this.call('exportAccount', params);
84
- }
85
-
86
- createAccountDocuments(params: CreateAccountDocumentsParams) {
87
- validation.createAccountDocuments(params);
88
- return this.call('createAccountDocuments', params);
89
- }
90
-
91
- resolveCorrelations(address: string) {
92
- validation.resolveCorrelations(address);
93
- return this.call('resolveCorrelations', address);
94
- }
95
-
96
9
  getDocumentsFromEncryptedWallet(params: GetDocumentsFromEncryptedWallet) {
97
10
  validation.getDocumentsFromEncryptedWallet(params);
98
11
  return this.call('getDocumentsFromEncryptedWallet', params);
@@ -5,7 +5,6 @@ import {v4 as uuid} from 'uuid';
5
5
  import {WalletDocument} from '../../types';
6
6
  import MemoryWallet from '../../wallet/memory-storage-wallet';
7
7
  import RpcWallet from '../../wallet/rpc-storage-wallet';
8
- import {keyringService} from '../keyring/service';
9
8
  import {
10
9
  CreateAccountDocumentsParams,
11
10
  CreateParams,
@@ -23,24 +22,6 @@ export class WalletService {
23
22
  wallet: StorageWallet;
24
23
 
25
24
  rpcMethods = [
26
- WalletService.prototype.create,
27
- WalletService.prototype.add,
28
- WalletService.prototype.exportWallet,
29
- WalletService.prototype.importWallet,
30
- WalletService.prototype.resolveCorrelations,
31
- WalletService.prototype.createAccountDocuments,
32
- WalletService.prototype.exportAccount,
33
- WalletService.prototype.getDocumentById,
34
- WalletService.prototype.load,
35
- WalletService.prototype.lock,
36
- WalletService.prototype.query,
37
- WalletService.prototype.remove,
38
- WalletService.prototype.status,
39
- WalletService.prototype.toJSON,
40
- WalletService.prototype.sync,
41
- WalletService.prototype.unlock,
42
- WalletService.prototype.update,
43
- WalletService.prototype.healthCheck,
44
25
  WalletService.prototype.getDocumentsFromEncryptedWallet,
45
26
  WalletService.prototype.exportDocuments,
46
27
  ];
@@ -49,245 +30,6 @@ export class WalletService {
49
30
  this.name = serviceName;
50
31
  }
51
32
 
52
- create(params: CreateParams) {
53
- const {walletId, type} = params;
54
- Logger.debug('Creating wallet', params);
55
- if (type === 'memory') {
56
- this.wallet = new MemoryWallet(walletId);
57
- } else {
58
- this.wallet = new RpcWallet(walletId);
59
- }
60
- }
61
-
62
- healthCheck(timestamp) {
63
- return `${this.name}: ${timestamp}`;
64
- }
65
-
66
- load() {
67
- this._assertWallet();
68
-
69
- return this.wallet.load();
70
- }
71
- sync() {
72
- this._assertWallet();
73
-
74
- return this.wallet.sync();
75
- }
76
- lock(password) {
77
- this._assertWallet();
78
-
79
- return this.wallet.lock(password);
80
- }
81
- unlock(password) {
82
- this._assertWallet();
83
-
84
- return this.wallet.unlock(password);
85
- }
86
- status() {
87
- this._assertWallet();
88
-
89
- return this.wallet.status;
90
- }
91
- toJSON() {
92
- this._assertWallet();
93
-
94
- return this.wallet.toJSON();
95
- }
96
-
97
- add(content) {
98
- this._assertWallet();
99
- validation.add(content);
100
- return this.wallet.add(content);
101
- }
102
-
103
- remove(id: string) {
104
- this._assertWallet();
105
- validation.remove(id);
106
- return this.wallet.remove(id);
107
- }
108
-
109
- update(content) {
110
- this._assertWallet();
111
- validation.update(content);
112
- return this.wallet.update(content);
113
- }
114
-
115
- query(search) {
116
- this._assertWallet();
117
- validation.query(search);
118
- return this.wallet.query(search);
119
- }
120
-
121
- /**
122
- *
123
- * @param {*} password
124
- * @returns
125
- */
126
- exportWallet(password) {
127
- this._assertWallet();
128
- validation.exportWallet(password);
129
- return this.wallet.export(password);
130
- }
131
-
132
- /**
133
- *
134
- * @param {*} param0
135
- * @returns
136
- */
137
- importWallet(params: ImportWalletParams) {
138
- this._assertWallet();
139
- validation.importWallet(params);
140
-
141
- const {json, password} = params;
142
- return this.wallet.import(json, password);
143
- }
144
-
145
- async removeAll() {
146
- this._assertWallet();
147
- const documents = await this.wallet.query({});
148
-
149
- for (let doc of documents) {
150
- await this.wallet.remove(doc.id);
151
- }
152
-
153
- await this.wallet.sync();
154
- }
155
- /**
156
- *
157
- * @param {*} params
158
- * @returns
159
- */
160
- async exportAccount(params: ExportAccountParams) {
161
- validation.exportAccount(params);
162
-
163
- const {address, password, keyPairDocument} = params;
164
-
165
- let pair;
166
-
167
- if (keyPairDocument) {
168
- pair = keyringService.decryptKeyPair({
169
- jsonData: keyPairDocument,
170
- password: '',
171
- });
172
- } else {
173
- pair = await this.getAccountKeypair(address);
174
- }
175
-
176
- return pair.toJson(password);
177
- }
178
- /**
179
- *
180
- * @param {*} params
181
- * @returns
182
- */
183
- async createAccountDocuments(params: CreateAccountDocumentsParams) {
184
- this._assertWallet();
185
- validation.createAccountDocuments(params);
186
-
187
- const {
188
- name,
189
- type = 'sr25519',
190
- derivePath,
191
- mnemonic,
192
- json,
193
- password,
194
- hasBackup
195
- } = params;
196
-
197
- const keyringPair = json
198
- ? keyringService.decryptKeyPair({jsonData: json, password})
199
- : keyringService.getKeyringPair({mnemonic, derivePath, type});
200
- const keyringJson = keyringPair.toJson();
201
- const correlationDocs: WalletDocument[] = [];
202
-
203
- correlationDocs.push({
204
- '@context': ['https://w3id.org/wallet/v1'],
205
- id: uuid(),
206
- type: 'KeyringPair',
207
- value: keyringJson,
208
- });
209
-
210
- correlationDocs.push({
211
- '@context': ['https://w3id.org/wallet/v1'],
212
- id: uuid(),
213
- type: 'Currency',
214
- value: 0,
215
- symbol: 'DOCK',
216
- });
217
-
218
- if (mnemonic) {
219
- correlationDocs.push({
220
- '@context': ['https://w3id.org/wallet/v1'],
221
- id: uuid(),
222
- type: 'Mnemonic',
223
- value: mnemonic,
224
- });
225
- }
226
-
227
- Logger.info(`Account created: ${keyringPair.address}`);
228
-
229
- const addressDocument: WalletDocument = {
230
- '@context': ['https://w3id.org/wallet/v1'],
231
- id: keyringPair.address,
232
- type: 'Address',
233
- value: keyringPair.address,
234
- address: keyringPair.address,
235
- name,
236
- correlation: correlationDocs.map(doc => doc.id),
237
- hasBackup,
238
- };
239
-
240
- await this.wallet.add(addressDocument);
241
- await Promise.all(correlationDocs.map(doc => this.wallet.add(doc)));
242
-
243
- return [addressDocument, ...correlationDocs];
244
- }
245
- async resolveCorrelations(documentId) {
246
- const document = await this.getDocumentById(documentId);
247
-
248
- assert(!!document, `Document ${documentId} not found`);
249
-
250
- const correlation = await Promise.all(
251
- (document.correlation || []).map(docId => this.getDocumentById(docId)),
252
- );
253
-
254
- const result = [document, ...correlation];
255
-
256
- return result;
257
- }
258
-
259
- _assertWallet() {
260
- assert(!!this.wallet, 'wallet is not created');
261
- }
262
-
263
- async getAccountKeypair(accountId) {
264
- const correlations = await this.resolveCorrelations(accountId);
265
- const keyPairDocument = correlations.find(
266
- doc => doc.type === 'KeyringPair',
267
- );
268
-
269
- assert(
270
- !!keyPairDocument,
271
- `Keypair document not found for account: ${accountId}`,
272
- );
273
-
274
- const pair = keyringService.decryptKeyPair({
275
- jsonData: keyPairDocument.value,
276
- password: '',
277
- });
278
-
279
- pair.unlock();
280
-
281
- return pair;
282
- }
283
-
284
- getDocumentById(id: string) {
285
- this._assertWallet();
286
- validation.getDocumentById(id);
287
-
288
- return this.wallet.getStorageDocument({id}).then(doc => doc.content);
289
- }
290
-
291
33
  async getDocumentsFromEncryptedWallet(params) {
292
34
  validation.getDocumentsFromEncryptedWallet(params);
293
35
  const {encryptedJSONWallet, password} = params;
package/src/test-utils.js CHANGED
@@ -27,16 +27,3 @@ export function testRpcEndpoint(service, rpcMethod, ...params) {
27
27
  }
28
28
 
29
29
  export const waitFor = timeout => new Promise(res => setTimeout(res, timeout));
30
-
31
- let sendTokensSpy;
32
- let getFeeSpy;
33
-
34
- export function resetMockTransaction() {
35
- if (sendTokensSpy) {
36
- sendTokensSpy.mockRestore();
37
- }
38
-
39
- if (getFeeSpy) {
40
- getFeeSpy.mockRestore();
41
- }
42
- }