@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
@@ -9,9 +9,6 @@ import '../../core/logger.mjs';
9
9
  import '../../logger.mjs';
10
10
  import '../../rpc-util.mjs';
11
11
  import './configs.mjs';
12
- import '../../core/validation.mjs';
13
- import 'bignumber.js';
14
- import '../../types.mjs';
15
12
 
16
13
  const utilCryptoService = new UtilCryptoServiceRpc();
17
14
 
@@ -3,14 +3,11 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var services_utilCrypto_service = require('./service.js');
6
- require('@polkadot/keyring');
7
- require('@polkadot/util');
8
- require('@polkadot/util-crypto');
9
- require('assert');
6
+ require('@docknetwork/credential-sdk/utils');
7
+ require('@scure/bip39');
8
+ require('@scure/bip39/wordlists/english');
10
9
  require('./configs.js');
11
- require('../../core/validation.js');
12
- require('bignumber.js');
13
- require('../../types.js');
10
+ require('assert');
14
11
 
15
12
 
16
13
 
@@ -1,9 +1,6 @@
1
1
  export { utilCryptoService } from './service.mjs';
2
- import '@polkadot/keyring';
3
- import '@polkadot/util';
4
- import '@polkadot/util-crypto';
5
- import 'assert';
2
+ import '@docknetwork/credential-sdk/utils';
3
+ import '@scure/bip39';
4
+ import '@scure/bip39/wordlists/english';
6
5
  import './configs.mjs';
7
- import '../../core/validation.mjs';
8
- import 'bignumber.js';
9
- import '../../types.mjs';
6
+ import 'assert';
@@ -12,9 +12,6 @@ require('crypto');
12
12
  require('../../core/logger.js');
13
13
  require('../../logger.js');
14
14
  require('../../rpc-util.js');
15
- require('../../core/validation.js');
16
- require('bignumber.js');
17
- require('../../types.js');
18
15
 
