@solana/webcrypto-ed25519-polyfill 2.0.0-experimental.c8d8b83 → 2.0.0-experimental.c9bd7fa
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/LICENSE +1 -1
- package/dist/index.browser.cjs +595 -22
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +174 -21
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +563 -1392
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +174 -21
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +604 -21
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +179 -19
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +3 -18
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/secrets.d.ts +5 -4
- package/dist/types/secrets.d.ts.map +1 -0
- package/package.json +13 -12
|
@@ -1,26 +1,11 @@
|
|
|
1
1
|
(function () {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
function Ce(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 St(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 Wt(t,e){Ce(t);let n=e.outputLen;if(t.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}var dt=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var Xt=t=>t instanceof Uint8Array;var pt=t=>new DataView(t.buffer,t.byteOffset,t.byteLength);var Ue=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!Ue)throw new Error("Non little-endian hardware is not supported");function vt(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function At(t){if(typeof t=="string"&&(t=vt(t)),!Xt(t))throw new Error(`expected Uint8Array, got ${typeof t}`);return t}function Qt(...t){let e=new Uint8Array(t.reduce((r,o)=>r+o.length,0)),n=0;return t.forEach(r=>{if(!Xt(r))throw new Error("Uint8Array expected");e.set(r,n),n+=r.length;}),e}var ht=class{clone(){return this._cloneInto()}};function Jt(t){let e=r=>t().update(At(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function te(t=32){if(dt&&typeof dt.getRandomValues=="function")return dt.getRandomValues(new Uint8Array(t));throw new Error("crypto.getRandomValues must be defined")}function Ke(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 yt=class extends ht{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=pt(this.buffer);}update(e){St(this);let{view:n,buffer:r,blockLen:o}=this;e=At(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=pt(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){St(this),Wt(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;Ke(r,o-8,BigInt(this.length*8),f),this.process(r,0);let i=pt(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 xt=BigInt(4294967295),It=BigInt(32);function ee(t,e=!1){return e?{h:Number(t&xt),l:Number(t>>It&xt)}:{h:Number(t>>It&xt)|0,l:Number(t&xt)|0}}function Re(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}=ee(t[o],e);[n[o],r[o]]=[f,a];}return [n,r]}var He=(t,e)=>BigInt(t>>>0)<<It|BigInt(e>>>0),qe=(t,e,n)=>t>>>n,De=(t,e,n)=>t<<32-n|e>>>n,Pe=(t,e,n)=>t>>>n|e<<32-n,Me=(t,e,n)=>t<<32-n|e>>>n,Ze=(t,e,n)=>t<<64-n|e>>>n-32,ke=(t,e,n)=>t>>>n-32|e<<64-n,Ve=(t,e)=>e,$e=(t,e)=>t,Ge=(t,e,n)=>t<<n|e>>>32-n,Fe=(t,e,n)=>e<<n|t>>>32-n,ze=(t,e,n)=>e<<n-32|t>>>64-n,Ye=(t,e,n)=>t<<n-32|e>>>64-n;function je(t,e,n,r){let o=(e>>>0)+(r>>>0);return {h:t+n+(o/2**32|0)|0,l:o|0}}var We=(t,e,n)=>(t>>>0)+(e>>>0)+(n>>>0),Xe=(t,e,n,r)=>e+n+r+(t/2**32|0)|0,Qe=(t,e,n,r)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0),Je=(t,e,n,r,o)=>e+n+r+o+(t/2**32|0)|0,tn=(t,e,n,r,o)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0)+(o>>>0),en=(t,e,n,r,o,f)=>e+n+r+o+f+(t/2**32|0)|0;var nn={fromBig:ee,split:Re,toBig:He,shrSH:qe,shrSL:De,rotrSH:Pe,rotrSL:Me,rotrBH:Ze,rotrBL:ke,rotr32H:Ve,rotr32L:$e,rotlSH:Ge,rotlSL:Fe,rotlBH:ze,rotlBL:Ye,add:je,add3L:We,add3H:Xe,add4L:Qe,add4H:Je,add5H:en,add5L:tn},y=nn;var[rn,on]=(()=>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),Lt=class extends yt{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:T,Gl:L,Hh:O,Hl:S}=this;return [e,n,r,o,f,a,i,s,l,c,d,b,T,L,O,S]}set(e,n,r,o,f,a,i,s,l,c,d,b,T,L,O,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=T|0,this.Gl=L|0,this.Hh=O|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 H=Q[m-15]|0,g=J[m-15]|0,z=y.rotrSH(H,g,1)^y.rotrSH(H,g,8)^y.shrSH(H,g,7),rt=y.rotrSL(H,g,1)^y.rotrSL(H,g,8)^y.shrSL(H,g,7),q=Q[m-2]|0,M=J[m-2]|0,tt=y.rotrSH(q,M,19)^y.rotrBH(q,M,61)^y.shrSH(q,M,6),W=y.rotrSL(q,M,19)^y.rotrBL(q,M,61)^y.shrSL(q,M,6),ot=y.add4L(rt,W,J[m-7],J[m-16]),et=y.add4H(ot,z,tt,Q[m-7],Q[m-16]);Q[m]=et|0,J[m]=ot|0;}let{Ah:r,Al:o,Bh:f,Bl:a,Ch:i,Cl:s,Dh:l,Dl:c,Eh:d,El:b,Fh:T,Fl:L,Gh:O,Gl:S,Hh:P,Hl:$}=this;for(let m=0;m<80;m++){let H=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&T^~d&O,rt=b&L^~b&S,q=y.add5L($,g,rt,on[m],J[m]),M=y.add5H(q,P,H,z,rn[m],Q[m]),tt=q|0,W=y.rotrSH(r,o,28)^y.rotrBH(r,o,34)^y.rotrBH(r,o,39),ot=y.rotrSL(r,o,28)^y.rotrBL(r,o,34)^y.rotrBL(r,o,39),et=r&f^r&i^f&i,Bt=o&a^o&s^a&s;P=O|0,$=S|0,O=T|0,S=L|0,T=d|0,L=b|0,{h:d,l:b}=y.add(l|0,c|0,M|0,tt|0),l=i|0,c=s|0,i=f|0,s=a|0,f=r|0,a=o|0;let at=y.add3L(tt,ot,Bt);r=y.add3H(at,M,W,et),o=at|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:T,l:L}=y.add(this.Fh|0,this.Fl|0,T|0,L|0),{h:O,l:S}=y.add(this.Gh|0,this.Gl|0,O|0,S|0),{h:P,l:$}=y.add(this.Hh|0,this.Hl|0,P|0,$|0),this.set(r,o,f,a,i,s,l,c,d,b,T,L,O,S,P,$);}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);}};var Nt=Jt(()=>new Lt);BigInt(0);var sn=BigInt(1),cn=BigInt(2),bt=t=>t instanceof Uint8Array,fn=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function gt(t){if(!bt(t))throw new Error("Uint8Array expected");let e="";for(let n=0;n<t.length;n++)e+=fn[t[n]];return e}function ne(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return BigInt(t===""?"0":`0x${t}`)}function re(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 oe(t){return ne(gt(t))}function st(t){if(!bt(t))throw new Error("Uint8Array expected");return ne(gt(Uint8Array.from(t).reverse()))}function Tt(t,e){return re(t.toString(16).padStart(e*2,"0"))}function ft(t,e){return Tt(t,e).reverse()}function F(t,e,n){let r;if(typeof e=="string")try{r=re(e);}catch(f){throw new Error(`${t} must be valid hex string, got "${e}". Cause: ${f}`)}else if(bt(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 Ot(...t){let e=new Uint8Array(t.reduce((r,o)=>r+o.length,0)),n=0;return t.forEach(r=>{if(!bt(r))throw new Error("Uint8Array expected");e.set(r,n),n+=r.length;}),e}var se=t=>(cn<<BigInt(t-1))-sn;var an={bigint:t=>typeof t=="bigint",function:t=>typeof t=="function",boolean:t=>typeof t=="boolean",string:t=>typeof t=="string",stringOrUint8Array:t=>typeof t=="string"||t instanceof Uint8Array,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 it(t,e,n={}){let r=(o,f,a)=>{let i=an[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 C=BigInt(0),I=BigInt(1),nt=BigInt(2),un=BigInt(3),Ct=BigInt(4),ie=BigInt(5),ce=BigInt(8);BigInt(9);BigInt(16);function N(t,e){let n=t%e;return n>=C?n:e+n}function pn(t,e,n){if(n<=C||e<C)throw new Error("Expected power/modulo > 0");if(n===I)return C;let r=I;for(;e>C;)e&I&&(r=r*t%n),t=t*t%n,e>>=I;return r}function k(t,e,n){let r=t;for(;e-- >C;)r*=r,r%=n;return r}function fe(t,e){if(t===C||e<=C)throw new Error(`invert: expected positive integers, got n=${t} mod=${e}`);let n=N(t,e),r=e,o=C,a=I;for(;n!==C;){let l=r/n,c=r%n,d=o-a*l;r=n,n=c,o=a,a=d;}if(r!==I)throw new Error("invert: does not exist");return N(o,e)}function yn(t){let e=(t-I)/nt,n,r,o;for(n=t-I,r=0;n%nt===C;n/=nt,r++);for(o=nt;o<t&&pn(o,e,t)!==t-I;o++);if(r===1){let a=(t+I)/Ct;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+I)/nt;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 T=1;for(let O=i.sqr(b);T<l&&!i.eql(O,i.ONE);T++)O=i.sqr(O);let L=i.pow(c,I<<BigInt(l-T-1));c=i.sqr(L),d=i.mul(d,L),b=i.mul(b,c),l=T;}return d}}function xn(t){if(t%Ct===un){let e=(t+I)/Ct;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%ce===ie){let e=(t-ie)/ce;return function(r,o){let f=r.mul(o,nt),a=r.pow(f,e),i=r.mul(o,a),s=r.mul(r.mul(i,nt),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 yn(t)}var ae=(t,e)=>(N(t,e)&I)===I,bn=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function le(t){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},n=bn.reduce((r,o)=>(r[o]="function",r),e);return it(t,n)}function gn(t,e,n){if(n<C)throw new Error("Expected power > 0");if(n===C)return t.ONE;if(n===I)return e;let r=t.ONE,o=e;for(;n>C;)n&I&&(r=t.mul(r,o)),o=t.sqr(o),n>>=I;return r}function wn(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 Ut(t,e){let n=e!==void 0?e:t.toString(2).length,r=Math.ceil(n/8);return {nBitLength:n,nByteLength:r}}function ue(t,e,n=!1,r={}){if(t<=C)throw new Error(`Expected Field ORDER > 0, got ${t}`);let{nBitLength:o,nByteLength:f}=Ut(t,e);if(f>2048)throw new Error("Field lengths over 2048 bytes are not supported");let a=xn(t),i=Object.freeze({ORDER:t,BITS:o,BYTES:f,MASK:se(o),ZERO:C,ONE:I,create:s=>N(s,t),isValid:s=>{if(typeof s!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof s}`);return C<=s&&s<t},is0:s=>s===C,isOdd:s=>(s&I)===I,neg:s=>N(-s,t),eql:(s,l)=>s===l,sqr:s=>N(s*s,t),add:(s,l)=>N(s+l,t),sub:(s,l)=>N(s-l,t),mul:(s,l)=>N(s*l,t),pow:(s,l)=>gn(i,s,l),div:(s,l)=>N(s*fe(l,t),t),sqrN:s=>s*s,addN:(s,l)=>s+l,subN:(s,l)=>s-l,mulN:(s,l)=>s*l,inv:s=>fe(s,t),sqrt:r.sqrt||(s=>a(i,s)),invertBatch:s=>wn(i,s),cmov:(s,l,c)=>c?l:s,toBytes:s=>n?ft(s,f):Tt(s,f),fromBytes:s=>{if(s.length!==f)throw new Error(`Fp.fromBytes: expected ${f}, got ${s.length}`);return n?st(s):oe(s)}});return Object.freeze(i)}function de(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 mn=BigInt(0),Kt=BigInt(1);function he(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>mn;)f&Kt&&(a=a.add(i)),i=i.double(),f>>=Kt;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,T=BigInt(o);for(let L=0;L<i;L++){let O=L*s,S=Number(a&d);a>>=T,S>s&&(S-=b,a+=Kt);let P=O,$=O+Math.abs(S)-1,m=L%2!==0,H=S<0;S===0?c=c.add(n(m,f[P])):l=l.add(n(H,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 pe(t){return le(t.Fp),it(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Ut(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}var V=BigInt(0),D=BigInt(1),wt=BigInt(2),En=BigInt(8),Bn={zip215:!0};function _n(t){let e=pe(t);return it(t,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function mt(t){let e=_n(t),{Fp:n,n:r,prehash:o,hash:f,randomBytes:a,nByteLength:i,h:s}=e,l=wt<<BigInt(i*8)-D,c=n.create,d=e.uvRatio||((h,u)=>{try{return {isValid:!0,value:n.sqrt(h*n.inv(u))}}catch{return {isValid:!1,value:V}}}),b=e.adjustScalarBytes||(h=>h),T=e.domain||((h,u,p)=>{if(u.length||p)throw new Error("Contexts/pre-hash are not supported");return h}),L=h=>typeof h=="bigint"&&V<h,O=(h,u)=>L(h)&&L(u)&&h<u,S=h=>h===V||O(h,l);function P(h,u){if(O(h,u))return h;throw new Error(`Expected valid scalar < ${u}, got ${typeof h} ${h}`)}function $(h){return h===V?h:P(h,r)}let m=new Map;function H(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,D,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,A=c(x*x),B=c(w*w),v=c(E*E),U=c(v*v),K=c(A*u),G=c(v*c(K+B)),R=c(U+c(p*c(A*B)));if(G!==R)throw new Error("bad point: equation left != right (1)");let X=c(x*w),Y=c(E*_);if(X!==Y)throw new Error("bad point: equation left != right (2)")}equals(u){H(u);let{ex:p,ey:x,ez:w}=this,{ex:E,ey:_,ez:A}=u,B=c(p*A),v=c(E*w),U=c(x*A),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),A=c(wt*c(w*w)),B=c(u*E),v=p+x,U=c(c(v*v)-E-_),K=B+_,G=K-A,R=B-_,X=c(U*G),Y=c(K*R),lt=c(U*R),ut=c(G*K);return new g(X,Y,ut,lt)}add(u){H(u);let{a:p,d:x}=e,{ex:w,ey:E,ez:_,et:A}=this,{ex:B,ey:v,ez:U,et:K}=u;if(p===BigInt(-1)){let Vt=c((E-w)*(v+B)),$t=c((E+w)*(v-B)),_t=c($t-Vt);if(_t===V)return this.double();let Gt=c(_*wt*K),Ft=c(A*wt*U),zt=Ft+Gt,Yt=$t+Vt,jt=Ft-Gt,Le=c(zt*_t),Ne=c(Yt*jt),Te=c(zt*jt),Oe=c(_t*Yt);return new g(Le,Ne,Oe,Te)}let G=c(w*B),R=c(E*v),X=c(A*x*K),Y=c(_*U),lt=c((w+E)*(B+v)-G-R),ut=Y-X,Zt=Y+X,kt=c(R-p*G),Se=c(lt*ut),ve=c(Zt*kt),Ae=c(lt*kt),Ie=c(ut*Zt);return new g(Se,ve,Ie,Ae)}subtract(u){return this.add(u.negate())}wNAF(u){return q.wNAFCached(this,m,u,g.normalizeZ)}multiply(u){let{p,f:x}=this.wNAF(P(u,r));return g.normalizeZ([p,x])[0]}multiplyUnsafe(u){let p=$(u);return p===V?rt:this.equals(rt)||p===D?this:this.equals(z)?this.wNAF(p).p:q.unsafeLadder(this,p)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}isTorsionFree(){return q.unsafeLadder(this,r).is0()}toAffine(u){let{ex:p,ey:x,ez:w}=this,E=this.is0();u==null&&(u=E?En:n.inv(w));let _=c(p*u),A=c(x*u),B=c(w*u);if(E)return {x:V,y:D};if(B!==D)throw new Error("invZ was invalid");return {x:_,y:A}}clearCofactor(){let{h:u}=e;return u===D?this:this.multiplyUnsafe(u)}static fromHex(u,p=!1){let{d:x,a:w}=e,E=n.BYTES;u=F("pointHex",u,E);let _=u.slice(),A=u[E-1];_[E-1]=A&-129;let B=st(_);B===V||(p?P(B,l):P(B,n.ORDER));let v=c(B*B),U=c(v-D),K=c(x*v-w),{isValid:G,value:R}=d(U,K);if(!G)throw new Error("Point.fromHex: invalid y coordinate");let X=(R&D)===D,Y=(A&128)!==0;if(!p&&R===V&&Y)throw new Error("Point.fromHex: x=0 and x_0=1");return Y!==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=ft(p,n.BYTES);return x[x.length-1]|=u&D?128:0,x}toHex(){return gt(this.toRawBytes())}}g.BASE=new g(e.Gx,e.Gy,D,c(e.Gx*e.Gy)),g.ZERO=new g(V,D,D,V);let{BASE:z,ZERO:rt}=g,q=he(g,i*8);function M(h){return N(h,r)}function tt(h){return M(st(h))}function W(h){let u=i;h=F("private key",h,u);let p=F("hashed private key",f(h),2*u),x=b(p.slice(0,u)),w=p.slice(u,2*u),E=tt(x),_=z.multiply(E),A=_.toRawBytes();return {head:x,prefix:w,scalar:E,point:_,pointBytes:A}}function ot(h){return W(h).pointBytes}function et(h=new Uint8Array,...u){let p=Ot(...u);return tt(f(T(p,F("context",h),!!o)))}function Bt(h,u,p={}){h=F("message",h),o&&(h=o(h));let{prefix:x,scalar:w,pointBytes:E}=W(u),_=et(p.context,x,h),A=z.multiply(_).toRawBytes(),B=et(p.context,A,E,h),v=M(_+B*w);$(v);let U=Ot(A,ft(v,n.BYTES));return F("result",U,i*2)}let at=Bn;function _e(h,u,p,x=at){let{context:w,zip215:E}=x,_=n.BYTES;h=F("signature",h,2*_),u=F("message",u),o&&(u=o(u));let A=st(h.slice(_,2*_)),B,v,U;try{B=g.fromHex(p,E),v=g.fromHex(h.slice(0,_),E),U=z.multiplyUnsafe(A);}catch{return !1}if(!E&&B.isSmallOrder())return !1;let K=et(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:ot,sign:Bt,verify:_e,ExtendedPoint:g,utils:{getExtendedPublicKey:W,randomPrivateKey:()=>a(n.BYTES),precompute(h=8,u=g.BASE){return u._setWindowSize(h),u.multiply(BigInt(3)),u}}}}var Ht=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),ye=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");BigInt(0);var Sn=BigInt(1),Rt=BigInt(2),vn=BigInt(5),xe=BigInt(10),An=BigInt(20),In=BigInt(40),be=BigInt(80);function Ln(t){let e=Ht,r=t*t%e*t%e,o=k(r,Rt,e)*r%e,f=k(o,Sn,e)*t%e,a=k(f,vn,e)*f%e,i=k(a,xe,e)*a%e,s=k(i,An,e)*i%e,l=k(s,In,e)*s%e,c=k(l,be,e)*l%e,d=k(c,be,e)*l%e,b=k(d,xe,e)*a%e;return {pow_p_5_8:k(b,Rt,e)*t%e,b2:r}}function Nn(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}function Tn(t,e){let n=Ht,r=N(e*e*e,n),o=N(r*r*e,n),f=Ln(t*o).pow_p_5_8,a=N(t*r*f,n),i=N(e*a*a,n),s=a,l=N(a*ye,n),c=i===t,d=i===N(-t,n),b=i===N(-t*ye,n);return c&&(a=s),(d||b)&&(a=l),ae(a,n)&&(a=N(-a,n)),{isValid:c||d,value:a}}var j=ue(Ht,void 0,!0),qt={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:j,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Nt,randomBytes:te,adjustScalarBytes:Nn,uvRatio:Tn},ct=mt(qt);function ge(t,e,n){if(e.length>255)throw new Error("Context is too big");return Qt(vt("SigEd25519 no Ed25519 collisions"),new Uint8Array([n?1:0,e.length]),e,t)}mt({...qt,domain:ge});mt({...qt,domain:ge,prehash:Nt});var On=(j.ORDER+BigInt(3))/BigInt(8);j.pow(Rt,On);j.sqrt(j.neg(j.ONE));(j.ORDER-BigInt(5))/BigInt(8);BigInt(486662);de(j,j.neg(BigInt(486664)));BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235");BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578");BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838");BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var Cn=new Set(["decrypt","deriveBits","deriveKey","encrypt","unwrapKey","wrapKey"]);function Dt(t){return t instanceof Uint8Array?t:new Uint8Array(ArrayBuffer.isView(t)?t.buffer:t)}var Pt;function Un(t,e,n){let r=Kn(e,n),o=Pt||(Pt=new WeakMap);return o.set(r.privateKey,t),o.set(r.publicKey,t),r}function Kn(t,e){if(e.length===0)throw new DOMException("Usages cannot be empty when creating a key.","SyntaxError");if(e.some(f=>Cn.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 Mt(t){let e=Pt?.get(t);if(e===void 0)throw new Error("Could not find secret key material associated with this `CryptoKey`");return e}function we(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 ct.getPublicKey(Mt(e))}default:throw new Error(`Exporting polyfilled Ed25519 keys in the "${t}" format is unimplemented`)}}function me(t,e){let n=ct.utils.randomPrivateKey();return Un(n,t,e)}function Et(t){return !!Pt?.has(t)}function Ee(t,e){if(t.type!=="private"||!t.usages.includes("sign"))throw new DOMException("Unable to use this key to sign","InvalidAccessError");let n=Mt(t),r=Dt(e);return ct.sign(r,n)}function Be(t,e,n){if(t.type!=="public"||!t.usages.includes("verify"))throw new DOMException("Unable to use this key to verify","InvalidAccessError");let r=ct.getPublicKey(Mt(t));try{return ct.verify(Dt(e),Dt(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(Et(l))return we(...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 me(d,b)}};let f=e.sign;e.sign=async(...i)=>{let[s,l]=i;if(Et(l)){let[c,...d]=i;return Ee(...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(Et(l)){let[c,...d]=i;return Be(...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/
|
|
8
|
-
(*! noble-
|
|
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/ed25519.js:
|
|
23
|
-
(*! 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) *)
|
|
24
9
|
*/
|
|
25
10
|
|
|
26
11
|
})();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":""}
|
package/dist/types/secrets.d.ts
CHANGED
|
@@ -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
|
|
@@ -0,0 +1 @@
|
|
|
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.
|
|
3
|
+
"version": "2.0.0-experimental.c9bd7fa",
|
|
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,23 +49,24 @@
|
|
|
49
49
|
"node": ">=17.4"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@noble/
|
|
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.
|
|
57
|
-
"@types/jest": "^29.5.
|
|
58
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
57
|
+
"@swc/jest": "^0.2.29",
|
|
58
|
+
"@types/jest": "^29.5.11",
|
|
59
|
+
"@typescript-eslint/eslint-plugin": "^6.13.2",
|
|
59
60
|
"@typescript-eslint/parser": "^6.3.0",
|
|
60
61
|
"eslint": "^8.45.0",
|
|
61
|
-
"eslint-plugin-jest": "^27.2
|
|
62
|
+
"eslint-plugin-jest": "^27.4.2",
|
|
62
63
|
"eslint-plugin-sort-keys-fix": "^1.1.2",
|
|
63
64
|
"jest": "^29.7.0",
|
|
64
|
-
"jest-environment-jsdom": "^29.
|
|
65
|
-
"jest-runner-eslint": "^2.1.
|
|
65
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
66
|
+
"jest-runner-eslint": "^2.1.2",
|
|
66
67
|
"jest-runner-prettier": "^1.0.0",
|
|
67
|
-
"prettier": "^
|
|
68
|
-
"tsup": "
|
|
68
|
+
"prettier": "^3.1",
|
|
69
|
+
"tsup": "^8.0.1",
|
|
69
70
|
"typescript": "^5.2.2",
|
|
70
71
|
"version-from-git": "^1.1.1",
|
|
71
72
|
"build-scripts": "0.0.0",
|
|
@@ -82,10 +83,10 @@
|
|
|
82
83
|
},
|
|
83
84
|
"scripts": {
|
|
84
85
|
"compile:js": "tsup --config build-scripts/tsup.config.library.ts",
|
|
85
|
-
"compile:typedefs": "tsc -p ./tsconfig.declarations.json",
|
|
86
|
+
"compile:typedefs": "tsc -p ./tsconfig.declarations.json && node node_modules/build-scripts/add-js-extension-to-types.mjs",
|
|
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",
|
|
88
|
-
"style:fix": "pnpm eslint --fix src/* && pnpm prettier -w src/*",
|
|
89
|
+
"style:fix": "pnpm eslint --fix src/* && pnpm prettier -w src/* package.json",
|
|
89
90
|
"test:lint": "jest -c node_modules/test-config/jest-lint.config.ts --rootDir . --silent",
|
|
90
91
|
"test:prettier": "jest -c node_modules/test-config/jest-prettier.config.ts --rootDir . --silent",
|
|
91
92
|
"test:typecheck": "tsc --noEmit",
|