@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
@@ -1,9 +1,8 @@
1
- import { WalletInterface } from '../Wallet.interfaces.js'
1
+ import { WalletInterface, SecurityLevel } from '../Wallet.interfaces.js'
2
2
  import WalletWire from './WalletWire.js'
3
3
  import { Utils } from '../../primitives/index.js'
4
4
  import calls from './WalletWireCalls.js'
5
5
  import Certificate from '../../auth/certificates/Certificate.js'
6
- import { SecurityLevel } from '../Wallet.interfaces.js'
7
6
 
8
7
  /**
9
8
  * Processes incoming wallet calls received over a wallet wire, with a given wallet.
@@ -38,7 +37,7 @@ export default class WalletWireProcessor implements WalletWire {
38
37
 
39
38
  // Map call code to call name
40
39
  const callName = calls[callCode] // calls is enum
41
- if (!callName) {
40
+ if (callName === undefined || callName === '') {
42
41
  // Invalid call code
43
42
  throw new Error(`Invalid call code: ${callCode}`)
44
43
  }
@@ -52,7 +51,7 @@ export default class WalletWireProcessor implements WalletWire {
52
51
  const paramsReader = messageReader // Remaining bytes
53
52
 
54
53
  switch (callName) {
55
- case 'createAction':
54
+ case 'createAction': {
56
55
  // Deserialize parameters from paramsReader
57
56
  const args: any = {}
58
57
 
@@ -82,7 +81,9 @@ export default class WalletWireProcessor implements WalletWire {
82
81
  // unlockingScript / unlockingScriptLength
83
82
  const unlockingScriptLength = paramsReader.readVarIntNum()
84
83
  if (unlockingScriptLength >= 0) {
85
- const unlockingScriptBytes = paramsReader.read(unlockingScriptLength)
84
+ const unlockingScriptBytes = paramsReader.read(
85
+ unlockingScriptLength
86
+ )
86
87
  input.unlockingScript = Utils.toHex(unlockingScriptBytes)
87
88
  } else {
88
89
  input.unlockingScript = undefined
@@ -92,7 +93,9 @@ export default class WalletWireProcessor implements WalletWire {
92
93
 
93
94
  // inputDescription
94
95
  const inputDescriptionLength = paramsReader.readVarIntNum()
95
- const inputDescriptionBytes = paramsReader.read(inputDescriptionLength)
96
+ const inputDescriptionBytes = paramsReader.read(
97
+ inputDescriptionLength
98
+ )
96
99
  input.inputDescription = Utils.toUTF8(inputDescriptionBytes)
97
100
 
98
101
  // sequenceNumber
@@ -126,7 +129,9 @@ export default class WalletWireProcessor implements WalletWire {
126
129
 
127
130
  // outputDescription
128
131
  const outputDescriptionLength = paramsReader.readVarIntNum()
129
- const outputDescriptionBytes = paramsReader.read(outputDescriptionLength)
132
+ const outputDescriptionBytes = paramsReader.read(
133
+ outputDescriptionLength
134
+ )
130
135
  output.outputDescription = Utils.toUTF8(outputDescriptionBytes)
131
136
 
132
137
  // basket
@@ -141,8 +146,12 @@ export default class WalletWireProcessor implements WalletWire {
141
146
  // customInstructions
142
147
  const customInstructionsLength = paramsReader.readVarIntNum()
143
148
  if (customInstructionsLength >= 0) {
144
- const customInstructionsBytes = paramsReader.read(customInstructionsLength)
145
- output.customInstructions = Utils.toUTF8(customInstructionsBytes)
149
+ const customInstructionsBytes = paramsReader.read(
150
+ customInstructionsLength
151
+ )
152
+ output.customInstructions = Utils.toUTF8(
153
+ customInstructionsBytes
154
+ )
146
155
  } else {
147
156
  output.customInstructions = undefined
148
157
  }
@@ -215,7 +224,8 @@ export default class WalletWireProcessor implements WalletWire {
215
224
  if (acceptDelayedBroadcastFlag === -1) {
216
225
  args.options.acceptDelayedBroadcast = undefined
217
226
  } else {
218
- args.options.acceptDelayedBroadcast = acceptDelayedBroadcastFlag === 1
227
+ args.options.acceptDelayedBroadcast =
228
+ acceptDelayedBroadcastFlag === 1
219
229
  }
220
230
 
221
231
  // trustSelf
@@ -292,13 +302,16 @@ export default class WalletWireProcessor implements WalletWire {
292
302
  }
293
303
 
294
304
  // Call the method
295
- const createActionResult = await this.wallet.createAction(args, originator)
305
+ const createActionResult = await this.wallet.createAction(
306
+ args,
307
+ originator
308
+ )
296
309
 
297
310
  // Serialize the result
298
311
  const resultWriter = new Utils.Writer()
299
312
 
300
313
  // txid
301
- if (createActionResult.txid) {
314
+ if (createActionResult.txid != null && createActionResult.txid !== '') {
302
315
  resultWriter.writeInt8(1)
303
316
  resultWriter.write(Utils.toArray(createActionResult.txid, 'hex'))
304
317
  } else {
@@ -306,7 +319,7 @@ export default class WalletWireProcessor implements WalletWire {
306
319
  }
307
320
 
308
321
  // tx
309
- if (createActionResult.tx) {
322
+ if (createActionResult.tx != null) {
310
323
  resultWriter.writeInt8(1)
311
324
  resultWriter.writeVarIntNum(createActionResult.tx.length)
312
325
  resultWriter.write(createActionResult.tx)
@@ -315,7 +328,7 @@ export default class WalletWireProcessor implements WalletWire {
315
328
  }
316
329
 
317
330
  // noSendChange
318
- if (createActionResult.noSendChange) {
331
+ if (createActionResult.noSendChange != null) {
319
332
  resultWriter.writeVarIntNum(createActionResult.noSendChange.length)
320
333
  for (const outpoint of createActionResult.noSendChange) {
321
334
  resultWriter.write(this.encodeOutpoint(outpoint))
@@ -325,8 +338,10 @@ export default class WalletWireProcessor implements WalletWire {
325
338
  }
326
339
 
327
340
  // sendWithResults
328
- if (createActionResult.sendWithResults) {
329
- resultWriter.writeVarIntNum(createActionResult.sendWithResults.length)
341
+ if (createActionResult.sendWithResults != null) {
342
+ resultWriter.writeVarIntNum(
343
+ createActionResult.sendWithResults.length
344
+ )
330
345
  for (const result of createActionResult.sendWithResults) {
331
346
  resultWriter.write(Utils.toArray(result.txid, 'hex'))
332
347
  let statusCode
@@ -340,11 +355,16 @@ export default class WalletWireProcessor implements WalletWire {
340
355
  }
341
356
 
342
357
  // signableTransaction
343
- if (createActionResult.signableTransaction) {
358
+ if (createActionResult.signableTransaction != null) {
344
359
  resultWriter.writeInt8(1)
345
- resultWriter.writeVarIntNum(createActionResult.signableTransaction.tx.length)
360
+ resultWriter.writeVarIntNum(
361
+ createActionResult.signableTransaction.tx.length
362
+ )
346
363
  resultWriter.write(createActionResult.signableTransaction.tx)
347
- const referenceBytes = Utils.toArray(createActionResult.signableTransaction.reference, 'base64')
364
+ const referenceBytes = Utils.toArray(
365
+ createActionResult.signableTransaction.reference,
366
+ 'base64'
367
+ )
348
368
  resultWriter.writeVarIntNum(referenceBytes.length)
349
369
  resultWriter.write(referenceBytes)
350
370
  } else {
@@ -356,1557 +376,1667 @@ export default class WalletWireProcessor implements WalletWire {
356
376
  responseWriter.writeUInt8(0) // errorByte = 0
357
377
  responseWriter.write(resultWriter.toArray())
358
378
  return responseWriter.toArray()
379
+ }
380
+ case 'signAction': {
381
+ const args: any = {}
359
382
 
360
- case 'signAction':
361
- {
362
- const args: any = {}
363
-
364
- // Deserialize spends
365
- const spendCount = paramsReader.readVarIntNum()
366
- args.spends = {}
367
- for (let i = 0; i < spendCount; i++) {
368
- const inputIndex = paramsReader.readVarIntNum()
369
- const spend: any = {}
370
-
371
- // unlockingScript
372
- const unlockingScriptLength = paramsReader.readVarIntNum()
373
- const unlockingScriptBytes = paramsReader.read(unlockingScriptLength)
374
- spend.unlockingScript = Utils.toHex(unlockingScriptBytes)
375
-
376
- // sequenceNumber
377
- const sequenceNumber = paramsReader.readVarIntNum()
378
- if (sequenceNumber >= 0) {
379
- spend.sequenceNumber = sequenceNumber
380
- } else {
381
- spend.sequenceNumber = undefined
382
- }
383
+ // Deserialize spends
384
+ const spendCount = paramsReader.readVarIntNum()
385
+ args.spends = {}
386
+ for (let i = 0; i < spendCount; i++) {
387
+ const inputIndex = paramsReader.readVarIntNum()
388
+ const spend: any = {}
389
+
390
+ // unlockingScript
391
+ const unlockingScriptLength = paramsReader.readVarIntNum()
392
+ const unlockingScriptBytes = paramsReader.read(
393
+ unlockingScriptLength
394
+ )
395
+ spend.unlockingScript = Utils.toHex(unlockingScriptBytes)
383
396
 
384
- args.spends[inputIndex] = spend
397
+ // sequenceNumber
398
+ const sequenceNumber = paramsReader.readVarIntNum()
399
+ if (sequenceNumber >= 0) {
400
+ spend.sequenceNumber = sequenceNumber
401
+ } else {
402
+ spend.sequenceNumber = undefined
385
403
  }
386
404
 
387
- // Deserialize reference
388
- const referenceLength = paramsReader.readVarIntNum()
389
- const referenceBytes = paramsReader.read(referenceLength)
390
- args.reference = Utils.toBase64(referenceBytes)
391
-
392
- // Deserialize options
393
- const optionsPresent = paramsReader.readInt8()
394
- if (optionsPresent === 1) {
395
- args.options = {}
396
-
397
- // acceptDelayedBroadcast
398
- const acceptDelayedBroadcastFlag = paramsReader.readInt8()
399
- if (acceptDelayedBroadcastFlag === -1) {
400
- args.options.acceptDelayedBroadcast = undefined
401
- } else {
402
- args.options.acceptDelayedBroadcast = acceptDelayedBroadcastFlag === 1
403
- }
405
+ args.spends[inputIndex] = spend
406
+ }
404
407
 
405
- // returnTXIDOnly
406
- const returnTXIDOnlyFlag = paramsReader.readInt8()
407
- if (returnTXIDOnlyFlag === -1) {
408
- args.options.returnTXIDOnly = undefined
409
- } else {
410
- args.options.returnTXIDOnly = returnTXIDOnlyFlag === 1
411
- }
408
+ // Deserialize reference
409
+ const referenceLength = paramsReader.readVarIntNum()
410
+ const referenceBytes = paramsReader.read(referenceLength)
411
+ args.reference = Utils.toBase64(referenceBytes)
412
412
 
413
- // noSend
414
- const noSendFlag = paramsReader.readInt8()
415
- if (noSendFlag === -1) {
416
- args.options.noSend = undefined
417
- } else {
418
- args.options.noSend = noSendFlag === 1
419
- }
413
+ // Deserialize options
414
+ const optionsPresent = paramsReader.readInt8()
415
+ if (optionsPresent === 1) {
416
+ args.options = {}
420
417
 
421
- // sendWith
422
- const sendWithLength = paramsReader.readVarIntNum()
423
- if (sendWithLength >= 0) {
424
- args.options.sendWith = []
425
- for (let i = 0; i < sendWithLength; i++) {
426
- const txidBytes = paramsReader.read(32)
427
- const txid = Utils.toHex(txidBytes)
428
- args.options.sendWith.push(txid)
429
- }
430
- } else {
431
- args.options.sendWith = undefined
432
- }
418
+ // acceptDelayedBroadcast
419
+ const acceptDelayedBroadcastFlag = paramsReader.readInt8()
420
+ if (acceptDelayedBroadcastFlag === -1) {
421
+ args.options.acceptDelayedBroadcast = undefined
433
422
  } else {
434
- args.options = undefined
423
+ args.options.acceptDelayedBroadcast =
424
+ acceptDelayedBroadcastFlag === 1
435
425
  }
436
426
 
437
- // Call the method
438
- const signActionResult = await this.wallet.signAction(args, originator)
439
-
440
- // Serialize the result
441
- const resultWriter = new Utils.Writer()
442
-
443
- // txid
444
- if (signActionResult.txid) {
445
- resultWriter.writeInt8(1)
446
- resultWriter.write(Utils.toArray(signActionResult.txid, 'hex'))
427
+ // returnTXIDOnly
428
+ const returnTXIDOnlyFlag = paramsReader.readInt8()
429
+ if (returnTXIDOnlyFlag === -1) {
430
+ args.options.returnTXIDOnly = undefined
447
431
  } else {
448
- resultWriter.writeInt8(0)
432
+ args.options.returnTXIDOnly = returnTXIDOnlyFlag === 1
449
433
  }
450
434
 
451
- // tx
452
- if (signActionResult.tx) {
453
- resultWriter.writeInt8(1)
454
- resultWriter.writeVarIntNum(signActionResult.tx.length)
455
- resultWriter.write(signActionResult.tx)
435
+ // noSend
436
+ const noSendFlag = paramsReader.readInt8()
437
+ if (noSendFlag === -1) {
438
+ args.options.noSend = undefined
456
439
  } else {
457
- resultWriter.writeInt8(0)
440
+ args.options.noSend = noSendFlag === 1
458
441
  }
459
442
 
460
- // sendWithResults
461
- if (signActionResult.sendWithResults) {
462
- resultWriter.writeVarIntNum(signActionResult.sendWithResults.length)
463
- for (const result of signActionResult.sendWithResults) {
464
- resultWriter.write(Utils.toArray(result.txid, 'hex'))
465
- let statusCode
466
- if (result.status === 'unproven') statusCode = 1
467
- else if (result.status === 'sending') statusCode = 2
468
- else if (result.status === 'failed') statusCode = 3
469
- resultWriter.writeInt8(statusCode)
443
+ // sendWith
444
+ const sendWithLength = paramsReader.readVarIntNum()
445
+ if (sendWithLength >= 0) {
446
+ args.options.sendWith = []
447
+ for (let i = 0; i < sendWithLength; i++) {
448
+ const txidBytes = paramsReader.read(32)
449
+ const txid = Utils.toHex(txidBytes)
450
+ args.options.sendWith.push(txid)
470
451
  }
471
452
  } else {
472
- resultWriter.writeVarIntNum(-1)
453
+ args.options.sendWith = undefined
473
454
  }
474
-
475
- // Return success code and result
476
- const responseWriter = new Utils.Writer()
477
- responseWriter.writeUInt8(0) // errorByte = 0
478
- responseWriter.write(resultWriter.toArray())
479
- return responseWriter.toArray()
455
+ } else {
456
+ args.options = undefined
480
457
  }
481
- case 'abortAction':
482
- {
483
- // Deserialize reference
484
- const referenceBytes = paramsReader.read()
485
- const reference = Utils.toBase64(referenceBytes)
486
458
 
487
- // Call the method
488
- await this.wallet.abortAction({ reference }, originator)
459
+ // Call the method
460
+ const signActionResult = await this.wallet.signAction(
461
+ args,
462
+ originator
463
+ )
464
+
465
+ // Serialize the result
466
+ const resultWriter = new Utils.Writer()
489
467
 
490
- // Return success code and result
491
- const responseWriter = new Utils.Writer()
492
- responseWriter.writeUInt8(0) // errorByte = 0
493
- return responseWriter.toArray()
468
+ // txid
469
+ if (signActionResult.txid != null && signActionResult.txid !== '') {
470
+ resultWriter.writeInt8(1)
471
+ resultWriter.write(Utils.toArray(signActionResult.txid, 'hex'))
472
+ } else {
473
+ resultWriter.writeInt8(0)
494
474
  }
495
- case 'listActions':
496
- {
497
- const args: any = {}
498
475
 
499
- // Deserialize labels
500
- const labelsLength = paramsReader.readVarIntNum()
501
- args.labels = []
502
- for (let i = 0; i < labelsLength; i++) {
503
- const labelLength = paramsReader.readVarIntNum()
504
- const labelBytes = paramsReader.read(labelLength)
505
- args.labels.push(Utils.toUTF8(labelBytes))
506
- }
476
+ // tx
477
+ if (signActionResult.tx != null) {
478
+ resultWriter.writeInt8(1)
479
+ resultWriter.writeVarIntNum(signActionResult.tx.length)
480
+ resultWriter.write(signActionResult.tx)
481
+ } else {
482
+ resultWriter.writeInt8(0)
483
+ }
507
484
 
508
- // Deserialize labelQueryMode
509
- const labelQueryModeFlag = paramsReader.readInt8()
510
- if (labelQueryModeFlag === -1) {
511
- args.labelQueryMode = undefined
512
- } else if (labelQueryModeFlag === 1) {
513
- args.labelQueryMode = 'any'
514
- } else if (labelQueryModeFlag === 2) {
515
- args.labelQueryMode = 'all'
485
+ // sendWithResults
486
+ if (signActionResult.sendWithResults != null) {
487
+ resultWriter.writeVarIntNum(
488
+ signActionResult.sendWithResults.length
489
+ )
490
+ for (const result of signActionResult.sendWithResults) {
491
+ resultWriter.write(Utils.toArray(result.txid, 'hex'))
492
+ let statusCode
493
+ if (result.status === 'unproven') statusCode = 1
494
+ else if (result.status === 'sending') statusCode = 2
495
+ else if (result.status === 'failed') statusCode = 3
496
+ resultWriter.writeInt8(statusCode)
516
497
  }
498
+ } else {
499
+ resultWriter.writeVarIntNum(-1)
500
+ }
517
501
 
518
- // Deserialize include options
519
- const includeOptionsNames = [
520
- 'includeLabels',
521
- 'includeInputs',
522
- 'includeInputSourceLockingScripts',
523
- 'includeInputUnlockingScripts',
524
- 'includeOutputs',
525
- 'includeOutputLockingScripts'
526
- ]
527
- for (const optionName of includeOptionsNames) {
528
- const optionFlag = paramsReader.readInt8()
529
- if (optionFlag === -1) {
530
- args[optionName] = undefined
531
- } else {
532
- args[optionName] = optionFlag === 1
533
- }
534
- }
502
+ // Return success code and result
503
+ const responseWriter = new Utils.Writer()
504
+ responseWriter.writeUInt8(0) // errorByte = 0
505
+ responseWriter.write(resultWriter.toArray())
506
+ return responseWriter.toArray()
507
+ }
508
+ case 'abortAction': {
509
+ // Deserialize reference
510
+ const referenceBytes = paramsReader.read()
511
+ const reference = Utils.toBase64(referenceBytes)
535
512
 
536
- // Deserialize limit
537
- const limit = paramsReader.readVarIntNum()
538
- if (limit >= 0) {
539
- args.limit = limit
540
- } else {
541
- args.limit = undefined
542
- }
513
+ // Call the method
514
+ await this.wallet.abortAction({ reference }, originator)
543
515
 
544
- // Deserialize offset
545
- const offset = paramsReader.readVarIntNum()
546
- if (offset >= 0) {
547
- args.offset = offset
548
- } else {
549
- args.offset = undefined
550
- }
516
+ // Return success code and result
517
+ const responseWriter = new Utils.Writer()
518
+ responseWriter.writeUInt8(0) // errorByte = 0
519
+ return responseWriter.toArray()
520
+ }
521
+ case 'listActions': {
522
+ const args: any = {}
523
+
524
+ // Deserialize labels
525
+ const labelsLength = paramsReader.readVarIntNum()
526
+ args.labels = []
527
+ for (let i = 0; i < labelsLength; i++) {
528
+ const labelLength = paramsReader.readVarIntNum()
529
+ const labelBytes = paramsReader.read(labelLength)
530
+ args.labels.push(Utils.toUTF8(labelBytes))
531
+ }
551
532
 
552
- // Deserialize seekPermission
553
- const seekPermission = paramsReader.readInt8()
554
- if (seekPermission >= 0) {
555
- args.seekPermission = seekPermission === 1
533
+ // Deserialize labelQueryMode
534
+ const labelQueryModeFlag = paramsReader.readInt8()
535
+ if (labelQueryModeFlag === -1) {
536
+ args.labelQueryMode = undefined
537
+ } else if (labelQueryModeFlag === 1) {
538
+ args.labelQueryMode = 'any'
539
+ } else if (labelQueryModeFlag === 2) {
540
+ args.labelQueryMode = 'all'
541
+ }
542
+
543
+ // Deserialize include options
544
+ const includeOptionsNames = [
545
+ 'includeLabels',
546
+ 'includeInputs',
547
+ 'includeInputSourceLockingScripts',
548
+ 'includeInputUnlockingScripts',
549
+ 'includeOutputs',
550
+ 'includeOutputLockingScripts'
551
+ ]
552
+ for (const optionName of includeOptionsNames) {
553
+ const optionFlag = paramsReader.readInt8()
554
+ if (optionFlag === -1) {
555
+ args[optionName] = undefined
556
556
  } else {
557
- args.seekPermission = undefined
557
+ args[optionName] = optionFlag === 1
558
558
  }
559
+ }
559
560
 
560
- // Call the method
561
- const listActionsResult = await this.wallet.listActions(args, originator)
561
+ // Deserialize limit
562
+ const limit = paramsReader.readVarIntNum()
563
+ if (limit >= 0) {
564
+ args.limit = limit
565
+ } else {
566
+ args.limit = undefined
567
+ }
562
568
 
563
- // Serialize the result
564
- const resultWriter = new Utils.Writer()
569
+ // Deserialize offset
570
+ const offset = paramsReader.readVarIntNum()
571
+ if (offset >= 0) {
572
+ args.offset = offset
573
+ } else {
574
+ args.offset = undefined
575
+ }
565
576
 
566
- // totalActions
567
- resultWriter.writeVarIntNum(listActionsResult.totalActions)
577
+ // Deserialize seekPermission
578
+ const seekPermission = paramsReader.readInt8()
579
+ if (seekPermission >= 0) {
580
+ args.seekPermission = seekPermission === 1
581
+ } else {
582
+ args.seekPermission = undefined
583
+ }
568
584
 
569
- // actions
570
- for (const action of listActionsResult.actions) {
571
- // txid
572
- resultWriter.write(Utils.toArray(action.txid, 'hex'))
585
+ // Call the method
586
+ const listActionsResult = await this.wallet.listActions(
587
+ args,
588
+ originator
589
+ )
573
590
 
574
- // satoshis
575
- resultWriter.writeVarIntNum(action.satoshis)
591
+ // Serialize the result
592
+ const resultWriter = new Utils.Writer()
576
593
 
577
- // status
578
- let statusCode
579
- switch (action.status) {
580
- case 'completed': statusCode = 1; break
581
- case 'unprocessed': statusCode = 2; break
582
- case 'sending': statusCode = 3; break
583
- case 'unproven': statusCode = 4; break
584
- case 'unsigned': statusCode = 5; break
585
- case 'nosend': statusCode = 6; break
586
- case 'nonfinal': statusCode = 7; break
587
- default: statusCode = -1; break
588
- }
589
- resultWriter.writeInt8(statusCode)
594
+ // totalActions
595
+ resultWriter.writeVarIntNum(listActionsResult.totalActions)
590
596
 
591
- // isOutgoing
592
- resultWriter.writeInt8(action.isOutgoing ? 1 : 0)
593
-
594
- // description
595
- const descriptionBytes = Utils.toArray(action.description, 'utf8')
596
- resultWriter.writeVarIntNum(descriptionBytes.length)
597
- resultWriter.write(descriptionBytes)
598
-
599
- // labels
600
- if (action.labels !== undefined) {
601
- resultWriter.writeVarIntNum(action.labels.length)
602
- for (const label of action.labels) {
603
- const labelBytes = Utils.toArray(label, 'utf8')
604
- resultWriter.writeVarIntNum(labelBytes.length)
605
- resultWriter.write(labelBytes)
606
- }
607
- } else {
608
- resultWriter.writeVarIntNum(-1)
597
+ // actions
598
+ for (const action of listActionsResult.actions) {
599
+ // txid
600
+ resultWriter.write(Utils.toArray(action.txid, 'hex'))
601
+
602
+ // satoshis
603
+ resultWriter.writeVarIntNum(action.satoshis)
604
+
605
+ // status
606
+ let statusCode
607
+ switch (action.status) {
608
+ case 'completed':
609
+ statusCode = 1
610
+ break
611
+ case 'unprocessed':
612
+ statusCode = 2
613
+ break
614
+ case 'sending':
615
+ statusCode = 3
616
+ break
617
+ case 'unproven':
618
+ statusCode = 4
619
+ break
620
+ case 'unsigned':
621
+ statusCode = 5
622
+ break
623
+ case 'nosend':
624
+ statusCode = 6
625
+ break
626
+ case 'nonfinal':
627
+ statusCode = 7
628
+ break
629
+ default:
630
+ statusCode = -1
631
+ break
632
+ }
633
+ resultWriter.writeInt8(statusCode)
634
+
635
+ // isOutgoing
636
+ resultWriter.writeInt8(action.isOutgoing ? 1 : 0)
637
+
638
+ // description
639
+ const descriptionBytes = Utils.toArray(action.description, 'utf8')
640
+ resultWriter.writeVarIntNum(descriptionBytes.length)
641
+ resultWriter.write(descriptionBytes)
642
+
643
+ // labels
644
+ if (action.labels !== undefined) {
645
+ resultWriter.writeVarIntNum(action.labels.length)
646
+ for (const label of action.labels) {
647
+ const labelBytes = Utils.toArray(label, 'utf8')
648
+ resultWriter.writeVarIntNum(labelBytes.length)
649
+ resultWriter.write(labelBytes)
609
650
  }
651
+ } else {
652
+ resultWriter.writeVarIntNum(-1)
653
+ }
610
654
 
611
- // version
612
- resultWriter.writeVarIntNum(action.version)
613
-
614
- // lockTime
615
- resultWriter.writeVarIntNum(action.lockTime)
616
-
617
- // inputs
618
- if (action.inputs !== undefined) {
619
- resultWriter.writeVarIntNum(action.inputs.length)
620
- for (const input of action.inputs) {
621
- // sourceOutpoint
622
- resultWriter.write(this.encodeOutpoint(input.sourceOutpoint))
623
-
624
- // sourceSatoshis
625
- resultWriter.writeVarIntNum(input.sourceSatoshis)
626
-
627
- // sourceLockingScript
628
- if (input.sourceLockingScript !== undefined) {
629
- const sourceLockingScriptBytes = Utils.toArray(input.sourceLockingScript, 'hex')
630
- resultWriter.writeVarIntNum(sourceLockingScriptBytes.length)
631
- resultWriter.write(sourceLockingScriptBytes)
632
- } else {
633
- resultWriter.writeVarIntNum(-1)
634
- }
655
+ // version
656
+ resultWriter.writeVarIntNum(action.version)
635
657
 
636
- // unlockingScript
637
- if (input.unlockingScript !== undefined) {
638
- const unlockingScriptBytes = Utils.toArray(input.unlockingScript, 'hex')
639
- resultWriter.writeVarIntNum(unlockingScriptBytes.length)
640
- resultWriter.write(unlockingScriptBytes)
641
- } else {
642
- resultWriter.writeVarIntNum(-1)
643
- }
658
+ // lockTime
659
+ resultWriter.writeVarIntNum(action.lockTime)
644
660
 
645
- // inputDescription
646
- const inputDescriptionBytes = Utils.toArray(input.inputDescription, 'utf8')
647
- resultWriter.writeVarIntNum(inputDescriptionBytes.length)
648
- resultWriter.write(inputDescriptionBytes)
661
+ // inputs
662
+ if (action.inputs !== undefined) {
663
+ resultWriter.writeVarIntNum(action.inputs.length)
664
+ for (const input of action.inputs) {
665
+ // sourceOutpoint
666
+ resultWriter.write(this.encodeOutpoint(input.sourceOutpoint))
649
667
 
650
- // sequenceNumber
651
- resultWriter.writeVarIntNum(input.sequenceNumber)
652
- }
653
- } else {
654
- resultWriter.writeVarIntNum(-1)
655
- }
668
+ // sourceSatoshis
669
+ resultWriter.writeVarIntNum(input.sourceSatoshis)
656
670
 
657
- // outputs
658
- if (action.outputs !== undefined) {
659
- resultWriter.writeVarIntNum(action.outputs.length)
660
- for (const output of action.outputs) {
661
- // outputIndex
662
- resultWriter.writeVarIntNum(output.outputIndex)
663
-
664
- // satoshis
665
- resultWriter.writeVarIntNum(output.satoshis)
666
-
667
- // lockingScript
668
- if (output.lockingScript !== undefined) {
669
- const lockingScriptBytes = Utils.toArray(output.lockingScript, 'hex')
670
- resultWriter.writeVarIntNum(lockingScriptBytes.length)
671
- resultWriter.write(lockingScriptBytes)
672
- } else {
673
- resultWriter.writeVarIntNum(-1)
674
- }
671
+ // sourceLockingScript
672
+ if (input.sourceLockingScript !== undefined) {
673
+ const sourceLockingScriptBytes = Utils.toArray(
674
+ input.sourceLockingScript,
675
+ 'hex'
676
+ )
677
+ resultWriter.writeVarIntNum(sourceLockingScriptBytes.length)
678
+ resultWriter.write(sourceLockingScriptBytes)
679
+ } else {
680
+ resultWriter.writeVarIntNum(-1)
681
+ }
675
682
 
676
- // spendable
677
- resultWriter.writeInt8(output.spendable ? 1 : 0)
678
-
679
- // outputDescription
680
- const outputDescriptionBytes = Utils.toArray(output.outputDescription, 'utf8')
681
- resultWriter.writeVarIntNum(outputDescriptionBytes.length)
682
- resultWriter.write(outputDescriptionBytes)
683
-
684
- // basket
685
- if (output.basket !== undefined) {
686
- const basketBytes = Utils.toArray(output.basket, 'utf8')
687
- resultWriter.writeVarIntNum(basketBytes.length)
688
- resultWriter.write(basketBytes)
689
- } else {
690
- resultWriter.writeVarIntNum(-1)
691
- }
683
+ // unlockingScript
684
+ if (input.unlockingScript !== undefined) {
685
+ const unlockingScriptBytes = Utils.toArray(
686
+ input.unlockingScript,
687
+ 'hex'
688
+ )
689
+ resultWriter.writeVarIntNum(unlockingScriptBytes.length)
690
+ resultWriter.write(unlockingScriptBytes)
691
+ } else {
692
+ resultWriter.writeVarIntNum(-1)
693
+ }
692
694
 
693
- // tags
694
- if (output.tags !== undefined) {
695
- resultWriter.writeVarIntNum(output.tags.length)
696
- for (const tag of output.tags) {
697
- const tagBytes = Utils.toArray(tag, 'utf8')
698
- resultWriter.writeVarIntNum(tagBytes.length)
699
- resultWriter.write(tagBytes)
700
- }
701
- } else {
702
- resultWriter.writeVarIntNum(-1)
703
- }
695
+ // inputDescription
696
+ const inputDescriptionBytes = Utils.toArray(
697
+ input.inputDescription,
698
+ 'utf8'
699
+ )
700
+ resultWriter.writeVarIntNum(inputDescriptionBytes.length)
701
+ resultWriter.write(inputDescriptionBytes)
704
702
 
705
- // customInstructions
706
- if (output.customInstructions !== undefined) {
707
- const customInstructionsBytes = Utils.toArray(output.customInstructions, 'utf8')
708
- resultWriter.writeVarIntNum(customInstructionsBytes.length)
709
- resultWriter.write(customInstructionsBytes)
710
- } else {
711
- resultWriter.writeVarIntNum(-1)
712
- }
713
- }
714
- } else {
715
- resultWriter.writeVarIntNum(-1)
703
+ // sequenceNumber
704
+ resultWriter.writeVarIntNum(input.sequenceNumber)
716
705
  }
706
+ } else {
707
+ resultWriter.writeVarIntNum(-1)
717
708
  }
718
709
 
719
- const responseWriter = new Utils.Writer()
720
- responseWriter.writeUInt8(0) // errorByte = 0
721
- responseWriter.write(resultWriter.toArray())
722
- return responseWriter.toArray()
723
- }
724
- case 'internalizeAction':
725
- {
726
- const args: any = {}
727
-
728
- // Read tx
729
- const txLength = paramsReader.readVarIntNum()
730
- args.tx = paramsReader.read(txLength)
731
-
732
- // Read outputs
733
- const outputsLength = paramsReader.readVarIntNum()
734
- args.outputs = []
735
- for (let i = 0; i < outputsLength; i++) {
736
- const output: any = {}
737
-
738
- // outputIndex
739
- output.outputIndex = paramsReader.readVarIntNum()
740
-
741
- // protocol
742
- const protocolFlag = paramsReader.readUInt8()
743
- if (protocolFlag === 1) {
744
- output.protocol = 'wallet payment'
745
- output.paymentRemittance = {}
746
-
747
- // senderIdentityKey
748
- const senderIdentityKeyBytes = paramsReader.read(33)
749
- output.paymentRemittance.senderIdentityKey = Utils.toHex(senderIdentityKeyBytes)
710
+ // outputs
711
+ if (action.outputs !== undefined) {
712
+ resultWriter.writeVarIntNum(action.outputs.length)
713
+ for (const output of action.outputs) {
714
+ // outputIndex
715
+ resultWriter.writeVarIntNum(output.outputIndex)
716
+
717
+ // satoshis
718
+ resultWriter.writeVarIntNum(output.satoshis)
719
+
720
+ // lockingScript
721
+ if (output.lockingScript !== undefined) {
722
+ const lockingScriptBytes = Utils.toArray(
723
+ output.lockingScript,
724
+ 'hex'
725
+ )
726
+ resultWriter.writeVarIntNum(lockingScriptBytes.length)
727
+ resultWriter.write(lockingScriptBytes)
728
+ } else {
729
+ resultWriter.writeVarIntNum(-1)
730
+ }
750
731
 
751
- // derivationPrefix
752
- const derivationPrefixLength = paramsReader.readVarIntNum()
753
- const derivationPrefixBytes = paramsReader.read(derivationPrefixLength)
754
- output.paymentRemittance.derivationPrefix = Utils.toBase64(derivationPrefixBytes)
732
+ // spendable
733
+ resultWriter.writeInt8(output.spendable ? 1 : 0)
755
734
 
756
- // derivationSuffix
757
- const derivationSuffixLength = paramsReader.readVarIntNum()
758
- const derivationSuffixBytes = paramsReader.read(derivationSuffixLength)
759
- output.paymentRemittance.derivationSuffix = Utils.toBase64(derivationSuffixBytes)
760
- } else if (protocolFlag === 2) {
761
- output.protocol = 'basket insertion'
762
- output.insertionRemittance = {}
735
+ // outputDescription
736
+ const outputDescriptionBytes = Utils.toArray(
737
+ output.outputDescription,
738
+ 'utf8'
739
+ )
740
+ resultWriter.writeVarIntNum(outputDescriptionBytes.length)
741
+ resultWriter.write(outputDescriptionBytes)
763
742
 
764
743
  // basket
765
- const basketLength = paramsReader.readVarIntNum()
766
- const basketBytes = paramsReader.read(basketLength)
767
- output.insertionRemittance.basket = Utils.toUTF8(basketBytes)
768
-
769
- // customInstructions
770
- const customInstructionsLength = paramsReader.readVarIntNum()
771
- if (customInstructionsLength >= 0) {
772
- const customInstructionsBytes = paramsReader.read(customInstructionsLength)
773
- output.insertionRemittance.customInstructions = Utils.toUTF8(customInstructionsBytes)
744
+ if (output.basket !== undefined) {
745
+ const basketBytes = Utils.toArray(output.basket, 'utf8')
746
+ resultWriter.writeVarIntNum(basketBytes.length)
747
+ resultWriter.write(basketBytes)
748
+ } else {
749
+ resultWriter.writeVarIntNum(-1)
774
750
  }
775
751
 
776
752
  // tags
777
- const tagsLength = paramsReader.readVarIntNum()
778
- if (tagsLength > 0) {
779
- output.insertionRemittance.tags = []
780
- for (let j = 0; j < tagsLength; j++) {
781
- const tagLength = paramsReader.readVarIntNum()
782
- const tagBytes = paramsReader.read(tagLength)
783
- output.insertionRemittance.tags.push(Utils.toUTF8(tagBytes))
753
+ if (output.tags !== undefined) {
754
+ resultWriter.writeVarIntNum(output.tags.length)
755
+ for (const tag of output.tags) {
756
+ const tagBytes = Utils.toArray(tag, 'utf8')
757
+ resultWriter.writeVarIntNum(tagBytes.length)
758
+ resultWriter.write(tagBytes)
784
759
  }
785
760
  } else {
786
- output.insertionRemittance.tags = []
761
+ resultWriter.writeVarIntNum(-1)
787
762
  }
788
- }
789
763
 
790
- args.outputs.push(output)
791
- }
792
-
793
- const numberOfLabels = paramsReader.readVarIntNum()
794
- if (numberOfLabels >= 0) {
795
- args.labels = []
796
- for (let i = 0; i < numberOfLabels; i++) {
797
- const labelLength = paramsReader.readVarIntNum()
798
- args.labels.push(Utils.toUTF8(paramsReader.read(labelLength)))
764
+ // customInstructions
765
+ if (output.customInstructions !== undefined) {
766
+ const customInstructionsBytes = Utils.toArray(
767
+ output.customInstructions,
768
+ 'utf8'
769
+ )
770
+ resultWriter.writeVarIntNum(customInstructionsBytes.length)
771
+ resultWriter.write(customInstructionsBytes)
772
+ } else {
773
+ resultWriter.writeVarIntNum(-1)
774
+ }
799
775
  }
776
+ } else {
777
+ resultWriter.writeVarIntNum(-1)
800
778
  }
779
+ }
801
780
 
802
- const descriptionLength = paramsReader.readVarIntNum()
803
- args.description = Utils.toUTF8(paramsReader.read(descriptionLength))
781
+ const responseWriter = new Utils.Writer()
782
+ responseWriter.writeUInt8(0) // errorByte = 0
783
+ responseWriter.write(resultWriter.toArray())
784
+ return responseWriter.toArray()
785
+ }
786
+ case 'internalizeAction': {
787
+ const args: any = {}
804
788
 
805
- // Deserialize seekPermission
806
- const seekPermission = paramsReader.readInt8()
807
- if (seekPermission >= 0) {
808
- args.seekPermission = seekPermission === 1
809
- } else {
810
- args.seekPermission = undefined
811
- }
789
+ // Read tx
790
+ const txLength = paramsReader.readVarIntNum()
791
+ args.tx = paramsReader.read(txLength)
812
792
 
813
- // Call the method
814
- await this.wallet.internalizeAction(args, originator)
793
+ // Read outputs
794
+ const outputsLength = paramsReader.readVarIntNum()
795
+ args.outputs = []
796
+ for (let i = 0; i < outputsLength; i++) {
797
+ const output: any = {}
798
+
799
+ // outputIndex
800
+ output.outputIndex = paramsReader.readVarIntNum()
801
+
802
+ // protocol
803
+ const protocolFlag = paramsReader.readUInt8()
804
+ if (protocolFlag === 1) {
805
+ output.protocol = 'wallet payment'
806
+ output.paymentRemittance = {}
807
+
808
+ // senderIdentityKey
809
+ const senderIdentityKeyBytes = paramsReader.read(33)
810
+ output.paymentRemittance.senderIdentityKey = Utils.toHex(
811
+ senderIdentityKeyBytes
812
+ )
815
813
 
816
- // Return success code and result
817
- const responseWriter = new Utils.Writer()
818
- responseWriter.writeUInt8(0) // errorByte = 0
819
- return responseWriter.toArray()
820
- }
814
+ // derivationPrefix
815
+ const derivationPrefixLength = paramsReader.readVarIntNum()
816
+ const derivationPrefixBytes = paramsReader.read(
817
+ derivationPrefixLength
818
+ )
819
+ output.paymentRemittance.derivationPrefix = Utils.toBase64(
820
+ derivationPrefixBytes
821
+ )
821
822
 
822
- case 'listOutputs':
823
- {
824
- const args: any = {}
823
+ // derivationSuffix
824
+ const derivationSuffixLength = paramsReader.readVarIntNum()
825
+ const derivationSuffixBytes = paramsReader.read(
826
+ derivationSuffixLength
827
+ )
828
+ output.paymentRemittance.derivationSuffix = Utils.toBase64(
829
+ derivationSuffixBytes
830
+ )
831
+ } else if (protocolFlag === 2) {
832
+ output.protocol = 'basket insertion'
833
+ output.insertionRemittance = {}
825
834
 
826
- // Deserialize basket
827
- const basketLength = paramsReader.readVarIntNum()
828
- const basketBytes = paramsReader.read(basketLength)
829
- args.basket = Utils.toUTF8(basketBytes)
835
+ // basket
836
+ const basketLength = paramsReader.readVarIntNum()
837
+ const basketBytes = paramsReader.read(basketLength)
838
+ output.insertionRemittance.basket = Utils.toUTF8(basketBytes)
830
839
 
831
- // Deserialize tags
832
- const tagsLength = paramsReader.readVarIntNum()
833
- if (tagsLength > 0) {
834
- args.tags = []
835
- for (let i = 0; i < tagsLength; i++) {
836
- const tagLength = paramsReader.readVarIntNum()
837
- const tagBytes = paramsReader.read(tagLength)
838
- args.tags.push(Utils.toUTF8(tagBytes))
840
+ // customInstructions
841
+ const customInstructionsLength = paramsReader.readVarIntNum()
842
+ if (customInstructionsLength >= 0) {
843
+ const customInstructionsBytes = paramsReader.read(
844
+ customInstructionsLength
845
+ )
846
+ output.insertionRemittance.customInstructions = Utils.toUTF8(
847
+ customInstructionsBytes
848
+ )
839
849
  }
840
- } else {
841
- args.tags = undefined
842
- }
843
850
 
844
- // Deserialize tagQueryMode
845
- const tagQueryModeFlag = paramsReader.readInt8()
846
- if (tagQueryModeFlag === 1) {
847
- args.tagQueryMode = 'all'
848
- } else if (tagQueryModeFlag === 2) {
849
- args.tagQueryMode = 'any'
850
- } else {
851
- args.tagQueryMode = undefined
851
+ // tags
852
+ const tagsLength = paramsReader.readVarIntNum()
853
+ if (tagsLength > 0) {
854
+ output.insertionRemittance.tags = []
855
+ for (let j = 0; j < tagsLength; j++) {
856
+ const tagLength = paramsReader.readVarIntNum()
857
+ const tagBytes = paramsReader.read(tagLength)
858
+ output.insertionRemittance.tags.push(Utils.toUTF8(tagBytes))
859
+ }
860
+ } else {
861
+ output.insertionRemittance.tags = []
862
+ }
852
863
  }
853
864
 
854
- // Deserialize include
855
- const includeFlag = paramsReader.readInt8()
856
- if (includeFlag === 1) {
857
- args.include = 'locking scripts'
858
- } else if (includeFlag === 2) {
859
- args.include = 'entire transactions'
860
- } else {
861
- args.include = undefined
862
- }
865
+ args.outputs.push(output)
866
+ }
863
867
 
864
- // Deserialize includeCustomInstructions
865
- const includeCustomInstructionsFlag = paramsReader.readInt8()
866
- if (includeCustomInstructionsFlag === -1) {
867
- args.includeCustomInstructions = undefined
868
- } else {
869
- args.includeCustomInstructions = includeCustomInstructionsFlag === 1
868
+ const numberOfLabels = paramsReader.readVarIntNum()
869
+ if (numberOfLabels >= 0) {
870
+ args.labels = []
871
+ for (let i = 0; i < numberOfLabels; i++) {
872
+ const labelLength = paramsReader.readVarIntNum()
873
+ args.labels.push(Utils.toUTF8(paramsReader.read(labelLength)))
870
874
  }
875
+ }
871
876
 
872
- // Deserialize includeTags
873
- const includeTagsFlag = paramsReader.readInt8()
874
- if (includeTagsFlag === -1) {
875
- args.includeTags = undefined
876
- } else {
877
- args.includeTags = includeTagsFlag === 1
878
- }
877
+ const descriptionLength = paramsReader.readVarIntNum()
878
+ args.description = Utils.toUTF8(paramsReader.read(descriptionLength))
879
879
 
880
- // Deserialize includeLabels
881
- const includeLabelsFlag = paramsReader.readInt8()
882
- if (includeLabelsFlag === -1) {
883
- args.includeLabels = undefined
884
- } else {
885
- args.includeLabels = includeLabelsFlag === 1
886
- }
880
+ // Deserialize seekPermission
881
+ const seekPermission = paramsReader.readInt8()
882
+ if (seekPermission >= 0) {
883
+ args.seekPermission = seekPermission === 1
884
+ } else {
885
+ args.seekPermission = undefined
886
+ }
887
887
 
888
- // Deserialize limit
889
- const limit = paramsReader.readVarIntNum()
890
- if (limit >= 0) {
891
- args.limit = limit
892
- } else {
893
- args.limit = undefined
894
- }
888
+ // Call the method
889
+ await this.wallet.internalizeAction(args, originator)
895
890
 
896
- // Deserialize offset
897
- const offset = paramsReader.readVarIntNum()
898
- if (offset >= 0) {
899
- args.offset = offset
900
- } else {
901
- args.offset = undefined
902
- }
891
+ // Return success code and result
892
+ const responseWriter = new Utils.Writer()
893
+ responseWriter.writeUInt8(0) // errorByte = 0
894
+ return responseWriter.toArray()
895
+ }
903
896
 
904
- // Deserialize seekPermission
905
- const seekPermission = paramsReader.readInt8()
906
- if (seekPermission >= 0) {
907
- args.seekPermission = seekPermission === 1
908
- } else {
909
- args.seekPermission = undefined
910
- }
897
+ case 'listOutputs': {
898
+ const args: any = {}
911
899
 
912
- // Call the method
913
- const listOutputsResult = await this.wallet.listOutputs(args, originator)
900
+ // Deserialize basket
901
+ const basketLength = paramsReader.readVarIntNum()
902
+ const basketBytes = paramsReader.read(basketLength)
903
+ args.basket = Utils.toUTF8(basketBytes)
914
904
 
915
- // Serialize the result
916
- const resultWriter = new Utils.Writer()
905
+ // Deserialize tags
906
+ const tagsLength = paramsReader.readVarIntNum()
907
+ if (tagsLength > 0) {
908
+ args.tags = []
909
+ for (let i = 0; i < tagsLength; i++) {
910
+ const tagLength = paramsReader.readVarIntNum()
911
+ const tagBytes = paramsReader.read(tagLength)
912
+ args.tags.push(Utils.toUTF8(tagBytes))
913
+ }
914
+ } else {
915
+ args.tags = undefined
916
+ }
917
917
 
918
- // totalOutputs
919
- resultWriter.writeVarIntNum(listOutputsResult.totalOutputs)
918
+ // Deserialize tagQueryMode
919
+ const tagQueryModeFlag = paramsReader.readInt8()
920
+ if (tagQueryModeFlag === 1) {
921
+ args.tagQueryMode = 'all'
922
+ } else if (tagQueryModeFlag === 2) {
923
+ args.tagQueryMode = 'any'
924
+ } else {
925
+ args.tagQueryMode = undefined
926
+ }
920
927
 
921
- // BEEF length and BEEF or -1
922
- if (listOutputsResult.BEEF) {
923
- resultWriter.writeVarIntNum(listOutputsResult.BEEF.length)
924
- resultWriter.write(listOutputsResult.BEEF)
925
- } else {
926
- resultWriter.writeVarIntNum(-1)
927
- }
928
+ // Deserialize include
929
+ const includeFlag = paramsReader.readInt8()
930
+ if (includeFlag === 1) {
931
+ args.include = 'locking scripts'
932
+ } else if (includeFlag === 2) {
933
+ args.include = 'entire transactions'
934
+ } else {
935
+ args.include = undefined
936
+ }
928
937
 
929
- // outputs
930
- for (const output of listOutputsResult.outputs) {
931
- // outpoint
932
- resultWriter.write(this.encodeOutpoint(output.outpoint))
938
+ // Deserialize includeCustomInstructions
939
+ const includeCustomInstructionsFlag = paramsReader.readInt8()
940
+ if (includeCustomInstructionsFlag === -1) {
941
+ args.includeCustomInstructions = undefined
942
+ } else {
943
+ args.includeCustomInstructions =
944
+ includeCustomInstructionsFlag === 1
945
+ }
933
946
 
934
- // satoshis
935
- resultWriter.writeVarIntNum(output.satoshis)
947
+ // Deserialize includeTags
948
+ const includeTagsFlag = paramsReader.readInt8()
949
+ if (includeTagsFlag === -1) {
950
+ args.includeTags = undefined
951
+ } else {
952
+ args.includeTags = includeTagsFlag === 1
953
+ }
936
954
 
937
- // lockingScript
938
- if (output.lockingScript !== undefined) {
939
- const lockingScriptBytes = Utils.toArray(output.lockingScript, 'hex')
940
- resultWriter.writeVarIntNum(lockingScriptBytes.length)
941
- resultWriter.write(lockingScriptBytes)
942
- } else {
943
- resultWriter.writeVarIntNum(-1)
944
- }
955
+ // Deserialize includeLabels
956
+ const includeLabelsFlag = paramsReader.readInt8()
957
+ if (includeLabelsFlag === -1) {
958
+ args.includeLabels = undefined
959
+ } else {
960
+ args.includeLabels = includeLabelsFlag === 1
961
+ }
945
962
 
946
- // customInstructions
947
- if (output.customInstructions !== undefined) {
948
- const customInstructionsBytes = Utils.toArray(output.customInstructions, 'utf8')
949
- resultWriter.writeVarIntNum(customInstructionsBytes.length)
950
- resultWriter.write(customInstructionsBytes)
951
- } else {
952
- resultWriter.writeVarIntNum(-1)
953
- }
954
-
955
- // tags
956
- if (output.tags !== undefined) {
957
- resultWriter.writeVarIntNum(output.tags.length)
958
- for (const tag of output.tags) {
959
- const tagBytes = Utils.toArray(tag, 'utf8')
960
- resultWriter.writeVarIntNum(tagBytes.length)
961
- resultWriter.write(tagBytes)
962
- }
963
- } else {
964
- resultWriter.writeVarIntNum(-1)
965
- }
966
-
967
- // labels
968
- if (output.labels !== undefined) {
969
- resultWriter.writeVarIntNum(output.labels.length)
970
- for (const label of output.labels) {
971
- const labelBytes = Utils.toArray(label, 'utf8')
972
- resultWriter.writeVarIntNum(labelBytes.length)
973
- resultWriter.write(labelBytes)
974
- }
975
- } else {
976
- resultWriter.writeVarIntNum(-1)
977
- }
978
- }
963
+ // Deserialize limit
964
+ const limit = paramsReader.readVarIntNum()
965
+ if (limit >= 0) {
966
+ args.limit = limit
967
+ } else {
968
+ args.limit = undefined
969
+ }
979
970
 
980
- // Return success code and result
981
- const responseWriter = new Utils.Writer()
982
- responseWriter.writeUInt8(0) // errorByte = 0
983
- responseWriter.write(resultWriter.toArray())
984
- return responseWriter.toArray()
971
+ // Deserialize offset
972
+ const offset = paramsReader.readVarIntNum()
973
+ if (offset >= 0) {
974
+ args.offset = offset
975
+ } else {
976
+ args.offset = undefined
985
977
  }
986
978
 
987
- case 'relinquishOutput':
988
- {
989
- const args: any = {}
979
+ // Deserialize seekPermission
980
+ const seekPermission = paramsReader.readInt8()
981
+ if (seekPermission >= 0) {
982
+ args.seekPermission = seekPermission === 1
983
+ } else {
984
+ args.seekPermission = undefined
985
+ }
990
986
 
991
- // Deserialize basket
992
- const basketLength = paramsReader.readVarIntNum()
993
- const basketBytes = paramsReader.read(basketLength)
994
- args.basket = Utils.toUTF8(basketBytes)
987
+ // Call the method
988
+ const listOutputsResult = await this.wallet.listOutputs(
989
+ args,
990
+ originator
991
+ )
995
992
 
996
- // Deserialize outpoint
997
- args.output = this.decodeOutpoint(paramsReader)
993
+ // Serialize the result
994
+ const resultWriter = new Utils.Writer()
998
995
 
999
- // Call the method
1000
- await this.wallet.relinquishOutput(args, originator)
996
+ // totalOutputs
997
+ resultWriter.writeVarIntNum(listOutputsResult.totalOutputs)
1001
998
 
1002
- // Return success code and result
1003
- const responseWriter = new Utils.Writer()
1004
- responseWriter.writeUInt8(0) // errorByte = 0
1005
- return responseWriter.toArray()
999
+ // BEEF length and BEEF or -1
1000
+ if (listOutputsResult.BEEF != null) {
1001
+ resultWriter.writeVarIntNum(listOutputsResult.BEEF.length)
1002
+ resultWriter.write(listOutputsResult.BEEF)
1003
+ } else {
1004
+ resultWriter.writeVarIntNum(-1)
1006
1005
  }
1007
1006
 
1008
- case 'getPublicKey':
1009
- {
1010
- const args: any = {}
1011
-
1012
- // Deserialize identityKey flag
1013
- const identityKeyFlag = paramsReader.readUInt8()
1014
- args.identityKey = identityKeyFlag === 1
1007
+ // outputs
1008
+ for (const output of listOutputsResult.outputs) {
1009
+ // outpoint
1010
+ resultWriter.write(this.encodeOutpoint(output.outpoint))
1015
1011
 
1016
- if (!args.identityKey) {
1017
- // Deserialize protocolID
1018
- args.protocolID = this.decodeProtocolID(paramsReader)
1012
+ // satoshis
1013
+ resultWriter.writeVarIntNum(output.satoshis)
1019
1014
 
1020
- // Deserialize keyID
1021
- args.keyID = this.decodeString(paramsReader)
1022
-
1023
- // Deserialize counterparty
1024
- args.counterparty = this.decodeCounterparty(paramsReader)
1025
-
1026
- // Deserialize privilege parameters
1027
- const privilegedFlag = paramsReader.readInt8()
1028
- if (privilegedFlag === -1) {
1029
- args.privileged = undefined
1030
- } else {
1031
- args.privileged = privilegedFlag === 1
1032
- }
1033
-
1034
- const privilegedReasonLength = paramsReader.readInt8()
1035
- if (privilegedReasonLength !== -1) {
1036
- const privilegedReasonBytes = paramsReader.read(privilegedReasonLength)
1037
- args.privilegedReason = Utils.toUTF8(privilegedReasonBytes)
1038
- } else {
1039
- args.privilegedReason = undefined
1040
- }
1015
+ // lockingScript
1016
+ if (output.lockingScript !== undefined) {
1017
+ const lockingScriptBytes = Utils.toArray(
1018
+ output.lockingScript,
1019
+ 'hex'
1020
+ )
1021
+ resultWriter.writeVarIntNum(lockingScriptBytes.length)
1022
+ resultWriter.write(lockingScriptBytes)
1023
+ } else {
1024
+ resultWriter.writeVarIntNum(-1)
1025
+ }
1041
1026
 
1042
- // Deserialize forSelf
1043
- const forSelfFlag = paramsReader.readInt8()
1044
- if (forSelfFlag === -1) {
1045
- args.forSelf = undefined
1046
- } else {
1047
- args.forSelf = forSelfFlag === 1
1048
- }
1027
+ // customInstructions
1028
+ if (output.customInstructions !== undefined) {
1029
+ const customInstructionsBytes = Utils.toArray(
1030
+ output.customInstructions,
1031
+ 'utf8'
1032
+ )
1033
+ resultWriter.writeVarIntNum(customInstructionsBytes.length)
1034
+ resultWriter.write(customInstructionsBytes)
1049
1035
  } else {
1050
- // Deserialize privilege parameters
1051
- const privilegedFlag = paramsReader.readInt8()
1052
- if (privilegedFlag === -1) {
1053
- args.privileged = undefined
1054
- } else {
1055
- args.privileged = privilegedFlag === 1
1056
- }
1036
+ resultWriter.writeVarIntNum(-1)
1037
+ }
1057
1038
 
1058
- const privilegedReasonLength = paramsReader.readInt8()
1059
- if (privilegedReasonLength !== -1) {
1060
- const privilegedReasonBytes = paramsReader.read(privilegedReasonLength)
1061
- args.privilegedReason = Utils.toUTF8(privilegedReasonBytes)
1062
- } else {
1063
- args.privilegedReason = undefined
1039
+ // tags
1040
+ if (output.tags !== undefined) {
1041
+ resultWriter.writeVarIntNum(output.tags.length)
1042
+ for (const tag of output.tags) {
1043
+ const tagBytes = Utils.toArray(tag, 'utf8')
1044
+ resultWriter.writeVarIntNum(tagBytes.length)
1045
+ resultWriter.write(tagBytes)
1064
1046
  }
1047
+ } else {
1048
+ resultWriter.writeVarIntNum(-1)
1065
1049
  }
1066
1050
 
1067
- // Deserialize seekPermission
1068
- const seekPermission = paramsReader.readInt8()
1069
- if (seekPermission >= 0) {
1070
- args.seekPermission = seekPermission === 1
1051
+ // labels
1052
+ if (output.labels !== undefined) {
1053
+ resultWriter.writeVarIntNum(output.labels.length)
1054
+ for (const label of output.labels) {
1055
+ const labelBytes = Utils.toArray(label, 'utf8')
1056
+ resultWriter.writeVarIntNum(labelBytes.length)
1057
+ resultWriter.write(labelBytes)
1058
+ }
1071
1059
  } else {
1072
- args.seekPermission = undefined
1060
+ resultWriter.writeVarIntNum(-1)
1073
1061
  }
1062
+ }
1074
1063
 
1075
- // Call the method
1076
- const getPublicKeyResult = await this.wallet.getPublicKey(args, originator)
1064
+ // Return success code and result
1065
+ const responseWriter = new Utils.Writer()
1066
+ responseWriter.writeUInt8(0) // errorByte = 0
1067
+ responseWriter.write(resultWriter.toArray())
1068
+ return responseWriter.toArray()
1069
+ }
1077
1070
 
1078
- // Serialize the result
1079
- const responseWriter = new Utils.Writer()
1080
- responseWriter.writeUInt8(0) // errorByte = 0
1081
- const publicKeyBytes = Utils.toArray(getPublicKeyResult.publicKey, 'hex')
1082
- responseWriter.write(publicKeyBytes)
1083
- return responseWriter.toArray()
1084
- }
1071
+ case 'relinquishOutput': {
1072
+ const args: any = {}
1085
1073
 
1086
- case 'encrypt':
1087
- {
1088
- const args: any = this.decodeKeyRelatedParams(paramsReader)
1074
+ // Deserialize basket
1075
+ const basketLength = paramsReader.readVarIntNum()
1076
+ const basketBytes = paramsReader.read(basketLength)
1077
+ args.basket = Utils.toUTF8(basketBytes)
1089
1078
 
1090
- // Deserialize plaintext
1091
- const plaintextLength = paramsReader.readVarIntNum()
1092
- args.plaintext = paramsReader.read(plaintextLength)
1079
+ // Deserialize outpoint
1080
+ args.output = this.decodeOutpoint(paramsReader)
1093
1081
 
1094
- // Deserialize seekPermission
1095
- const seekPermission = paramsReader.readInt8()
1096
- if (seekPermission >= 0) {
1097
- args.seekPermission = seekPermission === 1
1098
- } else {
1099
- args.seekPermission = undefined
1100
- }
1082
+ // Call the method
1083
+ await this.wallet.relinquishOutput(args, originator)
1101
1084
 
1102
- // Call the method
1103
- const encryptResult = await this.wallet.encrypt(args, originator)
1085
+ // Return success code and result
1086
+ const responseWriter = new Utils.Writer()
1087
+ responseWriter.writeUInt8(0) // errorByte = 0
1088
+ return responseWriter.toArray()
1089
+ }
1104
1090
 
1105
- // Serialize the result
1106
- const responseWriter = new Utils.Writer()
1107
- responseWriter.writeUInt8(0) // errorByte = 0
1108
- responseWriter.write(encryptResult.ciphertext)
1109
- return responseWriter.toArray()
1110
- }
1091
+ case 'getPublicKey': {
1092
+ const args: any = {}
1093
+
1094
+ // Deserialize identityKey flag
1095
+ const identityKeyFlag = paramsReader.readUInt8()
1096
+ args.identityKey = identityKeyFlag === 1
1097
+
1098
+ if (args.identityKey !== true) {
1099
+ // Deserialize protocolID
1100
+ args.protocolID = this.decodeProtocolID(paramsReader)
1111
1101
 
1112
- case 'decrypt':
1113
- {
1114
- const args: any = this.decodeKeyRelatedParams(paramsReader)
1102
+ // Deserialize keyID
1103
+ args.keyID = this.decodeString(paramsReader)
1115
1104
 
1116
- // Deserialize ciphertext
1117
- const ciphertextLength = paramsReader.readVarIntNum()
1118
- args.ciphertext = paramsReader.read(ciphertextLength)
1105
+ // Deserialize counterparty
1106
+ args.counterparty = this.decodeCounterparty(paramsReader)
1119
1107
 
1120
- // Deserialize seekPermission
1121
- const seekPermission = paramsReader.readInt8()
1122
- if (seekPermission >= 0) {
1123
- args.seekPermission = seekPermission === 1
1108
+ // Deserialize privilege parameters
1109
+ const privilegedFlag = paramsReader.readInt8()
1110
+ if (privilegedFlag === -1) {
1111
+ args.privileged = undefined
1124
1112
  } else {
1125
- args.seekPermission = undefined
1113
+ args.privileged = privilegedFlag === 1
1126
1114
  }
1127
1115
 
1128
- // Call the method
1129
- const decryptResult = await this.wallet.decrypt(args, originator)
1116
+ const privilegedReasonLength = paramsReader.readInt8()
1117
+ if (privilegedReasonLength !== -1) {
1118
+ const privilegedReasonBytes = paramsReader.read(
1119
+ privilegedReasonLength
1120
+ )
1121
+ args.privilegedReason = Utils.toUTF8(privilegedReasonBytes)
1122
+ } else {
1123
+ args.privilegedReason = undefined
1124
+ }
1125
+
1126
+ // Deserialize forSelf
1127
+ const forSelfFlag = paramsReader.readInt8()
1128
+ if (forSelfFlag === -1) {
1129
+ args.forSelf = undefined
1130
+ } else {
1131
+ args.forSelf = forSelfFlag === 1
1132
+ }
1133
+ } else {
1134
+ // Deserialize privilege parameters
1135
+ const privilegedFlag = paramsReader.readInt8()
1136
+ if (privilegedFlag === -1) {
1137
+ args.privileged = undefined
1138
+ } else {
1139
+ args.privileged = privilegedFlag === 1
1140
+ }
1130
1141
 
1131
- // Serialize the result
1132
- const responseWriter = new Utils.Writer()
1133
- responseWriter.writeUInt8(0) // errorByte = 0
1134
- responseWriter.write(decryptResult.plaintext)
1135
- return responseWriter.toArray()
1142
+ const privilegedReasonLength = paramsReader.readInt8()
1143
+ if (privilegedReasonLength !== -1) {
1144
+ const privilegedReasonBytes = paramsReader.read(
1145
+ privilegedReasonLength
1146
+ )
1147
+ args.privilegedReason = Utils.toUTF8(privilegedReasonBytes)
1148
+ } else {
1149
+ args.privilegedReason = undefined
1150
+ }
1136
1151
  }
1137
1152
 
1138
- case 'createHmac':
1139
- {
1140
- const args: any = this.decodeKeyRelatedParams(paramsReader)
1153
+ // Deserialize seekPermission
1154
+ const seekPermission = paramsReader.readInt8()
1155
+ if (seekPermission >= 0) {
1156
+ args.seekPermission = seekPermission === 1
1157
+ } else {
1158
+ args.seekPermission = undefined
1159
+ }
1141
1160
 
1142
- // Deserialize data
1143
- const dataLength = paramsReader.readVarIntNum()
1144
- args.data = paramsReader.read(dataLength)
1161
+ // Call the method
1162
+ const getPublicKeyResult = await this.wallet.getPublicKey(
1163
+ args,
1164
+ originator
1165
+ )
1145
1166
 
1146
- // Deserialize seekPermission
1147
- const seekPermission = paramsReader.readInt8()
1148
- if (seekPermission >= 0) {
1149
- args.seekPermission = seekPermission === 1
1150
- } else {
1151
- args.seekPermission = undefined
1152
- }
1167
+ // Serialize the result
1168
+ const responseWriter = new Utils.Writer()
1169
+ responseWriter.writeUInt8(0) // errorByte = 0
1170
+ const publicKeyBytes = Utils.toArray(
1171
+ getPublicKeyResult.publicKey,
1172
+ 'hex'
1173
+ )
1174
+ responseWriter.write(publicKeyBytes)
1175
+ return responseWriter.toArray()
1176
+ }
1153
1177
 
1154
- // Call the method
1155
- const createHmacResult = await this.wallet.createHmac(args, originator)
1178
+ case 'encrypt': {
1179
+ const args: any = this.decodeKeyRelatedParams(paramsReader)
1156
1180
 
1157
- // Serialize the result
1158
- const responseWriter = new Utils.Writer()
1159
- responseWriter.writeUInt8(0) // errorByte = 0
1160
- responseWriter.write(createHmacResult.hmac)
1161
- return responseWriter.toArray()
1162
- }
1181
+ // Deserialize plaintext
1182
+ const plaintextLength = paramsReader.readVarIntNum()
1183
+ args.plaintext = paramsReader.read(plaintextLength)
1163
1184
 
1164
- case 'verifyHmac':
1165
- {
1166
- const args: any = this.decodeKeyRelatedParams(paramsReader)
1185
+ // Deserialize seekPermission
1186
+ const seekPermission = paramsReader.readInt8()
1187
+ if (seekPermission >= 0) {
1188
+ args.seekPermission = seekPermission === 1
1189
+ } else {
1190
+ args.seekPermission = undefined
1191
+ }
1167
1192
 
1168
- // Deserialize hmac
1169
- args.hmac = paramsReader.read(32)
1193
+ // Call the method
1194
+ const encryptResult = await this.wallet.encrypt(args, originator)
1170
1195
 
1171
- // Deserialize data
1172
- const dataLength = paramsReader.readVarIntNum()
1173
- args.data = paramsReader.read(dataLength)
1196
+ // Serialize the result
1197
+ const responseWriter = new Utils.Writer()
1198
+ responseWriter.writeUInt8(0) // errorByte = 0
1199
+ responseWriter.write(encryptResult.ciphertext)
1200
+ return responseWriter.toArray()
1201
+ }
1174
1202
 
1175
- // Deserialize seekPermission
1176
- const seekPermission = paramsReader.readInt8()
1177
- if (seekPermission >= 0) {
1178
- args.seekPermission = seekPermission === 1
1179
- } else {
1180
- args.seekPermission = undefined
1181
- }
1203
+ case 'decrypt': {
1204
+ const args: any = this.decodeKeyRelatedParams(paramsReader)
1182
1205
 
1183
- // Call the method
1184
- await this.wallet.verifyHmac(args, originator)
1206
+ // Deserialize ciphertext
1207
+ const ciphertextLength = paramsReader.readVarIntNum()
1208
+ args.ciphertext = paramsReader.read(ciphertextLength)
1185
1209
 
1186
- // Serialize the result (no data to return)
1187
- const responseWriter = new Utils.Writer()
1188
- responseWriter.writeUInt8(0) // errorByte = 0
1189
- return responseWriter.toArray()
1210
+ // Deserialize seekPermission
1211
+ const seekPermission = paramsReader.readInt8()
1212
+ if (seekPermission >= 0) {
1213
+ args.seekPermission = seekPermission === 1
1214
+ } else {
1215
+ args.seekPermission = undefined
1190
1216
  }
1191
1217
 
1192
- case 'createSignature':
1193
- {
1194
- const args: any = this.decodeKeyRelatedParams(paramsReader)
1218
+ // Call the method
1219
+ const decryptResult = await this.wallet.decrypt(args, originator)
1195
1220
 
1196
- // Deserialize data or hashToDirectlySign
1197
- const dataTypeFlag = paramsReader.readUInt8()
1198
- if (dataTypeFlag === 1) {
1199
- const dataLength = paramsReader.readVarIntNum()
1200
- args.data = paramsReader.read(dataLength)
1201
- } else if (dataTypeFlag === 2) {
1202
- args.hashToDirectlySign = paramsReader.read(32)
1203
- }
1221
+ // Serialize the result
1222
+ const responseWriter = new Utils.Writer()
1223
+ responseWriter.writeUInt8(0) // errorByte = 0
1224
+ responseWriter.write(decryptResult.plaintext)
1225
+ return responseWriter.toArray()
1226
+ }
1204
1227
 
1205
- // Deserialize seekPermission
1206
- const seekPermission = paramsReader.readInt8()
1207
- if (seekPermission >= 0) {
1208
- args.seekPermission = seekPermission === 1
1209
- } else {
1210
- args.seekPermission = undefined
1211
- }
1228
+ case 'createHmac': {
1229
+ const args: any = this.decodeKeyRelatedParams(paramsReader)
1212
1230
 
1213
- // Call the method
1214
- const createSignatureResult = await this.wallet.createSignature(args, originator)
1231
+ // Deserialize data
1232
+ const dataLength = paramsReader.readVarIntNum()
1233
+ args.data = paramsReader.read(dataLength)
1215
1234
 
1216
- // Serialize the result
1217
- const responseWriter = new Utils.Writer()
1218
- responseWriter.writeUInt8(0) // errorByte = 0
1219
- responseWriter.write(createSignatureResult.signature)
1220
- return responseWriter.toArray()
1235
+ // Deserialize seekPermission
1236
+ const seekPermission = paramsReader.readInt8()
1237
+ if (seekPermission >= 0) {
1238
+ args.seekPermission = seekPermission === 1
1239
+ } else {
1240
+ args.seekPermission = undefined
1221
1241
  }
1222
1242
 
1223
- case 'verifySignature':
1224
- {
1225
- const args: any = this.decodeKeyRelatedParams(paramsReader)
1243
+ // Call the method
1244
+ const createHmacResult = await this.wallet.createHmac(
1245
+ args,
1246
+ originator
1247
+ )
1226
1248
 
1227
- // Deserialize forSelf
1228
- const forSelfFlag = paramsReader.readInt8()
1229
- if (forSelfFlag === -1) {
1230
- args.forSelf = undefined
1231
- } else {
1232
- args.forSelf = forSelfFlag === 1
1233
- }
1249
+ // Serialize the result
1250
+ const responseWriter = new Utils.Writer()
1251
+ responseWriter.writeUInt8(0) // errorByte = 0
1252
+ responseWriter.write(createHmacResult.hmac)
1253
+ return responseWriter.toArray()
1254
+ }
1234
1255
 
1235
- // Deserialize signature
1236
- const signatureLength = paramsReader.readVarIntNum()
1237
- args.signature = paramsReader.read(signatureLength)
1238
-
1239
- // Deserialize data or hashToDirectlyVerify
1240
- const dataTypeFlag = paramsReader.readUInt8()
1241
- if (dataTypeFlag === 1) {
1242
- const dataLength = paramsReader.readVarIntNum()
1243
- args.data = paramsReader.read(dataLength)
1244
- } else if (dataTypeFlag === 2) {
1245
- args.hashToDirectlyVerify = paramsReader.read(32)
1246
- }
1256
+ case 'verifyHmac': {
1257
+ const args: any = this.decodeKeyRelatedParams(paramsReader)
1247
1258
 
1248
- // Deserialize seekPermission
1249
- const seekPermission = paramsReader.readInt8()
1250
- if (seekPermission >= 0) {
1251
- args.seekPermission = seekPermission === 1
1252
- } else {
1253
- args.seekPermission = undefined
1254
- }
1259
+ // Deserialize hmac
1260
+ args.hmac = paramsReader.read(32)
1255
1261
 
1256
- // Call the method
1257
- await this.wallet.verifySignature(args, originator)
1262
+ // Deserialize data
1263
+ const dataLength = paramsReader.readVarIntNum()
1264
+ args.data = paramsReader.read(dataLength)
1258
1265
 
1259
- // Serialize the result (no data to return)
1260
- const responseWriter = new Utils.Writer()
1261
- responseWriter.writeUInt8(0) // errorByte = 0
1262
- return responseWriter.toArray()
1266
+ // Deserialize seekPermission
1267
+ const seekPermission = paramsReader.readInt8()
1268
+ if (seekPermission >= 0) {
1269
+ args.seekPermission = seekPermission === 1
1270
+ } else {
1271
+ args.seekPermission = undefined
1263
1272
  }
1264
1273
 
1265
- case 'isAuthenticated':
1266
- {
1267
- // No parameters to deserialize
1274
+ // Call the method
1275
+ await this.wallet.verifyHmac(args, originator)
1268
1276
 
1269
- // Call the method
1270
- const isAuthenticatedResult = await this.wallet.isAuthenticated({}, originator)
1277
+ // Serialize the result (no data to return)
1278
+ const responseWriter = new Utils.Writer()
1279
+ responseWriter.writeUInt8(0) // errorByte = 0
1280
+ return responseWriter.toArray()
1281
+ }
1271
1282
 
1272
- // Serialize the result
1273
- const responseWriter = new Utils.Writer()
1274
- responseWriter.writeUInt8(0) // errorByte = 0
1275
- responseWriter.writeUInt8(isAuthenticatedResult.authenticated ? 1 : 0)
1276
- return responseWriter.toArray()
1283
+ case 'createSignature': {
1284
+ const args: any = this.decodeKeyRelatedParams(paramsReader)
1285
+
1286
+ // Deserialize data or hashToDirectlySign
1287
+ const dataTypeFlag = paramsReader.readUInt8()
1288
+ if (dataTypeFlag === 1) {
1289
+ const dataLength = paramsReader.readVarIntNum()
1290
+ args.data = paramsReader.read(dataLength)
1291
+ } else if (dataTypeFlag === 2) {
1292
+ args.hashToDirectlySign = paramsReader.read(32)
1293
+ }
1294
+
1295
+ // Deserialize seekPermission
1296
+ const seekPermission = paramsReader.readInt8()
1297
+ if (seekPermission >= 0) {
1298
+ args.seekPermission = seekPermission === 1
1299
+ } else {
1300
+ args.seekPermission = undefined
1277
1301
  }
1278
1302
 
1279
- case 'waitForAuthentication':
1280
- {
1281
- // No parameters to deserialize
1303
+ // Call the method
1304
+ const createSignatureResult = await this.wallet.createSignature(
1305
+ args,
1306
+ originator
1307
+ )
1282
1308
 
1283
- // Call the method
1284
- await this.wallet.waitForAuthentication({}, originator)
1309
+ // Serialize the result
1310
+ const responseWriter = new Utils.Writer()
1311
+ responseWriter.writeUInt8(0) // errorByte = 0
1312
+ responseWriter.write(createSignatureResult.signature)
1313
+ return responseWriter.toArray()
1314
+ }
1315
+
1316
+ case 'verifySignature': {
1317
+ const args: any = this.decodeKeyRelatedParams(paramsReader)
1285
1318
 
1286
- // Serialize the result (authenticated is always true)
1287
- const responseWriter = new Utils.Writer()
1288
- responseWriter.writeUInt8(0) // errorByte = 0
1289
- return responseWriter.toArray()
1319
+ // Deserialize forSelf
1320
+ const forSelfFlag = paramsReader.readInt8()
1321
+ if (forSelfFlag === -1) {
1322
+ args.forSelf = undefined
1323
+ } else {
1324
+ args.forSelf = forSelfFlag === 1
1290
1325
  }
1291
1326
 
1292
- case 'getHeight':
1293
- {
1294
- // No parameters to deserialize
1327
+ // Deserialize signature
1328
+ const signatureLength = paramsReader.readVarIntNum()
1329
+ args.signature = paramsReader.read(signatureLength)
1295
1330
 
1296
- // Call the method
1297
- const getHeightResult = await this.wallet.getHeight({}, originator)
1331
+ // Deserialize data or hashToDirectlyVerify
1332
+ const dataTypeFlag = paramsReader.readUInt8()
1333
+ if (dataTypeFlag === 1) {
1334
+ const dataLength = paramsReader.readVarIntNum()
1335
+ args.data = paramsReader.read(dataLength)
1336
+ } else if (dataTypeFlag === 2) {
1337
+ args.hashToDirectlyVerify = paramsReader.read(32)
1338
+ }
1298
1339
 
1299
- // Serialize the result
1300
- const responseWriter = new Utils.Writer()
1301
- responseWriter.writeUInt8(0) // errorByte = 0
1302
- responseWriter.writeVarIntNum(getHeightResult.height)
1303
- return responseWriter.toArray()
1340
+ // Deserialize seekPermission
1341
+ const seekPermission = paramsReader.readInt8()
1342
+ if (seekPermission >= 0) {
1343
+ args.seekPermission = seekPermission === 1
1344
+ } else {
1345
+ args.seekPermission = undefined
1304
1346
  }
1305
1347
 
1306
- case 'getHeaderForHeight':
1307
- {
1308
- const args: any = {}
1348
+ // Call the method
1349
+ await this.wallet.verifySignature(args, originator)
1309
1350
 
1310
- // Deserialize height
1311
- args.height = paramsReader.readVarIntNum()
1351
+ // Serialize the result (no data to return)
1352
+ const responseWriter = new Utils.Writer()
1353
+ responseWriter.writeUInt8(0) // errorByte = 0
1354
+ return responseWriter.toArray()
1355
+ }
1312
1356
 
1313
- // Call the method
1314
- const getHeaderResult = await this.wallet.getHeaderForHeight(args, originator)
1357
+ case 'isAuthenticated': {
1358
+ // No parameters to deserialize
1315
1359
 
1316
- // Serialize the result
1317
- const responseWriter = new Utils.Writer()
1318
- responseWriter.writeUInt8(0) // errorByte = 0
1319
- const headerBytes = Utils.toArray(getHeaderResult.header, 'hex')
1320
- responseWriter.write(headerBytes)
1321
- return responseWriter.toArray()
1322
- }
1360
+ // Call the method
1361
+ const isAuthenticatedResult = await this.wallet.isAuthenticated(
1362
+ {},
1363
+ originator
1364
+ )
1323
1365
 
1324
- case 'getNetwork':
1325
- {
1326
- // No parameters to deserialize
1366
+ // Serialize the result
1367
+ const responseWriter = new Utils.Writer()
1368
+ responseWriter.writeUInt8(0) // errorByte = 0
1369
+ responseWriter.writeUInt8(
1370
+ isAuthenticatedResult.authenticated ? 1 : 0
1371
+ )
1372
+ return responseWriter.toArray()
1373
+ }
1327
1374
 
1328
- // Call the method
1329
- const getNetworkResult = await this.wallet.getNetwork({}, originator)
1375
+ case 'waitForAuthentication': {
1376
+ // No parameters to deserialize
1330
1377
 
1331
- // Serialize the result
1332
- const responseWriter = new Utils.Writer()
1333
- responseWriter.writeUInt8(0) // errorByte = 0
1334
- responseWriter.writeUInt8(getNetworkResult.network === 'mainnet' ? 0 : 1)
1335
- return responseWriter.toArray()
1336
- }
1378
+ // Call the method
1379
+ await this.wallet.waitForAuthentication({}, originator)
1337
1380
 
1338
- case 'getVersion':
1339
- {
1340
- // No parameters to deserialize
1381
+ // Serialize the result (authenticated is always true)
1382
+ const responseWriter = new Utils.Writer()
1383
+ responseWriter.writeUInt8(0) // errorByte = 0
1384
+ return responseWriter.toArray()
1385
+ }
1341
1386
 
1342
- // Call the method
1343
- const getVersionResult = await this.wallet.getVersion({}, originator)
1387
+ case 'getHeight': {
1388
+ // No parameters to deserialize
1344
1389
 
1345
- // Serialize the result
1346
- const responseWriter = new Utils.Writer()
1347
- responseWriter.writeUInt8(0) // errorByte = 0
1348
- const versionBytes = Utils.toArray(getVersionResult.version, 'utf8')
1349
- responseWriter.write(versionBytes)
1350
- return responseWriter.toArray()
1351
- }
1390
+ // Call the method
1391
+ const getHeightResult = await this.wallet.getHeight({}, originator)
1352
1392
 
1353
- case 'revealCounterpartyKeyLinkage':
1354
- {
1355
- const args: any = {}
1393
+ // Serialize the result
1394
+ const responseWriter = new Utils.Writer()
1395
+ responseWriter.writeUInt8(0) // errorByte = 0
1396
+ responseWriter.writeVarIntNum(getHeightResult.height)
1397
+ return responseWriter.toArray()
1398
+ }
1356
1399
 
1357
- // Read privileged parameters
1358
- const privilegedFlag = paramsReader.readInt8()
1359
- if (privilegedFlag === -1) {
1360
- args.privileged = undefined
1361
- } else {
1362
- args.privileged = privilegedFlag === 1
1363
- }
1400
+ case 'getHeaderForHeight': {
1401
+ const args: any = {}
1364
1402
 
1365
- const privilegedReasonLength = paramsReader.readInt8()
1366
- if (privilegedReasonLength === -1) {
1367
- args.privilegedReason = undefined
1368
- } else {
1369
- const privilegedReasonBytes = paramsReader.read(privilegedReasonLength)
1370
- args.privilegedReason = Utils.toUTF8(privilegedReasonBytes)
1371
- }
1403
+ // Deserialize height
1404
+ args.height = paramsReader.readVarIntNum()
1372
1405
 
1373
- // Read counterparty public key
1374
- const counterpartyBytes = paramsReader.read(33)
1375
- args.counterparty = Utils.toHex(counterpartyBytes)
1406
+ // Call the method
1407
+ const getHeaderResult = await this.wallet.getHeaderForHeight(
1408
+ args,
1409
+ originator
1410
+ )
1376
1411
 
1377
- // Read verifier public key
1378
- const verifierBytes = paramsReader.read(33)
1379
- args.verifier = Utils.toHex(verifierBytes)
1412
+ // Serialize the result
1413
+ const responseWriter = new Utils.Writer()
1414
+ responseWriter.writeUInt8(0) // errorByte = 0
1415
+ const headerBytes = Utils.toArray(getHeaderResult.header, 'hex')
1416
+ responseWriter.write(headerBytes)
1417
+ return responseWriter.toArray()
1418
+ }
1380
1419
 
1381
- // Call the method
1382
- const revealResult = await this.wallet.revealCounterpartyKeyLinkage(args, originator)
1420
+ case 'getNetwork': {
1421
+ // No parameters to deserialize
1383
1422
 
1384
- // Serialize the result
1385
- const resultWriter = new Utils.Writer()
1423
+ // Call the method
1424
+ const getNetworkResult = await this.wallet.getNetwork({}, originator)
1386
1425
 
1387
- // Write prover
1388
- resultWriter.write(Utils.toArray(revealResult.prover, 'hex'))
1426
+ // Serialize the result
1427
+ const responseWriter = new Utils.Writer()
1428
+ responseWriter.writeUInt8(0) // errorByte = 0
1429
+ responseWriter.writeUInt8(
1430
+ getNetworkResult.network === 'mainnet' ? 0 : 1
1431
+ )
1432
+ return responseWriter.toArray()
1433
+ }
1389
1434
 
1390
- // Write verifier
1391
- resultWriter.write(Utils.toArray(revealResult.verifier, 'hex'))
1435
+ case 'getVersion': {
1436
+ // No parameters to deserialize
1392
1437
 
1393
- // Write counterparty
1394
- resultWriter.write(Utils.toArray(revealResult.counterparty, 'hex'))
1438
+ // Call the method
1439
+ const getVersionResult = await this.wallet.getVersion({}, originator)
1395
1440
 
1396
- // Write revelationTime
1397
- const revelationTimeBytes = Utils.toArray(revealResult.revelationTime, 'utf8')
1398
- resultWriter.writeVarIntNum(revelationTimeBytes.length)
1399
- resultWriter.write(revelationTimeBytes)
1441
+ // Serialize the result
1442
+ const responseWriter = new Utils.Writer()
1443
+ responseWriter.writeUInt8(0) // errorByte = 0
1444
+ const versionBytes = Utils.toArray(getVersionResult.version, 'utf8')
1445
+ responseWriter.write(versionBytes)
1446
+ return responseWriter.toArray()
1447
+ }
1400
1448
 
1401
- // Write encryptedLinkage
1402
- resultWriter.writeVarIntNum(revealResult.encryptedLinkage.length)
1403
- resultWriter.write(revealResult.encryptedLinkage)
1449
+ case 'revealCounterpartyKeyLinkage': {
1450
+ const args: any = {}
1404
1451
 
1405
- // Write encryptedLinkageProof
1406
- resultWriter.writeVarIntNum(revealResult.encryptedLinkageProof.length)
1407
- resultWriter.write(revealResult.encryptedLinkageProof)
1452
+ // Read privileged parameters
1453
+ const privilegedFlag = paramsReader.readInt8()
1454
+ if (privilegedFlag === -1) {
1455
+ args.privileged = undefined
1456
+ } else {
1457
+ args.privileged = privilegedFlag === 1
1458
+ }
1408
1459
 
1409
- // Return success code and result
1410
- const responseWriter = new Utils.Writer()
1411
- responseWriter.writeUInt8(0) // errorByte = 0
1412
- responseWriter.write(resultWriter.toArray())
1413
- return responseWriter.toArray()
1460
+ const privilegedReasonLength = paramsReader.readInt8()
1461
+ if (privilegedReasonLength === -1) {
1462
+ args.privilegedReason = undefined
1463
+ } else {
1464
+ const privilegedReasonBytes = paramsReader.read(
1465
+ privilegedReasonLength
1466
+ )
1467
+ args.privilegedReason = Utils.toUTF8(privilegedReasonBytes)
1414
1468
  }
1415
1469
 
1416
- case 'revealSpecificKeyLinkage':
1417
- {
1418
- // Deserialize key-related parameters and privileged parameters
1419
- const args = this.decodeKeyRelatedParams(paramsReader)
1470
+ // Read counterparty public key
1471
+ const counterpartyBytes = paramsReader.read(33)
1472
+ args.counterparty = Utils.toHex(counterpartyBytes)
1420
1473
 
1421
- // Read verifier public key
1422
- const verifierBytes = paramsReader.read(33)
1423
- args.verifier = Utils.toHex(verifierBytes)
1474
+ // Read verifier public key
1475
+ const verifierBytes = paramsReader.read(33)
1476
+ args.verifier = Utils.toHex(verifierBytes)
1424
1477
 
1425
- // Call the method
1426
- const revealResult = await this.wallet.revealSpecificKeyLinkage(args, originator)
1478
+ // Call the method
1479
+ const revealResult = await this.wallet.revealCounterpartyKeyLinkage(
1480
+ args,
1481
+ originator
1482
+ )
1427
1483
 
1428
- // Serialize the result
1429
- const resultWriter = new Utils.Writer()
1484
+ // Serialize the result
1485
+ const resultWriter = new Utils.Writer()
1430
1486
 
1431
- // Write prover
1432
- resultWriter.write(Utils.toArray(revealResult.prover, 'hex'))
1487
+ // Write prover
1488
+ resultWriter.write(Utils.toArray(revealResult.prover, 'hex'))
1433
1489
 
1434
- // Write verifier
1435
- resultWriter.write(Utils.toArray(revealResult.verifier, 'hex'))
1490
+ // Write verifier
1491
+ resultWriter.write(Utils.toArray(revealResult.verifier, 'hex'))
1436
1492
 
1437
- // Write counterparty
1438
- resultWriter.write(Utils.toArray(revealResult.counterparty, 'hex'))
1493
+ // Write counterparty
1494
+ resultWriter.write(Utils.toArray(revealResult.counterparty, 'hex'))
1439
1495
 
1440
- // Write securityLevel
1441
- resultWriter.writeUInt8(revealResult.protocolID[0])
1496
+ // Write revelationTime
1497
+ const revelationTimeBytes = Utils.toArray(
1498
+ revealResult.revelationTime,
1499
+ 'utf8'
1500
+ )
1501
+ resultWriter.writeVarIntNum(revelationTimeBytes.length)
1502
+ resultWriter.write(revelationTimeBytes)
1442
1503
 
1443
- // Write protocol string
1444
- const protocolBytesOut = Utils.toArray(revealResult.protocolID[1], 'utf8')
1445
- resultWriter.writeVarIntNum(protocolBytesOut.length)
1446
- resultWriter.write(protocolBytesOut)
1504
+ // Write encryptedLinkage
1505
+ resultWriter.writeVarIntNum(revealResult.encryptedLinkage.length)
1506
+ resultWriter.write(revealResult.encryptedLinkage)
1447
1507
 
1448
- // Write keyID
1449
- const keyIDBytesOut = Utils.toArray(revealResult.keyID, 'utf8')
1450
- resultWriter.writeVarIntNum(keyIDBytesOut.length)
1451
- resultWriter.write(keyIDBytesOut)
1508
+ // Write encryptedLinkageProof
1509
+ resultWriter.writeVarIntNum(
1510
+ revealResult.encryptedLinkageProof.length
1511
+ )
1512
+ resultWriter.write(revealResult.encryptedLinkageProof)
1452
1513
 
1453
- // Write encryptedLinkage
1454
- resultWriter.writeVarIntNum(revealResult.encryptedLinkage.length)
1455
- resultWriter.write(revealResult.encryptedLinkage)
1514
+ // Return success code and result
1515
+ const responseWriter = new Utils.Writer()
1516
+ responseWriter.writeUInt8(0) // errorByte = 0
1517
+ responseWriter.write(resultWriter.toArray())
1518
+ return responseWriter.toArray()
1519
+ }
1456
1520
 
1457
- // Write encryptedLinkageProof
1458
- resultWriter.writeVarIntNum(revealResult.encryptedLinkageProof.length)
1459
- resultWriter.write(revealResult.encryptedLinkageProof)
1521
+ case 'revealSpecificKeyLinkage': {
1522
+ // Deserialize key-related parameters and privileged parameters
1523
+ const args = this.decodeKeyRelatedParams(paramsReader)
1460
1524
 
1461
- // Write proofType
1462
- resultWriter.writeUInt8(revealResult.proofType)
1525
+ // Read verifier public key
1526
+ const verifierBytes = paramsReader.read(33)
1527
+ args.verifier = Utils.toHex(verifierBytes)
1463
1528
 
1464
- // Return success code and result
1465
- const responseWriter = new Utils.Writer()
1466
- responseWriter.writeUInt8(0) // errorByte = 0
1467
- responseWriter.write(resultWriter.toArray())
1468
- return responseWriter.toArray()
1469
- }
1529
+ // Call the method
1530
+ const revealResult = await this.wallet.revealSpecificKeyLinkage(
1531
+ args,
1532
+ originator
1533
+ )
1470
1534
 
1471
- case 'acquireCertificate':
1472
- {
1473
- const args: any = {}
1535
+ // Serialize the result
1536
+ const resultWriter = new Utils.Writer()
1474
1537
 
1475
- // Read args.type
1476
- const typeBytes = paramsReader.read(32)
1477
- args.type = Utils.toBase64(typeBytes)
1538
+ // Write prover
1539
+ resultWriter.write(Utils.toArray(revealResult.prover, 'hex'))
1478
1540
 
1479
- // args.certifier
1480
- const certifierBytes = paramsReader.read(33)
1481
- args.certifier = Utils.toHex(certifierBytes)
1541
+ // Write verifier
1542
+ resultWriter.write(Utils.toArray(revealResult.verifier, 'hex'))
1482
1543
 
1483
- // Read fields
1484
- const fieldsLength = paramsReader.readVarIntNum()
1485
- args.fields = {}
1486
- for (let i = 0; i < fieldsLength; i++) {
1487
- const fieldNameLength = paramsReader.readVarIntNum()
1488
- const fieldNameBytes = paramsReader.read(fieldNameLength)
1489
- const fieldName = Utils.toUTF8(fieldNameBytes)
1544
+ // Write counterparty
1545
+ resultWriter.write(Utils.toArray(revealResult.counterparty, 'hex'))
1490
1546
 
1491
- const fieldValueLength = paramsReader.readVarIntNum()
1492
- const fieldValueBytes = paramsReader.read(fieldValueLength)
1493
- const fieldValue = Utils.toUTF8(fieldValueBytes)
1547
+ // Write securityLevel
1548
+ resultWriter.writeUInt8(revealResult.protocolID[0])
1494
1549
 
1495
- args.fields[fieldName] = fieldValue
1496
- }
1550
+ // Write protocol string
1551
+ const protocolBytesOut = Utils.toArray(
1552
+ revealResult.protocolID[1],
1553
+ 'utf8'
1554
+ )
1555
+ resultWriter.writeVarIntNum(protocolBytesOut.length)
1556
+ resultWriter.write(protocolBytesOut)
1497
1557
 
1498
- // Read privileged parameters
1499
- const privilegedFlag = paramsReader.readInt8()
1500
- if (privilegedFlag === -1) {
1501
- args.privileged = undefined
1502
- } else {
1503
- args.privileged = privilegedFlag === 1
1504
- }
1558
+ // Write keyID
1559
+ const keyIDBytesOut = Utils.toArray(revealResult.keyID, 'utf8')
1560
+ resultWriter.writeVarIntNum(keyIDBytesOut.length)
1561
+ resultWriter.write(keyIDBytesOut)
1505
1562
 
1506
- const privilegedReasonLength = paramsReader.readInt8()
1507
- if (privilegedReasonLength === -1) {
1508
- args.privilegedReason = undefined
1509
- } else {
1510
- const privilegedReasonBytes = paramsReader.read(privilegedReasonLength)
1511
- args.privilegedReason = Utils.toUTF8(privilegedReasonBytes)
1512
- }
1563
+ // Write encryptedLinkage
1564
+ resultWriter.writeVarIntNum(revealResult.encryptedLinkage.length)
1565
+ resultWriter.write(revealResult.encryptedLinkage)
1513
1566
 
1514
- // Read acquisitionProtocol
1515
- const acquisitionProtocolFlag = paramsReader.readUInt8()
1516
- args.acquisitionProtocol = acquisitionProtocolFlag === 1 ? 'direct' : 'issuance'
1567
+ // Write encryptedLinkageProof
1568
+ resultWriter.writeVarIntNum(
1569
+ revealResult.encryptedLinkageProof.length
1570
+ )
1571
+ resultWriter.write(revealResult.encryptedLinkageProof)
1517
1572
 
1518
- if (args.acquisitionProtocol === 'direct') {
1519
- // args.serialNumber
1520
- const serialNumberBytes = paramsReader.read(32)
1521
- args.serialNumber = Utils.toBase64(serialNumberBytes)
1573
+ // Write proofType
1574
+ resultWriter.writeUInt8(revealResult.proofType)
1522
1575
 
1523
- // args.revocationOutpoint
1524
- args.revocationOutpoint = this.decodeOutpoint(paramsReader)
1576
+ // Return success code and result
1577
+ const responseWriter = new Utils.Writer()
1578
+ responseWriter.writeUInt8(0) // errorByte = 0
1579
+ responseWriter.write(resultWriter.toArray())
1580
+ return responseWriter.toArray()
1581
+ }
1525
1582
 
1526
- // args.signature
1527
- const signatureLength = paramsReader.readVarIntNum()
1528
- const signatureBytes = paramsReader.read(signatureLength)
1529
- args.signature = Utils.toHex(signatureBytes)
1583
+ case 'acquireCertificate': {
1584
+ const args: any = {}
1530
1585
 
1531
- // args.keyringRevealer
1532
- const keyringRevealerIdentifier = paramsReader.readUInt8()
1533
- if (keyringRevealerIdentifier === 11) {
1534
- args.keyringRevealer = 'certifier'
1535
- } else {
1536
- const keyringRevealerBytes = [keyringRevealerIdentifier].concat(paramsReader.read(32))
1537
- args.keyringRevealer = Utils.toHex(keyringRevealerBytes)
1538
- }
1586
+ // Read args.type
1587
+ const typeBytes = paramsReader.read(32)
1588
+ args.type = Utils.toBase64(typeBytes)
1539
1589
 
1540
- // args.keyringForSubject
1541
- const keyringEntriesLength = paramsReader.readVarIntNum()
1542
- args.keyringForSubject = {}
1543
- for (let i = 0; i < keyringEntriesLength; i++) {
1544
- const fieldKeyLength = paramsReader.readVarIntNum()
1545
- const fieldKeyBytes = paramsReader.read(fieldKeyLength)
1546
- const fieldKey = Utils.toUTF8(fieldKeyBytes)
1590
+ // args.certifier
1591
+ const certifierBytes = paramsReader.read(33)
1592
+ args.certifier = Utils.toHex(certifierBytes)
1547
1593
 
1548
- const fieldValueLength = paramsReader.readVarIntNum()
1549
- const fieldValueBytes = paramsReader.read(fieldValueLength)
1550
- const fieldValue = Utils.toBase64(fieldValueBytes)
1594
+ // Read fields
1595
+ const fieldsLength = paramsReader.readVarIntNum()
1596
+ args.fields = {}
1597
+ for (let i = 0; i < fieldsLength; i++) {
1598
+ const fieldNameLength = paramsReader.readVarIntNum()
1599
+ const fieldNameBytes = paramsReader.read(fieldNameLength)
1600
+ const fieldName = Utils.toUTF8(fieldNameBytes)
1551
1601
 
1552
- args.keyringForSubject[fieldKey] = fieldValue
1553
- }
1554
- } else {
1555
- // args.certifierUrl
1556
- const certifierUrlLength = paramsReader.readVarIntNum()
1557
- const certifierUrlBytes = paramsReader.read(certifierUrlLength)
1558
- args.certifierUrl = Utils.toUTF8(certifierUrlBytes)
1559
- }
1602
+ const fieldValueLength = paramsReader.readVarIntNum()
1603
+ const fieldValueBytes = paramsReader.read(fieldValueLength)
1604
+ const fieldValue = Utils.toUTF8(fieldValueBytes)
1560
1605
 
1561
- // Call the method
1562
- const acquireResult = await this.wallet.acquireCertificate(args, originator)
1563
-
1564
- // Serialize the certificate (assuming Certificate class is available)
1565
- const cert = new Certificate(
1566
- acquireResult.type,
1567
- acquireResult.serialNumber,
1568
- acquireResult.subject,
1569
- acquireResult.certifier,
1570
- acquireResult.revocationOutpoint,
1571
- acquireResult.fields,
1572
- acquireResult.signature
1573
- )
1574
- const certBin = cert.toBinary()
1606
+ args.fields[fieldName] = fieldValue
1607
+ }
1575
1608
 
1576
- // Return success code and certificate binary
1577
- const responseWriter = new Utils.Writer()
1578
- responseWriter.writeUInt8(0) // errorByte = 0
1579
- responseWriter.write(certBin)
1580
- return responseWriter.toArray()
1609
+ // Read privileged parameters
1610
+ const privilegedFlag = paramsReader.readInt8()
1611
+ if (privilegedFlag === -1) {
1612
+ args.privileged = undefined
1613
+ } else {
1614
+ args.privileged = privilegedFlag === 1
1581
1615
  }
1582
1616
 
1583
- case 'listCertificates':
1584
- {
1585
- const args: any = {}
1617
+ const privilegedReasonLength = paramsReader.readInt8()
1618
+ if (privilegedReasonLength === -1) {
1619
+ args.privilegedReason = undefined
1620
+ } else {
1621
+ const privilegedReasonBytes = paramsReader.read(
1622
+ privilegedReasonLength
1623
+ )
1624
+ args.privilegedReason = Utils.toUTF8(privilegedReasonBytes)
1625
+ }
1586
1626
 
1587
- // Read certifiers
1588
- const certifiersLength = paramsReader.readVarIntNum()
1589
- args.certifiers = []
1590
- for (let i = 0; i < certifiersLength; i++) {
1591
- const certifierBytes = paramsReader.read(33)
1592
- args.certifiers.push(Utils.toHex(certifierBytes))
1593
- }
1627
+ // Read acquisitionProtocol
1628
+ const acquisitionProtocolFlag = paramsReader.readUInt8()
1629
+ args.acquisitionProtocol =
1630
+ acquisitionProtocolFlag === 1 ? 'direct' : 'issuance'
1594
1631
 
1595
- // Read types
1596
- const typesLength = paramsReader.readVarIntNum()
1597
- args.types = []
1598
- for (let i = 0; i < typesLength; i++) {
1599
- const typeBytes = paramsReader.read(32)
1600
- args.types.push(Utils.toBase64(typeBytes))
1601
- }
1632
+ if (args.acquisitionProtocol === 'direct') {
1633
+ // args.serialNumber
1634
+ const serialNumberBytes = paramsReader.read(32)
1635
+ args.serialNumber = Utils.toBase64(serialNumberBytes)
1602
1636
 
1603
- // Read limit and offset
1604
- const limit = paramsReader.readVarIntNum()
1605
- if (limit >= 0) {
1606
- args.limit = limit
1607
- } else {
1608
- args.limit = undefined
1609
- }
1637
+ // args.revocationOutpoint
1638
+ args.revocationOutpoint = this.decodeOutpoint(paramsReader)
1610
1639
 
1611
- const offset = paramsReader.readVarIntNum()
1612
- if (offset >= 0) {
1613
- args.offset = offset
1614
- } else {
1615
- args.offset = undefined
1616
- }
1640
+ // args.signature
1641
+ const signatureLength = paramsReader.readVarIntNum()
1642
+ const signatureBytes = paramsReader.read(signatureLength)
1643
+ args.signature = Utils.toHex(signatureBytes)
1617
1644
 
1618
- // Read privileged parameters
1619
- const privilegedFlag = paramsReader.readInt8()
1620
- if (privilegedFlag === -1) {
1621
- args.privileged = undefined
1645
+ // args.keyringRevealer
1646
+ const keyringRevealerIdentifier = paramsReader.readUInt8()
1647
+ if (keyringRevealerIdentifier === 11) {
1648
+ args.keyringRevealer = 'certifier'
1622
1649
  } else {
1623
- args.privileged = privilegedFlag === 1
1650
+ const keyringRevealerBytes = [keyringRevealerIdentifier].concat(
1651
+ paramsReader.read(32)
1652
+ )
1653
+ args.keyringRevealer = Utils.toHex(keyringRevealerBytes)
1624
1654
  }
1625
1655
 
1626
- const privilegedReasonLength = paramsReader.readInt8()
1627
- if (privilegedReasonLength === -1) {
1628
- args.privilegedReason = undefined
1629
- } else {
1630
- const privilegedReasonBytes = paramsReader.read(privilegedReasonLength)
1631
- args.privilegedReason = Utils.toUTF8(privilegedReasonBytes)
1632
- }
1656
+ // args.keyringForSubject
1657
+ const keyringEntriesLength = paramsReader.readVarIntNum()
1658
+ args.keyringForSubject = {}
1659
+ for (let i = 0; i < keyringEntriesLength; i++) {
1660
+ const fieldKeyLength = paramsReader.readVarIntNum()
1661
+ const fieldKeyBytes = paramsReader.read(fieldKeyLength)
1662
+ const fieldKey = Utils.toUTF8(fieldKeyBytes)
1633
1663
 
1634
- // Call the method
1635
- const listResult = await this.wallet.listCertificates(args, originator)
1636
-
1637
- // Serialize the result
1638
- const resultWriter = new Utils.Writer()
1639
-
1640
- // totalCertificates
1641
- resultWriter.writeVarIntNum(listResult.totalCertificates)
1642
-
1643
- // certificates
1644
- for (const cert of listResult.certificates) {
1645
- const certificate = new Certificate(
1646
- cert.type,
1647
- cert.serialNumber,
1648
- cert.subject,
1649
- cert.certifier,
1650
- cert.revocationOutpoint,
1651
- cert.fields,
1652
- cert.signature
1653
- )
1654
- const certBin = certificate.toBinary()
1664
+ const fieldValueLength = paramsReader.readVarIntNum()
1665
+ const fieldValueBytes = paramsReader.read(fieldValueLength)
1666
+ const fieldValue = Utils.toBase64(fieldValueBytes)
1655
1667
 
1656
- // Write certificate binary length and data
1657
- resultWriter.writeVarIntNum(certBin.length)
1658
- resultWriter.write(certBin)
1668
+ args.keyringForSubject[fieldKey] = fieldValue
1659
1669
  }
1660
-
1661
- // Return the response
1662
- const responseWriter = new Utils.Writer()
1663
- responseWriter.writeUInt8(0) // errorByte = 0
1664
- responseWriter.write(resultWriter.toArray())
1665
- return responseWriter.toArray()
1670
+ } else {
1671
+ // args.certifierUrl
1672
+ const certifierUrlLength = paramsReader.readVarIntNum()
1673
+ const certifierUrlBytes = paramsReader.read(certifierUrlLength)
1674
+ args.certifierUrl = Utils.toUTF8(certifierUrlBytes)
1666
1675
  }
1667
1676
 
1668
- case 'proveCertificate':
1669
- {
1670
- const args: any = {}
1677
+ // Call the method
1678
+ const acquireResult = await this.wallet.acquireCertificate(
1679
+ args,
1680
+ originator
1681
+ )
1682
+
1683
+ // Serialize the certificate (assuming Certificate class is available)
1684
+ const cert = new Certificate(
1685
+ acquireResult.type,
1686
+ acquireResult.serialNumber,
1687
+ acquireResult.subject,
1688
+ acquireResult.certifier,
1689
+ acquireResult.revocationOutpoint,
1690
+ acquireResult.fields,
1691
+ acquireResult.signature
1692
+ )
1693
+ const certBin = cert.toBinary()
1694
+
1695
+ // Return success code and certificate binary
1696
+ const responseWriter = new Utils.Writer()
1697
+ responseWriter.writeUInt8(0) // errorByte = 0
1698
+ responseWriter.write(certBin)
1699
+ return responseWriter.toArray()
1700
+ }
1701
+
1702
+ case 'listCertificates': {
1703
+ const args: any = {}
1671
1704
 
1672
- // Read certificate
1673
- const cert: any = {}
1705
+ // Read certifiers
1706
+ const certifiersLength = paramsReader.readVarIntNum()
1707
+ args.certifiers = []
1708
+ for (let i = 0; i < certifiersLength; i++) {
1709
+ const certifierBytes = paramsReader.read(33)
1710
+ args.certifiers.push(Utils.toHex(certifierBytes))
1711
+ }
1674
1712
 
1675
- // Read type
1713
+ // Read types
1714
+ const typesLength = paramsReader.readVarIntNum()
1715
+ args.types = []
1716
+ for (let i = 0; i < typesLength; i++) {
1676
1717
  const typeBytes = paramsReader.read(32)
1677
- cert.type = Utils.toBase64(typeBytes)
1718
+ args.types.push(Utils.toBase64(typeBytes))
1719
+ }
1678
1720
 
1679
- // Read subject
1680
- const subjectBytes = paramsReader.read(33)
1681
- cert.subject = Utils.toHex(subjectBytes)
1721
+ // Read limit and offset
1722
+ const limit = paramsReader.readVarIntNum()
1723
+ if (limit >= 0) {
1724
+ args.limit = limit
1725
+ } else {
1726
+ args.limit = undefined
1727
+ }
1682
1728
 
1683
- // Read serialNumber
1684
- const serialNumberBytes = paramsReader.read(32)
1685
- cert.serialNumber = Utils.toBase64(serialNumberBytes)
1729
+ const offset = paramsReader.readVarIntNum()
1730
+ if (offset >= 0) {
1731
+ args.offset = offset
1732
+ } else {
1733
+ args.offset = undefined
1734
+ }
1686
1735
 
1687
- // Read certifier
1688
- const certifierBytes = paramsReader.read(33)
1689
- cert.certifier = Utils.toHex(certifierBytes)
1736
+ // Read privileged parameters
1737
+ const privilegedFlag = paramsReader.readInt8()
1738
+ if (privilegedFlag === -1) {
1739
+ args.privileged = undefined
1740
+ } else {
1741
+ args.privileged = privilegedFlag === 1
1742
+ }
1743
+
1744
+ const privilegedReasonLength = paramsReader.readInt8()
1745
+ if (privilegedReasonLength === -1) {
1746
+ args.privilegedReason = undefined
1747
+ } else {
1748
+ const privilegedReasonBytes = paramsReader.read(
1749
+ privilegedReasonLength
1750
+ )
1751
+ args.privilegedReason = Utils.toUTF8(privilegedReasonBytes)
1752
+ }
1690
1753
 
1691
- // Read revocationOutpoint
1692
- cert.revocationOutpoint = this.decodeOutpoint(paramsReader)
1754
+ // Call the method
1755
+ const listResult = await this.wallet.listCertificates(
1756
+ args,
1757
+ originator
1758
+ )
1693
1759
 
1694
- // Read signature
1695
- const signatureLength = paramsReader.readVarIntNum()
1696
- const signatureBytes = paramsReader.read(signatureLength)
1697
- cert.signature = Utils.toHex(signatureBytes)
1760
+ // Serialize the result
1761
+ const resultWriter = new Utils.Writer()
1698
1762
 
1699
- // Read fields
1700
- const fieldsLength = paramsReader.readVarIntNum()
1701
- cert.fields = {}
1702
- for (let i = 0; i < fieldsLength; i++) {
1703
- const fieldNameLength = paramsReader.readVarIntNum()
1704
- const fieldNameBytes = paramsReader.read(fieldNameLength)
1705
- const fieldName = Utils.toUTF8(fieldNameBytes)
1763
+ // totalCertificates
1764
+ resultWriter.writeVarIntNum(listResult.totalCertificates)
1765
+
1766
+ // certificates
1767
+ for (const cert of listResult.certificates) {
1768
+ const certificate = new Certificate(
1769
+ cert.type,
1770
+ cert.serialNumber,
1771
+ cert.subject,
1772
+ cert.certifier,
1773
+ cert.revocationOutpoint,
1774
+ cert.fields,
1775
+ cert.signature
1776
+ )
1777
+ const certBin = certificate.toBinary()
1706
1778
 
1707
- const fieldValueLength = paramsReader.readVarIntNum()
1708
- const fieldValueBytes = paramsReader.read(fieldValueLength)
1709
- const fieldValue = Utils.toUTF8(fieldValueBytes)
1779
+ // Write certificate binary length and data
1780
+ resultWriter.writeVarIntNum(certBin.length)
1781
+ resultWriter.write(certBin)
1782
+ }
1710
1783
 
1711
- cert.fields[fieldName] = fieldValue
1712
- }
1784
+ // Return the response
1785
+ const responseWriter = new Utils.Writer()
1786
+ responseWriter.writeUInt8(0) // errorByte = 0
1787
+ responseWriter.write(resultWriter.toArray())
1788
+ return responseWriter.toArray()
1789
+ }
1713
1790
 
1714
- args.certificate = cert
1791
+ case 'proveCertificate': {
1792
+ const args: any = {}
1715
1793
 
1716
- // Read fields to reveal
1717
- const fieldsToRevealLength = paramsReader.readVarIntNum()
1718
- args.fieldsToReveal = []
1719
- for (let i = 0; i < fieldsToRevealLength; i++) {
1720
- const fieldNameLength = paramsReader.readVarIntNum()
1721
- const fieldNameBytes = paramsReader.read(fieldNameLength)
1722
- const fieldName = Utils.toUTF8(fieldNameBytes)
1723
- args.fieldsToReveal.push(fieldName)
1724
- }
1794
+ // Read certificate
1795
+ const cert: any = {}
1725
1796
 
1726
- // Read verifier
1727
- const verifierBytes = paramsReader.read(33)
1728
- args.verifier = Utils.toHex(verifierBytes)
1797
+ // Read type
1798
+ const typeBytes = paramsReader.read(32)
1799
+ cert.type = Utils.toBase64(typeBytes)
1729
1800
 
1730
- // Read privileged parameters
1731
- const privilegedFlag = paramsReader.readInt8()
1732
- if (privilegedFlag === -1) {
1733
- args.privileged = undefined
1734
- } else {
1735
- args.privileged = privilegedFlag === 1
1736
- }
1801
+ // Read subject
1802
+ const subjectBytes = paramsReader.read(33)
1803
+ cert.subject = Utils.toHex(subjectBytes)
1737
1804
 
1738
- const privilegedReasonLength = paramsReader.readInt8()
1739
- if (privilegedReasonLength === -1) {
1740
- args.privilegedReason = undefined
1741
- } else {
1742
- const privilegedReasonBytes = paramsReader.read(privilegedReasonLength)
1743
- args.privilegedReason = Utils.toUTF8(privilegedReasonBytes)
1744
- }
1805
+ // Read serialNumber
1806
+ const serialNumberBytes = paramsReader.read(32)
1807
+ cert.serialNumber = Utils.toBase64(serialNumberBytes)
1745
1808
 
1746
- // Call the method
1747
- const proveResult = await this.wallet.proveCertificate(args, originator)
1809
+ // Read certifier
1810
+ const certifierBytes = paramsReader.read(33)
1811
+ cert.certifier = Utils.toHex(certifierBytes)
1748
1812
 
1749
- // Serialize keyringForVerifier
1750
- const resultWriter = new Utils.Writer()
1813
+ // Read revocationOutpoint
1814
+ cert.revocationOutpoint = this.decodeOutpoint(paramsReader)
1751
1815
 
1752
- const keyringEntries = Object.entries(proveResult.keyringForVerifier)
1753
- resultWriter.writeVarIntNum(keyringEntries.length)
1754
- for (const [fieldName, fieldValue] of keyringEntries) {
1755
- const fieldNameBytes = Utils.toArray(fieldName, 'utf8')
1756
- resultWriter.writeVarIntNum(fieldNameBytes.length)
1757
- resultWriter.write(fieldNameBytes)
1816
+ // Read signature
1817
+ const signatureLength = paramsReader.readVarIntNum()
1818
+ const signatureBytes = paramsReader.read(signatureLength)
1819
+ cert.signature = Utils.toHex(signatureBytes)
1758
1820
 
1759
- const fieldValueBytes = Utils.toArray(fieldValue, 'base64')
1760
- resultWriter.writeVarIntNum(fieldValueBytes.length)
1761
- resultWriter.write(fieldValueBytes)
1762
- }
1821
+ // Read fields
1822
+ const fieldsLength = paramsReader.readVarIntNum()
1823
+ cert.fields = {}
1824
+ for (let i = 0; i < fieldsLength; i++) {
1825
+ const fieldNameLength = paramsReader.readVarIntNum()
1826
+ const fieldNameBytes = paramsReader.read(fieldNameLength)
1827
+ const fieldName = Utils.toUTF8(fieldNameBytes)
1763
1828
 
1764
- // Return the response
1765
- const responseWriter = new Utils.Writer()
1766
- responseWriter.writeUInt8(0) // errorByte = 0
1767
- responseWriter.write(resultWriter.toArray())
1768
- return responseWriter.toArray()
1829
+ const fieldValueLength = paramsReader.readVarIntNum()
1830
+ const fieldValueBytes = paramsReader.read(fieldValueLength)
1831
+ const fieldValue = Utils.toUTF8(fieldValueBytes)
1832
+
1833
+ cert.fields[fieldName] = fieldValue
1769
1834
  }
1770
1835
 
1771
- case 'relinquishCertificate':
1772
- {
1773
- const args: any = {}
1836
+ args.certificate = cert
1774
1837
 
1775
- // Read type
1776
- const typeBytes = paramsReader.read(32)
1777
- args.type = Utils.toBase64(typeBytes)
1838
+ // Read fields to reveal
1839
+ const fieldsToRevealLength = paramsReader.readVarIntNum()
1840
+ args.fieldsToReveal = []
1841
+ for (let i = 0; i < fieldsToRevealLength; i++) {
1842
+ const fieldNameLength = paramsReader.readVarIntNum()
1843
+ const fieldNameBytes = paramsReader.read(fieldNameLength)
1844
+ const fieldName = Utils.toUTF8(fieldNameBytes)
1845
+ args.fieldsToReveal.push(fieldName)
1846
+ }
1778
1847
 
1779
- // Read serialNumber
1780
- const serialNumberBytes = paramsReader.read(32)
1781
- args.serialNumber = Utils.toBase64(serialNumberBytes)
1848
+ // Read verifier
1849
+ const verifierBytes = paramsReader.read(33)
1850
+ args.verifier = Utils.toHex(verifierBytes)
1782
1851
 
1783
- // Read certifier
1784
- const certifierBytes = paramsReader.read(33)
1785
- args.certifier = Utils.toHex(certifierBytes)
1852
+ // Read privileged parameters
1853
+ const privilegedFlag = paramsReader.readInt8()
1854
+ if (privilegedFlag === -1) {
1855
+ args.privileged = undefined
1856
+ } else {
1857
+ args.privileged = privilegedFlag === 1
1858
+ }
1859
+
1860
+ const privilegedReasonLength = paramsReader.readInt8()
1861
+ if (privilegedReasonLength === -1) {
1862
+ args.privilegedReason = undefined
1863
+ } else {
1864
+ const privilegedReasonBytes = paramsReader.read(
1865
+ privilegedReasonLength
1866
+ )
1867
+ args.privilegedReason = Utils.toUTF8(privilegedReasonBytes)
1868
+ }
1869
+
1870
+ // Call the method
1871
+ const proveResult = await this.wallet.proveCertificate(
1872
+ args,
1873
+ originator
1874
+ )
1875
+
1876
+ // Serialize keyringForVerifier
1877
+ const resultWriter = new Utils.Writer()
1786
1878
 
1787
- // Call the method
1788
- await this.wallet.relinquishCertificate(args, originator)
1879
+ const keyringEntries = Object.entries(proveResult.keyringForVerifier)
1880
+ resultWriter.writeVarIntNum(keyringEntries.length)
1881
+ for (const [fieldName, fieldValue] of keyringEntries) {
1882
+ const fieldNameBytes = Utils.toArray(fieldName, 'utf8')
1883
+ resultWriter.writeVarIntNum(fieldNameBytes.length)
1884
+ resultWriter.write(fieldNameBytes)
1789
1885
 
1790
- // Return success code
1791
- const responseWriter = new Utils.Writer()
1792
- responseWriter.writeUInt8(0) // errorByte = 0
1793
- return responseWriter.toArray()
1886
+ const fieldValueBytes = Utils.toArray(fieldValue, 'base64')
1887
+ resultWriter.writeVarIntNum(fieldValueBytes.length)
1888
+ resultWriter.write(fieldValueBytes)
1794
1889
  }
1795
1890
 
1796
- case 'discoverByIdentityKey':
1797
- {
1798
- const args: any = {}
1891
+ // Return the response
1892
+ const responseWriter = new Utils.Writer()
1893
+ responseWriter.writeUInt8(0) // errorByte = 0
1894
+ responseWriter.write(resultWriter.toArray())
1895
+ return responseWriter.toArray()
1896
+ }
1799
1897
 
1800
- // Read identityKey
1801
- const identityKeyBytes = paramsReader.read(33)
1802
- args.identityKey = Utils.toHex(identityKeyBytes)
1898
+ case 'relinquishCertificate': {
1899
+ const args: any = {}
1803
1900
 
1804
- // Read limit and offset
1805
- const limit = paramsReader.readVarIntNum()
1806
- if (limit >= 0) {
1807
- args.limit = limit
1808
- } else {
1809
- args.limit = undefined
1810
- }
1901
+ // Read type
1902
+ const typeBytes = paramsReader.read(32)
1903
+ args.type = Utils.toBase64(typeBytes)
1811
1904
 
1812
- const offset = paramsReader.readVarIntNum()
1813
- if (offset >= 0) {
1814
- args.offset = offset
1815
- } else {
1816
- args.offset = undefined
1817
- }
1905
+ // Read serialNumber
1906
+ const serialNumberBytes = paramsReader.read(32)
1907
+ args.serialNumber = Utils.toBase64(serialNumberBytes)
1818
1908
 
1819
- // Deserialize seekPermission
1820
- const seekPermission = paramsReader.readInt8()
1821
- if (seekPermission >= 0) {
1822
- args.seekPermission = seekPermission === 1
1823
- } else {
1824
- args.seekPermission = undefined
1825
- }
1909
+ // Read certifier
1910
+ const certifierBytes = paramsReader.read(33)
1911
+ args.certifier = Utils.toHex(certifierBytes)
1826
1912
 
1827
- // Call the method
1828
- const discoverResult = await this.wallet.discoverByIdentityKey(args, originator)
1913
+ // Call the method
1914
+ await this.wallet.relinquishCertificate(args, originator)
1829
1915
 
1830
- // Serialize the result
1831
- const result = this.serializeDiscoveryResult(discoverResult)
1916
+ // Return success code
1917
+ const responseWriter = new Utils.Writer()
1918
+ responseWriter.writeUInt8(0) // errorByte = 0
1919
+ return responseWriter.toArray()
1920
+ }
1921
+
1922
+ case 'discoverByIdentityKey': {
1923
+ const args: any = {}
1924
+
1925
+ // Read identityKey
1926
+ const identityKeyBytes = paramsReader.read(33)
1927
+ args.identityKey = Utils.toHex(identityKeyBytes)
1832
1928
 
1833
- // Return the response
1834
- const responseWriter = new Utils.Writer()
1835
- responseWriter.writeUInt8(0) // errorByte = 0
1836
- responseWriter.write(result)
1837
- return responseWriter.toArray()
1929
+ // Read limit and offset
1930
+ const limit = paramsReader.readVarIntNum()
1931
+ if (limit >= 0) {
1932
+ args.limit = limit
1933
+ } else {
1934
+ args.limit = undefined
1838
1935
  }
1839
1936
 
1840
- case 'discoverByAttributes':
1841
- {
1842
- const args: any = {}
1937
+ const offset = paramsReader.readVarIntNum()
1938
+ if (offset >= 0) {
1939
+ args.offset = offset
1940
+ } else {
1941
+ args.offset = undefined
1942
+ }
1843
1943
 
1844
- // Read attributes
1845
- const attributesLength = paramsReader.readVarIntNum()
1846
- args.attributes = {}
1847
- for (let i = 0; i < attributesLength; i++) {
1848
- const fieldKeyLength = paramsReader.readVarIntNum()
1849
- const fieldKeyBytes = paramsReader.read(fieldKeyLength)
1850
- const fieldKey = Utils.toUTF8(fieldKeyBytes)
1944
+ // Deserialize seekPermission
1945
+ const seekPermission = paramsReader.readInt8()
1946
+ if (seekPermission >= 0) {
1947
+ args.seekPermission = seekPermission === 1
1948
+ } else {
1949
+ args.seekPermission = undefined
1950
+ }
1851
1951
 
1852
- const fieldValueLength = paramsReader.readVarIntNum()
1853
- const fieldValueBytes = paramsReader.read(fieldValueLength)
1854
- const fieldValue = Utils.toUTF8(fieldValueBytes)
1952
+ // Call the method
1953
+ const discoverResult = await this.wallet.discoverByIdentityKey(
1954
+ args,
1955
+ originator
1956
+ )
1855
1957
 
1856
- args.attributes[fieldKey] = fieldValue
1857
- }
1958
+ // Serialize the result
1959
+ const result = this.serializeDiscoveryResult(discoverResult)
1858
1960
 
1859
- // Read limit and offset
1860
- const limit = paramsReader.readVarIntNum()
1861
- if (limit >= 0) {
1862
- args.limit = limit
1863
- } else {
1864
- args.limit = undefined
1865
- }
1961
+ // Return the response
1962
+ const responseWriter = new Utils.Writer()
1963
+ responseWriter.writeUInt8(0) // errorByte = 0
1964
+ responseWriter.write(result)
1965
+ return responseWriter.toArray()
1966
+ }
1866
1967
 
1867
- const offset = paramsReader.readVarIntNum()
1868
- if (offset >= 0) {
1869
- args.offset = offset
1870
- } else {
1871
- args.offset = undefined
1872
- }
1968
+ case 'discoverByAttributes': {
1969
+ const args: any = {}
1873
1970
 
1874
- // Deserialize seekPermission
1875
- const seekPermission = paramsReader.readInt8()
1876
- if (seekPermission >= 0) {
1877
- args.seekPermission = seekPermission === 1
1878
- } else {
1879
- args.seekPermission = undefined
1880
- }
1971
+ // Read attributes
1972
+ const attributesLength = paramsReader.readVarIntNum()
1973
+ args.attributes = {}
1974
+ for (let i = 0; i < attributesLength; i++) {
1975
+ const fieldKeyLength = paramsReader.readVarIntNum()
1976
+ const fieldKeyBytes = paramsReader.read(fieldKeyLength)
1977
+ const fieldKey = Utils.toUTF8(fieldKeyBytes)
1978
+
1979
+ const fieldValueLength = paramsReader.readVarIntNum()
1980
+ const fieldValueBytes = paramsReader.read(fieldValueLength)
1981
+ const fieldValue = Utils.toUTF8(fieldValueBytes)
1881
1982
 
1882
- // Call the method
1883
- const discoverResult = await this.wallet.discoverByAttributes(args, originator)
1983
+ args.attributes[fieldKey] = fieldValue
1984
+ }
1985
+
1986
+ // Read limit and offset
1987
+ const limit = paramsReader.readVarIntNum()
1988
+ if (limit >= 0) {
1989
+ args.limit = limit
1990
+ } else {
1991
+ args.limit = undefined
1992
+ }
1884
1993
 
1885
- // Serialize the result
1886
- const result = this.serializeDiscoveryResult(discoverResult)
1994
+ const offset = paramsReader.readVarIntNum()
1995
+ if (offset >= 0) {
1996
+ args.offset = offset
1997
+ } else {
1998
+ args.offset = undefined
1999
+ }
1887
2000
 
1888
- // Return the response
1889
- const responseWriter = new Utils.Writer()
1890
- responseWriter.writeUInt8(0) // errorByte = 0
1891
- responseWriter.write(result)
1892
- return responseWriter.toArray()
2001
+ // Deserialize seekPermission
2002
+ const seekPermission = paramsReader.readInt8()
2003
+ if (seekPermission >= 0) {
2004
+ args.seekPermission = seekPermission === 1
2005
+ } else {
2006
+ args.seekPermission = undefined
1893
2007
  }
1894
2008
 
2009
+ // Call the method
2010
+ const discoverResult = await this.wallet.discoverByAttributes(
2011
+ args,
2012
+ originator
2013
+ )
2014
+
2015
+ // Serialize the result
2016
+ const result = this.serializeDiscoveryResult(discoverResult)
2017
+
2018
+ // Return the response
2019
+ const responseWriter = new Utils.Writer()
2020
+ responseWriter.writeUInt8(0) // errorByte = 0
2021
+ responseWriter.write(result)
2022
+ return responseWriter.toArray()
2023
+ }
2024
+
1895
2025
  default:
1896
2026
  throw new Error(`Method ${callName} not implemented`)
1897
2027
  }
1898
2028
  } catch (err) {
1899
2029
  const responseWriter = new Utils.Writer()
1900
- responseWriter.writeUInt8((err).code || 1) // errorCode = 1 (generic error)
2030
+ responseWriter.writeUInt8(typeof err.code === 'number' ? err.code : 1) // errorCode = 1 (generic error)
1901
2031
 
1902
2032
  // Serialize the error message
1903
- const errorMessage = err.message || 'Unknown error'
2033
+ const errorMessage = typeof err.message === 'string' ? err.message : 'Unknown error'
1904
2034
  const errorMessageBytes = Utils.toArray(errorMessage, 'utf8')
1905
2035
  responseWriter.writeVarIntNum(errorMessageBytes.length)
1906
2036
  responseWriter.write(errorMessageBytes)
1907
2037
 
1908
2038
  // Serialize the stack trace
1909
- const stackTrace = err.stack || ''
2039
+ const stackTrace = typeof err.stack === 'string' ? err.stack : ''
1910
2040
  const stackTraceBytes = Utils.toArray(stackTrace, 'utf8')
1911
2041
  responseWriter.writeVarIntNum(stackTraceBytes.length)
1912
2042
  responseWriter.write(stackTraceBytes)
@@ -1929,7 +2059,9 @@ export default class WalletWireProcessor implements WalletWire {
1929
2059
  return Utils.toUTF8(bytes)
1930
2060
  }
1931
2061
 
1932
- private decodeCounterparty(reader: Utils.Reader): string | 'self' | 'anyone' | undefined {
2062
+ private decodeCounterparty(
2063
+ reader: Utils.Reader
2064
+ ): string | 'self' | 'anyone' | undefined {
1933
2065
  const counterpartyFlag = reader.readUInt8()
1934
2066
  if (counterpartyFlag === 11) {
1935
2067
  return 'self'
@@ -1976,7 +2108,10 @@ export default class WalletWireProcessor implements WalletWire {
1976
2108
  resultWriter.writeVarIntNum(iconUrlBytes.length)
1977
2109
  resultWriter.write(iconUrlBytes)
1978
2110
 
1979
- const descriptionBytes = Utils.toArray(cert.certifierInfo.description, 'utf8')
2111
+ const descriptionBytes = Utils.toArray(
2112
+ cert.certifierInfo.description,
2113
+ 'utf8'
2114
+ )
1980
2115
  resultWriter.writeVarIntNum(descriptionBytes.length)
1981
2116
  resultWriter.write(descriptionBytes)
1982
2117