19
16
  class UtilCryptoServiceRpc extends services_rpcServiceClient.RpcService {
20
17
  constructor() {
@@ -33,37 +30,12 @@ class UtilCryptoServiceRpc extends services_rpcServiceClient.RpcService {
33
30
  return this.call('mnemonicToMiniSecret', phrase);
34
31
  }
35
32
 
36
- mnemonicValidate(phrase ) {
37
- services_utilCrypto_configs.validation.mnemonicValidate(phrase);
38
-
39
- return this.call('mnemonicValidate', phrase);
40
- }
41
-
42
- cryptoWaitReady() {
43
- return this.call('cryptoWaitReady');
44
- }
45
-
46
- cryptoIsReady() {
47
- return this.call('cryptoIsReady');
48
- }
49
-
50
- isAddressValid(address ) {
51
- services_utilCrypto_configs.validation.deriveValidate(address);
52
-
53
- return this.call('isAddressValid', address);
54
- }
55
-
56
- deriveValidate(uri ) {
57
- services_utilCrypto_configs.validation.deriveValidate(uri);
58
- return this.call('deriveValidate', uri);
59
- }
60
-
61
33
  isBase64(value ) {
62
34
  return this.call('isBase64', value);
63
35
  }
64
36
 
65
- getAddressPrefix(params ) {
66
- return this.call('getAddressPrefix', params);
37
+ hexToString(hex ) {
38
+ return this.call('hexToString', hex);
67
39
  }
68
40
  }
69
41
 
@@ -8,9 +8,6 @@ import 'crypto';
8
8
  import '../../core/logger.mjs';
9
9
  import '../../logger.mjs';
10
10
  import '../../rpc-util.mjs';
11
- import '../../core/validation.mjs';
12
- import 'bignumber.js';
13
- import '../../types.mjs';
14
11
 
15
12
  class UtilCryptoServiceRpc extends RpcService {
16
13
  constructor() {
@@ -29,37 +26,12 @@ class UtilCryptoServiceRpc extends RpcService {
29
26
  return this.call('mnemonicToMiniSecret', phrase);
30
27
  }
31
28
 
32
- mnemonicValidate(phrase ) {
33
- validation.mnemonicValidate(phrase);
34
-
35
- return this.call('mnemonicValidate', phrase);
36
- }
37
-
38
- cryptoWaitReady() {
39
- return this.call('cryptoWaitReady');
40
- }
41
-
42
- cryptoIsReady() {
43
- return this.call('cryptoIsReady');
44
- }
45
-
46
- isAddressValid(address ) {
47
- validation.deriveValidate(address);
48
-
49
- return this.call('isAddressValid', address);
50
- }
51
-
52
- deriveValidate(uri ) {
53
- validation.deriveValidate(uri);
54
- return this.call('deriveValidate', uri);
55
- }
56
-
57
29
  isBase64(value ) {
58
30
  return this.call('isBase64', value);
59
31
  }
60
32
 
61
- getAddressPrefix(params ) {
62
- return this.call('getAddressPrefix', params);
33
+ hexToString(hex ) {
34
+ return this.call('hexToString', hex);
63
35
  }
64
36
  }
65
37
 
@@ -2,97 +2,104 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var Keyring = require('@polkadot/keyring');
6
- var util = require('@polkadot/util');
7
- var utilCrypto = require('@polkadot/util-crypto');
8
- var assert = require('assert');
5
+ var utils = require('@docknetwork/credential-sdk/utils');
6
+ var bip39 = require('@scure/bip39');
7
+ var english = require('@scure/bip39/wordlists/english');
9
8
  var services_utilCrypto_configs = require('./configs.js');
10
- require('../../core/validation.js');
11
- require('bignumber.js');
12
- require('../../types.js');
9
+ require('assert');
13
10
 
14
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
11
+ function _interopNamespace(e) {
12
+ if (e && e.__esModule) return e;
13
+ var n = Object.create(null);
14
+ if (e) {
15
+ Object.keys(e).forEach(function (k) {
16
+ if (k !== 'default') {
17
+ var d = Object.getOwnPropertyDescriptor(e, k);
18
+ Object.defineProperty(n, k, d.get ? d : {
19
+ enumerable: true,
20
+ get: function () { return e[k]; }
21
+ });
22
+ }
23
+ });
24
+ }
25
+ n["default"] = e;
26
+ return Object.freeze(n);
27
+ }
15
28
 
16
- var assert__default = /*#__PURE__*/_interopDefaultLegacy(assert);
29
+ var bip39__namespace = /*#__PURE__*/_interopNamespace(bip39);
17
30
 
18
31
  // @ts-nocheck
19
32
  class UtilCryptoService {
20
33
  rpcMethods = [
21
34
  UtilCryptoService.prototype.mnemonicGenerate,
22
35
  UtilCryptoService.prototype.mnemonicToMiniSecret,
23
- UtilCryptoService.prototype.mnemonicValidate,
24
- UtilCryptoService.prototype.cryptoWaitReady,
25
- UtilCryptoService.prototype.cryptoIsReady,
26
- UtilCryptoService.prototype.isAddressValid,
27
- UtilCryptoService.prototype.deriveValidate,
28
36
  UtilCryptoService.prototype.isBase64,
29
- UtilCryptoService.prototype.getAddressPrefix,
37
+ UtilCryptoService.prototype.hexToString,
30
38
  ];
31
39
  constructor() {
32
40
  this.name = 'utilCrypto';
33
41
  }
34
- mnemonicGenerate(numWords) {
42
+ mnemonicGenerate(numWords = 12) {
35
43
  services_utilCrypto_configs.validation.mnemonicGenerate(numWords);
36
- return utilCrypto.mnemonicGenerate(numWords);
44
+ // @scure/bip39 uses strength in bits, not number of words
45
+ // 12 words = 128 bits, 15 words = 160 bits, 18 words = 192 bits, 21 words = 224 bits, 24 words = 256 bits
46
+ const strengthMap = {
47
+ 12: 128,
48
+ 15: 160,
49
+ 18: 192,
50
+ 21: 224,
51
+ 24: 256
52
+ };
53
+ const strength = strengthMap[numWords];
54
+ if (!strength) {
55
+ throw new Error(`Invalid number of words: ${numWords}. Supported values: 12, 15, 18, 21, 24`);
56
+ }
57
+ return bip39__namespace.generateMnemonic(english.wordlist, strength);
37
58
  }
38
59
  mnemonicToMiniSecret(phrase) {
39
60
  services_utilCrypto_configs.validation.mnemonicToMiniSecret(phrase);
40
- return utilCrypto.mnemonicToMiniSecret(phrase);
61
+ // Convert mnemonic to entropy which gives us a 32-byte mini secret for 12-word mnemonics
62
+ // This matches the behavior of Polkadot's mnemonicToMiniSecret
63
+ bip39__namespace.mnemonicToEntropy(phrase, english.wordlist);
64
+ // For 12-word mnemonics, entropy is already 16 bytes (128 bits)
65
+ // We need to pad it to 32 bytes to match Polkadot's mini secret size
66
+ // Polkadot uses PBKDF2 with specific parameters, but for compatibility
67
+ // we can use the seed derivation and take the first 32 bytes
68
+ const seed = bip39__namespace.mnemonicToSeedSync(phrase);
69
+ // Return first 32 bytes as Uint8Array to match the expected mini secret format
70
+ return new Uint8Array(seed.slice(0, 32));
41
71
  }
42
72
  isBase64(value) {
43
73
  if (typeof value !== 'string') {
44
74
  return false;
45
75
  }
46
- const decoded1 = Buffer.from(value, 'base64').toString('utf8');
47
- const encoded2 = Buffer.from(decoded1, 'binary').toString('base64');
48
- return value === encoded2;
49
- }
50
- mnemonicValidate(phrase) {
51
- services_utilCrypto_configs.validation.mnemonicValidate(phrase);
52
- return utilCrypto.mnemonicValidate(phrase);
53
- }
54
- cryptoWaitReady() {
55
- return utilCrypto.cryptoWaitReady();
56
- }
57
- cryptoIsReady(...args) {
58
- return utilCrypto.cryptoIsReady();
59
- }
60
- getAddressPrefix(params) {
61
- const { address, startPrefix, endPrefix } = params;
62
- for (let prefix = startPrefix; prefix <= endPrefix; prefix++) {
63
- try {
64
- const decoded = Keyring.decodeAddress(address);
65
- const reencoded = Keyring.encodeAddress(decoded, prefix);
66
- if (reencoded === address) {
67
- return prefix;
68
- }
69
- }
70
- catch (err) {
71
- // Ignore invalid prefixes
72
- }
76
+ if (value === '') {
77
+ return false;
78
+ }
79
+ const regex = '(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}(==)?|[A-Za-z0-9+\\/]{3}=?)?';
80
+ if (!(new RegExp('^' + regex + '$', 'gi')).test(value)) {
81
+ return false;
73
82
  }
74
- return null;
75
- }
76
- isAddressValid(address) {
77
- services_utilCrypto_configs.validation.isAddressValid(address);
78
83
  try {
79
- Keyring.encodeAddress(util.isHex(address) ? util.hexToU8a(address) : Keyring.decodeAddress(address));
80
- return true;
84
+ const decoded = Buffer.from(value, 'base64');
85
+ const asUtf8 = decoded.toString('utf8');
86
+ const reencoded = Buffer.from(asUtf8, 'utf8').toString('base64');
87
+ const normalize = (str) => str.replace(/=+$/, '');
88
+ return normalize(value) === normalize(reencoded);
81
89
  }
82
- catch (error) {
90
+ catch (e) {
83
91
  return false;
84
92
  }
85
93
  }
86
- deriveValidate(uri) {
87
- services_utilCrypto_configs.validation.deriveValidate(uri);
88
- const { password, path } = utilCrypto.keyExtractSuri(uri);
89
- let result = {};
90
- assert__default["default"](path.length, 'invalid derive path');
91
- // show a warning in case the password contains an unintended / character
92
- if (password && password.includes('/')) {
93
- result = { warning: 'slash password detected' };
94
+ hexToString(hex) {
95
+ try {
96
+ const bytes = utils.hexToU8a(hex);
97
+ return utils.u8aToString(bytes);
98
+ }
99
+ catch (e) {
100
+ console.log('error: ', e);
94
101
  }
95
- return result;
102
+ return '';
96
103
  }
97
104
  }
98
105
  const utilCryptoService = new UtilCryptoService();
@@ -1,90 +1,81 @@
1
- import { decodeAddress, encodeAddress } from '@polkadot/keyring';
2
- import { isHex, hexToU8a } from '@polkadot/util';
3
- import { mnemonicGenerate, mnemonicToMiniSecret, mnemonicValidate, cryptoWaitReady, cryptoIsReady, keyExtractSuri } from '@polkadot/util-crypto';
4
- import assert from 'assert';
1
+ import { hexToU8a, u8aToString } from '@docknetwork/credential-sdk/utils';
2
+ import * as bip39 from '@scure/bip39';
3
+ import { wordlist } from '@scure/bip39/wordlists/english';
5
4
  import { validation } from './configs.mjs';
6
- import '../../core/validation.mjs';
7
- import 'bignumber.js';
8
- import '../../types.mjs';
5
+ import 'assert';
9
6
 
10
7
  // @ts-nocheck
11
8
  class UtilCryptoService {
12
9
  rpcMethods = [
13
10
  UtilCryptoService.prototype.mnemonicGenerate,
14
11
  UtilCryptoService.prototype.mnemonicToMiniSecret,
15
- UtilCryptoService.prototype.mnemonicValidate,
16
- UtilCryptoService.prototype.cryptoWaitReady,
17
- UtilCryptoService.prototype.cryptoIsReady,
18
- UtilCryptoService.prototype.isAddressValid,
19
- UtilCryptoService.prototype.deriveValidate,
20
12
  UtilCryptoService.prototype.isBase64,
21
- UtilCryptoService.prototype.getAddressPrefix,
13
+ UtilCryptoService.prototype.hexToString,
22
14
  ];
23
15
  constructor() {
24
16
  this.name = 'utilCrypto';
25
17
  }
26
- mnemonicGenerate(numWords) {
18
+ mnemonicGenerate(numWords = 12) {
27
19
  validation.mnemonicGenerate(numWords);
28
- return mnemonicGenerate(numWords);
20
+ // @scure/bip39 uses strength in bits, not number of words
21
+ // 12 words = 128 bits, 15 words = 160 bits, 18 words = 192 bits, 21 words = 224 bits, 24 words = 256 bits
22
+ const strengthMap = {
23
+ 12: 128,
24
+ 15: 160,
25
+ 18: 192,
26
+ 21: 224,
27
+ 24: 256
28
+ };
29
+ const strength = strengthMap[numWords];
30
+ if (!strength) {
31
+ throw new Error(`Invalid number of words: ${numWords}. Supported values: 12, 15, 18, 21, 24`);
32
+ }
33
+ return bip39.generateMnemonic(wordlist, strength);
29
34
  }
30
35
  mnemonicToMiniSecret(phrase) {
31
36
  validation.mnemonicToMiniSecret(phrase);
32
- return mnemonicToMiniSecret(phrase);
37
+ // Convert mnemonic to entropy which gives us a 32-byte mini secret for 12-word mnemonics
38
+ // This matches the behavior of Polkadot's mnemonicToMiniSecret
39
+ bip39.mnemonicToEntropy(phrase, wordlist);
40
+ // For 12-word mnemonics, entropy is already 16 bytes (128 bits)
41
+ // We need to pad it to 32 bytes to match Polkadot's mini secret size
42
+ // Polkadot uses PBKDF2 with specific parameters, but for compatibility
43
+ // we can use the seed derivation and take the first 32 bytes
44
+ const seed = bip39.mnemonicToSeedSync(phrase);
45
+ // Return first 32 bytes as Uint8Array to match the expected mini secret format
46
+ return new Uint8Array(seed.slice(0, 32));
33
47
  }
34
48
  isBase64(value) {
35
49
  if (typeof value !== 'string') {
36
50
  return false;
37
51
  }
38
- const decoded1 = Buffer.from(value, 'base64').toString('utf8');
39
- const encoded2 = Buffer.from(decoded1, 'binary').toString('base64');
40
- return value === encoded2;
41
- }
42
- mnemonicValidate(phrase) {
43
- validation.mnemonicValidate(phrase);
44
- return mnemonicValidate(phrase);
45
- }
46
- cryptoWaitReady() {
47
- return cryptoWaitReady();
48
- }
49
- cryptoIsReady(...args) {
50
- return cryptoIsReady();
51
- }
52
- getAddressPrefix(params) {
53
- const { address, startPrefix, endPrefix } = params;
54
- for (let prefix = startPrefix; prefix <= endPrefix; prefix++) {
55
- try {
56
- const decoded = decodeAddress(address);
57
- const reencoded = encodeAddress(decoded, prefix);
58
- if (reencoded === address) {
59
- return prefix;
60
- }
61
- }
62
- catch (err) {
63
- // Ignore invalid prefixes
64
- }
52
+ if (value === '') {
53
+ return false;
54
+ }
55
+ const regex = '(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}(==)?|[A-Za-z0-9+\\/]{3}=?)?';
56
+ if (!(new RegExp('^' + regex + '$', 'gi')).test(value)) {
57
+ return false;
65
58
  }
66
- return null;
67
- }
68
- isAddressValid(address) {
69
- validation.isAddressValid(address);
70
59
  try {
71
- encodeAddress(isHex(address) ? hexToU8a(address) : decodeAddress(address));
72
- return true;
60
+ const decoded = Buffer.from(value, 'base64');
61
+ const asUtf8 = decoded.toString('utf8');
62
+ const reencoded = Buffer.from(asUtf8, 'utf8').toString('base64');
63
+ const normalize = (str) => str.replace(/=+$/, '');
64
+ return normalize(value) === normalize(reencoded);
73
65
  }
74
- catch (error) {
66
+ catch (e) {
75
67
  return false;
76
68
  }
77
69
  }
78
- deriveValidate(uri) {
79
- validation.deriveValidate(uri);
80
- const { password, path } = keyExtractSuri(uri);
81
- let result = {};
82
- assert(path.length, 'invalid derive path');
83
- // show a warning in case the password contains an unintended / character
84
- if (password && password.includes('/')) {
85
- result = { warning: 'slash password detected' };
70
+ hexToString(hex) {
71
+ try {
72
+ const bytes = hexToU8a(hex);
73
+ return u8aToString(bytes);
74
+ }
75
+ catch (e) {
76
+ console.log('error: ', e);
86
77
  }
87
- return result;
78
+ return '';
88
79
  }
89
80
  }
90
81
  const utilCryptoService = new UtilCryptoService();
@@ -4,7 +4,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var assert = require('assert');
6
6
  var core_validation = require('../../core/validation.js');
7
- require('bignumber.js');
8
7
  require('../../types.js');
9
8
 
10
9
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -12,57 +11,11 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
12
11
  var assert__default = /*#__PURE__*/_interopDefaultLegacy(assert);
13
12
 
14
13
  // @ts-nocheck
15
- function assertContent(content) {
16
- assert__default["default"](typeof content === 'object', 'invalid wallet content');
17
- assert__default["default"](typeof content.id === 'string', `invalid content id ${content.id}`);
18
- assert__default["default"](typeof content.type === 'string', `invalid content type ${content.type}`);
19
- }
20
14
  const validation = {
21
- getDocumentById(id) {
22
- assert__default["default"](typeof id === 'string', 'invalid documentId');
23
- assert__default["default"](!!id, 'documentId is required');
24
- },
25
- resolveCorrelations(address) {
26
- assert__default["default"](typeof address === 'string', 'invalid documentId');
27
- assert__default["default"](!!address, 'documentId is required');
28
- },
29
- exportAccount({ address, password }) {
30
- core_validation.assertAddress(address);
31
- core_validation.assertPassword(password);
32
- },
33
- create({ walletId }) {
34
- assert__default["default"](typeof walletId === 'string', `invalid walletId ${walletId}`);
35
- },
36
- lock(password) {
37
- core_validation.assertPassword(password);
38
- },
39
- unlock(password) {
40
- core_validation.assertPassword(password);
41
- },
42
- add(params) {
43
- assertContent(params);
44
- },
45
- remove(id) {
46
- assert__default["default"](typeof id === 'string', 'invalid documentId');
47
- assert__default["default"](!!id, 'documentId is required');
48
- },
49
- update(params) {
50
- assertContent(params);
51
- },
52
- query(params) {
53
- assert__default["default"](typeof params === 'object', 'invalid query');
54
- },
55
- exportWallet(password) {
56
- core_validation.assertPassword(password);
57
- },
58
15
  getDocumentsFromEncryptedWallet({ encryptedJSONWallet, password, }) {
59
16
  assert__default["default"](typeof encryptedJSONWallet === 'object', `invalid json data: ${encryptedJSONWallet}`);
60
17
  core_validation.assertPassword(password);
61
18
  },
62
- importWallet({ json, password }) {
63
- assert__default["default"](typeof json === 'object', `invalid json data: ${json}`);
64
- core_validation.assertPassword(password);
65
- },
66
19
  exportDocuments({ documents, password }) {
67
20
  assert__default["default"](Array.isArray(documents), 'Invalid Documents');
68
21
  assert__default["default"](documents.length > 0, 'Cannot export empty documents');
@@ -72,22 +25,6 @@ const validation = {
72
25
  }
73
26
  core_validation.assertPassword(password);
74
27
  },
75
- createAccountDocuments(params) {
76
- const { name, json, password, mnemonic, type } = params;
77
- // Property derivationPath was replaced by derivePath
78
- assert__default["default"](!params.derivationPath, 'invalid parameter derivationPath, it should be derivePath instead');
79
- assert__default["default"](typeof name === 'string', `invalid account name: ${name}`);
80
- if (json) {
81
- assert__default["default"](typeof json === 'object', `invalid json: ${password}`);
82
- assert__default["default"](typeof password === 'string', `invalid password: ${password}`);
83
- }
84
- else {
85
- assert__default["default"](typeof mnemonic === 'string', `invalid mnemonic: ${mnemonic}`);
86
- }
87
- if (type) {
88
- core_validation.assertKeyType(type);
89
- }
90
- },
91
28
  };
92
29
  const serviceName = 'wallet';
93
30
 
@@ -1,60 +1,13 @@
1
1
  import assert from 'assert';
2
- import { assertAddress, assertPassword, assertKeyType } from '../../core/validation.mjs';
3
- import 'bignumber.js';
2
+ import { assertPassword } from '../../core/validation.mjs';
4
3
  import '../../types.mjs';
5
4
 
6
5
  // @ts-nocheck
7
- function assertContent(content) {
8
- assert(typeof content === 'object', 'invalid wallet content');
9
- assert(typeof content.id === 'string', `invalid content id ${content.id}`);
10
- assert(typeof content.type === 'string', `invalid content type ${content.type}`);
11
- }
12
6
  const validation = {
13
- getDocumentById(id) {
14
- assert(typeof id === 'string', 'invalid documentId');
15
- assert(!!id, 'documentId is required');
16
- },
17
- resolveCorrelations(address) {
18
- assert(typeof address === 'string', 'invalid documentId');
19
- assert(!!address, 'documentId is required');
20
- },
21
- exportAccount({ address, password }) {
22
- assertAddress(address);
23
- assertPassword(password);
24
- },
25
- create({ walletId }) {
26
- assert(typeof walletId === 'string', `invalid walletId ${walletId}`);
27
- },
28
- lock(password) {
29
- assertPassword(password);
30
- },
31
- unlock(password) {
32
- assertPassword(password);
33
- },
34
- add(params) {
35
- assertContent(params);
36
- },
37
- remove(id) {
38
- assert(typeof id === 'string', 'invalid documentId');
39
- assert(!!id, 'documentId is required');
40
- },
41
- update(params) {
42
- assertContent(params);
43
- },
44
- query(params) {
45
- assert(typeof params === 'object', 'invalid query');
46
- },
47
- exportWallet(password) {
48
- assertPassword(password);
49
- },
50
7
  getDocumentsFromEncryptedWallet({ encryptedJSONWallet, password, }) {
51
8
  assert(typeof encryptedJSONWallet === 'object', `invalid json data: ${encryptedJSONWallet}`);
52
9
  assertPassword(password);
53
10
  },
54
- importWallet({ json, password }) {
55
- assert(typeof json === 'object', `invalid json data: ${json}`);
56
- assertPassword(password);
57
- },
58
11
  exportDocuments({ documents, password }) {
59
12
  assert(Array.isArray(documents), 'Invalid Documents');
60
13
  assert(documents.length > 0, 'Cannot export empty documents');
@@ -64,22 +17,6 @@ const validation = {
64
17
  }
65
18
  assertPassword(password);
66
19
  },
67
- createAccountDocuments(params) {
68
- const { name, json, password, mnemonic, type } = params;
69
- // Property derivationPath was replaced by derivePath
70
- assert(!params.derivationPath, 'invalid parameter derivationPath, it should be derivePath instead');
71
- assert(typeof name === 'string', `invalid account name: ${name}`);
72
- if (json) {
73
- assert(typeof json === 'object', `invalid json: ${password}`);
74
- assert(typeof password === 'string', `invalid password: ${password}`);
75
- }
76
- else {
77
- assert(typeof mnemonic === 'string', `invalid mnemonic: ${mnemonic}`);
78
- }
79
- if (type) {
80
- assertKeyType(type);
81
- }
82
- },
83
20
  };
84
21
  const serviceName = 'wallet';
85
22
 
@@ -14,7 +14,6 @@ require('../../logger.js');
14
14
  require('../../rpc-util.js');
15
15
  require('./configs.js');
16
16
  require('../../core/validation.js');
17
- require('bignumber.js');
18
17
  require('../../types.js');
19
18
 
20
19
  const walletService = new services_wallet_serviceRpc.WalletServiceRpc();
@@ -10,7 +10,6 @@ import '../../logger.mjs';
10
10
  import '../../rpc-util.mjs';
11
11
  import './configs.mjs';
12
12
  import '../../core/validation.mjs';
13
- import 'bignumber.js';
14
13
  import '../../types.mjs';
15
14
 
16
15
  const walletService = new WalletServiceRpc();
@@ -14,7 +14,6 @@ require('../../logger.js');
14
14
  require('../../rpc-util.js');
15
15
  require('./configs.js');
16
16
  require('../../core/validation.js');
17
- require('bignumber.js');
18
17
  require('../../types.js');
19
18
 
20
19
  const walletService = new services_wallet_serviceRpc.WalletServiceRpc();
@@ -10,7 +10,6 @@ import '../../logger.mjs';
10
10
  import '../../rpc-util.mjs';
11
11
  import './configs.mjs';
12
12
  import '../../core/validation.mjs';
13
- import 'bignumber.js';
14
13
  import '../../types.mjs';
15
14
 
16
15
  const walletService = new WalletServiceRpc();