@junobuild/utils 1.0.1 → 1.0.2-next-2026-04-11
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.
package/dist/browser/index.js
CHANGED
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
var L=class extends Error{},C=class extends Error{},U=(e,t)=>{if(e==null)throw new C(t)},ut=(e,t)=>(U(e,t),e),lt=e=>{if(e<0||e>100)throw new L(`${e} is not a valid percentage number.`)},pt=(e,t)=>{throw new Error(t)};var mt=e=>{let t=new DataView(e.buffer,e.byteOffset,e.byteLength);if(typeof t.getBigUint64=="function")return t.getBigUint64(0);let r=BigInt(t.getUint32(0)),n=BigInt(t.getUint32(4));return(r<<BigInt(32))+n},At=e=>{let t=new ArrayBuffer(8),r=new DataView(t);if(typeof r.setBigUint64=="function")r.setBigUint64(0,e);else{let n=Number(e>>BigInt(32)),o=Number(e&BigInt(4294967295));r.setUint32(0,n),r.setUint32(4,o)}return new Uint8Array(t)},wt=e=>{let t=new DataView(new ArrayBuffer(8));for(let r=7;r>=0;--r)t.setUint8(r,e%256),e=e>>8;return new Uint8Array(t.buffer)},Ut=e=>new Uint8Array(e),Tt=e=>Array.from(e),_t=e=>new Uint8Array(e),Bt=e=>Array.from(e).map(t=>t.charCodeAt(0)),Nt=e=>{let t=e.match(/.{1,2}/g);return U(t,"Invalid hex string."),Uint8Array.from(t.map(r=>parseInt(r,16)))},St=({a:e,b:t})=>e.length===t.length&&e.every((r,n)=>r===t[n]),Ht=e=>(e instanceof Uint8Array||(e=Uint8Array.from(e)),e.reduce((t,r)=>t+r.toString(16).padStart(2,"0"),"")),Et=e=>{let t=0n;for(let r=e.length-1;r>=0;r--)t=(t<<32n)+BigInt(e[r]);return t};var Lt=e=>{let r=[];for(let n=0;n<e.length;n+=32768)r.push(String.fromCharCode(...e.subarray(n,n+32768)));return btoa(r.join(""))},Ct=e=>Uint8Array.from(atob(e),t=>t.charCodeAt(0));var R=1000000n,kt=()=>BigInt(Date.now())*R,Ft=e=>BigInt(e.getTime())*R;var Gt=(e,t)=>{let r;return(...n)=>{let o=()=>e(...n);r&&clearTimeout(r),r=setTimeout(o,t!==void 0&&t>0?t:300)}};var ot=e=>e==null,d=e=>!ot(e),it=e=>d(e)&&e!=="",jt=e=>!it(e);var Mt=e=>d(e)?[e]:[],J=e=>e?.[0],Wt=e=>{let t=J(e);return U(t),t},Kt=e=>J(e??[]);var B="abcdefghijklmnopqrstuvwxyz234567",m=Object.create(null);for(let e=0;e<B.length;e++)m[B[e]]=e;m[0]=m.o;m[1]=m.i;function M(e){let t=0,r=0,n="";function o(i){return t<0?r|=i>>-t:r=i<<t&248,t>3?(t-=8,1):(t<4&&(n+=B[r>>3],t+=5),0)}for(let i=0;i<e.length;)i+=o(e[i]);return n+(t<0?B[r>>3]:"")}function W(e){let t=0,r=0,n=new Uint8Array(e.length*4/3|0),o=0;function i(s){let c=m[s.toLowerCase()];if(c===void 0)throw new Error(`Invalid character: ${JSON.stringify(s)}`);c<<=3,r|=c>>>t,t+=5,t>=8&&(n[o++]=r,t-=8,t>0?r=c<<5-t&255:r=0)}for(let s of e)i(s);return n.slice(0,o)}var st=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 K(e){let t=-1;for(let r=0;r<e.length;r++){let o=(e[r]^t)&255;t=st[o]^t>>>8}return(t^-1)>>>0}function ct(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function T(e,...t){if(!ct(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function D(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function $(e,t){T(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function _(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function S(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function b(e,t){return e<<32-t|e>>>t}var z=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",xt=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Y(e){if(T(e),z)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=xt[e[r]];return t}var h={_0:48,_9:57,A:65,F:70,a:97,f:102};function q(e){if(e>=h._0&&e<=h._9)return e-h._0;if(e>=h.A&&e<=h.F)return e-(h.A-10);if(e>=h.a&&e<=h.f)return e-(h.a-10)}function X(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(z)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,i=0;o<r;o++,i+=2){let s=q(e.charCodeAt(i)),c=q(e.charCodeAt(i+1));if(s===void 0||c===void 0){let a=e[i]+e[i+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+i)}n[o]=s*16+c}return n}function at(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function k(e){return typeof e=="string"&&(e=at(e)),T(e),e}var N=class{};function Z(e){let t=n=>e().update(k(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function ft(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),i=BigInt(4294967295),s=Number(r>>o&i),c=Number(r&i),a=n?4:0,f=n?0:4;e.setUint32(t+a,s,n),e.setUint32(t+f,c,n)}function v(e,t,r){return e&t^~e&r}function Q(e,t,r){return e&t^e&r^t&r}var H=class extends N{constructor(t,r,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=S(this.buffer)}update(t){D(this),t=k(t),T(t);let{view:r,buffer:n,blockLen:o}=this,i=t.length;for(let s=0;s<i;){let c=Math.min(o-this.pos,i-s);if(c===o){let a=S(t);for(;o<=i-s;s+=o)this.process(a,s);continue}n.set(t.subarray(s,s+c),this.pos),this.pos+=c,s+=c,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){D(this),$(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;r[s++]=128,_(this.buffer.subarray(s)),this.padOffset>o-s&&(this.process(n,0),s=0);for(let x=s;x<o;x++)r[x]=0;ft(n,o-8,BigInt(this.length*8),i),this.process(n,0);let c=S(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=a/4,p=this.get();if(f>p.length)throw new Error("_sha2: outputLen bigger than state");for(let x=0;x<f;x++)c.setUint32(4*x,p[x],i)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:i,destroyed:s,pos:c}=this;return t.destroyed=s,t.finished=i,t.length=o,t.pos=c,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},u=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),l=Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]);var bt=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),g=new Uint32Array(64),F=class extends H{constructor(t=32){super(64,t,8,!1),this.A=u[0]|0,this.B=u[1]|0,this.C=u[2]|0,this.D=u[3]|0,this.E=u[4]|0,this.F=u[5]|0,this.G=u[6]|0,this.H=u[7]|0}get(){let{A:t,B:r,C:n,D:o,E:i,F:s,G:c,H:a}=this;return[t,r,n,o,i,s,c,a]}set(t,r,n,o,i,s,c,a){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=c|0,this.H=a|0}process(t,r){for(let x=0;x<16;x++,r+=4)g[x]=t.getUint32(r,!1);for(let x=16;x<64;x++){let w=g[x-15],y=g[x-2],P=b(w,7)^b(w,18)^w>>>3,I=b(y,17)^b(y,19)^y>>>10;g[x]=I+g[x-7]+P+g[x-16]|0}let{A:n,B:o,C:i,D:s,E:c,F:a,G:f,H:p}=this;for(let x=0;x<64;x++){let w=b(c,6)^b(c,11)^b(c,25),y=p+w+v(c,a,f)+bt[x]+g[x]|0,I=(b(n,2)^b(n,13)^b(n,22))+Q(n,o,i)|0;p=f,f=a,a=c,c=s+y|0,s=i,i=o,o=n,n=y+I|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,c=c+this.E|0,a=a+this.F|0,f=f+this.G|0,p=p+this.H|0,this.set(n,o,i,s,c,a,f,p)}roundClean(){_(g)}destroy(){this.set(0,0,0,0,0,0,0,0),_(this.buffer)}},O=class extends F{constructor(){super(28),this.A=l[0]|0,this.B=l[1]|0,this.C=l[2]|0,this.D=l[3]|0,this.E=l[4]|0,this.F=l[5]|0,this.G=l[6]|0,this.H=l[7]|0}};var tt=Z(()=>new O);var E="__principal__",dt=2,et=4,ht="aaaaa-aa",A=class e{static anonymous(){return new this(new Uint8Array([et]))}static managementCanister(){return this.fromText(ht)}static selfAuthenticating(t){let r=tt(t);return new this(new Uint8Array([...r,dt]))}static from(t){if(typeof t=="string")return e.fromText(t);if(Object.getPrototypeOf(t)===Uint8Array.prototype)return new e(t);if(e.isPrincipal(t))return new e(t._arr);throw new Error(`Impossible to convert ${JSON.stringify(t)} to Principal.`)}static fromHex(t){return new this(X(t))}static fromText(t){let r=t;if(t.includes(E)){let s=JSON.parse(t);E in s&&(r=s[E])}let n=r.toLowerCase().replace(/-/g,""),o=W(n);o=o.slice(4,o.length);let i=new this(o);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(t){return new this(t)}static isPrincipal(t){return t instanceof e||typeof t=="object"&&t!==null&&"_isPrincipal"in t&&t._isPrincipal===!0&&"_arr"in t&&t._arr instanceof Uint8Array}constructor(t){this._arr=t,this._isPrincipal=!0}isAnonymous(){return this._arr.byteLength===1&&this._arr[0]===et}toUint8Array(){return this._arr}toHex(){return Y(this._arr).toUpperCase()}toText(){let t=new ArrayBuffer(4);new DataView(t).setUint32(0,K(this._arr));let n=new Uint8Array(t),o=new Uint8Array([...n,...this._arr]),s=M(o).match(/.{1,5}/g);if(!s)throw new Error;return s.join("-")}toString(){return this.toText()}toJSON(){return{[E]:this.toText()}}compareTo(t){for(let r=0;r<Math.min(this._arr.length,t._arr.length);r++){if(this._arr[r]<t._arr[r])return"lt";if(this._arr[r]>t._arr[r])return"gt"}return this._arr.length<t._arr.length?"lt":this._arr.length>t._arr.length?"gt":"eq"}ltEq(t){let r=this.compareTo(t);return r=="lt"||r=="eq"}gtEq(t){let r=this.compareTo(t);return r=="gt"||r=="eq"}};var G="__bigint__",V="__principal__",j="__uint8array__",rt=(e,t)=>typeof t=="bigint"?{[G]:`${t}`}:d(t)&&A.isPrincipal(t)?{[V]:A.from(t).toText()}:d(t)&&t instanceof Uint8Array?{[j]:Array.from(t)}:t,nt=(e,t)=>{let r=n=>t[n];return d(t)&&typeof t=="object"&&G in t?BigInt(r(G)):d(t)&&typeof t=="object"&&V in t?A.fromText(r(V)):d(t)&&typeof t=="object"&&j in t?Uint8Array.from(r(j)):t};var de=async e=>{let t=new Blob([JSON.stringify(e,rt)],{type:"application/json; charset=utf-8"});return new Uint8Array(await t.arrayBuffer())},he=async e=>{let t=new Blob([e instanceof Uint8Array?e:new Uint8Array(e)],{type:"application/json; charset=utf-8"});return JSON.parse(await t.text(),nt)};var le=()=>typeof window<"u";var ge=e=>e.replace(/([a-zA-Z])(?=[A-Z])/g,"$1_").toLowerCase(),ye=e=>e.charAt(0).toUpperCase()+e.slice(1);export{L as InvalidPercentageError,C as NullishError,Ut as arrayBufferToUint8Array,_t as arrayOfNumberToUint8Array,ut as asNonNullish,Bt as asciiStringToByteArray,pt as assertNever,U as assertNonNullish,lt as assertPercentageNumber,Ct as base64ToUint8Array,At as bigIntToUint8Array,Et as candidNumberArrayToBigInt,ye as capitalize,ge as convertCamelToSnake,Gt as debounce,he as fromArray,Wt as fromDefinedNullable,J as fromNullable,Kt as fromNullishNullable,Nt as hexStringToUint8Array,le as isBrowser,jt as isEmptyString,ot as isNullish,rt as jsonReplacer,nt as jsonReviver,d as nonNullish,it as notEmptyString,kt as nowInBigIntNanoSeconds,wt as numberToUint8Array,de as toArray,Ft as toBigIntNanoSeconds,Mt as toNullable,Tt as uint8ArrayToArrayOfNumber,Lt as uint8ArrayToBase64,mt as uint8ArrayToBigInt,Ht as uint8ArrayToHexString,St as uint8ArraysEqual};
|
|
2
|
-
/*! Bundled license information:
|
|
3
|
-
|
|
4
|
-
@noble/hashes/esm/utils.js:
|
|
5
|
-
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
6
|
-
*/
|
|
1
|
+
var a=class extends Error{},f=class extends Error{},i=(r,n)=>{if(r==null)throw new f(n)},T=(r,n)=>(i(r,n),r),N=r=>{if(r<0||r>100)throw new a(`${r} is not a valid percentage number.`)},d=(r,n)=>{throw new Error(n)};var h=r=>{let n=new DataView(r.buffer,r.byteOffset,r.byteLength);if(typeof n.getBigUint64=="function")return n.getBigUint64(0);let t=BigInt(n.getUint32(0)),e=BigInt(n.getUint32(4));return(t<<BigInt(32))+e},B=r=>{let n=new ArrayBuffer(8),t=new DataView(n);if(typeof t.setBigUint64=="function")t.setBigUint64(0,r);else{let e=Number(r>>BigInt(32)),s=Number(r&BigInt(4294967295));t.setUint32(0,e),t.setUint32(4,s)}return new Uint8Array(n)},_=r=>{let n=new DataView(new ArrayBuffer(8));for(let t=7;t>=0;--t)n.setUint8(t,r%256),r=r>>8;return new Uint8Array(n.buffer)},I=r=>new Uint8Array(r),S=r=>Array.from(r),k=r=>new Uint8Array(r),O=r=>Array.from(r).map(n=>n.charCodeAt(0)),j=r=>{let n=r.match(/.{1,2}/g);return i(n,"Invalid hex string."),Uint8Array.from(n.map(t=>parseInt(t,16)))},C=({a:r,b:n})=>r.length===n.length&&r.every((t,e)=>t===n[e]),E=r=>(r instanceof Uint8Array||(r=Uint8Array.from(r)),r.reduce((n,t)=>n+t.toString(16).padStart(2,"0"),"")),R=r=>{let n=0n;for(let t=r.length-1;t>=0;t--)n=(n<<32n)+BigInt(r[t]);return n};var P=r=>{let t=[];for(let e=0;e<r.length;e+=32768)t.push(String.fromCharCode(...r.subarray(e,e+32768)));return btoa(t.join(""))},J=r=>Uint8Array.from(atob(r),n=>n.charCodeAt(0));var y=1000000n,L=()=>BigInt(Date.now())*y,V=r=>BigInt(r.getTime())*y;var K=(r,n)=>{let t;return(...e)=>{let s=()=>r(...e);t&&clearTimeout(t),t=setTimeout(s,n!==void 0&&n>0?n:300)}};var x=r=>r==null,o=r=>!x(r),b=r=>o(r)&&r!=="",Z=r=>!b(r);var H=r=>o(r)?[r]:[],m=r=>r?.[0],M=r=>{let n=m(r);return i(n),n},Q=r=>m(r??[]);import{Principal as u}from"@icp-sdk/core/principal";var c="__bigint__",l="__principal__",p="__uint8array__",g=(r,n)=>typeof n=="bigint"?{[c]:`${n}`}:o(n)&&u.isPrincipal(n)?{[l]:u.from(n).toText()}:o(n)&&n instanceof Uint8Array?{[p]:Array.from(n)}:n,A=(r,n)=>{let t=e=>n[e];return o(n)&&typeof n=="object"&&c in n?BigInt(t(c)):o(n)&&typeof n=="object"&&l in n?u.fromText(t(l)):o(n)&&typeof n=="object"&&p in n?Uint8Array.from(t(p)):n};var tr=async r=>{let n=new Blob([JSON.stringify(r,g)],{type:"application/json; charset=utf-8"});return new Uint8Array(await n.arrayBuffer())},er=async r=>{let n=new Blob([r instanceof Uint8Array?r:new Uint8Array(r)],{type:"application/json; charset=utf-8"});return JSON.parse(await n.text(),A)};var ir=()=>typeof window<"u";var ar=r=>r.replace(/([a-zA-Z])(?=[A-Z])/g,"$1_").toLowerCase(),fr=r=>r.charAt(0).toUpperCase()+r.slice(1);export{a as InvalidPercentageError,f as NullishError,I as arrayBufferToUint8Array,k as arrayOfNumberToUint8Array,T as asNonNullish,O as asciiStringToByteArray,d as assertNever,i as assertNonNullish,N as assertPercentageNumber,J as base64ToUint8Array,B as bigIntToUint8Array,R as candidNumberArrayToBigInt,fr as capitalize,ar as convertCamelToSnake,K as debounce,er as fromArray,M as fromDefinedNullable,m as fromNullable,Q as fromNullishNullable,j as hexStringToUint8Array,ir as isBrowser,Z as isEmptyString,x as isNullish,g as jsonReplacer,A as jsonReviver,o as nonNullish,b as notEmptyString,L as nowInBigIntNanoSeconds,_ as numberToUint8Array,tr as toArray,V as toBigIntNanoSeconds,H as toNullable,S as uint8ArrayToArrayOfNumber,P as uint8ArrayToBase64,h as uint8ArrayToBigInt,E as uint8ArrayToHexString,C as uint8ArraysEqual};
|
|
7
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/utils/asserts.utils.ts", "../../src/utils/arrays.utils.ts", "../../src/utils/base64.utils.ts", "../../src/utils/date.utils.ts", "../../src/utils/debounce.utils.ts", "../../src/utils/nullish.utils.ts", "../../src/utils/did.utils.ts", "
|
|
4
|
-
"sourcesContent": ["export class InvalidPercentageError extends Error {}\nexport class NullishError extends Error {}\n\nexport const assertNonNullish: <T>(\n value: T,\n message?: string\n // eslint-disable-next-line local-rules/prefer-object-params\n) => asserts value is NonNullable<T> = <T>(value: T, message?: string): void => {\n if (value === null || value === undefined) {\n throw new NullishError(message);\n }\n};\n\n// eslint-disable-next-line local-rules/prefer-object-params\nexport const asNonNullish = <T>(value: T, message?: string): NonNullable<T> => {\n assertNonNullish(value, message);\n return value;\n};\n\nexport const assertPercentageNumber = (percentage: number) => {\n if (percentage < 0 || percentage > 100) {\n throw new InvalidPercentageError(`${percentage} is not a valid percentage number.`);\n }\n};\n\n/**\n * Utility to enforce exhaustiveness checks in TypeScript.\n *\n * This function should only be called in branches of a `switch` or conditional\n * that should be unreachable if the union type has been fully handled.\n *\n * By typing the parameter as `never`, the compiler will emit an error if\n * a new variant is added to the union but not covered in the logic.\n *\n * @param _ - A value that should be of type `never`. If this is not the case,\n * the TypeScript compiler will flag a type error.\n * @param message - Optional custom error message to include in the thrown error.\n * @throws {Error} Always throws when invoked at runtime.\n *\n */\n// eslint-disable-next-line local-rules/prefer-object-params\nexport const assertNever = (_: never, message?: string): never => {\n throw new Error(message);\n};\n", "import {assertNonNullish} from './asserts.utils';\n\nexport const uint8ArrayToBigInt = (array: Uint8Array): bigint => {\n const view = new DataView(array.buffer, array.byteOffset, array.byteLength);\n if (typeof view.getBigUint64 === 'function') {\n return view.getBigUint64(0);\n }\n const high = BigInt(view.getUint32(0));\n const low = BigInt(view.getUint32(4));\n\n return (high << BigInt(32)) + low;\n};\n\nexport const bigIntToUint8Array = (value: bigint): Uint8Array => {\n const buffer = new ArrayBuffer(8);\n const view = new DataView(buffer);\n if (typeof view.setBigUint64 === 'function') {\n view.setBigUint64(0, value);\n } else {\n const high = Number(value >> BigInt(32));\n const low = Number(value & BigInt(0xffffffff));\n\n view.setUint32(0, high);\n view.setUint32(4, low);\n }\n\n return new Uint8Array(buffer);\n};\n\nexport const numberToUint8Array = (value: number): Uint8Array => {\n const view = new DataView(new ArrayBuffer(8));\n for (let index = 7; index >= 0; --index) {\n view.setUint8(index, value % 256);\n value = value >> 8;\n }\n return new Uint8Array(view.buffer);\n};\n\nexport const arrayBufferToUint8Array = (buffer: ArrayBuffer): Uint8Array => new Uint8Array(buffer);\n\nexport const uint8ArrayToArrayOfNumber = (array: Uint8Array): Array<number> => Array.from(array);\n\nexport const arrayOfNumberToUint8Array = (numbers: Array<number>): Uint8Array =>\n new Uint8Array(numbers);\n\nexport const asciiStringToByteArray = (text: string): Array<number> =>\n Array.from(text).map((c) => c.charCodeAt(0));\n\nexport const hexStringToUint8Array = (hexString: string): Uint8Array => {\n const matches = hexString.match(/.{1,2}/g);\n\n assertNonNullish(matches, 'Invalid hex string.');\n\n return Uint8Array.from(matches.map((byte) => parseInt(byte, 16)));\n};\n\n/**\n * Compare two Uint8Arrays for byte-level equality.\n *\n * @param {Object} params\n * @param {Uint8Array} params.a - First Uint8Array to compare.\n * @param {Uint8Array} params.b - Second Uint8Array to compare.\n * @returns {boolean} True if both arrays have the same length and identical contents.\n */\nexport const uint8ArraysEqual = ({a, b}: {a: Uint8Array; b: Uint8Array}) =>\n a.length === b.length && a.every((byte, i) => byte === b[i]);\n\nexport const uint8ArrayToHexString = (bytes: Uint8Array | number[]) => {\n if (!(bytes instanceof Uint8Array)) {\n bytes = Uint8Array.from(bytes);\n }\n return bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), '');\n};\n\nexport const candidNumberArrayToBigInt = (array: number[]): bigint => {\n let result = 0n;\n for (let i = array.length - 1; i >= 0; i--) {\n result = (result << 32n) + BigInt(array[i]);\n }\n return result;\n};\n", "/**\n * Converts a Uint8Array (binary data) to a base64 encoded string.\n *\n * @param {Uint8Array} uint8Array - The Uint8Array containing binary data to be encoded.\n * @returns {string} - The base64 encoded string representation of the binary data.\n */\nexport const uint8ArrayToBase64 = (uint8Array: Uint8Array): string => {\n // Spreading large Uint8Arrays or using Array.from loses precision when used together with String.fromCharCode.\n // Therefore, we use a chunked loop, which better than a reducer or iterating on every value.\n // Spreading a small chunk - such as 32kb - works as expected.\n const chunkSize = 0x8000; // 32 kb\n const chunks: string[] = [];\n for (let i = 0; i < uint8Array.length; i += chunkSize) {\n chunks.push(String.fromCharCode(...uint8Array.subarray(i, i + chunkSize)));\n }\n return btoa(chunks.join(''));\n};\n\n/**\n * Converts a base64 encoded string to a Uint8Array (binary data).\n *\n * @param {string} base64String - The base64 encoded string to be decoded.\n * @returns {Uint8Array} - The Uint8Array representation of the decoded binary data.\n */\nexport const base64ToUint8Array = (base64String: string): Uint8Array =>\n Uint8Array.from(atob(base64String), (c) => c.charCodeAt(0));\n", "const NANOSECONDS_PER_MILLISECOND = 1_000_000n;\n\n/**\n * Returns the current timestamp in nanoseconds as a `bigint`.\n *\n * @returns {bigint} The current timestamp in nanoseconds.\n */\nexport const nowInBigIntNanoSeconds = (): bigint =>\n BigInt(Date.now()) * NANOSECONDS_PER_MILLISECOND;\n\n/**\n * Converts a given `Date` object to a timestamp in nanoseconds as a `bigint`.\n *\n * @param {Date} date - The `Date` object to convert.\n * @returns {bigint} The timestamp in nanoseconds.\n */\nexport const toBigIntNanoSeconds = (date: Date): bigint =>\n BigInt(date.getTime()) * NANOSECONDS_PER_MILLISECOND;\n", "/**\n * Creates a debounced version of the provided function.\n *\n * The debounced function postpones its execution until after a certain amount of time\n * has elapsed since the last time it was invoked. This is useful for limiting the rate\n * at which a function is called (e.g. in response to user input or events).\n *\n * @param {Function} func - The function to debounce. It will only be called after no new calls happen within the specified timeout.\n * @param {number} [timeout=300] - The debounce delay in milliseconds. Defaults to 300ms if not provided or invalid.\n * @returns {(args: unknown[]) => void} A debounced version of the original function.\n */\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type, local-rules/prefer-object-params\nexport const debounce = (func: Function, timeout?: number) => {\n let timer: NodeJS.Timer | undefined;\n\n return (...args: unknown[]) => {\n const next = () => func(...args);\n\n if (timer) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore TypeScript global and window confusion even if we are using @types/node\n clearTimeout(timer);\n }\n\n timer = setTimeout(next, timeout !== undefined && timeout > 0 ? timeout : 300);\n };\n};\n", "/**\n * Checks if a given argument is null or undefined.\n *\n * @template T - The type of the argument.\n * @param {T | undefined | null} argument - The argument to check.\n * @returns {argument is undefined | null} `true` if the argument is null or undefined; otherwise, `false`.\n */\nexport const isNullish = <T>(argument: T | undefined | null): argument is undefined | null =>\n argument === null || argument === undefined;\n\n/**\n * Checks if a given argument is neither null nor undefined.\n *\n * @template T - The type of the argument.\n * @param {T | undefined | null} argument - The argument to check.\n * @returns {argument is NonNullable<T>} `true` if the argument is not null or undefined; otherwise, `false`.\n */\nexport const nonNullish = <T>(argument: T | undefined | null): argument is NonNullable<T> =>\n !isNullish(argument);\n\n/**\n * Checks if a given value is not null, not undefined, and not an empty string.\n *\n * @param {string | undefined | null} value - The value to check.\n * @returns {boolean} `true` if the value is not null, not undefined, and not an empty string; otherwise, `false`.\n */\nexport const notEmptyString = (value: string | undefined | null): value is string =>\n nonNullish(value) && value !== '';\n\n/**\n * Checks if a given value is null, undefined, or an empty string.\n *\n * @param {string | undefined | null} value - The value to check.\n * @returns {value is undefined | null | \"\"} Type predicate indicating if the value is null, undefined, or an empty string.\n */\nexport const isEmptyString = (value: string | undefined | null): value is undefined | null | '' =>\n !notEmptyString(value);\n", "import type {Nullable, NullishNullable} from '../types/did.utils';\nimport {assertNonNullish} from './asserts.utils';\nimport {nonNullish} from './nullish.utils';\n\n/**\n * Converts a value into a Candid-style variant representation of an optional value.\n *\n * @template T The type of the value.\n * @param {T | null | undefined} value - The value to convert into a Candid-style variant.\n * @returns {Nullable<T>} A Candid-style variant representation: an empty array for `null` and `undefined` or an array with the value.\n */\nexport const toNullable = <T>(value?: T | null): Nullable<T> => (nonNullish(value) ? [value] : []);\n\n/**\n * Extracts the value from a Candid-style variant representation of an optional value.\n *\n * @template T The type of the value.\n * @param {Nullable<T>} value - A Candid-style variant representing an optional value.\n * @returns {T | undefined} The extracted value, or `undefined` if the array is empty.\n */\nexport const fromNullable = <T>(value: Nullable<T>): T | undefined => value?.[0];\n\n/**\n * Extracts the value from a Candid-style variant representation of an optional value,\n * ensuring the value is defined. Throws an error if the array is empty or the value is nullish.\n *\n * @template T The type of the value.\n * @param {Nullable<T>} value - A Candid-style variant representing an optional value.\n * @returns {T} The extracted value.\n * @throws {Error} If the array is empty or the value is nullish.\n */\nexport const fromDefinedNullable = <T>(value: Nullable<T>): T => {\n const result = fromNullable(value);\n\n assertNonNullish(result);\n\n return result;\n};\n\n/**\n * Extracts the value from a nullish Candid-style variant representation.\n *\n * @template T The type of the value.\n * @param {NullishNullable<T>} value - A Candid-style variant or `undefined`.\n * @returns {T | undefined} The extracted value, or `undefined` if the input is nullish or the array is empty.\n */\nexport const fromNullishNullable = <T>(value: NullishNullable<T>): T | undefined =>\n fromNullable(value ?? []);\n", "const alphabet = 'abcdefghijklmnopqrstuvwxyz234567';\n\n// Build a lookup table for decoding.\nconst lookupTable: Record<string, number> = Object.create(null);\nfor (let i = 0; i < alphabet.length; i++) {\n lookupTable[alphabet[i]] = i;\n}\n\n// Add aliases for rfc4648.\nlookupTable['0'] = lookupTable.o;\nlookupTable['1'] = lookupTable.i;\n\n/**\n * @param input The Uint8Array to encode.\n * @returns A Base32 string encoding the input.\n */\nexport function base32Encode(input: Uint8Array): string {\n // How many bits will we skip from the first byte.\n let skip = 0;\n // 5 high bits, carry from one byte to the next.\n let bits = 0;\n\n // The output string in base32.\n let output = '';\n\n function encodeByte(byte: number) {\n if (skip < 0) {\n // we have a carry from the previous byte\n bits |= byte >> -skip;\n } else {\n // no carry\n bits = (byte << skip) & 248;\n }\n\n if (skip > 3) {\n // Not enough data to produce a character, get us another one\n skip -= 8;\n return 1;\n }\n\n if (skip < 4) {\n // produce a character\n output += alphabet[bits >> 3];\n skip += 5;\n }\n\n return 0;\n }\n\n for (let i = 0; i < input.length; ) {\n i += encodeByte(input[i]);\n }\n\n return output + (skip < 0 ? alphabet[bits >> 3] : '');\n}\n\n/**\n * @param input The base32 encoded string to decode.\n */\nexport function base32Decode(input: string): Uint8Array {\n // how many bits we have from the previous character.\n let skip = 0;\n // current byte we're producing.\n let byte = 0;\n\n const output = new Uint8Array(((input.length * 4) / 3) | 0);\n let o = 0;\n\n function decodeChar(char: string) {\n // Consume a character from the stream, store\n // the output in this.output. As before, better\n // to use update().\n let val = lookupTable[char.toLowerCase()];\n if (val === undefined) {\n throw new Error(`Invalid character: ${JSON.stringify(char)}`);\n }\n\n // move to the high bits\n val <<= 3;\n byte |= val >>> skip;\n skip += 5;\n\n if (skip >= 8) {\n // We have enough bytes to produce an output\n output[o++] = byte;\n skip -= 8;\n\n if (skip > 0) {\n byte = (val << (5 - skip)) & 255;\n } else {\n byte = 0;\n }\n }\n }\n\n for (const c of input) {\n decodeChar(c);\n }\n\n return output.slice(0, o);\n}\n", "// This file is translated to JavaScript from\n// https://lxp32.github.io/docs/a-simple-example-crc32-calculation/\nconst lookUpTable: Uint32Array = new Uint32Array([\n 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,\n 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,\n 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,\n 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,\n 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,\n 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,\n 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,\n 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,\n 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,\n 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,\n 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,\n 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,\n 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,\n 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,\n 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,\n 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,\n 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,\n 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,\n 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,\n 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,\n 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,\n 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,\n 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,\n 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,\n 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,\n 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,\n 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,\n 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,\n 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,\n 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,\n 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,\n 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d,\n]);\n\n/**\n * Calculate the CRC32 of a Uint8Array.\n * @param buf The Uint8Array to calculate the CRC32 of.\n */\nexport function getCrc32(buf: Uint8Array): number {\n let crc = -1;\n\n for (let i = 0; i < buf.length; i++) {\n const byte = buf[i];\n const t = (byte ^ crc) & 0xff;\n crc = lookUpTable[t] ^ (crc >>> 8);\n }\n\n return (crc ^ -1) >>> 0;\n}\n", "/**\n * Utilities for hex, bytes, CSPRNG.\n * @module\n */\n/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */\n\n// We use WebCrypto aka globalThis.crypto, which exists in browsers and node.js 16+.\n// node.js versions earlier than v19 don't declare it in global scope.\n// For node.js, package.json#exports field mapping rewrites import\n// from `crypto` to `cryptoNode`, which imports native module.\n// Makes the utils un-importable in browsers without a bundler.\n// Once node.js 18 is deprecated (2025-04-30), we can just drop the import.\nimport { crypto } from '@noble/hashes/crypto';\n\n/** Checks if something is Uint8Array. Be careful: nodejs Buffer will return true. */\nexport function isBytes(a: unknown): a is Uint8Array {\n return a instanceof Uint8Array || (ArrayBuffer.isView(a) && a.constructor.name === 'Uint8Array');\n}\n\n/** Asserts something is positive integer. */\nexport function anumber(n: number): void {\n if (!Number.isSafeInteger(n) || n < 0) throw new Error('positive integer expected, got ' + n);\n}\n\n/** Asserts something is Uint8Array. */\nexport function abytes(b: Uint8Array | undefined, ...lengths: number[]): void {\n if (!isBytes(b)) throw new Error('Uint8Array expected');\n if (lengths.length > 0 && !lengths.includes(b.length))\n throw new Error('Uint8Array expected of length ' + lengths + ', got length=' + b.length);\n}\n\n/** Asserts something is hash */\nexport function ahash(h: IHash): void {\n if (typeof h !== 'function' || typeof h.create !== 'function')\n throw new Error('Hash should be wrapped by utils.createHasher');\n anumber(h.outputLen);\n anumber(h.blockLen);\n}\n\n/** Asserts a hash instance has not been destroyed / finished */\nexport function aexists(instance: any, checkFinished = true): void {\n if (instance.destroyed) throw new Error('Hash instance has been destroyed');\n if (checkFinished && instance.finished) throw new Error('Hash#digest() has already been called');\n}\n\n/** Asserts output is properly-sized byte array */\nexport function aoutput(out: any, instance: any): void {\n abytes(out);\n const min = instance.outputLen;\n if (out.length < min) {\n throw new Error('digestInto() expects output buffer of length at least ' + min);\n }\n}\n\n/** Generic type encompassing 8/16/32-byte arrays - but not 64-byte. */\n// prettier-ignore\nexport type TypedArray = Int8Array | Uint8ClampedArray | Uint8Array |\n Uint16Array | Int16Array | Uint32Array | Int32Array;\n\n/** Cast u8 / u16 / u32 to u8. */\nexport function u8(arr: TypedArray): Uint8Array {\n return new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);\n}\n\n/** Cast u8 / u16 / u32 to u32. */\nexport function u32(arr: TypedArray): Uint32Array {\n return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));\n}\n\n/** Zeroize a byte array. Warning: JS provides no guarantees. */\nexport function clean(...arrays: TypedArray[]): void {\n for (let i = 0; i < arrays.length; i++) {\n arrays[i].fill(0);\n }\n}\n\n/** Create DataView of an array for easy byte-level manipulation. */\nexport function createView(arr: TypedArray): DataView {\n return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);\n}\n\n/** The rotate right (circular right shift) operation for uint32 */\nexport function rotr(word: number, shift: number): number {\n return (word << (32 - shift)) | (word >>> shift);\n}\n\n/** The rotate left (circular left shift) operation for uint32 */\nexport function rotl(word: number, shift: number): number {\n return (word << shift) | ((word >>> (32 - shift)) >>> 0);\n}\n\n/** Is current platform little-endian? Most are. Big-Endian platform: IBM */\nexport const isLE: boolean = /* @__PURE__ */ (() =>\n new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44)();\n\n/** The byte swap operation for uint32 */\nexport function byteSwap(word: number): number {\n return (\n ((word << 24) & 0xff000000) |\n ((word << 8) & 0xff0000) |\n ((word >>> 8) & 0xff00) |\n ((word >>> 24) & 0xff)\n );\n}\n/** Conditionally byte swap if on a big-endian platform */\nexport const swap8IfBE: (n: number) => number = isLE\n ? (n: number) => n\n : (n: number) => byteSwap(n);\n\n/** @deprecated */\nexport const byteSwapIfBE: typeof swap8IfBE = swap8IfBE;\n/** In place byte swap for Uint32Array */\nexport function byteSwap32(arr: Uint32Array): Uint32Array {\n for (let i = 0; i < arr.length; i++) {\n arr[i] = byteSwap(arr[i]);\n }\n return arr;\n}\n\nexport const swap32IfBE: (u: Uint32Array) => Uint32Array = isLE\n ? (u: Uint32Array) => u\n : byteSwap32;\n\n// Built-in hex conversion https://caniuse.com/mdn-javascript_builtins_uint8array_fromhex\nconst hasHexBuiltin: boolean = /* @__PURE__ */ (() =>\n // @ts-ignore\n typeof Uint8Array.from([]).toHex === 'function' && typeof Uint8Array.fromHex === 'function')();\n\n// Array where index 0xf0 (240) is mapped to string 'f0'\nconst hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) =>\n i.toString(16).padStart(2, '0')\n);\n\n/**\n * Convert byte array to hex string. Uses built-in function, when available.\n * @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123'\n */\nexport function bytesToHex(bytes: Uint8Array): string {\n abytes(bytes);\n // @ts-ignore\n if (hasHexBuiltin) return bytes.toHex();\n // pre-caching improves the speed 6x\n let hex = '';\n for (let i = 0; i < bytes.length; i++) {\n hex += hexes[bytes[i]];\n }\n return hex;\n}\n\n// We use optimized technique to convert hex string to byte array\nconst asciis = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 } as const;\nfunction asciiToBase16(ch: number): number | undefined {\n if (ch >= asciis._0 && ch <= asciis._9) return ch - asciis._0; // '2' => 50-48\n if (ch >= asciis.A && ch <= asciis.F) return ch - (asciis.A - 10); // 'B' => 66-(65-10)\n if (ch >= asciis.a && ch <= asciis.f) return ch - (asciis.a - 10); // 'b' => 98-(97-10)\n return;\n}\n\n/**\n * Convert hex string to byte array. Uses built-in function, when available.\n * @example hexToBytes('cafe0123') // Uint8Array.from([0xca, 0xfe, 0x01, 0x23])\n */\nexport function hexToBytes(hex: string): Uint8Array {\n if (typeof hex !== 'string') throw new Error('hex string expected, got ' + typeof hex);\n // @ts-ignore\n if (hasHexBuiltin) return Uint8Array.fromHex(hex);\n const hl = hex.length;\n const al = hl / 2;\n if (hl % 2) throw new Error('hex string expected, got unpadded hex of length ' + hl);\n const array = new Uint8Array(al);\n for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {\n const n1 = asciiToBase16(hex.charCodeAt(hi));\n const n2 = asciiToBase16(hex.charCodeAt(hi + 1));\n if (n1 === undefined || n2 === undefined) {\n const char = hex[hi] + hex[hi + 1];\n throw new Error('hex string expected, got non-hex character \"' + char + '\" at index ' + hi);\n }\n array[ai] = n1 * 16 + n2; // multiply first octet, e.g. 'a3' => 10*16+3 => 160 + 3 => 163\n }\n return array;\n}\n\n/**\n * There is no setImmediate in browser and setTimeout is slow.\n * Call of async fn will return Promise, which will be fullfiled only on\n * next scheduler queue processing step and this is exactly what we need.\n */\nexport const nextTick = async (): Promise<void> => {};\n\n/** Returns control to thread each 'tick' ms to avoid blocking. */\nexport async function asyncLoop(\n iters: number,\n tick: number,\n cb: (i: number) => void\n): Promise<void> {\n let ts = Date.now();\n for (let i = 0; i < iters; i++) {\n cb(i);\n // Date.now() is not monotonic, so in case if clock goes backwards we return return control too\n const diff = Date.now() - ts;\n if (diff >= 0 && diff < tick) continue;\n await nextTick();\n ts += diff;\n }\n}\n\n// Global symbols, but ts doesn't see them: https://github.com/microsoft/TypeScript/issues/31535\ndeclare const TextEncoder: any;\ndeclare const TextDecoder: any;\n\n/**\n * Converts string to bytes using UTF8 encoding.\n * @example utf8ToBytes('abc') // Uint8Array.from([97, 98, 99])\n */\nexport function utf8ToBytes(str: string): Uint8Array {\n if (typeof str !== 'string') throw new Error('string expected');\n return new Uint8Array(new TextEncoder().encode(str)); // https://bugzil.la/1681809\n}\n\n/**\n * Converts bytes to string using UTF8 encoding.\n * @example bytesToUtf8(Uint8Array.from([97, 98, 99])) // 'abc'\n */\nexport function bytesToUtf8(bytes: Uint8Array): string {\n return new TextDecoder().decode(bytes);\n}\n\n/** Accepted input of hash functions. Strings are converted to byte arrays. */\nexport type Input = string | Uint8Array;\n/**\n * Normalizes (non-hex) string or Uint8Array to Uint8Array.\n * Warning: when Uint8Array is passed, it would NOT get copied.\n * Keep in mind for future mutable operations.\n */\nexport function toBytes(data: Input): Uint8Array {\n if (typeof data === 'string') data = utf8ToBytes(data);\n abytes(data);\n return data;\n}\n\n/** KDFs can accept string or Uint8Array for user convenience. */\nexport type KDFInput = string | Uint8Array;\n/**\n * Helper for KDFs: consumes uint8array or string.\n * When string is passed, does utf8 decoding, using TextDecoder.\n */\nexport function kdfInputToBytes(data: KDFInput): Uint8Array {\n if (typeof data === 'string') data = utf8ToBytes(data);\n abytes(data);\n return data;\n}\n\n/** Copies several Uint8Arrays into one. */\nexport function concatBytes(...arrays: Uint8Array[]): Uint8Array {\n let sum = 0;\n for (let i = 0; i < arrays.length; i++) {\n const a = arrays[i];\n abytes(a);\n sum += a.length;\n }\n const res = new Uint8Array(sum);\n for (let i = 0, pad = 0; i < arrays.length; i++) {\n const a = arrays[i];\n res.set(a, pad);\n pad += a.length;\n }\n return res;\n}\n\ntype EmptyObj = {};\nexport function checkOpts<T1 extends EmptyObj, T2 extends EmptyObj>(\n defaults: T1,\n opts?: T2\n): T1 & T2 {\n if (opts !== undefined && {}.toString.call(opts) !== '[object Object]')\n throw new Error('options should be object or undefined');\n const merged = Object.assign(defaults, opts);\n return merged as T1 & T2;\n}\n\n/** Hash interface. */\nexport type IHash = {\n (data: Uint8Array): Uint8Array;\n blockLen: number;\n outputLen: number;\n create: any;\n};\n\n/** For runtime check if class implements interface */\nexport abstract class Hash<T extends Hash<T>> {\n abstract blockLen: number; // Bytes per block\n abstract outputLen: number; // Bytes in output\n abstract update(buf: Input): this;\n // Writes digest into buf\n abstract digestInto(buf: Uint8Array): void;\n abstract digest(): Uint8Array;\n /**\n * Resets internal state. Makes Hash instance unusable.\n * Reset is impossible for keyed hashes if key is consumed into state. If digest is not consumed\n * by user, they will need to manually call `destroy()` when zeroing is necessary.\n */\n abstract destroy(): void;\n /**\n * Clones hash instance. Unsafe: doesn't check whether `to` is valid. Can be used as `clone()`\n * when no options are passed.\n * Reasons to use `_cloneInto` instead of clone: 1) performance 2) reuse instance => all internal\n * buffers are overwritten => causes buffer overwrite which is used for digest in some cases.\n * There are no guarantees for clean-up because it's impossible in JS.\n */\n abstract _cloneInto(to?: T): T;\n // Safe version that clones internal state\n abstract clone(): T;\n}\n\n/**\n * XOF: streaming API to read digest in chunks.\n * Same as 'squeeze' in keccak/k12 and 'seek' in blake3, but more generic name.\n * When hash used in XOF mode it is up to user to call '.destroy' afterwards, since we cannot\n * destroy state, next call can require more bytes.\n */\nexport type HashXOF<T extends Hash<T>> = Hash<T> & {\n xof(bytes: number): Uint8Array; // Read 'bytes' bytes from digest stream\n xofInto(buf: Uint8Array): Uint8Array; // read buf.length bytes from digest stream into buf\n};\n\n/** Hash function */\nexport type CHash = ReturnType<typeof createHasher>;\n/** Hash function with output */\nexport type CHashO = ReturnType<typeof createOptHasher>;\n/** XOF with output */\nexport type CHashXO = ReturnType<typeof createXOFer>;\n\n/** Wraps hash function, creating an interface on top of it */\nexport function createHasher<T extends Hash<T>>(\n hashCons: () => Hash<T>\n): {\n (msg: Input): Uint8Array;\n outputLen: number;\n blockLen: number;\n create(): Hash<T>;\n} {\n const hashC = (msg: Input): Uint8Array => hashCons().update(toBytes(msg)).digest();\n const tmp = hashCons();\n hashC.outputLen = tmp.outputLen;\n hashC.blockLen = tmp.blockLen;\n hashC.create = () => hashCons();\n return hashC;\n}\n\nexport function createOptHasher<H extends Hash<H>, T extends Object>(\n hashCons: (opts?: T) => Hash<H>\n): {\n (msg: Input, opts?: T): Uint8Array;\n outputLen: number;\n blockLen: number;\n create(opts?: T): Hash<H>;\n} {\n const hashC = (msg: Input, opts?: T): Uint8Array => hashCons(opts).update(toBytes(msg)).digest();\n const tmp = hashCons({} as T);\n hashC.outputLen = tmp.outputLen;\n hashC.blockLen = tmp.blockLen;\n hashC.create = (opts?: T) => hashCons(opts);\n return hashC;\n}\n\nexport function createXOFer<H extends HashXOF<H>, T extends Object>(\n hashCons: (opts?: T) => HashXOF<H>\n): {\n (msg: Input, opts?: T): Uint8Array;\n outputLen: number;\n blockLen: number;\n create(opts?: T): HashXOF<H>;\n} {\n const hashC = (msg: Input, opts?: T): Uint8Array => hashCons(opts).update(toBytes(msg)).digest();\n const tmp = hashCons({} as T);\n hashC.outputLen = tmp.outputLen;\n hashC.blockLen = tmp.blockLen;\n hashC.create = (opts?: T) => hashCons(opts);\n return hashC;\n}\nexport const wrapConstructor: typeof createHasher = createHasher;\nexport const wrapConstructorWithOpts: typeof createOptHasher = createOptHasher;\nexport const wrapXOFConstructorWithOpts: typeof createXOFer = createXOFer;\n\n/** Cryptographically secure PRNG. Uses internal OS-level `crypto.getRandomValues`. */\nexport function randomBytes(bytesLength = 32): Uint8Array {\n if (crypto && typeof crypto.getRandomValues === 'function') {\n return crypto.getRandomValues(new Uint8Array(bytesLength));\n }\n // Legacy Node.js compatibility\n if (crypto && typeof crypto.randomBytes === 'function') {\n return Uint8Array.from(crypto.randomBytes(bytesLength));\n }\n throw new Error('crypto.getRandomValues must be defined');\n}\n", "/**\n * Internal Merkle-Damgard hash utils.\n * @module\n */\nimport { type Input, Hash, abytes, aexists, aoutput, clean, createView, toBytes } from './utils.ts';\n\n/** Polyfill for Safari 14. https://caniuse.com/mdn-javascript_builtins_dataview_setbiguint64 */\nexport function setBigUint64(\n view: DataView,\n byteOffset: number,\n value: bigint,\n isLE: boolean\n): void {\n if (typeof view.setBigUint64 === 'function') return view.setBigUint64(byteOffset, value, isLE);\n const _32n = BigInt(32);\n const _u32_max = BigInt(0xffffffff);\n const wh = Number((value >> _32n) & _u32_max);\n const wl = Number(value & _u32_max);\n const h = isLE ? 4 : 0;\n const l = isLE ? 0 : 4;\n view.setUint32(byteOffset + h, wh, isLE);\n view.setUint32(byteOffset + l, wl, isLE);\n}\n\n/** Choice: a ? b : c */\nexport function Chi(a: number, b: number, c: number): number {\n return (a & b) ^ (~a & c);\n}\n\n/** Majority function, true if any two inputs is true. */\nexport function Maj(a: number, b: number, c: number): number {\n return (a & b) ^ (a & c) ^ (b & c);\n}\n\n/**\n * Merkle-Damgard hash construction base class.\n * Could be used to create MD5, RIPEMD, SHA1, SHA2.\n */\nexport abstract class HashMD<T extends HashMD<T>> extends Hash<T> {\n protected abstract process(buf: DataView, offset: number): void;\n protected abstract get(): number[];\n protected abstract set(...args: number[]): void;\n abstract destroy(): void;\n protected abstract roundClean(): void;\n\n readonly blockLen: number;\n readonly outputLen: number;\n readonly padOffset: number;\n readonly isLE: boolean;\n\n // For partial updates less than block size\n protected buffer: Uint8Array;\n protected view: DataView;\n protected finished = false;\n protected length = 0;\n protected pos = 0;\n protected destroyed = false;\n\n constructor(blockLen: number, outputLen: number, padOffset: number, isLE: boolean) {\n super();\n this.blockLen = blockLen;\n this.outputLen = outputLen;\n this.padOffset = padOffset;\n this.isLE = isLE;\n this.buffer = new Uint8Array(blockLen);\n this.view = createView(this.buffer);\n }\n update(data: Input): this {\n aexists(this);\n data = toBytes(data);\n abytes(data);\n const { view, buffer, blockLen } = this;\n const len = data.length;\n for (let pos = 0; pos < len; ) {\n const take = Math.min(blockLen - this.pos, len - pos);\n // Fast path: we have at least one block in input, cast it to view and process\n if (take === blockLen) {\n const dataView = createView(data);\n for (; blockLen <= len - pos; pos += blockLen) this.process(dataView, pos);\n continue;\n }\n buffer.set(data.subarray(pos, pos + take), this.pos);\n this.pos += take;\n pos += take;\n if (this.pos === blockLen) {\n this.process(view, 0);\n this.pos = 0;\n }\n }\n this.length += data.length;\n this.roundClean();\n return this;\n }\n digestInto(out: Uint8Array): void {\n aexists(this);\n aoutput(out, this);\n this.finished = true;\n // Padding\n // We can avoid allocation of buffer for padding completely if it\n // was previously not allocated here. But it won't change performance.\n const { buffer, view, blockLen, isLE } = this;\n let { pos } = this;\n // append the bit '1' to the message\n buffer[pos++] = 0b10000000;\n clean(this.buffer.subarray(pos));\n // we have less than padOffset left in buffer, so we cannot put length in\n // current block, need process it and pad again\n if (this.padOffset > blockLen - pos) {\n this.process(view, 0);\n pos = 0;\n }\n // Pad until full block byte with zeros\n for (let i = pos; i < blockLen; i++) buffer[i] = 0;\n // Note: sha512 requires length to be 128bit integer, but length in JS will overflow before that\n // You need to write around 2 exabytes (u64_max / 8 / (1024**6)) for this to happen.\n // So we just write lowest 64 bits of that value.\n setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);\n this.process(view, 0);\n const oview = createView(out);\n const len = this.outputLen;\n // NOTE: we do division by 4 later, which should be fused in single op with modulo by JIT\n if (len % 4) throw new Error('_sha2: outputLen should be aligned to 32bit');\n const outLen = len / 4;\n const state = this.get();\n if (outLen > state.length) throw new Error('_sha2: outputLen bigger than state');\n for (let i = 0; i < outLen; i++) oview.setUint32(4 * i, state[i], isLE);\n }\n digest(): Uint8Array {\n const { buffer, outputLen } = this;\n this.digestInto(buffer);\n const res = buffer.slice(0, outputLen);\n this.destroy();\n return res;\n }\n _cloneInto(to?: T): T {\n to ||= new (this.constructor as any)() as T;\n to.set(...this.get());\n const { blockLen, buffer, length, finished, destroyed, pos } = this;\n to.destroyed = destroyed;\n to.finished = finished;\n to.length = length;\n to.pos = pos;\n if (length % blockLen) to.buffer.set(buffer);\n return to;\n }\n clone(): T {\n return this._cloneInto();\n }\n}\n\n/**\n * Initial SHA-2 state: fractional parts of square roots of first 16 primes 2..53.\n * Check out `test/misc/sha2-gen-iv.js` for recomputation guide.\n */\n\n/** Initial SHA256 state. Bits 0..32 of frac part of sqrt of primes 2..19 */\nexport const SHA256_IV: Uint32Array = /* @__PURE__ */ Uint32Array.from([\n 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,\n]);\n\n/** Initial SHA224 state. Bits 32..64 of frac part of sqrt of primes 23..53 */\nexport const SHA224_IV: Uint32Array = /* @__PURE__ */ Uint32Array.from([\n 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4,\n]);\n\n/** Initial SHA384 state. Bits 0..64 of frac part of sqrt of primes 23..53 */\nexport const SHA384_IV: Uint32Array = /* @__PURE__ */ Uint32Array.from([\n 0xcbbb9d5d, 0xc1059ed8, 0x629a292a, 0x367cd507, 0x9159015a, 0x3070dd17, 0x152fecd8, 0xf70e5939,\n 0x67332667, 0xffc00b31, 0x8eb44a87, 0x68581511, 0xdb0c2e0d, 0x64f98fa7, 0x47b5481d, 0xbefa4fa4,\n]);\n\n/** Initial SHA512 state. Bits 0..64 of frac part of sqrt of primes 2..19 */\nexport const SHA512_IV: Uint32Array = /* @__PURE__ */ Uint32Array.from([\n 0x6a09e667, 0xf3bcc908, 0xbb67ae85, 0x84caa73b, 0x3c6ef372, 0xfe94f82b, 0xa54ff53a, 0x5f1d36f1,\n 0x510e527f, 0xade682d1, 0x9b05688c, 0x2b3e6c1f, 0x1f83d9ab, 0xfb41bd6b, 0x5be0cd19, 0x137e2179,\n]);\n", "/**\n * SHA2 hash function. A.k.a. sha256, sha384, sha512, sha512_224, sha512_256.\n * SHA256 is the fastest hash implementable in JS, even faster than Blake3.\n * Check out [RFC 4634](https://datatracker.ietf.org/doc/html/rfc4634) and\n * [FIPS 180-4](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf).\n * @module\n */\nimport { Chi, HashMD, Maj, SHA224_IV, SHA256_IV, SHA384_IV, SHA512_IV } from './_md.ts';\nimport * as u64 from './_u64.ts';\nimport { type CHash, clean, createHasher, rotr } from './utils.ts';\n\n/**\n * Round constants:\n * First 32 bits of fractional parts of the cube roots of the first 64 primes 2..311)\n */\n// prettier-ignore\nconst SHA256_K = /* @__PURE__ */ Uint32Array.from([\n 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,\n 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,\n 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,\n 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,\n 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,\n 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,\n 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,\n 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2\n]);\n\n/** Reusable temporary buffer. \"W\" comes straight from spec. */\nconst SHA256_W = /* @__PURE__ */ new Uint32Array(64);\nexport class SHA256 extends HashMD<SHA256> {\n // We cannot use array here since array allows indexing by variable\n // which means optimizer/compiler cannot use registers.\n protected A: number = SHA256_IV[0] | 0;\n protected B: number = SHA256_IV[1] | 0;\n protected C: number = SHA256_IV[2] | 0;\n protected D: number = SHA256_IV[3] | 0;\n protected E: number = SHA256_IV[4] | 0;\n protected F: number = SHA256_IV[5] | 0;\n protected G: number = SHA256_IV[6] | 0;\n protected H: number = SHA256_IV[7] | 0;\n\n constructor(outputLen: number = 32) {\n super(64, outputLen, 8, false);\n }\n protected get(): [number, number, number, number, number, number, number, number] {\n const { A, B, C, D, E, F, G, H } = this;\n return [A, B, C, D, E, F, G, H];\n }\n // prettier-ignore\n protected set(\n A: number, B: number, C: number, D: number, E: number, F: number, G: number, H: number\n ): void {\n this.A = A | 0;\n this.B = B | 0;\n this.C = C | 0;\n this.D = D | 0;\n this.E = E | 0;\n this.F = F | 0;\n this.G = G | 0;\n this.H = H | 0;\n }\n protected process(view: DataView, offset: number): void {\n // Extend the first 16 words into the remaining 48 words w[16..63] of the message schedule array\n for (let i = 0; i < 16; i++, offset += 4) SHA256_W[i] = view.getUint32(offset, false);\n for (let i = 16; i < 64; i++) {\n const W15 = SHA256_W[i - 15];\n const W2 = SHA256_W[i - 2];\n const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ (W15 >>> 3);\n const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ (W2 >>> 10);\n SHA256_W[i] = (s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16]) | 0;\n }\n // Compression function main loop, 64 rounds\n let { A, B, C, D, E, F, G, H } = this;\n for (let i = 0; i < 64; i++) {\n const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);\n const T1 = (H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0;\n const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);\n const T2 = (sigma0 + Maj(A, B, C)) | 0;\n H = G;\n G = F;\n F = E;\n E = (D + T1) | 0;\n D = C;\n C = B;\n B = A;\n A = (T1 + T2) | 0;\n }\n // Add the compressed chunk to the current hash value\n A = (A + this.A) | 0;\n B = (B + this.B) | 0;\n C = (C + this.C) | 0;\n D = (D + this.D) | 0;\n E = (E + this.E) | 0;\n F = (F + this.F) | 0;\n G = (G + this.G) | 0;\n H = (H + this.H) | 0;\n this.set(A, B, C, D, E, F, G, H);\n }\n protected roundClean(): void {\n clean(SHA256_W);\n }\n destroy(): void {\n this.set(0, 0, 0, 0, 0, 0, 0, 0);\n clean(this.buffer);\n }\n}\n\nexport class SHA224 extends SHA256 {\n protected A: number = SHA224_IV[0] | 0;\n protected B: number = SHA224_IV[1] | 0;\n protected C: number = SHA224_IV[2] | 0;\n protected D: number = SHA224_IV[3] | 0;\n protected E: number = SHA224_IV[4] | 0;\n protected F: number = SHA224_IV[5] | 0;\n protected G: number = SHA224_IV[6] | 0;\n protected H: number = SHA224_IV[7] | 0;\n constructor() {\n super(28);\n }\n}\n\n// SHA2-512 is slower than sha256 in js because u64 operations are slow.\n\n// Round contants\n// First 32 bits of the fractional parts of the cube roots of the first 80 primes 2..409\n// prettier-ignore\nconst K512 = /* @__PURE__ */ (() => u64.split([\n '0x428a2f98d728ae22', '0x7137449123ef65cd', '0xb5c0fbcfec4d3b2f', '0xe9b5dba58189dbbc',\n '0x3956c25bf348b538', '0x59f111f1b605d019', '0x923f82a4af194f9b', '0xab1c5ed5da6d8118',\n '0xd807aa98a3030242', '0x12835b0145706fbe', '0x243185be4ee4b28c', '0x550c7dc3d5ffb4e2',\n '0x72be5d74f27b896f', '0x80deb1fe3b1696b1', '0x9bdc06a725c71235', '0xc19bf174cf692694',\n '0xe49b69c19ef14ad2', '0xefbe4786384f25e3', '0x0fc19dc68b8cd5b5', '0x240ca1cc77ac9c65',\n '0x2de92c6f592b0275', '0x4a7484aa6ea6e483', '0x5cb0a9dcbd41fbd4', '0x76f988da831153b5',\n '0x983e5152ee66dfab', '0xa831c66d2db43210', '0xb00327c898fb213f', '0xbf597fc7beef0ee4',\n '0xc6e00bf33da88fc2', '0xd5a79147930aa725', '0x06ca6351e003826f', '0x142929670a0e6e70',\n '0x27b70a8546d22ffc', '0x2e1b21385c26c926', '0x4d2c6dfc5ac42aed', '0x53380d139d95b3df',\n '0x650a73548baf63de', '0x766a0abb3c77b2a8', '0x81c2c92e47edaee6', '0x92722c851482353b',\n '0xa2bfe8a14cf10364', '0xa81a664bbc423001', '0xc24b8b70d0f89791', '0xc76c51a30654be30',\n '0xd192e819d6ef5218', '0xd69906245565a910', '0xf40e35855771202a', '0x106aa07032bbd1b8',\n '0x19a4c116b8d2d0c8', '0x1e376c085141ab53', '0x2748774cdf8eeb99', '0x34b0bcb5e19b48a8',\n '0x391c0cb3c5c95a63', '0x4ed8aa4ae3418acb', '0x5b9cca4f7763e373', '0x682e6ff3d6b2b8a3',\n '0x748f82ee5defb2fc', '0x78a5636f43172f60', '0x84c87814a1f0ab72', '0x8cc702081a6439ec',\n '0x90befffa23631e28', '0xa4506cebde82bde9', '0xbef9a3f7b2c67915', '0xc67178f2e372532b',\n '0xca273eceea26619c', '0xd186b8c721c0c207', '0xeada7dd6cde0eb1e', '0xf57d4f7fee6ed178',\n '0x06f067aa72176fba', '0x0a637dc5a2c898a6', '0x113f9804bef90dae', '0x1b710b35131c471b',\n '0x28db77f523047d84', '0x32caab7b40c72493', '0x3c9ebe0a15c9bebc', '0x431d67c49c100d4c',\n '0x4cc5d4becb3e42b6', '0x597f299cfc657e2a', '0x5fcb6fab3ad6faec', '0x6c44198c4a475817'\n].map(n => BigInt(n))))();\nconst SHA512_Kh = /* @__PURE__ */ (() => K512[0])();\nconst SHA512_Kl = /* @__PURE__ */ (() => K512[1])();\n\n// Reusable temporary buffers\nconst SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);\nconst SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);\n\nexport class SHA512 extends HashMD<SHA512> {\n // We cannot use array here since array allows indexing by variable\n // which means optimizer/compiler cannot use registers.\n // h -- high 32 bits, l -- low 32 bits\n protected Ah: number = SHA512_IV[0] | 0;\n protected Al: number = SHA512_IV[1] | 0;\n protected Bh: number = SHA512_IV[2] | 0;\n protected Bl: number = SHA512_IV[3] | 0;\n protected Ch: number = SHA512_IV[4] | 0;\n protected Cl: number = SHA512_IV[5] | 0;\n protected Dh: number = SHA512_IV[6] | 0;\n protected Dl: number = SHA512_IV[7] | 0;\n protected Eh: number = SHA512_IV[8] | 0;\n protected El: number = SHA512_IV[9] | 0;\n protected Fh: number = SHA512_IV[10] | 0;\n protected Fl: number = SHA512_IV[11] | 0;\n protected Gh: number = SHA512_IV[12] | 0;\n protected Gl: number = SHA512_IV[13] | 0;\n protected Hh: number = SHA512_IV[14] | 0;\n protected Hl: number = SHA512_IV[15] | 0;\n\n constructor(outputLen: number = 64) {\n super(128, outputLen, 16, false);\n }\n // prettier-ignore\n protected get(): [\n number, number, number, number, number, number, number, number,\n number, number, number, number, number, number, number, number\n ] {\n const { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;\n return [Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl];\n }\n // prettier-ignore\n protected set(\n Ah: number, Al: number, Bh: number, Bl: number, Ch: number, Cl: number, Dh: number, Dl: number,\n Eh: number, El: number, Fh: number, Fl: number, Gh: number, Gl: number, Hh: number, Hl: number\n ): void {\n this.Ah = Ah | 0;\n this.Al = Al | 0;\n this.Bh = Bh | 0;\n this.Bl = Bl | 0;\n this.Ch = Ch | 0;\n this.Cl = Cl | 0;\n this.Dh = Dh | 0;\n this.Dl = Dl | 0;\n this.Eh = Eh | 0;\n this.El = El | 0;\n this.Fh = Fh | 0;\n this.Fl = Fl | 0;\n this.Gh = Gh | 0;\n this.Gl = Gl | 0;\n this.Hh = Hh | 0;\n this.Hl = Hl | 0;\n }\n protected process(view: DataView, offset: number): void {\n // Extend the first 16 words into the remaining 64 words w[16..79] of the message schedule array\n for (let i = 0; i < 16; i++, offset += 4) {\n SHA512_W_H[i] = view.getUint32(offset);\n SHA512_W_L[i] = view.getUint32((offset += 4));\n }\n for (let i = 16; i < 80; i++) {\n // s0 := (w[i-15] rightrotate 1) xor (w[i-15] rightrotate 8) xor (w[i-15] rightshift 7)\n const W15h = SHA512_W_H[i - 15] | 0;\n const W15l = SHA512_W_L[i - 15] | 0;\n const s0h = u64.rotrSH(W15h, W15l, 1) ^ u64.rotrSH(W15h, W15l, 8) ^ u64.shrSH(W15h, W15l, 7);\n const s0l = u64.rotrSL(W15h, W15l, 1) ^ u64.rotrSL(W15h, W15l, 8) ^ u64.shrSL(W15h, W15l, 7);\n // s1 := (w[i-2] rightrotate 19) xor (w[i-2] rightrotate 61) xor (w[i-2] rightshift 6)\n const W2h = SHA512_W_H[i - 2] | 0;\n const W2l = SHA512_W_L[i - 2] | 0;\n const s1h = u64.rotrSH(W2h, W2l, 19) ^ u64.rotrBH(W2h, W2l, 61) ^ u64.shrSH(W2h, W2l, 6);\n const s1l = u64.rotrSL(W2h, W2l, 19) ^ u64.rotrBL(W2h, W2l, 61) ^ u64.shrSL(W2h, W2l, 6);\n // SHA256_W[i] = s0 + s1 + SHA256_W[i - 7] + SHA256_W[i - 16];\n const SUMl = u64.add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16]);\n const SUMh = u64.add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]);\n SHA512_W_H[i] = SUMh | 0;\n SHA512_W_L[i] = SUMl | 0;\n }\n let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;\n // Compression function main loop, 80 rounds\n for (let i = 0; i < 80; i++) {\n // S1 := (e rightrotate 14) xor (e rightrotate 18) xor (e rightrotate 41)\n const sigma1h = u64.rotrSH(Eh, El, 14) ^ u64.rotrSH(Eh, El, 18) ^ u64.rotrBH(Eh, El, 41);\n const sigma1l = u64.rotrSL(Eh, El, 14) ^ u64.rotrSL(Eh, El, 18) ^ u64.rotrBL(Eh, El, 41);\n //const T1 = (H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0;\n const CHIh = (Eh & Fh) ^ (~Eh & Gh);\n const CHIl = (El & Fl) ^ (~El & Gl);\n // T1 = H + sigma1 + Chi(E, F, G) + SHA512_K[i] + SHA512_W[i]\n // prettier-ignore\n const T1ll = u64.add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);\n const T1h = u64.add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);\n const T1l = T1ll | 0;\n // S0 := (a rightrotate 28) xor (a rightrotate 34) xor (a rightrotate 39)\n const sigma0h = u64.rotrSH(Ah, Al, 28) ^ u64.rotrBH(Ah, Al, 34) ^ u64.rotrBH(Ah, Al, 39);\n const sigma0l = u64.rotrSL(Ah, Al, 28) ^ u64.rotrBL(Ah, Al, 34) ^ u64.rotrBL(Ah, Al, 39);\n const MAJh = (Ah & Bh) ^ (Ah & Ch) ^ (Bh & Ch);\n const MAJl = (Al & Bl) ^ (Al & Cl) ^ (Bl & Cl);\n Hh = Gh | 0;\n Hl = Gl | 0;\n Gh = Fh | 0;\n Gl = Fl | 0;\n Fh = Eh | 0;\n Fl = El | 0;\n ({ h: Eh, l: El } = u64.add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));\n Dh = Ch | 0;\n Dl = Cl | 0;\n Ch = Bh | 0;\n Cl = Bl | 0;\n Bh = Ah | 0;\n Bl = Al | 0;\n const All = u64.add3L(T1l, sigma0l, MAJl);\n Ah = u64.add3H(All, T1h, sigma0h, MAJh);\n Al = All | 0;\n }\n // Add the compressed chunk to the current hash value\n ({ h: Ah, l: Al } = u64.add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));\n ({ h: Bh, l: Bl } = u64.add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));\n ({ h: Ch, l: Cl } = u64.add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));\n ({ h: Dh, l: Dl } = u64.add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));\n ({ h: Eh, l: El } = u64.add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));\n ({ h: Fh, l: Fl } = u64.add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));\n ({ h: Gh, l: Gl } = u64.add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));\n ({ h: Hh, l: Hl } = u64.add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));\n this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);\n }\n protected roundClean(): void {\n clean(SHA512_W_H, SHA512_W_L);\n }\n destroy(): void {\n clean(this.buffer);\n this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);\n }\n}\n\nexport class SHA384 extends SHA512 {\n protected Ah: number = SHA384_IV[0] | 0;\n protected Al: number = SHA384_IV[1] | 0;\n protected Bh: number = SHA384_IV[2] | 0;\n protected Bl: number = SHA384_IV[3] | 0;\n protected Ch: number = SHA384_IV[4] | 0;\n protected Cl: number = SHA384_IV[5] | 0;\n protected Dh: number = SHA384_IV[6] | 0;\n protected Dl: number = SHA384_IV[7] | 0;\n protected Eh: number = SHA384_IV[8] | 0;\n protected El: number = SHA384_IV[9] | 0;\n protected Fh: number = SHA384_IV[10] | 0;\n protected Fl: number = SHA384_IV[11] | 0;\n protected Gh: number = SHA384_IV[12] | 0;\n protected Gl: number = SHA384_IV[13] | 0;\n protected Hh: number = SHA384_IV[14] | 0;\n protected Hl: number = SHA384_IV[15] | 0;\n\n constructor() {\n super(48);\n }\n}\n\n/**\n * Truncated SHA512/256 and SHA512/224.\n * SHA512_IV is XORed with 0xa5a5a5a5a5a5a5a5, then used as \"intermediary\" IV of SHA512/t.\n * Then t hashes string to produce result IV.\n * See `test/misc/sha2-gen-iv.js`.\n */\n\n/** SHA512/224 IV */\nconst T224_IV = /* @__PURE__ */ Uint32Array.from([\n 0x8c3d37c8, 0x19544da2, 0x73e19966, 0x89dcd4d6, 0x1dfab7ae, 0x32ff9c82, 0x679dd514, 0x582f9fcf,\n 0x0f6d2b69, 0x7bd44da8, 0x77e36f73, 0x04c48942, 0x3f9d85a8, 0x6a1d36c8, 0x1112e6ad, 0x91d692a1,\n]);\n\n/** SHA512/256 IV */\nconst T256_IV = /* @__PURE__ */ Uint32Array.from([\n 0x22312194, 0xfc2bf72c, 0x9f555fa3, 0xc84c64c2, 0x2393b86b, 0x6f53b151, 0x96387719, 0x5940eabd,\n 0x96283ee2, 0xa88effe3, 0xbe5e1e25, 0x53863992, 0x2b0199fc, 0x2c85b8aa, 0x0eb72ddc, 0x81c52ca2,\n]);\n\nexport class SHA512_224 extends SHA512 {\n protected Ah: number = T224_IV[0] | 0;\n protected Al: number = T224_IV[1] | 0;\n protected Bh: number = T224_IV[2] | 0;\n protected Bl: number = T224_IV[3] | 0;\n protected Ch: number = T224_IV[4] | 0;\n protected Cl: number = T224_IV[5] | 0;\n protected Dh: number = T224_IV[6] | 0;\n protected Dl: number = T224_IV[7] | 0;\n protected Eh: number = T224_IV[8] | 0;\n protected El: number = T224_IV[9] | 0;\n protected Fh: number = T224_IV[10] | 0;\n protected Fl: number = T224_IV[11] | 0;\n protected Gh: number = T224_IV[12] | 0;\n protected Gl: number = T224_IV[13] | 0;\n protected Hh: number = T224_IV[14] | 0;\n protected Hl: number = T224_IV[15] | 0;\n\n constructor() {\n super(28);\n }\n}\n\nexport class SHA512_256 extends SHA512 {\n protected Ah: number = T256_IV[0] | 0;\n protected Al: number = T256_IV[1] | 0;\n protected Bh: number = T256_IV[2] | 0;\n protected Bl: number = T256_IV[3] | 0;\n protected Ch: number = T256_IV[4] | 0;\n protected Cl: number = T256_IV[5] | 0;\n protected Dh: number = T256_IV[6] | 0;\n protected Dl: number = T256_IV[7] | 0;\n protected Eh: number = T256_IV[8] | 0;\n protected El: number = T256_IV[9] | 0;\n protected Fh: number = T256_IV[10] | 0;\n protected Fl: number = T256_IV[11] | 0;\n protected Gh: number = T256_IV[12] | 0;\n protected Gl: number = T256_IV[13] | 0;\n protected Hh: number = T256_IV[14] | 0;\n protected Hl: number = T256_IV[15] | 0;\n\n constructor() {\n super(32);\n }\n}\n\n/**\n * SHA2-256 hash function from RFC 4634.\n *\n * It is the fastest JS hash, even faster than Blake3.\n * To break sha256 using birthday attack, attackers need to try 2^128 hashes.\n * BTC network is doing 2^70 hashes/sec (2^95 hashes/year) as per 2025.\n */\nexport const sha256: CHash = /* @__PURE__ */ createHasher(() => new SHA256());\n/** SHA2-224 hash function from RFC 4634 */\nexport const sha224: CHash = /* @__PURE__ */ createHasher(() => new SHA224());\n\n/** SHA2-512 hash function from RFC 4634. */\nexport const sha512: CHash = /* @__PURE__ */ createHasher(() => new SHA512());\n/** SHA2-384 hash function from RFC 4634. */\nexport const sha384: CHash = /* @__PURE__ */ createHasher(() => new SHA384());\n\n/**\n * SHA2-512/256 \"truncated\" hash function, with improved resistance to length extension attacks.\n * See the paper on [truncated SHA512](https://eprint.iacr.org/2010/548.pdf).\n */\nexport const sha512_256: CHash = /* @__PURE__ */ createHasher(() => new SHA512_256());\n/**\n * SHA2-512/224 \"truncated\" hash function, with improved resistance to length extension attacks.\n * See the paper on [truncated SHA512](https://eprint.iacr.org/2010/548.pdf).\n */\nexport const sha512_224: CHash = /* @__PURE__ */ createHasher(() => new SHA512_224());\n", "import { base32Decode, base32Encode } from './utils/base32.ts';\nimport { getCrc32 } from './utils/getCrc.ts';\nimport { sha224 } from '@noble/hashes/sha2';\nimport { bytesToHex, hexToBytes } from '@noble/hashes/utils';\n\nexport const JSON_KEY_PRINCIPAL = '__principal__';\nconst SELF_AUTHENTICATING_SUFFIX = 2;\nconst ANONYMOUS_SUFFIX = 4;\n\nconst MANAGEMENT_CANISTER_PRINCIPAL_TEXT_STR = 'aaaaa-aa';\n\nexport interface JsonnablePrincipal {\n [JSON_KEY_PRINCIPAL]: string;\n}\n\nexport class Principal {\n public static anonymous(): Principal {\n return new this(new Uint8Array([ANONYMOUS_SUFFIX]));\n }\n\n /**\n * Utility method, returning the principal representing the management canister, decoded from the hex string `'aaaaa-aa'`\n * @returns {Principal} principal of the management canister\n */\n public static managementCanister(): Principal {\n return this.fromText(MANAGEMENT_CANISTER_PRINCIPAL_TEXT_STR);\n }\n\n public static selfAuthenticating(publicKey: Uint8Array): Principal {\n const sha = sha224(publicKey);\n return new this(new Uint8Array([...sha, SELF_AUTHENTICATING_SUFFIX]));\n }\n\n public static from(other: unknown): Principal {\n if (typeof other === 'string') {\n return Principal.fromText(other);\n }\n if (Object.getPrototypeOf(other) === Uint8Array.prototype) {\n return new Principal(other as Uint8Array);\n }\n if (Principal.isPrincipal(other)) {\n return new Principal(other._arr);\n }\n\n throw new Error(`Impossible to convert ${JSON.stringify(other)} to Principal.`);\n }\n\n public static fromHex(hex: string): Principal {\n return new this(hexToBytes(hex));\n }\n\n public static fromText(text: string): Principal {\n let maybePrincipal = text;\n // If formatted as JSON string, parse it first\n if (text.includes(JSON_KEY_PRINCIPAL)) {\n const obj = JSON.parse(text);\n if (JSON_KEY_PRINCIPAL in obj) {\n maybePrincipal = obj[JSON_KEY_PRINCIPAL];\n }\n }\n\n const canisterIdNoDash = maybePrincipal.toLowerCase().replace(/-/g, '');\n\n let arr = base32Decode(canisterIdNoDash);\n arr = arr.slice(4, arr.length);\n\n const principal = new this(arr);\n if (principal.toText() !== maybePrincipal) {\n throw new Error(\n `Principal \"${principal.toText()}\" does not have a valid checksum (original value \"${maybePrincipal}\" may not be a valid Principal ID).`,\n );\n }\n\n return principal;\n }\n\n public static fromUint8Array(arr: Uint8Array): Principal {\n return new this(arr);\n }\n\n public static isPrincipal(other: unknown): other is Principal {\n return (\n other instanceof Principal ||\n (typeof other === 'object' &&\n other !== null &&\n '_isPrincipal' in other &&\n (other as { _isPrincipal: boolean })['_isPrincipal'] === true &&\n '_arr' in other &&\n (other as { _arr: Uint8Array })['_arr'] instanceof Uint8Array)\n );\n }\n\n public readonly _isPrincipal = true;\n\n protected constructor(private _arr: Uint8Array) {}\n\n public isAnonymous(): boolean {\n return this._arr.byteLength === 1 && this._arr[0] === ANONYMOUS_SUFFIX;\n }\n\n public toUint8Array(): Uint8Array {\n return this._arr;\n }\n\n public toHex(): string {\n return bytesToHex(this._arr).toUpperCase();\n }\n\n public toText(): string {\n const checksumArrayBuf = new ArrayBuffer(4);\n const view = new DataView(checksumArrayBuf);\n view.setUint32(0, getCrc32(this._arr));\n const checksum = new Uint8Array(checksumArrayBuf);\n\n const array = new Uint8Array([...checksum, ...this._arr]);\n\n const result = base32Encode(array);\n const matches = result.match(/.{1,5}/g);\n if (!matches) {\n // This should only happen if there's no character, which is unreachable.\n throw new Error();\n }\n return matches.join('-');\n }\n\n public toString(): string {\n return this.toText();\n }\n\n /**\n * Serializes to JSON\n * @returns {JsonnablePrincipal} a JSON object with a single key, {@link JSON_KEY_PRINCIPAL}, whose value is the principal as a string\n */\n public toJSON(): JsonnablePrincipal {\n return { [JSON_KEY_PRINCIPAL]: this.toText() };\n }\n\n /**\n * Utility method taking a Principal to compare against. Used for determining canister ranges in certificate verification\n * @param {Principal} other - a {@link Principal} to compare\n * @returns {'lt' | 'eq' | 'gt'} `'lt' | 'eq' | 'gt'` a string, representing less than, equal to, or greater than\n */\n public compareTo(other: Principal): 'lt' | 'eq' | 'gt' {\n for (let i = 0; i < Math.min(this._arr.length, other._arr.length); i++) {\n if (this._arr[i] < other._arr[i]) {\n return 'lt';\n }\n if (this._arr[i] > other._arr[i]) {\n return 'gt';\n }\n }\n // Here, at least one principal is a prefix of the other principal (they could be the same)\n if (this._arr.length < other._arr.length) {\n return 'lt';\n }\n if (this._arr.length > other._arr.length) {\n return 'gt';\n }\n return 'eq';\n }\n\n /**\n * Utility method checking whether a provided Principal is less than or equal to the current one using the {@link Principal.compareTo} method\n * @param other a {@link Principal} to compare\n * @returns {boolean} boolean\n */\n public ltEq(other: Principal): boolean {\n const cmp = this.compareTo(other);\n return cmp == 'lt' || cmp == 'eq';\n }\n\n /**\n * Utility method checking whether a provided Principal is greater than or equal to the current one using the {@link Principal.compareTo} method\n * @param other a {@link Principal} to compare\n * @returns {boolean} boolean\n */\n public gtEq(other: Principal): boolean {\n const cmp = this.compareTo(other);\n return cmp == 'gt' || cmp == 'eq';\n }\n}\n", "import {Principal} from '@icp-sdk/core/principal';\nimport {nonNullish} from './nullish.utils';\n\nconst JSON_KEY_BIGINT = '__bigint__';\nconst JSON_KEY_PRINCIPAL = '__principal__';\nconst JSON_KEY_UINT8ARRAY = '__uint8array__';\n\n/**\n * A custom replacer for `JSON.stringify` that converts specific types not natively supported\n * by the API into JSON-compatible formats.\n *\n * Supported conversions:\n * - `BigInt` \u2192 `{ \"__bigint__\": string }`\n * - `Principal` \u2192 `{ \"__principal__\": string }`\n * - `Uint8Array` \u2192 `{ \"__uint8array__\": number[] }`\n *\n * @param {string} _key - Ignored. Only provided for API compatibility.\n * @param {unknown} value - The value to transform before stringification.\n * @returns {unknown} The transformed value if it matches a known type, otherwise the original value.\n */\n// eslint-disable-next-line local-rules/prefer-object-params\nexport const jsonReplacer = (_key: string, value: unknown): unknown => {\n if (typeof value === 'bigint') {\n return {[JSON_KEY_BIGINT]: `${value}`};\n }\n\n if (nonNullish(value) && Principal.isPrincipal(value)) {\n // isPrincipal asserts if a value is a Principal, but does not assert if the object\n // contains functions such as toText(). That's why we construct a new object.\n return {[JSON_KEY_PRINCIPAL]: Principal.from(value).toText()};\n }\n\n if (nonNullish(value) && value instanceof Uint8Array) {\n return {[JSON_KEY_UINT8ARRAY]: Array.from(value)};\n }\n\n return value;\n};\n\n/**\n * A custom reviver for `JSON.parse` that reconstructs specific types from their JSON-encoded representations.\n *\n * This reverses the transformations applied by `jsonReplacer`, restoring the original types.\n *\n * Supported conversions:\n * - `{ \"__bigint__\": string }` \u2192 `BigInt`\n * - `{ \"__principal__\": string }` \u2192 `Principal`\n * - `{ \"__uint8array__\": number[] }` \u2192 `Uint8Array`\n *\n * @param {string} _key - Ignored but provided for API compatibility.\n * @param {unknown} value - The parsed value to transform.\n * @returns {unknown} The reconstructed value if it matches a known type, otherwise the original value.\n */\n// eslint-disable-next-line local-rules/prefer-object-params\nexport const jsonReviver = (_key: string, value: unknown): unknown => {\n const mapValue = <T>(key: string): T => (value as Record<string, T>)[key];\n\n if (nonNullish(value) && typeof value === 'object' && JSON_KEY_BIGINT in value) {\n return BigInt(mapValue(JSON_KEY_BIGINT));\n }\n\n if (nonNullish(value) && typeof value === 'object' && JSON_KEY_PRINCIPAL in value) {\n return Principal.fromText(mapValue(JSON_KEY_PRINCIPAL));\n }\n\n if (nonNullish(value) && typeof value === 'object' && JSON_KEY_UINT8ARRAY in value) {\n return Uint8Array.from(mapValue(JSON_KEY_UINT8ARRAY));\n }\n\n return value;\n};\n", "import {jsonReplacer, jsonReviver} from './json.utils';\n\n/**\n * Converts data to a Uint8Array for transmission or storage.\n * @template T\n * @param {T} data - The data to convert.\n * @returns {Promise<Uint8Array>} A promise that resolves to a Uint8Array representation of the data.\n */\nexport const toArray = async <T>(data: T): Promise<Uint8Array> => {\n const blob = new Blob([JSON.stringify(data, jsonReplacer)], {\n type: 'application/json; charset=utf-8'\n });\n return new Uint8Array(await blob.arrayBuffer());\n};\n\n/**\n * Converts a Uint8Array or number array back to the original data type.\n * @template T\n * @param {(Uint8Array | number[])} data - The array to convert.\n * @returns {Promise<T>} A promise that resolves to the original data.\n */\nexport const fromArray = async <T>(data: Uint8Array | number[]): Promise<T> => {\n const blob = new Blob(\n [data instanceof Uint8Array ? (data as Uint8Array<ArrayBuffer>) : new Uint8Array(data)],\n {\n type: 'application/json; charset=utf-8'\n }\n );\n return JSON.parse(await blob.text(), jsonReviver);\n};\n", "/**\n * Checks if the current environment is a browser.\n * @returns {boolean} True if the current environment is a browser, false otherwise.\n */\nexport const isBrowser = (): boolean => typeof window !== `undefined`;\n", "// Source: https://stackoverflow.com/a/77489094/5404186\nexport const convertCamelToSnake = (str: string): string =>\n str.replace(/([a-zA-Z])(?=[A-Z])/g, '$1_').toLowerCase();\n\nexport const capitalize = (str: string): string => str.charAt(0).toUpperCase() + str.slice(1);\n"],
|
|
5
|
-
"mappings": "AAAO,IAAMA,EAAN,cAAqC,KAAM,CAAC,EACtCC,EAAN,cAA2B,KAAM,CAAC,EAE5BC,EAI0B,CAAIC,EAAUC,IAA2B,CAC9E,GAAID,GAAU,KACZ,MA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wBA,EAAI,OAAO,CAAC,EAAE,YAAY,EAAIA,EAAI,MAAM,CAAC",
|
|
6
|
-
"names": ["InvalidPercentageError", "NullishError", "assertNonNullish", "value", "message", "asNonNullish", "assertPercentageNumber", "percentage", "assertNever", "_", "uint8ArrayToBigInt", "array", "view", "high", "low", "bigIntToUint8Array", "value", "buffer", "numberToUint8Array", "index", "arrayBufferToUint8Array", "uint8ArrayToArrayOfNumber", "arrayOfNumberToUint8Array", "numbers", "asciiStringToByteArray", "text", "c", "hexStringToUint8Array", "hexString", "matches", "assertNonNullish", "byte", "uint8ArraysEqual", "a", "b", "i", "uint8ArrayToHexString", "bytes", "str", "candidNumberArrayToBigInt", "result", "uint8ArrayToBase64", "uint8Array", "chunks", "i", "base64ToUint8Array", "base64String", "c", "NANOSECONDS_PER_MILLISECOND", "nowInBigIntNanoSeconds", "toBigIntNanoSeconds", "date", "debounce", "func", "timeout", "timer", "args", "next", "isNullish", "argument", "nonNullish", "notEmptyString", "value", "isEmptyString", "toNullable", "value", "nonNullish", "fromNullable", "fromDefinedNullable", "result", "assertNonNullish", "fromNullishNullable", "
|
|
3
|
+
"sources": ["../../src/utils/asserts.utils.ts", "../../src/utils/arrays.utils.ts", "../../src/utils/base64.utils.ts", "../../src/utils/date.utils.ts", "../../src/utils/debounce.utils.ts", "../../src/utils/nullish.utils.ts", "../../src/utils/did.utils.ts", "../../src/utils/json.utils.ts", "../../src/utils/doc.utils.ts", "../../src/utils/env.utils.ts", "../../src/utils/string.utils.ts"],
|
|
4
|
+
"sourcesContent": ["export class InvalidPercentageError extends Error {}\nexport class NullishError extends Error {}\n\nexport const assertNonNullish: <T>(\n value: T,\n message?: string\n // eslint-disable-next-line local-rules/prefer-object-params\n) => asserts value is NonNullable<T> = <T>(value: T, message?: string): void => {\n if (value === null || value === undefined) {\n throw new NullishError(message);\n }\n};\n\n// eslint-disable-next-line local-rules/prefer-object-params\nexport const asNonNullish = <T>(value: T, message?: string): NonNullable<T> => {\n assertNonNullish(value, message);\n return value;\n};\n\nexport const assertPercentageNumber = (percentage: number) => {\n if (percentage < 0 || percentage > 100) {\n throw new InvalidPercentageError(`${percentage} is not a valid percentage number.`);\n }\n};\n\n/**\n * Utility to enforce exhaustiveness checks in TypeScript.\n *\n * This function should only be called in branches of a `switch` or conditional\n * that should be unreachable if the union type has been fully handled.\n *\n * By typing the parameter as `never`, the compiler will emit an error if\n * a new variant is added to the union but not covered in the logic.\n *\n * @param _ - A value that should be of type `never`. If this is not the case,\n * the TypeScript compiler will flag a type error.\n * @param message - Optional custom error message to include in the thrown error.\n * @throws {Error} Always throws when invoked at runtime.\n *\n */\n// eslint-disable-next-line local-rules/prefer-object-params\nexport const assertNever = (_: never, message?: string): never => {\n throw new Error(message);\n};\n", "import {assertNonNullish} from './asserts.utils';\n\nexport const uint8ArrayToBigInt = (array: Uint8Array): bigint => {\n const view = new DataView(array.buffer, array.byteOffset, array.byteLength);\n if (typeof view.getBigUint64 === 'function') {\n return view.getBigUint64(0);\n }\n const high = BigInt(view.getUint32(0));\n const low = BigInt(view.getUint32(4));\n\n return (high << BigInt(32)) + low;\n};\n\nexport const bigIntToUint8Array = (value: bigint): Uint8Array => {\n const buffer = new ArrayBuffer(8);\n const view = new DataView(buffer);\n if (typeof view.setBigUint64 === 'function') {\n view.setBigUint64(0, value);\n } else {\n const high = Number(value >> BigInt(32));\n const low = Number(value & BigInt(0xffffffff));\n\n view.setUint32(0, high);\n view.setUint32(4, low);\n }\n\n return new Uint8Array(buffer);\n};\n\nexport const numberToUint8Array = (value: number): Uint8Array => {\n const view = new DataView(new ArrayBuffer(8));\n for (let index = 7; index >= 0; --index) {\n view.setUint8(index, value % 256);\n value = value >> 8;\n }\n return new Uint8Array(view.buffer);\n};\n\nexport const arrayBufferToUint8Array = (buffer: ArrayBuffer): Uint8Array => new Uint8Array(buffer);\n\nexport const uint8ArrayToArrayOfNumber = (array: Uint8Array): Array<number> => Array.from(array);\n\nexport const arrayOfNumberToUint8Array = (numbers: Array<number>): Uint8Array =>\n new Uint8Array(numbers);\n\nexport const asciiStringToByteArray = (text: string): Array<number> =>\n Array.from(text).map((c) => c.charCodeAt(0));\n\nexport const hexStringToUint8Array = (hexString: string): Uint8Array => {\n const matches = hexString.match(/.{1,2}/g);\n\n assertNonNullish(matches, 'Invalid hex string.');\n\n return Uint8Array.from(matches.map((byte) => parseInt(byte, 16)));\n};\n\n/**\n * Compare two Uint8Arrays for byte-level equality.\n *\n * @param {Object} params\n * @param {Uint8Array} params.a - First Uint8Array to compare.\n * @param {Uint8Array} params.b - Second Uint8Array to compare.\n * @returns {boolean} True if both arrays have the same length and identical contents.\n */\nexport const uint8ArraysEqual = ({a, b}: {a: Uint8Array; b: Uint8Array}) =>\n a.length === b.length && a.every((byte, i) => byte === b[i]);\n\nexport const uint8ArrayToHexString = (bytes: Uint8Array | number[]) => {\n if (!(bytes instanceof Uint8Array)) {\n bytes = Uint8Array.from(bytes);\n }\n return bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), '');\n};\n\nexport const candidNumberArrayToBigInt = (array: number[]): bigint => {\n let result = 0n;\n for (let i = array.length - 1; i >= 0; i--) {\n result = (result << 32n) + BigInt(array[i]);\n }\n return result;\n};\n", "/**\n * Converts a Uint8Array (binary data) to a base64 encoded string.\n *\n * @param {Uint8Array} uint8Array - The Uint8Array containing binary data to be encoded.\n * @returns {string} - The base64 encoded string representation of the binary data.\n */\nexport const uint8ArrayToBase64 = (uint8Array: Uint8Array): string => {\n // Spreading large Uint8Arrays or using Array.from loses precision when used together with String.fromCharCode.\n // Therefore, we use a chunked loop, which better than a reducer or iterating on every value.\n // Spreading a small chunk - such as 32kb - works as expected.\n const chunkSize = 0x8000; // 32 kb\n const chunks: string[] = [];\n for (let i = 0; i < uint8Array.length; i += chunkSize) {\n chunks.push(String.fromCharCode(...uint8Array.subarray(i, i + chunkSize)));\n }\n return btoa(chunks.join(''));\n};\n\n/**\n * Converts a base64 encoded string to a Uint8Array (binary data).\n *\n * @param {string} base64String - The base64 encoded string to be decoded.\n * @returns {Uint8Array} - The Uint8Array representation of the decoded binary data.\n */\nexport const base64ToUint8Array = (base64String: string): Uint8Array =>\n Uint8Array.from(atob(base64String), (c) => c.charCodeAt(0));\n", "const NANOSECONDS_PER_MILLISECOND = 1_000_000n;\n\n/**\n * Returns the current timestamp in nanoseconds as a `bigint`.\n *\n * @returns {bigint} The current timestamp in nanoseconds.\n */\nexport const nowInBigIntNanoSeconds = (): bigint =>\n BigInt(Date.now()) * NANOSECONDS_PER_MILLISECOND;\n\n/**\n * Converts a given `Date` object to a timestamp in nanoseconds as a `bigint`.\n *\n * @param {Date} date - The `Date` object to convert.\n * @returns {bigint} The timestamp in nanoseconds.\n */\nexport const toBigIntNanoSeconds = (date: Date): bigint =>\n BigInt(date.getTime()) * NANOSECONDS_PER_MILLISECOND;\n", "/**\n * Creates a debounced version of the provided function.\n *\n * The debounced function postpones its execution until after a certain amount of time\n * has elapsed since the last time it was invoked. This is useful for limiting the rate\n * at which a function is called (e.g. in response to user input or events).\n *\n * @param {Function} func - The function to debounce. It will only be called after no new calls happen within the specified timeout.\n * @param {number} [timeout=300] - The debounce delay in milliseconds. Defaults to 300ms if not provided or invalid.\n * @returns {(args: unknown[]) => void} A debounced version of the original function.\n */\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type, local-rules/prefer-object-params\nexport const debounce = (func: Function, timeout?: number) => {\n let timer: NodeJS.Timer | undefined;\n\n return (...args: unknown[]) => {\n const next = () => func(...args);\n\n if (timer) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore TypeScript global and window confusion even if we are using @types/node\n clearTimeout(timer);\n }\n\n timer = setTimeout(next, timeout !== undefined && timeout > 0 ? timeout : 300);\n };\n};\n", "/**\n * Checks if a given argument is null or undefined.\n *\n * @template T - The type of the argument.\n * @param {T | undefined | null} argument - The argument to check.\n * @returns {argument is undefined | null} `true` if the argument is null or undefined; otherwise, `false`.\n */\nexport const isNullish = <T>(argument: T | undefined | null): argument is undefined | null =>\n argument === null || argument === undefined;\n\n/**\n * Checks if a given argument is neither null nor undefined.\n *\n * @template T - The type of the argument.\n * @param {T | undefined | null} argument - The argument to check.\n * @returns {argument is NonNullable<T>} `true` if the argument is not null or undefined; otherwise, `false`.\n */\nexport const nonNullish = <T>(argument: T | undefined | null): argument is NonNullable<T> =>\n !isNullish(argument);\n\n/**\n * Checks if a given value is not null, not undefined, and not an empty string.\n *\n * @param {string | undefined | null} value - The value to check.\n * @returns {boolean} `true` if the value is not null, not undefined, and not an empty string; otherwise, `false`.\n */\nexport const notEmptyString = (value: string | undefined | null): value is string =>\n nonNullish(value) && value !== '';\n\n/**\n * Checks if a given value is null, undefined, or an empty string.\n *\n * @param {string | undefined | null} value - The value to check.\n * @returns {value is undefined | null | \"\"} Type predicate indicating if the value is null, undefined, or an empty string.\n */\nexport const isEmptyString = (value: string | undefined | null): value is undefined | null | '' =>\n !notEmptyString(value);\n", "import type {Nullable, NullishNullable} from '../types/did.utils';\nimport {assertNonNullish} from './asserts.utils';\nimport {nonNullish} from './nullish.utils';\n\n/**\n * Converts a value into a Candid-style variant representation of an optional value.\n *\n * @template T The type of the value.\n * @param {T | null | undefined} value - The value to convert into a Candid-style variant.\n * @returns {Nullable<T>} A Candid-style variant representation: an empty array for `null` and `undefined` or an array with the value.\n */\nexport const toNullable = <T>(value?: T | null): Nullable<T> => (nonNullish(value) ? [value] : []);\n\n/**\n * Extracts the value from a Candid-style variant representation of an optional value.\n *\n * @template T The type of the value.\n * @param {Nullable<T>} value - A Candid-style variant representing an optional value.\n * @returns {T | undefined} The extracted value, or `undefined` if the array is empty.\n */\nexport const fromNullable = <T>(value: Nullable<T>): T | undefined => value?.[0];\n\n/**\n * Extracts the value from a Candid-style variant representation of an optional value,\n * ensuring the value is defined. Throws an error if the array is empty or the value is nullish.\n *\n * @template T The type of the value.\n * @param {Nullable<T>} value - A Candid-style variant representing an optional value.\n * @returns {T} The extracted value.\n * @throws {Error} If the array is empty or the value is nullish.\n */\nexport const fromDefinedNullable = <T>(value: Nullable<T>): T => {\n const result = fromNullable(value);\n\n assertNonNullish(result);\n\n return result;\n};\n\n/**\n * Extracts the value from a nullish Candid-style variant representation.\n *\n * @template T The type of the value.\n * @param {NullishNullable<T>} value - A Candid-style variant or `undefined`.\n * @returns {T | undefined} The extracted value, or `undefined` if the input is nullish or the array is empty.\n */\nexport const fromNullishNullable = <T>(value: NullishNullable<T>): T | undefined =>\n fromNullable(value ?? []);\n", "import {Principal} from '@icp-sdk/core/principal';\nimport {nonNullish} from './nullish.utils';\n\nconst JSON_KEY_BIGINT = '__bigint__';\nconst JSON_KEY_PRINCIPAL = '__principal__';\nconst JSON_KEY_UINT8ARRAY = '__uint8array__';\n\n/**\n * A custom replacer for `JSON.stringify` that converts specific types not natively supported\n * by the API into JSON-compatible formats.\n *\n * Supported conversions:\n * - `BigInt` \u2192 `{ \"__bigint__\": string }`\n * - `Principal` \u2192 `{ \"__principal__\": string }`\n * - `Uint8Array` \u2192 `{ \"__uint8array__\": number[] }`\n *\n * @param {string} _key - Ignored. Only provided for API compatibility.\n * @param {unknown} value - The value to transform before stringification.\n * @returns {unknown} The transformed value if it matches a known type, otherwise the original value.\n */\n// eslint-disable-next-line local-rules/prefer-object-params\nexport const jsonReplacer = (_key: string, value: unknown): unknown => {\n if (typeof value === 'bigint') {\n return {[JSON_KEY_BIGINT]: `${value}`};\n }\n\n if (nonNullish(value) && Principal.isPrincipal(value)) {\n // isPrincipal asserts if a value is a Principal, but does not assert if the object\n // contains functions such as toText(). That's why we construct a new object.\n return {[JSON_KEY_PRINCIPAL]: Principal.from(value).toText()};\n }\n\n if (nonNullish(value) && value instanceof Uint8Array) {\n return {[JSON_KEY_UINT8ARRAY]: Array.from(value)};\n }\n\n return value;\n};\n\n/**\n * A custom reviver for `JSON.parse` that reconstructs specific types from their JSON-encoded representations.\n *\n * This reverses the transformations applied by `jsonReplacer`, restoring the original types.\n *\n * Supported conversions:\n * - `{ \"__bigint__\": string }` \u2192 `BigInt`\n * - `{ \"__principal__\": string }` \u2192 `Principal`\n * - `{ \"__uint8array__\": number[] }` \u2192 `Uint8Array`\n *\n * @param {string} _key - Ignored but provided for API compatibility.\n * @param {unknown} value - The parsed value to transform.\n * @returns {unknown} The reconstructed value if it matches a known type, otherwise the original value.\n */\n// eslint-disable-next-line local-rules/prefer-object-params\nexport const jsonReviver = (_key: string, value: unknown): unknown => {\n const mapValue = <T>(key: string): T => (value as Record<string, T>)[key];\n\n if (nonNullish(value) && typeof value === 'object' && JSON_KEY_BIGINT in value) {\n return BigInt(mapValue(JSON_KEY_BIGINT));\n }\n\n if (nonNullish(value) && typeof value === 'object' && JSON_KEY_PRINCIPAL in value) {\n return Principal.fromText(mapValue(JSON_KEY_PRINCIPAL));\n }\n\n if (nonNullish(value) && typeof value === 'object' && JSON_KEY_UINT8ARRAY in value) {\n return Uint8Array.from(mapValue(JSON_KEY_UINT8ARRAY));\n }\n\n return value;\n};\n", "import {jsonReplacer, jsonReviver} from './json.utils';\n\n/**\n * Converts data to a Uint8Array for transmission or storage.\n * @template T\n * @param {T} data - The data to convert.\n * @returns {Promise<Uint8Array>} A promise that resolves to a Uint8Array representation of the data.\n */\nexport const toArray = async <T>(data: T): Promise<Uint8Array> => {\n const blob = new Blob([JSON.stringify(data, jsonReplacer)], {\n type: 'application/json; charset=utf-8'\n });\n return new Uint8Array(await blob.arrayBuffer());\n};\n\n/**\n * Converts a Uint8Array or number array back to the original data type.\n * @template T\n * @param {(Uint8Array | number[])} data - The array to convert.\n * @returns {Promise<T>} A promise that resolves to the original data.\n */\nexport const fromArray = async <T>(data: Uint8Array | number[]): Promise<T> => {\n const blob = new Blob(\n [data instanceof Uint8Array ? (data as Uint8Array<ArrayBuffer>) : new Uint8Array(data)],\n {\n type: 'application/json; charset=utf-8'\n }\n );\n return JSON.parse(await blob.text(), jsonReviver);\n};\n", "/**\n * Checks if the current environment is a browser.\n * @returns {boolean} True if the current environment is a browser, false otherwise.\n */\nexport const isBrowser = (): boolean => typeof window !== `undefined`;\n", "// Source: https://stackoverflow.com/a/77489094/5404186\nexport const convertCamelToSnake = (str: string): string =>\n str.replace(/([a-zA-Z])(?=[A-Z])/g, '$1_').toLowerCase();\n\nexport const capitalize = (str: string): string => str.charAt(0).toUpperCase() + str.slice(1);\n"],
|
|
5
|
+
"mappings": "AAAO,IAAMA,EAAN,cAAqC,KAAM,CAAC,EACtCC,EAAN,cAA2B,KAAM,CAAC,EAE5BC,EAI0B,CAAIC,EAAUC,IAA2B,CAC9E,GAAID,GAAU,KACZ,MAAM,IAAIF,EAAaG,CAAO,CAElC,EAGaC,EAAe,CAAIF,EAAUC,KACxCF,EAAiBC,EAAOC,CAAO,EACxBD,GAGIG,EAA0BC,GAAuB,CAC5D,GAAIA,EAAa,GAAKA,EAAa,IACjC,MAAM,IAAIP,EAAuB,GAAGO,CAAU,oCAAoC,CAEtF,EAkBaC,EAAc,CAACC,EAAUL,IAA4B,CAChE,MAAM,IAAI,MAAMA,CAAO,CACzB,ECzCO,IAAMM,EAAsBC,GAA8B,CAC/D,IAAMC,EAAO,IAAI,SAASD,EAAM,OAAQA,EAAM,WAAYA,EAAM,UAAU,EAC1E,GAAI,OAAOC,EAAK,cAAiB,WAC/B,OAAOA,EAAK,aAAa,CAAC,EAE5B,IAAMC,EAAO,OAAOD,EAAK,UAAU,CAAC,CAAC,EAC/BE,EAAM,OAAOF,EAAK,UAAU,CAAC,CAAC,EAEpC,OAAQC,GAAQ,OAAO,EAAE,GAAKC,CAChC,EAEaC,EAAsBC,GAA8B,CAC/D,IAAMC,EAAS,IAAI,YAAY,CAAC,EAC1BL,EAAO,IAAI,SAASK,CAAM,EAChC,GAAI,OAAOL,EAAK,cAAiB,WAC/BA,EAAK,aAAa,EAAGI,CAAK,MACrB,CACL,IAAMH,EAAO,OAAOG,GAAS,OAAO,EAAE,CAAC,EACjCF,EAAM,OAAOE,EAAQ,OAAO,UAAU,CAAC,EAE7CJ,EAAK,UAAU,EAAGC,CAAI,E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alidPercentageError", "NullishError", "assertNonNullish", "value", "message", "asNonNullish", "assertPercentageNumber", "percentage", "assertNever", "_", "uint8ArrayToBigInt", "array", "view", "high", "low", "bigIntToUint8Array", "value", "buffer", "numberToUint8Array", "index", "arrayBufferToUint8Array", "uint8ArrayToArrayOfNumber", "arrayOfNumberToUint8Array", "numbers", "asciiStringToByteArray", "text", "c", "hexStringToUint8Array", "hexString", "matches", "assertNonNullish", "byte", "uint8ArraysEqual", "a", "b", "i", "uint8ArrayToHexString", "bytes", "str", "candidNumberArrayToBigInt", "result", "uint8ArrayToBase64", "uint8Array", "chunks", "i", "base64ToUint8Array", "base64String", "c", "NANOSECONDS_PER_MILLISECOND", "nowInBigIntNanoSeconds", "toBigIntNanoSeconds", "date", "debounce", "func", "timeout", "timer", "args", "next", "isNullish", "argument", "nonNullish", "notEmptyString", "value", "isEmptyString", "toNullable", "value", "nonNullish", "fromNullable", "fromDefinedNullable", "result", "assertNonNullish", "fromNullishNullable", "Principal", "JSON_KEY_BIGINT", "JSON_KEY_PRINCIPAL", "JSON_KEY_UINT8ARRAY", "jsonReplacer", "_key", "value", "nonNullish", "Principal", "jsonReviver", "mapValue", "key", "toArray", "data", "blob", "jsonReplacer", "fromArray", "jsonReviver", "isBrowser", "convertCamelToSnake", "str", "capitalize"]
|
|
7
7
|
}
|
package/dist/node/index.mjs
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
import { createRequire as topLevelCreateRequire } from 'module';
|
|
2
2
|
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
-
var L=class extends Error{},C=class extends Error{},U=(e,t)=>{if(e==null)throw new C(t)},ut=(e,t)=>(U(e,t),e),lt=e=>{if(e<0||e>100)throw new L(`${e} is not a valid percentage number.`)},pt=(e,t)=>{throw new Error(t)};var mt=e=>{let t=new DataView(e.buffer,e.byteOffset,e.byteLength);if(typeof t.getBigUint64=="function")return t.getBigUint64(0);let r=BigInt(t.getUint32(0)),n=BigInt(t.getUint32(4));return(r<<BigInt(32))+n},At=e=>{let t=new ArrayBuffer(8),r=new DataView(t);if(typeof r.setBigUint64=="function")r.setBigUint64(0,e);else{let n=Number(e>>BigInt(32)),o=Number(e&BigInt(4294967295));r.setUint32(0,n),r.setUint32(4,o)}return new Uint8Array(t)},wt=e=>{let t=new DataView(new ArrayBuffer(8));for(let r=7;r>=0;--r)t.setUint8(r,e%256),e=e>>8;return new Uint8Array(t.buffer)},Ut=e=>new Uint8Array(e),Tt=e=>Array.from(e),_t=e=>new Uint8Array(e),Bt=e=>Array.from(e).map(t=>t.charCodeAt(0)),Nt=e=>{let t=e.match(/.{1,2}/g);return U(t,"Invalid hex string."),Uint8Array.from(t.map(r=>parseInt(r,16)))},St=({a:e,b:t})=>e.length===t.length&&e.every((r,n)=>r===t[n]),Ht=e=>(e instanceof Uint8Array||(e=Uint8Array.from(e)),e.reduce((t,r)=>t+r.toString(16).padStart(2,"0"),"")),Et=e=>{let t=0n;for(let r=e.length-1;r>=0;r--)t=(t<<32n)+BigInt(e[r]);return t};var Lt=e=>{let r=[];for(let n=0;n<e.length;n+=32768)r.push(String.fromCharCode(...e.subarray(n,n+32768)));return btoa(r.join(""))},Ct=e=>Uint8Array.from(atob(e),t=>t.charCodeAt(0));var R=1000000n,kt=()=>BigInt(Date.now())*R,Ft=e=>BigInt(e.getTime())*R;var Gt=(e,t)=>{let r;return(...n)=>{let o=()=>e(...n);r&&clearTimeout(r),r=setTimeout(o,t!==void 0&&t>0?t:300)}};var ot=e=>e==null,d=e=>!ot(e),it=e=>d(e)&&e!=="",jt=e=>!it(e);var Mt=e=>d(e)?[e]:[],J=e=>e?.[0],Wt=e=>{let t=J(e);return U(t),t},Kt=e=>J(e??[]);var B="abcdefghijklmnopqrstuvwxyz234567",m=Object.create(null);for(let e=0;e<B.length;e++)m[B[e]]=e;m[0]=m.o;m[1]=m.i;function M(e){let t=0,r=0,n="";function o(i){return t<0?r|=i>>-t:r=i<<t&248,t>3?(t-=8,1):(t<4&&(n+=B[r>>3],t+=5),0)}for(let i=0;i<e.length;)i+=o(e[i]);return n+(t<0?B[r>>3]:"")}function W(e){let t=0,r=0,n=new Uint8Array(e.length*4/3|0),o=0;function i(s){let c=m[s.toLowerCase()];if(c===void 0)throw new Error(`Invalid character: ${JSON.stringify(s)}`);c<<=3,r|=c>>>t,t+=5,t>=8&&(n[o++]=r,t-=8,t>0?r=c<<5-t&255:r=0)}for(let s of e)i(s);return n.slice(0,o)}var st=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 K(e){let t=-1;for(let r=0;r<e.length;r++){let o=(e[r]^t)&255;t=st[o]^t>>>8}return(t^-1)>>>0}function ct(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function T(e,...t){if(!ct(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function D(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function $(e,t){T(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function _(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function S(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function b(e,t){return e<<32-t|e>>>t}var z=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",xt=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Y(e){if(T(e),z)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=xt[e[r]];return t}var h={_0:48,_9:57,A:65,F:70,a:97,f:102};function q(e){if(e>=h._0&&e<=h._9)return e-h._0;if(e>=h.A&&e<=h.F)return e-(h.A-10);if(e>=h.a&&e<=h.f)return e-(h.a-10)}function X(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(z)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,i=0;o<r;o++,i+=2){let s=q(e.charCodeAt(i)),c=q(e.charCodeAt(i+1));if(s===void 0||c===void 0){let a=e[i]+e[i+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+i)}n[o]=s*16+c}return n}function at(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function k(e){return typeof e=="string"&&(e=at(e)),T(e),e}var N=class{};function Z(e){let t=n=>e().update(k(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function ft(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),i=BigInt(4294967295),s=Number(r>>o&i),c=Number(r&i),a=n?4:0,f=n?0:4;e.setUint32(t+a,s,n),e.setUint32(t+f,c,n)}function v(e,t,r){return e&t^~e&r}function Q(e,t,r){return e&t^e&r^t&r}var H=class extends N{constructor(t,r,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=S(this.buffer)}update(t){D(this),t=k(t),T(t);let{view:r,buffer:n,blockLen:o}=this,i=t.length;for(let s=0;s<i;){let c=Math.min(o-this.pos,i-s);if(c===o){let a=S(t);for(;o<=i-s;s+=o)this.process(a,s);continue}n.set(t.subarray(s,s+c),this.pos),this.pos+=c,s+=c,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){D(this),$(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;r[s++]=128,_(this.buffer.subarray(s)),this.padOffset>o-s&&(this.process(n,0),s=0);for(let x=s;x<o;x++)r[x]=0;ft(n,o-8,BigInt(this.length*8),i),this.process(n,0);let c=S(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=a/4,p=this.get();if(f>p.length)throw new Error("_sha2: outputLen bigger than state");for(let x=0;x<f;x++)c.setUint32(4*x,p[x],i)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:i,destroyed:s,pos:c}=this;return t.destroyed=s,t.finished=i,t.length=o,t.pos=c,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},u=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),l=Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]);var bt=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),g=new Uint32Array(64),F=class extends H{constructor(t=32){super(64,t,8,!1),this.A=u[0]|0,this.B=u[1]|0,this.C=u[2]|0,this.D=u[3]|0,this.E=u[4]|0,this.F=u[5]|0,this.G=u[6]|0,this.H=u[7]|0}get(){let{A:t,B:r,C:n,D:o,E:i,F:s,G:c,H:a}=this;return[t,r,n,o,i,s,c,a]}set(t,r,n,o,i,s,c,a){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=c|0,this.H=a|0}process(t,r){for(let x=0;x<16;x++,r+=4)g[x]=t.getUint32(r,!1);for(let x=16;x<64;x++){let w=g[x-15],y=g[x-2],P=b(w,7)^b(w,18)^w>>>3,I=b(y,17)^b(y,19)^y>>>10;g[x]=I+g[x-7]+P+g[x-16]|0}let{A:n,B:o,C:i,D:s,E:c,F:a,G:f,H:p}=this;for(let x=0;x<64;x++){let w=b(c,6)^b(c,11)^b(c,25),y=p+w+v(c,a,f)+bt[x]+g[x]|0,I=(b(n,2)^b(n,13)^b(n,22))+Q(n,o,i)|0;p=f,f=a,a=c,c=s+y|0,s=i,i=o,o=n,n=y+I|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,c=c+this.E|0,a=a+this.F|0,f=f+this.G|0,p=p+this.H|0,this.set(n,o,i,s,c,a,f,p)}roundClean(){_(g)}destroy(){this.set(0,0,0,0,0,0,0,0),_(this.buffer)}},O=class extends F{constructor(){super(28),this.A=l[0]|0,this.B=l[1]|0,this.C=l[2]|0,this.D=l[3]|0,this.E=l[4]|0,this.F=l[5]|0,this.G=l[6]|0,this.H=l[7]|0}};var tt=Z(()=>new O);var E="__principal__",dt=2,et=4,ht="aaaaa-aa",A=class e{static anonymous(){return new this(new Uint8Array([et]))}static managementCanister(){return this.fromText(ht)}static selfAuthenticating(t){let r=tt(t);return new this(new Uint8Array([...r,dt]))}static from(t){if(typeof t=="string")return e.fromText(t);if(Object.getPrototypeOf(t)===Uint8Array.prototype)return new e(t);if(e.isPrincipal(t))return new e(t._arr);throw new Error(`Impossible to convert ${JSON.stringify(t)} to Principal.`)}static fromHex(t){return new this(X(t))}static fromText(t){let r=t;if(t.includes(E)){let s=JSON.parse(t);E in s&&(r=s[E])}let n=r.toLowerCase().replace(/-/g,""),o=W(n);o=o.slice(4,o.length);let i=new this(o);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(t){return new this(t)}static isPrincipal(t){return t instanceof e||typeof t=="object"&&t!==null&&"_isPrincipal"in t&&t._isPrincipal===!0&&"_arr"in t&&t._arr instanceof Uint8Array}constructor(t){this._arr=t,this._isPrincipal=!0}isAnonymous(){return this._arr.byteLength===1&&this._arr[0]===et}toUint8Array(){return this._arr}toHex(){return Y(this._arr).toUpperCase()}toText(){let t=new ArrayBuffer(4);new DataView(t).setUint32(0,K(this._arr));let n=new Uint8Array(t),o=new Uint8Array([...n,...this._arr]),s=M(o).match(/.{1,5}/g);if(!s)throw new Error;return s.join("-")}toString(){return this.toText()}toJSON(){return{[E]:this.toText()}}compareTo(t){for(let r=0;r<Math.min(this._arr.length,t._arr.length);r++){if(this._arr[r]<t._arr[r])return"lt";if(this._arr[r]>t._arr[r])return"gt"}return this._arr.length<t._arr.length?"lt":this._arr.length>t._arr.length?"gt":"eq"}ltEq(t){let r=this.compareTo(t);return r=="lt"||r=="eq"}gtEq(t){let r=this.compareTo(t);return r=="gt"||r=="eq"}};var G="__bigint__",V="__principal__",j="__uint8array__",rt=(e,t)=>typeof t=="bigint"?{[G]:`${t}`}:d(t)&&A.isPrincipal(t)?{[V]:A.from(t).toText()}:d(t)&&t instanceof Uint8Array?{[j]:Array.from(t)}:t,nt=(e,t)=>{let r=n=>t[n];return d(t)&&typeof t=="object"&&G in t?BigInt(r(G)):d(t)&&typeof t=="object"&&V in t?A.fromText(r(V)):d(t)&&typeof t=="object"&&j in t?Uint8Array.from(r(j)):t};var de=async e=>{let t=new Blob([JSON.stringify(e,rt)],{type:"application/json; charset=utf-8"});return new Uint8Array(await t.arrayBuffer())},he=async e=>{let t=new Blob([e instanceof Uint8Array?e:new Uint8Array(e)],{type:"application/json; charset=utf-8"});return JSON.parse(await t.text(),nt)};var le=()=>typeof window<"u";var ge=e=>e.replace(/([a-zA-Z])(?=[A-Z])/g,"$1_").toLowerCase(),ye=e=>e.charAt(0).toUpperCase()+e.slice(1);export{L as InvalidPercentageError,C as NullishError,Ut as arrayBufferToUint8Array,_t as arrayOfNumberToUint8Array,ut as asNonNullish,Bt as asciiStringToByteArray,pt as assertNever,U as assertNonNullish,lt as assertPercentageNumber,Ct as base64ToUint8Array,At as bigIntToUint8Array,Et as candidNumberArrayToBigInt,ye as capitalize,ge as convertCamelToSnake,Gt as debounce,he as fromArray,Wt as fromDefinedNullable,J as fromNullable,Kt as fromNullishNullable,Nt as hexStringToUint8Array,le as isBrowser,jt as isEmptyString,ot as isNullish,rt as jsonReplacer,nt as jsonReviver,d as nonNullish,it as notEmptyString,kt as nowInBigIntNanoSeconds,wt as numberToUint8Array,de as toArray,Ft as toBigIntNanoSeconds,Mt as toNullable,Tt as uint8ArrayToArrayOfNumber,Lt as uint8ArrayToBase64,mt as uint8ArrayToBigInt,Ht as uint8ArrayToHexString,St as uint8ArraysEqual};
|
|
4
|
-
/*! Bundled license information:
|
|
5
|
-
|
|
6
|
-
@noble/hashes/esm/utils.js:
|
|
7
|
-
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
8
|
-
*/
|
|
3
|
+
var a=class extends Error{},f=class extends Error{},i=(r,n)=>{if(r==null)throw new f(n)},T=(r,n)=>(i(r,n),r),N=r=>{if(r<0||r>100)throw new a(`${r} is not a valid percentage number.`)},d=(r,n)=>{throw new Error(n)};var h=r=>{let n=new DataView(r.buffer,r.byteOffset,r.byteLength);if(typeof n.getBigUint64=="function")return n.getBigUint64(0);let t=BigInt(n.getUint32(0)),e=BigInt(n.getUint32(4));return(t<<BigInt(32))+e},B=r=>{let n=new ArrayBuffer(8),t=new DataView(n);if(typeof t.setBigUint64=="function")t.setBigUint64(0,r);else{let e=Number(r>>BigInt(32)),s=Number(r&BigInt(4294967295));t.setUint32(0,e),t.setUint32(4,s)}return new Uint8Array(n)},_=r=>{let n=new DataView(new ArrayBuffer(8));for(let t=7;t>=0;--t)n.setUint8(t,r%256),r=r>>8;return new Uint8Array(n.buffer)},I=r=>new Uint8Array(r),S=r=>Array.from(r),k=r=>new Uint8Array(r),O=r=>Array.from(r).map(n=>n.charCodeAt(0)),j=r=>{let n=r.match(/.{1,2}/g);return i(n,"Invalid hex string."),Uint8Array.from(n.map(t=>parseInt(t,16)))},C=({a:r,b:n})=>r.length===n.length&&r.every((t,e)=>t===n[e]),E=r=>(r instanceof Uint8Array||(r=Uint8Array.from(r)),r.reduce((n,t)=>n+t.toString(16).padStart(2,"0"),"")),R=r=>{let n=0n;for(let t=r.length-1;t>=0;t--)n=(n<<32n)+BigInt(r[t]);return n};var P=r=>{let t=[];for(let e=0;e<r.length;e+=32768)t.push(String.fromCharCode(...r.subarray(e,e+32768)));return btoa(t.join(""))},J=r=>Uint8Array.from(atob(r),n=>n.charCodeAt(0));var y=1000000n,L=()=>BigInt(Date.now())*y,V=r=>BigInt(r.getTime())*y;var K=(r,n)=>{let t;return(...e)=>{let s=()=>r(...e);t&&clearTimeout(t),t=setTimeout(s,n!==void 0&&n>0?n:300)}};var x=r=>r==null,o=r=>!x(r),b=r=>o(r)&&r!=="",Z=r=>!b(r);var H=r=>o(r)?[r]:[],m=r=>r?.[0],M=r=>{let n=m(r);return i(n),n},Q=r=>m(r??[]);import{Principal as u}from"@icp-sdk/core/principal";var c="__bigint__",l="__principal__",p="__uint8array__",g=(r,n)=>typeof n=="bigint"?{[c]:`${n}`}:o(n)&&u.isPrincipal(n)?{[l]:u.from(n).toText()}:o(n)&&n instanceof Uint8Array?{[p]:Array.from(n)}:n,A=(r,n)=>{let t=e=>n[e];return o(n)&&typeof n=="object"&&c in n?BigInt(t(c)):o(n)&&typeof n=="object"&&l in n?u.fromText(t(l)):o(n)&&typeof n=="object"&&p in n?Uint8Array.from(t(p)):n};var tr=async r=>{let n=new Blob([JSON.stringify(r,g)],{type:"application/json; charset=utf-8"});return new Uint8Array(await n.arrayBuffer())},er=async r=>{let n=new Blob([r instanceof Uint8Array?r:new Uint8Array(r)],{type:"application/json; charset=utf-8"});return JSON.parse(await n.text(),A)};var ir=()=>typeof window<"u";var ar=r=>r.replace(/([a-zA-Z])(?=[A-Z])/g,"$1_").toLowerCase(),fr=r=>r.charAt(0).toUpperCase()+r.slice(1);export{a as InvalidPercentageError,f as NullishError,I as arrayBufferToUint8Array,k as arrayOfNumberToUint8Array,T as asNonNullish,O as asciiStringToByteArray,d as assertNever,i as assertNonNullish,N as assertPercentageNumber,J as base64ToUint8Array,B as bigIntToUint8Array,R as candidNumberArrayToBigInt,fr as capitalize,ar as convertCamelToSnake,K as debounce,er as fromArray,M as fromDefinedNullable,m as fromNullable,Q as fromNullishNullable,j as hexStringToUint8Array,ir as isBrowser,Z as isEmptyString,x as isNullish,g as jsonReplacer,A as jsonReviver,o as nonNullish,b as notEmptyString,L as nowInBigIntNanoSeconds,_ as numberToUint8Array,tr as toArray,V as toBigIntNanoSeconds,H as toNullable,S as uint8ArrayToArrayOfNumber,P as uint8ArrayToBase64,h as uint8ArrayToBigInt,E as uint8ArrayToHexString,C as uint8ArraysEqual};
|
|
9
4
|
//# sourceMappingURL=index.mjs.map
|
package/dist/node/index.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/utils/asserts.utils.ts", "../../src/utils/arrays.utils.ts", "../../src/utils/base64.utils.ts", "../../src/utils/date.utils.ts", "../../src/utils/debounce.utils.ts", "../../src/utils/nullish.utils.ts", "../../src/utils/did.utils.ts", "
|
|
4
|
-
"sourcesContent": ["export class InvalidPercentageError extends Error {}\nexport class NullishError extends Error {}\n\nexport const assertNonNullish: <T>(\n value: T,\n message?: string\n // eslint-disable-next-line local-rules/prefer-object-params\n) => asserts value is NonNullable<T> = <T>(value: T, message?: string): void => {\n if (value === null || value === undefined) {\n throw new NullishError(message);\n }\n};\n\n// eslint-disable-next-line local-rules/prefer-object-params\nexport const asNonNullish = <T>(value: T, message?: string): NonNullable<T> => {\n assertNonNullish(value, message);\n return value;\n};\n\nexport const assertPercentageNumber = (percentage: number) => {\n if (percentage < 0 || percentage > 100) {\n throw new InvalidPercentageError(`${percentage} is not a valid percentage number.`);\n }\n};\n\n/**\n * Utility to enforce exhaustiveness checks in TypeScript.\n *\n * This function should only be called in branches of a `switch` or conditional\n * that should be unreachable if the union type has been fully handled.\n *\n * By typing the parameter as `never`, the compiler will emit an error if\n * a new variant is added to the union but not covered in the logic.\n *\n * @param _ - A value that should be of type `never`. If this is not the case,\n * the TypeScript compiler will flag a type error.\n * @param message - Optional custom error message to include in the thrown error.\n * @throws {Error} Always throws when invoked at runtime.\n *\n */\n// eslint-disable-next-line local-rules/prefer-object-params\nexport const assertNever = (_: never, message?: string): never => {\n throw new Error(message);\n};\n", "import {assertNonNullish} from './asserts.utils';\n\nexport const uint8ArrayToBigInt = (array: Uint8Array): bigint => {\n const view = new DataView(array.buffer, array.byteOffset, array.byteLength);\n if (typeof view.getBigUint64 === 'function') {\n return view.getBigUint64(0);\n }\n const high = BigInt(view.getUint32(0));\n const low = BigInt(view.getUint32(4));\n\n return (high << BigInt(32)) + low;\n};\n\nexport const bigIntToUint8Array = (value: bigint): Uint8Array => {\n const buffer = new ArrayBuffer(8);\n const view = new DataView(buffer);\n if (typeof view.setBigUint64 === 'function') {\n view.setBigUint64(0, value);\n } else {\n const high = Number(value >> BigInt(32));\n const low = Number(value & BigInt(0xffffffff));\n\n view.setUint32(0, high);\n view.setUint32(4, low);\n }\n\n return new Uint8Array(buffer);\n};\n\nexport const numberToUint8Array = (value: number): Uint8Array => {\n const view = new DataView(new ArrayBuffer(8));\n for (let index = 7; index >= 0; --index) {\n view.setUint8(index, value % 256);\n value = value >> 8;\n }\n return new Uint8Array(view.buffer);\n};\n\nexport const arrayBufferToUint8Array = (buffer: ArrayBuffer): Uint8Array => new Uint8Array(buffer);\n\nexport const uint8ArrayToArrayOfNumber = (array: Uint8Array): Array<number> => Array.from(array);\n\nexport const arrayOfNumberToUint8Array = (numbers: Array<number>): Uint8Array =>\n new Uint8Array(numbers);\n\nexport const asciiStringToByteArray = (text: string): Array<number> =>\n Array.from(text).map((c) => c.charCodeAt(0));\n\nexport const hexStringToUint8Array = (hexString: string): Uint8Array => {\n const matches = hexString.match(/.{1,2}/g);\n\n assertNonNullish(matches, 'Invalid hex string.');\n\n return Uint8Array.from(matches.map((byte) => parseInt(byte, 16)));\n};\n\n/**\n * Compare two Uint8Arrays for byte-level equality.\n *\n * @param {Object} params\n * @param {Uint8Array} params.a - First Uint8Array to compare.\n * @param {Uint8Array} params.b - Second Uint8Array to compare.\n * @returns {boolean} True if both arrays have the same length and identical contents.\n */\nexport const uint8ArraysEqual = ({a, b}: {a: Uint8Array; b: Uint8Array}) =>\n a.length === b.length && a.every((byte, i) => byte === b[i]);\n\nexport const uint8ArrayToHexString = (bytes: Uint8Array | number[]) => {\n if (!(bytes instanceof Uint8Array)) {\n bytes = Uint8Array.from(bytes);\n }\n return bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), '');\n};\n\nexport const candidNumberArrayToBigInt = (array: number[]): bigint => {\n let result = 0n;\n for (let i = array.length - 1; i >= 0; i--) {\n result = (result << 32n) + BigInt(array[i]);\n }\n return result;\n};\n", "/**\n * Converts a Uint8Array (binary data) to a base64 encoded string.\n *\n * @param {Uint8Array} uint8Array - The Uint8Array containing binary data to be encoded.\n * @returns {string} - The base64 encoded string representation of the binary data.\n */\nexport const uint8ArrayToBase64 = (uint8Array: Uint8Array): string => {\n // Spreading large Uint8Arrays or using Array.from loses precision when used together with String.fromCharCode.\n // Therefore, we use a chunked loop, which better than a reducer or iterating on every value.\n // Spreading a small chunk - such as 32kb - works as expected.\n const chunkSize = 0x8000; // 32 kb\n const chunks: string[] = [];\n for (let i = 0; i < uint8Array.length; i += chunkSize) {\n chunks.push(String.fromCharCode(...uint8Array.subarray(i, i + chunkSize)));\n }\n return btoa(chunks.join(''));\n};\n\n/**\n * Converts a base64 encoded string to a Uint8Array (binary data).\n *\n * @param {string} base64String - The base64 encoded string to be decoded.\n * @returns {Uint8Array} - The Uint8Array representation of the decoded binary data.\n */\nexport const base64ToUint8Array = (base64String: string): Uint8Array =>\n Uint8Array.from(atob(base64String), (c) => c.charCodeAt(0));\n", "const NANOSECONDS_PER_MILLISECOND = 1_000_000n;\n\n/**\n * Returns the current timestamp in nanoseconds as a `bigint`.\n *\n * @returns {bigint} The current timestamp in nanoseconds.\n */\nexport const nowInBigIntNanoSeconds = (): bigint =>\n BigInt(Date.now()) * NANOSECONDS_PER_MILLISECOND;\n\n/**\n * Converts a given `Date` object to a timestamp in nanoseconds as a `bigint`.\n *\n * @param {Date} date - The `Date` object to convert.\n * @returns {bigint} The timestamp in nanoseconds.\n */\nexport const toBigIntNanoSeconds = (date: Date): bigint =>\n BigInt(date.getTime()) * NANOSECONDS_PER_MILLISECOND;\n", "/**\n * Creates a debounced version of the provided function.\n *\n * The debounced function postpones its execution until after a certain amount of time\n * has elapsed since the last time it was invoked. This is useful for limiting the rate\n * at which a function is called (e.g. in response to user input or events).\n *\n * @param {Function} func - The function to debounce. It will only be called after no new calls happen within the specified timeout.\n * @param {number} [timeout=300] - The debounce delay in milliseconds. Defaults to 300ms if not provided or invalid.\n * @returns {(args: unknown[]) => void} A debounced version of the original function.\n */\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type, local-rules/prefer-object-params\nexport const debounce = (func: Function, timeout?: number) => {\n let timer: NodeJS.Timer | undefined;\n\n return (...args: unknown[]) => {\n const next = () => func(...args);\n\n if (timer) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore TypeScript global and window confusion even if we are using @types/node\n clearTimeout(timer);\n }\n\n timer = setTimeout(next, timeout !== undefined && timeout > 0 ? timeout : 300);\n };\n};\n", "/**\n * Checks if a given argument is null or undefined.\n *\n * @template T - The type of the argument.\n * @param {T | undefined | null} argument - The argument to check.\n * @returns {argument is undefined | null} `true` if the argument is null or undefined; otherwise, `false`.\n */\nexport const isNullish = <T>(argument: T | undefined | null): argument is undefined | null =>\n argument === null || argument === undefined;\n\n/**\n * Checks if a given argument is neither null nor undefined.\n *\n * @template T - The type of the argument.\n * @param {T | undefined | null} argument - The argument to check.\n * @returns {argument is NonNullable<T>} `true` if the argument is not null or undefined; otherwise, `false`.\n */\nexport const nonNullish = <T>(argument: T | undefined | null): argument is NonNullable<T> =>\n !isNullish(argument);\n\n/**\n * Checks if a given value is not null, not undefined, and not an empty string.\n *\n * @param {string | undefined | null} value - The value to check.\n * @returns {boolean} `true` if the value is not null, not undefined, and not an empty string; otherwise, `false`.\n */\nexport const notEmptyString = (value: string | undefined | null): value is string =>\n nonNullish(value) && value !== '';\n\n/**\n * Checks if a given value is null, undefined, or an empty string.\n *\n * @param {string | undefined | null} value - The value to check.\n * @returns {value is undefined | null | \"\"} Type predicate indicating if the value is null, undefined, or an empty string.\n */\nexport const isEmptyString = (value: string | undefined | null): value is undefined | null | '' =>\n !notEmptyString(value);\n", "import type {Nullable, NullishNullable} from '../types/did.utils';\nimport {assertNonNullish} from './asserts.utils';\nimport {nonNullish} from './nullish.utils';\n\n/**\n * Converts a value into a Candid-style variant representation of an optional value.\n *\n * @template T The type of the value.\n * @param {T | null | undefined} value - The value to convert into a Candid-style variant.\n * @returns {Nullable<T>} A Candid-style variant representation: an empty array for `null` and `undefined` or an array with the value.\n */\nexport const toNullable = <T>(value?: T | null): Nullable<T> => (nonNullish(value) ? [value] : []);\n\n/**\n * Extracts the value from a Candid-style variant representation of an optional value.\n *\n * @template T The type of the value.\n * @param {Nullable<T>} value - A Candid-style variant representing an optional value.\n * @returns {T | undefined} The extracted value, or `undefined` if the array is empty.\n */\nexport const fromNullable = <T>(value: Nullable<T>): T | undefined => value?.[0];\n\n/**\n * Extracts the value from a Candid-style variant representation of an optional value,\n * ensuring the value is defined. Throws an error if the array is empty or the value is nullish.\n *\n * @template T The type of the value.\n * @param {Nullable<T>} value - A Candid-style variant representing an optional value.\n * @returns {T} The extracted value.\n * @throws {Error} If the array is empty or the value is nullish.\n */\nexport const fromDefinedNullable = <T>(value: Nullable<T>): T => {\n const result = fromNullable(value);\n\n assertNonNullish(result);\n\n return result;\n};\n\n/**\n * Extracts the value from a nullish Candid-style variant representation.\n *\n * @template T The type of the value.\n * @param {NullishNullable<T>} value - A Candid-style variant or `undefined`.\n * @returns {T | undefined} The extracted value, or `undefined` if the input is nullish or the array is empty.\n */\nexport const fromNullishNullable = <T>(value: NullishNullable<T>): T | undefined =>\n fromNullable(value ?? []);\n", "const alphabet = 'abcdefghijklmnopqrstuvwxyz234567';\n\n// Build a lookup table for decoding.\nconst lookupTable: Record<string, number> = Object.create(null);\nfor (let i = 0; i < alphabet.length; i++) {\n lookupTable[alphabet[i]] = i;\n}\n\n// Add aliases for rfc4648.\nlookupTable['0'] = lookupTable.o;\nlookupTable['1'] = lookupTable.i;\n\n/**\n * @param input The Uint8Array to encode.\n * @returns A Base32 string encoding the input.\n */\nexport function base32Encode(input: Uint8Array): string {\n // How many bits will we skip from the first byte.\n let skip = 0;\n // 5 high bits, carry from one byte to the next.\n let bits = 0;\n\n // The output string in base32.\n let output = '';\n\n function encodeByte(byte: number) {\n if (skip < 0) {\n // we have a carry from the previous byte\n bits |= byte >> -skip;\n } else {\n // no carry\n bits = (byte << skip) & 248;\n }\n\n if (skip > 3) {\n // Not enough data to produce a character, get us another one\n skip -= 8;\n return 1;\n }\n\n if (skip < 4) {\n // produce a character\n output += alphabet[bits >> 3];\n skip += 5;\n }\n\n return 0;\n }\n\n for (let i = 0; i < input.length; ) {\n i += encodeByte(input[i]);\n }\n\n return output + (skip < 0 ? alphabet[bits >> 3] : '');\n}\n\n/**\n * @param input The base32 encoded string to decode.\n */\nexport function base32Decode(input: string): Uint8Array {\n // how many bits we have from the previous character.\n let skip = 0;\n // current byte we're producing.\n let byte = 0;\n\n const output = new Uint8Array(((input.length * 4) / 3) | 0);\n let o = 0;\n\n function decodeChar(char: string) {\n // Consume a character from the stream, store\n // the output in this.output. As before, better\n // to use update().\n let val = lookupTable[char.toLowerCase()];\n if (val === undefined) {\n throw new Error(`Invalid character: ${JSON.stringify(char)}`);\n }\n\n // move to the high bits\n val <<= 3;\n byte |= val >>> skip;\n skip += 5;\n\n if (skip >= 8) {\n // We have enough bytes to produce an output\n output[o++] = byte;\n skip -= 8;\n\n if (skip > 0) {\n byte = (val << (5 - skip)) & 255;\n } else {\n byte = 0;\n }\n }\n }\n\n for (const c of input) {\n decodeChar(c);\n }\n\n return output.slice(0, o);\n}\n", "// This file is translated to JavaScript from\n// https://lxp32.github.io/docs/a-simple-example-crc32-calculation/\nconst lookUpTable: Uint32Array = new Uint32Array([\n 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,\n 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,\n 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,\n 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,\n 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,\n 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,\n 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,\n 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,\n 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,\n 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,\n 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,\n 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,\n 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,\n 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,\n 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,\n 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,\n 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,\n 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,\n 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,\n 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,\n 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,\n 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,\n 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,\n 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,\n 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,\n 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,\n 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,\n 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,\n 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,\n 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,\n 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,\n 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d,\n]);\n\n/**\n * Calculate the CRC32 of a Uint8Array.\n * @param buf The Uint8Array to calculate the CRC32 of.\n */\nexport function getCrc32(buf: Uint8Array): number {\n let crc = -1;\n\n for (let i = 0; i < buf.length; i++) {\n const byte = buf[i];\n const t = (byte ^ crc) & 0xff;\n crc = lookUpTable[t] ^ (crc >>> 8);\n }\n\n return (crc ^ -1) >>> 0;\n}\n", "/**\n * Utilities for hex, bytes, CSPRNG.\n * @module\n */\n/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */\n\n// We use WebCrypto aka globalThis.crypto, which exists in browsers and node.js 16+.\n// node.js versions earlier than v19 don't declare it in global scope.\n// For node.js, package.json#exports field mapping rewrites import\n// from `crypto` to `cryptoNode`, which imports native module.\n// Makes the utils un-importable in browsers without a bundler.\n// Once node.js 18 is deprecated (2025-04-30), we can just drop the import.\nimport { crypto } from '@noble/hashes/crypto';\n\n/** Checks if something is Uint8Array. Be careful: nodejs Buffer will return true. */\nexport function isBytes(a: unknown): a is Uint8Array {\n return a instanceof Uint8Array || (ArrayBuffer.isView(a) && a.constructor.name === 'Uint8Array');\n}\n\n/** Asserts something is positive integer. */\nexport function anumber(n: number): void {\n if (!Number.isSafeInteger(n) || n < 0) throw new Error('positive integer expected, got ' + n);\n}\n\n/** Asserts something is Uint8Array. */\nexport function abytes(b: Uint8Array | undefined, ...lengths: number[]): void {\n if (!isBytes(b)) throw new Error('Uint8Array expected');\n if (lengths.length > 0 && !lengths.includes(b.length))\n throw new Error('Uint8Array expected of length ' + lengths + ', got length=' + b.length);\n}\n\n/** Asserts something is hash */\nexport function ahash(h: IHash): void {\n if (typeof h !== 'function' || typeof h.create !== 'function')\n throw new Error('Hash should be wrapped by utils.createHasher');\n anumber(h.outputLen);\n anumber(h.blockLen);\n}\n\n/** Asserts a hash instance has not been destroyed / finished */\nexport function aexists(instance: any, checkFinished = true): void {\n if (instance.destroyed) throw new Error('Hash instance has been destroyed');\n if (checkFinished && instance.finished) throw new Error('Hash#digest() has already been called');\n}\n\n/** Asserts output is properly-sized byte array */\nexport function aoutput(out: any, instance: any): void {\n abytes(out);\n const min = instance.outputLen;\n if (out.length < min) {\n throw new Error('digestInto() expects output buffer of length at least ' + min);\n }\n}\n\n/** Generic type encompassing 8/16/32-byte arrays - but not 64-byte. */\n// prettier-ignore\nexport type TypedArray = Int8Array | Uint8ClampedArray | Uint8Array |\n Uint16Array | Int16Array | Uint32Array | Int32Array;\n\n/** Cast u8 / u16 / u32 to u8. */\nexport function u8(arr: TypedArray): Uint8Array {\n return new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);\n}\n\n/** Cast u8 / u16 / u32 to u32. */\nexport function u32(arr: TypedArray): Uint32Array {\n return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));\n}\n\n/** Zeroize a byte array. Warning: JS provides no guarantees. */\nexport function clean(...arrays: TypedArray[]): void {\n for (let i = 0; i < arrays.length; i++) {\n arrays[i].fill(0);\n }\n}\n\n/** Create DataView of an array for easy byte-level manipulation. */\nexport function createView(arr: TypedArray): DataView {\n return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);\n}\n\n/** The rotate right (circular right shift) operation for uint32 */\nexport function rotr(word: number, shift: number): number {\n return (word << (32 - shift)) | (word >>> shift);\n}\n\n/** The rotate left (circular left shift) operation for uint32 */\nexport function rotl(word: number, shift: number): number {\n return (word << shift) | ((word >>> (32 - shift)) >>> 0);\n}\n\n/** Is current platform little-endian? Most are. Big-Endian platform: IBM */\nexport const isLE: boolean = /* @__PURE__ */ (() =>\n new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44)();\n\n/** The byte swap operation for uint32 */\nexport function byteSwap(word: number): number {\n return (\n ((word << 24) & 0xff000000) |\n ((word << 8) & 0xff0000) |\n ((word >>> 8) & 0xff00) |\n ((word >>> 24) & 0xff)\n );\n}\n/** Conditionally byte swap if on a big-endian platform */\nexport const swap8IfBE: (n: number) => number = isLE\n ? (n: number) => n\n : (n: number) => byteSwap(n);\n\n/** @deprecated */\nexport const byteSwapIfBE: typeof swap8IfBE = swap8IfBE;\n/** In place byte swap for Uint32Array */\nexport function byteSwap32(arr: Uint32Array): Uint32Array {\n for (let i = 0; i < arr.length; i++) {\n arr[i] = byteSwap(arr[i]);\n }\n return arr;\n}\n\nexport const swap32IfBE: (u: Uint32Array) => Uint32Array = isLE\n ? (u: Uint32Array) => u\n : byteSwap32;\n\n// Built-in hex conversion https://caniuse.com/mdn-javascript_builtins_uint8array_fromhex\nconst hasHexBuiltin: boolean = /* @__PURE__ */ (() =>\n // @ts-ignore\n typeof Uint8Array.from([]).toHex === 'function' && typeof Uint8Array.fromHex === 'function')();\n\n// Array where index 0xf0 (240) is mapped to string 'f0'\nconst hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) =>\n i.toString(16).padStart(2, '0')\n);\n\n/**\n * Convert byte array to hex string. Uses built-in function, when available.\n * @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123'\n */\nexport function bytesToHex(bytes: Uint8Array): string {\n abytes(bytes);\n // @ts-ignore\n if (hasHexBuiltin) return bytes.toHex();\n // pre-caching improves the speed 6x\n let hex = '';\n for (let i = 0; i < bytes.length; i++) {\n hex += hexes[bytes[i]];\n }\n return hex;\n}\n\n// We use optimized technique to convert hex string to byte array\nconst asciis = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 } as const;\nfunction asciiToBase16(ch: number): number | undefined {\n if (ch >= asciis._0 && ch <= asciis._9) return ch - asciis._0; // '2' => 50-48\n if (ch >= asciis.A && ch <= asciis.F) return ch - (asciis.A - 10); // 'B' => 66-(65-10)\n if (ch >= asciis.a && ch <= asciis.f) return ch - (asciis.a - 10); // 'b' => 98-(97-10)\n return;\n}\n\n/**\n * Convert hex string to byte array. Uses built-in function, when available.\n * @example hexToBytes('cafe0123') // Uint8Array.from([0xca, 0xfe, 0x01, 0x23])\n */\nexport function hexToBytes(hex: string): Uint8Array {\n if (typeof hex !== 'string') throw new Error('hex string expected, got ' + typeof hex);\n // @ts-ignore\n if (hasHexBuiltin) return Uint8Array.fromHex(hex);\n const hl = hex.length;\n const al = hl / 2;\n if (hl % 2) throw new Error('hex string expected, got unpadded hex of length ' + hl);\n const array = new Uint8Array(al);\n for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {\n const n1 = asciiToBase16(hex.charCodeAt(hi));\n const n2 = asciiToBase16(hex.charCodeAt(hi + 1));\n if (n1 === undefined || n2 === undefined) {\n const char = hex[hi] + hex[hi + 1];\n throw new Error('hex string expected, got non-hex character \"' + char + '\" at index ' + hi);\n }\n array[ai] = n1 * 16 + n2; // multiply first octet, e.g. 'a3' => 10*16+3 => 160 + 3 => 163\n }\n return array;\n}\n\n/**\n * There is no setImmediate in browser and setTimeout is slow.\n * Call of async fn will return Promise, which will be fullfiled only on\n * next scheduler queue processing step and this is exactly what we need.\n */\nexport const nextTick = async (): Promise<void> => {};\n\n/** Returns control to thread each 'tick' ms to avoid blocking. */\nexport async function asyncLoop(\n iters: number,\n tick: number,\n cb: (i: number) => void\n): Promise<void> {\n let ts = Date.now();\n for (let i = 0; i < iters; i++) {\n cb(i);\n // Date.now() is not monotonic, so in case if clock goes backwards we return return control too\n const diff = Date.now() - ts;\n if (diff >= 0 && diff < tick) continue;\n await nextTick();\n ts += diff;\n }\n}\n\n// Global symbols, but ts doesn't see them: https://github.com/microsoft/TypeScript/issues/31535\ndeclare const TextEncoder: any;\ndeclare const TextDecoder: any;\n\n/**\n * Converts string to bytes using UTF8 encoding.\n * @example utf8ToBytes('abc') // Uint8Array.from([97, 98, 99])\n */\nexport function utf8ToBytes(str: string): Uint8Array {\n if (typeof str !== 'string') throw new Error('string expected');\n return new Uint8Array(new TextEncoder().encode(str)); // https://bugzil.la/1681809\n}\n\n/**\n * Converts bytes to string using UTF8 encoding.\n * @example bytesToUtf8(Uint8Array.from([97, 98, 99])) // 'abc'\n */\nexport function bytesToUtf8(bytes: Uint8Array): string {\n return new TextDecoder().decode(bytes);\n}\n\n/** Accepted input of hash functions. Strings are converted to byte arrays. */\nexport type Input = string | Uint8Array;\n/**\n * Normalizes (non-hex) string or Uint8Array to Uint8Array.\n * Warning: when Uint8Array is passed, it would NOT get copied.\n * Keep in mind for future mutable operations.\n */\nexport function toBytes(data: Input): Uint8Array {\n if (typeof data === 'string') data = utf8ToBytes(data);\n abytes(data);\n return data;\n}\n\n/** KDFs can accept string or Uint8Array for user convenience. */\nexport type KDFInput = string | Uint8Array;\n/**\n * Helper for KDFs: consumes uint8array or string.\n * When string is passed, does utf8 decoding, using TextDecoder.\n */\nexport function kdfInputToBytes(data: KDFInput): Uint8Array {\n if (typeof data === 'string') data = utf8ToBytes(data);\n abytes(data);\n return data;\n}\n\n/** Copies several Uint8Arrays into one. */\nexport function concatBytes(...arrays: Uint8Array[]): Uint8Array {\n let sum = 0;\n for (let i = 0; i < arrays.length; i++) {\n const a = arrays[i];\n abytes(a);\n sum += a.length;\n }\n const res = new Uint8Array(sum);\n for (let i = 0, pad = 0; i < arrays.length; i++) {\n const a = arrays[i];\n res.set(a, pad);\n pad += a.length;\n }\n return res;\n}\n\ntype EmptyObj = {};\nexport function checkOpts<T1 extends EmptyObj, T2 extends EmptyObj>(\n defaults: T1,\n opts?: T2\n): T1 & T2 {\n if (opts !== undefined && {}.toString.call(opts) !== '[object Object]')\n throw new Error('options should be object or undefined');\n const merged = Object.assign(defaults, opts);\n return merged as T1 & T2;\n}\n\n/** Hash interface. */\nexport type IHash = {\n (data: Uint8Array): Uint8Array;\n blockLen: number;\n outputLen: number;\n create: any;\n};\n\n/** For runtime check if class implements interface */\nexport abstract class Hash<T extends Hash<T>> {\n abstract blockLen: number; // Bytes per block\n abstract outputLen: number; // Bytes in output\n abstract update(buf: Input): this;\n // Writes digest into buf\n abstract digestInto(buf: Uint8Array): void;\n abstract digest(): Uint8Array;\n /**\n * Resets internal state. Makes Hash instance unusable.\n * Reset is impossible for keyed hashes if key is consumed into state. If digest is not consumed\n * by user, they will need to manually call `destroy()` when zeroing is necessary.\n */\n abstract destroy(): void;\n /**\n * Clones hash instance. Unsafe: doesn't check whether `to` is valid. Can be used as `clone()`\n * when no options are passed.\n * Reasons to use `_cloneInto` instead of clone: 1) performance 2) reuse instance => all internal\n * buffers are overwritten => causes buffer overwrite which is used for digest in some cases.\n * There are no guarantees for clean-up because it's impossible in JS.\n */\n abstract _cloneInto(to?: T): T;\n // Safe version that clones internal state\n abstract clone(): T;\n}\n\n/**\n * XOF: streaming API to read digest in chunks.\n * Same as 'squeeze' in keccak/k12 and 'seek' in blake3, but more generic name.\n * When hash used in XOF mode it is up to user to call '.destroy' afterwards, since we cannot\n * destroy state, next call can require more bytes.\n */\nexport type HashXOF<T extends Hash<T>> = Hash<T> & {\n xof(bytes: number): Uint8Array; // Read 'bytes' bytes from digest stream\n xofInto(buf: Uint8Array): Uint8Array; // read buf.length bytes from digest stream into buf\n};\n\n/** Hash function */\nexport type CHash = ReturnType<typeof createHasher>;\n/** Hash function with output */\nexport type CHashO = ReturnType<typeof createOptHasher>;\n/** XOF with output */\nexport type CHashXO = ReturnType<typeof createXOFer>;\n\n/** Wraps hash function, creating an interface on top of it */\nexport function createHasher<T extends Hash<T>>(\n hashCons: () => Hash<T>\n): {\n (msg: Input): Uint8Array;\n outputLen: number;\n blockLen: number;\n create(): Hash<T>;\n} {\n const hashC = (msg: Input): Uint8Array => hashCons().update(toBytes(msg)).digest();\n const tmp = hashCons();\n hashC.outputLen = tmp.outputLen;\n hashC.blockLen = tmp.blockLen;\n hashC.create = () => hashCons();\n return hashC;\n}\n\nexport function createOptHasher<H extends Hash<H>, T extends Object>(\n hashCons: (opts?: T) => Hash<H>\n): {\n (msg: Input, opts?: T): Uint8Array;\n outputLen: number;\n blockLen: number;\n create(opts?: T): Hash<H>;\n} {\n const hashC = (msg: Input, opts?: T): Uint8Array => hashCons(opts).update(toBytes(msg)).digest();\n const tmp = hashCons({} as T);\n hashC.outputLen = tmp.outputLen;\n hashC.blockLen = tmp.blockLen;\n hashC.create = (opts?: T) => hashCons(opts);\n return hashC;\n}\n\nexport function createXOFer<H extends HashXOF<H>, T extends Object>(\n hashCons: (opts?: T) => HashXOF<H>\n): {\n (msg: Input, opts?: T): Uint8Array;\n outputLen: number;\n blockLen: number;\n create(opts?: T): HashXOF<H>;\n} {\n const hashC = (msg: Input, opts?: T): Uint8Array => hashCons(opts).update(toBytes(msg)).digest();\n const tmp = hashCons({} as T);\n hashC.outputLen = tmp.outputLen;\n hashC.blockLen = tmp.blockLen;\n hashC.create = (opts?: T) => hashCons(opts);\n return hashC;\n}\nexport const wrapConstructor: typeof createHasher = createHasher;\nexport const wrapConstructorWithOpts: typeof createOptHasher = createOptHasher;\nexport const wrapXOFConstructorWithOpts: typeof createXOFer = createXOFer;\n\n/** Cryptographically secure PRNG. Uses internal OS-level `crypto.getRandomValues`. */\nexport function randomBytes(bytesLength = 32): Uint8Array {\n if (crypto && typeof crypto.getRandomValues === 'function') {\n return crypto.getRandomValues(new Uint8Array(bytesLength));\n }\n // Legacy Node.js compatibility\n if (crypto && typeof crypto.randomBytes === 'function') {\n return Uint8Array.from(crypto.randomBytes(bytesLength));\n }\n throw new Error('crypto.getRandomValues must be defined');\n}\n", "/**\n * Internal Merkle-Damgard hash utils.\n * @module\n */\nimport { type Input, Hash, abytes, aexists, aoutput, clean, createView, toBytes } from './utils.ts';\n\n/** Polyfill for Safari 14. https://caniuse.com/mdn-javascript_builtins_dataview_setbiguint64 */\nexport function setBigUint64(\n view: DataView,\n byteOffset: number,\n value: bigint,\n isLE: boolean\n): void {\n if (typeof view.setBigUint64 === 'function') return view.setBigUint64(byteOffset, value, isLE);\n const _32n = BigInt(32);\n const _u32_max = BigInt(0xffffffff);\n const wh = Number((value >> _32n) & _u32_max);\n const wl = Number(value & _u32_max);\n const h = isLE ? 4 : 0;\n const l = isLE ? 0 : 4;\n view.setUint32(byteOffset + h, wh, isLE);\n view.setUint32(byteOffset + l, wl, isLE);\n}\n\n/** Choice: a ? b : c */\nexport function Chi(a: number, b: number, c: number): number {\n return (a & b) ^ (~a & c);\n}\n\n/** Majority function, true if any two inputs is true. */\nexport function Maj(a: number, b: number, c: number): number {\n return (a & b) ^ (a & c) ^ (b & c);\n}\n\n/**\n * Merkle-Damgard hash construction base class.\n * Could be used to create MD5, RIPEMD, SHA1, SHA2.\n */\nexport abstract class HashMD<T extends HashMD<T>> extends Hash<T> {\n protected abstract process(buf: DataView, offset: number): void;\n protected abstract get(): number[];\n protected abstract set(...args: number[]): void;\n abstract destroy(): void;\n protected abstract roundClean(): void;\n\n readonly blockLen: number;\n readonly outputLen: number;\n readonly padOffset: number;\n readonly isLE: boolean;\n\n // For partial updates less than block size\n protected buffer: Uint8Array;\n protected view: DataView;\n protected finished = false;\n protected length = 0;\n protected pos = 0;\n protected destroyed = false;\n\n constructor(blockLen: number, outputLen: number, padOffset: number, isLE: boolean) {\n super();\n this.blockLen = blockLen;\n this.outputLen = outputLen;\n this.padOffset = padOffset;\n this.isLE = isLE;\n this.buffer = new Uint8Array(blockLen);\n this.view = createView(this.buffer);\n }\n update(data: Input): this {\n aexists(this);\n data = toBytes(data);\n abytes(data);\n const { view, buffer, blockLen } = this;\n const len = data.length;\n for (let pos = 0; pos < len; ) {\n const take = Math.min(blockLen - this.pos, len - pos);\n // Fast path: we have at least one block in input, cast it to view and process\n if (take === blockLen) {\n const dataView = createView(data);\n for (; blockLen <= len - pos; pos += blockLen) this.process(dataView, pos);\n continue;\n }\n buffer.set(data.subarray(pos, pos + take), this.pos);\n this.pos += take;\n pos += take;\n if (this.pos === blockLen) {\n this.process(view, 0);\n this.pos = 0;\n }\n }\n this.length += data.length;\n this.roundClean();\n return this;\n }\n digestInto(out: Uint8Array): void {\n aexists(this);\n aoutput(out, this);\n this.finished = true;\n // Padding\n // We can avoid allocation of buffer for padding completely if it\n // was previously not allocated here. But it won't change performance.\n const { buffer, view, blockLen, isLE } = this;\n let { pos } = this;\n // append the bit '1' to the message\n buffer[pos++] = 0b10000000;\n clean(this.buffer.subarray(pos));\n // we have less than padOffset left in buffer, so we cannot put length in\n // current block, need process it and pad again\n if (this.padOffset > blockLen - pos) {\n this.process(view, 0);\n pos = 0;\n }\n // Pad until full block byte with zeros\n for (let i = pos; i < blockLen; i++) buffer[i] = 0;\n // Note: sha512 requires length to be 128bit integer, but length in JS will overflow before that\n // You need to write around 2 exabytes (u64_max / 8 / (1024**6)) for this to happen.\n // So we just write lowest 64 bits of that value.\n setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);\n this.process(view, 0);\n const oview = createView(out);\n const len = this.outputLen;\n // NOTE: we do division by 4 later, which should be fused in single op with modulo by JIT\n if (len % 4) throw new Error('_sha2: outputLen should be aligned to 32bit');\n const outLen = len / 4;\n const state = this.get();\n if (outLen > state.length) throw new Error('_sha2: outputLen bigger than state');\n for (let i = 0; i < outLen; i++) oview.setUint32(4 * i, state[i], isLE);\n }\n digest(): Uint8Array {\n const { buffer, outputLen } = this;\n this.digestInto(buffer);\n const res = buffer.slice(0, outputLen);\n this.destroy();\n return res;\n }\n _cloneInto(to?: T): T {\n to ||= new (this.constructor as any)() as T;\n to.set(...this.get());\n const { blockLen, buffer, length, finished, destroyed, pos } = this;\n to.destroyed = destroyed;\n to.finished = finished;\n to.length = length;\n to.pos = pos;\n if (length % blockLen) to.buffer.set(buffer);\n return to;\n }\n clone(): T {\n return this._cloneInto();\n }\n}\n\n/**\n * Initial SHA-2 state: fractional parts of square roots of first 16 primes 2..53.\n * Check out `test/misc/sha2-gen-iv.js` for recomputation guide.\n */\n\n/** Initial SHA256 state. Bits 0..32 of frac part of sqrt of primes 2..19 */\nexport const SHA256_IV: Uint32Array = /* @__PURE__ */ Uint32Array.from([\n 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,\n]);\n\n/** Initial SHA224 state. Bits 32..64 of frac part of sqrt of primes 23..53 */\nexport const SHA224_IV: Uint32Array = /* @__PURE__ */ Uint32Array.from([\n 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4,\n]);\n\n/** Initial SHA384 state. Bits 0..64 of frac part of sqrt of primes 23..53 */\nexport const SHA384_IV: Uint32Array = /* @__PURE__ */ Uint32Array.from([\n 0xcbbb9d5d, 0xc1059ed8, 0x629a292a, 0x367cd507, 0x9159015a, 0x3070dd17, 0x152fecd8, 0xf70e5939,\n 0x67332667, 0xffc00b31, 0x8eb44a87, 0x68581511, 0xdb0c2e0d, 0x64f98fa7, 0x47b5481d, 0xbefa4fa4,\n]);\n\n/** Initial SHA512 state. Bits 0..64 of frac part of sqrt of primes 2..19 */\nexport const SHA512_IV: Uint32Array = /* @__PURE__ */ Uint32Array.from([\n 0x6a09e667, 0xf3bcc908, 0xbb67ae85, 0x84caa73b, 0x3c6ef372, 0xfe94f82b, 0xa54ff53a, 0x5f1d36f1,\n 0x510e527f, 0xade682d1, 0x9b05688c, 0x2b3e6c1f, 0x1f83d9ab, 0xfb41bd6b, 0x5be0cd19, 0x137e2179,\n]);\n", "/**\n * SHA2 hash function. A.k.a. sha256, sha384, sha512, sha512_224, sha512_256.\n * SHA256 is the fastest hash implementable in JS, even faster than Blake3.\n * Check out [RFC 4634](https://datatracker.ietf.org/doc/html/rfc4634) and\n * [FIPS 180-4](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf).\n * @module\n */\nimport { Chi, HashMD, Maj, SHA224_IV, SHA256_IV, SHA384_IV, SHA512_IV } from './_md.ts';\nimport * as u64 from './_u64.ts';\nimport { type CHash, clean, createHasher, rotr } from './utils.ts';\n\n/**\n * Round constants:\n * First 32 bits of fractional parts of the cube roots of the first 64 primes 2..311)\n */\n// prettier-ignore\nconst SHA256_K = /* @__PURE__ */ Uint32Array.from([\n 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,\n 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,\n 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,\n 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,\n 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,\n 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,\n 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,\n 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2\n]);\n\n/** Reusable temporary buffer. \"W\" comes straight from spec. */\nconst SHA256_W = /* @__PURE__ */ new Uint32Array(64);\nexport class SHA256 extends HashMD<SHA256> {\n // We cannot use array here since array allows indexing by variable\n // which means optimizer/compiler cannot use registers.\n protected A: number = SHA256_IV[0] | 0;\n protected B: number = SHA256_IV[1] | 0;\n protected C: number = SHA256_IV[2] | 0;\n protected D: number = SHA256_IV[3] | 0;\n protected E: number = SHA256_IV[4] | 0;\n protected F: number = SHA256_IV[5] | 0;\n protected G: number = SHA256_IV[6] | 0;\n protected H: number = SHA256_IV[7] | 0;\n\n constructor(outputLen: number = 32) {\n super(64, outputLen, 8, false);\n }\n protected get(): [number, number, number, number, number, number, number, number] {\n const { A, B, C, D, E, F, G, H } = this;\n return [A, B, C, D, E, F, G, H];\n }\n // prettier-ignore\n protected set(\n A: number, B: number, C: number, D: number, E: number, F: number, G: number, H: number\n ): void {\n this.A = A | 0;\n this.B = B | 0;\n this.C = C | 0;\n this.D = D | 0;\n this.E = E | 0;\n this.F = F | 0;\n this.G = G | 0;\n this.H = H | 0;\n }\n protected process(view: DataView, offset: number): void {\n // Extend the first 16 words into the remaining 48 words w[16..63] of the message schedule array\n for (let i = 0; i < 16; i++, offset += 4) SHA256_W[i] = view.getUint32(offset, false);\n for (let i = 16; i < 64; i++) {\n const W15 = SHA256_W[i - 15];\n const W2 = SHA256_W[i - 2];\n const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ (W15 >>> 3);\n const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ (W2 >>> 10);\n SHA256_W[i] = (s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16]) | 0;\n }\n // Compression function main loop, 64 rounds\n let { A, B, C, D, E, F, G, H } = this;\n for (let i = 0; i < 64; i++) {\n const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);\n const T1 = (H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0;\n const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);\n const T2 = (sigma0 + Maj(A, B, C)) | 0;\n H = G;\n G = F;\n F = E;\n E = (D + T1) | 0;\n D = C;\n C = B;\n B = A;\n A = (T1 + T2) | 0;\n }\n // Add the compressed chunk to the current hash value\n A = (A + this.A) | 0;\n B = (B + this.B) | 0;\n C = (C + this.C) | 0;\n D = (D + this.D) | 0;\n E = (E + this.E) | 0;\n F = (F + this.F) | 0;\n G = (G + this.G) | 0;\n H = (H + this.H) | 0;\n this.set(A, B, C, D, E, F, G, H);\n }\n protected roundClean(): void {\n clean(SHA256_W);\n }\n destroy(): void {\n this.set(0, 0, 0, 0, 0, 0, 0, 0);\n clean(this.buffer);\n }\n}\n\nexport class SHA224 extends SHA256 {\n protected A: number = SHA224_IV[0] | 0;\n protected B: number = SHA224_IV[1] | 0;\n protected C: number = SHA224_IV[2] | 0;\n protected D: number = SHA224_IV[3] | 0;\n protected E: number = SHA224_IV[4] | 0;\n protected F: number = SHA224_IV[5] | 0;\n protected G: number = SHA224_IV[6] | 0;\n protected H: number = SHA224_IV[7] | 0;\n constructor() {\n super(28);\n }\n}\n\n// SHA2-512 is slower than sha256 in js because u64 operations are slow.\n\n// Round contants\n// First 32 bits of the fractional parts of the cube roots of the first 80 primes 2..409\n// prettier-ignore\nconst K512 = /* @__PURE__ */ (() => u64.split([\n '0x428a2f98d728ae22', '0x7137449123ef65cd', '0xb5c0fbcfec4d3b2f', '0xe9b5dba58189dbbc',\n '0x3956c25bf348b538', '0x59f111f1b605d019', '0x923f82a4af194f9b', '0xab1c5ed5da6d8118',\n '0xd807aa98a3030242', '0x12835b0145706fbe', '0x243185be4ee4b28c', '0x550c7dc3d5ffb4e2',\n '0x72be5d74f27b896f', '0x80deb1fe3b1696b1', '0x9bdc06a725c71235', '0xc19bf174cf692694',\n '0xe49b69c19ef14ad2', '0xefbe4786384f25e3', '0x0fc19dc68b8cd5b5', '0x240ca1cc77ac9c65',\n '0x2de92c6f592b0275', '0x4a7484aa6ea6e483', '0x5cb0a9dcbd41fbd4', '0x76f988da831153b5',\n '0x983e5152ee66dfab', '0xa831c66d2db43210', '0xb00327c898fb213f', '0xbf597fc7beef0ee4',\n '0xc6e00bf33da88fc2', '0xd5a79147930aa725', '0x06ca6351e003826f', '0x142929670a0e6e70',\n '0x27b70a8546d22ffc', '0x2e1b21385c26c926', '0x4d2c6dfc5ac42aed', '0x53380d139d95b3df',\n '0x650a73548baf63de', '0x766a0abb3c77b2a8', '0x81c2c92e47edaee6', '0x92722c851482353b',\n '0xa2bfe8a14cf10364', '0xa81a664bbc423001', '0xc24b8b70d0f89791', '0xc76c51a30654be30',\n '0xd192e819d6ef5218', '0xd69906245565a910', '0xf40e35855771202a', '0x106aa07032bbd1b8',\n '0x19a4c116b8d2d0c8', '0x1e376c085141ab53', '0x2748774cdf8eeb99', '0x34b0bcb5e19b48a8',\n '0x391c0cb3c5c95a63', '0x4ed8aa4ae3418acb', '0x5b9cca4f7763e373', '0x682e6ff3d6b2b8a3',\n '0x748f82ee5defb2fc', '0x78a5636f43172f60', '0x84c87814a1f0ab72', '0x8cc702081a6439ec',\n '0x90befffa23631e28', '0xa4506cebde82bde9', '0xbef9a3f7b2c67915', '0xc67178f2e372532b',\n '0xca273eceea26619c', '0xd186b8c721c0c207', '0xeada7dd6cde0eb1e', '0xf57d4f7fee6ed178',\n '0x06f067aa72176fba', '0x0a637dc5a2c898a6', '0x113f9804bef90dae', '0x1b710b35131c471b',\n '0x28db77f523047d84', '0x32caab7b40c72493', '0x3c9ebe0a15c9bebc', '0x431d67c49c100d4c',\n '0x4cc5d4becb3e42b6', '0x597f299cfc657e2a', '0x5fcb6fab3ad6faec', '0x6c44198c4a475817'\n].map(n => BigInt(n))))();\nconst SHA512_Kh = /* @__PURE__ */ (() => K512[0])();\nconst SHA512_Kl = /* @__PURE__ */ (() => K512[1])();\n\n// Reusable temporary buffers\nconst SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);\nconst SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);\n\nexport class SHA512 extends HashMD<SHA512> {\n // We cannot use array here since array allows indexing by variable\n // which means optimizer/compiler cannot use registers.\n // h -- high 32 bits, l -- low 32 bits\n protected Ah: number = SHA512_IV[0] | 0;\n protected Al: number = SHA512_IV[1] | 0;\n protected Bh: number = SHA512_IV[2] | 0;\n protected Bl: number = SHA512_IV[3] | 0;\n protected Ch: number = SHA512_IV[4] | 0;\n protected Cl: number = SHA512_IV[5] | 0;\n protected Dh: number = SHA512_IV[6] | 0;\n protected Dl: number = SHA512_IV[7] | 0;\n protected Eh: number = SHA512_IV[8] | 0;\n protected El: number = SHA512_IV[9] | 0;\n protected Fh: number = SHA512_IV[10] | 0;\n protected Fl: number = SHA512_IV[11] | 0;\n protected Gh: number = SHA512_IV[12] | 0;\n protected Gl: number = SHA512_IV[13] | 0;\n protected Hh: number = SHA512_IV[14] | 0;\n protected Hl: number = SHA512_IV[15] | 0;\n\n constructor(outputLen: number = 64) {\n super(128, outputLen, 16, false);\n }\n // prettier-ignore\n protected get(): [\n number, number, number, number, number, number, number, number,\n number, number, number, number, number, number, number, number\n ] {\n const { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;\n return [Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl];\n }\n // prettier-ignore\n protected set(\n Ah: number, Al: number, Bh: number, Bl: number, Ch: number, Cl: number, Dh: number, Dl: number,\n Eh: number, El: number, Fh: number, Fl: number, Gh: number, Gl: number, Hh: number, Hl: number\n ): void {\n this.Ah = Ah | 0;\n this.Al = Al | 0;\n this.Bh = Bh | 0;\n this.Bl = Bl | 0;\n this.Ch = Ch | 0;\n this.Cl = Cl | 0;\n this.Dh = Dh | 0;\n this.Dl = Dl | 0;\n this.Eh = Eh | 0;\n this.El = El | 0;\n this.Fh = Fh | 0;\n this.Fl = Fl | 0;\n this.Gh = Gh | 0;\n this.Gl = Gl | 0;\n this.Hh = Hh | 0;\n this.Hl = Hl | 0;\n }\n protected process(view: DataView, offset: number): void {\n // Extend the first 16 words into the remaining 64 words w[16..79] of the message schedule array\n for (let i = 0; i < 16; i++, offset += 4) {\n SHA512_W_H[i] = view.getUint32(offset);\n SHA512_W_L[i] = view.getUint32((offset += 4));\n }\n for (let i = 16; i < 80; i++) {\n // s0 := (w[i-15] rightrotate 1) xor (w[i-15] rightrotate 8) xor (w[i-15] rightshift 7)\n const W15h = SHA512_W_H[i - 15] | 0;\n const W15l = SHA512_W_L[i - 15] | 0;\n const s0h = u64.rotrSH(W15h, W15l, 1) ^ u64.rotrSH(W15h, W15l, 8) ^ u64.shrSH(W15h, W15l, 7);\n const s0l = u64.rotrSL(W15h, W15l, 1) ^ u64.rotrSL(W15h, W15l, 8) ^ u64.shrSL(W15h, W15l, 7);\n // s1 := (w[i-2] rightrotate 19) xor (w[i-2] rightrotate 61) xor (w[i-2] rightshift 6)\n const W2h = SHA512_W_H[i - 2] | 0;\n const W2l = SHA512_W_L[i - 2] | 0;\n const s1h = u64.rotrSH(W2h, W2l, 19) ^ u64.rotrBH(W2h, W2l, 61) ^ u64.shrSH(W2h, W2l, 6);\n const s1l = u64.rotrSL(W2h, W2l, 19) ^ u64.rotrBL(W2h, W2l, 61) ^ u64.shrSL(W2h, W2l, 6);\n // SHA256_W[i] = s0 + s1 + SHA256_W[i - 7] + SHA256_W[i - 16];\n const SUMl = u64.add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16]);\n const SUMh = u64.add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]);\n SHA512_W_H[i] = SUMh | 0;\n SHA512_W_L[i] = SUMl | 0;\n }\n let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;\n // Compression function main loop, 80 rounds\n for (let i = 0; i < 80; i++) {\n // S1 := (e rightrotate 14) xor (e rightrotate 18) xor (e rightrotate 41)\n const sigma1h = u64.rotrSH(Eh, El, 14) ^ u64.rotrSH(Eh, El, 18) ^ u64.rotrBH(Eh, El, 41);\n const sigma1l = u64.rotrSL(Eh, El, 14) ^ u64.rotrSL(Eh, El, 18) ^ u64.rotrBL(Eh, El, 41);\n //const T1 = (H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0;\n const CHIh = (Eh & Fh) ^ (~Eh & Gh);\n const CHIl = (El & Fl) ^ (~El & Gl);\n // T1 = H + sigma1 + Chi(E, F, G) + SHA512_K[i] + SHA512_W[i]\n // prettier-ignore\n const T1ll = u64.add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);\n const T1h = u64.add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);\n const T1l = T1ll | 0;\n // S0 := (a rightrotate 28) xor (a rightrotate 34) xor (a rightrotate 39)\n const sigma0h = u64.rotrSH(Ah, Al, 28) ^ u64.rotrBH(Ah, Al, 34) ^ u64.rotrBH(Ah, Al, 39);\n const sigma0l = u64.rotrSL(Ah, Al, 28) ^ u64.rotrBL(Ah, Al, 34) ^ u64.rotrBL(Ah, Al, 39);\n const MAJh = (Ah & Bh) ^ (Ah & Ch) ^ (Bh & Ch);\n const MAJl = (Al & Bl) ^ (Al & Cl) ^ (Bl & Cl);\n Hh = Gh | 0;\n Hl = Gl | 0;\n Gh = Fh | 0;\n Gl = Fl | 0;\n Fh = Eh | 0;\n Fl = El | 0;\n ({ h: Eh, l: El } = u64.add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));\n Dh = Ch | 0;\n Dl = Cl | 0;\n Ch = Bh | 0;\n Cl = Bl | 0;\n Bh = Ah | 0;\n Bl = Al | 0;\n const All = u64.add3L(T1l, sigma0l, MAJl);\n Ah = u64.add3H(All, T1h, sigma0h, MAJh);\n Al = All | 0;\n }\n // Add the compressed chunk to the current hash value\n ({ h: Ah, l: Al } = u64.add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));\n ({ h: Bh, l: Bl } = u64.add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));\n ({ h: Ch, l: Cl } = u64.add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));\n ({ h: Dh, l: Dl } = u64.add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));\n ({ h: Eh, l: El } = u64.add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));\n ({ h: Fh, l: Fl } = u64.add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));\n ({ h: Gh, l: Gl } = u64.add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));\n ({ h: Hh, l: Hl } = u64.add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));\n this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);\n }\n protected roundClean(): void {\n clean(SHA512_W_H, SHA512_W_L);\n }\n destroy(): void {\n clean(this.buffer);\n this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);\n }\n}\n\nexport class SHA384 extends SHA512 {\n protected Ah: number = SHA384_IV[0] | 0;\n protected Al: number = SHA384_IV[1] | 0;\n protected Bh: number = SHA384_IV[2] | 0;\n protected Bl: number = SHA384_IV[3] | 0;\n protected Ch: number = SHA384_IV[4] | 0;\n protected Cl: number = SHA384_IV[5] | 0;\n protected Dh: number = SHA384_IV[6] | 0;\n protected Dl: number = SHA384_IV[7] | 0;\n protected Eh: number = SHA384_IV[8] | 0;\n protected El: number = SHA384_IV[9] | 0;\n protected Fh: number = SHA384_IV[10] | 0;\n protected Fl: number = SHA384_IV[11] | 0;\n protected Gh: number = SHA384_IV[12] | 0;\n protected Gl: number = SHA384_IV[13] | 0;\n protected Hh: number = SHA384_IV[14] | 0;\n protected Hl: number = SHA384_IV[15] | 0;\n\n constructor() {\n super(48);\n }\n}\n\n/**\n * Truncated SHA512/256 and SHA512/224.\n * SHA512_IV is XORed with 0xa5a5a5a5a5a5a5a5, then used as \"intermediary\" IV of SHA512/t.\n * Then t hashes string to produce result IV.\n * See `test/misc/sha2-gen-iv.js`.\n */\n\n/** SHA512/224 IV */\nconst T224_IV = /* @__PURE__ */ Uint32Array.from([\n 0x8c3d37c8, 0x19544da2, 0x73e19966, 0x89dcd4d6, 0x1dfab7ae, 0x32ff9c82, 0x679dd514, 0x582f9fcf,\n 0x0f6d2b69, 0x7bd44da8, 0x77e36f73, 0x04c48942, 0x3f9d85a8, 0x6a1d36c8, 0x1112e6ad, 0x91d692a1,\n]);\n\n/** SHA512/256 IV */\nconst T256_IV = /* @__PURE__ */ Uint32Array.from([\n 0x22312194, 0xfc2bf72c, 0x9f555fa3, 0xc84c64c2, 0x2393b86b, 0x6f53b151, 0x96387719, 0x5940eabd,\n 0x96283ee2, 0xa88effe3, 0xbe5e1e25, 0x53863992, 0x2b0199fc, 0x2c85b8aa, 0x0eb72ddc, 0x81c52ca2,\n]);\n\nexport class SHA512_224 extends SHA512 {\n protected Ah: number = T224_IV[0] | 0;\n protected Al: number = T224_IV[1] | 0;\n protected Bh: number = T224_IV[2] | 0;\n protected Bl: number = T224_IV[3] | 0;\n protected Ch: number = T224_IV[4] | 0;\n protected Cl: number = T224_IV[5] | 0;\n protected Dh: number = T224_IV[6] | 0;\n protected Dl: number = T224_IV[7] | 0;\n protected Eh: number = T224_IV[8] | 0;\n protected El: number = T224_IV[9] | 0;\n protected Fh: number = T224_IV[10] | 0;\n protected Fl: number = T224_IV[11] | 0;\n protected Gh: number = T224_IV[12] | 0;\n protected Gl: number = T224_IV[13] | 0;\n protected Hh: number = T224_IV[14] | 0;\n protected Hl: number = T224_IV[15] | 0;\n\n constructor() {\n super(28);\n }\n}\n\nexport class SHA512_256 extends SHA512 {\n protected Ah: number = T256_IV[0] | 0;\n protected Al: number = T256_IV[1] | 0;\n protected Bh: number = T256_IV[2] | 0;\n protected Bl: number = T256_IV[3] | 0;\n protected Ch: number = T256_IV[4] | 0;\n protected Cl: number = T256_IV[5] | 0;\n protected Dh: number = T256_IV[6] | 0;\n protected Dl: number = T256_IV[7] | 0;\n protected Eh: number = T256_IV[8] | 0;\n protected El: number = T256_IV[9] | 0;\n protected Fh: number = T256_IV[10] | 0;\n protected Fl: number = T256_IV[11] | 0;\n protected Gh: number = T256_IV[12] | 0;\n protected Gl: number = T256_IV[13] | 0;\n protected Hh: number = T256_IV[14] | 0;\n protected Hl: number = T256_IV[15] | 0;\n\n constructor() {\n super(32);\n }\n}\n\n/**\n * SHA2-256 hash function from RFC 4634.\n *\n * It is the fastest JS hash, even faster than Blake3.\n * To break sha256 using birthday attack, attackers need to try 2^128 hashes.\n * BTC network is doing 2^70 hashes/sec (2^95 hashes/year) as per 2025.\n */\nexport const sha256: CHash = /* @__PURE__ */ createHasher(() => new SHA256());\n/** SHA2-224 hash function from RFC 4634 */\nexport const sha224: CHash = /* @__PURE__ */ createHasher(() => new SHA224());\n\n/** SHA2-512 hash function from RFC 4634. */\nexport const sha512: CHash = /* @__PURE__ */ createHasher(() => new SHA512());\n/** SHA2-384 hash function from RFC 4634. */\nexport const sha384: CHash = /* @__PURE__ */ createHasher(() => new SHA384());\n\n/**\n * SHA2-512/256 \"truncated\" hash function, with improved resistance to length extension attacks.\n * See the paper on [truncated SHA512](https://eprint.iacr.org/2010/548.pdf).\n */\nexport const sha512_256: CHash = /* @__PURE__ */ createHasher(() => new SHA512_256());\n/**\n * SHA2-512/224 \"truncated\" hash function, with improved resistance to length extension attacks.\n * See the paper on [truncated SHA512](https://eprint.iacr.org/2010/548.pdf).\n */\nexport const sha512_224: CHash = /* @__PURE__ */ createHasher(() => new SHA512_224());\n", "import { base32Decode, base32Encode } from './utils/base32.ts';\nimport { getCrc32 } from './utils/getCrc.ts';\nimport { sha224 } from '@noble/hashes/sha2';\nimport { bytesToHex, hexToBytes } from '@noble/hashes/utils';\n\nexport const JSON_KEY_PRINCIPAL = '__principal__';\nconst SELF_AUTHENTICATING_SUFFIX = 2;\nconst ANONYMOUS_SUFFIX = 4;\n\nconst MANAGEMENT_CANISTER_PRINCIPAL_TEXT_STR = 'aaaaa-aa';\n\nexport interface JsonnablePrincipal {\n [JSON_KEY_PRINCIPAL]: string;\n}\n\nexport class Principal {\n public static anonymous(): Principal {\n return new this(new Uint8Array([ANONYMOUS_SUFFIX]));\n }\n\n /**\n * Utility method, returning the principal representing the management canister, decoded from the hex string `'aaaaa-aa'`\n * @returns {Principal} principal of the management canister\n */\n public static managementCanister(): Principal {\n return this.fromText(MANAGEMENT_CANISTER_PRINCIPAL_TEXT_STR);\n }\n\n public static selfAuthenticating(publicKey: Uint8Array): Principal {\n const sha = sha224(publicKey);\n return new this(new Uint8Array([...sha, SELF_AUTHENTICATING_SUFFIX]));\n }\n\n public static from(other: unknown): Principal {\n if (typeof other === 'string') {\n return Principal.fromText(other);\n }\n if (Object.getPrototypeOf(other) === Uint8Array.prototype) {\n return new Principal(other as Uint8Array);\n }\n if (Principal.isPrincipal(other)) {\n return new Principal(other._arr);\n }\n\n throw new Error(`Impossible to convert ${JSON.stringify(other)} to Principal.`);\n }\n\n public static fromHex(hex: string): Principal {\n return new this(hexToBytes(hex));\n }\n\n public static fromText(text: string): Principal {\n let maybePrincipal = text;\n // If formatted as JSON string, parse it first\n if (text.includes(JSON_KEY_PRINCIPAL)) {\n const obj = JSON.parse(text);\n if (JSON_KEY_PRINCIPAL in obj) {\n maybePrincipal = obj[JSON_KEY_PRINCIPAL];\n }\n }\n\n const canisterIdNoDash = maybePrincipal.toLowerCase().replace(/-/g, '');\n\n let arr = base32Decode(canisterIdNoDash);\n arr = arr.slice(4, arr.length);\n\n const principal = new this(arr);\n if (principal.toText() !== maybePrincipal) {\n throw new Error(\n `Principal \"${principal.toText()}\" does not have a valid checksum (original value \"${maybePrincipal}\" may not be a valid Principal ID).`,\n );\n }\n\n return principal;\n }\n\n public static fromUint8Array(arr: Uint8Array): Principal {\n return new this(arr);\n }\n\n public static isPrincipal(other: unknown): other is Principal {\n return (\n other instanceof Principal ||\n (typeof other === 'object' &&\n other !== null &&\n '_isPrincipal' in other &&\n (other as { _isPrincipal: boolean })['_isPrincipal'] === true &&\n '_arr' in other &&\n (other as { _arr: Uint8Array })['_arr'] instanceof Uint8Array)\n );\n }\n\n public readonly _isPrincipal = true;\n\n protected constructor(private _arr: Uint8Array) {}\n\n public isAnonymous(): boolean {\n return this._arr.byteLength === 1 && this._arr[0] === ANONYMOUS_SUFFIX;\n }\n\n public toUint8Array(): Uint8Array {\n return this._arr;\n }\n\n public toHex(): string {\n return bytesToHex(this._arr).toUpperCase();\n }\n\n public toText(): string {\n const checksumArrayBuf = new ArrayBuffer(4);\n const view = new DataView(checksumArrayBuf);\n view.setUint32(0, getCrc32(this._arr));\n const checksum = new Uint8Array(checksumArrayBuf);\n\n const array = new Uint8Array([...checksum, ...this._arr]);\n\n const result = base32Encode(array);\n const matches = result.match(/.{1,5}/g);\n if (!matches) {\n // This should only happen if there's no character, which is unreachable.\n throw new Error();\n }\n return matches.join('-');\n }\n\n public toString(): string {\n return this.toText();\n }\n\n /**\n * Serializes to JSON\n * @returns {JsonnablePrincipal} a JSON object with a single key, {@link JSON_KEY_PRINCIPAL}, whose value is the principal as a string\n */\n public toJSON(): JsonnablePrincipal {\n return { [JSON_KEY_PRINCIPAL]: this.toText() };\n }\n\n /**\n * Utility method taking a Principal to compare against. Used for determining canister ranges in certificate verification\n * @param {Principal} other - a {@link Principal} to compare\n * @returns {'lt' | 'eq' | 'gt'} `'lt' | 'eq' | 'gt'` a string, representing less than, equal to, or greater than\n */\n public compareTo(other: Principal): 'lt' | 'eq' | 'gt' {\n for (let i = 0; i < Math.min(this._arr.length, other._arr.length); i++) {\n if (this._arr[i] < other._arr[i]) {\n return 'lt';\n }\n if (this._arr[i] > other._arr[i]) {\n return 'gt';\n }\n }\n // Here, at least one principal is a prefix of the other principal (they could be the same)\n if (this._arr.length < other._arr.length) {\n return 'lt';\n }\n if (this._arr.length > other._arr.length) {\n return 'gt';\n }\n return 'eq';\n }\n\n /**\n * Utility method checking whether a provided Principal is less than or equal to the current one using the {@link Principal.compareTo} method\n * @param other a {@link Principal} to compare\n * @returns {boolean} boolean\n */\n public ltEq(other: Principal): boolean {\n const cmp = this.compareTo(other);\n return cmp == 'lt' || cmp == 'eq';\n }\n\n /**\n * Utility method checking whether a provided Principal is greater than or equal to the current one using the {@link Principal.compareTo} method\n * @param other a {@link Principal} to compare\n * @returns {boolean} boolean\n */\n public gtEq(other: Principal): boolean {\n const cmp = this.compareTo(other);\n return cmp == 'gt' || cmp == 'eq';\n }\n}\n", "import {Principal} from '@icp-sdk/core/principal';\nimport {nonNullish} from './nullish.utils';\n\nconst JSON_KEY_BIGINT = '__bigint__';\nconst JSON_KEY_PRINCIPAL = '__principal__';\nconst JSON_KEY_UINT8ARRAY = '__uint8array__';\n\n/**\n * A custom replacer for `JSON.stringify` that converts specific types not natively supported\n * by the API into JSON-compatible formats.\n *\n * Supported conversions:\n * - `BigInt` \u2192 `{ \"__bigint__\": string }`\n * - `Principal` \u2192 `{ \"__principal__\": string }`\n * - `Uint8Array` \u2192 `{ \"__uint8array__\": number[] }`\n *\n * @param {string} _key - Ignored. Only provided for API compatibility.\n * @param {unknown} value - The value to transform before stringification.\n * @returns {unknown} The transformed value if it matches a known type, otherwise the original value.\n */\n// eslint-disable-next-line local-rules/prefer-object-params\nexport const jsonReplacer = (_key: string, value: unknown): unknown => {\n if (typeof value === 'bigint') {\n return {[JSON_KEY_BIGINT]: `${value}`};\n }\n\n if (nonNullish(value) && Principal.isPrincipal(value)) {\n // isPrincipal asserts if a value is a Principal, but does not assert if the object\n // contains functions such as toText(). That's why we construct a new object.\n return {[JSON_KEY_PRINCIPAL]: Principal.from(value).toText()};\n }\n\n if (nonNullish(value) && value instanceof Uint8Array) {\n return {[JSON_KEY_UINT8ARRAY]: Array.from(value)};\n }\n\n return value;\n};\n\n/**\n * A custom reviver for `JSON.parse` that reconstructs specific types from their JSON-encoded representations.\n *\n * This reverses the transformations applied by `jsonReplacer`, restoring the original types.\n *\n * Supported conversions:\n * - `{ \"__bigint__\": string }` \u2192 `BigInt`\n * - `{ \"__principal__\": string }` \u2192 `Principal`\n * - `{ \"__uint8array__\": number[] }` \u2192 `Uint8Array`\n *\n * @param {string} _key - Ignored but provided for API compatibility.\n * @param {unknown} value - The parsed value to transform.\n * @returns {unknown} The reconstructed value if it matches a known type, otherwise the original value.\n */\n// eslint-disable-next-line local-rules/prefer-object-params\nexport const jsonReviver = (_key: string, value: unknown): unknown => {\n const mapValue = <T>(key: string): T => (value as Record<string, T>)[key];\n\n if (nonNullish(value) && typeof value === 'object' && JSON_KEY_BIGINT in value) {\n return BigInt(mapValue(JSON_KEY_BIGINT));\n }\n\n if (nonNullish(value) && typeof value === 'object' && JSON_KEY_PRINCIPAL in value) {\n return Principal.fromText(mapValue(JSON_KEY_PRINCIPAL));\n }\n\n if (nonNullish(value) && typeof value === 'object' && JSON_KEY_UINT8ARRAY in value) {\n return Uint8Array.from(mapValue(JSON_KEY_UINT8ARRAY));\n }\n\n return value;\n};\n", "import {jsonReplacer, jsonReviver} from './json.utils';\n\n/**\n * Converts data to a Uint8Array for transmission or storage.\n * @template T\n * @param {T} data - The data to convert.\n * @returns {Promise<Uint8Array>} A promise that resolves to a Uint8Array representation of the data.\n */\nexport const toArray = async <T>(data: T): Promise<Uint8Array> => {\n const blob = new Blob([JSON.stringify(data, jsonReplacer)], {\n type: 'application/json; charset=utf-8'\n });\n return new Uint8Array(await blob.arrayBuffer());\n};\n\n/**\n * Converts a Uint8Array or number array back to the original data type.\n * @template T\n * @param {(Uint8Array | number[])} data - The array to convert.\n * @returns {Promise<T>} A promise that resolves to the original data.\n */\nexport const fromArray = async <T>(data: Uint8Array | number[]): Promise<T> => {\n const blob = new Blob(\n [data instanceof Uint8Array ? (data as Uint8Array<ArrayBuffer>) : new Uint8Array(data)],\n {\n type: 'application/json; charset=utf-8'\n }\n );\n return JSON.parse(await blob.text(), jsonReviver);\n};\n", "/**\n * Checks if the current environment is a browser.\n * @returns {boolean} True if the current environment is a browser, false otherwise.\n */\nexport const isBrowser = (): boolean => typeof window !== `undefined`;\n", "// Source: https://stackoverflow.com/a/77489094/5404186\nexport const convertCamelToSnake = (str: string): string =>\n str.replace(/([a-zA-Z])(?=[A-Z])/g, '$1_').toLowerCase();\n\nexport const capitalize = (str: string): string => str.charAt(0).toUpperCase() + str.slice(1);\n"],
|
|
5
|
-
"mappings": ";;AAAO,IAAMA,EAAN,cAAqC,KAAM,CAAC,EACtCC,EAAN,cAA2B,KAAM,CAAC,EAE5BC,EAI0B,CAAIC,EAAUC,IAA2B,CAC9E,GAAID,GAAU,KACZ,MAAM,IAAIF,EAAaG,CAAO,CAElC,EAGaC,GAAe,CAAIF,EAAUC,KACxCF,EAAiBC,EAAOC,CAAO,EACxBD,GAGIG,GAA0BC,GAAuB,CAC5D,GAAIA,EAAa,GAAKA,EAAa,IACjC,MAAM,IAAIP,EAAuB,GAAGO,CAAU,oCAAoC,CAEtF,EAkBaC,GAAc,CAACC,EAAUL,IAA4B,CAChE,MAAM,IAAI,MAAMA,CAAO,CACzB,ECzCO,IAAMM,GAAsBC,GAA8B,CAC/D,IAAMC,EAAO,IAAI,SAASD,EAAM,OAAQA,EAAM,WAAYA,EAAM,UAAU,EAC1E,GAAI,OAAOC,EAAK,cAAiB,WAC/B,OA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OAAIJ,EAAWD,CAAK,GAAK,OAAOA,GAAU,UAAYL,KAAmBK,EAChE,OAAOI,EAAST,CAAe,CAAC,EAGrCM,EAAWD,CAAK,GAAK,OAAOA,GAAU,UAAYJ,KAAsBI,EACnEE,EAAU,SAASE,EAASR,CAAkB,CAAC,EAGpDK,EAAWD,CAAK,GAAK,OAAOA,GAAU,UAAYH,KAAuBG,EACpE,WAAW,KAAKI,EAASP,CAAmB,CAAC,EAG/CG,CACT,EC9DO,IAAMM,GAAU,MAAUC,GAAiC,CAChE,IAAMC,EAAO,IAAI,KAAK,CAAC,KAAK,UAAUD,EAAME,EAAY,CAAC,EAAG,CAC1D,KAAM,iCACR,CAAC,EACD,OAAO,IAAI,WAAW,MAAMD,EAAK,YAAY,CAAC,CAChD,EAQaE,GAAY,MAAUH,GAA4C,CAC7E,IAAMC,EAAO,IAAI,KACf,CAACD,aAAgB,WAAcA,EAAmC,IAAI,WAAWA,CAAI,CAAC,EACtF,CACE,KAAM,iCACR,CACF,EACA,OAAO,KAAK,MAAM,MAAMC,EAAK,KAAK,EAAGG,EAAW,CAClD,ECzBO,IAAMC,GAAY,IAAe,OAAO,OAAW,ICHnD,IAAMC,GAAuBC,GAClCA,EAAI,QAAQ,uBAAwB,KAAK,EAAE,YAAY,EAE5CC,GAAcD,GAAwBA,EAAI,OAAO,CAAC,EAAE,YAAY,EAAIA,EAAI,MAAM,CAAC",
|
|
6
|
-
"names": ["InvalidPercentageError", "NullishError", "assertNonNullish", "value", "message", "asNonNullish", "assertPercentageNumber", "percentage", "assertNever", "_", "uint8ArrayToBigInt", "array", "view", "high", "low", "bigIntToUint8Array", "value", "buffer", "numberToUint8Array", "index", "arrayBufferToUint8Array", "uint8ArrayToArrayOfNumber", "arrayOfNumberToUint8Array", "numbers", "asciiStringToByteArray", "text", "c", "hexStringToUint8Array", "hexString", "matches", "assertNonNullish", "byte", "uint8ArraysEqual", "a", "b", "i", "uint8ArrayToHexString", "bytes", "str", "candidNumberArrayToBigInt", "result", "uint8ArrayToBase64", "uint8Array", "chunks", "i", "base64ToUint8Array", "base64String", "c", "NANOSECONDS_PER_MILLISECOND", "nowInBigIntNanoSeconds", "toBigIntNanoSeconds", "date", "debounce", "func", "timeout", "timer", "args", "next", "isNullish", "argument", "nonNullish", "notEmptyString", "value", "isEmptyString", "toNullable", "value", "nonNullish", "fromNullable", "fromDefinedNullable", "result", "assertNonNullish", "fromNullishNullable", "
|
|
3
|
+
"sources": ["../../src/utils/asserts.utils.ts", "../../src/utils/arrays.utils.ts", "../../src/utils/base64.utils.ts", "../../src/utils/date.utils.ts", "../../src/utils/debounce.utils.ts", "../../src/utils/nullish.utils.ts", "../../src/utils/did.utils.ts", "../../src/utils/json.utils.ts", "../../src/utils/doc.utils.ts", "../../src/utils/env.utils.ts", "../../src/utils/string.utils.ts"],
|
|
4
|
+
"sourcesContent": ["export class InvalidPercentageError extends Error {}\nexport class NullishError extends Error {}\n\nexport const assertNonNullish: <T>(\n value: T,\n message?: string\n // eslint-disable-next-line local-rules/prefer-object-params\n) => asserts value is NonNullable<T> = <T>(value: T, message?: string): void => {\n if (value === null || value === undefined) {\n throw new NullishError(message);\n }\n};\n\n// eslint-disable-next-line local-rules/prefer-object-params\nexport const asNonNullish = <T>(value: T, message?: string): NonNullable<T> => {\n assertNonNullish(value, message);\n return value;\n};\n\nexport const assertPercentageNumber = (percentage: number) => {\n if (percentage < 0 || percentage > 100) {\n throw new InvalidPercentageError(`${percentage} is not a valid percentage number.`);\n }\n};\n\n/**\n * Utility to enforce exhaustiveness checks in TypeScript.\n *\n * This function should only be called in branches of a `switch` or conditional\n * that should be unreachable if the union type has been fully handled.\n *\n * By typing the parameter as `never`, the compiler will emit an error if\n * a new variant is added to the union but not covered in the logic.\n *\n * @param _ - A value that should be of type `never`. If this is not the case,\n * the TypeScript compiler will flag a type error.\n * @param message - Optional custom error message to include in the thrown error.\n * @throws {Error} Always throws when invoked at runtime.\n *\n */\n// eslint-disable-next-line local-rules/prefer-object-params\nexport const assertNever = (_: never, message?: string): never => {\n throw new Error(message);\n};\n", "import {assertNonNullish} from './asserts.utils';\n\nexport const uint8ArrayToBigInt = (array: Uint8Array): bigint => {\n const view = new DataView(array.buffer, array.byteOffset, array.byteLength);\n if (typeof view.getBigUint64 === 'function') {\n return view.getBigUint64(0);\n }\n const high = BigInt(view.getUint32(0));\n const low = BigInt(view.getUint32(4));\n\n return (high << BigInt(32)) + low;\n};\n\nexport const bigIntToUint8Array = (value: bigint): Uint8Array => {\n const buffer = new ArrayBuffer(8);\n const view = new DataView(buffer);\n if (typeof view.setBigUint64 === 'function') {\n view.setBigUint64(0, value);\n } else {\n const high = Number(value >> BigInt(32));\n const low = Number(value & BigInt(0xffffffff));\n\n view.setUint32(0, high);\n view.setUint32(4, low);\n }\n\n return new Uint8Array(buffer);\n};\n\nexport const numberToUint8Array = (value: number): Uint8Array => {\n const view = new DataView(new ArrayBuffer(8));\n for (let index = 7; index >= 0; --index) {\n view.setUint8(index, value % 256);\n value = value >> 8;\n }\n return new Uint8Array(view.buffer);\n};\n\nexport const arrayBufferToUint8Array = (buffer: ArrayBuffer): Uint8Array => new Uint8Array(buffer);\n\nexport const uint8ArrayToArrayOfNumber = (array: Uint8Array): Array<number> => Array.from(array);\n\nexport const arrayOfNumberToUint8Array = (numbers: Array<number>): Uint8Array =>\n new Uint8Array(numbers);\n\nexport const asciiStringToByteArray = (text: string): Array<number> =>\n Array.from(text).map((c) => c.charCodeAt(0));\n\nexport const hexStringToUint8Array = (hexString: string): Uint8Array => {\n const matches = hexString.match(/.{1,2}/g);\n\n assertNonNullish(matches, 'Invalid hex string.');\n\n return Uint8Array.from(matches.map((byte) => parseInt(byte, 16)));\n};\n\n/**\n * Compare two Uint8Arrays for byte-level equality.\n *\n * @param {Object} params\n * @param {Uint8Array} params.a - First Uint8Array to compare.\n * @param {Uint8Array} params.b - Second Uint8Array to compare.\n * @returns {boolean} True if both arrays have the same length and identical contents.\n */\nexport const uint8ArraysEqual = ({a, b}: {a: Uint8Array; b: Uint8Array}) =>\n a.length === b.length && a.every((byte, i) => byte === b[i]);\n\nexport const uint8ArrayToHexString = (bytes: Uint8Array | number[]) => {\n if (!(bytes instanceof Uint8Array)) {\n bytes = Uint8Array.from(bytes);\n }\n return bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), '');\n};\n\nexport const candidNumberArrayToBigInt = (array: number[]): bigint => {\n let result = 0n;\n for (let i = array.length - 1; i >= 0; i--) {\n result = (result << 32n) + BigInt(array[i]);\n }\n return result;\n};\n", "/**\n * Converts a Uint8Array (binary data) to a base64 encoded string.\n *\n * @param {Uint8Array} uint8Array - The Uint8Array containing binary data to be encoded.\n * @returns {string} - The base64 encoded string representation of the binary data.\n */\nexport const uint8ArrayToBase64 = (uint8Array: Uint8Array): string => {\n // Spreading large Uint8Arrays or using Array.from loses precision when used together with String.fromCharCode.\n // Therefore, we use a chunked loop, which better than a reducer or iterating on every value.\n // Spreading a small chunk - such as 32kb - works as expected.\n const chunkSize = 0x8000; // 32 kb\n const chunks: string[] = [];\n for (let i = 0; i < uint8Array.length; i += chunkSize) {\n chunks.push(String.fromCharCode(...uint8Array.subarray(i, i + chunkSize)));\n }\n return btoa(chunks.join(''));\n};\n\n/**\n * Converts a base64 encoded string to a Uint8Array (binary data).\n *\n * @param {string} base64String - The base64 encoded string to be decoded.\n * @returns {Uint8Array} - The Uint8Array representation of the decoded binary data.\n */\nexport const base64ToUint8Array = (base64String: string): Uint8Array =>\n Uint8Array.from(atob(base64String), (c) => c.charCodeAt(0));\n", "const NANOSECONDS_PER_MILLISECOND = 1_000_000n;\n\n/**\n * Returns the current timestamp in nanoseconds as a `bigint`.\n *\n * @returns {bigint} The current timestamp in nanoseconds.\n */\nexport const nowInBigIntNanoSeconds = (): bigint =>\n BigInt(Date.now()) * NANOSECONDS_PER_MILLISECOND;\n\n/**\n * Converts a given `Date` object to a timestamp in nanoseconds as a `bigint`.\n *\n * @param {Date} date - The `Date` object to convert.\n * @returns {bigint} The timestamp in nanoseconds.\n */\nexport const toBigIntNanoSeconds = (date: Date): bigint =>\n BigInt(date.getTime()) * NANOSECONDS_PER_MILLISECOND;\n", "/**\n * Creates a debounced version of the provided function.\n *\n * The debounced function postpones its execution until after a certain amount of time\n * has elapsed since the last time it was invoked. This is useful for limiting the rate\n * at which a function is called (e.g. in response to user input or events).\n *\n * @param {Function} func - The function to debounce. It will only be called after no new calls happen within the specified timeout.\n * @param {number} [timeout=300] - The debounce delay in milliseconds. Defaults to 300ms if not provided or invalid.\n * @returns {(args: unknown[]) => void} A debounced version of the original function.\n */\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type, local-rules/prefer-object-params\nexport const debounce = (func: Function, timeout?: number) => {\n let timer: NodeJS.Timer | undefined;\n\n return (...args: unknown[]) => {\n const next = () => func(...args);\n\n if (timer) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore TypeScript global and window confusion even if we are using @types/node\n clearTimeout(timer);\n }\n\n timer = setTimeout(next, timeout !== undefined && timeout > 0 ? timeout : 300);\n };\n};\n", "/**\n * Checks if a given argument is null or undefined.\n *\n * @template T - The type of the argument.\n * @param {T | undefined | null} argument - The argument to check.\n * @returns {argument is undefined | null} `true` if the argument is null or undefined; otherwise, `false`.\n */\nexport const isNullish = <T>(argument: T | undefined | null): argument is undefined | null =>\n argument === null || argument === undefined;\n\n/**\n * Checks if a given argument is neither null nor undefined.\n *\n * @template T - The type of the argument.\n * @param {T | undefined | null} argument - The argument to check.\n * @returns {argument is NonNullable<T>} `true` if the argument is not null or undefined; otherwise, `false`.\n */\nexport const nonNullish = <T>(argument: T | undefined | null): argument is NonNullable<T> =>\n !isNullish(argument);\n\n/**\n * Checks if a given value is not null, not undefined, and not an empty string.\n *\n * @param {string | undefined | null} value - The value to check.\n * @returns {boolean} `true` if the value is not null, not undefined, and not an empty string; otherwise, `false`.\n */\nexport const notEmptyString = (value: string | undefined | null): value is string =>\n nonNullish(value) && value !== '';\n\n/**\n * Checks if a given value is null, undefined, or an empty string.\n *\n * @param {string | undefined | null} value - The value to check.\n * @returns {value is undefined | null | \"\"} Type predicate indicating if the value is null, undefined, or an empty string.\n */\nexport const isEmptyString = (value: string | undefined | null): value is undefined | null | '' =>\n !notEmptyString(value);\n", "import type {Nullable, NullishNullable} from '../types/did.utils';\nimport {assertNonNullish} from './asserts.utils';\nimport {nonNullish} from './nullish.utils';\n\n/**\n * Converts a value into a Candid-style variant representation of an optional value.\n *\n * @template T The type of the value.\n * @param {T | null | undefined} value - The value to convert into a Candid-style variant.\n * @returns {Nullable<T>} A Candid-style variant representation: an empty array for `null` and `undefined` or an array with the value.\n */\nexport const toNullable = <T>(value?: T | null): Nullable<T> => (nonNullish(value) ? [value] : []);\n\n/**\n * Extracts the value from a Candid-style variant representation of an optional value.\n *\n * @template T The type of the value.\n * @param {Nullable<T>} value - A Candid-style variant representing an optional value.\n * @returns {T | undefined} The extracted value, or `undefined` if the array is empty.\n */\nexport const fromNullable = <T>(value: Nullable<T>): T | undefined => value?.[0];\n\n/**\n * Extracts the value from a Candid-style variant representation of an optional value,\n * ensuring the value is defined. Throws an error if the array is empty or the value is nullish.\n *\n * @template T The type of the value.\n * @param {Nullable<T>} value - A Candid-style variant representing an optional value.\n * @returns {T} The extracted value.\n * @throws {Error} If the array is empty or the value is nullish.\n */\nexport const fromDefinedNullable = <T>(value: Nullable<T>): T => {\n const result = fromNullable(value);\n\n assertNonNullish(result);\n\n return result;\n};\n\n/**\n * Extracts the value from a nullish Candid-style variant representation.\n *\n * @template T The type of the value.\n * @param {NullishNullable<T>} value - A Candid-style variant or `undefined`.\n * @returns {T | undefined} The extracted value, or `undefined` if the input is nullish or the array is empty.\n */\nexport const fromNullishNullable = <T>(value: NullishNullable<T>): T | undefined =>\n fromNullable(value ?? []);\n", "import {Principal} from '@icp-sdk/core/principal';\nimport {nonNullish} from './nullish.utils';\n\nconst JSON_KEY_BIGINT = '__bigint__';\nconst JSON_KEY_PRINCIPAL = '__principal__';\nconst JSON_KEY_UINT8ARRAY = '__uint8array__';\n\n/**\n * A custom replacer for `JSON.stringify` that converts specific types not natively supported\n * by the API into JSON-compatible formats.\n *\n * Supported conversions:\n * - `BigInt` \u2192 `{ \"__bigint__\": string }`\n * - `Principal` \u2192 `{ \"__principal__\": string }`\n * - `Uint8Array` \u2192 `{ \"__uint8array__\": number[] }`\n *\n * @param {string} _key - Ignored. Only provided for API compatibility.\n * @param {unknown} value - The value to transform before stringification.\n * @returns {unknown} The transformed value if it matches a known type, otherwise the original value.\n */\n// eslint-disable-next-line local-rules/prefer-object-params\nexport const jsonReplacer = (_key: string, value: unknown): unknown => {\n if (typeof value === 'bigint') {\n return {[JSON_KEY_BIGINT]: `${value}`};\n }\n\n if (nonNullish(value) && Principal.isPrincipal(value)) {\n // isPrincipal asserts if a value is a Principal, but does not assert if the object\n // contains functions such as toText(). That's why we construct a new object.\n return {[JSON_KEY_PRINCIPAL]: Principal.from(value).toText()};\n }\n\n if (nonNullish(value) && value instanceof Uint8Array) {\n return {[JSON_KEY_UINT8ARRAY]: Array.from(value)};\n }\n\n return value;\n};\n\n/**\n * A custom reviver for `JSON.parse` that reconstructs specific types from their JSON-encoded representations.\n *\n * This reverses the transformations applied by `jsonReplacer`, restoring the original types.\n *\n * Supported conversions:\n * - `{ \"__bigint__\": string }` \u2192 `BigInt`\n * - `{ \"__principal__\": string }` \u2192 `Principal`\n * - `{ \"__uint8array__\": number[] }` \u2192 `Uint8Array`\n *\n * @param {string} _key - Ignored but provided for API compatibility.\n * @param {unknown} value - The parsed value to transform.\n * @returns {unknown} The reconstructed value if it matches a known type, otherwise the original value.\n */\n// eslint-disable-next-line local-rules/prefer-object-params\nexport const jsonReviver = (_key: string, value: unknown): unknown => {\n const mapValue = <T>(key: string): T => (value as Record<string, T>)[key];\n\n if (nonNullish(value) && typeof value === 'object' && JSON_KEY_BIGINT in value) {\n return BigInt(mapValue(JSON_KEY_BIGINT));\n }\n\n if (nonNullish(value) && typeof value === 'object' && JSON_KEY_PRINCIPAL in value) {\n return Principal.fromText(mapValue(JSON_KEY_PRINCIPAL));\n }\n\n if (nonNullish(value) && typeof value === 'object' && JSON_KEY_UINT8ARRAY in value) {\n return Uint8Array.from(mapValue(JSON_KEY_UINT8ARRAY));\n }\n\n return value;\n};\n", "import {jsonReplacer, jsonReviver} from './json.utils';\n\n/**\n * Converts data to a Uint8Array for transmission or storage.\n * @template T\n * @param {T} data - The data to convert.\n * @returns {Promise<Uint8Array>} A promise that resolves to a Uint8Array representation of the data.\n */\nexport const toArray = async <T>(data: T): Promise<Uint8Array> => {\n const blob = new Blob([JSON.stringify(data, jsonReplacer)], {\n type: 'application/json; charset=utf-8'\n });\n return new Uint8Array(await blob.arrayBuffer());\n};\n\n/**\n * Converts a Uint8Array or number array back to the original data type.\n * @template T\n * @param {(Uint8Array | number[])} data - The array to convert.\n * @returns {Promise<T>} A promise that resolves to the original data.\n */\nexport const fromArray = async <T>(data: Uint8Array | number[]): Promise<T> => {\n const blob = new Blob(\n [data instanceof Uint8Array ? (data as Uint8Array<ArrayBuffer>) : new Uint8Array(data)],\n {\n type: 'application/json; charset=utf-8'\n }\n );\n return JSON.parse(await blob.text(), jsonReviver);\n};\n", "/**\n * Checks if the current environment is a browser.\n * @returns {boolean} True if the current environment is a browser, false otherwise.\n */\nexport const isBrowser = (): boolean => typeof window !== `undefined`;\n", "// Source: https://stackoverflow.com/a/77489094/5404186\nexport const convertCamelToSnake = (str: string): string =>\n str.replace(/([a-zA-Z])(?=[A-Z])/g, '$1_').toLowerCase();\n\nexport const capitalize = (str: string): string => str.charAt(0).toUpperCase() + str.slice(1);\n"],
|
|
5
|
+
"mappings": ";;AAAO,IAAMA,EAAN,cAAqC,KAAM,CAAC,EACtCC,EAAN,cAA2B,KAAM,CAAC,EAE5BC,EAI0B,CAAIC,EAAUC,IAA2B,CAC9E,GAAID,GAAU,KACZ,MAAM,IAAIF,EAAaG,CAAO,CAElC,EAGaC,EAAe,CAAIF,EAAUC,KACxCF,EAAiBC,E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e,CAAC,EAGrCM,EAAWD,CAAK,GAAK,OAAOA,GAAU,UAAYJ,KAAsBI,EACnEE,EAAU,SAASE,EAASR,CAAkB,CAAC,EAGpDK,EAAWD,CAAK,GAAK,OAAOA,GAAU,UAAYH,KAAuBG,EACpE,WAAW,KAAKI,EAASP,CAAmB,CAAC,EAG/CG,CACT,EC9DO,IAAMM,GAAU,MAAUC,GAAiC,CAChE,IAAMC,EAAO,IAAI,KAAK,CAAC,KAAK,UAAUD,EAAME,CAAY,CAAC,EAAG,CAC1D,KAAM,iCACR,CAAC,EACD,OAAO,IAAI,WAAW,MAAMD,EAAK,YAAY,CAAC,CAChD,EAQaE,GAAY,MAAUH,GAA4C,CAC7E,IAAMC,EAAO,IAAI,KACf,CAACD,aAAgB,WAAcA,EAAmC,IAAI,WAAWA,CAAI,CAAC,EACtF,CACE,KAAM,iCACR,CACF,EACA,OAAO,KAAK,MAAM,MAAMC,EAAK,KAAK,EAAGG,CAAW,CAClD,ECzBO,IAAMC,GAAY,IAAe,OAAO,OAAW,ICHnD,IAAMC,GAAuBC,GAClCA,EAAI,QAAQ,uBAAwB,KAAK,EAAE,YAAY,EAE5CC,GAAcD,GAAwBA,EAAI,OAAO,CAAC,EAAE,YAAY,EAAIA,EAAI,MAAM,CAAC",
|
|
6
|
+
"names": ["InvalidPercentageError", "NullishError", "assertNonNullish", "value", "message", "asNonNullish", "assertPercentageNumber", "percentage", "assertNever", "_", "uint8ArrayToBigInt", "array", "view", "high", "low", "bigIntToUint8Array", "value", "buffer", "numberToUint8Array", "index", "arrayBufferToUint8Array", "uint8ArrayToArrayOfNumber", "arrayOfNumberToUint8Array", "numbers", "asciiStringToByteArray", "text", "c", "hexStringToUint8Array", "hexString", "matches", "assertNonNullish", "byte", "uint8ArraysEqual", "a", "b", "i", "uint8ArrayToHexString", "bytes", "str", "candidNumberArrayToBigInt", "result", "uint8ArrayToBase64", "uint8Array", "chunks", "i", "base64ToUint8Array", "base64String", "c", "NANOSECONDS_PER_MILLISECOND", "nowInBigIntNanoSeconds", "toBigIntNanoSeconds", "date", "debounce", "func", "timeout", "timer", "args", "next", "isNullish", "argument", "nonNullish", "notEmptyString", "value", "isEmptyString", "toNullable", "value", "nonNullish", "fromNullable", "fromDefinedNullable", "result", "assertNonNullish", "fromNullishNullable", "Principal", "JSON_KEY_BIGINT", "JSON_KEY_PRINCIPAL", "JSON_KEY_UINT8ARRAY", "jsonReplacer", "_key", "value", "nonNullish", "Principal", "jsonReviver", "mapValue", "key", "toArray", "data", "blob", "jsonReplacer", "fromArray", "jsonReviver", "isBrowser", "convertCamelToSnake", "str", "capitalize"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@junobuild/utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2-next-2026-04-11",
|
|
4
4
|
"description": "A collection of utilities and constants for Juno JS libs.",
|
|
5
5
|
"author": "David Dal Busco (https://daviddalbusco.com)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,5 +39,8 @@
|
|
|
39
39
|
"bugs": {
|
|
40
40
|
"url": "https://github.com/junobuild/juno-js"
|
|
41
41
|
},
|
|
42
|
-
"homepage": "https://juno.build"
|
|
43
|
-
|
|
42
|
+
"homepage": "https://juno.build",
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"@icp-sdk/core": "*"
|
|
45
|
+
}
|
|
46
|
+
}
|