@bsv/sdk 2.1.0 → 2.1.2

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 (392) hide show
  1. package/README.md +7 -7
  2. package/dist/cjs/package.json +1 -1
  3. package/dist/cjs/src/auth/Peer.js +8 -13
  4. package/dist/cjs/src/auth/Peer.js.map +1 -1
  5. package/dist/cjs/src/auth/SessionManager.js +4 -7
  6. package/dist/cjs/src/auth/SessionManager.js.map +1 -1
  7. package/dist/cjs/src/auth/certificates/MasterCertificate.js +1 -1
  8. package/dist/cjs/src/auth/certificates/MasterCertificate.js.map +1 -1
  9. package/dist/cjs/src/auth/certificates/__tests/CompletedProtoWallet.js +1 -1
  10. package/dist/cjs/src/auth/certificates/__tests/CompletedProtoWallet.js.map +1 -1
  11. package/dist/cjs/src/auth/clients/AuthFetch.js +32 -32
  12. package/dist/cjs/src/auth/clients/AuthFetch.js.map +1 -1
  13. package/dist/cjs/src/auth/transports/SimplifiedFetchTransport.js +4 -4
  14. package/dist/cjs/src/auth/transports/SimplifiedFetchTransport.js.map +1 -1
  15. package/dist/cjs/src/compat/ECIES.js +29 -34
  16. package/dist/cjs/src/compat/ECIES.js.map +1 -1
  17. package/dist/cjs/src/compat/HD.js +9 -4
  18. package/dist/cjs/src/compat/HD.js.map +1 -1
  19. package/dist/cjs/src/compat/Mnemonic.js +12 -12
  20. package/dist/cjs/src/compat/Mnemonic.js.map +1 -1
  21. package/dist/cjs/src/identity/ContactsManager.js +212 -234
  22. package/dist/cjs/src/identity/ContactsManager.js.map +1 -1
  23. package/dist/cjs/src/identity/IdentityClient.js +199 -63
  24. package/dist/cjs/src/identity/IdentityClient.js.map +1 -1
  25. package/dist/cjs/src/kvstore/GlobalKVStore.js +30 -31
  26. package/dist/cjs/src/kvstore/GlobalKVStore.js.map +1 -1
  27. package/dist/cjs/src/kvstore/LocalKVStore.js +9 -9
  28. package/dist/cjs/src/kvstore/LocalKVStore.js.map +1 -1
  29. package/dist/cjs/src/kvstore/kvStoreInterpreter.js +2 -2
  30. package/dist/cjs/src/kvstore/kvStoreInterpreter.js.map +1 -1
  31. package/dist/cjs/src/messages/SignedMessage.js +1 -1
  32. package/dist/cjs/src/messages/SignedMessage.js.map +1 -1
  33. package/dist/cjs/src/overlay-tools/Historian.js +1 -1
  34. package/dist/cjs/src/overlay-tools/Historian.js.map +1 -1
  35. package/dist/cjs/src/overlay-tools/LookupResolver.js +213 -93
  36. package/dist/cjs/src/overlay-tools/LookupResolver.js.map +1 -1
  37. package/dist/cjs/src/overlay-tools/SHIPBroadcaster.js +75 -146
  38. package/dist/cjs/src/overlay-tools/SHIPBroadcaster.js.map +1 -1
  39. package/dist/cjs/src/primitives/AESGCM.js +2 -2
  40. package/dist/cjs/src/primitives/AESGCM.js.map +1 -1
  41. package/dist/cjs/src/primitives/BigNumber.js +164 -148
  42. package/dist/cjs/src/primitives/BigNumber.js.map +1 -1
  43. package/dist/cjs/src/primitives/Curve.js +17 -15
  44. package/dist/cjs/src/primitives/Curve.js.map +1 -1
  45. package/dist/cjs/src/primitives/ECDSA.js +12 -7
  46. package/dist/cjs/src/primitives/ECDSA.js.map +1 -1
  47. package/dist/cjs/src/primitives/Hash.js +312 -105
  48. package/dist/cjs/src/primitives/Hash.js.map +1 -1
  49. package/dist/cjs/src/primitives/JacobianPoint.js +8 -8
  50. package/dist/cjs/src/primitives/JacobianPoint.js.map +1 -1
  51. package/dist/cjs/src/primitives/K256.js +3 -3
  52. package/dist/cjs/src/primitives/K256.js.map +1 -1
  53. package/dist/cjs/src/primitives/Point.js +36 -40
  54. package/dist/cjs/src/primitives/Point.js.map +1 -1
  55. package/dist/cjs/src/primitives/PrivateKey.js +4 -4
  56. package/dist/cjs/src/primitives/PrivateKey.js.map +1 -1
  57. package/dist/cjs/src/primitives/PublicKey.js +4 -4
  58. package/dist/cjs/src/primitives/PublicKey.js.map +1 -1
  59. package/dist/cjs/src/primitives/Random.js +10 -14
  60. package/dist/cjs/src/primitives/Random.js.map +1 -1
  61. package/dist/cjs/src/primitives/ReaderUint8Array.js +6 -6
  62. package/dist/cjs/src/primitives/ReaderUint8Array.js.map +1 -1
  63. package/dist/cjs/src/primitives/Schnorr.js +2 -2
  64. package/dist/cjs/src/primitives/Schnorr.js.map +1 -1
  65. package/dist/cjs/src/primitives/Secp256r1.js +2 -1
  66. package/dist/cjs/src/primitives/Secp256r1.js.map +1 -1
  67. package/dist/cjs/src/primitives/Signature.js +8 -8
  68. package/dist/cjs/src/primitives/Signature.js.map +1 -1
  69. package/dist/cjs/src/primitives/SymmetricKey.js +123 -1
  70. package/dist/cjs/src/primitives/SymmetricKey.js.map +1 -1
  71. package/dist/cjs/src/primitives/TransactionSignature.js +20 -21
  72. package/dist/cjs/src/primitives/TransactionSignature.js.map +1 -1
  73. package/dist/cjs/src/primitives/utils.js +39 -46
  74. package/dist/cjs/src/primitives/utils.js.map +1 -1
  75. package/dist/cjs/src/registry/RegistryClient.js +31 -23
  76. package/dist/cjs/src/registry/RegistryClient.js.map +1 -1
  77. package/dist/cjs/src/remittance/RemittanceManager.js +19 -18
  78. package/dist/cjs/src/remittance/RemittanceManager.js.map +1 -1
  79. package/dist/cjs/src/remittance/modules/BasicBRC29.js.map +1 -1
  80. package/dist/cjs/src/script/Script.js +93 -170
  81. package/dist/cjs/src/script/Script.js.map +1 -1
  82. package/dist/cjs/src/script/ScriptEvaluationError.js +2 -2
  83. package/dist/cjs/src/script/ScriptEvaluationError.js.map +1 -1
  84. package/dist/cjs/src/script/Spend.js +14 -12
  85. package/dist/cjs/src/script/Spend.js.map +1 -1
  86. package/dist/cjs/src/script/templates/PushDrop.js +22 -18
  87. package/dist/cjs/src/script/templates/PushDrop.js.map +1 -1
  88. package/dist/cjs/src/script/templates/RPuzzle.js +2 -4
  89. package/dist/cjs/src/script/templates/RPuzzle.js.map +1 -1
  90. package/dist/cjs/src/storage/StorageDownloader.js +42 -9
  91. package/dist/cjs/src/storage/StorageDownloader.js.map +1 -1
  92. package/dist/cjs/src/totp/totp.js +1 -1
  93. package/dist/cjs/src/totp/totp.js.map +1 -1
  94. package/dist/cjs/src/transaction/Beef.js +239 -192
  95. package/dist/cjs/src/transaction/Beef.js.map +1 -1
  96. package/dist/cjs/src/transaction/BeefConstants.js +19 -0
  97. package/dist/cjs/src/transaction/BeefConstants.js.map +1 -0
  98. package/dist/cjs/src/transaction/BeefTx.js +12 -12
  99. package/dist/cjs/src/transaction/BeefTx.js.map +1 -1
  100. package/dist/cjs/src/transaction/MerklePath.js +4 -4
  101. package/dist/cjs/src/transaction/MerklePath.js.map +1 -1
  102. package/dist/cjs/src/transaction/Transaction.js +49 -52
  103. package/dist/cjs/src/transaction/Transaction.js.map +1 -1
  104. package/dist/cjs/src/transaction/fee-models/SatoshisPerKilobyte.js +1 -1
  105. package/dist/cjs/src/transaction/fee-models/SatoshisPerKilobyte.js.map +1 -1
  106. package/dist/cjs/src/transaction/http/BinaryFetchClient.js +9 -9
  107. package/dist/cjs/src/transaction/http/BinaryFetchClient.js.map +1 -1
  108. package/dist/cjs/src/transaction/http/DefaultHttpClient.js +9 -9
  109. package/dist/cjs/src/transaction/http/DefaultHttpClient.js.map +1 -1
  110. package/dist/cjs/src/wallet/CachedKeyDeriver.js +1 -1
  111. package/dist/cjs/src/wallet/CachedKeyDeriver.js.map +1 -1
  112. package/dist/cjs/src/wallet/WalletClient.js.map +1 -1
  113. package/dist/cjs/src/wallet/WalletError.js.map +1 -1
  114. package/dist/cjs/src/wallet/substrates/HTTPWalletJSON.js +5 -4
  115. package/dist/cjs/src/wallet/substrates/HTTPWalletJSON.js.map +1 -1
  116. package/dist/cjs/src/wallet/substrates/ReactNativeWebView.js +9 -9
  117. package/dist/cjs/src/wallet/substrates/ReactNativeWebView.js.map +1 -1
  118. package/dist/cjs/src/wallet/substrates/WalletWireProcessor.js +92 -92
  119. package/dist/cjs/src/wallet/substrates/WalletWireProcessor.js.map +1 -1
  120. package/dist/cjs/src/wallet/substrates/WalletWireTransceiver.js +387 -711
  121. package/dist/cjs/src/wallet/substrates/WalletWireTransceiver.js.map +1 -1
  122. package/dist/cjs/src/wallet/substrates/XDM.js +4 -4
  123. package/dist/cjs/src/wallet/substrates/XDM.js.map +1 -1
  124. package/dist/cjs/src/wallet/substrates/window.CWI.js +2 -2
  125. package/dist/cjs/src/wallet/substrates/window.CWI.js.map +1 -1
  126. package/dist/cjs/src/wallet/validationHelpers.js +9 -9
  127. package/dist/cjs/src/wallet/validationHelpers.js.map +1 -1
  128. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  129. package/dist/esm/src/auth/Peer.js +25 -13
  130. package/dist/esm/src/auth/Peer.js.map +1 -1
  131. package/dist/esm/src/auth/SessionManager.js +4 -7
  132. package/dist/esm/src/auth/SessionManager.js.map +1 -1
  133. package/dist/esm/src/auth/certificates/MasterCertificate.js +1 -1
  134. package/dist/esm/src/auth/certificates/MasterCertificate.js.map +1 -1
  135. package/dist/esm/src/auth/certificates/__tests/CompletedProtoWallet.js +1 -1
  136. package/dist/esm/src/auth/certificates/__tests/CompletedProtoWallet.js.map +1 -1
  137. package/dist/esm/src/auth/clients/AuthFetch.js +32 -32
  138. package/dist/esm/src/auth/clients/AuthFetch.js.map +1 -1
  139. package/dist/esm/src/auth/transports/SimplifiedFetchTransport.js +4 -4
  140. package/dist/esm/src/auth/transports/SimplifiedFetchTransport.js.map +1 -1
  141. package/dist/esm/src/compat/ECIES.js +29 -34
  142. package/dist/esm/src/compat/ECIES.js.map +1 -1
  143. package/dist/esm/src/compat/HD.js +9 -4
  144. package/dist/esm/src/compat/HD.js.map +1 -1
  145. package/dist/esm/src/compat/Mnemonic.js +12 -12
  146. package/dist/esm/src/compat/Mnemonic.js.map +1 -1
  147. package/dist/esm/src/identity/ContactsManager.js +212 -234
  148. package/dist/esm/src/identity/ContactsManager.js.map +1 -1
  149. package/dist/esm/src/identity/IdentityClient.js +199 -63
  150. package/dist/esm/src/identity/IdentityClient.js.map +1 -1
  151. package/dist/esm/src/kvstore/GlobalKVStore.js +30 -31
  152. package/dist/esm/src/kvstore/GlobalKVStore.js.map +1 -1
  153. package/dist/esm/src/kvstore/LocalKVStore.js +9 -9
  154. package/dist/esm/src/kvstore/LocalKVStore.js.map +1 -1
  155. package/dist/esm/src/kvstore/kvStoreInterpreter.js +2 -2
  156. package/dist/esm/src/kvstore/kvStoreInterpreter.js.map +1 -1
  157. package/dist/esm/src/messages/SignedMessage.js +1 -1
  158. package/dist/esm/src/messages/SignedMessage.js.map +1 -1
  159. package/dist/esm/src/overlay-tools/Historian.js +1 -1
  160. package/dist/esm/src/overlay-tools/Historian.js.map +1 -1
  161. package/dist/esm/src/overlay-tools/LookupResolver.js +213 -93
  162. package/dist/esm/src/overlay-tools/LookupResolver.js.map +1 -1
  163. package/dist/esm/src/overlay-tools/SHIPBroadcaster.js +74 -146
  164. package/dist/esm/src/overlay-tools/SHIPBroadcaster.js.map +1 -1
  165. package/dist/esm/src/primitives/AESGCM.js +2 -2
  166. package/dist/esm/src/primitives/AESGCM.js.map +1 -1
  167. package/dist/esm/src/primitives/BigNumber.js +167 -154
  168. package/dist/esm/src/primitives/BigNumber.js.map +1 -1
  169. package/dist/esm/src/primitives/Curve.js +17 -15
  170. package/dist/esm/src/primitives/Curve.js.map +1 -1
  171. package/dist/esm/src/primitives/ECDSA.js +12 -7
  172. package/dist/esm/src/primitives/ECDSA.js.map +1 -1
  173. package/dist/esm/src/primitives/Hash.js +316 -105
  174. package/dist/esm/src/primitives/Hash.js.map +1 -1
  175. package/dist/esm/src/primitives/JacobianPoint.js +8 -8
  176. package/dist/esm/src/primitives/JacobianPoint.js.map +1 -1
  177. package/dist/esm/src/primitives/K256.js +3 -3
  178. package/dist/esm/src/primitives/K256.js.map +1 -1
  179. package/dist/esm/src/primitives/Point.js +36 -40
  180. package/dist/esm/src/primitives/Point.js.map +1 -1
  181. package/dist/esm/src/primitives/PrivateKey.js +4 -4
  182. package/dist/esm/src/primitives/PrivateKey.js.map +1 -1
  183. package/dist/esm/src/primitives/PublicKey.js +4 -4
  184. package/dist/esm/src/primitives/PublicKey.js.map +1 -1
  185. package/dist/esm/src/primitives/Random.js +10 -14
  186. package/dist/esm/src/primitives/Random.js.map +1 -1
  187. package/dist/esm/src/primitives/ReaderUint8Array.js +6 -6
  188. package/dist/esm/src/primitives/ReaderUint8Array.js.map +1 -1
  189. package/dist/esm/src/primitives/Schnorr.js +1 -1
  190. package/dist/esm/src/primitives/Schnorr.js.map +1 -1
  191. package/dist/esm/src/primitives/Secp256r1.js +2 -1
  192. package/dist/esm/src/primitives/Secp256r1.js.map +1 -1
  193. package/dist/esm/src/primitives/Signature.js +8 -8
  194. package/dist/esm/src/primitives/Signature.js.map +1 -1
  195. package/dist/esm/src/primitives/SymmetricKey.js +123 -1
  196. package/dist/esm/src/primitives/SymmetricKey.js.map +1 -1
  197. package/dist/esm/src/primitives/TransactionSignature.js +20 -21
  198. package/dist/esm/src/primitives/TransactionSignature.js.map +1 -1
  199. package/dist/esm/src/primitives/utils.js +39 -48
  200. package/dist/esm/src/primitives/utils.js.map +1 -1
  201. package/dist/esm/src/registry/RegistryClient.js +31 -23
  202. package/dist/esm/src/registry/RegistryClient.js.map +1 -1
  203. package/dist/esm/src/remittance/RemittanceManager.js +19 -18
  204. package/dist/esm/src/remittance/RemittanceManager.js.map +1 -1
  205. package/dist/esm/src/remittance/modules/BasicBRC29.js.map +1 -1
  206. package/dist/esm/src/script/Script.js +93 -170
  207. package/dist/esm/src/script/Script.js.map +1 -1
  208. package/dist/esm/src/script/ScriptEvaluationError.js +2 -2
  209. package/dist/esm/src/script/ScriptEvaluationError.js.map +1 -1
  210. package/dist/esm/src/script/Spend.js +14 -12
  211. package/dist/esm/src/script/Spend.js.map +1 -1
  212. package/dist/esm/src/script/templates/PushDrop.js +4 -3
  213. package/dist/esm/src/script/templates/PushDrop.js.map +1 -1
  214. package/dist/esm/src/script/templates/RPuzzle.js +2 -4
  215. package/dist/esm/src/script/templates/RPuzzle.js.map +1 -1
  216. package/dist/esm/src/storage/StorageDownloader.js +1 -1
  217. package/dist/esm/src/storage/StorageDownloader.js.map +1 -1
  218. package/dist/esm/src/totp/totp.js +1 -1
  219. package/dist/esm/src/totp/totp.js.map +1 -1
  220. package/dist/esm/src/transaction/Beef.js +229 -186
  221. package/dist/esm/src/transaction/Beef.js.map +1 -1
  222. package/dist/esm/src/transaction/BeefConstants.js +16 -0
  223. package/dist/esm/src/transaction/BeefConstants.js.map +1 -0
  224. package/dist/esm/src/transaction/BeefTx.js +3 -3
  225. package/dist/esm/src/transaction/BeefTx.js.map +1 -1
  226. package/dist/esm/src/transaction/MerklePath.js +4 -4
  227. package/dist/esm/src/transaction/MerklePath.js.map +1 -1
  228. package/dist/esm/src/transaction/Transaction.js +49 -52
  229. package/dist/esm/src/transaction/Transaction.js.map +1 -1
  230. package/dist/esm/src/transaction/fee-models/SatoshisPerKilobyte.js +1 -1
  231. package/dist/esm/src/transaction/fee-models/SatoshisPerKilobyte.js.map +1 -1
  232. package/dist/esm/src/transaction/http/BinaryFetchClient.js +9 -9
  233. package/dist/esm/src/transaction/http/BinaryFetchClient.js.map +1 -1
  234. package/dist/esm/src/transaction/http/DefaultHttpClient.js +9 -9
  235. package/dist/esm/src/transaction/http/DefaultHttpClient.js.map +1 -1
  236. package/dist/esm/src/wallet/CachedKeyDeriver.js +1 -1
  237. package/dist/esm/src/wallet/CachedKeyDeriver.js.map +1 -1
  238. package/dist/esm/src/wallet/WalletClient.js.map +1 -1
  239. package/dist/esm/src/wallet/WalletError.js.map +1 -1
  240. package/dist/esm/src/wallet/substrates/HTTPWalletJSON.js +5 -4
  241. package/dist/esm/src/wallet/substrates/HTTPWalletJSON.js.map +1 -1
  242. package/dist/esm/src/wallet/substrates/ReactNativeWebView.js +9 -9
  243. package/dist/esm/src/wallet/substrates/ReactNativeWebView.js.map +1 -1
  244. package/dist/esm/src/wallet/substrates/WalletWireProcessor.js +92 -92
  245. package/dist/esm/src/wallet/substrates/WalletWireProcessor.js.map +1 -1
  246. package/dist/esm/src/wallet/substrates/WalletWireTransceiver.js +387 -711
  247. package/dist/esm/src/wallet/substrates/WalletWireTransceiver.js.map +1 -1
  248. package/dist/esm/src/wallet/substrates/XDM.js +4 -4
  249. package/dist/esm/src/wallet/substrates/XDM.js.map +1 -1
  250. package/dist/esm/src/wallet/substrates/window.CWI.js +2 -2
  251. package/dist/esm/src/wallet/substrates/window.CWI.js.map +1 -1
  252. package/dist/esm/src/wallet/validationHelpers.js +9 -9
  253. package/dist/esm/src/wallet/validationHelpers.js.map +1 -1
  254. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  255. package/dist/types/src/auth/Peer.d.ts +13 -0
  256. package/dist/types/src/auth/Peer.d.ts.map +1 -1
  257. package/dist/types/src/auth/SessionManager.d.ts.map +1 -1
  258. package/dist/types/src/auth/clients/AuthFetch.d.ts.map +1 -1
  259. package/dist/types/src/compat/ECIES.d.ts.map +1 -1
  260. package/dist/types/src/compat/HD.d.ts.map +1 -1
  261. package/dist/types/src/identity/ContactsManager.d.ts +31 -2
  262. package/dist/types/src/identity/ContactsManager.d.ts.map +1 -1
  263. package/dist/types/src/identity/IdentityClient.d.ts +75 -10
  264. package/dist/types/src/identity/IdentityClient.d.ts.map +1 -1
  265. package/dist/types/src/kvstore/GlobalKVStore.d.ts.map +1 -1
  266. package/dist/types/src/overlay-tools/LookupResolver.d.ts +73 -2
  267. package/dist/types/src/overlay-tools/LookupResolver.d.ts.map +1 -1
  268. package/dist/types/src/overlay-tools/SHIPBroadcaster.d.ts +18 -3
  269. package/dist/types/src/overlay-tools/SHIPBroadcaster.d.ts.map +1 -1
  270. package/dist/types/src/primitives/BigNumber.d.ts +13 -3
  271. package/dist/types/src/primitives/BigNumber.d.ts.map +1 -1
  272. package/dist/types/src/primitives/Curve.d.ts.map +1 -1
  273. package/dist/types/src/primitives/ECDSA.d.ts.map +1 -1
  274. package/dist/types/src/primitives/Hash.d.ts +22 -17
  275. package/dist/types/src/primitives/Hash.d.ts.map +1 -1
  276. package/dist/types/src/primitives/JacobianPoint.d.ts +3 -1
  277. package/dist/types/src/primitives/JacobianPoint.d.ts.map +1 -1
  278. package/dist/types/src/primitives/Point.d.ts.map +1 -1
  279. package/dist/types/src/primitives/Random.d.ts +2 -2
  280. package/dist/types/src/primitives/Random.d.ts.map +1 -1
  281. package/dist/types/src/primitives/ReaderUint8Array.d.ts.map +1 -1
  282. package/dist/types/src/primitives/Schnorr.d.ts +2 -1
  283. package/dist/types/src/primitives/Schnorr.d.ts.map +1 -1
  284. package/dist/types/src/primitives/Secp256r1.d.ts.map +1 -1
  285. package/dist/types/src/primitives/SymmetricKey.d.ts.map +1 -1
  286. package/dist/types/src/primitives/utils.d.ts +2 -4
  287. package/dist/types/src/primitives/utils.d.ts.map +1 -1
  288. package/dist/types/src/registry/RegistryClient.d.ts.map +1 -1
  289. package/dist/types/src/remittance/RemittanceManager.d.ts.map +1 -1
  290. package/dist/types/src/remittance/modules/BasicBRC29.d.ts.map +1 -1
  291. package/dist/types/src/script/Script.d.ts +15 -8
  292. package/dist/types/src/script/Script.d.ts.map +1 -1
  293. package/dist/types/src/script/Spend.d.ts.map +1 -1
  294. package/dist/types/src/script/templates/PushDrop.d.ts +3 -1
  295. package/dist/types/src/script/templates/PushDrop.d.ts.map +1 -1
  296. package/dist/types/src/script/templates/RPuzzle.d.ts.map +1 -1
  297. package/dist/types/src/transaction/Beef.d.ts +46 -8
  298. package/dist/types/src/transaction/Beef.d.ts.map +1 -1
  299. package/dist/types/src/transaction/BeefConstants.d.ts +15 -0
  300. package/dist/types/src/transaction/BeefConstants.d.ts.map +1 -0
  301. package/dist/types/src/transaction/Transaction.d.ts.map +1 -1
  302. package/dist/types/src/wallet/CachedKeyDeriver.d.ts.map +1 -1
  303. package/dist/types/src/wallet/KeyDeriver.d.ts +1 -1
  304. package/dist/types/src/wallet/KeyDeriver.d.ts.map +1 -1
  305. package/dist/types/src/wallet/Wallet.interfaces.d.ts +18 -3
  306. package/dist/types/src/wallet/Wallet.interfaces.d.ts.map +1 -1
  307. package/dist/types/src/wallet/WalletClient.d.ts +8 -8
  308. package/dist/types/src/wallet/WalletClient.d.ts.map +1 -1
  309. package/dist/types/src/wallet/substrates/HTTPWalletJSON.d.ts +7 -7
  310. package/dist/types/src/wallet/substrates/HTTPWalletJSON.d.ts.map +1 -1
  311. package/dist/types/src/wallet/substrates/WalletWireTransceiver.d.ts +36 -7
  312. package/dist/types/src/wallet/substrates/WalletWireTransceiver.d.ts.map +1 -1
  313. package/dist/types/src/wallet/substrates/window.CWI.d.ts +9 -9
  314. package/dist/types/src/wallet/substrates/window.CWI.d.ts.map +1 -1
  315. package/dist/types/tsconfig.types.tsbuildinfo +1 -1
  316. package/dist/umd/bundle.js +3 -3
  317. package/package.json +1 -1
  318. package/src/auth/Peer.ts +26 -13
  319. package/src/auth/SessionManager.ts +4 -7
  320. package/src/auth/certificates/MasterCertificate.ts +1 -1
  321. package/src/auth/certificates/__tests/CompletedProtoWallet.ts +1 -1
  322. package/src/auth/clients/AuthFetch.ts +41 -41
  323. package/src/auth/transports/SimplifiedFetchTransport.ts +4 -4
  324. package/src/compat/ECIES.ts +29 -34
  325. package/src/compat/HD.ts +10 -5
  326. package/src/compat/Mnemonic.ts +11 -11
  327. package/src/compat/__tests/HD.test.ts +19 -0
  328. package/src/identity/ContactsManager.ts +236 -258
  329. package/src/identity/IdentityClient.ts +244 -71
  330. package/src/identity/__tests/IdentityClient.additional.test.ts +150 -1
  331. package/src/identity/__tests/IdentityClient.test.ts +27 -3
  332. package/src/kvstore/GlobalKVStore.ts +31 -32
  333. package/src/kvstore/LocalKVStore.ts +8 -8
  334. package/src/kvstore/kvStoreInterpreter.ts +2 -2
  335. package/src/messages/SignedMessage.ts +1 -1
  336. package/src/overlay-tools/Historian.ts +1 -1
  337. package/src/overlay-tools/LookupResolver.ts +264 -90
  338. package/src/overlay-tools/SHIPBroadcaster.ts +92 -168
  339. package/src/primitives/AESGCM.ts +2 -2
  340. package/src/primitives/BigNumber.ts +122 -113
  341. package/src/primitives/Curve.ts +16 -15
  342. package/src/primitives/ECDSA.ts +10 -8
  343. package/src/primitives/Hash.ts +381 -146
  344. package/src/primitives/JacobianPoint.ts +13 -11
  345. package/src/primitives/K256.ts +3 -3
  346. package/src/primitives/Point.ts +35 -38
  347. package/src/primitives/PrivateKey.ts +3 -3
  348. package/src/primitives/PublicKey.ts +3 -3
  349. package/src/primitives/Random.ts +11 -14
  350. package/src/primitives/ReaderUint8Array.ts +7 -7
  351. package/src/primitives/Schnorr.ts +2 -1
  352. package/src/primitives/Secp256r1.ts +2 -1
  353. package/src/primitives/Signature.ts +8 -8
  354. package/src/primitives/SymmetricKey.ts +145 -1
  355. package/src/primitives/TransactionSignature.ts +16 -16
  356. package/src/primitives/__tests/Hash.additional.test.ts +65 -0
  357. package/src/primitives/__tests/Hash.test.ts +6 -1
  358. package/src/primitives/utils.ts +37 -47
  359. package/src/registry/RegistryClient.ts +25 -25
  360. package/src/remittance/RemittanceManager.ts +17 -18
  361. package/src/remittance/modules/BasicBRC29.ts +2 -5
  362. package/src/script/Script.ts +114 -170
  363. package/src/script/ScriptEvaluationError.ts +2 -2
  364. package/src/script/Spend.ts +14 -15
  365. package/src/script/templates/PushDrop.ts +5 -3
  366. package/src/script/templates/RPuzzle.ts +2 -4
  367. package/src/storage/StorageDownloader.ts +1 -1
  368. package/src/totp/totp.ts +1 -1
  369. package/src/transaction/Beef.ts +241 -203
  370. package/src/transaction/BeefConstants.ts +16 -0
  371. package/src/transaction/BeefTx.ts +3 -3
  372. package/src/transaction/MerklePath.ts +4 -4
  373. package/src/transaction/Transaction.ts +48 -51
  374. package/src/transaction/fee-models/SatoshisPerKilobyte.ts +1 -1
  375. package/src/transaction/http/BinaryFetchClient.ts +8 -8
  376. package/src/transaction/http/DefaultHttpClient.ts +8 -8
  377. package/src/wallet/CachedKeyDeriver.ts +8 -6
  378. package/src/wallet/KeyDeriver.ts +1 -1
  379. package/src/wallet/Wallet.interfaces.ts +18 -5
  380. package/src/wallet/WalletClient.ts +9 -9
  381. package/src/wallet/WalletError.ts +1 -1
  382. package/src/wallet/__tests/WalletClient.substrate.test.ts +10 -6
  383. package/src/wallet/substrates/HTTPWalletJSON.ts +22 -21
  384. package/src/wallet/substrates/ReactNativeWebView.ts +9 -9
  385. package/src/wallet/substrates/WalletWireProcessor.ts +83 -83
  386. package/src/wallet/substrates/WalletWireTransceiver.ts +528 -938
  387. package/src/wallet/substrates/XDM.ts +4 -4
  388. package/src/wallet/substrates/__tests/HTTPWalletJSON.test.ts +38 -25
  389. package/src/wallet/substrates/__tests/ReactNativeWebView.test.ts +174 -0
  390. package/src/wallet/substrates/__tests/window.CWI.test.ts +256 -0
  391. package/src/wallet/substrates/window.CWI.ts +11 -11
  392. package/src/wallet/validationHelpers.ts +9 -9
