@docknetwork/wallet-sdk-wasm 1.5.9 → 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 (262) 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 +4 -6
  14. package/lib/services/blockchain/service.mjs +4 -6
  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 +65 -28
  24. package/lib/services/credential/utils.mjs +62 -32
  25. package/lib/services/dids/index.js +11 -14
  26. package/lib/services/dids/index.mjs +11 -14
  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 +15 -34
  30. package/lib/services/dids/service.mjs +15 -34
  31. package/lib/services/edv/index.js +8 -14
  32. package/lib/services/edv/index.mjs +8 -14
  33. package/lib/services/edv/service.js +10 -22
  34. package/lib/services/edv/service.mjs +10 -22
  35. package/lib/services/index.js +13 -25
  36. package/lib/services/index.mjs +13 -25
  37. package/lib/services/relay-service/configs.js +0 -1
  38. package/lib/services/relay-service/configs.mjs +0 -1
  39. package/lib/services/relay-service/index.android.js +0 -1
  40. package/lib/services/relay-service/index.android.mjs +0 -1
  41. package/lib/services/relay-service/index.ios.js +0 -1
  42. package/lib/services/relay-service/index.ios.mjs +0 -1
  43. package/lib/services/relay-service/index.js +0 -1
  44. package/lib/services/relay-service/index.mjs +0 -1
  45. package/lib/services/relay-service/service-rpc.js +0 -1
  46. package/lib/services/relay-service/service-rpc.mjs +0 -1
  47. package/lib/services/relay-service/service.js +0 -1
  48. package/lib/services/relay-service/service.mjs +0 -1
  49. package/lib/services/test-utils.js +0 -44
  50. package/lib/services/test-utils.mjs +1 -44
  51. package/lib/services/util-crypto/configs.js +0 -12
  52. package/lib/services/util-crypto/configs.mjs +0 -12
  53. package/lib/services/util-crypto/index.android.js +0 -3
  54. package/lib/services/util-crypto/index.android.mjs +0 -3
  55. package/lib/services/util-crypto/index.ios.js +0 -3
  56. package/lib/services/util-crypto/index.ios.mjs +0 -3
  57. package/lib/services/util-crypto/index.js +4 -7
  58. package/lib/services/util-crypto/index.mjs +4 -7
  59. package/lib/services/util-crypto/service-rpc.js +0 -23
  60. package/lib/services/util-crypto/service-rpc.mjs +0 -23
  61. package/lib/services/util-crypto/service.js +68 -61
  62. package/lib/services/util-crypto/service.mjs +50 -59
  63. package/lib/services/wallet/configs.js +0 -63
  64. package/lib/services/wallet/configs.mjs +1 -64
  65. package/lib/services/wallet/index.android.js +0 -1
  66. package/lib/services/wallet/index.android.mjs +0 -1
  67. package/lib/services/wallet/index.ios.js +0 -1
  68. package/lib/services/wallet/index.ios.mjs +0 -1
  69. package/lib/services/wallet/index.js +2 -12
  70. package/lib/services/wallet/index.mjs +2 -12
  71. package/lib/services/wallet/service-rpc.js +0 -77
  72. package/lib/services/wallet/service-rpc.mjs +0 -77
  73. package/lib/services/wallet/service.js +1 -215
  74. package/lib/services/wallet/service.mjs +1 -211
  75. package/lib/setup-nodejs.js +13 -23
  76. package/lib/setup-nodejs.mjs +13 -23
  77. package/lib/setup-tests.js +13 -23
  78. package/lib/setup-tests.mjs +13 -23
  79. package/lib/src/core/format-utils.d.ts +0 -5
  80. package/lib/src/core/format-utils.d.ts.map +1 -1
  81. package/lib/src/core/validation.d.ts +0 -3
  82. package/lib/src/core/validation.d.ts.map +1 -1
  83. package/lib/src/rpc-util.d.ts.map +1 -1
  84. package/lib/src/services/blockchain/service.d.ts.map +1 -1
  85. package/lib/src/services/credential/bbs-revocation.d.ts.map +1 -1
  86. package/lib/src/services/credential/bound-check.d.ts +1 -1
  87. package/lib/src/services/credential/bound-check.d.ts.map +1 -1
  88. package/lib/src/services/credential/service.d.ts.map +1 -1
  89. package/lib/src/services/credential/utils.d.ts +2 -1
  90. package/lib/src/services/credential/utils.d.ts.map +1 -1
  91. package/lib/src/services/dids/keypair-utils.d.ts +15 -0
  92. package/lib/src/services/dids/keypair-utils.d.ts.map +1 -0
  93. package/lib/src/services/dids/service.d.ts +6 -6
  94. package/lib/src/services/dids/service.d.ts.map +1 -1
  95. package/lib/src/services/edv/service.d.ts.map +1 -1
  96. package/lib/src/services/util-crypto/configs.d.ts +0 -3
  97. package/lib/src/services/util-crypto/configs.d.ts.map +1 -1
  98. package/lib/src/services/util-crypto/service.d.ts +3 -8
  99. package/lib/src/services/util-crypto/service.d.ts.map +1 -1
  100. package/lib/src/services/wallet/configs.d.ts +13 -0
  101. package/lib/src/services/wallet/configs.d.ts.map +1 -0
  102. package/lib/src/services/wallet/service.d.ts +1 -44
  103. package/lib/src/services/wallet/service.d.ts.map +1 -1
  104. package/lib/test-utils.js +0 -4
  105. package/lib/test-utils.mjs +1 -4
  106. package/lib/tsconfig.tsbuildinfo +1 -1
  107. package/package.json +5 -25
  108. package/readme.md +0 -61
  109. package/src/core/format-utils.test.js +1 -28
  110. package/src/core/format-utils.ts +0 -33
  111. package/src/core/validation.test.js +1 -33
  112. package/src/core/validation.ts +1 -25
  113. package/src/rpc-server.test.js +2 -9
  114. package/src/rpc-util.js +14 -0
  115. package/src/services/blockchain/service.ts +1 -0
  116. package/src/services/credential/bbs-revocation.ts +2 -1
  117. package/src/services/credential/bound-check.test.ts +6 -6
  118. package/src/services/credential/bound-check.ts +4 -4
  119. package/src/services/credential/index.test.js +0 -2
  120. package/src/services/credential/service.ts +5 -2
  121. package/src/services/credential/utils.js +65 -23
  122. package/src/services/dids/index.test.js +8 -19
  123. package/src/services/dids/keypair-utils.js +111 -0
  124. package/src/services/dids/service.ts +6 -25
  125. package/src/services/edv/service.ts +2 -9
  126. package/src/services/index.js +0 -4
  127. package/src/services/test-utils.js +0 -29
  128. package/src/services/util-crypto/configs.ts +0 -12
  129. package/src/services/util-crypto/index.test.js +6 -83
  130. package/src/services/util-crypto/service-rpc.js +0 -20
  131. package/src/services/util-crypto/service.ts +62 -75
  132. package/src/services/wallet/configs.ts +1 -113
  133. package/src/services/wallet/index.test.js +0 -159
  134. package/src/services/wallet/service-rpc.js +1 -88
  135. package/src/services/wallet/service.ts +0 -258
  136. package/src/test-utils.js +0 -13
  137. package/lib/account-357ab05d.js +0 -742
  138. package/lib/account-399e6053.js +0 -752
  139. package/lib/core/polkadot-utils.js +0 -119
  140. package/lib/core/polkadot-utils.mjs +0 -94
  141. package/lib/core/realm-schemas.js +0 -50
  142. package/lib/core/realm-schemas.mjs +0 -44
  143. package/lib/core/subscan.js +0 -75
  144. package/lib/core/subscan.mjs +0 -64
  145. package/lib/fixtures.js +0 -56
  146. package/lib/fixtures.mjs +0 -52
  147. package/lib/modules/account.js +0 -48
  148. package/lib/modules/account.mjs +0 -40
  149. package/lib/modules/accounts.js +0 -49
  150. package/lib/modules/accounts.mjs +0 -40
  151. package/lib/modules/data-migration.js +0 -72
  152. package/lib/modules/data-migration.mjs +0 -68
  153. package/lib/modules/wallet-backup.js +0 -82
  154. package/lib/modules/wallet-backup.mjs +0 -71
  155. package/lib/modules/wallet.js +0 -49
  156. package/lib/modules/wallet.mjs +0 -40
  157. package/lib/services/example/configs.js +0 -21
  158. package/lib/services/example/configs.mjs +0 -13
  159. package/lib/services/example/index.js +0 -18
  160. package/lib/services/example/index.mjs +0 -14
  161. package/lib/services/example/service-rpc.js +0 -25
  162. package/lib/services/example/service-rpc.mjs +0 -21
  163. package/lib/services/example/service.js +0 -25
  164. package/lib/services/example/service.mjs +0 -20
  165. package/lib/services/keyring/configs.js +0 -70
  166. package/lib/services/keyring/configs.mjs +0 -61
  167. package/lib/services/keyring/index.android.js +0 -22
  168. package/lib/services/keyring/index.android.mjs +0 -18
  169. package/lib/services/keyring/index.ios.js +0 -22
  170. package/lib/services/keyring/index.ios.mjs +0 -18
  171. package/lib/services/keyring/index.js +0 -16
  172. package/lib/services/keyring/index.mjs +0 -8
  173. package/lib/services/keyring/service-rpc.js +0 -65
  174. package/lib/services/keyring/service-rpc.mjs +0 -61
  175. package/lib/services/keyring/service.js +0 -84
  176. package/lib/services/keyring/service.mjs +0 -74
  177. package/lib/services/polkadot/configs.js +0 -17
  178. package/lib/services/polkadot/configs.mjs +0 -13
  179. package/lib/services/polkadot/index.android.js +0 -22
  180. package/lib/services/polkadot/index.android.mjs +0 -18
  181. package/lib/services/polkadot/index.ios.js +0 -22
  182. package/lib/services/polkadot/index.ios.mjs +0 -18
  183. package/lib/services/polkadot/index.js +0 -15
  184. package/lib/services/polkadot/index.mjs +0 -7
  185. package/lib/services/polkadot/service-rpc.js +0 -30
  186. package/lib/services/polkadot/service-rpc.mjs +0 -26
  187. package/lib/services/polkadot/service.js +0 -28
  188. package/lib/services/polkadot/service.mjs +0 -23
  189. package/lib/src/core/polkadot-utils.d.ts +0 -11
  190. package/lib/src/core/polkadot-utils.d.ts.map +0 -1
  191. package/lib/src/modules/account.d.ts +0 -60
  192. package/lib/src/modules/account.d.ts.map +0 -1
  193. package/lib/src/modules/accounts.d.ts +0 -48
  194. package/lib/src/modules/accounts.d.ts.map +0 -1
  195. package/lib/src/modules/data-migration.d.ts +0 -7
  196. package/lib/src/modules/data-migration.d.ts.map +0 -1
  197. package/lib/src/modules/wallet-backup.d.ts +0 -12
  198. package/lib/src/modules/wallet-backup.d.ts.map +0 -1
  199. package/lib/src/modules/wallet.d.ts +0 -134
  200. package/lib/src/modules/wallet.d.ts.map +0 -1
  201. package/lib/src/services/blockchain/index.d.ts +0 -2
  202. package/lib/src/services/blockchain/index.d.ts.map +0 -1
  203. package/lib/src/services/example/configs.d.ts +0 -9
  204. package/lib/src/services/example/configs.d.ts.map +0 -1
  205. package/lib/src/services/example/service.d.ts +0 -8
  206. package/lib/src/services/example/service.d.ts.map +0 -1
  207. package/lib/src/services/keyring/configs.d.ts +0 -39
  208. package/lib/src/services/keyring/configs.d.ts.map +0 -1
  209. package/lib/src/services/keyring/index.d.ts +0 -2
  210. package/lib/src/services/keyring/index.d.ts.map +0 -1
  211. package/lib/src/services/polkadot/configs.d.ts +0 -8
  212. package/lib/src/services/polkadot/configs.d.ts.map +0 -1
  213. package/lib/src/services/polkadot/index.d.ts +0 -2
  214. package/lib/src/services/polkadot/index.d.ts.map +0 -1
  215. package/lib/src/services/polkadot/service.d.ts +0 -8
  216. package/lib/src/services/polkadot/service.d.ts.map +0 -1
  217. package/lib/src/services/wallet/index.d.ts +0 -2
  218. package/lib/src/services/wallet/index.d.ts.map +0 -1
  219. package/lib/test/axiosMocks.js +0 -431
  220. package/lib/test/axiosMocks.mjs +0 -420
  221. package/lib/test/setup-test-state.js +0 -81
  222. package/lib/test/setup-test-state.mjs +0 -73
  223. package/src/core/polkadot-utils.js +0 -99
  224. package/src/core/realm-schemas.js +0 -42
  225. package/src/core/subscan.js +0 -62
  226. package/src/core/subscan.test.js +0 -56
  227. package/src/fixtures.js +0 -43
  228. package/src/modules/account.test.js +0 -56
  229. package/src/modules/account.ts +0 -128
  230. package/src/modules/accounts.test.js +0 -63
  231. package/src/modules/accounts.ts +0 -231
  232. package/src/modules/data-migration.test.js +0 -61
  233. package/src/modules/data-migration.ts +0 -86
  234. package/src/modules/wallet-backup.test.js +0 -24
  235. package/src/modules/wallet-backup.ts +0 -68
  236. package/src/modules/wallet.test.js +0 -216
  237. package/src/modules/wallet.ts +0 -424
  238. package/src/services/example/configs.js +0 -14
  239. package/src/services/example/index.js +0 -3
  240. package/src/services/example/index.test.js +0 -28
  241. package/src/services/example/service-rpc.js +0 -11
  242. package/src/services/example/service.ts +0 -18
  243. package/src/services/keyring/configs.ts +0 -110
  244. package/src/services/keyring/index.android.js +0 -3
  245. package/src/services/keyring/index.ios.js +0 -3
  246. package/src/services/keyring/index.js +0 -1
  247. package/src/services/keyring/index.test.js +0 -48
  248. package/src/services/keyring/service-rpc.js +0 -56
  249. package/src/services/keyring/service.ts +0 -111
  250. package/src/services/polkadot/configs.ts +0 -13
  251. package/src/services/polkadot/index.android.js +0 -3
  252. package/src/services/polkadot/index.ios.js +0 -3
  253. package/src/services/polkadot/index.js +0 -1
  254. package/src/services/polkadot/index.test.js +0 -52
  255. package/src/services/polkadot/service-rpc.js +0 -13
  256. package/src/services/polkadot/service.ts +0 -21
  257. package/src/test/axiosMocks.js +0 -20
  258. package/src/test/fixtures/subscan-failure.json +0 -5
  259. package/src/test/fixtures/subscan-success.json +0 -370
  260. package/src/test/fixtures/subscan-too-many-requests.json +0 -9
  261. package/src/test/setup-test-state.js +0 -35
  262. package/src/test/test-wallet.test.js +0 -15
@@ -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();
@@ -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);