@airgap/icp 0.13.11-beta.1 → 0.13.11-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 (144) hide show
  1. package/index.d.ts +1 -0
  2. package/index.js +18 -0
  3. package/index.js.map +1 -0
  4. package/package.json +6 -9
  5. package/v1/block-explorer/ICPBlockExplorer.d.ts +9 -0
  6. package/v1/block-explorer/ICPBlockExplorer.js +74 -0
  7. package/v1/block-explorer/ICPBlockExplorer.js.map +1 -0
  8. package/v1/index.d.ts +14 -0
  9. package/v1/index.js +14 -0
  10. package/v1/index.js.map +1 -0
  11. package/v1/module/ICPModule.d.ts +14 -0
  12. package/v1/module/ICPModule.js +119 -0
  13. package/v1/module/ICPModule.js.map +1 -0
  14. package/v1/module.d.ts +3 -0
  15. package/v1/module.js +24 -0
  16. package/v1/module.js.map +1 -0
  17. package/v1/protocol/ICPImplementation.d.ts +34 -0
  18. package/v1/protocol/ICPImplementation.js +376 -0
  19. package/v1/protocol/ICPImplementation.js.map +1 -0
  20. package/v1/protocol/ICPProtocol.d.ts +45 -0
  21. package/v1/protocol/ICPProtocol.js +423 -0
  22. package/v1/protocol/ICPProtocol.js.map +1 -0
  23. package/v1/protocol/icrc/CkBTCProtocol.d.ts +13 -0
  24. package/v1/protocol/icrc/CkBTCProtocol.js +328 -0
  25. package/v1/protocol/icrc/CkBTCProtocol.js.map +1 -0
  26. package/v1/protocol/icrc/ICRC1Protocol.d.ts +95 -0
  27. package/v1/protocol/icrc/ICRC1Protocol.js +717 -0
  28. package/v1/protocol/icrc/ICRC1Protocol.js.map +1 -0
  29. package/v1/serializer/v3/schemas/converter/transaction-converter.d.ts +7 -0
  30. package/v1/serializer/v3/schemas/converter/transaction-converter.js +21 -0
  31. package/v1/serializer/v3/schemas/converter/transaction-converter.js.map +1 -0
  32. package/v1/serializer/v3/schemas/definitions/transaction-sign-request-icp.d.ts +4 -0
  33. package/v1/serializer/v3/schemas/definitions/transaction-sign-request-icp.js +3 -0
  34. package/v1/serializer/v3/schemas/definitions/transaction-sign-request-icp.js.map +1 -0
  35. package/v1/serializer/v3/schemas/definitions/transaction-sign-response-icp.d.ts +3 -0
  36. package/v1/serializer/v3/schemas/definitions/transaction-sign-response-icp.js +3 -0
  37. package/v1/serializer/v3/schemas/definitions/transaction-sign-response-icp.js.map +1 -0
  38. package/v1/serializer/v3/schemas/generated/transaction-sign-request-icp.json +32 -0
  39. package/v1/serializer/v3/schemas/generated/transaction-sign-response-icp.json +19 -0
  40. package/v1/serializer/v3/serializer-companion.d.ts +14 -0
  41. package/v1/serializer/v3/serializer-companion.js +190 -0
  42. package/v1/serializer/v3/serializer-companion.js.map +1 -0
  43. package/v1/serializer/v3/validators/transaction-validator.d.ts +10 -0
  44. package/v1/serializer/v3/validators/transaction-validator.js +100 -0
  45. package/v1/serializer/v3/validators/transaction-validator.js.map +1 -0
  46. package/v1/serializer/v3/validators/validators.d.ts +5 -0
  47. package/v1/serializer/v3/validators/validators.js +106 -0
  48. package/v1/serializer/v3/validators/validators.js.map +1 -0
  49. package/v1/types/ckbtc/metadata.d.ts +4 -0
  50. package/v1/types/ckbtc/metadata.js +3 -0
  51. package/v1/types/ckbtc/metadata.js.map +1 -0
  52. package/v1/types/crypto.d.ts +2 -0
  53. package/v1/types/crypto.js +3 -0
  54. package/v1/types/crypto.js.map +1 -0
  55. package/v1/types/governance.d.ts +580 -0
  56. package/v1/types/governance.js +796 -0
  57. package/v1/types/governance.js.map +1 -0
  58. package/v1/types/icrc/account.d.ts +4 -0
  59. package/v1/types/icrc/account.js +3 -0
  60. package/v1/types/icrc/account.js.map +1 -0
  61. package/v1/types/icrc/ledger.d.ts +15 -0
  62. package/v1/types/icrc/ledger.js +92 -0
  63. package/v1/types/icrc/ledger.js.map +1 -0
  64. package/v1/types/icrc/metadata.d.ts +6 -0
  65. package/v1/types/icrc/metadata.js +3 -0
  66. package/v1/types/icrc/metadata.js.map +1 -0
  67. package/v1/types/icrc/transfer.d.ts +9 -0
  68. package/v1/types/icrc/transfer.js +3 -0
  69. package/v1/types/icrc/transfer.js.map +1 -0
  70. package/v1/types/ledger.d.ts +142 -0
  71. package/v1/types/ledger.js +145 -0
  72. package/v1/types/ledger.js.map +1 -0
  73. package/v1/types/management_idl.d.ts +7 -0
  74. package/v1/types/management_idl.js +72 -0
  75. package/v1/types/management_idl.js.map +1 -0
  76. package/v1/types/protocol.d.ts +37 -0
  77. package/v1/types/protocol.js +3 -0
  78. package/v1/types/protocol.js.map +1 -0
  79. package/v1/types/transaction.d.ts +11 -0
  80. package/v1/types/transaction.js +3 -0
  81. package/v1/types/transaction.js.map +1 -0
  82. package/v1/utils/account.d.ts +24 -0
  83. package/v1/utils/account.js +112 -0
  84. package/v1/utils/account.js.map +1 -0
  85. package/v1/utils/actor.d.ts +246 -0
  86. package/v1/utils/actor.js +458 -0
  87. package/v1/utils/actor.js.map +1 -0
  88. package/v1/utils/agent.d.ts +156 -0
  89. package/v1/utils/agent.js +16 -0
  90. package/v1/utils/agent.js.map +1 -0
  91. package/v1/utils/auth.d.ts +110 -0
  92. package/v1/utils/auth.js +261 -0
  93. package/v1/utils/auth.js.map +1 -0
  94. package/v1/utils/bls.d.ts +38 -0
  95. package/v1/utils/bls.js +204 -0
  96. package/v1/utils/bls.js.map +1 -0
  97. package/v1/utils/buffer.d.ts +70 -0
  98. package/v1/utils/buffer.js +216 -0
  99. package/v1/utils/buffer.js.map +1 -0
  100. package/v1/utils/cbor.d.ts +9 -0
  101. package/v1/utils/cbor.js +178 -0
  102. package/v1/utils/cbor.js.map +1 -0
  103. package/v1/utils/certificate.d.ts +74 -0
  104. package/v1/utils/certificate.js +396 -0
  105. package/v1/utils/certificate.js.map +1 -0
  106. package/v1/utils/convert.d.ts +10 -0
  107. package/v1/utils/convert.js +88 -0
  108. package/v1/utils/convert.js.map +1 -0
  109. package/v1/utils/crypto.d.ts +0 -0
  110. package/v1/utils/crypto.js +104 -0
  111. package/v1/utils/crypto.js.map +1 -0
  112. package/v1/utils/der.d.ts +35 -0
  113. package/v1/utils/der.js +176 -0
  114. package/v1/utils/der.js.map +1 -0
  115. package/v1/utils/errors.d.ts +7 -0
  116. package/v1/utils/errors.js +38 -0
  117. package/v1/utils/errors.js.map +1 -0
  118. package/v1/utils/hdkey.d.ts +13 -0
  119. package/v1/utils/hdkey.js +265 -0
  120. package/v1/utils/hdkey.js.map +1 -0
  121. package/v1/utils/http.d.ts +284 -0
  122. package/v1/utils/http.js +614 -0
  123. package/v1/utils/http.js.map +1 -0
  124. package/v1/utils/icrc1.d.ts +20 -0
  125. package/v1/utils/icrc1.js +171 -0
  126. package/v1/utils/icrc1.js.map +1 -0
  127. package/v1/utils/idl.d.ts +515 -0
  128. package/v1/utils/idl.js +2103 -0
  129. package/v1/utils/idl.js.map +1 -0
  130. package/v1/utils/leb128.d.ts +63 -0
  131. package/v1/utils/leb128.js +224 -0
  132. package/v1/utils/leb128.js.map +1 -0
  133. package/v1/utils/polling.d.ts +59 -0
  134. package/v1/utils/polling.js +325 -0
  135. package/v1/utils/polling.js.map +1 -0
  136. package/v1/utils/principal.d.ts +58 -0
  137. package/v1/utils/principal.js +543 -0
  138. package/v1/utils/principal.js.map +1 -0
  139. package/v1/utils/secp256k1.d.ts +79 -0
  140. package/v1/utils/secp256k1.js +278 -0
  141. package/v1/utils/secp256k1.js.map +1 -0
  142. package/v1/utils/transaction.d.ts +3 -0
  143. package/v1/utils/transaction.js +56 -0
  144. package/v1/utils/transaction.js.map +1 -0
