@bsv/sdk 1.1.32 → 1.2.0

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