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