@dfinity/vetkeys
Version:
JavaScript and TypeScript library to use Internet Computer vetKeys
1,816 lines (1,814 loc) • 154 kB
JavaScript
var bn = (t) => {
throw TypeError(t);
};
var xn = (t, e, r) => e.has(t) || bn("Cannot " + r);
var A = (t, e, r) => (xn(t, e, "read from private field"), r ? r.call(t) : e.get(t)), ee = (t, e, r) => e.has(t) ? bn("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, r), Q = (t, e, r, n) => (xn(t, e, "write to private field"), n ? n.call(t, r) : e.set(t, r), r);
var _n = (t, e, r, n) => ({
set _(s) {
Q(t, e, s, r);
},
get _() {
return A(t, e, n);
}
});
import { s as Zs, h as Kr, b as D, c as ge, d as ye, e as Ws, u as Z, F as Yn, _ as Qs, f as Gn, w as Js, r as ei, g as Or, i as En, j as Ht, k as Br, l as vn, m as Ue, n as In, o as qt, p as ti, q as ri, t as ni, v as Oe, x as me, y as si } from "./index-DeK1G2V9.mjs";
var Tn;
(function(t) {
t[t.SysFatal = 1] = "SysFatal", t[t.SysTransient = 2] = "SysTransient", t[t.DestinationInvalid = 3] = "DestinationInvalid", t[t.CanisterReject = 4] = "CanisterReject", t[t.CanisterError = 5] = "CanisterError";
})(Tn || (Tn = {}));
var ot;
(function(t) {
t.Replied = "replied", t.Rejected = "rejected";
})(ot || (ot = {}));
function ii(t) {
return t != null && "reject_code" in t;
}
function oi(t) {
return t != null && "certificate" in t;
}
const Wt = "abcdefghijklmnopqrstuvwxyz234567", at = /* @__PURE__ */ Object.create(null);
for (let t = 0; t < Wt.length; t++)
at[Wt[t]] = t;
at[0] = at.o;
at[1] = at.i;
function ai(t) {
let e = 0, r = 0, n = "";
function s(i) {
return e < 0 ? r |= i >> -e : r = i << e & 248, e > 3 ? (e -= 8, 1) : (e < 4 && (n += Wt[r >> 3], e += 5), 0);
}
for (let i = 0; i < t.length; )
i += s(t[i]);
return n + (e < 0 ? Wt[r >> 3] : "");
}
function ci(t) {
let e = 0, r = 0;
const n = new Uint8Array(t.length * 4 / 3 | 0);
let s = 0;
function i(o) {
let c = at[o.toLowerCase()];
if (c === void 0)
throw new Error(`Invalid character: ${JSON.stringify(o)}`);
c <<= 3, r |= c >>> e, e += 5, e >= 8 && (n[s++] = r, e -= 8, e > 0 ? r = c << 5 - e & 255 : r = 0);
}
for (const o of t)
i(o);
return n.slice(0, s);
}
const ui = new Uint32Array([
0,
1996959894,
3993919788,
2567524794,
124634137,
1886057615,
3915621685,
2657392035,
249268274,
2044508324,
3772115230,
2547177864,
162941995,
2125561021,
3887607047,
2428444049,
498536548,
1789927666,
4089016648,
2227061214,
450548861,
1843258603,
4107580753,
2211677639,
325883990,
1684777152,
4251122042,
2321926636,
335633487,
1661365465,
4195302755,
2366115317,
997073096,
1281953886,
3579855332,
2724688242,
1006888145,
1258607687,
3524101629,
2768942443,
901097722,
1119000684,
3686517206,
2898065728,
853044451,
1172266101,
3705015759,
2882616665,
651767980,
1373503546,
3369554304,
3218104598,
565507253,
1454621731,
3485111705,
3099436303,
671266974,
1594198024,
3322730930,
2970347812,
795835527,
1483230225,
3244367275,
3060149565,
1994146192,
31158534,
2563907772,
4023717930,
1907459465,
112637215,
2680153253,
3904427059,
2013776290,
251722036,
2517215374,
3775830040,
2137656763,
141376813,
2439277719,
3865271297,
1802195444,
476864866,
2238001368,
4066508878,
1812370925,
453092731,
2181625025,
4111451223,
1706088902,
314042704,
2344532202,
4240017532,
1658658271,
366619977,
2362670323,
4224994405,
1303535960,
984961486,
2747007092,
3569037538,
1256170817,
1037604311,
2765210733,
3554079995,
1131014506,
879679996,
2909243462,
3663771856,
1141124467,
855842277,
2852801631,
3708648649,
1342533948,
654459306,
3188396048,
3373015174,
1466479909,
544179635,
3110523913,
3462522015,
1591671054,
702138776,
2966460450,
3352799412,
1504918807,
783551873,
3082640443,
3233442989,
3988292384,
2596254646,
62317068,
1957810842,
3939845945,
2647816111,
81470997,
1943803523,
3814918930,
2489596804,
225274430,
2053790376,
3826175755,
2466906013,
167816743,
2097651377,
4027552580,
2265490386,
503444072,
1762050814,
4150417245,
2154129355,
426522225,
1852507879,
4275313526,
2312317920,
282753626,
1742555852,
4189708143,
2394877945,
397917763,
1622183637,
3604390888,
2714866558,
953729732,
1340076626,
3518719985,
2797360999,
1068828381,
1219638859,
3624741850,
2936675148,
906185462,
1090812512,
3747672003,
2825379669,
829329135,
1181335161,
3412177804,
3160834842,
628085408,
1382605366,
3423369109,
3138078467,
570562233,
1426400815,
3317316542,
2998733608,
733239954,
1555261956,
3268935591,
3050360625,
752459403,
1541320221,
2607071920,
3965973030,
1969922972,
40735498,
2617837225,
3943577151,
1913087877,
83908371,
2512341634,
3803740692,
2075208622,
213261112,
2463272603,
3855990285,
2094854071,
198958881,
2262029012,
4057260610,
1759359992,
534414190,
2176718541,
4139329115,
1873836001,
414664567,
2282248934,
4279200368,
1711684554,
285281116,
2405801727,
4167216745,
1634467795,
376229701,
2685067896,
3608007406,
1308918612,
956543938,
2808555105,
3495958263,
1231636301,
1047427035,
2932959818,
3654703836,
1088359270,
936918e3,
2847714899,
3736837829,
1202900863,
817233897,
3183342108,
3401237130,
1404277552,
615818150,
3134207493,
3453421203,
1423857449,
601450431,
3009837614,
3294710456,
1567103746,
711928724,
3020668471,
3272380065,
1510334235,
755167117
]);
function fi(t) {
let e = -1;
for (let r = 0; r < t.length; r++) {
const s = (t[r] ^ e) & 255;
e = ui[s] ^ e >>> 8;
}
return (e ^ -1) >>> 0;
}
const Dt = "__principal__", di = 2, Cn = 4, li = "aaaaa-aa";
let $ = class Qe {
static anonymous() {
return new this(new Uint8Array([Cn]));
}
/**
* Utility method, returning the principal representing the management canister, decoded from the hex string `'aaaaa-aa'`
* @returns {Principal} principal of the management canister
*/
static managementCanister() {
return this.fromText(li);
}
static selfAuthenticating(e) {
const r = Zs(e);
return new this(new Uint8Array([...r, di]));
}
static from(e) {
if (typeof e == "string")
return Qe.fromText(e);
if (Object.getPrototypeOf(e) === Uint8Array.prototype)
return new Qe(e);
if (Qe.isPrincipal(e))
return new Qe(e._arr);
throw new Error(`Impossible to convert ${JSON.stringify(e)} to Principal.`);
}
static fromHex(e) {
return new this(Kr(e));
}
static fromText(e) {
let r = e;
if (e.includes(Dt)) {
const o = JSON.parse(e);
Dt in o && (r = o[Dt]);
}
const n = r.toLowerCase().replace(/-/g, "");
let s = ci(n);
s = s.slice(4, s.length);
const i = new this(s);
if (i.toText() !== r)
throw new Error(`Principal "${i.toText()}" does not have a valid checksum (original value "${r}" may not be a valid Principal ID).`);
return i;
}
static fromUint8Array(e) {
return new this(e);
}
static isPrincipal(e) {
return e instanceof Qe || typeof e == "object" && e !== null && "_isPrincipal" in e && e._isPrincipal === !0 && "_arr" in e && e._arr instanceof Uint8Array;
}
constructor(e) {
this._arr = e, this._isPrincipal = !0;
}
isAnonymous() {
return this._arr.byteLength === 1 && this._arr[0] === Cn;
}
toUint8Array() {
return this._arr;
}
toHex() {
return D(this._arr).toUpperCase();
}
toText() {
const e = new ArrayBuffer(4);
new DataView(e).setUint32(0, fi(this._arr));
const n = new Uint8Array(e), s = new Uint8Array([...n, ...this._arr]), o = ai(s).match(/.{1,5}/g);
if (!o)
throw new Error();
return o.join("-");
}
toString() {
return this.toText();
}
/**
* Serializes to JSON
* @returns {JsonnablePrincipal} a JSON object with a single key, {@link JSON_KEY_PRINCIPAL}, whose value is the principal as a string
*/
toJSON() {
return { [Dt]: this.toText() };
}
/**
* Utility method taking a Principal to compare against. Used for determining canister ranges in certificate verification
* @param {Principal} other - a {@link Principal} to compare
* @returns {'lt' | 'eq' | 'gt'} `'lt' | 'eq' | 'gt'` a string, representing less than, equal to, or greater than
*/
compareTo(e) {
for (let r = 0; r < Math.min(this._arr.length, e._arr.length); r++) {
if (this._arr[r] < e._arr[r])
return "lt";
if (this._arr[r] > e._arr[r])
return "gt";
}
return this._arr.length < e._arr.length ? "lt" : this._arr.length > e._arr.length ? "gt" : "eq";
}
/**
* Utility method checking whether a provided Principal is less than or equal to the current one using the {@link Principal.compareTo} method
* @param other a {@link Principal} to compare
* @returns {boolean} boolean
*/
ltEq(e) {
const r = this.compareTo(e);
return r == "lt" || r == "eq";
}
/**
* Utility method checking whether a provided Principal is greater than or equal to the current one using the {@link Principal.compareTo} method
* @param other a {@link Principal} to compare
* @returns {boolean} boolean
*/
gtEq(e) {
const r = this.compareTo(e);
return r == "gt" || r == "eq";
}
};
var Te;
(function(t) {
t.Trust = "Trust", t.Protocol = "Protocol", t.Reject = "Reject", t.Transport = "Transport", t.External = "External", t.Limit = "Limit", t.Input = "Input", t.Unknown = "Unknown";
})(Te || (Te = {}));
class I {
constructor(e = !1) {
this.isCertified = e;
}
toString() {
let e = this.toErrorMessage();
return this.requestContext && (e += `
Request context:
Request ID (hex): ${this.requestContext.requestId ? D(this.requestContext.requestId) : "undefined"}
Sender pubkey (hex): ${D(this.requestContext.senderPubKey)}
Sender signature (hex): ${D(this.requestContext.senderSignature)}
Ingress expiry: ${this.requestContext.ingressExpiry.toString()}`), this.callContext && (e += `
Call context:
Canister ID: ${this.callContext.canisterId.toText()}
Method name: ${this.callContext.methodName}
HTTP details: ${JSON.stringify(this.callContext.httpDetails, null, 2)}`), e;
}
}
class Ie extends Error {
get code() {
return this.cause.code;
}
set code(e) {
this.cause.code = e;
}
get kind() {
return this.cause.kind;
}
set kind(e) {
this.cause.kind = e;
}
/**
* Reads the `isCertified` property of the underlying error code.
* @returns `true` if the error is certified, `false` otherwise.
*/
get isCertified() {
return this.code.isCertified;
}
constructor(e, r) {
super(e.toString()), this.name = "AgentError", this.cause = { code: e, kind: r }, Object.setPrototypeOf(this, Ie.prototype);
}
hasCode(e) {
return this.code instanceof e;
}
toString() {
return `${this.name} (${this.kind}): ${this.message}`;
}
}
class Xe extends Ie {
static fromCode(e) {
return new this(e);
}
}
class ce extends Xe {
constructor(e) {
super(e, Te.Trust), this.name = "TrustError", Object.setPrototypeOf(this, ce.prototype);
}
}
class F extends Xe {
constructor(e) {
super(e, Te.Protocol), this.name = "ProtocolError", Object.setPrototypeOf(this, F.prototype);
}
}
class et extends Xe {
constructor(e) {
super(e, Te.Reject), this.name = "RejectError", Object.setPrototypeOf(this, et.prototype);
}
}
class Qt extends Xe {
constructor(e) {
super(e, Te.Transport), this.name = "TransportError", Object.setPrototypeOf(this, Qt.prototype);
}
}
class J extends Xe {
constructor(e) {
super(e, Te.External), this.name = "ExternalError", Object.setPrototypeOf(this, J.prototype);
}
}
class V extends Xe {
constructor(e) {
super(e, Te.Input), this.name = "InputError", Object.setPrototypeOf(this, V.prototype);
}
}
class ne extends Xe {
constructor(e) {
super(e, Te.Unknown), this.name = "UnknownError", Object.setPrototypeOf(this, ne.prototype);
}
}
class _t extends I {
constructor(e) {
super(), this.reason = e, this.name = "CertificateVerificationErrorCode", Object.setPrototypeOf(this, _t.prototype);
}
toErrorMessage() {
return `Certificate verification error: "${this.reason}"`;
}
}
class Jt extends I {
constructor(e, r, n, s) {
super(), this.maxAgeInMinutes = e, this.certificateTime = r, this.currentTime = n, this.ageType = s, this.name = "CertificateTimeErrorCode", Object.setPrototypeOf(this, Jt.prototype);
}
toErrorMessage() {
return `Certificate is signed more than ${this.maxAgeInMinutes} minutes in the ${this.ageType}. Certificate time: ${this.certificateTime.toISOString()} Current time: ${this.currentTime.toISOString()}`;
}
}
class zr extends I {
constructor() {
super(), this.name = "CertificateHasTooManyDelegationsErrorCode", Object.setPrototypeOf(this, zr.prototype);
}
toErrorMessage() {
return "Certificate has too many delegations";
}
}
class dr extends I {
constructor(e, r) {
super(), this.canisterId = e, this.subnetId = r, this.name = "CertificateNotAuthorizedErrorCode", Object.setPrototypeOf(this, dr.prototype);
}
toErrorMessage() {
return `The certificate contains a delegation that does not include the canister ${this.canisterId.toText()} in the canister_ranges field. Subnet ID: 0x${D(this.subnetId)}`;
}
}
class ct extends I {
constructor(e, r) {
super(), this.message = e, this.lookupStatus = r, this.name = "LookupErrorCode", Object.setPrototypeOf(this, ct.prototype);
}
toErrorMessage() {
return `${this.message}. Lookup status: ${this.lookupStatus}`;
}
}
class lr extends I {
constructor(e) {
super(), this.message = e, this.name = "MalformedLookupFoundValueErrorCode", Object.setPrototypeOf(this, lr.prototype);
}
toErrorMessage() {
return this.message;
}
}
class Hr extends I {
constructor(e) {
super(), this.message = e, this.name = "MissingLookupValueErrorCode", Object.setPrototypeOf(this, Hr.prototype);
}
toErrorMessage() {
return this.message;
}
}
class hr extends I {
constructor(e, r) {
super(), this.expectedLength = e, this.actualLength = r, this.name = "DerKeyLengthMismatchErrorCode", Object.setPrototypeOf(this, hr.prototype);
}
toErrorMessage() {
return `BLS DER-encoded public key must be ${this.expectedLength} bytes long, but is ${this.actualLength} bytes long`;
}
}
class Yr extends I {
constructor(e, r) {
super(), this.expectedPrefix = e, this.actualPrefix = r, this.name = "DerPrefixMismatchErrorCode", Object.setPrototypeOf(this, Yr.prototype);
}
toErrorMessage() {
return `BLS DER-encoded public key is invalid. Expected the following prefix: ${D(this.expectedPrefix)}, but got ${D(this.actualPrefix)}`;
}
}
class Gr extends I {
constructor(e, r) {
super(), this.expectedLength = e, this.actualLength = r, this.name = "DerDecodeLengthMismatchErrorCode", Object.setPrototypeOf(this, Gr.prototype);
}
toErrorMessage() {
return `DER payload mismatch: Expected length ${this.expectedLength}, actual length: ${this.actualLength}`;
}
}
class Ce extends I {
constructor(e) {
super(), this.error = e, this.name = "DerDecodeErrorCode", Object.setPrototypeOf(this, Ce.prototype);
}
toErrorMessage() {
return `Failed to decode DER: ${this.error}`;
}
}
class yr extends I {
constructor(e) {
super(), this.error = e, this.name = "DerEncodeErrorCode", Object.setPrototypeOf(this, yr.prototype);
}
toErrorMessage() {
return `Failed to encode DER: ${this.error}`;
}
}
class Xr extends I {
constructor(e, r) {
super(), this.error = e, this.input = r, this.name = "CborDecodeErrorCode", Object.setPrototypeOf(this, Xr.prototype);
}
toErrorMessage() {
return `Failed to decode CBOR: ${this.error}, input: ${D(this.input)}`;
}
}
class Zr extends I {
constructor(e, r) {
super(), this.error = e, this.value = r, this.name = "CborEncodeErrorCode", Object.setPrototypeOf(this, Zr.prototype);
}
toErrorMessage() {
return `Failed to encode CBOR: ${this.error}, input: ${this.value}`;
}
}
class Et extends I {
constructor(e, r, n) {
super(), this.message = e, this.requestId = r, this.status = n, this.name = "TimeoutWaitingForResponseErrorCode", Object.setPrototypeOf(this, Et.prototype);
}
toErrorMessage() {
let e = `${this.message}
`;
return this.requestId && (e += ` Request ID: ${D(this.requestId)}
`), this.status && (e += ` Request status: ${this.status}
`), e;
}
}
class Wr extends I {
constructor(e, r, n) {
super(), this.maxIngressExpiryInMinutes = e, this.requestId = r, this.retryTimes = n, this.name = "CertificateOutdatedErrorCode", Object.setPrototypeOf(this, Wr.prototype);
}
toErrorMessage() {
let e = `Certificate is stale (over ${this.maxIngressExpiryInMinutes} minutes). Is the computer's clock synchronized?
Request ID: ${D(this.requestId)}
`;
return this.retryTimes !== void 0 && (e += ` Retried ${this.retryTimes} times.`), e;
}
}
class vt extends I {
constructor(e, r, n, s) {
super(!0), this.requestId = e, this.rejectCode = r, this.rejectMessage = n, this.rejectErrorCode = s, this.name = "CertifiedRejectErrorCode", Object.setPrototypeOf(this, vt.prototype);
}
toErrorMessage() {
return `The replica returned a rejection error:
Request ID: ${D(this.requestId)}
Reject code: ${this.rejectCode}
Reject text: ${this.rejectMessage}
Error code: ${this.rejectErrorCode}
`;
}
}
class Qr extends I {
constructor(e, r, n, s, i) {
super(), this.requestId = e, this.rejectCode = r, this.rejectMessage = n, this.rejectErrorCode = s, this.signatures = i, this.name = "UncertifiedRejectErrorCode", Object.setPrototypeOf(this, Qr.prototype);
}
toErrorMessage() {
return `The replica returned a rejection error:
Request ID: ${D(this.requestId)}
Reject code: ${this.rejectCode}
Reject text: ${this.rejectMessage}
Error code: ${this.rejectErrorCode}
`;
}
}
class Jr extends I {
constructor(e) {
super(), this.requestId = e, this.name = "RequestStatusDoneNoReplyErrorCode", Object.setPrototypeOf(this, Jr.prototype);
}
toErrorMessage() {
return `Call was marked as done but we never saw the reply:
Request ID: ${D(this.requestId)}
`;
}
}
class Ke extends I {
constructor(e) {
super(), this.shouldFetchRootKey = e, this.name = "MissingRootKeyErrorCode", Object.setPrototypeOf(this, Ke.prototype);
}
toErrorMessage() {
return this.shouldFetchRootKey === void 0 ? "Agent is missing root key" : `Agent is missing root key and the shouldFetchRootKey value is set to ${this.shouldFetchRootKey}. The root key should only be unknown if you are in local development. Otherwise you should avoid fetching and use the default IC Root Key or the known root key of your environment.`;
}
}
class en extends I {
constructor(e) {
super(), this.value = e, this.name = "HashValueErrorCode", Object.setPrototypeOf(this, en.prototype);
}
toErrorMessage() {
return `Attempt to hash a value of unsupported type: ${this.value}`;
}
}
class bt extends I {
constructor(e) {
super(), this.error = e, this.name = "HttpDefaultFetchErrorCode", Object.setPrototypeOf(this, bt.prototype);
}
toErrorMessage() {
return this.error;
}
}
class Pe extends I {
constructor() {
super(), this.name = "IdentityInvalidErrorCode", Object.setPrototypeOf(this, Pe.prototype);
}
toErrorMessage() {
return "This identity has expired due this application's security policy. Please refresh your authentication.";
}
}
class Je extends I {
constructor(e, r) {
super(), this.message = e, this.providedIngressExpiryInMinutes = r, this.name = "IngressExpiryInvalidErrorCode", Object.setPrototypeOf(this, Je.prototype);
}
toErrorMessage() {
return `${this.message}. Provided ingress expiry time is ${this.providedIngressExpiryInMinutes} minutes.`;
}
}
class tn extends I {
constructor() {
super(), this.name = "CreateHttpAgentErrorCode", Object.setPrototypeOf(this, tn.prototype);
}
toErrorMessage() {
return "Failed to create agent from provided agent";
}
}
class rn extends I {
constructor(e) {
super(), this.error = e, this.name = "MalformedSignatureErrorCode", Object.setPrototypeOf(this, rn.prototype);
}
toErrorMessage() {
return `Query response contained a malformed signature: ${this.error}`;
}
}
class er extends I {
constructor() {
super(), this.name = "MissingSignatureErrorCode", Object.setPrototypeOf(this, er.prototype);
}
toErrorMessage() {
return "Query response did not contain any node signatures";
}
}
class nn extends I {
constructor() {
super(), this.name = "MalformedPublicKeyErrorCode", Object.setPrototypeOf(this, nn.prototype);
}
toErrorMessage() {
return "Read state response contained a malformed public key";
}
}
class sn extends I {
constructor(e) {
super(), this.nodeId = e, this.name = "QuerySignatureVerificationFailedErrorCode", Object.setPrototypeOf(this, sn.prototype);
}
toErrorMessage() {
return `Query signature verification failed. Node ID: ${this.nodeId}`;
}
}
class be extends I {
constructor(e) {
super(), this.error = e, this.name = "UnexpectedErrorCode", Object.setPrototypeOf(this, be.prototype);
}
toErrorMessage() {
return `Unexpected error: ${this.error}`;
}
}
class jt extends I {
constructor(e) {
super(), this.error = e, this.name = "HashTreeDecodeErrorCode", Object.setPrototypeOf(this, jt.prototype);
}
toErrorMessage() {
return `Failed to decode certificate: ${this.error}`;
}
}
class tr extends I {
constructor(e, r, n, s) {
super(), this.status = e, this.statusText = r, this.headers = n, this.bodyText = s, this.name = "HttpErrorCode", Object.setPrototypeOf(this, tr.prototype);
}
toErrorMessage() {
let e = `HTTP request failed:
Status: ${this.status} (${this.statusText})
Headers: ${JSON.stringify(this.headers)}
`;
return this.bodyText && (e += ` Body: ${this.bodyText}
`), e;
}
}
class rr extends I {
constructor() {
super(), this.name = "HttpV3ApiNotSupportedErrorCode", Object.setPrototypeOf(this, rr.prototype);
}
toErrorMessage() {
return "HTTP request failed: v3 API is not supported";
}
}
class nr extends I {
constructor(e) {
super(), this.error = e, this.name = "HttpFetchErrorCode", Object.setPrototypeOf(this, nr.prototype);
}
toErrorMessage() {
return `Failed to fetch HTTP request: ${this.error}`;
}
}
class sr extends I {
constructor(e) {
super(), this.receivedCanisterId = e, this.name = "MissingCanisterIdErrorCode", Object.setPrototypeOf(this, sr.prototype);
}
toErrorMessage() {
return `Canister ID is required, but received ${typeof this.receivedCanisterId} instead. If you are using automatically generated declarations, this may be because your application is not setting the canister ID in process.env correctly.`;
}
}
class on extends I {
constructor(e) {
super(), this.request = e, this.name = "InvalidReadStateRequestErrorCode", Object.setPrototypeOf(this, on.prototype);
}
toErrorMessage() {
return `Invalid read state request: ${this.request}`;
}
}
class ir extends I {
constructor(e) {
super(), this.error = e, this.name = "ExpiryJsonDeserializeErrorCode", Object.setPrototypeOf(this, ir.prototype);
}
toErrorMessage() {
return `Failed to deserialize expiry: ${this.error}`;
}
}
const tt = new Error("unreachable");
function R(...t) {
const e = new Uint8Array(t.reduce((n, s) => n + s.byteLength, 0));
let r = 0;
for (const n of t)
e.set(n, r), r += n.byteLength;
return e;
}
class dt {
/**
* Save a checkpoint of the reading view (for backtracking)
*/
save() {
return this._view;
}
/**
* Restore a checkpoint of the reading view (for backtracking)
* @param checkPoint a previously saved checkpoint
*/
restore(e) {
if (!(e instanceof Uint8Array))
throw new Error("Checkpoint must be a Uint8Array");
this._view = e;
}
/**
* Creates a new instance of a pipe
* @param buffer an optional buffer to start with
* @param length an optional amount of bytes to use for the length.
*/
constructor(e, r = e?.byteLength || 0) {
if (e && !(e instanceof Uint8Array))
try {
e = Xn(e);
} catch {
throw new Error("Buffer must be a Uint8Array");
}
if (r < 0 || !Number.isInteger(r))
throw new Error("Length must be a non-negative integer");
if (e && r > e.byteLength)
throw new Error("Length cannot exceed buffer length");
this._buffer = e || new Uint8Array(0), this._view = new Uint8Array(this._buffer.buffer, 0, r);
}
get buffer() {
return this._view.slice();
}
get byteLength() {
return this._view.byteLength;
}
/**
* Read `num` number of bytes from the front of the pipe.
* @param num The number of bytes to read.
*/
read(e) {
const r = this._view.subarray(0, e);
return this._view = this._view.subarray(e), r.slice();
}
readUint8() {
if (this._view.byteLength === 0)
return;
const e = this._view[0];
return this._view = this._view.subarray(1), e;
}
/**
* Write a buffer to the end of the pipe.
* @param buf The bytes to write.
*/
write(e) {
if (!(e instanceof Uint8Array))
throw new Error("Buffer must be a Uint8Array");
const r = this._view.byteLength;
this._view.byteOffset + this._view.byteLength + e.byteLength >= this._buffer.byteLength ? this.alloc(e.byteLength) : this._view = new Uint8Array(this._buffer.buffer, this._view.byteOffset, this._view.byteLength + e.byteLength), this._view.set(e, r);
}
/**
* Whether or not there is more data to read from the buffer
*/
get end() {
return this._view.byteLength === 0;
}
/**
* Allocate a fixed amount of memory in the buffer. This does not affect the view.
* @param amount A number of bytes to add to the buffer.
*/
alloc(e) {
if (e <= 0 || !Number.isInteger(e))
throw new Error("Amount must be a positive integer");
const r = new Uint8Array((this._buffer.byteLength + e) * 1.2 | 0), n = new Uint8Array(r.buffer, 0, this._view.byteLength + e);
n.set(this._view), this._buffer = r, this._view = n;
}
}
function Xn(t) {
if (!t)
throw new Error("Input cannot be null or undefined");
return t instanceof Uint8Array ? t : t instanceof ArrayBuffer ? new Uint8Array(t) : Array.isArray(t) ? new Uint8Array(t) : "buffer" in t ? Xn(t.buffer) : new Uint8Array(t);
}
function hi(t, e) {
if (t.byteLength !== e.byteLength)
return t.byteLength - e.byteLength;
for (let r = 0; r < t.length; r++)
if (t[r] !== e[r])
return t[r] - e[r];
return 0;
}
function yi(t) {
if (!(t instanceof Uint8Array))
throw new Error("Input must be a Uint8Array");
return new DataView(t.buffer, t.byteOffset, t.byteLength);
}
function pi(t) {
const r = new TextEncoder().encode(t);
let n = 0;
for (const s of r)
n = (n * 223 + s) % 2 ** 32;
return n;
}
function te(t) {
if (/^_\d+_$/.test(t) || /^_0x[0-9a-fA-F]+_$/.test(t)) {
const e = +t.slice(1, -1);
if (Number.isSafeInteger(e) && e >= 0 && e < 2 ** 32)
return e;
}
return pi(t);
}
function Zn(t) {
const e = BigInt(t);
if (t <= 0)
throw new RangeError("Input must be positive");
return e.toString(2).length - 1;
}
function Ur(t) {
const e = BigInt(t);
if (t < 0)
throw new RangeError("Input must be non-negative");
return BigInt(1) << e;
}
function Wn() {
throw new Error("unexpected end of buffer");
}
function ze(t, e) {
return t.byteLength < e && Wn(), t.read(e);
}
function He(t) {
const e = t.readUint8();
return e === void 0 && Wn(), e;
}
function M(t) {
if (typeof t == "number" && (t = BigInt(t)), t < BigInt(0))
throw new Error("Cannot leb encode negative values.");
const e = (t === BigInt(0) ? 0 : Zn(t)) + 1, r = new dt(new Uint8Array(e), 0);
for (; ; ) {
const n = Number(t & BigInt(127));
if (t /= BigInt(128), t === BigInt(0)) {
r.write(new Uint8Array([n]));
break;
} else
r.write(new Uint8Array([n | 128]));
}
return r.buffer;
}
function Y(t) {
let e = BigInt(1), r = BigInt(0), n;
do
n = He(t), r += BigInt(n & 127).valueOf() * e, e *= BigInt(128);
while (n >= 128);
return r;
}
function z(t) {
typeof t == "number" && (t = BigInt(t));
const e = t < BigInt(0);
e && (t = -t - BigInt(1));
const r = (t === BigInt(0) ? 0 : Zn(t)) + 1, n = new dt(new Uint8Array(r), 0);
for (; ; ) {
const i = s(t);
if (t /= BigInt(128), e && t === BigInt(0) && (i & 64) !== 0 || !e && t === BigInt(0) && (i & 64) === 0) {
n.write(new Uint8Array([i]));
break;
} else
n.write(new Uint8Array([i | 128]));
}
function s(i) {
const o = i % BigInt(128);
return Number(e ? BigInt(128) - o - BigInt(1) : o);
}
return n.buffer;
}
function Re(t) {
const e = new Uint8Array(t.buffer);
let r = 0;
for (; r < e.byteLength; r++)
if (e[r] < 128) {
if ((e[r] & 64) === 0)
return Y(t);
break;
}
const n = new Uint8Array(ze(t, r + 1));
let s = BigInt(0);
for (let i = n.byteLength - 1; i >= 0; i--)
s = s * BigInt(128) + BigInt(128 - (n[i] & 127) - 1);
return -s - BigInt(1);
}
function wi(t, e) {
if (BigInt(t) < BigInt(0))
throw new Error("Cannot write negative values.");
return Qn(t, e);
}
function Qn(t, e) {
t = BigInt(t);
const r = new dt(new Uint8Array(Math.min(1, e)), 0);
let n = 0, s = BigInt(256), i = BigInt(0), o = Number(t % s);
for (r.write(new Uint8Array([o])); ++n < e; )
t < 0 && i === BigInt(0) && o !== 0 && (i = BigInt(1)), o = Number((t / s - i) % BigInt(256)), r.write(new Uint8Array([o])), s *= BigInt(256);
return r.buffer;
}
function Jn(t, e) {
if (e <= 0 || !Number.isInteger(e))
throw new Error("Byte length must be a positive integer");
let r = BigInt(He(t)), n = BigInt(1), s = 0;
for (; ++s < e; ) {
n *= BigInt(256);
const i = BigInt(He(t));
r = r + n * i;
}
return r;
}
function gi(t, e) {
if (e <= 0 || !Number.isInteger(e))
throw new Error("Byte length must be a positive integer");
let r = Jn(t, e);
const n = BigInt(2) ** (BigInt(8) * BigInt(e - 1) + BigInt(7));
return r >= n && (r -= n * BigInt(2)), r;
}
var U;
(function(t) {
t[t.Null = -1] = "Null", t[t.Bool = -2] = "Bool", t[t.Nat = -3] = "Nat", t[t.Int = -4] = "Int", t[t.Float32 = -13] = "Float32", t[t.Float64 = -14] = "Float64", t[t.Text = -15] = "Text", t[t.Reserved = -16] = "Reserved", t[t.Empty = -17] = "Empty", t[t.Opt = -18] = "Opt", t[t.Vector = -19] = "Vector", t[t.Record = -20] = "Record", t[t.Variant = -21] = "Variant", t[t.Func = -22] = "Func", t[t.Service = -23] = "Service", t[t.Principal = -24] = "Principal";
})(U || (U = {}));
const Yt = "DIDL", An = 400;
function It(t, e, r) {
return t.map((n, s) => r(n, e[s]));
}
class mi {
constructor() {
this._typs = [], this._idx = /* @__PURE__ */ new Map();
}
has(e) {
return this._idx.has(e.name);
}
add(e, r) {
const n = this._typs.length;
this._idx.set(e.name, n), this._typs.push(r);
}
merge(e, r) {
const n = this._idx.get(e.name), s = this._idx.get(r);
if (n === void 0)
throw new Error("Missing type index for " + e);
if (s === void 0)
throw new Error("Missing type index for " + r);
this._typs[n] = this._typs[s], this._typs.splice(s, 1), this._idx.delete(r);
}
encode() {
const e = M(this._typs.length), r = R(...this._typs);
return R(e, r);
}
indexOf(e) {
if (!this._idx.has(e))
throw new Error("Missing type index for " + e);
return z(this._idx.get(e) || 0);
}
}
class bi {
visitType(e, r) {
throw new Error("Not implemented");
}
visitPrimitive(e, r) {
return this.visitType(e, r);
}
visitEmpty(e, r) {
return this.visitPrimitive(e, r);
}
visitBool(e, r) {
return this.visitPrimitive(e, r);
}
visitNull(e, r) {
return this.visitPrimitive(e, r);
}
visitReserved(e, r) {
return this.visitPrimitive(e, r);
}
visitText(e, r) {
return this.visitPrimitive(e, r);
}
visitNumber(e, r) {
return this.visitPrimitive(e, r);
}
visitInt(e, r) {
return this.visitNumber(e, r);
}
visitNat(e, r) {
return this.visitNumber(e, r);
}
visitFloat(e, r) {
return this.visitPrimitive(e, r);
}
visitFixedInt(e, r) {
return this.visitNumber(e, r);
}
visitFixedNat(e, r) {
return this.visitNumber(e, r);
}
visitPrincipal(e, r) {
return this.visitPrimitive(e, r);
}
visitConstruct(e, r) {
return this.visitType(e, r);
}
visitVec(e, r, n) {
return this.visitConstruct(e, n);
}
visitOpt(e, r, n) {
return this.visitConstruct(e, n);
}
visitRecord(e, r, n) {
return this.visitConstruct(e, n);
}
visitTuple(e, r, n) {
const s = r.map((i, o) => [`_${o}_`, i]);
return this.visitRecord(e, s, n);
}
visitVariant(e, r, n) {
return this.visitConstruct(e, n);
}
visitRec(e, r, n) {
return this.visitConstruct(r, n);
}
visitFunc(e, r) {
return this.visitConstruct(e, r);
}
visitService(e, r) {
return this.visitConstruct(e, r);
}
}
var _;
(function(t) {
t.EmptyClass = "__IDL_EmptyClass__", t.UnknownClass = "__IDL_UnknownClass__", t.BoolClass = "__IDL_BoolClass__", t.NullClass = "__IDL_NullClass__", t.ReservedClass = "__IDL_ReservedClass__", t.TextClass = "__IDL_TextClass__", t.IntClass = "__IDL_IntClass__", t.NatClass = "__IDL_NatClass__", t.FloatClass = "__IDL_FloatClass__", t.FixedIntClass = "__IDL_FixedIntClass__", t.FixedNatClass = "__IDL_FixedNatClass__", t.VecClass = "__IDL_VecClass__", t.OptClass = "__IDL_OptClass__", t.RecordClass = "__IDL_RecordClass__", t.TupleClass = "__IDL_TupleClass__", t.VariantClass = "__IDL_VariantClass__", t.RecClass = "__IDL_RecClass__", t.PrincipalClass = "__IDL_PrincipalClass__", t.FuncClass = "__IDL_FuncClass__", t.ServiceClass = "__IDL_ServiceClass__";
})(_ || (_ = {}));
class pr {
/* Display type name */
display() {
return this.name;
}
valueToString(e) {
return q(e);
}
/* Implement `T` in the IDL spec, only needed for non-primitive types */
buildTypeTable(e) {
e.has(this) || this._buildTypeTableImpl(e);
}
}
class fe extends pr {
checkType(e) {
if (this.name !== e.name)
throw new Error(`type mismatch: type on the wire ${e.name}, expect type ${this.name}`);
return e;
}
_buildTypeTableImpl(e) {
}
}
class ke extends pr {
checkType(e) {
if (e instanceof ue) {
const r = e.getType();
if (typeof r > "u")
throw new Error("type mismatch with uninitialized type");
return r;
}
throw new Error(`type mismatch: type on the wire ${e.name}, expect type ${this.name}`);
}
encodeType(e) {
return e.indexOf(this.name);
}
}
class an extends fe {
get typeName() {
return _.EmptyClass;
}
static [Symbol.hasInstance](e) {
return e.typeName === _.EmptyClass;
}
accept(e, r) {
return e.visitEmpty(this, r);
}
covariant(e) {
throw new Error(`Invalid ${this.display()} argument: ${q(e)}`);
}
encodeValue() {
throw new Error("Empty cannot appear as a function argument");
}
valueToString() {
throw new Error("Empty cannot appear as a value");
}
encodeType() {
return z(U.Empty);
}
decodeValue() {
throw new Error("Empty cannot appear as an output");
}
get name() {
return "empty";
}
}
class es extends pr {
get typeName() {
return _.UnknownClass;
}
static [Symbol.hasInstance](e) {
return e.typeName === _.UnknownClass;
}
checkType(e) {
throw new Error("Method not implemented for unknown.");
}
accept(e, r) {
throw e.visitType(this, r);
}
covariant(e) {
throw new Error(`Invalid ${this.display()} argument: ${q(e)}`);
}
encodeValue() {
throw new Error("Unknown cannot appear as a function argument");
}
valueToString() {
throw new Error("Unknown cannot appear as a value");
}
encodeType() {
throw new Error("Unknown cannot be serialized");
}
decodeValue(e, r) {
let n = r.decodeValue(e, r);
Object(n) !== n && (n = Object(n));
let s;
return r instanceof ue ? s = () => r.getType() : s = () => r, Object.defineProperty(n, "type", {
value: s,
writable: !0,
enumerable: !1,
configurable: !0
}), n;
}
_buildTypeTableImpl() {
throw new Error("Unknown cannot be serialized");
}
get name() {
return "Unknown";
}
}
class ts extends fe {
get typeName() {
return _.BoolClass;
}
static [Symbol.hasInstance](e) {
return e.typeName === _.BoolClass;
}
accept(e, r) {
return e.visitBool(this, r);
}
covariant(e) {
if (typeof e == "boolean")
return !0;
throw new Error(`Invalid ${this.display()} argument: ${q(e)}`);
}
encodeValue(e) {
return new Uint8Array([e ? 1 : 0]);
}
encodeType() {
return z(U.Bool);
}
decodeValue(e, r) {
switch (this.checkType(r), He(e)) {
case 0:
return !1;
case 1:
return !0;
default:
throw new Error("Boolean value out of range");
}
}
get name() {
return "bool";
}
}
class Tt extends fe {
get typeName() {
return _.NullClass;
}
static [Symbol.hasInstance](e) {
return e.typeName === _.NullClass;
}
accept(e, r) {
return e.visitNull(this, r);
}
covariant(e) {
if (e === null)
return !0;
throw new Error(`Invalid ${this.display()} argument: ${q(e)}`);
}
encodeValue() {
return new Uint8Array(0);
}
encodeType() {
return z(U.Null);
}
decodeValue(e, r) {
return this.checkType(r), null;
}
get name() {
return "null";
}
}
class Ne extends fe {
get typeName() {
return _.ReservedClass;
}
static [Symbol.hasInstance](e) {
return e.typeName === _.ReservedClass;
}
accept(e, r) {
return e.visitReserved(this, r);
}
covariant(e) {
return !0;
}
encodeValue() {
return new Uint8Array(0);
}
encodeType() {
return z(U.Reserved);
}
decodeValue(e, r) {
return r.name !== this.name && r.decodeValue(e, r), null;
}
get name() {
return "reserved";
}
}
class rs extends fe {
get typeName() {
return _.TextClass;
}
static [Symbol.hasInstance](e) {
return e.typeName === _.TextClass;
}
accept(e, r) {
return e.visitText(this, r);
}
covariant(e) {
if (typeof e == "string")
return !0;
throw new Error(`Invalid ${this.display()} argument: ${q(e)}`);
}
encodeValue(e) {
const r = new TextEncoder().encode(e), n = M(r.byteLength);
return R(n, r);
}
encodeType() {
return z(U.Text);
}
decodeValue(e, r) {
this.checkType(r);
const n = Y(e), s = ze(e, Number(n));
return new TextDecoder("utf8", { fatal: !0 }).decode(s);
}
get name() {
return "text";
}
valueToString(e) {
return '"' + e + '"';
}
}
class cn extends fe {
get typeName() {
return _.IntClass;
}
static [Symbol.hasInstance](e) {
return e.typeName === _.IntClass;
}
accept(e, r) {
return e.visitInt(this, r);
}
covariant(e) {
if (typeof e == "bigint" || Number.isInteger(e))
return !0;
throw new Error(`Invalid ${this.display()} argument: ${q(e)}`);
}
encodeValue(e) {
return z(e);
}
encodeType() {
return z(U.Int);
}
decodeValue(e, r) {
return this.checkType(r), Re(e);
}
get name() {
return "int";
}
valueToString(e) {
return e.toString();
}
}
class un extends fe {
get typeName() {
return _.NatClass;
}
static [Symbol.hasInstance](e) {
return e.typeName === _.NatClass;
}
accept(e, r) {
return e.visitNat(this, r);
}
covariant(e) {
if (typeof e == "bigint" && e >= BigInt(0) || Number.isInteger(e) && e >= 0)
return !0;
throw new Error(`Invalid ${this.display()} argument: ${q(e)}`);
}
encodeValue(e) {
return M(e);
}
encodeType() {
return z(U.Nat);
}
decodeValue(e, r) {
return this.checkType(r), Y(e);
}
get name() {
return "nat";
}
valueToString(e) {
return e.toString();
}
}
class fn extends fe {
get typeName() {
return _.FloatClass;
}
static [Symbol.hasInstance](e) {
return e.typeName === _.FloatClass;
}
constructor(e) {
if (super(), this._bits = e, e !== 32 && e !== 64)
throw new Error("not a valid float type");
}
accept(e, r) {
return e.visitFloat(this, r);
}
covariant(e) {
if (typeof e == "number" || e instanceof Number)
return !0;
throw new Error(`Invalid ${this.display()} argument: ${q(e)}`);
}
encodeValue(e) {
const r = new ArrayBuffer(this._bits / 8), n = new DataView(r);
return this._bits === 32 ? n.setFloat32(0, e, !0) : n.setFloat64(0, e, !0), new Uint8Array(r);
}
encodeType() {
const e = this._bits === 32 ? U.Float32 : U.Float64;
return z(e);
}
decodeValue(e, r) {
this.checkType(r);
const n = ze(e, this._bits / 8), s = yi(n);
return this._bits === 32 ? s.getFloat32(0, !0) : s.getFloat64(0, !0);
}
get name() {
return "float" + this._bits;
}
valueToString(e) {
return e.toString();
}
}
class Ye extends fe {
get typeName() {
return _.FixedIntClass;
}
static [Symbol.hasInstance](e) {
return e.typeName === _.FixedIntClass;
}
constructor(e) {
super(), this._bits = e;
}
accept(e, r) {
return e.visitFixedInt(this, r);
}
covariant(e) {
const r = Ur(this._bits - 1) * BigInt(-1), n = Ur(this._bits - 1) - BigInt(1);
let s = !1;
if (typeof e == "bigint")
s = e >= r && e <= n;
else if (Number.isInteger(e)) {
const i = BigInt(e);
s = i >= r && i <= n;
} else
s = !1;
if (s)
return !0;
throw new Error(`Invalid ${this.display()} argument: ${q(e)}`);
}
encodeValue(e) {
return Qn(e, this._bits / 8);
}
encodeType() {
const e = Math.log2(this._bits) - 3;
return z(-9 - e);
}
decodeValue(e, r) {
this.checkType(r);
const n = gi(e, this._bits / 8);
return this._bits <= 32 ? Number(n) : n;
}
get name() {
return `int${this._bits}`;
}
valueToString(e) {
return e.toString();
}
}
class $e extends fe {
get typeName() {
return _.FixedNatClass;
}
static [Symbol.hasInstance](e) {
return e.typeName === _.FixedNatClass;
}
constructor(e) {
super(), this._bits = e;
}
accept(e, r) {
return e.visitFixedNat(this, r);
}
covariant(e) {
const r = Ur(this._bits);
let n = !1;
if (typeof e == "bigint" && e >= BigInt(0) ? n = e < r : Number.isInteger(e) && e >= 0 ? n = BigInt(e) < r : n = !1, n)
return !0;
throw new Error(`Invalid ${this.display()} argument: ${q(e)}`);
}
encodeValue(e) {
return wi(e, this._bits / 8);
}
encodeType() {
const e = Math.log2(this._bits) - 3;
return z(-5 - e);
}
decodeValue(e, r) {
this.checkType(r);
const n = Jn(e, this._bits / 8);
return this._bits <= 32 ? Number(n) : n;
}
get name() {
return `nat${this._bits}`;
}
valueToString(e) {
return e.toString();
}
}
class ut extends ke {
get typeName() {
return _.VecClass;
}
static [Symbol.hasInstance](e) {
return e.typeName === _.VecClass;
}
constructor(e) {
super(), this._type = e, this._blobOptimization = !1, e instanceof $e && e._bits === 8 && (this._blobOptimization = !0);
}
accept(e, r) {
return e.visitVec(this, this._type, r);
}
covariant(e) {
const r = this._type instanceof $e ? this._type._bits : this._type instanceof Ye ? this._type._bits : 0;
if (ArrayBuffer.isView(e) && r == e.BYTES_PER_ELEMENT * 8 || Array.isArray(e) && e.every((n, s) => {
try {
return this._type.covariant(n);
} catch (i) {
throw new Error(`Invalid ${this.display()} argument:
index ${s} -> ${i.message}`);
}
}))
return !0;
throw new Error(`Invalid ${this.display()} argument: ${q(e)}`);
}
encodeValue(e) {
const r = M(e.length);
if (this._blobOptimization)
return R(r, new Uint8Array(e));
if (ArrayBuffer.isView(e))
if (e instanceof Int16Array || e instanceof Uint16Array) {
const s = new DataView(new ArrayBuffer(e.length * 2));
for (let i = 0; i < e.length; i++)
e instanceof Int16Array ? s.setInt16(i * 2, e[i], !0) : s.setUint16(i * 2, e[i], !0);
return R(r, new Uint8Array(s.buffer));
} else if (e instanceof Int32Array || e instanceof Uint32Array) {
const s = new DataView(new ArrayBuffer(e.length * 4));
for (let i = 0; i < e.length; i++)
e instanceof Int32Array ? s.setInt32(i * 4, e[i], !0) : s.setUint32(i * 4, e[i], !0);
return R(r, new Uint8Array(s.buffer));
} else if (e instanceof BigInt64Array || e instanceof BigUint64Array) {
const s = new DataView(new ArrayBuffer(e.length * 8));
for (let i = 0; i < e.length; i++)
e instanceof BigInt64Array ? s.setBigInt64(i * 8, e[i], !0) : s.setBigUint64(i * 8, e[i], !0);
return R(r, new Uint8Array(s.buffer));
} else
return R(r, new Uint8Array(e.buffer, e.byteOffset, e.byteLength));
const n = new dt(new Uint8Array(r.byteLength + e.length), 0);
n.write(r);
for (const s of e) {
const i = this._type.encodeValue(s);
n.write(new Uint8Array(i));
}
return n.buffer;
}
_buildTypeTableImpl(e) {
this._type.buildTypeTable(e);
const r = z(U.Vector), n = this._type.encodeType(e);
e.add(this, R(r, n));
}
decodeValue(e, r) {
const n = this.checkType(r);
if (!(n instanceof ut))
throw new Error("Not a vector type");
const s = Number(Y(e));
if (this._type instanceof $e) {
if (this._type._bits == 8)
return new Uint8Array(e.read(s));
if (this._type._bits == 16) {
const o = e.read(s * 2);
return new Uint16Array(o.buffer, o.byteOffset, s);
}
if (this._type._bits == 32) {
const o = e.read(s * 4);
return new Uint32Array(o.buffer, o.byteOffset, s);
}
if (this._type._bits == 64)
return new BigUint64Array(e.read(s * 8).buffer);
}
if (this._type instanceof Ye) {
if (this._type._bits == 8)
return new Int8Array(e.read(s));
if (this._type._bits == 16) {
const o = e.read(s * 2), c = new DataView(o.buffer, o.byteOffset, o.byteLength), a = new Int16Array(s);
for (let d = 0; d < s; d++)
a[d] = c.getInt16(d * 2, !0);
return a;
}
if (this._type._bits == 32) {
const o = e.read(s * 4), c = new DataView(o.buffer, o.byteOffset, o.byteLength), a = new Int32Array(s);
for (let d = 0; d < s; d++)
a[d] = c.getInt32(d * 4, !0);
return a;
}
if (this._type._bits == 64) {
const o = e.read(s * 8), c = new DataView(o.buffer, o.byteOffset, o.byteLength), a = new BigInt64Array(s);
for (let d = 0; d < s; d++)
a[d] = c.getBigInt64(d * 8, !0);
return a;
}
}
const i = [];
for (let o = 0; o < s; o++)
i.push(this._type.decodeValue(e, n._type));
return i;
}
get name() {
return `vec ${this._type.name}`;
}
display() {
return `vec ${this._type.display()}`;
}
valueToString(e) {
return "vec {" + e.map((n) => this._type.valueToString(n)).join("; ") + "}";
}
}
class Ae extends ke {
get typeName() {
return _.OptClass;
}
static [Symbol.hasInstance](e) {
return e.typeName === _.OptClass;
}
constructor(e) {
super(), this._type = e;
}
accept(e, r) {
return e.visitOpt(this, this._type, r);
}
covariant(e) {
try {
if (Array.isArray(e) && (e.length === 0 || e.length === 1 && this._type.covariant(e[0])))
return !0;
} catch (r) {
throw new Error(`Invalid ${this.display()} argument: ${q(e)}
-> ${r.message}`);
}
throw new Error(`Invalid ${this.display()} argument: ${q(e)}`);
}
encodeValue(e) {
return e.length === 0 ? new Uint8Array([0]) : R(new Uint8Array([1]), this._type.encodeValue(e[0]));
}
_buildTypeTableImpl(e) {
this._type.buildTypeTable(e);
const r = z(U.Opt), n = this._type.encodeType(e);
e.add(this, R(r, n));
}
decodeValue(e, r) {
if (r instanceof Tt)
return [];
if (r instanceof Ne)
return [];
let n = r;
if (r instanceof ue) {
const s = r.getType();
if (typeof s > "u")
throw new Error("type mismatch with uninitialized type");
n = s;
}
if (n instanceof Ae)
switch (He(e)) {
case 0:
return [];
case 1: {
const s = e.save();
try {
return [this._type.decodeValue(e, n._type)];
} catch {
return e.restore(s), n._type.decodeValue(e, n._type), [];
}
}
default:
throw new Error("Not an option value");
}
else {
if (
// this check corresponds to `not (null <: <t>)` in the spec
this._type instanceof Tt || this._type instanceof Ae || this._type instanceof Ne
)
return n.decodeValue(e, n), [];
{
const s = e.save();
try {
return [this._type.decodeValue(e, r)];
} catch {
return e.restore(s), n.decodeValue(e, r), [];
}
}
}
}
get name() {
return `opt ${this._type.name}`;
}
display() {
return `opt ${this._type.display()}`;
}
valueToString(e) {
return e.length === 0 ? "null" : `opt ${this._type.valueToString(e[0])}`;
}
}
class Ge extends ke {
get typeName() {
return _.RecordClass;
}
static [Symbol.hasInstance](e) {
return e.typeName === _.RecordClass || e.typeName === _.TupleClass;
}
constructor(e =