@bsv/sdk 2.0.16 → 2.1.1

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 (405) hide show
  1. package/README.md +7 -7
  2. package/dist/cjs/package.json +14 -13
  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 +172 -232
  22. package/dist/cjs/src/identity/ContactsManager.js.map +1 -1
  23. package/dist/cjs/src/identity/IdentityClient.js +122 -55
  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 +139 -46
  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 +140 -56
  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/TransactionSignature.js +20 -21
  70. package/dist/cjs/src/primitives/TransactionSignature.js.map +1 -1
  71. package/dist/cjs/src/primitives/utils.js +39 -46
  72. package/dist/cjs/src/primitives/utils.js.map +1 -1
  73. package/dist/cjs/src/registry/RegistryClient.js +31 -23
  74. package/dist/cjs/src/registry/RegistryClient.js.map +1 -1
  75. package/dist/cjs/src/remittance/RemittanceManager.js +19 -18
  76. package/dist/cjs/src/remittance/RemittanceManager.js.map +1 -1
  77. package/dist/cjs/src/remittance/modules/BasicBRC29.js.map +1 -1
  78. package/dist/cjs/src/script/Script.js +93 -170
  79. package/dist/cjs/src/script/Script.js.map +1 -1
  80. package/dist/cjs/src/script/ScriptEvaluationError.js +2 -2
  81. package/dist/cjs/src/script/ScriptEvaluationError.js.map +1 -1
  82. package/dist/cjs/src/script/Spend.js +14 -12
  83. package/dist/cjs/src/script/Spend.js.map +1 -1
  84. package/dist/cjs/src/script/templates/PushDrop.js +22 -18
  85. package/dist/cjs/src/script/templates/PushDrop.js.map +1 -1
  86. package/dist/cjs/src/script/templates/RPuzzle.js +2 -4
  87. package/dist/cjs/src/script/templates/RPuzzle.js.map +1 -1
  88. package/dist/cjs/src/storage/StorageDownloader.js +42 -9
  89. package/dist/cjs/src/storage/StorageDownloader.js.map +1 -1
  90. package/dist/cjs/src/totp/totp.js +1 -1
  91. package/dist/cjs/src/totp/totp.js.map +1 -1
  92. package/dist/cjs/src/transaction/Beef.js +239 -192
  93. package/dist/cjs/src/transaction/Beef.js.map +1 -1
  94. package/dist/cjs/src/transaction/BeefConstants.js +19 -0
  95. package/dist/cjs/src/transaction/BeefConstants.js.map +1 -0
  96. package/dist/cjs/src/transaction/BeefTx.js +12 -12
  97. package/dist/cjs/src/transaction/BeefTx.js.map +1 -1
  98. package/dist/cjs/src/transaction/MerklePath.js +4 -4
  99. package/dist/cjs/src/transaction/MerklePath.js.map +1 -1
  100. package/dist/cjs/src/transaction/Transaction.js +49 -52
  101. package/dist/cjs/src/transaction/Transaction.js.map +1 -1
  102. package/dist/cjs/src/transaction/fee-models/SatoshisPerKilobyte.js +1 -1
  103. package/dist/cjs/src/transaction/fee-models/SatoshisPerKilobyte.js.map +1 -1
  104. package/dist/cjs/src/transaction/http/BinaryFetchClient.js +9 -9
  105. package/dist/cjs/src/transaction/http/BinaryFetchClient.js.map +1 -1
  106. package/dist/cjs/src/transaction/http/DefaultHttpClient.js +9 -9
  107. package/dist/cjs/src/transaction/http/DefaultHttpClient.js.map +1 -1
  108. package/dist/cjs/src/wallet/CachedKeyDeriver.js +1 -1
  109. package/dist/cjs/src/wallet/CachedKeyDeriver.js.map +1 -1
  110. package/dist/cjs/src/wallet/WalletClient.js.map +1 -1
  111. package/dist/cjs/src/wallet/WalletError.js.map +1 -1
  112. package/dist/cjs/src/wallet/substrates/HTTPWalletJSON.js +5 -4
  113. package/dist/cjs/src/wallet/substrates/HTTPWalletJSON.js.map +1 -1
  114. package/dist/cjs/src/wallet/substrates/ReactNativeWebView.js +9 -9
  115. package/dist/cjs/src/wallet/substrates/ReactNativeWebView.js.map +1 -1
  116. package/dist/cjs/src/wallet/substrates/WalletWireProcessor.js +92 -92
  117. package/dist/cjs/src/wallet/substrates/WalletWireProcessor.js.map +1 -1
  118. package/dist/cjs/src/wallet/substrates/WalletWireTransceiver.js +387 -711
  119. package/dist/cjs/src/wallet/substrates/WalletWireTransceiver.js.map +1 -1
  120. package/dist/cjs/src/wallet/substrates/XDM.js +4 -4
  121. package/dist/cjs/src/wallet/substrates/XDM.js.map +1 -1
  122. package/dist/cjs/src/wallet/substrates/window.CWI.js +2 -2
  123. package/dist/cjs/src/wallet/substrates/window.CWI.js.map +1 -1
  124. package/dist/cjs/src/wallet/validationHelpers.js +9 -9
  125. package/dist/cjs/src/wallet/validationHelpers.js.map +1 -1
  126. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  127. package/dist/esm/src/auth/Peer.js +25 -13
  128. package/dist/esm/src/auth/Peer.js.map +1 -1
  129. package/dist/esm/src/auth/SessionManager.js +4 -7
  130. package/dist/esm/src/auth/SessionManager.js.map +1 -1
  131. package/dist/esm/src/auth/certificates/MasterCertificate.js +1 -1
  132. package/dist/esm/src/auth/certificates/MasterCertificate.js.map +1 -1
  133. package/dist/esm/src/auth/certificates/__tests/CompletedProtoWallet.js +1 -1
  134. package/dist/esm/src/auth/certificates/__tests/CompletedProtoWallet.js.map +1 -1
  135. package/dist/esm/src/auth/clients/AuthFetch.js +32 -32
  136. package/dist/esm/src/auth/clients/AuthFetch.js.map +1 -1
  137. package/dist/esm/src/auth/transports/SimplifiedFetchTransport.js +4 -4
  138. package/dist/esm/src/auth/transports/SimplifiedFetchTransport.js.map +1 -1
  139. package/dist/esm/src/compat/ECIES.js +29 -34
  140. package/dist/esm/src/compat/ECIES.js.map +1 -1
  141. package/dist/esm/src/compat/HD.js +9 -4
  142. package/dist/esm/src/compat/HD.js.map +1 -1
  143. package/dist/esm/src/compat/Mnemonic.js +12 -12
  144. package/dist/esm/src/compat/Mnemonic.js.map +1 -1
  145. package/dist/esm/src/identity/ContactsManager.js +172 -232
  146. package/dist/esm/src/identity/ContactsManager.js.map +1 -1
  147. package/dist/esm/src/identity/IdentityClient.js +122 -55
  148. package/dist/esm/src/identity/IdentityClient.js.map +1 -1
  149. package/dist/esm/src/kvstore/GlobalKVStore.js +30 -31
  150. package/dist/esm/src/kvstore/GlobalKVStore.js.map +1 -1
  151. package/dist/esm/src/kvstore/LocalKVStore.js +9 -9
  152. package/dist/esm/src/kvstore/LocalKVStore.js.map +1 -1
  153. package/dist/esm/src/kvstore/kvStoreInterpreter.js +2 -2
  154. package/dist/esm/src/kvstore/kvStoreInterpreter.js.map +1 -1
  155. package/dist/esm/src/messages/SignedMessage.js +1 -1
  156. package/dist/esm/src/messages/SignedMessage.js.map +1 -1
  157. package/dist/esm/src/overlay-tools/Historian.js +1 -1
  158. package/dist/esm/src/overlay-tools/Historian.js.map +1 -1
  159. package/dist/esm/src/overlay-tools/LookupResolver.js +139 -46
  160. package/dist/esm/src/overlay-tools/LookupResolver.js.map +1 -1
  161. package/dist/esm/src/overlay-tools/SHIPBroadcaster.js +74 -146
  162. package/dist/esm/src/overlay-tools/SHIPBroadcaster.js.map +1 -1
  163. package/dist/esm/src/primitives/AESGCM.js +2 -2
  164. package/dist/esm/src/primitives/AESGCM.js.map +1 -1
  165. package/dist/esm/src/primitives/BigNumber.js +167 -154
  166. package/dist/esm/src/primitives/BigNumber.js.map +1 -1
  167. package/dist/esm/src/primitives/Curve.js +17 -15
  168. package/dist/esm/src/primitives/Curve.js.map +1 -1
  169. package/dist/esm/src/primitives/ECDSA.js +12 -7
  170. package/dist/esm/src/primitives/ECDSA.js.map +1 -1
  171. package/dist/esm/src/primitives/Hash.js +140 -56
  172. package/dist/esm/src/primitives/Hash.js.map +1 -1
  173. package/dist/esm/src/primitives/JacobianPoint.js +8 -8
  174. package/dist/esm/src/primitives/JacobianPoint.js.map +1 -1
  175. package/dist/esm/src/primitives/K256.js +3 -3
  176. package/dist/esm/src/primitives/K256.js.map +1 -1
  177. package/dist/esm/src/primitives/Point.js +36 -40
  178. package/dist/esm/src/primitives/Point.js.map +1 -1
  179. package/dist/esm/src/primitives/PrivateKey.js +4 -4
  180. package/dist/esm/src/primitives/PrivateKey.js.map +1 -1
  181. package/dist/esm/src/primitives/PublicKey.js +4 -4
  182. package/dist/esm/src/primitives/PublicKey.js.map +1 -1
  183. package/dist/esm/src/primitives/Random.js +10 -14
  184. package/dist/esm/src/primitives/Random.js.map +1 -1
  185. package/dist/esm/src/primitives/ReaderUint8Array.js +6 -6
  186. package/dist/esm/src/primitives/ReaderUint8Array.js.map +1 -1
  187. package/dist/esm/src/primitives/Schnorr.js +1 -1
  188. package/dist/esm/src/primitives/Schnorr.js.map +1 -1
  189. package/dist/esm/src/primitives/Secp256r1.js +2 -1
  190. package/dist/esm/src/primitives/Secp256r1.js.map +1 -1
  191. package/dist/esm/src/primitives/Signature.js +8 -8
  192. package/dist/esm/src/primitives/Signature.js.map +1 -1
  193. package/dist/esm/src/primitives/TransactionSignature.js +20 -21
  194. package/dist/esm/src/primitives/TransactionSignature.js.map +1 -1
  195. package/dist/esm/src/primitives/utils.js +39 -48
  196. package/dist/esm/src/primitives/utils.js.map +1 -1
  197. package/dist/esm/src/registry/RegistryClient.js +31 -23
  198. package/dist/esm/src/registry/RegistryClient.js.map +1 -1
  199. package/dist/esm/src/remittance/RemittanceManager.js +19 -18
  200. package/dist/esm/src/remittance/RemittanceManager.js.map +1 -1
  201. package/dist/esm/src/remittance/modules/BasicBRC29.js.map +1 -1
  202. package/dist/esm/src/script/Script.js +93 -170
  203. package/dist/esm/src/script/Script.js.map +1 -1
  204. package/dist/esm/src/script/ScriptEvaluationError.js +2 -2
  205. package/dist/esm/src/script/ScriptEvaluationError.js.map +1 -1
  206. package/dist/esm/src/script/Spend.js +14 -12
  207. package/dist/esm/src/script/Spend.js.map +1 -1
  208. package/dist/esm/src/script/templates/PushDrop.js +4 -3
  209. package/dist/esm/src/script/templates/PushDrop.js.map +1 -1
  210. package/dist/esm/src/script/templates/RPuzzle.js +2 -4
  211. package/dist/esm/src/script/templates/RPuzzle.js.map +1 -1
  212. package/dist/esm/src/storage/StorageDownloader.js +1 -1
  213. package/dist/esm/src/storage/StorageDownloader.js.map +1 -1
  214. package/dist/esm/src/totp/totp.js +1 -1
  215. package/dist/esm/src/totp/totp.js.map +1 -1
  216. package/dist/esm/src/transaction/Beef.js +229 -186
  217. package/dist/esm/src/transaction/Beef.js.map +1 -1
  218. package/dist/esm/src/transaction/BeefConstants.js +16 -0
  219. package/dist/esm/src/transaction/BeefConstants.js.map +1 -0
  220. package/dist/esm/src/transaction/BeefTx.js +3 -3
  221. package/dist/esm/src/transaction/BeefTx.js.map +1 -1
  222. package/dist/esm/src/transaction/MerklePath.js +4 -4
  223. package/dist/esm/src/transaction/MerklePath.js.map +1 -1
  224. package/dist/esm/src/transaction/Transaction.js +49 -52
  225. package/dist/esm/src/transaction/Transaction.js.map +1 -1
  226. package/dist/esm/src/transaction/fee-models/SatoshisPerKilobyte.js +1 -1
  227. package/dist/esm/src/transaction/fee-models/SatoshisPerKilobyte.js.map +1 -1
  228. package/dist/esm/src/transaction/http/BinaryFetchClient.js +9 -9
  229. package/dist/esm/src/transaction/http/BinaryFetchClient.js.map +1 -1
  230. package/dist/esm/src/transaction/http/DefaultHttpClient.js +9 -9
  231. package/dist/esm/src/transaction/http/DefaultHttpClient.js.map +1 -1
  232. package/dist/esm/src/wallet/CachedKeyDeriver.js +1 -1
  233. package/dist/esm/src/wallet/CachedKeyDeriver.js.map +1 -1
  234. package/dist/esm/src/wallet/WalletClient.js.map +1 -1
  235. package/dist/esm/src/wallet/WalletError.js.map +1 -1
  236. package/dist/esm/src/wallet/substrates/HTTPWalletJSON.js +5 -4
  237. package/dist/esm/src/wallet/substrates/HTTPWalletJSON.js.map +1 -1
  238. package/dist/esm/src/wallet/substrates/ReactNativeWebView.js +9 -9
  239. package/dist/esm/src/wallet/substrates/ReactNativeWebView.js.map +1 -1
  240. package/dist/esm/src/wallet/substrates/WalletWireProcessor.js +92 -92
  241. package/dist/esm/src/wallet/substrates/WalletWireProcessor.js.map +1 -1
  242. package/dist/esm/src/wallet/substrates/WalletWireTransceiver.js +387 -711
  243. package/dist/esm/src/wallet/substrates/WalletWireTransceiver.js.map +1 -1
  244. package/dist/esm/src/wallet/substrates/XDM.js +4 -4
  245. package/dist/esm/src/wallet/substrates/XDM.js.map +1 -1
  246. package/dist/esm/src/wallet/substrates/window.CWI.js +2 -2
  247. package/dist/esm/src/wallet/substrates/window.CWI.js.map +1 -1
  248. package/dist/esm/src/wallet/validationHelpers.js +9 -9
  249. package/dist/esm/src/wallet/validationHelpers.js.map +1 -1
  250. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  251. package/dist/types/src/auth/Peer.d.ts +13 -0
  252. package/dist/types/src/auth/Peer.d.ts.map +1 -1
  253. package/dist/types/src/auth/SessionManager.d.ts.map +1 -1
  254. package/dist/types/src/auth/clients/AuthFetch.d.ts.map +1 -1
  255. package/dist/types/src/compat/ECIES.d.ts.map +1 -1
  256. package/dist/types/src/compat/HD.d.ts.map +1 -1
  257. package/dist/types/src/identity/ContactsManager.d.ts +18 -0
  258. package/dist/types/src/identity/ContactsManager.d.ts.map +1 -1
  259. package/dist/types/src/identity/IdentityClient.d.ts +47 -8
  260. package/dist/types/src/identity/IdentityClient.d.ts.map +1 -1
  261. package/dist/types/src/kvstore/GlobalKVStore.d.ts.map +1 -1
  262. package/dist/types/src/overlay-tools/LookupResolver.d.ts +59 -1
  263. package/dist/types/src/overlay-tools/LookupResolver.d.ts.map +1 -1
  264. package/dist/types/src/overlay-tools/SHIPBroadcaster.d.ts +18 -3
  265. package/dist/types/src/overlay-tools/SHIPBroadcaster.d.ts.map +1 -1
  266. package/dist/types/src/primitives/BigNumber.d.ts +13 -3
  267. package/dist/types/src/primitives/BigNumber.d.ts.map +1 -1
  268. package/dist/types/src/primitives/Curve.d.ts.map +1 -1
  269. package/dist/types/src/primitives/ECDSA.d.ts.map +1 -1
  270. package/dist/types/src/primitives/Hash.d.ts +3 -3
  271. package/dist/types/src/primitives/Hash.d.ts.map +1 -1
  272. package/dist/types/src/primitives/JacobianPoint.d.ts +3 -1
  273. package/dist/types/src/primitives/JacobianPoint.d.ts.map +1 -1
  274. package/dist/types/src/primitives/Point.d.ts.map +1 -1
  275. package/dist/types/src/primitives/Random.d.ts +2 -2
  276. package/dist/types/src/primitives/Random.d.ts.map +1 -1
  277. package/dist/types/src/primitives/ReaderUint8Array.d.ts.map +1 -1
  278. package/dist/types/src/primitives/Schnorr.d.ts +2 -1
  279. package/dist/types/src/primitives/Schnorr.d.ts.map +1 -1
  280. package/dist/types/src/primitives/Secp256r1.d.ts.map +1 -1
  281. package/dist/types/src/primitives/utils.d.ts +2 -4
  282. package/dist/types/src/primitives/utils.d.ts.map +1 -1
  283. package/dist/types/src/registry/RegistryClient.d.ts.map +1 -1
  284. package/dist/types/src/remittance/RemittanceManager.d.ts.map +1 -1
  285. package/dist/types/src/remittance/modules/BasicBRC29.d.ts.map +1 -1
  286. package/dist/types/src/script/Script.d.ts +15 -8
  287. package/dist/types/src/script/Script.d.ts.map +1 -1
  288. package/dist/types/src/script/Spend.d.ts.map +1 -1
  289. package/dist/types/src/script/templates/PushDrop.d.ts +3 -1
  290. package/dist/types/src/script/templates/PushDrop.d.ts.map +1 -1
  291. package/dist/types/src/script/templates/RPuzzle.d.ts.map +1 -1
  292. package/dist/types/src/transaction/Beef.d.ts +46 -8
  293. package/dist/types/src/transaction/Beef.d.ts.map +1 -1
  294. package/dist/types/src/transaction/BeefConstants.d.ts +15 -0
  295. package/dist/types/src/transaction/BeefConstants.d.ts.map +1 -0
  296. package/dist/types/src/transaction/Transaction.d.ts.map +1 -1
  297. package/dist/types/src/wallet/CachedKeyDeriver.d.ts.map +1 -1
  298. package/dist/types/src/wallet/KeyDeriver.d.ts +1 -1
  299. package/dist/types/src/wallet/KeyDeriver.d.ts.map +1 -1
  300. package/dist/types/src/wallet/Wallet.interfaces.d.ts +2 -2
  301. package/dist/types/src/wallet/Wallet.interfaces.d.ts.map +1 -1
  302. package/dist/types/src/wallet/WalletClient.d.ts +7 -7
  303. package/dist/types/src/wallet/WalletClient.d.ts.map +1 -1
  304. package/dist/types/src/wallet/substrates/HTTPWalletJSON.d.ts +7 -7
  305. package/dist/types/src/wallet/substrates/HTTPWalletJSON.d.ts.map +1 -1
  306. package/dist/types/src/wallet/substrates/WalletWireTransceiver.d.ts +36 -7
  307. package/dist/types/src/wallet/substrates/WalletWireTransceiver.d.ts.map +1 -1
  308. package/dist/types/src/wallet/substrates/window.CWI.d.ts +8 -8
  309. package/dist/types/src/wallet/substrates/window.CWI.d.ts.map +1 -1
  310. package/dist/types/tsconfig.types.tsbuildinfo +1 -1
  311. package/dist/umd/bundle.js +3 -3
  312. package/docs/reference/kvstore.md +1 -2
  313. package/docs/reference/primitives.md +0 -1
  314. package/docs/reference/script.md +0 -7
  315. package/docs/reference/transaction.md +2 -2
  316. package/package.json +29 -28
  317. package/src/auth/Peer.ts +26 -13
  318. package/src/auth/SessionManager.ts +4 -7
  319. package/src/auth/certificates/MasterCertificate.ts +1 -1
  320. package/src/auth/certificates/__tests/CompletedProtoWallet.ts +1 -1
  321. package/src/auth/clients/AuthFetch.ts +41 -41
  322. package/src/auth/transports/SimplifiedFetchTransport.ts +4 -4
  323. package/src/compat/ECIES.ts +29 -34
  324. package/src/compat/HD.ts +10 -5
  325. package/src/compat/Mnemonic.ts +11 -11
  326. package/src/compat/__tests/HD.test.ts +19 -0
  327. package/src/identity/ContactsManager.ts +194 -257
  328. package/src/identity/IdentityClient.ts +155 -66
  329. package/src/identity/__tests/IdentityClient.test.ts +25 -1
  330. package/src/kvstore/GlobalKVStore.ts +31 -32
  331. package/src/kvstore/LocalKVStore.ts +8 -8
  332. package/src/kvstore/kvStoreInterpreter.ts +2 -2
  333. package/src/messages/SignedMessage.ts +1 -1
  334. package/src/overlay-tools/Historian.ts +1 -1
  335. package/src/overlay-tools/LookupResolver.ts +182 -45
  336. package/src/overlay-tools/SHIPBroadcaster.ts +92 -168
  337. package/src/primitives/AESGCM.ts +2 -2
  338. package/src/primitives/BigNumber.ts +122 -113
  339. package/src/primitives/Curve.ts +16 -15
  340. package/src/primitives/ECDSA.ts +10 -8
  341. package/src/primitives/Hash.ts +152 -53
  342. package/src/primitives/JacobianPoint.ts +13 -11
  343. package/src/primitives/K256.ts +3 -3
  344. package/src/primitives/Point.ts +35 -38
  345. package/src/primitives/PrivateKey.ts +3 -3
  346. package/src/primitives/PublicKey.ts +3 -3
  347. package/src/primitives/Random.ts +11 -14
  348. package/src/primitives/ReaderUint8Array.ts +7 -7
  349. package/src/primitives/Schnorr.ts +2 -1
  350. package/src/primitives/Secp256r1.ts +2 -1
  351. package/src/primitives/Signature.ts +8 -8
  352. package/src/primitives/TransactionSignature.ts +16 -16
  353. package/src/primitives/utils.ts +37 -47
  354. package/src/registry/RegistryClient.ts +25 -25
  355. package/src/remittance/RemittanceManager.ts +17 -18
  356. package/src/remittance/modules/BasicBRC29.ts +2 -5
  357. package/src/script/Script.ts +114 -170
  358. package/src/script/ScriptEvaluationError.ts +2 -2
  359. package/src/script/Spend.ts +14 -15
  360. package/src/script/templates/PushDrop.ts +5 -3
  361. package/src/script/templates/RPuzzle.ts +2 -4
  362. package/src/storage/StorageDownloader.ts +1 -1
  363. package/src/totp/totp.ts +1 -1
  364. package/src/transaction/Beef.ts +241 -203
  365. package/src/transaction/BeefConstants.ts +16 -0
  366. package/src/transaction/BeefTx.ts +3 -3
  367. package/src/transaction/MerklePath.ts +4 -4
  368. package/src/transaction/Transaction.ts +48 -51
  369. package/src/transaction/fee-models/SatoshisPerKilobyte.ts +1 -1
  370. package/src/transaction/http/BinaryFetchClient.ts +8 -8
  371. package/src/transaction/http/DefaultHttpClient.ts +8 -8
  372. package/src/wallet/CachedKeyDeriver.ts +8 -6
  373. package/src/wallet/KeyDeriver.ts +1 -1
  374. package/src/wallet/Wallet.interfaces.ts +2 -4
  375. package/src/wallet/WalletClient.ts +8 -8
  376. package/src/wallet/WalletError.ts +1 -1
  377. package/src/wallet/__tests/WalletClient.substrate.test.ts +10 -6
  378. package/src/wallet/substrates/HTTPWalletJSON.ts +22 -21
  379. package/src/wallet/substrates/ReactNativeWebView.ts +9 -9
  380. package/src/wallet/substrates/WalletWireProcessor.ts +83 -83
  381. package/src/wallet/substrates/WalletWireTransceiver.ts +528 -938
  382. package/src/wallet/substrates/XDM.ts +4 -4
  383. package/src/wallet/substrates/__tests/HTTPWalletJSON.test.ts +38 -25
  384. package/src/wallet/substrates/__tests/ReactNativeWebView.test.ts +174 -0
  385. package/src/wallet/substrates/__tests/window.CWI.test.ts +256 -0
  386. package/src/wallet/substrates/window.CWI.ts +10 -10
  387. package/src/wallet/validationHelpers.ts +9 -9
  388. package/docs/swagger/dist/LICENSE +0 -21
  389. package/docs/swagger/dist/favicon-16x16.png +0 -0
  390. package/docs/swagger/dist/favicon-32x32.png +0 -0
  391. package/docs/swagger/dist/index.css +0 -16
  392. package/docs/swagger/dist/oauth2-redirect.html +0 -79
  393. package/docs/swagger/dist/swagger-initializer.js +0 -20
  394. package/docs/swagger/dist/swagger-ui-bundle.js +0 -2
  395. package/docs/swagger/dist/swagger-ui-bundle.js.map +0 -1
  396. package/docs/swagger/dist/swagger-ui-es-bundle-core.js +0 -3
  397. package/docs/swagger/dist/swagger-ui-es-bundle-core.js.map +0 -1
  398. package/docs/swagger/dist/swagger-ui-es-bundle.js +0 -2
  399. package/docs/swagger/dist/swagger-ui-es-bundle.js.map +0 -1
  400. package/docs/swagger/dist/swagger-ui-standalone-preset.js +0 -2
  401. package/docs/swagger/dist/swagger-ui-standalone-preset.js.map +0 -1
  402. package/docs/swagger/dist/swagger-ui.css +0 -3
  403. package/docs/swagger/dist/swagger-ui.css.map +0 -1
  404. package/docs/swagger/dist/swagger-ui.js +0 -2
  405. package/docs/swagger/dist/swagger-ui.js.map +0 -1
