@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
@@ -11,7 +11,7 @@ import BigNumber from '../primitives/BigNumber.js'
11
11
  * @property {ScriptChunk[]} chunks - An array of script chunks that make up the script.
12
12
  */
13
13
  const BufferCtor =
14
- typeof globalThis !== 'undefined' ? (globalThis as any).Buffer : undefined
14
+ typeof globalThis === 'undefined' ? undefined : (globalThis as any).Buffer
15
15
 
16
16
  export default class Script {
17
17
  private _chunks: ScriptChunk[]
@@ -32,70 +32,54 @@ export default class Script {
32
32
  const tokens = asm.split(' ')
33
33
  let i = 0
34
34
  while (i < tokens.length) {
35
- const token = tokens[i]
36
- let opCode
37
- let opCodeNum: number = 0
38
- if (token.startsWith('OP_') && typeof OP[token] !== 'undefined') {
39
- opCode = token
40
- opCodeNum = OP[token]
41
- }
35
+ const { chunk, advance } = Script.parseASMToken(tokens, i)
36
+ chunks.push(chunk)
37
+ i += advance
38
+ }
39
+ return new Script(chunks)
40
+ }
42
41
 
43
- // we start with two special cases, 0 and -1, which are handled specially in
44
- // toASM. see _chunkToString.
45
- if (token === '0') {
46
- opCodeNum = 0
47
- chunks.push({
48
- op: opCodeNum
49
- })
50
- i = i + 1
51
- } else if (token === '-1') {
52
- opCodeNum = OP.OP_1NEGATE
53
- chunks.push({
54
- op: opCodeNum
55
- })
56
- i = i + 1
57
- } else if (opCode === undefined) {
58
- let hex = tokens[i]
59
- if (hex.length % 2 !== 0) {
60
- hex = '0' + hex
61
- }
62
- const arr = toArray(hex, 'hex')
63
- if (encode(arr, 'hex') !== hex) {
64
- throw new Error('invalid hex string in script')
65
- }
66
- const len = arr.length
67
- if (len >= 0 && len < OP.OP_PUSHDATA1) {
68
- opCodeNum = len
69
- } else if (len < Math.pow(2, 8)) {
70
- opCodeNum = OP.OP_PUSHDATA1
71
- } else if (len < Math.pow(2, 16)) {
72
- opCodeNum = OP.OP_PUSHDATA2
73
- } else if (len < Math.pow(2, 32)) {
74
- opCodeNum = OP.OP_PUSHDATA4
75
- }
76
- chunks.push({
77
- data: arr,
78
- op: opCodeNum
79
- })
80
- i = i + 1
81
- } else if (
82
- opCodeNum === OP.OP_PUSHDATA1 ||
83
- opCodeNum === OP.OP_PUSHDATA2 ||
84
- opCodeNum === OP.OP_PUSHDATA4
85
- ) {
86
- chunks.push({
87
- data: toArray(tokens[i + 2], 'hex'),
88
- op: opCodeNum
89
- })
90
- i = i + 3
91
- } else {
92
- chunks.push({
93
- op: opCodeNum
94
- })
95
- i = i + 1
42
+ private static pushdataOpCodeNum (len: number): number {
43
+ if (len >= 0 && len < OP.OP_PUSHDATA1) return len
44
+ if (len < Math.pow(2, 8)) return OP.OP_PUSHDATA1
45
+ if (len < Math.pow(2, 16)) return OP.OP_PUSHDATA2
46
+ return OP.OP_PUSHDATA4
47
+ }
48
+
49
+ private static parseASMToken (
50
+ tokens: string[],
51
+ i: number
52
+ ): { chunk: ScriptChunk, advance: number } {
53
+ const token = tokens[i]
54
+
55
+ // Special literal tokens
56
+ if (token === '0') return { chunk: { op: 0 }, advance: 1 }
57
+ if (token === '-1') return { chunk: { op: OP.OP_1NEGATE }, advance: 1 }
58
+
59
+ const isKnownOp = token.startsWith('OP_') && OP[token] !== undefined
60
+ const opCodeNum: number = isKnownOp ? OP[token] : 0
61
+
62
+ // Inline PUSHDATA opcodes consume the next two tokens (size, hex data)
63
+ if (
64
+ opCodeNum === OP.OP_PUSHDATA1 ||
65
+ opCodeNum === OP.OP_PUSHDATA2 ||
66
+ opCodeNum === OP.OP_PUSHDATA4
67
+ ) {
68
+ return { chunk: { data: toArray(tokens[i + 2], 'hex'), op: opCodeNum }, advance: 3 }
69
+ }
70
+
71
+ // Unknown opcode token — treat as raw hex push data
72
+ if (!isKnownOp) {
73
+ let hex = token
74
+ if (hex.length % 2 !== 0) hex = '0' + hex
75
+ const arr = toArray(hex, 'hex')
76
+ if (encode(arr, 'hex') !== hex) {
77
+ throw new Error('invalid hex string in script')
96
78
  }
79
+ return { chunk: { data: arr, op: Script.pushdataOpCodeNum(arr.length) }, advance: 1 }
97
80
  }
98
- return new Script(chunks)
81
+
82
+ return { chunk: { op: opCodeNum }, advance: 1 }
99
83
  }
100
84
 
101
85
  /**
@@ -177,8 +161,7 @@ export default class Script {
177
161
  */
178
162
  toASM (): string {
179
163
  let str = ''
180
- for (let i = 0; i < this.chunks.length; i++) {
181
- const chunk = this.chunks[i]
164
+ for (const chunk of this.chunks) {
182
165
  str += this._chunkToString(chunk)
183
166
  }
184
167
 
@@ -194,13 +177,11 @@ export default class Script {
194
177
  if (this.hexCache != null) {
195
178
  return this.hexCache
196
179
  }
197
- if (this.rawBytesCache == null) {
198
- this.rawBytesCache = this.serializeChunksToBytes()
199
- }
180
+ this.rawBytesCache ??= this.serializeChunksToBytes()
200
181
  const hex =
201
- BufferCtor != null
202
- ? BufferCtor.from(this.rawBytesCache).toString('hex')
203
- : (encode(Array.from(this.rawBytesCache), 'hex') as string)
182
+ BufferCtor == null
183
+ ? (encode(Array.from(this.rawBytesCache), 'hex') as string)
184
+ : BufferCtor.from(this.rawBytesCache).toString('hex')
204
185
  this.hexCache = hex
205
186
  return hex
206
187
  }
@@ -215,9 +196,7 @@ export default class Script {
215
196
  }
216
197
 
217
198
  toUint8Array (): Uint8Array {
218
- if (this.rawBytesCache == null) {
219
- this.rawBytesCache = this.serializeChunksToBytes()
220
- }
199
+ this.rawBytesCache ??= this.serializeChunksToBytes()
221
200
  return this.rawBytesCache
222
201
  }
223
202
 
@@ -227,7 +206,7 @@ export default class Script {
227
206
  * @param script - The script to append.
228
207
  * @returns This script instance for chaining.
229
208
  */
230
- writeScript (script: Script): Script {
209
+ writeScript (script: Script): this {
231
210
  this.invalidateSerializationCaches()
232
211
  this.chunks = this.chunks.concat(script.chunks)
233
212
  return this
@@ -239,7 +218,7 @@ export default class Script {
239
218
  * @param op - The opcode to append.
240
219
  * @returns This script instance for chaining.
241
220
  */
242
- writeOpCode (op: number): Script {
221
+ writeOpCode (op: number): this {
243
222
  this.invalidateSerializationCaches()
244
223
  this.chunks.push({ op })
245
224
  return this
@@ -252,7 +231,7 @@ export default class Script {
252
231
  * @param op - The opcode to set.
253
232
  * @returns This script instance for chaining.
254
233
  */
255
- setChunkOpCode (i: number, op: number): Script {
234
+ setChunkOpCode (i: number, op: number): this {
256
235
  this.invalidateSerializationCaches()
257
236
  this.chunks[i] = { op }
258
237
  return this
@@ -264,7 +243,7 @@ export default class Script {
264
243
  * @param bn - The BigNumber to append.
265
244
  * @returns This script instance for chaining.
266
245
  */
267
- writeBn (bn: BigNumber): Script {
246
+ writeBn (bn: BigNumber): this {
268
247
  this.invalidateSerializationCaches()
269
248
  if (bn.cmpn(0) === OP.OP_0) {
270
249
  this.chunks.push({
@@ -293,7 +272,7 @@ export default class Script {
293
272
  * @returns This script instance for chaining.
294
273
  * @throws {Error} Throws an error if the data is too large to be pushed.
295
274
  */
296
- writeBin (bin: number[]): Script {
275
+ writeBin (bin: number[]): this {
297
276
  this.invalidateSerializationCaches()
298
277
  let op: number
299
278
  const data = bin.length > 0 ? bin : undefined
@@ -323,7 +302,7 @@ export default class Script {
323
302
  * @param num - The number to append.
324
303
  * @returns This script instance for chaining.
325
304
  */
326
- writeNumber (num: number): Script {
305
+ writeNumber (num: number): this {
327
306
  this.invalidateSerializationCaches()
328
307
  this.writeBn(new BigNumber(num))
329
308
  return this
@@ -334,7 +313,7 @@ export default class Script {
334
313
  * Removes all OP_CODESEPARATOR opcodes from the script.
335
314
  * @returns This script instance for chaining.
336
315
  */
337
- removeCodeseparators (): Script {
316
+ removeCodeseparators (): this {
338
317
  const bytes = this.toUint8Array()
339
318
  this.rawBytesCache = Uint8Array.from(Script.removeOpcodeBytes(bytes, OP.OP_CODESEPARATOR))
340
319
  this.hexCache = undefined
@@ -350,7 +329,7 @@ export default class Script {
350
329
  *
351
330
  * @returns This script instance for chaining.
352
331
  */
353
- findAndDelete (script: Script): Script {
332
+ findAndDelete (script: Script): this {
354
333
  this.invalidateSerializationCaches()
355
334
  const targetBytes = script.toUint8Array()
356
335
  const targetLen = targetBytes.length
@@ -434,8 +413,7 @@ export default class Script {
434
413
  * @returns True if the script is push-only, otherwise false.
435
414
  */
436
415
  isPushOnly (): boolean {
437
- for (let i = 0; i < this.chunks.length; i++) {
438
- const chunk = this.chunks[i]
416
+ for (const chunk of this.chunks) {
439
417
  const opCodeNum = chunk.op
440
418
  if (opCodeNum > OP.OP_16) {
441
419
  return false
@@ -498,13 +476,11 @@ export default class Script {
498
476
  const bytes = new Uint8Array(totalLength)
499
477
  let offset = 0
500
478
 
501
- for (let i = 0; i < chunks.length; i++) {
502
- const chunk = chunks[i]
479
+ for (const chunk of chunks) {
503
480
  bytes[offset++] = chunk.op
504
481
  if (chunk.data == null) continue
505
482
  if (chunk.op === OP.OP_RETURN) {
506
483
  bytes.set(chunk.data, offset)
507
- offset += chunk.data.length
508
484
  break
509
485
  }
510
486
  offset = Script.writeChunkData(bytes, offset, chunk.op, chunk.data)
@@ -549,6 +525,40 @@ export default class Script {
549
525
  return offset
550
526
  }
551
527
 
528
+ /**
529
+ * Reads pushdata length bytes from `bytes` at `pos` and returns the resulting
530
+ * `{ len, newPos, hasLength }` for a given opcode. Does not read the actual data.
531
+ */
532
+ private static readPushdataLength (
533
+ op: number,
534
+ bytes: ArrayLike<number>,
535
+ pos: number,
536
+ length: number
537
+ ): { len: number, newPos: number, hasLength: boolean } {
538
+ if (op > 0 && op < OP.OP_PUSHDATA1) {
539
+ return { len: op, newPos: pos, hasLength: true }
540
+ }
541
+ if (op === OP.OP_PUSHDATA1) {
542
+ const hasLength = pos < length
543
+ const len = hasLength ? bytes[pos++] ?? 0 : 0
544
+ return { len, newPos: pos, hasLength }
545
+ }
546
+ if (op === OP.OP_PUSHDATA2) {
547
+ const hasLength = pos + 1 < length
548
+ const len = (bytes[pos] ?? 0) | ((bytes[pos + 1] ?? 0) << 8)
549
+ return { len, newPos: Math.min(pos + 2, length), hasLength }
550
+ }
551
+ // OP_PUSHDATA4
552
+ const hasLength = pos + 3 < length
553
+ const len = (
554
+ (bytes[pos] ?? 0) |
555
+ ((bytes[pos + 1] ?? 0) << 8) |
556
+ ((bytes[pos + 2] ?? 0) << 16) |
557
+ ((bytes[pos + 3] ?? 0) << 24)
558
+ ) >>> 0
559
+ return { len, newPos: Math.min(pos + 4, length), hasLength }
560
+ }
561
+
552
562
  private static parseChunks (bytes: ArrayLike<number>): ScriptChunk[] {
553
563
  const chunks: ScriptChunk[] = []
554
564
  const length = bytes.length
@@ -559,71 +569,22 @@ export default class Script {
559
569
  const op = bytes[pos++] ?? 0
560
570
 
561
571
  if (op === OP.OP_RETURN && inConditionalBlock === 0) {
562
- chunks.push({
563
- op,
564
- data: Script.copyRange(bytes, pos, length)
565
- })
572
+ chunks.push({ op, data: Script.copyRange(bytes, pos, length) })
566
573
  break
567
574
  }
568
575
 
569
- if (
570
- op === OP.OP_IF ||
571
- op === OP.OP_NOTIF ||
572
- op === OP.OP_VERIF ||
573
- op === OP.OP_VERNOTIF
574
- ) {
576
+ if (op === OP.OP_IF || op === OP.OP_NOTIF || op === OP.OP_VERIF || op === OP.OP_VERNOTIF) {
575
577
  inConditionalBlock++
576
578
  } else if (op === OP.OP_ENDIF) {
577
579
  inConditionalBlock--
578
580
  }
579
581
 
580
- if (op > 0 && op < OP.OP_PUSHDATA1) {
581
- const len = op
582
- const end = Math.min(pos + len, length)
583
- chunks.push({
584
- data: Script.copyRange(bytes, pos, end),
585
- op,
586
- invalidLength: end - pos !== len
587
- })
588
- pos = end
589
- } else if (op === OP.OP_PUSHDATA1) {
590
- const hasLength = pos < length
591
- const len = hasLength ? bytes[pos++] ?? 0 : 0
582
+ if (op > 0 && op <= OP.OP_PUSHDATA4) {
583
+ const { len, newPos, hasLength } = Script.readPushdataLength(op, bytes, pos, length)
584
+ pos = newPos
592
585
  const end = Math.min(pos + len, length)
593
- chunks.push({
594
- data: Script.copyRange(bytes, pos, end),
595
- op,
596
- invalidLength: !hasLength || end - pos !== len
597
- })
598
- pos = end
599
- } else if (op === OP.OP_PUSHDATA2) {
600
- const hasLength = pos + 1 < length
601
- const b0 = bytes[pos] ?? 0
602
- const b1 = bytes[pos + 1] ?? 0
603
- const len = b0 | (b1 << 8)
604
- pos = Math.min(pos + 2, length)
605
- const end = Math.min(pos + len, length)
606
- chunks.push({
607
- data: Script.copyRange(bytes, pos, end),
608
- op,
609
- invalidLength: !hasLength || end - pos !== len
610
- })
611
- pos = end
612
- } else if (op === OP.OP_PUSHDATA4) {
613
- const hasLength = pos + 3 < length
614
- const len =
615
- ((bytes[pos] ?? 0) |
616
- ((bytes[pos + 1] ?? 0) << 8) |
617
- ((bytes[pos + 2] ?? 0) << 16) |
618
- ((bytes[pos + 3] ?? 0) << 24)) >>>
619
- 0
620
- pos = Math.min(pos + 4, length)
621
- const end = Math.min(pos + len, length)
622
- chunks.push({
623
- data: Script.copyRange(bytes, pos, end),
624
- op,
625
- invalidLength: !hasLength || end - pos !== len
626
- })
586
+ const invalidLength = !hasLength || end - pos !== len
587
+ chunks.push({ data: Script.copyRange(bytes, pos, end), op, invalidLength })
627
588
  pos = end
628
589
  } else {
629
590
  chunks.push({ op })
@@ -641,35 +602,18 @@ export default class Script {
641
602
  while (pos < length) {
642
603
  const start = pos
643
604
  const op = bytes[pos++] ?? 0
644
- let dataStart = pos
645
- let dataLength = 0
646
-
647
- if (op > 0 && op < OP.OP_PUSHDATA1) {
648
- dataLength = op
649
- } else if (op === OP.OP_PUSHDATA1) {
650
- if (pos < length) dataLength = bytes[pos++] ?? 0
651
- dataStart = pos
652
- } else if (op === OP.OP_PUSHDATA2) {
653
- if (pos + 1 < length) dataLength = (bytes[pos] ?? 0) | ((bytes[pos + 1] ?? 0) << 8)
654
- pos = Math.min(pos + 2, length)
655
- dataStart = pos
656
- } else if (op === OP.OP_PUSHDATA4) {
657
- if (pos + 3 < length) {
658
- dataLength =
659
- ((bytes[pos] ?? 0) |
660
- ((bytes[pos + 1] ?? 0) << 8) |
661
- ((bytes[pos + 2] ?? 0) << 16) |
662
- ((bytes[pos + 3] ?? 0) << 24)) >>> 0
663
- }
664
- pos = Math.min(pos + 4, length)
665
- dataStart = pos
666
- }
667
605
 
668
- const end = Math.min(dataStart + dataLength, length)
669
- if (op !== opcode) {
670
- for (let i = start; i < end; i++) out.push(bytes[i] ?? 0)
606
+ if (op > 0 && op <= OP.OP_PUSHDATA4) {
607
+ const { len, newPos } = Script.readPushdataLength(op, bytes, pos, length)
608
+ pos = newPos
609
+ const end = Math.min(pos + len, length)
610
+ if (op !== opcode) {
611
+ for (let i = start; i < end; i++) out.push(bytes[i] ?? 0)
612
+ }
613
+ pos = end
614
+ } else if (op !== opcode) {
615
+ out.push(op)
671
616
  }
672
- pos = end
673
617
  }
674
618
 
675
619
  return out
@@ -691,7 +635,7 @@ export default class Script {
691
635
  private _chunkToString (chunk: ScriptChunk): string {
692
636
  const op = chunk.op
693
637
  let str = ''
694
- if (typeof chunk.data === 'undefined') {
638
+ if (chunk.data === undefined) {
695
639
  const val = OP[op] as string
696
640
  str = `${str} ${val}`
697
641
  } else {
@@ -22,8 +22,8 @@ export default class ScriptEvaluationError extends Error {
22
22
  stackMem: number
23
23
  altStackMem: number
24
24
  }) {
25
- const stackHex = params.stackState.map(s => s != null && typeof s.length !== 'undefined' ? toHex(s) : (s === null || s === undefined ? 'null/undef' : 'INVALID_STACK_ITEM')).join(', ')
26
- const altStackHex = params.altStackState.map(s => s != null && typeof s.length !== 'undefined' ? toHex(s) : (s === null || s === undefined ? 'null/undef' : 'INVALID_STACK_ITEM')).join(', ')
25
+ const stackHex = params.stackState.map(s => s != null && s.length !== undefined ? toHex(s) : (s === null || s === undefined ? 'null/undef' : 'INVALID_STACK_ITEM')).join(', ')
26
+ const altStackHex = params.altStackState.map(s => s != null && s.length !== undefined ? toHex(s) : (s === null || s === undefined ? 'null/undef' : 'INVALID_STACK_ITEM')).join(', ')
27
27
  const pcInfo = `Context: ${params.context}, PC: ${params.programCounter}`
28
28
  const stackInfo = `Stack: [${stackHex}] (len: ${params.stackState.length}, mem: ${params.stackMem})`
29
29
  const altStackInfo = `AltStack: [${altStackHex}] (len: ${params.altStackState.length}, mem: ${params.altStackMem})`
@@ -48,8 +48,8 @@ function isMinimallyEncodedHelper (
48
48
  return false
49
49
  }
50
50
  if (buf.length > 0) {
51
- if ((buf[buf.length - 1] & 0x7f) === 0) {
52
- if (buf.length <= 1 || (buf[buf.length - 2] & 0x80) === 0) {
51
+ if ((buf.at(-1) & 0x7f) === 0) {
52
+ if (buf.length <= 1 || (buf.at(-2) & 0x80) === 0) {
53
53
  return false
54
54
  }
55
55
  }
@@ -218,15 +218,14 @@ export default class Spend {
218
218
  this.lockTime = params.lockTime
219
219
  this.memoryLimit = params.memoryLimit ?? 32000000
220
220
  this.isRelaxedOverride = params.isRelaxed === true
221
- this.verifyFlags = params.verifyFlags === undefined
222
- ? undefined
223
- : new Set(
224
- (Array.isArray(params.verifyFlags)
225
- ? params.verifyFlags
226
- : params.verifyFlags.split(','))
227
- .map(flag => flag.trim())
228
- .filter(flag => flag.length > 0)
229
- )
221
+ if (params.verifyFlags === undefined) {
222
+ this.verifyFlags = undefined
223
+ } else {
224
+ const flagArr = Array.isArray(params.verifyFlags)
225
+ ? params.verifyFlags
226
+ : params.verifyFlags.split(',')
227
+ this.verifyFlags = new Set(flagArr.map(flag => flag.trim()).filter(flag => flag.length > 0))
228
+ }
230
229
  this.stack = []
231
230
  this.altStack = []
232
231
  this.ifStack = []
@@ -524,7 +523,7 @@ export default class Spend {
524
523
  private parseLaxChecksigSignature (buf: number[]): TransactionSignature {
525
524
  if (buf.length === 0) return TransactionSignature.fromChecksigFormat(buf)
526
525
 
527
- const scope = buf[buf.length - 1]
526
+ const scope = buf.at(-1)
528
527
  const der = buf.slice(0, -1)
529
528
  const position = { value: 0 }
530
529
  if (der[position.value++] !== 0x30) throw new Error('Signature DER must start with 0x30')
@@ -881,11 +880,11 @@ export default class Spend {
881
880
  break
882
881
  case OP.OP_ELSE:
883
882
  if (this.ifStack.length === 0) this.scriptEvaluationError('OP_ELSE requires a preceeding OP_IF.')
884
- if (this.hasExplicitFlags() && this.isAfterGenesis() && this.elseStack[this.elseStack.length - 1]) {
883
+ if (this.hasExplicitFlags() && this.isAfterGenesis() && this.elseStack.at(-1)) {
885
884
  this.scriptEvaluationError('OP_ELSE may only be used once for each OP_IF or OP_NOTIF after Genesis.')
886
885
  }
887
886
  this.elseStack[this.elseStack.length - 1] = true
888
- this.ifStack[this.ifStack.length - 1] = !(this.ifStack[this.ifStack.length - 1])
887
+ this.ifStack[this.ifStack.length - 1] = !this.ifStack.at(-1)
889
888
  break
890
889
  case OP.OP_ENDIF:
891
890
  if (this.ifStack.length === 0) this.scriptEvaluationError('OP_ENDIF requires a preceeding OP_IF.')
@@ -1400,7 +1399,7 @@ export default class Spend {
1400
1399
  let signbit = 0x00
1401
1400
 
1402
1401
  if (rawnum.length > 0) {
1403
- signbit = rawnum[rawnum.length - 1] & 0x80 // Store sign bit
1402
+ signbit = rawnum.at(-1) & 0x80 // Store sign bit
1404
1403
  rawnum[rawnum.length - 1] &= 0x7f // Remove sign bit for padding
1405
1404
  }
1406
1405
 
@@ -1,4 +1,7 @@
1
- import { ScriptTemplate, LockingScript, UnlockingScript, OP } from '../index.js'
1
+ import type ScriptTemplate from '../ScriptTemplate.js'
2
+ import LockingScript from '../LockingScript.js'
3
+ import UnlockingScript from '../UnlockingScript.js'
4
+ import OP from '../OP.js'
2
5
  import {
3
6
  Utils,
4
7
  Hash,
@@ -15,7 +18,6 @@ import { computeSignatureScope, resolveSourceDetails, formatPreimage } from './S
15
18
  * For a given piece of data to push onto the stack in script, creates the correct minimally-encoded script chunk,
16
19
  * including the correct push operation.
17
20
  *
18
- * TODO: This should be made into a TS-SDK util (distinct from the `minimallyEncode` util)
19
21
  */
20
22
  const createMinimallyEncodedScriptChunk = (
21
23
  data: number[]
@@ -160,7 +162,7 @@ export default class PushDrop implements ScriptTemplate {
160
162
  })
161
163
  lockChunks.push({ op: OP.OP_CHECKSIG })
162
164
  if (includeSignature) {
163
- const dataToSign = fields.reduce((a, e) => [...a, ...e], [])
165
+ const dataToSign = fields.flat()
164
166
  const { signature } = await this.wallet.createSignature({
165
167
  data: dataToSign,
166
168
  protocolID,
@@ -90,9 +90,7 @@ export default class RPuzzle implements ScriptTemplate {
90
90
  } {
91
91
  return {
92
92
  sign: async (tx: Transaction, inputIndex: number) => {
93
- if (typeof privateKey === 'undefined') {
94
- privateKey = PrivateKey.fromRandom()
95
- }
93
+ privateKey ??= PrivateKey.fromRandom()
96
94
  let signatureScope = TransactionSignature.SIGHASH_FORKID
97
95
  if (signOutputs === 'all') {
98
96
  signatureScope |= TransactionSignature.SIGHASH_ALL
@@ -109,7 +107,7 @@ export default class RPuzzle implements ScriptTemplate {
109
107
  const otherInputs = [...tx.inputs]
110
108
  const [input] = otherInputs.splice(inputIndex, 1)
111
109
  if (typeof input.sourceTransaction !== 'object') {
112
- throw new Error(
110
+ throw new TypeError(
113
111
  'The source transaction is needed for transaction signing.'
114
112
  )
115
113
  }
@@ -1,5 +1,5 @@
1
1
  import { LookupResolver } from '../overlay-tools/index.js'
2
- import { StorageUtils } from './index.js'
2
+ import * as StorageUtils from './StorageUtils.js'
3
3
  import PushDrop from '../script/templates/PushDrop.js'
4
4
  import Transaction from '../transaction/Transaction.js'
5
5
  import { Hash, Utils } from '../primitives/index.js'
package/src/totp/totp.ts CHANGED
@@ -119,7 +119,7 @@ function generateHOTP (
119
119
  const signature = hmac.digest()
120
120
 
121
121
  // RFC 4226 https://datatracker.ietf.org/doc/html/rfc4226#section-5.4
122
- const offset = signature[signature.length - 1] & 0x0f // offset is the last byte in the hmac
122
+ const offset = (signature.at(-1) ?? 0) & 0x0f // offset is the last byte in the hmac
123
123
  const fourBytesRange = signature.slice(offset, offset + 4) // starting from offset, get 4 bytes
124
124
  const mask = 0x7fffffff // 32-bit number with a leading 0 followed by 31 ones [0111 (...) 1111]
125
125
  const masked = new BigNumber(fourBytesRange).toNumber() & mask