@@ -0,0 +1,2103 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __values = (this && this.__values) || function(o) {
18
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
19
+ if (m) return m.call(o);
20
+ if (o && typeof o.length === "number") return {
21
+ next: function () {
22
+ if (o && i >= o.length) o = void 0;
23
+ return { value: o && o[i++], done: !o };
24
+ }
25
+ };
26
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
27
+ };
28
+ var __read = (this && this.__read) || function (o, n) {
29
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
30
+ if (!m) return o;
31
+ var i = m.call(o), r, ar = [], e;
32
+ try {
33
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
34
+ }
35
+ catch (error) { e = { error: error }; }
36
+ finally {
37
+ try {
38
+ if (r && !r.done && (m = i["return"])) m.call(i);
39
+ }
40
+ finally { if (e) throw e.error; }
41
+ }
42
+ return ar;
43
+ };
44
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
45
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
46
+ if (ar || !(i in from)) {
47
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
48
+ ar[i] = from[i];
49
+ }
50
+ }
51
+ return to.concat(ar || Array.prototype.slice.call(from));
52
+ };
53
+ Object.defineProperty(exports, "__esModule", { value: true });
54
+ exports.Vec = exports.Tuple = exports.Principal = exports.Nat64 = exports.Nat32 = exports.Nat16 = exports.Nat8 = exports.Int64 = exports.Int32 = exports.Int16 = exports.Int8 = exports.Float64 = exports.Float32 = exports.Nat = exports.Int = exports.Text = exports.Null = exports.Bool = exports.Unknown = exports.Reserved = exports.Empty = exports.decode = exports.encode = exports.ServiceClass = exports.FuncClass = exports.PrincipalClass = exports.RecClass = exports.VariantClass = exports.TupleClass = exports.RecordClass = exports.OptClass = exports.VecClass = exports.FixedNatClass = exports.FixedIntClass = exports.FloatClass = exports.NatClass = exports.IntClass = exports.TextClass = exports.ReservedClass = exports.NullClass = exports.BoolClass = exports.UnknownClass = exports.EmptyClass = exports.ConstructType = exports.PrimitiveType = exports.Type = exports.Visitor = exports.idlLabelToId = exports.iexp2 = exports.ilog2 = void 0;
55
+ exports.Service = exports.Func = exports.Rec = exports.Variant = exports.Record = exports.Opt = void 0;
56
+ var buffer_1 = require("./buffer");
57
+ var leb128_1 = require("./leb128");
58
+ var buffer_2 = require("./buffer");
59
+ var principal_1 = require("./principal");
60
+ /**
61
+ * Equivalent to `Math.log2(n)` with support for `BigInt` values
62
+ *
63
+ * @param n bigint or integer
64
+ * @returns integer
65
+ */
66
+ function ilog2(n) {
67
+ var nBig = BigInt(n);
68
+ if (n <= 0) {
69
+ throw new RangeError('Input must be positive');
70
+ }
71
+ return nBig.toString(2).length - 1;
72
+ }
73
+ exports.ilog2 = ilog2;
74
+ /**
75
+ * Equivalent to `2 ** n` with support for `BigInt` values
76
+ * (necessary for browser preprocessors which replace the `**` operator with `Math.pow`)
77
+ *
78
+ * @param n bigint or integer
79
+ * @returns bigint
80
+ */
81
+ function iexp2(n) {
82
+ var nBig = BigInt(n);
83
+ if (n < 0) {
84
+ throw new RangeError('Input must be non-negative');
85
+ }
86
+ return BigInt(1) << nBig;
87
+ }
88
+ exports.iexp2 = iexp2;
89
+ function idlHash(s) {
90
+ var e_1, _a;
91
+ var utf8encoder = new TextEncoder();
92
+ var array = utf8encoder.encode(s);
93
+ var h = 0;
94
+ try {
95
+ for (var array_1 = __values(array), array_1_1 = array_1.next(); !array_1_1.done; array_1_1 = array_1.next()) {
96
+ var c = array_1_1.value;
97
+ h = (h * 223 + c) % Math.pow(2, 32);
98
+ }
99
+ }
100
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
101
+ finally {
102
+ try {
103
+ if (array_1_1 && !array_1_1.done && (_a = array_1.return)) _a.call(array_1);
104
+ }
105
+ finally { if (e_1) throw e_1.error; }
106
+ }
107
+ return h;
108
+ }
109
+ /**
110
+ *
111
+ * @param label string
112
+ * @returns number representing hashed label
113
+ */
114
+ function idlLabelToId(label) {
115
+ if (/^_\d+_$/.test(label) || /^_0x[0-9a-fA-F]+_$/.test(label)) {
116
+ var num = +label.slice(1, -1);
117
+ if (Number.isSafeInteger(num) && num >= 0 && num < Math.pow(2, 32)) {
118
+ return num;
119
+ }
120
+ }
121
+ return idlHash(label);
122
+ }
123
+ exports.idlLabelToId = idlLabelToId;
124
+ var magicNumber = 'DIDL';
125
+ var toReadableString_max = 400; // will not display arguments after 400chars. Makes sure 2mb blobs don't get inside the error
126
+ function zipWith(xs, ys, f) {
127
+ return xs.map(function (x, i) { return f(x, ys[i]); });
128
+ }
129
+ /**
130
+ * An IDL Type Table, which precedes the data in the stream.
131
+ */
132
+ var TypeTable = /** @class */ (function () {
133
+ function TypeTable() {
134
+ // List of types. Needs to be an array as the index needs to be stable.
135
+ this._typs = [];
136
+ this._idx = new Map();
137
+ }
138
+ TypeTable.prototype.has = function (obj) {
139
+ return this._idx.has(obj.name);
140
+ };
141
+ TypeTable.prototype.add = function (type, buf) {
142
+ var idx = this._typs.length;
143
+ this._idx.set(type.name, idx);
144
+ this._typs.push(buf);
145
+ };
146
+ TypeTable.prototype.merge = function (obj, knot) {
147
+ var idx = this._idx.get(obj.name);
148
+ var knotIdx = this._idx.get(knot);
149
+ if (idx === undefined) {
150
+ throw new Error('Missing type index for ' + obj);
151
+ }
152
+ if (knotIdx === undefined) {
153
+ throw new Error('Missing type index for ' + knot);
154
+ }
155
+ this._typs[idx] = this._typs[knotIdx];
156
+ // Delete the type.
157
+ this._typs.splice(knotIdx, 1);
158
+ this._idx.delete(knot);
159
+ };
160
+ TypeTable.prototype.encode = function () {
161
+ var len = (0, leb128_1.lebEncode)(this._typs.length);
162
+ var buf = buffer_1.concat.apply(void 0, __spreadArray([], __read(this._typs), false));
163
+ return (0, buffer_1.concat)(len, buf);
164
+ };
165
+ TypeTable.prototype.indexOf = function (typeName) {
166
+ if (!this._idx.has(typeName)) {
167
+ throw new Error('Missing type index for ' + typeName);
168
+ }
169
+ return (0, leb128_1.slebEncode)(this._idx.get(typeName) || 0);
170
+ };
171
+ return TypeTable;
172
+ }());
173
+ var Visitor = /** @class */ (function () {
174
+ function Visitor() {
175
+ }
176
+ Visitor.prototype.visitType = function (t, data) {
177
+ throw new Error('Not implemented');
178
+ };
179
+ Visitor.prototype.visitPrimitive = function (t, data) {
180
+ return this.visitType(t, data);
181
+ };
182
+ Visitor.prototype.visitEmpty = function (t, data) {
183
+ return this.visitPrimitive(t, data);
184
+ };
185
+ Visitor.prototype.visitBool = function (t, data) {
186
+ return this.visitPrimitive(t, data);
187
+ };
188
+ Visitor.prototype.visitNull = function (t, data) {
189
+ return this.visitPrimitive(t, data);
190
+ };
191
+ Visitor.prototype.visitReserved = function (t, data) {
192
+ return this.visitPrimitive(t, data);
193
+ };
194
+ Visitor.prototype.visitText = function (t, data) {
195
+ return this.visitPrimitive(t, data);
196
+ };
197
+ Visitor.prototype.visitNumber = function (t, data) {
198
+ return this.visitPrimitive(t, data);
199
+ };
200
+ Visitor.prototype.visitInt = function (t, data) {
201
+ return this.visitNumber(t, data);
202
+ };
203
+ Visitor.prototype.visitNat = function (t, data) {
204
+ return this.visitNumber(t, data);
205
+ };
206
+ Visitor.prototype.visitFloat = function (t, data) {
207
+ return this.visitPrimitive(t, data);
208
+ };
209
+ Visitor.prototype.visitFixedInt = function (t, data) {
210
+ return this.visitNumber(t, data);
211
+ };
212
+ Visitor.prototype.visitFixedNat = function (t, data) {
213
+ return this.visitNumber(t, data);
214
+ };
215
+ Visitor.prototype.visitPrincipal = function (t, data) {
216
+ return this.visitPrimitive(t, data);
217
+ };
218
+ Visitor.prototype.visitConstruct = function (t, data) {
219
+ return this.visitType(t, data);
220
+ };
221
+ Visitor.prototype.visitVec = function (t, ty, data) {
222
+ return this.visitConstruct(t, data);
223
+ };
224
+ Visitor.prototype.visitOpt = function (t, ty, data) {
225
+ return this.visitConstruct(t, data);
226
+ };
227
+ Visitor.prototype.visitRecord = function (t, fields, data) {
228
+ return this.visitConstruct(t, data);
229
+ };
230
+ Visitor.prototype.visitTuple = function (t, components, data) {
231
+ var fields = components.map(function (ty, i) { return ["_".concat(i, "_"), ty]; });
232
+ return this.visitRecord(t, fields, data);
233
+ };
234
+ Visitor.prototype.visitVariant = function (t, fields, data) {
235
+ return this.visitConstruct(t, data);
236
+ };
237
+ Visitor.prototype.visitRec = function (t, ty, data) {
238
+ return this.visitConstruct(ty, data);
239
+ };
240
+ Visitor.prototype.visitFunc = function (t, data) {
241
+ return this.visitConstruct(t, data);
242
+ };
243
+ Visitor.prototype.visitService = function (t, data) {
244
+ return this.visitConstruct(t, data);
245
+ };
246
+ return Visitor;
247
+ }());
248
+ exports.Visitor = Visitor;
249
+ /**
250
+ * Represents an IDL type.
251
+ */
252
+ var Type = /** @class */ (function () {
253
+ function Type() {
254
+ }
255
+ /* Display type name */
256
+ Type.prototype.display = function () {
257
+ return this.name;
258
+ };
259
+ Type.prototype.valueToString = function (x) {
260
+ return toReadableString(x);
261
+ };
262
+ /* Implement `T` in the IDL spec, only needed for non-primitive types */
263
+ Type.prototype.buildTypeTable = function (typeTable) {
264
+ if (!typeTable.has(this)) {
265
+ this._buildTypeTableImpl(typeTable);
266
+ }
267
+ };
268
+ return Type;
269
+ }());
270
+ exports.Type = Type;
271
+ var PrimitiveType = /** @class */ (function (_super) {
272
+ __extends(PrimitiveType, _super);
273
+ function PrimitiveType() {
274
+ return _super !== null && _super.apply(this, arguments) || this;
275
+ }
276
+ PrimitiveType.prototype.checkType = function (t) {
277
+ if (this.name !== t.name) {
278
+ throw new Error("type mismatch: type on the wire ".concat(t.name, ", expect type ").concat(this.name));
279
+ }
280
+ return t;
281
+ };
282
+ PrimitiveType.prototype._buildTypeTableImpl = function (typeTable) {
283
+ // No type table encoding for Primitive types.
284
+ return;
285
+ };
286
+ return PrimitiveType;
287
+ }(Type));
288
+ exports.PrimitiveType = PrimitiveType;
289
+ var ConstructType = /** @class */ (function (_super) {
290
+ __extends(ConstructType, _super);
291
+ function ConstructType() {
292
+ return _super !== null && _super.apply(this, arguments) || this;
293
+ }
294
+ ConstructType.prototype.checkType = function (t) {
295
+ if (t instanceof RecClass) {
296
+ var ty = t.getType();
297
+ if (typeof ty === 'undefined') {
298
+ throw new Error('type mismatch with uninitialized type');
299
+ }
300
+ return ty;
301
+ }
302
+ throw new Error("type mismatch: type on the wire ".concat(t.name, ", expect type ").concat(this.name));
303
+ };
304
+ ConstructType.prototype.encodeType = function (typeTable) {
305
+ return typeTable.indexOf(this.name);
306
+ };
307
+ return ConstructType;
308
+ }(Type));
309
+ exports.ConstructType = ConstructType;
310
+ /**
311
+ * Represents an IDL Empty, a type which has no inhabitants.
312
+ * Since no values exist for this type, it cannot be serialised or deserialised.
313
+ * Result types like `Result<Text, Empty>` should always succeed.
314
+ */
315
+ var EmptyClass = /** @class */ (function (_super) {
316
+ __extends(EmptyClass, _super);
317
+ function EmptyClass() {
318
+ return _super !== null && _super.apply(this, arguments) || this;
319
+ }
320
+ EmptyClass.prototype.accept = function (v, d) {
321
+ return v.visitEmpty(this, d);
322
+ };
323
+ EmptyClass.prototype.covariant = function (x) {
324
+ throw new Error("Invalid ".concat(this.display(), " argument: ").concat(toReadableString(x)));
325
+ };
326
+ EmptyClass.prototype.encodeValue = function () {
327
+ throw new Error('Empty cannot appear as a function argument');
328
+ };
329
+ EmptyClass.prototype.valueToString = function () {
330
+ throw new Error('Empty cannot appear as a value');
331
+ };
332
+ EmptyClass.prototype.encodeType = function () {
333
+ return (0, leb128_1.slebEncode)(-17 /* IDLTypeIds.Empty */);
334
+ };
335
+ EmptyClass.prototype.decodeValue = function () {
336
+ throw new Error('Empty cannot appear as an output');
337
+ };
338
+ Object.defineProperty(EmptyClass.prototype, "name", {
339
+ get: function () {
340
+ return 'empty';
341
+ },
342
+ enumerable: false,
343
+ configurable: true
344
+ });
345
+ return EmptyClass;
346
+ }(PrimitiveType));
347
+ exports.EmptyClass = EmptyClass;
348
+ /**
349
+ * Represents an IDL Unknown, a placeholder type for deserialization only.
350
+ * When decoding a value as Unknown, all fields will be retained but the names are only available in
351
+ * hashed form.
352
+ * A deserialized unknown will offer it's actual type by calling the `type()` function.
353
+ * Unknown cannot be serialized and attempting to do so will throw an error.
354
+ */
355
+ var UnknownClass = /** @class */ (function (_super) {
356
+ __extends(UnknownClass, _super);
357
+ function UnknownClass() {
358
+ return _super !== null && _super.apply(this, arguments) || this;
359
+ }
360
+ UnknownClass.prototype.checkType = function (t) {
361
+ throw new Error('Method not implemented for unknown.');
362
+ };
363
+ UnknownClass.prototype.accept = function (v, d) {
364
+ throw v.visitType(this, d);
365
+ };
366
+ UnknownClass.prototype.covariant = function (x) {
367
+ throw new Error("Invalid ".concat(this.display(), " argument: ").concat(toReadableString(x)));
368
+ };
369
+ UnknownClass.prototype.encodeValue = function () {
370
+ throw new Error('Unknown cannot appear as a function argument');
371
+ };
372
+ UnknownClass.prototype.valueToString = function () {
373
+ throw new Error('Unknown cannot appear as a value');
374
+ };
375
+ UnknownClass.prototype.encodeType = function () {
376
+ throw new Error('Unknown cannot be serialized');
377
+ };
378
+ UnknownClass.prototype.decodeValue = function (b, t) {
379
+ var decodedValue = t.decodeValue(b, t);
380
+ if (Object(decodedValue) !== decodedValue) {
381
+ // decodedValue is primitive. Box it, otherwise we cannot add the type() function.
382
+ // The type() function is important for primitives because otherwise we cannot tell apart the
383
+ // different number types.
384
+ decodedValue = Object(decodedValue);
385
+ }
386
+ var typeFunc;
387
+ if (t instanceof RecClass) {
388
+ typeFunc = function () { return t.getType(); };
389
+ }
390
+ else {
391
+ typeFunc = function () { return t; };
392
+ }
393
+ // Do not use 'decodedValue.type = typeFunc' because this would lead to an enumerable property
394
+ // 'type' which means it would be serialized if the value would be candid encoded again.
395
+ // This in turn leads to problems if the decoded value is a variant because these values are
396
+ // only allowed to have a single property.
397
+ Object.defineProperty(decodedValue, 'type', {
398
+ value: typeFunc,
399
+ writable: true,
400
+ enumerable: false,
401
+ configurable: true
402
+ });
403
+ return decodedValue;
404
+ };
405
+ UnknownClass.prototype._buildTypeTableImpl = function () {
406
+ throw new Error('Unknown cannot be serialized');
407
+ };
408
+ Object.defineProperty(UnknownClass.prototype, "name", {
409
+ get: function () {
410
+ return 'Unknown';
411
+ },
412
+ enumerable: false,
413
+ configurable: true
414
+ });
415
+ return UnknownClass;
416
+ }(Type));
417
+ exports.UnknownClass = UnknownClass;
418
+ /**
419
+ * Represents an IDL Bool
420
+ */
421
+ var BoolClass = /** @class */ (function (_super) {
422
+ __extends(BoolClass, _super);
423
+ function BoolClass() {
424
+ return _super !== null && _super.apply(this, arguments) || this;
425
+ }
426
+ BoolClass.prototype.accept = function (v, d) {
427
+ return v.visitBool(this, d);
428
+ };
429
+ BoolClass.prototype.covariant = function (x) {
430
+ if (typeof x === 'boolean')
431
+ return true;
432
+ throw new Error("Invalid ".concat(this.display(), " argument: ").concat(toReadableString(x)));
433
+ };
434
+ BoolClass.prototype.encodeValue = function (x) {
435
+ return new Uint8Array([x ? 1 : 0]);
436
+ };
437
+ BoolClass.prototype.encodeType = function () {
438
+ return (0, leb128_1.slebEncode)(-2 /* IDLTypeIds.Bool */);
439
+ };
440
+ BoolClass.prototype.decodeValue = function (b, t) {
441
+ this.checkType(t);
442
+ switch ((0, leb128_1.safeReadUint8)(b)) {
443
+ case 0:
444
+ return false;
445
+ case 1:
446
+ return true;
447
+ default:
448
+ throw new Error('Boolean value out of range');
449
+ }
450
+ };
451
+ Object.defineProperty(BoolClass.prototype, "name", {
452
+ get: function () {
453
+ return 'bool';
454
+ },
455
+ enumerable: false,
456
+ configurable: true
457
+ });
458
+ return BoolClass;
459
+ }(PrimitiveType));
460
+ exports.BoolClass = BoolClass;
461
+ /**
462
+ * Represents an IDL Null
463
+ */
464
+ var NullClass = /** @class */ (function (_super) {
465
+ __extends(NullClass, _super);
466
+ function NullClass() {
467
+ return _super !== null && _super.apply(this, arguments) || this;
468
+ }
469
+ NullClass.prototype.accept = function (v, d) {
470
+ return v.visitNull(this, d);
471
+ };
472
+ NullClass.prototype.covariant = function (x) {
473
+ if (x === null)
474
+ return true;
475
+ throw new Error("Invalid ".concat(this.display(), " argument: ").concat(toReadableString(x)));
476
+ };
477
+ NullClass.prototype.encodeValue = function () {
478
+ return new ArrayBuffer(0);
479
+ };
480
+ NullClass.prototype.encodeType = function () {
481
+ return (0, leb128_1.slebEncode)(-1 /* IDLTypeIds.Null */);
482
+ };
483
+ NullClass.prototype.decodeValue = function (b, t) {
484
+ this.checkType(t);
485
+ return null;
486
+ };
487
+ Object.defineProperty(NullClass.prototype, "name", {
488
+ get: function () {
489
+ return 'null';
490
+ },
491
+ enumerable: false,
492
+ configurable: true
493
+ });
494
+ return NullClass;
495
+ }(PrimitiveType));
496
+ exports.NullClass = NullClass;
497
+ /**
498
+ * Represents an IDL Reserved
499
+ */
500
+ var ReservedClass = /** @class */ (function (_super) {
501
+ __extends(ReservedClass, _super);
502
+ function ReservedClass() {
503
+ return _super !== null && _super.apply(this, arguments) || this;
504
+ }
505
+ ReservedClass.prototype.accept = function (v, d) {
506
+ return v.visitReserved(this, d);
507
+ };
508
+ ReservedClass.prototype.covariant = function (x) {
509
+ return true;
510
+ };
511
+ ReservedClass.prototype.encodeValue = function () {
512
+ return new ArrayBuffer(0);
513
+ };
514
+ ReservedClass.prototype.encodeType = function () {
515
+ return (0, leb128_1.slebEncode)(-16 /* IDLTypeIds.Reserved */);
516
+ };
517
+ ReservedClass.prototype.decodeValue = function (b, t) {
518
+ if (t.name !== this.name) {
519
+ t.decodeValue(b, t);
520
+ }
521
+ return null;
522
+ };
523
+ Object.defineProperty(ReservedClass.prototype, "name", {
524
+ get: function () {
525
+ return 'reserved';
526
+ },
527
+ enumerable: false,
528
+ configurable: true
529
+ });
530
+ return ReservedClass;
531
+ }(PrimitiveType));
532
+ exports.ReservedClass = ReservedClass;
533
+ /**
534
+ * Represents an IDL Text
535
+ */
536
+ var TextClass = /** @class */ (function (_super) {
537
+ __extends(TextClass, _super);
538
+ function TextClass() {
539
+ return _super !== null && _super.apply(this, arguments) || this;
540
+ }
541
+ TextClass.prototype.accept = function (v, d) {
542
+ return v.visitText(this, d);
543
+ };
544
+ TextClass.prototype.covariant = function (x) {
545
+ if (typeof x === 'string')
546
+ return true;
547
+ throw new Error("Invalid ".concat(this.display(), " argument: ").concat(toReadableString(x)));
548
+ };
549
+ TextClass.prototype.encodeValue = function (x) {
550
+ var buf = new TextEncoder().encode(x);
551
+ var len = (0, leb128_1.lebEncode)(buf.byteLength);
552
+ return (0, buffer_1.concat)(len, buf);
553
+ };
554
+ TextClass.prototype.encodeType = function () {
555
+ return (0, leb128_1.slebEncode)(-15 /* IDLTypeIds.Text */);
556
+ };
557
+ TextClass.prototype.decodeValue = function (b, t) {
558
+ this.checkType(t);
559
+ var len = (0, leb128_1.lebDecode)(b);
560
+ var buf = (0, leb128_1.safeRead)(b, Number(len));
561
+ var decoder = new TextDecoder('utf8', { fatal: true });
562
+ return decoder.decode(buf);
563
+ };
564
+ Object.defineProperty(TextClass.prototype, "name", {
565
+ get: function () {
566
+ return 'text';
567
+ },
568
+ enumerable: false,
569
+ configurable: true
570
+ });
571
+ TextClass.prototype.valueToString = function (x) {
572
+ return '"' + x + '"';
573
+ };
574
+ return TextClass;
575
+ }(PrimitiveType));
576
+ exports.TextClass = TextClass;
577
+ /**
578
+ * Represents an IDL Int
579
+ */
580
+ var IntClass = /** @class */ (function (_super) {
581
+ __extends(IntClass, _super);
582
+ function IntClass() {
583
+ return _super !== null && _super.apply(this, arguments) || this;
584
+ }
585
+ IntClass.prototype.accept = function (v, d) {
586
+ return v.visitInt(this, d);
587
+ };
588
+ IntClass.prototype.covariant = function (x) {
589
+ // We allow encoding of JavaScript plain numbers.
590
+ // But we will always decode to bigint.
591
+ if (typeof x === 'bigint' || Number.isInteger(x))
592
+ return true;
593
+ throw new Error("Invalid ".concat(this.display(), " argument: ").concat(toReadableString(x)));
594
+ };
595
+ IntClass.prototype.encodeValue = function (x) {
596
+ return (0, leb128_1.slebEncode)(x);
597
+ };
598
+ IntClass.prototype.encodeType = function () {
599
+ return (0, leb128_1.slebEncode)(-4 /* IDLTypeIds.Int */);
600
+ };
601
+ IntClass.prototype.decodeValue = function (b, t) {
602
+ this.checkType(t);
603
+ return (0, leb128_1.slebDecode)(b);
604
+ };
605
+ Object.defineProperty(IntClass.prototype, "name", {
606
+ get: function () {
607
+ return 'int';
608
+ },
609
+ enumerable: false,
610
+ configurable: true
611
+ });
612
+ IntClass.prototype.valueToString = function (x) {
613
+ return x.toString();
614
+ };
615
+ return IntClass;
616
+ }(PrimitiveType));
617
+ exports.IntClass = IntClass;
618
+ /**
619
+ * Represents an IDL Nat
620
+ */
621
+ var NatClass = /** @class */ (function (_super) {
622
+ __extends(NatClass, _super);
623
+ function NatClass() {
624
+ return _super !== null && _super.apply(this, arguments) || this;
625
+ }
626
+ NatClass.prototype.accept = function (v, d) {
627
+ return v.visitNat(this, d);
628
+ };
629
+ NatClass.prototype.covariant = function (x) {
630
+ // We allow encoding of JavaScript plain numbers.
631
+ // But we will always decode to bigint.
632
+ if ((typeof x === 'bigint' && x >= BigInt(0)) || (Number.isInteger(x) && x >= 0))
633
+ return true;
634
+ throw new Error("Invalid ".concat(this.display(), " argument: ").concat(toReadableString(x)));
635
+ };
636
+ NatClass.prototype.encodeValue = function (x) {
637
+ return (0, leb128_1.lebEncode)(x);
638
+ };
639
+ NatClass.prototype.encodeType = function () {
640
+ return (0, leb128_1.slebEncode)(-3 /* IDLTypeIds.Nat */);
641
+ };
642
+ NatClass.prototype.decodeValue = function (b, t) {
643
+ this.checkType(t);
644
+ return (0, leb128_1.lebDecode)(b);
645
+ };
646
+ Object.defineProperty(NatClass.prototype, "name", {
647
+ get: function () {
648
+ return 'nat';
649
+ },
650
+ enumerable: false,
651
+ configurable: true
652
+ });
653
+ NatClass.prototype.valueToString = function (x) {
654
+ return x.toString();
655
+ };
656
+ return NatClass;
657
+ }(PrimitiveType));
658
+ exports.NatClass = NatClass;
659
+ /**
660
+ * Represents an IDL Float
661
+ */
662
+ var FloatClass = /** @class */ (function (_super) {
663
+ __extends(FloatClass, _super);
664
+ function FloatClass(_bits) {
665
+ var _this = _super.call(this) || this;
666
+ _this._bits = _bits;
667
+ if (_bits !== 32 && _bits !== 64) {
668
+ throw new Error('not a valid float type');
669
+ }
670
+ return _this;
671
+ }
672
+ FloatClass.prototype.accept = function (v, d) {
673
+ return v.visitFloat(this, d);
674
+ };
675
+ FloatClass.prototype.covariant = function (x) {
676
+ if (typeof x === 'number' || x instanceof Number)
677
+ return true;
678
+ throw new Error("Invalid ".concat(this.display(), " argument: ").concat(toReadableString(x)));
679
+ };
680
+ FloatClass.prototype.encodeValue = function (x) {
681
+ var buf = new ArrayBuffer(this._bits / 8);
682
+ var view = new DataView(buf);
683
+ if (this._bits === 32) {
684
+ view.setFloat32(0, x, true);
685
+ }
686
+ else {
687
+ view.setFloat64(0, x, true);
688
+ }
689
+ return buf;
690
+ };
691
+ FloatClass.prototype.encodeType = function () {
692
+ var opcode = this._bits === 32 ? -13 /* IDLTypeIds.Float32 */ : -14 /* IDLTypeIds.Float64 */;
693
+ return (0, leb128_1.slebEncode)(opcode);
694
+ };
695
+ FloatClass.prototype.decodeValue = function (b, t) {
696
+ this.checkType(t);
697
+ var bytes = (0, leb128_1.safeRead)(b, this._bits / 8);
698
+ var view = new DataView(bytes);
699
+ if (this._bits === 32) {
700
+ return view.getFloat32(0, true);
701
+ }
702
+ else {
703
+ return view.getFloat64(0, true);
704
+ }
705
+ };
706
+ Object.defineProperty(FloatClass.prototype, "name", {
707
+ get: function () {
708
+ return 'float' + this._bits;
709
+ },
710
+ enumerable: false,
711
+ configurable: true
712
+ });
713
+ FloatClass.prototype.valueToString = function (x) {
714
+ return x.toString();
715
+ };
716
+ return FloatClass;
717
+ }(PrimitiveType));
718
+ exports.FloatClass = FloatClass;
719
+ /**
720
+ * Represents an IDL fixed-width Int(n)
721
+ */
722
+ var FixedIntClass = /** @class */ (function (_super) {
723
+ __extends(FixedIntClass, _super);
724
+ function FixedIntClass(_bits) {
725
+ var _this = _super.call(this) || this;
726
+ _this._bits = _bits;
727
+ return _this;
728
+ }
729
+ FixedIntClass.prototype.accept = function (v, d) {
730
+ return v.visitFixedInt(this, d);
731
+ };
732
+ FixedIntClass.prototype.covariant = function (x) {
733
+ var min = iexp2(this._bits - 1) * BigInt(-1);
734
+ var max = iexp2(this._bits - 1) - BigInt(1);
735
+ var ok = false;
736
+ if (typeof x === 'bigint') {
737
+ ok = x >= min && x <= max;
738
+ }
739
+ else if (Number.isInteger(x)) {
740
+ var v = BigInt(x);
741
+ ok = v >= min && v <= max;
742
+ }
743
+ else {
744
+ ok = false;
745
+ }
746
+ if (ok)
747
+ return true;
748
+ throw new Error("Invalid ".concat(this.display(), " argument: ").concat(toReadableString(x)));
749
+ };
750
+ FixedIntClass.prototype.encodeValue = function (x) {
751
+ return (0, leb128_1.writeIntLE)(x, this._bits / 8);
752
+ };
753
+ FixedIntClass.prototype.encodeType = function () {
754
+ var offset = Math.log2(this._bits) - 3;
755
+ return (0, leb128_1.slebEncode)(-9 - offset);
756
+ };
757
+ FixedIntClass.prototype.decodeValue = function (b, t) {
758
+ this.checkType(t);
759
+ var num = (0, leb128_1.readIntLE)(b, this._bits / 8);
760
+ if (this._bits <= 32) {
761
+ return Number(num);
762
+ }
763
+ else {
764
+ return num;
765
+ }
766
+ };
767
+ Object.defineProperty(FixedIntClass.prototype, "name", {
768
+ get: function () {
769
+ return "int".concat(this._bits);
770
+ },
771
+ enumerable: false,
772
+ configurable: true
773
+ });
774
+ FixedIntClass.prototype.valueToString = function (x) {
775
+ return x.toString();
776
+ };
777
+ return FixedIntClass;
778
+ }(PrimitiveType));
779
+ exports.FixedIntClass = FixedIntClass;
780
+ /**
781
+ * Represents an IDL fixed-width Nat(n)
782
+ */
783
+ var FixedNatClass = /** @class */ (function (_super) {
784
+ __extends(FixedNatClass, _super);
785
+ function FixedNatClass(_bits) {
786
+ var _this = _super.call(this) || this;
787
+ _this._bits = _bits;
788
+ return _this;
789
+ }
790
+ FixedNatClass.prototype.accept = function (v, d) {
791
+ return v.visitFixedNat(this, d);
792
+ };
793
+ FixedNatClass.prototype.covariant = function (x) {
794
+ var max = iexp2(this._bits);
795
+ var ok = false;
796
+ if (typeof x === 'bigint' && x >= BigInt(0)) {
797
+ ok = x < max;
798
+ }
799
+ else if (Number.isInteger(x) && x >= 0) {
800
+ var v = BigInt(x);
801
+ ok = v < max;
802
+ }
803
+ else {
804
+ ok = false;
805
+ }
806
+ if (ok)
807
+ return true;
808
+ throw new Error("Invalid ".concat(this.display(), " argument: ").concat(toReadableString(x)));
809
+ };
810
+ FixedNatClass.prototype.encodeValue = function (x) {
811
+ return (0, leb128_1.writeUIntLE)(x, this._bits / 8);
812
+ };
813
+ FixedNatClass.prototype.encodeType = function () {
814
+ var offset = Math.log2(this._bits) - 3;
815
+ return (0, leb128_1.slebEncode)(-5 - offset);
816
+ };
817
+ FixedNatClass.prototype.decodeValue = function (b, t) {
818
+ this.checkType(t);
819
+ var num = (0, leb128_1.readUIntLE)(b, this._bits / 8);
820
+ if (this._bits <= 32) {
821
+ return Number(num);
822
+ }
823
+ else {
824
+ return num;
825
+ }
826
+ };
827
+ Object.defineProperty(FixedNatClass.prototype, "name", {
828
+ get: function () {
829
+ return "nat".concat(this._bits);
830
+ },
831
+ enumerable: false,
832
+ configurable: true
833
+ });
834
+ FixedNatClass.prototype.valueToString = function (x) {
835
+ return x.toString();
836
+ };
837
+ return FixedNatClass;
838
+ }(PrimitiveType));
839
+ exports.FixedNatClass = FixedNatClass;
840
+ /**
841
+ * Represents an IDL Array
842
+ *
843
+ * Arrays of fixed-sized nat/int type (e.g. nat8), are encoded from and decoded to TypedArrays (e.g. Uint8Array).
844
+ * Arrays of float or other non-primitive types are encoded/decoded as untyped array in Javascript.
845
+ *
846
+ * @param {Type} t
847
+ */
848
+ var VecClass = /** @class */ (function (_super) {
849
+ __extends(VecClass, _super);
850
+ function VecClass(_type) {
851
+ var _this = _super.call(this) || this;
852
+ _this._type = _type;
853
+ // If true, this vector is really a blob and we can just use memcpy.
854
+ //
855
+ // NOTE:
856
+ // With support of encoding/dencoding of TypedArrays, this optimization is
857
+ // only used when plain array of bytes are passed as encoding input in order
858
+ // to be backward compatible.
859
+ _this._blobOptimization = false;
860
+ if (_type instanceof FixedNatClass && _type._bits === 8) {
861
+ _this._blobOptimization = true;
862
+ }
863
+ return _this;
864
+ }
865
+ VecClass.prototype.accept = function (v, d) {
866
+ return v.visitVec(this, this._type, d);
867
+ };
868
+ VecClass.prototype.covariant = function (x) {
869
+ var _this = this;
870
+ // Special case for ArrayBuffer
871
+ var bits = this._type instanceof FixedNatClass ? this._type._bits : this._type instanceof FixedIntClass ? this._type._bits : 0;
872
+ if ((ArrayBuffer.isView(x) && bits == x.BYTES_PER_ELEMENT * 8) ||
873
+ (Array.isArray(x) &&
874
+ x.every(function (v, idx) {
875
+ try {
876
+ return _this._type.covariant(v);
877
+ }
878
+ catch (e) {
879
+ throw new Error("Invalid ".concat(_this.display(), " argument: \n\nindex ").concat(idx, " -> ").concat(e.message));
880
+ }
881
+ })))
882
+ return true;
883
+ throw new Error("Invalid ".concat(this.display(), " argument: ").concat(toReadableString(x)));
884
+ };
885
+ VecClass.prototype.encodeValue = function (x) {
886
+ var e_2, _a;
887
+ var len = (0, leb128_1.lebEncode)(x.length);
888
+ if (this._blobOptimization) {
889
+ return (0, buffer_1.concat)(len, new Uint8Array(x));
890
+ }
891
+ if (ArrayBuffer.isView(x)) {
892
+ return (0, buffer_1.concat)(len, new Uint8Array(x.buffer));
893
+ }
894
+ var buf = new buffer_2.PipeArrayBuffer(new ArrayBuffer(len.byteLength + x.length), 0);
895
+ buf.write(len);
896
+ try {
897
+ for (var x_1 = __values(x), x_1_1 = x_1.next(); !x_1_1.done; x_1_1 = x_1.next()) {
898
+ var d = x_1_1.value;
899
+ var encoded = this._type.encodeValue(d);
900
+ buf.write(new Uint8Array(encoded));
901
+ }
902
+ }
903
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
904
+ finally {
905
+ try {
906
+ if (x_1_1 && !x_1_1.done && (_a = x_1.return)) _a.call(x_1);
907
+ }
908
+ finally { if (e_2) throw e_2.error; }
909
+ }
910
+ return buf.buffer;
911
+ };
912
+ VecClass.prototype._buildTypeTableImpl = function (typeTable) {
913
+ this._type.buildTypeTable(typeTable);
914
+ var opCode = (0, leb128_1.slebEncode)(-19 /* IDLTypeIds.Vector */);
915
+ var buffer = this._type.encodeType(typeTable);
916
+ typeTable.add(this, (0, buffer_1.concat)(opCode, buffer));
917
+ };
918
+ VecClass.prototype.decodeValue = function (b, t) {
919
+ var vec = this.checkType(t);
920
+ if (!(vec instanceof VecClass)) {
921
+ throw new Error('Not a vector type');
922
+ }
923
+ var len = Number((0, leb128_1.lebDecode)(b));
924
+ if (this._type instanceof FixedNatClass) {
925
+ if (this._type._bits == 8) {
926
+ return new Uint8Array(b.read(len));
927
+ }
928
+ if (this._type._bits == 16) {
929
+ return new Uint16Array(b.read(len * 2));
930
+ }
931
+ if (this._type._bits == 32) {
932
+ return new Uint32Array(b.read(len * 4));
933
+ }
934
+ if (this._type._bits == 64) {
935
+ return new BigUint64Array(b.read(len * 8));
936
+ }
937
+ }
938
+ if (this._type instanceof FixedIntClass) {
939
+ if (this._type._bits == 8) {
940
+ return new Int8Array(b.read(len));
941
+ }
942
+ if (this._type._bits == 16) {
943
+ return new Int16Array(b.read(len * 2));
944
+ }
945
+ if (this._type._bits == 32) {
946
+ return new Int32Array(b.read(len * 4));
947
+ }
948
+ if (this._type._bits == 64) {
949
+ return new BigInt64Array(b.read(len * 8));
950
+ }
951
+ }
952
+ var rets = [];
953
+ for (var i = 0; i < len; i++) {
954
+ rets.push(this._type.decodeValue(b, vec._type));
955
+ }
956
+ return rets;
957
+ };
958
+ Object.defineProperty(VecClass.prototype, "name", {
959
+ get: function () {
960
+ return "vec ".concat(this._type.name);
961
+ },
962
+ enumerable: false,
963
+ configurable: true
964
+ });
965
+ VecClass.prototype.display = function () {
966
+ return "vec ".concat(this._type.display());
967
+ };
968
+ VecClass.prototype.valueToString = function (x) {
969
+ var _this = this;
970
+ var elements = x.map(function (e) { return _this._type.valueToString(e); });
971
+ return 'vec {' + elements.join('; ') + '}';
972
+ };
973
+ return VecClass;
974
+ }(ConstructType));
975
+ exports.VecClass = VecClass;
976
+ /**
977
+ * Represents an IDL Option
978
+ * @param {Type} t
979
+ */
980
+ var OptClass = /** @class */ (function (_super) {
981
+ __extends(OptClass, _super);
982
+ function OptClass(_type) {
983
+ var _this = _super.call(this) || this;
984
+ _this._type = _type;
985
+ return _this;
986
+ }
987
+ OptClass.prototype.accept = function (v, d) {
988
+ return v.visitOpt(this, this._type, d);
989
+ };
990
+ OptClass.prototype.covariant = function (x) {
991
+ try {
992
+ if (Array.isArray(x) && (x.length === 0 || (x.length === 1 && this._type.covariant(x[0]))))
993
+ return true;
994
+ }
995
+ catch (e) {
996
+ throw new Error("Invalid ".concat(this.display(), " argument: ").concat(toReadableString(x), " \n\n-> ").concat(e.message));
997
+ }
998
+ throw new Error("Invalid ".concat(this.display(), " argument: ").concat(toReadableString(x)));
999
+ };
1000
+ OptClass.prototype.encodeValue = function (x) {
1001
+ if (x.length === 0) {
1002
+ return new Uint8Array([0]);
1003
+ }
1004
+ else {
1005
+ return (0, buffer_1.concat)(new Uint8Array([1]), this._type.encodeValue(x[0]));
1006
+ }
1007
+ };
1008
+ OptClass.prototype._buildTypeTableImpl = function (typeTable) {
1009
+ this._type.buildTypeTable(typeTable);
1010
+ var opCode = (0, leb128_1.slebEncode)(-18 /* IDLTypeIds.Opt */);
1011
+ var buffer = this._type.encodeType(typeTable);
1012
+ typeTable.add(this, (0, buffer_1.concat)(opCode, buffer));
1013
+ };
1014
+ OptClass.prototype.decodeValue = function (b, t) {
1015
+ var opt = this.checkType(t);
1016
+ if (!(opt instanceof OptClass)) {
1017
+ throw new Error('Not an option type');
1018
+ }
1019
+ switch ((0, leb128_1.safeReadUint8)(b)) {
1020
+ case 0:
1021
+ return [];
1022
+ case 1:
1023
+ return [this._type.decodeValue(b, opt._type)];
1024
+ default:
1025
+ throw new Error('Not an option value');
1026
+ }
1027
+ };
1028
+ Object.defineProperty(OptClass.prototype, "name", {
1029
+ get: function () {
1030
+ return "opt ".concat(this._type.name);
1031
+ },
1032
+ enumerable: false,
1033
+ configurable: true
1034
+ });
1035
+ OptClass.prototype.display = function () {
1036
+ return "opt ".concat(this._type.display());
1037
+ };
1038
+ OptClass.prototype.valueToString = function (x) {
1039
+ if (x.length === 0) {
1040
+ return 'null';
1041
+ }
1042
+ else {
1043
+ return "opt ".concat(this._type.valueToString(x[0]));
1044
+ }
1045
+ };
1046
+ return OptClass;
1047
+ }(ConstructType));
1048
+ exports.OptClass = OptClass;
1049
+ /**
1050
+ * Represents an IDL Record
1051
+ * @param {Object} [fields] - mapping of function name to Type
1052
+ */
1053
+ var RecordClass = /** @class */ (function (_super) {
1054
+ __extends(RecordClass, _super);
1055
+ function RecordClass(fields) {
1056
+ if (fields === void 0) { fields = {}; }
1057
+ var _this = _super.call(this) || this;
1058
+ _this._fields = Object.entries(fields).sort(function (a, b) { return idlLabelToId(a[0]) - idlLabelToId(b[0]); });
1059
+ return _this;
1060
+ }
1061
+ RecordClass.prototype.accept = function (v, d) {
1062
+ return v.visitRecord(this, this._fields, d);
1063
+ };
1064
+ RecordClass.prototype.tryAsTuple = function () {
1065
+ var res = [];
1066
+ for (var i = 0; i < this._fields.length; i++) {
1067
+ var _a = __read(this._fields[i], 2), key = _a[0], type = _a[1];
1068
+ if (key !== "_".concat(i, "_")) {
1069
+ return null;
1070
+ }
1071
+ res.push(type);
1072
+ }
1073
+ return res;
1074
+ };
1075
+ RecordClass.prototype.covariant = function (x) {
1076
+ var _this = this;
1077
+ if (typeof x === 'object' &&
1078
+ this._fields.every(function (_a) {
1079
+ var _b = __read(_a, 2), k = _b[0], t = _b[1];
1080
+ // eslint-disable-next-line
1081
+ if (!x.hasOwnProperty(k)) {
1082
+ throw new Error("Record is missing key \"".concat(k, "\"."));
1083
+ }
1084
+ try {
1085
+ return t.covariant(x[k]);
1086
+ }
1087
+ catch (e) {
1088
+ throw new Error("Invalid ".concat(_this.display(), " argument: \n\nfield ").concat(k, " -> ").concat(e.message));
1089
+ }
1090
+ }))
1091
+ return true;
1092
+ throw new Error("Invalid ".concat(this.display(), " argument: ").concat(toReadableString(x)));
1093
+ };
1094
+ RecordClass.prototype.encodeValue = function (x) {
1095
+ var values = this._fields.map(function (_a) {
1096
+ var _b = __read(_a, 1), key = _b[0];
1097
+ return x[key];
1098
+ });
1099
+ var bufs = zipWith(this._fields, values, function (_a, d) {
1100
+ var _b = __read(_a, 2), c = _b[1];
1101
+ return c.encodeValue(d);
1102
+ });
1103
+ return buffer_1.concat.apply(void 0, __spreadArray([], __read(bufs), false));
1104
+ };
1105
+ RecordClass.prototype._buildTypeTableImpl = function (T) {
1106
+ this._fields.forEach(function (_a) {
1107
+ var _b = __read(_a, 2), _ = _b[0], value = _b[1];
1108
+ return value.buildTypeTable(T);
1109
+ });
1110
+ var opCode = (0, leb128_1.slebEncode)(-20 /* IDLTypeIds.Record */);
1111
+ var len = (0, leb128_1.lebEncode)(this._fields.length);
1112
+ var fields = this._fields.map(function (_a) {
1113
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
1114
+ return (0, buffer_1.concat)((0, leb128_1.lebEncode)(idlLabelToId(key)), value.encodeType(T));
1115
+ });
1116
+ T.add(this, (0, buffer_1.concat)(opCode, len, buffer_1.concat.apply(void 0, __spreadArray([], __read(fields), false))));
1117
+ };
1118
+ RecordClass.prototype.decodeValue = function (b, t) {
1119
+ var e_3, _a;
1120
+ var record = this.checkType(t);
1121
+ if (!(record instanceof RecordClass)) {
1122
+ throw new Error('Not a record type');
1123
+ }
1124
+ var x = {};
1125
+ var expectedRecordIdx = 0;
1126
+ var actualRecordIdx = 0;
1127
+ while (actualRecordIdx < record._fields.length) {
1128
+ var _b = __read(record._fields[actualRecordIdx], 2), hash = _b[0], type = _b[1];
1129
+ if (expectedRecordIdx >= this._fields.length) {
1130
+ // skip unexpected left over fields present on the wire
1131
+ type.decodeValue(b, type);
1132
+ actualRecordIdx++;
1133
+ continue;
1134
+ }
1135
+ var _c = __read(this._fields[expectedRecordIdx], 2), expectKey = _c[0], expectType = _c[1];
1136
+ var expectedId = idlLabelToId(this._fields[expectedRecordIdx][0]);
1137
+ var actualId = idlLabelToId(hash);
1138
+ if (expectedId === actualId) {
1139
+ // the current field on the wire matches the expected field
1140
+ x[expectKey] = expectType.decodeValue(b, type);
1141
+ expectedRecordIdx++;
1142
+ actualRecordIdx++;
1143
+ }
1144
+ else if (actualId > expectedId) {
1145
+ // The expected field does not exist on the wire
1146
+ if (expectType instanceof OptClass || expectType instanceof ReservedClass) {
1147
+ x[expectKey] = [];
1148
+ expectedRecordIdx++;
1149
+ }
1150
+ else {
1151
+ throw new Error('Cannot find required field ' + expectKey);
1152
+ }
1153
+ }
1154
+ else {
1155
+ // The field on the wire does not exist in the output type, so we can skip it
1156
+ type.decodeValue(b, type);
1157
+ actualRecordIdx++;
1158
+ }
1159
+ }
1160
+ try {
1161
+ // initialize left over expected optional fields
1162
+ for (var _d = __values(this._fields.slice(expectedRecordIdx)), _e = _d.next(); !_e.done; _e = _d.next()) {
1163
+ var _f = __read(_e.value, 2), expectKey = _f[0], expectType = _f[1];
1164
+ if (expectType instanceof OptClass || expectType instanceof ReservedClass) {
1165
+ // TODO this assumes null value in opt is represented as []
1166
+ x[expectKey] = [];
1167
+ }
1168
+ else {
1169
+ throw new Error('Cannot find required field ' + expectKey);
1170
+ }
1171
+ }
1172
+ }
1173
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
1174
+ finally {
1175
+ try {
1176
+ if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
1177
+ }
1178
+ finally { if (e_3) throw e_3.error; }
1179
+ }
1180
+ return x;
1181
+ };
1182
+ Object.defineProperty(RecordClass.prototype, "name", {
1183
+ get: function () {
1184
+ var fields = this._fields.map(function (_a) {
1185
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
1186
+ return key + ':' + value.name;
1187
+ });
1188
+ return "record {".concat(fields.join('; '), "}");
1189
+ },
1190
+ enumerable: false,
1191
+ configurable: true
1192
+ });
1193
+ RecordClass.prototype.display = function () {
1194
+ var fields = this._fields.map(function (_a) {
1195
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
1196
+ return key + ':' + value.display();
1197
+ });
1198
+ return "record {".concat(fields.join('; '), "}");
1199
+ };
1200
+ RecordClass.prototype.valueToString = function (x) {
1201
+ var values = this._fields.map(function (_a) {
1202
+ var _b = __read(_a, 1), key = _b[0];
1203
+ return x[key];
1204
+ });
1205
+ var fields = zipWith(this._fields, values, function (_a, d) {
1206
+ var _b = __read(_a, 2), k = _b[0], c = _b[1];
1207
+ return k + '=' + c.valueToString(d);
1208
+ });
1209
+ return "record {".concat(fields.join('; '), "}");
1210
+ };
1211
+ return RecordClass;
1212
+ }(ConstructType));
1213
+ exports.RecordClass = RecordClass;
1214
+ /**
1215
+ * Represents Tuple, a syntactic sugar for Record.
1216
+ * @param {Type} components
1217
+ */
1218
+ var TupleClass = /** @class */ (function (_super) {
1219
+ __extends(TupleClass, _super);
1220
+ function TupleClass(_components) {
1221
+ var _this = this;
1222
+ var x = {};
1223
+ _components.forEach(function (e, i) { return (x['_' + i + '_'] = e); });
1224
+ _this = _super.call(this, x) || this;
1225
+ _this._components = _components;
1226
+ return _this;
1227
+ }
1228
+ TupleClass.prototype.accept = function (v, d) {
1229
+ return v.visitTuple(this, this._components, d);
1230
+ };
1231
+ TupleClass.prototype.covariant = function (x) {
1232
+ // `>=` because tuples can be covariant when encoded.
1233
+ var _this = this;
1234
+ if (Array.isArray(x) &&
1235
+ x.length >= this._fields.length &&
1236
+ this._components.every(function (t, i) {
1237
+ try {
1238
+ return t.covariant(x[i]);
1239
+ }
1240
+ catch (e) {
1241
+ throw new Error("Invalid ".concat(_this.display(), " argument: \n\nindex ").concat(i, " -> ").concat(e.message));
1242
+ }
1243
+ }))
1244
+ return true;
1245
+ throw new Error("Invalid ".concat(this.display(), " argument: ").concat(toReadableString(x)));
1246
+ };
1247
+ TupleClass.prototype.encodeValue = function (x) {
1248
+ var bufs = zipWith(this._components, x, function (c, d) { return c.encodeValue(d); });
1249
+ return buffer_1.concat.apply(void 0, __spreadArray([], __read(bufs), false));
1250
+ };
1251
+ TupleClass.prototype.decodeValue = function (b, t) {
1252
+ var e_4, _a;
1253
+ var tuple = this.checkType(t);
1254
+ if (!(tuple instanceof TupleClass)) {
1255
+ throw new Error('not a tuple type');
1256
+ }
1257
+ if (tuple._components.length < this._components.length) {
1258
+ throw new Error('tuple mismatch');
1259
+ }
1260
+ var res = [];
1261
+ try {
1262
+ for (var _b = __values(tuple._components.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
1263
+ var _d = __read(_c.value, 2), i = _d[0], wireType = _d[1];
1264
+ if (i >= this._components.length) {
1265
+ // skip value
1266
+ wireType.decodeValue(b, wireType);
1267
+ }
1268
+ else {
1269
+ res.push(this._components[i].decodeValue(b, wireType));
1270
+ }
1271
+ }
1272
+ }
1273
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
1274
+ finally {
1275
+ try {
1276
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1277
+ }
1278
+ finally { if (e_4) throw e_4.error; }
1279
+ }
1280
+ return res;
1281
+ };
1282
+ TupleClass.prototype.display = function () {
1283
+ var fields = this._components.map(function (value) { return value.display(); });
1284
+ return "record {".concat(fields.join('; '), "}");
1285
+ };
1286
+ TupleClass.prototype.valueToString = function (values) {
1287
+ var fields = zipWith(this._components, values, function (c, d) { return c.valueToString(d); });
1288
+ return "record {".concat(fields.join('; '), "}");
1289
+ };
1290
+ return TupleClass;
1291
+ }(RecordClass));
1292
+ exports.TupleClass = TupleClass;
1293
+ /**
1294
+ * Represents an IDL Variant
1295
+ * @param {Object} [fields] - mapping of function name to Type
1296
+ */
1297
+ var VariantClass = /** @class */ (function (_super) {
1298
+ __extends(VariantClass, _super);
1299
+ function VariantClass(fields) {
1300
+ if (fields === void 0) { fields = {}; }
1301
+ var _this = _super.call(this) || this;
1302
+ _this._fields = Object.entries(fields).sort(function (a, b) { return idlLabelToId(a[0]) - idlLabelToId(b[0]); });
1303
+ return _this;
1304
+ }
1305
+ VariantClass.prototype.accept = function (v, d) {
1306
+ return v.visitVariant(this, this._fields, d);
1307
+ };
1308
+ VariantClass.prototype.covariant = function (x) {
1309
+ var _this = this;
1310
+ if (typeof x === 'object' &&
1311
+ Object.entries(x).length === 1 &&
1312
+ this._fields.every(function (_a) {
1313
+ var _b = __read(_a, 2), k = _b[0], v = _b[1];
1314
+ try {
1315
+ // eslint-disable-next-line
1316
+ return !x.hasOwnProperty(k) || v.covariant(x[k]);
1317
+ }
1318
+ catch (e) {
1319
+ throw new Error("Invalid ".concat(_this.display(), " argument: \n\nvariant ").concat(k, " -> ").concat(e.message));
1320
+ }
1321
+ }))
1322
+ return true;
1323
+ throw new Error("Invalid ".concat(this.display(), " argument: ").concat(toReadableString(x)));
1324
+ };
1325
+ VariantClass.prototype.encodeValue = function (x) {
1326
+ for (var i = 0; i < this._fields.length; i++) {
1327
+ var _a = __read(this._fields[i], 2), name_1 = _a[0], type = _a[1];
1328
+ // eslint-disable-next-line
1329
+ if (x.hasOwnProperty(name_1)) {
1330
+ var idx = (0, leb128_1.lebEncode)(i);
1331
+ var buf = type.encodeValue(x[name_1]);
1332
+ return (0, buffer_1.concat)(idx, buf);
1333
+ }
1334
+ }
1335
+ throw Error('Variant has no data: ' + x);
1336
+ };
1337
+ VariantClass.prototype._buildTypeTableImpl = function (typeTable) {
1338
+ this._fields.forEach(function (_a) {
1339
+ var _b = __read(_a, 2), type = _b[1];
1340
+ type.buildTypeTable(typeTable);
1341
+ });
1342
+ var opCode = (0, leb128_1.slebEncode)(-21 /* IDLTypeIds.Variant */);
1343
+ var len = (0, leb128_1.lebEncode)(this._fields.length);
1344
+ var fields = this._fields.map(function (_a) {
1345
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
1346
+ return (0, buffer_1.concat)((0, leb128_1.lebEncode)(idlLabelToId(key)), value.encodeType(typeTable));
1347
+ });
1348
+ typeTable.add(this, buffer_1.concat.apply(void 0, __spreadArray([opCode, len], __read(fields), false)));
1349
+ };
1350
+ VariantClass.prototype.decodeValue = function (b, t) {
1351
+ var e_5, _a, _b;
1352
+ var variant = this.checkType(t);
1353
+ if (!(variant instanceof VariantClass)) {
1354
+ throw new Error('Not a variant type');
1355
+ }
1356
+ var idx = Number((0, leb128_1.lebDecode)(b));
1357
+ if (idx >= variant._fields.length) {
1358
+ throw Error('Invalid variant index: ' + idx);
1359
+ }
1360
+ var _c = __read(variant._fields[idx], 2), wireHash = _c[0], wireType = _c[1];
1361
+ try {
1362
+ for (var _d = __values(this._fields), _e = _d.next(); !_e.done; _e = _d.next()) {
1363
+ var _f = __read(_e.value, 2), key = _f[0], expectType = _f[1];
1364
+ if (idlLabelToId(wireHash) === idlLabelToId(key)) {
1365
+ var value = expectType.decodeValue(b, wireType);
1366
+ return _b = {}, _b[key] = value, _b;
1367
+ }
1368
+ }
1369
+ }
1370
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
1371
+ finally {
1372
+ try {
1373
+ if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
1374
+ }
1375
+ finally { if (e_5) throw e_5.error; }
1376
+ }
1377
+ throw new Error('Cannot find field hash ' + wireHash);
1378
+ };
1379
+ Object.defineProperty(VariantClass.prototype, "name", {
1380
+ get: function () {
1381
+ var fields = this._fields.map(function (_a) {
1382
+ var _b = __read(_a, 2), key = _b[0], type = _b[1];
1383
+ return key + ':' + type.name;
1384
+ });
1385
+ return "variant {".concat(fields.join('; '), "}");
1386
+ },
1387
+ enumerable: false,
1388
+ configurable: true
1389
+ });
1390
+ VariantClass.prototype.display = function () {
1391
+ var fields = this._fields.map(function (_a) {
1392
+ var _b = __read(_a, 2), key = _b[0], type = _b[1];
1393
+ return key + (type.name === 'null' ? '' : ":".concat(type.display()));
1394
+ });
1395
+ return "variant {".concat(fields.join('; '), "}");
1396
+ };
1397
+ VariantClass.prototype.valueToString = function (x) {
1398
+ var e_6, _a;
1399
+ try {
1400
+ for (var _b = __values(this._fields), _c = _b.next(); !_c.done; _c = _b.next()) {
1401
+ var _d = __read(_c.value, 2), name_2 = _d[0], type = _d[1];
1402
+ // eslint-disable-next-line
1403
+ if (x.hasOwnProperty(name_2)) {
1404
+ var value = type.valueToString(x[name_2]);
1405
+ if (value === 'null') {
1406
+ return "variant {".concat(name_2, "}");
1407
+ }
1408
+ else {
1409
+ return "variant {".concat(name_2, "=").concat(value, "}");
1410
+ }
1411
+ }
1412
+ }
1413
+ }
1414
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
1415
+ finally {
1416
+ try {
1417
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1418
+ }
1419
+ finally { if (e_6) throw e_6.error; }
1420
+ }
1421
+ throw new Error('Variant has no data: ' + x);
1422
+ };
1423
+ return VariantClass;
1424
+ }(ConstructType));
1425
+ exports.VariantClass = VariantClass;
1426
+ /**
1427
+ * Represents a reference to an IDL type, used for defining recursive data
1428
+ * types.
1429
+ */
1430
+ var RecClass = /** @class */ (function (_super) {
1431
+ __extends(RecClass, _super);
1432
+ function RecClass() {
1433
+ var _this = _super !== null && _super.apply(this, arguments) || this;
1434
+ _this._id = RecClass._counter++;
1435
+ _this._type = undefined;
1436
+ return _this;
1437
+ }
1438
+ RecClass.prototype.accept = function (v, d) {
1439
+ if (!this._type) {
1440
+ throw Error('Recursive type uninitialized.');
1441
+ }
1442
+ return v.visitRec(this, this._type, d);
1443
+ };
1444
+ RecClass.prototype.fill = function (t) {
1445
+ this._type = t;
1446
+ };
1447
+ RecClass.prototype.getType = function () {
1448
+ return this._type;
1449
+ };
1450
+ RecClass.prototype.covariant = function (x) {
1451
+ if (this._type ? this._type.covariant(x) : false)
1452
+ return true;
1453
+ throw new Error("Invalid ".concat(this.display(), " argument: ").concat(toReadableString(x)));
1454
+ };
1455
+ RecClass.prototype.encodeValue = function (x) {
1456
+ if (!this._type) {
1457
+ throw Error('Recursive type uninitialized.');
1458
+ }
1459
+ return this._type.encodeValue(x);
1460
+ };
1461
+ RecClass.prototype._buildTypeTableImpl = function (typeTable) {
1462
+ if (!this._type) {
1463
+ throw Error('Recursive type uninitialized.');
1464
+ }
1465
+ typeTable.add(this, new Uint8Array([]));
1466
+ this._type.buildTypeTable(typeTable);
1467
+ typeTable.merge(this, this._type.name);
1468
+ };
1469
+ RecClass.prototype.decodeValue = function (b, t) {
1470
+ if (!this._type) {
1471
+ throw Error('Recursive type uninitialized.');
1472
+ }
1473
+ return this._type.decodeValue(b, t);
1474
+ };
1475
+ Object.defineProperty(RecClass.prototype, "name", {
1476
+ get: function () {
1477
+ return "rec_".concat(this._id);
1478
+ },
1479
+ enumerable: false,
1480
+ configurable: true
1481
+ });
1482
+ RecClass.prototype.display = function () {
1483
+ if (!this._type) {
1484
+ throw Error('Recursive type uninitialized.');
1485
+ }
1486
+ return "\u03BC".concat(this.name, ".").concat(this._type.name);
1487
+ };
1488
+ RecClass.prototype.valueToString = function (x) {
1489
+ if (!this._type) {
1490
+ throw Error('Recursive type uninitialized.');
1491
+ }
1492
+ return this._type.valueToString(x);
1493
+ };
1494
+ RecClass._counter = 0;
1495
+ return RecClass;
1496
+ }(ConstructType));
1497
+ exports.RecClass = RecClass;
1498
+ function decodePrincipalId(b) {
1499
+ var x = (0, leb128_1.safeReadUint8)(b);
1500
+ if (x !== 1) {
1501
+ throw new Error('Cannot decode principal');
1502
+ }
1503
+ var len = Number((0, leb128_1.lebDecode)(b));
1504
+ return principal_1.Principal.fromUint8Array(new Uint8Array((0, leb128_1.safeRead)(b, len)));
1505
+ }
1506
+ /**
1507
+ * Represents an IDL principal reference
1508
+ */
1509
+ var PrincipalClass = /** @class */ (function (_super) {
1510
+ __extends(PrincipalClass, _super);
1511
+ function PrincipalClass() {
1512
+ return _super !== null && _super.apply(this, arguments) || this;
1513
+ }
1514
+ PrincipalClass.prototype.accept = function (v, d) {
1515
+ return v.visitPrincipal(this, d);
1516
+ };
1517
+ PrincipalClass.prototype.covariant = function (x) {
1518
+ if (x && x._isPrincipal)
1519
+ return true;
1520
+ throw new Error("Invalid ".concat(this.display(), " argument: ").concat(toReadableString(x)));
1521
+ };
1522
+ PrincipalClass.prototype.encodeValue = function (x) {
1523
+ var buf = x.toUint8Array();
1524
+ var len = (0, leb128_1.lebEncode)(buf.byteLength);
1525
+ return (0, buffer_1.concat)(new Uint8Array([1]), len, buf);
1526
+ };
1527
+ PrincipalClass.prototype.encodeType = function () {
1528
+ return (0, leb128_1.slebEncode)(-24 /* IDLTypeIds.Principal */);
1529
+ };
1530
+ PrincipalClass.prototype.decodeValue = function (b, t) {
1531
+ this.checkType(t);
1532
+ return decodePrincipalId(b);
1533
+ };
1534
+ Object.defineProperty(PrincipalClass.prototype, "name", {
1535
+ get: function () {
1536
+ return 'principal';
1537
+ },
1538
+ enumerable: false,
1539
+ configurable: true
1540
+ });
1541
+ PrincipalClass.prototype.valueToString = function (x) {
1542
+ return "".concat(this.name, " \"").concat(x.toText(), "\"");
1543
+ };
1544
+ return PrincipalClass;
1545
+ }(PrimitiveType));
1546
+ exports.PrincipalClass = PrincipalClass;
1547
+ /**
1548
+ * Represents an IDL function reference.
1549
+ * @param argTypes Argument types.
1550
+ * @param retTypes Return types.
1551
+ * @param annotations Function annotations.
1552
+ */
1553
+ var FuncClass = /** @class */ (function (_super) {
1554
+ __extends(FuncClass, _super);
1555
+ function FuncClass(argTypes, retTypes, annotations) {
1556
+ if (annotations === void 0) { annotations = []; }
1557
+ var _this = _super.call(this) || this;
1558
+ _this.argTypes = argTypes;
1559
+ _this.retTypes = retTypes;
1560
+ _this.annotations = annotations;
1561
+ return _this;
1562
+ }
1563
+ FuncClass.argsToString = function (types, v) {
1564
+ if (types.length !== v.length) {
1565
+ throw new Error('arity mismatch');
1566
+ }
1567
+ return '(' + types.map(function (t, i) { return t.valueToString(v[i]); }).join(', ') + ')';
1568
+ };
1569
+ FuncClass.prototype.accept = function (v, d) {
1570
+ return v.visitFunc(this, d);
1571
+ };
1572
+ FuncClass.prototype.covariant = function (x) {
1573
+ if (Array.isArray(x) && x.length === 2 && x[0] && x[0]._isPrincipal && typeof x[1] === 'string')
1574
+ return true;
1575
+ throw new Error("Invalid ".concat(this.display(), " argument: ").concat(toReadableString(x)));
1576
+ };
1577
+ FuncClass.prototype.encodeValue = function (_a) {
1578
+ var _b = __read(_a, 2), principal = _b[0], methodName = _b[1];
1579
+ var buf = principal.toUint8Array();
1580
+ var len = (0, leb128_1.lebEncode)(buf.byteLength);
1581
+ var canister = (0, buffer_1.concat)(new Uint8Array([1]), len, buf);
1582
+ var method = new TextEncoder().encode(methodName);
1583
+ var methodLen = (0, leb128_1.lebEncode)(method.byteLength);
1584
+ return (0, buffer_1.concat)(new Uint8Array([1]), canister, methodLen, method);
1585
+ };
1586
+ FuncClass.prototype._buildTypeTableImpl = function (T) {
1587
+ var _this = this;
1588
+ this.argTypes.forEach(function (arg) { return arg.buildTypeTable(T); });
1589
+ this.retTypes.forEach(function (arg) { return arg.buildTypeTable(T); });
1590
+ var opCode = (0, leb128_1.slebEncode)(-22 /* IDLTypeIds.Func */);
1591
+ var argLen = (0, leb128_1.lebEncode)(this.argTypes.length);
1592
+ var args = buffer_1.concat.apply(void 0, __spreadArray([], __read(this.argTypes.map(function (arg) { return arg.encodeType(T); })), false));
1593
+ var retLen = (0, leb128_1.lebEncode)(this.retTypes.length);
1594
+ var rets = buffer_1.concat.apply(void 0, __spreadArray([], __read(this.retTypes.map(function (arg) { return arg.encodeType(T); })), false));
1595
+ var annLen = (0, leb128_1.lebEncode)(this.annotations.length);
1596
+ var anns = buffer_1.concat.apply(void 0, __spreadArray([], __read(this.annotations.map(function (a) { return _this.encodeAnnotation(a); })), false));
1597
+ T.add(this, (0, buffer_1.concat)(opCode, argLen, args, retLen, rets, annLen, anns));
1598
+ };
1599
+ FuncClass.prototype.decodeValue = function (b) {
1600
+ var x = (0, leb128_1.safeReadUint8)(b);
1601
+ if (x !== 1) {
1602
+ throw new Error('Cannot decode function reference');
1603
+ }
1604
+ var canister = decodePrincipalId(b);
1605
+ var mLen = Number((0, leb128_1.lebDecode)(b));
1606
+ var buf = (0, leb128_1.safeRead)(b, mLen);
1607
+ var decoder = new TextDecoder('utf8', { fatal: true });
1608
+ var method = decoder.decode(buf);
1609
+ return [canister, method];
1610
+ };
1611
+ Object.defineProperty(FuncClass.prototype, "name", {
1612
+ get: function () {
1613
+ var args = this.argTypes.map(function (arg) { return arg.name; }).join(', ');
1614
+ var rets = this.retTypes.map(function (arg) { return arg.name; }).join(', ');
1615
+ var annon = ' ' + this.annotations.join(' ');
1616
+ return "(".concat(args, ") -> (").concat(rets, ")").concat(annon);
1617
+ },
1618
+ enumerable: false,
1619
+ configurable: true
1620
+ });
1621
+ FuncClass.prototype.valueToString = function (_a) {
1622
+ var _b = __read(_a, 2), principal = _b[0], str = _b[1];
1623
+ return "func \"".concat(principal.toText(), "\".").concat(str);
1624
+ };
1625
+ FuncClass.prototype.display = function () {
1626
+ var args = this.argTypes.map(function (arg) { return arg.display(); }).join(', ');
1627
+ var rets = this.retTypes.map(function (arg) { return arg.display(); }).join(', ');
1628
+ var annon = ' ' + this.annotations.join(' ');
1629
+ return "(".concat(args, ") \u2192 (").concat(rets, ")").concat(annon);
1630
+ };
1631
+ FuncClass.prototype.encodeAnnotation = function (ann) {
1632
+ if (ann === 'query') {
1633
+ return new Uint8Array([1]);
1634
+ }
1635
+ else if (ann === 'oneway') {
1636
+ return new Uint8Array([2]);
1637
+ }
1638
+ else {
1639
+ throw new Error('Illegal function annotation');
1640
+ }
1641
+ };
1642
+ return FuncClass;
1643
+ }(ConstructType));
1644
+ exports.FuncClass = FuncClass;
1645
+ var ServiceClass = /** @class */ (function (_super) {
1646
+ __extends(ServiceClass, _super);
1647
+ function ServiceClass(fields) {
1648
+ var _this = _super.call(this) || this;
1649
+ _this._fields = Object.entries(fields).sort(function (a, b) { return idlLabelToId(a[0]) - idlLabelToId(b[0]); });
1650
+ return _this;
1651
+ }
1652
+ ServiceClass.prototype.accept = function (v, d) {
1653
+ return v.visitService(this, d);
1654
+ };
1655
+ ServiceClass.prototype.covariant = function (x) {
1656
+ if (x && x._isPrincipal)
1657
+ return true;
1658
+ throw new Error("Invalid ".concat(this.display(), " argument: ").concat(toReadableString(x)));
1659
+ };
1660
+ ServiceClass.prototype.encodeValue = function (x) {
1661
+ var buf = x.toUint8Array();
1662
+ var len = (0, leb128_1.lebEncode)(buf.length);
1663
+ return (0, buffer_1.concat)(new Uint8Array([1]), len, buf);
1664
+ };
1665
+ ServiceClass.prototype._buildTypeTableImpl = function (T) {
1666
+ this._fields.forEach(function (_a) {
1667
+ var _b = __read(_a, 2), _ = _b[0], func = _b[1];
1668
+ return func.buildTypeTable(T);
1669
+ });
1670
+ var opCode = (0, leb128_1.slebEncode)(-23 /* IDLTypeIds.Service */);
1671
+ var len = (0, leb128_1.lebEncode)(this._fields.length);
1672
+ var meths = this._fields.map(function (_a) {
1673
+ var _b = __read(_a, 2), label = _b[0], func = _b[1];
1674
+ var labelBuf = new TextEncoder().encode(label);
1675
+ var labelLen = (0, leb128_1.lebEncode)(labelBuf.length);
1676
+ return (0, buffer_1.concat)(labelLen, labelBuf, func.encodeType(T));
1677
+ });
1678
+ T.add(this, buffer_1.concat.apply(void 0, __spreadArray([opCode, len], __read(meths), false)));
1679
+ };
1680
+ ServiceClass.prototype.decodeValue = function (b) {
1681
+ return decodePrincipalId(b);
1682
+ };
1683
+ Object.defineProperty(ServiceClass.prototype, "name", {
1684
+ get: function () {
1685
+ var fields = this._fields.map(function (_a) {
1686
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
1687
+ return key + ':' + value.name;
1688
+ });
1689
+ return "service {".concat(fields.join('; '), "}");
1690
+ },
1691
+ enumerable: false,
1692
+ configurable: true
1693
+ });
1694
+ ServiceClass.prototype.valueToString = function (x) {
1695
+ return "service \"".concat(x.toText(), "\"");
1696
+ };
1697
+ return ServiceClass;
1698
+ }(ConstructType));
1699
+ exports.ServiceClass = ServiceClass;
1700
+ /**
1701
+ *
1702
+ * @param x
1703
+ * @returns {string}
1704
+ */
1705
+ function toReadableString(x) {
1706
+ var str = JSON.stringify(x, function (_key, value) { return (typeof value === 'bigint' ? "BigInt(".concat(value, ")") : value); });
1707
+ return str && str.length > toReadableString_max ? str.substring(0, toReadableString_max - 3) + '...' : str;
1708
+ }
1709
+ /**
1710
+ * Encode a array of values
1711
+ * @param argTypes
1712
+ * @param args
1713
+ * @returns {Buffer} serialised value
1714
+ */
1715
+ function encode(argTypes, args) {
1716
+ if (args.length < argTypes.length) {
1717
+ throw Error('Wrong number of message arguments');
1718
+ }
1719
+ var typeTable = new TypeTable();
1720
+ argTypes.forEach(function (t) { return t.buildTypeTable(typeTable); });
1721
+ var magic = new TextEncoder().encode(magicNumber);
1722
+ var table = typeTable.encode();
1723
+ var len = (0, leb128_1.lebEncode)(args.length);
1724
+ var typs = buffer_1.concat.apply(void 0, __spreadArray([], __read(argTypes.map(function (t) { return t.encodeType(typeTable); })), false));
1725
+ var vals = buffer_1.concat.apply(void 0, __spreadArray([], __read(zipWith(argTypes, args, function (t, x) {
1726
+ try {
1727
+ t.covariant(x);
1728
+ }
1729
+ catch (e) {
1730
+ var err = new Error(e.message + '\n\n');
1731
+ throw err;
1732
+ }
1733
+ return t.encodeValue(x);
1734
+ })), false));
1735
+ return (0, buffer_1.concat)(magic, table, len, typs, vals);
1736
+ }
1737
+ exports.encode = encode;
1738
+ /**
1739
+ * Decode a binary value
1740
+ * @param retTypes - Types expected in the buffer.
1741
+ * @param bytes - hex-encoded string, or buffer.
1742
+ * @returns Value deserialised to JS type
1743
+ */
1744
+ function decode(retTypes, bytes) {
1745
+ var b = new buffer_2.PipeArrayBuffer(bytes);
1746
+ if (bytes.byteLength < magicNumber.length) {
1747
+ throw new Error('Message length smaller than magic number');
1748
+ }
1749
+ var magicBuffer = (0, leb128_1.safeRead)(b, magicNumber.length);
1750
+ var magic = new TextDecoder().decode(magicBuffer);
1751
+ if (magic !== magicNumber) {
1752
+ throw new Error('Wrong magic number: ' + JSON.stringify(magic));
1753
+ }
1754
+ function readTypeTable(pipe) {
1755
+ var typeTable = [];
1756
+ var len = Number((0, leb128_1.lebDecode)(pipe));
1757
+ for (var i = 0; i < len; i++) {
1758
+ var ty = Number((0, leb128_1.slebDecode)(pipe));
1759
+ switch (ty) {
1760
+ case -18 /* IDLTypeIds.Opt */:
1761
+ case -19 /* IDLTypeIds.Vector */: {
1762
+ var t = Number((0, leb128_1.slebDecode)(pipe));
1763
+ typeTable.push([ty, t]);
1764
+ break;
1765
+ }
1766
+ case -20 /* IDLTypeIds.Record */:
1767
+ case -21 /* IDLTypeIds.Variant */: {
1768
+ var fields = [];
1769
+ var objectLength = Number((0, leb128_1.lebDecode)(pipe));
1770
+ var prevHash = void 0;
1771
+ while (objectLength--) {
1772
+ var hash = Number((0, leb128_1.lebDecode)(pipe));
1773
+ if (hash >= Math.pow(2, 32)) {
1774
+ throw new Error('field id out of 32-bit range');
1775
+ }
1776
+ if (typeof prevHash === 'number' && prevHash >= hash) {
1777
+ throw new Error('field id collision or not sorted');
1778
+ }
1779
+ prevHash = hash;
1780
+ var t = Number((0, leb128_1.slebDecode)(pipe));
1781
+ fields.push([hash, t]);
1782
+ }
1783
+ typeTable.push([ty, fields]);
1784
+ break;
1785
+ }
1786
+ case -22 /* IDLTypeIds.Func */: {
1787
+ var args = [];
1788
+ var argLength = Number((0, leb128_1.lebDecode)(pipe));
1789
+ while (argLength--) {
1790
+ args.push(Number((0, leb128_1.slebDecode)(pipe)));
1791
+ }
1792
+ var returnValues = [];
1793
+ var returnValuesLength = Number((0, leb128_1.lebDecode)(pipe));
1794
+ while (returnValuesLength--) {
1795
+ returnValues.push(Number((0, leb128_1.slebDecode)(pipe)));
1796
+ }
1797
+ var annotations = [];
1798
+ var annotationLength = Number((0, leb128_1.lebDecode)(pipe));
1799
+ while (annotationLength--) {
1800
+ var annotation = Number((0, leb128_1.lebDecode)(pipe));
1801
+ switch (annotation) {
1802
+ case 1: {
1803
+ annotations.push('query');
1804
+ break;
1805
+ }
1806
+ case 2: {
1807
+ annotations.push('oneway');
1808
+ break;
1809
+ }
1810
+ default:
1811
+ throw new Error('unknown annotation');
1812
+ }
1813
+ }
1814
+ typeTable.push([ty, [args, returnValues, annotations]]);
1815
+ break;
1816
+ }
1817
+ case -23 /* IDLTypeIds.Service */: {
1818
+ var servLength = Number((0, leb128_1.lebDecode)(pipe));
1819
+ var methods = [];
1820
+ while (servLength--) {
1821
+ var nameLength = Number((0, leb128_1.lebDecode)(pipe));
1822
+ var funcName = new TextDecoder().decode((0, leb128_1.safeRead)(pipe, nameLength));
1823
+ var funcType = (0, leb128_1.slebDecode)(pipe);
1824
+ methods.push([funcName, funcType]);
1825
+ }
1826
+ typeTable.push([ty, methods]);
1827
+ break;
1828
+ }
1829
+ default:
1830
+ throw new Error('Illegal op_code: ' + ty);
1831
+ }
1832
+ }
1833
+ var rawList = [];
1834
+ var length = Number((0, leb128_1.lebDecode)(pipe));
1835
+ for (var i = 0; i < length; i++) {
1836
+ rawList.push(Number((0, leb128_1.slebDecode)(pipe)));
1837
+ }
1838
+ return [typeTable, rawList];
1839
+ }
1840
+ var _a = __read(readTypeTable(b), 2), rawTable = _a[0], rawTypes = _a[1];
1841
+ if (rawTypes.length < retTypes.length) {
1842
+ throw new Error('Wrong number of return values');
1843
+ }
1844
+ var table = rawTable.map(function (_) { return Rec(); });
1845
+ function getType(t) {
1846
+ if (t < -24) {
1847
+ throw new Error('future value not supported');
1848
+ }
1849
+ if (t < 0) {
1850
+ switch (t) {
1851
+ case -1:
1852
+ return exports.Null;
1853
+ case -2:
1854
+ return exports.Bool;
1855
+ case -3:
1856
+ return exports.Nat;
1857
+ case -4:
1858
+ return exports.Int;
1859
+ case -5:
1860
+ return exports.Nat8;
1861
+ case -6:
1862
+ return exports.Nat16;
1863
+ case -7:
1864
+ return exports.Nat32;
1865
+ case -8:
1866
+ return exports.Nat64;
1867
+ case -9:
1868
+ return exports.Int8;
1869
+ case -10:
1870
+ return exports.Int16;
1871
+ case -11:
1872
+ return exports.Int32;
1873
+ case -12:
1874
+ return exports.Int64;
1875
+ case -13:
1876
+ return exports.Float32;
1877
+ case -14:
1878
+ return exports.Float64;
1879
+ case -15:
1880
+ return exports.Text;
1881
+ case -16:
1882
+ return exports.Reserved;
1883
+ case -17:
1884
+ return exports.Empty;
1885
+ case -24:
1886
+ return exports.Principal;
1887
+ default:
1888
+ throw new Error('Illegal op_code: ' + t);
1889
+ }
1890
+ }
1891
+ if (t >= rawTable.length) {
1892
+ throw new Error('type index out of range');
1893
+ }
1894
+ return table[t];
1895
+ }
1896
+ function buildType(entry) {
1897
+ var e_7, _a, e_8, _b, e_9, _c;
1898
+ switch (entry[0]) {
1899
+ case -19 /* IDLTypeIds.Vector */: {
1900
+ var ty = getType(entry[1]);
1901
+ return Vec(ty);
1902
+ }
1903
+ case -18 /* IDLTypeIds.Opt */: {
1904
+ var ty = getType(entry[1]);
1905
+ return Opt(ty);
1906
+ }
1907
+ case -20 /* IDLTypeIds.Record */: {
1908
+ var fields = {};
1909
+ try {
1910
+ for (var _d = __values(entry[1]), _e = _d.next(); !_e.done; _e = _d.next()) {
1911
+ var _f = __read(_e.value, 2), hash = _f[0], ty = _f[1];
1912
+ var name_3 = "_".concat(hash, "_");
1913
+ fields[name_3] = getType(ty);
1914
+ }
1915
+ }
1916
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
1917
+ finally {
1918
+ try {
1919
+ if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
1920
+ }
1921
+ finally { if (e_7) throw e_7.error; }
1922
+ }
1923
+ var record = Record(fields);
1924
+ var tuple = record.tryAsTuple();
1925
+ if (Array.isArray(tuple)) {
1926
+ return Tuple.apply(void 0, __spreadArray([], __read(tuple), false));
1927
+ }
1928
+ else {
1929
+ return record;
1930
+ }
1931
+ }
1932
+ case -21 /* IDLTypeIds.Variant */: {
1933
+ var fields = {};
1934
+ try {
1935
+ for (var _g = __values(entry[1]), _h = _g.next(); !_h.done; _h = _g.next()) {
1936
+ var _j = __read(_h.value, 2), hash = _j[0], ty = _j[1];
1937
+ var name_4 = "_".concat(hash, "_");
1938
+ fields[name_4] = getType(ty);
1939
+ }
1940
+ }
1941
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
1942
+ finally {
1943
+ try {
1944
+ if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
1945
+ }
1946
+ finally { if (e_8) throw e_8.error; }
1947
+ }
1948
+ return Variant(fields);
1949
+ }
1950
+ case -22 /* IDLTypeIds.Func */: {
1951
+ var _k = __read(entry[1], 3), args = _k[0], returnValues = _k[1], annotations = _k[2];
1952
+ return Func(args.map(function (t) { return getType(t); }), returnValues.map(function (t) { return getType(t); }), annotations);
1953
+ }
1954
+ case -23 /* IDLTypeIds.Service */: {
1955
+ var rec = {};
1956
+ var methods = entry[1];
1957
+ try {
1958
+ for (var methods_1 = __values(methods), methods_1_1 = methods_1.next(); !methods_1_1.done; methods_1_1 = methods_1.next()) {
1959
+ var _l = __read(methods_1_1.value, 2), name_5 = _l[0], typeRef = _l[1];
1960
+ var type = getType(typeRef);
1961
+ if (type instanceof RecClass) {
1962
+ // unpack reference type
1963
+ type = type.getType();
1964
+ }
1965
+ if (!(type instanceof FuncClass)) {
1966
+ throw new Error('Illegal service definition: services can only contain functions');
1967
+ }
1968
+ rec[name_5] = type;
1969
+ }
1970
+ }
1971
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
1972
+ finally {
1973
+ try {
1974
+ if (methods_1_1 && !methods_1_1.done && (_c = methods_1.return)) _c.call(methods_1);
1975
+ }
1976
+ finally { if (e_9) throw e_9.error; }
1977
+ }
1978
+ return Service(rec);
1979
+ }
1980
+ default:
1981
+ throw new Error('Illegal op_code: ' + entry[0]);
1982
+ }
1983
+ }
1984
+ rawTable.forEach(function (entry, i) {
1985
+ var t = buildType(entry);
1986
+ table[i].fill(t);
1987
+ });
1988
+ var types = rawTypes.map(function (t) { return getType(t); });
1989
+ var output = retTypes.map(function (t, i) {
1990
+ return t.decodeValue(b, types[i]);
1991
+ });
1992
+ // skip unused values
1993
+ for (var ind = retTypes.length; ind < types.length; ind++) {
1994
+ types[ind].decodeValue(b, types[ind]);
1995
+ }
1996
+ if (b.byteLength > 0) {
1997
+ throw new Error('decode: Left-over bytes');
1998
+ }
1999
+ return output;
2000
+ }
2001
+ exports.decode = decode;
2002
+ // Export Types instances.
2003
+ exports.Empty = new EmptyClass();
2004
+ exports.Reserved = new ReservedClass();
2005
+ /**
2006
+ * Client-only type for deserializing unknown data. Not supported by Candid, and its use is discouraged.
2007
+ */
2008
+ exports.Unknown = new UnknownClass();
2009
+ exports.Bool = new BoolClass();
2010
+ exports.Null = new NullClass();
2011
+ exports.Text = new TextClass();
2012
+ exports.Int = new IntClass();
2013
+ exports.Nat = new NatClass();
2014
+ exports.Float32 = new FloatClass(32);
2015
+ exports.Float64 = new FloatClass(64);
2016
+ exports.Int8 = new FixedIntClass(8);
2017
+ exports.Int16 = new FixedIntClass(16);
2018
+ exports.Int32 = new FixedIntClass(32);
2019
+ exports.Int64 = new FixedIntClass(64);
2020
+ exports.Nat8 = new FixedNatClass(8);
2021
+ exports.Nat16 = new FixedNatClass(16);
2022
+ exports.Nat32 = new FixedNatClass(32);
2023
+ exports.Nat64 = new FixedNatClass(64);
2024
+ exports.Principal = new PrincipalClass();
2025
+ /**
2026
+ *
2027
+ * @param types array of any types
2028
+ * @returns TupleClass from those types
2029
+ */
2030
+ function Tuple() {
2031
+ var types = [];
2032
+ for (var _i = 0; _i < arguments.length; _i++) {
2033
+ types[_i] = arguments[_i];
2034
+ }
2035
+ return new TupleClass(types);
2036
+ }
2037
+ exports.Tuple = Tuple;
2038
+ /**
2039
+ *
2040
+ * @param t IDL Type
2041
+ * @returns VecClass from that type
2042
+ */
2043
+ function Vec(t) {
2044
+ return new VecClass(t);
2045
+ }
2046
+ exports.Vec = Vec;
2047
+ /**
2048
+ *
2049
+ * @param t IDL Type
2050
+ * @returns OptClass of Type
2051
+ */
2052
+ function Opt(t) {
2053
+ return new OptClass(t);
2054
+ }
2055
+ exports.Opt = Opt;
2056
+ /**
2057
+ *
2058
+ * @param t Record of string and IDL Type
2059
+ * @returns RecordClass of string and Type
2060
+ */
2061
+ function Record(t) {
2062
+ return new RecordClass(t);
2063
+ }
2064
+ exports.Record = Record;
2065
+ /**
2066
+ *
2067
+ * @param fields Record of string and IDL Type
2068
+ * @returns VariantClass
2069
+ */
2070
+ function Variant(fields) {
2071
+ return new VariantClass(fields);
2072
+ }
2073
+ exports.Variant = Variant;
2074
+ /**
2075
+ *
2076
+ * @returns new RecClass
2077
+ */
2078
+ function Rec() {
2079
+ return new RecClass();
2080
+ }
2081
+ exports.Rec = Rec;
2082
+ /**
2083
+ *
2084
+ * @param args array of IDL Types
2085
+ * @param ret array of IDL Types
2086
+ * @param annotations array of strings, [] by default
2087
+ * @returns new FuncClass
2088
+ */
2089
+ function Func(args, ret, annotations) {
2090
+ if (annotations === void 0) { annotations = []; }
2091
+ return new FuncClass(args, ret, annotations);
2092
+ }
2093
+ exports.Func = Func;
2094
+ /**
2095
+ *
2096
+ * @param t Record of string and FuncClass
2097
+ * @returns ServiceClass
2098
+ */
2099
+ function Service(t) {
2100
+ return new ServiceClass(t);
2101
+ }
2102
+ exports.Service = Service;
2103
+ //# sourceMappingURL=idl.js.map