@@ -331,7 +331,7 @@ export default class MerklePath {
331
331
  const l = offset << 1
332
332
 
333
333
  const leaf0 = this.findOrComputeLeaf(h, l)
334
- if (leaf0 == null || leaf0.hash == null || leaf0.hash === '') return undefined
334
+ if (leaf0?.hash == null || leaf0.hash === '') return undefined
335
335
 
336
336
  const leaf1 = this.findOrComputeLeaf(h, l + 1)
337
337
  if (leaf1?.hash == null) {
@@ -431,7 +431,7 @@ export default class MerklePath {
431
431
  */
432
432
  trim (): void {
433
433
  const pushIfNew = (v: number, a: number[]): void => {
434
- if (a.length === 0 || a.slice(-1)[0] !== v) {
434
+ if (a.length === 0 || a.at(-1) !== v) {
435
435
  a.push(v)
436
436
  }
437
437
  }
@@ -457,9 +457,9 @@ export default class MerklePath {
457
457
 
458
458
  let computedOffsets: number[] = [] // in next level
459
459
  let dropOffsets: number[] = []
460
- for (let h = 0; h < this.path.length; h++) {
460
+ for (const level of this.path) {
461
461
  // Sort each level by increasing offset order
462
- this.path[h].sort((a, b) => a.offset - b.offset)
462
+ level.sort((a, b) => a.offset - b.offset)
463
463
  }
464
464
  for (let l = 0; l < this.path[0].length; l++) {
465
465
  const n = this.path[0][l]
@@ -17,6 +17,7 @@ import { Beef, BEEF_V1 } from './Beef.js'
17
17
  import P2PKH from '../script/templates/P2PKH.js'
18
18
  import type { WalletInterface, DescriptionString5to50Bytes, CreateActionOptions } from '../wallet/Wallet.interfaces.js'
19
19
  import TransactionSignature from '../primitives/TransactionSignature.js'
20
+ import Random from '../primitives/Random.js'
20
21
 
21
22
  /**
22
23
  * Represents a complete Bitcoin transaction. This class encapsulates all the details
@@ -79,7 +80,7 @@ export default class Transaction {
79
80
  if (typeof obj.pathIndex === 'number') {
80
81
  const path = BUMPs[obj.pathIndex]
81
82
  if (typeof path !== 'object') {
82
- throw new Error('Invalid merkle path index found in BEEF!')
83
+ throw new TypeError('Invalid merkle path index found in BEEF!')
83
84
  }
84
85
  obj.tx.merklePath = path
85
86
  } else {
@@ -89,7 +90,7 @@ export default class Transaction {
89
90
  }
90
91
  const sourceObj = transactions[input.sourceTXID]
91
92
  if (typeof sourceObj !== 'object') {
92
- throw new Error(
93
+ throw new TypeError(
93
94
  `Reference to unknown TXID in BEEF: ${input.sourceTXID ?? 'undefined'}`
94
95
  )
95
96
  }
@@ -123,10 +124,10 @@ export default class Transaction {
123
124
  static fromAtomicBEEF (beef: number[] | Uint8Array): Transaction {
124
125
  const { tx, txid, beef: b } = Transaction.fromAnyBeef(beef)
125
126
  if (txid !== b.atomicTxid) {
126
- if (b.atomicTxid != null) {
127
- throw new Error(`Transaction with TXID ${b.atomicTxid} not found in BEEF data.`)
128
- } else {
127
+ if (b.atomicTxid == null) {
129
128
  throw new Error('beef must conform to BRC-95 and must contain the subject txid.')
129
+ } else {
130
+ throw new Error(`Transaction with TXID ${b.atomicTxid} not found in BEEF data.`)
130
131
  }
131
132
  }
132
133
  return tx
@@ -137,13 +138,17 @@ export default class Transaction {
137
138
  if (b.txs.length < 1) {
138
139
  throw new Error('beef must include at least one transaction.')
139
140
  }
140
- const target = txid ?? b.atomicTxid ?? b.txs.slice(-1)[0].txid
141
+ const lastTx = b.txs.at(-1)
142
+ if (lastTx == null) {
143
+ throw new Error('beef must include at least one transaction.')
144
+ }
145
+ const target = txid ?? b.atomicTxid ?? lastTx.txid
141
146
  const tx = b.findAtomicTransaction(target)
142
147
  if (tx == null) {
143
- if (txid != null) {
144
- throw new Error(`Transaction with TXID ${target} not found in BEEF data.`)
145
- } else {
148
+ if (txid == null) {
146
149
  throw new Error('beef does not contain transaction for atomic txid.')
150
+ } else {
151
+ throw new Error(`Transaction with TXID ${String(target)} not found in BEEF data.`)
147
152
  }
148
153
  }
149
154
  return { tx, beef: b, txid: target }
@@ -172,7 +177,7 @@ export default class Transaction {
172
177
  const lockingScriptBin = br.read(lockingScriptLength)
173
178
  const lockingScript = LockingScript.fromBinary(lockingScriptBin)
174
179
  const sourceTransaction = new Transaction(undefined, [], [], undefined)
175
- sourceTransaction.outputs = Array(sourceOutputIndex + 1).fill(null)
180
+ sourceTransaction.outputs = new Array(sourceOutputIndex + 1).fill(null)
176
181
  sourceTransaction.outputs[sourceOutputIndex] = {
177
182
  satoshis,
178
183
  lockingScript
@@ -364,17 +369,15 @@ export default class Transaction {
364
369
  */
365
370
  addInput (input: TransactionInput): void {
366
371
  if (
367
- typeof input.sourceTXID === 'undefined' &&
368
- typeof input.sourceTransaction === 'undefined'
372
+ input.sourceTXID === undefined &&
373
+ input.sourceTransaction === undefined
369
374
  ) {
370
- throw new Error(
375
+ throw new TypeError(
371
376
  'A reference to an an input transaction is required. If the input transaction itself cannot be referenced, its TXID must still be provided.'
372
377
  )
373
378
  }
374
379
  // If the input sequence number hasn't been set, the expectation is that it is final.
375
- if (typeof input.sequence === 'undefined') {
376
- input.sequence = 0xffffffff
377
- }
380
+ input.sequence ??= 0xffffffff
378
381
  this.invalidateSerializationCaches()
379
382
  this.inputs.push(input)
380
383
  }
@@ -387,8 +390,8 @@ export default class Transaction {
387
390
  addOutput (output: TransactionOutput): void {
388
391
  this.cachedHash = undefined
389
392
  if (output.change !== true) {
390
- if (typeof output.satoshis === 'undefined') {
391
- throw new Error(
393
+ if (output.satoshis === undefined) {
394
+ throw new TypeError(
392
395
  'either satoshis must be defined or change must be set to true'
393
396
  )
394
397
  }
@@ -407,7 +410,7 @@ export default class Transaction {
407
410
  */
408
411
  addP2PKHOutput (address: number[] | string, satoshis?: number): void {
409
412
  const lockingScript = new P2PKH().lock(address)
410
- if (typeof satoshis === 'undefined') {
413
+ if (satoshis === undefined) {
411
414
  return this.addOutput({ lockingScript, change: true })
412
415
  }
413
416
  this.addOutput({
@@ -462,7 +465,7 @@ export default class Transaction {
462
465
  let change = 0
463
466
  for (const input of this.inputs) {
464
467
  if (typeof input.sourceTransaction !== 'object') {
465
- throw new Error(
468
+ throw new TypeError(
466
469
  'Source transactions are required for all inputs during fee computation'
467
470
  )
468
471
  }
@@ -492,11 +495,11 @@ export default class Transaction {
492
495
  distributedChange = this.distributeEqualChange(change, changeOutputs)
493
496
  }
494
497
  if (distributedChange < change) {
495
- const lastOutput = this.outputs[this.outputs.length - 1]
496
- if (lastOutput.satoshis !== undefined) {
497
- lastOutput.satoshis += change - distributedChange
498
- } else {
498
+ const lastOutput = this.outputs.at(-1)
499
+ if (lastOutput.satoshis === undefined) {
499
500
  lastOutput.satoshis = change - distributedChange
501
+ } else {
502
+ lastOutput.satoshis += change - distributedChange
500
503
  }
501
504
  }
502
505
  }
@@ -507,7 +510,7 @@ export default class Transaction {
507
510
  ): number {
508
511
  let distributedChange = 0
509
512
  let changeToUse = change
510
- const benfordNumbers = Array(changeOutputs.length).fill(1)
513
+ const benfordNumbers = new Array(changeOutputs.length).fill(1)
511
514
  changeToUse -= changeOutputs.length
512
515
  distributedChange += changeOutputs.length
513
516
  for (let i = 0; i < changeOutputs.length - 1; i++) {
@@ -536,7 +539,7 @@ export default class Transaction {
536
539
  }
537
540
 
538
541
  private benfordNumber (min: number, max: number): number {
539
- const d = Math.floor(Math.random() * 9) + 1
542
+ const d = Random(1)[0] % 9 + 1
540
543
  return Math.floor(
541
544
  min + ((max - min) * Math.log10(1 + 1 / d)) / Math.log10(10)
542
545
  )
@@ -551,7 +554,7 @@ export default class Transaction {
551
554
  let totalIn = 0
552
555
  for (const input of this.inputs) {
553
556
  if (typeof input.sourceTransaction !== 'object') {
554
- throw new Error(
557
+ throw new TypeError(
555
558
  'Source transactions or sourceSatoshis are required for all inputs to calculate fee'
556
559
  )
557
560
  }
@@ -571,7 +574,7 @@ export default class Transaction {
571
574
  async sign (): Promise<void> {
572
575
  this.invalidateSerializationCaches()
573
576
  for (const out of this.outputs) {
574
- if (typeof out.satoshis === 'undefined') {
577
+ if (out.satoshis === undefined) {
575
578
  if (out.change === true) {
576
579
  throw new Error(
577
580
  'There are still change outputs with uncomputed amounts. Use the fee() method to compute the change amounts and transaction fees prior to signing.'
@@ -615,11 +618,11 @@ export default class Transaction {
615
618
  writer.writeUInt32LE(this.version)
616
619
  writer.writeVarIntNum(this.inputs.length)
617
620
  for (const i of this.inputs) {
618
- if (typeof i.sourceTXID === 'undefined') {
619
- if (i.sourceTransaction != null) {
620
- writer.write(i.sourceTransaction.hash() as number[])
621
- } else {
621
+ if (i.sourceTXID === undefined) {
622
+ if (i.sourceTransaction == null) {
622
623
  throw new Error('sourceTransaction is undefined')
624
+ } else {
625
+ writer.write(i.sourceTransaction.hash() as number[])
623
626
  }
624
627
  } else {
625
628
  writer.writeReverse(toArray(i.sourceTXID, 'hex'))
@@ -650,9 +653,7 @@ export default class Transaction {
650
653
  }
651
654
 
652
655
  private getSerializedBytes (): Uint8Array {
653
- if (this.rawBytesCache == null) {
654
- this.rawBytesCache = this.buildSerializedBytes()
655
- }
656
+ this.rawBytesCache ??= this.buildSerializedBytes()
656
657
  return this.rawBytesCache
657
658
  }
658
659
 
@@ -674,12 +675,12 @@ export default class Transaction {
674
675
  writer.write([0, 0, 0, 0, 0, 0xef])
675
676
  writer.writeVarIntNum(this.inputs.length)
676
677
  for (const i of this.inputs) {
677
- if (typeof i.sourceTransaction === 'undefined') {
678
- throw new Error(
678
+ if (i.sourceTransaction === undefined) {
679
+ throw new TypeError(
679
680
  'All inputs must have source transactions when serializing to EF format'
680
681
  )
681
682
  }
682
- if (typeof i.sourceTXID === 'undefined') {
683
+ if (i.sourceTXID === undefined) {
683
684
  writer.write(i.sourceTransaction.hash() as number[])
684
685
  } else {
685
686
  writer.write(toArray(i.sourceTXID, 'hex').reverse() as number[])
@@ -783,9 +784,7 @@ export default class Transaction {
783
784
  * @returns {string | number[]} - The hash of the transaction in the specified format.
784
785
  */
785
786
  hash (enc?: 'hex'): number[] | string {
786
- if (this.cachedHash == null) {
787
- this.cachedHash = hash256(this.getSerializedBytes())
788
- }
787
+ this.cachedHash ??= hash256(this.getSerializedBytes())
789
788
  if (enc === 'hex') {
790
789
  return toHex(this.cachedHash)
791
790
  }
@@ -866,7 +865,7 @@ export default class Transaction {
866
865
  }
867
866
 
868
867
  // Verify fee if feeModel is provided
869
- if (typeof feeModel !== 'undefined') {
868
+ if (feeModel !== undefined) {
870
869
  if (tx === undefined) {
871
870
  throw new Error('Transaction is undefined')
872
871
  }
@@ -890,12 +889,12 @@ export default class Transaction {
890
889
  for (let i = 0; i < tx.inputs.length; i++) {
891
890
  const input = tx.inputs[i]
892
891
  if (typeof input.sourceTransaction !== 'object') {
893
- throw new Error(
892
+ throw new TypeError(
894
893
  `Verification failed because the input at index ${i} of transaction ${txid} is missing an associated source transaction. This source transaction is required for transaction verification because there is no merkle proof for the transaction spending a UTXO it contains.`
895
894
  )
896
895
  }
897
896
  if (typeof input.unlockingScript !== 'object') {
898
- throw new Error(
897
+ throw new TypeError(
899
898
  `Verification failed because the input at index ${i} of transaction ${txid} is missing an associated unlocking script. This script is required for transaction verification because there is no merkle proof for the transaction spending the UTXO.`
900
899
  )
901
900
  }
@@ -909,9 +908,7 @@ export default class Transaction {
909
908
  }
910
909
 
911
910
  const otherInputs = tx.inputs.filter((_, idx) => idx !== i)
912
- if (typeof input.sourceTXID === 'undefined') {
913
- input.sourceTXID = sourceTxid
914
- }
911
+ input.sourceTXID ??= sourceTxid
915
912
 
916
913
  const spend = new Spend({
917
914
  sourceTXID: input.sourceTXID,
@@ -938,7 +935,7 @@ export default class Transaction {
938
935
  let outputTotal = 0
939
936
  for (const out of tx.outputs) {
940
937
  if (typeof out.satoshis !== 'number') {
941
- throw new Error(
938
+ throw new TypeError(
942
939
  'Every output must have a defined amount during transaction verification.'
943
940
  )
944
941
  }
@@ -1240,14 +1237,14 @@ export default class Transaction {
1240
1237
  }
1241
1238
 
1242
1239
  // Extract options that apply to signAction (subset of CreateActionOptions)
1243
- const signActionOptions: SignActionOptions | undefined = options != null
1244
- ? {
1240
+ const signActionOptions: SignActionOptions | undefined = options == null
1241
+ ? undefined
1242
+ : {
1245
1243
  acceptDelayedBroadcast: options.acceptDelayedBroadcast,
1246
1244
  returnTXIDOnly: options.returnTXIDOnly,
1247
1245
  noSend: options.noSend,
1248
1246
  sendWith: options.sendWith
1249
1247
  }
1250
- : undefined
1251
1248
 
1252
1249
  // Call signAction with the generated unlocking scripts
1253
1250
  const signResult = await wallet.signAction({
@@ -53,7 +53,7 @@ export default class SatoshisPerKilobyte implements FeeModel {
53
53
  i
54
54
  )
55
55
  } else {
56
- throw new Error(
56
+ throw new TypeError(
57
57
  'All inputs must have an unlocking script or an unlocking script template for sat/kb fee computation.'
58
58
  )
59
59
  }
@@ -98,23 +98,23 @@ export function binaryHttpClient(): HttpClient {
98
98
  }
99
99
  }
100
100
 
101
- if (typeof window !== 'undefined' && typeof window.fetch === 'function') {
101
+ if (globalThis.window !== undefined && typeof globalThis.window.fetch === 'function') {
102
102
  // Browser tab/page context
103
- return new BinaryFetchClient(window.fetch.bind(window))
103
+ return new BinaryFetchClient(globalThis.window.fetch.bind(globalThis.window))
104
104
  } else if (typeof globalThis.fetch === 'function') {
105
105
  // Service workers, Deno, Node 18+ (any environment with global fetch)
106
106
  return new BinaryFetchClient(globalThis.fetch.bind(globalThis))
107
- } else if (typeof require !== 'undefined') {
107
+ } else if (typeof require === 'undefined') {
108
+ return noHttpClient
109
+ } else {
108
110
  // Older Node.js — use https module
109
- // eslint-disable-next-line
110
111
  try {
111
112
  // eslint-disable-next-line @typescript-eslint/no-var-requires
112
- const https = require('https')
113
+ const https = require('node:https')
113
114
  return new BinaryNodejsHttpClient(https)
114
- } catch (e) {
115
+ } catch (_httpsModuleUnavailable) {
116
+ // node:https not available in this runtime; fall through to noHttpClient
115
117
  return noHttpClient
116
118
  }
117
- } else {
118
- return noHttpClient
119
119
  }
120
120
  }
@@ -14,23 +14,23 @@ export function defaultHttpClient(): HttpClient {
14
14
  }
15
15
  }
16
16
 
17
- if (typeof window !== 'undefined' && typeof window.fetch === 'function') {
17
+ if (globalThis.window !== undefined && typeof globalThis.window.fetch === 'function') {
18
18
  // Browser tab/page context
19
- return new FetchHttpClient(window.fetch.bind(window))
19
+ return new FetchHttpClient(globalThis.window.fetch.bind(globalThis.window))
20
20
  } else if (typeof globalThis.fetch === 'function') {
21
21
  // Service workers, Deno, Node 18+ (any environment with global fetch)
22
22
  return new FetchHttpClient(globalThis.fetch.bind(globalThis))
23
- } else if (typeof require !== 'undefined') {
23
+ } else if (typeof require === 'undefined') {
24
+ return noHttpClient
25
+ } else {
24
26
  // Older Node.js — use https module
25
- // eslint-disable-next-line
26
27
  try {
27
28
  // eslint-disable-next-line @typescript-eslint/no-var-requires
28
- const https = require('https')
29
+ const https = require('node:https')
29
30
  return new NodejsHttpClient(https)
30
- } catch (e) {
31
+ } catch (_httpsModuleUnavailable) {
32
+ // node:https not available in this runtime; fall through to noHttpClient
31
33
  return noHttpClient
32
34
  }
33
- } else {
34
- return noHttpClient
35
35
  }
36
36
  }
@@ -2,6 +2,8 @@ import { Point, PrivateKey, PublicKey, SymmetricKey } from '../primitives/index.
2
2
  import { Counterparty, KeyDeriver, KeyDeriverApi } from './KeyDeriver.js'
3
3
  import { WalletProtocol } from './Wallet.interfaces.js'
4
4
 
5
+ type CachedKeyValue = PublicKey | PrivateKey | SymmetricKey | Point | number[]
6
+
5
7
  /**
6
8
  * A cached version of KeyDeriver that caches the results of key derivation methods.
7
9
  * This is useful for optimizing performance when the same keys are derived multiple times.
@@ -9,7 +11,7 @@ import { WalletProtocol } from './Wallet.interfaces.js'
9
11
  */
10
12
  export default class CachedKeyDeriver implements KeyDeriverApi {
11
13
  private readonly keyDeriver: KeyDeriver
12
- private readonly cache: Map<string, PublicKey | PrivateKey | SymmetricKey | Point | number[]>
14
+ private readonly cache: Map<string, CachedKeyValue>
13
15
  private readonly maxCacheSize: number
14
16
 
15
17
  /**
@@ -47,9 +49,9 @@ export default class CachedKeyDeriver implements KeyDeriverApi {
47
49
  }
48
50
  )
49
51
  this.identityKey = this.rootKey.toPublicKey().toString()
50
- this.cache = new Map<string, PublicKey | PrivateKey | SymmetricKey | Point | number[]>()
52
+ this.cache = new Map<string, CachedKeyValue>()
51
53
  const maxCacheSize = options?.maxCacheSize
52
- this.maxCacheSize = (maxCacheSize != null && !isNaN(maxCacheSize) && maxCacheSize > 0) ? maxCacheSize : 1000
54
+ this.maxCacheSize = (maxCacheSize != null && !Number.isNaN(maxCacheSize) && maxCacheSize > 0) ? maxCacheSize : 1000
53
55
  }
54
56
 
55
57
  /**
@@ -252,7 +254,7 @@ export default class CachedKeyDeriver implements KeyDeriverApi {
252
254
  } else if (typeof arg === 'object' && arg !== null) {
253
255
  return JSON.stringify(arg)
254
256
  } else {
255
- return String(arg)
257
+ return String(arg as string | number | boolean)
256
258
  }
257
259
  }
258
260
 
@@ -261,7 +263,7 @@ export default class CachedKeyDeriver implements KeyDeriverApi {
261
263
  * @param {string} cacheKey - The key of the cached item.
262
264
  * @returns {any} - The cached value.
263
265
  */
264
- private cacheGet (cacheKey: string): PublicKey | PrivateKey | SymmetricKey | Point | number[] | undefined {
266
+ private cacheGet (cacheKey: string): CachedKeyValue | undefined {
265
267
  const value = this.cache.get(cacheKey)
266
268
  // Update the entry to reflect recent use
267
269
  this.cache.delete(cacheKey)
@@ -276,7 +278,7 @@ export default class CachedKeyDeriver implements KeyDeriverApi {
276
278
  * @param {string} cacheKey - The key of the item to cache.
277
279
  * @param {any} value - The value to cache.
278
280
  */
279
- private cacheSet (cacheKey: string, value: PublicKey | PrivateKey | SymmetricKey | Point | number[]): void {
281
+ private cacheSet (cacheKey: string, value: CachedKeyValue): void {
280
282
  if (this.cache.size >= this.maxCacheSize) {
281
283
  // Evict the least recently used item (first item in Map)
282
284
  const firstKey = this.cache.keys().next().value
@@ -8,7 +8,7 @@ import {
8
8
  } from '../primitives/index.js'
9
9
  import { WalletProtocol, PubKeyHex } from './Wallet.interfaces.js'
10
10
 
11
- export type Counterparty = PublicKey | PubKeyHex | 'self' | 'anyone'
11
+ export type Counterparty = PublicKey | PubKeyHex
12
12
 
13
13
  export interface KeyDeriverApi {
14
14
  /**
@@ -216,11 +216,11 @@ export type SecurityLevel = 0 | 1 | 2
216
216
 
217
217
  export type WalletProtocol = [SecurityLevel, ProtocolString5To400Bytes]
218
218
 
219
- export type WalletCounterparty = PubKeyHex | 'self' | 'anyone'
219
+ export type WalletCounterparty = PubKeyHex
220
220
 
221
221
  export type AcquisitionProtocol = 'direct' | 'issuance'
222
222
 
223
- export type KeyringRevealer = PubKeyHex | 'certifier'
223
+ export type KeyringRevealer = PubKeyHex
224
224
 
225
225
  export type ActionStatus =
226
226
  | 'completed'
@@ -935,8 +935,6 @@ export interface DiscoverByAttributesArgs {
935
935
  seekPermission?: BooleanDefaultTrue
936
936
  }
937
937
 
938
- // export interface AcquireCertificateResult extends WalletCertificate {}
939
-
940
938
  /**
941
939
  * Every method of the `Wallet` interface has a return value of the form `Promise<object>`.
942
940
  * When errors occur, an exception object may be thrown which must conform to the `WalletErrorObject` interface.
@@ -131,7 +131,7 @@ export default class WalletClient implements WalletInterface {
131
131
  const fastResults = await Promise.allSettled(fastAttempts)
132
132
  const fastSuccessful = fastResults
133
133
  .filter((r): r is PromiseFulfilledResult<{ success: boolean, sub?: WalletInterface }> => r.status === 'fulfilled' && r.value.success && r.value.sub !== undefined)
134
- .map(r => r.value.sub as WalletInterface)
134
+ .map(r => r.value.sub)
135
135
 
136
136
  if (fastSuccessful.length > 0) {
137
137
  this.substrate = fastSuccessful[0]
@@ -225,7 +225,7 @@ export default class WalletClient implements WalletInterface {
225
225
  keyID?: KeyIDStringUnder800Bytes
226
226
  privileged?: BooleanDefaultFalse
227
227
  privilegedReason?: DescriptionString5to50Bytes
228
- counterparty?: PubKeyHex | 'self' | 'anyone'
228
+ counterparty?: PubKeyHex
229
229
  forSelf?: BooleanDefaultFalse
230
230
  }): Promise<{ publicKey: PubKeyHex }> {
231
231
  await this.connectToSubstrate()
@@ -283,7 +283,7 @@ export default class WalletClient implements WalletInterface {
283
283
  protocolID: [SecurityLevel, ProtocolString5To400Bytes]
284
284
  keyID: KeyIDStringUnder800Bytes
285
285
  privilegedReason?: DescriptionString5to50Bytes
286
- counterparty?: PubKeyHex | 'self' | 'anyone'
286
+ counterparty?: PubKeyHex
287
287
  privileged?: BooleanDefaultFalse
288
288
  }): Promise<{ ciphertext: Byte[] }> {
289
289
  await this.connectToSubstrate()
@@ -298,7 +298,7 @@ export default class WalletClient implements WalletInterface {
298
298
  protocolID: [SecurityLevel, ProtocolString5To400Bytes]
299
299
  keyID: KeyIDStringUnder800Bytes
300
300
  privilegedReason?: DescriptionString5to50Bytes
301
- counterparty?: PubKeyHex | 'self' | 'anyone'
301
+ counterparty?: PubKeyHex
302
302
  privileged?: BooleanDefaultFalse
303
303
  }): Promise<{ plaintext: Byte[] }> {
304
304
  await this.connectToSubstrate()
@@ -313,7 +313,7 @@ export default class WalletClient implements WalletInterface {
313
313
  protocolID: [SecurityLevel, ProtocolString5To400Bytes]
314
314
  keyID: KeyIDStringUnder800Bytes
315
315
  privilegedReason?: DescriptionString5to50Bytes
316
- counterparty?: PubKeyHex | 'self' | 'anyone'
316
+ counterparty?: PubKeyHex
317
317
  privileged?: BooleanDefaultFalse
318
318
  }): Promise<{ hmac: Byte[] }> {
319
319
  await this.connectToSubstrate()
@@ -329,7 +329,7 @@ export default class WalletClient implements WalletInterface {
329
329
  protocolID: [SecurityLevel, ProtocolString5To400Bytes]
330
330
  keyID: KeyIDStringUnder800Bytes
331
331
  privilegedReason?: DescriptionString5to50Bytes
332
- counterparty?: PubKeyHex | 'self' | 'anyone'
332
+ counterparty?: PubKeyHex
333
333
  privileged?: BooleanDefaultFalse
334
334
  }): Promise<{ valid: true }> {
335
335
  await this.connectToSubstrate()
@@ -345,7 +345,7 @@ export default class WalletClient implements WalletInterface {
345
345
  protocolID: [SecurityLevel, ProtocolString5To400Bytes]
346
346
  keyID: KeyIDStringUnder800Bytes
347
347
  privilegedReason?: DescriptionString5to50Bytes
348
- counterparty?: PubKeyHex | 'self' | 'anyone'
348
+ counterparty?: PubKeyHex
349
349
  privileged?: BooleanDefaultFalse
350
350
  }): Promise<{ signature: Byte[] }> {
351
351
  await this.connectToSubstrate()
@@ -362,7 +362,7 @@ export default class WalletClient implements WalletInterface {
362
362
  protocolID: [SecurityLevel, ProtocolString5To400Bytes]
363
363
  keyID: KeyIDStringUnder800Bytes
364
364
  privilegedReason?: DescriptionString5to50Bytes
365
- counterparty?: PubKeyHex | 'self' | 'anyone'
365
+ counterparty?: PubKeyHex
366
366
  forSelf?: BooleanDefaultFalse
367
367
  privileged?: BooleanDefaultFalse
368
368
  }): Promise<{ valid: true }> {
@@ -25,7 +25,7 @@ export class WalletError extends Error {
25
25
  * @returns stringified JSON representation of the error such that it can be deserialized to a WalletError.
26
26
  */
27
27
  static unknownToJson (error: any): string {
28
- let e: any | undefined
28
+ let e: any
29
29
  if (error.isError === true && String(error.name).startsWith('WERR_')) {
30
30
  e = {
31
31
  name: error.name,
@@ -749,11 +749,15 @@ describe('WalletClient.listOutputs – substrate delegation', () => {
749
749
 
750
750
  describe('WalletClient.connectToSubstrate – error when no substrate available', () => {
751
751
  it('throws a descriptive error when auto-substrate fails to connect', async () => {
752
- // The 'auto' substrate string means connectToSubstrate will try real substrates.
753
- // All of them will fail in a test environment, so an error should be thrown.
754
- const client = new WalletClient('auto', 'test.origin')
755
- await expect(client.connectToSubstrate()).rejects.toThrow(
756
- 'No wallet available over any communication substrate'
757
- )
752
+ const fetchSpy = jest.spyOn(globalThis, 'fetch').mockRejectedValue(new Error('No test wallet available'))
753
+
754
+ try {
755
+ const client = new WalletClient('auto', 'test.origin')
756
+ await expect(client.connectToSubstrate()).rejects.toThrow(
757
+ 'No wallet available over any communication substrate'
758
+ )
759
+ } finally {
760
+ fetchSpy.mockRestore()
761
+ }
758
762
  }, 10000)
759
763
  })