@pezkuwi/util-crypto 14.0.1 → 14.0.3

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 (750) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +4 -4
  3. package/address/addressToEvm.d.ts +5 -0
  4. package/address/addressToEvm.js +8 -0
  5. package/address/check.d.ts +8 -0
  6. package/address/check.js +26 -0
  7. package/address/checksum.d.ts +1 -0
  8. package/address/checksum.js +16 -0
  9. package/address/decode.d.ts +2 -0
  10. package/address/decode.js +29 -0
  11. package/address/defaults.d.ts +6 -0
  12. package/address/defaults.js +8 -0
  13. package/address/derive.d.ts +8 -0
  14. package/address/derive.js +24 -0
  15. package/address/encode.d.ts +2 -0
  16. package/address/encode.js +23 -0
  17. package/address/encodeDerived.d.ts +9 -0
  18. package/address/encodeDerived.js +12 -0
  19. package/address/encodeMulti.d.ts +9 -0
  20. package/address/encodeMulti.js +11 -0
  21. package/address/eq.d.ts +15 -0
  22. package/{src/address/eq.ts → address/eq.js} +2 -7
  23. package/address/evmToAddress.d.ts +7 -0
  24. package/address/evmToAddress.js +14 -0
  25. package/{src/address/index.ts → address/index.d.ts} +0 -5
  26. package/address/index.js +16 -0
  27. package/address/is.d.ts +2 -0
  28. package/address/is.js +9 -0
  29. package/address/keyDerived.d.ts +2 -0
  30. package/address/keyDerived.js +8 -0
  31. package/address/keyMulti.d.ts +2 -0
  32. package/address/keyMulti.js +8 -0
  33. package/address/setSS58Format.d.ts +6 -0
  34. package/address/setSS58Format.js +11 -0
  35. package/address/sort.d.ts +2 -0
  36. package/address/sort.js +7 -0
  37. package/address/sshash.d.ts +1 -0
  38. package/address/sshash.js +6 -0
  39. package/address/types.d.ts +1 -0
  40. package/address/types.js +1 -0
  41. package/address/util.d.ts +1 -0
  42. package/address/util.js +4 -0
  43. package/address/validate.d.ts +2 -0
  44. package/address/validate.js +4 -0
  45. package/base32/bs32.d.ts +26 -0
  46. package/{src/base32/bs32.ts → base32/bs32.js} +8 -21
  47. package/base32/helpers.d.ts +25 -0
  48. package/base32/helpers.js +61 -0
  49. package/{src/base32/index.ts → base32/index.d.ts} +0 -4
  50. package/base32/index.js +4 -0
  51. package/base58/bs58.d.ts +26 -0
  52. package/{src/base58/bs58.ts → base58/bs58.js} +4 -13
  53. package/{src/base58/index.ts → base58/index.d.ts} +0 -4
  54. package/base58/index.js +4 -0
  55. package/base64/bs64.d.ts +26 -0
  56. package/{src/base64/bs64.ts → base64/bs64.js} +4 -13
  57. package/{src/base64/index.ts → base64/index.d.ts} +0 -4
  58. package/base64/index.js +6 -0
  59. package/base64/pad.d.ts +5 -0
  60. package/base64/pad.js +7 -0
  61. package/base64/trim.d.ts +5 -0
  62. package/base64/trim.js +10 -0
  63. package/blake2/asU8a.d.ts +20 -0
  64. package/{src/blake2/asU8a.ts → blake2/asU8a.js} +8 -16
  65. package/{src/blake2/index.ts → blake2/index.d.ts} +0 -4
  66. package/blake2/index.js +4 -0
  67. package/bn.d.ts +30 -0
  68. package/{src/bn.ts → bn.js} +0 -7
  69. package/bundle-polkadot-util-crypto.js +11813 -0
  70. package/{src/bundle.ts → bundle.d.ts} +0 -7
  71. package/bundle.js +26 -0
  72. package/bundleInit.d.ts +1 -0
  73. package/bundleInit.js +5 -0
  74. package/cjs/address/addressToEvm.d.ts +5 -0
  75. package/cjs/address/addressToEvm.js +11 -0
  76. package/cjs/address/check.d.ts +8 -0
  77. package/cjs/address/check.js +29 -0
  78. package/cjs/address/checksum.d.ts +1 -0
  79. package/cjs/address/checksum.js +19 -0
  80. package/cjs/address/decode.d.ts +2 -0
  81. package/cjs/address/decode.js +32 -0
  82. package/cjs/address/defaults.d.ts +6 -0
  83. package/cjs/address/defaults.js +11 -0
  84. package/cjs/address/derive.d.ts +8 -0
  85. package/cjs/address/derive.js +27 -0
  86. package/cjs/address/encode.d.ts +2 -0
  87. package/cjs/address/encode.js +26 -0
  88. package/cjs/address/encodeDerived.d.ts +9 -0
  89. package/cjs/address/encodeDerived.js +15 -0
  90. package/cjs/address/encodeMulti.d.ts +9 -0
  91. package/cjs/address/encodeMulti.js +14 -0
  92. package/cjs/address/eq.d.ts +15 -0
  93. package/cjs/address/eq.js +22 -0
  94. package/cjs/address/evmToAddress.d.ts +7 -0
  95. package/cjs/address/evmToAddress.js +17 -0
  96. package/cjs/address/index.d.ts +16 -0
  97. package/cjs/address/index.js +35 -0
  98. package/cjs/address/is.d.ts +2 -0
  99. package/cjs/address/is.js +12 -0
  100. package/cjs/address/keyDerived.d.ts +2 -0
  101. package/cjs/address/keyDerived.js +11 -0
  102. package/cjs/address/keyMulti.d.ts +2 -0
  103. package/cjs/address/keyMulti.js +11 -0
  104. package/cjs/address/setSS58Format.d.ts +6 -0
  105. package/cjs/address/setSS58Format.js +14 -0
  106. package/cjs/address/sort.d.ts +2 -0
  107. package/cjs/address/sort.js +10 -0
  108. package/cjs/address/sshash.d.ts +1 -0
  109. package/cjs/address/sshash.js +9 -0
  110. package/cjs/address/types.d.ts +1 -0
  111. package/cjs/address/types.js +2 -0
  112. package/cjs/address/util.d.ts +1 -0
  113. package/cjs/address/util.js +7 -0
  114. package/cjs/address/validate.d.ts +2 -0
  115. package/cjs/address/validate.js +7 -0
  116. package/cjs/base32/bs32.d.ts +26 -0
  117. package/cjs/base32/bs32.js +43 -0
  118. package/cjs/base32/helpers.d.ts +25 -0
  119. package/cjs/base32/helpers.js +67 -0
  120. package/cjs/base32/index.d.ts +4 -0
  121. package/cjs/base32/index.js +11 -0
  122. package/cjs/base58/bs58.d.ts +26 -0
  123. package/cjs/base58/bs58.js +37 -0
  124. package/cjs/base58/index.d.ts +4 -0
  125. package/cjs/base58/index.js +11 -0
  126. package/cjs/base64/bs64.d.ts +26 -0
  127. package/cjs/base64/bs64.js +37 -0
  128. package/cjs/base64/index.d.ts +6 -0
  129. package/cjs/base64/index.js +15 -0
  130. package/cjs/base64/pad.d.ts +5 -0
  131. package/cjs/base64/pad.js +10 -0
  132. package/cjs/base64/trim.d.ts +5 -0
  133. package/cjs/base64/trim.js +13 -0
  134. package/cjs/blake2/asU8a.d.ts +20 -0
  135. package/cjs/blake2/asU8a.js +36 -0
  136. package/cjs/blake2/index.d.ts +4 -0
  137. package/cjs/blake2/index.js +9 -0
  138. package/cjs/bn.d.ts +30 -0
  139. package/cjs/bn.js +11 -0
  140. package/cjs/bundle.d.ts +26 -0
  141. package/cjs/bundle.js +31 -0
  142. package/cjs/bundleInit.d.ts +1 -0
  143. package/cjs/bundleInit.js +7 -0
  144. package/cjs/crypto.d.ts +3 -0
  145. package/cjs/crypto.js +16 -0
  146. package/cjs/ed25519/deriveHard.d.ts +1 -0
  147. package/cjs/ed25519/deriveHard.js +12 -0
  148. package/{src/ed25519/index.ts → cjs/ed25519/index.d.ts} +0 -3
  149. package/cjs/ed25519/index.js +20 -0
  150. package/cjs/ed25519/pair/fromRandom.d.ts +16 -0
  151. package/cjs/ed25519/pair/fromRandom.js +22 -0
  152. package/cjs/ed25519/pair/fromSecret.d.ts +16 -0
  153. package/{src/ed25519/pair/fromSecret.ts → cjs/ed25519/pair/fromSecret.js} +11 -14
  154. package/cjs/ed25519/pair/fromSeed.d.ts +16 -0
  155. package/cjs/ed25519/pair/fromSeed.js +34 -0
  156. package/cjs/ed25519/pair/fromString.d.ts +16 -0
  157. package/cjs/ed25519/pair/fromString.js +23 -0
  158. package/cjs/ed25519/sign.d.ts +16 -0
  159. package/cjs/ed25519/sign.js +33 -0
  160. package/cjs/ed25519/verify.d.ts +15 -0
  161. package/cjs/ed25519/verify.js +39 -0
  162. package/cjs/ethereum/encode.d.ts +2 -0
  163. package/cjs/ethereum/encode.js +28 -0
  164. package/{src/ethereum/index.ts → cjs/ethereum/index.d.ts} +0 -3
  165. package/cjs/ethereum/index.js +9 -0
  166. package/cjs/ethereum/isAddress.d.ts +1 -0
  167. package/cjs/ethereum/isAddress.js +14 -0
  168. package/cjs/ethereum/isChecksum.d.ts +1 -0
  169. package/cjs/ethereum/isChecksum.js +20 -0
  170. package/cjs/hd/ethereum/index.d.ts +2 -0
  171. package/cjs/hd/ethereum/index.js +47 -0
  172. package/{src/hd/index.ts → cjs/hd/index.d.ts} +0 -3
  173. package/cjs/hd/index.js +9 -0
  174. package/cjs/hd/ledger/derivePrivate.d.ts +1 -0
  175. package/cjs/hd/ledger/derivePrivate.js +15 -0
  176. package/cjs/hd/ledger/index.d.ts +2 -0
  177. package/cjs/hd/ledger/index.js +33 -0
  178. package/cjs/hd/ledger/master.d.ts +1 -0
  179. package/cjs/hd/ledger/master.js +19 -0
  180. package/cjs/hd/validatePath.d.ts +2 -0
  181. package/cjs/hd/validatePath.js +20 -0
  182. package/cjs/helpers.d.ts +12 -0
  183. package/cjs/helpers.js +24 -0
  184. package/cjs/hmac/index.d.ts +1 -0
  185. package/cjs/hmac/index.js +7 -0
  186. package/cjs/hmac/shaAsU8a.d.ts +15 -0
  187. package/cjs/hmac/shaAsU8a.js +40 -0
  188. package/cjs/index.d.ts +2 -0
  189. package/cjs/index.js +5 -0
  190. package/cjs/json/constants.d.ts +6 -0
  191. package/cjs/json/constants.js +8 -0
  192. package/cjs/json/decrypt.d.ts +2 -0
  193. package/cjs/json/decrypt.js +16 -0
  194. package/cjs/json/decryptData.d.ts +2 -0
  195. package/cjs/json/decryptData.js +32 -0
  196. package/cjs/json/encrypt.d.ts +2 -0
  197. package/cjs/json/encrypt.js +18 -0
  198. package/cjs/json/encryptFormat.d.ts +2 -0
  199. package/cjs/json/encryptFormat.js +17 -0
  200. package/{src/json/index.ts → cjs/json/index.d.ts} +0 -3
  201. package/cjs/json/index.js +11 -0
  202. package/cjs/json/types.d.ts +16 -0
  203. package/cjs/json/types.js +2 -0
  204. package/cjs/keccak/asU8a.d.ts +30 -0
  205. package/cjs/keccak/asU8a.js +36 -0
  206. package/{src/keccak/index.ts → cjs/keccak/index.d.ts} +0 -4
  207. package/cjs/keccak/index.js +11 -0
  208. package/cjs/key/DeriveJunction.d.ts +12 -0
  209. package/cjs/key/DeriveJunction.js +62 -0
  210. package/cjs/key/extractPath.d.ts +9 -0
  211. package/cjs/key/extractPath.js +26 -0
  212. package/cjs/key/extractSuri.d.ts +11 -0
  213. package/cjs/key/extractSuri.js +25 -0
  214. package/cjs/key/fromPath.d.ts +3 -0
  215. package/cjs/key/fromPath.js +21 -0
  216. package/cjs/key/hdkdDerive.d.ts +3 -0
  217. package/cjs/key/hdkdDerive.js +11 -0
  218. package/cjs/key/hdkdEcdsa.d.ts +1 -0
  219. package/cjs/key/hdkdEcdsa.js +7 -0
  220. package/cjs/key/hdkdEd25519.d.ts +1 -0
  221. package/cjs/key/hdkdEd25519.js +6 -0
  222. package/cjs/key/hdkdSr25519.d.ts +3 -0
  223. package/cjs/key/hdkdSr25519.js +10 -0
  224. package/{src/key/index.ts → cjs/key/index.d.ts} +0 -3
  225. package/cjs/key/index.js +18 -0
  226. package/cjs/mnemonic/bip39.d.ts +5 -0
  227. package/cjs/mnemonic/bip39.js +90 -0
  228. package/cjs/mnemonic/generate.d.ts +13 -0
  229. package/cjs/mnemonic/generate.js +23 -0
  230. package/{src/mnemonic/index.ts → cjs/mnemonic/index.d.ts} +0 -3
  231. package/cjs/mnemonic/index.js +16 -0
  232. package/cjs/mnemonic/toEntropy.d.ts +1 -0
  233. package/cjs/mnemonic/toEntropy.js +11 -0
  234. package/cjs/mnemonic/toLegacySeed.d.ts +18 -0
  235. package/cjs/mnemonic/toLegacySeed.js +37 -0
  236. package/cjs/mnemonic/toMiniSecret.d.ts +1 -0
  237. package/cjs/mnemonic/toMiniSecret.js +20 -0
  238. package/cjs/mnemonic/validate.d.ts +14 -0
  239. package/cjs/mnemonic/validate.js +24 -0
  240. package/cjs/mnemonic/wordlists/en.d.ts +2 -0
  241. package/cjs/mnemonic/wordlists/en.js +3 -0
  242. package/cjs/mnemonic/wordlists/es.d.ts +2 -0
  243. package/cjs/mnemonic/wordlists/es.js +3 -0
  244. package/cjs/mnemonic/wordlists/fr.d.ts +2 -0
  245. package/cjs/mnemonic/wordlists/fr.js +3 -0
  246. package/{src/mnemonic/wordlists/index.ts → cjs/mnemonic/wordlists/index.d.ts} +0 -3
  247. package/cjs/mnemonic/wordlists/index.js +20 -0
  248. package/cjs/mnemonic/wordlists/it.d.ts +2 -0
  249. package/cjs/mnemonic/wordlists/it.js +3 -0
  250. package/cjs/mnemonic/wordlists/jp.d.ts +2 -0
  251. package/cjs/mnemonic/wordlists/jp.js +3 -0
  252. package/cjs/mnemonic/wordlists/ko.d.ts +2 -0
  253. package/cjs/mnemonic/wordlists/ko.js +3 -0
  254. package/cjs/mnemonic/wordlists/zh-s.d.ts +2 -0
  255. package/cjs/mnemonic/wordlists/zh-s.js +3 -0
  256. package/cjs/mnemonic/wordlists/zh-t.d.ts +2 -0
  257. package/cjs/mnemonic/wordlists/zh-t.js +3 -0
  258. package/cjs/nacl/decrypt.d.ts +15 -0
  259. package/cjs/nacl/decrypt.js +21 -0
  260. package/cjs/nacl/encrypt.d.ts +20 -0
  261. package/cjs/nacl/encrypt.js +25 -0
  262. package/{src/nacl/index.ts → cjs/nacl/index.d.ts} +0 -3
  263. package/cjs/nacl/index.js +10 -0
  264. package/cjs/nacl/tweetnacl.d.ts +2 -0
  265. package/cjs/nacl/tweetnacl.js +238 -0
  266. package/cjs/networks.d.ts +1 -0
  267. package/cjs/networks.js +7 -0
  268. package/cjs/package.json +3 -0
  269. package/cjs/packageDetect.d.ts +1 -0
  270. package/cjs/packageDetect.js +8 -0
  271. package/cjs/packageInfo.d.ts +6 -0
  272. package/cjs/packageInfo.js +4 -0
  273. package/cjs/pbkdf2/encode.d.ts +7 -0
  274. package/cjs/pbkdf2/encode.js +19 -0
  275. package/cjs/pbkdf2/index.d.ts +1 -0
  276. package/cjs/pbkdf2/index.js +5 -0
  277. package/cjs/random/asNumber.d.ts +15 -0
  278. package/cjs/random/asNumber.js +23 -0
  279. package/cjs/random/asU8a.d.ts +20 -0
  280. package/cjs/random/asU8a.js +28 -0
  281. package/{src/random/index.ts → cjs/random/index.d.ts} +0 -4
  282. package/cjs/random/index.js +11 -0
  283. package/cjs/scrypt/defaults.d.ts +3 -0
  284. package/cjs/scrypt/defaults.js +16 -0
  285. package/cjs/scrypt/encode.d.ts +8 -0
  286. package/cjs/scrypt/encode.js +18 -0
  287. package/cjs/scrypt/fromU8a.d.ts +7 -0
  288. package/cjs/scrypt/fromU8a.js +27 -0
  289. package/{src/scrypt/index.ts → cjs/scrypt/index.d.ts} +0 -3
  290. package/cjs/scrypt/index.js +9 -0
  291. package/cjs/scrypt/toU8a.d.ts +2 -0
  292. package/cjs/scrypt/toU8a.js +8 -0
  293. package/cjs/scrypt/types.d.ts +6 -0
  294. package/cjs/scrypt/types.js +2 -0
  295. package/cjs/secp256k1/compress.d.ts +1 -0
  296. package/cjs/secp256k1/compress.js +17 -0
  297. package/cjs/secp256k1/deriveHard.d.ts +1 -0
  298. package/cjs/secp256k1/deriveHard.js +13 -0
  299. package/cjs/secp256k1/expand.d.ts +1 -0
  300. package/cjs/secp256k1/expand.js +20 -0
  301. package/cjs/secp256k1/hasher.d.ts +2 -0
  302. package/cjs/secp256k1/hasher.js +10 -0
  303. package/{src/secp256k1/index.ts → cjs/secp256k1/index.d.ts} +0 -3
  304. package/cjs/secp256k1/index.js +17 -0
  305. package/cjs/secp256k1/pair/fromSeed.d.ts +6 -0
  306. package/cjs/secp256k1/pair/fromSeed.js +34 -0
  307. package/cjs/secp256k1/recover.d.ts +6 -0
  308. package/cjs/secp256k1/recover.js +29 -0
  309. package/cjs/secp256k1/sign.d.ts +7 -0
  310. package/cjs/secp256k1/sign.js +23 -0
  311. package/cjs/secp256k1/tweakAdd.d.ts +1 -0
  312. package/cjs/secp256k1/tweakAdd.js +48 -0
  313. package/cjs/secp256k1/types.d.ts +1 -0
  314. package/cjs/secp256k1/types.js +2 -0
  315. package/cjs/secp256k1/verify.d.ts +6 -0
  316. package/cjs/secp256k1/verify.js +23 -0
  317. package/cjs/sha/asU8a.d.ts +15 -0
  318. package/cjs/sha/asU8a.js +22 -0
  319. package/{src/sha/index.ts → cjs/sha/index.d.ts} +0 -4
  320. package/cjs/sha/index.js +10 -0
  321. package/cjs/signature/index.d.ts +4 -0
  322. package/cjs/signature/index.js +8 -0
  323. package/cjs/signature/verify.d.ts +2 -0
  324. package/cjs/signature/verify.js +81 -0
  325. package/cjs/sr25519/agreement.d.ts +5 -0
  326. package/cjs/sr25519/agreement.js +20 -0
  327. package/cjs/sr25519/derive.d.ts +2 -0
  328. package/cjs/sr25519/derive.js +16 -0
  329. package/cjs/sr25519/deriveHard.d.ts +1 -0
  330. package/cjs/sr25519/deriveHard.js +7 -0
  331. package/cjs/sr25519/derivePublic.d.ts +1 -0
  332. package/cjs/sr25519/derivePublic.js +16 -0
  333. package/cjs/sr25519/deriveSoft.d.ts +1 -0
  334. package/cjs/sr25519/deriveSoft.js +7 -0
  335. package/{src/sr25519/index.ts → cjs/sr25519/index.d.ts} +0 -3
  336. package/cjs/sr25519/index.js +21 -0
  337. package/cjs/sr25519/pair/fromSeed.d.ts +6 -0
  338. package/cjs/sr25519/pair/fromSeed.js +22 -0
  339. package/cjs/sr25519/pair/fromU8a.d.ts +2 -0
  340. package/cjs/sr25519/pair/fromU8a.js +17 -0
  341. package/cjs/sr25519/pair/toU8a.d.ts +2 -0
  342. package/cjs/sr25519/pair/toU8a.js +7 -0
  343. package/cjs/sr25519/sign.d.ts +6 -0
  344. package/cjs/sr25519/sign.js +19 -0
  345. package/cjs/sr25519/verify.d.ts +5 -0
  346. package/cjs/sr25519/verify.js +21 -0
  347. package/cjs/sr25519/vrfSign.d.ts +6 -0
  348. package/cjs/sr25519/vrfSign.js +19 -0
  349. package/cjs/sr25519/vrfVerify.d.ts +5 -0
  350. package/cjs/sr25519/vrfVerify.js +22 -0
  351. package/cjs/types.d.ts +26 -0
  352. package/cjs/types.js +5 -0
  353. package/cjs/xxhash/asU8a.d.ts +20 -0
  354. package/cjs/xxhash/asU8a.js +39 -0
  355. package/{src/xxhash/index.ts → cjs/xxhash/index.d.ts} +0 -4
  356. package/cjs/xxhash/index.js +9 -0
  357. package/cjs/xxhash/xxhash64.d.ts +1 -0
  358. package/cjs/xxhash/xxhash64.js +103 -0
  359. package/crypto.d.ts +3 -0
  360. package/crypto.js +12 -0
  361. package/ed25519/deriveHard.d.ts +1 -0
  362. package/ed25519/deriveHard.js +9 -0
  363. package/ed25519/index.d.ts +10 -0
  364. package/ed25519/index.js +10 -0
  365. package/ed25519/pair/fromRandom.d.ts +16 -0
  366. package/{src/ed25519/pair/fromRandom.ts → ed25519/pair/fromRandom.js} +2 -8
  367. package/ed25519/pair/fromSecret.d.ts +16 -0
  368. package/ed25519/pair/fromSecret.js +23 -0
  369. package/ed25519/pair/fromSeed.d.ts +16 -0
  370. package/{src/ed25519/pair/fromSeed.ts → ed25519/pair/fromSeed.js} +11 -21
  371. package/ed25519/pair/fromString.d.ts +16 -0
  372. package/{src/ed25519/pair/fromString.ts → ed25519/pair/fromString.js} +2 -13
  373. package/ed25519/sign.d.ts +16 -0
  374. package/ed25519/sign.js +30 -0
  375. package/ed25519/verify.d.ts +15 -0
  376. package/ed25519/verify.js +36 -0
  377. package/ethereum/encode.d.ts +2 -0
  378. package/ethereum/encode.js +25 -0
  379. package/ethereum/index.d.ts +3 -0
  380. package/ethereum/index.js +3 -0
  381. package/ethereum/isAddress.d.ts +1 -0
  382. package/ethereum/isAddress.js +11 -0
  383. package/ethereum/isChecksum.d.ts +1 -0
  384. package/ethereum/isChecksum.js +17 -0
  385. package/hd/ethereum/index.d.ts +2 -0
  386. package/hd/ethereum/index.js +44 -0
  387. package/hd/index.d.ts +3 -0
  388. package/hd/index.js +3 -0
  389. package/hd/ledger/derivePrivate.d.ts +1 -0
  390. package/hd/ledger/derivePrivate.js +12 -0
  391. package/hd/ledger/index.d.ts +2 -0
  392. package/hd/ledger/index.js +30 -0
  393. package/hd/ledger/master.d.ts +1 -0
  394. package/hd/ledger/master.js +16 -0
  395. package/hd/validatePath.d.ts +2 -0
  396. package/hd/validatePath.js +16 -0
  397. package/helpers.d.ts +12 -0
  398. package/helpers.js +19 -0
  399. package/hmac/index.d.ts +1 -0
  400. package/hmac/index.js +1 -0
  401. package/hmac/shaAsU8a.d.ts +15 -0
  402. package/{src/hmac/shaAsU8a.ts → hmac/shaAsU8a.js} +11 -23
  403. package/index.d.ts +2 -0
  404. package/index.js +2 -0
  405. package/json/constants.d.ts +6 -0
  406. package/json/constants.js +5 -0
  407. package/json/decrypt.d.ts +2 -0
  408. package/json/decrypt.js +13 -0
  409. package/json/decryptData.d.ts +2 -0
  410. package/json/decryptData.js +29 -0
  411. package/json/encrypt.d.ts +2 -0
  412. package/json/encrypt.js +15 -0
  413. package/json/encryptFormat.d.ts +2 -0
  414. package/json/encryptFormat.js +14 -0
  415. package/json/index.d.ts +4 -0
  416. package/json/index.js +4 -0
  417. package/json/types.d.ts +16 -0
  418. package/json/types.js +1 -0
  419. package/keccak/asU8a.d.ts +30 -0
  420. package/{src/keccak/asU8a.ts → keccak/asU8a.js} +1 -13
  421. package/keccak/index.d.ts +4 -0
  422. package/keccak/index.js +4 -0
  423. package/key/DeriveJunction.d.ts +12 -0
  424. package/key/DeriveJunction.js +58 -0
  425. package/key/extractPath.d.ts +9 -0
  426. package/key/extractPath.js +23 -0
  427. package/key/extractSuri.d.ts +11 -0
  428. package/key/extractSuri.js +22 -0
  429. package/key/fromPath.d.ts +3 -0
  430. package/key/fromPath.js +18 -0
  431. package/key/hdkdDerive.d.ts +3 -0
  432. package/key/hdkdDerive.js +8 -0
  433. package/key/hdkdEcdsa.d.ts +1 -0
  434. package/{src/key/hdkdEcdsa.ts → key/hdkdEcdsa.js} +0 -4
  435. package/key/hdkdEd25519.d.ts +1 -0
  436. package/{src/key/hdkdEd25519.ts → key/hdkdEd25519.js} +0 -4
  437. package/key/hdkdSr25519.d.ts +3 -0
  438. package/key/hdkdSr25519.js +7 -0
  439. package/key/index.d.ts +9 -0
  440. package/key/index.js +9 -0
  441. package/mnemonic/bip39.d.ts +5 -0
  442. package/mnemonic/bip39.js +82 -0
  443. package/mnemonic/generate.d.ts +13 -0
  444. package/{src/mnemonic/generate.ts → mnemonic/generate.js} +4 -9
  445. package/mnemonic/index.d.ts +8 -0
  446. package/mnemonic/index.js +8 -0
  447. package/mnemonic/toEntropy.d.ts +1 -0
  448. package/mnemonic/toEntropy.js +8 -0
  449. package/mnemonic/toLegacySeed.d.ts +18 -0
  450. package/{src/mnemonic/toLegacySeed.ts → mnemonic/toLegacySeed.js} +12 -17
  451. package/mnemonic/toMiniSecret.d.ts +1 -0
  452. package/mnemonic/toMiniSecret.js +17 -0
  453. package/mnemonic/validate.d.ts +14 -0
  454. package/{src/mnemonic/validate.ts → mnemonic/validate.js} +4 -9
  455. package/mnemonic/wordlists/en.d.ts +2 -0
  456. package/{src/mnemonic/wordlists/en.ts → mnemonic/wordlists/en.js} +0 -6
  457. package/mnemonic/wordlists/es.d.ts +2 -0
  458. package/{src/mnemonic/wordlists/es.ts → mnemonic/wordlists/es.js} +0 -6
  459. package/mnemonic/wordlists/fr.d.ts +2 -0
  460. package/{src/mnemonic/wordlists/fr.ts → mnemonic/wordlists/fr.js} +0 -6
  461. package/mnemonic/wordlists/index.d.ts +8 -0
  462. package/mnemonic/wordlists/index.js +8 -0
  463. package/mnemonic/wordlists/it.d.ts +2 -0
  464. package/{src/mnemonic/wordlists/it.ts → mnemonic/wordlists/it.js} +0 -6
  465. package/mnemonic/wordlists/jp.d.ts +2 -0
  466. package/{src/mnemonic/wordlists/jp.ts → mnemonic/wordlists/jp.js} +0 -6
  467. package/mnemonic/wordlists/ko.d.ts +2 -0
  468. package/{src/mnemonic/wordlists/ko.ts → mnemonic/wordlists/ko.js} +0 -6
  469. package/mnemonic/wordlists/zh-s.d.ts +2 -0
  470. package/{src/mnemonic/wordlists/zh-s.ts → mnemonic/wordlists/zh-s.js} +0 -6
  471. package/mnemonic/wordlists/zh-t.d.ts +2 -0
  472. package/{src/mnemonic/wordlists/zh-t.ts → mnemonic/wordlists/zh-t.js} +0 -6
  473. package/nacl/decrypt.d.ts +15 -0
  474. package/{src/nacl/decrypt.ts → nacl/decrypt.js} +2 -6
  475. package/nacl/encrypt.d.ts +20 -0
  476. package/{src/nacl/encrypt.ts → nacl/encrypt.js} +5 -14
  477. package/nacl/index.d.ts +5 -0
  478. package/nacl/index.js +5 -0
  479. package/nacl/tweetnacl.d.ts +2 -0
  480. package/nacl/tweetnacl.js +234 -0
  481. package/networks.d.ts +1 -0
  482. package/networks.js +1 -0
  483. package/package.json +2020 -8
  484. package/packageDetect.d.ts +1 -0
  485. package/{src/packageDetect.ts → packageDetect.js} +0 -8
  486. package/packageInfo.d.ts +6 -0
  487. package/packageInfo.js +1 -0
  488. package/pbkdf2/encode.d.ts +7 -0
  489. package/pbkdf2/encode.js +16 -0
  490. package/pbkdf2/index.d.ts +1 -0
  491. package/pbkdf2/index.js +1 -0
  492. package/random/asNumber.d.ts +15 -0
  493. package/{src/random/asNumber.ts → random/asNumber.js} +2 -10
  494. package/random/asU8a.d.ts +20 -0
  495. package/{src/random/asU8a.ts → random/asU8a.js} +2 -8
  496. package/random/index.d.ts +5 -0
  497. package/random/index.js +5 -0
  498. package/scrypt/defaults.d.ts +3 -0
  499. package/scrypt/defaults.js +13 -0
  500. package/scrypt/encode.d.ts +8 -0
  501. package/scrypt/encode.js +15 -0
  502. package/scrypt/fromU8a.d.ts +7 -0
  503. package/scrypt/fromU8a.js +24 -0
  504. package/scrypt/index.d.ts +3 -0
  505. package/scrypt/index.js +3 -0
  506. package/scrypt/toU8a.d.ts +2 -0
  507. package/scrypt/toU8a.js +5 -0
  508. package/scrypt/types.d.ts +6 -0
  509. package/scrypt/types.js +1 -0
  510. package/secp256k1/compress.d.ts +1 -0
  511. package/secp256k1/compress.js +14 -0
  512. package/secp256k1/deriveHard.d.ts +1 -0
  513. package/secp256k1/deriveHard.js +10 -0
  514. package/secp256k1/expand.d.ts +1 -0
  515. package/secp256k1/expand.js +17 -0
  516. package/secp256k1/hasher.d.ts +2 -0
  517. package/secp256k1/hasher.js +7 -0
  518. package/secp256k1/index.d.ts +7 -0
  519. package/secp256k1/index.js +7 -0
  520. package/secp256k1/pair/fromSeed.d.ts +6 -0
  521. package/secp256k1/pair/fromSeed.js +31 -0
  522. package/secp256k1/recover.d.ts +6 -0
  523. package/secp256k1/recover.js +26 -0
  524. package/secp256k1/sign.d.ts +7 -0
  525. package/secp256k1/sign.js +20 -0
  526. package/secp256k1/tweakAdd.d.ts +1 -0
  527. package/secp256k1/tweakAdd.js +45 -0
  528. package/secp256k1/types.d.ts +1 -0
  529. package/secp256k1/types.js +1 -0
  530. package/secp256k1/verify.d.ts +6 -0
  531. package/secp256k1/verify.js +20 -0
  532. package/sha/asU8a.d.ts +15 -0
  533. package/{src/sha/asU8a.ts → sha/asU8a.js} +1 -12
  534. package/sha/index.d.ts +4 -0
  535. package/sha/index.js +4 -0
  536. package/signature/index.d.ts +4 -0
  537. package/signature/index.js +4 -0
  538. package/signature/verify.d.ts +2 -0
  539. package/signature/verify.js +78 -0
  540. package/sr25519/agreement.d.ts +5 -0
  541. package/sr25519/agreement.js +17 -0
  542. package/sr25519/derive.d.ts +2 -0
  543. package/sr25519/derive.js +12 -0
  544. package/sr25519/deriveHard.d.ts +1 -0
  545. package/{src/sr25519/deriveHard.ts → sr25519/deriveHard.js} +0 -6
  546. package/sr25519/derivePublic.d.ts +1 -0
  547. package/sr25519/derivePublic.js +12 -0
  548. package/sr25519/deriveSoft.d.ts +1 -0
  549. package/{src/sr25519/deriveSoft.ts → sr25519/deriveSoft.js} +0 -6
  550. package/sr25519/index.d.ts +9 -0
  551. package/sr25519/index.js +9 -0
  552. package/sr25519/pair/fromSeed.d.ts +6 -0
  553. package/sr25519/pair/fromSeed.js +18 -0
  554. package/sr25519/pair/fromU8a.d.ts +2 -0
  555. package/sr25519/pair/fromU8a.js +14 -0
  556. package/sr25519/pair/toU8a.d.ts +2 -0
  557. package/sr25519/pair/toU8a.js +4 -0
  558. package/sr25519/sign.d.ts +6 -0
  559. package/sr25519/sign.js +15 -0
  560. package/sr25519/verify.d.ts +5 -0
  561. package/sr25519/verify.js +17 -0
  562. package/sr25519/vrfSign.d.ts +6 -0
  563. package/sr25519/vrfSign.js +15 -0
  564. package/sr25519/vrfVerify.d.ts +5 -0
  565. package/sr25519/vrfVerify.js +18 -0
  566. package/types.d.ts +26 -0
  567. package/types.js +2 -0
  568. package/xxhash/asU8a.d.ts +20 -0
  569. package/{src/xxhash/asU8a.ts → xxhash/asU8a.js} +11 -21
  570. package/xxhash/index.d.ts +4 -0
  571. package/xxhash/index.js +4 -0
  572. package/xxhash/xxhash64.d.ts +1 -0
  573. package/xxhash/xxhash64.js +100 -0
  574. package/src/address/addressToEvm.spec.ts +0 -16
  575. package/src/address/addressToEvm.ts +0 -12
  576. package/src/address/check.spec.ts +0 -44
  577. package/src/address/check.ts +0 -34
  578. package/src/address/checksum.spec.ts +0 -45
  579. package/src/address/checksum.ts +0 -25
  580. package/src/address/decode.spec.ts +0 -138
  581. package/src/address/decode.ts +0 -41
  582. package/src/address/defaults.ts +0 -12
  583. package/src/address/derive.spec.ts +0 -26
  584. package/src/address/derive.ts +0 -36
  585. package/src/address/encode.spec.ts +0 -177
  586. package/src/address/encode.ts +0 -43
  587. package/src/address/encodeDerived.spec.ts +0 -14
  588. package/src/address/encodeDerived.ts +0 -19
  589. package/src/address/encodeMulti.spec.ts +0 -18
  590. package/src/address/encodeMulti.ts +0 -18
  591. package/src/address/eq.spec.ts +0 -45
  592. package/src/address/evmToAddress.spec.ts +0 -20
  593. package/src/address/evmToAddress.ts +0 -24
  594. package/src/address/is.spec.ts +0 -113
  595. package/src/address/is.ts +0 -14
  596. package/src/address/keyDerived.spec.ts +0 -24
  597. package/src/address/keyDerived.ts +0 -22
  598. package/src/address/keyMulti.spec.ts +0 -20
  599. package/src/address/keyMulti.ts +0 -23
  600. package/src/address/setSS58Format.spec.ts +0 -21
  601. package/src/address/setSS58Format.ts +0 -20
  602. package/src/address/sort.spec.ts +0 -22
  603. package/src/address/sort.ts +0 -17
  604. package/src/address/sshash.ts +0 -12
  605. package/src/address/types.ts +0 -6
  606. package/src/address/util.ts +0 -8
  607. package/src/address/validate.spec.ts +0 -113
  608. package/src/address/validate.ts +0 -10
  609. package/src/base32/decode.spec.ts +0 -34
  610. package/src/base32/encode.spec.ts +0 -30
  611. package/src/base32/helpers.ts +0 -93
  612. package/src/base32/is.spec.ts +0 -32
  613. package/src/base32/validate.spec.ts +0 -44
  614. package/src/base58/decode.spec.ts +0 -31
  615. package/src/base58/encode.spec.ts +0 -26
  616. package/src/base58/validate.spec.ts +0 -20
  617. package/src/base64/decode.spec.ts +0 -42
  618. package/src/base64/encode.spec.ts +0 -14
  619. package/src/base64/pad.spec.ts +0 -14
  620. package/src/base64/pad.ts +0 -10
  621. package/src/base64/trim.spec.ts +0 -14
  622. package/src/base64/trim.ts +0 -14
  623. package/src/base64/validate.spec.ts +0 -32
  624. package/src/blake2/asHex.spec.ts +0 -57
  625. package/src/blake2/asU8a.spec.ts +0 -74
  626. package/src/bundleInit.ts +0 -11
  627. package/src/crypto.spec.ts +0 -18
  628. package/src/crypto.ts +0 -18
  629. package/src/ed25519/deriveHard.ts +0 -18
  630. package/src/ed25519/pair/fromRandom.spec.ts +0 -28
  631. package/src/ed25519/pair/fromSecret.spec.ts +0 -33
  632. package/src/ed25519/pair/fromSeed.spec.ts +0 -42
  633. package/src/ed25519/pair/fromString.spec.ts +0 -17
  634. package/src/ed25519/sign.spec.ts +0 -40
  635. package/src/ed25519/sign.ts +0 -38
  636. package/src/ed25519/verify.spec.ts +0 -84
  637. package/src/ed25519/verify.ts +0 -41
  638. package/src/ethereum/encode.spec.ts +0 -59
  639. package/src/ethereum/encode.ts +0 -39
  640. package/src/ethereum/isAddress.spec.ts +0 -34
  641. package/src/ethereum/isAddress.ts +0 -16
  642. package/src/ethereum/isChecksum.ts +0 -27
  643. package/src/ethereum/isCheksum.spec.ts +0 -30
  644. package/src/hd/ethereum/index.spec.ts +0 -54
  645. package/src/hd/ethereum/index.ts +0 -69
  646. package/src/hd/ledger/derivePrivate.ts +0 -34
  647. package/src/hd/ledger/index.spec.ts +0 -64
  648. package/src/hd/ledger/index.ts +0 -42
  649. package/src/hd/ledger/master.spec.ts +0 -19
  650. package/src/hd/ledger/master.ts +0 -26
  651. package/src/hd/validatePath.spec.ts +0 -30
  652. package/src/hd/validatePath.ts +0 -24
  653. package/src/helpers.ts +0 -38
  654. package/src/hmac/index.ts +0 -4
  655. package/src/hmac/shaAsU8a.spec.ts +0 -45
  656. package/src/index.ts +0 -6
  657. package/src/json/constants.ts +0 -11
  658. package/src/json/decrypt.ts +0 -25
  659. package/src/json/decryptData.ts +0 -45
  660. package/src/json/encrypt.ts +0 -25
  661. package/src/json/encryptFormat.ts +0 -20
  662. package/src/json/types.ts +0 -22
  663. package/src/keccak/asHex.spec.ts +0 -30
  664. package/src/keccak/asU8a.spec.ts +0 -56
  665. package/src/key/DeriveJunction.ts +0 -79
  666. package/src/key/extractPath.spec.ts +0 -51
  667. package/src/key/extractPath.ts +0 -37
  668. package/src/key/extractSuri.spec.ts +0 -147
  669. package/src/key/extractSuri.ts +0 -40
  670. package/src/key/fromPath.ts +0 -28
  671. package/src/key/hdkdDerive.ts +0 -17
  672. package/src/key/hdkdSr25519.ts +0 -14
  673. package/src/mnemonic/bip39.spec.ts +0 -80
  674. package/src/mnemonic/bip39.ts +0 -127
  675. package/src/mnemonic/generate.spec.ts +0 -58
  676. package/src/mnemonic/toEntropy.spec.ts +0 -36
  677. package/src/mnemonic/toEntropy.ts +0 -13
  678. package/src/mnemonic/toLegacySeed.spec.ts +0 -52
  679. package/src/mnemonic/toMiniSecret.spec.ts +0 -67
  680. package/src/mnemonic/toMiniSecret.ts +0 -23
  681. package/src/mnemonic/toMiniSecretCmp.spec.ts +0 -64
  682. package/src/mnemonic/validate.spec.ts +0 -39
  683. package/src/mod.ts +0 -4
  684. package/src/nacl/decrypt.spec.ts +0 -26
  685. package/src/nacl/encrypt.spec.ts +0 -20
  686. package/src/nacl/tweetnacl-secretbox-data.spec.ts +0 -4629
  687. package/src/nacl/tweetnacl-secretbox.spec.ts +0 -161
  688. package/src/nacl/tweetnacl.ts +0 -1159
  689. package/src/networks.ts +0 -5
  690. package/src/packageInfo.ts +0 -6
  691. package/src/pbkdf2/encode.spec.ts +0 -54
  692. package/src/pbkdf2/encode.ts +0 -29
  693. package/src/pbkdf2/index.ts +0 -4
  694. package/src/random/asHex.spec.ts +0 -38
  695. package/src/random/asNumber.spec.ts +0 -16
  696. package/src/random/asU8a.spec.ts +0 -36
  697. package/src/scrypt/defaults.ts +0 -19
  698. package/src/scrypt/encode.spec.ts +0 -43
  699. package/src/scrypt/encode.ts +0 -30
  700. package/src/scrypt/fromU8a.ts +0 -44
  701. package/src/scrypt/toU8a.ts +0 -17
  702. package/src/scrypt/types.ts +0 -9
  703. package/src/secp256k1/compress.spec.ts +0 -47
  704. package/src/secp256k1/compress.ts +0 -21
  705. package/src/secp256k1/deriveHard.ts +0 -17
  706. package/src/secp256k1/expand.spec.ts +0 -47
  707. package/src/secp256k1/expand.ts +0 -30
  708. package/src/secp256k1/hasher.spec.ts +0 -24
  709. package/src/secp256k1/hasher.ts +0 -13
  710. package/src/secp256k1/pair/fromSeed.spec.ts +0 -75
  711. package/src/secp256k1/pair/fromSeed.ts +0 -42
  712. package/src/secp256k1/recover.spec.ts +0 -35
  713. package/src/secp256k1/recover.ts +0 -36
  714. package/src/secp256k1/sign.spec.ts +0 -39
  715. package/src/secp256k1/sign.ts +0 -37
  716. package/src/secp256k1/signVerify.spec.ts +0 -94
  717. package/src/secp256k1/tweakAdd.spec.ts +0 -35
  718. package/src/secp256k1/tweakAdd.ts +0 -65
  719. package/src/secp256k1/types.ts +0 -4
  720. package/src/secp256k1/verify.spec.ts +0 -81
  721. package/src/secp256k1/verify.ts +0 -32
  722. package/src/sha/asU8a256.spec.ts +0 -55
  723. package/src/sha/asU8a512.spec.ts +0 -33
  724. package/src/signature/index.ts +0 -8
  725. package/src/signature/verify.spec.ts +0 -230
  726. package/src/signature/verify.ts +0 -114
  727. package/src/sr25519/agreement.spec.ts +0 -31
  728. package/src/sr25519/agreement.ts +0 -23
  729. package/src/sr25519/derive.ts +0 -21
  730. package/src/sr25519/derivePublic.ts +0 -18
  731. package/src/sr25519/pair/fromSeed.spec.ts +0 -35
  732. package/src/sr25519/pair/fromSeed.ts +0 -28
  733. package/src/sr25519/pair/fromU8a.ts +0 -23
  734. package/src/sr25519/pair/testing.spec.ts +0 -161
  735. package/src/sr25519/pair/toU8a.ts +0 -10
  736. package/src/sr25519/sign.spec.ts +0 -28
  737. package/src/sr25519/sign.ts +0 -22
  738. package/src/sr25519/verify.spec.ts +0 -42
  739. package/src/sr25519/verify.ts +0 -23
  740. package/src/sr25519/vrfSign.ts +0 -24
  741. package/src/sr25519/vrfSignVerify.spec.ts +0 -73
  742. package/src/sr25519/vrfVerify.ts +0 -25
  743. package/src/test/index.ts +0 -8
  744. package/src/test/performance.ts +0 -17
  745. package/src/types.ts +0 -33
  746. package/src/xxhash/asHex.spec.ts +0 -36
  747. package/src/xxhash/asU8a.spec.ts +0 -48
  748. package/src/xxhash/xxhash64.ts +0 -155
  749. package/tsconfig.build.json +0 -18
  750. package/tsconfig.spec.json +0 -20
