@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
@@ -223,6 +223,68 @@ function isSurrogatePair (msg: string, i: number): boolean {
223
223
  return (msg.charCodeAt(i + 1) & 0xfc00) === 0xdc00
224
224
  }
225
225
 
226
+ /**
227
+ * Encode a single UTF-16 code unit (and possibly its surrogate partner)
228
+ * into UTF-8 bytes, appending them to `out`.
229
+ *
230
+ * Returns the index of the last consumed code unit so the caller can
231
+ * advance its loop variable when a surrogate pair is consumed.
232
+ *
233
+ * Inspired by stringToUtf8ByteArray() in closure-library by Google
234
+ * https://github.com/google/closure-library/blob/8598d87242af59aac233270742c8984e2b2bdbe0/closure/goog/crypt/crypt#L117-L143
235
+ * Apache License 2.0
236
+ * https://github.com/google/closure-library/blob/master/LICENSE
237
+ */
238
+ function appendUtf8CodeUnit (msg: string, i: number, out: number[]): number {
239
+ let c = msg.charCodeAt(i)
240
+ if (c < 128) {
241
+ out.push(c)
242
+ return i
243
+ }
244
+ if (c < 2048) {
245
+ out.push((c >> 6) | 192, (c & 63) | 128)
246
+ return i
247
+ }
248
+ if (isSurrogatePair(msg, i)) {
249
+ c = 0x10000 + ((c & 0x03ff) << 10) + (msg.charCodeAt(i + 1) & 0x03ff)
250
+ out.push(
251
+ (c >> 18) | 240,
252
+ ((c >> 12) & 63) | 128,
253
+ ((c >> 6) & 63) | 128,
254
+ (c & 63) | 128
255
+ )
256
+ return i + 1
257
+ }
258
+ out.push((c >> 12) | 224, ((c >> 6) & 63) | 128, (c & 63) | 128)
259
+ return i
260
+ }
261
+
262
+ function utf8StringToArray (msg: string): number[] {
263
+ const res: number[] = []
264
+ for (let i = 0; i < msg.length; i++) {
265
+ i = appendUtf8CodeUnit(msg, i, res)
266
+ }
267
+ return res
268
+ }
269
+
270
+ function hexStringToArray (msg: string): number[] {
271
+ assertValidHex(msg)
272
+ const normalized = normalizeHex(msg)
273
+ const res: number[] = []
274
+ for (let i = 0; i < normalized.length; i += 2) {
275
+ res.push(Number.parseInt(normalized[i] + normalized[i + 1], 16))
276
+ }
277
+ return res
278
+ }
279
+
280
+ function numberArrayToByteArray (msg: number[]): number[] {
281
+ const res: number[] = []
282
+ for (let i = 0; i < msg.length; i++) {
283
+ res[i] = Math.trunc(msg[i])
284
+ }
285
+ return res
286
+ }
287
+
226
288
  /**
227
289
  *
228
290
  * @param msg
@@ -239,47 +301,10 @@ export function toArray (
239
301
  if (!(msg as unknown as boolean)) {
240
302
  return []
241
303
  }
242
- const res: number[] = []
243
304
  if (typeof msg === 'string') {
244
- if (enc !== 'hex') {
245
- // Inspired by stringToUtf8ByteArray() in closure-library by Google
246
- // https://github.com/google/closure-library/blob/8598d87242af59aac233270742c8984e2b2bdbe0/closure/goog/crypt/crypt#L117-L143
247
- // Apache License 2.0
248
- // https://github.com/google/closure-library/blob/master/LICENSE
249
- let p = 0
250
- for (let i = 0; i < msg.length; i++) {
251
- let c = msg.charCodeAt(i)
252
- if (c < 128) {
253
- res[p++] = c
254
- } else if (c < 2048) {
255
- res[p++] = (c >> 6) | 192
256
- res[p++] = (c & 63) | 128
257
- } else if (isSurrogatePair(msg, i)) {
258
- c = 0x10000 + ((c & 0x03ff) << 10) + (msg.charCodeAt(++i) & 0x03ff)
259
- res[p++] = (c >> 18) | 240
260
- res[p++] = ((c >> 12) & 63) | 128
261
- res[p++] = ((c >> 6) & 63) | 128
262
- res[p++] = (c & 63) | 128
263
- } else {
264
- res[p++] = (c >> 12) | 224
265
- res[p++] = ((c >> 6) & 63) | 128
266
- res[p++] = (c & 63) | 128
267
- }
268
- }
269
- } else {
270
- assertValidHex(msg)
271
- msg = normalizeHex(msg)
272
- for (let i = 0; i < msg.length; i += 2) {
273
- res.push(parseInt(msg[i] + msg[i + 1], 16))
274
- }
275
- }
276
- } else {
277
- msg = msg as number[]
278
- for (let i = 0; i < msg.length; i++) {
279
- res[i] = msg[i] | 0
280
- }
305
+ return enc === 'hex' ? hexStringToArray(msg) : utf8StringToArray(msg)
281
306
  }
282
- return res
307
+ return numberArrayToByteArray(msg as number[])
283
308
  }
284
309
 
285
310
  /**
@@ -295,8 +320,7 @@ export function htonl (w: number): number {
295
320
 
296
321
  function toHex32 (msg: number[], endian?: 'little' | 'big'): string {
297
322
  let res = ''
298
- for (let i = 0; i < msg.length; i++) {
299
- let w = msg[i]
323
+ for (let w of msg) {
300
324
  if (endian === 'little') {
301
325
  w = htonl(w)
302
326
  }
@@ -325,10 +349,141 @@ function zero8 (word: string): string {
325
349
  }
326
350
  }
327
351
 
352
+ const BufferCtor =
353
+ typeof globalThis === 'undefined' ? undefined : (globalThis as any).Buffer
354
+ const CAN_USE_BUFFER =
355
+ BufferCtor != null && typeof BufferCtor.from === 'function'
356
+ const HEX_DIGITS = '0123456789abcdef'
357
+ const HEX_BYTE_STRINGS = new Array<string>(256)
358
+ for (let i = 0; i < HEX_BYTE_STRINGS.length; i++) {
359
+ HEX_BYTE_STRINGS[i] = HEX_DIGITS[(i >> 4) & 0xf] + HEX_DIGITS[i & 0xf]
360
+ }
361
+
328
362
  function bytesToHex (data: Uint8Array): string {
329
- let res = ''
330
- for (const b of data) res += (b.toString(16).padStart(2, '0'))
331
- return res
363
+ if (CAN_USE_BUFFER) {
364
+ return BufferCtor.from(data).toString('hex')
365
+ }
366
+ const out = new Array<string>(data.length)
367
+ for (let i = 0; i < data.length; i++) out[i] = HEX_BYTE_STRINGS[data[i]]
368
+ return out.join('')
369
+ }
370
+
371
+ const NODE_CRYPTO = (() => {
372
+ const processLike =
373
+ typeof globalThis === 'undefined' ? undefined : (globalThis as any).process
374
+ const getBuiltinModule = processLike?.getBuiltinModule
375
+ if (typeof getBuiltinModule === 'function') {
376
+ try {
377
+ const crypto = getBuiltinModule.call(processLike, 'node:crypto')
378
+ if (crypto != null) return crypto
379
+ } catch {
380
+ // continue to CommonJS fallback
381
+ }
382
+ }
383
+
384
+ try {
385
+ if (typeof require === 'function') {
386
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
387
+ return require('node:crypto')
388
+ }
389
+ } catch {
390
+ // node:crypto is unavailable in this runtime
391
+ }
392
+ return undefined
393
+ })()
394
+
395
+ type HashInput = Uint8Array | number[] | string
396
+
397
+ function toHashBytes (msg: HashInput, enc?: 'hex' | 'utf8'): Uint8Array {
398
+ if (msg instanceof Uint8Array) {
399
+ return msg
400
+ }
401
+ if (Array.isArray(msg)) {
402
+ return new Uint8Array(msg)
403
+ }
404
+ return Uint8Array.from(toArray(msg, enc))
405
+ }
406
+
407
+ function toHashKeyBytes (key: HashInput): Uint8Array {
408
+ return typeof key === 'string' ? toHashBytes(key, 'hex') : toHashBytes(key)
409
+ }
410
+
411
+ interface FallbackHashLike {
412
+ update: (data: Uint8Array) => unknown
413
+ digest: () => Uint8Array
414
+ }
415
+
416
+ function updateNativeOrFallback (
417
+ native: any,
418
+ fallback: FallbackHashLike | undefined,
419
+ data: Uint8Array
420
+ ): void {
421
+ if (native != null) {
422
+ native.update(data)
423
+ } else if (fallback != null) {
424
+ fallback.update(data)
425
+ }
426
+ }
427
+
428
+ function digestNativeOrFallback (
429
+ native: any,
430
+ fallback: FallbackHashLike | undefined
431
+ ): number[] {
432
+ if (native != null) return Array.from(native.digest())
433
+ if (fallback != null) return Array.from(fallback.digest())
434
+ return []
435
+ }
436
+
437
+ function digestHexNativeOrFallback (
438
+ native: any,
439
+ fallback: FallbackHashLike | undefined
440
+ ): string {
441
+ if (native != null) return native.digest('hex')
442
+ if (fallback != null) return bytesToHex(fallback.digest())
443
+ return ''
444
+ }
445
+
446
+ function createNodeHash (algorithm: string): any {
447
+ const createHash = NODE_CRYPTO?.createHash
448
+ if (typeof createHash !== 'function') return undefined
449
+ try {
450
+ return createHash(algorithm)
451
+ } catch {
452
+ return undefined
453
+ }
454
+ }
455
+
456
+ function createNodeHmac (algorithm: string, keyBytes: Uint8Array): any {
457
+ const createHmac = NODE_CRYPTO?.createHmac
458
+ if (typeof createHmac !== 'function') return undefined
459
+ try {
460
+ return createHmac(algorithm, keyBytes)
461
+ } catch {
462
+ return undefined
463
+ }
464
+ }
465
+
466
+ function digestWithNodeHash (
467
+ algorithm: string,
468
+ msg: HashInput,
469
+ enc?: 'hex' | 'utf8'
470
+ ): Uint8Array | undefined {
471
+ const hash = createNodeHash(algorithm)
472
+ if (hash == null) return undefined
473
+ hash.update(toHashBytes(msg, enc))
474
+ return hash.digest()
475
+ }
476
+
477
+ function digestWithNodeHmac (
478
+ algorithm: string,
479
+ key: HashInput,
480
+ msg: HashInput,
481
+ enc?: 'hex' | 'utf8'
482
+ ): Uint8Array | undefined {
483
+ const hmac = createNodeHmac(algorithm, toHashKeyBytes(key))
484
+ if (hmac == null) return undefined
485
+ hmac.update(toHashBytes(msg, enc))
486
+ return hmac.digest()
332
487
  }
333
488
 
334
489
  function join32 (msg, start, end, endian): number[] {
@@ -607,27 +762,27 @@ export class RIPEMD160 extends BaseHash {
607
762
  * @property k - The round constants used for each round of SHA-256
608
763
  */
