@0xsequence/relayer 2.3.39 → 3.0.0-beta.10

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 (83) hide show
  1. package/.turbo/turbo-build.log +5 -0
  2. package/CHANGELOG.md +3926 -0
  3. package/LICENSE +0 -17
  4. package/README.md +1 -2
  5. package/dist/index.d.ts +4 -0
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +3 -0
  8. package/dist/preconditions/codec.d.ts +12 -0
  9. package/dist/preconditions/codec.d.ts.map +1 -0
  10. package/dist/preconditions/codec.js +125 -0
  11. package/dist/preconditions/index.d.ts +4 -0
  12. package/dist/preconditions/index.d.ts.map +1 -0
  13. package/dist/preconditions/index.js +3 -0
  14. package/dist/preconditions/selectors.d.ts +7 -0
  15. package/dist/preconditions/selectors.d.ts.map +1 -0
  16. package/dist/preconditions/selectors.js +27 -0
  17. package/dist/preconditions/types.d.ts +70 -0
  18. package/dist/preconditions/types.d.ts.map +1 -0
  19. package/dist/preconditions/types.js +203 -0
  20. package/dist/relayer/index.d.ts +45 -0
  21. package/dist/relayer/index.d.ts.map +1 -0
  22. package/dist/relayer/index.js +3 -0
  23. package/dist/relayer/relayer.d.ts +26 -0
  24. package/dist/relayer/relayer.d.ts.map +1 -0
  25. package/dist/relayer/relayer.js +7 -0
  26. package/dist/relayer/rpc-relayer/index.d.ts +38 -0
  27. package/dist/relayer/rpc-relayer/index.d.ts.map +1 -0
  28. package/dist/relayer/rpc-relayer/index.js +375 -0
  29. package/dist/{declarations/src → relayer}/rpc-relayer/relayer.gen.d.ts +3 -2
  30. package/dist/relayer/rpc-relayer/relayer.gen.d.ts.map +1 -0
  31. package/dist/relayer/rpc-relayer/relayer.gen.js +1246 -0
  32. package/dist/relayer/standard/abi.d.ts +73 -0
  33. package/dist/relayer/standard/abi.d.ts.map +1 -0
  34. package/dist/relayer/standard/abi.js +10 -0
  35. package/dist/relayer/standard/eip6963.d.ts +31 -0
  36. package/dist/relayer/standard/eip6963.d.ts.map +1 -0
  37. package/dist/relayer/standard/eip6963.js +51 -0
  38. package/dist/relayer/standard/index.d.ts +5 -0
  39. package/dist/relayer/standard/index.d.ts.map +1 -0
  40. package/dist/relayer/standard/index.js +4 -0
  41. package/dist/relayer/standard/local.d.ts +60 -0
  42. package/dist/relayer/standard/local.d.ts.map +1 -0
  43. package/dist/relayer/standard/local.js +285 -0
  44. package/dist/relayer/standard/pk-relayer.d.ts +28 -0
  45. package/dist/relayer/standard/pk-relayer.d.ts.map +1 -0
  46. package/dist/relayer/standard/pk-relayer.js +112 -0
  47. package/dist/relayer/standard/sequence.d.ts +27 -0
  48. package/dist/relayer/standard/sequence.d.ts.map +1 -0
  49. package/dist/relayer/standard/sequence.js +84 -0
  50. package/package.json +28 -25
  51. package/src/index.ts +3 -111
  52. package/src/preconditions/codec.ts +190 -0
  53. package/src/preconditions/index.ts +3 -0
  54. package/src/preconditions/selectors.ts +38 -0
  55. package/src/preconditions/types.ts +201 -0
  56. package/src/relayer/index.ts +60 -0
  57. package/src/relayer/relayer.ts +37 -0
  58. package/src/relayer/rpc-relayer/index.ts +449 -0
  59. package/src/{rpc-relayer → relayer/rpc-relayer}/relayer.gen.ts +483 -258
  60. package/src/relayer/standard/abi.ts +13 -0
  61. package/src/relayer/standard/eip6963.ts +74 -0
  62. package/src/relayer/standard/index.ts +4 -0
  63. package/src/relayer/standard/local.ts +353 -0
  64. package/src/relayer/standard/pk-relayer.ts +138 -0
  65. package/src/relayer/standard/sequence.ts +110 -0
  66. package/test/preconditions/codec.test.ts +531 -0
  67. package/test/preconditions/preconditions.test.ts +283 -0
  68. package/test/preconditions/selectors.test.ts +415 -0
  69. package/test/preconditions/types.test.ts +443 -0
  70. package/test/relayer/relayer.test.ts +355 -0
  71. package/tsconfig.json +10 -0
  72. package/dist/0xsequence-relayer.cjs.d.ts +0 -2
  73. package/dist/0xsequence-relayer.cjs.dev.js +0 -1865
  74. package/dist/0xsequence-relayer.cjs.js +0 -7
  75. package/dist/0xsequence-relayer.cjs.prod.js +0 -1865
  76. package/dist/0xsequence-relayer.esm.js +0 -1852
  77. package/dist/declarations/src/index.d.ts +0 -42
  78. package/dist/declarations/src/local-relayer.d.ts +0 -35
  79. package/dist/declarations/src/provider-relayer.d.ts +0 -47
  80. package/dist/declarations/src/rpc-relayer/index.d.ts +0 -72
  81. package/src/local-relayer.ts +0 -125
  82. package/src/provider-relayer.ts +0 -284
  83. package/src/rpc-relayer/index.ts +0 -380
