@pezkuwi/util-crypto 14.0.10 → 14.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (571) hide show
  1. package/address/addressToEvm.d.ts +5 -0
  2. package/address/addressToEvm.js +8 -0
  3. package/address/check.d.ts +8 -0
  4. package/address/check.js +26 -0
  5. package/address/checksum.d.ts +1 -0
  6. package/address/checksum.js +16 -0
  7. package/address/decode.d.ts +2 -0
  8. package/address/decode.js +29 -0
  9. package/address/defaults.d.ts +6 -0
  10. package/address/defaults.js +8 -0
  11. package/address/derive.d.ts +8 -0
  12. package/address/derive.js +24 -0
  13. package/address/encode.d.ts +2 -0
  14. package/address/encode.js +23 -0
  15. package/address/encodeDerived.d.ts +9 -0
  16. package/address/encodeDerived.js +12 -0
  17. package/address/encodeMulti.d.ts +9 -0
  18. package/address/encodeMulti.js +11 -0
  19. package/address/eq.d.ts +15 -0
  20. package/address/eq.js +19 -0
  21. package/address/evmToAddress.d.ts +7 -0
  22. package/address/evmToAddress.js +14 -0
  23. package/address/index.d.ts +16 -0
  24. package/address/index.js +16 -0
  25. package/address/is.d.ts +2 -0
  26. package/address/is.js +9 -0
  27. package/address/keyDerived.d.ts +2 -0
  28. package/address/keyDerived.js +8 -0
  29. package/address/keyMulti.d.ts +2 -0
  30. package/address/keyMulti.js +8 -0
  31. package/address/setSS58Format.d.ts +6 -0
  32. package/address/setSS58Format.js +11 -0
  33. package/address/sort.d.ts +2 -0
  34. package/address/sort.js +7 -0
  35. package/address/sshash.d.ts +1 -0
  36. package/address/sshash.js +6 -0
  37. package/address/types.d.ts +1 -0
  38. package/address/types.js +1 -0
  39. package/address/util.d.ts +1 -0
  40. package/address/util.js +4 -0
  41. package/address/validate.d.ts +2 -0
  42. package/address/validate.js +4 -0
  43. package/base32/bs32.d.ts +26 -0
  44. package/base32/bs32.js +40 -0
  45. package/base32/helpers.d.ts +25 -0
  46. package/base32/helpers.js +61 -0
  47. package/base32/index.d.ts +4 -0
  48. package/base32/index.js +4 -0
  49. package/base58/bs58.d.ts +26 -0
  50. package/base58/bs58.js +34 -0
  51. package/base58/index.d.ts +4 -0
  52. package/base58/index.js +4 -0
  53. package/base64/bs64.d.ts +26 -0
  54. package/base64/bs64.js +34 -0
  55. package/base64/index.d.ts +6 -0
  56. package/base64/index.js +6 -0
  57. package/base64/pad.d.ts +5 -0
  58. package/base64/pad.js +7 -0
  59. package/base64/trim.d.ts +5 -0
  60. package/base64/trim.js +10 -0
  61. package/blake2/asU8a.d.ts +20 -0
  62. package/blake2/asU8a.js +32 -0
  63. package/blake2/index.d.ts +4 -0
  64. package/blake2/index.js +4 -0
  65. package/bn.d.ts +30 -0
  66. package/bn.js +8 -0
  67. package/bundle-pezkuwi-util-crypto.js +8251 -0
  68. package/bundle.d.ts +26 -0
  69. package/bundle.js +26 -0
  70. package/bundleInit.d.ts +1 -0
  71. package/bundleInit.js +5 -0
  72. package/cjs/address/addressToEvm.d.ts +5 -0
  73. package/cjs/address/addressToEvm.js +11 -0
  74. package/cjs/address/check.d.ts +8 -0
  75. package/cjs/address/check.js +29 -0
  76. package/cjs/address/checksum.d.ts +1 -0
  77. package/cjs/address/checksum.js +19 -0
  78. package/cjs/address/decode.d.ts +2 -0
  79. package/cjs/address/decode.js +32 -0
  80. package/cjs/address/defaults.d.ts +6 -0
  81. package/cjs/address/defaults.js +11 -0
  82. package/cjs/address/derive.d.ts +8 -0
  83. package/cjs/address/derive.js +27 -0
  84. package/cjs/address/encode.d.ts +2 -0
  85. package/cjs/address/encode.js +26 -0
  86. package/cjs/address/encodeDerived.d.ts +9 -0
  87. package/cjs/address/encodeDerived.js +15 -0
  88. package/cjs/address/encodeMulti.d.ts +9 -0
  89. package/cjs/address/encodeMulti.js +14 -0
  90. package/cjs/address/eq.d.ts +15 -0
  91. package/cjs/address/eq.js +22 -0
  92. package/cjs/address/evmToAddress.d.ts +7 -0
  93. package/cjs/address/evmToAddress.js +17 -0
  94. package/cjs/address/index.d.ts +16 -0
  95. package/cjs/address/index.js +35 -0
  96. package/cjs/address/is.d.ts +2 -0
  97. package/cjs/address/is.js +12 -0
  98. package/cjs/address/keyDerived.d.ts +2 -0
  99. package/cjs/address/keyDerived.js +11 -0
  100. package/cjs/address/keyMulti.d.ts +2 -0
  101. package/cjs/address/keyMulti.js +11 -0
  102. package/cjs/address/setSS58Format.d.ts +6 -0
  103. package/cjs/address/setSS58Format.js +14 -0
  104. package/cjs/address/sort.d.ts +2 -0
  105. package/cjs/address/sort.js +10 -0
  106. package/cjs/address/sshash.d.ts +1 -0
  107. package/cjs/address/sshash.js +9 -0
  108. package/cjs/address/types.d.ts +1 -0
  109. package/cjs/address/types.js +2 -0
  110. package/cjs/address/util.d.ts +1 -0
  111. package/cjs/address/util.js +7 -0
  112. package/cjs/address/validate.d.ts +2 -0
  113. package/cjs/address/validate.js +7 -0
  114. package/cjs/base32/bs32.d.ts +26 -0
  115. package/cjs/base32/bs32.js +43 -0
  116. package/cjs/base32/helpers.d.ts +25 -0
  117. package/cjs/base32/helpers.js +67 -0
  118. package/cjs/base32/index.d.ts +4 -0
  119. package/cjs/base32/index.js +11 -0
  120. package/cjs/base58/bs58.d.ts +26 -0
  121. package/cjs/base58/bs58.js +37 -0
  122. package/cjs/base58/index.d.ts +4 -0
  123. package/cjs/base58/index.js +11 -0
  124. package/cjs/base64/bs64.d.ts +26 -0
  125. package/cjs/base64/bs64.js +37 -0
  126. package/cjs/base64/index.d.ts +6 -0
  127. package/cjs/base64/index.js +15 -0
  128. package/cjs/base64/pad.d.ts +5 -0
  129. package/cjs/base64/pad.js +10 -0
  130. package/cjs/base64/trim.d.ts +5 -0
  131. package/cjs/base64/trim.js +13 -0
  132. package/cjs/blake2/asU8a.d.ts +20 -0
  133. package/cjs/blake2/asU8a.js +36 -0
  134. package/cjs/blake2/index.d.ts +4 -0
  135. package/cjs/blake2/index.js +9 -0
  136. package/cjs/bn.d.ts +30 -0
  137. package/cjs/bn.js +11 -0
  138. package/cjs/bundle.d.ts +26 -0
  139. package/cjs/bundle.js +31 -0
  140. package/cjs/bundleInit.d.ts +1 -0
  141. package/cjs/bundleInit.js +7 -0
  142. package/cjs/crypto.d.ts +3 -0
  143. package/cjs/crypto.js +16 -0
  144. package/cjs/ed25519/deriveHard.d.ts +1 -0
  145. package/cjs/ed25519/deriveHard.js +12 -0
  146. package/cjs/ed25519/index.d.ts +10 -0
  147. package/cjs/ed25519/index.js +20 -0
  148. package/cjs/ed25519/pair/fromRandom.d.ts +16 -0
  149. package/cjs/ed25519/pair/fromRandom.js +22 -0
  150. package/cjs/ed25519/pair/fromSecret.d.ts +16 -0
  151. package/cjs/ed25519/pair/fromSecret.js +26 -0
  152. package/cjs/ed25519/pair/fromSeed.d.ts +16 -0
  153. package/cjs/ed25519/pair/fromSeed.js +34 -0
  154. package/cjs/ed25519/pair/fromString.d.ts +16 -0
  155. package/cjs/ed25519/pair/fromString.js +23 -0
  156. package/cjs/ed25519/sign.d.ts +16 -0
  157. package/cjs/ed25519/sign.js +33 -0
  158. package/cjs/ed25519/verify.d.ts +15 -0
  159. package/cjs/ed25519/verify.js +39 -0
  160. package/cjs/ethereum/encode.d.ts +2 -0
  161. package/cjs/ethereum/encode.js +28 -0
  162. package/cjs/ethereum/index.d.ts +3 -0
  163. package/cjs/ethereum/index.js +9 -0
  164. package/cjs/ethereum/isAddress.d.ts +1 -0
  165. package/cjs/ethereum/isAddress.js +14 -0
  166. package/cjs/ethereum/isChecksum.d.ts +1 -0
  167. package/cjs/ethereum/isChecksum.js +20 -0
  168. package/cjs/hd/ethereum/index.d.ts +2 -0
  169. package/cjs/hd/ethereum/index.js +47 -0
  170. package/cjs/hd/index.d.ts +3 -0
  171. package/cjs/hd/index.js +9 -0
  172. package/cjs/hd/ledger/derivePrivate.d.ts +1 -0
  173. package/cjs/hd/ledger/derivePrivate.js +15 -0
  174. package/cjs/hd/ledger/index.d.ts +2 -0
  175. package/cjs/hd/ledger/index.js +33 -0
  176. package/cjs/hd/ledger/master.d.ts +1 -0
  177. package/cjs/hd/ledger/master.js +19 -0
  178. package/cjs/hd/validatePath.d.ts +2 -0
  179. package/cjs/hd/validatePath.js +20 -0
  180. package/cjs/helpers.d.ts +12 -0
  181. package/cjs/helpers.js +24 -0
  182. package/cjs/hmac/index.d.ts +1 -0
  183. package/cjs/hmac/index.js +7 -0
  184. package/cjs/hmac/shaAsU8a.d.ts +15 -0
  185. package/cjs/hmac/shaAsU8a.js +40 -0
  186. package/cjs/index.d.ts +2 -0
  187. package/cjs/index.js +5 -0
  188. package/cjs/json/constants.d.ts +6 -0
  189. package/cjs/json/constants.js +8 -0
  190. package/cjs/json/decrypt.d.ts +2 -0
  191. package/cjs/json/decrypt.js +16 -0
  192. package/cjs/json/decryptData.d.ts +2 -0
  193. package/cjs/json/decryptData.js +32 -0
  194. package/cjs/json/encrypt.d.ts +2 -0
  195. package/cjs/json/encrypt.js +18 -0
  196. package/cjs/json/encryptFormat.d.ts +2 -0
  197. package/cjs/json/encryptFormat.js +17 -0
  198. package/cjs/json/index.d.ts +4 -0
  199. package/cjs/json/index.js +11 -0
  200. package/cjs/json/types.d.ts +16 -0
  201. package/cjs/json/types.js +2 -0
  202. package/cjs/keccak/asU8a.d.ts +30 -0
  203. package/cjs/keccak/asU8a.js +36 -0
  204. package/cjs/keccak/index.d.ts +4 -0
  205. package/cjs/keccak/index.js +11 -0
  206. package/cjs/key/DeriveJunction.d.ts +12 -0
  207. package/cjs/key/DeriveJunction.js +62 -0
  208. package/cjs/key/extractPath.d.ts +9 -0
  209. package/cjs/key/extractPath.js +26 -0
  210. package/cjs/key/extractSuri.d.ts +11 -0
  211. package/cjs/key/extractSuri.js +25 -0
  212. package/cjs/key/fromPath.d.ts +3 -0
  213. package/cjs/key/fromPath.js +21 -0
  214. package/cjs/key/hdkdDerive.d.ts +3 -0
  215. package/cjs/key/hdkdDerive.js +11 -0
  216. package/cjs/key/hdkdEcdsa.d.ts +1 -0
  217. package/cjs/key/hdkdEcdsa.js +7 -0
  218. package/cjs/key/hdkdEd25519.d.ts +1 -0
  219. package/cjs/key/hdkdEd25519.js +6 -0
  220. package/cjs/key/hdkdSr25519.d.ts +3 -0
  221. package/cjs/key/hdkdSr25519.js +10 -0
  222. package/cjs/key/index.d.ts +9 -0
  223. package/cjs/key/index.js +18 -0
  224. package/cjs/mnemonic/bip39.d.ts +5 -0
  225. package/cjs/mnemonic/bip39.js +90 -0
  226. package/cjs/mnemonic/generate.d.ts +13 -0
  227. package/cjs/mnemonic/generate.js +23 -0
  228. package/cjs/mnemonic/index.d.ts +8 -0
  229. package/cjs/mnemonic/index.js +16 -0
  230. package/cjs/mnemonic/toEntropy.d.ts +1 -0
  231. package/cjs/mnemonic/toEntropy.js +11 -0
  232. package/cjs/mnemonic/toLegacySeed.d.ts +18 -0
  233. package/cjs/mnemonic/toLegacySeed.js +37 -0
  234. package/cjs/mnemonic/toMiniSecret.d.ts +1 -0
  235. package/cjs/mnemonic/toMiniSecret.js +20 -0
  236. package/cjs/mnemonic/validate.d.ts +14 -0
  237. package/cjs/mnemonic/validate.js +24 -0
  238. package/cjs/mnemonic/wordlists/en.d.ts +2 -0
  239. package/cjs/mnemonic/wordlists/en.js +3 -0
  240. package/cjs/mnemonic/wordlists/es.d.ts +2 -0
  241. package/cjs/mnemonic/wordlists/es.js +3 -0
  242. package/cjs/mnemonic/wordlists/fr.d.ts +2 -0
  243. package/cjs/mnemonic/wordlists/fr.js +3 -0
  244. package/cjs/mnemonic/wordlists/index.d.ts +8 -0
  245. package/cjs/mnemonic/wordlists/index.js +20 -0
  246. package/cjs/mnemonic/wordlists/it.d.ts +2 -0
  247. package/cjs/mnemonic/wordlists/it.js +3 -0
  248. package/cjs/mnemonic/wordlists/jp.d.ts +2 -0
  249. package/cjs/mnemonic/wordlists/jp.js +3 -0
  250. package/cjs/mnemonic/wordlists/ko.d.ts +2 -0
  251. package/cjs/mnemonic/wordlists/ko.js +3 -0
  252. package/cjs/mnemonic/wordlists/zh-s.d.ts +2 -0
  253. package/cjs/mnemonic/wordlists/zh-s.js +3 -0
  254. package/cjs/mnemonic/wordlists/zh-t.d.ts +2 -0
  255. package/cjs/mnemonic/wordlists/zh-t.js +3 -0
  256. package/cjs/nacl/decrypt.d.ts +15 -0
  257. package/cjs/nacl/decrypt.js +21 -0
  258. package/cjs/nacl/encrypt.d.ts +20 -0
  259. package/cjs/nacl/encrypt.js +25 -0
  260. package/cjs/nacl/index.d.ts +5 -0
  261. package/cjs/nacl/index.js +10 -0
  262. package/cjs/nacl/tweetnacl.d.ts +2 -0
  263. package/cjs/nacl/tweetnacl.js +238 -0
  264. package/cjs/networks.d.ts +1 -0
  265. package/cjs/networks.js +7 -0
  266. package/cjs/package.json +3 -0
  267. package/cjs/packageDetect.d.ts +1 -0
  268. package/cjs/packageDetect.js +8 -0
  269. package/cjs/packageInfo.d.ts +6 -0
  270. package/cjs/packageInfo.js +4 -0
  271. package/cjs/pbkdf2/encode.d.ts +7 -0
  272. package/cjs/pbkdf2/encode.js +19 -0
  273. package/cjs/pbkdf2/index.d.ts +1 -0
  274. package/cjs/pbkdf2/index.js +5 -0
  275. package/cjs/random/asNumber.d.ts +15 -0
  276. package/cjs/random/asNumber.js +23 -0
  277. package/cjs/random/asU8a.d.ts +20 -0
  278. package/cjs/random/asU8a.js +28 -0
  279. package/cjs/random/index.d.ts +5 -0
  280. package/cjs/random/index.js +11 -0
  281. package/cjs/scrypt/defaults.d.ts +3 -0
  282. package/cjs/scrypt/defaults.js +16 -0
  283. package/cjs/scrypt/encode.d.ts +8 -0
  284. package/cjs/scrypt/encode.js +18 -0
  285. package/cjs/scrypt/fromU8a.d.ts +7 -0
  286. package/cjs/scrypt/fromU8a.js +27 -0
  287. package/cjs/scrypt/index.d.ts +3 -0
  288. package/cjs/scrypt/index.js +9 -0
  289. package/cjs/scrypt/toU8a.d.ts +2 -0
  290. package/cjs/scrypt/toU8a.js +8 -0
  291. package/cjs/scrypt/types.d.ts +6 -0
  292. package/cjs/scrypt/types.js +2 -0
  293. package/cjs/secp256k1/compress.d.ts +1 -0
  294. package/cjs/secp256k1/compress.js +17 -0
  295. package/cjs/secp256k1/deriveHard.d.ts +1 -0
  296. package/cjs/secp256k1/deriveHard.js +13 -0
  297. package/cjs/secp256k1/expand.d.ts +1 -0
  298. package/cjs/secp256k1/expand.js +20 -0
  299. package/cjs/secp256k1/hasher.d.ts +2 -0
  300. package/cjs/secp256k1/hasher.js +10 -0
  301. package/cjs/secp256k1/index.d.ts +7 -0
  302. package/cjs/secp256k1/index.js +17 -0
  303. package/cjs/secp256k1/pair/fromSeed.d.ts +6 -0
  304. package/cjs/secp256k1/pair/fromSeed.js +34 -0
  305. package/cjs/secp256k1/recover.d.ts +6 -0
  306. package/cjs/secp256k1/recover.js +29 -0
  307. package/cjs/secp256k1/sign.d.ts +7 -0
  308. package/cjs/secp256k1/sign.js +23 -0
  309. package/cjs/secp256k1/tweakAdd.d.ts +1 -0
  310. package/cjs/secp256k1/tweakAdd.js +48 -0
  311. package/cjs/secp256k1/types.d.ts +1 -0
  312. package/cjs/secp256k1/types.js +2 -0
  313. package/cjs/secp256k1/verify.d.ts +6 -0
  314. package/cjs/secp256k1/verify.js +23 -0
  315. package/cjs/sha/asU8a.d.ts +15 -0
  316. package/cjs/sha/asU8a.js +22 -0
  317. package/cjs/sha/index.d.ts +4 -0
  318. package/cjs/sha/index.js +10 -0
  319. package/cjs/signature/index.d.ts +4 -0
  320. package/cjs/signature/index.js +8 -0
  321. package/cjs/signature/verify.d.ts +2 -0
  322. package/cjs/signature/verify.js +81 -0
  323. package/cjs/sr25519/agreement.d.ts +5 -0
  324. package/cjs/sr25519/agreement.js +20 -0
  325. package/cjs/sr25519/derive.d.ts +2 -0
  326. package/cjs/sr25519/derive.js +16 -0
  327. package/cjs/sr25519/deriveHard.d.ts +1 -0
  328. package/cjs/sr25519/deriveHard.js +7 -0
  329. package/cjs/sr25519/derivePublic.d.ts +1 -0
  330. package/cjs/sr25519/derivePublic.js +16 -0
  331. package/cjs/sr25519/deriveSoft.d.ts +1 -0
  332. package/cjs/sr25519/deriveSoft.js +7 -0
  333. package/cjs/sr25519/index.d.ts +9 -0
  334. package/cjs/sr25519/index.js +21 -0
  335. package/cjs/sr25519/pair/fromSeed.d.ts +6 -0
  336. package/cjs/sr25519/pair/fromSeed.js +22 -0
  337. package/cjs/sr25519/pair/fromU8a.d.ts +2 -0
  338. package/cjs/sr25519/pair/fromU8a.js +17 -0
  339. package/cjs/sr25519/pair/toU8a.d.ts +2 -0
  340. package/cjs/sr25519/pair/toU8a.js +7 -0
  341. package/cjs/sr25519/sign.d.ts +6 -0
  342. package/cjs/sr25519/sign.js +19 -0
  343. package/cjs/sr25519/verify.d.ts +5 -0
  344. package/cjs/sr25519/verify.js +21 -0
  345. package/cjs/sr25519/vrfSign.d.ts +6 -0
  346. package/cjs/sr25519/vrfSign.js +19 -0
  347. package/cjs/sr25519/vrfVerify.d.ts +5 -0
  348. package/cjs/sr25519/vrfVerify.js +22 -0
  349. package/cjs/types.d.ts +26 -0
  350. package/cjs/types.js +5 -0
  351. package/cjs/xxhash/asU8a.d.ts +20 -0
  352. package/cjs/xxhash/asU8a.js +39 -0
  353. package/cjs/xxhash/index.d.ts +4 -0
  354. package/cjs/xxhash/index.js +9 -0
  355. package/cjs/xxhash/xxhash64.d.ts +1 -0
  356. package/cjs/xxhash/xxhash64.js +103 -0
  357. package/crypto.d.ts +3 -0
  358. package/crypto.js +12 -0
  359. package/ed25519/deriveHard.d.ts +1 -0
  360. package/ed25519/deriveHard.js +9 -0
  361. package/ed25519/index.d.ts +10 -0
  362. package/ed25519/index.js +10 -0
  363. package/ed25519/pair/fromRandom.d.ts +16 -0
  364. package/ed25519/pair/fromRandom.js +19 -0
  365. package/ed25519/pair/fromSecret.d.ts +16 -0
  366. package/ed25519/pair/fromSecret.js +23 -0
  367. package/ed25519/pair/fromSeed.d.ts +16 -0
  368. package/ed25519/pair/fromSeed.js +31 -0
  369. package/ed25519/pair/fromString.d.ts +16 -0
  370. package/ed25519/pair/fromString.js +20 -0
  371. package/ed25519/sign.d.ts +16 -0
  372. package/ed25519/sign.js +30 -0
  373. package/ed25519/verify.d.ts +15 -0
  374. package/ed25519/verify.js +36 -0
  375. package/ethereum/encode.d.ts +2 -0
  376. package/ethereum/encode.js +25 -0
  377. package/ethereum/index.d.ts +3 -0
  378. package/ethereum/index.js +3 -0
  379. package/ethereum/isAddress.d.ts +1 -0
  380. package/ethereum/isAddress.js +11 -0
  381. package/ethereum/isChecksum.d.ts +1 -0
  382. package/ethereum/isChecksum.js +17 -0
  383. package/hd/ethereum/index.d.ts +2 -0
  384. package/hd/ethereum/index.js +44 -0
  385. package/hd/index.d.ts +3 -0
  386. package/hd/index.js +3 -0
  387. package/hd/ledger/derivePrivate.d.ts +1 -0
  388. package/hd/ledger/derivePrivate.js +12 -0
  389. package/hd/ledger/index.d.ts +2 -0
  390. package/hd/ledger/index.js +30 -0
  391. package/hd/ledger/master.d.ts +1 -0
  392. package/hd/ledger/master.js +16 -0
  393. package/hd/validatePath.d.ts +2 -0
  394. package/hd/validatePath.js +16 -0
  395. package/helpers.d.ts +12 -0
  396. package/helpers.js +19 -0
  397. package/hmac/index.d.ts +1 -0
  398. package/hmac/index.js +1 -0
  399. package/hmac/shaAsU8a.d.ts +15 -0
  400. package/hmac/shaAsU8a.js +36 -0
  401. package/index.d.ts +2 -0
  402. package/index.js +2 -0
  403. package/json/constants.d.ts +6 -0
  404. package/json/constants.js +5 -0
  405. package/json/decrypt.d.ts +2 -0
  406. package/json/decrypt.js +13 -0
  407. package/json/decryptData.d.ts +2 -0
  408. package/json/decryptData.js +29 -0
  409. package/json/encrypt.d.ts +2 -0
  410. package/json/encrypt.js +15 -0
  411. package/json/encryptFormat.d.ts +2 -0
  412. package/json/encryptFormat.js +14 -0
  413. package/json/index.d.ts +4 -0
  414. package/json/index.js +4 -0
  415. package/json/types.d.ts +16 -0
  416. package/json/types.js +1 -0
  417. package/keccak/asU8a.d.ts +30 -0
  418. package/keccak/asU8a.js +33 -0
  419. package/keccak/index.d.ts +4 -0
  420. package/keccak/index.js +4 -0
  421. package/key/DeriveJunction.d.ts +12 -0
  422. package/key/DeriveJunction.js +58 -0
  423. package/key/extractPath.d.ts +9 -0
  424. package/key/extractPath.js +23 -0
  425. package/key/extractSuri.d.ts +11 -0
  426. package/key/extractSuri.js +22 -0
  427. package/key/fromPath.d.ts +3 -0
  428. package/key/fromPath.js +18 -0
  429. package/key/hdkdDerive.d.ts +3 -0
  430. package/key/hdkdDerive.js +8 -0
  431. package/key/hdkdEcdsa.d.ts +1 -0
  432. package/key/hdkdEcdsa.js +4 -0
  433. package/key/hdkdEd25519.d.ts +1 -0
  434. package/key/hdkdEd25519.js +3 -0
  435. package/key/hdkdSr25519.d.ts +3 -0
  436. package/key/hdkdSr25519.js +7 -0
  437. package/key/index.d.ts +9 -0
  438. package/key/index.js +9 -0
  439. package/mnemonic/bip39.d.ts +5 -0
  440. package/mnemonic/bip39.js +82 -0
  441. package/mnemonic/generate.d.ts +13 -0
  442. package/mnemonic/generate.js +20 -0
  443. package/mnemonic/index.d.ts +8 -0
  444. package/mnemonic/index.js +8 -0
  445. package/mnemonic/toEntropy.d.ts +1 -0
  446. package/mnemonic/toEntropy.js +8 -0
  447. package/mnemonic/toLegacySeed.d.ts +18 -0
  448. package/mnemonic/toLegacySeed.js +34 -0
  449. package/mnemonic/toMiniSecret.d.ts +1 -0
  450. package/mnemonic/toMiniSecret.js +17 -0
  451. package/mnemonic/validate.d.ts +14 -0
  452. package/mnemonic/validate.js +21 -0
  453. package/mnemonic/wordlists/en.d.ts +2 -0
  454. package/mnemonic/wordlists/en.js +1 -0
  455. package/mnemonic/wordlists/es.d.ts +2 -0
  456. package/mnemonic/wordlists/es.js +1 -0
  457. package/mnemonic/wordlists/fr.d.ts +2 -0
  458. package/mnemonic/wordlists/fr.js +1 -0
  459. package/mnemonic/wordlists/index.d.ts +8 -0
  460. package/mnemonic/wordlists/index.js +8 -0
  461. package/mnemonic/wordlists/it.d.ts +2 -0
  462. package/mnemonic/wordlists/it.js +1 -0
  463. package/mnemonic/wordlists/jp.d.ts +2 -0
  464. package/mnemonic/wordlists/jp.js +1 -0
  465. package/mnemonic/wordlists/ko.d.ts +2 -0
  466. package/mnemonic/wordlists/ko.js +1 -0
  467. package/mnemonic/wordlists/zh-s.d.ts +2 -0
  468. package/mnemonic/wordlists/zh-s.js +1 -0
  469. package/mnemonic/wordlists/zh-t.d.ts +2 -0
  470. package/mnemonic/wordlists/zh-t.js +1 -0
  471. package/nacl/decrypt.d.ts +15 -0
  472. package/nacl/decrypt.js +18 -0
  473. package/nacl/encrypt.d.ts +20 -0
  474. package/nacl/encrypt.js +22 -0
  475. package/nacl/index.d.ts +5 -0
  476. package/nacl/index.js +5 -0
  477. package/nacl/tweetnacl.d.ts +2 -0
  478. package/nacl/tweetnacl.js +234 -0
  479. package/networks.d.ts +1 -0
  480. package/networks.js +1 -0
  481. package/package.json +2022 -10
  482. package/packageDetect.d.ts +1 -0
  483. package/packageDetect.js +6 -0
  484. package/packageInfo.d.ts +6 -0
  485. package/packageInfo.js +1 -0
  486. package/pbkdf2/encode.d.ts +7 -0
  487. package/pbkdf2/encode.js +16 -0
  488. package/pbkdf2/index.d.ts +1 -0
  489. package/pbkdf2/index.js +1 -0
  490. package/random/asNumber.d.ts +15 -0
  491. package/random/asNumber.js +20 -0
  492. package/random/asU8a.d.ts +20 -0
  493. package/random/asU8a.js +24 -0
  494. package/random/index.d.ts +5 -0
  495. package/random/index.js +5 -0
  496. package/scrypt/defaults.d.ts +3 -0
  497. package/scrypt/defaults.js +13 -0
  498. package/scrypt/encode.d.ts +8 -0
  499. package/scrypt/encode.js +15 -0
  500. package/scrypt/fromU8a.d.ts +7 -0
  501. package/scrypt/fromU8a.js +24 -0
  502. package/scrypt/index.d.ts +3 -0
  503. package/scrypt/index.js +3 -0
  504. package/scrypt/toU8a.d.ts +2 -0
  505. package/scrypt/toU8a.js +5 -0
  506. package/scrypt/types.d.ts +6 -0
  507. package/scrypt/types.js +1 -0
  508. package/secp256k1/compress.d.ts +1 -0
  509. package/secp256k1/compress.js +14 -0
  510. package/secp256k1/deriveHard.d.ts +1 -0
  511. package/secp256k1/deriveHard.js +10 -0
  512. package/secp256k1/expand.d.ts +1 -0
  513. package/secp256k1/expand.js +17 -0
  514. package/secp256k1/hasher.d.ts +2 -0
  515. package/secp256k1/hasher.js +7 -0
  516. package/secp256k1/index.d.ts +7 -0
  517. package/secp256k1/index.js +7 -0
  518. package/secp256k1/pair/fromSeed.d.ts +6 -0
  519. package/secp256k1/pair/fromSeed.js +31 -0
  520. package/secp256k1/recover.d.ts +6 -0
  521. package/secp256k1/recover.js +26 -0
  522. package/secp256k1/sign.d.ts +7 -0
  523. package/secp256k1/sign.js +20 -0
  524. package/secp256k1/tweakAdd.d.ts +1 -0
  525. package/secp256k1/tweakAdd.js +45 -0
  526. package/secp256k1/types.d.ts +1 -0
  527. package/secp256k1/types.js +1 -0
  528. package/secp256k1/verify.d.ts +6 -0
  529. package/secp256k1/verify.js +20 -0
  530. package/sha/asU8a.d.ts +15 -0
  531. package/sha/asU8a.js +19 -0
  532. package/sha/index.d.ts +4 -0
  533. package/sha/index.js +4 -0
  534. package/signature/index.d.ts +4 -0
  535. package/signature/index.js +4 -0
  536. package/signature/verify.d.ts +2 -0
  537. package/signature/verify.js +78 -0
  538. package/sr25519/agreement.d.ts +5 -0
  539. package/sr25519/agreement.js +17 -0
  540. package/sr25519/derive.d.ts +2 -0
  541. package/sr25519/derive.js +12 -0
  542. package/sr25519/deriveHard.d.ts +1 -0
  543. package/sr25519/deriveHard.js +3 -0
  544. package/sr25519/derivePublic.d.ts +1 -0
  545. package/sr25519/derivePublic.js +12 -0
  546. package/sr25519/deriveSoft.d.ts +1 -0
  547. package/sr25519/deriveSoft.js +3 -0
  548. package/sr25519/index.d.ts +9 -0
  549. package/sr25519/index.js +9 -0
  550. package/sr25519/pair/fromSeed.d.ts +6 -0
  551. package/sr25519/pair/fromSeed.js +18 -0
  552. package/sr25519/pair/fromU8a.d.ts +2 -0
  553. package/sr25519/pair/fromU8a.js +14 -0
  554. package/sr25519/pair/toU8a.d.ts +2 -0
  555. package/sr25519/pair/toU8a.js +4 -0
  556. package/sr25519/sign.d.ts +6 -0
  557. package/sr25519/sign.js +15 -0
  558. package/sr25519/verify.d.ts +5 -0
  559. package/sr25519/verify.js +17 -0
  560. package/sr25519/vrfSign.d.ts +6 -0
  561. package/sr25519/vrfSign.js +15 -0
  562. package/sr25519/vrfVerify.d.ts +5 -0
  563. package/sr25519/vrfVerify.js +18 -0
  564. package/types.d.ts +26 -0
  565. package/types.js +2 -0
  566. package/xxhash/asU8a.d.ts +20 -0
  567. package/xxhash/asU8a.js +35 -0
  568. package/xxhash/index.d.ts +4 -0
  569. package/xxhash/index.js +4 -0
  570. package/xxhash/xxhash64.d.ts +1 -0
  571. package/xxhash/xxhash64.js +100 -0
