@bsv/sdk 2.1.0 → 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (392) hide show
  1. package/README.md +7 -7
  2. package/dist/cjs/package.json +1 -1
  3. package/dist/cjs/src/auth/Peer.js +8 -13
  4. package/dist/cjs/src/auth/Peer.js.map +1 -1
  5. package/dist/cjs/src/auth/SessionManager.js +4 -7
  6. package/dist/cjs/src/auth/SessionManager.js.map +1 -1
  7. package/dist/cjs/src/auth/certificates/MasterCertificate.js +1 -1
  8. package/dist/cjs/src/auth/certificates/MasterCertificate.js.map +1 -1
  9. package/dist/cjs/src/auth/certificates/__tests/CompletedProtoWallet.js +1 -1
  10. package/dist/cjs/src/auth/certificates/__tests/CompletedProtoWallet.js.map +1 -1
  11. package/dist/cjs/src/auth/clients/AuthFetch.js +32 -32
  12. package/dist/cjs/src/auth/clients/AuthFetch.js.map +1 -1
  13. package/dist/cjs/src/auth/transports/SimplifiedFetchTransport.js +4 -4
  14. package/dist/cjs/src/auth/transports/SimplifiedFetchTransport.js.map +1 -1
  15. package/dist/cjs/src/compat/ECIES.js +29 -34
  16. package/dist/cjs/src/compat/ECIES.js.map +1 -1
  17. package/dist/cjs/src/compat/HD.js +9 -4
  18. package/dist/cjs/src/compat/HD.js.map +1 -1
  19. package/dist/cjs/src/compat/Mnemonic.js +12 -12
  20. package/dist/cjs/src/compat/Mnemonic.js.map +1 -1
  21. package/dist/cjs/src/identity/ContactsManager.js +212 -234
  22. package/dist/cjs/src/identity/ContactsManager.js.map +1 -1
  23. package/dist/cjs/src/identity/IdentityClient.js +199 -63
  24. package/dist/cjs/src/identity/IdentityClient.js.map +1 -1
  25. package/dist/cjs/src/kvstore/GlobalKVStore.js +30 -31
  26. package/dist/cjs/src/kvstore/GlobalKVStore.js.map +1 -1
  27. package/dist/cjs/src/kvstore/LocalKVStore.js +9 -9
  28. package/dist/cjs/src/kvstore/LocalKVStore.js.map +1 -1
  29. package/dist/cjs/src/kvstore/kvStoreInterpreter.js +2 -2
  30. package/dist/cjs/src/kvstore/kvStoreInterpreter.js.map +1 -1
  31. package/dist/cjs/src/messages/SignedMessage.js +1 -1
  32. package/dist/cjs/src/messages/SignedMessage.js.map +1 -1
  33. package/dist/cjs/src/overlay-tools/Historian.js +1 -1
  34. package/dist/cjs/src/overlay-tools/Historian.js.map +1 -1
  35. package/dist/cjs/src/overlay-tools/LookupResolver.js +213 -93
  36. package/dist/cjs/src/overlay-tools/LookupResolver.js.map +1 -1
  37. package/dist/cjs/src/overlay-tools/SHIPBroadcaster.js +75 -146
  38. package/dist/cjs/src/overlay-tools/SHIPBroadcaster.js.map +1 -1
  39. package/dist/cjs/src/primitives/AESGCM.js +2 -2
  40. package/dist/cjs/src/primitives/AESGCM.js.map +1 -1
  41. package/dist/cjs/src/primitives/BigNumber.js +164 -148
  42. package/dist/cjs/src/primitives/BigNumber.js.map +1 -1
  43. package/dist/cjs/src/primitives/Curve.js +17 -15
  44. package/dist/cjs/src/primitives/Curve.js.map +1 -1
  45. package/dist/cjs/src/primitives/ECDSA.js +12 -7
  46. package/dist/cjs/src/primitives/ECDSA.js.map +1 -1
  47. package/dist/cjs/src/primitives/Hash.js +312 -105
  48. package/dist/cjs/src/primitives/Hash.js.map +1 -1
  49. package/dist/cjs/src/primitives/JacobianPoint.js +8 -8
  50. package/dist/cjs/src/primitives/JacobianPoint.js.map +1 -1
  51. package/dist/cjs/src/primitives/K256.js +3 -3
  52. package/dist/cjs/src/primitives/K256.js.map +1 -1
  53. package/dist/cjs/src/primitives/Point.js +36 -40
  54. package/dist/cjs/src/primitives/Point.js.map +1 -1
  55. package/dist/cjs/src/primitives/PrivateKey.js +4 -4
  56. package/dist/cjs/src/primitives/PrivateKey.js.map +1 -1
  57. package/dist/cjs/src/primitives/PublicKey.js +4 -4
  58. package/dist/cjs/src/primitives/PublicKey.js.map +1 -1
  59. package/dist/cjs/src/primitives/Random.js +10 -14
  60. package/dist/cjs/src/primitives/Random.js.map +1 -1
  61. package/dist/cjs/src/primitives/ReaderUint8Array.js +6 -6
  62. package/dist/cjs/src/primitives/ReaderUint8Array.js.map +1 -1
  63. package/dist/cjs/src/primitives/Schnorr.js +2 -2
  64. package/dist/cjs/src/primitives/Schnorr.js.map +1 -1
  65. package/dist/cjs/src/primitives/Secp256r1.js +2 -1
  66. package/dist/cjs/src/primitives/Secp256r1.js.map +1 -1
  67. package/dist/cjs/src/primitives/Signature.js +8 -8
  68. package/dist/cjs/src/primitives/Signature.js.map +1 -1
  69. package/dist/cjs/src/primitives/SymmetricKey.js +123 -1
  70. package/dist/cjs/src/primitives/SymmetricKey.js.map +1 -1
  71. package/dist/cjs/src/primitives/TransactionSignature.js +20 -21
  72. package/dist/cjs/src/primitives/TransactionSignature.js.map +1 -1
  73. package/dist/cjs/src/primitives/utils.js +39 -46
  74. package/dist/cjs/src/primitives/utils.js.map +1 -1
  75. package/dist/cjs/src/registry/RegistryClient.js +31 -23
  76. package/dist/cjs/src/registry/RegistryClient.js.map +1 -1
  77. package/dist/cjs/src/remittance/RemittanceManager.js +19 -18
  78. package/dist/cjs/src/remittance/RemittanceManager.js.map +1 -1
  79. package/dist/cjs/src/remittance/modules/BasicBRC29.js.map +1 -1
  80. package/dist/cjs/src/script/Script.js +93 -170
  81. package/dist/cjs/src/script/Script.js.map +1 -1
  82. package/dist/cjs/src/script/ScriptEvaluationError.js +2 -2
  83. package/dist/cjs/src/script/ScriptEvaluationError.js.map +1 -1
  84. package/dist/cjs/src/script/Spend.js +14 -12
  85. package/dist/cjs/src/script/Spend.js.map +1 -1
  86. package/dist/cjs/src/script/templates/PushDrop.js +22 -18
  87. package/dist/cjs/src/script/templates/PushDrop.js.map +1 -1
  88. package/dist/cjs/src/script/templates/RPuzzle.js +2 -4
  89. package/dist/cjs/src/script/templates/RPuzzle.js.map +1 -1
  90. package/dist/cjs/src/storage/StorageDownloader.js +42 -9
  91. package/dist/cjs/src/storage/StorageDownloader.js.map +1 -1
  92. package/dist/cjs/src/totp/totp.js +1 -1
  93. package/dist/cjs/src/totp/totp.js.map +1 -1
  94. package/dist/cjs/src/transaction/Beef.js +239 -192
  95. package/dist/cjs/src/transaction/Beef.js.map +1 -1
  96. package/dist/cjs/src/transaction/BeefConstants.js +19 -0
  97. package/dist/cjs/src/transaction/BeefConstants.js.map +1 -0
  98. package/dist/cjs/src/transaction/BeefTx.js +12 -12
  99. package/dist/cjs/src/transaction/BeefTx.js.map +1 -1
  100. package/dist/cjs/src/transaction/MerklePath.js +4 -4
  101. package/dist/cjs/src/transaction/MerklePath.js.map +1 -1
  102. package/dist/cjs/src/transaction/Transaction.js +49 -52
  103. package/dist/cjs/src/transaction/Transaction.js.map +1 -1
  104. package/dist/cjs/src/transaction/fee-models/SatoshisPerKilobyte.js +1 -1
  105. package/dist/cjs/src/transaction/fee-models/SatoshisPerKilobyte.js.map +1 -1
  106. package/dist/cjs/src/transaction/http/BinaryFetchClient.js +9 -9
  107. package/dist/cjs/src/transaction/http/BinaryFetchClient.js.map +1 -1
  108. package/dist/cjs/src/transaction/http/DefaultHttpClient.js +9 -9
  109. package/dist/cjs/src/transaction/http/DefaultHttpClient.js.map +1 -1
  110. package/dist/cjs/src/wallet/CachedKeyDeriver.js +1 -1
  111. package/dist/cjs/src/wallet/CachedKeyDeriver.js.map +1 -1
  112. package/dist/cjs/src/wallet/WalletClient.js.map +1 -1
  113. package/dist/cjs/src/wallet/WalletError.js.map +1 -1
  114. package/dist/cjs/src/wallet/substrates/HTTPWalletJSON.js +5 -4
  115. package/dist/cjs/src/wallet/substrates/HTTPWalletJSON.js.map +1 -1
  116. package/dist/cjs/src/wallet/substrates/ReactNativeWebView.js +9 -9
  117. package/dist/cjs/src/wallet/substrates/ReactNativeWebView.js.map +1 -1
  118. package/dist/cjs/src/wallet/substrates/WalletWireProcessor.js +92 -92
  119. package/dist/cjs/src/wallet/substrates/WalletWireProcessor.js.map +1 -1
  120. package/dist/cjs/src/wallet/substrates/WalletWireTransceiver.js +387 -711
  121. package/dist/cjs/src/wallet/substrates/WalletWireTransceiver.js.map +1 -1
  122. package/dist/cjs/src/wallet/substrates/XDM.js +4 -4
  123. package/dist/cjs/src/wallet/substrates/XDM.js.map +1 -1
  124. package/dist/cjs/src/wallet/substrates/window.CWI.js +2 -2
  125. package/dist/cjs/src/wallet/substrates/window.CWI.js.map +1 -1
  126. package/dist/cjs/src/wallet/validationHelpers.js +9 -9
  127. package/dist/cjs/src/wallet/validationHelpers.js.map +1 -1
  128. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  129. package/dist/esm/src/auth/Peer.js +25 -13
  130. package/dist/esm/src/auth/Peer.js.map +1 -1
  131. package/dist/esm/src/auth/SessionManager.js +4 -7
  132. package/dist/esm/src/auth/SessionManager.js.map +1 -1
  133. package/dist/esm/src/auth/certificates/MasterCertificate.js +1 -1
  134. package/dist/esm/src/auth/certificates/MasterCertificate.js.map +1 -1
  135. package/dist/esm/src/auth/certificates/__tests/CompletedProtoWallet.js +1 -1
  136. package/dist/esm/src/auth/certificates/__tests/CompletedProtoWallet.js.map +1 -1
  137. package/dist/esm/src/auth/clients/AuthFetch.js +32 -32
  138. package/dist/esm/src/auth/clients/AuthFetch.js.map +1 -1
  139. package/dist/esm/src/auth/transports/SimplifiedFetchTransport.js +4 -4
  140. package/dist/esm/src/auth/transports/SimplifiedFetchTransport.js.map +1 -1
  141. package/dist/esm/src/compat/ECIES.js +29 -34
  142. package/dist/esm/src/compat/ECIES.js.map +1 -1
  143. package/dist/esm/src/compat/HD.js +9 -4
  144. package/dist/esm/src/compat/HD.js.map +1 -1
  145. package/dist/esm/src/compat/Mnemonic.js +12 -12
  146. package/dist/esm/src/compat/Mnemonic.js.map +1 -1
  147. package/dist/esm/src/identity/ContactsManager.js +212 -234
  148. package/dist/esm/src/identity/ContactsManager.js.map +1 -1
  149. package/dist/esm/src/identity/IdentityClient.js +199 -63
  150. package/dist/esm/src/identity/IdentityClient.js.map +1 -1
  151. package/dist/esm/src/kvstore/GlobalKVStore.js +30 -31
  152. package/dist/esm/src/kvstore/GlobalKVStore.js.map +1 -1
  153. package/dist/esm/src/kvstore/LocalKVStore.js +9 -9
  154. package/dist/esm/src/kvstore/LocalKVStore.js.map +1 -1
  155. package/dist/esm/src/kvstore/kvStoreInterpreter.js +2 -2
  156. package/dist/esm/src/kvstore/kvStoreInterpreter.js.map +1 -1
  157. package/dist/esm/src/messages/SignedMessage.js +1 -1
  158. package/dist/esm/src/messages/SignedMessage.js.map +1 -1
  159. package/dist/esm/src/overlay-tools/Historian.js +1 -1
  160. package/dist/esm/src/overlay-tools/Historian.js.map +1 -1
  161. package/dist/esm/src/overlay-tools/LookupResolver.js +213 -93
  162. package/dist/esm/src/overlay-tools/LookupResolver.js.map +1 -1
  163. package/dist/esm/src/overlay-tools/SHIPBroadcaster.js +74 -146
  164. package/dist/esm/src/overlay-tools/SHIPBroadcaster.js.map +1 -1
  165. package/dist/esm/src/primitives/AESGCM.js +2 -2
  166. package/dist/esm/src/primitives/AESGCM.js.map +1 -1
  167. package/dist/esm/src/primitives/BigNumber.js +167 -154
  168. package/dist/esm/src/primitives/BigNumber.js.map +1 -1
  169. package/dist/esm/src/primitives/Curve.js +17 -15
  170. package/dist/esm/src/primitives/Curve.js.map +1 -1
  171. package/dist/esm/src/primitives/ECDSA.js +12 -7
  172. package/dist/esm/src/primitives/ECDSA.js.map +1 -1
  173. package/dist/esm/src/primitives/Hash.js +316 -105
  174. package/dist/esm/src/primitives/Hash.js.map +1 -1
  175. package/dist/esm/src/primitives/JacobianPoint.js +8 -8
  176. package/dist/esm/src/primitives/JacobianPoint.js.map +1 -1
  177. package/dist/esm/src/primitives/K256.js +3 -3
  178. package/dist/esm/src/primitives/K256.js.map +1 -1
  179. package/dist/esm/src/primitives/Point.js +36 -40
  180. package/dist/esm/src/primitives/Point.js.map +1 -1
  181. package/dist/esm/src/primitives/PrivateKey.js +4 -4
  182. package/dist/esm/src/primitives/PrivateKey.js.map +1 -1
  183. package/dist/esm/src/primitives/PublicKey.js +4 -4
  184. package/dist/esm/src/primitives/PublicKey.js.map +1 -1
  185. package/dist/esm/src/primitives/Random.js +10 -14
  186. package/dist/esm/src/primitives/Random.js.map +1 -1
  187. package/dist/esm/src/primitives/ReaderUint8Array.js +6 -6
  188. package/dist/esm/src/primitives/ReaderUint8Array.js.map +1 -1
  189. package/dist/esm/src/primitives/Schnorr.js +1 -1
  190. package/dist/esm/src/primitives/Schnorr.js.map +1 -1
  191. package/dist/esm/src/primitives/Secp256r1.js +2 -1
  192. package/dist/esm/src/primitives/Secp256r1.js.map +1 -1
  193. package/dist/esm/src/primitives/Signature.js +8 -8
  194. package/dist/esm/src/primitives/Signature.js.map +1 -1
  195. package/dist/esm/src/primitives/SymmetricKey.js +123 -1
  196. package/dist/esm/src/primitives/SymmetricKey.js.map +1 -1
  197. package/dist/esm/src/primitives/TransactionSignature.js +20 -21
  198. package/dist/esm/src/primitives/TransactionSignature.js.map +1 -1
  199. package/dist/esm/src/primitives/utils.js +39 -48
  200. package/dist/esm/src/primitives/utils.js.map +1 -1
  201. package/dist/esm/src/registry/RegistryClient.js +31 -23
  202. package/dist/esm/src/registry/RegistryClient.js.map +1 -1
  203. package/dist/esm/src/remittance/RemittanceManager.js +19 -18
  204. package/dist/esm/src/remittance/RemittanceManager.js.map +1 -1
  205. package/dist/esm/src/remittance/modules/BasicBRC29.js.map +1 -1
  206. package/dist/esm/src/script/Script.js +93 -170
  207. package/dist/esm/src/script/Script.js.map +1 -1
  208. package/dist/esm/src/script/ScriptEvaluationError.js +2 -2
  209. package/dist/esm/src/script/ScriptEvaluationError.js.map +1 -1
  210. package/dist/esm/src/script/Spend.js +14 -12
  211. package/dist/esm/src/script/Spend.js.map +1 -1
  212. package/dist/esm/src/script/templates/PushDrop.js +4 -3
  213. package/dist/esm/src/script/templates/PushDrop.js.map +1 -1
  214. package/dist/esm/src/script/templates/RPuzzle.js +2 -4
  215. package/dist/esm/src/script/templates/RPuzzle.js.map +1 -1
  216. package/dist/esm/src/storage/StorageDownloader.js +1 -1
  217. package/dist/esm/src/storage/StorageDownloader.js.map +1 -1
  218. package/dist/esm/src/totp/totp.js +1 -1
  219. package/dist/esm/src/totp/totp.js.map +1 -1
  220. package/dist/esm/src/transaction/Beef.js +229 -186
  221. package/dist/esm/src/transaction/Beef.js.map +1 -1
  222. package/dist/esm/src/transaction/BeefConstants.js +16 -0
  223. package/dist/esm/src/transaction/BeefConstants.js.map +1 -0
  224. package/dist/esm/src/transaction/BeefTx.js +3 -3
  225. package/dist/esm/src/transaction/BeefTx.js.map +1 -1
  226. package/dist/esm/src/transaction/MerklePath.js +4 -4
  227. package/dist/esm/src/transaction/MerklePath.js.map +1 -1
  228. package/dist/esm/src/transaction/Transaction.js +49 -52
  229. package/dist/esm/src/transaction/Transaction.js.map +1 -1
  230. package/dist/esm/src/transaction/fee-models/SatoshisPerKilobyte.js +1 -1
  231. package/dist/esm/src/transaction/fee-models/SatoshisPerKilobyte.js.map +1 -1
  232. package/dist/esm/src/transaction/http/BinaryFetchClient.js +9 -9
  233. package/dist/esm/src/transaction/http/BinaryFetchClient.js.map +1 -1
  234. package/dist/esm/src/transaction/http/DefaultHttpClient.js +9 -9
  235. package/dist/esm/src/transaction/http/DefaultHttpClient.js.map +1 -1
  236. package/dist/esm/src/wallet/CachedKeyDeriver.js +1 -1
  237. package/dist/esm/src/wallet/CachedKeyDeriver.js.map +1 -1
  238. package/dist/esm/src/wallet/WalletClient.js.map +1 -1
  239. package/dist/esm/src/wallet/WalletError.js.map +1 -1
  240. package/dist/esm/src/wallet/substrates/HTTPWalletJSON.js +5 -4
  241. package/dist/esm/src/wallet/substrates/HTTPWalletJSON.js.map +1 -1
  242. package/dist/esm/src/wallet/substrates/ReactNativeWebView.js +9 -9
  243. package/dist/esm/src/wallet/substrates/ReactNativeWebView.js.map +1 -1
  244. package/dist/esm/src/wallet/substrates/WalletWireProcessor.js +92 -92
  245. package/dist/esm/src/wallet/substrates/WalletWireProcessor.js.map +1 -1
  246. package/dist/esm/src/wallet/substrates/WalletWireTransceiver.js +387 -711
  247. package/dist/esm/src/wallet/substrates/WalletWireTransceiver.js.map +1 -1
  248. package/dist/esm/src/wallet/substrates/XDM.js +4 -4
  249. package/dist/esm/src/wallet/substrates/XDM.js.map +1 -1
  250. package/dist/esm/src/wallet/substrates/window.CWI.js +2 -2
  251. package/dist/esm/src/wallet/substrates/window.CWI.js.map +1 -1
  252. package/dist/esm/src/wallet/validationHelpers.js +9 -9
  253. package/dist/esm/src/wallet/validationHelpers.js.map +1 -1
  254. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  255. package/dist/types/src/auth/Peer.d.ts +13 -0
  256. package/dist/types/src/auth/Peer.d.ts.map +1 -1
  257. package/dist/types/src/auth/SessionManager.d.ts.map +1 -1
  258. package/dist/types/src/auth/clients/AuthFetch.d.ts.map +1 -1
  259. package/dist/types/src/compat/ECIES.d.ts.map +1 -1
  260. package/dist/types/src/compat/HD.d.ts.map +1 -1
  261. package/dist/types/src/identity/ContactsManager.d.ts +31 -2
  262. package/dist/types/src/identity/ContactsManager.d.ts.map +1 -1
  263. package/dist/types/src/identity/IdentityClient.d.ts +75 -10
  264. package/dist/types/src/identity/IdentityClient.d.ts.map +1 -1
  265. package/dist/types/src/kvstore/GlobalKVStore.d.ts.map +1 -1
  266. package/dist/types/src/overlay-tools/LookupResolver.d.ts +73 -2
  267. package/dist/types/src/overlay-tools/LookupResolver.d.ts.map +1 -1
  268. package/dist/types/src/overlay-tools/SHIPBroadcaster.d.ts +18 -3
  269. package/dist/types/src/overlay-tools/SHIPBroadcaster.d.ts.map +1 -1
  270. package/dist/types/src/primitives/BigNumber.d.ts +13 -3
  271. package/dist/types/src/primitives/BigNumber.d.ts.map +1 -1
  272. package/dist/types/src/primitives/Curve.d.ts.map +1 -1
  273. package/dist/types/src/primitives/ECDSA.d.ts.map +1 -1
  274. package/dist/types/src/primitives/Hash.d.ts +22 -17
  275. package/dist/types/src/primitives/Hash.d.ts.map +1 -1
  276. package/dist/types/src/primitives/JacobianPoint.d.ts +3 -1
  277. package/dist/types/src/primitives/JacobianPoint.d.ts.map +1 -1
  278. package/dist/types/src/primitives/Point.d.ts.map +1 -1
  279. package/dist/types/src/primitives/Random.d.ts +2 -2
  280. package/dist/types/src/primitives/Random.d.ts.map +1 -1
  281. package/dist/types/src/primitives/ReaderUint8Array.d.ts.map +1 -1
  282. package/dist/types/src/primitives/Schnorr.d.ts +2 -1
  283. package/dist/types/src/primitives/Schnorr.d.ts.map +1 -1
  284. package/dist/types/src/primitives/Secp256r1.d.ts.map +1 -1
  285. package/dist/types/src/primitives/SymmetricKey.d.ts.map +1 -1
  286. package/dist/types/src/primitives/utils.d.ts +2 -4
  287. package/dist/types/src/primitives/utils.d.ts.map +1 -1
  288. package/dist/types/src/registry/RegistryClient.d.ts.map +1 -1
  289. package/dist/types/src/remittance/RemittanceManager.d.ts.map +1 -1
  290. package/dist/types/src/remittance/modules/BasicBRC29.d.ts.map +1 -1
  291. package/dist/types/src/script/Script.d.ts +15 -8
  292. package/dist/types/src/script/Script.d.ts.map +1 -1
  293. package/dist/types/src/script/Spend.d.ts.map +1 -1
  294. package/dist/types/src/script/templates/PushDrop.d.ts +3 -1
  295. package/dist/types/src/script/templates/PushDrop.d.ts.map +1 -1
  296. package/dist/types/src/script/templates/RPuzzle.d.ts.map +1 -1
  297. package/dist/types/src/transaction/Beef.d.ts +46 -8
  298. package/dist/types/src/transaction/Beef.d.ts.map +1 -1
  299. package/dist/types/src/transaction/BeefConstants.d.ts +15 -0
  300. package/dist/types/src/transaction/BeefConstants.d.ts.map +1 -0
  301. package/dist/types/src/transaction/Transaction.d.ts.map +1 -1
  302. package/dist/types/src/wallet/CachedKeyDeriver.d.ts.map +1 -1
  303. package/dist/types/src/wallet/KeyDeriver.d.ts +1 -1
  304. package/dist/types/src/wallet/KeyDeriver.d.ts.map +1 -1
  305. package/dist/types/src/wallet/Wallet.interfaces.d.ts +18 -3
  306. package/dist/types/src/wallet/Wallet.interfaces.d.ts.map +1 -1
  307. package/dist/types/src/wallet/WalletClient.d.ts +8 -8
  308. package/dist/types/src/wallet/WalletClient.d.ts.map +1 -1
  309. package/dist/types/src/wallet/substrates/HTTPWalletJSON.d.ts +7 -7
  310. package/dist/types/src/wallet/substrates/HTTPWalletJSON.d.ts.map +1 -1
  311. package/dist/types/src/wallet/substrates/WalletWireTransceiver.d.ts +36 -7
  312. package/dist/types/src/wallet/substrates/WalletWireTransceiver.d.ts.map +1 -1
  313. package/dist/types/src/wallet/substrates/window.CWI.d.ts +9 -9
  314. package/dist/types/src/wallet/substrates/window.CWI.d.ts.map +1 -1
  315. package/dist/types/tsconfig.types.tsbuildinfo +1 -1
  316. package/dist/umd/bundle.js +3 -3
  317. package/package.json +1 -1
  318. package/src/auth/Peer.ts +26 -13
  319. package/src/auth/SessionManager.ts +4 -7
  320. package/src/auth/certificates/MasterCertificate.ts +1 -1
  321. package/src/auth/certificates/__tests/CompletedProtoWallet.ts +1 -1
  322. package/src/auth/clients/AuthFetch.ts +41 -41
  323. package/src/auth/transports/SimplifiedFetchTransport.ts +4 -4
  324. package/src/compat/ECIES.ts +29 -34
  325. package/src/compat/HD.ts +10 -5
  326. package/src/compat/Mnemonic.ts +11 -11
  327. package/src/compat/__tests/HD.test.ts +19 -0
  328. package/src/identity/ContactsManager.ts +236 -258
  329. package/src/identity/IdentityClient.ts +244 -71
  330. package/src/identity/__tests/IdentityClient.additional.test.ts +150 -1
  331. package/src/identity/__tests/IdentityClient.test.ts +27 -3
  332. package/src/kvstore/GlobalKVStore.ts +31 -32
  333. package/src/kvstore/LocalKVStore.ts +8 -8
  334. package/src/kvstore/kvStoreInterpreter.ts +2 -2
  335. package/src/messages/SignedMessage.ts +1 -1
  336. package/src/overlay-tools/Historian.ts +1 -1
  337. package/src/overlay-tools/LookupResolver.ts +264 -90
  338. package/src/overlay-tools/SHIPBroadcaster.ts +92 -168
  339. package/src/primitives/AESGCM.ts +2 -2
  340. package/src/primitives/BigNumber.ts +122 -113
  341. package/src/primitives/Curve.ts +16 -15
  342. package/src/primitives/ECDSA.ts +10 -8
  343. package/src/primitives/Hash.ts +381 -146
  344. package/src/primitives/JacobianPoint.ts +13 -11
  345. package/src/primitives/K256.ts +3 -3
  346. package/src/primitives/Point.ts +35 -38
  347. package/src/primitives/PrivateKey.ts +3 -3
  348. package/src/primitives/PublicKey.ts +3 -3
  349. package/src/primitives/Random.ts +11 -14
  350. package/src/primitives/ReaderUint8Array.ts +7 -7
  351. package/src/primitives/Schnorr.ts +2 -1
  352. package/src/primitives/Secp256r1.ts +2 -1
  353. package/src/primitives/Signature.ts +8 -8
  354. package/src/primitives/SymmetricKey.ts +145 -1
  355. package/src/primitives/TransactionSignature.ts +16 -16
  356. package/src/primitives/__tests/Hash.additional.test.ts +65 -0
  357. package/src/primitives/__tests/Hash.test.ts +6 -1
  358. package/src/primitives/utils.ts +37 -47
  359. package/src/registry/RegistryClient.ts +25 -25
  360. package/src/remittance/RemittanceManager.ts +17 -18
  361. package/src/remittance/modules/BasicBRC29.ts +2 -5
  362. package/src/script/Script.ts +114 -170
  363. package/src/script/ScriptEvaluationError.ts +2 -2
  364. package/src/script/Spend.ts +14 -15
  365. package/src/script/templates/PushDrop.ts +5 -3
  366. package/src/script/templates/RPuzzle.ts +2 -4
  367. package/src/storage/StorageDownloader.ts +1 -1
  368. package/src/totp/totp.ts +1 -1
  369. package/src/transaction/Beef.ts +241 -203
  370. package/src/transaction/BeefConstants.ts +16 -0
  371. package/src/transaction/BeefTx.ts +3 -3
  372. package/src/transaction/MerklePath.ts +4 -4
  373. package/src/transaction/Transaction.ts +48 -51
  374. package/src/transaction/fee-models/SatoshisPerKilobyte.ts +1 -1
  375. package/src/transaction/http/BinaryFetchClient.ts +8 -8
  376. package/src/transaction/http/DefaultHttpClient.ts +8 -8
  377. package/src/wallet/CachedKeyDeriver.ts +8 -6
  378. package/src/wallet/KeyDeriver.ts +1 -1
  379. package/src/wallet/Wallet.interfaces.ts +18 -5
  380. package/src/wallet/WalletClient.ts +9 -9
  381. package/src/wallet/WalletError.ts +1 -1
  382. package/src/wallet/__tests/WalletClient.substrate.test.ts +10 -6
  383. package/src/wallet/substrates/HTTPWalletJSON.ts +22 -21
  384. package/src/wallet/substrates/ReactNativeWebView.ts +9 -9
  385. package/src/wallet/substrates/WalletWireProcessor.ts +83 -83
  386. package/src/wallet/substrates/WalletWireTransceiver.ts +528 -938
  387. package/src/wallet/substrates/XDM.ts +4 -4
  388. package/src/wallet/substrates/__tests/HTTPWalletJSON.test.ts +38 -25
  389. package/src/wallet/substrates/__tests/ReactNativeWebView.test.ts +174 -0
  390. package/src/wallet/substrates/__tests/window.CWI.test.ts +256 -0
  391. package/src/wallet/substrates/window.CWI.ts +11 -11
  392. package/src/wallet/validationHelpers.ts +9 -9