@@ -191,6 +191,59 @@ function isSurrogatePair(msg, i) {
191
191
  }
192
192
  return (msg.charCodeAt(i + 1) & 0xfc00) === 0xdc00;
193
193
  }
194
+ /**
195
+ * Encode a single UTF-16 code unit (and possibly its surrogate partner)
196
+ * into UTF-8 bytes, appending them to `out`.
197
+ *
198
+ * Returns the index of the last consumed code unit so the caller can
199
+ * advance its loop variable when a surrogate pair is consumed.
200
+ *
201
+ * Inspired by stringToUtf8ByteArray() in closure-library by Google
202
+ * https://github.com/google/closure-library/blob/8598d87242af59aac233270742c8984e2b2bdbe0/closure/goog/crypt/crypt#L117-L143
203
+ * Apache License 2.0
204
+ * https://github.com/google/closure-library/blob/master/LICENSE
205
+ */
206
+ function appendUtf8CodeUnit(msg, i, out) {
207
+ let c = msg.charCodeAt(i);
208
+ if (c < 128) {
209
+ out.push(c);
210
+ return i;
211
+ }
212
+ if (c < 2048) {
213
+ out.push((c >> 6) | 192, (c & 63) | 128);
214
+ return i;
215
+ }
216
+ if (isSurrogatePair(msg, i)) {
217
+ c = 0x10000 + ((c & 0x03ff) << 10) + (msg.charCodeAt(i + 1) & 0x03ff);
218
+ out.push((c >> 18) | 240, ((c >> 12) & 63) | 128, ((c >> 6) & 63) | 128, (c & 63) | 128);
219
+ return i + 1;
220
+ }
221
+ out.push((c >> 12) | 224, ((c >> 6) & 63) | 128, (c & 63) | 128);
222
+ return i;
223
+ }
224
+ function utf8StringToArray(msg) {
225
+ const res = [];
226
+ for (let i = 0; i < msg.length; i++) {
227
+ i = appendUtf8CodeUnit(msg, i, res);
228
+ }
229
+ return res;
230
+ }
231
+ function hexStringToArray(msg) {
232
+ assertValidHex(msg);
233
+ const normalized = normalizeHex(msg);
234
+ const res = [];
235
+ for (let i = 0; i < normalized.length; i += 2) {
236
+ res.push(Number.parseInt(normalized[i] + normalized[i + 1], 16));
237
+ }
238
+ return res;
239
+ }
240
+ function numberArrayToByteArray(msg) {
241
+ const res = [];
242
+ for (let i = 0; i < msg.length; i++) {
243
+ res[i] = Math.trunc(msg[i]);
244
+ }
245
+ return res;
246
+ }
194
247
  /**
195
248
  *
196
249
  * @param msg
@@ -204,52 +257,10 @@ export function toArray(msg, enc) {
204
257
  if (!msg) {
205
258
  return [];
206
259
  }
207
- const res = [];
208
260
  if (typeof msg === 'string') {
209
- if (enc !== 'hex') {
210
- // Inspired by stringToUtf8ByteArray() in closure-library by Google
211
- // https://github.com/google/closure-library/blob/8598d87242af59aac233270742c8984e2b2bdbe0/closure/goog/crypt/crypt#L117-L143
212
- // Apache License 2.0
213
- // https://github.com/google/closure-library/blob/master/LICENSE
214
- let p = 0;
215
- for (let i = 0; i < msg.length; i++) {
216
- let c = msg.charCodeAt(i);
217
- if (c < 128) {
218
- res[p++] = c;
219
- }
220
- else if (c < 2048) {
221
- res[p++] = (c >> 6) | 192;
222
- res[p++] = (c & 63) | 128;
223
- }
224
- else if (isSurrogatePair(msg, i)) {
225
- c = 0x10000 + ((c & 0x03ff) << 10) + (msg.charCodeAt(++i) & 0x03ff);
226
- res[p++] = (c >> 18) | 240;
227
- res[p++] = ((c >> 12) & 63) | 128;
228
- res[p++] = ((c >> 6) & 63) | 128;
229
- res[p++] = (c & 63) | 128;
230
- }
231
- else {
232
- res[p++] = (c >> 12) | 224;
233
- res[p++] = ((c >> 6) & 63) | 128;
234
- res[p++] = (c & 63) | 128;
235
- }
236
- }
237
- }
238
- else {
239
- assertValidHex(msg);
240
- msg = normalizeHex(msg);
241
- for (let i = 0; i < msg.length; i += 2) {
242
- res.push(parseInt(msg[i] + msg[i + 1], 16));
243
- }
244
- }
261
+ return enc === 'hex' ? hexStringToArray(msg) : utf8StringToArray(msg);
245
262
  }
246
- else {
247
- msg = msg;
248
- for (let i = 0; i < msg.length; i++) {
249
- res[i] = msg[i] | 0;
250
- }
251
- }
252
- return res;
263
+ return numberArrayToByteArray(msg);
253
264
  }
254
265
  /**
255
266
  * @deprecated
@@ -263,8 +274,7 @@ export function htonl(w) {
263
274
  }
264
275
  function toHex32(msg, endian) {
265
276
  let res = '';
266
- for (let i = 0; i < msg.length; i++) {
267
- let w = msg[i];
277
+ for (let w of msg) {
268
278
  if (endian === 'little') {
269
279
  w = htonl(w);
270
280
  }
@@ -298,11 +308,115 @@ function zero8(word) {
298
308
  return word;
299
309
  }
300
310
  }
311
+ const BufferCtor = typeof globalThis === 'undefined' ? undefined : globalThis.Buffer;
312
+ const CAN_USE_BUFFER = BufferCtor != null && typeof BufferCtor.from === 'function';
313
+ const HEX_DIGITS = '0123456789abcdef';
314
+ const HEX_BYTE_STRINGS = new Array(256);
315
+ for (let i = 0; i < HEX_BYTE_STRINGS.length; i++) {
316
+ HEX_BYTE_STRINGS[i] = HEX_DIGITS[(i >> 4) & 0xf] + HEX_DIGITS[i & 0xf];
317
+ }
301
318
  function bytesToHex(data) {
302
- let res = '';
303
- for (const b of data)
304
- res += (b.toString(16).padStart(2, '0'));
305
- return res;
319
+ if (CAN_USE_BUFFER) {
320
+ return BufferCtor.from(data).toString('hex');
321
+ }
322
+ const out = new Array(data.length);
323
+ for (let i = 0; i < data.length; i++)
324
+ out[i] = HEX_BYTE_STRINGS[data[i]];
325
+ return out.join('');
326
+ }
327
+ const NODE_CRYPTO = (() => {
328
+ const processLike = typeof globalThis === 'undefined' ? undefined : globalThis.process;
329
+ const getBuiltinModule = processLike?.getBuiltinModule;
330
+ if (typeof getBuiltinModule === 'function') {
331
+ try {
332
+ const crypto = getBuiltinModule.call(processLike, 'node:crypto');
333
+ if (crypto != null)
334
+ return crypto;
335
+ }
336
+ catch {
337
+ // continue to CommonJS fallback
338
+ }
339
+ }
340
+ try {
341
+ if (typeof require === 'function') {
342
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
343
+ return require('node:crypto');
344
+ }
345
+ }
346
+ catch {
347
+ // node:crypto is unavailable in this runtime
348
+ }
349
+ return undefined;
350
+ })();
351
+ function toHashBytes(msg, enc) {
352
+ if (msg instanceof Uint8Array) {
353
+ return msg;
354
+ }
355
+ if (Array.isArray(msg)) {
356
+ return new Uint8Array(msg);
357
+ }
358
+ return Uint8Array.from(toArray(msg, enc));
359
+ }
360
+ function toHashKeyBytes(key) {
361
+ return typeof key === 'string' ? toHashBytes(key, 'hex') : toHashBytes(key);
362
+ }
363
+ function updateNativeOrFallback(native, fallback, data) {
364
+ if (native != null) {
365
+ native.update(data);
366
+ }
367
+ else if (fallback != null) {
368
+ fallback.update(data);
369
+ }
370
+ }
371
+ function digestNativeOrFallback(native, fallback) {
372
+ if (native != null)
373
+ return Array.from(native.digest());
374
+ if (fallback != null)
375
+ return Array.from(fallback.digest());
376
+ return [];
377
+ }
378
+ function digestHexNativeOrFallback(native, fallback) {
379
+ if (native != null)
380
+ return native.digest('hex');
381
+ if (fallback != null)
382
+ return bytesToHex(fallback.digest());
383
+ return '';
384
+ }
385
+ function createNodeHash(algorithm) {
386
+ const createHash = NODE_CRYPTO?.createHash;
387
+ if (typeof createHash !== 'function')
388
+ return undefined;
389
+ try {
390
+ return createHash(algorithm);
391
+ }
392
+ catch {
393
+ return undefined;
394
+ }
395
+ }
396
+ function createNodeHmac(algorithm, keyBytes) {
397
+ const createHmac = NODE_CRYPTO?.createHmac;
398
+ if (typeof createHmac !== 'function')
399
+ return undefined;
400
+ try {
401
+ return createHmac(algorithm, keyBytes);
402
+ }
403
+ catch {
404
+ return undefined;
405
+ }
406
+ }
407
+ function digestWithNodeHash(algorithm, msg, enc) {
408
+ const hash = createNodeHash(algorithm);
409
+ if (hash == null)
410
+ return undefined;
411
+ hash.update(toHashBytes(msg, enc));
412
+ return hash.digest();
413
+ }
414
+ function digestWithNodeHmac(algorithm, key, msg, enc) {
415
+ const hmac = createNodeHmac(algorithm, toHashKeyBytes(key));
416
+ if (hmac == null)
417
+ return undefined;
418
+ hmac.update(toHashBytes(msg, enc));
419
+ return hmac.digest();
306
420
  }
307
421
  function join32(msg, start, end, endian) {
308
422
  const len = end - start;
@@ -551,19 +665,22 @@ export class RIPEMD160 extends BaseHash {
551
665
  */
