@bsv/sdk 1.3.12 → 1.3.14

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 (607) hide show
  1. package/dist/cjs/package.json +15 -3
  2. package/dist/cjs/src/auth/Peer.js +83 -57
  3. package/dist/cjs/src/auth/Peer.js.map +1 -1
  4. package/dist/cjs/src/auth/SessionManager.js +14 -9
  5. package/dist/cjs/src/auth/SessionManager.js.map +1 -1
  6. package/dist/cjs/src/auth/certificates/Certificate.js +16 -10
  7. package/dist/cjs/src/auth/certificates/Certificate.js.map +1 -1
  8. package/dist/cjs/src/auth/certificates/MasterCertificate.js +25 -23
  9. package/dist/cjs/src/auth/certificates/MasterCertificate.js.map +1 -1
  10. package/dist/cjs/src/auth/certificates/VerifiableCertificate.js +2 -2
  11. package/dist/cjs/src/auth/certificates/VerifiableCertificate.js.map +1 -1
  12. package/dist/cjs/src/auth/certificates/__tests/CompletedProtoWallet.js +62 -46
  13. package/dist/cjs/src/auth/certificates/__tests/CompletedProtoWallet.js.map +1 -1
  14. package/dist/cjs/src/auth/clients/AuthFetch.js +1 -0
  15. package/dist/cjs/src/auth/clients/AuthFetch.js.map +1 -1
  16. package/dist/cjs/src/auth/transports/SimplifiedFetchTransport.js +70 -43
  17. package/dist/cjs/src/auth/transports/SimplifiedFetchTransport.js.map +1 -1
  18. package/dist/cjs/src/auth/utils/createNonce.js +2 -1
  19. package/dist/cjs/src/auth/utils/createNonce.js.map +1 -1
  20. package/dist/cjs/src/auth/utils/getVerifiableCertificates.js.map +1 -1
  21. package/dist/cjs/src/auth/utils/validateCertificates.js +5 -2
  22. package/dist/cjs/src/auth/utils/validateCertificates.js.map +1 -1
  23. package/dist/cjs/src/auth/utils/verifyNonce.js +2 -1
  24. package/dist/cjs/src/auth/utils/verifyNonce.js.map +1 -1
  25. package/dist/cjs/src/compat/BSM.js +7 -17
  26. package/dist/cjs/src/compat/BSM.js.map +1 -1
  27. package/dist/cjs/src/compat/ECIES.js +172 -133
  28. package/dist/cjs/src/compat/ECIES.js.map +1 -1
  29. package/dist/cjs/src/compat/HD.js +63 -73
  30. package/dist/cjs/src/compat/HD.js.map +1 -1
  31. package/dist/cjs/src/compat/Mnemonic.js +102 -106
  32. package/dist/cjs/src/compat/Mnemonic.js.map +1 -1
  33. package/dist/cjs/src/compat/Utxo.js +2 -2
  34. package/dist/cjs/src/compat/Utxo.js.map +1 -1
  35. package/dist/cjs/src/compat/index.js +7 -17
  36. package/dist/cjs/src/compat/index.js.map +1 -1
  37. package/dist/cjs/src/messages/EncryptedMessage.js +3 -1
  38. package/dist/cjs/src/messages/EncryptedMessage.js.map +1 -1
  39. package/dist/cjs/src/messages/SignedMessage.js +1 -0
  40. package/dist/cjs/src/messages/SignedMessage.js.map +1 -1
  41. package/dist/cjs/src/messages/index.js +7 -17
  42. package/dist/cjs/src/messages/index.js.map +1 -1
  43. package/dist/cjs/src/overlay-tools/LookupResolver.js +54 -35
  44. package/dist/cjs/src/overlay-tools/LookupResolver.js.map +1 -1
  45. package/dist/cjs/src/overlay-tools/OverlayAdminTokenTemplate.js +32 -20
  46. package/dist/cjs/src/overlay-tools/OverlayAdminTokenTemplate.js.map +1 -1
  47. package/dist/cjs/src/overlay-tools/SHIPBroadcaster.js +40 -28
  48. package/dist/cjs/src/overlay-tools/SHIPBroadcaster.js.map +1 -1
  49. package/dist/cjs/src/primitives/AESGCM.js +6 -5
  50. package/dist/cjs/src/primitives/AESGCM.js.map +1 -1
  51. package/dist/cjs/src/primitives/BasePoint.js +1 -1
  52. package/dist/cjs/src/primitives/BasePoint.js.map +1 -1
  53. package/dist/cjs/src/primitives/BigNumber.js +50 -62
  54. package/dist/cjs/src/primitives/BigNumber.js.map +1 -1
  55. package/dist/cjs/src/primitives/Curve.js +46 -22
  56. package/dist/cjs/src/primitives/Curve.js.map +1 -1
  57. package/dist/cjs/src/primitives/DRBG.js +2 -8
  58. package/dist/cjs/src/primitives/DRBG.js.map +1 -1
  59. package/dist/cjs/src/primitives/ECDSA.js +51 -35
  60. package/dist/cjs/src/primitives/ECDSA.js.map +1 -1
  61. package/dist/cjs/src/primitives/Hash.js +191 -216
  62. package/dist/cjs/src/primitives/Hash.js.map +1 -1
  63. package/dist/cjs/src/primitives/JacobianPoint.js +19 -5
  64. package/dist/cjs/src/primitives/JacobianPoint.js.map +1 -1
  65. package/dist/cjs/src/primitives/K256.js.map +1 -1
  66. package/dist/cjs/src/primitives/Mersenne.js.map +1 -1
  67. package/dist/cjs/src/primitives/MontgomoryMethod.js.map +1 -1
  68. package/dist/cjs/src/primitives/Point.js +117 -88
  69. package/dist/cjs/src/primitives/Point.js.map +1 -1
  70. package/dist/cjs/src/primitives/Polynomial.js +4 -2
  71. package/dist/cjs/src/primitives/Polynomial.js.map +1 -1
  72. package/dist/cjs/src/primitives/PrivateKey.js +32 -33
  73. package/dist/cjs/src/primitives/PrivateKey.js.map +1 -1
  74. package/dist/cjs/src/primitives/PublicKey.js.map +1 -1
  75. package/dist/cjs/src/primitives/Random.js +6 -5
  76. package/dist/cjs/src/primitives/Random.js.map +1 -1
  77. package/dist/cjs/src/primitives/ReductionContext.js +1 -1
  78. package/dist/cjs/src/primitives/ReductionContext.js.map +1 -1
  79. package/dist/cjs/src/primitives/Schnorr.js +21 -15
  80. package/dist/cjs/src/primitives/Schnorr.js.map +1 -1
  81. package/dist/cjs/src/primitives/Signature.js +8 -7
  82. package/dist/cjs/src/primitives/Signature.js.map +1 -1
  83. package/dist/cjs/src/primitives/SymmetricKey.js +13 -13
  84. package/dist/cjs/src/primitives/SymmetricKey.js.map +1 -1
  85. package/dist/cjs/src/primitives/TransactionSignature.js +31 -29
  86. package/dist/cjs/src/primitives/TransactionSignature.js.map +1 -1
  87. package/dist/cjs/src/primitives/index.js +7 -17
  88. package/dist/cjs/src/primitives/index.js.map +1 -1
  89. package/dist/cjs/src/primitives/utils.js +79 -68
  90. package/dist/cjs/src/primitives/utils.js.map +1 -1
  91. package/dist/cjs/src/script/OP.js +3 -3
  92. package/dist/cjs/src/script/OP.js.map +1 -1
  93. package/dist/cjs/src/script/Script.js +12 -10
  94. package/dist/cjs/src/script/Script.js.map +1 -1
  95. package/dist/cjs/src/script/Spend.js +47 -49
  96. package/dist/cjs/src/script/Spend.js.map +1 -1
  97. package/dist/cjs/src/script/templates/P2PKH.js +24 -12
  98. package/dist/cjs/src/script/templates/P2PKH.js.map +1 -1
  99. package/dist/cjs/src/script/templates/PushDrop.js +28 -23
  100. package/dist/cjs/src/script/templates/PushDrop.js.map +1 -1
  101. package/dist/cjs/src/script/templates/RPuzzle.js +10 -6
  102. package/dist/cjs/src/script/templates/RPuzzle.js.map +1 -1
  103. package/dist/cjs/src/totp/totp.js +2 -1
  104. package/dist/cjs/src/totp/totp.js.map +1 -1
  105. package/dist/cjs/src/transaction/Beef.js +177 -154
  106. package/dist/cjs/src/transaction/Beef.js.map +1 -1
  107. package/dist/cjs/src/transaction/BeefParty.js +24 -24
  108. package/dist/cjs/src/transaction/BeefParty.js.map +1 -1
  109. package/dist/cjs/src/transaction/BeefTx.js +26 -18
  110. package/dist/cjs/src/transaction/BeefTx.js.map +1 -1
  111. package/dist/cjs/src/transaction/Broadcaster.js +3 -2
  112. package/dist/cjs/src/transaction/Broadcaster.js.map +1 -1
  113. package/dist/cjs/src/transaction/MerklePath.js +64 -37
  114. package/dist/cjs/src/transaction/MerklePath.js.map +1 -1
  115. package/dist/cjs/src/transaction/Transaction.js +111 -137
  116. package/dist/cjs/src/transaction/Transaction.js.map +1 -1
  117. package/dist/cjs/src/transaction/broadcasters/ARC.js +25 -16
  118. package/dist/cjs/src/transaction/broadcasters/ARC.js.map +1 -1
  119. package/dist/cjs/src/transaction/broadcasters/DefaultBroadcaster.js +2 -1
  120. package/dist/cjs/src/transaction/broadcasters/DefaultBroadcaster.js.map +1 -1
  121. package/dist/cjs/src/transaction/broadcasters/WhatsOnChainBroadcaster.js.map +1 -1
  122. package/dist/cjs/src/transaction/chaintrackers/DefaultChainTracker.js +2 -1
  123. package/dist/cjs/src/transaction/chaintrackers/DefaultChainTracker.js.map +1 -1
  124. package/dist/cjs/src/transaction/chaintrackers/WhatsOnChain.js +3 -3
  125. package/dist/cjs/src/transaction/chaintrackers/WhatsOnChain.js.map +1 -1
  126. package/dist/cjs/src/transaction/fee-models/SatoshisPerKilobyte.js.map +1 -1
  127. package/dist/cjs/src/transaction/http/DefaultHttpClient.js +5 -3
  128. package/dist/cjs/src/transaction/http/DefaultHttpClient.js.map +1 -1
  129. package/dist/cjs/src/transaction/http/FetchHttpClient.js +5 -2
  130. package/dist/cjs/src/transaction/http/FetchHttpClient.js.map +1 -1
  131. package/dist/cjs/src/transaction/http/NodejsHttpClient.js +5 -3
  132. package/dist/cjs/src/transaction/http/NodejsHttpClient.js.map +1 -1
  133. package/dist/cjs/src/transaction/http/index.js.map +1 -1
  134. package/dist/cjs/src/transaction/index.js.map +1 -1
  135. package/dist/cjs/src/wallet/CachedKeyDeriver.js +91 -66
  136. package/dist/cjs/src/wallet/CachedKeyDeriver.js.map +1 -1
  137. package/dist/cjs/src/wallet/KeyDeriver.js +61 -52
  138. package/dist/cjs/src/wallet/KeyDeriver.js.map +1 -1
  139. package/dist/cjs/src/wallet/ProtoWallet.js +79 -29
  140. package/dist/cjs/src/wallet/ProtoWallet.js.map +1 -1
  141. package/dist/cjs/src/wallet/WalletClient.js +7 -2
  142. package/dist/cjs/src/wallet/WalletClient.js.map +1 -1
  143. package/dist/cjs/src/wallet/WalletError.js +2 -2
  144. package/dist/cjs/src/wallet/WalletError.js.map +1 -1
  145. package/dist/cjs/src/wallet/substrates/HTTPWalletJSON.js +4 -3
  146. package/dist/cjs/src/wallet/substrates/HTTPWalletJSON.js.map +1 -1
  147. package/dist/cjs/src/wallet/substrates/HTTPWalletWire.js +2 -2
  148. package/dist/cjs/src/wallet/substrates/HTTPWalletWire.js.map +1 -1
  149. package/dist/cjs/src/wallet/substrates/WalletWireProcessor.js +1239 -1261
  150. package/dist/cjs/src/wallet/substrates/WalletWireProcessor.js.map +1 -1
  151. package/dist/cjs/src/wallet/substrates/WalletWireTransceiver.js +102 -43
  152. package/dist/cjs/src/wallet/substrates/WalletWireTransceiver.js.map +1 -1
  153. package/dist/cjs/src/wallet/substrates/XDM.js +8 -3
  154. package/dist/cjs/src/wallet/substrates/XDM.js.map +1 -1
  155. package/dist/cjs/src/wallet/substrates/window.CWI.js +28 -28
  156. package/dist/cjs/src/wallet/substrates/window.CWI.js.map +1 -1
  157. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  158. package/dist/esm/mod.js +15 -15
  159. package/dist/esm/src/auth/Peer.js +75 -54
  160. package/dist/esm/src/auth/Peer.js.map +1 -1
  161. package/dist/esm/src/auth/SessionManager.js +14 -9
  162. package/dist/esm/src/auth/SessionManager.js.map +1 -1
  163. package/dist/esm/src/auth/certificates/Certificate.js +15 -11
  164. package/dist/esm/src/auth/certificates/Certificate.js.map +1 -1
  165. package/dist/esm/src/auth/certificates/MasterCertificate.js +25 -23
  166. package/dist/esm/src/auth/certificates/MasterCertificate.js.map +1 -1
  167. package/dist/esm/src/auth/certificates/VerifiableCertificate.js +2 -2
  168. package/dist/esm/src/auth/certificates/VerifiableCertificate.js.map +1 -1
  169. package/dist/esm/src/auth/certificates/__tests/CompletedProtoWallet.js +64 -47
  170. package/dist/esm/src/auth/certificates/__tests/CompletedProtoWallet.js.map +1 -1
  171. package/dist/esm/src/auth/clients/AuthFetch.js +1 -0
  172. package/dist/esm/src/auth/clients/AuthFetch.js.map +1 -1
  173. package/dist/esm/src/auth/transports/SimplifiedFetchTransport.js +69 -43
  174. package/dist/esm/src/auth/transports/SimplifiedFetchTransport.js.map +1 -1
  175. package/dist/esm/src/auth/utils/createNonce.js.map +1 -1
  176. package/dist/esm/src/auth/utils/getVerifiableCertificates.js +1 -1
  177. package/dist/esm/src/auth/utils/getVerifiableCertificates.js.map +1 -1
  178. package/dist/esm/src/auth/utils/validateCertificates.js +6 -3
  179. package/dist/esm/src/auth/utils/validateCertificates.js.map +1 -1
  180. package/dist/esm/src/auth/utils/verifyNonce.js.map +1 -1
  181. package/dist/esm/src/compat/BSM.js.map +1 -1
  182. package/dist/esm/src/compat/ECIES.js +165 -116
  183. package/dist/esm/src/compat/ECIES.js.map +1 -1
  184. package/dist/esm/src/compat/HD.js +56 -56
  185. package/dist/esm/src/compat/HD.js.map +1 -1
  186. package/dist/esm/src/compat/Mnemonic.js +95 -89
  187. package/dist/esm/src/compat/Mnemonic.js.map +1 -1
  188. package/dist/esm/src/compat/Utxo.js +1 -1
  189. package/dist/esm/src/compat/Utxo.js.map +1 -1
  190. package/dist/esm/src/messages/EncryptedMessage.js +3 -1
  191. package/dist/esm/src/messages/EncryptedMessage.js.map +1 -1
  192. package/dist/esm/src/messages/SignedMessage.js +1 -0
  193. package/dist/esm/src/messages/SignedMessage.js.map +1 -1
  194. package/dist/esm/src/overlay-tools/LookupResolver.js +53 -35
  195. package/dist/esm/src/overlay-tools/LookupResolver.js.map +1 -1
  196. package/dist/esm/src/overlay-tools/OverlayAdminTokenTemplate.js +32 -20
  197. package/dist/esm/src/overlay-tools/OverlayAdminTokenTemplate.js.map +1 -1
  198. package/dist/esm/src/overlay-tools/SHIPBroadcaster.js +40 -28
  199. package/dist/esm/src/overlay-tools/SHIPBroadcaster.js.map +1 -1
  200. package/dist/esm/src/primitives/AESGCM.js +1 -0
  201. package/dist/esm/src/primitives/AESGCM.js.map +1 -1
  202. package/dist/esm/src/primitives/BasePoint.js +1 -1
  203. package/dist/esm/src/primitives/BasePoint.js.map +1 -1
  204. package/dist/esm/src/primitives/BigNumber.js +50 -62
  205. package/dist/esm/src/primitives/BigNumber.js.map +1 -1
  206. package/dist/esm/src/primitives/Curve.js +45 -22
  207. package/dist/esm/src/primitives/Curve.js.map +1 -1
  208. package/dist/esm/src/primitives/DRBG.js +2 -8
  209. package/dist/esm/src/primitives/DRBG.js.map +1 -1
  210. package/dist/esm/src/primitives/ECDSA.js +50 -35
  211. package/dist/esm/src/primitives/ECDSA.js.map +1 -1
  212. package/dist/esm/src/primitives/Hash.js +188 -213
  213. package/dist/esm/src/primitives/Hash.js.map +1 -1
  214. package/dist/esm/src/primitives/JacobianPoint.js +18 -5
  215. package/dist/esm/src/primitives/JacobianPoint.js.map +1 -1
  216. package/dist/esm/src/primitives/K256.js.map +1 -1
  217. package/dist/esm/src/primitives/Mersenne.js.map +1 -1
  218. package/dist/esm/src/primitives/MontgomoryMethod.js.map +1 -1
  219. package/dist/esm/src/primitives/Point.js +107 -88
  220. package/dist/esm/src/primitives/Point.js.map +1 -1
  221. package/dist/esm/src/primitives/Polynomial.js +4 -2
  222. package/dist/esm/src/primitives/Polynomial.js.map +1 -1
  223. package/dist/esm/src/primitives/PrivateKey.js +25 -16
  224. package/dist/esm/src/primitives/PrivateKey.js.map +1 -1
  225. package/dist/esm/src/primitives/PublicKey.js.map +1 -1
  226. package/dist/esm/src/primitives/Random.js +7 -6
  227. package/dist/esm/src/primitives/Random.js.map +1 -1
  228. package/dist/esm/src/primitives/ReductionContext.js +1 -1
  229. package/dist/esm/src/primitives/ReductionContext.js.map +1 -1
  230. package/dist/esm/src/primitives/Schnorr.js +21 -15
  231. package/dist/esm/src/primitives/Schnorr.js.map +1 -1
  232. package/dist/esm/src/primitives/Signature.js +8 -7
  233. package/dist/esm/src/primitives/Signature.js.map +1 -1
  234. package/dist/esm/src/primitives/SymmetricKey.js +13 -13
  235. package/dist/esm/src/primitives/SymmetricKey.js.map +1 -1
  236. package/dist/esm/src/primitives/TransactionSignature.js +22 -12
  237. package/dist/esm/src/primitives/TransactionSignature.js.map +1 -1
  238. package/dist/esm/src/primitives/utils.js +76 -66
  239. package/dist/esm/src/primitives/utils.js.map +1 -1
  240. package/dist/esm/src/script/OP.js +3 -3
  241. package/dist/esm/src/script/OP.js.map +1 -1
  242. package/dist/esm/src/script/Script.js +12 -10
  243. package/dist/esm/src/script/Script.js.map +1 -1
  244. package/dist/esm/src/script/Spend.js +39 -32
  245. package/dist/esm/src/script/Spend.js.map +1 -1
  246. package/dist/esm/src/script/templates/P2PKH.js +26 -11
  247. package/dist/esm/src/script/templates/P2PKH.js.map +1 -1
  248. package/dist/esm/src/script/templates/PushDrop.js +29 -22
  249. package/dist/esm/src/script/templates/PushDrop.js.map +1 -1
  250. package/dist/esm/src/script/templates/RPuzzle.js +11 -6
  251. package/dist/esm/src/script/templates/RPuzzle.js.map +1 -1
  252. package/dist/esm/src/totp/totp.js +2 -1
  253. package/dist/esm/src/totp/totp.js.map +1 -1
  254. package/dist/esm/src/transaction/Beef.js +176 -154
  255. package/dist/esm/src/transaction/Beef.js.map +1 -1
  256. package/dist/esm/src/transaction/BeefParty.js +24 -24
  257. package/dist/esm/src/transaction/BeefParty.js.map +1 -1
  258. package/dist/esm/src/transaction/BeefTx.js +26 -18
  259. package/dist/esm/src/transaction/BeefTx.js.map +1 -1
  260. package/dist/esm/src/transaction/Broadcaster.js.map +1 -1
  261. package/dist/esm/src/transaction/MerklePath.js +61 -36
  262. package/dist/esm/src/transaction/MerklePath.js.map +1 -1
  263. package/dist/esm/src/transaction/Transaction.js +105 -138
  264. package/dist/esm/src/transaction/Transaction.js.map +1 -1
  265. package/dist/esm/src/transaction/broadcasters/ARC.js +25 -16
  266. package/dist/esm/src/transaction/broadcasters/ARC.js.map +1 -1
  267. package/dist/esm/src/transaction/broadcasters/DefaultBroadcaster.js.map +1 -1
  268. package/dist/esm/src/transaction/broadcasters/WhatsOnChainBroadcaster.js.map +1 -1
  269. package/dist/esm/src/transaction/chaintrackers/WhatsOnChain.js +3 -3
  270. package/dist/esm/src/transaction/chaintrackers/WhatsOnChain.js.map +1 -1
  271. package/dist/esm/src/transaction/fee-models/SatoshisPerKilobyte.js.map +1 -1
  272. package/dist/esm/src/transaction/http/DefaultHttpClient.js +3 -2
  273. package/dist/esm/src/transaction/http/DefaultHttpClient.js.map +1 -1
  274. package/dist/esm/src/transaction/http/FetchHttpClient.js +4 -2
  275. package/dist/esm/src/transaction/http/FetchHttpClient.js.map +1 -1
  276. package/dist/esm/src/transaction/http/NodejsHttpClient.js +5 -3
  277. package/dist/esm/src/transaction/http/NodejsHttpClient.js.map +1 -1
  278. package/dist/esm/src/transaction/http/index.js.map +1 -1
  279. package/dist/esm/src/transaction/index.js.map +1 -1
  280. package/dist/esm/src/wallet/CachedKeyDeriver.js +91 -66
  281. package/dist/esm/src/wallet/CachedKeyDeriver.js.map +1 -1
  282. package/dist/esm/src/wallet/KeyDeriver.js +60 -52
  283. package/dist/esm/src/wallet/KeyDeriver.js.map +1 -1
  284. package/dist/esm/src/wallet/ProtoWallet.js +75 -29
  285. package/dist/esm/src/wallet/ProtoWallet.js.map +1 -1
  286. package/dist/esm/src/wallet/WalletClient.js +7 -2
  287. package/dist/esm/src/wallet/WalletClient.js.map +1 -1
  288. package/dist/esm/src/wallet/WalletError.js +2 -2
  289. package/dist/esm/src/wallet/WalletError.js.map +1 -1
  290. package/dist/esm/src/wallet/substrates/HTTPWalletJSON.js +4 -4
  291. package/dist/esm/src/wallet/substrates/HTTPWalletJSON.js.map +1 -1
  292. package/dist/esm/src/wallet/substrates/HTTPWalletWire.js +2 -2
  293. package/dist/esm/src/wallet/substrates/HTTPWalletWire.js.map +1 -1
  294. package/dist/esm/src/wallet/substrates/WalletWireProcessor.js +1239 -1261
  295. package/dist/esm/src/wallet/substrates/WalletWireProcessor.js.map +1 -1
  296. package/dist/esm/src/wallet/substrates/WalletWireTransceiver.js +95 -43
  297. package/dist/esm/src/wallet/substrates/WalletWireTransceiver.js.map +1 -1
  298. package/dist/esm/src/wallet/substrates/XDM.js +8 -3
  299. package/dist/esm/src/wallet/substrates/XDM.js.map +1 -1
  300. package/dist/esm/src/wallet/substrates/window.CWI.js +28 -28
  301. package/dist/esm/src/wallet/substrates/window.CWI.js.map +1 -1
  302. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  303. package/dist/types/mod.d.ts +15 -15
  304. package/dist/types/src/auth/Peer.d.ts +10 -10
  305. package/dist/types/src/auth/Peer.d.ts.map +1 -1
  306. package/dist/types/src/auth/SessionManager.d.ts +4 -4
  307. package/dist/types/src/auth/SessionManager.d.ts.map +1 -1
  308. package/dist/types/src/auth/certificates/Certificate.d.ts +6 -6
  309. package/dist/types/src/auth/certificates/Certificate.d.ts.map +1 -1
  310. package/dist/types/src/auth/certificates/MasterCertificate.d.ts +5 -5
  311. package/dist/types/src/auth/certificates/MasterCertificate.d.ts.map +1 -1
  312. package/dist/types/src/auth/certificates/VerifiableCertificate.d.ts.map +1 -1
  313. package/dist/types/src/auth/certificates/__tests/CompletedProtoWallet.d.ts +23 -22
  314. package/dist/types/src/auth/certificates/__tests/CompletedProtoWallet.d.ts.map +1 -1
  315. package/dist/types/src/auth/clients/AuthFetch.d.ts.map +1 -1
  316. package/dist/types/src/auth/transports/SimplifiedFetchTransport.d.ts +1 -1
  317. package/dist/types/src/auth/transports/SimplifiedFetchTransport.d.ts.map +1 -1
  318. package/dist/types/src/auth/utils/createNonce.d.ts.map +1 -1
  319. package/dist/types/src/auth/utils/getVerifiableCertificates.d.ts +3 -3
  320. package/dist/types/src/auth/utils/getVerifiableCertificates.d.ts.map +1 -1
  321. package/dist/types/src/auth/utils/validateCertificates.d.ts +2 -2
  322. package/dist/types/src/auth/utils/validateCertificates.d.ts.map +1 -1
  323. package/dist/types/src/auth/utils/verifyNonce.d.ts +1 -1
  324. package/dist/types/src/auth/utils/verifyNonce.d.ts.map +1 -1
  325. package/dist/types/src/compat/BSM.d.ts +1 -1
  326. package/dist/types/src/compat/BSM.d.ts.map +1 -1
  327. package/dist/types/src/compat/ECIES.d.ts +36 -36
  328. package/dist/types/src/compat/ECIES.d.ts.map +1 -1
  329. package/dist/types/src/compat/HD.d.ts +51 -51
  330. package/dist/types/src/compat/HD.d.ts.map +1 -1
  331. package/dist/types/src/compat/Mnemonic.d.ts +79 -79
  332. package/dist/types/src/compat/Mnemonic.d.ts.map +1 -1
  333. package/dist/types/src/compat/Utxo.d.ts.map +1 -1
  334. package/dist/types/src/messages/EncryptedMessage.d.ts.map +1 -1
  335. package/dist/types/src/messages/SignedMessage.d.ts.map +1 -1
  336. package/dist/types/src/overlay-tools/LookupResolver.d.ts +9 -9
  337. package/dist/types/src/overlay-tools/LookupResolver.d.ts.map +1 -1
  338. package/dist/types/src/overlay-tools/OverlayAdminTokenTemplate.d.ts +17 -17
  339. package/dist/types/src/overlay-tools/OverlayAdminTokenTemplate.d.ts.map +1 -1
  340. package/dist/types/src/overlay-tools/SHIPBroadcaster.d.ts +14 -14
  341. package/dist/types/src/overlay-tools/SHIPBroadcaster.d.ts.map +1 -1
  342. package/dist/types/src/primitives/AESGCM.d.ts.map +1 -1
  343. package/dist/types/src/primitives/BasePoint.d.ts +8 -8
  344. package/dist/types/src/primitives/BasePoint.d.ts.map +1 -1
  345. package/dist/types/src/primitives/BigNumber.d.ts.map +1 -1
  346. package/dist/types/src/primitives/Curve.d.ts +14 -7
  347. package/dist/types/src/primitives/Curve.d.ts.map +1 -1
  348. package/dist/types/src/primitives/DRBG.d.ts.map +1 -1
  349. package/dist/types/src/primitives/ECDSA.d.ts +1 -1
  350. package/dist/types/src/primitives/ECDSA.d.ts.map +1 -1
  351. package/dist/types/src/primitives/Hash.d.ts +11 -11
  352. package/dist/types/src/primitives/Hash.d.ts.map +1 -1
  353. package/dist/types/src/primitives/JacobianPoint.d.ts.map +1 -1
  354. package/dist/types/src/primitives/Point.d.ts +14 -10
  355. package/dist/types/src/primitives/Point.d.ts.map +1 -1
  356. package/dist/types/src/primitives/Polynomial.d.ts.map +1 -1
  357. package/dist/types/src/primitives/PrivateKey.d.ts +2 -2
  358. package/dist/types/src/primitives/PrivateKey.d.ts.map +1 -1
  359. package/dist/types/src/primitives/PublicKey.d.ts.map +1 -1
  360. package/dist/types/src/primitives/Random.d.ts.map +1 -1
  361. package/dist/types/src/primitives/Schnorr.d.ts +14 -14
  362. package/dist/types/src/primitives/Schnorr.d.ts.map +1 -1
  363. package/dist/types/src/primitives/Signature.d.ts +1 -1
  364. package/dist/types/src/primitives/Signature.d.ts.map +1 -1
  365. package/dist/types/src/primitives/SymmetricKey.d.ts +13 -13
  366. package/dist/types/src/primitives/SymmetricKey.d.ts.map +1 -1
  367. package/dist/types/src/primitives/TransactionSignature.d.ts +4 -4
  368. package/dist/types/src/primitives/TransactionSignature.d.ts.map +1 -1
  369. package/dist/types/src/primitives/utils.d.ts +3 -6
  370. package/dist/types/src/primitives/utils.d.ts.map +1 -1
  371. package/dist/types/src/script/Script.d.ts +3 -3
  372. package/dist/types/src/script/Script.d.ts.map +1 -1
  373. package/dist/types/src/script/ScriptTemplate.d.ts +2 -2
  374. package/dist/types/src/script/ScriptTemplate.d.ts.map +1 -1
  375. package/dist/types/src/script/Spend.d.ts.map +1 -1
  376. package/dist/types/src/script/templates/P2PKH.d.ts.map +1 -1
  377. package/dist/types/src/script/templates/PushDrop.d.ts +1 -2
  378. package/dist/types/src/script/templates/PushDrop.d.ts.map +1 -1
  379. package/dist/types/src/script/templates/RPuzzle.d.ts.map +1 -1
  380. package/dist/types/src/totp/totp.d.ts.map +1 -1
  381. package/dist/types/src/transaction/Beef.d.ts +96 -96
  382. package/dist/types/src/transaction/Beef.d.ts.map +1 -1
  383. package/dist/types/src/transaction/BeefParty.d.ts +22 -22
  384. package/dist/types/src/transaction/BeefParty.d.ts.map +1 -1
  385. package/dist/types/src/transaction/BeefTx.d.ts +5 -5
  386. package/dist/types/src/transaction/BeefTx.d.ts.map +1 -1
  387. package/dist/types/src/transaction/Broadcaster.d.ts.map +1 -1
  388. package/dist/types/src/transaction/ChainTracker.d.ts +2 -2
  389. package/dist/types/src/transaction/FeeModel.d.ts.map +1 -1
  390. package/dist/types/src/transaction/MerklePath.d.ts.map +1 -1
  391. package/dist/types/src/transaction/Transaction.d.ts +4 -12
  392. package/dist/types/src/transaction/Transaction.d.ts.map +1 -1
  393. package/dist/types/src/transaction/TransactionOutput.d.ts.map +1 -1
  394. package/dist/types/src/transaction/broadcasters/ARC.d.ts +1 -1
  395. package/dist/types/src/transaction/broadcasters/ARC.d.ts.map +1 -1
  396. package/dist/types/src/transaction/broadcasters/DefaultBroadcaster.d.ts.map +1 -1
  397. package/dist/types/src/transaction/broadcasters/WhatsOnChainBroadcaster.d.ts.map +1 -1
  398. package/dist/types/src/transaction/chaintrackers/DefaultChainTracker.d.ts.map +1 -1
  399. package/dist/types/src/transaction/chaintrackers/WhatsOnChain.d.ts.map +1 -1
  400. package/dist/types/src/transaction/fee-models/SatoshisPerKilobyte.d.ts.map +1 -1
  401. package/dist/types/src/transaction/http/DefaultHttpClient.d.ts +1 -1
  402. package/dist/types/src/transaction/http/DefaultHttpClient.d.ts.map +1 -1
  403. package/dist/types/src/transaction/http/FetchHttpClient.d.ts +5 -5
  404. package/dist/types/src/transaction/http/FetchHttpClient.d.ts.map +1 -1
  405. package/dist/types/src/transaction/http/HttpClient.d.ts +4 -4
  406. package/dist/types/src/transaction/http/HttpClient.d.ts.map +1 -1
  407. package/dist/types/src/transaction/http/NodejsHttpClient.d.ts +3 -3
  408. package/dist/types/src/transaction/http/NodejsHttpClient.d.ts.map +1 -1
  409. package/dist/types/src/transaction/http/index.d.ts.map +1 -1
  410. package/dist/types/src/transaction/index.d.ts.map +1 -1
  411. package/dist/types/src/wallet/CachedKeyDeriver.d.ts +58 -58
  412. package/dist/types/src/wallet/CachedKeyDeriver.d.ts.map +1 -1
  413. package/dist/types/src/wallet/KeyDeriver.d.ts +78 -78
  414. package/dist/types/src/wallet/KeyDeriver.d.ts.map +1 -1
  415. package/dist/types/src/wallet/ProtoWallet.d.ts +10 -10
  416. package/dist/types/src/wallet/ProtoWallet.d.ts.map +1 -1
  417. package/dist/types/src/wallet/Wallet.interfaces.d.ts +151 -152
  418. package/dist/types/src/wallet/Wallet.interfaces.d.ts.map +1 -1
  419. package/dist/types/src/wallet/WalletClient.d.ts +5 -5
  420. package/dist/types/src/wallet/WalletClient.d.ts.map +1 -1
  421. package/dist/types/src/wallet/substrates/HTTPWalletJSON.d.ts +6 -6
  422. package/dist/types/src/wallet/substrates/HTTPWalletJSON.d.ts.map +1 -1
  423. package/dist/types/src/wallet/substrates/HTTPWalletWire.d.ts.map +1 -1
  424. package/dist/types/src/wallet/substrates/WalletWireProcessor.d.ts.map +1 -1
  425. package/dist/types/src/wallet/substrates/WalletWireTransceiver.d.ts.map +1 -1
  426. package/dist/types/src/wallet/substrates/XDM.d.ts +1 -1
  427. package/dist/types/src/wallet/substrates/XDM.d.ts.map +1 -1
  428. package/dist/types/src/wallet/substrates/window.CWI.d.ts +6 -6
  429. package/dist/types/src/wallet/substrates/window.CWI.d.ts.map +1 -1
  430. package/dist/types/tsconfig.types.tsbuildinfo +1 -1
  431. package/dist/umd/bundle.js +1 -1
  432. package/docs/auth.md +92 -82
  433. package/docs/compat.md +24 -24
  434. package/docs/messages.md +7 -5
  435. package/docs/overlay-tools.md +21 -21
  436. package/docs/primitives.md +336 -315
  437. package/docs/script.md +35 -35
  438. package/docs/swagger/dist/swagger-initializer.js +7 -7
  439. package/docs/swagger/dist/swagger-ui-bundle.js +1 -1
  440. package/docs/swagger/dist/swagger-ui-es-bundle-core.js +2 -2
  441. package/docs/swagger/dist/swagger-ui-es-bundle.js +1 -1
  442. package/docs/swagger/dist/swagger-ui-standalone-preset.js +1 -1
  443. package/docs/swagger/dist/swagger-ui.js +2 -2
  444. package/docs/totp.md +5 -5
  445. package/docs/transaction.md +103 -105
  446. package/docs/wallet-substrates.md +17 -17
  447. package/docs/wallet.md +202 -204
  448. package/mod.ts +15 -15
  449. package/package.json +15 -3
  450. package/src/auth/Peer.ts +271 -121
  451. package/src/auth/SessionManager.ts +17 -10
  452. package/src/auth/__tests/Peer.test.ts +361 -179
  453. package/src/auth/__tests/SessionManager.test.ts +67 -19
  454. package/src/auth/__tests/build.test.ts +11 -0
  455. package/src/auth/certificates/Certificate.ts +27 -14
  456. package/src/auth/certificates/MasterCertificate.ts +106 -62
  457. package/src/auth/certificates/VerifiableCertificate.ts +30 -8
  458. package/src/auth/certificates/__tests/Certificate.test.ts +32 -17
  459. package/src/auth/certificates/__tests/CompletedProtoWallet.ts +171 -68
  460. package/src/auth/certificates/__tests/MasterCertificate.test.ts +63 -47
  461. package/src/auth/certificates/__tests/VerifiableCertificate.test.ts +42 -31
  462. package/src/auth/certificates/index.ts +1 -1
  463. package/src/auth/clients/AuthFetch.ts +1 -0
  464. package/src/auth/clients/index.ts +1 -1
  465. package/src/auth/transports/SimplifiedFetchTransport.ts +145 -72
  466. package/src/auth/transports/index.ts +1 -1
  467. package/src/auth/utils/__tests/cryptononce.test.ts +52 -23
  468. package/src/auth/utils/__tests/getVerifiableCertificates.test.ts +56 -30
  469. package/src/auth/utils/__tests/validateCertificates.test.ts +53 -31
  470. package/src/auth/utils/createNonce.ts +11 -3
  471. package/src/auth/utils/getVerifiableCertificates.ts +12 -7
  472. package/src/auth/utils/validateCertificates.ts +57 -39
  473. package/src/auth/utils/verifyNonce.ts +6 -2
  474. package/src/compat/BSM.ts +10 -2
  475. package/src/compat/ECIES.ts +265 -141
  476. package/src/compat/HD.ts +81 -63
  477. package/src/compat/Mnemonic.ts +104 -91
  478. package/src/compat/Utxo.ts +8 -5
  479. package/src/compat/__tests/BSM.test.ts +42 -16
  480. package/src/compat/__tests/ECIES.test.ts +117 -52
  481. package/src/compat/__tests/HD.test.ts +55 -42
  482. package/src/compat/__tests/Mnemonic.test.ts +11 -12
  483. package/src/compat/__tests/Mnemonic.vectors.ts +110 -55
  484. package/src/messages/EncryptedMessage.ts +6 -2
  485. package/src/messages/SignedMessage.ts +14 -8
  486. package/src/messages/__tests/EncryptedMessage.test.ts +23 -24
  487. package/src/messages/__tests/SignedMessage.test.ts +17 -11
  488. package/src/overlay-tools/LookupResolver.ts +108 -56
  489. package/src/overlay-tools/OverlayAdminTokenTemplate.ts +52 -23
  490. package/src/overlay-tools/SHIPBroadcaster.ts +135 -59
  491. package/src/overlay-tools/__tests/LookupResolver.test.ts +723 -323
  492. package/src/overlay-tools/__tests/OverlayAdminTokenTemplate.test.ts +50 -22
  493. package/src/overlay-tools/__tests/SHIPBroadcaster.test.ts +607 -290
  494. package/src/primitives/AESGCM.ts +2 -0
  495. package/src/primitives/BasePoint.ts +4 -4
  496. package/src/primitives/BigNumber.ts +99 -90
  497. package/src/primitives/Curve.ts +117 -46
  498. package/src/primitives/DRBG.ts +9 -11
  499. package/src/primitives/ECDSA.ts +109 -63
  500. package/src/primitives/Hash.ts +492 -321
  501. package/src/primitives/JacobianPoint.ts +67 -19
  502. package/src/primitives/Point.ts +254 -152
  503. package/src/primitives/Polynomial.ts +8 -3
  504. package/src/primitives/PrivateKey.ts +41 -17
  505. package/src/primitives/PublicKey.ts +13 -3
  506. package/src/primitives/Random.ts +14 -8
  507. package/src/primitives/ReductionContext.ts +1 -1
  508. package/src/primitives/Schnorr.ts +40 -18
  509. package/src/primitives/Signature.ts +26 -16
  510. package/src/primitives/SymmetricKey.ts +14 -14
  511. package/src/primitives/TransactionSignature.ts +41 -17
  512. package/src/primitives/__tests/AESGCM.test.ts +457 -151
  513. package/src/primitives/__tests/BRC42.private.vectors.ts +30 -15
  514. package/src/primitives/__tests/BRC42.public.vectors.ts +30 -15
  515. package/src/primitives/__tests/BigNumber.arithmatic.test.ts +344 -125
  516. package/src/primitives/__tests/BigNumber.binary.test.ts +148 -67
  517. package/src/primitives/__tests/BigNumber.constructor.test.ts +65 -25
  518. package/src/primitives/__tests/BigNumber.dhGroup.test.ts +15 -11
  519. package/src/primitives/__tests/BigNumber.fixtures.ts +16 -8
  520. package/src/primitives/__tests/BigNumber.serializers.test.ts +41 -15
  521. package/src/primitives/__tests/BigNumber.utils.test.ts +132 -42
  522. package/src/primitives/__tests/Curve.unit.test.ts +75 -53
  523. package/src/primitives/__tests/DRBG.test.ts +1 -1
  524. package/src/primitives/__tests/DRBG.vectors.ts +45 -75
  525. package/src/primitives/__tests/ECDH.test.ts +15 -8
  526. package/src/primitives/__tests/ECDSA.test.ts +12 -6
  527. package/src/primitives/__tests/HMAC.test.ts +24 -18
  528. package/src/primitives/__tests/Hash.test.ts +57 -46
  529. package/src/primitives/__tests/PBKDF2.vectors.ts +130 -117
  530. package/src/primitives/__tests/PrivateKey.split.test.ts +33 -11
  531. package/src/primitives/__tests/PrivateKey.test.ts +11 -10
  532. package/src/primitives/__tests/PublicKey.test.ts +64 -53
  533. package/src/primitives/__tests/Random.test.ts +1 -1
  534. package/src/primitives/__tests/Reader.test.ts +240 -219
  535. package/src/primitives/__tests/ReductionContext.test.ts +98 -61
  536. package/src/primitives/__tests/Schnorr.test.ts +249 -237
  537. package/src/primitives/__tests/SymmetricKey.test.ts +18 -15
  538. package/src/primitives/__tests/SymmetricKey.vectors.ts +16 -8
  539. package/src/primitives/__tests/Writer.test.ts +23 -13
  540. package/src/primitives/__tests/bug-31.test.ts +6 -10
  541. package/src/primitives/__tests/utils.test.ts +70 -19
  542. package/src/primitives/utils.ts +103 -79
  543. package/src/script/Script.ts +18 -12
  544. package/src/script/ScriptTemplate.ts +3 -5
  545. package/src/script/Spend.ts +306 -108
  546. package/src/script/__tests/Script.test.ts +73 -55
  547. package/src/script/__tests/Spend.test.ts +208 -83
  548. package/src/script/__tests/SpendComplex.test.ts +19 -13
  549. package/src/script/__tests/script.invalid.vectors.ts +428 -1796
  550. package/src/script/__tests/script.valid.vectors.ts +728 -2764
  551. package/src/script/templates/P2PKH.ts +34 -12
  552. package/src/script/templates/PushDrop.ts +65 -31
  553. package/src/script/templates/RPuzzle.ts +29 -8
  554. package/src/script/templates/__tests/PushDrop.test.ts +146 -41
  555. package/src/totp/__tests/totp.test.ts +45 -44
  556. package/src/totp/totp.ts +3 -2
  557. package/src/transaction/Beef.ts +269 -174
  558. package/src/transaction/BeefParty.ts +41 -31
  559. package/src/transaction/BeefTx.ts +36 -26
  560. package/src/transaction/Broadcaster.ts +10 -6
  561. package/src/transaction/ChainTracker.ts +2 -2
  562. package/src/transaction/FeeModel.ts +0 -1
  563. package/src/transaction/MerklePath.ts +124 -59
  564. package/src/transaction/Transaction.ts +188 -187
  565. package/src/transaction/TransactionOutput.ts +0 -1
  566. package/src/transaction/__tests/Beef.test.ts +390 -287
  567. package/src/transaction/__tests/MerklePath.test.ts +59 -26
  568. package/src/transaction/__tests/Transaction.benchmarks.test.ts +231 -201
  569. package/src/transaction/__tests/Transaction.test.ts +758 -482
  570. package/src/transaction/__tests/bigtx.vectors.ts +2 -1
  571. package/src/transaction/__tests/bump.invalid.vectors.ts +24 -6
  572. package/src/transaction/__tests/bump.valid.vectors.ts +6 -2
  573. package/src/transaction/__tests/tx.invalid.vectors.ts +881 -185
  574. package/src/transaction/__tests/tx.valid.vectors.ts +1210 -257
  575. package/src/transaction/broadcasters/ARC.ts +69 -38
  576. package/src/transaction/broadcasters/DefaultBroadcaster.ts +9 -3
  577. package/src/transaction/broadcasters/WhatsOnChainBroadcaster.ts +20 -7
  578. package/src/transaction/broadcasters/__tests/ARC.test.ts +127 -59
  579. package/src/transaction/broadcasters/__tests/WhatsOnChainBroadcaster.test.ts +27 -18
  580. package/src/transaction/chaintrackers/DefaultChainTracker.ts +1 -1
  581. package/src/transaction/chaintrackers/WhatsOnChain.ts +27 -11
  582. package/src/transaction/chaintrackers/__tests/WhatsOnChainChainTracker.test.ts +59 -23
  583. package/src/transaction/fee-models/SatoshisPerKilobyte.ts +9 -5
  584. package/src/transaction/http/DefaultHttpClient.ts +5 -4
  585. package/src/transaction/http/FetchHttpClient.ts +18 -9
  586. package/src/transaction/http/HttpClient.ts +27 -22
  587. package/src/transaction/http/NodejsHttpClient.ts +23 -9
  588. package/src/transaction/http/index.ts +5 -1
  589. package/src/transaction/index.ts +5 -1
  590. package/src/wallet/CachedKeyDeriver.ts +151 -82
  591. package/src/wallet/KeyDeriver.ts +186 -105
  592. package/src/wallet/ProtoWallet.ts +121 -52
  593. package/src/wallet/Wallet.interfaces.ts +167 -156
  594. package/src/wallet/WalletClient.ts +314 -59
  595. package/src/wallet/WalletError.ts +2 -2
  596. package/src/wallet/__tests/CachedKeyDeriver.test.ts +86 -27
  597. package/src/wallet/__tests/KeyDeriver.test.ts +136 -33
  598. package/src/wallet/__tests/ProtoWallet.test.ts +190 -102
  599. package/src/wallet/substrates/HTTPWalletJSON.ts +250 -67
  600. package/src/wallet/substrates/HTTPWalletWire.ts +7 -3
  601. package/src/wallet/substrates/WalletWireCalls.ts +2 -2
  602. package/src/wallet/substrates/WalletWireProcessor.ts +1412 -1277
  603. package/src/wallet/substrates/WalletWireTransceiver.ts +713 -138
  604. package/src/wallet/substrates/XDM.ts +425 -36
  605. package/src/wallet/substrates/__tests/WalletWire.integration.test.ts +488 -225
  606. package/src/wallet/substrates/__tests/XDM.test.ts +232 -234
  607. package/src/wallet/substrates/window.CWI.ts +520 -61