@@ -6,7 +6,6 @@ import {
6
6
  SecurityLevels,
7
7
  Base64String,
8
8
  BasketStringUnder300Bytes,
9
- BEEF,
10
9
  BooleanDefaultFalse,
11
10
  BooleanDefaultTrue,
12
11
  Byte,
@@ -45,7 +44,8 @@ import {
45
44
  TXIDHexString,
46
45
  VersionString7To30Bytes,
47
46
  WalletInterface,
48
- ActionStatus
47
+ ActionStatus,
48
+ SendWithResultStatus
49
49
  } from '../Wallet.interfaces.js'
50
50
  import WalletWire from './WalletWire.js'
51
51
  import Certificate from '../../auth/certificates/Certificate.js'
@@ -53,17 +53,28 @@ import * as Utils from '../../primitives/utils.js'
53
53
  import calls, { CallType } from './WalletWireCalls.js'
54
54
  import { WalletError } from '../WalletError.js'
55
55
 
56
+ const ACTION_STATUS_MAP: Record<number, ActionStatus> = {
57
+ 1: 'completed',
58
+ 2: 'unprocessed',
59
+ 3: 'sending',
60
+ 4: 'unproven',
61
+ 5: 'unsigned',
62
+ 6: 'nosend',
63
+ 7: 'nonfinal',
64
+ 8: 'failed'
65
+ }
66
+
56
67
  /**
57
68
  * A way to make remote calls to a wallet over a wallet wire.
58
69
  */
59
70
  export default class WalletWireTransceiver implements WalletInterface {
60
71
  wire: WalletWire
61
72
 
62
- constructor(wire: WalletWire) {
73
+ constructor (wire: WalletWire) {
63
74
  this.wire = wire
64
75
  }
65
76
 
66
- private async transmit(
77
+ private async transmit (
67
78
  call: CallType,
68
79
  originator: OriginatorDomainNameStringUnder250Bytes = '',
69
80
  params: number[] = []
@@ -100,307 +111,91 @@ export default class WalletWireTransceiver implements WalletInterface {
100
111
  }
101
112
  }
102
113
 
103
- async createAction(
114
+ async createAction (
104
115
  args: CreateActionArgs,
105
116
  originator?: OriginatorDomainNameStringUnder250Bytes
106
117
  ): Promise<CreateActionResult> {
107
118
  const paramWriter = new Utils.Writer()
108
119
 
109
120
  // Serialize description
110
- const descriptionBytes = Utils.toArray(args.description, 'utf8')
111
- paramWriter.writeVarIntNum(descriptionBytes.length)
112
- paramWriter.write(descriptionBytes)
121
+ this.writeUTF8(paramWriter, args.description)
113
122
 
114
123
  // input BEEF
115
- if (args.inputBEEF != null) {
124
+ if (args.inputBEEF == null) {
125
+ paramWriter.writeVarIntNum(-1)
126
+ } else {
116
127
  paramWriter.writeVarIntNum(args.inputBEEF.length)
117
128
  paramWriter.write(args.inputBEEF)
118
- } else {
119
- paramWriter.writeVarIntNum(-1)
120
129
  }
121
130
 
122
131
  // Serialize inputs
123
- if (args.inputs != null) {
132
+ if (args.inputs == null) {
133
+ paramWriter.writeVarIntNum(-1)
134
+ } else {
124
135
  paramWriter.writeVarIntNum(args.inputs.length)
125
136
  for (const input of args.inputs) {
126
- // outpoint
127
- paramWriter.write(this.encodeOutpoint(input.outpoint))
128
-
129
- // unlockingScript / unlockingScriptLength
130
- if (input.unlockingScript != null && input.unlockingScript !== '') {
131
- const unlockingScriptBytes = Utils.toArray(
132
- input.unlockingScript,
133
- 'hex'
134
- )
135
- paramWriter.writeVarIntNum(unlockingScriptBytes.length)
136
- paramWriter.write(unlockingScriptBytes)
137
- } else {
138
- paramWriter.writeVarIntNum(-1)
139
- paramWriter.writeVarIntNum(input.unlockingScriptLength ?? 0)
140
- }
141
-
142
- // inputDescription
143
- const inputDescriptionBytes = Utils.toArray(
144
- input.inputDescription,
145
- 'utf8'
146
- )
147
- paramWriter.writeVarIntNum(inputDescriptionBytes.length)
148
- paramWriter.write(inputDescriptionBytes)
149
-
150
- // sequenceNumber
151
- if (typeof input.sequenceNumber === 'number') {
152
- paramWriter.writeVarIntNum(input.sequenceNumber)
153
- } else {
154
- paramWriter.writeVarIntNum(-1)
155
- }
137
+ this.serializeCreateActionInput(paramWriter, input)
156
138
  }
157
- } else {
158
- paramWriter.writeVarIntNum(-1)
159
139
  }
160
140
 
161
141
  // Serialize outputs
162
- if (args.outputs != null) {
142
+ if (args.outputs == null) {
143
+ paramWriter.writeVarIntNum(-1)
144
+ } else {
163
145
  paramWriter.writeVarIntNum(args.outputs.length)
164
146
  for (const output of args.outputs) {
165
- // lockingScript
166
- const lockingScriptBytes = Utils.toArray(output.lockingScript, 'hex')
167
- paramWriter.writeVarIntNum(lockingScriptBytes.length)
168
- paramWriter.write(lockingScriptBytes)
169
-
170
- // satoshis
171
- paramWriter.writeVarIntNum(output.satoshis)
172
-
173
- // outputDescription
174
- const outputDescriptionBytes = Utils.toArray(
175
- output.outputDescription,
176
- 'utf8'
177
- )
178
- paramWriter.writeVarIntNum(outputDescriptionBytes.length)
179
- paramWriter.write(outputDescriptionBytes)
180
-
181
- // basket
182
- if (output.basket != null && output.basket !== '') {
183
- const basketBytes = Utils.toArray(output.basket, 'utf8')
184
- paramWriter.writeVarIntNum(basketBytes.length)
185
- paramWriter.write(basketBytes)
186
- } else {
187
- paramWriter.writeVarIntNum(-1)
188
- }
189
-
190
- // customInstructions
191
- if (output.customInstructions != null && output.customInstructions !== '') {
192
- const customInstructionsBytes = Utils.toArray(
193
- output.customInstructions,
194
- 'utf8'
195
- )
196
- paramWriter.writeVarIntNum(customInstructionsBytes.length)
197
- paramWriter.write(customInstructionsBytes)
198
- } else {
199
- paramWriter.writeVarIntNum(-1)
200
- }
201
-
202
- // tags
203
- if (output.tags != null) {
204
- paramWriter.writeVarIntNum(output.tags.length)
205
- for (const tag of output.tags) {
206
- const tagBytes = Utils.toArray(tag, 'utf8')
207
- paramWriter.writeVarIntNum(tagBytes.length)
208
- paramWriter.write(tagBytes)
209
- }
210
- } else {
211
- paramWriter.writeVarIntNum(-1)
212
- }
147
+ this.serializeCreateActionOutput(paramWriter, output)
213
148
  }
214
- } else {
215
- paramWriter.writeVarIntNum(-1)
216
149
  }
217
150
 
218
- // Serialize lockTime
219
- if (typeof args.lockTime === 'number') {
220
- paramWriter.writeVarIntNum(args.lockTime)
221
- } else {
222
- paramWriter.writeVarIntNum(-1)
223
- }
224
-
225
- // Serialize version
226
- if (typeof args.version === 'number') {
227
- paramWriter.writeVarIntNum(args.version)
228
- } else {
229
- paramWriter.writeVarIntNum(-1)
230
- }
151
+ // Serialize lockTime, version
152
+ this.writeOptionalVarInt(paramWriter, args.lockTime)
153
+ this.writeOptionalVarInt(paramWriter, args.version)
231
154
 
232
155
  // Serialize labels
233
- if (args.labels != null) {
234
- paramWriter.writeVarIntNum(args.labels.length)
235
- for (const label of args.labels) {
236
- const labelBytes = Utils.toArray(label, 'utf8')
237
- paramWriter.writeVarIntNum(labelBytes.length)
238
- paramWriter.write(labelBytes)
239
- }
240
- } else {
241
- paramWriter.writeVarIntNum(-1)
242
- }
156
+ this.writeUTF8Array(paramWriter, args.labels)
243
157
 
244
158
  // Serialize options
245
- if (args.options != null) {
246
- paramWriter.writeInt8(1) // options present
247
-
248
- // signAndProcess
249
- if (typeof args.options.signAndProcess === 'boolean') {
250
- paramWriter.writeInt8(args.options.signAndProcess ? 1 : 0)
251
- } else {
252
- paramWriter.writeInt8(-1)
253
- }
254
-
255
- // acceptDelayedBroadcast
256
- if (typeof args.options.acceptDelayedBroadcast === 'boolean') {
257
- paramWriter.writeInt8(args.options.acceptDelayedBroadcast ? 1 : 0)
258
- } else {
259
- paramWriter.writeInt8(-1)
260
- }
261
-
262
- // trustSelf
263
- if (args.options.trustSelf === 'known') {
264
- paramWriter.writeInt8(1)
265
- } else {
266
- paramWriter.writeInt8(-1)
267
- }
268
-
269
- // knownTxids
270
- if (args.options.knownTxids != null) {
271
- paramWriter.writeVarIntNum(args.options.knownTxids.length)
272
- for (const txid of args.options.knownTxids) {
273
- const txidBytes = Utils.toArray(txid, 'hex')
274
- paramWriter.write(txidBytes)
275
- }
276
- } else {
277
- paramWriter.writeVarIntNum(-1)
278
- }
279
-
280
- // returnTXIDOnly
281
- if (typeof args.options.returnTXIDOnly === 'boolean') {
282
- paramWriter.writeInt8(args.options.returnTXIDOnly ? 1 : 0)
283
- } else {
284
- paramWriter.writeInt8(-1)
285
- }
286
-
287
- // noSend
288
- if (typeof args.options.noSend === 'boolean') {
289
- paramWriter.writeInt8(args.options.noSend ? 1 : 0)
290
- } else {
291
- paramWriter.writeInt8(-1)
292
- }
293
-
294
- // noSendChange
295
- if (args.options.noSendChange != null) {
296
- paramWriter.writeVarIntNum(args.options.noSendChange.length)
297
- for (const outpoint of args.options.noSendChange) {
298
- paramWriter.write(this.encodeOutpoint(outpoint))
299
- }
300
- } else {
301
- paramWriter.writeVarIntNum(-1)
302
- }
303
-
304
- // sendWith
305
- if (args.options.sendWith != null) {
306
- paramWriter.writeVarIntNum(args.options.sendWith.length)
307
- for (const txid of args.options.sendWith) {
308
- const txidBytes = Utils.toArray(txid, 'hex')
309
- paramWriter.write(txidBytes)
310
- }
311
- } else {
312
- paramWriter.writeVarIntNum(-1)
313
- }
314
-
315
- // randomizeOutputs
316
- if (typeof args.options.randomizeOutputs === 'boolean') {
317
- paramWriter.writeInt8(args.options.randomizeOutputs ? 1 : 0)
318
- } else {
319
- paramWriter.writeInt8(-1)
320
- }
321
- } else {
322
- paramWriter.writeInt8(0) // options not present
323
- }
159
+ this.serializeCreateActionOptions(paramWriter, args.options)
324
160
 
325
161
  // Transmit and parse response
326
- const result = await this.transmit(
327
- 'createAction',
328
- originator,
329
- paramWriter.toArray()
330
- )
331
- const resultReader = new Utils.Reader(result)
162
+ const result = await this.transmit('createAction', originator, paramWriter.toArray())
163
+ return this.parseCreateActionResult(result)
164
+ }
332
165
 
333
- const response: {
334
- txid?: TXIDHexString
335
- tx?: BEEF
336
- noSendChange?: OutpointString[]
337
- sendWithResults?: Array<{
338
- txid: TXIDHexString
339
- status: 'unproven' | 'sending' | 'failed'
340
- }>
341
- signableTransaction?: {
342
- tx: BEEF
343
- reference: Base64String
344
- }
345
- } = {}
166
+ private parseCreateActionResult (result: number[]): CreateActionResult {
167
+ const resultReader = new Utils.Reader(result)
168
+ const response: CreateActionResult = {}
346
169
 
347
- // Parse txid
348
- const txidFlag = resultReader.readInt8()
349
- if (txidFlag === 1) {
350
- const txidBytes = resultReader.read(32)
351
- response.txid = Utils.toHex(txidBytes)
170
+ if (resultReader.readInt8() === 1) {
171
+ response.txid = Utils.toHex(resultReader.read(32))
352
172
  }
353
173
 
354
- // Parse tx
355
- const txFlag = resultReader.readInt8()
356
- if (txFlag === 1) {
357
- const txLength = resultReader.readVarIntNum()
358
- response.tx = resultReader.read(txLength)
174
+ if (resultReader.readInt8() === 1) {
175
+ response.tx = resultReader.read(resultReader.readVarIntNum())
359
176
  }
360
177
 
361
- // Parse noSendChange
362
178
  const noSendChangeLength = resultReader.readVarIntNum()
363
179
  if (noSendChangeLength >= 0) {
364
180
  response.noSendChange = []
365
181
  for (let i = 0; i < noSendChangeLength; i++) {
366
- const outpoint = this.readOutpoint(resultReader)
367
- response.noSendChange.push(outpoint)
182
+ response.noSendChange.push(this.readOutpoint(resultReader))
368
183
  }
369
184
  }
370
185
 
371
- // Parse sendWithResults
372
- const sendWithResultsLength = resultReader.readVarIntNum()
373
- if (sendWithResultsLength >= 0) {
374
- response.sendWithResults = []
375
- for (let i = 0; i < sendWithResultsLength; i++) {
376
- const txidBytes = resultReader.read(32)
377
- const txid = Utils.toHex(txidBytes)
378
- const statusCode = resultReader.readInt8()
379
- let status: 'unproven' | 'sending' | 'failed' = 'unproven'
380
- if (statusCode === 1) status = 'unproven'
381
- else if (statusCode === 2) status = 'sending'
382
- else if (statusCode === 3) status = 'failed'
383
- response.sendWithResults.push({ txid, status })
384
- }
385
- }
186
+ const sendWithResults = this.readSendWithResults(resultReader)
187
+ if (sendWithResults != null) response.sendWithResults = sendWithResults
386
188
 
387
- // Parse signableTransaction
388
- const signableTransactionFlag = resultReader.readInt8()
389
- if (signableTransactionFlag === 1) {
390
- const txLength = resultReader.readVarIntNum()
391
- const tx = resultReader.read(txLength)
392
- const referenceLength = resultReader.readVarIntNum()
393
- const referenceBytes = resultReader.read(referenceLength)
394
- response.signableTransaction = {
395
- tx,
396
- reference: Utils.toBase64(referenceBytes)
397
- }
189
+ if (resultReader.readInt8() === 1) {
190
+ const tx = resultReader.read(resultReader.readVarIntNum())
191
+ const referenceBytes = resultReader.read(resultReader.readVarIntNum())
192
+ response.signableTransaction = { tx, reference: Utils.toBase64(referenceBytes) }
398
193
  }
399
194
 
400
195
  return response
401
196
  }
402
197
 
403
- async signAction(
198
+ async signAction (
404
199
  args: SignActionArgs,
405
200
  originator?: OriginatorDomainNameStringUnder250Bytes
406
201
  ): Promise<SignActionResult> {
@@ -412,16 +207,10 @@ export default class WalletWireTransceiver implements WalletInterface {
412
207
  for (const index of spendIndexes) {
413
208
  paramWriter.writeVarIntNum(Number(index))
414
209
  const spend = args.spends[Number(index)]
415
- // unlockingScript
416
210
  const unlockingScriptBytes = Utils.toArray(spend.unlockingScript, 'hex')
417
211
  paramWriter.writeVarIntNum(unlockingScriptBytes.length)
418
212
  paramWriter.write(unlockingScriptBytes)
419
- // sequenceNumber
420
- if (typeof spend.sequenceNumber === 'number') {
421
- paramWriter.writeVarIntNum(spend.sequenceNumber)
422
- } else {
423
- paramWriter.writeVarIntNum(-1)
424
- }
213
+ this.writeOptionalVarInt(paramWriter, spend.sequenceNumber)
425
214
  }
426
215
 
427
216
  // Serialize reference
@@ -430,96 +219,26 @@ export default class WalletWireTransceiver implements WalletInterface {
430
219
  paramWriter.write(referenceBytes)
431
220
 
432
221
  // Serialize options
433
- if (args.options != null) {
434
- paramWriter.writeInt8(1) // options present
435
-
436
- // acceptDelayedBroadcast
437
- if (typeof args.options.acceptDelayedBroadcast === 'boolean') {
438
- paramWriter.writeInt8(args.options.acceptDelayedBroadcast ? 1 : 0)
439
- } else {
440
- paramWriter.writeInt8(-1)
441
- }
442
-
443
- // returnTXIDOnly
444
- if (typeof args.options.returnTXIDOnly === 'boolean') {
445
- paramWriter.writeInt8(args.options.returnTXIDOnly ? 1 : 0)
446
- } else {
447
- paramWriter.writeInt8(-1)
448
- }
449
-
450
- // noSend
451
- if (typeof args.options.noSend === 'boolean') {
452
- paramWriter.writeInt8(args.options.noSend ? 1 : 0)
453
- } else {
454
- paramWriter.writeInt8(-1)
455
- }
456
-
457
- // sendWith
458
- if (args.options.sendWith != null) {
459
- paramWriter.writeVarIntNum(args.options.sendWith.length)
460
- for (const txid of args.options.sendWith) {
461
- const txidBytes = Utils.toArray(txid, 'hex')
462
- paramWriter.write(txidBytes)
463
- }
464
- } else {
465
- paramWriter.writeVarIntNum(-1)
466
- }
467
- } else {
468
- paramWriter.writeInt8(0) // options not present
469
- }
222
+ this.serializeSignActionOptions(paramWriter, args.options)
470
223
 
471
224
  // Transmit and parse response
472
- const result = await this.transmit(
473
- 'signAction',
474
- originator,
475
- paramWriter.toArray()
476
- )
225
+ const result = await this.transmit('signAction', originator, paramWriter.toArray())
477
226
  const resultReader = new Utils.Reader(result)
478
227
 
479
- const response: {
480
- txid?: TXIDHexString
481
- tx?: BEEF
482
- noSendChange?: OutpointString[]
483
- sendWithResults?: Array<{
484
- txid: TXIDHexString
485
- status: 'unproven' | 'sending' | 'failed'
486
- }>
487
- } = {}
488
-
489
- // Parse txid
490
- const txidFlag = resultReader.readInt8()
491
- if (txidFlag === 1) {
492
- const txidBytes = resultReader.read(32)
493
- response.txid = Utils.toHex(txidBytes)
494
- }
495
-
496
- // Parse tx
497
- const txFlag = resultReader.readInt8()
498
- if (txFlag === 1) {
499
- const txLength = resultReader.readVarIntNum()
500
- response.tx = resultReader.read(txLength)
501
- }
502
-
503
- // Parse sendWithResults
504
- const sendWithResultsLength = resultReader.readVarIntNum()
505
- if (sendWithResultsLength >= 0) {
506
- response.sendWithResults = []
507
- for (let i = 0; i < sendWithResultsLength; i++) {
508
- const txidBytes = resultReader.read(32)
509
- const txid = Utils.toHex(txidBytes)
510
- const statusCode = resultReader.readInt8()
511
- let status: 'unproven' | 'sending' | 'failed' = 'unproven'
512
- if (statusCode === 1) status = 'unproven'
513
- else if (statusCode === 2) status = 'sending'
514
- else if (statusCode === 3) status = 'failed'
515
- response.sendWithResults.push({ txid, status })
516
- }
228
+ const response: SignActionResult = {}
229
+ if (resultReader.readInt8() === 1) {
230
+ response.txid = Utils.toHex(resultReader.read(32))
517
231
  }
232
+ if (resultReader.readInt8() === 1) {
233
+ response.tx = resultReader.read(resultReader.readVarIntNum())
234
+ }
235
+ const sendWithResults = this.readSendWithResults(resultReader)
236
+ if (sendWithResults != null) response.sendWithResults = sendWithResults
518
237
 
519
238
  return response
520
239
  }
521
240
 
522
- async abortAction(
241
+ async abortAction (
523
242
  args: { reference: Base64String },
524
243
  originator?: OriginatorDomainNameStringUnder250Bytes
525
244
  ): Promise<{ aborted: true }> {
@@ -531,300 +250,144 @@ export default class WalletWireTransceiver implements WalletInterface {
531
250
  return { aborted: true }
532
251
  }
533
252
 
534
- async listActions(
253
+ async listActions (
535
254
  args: ListActionsArgs,
536
255
  originator?: OriginatorDomainNameStringUnder250Bytes
537
256
  ): Promise<ListActionsResult> {
538
257
  const paramWriter = new Utils.Writer()
539
258
 
540
- // Serialize labels
259
+ // Serialize labels (always-present array, no -1 sentinel)
541
260
  paramWriter.writeVarIntNum(args.labels.length)
542
261
  for (const label of args.labels) {
543
- const labelBytes = Utils.toArray(label, 'utf8')
544
- paramWriter.writeVarIntNum(labelBytes.length)
545
- paramWriter.write(labelBytes)
262
+ this.writeUTF8(paramWriter, label)
546
263
  }
547
264
 
548
265
  // Serialize labelQueryMode
549
- if (args.labelQueryMode === 'any') {
550
- paramWriter.writeInt8(1)
551
- } else if (args.labelQueryMode === 'all') {
552
- paramWriter.writeInt8(2)
553
- } else {
554
- paramWriter.writeInt8(-1)
555
- }
266
+ if (args.labelQueryMode === 'any') paramWriter.writeInt8(1)
267
+ else if (args.labelQueryMode === 'all') paramWriter.writeInt8(2)
268
+ else paramWriter.writeInt8(-1)
556
269
 
557
270
  // Serialize include options
558
- const includeOptions = [
271
+ for (const option of [
559
272
  args.includeLabels,
560
273
  args.includeInputs,
561
274
  args.includeInputSourceLockingScripts,
562
275
  args.includeInputUnlockingScripts,
563
276
  args.includeOutputs,
564
277
  args.includeOutputLockingScripts
565
- ]
566
- for (const option of includeOptions) {
567
- if (typeof option === 'boolean') {
568
- paramWriter.writeInt8(option ? 1 : 0)
569
- } else {
570
- paramWriter.writeInt8(-1)
571
- }
572
- }
573
-
574
- // Serialize limit and offset
575
- if (typeof args.limit === 'number') {
576
- paramWriter.writeVarIntNum(args.limit)
577
- } else {
578
- paramWriter.writeVarIntNum(-1)
579
- }
580
- if (typeof args.offset === 'number') {
581
- paramWriter.writeVarIntNum(args.offset)
582
- } else {
583
- paramWriter.writeVarIntNum(-1)
278
+ ]) {
279
+ this.writeOptionalBool(paramWriter, option)
584
280
  }
585
281
 
586
- // Serialize seekPermission
587
- paramWriter.writeInt8(
588
- typeof args.seekPermission === 'boolean'
589
- ? args.seekPermission
590
- ? 1
591
- : 0
592
- : -1
593
- )
282
+ this.writeOptionalVarInt(paramWriter, args.limit)
283
+ this.writeOptionalVarInt(paramWriter, args.offset)
284
+ this.writeOptionalBool(paramWriter, args.seekPermission)
594
285
 
595
- // Transmit and parse response
596
- const result = await this.transmit(
597
- 'listActions',
598
- originator,
599
- paramWriter.toArray()
600
- )
286
+ const result = await this.transmit('listActions', originator, paramWriter.toArray())
601
287
  const resultReader = new Utils.Reader(result)
602
-
603
288
  const totalActions = resultReader.readVarIntNum()
604
- const actions: Array<{
605
- txid: TXIDHexString
606
- satoshis: SatoshiValue
607
- status: ActionStatus
608
- isOutgoing: boolean
609
- description: DescriptionString5to50Bytes
610
- labels?: LabelStringUnder300Bytes[]
611
- version: PositiveIntegerOrZero
612
- lockTime: PositiveIntegerOrZero
613
- inputs?: Array<{
614
- sourceOutpoint: OutpointString
615
- sourceSatoshis: SatoshiValue
616
- sourceLockingScript?: HexString
617
- unlockingScript?: HexString
618
- inputDescription: DescriptionString5to50Bytes
619
- sequenceNumber: PositiveIntegerOrZero
620
- }>
621
- outputs?: Array<{
622
- outputIndex: PositiveIntegerOrZero
623
- satoshis: SatoshiValue
624
- lockingScript?: HexString
625
- spendable: boolean
626
- outputDescription: DescriptionString5to50Bytes
627
- basket: BasketStringUnder300Bytes
628
- tags: OutputTagStringUnder300Bytes[]
629
- customInstructions?: string
630
- }>
631
- }> = []
632
-
289
+ const actions: ListActionsResult['actions'] = []
633
290
  for (let i = 0; i < totalActions; i++) {
634
- // Parse action fields
635
- const txidBytes = resultReader.read(32)
636
- const txid = Utils.toHex(txidBytes)
637
-
638
- const satoshis = resultReader.readVarIntNum()
639
-
640
- const statusCode = resultReader.readInt8()
641
- let status: ActionStatus
642
- switch (statusCode) {
643
- case 1:
644
- status = 'completed'
645
- break
646
- case 2:
647
- status = 'unprocessed'
648
- break
649
- case 3:
650
- status = 'sending'
651
- break
652
- case 4:
653
- status = 'unproven'
654
- break
655
- case 5:
656
- status = 'unsigned'
657
- break
658
- case 6:
659
- status = 'nosend'
660
- break
661
- case 7:
662
- status = 'nonfinal'
663
- break
664
- case 8:
665
- status = 'failed'
666
- break
667
- default:
668
- throw new Error(`Unknown status code: ${statusCode}`)
669
- }
291
+ actions.push(this.parseAction(resultReader))
292
+ }
293
+ return { totalActions, actions }
294
+ }
670
295
 
671
- const isOutgoing = resultReader.readInt8() === 1
296
+ private parseActionStatus (code: number): ActionStatus {
297
+ const status = ACTION_STATUS_MAP[code]
298
+ if (status == null) throw new Error(`Unknown status code: ${code}`)
299
+ return status
300
+ }
672
301
 
673
- const descriptionLength = resultReader.readVarIntNum()
674
- const descriptionBytes = resultReader.read(descriptionLength)
675
- const description = Utils.toUTF8(descriptionBytes)
676
-
677
- const action: any = {
678
- txid,
679
- satoshis,
680
- status,
681
- isOutgoing,
682
- description,
683
- version: 0,
684
- lockTime: 0
302
+ private parseAction (reader: Utils.Reader): ListActionsResult['actions'][number] {
303
+ const txid = Utils.toHex(reader.read(32))
304
+ const satoshis = reader.readVarIntNum()
305
+ const status = this.parseActionStatus(reader.readInt8())
306
+ const isOutgoing = reader.readInt8() === 1
307
+ const description = Utils.toUTF8(reader.read(reader.readVarIntNum()))
308
+
309
+ const action: any = { txid, satoshis, status, isOutgoing, description, version: 0, lockTime: 0 }
310
+
311
+ const labelsLen = reader.readVarIntNum()
312
+ if (labelsLen >= 0) {
313
+ action.labels = []
314
+ for (let j = 0; j < labelsLen; j++) {
315
+ action.labels.push(Utils.toUTF8(reader.read(reader.readVarIntNum())))
685
316
  }
317
+ }
686
318
 
687
- // Parse labels
688
- const labelsLength = resultReader.readVarIntNum()
689
- if (labelsLength >= 0) {
690
- action.labels = []
691
- for (let j = 0; j < labelsLength; j++) {
692
- const labelLength = resultReader.readVarIntNum()
693
- const labelBytes = resultReader.read(labelLength)
694
- action.labels.push(Utils.toUTF8(labelBytes))
695
- }
696
- }
319
+ action.version = reader.readVarIntNum()
320
+ action.lockTime = reader.readVarIntNum()
697
321
 
698
- // Parse version and lockTime
699
- action.version = resultReader.readVarIntNum()
700
- action.lockTime = resultReader.readVarIntNum()
701
-
702
- // Parse inputs
703
- const inputsLength = resultReader.readVarIntNum()
704
- if (inputsLength >= 0) {
705
- action.inputs = []
706
- for (let k = 0; k < inputsLength; k++) {
707
- const sourceOutpoint = this.readOutpoint(resultReader)
708
- const sourceSatoshis = resultReader.readVarIntNum()
709
-
710
- // sourceLockingScript
711
- const sourceLockingScriptLength = resultReader.readVarIntNum()
712
- let sourceLockingScript: string | undefined
713
- if (sourceLockingScriptLength >= 0) {
714
- const sourceLockingScriptBytes = resultReader.read(
715
- sourceLockingScriptLength
716
- )
717
- sourceLockingScript = Utils.toHex(sourceLockingScriptBytes)
718
- }
719
-
720
- // unlockingScript
721
- const unlockingScriptLength = resultReader.readVarIntNum()
722
- let unlockingScript: string | undefined
723
- if (unlockingScriptLength >= 0) {
724
- const unlockingScriptBytes = resultReader.read(
725
- unlockingScriptLength
726
- )
727
- unlockingScript = Utils.toHex(unlockingScriptBytes)
728
- }
729
-
730
- // inputDescription
731
- const inputDescriptionLength = resultReader.readVarIntNum()
732
- const inputDescriptionBytes = resultReader.read(
733
- inputDescriptionLength
734
- )
735
- const inputDescription = Utils.toUTF8(inputDescriptionBytes)
736
-
737
- // sequenceNumber
738
- const sequenceNumber = resultReader.readVarIntNum()
739
-
740
- action.inputs.push({
741
- sourceOutpoint,
742
- sourceSatoshis,
743
- sourceLockingScript,
744
- unlockingScript,
745
- inputDescription,
746
- sequenceNumber
747
- })
748
- }
322
+ const inputsLen = reader.readVarIntNum()
323
+ if (inputsLen >= 0) {
324
+ action.inputs = []
325
+ for (let k = 0; k < inputsLen; k++) {
326
+ action.inputs.push(this.parseActionInput(reader))
749
327
  }
328
+ }
750
329
 
751
- // Parse outputs
752
- const outputsLength = resultReader.readVarIntNum()
753
- if (outputsLength >= 0) {
754
- action.outputs = []
755
- for (let l = 0; l < outputsLength; l++) {
756
- const outputIndex = resultReader.readVarIntNum()
757
- const satoshis = resultReader.readVarIntNum()
758
-
759
- // lockingScript
760
- const lockingScriptLength = resultReader.readVarIntNum()
761
- let lockingScript: string | undefined
762
- if (lockingScriptLength >= 0) {
763
- const lockingScriptBytes = resultReader.read(lockingScriptLength)
764
- lockingScript = Utils.toHex(lockingScriptBytes)
765
- }
766
-
767
- const spendable = resultReader.readInt8() === 1
768
-
769
- // outputDescription
770
- const outputDescriptionLength = resultReader.readVarIntNum()
771
- const outputDescriptionBytes = resultReader.read(
772
- outputDescriptionLength
773
- )
774
- const outputDescription = Utils.toUTF8(outputDescriptionBytes)
775
-
776
- // basket
777
- const basketLength = resultReader.readVarIntNum()
778
- let basket: string | undefined
779
- if (basketLength >= 0) {
780
- const basketBytes = resultReader.read(basketLength)
781
- basket = Utils.toUTF8(basketBytes)
782
- }
783
-
784
- // tags
785
- const tagsLength = resultReader.readVarIntNum()
786
- const tags: string[] = []
787
- if (tagsLength >= 0) {
788
- for (let m = 0; m < tagsLength; m++) {
789
- const tagLength = resultReader.readVarIntNum()
790
- const tagBytes = resultReader.read(tagLength)
791
- tags.push(Utils.toUTF8(tagBytes))
792
- }
793
- }
794
-
795
- // customInstructions
796
- const customInstructionsLength = resultReader.readVarIntNum()
797
- let customInstructions: string | undefined
798
- if (customInstructionsLength >= 0) {
799
- const customInstructionsBytes = resultReader.read(
800
- customInstructionsLength
801
- )
802
- customInstructions = Utils.toUTF8(customInstructionsBytes)
803
- }
804
-
805
- action.outputs.push({
806
- outputIndex,
807
- satoshis,
808
- lockingScript,
809
- spendable,
810
- outputDescription,
811
- basket,
812
- tags,
813
- customInstructions
814
- })
815
- }
330
+ const outputsLen = reader.readVarIntNum()
331
+ if (outputsLen >= 0) {
332
+ action.outputs = []
333
+ for (let l = 0; l < outputsLen; l++) {
334
+ action.outputs.push(this.parseActionOutput(reader))
816
335
  }
817
-
818
- actions.push(action)
819
336
  }
820
337
 
821
- return {
822
- totalActions,
823
- actions
338
+ return action
339
+ }
340
+
341
+ private parseActionInput (reader: Utils.Reader): {
342
+ sourceOutpoint: OutpointString
343
+ sourceSatoshis: SatoshiValue
344
+ sourceLockingScript?: HexString
345
+ unlockingScript?: HexString
346
+ inputDescription: DescriptionString5to50Bytes
347
+ sequenceNumber: PositiveIntegerOrZero
348
+ } {
349
+ const sourceOutpoint = this.readOutpoint(reader)
350
+ const sourceSatoshis = reader.readVarIntNum()
351
+ const srcLockLen = reader.readVarIntNum()
352
+ const sourceLockingScript = srcLockLen >= 0 ? Utils.toHex(reader.read(srcLockLen)) : undefined
353
+ const unlockLen = reader.readVarIntNum()
354
+ const unlockingScript = unlockLen >= 0 ? Utils.toHex(reader.read(unlockLen)) : undefined
355
+ const inputDescription = Utils.toUTF8(reader.read(reader.readVarIntNum()))
356
+ const sequenceNumber = reader.readVarIntNum()
357
+ return { sourceOutpoint, sourceSatoshis, sourceLockingScript, unlockingScript, inputDescription, sequenceNumber }
358
+ }
359
+
360
+ private parseActionOutput (reader: Utils.Reader): {
361
+ outputIndex: PositiveIntegerOrZero
362
+ satoshis: SatoshiValue
363
+ lockingScript?: HexString
364
+ spendable: boolean
365
+ outputDescription: DescriptionString5to50Bytes
366
+ basket: BasketStringUnder300Bytes
367
+ tags: OutputTagStringUnder300Bytes[]
368
+ customInstructions?: string
369
+ } {
370
+ const outputIndex = reader.readVarIntNum()
371
+ const satoshis = reader.readVarIntNum()
372
+ const lockLen = reader.readVarIntNum()
373
+ const lockingScript = lockLen >= 0 ? Utils.toHex(reader.read(lockLen)) : undefined
374
+ const spendable = reader.readInt8() === 1
375
+ const outputDescription = Utils.toUTF8(reader.read(reader.readVarIntNum()))
376
+ const basketLen = reader.readVarIntNum()
377
+ const basket = basketLen >= 0 ? Utils.toUTF8(reader.read(basketLen)) : undefined
378
+ const tagsLen = reader.readVarIntNum()
379
+ const tags: string[] = []
380
+ if (tagsLen >= 0) {
381
+ for (let m = 0; m < tagsLen; m++) {
382
+ tags.push(Utils.toUTF8(reader.read(reader.readVarIntNum())))
383
+ }
824
384
  }
385
+ const custLen = reader.readVarIntNum()
386
+ const customInstructions = custLen >= 0 ? Utils.toUTF8(reader.read(custLen)) : undefined
387
+ return { outputIndex, satoshis, lockingScript, spendable, outputDescription, basket: basket as BasketStringUnder300Bytes, tags, customInstructions }
825
388
  }
826
389
 
827
- async internalizeAction(
390
+ async internalizeAction (
828
391
  args: InternalizeActionArgs,
829
392
  originator?: OriginatorDomainNameStringUnder250Bytes
830
393
  ): Promise<{ accepted: true }> {
@@ -833,228 +396,121 @@ export default class WalletWireTransceiver implements WalletInterface {
833
396
  paramWriter.write(args.tx)
834
397
  paramWriter.writeVarIntNum(args.outputs.length)
835
398
  for (const out of args.outputs) {
836
- paramWriter.writeVarIntNum(out.outputIndex)
837
- if (out.protocol === 'wallet payment') {
838
- if (out.paymentRemittance == null) {
839
- throw new Error('Payment remittance is required for wallet payment')
840
- }
841
- paramWriter.writeUInt8(1)
842
- paramWriter.write(
843
- Utils.toArray(out.paymentRemittance.senderIdentityKey, 'hex')
844
- )
845
- const derivationPrefixAsArray = Utils.toArray(
846
- out.paymentRemittance.derivationPrefix,
847
- 'base64'
848
- )
849
- paramWriter.writeVarIntNum(derivationPrefixAsArray.length)
850
- paramWriter.write(derivationPrefixAsArray)
851
- const derivationSuffixAsArray = Utils.toArray(
852
- out.paymentRemittance.derivationSuffix,
853
- 'base64'
854
- )
855
- paramWriter.writeVarIntNum(derivationSuffixAsArray.length)
856
- paramWriter.write(derivationSuffixAsArray)
857
- } else {
858
- paramWriter.writeUInt8(2)
859
- const basketAsArray = Utils.toArray(
860
- out.insertionRemittance?.basket,
861
- 'utf8'
862
- )
863
- paramWriter.writeVarIntNum(basketAsArray.length)
864
- paramWriter.write(basketAsArray)
865
- if (typeof out.insertionRemittance?.customInstructions === 'string' && out.insertionRemittance.customInstructions !== '') {
866
- const customInstructionsAsArray = Utils.toArray(
867
- out.insertionRemittance.customInstructions,
868
- 'utf8'
869
- )
870
- paramWriter.writeVarIntNum(customInstructionsAsArray.length)
871
- paramWriter.write(customInstructionsAsArray)
872
- } else {
873
- paramWriter.writeVarIntNum(-1)
874
- }
875
- if (typeof out.insertionRemittance?.tags === 'object') {
876
- paramWriter.writeVarIntNum(out.insertionRemittance.tags.length)
877
- for (const tag of out.insertionRemittance.tags) {
878
- const tagAsArray = Utils.toArray(tag, 'utf8')
879
- paramWriter.writeVarIntNum(tagAsArray.length)
880
- paramWriter.write(tagAsArray)
881
- }
882
- } else {
883
- paramWriter.writeVarIntNum(0)
884
- }
885
- }
886
- }
887
- if (typeof args.labels === 'object') {
888
- paramWriter.writeVarIntNum(args.labels.length)
889
- for (const l of args.labels) {
890
- const labelAsArray = Utils.toArray(l, 'utf8')
891
- paramWriter.writeVarIntNum(labelAsArray.length)
892
- paramWriter.write(labelAsArray)
893
- }
894
- } else {
895
- paramWriter.writeVarIntNum(-1)
399
+ this.serializeInternalizeOutput(paramWriter, out)
896
400
  }
401
+ this.writeUTF8Array(paramWriter, typeof args.labels === 'object' ? args.labels : undefined)
897
402
  const descriptionAsArray = Utils.toArray(args.description)
898
403
  paramWriter.writeVarIntNum(descriptionAsArray.length)
899
404
  paramWriter.write(descriptionAsArray)
900
-
901
- // Serialize seekPermission
902
- paramWriter.writeInt8(
903
- typeof args.seekPermission === 'boolean'
904
- ? args.seekPermission
905
- ? 1
906
- : 0
907
- : -1
908
- )
909
-
405
+ this.writeOptionalBool(paramWriter, args.seekPermission)
910
406
  await this.transmit('internalizeAction', originator, paramWriter.toArray())
911
407
  return { accepted: true }
912
408
  }
913
409
 
914
- async listOutputs(
410
+ private serializeInternalizeOutput (
411
+ writer: Utils.Writer,
412
+ out: InternalizeActionArgs['outputs'][number]
413
+ ): void {
414
+ writer.writeVarIntNum(out.outputIndex)
415
+ if (out.protocol === 'wallet payment') {
416
+ if (out.paymentRemittance == null) {
417
+ throw new Error('Payment remittance is required for wallet payment')
418
+ }
419
+ writer.writeUInt8(1)
420
+ writer.write(Utils.toArray(out.paymentRemittance.senderIdentityKey, 'hex'))
421
+ const prefix = Utils.toArray(out.paymentRemittance.derivationPrefix, 'base64')
422
+ writer.writeVarIntNum(prefix.length)
423
+ writer.write(prefix)
424
+ const suffix = Utils.toArray(out.paymentRemittance.derivationSuffix, 'base64')
425
+ writer.writeVarIntNum(suffix.length)
426
+ writer.write(suffix)
427
+ } else {
428
+ writer.writeUInt8(2)
429
+ const basket = Utils.toArray(out.insertionRemittance?.basket, 'utf8')
430
+ writer.writeVarIntNum(basket.length)
431
+ writer.write(basket)
432
+ this.writeOptionalUTF8(writer, out.insertionRemittance?.customInstructions)
433
+ const tags = out.insertionRemittance?.tags
434
+ if (typeof tags === 'object') {
435
+ writer.writeVarIntNum(tags.length)
436
+ for (const tag of tags) {
437
+ const t = Utils.toArray(tag, 'utf8')
438
+ writer.writeVarIntNum(t.length)
439
+ writer.write(t)
440
+ }
441
+ } else {
442
+ writer.writeVarIntNum(0)
443
+ }
444
+ }
445
+ }
446
+
447
+ async listOutputs (
915
448
  args: ListOutputsArgs,
916
449
  originator?: OriginatorDomainNameStringUnder250Bytes
917
450
  ): Promise<ListOutputsResult> {
918
451
  const paramWriter = new Utils.Writer()
919
- const basketAsArray = Utils.toArray(args.basket, 'utf8')
920
- paramWriter.writeVarIntNum(basketAsArray.length)
921
- paramWriter.write(basketAsArray)
452
+ this.writeUTF8(paramWriter, args.basket)
922
453
  if (typeof args.tags === 'object') {
923
454
  paramWriter.writeVarIntNum(args.tags.length)
924
455
  for (const tag of args.tags) {
925
- const tagAsArray = Utils.toArray(tag, 'utf8')
926
- paramWriter.writeVarIntNum(tagAsArray.length)
927
- paramWriter.write(tagAsArray)
456
+ this.writeUTF8(paramWriter, tag)
928
457
  }
929
458
  } else {
930
459
  paramWriter.writeVarIntNum(0)
931
460
  }
932
- if (args.tagQueryMode === 'all') {
933
- paramWriter.writeInt8(1)
934
- } else if (args.tagQueryMode === 'any') {
935
- paramWriter.writeInt8(2)
936
- } else {
937
- paramWriter.writeInt8(-1)
938
- }
939
- if (args.include === 'locking scripts') {
940
- paramWriter.writeInt8(1)
941
- } else if (args.include === 'entire transactions') {
942
- paramWriter.writeInt8(2)
943
- } else {
944
- paramWriter.writeInt8(-1)
945
- }
946
- if (typeof args.includeCustomInstructions === 'boolean') {
947
- paramWriter.writeInt8(args.includeCustomInstructions ? 1 : 0)
948
- } else {
949
- paramWriter.writeInt8(-1)
950
- }
951
- if (typeof args.includeTags === 'boolean') {
952
- paramWriter.writeInt8(args.includeTags ? 1 : 0)
953
- } else {
954
- paramWriter.writeInt8(-1)
955
- }
956
- if (typeof args.includeLabels === 'boolean') {
957
- paramWriter.writeInt8(args.includeLabels ? 1 : 0)
958
- } else {
959
- paramWriter.writeInt8(-1)
960
- }
961
- if (typeof args.limit === 'number') {
962
- paramWriter.writeVarIntNum(args.limit)
963
- } else {
964
- paramWriter.writeVarIntNum(-1)
965
- }
966
- if (typeof args.offset === 'number') {
967
- paramWriter.writeVarIntNum(args.offset)
968
- } else {
969
- paramWriter.writeVarIntNum(-1)
970
- }
971
-
972
- // Serialize seekPermission
973
- paramWriter.writeInt8(
974
- typeof args.seekPermission === 'boolean'
975
- ? args.seekPermission
976
- ? 1
977
- : 0
978
- : -1
979
- )
980
-
981
- const result = await this.transmit(
982
- 'listOutputs',
983
- originator,
984
- paramWriter.toArray()
985
- )
461
+ if (args.tagQueryMode === 'all') paramWriter.writeInt8(1)
462
+ else if (args.tagQueryMode === 'any') paramWriter.writeInt8(2)
463
+ else paramWriter.writeInt8(-1)
464
+ if (args.include === 'locking scripts') paramWriter.writeInt8(1)
465
+ else if (args.include === 'entire transactions') paramWriter.writeInt8(2)
466
+ else paramWriter.writeInt8(-1)
467
+ this.writeOptionalBool(paramWriter, args.includeCustomInstructions)
468
+ this.writeOptionalBool(paramWriter, args.includeTags)
469
+ this.writeOptionalBool(paramWriter, args.includeLabels)
470
+ this.writeOptionalVarInt(paramWriter, args.limit)
471
+ this.writeOptionalVarInt(paramWriter, args.offset)
472
+ this.writeOptionalBool(paramWriter, args.seekPermission)
473
+
474
+ const result = await this.transmit('listOutputs', originator, paramWriter.toArray())
986
475
  const resultReader = new Utils.Reader(result)
987
476
  const totalOutputs = resultReader.readVarIntNum()
988
477
  const beefLength = resultReader.readVarIntNum()
989
- let BEEF
990
- if (beefLength >= 0) {
991
- BEEF = resultReader.read(beefLength)
992
- }
993
- const outputs: Array<{
994
- outpoint: OutpointString
995
- satoshis: SatoshiValue
996
- lockingScript?: HexString
997
- tx?: BEEF
998
- spendable: true
999
- customInstructions?: string
1000
- tags?: OutputTagStringUnder300Bytes[]
1001
- labels?: LabelStringUnder300Bytes[]
1002
- }> = []
478
+ const BEEF = beefLength >= 0 ? resultReader.read(beefLength) : undefined
479
+ const outputs: ListOutputsResult['outputs'] = []
1003
480
  for (let i = 0; i < totalOutputs; i++) {
1004
- const outpoint = this.readOutpoint(resultReader)
1005
- const satoshis = resultReader.readVarIntNum()
1006
- const output: {
1007
- outpoint: OutpointString
1008
- satoshis: SatoshiValue
1009
- lockingScript?: HexString
1010
- tx?: BEEF
1011
- spendable: true
1012
- customInstructions?: string
1013
- tags?: OutputTagStringUnder300Bytes[]
1014
- labels?: LabelStringUnder300Bytes[]
1015
- } = {
1016
- spendable: true,
1017
- outpoint,
1018
- satoshis
1019
- }
1020
- const scriptLength = resultReader.readVarIntNum()
1021
- if (scriptLength >= 0) {
1022
- output.lockingScript = Utils.toHex(resultReader.read(scriptLength))
1023
- }
1024
- const customInstructionsLength = resultReader.readVarIntNum()
1025
- if (customInstructionsLength >= 0) {
1026
- output.customInstructions = Utils.toUTF8(
1027
- resultReader.read(customInstructionsLength)
1028
- )
1029
- }
1030
- const tagsLength = resultReader.readVarIntNum()
1031
- if (tagsLength !== -1) {
1032
- const tags: OutputTagStringUnder300Bytes[] = []
1033
- for (let i = 0; i < tagsLength; i++) {
1034
- const tagLength = resultReader.readVarIntNum()
1035
- tags.push(Utils.toUTF8(resultReader.read(tagLength)))
1036
- }
1037
- output.tags = tags
1038
- }
1039
- const labelsLength = resultReader.readVarIntNum()
1040
- if (labelsLength !== -1) {
1041
- const labels: LabelStringUnder300Bytes[] = []
1042
- for (let i = 0; i < labelsLength; i++) {
1043
- const labelLength = resultReader.readVarIntNum()
1044
- labels.push(Utils.toUTF8(resultReader.read(labelLength)))
1045
- }
1046
- output.labels = labels
481
+ outputs.push(this.parseListOutputEntry(resultReader))
482
+ }
483
+ return { totalOutputs, BEEF, outputs }
484
+ }
485
+
486
+ private parseListOutputEntry (reader: Utils.Reader): ListOutputsResult['outputs'][number] {
487
+ const outpoint = this.readOutpoint(reader)
488
+ const satoshis = reader.readVarIntNum()
489
+ const output: ListOutputsResult['outputs'][number] = { spendable: true, outpoint, satoshis }
490
+ const scriptLen = reader.readVarIntNum()
491
+ if (scriptLen >= 0) output.lockingScript = Utils.toHex(reader.read(scriptLen))
492
+ const custLen = reader.readVarIntNum()
493
+ if (custLen >= 0) output.customInstructions = Utils.toUTF8(reader.read(custLen))
494
+ const tagsLen = reader.readVarIntNum()
495
+ if (tagsLen !== -1) {
496
+ const tags: OutputTagStringUnder300Bytes[] = []
497
+ for (let i = 0; i < tagsLen; i++) {
498
+ tags.push(Utils.toUTF8(reader.read(reader.readVarIntNum())))
1047
499
  }
1048
- outputs.push(output)
500
+ output.tags = tags
1049
501
  }
1050
- return {
1051
- totalOutputs,
1052
- BEEF,
1053
- outputs
502
+ const labelsLen = reader.readVarIntNum()
503
+ if (labelsLen !== -1) {
504
+ const labels: LabelStringUnder300Bytes[] = []
505
+ for (let i = 0; i < labelsLen; i++) {
506
+ labels.push(Utils.toUTF8(reader.read(reader.readVarIntNum())))
507
+ }
508
+ output.labels = labels
1054
509
  }
510
+ return output
1055
511
  }
1056
512
 
1057
- async relinquishOutput(
513
+ async relinquishOutput (
1058
514
  args: { basket: BasketStringUnder300Bytes, output: OutpointString },
1059
515
  originator?: OriginatorDomainNameStringUnder250Bytes
1060
516
  ): Promise<{ relinquished: true }> {
@@ -1067,7 +523,7 @@ export default class WalletWireTransceiver implements WalletInterface {
1067
523
  return { relinquished: true }
1068
524
  }
1069
525
 
1070
- private encodeOutpoint(outpoint: OutpointString): number[] {
526
+ private encodeOutpoint (outpoint: OutpointString): number[] {
1071
527
  const writer = new Utils.Writer()
1072
528
  const [txid, index] = outpoint.split('.')
1073
529
  writer.write(Utils.toArray(txid, 'hex'))
@@ -1075,13 +531,13 @@ export default class WalletWireTransceiver implements WalletInterface {
1075
531
  return writer.toArray()
1076
532
  }
1077
533
 
1078
- private readOutpoint(reader: Utils.Reader): OutpointString {
534
+ private readOutpoint (reader: Utils.Reader): OutpointString {
1079
535
  const txid = Utils.toHex(reader.read(32))
1080
536
  const index = reader.readVarIntNum()
1081
537
  return `${txid}.${index}`
1082
538
  }
1083
539
 
1084
- async getPublicKey(
540
+ async getPublicKey (
1085
541
  args: {
1086
542
  seekPermission?: BooleanDefaultTrue
1087
543
  identityKey?: true
@@ -1089,18 +545,24 @@ export default class WalletWireTransceiver implements WalletInterface {
1089
545
  keyID?: KeyIDStringUnder800Bytes
1090
546
  privileged?: BooleanDefaultFalse
1091
547
  privilegedReason?: DescriptionString5to50Bytes
1092
- counterparty?: PubKeyHex | 'self' | 'anyone'
548
+ counterparty?: PubKeyHex
1093
549
  forSelf?: BooleanDefaultFalse
1094
550
  },
1095
551
  originator?: OriginatorDomainNameStringUnder250Bytes
1096
552
  ): Promise<{ publicKey: PubKeyHex }> {
1097
553
  const paramWriter = new Utils.Writer()
1098
554
  paramWriter.writeUInt8(args.identityKey ? 1 : 0)
1099
- if (!args.identityKey) {
555
+ if (args.identityKey) {
556
+ paramWriter.write(
557
+ this.encodePrivilegedParams(args.privileged, args.privilegedReason)
558
+ )
559
+ } else {
560
+ args.protocolID ??= [SecurityLevels.Silent, 'default']
561
+ args.keyID ??= ''
1100
562
  paramWriter.write(
1101
563
  this.encodeKeyRelatedParams(
1102
- args.protocolID ??= [SecurityLevels.Silent, 'default'],
1103
- args.keyID ??= '',
564
+ args.protocolID,
565
+ args.keyID,
1104
566
  args.counterparty,
1105
567
  args.privileged,
1106
568
  args.privilegedReason
@@ -1111,20 +573,10 @@ export default class WalletWireTransceiver implements WalletInterface {
1111
573
  } else {
1112
574
  paramWriter.writeInt8(-1)
1113
575
  }
1114
- } else {
1115
- paramWriter.write(
1116
- this.encodePrivilegedParams(args.privileged, args.privilegedReason)
1117
- )
1118
576
  }
1119
577
 
1120
578
  // Serialize seekPermission
1121
- paramWriter.writeInt8(
1122
- typeof args.seekPermission === 'boolean'
1123
- ? args.seekPermission
1124
- ? 1
1125
- : 0
1126
- : -1
1127
- )
579
+ this.writeOptionalBool(paramWriter, args.seekPermission)
1128
580
 
1129
581
  const result = await this.transmit(
1130
582
  'getPublicKey',
@@ -1136,7 +588,7 @@ export default class WalletWireTransceiver implements WalletInterface {
1136
588
  }
1137
589
  }
1138
590
 
1139
- async revealCounterpartyKeyLinkage(
591
+ async revealCounterpartyKeyLinkage (
1140
592
  args: {
1141
593
  counterparty: PubKeyHex
1142
594
  verifier: PubKeyHex
@@ -1145,13 +597,13 @@ export default class WalletWireTransceiver implements WalletInterface {
1145
597
  },
1146
598
  originator?: OriginatorDomainNameStringUnder250Bytes
1147
599
  ): Promise<{
1148
- prover: PubKeyHex
1149
- verifier: PubKeyHex
1150
- counterparty: PubKeyHex
1151
- revelationTime: ISOTimestampString
1152
- encryptedLinkage: Byte[]
1153
- encryptedLinkageProof: number[]
1154
- }> {
600
+ prover: PubKeyHex
601
+ verifier: PubKeyHex
602
+ counterparty: PubKeyHex
603
+ revelationTime: ISOTimestampString
604
+ encryptedLinkage: Byte[]
605
+ encryptedLinkageProof: number[]
606
+ }> {
1155
607
  const paramWriter = new Utils.Writer()
1156
608
  paramWriter.write(
1157
609
  this.encodePrivilegedParams(args.privileged, args.privilegedReason)
@@ -1187,7 +639,7 @@ export default class WalletWireTransceiver implements WalletInterface {
1187
639
  }
1188
640
  }
1189
641
 
1190
- async revealSpecificKeyLinkage(
642
+ async revealSpecificKeyLinkage (
1191
643
  args: {
1192
644
  counterparty: PubKeyHex
1193
645
  verifier: PubKeyHex
@@ -1198,15 +650,15 @@ export default class WalletWireTransceiver implements WalletInterface {
1198
650
  },
1199
651
  originator?: OriginatorDomainNameStringUnder250Bytes
1200
652
  ): Promise<{
1201
- prover: PubKeyHex
1202
- verifier: PubKeyHex
1203
- counterparty: PubKeyHex
1204
- protocolID: [SecurityLevel, ProtocolString5To400Bytes]
1205
- keyID: KeyIDStringUnder800Bytes
1206
- encryptedLinkage: Byte[]
1207
- encryptedLinkageProof: Byte[]
1208
- proofType: Byte
1209
- }> {
653
+ prover: PubKeyHex
654
+ verifier: PubKeyHex
655
+ counterparty: PubKeyHex
656
+ protocolID: [SecurityLevel, ProtocolString5To400Bytes]
657
+ keyID: KeyIDStringUnder800Bytes
658
+ encryptedLinkage: Byte[]
659
+ encryptedLinkageProof: Byte[]
660
+ proofType: Byte
661
+ }> {
1210
662
  const paramWriter = new Utils.Writer()
1211
663
  paramWriter.write(
1212
664
  this.encodeKeyRelatedParams(
@@ -1251,14 +703,14 @@ export default class WalletWireTransceiver implements WalletInterface {
1251
703
  }
1252
704
  }
1253
705
 
1254
- async encrypt(
706
+ async encrypt (
1255
707
  args: {
1256
708
  seekPermission?: BooleanDefaultTrue
1257
709
  plaintext: Byte[]
1258
710
  protocolID: [SecurityLevel, ProtocolString5To400Bytes]
1259
711
  keyID: KeyIDStringUnder800Bytes
1260
712
  privilegedReason?: DescriptionString5to50Bytes
1261
- counterparty?: PubKeyHex | 'self' | 'anyone'
713
+ counterparty?: PubKeyHex
1262
714
  privileged?: BooleanDefaultFalse
1263
715
  },
1264
716
  originator?: OriginatorDomainNameStringUnder250Bytes
@@ -1276,13 +728,7 @@ export default class WalletWireTransceiver implements WalletInterface {
1276
728
  paramWriter.writeVarIntNum(args.plaintext.length)
1277
729
  paramWriter.write(args.plaintext)
1278
730
  // Serialize seekPermission
1279
- paramWriter.writeInt8(
1280
- typeof args.seekPermission === 'boolean'
1281
- ? args.seekPermission
1282
- ? 1
1283
- : 0
1284
- : -1
1285
- )
731
+ this.writeOptionalBool(paramWriter, args.seekPermission)
1286
732
  return {
1287
733
  ciphertext: await this.transmit(
1288
734
  'encrypt',
@@ -1292,14 +738,14 @@ export default class WalletWireTransceiver implements WalletInterface {
1292
738
  }
1293
739
  }
1294
740
 
1295
- async decrypt(
741
+ async decrypt (
1296
742
  args: {
1297
743
  seekPermission?: BooleanDefaultTrue
1298
744
  ciphertext: Byte[]
1299
745
  protocolID: [SecurityLevel, ProtocolString5To400Bytes]
1300
746
  keyID: KeyIDStringUnder800Bytes
1301
747
  privilegedReason?: DescriptionString5to50Bytes
1302
- counterparty?: PubKeyHex | 'self' | 'anyone'
748
+ counterparty?: PubKeyHex
1303
749
  privileged?: BooleanDefaultFalse
1304
750
  },
1305
751
  originator?: OriginatorDomainNameStringUnder250Bytes
@@ -1317,13 +763,7 @@ export default class WalletWireTransceiver implements WalletInterface {
1317
763
  paramWriter.writeVarIntNum(args.ciphertext.length)
1318
764
  paramWriter.write(args.ciphertext)
1319
765
  // Serialize seekPermission
1320
- paramWriter.writeInt8(
1321
- typeof args.seekPermission === 'boolean'
1322
- ? args.seekPermission
1323
- ? 1
1324
- : 0
1325
- : -1
1326
- )
766
+ this.writeOptionalBool(paramWriter, args.seekPermission)
1327
767
  return {
1328
768
  plaintext: await this.transmit(
1329
769
  'decrypt',
@@ -1333,14 +773,14 @@ export default class WalletWireTransceiver implements WalletInterface {
1333
773
  }
1334
774
  }
1335
775
 
1336
- async createHmac(
776
+ async createHmac (
1337
777
  args: {
1338
778
  seekPermission?: BooleanDefaultTrue
1339
779
  data: Byte[]
1340
780
  protocolID: [SecurityLevel, ProtocolString5To400Bytes]
1341
781
  keyID: KeyIDStringUnder800Bytes
1342
782
  privilegedReason?: DescriptionString5to50Bytes
1343
- counterparty?: PubKeyHex | 'self' | 'anyone'
783
+ counterparty?: PubKeyHex
1344
784
  privileged?: BooleanDefaultFalse
1345
785
  },
1346
786
  originator?: OriginatorDomainNameStringUnder250Bytes
@@ -1358,13 +798,7 @@ export default class WalletWireTransceiver implements WalletInterface {
1358
798
  paramWriter.writeVarIntNum(args.data.length)
1359
799
  paramWriter.write(args.data)
1360
800
  // Serialize seekPermission
1361
- paramWriter.writeInt8(
1362
- typeof args.seekPermission === 'boolean'
1363
- ? args.seekPermission
1364
- ? 1
1365
- : 0
1366
- : -1
1367
- )
801
+ this.writeOptionalBool(paramWriter, args.seekPermission)
1368
802
  return {
1369
803
  hmac: await this.transmit(
1370
804
  'createHmac',
@@ -1374,7 +808,7 @@ export default class WalletWireTransceiver implements WalletInterface {
1374
808
  }
1375
809
  }
1376
810
 
1377
- async verifyHmac(
811
+ async verifyHmac (
1378
812
  args: {
1379
813
  seekPermission?: BooleanDefaultTrue
1380
814
  data: Byte[]
@@ -1382,7 +816,7 @@ export default class WalletWireTransceiver implements WalletInterface {
1382
816
  protocolID: [SecurityLevel, ProtocolString5To400Bytes]
1383
817
  keyID: KeyIDStringUnder800Bytes
1384
818
  privilegedReason?: DescriptionString5to50Bytes
1385
- counterparty?: PubKeyHex | 'self' | 'anyone'
819
+ counterparty?: PubKeyHex
1386
820
  privileged?: BooleanDefaultFalse
1387
821
  },
1388
822
  originator?: OriginatorDomainNameStringUnder250Bytes
@@ -1401,18 +835,12 @@ export default class WalletWireTransceiver implements WalletInterface {
1401
835
  paramWriter.writeVarIntNum(args.data.length)
1402
836
  paramWriter.write(args.data)
1403
837
  // Serialize seekPermission
1404
- paramWriter.writeInt8(
1405
- typeof args.seekPermission === 'boolean'
1406
- ? args.seekPermission
1407
- ? 1
1408
- : 0
1409
- : -1
1410
- )
838
+ this.writeOptionalBool(paramWriter, args.seekPermission)
1411
839
  await this.transmit('verifyHmac', originator, paramWriter.toArray())
1412
840
  return { valid: true }
1413
841
  }
1414
842
 
1415
- async createSignature(
843
+ async createSignature (
1416
844
  args: {
1417
845
  seekPermission?: BooleanDefaultTrue
1418
846
  data?: Byte[]
@@ -1420,7 +848,7 @@ export default class WalletWireTransceiver implements WalletInterface {
1420
848
  protocolID: [SecurityLevel, ProtocolString5To400Bytes]
1421
849
  keyID: KeyIDStringUnder800Bytes
1422
850
  privilegedReason?: DescriptionString5to50Bytes
1423
- counterparty?: PubKeyHex | 'self' | 'anyone'
851
+ counterparty?: PubKeyHex
1424
852
  privileged?: BooleanDefaultFalse
1425
853
  },
1426
854
  originator?: OriginatorDomainNameStringUnder250Bytes
@@ -1440,17 +868,12 @@ export default class WalletWireTransceiver implements WalletInterface {
1440
868
  paramWriter.writeVarIntNum(args.data.length)
1441
869
  paramWriter.write(args.data)
1442
870
  } else {
871
+ args.hashToDirectlySign ??= []
1443
872
  paramWriter.writeUInt8(2)
1444
- paramWriter.write(args.hashToDirectlySign ??= [])
873
+ paramWriter.write(args.hashToDirectlySign)
1445
874
  }
1446
875
  // Serialize seekPermission
1447
- paramWriter.writeInt8(
1448
- typeof args.seekPermission === 'boolean'
1449
- ? args.seekPermission
1450
- ? 1
1451
- : 0
1452
- : -1
1453
- )
876
+ this.writeOptionalBool(paramWriter, args.seekPermission)
1454
877
  return {
1455
878
  signature: await this.transmit(
1456
879
  'createSignature',
@@ -1460,7 +883,7 @@ export default class WalletWireTransceiver implements WalletInterface {
1460
883
  }
1461
884
  }
1462
885
 
1463
- async verifySignature(
886
+ async verifySignature (
1464
887
  args: {
1465
888
  seekPermission?: BooleanDefaultTrue
1466
889
  data?: Byte[]
@@ -1469,7 +892,7 @@ export default class WalletWireTransceiver implements WalletInterface {
1469
892
  protocolID: [SecurityLevel, ProtocolString5To400Bytes]
1470
893
  keyID: KeyIDStringUnder800Bytes
1471
894
  privilegedReason?: DescriptionString5to50Bytes
1472
- counterparty?: PubKeyHex | 'self' | 'anyone'
895
+ counterparty?: PubKeyHex
1473
896
  forSelf?: BooleanDefaultFalse
1474
897
  privileged?: BooleanDefaultFalse
1475
898
  },
@@ -1501,21 +924,200 @@ export default class WalletWireTransceiver implements WalletInterface {
1501
924
  paramWriter.write(args.hashToDirectlyVerify ?? [])
1502
925
  }
1503
926
  // Serialize seekPermission
1504
- paramWriter.writeInt8(
1505
- typeof args.seekPermission === 'boolean'
1506
- ? args.seekPermission
1507
- ? 1
1508
- : 0
1509
- : -1
1510
- )
927
+ this.writeOptionalBool(paramWriter, args.seekPermission)
1511
928
  await this.transmit('verifySignature', originator, paramWriter.toArray())
1512
929
  return { valid: true }
1513
930
  }
1514
931
 
1515
- private encodeKeyRelatedParams(
932
+ /** Writes an optional boolean as Int8: 1/0 if present, -1 if absent. */
933
+ private writeOptionalBool (writer: Utils.Writer, val: boolean | undefined): void {
934
+ if (typeof val === 'boolean') {
935
+ writer.writeInt8(val ? 1 : 0)
936
+ } else {
937
+ writer.writeInt8(-1)
938
+ }
939
+ }
940
+
941
+ /** Writes an optional number as VarInt: the value if present, -1 if absent. */
942
+ private writeOptionalVarInt (writer: Utils.Writer, val: number | undefined): void {
943
+ if (typeof val === 'number') {
944
+ writer.writeVarIntNum(val)
945
+ } else {
946
+ writer.writeVarIntNum(-1)
947
+ }
948
+ }
949
+
950
+ /** Writes a UTF-8 string as (VarInt length, bytes). */
951
+ private writeUTF8 (writer: Utils.Writer, val: string | undefined): void {
952
+ const bytes = Utils.toArray(val ?? '', 'utf8')
953
+ writer.writeVarIntNum(bytes.length)
954
+ writer.write(bytes)
955
+ }
956
+
957
+ /** Writes an optional UTF-8 string: (VarInt length, bytes) if non-empty, -1 if absent/empty. */
958
+ private writeOptionalUTF8 (writer: Utils.Writer, val: string | undefined): void {
959
+ if (val != null && val !== '') {
960
+ const bytes = Utils.toArray(val, 'utf8')
961
+ writer.writeVarIntNum(bytes.length)
962
+ writer.write(bytes)
963
+ } else {
964
+ writer.writeVarIntNum(-1)
965
+ }
966
+ }
967
+
968
+ /** Writes an array of UTF-8 strings as (VarInt count, ...items). -1 if null. */
969
+ private writeUTF8Array (writer: Utils.Writer, arr: string[] | undefined): void {
970
+ if (arr == null) {
971
+ writer.writeVarIntNum(-1)
972
+ } else {
973
+ writer.writeVarIntNum(arr.length)
974
+ for (const item of arr) {
975
+ const bytes = Utils.toArray(item, 'utf8')
976
+ writer.writeVarIntNum(bytes.length)
977
+ writer.write(bytes)
978
+ }
979
+ }
980
+ }
981
+
982
+ /** Writes an array of hex-encoded txids (each 32 bytes) as (VarInt count, ...items). -1 if null. */
983
+ private writeTxidArray (writer: Utils.Writer, arr: string[] | undefined): void {
984
+ if (arr == null) {
985
+ writer.writeVarIntNum(-1)
986
+ } else {
987
+ writer.writeVarIntNum(arr.length)
988
+ for (const txid of arr) {
989
+ writer.write(Utils.toArray(txid, 'hex'))
990
+ }
991
+ }
992
+ }
993
+
994
+ /** Reads a list of SendWithResults entries from a binary reader. */
995
+ private readSendWithResults (
996
+ reader: Utils.Reader
997
+ ): Array<{ txid: TXIDHexString, status: SendWithResultStatus }> | undefined {
998
+ const len = reader.readVarIntNum()
999
+ if (len < 0) return undefined
1000
+ const results: Array<{ txid: TXIDHexString, status: SendWithResultStatus }> = []
1001
+ for (let i = 0; i < len; i++) {
1002
+ const txid = Utils.toHex(reader.read(32))
1003
+ const code = reader.readInt8()
1004
+ const status: SendWithResultStatus = code === 2 ? 'sending' : code === 3 ? 'failed' : 'unproven'
1005
+ results.push({ txid, status })
1006
+ }
1007
+ return results
1008
+ }
1009
+
1010
+ /** Serializes a single createAction input to the writer. */
1011
+ private serializeCreateActionInput (
1012
+ writer: Utils.Writer,
1013
+ input: {
1014
+ outpoint: OutpointString
1015
+ unlockingScript?: string
1016
+ unlockingScriptLength?: number
1017
+ inputDescription: string
1018
+ sequenceNumber?: number
1019
+ }
1020
+ ): void {
1021
+ writer.write(this.encodeOutpoint(input.outpoint))
1022
+
1023
+ if (input.unlockingScript != null && input.unlockingScript !== '') {
1024
+ const bytes = Utils.toArray(input.unlockingScript, 'hex')
1025
+ writer.writeVarIntNum(bytes.length)
1026
+ writer.write(bytes)
1027
+ } else {
1028
+ writer.writeVarIntNum(-1)
1029
+ writer.writeVarIntNum(input.unlockingScriptLength ?? 0)
1030
+ }
1031
+
1032
+ this.writeUTF8(writer, input.inputDescription)
1033
+ this.writeOptionalVarInt(writer, input.sequenceNumber)
1034
+ }
1035
+
1036
+ /** Serializes a single createAction output to the writer. */
1037
+ private serializeCreateActionOutput (
1038
+ writer: Utils.Writer,
1039
+ output: {
1040
+ lockingScript: string
1041
+ satoshis: number
1042
+ outputDescription: string
1043
+ basket?: string
1044
+ customInstructions?: string
1045
+ tags?: string[]
1046
+ }
1047
+ ): void {
1048
+ const lockingBytes = Utils.toArray(output.lockingScript, 'hex')
1049
+ writer.writeVarIntNum(lockingBytes.length)
1050
+ writer.write(lockingBytes)
1051
+ writer.writeVarIntNum(output.satoshis)
1052
+ this.writeUTF8(writer, output.outputDescription)
1053
+ this.writeOptionalUTF8(writer, output.basket)
1054
+ this.writeOptionalUTF8(writer, output.customInstructions)
1055
+ this.writeUTF8Array(writer, output.tags)
1056
+ }
1057
+
1058
+ /** Serializes createAction options to the writer (Int8 presence byte + fields). */
1059
+ private serializeCreateActionOptions (
1060
+ writer: Utils.Writer,
1061
+ options: {
1062
+ signAndProcess?: boolean
1063
+ acceptDelayedBroadcast?: boolean
1064
+ trustSelf?: string
1065
+ knownTxids?: string[]
1066
+ returnTXIDOnly?: boolean
1067
+ noSend?: boolean
1068
+ noSendChange?: OutpointString[]
1069
+ sendWith?: string[]
1070
+ randomizeOutputs?: boolean
1071
+ } | undefined
1072
+ ): void {
1073
+ if (options == null) {
1074
+ writer.writeInt8(0)
1075
+ return
1076
+ }
1077
+ writer.writeInt8(1)
1078
+ this.writeOptionalBool(writer, options.signAndProcess)
1079
+ this.writeOptionalBool(writer, options.acceptDelayedBroadcast)
1080
+ writer.writeInt8(options.trustSelf === 'known' ? 1 : -1)
1081
+ this.writeTxidArray(writer, options.knownTxids)
1082
+ this.writeOptionalBool(writer, options.returnTXIDOnly)
1083
+ this.writeOptionalBool(writer, options.noSend)
1084
+ if (options.noSendChange == null) {
1085
+ writer.writeVarIntNum(-1)
1086
+ } else {
1087
+ writer.writeVarIntNum(options.noSendChange.length)
1088
+ for (const outpoint of options.noSendChange) {
1089
+ writer.write(this.encodeOutpoint(outpoint))
1090
+ }
1091
+ }
1092
+ this.writeTxidArray(writer, options.sendWith)
1093
+ this.writeOptionalBool(writer, options.randomizeOutputs)
1094
+ }
1095
+
1096
+ /** Serializes signAction options to the writer (Int8 presence byte + fields). */
1097
+ private serializeSignActionOptions (
1098
+ writer: Utils.Writer,
1099
+ options: {
1100
+ acceptDelayedBroadcast?: boolean
1101
+ returnTXIDOnly?: boolean
1102
+ noSend?: boolean
1103
+ sendWith?: string[]
1104
+ } | undefined
1105
+ ): void {
1106
+ if (options == null) {
1107
+ writer.writeInt8(0)
1108
+ return
1109
+ }
1110
+ writer.writeInt8(1)
1111
+ this.writeOptionalBool(writer, options.acceptDelayedBroadcast)
1112
+ this.writeOptionalBool(writer, options.returnTXIDOnly)
1113
+ this.writeOptionalBool(writer, options.noSend)
1114
+ this.writeTxidArray(writer, options.sendWith)
1115
+ }
1116
+
1117
+ private encodeKeyRelatedParams (
1516
1118
  protocolID: [SecurityLevel, ProtocolString5To400Bytes],
1517
1119
  keyID: KeyIDStringUnder800Bytes,
1518
- counterparty?: PubKeyHex | 'self' | 'anyone',
1120
+ counterparty?: PubKeyHex,
1519
1121
  privileged?: boolean,
1520
1122
  privilegedReason?: string
1521
1123
  ): number[] {
@@ -1542,7 +1144,7 @@ export default class WalletWireTransceiver implements WalletInterface {
1542
1144
  return paramWriter.toArray()
1543
1145
  }
1544
1146
 
1545
- async acquireCertificate(
1147
+ async acquireCertificate (
1546
1148
  args: AcquireCertificateArgs,
1547
1149
  originator?: OriginatorDomainNameStringUnder250Bytes
1548
1150
  ): Promise<AcquireCertificateResult> {
@@ -1576,19 +1178,19 @@ export default class WalletWireTransceiver implements WalletInterface {
1576
1178
  paramWriter.write(signatureAsArray)
1577
1179
 
1578
1180
  const keyringRevealerAsArray =
1579
- args.keyringRevealer !== 'certifier'
1580
- ? Utils.toArray(args.keyringRevealer, 'hex')
1581
- : [11]
1181
+ args.keyringRevealer === 'certifier'
1182
+ ? [11]
1183
+ : Utils.toArray(args.keyringRevealer, 'hex')
1582
1184
  paramWriter.write(keyringRevealerAsArray)
1583
1185
 
1584
1186
  const keyringKeys = Object.keys(args.keyringForSubject ?? {})
1585
1187
  paramWriter.writeVarIntNum(keyringKeys.length)
1586
- for (let i = 0; i < keyringKeys.length; i++) {
1587
- const keyringKeysAsArray = Utils.toArray(keyringKeys[i], 'utf8')
1188
+ for (const key of keyringKeys) {
1189
+ const keyringKeysAsArray = Utils.toArray(key, 'utf8')
1588
1190
  paramWriter.writeVarIntNum(keyringKeysAsArray.length)
1589
1191
  paramWriter.write(keyringKeysAsArray)
1590
1192
  const keyringForSubjectAsArray = Utils.toArray(
1591
- args.keyringForSubject?.[keyringKeys[i]],
1193
+ args.keyringForSubject?.[key],
1592
1194
  'base64'
1593
1195
  )
1594
1196
  paramWriter.writeVarIntNum(keyringForSubjectAsArray.length)
@@ -1612,7 +1214,7 @@ export default class WalletWireTransceiver implements WalletInterface {
1612
1214
  }
1613
1215
  }
1614
1216
 
1615
- private encodePrivilegedParams(
1217
+ private encodePrivilegedParams (
1616
1218
  privileged?: boolean,
1617
1219
  privilegedReason?: string
1618
1220
  ): number[] {
@@ -1632,7 +1234,7 @@ export default class WalletWireTransceiver implements WalletInterface {
1632
1234
  return paramWriter.toArray()
1633
1235
  }
1634
1236
 
1635
- async listCertificates(
1237
+ async listCertificates (
1636
1238
  args: {
1637
1239
  certifiers: PubKeyHex[]
1638
1240
  types: Base64String[]
@@ -1645,13 +1247,13 @@ export default class WalletWireTransceiver implements WalletInterface {
1645
1247
  ): Promise<ListCertificatesResult> {
1646
1248
  const paramWriter = new Utils.Writer()
1647
1249
  paramWriter.writeVarIntNum(args.certifiers.length)
1648
- for (let i = 0; i < args.certifiers.length; i++) {
1649
- paramWriter.write(Utils.toArray(args.certifiers[i], 'hex'))
1250
+ for (const certifier of args.certifiers) {
1251
+ paramWriter.write(Utils.toArray(certifier, 'hex'))
1650
1252
  }
1651
1253
 
1652
1254
  paramWriter.writeVarIntNum(args.types.length)
1653
- for (let i = 0; i < args.types.length; i++) {
1654
- paramWriter.write(Utils.toArray(args.types[i], 'base64'))
1255
+ for (const type of args.types) {
1256
+ paramWriter.write(Utils.toArray(type, 'base64'))
1655
1257
  }
1656
1258
  if (typeof args.limit === 'number') {
1657
1259
  paramWriter.writeVarIntNum(args.limit)
@@ -1673,7 +1275,7 @@ export default class WalletWireTransceiver implements WalletInterface {
1673
1275
  )
1674
1276
  const resultReader = new Utils.Reader(result)
1675
1277
  const totalCertificates = resultReader.readVarIntNum()
1676
- const certificates: Array<CertificateResult> = []
1278
+ const certificates: CertificateResult[] = []
1677
1279
  for (let i = 0; i < totalCertificates; i++) {
1678
1280
  const certificateLength = resultReader.readVarIntNum()
1679
1281
  const certificateBin = resultReader.read(certificateLength)
@@ -1691,7 +1293,7 @@ export default class WalletWireTransceiver implements WalletInterface {
1691
1293
  }
1692
1294
  }
1693
1295
  const verifierLength = resultReader.readVarIntNum()
1694
- let verifier: string | undefined = undefined
1296
+ let verifier: string | undefined
1695
1297
  if (verifierLength > 0) {
1696
1298
  verifier = Utils.toUTF8(resultReader.read(verifierLength))
1697
1299
  }
@@ -1699,7 +1301,7 @@ export default class WalletWireTransceiver implements WalletInterface {
1699
1301
  ...cert,
1700
1302
  signature: cert.signature as string,
1701
1303
  keyring: keyringForVerifier,
1702
- verifier,
1304
+ verifier
1703
1305
  })
1704
1306
  }
1705
1307
  return {
@@ -1708,7 +1310,7 @@ export default class WalletWireTransceiver implements WalletInterface {
1708
1310
  }
1709
1311
  }
1710
1312
 
1711
- async proveCertificate(
1313
+ async proveCertificate (
1712
1314
  args: ProveCertificateArgs,
1713
1315
  originator?: OriginatorDomainNameStringUnder250Bytes
1714
1316
  ): Promise<ProveCertificateResult> {
@@ -1772,7 +1374,7 @@ export default class WalletWireTransceiver implements WalletInterface {
1772
1374
  }
1773
1375
  }
1774
1376
 
1775
- async relinquishCertificate(
1377
+ async relinquishCertificate (
1776
1378
  args: {
1777
1379
  type: Base64String
1778
1380
  serialNumber: Base64String
@@ -1795,7 +1397,7 @@ export default class WalletWireTransceiver implements WalletInterface {
1795
1397
  return { relinquished: true }
1796
1398
  }
1797
1399
 
1798
- private parseDiscoveryResult(result: number[]): {
1400
+ private parseDiscoveryResult (result: number[]): {
1799
1401
  totalCertificates: number
1800
1402
  certificates: Array<{
1801
1403
  type: Base64String
@@ -1812,8 +1414,8 @@ export default class WalletWireTransceiver implements WalletInterface {
1812
1414
  trust: PositiveIntegerMax10
1813
1415
  }
1814
1416
  publiclyRevealedKeyring: Record<
1815
- CertificateFieldNameUnder50Bytes,
1816
- Base64String
1417
+ CertificateFieldNameUnder50Bytes,
1418
+ Base64String
1817
1419
  >
1818
1420
  decryptedFields: Record<CertificateFieldNameUnder50Bytes, string>
1819
1421
  }>
@@ -1835,8 +1437,8 @@ export default class WalletWireTransceiver implements WalletInterface {
1835
1437
  trust: PositiveIntegerMax10
1836
1438
  }
1837
1439
  publiclyRevealedKeyring: Record<
1838
- CertificateFieldNameUnder50Bytes,
1839
- Base64String
1440
+ CertificateFieldNameUnder50Bytes,
1441
+ Base64String
1840
1442
  >
1841
1443
  decryptedFields: Record<CertificateFieldNameUnder50Bytes, string>
1842
1444
  }> = []
@@ -1883,7 +1485,7 @@ export default class WalletWireTransceiver implements WalletInterface {
1883
1485
  }
1884
1486
  }
1885
1487
 
1886
- async discoverByIdentityKey(
1488
+ async discoverByIdentityKey (
1887
1489
  args: {
1888
1490
  seekPermission?: BooleanDefaultTrue
1889
1491
  identityKey: PubKeyHex
@@ -1905,13 +1507,7 @@ export default class WalletWireTransceiver implements WalletInterface {
1905
1507
  paramWriter.writeVarIntNum(-1)
1906
1508
  }
1907
1509
  // Serialize seekPermission
1908
- paramWriter.writeInt8(
1909
- typeof args.seekPermission === 'boolean'
1910
- ? args.seekPermission
1911
- ? 1
1912
- : 0
1913
- : -1
1914
- )
1510
+ this.writeOptionalBool(paramWriter, args.seekPermission)
1915
1511
  const result = await this.transmit(
1916
1512
  'discoverByIdentityKey',
1917
1513
  originator,
@@ -1920,7 +1516,7 @@ export default class WalletWireTransceiver implements WalletInterface {
1920
1516
  return this.parseDiscoveryResult(result)
1921
1517
  }
1922
1518
 
1923
- async discoverByAttributes(
1519
+ async discoverByAttributes (
1924
1520
  args: {
1925
1521
  seekPermission?: BooleanDefaultTrue
1926
1522
  attributes: Record<CertificateFieldNameUnder50Bytes, string>
@@ -1932,12 +1528,12 @@ export default class WalletWireTransceiver implements WalletInterface {
1932
1528
  const paramWriter = new Utils.Writer()
1933
1529
  const attributeKeys = Object.keys(args.attributes)
1934
1530
  paramWriter.writeVarIntNum(attributeKeys.length)
1935
- for (let i = 0; i < attributeKeys.length; i++) {
1936
- paramWriter.writeVarIntNum(attributeKeys[i].length)
1937
- paramWriter.write(Utils.toArray(attributeKeys[i], 'utf8'))
1938
- paramWriter.writeVarIntNum(args.attributes[attributeKeys[i]].length)
1531
+ for (const attrKey of attributeKeys) {
1532
+ paramWriter.writeVarIntNum(attrKey.length)
1533
+ paramWriter.write(Utils.toArray(attrKey, 'utf8'))
1534
+ paramWriter.writeVarIntNum(args.attributes[attrKey].length)
1939
1535
  paramWriter.write(
1940
- Utils.toArray(args.attributes[attributeKeys[i]], 'utf8')
1536
+ Utils.toArray(args.attributes[attrKey], 'utf8')
1941
1537
  )
1942
1538
  }
1943
1539
  if (typeof args.limit === 'number') {
@@ -1951,13 +1547,7 @@ export default class WalletWireTransceiver implements WalletInterface {
1951
1547
  paramWriter.writeVarIntNum(-1)
1952
1548
  }
1953
1549
  // Serialize seekPermission
1954
- paramWriter.writeInt8(
1955
- typeof args.seekPermission === 'boolean'
1956
- ? args.seekPermission
1957
- ? 1
1958
- : 0
1959
- : -1
1960
- )
1550
+ this.writeOptionalBool(paramWriter, args.seekPermission)
1961
1551
  const result = await this.transmit(
1962
1552
  'discoverByAttributes',
1963
1553
  originator,
@@ -1966,7 +1556,7 @@ export default class WalletWireTransceiver implements WalletInterface {
1966
1556
  return this.parseDiscoveryResult(result)
1967
1557
  }
1968
1558
 
1969
- async isAuthenticated(
1559
+ async isAuthenticated (
1970
1560
  args: {},
1971
1561
  originator?: OriginatorDomainNameStringUnder250Bytes
1972
1562
  ): Promise<{ authenticated: true }> {
@@ -1975,7 +1565,7 @@ export default class WalletWireTransceiver implements WalletInterface {
1975
1565
  return { authenticated: result[0] === 1 }
1976
1566
  }
1977
1567
 
1978
- async waitForAuthentication(
1568
+ async waitForAuthentication (
1979
1569
  args: {},
1980
1570
  originator?: OriginatorDomainNameStringUnder250Bytes
1981
1571
  ): Promise<{ authenticated: true }> {
@@ -1983,7 +1573,7 @@ export default class WalletWireTransceiver implements WalletInterface {
1983
1573
  return { authenticated: true }
1984
1574
  }
1985
1575
 
1986
- async getHeight(
1576
+ async getHeight (
1987
1577
  args: {},
1988
1578
  originator?: OriginatorDomainNameStringUnder250Bytes
1989
1579
  ): Promise<{ height: PositiveInteger }> {
@@ -1994,7 +1584,7 @@ export default class WalletWireTransceiver implements WalletInterface {
1994
1584
  }
1995
1585
  }
1996
1586
 
1997
- async getHeaderForHeight(
1587
+ async getHeaderForHeight (
1998
1588
  args: { height: PositiveInteger },
1999
1589
  originator?: OriginatorDomainNameStringUnder250Bytes
2000
1590
  ): Promise<{ header: HexString }> {
@@ -2010,7 +1600,7 @@ export default class WalletWireTransceiver implements WalletInterface {
2010
1600
  }
2011
1601
  }
2012
1602
 
2013
- async getNetwork(
1603
+ async getNetwork (
2014
1604
  args: {},
2015
1605
  originator?: OriginatorDomainNameStringUnder250Bytes
2016
1606
  ): Promise<{ network: 'mainnet' | 'testnet' }> {
@@ -2020,7 +1610,7 @@ export default class WalletWireTransceiver implements WalletInterface {
2020
1610
  }
2021
1611
  }
2022
1612
 
2023
- async getVersion(
1613
+ async getVersion (
2024
1614
  args: {},
2025
1615
  originator?: OriginatorDomainNameStringUnder250Bytes
2026
1616
  ): Promise<{ version: VersionString7To30Bytes }> {