609
764
  export class SHA256 {
610
- private readonly h: FastSHA256
765
+ private readonly h?: FastSHA256
766
+ private readonly native?: any
767
+
611
768
  constructor () {
612
- this.h = new FastSHA256()
769
+ this.native = createNodeHash('sha256')
770
+ if (this.native == null) {
771
+ this.h = new FastSHA256()
772
+ }
613
773
  }
614
774
 
615
- update (
616
- msg: Uint8Array | number[] | string,
617
- enc?: 'hex' | 'utf8'
618
- ): this {
619
- const data =
620
- msg instanceof Uint8Array ? msg : Uint8Array.from(toArray(msg, enc))
621
- this.h.update(data)
775
+ update (msg: HashInput, enc?: 'hex' | 'utf8'): this {
776
+ updateNativeOrFallback(this.native, this.h, toHashBytes(msg, enc))
622
777
  return this
623
778
  }
624
779
 
625
780
  digest (): number[] {
626
- return Array.from(this.h.digest())
781
+ return digestNativeOrFallback(this.native, this.h)
627
782
  }
628
783
 
629
784
  digestHex (): string {
630
- return bytesToHex(this.h.digest())
785
+ return digestHexNativeOrFallback(this.native, this.h)
631
786
  }
632
787
  }
633
788
 
@@ -686,7 +841,7 @@ export class SHA1 extends BaseHash {
686
841
  let e = this.h[4]
687
842
 
688
843
  for (i = 0; i < W.length; i++) {
689
- const s = ~~(i / 20)
844
+ const s = Math.trunc(i / 20)
690
845
  const t = SUM32_5(rotl32(a, 5), FT_1(s, b, c, d), e, W[i], this.k[s])
691
846
  e = d
692
847
  d = c
@@ -731,23 +886,27 @@ export class SHA1 extends BaseHash {
731
886
  * @property k - The round constants used for each round of SHA-512.
732
887
  */
733
888
  export class SHA512 {
734
- private readonly h: FastSHA512
889
+ private readonly h?: FastSHA512
890
+ private readonly native?: any
891
+
735
892
  constructor () {
736
- this.h = new FastSHA512()
893
+ this.native = createNodeHash('sha512')
894
+ if (this.native == null) {
895
+ this.h = new FastSHA512()
896
+ }
737
897
  }
738
898
 
739
- update (msg: number[] | string, enc?: 'hex' | 'utf8'): this {
740
- const data = Uint8Array.from(toArray(msg, enc))
741
- this.h.update(data)
899
+ update (msg: HashInput, enc?: 'hex' | 'utf8'): this {
900
+ updateNativeOrFallback(this.native, this.h, toHashBytes(msg, enc))
742
901
  return this
743
902
  }
744
903
 
745
904
  digest (): number[] {
746
- return Array.from(this.h.digest())
905
+ return digestNativeOrFallback(this.native, this.h)
747
906
  }
748
907
 
749
908
  digestHex (): string {
750
- return bytesToHex(this.h.digest())
909
+ return digestHexNativeOrFallback(this.native, this.h)
751
910
  }
752
911
  }
753
912
 
@@ -764,7 +923,8 @@ export class SHA512 {
764
923
  * @property outSize - The output size of the SHA-256 hash function, in bytes. It's set to 32 bytes.
765
924
  */
766
925
  export class SHA256HMAC {
767
- private readonly h: HMAC<FastSHA256>
926
+ private readonly h?: HMAC<FastSHA256>
927
+ private readonly native?: any
768
928
  blockSize = 64
769
929
  outSize = 32
770
930
 
@@ -781,17 +941,12 @@ export class SHA256HMAC {
781
941
  * @example
782
942
  * const myHMAC = new SHA256HMAC('deadbeef');
783
943
  */
784
- constructor (key: Uint8Array | number[] | string) {
785
- const k =
786
- key instanceof Uint8Array
787
- ? key
788
- : Uint8Array.from(
789
- toArray(
790
- key,
791
- typeof key === 'string' ? 'hex' : undefined
792
- )
793
- )
794
- this.h = new HMAC(sha256Fast, k)
944
+ constructor (key: HashInput) {
945
+ const k = toHashKeyBytes(key)
946
+ this.native = createNodeHmac('sha256', k)
947
+ if (this.native == null) {
948
+ this.h = new HMAC(sha256Fast, k)
949
+ }
795
950
  }
796
951
 
797
952
  /**
@@ -805,10 +960,8 @@ export class SHA256HMAC {
805
960
  * @example
806
961
  * myHMAC.update('deadbeef', 'hex');
807
962
  */
808
- update (msg: Uint8Array | number[] | string, enc?: 'hex'): SHA256HMAC {
809
- const data =
810
- msg instanceof Uint8Array ? msg : Uint8Array.from(toArray(msg, enc))
811
- this.h.update(data)
963
+ update (msg: HashInput, enc?: 'hex'): this {
964
+ updateNativeOrFallback(this.native, this.h, toHashBytes(msg, enc))
812
965
  return this
813
966
  }
814
967
 
@@ -822,7 +975,7 @@ export class SHA256HMAC {
822
975
  * let hashedMessage = myHMAC.digest();
823
976
  */
824
977
  digest (): number[] {
825
- return Array.from(this.h.digest())
978
+ return digestNativeOrFallback(this.native, this.h)
826
979
  }
827
980
 
828
981
  /**
@@ -835,7 +988,7 @@ export class SHA256HMAC {
835
988
  * let hashedMessage = myHMAC.digestHex();
836
989
  */
837
990
  digestHex (): string {
838
- return bytesToHex(this.h.digest())
991
+ return digestHexNativeOrFallback(this.native, this.h)
839
992
  }
840
993
  }
841
994
 
@@ -869,7 +1022,7 @@ export class SHA1HMAC {
869
1022
  this.outer = new SHA1().update(key)
870
1023
  }
871
1024
 
872
- update (msg: number[] | string, enc?: 'hex'): SHA1HMAC {
1025
+ update (msg: number[] | string, enc?: 'hex'): this {
873
1026
  this.inner.update(msg, enc)
874
1027
  return this
875
1028
  }
@@ -898,7 +1051,8 @@ export class SHA1HMAC {
898
1051
  * @property outSize - The output size of the SHA-512 hash function, in bytes. It's set to 64 bytes.
899
1052
  */
900
1053
  export class SHA512HMAC {
901
- private readonly h: HMAC<FastSHA512>
1054
+ private readonly h?: HMAC<FastSHA512>
1055
+ private readonly native?: any
902
1056
  blockSize = 128
903
1057
  outSize = 32
904
1058
 
@@ -915,17 +1069,12 @@ export class SHA512HMAC {
915
1069
  * @example
916
1070
  * const myHMAC = new SHA512HMAC('deadbeef');
917
1071
  */
918
- constructor (key: Uint8Array | number[] | string) {
919
- const k =
920
- key instanceof Uint8Array
921
- ? key
922
- : Uint8Array.from(
923
- toArray(
924
- key,
925
- typeof key === 'string' ? 'hex' : undefined
926
- )
927
- )
928
- this.h = new HMAC(sha512Fast, k)
1072
+ constructor (key: HashInput) {
1073
+ const k = toHashKeyBytes(key)
1074
+ this.native = createNodeHmac('sha512', k)
1075
+ if (this.native == null) {
1076
+ this.h = new HMAC(sha512Fast, k)
1077
+ }
929
1078
  }
930
1079
 
931
1080
  /**
@@ -939,10 +1088,8 @@ export class SHA512HMAC {
939
1088
  * @example
940
1089
  * myHMAC.update('deadbeef', 'hex');
941
1090
  */
942
- update (msg: Uint8Array | number[] | string, enc?: 'hex' | 'utf8'): SHA512HMAC {
943
- const data =
944
- msg instanceof Uint8Array ? msg : Uint8Array.from(toArray(msg, enc))
945
- this.h.update(data)
1091
+ update (msg: HashInput, enc?: 'hex' | 'utf8'): this {
1092
+ updateNativeOrFallback(this.native, this.h, toHashBytes(msg, enc))
946
1093
  return this
947
1094
  }
948
1095
 
@@ -956,7 +1103,7 @@ export class SHA512HMAC {
956
1103
  * let hashedMessage = myHMAC.digest();
957
1104
  */
958
1105
  digest (): number[] {
959
- return Array.from(this.h.digest())
1106
+ return digestNativeOrFallback(this.native, this.h)
960
1107
  }
961
1108
 
962
1109
  /**
@@ -969,10 +1116,32 @@ export class SHA512HMAC {
969
1116
  * let hashedMessage = myHMAC.digestHex();
970
1117
  */
971
1118
  digestHex (): string {
972
- return bytesToHex(this.h.digest())
1119
+ return digestHexNativeOrFallback(this.native, this.h)
973
1120
  }
974
1121
  }
975
1122
 
1123
+ function sha256Bytes (msg: HashInput, enc?: 'hex' | 'utf8'): Uint8Array {
1124
+ const native = digestWithNodeHash('sha256', msg, enc)
1125
+ if (native != null) return native
1126
+ return new FastSHA256().update(toHashBytes(msg, enc)).digest()
1127
+ }
1128
+
1129
+ function sha512Bytes (
1130
+ msg: HashInput,
1131
+ enc?: 'hex' | 'utf8'
1132
+ ): Uint8Array {
1133
+ const native = digestWithNodeHash('sha512', msg, enc)
1134
+ if (native != null) return native
1135
+ return new FastSHA512().update(toHashBytes(msg, enc)).digest()
1136
+ }
1137
+
1138
+ function ripemd160Bytes (
1139
+ msg: HashInput,
1140
+ enc?: 'hex' | 'utf8'
1141
+ ): Uint8Array | undefined {
1142
+ return digestWithNodeHash('ripemd160', msg, enc)
1143
+ }
1144
+
976
1145
  /**
977
1146
  * Computes RIPEMD160 hash of a given message.
978
1147
  * @function ripemd160
@@ -988,6 +1157,8 @@ export const ripemd160 = (
988
1157
  msg: number[] | string,
989
1158
  enc?: 'hex' | 'utf8'
990
1159
  ): number[] => {
1160
+ const native = ripemd160Bytes(msg, enc)
1161
+ if (native != null) return Array.from(native)
991
1162
  return new RIPEMD160().update(msg, enc).digest()
992
1163
  }
993
1164
 
@@ -1020,11 +1191,8 @@ export const sha1 = (
1020
1191
  * @example
1021
1192
  * const digest = sha256('Hello, world!');
1022
1193
  */
1023
- export const sha256 = (
1024
- msg: Uint8Array | number[] | string,
1025
- enc?: 'hex' | 'utf8'
1026
- ): number[] => {
1027
- return new SHA256().update(msg, enc).digest()
1194
+ export const sha256 = (msg: HashInput, enc?: 'hex' | 'utf8'): number[] => {
1195
+ return Array.from(sha256Bytes(msg, enc))
1028
1196
  }
1029
1197
 
1030
1198
  /**
@@ -1038,11 +1206,8 @@ export const sha256 = (
1038
1206
  * @example
1039
1207
  * const digest = sha512('Hello, world!');
1040
1208
  */
1041
- export const sha512 = (
1042
- msg: number[] | string,
1043
- enc?: 'hex' | 'utf8'
1044
- ): number[] => {
1045
- return new SHA512().update(msg, enc).digest()
1209
+ export const sha512 = (msg: HashInput, enc?: 'hex' | 'utf8'): number[] => {
1210
+ return Array.from(sha512Bytes(msg, enc))
1046
1211
  }
1047
1212
 
1048
1213
  /**
@@ -1058,12 +1223,8 @@ export const sha512 = (
1058
1223
  * @example
1059
1224
  * const doubleHash = hash256('Hello, world!');
1060
1225
  */
1061
- export const hash256 = (
1062
- msg: Uint8Array | number[] | string,
1063
- enc?: 'hex' | 'utf8'
1064
- ): number[] => {
1065
- const first = new SHA256().update(msg, enc).digest()
1066
- return new SHA256().update(first).digest()
1226
+ export const hash256 = (msg: HashInput, enc?: 'hex' | 'utf8'): number[] => {
1227
+ return Array.from(sha256Bytes(sha256Bytes(msg, enc)))
1067
1228
  }
1068
1229
 
1069
1230
  /**
@@ -1078,11 +1239,10 @@ export const hash256 = (
1078
1239
  * @example
1079
1240
  * const hash = hash160('Hello, world!');
1080
1241
  */
1081
- export const hash160 = (
1082
- msg: Uint8Array | number[] | string,
1083
- enc?: 'hex' | 'utf8'
1084
- ): number[] => {
1085
- const first = new SHA256().update(msg, enc).digest()
1242
+ export const hash160 = (msg: HashInput, enc?: 'hex' | 'utf8'): number[] => {
1243
+ const first = sha256Bytes(msg, enc)
1244
+ const native = ripemd160Bytes(first)
1245
+ if (native != null) return Array.from(native)
1086
1246
  return new RIPEMD160().update(first).digest()
1087
1247
  }
1088
1248
 
@@ -1099,10 +1259,12 @@ export const hash160 = (
1099
1259
  * const digest = sha256hmac('deadbeef', 'ffff001d');
1100
1260
  */
1101
1261
  export const sha256hmac = (
1102
- key: Uint8Array | number[] | string,
1103
- msg: Uint8Array | number[] | string,
1262
+ key: HashInput,
1263
+ msg: HashInput,
1104
1264
  enc?: 'hex'
1105
1265
  ): number[] => {
1266
+ const native = digestWithNodeHmac('sha256', key, msg, enc)
1267
+ if (native != null) return Array.from(native)
1106
1268
  return new SHA256HMAC(key).update(msg, enc).digest()
1107
1269
  }
1108
1270
 
@@ -1119,10 +1281,12 @@ export const sha256hmac = (
1119
1281
  * const digest = sha512hmac('deadbeef', 'ffff001d');
1120
1282
  */
1121
1283
  export const sha512hmac = (
1122
- key: Uint8Array | number[] | string,
1123
- msg: Uint8Array | number[] | string,
1284
+ key: HashInput,
1285
+ msg: HashInput,
1124
1286
  enc?: 'hex'
1125
1287
  ): number[] => {
1288
+ const native = digestWithNodeHmac('sha512', key, msg, enc)
1289
+ if (native != null) return Array.from(native)
1126
1290
  return new SHA512HMAC(key).update(msg, enc).digest()
1127
1291
  }
1128
1292
 
@@ -1144,7 +1308,7 @@ function abytes (b: Uint8Array | undefined, ...lengths: number[]): void {
1144
1308
  }
1145
1309
  }
1146
1310
  function ahash (h: IHash): void {
1147
- if (typeof h !== 'function' || typeof h.create !== 'function') { throw new Error('Hash should be wrapped by utils.createHasher') }
1311
+ if (typeof h !== 'function' || typeof h.create !== 'function') { throw new TypeError('Hash should be wrapped by utils.createHasher') }
1148
1312
  anumber(h.outputLen)
1149
1313
  anumber(h.blockLen)
1150
1314
  }
@@ -1171,7 +1335,7 @@ type TypedArray =
1171
1335
  | Int32Array
1172
1336
 
1173
1337
  function clean (...arrays: TypedArray[]): void {
1174
- for (let i = 0; i < arrays.length; i++) arrays[i].fill(0)
1338
+ for (const arr of arrays) arr.fill(0)
1175
1339
  }
1176
1340
  function createView (arr: TypedArray): DataView {
1177
1341
  return new DataView(arr.buffer, arr.byteOffset, arr.byteLength)
@@ -1229,6 +1393,7 @@ const U32_MASK64 = BigInt(2 ** 32 - 1)
1229
1393
  const _32n = BigInt(32)
1230
1394
  function fromBig (n: bigint, le = false): { h: number, l: number } {
1231
1395
  if (le) return { h: Number(n & U32_MASK64), l: Number((n >> _32n) & U32_MASK64) }
1396
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1232
1397
  return { h: Number((n >> _32n) & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 }
1233
1398
  }
1234
1399
  function split (lst: bigint[], le = false): Uint32Array[] {
@@ -1250,14 +1415,18 @@ const rotrBH = (h: number, l: number, s: number): number => (h << (64 - s)) | (l
1250
1415
  const rotrBL = (h: number, l: number, s: number): number => (h >>> (s - 32)) | (l << (64 - s))
1251
1416
  function add (Ah: number, Al: number, Bh: number, Bl: number): { h: number, l: number } {
1252
1417
  const l = (Al >>> 0) + (Bl >>> 0)
1418
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1253
1419
  return { h: (Ah + Bh + ((l / 2 ** 32) | 0)) | 0, l: l | 0 }
1254
1420
  }
1255
1421
  const add3L = (Al: number, Bl: number, Cl: number): number => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0)
1422
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1256
1423
  const add3H = (low: number, Ah: number, Bh: number, Ch: number): number => (Ah + Bh + Ch + ((low / 2 ** 32) | 0)) | 0
1257
1424
  const add4L = (Al: number, Bl: number, Cl: number, Dl: number): number => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0)
1425
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1258
1426
  const add4H = (low: number, Ah: number, Bh: number, Ch: number, Dh: number): number => (Ah + Bh + Ch + Dh + ((low / 2 ** 32) | 0)) | 0
1259
1427
  const add5L = (Al: number, Bl: number, Cl: number, Dl: number, El: number): number =>
1260
1428
  (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0)
1429
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1261
1430
  const add5H = (low: number, Ah: number, Bh: number, Ch: number, Dh: number, Eh: number): number =>
1262
1431
  (Ah + Bh + Ch + Dh + Eh + ((low / 2 ** 32) | 0)) | 0
1263
1432
 
@@ -1395,13 +1564,21 @@ const K256 = Uint32Array.from([
1395
1564
  const SHA256_W = new Uint32Array(64)
1396
1565
 
1397
1566
  class FastSHA256 extends HashMD<FastSHA256> {
1567
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1398
1568
  protected A = SHA256_IV[0] | 0
1569
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1399
1570
  protected B = SHA256_IV[1] | 0
1571
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1400
1572
  protected C = SHA256_IV[2] | 0
1573
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1401
1574
  protected D = SHA256_IV[3] | 0
1575
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1402
1576
  protected E = SHA256_IV[4] | 0
1577
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1403
1578
  protected F = SHA256_IV[5] | 0
1579
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1404
1580
  protected G = SHA256_IV[6] | 0
1581
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1405
1582
  protected H = SHA256_IV[7] | 0
1406
1583
  constructor (outputLen = 32) {
1407
1584
  super(64, outputLen, 8, false)
@@ -1422,13 +1599,21 @@ class FastSHA256 extends HashMD<FastSHA256> {
1422
1599
  G: number,
1423
1600
  H: number
1424
1601
  ): void {
1602
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1425
1603
  this.A = A | 0
1604
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1426
1605
  this.B = B | 0
1606
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1427
1607
  this.C = C | 0
1608
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1428
1609
  this.D = D | 0
1610
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1429
1611
  this.E = E | 0
1612
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1430
1613
  this.F = F | 0
1614
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1431
1615
  this.G = G | 0
1616
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1432
1617
  this.H = H | 0
1433
1618
  }
1434
1619
 
@@ -1565,7 +1750,7 @@ const K512 = (() =>
1565
1750
  '0x597f299cfc657e2a',
1566
1751
  '0x5fcb6fab3ad6faec',
1567
1752
  '0x6c44198c4a475817'
1568
- ].map((n) => BigInt(n)))
1753
+ ].map(BigInt))
1569
1754
  )()
1570
1755
  const SHA512_Kh = (() => K512[0])()
1571
1756
  const SHA512_Kl = (() => K512[1])()
@@ -1573,21 +1758,37 @@ const SHA512_W_H = new Uint32Array(80)
1573
1758
  const SHA512_W_L = new Uint32Array(80)
1574
1759
 
1575
1760
  class FastSHA512 extends HashMD<FastSHA512> {
1761
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1576
1762
  protected Ah = SHA512_IV[0] | 0
1763
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1577
1764
  protected Al = SHA512_IV[1] | 0
1765
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1578
1766
  protected Bh = SHA512_IV[2] | 0
1767
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1579
1768
  protected Bl = SHA512_IV[3] | 0
1769
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1580
1770
  protected Ch = SHA512_IV[4] | 0
1771
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1581
1772
  protected Cl = SHA512_IV[5] | 0
1773
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1582
1774
  protected Dh = SHA512_IV[6] | 0
1775
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1583
1776
  protected Dl = SHA512_IV[7] | 0
1777
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1584
1778
  protected Eh = SHA512_IV[8] | 0
1779
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1585
1780
  protected El = SHA512_IV[9] | 0
1781
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1586
1782
  protected Fh = SHA512_IV[10] | 0
1783
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1587
1784
  protected Fl = SHA512_IV[11] | 0
1785
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1588
1786
  protected Gh = SHA512_IV[12] | 0
1787
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1589
1788
  protected Gl = SHA512_IV[13] | 0
1789
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1590
1790
  protected Hh = SHA512_IV[14] | 0
1791
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1591
1792
  protected Hl = SHA512_IV[15] | 0
1592
1793
  constructor (outputLen = 64) {
1593
1794
  super(128, outputLen, 16, false)
@@ -1616,41 +1817,63 @@ class FastSHA512 extends HashMD<FastSHA512> {
1616
1817
  Hh: number,
1617
1818
  Hl: number
1618
1819
  ): void {
1820
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1619
1821
  this.Ah = Ah | 0
1822
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1620
1823
  this.Al = Al | 0
1824
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1621
1825
  this.Bh = Bh | 0
1826
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1622
1827
  this.Bl = Bl | 0
1828
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1623
1829
  this.Ch = Ch | 0
1830
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1624
1831
  this.Cl = Cl | 0
1832
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1625
1833
  this.Dh = Dh | 0
1834
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1626
1835
  this.Dl = Dl | 0
1836
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1627
1837
  this.Eh = Eh | 0
1838
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1628
1839
  this.El = El | 0
1840
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1629
1841
  this.Fh = Fh | 0
1842
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1630
1843
  this.Fl = Fl | 0
1844
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1631
1845
  this.Gh = Gh | 0
1846
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1632
1847
  this.Gl = Gl | 0
1848
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1633
1849
  this.Hh = Hh | 0
1850
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1634
1851
  this.Hl = Hl | 0
1635
1852
  }
1636
1853
 
1637
1854
  protected process (view: DataView, offset: number): void {
1638
- for (let i = 0; i < 16; i++, offset += 4) {
1855
+ for (let i = 0; i < 16; i++, offset += 8) {
1639
1856
  SHA512_W_H[i] = view.getUint32(offset)
1640
- SHA512_W_L[i] = view.getUint32((offset += 4))
1857
+ SHA512_W_L[i] = view.getUint32(offset + 4)
1641
1858
  }
1642
1859
  for (let i = 16; i < 80; i++) {
1860
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1643
1861
  const W15h = SHA512_W_H[i - 15] | 0
1862
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1644
1863
  const W15l = SHA512_W_L[i - 15] | 0
1645
1864
  const s0h = rotrSH(W15h, W15l, 1) ^ rotrSH(W15h, W15l, 8) ^ shrSH(W15h, W15l, 7)
1646
1865
  const s0l = rotrSL(W15h, W15l, 1) ^ rotrSL(W15h, W15l, 8) ^ shrSL(W15h, W15l, 7)
1866
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1647
1867
  const W2h = SHA512_W_H[i - 2] | 0
1868
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1648
1869
  const W2l = SHA512_W_L[i - 2] | 0
1649
1870
  const s1h = rotrSH(W2h, W2l, 19) ^ rotrBH(W2h, W2l, 61) ^ shrSH(W2h, W2l, 6)
1650
1871
  const s1l = rotrSL(W2h, W2l, 19) ^ rotrBL(W2h, W2l, 61) ^ shrSL(W2h, W2l, 6)
1651
1872
  const SUMl = add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16])
1652
1873
  const SUMh = add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16])
1874
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1653
1875
  SHA512_W_H[i] = SUMh | 0
1876
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1654
1877
  SHA512_W_L[i] = SUMl | 0
1655
1878
  }
1656
1879
  let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this
@@ -1661,26 +1884,41 @@ class FastSHA512 extends HashMD<FastSHA512> {
1661
1884
  const CHIl = (El & Fl) ^ (~El & Gl)
1662
1885
  const T1ll = add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i])
1663
1886
  const T1h = add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i])
1887
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1664
1888
  const T1l = T1ll | 0
1665
1889
  const sigma0h = rotrSH(Ah, Al, 28) ^ rotrBH(Ah, Al, 34) ^ rotrBH(Ah, Al, 39)
1666
1890
  const sigma0l = rotrSL(Ah, Al, 28) ^ rotrBL(Ah, Al, 34) ^ rotrBL(Ah, Al, 39)
1667
1891
  const MAJh = (Ah & Bh) ^ (Ah & Ch) ^ (Bh & Ch)
1668
1892
  const MAJl = (Al & Bl) ^ (Al & Cl) ^ (Bl & Cl)
1893
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1669
1894
  Hh = Gh | 0
1895
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1670
1896
  Hl = Gl | 0
1897
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1671
1898
  Gh = Fh | 0
1899
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1672
1900
  Gl = Fl | 0
1901
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1673
1902
  Fh = Eh | 0
1903
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1674
1904
  Fl = El | 0
1905
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1675
1906
  ;({ h: Eh, l: El } = add(Dh | 0, Dl | 0, T1h | 0, T1l | 0))
1907
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1676
1908
  Dh = Ch | 0
1909
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1677
1910
  Dl = Cl | 0
1911
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1678
1912
  Ch = Bh | 0
1913
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1679
1914
  Cl = Bl | 0
1915
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1680
1916
  Bh = Ah | 0
1917
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1681
1918
  Bl = Al | 0
1682
1919
  const T2l = add3L(sigma0l, MAJl, T1l)
1683
1920
  Ah = add3H(T2l, sigma0h, MAJh, T1h)
1921
+ // eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
1684
1922
  Al = T2l | 0
1685
1923
  }
1686
1924
  ;({ h: Ah, l: Al } = add(Ah, Al, this.Ah, this.Al))
@@ -1717,7 +1955,7 @@ class HMAC<T extends Hash<T>> extends Hash<HMAC<T>> {
1717
1955
  ahash(hash)
1718
1956
  const key = toBytes(_key)
1719
1957
  this.iHash = hash.create() as T
1720
- if (typeof (this.iHash as any).update !== 'function') { throw new Error('Expected instance of class which extends utils.Hash') }
1958
+ if (typeof (this.iHash as any).update !== 'function') { throw new TypeError('Expected instance of class which extends utils.Hash') }
1721
1959
  this.blockLen = this.iHash.blockLen
1722
1960
  this.outputLen = this.iHash.outputLen
1723
1961
  const blockLen = this.blockLen
@@ -1795,7 +2033,8 @@ function pbkdf2Core (hash: (msg: Input) => Uint8Array & { create: () => FastSHA5
1795
2033
  for (let ti = 1, pos = 0; pos < dkLen; ti++, pos += PRF.outputLen) {
1796
2034
  const Ti = DK.subarray(pos, pos + PRF.outputLen)
1797
2035
  view.setInt32(0, ti, false)
1798
- ;(prfW = PRFSalt._cloneInto(prfW)).update(arr).digestInto(u)
2036
+ prfW = PRFSalt._cloneInto(prfW)
2037
+ prfW.update(arr).digestInto(u)
1799
2038
  Ti.set(u.subarray(0, Ti.length))
1800
2039
  for (let ui = 1; ui < c; ui++) {
1801
2040
  PRF._cloneInto(prfW).update(u).digestInto(u)
@@ -1839,20 +2078,16 @@ export function pbkdf2 (
1839
2078
  if (digest !== 'sha512') {
1840
2079
  throw new Error('Only sha512 is supported in this PBKDF2 implementation')
1841
2080
  }
1842
- // Attempt to use the native Node.js implementation if available as it is
1843
- // considerably faster than the pure TypeScript fallback below. If the crypto
1844
- // module isn't present (for example in a browser build) we'll silently fall
1845
- // back to the original implementation.
1846
- try {
1847
- // eslint-disable-next-line @typescript-eslint/no-var-requires
1848
- const nodeCrypto = require('crypto')
1849
- if (typeof nodeCrypto.pbkdf2Sync === 'function') {
1850
- const p = Buffer.from(password)
1851
- const s = Buffer.from(salt)
1852
- return [...nodeCrypto.pbkdf2Sync(p, s, iterations, keylen, digest)]
1853
- }
1854
- } catch {
1855
- // ignore
2081
+ const pbkdf2Sync = NODE_CRYPTO?.pbkdf2Sync
2082
+ if (typeof pbkdf2Sync === 'function') {
2083
+ const out = pbkdf2Sync(
2084
+ toHashBytes(password),
2085
+ toHashBytes(salt),
2086
+ iterations,
2087
+ keylen,
2088
+ digest
2089
+ )
2090
+ return Array.from(out)
1856
2091
  }
1857
2092
  const p = Uint8Array.from(password)
1858
2093
  const s = Uint8Array.from(salt)