@@ -0,0 +1,16 @@
1
+ import type { Keypair } from '../types.js';
2
+ /**
3
+ * @name ed25519Sign
4
+ * @summary Signs a message using the supplied secretKey
5
+ * @description
6
+ * Returns message signature of `message`, using the `secretKey`.
7
+ * @example
8
+ * <BR>
9
+ *
10
+ * ```javascript
11
+ * import { ed25519Sign } from '@pezkuwi/util-crypto';
12
+ *
13
+ * ed25519Sign([...], [...]); // => [...]
14
+ * ```
15
+ */
16
+ export declare function ed25519Sign(message: string | Uint8Array, { publicKey, secretKey }: Partial<Keypair>, onlyJs?: boolean): Uint8Array;
@@ -0,0 +1,30 @@
1
+ import { ed25519 } from '@noble/curves/ed25519';
2
+ import { hasBigInt, u8aToU8a } from '@pezkuwi/util';
3
+ import { ed25519Sign as wasmSign, isReady } from '@pezkuwi/wasm-crypto';
4
+ /**
5
+ * @name ed25519Sign
6
+ * @summary Signs a message using the supplied secretKey
7
+ * @description
8
+ * Returns message signature of `message`, using the `secretKey`.
9
+ * @example
10
+ * <BR>
11
+ *
12
+ * ```javascript
13
+ * import { ed25519Sign } from '@pezkuwi/util-crypto';
14
+ *
15
+ * ed25519Sign([...], [...]); // => [...]
16
+ * ```
17
+ */
18
+ export function ed25519Sign(message, { publicKey, secretKey }, onlyJs) {
19
+ if (!secretKey) {
20
+ throw new Error('Expected a valid secretKey');
21
+ }
22
+ else if (!publicKey) {
23
+ throw new Error('Expected a valid publicKey');
24
+ }
25
+ const messageU8a = u8aToU8a(message);
26
+ const privateU8a = secretKey.subarray(0, 32);
27
+ return !hasBigInt || (!onlyJs && isReady())
28
+ ? wasmSign(publicKey, privateU8a, messageU8a)
29
+ : ed25519.sign(messageU8a, privateU8a);
30
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @name ed25519Sign
3
+ * @summary Verifies the signature on the supplied message.
4
+ * @description
5
+ * Verifies the `signature` on `message` with the supplied `publicKey`. Returns `true` on sucess, `false` otherwise.
6
+ * @example
7
+ * <BR>
8
+ *
9
+ * ```javascript
10
+ * import { ed25519Verify } from '@pezkuwi/util-crypto';
11
+ *
12
+ * ed25519Verify([...], [...], [...]); // => true/false
13
+ * ```
14
+ */
15
+ export declare function ed25519Verify(message: string | Uint8Array, signature: string | Uint8Array, publicKey: string | Uint8Array, onlyJs?: boolean): boolean;
@@ -0,0 +1,36 @@
1
+ import { ed25519 } from '@noble/curves/ed25519';
2
+ import { hasBigInt, u8aToU8a } from '@pezkuwi/util';
3
+ import { ed25519Verify as wasmVerify, isReady } from '@pezkuwi/wasm-crypto';
4
+ /**
5
+ * @name ed25519Sign
6
+ * @summary Verifies the signature on the supplied message.
7
+ * @description
8
+ * Verifies the `signature` on `message` with the supplied `publicKey`. Returns `true` on sucess, `false` otherwise.
9
+ * @example
10
+ * <BR>
11
+ *
12
+ * ```javascript
13
+ * import { ed25519Verify } from '@pezkuwi/util-crypto';
14
+ *
15
+ * ed25519Verify([...], [...], [...]); // => true/false
16
+ * ```
17
+ */
18
+ export function ed25519Verify(message, signature, publicKey, onlyJs) {
19
+ const messageU8a = u8aToU8a(message);
20
+ const publicKeyU8a = u8aToU8a(publicKey);
21
+ const signatureU8a = u8aToU8a(signature);
22
+ if (publicKeyU8a.length !== 32) {
23
+ throw new Error(`Invalid publicKey, received ${publicKeyU8a.length}, expected 32`);
24
+ }
25
+ else if (signatureU8a.length !== 64) {
26
+ throw new Error(`Invalid signature, received ${signatureU8a.length} bytes, expected 64`);
27
+ }
28
+ try {
29
+ return !hasBigInt || (!onlyJs && isReady())
30
+ ? wasmVerify(signatureU8a, messageU8a, publicKeyU8a)
31
+ : ed25519.verify(signatureU8a, messageU8a, publicKeyU8a);
32
+ }
33
+ catch {
34
+ return false;
35
+ }
36
+ }
@@ -0,0 +1,2 @@
1
+ import type { HexString } from '@pezkuwi/util/types';
2
+ export declare function ethereumEncode(addressOrPublic?: string | Uint8Array): HexString;
@@ -0,0 +1,25 @@
1
+ import { u8aToHex, u8aToU8a } from '@pezkuwi/util';
2
+ import { keccakAsU8a } from '../keccak/index.js';
3
+ import { secp256k1Expand } from '../secp256k1/index.js';
4
+ function getH160(u8a) {
5
+ if ([33, 65].includes(u8a.length)) {
6
+ u8a = keccakAsU8a(secp256k1Expand(u8a));
7
+ }
8
+ return u8a.slice(-20);
9
+ }
10
+ export function ethereumEncode(addressOrPublic) {
11
+ if (!addressOrPublic) {
12
+ return '0x';
13
+ }
14
+ const u8aAddress = u8aToU8a(addressOrPublic);
15
+ if (![20, 32, 33, 65].includes(u8aAddress.length)) {
16
+ throw new Error(`Invalid address or publicKey provided, received ${u8aAddress.length} bytes input`);
17
+ }
18
+ const address = u8aToHex(getH160(u8aAddress), -1, false);
19
+ const hash = u8aToHex(keccakAsU8a(address), -1, false);
20
+ let result = '';
21
+ for (let i = 0; i < 40; i++) {
22
+ result = `${result}${parseInt(hash[i], 16) > 7 ? address[i].toUpperCase() : address[i]}`;
23
+ }
24
+ return `0x${result}`;
25
+ }
@@ -0,0 +1,3 @@
1
+ export { ethereumEncode } from './encode.js';
2
+ export { isEthereumAddress } from './isAddress.js';
3
+ export { isEthereumChecksum } from './isChecksum.js';
@@ -0,0 +1,3 @@
1
+ export { ethereumEncode } from './encode.js';
2
+ export { isEthereumAddress } from './isAddress.js';
3
+ export { isEthereumChecksum } from './isChecksum.js';
@@ -0,0 +1 @@
1
+ export declare function isEthereumAddress(address?: string): boolean;
@@ -0,0 +1,11 @@
1
+ import { isHex } from '@pezkuwi/util';
2
+ import { isEthereumChecksum } from './isChecksum.js';
3
+ export function isEthereumAddress(address) {
4
+ if (!address || address.length !== 42 || !isHex(address)) {
5
+ return false;
6
+ }
7
+ else if (/^(0x)?[0-9a-f]{40}$/.test(address) || /^(0x)?[0-9A-F]{40}$/.test(address)) {
8
+ return true;
9
+ }
10
+ return isEthereumChecksum(address);
11
+ }
@@ -0,0 +1 @@
1
+ export declare function isEthereumChecksum(_address: string): boolean;
@@ -0,0 +1,17 @@
1
+ import { u8aToHex } from '@pezkuwi/util';
2
+ import { keccakAsU8a } from '../keccak/index.js';
3
+ function isInvalidChar(char, byte) {
4
+ return char !== (byte > 7
5
+ ? char.toUpperCase()
6
+ : char.toLowerCase());
7
+ }
8
+ export function isEthereumChecksum(_address) {
9
+ const address = _address.replace('0x', '');
10
+ const hash = u8aToHex(keccakAsU8a(address.toLowerCase()), -1, false);
11
+ for (let i = 0; i < 40; i++) {
12
+ if (isInvalidChar(address[i], parseInt(hash[i], 16))) {
13
+ return false;
14
+ }
15
+ }
16
+ return true;
17
+ }
@@ -0,0 +1,2 @@
1
+ import type { Keypair } from '../../types.js';
2
+ export declare function hdEthereum(seed: Uint8Array, path?: string): Keypair;
@@ -0,0 +1,44 @@
1
+ import { bnToU8a, stringToU8a, u8aConcat } from '@pezkuwi/util';
2
+ import { BN_BE_32_OPTS } from '../../bn.js';
3
+ import { hmacShaAsU8a } from '../../hmac/index.js';
4
+ import { secp256k1PairFromSeed, secp256k1PrivateKeyTweakAdd } from '../../secp256k1/index.js';
5
+ import { HARDENED, hdValidatePath } from '../validatePath.js';
6
+ const MASTER_SECRET = stringToU8a('Bitcoin seed');
7
+ function createCoded(secretKey, chainCode) {
8
+ return {
9
+ chainCode,
10
+ publicKey: secp256k1PairFromSeed(secretKey).publicKey,
11
+ secretKey
12
+ };
13
+ }
14
+ function deriveChild(hd, index) {
15
+ const indexBuffer = bnToU8a(index, BN_BE_32_OPTS);
16
+ const data = index >= HARDENED
17
+ ? u8aConcat(new Uint8Array(1), hd.secretKey, indexBuffer)
18
+ : u8aConcat(hd.publicKey, indexBuffer);
19
+ try {
20
+ const I = hmacShaAsU8a(hd.chainCode, data, 512);
21
+ return createCoded(secp256k1PrivateKeyTweakAdd(hd.secretKey, I.slice(0, 32)), I.slice(32));
22
+ }
23
+ catch {
24
+ // In case parse256(IL) >= n or ki == 0, proceed with the next value for i
25
+ return deriveChild(hd, index + 1);
26
+ }
27
+ }
28
+ export function hdEthereum(seed, path = '') {
29
+ const I = hmacShaAsU8a(MASTER_SECRET, seed, 512);
30
+ let hd = createCoded(I.slice(0, 32), I.slice(32));
31
+ if (!path || path === 'm' || path === 'M' || path === "m'" || path === "M'") {
32
+ return hd;
33
+ }
34
+ if (!hdValidatePath(path)) {
35
+ throw new Error('Invalid derivation path');
36
+ }
37
+ const parts = path.split('/').slice(1);
38
+ for (const p of parts) {
39
+ hd = deriveChild(hd, parseInt(p, 10) + ((p.length > 1) && p.endsWith("'")
40
+ ? HARDENED
41
+ : 0));
42
+ }
43
+ return hd;
44
+ }
package/hd/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export { hdEthereum } from './ethereum/index.js';
2
+ export { hdLedger } from './ledger/index.js';
3
+ export { hdValidatePath } from './validatePath.js';
package/hd/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { hdEthereum } from './ethereum/index.js';
2
+ export { hdLedger } from './ledger/index.js';
3
+ export { hdValidatePath } from './validatePath.js';
@@ -0,0 +1 @@
1
+ export declare function ledgerDerivePrivate(xprv: Uint8Array, index: number): Uint8Array;
@@ -0,0 +1,12 @@
1
+ import { BN_EIGHT, bnToU8a, u8aConcat, u8aToBn } from '@pezkuwi/util';
2
+ import { BN_LE_32_OPTS, BN_LE_512_OPTS, BN_LE_OPTS } from '../../bn.js';
3
+ import { hmacShaAsU8a } from '../../hmac/index.js';
4
+ export function ledgerDerivePrivate(xprv, index) {
5
+ const kl = xprv.subarray(0, 32);
6
+ const kr = xprv.subarray(32, 64);
7
+ const cc = xprv.subarray(64, 96);
8
+ const data = u8aConcat([0], kl, kr, bnToU8a(index, BN_LE_32_OPTS));
9
+ const z = hmacShaAsU8a(cc, data, 512);
10
+ data[0] = 0x01;
11
+ return u8aConcat(bnToU8a(u8aToBn(kl, BN_LE_OPTS).iadd(u8aToBn(z.subarray(0, 28), BN_LE_OPTS).imul(BN_EIGHT)), BN_LE_512_OPTS).subarray(0, 32), bnToU8a(u8aToBn(kr, BN_LE_OPTS).iadd(u8aToBn(z.subarray(32, 64), BN_LE_OPTS)), BN_LE_512_OPTS).subarray(0, 32), hmacShaAsU8a(cc, data, 512).subarray(32, 64));
12
+ }
@@ -0,0 +1,2 @@
1
+ import type { Keypair } from '../../types.js';
2
+ export declare function hdLedger(_mnemonic: string, path: string): Keypair;
@@ -0,0 +1,30 @@
1
+ import { ed25519PairFromSeed } from '../../ed25519/index.js';
2
+ import { mnemonicValidate } from '../../mnemonic/index.js';
3
+ import { HARDENED, hdValidatePath } from '../validatePath.js';
4
+ import { ledgerDerivePrivate } from './derivePrivate.js';
5
+ import { ledgerMaster } from './master.js';
6
+ export function hdLedger(_mnemonic, path) {
7
+ const words = _mnemonic
8
+ .split(' ')
9
+ .map((s) => s.trim())
10
+ .filter((s) => s);
11
+ if (![12, 24, 25].includes(words.length)) {
12
+ throw new Error('Expected a mnemonic with 24 words (or 25 including a password)');
13
+ }
14
+ const [mnemonic, password] = words.length === 25
15
+ ? [words.slice(0, 24).join(' '), words[24]]
16
+ : [words.join(' '), ''];
17
+ if (!mnemonicValidate(mnemonic)) {
18
+ throw new Error('Invalid mnemonic passed to ledger derivation');
19
+ }
20
+ else if (!hdValidatePath(path)) {
21
+ throw new Error('Invalid derivation path');
22
+ }
23
+ const parts = path.split('/').slice(1);
24
+ let seed = ledgerMaster(mnemonic, password);
25
+ for (const p of parts) {
26
+ const n = parseInt(p.replace(/'$/, ''), 10);
27
+ seed = ledgerDerivePrivate(seed, (n < HARDENED) ? (n + HARDENED) : n);
28
+ }
29
+ return ed25519PairFromSeed(seed.slice(0, 32));
30
+ }
@@ -0,0 +1 @@
1
+ export declare function ledgerMaster(mnemonic: string, password?: string): Uint8Array;
@@ -0,0 +1,16 @@
1
+ import { u8aConcat } from '@pezkuwi/util';
2
+ import { hmacShaAsU8a } from '../../hmac/index.js';
3
+ import { mnemonicToSeedSync } from '../../mnemonic/bip39.js';
4
+ const ED25519_CRYPTO = 'ed25519 seed';
5
+ export function ledgerMaster(mnemonic, password) {
6
+ const seed = mnemonicToSeedSync(mnemonic, password);
7
+ const chainCode = hmacShaAsU8a(ED25519_CRYPTO, new Uint8Array([1, ...seed]), 256);
8
+ let priv;
9
+ while (!priv || (priv[31] & 0b0010_0000)) {
10
+ priv = hmacShaAsU8a(ED25519_CRYPTO, priv || seed, 512);
11
+ }
12
+ priv[0] &= 0b1111_1000;
13
+ priv[31] &= 0b0111_1111;
14
+ priv[31] |= 0b0100_0000;
15
+ return u8aConcat(priv, chainCode);
16
+ }
@@ -0,0 +1,2 @@
1
+ export declare const HARDENED = 2147483648;
2
+ export declare function hdValidatePath(path: string): boolean;
@@ -0,0 +1,16 @@
1
+ export const HARDENED = 0x80000000;
2
+ export function hdValidatePath(path) {
3
+ if (!path.startsWith('m/')) {
4
+ return false;
5
+ }
6
+ const parts = path.split('/').slice(1);
7
+ for (const p of parts) {
8
+ const n = /^\d+'?$/.test(p)
9
+ ? parseInt(p.replace(/'$/, ''), 10)
10
+ : Number.NaN;
11
+ if (isNaN(n) || (n >= HARDENED) || (n < 0)) {
12
+ return false;
13
+ }
14
+ }
15
+ return true;
16
+ }
package/helpers.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import type { HexString } from '@pezkuwi/util/types';
2
+ export type { HexString } from '@pezkuwi/util/types';
3
+ interface DualHash {
4
+ 256: (u8a: Uint8Array) => Uint8Array;
5
+ 512: (u8a: Uint8Array) => Uint8Array;
6
+ }
7
+ /** @internal */
8
+ export declare function createAsHex<T extends (...args: never[]) => Uint8Array>(fn: T): (...args: Parameters<T>) => HexString;
9
+ /** @internal */
10
+ export declare function createBitHasher(bitLength: 256 | 512, fn: (data: string | Uint8Array, bitLength: 256 | 512, onlyJs?: boolean) => Uint8Array): (data: string | Uint8Array, onlyJs?: boolean) => Uint8Array;
11
+ /** @internal */
12
+ export declare function createDualHasher(wa: DualHash, js: DualHash): (value: string | Uint8Array, bitLength?: 256 | 512, onlyJs?: boolean) => Uint8Array;
package/helpers.js ADDED
@@ -0,0 +1,19 @@
1
+ import { hasBigInt, u8aToHex, u8aToU8a } from '@pezkuwi/util';
2
+ import { isReady } from '@pezkuwi/wasm-crypto';
3
+ /** @internal */
4
+ export function createAsHex(fn) {
5
+ return (...args) => u8aToHex(fn(...args));
6
+ }
7
+ /** @internal */
8
+ export function createBitHasher(bitLength, fn) {
9
+ return (data, onlyJs) => fn(data, bitLength, onlyJs);
10
+ }
11
+ /** @internal */
12
+ export function createDualHasher(wa, js) {
13
+ return (value, bitLength = 256, onlyJs) => {
14
+ const u8a = u8aToU8a(value);
15
+ return !hasBigInt || (!onlyJs && isReady())
16
+ ? wa[bitLength](u8a)
17
+ : js[bitLength](u8a);
18
+ };
19
+ }
@@ -0,0 +1 @@
1
+ export { hmacSha256AsU8a, hmacSha512AsU8a, hmacShaAsU8a } from './shaAsU8a.js';
package/hmac/index.js ADDED
@@ -0,0 +1 @@
1
+ export { hmacSha256AsU8a, hmacSha512AsU8a, hmacShaAsU8a } from './shaAsU8a.js';
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @name hmacShaAsU8a
3
+ * @description creates a Hmac Sha (256/512) Uint8Array from the key & data
4
+ */
5
+ export declare function hmacShaAsU8a(key: Uint8Array | string, data: Uint8Array, bitLength?: 256 | 512, onlyJs?: boolean): Uint8Array;
6
+ /**
7
+ * @name hmacSha256AsU8a
8
+ * @description creates a Hmac Sha256 Uint8Array from the key & data
9
+ */
10
+ export declare const hmacSha256AsU8a: (key: Uint8Array | string, data: Uint8Array, onlyJs?: boolean) => Uint8Array;
11
+ /**
12
+ * @name hmacSha512AsU8a
13
+ * @description creates a Hmac Sha512 Uint8Array from the key & data
14
+ */
15
+ export declare const hmacSha512AsU8a: (key: Uint8Array | string, data: Uint8Array, onlyJs?: boolean) => Uint8Array;
@@ -0,0 +1,36 @@
1
+ import { hmac } from '@noble/hashes/hmac';
2
+ import { sha256 } from '@noble/hashes/sha256';
3
+ import { sha512 } from '@noble/hashes/sha512';
4
+ import { hasBigInt, u8aToU8a } from '@pezkuwi/util';
5
+ import { hmacSha256, hmacSha512, isReady } from '@pezkuwi/wasm-crypto';
6
+ const JS_HASH = {
7
+ 256: sha256,
8
+ 512: sha512
9
+ };
10
+ const WA_MHAC = {
11
+ 256: hmacSha256,
12
+ 512: hmacSha512
13
+ };
14
+ function createSha(bitLength) {
15
+ return (key, data, onlyJs) => hmacShaAsU8a(key, data, bitLength, onlyJs);
16
+ }
17
+ /**
18
+ * @name hmacShaAsU8a
19
+ * @description creates a Hmac Sha (256/512) Uint8Array from the key & data
20
+ */
21
+ export function hmacShaAsU8a(key, data, bitLength = 256, onlyJs) {
22
+ const u8aKey = u8aToU8a(key);
23
+ return !hasBigInt || (!onlyJs && isReady())
24
+ ? WA_MHAC[bitLength](u8aKey, data)
25
+ : hmac(JS_HASH[bitLength], u8aKey, data);
26
+ }
27
+ /**
28
+ * @name hmacSha256AsU8a
29
+ * @description creates a Hmac Sha256 Uint8Array from the key & data
30
+ */
31
+ export const hmacSha256AsU8a = /*#__PURE__*/ createSha(256);
32
+ /**
33
+ * @name hmacSha512AsU8a
34
+ * @description creates a Hmac Sha512 Uint8Array from the key & data
35
+ */
36
+ export const hmacSha512AsU8a = /*#__PURE__*/ createSha(512);
package/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import './packageDetect.js';
2
+ export * from './bundle.js';
package/index.js ADDED
@@ -0,0 +1,2 @@
1
+ import './packageDetect.js';
2
+ export * from './bundle.js';
@@ -0,0 +1,6 @@
1
+ import type { EncryptedJsonEncoding, EncryptedJsonVersion } from './types.js';
2
+ export declare const ENCODING: EncryptedJsonEncoding[];
3
+ export declare const ENCODING_NONE: EncryptedJsonEncoding[];
4
+ export declare const ENCODING_VERSION: EncryptedJsonVersion;
5
+ export declare const NONCE_LENGTH = 24;
6
+ export declare const SCRYPT_LENGTH: number;
@@ -0,0 +1,5 @@
1
+ export const ENCODING = ['scrypt', 'xsalsa20-poly1305'];
2
+ export const ENCODING_NONE = ['none'];
3
+ export const ENCODING_VERSION = '3';
4
+ export const NONCE_LENGTH = 24;
5
+ export const SCRYPT_LENGTH = 32 + (3 * 4);
@@ -0,0 +1,2 @@
1
+ import type { EncryptedJson } from './types.js';
2
+ export declare function jsonDecrypt({ encoded, encoding }: EncryptedJson, passphrase?: string | null): Uint8Array;
@@ -0,0 +1,13 @@
1
+ import { hexToU8a, isHex } from '@pezkuwi/util';
2
+ import { base64Decode } from '../base64/index.js';
3
+ import { jsonDecryptData } from './decryptData.js';
4
+ export function jsonDecrypt({ encoded, encoding }, passphrase) {
5
+ if (!encoded) {
6
+ throw new Error('No encrypted data available to decode');
7
+ }
8
+ return jsonDecryptData(isHex(encoded)
9
+ ? hexToU8a(encoded)
10
+ : base64Decode(encoded), passphrase, Array.isArray(encoding.type)
11
+ ? encoding.type
12
+ : [encoding.type]);
13
+ }
@@ -0,0 +1,2 @@
1
+ import type { EncryptedJsonEncoding } from './types.js';
2
+ export declare function jsonDecryptData(encrypted?: Uint8Array | null, passphrase?: string | null, encType?: EncryptedJsonEncoding[]): Uint8Array;
@@ -0,0 +1,29 @@
1
+ import { stringToU8a, u8aFixLength } from '@pezkuwi/util';
2
+ import { naclDecrypt } from '../nacl/index.js';
3
+ import { scryptEncode, scryptFromU8a } from '../scrypt/index.js';
4
+ import { ENCODING, NONCE_LENGTH, SCRYPT_LENGTH } from './constants.js';
5
+ export function jsonDecryptData(encrypted, passphrase, encType = ENCODING) {
6
+ if (!encrypted) {
7
+ throw new Error('No encrypted data available to decode');
8
+ }
9
+ else if (encType.includes('xsalsa20-poly1305') && !passphrase) {
10
+ throw new Error('Password required to decode encrypted data');
11
+ }
12
+ let encoded = encrypted;
13
+ if (passphrase) {
14
+ let password;
15
+ if (encType.includes('scrypt')) {
16
+ const { params, salt } = scryptFromU8a(encrypted);
17
+ password = scryptEncode(passphrase, salt, params).password;
18
+ encrypted = encrypted.subarray(SCRYPT_LENGTH);
19
+ }
20
+ else {
21
+ password = stringToU8a(passphrase);
22
+ }
23
+ encoded = naclDecrypt(encrypted.subarray(NONCE_LENGTH), encrypted.subarray(0, NONCE_LENGTH), u8aFixLength(password, 256, true));
24
+ }
25
+ if (!encoded) {
26
+ throw new Error('Unable to decode using the supplied passphrase');
27
+ }
28
+ return encoded;
29
+ }
@@ -0,0 +1,2 @@
1
+ import type { EncryptedJson } from './types.js';
2
+ export declare function jsonEncrypt(data: Uint8Array, contentType: string[], passphrase?: string | null): EncryptedJson;
@@ -0,0 +1,15 @@
1
+ import { u8aConcat } from '@pezkuwi/util';
2
+ import { naclEncrypt } from '../nacl/index.js';
3
+ import { scryptEncode, scryptToU8a } from '../scrypt/index.js';
4
+ import { jsonEncryptFormat } from './encryptFormat.js';
5
+ export function jsonEncrypt(data, contentType, passphrase) {
6
+ let isEncrypted = false;
7
+ let encoded = data;
8
+ if (passphrase) {
9
+ const { params, password, salt } = scryptEncode(passphrase);
10
+ const { encrypted, nonce } = naclEncrypt(encoded, password.subarray(0, 32));
11
+ isEncrypted = true;
12
+ encoded = u8aConcat(scryptToU8a(salt, params), nonce, encrypted);
13
+ }
14
+ return jsonEncryptFormat(encoded, contentType, isEncrypted);
15
+ }
@@ -0,0 +1,2 @@
1
+ import type { EncryptedJson } from './types.js';
2
+ export declare function jsonEncryptFormat(encoded: Uint8Array, contentType: string[], isEncrypted: boolean): EncryptedJson;
@@ -0,0 +1,14 @@
1
+ import { base64Encode } from '../base64/index.js';
2
+ import { ENCODING, ENCODING_NONE, ENCODING_VERSION } from './constants.js';
3
+ export function jsonEncryptFormat(encoded, contentType, isEncrypted) {
4
+ return {
5
+ encoded: base64Encode(encoded),
6
+ encoding: {
7
+ content: contentType,
8
+ type: isEncrypted
9
+ ? ENCODING
10
+ : ENCODING_NONE,
11
+ version: ENCODING_VERSION
12
+ }
13
+ };
14
+ }
@@ -0,0 +1,4 @@
1
+ export { jsonDecrypt } from './decrypt.js';
2
+ export { jsonDecryptData } from './decryptData.js';
3
+ export { jsonEncrypt } from './encrypt.js';
4
+ export { jsonEncryptFormat } from './encryptFormat.js';
package/json/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export { jsonDecrypt } from './decrypt.js';
2
+ export { jsonDecryptData } from './decryptData.js';
3
+ export { jsonEncrypt } from './encrypt.js';
4
+ export { jsonEncryptFormat } from './encryptFormat.js';
@@ -0,0 +1,16 @@
1
+ export type EncryptedJsonVersion = '0' | '1' | '2' | '3';
2
+ export type EncryptedJsonEncoding = 'none' | 'scrypt' | 'xsalsa20-poly1305';
3
+ export interface EncryptedJsonDescriptor {
4
+ /** Descriptor for the content */
5
+ content: string[];
6
+ /** The encoding (in current/latest versions this is always an array) */
7
+ type: EncryptedJsonEncoding | EncryptedJsonEncoding[];
8
+ /** The version of encoding applied */
9
+ version: EncryptedJsonVersion;
10
+ }
11
+ export interface EncryptedJson {
12
+ /** The encoded string */
13
+ encoded: string;
14
+ /** The encoding used */
15
+ encoding: EncryptedJsonDescriptor;
16
+ }
package/json/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @name keccakAsU8a
3
+ * @summary Creates a keccak Uint8Array from the input.
4
+ * @description
5
+ * From either a `string` or a `Buffer` input, create the keccak and return the result as a `Uint8Array`.
6
+ * @example
7
+ * <BR>
8
+ *
9
+ * ```javascript
10
+ * import { keccakAsU8a } from '@pezkuwi/util-crypto';
11
+ *
12
+ * keccakAsU8a('123'); // => Uint8Array
13
+ * ```
14
+ */
15
+ export declare const keccakAsU8a: (value: string | Uint8Array, bitLength?: 256 | 512, onlyJs?: boolean) => Uint8Array;
16
+ /**
17
+ * @name keccak256AsU8a
18
+ * @description Creates a keccak256 Uint8Array from the input.
19
+ */
20
+ export declare const keccak256AsU8a: (data: string | Uint8Array, onlyJs?: boolean) => Uint8Array;
21
+ /**
22
+ * @name keccak512AsU8a
23
+ * @description Creates a keccak512 Uint8Array from the input.
24
+ */
25
+ export declare const keccak512AsU8a: (data: string | Uint8Array, onlyJs?: boolean) => Uint8Array;
26
+ /**
27
+ * @name keccakAsHex
28
+ * @description Creates a keccak hex string from the input.
29
+ */
30
+ export declare const keccakAsHex: (value: string | Uint8Array, bitLength?: 256 | 512 | undefined, onlyJs?: boolean | undefined) => import("@pezkuwi/util/types").HexString;
@@ -0,0 +1,33 @@
1
+ import { keccak_256 as keccak256Js, keccak_512 as keccak512Js } from '@noble/hashes/sha3';
2
+ import { keccak256, keccak512 } from '@pezkuwi/wasm-crypto';
3
+ import { createAsHex, createBitHasher, createDualHasher } from '../helpers.js';
4
+ /**
5
+ * @name keccakAsU8a
6
+ * @summary Creates a keccak Uint8Array from the input.
7
+ * @description
8
+ * From either a `string` or a `Buffer` input, create the keccak and return the result as a `Uint8Array`.
9
+ * @example
10
+ * <BR>
11
+ *
12
+ * ```javascript
13
+ * import { keccakAsU8a } from '@pezkuwi/util-crypto';
14
+ *
15
+ * keccakAsU8a('123'); // => Uint8Array
16
+ * ```
17
+ */
18
+ export const keccakAsU8a = /*#__PURE__*/ createDualHasher({ 256: keccak256, 512: keccak512 }, { 256: keccak256Js, 512: keccak512Js });
19
+ /**
20
+ * @name keccak256AsU8a
21
+ * @description Creates a keccak256 Uint8Array from the input.
22
+ */
23
+ export const keccak256AsU8a = /*#__PURE__*/ createBitHasher(256, keccakAsU8a);
24
+ /**
25
+ * @name keccak512AsU8a
26
+ * @description Creates a keccak512 Uint8Array from the input.
27
+ */
28
+ export const keccak512AsU8a = /*#__PURE__*/ createBitHasher(512, keccakAsU8a);
29
+ /**
30
+ * @name keccakAsHex
31
+ * @description Creates a keccak hex string from the input.
32
+ */
33
+ export const keccakAsHex = /*#__PURE__*/ createAsHex(keccakAsU8a);