552
666
  export class SHA256 {
553
667
  h;
668
+ native;
554
669
  constructor() {
555
- this.h = new FastSHA256();
670
+ this.native = createNodeHash('sha256');
671
+ if (this.native == null) {
672
+ this.h = new FastSHA256();
673
+ }
556
674
  }
557
675
  update(msg, enc) {
558
- const data = msg instanceof Uint8Array ? msg : Uint8Array.from(toArray(msg, enc));
559
- this.h.update(data);
676
+ updateNativeOrFallback(this.native, this.h, toHashBytes(msg, enc));
560
677
  return this;
561
678
  }
562
679
  digest() {
563
- return Array.from(this.h.digest());
680
+ return digestNativeOrFallback(this.native, this.h);
564
681
  }
565
682
  digestHex() {
566
- return bytesToHex(this.h.digest());
683
+ return digestHexNativeOrFallback(this.native, this.h);
567
684
  }
568
685
  }
569
686
  /**
@@ -614,7 +731,7 @@ export class SHA1 extends BaseHash {
614
731
  let d = this.h[3];
615
732
  let e = this.h[4];
616
733
  for (i = 0; i < W.length; i++) {
617
- const s = ~~(i / 20);
734
+ const s = Math.trunc(i / 20);
618
735
  const t = SUM32_5(rotl32(a, 5), FT_1(s, b, c, d), e, W[i], this.k[s]);
619
736
  e = d;
620
737
  d = c;
@@ -656,19 +773,22 @@ export class SHA1 extends BaseHash {
656
773
  */