@@ -0,0 +1,1246 @@
1
+ /* eslint-disable */
2
+ // sequence-relayer v0.4.1 7f8a4b83b00e0b6849c76c2ff0e23931e26b3d9f
3
+ // --
4
+ // Code generated by Webrpc-gen@v0.30.2 with typescript generator. DO NOT EDIT.
5
+ //
6
+ // webrpc-gen -schema=relayer.ridl -target=typescript -client -out=./clients/relayer.gen.ts -compat
7
+ // Webrpc description and code-gen version
8
+ export const WebrpcVersion = 'v1';
9
+ // Schema version of your RIDL schema
10
+ export const WebrpcSchemaVersion = 'v0.4.1';
11
+ // Schema hash generated from your RIDL schema
12
+ export const WebrpcSchemaHash = '7f8a4b83b00e0b6849c76c2ff0e23931e26b3d9f';
13
+ //
14
+ // Schema types
15
+ //
16
+ export var ETHTxnStatus;
17
+ (function (ETHTxnStatus) {
18
+ ETHTxnStatus["UNKNOWN"] = "UNKNOWN";
19
+ ETHTxnStatus["DROPPED"] = "DROPPED";
20
+ ETHTxnStatus["QUEUED"] = "QUEUED";
21
+ ETHTxnStatus["SENT"] = "SENT";
22
+ ETHTxnStatus["SUCCEEDED"] = "SUCCEEDED";
23
+ ETHTxnStatus["PARTIALLY_FAILED"] = "PARTIALLY_FAILED";
24
+ ETHTxnStatus["FAILED"] = "FAILED";
25
+ ETHTxnStatus["PENDING_PRECONDITION"] = "PENDING_PRECONDITION";
26
+ })(ETHTxnStatus || (ETHTxnStatus = {}));
27
+ export var TransferType;
28
+ (function (TransferType) {
29
+ TransferType["SEND"] = "SEND";
30
+ TransferType["RECEIVE"] = "RECEIVE";
31
+ TransferType["BRIDGE_DEPOSIT"] = "BRIDGE_DEPOSIT";
32
+ TransferType["BRIDGE_WITHDRAW"] = "BRIDGE_WITHDRAW";
33
+ TransferType["BURN"] = "BURN";
34
+ TransferType["UNKNOWN"] = "UNKNOWN";
35
+ })(TransferType || (TransferType = {}));
36
+ export var SimulateStatus;
37
+ (function (SimulateStatus) {
38
+ SimulateStatus["SKIPPED"] = "SKIPPED";
39
+ SimulateStatus["SUCCEEDED"] = "SUCCEEDED";
40
+ SimulateStatus["FAILED"] = "FAILED";
41
+ SimulateStatus["ABORTED"] = "ABORTED";
42
+ SimulateStatus["REVERTED"] = "REVERTED";
43
+ SimulateStatus["NOT_ENOUGH_GAS"] = "NOT_ENOUGH_GAS";
44
+ })(SimulateStatus || (SimulateStatus = {}));
45
+ export var FeeTokenType;
46
+ (function (FeeTokenType) {
47
+ FeeTokenType["UNKNOWN"] = "UNKNOWN";
48
+ FeeTokenType["ERC20_TOKEN"] = "ERC20_TOKEN";
49
+ FeeTokenType["ERC1155_TOKEN"] = "ERC1155_TOKEN";
50
+ })(FeeTokenType || (FeeTokenType = {}));
51
+ export var SortOrder;
52
+ (function (SortOrder) {
53
+ SortOrder["DESC"] = "DESC";
54
+ SortOrder["ASC"] = "ASC";
55
+ })(SortOrder || (SortOrder = {}));
56
+ //
57
+ // Client
58
+ //
59
+ export class Relayer {
60
+ hostname;
61
+ fetch;
62
+ path = '/rpc/Relayer/';
63
+ constructor(hostname, fetch) {
64
+ this.hostname = hostname.replace(/\/*$/, '');
65
+ this.fetch = (input, init) => fetch(input, init);
66
+ }
67
+ url(name) {
68
+ return this.hostname + this.path + name;
69
+ }
70
+ queryKey = {
71
+ ping: () => ['Relayer', 'ping'],
72
+ version: () => ['Relayer', 'version'],
73
+ runtimeStatus: () => ['Relayer', 'runtimeStatus'],
74
+ getSequenceContext: () => ['Relayer', 'getSequenceContext'],
75
+ getChainID: () => ['Relayer', 'getChainID'],
76
+ sendMetaTxn: (req) => ['Relayer', 'sendMetaTxn', req],
77
+ getMetaTxnNonce: (req) => ['Relayer', 'getMetaTxnNonce', req],
78
+ getMetaTxnReceipt: (req) => ['Relayer', 'getMetaTxnReceipt', req],
79
+ simulate: (req) => ['Relayer', 'simulate', req],
80
+ simulateV3: (req) => ['Relayer', 'simulateV3', req],
81
+ updateMetaTxnGasLimits: (req) => ['Relayer', 'updateMetaTxnGasLimits', req],
82
+ feeTokens: () => ['Relayer', 'feeTokens'],
83
+ feeOptions: (req) => ['Relayer', 'feeOptions', req],
84
+ getMetaTxnNetworkFeeOptions: (req) => ['Relayer', 'getMetaTxnNetworkFeeOptions', req],
85
+ getMetaTransactions: (req) => ['Relayer', 'getMetaTransactions', req],
86
+ getTransactionCost: (req) => ['Relayer', 'getTransactionCost', req],
87
+ sentTransactions: (req) => ['Relayer', 'sentTransactions', req],
88
+ pendingTransactions: (req) => ['Relayer', 'pendingTransactions', req],
89
+ getGasTank: (req) => ['Relayer', 'getGasTank', req],
90
+ addGasTank: (req) => ['Relayer', 'addGasTank', req],
91
+ updateGasTank: (req) => ['Relayer', 'updateGasTank', req],
92
+ nextGasTankBalanceAdjustmentNonce: (req) => ['Relayer', 'nextGasTankBalanceAdjustmentNonce', req],
93
+ adjustGasTankBalance: (req) => ['Relayer', 'adjustGasTankBalance', req],
94
+ getGasTankBalanceAdjustment: (req) => ['Relayer', 'getGasTankBalanceAdjustment', req],
95
+ listGasTankBalanceAdjustments: (req) => ['Relayer', 'listGasTankBalanceAdjustments', req],
96
+ listGasSponsors: (req) => ['Relayer', 'listGasSponsors', req],
97
+ getGasSponsor: (req) => ['Relayer', 'getGasSponsor', req],
98
+ addGasSponsor: (req) => ['Relayer', 'addGasSponsor', req],
99
+ updateGasSponsor: (req) => ['Relayer', 'updateGasSponsor', req],
100
+ removeGasSponsor: (req) => ['Relayer', 'removeGasSponsor', req],
101
+ addressGasSponsors: (req) => ['Relayer', 'addressGasSponsors', req],
102
+ getProjectBalance: (req) => ['Relayer', 'getProjectBalance', req],
103
+ adjustProjectBalance: (req) => ['Relayer', 'adjustProjectBalance', req],
104
+ };
105
+ ping = (headers, signal) => {
106
+ return this.fetch(this.url('Ping'), createHttpRequest('{}', headers, signal)).then((res) => {
107
+ return buildResponse(res).then((_data) => {
108
+ return JsonDecode(_data, 'PingReturn');
109
+ });
110
+ }, (error) => {
111
+ throw WebrpcRequestFailedError.new({
112
+ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
113
+ });
114
+ });
115
+ };
116
+ version = (headers, signal) => {
117
+ return this.fetch(this.url('Version'), createHttpRequest('{}', headers, signal)).then((res) => {
118
+ return buildResponse(res).then((_data) => {
119
+ return JsonDecode(_data, 'VersionReturn');
120
+ });
121
+ }, (error) => {
122
+ throw WebrpcRequestFailedError.new({
123
+ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
124
+ });
125
+ });
126
+ };
127
+ runtimeStatus = (headers, signal) => {
128
+ return this.fetch(this.url('RuntimeStatus'), createHttpRequest('{}', headers, signal)).then((res) => {
129
+ return buildResponse(res).then((_data) => {
130
+ return JsonDecode(_data, 'RuntimeStatusReturn');
131
+ });
132
+ }, (error) => {
133
+ throw WebrpcRequestFailedError.new({
134
+ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
135
+ });
136
+ });
137
+ };
138
+ getSequenceContext = (headers, signal) => {
139
+ return this.fetch(this.url('GetSequenceContext'), createHttpRequest('{}', headers, signal)).then((res) => {
140
+ return buildResponse(res).then((_data) => {
141
+ return JsonDecode(_data, 'GetSequenceContextReturn');
142
+ });
143
+ }, (error) => {
144
+ throw WebrpcRequestFailedError.new({
145
+ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
146
+ });
147
+ });
148
+ };
149
+ getChainID = (headers, signal) => {
150
+ return this.fetch(this.url('GetChainID'), createHttpRequest('{}', headers, signal)).then((res) => {
151
+ return buildResponse(res).then((_data) => {
152
+ return JsonDecode(_data, 'GetChainIDReturn');
153
+ });
154
+ }, (error) => {
155
+ throw WebrpcRequestFailedError.new({
156
+ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
157
+ });
158
+ });
159
+ };
160
+ sendMetaTxn = (req, headers, signal) => {
161
+ return this.fetch(this.url('SendMetaTxn'), createHttpRequest(JsonEncode(req, 'SendMetaTxnArgs'), headers, signal)).then((res) => {
162
+ return buildResponse(res).then((_data) => {
163
+ return JsonDecode(_data, 'SendMetaTxnReturn');
164
+ });
165
+ }, (error) => {
166
+ throw WebrpcRequestFailedError.new({
167
+ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
168
+ });
169
+ });
170
+ };
171
+ getMetaTxnNonce = (req, headers, signal) => {
172
+ return this.fetch(this.url('GetMetaTxnNonce'), createHttpRequest(JsonEncode(req, 'GetMetaTxnNonceArgs'), headers, signal)).then((res) => {
173
+ return buildResponse(res).then((_data) => {
174
+ return JsonDecode(_data, 'GetMetaTxnNonceReturn');
175
+ });
176
+ }, (error) => {
177
+ throw WebrpcRequestFailedError.new({
178
+ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
179
+ });
180
+ });
181
+ };
182
+ getMetaTxnReceipt = (req, headers, signal) => {
183
+ return this.fetch(this.url('GetMetaTxnReceipt'), createHttpRequest(JsonEncode(req, 'GetMetaTxnReceiptArgs'), headers, signal)).then((res) => {
184
+ return buildResponse(res).then((_data) => {
185
+ return JsonDecode(_data, 'GetMetaTxnReceiptReturn');
186
+ });
187
+ }, (error) => {
188
+ throw WebrpcRequestFailedError.new({
189
+ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
190
+ });
191
+ });
192
+ };
193
+ simulate = (req, headers, signal) => {
194
+ return this.fetch(this.url('Simulate'), createHttpRequest(JsonEncode(req, 'SimulateArgs'), headers, signal)).then((res) => {
195
+ return buildResponse(res).then((_data) => {
196
+ return JsonDecode(_data, 'SimulateReturn');
197
+ });
198
+ }, (error) => {
199
+ throw WebrpcRequestFailedError.new({
200
+ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
201
+ });
202
+ });
203
+ };
204
+ simulateV3 = (req, headers, signal) => {
205
+ return this.fetch(this.url('SimulateV3'), createHttpRequest(JsonEncode(req, 'SimulateV3Args'), headers, signal)).then((res) => {
206
+ return buildResponse(res).then((_data) => {
207
+ return JsonDecode(_data, 'SimulateV3Return');
208
+ });
209
+ }, (error) => {
210
+ throw WebrpcRequestFailedError.new({
211
+ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
212
+ });
213
+ });
214
+ };
215
+ updateMetaTxnGasLimits = (req, headers, signal) => {
216
+ return this.fetch(this.url('UpdateMetaTxnGasLimits'), createHttpRequest(JsonEncode(req, 'UpdateMetaTxnGasLimitsArgs'), headers, signal)).then((res) => {
217
+ return buildResponse(res).then((_data) => {
218
+ return JsonDecode(_data, 'UpdateMetaTxnGasLimitsReturn');
219
+ });
220
+ }, (error) => {
221
+ throw WebrpcRequestFailedError.new({
222
+ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
223
+ });
224
+ });
225
+ };
226
+ feeTokens = (headers, signal) => {
227
+ return this.fetch(this.url('FeeTokens'), createHttpRequest('{}', headers, signal)).then((res) => {
228
+ return buildResponse(res).then((_data) => {
229
+ return JsonDecode(_data, 'FeeTokensReturn');
230
+ });
231
+ }, (error) => {
232
+ throw WebrpcRequestFailedError.new({
233
+ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
234
+ });
235
+ });
236
+ };
237
+ feeOptions = (req, headers, signal) => {
238
+ return this.fetch(this.url('FeeOptions'), createHttpRequest(JsonEncode(req, 'FeeOptionsArgs'), headers, signal)).then((res) => {
239
+ return buildResponse(res).then((_data) => {
240
+ return JsonDecode(_data, 'FeeOptionsReturn');
241
+ });
242
+ }, (error) => {
243
+ throw WebrpcRequestFailedError.new({
244
+ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
245
+ });
246
+ });
247
+ };
248
+ getMetaTxnNetworkFeeOptions = (req, headers, signal) => {
249
+ return this.fetch(this.url('GetMetaTxnNetworkFeeOptions'), createHttpRequest(JsonEncode(req, 'GetMetaTxnNetworkFeeOptionsArgs'), headers, signal)).then((res) => {
250
+ return buildResponse(res).then((_data) => {
251
+ return JsonDecode(_data, 'GetMetaTxnNetworkFeeOptionsReturn');
252
+ });
253
+ }, (error) => {
254
+ throw WebrpcRequestFailedError.new({
255
+ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
256
+ });
257
+ });
258
+ };
259
+ getMetaTransactions = (req, headers, signal) => {
260
+ return this.fetch(this.url('GetMetaTransactions'), createHttpRequest(JsonEncode(req, 'GetMetaTransactionsArgs'), headers, signal)).then((res) => {
261
+ return buildResponse(res).then((_data) => {
262
+ return JsonDecode(_data, 'GetMetaTransactionsReturn');
263
+ });
264
+ }, (error) => {
265
+ throw WebrpcRequestFailedError.new({
266
+ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
267
+ });
268
+ });
269
+ };
270
+ getTransactionCost = (req, headers, signal) => {
271
+ return this.fetch(this.url('GetTransactionCost'), createHttpRequest(JsonEncode(req, 'GetTransactionCostArgs'), headers, signal)).then((res) => {
272
+ return buildResponse(res).then((_data) => {
273
+ return JsonDecode(_data, 'GetTransactionCostReturn');
274
+ });
275
+ }, (error) => {
276
+ throw WebrpcRequestFailedError.new({
277
+ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
278
+ });
279
+ });
280
+ };
281
+ sentTransactions = (req, headers, signal) => {
282
+ return this.fetch(this.url('SentTransactions'), createHttpRequest(JsonEncode(req, 'SentTransactionsArgs'), headers, signal)).then((res) => {
283
+ return buildResponse(res).then((_data) => {
284
+ return JsonDecode(_data, 'SentTransactionsReturn');
285
+ });
286
+ }, (error) => {
287
+ throw WebrpcRequestFailedError.new({
288
+ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
289
+ });
290
+ });
291
+ };
292
+ pendingTransactions = (req, headers, signal) => {
293
+ return this.fetch(this.url('PendingTransactions'), createHttpRequest(JsonEncode(req, 'PendingTransactionsArgs'), headers, signal)).then((res) => {
294
+ return buildResponse(res).then((_data) => {
295
+ return JsonDecode(_data, 'PendingTransactionsReturn');
296
+ });
297
+ }, (error) => {
298
+ throw WebrpcRequestFailedError.new({
299
+ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
300
+ });
301
+ });
302
+ };
303
+ getGasTank = (req, headers, signal) => {
304
+ return this.fetch(this.url('GetGasTank'), createHttpRequest(JsonEncode(req, 'GetGasTankArgs'), headers, signal)).then((res) => {
305
+ return buildResponse(res).then((_data) => {
306
+ return JsonDecode(_data, 'GetGasTankReturn');
307
+ });
308
+ }, (error) => {
309
+ throw WebrpcRequestFailedError.new({
310
+ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
311
+ });
312
+ });
313
+ };
314
+ addGasTank = (req, headers, signal) => {
315
+ return this.fetch(this.url('AddGasTank'), createHttpRequest(JsonEncode(req, 'AddGasTankArgs'), headers, signal)).then((res) => {
316
+ return buildResponse(res).then((_data) => {
317
+ return JsonDecode(_data, 'AddGasTankReturn');
318
+ });
319
+ }, (error) => {
320
+ throw WebrpcRequestFailedError.new({
321
+ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
322
+ });
323
+ });
324
+ };
325
+ updateGasTank = (req, headers, signal) => {
326
+ return this.fetch(this.url('UpdateGasTank'), createHttpRequest(JsonEncode(req, 'UpdateGasTankArgs'), headers, signal)).then((res) => {
327
+ return buildResponse(res).then((_data) => {
328
+ return JsonDecode(_data, 'UpdateGasTankReturn');
329
+ });
330
+ }, (error) => {
331
+ throw WebrpcRequestFailedError.new({
332
+ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
333
+ });
334
+ });
335
+ };
336
+ nextGasTankBalanceAdjustmentNonce = (req, headers, signal) => {
337
+ return this.fetch(this.url('NextGasTankBalanceAdjustmentNonce'), createHttpRequest(JsonEncode(req, 'NextGasTankBalanceAdjustmentNonceArgs'), headers, signal)).then((res) => {
338
+ return buildResponse(res).then((_data) => {
339
+ return JsonDecode(_data, 'NextGasTankBalanceAdjustmentNonceReturn');
340
+ });
341
+ }, (error) => {
342
+ throw WebrpcRequestFailedError.new({
343
+ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
344
+ });
345
+ });
346
+ };
347
+ adjustGasTankBalance = (req, headers, signal) => {
348
+ return this.fetch(this.url('AdjustGasTankBalance'), createHttpRequest(JsonEncode(req, 'AdjustGasTankBalanceArgs'), headers, signal)).then((res) => {
349
+ return buildResponse(res).then((_data) => {
350
+ return JsonDecode(_data, 'AdjustGasTankBalanceReturn');
351
+ });
352
+ }, (error) => {
353
+ throw WebrpcRequestFailedError.new({
354
+ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
355
+ });
356
+ });
357
+ };
358
+ getGasTankBalanceAdjustment = (req, headers, signal) => {
359
+ return this.fetch(this.url('GetGasTankBalanceAdjustment'), createHttpRequest(JsonEncode(req, 'GetGasTankBalanceAdjustmentArgs'), headers, signal)).then((res) => {
360
+ return buildResponse(res).then((_data) => {
361
+ return JsonDecode(_data, 'GetGasTankBalanceAdjustmentReturn');
362
+ });
363
+ }, (error) => {
364
+ throw WebrpcRequestFailedError.new({
365
+ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
366
+ });
367
+ });
368
+ };
369
+ listGasTankBalanceAdjustments = (req, headers, signal) => {
370
+ return this.fetch(this.url('ListGasTankBalanceAdjustments'), createHttpRequest(JsonEncode(req, 'ListGasTankBalanceAdjustmentsArgs'), headers, signal)).then((res) => {
371
+ return buildResponse(res).then((_data) => {
372
+ return JsonDecode(_data, 'ListGasTankBalanceAdjustmentsReturn');
373
+ });
374
+ }, (error) => {
375
+ throw WebrpcRequestFailedError.new({
376
+ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
377
+ });
378
+ });
379
+ };
380
+ listGasSponsors = (req, headers, signal) => {
381
+ return this.fetch(this.url('ListGasSponsors'), createHttpRequest(JsonEncode(req, 'ListGasSponsorsArgs'), headers, signal)).then((res) => {
382
+ return buildResponse(res).then((_data) => {
383
+ return JsonDecode(_data, 'ListGasSponsorsReturn');
384
+ });
385
+ }, (error) => {
386
+ throw WebrpcRequestFailedError.new({
387
+ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
388
+ });
389
+ });
390
+ };
391
+ getGasSponsor = (req, headers, signal) => {
392
+ return this.fetch(this.url('GetGasSponsor'), createHttpRequest(JsonEncode(req, 'GetGasSponsorArgs'), headers, signal)).then((res) => {
393
+ return buildResponse(res).then((_data) => {
394
+ return JsonDecode(_data, 'GetGasSponsorReturn');
395
+ });
396
+ }, (error) => {
397
+ throw WebrpcRequestFailedError.new({
398
+ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
399
+ });
400
+ });
401
+ };
402
+ addGasSponsor = (req, headers, signal) => {
403
+ return this.fetch(this.url('AddGasSponsor'), createHttpRequest(JsonEncode(req, 'AddGasSponsorArgs'), headers, signal)).then((res) => {
404
+ return buildResponse(res).then((_data) => {
405
+ return JsonDecode(_data, 'AddGasSponsorReturn');
406
+ });
407
+ }, (error) => {
408
+ throw WebrpcRequestFailedError.new({
409
+ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
410
+ });
411
+ });
412
+ };
413
+ updateGasSponsor = (req, headers, signal) => {
414
+ return this.fetch(this.url('UpdateGasSponsor'), createHttpRequest(JsonEncode(req, 'UpdateGasSponsorArgs'), headers, signal)).then((res) => {
415
+ return buildResponse(res).then((_data) => {
416
+ return JsonDecode(_data, 'UpdateGasSponsorReturn');
417
+ });
418
+ }, (error) => {
419
+ throw WebrpcRequestFailedError.new({
420
+ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
421
+ });
422
+ });
423
+ };
424
+ removeGasSponsor = (req, headers, signal) => {
425
+ return this.fetch(this.url('RemoveGasSponsor'), createHttpRequest(JsonEncode(req, 'RemoveGasSponsorArgs'), headers, signal)).then((res) => {
426
+ return buildResponse(res).then((_data) => {
427
+ return JsonDecode(_data, 'RemoveGasSponsorReturn');
428
+ });
429
+ }, (error) => {
430
+ throw WebrpcRequestFailedError.new({
431
+ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
432
+ });
433
+ });
434
+ };
435
+ addressGasSponsors = (req, headers, signal) => {
436
+ return this.fetch(this.url('AddressGasSponsors'), createHttpRequest(JsonEncode(req, 'AddressGasSponsorsArgs'), headers, signal)).then((res) => {
437
+ return buildResponse(res).then((_data) => {
438
+ return JsonDecode(_data, 'AddressGasSponsorsReturn');
439
+ });
440
+ }, (error) => {
441
+ throw WebrpcRequestFailedError.new({
442
+ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
443
+ });
444
+ });
445
+ };
446
+ getProjectBalance = (req, headers, signal) => {
447
+ return this.fetch(this.url('GetProjectBalance'), createHttpRequest(JsonEncode(req, 'GetProjectBalanceArgs'), headers, signal)).then((res) => {
448
+ return buildResponse(res).then((_data) => {
449
+ return JsonDecode(_data, 'GetProjectBalanceReturn');
450
+ });
451
+ }, (error) => {
452
+ throw WebrpcRequestFailedError.new({
453
+ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
454
+ });
455
+ });
456
+ };
457
+ adjustProjectBalance = (req, headers, signal) => {
458
+ return this.fetch(this.url('AdjustProjectBalance'), createHttpRequest(JsonEncode(req, 'AdjustProjectBalanceArgs'), headers, signal)).then((res) => {
459
+ return buildResponse(res).then((_data) => {
460
+ return JsonDecode(_data, 'AdjustProjectBalanceReturn');
461
+ });
462
+ }, (error) => {
463
+ throw WebrpcRequestFailedError.new({
464
+ cause: `fetch(): ${error instanceof Error ? error.message : String(error)}`,
465
+ });
466
+ });
467
+ };
468
+ }
469
+ const createHttpRequest = (body = '{}', headers = {}, signal = null) => {
470
+ const reqHeaders = { ...headers, 'Content-Type': 'application/json' };
471
+ return { method: 'POST', headers: reqHeaders, body, signal };
472
+ };
473
+ const buildResponse = (res) => {
474
+ return res.text().then((text) => {
475
+ let data;
476
+ try {
477
+ data = JSON.parse(text);
478
+ }
479
+ catch (error) {
480
+ throw WebrpcBadResponseError.new({
481
+ status: res.status,
482
+ cause: `JSON.parse(): ${error instanceof Error ? error.message : String(error)}: response text: ${text}`,
483
+ });
484
+ }
485
+ if (!res.ok) {
486
+ const code = typeof data.code === 'number' ? data.code : 0;
487
+ throw (webrpcErrorByCode[code] || WebrpcError).new(data);
488
+ }
489
+ return data;
490
+ });
491
+ };
492
+ //
493
+ // BigInt helpers
494
+ //
495
+ const BIG_INT_FIELDS = {
496
+ SendMetaTxnArgs: [['preconditions', 'TransactionPrecondition[]']],
497
+ TransactionPrecondition: ['minAmount'],
498
+ Transactions: [['preconditions', 'TransactionPrecondition[]']],
499
+ };
500
+ // Encode in-place: mutate provided object graph to serialize bigints to strings.
501
+ function encodeType(typ, obj) {
502
+ if (obj == null || typeof obj !== 'object')
503
+ return obj;
504
+ const descs = BIG_INT_FIELDS[typ] || [];
505
+ if (!descs.length)
506
+ return obj;
507
+ for (const d of descs) {
508
+ if (Array.isArray(d)) {
509
+ const [fieldName, nestedType] = d;
510
+ if (fieldName.endsWith('[]')) {
511
+ const base = fieldName.slice(0, -2);
512
+ const arr = obj[base];
513
+ if (Array.isArray(arr)) {
514
+ for (let i = 0; i < arr.length; i++)
515
+ arr[i] = encodeType(nestedType, arr[i]);
516
+ }
517
+ }
518
+ else if (obj[fieldName]) {
519
+ obj[fieldName] = encodeType(nestedType, obj[fieldName]);
520
+ }
521
+ continue;
522
+ }
523
+ if (d.endsWith('[]')) {
524
+ const base = d.slice(0, -2);
525
+ const arr = obj[base];
526
+ if (Array.isArray(arr)) {
527
+ for (let i = 0; i < arr.length; i++) {
528
+ if (typeof arr[i] === 'bigint')
529
+ arr[i] = arr[i].toString();
530
+ }
531
+ }
532
+ continue;
533
+ }
534
+ if (typeof obj[d] === 'bigint')
535
+ obj[d] = obj[d].toString();
536
+ }
537
+ return obj;
538
+ }
539
+ // Decode in-place: mutate object graph; throw if expected numeric string is invalid.
540
+ function decodeType(typ, obj) {
541
+ if (obj == null || typeof obj !== 'object')
542
+ return obj;
543
+ const descs = BIG_INT_FIELDS[typ] || [];
544
+ if (!descs.length)
545
+ return obj;
546
+ for (const d of descs) {
547
+ if (Array.isArray(d)) {
548
+ const [fieldName, nestedType] = d;
549
+ if (fieldName.endsWith('[]')) {
550
+ const base = fieldName.slice(0, -2);
551
+ const arr = obj[base];
552
+ if (Array.isArray(arr)) {
553
+ for (let i = 0; i < arr.length; i++)
554
+ arr[i] = decodeType(nestedType, arr[i]);
555
+ }
556
+ }
557
+ else if (obj[fieldName]) {
558
+ obj[fieldName] = decodeType(nestedType, obj[fieldName]);
559
+ }
560
+ continue;
561
+ }
562
+ if (d.endsWith('[]')) {
563
+ const base = d.slice(0, -2);
564
+ const arr = obj[base];
565
+ if (Array.isArray(arr)) {
566
+ for (let i = 0; i < arr.length; i++) {
567
+ const v = arr[i];
568
+ if (typeof v === 'string') {
569
+ try {
570
+ arr[i] = BigInt(v);
571
+ }
572
+ catch (e) {
573
+ throw WebrpcBadResponseError.new({ cause: `Invalid bigint value for ${base}[${i}]: ${v}` });
574
+ }
575
+ }
576
+ }
577
+ }
578
+ continue;
579
+ }
580
+ const v = obj[d];
581
+ if (typeof v === 'string') {
582
+ try {
583
+ obj[d] = BigInt(v);
584
+ }
585
+ catch (e) {
586
+ throw WebrpcBadResponseError.new({ cause: `Invalid bigint value for ${d}: ${v}` });
587
+ }
588
+ }
589
+ }
590
+ return obj;
591
+ }
592
+ // Encode object of given root type to JSON with BigInts converted to decimal strings.
593
+ export const JsonEncode = (obj, typ = '') => {
594
+ return JSON.stringify(encodeType(typ, obj));
595
+ };
596
+ // Decode data (JSON string or already-parsed object) and convert declared BigInt string fields back to BigInt.
597
+ export const JsonDecode = (data, typ = '') => {
598
+ let parsed = data;
599
+ if (typeof data === 'string') {
600
+ try {
601
+ parsed = JSON.parse(data);
602
+ }
603
+ catch (err) {
604
+ throw WebrpcBadResponseError.new({ cause: `JsonDecode: JSON.parse failed: ${err.message}` });
605
+ }
606
+ }
607
+ return decodeType(typ, parsed);
608
+ };
609
+ export class WebrpcError extends Error {
610
+ code;
611
+ status;
612
+ constructor(error = {}) {
613
+ super(error.message);
614
+ this.name = error.name || 'WebrpcEndpointError';
615
+ this.code = typeof error.code === 'number' ? error.code : 0;
616
+ this.message = error.message || `endpoint error`;
617
+ this.status = typeof error.status === 'number' ? error.status : 400;
618
+ if (error.cause !== undefined)
619
+ this.cause = error.cause;
620
+ Object.setPrototypeOf(this, WebrpcError.prototype);
621
+ }
622
+ static new(payload) {
623
+ return new this({ message: payload.message, code: payload.code, status: payload.status, cause: payload.cause });
624
+ }
625
+ }
626
+ export class WebrpcEndpointError extends WebrpcError {
627
+ constructor(error = {}) {
628
+ super(error);
629
+ this.name = error.name || 'WebrpcEndpoint';
630
+ this.code = typeof error.code === 'number' ? error.code : 0;
631
+ this.message = error.message || `endpoint error`;
632
+ this.status = typeof error.status === 'number' ? error.status : 400;
633
+ if (error.cause !== undefined)
634
+ this.cause = error.cause;
635
+ Object.setPrototypeOf(this, WebrpcEndpointError.prototype);
636
+ }
637
+ }
638
+ export class WebrpcRequestFailedError extends WebrpcError {
639
+ constructor(error = {}) {
640
+ super(error);
641
+ this.name = error.name || 'WebrpcRequestFailed';
642
+ this.code = typeof error.code === 'number' ? error.code : -1;
643
+ this.message = error.message || `request failed`;
644
+ this.status = typeof error.status === 'number' ? error.status : 400;
645
+ if (error.cause !== undefined)
646
+ this.cause = error.cause;
647
+ Object.setPrototypeOf(this, WebrpcRequestFailedError.prototype);
648
+ }
649
+ }
650
+ export class WebrpcBadRouteError extends WebrpcError {
651
+ constructor(error = {}) {
652
+ super(error);
653
+ this.name = error.name || 'WebrpcBadRoute';
654
+ this.code = typeof error.code === 'number' ? error.code : -2;
655
+ this.message = error.message || `bad route`;
656
+ this.status = typeof error.status === 'number' ? error.status : 404;
657
+ if (error.cause !== undefined)
658
+ this.cause = error.cause;
659
+ Object.setPrototypeOf(this, WebrpcBadRouteError.prototype);
660
+ }
661
+ }
662
+ export class WebrpcBadMethodError extends WebrpcError {
663
+ constructor(error = {}) {
664
+ super(error);
665
+ this.name = error.name || 'WebrpcBadMethod';
666
+ this.code = typeof error.code === 'number' ? error.code : -3;
667
+ this.message = error.message || `bad method`;
668
+ this.status = typeof error.status === 'number' ? error.status : 405;
669
+ if (error.cause !== undefined)
670
+ this.cause = error.cause;
671
+ Object.setPrototypeOf(this, WebrpcBadMethodError.prototype);
672
+ }
673
+ }
674
+ export class WebrpcBadRequestError extends WebrpcError {
675
+ constructor(error = {}) {
676
+ super(error);
677
+ this.name = error.name || 'WebrpcBadRequest';
678
+ this.code = typeof error.code === 'number' ? error.code : -4;
679
+ this.message = error.message || `bad request`;
680
+ this.status = typeof error.status === 'number' ? error.status : 400;
681
+ if (error.cause !== undefined)
682
+ this.cause = error.cause;
683
+ Object.setPrototypeOf(this, WebrpcBadRequestError.prototype);
684
+ }
685
+ }
686
+ export class WebrpcBadResponseError extends WebrpcError {
687
+ constructor(error = {}) {
688
+ super(error);
689
+ this.name = error.name || 'WebrpcBadResponse';
690
+ this.code = typeof error.code === 'number' ? error.code : -5;
691
+ this.message = error.message || `bad response`;
692
+ this.status = typeof error.status === 'number' ? error.status : 500;
693
+ if (error.cause !== undefined)
694
+ this.cause = error.cause;
695
+ Object.setPrototypeOf(this, WebrpcBadResponseError.prototype);
696
+ }
697
+ }
698
+ export class WebrpcServerPanicError extends WebrpcError {
699
+ constructor(error = {}) {
700
+ super(error);
701
+ this.name = error.name || 'WebrpcServerPanic';
702
+ this.code = typeof error.code === 'number' ? error.code : -6;
703
+ this.message = error.message || `server panic`;
704
+ this.status = typeof error.status === 'number' ? error.status : 500;
705
+ if (error.cause !== undefined)
706
+ this.cause = error.cause;
707
+ Object.setPrototypeOf(this, WebrpcServerPanicError.prototype);
708
+ }
709
+ }
710
+ export class WebrpcInternalErrorError extends WebrpcError {
711
+ constructor(error = {}) {
712
+ super(error);
713
+ this.name = error.name || 'WebrpcInternalError';
714
+ this.code = typeof error.code === 'number' ? error.code : -7;
715
+ this.message = error.message || `internal error`;
716
+ this.status = typeof error.status === 'number' ? error.status : 500;
717
+ if (error.cause !== undefined)
718
+ this.cause = error.cause;
719
+ Object.setPrototypeOf(this, WebrpcInternalErrorError.prototype);
720
+ }
721
+ }
722
+ export class WebrpcClientAbortedError extends WebrpcError {
723
+ constructor(error = {}) {
724
+ super(error);
725
+ this.name = error.name || 'WebrpcClientAborted';
726
+ this.code = typeof error.code === 'number' ? error.code : -8;
727
+ this.message = error.message || `request aborted by client`;
728
+ this.status = typeof error.status === 'number' ? error.status : 400;
729
+ if (error.cause !== undefined)
730
+ this.cause = error.cause;
731
+ Object.setPrototypeOf(this, WebrpcClientAbortedError.prototype);
732
+ }
733
+ }
734
+ export class WebrpcStreamLostError extends WebrpcError {
735
+ constructor(error = {}) {
736
+ super(error);
737
+ this.name = error.name || 'WebrpcStreamLost';
738
+ this.code = typeof error.code === 'number' ? error.code : -9;
739
+ this.message = error.message || `stream lost`;
740
+ this.status = typeof error.status === 'number' ? error.status : 400;
741
+ if (error.cause !== undefined)
742
+ this.cause = error.cause;
743
+ Object.setPrototypeOf(this, WebrpcStreamLostError.prototype);
744
+ }
745
+ }
746
+ export class WebrpcStreamFinishedError extends WebrpcError {
747
+ constructor(error = {}) {
748
+ super(error);
749
+ this.name = error.name || 'WebrpcStreamFinished';
750
+ this.code = typeof error.code === 'number' ? error.code : -10;
751
+ this.message = error.message || `stream finished`;
752
+ this.status = typeof error.status === 'number' ? error.status : 200;
753
+ if (error.cause !== undefined)
754
+ this.cause = error.cause;
755
+ Object.setPrototypeOf(this, WebrpcStreamFinishedError.prototype);
756
+ }
757
+ }
758
+ //
759
+ // Schema errors
760
+ //
761
+ export class UnauthorizedError extends WebrpcError {
762
+ constructor(error = {}) {
763
+ super(error);
764
+ this.name = error.name || 'Unauthorized';
765
+ this.code = typeof error.code === 'number' ? error.code : 1000;
766
+ this.message = error.message || `Unauthorized access`;
767
+ this.status = typeof error.status === 'number' ? error.status : 401;
768
+ if (error.cause !== undefined)
769
+ this.cause = error.cause;
770
+ Object.setPrototypeOf(this, UnauthorizedError.prototype);
771
+ }
772
+ }
773
+ export class PermissionDeniedError extends WebrpcError {
774
+ constructor(error = {}) {
775
+ super(error);
776
+ this.name = error.name || 'PermissionDenied';
777
+ this.code = typeof error.code === 'number' ? error.code : 1001;
778
+ this.message = error.message || `Permission denied`;
779
+ this.status = typeof error.status === 'number' ? error.status : 403;
780
+ if (error.cause !== undefined)
781
+ this.cause = error.cause;
782
+ Object.setPrototypeOf(this, PermissionDeniedError.prototype);
783
+ }
784
+ }
785
+ export class SessionExpiredError extends WebrpcError {
786
+ constructor(error = {}) {
787
+ super(error);
788
+ this.name = error.name || 'SessionExpired';
789
+ this.code = typeof error.code === 'number' ? error.code : 1002;
790
+ this.message = error.message || `Session expired`;
791
+ this.status = typeof error.status === 'number' ? error.status : 403;
792
+ if (error.cause !== undefined)
793
+ this.cause = error.cause;
794
+ Object.setPrototypeOf(this, SessionExpiredError.prototype);
795
+ }
796
+ }
797
+ export class MethodNotFoundError extends WebrpcError {
798
+ constructor(error = {}) {
799
+ super(error);
800
+ this.name = error.name || 'MethodNotFound';
801
+ this.code = typeof error.code === 'number' ? error.code : 1003;
802
+ this.message = error.message || `Method not found`;
803
+ this.status = typeof error.status === 'number' ? error.status : 404;
804
+ if (error.cause !== undefined)
805
+ this.cause = error.cause;
806
+ Object.setPrototypeOf(this, MethodNotFoundError.prototype);
807
+ }
808
+ }
809
+ export class RequestConflictError extends WebrpcError {
810
+ constructor(error = {}) {
811
+ super(error);
812
+ this.name = error.name || 'RequestConflict';
813
+ this.code = typeof error.code === 'number' ? error.code : 1004;
814
+ this.message = error.message || `Conflict with target resource`;
815
+ this.status = typeof error.status === 'number' ? error.status : 409;
816
+ if (error.cause !== undefined)
817
+ this.cause = error.cause;
818
+ Object.setPrototypeOf(this, RequestConflictError.prototype);
819
+ }
820
+ }
821
+ export class AbortedError extends WebrpcError {
822
+ constructor(error = {}) {
823
+ super(error);
824
+ this.name = error.name || 'Aborted';
825
+ this.code = typeof error.code === 'number' ? error.code : 1005;
826
+ this.message = error.message || `Request aborted`;
827
+ this.status = typeof error.status === 'number' ? error.status : 400;
828
+ if (error.cause !== undefined)
829
+ this.cause = error.cause;
830
+ Object.setPrototypeOf(this, AbortedError.prototype);
831
+ }
832
+ }
833
+ export class GeoblockedError extends WebrpcError {
834
+ constructor(error = {}) {
835
+ super(error);
836
+ this.name = error.name || 'Geoblocked';
837
+ this.code = typeof error.code === 'number' ? error.code : 1006;
838
+ this.message = error.message || `Geoblocked region`;
839
+ this.status = typeof error.status === 'number' ? error.status : 451;
840
+ if (error.cause !== undefined)
841
+ this.cause = error.cause;
842
+ Object.setPrototypeOf(this, GeoblockedError.prototype);
843
+ }
844
+ }
845
+ export class RateLimitedError extends WebrpcError {
846
+ constructor(error = {}) {
847
+ super(error);
848
+ this.name = error.name || 'RateLimited';
849
+ this.code = typeof error.code === 'number' ? error.code : 1007;
850
+ this.message = error.message || `Rate-limited. Please slow down.`;
851
+ this.status = typeof error.status === 'number' ? error.status : 429;
852
+ if (error.cause !== undefined)
853
+ this.cause = error.cause;
854
+ Object.setPrototypeOf(this, RateLimitedError.prototype);
855
+ }
856
+ }
857
+ export class ProjectNotFoundError extends WebrpcError {
858
+ constructor(error = {}) {
859
+ super(error);
860
+ this.name = error.name || 'ProjectNotFound';
861
+ this.code = typeof error.code === 'number' ? error.code : 1008;
862
+ this.message = error.message || `Project not found`;
863
+ this.status = typeof error.status === 'number' ? error.status : 401;
864
+ if (error.cause !== undefined)
865
+ this.cause = error.cause;
866
+ Object.setPrototypeOf(this, ProjectNotFoundError.prototype);
867
+ }
868
+ }
869
+ export class AccessKeyNotFoundError extends WebrpcError {
870
+ constructor(error = {}) {
871
+ super(error);
872
+ this.name = error.name || 'AccessKeyNotFound';
873
+ this.code = typeof error.code === 'number' ? error.code : 1101;
874
+ this.message = error.message || `Access key not found`;
875
+ this.status = typeof error.status === 'number' ? error.status : 401;
876
+ if (error.cause !== undefined)
877
+ this.cause = error.cause;
878
+ Object.setPrototypeOf(this, AccessKeyNotFoundError.prototype);
879
+ }
880
+ }
881
+ export class AccessKeyMismatchError extends WebrpcError {
882
+ constructor(error = {}) {
883
+ super(error);
884
+ this.name = error.name || 'AccessKeyMismatch';
885
+ this.code = typeof error.code === 'number' ? error.code : 1102;
886
+ this.message = error.message || `Access key mismatch`;
887
+ this.status = typeof error.status === 'number' ? error.status : 409;
888
+ if (error.cause !== undefined)
889
+ this.cause = error.cause;
890
+ Object.setPrototypeOf(this, AccessKeyMismatchError.prototype);
891
+ }
892
+ }
893
+ export class InvalidOriginError extends WebrpcError {
894
+ constructor(error = {}) {
895
+ super(error);
896
+ this.name = error.name || 'InvalidOrigin';
897
+ this.code = typeof error.code === 'number' ? error.code : 1103;
898
+ this.message = error.message || `Invalid origin for Access Key`;
899
+ this.status = typeof error.status === 'number' ? error.status : 403;
900
+ if (error.cause !== undefined)
901
+ this.cause = error.cause;
902
+ Object.setPrototypeOf(this, InvalidOriginError.prototype);
903
+ }
904
+ }
905
+ export class InvalidServiceError extends WebrpcError {
906
+ constructor(error = {}) {
907
+ super(error);
908
+ this.name = error.name || 'InvalidService';
909
+ this.code = typeof error.code === 'number' ? error.code : 1104;
910
+ this.message = error.message || `Service not enabled for Access key`;
911
+ this.status = typeof error.status === 'number' ? error.status : 403;
912
+ if (error.cause !== undefined)
913
+ this.cause = error.cause;
914
+ Object.setPrototypeOf(this, InvalidServiceError.prototype);
915
+ }
916
+ }
917
+ export class UnauthorizedUserError extends WebrpcError {
918
+ constructor(error = {}) {
919
+ super(error);
920
+ this.name = error.name || 'UnauthorizedUser';
921
+ this.code = typeof error.code === 'number' ? error.code : 1105;
922
+ this.message = error.message || `Unauthorized user`;
923
+ this.status = typeof error.status === 'number' ? error.status : 403;
924
+ if (error.cause !== undefined)
925
+ this.cause = error.cause;
926
+ Object.setPrototypeOf(this, UnauthorizedUserError.prototype);
927
+ }
928
+ }
929
+ export class QuotaExceededError extends WebrpcError {
930
+ constructor(error = {}) {
931
+ super(error);
932
+ this.name = error.name || 'QuotaExceeded';
933
+ this.code = typeof error.code === 'number' ? error.code : 1200;
934
+ this.message = error.message || `Quota request exceeded`;
935
+ this.status = typeof error.status === 'number' ? error.status : 429;
936
+ if (error.cause !== undefined)
937
+ this.cause = error.cause;
938
+ Object.setPrototypeOf(this, QuotaExceededError.prototype);
939
+ }
940
+ }
941
+ export class QuotaRateLimitError extends WebrpcError {
942
+ constructor(error = {}) {
943
+ super(error);
944
+ this.name = error.name || 'QuotaRateLimit';
945
+ this.code = typeof error.code === 'number' ? error.code : 1201;
946
+ this.message = error.message || `Quota rate limit exceeded`;
947
+ this.status = typeof error.status === 'number' ? error.status : 429;
948
+ if (error.cause !== undefined)
949
+ this.cause = error.cause;
950
+ Object.setPrototypeOf(this, QuotaRateLimitError.prototype);
951
+ }
952
+ }
953
+ export class NoDefaultKeyError extends WebrpcError {
954
+ constructor(error = {}) {
955
+ super(error);
956
+ this.name = error.name || 'NoDefaultKey';
957
+ this.code = typeof error.code === 'number' ? error.code : 1300;
958
+ this.message = error.message || `No default access key found`;
959
+ this.status = typeof error.status === 'number' ? error.status : 403;
960
+ if (error.cause !== undefined)
961
+ this.cause = error.cause;
962
+ Object.setPrototypeOf(this, NoDefaultKeyError.prototype);
963
+ }
964
+ }
965
+ export class MaxAccessKeysError extends WebrpcError {
966
+ constructor(error = {}) {
967
+ super(error);
968
+ this.name = error.name || 'MaxAccessKeys';
969
+ this.code = typeof error.code === 'number' ? error.code : 1301;
970
+ this.message = error.message || `Access keys limit reached`;
971
+ this.status = typeof error.status === 'number' ? error.status : 403;
972
+ if (error.cause !== undefined)
973
+ this.cause = error.cause;
974
+ Object.setPrototypeOf(this, MaxAccessKeysError.prototype);
975
+ }
976
+ }
977
+ export class AtLeastOneKeyError extends WebrpcError {
978
+ constructor(error = {}) {
979
+ super(error);
980
+ this.name = error.name || 'AtLeastOneKey';
981
+ this.code = typeof error.code === 'number' ? error.code : 1302;
982
+ this.message = error.message || `You need at least one Access Key`;
983
+ this.status = typeof error.status === 'number' ? error.status : 403;
984
+ if (error.cause !== undefined)
985
+ this.cause = error.cause;
986
+ Object.setPrototypeOf(this, AtLeastOneKeyError.prototype);
987
+ }
988
+ }
989
+ export class TimeoutError extends WebrpcError {
990
+ constructor(error = {}) {
991
+ super(error);
992
+ this.name = error.name || 'Timeout';
993
+ this.code = typeof error.code === 'number' ? error.code : 1900;
994
+ this.message = error.message || `Request timed out`;
995
+ this.status = typeof error.status === 'number' ? error.status : 408;
996
+ if (error.cause !== undefined)
997
+ this.cause = error.cause;
998
+ Object.setPrototypeOf(this, TimeoutError.prototype);
999
+ }
1000
+ }
1001
+ export class InvalidArgumentError extends WebrpcError {
1002
+ constructor(error = {}) {
1003
+ super(error);
1004
+ this.name = error.name || 'InvalidArgument';
1005
+ this.code = typeof error.code === 'number' ? error.code : 2001;
1006
+ this.message = error.message || `Invalid argument`;
1007
+ this.status = typeof error.status === 'number' ? error.status : 400;
1008
+ if (error.cause !== undefined)
1009
+ this.cause = error.cause;
1010
+ Object.setPrototypeOf(this, InvalidArgumentError.prototype);
1011
+ }
1012
+ }
1013
+ export class UnavailableError extends WebrpcError {
1014
+ constructor(error = {}) {
1015
+ super(error);
1016
+ this.name = error.name || 'Unavailable';
1017
+ this.code = typeof error.code === 'number' ? error.code : 2002;
1018
+ this.message = error.message || `Unavailable resource`;
1019
+ this.status = typeof error.status === 'number' ? error.status : 400;
1020
+ if (error.cause !== undefined)
1021
+ this.cause = error.cause;
1022
+ Object.setPrototypeOf(this, UnavailableError.prototype);
1023
+ }
1024
+ }
1025
+ export class QueryFailedError extends WebrpcError {
1026
+ constructor(error = {}) {
1027
+ super(error);
1028
+ this.name = error.name || 'QueryFailed';
1029
+ this.code = typeof error.code === 'number' ? error.code : 2003;
1030
+ this.message = error.message || `Query failed`;
1031
+ this.status = typeof error.status === 'number' ? error.status : 400;
1032
+ if (error.cause !== undefined)
1033
+ this.cause = error.cause;
1034
+ Object.setPrototypeOf(this, QueryFailedError.prototype);
1035
+ }
1036
+ }
1037
+ export class NotFoundError extends WebrpcError {
1038
+ constructor(error = {}) {
1039
+ super(error);
1040
+ this.name = error.name || 'NotFound';
1041
+ this.code = typeof error.code === 'number' ? error.code : 3000;
1042
+ this.message = error.message || `Resource not found`;
1043
+ this.status = typeof error.status === 'number' ? error.status : 400;
1044
+ if (error.cause !== undefined)
1045
+ this.cause = error.cause;
1046
+ Object.setPrototypeOf(this, NotFoundError.prototype);
1047
+ }
1048
+ }
1049
+ export class InsufficientFeeError extends WebrpcError {
1050
+ constructor(error = {}) {
1051
+ super(error);
1052
+ this.name = error.name || 'InsufficientFee';
1053
+ this.code = typeof error.code === 'number' ? error.code : 3004;
1054
+ this.message = error.message || `Insufficient fee`;
1055
+ this.status = typeof error.status === 'number' ? error.status : 402;
1056
+ if (error.cause !== undefined)
1057
+ this.cause = error.cause;
1058
+ Object.setPrototypeOf(this, InsufficientFeeError.prototype);
1059
+ }
1060
+ }
1061
+ export class NotEnoughBalanceError extends WebrpcError {
1062
+ constructor(error = {}) {
1063
+ super(error);
1064
+ this.name = error.name || 'NotEnoughBalance';
1065
+ this.code = typeof error.code === 'number' ? error.code : 3005;
1066
+ this.message = error.message || `Not enough balance`;
1067
+ this.status = typeof error.status === 'number' ? error.status : 402;
1068
+ if (error.cause !== undefined)
1069
+ this.cause = error.cause;
1070
+ Object.setPrototypeOf(this, NotEnoughBalanceError.prototype);
1071
+ }
1072
+ }
1073
+ export class SimulationFailedError extends WebrpcError {
1074
+ constructor(error = {}) {
1075
+ super(error);
1076
+ this.name = error.name || 'SimulationFailed';
1077
+ this.code = typeof error.code === 'number' ? error.code : 3006;
1078
+ this.message = error.message || `Simulation failed`;
1079
+ this.status = typeof error.status === 'number' ? error.status : 400;
1080
+ if (error.cause !== undefined)
1081
+ this.cause = error.cause;
1082
+ Object.setPrototypeOf(this, SimulationFailedError.prototype);
1083
+ }
1084
+ }
1085
+ export var errors;
1086
+ (function (errors) {
1087
+ errors["WebrpcEndpoint"] = "WebrpcEndpoint";
1088
+ errors["WebrpcRequestFailed"] = "WebrpcRequestFailed";
1089
+ errors["WebrpcBadRoute"] = "WebrpcBadRoute";
1090
+ errors["WebrpcBadMethod"] = "WebrpcBadMethod";
1091
+ errors["WebrpcBadRequest"] = "WebrpcBadRequest";
1092
+ errors["WebrpcBadResponse"] = "WebrpcBadResponse";
1093
+ errors["WebrpcServerPanic"] = "WebrpcServerPanic";
1094
+ errors["WebrpcInternalError"] = "WebrpcInternalError";
1095
+ errors["WebrpcClientAborted"] = "WebrpcClientAborted";
1096
+ errors["WebrpcStreamLost"] = "WebrpcStreamLost";
1097
+ errors["WebrpcStreamFinished"] = "WebrpcStreamFinished";
1098
+ errors["Unauthorized"] = "Unauthorized";
1099
+ errors["PermissionDenied"] = "PermissionDenied";
1100
+ errors["SessionExpired"] = "SessionExpired";
1101
+ errors["MethodNotFound"] = "MethodNotFound";
1102
+ errors["RequestConflict"] = "RequestConflict";
1103
+ errors["Aborted"] = "Aborted";
1104
+ errors["Geoblocked"] = "Geoblocked";
1105
+ errors["RateLimited"] = "RateLimited";
1106
+ errors["ProjectNotFound"] = "ProjectNotFound";
1107
+ errors["AccessKeyNotFound"] = "AccessKeyNotFound";
1108
+ errors["AccessKeyMismatch"] = "AccessKeyMismatch";
1109
+ errors["InvalidOrigin"] = "InvalidOrigin";
1110
+ errors["InvalidService"] = "InvalidService";
1111
+ errors["UnauthorizedUser"] = "UnauthorizedUser";
1112
+ errors["QuotaExceeded"] = "QuotaExceeded";
1113
+ errors["QuotaRateLimit"] = "QuotaRateLimit";
1114
+ errors["NoDefaultKey"] = "NoDefaultKey";
1115
+ errors["MaxAccessKeys"] = "MaxAccessKeys";
1116
+ errors["AtLeastOneKey"] = "AtLeastOneKey";
1117
+ errors["Timeout"] = "Timeout";
1118
+ errors["InvalidArgument"] = "InvalidArgument";
1119
+ errors["Unavailable"] = "Unavailable";
1120
+ errors["QueryFailed"] = "QueryFailed";
1121
+ errors["NotFound"] = "NotFound";
1122
+ errors["InsufficientFee"] = "InsufficientFee";
1123
+ errors["NotEnoughBalance"] = "NotEnoughBalance";
1124
+ errors["SimulationFailed"] = "SimulationFailed";
1125
+ })(errors || (errors = {}));
1126
+ export var WebrpcErrorCodes;
1127
+ (function (WebrpcErrorCodes) {
1128
+ WebrpcErrorCodes[WebrpcErrorCodes["WebrpcEndpoint"] = 0] = "WebrpcEndpoint";
1129
+ WebrpcErrorCodes[WebrpcErrorCodes["WebrpcRequestFailed"] = -1] = "WebrpcRequestFailed";
1130
+ WebrpcErrorCodes[WebrpcErrorCodes["WebrpcBadRoute"] = -2] = "WebrpcBadRoute";
1131
+ WebrpcErrorCodes[WebrpcErrorCodes["WebrpcBadMethod"] = -3] = "WebrpcBadMethod";
1132
+ WebrpcErrorCodes[WebrpcErrorCodes["WebrpcBadRequest"] = -4] = "WebrpcBadRequest";
1133
+ WebrpcErrorCodes[WebrpcErrorCodes["WebrpcBadResponse"] = -5] = "WebrpcBadResponse";
1134
+ WebrpcErrorCodes[WebrpcErrorCodes["WebrpcServerPanic"] = -6] = "WebrpcServerPanic";
1135
+ WebrpcErrorCodes[WebrpcErrorCodes["WebrpcInternalError"] = -7] = "WebrpcInternalError";
1136
+ WebrpcErrorCodes[WebrpcErrorCodes["WebrpcClientAborted"] = -8] = "WebrpcClientAborted";
1137
+ WebrpcErrorCodes[WebrpcErrorCodes["WebrpcStreamLost"] = -9] = "WebrpcStreamLost";
1138
+ WebrpcErrorCodes[WebrpcErrorCodes["WebrpcStreamFinished"] = -10] = "WebrpcStreamFinished";
1139
+ WebrpcErrorCodes[WebrpcErrorCodes["Unauthorized"] = 1000] = "Unauthorized";
1140
+ WebrpcErrorCodes[WebrpcErrorCodes["PermissionDenied"] = 1001] = "PermissionDenied";
1141
+ WebrpcErrorCodes[WebrpcErrorCodes["SessionExpired"] = 1002] = "SessionExpired";
1142
+ WebrpcErrorCodes[WebrpcErrorCodes["MethodNotFound"] = 1003] = "MethodNotFound";
1143
+ WebrpcErrorCodes[WebrpcErrorCodes["RequestConflict"] = 1004] = "RequestConflict";
1144
+ WebrpcErrorCodes[WebrpcErrorCodes["Aborted"] = 1005] = "Aborted";
1145
+ WebrpcErrorCodes[WebrpcErrorCodes["Geoblocked"] = 1006] = "Geoblocked";
1146
+ WebrpcErrorCodes[WebrpcErrorCodes["RateLimited"] = 1007] = "RateLimited";
1147
+ WebrpcErrorCodes[WebrpcErrorCodes["ProjectNotFound"] = 1008] = "ProjectNotFound";
1148
+ WebrpcErrorCodes[WebrpcErrorCodes["AccessKeyNotFound"] = 1101] = "AccessKeyNotFound";
1149
+ WebrpcErrorCodes[WebrpcErrorCodes["AccessKeyMismatch"] = 1102] = "AccessKeyMismatch";
1150
+ WebrpcErrorCodes[WebrpcErrorCodes["InvalidOrigin"] = 1103] = "InvalidOrigin";
1151
+ WebrpcErrorCodes[WebrpcErrorCodes["InvalidService"] = 1104] = "InvalidService";
1152
+ WebrpcErrorCodes[WebrpcErrorCodes["UnauthorizedUser"] = 1105] = "UnauthorizedUser";
1153
+ WebrpcErrorCodes[WebrpcErrorCodes["QuotaExceeded"] = 1200] = "QuotaExceeded";
1154
+ WebrpcErrorCodes[WebrpcErrorCodes["QuotaRateLimit"] = 1201] = "QuotaRateLimit";
1155
+ WebrpcErrorCodes[WebrpcErrorCodes["NoDefaultKey"] = 1300] = "NoDefaultKey";
1156
+ WebrpcErrorCodes[WebrpcErrorCodes["MaxAccessKeys"] = 1301] = "MaxAccessKeys";
1157
+ WebrpcErrorCodes[WebrpcErrorCodes["AtLeastOneKey"] = 1302] = "AtLeastOneKey";
1158
+ WebrpcErrorCodes[WebrpcErrorCodes["Timeout"] = 1900] = "Timeout";
1159
+ WebrpcErrorCodes[WebrpcErrorCodes["InvalidArgument"] = 2001] = "InvalidArgument";
1160
+ WebrpcErrorCodes[WebrpcErrorCodes["Unavailable"] = 2002] = "Unavailable";
1161
+ WebrpcErrorCodes[WebrpcErrorCodes["QueryFailed"] = 2003] = "QueryFailed";
1162
+ WebrpcErrorCodes[WebrpcErrorCodes["NotFound"] = 3000] = "NotFound";
1163
+ WebrpcErrorCodes[WebrpcErrorCodes["InsufficientFee"] = 3004] = "InsufficientFee";
1164
+ WebrpcErrorCodes[WebrpcErrorCodes["NotEnoughBalance"] = 3005] = "NotEnoughBalance";
1165
+ WebrpcErrorCodes[WebrpcErrorCodes["SimulationFailed"] = 3006] = "SimulationFailed";
1166
+ })(WebrpcErrorCodes || (WebrpcErrorCodes = {}));
1167
+ export const webrpcErrorByCode = {
1168
+ [0]: WebrpcEndpointError,
1169
+ [-1]: WebrpcRequestFailedError,
1170
+ [-2]: WebrpcBadRouteError,
1171
+ [-3]: WebrpcBadMethodError,
1172
+ [-4]: WebrpcBadRequestError,
1173
+ [-5]: WebrpcBadResponseError,
1174
+ [-6]: WebrpcServerPanicError,
1175
+ [-7]: WebrpcInternalErrorError,
1176
+ [-8]: WebrpcClientAbortedError,
1177
+ [-9]: WebrpcStreamLostError,
1178
+ [-10]: WebrpcStreamFinishedError,
1179
+ [1000]: UnauthorizedError,
1180
+ [1001]: PermissionDeniedError,
1181
+ [1002]: SessionExpiredError,
1182
+ [1003]: MethodNotFoundError,
1183
+ [1004]: RequestConflictError,
1184
+ [1005]: AbortedError,
1185
+ [1006]: GeoblockedError,
1186
+ [1007]: RateLimitedError,
1187
+ [1008]: ProjectNotFoundError,
1188
+ [1101]: AccessKeyNotFoundError,
1189
+ [1102]: AccessKeyMismatchError,
1190
+ [1103]: InvalidOriginError,
1191
+ [1104]: InvalidServiceError,
1192
+ [1105]: UnauthorizedUserError,
1193
+ [1200]: QuotaExceededError,
1194
+ [1201]: QuotaRateLimitError,
1195
+ [1300]: NoDefaultKeyError,
1196
+ [1301]: MaxAccessKeysError,
1197
+ [1302]: AtLeastOneKeyError,
1198
+ [1900]: TimeoutError,
1199
+ [2001]: InvalidArgumentError,
1200
+ [2002]: UnavailableError,
1201
+ [2003]: QueryFailedError,
1202
+ [3000]: NotFoundError,
1203
+ [3004]: InsufficientFeeError,
1204
+ [3005]: NotEnoughBalanceError,
1205
+ [3006]: SimulationFailedError,
1206
+ };
1207
+ //
1208
+ // Webrpc
1209
+ //
1210
+ export const WebrpcHeader = 'Webrpc';
1211
+ export const WebrpcHeaderValue = 'webrpc@v0.30.2;gen-typescript@v0.22.2;sequence-relayer@v0.4.1';
1212
+ export function VersionFromHeader(headers) {
1213
+ const headerValue = headers.get(WebrpcHeader);
1214
+ if (!headerValue) {
1215
+ return {
1216
+ WebrpcGenVersion: '',
1217
+ codeGenName: '',
1218
+ codeGenVersion: '',
1219
+ schemaName: '',
1220
+ schemaVersion: '',
1221
+ };
1222
+ }
1223
+ return parseWebrpcGenVersions(headerValue);
1224
+ }
1225
+ function parseWebrpcGenVersions(header) {
1226
+ const versions = header.split(';');
1227
+ if (versions.length < 3) {
1228
+ return {
1229
+ WebrpcGenVersion: '',
1230
+ codeGenName: '',
1231
+ codeGenVersion: '',
1232
+ schemaName: '',
1233
+ schemaVersion: '',
1234
+ };
1235
+ }
1236
+ const [_, WebrpcGenVersion] = versions[0].split('@');
1237
+ const [codeGenName, codeGenVersion] = versions[1].split('@');
1238
+ const [schemaName, schemaVersion] = versions[2].split('@');
1239
+ return {
1240
+ WebrpcGenVersion: WebrpcGenVersion ?? '',
1241
+ codeGenName: codeGenName ?? '',
1242
+ codeGenVersion: codeGenVersion ?? '',
1243
+ schemaName: schemaName ?? '',
1244
+ schemaVersion: schemaVersion ?? '',
1245
+ };
1246
+ }