@@ -33,7 +33,7 @@ class WalletWireProcessor {
33
33
  const callCode = messageReader.readUInt8();
34
34
  // Map call code to call name
35
35
  const callName = WalletWireCalls_js_1.default[callCode]; // calls is enum
36
- if (!callName) {
36
+ if (callName === undefined || callName === '') {
37
37
  // Invalid call code
38
38
  throw new Error(`Invalid call code: ${callCode}`);
39
39
  }
@@ -44,7 +44,7 @@ class WalletWireProcessor {
44
44
  // Read parameters
45
45
  const paramsReader = messageReader; // Remaining bytes
46
46
  switch (callName) {
47
- case 'createAction':
47
+ case 'createAction': {
48
48
  // Deserialize parameters from paramsReader
49
49
  const args = {};
50
50
  // Read description
@@ -198,7 +198,8 @@ class WalletWireProcessor {
198
198
  args.options.acceptDelayedBroadcast = undefined;
199
199
  }
200
200
  else {
201
- args.options.acceptDelayedBroadcast = acceptDelayedBroadcastFlag === 1;
201
+ args.options.acceptDelayedBroadcast =
202
+ acceptDelayedBroadcastFlag === 1;
202
203
  }
203
204
  // trustSelf
204
205
  const trustSelfFlag = paramsReader.readInt8();
@@ -279,7 +280,7 @@ class WalletWireProcessor {
279
280
  // Serialize the result
280
281
  const resultWriter = new index_js_1.Utils.Writer();
281
282
  // txid
282
- if (createActionResult.txid) {
283
+ if (createActionResult.txid != null && createActionResult.txid !== '') {
283
284
  resultWriter.writeInt8(1);
284
285
  resultWriter.write(index_js_1.Utils.toArray(createActionResult.txid, 'hex'));
285
286
  }
@@ -287,7 +288,7 @@ class WalletWireProcessor {
287
288
  resultWriter.writeInt8(0);
288
289
  }
289
290
  // tx
290
- if (createActionResult.tx) {
291
+ if (createActionResult.tx != null) {
291
292
  resultWriter.writeInt8(1);
292
293
  resultWriter.writeVarIntNum(createActionResult.tx.length);
293
294
  resultWriter.write(createActionResult.tx);
@@ -296,7 +297,7 @@ class WalletWireProcessor {
296
297
  resultWriter.writeInt8(0);
297
298
  }
298
299
  // noSendChange
299
- if (createActionResult.noSendChange) {
300
+ if (createActionResult.noSendChange != null) {
300
301
  resultWriter.writeVarIntNum(createActionResult.noSendChange.length);
301
302
  for (const outpoint of createActionResult.noSendChange) {
302
303
  resultWriter.write(this.encodeOutpoint(outpoint));
@@ -306,7 +307,7 @@ class WalletWireProcessor {
306
307
  resultWriter.writeVarIntNum(-1);
307
308
  }
308
309
  // sendWithResults
309
- if (createActionResult.sendWithResults) {
310
+ if (createActionResult.sendWithResults != null) {
310
311
  resultWriter.writeVarIntNum(createActionResult.sendWithResults.length);
311
312
  for (const result of createActionResult.sendWithResults) {
312
313
  resultWriter.write(index_js_1.Utils.toArray(result.txid, 'hex'));
@@ -324,7 +325,7 @@ class WalletWireProcessor {
324
325
  resultWriter.writeVarIntNum(-1);
325
326
  }
326
327
  // signableTransaction
327
- if (createActionResult.signableTransaction) {
328
+ if (createActionResult.signableTransaction != null) {
328
329
  resultWriter.writeInt8(1);
329
330
  resultWriter.writeVarIntNum(createActionResult.signableTransaction.tx.length);
330
331
  resultWriter.write(createActionResult.signableTransaction.tx);
@@ -340,923 +341,632 @@ class WalletWireProcessor {
340
341
  responseWriter.writeUInt8(0); // errorByte = 0
341
342
  responseWriter.write(resultWriter.toArray());
342
343
  return responseWriter.toArray();
343
- case 'signAction':
344
- {
345
- const args = {};
346
- // Deserialize spends
347
- const spendCount = paramsReader.readVarIntNum();
348
- args.spends = {};
349
- for (let i = 0; i < spendCount; i++) {
350
- const inputIndex = paramsReader.readVarIntNum();
351
- const spend = {};
352
- // unlockingScript
353
- const unlockingScriptLength = paramsReader.readVarIntNum();
354
- const unlockingScriptBytes = paramsReader.read(unlockingScriptLength);
355
- spend.unlockingScript = index_js_1.Utils.toHex(unlockingScriptBytes);
356
- // sequenceNumber
357
- const sequenceNumber = paramsReader.readVarIntNum();
358
- if (sequenceNumber >= 0) {
359
- spend.sequenceNumber = sequenceNumber;
360
- }
361
- else {
362
- spend.sequenceNumber = undefined;
363
- }
364
- args.spends[inputIndex] = spend;
365
- }
366
- // Deserialize reference
367
- const referenceLength = paramsReader.readVarIntNum();
368
- const referenceBytes = paramsReader.read(referenceLength);
369
- args.reference = index_js_1.Utils.toBase64(referenceBytes);
370
- // Deserialize options
371
- const optionsPresent = paramsReader.readInt8();
372
- if (optionsPresent === 1) {
373
- args.options = {};
374
- // acceptDelayedBroadcast
375
- const acceptDelayedBroadcastFlag = paramsReader.readInt8();
376
- if (acceptDelayedBroadcastFlag === -1) {
377
- args.options.acceptDelayedBroadcast = undefined;
378
- }
379
- else {
380
- args.options.acceptDelayedBroadcast = acceptDelayedBroadcastFlag === 1;
381
- }
382
- // returnTXIDOnly
383
- const returnTXIDOnlyFlag = paramsReader.readInt8();
384
- if (returnTXIDOnlyFlag === -1) {
385
- args.options.returnTXIDOnly = undefined;
386
- }
387
- else {
388
- args.options.returnTXIDOnly = returnTXIDOnlyFlag === 1;
389
- }
390
- // noSend
391
- const noSendFlag = paramsReader.readInt8();
392
- if (noSendFlag === -1) {
393
- args.options.noSend = undefined;
394
- }
395
- else {
396
- args.options.noSend = noSendFlag === 1;
397
- }
398
- // sendWith
399
- const sendWithLength = paramsReader.readVarIntNum();
400
- if (sendWithLength >= 0) {
401
- args.options.sendWith = [];
402
- for (let i = 0; i < sendWithLength; i++) {
403
- const txidBytes = paramsReader.read(32);
404
- const txid = index_js_1.Utils.toHex(txidBytes);
405
- args.options.sendWith.push(txid);
406
- }
407
- }
408
- else {
409
- args.options.sendWith = undefined;
410
- }
344
+ }
345
+ case 'signAction': {
346
+ const args = {};
347
+ // Deserialize spends
348
+ const spendCount = paramsReader.readVarIntNum();
349
+ args.spends = {};
350
+ for (let i = 0; i < spendCount; i++) {
351
+ const inputIndex = paramsReader.readVarIntNum();
352
+ const spend = {};
353
+ // unlockingScript
354
+ const unlockingScriptLength = paramsReader.readVarIntNum();
355
+ const unlockingScriptBytes = paramsReader.read(unlockingScriptLength);
356
+ spend.unlockingScript = index_js_1.Utils.toHex(unlockingScriptBytes);
357
+ // sequenceNumber
358
+ const sequenceNumber = paramsReader.readVarIntNum();
359
+ if (sequenceNumber >= 0) {
360
+ spend.sequenceNumber = sequenceNumber;
411
361
  }
412
362
  else {
413
- args.options = undefined;
363
+ spend.sequenceNumber = undefined;
414
364
  }
415
- // Call the method
416
- const signActionResult = await this.wallet.signAction(args, originator);
417
- // Serialize the result
418
- const resultWriter = new index_js_1.Utils.Writer();
419
- // txid
420
- if (signActionResult.txid) {
421
- resultWriter.writeInt8(1);
422
- resultWriter.write(index_js_1.Utils.toArray(signActionResult.txid, 'hex'));
365
+ args.spends[inputIndex] = spend;
366
+ }
367
+ // Deserialize reference
368
+ const referenceLength = paramsReader.readVarIntNum();
369
+ const referenceBytes = paramsReader.read(referenceLength);
370
+ args.reference = index_js_1.Utils.toBase64(referenceBytes);
371
+ // Deserialize options
372
+ const optionsPresent = paramsReader.readInt8();
373
+ if (optionsPresent === 1) {
374
+ args.options = {};
375
+ // acceptDelayedBroadcast
376
+ const acceptDelayedBroadcastFlag = paramsReader.readInt8();
377
+ if (acceptDelayedBroadcastFlag === -1) {
378
+ args.options.acceptDelayedBroadcast = undefined;
423
379
  }
424
380
  else {
425
- resultWriter.writeInt8(0);
381
+ args.options.acceptDelayedBroadcast =
382
+ acceptDelayedBroadcastFlag === 1;
426
383
  }
427
- // tx
428
- if (signActionResult.tx) {
429
- resultWriter.writeInt8(1);
430
- resultWriter.writeVarIntNum(signActionResult.tx.length);
431
- resultWriter.write(signActionResult.tx);
384
+ // returnTXIDOnly
385
+ const returnTXIDOnlyFlag = paramsReader.readInt8();
386
+ if (returnTXIDOnlyFlag === -1) {
387
+ args.options.returnTXIDOnly = undefined;
432
388
  }
433
389
  else {
434
- resultWriter.writeInt8(0);
435
- }
436
- // sendWithResults
437
- if (signActionResult.sendWithResults) {
438
- resultWriter.writeVarIntNum(signActionResult.sendWithResults.length);
439
- for (const result of signActionResult.sendWithResults) {
440
- resultWriter.write(index_js_1.Utils.toArray(result.txid, 'hex'));
441
- let statusCode;
442
- if (result.status === 'unproven')
443
- statusCode = 1;
444
- else if (result.status === 'sending')
445
- statusCode = 2;
446
- else if (result.status === 'failed')
447
- statusCode = 3;
448
- resultWriter.writeInt8(statusCode);
449
- }
390
+ args.options.returnTXIDOnly = returnTXIDOnlyFlag === 1;
391
+ }
392
+ // noSend
393
+ const noSendFlag = paramsReader.readInt8();
394
+ if (noSendFlag === -1) {
395
+ args.options.noSend = undefined;
450
396
  }
451
397
  else {
452
- resultWriter.writeVarIntNum(-1);
398
+ args.options.noSend = noSendFlag === 1;
453
399
  }
454
- // Return success code and result
455
- const responseWriter = new index_js_1.Utils.Writer();
456
- responseWriter.writeUInt8(0); // errorByte = 0
457
- responseWriter.write(resultWriter.toArray());
458
- return responseWriter.toArray();
459
- }
460
- case 'abortAction':
461
- {
462
- // Deserialize reference
463
- const referenceBytes = paramsReader.read();
464
- const reference = index_js_1.Utils.toBase64(referenceBytes);
465
- // Call the method
466
- await this.wallet.abortAction({ reference }, originator);
467
- // Return success code and result
468
- const responseWriter = new index_js_1.Utils.Writer();
469
- responseWriter.writeUInt8(0); // errorByte = 0
470
- return responseWriter.toArray();
471
- }
472
- case 'listActions':
473
- {
474
- const args = {};
475
- // Deserialize labels
476
- const labelsLength = paramsReader.readVarIntNum();
477
- args.labels = [];
478
- for (let i = 0; i < labelsLength; i++) {
479
- const labelLength = paramsReader.readVarIntNum();
480
- const labelBytes = paramsReader.read(labelLength);
481
- args.labels.push(index_js_1.Utils.toUTF8(labelBytes));
482
- }
483
- // Deserialize labelQueryMode
484
- const labelQueryModeFlag = paramsReader.readInt8();
485
- if (labelQueryModeFlag === -1) {
486
- args.labelQueryMode = undefined;
487
- }
488
- else if (labelQueryModeFlag === 1) {
489
- args.labelQueryMode = 'any';
490
- }
491
- else if (labelQueryModeFlag === 2) {
492
- args.labelQueryMode = 'all';
493
- }
494
- // Deserialize include options
495
- const includeOptionsNames = [
496
- 'includeLabels',
497
- 'includeInputs',
498
- 'includeInputSourceLockingScripts',
499
- 'includeInputUnlockingScripts',
500
- 'includeOutputs',
501
- 'includeOutputLockingScripts'
502
- ];
503
- for (const optionName of includeOptionsNames) {
504
- const optionFlag = paramsReader.readInt8();
505
- if (optionFlag === -1) {
506
- args[optionName] = undefined;
507
- }
508
- else {
509
- args[optionName] = optionFlag === 1;
400
+ // sendWith
401
+ const sendWithLength = paramsReader.readVarIntNum();
402
+ if (sendWithLength >= 0) {
403
+ args.options.sendWith = [];
404
+ for (let i = 0; i < sendWithLength; i++) {
405
+ const txidBytes = paramsReader.read(32);
406
+ const txid = index_js_1.Utils.toHex(txidBytes);
407
+ args.options.sendWith.push(txid);
510
408
  }
511
409
  }
512
- // Deserialize limit
513
- const limit = paramsReader.readVarIntNum();
514
- if (limit >= 0) {
515
- args.limit = limit;
516
- }
517
410
  else {
518
- args.limit = undefined;
411
+ args.options.sendWith = undefined;
412
+ }
413
+ }
414
+ else {
415
+ args.options = undefined;
416
+ }
417
+ // Call the method
418
+ const signActionResult = await this.wallet.signAction(args, originator);
419
+ // Serialize the result
420
+ const resultWriter = new index_js_1.Utils.Writer();
421
+ // txid
422
+ if (signActionResult.txid != null && signActionResult.txid !== '') {
423
+ resultWriter.writeInt8(1);
424
+ resultWriter.write(index_js_1.Utils.toArray(signActionResult.txid, 'hex'));
425
+ }
426
+ else {
427
+ resultWriter.writeInt8(0);
428
+ }
429
+ // tx
430
+ if (signActionResult.tx != null) {
431
+ resultWriter.writeInt8(1);
432
+ resultWriter.writeVarIntNum(signActionResult.tx.length);
433
+ resultWriter.write(signActionResult.tx);
434
+ }
435
+ else {
436
+ resultWriter.writeInt8(0);
437
+ }
438
+ // sendWithResults
439
+ if (signActionResult.sendWithResults != null) {
440
+ resultWriter.writeVarIntNum(signActionResult.sendWithResults.length);
441
+ for (const result of signActionResult.sendWithResults) {
442
+ resultWriter.write(index_js_1.Utils.toArray(result.txid, 'hex'));
443
+ let statusCode;
444
+ if (result.status === 'unproven')
445
+ statusCode = 1;
446
+ else if (result.status === 'sending')
447
+ statusCode = 2;
448
+ else if (result.status === 'failed')
449
+ statusCode = 3;
450
+ resultWriter.writeInt8(statusCode);
519
451
  }
520
- // Deserialize offset
521
- const offset = paramsReader.readVarIntNum();
522
- if (offset >= 0) {
523
- args.offset = offset;
452
+ }
453
+ else {
454
+ resultWriter.writeVarIntNum(-1);
455
+ }
456
+ // Return success code and result
457
+ const responseWriter = new index_js_1.Utils.Writer();
458
+ responseWriter.writeUInt8(0); // errorByte = 0
459
+ responseWriter.write(resultWriter.toArray());
460
+ return responseWriter.toArray();
461
+ }
462
+ case 'abortAction': {
463
+ // Deserialize reference
464
+ const referenceBytes = paramsReader.read();
465
+ const reference = index_js_1.Utils.toBase64(referenceBytes);
466
+ // Call the method
467
+ await this.wallet.abortAction({ reference }, originator);
468
+ // Return success code and result
469
+ const responseWriter = new index_js_1.Utils.Writer();
470
+ responseWriter.writeUInt8(0); // errorByte = 0
471
+ return responseWriter.toArray();
472
+ }
473
+ case 'listActions': {
474
+ const args = {};
475
+ // Deserialize labels
476
+ const labelsLength = paramsReader.readVarIntNum();
477
+ args.labels = [];
478
+ for (let i = 0; i < labelsLength; i++) {
479
+ const labelLength = paramsReader.readVarIntNum();
480
+ const labelBytes = paramsReader.read(labelLength);
481
+ args.labels.push(index_js_1.Utils.toUTF8(labelBytes));
482
+ }
483
+ // Deserialize labelQueryMode
484
+ const labelQueryModeFlag = paramsReader.readInt8();
485
+ if (labelQueryModeFlag === -1) {
486
+ args.labelQueryMode = undefined;
487
+ }
488
+ else if (labelQueryModeFlag === 1) {
489
+ args.labelQueryMode = 'any';
490
+ }
491
+ else if (labelQueryModeFlag === 2) {
492
+ args.labelQueryMode = 'all';
493
+ }
494
+ // Deserialize include options
495
+ const includeOptionsNames = [
496
+ 'includeLabels',
497
+ 'includeInputs',
498
+ 'includeInputSourceLockingScripts',
499
+ 'includeInputUnlockingScripts',
500
+ 'includeOutputs',
501
+ 'includeOutputLockingScripts'
502
+ ];
503
+ for (const optionName of includeOptionsNames) {
504
+ const optionFlag = paramsReader.readInt8();
505
+ if (optionFlag === -1) {
506
+ args[optionName] = undefined;
524
507
  }
525
508
  else {
526
- args.offset = undefined;
509
+ args[optionName] = optionFlag === 1;
527
510
  }
528
- // Deserialize seekPermission
529
- const seekPermission = paramsReader.readInt8();
530
- if (seekPermission >= 0) {
531
- args.seekPermission = seekPermission === 1;
511
+ }
512
+ // Deserialize limit
513
+ const limit = paramsReader.readVarIntNum();
514
+ if (limit >= 0) {
515
+ args.limit = limit;
516
+ }
517
+ else {
518
+ args.limit = undefined;
519
+ }
520
+ // Deserialize offset
521
+ const offset = paramsReader.readVarIntNum();
522
+ if (offset >= 0) {
523
+ args.offset = offset;
524
+ }
525
+ else {
526
+ args.offset = undefined;
527
+ }
528
+ // Deserialize seekPermission
529
+ const seekPermission = paramsReader.readInt8();
530
+ if (seekPermission >= 0) {
531
+ args.seekPermission = seekPermission === 1;
532
+ }
533
+ else {
534
+ args.seekPermission = undefined;
535
+ }
536
+ // Call the method
537
+ const listActionsResult = await this.wallet.listActions(args, originator);
538
+ // Serialize the result
539
+ const resultWriter = new index_js_1.Utils.Writer();
540
+ // totalActions
541
+ resultWriter.writeVarIntNum(listActionsResult.totalActions);
542
+ // actions
543
+ for (const action of listActionsResult.actions) {
544
+ // txid
545
+ resultWriter.write(index_js_1.Utils.toArray(action.txid, 'hex'));
546
+ // satoshis
547
+ resultWriter.writeVarIntNum(action.satoshis);
548
+ // status
549
+ let statusCode;
550
+ switch (action.status) {
551
+ case 'completed':
552
+ statusCode = 1;
553
+ break;
554
+ case 'unprocessed':
555
+ statusCode = 2;
556
+ break;
557
+ case 'sending':
558
+ statusCode = 3;
559
+ break;
560
+ case 'unproven':
561
+ statusCode = 4;
562
+ break;
563
+ case 'unsigned':
564
+ statusCode = 5;
565
+ break;
566
+ case 'nosend':
567
+ statusCode = 6;
568
+ break;
569
+ case 'nonfinal':
570
+ statusCode = 7;
571
+ break;
572
+ default:
573
+ statusCode = -1;
574
+ break;
575
+ }
576
+ resultWriter.writeInt8(statusCode);
577
+ // isOutgoing
578
+ resultWriter.writeInt8(action.isOutgoing ? 1 : 0);
579
+ // description
580
+ const descriptionBytes = index_js_1.Utils.toArray(action.description, 'utf8');
581
+ resultWriter.writeVarIntNum(descriptionBytes.length);
582
+ resultWriter.write(descriptionBytes);
583
+ // labels
584
+ if (action.labels !== undefined) {
585
+ resultWriter.writeVarIntNum(action.labels.length);
586
+ for (const label of action.labels) {
587
+ const labelBytes = index_js_1.Utils.toArray(label, 'utf8');
588
+ resultWriter.writeVarIntNum(labelBytes.length);
589
+ resultWriter.write(labelBytes);
590
+ }
532
591
  }
533
592
  else {
534
- args.seekPermission = undefined;
535
- }
536
- // Call the method
537
- const listActionsResult = await this.wallet.listActions(args, originator);
538
- // Serialize the result
539
- const resultWriter = new index_js_1.Utils.Writer();
540
- // totalActions
541
- resultWriter.writeVarIntNum(listActionsResult.totalActions);
542
- // actions
543
- for (const action of listActionsResult.actions) {
544
- // txid
545
- resultWriter.write(index_js_1.Utils.toArray(action.txid, 'hex'));
546
- // satoshis
547
- resultWriter.writeVarIntNum(action.satoshis);
548
- // status
549
- let statusCode;
550
- switch (action.status) {
551
- case 'completed':
552
- statusCode = 1;
553
- break;
554
- case 'unprocessed':
555
- statusCode = 2;
556
- break;
557
- case 'sending':
558
- statusCode = 3;
559
- break;
560
- case 'unproven':
561
- statusCode = 4;
562
- break;
563
- case 'unsigned':
564
- statusCode = 5;
565
- break;
566
- case 'nosend':
567
- statusCode = 6;
568
- break;
569
- case 'nonfinal':
570
- statusCode = 7;
571
- break;
572
- default:
573
- statusCode = -1;
574
- break;
575
- }
576
- resultWriter.writeInt8(statusCode);
577
- // isOutgoing
578
- resultWriter.writeInt8(action.isOutgoing ? 1 : 0);
579
- // description
580
- const descriptionBytes = index_js_1.Utils.toArray(action.description, 'utf8');
581
- resultWriter.writeVarIntNum(descriptionBytes.length);
582
- resultWriter.write(descriptionBytes);
583
- // labels
584
- if (action.labels !== undefined) {
585
- resultWriter.writeVarIntNum(action.labels.length);
586
- for (const label of action.labels) {
587
- const labelBytes = index_js_1.Utils.toArray(label, 'utf8');
588
- resultWriter.writeVarIntNum(labelBytes.length);
589
- resultWriter.write(labelBytes);
593
+ resultWriter.writeVarIntNum(-1);
594
+ }
595
+ // version
596
+ resultWriter.writeVarIntNum(action.version);
597
+ // lockTime
598
+ resultWriter.writeVarIntNum(action.lockTime);
599
+ // inputs
600
+ if (action.inputs !== undefined) {
601
+ resultWriter.writeVarIntNum(action.inputs.length);
602
+ for (const input of action.inputs) {
603
+ // sourceOutpoint
604
+ resultWriter.write(this.encodeOutpoint(input.sourceOutpoint));
605
+ // sourceSatoshis
606
+ resultWriter.writeVarIntNum(input.sourceSatoshis);
607
+ // sourceLockingScript
608
+ if (input.sourceLockingScript !== undefined) {
609
+ const sourceLockingScriptBytes = index_js_1.Utils.toArray(input.sourceLockingScript, 'hex');
610
+ resultWriter.writeVarIntNum(sourceLockingScriptBytes.length);
611
+ resultWriter.write(sourceLockingScriptBytes);
590
612
  }
591
- }
592
- else {
593
- resultWriter.writeVarIntNum(-1);
594
- }
595
- // version
596
- resultWriter.writeVarIntNum(action.version);
597
- // lockTime
598
- resultWriter.writeVarIntNum(action.lockTime);
599
- // inputs
600
- if (action.inputs !== undefined) {
601
- resultWriter.writeVarIntNum(action.inputs.length);
602
- for (const input of action.inputs) {
603
- // sourceOutpoint
604
- resultWriter.write(this.encodeOutpoint(input.sourceOutpoint));
605
- // sourceSatoshis
606
- resultWriter.writeVarIntNum(input.sourceSatoshis);
607
- // sourceLockingScript
608
- if (input.sourceLockingScript !== undefined) {
609
- const sourceLockingScriptBytes = index_js_1.Utils.toArray(input.sourceLockingScript, 'hex');
610
- resultWriter.writeVarIntNum(sourceLockingScriptBytes.length);
611
- resultWriter.write(sourceLockingScriptBytes);
612
- }
613
- else {
614
- resultWriter.writeVarIntNum(-1);
615
- }
616
- // unlockingScript
617
- if (input.unlockingScript !== undefined) {
618
- const unlockingScriptBytes = index_js_1.Utils.toArray(input.unlockingScript, 'hex');
619
- resultWriter.writeVarIntNum(unlockingScriptBytes.length);
620
- resultWriter.write(unlockingScriptBytes);
621
- }
622
- else {
623
- resultWriter.writeVarIntNum(-1);
624
- }
625
- // inputDescription
626
- const inputDescriptionBytes = index_js_1.Utils.toArray(input.inputDescription, 'utf8');
627
- resultWriter.writeVarIntNum(inputDescriptionBytes.length);
628
- resultWriter.write(inputDescriptionBytes);
629
- // sequenceNumber
630
- resultWriter.writeVarIntNum(input.sequenceNumber);
613
+ else {
614
+ resultWriter.writeVarIntNum(-1);
631
615
  }
632
- }
633
- else {
634
- resultWriter.writeVarIntNum(-1);
635
- }
636
- // outputs
637
- if (action.outputs !== undefined) {
638
- resultWriter.writeVarIntNum(action.outputs.length);
639
- for (const output of action.outputs) {
640
- // outputIndex
641
- resultWriter.writeVarIntNum(output.outputIndex);
642
- // satoshis
643
- resultWriter.writeVarIntNum(output.satoshis);
644
- // lockingScript
645
- if (output.lockingScript !== undefined) {
646
- const lockingScriptBytes = index_js_1.Utils.toArray(output.lockingScript, 'hex');
647
- resultWriter.writeVarIntNum(lockingScriptBytes.length);
648
- resultWriter.write(lockingScriptBytes);
649
- }
650
- else {
651
- resultWriter.writeVarIntNum(-1);
652
- }
653
- // spendable
654
- resultWriter.writeInt8(output.spendable ? 1 : 0);
655
- // outputDescription
656
- const outputDescriptionBytes = index_js_1.Utils.toArray(output.outputDescription, 'utf8');
657
- resultWriter.writeVarIntNum(outputDescriptionBytes.length);
658
- resultWriter.write(outputDescriptionBytes);
659
- // basket
660
- if (output.basket !== undefined) {
661
- const basketBytes = index_js_1.Utils.toArray(output.basket, 'utf8');
662
- resultWriter.writeVarIntNum(basketBytes.length);
663
- resultWriter.write(basketBytes);
664
- }
665
- else {
666
- resultWriter.writeVarIntNum(-1);
667
- }
668
- // tags
669
- if (output.tags !== undefined) {
670
- resultWriter.writeVarIntNum(output.tags.length);
671
- for (const tag of output.tags) {
672
- const tagBytes = index_js_1.Utils.toArray(tag, 'utf8');
673
- resultWriter.writeVarIntNum(tagBytes.length);
674
- resultWriter.write(tagBytes);
675
- }
676
- }
677
- else {
678
- resultWriter.writeVarIntNum(-1);
679
- }
680
- // customInstructions
681
- if (output.customInstructions !== undefined) {
682
- const customInstructionsBytes = index_js_1.Utils.toArray(output.customInstructions, 'utf8');
683
- resultWriter.writeVarIntNum(customInstructionsBytes.length);
684
- resultWriter.write(customInstructionsBytes);
685
- }
686
- else {
687
- resultWriter.writeVarIntNum(-1);
688
- }
616
+ // unlockingScript
617
+ if (input.unlockingScript !== undefined) {
618
+ const unlockingScriptBytes = index_js_1.Utils.toArray(input.unlockingScript, 'hex');
619
+ resultWriter.writeVarIntNum(unlockingScriptBytes.length);
620
+ resultWriter.write(unlockingScriptBytes);
689
621
  }
690
- }
691
- else {
692
- resultWriter.writeVarIntNum(-1);
622
+ else {
623
+ resultWriter.writeVarIntNum(-1);
624
+ }
625
+ // inputDescription
626
+ const inputDescriptionBytes = index_js_1.Utils.toArray(input.inputDescription, 'utf8');
627
+ resultWriter.writeVarIntNum(inputDescriptionBytes.length);
628
+ resultWriter.write(inputDescriptionBytes);
629
+ // sequenceNumber
630
+ resultWriter.writeVarIntNum(input.sequenceNumber);
693
631
  }
694
632
  }
695
- const responseWriter = new index_js_1.Utils.Writer();
696
- responseWriter.writeUInt8(0); // errorByte = 0
697
- responseWriter.write(resultWriter.toArray());
698
- return responseWriter.toArray();
699
- }
700
- case 'internalizeAction':
701
- {
702
- const args = {};
703
- // Read tx
704
- const txLength = paramsReader.readVarIntNum();
705
- args.tx = paramsReader.read(txLength);
706
- // Read outputs
707
- const outputsLength = paramsReader.readVarIntNum();
708
- args.outputs = [];
709
- for (let i = 0; i < outputsLength; i++) {
710
- const output = {};
711
- // outputIndex
712
- output.outputIndex = paramsReader.readVarIntNum();
713
- // protocol
714
- const protocolFlag = paramsReader.readUInt8();
715
- if (protocolFlag === 1) {
716
- output.protocol = 'wallet payment';
717
- output.paymentRemittance = {};
718
- // senderIdentityKey
719
- const senderIdentityKeyBytes = paramsReader.read(33);
720
- output.paymentRemittance.senderIdentityKey = index_js_1.Utils.toHex(senderIdentityKeyBytes);
721
- // derivationPrefix
722
- const derivationPrefixLength = paramsReader.readVarIntNum();
723
- const derivationPrefixBytes = paramsReader.read(derivationPrefixLength);
724
- output.paymentRemittance.derivationPrefix = index_js_1.Utils.toBase64(derivationPrefixBytes);
725
- // derivationSuffix
726
- const derivationSuffixLength = paramsReader.readVarIntNum();
727
- const derivationSuffixBytes = paramsReader.read(derivationSuffixLength);
728
- output.paymentRemittance.derivationSuffix = index_js_1.Utils.toBase64(derivationSuffixBytes);
729
- }
730
- else if (protocolFlag === 2) {
731
- output.protocol = 'basket insertion';
732
- output.insertionRemittance = {};
633
+ else {
634
+ resultWriter.writeVarIntNum(-1);
635
+ }
636
+ // outputs
637
+ if (action.outputs !== undefined) {
638
+ resultWriter.writeVarIntNum(action.outputs.length);
639
+ for (const output of action.outputs) {
640
+ // outputIndex
641
+ resultWriter.writeVarIntNum(output.outputIndex);
642
+ // satoshis
643
+ resultWriter.writeVarIntNum(output.satoshis);
644
+ // lockingScript
645
+ if (output.lockingScript !== undefined) {
646
+ const lockingScriptBytes = index_js_1.Utils.toArray(output.lockingScript, 'hex');
647
+ resultWriter.writeVarIntNum(lockingScriptBytes.length);
648
+ resultWriter.write(lockingScriptBytes);
649
+ }
650
+ else {
651
+ resultWriter.writeVarIntNum(-1);
652
+ }
653
+ // spendable
654
+ resultWriter.writeInt8(output.spendable ? 1 : 0);
655
+ // outputDescription
656
+ const outputDescriptionBytes = index_js_1.Utils.toArray(output.outputDescription, 'utf8');
657
+ resultWriter.writeVarIntNum(outputDescriptionBytes.length);
658
+ resultWriter.write(outputDescriptionBytes);
733
659
  // basket
734
- const basketLength = paramsReader.readVarIntNum();
735
- const basketBytes = paramsReader.read(basketLength);
736
- output.insertionRemittance.basket = index_js_1.Utils.toUTF8(basketBytes);
737
- // customInstructions
738
- const customInstructionsLength = paramsReader.readVarIntNum();
739
- if (customInstructionsLength >= 0) {
740
- const customInstructionsBytes = paramsReader.read(customInstructionsLength);
741
- output.insertionRemittance.customInstructions = index_js_1.Utils.toUTF8(customInstructionsBytes);
660
+ if (output.basket !== undefined) {
661
+ const basketBytes = index_js_1.Utils.toArray(output.basket, 'utf8');
662
+ resultWriter.writeVarIntNum(basketBytes.length);
663
+ resultWriter.write(basketBytes);
664
+ }
665
+ else {
666
+ resultWriter.writeVarIntNum(-1);
742
667
  }
743
668
  // tags
744
- const tagsLength = paramsReader.readVarIntNum();
745
- if (tagsLength > 0) {
746
- output.insertionRemittance.tags = [];
747
- for (let j = 0; j < tagsLength; j++) {
748
- const tagLength = paramsReader.readVarIntNum();
749
- const tagBytes = paramsReader.read(tagLength);
750
- output.insertionRemittance.tags.push(index_js_1.Utils.toUTF8(tagBytes));
669
+ if (output.tags !== undefined) {
670
+ resultWriter.writeVarIntNum(output.tags.length);
671
+ for (const tag of output.tags) {
672
+ const tagBytes = index_js_1.Utils.toArray(tag, 'utf8');
673
+ resultWriter.writeVarIntNum(tagBytes.length);
674
+ resultWriter.write(tagBytes);
751
675
  }
752
676
  }
753
677
  else {
754
- output.insertionRemittance.tags = [];
678
+ resultWriter.writeVarIntNum(-1);
679
+ }
680
+ // customInstructions
681
+ if (output.customInstructions !== undefined) {
682
+ const customInstructionsBytes = index_js_1.Utils.toArray(output.customInstructions, 'utf8');
683
+ resultWriter.writeVarIntNum(customInstructionsBytes.length);
684
+ resultWriter.write(customInstructionsBytes);
685
+ }
686
+ else {
687
+ resultWriter.writeVarIntNum(-1);
755
688
  }
756
689
  }
757
- args.outputs.push(output);
758
- }
759
- const numberOfLabels = paramsReader.readVarIntNum();
760
- if (numberOfLabels >= 0) {
761
- args.labels = [];
762
- for (let i = 0; i < numberOfLabels; i++) {
763
- const labelLength = paramsReader.readVarIntNum();
764
- args.labels.push(index_js_1.Utils.toUTF8(paramsReader.read(labelLength)));
765
- }
766
- }
767
- const descriptionLength = paramsReader.readVarIntNum();
768
- args.description = index_js_1.Utils.toUTF8(paramsReader.read(descriptionLength));
769
- // Deserialize seekPermission
770
- const seekPermission = paramsReader.readInt8();
771
- if (seekPermission >= 0) {
772
- args.seekPermission = seekPermission === 1;
773
- }
774
- else {
775
- args.seekPermission = undefined;
776
- }
777
- // Call the method
778
- await this.wallet.internalizeAction(args, originator);
779
- // Return success code and result
780
- const responseWriter = new index_js_1.Utils.Writer();
781
- responseWriter.writeUInt8(0); // errorByte = 0
782
- return responseWriter.toArray();
783
- }
784
- case 'listOutputs':
785
- {
786
- const args = {};
787
- // Deserialize basket
788
- const basketLength = paramsReader.readVarIntNum();
789
- const basketBytes = paramsReader.read(basketLength);
790
- args.basket = index_js_1.Utils.toUTF8(basketBytes);
791
- // Deserialize tags
792
- const tagsLength = paramsReader.readVarIntNum();
793
- if (tagsLength > 0) {
794
- args.tags = [];
795
- for (let i = 0; i < tagsLength; i++) {
796
- const tagLength = paramsReader.readVarIntNum();
797
- const tagBytes = paramsReader.read(tagLength);
798
- args.tags.push(index_js_1.Utils.toUTF8(tagBytes));
799
- }
800
- }
801
- else {
802
- args.tags = undefined;
803
- }
804
- // Deserialize tagQueryMode
805
- const tagQueryModeFlag = paramsReader.readInt8();
806
- if (tagQueryModeFlag === 1) {
807
- args.tagQueryMode = 'all';
808
- }
809
- else if (tagQueryModeFlag === 2) {
810
- args.tagQueryMode = 'any';
811
- }
812
- else {
813
- args.tagQueryMode = undefined;
814
- }
815
- // Deserialize include
816
- const includeFlag = paramsReader.readInt8();
817
- if (includeFlag === 1) {
818
- args.include = 'locking scripts';
819
- }
820
- else if (includeFlag === 2) {
821
- args.include = 'entire transactions';
822
- }
823
- else {
824
- args.include = undefined;
825
- }
826
- // Deserialize includeCustomInstructions
827
- const includeCustomInstructionsFlag = paramsReader.readInt8();
828
- if (includeCustomInstructionsFlag === -1) {
829
- args.includeCustomInstructions = undefined;
830
- }
831
- else {
832
- args.includeCustomInstructions = includeCustomInstructionsFlag === 1;
833
- }
834
- // Deserialize includeTags
835
- const includeTagsFlag = paramsReader.readInt8();
836
- if (includeTagsFlag === -1) {
837
- args.includeTags = undefined;
838
- }
839
- else {
840
- args.includeTags = includeTagsFlag === 1;
841
- }
842
- // Deserialize includeLabels
843
- const includeLabelsFlag = paramsReader.readInt8();
844
- if (includeLabelsFlag === -1) {
845
- args.includeLabels = undefined;
846
- }
847
- else {
848
- args.includeLabels = includeLabelsFlag === 1;
849
- }
850
- // Deserialize limit
851
- const limit = paramsReader.readVarIntNum();
852
- if (limit >= 0) {
853
- args.limit = limit;
854
- }
855
- else {
856
- args.limit = undefined;
857
- }
858
- // Deserialize offset
859
- const offset = paramsReader.readVarIntNum();
860
- if (offset >= 0) {
861
- args.offset = offset;
862
- }
863
- else {
864
- args.offset = undefined;
865
- }
866
- // Deserialize seekPermission
867
- const seekPermission = paramsReader.readInt8();
868
- if (seekPermission >= 0) {
869
- args.seekPermission = seekPermission === 1;
870
- }
871
- else {
872
- args.seekPermission = undefined;
873
- }
874
- // Call the method
875
- const listOutputsResult = await this.wallet.listOutputs(args, originator);
876
- // Serialize the result
877
- const resultWriter = new index_js_1.Utils.Writer();
878
- // totalOutputs
879
- resultWriter.writeVarIntNum(listOutputsResult.totalOutputs);
880
- // BEEF length and BEEF or -1
881
- if (listOutputsResult.BEEF) {
882
- resultWriter.writeVarIntNum(listOutputsResult.BEEF.length);
883
- resultWriter.write(listOutputsResult.BEEF);
884
690
  }
885
691
  else {
886
692
  resultWriter.writeVarIntNum(-1);
887
693
  }
888
- // outputs
889
- for (const output of listOutputsResult.outputs) {
890
- // outpoint
891
- resultWriter.write(this.encodeOutpoint(output.outpoint));
892
- // satoshis
893
- resultWriter.writeVarIntNum(output.satoshis);
894
- // lockingScript
895
- if (output.lockingScript !== undefined) {
896
- const lockingScriptBytes = index_js_1.Utils.toArray(output.lockingScript, 'hex');
897
- resultWriter.writeVarIntNum(lockingScriptBytes.length);
898
- resultWriter.write(lockingScriptBytes);
899
- }
900
- else {
901
- resultWriter.writeVarIntNum(-1);
902
- }
694
+ }
695
+ const responseWriter = new index_js_1.Utils.Writer();
696
+ responseWriter.writeUInt8(0); // errorByte = 0
697
+ responseWriter.write(resultWriter.toArray());
698
+ return responseWriter.toArray();
699
+ }
700
+ case 'internalizeAction': {
701
+ const args = {};
702
+ // Read tx
703
+ const txLength = paramsReader.readVarIntNum();
704
+ args.tx = paramsReader.read(txLength);
705
+ // Read outputs
706
+ const outputsLength = paramsReader.readVarIntNum();
707
+ args.outputs = [];
708
+ for (let i = 0; i < outputsLength; i++) {
709
+ const output = {};
710
+ // outputIndex
711
+ output.outputIndex = paramsReader.readVarIntNum();
712
+ // protocol
713
+ const protocolFlag = paramsReader.readUInt8();
714
+ if (protocolFlag === 1) {
715
+ output.protocol = 'wallet payment';
716
+ output.paymentRemittance = {};
717
+ // senderIdentityKey
718
+ const senderIdentityKeyBytes = paramsReader.read(33);
719
+ output.paymentRemittance.senderIdentityKey = index_js_1.Utils.toHex(senderIdentityKeyBytes);
720
+ // derivationPrefix
721
+ const derivationPrefixLength = paramsReader.readVarIntNum();
722
+ const derivationPrefixBytes = paramsReader.read(derivationPrefixLength);
723
+ output.paymentRemittance.derivationPrefix = index_js_1.Utils.toBase64(derivationPrefixBytes);
724
+ // derivationSuffix
725
+ const derivationSuffixLength = paramsReader.readVarIntNum();
726
+ const derivationSuffixBytes = paramsReader.read(derivationSuffixLength);
727
+ output.paymentRemittance.derivationSuffix = index_js_1.Utils.toBase64(derivationSuffixBytes);
728
+ }
729
+ else if (protocolFlag === 2) {
730
+ output.protocol = 'basket insertion';
731
+ output.insertionRemittance = {};
732
+ // basket
733
+ const basketLength = paramsReader.readVarIntNum();
734
+ const basketBytes = paramsReader.read(basketLength);
735
+ output.insertionRemittance.basket = index_js_1.Utils.toUTF8(basketBytes);
903
736
  // customInstructions
904
- if (output.customInstructions !== undefined) {
905
- const customInstructionsBytes = index_js_1.Utils.toArray(output.customInstructions, 'utf8');
906
- resultWriter.writeVarIntNum(customInstructionsBytes.length);
907
- resultWriter.write(customInstructionsBytes);
908
- }
909
- else {
910
- resultWriter.writeVarIntNum(-1);
737
+ const customInstructionsLength = paramsReader.readVarIntNum();
738
+ if (customInstructionsLength >= 0) {
739
+ const customInstructionsBytes = paramsReader.read(customInstructionsLength);
740
+ output.insertionRemittance.customInstructions = index_js_1.Utils.toUTF8(customInstructionsBytes);
911
741
  }
912
742
  // tags
913
- if (output.tags !== undefined) {
914
- resultWriter.writeVarIntNum(output.tags.length);
915
- for (const tag of output.tags) {
916
- const tagBytes = index_js_1.Utils.toArray(tag, 'utf8');
917
- resultWriter.writeVarIntNum(tagBytes.length);
918
- resultWriter.write(tagBytes);
919
- }
920
- }
921
- else {
922
- resultWriter.writeVarIntNum(-1);
923
- }
924
- // labels
925
- if (output.labels !== undefined) {
926
- resultWriter.writeVarIntNum(output.labels.length);
927
- for (const label of output.labels) {
928
- const labelBytes = index_js_1.Utils.toArray(label, 'utf8');
929
- resultWriter.writeVarIntNum(labelBytes.length);
930
- resultWriter.write(labelBytes);
743
+ const tagsLength = paramsReader.readVarIntNum();
744
+ if (tagsLength > 0) {
745
+ output.insertionRemittance.tags = [];
746
+ for (let j = 0; j < tagsLength; j++) {
747
+ const tagLength = paramsReader.readVarIntNum();
748
+ const tagBytes = paramsReader.read(tagLength);
749
+ output.insertionRemittance.tags.push(index_js_1.Utils.toUTF8(tagBytes));
931
750
  }
932
751
  }
933
752
  else {
934
- resultWriter.writeVarIntNum(-1);
753
+ output.insertionRemittance.tags = [];
935
754
  }
936
755
  }
937
- // Return success code and result
938
- const responseWriter = new index_js_1.Utils.Writer();
939
- responseWriter.writeUInt8(0); // errorByte = 0
940
- responseWriter.write(resultWriter.toArray());
941
- return responseWriter.toArray();
942
- }
943
- case 'relinquishOutput':
944
- {
945
- const args = {};
946
- // Deserialize basket
947
- const basketLength = paramsReader.readVarIntNum();
948
- const basketBytes = paramsReader.read(basketLength);
949
- args.basket = index_js_1.Utils.toUTF8(basketBytes);
950
- // Deserialize outpoint
951
- args.output = this.decodeOutpoint(paramsReader);
952
- // Call the method
953
- await this.wallet.relinquishOutput(args, originator);
954
- // Return success code and result
955
- const responseWriter = new index_js_1.Utils.Writer();
956
- responseWriter.writeUInt8(0); // errorByte = 0
957
- return responseWriter.toArray();
958
- }
959
- case 'getPublicKey':
960
- {
961
- const args = {};
962
- // Deserialize identityKey flag
963
- const identityKeyFlag = paramsReader.readUInt8();
964
- args.identityKey = identityKeyFlag === 1;
965
- if (!args.identityKey) {
966
- // Deserialize protocolID
967
- args.protocolID = this.decodeProtocolID(paramsReader);
968
- // Deserialize keyID
969
- args.keyID = this.decodeString(paramsReader);
970
- // Deserialize counterparty
971
- args.counterparty = this.decodeCounterparty(paramsReader);
972
- // Deserialize privilege parameters
973
- const privilegedFlag = paramsReader.readInt8();
974
- if (privilegedFlag === -1) {
975
- args.privileged = undefined;
976
- }
977
- else {
978
- args.privileged = privilegedFlag === 1;
979
- }
980
- const privilegedReasonLength = paramsReader.readInt8();
981
- if (privilegedReasonLength !== -1) {
982
- const privilegedReasonBytes = paramsReader.read(privilegedReasonLength);
983
- args.privilegedReason = index_js_1.Utils.toUTF8(privilegedReasonBytes);
984
- }
985
- else {
986
- args.privilegedReason = undefined;
987
- }
988
- // Deserialize forSelf
989
- const forSelfFlag = paramsReader.readInt8();
990
- if (forSelfFlag === -1) {
991
- args.forSelf = undefined;
992
- }
993
- else {
994
- args.forSelf = forSelfFlag === 1;
995
- }
756
+ args.outputs.push(output);
757
+ }
758
+ const numberOfLabels = paramsReader.readVarIntNum();
759
+ if (numberOfLabels >= 0) {
760
+ args.labels = [];
761
+ for (let i = 0; i < numberOfLabels; i++) {
762
+ const labelLength = paramsReader.readVarIntNum();
763
+ args.labels.push(index_js_1.Utils.toUTF8(paramsReader.read(labelLength)));
996
764
  }
997
- else {
998
- // Deserialize privilege parameters
999
- const privilegedFlag = paramsReader.readInt8();
1000
- if (privilegedFlag === -1) {
1001
- args.privileged = undefined;
1002
- }
1003
- else {
1004
- args.privileged = privilegedFlag === 1;
1005
- }
1006
- const privilegedReasonLength = paramsReader.readInt8();
1007
- if (privilegedReasonLength !== -1) {
1008
- const privilegedReasonBytes = paramsReader.read(privilegedReasonLength);
1009
- args.privilegedReason = index_js_1.Utils.toUTF8(privilegedReasonBytes);
1010
- }
1011
- else {
1012
- args.privilegedReason = undefined;
1013
- }
765
+ }
766
+ const descriptionLength = paramsReader.readVarIntNum();
767
+ args.description = index_js_1.Utils.toUTF8(paramsReader.read(descriptionLength));
768
+ // Deserialize seekPermission
769
+ const seekPermission = paramsReader.readInt8();
770
+ if (seekPermission >= 0) {
771
+ args.seekPermission = seekPermission === 1;
772
+ }
773
+ else {
774
+ args.seekPermission = undefined;
775
+ }
776
+ // Call the method
777
+ await this.wallet.internalizeAction(args, originator);
778
+ // Return success code and result
779
+ const responseWriter = new index_js_1.Utils.Writer();
780
+ responseWriter.writeUInt8(0); // errorByte = 0
781
+ return responseWriter.toArray();
782
+ }
783
+ case 'listOutputs': {
784
+ const args = {};
785
+ // Deserialize basket
786
+ const basketLength = paramsReader.readVarIntNum();
787
+ const basketBytes = paramsReader.read(basketLength);
788
+ args.basket = index_js_1.Utils.toUTF8(basketBytes);
789
+ // Deserialize tags
790
+ const tagsLength = paramsReader.readVarIntNum();
791
+ if (tagsLength > 0) {
792
+ args.tags = [];
793
+ for (let i = 0; i < tagsLength; i++) {
794
+ const tagLength = paramsReader.readVarIntNum();
795
+ const tagBytes = paramsReader.read(tagLength);
796
+ args.tags.push(index_js_1.Utils.toUTF8(tagBytes));
1014
797
  }
1015
- // Deserialize seekPermission
1016
- const seekPermission = paramsReader.readInt8();
1017
- if (seekPermission >= 0) {
1018
- args.seekPermission = seekPermission === 1;
798
+ }
799
+ else {
800
+ args.tags = undefined;
801
+ }
802
+ // Deserialize tagQueryMode
803
+ const tagQueryModeFlag = paramsReader.readInt8();
804
+ if (tagQueryModeFlag === 1) {
805
+ args.tagQueryMode = 'all';
806
+ }
807
+ else if (tagQueryModeFlag === 2) {
808
+ args.tagQueryMode = 'any';
809
+ }
810
+ else {
811
+ args.tagQueryMode = undefined;
812
+ }
813
+ // Deserialize include
814
+ const includeFlag = paramsReader.readInt8();
815
+ if (includeFlag === 1) {
816
+ args.include = 'locking scripts';
817
+ }
818
+ else if (includeFlag === 2) {
819
+ args.include = 'entire transactions';
820
+ }
821
+ else {
822
+ args.include = undefined;
823
+ }
824
+ // Deserialize includeCustomInstructions
825
+ const includeCustomInstructionsFlag = paramsReader.readInt8();
826
+ if (includeCustomInstructionsFlag === -1) {
827
+ args.includeCustomInstructions = undefined;
828
+ }
829
+ else {
830
+ args.includeCustomInstructions =
831
+ includeCustomInstructionsFlag === 1;
832
+ }
833
+ // Deserialize includeTags
834
+ const includeTagsFlag = paramsReader.readInt8();
835
+ if (includeTagsFlag === -1) {
836
+ args.includeTags = undefined;
837
+ }
838
+ else {
839
+ args.includeTags = includeTagsFlag === 1;
840
+ }
841
+ // Deserialize includeLabels
842
+ const includeLabelsFlag = paramsReader.readInt8();
843
+ if (includeLabelsFlag === -1) {
844
+ args.includeLabels = undefined;
845
+ }
846
+ else {
847
+ args.includeLabels = includeLabelsFlag === 1;
848
+ }
849
+ // Deserialize limit
850
+ const limit = paramsReader.readVarIntNum();
851
+ if (limit >= 0) {
852
+ args.limit = limit;
853
+ }
854
+ else {
855
+ args.limit = undefined;
856
+ }
857
+ // Deserialize offset
858
+ const offset = paramsReader.readVarIntNum();
859
+ if (offset >= 0) {
860
+ args.offset = offset;
861
+ }
862
+ else {
863
+ args.offset = undefined;
864
+ }
865
+ // Deserialize seekPermission
866
+ const seekPermission = paramsReader.readInt8();
867
+ if (seekPermission >= 0) {
868
+ args.seekPermission = seekPermission === 1;
869
+ }
870
+ else {
871
+ args.seekPermission = undefined;
872
+ }
873
+ // Call the method
874
+ const listOutputsResult = await this.wallet.listOutputs(args, originator);
875
+ // Serialize the result
876
+ const resultWriter = new index_js_1.Utils.Writer();
877
+ // totalOutputs
878
+ resultWriter.writeVarIntNum(listOutputsResult.totalOutputs);
879
+ // BEEF length and BEEF or -1
880
+ if (listOutputsResult.BEEF != null) {
881
+ resultWriter.writeVarIntNum(listOutputsResult.BEEF.length);
882
+ resultWriter.write(listOutputsResult.BEEF);
883
+ }
884
+ else {
885
+ resultWriter.writeVarIntNum(-1);
886
+ }
887
+ // outputs
888
+ for (const output of listOutputsResult.outputs) {
889
+ // outpoint
890
+ resultWriter.write(this.encodeOutpoint(output.outpoint));
891
+ // satoshis
892
+ resultWriter.writeVarIntNum(output.satoshis);
893
+ // lockingScript
894
+ if (output.lockingScript !== undefined) {
895
+ const lockingScriptBytes = index_js_1.Utils.toArray(output.lockingScript, 'hex');
896
+ resultWriter.writeVarIntNum(lockingScriptBytes.length);
897
+ resultWriter.write(lockingScriptBytes);
1019
898
  }
1020
899
  else {
1021
- args.seekPermission = undefined;
1022
- }
1023
- // Call the method
1024
- const getPublicKeyResult = await this.wallet.getPublicKey(args, originator);
1025
- // Serialize the result
1026
- const responseWriter = new index_js_1.Utils.Writer();
1027
- responseWriter.writeUInt8(0); // errorByte = 0
1028
- const publicKeyBytes = index_js_1.Utils.toArray(getPublicKeyResult.publicKey, 'hex');
1029
- responseWriter.write(publicKeyBytes);
1030
- return responseWriter.toArray();
1031
- }
1032
- case 'encrypt':
1033
- {
1034
- const args = this.decodeKeyRelatedParams(paramsReader);
1035
- // Deserialize plaintext
1036
- const plaintextLength = paramsReader.readVarIntNum();
1037
- args.plaintext = paramsReader.read(plaintextLength);
1038
- // Deserialize seekPermission
1039
- const seekPermission = paramsReader.readInt8();
1040
- if (seekPermission >= 0) {
1041
- args.seekPermission = seekPermission === 1;
900
+ resultWriter.writeVarIntNum(-1);
1042
901
  }
1043
- else {
1044
- args.seekPermission = undefined;
1045
- }
1046
- // Call the method
1047
- const encryptResult = await this.wallet.encrypt(args, originator);
1048
- // Serialize the result
1049
- const responseWriter = new index_js_1.Utils.Writer();
1050
- responseWriter.writeUInt8(0); // errorByte = 0
1051
- responseWriter.write(encryptResult.ciphertext);
1052
- return responseWriter.toArray();
1053
- }
1054
- case 'decrypt':
1055
- {
1056
- const args = this.decodeKeyRelatedParams(paramsReader);
1057
- // Deserialize ciphertext
1058
- const ciphertextLength = paramsReader.readVarIntNum();
1059
- args.ciphertext = paramsReader.read(ciphertextLength);
1060
- // Deserialize seekPermission
1061
- const seekPermission = paramsReader.readInt8();
1062
- if (seekPermission >= 0) {
1063
- args.seekPermission = seekPermission === 1;
902
+ // customInstructions
903
+ if (output.customInstructions !== undefined) {
904
+ const customInstructionsBytes = index_js_1.Utils.toArray(output.customInstructions, 'utf8');
905
+ resultWriter.writeVarIntNum(customInstructionsBytes.length);
906
+ resultWriter.write(customInstructionsBytes);
1064
907
  }
1065
908
  else {
1066
- args.seekPermission = undefined;
1067
- }
1068
- // Call the method
1069
- const decryptResult = await this.wallet.decrypt(args, originator);
1070
- // Serialize the result
1071
- const responseWriter = new index_js_1.Utils.Writer();
1072
- responseWriter.writeUInt8(0); // errorByte = 0
1073
- responseWriter.write(decryptResult.plaintext);
1074
- return responseWriter.toArray();
1075
- }
1076
- case 'createHmac':
1077
- {
1078
- const args = this.decodeKeyRelatedParams(paramsReader);
1079
- // Deserialize data
1080
- const dataLength = paramsReader.readVarIntNum();
1081
- args.data = paramsReader.read(dataLength);
1082
- // Deserialize seekPermission
1083
- const seekPermission = paramsReader.readInt8();
1084
- if (seekPermission >= 0) {
1085
- args.seekPermission = seekPermission === 1;
909
+ resultWriter.writeVarIntNum(-1);
1086
910
  }
1087
- else {
1088
- args.seekPermission = undefined;
1089
- }
1090
- // Call the method
1091
- const createHmacResult = await this.wallet.createHmac(args, originator);
1092
- // Serialize the result
1093
- const responseWriter = new index_js_1.Utils.Writer();
1094
- responseWriter.writeUInt8(0); // errorByte = 0
1095
- responseWriter.write(createHmacResult.hmac);
1096
- return responseWriter.toArray();
1097
- }
1098
- case 'verifyHmac':
1099
- {
1100
- const args = this.decodeKeyRelatedParams(paramsReader);
1101
- // Deserialize hmac
1102
- args.hmac = paramsReader.read(32);
1103
- // Deserialize data
1104
- const dataLength = paramsReader.readVarIntNum();
1105
- args.data = paramsReader.read(dataLength);
1106
- // Deserialize seekPermission
1107
- const seekPermission = paramsReader.readInt8();
1108
- if (seekPermission >= 0) {
1109
- args.seekPermission = seekPermission === 1;
911
+ // tags
912
+ if (output.tags !== undefined) {
913
+ resultWriter.writeVarIntNum(output.tags.length);
914
+ for (const tag of output.tags) {
915
+ const tagBytes = index_js_1.Utils.toArray(tag, 'utf8');
916
+ resultWriter.writeVarIntNum(tagBytes.length);
917
+ resultWriter.write(tagBytes);
918
+ }
1110
919
  }
1111
920
  else {
1112
- args.seekPermission = undefined;
1113
- }
1114
- // Call the method
1115
- await this.wallet.verifyHmac(args, originator);
1116
- // Serialize the result (no data to return)
1117
- const responseWriter = new index_js_1.Utils.Writer();
1118
- responseWriter.writeUInt8(0); // errorByte = 0
1119
- return responseWriter.toArray();
1120
- }
1121
- case 'createSignature':
1122
- {
1123
- const args = this.decodeKeyRelatedParams(paramsReader);
1124
- // Deserialize data or hashToDirectlySign
1125
- const dataTypeFlag = paramsReader.readUInt8();
1126
- if (dataTypeFlag === 1) {
1127
- const dataLength = paramsReader.readVarIntNum();
1128
- args.data = paramsReader.read(dataLength);
1129
- }
1130
- else if (dataTypeFlag === 2) {
1131
- args.hashToDirectlySign = paramsReader.read(32);
1132
- }
1133
- // Deserialize seekPermission
1134
- const seekPermission = paramsReader.readInt8();
1135
- if (seekPermission >= 0) {
1136
- args.seekPermission = seekPermission === 1;
921
+ resultWriter.writeVarIntNum(-1);
1137
922
  }
1138
- else {
1139
- args.seekPermission = undefined;
1140
- }
1141
- // Call the method
1142
- const createSignatureResult = await this.wallet.createSignature(args, originator);
1143
- // Serialize the result
1144
- const responseWriter = new index_js_1.Utils.Writer();
1145
- responseWriter.writeUInt8(0); // errorByte = 0
1146
- responseWriter.write(createSignatureResult.signature);
1147
- return responseWriter.toArray();
1148
- }
1149
- case 'verifySignature':
1150
- {
1151
- const args = this.decodeKeyRelatedParams(paramsReader);
1152
- // Deserialize forSelf
1153
- const forSelfFlag = paramsReader.readInt8();
1154
- if (forSelfFlag === -1) {
1155
- args.forSelf = undefined;
923
+ // labels
924
+ if (output.labels !== undefined) {
925
+ resultWriter.writeVarIntNum(output.labels.length);
926
+ for (const label of output.labels) {
927
+ const labelBytes = index_js_1.Utils.toArray(label, 'utf8');
928
+ resultWriter.writeVarIntNum(labelBytes.length);
929
+ resultWriter.write(labelBytes);
930
+ }
1156
931
  }
1157
932
  else {
1158
- args.forSelf = forSelfFlag === 1;
1159
- }
1160
- // Deserialize signature
1161
- const signatureLength = paramsReader.readVarIntNum();
1162
- args.signature = paramsReader.read(signatureLength);
1163
- // Deserialize data or hashToDirectlyVerify
1164
- const dataTypeFlag = paramsReader.readUInt8();
1165
- if (dataTypeFlag === 1) {
1166
- const dataLength = paramsReader.readVarIntNum();
1167
- args.data = paramsReader.read(dataLength);
1168
- }
1169
- else if (dataTypeFlag === 2) {
1170
- args.hashToDirectlyVerify = paramsReader.read(32);
1171
- }
1172
- // Deserialize seekPermission
1173
- const seekPermission = paramsReader.readInt8();
1174
- if (seekPermission >= 0) {
1175
- args.seekPermission = seekPermission === 1;
933
+ resultWriter.writeVarIntNum(-1);
1176
934
  }
1177
- else {
1178
- args.seekPermission = undefined;
1179
- }
1180
- // Call the method
1181
- await this.wallet.verifySignature(args, originator);
1182
- // Serialize the result (no data to return)
1183
- const responseWriter = new index_js_1.Utils.Writer();
1184
- responseWriter.writeUInt8(0); // errorByte = 0
1185
- return responseWriter.toArray();
1186
- }
1187
- case 'isAuthenticated':
1188
- {
1189
- // No parameters to deserialize
1190
- // Call the method
1191
- const isAuthenticatedResult = await this.wallet.isAuthenticated({}, originator);
1192
- // Serialize the result
1193
- const responseWriter = new index_js_1.Utils.Writer();
1194
- responseWriter.writeUInt8(0); // errorByte = 0
1195
- responseWriter.writeUInt8(isAuthenticatedResult.authenticated ? 1 : 0);
1196
- return responseWriter.toArray();
1197
- }
1198
- case 'waitForAuthentication':
1199
- {
1200
- // No parameters to deserialize
1201
- // Call the method
1202
- await this.wallet.waitForAuthentication({}, originator);
1203
- // Serialize the result (authenticated is always true)
1204
- const responseWriter = new index_js_1.Utils.Writer();
1205
- responseWriter.writeUInt8(0); // errorByte = 0
1206
- return responseWriter.toArray();
1207
- }
1208
- case 'getHeight':
1209
- {
1210
- // No parameters to deserialize
1211
- // Call the method
1212
- const getHeightResult = await this.wallet.getHeight({}, originator);
1213
- // Serialize the result
1214
- const responseWriter = new index_js_1.Utils.Writer();
1215
- responseWriter.writeUInt8(0); // errorByte = 0
1216
- responseWriter.writeVarIntNum(getHeightResult.height);
1217
- return responseWriter.toArray();
1218
- }
1219
- case 'getHeaderForHeight':
1220
- {
1221
- const args = {};
1222
- // Deserialize height
1223
- args.height = paramsReader.readVarIntNum();
1224
- // Call the method
1225
- const getHeaderResult = await this.wallet.getHeaderForHeight(args, originator);
1226
- // Serialize the result
1227
- const responseWriter = new index_js_1.Utils.Writer();
1228
- responseWriter.writeUInt8(0); // errorByte = 0
1229
- const headerBytes = index_js_1.Utils.toArray(getHeaderResult.header, 'hex');
1230
- responseWriter.write(headerBytes);
1231
- return responseWriter.toArray();
1232
- }
1233
- case 'getNetwork':
1234
- {
1235
- // No parameters to deserialize
1236
- // Call the method
1237
- const getNetworkResult = await this.wallet.getNetwork({}, originator);
1238
- // Serialize the result
1239
- const responseWriter = new index_js_1.Utils.Writer();
1240
- responseWriter.writeUInt8(0); // errorByte = 0
1241
- responseWriter.writeUInt8(getNetworkResult.network === 'mainnet' ? 0 : 1);
1242
- return responseWriter.toArray();
1243
- }
1244
- case 'getVersion':
1245
- {
1246
- // No parameters to deserialize
1247
- // Call the method
1248
- const getVersionResult = await this.wallet.getVersion({}, originator);
1249
- // Serialize the result
1250
- const responseWriter = new index_js_1.Utils.Writer();
1251
- responseWriter.writeUInt8(0); // errorByte = 0
1252
- const versionBytes = index_js_1.Utils.toArray(getVersionResult.version, 'utf8');
1253
- responseWriter.write(versionBytes);
1254
- return responseWriter.toArray();
1255
- }
1256
- case 'revealCounterpartyKeyLinkage':
1257
- {
1258
- const args = {};
1259
- // Read privileged parameters
935
+ }
936
+ // Return success code and result
937
+ const responseWriter = new index_js_1.Utils.Writer();
938
+ responseWriter.writeUInt8(0); // errorByte = 0
939
+ responseWriter.write(resultWriter.toArray());
940
+ return responseWriter.toArray();
941
+ }
942
+ case 'relinquishOutput': {
943
+ const args = {};
944
+ // Deserialize basket
945
+ const basketLength = paramsReader.readVarIntNum();
946
+ const basketBytes = paramsReader.read(basketLength);
947
+ args.basket = index_js_1.Utils.toUTF8(basketBytes);
948
+ // Deserialize outpoint
949
+ args.output = this.decodeOutpoint(paramsReader);
950
+ // Call the method
951
+ await this.wallet.relinquishOutput(args, originator);
952
+ // Return success code and result
953
+ const responseWriter = new index_js_1.Utils.Writer();
954
+ responseWriter.writeUInt8(0); // errorByte = 0
955
+ return responseWriter.toArray();
956
+ }
957
+ case 'getPublicKey': {
958
+ const args = {};
959
+ // Deserialize identityKey flag
960
+ const identityKeyFlag = paramsReader.readUInt8();
961
+ args.identityKey = identityKeyFlag === 1;
962
+ if (args.identityKey !== true) {
963
+ // Deserialize protocolID
964
+ args.protocolID = this.decodeProtocolID(paramsReader);
965
+ // Deserialize keyID
966
+ args.keyID = this.decodeString(paramsReader);
967
+ // Deserialize counterparty
968
+ args.counterparty = this.decodeCounterparty(paramsReader);
969
+ // Deserialize privilege parameters
1260
970
  const privilegedFlag = paramsReader.readInt8();
1261
971
  if (privilegedFlag === -1) {
1262
972
  args.privileged = undefined;
@@ -1265,208 +975,24 @@ class WalletWireProcessor {
1265
975
  args.privileged = privilegedFlag === 1;
1266
976
  }
1267
977
  const privilegedReasonLength = paramsReader.readInt8();
1268
- if (privilegedReasonLength === -1) {
1269
- args.privilegedReason = undefined;
1270
- }
1271
- else {
978
+ if (privilegedReasonLength !== -1) {
1272
979
  const privilegedReasonBytes = paramsReader.read(privilegedReasonLength);
1273
980
  args.privilegedReason = index_js_1.Utils.toUTF8(privilegedReasonBytes);
1274
981
  }
1275
- // Read counterparty public key
1276
- const counterpartyBytes = paramsReader.read(33);
1277
- args.counterparty = index_js_1.Utils.toHex(counterpartyBytes);
1278
- // Read verifier public key
1279
- const verifierBytes = paramsReader.read(33);
1280
- args.verifier = index_js_1.Utils.toHex(verifierBytes);
1281
- // Call the method
1282
- const revealResult = await this.wallet.revealCounterpartyKeyLinkage(args, originator);
1283
- // Serialize the result
1284
- const resultWriter = new index_js_1.Utils.Writer();
1285
- // Write prover
1286
- resultWriter.write(index_js_1.Utils.toArray(revealResult.prover, 'hex'));
1287
- // Write verifier
1288
- resultWriter.write(index_js_1.Utils.toArray(revealResult.verifier, 'hex'));
1289
- // Write counterparty
1290
- resultWriter.write(index_js_1.Utils.toArray(revealResult.counterparty, 'hex'));
1291
- // Write revelationTime
1292
- const revelationTimeBytes = index_js_1.Utils.toArray(revealResult.revelationTime, 'utf8');
1293
- resultWriter.writeVarIntNum(revelationTimeBytes.length);
1294
- resultWriter.write(revelationTimeBytes);
1295
- // Write encryptedLinkage
1296
- resultWriter.writeVarIntNum(revealResult.encryptedLinkage.length);
1297
- resultWriter.write(revealResult.encryptedLinkage);
1298
- // Write encryptedLinkageProof
1299
- resultWriter.writeVarIntNum(revealResult.encryptedLinkageProof.length);
1300
- resultWriter.write(revealResult.encryptedLinkageProof);
1301
- // Return success code and result
1302
- const responseWriter = new index_js_1.Utils.Writer();
1303
- responseWriter.writeUInt8(0); // errorByte = 0
1304
- responseWriter.write(resultWriter.toArray());
1305
- return responseWriter.toArray();
1306
- }
1307
- case 'revealSpecificKeyLinkage':
1308
- {
1309
- // Deserialize key-related parameters and privileged parameters
1310
- const args = this.decodeKeyRelatedParams(paramsReader);
1311
- // Read verifier public key
1312
- const verifierBytes = paramsReader.read(33);
1313
- args.verifier = index_js_1.Utils.toHex(verifierBytes);
1314
- // Call the method
1315
- const revealResult = await this.wallet.revealSpecificKeyLinkage(args, originator);
1316
- // Serialize the result
1317
- const resultWriter = new index_js_1.Utils.Writer();
1318
- // Write prover
1319
- resultWriter.write(index_js_1.Utils.toArray(revealResult.prover, 'hex'));
1320
- // Write verifier
1321
- resultWriter.write(index_js_1.Utils.toArray(revealResult.verifier, 'hex'));
1322
- // Write counterparty
1323
- resultWriter.write(index_js_1.Utils.toArray(revealResult.counterparty, 'hex'));
1324
- // Write securityLevel
1325
- resultWriter.writeUInt8(revealResult.protocolID[0]);
1326
- // Write protocol string
1327
- const protocolBytesOut = index_js_1.Utils.toArray(revealResult.protocolID[1], 'utf8');
1328
- resultWriter.writeVarIntNum(protocolBytesOut.length);
1329
- resultWriter.write(protocolBytesOut);
1330
- // Write keyID
1331
- const keyIDBytesOut = index_js_1.Utils.toArray(revealResult.keyID, 'utf8');
1332
- resultWriter.writeVarIntNum(keyIDBytesOut.length);
1333
- resultWriter.write(keyIDBytesOut);
1334
- // Write encryptedLinkage
1335
- resultWriter.writeVarIntNum(revealResult.encryptedLinkage.length);
1336
- resultWriter.write(revealResult.encryptedLinkage);
1337
- // Write encryptedLinkageProof
1338
- resultWriter.writeVarIntNum(revealResult.encryptedLinkageProof.length);
1339
- resultWriter.write(revealResult.encryptedLinkageProof);
1340
- // Write proofType
1341
- resultWriter.writeUInt8(revealResult.proofType);
1342
- // Return success code and result
1343
- const responseWriter = new index_js_1.Utils.Writer();
1344
- responseWriter.writeUInt8(0); // errorByte = 0
1345
- responseWriter.write(resultWriter.toArray());
1346
- return responseWriter.toArray();
1347
- }
1348
- case 'acquireCertificate':
1349
- {
1350
- const args = {};
1351
- // Read args.type
1352
- const typeBytes = paramsReader.read(32);
1353
- args.type = index_js_1.Utils.toBase64(typeBytes);
1354
- // args.certifier
1355
- const certifierBytes = paramsReader.read(33);
1356
- args.certifier = index_js_1.Utils.toHex(certifierBytes);
1357
- // Read fields
1358
- const fieldsLength = paramsReader.readVarIntNum();
1359
- args.fields = {};
1360
- for (let i = 0; i < fieldsLength; i++) {
1361
- const fieldNameLength = paramsReader.readVarIntNum();
1362
- const fieldNameBytes = paramsReader.read(fieldNameLength);
1363
- const fieldName = index_js_1.Utils.toUTF8(fieldNameBytes);
1364
- const fieldValueLength = paramsReader.readVarIntNum();
1365
- const fieldValueBytes = paramsReader.read(fieldValueLength);
1366
- const fieldValue = index_js_1.Utils.toUTF8(fieldValueBytes);
1367
- args.fields[fieldName] = fieldValue;
1368
- }
1369
- // Read privileged parameters
1370
- const privilegedFlag = paramsReader.readInt8();
1371
- if (privilegedFlag === -1) {
1372
- args.privileged = undefined;
1373
- }
1374
982
  else {
1375
- args.privileged = privilegedFlag === 1;
1376
- }
1377
- const privilegedReasonLength = paramsReader.readInt8();
1378
- if (privilegedReasonLength === -1) {
1379
983
  args.privilegedReason = undefined;
1380
984
  }
1381
- else {
1382
- const privilegedReasonBytes = paramsReader.read(privilegedReasonLength);
1383
- args.privilegedReason = index_js_1.Utils.toUTF8(privilegedReasonBytes);
1384
- }
1385
- // Read acquisitionProtocol
1386
- const acquisitionProtocolFlag = paramsReader.readUInt8();
1387
- args.acquisitionProtocol = acquisitionProtocolFlag === 1 ? 'direct' : 'issuance';
1388
- if (args.acquisitionProtocol === 'direct') {
1389
- // args.serialNumber
1390
- const serialNumberBytes = paramsReader.read(32);
1391
- args.serialNumber = index_js_1.Utils.toBase64(serialNumberBytes);
1392
- // args.revocationOutpoint
1393
- args.revocationOutpoint = this.decodeOutpoint(paramsReader);
1394
- // args.signature
1395
- const signatureLength = paramsReader.readVarIntNum();
1396
- const signatureBytes = paramsReader.read(signatureLength);
1397
- args.signature = index_js_1.Utils.toHex(signatureBytes);
1398
- // args.keyringRevealer
1399
- const keyringRevealerIdentifier = paramsReader.readUInt8();
1400
- if (keyringRevealerIdentifier === 11) {
1401
- args.keyringRevealer = 'certifier';
1402
- }
1403
- else {
1404
- const keyringRevealerBytes = [keyringRevealerIdentifier].concat(paramsReader.read(32));
1405
- args.keyringRevealer = index_js_1.Utils.toHex(keyringRevealerBytes);
1406
- }
1407
- // args.keyringForSubject
1408
- const keyringEntriesLength = paramsReader.readVarIntNum();
1409
- args.keyringForSubject = {};
1410
- for (let i = 0; i < keyringEntriesLength; i++) {
1411
- const fieldKeyLength = paramsReader.readVarIntNum();
1412
- const fieldKeyBytes = paramsReader.read(fieldKeyLength);
1413
- const fieldKey = index_js_1.Utils.toUTF8(fieldKeyBytes);
1414
- const fieldValueLength = paramsReader.readVarIntNum();
1415
- const fieldValueBytes = paramsReader.read(fieldValueLength);
1416
- const fieldValue = index_js_1.Utils.toBase64(fieldValueBytes);
1417
- args.keyringForSubject[fieldKey] = fieldValue;
1418
- }
1419
- }
1420
- else {
1421
- // args.certifierUrl
1422
- const certifierUrlLength = paramsReader.readVarIntNum();
1423
- const certifierUrlBytes = paramsReader.read(certifierUrlLength);
1424
- args.certifierUrl = index_js_1.Utils.toUTF8(certifierUrlBytes);
1425
- }
1426
- // Call the method
1427
- const acquireResult = await this.wallet.acquireCertificate(args, originator);
1428
- // Serialize the certificate (assuming Certificate class is available)
1429
- const cert = new Certificate_js_1.default(acquireResult.type, acquireResult.serialNumber, acquireResult.subject, acquireResult.certifier, acquireResult.revocationOutpoint, acquireResult.fields, acquireResult.signature);
1430
- const certBin = cert.toBinary();
1431
- // Return success code and certificate binary
1432
- const responseWriter = new index_js_1.Utils.Writer();
1433
- responseWriter.writeUInt8(0); // errorByte = 0
1434
- responseWriter.write(certBin);
1435
- return responseWriter.toArray();
1436
- }
1437
- case 'listCertificates':
1438
- {
1439
- const args = {};
1440
- // Read certifiers
1441
- const certifiersLength = paramsReader.readVarIntNum();
1442
- args.certifiers = [];
1443
- for (let i = 0; i < certifiersLength; i++) {
1444
- const certifierBytes = paramsReader.read(33);
1445
- args.certifiers.push(index_js_1.Utils.toHex(certifierBytes));
1446
- }
1447
- // Read types
1448
- const typesLength = paramsReader.readVarIntNum();
1449
- args.types = [];
1450
- for (let i = 0; i < typesLength; i++) {
1451
- const typeBytes = paramsReader.read(32);
1452
- args.types.push(index_js_1.Utils.toBase64(typeBytes));
1453
- }
1454
- // Read limit and offset
1455
- const limit = paramsReader.readVarIntNum();
1456
- if (limit >= 0) {
1457
- args.limit = limit;
1458
- }
1459
- else {
1460
- args.limit = undefined;
1461
- }
1462
- const offset = paramsReader.readVarIntNum();
1463
- if (offset >= 0) {
1464
- args.offset = offset;
985
+ // Deserialize forSelf
986
+ const forSelfFlag = paramsReader.readInt8();
987
+ if (forSelfFlag === -1) {
988
+ args.forSelf = undefined;
1465
989
  }
1466
990
  else {
1467
- args.offset = undefined;
991
+ args.forSelf = forSelfFlag === 1;
1468
992
  }
1469
- // Read privileged parameters
993
+ }
994
+ else {
995
+ // Deserialize privilege parameters
1470
996
  const privilegedFlag = paramsReader.readInt8();
1471
997
  if (privilegedFlag === -1) {
1472
998
  args.privileged = undefined;
@@ -1475,237 +1001,689 @@ class WalletWireProcessor {
1475
1001
  args.privileged = privilegedFlag === 1;
1476
1002
  }
1477
1003
  const privilegedReasonLength = paramsReader.readInt8();
1478
- if (privilegedReasonLength === -1) {
1479
- args.privilegedReason = undefined;
1480
- }
1481
- else {
1004
+ if (privilegedReasonLength !== -1) {
1482
1005
  const privilegedReasonBytes = paramsReader.read(privilegedReasonLength);
1483
1006
  args.privilegedReason = index_js_1.Utils.toUTF8(privilegedReasonBytes);
1484
1007
  }
1485
- // Call the method
1486
- const listResult = await this.wallet.listCertificates(args, originator);
1487
- // Serialize the result
1488
- const resultWriter = new index_js_1.Utils.Writer();
1489
- // totalCertificates
1490
- resultWriter.writeVarIntNum(listResult.totalCertificates);
1491
- // certificates
1492
- for (const cert of listResult.certificates) {
1493
- const certificate = new Certificate_js_1.default(cert.type, cert.serialNumber, cert.subject, cert.certifier, cert.revocationOutpoint, cert.fields, cert.signature);
1494
- const certBin = certificate.toBinary();
1495
- // Write certificate binary length and data
1496
- resultWriter.writeVarIntNum(certBin.length);
1497
- resultWriter.write(certBin);
1498
- }
1499
- // Return the response
1500
- const responseWriter = new index_js_1.Utils.Writer();
1501
- responseWriter.writeUInt8(0); // errorByte = 0
1502
- responseWriter.write(resultWriter.toArray());
1503
- return responseWriter.toArray();
1504
- }
1505
- case 'proveCertificate':
1506
- {
1507
- const args = {};
1508
- // Read certificate
1509
- const cert = {};
1510
- // Read type
1511
- const typeBytes = paramsReader.read(32);
1512
- cert.type = index_js_1.Utils.toBase64(typeBytes);
1513
- // Read subject
1514
- const subjectBytes = paramsReader.read(33);
1515
- cert.subject = index_js_1.Utils.toHex(subjectBytes);
1516
- // Read serialNumber
1517
- const serialNumberBytes = paramsReader.read(32);
1518
- cert.serialNumber = index_js_1.Utils.toBase64(serialNumberBytes);
1519
- // Read certifier
1520
- const certifierBytes = paramsReader.read(33);
1521
- cert.certifier = index_js_1.Utils.toHex(certifierBytes);
1522
- // Read revocationOutpoint
1523
- cert.revocationOutpoint = this.decodeOutpoint(paramsReader);
1524
- // Read signature
1525
- const signatureLength = paramsReader.readVarIntNum();
1526
- const signatureBytes = paramsReader.read(signatureLength);
1527
- cert.signature = index_js_1.Utils.toHex(signatureBytes);
1528
- // Read fields
1529
- const fieldsLength = paramsReader.readVarIntNum();
1530
- cert.fields = {};
1531
- for (let i = 0; i < fieldsLength; i++) {
1532
- const fieldNameLength = paramsReader.readVarIntNum();
1533
- const fieldNameBytes = paramsReader.read(fieldNameLength);
1534
- const fieldName = index_js_1.Utils.toUTF8(fieldNameBytes);
1535
- const fieldValueLength = paramsReader.readVarIntNum();
1536
- const fieldValueBytes = paramsReader.read(fieldValueLength);
1537
- const fieldValue = index_js_1.Utils.toUTF8(fieldValueBytes);
1538
- cert.fields[fieldName] = fieldValue;
1539
- }
1540
- args.certificate = cert;
1541
- // Read fields to reveal
1542
- const fieldsToRevealLength = paramsReader.readVarIntNum();
1543
- args.fieldsToReveal = [];
1544
- for (let i = 0; i < fieldsToRevealLength; i++) {
1545
- const fieldNameLength = paramsReader.readVarIntNum();
1546
- const fieldNameBytes = paramsReader.read(fieldNameLength);
1547
- const fieldName = index_js_1.Utils.toUTF8(fieldNameBytes);
1548
- args.fieldsToReveal.push(fieldName);
1549
- }
1550
- // Read verifier
1551
- const verifierBytes = paramsReader.read(33);
1552
- args.verifier = index_js_1.Utils.toHex(verifierBytes);
1553
- // Read privileged parameters
1554
- const privilegedFlag = paramsReader.readInt8();
1555
- if (privilegedFlag === -1) {
1556
- args.privileged = undefined;
1557
- }
1558
1008
  else {
1559
- args.privileged = privilegedFlag === 1;
1560
- }
1561
- const privilegedReasonLength = paramsReader.readInt8();
1562
- if (privilegedReasonLength === -1) {
1563
1009
  args.privilegedReason = undefined;
1564
1010
  }
1565
- else {
1566
- const privilegedReasonBytes = paramsReader.read(privilegedReasonLength);
1567
- args.privilegedReason = index_js_1.Utils.toUTF8(privilegedReasonBytes);
1568
- }
1569
- // Call the method
1570
- const proveResult = await this.wallet.proveCertificate(args, originator);
1571
- // Serialize keyringForVerifier
1572
- const resultWriter = new index_js_1.Utils.Writer();
1573
- const keyringEntries = Object.entries(proveResult.keyringForVerifier);
1574
- resultWriter.writeVarIntNum(keyringEntries.length);
1575
- for (const [fieldName, fieldValue] of keyringEntries) {
1576
- const fieldNameBytes = index_js_1.Utils.toArray(fieldName, 'utf8');
1577
- resultWriter.writeVarIntNum(fieldNameBytes.length);
1578
- resultWriter.write(fieldNameBytes);
1579
- const fieldValueBytes = index_js_1.Utils.toArray(fieldValue, 'base64');
1580
- resultWriter.writeVarIntNum(fieldValueBytes.length);
1581
- resultWriter.write(fieldValueBytes);
1582
- }
1583
- // Return the response
1584
- const responseWriter = new index_js_1.Utils.Writer();
1585
- responseWriter.writeUInt8(0); // errorByte = 0
1586
- responseWriter.write(resultWriter.toArray());
1587
- return responseWriter.toArray();
1588
- }
1589
- case 'relinquishCertificate':
1590
- {
1591
- const args = {};
1592
- // Read type
1593
- const typeBytes = paramsReader.read(32);
1594
- args.type = index_js_1.Utils.toBase64(typeBytes);
1595
- // Read serialNumber
1011
+ }
1012
+ // Deserialize seekPermission
1013
+ const seekPermission = paramsReader.readInt8();
1014
+ if (seekPermission >= 0) {
1015
+ args.seekPermission = seekPermission === 1;
1016
+ }
1017
+ else {
1018
+ args.seekPermission = undefined;
1019
+ }
1020
+ // Call the method
1021
+ const getPublicKeyResult = await this.wallet.getPublicKey(args, originator);
1022
+ // Serialize the result
1023
+ const responseWriter = new index_js_1.Utils.Writer();
1024
+ responseWriter.writeUInt8(0); // errorByte = 0
1025
+ const publicKeyBytes = index_js_1.Utils.toArray(getPublicKeyResult.publicKey, 'hex');
1026
+ responseWriter.write(publicKeyBytes);
1027
+ return responseWriter.toArray();
1028
+ }
1029
+ case 'encrypt': {
1030
+ const args = this.decodeKeyRelatedParams(paramsReader);
1031
+ // Deserialize plaintext
1032
+ const plaintextLength = paramsReader.readVarIntNum();
1033
+ args.plaintext = paramsReader.read(plaintextLength);
1034
+ // Deserialize seekPermission
1035
+ const seekPermission = paramsReader.readInt8();
1036
+ if (seekPermission >= 0) {
1037
+ args.seekPermission = seekPermission === 1;
1038
+ }
1039
+ else {
1040
+ args.seekPermission = undefined;
1041
+ }
1042
+ // Call the method
1043
+ const encryptResult = await this.wallet.encrypt(args, originator);
1044
+ // Serialize the result
1045
+ const responseWriter = new index_js_1.Utils.Writer();
1046
+ responseWriter.writeUInt8(0); // errorByte = 0
1047
+ responseWriter.write(encryptResult.ciphertext);
1048
+ return responseWriter.toArray();
1049
+ }
1050
+ case 'decrypt': {
1051
+ const args = this.decodeKeyRelatedParams(paramsReader);
1052
+ // Deserialize ciphertext
1053
+ const ciphertextLength = paramsReader.readVarIntNum();
1054
+ args.ciphertext = paramsReader.read(ciphertextLength);
1055
+ // Deserialize seekPermission
1056
+ const seekPermission = paramsReader.readInt8();
1057
+ if (seekPermission >= 0) {
1058
+ args.seekPermission = seekPermission === 1;
1059
+ }
1060
+ else {
1061
+ args.seekPermission = undefined;
1062
+ }
1063
+ // Call the method
1064
+ const decryptResult = await this.wallet.decrypt(args, originator);
1065
+ // Serialize the result
1066
+ const responseWriter = new index_js_1.Utils.Writer();
1067
+ responseWriter.writeUInt8(0); // errorByte = 0
1068
+ responseWriter.write(decryptResult.plaintext);
1069
+ return responseWriter.toArray();
1070
+ }
1071
+ case 'createHmac': {
1072
+ const args = this.decodeKeyRelatedParams(paramsReader);
1073
+ // Deserialize data
1074
+ const dataLength = paramsReader.readVarIntNum();
1075
+ args.data = paramsReader.read(dataLength);
1076
+ // Deserialize seekPermission
1077
+ const seekPermission = paramsReader.readInt8();
1078
+ if (seekPermission >= 0) {
1079
+ args.seekPermission = seekPermission === 1;
1080
+ }
1081
+ else {
1082
+ args.seekPermission = undefined;
1083
+ }
1084
+ // Call the method
1085
+ const createHmacResult = await this.wallet.createHmac(args, originator);
1086
+ // Serialize the result
1087
+ const responseWriter = new index_js_1.Utils.Writer();
1088
+ responseWriter.writeUInt8(0); // errorByte = 0
1089
+ responseWriter.write(createHmacResult.hmac);
1090
+ return responseWriter.toArray();
1091
+ }
1092
+ case 'verifyHmac': {
1093
+ const args = this.decodeKeyRelatedParams(paramsReader);
1094
+ // Deserialize hmac
1095
+ args.hmac = paramsReader.read(32);
1096
+ // Deserialize data
1097
+ const dataLength = paramsReader.readVarIntNum();
1098
+ args.data = paramsReader.read(dataLength);
1099
+ // Deserialize seekPermission
1100
+ const seekPermission = paramsReader.readInt8();
1101
+ if (seekPermission >= 0) {
1102
+ args.seekPermission = seekPermission === 1;
1103
+ }
1104
+ else {
1105
+ args.seekPermission = undefined;
1106
+ }
1107
+ // Call the method
1108
+ await this.wallet.verifyHmac(args, originator);
1109
+ // Serialize the result (no data to return)
1110
+ const responseWriter = new index_js_1.Utils.Writer();
1111
+ responseWriter.writeUInt8(0); // errorByte = 0
1112
+ return responseWriter.toArray();
1113
+ }
1114
+ case 'createSignature': {
1115
+ const args = this.decodeKeyRelatedParams(paramsReader);
1116
+ // Deserialize data or hashToDirectlySign
1117
+ const dataTypeFlag = paramsReader.readUInt8();
1118
+ if (dataTypeFlag === 1) {
1119
+ const dataLength = paramsReader.readVarIntNum();
1120
+ args.data = paramsReader.read(dataLength);
1121
+ }
1122
+ else if (dataTypeFlag === 2) {
1123
+ args.hashToDirectlySign = paramsReader.read(32);
1124
+ }
1125
+ // Deserialize seekPermission
1126
+ const seekPermission = paramsReader.readInt8();
1127
+ if (seekPermission >= 0) {
1128
+ args.seekPermission = seekPermission === 1;
1129
+ }
1130
+ else {
1131
+ args.seekPermission = undefined;
1132
+ }
1133
+ // Call the method
1134
+ const createSignatureResult = await this.wallet.createSignature(args, originator);
1135
+ // Serialize the result
1136
+ const responseWriter = new index_js_1.Utils.Writer();
1137
+ responseWriter.writeUInt8(0); // errorByte = 0
1138
+ responseWriter.write(createSignatureResult.signature);
1139
+ return responseWriter.toArray();
1140
+ }
1141
+ case 'verifySignature': {
1142
+ const args = this.decodeKeyRelatedParams(paramsReader);
1143
+ // Deserialize forSelf
1144
+ const forSelfFlag = paramsReader.readInt8();
1145
+ if (forSelfFlag === -1) {
1146
+ args.forSelf = undefined;
1147
+ }
1148
+ else {
1149
+ args.forSelf = forSelfFlag === 1;
1150
+ }
1151
+ // Deserialize signature
1152
+ const signatureLength = paramsReader.readVarIntNum();
1153
+ args.signature = paramsReader.read(signatureLength);
1154
+ // Deserialize data or hashToDirectlyVerify
1155
+ const dataTypeFlag = paramsReader.readUInt8();
1156
+ if (dataTypeFlag === 1) {
1157
+ const dataLength = paramsReader.readVarIntNum();
1158
+ args.data = paramsReader.read(dataLength);
1159
+ }
1160
+ else if (dataTypeFlag === 2) {
1161
+ args.hashToDirectlyVerify = paramsReader.read(32);
1162
+ }
1163
+ // Deserialize seekPermission
1164
+ const seekPermission = paramsReader.readInt8();
1165
+ if (seekPermission >= 0) {
1166
+ args.seekPermission = seekPermission === 1;
1167
+ }
1168
+ else {
1169
+ args.seekPermission = undefined;
1170
+ }
1171
+ // Call the method
1172
+ await this.wallet.verifySignature(args, originator);
1173
+ // Serialize the result (no data to return)
1174
+ const responseWriter = new index_js_1.Utils.Writer();
1175
+ responseWriter.writeUInt8(0); // errorByte = 0
1176
+ return responseWriter.toArray();
1177
+ }
1178
+ case 'isAuthenticated': {
1179
+ // No parameters to deserialize
1180
+ // Call the method
1181
+ const isAuthenticatedResult = await this.wallet.isAuthenticated({}, originator);
1182
+ // Serialize the result
1183
+ const responseWriter = new index_js_1.Utils.Writer();
1184
+ responseWriter.writeUInt8(0); // errorByte = 0
1185
+ responseWriter.writeUInt8(isAuthenticatedResult.authenticated ? 1 : 0);
1186
+ return responseWriter.toArray();
1187
+ }
1188
+ case 'waitForAuthentication': {
1189
+ // No parameters to deserialize
1190
+ // Call the method
1191
+ await this.wallet.waitForAuthentication({}, originator);
1192
+ // Serialize the result (authenticated is always true)
1193
+ const responseWriter = new index_js_1.Utils.Writer();
1194
+ responseWriter.writeUInt8(0); // errorByte = 0
1195
+ return responseWriter.toArray();
1196
+ }
1197
+ case 'getHeight': {
1198
+ // No parameters to deserialize
1199
+ // Call the method
1200
+ const getHeightResult = await this.wallet.getHeight({}, originator);
1201
+ // Serialize the result
1202
+ const responseWriter = new index_js_1.Utils.Writer();
1203
+ responseWriter.writeUInt8(0); // errorByte = 0
1204
+ responseWriter.writeVarIntNum(getHeightResult.height);
1205
+ return responseWriter.toArray();
1206
+ }
1207
+ case 'getHeaderForHeight': {
1208
+ const args = {};
1209
+ // Deserialize height
1210
+ args.height = paramsReader.readVarIntNum();
1211
+ // Call the method
1212
+ const getHeaderResult = await this.wallet.getHeaderForHeight(args, originator);
1213
+ // Serialize the result
1214
+ const responseWriter = new index_js_1.Utils.Writer();
1215
+ responseWriter.writeUInt8(0); // errorByte = 0
1216
+ const headerBytes = index_js_1.Utils.toArray(getHeaderResult.header, 'hex');
1217
+ responseWriter.write(headerBytes);
1218
+ return responseWriter.toArray();
1219
+ }
1220
+ case 'getNetwork': {
1221
+ // No parameters to deserialize
1222
+ // Call the method
1223
+ const getNetworkResult = await this.wallet.getNetwork({}, originator);
1224
+ // Serialize the result
1225
+ const responseWriter = new index_js_1.Utils.Writer();
1226
+ responseWriter.writeUInt8(0); // errorByte = 0
1227
+ responseWriter.writeUInt8(getNetworkResult.network === 'mainnet' ? 0 : 1);
1228
+ return responseWriter.toArray();
1229
+ }
1230
+ case 'getVersion': {
1231
+ // No parameters to deserialize
1232
+ // Call the method
1233
+ const getVersionResult = await this.wallet.getVersion({}, originator);
1234
+ // Serialize the result
1235
+ const responseWriter = new index_js_1.Utils.Writer();
1236
+ responseWriter.writeUInt8(0); // errorByte = 0
1237
+ const versionBytes = index_js_1.Utils.toArray(getVersionResult.version, 'utf8');
1238
+ responseWriter.write(versionBytes);
1239
+ return responseWriter.toArray();
1240
+ }
1241
+ case 'revealCounterpartyKeyLinkage': {
1242
+ const args = {};
1243
+ // Read privileged parameters
1244
+ const privilegedFlag = paramsReader.readInt8();
1245
+ if (privilegedFlag === -1) {
1246
+ args.privileged = undefined;
1247
+ }
1248
+ else {
1249
+ args.privileged = privilegedFlag === 1;
1250
+ }
1251
+ const privilegedReasonLength = paramsReader.readInt8();
1252
+ if (privilegedReasonLength === -1) {
1253
+ args.privilegedReason = undefined;
1254
+ }
1255
+ else {
1256
+ const privilegedReasonBytes = paramsReader.read(privilegedReasonLength);
1257
+ args.privilegedReason = index_js_1.Utils.toUTF8(privilegedReasonBytes);
1258
+ }
1259
+ // Read counterparty public key
1260
+ const counterpartyBytes = paramsReader.read(33);
1261
+ args.counterparty = index_js_1.Utils.toHex(counterpartyBytes);
1262
+ // Read verifier public key
1263
+ const verifierBytes = paramsReader.read(33);
1264
+ args.verifier = index_js_1.Utils.toHex(verifierBytes);
1265
+ // Call the method
1266
+ const revealResult = await this.wallet.revealCounterpartyKeyLinkage(args, originator);
1267
+ // Serialize the result
1268
+ const resultWriter = new index_js_1.Utils.Writer();
1269
+ // Write prover
1270
+ resultWriter.write(index_js_1.Utils.toArray(revealResult.prover, 'hex'));
1271
+ // Write verifier
1272
+ resultWriter.write(index_js_1.Utils.toArray(revealResult.verifier, 'hex'));
1273
+ // Write counterparty
1274
+ resultWriter.write(index_js_1.Utils.toArray(revealResult.counterparty, 'hex'));
1275
+ // Write revelationTime
1276
+ const revelationTimeBytes = index_js_1.Utils.toArray(revealResult.revelationTime, 'utf8');
1277
+ resultWriter.writeVarIntNum(revelationTimeBytes.length);
1278
+ resultWriter.write(revelationTimeBytes);
1279
+ // Write encryptedLinkage
1280
+ resultWriter.writeVarIntNum(revealResult.encryptedLinkage.length);
1281
+ resultWriter.write(revealResult.encryptedLinkage);
1282
+ // Write encryptedLinkageProof
1283
+ resultWriter.writeVarIntNum(revealResult.encryptedLinkageProof.length);
1284
+ resultWriter.write(revealResult.encryptedLinkageProof);
1285
+ // Return success code and result
1286
+ const responseWriter = new index_js_1.Utils.Writer();
1287
+ responseWriter.writeUInt8(0); // errorByte = 0
1288
+ responseWriter.write(resultWriter.toArray());
1289
+ return responseWriter.toArray();
1290
+ }
1291
+ case 'revealSpecificKeyLinkage': {
1292
+ // Deserialize key-related parameters and privileged parameters
1293
+ const args = this.decodeKeyRelatedParams(paramsReader);
1294
+ // Read verifier public key
1295
+ const verifierBytes = paramsReader.read(33);
1296
+ args.verifier = index_js_1.Utils.toHex(verifierBytes);
1297
+ // Call the method
1298
+ const revealResult = await this.wallet.revealSpecificKeyLinkage(args, originator);
1299
+ // Serialize the result
1300
+ const resultWriter = new index_js_1.Utils.Writer();
1301
+ // Write prover
1302
+ resultWriter.write(index_js_1.Utils.toArray(revealResult.prover, 'hex'));
1303
+ // Write verifier
1304
+ resultWriter.write(index_js_1.Utils.toArray(revealResult.verifier, 'hex'));
1305
+ // Write counterparty
1306
+ resultWriter.write(index_js_1.Utils.toArray(revealResult.counterparty, 'hex'));
1307
+ // Write securityLevel
1308
+ resultWriter.writeUInt8(revealResult.protocolID[0]);
1309
+ // Write protocol string
1310
+ const protocolBytesOut = index_js_1.Utils.toArray(revealResult.protocolID[1], 'utf8');
1311
+ resultWriter.writeVarIntNum(protocolBytesOut.length);
1312
+ resultWriter.write(protocolBytesOut);
1313
+ // Write keyID
1314
+ const keyIDBytesOut = index_js_1.Utils.toArray(revealResult.keyID, 'utf8');
1315
+ resultWriter.writeVarIntNum(keyIDBytesOut.length);
1316
+ resultWriter.write(keyIDBytesOut);
1317
+ // Write encryptedLinkage
1318
+ resultWriter.writeVarIntNum(revealResult.encryptedLinkage.length);
1319
+ resultWriter.write(revealResult.encryptedLinkage);
1320
+ // Write encryptedLinkageProof
1321
+ resultWriter.writeVarIntNum(revealResult.encryptedLinkageProof.length);
1322
+ resultWriter.write(revealResult.encryptedLinkageProof);
1323
+ // Write proofType
1324
+ resultWriter.writeUInt8(revealResult.proofType);
1325
+ // Return success code and result
1326
+ const responseWriter = new index_js_1.Utils.Writer();
1327
+ responseWriter.writeUInt8(0); // errorByte = 0
1328
+ responseWriter.write(resultWriter.toArray());
1329
+ return responseWriter.toArray();
1330
+ }
1331
+ case 'acquireCertificate': {
1332
+ const args = {};
1333
+ // Read args.type
1334
+ const typeBytes = paramsReader.read(32);
1335
+ args.type = index_js_1.Utils.toBase64(typeBytes);
1336
+ // args.certifier
1337
+ const certifierBytes = paramsReader.read(33);
1338
+ args.certifier = index_js_1.Utils.toHex(certifierBytes);
1339
+ // Read fields
1340
+ const fieldsLength = paramsReader.readVarIntNum();
1341
+ args.fields = {};
1342
+ for (let i = 0; i < fieldsLength; i++) {
1343
+ const fieldNameLength = paramsReader.readVarIntNum();
1344
+ const fieldNameBytes = paramsReader.read(fieldNameLength);
1345
+ const fieldName = index_js_1.Utils.toUTF8(fieldNameBytes);
1346
+ const fieldValueLength = paramsReader.readVarIntNum();
1347
+ const fieldValueBytes = paramsReader.read(fieldValueLength);
1348
+ const fieldValue = index_js_1.Utils.toUTF8(fieldValueBytes);
1349
+ args.fields[fieldName] = fieldValue;
1350
+ }
1351
+ // Read privileged parameters
1352
+ const privilegedFlag = paramsReader.readInt8();
1353
+ if (privilegedFlag === -1) {
1354
+ args.privileged = undefined;
1355
+ }
1356
+ else {
1357
+ args.privileged = privilegedFlag === 1;
1358
+ }
1359
+ const privilegedReasonLength = paramsReader.readInt8();
1360
+ if (privilegedReasonLength === -1) {
1361
+ args.privilegedReason = undefined;
1362
+ }
1363
+ else {
1364
+ const privilegedReasonBytes = paramsReader.read(privilegedReasonLength);
1365
+ args.privilegedReason = index_js_1.Utils.toUTF8(privilegedReasonBytes);
1366
+ }
1367
+ // Read acquisitionProtocol
1368
+ const acquisitionProtocolFlag = paramsReader.readUInt8();
1369
+ args.acquisitionProtocol =
1370
+ acquisitionProtocolFlag === 1 ? 'direct' : 'issuance';
1371
+ if (args.acquisitionProtocol === 'direct') {
1372
+ // args.serialNumber
1596
1373
  const serialNumberBytes = paramsReader.read(32);
1597
1374
  args.serialNumber = index_js_1.Utils.toBase64(serialNumberBytes);
1598
- // Read certifier
1599
- const certifierBytes = paramsReader.read(33);
1600
- args.certifier = index_js_1.Utils.toHex(certifierBytes);
1601
- // Call the method
1602
- await this.wallet.relinquishCertificate(args, originator);
1603
- // Return success code
1604
- const responseWriter = new index_js_1.Utils.Writer();
1605
- responseWriter.writeUInt8(0); // errorByte = 0
1606
- return responseWriter.toArray();
1607
- }
1608
- case 'discoverByIdentityKey':
1609
- {
1610
- const args = {};
1611
- // Read identityKey
1612
- const identityKeyBytes = paramsReader.read(33);
1613
- args.identityKey = index_js_1.Utils.toHex(identityKeyBytes);
1614
- // Read limit and offset
1615
- const limit = paramsReader.readVarIntNum();
1616
- if (limit >= 0) {
1617
- args.limit = limit;
1618
- }
1619
- else {
1620
- args.limit = undefined;
1621
- }
1622
- const offset = paramsReader.readVarIntNum();
1623
- if (offset >= 0) {
1624
- args.offset = offset;
1375
+ // args.revocationOutpoint
1376
+ args.revocationOutpoint = this.decodeOutpoint(paramsReader);
1377
+ // args.signature
1378
+ const signatureLength = paramsReader.readVarIntNum();
1379
+ const signatureBytes = paramsReader.read(signatureLength);
1380
+ args.signature = index_js_1.Utils.toHex(signatureBytes);
1381
+ // args.keyringRevealer
1382
+ const keyringRevealerIdentifier = paramsReader.readUInt8();
1383
+ if (keyringRevealerIdentifier === 11) {
1384
+ args.keyringRevealer = 'certifier';
1625
1385
  }
1626
1386
  else {
1627
- args.offset = undefined;
1628
- }
1629
- // Deserialize seekPermission
1630
- const seekPermission = paramsReader.readInt8();
1631
- if (seekPermission >= 0) {
1632
- args.seekPermission = seekPermission === 1;
1387
+ const keyringRevealerBytes = [keyringRevealerIdentifier].concat(paramsReader.read(32));
1388
+ args.keyringRevealer = index_js_1.Utils.toHex(keyringRevealerBytes);
1633
1389
  }
1634
- else {
1635
- args.seekPermission = undefined;
1636
- }
1637
- // Call the method
1638
- const discoverResult = await this.wallet.discoverByIdentityKey(args, originator);
1639
- // Serialize the result
1640
- const result = this.serializeDiscoveryResult(discoverResult);
1641
- // Return the response
1642
- const responseWriter = new index_js_1.Utils.Writer();
1643
- responseWriter.writeUInt8(0); // errorByte = 0
1644
- responseWriter.write(result);
1645
- return responseWriter.toArray();
1646
- }
1647
- case 'discoverByAttributes':
1648
- {
1649
- const args = {};
1650
- // Read attributes
1651
- const attributesLength = paramsReader.readVarIntNum();
1652
- args.attributes = {};
1653
- for (let i = 0; i < attributesLength; i++) {
1390
+ // args.keyringForSubject
1391
+ const keyringEntriesLength = paramsReader.readVarIntNum();
1392
+ args.keyringForSubject = {};
1393
+ for (let i = 0; i < keyringEntriesLength; i++) {
1654
1394
  const fieldKeyLength = paramsReader.readVarIntNum();
1655
1395
  const fieldKeyBytes = paramsReader.read(fieldKeyLength);
1656
1396
  const fieldKey = index_js_1.Utils.toUTF8(fieldKeyBytes);
1657
1397
  const fieldValueLength = paramsReader.readVarIntNum();
1658
1398
  const fieldValueBytes = paramsReader.read(fieldValueLength);
1659
- const fieldValue = index_js_1.Utils.toUTF8(fieldValueBytes);
1660
- args.attributes[fieldKey] = fieldValue;
1661
- }
1662
- // Read limit and offset
1663
- const limit = paramsReader.readVarIntNum();
1664
- if (limit >= 0) {
1665
- args.limit = limit;
1666
- }
1667
- else {
1668
- args.limit = undefined;
1669
- }
1670
- const offset = paramsReader.readVarIntNum();
1671
- if (offset >= 0) {
1672
- args.offset = offset;
1673
- }
1674
- else {
1675
- args.offset = undefined;
1676
- }
1677
- // Deserialize seekPermission
1678
- const seekPermission = paramsReader.readInt8();
1679
- if (seekPermission >= 0) {
1680
- args.seekPermission = seekPermission === 1;
1399
+ const fieldValue = index_js_1.Utils.toBase64(fieldValueBytes);
1400
+ args.keyringForSubject[fieldKey] = fieldValue;
1681
1401
  }
1682
- else {
1683
- args.seekPermission = undefined;
1684
- }
1685
- // Call the method
1686
- const discoverResult = await this.wallet.discoverByAttributes(args, originator);
1687
- // Serialize the result
1688
- const result = this.serializeDiscoveryResult(discoverResult);
1689
- // Return the response
1690
- const responseWriter = new index_js_1.Utils.Writer();
1691
- responseWriter.writeUInt8(0); // errorByte = 0
1692
- responseWriter.write(result);
1693
- return responseWriter.toArray();
1694
1402
  }
1403
+ else {
1404
+ // args.certifierUrl
1405
+ const certifierUrlLength = paramsReader.readVarIntNum();
1406
+ const certifierUrlBytes = paramsReader.read(certifierUrlLength);
1407
+ args.certifierUrl = index_js_1.Utils.toUTF8(certifierUrlBytes);
1408
+ }
1409
+ // Call the method
1410
+ const acquireResult = await this.wallet.acquireCertificate(args, originator);
1411
+ // Serialize the certificate (assuming Certificate class is available)
1412
+ const cert = new Certificate_js_1.default(acquireResult.type, acquireResult.serialNumber, acquireResult.subject, acquireResult.certifier, acquireResult.revocationOutpoint, acquireResult.fields, acquireResult.signature);
1413
+ const certBin = cert.toBinary();
1414
+ // Return success code and certificate binary
1415
+ const responseWriter = new index_js_1.Utils.Writer();
1416
+ responseWriter.writeUInt8(0); // errorByte = 0
1417
+ responseWriter.write(certBin);
1418
+ return responseWriter.toArray();
1419
+ }
1420
+ case 'listCertificates': {
1421
+ const args = {};
1422
+ // Read certifiers
1423
+ const certifiersLength = paramsReader.readVarIntNum();
1424
+ args.certifiers = [];
1425
+ for (let i = 0; i < certifiersLength; i++) {
1426
+ const certifierBytes = paramsReader.read(33);
1427
+ args.certifiers.push(index_js_1.Utils.toHex(certifierBytes));
1428
+ }
1429
+ // Read types
1430
+ const typesLength = paramsReader.readVarIntNum();
1431
+ args.types = [];
1432
+ for (let i = 0; i < typesLength; i++) {
1433
+ const typeBytes = paramsReader.read(32);
1434
+ args.types.push(index_js_1.Utils.toBase64(typeBytes));
1435
+ }
1436
+ // Read limit and offset
1437
+ const limit = paramsReader.readVarIntNum();
1438
+ if (limit >= 0) {
1439
+ args.limit = limit;
1440
+ }
1441
+ else {
1442
+ args.limit = undefined;
1443
+ }
1444
+ const offset = paramsReader.readVarIntNum();
1445
+ if (offset >= 0) {
1446
+ args.offset = offset;
1447
+ }
1448
+ else {
1449
+ args.offset = undefined;
1450
+ }
1451
+ // Read privileged parameters
1452
+ const privilegedFlag = paramsReader.readInt8();
1453
+ if (privilegedFlag === -1) {
1454
+ args.privileged = undefined;
1455
+ }
1456
+ else {
1457
+ args.privileged = privilegedFlag === 1;
1458
+ }
1459
+ const privilegedReasonLength = paramsReader.readInt8();
1460
+ if (privilegedReasonLength === -1) {
1461
+ args.privilegedReason = undefined;
1462
+ }
1463
+ else {
1464
+ const privilegedReasonBytes = paramsReader.read(privilegedReasonLength);
1465
+ args.privilegedReason = index_js_1.Utils.toUTF8(privilegedReasonBytes);
1466
+ }
1467
+ // Call the method
1468
+ const listResult = await this.wallet.listCertificates(args, originator);
1469
+ // Serialize the result
1470
+ const resultWriter = new index_js_1.Utils.Writer();
1471
+ // totalCertificates
1472
+ resultWriter.writeVarIntNum(listResult.totalCertificates);
1473
+ // certificates
1474
+ for (const cert of listResult.certificates) {
1475
+ const certificate = new Certificate_js_1.default(cert.type, cert.serialNumber, cert.subject, cert.certifier, cert.revocationOutpoint, cert.fields, cert.signature);
1476
+ const certBin = certificate.toBinary();
1477
+ // Write certificate binary length and data
1478
+ resultWriter.writeVarIntNum(certBin.length);
1479
+ resultWriter.write(certBin);
1480
+ }
1481
+ // Return the response
1482
+ const responseWriter = new index_js_1.Utils.Writer();
1483
+ responseWriter.writeUInt8(0); // errorByte = 0
1484
+ responseWriter.write(resultWriter.toArray());
1485
+ return responseWriter.toArray();
1486
+ }
1487
+ case 'proveCertificate': {
1488
+ const args = {};
1489
+ // Read certificate
1490
+ const cert = {};
1491
+ // Read type
1492
+ const typeBytes = paramsReader.read(32);
1493
+ cert.type = index_js_1.Utils.toBase64(typeBytes);
1494
+ // Read subject
1495
+ const subjectBytes = paramsReader.read(33);
1496
+ cert.subject = index_js_1.Utils.toHex(subjectBytes);
1497
+ // Read serialNumber
1498
+ const serialNumberBytes = paramsReader.read(32);
1499
+ cert.serialNumber = index_js_1.Utils.toBase64(serialNumberBytes);
1500
+ // Read certifier
1501
+ const certifierBytes = paramsReader.read(33);
1502
+ cert.certifier = index_js_1.Utils.toHex(certifierBytes);
1503
+ // Read revocationOutpoint
1504
+ cert.revocationOutpoint = this.decodeOutpoint(paramsReader);
1505
+ // Read signature
1506
+ const signatureLength = paramsReader.readVarIntNum();
1507
+ const signatureBytes = paramsReader.read(signatureLength);
1508
+ cert.signature = index_js_1.Utils.toHex(signatureBytes);
1509
+ // Read fields
1510
+ const fieldsLength = paramsReader.readVarIntNum();
1511
+ cert.fields = {};
1512
+ for (let i = 0; i < fieldsLength; i++) {
1513
+ const fieldNameLength = paramsReader.readVarIntNum();
1514
+ const fieldNameBytes = paramsReader.read(fieldNameLength);
1515
+ const fieldName = index_js_1.Utils.toUTF8(fieldNameBytes);
1516
+ const fieldValueLength = paramsReader.readVarIntNum();
1517
+ const fieldValueBytes = paramsReader.read(fieldValueLength);
1518
+ const fieldValue = index_js_1.Utils.toUTF8(fieldValueBytes);
1519
+ cert.fields[fieldName] = fieldValue;
1520
+ }
1521
+ args.certificate = cert;
1522
+ // Read fields to reveal
1523
+ const fieldsToRevealLength = paramsReader.readVarIntNum();
1524
+ args.fieldsToReveal = [];
1525
+ for (let i = 0; i < fieldsToRevealLength; i++) {
1526
+ const fieldNameLength = paramsReader.readVarIntNum();
1527
+ const fieldNameBytes = paramsReader.read(fieldNameLength);
1528
+ const fieldName = index_js_1.Utils.toUTF8(fieldNameBytes);
1529
+ args.fieldsToReveal.push(fieldName);
1530
+ }
1531
+ // Read verifier
1532
+ const verifierBytes = paramsReader.read(33);
1533
+ args.verifier = index_js_1.Utils.toHex(verifierBytes);
1534
+ // Read privileged parameters
1535
+ const privilegedFlag = paramsReader.readInt8();
1536
+ if (privilegedFlag === -1) {
1537
+ args.privileged = undefined;
1538
+ }
1539
+ else {
1540
+ args.privileged = privilegedFlag === 1;
1541
+ }
1542
+ const privilegedReasonLength = paramsReader.readInt8();
1543
+ if (privilegedReasonLength === -1) {
1544
+ args.privilegedReason = undefined;
1545
+ }
1546
+ else {
1547
+ const privilegedReasonBytes = paramsReader.read(privilegedReasonLength);
1548
+ args.privilegedReason = index_js_1.Utils.toUTF8(privilegedReasonBytes);
1549
+ }
1550
+ // Call the method
1551
+ const proveResult = await this.wallet.proveCertificate(args, originator);
1552
+ // Serialize keyringForVerifier
1553
+ const resultWriter = new index_js_1.Utils.Writer();
1554
+ const keyringEntries = Object.entries(proveResult.keyringForVerifier);
1555
+ resultWriter.writeVarIntNum(keyringEntries.length);
1556
+ for (const [fieldName, fieldValue] of keyringEntries) {
1557
+ const fieldNameBytes = index_js_1.Utils.toArray(fieldName, 'utf8');
1558
+ resultWriter.writeVarIntNum(fieldNameBytes.length);
1559
+ resultWriter.write(fieldNameBytes);
1560
+ const fieldValueBytes = index_js_1.Utils.toArray(fieldValue, 'base64');
1561
+ resultWriter.writeVarIntNum(fieldValueBytes.length);
1562
+ resultWriter.write(fieldValueBytes);
1563
+ }
1564
+ // Return the response
1565
+ const responseWriter = new index_js_1.Utils.Writer();
1566
+ responseWriter.writeUInt8(0); // errorByte = 0
1567
+ responseWriter.write(resultWriter.toArray());
1568
+ return responseWriter.toArray();
1569
+ }
1570
+ case 'relinquishCertificate': {
1571
+ const args = {};
1572
+ // Read type
1573
+ const typeBytes = paramsReader.read(32);
1574
+ args.type = index_js_1.Utils.toBase64(typeBytes);
1575
+ // Read serialNumber
1576
+ const serialNumberBytes = paramsReader.read(32);
1577
+ args.serialNumber = index_js_1.Utils.toBase64(serialNumberBytes);
1578
+ // Read certifier
1579
+ const certifierBytes = paramsReader.read(33);
1580
+ args.certifier = index_js_1.Utils.toHex(certifierBytes);
1581
+ // Call the method
1582
+ await this.wallet.relinquishCertificate(args, originator);
1583
+ // Return success code
1584
+ const responseWriter = new index_js_1.Utils.Writer();
1585
+ responseWriter.writeUInt8(0); // errorByte = 0
1586
+ return responseWriter.toArray();
1587
+ }
1588
+ case 'discoverByIdentityKey': {
1589
+ const args = {};
1590
+ // Read identityKey
1591
+ const identityKeyBytes = paramsReader.read(33);
1592
+ args.identityKey = index_js_1.Utils.toHex(identityKeyBytes);
1593
+ // Read limit and offset
1594
+ const limit = paramsReader.readVarIntNum();
1595
+ if (limit >= 0) {
1596
+ args.limit = limit;
1597
+ }
1598
+ else {
1599
+ args.limit = undefined;
1600
+ }
1601
+ const offset = paramsReader.readVarIntNum();
1602
+ if (offset >= 0) {
1603
+ args.offset = offset;
1604
+ }
1605
+ else {
1606
+ args.offset = undefined;
1607
+ }
1608
+ // Deserialize seekPermission
1609
+ const seekPermission = paramsReader.readInt8();
1610
+ if (seekPermission >= 0) {
1611
+ args.seekPermission = seekPermission === 1;
1612
+ }
1613
+ else {
1614
+ args.seekPermission = undefined;
1615
+ }
1616
+ // Call the method
1617
+ const discoverResult = await this.wallet.discoverByIdentityKey(args, originator);
1618
+ // Serialize the result
1619
+ const result = this.serializeDiscoveryResult(discoverResult);
1620
+ // Return the response
1621
+ const responseWriter = new index_js_1.Utils.Writer();
1622
+ responseWriter.writeUInt8(0); // errorByte = 0
1623
+ responseWriter.write(result);
1624
+ return responseWriter.toArray();
1625
+ }
1626
+ case 'discoverByAttributes': {
1627
+ const args = {};
1628
+ // Read attributes
1629
+ const attributesLength = paramsReader.readVarIntNum();
1630
+ args.attributes = {};
1631
+ for (let i = 0; i < attributesLength; i++) {
1632
+ const fieldKeyLength = paramsReader.readVarIntNum();
1633
+ const fieldKeyBytes = paramsReader.read(fieldKeyLength);
1634
+ const fieldKey = index_js_1.Utils.toUTF8(fieldKeyBytes);
1635
+ const fieldValueLength = paramsReader.readVarIntNum();
1636
+ const fieldValueBytes = paramsReader.read(fieldValueLength);
1637
+ const fieldValue = index_js_1.Utils.toUTF8(fieldValueBytes);
1638
+ args.attributes[fieldKey] = fieldValue;
1639
+ }
1640
+ // Read limit and offset
1641
+ const limit = paramsReader.readVarIntNum();
1642
+ if (limit >= 0) {
1643
+ args.limit = limit;
1644
+ }
1645
+ else {
1646
+ args.limit = undefined;
1647
+ }
1648
+ const offset = paramsReader.readVarIntNum();
1649
+ if (offset >= 0) {
1650
+ args.offset = offset;
1651
+ }
1652
+ else {
1653
+ args.offset = undefined;
1654
+ }
1655
+ // Deserialize seekPermission
1656
+ const seekPermission = paramsReader.readInt8();
1657
+ if (seekPermission >= 0) {
1658
+ args.seekPermission = seekPermission === 1;
1659
+ }
1660
+ else {
1661
+ args.seekPermission = undefined;
1662
+ }
1663
+ // Call the method
1664
+ const discoverResult = await this.wallet.discoverByAttributes(args, originator);
1665
+ // Serialize the result
1666
+ const result = this.serializeDiscoveryResult(discoverResult);
1667
+ // Return the response
1668
+ const responseWriter = new index_js_1.Utils.Writer();
1669
+ responseWriter.writeUInt8(0); // errorByte = 0
1670
+ responseWriter.write(result);
1671
+ return responseWriter.toArray();
1672
+ }
1695
1673
  default:
1696
1674
  throw new Error(`Method ${callName} not implemented`);
1697
1675
  }
1698
1676
  }
1699
1677
  catch (err) {
1700
1678
  const responseWriter = new index_js_1.Utils.Writer();
1701
- responseWriter.writeUInt8((err).code || 1); // errorCode = 1 (generic error)
1679
+ responseWriter.writeUInt8(typeof err.code === 'number' ? err.code : 1); // errorCode = 1 (generic error)
1702
1680
  // Serialize the error message
1703
- const errorMessage = err.message || 'Unknown error';
1681
+ const errorMessage = typeof err.message === 'string' ? err.message : 'Unknown error';
1704
1682
  const errorMessageBytes = index_js_1.Utils.toArray(errorMessage, 'utf8');
1705
1683
  responseWriter.writeVarIntNum(errorMessageBytes.length);
1706
1684
  responseWriter.write(errorMessageBytes);
1707
1685
  // Serialize the stack trace
1708
- const stackTrace = err.stack || '';
1686
+ const stackTrace = typeof err.stack === 'string' ? err.stack : '';
1709
1687
  const stackTraceBytes = index_js_1.Utils.toArray(stackTrace, 'utf8');
1710
1688
  responseWriter.writeVarIntNum(stackTraceBytes.length);
1711
1689
  responseWriter.write(stackTraceBytes);