@solana/webcrypto-ed25519-polyfill 2.0.0-experimental.fcae73c → 2.0.0-experimental.fcff844

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.
@@ -1,29 +1,11 @@
1
1
  (function () {
2
2
  'use strict';
3
3
 
4
- function Lt(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`Wrong positive integer: ${t}`)}function qe(t){if(typeof t!="boolean")throw new Error(`Expected boolean, not ${t}`)}function ne(t,...e){if(!(t instanceof Uint8Array))throw new Error("Expected Uint8Array");if(e.length>0&&!e.includes(t.length))throw new Error(`Expected Uint8Array of length ${e}, not of length=${t.length}`)}function De(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Lt(t.outputLen),Lt(t.blockLen);}function Pe(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function Me(t,e){ne(t);let n=e.outputLen;if(t.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}var ke={number:Lt,bool:qe,bytes:ne,hash:De,exists:Pe,output:Me},yt=ke;var xt=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var re=t=>t instanceof Uint8Array;var gt=t=>new DataView(t.buffer,t.byteOffset,t.byteLength);var Ve=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!Ve)throw new Error("Non little-endian hardware is not supported");Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Ot(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function Nt(t){if(typeof t=="string"&&(t=Ot(t)),!re(t))throw new Error(`expected Uint8Array, got ${typeof t}`);return t}function oe(...t){let e=new Uint8Array(t.reduce((r,o)=>r+o.length,0)),n=0;return t.forEach(r=>{if(!re(r))throw new Error("Uint8Array expected");e.set(r,n),n+=r.length;}),e}var bt=class{clone(){return this._cloneInto()}};function lt(t){let e=r=>t().update(Nt(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function se(t=32){if(xt&&typeof xt.getRandomValues=="function")return xt.getRandomValues(new Uint8Array(t));throw new Error("crypto.getRandomValues must be defined")}function Ze(t,e,n,r){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,n,r);let o=BigInt(32),f=BigInt(4294967295),a=Number(n>>o&f),i=Number(n&f),s=r?4:0,l=r?0:4;t.setUint32(e+s,a,r),t.setUint32(e+l,i,r);}var wt=class extends bt{constructor(e,n,r,o){super(),this.blockLen=e,this.outputLen=n,this.padOffset=r,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=gt(this.buffer);}update(e){yt.exists(this);let{view:n,buffer:r,blockLen:o}=this;e=Nt(e);let f=e.length;for(let a=0;a<f;){let i=Math.min(o-this.pos,f-a);if(i===o){let s=gt(e);for(;o<=f-a;a+=o)this.process(s,a);continue}r.set(e.subarray(a,a+i),this.pos),this.pos+=i,a+=i,this.pos===o&&(this.process(n,0),this.pos=0);}return this.length+=e.length,this.roundClean(),this}digestInto(e){yt.exists(this),yt.output(e,this),this.finished=!0;let{buffer:n,view:r,blockLen:o,isLE:f}=this,{pos:a}=this;n[a++]=128,this.buffer.subarray(a).fill(0),this.padOffset>o-a&&(this.process(r,0),a=0);for(let d=a;d<o;d++)n[d]=0;Ze(r,o-8,BigInt(this.length*8),f),this.process(r,0);let i=gt(e),s=this.outputLen;if(s%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let l=s/4,c=this.get();if(l>c.length)throw new Error("_sha2: outputLen bigger than state");for(let d=0;d<l;d++)i.setUint32(4*d,c[d],f);}digest(){let{buffer:e,outputLen:n}=this;this.digestInto(e);let r=e.slice(0,n);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:n,buffer:r,length:o,finished:f,destroyed:a,pos:i}=this;return e.length=o,e.pos=i,e.finished=f,e.destroyed=a,o%n&&e.buffer.set(r),e}};var mt=BigInt(4294967295),Ct=BigInt(32);function ie(t,e=!1){return e?{h:Number(t&mt),l:Number(t>>Ct&mt)}:{h:Number(t>>Ct&mt)|0,l:Number(t&mt)|0}}function Ge(t,e=!1){let n=new Uint32Array(t.length),r=new Uint32Array(t.length);for(let o=0;o<t.length;o++){let{h:f,l:a}=ie(t[o],e);[n[o],r[o]]=[f,a];}return [n,r]}var $e=(t,e)=>BigInt(t>>>0)<<Ct|BigInt(e>>>0),je=(t,e,n)=>t>>>n,ze=(t,e,n)=>t<<32-n|e>>>n,Fe=(t,e,n)=>t>>>n|e<<32-n,Ye=(t,e,n)=>t<<32-n|e>>>n,We=(t,e,n)=>t<<64-n|e>>>n-32,Xe=(t,e,n)=>t>>>n-32|e<<64-n,Qe=(t,e)=>e,Je=(t,e)=>t,tn=(t,e,n)=>t<<n|e>>>32-n,en=(t,e,n)=>e<<n|t>>>32-n,nn=(t,e,n)=>e<<n-32|t>>>64-n,rn=(t,e,n)=>t<<n-32|e>>>64-n;function on(t,e,n,r){let o=(e>>>0)+(r>>>0);return {h:t+n+(o/2**32|0)|0,l:o|0}}var sn=(t,e,n)=>(t>>>0)+(e>>>0)+(n>>>0),cn=(t,e,n,r)=>e+n+r+(t/2**32|0)|0,fn=(t,e,n,r)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0),an=(t,e,n,r,o)=>e+n+r+o+(t/2**32|0)|0,ln=(t,e,n,r,o)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0)+(o>>>0),un=(t,e,n,r,o,f)=>e+n+r+o+f+(t/2**32|0)|0,dn={fromBig:ie,split:Ge,toBig:$e,shrSH:je,shrSL:ze,rotrSH:Fe,rotrSL:Ye,rotrBH:We,rotrBL:Xe,rotr32H:Qe,rotr32L:Je,rotlSH:tn,rotlSL:en,rotlBH:nn,rotlBL:rn,add:on,add3L:sn,add3H:cn,add4L:fn,add4H:an,add5H:un,add5L:ln},y=dn;var [hn,pn]=y.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(t=>BigInt(t))),Q=new Uint32Array(80),J=new Uint32Array(80),ft=class extends wt{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209;}get(){let{Ah:e,Al:n,Bh:r,Bl:o,Ch:f,Cl:a,Dh:i,Dl:s,Eh:l,El:c,Fh:d,Fl:b,Gh:N,Gl:O,Hh:C,Hl:S}=this;return [e,n,r,o,f,a,i,s,l,c,d,b,N,O,C,S]}set(e,n,r,o,f,a,i,s,l,c,d,b,N,O,C,S){this.Ah=e|0,this.Al=n|0,this.Bh=r|0,this.Bl=o|0,this.Ch=f|0,this.Cl=a|0,this.Dh=i|0,this.Dl=s|0,this.Eh=l|0,this.El=c|0,this.Fh=d|0,this.Fl=b|0,this.Gh=N|0,this.Gl=O|0,this.Hh=C|0,this.Hl=S|0;}process(e,n){for(let m=0;m<16;m++,n+=4)Q[m]=e.getUint32(n),J[m]=e.getUint32(n+=4);for(let m=16;m<80;m++){let q=Q[m-15]|0,g=J[m-15]|0,z=y.rotrSH(q,g,1)^y.rotrSH(q,g,8)^y.shrSH(q,g,7),it=y.rotrSL(q,g,1)^y.rotrSL(q,g,8)^y.shrSL(q,g,7),D=Q[m-2]|0,k=J[m-2]|0,nt=y.rotrSH(D,k,19)^y.rotrBH(D,k,61)^y.shrSH(D,k,6),W=y.rotrSL(D,k,19)^y.rotrBL(D,k,61)^y.shrSL(D,k,6),ct=y.add4L(it,W,J[m-7],J[m-16]),rt=y.add4H(ct,z,nt,Q[m-7],Q[m-16]);Q[m]=rt|0,J[m]=ct|0;}let{Ah:r,Al:o,Bh:f,Bl:a,Ch:i,Cl:s,Dh:l,Dl:c,Eh:d,El:b,Fh:N,Fl:O,Gh:C,Gl:S,Hh:M,Hl:$}=this;for(let m=0;m<80;m++){let q=y.rotrSH(d,b,14)^y.rotrSH(d,b,18)^y.rotrBH(d,b,41),g=y.rotrSL(d,b,14)^y.rotrSL(d,b,18)^y.rotrBL(d,b,41),z=d&N^~d&C,it=b&O^~b&S,D=y.add5L($,g,it,pn[m],J[m]),k=y.add5H(D,M,q,z,hn[m],Q[m]),nt=D|0,W=y.rotrSH(r,o,28)^y.rotrBH(r,o,34)^y.rotrBH(r,o,39),ct=y.rotrSL(r,o,28)^y.rotrBL(r,o,34)^y.rotrBL(r,o,39),rt=r&f^r&i^f&i,At=o&a^o&s^a&s;M=C|0,$=S|0,C=N|0,S=O|0,N=d|0,O=b|0,{h:d,l:b}=y.add(l|0,c|0,k|0,nt|0),l=i|0,c=s|0,i=f|0,s=a|0,f=r|0,a=o|0;let dt=y.add3L(nt,ct,At);r=y.add3H(dt,k,W,rt),o=dt|0;}(({h:r,l:o}=y.add(this.Ah|0,this.Al|0,r|0,o|0))),{h:f,l:a}=y.add(this.Bh|0,this.Bl|0,f|0,a|0),{h:i,l:s}=y.add(this.Ch|0,this.Cl|0,i|0,s|0),{h:l,l:c}=y.add(this.Dh|0,this.Dl|0,l|0,c|0),{h:d,l:b}=y.add(this.Eh|0,this.El|0,d|0,b|0),{h:N,l:O}=y.add(this.Fh|0,this.Fl|0,N|0,O|0),{h:C,l:S}=y.add(this.Gh|0,this.Gl|0,C|0,S|0),{h:M,l:$}=y.add(this.Hh|0,this.Hl|0,M|0,$|0),this.set(r,o,f,a,i,s,l,c,d,b,N,O,C,S,M,$);}roundClean(){Q.fill(0),J.fill(0);}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);}},Tt=class extends ft{constructor(){super(),this.Ah=-1942145080,this.Al=424955298,this.Bh=1944164710,this.Bl=-1982016298,this.Ch=502970286,this.Cl=855612546,this.Dh=1738396948,this.Dl=1479516111,this.Eh=258812777,this.El=2077511080,this.Fh=2011393907,this.Fl=79989058,this.Gh=1067287976,this.Gl=1780299464,this.Hh=286451373,this.Hl=-1848208735,this.outputLen=28;}},Ut=class extends ft{constructor(){super(),this.Ah=573645204,this.Al=-64227540,this.Bh=-1621794909,this.Bl=-934517566,this.Ch=596883563,this.Cl=1867755857,this.Dh=-1774684391,this.Dl=1497426621,this.Eh=-1775747358,this.El=-1467023389,this.Fh=-1101128155,this.Fl=1401305490,this.Gh=721525244,this.Gl=746961066,this.Hh=246885852,this.Hl=-2117784414,this.outputLen=32;}},Kt=class extends ft{constructor(){super(),this.Ah=-876896931,this.Al=-1056596264,this.Bh=1654270250,this.Bl=914150663,this.Ch=-1856437926,this.Cl=812702999,this.Dh=355462360,this.Dl=-150054599,this.Eh=1731405415,this.El=-4191439,this.Fh=-1900787065,this.Fl=1750603025,this.Gh=-619958771,this.Gl=1694076839,this.Hh=1203062813,this.Hl=-1090891868,this.outputLen=48;}},Rt=lt(()=>new ft);lt(()=>new Tt);lt(()=>new Ut);lt(()=>new Kt);BigInt(0);var yn=BigInt(1),xn=BigInt(2),Et=t=>t instanceof Uint8Array,bn=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function ut(t){if(!Et(t))throw new Error("Uint8Array expected");let e="";for(let n=0;n<t.length;n++)e+=bn[t[n]];return e}function ce(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return BigInt(t===""?"0":`0x${t}`)}function fe(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);let e=t.length;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(e/2);for(let r=0;r<n.length;r++){let o=r*2,f=t.slice(o,o+2),a=Number.parseInt(f,16);if(Number.isNaN(a)||a<0)throw new Error("Invalid byte sequence");n[r]=a;}return n}function Ht(t){return ce(ut(t))}function tt(t){if(!Et(t))throw new Error("Uint8Array expected");return ce(ut(Uint8Array.from(t).reverse()))}function qt(t,e){return fe(t.toString(16).padStart(e*2,"0"))}function ot(t,e){return qt(t,e).reverse()}function V(t,e,n){let r;if(typeof e=="string")try{r=fe(e);}catch(f){throw new Error(`${t} must be valid hex string, got "${e}". Cause: ${f}`)}else if(Et(e))r=Uint8Array.from(e);else throw new Error(`${t} must be hex string or Uint8Array`);let o=r.length;if(typeof n=="number"&&o!==n)throw new Error(`${t} expected ${n} bytes, got ${o}`);return r}function Bt(...t){let e=new Uint8Array(t.reduce((r,o)=>r+o.length,0)),n=0;return t.forEach(r=>{if(!Et(r))throw new Error("Uint8Array expected");e.set(r,n),n+=r.length;}),e}var ae=t=>(xn<<BigInt(t-1))-yn;var gn={bigint:t=>typeof t=="bigint",function:t=>typeof t=="function",boolean:t=>typeof t=="boolean",string:t=>typeof t=="string",isSafeInteger:t=>Number.isSafeInteger(t),array:t=>Array.isArray(t),field:(t,e)=>e.Fp.isValid(t),hash:t=>typeof t=="function"&&Number.isSafeInteger(t.outputLen)};function et(t,e,n={}){let r=(o,f,a)=>{let i=gn[f];if(typeof i!="function")throw new Error(`Invalid validator "${f}", expected function`);let s=t[o];if(!(a&&s===void 0)&&!i(s,t))throw new Error(`Invalid param ${String(o)}=${s} (${typeof s}), expected ${f}`)};for(let[o,f]of Object.entries(e))r(o,f,!1);for(let[o,f]of Object.entries(n))r(o,f,!0);return t}var T=BigInt(0),L=BigInt(1),st=BigInt(2),mn=BigInt(3),Dt=BigInt(4),le=BigInt(5),ue=BigInt(8);BigInt(9);BigInt(16);function A(t,e){let n=t%e;return n>=T?n:e+n}function he(t,e,n){if(n<=T||e<T)throw new Error("Expected power/modulo > 0");if(n===L)return T;let r=L;for(;e>T;)e&L&&(r=r*t%n),t=t*t%n,e>>=L;return r}function Z(t,e,n){let r=t;for(;e-- >T;)r*=r,r%=n;return r}function de(t,e){if(t===T||e<=T)throw new Error(`invert: expected positive integers, got n=${t} mod=${e}`);let n=A(t,e),r=e,o=T,a=L;for(;n!==T;){let l=r/n,c=r%n,d=o-a*l;r=n,n=c,o=a,a=d;}if(r!==L)throw new Error("invert: does not exist");return A(o,e)}function _n(t){let e=(t-L)/st,n,r,o;for(n=t-L,r=0;n%st===T;n/=st,r++);for(o=st;o<t&&he(o,e,t)!==t-L;o++);if(r===1){let a=(t+L)/Dt;return function(s,l){let c=s.pow(l,a);if(!s.eql(s.sqr(c),l))throw new Error("Cannot find square root");return c}}let f=(n+L)/st;return function(i,s){if(i.pow(s,e)===i.neg(i.ONE))throw new Error("Cannot find square root");let l=r,c=i.pow(i.mul(i.ONE,o),n),d=i.pow(s,f),b=i.pow(s,n);for(;!i.eql(b,i.ONE);){if(i.eql(b,i.ZERO))return i.ZERO;let N=1;for(let C=i.sqr(b);N<l&&!i.eql(C,i.ONE);N++)C=i.sqr(C);let O=i.pow(c,L<<BigInt(l-N-1));c=i.sqr(O),d=i.mul(d,O),b=i.mul(b,c),l=N;}return d}}function Sn(t){if(t%Dt===mn){let e=(t+L)/Dt;return function(r,o){let f=r.pow(o,e);if(!r.eql(r.sqr(f),o))throw new Error("Cannot find square root");return f}}if(t%ue===le){let e=(t-le)/ue;return function(r,o){let f=r.mul(o,st),a=r.pow(f,e),i=r.mul(o,a),s=r.mul(r.mul(i,st),a),l=r.mul(i,r.sub(s,r.ONE));if(!r.eql(r.sqr(l),o))throw new Error("Cannot find square root");return l}}return _n(t)}var pe=(t,e)=>(A(t,e)&L)===L,vn=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ye(t){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},n=vn.reduce((r,o)=>(r[o]="function",r),e);return et(t,n)}function An(t,e,n){if(n<T)throw new Error("Expected power > 0");if(n===T)return t.ONE;if(n===L)return e;let r=t.ONE,o=e;for(;n>T;)n&L&&(r=t.mul(r,o)),o=t.sqr(o),n>>=L;return r}function In(t,e){let n=new Array(e.length),r=e.reduce((f,a,i)=>t.is0(a)?f:(n[i]=f,t.mul(f,a)),t.ONE),o=t.inv(r);return e.reduceRight((f,a,i)=>t.is0(a)?f:(n[i]=t.mul(f,n[i]),t.mul(f,a)),o),n}function Pt(t,e){let n=e!==void 0?e:t.toString(2).length,r=Math.ceil(n/8);return {nBitLength:n,nByteLength:r}}function xe(t,e,n=!1,r={}){if(t<=T)throw new Error(`Expected Fp ORDER > 0, got ${t}`);let{nBitLength:o,nByteLength:f}=Pt(t,e);if(f>2048)throw new Error("Field lengths over 2048 bytes are not supported");let a=Sn(t),i=Object.freeze({ORDER:t,BITS:o,BYTES:f,MASK:ae(o),ZERO:T,ONE:L,create:s=>A(s,t),isValid:s=>{if(typeof s!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof s}`);return T<=s&&s<t},is0:s=>s===T,isOdd:s=>(s&L)===L,neg:s=>A(-s,t),eql:(s,l)=>s===l,sqr:s=>A(s*s,t),add:(s,l)=>A(s+l,t),sub:(s,l)=>A(s-l,t),mul:(s,l)=>A(s*l,t),pow:(s,l)=>An(i,s,l),div:(s,l)=>A(s*de(l,t),t),sqrN:s=>s*s,addN:(s,l)=>s+l,subN:(s,l)=>s-l,mulN:(s,l)=>s*l,inv:s=>de(s,t),sqrt:r.sqrt||(s=>a(i,s)),invertBatch:s=>In(i,s),cmov:(s,l,c)=>c?l:s,toBytes:s=>n?ot(s,f):qt(s,f),fromBytes:s=>{if(s.length!==f)throw new Error(`Fp.fromBytes: expected ${f}, got ${s.length}`);return n?tt(s):Ht(s)}});return Object.freeze(i)}function be(t,e){if(!t.isOdd)throw new Error("Field doesn't have isOdd");let n=t.sqrt(e);return t.isOdd(n)?t.neg(n):n}var Ln=BigInt(0),Mt=BigInt(1);function ge(t,e){let n=(o,f)=>{let a=f.negate();return o?a:f},r=o=>{let f=Math.ceil(e/o)+1,a=2**(o-1);return {windows:f,windowSize:a}};return {constTimeNegate:n,unsafeLadder(o,f){let a=t.ZERO,i=o;for(;f>Ln;)f&Mt&&(a=a.add(i)),i=i.double(),f>>=Mt;return a},precomputeWindow(o,f){let{windows:a,windowSize:i}=r(f),s=[],l=o,c=l;for(let d=0;d<a;d++){c=l,s.push(c);for(let b=1;b<i;b++)c=c.add(l),s.push(c);l=c.double();}return s},wNAF(o,f,a){let{windows:i,windowSize:s}=r(o),l=t.ZERO,c=t.BASE,d=BigInt(2**o-1),b=2**o,N=BigInt(o);for(let O=0;O<i;O++){let C=O*s,S=Number(a&d);a>>=N,S>s&&(S-=b,a+=Mt);let M=C,$=C+Math.abs(S)-1,m=O%2!==0,q=S<0;S===0?c=c.add(n(m,f[M])):l=l.add(n(q,f[$]));}return {p:l,f:c}},wNAFCached(o,f,a,i){let s=o._WINDOW_SIZE||1,l=f.get(o);return l||(l=this.precomputeWindow(o,s),s!==1&&f.set(o,i(l))),this.wNAF(s,l,a)}}}function we(t){return ye(t.Fp),et(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Pt(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}var G=BigInt(0),P=BigInt(1),_t=BigInt(2),On=BigInt(8),Nn={zip215:!0};function Cn(t){let e=we(t);return et(t,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function St(t){let e=Cn(t),{Fp:n,n:r,prehash:o,hash:f,randomBytes:a,nByteLength:i,h:s}=e,l=_t<<BigInt(i*8)-P,c=n.create,d=e.uvRatio||((h,u)=>{try{return {isValid:!0,value:n.sqrt(h*n.inv(u))}}catch{return {isValid:!1,value:G}}}),b=e.adjustScalarBytes||(h=>h),N=e.domain||((h,u,p)=>{if(u.length||p)throw new Error("Contexts/pre-hash are not supported");return h}),O=h=>typeof h=="bigint"&&G<h,C=(h,u)=>O(h)&&O(u)&&h<u,S=h=>h===G||C(h,l);function M(h,u){if(C(h,u))return h;throw new Error(`Expected valid scalar < ${u}, got ${typeof h} ${h}`)}function $(h){return h===G?h:M(h,r)}let m=new Map;function q(h){if(!(h instanceof g))throw new Error("ExtendedPoint expected")}class g{constructor(u,p,x,w){if(this.ex=u,this.ey=p,this.ez=x,this.et=w,!S(u))throw new Error("x required");if(!S(p))throw new Error("y required");if(!S(x))throw new Error("z required");if(!S(w))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(u){if(u instanceof g)throw new Error("extended point not allowed");let{x:p,y:x}=u||{};if(!S(p)||!S(x))throw new Error("invalid affine point");return new g(p,x,P,c(p*x))}static normalizeZ(u){let p=n.invertBatch(u.map(x=>x.ez));return u.map((x,w)=>x.toAffine(p[w])).map(g.fromAffine)}_setWindowSize(u){this._WINDOW_SIZE=u,m.delete(this);}assertValidity(){let{a:u,d:p}=e;if(this.is0())throw new Error("bad point: ZERO");let{ex:x,ey:w,ez:E,et:_}=this,I=c(x*x),B=c(w*w),v=c(E*E),U=c(v*v),K=c(I*u),j=c(v*c(K+B)),R=c(U+c(p*c(I*B)));if(j!==R)throw new Error("bad point: equation left != right (1)");let X=c(x*w),F=c(E*_);if(X!==F)throw new Error("bad point: equation left != right (2)")}equals(u){q(u);let{ex:p,ey:x,ez:w}=this,{ex:E,ey:_,ez:I}=u,B=c(p*I),v=c(E*w),U=c(x*I),K=c(_*w);return B===v&&U===K}is0(){return this.equals(g.ZERO)}negate(){return new g(c(-this.ex),this.ey,this.ez,c(-this.et))}double(){let{a:u}=e,{ex:p,ey:x,ez:w}=this,E=c(p*p),_=c(x*x),I=c(_t*c(w*w)),B=c(u*E),v=p+x,U=c(c(v*v)-E-_),K=B+_,j=K-I,R=B-_,X=c(U*j),F=c(K*R),ht=c(U*R),pt=c(j*K);return new g(X,F,pt,ht)}add(u){q(u);let{a:p,d:x}=e,{ex:w,ey:E,ez:_,et:I}=this,{ex:B,ey:v,ez:U,et:K}=u;if(p===BigInt(-1)){let Yt=c((E-w)*(v+B)),Wt=c((E+w)*(v-B)),It=c(Wt-Yt);if(It===G)return this.double();let Xt=c(_*_t*K),Qt=c(I*_t*U),Jt=Qt+Xt,te=Wt+Yt,ee=Qt-Xt,Ue=c(Jt*It),Ke=c(te*ee),Re=c(Jt*ee),He=c(It*te);return new g(Ue,Ke,He,Re)}let j=c(w*B),R=c(E*v),X=c(I*x*K),F=c(_*U),ht=c((w+E)*(B+v)-j-R),pt=F-X,zt=F+X,Ft=c(R-p*j),Oe=c(ht*pt),Ne=c(zt*Ft),Ce=c(ht*Ft),Te=c(pt*zt);return new g(Oe,Ne,Te,Ce)}subtract(u){return this.add(u.negate())}wNAF(u){return D.wNAFCached(this,m,u,g.normalizeZ)}multiply(u){let{p,f:x}=this.wNAF(M(u,r));return g.normalizeZ([p,x])[0]}multiplyUnsafe(u){let p=$(u);return p===G?it:this.equals(it)||p===P?this:this.equals(z)?this.wNAF(p).p:D.unsafeLadder(this,p)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}isTorsionFree(){return D.unsafeLadder(this,r).is0()}toAffine(u){let{ex:p,ey:x,ez:w}=this,E=this.is0();u==null&&(u=E?On:n.inv(w));let _=c(p*u),I=c(x*u),B=c(w*u);if(E)return {x:G,y:P};if(B!==P)throw new Error("invZ was invalid");return {x:_,y:I}}clearCofactor(){let{h:u}=e;return u===P?this:this.multiplyUnsafe(u)}static fromHex(u,p=!1){let{d:x,a:w}=e,E=n.BYTES;u=V("pointHex",u,E);let _=u.slice(),I=u[E-1];_[E-1]=I&-129;let B=tt(_);B===G||(p?M(B,l):M(B,n.ORDER));let v=c(B*B),U=c(v-P),K=c(x*v-w),{isValid:j,value:R}=d(U,K);if(!j)throw new Error("Point.fromHex: invalid y coordinate");let X=(R&P)===P,F=(I&128)!==0;if(!p&&R===G&&F)throw new Error("Point.fromHex: x=0 and x_0=1");return F!==X&&(R=c(-R)),g.fromAffine({x:R,y:B})}static fromPrivateKey(u){return W(u).point}toRawBytes(){let{x:u,y:p}=this.toAffine(),x=ot(p,n.BYTES);return x[x.length-1]|=u&P?128:0,x}toHex(){return ut(this.toRawBytes())}}g.BASE=new g(e.Gx,e.Gy,P,c(e.Gx*e.Gy)),g.ZERO=new g(G,P,P,G);let{BASE:z,ZERO:it}=g,D=ge(g,i*8);function k(h){return A(h,r)}function nt(h){return k(tt(h))}function W(h){let u=i;h=V("private key",h,u);let p=V("hashed private key",f(h),2*u),x=b(p.slice(0,u)),w=p.slice(u,2*u),E=nt(x),_=z.multiply(E),I=_.toRawBytes();return {head:x,prefix:w,scalar:E,point:_,pointBytes:I}}function ct(h){return W(h).pointBytes}function rt(h=new Uint8Array,...u){let p=Bt(...u);return nt(f(N(p,V("context",h),!!o)))}function At(h,u,p={}){h=V("message",h),o&&(h=o(h));let{prefix:x,scalar:w,pointBytes:E}=W(u),_=rt(p.context,x,h),I=z.multiply(_).toRawBytes(),B=rt(p.context,I,E,h),v=k(_+B*w);$(v);let U=Bt(I,ot(v,n.BYTES));return V("result",U,i*2)}let dt=Nn;function Le(h,u,p,x=dt){let{context:w,zip215:E}=x,_=n.BYTES;h=V("signature",h,2*_),u=V("message",u),o&&(u=o(u));let I=tt(h.slice(_,2*_)),B,v,U;try{B=g.fromHex(p,E),v=g.fromHex(h.slice(0,_),E),U=z.multiplyUnsafe(I);}catch{return !1}if(!E&&B.isSmallOrder())return !1;let K=rt(w,v.toRawBytes(),B.toRawBytes(),u);return v.add(B.multiplyUnsafe(K)).subtract(U).clearCofactor().equals(g.ZERO)}return z._setWindowSize(8),{CURVE:e,getPublicKey:ct,sign:At,verify:Le,ExtendedPoint:g,utils:{getExtendedPublicKey:W,randomPrivateKey:()=>a(n.BYTES),precompute(h=8,u=g.BASE){return u._setWindowSize(h),u.multiply(BigInt(3)),u}}}}BigInt(0);BigInt(1);var Vt=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),me=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");BigInt(0);var Tn=BigInt(1),kt=BigInt(2),Un=BigInt(5),Ee=BigInt(10),Kn=BigInt(20),Rn=BigInt(40),Be=BigInt(80);function Hn(t){let e=Vt,r=t*t%e*t%e,o=Z(r,kt,e)*r%e,f=Z(o,Tn,e)*t%e,a=Z(f,Un,e)*f%e,i=Z(a,Ee,e)*a%e,s=Z(i,Kn,e)*i%e,l=Z(s,Rn,e)*s%e,c=Z(l,Be,e)*l%e,d=Z(c,Be,e)*l%e,b=Z(d,Ee,e)*a%e;return {pow_p_5_8:Z(b,kt,e)*t%e,b2:r}}function qn(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}function Dn(t,e){let n=Vt,r=A(e*e*e,n),o=A(r*r*e,n),f=Hn(t*o).pow_p_5_8,a=A(t*r*f,n),i=A(e*a*a,n),s=a,l=A(a*me,n),c=i===t,d=i===A(-t,n),b=i===A(-t*me,n);return c&&(a=s),(d||b)&&(a=l),pe(a,n)&&(a=A(-a,n)),{isValid:c||d,value:a}}var Y=xe(Vt,void 0,!0),Zt={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Y,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Rt,randomBytes:se,adjustScalarBytes:qn,uvRatio:Dn},at=St(Zt);function _e(t,e,n){if(e.length>255)throw new Error("Context is too big");return oe(Ot("SigEd25519 no Ed25519 collisions"),new Uint8Array([n?1:0,e.length]),e,t)}St({...Zt,domain:_e});St({...Zt,domain:_e,prehash:Rt});var Pn=(Y.ORDER+BigInt(3))/BigInt(8);Y.pow(kt,Pn);Y.sqrt(Y.neg(Y.ONE));(Y.ORDER-BigInt(5))/BigInt(8);BigInt(486662);be(Y,Y.neg(BigInt(486664)));BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235");BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578");BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838");BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var Mn=new Set(["decrypt","deriveBits","deriveKey","encrypt","unwrapKey","wrapKey"]);function Gt(t){return t instanceof Uint8Array?t:new Uint8Array(ArrayBuffer.isView(t)?t.buffer:t)}var $t;function kn(t,e,n){let r=Vn(e,n),o=$t||($t=new WeakMap);return o.set(r.privateKey,t),o.set(r.publicKey,t),r}function Vn(t,e){if(e.length===0)throw new DOMException("Usages cannot be empty when creating a key.","SyntaxError");if(e.some(f=>Mn.has(f)))throw new DOMException("Unsupported key usage for an Ed25519 key.","SyntaxError");let n={[Symbol.toStringTag]:"CryptoKey",algorithm:Object.freeze({name:"Ed25519"})},r={...n,extractable:t,type:"private",usages:Object.freeze(e.filter(f=>f==="sign"))},o={...n,extractable:!0,type:"public",usages:Object.freeze(e.filter(f=>f==="verify"))};return Object.freeze({privateKey:Object.freeze(r),publicKey:Object.freeze(o)})}function jt(t){let e=$t?.get(t);if(e===void 0)throw new Error("Could not find secret key material associated with this `CryptoKey`");return e}function Se(t,e){switch(t){case"raw":{if(e.extractable===!1)throw new DOMException("key is not extractable","InvalidAccessException");if(e.type!=="public")throw new DOMException(`Unable to export a raw Ed25519 ${e.type} key`,"InvalidAccessError");return at.getPublicKey(jt(e))}default:throw new Error(`Exporting polyfilled Ed25519 keys in the "${t}" format is unimplemented`)}}function ve(t,e){let n=at.utils.randomPrivateKey();return kn(n,t,e)}function vt(t){return !!$t?.has(t)}function Ae(t,e){if(t.type!=="private"||!t.usages.includes("sign"))throw new DOMException("Unable to use this key to sign","InvalidAccessError");let n=jt(t),r=Gt(e);return at.sign(r,n)}function Ie(t,e,n){if(t.type!=="public"||!t.usages.includes("verify"))throw new DOMException("Unable to use this key to verify","InvalidAccessError");let r=at.getPublicKey(jt(t));try{return at.verify(Gt(e),Gt(n),r)}catch{return !1}}if(globalThis.isSecureContext){let t=globalThis.crypto||(globalThis.crypto={}),e=t.subtle||(t.subtle={}),n=e.exportKey;e.exportKey=async(...i)=>{let[s,l]=i;if(vt(l))return Se(...i);if(n)return await n.apply(e,i);throw new TypeError("No native `exportKey` function exists to handle this call")};let r=e.generateKey,o;e.generateKey=async(...i)=>{let[s]=i;if(s!=="Ed25519"){if(r)return await r.apply(e,i);throw new TypeError("No native `generateKey` function exists to handle this call")}let l;if(o===void 0&&(o=new Promise(c=>{if(!r){c(o=!1);return}r.apply(e,i).then(d=>{e.generateKey!==r&&(e.generateKey=r),l=d,c(o=!0);}).catch(()=>{c(o=!1);});})),typeof o=="boolean"?o:await o){if(l)return l;if(r)return await r.apply(e,i);throw new TypeError("No native `generateKey` function exists to handle this call")}else {let[c,d,b]=i;return ve(d,b)}};let f=e.sign;e.sign=async(...i)=>{let[s,l]=i;if(vt(l)){let[c,...d]=i;return Ae(...d)}else {if(f)return await f.apply(e,i);throw new TypeError("No native `sign` function exists to handle this call")}};let a=e.verify;e.verify=async(...i)=>{let[s,l]=i;if(vt(l)){let[c,...d]=i;return Ie(...d)}else {if(a)return await a.apply(e,i);throw new TypeError("No native `verify` function exists to handle this call")}};}
4
+ var h=2n**255n-19n,C=2n**252n+27742317777372353535851937790883648493n,j=0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51an,N=0x6666666666666666666666666666666666666666666666666666666666666658n,O={a:-1n,d:37095705934669439343138083508754565189542113879843219016388785533085940283555n,p:h,n:C,h:8,Gx:j,Gy:N},b=(t="")=>{throw new Error(t)},te=t=>typeof t=="string",z=(t,e)=>!(t instanceof Uint8Array)||typeof e=="number"&&e>0&&t.length!==e?b("Uint8Array expected"):t,A=t=>new Uint8Array(t),B=(t,e)=>z(te(t)?H(t):A(t),e),i=(t,e=h)=>{let n=t%e;return n>=0n?n:e+n},$=t=>t instanceof x?t:b("Point expected"),J,x=class t{constructor(e,n,o,r){this.ex=e,this.ey=n,this.ez=o,this.et=r;}static fromAffine(e){return new t(e.x,e.y,1n,i(e.x*e.y))}static fromHex(e,n=!0){let{d:o}=O;e=B(e,32);let r=e.slice();r[31]=e[31]&-129;let s=F(r);s===0n||(n&&!(0n<s&&s<h)&&b("bad y coord 1"),!n&&!(0n<s&&s<2n**256n)&&b("bad y coord 2"));let c=i(s*s),y=i(c-1n),p=i(o*c+1n),{isValid:a,value:l}=Se(y,p);a||b("bad y coordinate 3");let f=(l&1n)===1n;return (e[31]&128)!==0!==f&&(l=i(-l)),new t(l,s,1n,i(l*s))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}equals(e){let{ex:n,ey:o,ez:r}=this,{ex:s,ey:c,ez:y}=$(e),p=i(n*y),a=i(s*r),l=i(o*y),f=i(c*r);return p===a&&l===f}is0(){return this.equals(R)}negate(){return new t(i(-this.ex),this.ey,this.ez,i(-this.et))}double(){let{ex:e,ey:n,ez:o}=this,{a:r}=O,s=i(e*e),c=i(n*n),y=i(2n*i(o*o)),p=i(r*s),a=e+n,l=i(i(a*a)-s-c),f=p+c,u=f-y,d=p-c,w=i(l*u),K=i(f*d),v=i(l*d),P=i(u*f);return new t(w,K,P,v)}add(e){let{ex:n,ey:o,ez:r,et:s}=this,{ex:c,ey:y,ez:p,et:a}=$(e),{a:l,d:f}=O,u=i(n*c),d=i(o*y),w=i(s*f*a),K=i(r*p),v=i((n+o)*(c+y)-u-d),P=i(K-w),D=i(K+w),q=i(d-l*u),xe=i(v*P),Ke=i(D*q),ge=i(v*q),Ee=i(P*D);return new t(xe,Ke,Ee,ge)}mul(e,n=!0){if(e===0n)return n===!0?b("cannot multiply by 0"):R;if(typeof e=="bigint"&&0n<e&&e<C||b("invalid scalar, must be < L"),!n&&this.is0()||e===1n)return this;if(this.equals(g))return _e(e).p;let o=R,r=g;for(let s=this;e>0n;s=s.double(),e>>=1n)e&1n?o=o.add(s):n&&(r=r.add(s));return o}multiply(e){return this.mul(e)}clearCofactor(){return this.mul(BigInt(O.h),!1)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){let e=this.mul(C/2n,!1).double();return C%2n&&(e=e.add(this)),e.is0()}toAffine(){let{ex:e,ey:n,ez:o}=this;if(this.is0())return {x:0n,y:0n};let r=re(o);return i(o*r)!==1n&&b("invalid inverse"),{x:i(e*r),y:i(n*r)}}toRawBytes(){let{x:e,y:n}=this.toAffine(),o=oe(n);return o[31]|=e&1n?128:0,o}toHex(){return Z(this.toRawBytes())}};x.BASE=new x(j,N,1n,i(j*N));x.ZERO=new x(0n,1n,1n,0n);var{BASE:g,ZERO:R}=x,ne=(t,e)=>t.toString(16).padStart(e,"0"),Z=t=>Array.from(t).map(e=>ne(e,2)).join(""),H=t=>{let e=t.length;(!te(t)||e%2)&&b("hex invalid 1");let n=A(e/2);for(let o=0;o<n.length;o++){let r=o*2,s=t.slice(r,r+2),c=Number.parseInt(s,16);(Number.isNaN(c)||c<0)&&b("hex invalid 2"),n[o]=c;}return n},oe=t=>H(ne(t,32*2)).reverse(),F=t=>BigInt("0x"+Z(A(z(t)).reverse())),k=(...t)=>{let e=A(t.reduce((o,r)=>o+z(r).length,0)),n=0;return t.forEach(o=>{e.set(o,n),n+=o.length;}),e},re=(t,e=h)=>{(t===0n||e<=0n)&&b("no inverse n="+t+" mod="+e);let n=i(t,e),o=e,r=0n,c=1n;for(;n!==0n;){let p=o/n,a=o%n,l=r-c*p;o=n,n=a,r=c,c=l;}return o===1n?i(r,e):b("no inverse")},m=(t,e)=>{let n=t;for(;e-- >0n;)n*=n,n%=h;return n},ve=t=>{let n=t*t%h*t%h,o=m(n,2n)*n%h,r=m(o,1n)*t%h,s=m(r,5n)*r%h,c=m(s,10n)*s%h,y=m(c,20n)*c%h,p=m(y,40n)*y%h,a=m(p,80n)*p%h,l=m(a,80n)*p%h,f=m(l,10n)*s%h;return {pow_p_5_8:m(f,2n)*t%h,b2:n}},L=19681161376707505956807079304988542015446066515923890162744021073123829784752n,Se=(t,e)=>{let n=i(e*e*e),o=i(n*n*e),r=ve(t*o).pow_p_5_8,s=i(t*n*r),c=i(e*s*s),y=s,p=i(s*L),a=c===t,l=c===i(-t),f=c===i(-t*L);return a&&(s=y),(l||f)&&(s=p),(i(s)&1n)===1n&&(s=i(-s)),{isValid:a||l,value:s}},T=t=>i(F(t),C),_,V=(...t)=>W.sha512Async(...t),se=(...t)=>typeof _=="function"?_(...t):b("etc.sha512Sync not set"),ie=t=>{let e=t.slice(0,32);e[0]&=248,e[31]&=127,e[31]|=64;let n=t.slice(32,64),o=T(e),r=g.mul(o),s=r.toRawBytes();return {head:e,prefix:n,scalar:o,point:r,pointBytes:s}},G=t=>V(B(t,32)).then(ie),Pe=t=>ie(se(B(t,32))),ae=t=>G(t).then(e=>e.pointBytes);function ce(t,e){return t?V(e.hashable).then(e.finish):e.finish(se(e.hashable))}var Ce=(t,e,n)=>{let{pointBytes:o,scalar:r}=t,s=T(e),c=g.mul(s).toRawBytes();return {hashable:k(c,o,n),finish:a=>{let l=i(s+T(a)*r,C);return z(k(c,oe(l)),64)}}},ye=async(t,e)=>{let n=B(t),o=await G(e),r=await V(o.prefix,n);return ce(!0,Ce(o,r,n))};var Ae=(t,e,n)=>{e=B(e),t=B(t,64);let o=x.fromHex(n,!1),r=x.fromHex(t.slice(0,32),!1),s=F(t.slice(32,64)),c=g.mul(s,!1);return {hashable:k(r.toRawBytes(),o.toRawBytes(),e),finish:a=>{let l=T(a);return r.add(o.mul(l,!1)).add(c.negate()).clearCofactor().is0()}}},le=async(t,e,n)=>ce(!0,Ae(t,e,n));var Q=()=>typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0,W={bytesToHex:Z,hexToBytes:H,concatBytes:k,mod:i,invert:re,randomBytes:t=>{let e=Q();return e||b("crypto.getRandomValues must be defined"),e.getRandomValues(A(t))},sha512Async:async(...t)=>{let e=Q();e||b("crypto.subtle or etc.sha512Async must be defined");let n=k(...t);return A(await e.subtle.digest("SHA-512",n.buffer))},sha512Sync:void 0};Object.defineProperties(W,{sha512Sync:{configurable:!1,get(){return _},set(t){_||(_=t);}}});var fe={getExtendedPublicKeyAsync:G,getExtendedPublicKey:Pe,randomPrivateKey:()=>W.randomBytes(32),precompute(t=8,e=g){return e.multiply(3n),e}},S=8,Be=()=>{let t=[],e=256/S+1,n=g,o=n;for(let r=0;r<e;r++){o=n,t.push(o);for(let s=1;s<2**(S-1);s++)o=o.add(n),t.push(o);n=o.double();}return t},_e=t=>{let e=J||(J=Be()),n=(l,f)=>{let u=f.negate();return l?u:f},o=R,r=g,s=1+256/S,c=2**(S-1),y=BigInt(2**S-1),p=2**S,a=BigInt(S);for(let l=0;l<s;l++){let f=l*c,u=Number(t&y);t>>=a,u>c&&(u-=p,t+=1n);let d=f,w=f+Math.abs(u)-1,K=l%2!==0,v=u<0;u===0?r=r.add(n(K,e[d])):o=o.add(n(v,e[w]));}return {p:o,f:r}};var X=new Set(["decrypt","deriveBits","deriveKey","encrypt","unwrapKey","wrapKey"]),pe=[48,46,2,1,0,48,5,6,3,43,101,112,4,34,4,32];function I(t){return t instanceof Uint8Array?t:new Uint8Array(ArrayBuffer.isView(t)?t.buffer:t)}var E,U;function ke(t,e,n){let o=Ue(e,n),r=E||(E=new WeakMap);return r.set(o.privateKey,t),r.set(o.publicKey,t),o}function Ue(t,e){if(e.length===0)throw new DOMException("Usages cannot be empty when creating a key.","SyntaxError");if(e.some(s=>X.has(s)))throw new DOMException("Unsupported key usage for an Ed25519 key.","SyntaxError");let n={[Symbol.toStringTag]:"CryptoKey",algorithm:Object.freeze({name:"Ed25519"})},o={...n,extractable:t,type:"private",usages:Object.freeze(e.filter(s=>s==="sign"))},r={...n,extractable:!0,type:"public",usages:Object.freeze(e.filter(s=>s==="verify"))};return Object.freeze({privateKey:Object.freeze(o),publicKey:Object.freeze(r)})}function Y(t){let e=E==null?void 0:E.get(t);if(e===void 0)throw new Error("Could not find secret key material associated with this `CryptoKey`");return e}async function ue(t){let e=U||(U=new WeakMap),n=e.get(t);if(n)return n;let o=await ae(Y(t));return e.set(t,o),o}async function de(t,e){if(e.extractable===!1)throw new DOMException("key is not extractable","InvalidAccessException");switch(t){case"raw":{if(e.type!=="public")throw new DOMException(`Unable to export a raw Ed25519 ${e.type} key`,"InvalidAccessError");return await ue(e)}case"pkcs8":{if(e.type!=="private")throw new DOMException(`Unable to export a pkcs8 Ed25519 ${e.type} key`,"InvalidAccessError");let n=Y(e);return new Uint8Array([...pe,...n])}default:throw new Error(`Exporting polyfilled Ed25519 keys in the "${t}" format is unimplemented`)}}function he(t,e){let n=fe.randomPrivateKey();return ke(n,t,e)}function M(t){return !!(E!=null&&E.has(t))||!!(U!=null&&U.has(t))}async function be(t,e){if(t.type!=="private"||!t.usages.includes("sign"))throw new DOMException("Unable to use this key to sign","InvalidAccessError");let n=Y(t),o=I(e);return await ye(o,n)}async function we(t,e,n){if(t.type!=="public"||!t.usages.includes("verify"))throw new DOMException("Unable to use this key to verify","InvalidAccessError");let o=await ue(t);try{return await le(I(e),I(n),o)}catch{return !1}}function me(t,e,n,o){let r=I(e);if(t==="raw"){if(o.some(y=>y==="sign"||X.has(y)))throw new DOMException("Unsupported key usage for a Ed25519 key","SyntaxError");if(r.length!==32)throw new DOMException("Ed25519 raw keys must be exactly 32-bytes","DataError");let s={[Symbol.toStringTag]:"CryptoKey",algorithm:Object.freeze({name:"Ed25519"}),extractable:n,type:"public",usages:Object.freeze(o.filter(y=>y==="verify"))};return (U||(U=new WeakMap)).set(s,r),s}if(t==="pkcs8"){if(o.some(a=>a==="verify"||X.has(a)))throw new DOMException("Unsupported key usage for a Ed25519 key","SyntaxError");if(r.length!==48)throw new DOMException("Invalid keyData","DataError");if(!r.slice(0,16).every((a,l)=>a===pe[l]))throw new DOMException("Invalid keyData","DataError");let c=r.slice(16),y={[Symbol.toStringTag]:"CryptoKey",algorithm:Object.freeze({name:"Ed25519"}),extractable:n,type:"private",usages:Object.freeze(o.filter(a=>a==="sign"))};return (E||(E=new WeakMap)).set(y,c),y}throw new Error(`Importing Ed25519 keys in the "${t}" format is unimplemented`)}if(globalThis.isSecureContext){let t=globalThis.crypto||(globalThis.crypto={}),e=t.subtle||(t.subtle={}),n=e.exportKey;e.exportKey=async(...a)=>{let[l,f]=a;if(M(f))return await de(...a);if(n)return await n.apply(e,a);throw new TypeError("No native `exportKey` function exists to handle this call")};let o=e.generateKey,r;e.generateKey=async(...a)=>{let[l]=a;if(l!=="Ed25519"){if(o)return await o.apply(e,a);throw new TypeError("No native `generateKey` function exists to handle this call")}let f;if(r===void 0&&(r=new Promise(u=>{if(!o){u(r=!1);return}o.apply(e,a).then(d=>{e.generateKey!==o&&(e.generateKey=o),f=d,u(r=!0);}).catch(()=>{u(r=!1);});})),typeof r=="boolean"?r:await r){if(f)return f;if(o)return await o.apply(e,a);throw new TypeError("No native `generateKey` function exists to handle this call")}else {let[u,d,w]=a;return he(d,w)}};let s=e.sign;e.sign=async(...a)=>{let[l,f]=a;if(M(f)){let[u,...d]=a;return await be(...d)}else {if(s)return await s.apply(e,a);throw new TypeError("No native `sign` function exists to handle this call")}};let c=e.verify;e.verify=async(...a)=>{let[l,f]=a;if(M(f)){let[u,...d]=a;return await we(...d)}else {if(c)return await c.apply(e,a);throw new TypeError("No native `verify` function exists to handle this call")}};let y=e.importKey,p;e.importKey=async(...a)=>{let[l,f,u]=a;if(u!=="Ed25519"){if(y)return await y.apply(e,a);throw new TypeError("No native `importKey` function exists to handle this call")}let d;if(p===void 0&&(p=new Promise(w=>{if(!y){w(p=!1);return}y.apply(e,a).then(K=>{e.importKey!==y&&(e.importKey=y),d=K,w(p=!0);}).catch(()=>{w(p=!1);});})),typeof y=="boolean"?p:await p){if(d)return d;if(y)return await y.apply(e,a);throw new TypeError("No native `importKey` function exists to handle this call")}else {let[w,K,v,P,D]=a;return me(l,f,P,D)}};}
5
5
  /*! Bundled license information:
6
6
 
7
- @noble/hashes/esm/utils.js:
8
- (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
9
-
10
- @noble/curves/esm/abstract/utils.js:
11
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
12
-
13
- @noble/curves/esm/abstract/modular.js:
14
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
15
-
16
- @noble/curves/esm/abstract/curve.js:
17
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
18
-
19
- @noble/curves/esm/abstract/edwards.js:
20
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
21
-
22
- @noble/curves/esm/abstract/montgomery.js:
23
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
24
-
25
- @noble/curves/esm/ed25519.js:
26
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
7
+ @noble/ed25519/index.js:
8
+ (*! noble-ed25519 - MIT License (c) 2019 Paul Miller (paulmillr.com) *)
27
9
  */
28
10
 
29
11
  })();
@@ -1,5 +1,5 @@
1
- export declare function exportKeyPolyfill(format: 'jwk', key: CryptoKey): JsonWebKey;
2
- export declare function exportKeyPolyfill(format: KeyFormat, key: CryptoKey): ArrayBuffer;
1
+ export declare function exportKeyPolyfill(format: 'jwk', key: CryptoKey): Promise<JsonWebKey>;
2
+ export declare function exportKeyPolyfill(format: KeyFormat, key: CryptoKey): Promise<ArrayBuffer>;
3
3
  /**
4
4
  * This function generates a key pair and stores the secret bytes associated with it in a
5
5
  * module-private cache. Instead of vending the actual secret bytes, it returns a `CryptoKeyPair`
@@ -8,6 +8,7 @@ export declare function exportKeyPolyfill(format: KeyFormat, key: CryptoKey): Ar
8
8
  */
9
9
  export declare function generateKeyPolyfill(extractable: boolean, keyUsages: readonly KeyUsage[]): CryptoKeyPair;
10
10
  export declare function isPolyfilledKey(key: CryptoKey): boolean;
11
- export declare function signPolyfill(key: CryptoKey, data: BufferSource): ArrayBuffer;
12
- export declare function verifyPolyfill(key: CryptoKey, signature: BufferSource, data: BufferSource): boolean;
11
+ export declare function signPolyfill(key: CryptoKey, data: BufferSource): Promise<ArrayBuffer>;
12
+ export declare function verifyPolyfill(key: CryptoKey, signature: BufferSource, data: BufferSource): Promise<boolean>;
13
+ export declare function importKeyPolyfill(format: KeyFormat, keyData: BufferSource, extractable: boolean, keyUsages: readonly KeyUsage[]): CryptoKey;
13
14
  //# sourceMappingURL=secrets.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"secrets.d.ts","sourceRoot":"","sources":["../../src/secrets.ts"],"names":[],"mappings":"AAoFA,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,SAAS,GAAG,UAAU,CAAC;AAC7E,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,GAAG,WAAW,CAAC;AAkBlF;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,QAAQ,EAAE,GAAG,aAAa,CAIvG;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,SAAS,GAAG,OAAO,CAEvD;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,YAAY,GAAG,WAAW,CAQ5E;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,IAAI,EAAE,YAAY,GAAG,OAAO,CAUnG"}
1
+ {"version":3,"file":"secrets.d.ts","sourceRoot":"","sources":["../../src/secrets.ts"],"names":[],"mappings":"AAwIA,wBAAsB,iBAAiB,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAC5F,wBAAsB,iBAAiB,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;AAyBjG;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,QAAQ,EAAE,GAAG,aAAa,CAIvG;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,SAAS,GAAG,OAAO,CAEvD;AAED,wBAAsB,YAAY,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC,CAQ3F;AAED,wBAAsB,cAAc,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,CAUlH;AAED,wBAAgB,iBAAiB,CAC7B,MAAM,EAAE,SAAS,EACjB,OAAO,EAAE,YAAY,EACrB,WAAW,EAAE,OAAO,EACpB,SAAS,EAAE,SAAS,QAAQ,EAAE,GAC/B,SAAS,CAsDX"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solana/webcrypto-ed25519-polyfill",
3
- "version": "2.0.0-experimental.fcae73c",
3
+ "version": "2.0.0-experimental.fcff844",
4
4
  "description": "A polyfill that adds Ed25519 key manipulation capabilities to `SubtleCrypto` in environments where it is not yet supported",
5
5
  "exports": {
6
6
  "browser": {
@@ -49,24 +49,25 @@
49
49
  "node": ">=17.4"
50
50
  },
51
51
  "dependencies": {
52
- "@noble/curves": "^1.1.0"
52
+ "@noble/ed25519": "^2.0.0",
53
+ "crypto-impl": "0.0.0"
53
54
  },
54
55
  "devDependencies": {
55
56
  "@solana/eslint-config-solana": "^1.0.2",
56
- "@swc/jest": "^0.2.27",
57
- "@types/jest": "^29.5.3",
58
- "@typescript-eslint/eslint-plugin": "^6.0.0",
59
- "@typescript-eslint/parser": "^6.0.0",
57
+ "@swc/jest": "^0.2.29",
58
+ "@types/jest": "^29.5.6",
59
+ "@typescript-eslint/eslint-plugin": "^6.7.0",
60
+ "@typescript-eslint/parser": "^6.3.0",
60
61
  "eslint": "^8.45.0",
61
- "eslint-plugin-jest": "^27.2.3",
62
+ "eslint-plugin-jest": "^27.4.2",
62
63
  "eslint-plugin-sort-keys-fix": "^1.1.2",
63
- "jest": "^29.6.1",
64
- "jest-environment-jsdom": "^29.6.0",
65
- "jest-runner-eslint": "^2.1.0",
64
+ "jest": "^29.7.0",
65
+ "jest-environment-jsdom": "^29.7.0",
66
+ "jest-runner-eslint": "^2.1.2",
66
67
  "jest-runner-prettier": "^1.0.0",
67
- "prettier": "^2.8.8",
68
- "tsup": "6.7.0",
69
- "typescript": "^5.1.6",
68
+ "prettier": "^3.1",
69
+ "tsup": "^8.0.1",
70
+ "typescript": "^5.2.2",
70
71
  "version-from-git": "^1.1.1",
71
72
  "build-scripts": "0.0.0",
72
73
  "test-config": "0.0.0",
@@ -85,6 +86,7 @@
85
86
  "compile:typedefs": "tsc -p ./tsconfig.declarations.json",
86
87
  "dev": "jest -c node_modules/test-config/jest-dev.config.ts --rootDir . --watch",
87
88
  "publish-packages": "pnpm publish --tag experimental --access public --no-git-checks",
89
+ "style:fix": "pnpm eslint --fix src/* && pnpm prettier -w src/* package.json",
88
90
  "test:lint": "jest -c node_modules/test-config/jest-lint.config.ts --rootDir . --silent",
89
91
  "test:prettier": "jest -c node_modules/test-config/jest-prettier.config.ts --rootDir . --silent",
90
92
  "test:typecheck": "tsc --noEmit",