657
774
  export class SHA512 {
658
775
  h;
776
+ native;
659
777
  constructor() {
660
- this.h = new FastSHA512();
778
+ this.native = createNodeHash('sha512');
779
+ if (this.native == null) {
780
+ this.h = new FastSHA512();
781
+ }
661
782
  }
662
783
  update(msg, enc) {
663
- const data = Uint8Array.from(toArray(msg, enc));
664
- this.h.update(data);
784
+ updateNativeOrFallback(this.native, this.h, toHashBytes(msg, enc));
665
785
  return this;
666
786
  }
667
787
  digest() {
668
- return Array.from(this.h.digest());
788
+ return digestNativeOrFallback(this.native, this.h);
669
789
  }
670
790
  digestHex() {
671
- return bytesToHex(this.h.digest());
791
+ return digestHexNativeOrFallback(this.native, this.h);
672
792
  }
673
793
  }
674
794
  /**
@@ -685,6 +805,7 @@ export class SHA512 {
685
805
  */
686
806
  export class SHA256HMAC {
687
807
  h;
808
+ native;
688
809
  blockSize = 64;
689
810
  outSize = 32;
690
811
  /**
@@ -701,10 +822,11 @@ export class SHA256HMAC {
701
822
  * const myHMAC = new SHA256HMAC('deadbeef');
702
823
  */
703
824
  constructor(key) {
704
- const k = key instanceof Uint8Array
705
- ? key
706
- : Uint8Array.from(toArray(key, typeof key === 'string' ? 'hex' : undefined));
707
- this.h = new HMAC(sha256Fast, k);
825
+ const k = toHashKeyBytes(key);
826
+ this.native = createNodeHmac('sha256', k);
827
+ if (this.native == null) {
828
+ this.h = new HMAC(sha256Fast, k);
829
+ }
708
830
  }
709
831
  /**
710
832
  * Updates the `SHA256HMAC` object with part of the message to be hashed.
@@ -718,8 +840,7 @@ export class SHA256HMAC {
718
840
  * myHMAC.update('deadbeef', 'hex');
719
841
  */
720
842
  update(msg, enc) {
721
- const data = msg instanceof Uint8Array ? msg : Uint8Array.from(toArray(msg, enc));
722
- this.h.update(data);
843
+ updateNativeOrFallback(this.native, this.h, toHashBytes(msg, enc));
723
844
  return this;
724
845
  }
725
846
  /**
@@ -732,7 +853,7 @@ export class SHA256HMAC {
732
853
  * let hashedMessage = myHMAC.digest();
733
854
  */
734
855
  digest() {
735
- return Array.from(this.h.digest());
856
+ return digestNativeOrFallback(this.native, this.h);
736
857
  }
737
858
  /**
738
859
  * Finalizes the HMAC computation and returns the resultant hash as a hex string.
@@ -744,7 +865,7 @@ export class SHA256HMAC {
744
865
  * let hashedMessage = myHMAC.digestHex();
745
866
  */
746
867
  digestHex() {
747
- return bytesToHex(this.h.digest());
868
+ return digestHexNativeOrFallback(this.native, this.h);
748
869
  }
749
870
  }
