@solana/webcrypto-ed25519-polyfill 2.0.0-experimental.762ff13 → 2.0.0-experimental.76cf6b4
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/index.browser.cjs +441 -25
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +20 -22
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +413 -1397
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +20 -22
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +450 -20
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +25 -20
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +3 -18
- package/dist/types/secrets.d.ts +4 -4
- package/dist/types/secrets.d.ts.map +1 -1
- package/package.json +7 -6
|
@@ -1,26 +1,11 @@
|
|
|
1
1
|
(function () {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
function He(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 At(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 Qt(t,e){He(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 Jt=t=>t instanceof Uint8Array;var pt=t=>new DataView(t.buffer,t.byteOffset,t.byteLength);var qe=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!qe)throw new Error("Non little-endian hardware is not supported");function It(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function Kt(t){if(typeof t=="string"&&(t=It(t)),!Jt(t))throw new Error(`expected Uint8Array, got ${typeof t}`);return t}function te(...t){let e=new Uint8Array(t.reduce((r,o)=>r+o.length,0)),n=0;return t.forEach(r=>{if(!Jt(r))throw new Error("Uint8Array expected");e.set(r,n),n+=r.length;}),e}var ht=class{clone(){return this._cloneInto()}};function ee(t){let e=r=>t().update(Kt(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function ne(t=32){if(dt&&typeof dt.getRandomValues=="function")return dt.getRandomValues(new Uint8Array(t));throw new Error("crypto.getRandomValues must be defined")}function Me(t,e,n,r){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,n,r);let o=BigInt(32),a=BigInt(4294967295),l=Number(n>>o&a),c=Number(n&a),s=r?4:0,f=r?0:4;t.setUint32(e+s,l,r),t.setUint32(e+f,c,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){At(this);let{view:n,buffer:r,blockLen:o}=this;e=Kt(e);let a=e.length;for(let l=0;l<a;){let c=Math.min(o-this.pos,a-l);if(c===o){let s=pt(e);for(;o<=a-l;l+=o)this.process(s,l);continue}r.set(e.subarray(l,l+c),this.pos),this.pos+=c,l+=c,this.pos===o&&(this.process(n,0),this.pos=0);}return this.length+=e.length,this.roundClean(),this}digestInto(e){At(this),Qt(e,this),this.finished=!0;let{buffer:n,view:r,blockLen:o,isLE:a}=this,{pos:l}=this;n[l++]=128,this.buffer.subarray(l).fill(0),this.padOffset>o-l&&(this.process(r,0),l=0);for(let d=l;d<o;d++)n[d]=0;Me(r,o-8,BigInt(this.length*8),a),this.process(r,0);let c=pt(e),s=this.outputLen;if(s%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=s/4,i=this.get();if(f>i.length)throw new Error("_sha2: outputLen bigger than state");for(let d=0;d<f;d++)c.setUint32(4*d,i[d],a);}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:a,destroyed:l,pos:c}=this;return e.length=o,e.pos=c,e.finished=a,e.destroyed=l,o%n&&e.buffer.set(r),e}};var xt=BigInt(4294967295),Lt=BigInt(32);function re(t,e=!1){return e?{h:Number(t&xt),l:Number(t>>Lt&xt)}:{h:Number(t>>Lt&xt)|0,l:Number(t&xt)|0}}function Pe(t,e=!1){let n=new Uint32Array(t.length),r=new Uint32Array(t.length);for(let o=0;o<t.length;o++){let{h:a,l}=re(t[o],e);[n[o],r[o]]=[a,l];}return [n,r]}var ke=(t,e)=>BigInt(t>>>0)<<Lt|BigInt(e>>>0),Ve=(t,e,n)=>t>>>n,Ze=(t,e,n)=>t<<32-n|e>>>n,$e=(t,e,n)=>t>>>n|e<<32-n,ze=(t,e,n)=>t<<32-n|e>>>n,Fe=(t,e,n)=>t<<64-n|e>>>n-32,Ge=(t,e,n)=>t>>>n-32|e<<64-n,je=(t,e)=>e,We=(t,e)=>t,Ye=(t,e,n)=>t<<n|e>>>32-n,Xe=(t,e,n)=>e<<n|t>>>32-n,Qe=(t,e,n)=>e<<n-32|t>>>64-n,Je=(t,e,n)=>t<<n-32|e>>>64-n;function tn(t,e,n,r){let o=(e>>>0)+(r>>>0);return {h:t+n+(o/2**32|0)|0,l:o|0}}var en=(t,e,n)=>(t>>>0)+(e>>>0)+(n>>>0),nn=(t,e,n,r)=>e+n+r+(t/2**32|0)|0,rn=(t,e,n,r)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0),on=(t,e,n,r,o)=>e+n+r+o+(t/2**32|0)|0,sn=(t,e,n,r,o)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0)+(o>>>0),cn=(t,e,n,r,o,a)=>e+n+r+o+a+(t/2**32|0)|0;var an={fromBig:re,split:Pe,toBig:ke,shrSH:Ve,shrSL:Ze,rotrSH:$e,rotrSL:ze,rotrBH:Fe,rotrBL:Ge,rotr32H:je,rotr32L:We,rotlSH:Ye,rotlSL:Xe,rotlBH:Qe,rotlBL:Je,add:tn,add3L:en,add3H:nn,add4L:rn,add4H:on,add5H:cn,add5L:sn},x=an;var[fn,ln]=(()=>x.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),Ct=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:a,Cl:l,Dh:c,Dl:s,Eh:f,El:i,Fh:d,Fl:y,Gh:g,Gl:S,Hh:I,Hl:A}=this;return [e,n,r,o,a,l,c,s,f,i,d,y,g,S,I,A]}set(e,n,r,o,a,l,c,s,f,i,d,y,g,S,I,A){this.Ah=e|0,this.Al=n|0,this.Bh=r|0,this.Bl=o|0,this.Ch=a|0,this.Cl=l|0,this.Dh=c|0,this.Dl=s|0,this.Eh=f|0,this.El=i|0,this.Fh=d|0,this.Fl=y|0,this.Gh=g|0,this.Gl=S|0,this.Hh=I|0,this.Hl=A|0;}process(e,n){for(let E=0;E<16;E++,n+=4)Q[E]=e.getUint32(n),J[E]=e.getUint32(n+=4);for(let E=16;E<80;E++){let H=Q[E-15]|0,w=J[E-15]|0,G=x.rotrSH(H,w,1)^x.rotrSH(H,w,8)^x.shrSH(H,w,7),rt=x.rotrSL(H,w,1)^x.rotrSL(H,w,8)^x.shrSL(H,w,7),q=Q[E-2]|0,k=J[E-2]|0,tt=x.rotrSH(q,k,19)^x.rotrBH(q,k,61)^x.shrSH(q,k,6),Y=x.rotrSL(q,k,19)^x.rotrBL(q,k,61)^x.shrSL(q,k,6),ot=x.add4L(rt,Y,J[E-7],J[E-16]),et=x.add4H(ot,G,tt,Q[E-7],Q[E-16]);Q[E]=et|0,J[E]=ot|0;}let{Ah:r,Al:o,Bh:a,Bl:l,Ch:c,Cl:s,Dh:f,Dl:i,Eh:d,El:y,Fh:g,Fl:S,Gh:I,Gl:A,Hh:U,Hl:P}=this;for(let E=0;E<80;E++){let H=x.rotrSH(d,y,14)^x.rotrSH(d,y,18)^x.rotrBH(d,y,41),w=x.rotrSL(d,y,14)^x.rotrSL(d,y,18)^x.rotrBL(d,y,41),G=d&g^~d&I,rt=y&S^~y&A,q=x.add5L(P,w,rt,ln[E],J[E]),k=x.add5H(q,U,H,G,fn[E],Q[E]),tt=q|0,Y=x.rotrSH(r,o,28)^x.rotrBH(r,o,34)^x.rotrBH(r,o,39),ot=x.rotrSL(r,o,28)^x.rotrBL(r,o,34)^x.rotrBL(r,o,39),et=r&a^r&c^a&c,_t=o&l^o&s^l&s;U=I|0,P=A|0,I=g|0,A=S|0,g=d|0,S=y|0,{h:d,l:y}=x.add(f|0,i|0,k|0,tt|0),f=c|0,i=s|0,c=a|0,s=l|0,a=r|0,l=o|0;let ft=x.add3L(tt,ot,_t);r=x.add3H(ft,k,Y,et),o=ft|0;}(({h:r,l:o}=x.add(this.Ah|0,this.Al|0,r|0,o|0))),{h:a,l}=x.add(this.Bh|0,this.Bl|0,a|0,l|0),{h:c,l:s}=x.add(this.Ch|0,this.Cl|0,c|0,s|0),{h:f,l:i}=x.add(this.Dh|0,this.Dl|0,f|0,i|0),{h:d,l:y}=x.add(this.Eh|0,this.El|0,d|0,y|0),{h:g,l:S}=x.add(this.Fh|0,this.Fl|0,g|0,S|0),{h:I,l:A}=x.add(this.Gh|0,this.Gl|0,I|0,A|0),{h:U,l:P}=x.add(this.Hh|0,this.Hl|0,U|0,P|0),this.set(r,o,a,l,c,s,f,i,d,y,g,S,I,A,U,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 Ot=ee(()=>new Ct);BigInt(0);var un=BigInt(1),dn=BigInt(2),bt=t=>t instanceof Uint8Array,hn=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function wt(t){if(!bt(t))throw new Error("Uint8Array expected");let e="";for(let n=0;n<t.length;n++)e+=hn[t[n]];return e}function oe(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return BigInt(t===""?"0":`0x${t}`)}function se(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,a=t.slice(o,o+2),l=Number.parseInt(a,16);if(Number.isNaN(l)||l<0)throw new Error("Invalid byte sequence");n[r]=l;}return n}function ie(t){return oe(wt(t))}function st(t){if(!bt(t))throw new Error("Uint8Array expected");return oe(wt(Uint8Array.from(t).reverse()))}function Tt(t,e){return se(t.toString(16).padStart(e*2,"0"))}function ct(t,e){return Tt(t,e).reverse()}function F(t,e,n){let r;if(typeof e=="string")try{r=se(e);}catch(a){throw new Error(`${t} must be valid hex string, got "${e}". Cause: ${a}`)}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 Nt(...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 ce=t=>(dn<<BigInt(t-1))-un;var pn={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,a,l)=>{let c=pn[a];if(typeof c!="function")throw new Error(`Invalid validator "${a}", expected function`);let s=t[o];if(!(l&&s===void 0)&&!c(s,t))throw new Error(`Invalid param ${String(o)}=${s} (${typeof s}), expected ${a}`)};for(let[o,a]of Object.entries(e))r(o,a,!1);for(let[o,a]of Object.entries(n))r(o,a,!0);return t}var T=BigInt(0),C=BigInt(1),nt=BigInt(2),xn=BigInt(3),Ut=BigInt(4),ae=BigInt(5),fe=BigInt(8);BigInt(9);BigInt(16);function O(t,e){let n=t%e;return n>=T?n:e+n}function gn(t,e,n){if(n<=T||e<T)throw new Error("Expected power/modulo > 0");if(n===C)return T;let r=C;for(;e>T;)e&C&&(r=r*t%n),t=t*t%n,e>>=C;return r}function Z(t,e,n){let r=t;for(;e-- >T;)r*=r,r%=n;return r}function le(t,e){if(t===T||e<=T)throw new Error(`invert: expected positive integers, got n=${t} mod=${e}`);let n=O(t,e),r=e,o=T,l=C;for(;n!==T;){let f=r/n,i=r%n,d=o-l*f;r=n,n=i,o=l,l=d;}if(r!==C)throw new Error("invert: does not exist");return O(o,e)}function mn(t){let e=(t-C)/nt,n,r,o;for(n=t-C,r=0;n%nt===T;n/=nt,r++);for(o=nt;o<t&&gn(o,e,t)!==t-C;o++);if(r===1){let l=(t+C)/Ut;return function(s,f){let i=s.pow(f,l);if(!s.eql(s.sqr(i),f))throw new Error("Cannot find square root");return i}}let a=(n+C)/nt;return function(c,s){if(c.pow(s,e)===c.neg(c.ONE))throw new Error("Cannot find square root");let f=r,i=c.pow(c.mul(c.ONE,o),n),d=c.pow(s,a),y=c.pow(s,n);for(;!c.eql(y,c.ONE);){if(c.eql(y,c.ZERO))return c.ZERO;let g=1;for(let I=c.sqr(y);g<f&&!c.eql(I,c.ONE);g++)I=c.sqr(I);let S=c.pow(i,C<<BigInt(f-g-1));i=c.sqr(S),d=c.mul(d,S),y=c.mul(y,i),f=g;}return d}}function En(t){if(t%Ut===xn){let e=(t+C)/Ut;return function(r,o){let a=r.pow(o,e);if(!r.eql(r.sqr(a),o))throw new Error("Cannot find square root");return a}}if(t%fe===ae){let e=(t-ae)/fe;return function(r,o){let a=r.mul(o,nt),l=r.pow(a,e),c=r.mul(o,l),s=r.mul(r.mul(c,nt),l),f=r.mul(c,r.sub(s,r.ONE));if(!r.eql(r.sqr(f),o))throw new Error("Cannot find square root");return f}}return mn(t)}var ue=(t,e)=>(O(t,e)&C)===C,Bn=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function de(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 Sn(t,e,n){if(n<T)throw new Error("Expected power > 0");if(n===T)return t.ONE;if(n===C)return e;let r=t.ONE,o=e;for(;n>T;)n&C&&(r=t.mul(r,o)),o=t.sqr(o),n>>=C;return r}function _n(t,e){let n=new Array(e.length),r=e.reduce((a,l,c)=>t.is0(l)?a:(n[c]=a,t.mul(a,l)),t.ONE),o=t.inv(r);return e.reduceRight((a,l,c)=>t.is0(l)?a:(n[c]=t.mul(a,n[c]),t.mul(a,l)),o),n}function Dt(t,e){let n=e!==void 0?e:t.toString(2).length,r=Math.ceil(n/8);return {nBitLength:n,nByteLength:r}}function he(t,e,n=!1,r={}){if(t<=T)throw new Error(`Expected Field ORDER > 0, got ${t}`);let{nBitLength:o,nByteLength:a}=Dt(t,e);if(a>2048)throw new Error("Field lengths over 2048 bytes are not supported");let l=En(t),c=Object.freeze({ORDER:t,BITS:o,BYTES:a,MASK:ce(o),ZERO:T,ONE:C,create:s=>O(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&C)===C,neg:s=>O(-s,t),eql:(s,f)=>s===f,sqr:s=>O(s*s,t),add:(s,f)=>O(s+f,t),sub:(s,f)=>O(s-f,t),mul:(s,f)=>O(s*f,t),pow:(s,f)=>Sn(c,s,f),div:(s,f)=>O(s*le(f,t),t),sqrN:s=>s*s,addN:(s,f)=>s+f,subN:(s,f)=>s-f,mulN:(s,f)=>s*f,inv:s=>le(s,t),sqrt:r.sqrt||(s=>l(c,s)),invertBatch:s=>_n(c,s),cmov:(s,f,i)=>i?f:s,toBytes:s=>n?ct(s,a):Tt(s,a),fromBytes:s=>{if(s.length!==a)throw new Error(`Fp.fromBytes: expected ${a}, got ${s.length}`);return n?st(s):ie(s)}});return Object.freeze(c)}function pe(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 vn=BigInt(0),Rt=BigInt(1);function ye(t,e){let n=(o,a)=>{let l=a.negate();return o?l:a},r=o=>{let a=Math.ceil(e/o)+1,l=2**(o-1);return {windows:a,windowSize:l}};return {constTimeNegate:n,unsafeLadder(o,a){let l=t.ZERO,c=o;for(;a>vn;)a&Rt&&(l=l.add(c)),c=c.double(),a>>=Rt;return l},precomputeWindow(o,a){let{windows:l,windowSize:c}=r(a),s=[],f=o,i=f;for(let d=0;d<l;d++){i=f,s.push(i);for(let y=1;y<c;y++)i=i.add(f),s.push(i);f=i.double();}return s},wNAF(o,a,l){let{windows:c,windowSize:s}=r(o),f=t.ZERO,i=t.BASE,d=BigInt(2**o-1),y=2**o,g=BigInt(o);for(let S=0;S<c;S++){let I=S*s,A=Number(l&d);l>>=g,A>s&&(A-=y,l+=Rt);let U=I,P=I+Math.abs(A)-1,E=S%2!==0,H=A<0;A===0?i=i.add(n(E,a[U])):f=f.add(n(H,a[P]));}return {p:f,f:i}},wNAFCached(o,a,l,c){let s=o._WINDOW_SIZE||1,f=a.get(o);return f||(f=this.precomputeWindow(o,s),s!==1&&a.set(o,c(f))),this.wNAF(s,f,l)}}}function xe(t){return de(t.Fp),it(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Dt(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}var $=BigInt(0),M=BigInt(1),gt=BigInt(2),An=BigInt(8),In={zip215:!0};function Kn(t){let e=xe(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=Kn(t),{Fp:n,n:r,prehash:o,hash:a,randomBytes:l,nByteLength:c,h:s}=e,f=gt<<BigInt(c*8)-M,i=n.create,d=e.uvRatio||((h,u)=>{try{return {isValid:!0,value:n.sqrt(h*n.inv(u))}}catch{return {isValid:!1,value:$}}}),y=e.adjustScalarBytes||(h=>h),g=e.domain||((h,u,p)=>{if(u.length||p)throw new Error("Contexts/pre-hash are not supported");return h}),S=h=>typeof h=="bigint"&&$<h,I=(h,u)=>S(h)&&S(u)&&h<u,A=h=>h===$||I(h,f);function U(h,u){if(I(h,u))return h;throw new Error(`Expected valid scalar < ${u}, got ${typeof h} ${h}`)}function P(h){return h===$?h:U(h,r)}let E=new Map;function H(h){if(!(h instanceof w))throw new Error("ExtendedPoint expected")}class w{constructor(u,p,b,m){if(this.ex=u,this.ey=p,this.ez=b,this.et=m,!A(u))throw new Error("x required");if(!A(p))throw new Error("y required");if(!A(b))throw new Error("z required");if(!A(m))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(u){if(u instanceof w)throw new Error("extended point not allowed");let{x:p,y:b}=u||{};if(!A(p)||!A(b))throw new Error("invalid affine point");return new w(p,b,M,i(p*b))}static normalizeZ(u){let p=n.invertBatch(u.map(b=>b.ez));return u.map((b,m)=>b.toAffine(p[m])).map(w.fromAffine)}_setWindowSize(u){this._WINDOW_SIZE=u,E.delete(this);}assertValidity(){let{a:u,d:p}=e;if(this.is0())throw new Error("bad point: ZERO");let{ex:b,ey:m,ez:B,et:v}=this,L=i(b*b),_=i(m*m),K=i(B*B),N=i(K*K),D=i(L*u),z=i(K*i(D+_)),R=i(N+i(p*i(L*_)));if(z!==R)throw new Error("bad point: equation left != right (1)");let X=i(b*m),j=i(B*v);if(X!==j)throw new Error("bad point: equation left != right (2)")}equals(u){H(u);let{ex:p,ey:b,ez:m}=this,{ex:B,ey:v,ez:L}=u,_=i(p*L),K=i(B*m),N=i(b*L),D=i(v*m);return _===K&&N===D}is0(){return this.equals(w.ZERO)}negate(){return new w(i(-this.ex),this.ey,this.ez,i(-this.et))}double(){let{a:u}=e,{ex:p,ey:b,ez:m}=this,B=i(p*p),v=i(b*b),L=i(gt*i(m*m)),_=i(u*B),K=p+b,N=i(i(K*K)-B-v),D=_+v,z=D-L,R=_-v,X=i(N*z),j=i(D*R),lt=i(N*R),ut=i(z*D);return new w(X,j,ut,lt)}add(u){H(u);let{a:p,d:b}=e,{ex:m,ey:B,ez:v,et:L}=this,{ex:_,ey:K,ez:N,et:D}=u;if(p===BigInt(-1)){let zt=i((B-m)*(K+_)),Ft=i((B+m)*(K-_)),vt=i(Ft-zt);if(vt===$)return this.double();let Gt=i(v*gt*D),jt=i(L*gt*N),Wt=jt+Gt,Yt=Ft+zt,Xt=jt-Gt,Ne=i(Wt*vt),Ue=i(Yt*Xt),De=i(Wt*Xt),Re=i(vt*Yt);return new w(Ne,Ue,Re,De)}let z=i(m*_),R=i(B*K),X=i(L*b*D),j=i(v*N),lt=i((m+B)*(_+K)-z-R),ut=j-X,Zt=j+X,$t=i(R-p*z),Le=i(lt*ut),Ce=i(Zt*$t),Oe=i(lt*$t),Te=i(ut*Zt);return new w(Le,Ce,Te,Oe)}subtract(u){return this.add(u.negate())}wNAF(u){return q.wNAFCached(this,E,u,w.normalizeZ)}multiply(u){let{p,f:b}=this.wNAF(U(u,r));return w.normalizeZ([p,b])[0]}multiplyUnsafe(u){let p=P(u);return p===$?rt:this.equals(rt)||p===M?this:this.equals(G)?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:b,ez:m}=this,B=this.is0();u==null&&(u=B?An:n.inv(m));let v=i(p*u),L=i(b*u),_=i(m*u);if(B)return {x:$,y:M};if(_!==M)throw new Error("invZ was invalid");return {x:v,y:L}}clearCofactor(){let{h:u}=e;return u===M?this:this.multiplyUnsafe(u)}static fromHex(u,p=!1){let{d:b,a:m}=e,B=n.BYTES;u=F("pointHex",u,B);let v=u.slice(),L=u[B-1];v[B-1]=L&-129;let _=st(v);_===$||(p?U(_,f):U(_,n.ORDER));let K=i(_*_),N=i(K-M),D=i(b*K-m),{isValid:z,value:R}=d(N,D);if(!z)throw new Error("Point.fromHex: invalid y coordinate");let X=(R&M)===M,j=(L&128)!==0;if(!p&&R===$&&j)throw new Error("Point.fromHex: x=0 and x_0=1");return j!==X&&(R=i(-R)),w.fromAffine({x:R,y:_})}static fromPrivateKey(u){return Y(u).point}toRawBytes(){let{x:u,y:p}=this.toAffine(),b=ct(p,n.BYTES);return b[b.length-1]|=u&M?128:0,b}toHex(){return wt(this.toRawBytes())}}w.BASE=new w(e.Gx,e.Gy,M,i(e.Gx*e.Gy)),w.ZERO=new w($,M,M,$);let{BASE:G,ZERO:rt}=w,q=ye(w,c*8);function k(h){return O(h,r)}function tt(h){return k(st(h))}function Y(h){let u=c;h=F("private key",h,u);let p=F("hashed private key",a(h),2*u),b=y(p.slice(0,u)),m=p.slice(u,2*u),B=tt(b),v=G.multiply(B),L=v.toRawBytes();return {head:b,prefix:m,scalar:B,point:v,pointBytes:L}}function ot(h){return Y(h).pointBytes}function et(h=new Uint8Array,...u){let p=Nt(...u);return tt(a(g(p,F("context",h),!!o)))}function _t(h,u,p={}){h=F("message",h),o&&(h=o(h));let{prefix:b,scalar:m,pointBytes:B}=Y(u),v=et(p.context,b,h),L=G.multiply(v).toRawBytes(),_=et(p.context,L,B,h),K=k(v+_*m);P(K);let N=Nt(L,ct(K,n.BYTES));return F("result",N,c*2)}let ft=In;function Ke(h,u,p,b=ft){let{context:m,zip215:B}=b,v=n.BYTES;h=F("signature",h,2*v),u=F("message",u),o&&(u=o(u));let L=st(h.slice(v,2*v)),_,K,N;try{_=w.fromHex(p,B),K=w.fromHex(h.slice(0,v),B),N=G.multiplyUnsafe(L);}catch{return !1}if(!B&&_.isSmallOrder())return !1;let D=et(m,K.toRawBytes(),_.toRawBytes(),u);return K.add(_.multiplyUnsafe(D)).subtract(N).clearCofactor().equals(w.ZERO)}return G._setWindowSize(8),{CURVE:e,getPublicKey:ot,sign:_t,verify:Ke,ExtendedPoint:w,utils:{getExtendedPublicKey:Y,randomPrivateKey:()=>l(n.BYTES),precompute(h=8,u=w.BASE){return u._setWindowSize(h),u.multiply(BigInt(3)),u}}}}var qt=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),be=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");BigInt(0);var Ln=BigInt(1),Ht=BigInt(2),Cn=BigInt(5),we=BigInt(10),On=BigInt(20),Tn=BigInt(40),ge=BigInt(80);function Nn(t){let e=qt,r=t*t%e*t%e,o=Z(r,Ht,e)*r%e,a=Z(o,Ln,e)*t%e,l=Z(a,Cn,e)*a%e,c=Z(l,we,e)*l%e,s=Z(c,On,e)*c%e,f=Z(s,Tn,e)*s%e,i=Z(f,ge,e)*f%e,d=Z(i,ge,e)*f%e,y=Z(d,we,e)*l%e;return {pow_p_5_8:Z(y,Ht,e)*t%e,b2:r}}function Un(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}function Dn(t,e){let n=qt,r=O(e*e*e,n),o=O(r*r*e,n),a=Nn(t*o).pow_p_5_8,l=O(t*r*a,n),c=O(e*l*l,n),s=l,f=O(l*be,n),i=c===t,d=c===O(-t,n),y=c===O(-t*be,n);return i&&(l=s),(d||y)&&(l=f),ue(l,n)&&(l=O(-l,n)),{isValid:i||d,value:l}}var W=he(qt,void 0,!0),Mt={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:W,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Ot,randomBytes:ne,adjustScalarBytes:Un,uvRatio:Dn},at=mt(Mt);function me(t,e,n){if(e.length>255)throw new Error("Context is too big");return te(It("SigEd25519 no Ed25519 collisions"),new Uint8Array([n?1:0,e.length]),e,t)}mt({...Mt,domain:me});mt({...Mt,domain:me,prehash:Ot});var Rn=(W.ORDER+BigInt(3))/BigInt(8);W.pow(Ht,Rn);W.sqrt(W.neg(W.ONE));(W.ORDER-BigInt(5))/BigInt(8);BigInt(486662);pe(W,W.neg(BigInt(486664)));BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235");BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578");BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838");BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var Pt=new Set(["decrypt","deriveBits","deriveKey","encrypt","unwrapKey","wrapKey"]),Ee=[48,46,2,1,0,48,5,6,3,43,101,112,4,34,4,32];function Et(t){return t instanceof Uint8Array?t:new Uint8Array(ArrayBuffer.isView(t)?t.buffer:t)}var Bt,kt;function Hn(t,e,n){let r=qn(e,n),o=Bt||(Bt=new WeakMap);return o.set(r.privateKey,t),o.set(r.publicKey,t),r}function qn(t,e){if(e.length===0)throw new DOMException("Usages cannot be empty when creating a key.","SyntaxError");if(e.some(a=>Pt.has(a)))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(a=>a==="sign"))},o={...n,extractable:!0,type:"public",usages:Object.freeze(e.filter(a=>a==="verify"))};return Object.freeze({privateKey:Object.freeze(r),publicKey:Object.freeze(o)})}function Vt(t){let e=Bt?.get(t);if(e===void 0)throw new Error("Could not find secret key material associated with this `CryptoKey`");return e}function Be(t){let e=kt||(kt=new WeakMap),n=e.get(t);if(n)return n;let r=at.getPublicKey(Vt(t));return e.set(t,r),r}function Se(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 Be(e)}case"pkcs8":{if(e.type!=="private")throw new DOMException(`Unable to export a pkcs8 Ed25519 ${e.type} key`,"InvalidAccessError");let n=Vt(e);return new Uint8Array([...Ee,...n])}default:throw new Error(`Exporting polyfilled Ed25519 keys in the "${t}" format is unimplemented`)}}function _e(t,e){let n=at.utils.randomPrivateKey();return Hn(n,t,e)}function St(t){return !!Bt?.has(t)||!!kt?.has(t)}function ve(t,e){if(t.type!=="private"||!t.usages.includes("sign"))throw new DOMException("Unable to use this key to sign","InvalidAccessError");let n=Vt(t),r=Et(e);return at.sign(r,n)}function Ae(t,e,n){if(t.type!=="public"||!t.usages.includes("verify"))throw new DOMException("Unable to use this key to verify","InvalidAccessError");let r=Be(t);try{return at.verify(Et(e),Et(n),r)}catch{return !1}}function Ie(t,e,n,r){let o=Et(e);if(t==="raw"){if(r.some(c=>c==="sign"||Pt.has(c)))throw new DOMException("Unsupported key usage for a Ed25519 key","SyntaxError");if(o.length!==32)throw new DOMException("Ed25519 raw keys must be exactly 32-bytes","DataError");let a={[Symbol.toStringTag]:"CryptoKey",algorithm:Object.freeze({name:"Ed25519"}),extractable:n,type:"public",usages:Object.freeze(r.filter(c=>c==="verify"))};return (kt||(kt=new WeakMap)).set(a,o),a}if(t==="pkcs8"){if(r.some(f=>f==="verify"||Pt.has(f)))throw new DOMException("Unsupported key usage for a Ed25519 key","SyntaxError");if(o.length!==48)throw new DOMException("Invalid keyData","DataError");if(!o.slice(0,16).every((f,i)=>f===Ee[i]))throw new DOMException("Invalid keyData","DataError");let l=o.slice(16),c={[Symbol.toStringTag]:"CryptoKey",algorithm:Object.freeze({name:"Ed25519"}),extractable:n,type:"private",usages:Object.freeze(r.filter(f=>f==="sign"))};return (Bt||(Bt=new WeakMap)).set(c,l),c}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(...f)=>{let[i,d]=f;if(St(d))return Se(...f);if(n)return await n.apply(e,f);throw new TypeError("No native `exportKey` function exists to handle this call")};let r=e.generateKey,o;e.generateKey=async(...f)=>{let[i]=f;if(i!=="Ed25519"){if(r)return await r.apply(e,f);throw new TypeError("No native `generateKey` function exists to handle this call")}let d;if(o===void 0&&(o=new Promise(y=>{if(!r){y(o=!1);return}r.apply(e,f).then(g=>{e.generateKey!==r&&(e.generateKey=r),d=g,y(o=!0);}).catch(()=>{y(o=!1);});})),typeof o=="boolean"?o:await o){if(d)return d;if(r)return await r.apply(e,f);throw new TypeError("No native `generateKey` function exists to handle this call")}else {let[y,g,S]=f;return _e(g,S)}};let a=e.sign;e.sign=async(...f)=>{let[i,d]=f;if(St(d)){let[y,...g]=f;return ve(...g)}else {if(a)return await a.apply(e,f);throw new TypeError("No native `sign` function exists to handle this call")}};let l=e.verify;e.verify=async(...f)=>{let[i,d]=f;if(St(d)){let[y,...g]=f;return Ae(...g)}else {if(l)return await l.apply(e,f);throw new TypeError("No native `verify` function exists to handle this call")}};let c=e.importKey,s;e.importKey=async(...f)=>{let[i,d,y]=f;if(y!=="Ed25519"){if(c)return await c.apply(e,f);throw new TypeError("No native `importKey` function exists to handle this call")}let g;if(s===void 0&&(s=new Promise(S=>{if(!c){S(s=!1);return}c.apply(e,f).then(I=>{e.importKey!==c&&(e.importKey=c),g=I,S(s=!0);}).catch(()=>{S(s=!1);});})),typeof c=="boolean"?s:await s){if(g)return g;if(c)return await c.apply(e,f);throw new TypeError("No native `importKey` function exists to handle this call")}else {let[S,I,A,U,P]=f;return Ie(i,d,U,P)}};}
|
|
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
|
})();
|
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,7 +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
13
|
export declare function importKeyPolyfill(format: KeyFormat, keyData: BufferSource, extractable: boolean, keyUsages: readonly KeyUsage[]): CryptoKey;
|
|
14
14
|
//# sourceMappingURL=secrets.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secrets.d.ts","sourceRoot":"","sources":["../../src/secrets.ts"],"names":[],"mappings":"AAwIA,
|
|
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.76cf6b4",
|
|
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,12 +49,13 @@
|
|
|
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
57
|
"@swc/jest": "^0.2.29",
|
|
57
|
-
"@types/jest": "^29.5.
|
|
58
|
+
"@types/jest": "^29.5.11",
|
|
58
59
|
"@typescript-eslint/eslint-plugin": "^6.7.0",
|
|
59
60
|
"@typescript-eslint/parser": "^6.3.0",
|
|
60
61
|
"eslint": "^8.45.0",
|
|
@@ -64,8 +65,8 @@
|
|
|
64
65
|
"jest-environment-jsdom": "^29.7.0",
|
|
65
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,7 +83,7 @@
|
|
|
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
89
|
"style:fix": "pnpm eslint --fix src/* && pnpm prettier -w src/* package.json",
|