@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
@@ -41,6 +41,16 @@ const Certificate_js_1 = __importDefault(require("../../auth/certificates/Certif
41
41
  const Utils = __importStar(require("../../primitives/utils.js"));
42
42
  const WalletWireCalls_js_1 = __importDefault(require("./WalletWireCalls.js"));
43
43
  const WalletError_js_1 = require("../WalletError.js");
44
+ const ACTION_STATUS_MAP = {
45
+ 1: 'completed',
46
+ 2: 'unprocessed',
47
+ 3: 'sending',
48
+ 4: 'unproven',
49
+ 5: 'unsigned',
50
+ 6: 'nosend',
51
+ 7: 'nonfinal',
52
+ 8: 'failed'
53
+ };
44
54
  /**
45
55
  * A way to make remote calls to a wallet over a wallet wire.
46
56
  */
@@ -82,259 +92,69 @@ class WalletWireTransceiver {
82
92
  async createAction(args, originator) {
83
93
  const paramWriter = new Utils.Writer();
84
94
  // Serialize description
85
- const descriptionBytes = Utils.toArray(args.description, 'utf8');
86
- paramWriter.writeVarIntNum(descriptionBytes.length);
87
- paramWriter.write(descriptionBytes);
95
+ this.writeUTF8(paramWriter, args.description);
88
96
  // input BEEF
89
- if (args.inputBEEF != null) {
97
+ if (args.inputBEEF == null) {
98
+ paramWriter.writeVarIntNum(-1);
99
+ }
100
+ else {
90
101
  paramWriter.writeVarIntNum(args.inputBEEF.length);
91
102
  paramWriter.write(args.inputBEEF);
92
103
  }
93
- else {
104
+ // Serialize inputs
105
+ if (args.inputs == null) {
94
106
  paramWriter.writeVarIntNum(-1);
95
107
  }
96
- // Serialize inputs
97
- if (args.inputs != null) {
108
+ else {
98
109
  paramWriter.writeVarIntNum(args.inputs.length);
99
110
  for (const input of args.inputs) {
100
- // outpoint
101
- paramWriter.write(this.encodeOutpoint(input.outpoint));
102
- // unlockingScript / unlockingScriptLength
103
- if (input.unlockingScript != null && input.unlockingScript !== '') {
104
- const unlockingScriptBytes = Utils.toArray(input.unlockingScript, 'hex');
105
- paramWriter.writeVarIntNum(unlockingScriptBytes.length);
106
- paramWriter.write(unlockingScriptBytes);
107
- }
108
- else {
109
- paramWriter.writeVarIntNum(-1);
110
- paramWriter.writeVarIntNum(input.unlockingScriptLength ?? 0);
111
- }
112
- // inputDescription
113
- const inputDescriptionBytes = Utils.toArray(input.inputDescription, 'utf8');
114
- paramWriter.writeVarIntNum(inputDescriptionBytes.length);
115
- paramWriter.write(inputDescriptionBytes);
116
- // sequenceNumber
117
- if (typeof input.sequenceNumber === 'number') {
118
- paramWriter.writeVarIntNum(input.sequenceNumber);
119
- }
120
- else {
121
- paramWriter.writeVarIntNum(-1);
122
- }
111
+ this.serializeCreateActionInput(paramWriter, input);
123
112
  }
124
113
  }
125
- else {
114
+ // Serialize outputs
115
+ if (args.outputs == null) {
126
116
  paramWriter.writeVarIntNum(-1);
127
117
  }
128
- // Serialize outputs
129
- if (args.outputs != null) {
118
+ else {
130
119
  paramWriter.writeVarIntNum(args.outputs.length);
131
120
  for (const output of args.outputs) {
132
- // lockingScript
133
- const lockingScriptBytes = Utils.toArray(output.lockingScript, 'hex');
134
- paramWriter.writeVarIntNum(lockingScriptBytes.length);
135
- paramWriter.write(lockingScriptBytes);
136
- // satoshis
137
- paramWriter.writeVarIntNum(output.satoshis);
138
- // outputDescription
139
- const outputDescriptionBytes = Utils.toArray(output.outputDescription, 'utf8');
140
- paramWriter.writeVarIntNum(outputDescriptionBytes.length);
141
- paramWriter.write(outputDescriptionBytes);
142
- // basket
143
- if (output.basket != null && output.basket !== '') {
144
- const basketBytes = Utils.toArray(output.basket, 'utf8');
145
- paramWriter.writeVarIntNum(basketBytes.length);
146
- paramWriter.write(basketBytes);
147
- }
148
- else {
149
- paramWriter.writeVarIntNum(-1);
150
- }
151
- // customInstructions
152
- if (output.customInstructions != null && output.customInstructions !== '') {
153
- const customInstructionsBytes = Utils.toArray(output.customInstructions, 'utf8');
154
- paramWriter.writeVarIntNum(customInstructionsBytes.length);
155
- paramWriter.write(customInstructionsBytes);
156
- }
157
- else {
158
- paramWriter.writeVarIntNum(-1);
159
- }
160
- // tags
161
- if (output.tags != null) {
162
- paramWriter.writeVarIntNum(output.tags.length);
163
- for (const tag of output.tags) {
164
- const tagBytes = Utils.toArray(tag, 'utf8');
165
- paramWriter.writeVarIntNum(tagBytes.length);
166
- paramWriter.write(tagBytes);
167
- }
168
- }
169
- else {
170
- paramWriter.writeVarIntNum(-1);
171
- }
121
+ this.serializeCreateActionOutput(paramWriter, output);
172
122
  }
173
123
  }
174
- else {
175
- paramWriter.writeVarIntNum(-1);
176
- }
177
- // Serialize lockTime
178
- if (typeof args.lockTime === 'number') {
179
- paramWriter.writeVarIntNum(args.lockTime);
180
- }
181
- else {
182
- paramWriter.writeVarIntNum(-1);
183
- }
184
- // Serialize version
185
- if (typeof args.version === 'number') {
186
- paramWriter.writeVarIntNum(args.version);
187
- }
188
- else {
189
- paramWriter.writeVarIntNum(-1);
190
- }
124
+ // Serialize lockTime, version
125
+ this.writeOptionalVarInt(paramWriter, args.lockTime);
126
+ this.writeOptionalVarInt(paramWriter, args.version);
191
127
  // Serialize labels
192
- if (args.labels != null) {
193
- paramWriter.writeVarIntNum(args.labels.length);
194
- for (const label of args.labels) {
195
- const labelBytes = Utils.toArray(label, 'utf8');
196
- paramWriter.writeVarIntNum(labelBytes.length);
197
- paramWriter.write(labelBytes);
198
- }
199
- }
200
- else {
201
- paramWriter.writeVarIntNum(-1);
202
- }
128
+ this.writeUTF8Array(paramWriter, args.labels);
203
129
  // Serialize options
204
- if (args.options != null) {
205
- paramWriter.writeInt8(1); // options present
206
- // signAndProcess
207
- if (typeof args.options.signAndProcess === 'boolean') {
208
- paramWriter.writeInt8(args.options.signAndProcess ? 1 : 0);
209
- }
210
- else {
211
- paramWriter.writeInt8(-1);
212
- }
213
- // acceptDelayedBroadcast
214
- if (typeof args.options.acceptDelayedBroadcast === 'boolean') {
215
- paramWriter.writeInt8(args.options.acceptDelayedBroadcast ? 1 : 0);
216
- }
217
- else {
218
- paramWriter.writeInt8(-1);
219
- }
220
- // trustSelf
221
- if (args.options.trustSelf === 'known') {
222
- paramWriter.writeInt8(1);
223
- }
224
- else {
225
- paramWriter.writeInt8(-1);
226
- }
227
- // knownTxids
228
- if (args.options.knownTxids != null) {
229
- paramWriter.writeVarIntNum(args.options.knownTxids.length);
230
- for (const txid of args.options.knownTxids) {
231
- const txidBytes = Utils.toArray(txid, 'hex');
232
- paramWriter.write(txidBytes);
233
- }
234
- }
235
- else {
236
- paramWriter.writeVarIntNum(-1);
237
- }
238
- // returnTXIDOnly
239
- if (typeof args.options.returnTXIDOnly === 'boolean') {
240
- paramWriter.writeInt8(args.options.returnTXIDOnly ? 1 : 0);
241
- }
242
- else {
243
- paramWriter.writeInt8(-1);
244
- }
245
- // noSend
246
- if (typeof args.options.noSend === 'boolean') {
247
- paramWriter.writeInt8(args.options.noSend ? 1 : 0);
248
- }
249
- else {
250
- paramWriter.writeInt8(-1);
251
- }
252
- // noSendChange
253
- if (args.options.noSendChange != null) {
254
- paramWriter.writeVarIntNum(args.options.noSendChange.length);
255
- for (const outpoint of args.options.noSendChange) {
256
- paramWriter.write(this.encodeOutpoint(outpoint));
257
- }
258
- }
259
- else {
260
- paramWriter.writeVarIntNum(-1);
261
- }
262
- // sendWith
263
- if (args.options.sendWith != null) {
264
- paramWriter.writeVarIntNum(args.options.sendWith.length);
265
- for (const txid of args.options.sendWith) {
266
- const txidBytes = Utils.toArray(txid, 'hex');
267
- paramWriter.write(txidBytes);
268
- }
269
- }
270
- else {
271
- paramWriter.writeVarIntNum(-1);
272
- }
273
- // randomizeOutputs
274
- if (typeof args.options.randomizeOutputs === 'boolean') {
275
- paramWriter.writeInt8(args.options.randomizeOutputs ? 1 : 0);
276
- }
277
- else {
278
- paramWriter.writeInt8(-1);
279
- }
280
- }
281
- else {
282
- paramWriter.writeInt8(0); // options not present
283
- }
130
+ this.serializeCreateActionOptions(paramWriter, args.options);
284
131
  // Transmit and parse response
285
132
  const result = await this.transmit('createAction', originator, paramWriter.toArray());
133
+ return this.parseCreateActionResult(result);
134
+ }
135
+ parseCreateActionResult(result) {
286
136
  const resultReader = new Utils.Reader(result);
287
137
  const response = {};
288
- // Parse txid
289
- const txidFlag = resultReader.readInt8();
290
- if (txidFlag === 1) {
291
- const txidBytes = resultReader.read(32);
292
- response.txid = Utils.toHex(txidBytes);
293
- }
294
- // Parse tx
295
- const txFlag = resultReader.readInt8();
296
- if (txFlag === 1) {
297
- const txLength = resultReader.readVarIntNum();
298
- response.tx = resultReader.read(txLength);
299
- }
300
- // Parse noSendChange
138
+ if (resultReader.readInt8() === 1) {
139
+ response.txid = Utils.toHex(resultReader.read(32));
140
+ }
141
+ if (resultReader.readInt8() === 1) {
142
+ response.tx = resultReader.read(resultReader.readVarIntNum());
143
+ }
301
144
  const noSendChangeLength = resultReader.readVarIntNum();
302
145
  if (noSendChangeLength >= 0) {
303
146
  response.noSendChange = [];
304
147
  for (let i = 0; i < noSendChangeLength; i++) {
305
- const outpoint = this.readOutpoint(resultReader);
306
- response.noSendChange.push(outpoint);
148
+ response.noSendChange.push(this.readOutpoint(resultReader));
307
149
  }
308
150
  }
309
- // Parse sendWithResults
310
- const sendWithResultsLength = resultReader.readVarIntNum();
311
- if (sendWithResultsLength >= 0) {
312
- response.sendWithResults = [];
313
- for (let i = 0; i < sendWithResultsLength; i++) {
314
- const txidBytes = resultReader.read(32);
315
- const txid = Utils.toHex(txidBytes);
316
- const statusCode = resultReader.readInt8();
317
- let status = 'unproven';
318
- if (statusCode === 1)
319
- status = 'unproven';
320
- else if (statusCode === 2)
321
- status = 'sending';
322
- else if (statusCode === 3)
323
- status = 'failed';
324
- response.sendWithResults.push({ txid, status });
325
- }
326
- }
327
- // Parse signableTransaction
328
- const signableTransactionFlag = resultReader.readInt8();
329
- if (signableTransactionFlag === 1) {
330
- const txLength = resultReader.readVarIntNum();
331
- const tx = resultReader.read(txLength);
332
- const referenceLength = resultReader.readVarIntNum();
333
- const referenceBytes = resultReader.read(referenceLength);
334
- response.signableTransaction = {
335
- tx,
336
- reference: Utils.toBase64(referenceBytes)
337
- };
151
+ const sendWithResults = this.readSendWithResults(resultReader);
152
+ if (sendWithResults != null)
153
+ response.sendWithResults = sendWithResults;
154
+ if (resultReader.readInt8() === 1) {
155
+ const tx = resultReader.read(resultReader.readVarIntNum());
156
+ const referenceBytes = resultReader.read(resultReader.readVarIntNum());
157
+ response.signableTransaction = { tx, reference: Utils.toBase64(referenceBytes) };
338
158
  }
339
159
  return response;
340
160
  }
@@ -346,95 +166,30 @@ class WalletWireTransceiver {
346
166
  for (const index of spendIndexes) {
347
167
  paramWriter.writeVarIntNum(Number(index));
348
168
  const spend = args.spends[Number(index)];
349
- // unlockingScript
350
169
  const unlockingScriptBytes = Utils.toArray(spend.unlockingScript, 'hex');
351
170
  paramWriter.writeVarIntNum(unlockingScriptBytes.length);
352
171
  paramWriter.write(unlockingScriptBytes);
353
- // sequenceNumber
354
- if (typeof spend.sequenceNumber === 'number') {
355
- paramWriter.writeVarIntNum(spend.sequenceNumber);
356
- }
357
- else {
358
- paramWriter.writeVarIntNum(-1);
359
- }
172
+ this.writeOptionalVarInt(paramWriter, spend.sequenceNumber);
360
173
  }
361
174
  // Serialize reference
362
175
  const referenceBytes = Utils.toArray(args.reference, 'base64');
363
176
  paramWriter.writeVarIntNum(referenceBytes.length);
364
177
  paramWriter.write(referenceBytes);
365
178
  // Serialize options
366
- if (args.options != null) {
367
- paramWriter.writeInt8(1); // options present
368
- // acceptDelayedBroadcast
369
- if (typeof args.options.acceptDelayedBroadcast === 'boolean') {
370
- paramWriter.writeInt8(args.options.acceptDelayedBroadcast ? 1 : 0);
371
- }
372
- else {
373
- paramWriter.writeInt8(-1);
374
- }
375
- // returnTXIDOnly
376
- if (typeof args.options.returnTXIDOnly === 'boolean') {
377
- paramWriter.writeInt8(args.options.returnTXIDOnly ? 1 : 0);
378
- }
379
- else {
380
- paramWriter.writeInt8(-1);
381
- }
382
- // noSend
383
- if (typeof args.options.noSend === 'boolean') {
384
- paramWriter.writeInt8(args.options.noSend ? 1 : 0);
385
- }
386
- else {
387
- paramWriter.writeInt8(-1);
388
- }
389
- // sendWith
390
- if (args.options.sendWith != null) {
391
- paramWriter.writeVarIntNum(args.options.sendWith.length);
392
- for (const txid of args.options.sendWith) {
393
- const txidBytes = Utils.toArray(txid, 'hex');
394
- paramWriter.write(txidBytes);
395
- }
396
- }
397
- else {
398
- paramWriter.writeVarIntNum(-1);
399
- }
400
- }
401
- else {
402
- paramWriter.writeInt8(0); // options not present
403
- }
179
+ this.serializeSignActionOptions(paramWriter, args.options);
404
180
  // Transmit and parse response
405
181
  const result = await this.transmit('signAction', originator, paramWriter.toArray());
406
182
  const resultReader = new Utils.Reader(result);
407
183
  const response = {};
408
- // Parse txid
409
- const txidFlag = resultReader.readInt8();
410
- if (txidFlag === 1) {
411
- const txidBytes = resultReader.read(32);
412
- response.txid = Utils.toHex(txidBytes);
413
- }
414
- // Parse tx
415
- const txFlag = resultReader.readInt8();
416
- if (txFlag === 1) {
417
- const txLength = resultReader.readVarIntNum();
418
- response.tx = resultReader.read(txLength);
419
- }
420
- // Parse sendWithResults
421
- const sendWithResultsLength = resultReader.readVarIntNum();
422
- if (sendWithResultsLength >= 0) {
423
- response.sendWithResults = [];
424
- for (let i = 0; i < sendWithResultsLength; i++) {
425
- const txidBytes = resultReader.read(32);
426
- const txid = Utils.toHex(txidBytes);
427
- const statusCode = resultReader.readInt8();
428
- let status = 'unproven';
429
- if (statusCode === 1)
430
- status = 'unproven';
431
- else if (statusCode === 2)
432
- status = 'sending';
433
- else if (statusCode === 3)
434
- status = 'failed';
435
- response.sendWithResults.push({ txid, status });
436
- }
184
+ if (resultReader.readInt8() === 1) {
185
+ response.txid = Utils.toHex(resultReader.read(32));
186
+ }
187
+ if (resultReader.readInt8() === 1) {
188
+ response.tx = resultReader.read(resultReader.readVarIntNum());
437
189
  }
190
+ const sendWithResults = this.readSendWithResults(resultReader);
191
+ if (sendWithResults != null)
192
+ response.sendWithResults = sendWithResults;
438
193
  return response;
439
194
  }
440
195
  async abortAction(args, originator) {
@@ -443,223 +198,109 @@ class WalletWireTransceiver {
443
198
  }
444
199
  async listActions(args, originator) {
445
200
  const paramWriter = new Utils.Writer();
446
- // Serialize labels
201
+ // Serialize labels (always-present array, no -1 sentinel)
447
202
  paramWriter.writeVarIntNum(args.labels.length);
448
203
  for (const label of args.labels) {
449
- const labelBytes = Utils.toArray(label, 'utf8');
450
- paramWriter.writeVarIntNum(labelBytes.length);
451
- paramWriter.write(labelBytes);
204
+ this.writeUTF8(paramWriter, label);
452
205
  }
453
206
  // Serialize labelQueryMode
454
- if (args.labelQueryMode === 'any') {
207
+ if (args.labelQueryMode === 'any')
455
208
  paramWriter.writeInt8(1);
456
- }
457
- else if (args.labelQueryMode === 'all') {
209
+ else if (args.labelQueryMode === 'all')
458
210
  paramWriter.writeInt8(2);
459
- }
460
- else {
211
+ else
461
212
  paramWriter.writeInt8(-1);
462
- }
463
213
  // Serialize include options
464
- const includeOptions = [
214
+ for (const option of [
465
215
  args.includeLabels,
466
216
  args.includeInputs,
467
217
  args.includeInputSourceLockingScripts,
468
218
  args.includeInputUnlockingScripts,
469
219
  args.includeOutputs,
470
220
  args.includeOutputLockingScripts
471
- ];
472
- for (const option of includeOptions) {
473
- if (typeof option === 'boolean') {
474
- paramWriter.writeInt8(option ? 1 : 0);
475
- }
476
- else {
477
- paramWriter.writeInt8(-1);
478
- }
479
- }
480
- // Serialize limit and offset
481
- if (typeof args.limit === 'number') {
482
- paramWriter.writeVarIntNum(args.limit);
483
- }
484
- else {
485
- paramWriter.writeVarIntNum(-1);
486
- }
487
- if (typeof args.offset === 'number') {
488
- paramWriter.writeVarIntNum(args.offset);
489
- }
490
- else {
491
- paramWriter.writeVarIntNum(-1);
221
+ ]) {
222
+ this.writeOptionalBool(paramWriter, option);
492
223
  }
493
- // Serialize seekPermission
494
- paramWriter.writeInt8(typeof args.seekPermission === 'boolean'
495
- ? args.seekPermission
496
- ? 1
497
- : 0
498
- : -1);
499
- // Transmit and parse response
224
+ this.writeOptionalVarInt(paramWriter, args.limit);
225
+ this.writeOptionalVarInt(paramWriter, args.offset);
226
+ this.writeOptionalBool(paramWriter, args.seekPermission);
500
227
  const result = await this.transmit('listActions', originator, paramWriter.toArray());
501
228
  const resultReader = new Utils.Reader(result);
502
229
  const totalActions = resultReader.readVarIntNum();
503
230
  const actions = [];
504
231
  for (let i = 0; i < totalActions; i++) {
505
- // Parse action fields
506
- const txidBytes = resultReader.read(32);
507
- const txid = Utils.toHex(txidBytes);
508
- const satoshis = resultReader.readVarIntNum();
509
- const statusCode = resultReader.readInt8();
510
- let status;
511
- switch (statusCode) {
512
- case 1:
513
- status = 'completed';
514
- break;
515
- case 2:
516
- status = 'unprocessed';
517
- break;
518
- case 3:
519
- status = 'sending';
520
- break;
521
- case 4:
522
- status = 'unproven';
523
- break;
524
- case 5:
525
- status = 'unsigned';
526
- break;
527
- case 6:
528
- status = 'nosend';
529
- break;
530
- case 7:
531
- status = 'nonfinal';
532
- break;
533
- case 8:
534
- status = 'failed';
535
- break;
536
- default:
537
- throw new Error(`Unknown status code: ${statusCode}`);
232
+ actions.push(this.parseAction(resultReader));
233
+ }
234
+ return { totalActions, actions };
235
+ }
236
+ parseActionStatus(code) {
237
+ const status = ACTION_STATUS_MAP[code];
238
+ if (status == null)
239
+ throw new Error(`Unknown status code: ${code}`);
240
+ return status;
241
+ }
242
+ parseAction(reader) {
243
+ const txid = Utils.toHex(reader.read(32));
244
+ const satoshis = reader.readVarIntNum();
245
+ const status = this.parseActionStatus(reader.readInt8());
246
+ const isOutgoing = reader.readInt8() === 1;
247
+ const description = Utils.toUTF8(reader.read(reader.readVarIntNum()));
248
+ const action = { txid, satoshis, status, isOutgoing, description, version: 0, lockTime: 0 };
249
+ const labelsLen = reader.readVarIntNum();
250
+ if (labelsLen >= 0) {
251
+ action.labels = [];
252
+ for (let j = 0; j < labelsLen; j++) {
253
+ action.labels.push(Utils.toUTF8(reader.read(reader.readVarIntNum())));
538
254
  }
539
- const isOutgoing = resultReader.readInt8() === 1;
540
- const descriptionLength = resultReader.readVarIntNum();
541
- const descriptionBytes = resultReader.read(descriptionLength);
542
- const description = Utils.toUTF8(descriptionBytes);
543
- const action = {
544
- txid,
545
- satoshis,
546
- status,
547
- isOutgoing,
548
- description,
549
- version: 0,
550
- lockTime: 0
551
- };
552
- // Parse labels
553
- const labelsLength = resultReader.readVarIntNum();
554
- if (labelsLength >= 0) {
555
- action.labels = [];
556
- for (let j = 0; j < labelsLength; j++) {
557
- const labelLength = resultReader.readVarIntNum();
558
- const labelBytes = resultReader.read(labelLength);
559
- action.labels.push(Utils.toUTF8(labelBytes));
560
- }
255
+ }
256
+ action.version = reader.readVarIntNum();
257
+ action.lockTime = reader.readVarIntNum();
258
+ const inputsLen = reader.readVarIntNum();
259
+ if (inputsLen >= 0) {
260
+ action.inputs = [];
261
+ for (let k = 0; k < inputsLen; k++) {
262
+ action.inputs.push(this.parseActionInput(reader));
561
263
  }
562
- // Parse version and lockTime
563
- action.version = resultReader.readVarIntNum();
564
- action.lockTime = resultReader.readVarIntNum();
565
- // Parse inputs
566
- const inputsLength = resultReader.readVarIntNum();
567
- if (inputsLength >= 0) {
568
- action.inputs = [];
569
- for (let k = 0; k < inputsLength; k++) {
570
- const sourceOutpoint = this.readOutpoint(resultReader);
571
- const sourceSatoshis = resultReader.readVarIntNum();
572
- // sourceLockingScript
573
- const sourceLockingScriptLength = resultReader.readVarIntNum();
574
- let sourceLockingScript;
575
- if (sourceLockingScriptLength >= 0) {
576
- const sourceLockingScriptBytes = resultReader.read(sourceLockingScriptLength);
577
- sourceLockingScript = Utils.toHex(sourceLockingScriptBytes);
578
- }
579
- // unlockingScript
580
- const unlockingScriptLength = resultReader.readVarIntNum();
581
- let unlockingScript;
582
- if (unlockingScriptLength >= 0) {
583
- const unlockingScriptBytes = resultReader.read(unlockingScriptLength);
584
- unlockingScript = Utils.toHex(unlockingScriptBytes);
585
- }
586
- // inputDescription
587
- const inputDescriptionLength = resultReader.readVarIntNum();
588
- const inputDescriptionBytes = resultReader.read(inputDescriptionLength);
589
- const inputDescription = Utils.toUTF8(inputDescriptionBytes);
590
- // sequenceNumber
591
- const sequenceNumber = resultReader.readVarIntNum();
592
- action.inputs.push({
593
- sourceOutpoint,
594
- sourceSatoshis,
595
- sourceLockingScript,
596
- unlockingScript,
597
- inputDescription,
598
- sequenceNumber
599
- });
600
- }
264
+ }
265
+ const outputsLen = reader.readVarIntNum();
266
+ if (outputsLen >= 0) {
267
+ action.outputs = [];
268
+ for (let l = 0; l < outputsLen; l++) {
269
+ action.outputs.push(this.parseActionOutput(reader));
601
270
  }
602
- // Parse outputs
603
- const outputsLength = resultReader.readVarIntNum();
604
- if (outputsLength >= 0) {
605
- action.outputs = [];
606
- for (let l = 0; l < outputsLength; l++) {
607
- const outputIndex = resultReader.readVarIntNum();
608
- const satoshis = resultReader.readVarIntNum();
609
- // lockingScript
610
- const lockingScriptLength = resultReader.readVarIntNum();
611
- let lockingScript;
612
- if (lockingScriptLength >= 0) {
613
- const lockingScriptBytes = resultReader.read(lockingScriptLength);
614
- lockingScript = Utils.toHex(lockingScriptBytes);
615
- }
616
- const spendable = resultReader.readInt8() === 1;
617
- // outputDescription
618
- const outputDescriptionLength = resultReader.readVarIntNum();
619
- const outputDescriptionBytes = resultReader.read(outputDescriptionLength);
620
- const outputDescription = Utils.toUTF8(outputDescriptionBytes);
621
- // basket
622
- const basketLength = resultReader.readVarIntNum();
623
- let basket;
624
- if (basketLength >= 0) {
625
- const basketBytes = resultReader.read(basketLength);
626
- basket = Utils.toUTF8(basketBytes);
627
- }
628
- // tags
629
- const tagsLength = resultReader.readVarIntNum();
630
- const tags = [];
631
- if (tagsLength >= 0) {
632
- for (let m = 0; m < tagsLength; m++) {
633
- const tagLength = resultReader.readVarIntNum();
634
- const tagBytes = resultReader.read(tagLength);
635
- tags.push(Utils.toUTF8(tagBytes));
636
- }
637
- }
638
- // customInstructions
639
- const customInstructionsLength = resultReader.readVarIntNum();
640
- let customInstructions;
641
- if (customInstructionsLength >= 0) {
642
- const customInstructionsBytes = resultReader.read(customInstructionsLength);
643
- customInstructions = Utils.toUTF8(customInstructionsBytes);
644
- }
645
- action.outputs.push({
646
- outputIndex,
647
- satoshis,
648
- lockingScript,
649
- spendable,
650
- outputDescription,
651
- basket,
652
- tags,
653
- customInstructions
654
- });
655
- }
271
+ }
272
+ return action;
273
+ }
274
+ parseActionInput(reader) {
275
+ const sourceOutpoint = this.readOutpoint(reader);
276
+ const sourceSatoshis = reader.readVarIntNum();
277
+ const srcLockLen = reader.readVarIntNum();
278
+ const sourceLockingScript = srcLockLen >= 0 ? Utils.toHex(reader.read(srcLockLen)) : undefined;
279
+ const unlockLen = reader.readVarIntNum();
280
+ const unlockingScript = unlockLen >= 0 ? Utils.toHex(reader.read(unlockLen)) : undefined;
281
+ const inputDescription = Utils.toUTF8(reader.read(reader.readVarIntNum()));
282
+ const sequenceNumber = reader.readVarIntNum();
283
+ return { sourceOutpoint, sourceSatoshis, sourceLockingScript, unlockingScript, inputDescription, sequenceNumber };
284
+ }
285
+ parseActionOutput(reader) {
286
+ const outputIndex = reader.readVarIntNum();
287
+ const satoshis = reader.readVarIntNum();
288
+ const lockLen = reader.readVarIntNum();
289
+ const lockingScript = lockLen >= 0 ? Utils.toHex(reader.read(lockLen)) : undefined;
290
+ const spendable = reader.readInt8() === 1;
291
+ const outputDescription = Utils.toUTF8(reader.read(reader.readVarIntNum()));
292
+ const basketLen = reader.readVarIntNum();
293
+ const basket = basketLen >= 0 ? Utils.toUTF8(reader.read(basketLen)) : undefined;
294
+ const tagsLen = reader.readVarIntNum();
295
+ const tags = [];
296
+ if (tagsLen >= 0) {
297
+ for (let m = 0; m < tagsLen; m++) {
298
+ tags.push(Utils.toUTF8(reader.read(reader.readVarIntNum())));
656
299
  }
657
- actions.push(action);
658
300
  }
659
- return {
660
- totalActions,
661
- actions
662
- };
301
+ const custLen = reader.readVarIntNum();
302
+ const customInstructions = custLen >= 0 ? Utils.toUTF8(reader.read(custLen)) : undefined;
303
+ return { outputIndex, satoshis, lockingScript, spendable, outputDescription, basket: basket, tags, customInstructions };
663
304
  }
664
305
  async internalizeAction(args, originator) {
665
306
  const paramWriter = new Utils.Writer();
@@ -667,189 +308,119 @@ class WalletWireTransceiver {
667
308
  paramWriter.write(args.tx);
668
309
  paramWriter.writeVarIntNum(args.outputs.length);
669
310
  for (const out of args.outputs) {
670
- paramWriter.writeVarIntNum(out.outputIndex);
671
- if (out.protocol === 'wallet payment') {
672
- if (out.paymentRemittance == null) {
673
- throw new Error('Payment remittance is required for wallet payment');
674
- }
675
- paramWriter.writeUInt8(1);
676
- paramWriter.write(Utils.toArray(out.paymentRemittance.senderIdentityKey, 'hex'));
677
- const derivationPrefixAsArray = Utils.toArray(out.paymentRemittance.derivationPrefix, 'base64');
678
- paramWriter.writeVarIntNum(derivationPrefixAsArray.length);
679
- paramWriter.write(derivationPrefixAsArray);
680
- const derivationSuffixAsArray = Utils.toArray(out.paymentRemittance.derivationSuffix, 'base64');
681
- paramWriter.writeVarIntNum(derivationSuffixAsArray.length);
682
- paramWriter.write(derivationSuffixAsArray);
683
- }
684
- else {
685
- paramWriter.writeUInt8(2);
686
- const basketAsArray = Utils.toArray(out.insertionRemittance?.basket, 'utf8');
687
- paramWriter.writeVarIntNum(basketAsArray.length);
688
- paramWriter.write(basketAsArray);
689
- if (typeof out.insertionRemittance?.customInstructions === 'string' && out.insertionRemittance.customInstructions !== '') {
690
- const customInstructionsAsArray = Utils.toArray(out.insertionRemittance.customInstructions, 'utf8');
691
- paramWriter.writeVarIntNum(customInstructionsAsArray.length);
692
- paramWriter.write(customInstructionsAsArray);
693
- }
694
- else {
695
- paramWriter.writeVarIntNum(-1);
696
- }
697
- if (typeof out.insertionRemittance?.tags === 'object') {
698
- paramWriter.writeVarIntNum(out.insertionRemittance.tags.length);
699
- for (const tag of out.insertionRemittance.tags) {
700
- const tagAsArray = Utils.toArray(tag, 'utf8');
701
- paramWriter.writeVarIntNum(tagAsArray.length);
702
- paramWriter.write(tagAsArray);
703
- }
704
- }
705
- else {
706
- paramWriter.writeVarIntNum(0);
707
- }
708
- }
709
- }
710
- if (typeof args.labels === 'object') {
711
- paramWriter.writeVarIntNum(args.labels.length);
712
- for (const l of args.labels) {
713
- const labelAsArray = Utils.toArray(l, 'utf8');
714
- paramWriter.writeVarIntNum(labelAsArray.length);
715
- paramWriter.write(labelAsArray);
716
- }
717
- }
718
- else {
719
- paramWriter.writeVarIntNum(-1);
311
+ this.serializeInternalizeOutput(paramWriter, out);
720
312
  }
313
+ this.writeUTF8Array(paramWriter, typeof args.labels === 'object' ? args.labels : undefined);
721
314
  const descriptionAsArray = Utils.toArray(args.description);
722
315
  paramWriter.writeVarIntNum(descriptionAsArray.length);
723
316
  paramWriter.write(descriptionAsArray);
724
- // Serialize seekPermission
725
- paramWriter.writeInt8(typeof args.seekPermission === 'boolean'
726
- ? args.seekPermission
727
- ? 1
728
- : 0
729
- : -1);
317
+ this.writeOptionalBool(paramWriter, args.seekPermission);
730
318
  await this.transmit('internalizeAction', originator, paramWriter.toArray());
731
319
  return { accepted: true };
732
320
  }
321
+ serializeInternalizeOutput(writer, out) {
322
+ writer.writeVarIntNum(out.outputIndex);
323
+ if (out.protocol === 'wallet payment') {
324
+ if (out.paymentRemittance == null) {
325
+ throw new Error('Payment remittance is required for wallet payment');
326
+ }
327
+ writer.writeUInt8(1);
328
+ writer.write(Utils.toArray(out.paymentRemittance.senderIdentityKey, 'hex'));
329
+ const prefix = Utils.toArray(out.paymentRemittance.derivationPrefix, 'base64');
330
+ writer.writeVarIntNum(prefix.length);
331
+ writer.write(prefix);
332
+ const suffix = Utils.toArray(out.paymentRemittance.derivationSuffix, 'base64');
333
+ writer.writeVarIntNum(suffix.length);
334
+ writer.write(suffix);
335
+ }
336
+ else {
337
+ writer.writeUInt8(2);
338
+ const basket = Utils.toArray(out.insertionRemittance?.basket, 'utf8');
339
+ writer.writeVarIntNum(basket.length);
340
+ writer.write(basket);
341
+ this.writeOptionalUTF8(writer, out.insertionRemittance?.customInstructions);
342
+ const tags = out.insertionRemittance?.tags;
343
+ if (typeof tags === 'object') {
344
+ writer.writeVarIntNum(tags.length);
345
+ for (const tag of tags) {
346
+ const t = Utils.toArray(tag, 'utf8');
347
+ writer.writeVarIntNum(t.length);
348
+ writer.write(t);
349
+ }
350
+ }
351
+ else {
352
+ writer.writeVarIntNum(0);
353
+ }
354
+ }
355
+ }
733
356
  async listOutputs(args, originator) {
734
357
  const paramWriter = new Utils.Writer();
735
- const basketAsArray = Utils.toArray(args.basket, 'utf8');
736
- paramWriter.writeVarIntNum(basketAsArray.length);
737
- paramWriter.write(basketAsArray);
358
+ this.writeUTF8(paramWriter, args.basket);
738
359
  if (typeof args.tags === 'object') {
739
360
  paramWriter.writeVarIntNum(args.tags.length);
740
361
  for (const tag of args.tags) {
741
- const tagAsArray = Utils.toArray(tag, 'utf8');
742
- paramWriter.writeVarIntNum(tagAsArray.length);
743
- paramWriter.write(tagAsArray);
362
+ this.writeUTF8(paramWriter, tag);
744
363
  }
745
364
  }
746
365
  else {
747
366
  paramWriter.writeVarIntNum(0);
748
367
  }
749
- if (args.tagQueryMode === 'all') {
368
+ if (args.tagQueryMode === 'all')
750
369
  paramWriter.writeInt8(1);
751
- }
752
- else if (args.tagQueryMode === 'any') {
370
+ else if (args.tagQueryMode === 'any')
753
371
  paramWriter.writeInt8(2);
754
- }
755
- else {
372
+ else
756
373
  paramWriter.writeInt8(-1);
757
- }
758
- if (args.include === 'locking scripts') {
374
+ if (args.include === 'locking scripts')
759
375
  paramWriter.writeInt8(1);
760
- }
761
- else if (args.include === 'entire transactions') {
376
+ else if (args.include === 'entire transactions')
762
377
  paramWriter.writeInt8(2);
763
- }
764
- else {
765
- paramWriter.writeInt8(-1);
766
- }
767
- if (typeof args.includeCustomInstructions === 'boolean') {
768
- paramWriter.writeInt8(args.includeCustomInstructions ? 1 : 0);
769
- }
770
- else {
771
- paramWriter.writeInt8(-1);
772
- }
773
- if (typeof args.includeTags === 'boolean') {
774
- paramWriter.writeInt8(args.includeTags ? 1 : 0);
775
- }
776
- else {
777
- paramWriter.writeInt8(-1);
778
- }
779
- if (typeof args.includeLabels === 'boolean') {
780
- paramWriter.writeInt8(args.includeLabels ? 1 : 0);
781
- }
782
- else {
378
+ else
783
379
  paramWriter.writeInt8(-1);
784
- }
785
- if (typeof args.limit === 'number') {
786
- paramWriter.writeVarIntNum(args.limit);
787
- }
788
- else {
789
- paramWriter.writeVarIntNum(-1);
790
- }
791
- if (typeof args.offset === 'number') {
792
- paramWriter.writeVarIntNum(args.offset);
793
- }
794
- else {
795
- paramWriter.writeVarIntNum(-1);
796
- }
797
- // Serialize seekPermission
798
- paramWriter.writeInt8(typeof args.seekPermission === 'boolean'
799
- ? args.seekPermission
800
- ? 1
801
- : 0
802
- : -1);
380
+ this.writeOptionalBool(paramWriter, args.includeCustomInstructions);
381
+ this.writeOptionalBool(paramWriter, args.includeTags);
382
+ this.writeOptionalBool(paramWriter, args.includeLabels);
383
+ this.writeOptionalVarInt(paramWriter, args.limit);
384
+ this.writeOptionalVarInt(paramWriter, args.offset);
385
+ this.writeOptionalBool(paramWriter, args.seekPermission);
803
386
  const result = await this.transmit('listOutputs', originator, paramWriter.toArray());
804
387
  const resultReader = new Utils.Reader(result);
805
388
  const totalOutputs = resultReader.readVarIntNum();
806
389
  const beefLength = resultReader.readVarIntNum();
807
- let BEEF;
808
- if (beefLength >= 0) {
809
- BEEF = resultReader.read(beefLength);
810
- }
390
+ const BEEF = beefLength >= 0 ? resultReader.read(beefLength) : undefined;
811
391
  const outputs = [];
812
392
  for (let i = 0; i < totalOutputs; i++) {
813
- const outpoint = this.readOutpoint(resultReader);
814
- const satoshis = resultReader.readVarIntNum();
815
- const output = {
816
- spendable: true,
817
- outpoint,
818
- satoshis
819
- };
820
- const scriptLength = resultReader.readVarIntNum();
821
- if (scriptLength >= 0) {
822
- output.lockingScript = Utils.toHex(resultReader.read(scriptLength));
823
- }
824
- const customInstructionsLength = resultReader.readVarIntNum();
825
- if (customInstructionsLength >= 0) {
826
- output.customInstructions = Utils.toUTF8(resultReader.read(customInstructionsLength));
827
- }
828
- const tagsLength = resultReader.readVarIntNum();
829
- if (tagsLength !== -1) {
830
- const tags = [];
831
- for (let i = 0; i < tagsLength; i++) {
832
- const tagLength = resultReader.readVarIntNum();
833
- tags.push(Utils.toUTF8(resultReader.read(tagLength)));
834
- }
835
- output.tags = tags;
393
+ outputs.push(this.parseListOutputEntry(resultReader));
394
+ }
395
+ return { totalOutputs, BEEF, outputs };
396
+ }
397
+ parseListOutputEntry(reader) {
398
+ const outpoint = this.readOutpoint(reader);
399
+ const satoshis = reader.readVarIntNum();
400
+ const output = { spendable: true, outpoint, satoshis };
401
+ const scriptLen = reader.readVarIntNum();
402
+ if (scriptLen >= 0)
403
+ output.lockingScript = Utils.toHex(reader.read(scriptLen));
404
+ const custLen = reader.readVarIntNum();
405
+ if (custLen >= 0)
406
+ output.customInstructions = Utils.toUTF8(reader.read(custLen));
407
+ const tagsLen = reader.readVarIntNum();
408
+ if (tagsLen !== -1) {
409
+ const tags = [];
410
+ for (let i = 0; i < tagsLen; i++) {
411
+ tags.push(Utils.toUTF8(reader.read(reader.readVarIntNum())));
836
412
  }
837
- const labelsLength = resultReader.readVarIntNum();
838
- if (labelsLength !== -1) {
839
- const labels = [];
840
- for (let i = 0; i < labelsLength; i++) {
841
- const labelLength = resultReader.readVarIntNum();
842
- labels.push(Utils.toUTF8(resultReader.read(labelLength)));
843
- }
844
- output.labels = labels;
413
+ output.tags = tags;
414
+ }
415
+ const labelsLen = reader.readVarIntNum();
416
+ if (labelsLen !== -1) {
417
+ const labels = [];
418
+ for (let i = 0; i < labelsLen; i++) {
419
+ labels.push(Utils.toUTF8(reader.read(reader.readVarIntNum())));
845
420
  }
846
- outputs.push(output);
421
+ output.labels = labels;
847
422
  }
848
- return {
849
- totalOutputs,
850
- BEEF,
851
- outputs
852
- };
423
+ return output;
853
424
  }
854
425
  async relinquishOutput(args, originator) {
855
426
  const paramWriter = new Utils.Writer();
@@ -875,8 +446,13 @@ class WalletWireTransceiver {
875
446
  async getPublicKey(args, originator) {
876
447
  const paramWriter = new Utils.Writer();
877
448
  paramWriter.writeUInt8(args.identityKey ? 1 : 0);
878
- if (!args.identityKey) {
879
- paramWriter.write(this.encodeKeyRelatedParams(args.protocolID ?? (args.protocolID = [Wallet_interfaces_js_1.SecurityLevels.Silent, 'default']), args.keyID ?? (args.keyID = ''), args.counterparty, args.privileged, args.privilegedReason));
449
+ if (args.identityKey) {
450
+ paramWriter.write(this.encodePrivilegedParams(args.privileged, args.privilegedReason));
451
+ }
452
+ else {
453
+ args.protocolID ?? (args.protocolID = [Wallet_interfaces_js_1.SecurityLevels.Silent, 'default']);
454
+ args.keyID ?? (args.keyID = '');
455
+ paramWriter.write(this.encodeKeyRelatedParams(args.protocolID, args.keyID, args.counterparty, args.privileged, args.privilegedReason));
880
456
  if (typeof args.forSelf === 'boolean') {
881
457
  paramWriter.writeInt8(args.forSelf ? 1 : 0);
882
458
  }
@@ -884,15 +460,8 @@ class WalletWireTransceiver {
884
460
  paramWriter.writeInt8(-1);
885
461
  }
886
462
  }
887
- else {
888
- paramWriter.write(this.encodePrivilegedParams(args.privileged, args.privilegedReason));
889
- }
890
463
  // Serialize seekPermission
891
- paramWriter.writeInt8(typeof args.seekPermission === 'boolean'
892
- ? args.seekPermission
893
- ? 1
894
- : 0
895
- : -1);
464
+ this.writeOptionalBool(paramWriter, args.seekPermission);
896
465
  const result = await this.transmit('getPublicKey', originator, paramWriter.toArray());
897
466
  return {
898
467
  publicKey: Utils.toHex(result)
@@ -959,11 +528,7 @@ class WalletWireTransceiver {
959
528
  paramWriter.writeVarIntNum(args.plaintext.length);
960
529
  paramWriter.write(args.plaintext);
961
530
  // Serialize seekPermission
962
- paramWriter.writeInt8(typeof args.seekPermission === 'boolean'
963
- ? args.seekPermission
964
- ? 1
965
- : 0
966
- : -1);
531
+ this.writeOptionalBool(paramWriter, args.seekPermission);
967
532
  return {
968
533
  ciphertext: await this.transmit('encrypt', originator, paramWriter.toArray())
969
534
  };
@@ -974,11 +539,7 @@ class WalletWireTransceiver {
974
539
  paramWriter.writeVarIntNum(args.ciphertext.length);
975
540
  paramWriter.write(args.ciphertext);
976
541
  // Serialize seekPermission
977
- paramWriter.writeInt8(typeof args.seekPermission === 'boolean'
978
- ? args.seekPermission
979
- ? 1
980
- : 0
981
- : -1);
542
+ this.writeOptionalBool(paramWriter, args.seekPermission);
982
543
  return {
983
544
  plaintext: await this.transmit('decrypt', originator, paramWriter.toArray())
984
545
  };
@@ -989,11 +550,7 @@ class WalletWireTransceiver {
989
550
  paramWriter.writeVarIntNum(args.data.length);
990
551
  paramWriter.write(args.data);
991
552
  // Serialize seekPermission
992
- paramWriter.writeInt8(typeof args.seekPermission === 'boolean'
993
- ? args.seekPermission
994
- ? 1
995
- : 0
996
- : -1);
553
+ this.writeOptionalBool(paramWriter, args.seekPermission);
997
554
  return {
998
555
  hmac: await this.transmit('createHmac', originator, paramWriter.toArray())
999
556
  };
@@ -1005,11 +562,7 @@ class WalletWireTransceiver {
1005
562
  paramWriter.writeVarIntNum(args.data.length);
1006
563
  paramWriter.write(args.data);
1007
564
  // Serialize seekPermission
1008
- paramWriter.writeInt8(typeof args.seekPermission === 'boolean'
1009
- ? args.seekPermission
1010
- ? 1
1011
- : 0
1012
- : -1);
565
+ this.writeOptionalBool(paramWriter, args.seekPermission);
1013
566
  await this.transmit('verifyHmac', originator, paramWriter.toArray());
1014
567
  return { valid: true };
1015
568
  }
@@ -1022,15 +575,12 @@ class WalletWireTransceiver {
1022
575
  paramWriter.write(args.data);
1023
576
  }
1024
577
  else {
578
+ args.hashToDirectlySign ?? (args.hashToDirectlySign = []);
1025
579
  paramWriter.writeUInt8(2);
1026
- paramWriter.write(args.hashToDirectlySign ?? (args.hashToDirectlySign = []));
580
+ paramWriter.write(args.hashToDirectlySign);
1027
581
  }
1028
582
  // Serialize seekPermission
1029
- paramWriter.writeInt8(typeof args.seekPermission === 'boolean'
1030
- ? args.seekPermission
1031
- ? 1
1032
- : 0
1033
- : -1);
583
+ this.writeOptionalBool(paramWriter, args.seekPermission);
1034
584
  return {
1035
585
  signature: await this.transmit('createSignature', originator, paramWriter.toArray())
1036
586
  };
@@ -1056,14 +606,148 @@ class WalletWireTransceiver {
1056
606
  paramWriter.write(args.hashToDirectlyVerify ?? []);
1057
607
  }
1058
608
  // Serialize seekPermission
1059
- paramWriter.writeInt8(typeof args.seekPermission === 'boolean'
1060
- ? args.seekPermission
1061
- ? 1
1062
- : 0
1063
- : -1);
609
+ this.writeOptionalBool(paramWriter, args.seekPermission);
1064
610
  await this.transmit('verifySignature', originator, paramWriter.toArray());
1065
611
  return { valid: true };
1066
612
  }
613
+ /** Writes an optional boolean as Int8: 1/0 if present, -1 if absent. */
614
+ writeOptionalBool(writer, val) {
615
+ if (typeof val === 'boolean') {
616
+ writer.writeInt8(val ? 1 : 0);
617
+ }
618
+ else {
619
+ writer.writeInt8(-1);
620
+ }
621
+ }
622
+ /** Writes an optional number as VarInt: the value if present, -1 if absent. */
623
+ writeOptionalVarInt(writer, val) {
624
+ if (typeof val === 'number') {
625
+ writer.writeVarIntNum(val);
626
+ }
627
+ else {
628
+ writer.writeVarIntNum(-1);
629
+ }
630
+ }
631
+ /** Writes a UTF-8 string as (VarInt length, bytes). */
632
+ writeUTF8(writer, val) {
633
+ const bytes = Utils.toArray(val ?? '', 'utf8');
634
+ writer.writeVarIntNum(bytes.length);
635
+ writer.write(bytes);
636
+ }
637
+ /** Writes an optional UTF-8 string: (VarInt length, bytes) if non-empty, -1 if absent/empty. */
638
+ writeOptionalUTF8(writer, val) {
639
+ if (val != null && val !== '') {
640
+ const bytes = Utils.toArray(val, 'utf8');
641
+ writer.writeVarIntNum(bytes.length);
642
+ writer.write(bytes);
643
+ }
644
+ else {
645
+ writer.writeVarIntNum(-1);
646
+ }
647
+ }
648
+ /** Writes an array of UTF-8 strings as (VarInt count, ...items). -1 if null. */
649
+ writeUTF8Array(writer, arr) {
650
+ if (arr == null) {
651
+ writer.writeVarIntNum(-1);
652
+ }
653
+ else {
654
+ writer.writeVarIntNum(arr.length);
655
+ for (const item of arr) {
656
+ const bytes = Utils.toArray(item, 'utf8');
657
+ writer.writeVarIntNum(bytes.length);
658
+ writer.write(bytes);
659
+ }
660
+ }
661
+ }
662
+ /** Writes an array of hex-encoded txids (each 32 bytes) as (VarInt count, ...items). -1 if null. */
663
+ writeTxidArray(writer, arr) {
664
+ if (arr == null) {
665
+ writer.writeVarIntNum(-1);
666
+ }
667
+ else {
668
+ writer.writeVarIntNum(arr.length);
669
+ for (const txid of arr) {
670
+ writer.write(Utils.toArray(txid, 'hex'));
671
+ }
672
+ }
673
+ }
674
+ /** Reads a list of SendWithResults entries from a binary reader. */
675
+ readSendWithResults(reader) {
676
+ const len = reader.readVarIntNum();
677
+ if (len < 0)
678
+ return undefined;
679
+ const results = [];
680
+ for (let i = 0; i < len; i++) {
681
+ const txid = Utils.toHex(reader.read(32));
682
+ const code = reader.readInt8();
683
+ const status = code === 2 ? 'sending' : code === 3 ? 'failed' : 'unproven';
684
+ results.push({ txid, status });
685
+ }
686
+ return results;
687
+ }
688
+ /** Serializes a single createAction input to the writer. */
689
+ serializeCreateActionInput(writer, input) {
690
+ writer.write(this.encodeOutpoint(input.outpoint));
691
+ if (input.unlockingScript != null && input.unlockingScript !== '') {
692
+ const bytes = Utils.toArray(input.unlockingScript, 'hex');
693
+ writer.writeVarIntNum(bytes.length);
694
+ writer.write(bytes);
695
+ }
696
+ else {
697
+ writer.writeVarIntNum(-1);
698
+ writer.writeVarIntNum(input.unlockingScriptLength ?? 0);
699
+ }
700
+ this.writeUTF8(writer, input.inputDescription);
701
+ this.writeOptionalVarInt(writer, input.sequenceNumber);
702
+ }
703
+ /** Serializes a single createAction output to the writer. */
704
+ serializeCreateActionOutput(writer, output) {
705
+ const lockingBytes = Utils.toArray(output.lockingScript, 'hex');
706
+ writer.writeVarIntNum(lockingBytes.length);
707
+ writer.write(lockingBytes);
708
+ writer.writeVarIntNum(output.satoshis);
709
+ this.writeUTF8(writer, output.outputDescription);
710
+ this.writeOptionalUTF8(writer, output.basket);
711
+ this.writeOptionalUTF8(writer, output.customInstructions);
712
+ this.writeUTF8Array(writer, output.tags);
713
+ }
714
+ /** Serializes createAction options to the writer (Int8 presence byte + fields). */
715
+ serializeCreateActionOptions(writer, options) {
716
+ if (options == null) {
717
+ writer.writeInt8(0);
718
+ return;
719
+ }
720
+ writer.writeInt8(1);
721
+ this.writeOptionalBool(writer, options.signAndProcess);
722
+ this.writeOptionalBool(writer, options.acceptDelayedBroadcast);
723
+ writer.writeInt8(options.trustSelf === 'known' ? 1 : -1);
724
+ this.writeTxidArray(writer, options.knownTxids);
725
+ this.writeOptionalBool(writer, options.returnTXIDOnly);
726
+ this.writeOptionalBool(writer, options.noSend);
727
+ if (options.noSendChange == null) {
728
+ writer.writeVarIntNum(-1);
729
+ }
730
+ else {
731
+ writer.writeVarIntNum(options.noSendChange.length);
732
+ for (const outpoint of options.noSendChange) {
733
+ writer.write(this.encodeOutpoint(outpoint));
734
+ }
735
+ }
736
+ this.writeTxidArray(writer, options.sendWith);
737
+ this.writeOptionalBool(writer, options.randomizeOutputs);
738
+ }
739
+ /** Serializes signAction options to the writer (Int8 presence byte + fields). */
740
+ serializeSignActionOptions(writer, options) {
741
+ if (options == null) {
742
+ writer.writeInt8(0);
743
+ return;
744
+ }
745
+ writer.writeInt8(1);
746
+ this.writeOptionalBool(writer, options.acceptDelayedBroadcast);
747
+ this.writeOptionalBool(writer, options.returnTXIDOnly);
748
+ this.writeOptionalBool(writer, options.noSend);
749
+ this.writeTxidArray(writer, options.sendWith);
750
+ }
1067
751
  encodeKeyRelatedParams(protocolID, keyID, counterparty, privileged, privilegedReason) {
1068
752
  const paramWriter = new Utils.Writer();
1069
753
  paramWriter.writeUInt8(protocolID[0]);
@@ -1110,17 +794,17 @@ class WalletWireTransceiver {
1110
794
  const signatureAsArray = Utils.toArray(args.signature, 'hex');
1111
795
  paramWriter.writeVarIntNum(signatureAsArray.length);
1112
796
  paramWriter.write(signatureAsArray);
1113
- const keyringRevealerAsArray = args.keyringRevealer !== 'certifier'
1114
- ? Utils.toArray(args.keyringRevealer, 'hex')
1115
- : [11];
797
+ const keyringRevealerAsArray = args.keyringRevealer === 'certifier'
798
+ ? [11]
799
+ : Utils.toArray(args.keyringRevealer, 'hex');
1116
800
  paramWriter.write(keyringRevealerAsArray);
1117
801
  const keyringKeys = Object.keys(args.keyringForSubject ?? {});
1118
802
  paramWriter.writeVarIntNum(keyringKeys.length);
1119
- for (let i = 0; i < keyringKeys.length; i++) {
1120
- const keyringKeysAsArray = Utils.toArray(keyringKeys[i], 'utf8');
803
+ for (const key of keyringKeys) {
804
+ const keyringKeysAsArray = Utils.toArray(key, 'utf8');
1121
805
  paramWriter.writeVarIntNum(keyringKeysAsArray.length);
1122
806
  paramWriter.write(keyringKeysAsArray);
1123
- const keyringForSubjectAsArray = Utils.toArray(args.keyringForSubject?.[keyringKeys[i]], 'base64');
807
+ const keyringForSubjectAsArray = Utils.toArray(args.keyringForSubject?.[key], 'base64');
1124
808
  paramWriter.writeVarIntNum(keyringForSubjectAsArray.length);
1125
809
  paramWriter.write(keyringForSubjectAsArray);
1126
810
  }
@@ -1158,12 +842,12 @@ class WalletWireTransceiver {
1158
842
  async listCertificates(args, originator) {
1159
843
  const paramWriter = new Utils.Writer();
1160
844
  paramWriter.writeVarIntNum(args.certifiers.length);
1161
- for (let i = 0; i < args.certifiers.length; i++) {
1162
- paramWriter.write(Utils.toArray(args.certifiers[i], 'hex'));
845
+ for (const certifier of args.certifiers) {
846
+ paramWriter.write(Utils.toArray(certifier, 'hex'));
1163
847
  }
1164
848
  paramWriter.writeVarIntNum(args.types.length);
1165
- for (let i = 0; i < args.types.length; i++) {
1166
- paramWriter.write(Utils.toArray(args.types[i], 'base64'));
849
+ for (const type of args.types) {
850
+ paramWriter.write(Utils.toArray(type, 'base64'));
1167
851
  }
1168
852
  if (typeof args.limit === 'number') {
1169
853
  paramWriter.writeVarIntNum(args.limit);
@@ -1197,7 +881,7 @@ class WalletWireTransceiver {
1197
881
  }
1198
882
  }
1199
883
  const verifierLength = resultReader.readVarIntNum();
1200
- let verifier = undefined;
884
+ let verifier;
1201
885
  if (verifierLength > 0) {
1202
886
  verifier = Utils.toUTF8(resultReader.read(verifierLength));
1203
887
  }
@@ -1205,7 +889,7 @@ class WalletWireTransceiver {
1205
889
  ...cert,
1206
890
  signature: cert.signature,
1207
891
  keyring: keyringForVerifier,
1208
- verifier,
892
+ verifier
1209
893
  });
1210
894
  }
1211
895
  return {
@@ -1331,11 +1015,7 @@ class WalletWireTransceiver {
1331
1015
  paramWriter.writeVarIntNum(-1);
1332
1016
  }
1333
1017
  // Serialize seekPermission
1334
- paramWriter.writeInt8(typeof args.seekPermission === 'boolean'
1335
- ? args.seekPermission
1336
- ? 1
1337
- : 0
1338
- : -1);
1018
+ this.writeOptionalBool(paramWriter, args.seekPermission);
1339
1019
  const result = await this.transmit('discoverByIdentityKey', originator, paramWriter.toArray());
1340
1020
  return this.parseDiscoveryResult(result);
1341
1021
  }
@@ -1343,11 +1023,11 @@ class WalletWireTransceiver {
1343
1023
  const paramWriter = new Utils.Writer();
1344
1024
  const attributeKeys = Object.keys(args.attributes);
1345
1025
  paramWriter.writeVarIntNum(attributeKeys.length);
1346
- for (let i = 0; i < attributeKeys.length; i++) {
1347
- paramWriter.writeVarIntNum(attributeKeys[i].length);
1348
- paramWriter.write(Utils.toArray(attributeKeys[i], 'utf8'));
1349
- paramWriter.writeVarIntNum(args.attributes[attributeKeys[i]].length);
1350
- paramWriter.write(Utils.toArray(args.attributes[attributeKeys[i]], 'utf8'));
1026
+ for (const attrKey of attributeKeys) {
1027
+ paramWriter.writeVarIntNum(attrKey.length);
1028
+ paramWriter.write(Utils.toArray(attrKey, 'utf8'));
1029
+ paramWriter.writeVarIntNum(args.attributes[attrKey].length);
1030
+ paramWriter.write(Utils.toArray(args.attributes[attrKey], 'utf8'));
1351
1031
  }
1352
1032
  if (typeof args.limit === 'number') {
1353
1033
  paramWriter.writeVarIntNum(args.limit);
@@ -1362,11 +1042,7 @@ class WalletWireTransceiver {
1362
1042
  paramWriter.writeVarIntNum(-1);
1363
1043
  }
1364
1044
  // Serialize seekPermission
1365
- paramWriter.writeInt8(typeof args.seekPermission === 'boolean'
1366
- ? args.seekPermission
1367
- ? 1
1368
- : 0
1369
- : -1);
1045
+ this.writeOptionalBool(paramWriter, args.seekPermission);
1370
1046
  const result = await this.transmit('discoverByAttributes', originator, paramWriter.toArray());
1371
1047
  return this.parseDiscoveryResult(result);
1372
1048
  }