750
871
  export class SHA1HMAC {
@@ -799,6 +920,7 @@ export class SHA1HMAC {
799
920
  */
800
921
  export class SHA512HMAC {
801
922
  h;
923
+ native;
802
924
  blockSize = 128;
803
925
  outSize = 32;
804
926
  /**
@@ -815,10 +937,11 @@ export class SHA512HMAC {
815
937
  * const myHMAC = new SHA512HMAC('deadbeef');
816
938
  */
817
939
  constructor(key) {
818
- const k = key instanceof Uint8Array
819
- ? key
820
- : Uint8Array.from(toArray(key, typeof key === 'string' ? 'hex' : undefined));
821
- this.h = new HMAC(sha512Fast, k);
940
+ const k = toHashKeyBytes(key);
941
+ this.native = createNodeHmac('sha512', k);
942
+ if (this.native == null) {
943
+ this.h = new HMAC(sha512Fast, k);
944
+ }
822
945
  }
823
946
  /**
824
947
  * Updates the `SHA512HMAC` object with part of the message to be hashed.
@@ -832,8 +955,7 @@ export class SHA512HMAC {
832
955
  * myHMAC.update('deadbeef', 'hex');
833
956
  */
834
957
  update(msg, enc) {
835
- const data = msg instanceof Uint8Array ? msg : Uint8Array.from(toArray(msg, enc));
836
- this.h.update(data);
958
+ updateNativeOrFallback(this.native, this.h, toHashBytes(msg, enc));
837
959
  return this;
838
960
  }
839
961
  /**
@@ -846,7 +968,7 @@ export class SHA512HMAC {
846
968
  * let hashedMessage = myHMAC.digest();
847
969
  */
848
970
  digest() {
849
- return Array.from(this.h.digest());
971
+ return digestNativeOrFallback(this.native, this.h);
850
972
  }
851
973
  /**
852
974
  * Finalizes the HMAC computation and returns the resultant hash as a hex string.
@@ -858,9 +980,24 @@ export class SHA512HMAC {
858
980
  * let hashedMessage = myHMAC.digestHex();
859
981
  */
860
982
  digestHex() {
861
- return bytesToHex(this.h.digest());
983
+ return digestHexNativeOrFallback(this.native, this.h);
862
984
  }
863
985
  }
986
+ function sha256Bytes(msg, enc) {
987
+ const native = digestWithNodeHash('sha256', msg, enc);
988
+ if (native != null)
989
+ return native;
990
+ return new FastSHA256().update(toHashBytes(msg, enc)).digest();
991
+ }
992
+ function sha512Bytes(msg, enc) {
993
+ const native = digestWithNodeHash('sha512', msg, enc);
994
+ if (native != null)
995
+ return native;
996
+ return new FastSHA512().update(toHashBytes(msg, enc)).digest();
997
+ }
998
+ function ripemd160Bytes(msg, enc) {
999
+ return digestWithNodeHash('ripemd160', msg, enc);
1000
+ }
864
1001
  /**
865
1002
  * Computes RIPEMD160 hash of a given message.
866
1003
  * @function ripemd160
@@ -873,6 +1010,9 @@ export class SHA512HMAC {
873
1010
  * const digest = ripemd160('Hello, world!');
874
1011
  */
875
1012
  export const ripemd160 = (msg, enc) => {
1013
+ const native = ripemd160Bytes(msg, enc);
1014
+ if (native != null)
1015
+ return Array.from(native);
876
1016
  return new RIPEMD160().update(msg, enc).digest();
877
1017
  };
878
1018
  /**
@@ -901,7 +1041,7 @@ export const sha1 = (msg, enc) => {
901
1041
  * const digest = sha256('Hello, world!');
902
1042
  */
903
1043
  export const sha256 = (msg, enc) => {
904
- return new SHA256().update(msg, enc).digest();
1044
+ return Array.from(sha256Bytes(msg, enc));
905
1045
  };
906
1046
  /**
907
1047
  * Computes SHA512 hash of a given message.
@@ -915,7 +1055,7 @@ export const sha256 = (msg, enc) => {
915
1055
  * const digest = sha512('Hello, world!');
916
1056
  */
917
1057
  export const sha512 = (msg, enc) => {
918
- return new SHA512().update(msg, enc).digest();
1058
+ return Array.from(sha512Bytes(msg, enc));
919
1059
  };
920
1060
  /**
921
1061
  * Performs a 'double hash' using SHA256. This means the data is hashed twice
@@ -931,8 +1071,7 @@ export const sha512 = (msg, enc) => {
931
1071
  * const doubleHash = hash256('Hello, world!');
932
1072
  */
933
1073
  export const hash256 = (msg, enc) => {
934
- const first = new SHA256().update(msg, enc).digest();
935
- return new SHA256().update(first).digest();
1074
+ return Array.from(sha256Bytes(sha256Bytes(msg, enc)));
936
1075
  };
937
1076
  /**
938
1077
  * Computes SHA256 hash of a given message and then computes a RIPEMD160 hash of the result.
@@ -947,7 +1086,10 @@ export const hash256 = (msg, enc) => {
947
1086
  * const hash = hash160('Hello, world!');
948
1087
  */
949
1088
  export const hash160 = (msg, enc) => {
950
- const first = new SHA256().update(msg, enc).digest();
1089
+ const first = sha256Bytes(msg, enc);
1090
+ const native = ripemd160Bytes(first);
1091
+ if (native != null)
1092
+ return Array.from(native);
951
1093
  return new RIPEMD160().update(first).digest();
952
1094
  };
953
1095
  /**
@@ -963,6 +1105,9 @@ export const hash160 = (msg, enc) => {
963
1105
  * const digest = sha256hmac('deadbeef', 'ffff001d');
964
1106
  */
965
1107
  export const sha256hmac = (key, msg, enc) => {
1108
+ const native = digestWithNodeHmac('sha256', key, msg, enc);
1109
+ if (native != null)
1110
+ return Array.from(native);
966
1111
  return new SHA256HMAC(key).update(msg, enc).digest();
967
1112
  };
968
1113
  /**
@@ -978,6 +1123,9 @@ export const sha256hmac = (key, msg, enc) => {
978
1123
  * const digest = sha512hmac('deadbeef', 'ffff001d');
979
1124
  */
980
1125
  export const sha512hmac = (key, msg, enc) => {
1126
+ const native = digestWithNodeHmac('sha512', key, msg, enc);
1127
+ if (native != null)
1128
+ return Array.from(native);
981
1129
  return new SHA512HMAC(key).update(msg, enc).digest();
982
1130
  };
983
1131
  // BEGIN fast-pbkdf2 helpers
@@ -1000,7 +1148,7 @@ function abytes(b, ...lengths) {
1000
1148
  }
1001
1149
  function ahash(h) {
1002
1150
  if (typeof h !== 'function' || typeof h.create !== 'function') {
1003
- throw new Error('Hash should be wrapped by utils.createHasher');
1151
+ throw new TypeError('Hash should be wrapped by utils.createHasher');
1004
1152
  }
1005
1153
  anumber(h.outputLen);
1006
1154
  anumber(h.blockLen);
@@ -1020,8 +1168,8 @@ function aoutput(out, instance) {
1020
1168
  }
1021
1169
  }
1022
1170
  function clean(...arrays) {
1023
- for (let i = 0; i < arrays.length; i++)
1024
- arrays[i].fill(0);
1171
+ for (const arr of arrays)
1172
+ arr.fill(0);
1025
1173
  }
1026
1174
  function createView(arr) {
1027
1175
  return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
@@ -1059,6 +1207,7 @@ const _32n = BigInt(32);
1059
1207
  function fromBig(n, le = false) {
1060
1208
  if (le)
1061
1209
  return { h: Number(n & U32_MASK64), l: Number((n >> _32n) & U32_MASK64) };
1210
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1062
1211
  return { h: Number((n >> _32n) & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
1063
1212
  }
1064
1213
  function split(lst, le = false) {
@@ -1080,13 +1229,17 @@ const rotrBH = (h, l, s) => (h << (64 - s)) | (l >>> (s - 32));
1080
1229
  const rotrBL = (h, l, s) => (h >>> (s - 32)) | (l << (64 - s));
1081
1230
  function add(Ah, Al, Bh, Bl) {
1082
1231
  const l = (Al >>> 0) + (Bl >>> 0);
1232
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1083
1233
  return { h: (Ah + Bh + ((l / 2 ** 32) | 0)) | 0, l: l | 0 };
1084
1234
  }
1085
1235
  const add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
1236
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1086
1237
  const add3H = (low, Ah, Bh, Ch) => (Ah + Bh + Ch + ((low / 2 ** 32) | 0)) | 0;
1087
1238
  const add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
1239
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1088
1240
  const add4H = (low, Ah, Bh, Ch, Dh) => (Ah + Bh + Ch + Dh + ((low / 2 ** 32) | 0)) | 0;
1089
1241
  const add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
1242
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1090
1243
  const add5H = (low, Ah, Bh, Ch, Dh, Eh) => (Ah + Bh + Ch + Dh + Eh + ((low / 2 ** 32) | 0)) | 0;
1091
1244
  // _md helpers
1092
1245
  class HashMD extends Hash {
@@ -1217,13 +1370,21 @@ const K256 = Uint32Array.from([
1217
1370
  ]);
1218
1371
  const SHA256_W = new Uint32Array(64);
1219
1372
  class FastSHA256 extends HashMD {
1373
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1220
1374
  A = SHA256_IV[0] | 0;
1375
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1221
1376
  B = SHA256_IV[1] | 0;
1377
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1222
1378
  C = SHA256_IV[2] | 0;
1379
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1223
1380
  D = SHA256_IV[3] | 0;
1381
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1224
1382
  E = SHA256_IV[4] | 0;
1383
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1225
1384
  F = SHA256_IV[5] | 0;
1385
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1226
1386
  G = SHA256_IV[6] | 0;
1387
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1227
1388
  H = SHA256_IV[7] | 0;
1228
1389
  constructor(outputLen = 32) {
1229
1390
  super(64, outputLen, 8, false);
@@ -1233,13 +1394,21 @@ class FastSHA256 extends HashMD {
1233
1394
  return [A, B, C, D, E, F, G, H];
1234
1395
  }
1235
1396
  set(A, B, C, D, E, F, G, H) {
1397
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1236
1398
  this.A = A | 0;
1399
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1237
1400
  this.B = B | 0;
1401
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1238
1402
  this.C = C | 0;
1403
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1239
1404
  this.D = D | 0;
1405
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1240
1406
  this.E = E | 0;
1407
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1241
1408
  this.F = F | 0;
1409
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1242
1410
  this.G = G | 0;
1411
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1243
1412
  this.H = H | 0;
1244
1413
  }
1245
1414
  process(view, offset) {
@@ -1370,27 +1539,43 @@ const K512 = (() => split([
1370
1539
  '0x597f299cfc657e2a',
1371
1540
  '0x5fcb6fab3ad6faec',
1372
1541
  '0x6c44198c4a475817'
1373
- ].map((n) => BigInt(n))))();
1542
+ ].map(BigInt)))();
1374
1543
  const SHA512_Kh = (() => K512[0])();
1375
1544
  const SHA512_Kl = (() => K512[1])();
1376
1545
  const SHA512_W_H = new Uint32Array(80);
1377
1546
  const SHA512_W_L = new Uint32Array(80);
1378
1547
  class FastSHA512 extends HashMD {
1548
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1379
1549
  Ah = SHA512_IV[0] | 0;
1550
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1380
1551
  Al = SHA512_IV[1] | 0;
1552
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1381
1553
  Bh = SHA512_IV[2] | 0;
1554
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1382
1555
  Bl = SHA512_IV[3] | 0;
1556
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1383
1557
  Ch = SHA512_IV[4] | 0;
1558
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1384
1559
  Cl = SHA512_IV[5] | 0;
1560
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1385
1561
  Dh = SHA512_IV[6] | 0;
1562
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1386
1563
  Dl = SHA512_IV[7] | 0;
1564
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1387
1565
  Eh = SHA512_IV[8] | 0;
1566
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1388
1567
  El = SHA512_IV[9] | 0;
1568
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1389
1569
  Fh = SHA512_IV[10] | 0;
1570
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1390
1571
  Fl = SHA512_IV[11] | 0;
1572
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1391
1573
  Gh = SHA512_IV[12] | 0;
1574
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1392
1575
  Gl = SHA512_IV[13] | 0;
1576
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1393
1577
  Hh = SHA512_IV[14] | 0;
1578
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1394
1579
  Hl = SHA512_IV[15] | 0;
1395
1580
  constructor(outputLen = 64) {
1396
1581
  super(128, outputLen, 16, false);
@@ -1400,40 +1585,62 @@ class FastSHA512 extends HashMD {
1400
1585
  return [Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl];
1401
1586
  }
1402
1587
  set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl) {
1588
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1403
1589
  this.Ah = Ah | 0;
1590
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1404
1591
  this.Al = Al | 0;
1592
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1405
1593
  this.Bh = Bh | 0;
1594
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1406
1595
  this.Bl = Bl | 0;
1596
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1407
1597
  this.Ch = Ch | 0;
1598
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1408
1599
  this.Cl = Cl | 0;
1600
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1409
1601
  this.Dh = Dh | 0;
1602
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1410
1603
  this.Dl = Dl | 0;
1604
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1411
1605
  this.Eh = Eh | 0;
1606
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1412
1607
  this.El = El | 0;
1608
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1413
1609
  this.Fh = Fh | 0;
1610
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1414
1611
  this.Fl = Fl | 0;
1612
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1415
1613
  this.Gh = Gh | 0;
1614
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1416
1615
  this.Gl = Gl | 0;
1616
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1417
1617
  this.Hh = Hh | 0;
1618
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1418
1619
  this.Hl = Hl | 0;
1419
1620
  }
1420
1621
  process(view, offset) {
1421
- for (let i = 0; i < 16; i++, offset += 4) {
1622
+ for (let i = 0; i < 16; i++, offset += 8) {
1422
1623
  SHA512_W_H[i] = view.getUint32(offset);
1423
- SHA512_W_L[i] = view.getUint32((offset += 4));
1624
+ SHA512_W_L[i] = view.getUint32(offset + 4);
1424
1625
  }
1425
1626
  for (let i = 16; i < 80; i++) {
1627
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1426
1628
  const W15h = SHA512_W_H[i - 15] | 0;
1629
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1427
1630
  const W15l = SHA512_W_L[i - 15] | 0;
1428
1631
  const s0h = rotrSH(W15h, W15l, 1) ^ rotrSH(W15h, W15l, 8) ^ shrSH(W15h, W15l, 7);
1429
1632
  const s0l = rotrSL(W15h, W15l, 1) ^ rotrSL(W15h, W15l, 8) ^ shrSL(W15h, W15l, 7);
1633
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1430
1634
  const W2h = SHA512_W_H[i - 2] | 0;
1635
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1431
1636
  const W2l = SHA512_W_L[i - 2] | 0;
1432
1637
  const s1h = rotrSH(W2h, W2l, 19) ^ rotrBH(W2h, W2l, 61) ^ shrSH(W2h, W2l, 6);
1433
1638
  const s1l = rotrSL(W2h, W2l, 19) ^ rotrBL(W2h, W2l, 61) ^ shrSL(W2h, W2l, 6);
1434
1639
  const SUMl = add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16]);
1435
1640
  const SUMh = add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]);
1641
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1436
1642
  SHA512_W_H[i] = SUMh | 0;
1643
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1437
1644
  SHA512_W_L[i] = SUMl | 0;
1438
1645
  }
1439
1646
  let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
@@ -1444,26 +1651,40 @@ class FastSHA512 extends HashMD {
1444
1651
  const CHIl = (El & Fl) ^ (~El & Gl);
1445
1652
  const T1ll = add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);
1446
1653
  const T1h = add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);
1654
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1447
1655
  const T1l = T1ll | 0;
1448
1656
  const sigma0h = rotrSH(Ah, Al, 28) ^ rotrBH(Ah, Al, 34) ^ rotrBH(Ah, Al, 39);
1449
1657
  const sigma0l = rotrSL(Ah, Al, 28) ^ rotrBL(Ah, Al, 34) ^ rotrBL(Ah, Al, 39);
1450
1658
  const MAJh = (Ah & Bh) ^ (Ah & Ch) ^ (Bh & Ch);
1451
1659
  const MAJl = (Al & Bl) ^ (Al & Cl) ^ (Bl & Cl);
1660
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1452
1661
  Hh = Gh | 0;
1662
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1453
1663
  Hl = Gl | 0;
1664
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1454
1665
  Gh = Fh | 0;
1666
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1455
1667
  Gl = Fl | 0;
1668
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1456
1669
  Fh = Eh | 0;
1670
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1457
1671
  Fl = El | 0;
1458
1672
  ({ h: Eh, l: El } = add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
1673
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1459
1674
  Dh = Ch | 0;
1675
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1460
1676
  Dl = Cl | 0;
1677
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1461
1678
  Ch = Bh | 0;
1679
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1462
1680
  Cl = Bl | 0;
1681
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1463
1682
  Bh = Ah | 0;
1683
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1464
1684
  Bl = Al | 0;
1465
1685
  const T2l = add3L(sigma0l, MAJl, T1l);
1466
1686
  Ah = add3H(T2l, sigma0h, MAJh, T1h);
1687
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1467
1688
  Al = T2l | 0;
1468
1689
  }
1469
1690
  ;
@@ -1499,7 +1720,7 @@ class HMAC extends Hash {
1499
1720
  const key = toBytes(_key);
1500
1721
  this.iHash = hash.create();
1501
1722
  if (typeof this.iHash.update !== 'function') {
1502
- throw new Error('Expected instance of class which extends utils.Hash');
1723
+ throw new TypeError('Expected instance of class which extends utils.Hash');
1503
1724
  }
1504
1725
  this.blockLen = this.iHash.blockLen;
1505
1726
  this.outputLen = this.iHash.outputLen;
@@ -1574,7 +1795,8 @@ function pbkdf2Core(hash, password, salt, opts) {
1574
1795
  for (let ti = 1, pos = 0; pos < dkLen; ti++, pos += PRF.outputLen) {
1575
1796
  const Ti = DK.subarray(pos, pos + PRF.outputLen);
1576
1797
  view.setInt32(0, ti, false);
1577
- (prfW = PRFSalt._cloneInto(prfW)).update(arr).digestInto(u);
1798
+ prfW = PRFSalt._cloneInto(prfW);
1799
+ prfW.update(arr).digestInto(u);
1578
1800
  Ti.set(u.subarray(0, Ti.length));
1579
1801
  for (let ui = 1; ui < c; ui++) {
1580
1802
  PRF._cloneInto(prfW).update(u).digestInto(u);
@@ -1610,21 +1832,10 @@ export function pbkdf2(password, salt, iterations, keylen, digest = 'sha512') {
1610
1832
  if (digest !== 'sha512') {
1611
1833
  throw new Error('Only sha512 is supported in this PBKDF2 implementation');
1612
1834
  }
1613
- // Attempt to use the native Node.js implementation if available as it is
1614
- // considerably faster than the pure TypeScript fallback below. If the crypto
1615
- // module isn't present (for example in a browser build) we'll silently fall
1616
- // back to the original implementation.
1617
- try {
1618
- // eslint-disable-next-line @typescript-eslint/no-var-requires
1619
- const nodeCrypto = require('crypto');
1620
- if (typeof nodeCrypto.pbkdf2Sync === 'function') {
1621
- const p = Buffer.from(password);
1622
- const s = Buffer.from(salt);
1623
- return [...nodeCrypto.pbkdf2Sync(p, s, iterations, keylen, digest)];
1624
- }
1625
- }
1626
- catch {
1627
- // ignore
1835
+ const pbkdf2Sync = NODE_CRYPTO?.pbkdf2Sync;
1836
+ if (typeof pbkdf2Sync === 'function') {
1837
+ const out = pbkdf2Sync(toHashBytes(password), toHashBytes(salt), iterations, keylen, digest);
1838
+ return Array.from(out);
1628
1839
  }
1629
1840
  const p = Uint8Array.from(password);
1630
1841
  const s = Uint8Array.from(salt);