@catena/cli 0.7.0 → 0.9.0
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/README.md +70 -13
- package/THIRD-PARTY-NOTICES +156 -0
- package/dist/dist-w03V0QPF.mjs +3 -0
- package/dist/hmac-CXnNqvhW.mjs +1 -0
- package/dist/index.mjs +449 -316
- package/dist/mpp-CZl4wkkp.mjs +14 -0
- package/dist/{nodecrypto-CIGSbdQh.mjs → nodecrypto-BSdTIm8T.mjs} +1 -1
- package/dist/purejs-xzcexc4T.mjs +15 -0
- package/dist/rolldown-runtime-B0Z9INg1.mjs +1 -0
- package/dist/{utils-DZmc0RJW.mjs → utils-CrMT-n--.mjs} +1 -1
- package/dist/{webcrypto-CRLL4ptE.mjs → webcrypto-BeKbrVgs.mjs} +1 -1
- package/package.json +8 -5
- package/dist/base64-WTSXTrii.mjs +0 -1
- package/dist/dist-B0qgGwAq.mjs +0 -3
- package/dist/purejs-CZxWHjtN.mjs +0 -15
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import{C as e,T as t,_ as n,a as r,c as i,d as a,f as o,h as s,l as c,m as l,o as u,s as d,t as f,u as p,w as m,y as h}from"./dist-w03V0QPF.mjs";import{t as g}from"./hmac-CXnNqvhW.mjs";import{A as _,C as v,D as y,E as b,O as ee,S as x,T as te,_ as S,a as C,b as ne,c as w,d as re,f as ie,g as T,h as ae,i as oe,k as se,l as ce,m as le,n as ue,o as de,p as fe,r as pe,s as me,t as he,u as ge,v as _e,w as ve,x as ye,y as be}from"./index.mjs";import{defineCommand as xe}from"citty";import*as Se from"valibot";const Ce=`2.56.3`;let we={getDocsUrl:({docsBaseUrl:e,docsPath:t=``,docsSlug:n})=>t?`${e??`https://viem.sh`}${t}${n?`#${n}`:``}`:void 0,version:`viem@${Ce}`};var Te=class e extends Error{constructor(t,n={}){let r=n.cause instanceof e?n.cause.details:n.cause?.message?n.cause.message:n.details,i=n.cause instanceof e&&n.cause.docsPath||n.docsPath,a=we.getDocsUrl?.({...n,docsPath:i}),o=[t||`An error occurred.`,``,...n.metaMessages?[...n.metaMessages,``]:[],...a?[`Docs: ${a}`]:[],...r?[`Details: ${r}`]:[],...we.version?[`Version: ${we.version}`]:[]].join(`
|
|
2
|
+
`);super(o,n.cause?{cause:n.cause}:void 0),Object.defineProperty(this,"details",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docsPath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"metaMessages",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"shortMessage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"version",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:`BaseError`}),this.details=r,this.docsPath=i,this.metaMessages=n.metaMessages,this.name=n.name??this.name,this.shortMessage=t,this.version=Ce}walk(e){return Ee(this,e)}};function Ee(e,t){return t?.(e)?e:e&&typeof e==`object`&&`cause`in e&&e.cause!==void 0?Ee(e.cause,t):t?null:e}function De(e,{strict:t=!0}={}){return!e||typeof e!=`string`?!1:t?/^0x[0-9a-fA-F]*$/.test(e):e.startsWith(`0x`)}function Oe(e){return De(e,{strict:!1})?Math.ceil((e.length-2)/2):e.length}var ke=class extends Te{constructor({size:e,targetSize:t,type:n}){super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} size (${e}) exceeds padding size (${t}).`,{name:`SizeExceedsPaddingSizeError`})}};function Ae(e,{dir:t,size:n=32}={}){return typeof e==`string`?je(e,{dir:t,size:n}):Me(e,{dir:t,size:n})}function je(e,{dir:t,size:n=32}={}){if(n===null)return e;let r=e.replace(`0x`,``);if(r.length>n*2)throw new ke({size:Math.ceil(r.length/2),targetSize:n,type:`hex`});return`0x${r[t===`right`?`padEnd`:`padStart`](n*2,`0`)}`}function Me(e,{dir:t,size:n=32}={}){if(n===null)return e;if(e.length>n)throw new ke({size:e.length,targetSize:n,type:`bytes`});let r=new Uint8Array(n);for(let i=0;i<n;i++){let a=t===`right`;r[a?i:n-i-1]=e[a?i:e.length-i-1]}return r}var Ne=class extends Te{constructor({max:e,min:t,signed:n,size:r,value:i}){super(`Number "${i}" is not in safe ${r?`${r*8}-bit ${n?`signed`:`unsigned`} `:``}integer range ${e?`(${t} to ${e})`:`(above ${t})`}`,{name:`IntegerOutOfRangeError`})}},Pe=class extends Te{constructor({givenSize:e,maxSize:t}){super(`Size cannot exceed ${t} bytes. Given size: ${e} bytes.`,{name:`SizeOverflowError`})}};function Fe(e,{size:t}){if(Oe(e)>t)throw new Pe({givenSize:Oe(e),maxSize:t})}const Ie=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`));function Le(e,t={}){return typeof e==`number`||typeof e==`bigint`?Be(e,t):typeof e==`string`?He(e,t):typeof e==`boolean`?Re(e,t):ze(e,t)}function Re(e,t={}){let n=`0x${Number(e)}`;return typeof t.size==`number`?(Fe(n,{size:t.size}),Ae(n,{size:t.size})):n}function ze(e,t={}){let n=``;for(let t=0;t<e.length;t++)n+=Ie[e[t]];let r=`0x${n}`;return typeof t.size==`number`?(Fe(r,{size:t.size}),Ae(r,{dir:`right`,size:t.size})):r}function Be(e,t={}){let{signed:n,size:r}=t,i=BigInt(e),a;r?a=n?(1n<<BigInt(r)*8n-1n)-1n:2n**(BigInt(r)*8n)-1n:typeof e==`number`&&(a=BigInt(2**53-1));let o=typeof a==`bigint`&&n?-a-1n:0;if(a&&i>a||i<o){let t=typeof e==`bigint`?`n`:``;throw new Ne({max:a?`${a}${t}`:void 0,min:`${o}${t}`,signed:n,size:r,value:`${e}${t}`})}let s=`0x${(n&&i<0?(1n<<BigInt(r*8))+BigInt(i):i).toString(16)}`;return r?Ae(s,{size:r}):s}const Ve=new TextEncoder;function He(e,t={}){return ze(Ve.encode(e),t)}const Ue=new TextEncoder;function We(e,t={}){return typeof e==`number`||typeof e==`bigint`?Je(e,t):typeof e==`boolean`?Ge(e,t):De(e)?qe(e,t):Ye(e,t)}function Ge(e,t={}){let n=new Uint8Array(1);return n[0]=Number(e),typeof t.size==`number`?(Fe(n,{size:t.size}),Ae(n,{size:t.size})):n}const E={zero:48,nine:57,A:65,F:70,a:97,f:102};function Ke(e){if(e>=E.zero&&e<=E.nine)return e-E.zero;if(e>=E.A&&e<=E.F)return e-(E.A-10);if(e>=E.a&&e<=E.f)return e-(E.a-10)}function qe(e,t={}){let n=e;t.size&&(Fe(n,{size:t.size}),n=Ae(n,{dir:`right`,size:t.size}));let r=n.slice(2);r.length%2&&(r=`0${r}`);let i=r.length/2,a=new Uint8Array(i);for(let e=0,t=0;e<i;e++){let n=Ke(r.charCodeAt(t++)),i=Ke(r.charCodeAt(t++));if(n===void 0||i===void 0)throw new Te(`Invalid byte sequence ("${r[t-2]}${r[t-1]}" in "${r}").`);a[e]=n*16+i}return a}function Je(e,t){return qe(Be(e,t))}function Ye(e,t={}){let n=Ue.encode(e);return typeof t.size==`number`?(Fe(n,{size:t.size}),Ae(n,{dir:`right`,size:t.size})):n}const Xe=BigInt(0),Ze=BigInt(1),Qe=BigInt(2),$e=BigInt(7),et=BigInt(256),tt=BigInt(113),nt=[],rt=[],it=[];for(let e=0,t=Ze,n=1,r=0;e<24;e++){[n,r]=[r,(2*n+3*r)%5],nt.push(2*(5*r+n)),rt.push((e+1)*(e+2)/2%64);let i=Xe;for(let e=0;e<7;e++)t=(t<<Ze^(t>>$e)*tt)%et,t&Qe&&(i^=Ze<<(Ze<<BigInt(e))-Ze);it.push(i)}const at=c(it,!0),ot=at[0],st=at[1],ct=(e,t,n)=>n>32?r(e,t,n):d(e,t,n),lt=(e,t,n)=>n>32?u(e,t,n):i(e,t,n);function ut(e,t=24){let r=new Uint32Array(10);for(let n=24-t;n<24;n++){for(let t=0;t<10;t++)r[t]=e[t]^e[t+10]^e[t+20]^e[t+30]^e[t+40];for(let t=0;t<10;t+=2){let n=(t+8)%10,i=(t+2)%10,a=r[i],o=r[i+1],s=ct(a,o,1)^r[n],c=lt(a,o,1)^r[n+1];for(let n=0;n<50;n+=10)e[t+n]^=s,e[t+n+1]^=c}let t=e[2],i=e[3];for(let n=0;n<24;n++){let r=rt[n],a=ct(t,i,r),o=lt(t,i,r),s=nt[n];t=e[s],i=e[s+1],e[s]=a,e[s+1]=o}for(let t=0;t<50;t+=10){for(let n=0;n<10;n++)r[n]=e[t+n];for(let n=0;n<10;n++)e[t+n]^=~r[(n+2)%10]&r[(n+4)%10]}e[0]^=ot[n],e[1]^=st[n]}n(r)}var dt=class r extends p{constructor(e,n,r,i=!1,a=24){if(super(),this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,this.enableXOF=!1,this.blockLen=e,this.suffix=n,this.outputLen=r,this.enableXOF=i,this.rounds=a,l(r),!(0<e&&e<200))throw Error(`only keccak-f1600 function is supported`);this.state=new Uint8Array(200),this.state32=t(this.state)}clone(){return this._cloneInto()}keccak(){e(this.state32),ut(this.state32,this.rounds),e(this.state32),this.posOut=0,this.pos=0}update(e){o(this),e=m(e),a(e);let{blockLen:t,state:n}=this,r=e.length;for(let i=0;i<r;){let a=Math.min(t-this.pos,r-i);for(let t=0;t<a;t++)n[this.pos++]^=e[i++];this.pos===t&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;let{state:e,suffix:t,pos:n,blockLen:r}=this;e[n]^=t,t&128&&n===r-1&&this.keccak(),e[r-1]^=128,this.keccak()}writeInto(e){o(this,!1),a(e),this.finish();let t=this.state,{blockLen:n}=this;for(let r=0,i=e.length;r<i;){this.posOut>=n&&this.keccak();let a=Math.min(n-this.posOut,i-r);e.set(t.subarray(this.posOut,this.posOut+a),r),this.posOut+=a,r+=a}return e}xofInto(e){if(!this.enableXOF)throw Error(`XOF is not possible for this instance`);return this.writeInto(e)}xof(e){return l(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(s(e,this),this.finished)throw Error(`digest() was already called`);return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,n(this.state)}_cloneInto(e){let{blockLen:t,suffix:n,outputLen:i,rounds:a,enableXOF:o}=this;return e||=new r(t,n,i,o,a),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=a,e.suffix=n,e.outputLen=i,e.enableXOF=o,e.destroyed=this.destroyed,e}};const ft=((e,t,n)=>h(()=>new dt(t,e,n)))(1,136,32);function pt(e,t){let n=t||`hex`,r=ft(De(e,{strict:!1})?We(e):e);return n===`bytes`?r:Le(r)}var mt=class extends Map{constructor(e){super(),Object.defineProperty(this,"maxSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.maxSize=e}get(e){let t=super.get(e);return super.has(e)&&(super.delete(e),super.set(e,t)),t}set(e,t){if(super.has(e)&&super.delete(e),super.set(e,t),this.maxSize&&this.size>this.maxSize){let e=super.keys().next().value;e!==void 0&&super.delete(e)}return this}};const ht=/^0x[a-fA-F0-9]{40}$/,gt=new mt(8192);function _t(e,t){let{strict:n=!0}=t??{},r=`${e}.${n}`;if(gt.has(r))return gt.get(r);let i=ht.test(e)?e.toLowerCase()===e||!n||yt(e)===e:!1;return gt.set(r,i),i}const vt=new mt(8192);function yt(e,t){if(vt.has(`${e}.${t}`))return vt.get(`${e}.${t}`);let n=t?`${t}${e.toLowerCase()}`:e.substring(2).toLowerCase(),r=pt(Ye(n),`bytes`),i=(t?n.substring(`${t}0x`.length):n).split(``);for(let e=0;e<40;e+=2)r[e>>1]>>4>=8&&i[e]&&(i[e]=i[e].toUpperCase()),(r[e>>1]&15)>=8&&i[e+1]&&(i[e+1]=i[e+1].toUpperCase());let a=`0x${i.join(``)}`;return vt.set(`${e}.${t}`,a),a}function bt(){return`0.1.1`}var D=class e extends Error{static setStaticOptions(t){e.prototype.docsOrigin=t.docsOrigin,e.prototype.showVersion=t.showVersion,e.prototype.version=t.version}constructor(t,n={}){let r=(()=>{if(n.cause instanceof e){if(n.cause.details)return n.cause.details;if(n.cause.shortMessage)return n.cause.shortMessage}return n.cause&&`details`in n.cause&&typeof n.cause.details==`string`?n.cause.details:n.cause?.message?n.cause.message:n.details})(),i=n.cause instanceof e&&n.cause.docsPath||n.docsPath,a=n.docsOrigin??e.prototype.docsOrigin,o=`${a}${i??``}`,s=!!(n.version??e.prototype.showVersion),c=n.version??e.prototype.version,l=[t||`An error occurred.`,...n.metaMessages?[``,...n.metaMessages]:[],...r||i||s?[``,r?`Details: ${r}`:void 0,i?`See: ${o}`:void 0,s?`Version: ${c}`:void 0]:[]].filter(e=>typeof e==`string`).join(`
|
|
3
|
+
`);super(l,n.cause?{cause:n.cause}:void 0),Object.defineProperty(this,"details",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docs",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docsOrigin",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docsPath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"shortMessage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"showVersion",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"version",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"cause",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:`BaseError`}),this.cause=n.cause,this.details=r,this.docs=o,this.docsOrigin=a,this.docsPath=i,this.shortMessage=t,this.showVersion=s,this.version=c}walk(e){return xt(this,e)}};Object.defineProperty(D,"defaultStaticOptions",{enumerable:!0,configurable:!0,writable:!0,value:{docsOrigin:`https://oxlib.sh`,showVersion:!1,version:`ox@${bt()}`}}),D.setStaticOptions(D.defaultStaticOptions);function xt(e,t){return t?.(e)?e:e&&typeof e==`object`&&`cause`in e&&e.cause?xt(e.cause,t):t?null:e}function St(e,t){if(Ht(e)>t)throw new Gt({givenSize:Ht(e),maxSize:t})}const O={zero:48,nine:57,A:65,F:70,a:97,f:102};function Ct(e){if(e>=O.zero&&e<=O.nine)return e-O.zero;if(e>=O.A&&e<=O.F)return e-(O.A-10);if(e>=O.a&&e<=O.f)return e-(O.a-10)}function wt(e,t={}){let{dir:n,size:r=32}=t;if(r===0)return e;if(e.length>r)throw new Kt({size:e.length,targetSize:r,type:`Bytes`});let i=new Uint8Array(r);for(let t=0;t<r;t++){let a=n===`right`;i[a?t:r-t-1]=e[a?t:e.length-t-1]}return i}function Tt(e,t={}){let{dir:n=`left`}=t,r=e,i=0;for(let e=0;e<r.length-1&&r[n===`left`?e:r.length-e-1].toString()===`0`;e++)i++;return r=n===`left`?r.slice(i):r.slice(0,r.length-i),r}function Et(e,t){if(Mt(e)>t)throw new Nt({givenSize:Mt(e),maxSize:t})}function Dt(e,t={}){let{dir:n,size:r=32}=t;if(r===0)return e;let i=e.replace(`0x`,``);if(i.length>r*2)throw new Pt({size:Math.ceil(i.length/2),targetSize:r,type:`Hex`});return`0x${i[n===`right`?`padEnd`:`padStart`](r*2,`0`)}`}function Ot(e){if(e===null||typeof e==`boolean`||typeof e==`string`)return JSON.stringify(e);if(typeof e==`number`){if(!Number.isFinite(e))throw TypeError(`Cannot canonicalize non-finite number`);return Object.is(e,-0)?`0`:JSON.stringify(e)}if(typeof e==`bigint`)throw TypeError(`Cannot canonicalize bigint`);if(Array.isArray(e))return`[${e.map(e=>Ot(e)).join(`,`)}]`;if(typeof e==`object`)return`{${Object.keys(e).sort().reduce((t,n)=>{let r=e[n];return r!==void 0&&t.push(`${JSON.stringify(n)}:${Ot(r)}`),t},[]).join(`,`)}}`}const kt=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`));function At(e,t={}){let n=``;for(let t=0;t<e.length;t++)n+=kt[e[t]];let r=`0x${n}`;return typeof t.size==`number`?(Et(r,t.size),jt(r,t.size)):r}function jt(e,t){return Dt(e,{dir:`right`,size:t})}function Mt(e){return Math.ceil((e.length-2)/2)}var Nt=class extends D{constructor({givenSize:e,maxSize:t}){super(`Size cannot exceed \`${t}\` bytes. Given size: \`${e}\` bytes.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:`Hex.SizeOverflowError`})}},Pt=class extends D{constructor({size:e,targetSize:t,type:n}){super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} size (\`${e}\`) exceeds padding size (\`${t}\`).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:`Hex.SizeExceedsPaddingSizeError`})}};const Ft=new TextDecoder,It=new TextEncoder;function Lt(e){return e instanceof Uint8Array?e:typeof e==`string`?zt(e):Rt(e)}function Rt(e){return e instanceof Uint8Array?e:new Uint8Array(e)}function zt(e,t={}){let{size:n}=t,r=e;n&&(Et(e,n),r=jt(e,n));let i=r.slice(2);i.length%2&&(i=`0${i}`);let a=i.length/2,o=new Uint8Array(a);for(let e=0,t=0;e<a;e++){let n=Ct(i.charCodeAt(t++)),r=Ct(i.charCodeAt(t++));if(n===void 0||r===void 0)throw new D(`Invalid byte sequence ("${i[t-2]}${i[t-1]}" in "${i}").`);o[e]=n<<4|r}return o}function Bt(e,t={}){let{size:n}=t,r=It.encode(e);return typeof n==`number`?(St(r,n),Vt(r,n)):r}function Vt(e,t){return wt(e,{dir:`right`,size:t})}function Ht(e){return e.length}function Ut(e,t={}){let{size:n}=t,r=e;return n!==void 0&&(St(r,n),r=Wt(r)),Ft.decode(r)}function Wt(e){return Tt(e,{dir:`right`})}var Gt=class extends D{constructor({givenSize:e,maxSize:t}){super(`Size cannot exceed \`${t}\` bytes. Given size: \`${e}\` bytes.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:`Bytes.SizeOverflowError`})}},Kt=class extends D{constructor({size:e,targetSize:t,type:n}){super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} size (\`${e}\`) exceeds padding size (\`${t}\`).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:`Bytes.SizeExceedsPaddingSizeError`})}};function qt(e,t,n={}){let{as:r=typeof t==`string`?`Hex`:`Bytes`}=n,i=g(f,Lt(e),Lt(t));return r===`Bytes`?i:At(i)}const Jt=new TextEncoder,Yt=new TextDecoder,Xt=Object.fromEntries(Array.from(`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`).map((e,t)=>[t,e.charCodeAt(0)])),Zt={...Object.fromEntries(Array.from(`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`).map((e,t)=>[e.charCodeAt(0),t])),61:0,45:62,95:63};function Qt(e,t={}){let{pad:n=!0,url:r=!1}=t,i=new Uint8Array(Math.ceil(e.length/3)*4);for(let t=0,n=0;n<e.length;t+=4,n+=3){let r=(e[n]<<16)+(e[n+1]<<8)+(e[n+2]|0);i[t]=Xt[r>>18],i[t+1]=Xt[r>>12&63],i[t+2]=Xt[r>>6&63],i[t+3]=Xt[r&63]}let a=e.length%3,o=Math.floor(e.length/3)*4+(a&&a+1),s=Yt.decode(new Uint8Array(i.buffer,0,o));return n&&a===1&&(s+=`==`),n&&a===2&&(s+=`=`),r&&(s=s.replaceAll(`+`,`-`).replaceAll(`/`,`_`)),s}function $t(e,t={}){return Qt(Bt(e),t)}function en(e){let t=e.replace(/=+$/,``),n=t.length,r=new Uint8Array(n+3);Jt.encodeInto(t+`===`,r);for(let e=0,n=0;e<t.length;e+=4,n+=3){let t=(Zt[r[e]]<<18)+(Zt[r[e+1]]<<12)+(Zt[r[e+2]]<<6)+Zt[r[e+3]];r[n]=t>>16,r[n+1]=t>>8&255,r[n+2]=t&255}let i=(n>>2)*3+(n%4&&n%4-1);return new Uint8Array(r.buffer,0,i)}function tn(e){return Ut(en(e))}const k={acceptPayment:`Accept-Payment`,authorization:`Authorization`,paymentAuthorization:`Payment-Authorization`,paymentReceipt:`Payment-Receipt`,paymentSession:`Payment-Session`,paymentSessionSnapshot:`Payment-Session-Snapshot`,wwwAuthenticate:`WWW-Authenticate`},nn={payment:`Payment`};function rn(e){let t=tn(e);return JSON.parse(t)}function A(e){return $t(Ot(e),{pad:!1,url:!0})}function an(e){let t=Object.values(e).filter(e=>typeof e==`number`);return Object.entries(e).filter(([e,n])=>t.indexOf(+e)===-1).map(([e,t])=>t)}function on(e,t){return typeof t==`bigint`?t.toString():t}function sn(e){return{get value(){{let t=e();return Object.defineProperty(this,"value",{value:t}),t}}}}function cn(e){return e==null}function ln(e){let t=+!!e.startsWith(`^`),n=e.endsWith(`$`)?e.length-1:e.length;return e.slice(t,n)}function un(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}const dn=`captureStackTrace`in Error?Error.captureStackTrace:(...e)=>{};function fn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function pn(e){if(fn(e)===!1)return!1;let t=e.constructor;if(t===void 0||typeof t!=`function`)return!0;let n=t.prototype;return fn(n)!==!1&&Object.prototype.hasOwnProperty.call(n,`isPrototypeOf`)!==!1}const mn=new Set([`string`,`number`,`symbol`]);function hn(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function gn(e,t,n){let r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function j(e){let t=e;if(!t)return{};if(typeof t==`string`)return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error==`string`?{...t,error:()=>t.error}:t}function _n(e){return Object.keys(e).filter(t=>e[t]._zod.optin!==void 0&&e[t]._zod.optout===`optional`)}function vn(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue!==!0)return!0;return!1}function yn(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue===!1)return!0;return!1}function M(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function bn(e){return typeof e==`string`?e:e?.message}function xn(e,t,n){var r;for(let i=t;i<e.length;i++)(r=e[i]).schema??(r.schema=n)}function N(e,t,n){var r;let i=e.inst?._zod?.traits;i?.has(`$ZodType`)&&(i.has(`$ZodCheck`)?(r=e).schema??(r.schema=e.inst):e.schema=e.inst);let a=e.schema===e.inst?void 0:e.schema?._zod.def?.error,o=e.message?e.message:bn(e.inst?._zod.def?.error?.(e))??bn(a?.(e))??bn(t?.error?.(e))??bn(n.customError?.(e))??bn(n.localeError?.(e))??`Invalid input`,{inst:s,schema:c,continue:l,input:u,...d}=e;return d.path??=[],d.message=o,t?.reportInput&&(d.input=u),d}const Sn=/[\uD800-\uDBFF]/;function Cn(e){let t=e.length;if(!Sn.test(e))return t;let n=t;for(let r=0;r<t-1;r++)(e.charCodeAt(r)&64512)==55296&&(e.charCodeAt(r+1)&64512)==56320&&(n--,r++);return n}function wn(e){return Array.isArray(e)?`array`:typeof e==`string`?`string`:`unknown`}function Tn(...e){let[t,n,r]=e;return typeof t==`string`?{message:t,code:`custom`,input:n,inst:r}:{...t}}function En(e,t){for(let n in t){let r=Object.getOwnPropertyDescriptor(t,n);r.get?Object.defineProperty(e,n,{...r,enumerable:!1}):kn(e,n,r.value)}}function Dn(e,t,n,r=!0){return Object.defineProperty(e,t,{configurable:!0,writable:!0,enumerable:r,value:n}),n}function On(e,t,n){return Dn(e,t,n,!1)}function kn(e,t,n){Object.defineProperty(e,t,{configurable:!0,get(){return this==null?n:Dn(this,t,n.bind(this))},set(e){Dn(this,t,e)}})}function An(e,t){let n=Object.getPrototypeOf(e);return t in n?void 0:n}let jn,P=!1;const Mn={configurable:!0,get(){P=!0}};function F(e,t,n){let r=Object.getPrototypeOf(e._zod);if(t in r&&jn!==e._zod){jn=void 0;return}jn=e._zod,Object.defineProperty(r,t,{configurable:!0,get(){Object.defineProperty(this,t,Mn);let e=P;P=!1;try{let r=n(this);return P?delete this[t]:Object.defineProperty(this,t,{configurable:!0,writable:!0,value:r}),P||=e,r}catch(n){throw delete this[t],P||=e,n}},set(e){Object.defineProperty(this,t,{configurable:!0,writable:!0,value:e})}})}function Nn(e,t,n,r){let i=An(e,t);i&&Object.defineProperty(i,t,{configurable:!0,get(){let e={configurable:!0,writable:!0,enumerable:r,value:void 0};return Object.defineProperty(this,t,e),e.value=n(this),Object.defineProperty(this,t,e),e.value},set(e){Object.defineProperty(this,t,{configurable:!0,writable:!0,enumerable:r,value:e})}})}var Pn;const Fn={value:void 0,enumerable:!1};let In=`captureStackTrace`in Error?Error:null;function Ln(e){let t=In;if(t){let n=t.stackTraceLimit;if(typeof n==`number`){try{t.stackTraceLimit=0}catch{return In=null,new e}try{return new e}finally{t.stackTraceLimit=n}}}return new e}function I(e,t,n,r){let i={};function a(e){this.def=e,this.constr=d,this.traits=new Set}a.prototype=i;let o=n,s=o&&new WeakSet;function c(n,r){if(!n._zod){Fn.value=new a(r);try{Object.defineProperty(n,"_zod",Fn)}finally{Fn.value=void 0}}if(n._zod.traits.has(e))return;if(n._zod.traits.add(e),t(n,r),s){let e=Object.getPrototypeOf(n),t=n._zod.constr.prototype,r=e;for(;r&&r!==t;)r=Object.getPrototypeOf(r);let i=r??e;s.has(i)||(s.add(i),En(i,o))}let i=d.prototype;for(let e in i)Object.prototype.hasOwnProperty.call(i,e)&&(e in n||(n[e]=i[e].bind(n)))}let l=r?.Parent??Object;class u extends l{}Object.defineProperty(u,"name",{value:e});function d(e){let t=r?.Parent?Ln(u):this;c(t,e);let n=t._zod.deferred;if(n){for(let e of n)e();t._zod.deferred=void 0}let i=globalThis.__zod_globalConfig?.postProcessor;return i&&i(t),t}return Object.defineProperty(d,"init",{value:c}),Object.defineProperty(d,Symbol.hasInstance,{value:t=>r?.Parent&&t instanceof r.Parent?!0:t?._zod?.traits?.has(e)}),Object.defineProperty(d,"name",{value:e}),d}var Rn=class extends Error{constructor(){super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`)}};(Pn=globalThis).__zod_globalConfig??(Pn.__zod_globalConfig={});const zn=globalThis.__zod_globalConfig;function L(e){return e&&Object.assign(zn,e),zn}function Bn(){let e=this._zod;return e.message??=JSON.stringify(e.def,on,2),e.message}function Vn(e){this._zod.message=e}const Hn={get:Bn,set:Vn,enumerable:!0,configurable:!0},Un={value:void 0,enumerable:!1},Wn={value:void 0,enumerable:!1},Gn=new WeakSet([Object.prototype,Error.prototype]),Kn=(e,t)=>{e.name=`$ZodError`,Un.value=e._zod,Object.defineProperty(e,"_zod",Un),Wn.value=t,Object.defineProperty(e,"issues",Wn),Un.value=void 0,Wn.value=void 0,Object.defineProperty(e,"message",Hn);let n=Object.getPrototypeOf(e);Gn.has(n)||(Gn.add(n),Object.defineProperty(n,"toString",{configurable:!0,enumerable:!1,get(){let e=()=>this.message;return Object.defineProperty(this,"toString",{value:e,configurable:!0,writable:!0}),e},set(e){Object.defineProperty(this,"toString",{value:e,configurable:!0,writable:!0})}}))},qn=I(`$ZodError`,Kn),Jn=I(`$ZodError`,Kn,void 0,{Parent:Error}),Yn=(e=>{let t=(n,r,i,a)=>{let o=i?{...i,async:!1}:{async:!1},s=n._zod.run({value:r,issues:[]},o);if(s instanceof Promise)throw new Rn;if(s.issues.length){let n=new((a?.Err)??e)(s.issues.map(e=>N(e,o,L())));throw dn(n,a?.callee??t),n}return s.value};return t})(Jn),Xn=(e=>{let t=async(n,r,i,a)=>{let o=i?{...i,async:!0}:{async:!0},s=n._zod.run({value:r,issues:[]},o);if(s instanceof Promise&&(s=await s),s.issues.length){let n=new((a?.Err)??e)(s.issues.map(e=>N(e,o,L())));throw dn(n,a?.callee??t),n}return s.value};return t})(Jn),Zn=(e=>(t,n,r)=>{let i=r?{...r,async:!1}:{async:!1},a=t._zod.run({value:n,issues:[]},i);if(a instanceof Promise)throw new Rn;return a.issues.length?{success:!1,error:new(e??qn)(a.issues.map(e=>N(e,i,L())))}:{success:!0,data:a.value}})(Jn),Qn=(e=>async(t,n,r)=>{let i=r?{...r,async:!0}:{async:!0},a=t._zod.run({value:n,issues:[]},i);return a instanceof Promise&&(a=await a),a.issues.length?{success:!1,error:new e(a.issues.map(e=>N(e,i,L())))}:{success:!0,data:a.value}})(Jn),$n=e=>{let t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??``}}`:`[\\s\\S]*`;return RegExp(`^${t}$`)},er=/^-?\d+(?:\.\d+)?$/,tr=/^(?:true|false)$/i,nr=I(`$ZodCheck`,(e,t)=>{var n;e._zod??={},e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),rr=e=>{let t=e.value;return!cn(t)&&t.length!==void 0},ir=I(`$ZodCheckMinLength`,(e,t)=>{var n;nr.init(e,t),(n=e._zod.def).when??(n.when=rr),e._zod.onattach.push(e=>{let n=e._zod.bag.minimum??-1/0;t.minimum>n&&(e._zod.bag.minimum=t.minimum)}),e._zod.check=n=>{let r=n.value,i=r.length;if((typeof r==`string`&&i>=t.minimum&&i<t.minimum*2?Cn(r):i)>=t.minimum)return;let a=wn(r);n.issues.push({origin:a,code:`too_small`,minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),ar=I(`$ZodCheckStringFormat`,(e,t)=>{var n,r;nr.init(e,t),e._zod.onattach.push(e=>{let n=e._zod.bag;n.format=t.format,t.pattern&&(n.patterns??=new Set,n.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:t.format,input:n.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),or=I(`$ZodCheckRegex`,(e,t)=>{ar.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:`regex`,input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),sr={major:4,minor:5,patch:4},R=I(`$ZodType`,(e,t)=>{var n;e??={},e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=sr;let r=e._zod.def.checks,i=e._zod.traits.has(`$ZodCheck`)?[e,...r??[]]:r?.length?[...r]:[];for(let t of i)for(let n of t._zod.onattach)n(e);if(i.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{let t=(t,n,r)=>{if(t.memo)return t;let i=vn(t),a;for(let o of n){if(o._zod.def.when){if(yn(t)||!o._zod.def.when(t))continue}else if(i)continue;let n=t.issues.length,s=o._zod.check(t);if(s instanceof Promise&&r?.async===!1)throw new Rn;if(a||s instanceof Promise)a=(a??Promise.resolve()).then(async()=>{await s,t.issues.length!==n&&(xn(t.issues,n,e),i||=vn(t,n))});else{if(t.issues.length===n)continue;xn(t.issues,n,e),i||=vn(t,n)}}return a?a.then(()=>t):t},n=(n,r,a)=>{if(vn(n))return n.aborted=!0,n;let o=t(r,i,a);if(o instanceof Promise){if(a.async===!1)throw new Rn;return o.then(t=>e._zod.parse(t,a))}return e._zod.parse(o,a)};e._zod.run=(r,a)=>{if(a.skipChecks)return e._zod.parse(r,a);if(a.direction===`backward`){let t=e._zod.parse({value:r.value,issues:[]},{...a,skipChecks:!0});return t instanceof Promise?t.then(e=>n(e,r,a)):n(t,r,a)}let o=e._zod.parse(r,a);if(o instanceof Promise){if(a.async===!1)throw new Rn;return o.then(e=>t(e,i,a))}return t(o,i,a)}}},{get"~standard"(){return On(this,`~standard`,lr(this))},set"~standard"(e){Dn(this,`~standard`,e)}}),cr=e=>e.success?{value:e.data}:{issues:e.error?.issues};function lr(e){return{validate:t=>{try{return cr(Zn(e,t))}catch{return Qn(e,t).then(cr)}},vendor:`zod`,version:1}}const ur=I(`$ZodString`,(e,t)=>{R.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??$n(e._zod.bag),e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=String(n.value)}catch{}return typeof n.value==`string`||n.issues.push({expected:`string`,code:`invalid_type`,input:n.value,inst:e}),n}}),dr=I(`$ZodNumber`,(e,t)=>{R.init(e,t),e._zod.pattern=e._zod.bag.pattern??er,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch{}let i=n.value;if(typeof i==`number`&&!Number.isNaN(i)&&Number.isFinite(i))return n;let a=typeof i==`number`?Number.isNaN(i)?`NaN`:Number.isFinite(i)?void 0:String(i):void 0;return n.issues.push({expected:`number`,code:`invalid_type`,input:i,inst:e,...a?{received:a}:{}}),n}}),fr=I(`$ZodBoolean`,(e,t)=>{R.init(e,t),e._zod.pattern=tr,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=!!n.value}catch{}let i=n.value;return typeof i==`boolean`||n.issues.push({expected:`boolean`,code:`invalid_type`,input:i,inst:e}),n}}),pr=I(`$ZodUnknown`,(e,t)=>{R.init(e,t),e._zod.parse=e=>e}),mr=I(`$ZodNever`,(e,t)=>{R.init(e,t),e._zod.parse=(t,n)=>(t.issues.push({expected:`never`,code:`invalid_type`,input:t.value,inst:e}),t)});function hr(e,t,n){e.issues.length&&t.issues.push(...M(n,e.issues)),t.value[n]=e.value}const gr=I(`$ZodArray`,(e,t)=>{R.init(e,t);let n=zn.memoizer;n?.attach(e),e._zod.parse=(r,i)=>{let a=r.value;if(!Array.isArray(a))return r.issues.push({expected:`array`,code:`invalid_type`,input:a,inst:e}),r;r.value=n?n.alloc(e,r,Array(a.length),i):Array(a.length);let o=[];for(let e=0;e<a.length;e++){let n=a[e],s=t.element._zod.run({value:n,issues:[]},i);s instanceof Promise?o.push(s.then(t=>hr(t,r,e))):hr(s,r,e)}return o.length?Promise.all(o).then(()=>r):r}});function _r(e,t,n,r,i,a){let o=n in r,s=a===`optional`;if(o||!s||i!==`optional`){if(e.issues.length){if(i!==void 0&&s&&!o)return;t.issues.push(...M(n,e.issues))}if(!o&&i===void 0){e.issues.length||t.issues.push({code:`invalid_type`,expected:`nonoptional`,input:void 0,path:[n]});return}e.value===void 0?o&&(t.value[n]=void 0):t.value[n]=e.value}}const vr=[];function yr(e){let t=Object.keys(e.shape),n=Object.getOwnPropertySymbols(e.shape),r=n.length?n:vr,i=r.length?[...t,...r]:t;for(let t of i)if(!e.shape?.[t]?._zod?.traits?.has(`$ZodType`))throw Error(`Invalid element at key "${String(t)}": expected a Zod schema`);let a=_n(e.shape);return{...e,allKeys:i,symbolKeys:r,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(a)}}function br(e,t,n,r,i,a){let o=[],s=i.keySet,c=i.catchall._zod,l=c.def.type,u=c.optin,d=c.optout;for(let i in t){if(s.has(i))continue;if(i===`__proto__`){l===`never`&&o.push(i);continue}if(l===`never`){o.push(i);continue}let a=c.run({value:t[i],issues:[]},r);a instanceof Promise?e.push(a.then(e=>_r(e,n,i,t,u,d))):_r(a,n,i,t,u,d)}return o.length&&n.issues.push({code:`unrecognized_keys`,keys:o,input:t,inst:a,continue:!0}),e.length?Promise.all(e).then(()=>n):n}const xr=new WeakMap,Sr=I(`$ZodObject`,(e,t)=>{if(R.init(e,t),!Object.getOwnPropertyDescriptor(t,`shape`)?.get){let e=t.shape;xr.set(t,e),Object.defineProperty(t,"shape",{get:()=>{let n={...e};return Object.defineProperty(t,"shape",{value:n}),xr.set(t,n),n}})}let n=sn(()=>yr(t));F(e,`propValues`,e=>{let t=e.def.shape,n={};for(let e in t){let r=t[e]._zod;if(r.values){Object.prototype.hasOwnProperty.call(n,e)||un(n,e,new Set);for(let t of r.values)n[e].add(t);r.optin!==void 0&&n[e].add(void 0)}}return n});let r=fn,i=t.catchall,a,o=zn.memoizer;o?.attach(e),e._zod.parse=(t,s)=>{a??=n.value;let c=t.value;if(!r(c))return t.issues.push({expected:`object`,code:`invalid_type`,input:c,inst:e}),t;t.value=o?o.alloc(e,t,{},s):{};let l=[],u=a.shape;for(let e of a.allKeys){if(e===`__proto__`)continue;let n=u[e],r=n._zod.optin,i=n._zod.optout,a=n._zod.run({value:c[e],issues:[]},s);a instanceof Promise?l.push(a.then(n=>_r(n,t,e,c,r,i))):_r(a,t,e,c,r,i)}return i?br(l,c,t,s,n.value,e):l.length?Promise.all(l).then(()=>t):t}});function Cr(e,t,n,r){for(let n of e)if(n.issues.length===0)return t.value=n.value,t;let i=e.filter(e=>!vn(e));return i.length===1?(t.value=i[0].value,i[0]):(t.issues.push({code:`invalid_union`,input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>N(e,r,L())))}),t)}const wr=I(`$ZodUnion`,(e,t)=>{R.init(e,t),F(e,`optin`,e=>e.def.options.some(e=>e._zod.optin===`defaulted`)?`defaulted`:e.def.options.some(e=>e._zod.optin!==void 0)?`optional`:void 0),F(e,`optout`,e=>e.def.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),F(e,`values`,e=>{if(e.def.options.every(e=>e._zod.values))return new Set(e.def.options.flatMap(e=>Array.from(e._zod.values)))}),F(e,`pattern`,e=>{if(e.def.options.every(e=>e._zod.pattern)){let t=e.def.options.map(e=>e._zod.pattern);return RegExp(`^(${t.map(e=>ln(e.source)).join(`|`)})$`)}});let n=t.options.length===1?t.options[0]._zod.run:null;e._zod.parse=(r,i)=>{if(n)return n(r,i);let a=!1,o=[];for(let e of t.options){let t=e._zod.run({value:r.value,issues:[]},i);if(t instanceof Promise)o.push(t),a=!0;else{if(t.issues.length===0)return t;o.push(t)}}return a?Promise.all(o).then(t=>Cr(t,r,e,i)):Cr(o,r,e,i)}}),Tr=I(`$ZodRecord`,(e,t)=>{R.init(e,t);let n=zn.memoizer;n?.attach(e),e._zod.parse=(r,i)=>{let a=r.value;if(!pn(a))return r.issues.push({expected:`record`,code:`invalid_type`,input:a,inst:e}),r;let o=[],s=t.keyType._zod.values;if(s&&!t.partial){r.value=n?n.alloc(e,r,{},i):{};let c=new Set;for(let n of s)if(typeof n==`string`||typeof n==`number`||typeof n==`symbol`){if(c.add(typeof n==`number`?n.toString():n),n===`__proto__`)continue;let s=t.keyType._zod.run({value:n,issues:[]},i);if(s instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(s.issues.length){r.issues.push({code:`invalid_key`,origin:`record`,issues:s.issues.map(e=>N(e,i,L())),input:n,path:[n],inst:e});continue}let l=s.value;if(l===`__proto__`)continue;let u=t.valueType._zod.run({value:a[n],issues:[]},i);u instanceof Promise?o.push(u.then(e=>{e.issues.length&&r.issues.push(...M(n,e.issues)),r.value[l]=e.value})):(u.issues.length&&r.issues.push(...M(n,u.issues)),r.value[l]=u.value)}let l;for(let e in a)if(!c.has(e)){if(t.mode===`loose`){if(e===`__proto__`)continue;r.value[e]=a[e]}else l??=[],l.push(e)}l&&l.length>0&&r.issues.push({code:`unrecognized_keys`,input:a,inst:e,keys:l,continue:!0})}else{r.value=n?n.alloc(e,r,{},i):{};let c;for(let n of Reflect.ownKeys(a)){if(n===`__proto__`||!Object.prototype.propertyIsEnumerable.call(a,n))continue;let l=t.keyType._zod.run({value:n,issues:[]},i);if(l instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(typeof n==`string`&&er.test(n)&&l.issues.length){let e=t.keyType._zod.run({value:Number(n),issues:[]},i);if(e instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);e.issues.length===0&&(l=e)}if(l.issues.length){t.mode===`loose`?r.value[n]=a[n]:s?(c??=[],c.push(n)):r.issues.push({code:`invalid_key`,origin:`record`,issues:l.issues.map(e=>N(e,i,L())),input:n,path:[n],inst:e});continue}let u=l.value;if(u===`__proto__`)continue;let d=t.valueType._zod.run({value:a[n],issues:[]},i);d instanceof Promise?o.push(d.then(e=>{e.issues.length&&r.issues.push(...M(n,e.issues)),r.value[u]=e.value})):(d.issues.length&&r.issues.push(...M(n,d.issues)),r.value[u]=d.value)}c&&c.length>0&&r.issues.push({code:`unrecognized_keys`,input:a,inst:e,keys:c,continue:!0})}return o.length?Promise.all(o).then(()=>r):r}}),Er=I(`$ZodEnum`,(e,t)=>{R.init(e,t);let n=an(t.entries),r=new Set(n);e._zod.values=r;let i=n.filter(e=>mn.has(typeof e));e._zod.pattern=RegExp(i.length?`^(${i.map(e=>hn(e.toString())).join(`|`)})$`:`^[^\\s\\S]$`),e._zod.parse=(t,i)=>{let a=t.value;return r.has(a)||t.issues.push({code:`invalid_value`,values:n,input:a,inst:e}),t}}),Dr=I(`$ZodLiteral`,(e,t)=>{R.init(e,t);let n=new Set(t.values);e._zod.values=n,e._zod.pattern=RegExp(t.values.length?`^(${t.values.map(e=>typeof e==`string`?hn(e):e?hn(e.toString()):String(e)).join(`|`)})$`:`^[^\\s\\S]$`),e._zod.parse=(r,i)=>{let a=r.value;return n.has(a)||r.issues.push({code:`invalid_value`,values:t.values,input:a,inst:e}),r}});function Or(e,t){return e.value=t.issues.length?void 0:t.value,e}const kr=I(`$ZodOptional`,(e,t)=>{R.init(e,t),F(e,`optin`,e=>e.def.innerType._zod.optin===`defaulted`?`defaulted`:`optional`),e._zod.optout=`optional`,F(e,`values`,e=>{let t=e.def.innerType._zod.values;return t?new Set([...t,void 0]):void 0}),F(e,`pattern`,e=>{let t=e.def.innerType._zod.pattern;return t?RegExp(`^(${ln(t.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if(e.value===void 0){if(t.innerType._zod.optin!==`defaulted`)return e;let r=t.innerType._zod.run({value:e.value,issues:[]},n);return r instanceof Promise?r.then(t=>Or(e,t)):Or(e,r)}return t.innerType._zod.run(e,n)}}),Ar=I(`$ZodCustom`,(e,t)=>{nr.init(e,t),R.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{let r=n.value,i=t.fn(r);if(i instanceof Promise)return i.then(t=>jr(t,n,r,e));jr(i,n,r,e)}});function jr(e,t,n,r){if(!e){let e={code:`custom`,input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(e.params=r._zod.def.params),t.issues.push(Tn(e))}}function Mr(e,t){return new e({type:`string`,...j(t)})}function Nr(e,t){return new e({type:`number`,checks:[],...j(t)})}function Pr(e,t){return new e({type:`boolean`,...j(t)})}function Fr(e){return new e({type:`unknown`})}function Ir(e,t){return new e({type:`never`,...j(t)})}function Lr(e,t){return new ir({check:`min_length`,...j(t),minimum:e})}function z(e,t){return new or({check:`string_format`,format:`regex`,...j(t),pattern:e})}function Rr(e,t,n){return new e({type:`custom`,check:`custom`,fn:t,...j(n)})}const B=I(`ZodMiniType`,(e,t)=>{if(!e._zod)throw Error(`Uninitialized schema in ZodMiniType.`);R.init(e,t),e.def=t,e.type=t.type},{get with(){return this.check},set with(e){Dn(this,`with`,e)},parse(e,t){return Yn(this,e,t,{callee:this.parse})},parseAsync(e,t){return Xn(this,e,t,{callee:this.parseAsync})},safeParse(e,t){return Zn(this,e,t)},safeParseAsync(e,t){return Qn(this,e,t)},check(...e){let t=this.def;return this.clone({...t,checks:[...t.checks??[],...e.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]},{parent:!0})},clone(e,t){return gn(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},apply(e,...t){return t.length===0?e(this):e(this,...t)}}),zr=I(`ZodMiniString`,(e,t)=>{ur.init(e,t),B.init(e,t)});function V(e){return Mr(zr,e)}const Br=I(`ZodMiniNumber`,(e,t)=>{dr.init(e,t),B.init(e,t)});function Vr(e){return Nr(Br,e)}const Hr=I(`ZodMiniBoolean`,(e,t)=>{fr.init(e,t),B.init(e,t)});function Ur(e){return Pr(Hr,e)}const Wr=I(`ZodMiniUnknown`,(e,t)=>{pr.init(e,t),B.init(e,t)});function Gr(){return Fr(Wr)}const Kr=I(`ZodMiniNever`,(e,t)=>{mr.init(e,t),B.init(e,t)});function qr(e){return Ir(Kr,e)}const Jr=I(`ZodMiniArray`,(e,t)=>{gr.init(e,t),B.init(e,t)});function Yr(e,t){return new Jr({type:`array`,element:e,...j(t)})}const Xr=I(`ZodMiniObject`,(e,t)=>{Sr.init(e,t),B.init(e,t),Nn(e,`shape`,e=>e._zod.def.shape,!1)});function H(e,t){let n={type:`object`,shape:e??{},...j(t)};return new Xr(n)}function Zr(e,t){return new Xr({type:`object`,shape:e,catchall:Gr(),...j(t)})}const Qr=I(`ZodMiniUnion`,(e,t)=>{wr.init(e,t),B.init(e,t)});function $r(e,t){return new Qr({type:`union`,options:e,...j(t)})}const ei=I(`ZodMiniRecord`,(e,t)=>{Tr.init(e,t),B.init(e,t)});function U(e,t,n){return!t||!t._zod?new ei({type:`record`,keyType:V(),valueType:e,...j(t)}):new ei({type:`record`,keyType:e,valueType:t,...j(n)})}const ti=I(`ZodMiniEnum`,(e,t)=>{Er.init(e,t),B.init(e,t),e.options=Object.values(t.entries)});function ni(e,t){let n=Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e;return new ti({type:`enum`,entries:n,...j(t)})}const ri=I(`ZodMiniLiteral`,(e,t)=>{Dr.init(e,t),B.init(e,t)});function W(e,t){return new ri({type:`literal`,values:Array.isArray(e)?e:[e],...j(t)})}const ii=I(`ZodMiniOptional`,(e,t)=>{kr.init(e,t),B.init(e,t)});function G(e){return new ii({type:`optional`,innerType:e})}const ai=I(`ZodMiniCustom`,(e,t)=>{Ar.init(e,t),B.init(e,t)});function oi(e,t={}){return Rr(ai,e,t)}function si(){return V().check(z(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/,`Invalid ISO 8601 datetime`))}function ci(e){return e instanceof Date?Number.isFinite(e.getTime())?e.toISOString():`Invalid Date`:e}function li(){return V().check(z(/^0x[0-9a-fA-F]{40}$/,`Invalid address`))}function ui(){return V().check(z(/^0x[0-9a-fA-F]{64}$/,`Invalid hash`))}function di(){return V().check(z(/^0x[0-9a-fA-F]+$/,`Invalid signature`))}const fi=H({description:G(V()),digest:G(V().check(z(/^sha-256=/,`Invalid digest format`))),expires:G(si()),header:G(V().check(z(/^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/,`Invalid HTTP header name`))),id:V().check(Lr(1)),intent:V(),method:V(),meta:G(U(V(),V())),opaque:G(V()),realm:V(),request:U(V(),Gr())});function pi(e,t){let{description:n,digest:r,meta:i,method:a,header:o,intent:s,realm:c,request:l,secretKey:u}=e,d=Di(o)?void 0:o,f=e.expires?ci(e.expires):void 0,p=e.opaque??(i===void 0?void 0:A(i)),m=u?Oi({...e,expires:f,...i!==void 0&&{meta:i},opaque:p},{secretKey:u}):e.id;return fi.parse({id:m,realm:c,method:a,intent:s,request:l,...n&&{description:n},...r&&{digest:r},...f&&{expires:f},...d!==void 0&&{header:d},...i!==void 0&&{meta:i},...p!==void 0&&{opaque:p}})}function mi(e){let t=[K(`id`,e.id),K(`realm`,e.realm),K(`method`,e.method),K(`intent`,e.intent),K(`request`,A(e.request))];e.description!==void 0&&t.push(K(`description`,e.description)),e.digest!==void 0&&t.push(K(`digest`,e.digest)),e.expires!==void 0&&t.push(K(`expires`,e.expires));let n=e.header;return n!==void 0&&!Di(n)&&t.push(K(`header`,n)),e.opaque===void 0?e.meta!==void 0&&t.push(K(`opaque`,A(e.meta))):t.push(K(`opaque`,e.opaque)),`${nn.payment} ${t.join(`, `)}`}function K(e,t){if(/[\r\n]/.test(t))throw Error(`Invalid quoted-string value.`);return`${e}="${t.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/[\u0100-\uffff]/g,e=>`\\u${e.charCodeAt(0).toString(16).padStart(4,`0`)}`)}"`}function hi(e,t){let n=gi(e);if(!n)throw Error(`Missing Payment scheme.`);let{request:r,opaque:i,...a}=_i(n);if(!r)throw Error(`Missing request parameter.`);if(r.length>16384)throw Error(`Request parameter too large.`);if(a.method&&!/^[a-z][a-z0-9:_-]*$/.test(a.method))throw Error(`Invalid method: "${a.method}". Must be lowercase per spec.`);return pi({...a,request:rn(r),...i&&{opaque:i}},t)}function gi(e){let t=nn.payment,[n]=xi(e,t);if(n===void 0)return null;let r=n+t.length;for(;r<e.length&&/\s/.test(e[r]??``);)r++;return e.slice(r)}function _i(e){let t=Object.create(null),n=0;for(;n<e.length;){for(;n<e.length&&/[\s,]/.test(e[n]??``);)n++;if(n>=e.length)break;let r=n;for(;n<e.length&&/[A-Za-z0-9_-]/.test(e[n]??``);)n++;let i=e.slice(r,n).toLowerCase();if(!i)throw Error(`Malformed auth-param.`);for(;n<e.length&&/\s/.test(e[n]??``);)n++;if(e[n]!==`=`)break;for(n++;n<e.length&&/\s/.test(e[n]??``);)n++;let[a,o]=vi(e,n);if(n=o,i in t)throw Error(`Duplicate parameter: ${i}`);t[i]=a}return t}function vi(e,t){if(e[t]===`"`)return yi(e,t+1);let n=t;for(;n<e.length&&e[n]!==`,`;)n++;return[e.slice(t,n).trim(),n]}function yi(e,t){let n=t,r=!1,i=t,a;for(;n<e.length;){let o=e[n];if(n++,r){a??=[];let t=o===`u`?e.slice(n,n+4):void 0;t&&/^[0-9A-Fa-f]{4}$/.test(t)?(a.push(String.fromCharCode(Number.parseInt(t,16))),n+=4):a.push(o),i=n,r=!1;continue}if(o===`\\`){a??=[],a.push(e.slice(i,n-1)),i=n,r=!0;continue}if(o===`"`)return[a?[...a,e.slice(i,n-1)].join(``):e.slice(t,n-1),n]}throw Error(`Unterminated quoted-string.`)}function bi(e,t,n){if(e.slice(t,t+n.length).toLowerCase()!==n.toLowerCase())return!1;let r=e[t+n.length];return!!(r&&/\s/.test(r))}function xi(e,t){let n=[],r=!1,i=!1;for(let a=0;a<e.length;a++){let o=e[a];if(r){i?i=!1:o===`\\`?i=!0:o===`"`&&(r=!1);continue}if(o===`"`){r=!0;continue}if(!bi(e,a,t))continue;let s=a-1;for(;s>=0&&/\s/.test(e[s]??``);)s--;s>=0&&e[s]!==`,`||n.push(a)}return n}function Si(e,t){if(e.status!==402)throw Error(`Response status is not 402.`);return Ci(e.headers,t)}function Ci(e,t){let n=e.get(k.wwwAuthenticate);if(!n)throw Error(`Missing ${k.wwwAuthenticate} header.`);return wi(n,t)}function wi(e,t){let n=xi(e,nn.payment);if(n.length===0)throw Error(`No Payment schemes found.`);return n.map((r,i)=>{let a=i+1<n.length?n[i+1]:e.length;return hi(e.slice(r,a).replace(/,\s*$/,``),t)})}function Ti(e){let t=[e.realm,e.method,e.intent,A(e.request),e.expires??``,e.digest??``],n=e.header;return n!==void 0&&!Di(n)&&t.push(n),t.push(e.opaque??(e.meta?A(e.meta):``)),t.join(`|`)}function Ei(e){return e.header??k.authorization}function Di(e){return e?.toLowerCase()===k.authorization.toLowerCase()}function Oi(e,t){let n=Ti(e);return Qt(qt(Bt(t.secretKey),Bt(n),{as:`Bytes`}),{url:!0,pad:!1})}var ki=class extends Error{name=`MissingPaymentSchemeError`;constructor(){super(`Missing Payment scheme.`)}},Ai=class extends Error{name=`InvalidCredentialEncodingError`;constructor(){super(`Invalid base64url or JSON.`)}};function ji(e){let t=e.match(RegExp(`^${nn.payment}\\s+(.+)$`,`i`));if(!t?.[1])throw new ki;try{let e=tn(t[1]),n=JSON.parse(e),{opaque:r,request:i,meta:a,...o}=n.challenge,{meta:s,opaque:c}=Mi(r);return{challenge:fi.parse({...o,...s!==void 0&&{meta:s},...c!==void 0&&{opaque:c},request:rn(i)}),payload:n.payload,...n.source&&{source:n.source}}}catch{throw new Ai}}function Mi(e){if(e===void 0)return{};if(typeof e==`string`)return{opaque:e};if(!Ni(e))throw Error(`Invalid opaque.`);return{meta:e,opaque:A(e)}}function Ni(e){return typeof e!=`object`||!e||Array.isArray(e)?!1:Object.values(e).every(e=>typeof e==`string`)}var Pi=class extends Error{details;status=402;hint;constructor(e,t={}){super(e),this.details=t.details}toProblemDetails(e){return{type:this.type,title:this.title,status:this.status,detail:this.message,...this.details&&Object.keys(this.details).length>0&&{details:this.details},...this.hint&&{hint:this.hint},...e&&{challengeId:e}}}},Fi=class extends Pi{name=`InvalidChallengeError`;title=`Invalid Challenge`;status=402;type=`https://paymentauth.org/problems/invalid-challenge`;constructor(e={}){let{id:t,reason:n}=e,r=t?` "${t}"`:``,i=n?`: ${n}`:``;super(`Challenge${r} is invalid${i}.`)}},Ii=class extends Pi{name=`PaymentExpiredError`;title=`Payment Expired`;type=`https://paymentauth.org/problems/payment-expired`;constructor(e={}){let{expires:t}=e;super(t?`Payment expired at ${t}.`:`Payment has expired.`)}};function Li(e,t){if(!e)throw new Fi({...t&&{id:t},reason:`missing required expires field`});if(Number.isNaN(new Date(e).getTime()))throw new Fi({...t&&{id:t},reason:`malformed expires timestamp`});if(new Date(e)<new Date)throw new Ii({expires:e})}function Ri(e){return e}function zi(e,t){let{canHandleChallenge:n,context:r,createCredential:i}=t;return{...e,canHandleChallenge:n,context:r,createCredential:i}}const Bi=Zr({method:V(),reference:V(),externalId:G(V()),subscriptionId:G(V()),status:W(`success`),timestamp:si()});function Vi(e){let t=tn(e);return Hi(JSON.parse(t))}function Hi(e){return Bi.parse(e)}function Ui(e){let t=e.headers.get(k.paymentReceipt);if(!t)throw Error(`Missing ${k.paymentReceipt} header.`);return Vi(t)}function Wi(e){return{encode(t){return $t(JSON.stringify(e.parse(t)))},decode(t){try{return e.parse(JSON.parse(tn(t)))}catch{throw new Gi}}}}var Gi=class extends Error{name=`InvalidJsonHeaderError`;constructor(){super(`Invalid base64 JSON header.`)}};const Ki=[`exact`],qi=`PAYMENT-REQUIRED`,Ji=`PAYMENT-SIGNATURE`,Yi=V().check(Lr(1)),Xi=Vr().check(oi(e=>e>0,`Must be positive`)),q=V().check(z(/^\d+$/,`Invalid atomic amount`)),Zi=li(),Qi=V().check(z(RegExp(`^eip155:\\d+$`),`Invalid EVM CAIP-2 network`)),$i=H({description:G(V()),iconUrl:G(V()),mimeType:G(V()),serviceName:G(V()),tags:G(Yr(V())),url:Yi}),ea=H({amount:q,asset:Yi,extra:G(U(V(),Gr())),maxTimeoutSeconds:Xi,network:Qi,payTo:Yi,scheme:ni(Ki)}),ta=U(V(),H({info:U(V(),Gr()),schema:U(V(),Gr())})),na=H({accepts:Yr(ea).check(Lr(1)),error:G(V()),extensions:G(ta),resource:$i,x402Version:W(2)}),ra=$r([H({authorization:H({from:Zi,nonce:ui(),to:Zi,validAfter:q,validBefore:q,value:q}),signature:di()}),H({permit2Authorization:H({deadline:q,from:Zi,nonce:q,permitted:H({amount:q,token:Zi}),spender:Zi,witness:H({to:Zi,validAfter:q})}),signature:di()})]),ia=H({accepted:ea,extensions:G(ta),payload:ra,resource:G($i),x402Version:W(2)}),aa=H({amount:G(q),errorMessage:G(V()),errorReason:G(V()),extensions:G(ta),extra:G(U(V(),Gr())),network:Yi,payer:G(V()),success:Ur(),transaction:V()}),oa=Wi(na),sa=Wi(ia),ca=Wi(aa);oa.encode,oa.decode;function la(e){try{let t=JSON.parse(tn(e));return ua(t)}catch{throw new Gi}}sa.encode,sa.decode,ca.encode,ca.decode;const ua=e=>{if(!e||typeof e!=`object`||Array.isArray(e))throw new Gi;let t=e;if(t.x402Version!==2||!Array.isArray(t.accepts))throw new Gi;let n=$i.parse(t.resource),r=t.extensions===void 0?void 0:ta.safeParse(t.extensions).data;return{accepts:t.accepts,...r?{extensions:r}:{},resource:n,x402Version:2}},da=Symbol.for(`mppx.x402.challenge`);function fa(e){return Object.defineProperty(e,da,{value:!0}),e}function pa(e){return!!e?.[da]}function ma(e){let t={};for(let n of e){let e=t[n.name]??={};e[n.intent]=ya(n)}return t}function ha(e,t){let n=ma(e),r=Ea(e,n,t),i=e.map((e,t)=>({intent:e.intent,method:e.name,q:r[ya(e)]??1,index:t}));return{definition:r,entries:i,header:_a(i),keys:n}}function ga(e){let t=e.split(/\s*,\s*/).map(e=>e.trim()).filter(Boolean);if(t.length===0)throw Error(`Accept-Payment header is empty.`);return t.map((e,t)=>wa(e,t))}function _a(e){return e.map(({method:e,intent:t,q:n})=>{let r=`${e}/${t}`;return n===1?r:`${r};q=${Aa(n)}`}).join(`, `)}function va(e,t,n){let r=new Map;for(let e of t){let t=ya(e),n=r.get(t);n?n.push(e):r.set(t,[e])}return e.flatMap((e,t)=>{let i=r.get(ya(e));if(!i)return[];let a=ba(e,n);return!a||a.q<=0?[]:i.filter(t=>t.canHandleChallenge?.({challenge:e})??!0).map(n=>({challenge:e,index:t,match:a,method:n}))}).sort((e,t)=>Ca(e.challenge)-Ca(t.challenge)||t.match.q-e.match.q||e.index-t.index).map(e=>{let{match:t,...n}=e;return n})}function ya(e){let t=e.method??e.name;if(!t)throw Error(`Missing payment method name.`);return`${t}/${e.intent}`}function ba(e,t){let n;for(let r of t){if(!xa(e,r))continue;let t={...r,specificity:Sa(r)};(!n||t.specificity>n.specificity||t.specificity===n.specificity&&t.q>n.q||t.specificity===n.specificity&&t.q===n.q&&t.index<n.index)&&(n=t)}return n}function xa(e,t){return(t.method===`*`||t.method===e.method)&&(t.intent===`*`||t.intent===e.intent)}function Sa(e){return Number(e.method!==`*`)+Number(e.intent!==`*`)}function Ca(e){return+!!pa(e)}function wa(e,t){let n=/^(?<method>[^/;\s]+|\*)\s*\/\s*(?<intent>[^/;\s]+|\*)(?<params>(?:\s*;\s*.+)?)$/u.exec(e),r=n?.groups?.method,i=n?.groups?.intent;if(!r||!i)throw Error(`Invalid Accept-Payment entry: ${e}`);ja(r,`method`),ja(i,`intent`);let a=1;for(let t of Ta(n.groups?.params)){if(!t)continue;let n=/^(?<name>[A-Za-z0-9_-]+)\s*=\s*(?<value>\S+)$/u.exec(t),r=n?.groups?.name,i=n?.groups?.value;if(!r||!i)throw Error(`Invalid Accept-Payment parameter: ${t}`);r===`q`&&(a=Oa(i,`Accept-Payment entry "${e}"`))}return{intent:i,method:r,q:a,index:t}}function Ta(e){return e?e.split(/\s*;\s*/).filter(Boolean):[]}function Ea(e,t,n){if(!n)return{};let r=typeof n==`function`?n(t):n,i=new Set(e.map(e=>ya(e))),a={};for(let[e,t]of Object.entries(r??{})){if(!i.has(e))throw Error(`Unknown payment preference "${e}". Available: ${[...i].join(`, `)}`);a[e]=Da(t,`payment preference "${e}"`)}return a}function Da(e,t){if(typeof e!=`number`||Number.isNaN(e)||!Number.isFinite(e))throw Error(`Invalid q-value for ${t}. Expected a finite number.`);return ka(e,t)}function Oa(e,t){if(!/^0(?:\.\d{0,3})?$|^1(?:\.0{0,3})?$/.test(e))throw Error(`Invalid q-value for ${t}. Expected an HTTP qvalue.`);return ka(Number(e),t)}function ka(e,t){if(e<0||e>1)throw Error(`Invalid q-value for ${t}. Expected a value between 0 and 1.`);let n=Math.round(e*1e3);if(Math.abs(e*1e3-n)>1e-9)throw Error(`Invalid q-value for ${t}. Expected at most 3 decimal places.`);return n/1e3}function Aa(e){return e.toFixed(3).replace(/\.0+$/,``).replace(/(\.\d*?)0+$/,`$1`)}function ja(e,t){if(e!==`*`&&!/^[a-z0-9-]+$/.test(e))throw Error(`Invalid Accept-Payment ${t}: ${e}`)}var Ma=class extends Error{constructor(e,t){super(e),this.name=`ParseError`,this.type=t.type,this.field=t.field,this.value=t.value,this.line=t.line}};function Na(e){}function Pa(e){if(typeof e==`function`)throw TypeError("`config` must be an object, got a function instead. Did you mean `createParser({onEvent: fn})`?");let{onEvent:t=Na,onError:n=Na,onRetry:r=Na,onComment:i,maxBufferSize:a}=e,o=[],s=0,c=!0,l,u=``,d=0,f,p=!1;function m(e){if(p)throw Error("Cannot feed parser: it was terminated after exceeding the configured max buffer size. Call `reset()` to resume parsing.");if(c&&(c=!1,e.charCodeAt(0)===239&&e.charCodeAt(1)===187&&e.charCodeAt(2)===191&&(e=e.slice(3))),o.length===0){let t=g(e);t!==``&&(o.push(t),s=t.length),h();return}if(e.indexOf(`
|
|
4
|
+
`)===-1&&e.indexOf(`\r`)===-1){o.push(e),s+=e.length,h();return}o.push(e);let t=o.join(``);o.length=0,s=0;let n=g(t);n!==``&&(o.push(n),s=n.length),h()}function h(){a!==void 0&&(s+u.length<=a||(p=!0,o.length=0,s=0,l=void 0,u=``,d=0,f=void 0,n(new Ma(`Buffered data exceeded max buffer size of ${a} characters`,{type:`max-buffer-size-exceeded`}))))}function g(e){let n=0;if(e.indexOf(`\r`)===-1){let r=e.indexOf(`
|
|
5
|
+
`,n);for(;r!==-1;){if(n===r){d>0&&t({id:l,event:f,data:u}),l=void 0,u=``,d=0,f=void 0,n=r+1,r=e.indexOf(`
|
|
6
|
+
`,n);continue}let i=e.charCodeAt(n);if(Fa(e,n,i)){let i=e.charCodeAt(n+5)===32?n+6:n+5,a=e.slice(i,r);if(d===0&&e.charCodeAt(r+1)===10){t({id:l,event:f,data:a}),l=void 0,u=``,f=void 0,n=r+2,r=e.indexOf(`
|
|
7
|
+
`,n);continue}u=d===0?a:`${u}
|
|
8
|
+
${a}`,d++}else Ia(e,n,i)?f=e.slice(e.charCodeAt(n+6)===32?n+7:n+6,r)||void 0:_(e,n,r);n=r+1,r=e.indexOf(`
|
|
9
|
+
`,n)}return e.slice(n)}for(;n<e.length;){let t=e.indexOf(`\r`,n),r=e.indexOf(`
|
|
10
|
+
`,n),i=-1;if(t!==-1&&r!==-1?i=t<r?t:r:t===-1?r!==-1&&(i=r):i=t===e.length-1?-1:t,i===-1)break;_(e,n,i),n=i+1,e.charCodeAt(n-1)===13&&e.charCodeAt(n)===10&&n++}return e.slice(n)}function _(e,t,n){if(t===n){y();return}let r=e.charCodeAt(t);if(Fa(e,t,r)){let r=e.charCodeAt(t+5)===32?t+6:t+5,i=e.slice(r,n);u=d===0?i:`${u}
|
|
11
|
+
${i}`,d++;return}if(Ia(e,t,r)){f=e.slice(e.charCodeAt(t+6)===32?t+7:t+6,n)||void 0;return}if(r===105&&e.charCodeAt(t+1)===100&&e.charCodeAt(t+2)===58){let r=e.slice(e.charCodeAt(t+3)===32?t+4:t+3,n);r.includes(`\0`)||(l=r);return}if(r===58){if(i){let r=e.slice(t,n);i(r.slice(e.charCodeAt(t+1)===32?2:1))}return}let a=e.slice(t,n),o=a.indexOf(`:`);if(o===-1){v(a,``,a);return}let s=a.slice(0,o),c=a.charCodeAt(o+1)===32?2:1;v(s,a.slice(o+c),a)}function v(e,t,i){switch(e){case`event`:f=t||void 0;break;case`data`:u=d===0?t:`${u}
|
|
12
|
+
${t}`,d++;break;case`id`:t.includes(`\0`)||(l=t);break;case`retry`:/^\d+$/.test(t)?r(parseInt(t,10)):n(new Ma(`Invalid \`retry\` value: "${t}"`,{type:`invalid-retry`,value:t,line:i}));break;default:n(new Ma(`Unknown field "${e.length>20?`${e.slice(0,20)}\u2026`:e}"`,{type:`unknown-field`,field:e,value:t,line:i}))}}function y(){d>0&&t({id:l,event:f,data:u}),l=void 0,u=``,d=0,f=void 0}function b(e={}){if(e.consume&&o.length>0){let e=o.join(``);_(e,0,e.length)}c=!0,l=void 0,u=``,d=0,f=void 0,o.length=0,s=0,p=!1}return{feed:m,reset:b}}function Fa(e,t,n){return n===100&&e.charCodeAt(t+1)===97&&e.charCodeAt(t+2)===116&&e.charCodeAt(t+3)===97&&e.charCodeAt(t+4)===58}function Ia(e,t,n){return n===101&&e.charCodeAt(t+1)===118&&e.charCodeAt(t+2)===101&&e.charCodeAt(t+3)===110&&e.charCodeAt(t+4)===116&&e.charCodeAt(t+5)===58}const La=[k.authorization,qi,`PAYMENT-RESPONSE`,Ji];function Ra(e,t,n){let r=new Headers(e.headers);for(let e of La)(e!==k.authorization||r.get(e)?.startsWith(`Payment `))&&r.delete(e);return r.set(t,n),{...e,headers:r}}function za(e){if(typeof e==`string`)try{let t=JSON.parse(e),n=t?.id;return t?.jsonrpc!==`2.0`||typeof t?.method!=`string`?void 0:typeof n==`string`||typeof n==`number`?n:void 0}catch{return}}const Ba=new WeakMap;function Va(e){let t=za(e?.body);if(t===void 0)return;let n=new Headers(e?.headers);if(n.has(`mcp-method`))return t;let r=n.get(`accept`)?.toLowerCase()??``;return r.includes(`application/json`)&&r.includes(`text/event-stream`)?t:void 0}function Ha(e){if(!e||typeof e!=`object`)return;let t=e,n=t.id;if(t.jsonrpc!==`2.0`||n!==void 0&&typeof n!=`string`&&typeof n!=`number`)return;let r=`error`in t;if(r!==`result`in t)return r?Number.isInteger(t.error?.code)&&typeof t.error?.message==`string`?e:void 0:n!==void 0&&typeof t.result==`object`?e:void 0}function Ua(e){if(!e||typeof e!=`object`)return;let t=e?.challenges;if(!Array.isArray(t)||t.length===0)return;let n=[];for(let e of t){let t=fi.safeParse(e);if(!t.success)return;n.push(t.data)}let{httpStatus:r,problem:i}=e;return{challenges:n,...typeof r==`number`?{httpStatus:r}:{},...i===void 0?{}:{problem:i}}}function Wa(e){if(e)return`error`in e?e.error?.code!==-32042&&e.error?.code!==-32043?void 0:Ua(e.error.data):Ua(e.result?._meta?.[`org.paymentauth/payment-required`])}function Ga(e,t){return!e||e.id!==t?[]:Wa(e)?.challenges??[]}async function Ka(e){let t=e.clone().body?.getReader();if(!t)return;let n=new TextDecoder,r=!1,i,a=Pa({onEvent(e){if(!r&&e.data&&(r=!0,!(e.event&&e.event!==`message`)))try{i=Ha(JSON.parse(e.data))}catch{}}});try{for(;;){if(r)return i;let{done:e,value:o}=await t.read();if(e)return a.feed(n.decode()),a.reset({consume:!0}),i;a.feed(n.decode(o,{stream:!0}))}}finally{t.cancel().catch(()=>{})}}function qa(e){let t=Ba.get(e);if(t)return t;let n=(async()=>{let t=e.headers.get(`content-type`)?.toLowerCase()??``;if(t.includes(`application/json`))return e.clone().json().then(Ha).catch(()=>void 0);if(t.includes(`text/event-stream`))return Ka(e)})();return Ba.set(e,n),n}function Ja(){return{getChallenges(e,t){let n=Va(t);return e.status===402||n===void 0?[]:qa(e).then(e=>Ga(e,n))},setCredential(e,t){let n=JSON.parse(e.body),r=ji(t);return{...e,body:JSON.stringify({...n,params:{...n.params,_meta:{...n.params?._meta,"org.paymentauth/credential":r}}})}}}}function Ya(){return{getChallenges(e){return e.status!==402||!e.headers.has(k.wwwAuthenticate)?[]:Si(e)},setCredential(e,t,n){return Ra(e,n?.challenge?Ei(n.challenge):k.authorization,t)}}}function Xa(){return{getChallenges(e){if(e.status!==402)return[];let t=e.headers.get(qi);if(!t)return[];let n=la(t);if(e.url&&n.resource.url!==e.url)throw Error(`x402 payment-required resource does not match response URL.`);return n.accepts.flatMap((e,t)=>{let r=ea.safeParse(e);if(!r.success)return[];let i=r.data;return fa(pi({id:`x402:${t}`,intent:`charge`,method:`evm`,realm:new URL(n.resource.url).host,request:{...i,...n.extensions?{extensions:n.extensions}:{},resource:n.resource}}))})},setCredential(e,t){return Ra(e,Ji,t)}}}function Za(e){return e}function Qa(){let e=[Ya(),Xa(),Ja()],t=new WeakMap,n=(e,n)=>{for(let r of n)t.set(r,e);return n},r=(t,r)=>{let i=(a,o)=>{for(let s=a;s<e.length;s++){let a=e[s],c=a.getChallenges(t,r);if(c instanceof Promise)return c.then(e=>i(s+1,[...o,...n(a,e)]));o.push(...n(a,c))}return o};return i(0,[])};return Za({name:`http`,isPaymentRequired(e,t){if(e.status===402)return!0;let n=r(e,t);return n instanceof Promise?n.then(e=>e.length>0):n.length>0},getChallenges(e,t){return r(e,t)},setCredential(n,r,i){let a=i?.challenge?t.get(i.challenge):void 0,o=e[0];if(!a&&!o)throw Error(`No protocol to attach the credential.`);return(a??o).setCredential(n,r,i)}})}const $a=new WeakMap;function eo(e){return $a.has(e)}function to(e,t){return Promise.resolve($a.get(e)?.(t))}const no=new WeakMap,ro=new WeakMap;function io(e,t,n){no.has(e)&&ro.set(t,n)}function ao(e,t){return Promise.resolve(no.get(e)?.(t)??t.response)}const oo=Symbol.for(`mppx.fetch.wrapper`);let so;const co=new WeakMap;async function J(e,t){let n=e?.attempt.settle;if(!n)return t.status!==`pending`;e.attempt.settle=void 0;let r=await n(t);return r||(e.attempt.settle=n),r}function lo(e){let{acceptPayment:t,acceptPaymentPolicy:n=`always`,fetch:r=globalThis.fetch,maxPaymentRetries:i=3,methods:a,onChallenge:o,orderChallenges:s,transport:c=Qa()}=e,l=e.eventDispatcher??fo(),u=t??ha(a),d=Mo(r),f=async(e,t,r)=>{let p=jo(e,t?.headers),m=p.has(k.acceptPayment),h=Lo(p,u),g=ko(e,t,p),_=Oo(e,t,p,h.header,m,n),v=await d(No(_.input),_.init),y=Ao(_.init,await g);if(!await c.isPaymentRequired(v,y))return v;let b=t?.context,{context:ee,orderChallenges:x,...te}=y??{},S,C,ne,w;try{for(let n=0;n<i;n++){C=await c.getChallenges(v,y);let i=(await Ro(va(C,a,h.entries),x??s))[0];if(!i){if(await J(w,{challenges:C,response:v,status:`rejected`}),n>0)return v;throw Error(`No method found for challenges: ${C.map(e=>`${e.method}.${e.intent}`).join(`, `)}. Available: ${a.map(e=>`${e.name}.${e.intent}`).join(`, `)}`)}let u=i.challenge;S=u,ne=i.method,S.expires&&Li(S.expires,S.id);let p=Uo(v,_.input,_.input),m=w,g=mi(u),ee=m?.method===i.method&&m?.key===g,re=!1;if(m){let e=await J(m,{challenges:C,response:v,status:ee?`pending`:`rejected`});re=ee&&!e}w=re?m:void 0;let ie=_o(async e=>{if(e===void 0&&re&&m)return m.promise;re&&m&&(await J(m,{status:`rejected`}),w=void 0);let t=e??b;if(!eo(i.method))return Io(u,i.method,t);let n={prepare:()=>to(i.method,{challenge:u,context:t,fetch:d,input:p})},r=n.prepare().then(()=>Io(u,i.method,t,n));return w={attempt:n,key:e===void 0?g:void 0,method:i.method,promise:r},r}),T=await l.emit(`challenge.received`,vo({challenge:u,challenges:C,createCredential:ie,init:t,input:e,method:i.method,response:v}))??(o?await o(S,{createCredential:ie}):void 0)??await ie(),ae=w;ae&&await ae.promise.catch(()=>void 0)!==T&&(await J(ae,{status:`rejected`}),w=void 0),Fo(T),await l.emit(`credential.created`,yo({challenge:u,credential:T,init:t,input:e,method:i.method,response:v})),v=await d(p,c.setCredential({...te,headers:_.headers},T,{challenge:u}));let oe=await c.isPaymentRequired(v,y);if(oe||(await J(ae,{response:v,status:v.ok?`accepted`:`rejected`}),w=void 0),v.ok&&po(l,`payment.response`)&&await l.emit(`payment.response`,bo({challenge:u,credential:T,init:t,input:e,method:i.method,response:v})),!oe)return v.ok?ao(i.method,{challenge:u,credential:T,fetch:d,headers:_.headers,input:p,...r?{refetch:()=>f(No(_.input),t,!1)}:{},response:v,signal:Po(e,t)}):v}C=void 0;try{C=await c.getChallenges(v,y)}catch{}return await J(w,{challenges:C,response:v,status:`rejected`}),v}catch(n){throw await J(w,{challenges:C,response:v,status:`rejected`}),await l.emit(`payment.failed`,xo({challenge:S,challenges:C,error:n,init:t,input:e,method:ne,response:v})),n}},p=(e,t)=>f(e,t,!0);return p[oo]=d,p}function uo(e){let t=Object.getOwnPropertyDescriptor(globalThis,`fetch`);if(!t||!t.writable&&!t.set)throw Error(`globalThis.fetch is not writable`);so||=globalThis.fetch,globalThis.fetch=lo({...e,acceptPaymentPolicy:e.acceptPaymentPolicy??(Vo()?`same-origin`:`always`),fetch:globalThis.fetch})}function fo(){let e={"*":new Set,"challenge.received":new Set,"credential.created":new Set,"payment.failed":new Set,"payment.response":new Set},t={async emit(t,n){switch(t){case`challenge.received`:{let r;for(let t of e[`challenge.received`]){let e=await mo(t,n);if(typeof e==`string`&&e.length>0){r=e;break}}return await go(e[`*`],t,n),r}case`credential.created`:await ho(e[`credential.created`],n),await go(e[`*`],t,n);return;case`payment.failed`:await ho(e[`payment.failed`],n),await go(e[`*`],t,n);return;case`payment.response`:await ho(e[`payment.response`],n),await go(e[`*`],t,n);return}},on:(t,n)=>{switch(t){case`*`:case`challenge.received`:case`credential.created`:case`payment.failed`:case`payment.response`:return e[t].add(n),()=>e[t].delete(n);default:throw Error(`Unknown client event "${String(t)}".`)}}};return co.set(t,t=>e[t].size>0||e[`*`].size>0),t}function po(e,t){return co.get(e)?.(t)??!0}async function mo(e,t){try{return await e(t)}catch{return}}async function ho(e,t){for(let n of e)try{await n(t)}catch{}}async function go(e,t,n){await ho(e,Object.freeze({name:t,payload:n}))}function _o(e){let t;return n=>(t??=e(n),t)}function vo(e){return Object.freeze({challenge:Y(e.challenge),challenges:e.challenges.map(e=>Y(e)),createCredential:e.createCredential,init:So(e.init),input:Co(e.input),method:wo(e.method),response:To(e.response)})}function yo(e){return Object.freeze({challenge:Y(e.challenge),credential:e.credential,init:So(e.init),input:Co(e.input),method:wo(e.method),...e.response===void 0?{}:{response:To(e.response)}})}function bo(e){return Object.freeze({challenge:Y(e.challenge),credential:e.credential,init:So(e.init),input:Co(e.input),method:wo(e.method),response:To(e.response)})}function xo(e){return Object.freeze({...e.challenge?{challenge:Y(e.challenge)}:{},...e.challenges?{challenges:e.challenges.map(e=>Y(e))}:{},error:e.error,init:So(e.init),input:Co(e.input),...e.method?{method:wo(e.method)}:{},...e.response===void 0?{}:{response:To(e.response)}})}function So(e){if(e)return Do({...e,...e.headers?{headers:new Headers(e.headers)}:{}})}function Co(e){if(e instanceof Request)try{return e.clone()}catch{return e}return e instanceof URL?new URL(e):e}function wo(e){return Do(Object.assign({},e))}function To(e){return e instanceof Response?e.clone():Y(e)}function Y(e){try{return Eo(structuredClone(e))}catch{return Do(e)}}function Eo(e){if(!e||typeof e!=`object`||Object.isFrozen(e))return e;Object.freeze(e);for(let t of Object.values(e))Eo(t);return e}function Do(e){return!e||typeof e!=`object`||Object.isFrozen(e)||Object.freeze(e),e}function Oo(e,t,n,r,i,a){let o=!!r&&!i&&zo(e,a);if(!o)return{headers:n,init:t,input:e};let s=new Headers(e instanceof Request?e.headers:void 0);return n.forEach((e,t)=>{s.set(t,e)}),s.set(k.acceptPayment,r),t?(t.headers=s,{headers:s,init:t,input:e}):{headers:s,init:o?{headers:s}:void 0,input:e}}function ko(e,t,n){if(e instanceof Request&&t?.body===void 0&&e.body&&!e.bodyUsed){if(!n.has(`mcp-method`)){let e=n.get(`accept`)?.toLowerCase()??``;if(!e.includes(`application/json`)||!e.includes(`text/event-stream`))return}try{return e.clone().text().catch(()=>void 0)}catch{return}}}function Ao(e,t){return t===void 0?e:{...e,body:t}}function jo(e,t){return t?new Headers(t):new Headers(e instanceof Request?e.headers:void 0)}function Mo(e){let t=e;for(;t[oo];)t=t[oo];return t}function No(e){if(!(e instanceof Request)||!e.body||e.bodyUsed)return e;try{return e.clone()}catch{return e}}function Po(e,t){return t?.signal??(e instanceof Request?e.signal:void 0)}function Fo(e){if(!e.trim())throw Error(`Credential header value must be non-empty`);if(e.includes(`\r`)||e.includes(`
|
|
13
|
+
`))throw Error(`Credential header value contains illegal newline characters`)}async function Io(e,t,n,r){let i=t.context&&n!==void 0?t.context.parse(n):void 0,a=i===void 0?{challenge:e}:{challenge:e,context:i};return r&&io(t,a,r),t.createCredential(a)}function Lo(e,t){let n=e.get(k.acceptPayment);if(!n)return t;try{return{...t,entries:ga(n),header:n}}catch{return t}}async function Ro(e,t){return t?t(e):e}function zo(e,t){if(t===`always`)return!0;if(t===`never`)return!1;let n=Ho(e);return t===`same-origin`?!Vo()||n.origin===globalThis.location.origin:t.origins.some(e=>Bo(n,e))}function Bo(e,t){if(t.startsWith(`*.`)){let n=t.slice(1);return e.hostname.endsWith(n)||e.hostname===t.slice(2)}return e.origin===new URL(t).origin}function Vo(){return globalThis.location!==void 0}function Ho(e){return e instanceof URL?e:e instanceof Request?new URL(e.url):new URL(e,Vo()?globalThis.location.href:void 0)}function Uo(e,t,n){if(!e.url)return t;let r=new URL(e.url),i=Ho(n);if(r.origin!==i.origin)throw Error(`Refusing to send payment credential across redirect from ${i.origin} to ${r.origin}`);return e.url}function Wo(){let e=new Uint8Array(64);return crypto.getRandomValues(e),Object.freeze({created:Math.floor(Date.now()/1e3),nonce:Qt(e,{pad:!1,url:!0})})}function Go(...e){return{protocol:`composed`,async sign(t,n=Wo()){for(let r of e)t=await r.sign(t,n);return t}}}function Ko(e,t){return async(n,r)=>e(await t.sign(new Request(n,r)))}function qo(e){let{attestation:t,maxPaymentRetries:n,onChallenge:r,orderChallenges:i,polyfill:a=!0,acceptPaymentPolicy:o=a&&globalThis.location!==void 0?`same-origin`:`always`,transport:s=Qa()}=e,c=e.fetch??globalThis.fetch,l=t?Jo(c,t):c,u=e.methods.flat(),d=ha(u,e.paymentPreferences),f=fo(),p=r,m={acceptPayment:d,acceptPaymentPolicy:o,...(e.fetch||t)&&{fetch:l},eventDispatcher:f,...n!==void 0&&{maxPaymentRetries:n},...p&&{onChallenge:p},...i&&{orderChallenges:i},methods:u,transport:s},h=lo(m);a&&uo(m);function g(e){return f.on(`challenge.received`,e)}function _(e){return f.on(`credential.created`,e)}function v(e){return f.on(`payment.failed`,e)}function y(e){return f.on(`payment.response`,e)}async function b(e,t){let n=es(e),r=await s.getChallenges(e,t?.request),a=Object.freeze(r.map(e=>X(e))),o=rs(d.entries,t?.acceptPayment),c,l;try{let e=(await is(va(r,u,o),t?.orderChallenges??i))[0];if(!e)throw Error(`No method found for challenges: ${r.map(e=>`${e.method}.${e.intent}`).join(`, `)}. Available: ${u.map(e=>`${e.name}.${e.intent}`).join(`, `)}`);let d=e.challenge;c=a[e.index],l=e.method,c.expires&&Li(c.expires,c.id);let p=c,m=l,h=Yo(async e=>{try{p.expires&&Li(p.expires,p.id);let t=Yo(t=>as(p,m,t??e)),i=await f.emit(`challenge.received`,Xo({challenge:p,challenges:r,createCredential:t,method:m,response:n}))??await t();return Fo(i),await f.emit(`credential.created`,Zo({challenge:p,credential:i,method:m,response:n})),i}catch(e){throw await f.emit(`payment.failed`,Qo({challenge:p,challenges:r,error:e,method:m,response:n})),e}});return Object.freeze({challenge:p,challenges:a,createCredential:h,method:$o(m),setCredential(e,t){return Fo(t),s.setCredential(e,t,{challenge:d})}})}catch(e){throw await f.emit(`payment.failed`,Qo({challenge:c,challenges:r,error:e,method:l,response:n})),e}}return{fetch:h,rawFetch:c,methods:u,transport:s,on:f.on,onChallengeReceived:g,onCredentialCreated:_,onPaymentFailed:v,onPaymentResponse:y,preparePayment:b,async createCredential(e,t,n){return(await b(e,n)).createCredential(t)}}}function Jo(e,t){let n=Object.values(t);if(n.length===0)throw TypeError(`Mppx client attestation must configure at least one signer.`);return Ko(e,Go(...n))}function Yo(e){let t;return n=>(t??=e(n),t)}function Xo(e){return Object.freeze({challenge:X(e.challenge),challenges:e.challenges.map(e=>X(e)),createCredential:e.createCredential,method:$o(e.method),response:es(e.response)})}function Zo(e){return Object.freeze({challenge:X(e.challenge),credential:e.credential,method:$o(e.method),response:es(e.response)})}function Qo(e){return Object.freeze({...e.challenge?{challenge:X(e.challenge)}:{},...e.challenges?{challenges:e.challenges.map(e=>X(e))}:{},error:e.error,...e.method?{method:$o(e.method)}:{},response:es(e.response)})}function $o(e){return ns(Object.assign({},e))}function es(e){if(e instanceof Response)try{return e.clone()}catch{return new Response(null,{headers:e.headers,status:e.status,statusText:e.statusText})}return X(e)}function X(e){try{let t=structuredClone(e);if(e&&t&&typeof e==`object`&&typeof t==`object`)for(let n of Object.getOwnPropertySymbols(e)){let r=Object.getOwnPropertyDescriptor(e,n);r&&Object.defineProperty(t,n,r)}return ts(t)}catch{return ns(e)}}function ts(e){if(!e||typeof e!=`object`||Object.isFrozen(e))return e;Object.freeze(e);for(let t of Object.values(e))ts(t);return e}function ns(e){return!e||typeof e!=`object`||Object.isFrozen(e)||Object.freeze(e),e}function rs(e,t){return t?typeof t==`string`?ga(t):t:e}async function is(e,t){return t?t(e):e}async function as(e,t,n){let r=t.context&&n!==void 0?t.context.parse(n):void 0;return t.createCredential(r===void 0?{challenge:e}:{challenge:e,context:r})}const os=2048;var Z=class extends Error{name=`MppResourceUrlError`};function ss(e){if(e.length>os)throw new Z(`MPP resource URL is too long`);if(Array.from(e).some(e=>{let t=e.charCodeAt(0);return e===`\\`||t<=32||t===127}))throw new Z(`MPP resource URL is invalid`);let t=e.match(/^([A-Za-z][A-Za-z0-9+.-]*):\/\/([^/?#]*)([^?#]*)(\?[^#]*)?(?:#.*)?$/);if(!t)throw new Z(`MPP resource URL must be absolute`);let n;try{n=new URL(e)}catch{throw new Z(`MPP resource URL is invalid`)}if(n.username||n.password)throw new Z(`MPP resource URL must not contain credentials`);let r=n.protocol.toLowerCase();if(r!==`https:`&&!(r===`http:`&&cs(n.hostname)))throw new Z(`MPP resource URL must use HTTPS or loopback HTTP`);let i=t[3]||`/`,a=t[4]||``,o=`${r}//${n.hostname.toLowerCase()}${n.port?`:${n.port}`:``}${i}${a}`;if(o.length>os)throw new Z(`MPP resource URL is too long`);return o}function cs(e){let t=e.toLowerCase();if(t===`localhost`||t===`[::1]`)return!0;let n=t.split(`.`);return n.length===4&&n[0]===`127`&&n.every(e=>/^\d{1,3}$/.test(e)&&Number(e)<=255)}const ls=/^[A-Za-z0-9_-]+$/,us=/^0x[0-9a-fA-F]{40}$/,ds=/^(?:0|[1-9]\d*)$/,fs=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?Z$/,ps=/^sha-256=:([A-Za-z0-9+/]{43}=):$/,ms=/^sha-256=([A-Za-z0-9+/]{43}=)$/,hs=new Set([`mpp_challenge_not_payable`,`mpp_network_mismatch`,`mpp_counterparty_rail_not_found`]),gs=`mpp_counterparty_rail_not_found`,_s=`mpp_network_mismatch`,vs=H({type:W(`authorization`),from:V(),to:V(),value:V(),validAfter:V(),validBefore:V(),nonce:V(),signature:V()}),ys={amount:V(),currency:V(),description:G(V()),externalId:G(V()),recipient:V()},bs=H({...ys,methodDetails:H({chainId:Vr(),credentialTypes:Yr(W(`authorization`)),decimals:W(6),permit2Address:G(V()),splits:G(qr())})}),xs=H({...ys,methodDetails:H({type:W(`evm`),evm:H({chainId:Vr(),credentialTypes:G(Yr(W(`authorization`))),decimals:W(6),permit2Address:G(V()),splits:G(qr())})})}),Ss=Ri({name:`evm`,intent:`charge`,schema:{credential:{payload:vs},request:bs}}),Cs=Ri({name:`usdc`,intent:`charge`,schema:{credential:{payload:vs},request:xs}});var ws=class extends Error{intentId;status;reasons;expiresAt;constructor(e,t){super(e),this.name=`MppPaymentError`,this.intentId=t.intentId,this.status=t.status,this.reasons=t.reasons,this.expiresAt=t.expiresAt}},Q=class extends Error{intentId;reasons;constructor(e,t={}){super(e,t.cause===void 0?void 0:{cause:t.cause}),this.name=`MppFetchPaymentError`,this.intentId=t.intentId,this.reasons=t.reasons??[]}},Ts=class extends Q{accountId;requiredNetworks;constructor(e,t,n){super(`Account ${e} cannot pay on the MPP challenge's required network${t.length===1?``:`s`}: ${t.join(`, `)}`,{reasons:n}),this.name=`MppNetworkMismatchError`,this.accountId=e,this.requiredNetworks=t}},Es=class extends Q{recipient;network;constructor(e,t,n){super(`No saved Catena counterparty rail can pay ${e} on ${t}`,{reasons:n}),this.name=`MppCounterpartyNotFoundError`,this.recipient=e,this.network=t}},Ds=class extends Q{expiresAt;constructor(e,t,n){super(`The MPP payment is awaiting human approval (intent ${e}); retry the request after approval`,{intentId:e,reasons:t}),this.name=`MppApprovalPendingError`,this.expiresAt=n}},Os=class extends Q{status;constructor(e,t,n){super(`Catena ${t} the MPP payment (intent ${e})`,{intentId:e,reasons:n}),this.name=`MppPaymentDeclinedError`,this.status=t}},ks=class extends Q{method;atomicAmount;network;recipient;resourceUrl;constructor(e,t,n,r){super(`The MPP payment could not be confirmed (intent ${e}); reconcile it with getIntent("${e}") before paying again`,{intentId:e,cause:r}),this.name=`MppSubmitInterruptedError`,this.method=t.method,this.atomicAmount=t.atomicAmount,this.network=t.network,this.recipient=t.recipient,this.resourceUrl=n}},As=class extends Q{receipt;constructor(e,t){super(`The MPP payment completed (intent ${e.intentId}) but the post-payment continuation failed; inspect getIntent("${e.intentId}") before retrying manually`,{intentId:e.intentId,cause:t}),this.name=`MppRetryFailedError`,this.receipt=e}};function js(e){let t=async({challenge:t})=>(await Hs(e,Vs(t,e.maxAtomicAmount))).credential;return[zi(Ss,{canHandleChallenge:({challenge:t})=>Us(`evm`,t,e.maxAtomicAmount)!==void 0,createCredential:t}),zi(Cs,{canHandleChallenge:({challenge:t})=>Us(`usdc`,t,e.maxAtomicAmount)!==void 0,createCredential:t})]}const Ms=Object.assign(e=>js(e),{charge:js});function Ns(e,t){let n=(t.baseFetch??globalThis.fetch).bind(globalThis),r={client:e,accountId:t.accountId,...t.maxAtomicAmount!==void 0&&{maxAtomicAmount:t.maxAtomicAmount}},i=qo({methods:Ms(r),fetch:n,polyfill:!1});return async(a,o)=>{let s=await n(a,o);if(s.status!==402||!s.headers.has(`WWW-Authenticate`))return s;let c;try{c=await i.transport.getChallenges(s,o)}catch{return s}if(c.length===0)return s;if(!T(a,o))throw new Q(`The request body cannot be replayed after MPP payment; buffer it as a string, URLSearchParams, Blob, ArrayBuffer, or typed array`);let l=Ls(a,s),{payment:u,prepared:d}=await Ps(i,s,c,o,r,l),f={intentId:u.intentId,...u.terms,resourceUrl:l};await zs(f,async()=>{await t.onPayment?.(f)});let p=ae(a,o),m=d.setCredential({...o,headers:p},u.credential),h=await zs(f,()=>n(a,m));if(h.status===402)throw new As(f,Error(`The paid MPP retry still requires payment`));return Bs(e,f.intentId,h),h}}async function Ps(e,t,n,r,i,a){let o,s=[];for(let c=0;c<5;c+=1){let l={missing:!1},u;try{u=await e.preparePayment(t,{request:r,orderChallenges:e=>{o??=e.slice(0,5).map(e=>e.index);let t=o[c],n=e.find(e=>e.index===t);return l.missing=n===void 0,n===void 0?[]:[n]}})}catch(e){let t=o??[];if(t.length===0)throw n.some(e=>Ws(e,i.maxAtomicAmount))?new Q(`Every supported charge in the MPP challenge costs more than the caller's maximum amount`,{cause:e}):new Q(`The MPP challenge offers no Catena-supported native USDC charge`,{cause:e});if(l.missing&&s.length>0){if(c+1<t.length)continue;break}throw new Q(`The selected MPP challenge could not be prepared`,{cause:e})}let d=Vs(u.challenge,i.maxAtomicAmount);try{return{payment:await Hs(i,d,a),prepared:u}}catch(e){if(e instanceof ee&&e.code!==void 0&&hs.has(e.code))s.push({error:e,terms:d.terms});else throw Fs(e,d.terms,a)}if(c+1>=(o?.length??0))break}throw Is(i.accountId,s)}function Fs(e,t,n){if(e instanceof se&&e.outcome===`unknown`)return new ks(e.intentId,t,n,e);if(!(e instanceof ws))return e;switch(e.status){case`pending`:return new Ds(e.intentId,e.reasons,e.expiresAt);case`blocked`:case`failed`:return new Os(e.intentId,e.status,e.reasons);case`processing`:case`completed`:return new Q(e.message,{intentId:e.intentId,reasons:e.reasons,cause:e})}return S(e.status)}function Is(e,t){let n=t.filter(e=>e.error.code===gs),r=t.filter(e=>e.error.code===_s),i=t.filter(e=>e.error.code!==gs&&e.error.code!==_s),a=[...new Set([...n,...r,...i].map(e=>e.error.message))],o=n.find(e=>e.error.status===404);return o?new Es(o.terms.recipient,o.terms.network,a):r.length>0&&n.length===0?new Ts(e,[...new Set(r.map(e=>e.terms.network))],a):new Q(`No supported candidate in the MPP challenge is payable from this account`,{reasons:a})}function Ls(e,t){let n;try{n=typeof e==`string`?Rs(e):e instanceof URL?e:new URL(e.url)}catch(e){throw new Q(`The MPP resource request URL must be absolute`,{cause:e})}let r;try{r=new URL(t.url||n.href)}catch(e){throw new Q(`The final MPP resource URL is invalid`,{cause:e})}if(r.origin!==n.origin)throw new Q(`Refusing to pay after a cross-origin redirect from ${n.origin} to ${r.origin}`);try{return ss(t.url||n.href)}catch(e){throw new Q(`The final MPP resource URL cannot be bound to a payment intent`,{cause:e})}}function Rs(e){try{return new URL(e)}catch{return new URL(e,globalThis.location.href)}}async function zs(e,t){try{return await t()}catch(t){throw new As(e,t)}}function Bs(e,t,n){try{let r=Ui(n);if(!fe.test(r.reference))return;le(e,t,r.reference)}catch{return}}function Vs(e,t){let n=e.method;if(n!==`evm`&&n!==`usdc`)throw Error(`Unsupported Catena MPP challenge ${e.method}/${e.intent}`);let r=Us(n,e,t);if(r===void 0)throw Error(`Catena MPP charge challenge failed validation`);return{challenge:{id:e.id,realm:e.realm,method:n,intent:`charge`,request:r.request,...e.description!==void 0&&{description:e.description},...e.digest!==void 0&&{digest:e.digest},expires:r.expires,...r.header!==void 0&&{header:r.header},...e.opaque!==void 0&&{opaque:e.opaque}},terms:r.terms}}async function Hs(e,t,n){let r=await e.client.submitIntent({action:{type:`mpp`,accountId:e.accountId,challenge:t.challenge,...n!==void 0&&{resource:{url:n}}}});return{...t,credential:nc(r,t.challenge),intentId:r.id}}function Us(e,t,n){if(t.method!==e||t.intent!==`charge`)return;let r=Zs(t);if(r===void 0)return;let i=e===`evm`?qs(t.request,n):Js(t.request,n);return i===void 0?void 0:{...r,terms:i}}function Ws(e,t){if(t===void 0||e.method!==`evm`&&e.method!==`usdc`)return!1;let n=Us(e.method,e,void 0);return n!==void 0&&BigInt(n.terms.atomicAmount)>t}function Gs(e,t){return ec(e.amount)&&(t===void 0||BigInt(e.amount)<=t)&&tc(e.currency)&&tc(e.recipient)&&(e.description===void 0||Ks(e.description,1024))&&(e.externalId===void 0||Ks(e.externalId,256))}function Ks(e,t){if(e.length>t)return!1;for(let t of e){let e=t.codePointAt(0);if(e!==void 0&&e>=55296&&e<=57343)return!1}return!0}function qs(e,t){let n=bs.safeParse(e);if(!n.success||!Gs(n.data,t))return;let{amount:r,currency:i,methodDetails:a,recipient:o}=n.data,s=Xs(a.chainId,i);return Ys(a)&&a.credentialTypes.length===1&&s!==void 0?{method:`evm`,atomicAmount:r,network:s,recipient:o}:void 0}function Js(e,t){let n=xs.safeParse(e);if(!n.success||!Gs(n.data,t))return;let{amount:r,currency:i,methodDetails:a,recipient:o}=n.data,s=a.evm,c=Xs(s.chainId,i);return Ys(s)&&(s.credentialTypes===void 0||s.credentialTypes.length===1)&&c!==void 0?{method:`usdc`,atomicAmount:r,network:c,recipient:o}:void 0}function Ys(e){return Number.isSafeInteger(e.chainId)&&e.chainId>=1&&(e.permit2Address===void 0||tc(e.permit2Address))}function Xs(e,t){if(e===8453)return t.toLowerCase()===`0x833589fcd6edb6e08f4c7c32d4f71b54bda02913`?`eip155:8453`:void 0;if(e===84532)return t.toLowerCase()===`0x036cbd53842c5426634e7929541ec2318f3dcf7e`?`eip155:84532`:void 0}function Zs(e){if(!Qs(e))return;let t=Date.parse(e.expires),n=t-Date.now();if(!Number.isFinite(t)||n<5e3||n>36e5)return;let r=A(e.request),i=new TextEncoder().encode(JSON.stringify({...e,request:r})).byteLength;return r.length>0&&r.length<=16384&&i<=32768?{request:r,expires:e.expires,header:e.header}:void 0}function Qs(e){return!(e.id.length<1||e.id.length>256||e.realm.length<1||e.realm.length>256||e.expires===void 0||!fs.test(e.expires)||e.description!==void 0&&e.description.length>1024||e.header!==void 0&&e.header!==`Payment-Authorization`||e.opaque!==void 0&&(e.opaque.length>8192||!ls.test(e.opaque))||e.digest!==void 0&&!$s(e.digest))}function $s(e){if(e.length>128)return!1;let t=ps.exec(e)??ms.exec(e);if(!t)return!1;try{let e=atob(t[1]);return e.length===32&&btoa(e)===t[1]}catch{return!1}}function ec(e){return e.length<=78&&ds.test(e)&&BigInt(e)>0n}function tc(e){return us.test(e)&&_t(e)}function nc(e,t){switch(e.status){case`completed`:{let n=_(e.data,`mpp`);if(n===void 0)throw $(`Catena MPP payment ${e.id} completed without an MPP credential`,e);if(!rc(n,t))throw $(`Catena MPP payment ${e.id} completed with a credential that does not match the selected challenge; reconcile with client.getIntent("${e.id}") before another payment attempt`,e);return n}case`pending`:throw $(`Catena MPP payment ${e.id} is pending${ac(e.reasons)}`,e);case`processing`:throw $(`Catena MPP payment ${e.id} is processing; if it was approved, re-run the paid request so a fresh challenge can consume the grant (polling never advances an approved payment); otherwise poll client.getIntent("${e.id}"), because an executing payment completes on its own`,e);case`blocked`:throw $(`Catena MPP payment ${e.id} was blocked${ac(e.reasons)}`,e);case`failed`:throw $(`Catena MPP payment ${e.id} failed${ac(e.reasons)}`,e)}return S(e.status)}function rc(e,t){if(e.trim().length===0||e.includes(`\r`)||e.includes(`
|
|
14
|
+
`))return!1;let n;try{n=ji(e)}catch{return!1}let r=n.challenge;if(r.id!==t.id||r.realm!==t.realm||r.method!==t.method||r.intent!==t.intent||r.description!==t.description||r.digest!==t.digest||r.expires!==t.expires||r.header!==t.header||r.opaque!==t.opaque||A(r.request)!==t.request)return!1;let i=vs.safeParse(n.payload),a=t.method===`evm`?bs.safeParse(r.request):xs.safeParse(r.request);if(!i.success||!a.success)return!1;let o=a.data.recipient;return tc(i.data.from)&&tc(i.data.to)&&i.data.to.toLowerCase()===o.toLowerCase()&&i.data.value===a.data.amount&&ic(i.data.validAfter)&&ic(i.data.validBefore)&&BigInt(i.data.validBefore)>BigInt(i.data.validAfter)&&/^0x[0-9a-fA-F]{64}$/.test(i.data.nonce)&&/^0x[0-9a-fA-F]{130}$/.test(i.data.signature)}function ic(e){return e.length<=78&&ds.test(e)}function $(e,t){return new ws(e,{intentId:t.id,status:t.status,reasons:t.reasons,expiresAt:t.expiresAt})}function ac(e){return e.length>0?`: ${e.join(`; `)}`:``}function oc(e){return{intentId:e.intentId,method:e.method,amountAtomicUsdc:e.atomicAmount,recipient:e.recipient,network:e.network}}const sc=/(?:^|,)\s*Payment(?![!#$%&'*+\-.^_`|~0-9A-Za-z])/i;function cc(e,t){de(e,`payment-authorization`)&&b(`--header cannot set Payment-Authorization; the payment loop attaches it after paying`),e.some(e=>e.name.toLowerCase()===`authorization`&&sc.test(e.value))&&b(`--header cannot provide the Payment authentication scheme in Authorization; the payment loop attaches it after paying`),pe(e,t)}const lc=v({url:x({description:`The paywalled URL to fetch (an MPP endpoint)`,required:!0,schema:Se.pipe(Se.string(),Se.url())}),account:x({description:`Source wallet account id the payment draws from`,required:!0,schema:be}),maxAmount:x({description:`Refuse challenges above this USD amount (decimal string, e.g. 0.25). Policy limits still apply server-side.`,schema:Se.pipe(Se.string(),Se.regex(/^\d+(\.\d{1,6})?$/))}),method:ne({description:`HTTP method for the request`,choices:[`GET`,`POST`]}),data:x({description:`Request body. Use @path to read a file or @- for stdin. Implies POST and a JSON content type unless overridden.`}),contentType:x({description:`Content-Type header for the request body (default application/json when --data is set)`}),output:x({description:`Write the full response body to this file (must be a regular file; written for any HTTP status — check .status). Without it .body is capped at 4000 characters; longer or non-UTF-8 bodies are saved to a file (path reported in .bodyPath)`}),header:ye({description:`Request header as "Name: Value" (repeatable, like curl -H); sent on both requests, except caller Authorization is replaced on the paid retry when MPP uses that field for its credential`,schema:w}),profile:te,json:ve}),uc=xe({meta:{name:`mpp`,description:`Fetch a URL, paying its MPP challenge via USDC`},args:lc.args,async run({args:e,rawArgs:t}){let n=lc.parse(e,t),r=n.method??(n.data===void 0?`GET`:`POST`);n.data!==void 0&&r!==`POST`&&b(`--data cannot be sent with --method ${r}; a body requires POST`),n.contentType!==void 0&&n.data===void 0&&b(`--content-type has no effect without --data`),cc(n.header,n.contentType);let i=n.output===void 0?void 0:ue(n.output),a=n.data===void 0?void 0:re(n.data),o=oe(n.header,n.contentType,a);await _e(n)(async e=>{let t,s=Ns(e,{accountId:n.account,...n.maxAmount!==void 0&&{maxAtomicAmount:ie(n.maxAmount)},onPayment:e=>{t=e}}),c;try{c=await s(n.url,{method:r,...a!==void 0&&{body:a},...o!==void 0&&{headers:o}})}catch(e){if(e instanceof ks&&e.intentId!==void 0)throw Error(ge(e.intentId,n.profile),{cause:e});if(e instanceof As)return{status:null,paid:!0,retryFailed:!0,payment:oc(e.receipt),error:e.message};if(e instanceof Ts){let t=e.requiredNetworks.map(e=>me(e)??e);return{status:null,paid:!1,retryFailed:!1,networkMismatch:{account:e.accountId,requiredNetworks:t,requiredNetworkIds:[...e.requiredNetworks]},error:`${e.message}. Re-run with --account set to a wallet account on ${t.join(` or `)} (your account ids are in \`catena accounts list${ce(n.profile)}\`).`}}if(e instanceof Es){let t=C(e.recipient,e.network,void 0,n.profile);return{status:null,paid:!1,retryFailed:!1,counterpartyNotFound:{recipient:e.recipient,network:me(e.network)??e.network,networkId:e.network,createCommand:t,nameIsPlaceholder:!0},error:`${e.message}. Add it, then re-run:\n ${t}\n(counterparty creation may require approval per your policy)`}}if(e instanceof Ds)return{status:null,paid:!1,retryFailed:!1,approvalPending:{intentId:e.intentId,expiresAt:e.expiresAt,reasons:[...e.reasons]},error:e.message};throw e}let l={status:c.status,paid:t!==void 0,retryFailed:!1,...t!==void 0&&{payment:oc(t)}},u;try{u=Buffer.from(await c.arrayBuffer())}catch(e){let r=t===void 0?``:`; the payment completed — inspect it with \`catena intents get ${t.intentId}${ce(n.profile)}\` before any manual retry`;return{...l,error:`failed to read the response body: ${y(e)}${r}`}}return{...l,...he(u,t?.intentId,i)}},{exitCode:e=>+(`error`in e)})}});export{uc as mppCommand};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./utils-
|
|
1
|
+
import{t as e}from"./utils-CrMT-n--.mjs";import*as t from"crypto";const n=async n=>{let{content:r,publicKey:i,privateKey:a}=n,o=t.createPrivateKey({key:e({uncompressedPrivateKeyHex:a,compressedPublicKeyHex:i}),format:`jwk`}),s=t.createSign(`SHA256`);return s.write(Buffer.from(r)),s.end(),s.sign(o,`hex`)};export{n as signWithApiKey};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import{O as e,S as t,b as n,d as r,g as i,i as a,m as o,n as s,p as c,r as l,v as u,x as d}from"./dist-w03V0QPF.mjs";import{t as f}from"./hmac-CXnNqvhW.mjs";
|
|
2
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
3
|
+
const p=BigInt(0),m=BigInt(1);function h(e,t=``){if(typeof e!=`boolean`){let n=t&&`"${t}"`;throw Error(n+`expected boolean, got type=`+typeof e)}return e}function g(e,t,n=``){let r=d(e),i=e?.length,a=t!==void 0;if(!r||a&&i!==t){let o=n&&`"${n}" `,s=a?` of length ${t}`:``,c=r?`length=${i}`:`type=${typeof e}`;throw Error(o+`expected Uint8Array`+s+`, got `+c)}return e}function _(e){let t=e.toString(16);return t.length&1?`0`+t:t}function v(e){if(typeof e!=`string`)throw Error(`hex string expected, got `+typeof e);return e===``?p:BigInt(`0x`+e)}function y(e){return v(i(e))}function b(e){return r(e),v(i(Uint8Array.from(e).reverse()))}function x(e,t){return n(e.toString(16).padStart(t*2,`0`))}function S(e,t){return x(e,t).reverse()}function C(e,t,r){let i;if(typeof t==`string`)try{i=n(t)}catch(t){throw Error(e+` must be hex string or Uint8Array, cause: `+t)}else if(d(t))i=Uint8Array.from(t);else throw Error(e+` must be hex string or Uint8Array`);let a=i.length;if(typeof r==`number`&&a!==r)throw Error(e+` of length `+r+` expected, got `+a);return i}const w=e=>typeof e==`bigint`&&p<=e;function T(e,t,n){return w(e)&&w(t)&&w(n)&&t<=e&&e<n}function ee(e,t,n,r){if(!T(t,n,r))throw Error(`expected valid `+e+`: `+n+` <= n < `+r+`, got `+t)}function E(e){let t=0;for(;e>p;e>>=m,t+=1);return t}const D=e=>(m<<BigInt(e))-m;function te(e,t,n){if(typeof e!=`number`||e<2)throw Error(`hashLen must be a number`);if(typeof t!=`number`||t<2)throw Error(`qByteLen must be a number`);if(typeof n!=`function`)throw Error(`hmacFn must be a function`);let r=e=>new Uint8Array(e),i=e=>Uint8Array.of(e),a=r(e),o=r(e),s=0,c=()=>{a.fill(1),o.fill(0),s=0},l=(...e)=>n(o,a,...e),d=(e=r(0))=>{o=l(i(0),e),a=l(),e.length!==0&&(o=l(i(1),e),a=l())},f=()=>{if(s++>=1e3)throw Error(`drbg: tried 1000 values`);let e=0,n=[];for(;e<t;){a=l();let t=a.slice();n.push(t),e+=a.length}return u(...n)};return(e,t)=>{c(),d(e);let n;for(;!(n=t(f()));)d();return c(),n}}function ne(e,t,n={}){if(!e||typeof e!=`object`)throw Error(`expected valid options object`);function r(t,n,r){let i=e[t];if(r&&i===void 0)return;let a=typeof i;if(a!==n||i===null)throw Error(`param "${t}" is invalid: expected ${n}, got ${a}`)}Object.entries(t).forEach(([e,t])=>r(e,t,!1)),Object.entries(n).forEach(([e,t])=>r(e,t,!0))}function O(e){let t=new WeakMap;return(n,...r)=>{let i=t.get(n);if(i!==void 0)return i;let a=e(n,...r);return t.set(n,a),a}}
|
|
4
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
5
|
+
const k=BigInt(0),A=BigInt(1),j=BigInt(2),M=BigInt(3),re=BigInt(4),N=BigInt(5),P=BigInt(7),ie=BigInt(8),ae=BigInt(9),oe=BigInt(16);function F(e,t){let n=e%t;return n>=k?n:t+n}function se(e,t){if(e===k)throw Error(`invert: expected non-zero number`);if(t<=k)throw Error(`invert: expected positive modulus, got `+t);let n=F(e,t),r=t,i=k,a=A,o=A,s=k;for(;n!==k;){let e=r/n,t=r%n,c=i-o*e,l=a-s*e;r=n,n=t,i=o,a=s,o=c,s=l}if(r!==A)throw Error(`invert: does not exist`);return F(i,t)}function ce(e,t,n){if(!e.eql(e.sqr(t),n))throw Error(`Cannot find square root`)}function le(e,t){let n=(e.ORDER+A)/re,r=e.pow(t,n);return ce(e,r,t),r}function ue(e,t){let n=(e.ORDER-N)/ie,r=e.mul(t,j),i=e.pow(r,n),a=e.mul(t,i),o=e.mul(e.mul(a,j),i),s=e.mul(a,e.sub(o,e.ONE));return ce(e,s,t),s}function de(e){let t=I(e),n=fe(e),r=n(t,t.neg(t.ONE)),i=n(t,r),a=n(t,t.neg(r)),o=(e+P)/oe;return(e,t)=>{let n=e.pow(t,o),s=e.mul(n,r),c=e.mul(n,i),l=e.mul(n,a),u=e.eql(e.sqr(s),t),d=e.eql(e.sqr(c),t);n=e.cmov(n,s,u),s=e.cmov(l,c,d);let f=e.eql(e.sqr(s),t),p=e.cmov(n,s,f);return ce(e,p,t),p}}function fe(e){if(e<M)throw Error(`sqrt is not defined for small field`);let t=e-A,n=0;for(;t%j===k;)t/=j,n++;let r=j,i=I(e);for(;ve(i,r)===1;)if(r++>1e3)throw Error(`Cannot find square root: probably non-prime P`);if(n===1)return le;let a=i.pow(r,t),o=(t+A)/j;return function(e,r){if(e.is0(r))return r;if(ve(e,r)!==1)throw Error(`Cannot find square root`);let i=n,s=e.mul(e.ONE,a),c=e.pow(r,t),l=e.pow(r,o);for(;!e.eql(c,e.ONE);){if(e.is0(c))return e.ZERO;let t=1,n=e.sqr(c);for(;!e.eql(n,e.ONE);)if(t++,n=e.sqr(n),t===i)throw Error(`Cannot find square root`);let r=A<<BigInt(i-t-1),a=e.pow(s,r);i=t,s=e.sqr(a),c=e.mul(c,s),l=e.mul(l,a)}return l}}function pe(e){return e%re===M?le:e%ie===N?ue:e%oe===ae?de(e):fe(e)}const me=[`create`,`isValid`,`is0`,`neg`,`inv`,`sqrt`,`sqr`,`eql`,`add`,`sub`,`mul`,`pow`,`div`,`addN`,`subN`,`mulN`,`sqrN`];function he(e){return ne(e,me.reduce((e,t)=>(e[t]=`function`,e),{ORDER:`bigint`,MASK:`bigint`,BYTES:`number`,BITS:`number`})),e}function ge(e,t,n){if(n<k)throw Error(`invalid exponent, negatives unsupported`);if(n===k)return e.ONE;if(n===A)return t;let r=e.ONE,i=t;for(;n>k;)n&A&&(r=e.mul(r,i)),i=e.sqr(i),n>>=A;return r}function _e(e,t,n=!1){let r=Array(t.length).fill(n?e.ZERO:void 0),i=t.reduce((t,n,i)=>e.is0(n)?t:(r[i]=t,e.mul(t,n)),e.ONE),a=e.inv(i);return t.reduceRight((t,n,i)=>e.is0(n)?t:(r[i]=e.mul(t,r[i]),e.mul(t,n)),a),r}function ve(e,t){let n=(e.ORDER-A)/j,r=e.pow(t,n),i=e.eql(r,e.ONE),a=e.eql(r,e.ZERO),o=e.eql(r,e.neg(e.ONE));if(!i&&!a&&!o)throw Error(`invalid Legendre symbol result`);return i?1:a?0:-1}function ye(e,t){t!==void 0&&o(t);let n=t===void 0?e.toString(2).length:t;return{nBitLength:n,nByteLength:Math.ceil(n/8)}}function I(e,t,n=!1,r={}){if(e<=k)throw Error(`invalid field: expected ORDER > 0, got `+e);let i,a,o=!1,s;if(typeof t==`object`&&t){if(r.sqrt||n)throw Error(`cannot specify opts in two arguments`);let e=t;e.BITS&&(i=e.BITS),e.sqrt&&(a=e.sqrt),typeof e.isLE==`boolean`&&(n=e.isLE),typeof e.modFromBytes==`boolean`&&(o=e.modFromBytes),s=e.allowedLengths}else typeof t==`number`&&(i=t),r.sqrt&&(a=r.sqrt);let{nBitLength:c,nByteLength:l}=ye(e,i);if(l>2048)throw Error(`invalid field: expected ORDER of <= 2048 bytes`);let u,d=Object.freeze({ORDER:e,isLE:n,BITS:c,BYTES:l,MASK:D(c),ZERO:k,ONE:A,allowedLengths:s,create:t=>F(t,e),isValid:t=>{if(typeof t!=`bigint`)throw Error(`invalid field element: expected bigint, got `+typeof t);return k<=t&&t<e},is0:e=>e===k,isValidNot0:e=>!d.is0(e)&&d.isValid(e),isOdd:e=>(e&A)===A,neg:t=>F(-t,e),eql:(e,t)=>e===t,sqr:t=>F(t*t,e),add:(t,n)=>F(t+n,e),sub:(t,n)=>F(t-n,e),mul:(t,n)=>F(t*n,e),pow:(e,t)=>ge(d,e,t),div:(t,n)=>F(t*se(n,e),e),sqrN:e=>e*e,addN:(e,t)=>e+t,subN:(e,t)=>e-t,mulN:(e,t)=>e*t,inv:t=>se(t,e),sqrt:a||(t=>(u||=pe(e),u(d,t))),toBytes:e=>n?S(e,l):x(e,l),fromBytes:(t,r=!0)=>{if(s){if(!s.includes(t.length)||t.length>l)throw Error(`Field.fromBytes: expected `+s+` bytes, got `+t.length);let e=new Uint8Array(l);e.set(t,n?0:e.length-t.length),t=e}if(t.length!==l)throw Error(`Field.fromBytes: expected `+l+` bytes, got `+t.length);let i=n?b(t):y(t);if(o&&(i=F(i,e)),!r&&!d.isValid(i))throw Error(`invalid field element: outside of range 0..ORDER`);return i},invertBatch:e=>_e(d,e),cmov:(e,t,n)=>n?t:e});return Object.freeze(d)}function be(e){if(typeof e!=`bigint`)throw Error(`field order must be bigint`);let t=e.toString(2).length;return Math.ceil(t/8)}function xe(e){let t=be(e);return t+Math.ceil(t/2)}function Se(e,t,n=!1){let r=e.length,i=be(t),a=xe(t);if(r<16||r<a||r>1024)throw Error(`expected `+a+`-1024 bytes of input, got `+r);let o=F(n?b(e):y(e),t-A)+A;return n?S(o,i):x(o,i)}
|
|
6
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
7
|
+
const L=BigInt(0),R=BigInt(1);function z(e,t){let n=t.negate();return e?n:t}function Ce(e,t){let n=_e(e.Fp,t.map(e=>e.Z));return t.map((t,r)=>e.fromAffine(t.toAffine(n[r])))}function we(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw Error(`invalid window size, expected [1..`+t+`], got W=`+e)}function Te(e,t){we(e,t);let n=Math.ceil(t/e)+1,r=2**(e-1),i=2**e;return{windows:n,windowSize:r,mask:D(e),maxNumber:i,shiftBy:BigInt(e)}}function Ee(e,t,n){let{windowSize:r,mask:i,maxNumber:a,shiftBy:o}=n,s=Number(e&i),c=e>>o;s>r&&(s-=a,c+=R);let l=t*r,u=l+Math.abs(s)-1,d=s===0,f=s<0,p=t%2!=0;return{nextN:c,offset:u,isZero:d,isNeg:f,isNegF:p,offsetF:l}}function De(e,t){if(!Array.isArray(e))throw Error(`array expected`);e.forEach((e,n)=>{if(!(e instanceof t))throw Error(`invalid point at index `+n)})}function Oe(e,t){if(!Array.isArray(e))throw Error(`array of scalars expected`);e.forEach((e,n)=>{if(!t.isValid(e))throw Error(`invalid scalar at index `+n)})}const ke=new WeakMap,Ae=new WeakMap;function B(e){return Ae.get(e)||1}function je(e){if(e!==L)throw Error(`invalid wNAF`)}var Me=class{constructor(e,t){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=t}_unsafeLadder(e,t,n=this.ZERO){let r=e;for(;t>L;)t&R&&(n=n.add(r)),r=r.double(),t>>=R;return n}precomputeWindow(e,t){let{windows:n,windowSize:r}=Te(t,this.bits),i=[],a=e,o=a;for(let e=0;e<n;e++){o=a,i.push(o);for(let e=1;e<r;e++)o=o.add(a),i.push(o);a=o.double()}return i}wNAF(e,t,n){if(!this.Fn.isValid(n))throw Error(`invalid scalar`);let r=this.ZERO,i=this.BASE,a=Te(e,this.bits);for(let e=0;e<a.windows;e++){let{nextN:o,offset:s,isZero:c,isNeg:l,isNegF:u,offsetF:d}=Ee(n,e,a);n=o,c?i=i.add(z(u,t[d])):r=r.add(z(l,t[s]))}return je(n),{p:r,f:i}}wNAFUnsafe(e,t,n,r=this.ZERO){let i=Te(e,this.bits);for(let e=0;e<i.windows&&n!==L;e++){let{nextN:a,offset:o,isZero:s,isNeg:c}=Ee(n,e,i);if(n=a,!s){let e=t[o];r=r.add(c?e.negate():e)}}return je(n),r}getPrecomputes(e,t,n){let r=ke.get(t);return r||(r=this.precomputeWindow(t,e),e!==1&&(typeof n==`function`&&(r=n(r)),ke.set(t,r))),r}cached(e,t,n){let r=B(e);return this.wNAF(r,this.getPrecomputes(r,e,n),t)}unsafe(e,t,n,r){let i=B(e);return i===1?this._unsafeLadder(e,t,r):this.wNAFUnsafe(i,this.getPrecomputes(i,e,n),t,r)}createCache(e,t){we(t,this.bits),Ae.set(e,t),ke.delete(e)}hasCache(e){return B(e)!==1}};function Ne(e,t,n,r){let i=t,a=e.ZERO,o=e.ZERO;for(;n>L||r>L;)n&R&&(a=a.add(i)),r&R&&(o=o.add(i)),i=i.double(),n>>=R,r>>=R;return{p1:a,p2:o}}function Pe(e,t,n,r){De(n,e),Oe(r,t);let i=n.length,a=r.length;if(i!==a)throw Error(`arrays of points and scalars must have equal length`);let o=e.ZERO,s=E(BigInt(i)),c=1;s>12?c=s-3:s>4?c=s-2:s>0&&(c=2);let l=D(c),u=Array(Number(l)+1).fill(o),d=Math.floor((t.BITS-1)/c)*c,f=o;for(let e=d;e>=0;e-=c){u.fill(o);for(let t=0;t<a;t++){let i=r[t],a=Number(i>>BigInt(e)&l);u[a]=u[a].add(n[t])}let t=o;for(let e=u.length-1,n=o;e>0;e--)n=n.add(u[e]),t=t.add(n);if(f=f.add(t),e!==0)for(let e=0;e<c;e++)f=f.double()}return f}function Fe(e,t,n){if(t){if(t.ORDER!==e)throw Error(`Field.ORDER must match order: Fp == p, Fn == n`);return he(t),t}return I(e,{isLE:n})}function Ie(e,t,n={},r){if(r===void 0&&(r=e===`edwards`),!t||typeof t!=`object`)throw Error(`expected valid ${e} CURVE object`);for(let e of[`p`,`n`,`h`]){let n=t[e];if(!(typeof n==`bigint`&&n>L))throw Error(`CURVE.${e} must be positive bigint`)}let i=Fe(t.p,n.Fp,r),a=Fe(t.n,n.Fn,r),o=[`Gx`,`Gy`,`a`,e===`weierstrass`?`b`:`d`];for(let e of o)if(!i.isValid(t[e]))throw Error(`CURVE.${e} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:i,Fn:a}}
|
|
8
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
9
|
+
const Le=(e,t)=>(e+(e>=0?t:-t)/ze)/t;function Re(e,t,n){let[[r,i],[a,o]]=t,s=Le(o*e,n),c=Le(-i*e,n),l=e-s*r-c*a,u=-s*i-c*o,d=l<W,f=u<W;d&&(l=-l),f&&(u=-u);let p=D(Math.ceil(E(n)/2))+G;if(l<W||l>=p||u<W||u>=p)throw Error(`splitScalar (endomorphism): failed, k=`+e);return{k1neg:d,k1:l,k2neg:f,k2:u}}function V(e){if(![`compact`,`recovered`,`der`].includes(e))throw Error(`Signature format must be "compact", "recovered", or "der"`);return e}function H(e,t){let n={};for(let r of Object.keys(t))n[r]=e[r]===void 0?t[r]:e[r];return h(n.lowS,`lowS`),h(n.prehash,`prehash`),n.format!==void 0&&V(n.format),n}const U={Err:class extends Error{constructor(e=``){super(e)}},_tlv:{encode:(e,t)=>{let{Err:n}=U;if(e<0||e>256)throw new n(`tlv.encode: wrong tag`);if(t.length&1)throw new n(`tlv.encode: unpadded data`);let r=t.length/2,i=_(r);if(i.length/2&128)throw new n(`tlv.encode: long form length too big`);let a=r>127?_(i.length/2|128):``;return _(e)+a+i+t},decode(e,t){let{Err:n}=U,r=0;if(e<0||e>256)throw new n(`tlv.encode: wrong tag`);if(t.length<2||t[r++]!==e)throw new n(`tlv.decode: wrong tlv`);let i=t[r++],a=!!(i&128),o=0;if(!a)o=i;else{let e=i&127;if(!e)throw new n(`tlv.decode(long): indefinite length not supported`);if(e>4)throw new n(`tlv.decode(long): byte length is too big`);let a=t.subarray(r,r+e);if(a.length!==e)throw new n(`tlv.decode: length bytes not complete`);if(a[0]===0)throw new n(`tlv.decode(long): zero leftmost byte`);for(let e of a)o=o<<8|e;if(r+=e,o<128)throw new n(`tlv.decode(long): not minimal encoding`)}let s=t.subarray(r,r+o);if(s.length!==o)throw new n(`tlv.decode: wrong value length`);return{v:s,l:t.subarray(r+o)}}},_int:{encode(e){let{Err:t}=U;if(e<W)throw new t(`integer: negative integers are not allowed`);let n=_(e);if(Number.parseInt(n[0],16)&8&&(n=`00`+n),n.length&1)throw new t(`unexpected DER parsing assertion: unpadded hex`);return n},decode(e){let{Err:t}=U;if(e[0]&128)throw new t(`invalid signature integer: negative`);if(e[0]===0&&!(e[1]&128))throw new t(`invalid signature integer: unnecessary leading zero`);return y(e)}},toSig(e){let{Err:t,_int:n,_tlv:r}=U,i=C(`signature`,e),{v:a,l:o}=r.decode(48,i);if(o.length)throw new t(`invalid signature: left bytes after parsing`);let{v:s,l:c}=r.decode(2,a),{v:l,l:u}=r.decode(2,c);if(u.length)throw new t(`invalid signature: left bytes after parsing`);return{r:n.decode(s),s:n.decode(l)}},hexFromSig(e){let{_tlv:t,_int:n}=U,r=t.encode(2,n.encode(e.r))+t.encode(2,n.encode(e.s));return t.encode(48,r)}},W=BigInt(0),G=BigInt(1),ze=BigInt(2),K=BigInt(3),Be=BigInt(4);function q(e,t){let{BYTES:n}=e,r;if(typeof t==`bigint`)r=t;else{let i=C(`private key`,t);try{r=e.fromBytes(i)}catch{throw Error(`invalid private key: expected ui8a of size ${n}, got ${typeof t}`)}}if(!e.isValidNot0(r))throw Error(`invalid private key: out of range [1..N-1]`);return r}function Ve(e,t={}){let n=Ie(`weierstrass`,e,t),{Fp:r,Fn:a}=n,o=n.CURVE,{h:s,n:c}=o;ne(t,{},{allowInfinityPoint:`boolean`,clearCofactor:`function`,isTorsionFree:`function`,fromBytes:`function`,toBytes:`function`,endo:`object`,wrapPrivateKey:`boolean`});let{endo:l}=t;if(l&&(!r.is0(o.a)||typeof l.beta!=`bigint`||!Array.isArray(l.basises)))throw Error(`invalid endo: expected "beta": bigint and "basises": array`);let d=Ue(r,a);function f(){if(!r.isOdd)throw Error(`compression is not supported: Field does not have .isOdd()`)}function p(e,t,n){let{x:i,y:a}=t.toAffine(),o=r.toBytes(i);if(h(n,`isCompressed`),n){f();let e=!r.isOdd(a);return u(He(e),o)}return u(Uint8Array.of(4),o,r.toBytes(a))}function m(e){g(e,void 0,`Point`);let{publicKey:t,publicKeyUncompressed:n}=d,i=e.length,a=e[0],o=e.subarray(1);if(i===t&&(a===2||a===3)){let e=r.fromBytes(o);if(!r.isValid(e))throw Error(`bad point: is not on curve, wrong x`);let t=y(e),n;try{n=r.sqrt(t)}catch(e){let t=e instanceof Error?`: `+e.message:``;throw Error(`bad point: is not on curve, sqrt error`+t)}f();let i=r.isOdd(n);return(a&1)==1!==i&&(n=r.neg(n)),{x:e,y:n}}if(i===n&&a===4){let e=r.BYTES,t=r.fromBytes(o.subarray(0,e)),n=r.fromBytes(o.subarray(e,e*2));if(!b(t,n))throw Error(`bad point: is not on curve`);return{x:t,y:n}}throw Error(`bad point: got length ${i}, expected compressed=${t} or uncompressed=${n}`)}let _=t.toBytes||p,v=t.fromBytes||m;function y(e){let t=r.sqr(e),n=r.mul(t,e);return r.add(r.add(n,r.mul(e,o.a)),o.b)}function b(e,t){let n=r.sqr(t),i=y(e);return r.eql(n,i)}if(!b(o.Gx,o.Gy))throw Error(`bad curve params: generator point`);let x=r.mul(r.pow(o.a,K),Be),S=r.mul(r.sqr(o.b),BigInt(27));if(r.is0(r.add(x,S)))throw Error(`bad curve params: a or b`);function w(e,t,n=!1){if(!r.isValid(t)||n&&r.is0(t))throw Error(`bad point coordinate ${e}`);return t}function T(e){if(!(e instanceof k))throw Error(`ProjectivePoint expected`)}function ee(e){if(!l||!l.basises)throw Error(`no endo`);return Re(e,l.basises,a.ORDER)}let E=O((e,t)=>{let{X:n,Y:i,Z:a}=e;if(r.eql(a,r.ONE))return{x:n,y:i};let o=e.is0();t??=o?r.ONE:r.inv(a);let s=r.mul(n,t),c=r.mul(i,t),l=r.mul(a,t);if(o)return{x:r.ZERO,y:r.ZERO};if(!r.eql(l,r.ONE))throw Error(`invZ was invalid`);return{x:s,y:c}}),D=O(e=>{if(e.is0()){if(t.allowInfinityPoint&&!r.is0(e.Y))return;throw Error(`bad point: ZERO`)}let{x:n,y:i}=e.toAffine();if(!r.isValid(n)||!r.isValid(i))throw Error(`bad point: x or y not field elements`);if(!b(n,i))throw Error(`bad point: equation left != right`);if(!e.isTorsionFree())throw Error(`bad point: not in prime-order subgroup`);return!0});function te(e,t,n,i,a){return n=new k(r.mul(n.X,e),n.Y,n.Z),t=z(i,t),n=z(a,n),t.add(n)}class k{constructor(e,t,n){this.X=w(`x`,e),this.Y=w(`y`,t,!0),this.Z=w(`z`,n),Object.freeze(this)}static CURVE(){return o}static fromAffine(e){let{x:t,y:n}=e||{};if(!e||!r.isValid(t)||!r.isValid(n))throw Error(`invalid affine point`);if(e instanceof k)throw Error(`projective point not allowed`);return r.is0(t)&&r.is0(n)?k.ZERO:new k(t,n,r.ONE)}static fromBytes(e){let t=k.fromAffine(v(g(e,void 0,`point`)));return t.assertValidity(),t}static fromHex(e){return k.fromBytes(C(`pointHex`,e))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(e=8,t=!0){return j.createCache(this,e),t||this.multiply(K),this}assertValidity(){D(this)}hasEvenY(){let{y:e}=this.toAffine();if(!r.isOdd)throw Error(`Field doesn't support isOdd`);return!r.isOdd(e)}equals(e){T(e);let{X:t,Y:n,Z:i}=this,{X:a,Y:o,Z:s}=e,c=r.eql(r.mul(t,s),r.mul(a,i)),l=r.eql(r.mul(n,s),r.mul(o,i));return c&&l}negate(){return new k(this.X,r.neg(this.Y),this.Z)}double(){let{a:e,b:t}=o,n=r.mul(t,K),{X:i,Y:a,Z:s}=this,c=r.ZERO,l=r.ZERO,u=r.ZERO,d=r.mul(i,i),f=r.mul(a,a),p=r.mul(s,s),m=r.mul(i,a);return m=r.add(m,m),u=r.mul(i,s),u=r.add(u,u),c=r.mul(e,u),l=r.mul(n,p),l=r.add(c,l),c=r.sub(f,l),l=r.add(f,l),l=r.mul(c,l),c=r.mul(m,c),u=r.mul(n,u),p=r.mul(e,p),m=r.sub(d,p),m=r.mul(e,m),m=r.add(m,u),u=r.add(d,d),d=r.add(u,d),d=r.add(d,p),d=r.mul(d,m),l=r.add(l,d),p=r.mul(a,s),p=r.add(p,p),d=r.mul(p,m),c=r.sub(c,d),u=r.mul(p,f),u=r.add(u,u),u=r.add(u,u),new k(c,l,u)}add(e){T(e);let{X:t,Y:n,Z:i}=this,{X:a,Y:s,Z:c}=e,l=r.ZERO,u=r.ZERO,d=r.ZERO,f=o.a,p=r.mul(o.b,K),m=r.mul(t,a),h=r.mul(n,s),g=r.mul(i,c),_=r.add(t,n),v=r.add(a,s);_=r.mul(_,v),v=r.add(m,h),_=r.sub(_,v),v=r.add(t,i);let y=r.add(a,c);return v=r.mul(v,y),y=r.add(m,g),v=r.sub(v,y),y=r.add(n,i),l=r.add(s,c),y=r.mul(y,l),l=r.add(h,g),y=r.sub(y,l),d=r.mul(f,v),l=r.mul(p,g),d=r.add(l,d),l=r.sub(h,d),d=r.add(h,d),u=r.mul(l,d),h=r.add(m,m),h=r.add(h,m),g=r.mul(f,g),v=r.mul(p,v),h=r.add(h,g),g=r.sub(m,g),g=r.mul(f,g),v=r.add(v,g),m=r.mul(h,v),u=r.add(u,m),m=r.mul(y,v),l=r.mul(_,l),l=r.sub(l,m),m=r.mul(_,h),d=r.mul(y,d),d=r.add(d,m),new k(l,u,d)}subtract(e){return this.add(e.negate())}is0(){return this.equals(k.ZERO)}multiply(e){let{endo:n}=t;if(!a.isValidNot0(e))throw Error(`invalid scalar: out of range`);let r,i,o=e=>j.cached(this,e,e=>Ce(k,e));if(n){let{k1neg:t,k1:a,k2neg:s,k2:c}=ee(e),{p:l,f:u}=o(a),{p:d,f}=o(c);i=u.add(f),r=te(n.beta,l,d,t,s)}else{let{p:t,f:n}=o(e);r=t,i=n}return Ce(k,[r,i])[0]}multiplyUnsafe(e){let{endo:n}=t,r=this;if(!a.isValid(e))throw Error(`invalid scalar: out of range`);if(e===W||r.is0())return k.ZERO;if(e===G)return r;if(j.hasCache(this))return this.multiply(e);if(n){let{k1neg:t,k1:i,k2neg:a,k2:o}=ee(e),{p1:s,p2:c}=Ne(k,r,i,o);return te(n.beta,s,c,t,a)}return j.unsafe(r,e)}multiplyAndAddUnsafe(e,t,n){let r=this.multiplyUnsafe(t).add(e.multiplyUnsafe(n));return r.is0()?void 0:r}toAffine(e){return E(this,e)}isTorsionFree(){let{isTorsionFree:e}=t;return s===G?!0:e?e(k,this):j.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:e}=t;return s===G?this:e?e(k,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(e=!0){return h(e,`isCompressed`),this.assertValidity(),_(k,this,e)}toHex(e=!0){return i(this.toBytes(e))}toString(){return`<Point ${this.is0()?`ZERO`:this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(e=!0){return this.toBytes(e)}_setWindowSize(e){this.precompute(e)}static normalizeZ(e){return Ce(k,e)}static msm(e,t){return Pe(k,a,e,t)}static fromPrivateKey(e){return k.BASE.multiply(q(a,e))}}k.BASE=new k(o.Gx,o.Gy,r.ONE),k.ZERO=new k(r.ZERO,r.ONE,r.ZERO),k.Fp=r,k.Fn=a;let A=a.BITS,j=new Me(k,t.endo?Math.ceil(A/2):A);return k.BASE.precompute(8),k}function He(e){return Uint8Array.of(e?2:3)}function Ue(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function We(e,n={}){let{Fn:r}=e,i=n.randomBytes||t,a=Object.assign(Ue(e.Fp,r),{seed:xe(r.ORDER)});function o(e){try{return!!q(r,e)}catch{return!1}}function s(t,n){let{publicKey:r,publicKeyUncompressed:i}=a;try{let a=t.length;return n===!0&&a!==r||n===!1&&a!==i?!1:!!e.fromBytes(t)}catch{return!1}}function c(e=i(a.seed)){return Se(g(e,a.seed,`seed`),r.ORDER)}function l(t,n=!0){return e.BASE.multiply(q(r,t)).toBytes(n)}function u(e){let t=c(e);return{secretKey:t,publicKey:l(t)}}function d(t){if(typeof t==`bigint`)return!1;if(t instanceof e)return!0;let{secretKey:n,publicKey:i,publicKeyUncompressed:o}=a;if(r.allowedLengths||n===i)return;let s=C(`key`,t).length;return s===i||s===o}function f(t,n,i=!0){if(d(t)===!0)throw Error(`first arg must be private key`);if(d(n)===!1)throw Error(`second arg must be public key`);let a=q(r,t);return e.fromHex(n).multiply(a).toBytes(i)}return Object.freeze({getPublicKey:l,getSharedSecret:f,keygen:u,Point:e,utils:{isValidSecretKey:o,isValidPublicKey:s,randomSecretKey:c,isValidPrivateKey:o,randomPrivateKey:c,normPrivateKeyToScalar:e=>q(r,e),precompute(t=8,n=e.BASE){return n.precompute(t,!1)}},lengths:a})}function Ge(e,r,a={}){c(r),ne(a,{},{hmac:`function`,lowS:`boolean`,randomBytes:`function`,bits2int:`function`,bits2int_modN:`function`});let o=a.randomBytes||t,s=a.hmac||((e,...t)=>f(r,e,u(...t))),{Fp:l,Fn:p}=e,{ORDER:m,BITS:h}=p,{keygen:_,getPublicKey:v,getSharedSecret:b,utils:x,lengths:S}=We(e,a),w={prehash:!1,lowS:typeof a.lowS==`boolean`&&a.lowS,format:void 0,extraEntropy:!1},T=`compact`;function E(e){return e>m>>G}function O(e,t){if(!p.isValidNot0(t))throw Error(`invalid signature ${e}: out of range 1..Point.Fn.ORDER`);return t}function k(e,t){V(t);let n=S.signature;return g(e,t===`compact`?n:t===`recovered`?n+1:void 0,`${t} signature`)}class A{constructor(e,t,n){this.r=O(`r`,e),this.s=O(`s`,t),n!=null&&(this.recovery=n),Object.freeze(this)}static fromBytes(e,t=T){k(e,t);let n;if(t===`der`){let{r:t,s:n}=U.toSig(g(e));return new A(t,n)}t===`recovered`&&(n=e[0],t=`compact`,e=e.subarray(1));let r=p.BYTES,i=e.subarray(0,r),a=e.subarray(r,r*2);return new A(p.fromBytes(i),p.fromBytes(a),n)}static fromHex(e,t){return this.fromBytes(n(e),t)}addRecoveryBit(e){return new A(this.r,this.s,e)}recoverPublicKey(t){let n=l.ORDER,{r,s:i,recovery:a}=this;if(a==null||![0,1,2,3].includes(a))throw Error(`recovery id invalid`);if(m*ze<n&&a>1)throw Error(`recovery id is ambiguous for h>1 curve`);let o=a===2||a===3?r+m:r;if(!l.isValid(o))throw Error(`recovery id 2 or 3 invalid`);let s=l.toBytes(o),c=e.fromBytes(u(He(!(a&1)),s)),d=p.inv(o),f=M(C(`msgHash`,t)),h=p.create(-f*d),g=p.create(i*d),_=e.BASE.multiplyUnsafe(h).add(c.multiplyUnsafe(g));if(_.is0())throw Error(`point at infinify`);return _.assertValidity(),_}hasHighS(){return E(this.s)}toBytes(e=T){if(V(e),e===`der`)return n(U.hexFromSig(this));let t=p.toBytes(this.r),r=p.toBytes(this.s);if(e===`recovered`){if(this.recovery==null)throw Error(`recovery bit must be present`);return u(Uint8Array.of(this.recovery),t,r)}return u(t,r)}toHex(e){return i(this.toBytes(e))}assertValidity(){}static fromCompact(e){return A.fromBytes(C(`sig`,e),`compact`)}static fromDER(e){return A.fromBytes(C(`sig`,e),`der`)}normalizeS(){return this.hasHighS()?new A(this.r,p.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes(`der`)}toDERHex(){return i(this.toBytes(`der`))}toCompactRawBytes(){return this.toBytes(`compact`)}toCompactHex(){return i(this.toBytes(`compact`))}}let j=a.bits2int||function(e){if(e.length>8192)throw Error(`input is too large`);let t=y(e),n=e.length*8-h;return n>0?t>>BigInt(n):t},M=a.bits2int_modN||function(e){return p.create(j(e))},re=D(h);function N(e){return ee(`num < 2^`+h,e,W,re),p.toBytes(e)}function P(e,t){return g(e,void 0,`message`),t?g(r(e),void 0,`prehashed message`):e}function ie(t,n,r){if([`recovered`,`canonical`].some(e=>e in r))throw Error(`sign() legacy options not supported`);let{lowS:i,prehash:a,extraEntropy:s}=H(r,w);t=P(t,a);let c=M(t),l=q(p,n),d=[N(l),N(c)];if(s!=null&&s!==!1){let e=s===!0?o(S.secretKey):s;d.push(C(`extraEntropy`,e))}let f=u(...d),m=c;function h(t){let n=j(t);if(!p.isValidNot0(n))return;let r=p.inv(n),a=e.BASE.multiply(n).toAffine(),o=p.create(a.x);if(o===W)return;let s=p.create(r*p.create(m+o*l));if(s===W)return;let c=(a.x===o?0:2)|Number(a.y&G),u=s;return i&&E(s)&&(u=p.neg(s),c^=1),new A(o,u,c)}return{seed:f,k2sig:h}}function ae(e,t,n={}){e=C(`message`,e);let{seed:i,k2sig:a}=ie(e,t,n);return te(r.outputLen,p.BYTES,s)(i,a)}function oe(e){let t,n=typeof e==`string`||d(e),r=!n&&typeof e==`object`&&!!e&&typeof e.r==`bigint`&&typeof e.s==`bigint`;if(!n&&!r)throw Error(`invalid signature, expected Uint8Array, hex string or Signature instance`);if(r)t=new A(e.r,e.s);else if(n){try{t=A.fromBytes(C(`sig`,e),`der`)}catch(e){if(!(e instanceof U.Err))throw e}if(!t)try{t=A.fromBytes(C(`sig`,e),`compact`)}catch{return!1}}return t||!1}function F(t,n,r,i={}){let{lowS:a,prehash:o,format:s}=H(i,w);if(r=C(`publicKey`,r),n=P(C(`message`,n),o),`strict`in i)throw Error(`options.strict was renamed to lowS`);let c=s===void 0?oe(t):A.fromBytes(C(`sig`,t),s);if(c===!1)return!1;try{let t=e.fromBytes(r);if(a&&c.hasHighS())return!1;let{r:i,s:o}=c,s=M(n),l=p.inv(o),u=p.create(s*l),d=p.create(i*l),f=e.BASE.multiplyUnsafe(u).add(t.multiplyUnsafe(d));return!f.is0()&&p.create(f.x)===i}catch{return!1}}function se(e,t,n={}){let{prehash:r}=H(n,w);return t=P(t,r),A.fromBytes(e,`recovered`).recoverPublicKey(t).toBytes()}return Object.freeze({keygen:_,getPublicKey:v,getSharedSecret:b,utils:x,lengths:S,Point:e,sign:ae,verify:F,recoverPublicKey:se,Signature:A,hash:r})}function Ke(e){let t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},n=e.Fp,r=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(e=>Math.ceil(e/2)))):void 0;return{CURVE:t,curveOpts:{Fp:n,Fn:I(t.n,{BITS:e.nBitLength,allowedLengths:r,modFromBytes:e.wrapPrivateKey}),allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes}}}function qe(e){let{CURVE:t,curveOpts:n}=Ke(e),r={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:n,hash:e.hash,ecdsaOpts:r}}function Je(e,t){let n=t.Point;return Object.assign({},t,{ProjectivePoint:n,CURVE:Object.assign({},e,ye(n.Fn.ORDER,n.Fn.BITS))})}function Ye(e){let{CURVE:t,curveOpts:n,hash:r,ecdsaOpts:i}=qe(e);return Je(e,Ge(Ve(t,n),r,i))}
|
|
10
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
11
|
+
function J(e,t){let n=t=>Ye({...e,hash:t});return{...n(t),create:n}}
|
|
12
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
13
|
+
const Xe={p:BigInt(`0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff`),n:BigInt(`0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551`),h:BigInt(1),a:BigInt(`0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc`),b:BigInt(`0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b`),Gx:BigInt(`0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296`),Gy:BigInt(`0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5`)},Ze={p:BigInt(`0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff`),n:BigInt(`0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973`),h:BigInt(1),a:BigInt(`0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000fffffffc`),b:BigInt(`0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef`),Gx:BigInt(`0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7`),Gy:BigInt(`0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f`)},Qe={p:BigInt(`0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff`),n:BigInt(`0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409`),h:BigInt(1),a:BigInt(`0x1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc`),b:BigInt(`0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00`),Gx:BigInt(`0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66`),Gy:BigInt(`0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650`)},$e=I(Xe.p),et=I(Ze.p),tt=I(Qe.p),nt=J({...Xe,Fp:$e,lowS:!1},s);J({...Ze,Fp:et,lowS:!1},l),J({...Qe,Fp:tt,lowS:!1,allowedPrivateKeyLengths:[130,131,132]},a);
|
|
14
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
15
|
+
const rt=nt,it=[1116352408,1899447441,-1245643825,-373957723,961987163,1508970993,-1841331548,-1424204075,-670586216,310598401,607225278,1426881987,1925078388,-2132889090,-1680079193,-1046744716,-459576895,-272742522,264347078,604807628,770255983,1249150122,1555081692,1996064986,-1740746414,-1473132947,-1341970488,-1084653625,-958395405,-710438585,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,-2117940946,-1838011259,-1564481375,-1474664885,-1035236496,-949202525,-778901479,-694614492,-200395387,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,-2067236844,-1933114872,-1866530822,-1538233109,-1090935817,-965641998],at={sha256:1};function ot(e){if(e&&!at[e]&&!at[e.toLowerCase()])throw Error(`Digest method not supported`);return new st}var st=class{constructor(){this.A=1779033703,this.B=-1150833019,this.C=1013904242,this.D=-1521486534,this.E=1359893119,this.F=-1694144372,this.G=528734635,this.H=1541459225,this._size=0,this._sp=0,(!X||Z>=8e3)&&(X=new ArrayBuffer(8e3),Z=0),this._byte=new Uint8Array(X,Z,80),this._word=new Int32Array(X,Z,20),Z+=80}update(e){if(typeof e==`string`)return this._utf8(e);if(e==null)throw TypeError(`Invalid type: `+typeof e);let t=e.byteOffset,n=e.byteLength,r=n/64|0,i=0;if(r&&!(t&3)&&!(this._size%64)){let n=new Int32Array(e.buffer,t,r*16);for(;r--;)this._int32(n,i>>2),i+=64;this._size+=i}if(e.BYTES_PER_ELEMENT!==1&&e.buffer){let r=new Uint8Array(e.buffer,t+i,n-i);return this._uint8(r)}return i===n?this:this._uint8(e,i)}_uint8(e,t){let{_byte:n,_word:r}=this,i=e.length;for(t|=0;t<i;){let a=this._size%64,o=a;for(;t<i&&o<64;)n[o++]=e[t++];o>=64&&this._int32(r),this._size+=o-a}return this}_utf8(e){let{_byte:t,_word:n}=this,r=e.length,i=this._sp;for(let a=0;a<r;){let o=this._size%64,s=o;for(;a<r&&s<64;){let n=e.charCodeAt(a++)|0;n<128?t[s++]=n:n<2048?(t[s++]=192|n>>>6,t[s++]=128|n&63):n<55296||n>57343?(t[s++]=224|n>>>12,t[s++]=128|n>>>6&63,t[s++]=128|n&63):i?(n=((i&1023)<<10)+(n&1023)+65536,t[s++]=240|n>>>18,t[s++]=128|n>>>12&63,t[s++]=128|n>>>6&63,t[s++]=128|n&63,i=0):i=n}s>=64&&(this._int32(n),n[0]=n[16]),this._size+=s-o}return this._sp=i,this}_int32(e,t){let{A:n,B:r,C:i,D:a,E:o,F:s,G:c,H:l}=this,u=0;for(t|=0;u<16;)Y[u++]=$(e[t++]);for(u=16;u<64;u++)Y[u]=pt(Y[u-2])+Y[u-7]+ft(Y[u-15])+Y[u-16]|0;for(u=0;u<64;u++){let e=l+dt(o)+ct(o,s,c)+it[u]+Y[u]|0,t=ut(n)+lt(n,r,i)|0;l=c,c=s,s=o,o=a+e|0,a=i,i=r,r=n,n=e+t|0}this.A=n+this.A|0,this.B=r+this.B|0,this.C=i+this.C|0,this.D=a+this.D|0,this.E=o+this.E|0,this.F=s+this.F|0,this.G=c+this.G|0,this.H=l+this.H|0}digest(e){let{_byte:t,_word:n}=this,r=this._size%64|0;for(t[r++]=128;r&3;)t[r++]=0;if(r>>=2,r>14){for(;r<16;)n[r++]=0;r=0,this._int32(n)}for(;r<16;)n[r++]=0;let i=this._size*8,a=(i&4294967295)>>>0,o=(i-a)/4294967296;return o&&(n[14]=$(o)),a&&(n[15]=$(a)),this._int32(n),e===`hex`?this._hex():this._bin()}_hex(){let{A:e,B:t,C:n,D:r,E:i,F:a,G:o,H:s}=this;return Q(e)+Q(t)+Q(n)+Q(r)+Q(i)+Q(a)+Q(o)+Q(s)}_bin(){let{A:e,B:t,C:n,D:r,E:i,F:a,G:o,H:s,_byte:c,_word:l}=this;return l[0]=$(e),l[1]=$(t),l[2]=$(n),l[3]=$(r),l[4]=$(i),l[5]=$(a),l[6]=$(o),l[7]=$(s),c.slice(0,32)}};const Y=new Int32Array(64);let X,Z=0;const Q=e=>(e+4294967296).toString(16).substr(-8),$=mt()?(e=>e):(e=>e<<24&4278190080|e<<8&16711680|e>>8&65280|e>>24&255),ct=(e,t,n)=>n^e&(t^n),lt=(e,t,n)=>e&t|n&(e|t),ut=e=>(e>>>2|e<<30)^(e>>>13|e<<19)^(e>>>22|e<<10),dt=e=>(e>>>6|e<<26)^(e>>>11|e<<21)^(e>>>25|e<<7),ft=e=>(e>>>7|e<<25)^(e>>>18|e<<14)^e>>>3,pt=e=>(e>>>17|e<<15)^(e>>>19|e<<13)^e>>>10;function mt(){return new Uint8Array(new Uint16Array([65279]).buffer)[0]===254}const ht=async t=>{let n=rt.getPublicKey(t.privateKey,!0),r=e(n);if(r!=t.publicKey)throw Error(`Bad API key. Expected to get public key ${t.publicKey}, got ${r}`);let i=ot().update(t.content).digest();return rt.sign(i,t.privateKey).toDERHex()};export{ht as signWithApiKey};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(e){throw n=[e],e}},s=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),c=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r},l=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},u=(n,r,o)=>(o=n==null?{}:e(i(n)),l(r||!n||!n.__esModule||!a.call(n,`default`)?t(o,`default`,{value:n,enumerable:!0}):o,n)),d=e=>a.call(e,`module.exports`)?e[`module.exports`]:l(t({},`__esModule`,{value:!0}),e);export{u as a,d as i,o as n,c as r,s as t};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{D as e}from"./dist-w03V0QPF.mjs";import{j as t}from"./index.mjs";
|
|
2
2
|
/**
|
|
3
3
|
* Code modified from https://github.com/google/tink/blob/6f74b99a2bfe6677e3670799116a57268fd067fa/javascript/subtle/bytes.ts
|
|
4
4
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{O as e}from"./dist-w03V0QPF.mjs";import{t}from"./utils-CrMT-n--.mjs";const n=async e=>{let{content:t,publicKey:n,privateKey:a}=e;return await i({key:await r({uncompressedPrivateKeyHex:a,compressedPublicKeyHex:n}),content:t})};async function r(e){let{uncompressedPrivateKeyHex:n,compressedPublicKeyHex:r}=e,i=t({uncompressedPrivateKeyHex:n,compressedPublicKeyHex:r});return await crypto.subtle.importKey(`jwk`,i,{name:`ECDSA`,namedCurve:`P-256`},!1,[`sign`])}async function i(t){let{key:n,content:r}=t,i=await crypto.subtle.sign({name:`ECDSA`,hash:`SHA-256`},n,new TextEncoder().encode(r)),o=a(new Uint8Array(i));return e(o)}function a(e){if(e.length%2!=0||e.length==0||e.length>132)throw Error(`Invalid IEEE P1363 signature encoding. Length: `+e.length);let t=o(e.subarray(0,e.length/2)),n=o(e.subarray(e.length/2,e.length)),r=0,i=2+t.length+1+1+n.length,a;return i>=128?(a=new Uint8Array(i+3),a[r++]=48,a[r++]=129,a[r++]=i):(a=new Uint8Array(i+2),a[r++]=48,a[r++]=i),a[r++]=2,a[r++]=t.length,a.set(t,r),r+=t.length,a[r++]=2,a[r++]=n.length,a.set(n,r),a}function o(e){let t=0;for(;t<e.length&&e[t]==0;)t++;t==e.length&&(t=e.length-1);let n=0;(e[t]&128)==128&&(n=1);let r=new Uint8Array(e.length-t+n);return r.set(e.subarray(t),n),r}export{n as signWithApiKey};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@catena/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Catena CLI for agent runtimes",
|
|
5
5
|
"homepage": "https://catena.com/",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"files": [
|
|
11
11
|
"dist",
|
|
12
12
|
"LICENSE",
|
|
13
|
-
"README.md"
|
|
13
|
+
"README.md",
|
|
14
|
+
"THIRD-PARTY-NOTICES"
|
|
14
15
|
],
|
|
15
16
|
"type": "module",
|
|
16
17
|
"publishConfig": {
|
|
@@ -23,9 +24,11 @@
|
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
|
25
26
|
"@types/semver": "7.8.0",
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
27
|
+
"mppx": "0.9.2",
|
|
28
|
+
"publint": "0.3.24",
|
|
29
|
+
"tsdown": "0.23.0",
|
|
30
|
+
"tsx": "4.23.13",
|
|
31
|
+
"viem": "2.56.3",
|
|
29
32
|
"@bank/money": "0.1.0",
|
|
30
33
|
"@bank/shared": "0.1.0",
|
|
31
34
|
"@catena/sdk": "0.1.0"
|
package/dist/base64-WTSXTrii.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{_ as e}from"./dist-B0qgGwAq.mjs";function t(e){return r(i(e))}function n(n,r){let i=n.padStart(Math.ceil(n.length/2)*2,`0`);return t(e(i,r).reduce((e,t)=>e+String.fromCharCode(t),``))}function r(e){return e.replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=/g,``)}function i(e){if(arguments.length===0)throw TypeError(`1 argument required, but only 0 present.`);let t;for(e=`${e}`,t=0;t<e.length;t++)if(e.charCodeAt(t)>255)throw Error(`InvalidCharacterError: found code point greater than 255:${e.charCodeAt(t)} at position ${t}`);let n=``;for(t=0;t<e.length;t+=3){let r=[void 0,void 0,void 0,void 0];r[0]=e.charCodeAt(t)>>2,r[1]=(e.charCodeAt(t)&3)<<4,e.length>t+1&&(r[1]|=e.charCodeAt(t+1)>>4,r[2]=(e.charCodeAt(t+1)&15)<<2),e.length>t+2&&(r[2]|=e.charCodeAt(t+2)>>6,r[3]=e.charCodeAt(t+2)&63);for(let e=0;e<r.length;e++)r[e]===void 0?n+=`=`:n+=a(r[e])}return n}function a(e){if(e>=0&&e<64)return`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`[e]}export{t as n,n as t};
|
package/dist/dist-B0qgGwAq.mjs
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import*as e from"node:crypto";var t=Object.create,n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,a=Object.getPrototypeOf,o=Object.prototype.hasOwnProperty,s=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(e){throw n=[e],e}},c=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),l=(e,t)=>{let r={};for(var i in e)n(r,i,{get:e[i],enumerable:!0});return t||n(r,Symbol.toStringTag,{value:`Module`}),r},u=(e,t,a,s)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var c=i(t),l=0,u=c.length,d;l<u;l++)d=c[l],!o.call(e,d)&&d!==a&&n(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(s=r(t,d))||s.enumerable});return e},d=(e,r,i)=>(i=e==null?{}:t(a(e)),u(r||!e||!e.__esModule||!o.call(e,`default`)?n(i,`default`,{value:e,enumerable:!0}):i,e)),f=e=>o.call(e,`module.exports`)?e[`module.exports`]:u(n({},`__esModule`,{value:!0}),e);function p(e){return e.reduce((e,t)=>e+t.toString(16).padStart(2,`0`),``)}const m=(e,t)=>{if(!e||e.length%2!=0||!/^[0-9A-Fa-f]+$/.test(e))throw Error(`cannot create uint8array from invalid hex string: "${e}"`);let n=new Uint8Array(e.match(/../g).map(e=>parseInt(e,16)));if(!t)return n;if(e.length/2>t)throw Error(`hex value cannot fit in a buffer of `+t+` byte(s)`);let r=new Uint8Array(t);return r.set(n,t-n.length),r},h=(e,t)=>{let n=t-e.length;if(n>0){let t=new Uint8Array(n).fill(0);return new Uint8Array([...t,...e])}if(n<0){let r=n*-1,i=0;for(let t=0;t<r&&t<e.length;t++)e[t]===0&&i++;if(i!==r)throw Error(`invalid number of starting zeroes. Expected number of zeroes: ${r}. Found: ${i}.`);return e.slice(r,r+t)}return e};function g(e){if(e.length>=255)throw TypeError(`Alphabet too long`);let t=new Uint8Array(256);for(let e=0;e<t.length;e++)t[e]=255;for(let n=0;n<e.length;n++){let r=e.charAt(n),i=r.charCodeAt(0);if(t[i]!==255)throw TypeError(r+` is ambiguous`);t[i]=n}let n=e.length,r=e.charAt(0),i=Math.log(n)/Math.log(256),a=Math.log(256)/Math.log(n);function o(t){if(t instanceof Uint8Array||(ArrayBuffer.isView(t)?t=new Uint8Array(t.buffer,t.byteOffset,t.byteLength):Array.isArray(t)&&(t=Uint8Array.from(t))),!(t instanceof Uint8Array))throw TypeError(`Expected Uint8Array`);if(t.length===0)return``;let i=0,o=0,s=0,c=t.length;for(;s!==c&&t[s]===0;)s++,i++;let l=(c-s)*a+1>>>0,u=new Uint8Array(l);for(;s!==c;){let e=t[s],r=0;for(let t=l-1;(e!==0||r<o)&&t!==-1;t--,r++)e+=256*u[t]>>>0,u[t]=e%n>>>0,e=e/n>>>0;if(e!==0)throw Error(`Non-zero carry`);o=r,s++}let d=l-o;for(;d!==l&&u[d]===0;)d++;let f=r.repeat(i);for(;d<l;++d)f+=e.charAt(u[d]);return f}function s(e){if(typeof e!=`string`)throw TypeError(`Expected String`);if(e.length===0)return new Uint8Array;let a=0,o=0,s=0;for(;e[a]===r;)o++,a++;let c=(e.length-a)*i+1>>>0,l=new Uint8Array(c);for(;a<e.length;){let r=e.charCodeAt(a);if(r>255)return;let i=t[r];if(i===255)return;let o=0;for(let e=c-1;(i!==0||o<s)&&e!==-1;e--,o++)i+=n*l[e]>>>0,l[e]=i%256>>>0,i=i/256>>>0;if(i!==0)throw Error(`Non-zero carry`);s=o,a++}let u=c-s;for(;u!==c&&l[u]===0;)u++;let d=new Uint8Array(o+(c-u)),f=o;for(;u!==c;)d[f++]=l[u++];return d}function c(e){let t=s(e);if(t)return t;throw Error(`Non-base`+n+` character`)}return{encode:o,decodeUnsafe:s,decode:c}}var _=l({default:()=>v}),v=g(`123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz`);function y(e){let t=e;for(;t&&!(t.encode&&t.decode&&t.decodeUnsafe)&&t.default;)t=t.default;return t}y(_);const b=e&&typeof e==`object`&&`webcrypto`in e?e.webcrypto:e&&typeof e==`object`&&`randomBytes`in e?e:void 0;
|
|
2
|
-
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
3
|
-
function x(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`}function S(e){if(!Number.isSafeInteger(e)||e<0)throw Error(`positive integer expected, got `+e)}function C(e,...t){if(!x(e))throw Error(`Uint8Array expected`);if(t.length>0&&!t.includes(e.length))throw Error(`Uint8Array expected of length `+t+`, got length=`+e.length)}function w(e){if(typeof e!=`function`||typeof e.create!=`function`)throw Error(`Hash should be wrapped by utils.createHasher`);S(e.outputLen),S(e.blockLen)}function T(e,t=!0){if(e.destroyed)throw Error(`Hash instance has been destroyed`);if(t&&e.finished)throw Error(`Hash#digest() has already been called`)}function E(e,t){C(e);let n=t.outputLen;if(e.length<n)throw Error(`digestInto() expects output buffer of length at least `+n)}function D(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function O(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function k(e,t){return e<<32-t|e>>>t}const A=typeof Uint8Array.from([]).toHex==`function`&&typeof Uint8Array.fromHex==`function`,ee=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`));function te(e){if(C(e),A)return e.toHex();let t=``;for(let n=0;n<e.length;n++)t+=ee[e[n]];return t}const j={_0:48,_9:57,A:65,F:70,a:97,f:102};function M(e){if(e>=j._0&&e<=j._9)return e-j._0;if(e>=j.A&&e<=j.F)return e-(j.A-10);if(e>=j.a&&e<=j.f)return e-(j.a-10)}function ne(e){if(typeof e!=`string`)throw Error(`hex string expected, got `+typeof e);if(A)return Uint8Array.fromHex(e);let t=e.length,n=t/2;if(t%2)throw Error(`hex string expected, got unpadded hex of length `+t);let r=new Uint8Array(n);for(let t=0,i=0;t<n;t++,i+=2){let n=M(e.charCodeAt(i)),a=M(e.charCodeAt(i+1));if(n===void 0||a===void 0){let t=e[i]+e[i+1];throw Error(`hex string expected, got non-hex character "`+t+`" at index `+i)}r[t]=n*16+a}return r}function re(e){if(typeof e!=`string`)throw Error(`string expected`);return new Uint8Array(new TextEncoder().encode(e))}function N(e){return typeof e==`string`&&(e=re(e)),C(e),e}function ie(...e){let t=0;for(let n=0;n<e.length;n++){let r=e[n];C(r),t+=r.length}let n=new Uint8Array(t);for(let t=0,r=0;t<e.length;t++){let i=e[t];n.set(i,r),r+=i.length}return n}var P=class{};function F(e){let t=t=>e().update(N(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function ae(e=32){if(b&&typeof b.getRandomValues==`function`)return b.getRandomValues(new Uint8Array(e));if(b&&typeof b.randomBytes==`function`)return Uint8Array.from(b.randomBytes(e));throw Error(`crypto.getRandomValues must be defined`)}function oe(e,t,n,r){if(typeof e.setBigUint64==`function`)return e.setBigUint64(t,n,r);let i=BigInt(32),a=BigInt(4294967295),o=Number(n>>i&a),s=Number(n&a),c=r?4:0,l=r?0:4;e.setUint32(t+c,o,r),e.setUint32(t+l,s,r)}function se(e,t,n){return e&t^~e&n}function ce(e,t,n){return e&t^e&n^t&n}var I=class extends P{constructor(e,t,n,r){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.buffer=new Uint8Array(e),this.view=O(this.buffer)}update(e){T(this),e=N(e),C(e);let{view:t,buffer:n,blockLen:r}=this,i=e.length;for(let a=0;a<i;){let o=Math.min(r-this.pos,i-a);if(o===r){let t=O(e);for(;r<=i-a;a+=r)this.process(t,a);continue}n.set(e.subarray(a,a+o),this.pos),this.pos+=o,a+=o,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){T(this),E(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:r,isLE:i}=this,{pos:a}=this;t[a++]=128,D(this.buffer.subarray(a)),this.padOffset>r-a&&(this.process(n,0),a=0);for(let e=a;e<r;e++)t[e]=0;oe(n,r-8,BigInt(this.length*8),i),this.process(n,0);let o=O(e),s=this.outputLen;if(s%4)throw Error(`_sha2: outputLen should be aligned to 32bit`);let c=s/4,l=this.get();if(c>l.length)throw Error(`_sha2: outputLen bigger than state`);for(let e=0;e<c;e++)o.setUint32(4*e,l[e],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:t,buffer:n,length:r,finished:i,destroyed:a,pos:o}=this;return e.destroyed=a,e.finished=i,e.length=r,e.pos=o,r%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}};const L=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),R=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),z=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),B=BigInt(2**32-1),V=BigInt(32);function le(e,t=!1){return t?{h:Number(e&B),l:Number(e>>V&B)}:{h:Number(e>>V&B)|0,l:Number(e&B)|0}}function ue(e,t=!1){let n=e.length,r=new Uint32Array(n),i=new Uint32Array(n);for(let a=0;a<n;a++){let{h:n,l:o}=le(e[a],t);[r[a],i[a]]=[n,o]}return[r,i]}const H=(e,t,n)=>e>>>n,U=(e,t,n)=>e<<32-n|t>>>n,W=(e,t,n)=>e>>>n|t<<32-n,G=(e,t,n)=>e<<32-n|t>>>n,K=(e,t,n)=>e<<64-n|t>>>n-32,q=(e,t,n)=>e>>>n-32|t<<64-n;function J(e,t,n,r){let i=(t>>>0)+(r>>>0);return{h:e+n+(i/2**32|0)|0,l:i|0}}const de=(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0),fe=(e,t,n,r)=>t+n+r+(e/2**32|0)|0,pe=(e,t,n,r)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0),me=(e,t,n,r,i)=>t+n+r+i+(e/2**32|0)|0,he=(e,t,n,r,i)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0)+(i>>>0),ge=(e,t,n,r,i,a)=>t+n+r+i+a+(e/2**32|0)|0,_e=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Y=new Uint32Array(64);var ve=class extends I{constructor(e=32){super(64,e,8,!1),this.A=L[0]|0,this.B=L[1]|0,this.C=L[2]|0,this.D=L[3]|0,this.E=L[4]|0,this.F=L[5]|0,this.G=L[6]|0,this.H=L[7]|0}get(){let{A:e,B:t,C:n,D:r,E:i,F:a,G:o,H:s}=this;return[e,t,n,r,i,a,o,s]}set(e,t,n,r,i,a,o,s){this.A=e|0,this.B=t|0,this.C=n|0,this.D=r|0,this.E=i|0,this.F=a|0,this.G=o|0,this.H=s|0}process(e,t){for(let n=0;n<16;n++,t+=4)Y[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){let t=Y[e-15],n=Y[e-2],r=k(t,7)^k(t,18)^t>>>3,i=k(n,17)^k(n,19)^n>>>10;Y[e]=i+Y[e-7]+r+Y[e-16]|0}let{A:n,B:r,C:i,D:a,E:o,F:s,G:c,H:l}=this;for(let e=0;e<64;e++){let t=k(o,6)^k(o,11)^k(o,25),u=l+t+se(o,s,c)+_e[e]+Y[e]|0,d=(k(n,2)^k(n,13)^k(n,22))+ce(n,r,i)|0;l=c,c=s,s=o,o=a+u|0,a=i,i=r,r=n,n=u+d|0}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,a=a+this.D|0,o=o+this.E|0,s=s+this.F|0,c=c+this.G|0,l=l+this.H|0,this.set(n,r,i,a,o,s,c,l)}roundClean(){D(Y)}destroy(){this.set(0,0,0,0,0,0,0,0),D(this.buffer)}};const X=ue(`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`.split(`.`).map(e=>BigInt(e))),ye=X[0],be=X[1],Z=new Uint32Array(80),Q=new Uint32Array(80);var xe=class extends I{constructor(e=64){super(128,e,16,!1),this.Ah=z[0]|0,this.Al=z[1]|0,this.Bh=z[2]|0,this.Bl=z[3]|0,this.Ch=z[4]|0,this.Cl=z[5]|0,this.Dh=z[6]|0,this.Dl=z[7]|0,this.Eh=z[8]|0,this.El=z[9]|0,this.Fh=z[10]|0,this.Fl=z[11]|0,this.Gh=z[12]|0,this.Gl=z[13]|0,this.Hh=z[14]|0,this.Hl=z[15]|0}get(){let{Ah:e,Al:t,Bh:n,Bl:r,Ch:i,Cl:a,Dh:o,Dl:s,Eh:c,El:l,Fh:u,Fl:d,Gh:f,Gl:p,Hh:m,Hl:h}=this;return[e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h]}set(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=r|0,this.Ch=i|0,this.Cl=a|0,this.Dh=o|0,this.Dl=s|0,this.Eh=c|0,this.El=l|0,this.Fh=u|0,this.Fl=d|0,this.Gh=f|0,this.Gl=p|0,this.Hh=m|0,this.Hl=h|0}process(e,t){for(let n=0;n<16;n++,t+=4)Z[n]=e.getUint32(t),Q[n]=e.getUint32(t+=4);for(let e=16;e<80;e++){let t=Z[e-15]|0,n=Q[e-15]|0,r=W(t,n,1)^W(t,n,8)^H(t,n,7),i=G(t,n,1)^G(t,n,8)^U(t,n,7),a=Z[e-2]|0,o=Q[e-2]|0,s=W(a,o,19)^K(a,o,61)^H(a,o,6),c=G(a,o,19)^q(a,o,61)^U(a,o,6),l=pe(i,c,Q[e-7],Q[e-16]),u=me(l,r,s,Z[e-7],Z[e-16]);Z[e]=u|0,Q[e]=l|0}let{Ah:n,Al:r,Bh:i,Bl:a,Ch:o,Cl:s,Dh:c,Dl:l,Eh:u,El:d,Fh:f,Fl:p,Gh:m,Gl:h,Hh:g,Hl:_}=this;for(let e=0;e<80;e++){let t=W(u,d,14)^W(u,d,18)^K(u,d,41),v=G(u,d,14)^G(u,d,18)^q(u,d,41),y=u&f^~u&m,b=d&p^~d&h,x=he(_,v,b,be[e],Q[e]),S=ge(x,g,t,y,ye[e],Z[e]),C=x|0,w=W(n,r,28)^K(n,r,34)^K(n,r,39),T=G(n,r,28)^q(n,r,34)^q(n,r,39),E=n&i^n&o^i&o,D=r&a^r&s^a&s;g=m|0,_=h|0,m=f|0,h=p|0,f=u|0,p=d|0,{h:u,l:d}=J(c|0,l|0,S|0,C|0),c=o|0,l=s|0,o=i|0,s=a|0,i=n|0,a=r|0;let O=de(C,T,D);n=fe(O,S,w,E),r=O|0}({h:n,l:r}=J(this.Ah|0,this.Al|0,n|0,r|0)),{h:i,l:a}=J(this.Bh|0,this.Bl|0,i|0,a|0),{h:o,l:s}=J(this.Ch|0,this.Cl|0,o|0,s|0),{h:c,l}=J(this.Dh|0,this.Dl|0,c|0,l|0),{h:u,l:d}=J(this.Eh|0,this.El|0,u|0,d|0),{h:f,l:p}=J(this.Fh|0,this.Fl|0,f|0,p|0),{h:m,l:h}=J(this.Gh|0,this.Gl|0,m|0,h|0),{h:g,l:_}=J(this.Hh|0,this.Hl|0,g|0,_|0),this.set(n,r,i,a,o,s,c,l,u,d,f,p,m,h,g,_)}roundClean(){D(Z,Q)}destroy(){D(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Se=class extends xe{constructor(){super(48),this.Ah=R[0]|0,this.Al=R[1]|0,this.Bh=R[2]|0,this.Bl=R[3]|0,this.Ch=R[4]|0,this.Cl=R[5]|0,this.Dh=R[6]|0,this.Dl=R[7]|0,this.Eh=R[8]|0,this.El=R[9]|0,this.Fh=R[10]|0,this.Fl=R[11]|0,this.Gh=R[12]|0,this.Gl=R[13]|0,this.Hh=R[14]|0,this.Hl=R[15]|0}};const Ce=F(()=>new ve),we=F(()=>new xe),Te=F(()=>new Se),$=Ce;function Ee(e){function t(t){var n=Uint8Array.from(t),r=e(n),i=n.length+4,a=new Uint8Array(i);return a.set(n,0),a.set(r.subarray(0,4),n.length),v.encode(a)}function n(t){var n=t.slice(0,-4),r=t.slice(-4),i=e(n);if(!(r[0]^i[0]|r[1]^i[1]|r[2]^i[2]|r[3]^i[3]))return n}function r(e){var t=v.decodeUnsafe(e);if(t!=null)return n(t)}function i(e){var t=n(v.decode(e));if(t==null)throw Error(`Invalid checksum`);return t}return{encode:t,decode:i,decodeUnsafe:r}}var De=l({default:()=>ke});function Oe(e){return $($(e))}var ke=Ee(Oe);function Ae(e){let t=e;for(;t&&!(t.encode&&t.decode&&t.decodeUnsafe)&&t.default;)t=t.default;return t}Ae(De);export{d as C,f as S,m as _,C as a,s as b,S as c,ie as d,ne as f,h as g,N as h,P as i,te as l,ae as m,Te as n,T as o,x as p,we as r,w as s,Ce as t,D as u,p as v,l as x,c as y};
|
package/dist/purejs-CZxWHjtN.mjs
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import{a as e,c as t,d as n,f as r,h as i,i as a,l as o,m as s,n as c,o as l,p as u,r as d,s as f,t as p,u as m,v as h}from"./dist-B0qgGwAq.mjs";var g=class extends a{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,f(e);let n=i(t);if(this.iHash=e.create(),typeof this.iHash.update!=`function`)throw Error(`Expected instance of class which extends utils.Hash`);this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let r=this.blockLen,a=new Uint8Array(r);a.set(n.length>r?e.create().update(n).digest():n);for(let e=0;e<a.length;e++)a[e]^=54;this.iHash.update(a),this.oHash=e.create();for(let e=0;e<a.length;e++)a[e]^=106;this.oHash.update(a),m(a)}update(e){return l(this),this.iHash.update(e),this}digestInto(t){l(this),e(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:t,iHash:n,finished:r,destroyed:i,blockLen:a,outputLen:o}=this;return e=e,e.finished=r,e.destroyed=i,e.blockLen=a,e.outputLen=o,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}};const _=(e,t,n)=>new g(e,t).update(n).digest();_.create=(e,t)=>new g(e,t);
|
|
2
|
-
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
3
|
-
const v=BigInt(0),y=BigInt(1);function b(e,t=``){if(typeof e!=`boolean`){let n=t&&`"${t}"`;throw Error(n+`expected boolean, got type=`+typeof e)}return e}function x(e,t,n=``){let r=u(e),i=e?.length,a=t!==void 0;if(!r||a&&i!==t){let o=n&&`"${n}" `,s=a?` of length ${t}`:``,c=r?`length=${i}`:`type=${typeof e}`;throw Error(o+`expected Uint8Array`+s+`, got `+c)}return e}function S(e){let t=e.toString(16);return t.length&1?`0`+t:t}function C(e){if(typeof e!=`string`)throw Error(`hex string expected, got `+typeof e);return e===``?v:BigInt(`0x`+e)}function w(e){return C(o(e))}function T(t){return e(t),C(o(Uint8Array.from(t).reverse()))}function E(e,t){return r(e.toString(16).padStart(t*2,`0`))}function D(e,t){return E(e,t).reverse()}function O(e,t,n){let i;if(typeof t==`string`)try{i=r(t)}catch(t){throw Error(e+` must be hex string or Uint8Array, cause: `+t)}else if(u(t))i=Uint8Array.from(t);else throw Error(e+` must be hex string or Uint8Array`);let a=i.length;if(typeof n==`number`&&a!==n)throw Error(e+` of length `+n+` expected, got `+a);return i}const k=e=>typeof e==`bigint`&&v<=e;function A(e,t,n){return k(e)&&k(t)&&k(n)&&t<=e&&e<n}function j(e,t,n,r){if(!A(t,n,r))throw Error(`expected valid `+e+`: `+n+` <= n < `+r+`, got `+t)}function M(e){let t;for(t=0;e>v;e>>=y,t+=1);return t}const N=e=>(y<<BigInt(e))-y;function ee(e,t,r){if(typeof e!=`number`||e<2)throw Error(`hashLen must be a number`);if(typeof t!=`number`||t<2)throw Error(`qByteLen must be a number`);if(typeof r!=`function`)throw Error(`hmacFn must be a function`);let i=e=>new Uint8Array(e),a=e=>Uint8Array.of(e),o=i(e),s=i(e),c=0,l=()=>{o.fill(1),s.fill(0),c=0},u=(...e)=>r(s,o,...e),d=(e=i(0))=>{s=u(a(0),e),o=u(),e.length!==0&&(s=u(a(1),e),o=u())},f=()=>{if(c++>=1e3)throw Error(`drbg: tried 1000 values`);let e=0,r=[];for(;e<t;){o=u();let t=o.slice();r.push(t),e+=o.length}return n(...r)};return(e,t)=>{l(),d(e);let n;for(;!(n=t(f()));)d();return l(),n}}function te(e,t,n={}){if(!e||typeof e!=`object`)throw Error(`expected valid options object`);function r(t,n,r){let i=e[t];if(r&&i===void 0)return;let a=typeof i;if(a!==n||i===null)throw Error(`param "${t}" is invalid: expected ${n}, got ${a}`)}Object.entries(t).forEach(([e,t])=>r(e,t,!1)),Object.entries(n).forEach(([e,t])=>r(e,t,!0))}function ne(e){let t=new WeakMap;return(n,...r)=>{let i=t.get(n);if(i!==void 0)return i;let a=e(n,...r);return t.set(n,a),a}}
|
|
4
|
-
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
5
|
-
const P=BigInt(0),F=BigInt(1),I=BigInt(2),re=BigInt(3),ie=BigInt(4),ae=BigInt(5),oe=BigInt(7),se=BigInt(8),ce=BigInt(9),le=BigInt(16);function L(e,t){let n=e%t;return n>=P?n:t+n}function ue(e,t){if(e===P)throw Error(`invert: expected non-zero number`);if(t<=P)throw Error(`invert: expected positive modulus, got `+t);let n=L(e,t),r=t,i=P,a=F,o=F,s=P;for(;n!==P;){let e=r/n,t=r%n,c=i-o*e,l=a-s*e;r=n,n=t,i=o,a=s,o=c,s=l}if(r!==F)throw Error(`invert: does not exist`);return L(i,t)}function R(e,t,n){if(!e.eql(e.sqr(t),n))throw Error(`Cannot find square root`)}function de(e,t){let n=(e.ORDER+F)/ie,r=e.pow(t,n);return R(e,r,t),r}function fe(e,t){let n=(e.ORDER-ae)/se,r=e.mul(t,I),i=e.pow(r,n),a=e.mul(t,i),o=e.mul(e.mul(a,I),i),s=e.mul(a,e.sub(o,e.ONE));return R(e,s,t),s}function pe(e){let t=z(e),n=me(e),r=n(t,t.neg(t.ONE)),i=n(t,r),a=n(t,t.neg(r)),o=(e+oe)/le;return(e,t)=>{let n=e.pow(t,o),s=e.mul(n,r),c=e.mul(n,i),l=e.mul(n,a),u=e.eql(e.sqr(s),t),d=e.eql(e.sqr(c),t);n=e.cmov(n,s,u),s=e.cmov(l,c,d);let f=e.eql(e.sqr(s),t),p=e.cmov(n,s,f);return R(e,p,t),p}}function me(e){if(e<re)throw Error(`sqrt is not defined for small field`);let t=e-F,n=0;for(;t%I===P;)t/=I,n++;let r=I,i=z(e);for(;be(i,r)===1;)if(r++>1e3)throw Error(`Cannot find square root: probably non-prime P`);if(n===1)return de;let a=i.pow(r,t),o=(t+F)/I;return function(e,r){if(e.is0(r))return r;if(be(e,r)!==1)throw Error(`Cannot find square root`);let i=n,s=e.mul(e.ONE,a),c=e.pow(r,t),l=e.pow(r,o);for(;!e.eql(c,e.ONE);){if(e.is0(c))return e.ZERO;let t=1,n=e.sqr(c);for(;!e.eql(n,e.ONE);)if(t++,n=e.sqr(n),t===i)throw Error(`Cannot find square root`);let r=F<<BigInt(i-t-1),a=e.pow(s,r);i=t,s=e.sqr(a),c=e.mul(c,s),l=e.mul(l,a)}return l}}function he(e){return e%ie===re?de:e%se===ae?fe:e%le===ce?pe(e):me(e)}const ge=[`create`,`isValid`,`is0`,`neg`,`inv`,`sqrt`,`sqr`,`eql`,`add`,`sub`,`mul`,`pow`,`div`,`addN`,`subN`,`mulN`,`sqrN`];function _e(e){return te(e,ge.reduce((e,t)=>(e[t]=`function`,e),{ORDER:`bigint`,MASK:`bigint`,BYTES:`number`,BITS:`number`})),e}function ve(e,t,n){if(n<P)throw Error(`invalid exponent, negatives unsupported`);if(n===P)return e.ONE;if(n===F)return t;let r=e.ONE,i=t;for(;n>P;)n&F&&(r=e.mul(r,i)),i=e.sqr(i),n>>=F;return r}function ye(e,t,n=!1){let r=Array(t.length).fill(n?e.ZERO:void 0),i=t.reduce((t,n,i)=>e.is0(n)?t:(r[i]=t,e.mul(t,n)),e.ONE),a=e.inv(i);return t.reduceRight((t,n,i)=>e.is0(n)?t:(r[i]=e.mul(t,r[i]),e.mul(t,n)),a),r}function be(e,t){let n=(e.ORDER-F)/I,r=e.pow(t,n),i=e.eql(r,e.ONE),a=e.eql(r,e.ZERO),o=e.eql(r,e.neg(e.ONE));if(!i&&!a&&!o)throw Error(`invalid Legendre symbol result`);return i?1:a?0:-1}function xe(e,n){n!==void 0&&t(n);let r=n===void 0?e.toString(2).length:n;return{nBitLength:r,nByteLength:Math.ceil(r/8)}}function z(e,t,n=!1,r={}){if(e<=P)throw Error(`invalid field: expected ORDER > 0, got `+e);let i,a,o=!1,s;if(typeof t==`object`&&t){if(r.sqrt||n)throw Error(`cannot specify opts in two arguments`);let e=t;e.BITS&&(i=e.BITS),e.sqrt&&(a=e.sqrt),typeof e.isLE==`boolean`&&(n=e.isLE),typeof e.modFromBytes==`boolean`&&(o=e.modFromBytes),s=e.allowedLengths}else typeof t==`number`&&(i=t),r.sqrt&&(a=r.sqrt);let{nBitLength:c,nByteLength:l}=xe(e,i);if(l>2048)throw Error(`invalid field: expected ORDER of <= 2048 bytes`);let u,d=Object.freeze({ORDER:e,isLE:n,BITS:c,BYTES:l,MASK:N(c),ZERO:P,ONE:F,allowedLengths:s,create:t=>L(t,e),isValid:t=>{if(typeof t!=`bigint`)throw Error(`invalid field element: expected bigint, got `+typeof t);return P<=t&&t<e},is0:e=>e===P,isValidNot0:e=>!d.is0(e)&&d.isValid(e),isOdd:e=>(e&F)===F,neg:t=>L(-t,e),eql:(e,t)=>e===t,sqr:t=>L(t*t,e),add:(t,n)=>L(t+n,e),sub:(t,n)=>L(t-n,e),mul:(t,n)=>L(t*n,e),pow:(e,t)=>ve(d,e,t),div:(t,n)=>L(t*ue(n,e),e),sqrN:e=>e*e,addN:(e,t)=>e+t,subN:(e,t)=>e-t,mulN:(e,t)=>e*t,inv:t=>ue(t,e),sqrt:a||(t=>(u||=he(e),u(d,t))),toBytes:e=>n?D(e,l):E(e,l),fromBytes:(t,r=!0)=>{if(s){if(!s.includes(t.length)||t.length>l)throw Error(`Field.fromBytes: expected `+s+` bytes, got `+t.length);let e=new Uint8Array(l);e.set(t,n?0:e.length-t.length),t=e}if(t.length!==l)throw Error(`Field.fromBytes: expected `+l+` bytes, got `+t.length);let i=n?T(t):w(t);if(o&&(i=L(i,e)),!r&&!d.isValid(i))throw Error(`invalid field element: outside of range 0..ORDER`);return i},invertBatch:e=>ye(d,e),cmov:(e,t,n)=>n?t:e});return Object.freeze(d)}function Se(e){if(typeof e!=`bigint`)throw Error(`field order must be bigint`);let t=e.toString(2).length;return Math.ceil(t/8)}function Ce(e){let t=Se(e);return t+Math.ceil(t/2)}function we(e,t,n=!1){let r=e.length,i=Se(t),a=Ce(t);if(r<16||r<a||r>1024)throw Error(`expected `+a+`-1024 bytes of input, got `+r);let o=L(n?T(e):w(e),t-F)+F;return n?D(o,i):E(o,i)}
|
|
6
|
-
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
7
|
-
const B=BigInt(0),V=BigInt(1);function H(e,t){let n=t.negate();return e?n:t}function U(e,t){let n=ye(e.Fp,t.map(e=>e.Z));return t.map((t,r)=>e.fromAffine(t.toAffine(n[r])))}function Te(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw Error(`invalid window size, expected [1..`+t+`], got W=`+e)}function Ee(e,t){Te(e,t);let n=Math.ceil(t/e)+1,r=2**(e-1),i=2**e;return{windows:n,windowSize:r,mask:N(e),maxNumber:i,shiftBy:BigInt(e)}}function De(e,t,n){let{windowSize:r,mask:i,maxNumber:a,shiftBy:o}=n,s=Number(e&i),c=e>>o;s>r&&(s-=a,c+=V);let l=t*r,u=l+Math.abs(s)-1,d=s===0,f=s<0,p=t%2!=0;return{nextN:c,offset:u,isZero:d,isNeg:f,isNegF:p,offsetF:l}}function Oe(e,t){if(!Array.isArray(e))throw Error(`array expected`);e.forEach((e,n)=>{if(!(e instanceof t))throw Error(`invalid point at index `+n)})}function ke(e,t){if(!Array.isArray(e))throw Error(`array of scalars expected`);e.forEach((e,n)=>{if(!t.isValid(e))throw Error(`invalid scalar at index `+n)})}const Ae=new WeakMap,je=new WeakMap;function Me(e){return je.get(e)||1}function Ne(e){if(e!==B)throw Error(`invalid wNAF`)}var Pe=class{constructor(e,t){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=t}_unsafeLadder(e,t,n=this.ZERO){let r=e;for(;t>B;)t&V&&(n=n.add(r)),r=r.double(),t>>=V;return n}precomputeWindow(e,t){let{windows:n,windowSize:r}=Ee(t,this.bits),i=[],a=e,o=a;for(let e=0;e<n;e++){o=a,i.push(o);for(let e=1;e<r;e++)o=o.add(a),i.push(o);a=o.double()}return i}wNAF(e,t,n){if(!this.Fn.isValid(n))throw Error(`invalid scalar`);let r=this.ZERO,i=this.BASE,a=Ee(e,this.bits);for(let e=0;e<a.windows;e++){let{nextN:o,offset:s,isZero:c,isNeg:l,isNegF:u,offsetF:d}=De(n,e,a);n=o,c?i=i.add(H(u,t[d])):r=r.add(H(l,t[s]))}return Ne(n),{p:r,f:i}}wNAFUnsafe(e,t,n,r=this.ZERO){let i=Ee(e,this.bits);for(let e=0;e<i.windows&&n!==B;e++){let{nextN:a,offset:o,isZero:s,isNeg:c}=De(n,e,i);if(n=a,!s){let e=t[o];r=r.add(c?e.negate():e)}}return Ne(n),r}getPrecomputes(e,t,n){let r=Ae.get(t);return r||(r=this.precomputeWindow(t,e),e!==1&&(typeof n==`function`&&(r=n(r)),Ae.set(t,r))),r}cached(e,t,n){let r=Me(e);return this.wNAF(r,this.getPrecomputes(r,e,n),t)}unsafe(e,t,n,r){let i=Me(e);return i===1?this._unsafeLadder(e,t,r):this.wNAFUnsafe(i,this.getPrecomputes(i,e,n),t,r)}createCache(e,t){Te(t,this.bits),je.set(e,t),Ae.delete(e)}hasCache(e){return Me(e)!==1}};function Fe(e,t,n,r){let i=t,a=e.ZERO,o=e.ZERO;for(;n>B||r>B;)n&V&&(a=a.add(i)),r&V&&(o=o.add(i)),i=i.double(),n>>=V,r>>=V;return{p1:a,p2:o}}function Ie(e,t,n,r){Oe(n,e),ke(r,t);let i=n.length,a=r.length;if(i!==a)throw Error(`arrays of points and scalars must have equal length`);let o=e.ZERO,s=M(BigInt(i)),c=1;s>12?c=s-3:s>4?c=s-2:s>0&&(c=2);let l=N(c),u=Array(Number(l)+1).fill(o),d=Math.floor((t.BITS-1)/c)*c,f=o;for(let e=d;e>=0;e-=c){u.fill(o);for(let t=0;t<a;t++){let i=r[t],a=Number(i>>BigInt(e)&l);u[a]=u[a].add(n[t])}let t=o;for(let e=u.length-1,n=o;e>0;e--)n=n.add(u[e]),t=t.add(n);if(f=f.add(t),e!==0)for(let e=0;e<c;e++)f=f.double()}return f}function Le(e,t,n){if(t){if(t.ORDER!==e)throw Error(`Field.ORDER must match order: Fp == p, Fn == n`);return _e(t),t}return z(e,{isLE:n})}function Re(e,t,n={},r){if(r===void 0&&(r=e===`edwards`),!t||typeof t!=`object`)throw Error(`expected valid ${e} CURVE object`);for(let e of[`p`,`n`,`h`]){let n=t[e];if(!(typeof n==`bigint`&&n>B))throw Error(`CURVE.${e} must be positive bigint`)}let i=Le(t.p,n.Fp,r),a=Le(t.n,n.Fn,r),o=[`Gx`,`Gy`,`a`,e===`weierstrass`?`b`:`d`];for(let e of o)if(!i.isValid(t[e]))throw Error(`CURVE.${e} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:i,Fn:a}}
|
|
8
|
-
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
9
|
-
const ze=(e,t)=>(e+(e>=0?t:-t)/Ue)/t;function Be(e,t,n){let[[r,i],[a,o]]=t,s=ze(o*e,n),c=ze(-i*e,n),l=e-s*r-c*a,u=-s*i-c*o,d=l<G,f=u<G;d&&(l=-l),f&&(u=-u);let p=N(Math.ceil(M(n)/2))+K;if(l<G||l>=p||u<G||u>=p)throw Error(`splitScalar (endomorphism): failed, k=`+e);return{k1neg:d,k1:l,k2neg:f,k2:u}}function Ve(e){if(![`compact`,`recovered`,`der`].includes(e))throw Error(`Signature format must be "compact", "recovered", or "der"`);return e}function He(e,t){let n={};for(let r of Object.keys(t))n[r]=e[r]===void 0?t[r]:e[r];return b(n.lowS,`lowS`),b(n.prehash,`prehash`),n.format!==void 0&&Ve(n.format),n}const W={Err:class extends Error{constructor(e=``){super(e)}},_tlv:{encode:(e,t)=>{let{Err:n}=W;if(e<0||e>256)throw new n(`tlv.encode: wrong tag`);if(t.length&1)throw new n(`tlv.encode: unpadded data`);let r=t.length/2,i=S(r);if(i.length/2&128)throw new n(`tlv.encode: long form length too big`);let a=r>127?S(i.length/2|128):``;return S(e)+a+i+t},decode(e,t){let{Err:n}=W,r=0;if(e<0||e>256)throw new n(`tlv.encode: wrong tag`);if(t.length<2||t[r++]!==e)throw new n(`tlv.decode: wrong tlv`);let i=t[r++],a=!!(i&128),o=0;if(!a)o=i;else{let e=i&127;if(!e)throw new n(`tlv.decode(long): indefinite length not supported`);if(e>4)throw new n(`tlv.decode(long): byte length is too big`);let a=t.subarray(r,r+e);if(a.length!==e)throw new n(`tlv.decode: length bytes not complete`);if(a[0]===0)throw new n(`tlv.decode(long): zero leftmost byte`);for(let e of a)o=o<<8|e;if(r+=e,o<128)throw new n(`tlv.decode(long): not minimal encoding`)}let s=t.subarray(r,r+o);if(s.length!==o)throw new n(`tlv.decode: wrong value length`);return{v:s,l:t.subarray(r+o)}}},_int:{encode(e){let{Err:t}=W;if(e<G)throw new t(`integer: negative integers are not allowed`);let n=S(e);if(Number.parseInt(n[0],16)&8&&(n=`00`+n),n.length&1)throw new t(`unexpected DER parsing assertion: unpadded hex`);return n},decode(e){let{Err:t}=W;if(e[0]&128)throw new t(`invalid signature integer: negative`);if(e[0]===0&&!(e[1]&128))throw new t(`invalid signature integer: unnecessary leading zero`);return w(e)}},toSig(e){let{Err:t,_int:n,_tlv:r}=W,i=O(`signature`,e),{v:a,l:o}=r.decode(48,i);if(o.length)throw new t(`invalid signature: left bytes after parsing`);let{v:s,l:c}=r.decode(2,a),{v:l,l:u}=r.decode(2,c);if(u.length)throw new t(`invalid signature: left bytes after parsing`);return{r:n.decode(s),s:n.decode(l)}},hexFromSig(e){let{_tlv:t,_int:n}=W,r=t.encode(2,n.encode(e.r))+t.encode(2,n.encode(e.s));return t.encode(48,r)}},G=BigInt(0),K=BigInt(1),Ue=BigInt(2),q=BigInt(3),We=BigInt(4);function J(e,t){let{BYTES:n}=e,r;if(typeof t==`bigint`)r=t;else{let i=O(`private key`,t);try{r=e.fromBytes(i)}catch{throw Error(`invalid private key: expected ui8a of size ${n}, got ${typeof t}`)}}if(!e.isValidNot0(r))throw Error(`invalid private key: out of range [1..N-1]`);return r}function Ge(e,t={}){let r=Re(`weierstrass`,e,t),{Fp:i,Fn:a}=r,s=r.CURVE,{h:c,n:l}=s;te(t,{},{allowInfinityPoint:`boolean`,clearCofactor:`function`,isTorsionFree:`function`,fromBytes:`function`,toBytes:`function`,endo:`object`,wrapPrivateKey:`boolean`});let{endo:u}=t;if(u&&(!i.is0(s.a)||typeof u.beta!=`bigint`||!Array.isArray(u.basises)))throw Error(`invalid endo: expected "beta": bigint and "basises": array`);let d=qe(i,a);function f(){if(!i.isOdd)throw Error(`compression is not supported: Field does not have .isOdd()`)}function p(e,t,r){let{x:a,y:o}=t.toAffine(),s=i.toBytes(a);if(b(r,`isCompressed`),r){f();let e=!i.isOdd(o);return n(Ke(e),s)}return n(Uint8Array.of(4),s,i.toBytes(o))}function m(e){x(e,void 0,`Point`);let{publicKey:t,publicKeyUncompressed:n}=d,r=e.length,a=e[0],o=e.subarray(1);if(r===t&&(a===2||a===3)){let e=i.fromBytes(o);if(!i.isValid(e))throw Error(`bad point: is not on curve, wrong x`);let t=_(e),n;try{n=i.sqrt(t)}catch(e){let t=e instanceof Error?`: `+e.message:``;throw Error(`bad point: is not on curve, sqrt error`+t)}f();let r=i.isOdd(n);return(a&1)==1!==r&&(n=i.neg(n)),{x:e,y:n}}if(r===n&&a===4){let e=i.BYTES,t=i.fromBytes(o.subarray(0,e)),n=i.fromBytes(o.subarray(e,e*2));if(!v(t,n))throw Error(`bad point: is not on curve`);return{x:t,y:n}}throw Error(`bad point: got length ${r}, expected compressed=${t} or uncompressed=${n}`)}let h=t.toBytes||p,g=t.fromBytes||m;function _(e){let t=i.sqr(e),n=i.mul(t,e);return i.add(i.add(n,i.mul(e,s.a)),s.b)}function v(e,t){let n=i.sqr(t),r=_(e);return i.eql(n,r)}if(!v(s.Gx,s.Gy))throw Error(`bad curve params: generator point`);let y=i.mul(i.pow(s.a,q),We),S=i.mul(i.sqr(s.b),BigInt(27));if(i.is0(i.add(y,S)))throw Error(`bad curve params: a or b`);function C(e,t,n=!1){if(!i.isValid(t)||n&&i.is0(t))throw Error(`bad point coordinate ${e}`);return t}function w(e){if(!(e instanceof A))throw Error(`ProjectivePoint expected`)}function T(e){if(!u||!u.basises)throw Error(`no endo`);return Be(e,u.basises,a.ORDER)}let E=ne((e,t)=>{let{X:n,Y:r,Z:a}=e;if(i.eql(a,i.ONE))return{x:n,y:r};let o=e.is0();t??=o?i.ONE:i.inv(a);let s=i.mul(n,t),c=i.mul(r,t),l=i.mul(a,t);if(o)return{x:i.ZERO,y:i.ZERO};if(!i.eql(l,i.ONE))throw Error(`invZ was invalid`);return{x:s,y:c}}),D=ne(e=>{if(e.is0()){if(t.allowInfinityPoint&&!i.is0(e.Y))return;throw Error(`bad point: ZERO`)}let{x:n,y:r}=e.toAffine();if(!i.isValid(n)||!i.isValid(r))throw Error(`bad point: x or y not field elements`);if(!v(n,r))throw Error(`bad point: equation left != right`);if(!e.isTorsionFree())throw Error(`bad point: not in prime-order subgroup`);return!0});function k(e,t,n,r,a){return n=new A(i.mul(n.X,e),n.Y,n.Z),t=H(r,t),n=H(a,n),t.add(n)}class A{constructor(e,t,n){this.X=C(`x`,e),this.Y=C(`y`,t,!0),this.Z=C(`z`,n),Object.freeze(this)}static CURVE(){return s}static fromAffine(e){let{x:t,y:n}=e||{};if(!e||!i.isValid(t)||!i.isValid(n))throw Error(`invalid affine point`);if(e instanceof A)throw Error(`projective point not allowed`);return i.is0(t)&&i.is0(n)?A.ZERO:new A(t,n,i.ONE)}static fromBytes(e){let t=A.fromAffine(g(x(e,void 0,`point`)));return t.assertValidity(),t}static fromHex(e){return A.fromBytes(O(`pointHex`,e))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(e=8,t=!0){return M.createCache(this,e),t||this.multiply(q),this}assertValidity(){D(this)}hasEvenY(){let{y:e}=this.toAffine();if(!i.isOdd)throw Error(`Field doesn't support isOdd`);return!i.isOdd(e)}equals(e){w(e);let{X:t,Y:n,Z:r}=this,{X:a,Y:o,Z:s}=e,c=i.eql(i.mul(t,s),i.mul(a,r)),l=i.eql(i.mul(n,s),i.mul(o,r));return c&&l}negate(){return new A(this.X,i.neg(this.Y),this.Z)}double(){let{a:e,b:t}=s,n=i.mul(t,q),{X:r,Y:a,Z:o}=this,c=i.ZERO,l=i.ZERO,u=i.ZERO,d=i.mul(r,r),f=i.mul(a,a),p=i.mul(o,o),m=i.mul(r,a);return m=i.add(m,m),u=i.mul(r,o),u=i.add(u,u),c=i.mul(e,u),l=i.mul(n,p),l=i.add(c,l),c=i.sub(f,l),l=i.add(f,l),l=i.mul(c,l),c=i.mul(m,c),u=i.mul(n,u),p=i.mul(e,p),m=i.sub(d,p),m=i.mul(e,m),m=i.add(m,u),u=i.add(d,d),d=i.add(u,d),d=i.add(d,p),d=i.mul(d,m),l=i.add(l,d),p=i.mul(a,o),p=i.add(p,p),d=i.mul(p,m),c=i.sub(c,d),u=i.mul(p,f),u=i.add(u,u),u=i.add(u,u),new A(c,l,u)}add(e){w(e);let{X:t,Y:n,Z:r}=this,{X:a,Y:o,Z:c}=e,l=i.ZERO,u=i.ZERO,d=i.ZERO,f=s.a,p=i.mul(s.b,q),m=i.mul(t,a),h=i.mul(n,o),g=i.mul(r,c),_=i.add(t,n),v=i.add(a,o);_=i.mul(_,v),v=i.add(m,h),_=i.sub(_,v),v=i.add(t,r);let y=i.add(a,c);return v=i.mul(v,y),y=i.add(m,g),v=i.sub(v,y),y=i.add(n,r),l=i.add(o,c),y=i.mul(y,l),l=i.add(h,g),y=i.sub(y,l),d=i.mul(f,v),l=i.mul(p,g),d=i.add(l,d),l=i.sub(h,d),d=i.add(h,d),u=i.mul(l,d),h=i.add(m,m),h=i.add(h,m),g=i.mul(f,g),v=i.mul(p,v),h=i.add(h,g),g=i.sub(m,g),g=i.mul(f,g),v=i.add(v,g),m=i.mul(h,v),u=i.add(u,m),m=i.mul(y,v),l=i.mul(_,l),l=i.sub(l,m),m=i.mul(_,h),d=i.mul(y,d),d=i.add(d,m),new A(l,u,d)}subtract(e){return this.add(e.negate())}is0(){return this.equals(A.ZERO)}multiply(e){let{endo:n}=t;if(!a.isValidNot0(e))throw Error(`invalid scalar: out of range`);let r,i,o=e=>M.cached(this,e,e=>U(A,e));if(n){let{k1neg:t,k1:a,k2neg:s,k2:c}=T(e),{p:l,f:u}=o(a),{p:d,f}=o(c);i=u.add(f),r=k(n.beta,l,d,t,s)}else{let{p:t,f:n}=o(e);r=t,i=n}return U(A,[r,i])[0]}multiplyUnsafe(e){let{endo:n}=t,r=this;if(!a.isValid(e))throw Error(`invalid scalar: out of range`);if(e===G||r.is0())return A.ZERO;if(e===K)return r;if(M.hasCache(this))return this.multiply(e);if(n){let{k1neg:t,k1:i,k2neg:a,k2:o}=T(e),{p1:s,p2:c}=Fe(A,r,i,o);return k(n.beta,s,c,t,a)}return M.unsafe(r,e)}multiplyAndAddUnsafe(e,t,n){let r=this.multiplyUnsafe(t).add(e.multiplyUnsafe(n));return r.is0()?void 0:r}toAffine(e){return E(this,e)}isTorsionFree(){let{isTorsionFree:e}=t;return c===K?!0:e?e(A,this):M.unsafe(this,l).is0()}clearCofactor(){let{clearCofactor:e}=t;return c===K?this:e?e(A,this):this.multiplyUnsafe(c)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}toBytes(e=!0){return b(e,`isCompressed`),this.assertValidity(),h(A,this,e)}toHex(e=!0){return o(this.toBytes(e))}toString(){return`<Point ${this.is0()?`ZERO`:this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(e=!0){return this.toBytes(e)}_setWindowSize(e){this.precompute(e)}static normalizeZ(e){return U(A,e)}static msm(e,t){return Ie(A,a,e,t)}static fromPrivateKey(e){return A.BASE.multiply(J(a,e))}}A.BASE=new A(s.Gx,s.Gy,i.ONE),A.ZERO=new A(i.ZERO,i.ONE,i.ZERO),A.Fp=i,A.Fn=a;let j=a.BITS,M=new Pe(A,t.endo?Math.ceil(j/2):j);return A.BASE.precompute(8),A}function Ke(e){return Uint8Array.of(e?2:3)}function qe(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Je(e,t={}){let{Fn:n}=e,r=t.randomBytes||s,i=Object.assign(qe(e.Fp,n),{seed:Ce(n.ORDER)});function a(e){try{return!!J(n,e)}catch{return!1}}function o(t,n){let{publicKey:r,publicKeyUncompressed:a}=i;try{let i=t.length;return n===!0&&i!==r||n===!1&&i!==a?!1:!!e.fromBytes(t)}catch{return!1}}function c(e=r(i.seed)){return we(x(e,i.seed,`seed`),n.ORDER)}function l(t,r=!0){return e.BASE.multiply(J(n,t)).toBytes(r)}function u(e){let t=c(e);return{secretKey:t,publicKey:l(t)}}function d(t){if(typeof t==`bigint`)return!1;if(t instanceof e)return!0;let{secretKey:r,publicKey:a,publicKeyUncompressed:o}=i;if(n.allowedLengths||r===a)return;let s=O(`key`,t).length;return s===a||s===o}function f(t,r,i=!0){if(d(t)===!0)throw Error(`first arg must be private key`);if(d(r)===!1)throw Error(`second arg must be public key`);let a=J(n,t);return e.fromHex(r).multiply(a).toBytes(i)}return Object.freeze({getPublicKey:l,getSharedSecret:f,keygen:u,Point:e,utils:{isValidSecretKey:a,isValidPublicKey:o,randomSecretKey:c,isValidPrivateKey:a,randomPrivateKey:c,normPrivateKeyToScalar:e=>J(n,e),precompute(t=8,n=e.BASE){return n.precompute(t,!1)}},lengths:i})}function Ye(e,t,i={}){f(t),te(i,{},{hmac:`function`,lowS:`boolean`,randomBytes:`function`,bits2int:`function`,bits2int_modN:`function`});let a=i.randomBytes||s,c=i.hmac||((e,...r)=>_(t,e,n(...r))),{Fp:l,Fn:d}=e,{ORDER:p,BITS:m}=d,{keygen:h,getPublicKey:g,getSharedSecret:v,utils:y,lengths:b}=Je(e,i),S={prehash:!1,lowS:typeof i.lowS==`boolean`&&i.lowS,format:void 0,extraEntropy:!1},C=`compact`;function T(e){return e>p>>K}function E(e,t){if(!d.isValidNot0(t))throw Error(`invalid signature ${e}: out of range 1..Point.Fn.ORDER`);return t}function D(e,t){Ve(t);let n=b.signature;return x(e,t===`compact`?n:t===`recovered`?n+1:void 0,`${t} signature`)}class k{constructor(e,t,n){this.r=E(`r`,e),this.s=E(`s`,t),n!=null&&(this.recovery=n),Object.freeze(this)}static fromBytes(e,t=C){D(e,t);let n;if(t===`der`){let{r:t,s:n}=W.toSig(x(e));return new k(t,n)}t===`recovered`&&(n=e[0],t=`compact`,e=e.subarray(1));let r=d.BYTES,i=e.subarray(0,r),a=e.subarray(r,r*2);return new k(d.fromBytes(i),d.fromBytes(a),n)}static fromHex(e,t){return this.fromBytes(r(e),t)}addRecoveryBit(e){return new k(this.r,this.s,e)}recoverPublicKey(t){let r=l.ORDER,{r:i,s:a,recovery:o}=this;if(o==null||![0,1,2,3].includes(o))throw Error(`recovery id invalid`);if(p*Ue<r&&o>1)throw Error(`recovery id is ambiguous for h>1 curve`);let s=o===2||o===3?i+p:i;if(!l.isValid(s))throw Error(`recovery id 2 or 3 invalid`);let c=l.toBytes(s),u=e.fromBytes(n(Ke(!(o&1)),c)),f=d.inv(s),m=M(O(`msgHash`,t)),h=d.create(-m*f),g=d.create(a*f),_=e.BASE.multiplyUnsafe(h).add(u.multiplyUnsafe(g));if(_.is0())throw Error(`point at infinify`);return _.assertValidity(),_}hasHighS(){return T(this.s)}toBytes(e=C){if(Ve(e),e===`der`)return r(W.hexFromSig(this));let t=d.toBytes(this.r),i=d.toBytes(this.s);if(e===`recovered`){if(this.recovery==null)throw Error(`recovery bit must be present`);return n(Uint8Array.of(this.recovery),t,i)}return n(t,i)}toHex(e){return o(this.toBytes(e))}assertValidity(){}static fromCompact(e){return k.fromBytes(O(`sig`,e),`compact`)}static fromDER(e){return k.fromBytes(O(`sig`,e),`der`)}normalizeS(){return this.hasHighS()?new k(this.r,d.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes(`der`)}toDERHex(){return o(this.toBytes(`der`))}toCompactRawBytes(){return this.toBytes(`compact`)}toCompactHex(){return o(this.toBytes(`compact`))}}let A=i.bits2int||function(e){if(e.length>8192)throw Error(`input is too large`);let t=w(e),n=e.length*8-m;return n>0?t>>BigInt(n):t},M=i.bits2int_modN||function(e){return d.create(A(e))},ne=N(m);function P(e){return j(`num < 2^`+m,e,G,ne),d.toBytes(e)}function F(e,n){return x(e,void 0,`message`),n?x(t(e),void 0,`prehashed message`):e}function I(t,r,i){if([`recovered`,`canonical`].some(e=>e in i))throw Error(`sign() legacy options not supported`);let{lowS:o,prehash:s,extraEntropy:c}=He(i,S);t=F(t,s);let l=M(t),u=J(d,r),f=[P(u),P(l)];if(c!=null&&c!==!1){let e=c===!0?a(b.secretKey):c;f.push(O(`extraEntropy`,e))}let p=n(...f),m=l;function h(t){let n=A(t);if(!d.isValidNot0(n))return;let r=d.inv(n),i=e.BASE.multiply(n).toAffine(),a=d.create(i.x);if(a===G)return;let s=d.create(r*d.create(m+a*u));if(s===G)return;let c=(i.x===a?0:2)|Number(i.y&K),l=s;return o&&T(s)&&(l=d.neg(s),c^=1),new k(a,l,c)}return{seed:p,k2sig:h}}function re(e,n,r={}){e=O(`message`,e);let{seed:i,k2sig:a}=I(e,n,r);return ee(t.outputLen,d.BYTES,c)(i,a)}function ie(e){let t,n=typeof e==`string`||u(e),r=!n&&typeof e==`object`&&!!e&&typeof e.r==`bigint`&&typeof e.s==`bigint`;if(!n&&!r)throw Error(`invalid signature, expected Uint8Array, hex string or Signature instance`);if(r)t=new k(e.r,e.s);else if(n){try{t=k.fromBytes(O(`sig`,e),`der`)}catch(e){if(!(e instanceof W.Err))throw e}if(!t)try{t=k.fromBytes(O(`sig`,e),`compact`)}catch{return!1}}return t||!1}function ae(t,n,r,i={}){let{lowS:a,prehash:o,format:s}=He(i,S);if(r=O(`publicKey`,r),n=F(O(`message`,n),o),`strict`in i)throw Error(`options.strict was renamed to lowS`);let c=s===void 0?ie(t):k.fromBytes(O(`sig`,t),s);if(c===!1)return!1;try{let t=e.fromBytes(r);if(a&&c.hasHighS())return!1;let{r:i,s:o}=c,s=M(n),l=d.inv(o),u=d.create(s*l),f=d.create(i*l),p=e.BASE.multiplyUnsafe(u).add(t.multiplyUnsafe(f));return!p.is0()&&d.create(p.x)===i}catch{return!1}}function oe(e,t,n={}){let{prehash:r}=He(n,S);return t=F(t,r),k.fromBytes(e,`recovered`).recoverPublicKey(t).toBytes()}return Object.freeze({keygen:h,getPublicKey:g,getSharedSecret:v,utils:y,lengths:b,Point:e,sign:re,verify:ae,recoverPublicKey:oe,Signature:k,hash:t})}function Xe(e){let t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},n=e.Fp,r=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(e=>Math.ceil(e/2)))):void 0;return{CURVE:t,curveOpts:{Fp:n,Fn:z(t.n,{BITS:e.nBitLength,allowedLengths:r,modFromBytes:e.wrapPrivateKey}),allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes}}}function Ze(e){let{CURVE:t,curveOpts:n}=Xe(e),r={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:n,hash:e.hash,ecdsaOpts:r}}function Qe(e,t){let n=t.Point;return Object.assign({},t,{ProjectivePoint:n,CURVE:Object.assign({},e,xe(n.Fn.ORDER,n.Fn.BITS))})}function $e(e){let{CURVE:t,curveOpts:n,hash:r,ecdsaOpts:i}=Ze(e);return Qe(e,Ye(Ge(t,n),r,i))}
|
|
10
|
-
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
11
|
-
function et(e,t){let n=t=>$e({...e,hash:t});return{...n(t),create:n}}
|
|
12
|
-
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
13
|
-
const tt={p:BigInt(`0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff`),n:BigInt(`0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551`),h:BigInt(1),a:BigInt(`0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc`),b:BigInt(`0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b`),Gx:BigInt(`0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296`),Gy:BigInt(`0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5`)},nt={p:BigInt(`0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff`),n:BigInt(`0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973`),h:BigInt(1),a:BigInt(`0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000fffffffc`),b:BigInt(`0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef`),Gx:BigInt(`0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7`),Gy:BigInt(`0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f`)},rt={p:BigInt(`0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff`),n:BigInt(`0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409`),h:BigInt(1),a:BigInt(`0x1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc`),b:BigInt(`0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00`),Gx:BigInt(`0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66`),Gy:BigInt(`0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650`)},it=z(tt.p),at=z(nt.p),ot=z(rt.p),st=et({...tt,Fp:it,lowS:!1},p);et({...nt,Fp:at,lowS:!1},c),et({...rt,Fp:ot,lowS:!1,allowedPrivateKeyLengths:[130,131,132]},d);
|
|
14
|
-
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
15
|
-
const ct=st,lt=[1116352408,1899447441,-1245643825,-373957723,961987163,1508970993,-1841331548,-1424204075,-670586216,310598401,607225278,1426881987,1925078388,-2132889090,-1680079193,-1046744716,-459576895,-272742522,264347078,604807628,770255983,1249150122,1555081692,1996064986,-1740746414,-1473132947,-1341970488,-1084653625,-958395405,-710438585,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,-2117940946,-1838011259,-1564481375,-1474664885,-1035236496,-949202525,-778901479,-694614492,-200395387,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,-2067236844,-1933114872,-1866530822,-1538233109,-1090935817,-965641998],ut={sha256:1};function dt(e){if(e&&!ut[e]&&!ut[e.toLowerCase()])throw Error(`Digest method not supported`);return new ft}var ft=class{constructor(){this.A=1779033703,this.B=-1150833019,this.C=1013904242,this.D=-1521486534,this.E=1359893119,this.F=-1694144372,this.G=528734635,this.H=1541459225,this._size=0,this._sp=0,(!X||Z>=8e3)&&(X=new ArrayBuffer(8e3),Z=0),this._byte=new Uint8Array(X,Z,80),this._word=new Int32Array(X,Z,20),Z+=80}update(e){if(typeof e==`string`)return this._utf8(e);if(e==null)throw TypeError(`Invalid type: `+typeof e);let t=e.byteOffset,n=e.byteLength,r=n/64|0,i=0;if(r&&!(t&3)&&!(this._size%64)){let n=new Int32Array(e.buffer,t,r*16);for(;r--;)this._int32(n,i>>2),i+=64;this._size+=i}if(e.BYTES_PER_ELEMENT!==1&&e.buffer){let r=new Uint8Array(e.buffer,t+i,n-i);return this._uint8(r)}return i===n?this:this._uint8(e,i)}_uint8(e,t){let{_byte:n,_word:r}=this,i=e.length;for(t|=0;t<i;){let a=this._size%64,o=a;for(;t<i&&o<64;)n[o++]=e[t++];o>=64&&this._int32(r),this._size+=o-a}return this}_utf8(e){let{_byte:t,_word:n}=this,r=e.length,i=this._sp;for(let a=0;a<r;){let o=this._size%64,s=o;for(;a<r&&s<64;){let n=e.charCodeAt(a++)|0;n<128?t[s++]=n:n<2048?(t[s++]=192|n>>>6,t[s++]=128|n&63):n<55296||n>57343?(t[s++]=224|n>>>12,t[s++]=128|n>>>6&63,t[s++]=128|n&63):i?(n=((i&1023)<<10)+(n&1023)+65536,t[s++]=240|n>>>18,t[s++]=128|n>>>12&63,t[s++]=128|n>>>6&63,t[s++]=128|n&63,i=0):i=n}s>=64&&(this._int32(n),n[0]=n[16]),this._size+=s-o}return this._sp=i,this}_int32(e,t){let{A:n,B:r,C:i,D:a,E:o,F:s,G:c,H:l}=this,u=0;for(t|=0;u<16;)Y[u++]=$(e[t++]);for(u=16;u<64;u++)Y[u]=vt(Y[u-2])+Y[u-7]+_t(Y[u-15])+Y[u-16]|0;for(u=0;u<64;u++){let e=l+gt(o)+pt(o,s,c)+lt[u]+Y[u]|0,t=ht(n)+mt(n,r,i)|0;l=c,c=s,s=o,o=a+e|0,a=i,i=r,r=n,n=e+t|0}this.A=n+this.A|0,this.B=r+this.B|0,this.C=i+this.C|0,this.D=a+this.D|0,this.E=o+this.E|0,this.F=s+this.F|0,this.G=c+this.G|0,this.H=l+this.H|0}digest(e){let{_byte:t,_word:n}=this,r=this._size%64|0;for(t[r++]=128;r&3;)t[r++]=0;if(r>>=2,r>14){for(;r<16;)n[r++]=0;r=0,this._int32(n)}for(;r<16;)n[r++]=0;let i=this._size*8,a=(i&4294967295)>>>0,o=(i-a)/4294967296;return o&&(n[14]=$(o)),a&&(n[15]=$(a)),this._int32(n),e===`hex`?this._hex():this._bin()}_hex(){let{A:e,B:t,C:n,D:r,E:i,F:a,G:o,H:s}=this;return Q(e)+Q(t)+Q(n)+Q(r)+Q(i)+Q(a)+Q(o)+Q(s)}_bin(){let{A:e,B:t,C:n,D:r,E:i,F:a,G:o,H:s,_byte:c,_word:l}=this;return l[0]=$(e),l[1]=$(t),l[2]=$(n),l[3]=$(r),l[4]=$(i),l[5]=$(a),l[6]=$(o),l[7]=$(s),c.slice(0,32)}};const Y=new Int32Array(64);let X,Z=0;const Q=e=>(e+4294967296).toString(16).substr(-8),$=yt()?(e=>e):(e=>e<<24&4278190080|e<<8&16711680|e>>8&65280|e>>24&255),pt=(e,t,n)=>n^e&(t^n),mt=(e,t,n)=>e&t|n&(e|t),ht=e=>(e>>>2|e<<30)^(e>>>13|e<<19)^(e>>>22|e<<10),gt=e=>(e>>>6|e<<26)^(e>>>11|e<<21)^(e>>>25|e<<7),_t=e=>(e>>>7|e<<25)^(e>>>18|e<<14)^e>>>3,vt=e=>(e>>>17|e<<15)^(e>>>19|e<<13)^e>>>10;function yt(){return new Uint8Array(new Uint16Array([65279]).buffer)[0]===254}const bt=async e=>{let t=ct.getPublicKey(e.privateKey,!0),n=h(t);if(n!=e.publicKey)throw Error(`Bad API key. Expected to get public key ${e.publicKey}, got ${n}`);let r=dt().update(e.content).digest();return ct.sign(r,e.privateKey).toDERHex()};export{bt as signWithApiKey};
|