@@ -1,51 +0,0 @@
1
- // Copyright 2017-2025 @polkadot/util-crypto authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- /// <reference types="@polkadot/dev-test/globals.d.ts" />
5
-
6
- import type { ExtractResult } from './extractPath.js';
7
-
8
- import { keyExtractPath } from './extractPath.js';
9
-
10
- describe('keyExtractPath', (): void => {
11
- it('extracts properly from soft', (): void => {
12
- const test = keyExtractPath('/1');
13
-
14
- expect(test.parts).toEqual(['/1']);
15
- expect(test.path.length).toEqual(1);
16
- expect(test.path[0].isHard).toEqual(false);
17
- expect(test.path[0].chainCode).toEqual(Uint8Array.from([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
18
- });
19
-
20
- it('extracts properly from hard', (): void => {
21
- const test = keyExtractPath('//1');
22
-
23
- expect(test.parts).toEqual(['//1']);
24
- expect(test.path.length).toEqual(1);
25
- expect(test.path[0].isHard).toEqual(true);
26
- expect(test.path[0].chainCode).toEqual(Uint8Array.from([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
27
- });
28
-
29
- it('extracts properly from hard/soft', (): void => {
30
- const test = keyExtractPath('//1/2');
31
-
32
- expect(test.parts).toEqual(['//1', '/2']);
33
- expect(test.path.length).toEqual(2);
34
- expect(test.path[0].isHard).toEqual(true);
35
- expect(test.path[0].chainCode).toEqual(Uint8Array.from([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
36
- expect(test.path[1].isHard).toEqual(false);
37
- expect(test.path[1].chainCode).toEqual(Uint8Array.from([2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
38
- });
39
-
40
- it('does not extract from invalid paths (1)', (): void => {
41
- expect(
42
- (): ExtractResult => keyExtractPath('1/2')
43
- ).toThrow(/does not match input/);
44
- });
45
-
46
- it('does not extract from invalid paths (2)', (): void => {
47
- expect(
48
- (): ExtractResult => keyExtractPath('hello')
49
- ).toThrow(/does not match input/);
50
- });
51
- });
@@ -1,37 +0,0 @@
1
- // Copyright 2017-2025 @polkadot/util-crypto authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import { DeriveJunction } from './DeriveJunction.js';
5
-
6
- const RE_JUNCTION = /\/(\/?)([^/]+)/g;
7
-
8
- export interface ExtractResult {
9
- parts: string[] | null;
10
- path: DeriveJunction[];
11
- }
12
-
13
- /**
14
- * @description Extract derivation junctions from the supplied path
15
- */
16
- export function keyExtractPath (derivePath: string): ExtractResult {
17
- const parts = derivePath.match(RE_JUNCTION);
18
- const path: DeriveJunction[] = [];
19
- let constructed = '';
20
-
21
- if (parts) {
22
- constructed = parts.join('');
23
-
24
- for (const p of parts) {
25
- path.push(DeriveJunction.from(p.substring(1)));
26
- }
27
- }
28
-
29
- if (constructed !== derivePath) {
30
- throw new Error(`Re-constructed path "${constructed}" does not match input`);
31
- }
32
-
33
- return {
34
- parts,
35
- path
36
- };
37
- }
@@ -1,147 +0,0 @@
1
- // Copyright 2017-2025 @polkadot/util-crypto authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- /// <reference types="@polkadot/dev-test/globals.d.ts" />
5
-
6
- import type { ExtractResult } from './extractSuri.js';
7
-
8
- import { keyExtractSuri } from './extractSuri.js';
9
-
10
- describe('keyExtractSuri', (): void => {
11
- it('does not extract from invalid suri', (): void => {
12
- expect(
13
- (): ExtractResult => keyExtractSuri('//2')
14
- ).toThrow('Unable to match provided value to a secret URI');
15
- });
16
-
17
- it('derives on "hello world"', (): void => {
18
- const test = keyExtractSuri('hello world');
19
-
20
- expect(test.phrase).toEqual('hello world');
21
- expect(test.path.length).toEqual(0);
22
- });
23
-
24
- it('derives on "hello world/1', (): void => {
25
- const test = keyExtractSuri('hello world/1');
26
-
27
- expect(test.password).not.toBeDefined();
28
- expect(test.phrase).toEqual('hello world');
29
- expect(test.path.length).toEqual(1);
30
- expect(test.path[0].isHard).toEqual(false);
31
- expect(test.path[0].chainCode).toEqual(Uint8Array.from([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
32
- });
33
-
34
- it('derives on "hello world/DOT', (): void => {
35
- const test = keyExtractSuri('hello world/DOT');
36
-
37
- expect(test.password).not.toBeDefined();
38
- expect(test.phrase).toEqual('hello world');
39
- expect(test.path.length).toEqual(1);
40
- expect(test.path[0].isHard).toEqual(false);
41
- expect(test.path[0].chainCode).toEqual(Uint8Array.from([12, 68, 79, 84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
42
- });
43
-
44
- it('derives on "hello world//1', (): void => {
45
- const test = keyExtractSuri('hello world//1');
46
-
47
- expect(test.password).not.toBeDefined();
48
- expect(test.phrase).toEqual('hello world');
49
- expect(test.path.length).toEqual(1);
50
- expect(test.path[0].isHard).toEqual(true);
51
- expect(test.path[0].chainCode).toEqual(Uint8Array.from([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
52
- });
53
-
54
- it('derives on "hello world//DOT', (): void => {
55
- const test = keyExtractSuri('hello world//DOT');
56
-
57
- expect(test.password).not.toBeDefined();
58
- expect(test.phrase).toEqual('hello world');
59
- expect(test.path.length).toEqual(1);
60
- expect(test.path[0].isHard).toEqual(true);
61
- expect(test.path[0].chainCode).toEqual(Uint8Array.from([12, 68, 79, 84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
62
- });
63
-
64
- it('derives on "hello world//1/DOT', (): void => {
65
- const test = keyExtractSuri('hello world//1/DOT');
66
-
67
- expect(test.password).not.toBeDefined();
68
- expect(test.phrase).toEqual('hello world');
69
- expect(test.path.length).toEqual(2);
70
- expect(test.path[0].isHard).toEqual(true);
71
- expect(test.path[0].chainCode).toEqual(Uint8Array.from([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
72
- expect(test.path[1].isHard).toEqual(false);
73
- expect(test.path[1].chainCode).toEqual(Uint8Array.from([12, 68, 79, 84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
74
- });
75
-
76
- it('derives on "hello world//DOT/1', (): void => {
77
- const test = keyExtractSuri('hello world//DOT/1');
78
-
79
- expect(test.password).not.toBeDefined();
80
- expect(test.phrase).toEqual('hello world');
81
- expect(test.path.length).toEqual(2);
82
- expect(test.path[0].isHard).toEqual(true);
83
- expect(test.path[0].chainCode).toEqual(Uint8Array.from([12, 68, 79, 84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
84
- expect(test.path[1].isHard).toEqual(false);
85
- expect(test.path[1].chainCode).toEqual(Uint8Array.from([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
86
- });
87
-
88
- it('derives on "hello world///password"', (): void => {
89
- const test = keyExtractSuri('hello world///password');
90
-
91
- expect(test.password).toEqual('password');
92
- expect(test.phrase).toEqual('hello world');
93
- expect(test.path.length).toEqual(0);
94
- });
95
-
96
- it('derives on "hello world//1/DOT///password"', (): void => {
97
- const test = keyExtractSuri('hello world//1/DOT///password');
98
-
99
- expect(test.password).toEqual('password');
100
- expect(test.phrase).toEqual('hello world');
101
- expect(test.path.length).toEqual(2);
102
- expect(test.path[0].isHard).toEqual(true);
103
- expect(test.path[0].chainCode).toEqual(Uint8Array.from([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
104
- expect(test.path[1].isHard).toEqual(false);
105
- expect(test.path[1].chainCode).toEqual(Uint8Array.from([12, 68, 79, 84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
106
- });
107
-
108
- it('derives on "hello world/1//DOT///password"', (): void => {
109
- const test = keyExtractSuri('hello world/1//DOT///password');
110
-
111
- expect(test.password).toEqual('password');
112
- expect(test.phrase).toEqual('hello world');
113
- expect(test.path.length).toEqual(2);
114
- expect(test.path[0].isHard).toEqual(false);
115
- expect(test.path[0].chainCode).toEqual(Uint8Array.from([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
116
- expect(test.path[1].isHard).toEqual(true);
117
- expect(test.path[1].chainCode).toEqual(Uint8Array.from([12, 68, 79, 84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
118
- });
119
-
120
- it('derives on actual Alice', (): void => {
121
- const test = keyExtractSuri('bottom drive obey lake curtain smoke basket hold race lonely fit walk//Alice');
122
-
123
- expect(test.password).not.toBeDefined();
124
- expect(test.phrase).toEqual('bottom drive obey lake curtain smoke basket hold race lonely fit walk');
125
- expect(test.path.length).toEqual(1);
126
- expect(test.path[0].isHard).toEqual(true);
127
- expect(test.path[0].chainCode).toEqual(Uint8Array.from([20, 65, 108, 105, 99, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
128
- });
129
-
130
- it('derives on uncommon characters', (): void => {
131
- const languageMnemonics = {
132
- chineseSimplified: '熙 礼 淀 谋 耗 搜 雨 瑞 雷 合 析 感',
133
- chineseTraditional: '召 胸 捕 乏 講 祥 隙 幫 動 框 場 給',
134
- french: 'ruiner minute maison ouragan palourde piscine nerveux descente romance édifier ancien médaille',
135
- japanese: 'ほったん はちみつ おやゆび ほかん いりぐち さんいん てぶくろ だいじょうぶ ふとん でぬかえ ちしき あわてる',
136
- korean: '김밥 방향 논리 저절로 증상 지진 회장 오히려 시리즈 최근 학용품 곡식'
137
- };
138
-
139
- Object.keys(languageMnemonics).forEach((mnemonic) => {
140
- const test = keyExtractSuri(mnemonic);
141
-
142
- expect(test.password).not.toBeDefined();
143
- expect(test.phrase).toEqual(mnemonic);
144
- expect(test.path.length).toEqual(0);
145
- });
146
- });
147
- });
@@ -1,40 +0,0 @@
1
- // Copyright 2017-2025 @polkadot/util-crypto authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import type { DeriveJunction } from './DeriveJunction.js';
5
-
6
- import { keyExtractPath } from './extractPath.js';
7
-
8
- export interface ExtractResult {
9
- derivePath: string,
10
- password?: string;
11
- path: DeriveJunction[];
12
- phrase: string;
13
- }
14
-
15
- const RE_CAPTURE = /^((0x[a-fA-F0-9]+|[\p{L}\d]+(?: [\p{L}\d]+)*))((\/\/?[^/]+)*)(\/\/\/(.*))?$/u;
16
-
17
- /**
18
- * @description Extracts the phrase, path and password from a SURI format for specifying secret keys `<secret>/<soft-key>//<hard-key>///<password>` (the `///password` may be omitted, and `/<soft-key>` and `//<hard-key>` maybe repeated and mixed).
19
- */
20
- export function keyExtractSuri (suri: string): ExtractResult {
21
- // Normalize Unicode to NFC to avoid accent-related mismatches
22
- const normalizedSuri = suri.normalize('NFC');
23
-
24
- // eslint-disable-next-line @typescript-eslint/prefer-regexp-exec
25
- const matches = normalizedSuri.match(RE_CAPTURE);
26
-
27
- if (matches === null) {
28
- throw new Error('Unable to match provided value to a secret URI');
29
- }
30
-
31
- const [, phrase, , derivePath, , , password] = matches;
32
- const { path } = keyExtractPath(derivePath);
33
-
34
- return {
35
- derivePath,
36
- password,
37
- path,
38
- phrase
39
- };
40
- }
@@ -1,28 +0,0 @@
1
- // Copyright 2017-2025 @polkadot/util-crypto authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import type { Keypair, KeypairType } from '../types.js';
5
- import type { DeriveJunction } from './DeriveJunction.js';
6
-
7
- import { keyHdkdEcdsa } from './hdkdEcdsa.js';
8
- import { keyHdkdEd25519 } from './hdkdEd25519.js';
9
- import { keyHdkdSr25519 } from './hdkdSr25519.js';
10
-
11
- const generators = {
12
- ecdsa: keyHdkdEcdsa,
13
- ed25519: keyHdkdEd25519,
14
- // FIXME This is Substrate-compatible, not Ethereum-compatible
15
- ethereum: keyHdkdEcdsa,
16
- sr25519: keyHdkdSr25519
17
- };
18
-
19
- export function keyFromPath (pair: Keypair, path: DeriveJunction[], type: KeypairType): Keypair {
20
- const keyHdkd = generators[type];
21
- let result = pair;
22
-
23
- for (const junction of path) {
24
- result = keyHdkd(result, junction);
25
- }
26
-
27
- return result;
28
- }
@@ -1,17 +0,0 @@
1
- // Copyright 2017-2025 @polkadot/util-crypto authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import type { Keypair } from '../types.js';
5
- import type { DeriveJunction } from './DeriveJunction.js';
6
-
7
- export function createSeedDeriveFn (fromSeed: (seed: Uint8Array) => Keypair, derive: (seed: Uint8Array, chainCode: Uint8Array) => Uint8Array): (keypair: Keypair, junction: DeriveJunction) => Keypair {
8
- return (keypair: Keypair, { chainCode, isHard }: DeriveJunction): Keypair => {
9
- if (!isHard) {
10
- throw new Error('A soft key was found in the path and is not supported');
11
- }
12
-
13
- return fromSeed(
14
- derive(keypair.secretKey.subarray(0, 32), chainCode)
15
- );
16
- };
17
- }
@@ -1,14 +0,0 @@
1
- // Copyright 2017-2025 @polkadot/util-crypto authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import type { Keypair } from '../types.js';
5
- import type { DeriveJunction } from './DeriveJunction.js';
6
-
7
- import { sr25519DeriveHard } from '../sr25519/deriveHard.js';
8
- import { sr25519DeriveSoft } from '../sr25519/deriveSoft.js';
9
-
10
- export function keyHdkdSr25519 (keypair: Keypair, { chainCode, isSoft }: DeriveJunction): Keypair {
11
- return isSoft
12
- ? sr25519DeriveSoft(keypair, chainCode)
13
- : sr25519DeriveHard(keypair, chainCode);
14
- }
@@ -1,80 +0,0 @@
1
- // Copyright 2017-2025 @polkadot/util-crypto authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- /// <reference types="@polkadot/dev-test/globals.d.ts" />
5
-
6
- import * as lists from './wordlists/index.js';
7
- import { entropyToMnemonic, generateMnemonic, mnemonicToEntropy, validateMnemonic } from './bip39.js';
8
-
9
- describe('wordlists', (): void => {
10
- for (const [lang, words] of Object.entries(lists)) {
11
- describe(`language ${lang}`, (): void => {
12
- it('has the correct number of words', (): void => {
13
- expect(words).toHaveLength(2048);
14
- });
15
-
16
- it('has no empty words', (): void => {
17
- expect(
18
- words.some((w) => !w.length || w.trim() !== w)
19
- ).toEqual(false);
20
- });
21
- });
22
- }
23
- });
24
-
25
- describe('bip39', (): void => {
26
- const m = 'seed sock milk update focus rotate barely fade car face mechanic mercy';
27
- const e = mnemonicToEntropy(m);
28
-
29
- it('generates a known entropy', (): void => {
30
- expect(e).toEqual(
31
- new Uint8Array([194, 249, 194, 50, 119, 69, 163, 120, 68, 162, 142, 34, 74, 50, 40, 197])
32
- );
33
- });
34
-
35
- it('has a two-way entropy <-> mnemonic (default wordlist)', (): void => {
36
- expect(
37
- entropyToMnemonic(mnemonicToEntropy(entropyToMnemonic(e)))
38
- ).toEqual(m);
39
- });
40
-
41
- for (const [lang, words] of Object.entries(lists)) {
42
- const isUsingList = (test: string, length = 12): void => {
43
- const split = test.split(' ');
44
-
45
- expect(
46
- split
47
- ).toHaveLength(length);
48
- expect(
49
- split.some((w) => words.indexOf(w) === -1)
50
- ).toEqual(false);
51
- };
52
-
53
- describe(`language ${lang}`, (): void => {
54
- it('has a two-way entropy <-> mnemonic', (): void => {
55
- const test = entropyToMnemonic(e, words);
56
- const entr = mnemonicToEntropy(test, words);
57
-
58
- isUsingList(test);
59
-
60
- expect(
61
- entr
62
- ).toEqual(e);
63
-
64
- expect(
65
- entropyToMnemonic(entr, words)
66
- ).toEqual(test);
67
- });
68
-
69
- it('generates a valid mnemonic', (): void => {
70
- const test = generateMnemonic(24, words);
71
-
72
- isUsingList(test, 24);
73
-
74
- expect(
75
- validateMnemonic(test, words)
76
- ).toEqual(true);
77
- });
78
- });
79
- }
80
- });
@@ -1,127 +0,0 @@
1
- // Copyright 2017-2025 @polkadot/util-crypto authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- // Adapted from the bitcoinjs/bip39 source
5
- // https://github.com/bitcoinjs/bip39/blob/1d063b6a6aee4145b34d701037cd3e67f5446ff9/ts_src/index.ts
6
- // Copyright (c) 2014, Wei Lu <luwei.here@gmail.com> and Daniel Cousens <email@dcousens.com>
7
- // ISC Licence
8
- //
9
- // Change made in this version -
10
- // - Adjust formatting (just eslint differences)
11
- // - Only English wordlist (this aligns with the wasm-crypto implementation)
12
- // - Use util-crypto randomAsU8a (instead of randombytes)
13
- // - Remove setting of wordlist passing of wordlist in functions
14
- // - Remove mnemonicToSeed (we only use the sync variant)
15
- // - generateMnemonic takes number of words (instead of strength)
16
-
17
- import { stringToU8a, u8aToU8a } from '@pezkuwi/util';
18
-
19
- import { pbkdf2Encode } from '../pbkdf2/index.js';
20
- import { randomAsU8a } from '../random/index.js';
21
- import { sha256AsU8a } from '../sha/index.js';
22
- import DEFAULT_WORDLIST from './wordlists/en.js';
23
-
24
- const INVALID_MNEMONIC = 'Invalid mnemonic';
25
- const INVALID_ENTROPY = 'Invalid entropy';
26
- const INVALID_CHECKSUM = 'Invalid mnemonic checksum';
27
-
28
- /** @internal */
29
- function normalize (str?: string): string {
30
- return (str || '').normalize('NFKD');
31
- }
32
-
33
- /** @internal */
34
- function binaryToByte (bin: string): number {
35
- return parseInt(bin, 2);
36
- }
37
-
38
- /** @internal */
39
- function bytesToBinary (bytes: number[]): string {
40
- return bytes.map((x) => x.toString(2).padStart(8, '0')).join('');
41
- }
42
-
43
- /** @internal */
44
- function deriveChecksumBits (entropyBuffer: Uint8Array): string {
45
- return bytesToBinary(
46
- Array.from(sha256AsU8a(entropyBuffer))
47
- ).slice(0, (entropyBuffer.length * 8) / 32);
48
- }
49
-
50
- export function mnemonicToSeedSync (mnemonic: string, password?: string): Uint8Array {
51
- return pbkdf2Encode(
52
- stringToU8a(normalize(mnemonic)),
53
- stringToU8a(`mnemonic${normalize(password)}`)
54
- ).password;
55
- }
56
-
57
- export function mnemonicToEntropy (mnemonic: string, wordlist: string[] = DEFAULT_WORDLIST): Uint8Array {
58
- const words = normalize(mnemonic).split(' ');
59
-
60
- if (words.length % 3 !== 0) {
61
- throw new Error(INVALID_MNEMONIC);
62
- }
63
-
64
- // convert word indices to 11 bit binary strings
65
- const bits = words
66
- .map((word): string => {
67
- const index = wordlist.indexOf(word);
68
-
69
- if (index === -1) {
70
- throw new Error(INVALID_MNEMONIC);
71
- }
72
-
73
- return index.toString(2).padStart(11, '0');
74
- })
75
- .join('');
76
-
77
- // split the binary string into ENT/CS
78
- const dividerIndex = Math.floor(bits.length / 33) * 32;
79
- const entropyBits = bits.slice(0, dividerIndex);
80
- const checksumBits = bits.slice(dividerIndex);
81
-
82
- // calculate the checksum and compare
83
- const matched = entropyBits.match(/(.{1,8})/g);
84
- const entropyBytes = matched?.map(binaryToByte);
85
-
86
- if (!entropyBytes || (entropyBytes.length % 4 !== 0) || (entropyBytes.length < 16) || (entropyBytes.length > 32)) {
87
- throw new Error(INVALID_ENTROPY);
88
- }
89
-
90
- const entropy = u8aToU8a(entropyBytes);
91
-
92
- if (deriveChecksumBits(entropy) !== checksumBits) {
93
- throw new Error(INVALID_CHECKSUM);
94
- }
95
-
96
- return entropy;
97
- }
98
-
99
- export function entropyToMnemonic (entropy: Uint8Array, wordlist: string[] = DEFAULT_WORDLIST): string {
100
- // 128 <= ENT <= 256
101
- if ((entropy.length % 4 !== 0) || (entropy.length < 16) || (entropy.length > 32)) {
102
- throw new Error(INVALID_ENTROPY);
103
- }
104
-
105
- const matched = `${bytesToBinary(Array.from(entropy))}${deriveChecksumBits(entropy)}`.match(/(.{1,11})/g);
106
- const mapped = matched?.map((b) => wordlist[binaryToByte(b)]);
107
-
108
- if (!mapped || (mapped.length < 12)) {
109
- throw new Error('Unable to map entropy to mnemonic');
110
- }
111
-
112
- return mapped.join(' ');
113
- }
114
-
115
- export function generateMnemonic (numWords: 12 | 15 | 18 | 21 | 24, wordlist?: string[]): string {
116
- return entropyToMnemonic(randomAsU8a((numWords / 3) * 4), wordlist);
117
- }
118
-
119
- export function validateMnemonic (mnemonic: string, wordlist?: string[]): boolean {
120
- try {
121
- mnemonicToEntropy(mnemonic, wordlist);
122
- } catch {
123
- return false;
124
- }
125
-
126
- return true;
127
- }
@@ -1,58 +0,0 @@
1
- // Copyright 2017-2025 @polkadot/util-crypto authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- /// <reference types="@polkadot/dev-test/globals.d.ts" />
5
-
6
- import { cryptoWaitReady } from '../index.js';
7
- import { french as frenchWords } from './wordlists/index.js';
8
- import { mnemonicGenerate } from './generate.js';
9
- import { mnemonicValidate } from './validate.js';
10
-
11
- await cryptoWaitReady();
12
-
13
- describe('mnemonicGenerate', (): void => {
14
- it('generates a valid mnemonic (default strength)', (): void => {
15
- expect(
16
- mnemonicValidate(mnemonicGenerate())
17
- ).toEqual(true);
18
- });
19
-
20
- it('generates a french mnemonic', (): void => {
21
- const mnemonic = mnemonicGenerate(24, frenchWords);
22
- const words = mnemonic.split(' ');
23
-
24
- expect(words).toHaveLength(24);
25
- expect(
26
- mnemonicValidate(mnemonic, frenchWords)
27
- ).toEqual(true);
28
- expect(
29
- mnemonicValidate(mnemonic)
30
- ).toEqual(false);
31
- expect(
32
- words.every((w) => frenchWords.includes(w))
33
- ).toEqual(true);
34
- });
35
-
36
- for (const onlyJs of [false, true]) {
37
- describe(`onlyJs=${(onlyJs && 'true') || 'false'}`, (): void => {
38
- for (const num of [12, 15, 18, 21, 24] as const) {
39
- it(`generates a valid mnemonic (${num} words)`, (): void => {
40
- const mnemonic = mnemonicGenerate(num, undefined, onlyJs);
41
- const isValid = mnemonicValidate(mnemonic);
42
-
43
- expect(mnemonic.split(' ')).toHaveLength(num);
44
- expect(isValid).toEqual(true);
45
- });
46
- }
47
-
48
- it('generates non-deterministic', (): void => {
49
- const m1 = mnemonicGenerate(24, undefined, onlyJs);
50
- const m2 = mnemonicGenerate(24, undefined, onlyJs);
51
-
52
- expect(m1 === m2).toEqual(false);
53
- expect(mnemonicValidate(m1)).toEqual(true);
54
- expect(mnemonicValidate(m2)).toEqual(true);
55
- });
56
- });
57
- }
58
- });
@@ -1,36 +0,0 @@
1
- // Copyright 2017-2025 @polkadot/util-crypto authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- /// <reference types="@polkadot/dev-test/globals.d.ts" />
5
-
6
- import { u8aToHex } from '@pezkuwi/util';
7
-
8
- import { cryptoWaitReady } from '../index.js';
9
- import tests from '../sr25519/pair/testing.spec.js';
10
- import { french as frenchWords } from './wordlists/index.js';
11
- import { mnemonicToEntropy } from './toEntropy.js';
12
-
13
- await cryptoWaitReady();
14
-
15
- describe('mnemonicToEntropy', (): void => {
16
- for (const onlyJs of [false, true]) {
17
- describe(`onlyJs=${(onlyJs && 'true') || 'false'}`, (): void => {
18
- tests.forEach(([mnemonic, entropy], index): void => {
19
- it(`Created correct entropy for ${index}`, (): void => {
20
- expect(u8aToHex(mnemonicToEntropy(mnemonic, undefined, onlyJs))).toEqual(entropy);
21
- });
22
- });
23
- });
24
- }
25
-
26
- it('has the correct entropy for non-Englist mnemonics', (): void => {
27
- const mnemonic = 'pompier circuler pulpe injure aspect abyssal nuque boueux équerre balisage pieuvre médecin petit suffixe soleil cumuler monstre arlequin liasse pixel garrigue noble buisson scandale';
28
-
29
- expect(
30
- () => mnemonicToEntropy(mnemonic)
31
- ).toThrow();
32
- expect(
33
- mnemonicToEntropy(mnemonic, frenchWords)
34
- ).toEqual(new Uint8Array([189, 230, 55, 17, 65, 33, 40, 4, 106, 9, 11, 88, 227, 26, 229, 76, 59, 123, 200, 55, 177, 232, 158, 66, 34, 54, 93, 54, 255, 74, 137, 70]));
35
- });
36
- });
@@ -1,13 +0,0 @@
1
- // Copyright 2017-2025 @polkadot/util-crypto authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import { hasBigInt } from '@pezkuwi/util';
5
- import { bip39ToEntropy, isReady } from '@pezkuwi/wasm-crypto';
6
-
7
- import { mnemonicToEntropy as jsToEntropy } from './bip39.js';
8
-
9
- export function mnemonicToEntropy (mnemonic: string, wordlist?: string[], onlyJs?: boolean): Uint8Array {
10
- return !hasBigInt || (!wordlist && !onlyJs && isReady())
11
- ? bip39ToEntropy(mnemonic)
12
- : jsToEntropy(mnemonic, wordlist);
13
- }