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