@notabene/verify-proof 1.0.0-preview.6 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { type OwnershipProof } from "@notabene/javascript-sdk/src/types";
1
+ import { type OwnershipProof } from "@notabene/javascript-sdk";
2
2
  export declare function verifyProof(proof: OwnershipProof): Promise<OwnershipProof>;
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{ProofStatus as r,ProofTypes as e}from"@notabene/javascript-sdk/src/types";import*as t from"bitcoinjs-message";import{verifyMessage as s}from"viem";import{PublicKey as o}from"@solana/web3.js";import n from"tweetnacl";import{decode as a}from"@stablelib/base64";function i(){return i=Object.assign?Object.assign.bind():function(r){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var s in t)({}).hasOwnProperty.call(t,s)&&(r[s]=t[s])}return r},i.apply(null,arguments)}var c;!function(r){r.LEGACY="Legacy",r.NATIVE="Native SegWit",r.SEGWIT="SegWit",r.P2SH_SEGWIT="p2sh",r.BCH="Bitcoin Cash",r.ETHEREUM="Ethereum",r.DOGECOIN="Dogecoin",r.UNKNOWN="Unknown"}(c||(c={}));var u=function(u){try{switch(u.type){case e.SelfDeclaration:return Promise.resolve(i({},u,{status:u.confirmed?r.VERIFIED:r.FAILED}));case e.Screenshot:return Promise.resolve(i({},u,{status:u.url?r.FLAGGED:r.FAILED}));case e.EIP191:return Promise.resolve(function(e){try{var t=e.address.split(/:/),o=t[2];return"eip155"!==t[0]?Promise.resolve(i({},e,{status:r.FAILED})):Promise.resolve(s({address:o,message:e.attestation,signature:e.proof})).then(function(t){return i({},e,{status:t?r.VERIFIED:r.FAILED})})}catch(r){return Promise.reject(r)}}(u));case e.ED25519:return Promise.resolve(function(e){try{var t=e.address.split(/:/),s=t[2];if("solana"!==t[0])return Promise.resolve(i({},e,{status:r.FAILED}));try{var c=new o(s),u=(new TextEncoder).encode(e.attestation),m=a(e.proof),E=n.sign.detached.verify(u,m,c.toBytes());return Promise.resolve(i({},e,{status:E?r.VERIFIED:r.FAILED}))}catch(t){return Promise.resolve(i({},e,{status:r.FAILED}))}}catch(r){return Promise.reject(r)}}(u));case e.EIP712:case e.BIP137:return Promise.resolve(function(e){try{var s=e.address.split(/:/),o=s[2];if("bip122"!==s[0])return Promise.resolve(i({},e,{status:r.FAILED}));try{var n=[c.SEGWIT,c.NATIVE].includes(function(r){if(r.match("^(bc1|tb1|ltc1).*"))return c.NATIVE;if(r.match("^[32M].*"))return c.SEGWIT;if(r.match("^[1nmL].*"))return c.LEGACY;if(r.match("^(D).*"))return c.DOGECOIN;throw new Error("INVALID ADDRESS: ".concat(r).concat(" is not a valid or a supported address"))}(o)),a=t.verify(e.attestation,o,e.proof,void 0,n);return Promise.resolve(i({},e,{status:a?r.VERIFIED:r.FAILED}))}catch(t){return Promise.resolve(i({},e,{status:r.FAILED}))}}catch(r){return Promise.reject(r)}}(u))}return Promise.resolve(u)}catch(r){return Promise.reject(r)}};export{u as verifyProof};
1
+ import{ProofStatus as e,ProofTypes as t}from"@notabene/javascript-sdk";import{bech32 as r}from"bech32";import{secp256k1 as n,hash160 as i,encodeBase58AddressFormat as o,hash256 as s}from"@bitauth/libauth";import{encode as a}from"varuint-bitcoin";import{decode as u}from"@stablelib/base64";import c from"tweetnacl";import f from"bs58";function l(){return l=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)({}).hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},l.apply(null,arguments)}var h,d;function g(e){var t=r.toWords(e);return t.unshift(0),r.encode("bc",t)}!function(e){e.P2WPKH="p2wpkh",e.P2SH_P2WPKH="p2sh(p2wpkh)"}(h||(h={})),function(e){e.LEGACY="Legacy",e.NATIVE="Native SegWit",e.SEGWIT="SegWit",e.P2SH_SEGWIT="p2sh",e.BCH="Bitcoin Cash",e.ETHEREUM="Ethereum",e.DOGECOIN="Dogecoin",e.UNKNOWN="Unknown"}(d||(d={}));class p extends Error{constructor(e,t={}){const r=(()=>{if(t.cause instanceof p){if(t.cause.details)return t.cause.details;if(t.cause.shortMessage)return t.cause.shortMessage}return t.cause?.message?t.cause.message:t.details})(),n=t.cause instanceof p&&t.cause.docsPath||t.docsPath,i=`https://oxlib.sh${n??""}`;super([e||"An error occurred.",...t.metaMessages?["",...t.metaMessages]:[],...r||n?["",r?`Details: ${r}`:void 0,n?`See: ${i}`:void 0]:[]].filter(e=>"string"==typeof e).join("\n"),t.cause?{cause:t.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,"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,"cause",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"BaseError"}),Object.defineProperty(this,"version",{enumerable:!0,configurable:!0,writable:!0,value:"ox@0.1.1"}),this.cause=t.cause,this.details=r,this.docs=i,this.docsPath=n,this.shortMessage=e}walk(e){return w(this,e)}}function w(e,t){return t?.(e)?e:e&&"object"==typeof e&&"cause"in e&&e.cause?w(e.cause,t):t?null:e}function y(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function b(e,...t){if(!((r=e)instanceof Uint8Array||ArrayBuffer.isView(r)&&"Uint8Array"===r.constructor.name))throw new Error("Uint8Array expected");var r;if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function m(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}const E=/* @__PURE__ */(()=>68===new Uint8Array(new Uint32Array([287454020]).buffer)[0])();function v(e){for(let r=0;r<e.length;r++)e[r]=(t=e[r])<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255;var t}function x(e){return"string"==typeof e&&(e=function(e){if("string"!=typeof e)throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array((new TextEncoder).encode(e))}(e)),b(e),e}class B{clone(){return this._cloneInto()}}const I=/* @__PURE__ */BigInt(2**32-1),A=/* @__PURE__ */BigInt(32);function S(e,t=!1){return t?{h:Number(e&I),l:Number(e>>A&I)}:{h:0|Number(e>>A&I),l:0|Number(e&I)}}function O(e,t=!1){let r=new Uint32Array(e.length),n=new Uint32Array(e.length);for(let i=0;i<e.length;i++){const{h:o,l:s}=S(e[i],t);[r[i],n[i]]=[o,s]}return[r,n]}const P=[],z=[],L=[],U=/* @__PURE__ */BigInt(0),N=/* @__PURE__ */BigInt(1),k=/* @__PURE__ */BigInt(2),R=/* @__PURE__ */BigInt(7),H=/* @__PURE__ */BigInt(256),T=/* @__PURE__ */BigInt(113);for(let e=0,t=N,r=1,n=0;e<24;e++){[r,n]=[n,(2*r+3*n)%5],P.push(2*(5*n+r)),z.push((e+1)*(e+2)/2%64);let i=U;for(let e=0;e<7;e++)t=(t<<N^(t>>R)*T)%H,t&k&&(i^=N<<(N<</* @__PURE__ */BigInt(e))-N);L.push(i)}const[$,j]=/* @__PURE__ */O(L,!0),F=(e,t,r)=>r>32?((e,t,r)=>t<<r-32|e>>>64-r)(e,t,r):((e,t,r)=>e<<r|t>>>32-r)(e,t,r),q=(e,t,r)=>r>32?((e,t,r)=>e<<r-32|t>>>64-r)(e,t,r):((e,t,r)=>t<<r|e>>>32-r)(e,t,r);class C extends B{constructor(e,t,r,n=!1,i=24){if(super(),this.blockLen=e,this.suffix=t,this.outputLen=r,this.enableXOF=n,this.rounds=i,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,y(r),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");var o;this.state=new Uint8Array(200),this.state32=(o=this.state,new Uint32Array(o.buffer,o.byteOffset,Math.floor(o.byteLength/4)))}keccak(){E||v(this.state32),function(e,t=24){const 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){const n=(t+8)%10,i=(t+2)%10,o=r[i],s=r[i+1],a=F(o,s,1)^r[n],u=q(o,s,1)^r[n+1];for(let r=0;r<50;r+=10)e[t+r]^=a,e[t+r+1]^=u}let t=e[2],i=e[3];for(let r=0;r<24;r++){const n=z[r],o=F(t,i,n),s=q(t,i,n),a=P[r];t=e[a],i=e[a+1],e[a]=o,e[a+1]=s}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]^=$[n],e[1]^=j[n]}r.fill(0)}(this.state32,this.rounds),E||v(this.state32),this.posOut=0,this.pos=0}update(e){m(this);const{blockLen:t,state:r}=this,n=(e=x(e)).length;for(let i=0;i<n;){const o=Math.min(t-this.pos,n-i);for(let t=0;t<o;t++)r[this.pos++]^=e[i++];this.pos===t&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:e,suffix:t,pos:r,blockLen:n}=this;e[r]^=t,128&t&&r===n-1&&this.keccak(),e[n-1]^=128,this.keccak()}writeInto(e){m(this,!1),b(e),this.finish();const t=this.state,{blockLen:r}=this;for(let n=0,i=e.length;n<i;){this.posOut>=r&&this.keccak();const o=Math.min(r-this.posOut,i-n);e.set(t.subarray(this.posOut,this.posOut+o),n),this.posOut+=o,n+=o}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return y(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(function(e,t){b(e);const r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(e){const{blockLen:t,suffix:r,outputLen:n,rounds:i,enableXOF:o}=this;return e||(e=new C(t,r,n,o,i)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=i,e.suffix=r,e.outputLen=n,e.enableXOF=o,e.destroyed=this.destroyed,e}}const D=/* @__PURE__ */(()=>function(e){const t=t=>e().update(x(t)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}(()=>new C(136,1,32)))(),V=/* @__PURE__ */BigInt(0),M=/* @__PURE__ */BigInt(1),_=/* @__PURE__ */BigInt(2);function K(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function Z(e){if(!K(e))throw new Error("Uint8Array expected")}function G(e,t){if("boolean"!=typeof t)throw new Error(e+" boolean expected, got "+t)}const W=/* @__PURE__ */Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Y(e){Z(e);let t="";for(let r=0;r<e.length;r++)t+=W[e[r]];return t}function X(e){const t=e.toString(16);return 1&t.length?"0"+t:t}function J(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);return""===e?V:BigInt("0x"+e)}function Q(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:void 0}function ee(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);const t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);const n=new Uint8Array(r);for(let t=0,i=0;t<r;t++,i+=2){const r=Q(e.charCodeAt(i)),o=Q(e.charCodeAt(i+1));if(void 0===r||void 0===o)throw new Error('hex string expected, got non-hex character "'+(e[i]+e[i+1])+'" at index '+i);n[t]=16*r+o}return n}function te(e){return J(Y(e))}function re(e){return Z(e),J(Y(Uint8Array.from(e).reverse()))}function ne(e,t){return ee(e.toString(16).padStart(2*t,"0"))}function ie(e,t){return ne(e,t).reverse()}function oe(e,t,r){let n;if("string"==typeof t)try{n=ee(t)}catch(t){throw new Error(e+" must be hex string or Uint8Array, cause: "+t)}else{if(!K(t))throw new Error(e+" must be hex string or Uint8Array");n=Uint8Array.from(t)}const i=n.length;if("number"==typeof r&&i!==r)throw new Error(e+" of length "+r+" expected, got "+i);return n}function se(...e){let t=0;for(let r=0;r<e.length;r++){const n=e[r];Z(n),t+=n.length}const r=new Uint8Array(t);for(let t=0,n=0;t<e.length;t++){const i=e[t];r.set(i,n),n+=i.length}return r}const ae=e=>"bigint"==typeof e&&V<=e;function ue(e,t,r){return ae(e)&&ae(t)&&ae(r)&&t<=e&&e<r}function ce(e,t,r,n){if(!ue(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function fe(e){let t;for(t=0;e>V;e>>=M,t+=1);return t}const le=e=>(_<<BigInt(e-1))-M,he=e=>new Uint8Array(e),de=e=>Uint8Array.from(e);function ge(e,t,r){if("number"!=typeof e||e<2)throw new Error("hashLen must be a number");if("number"!=typeof t||t<2)throw new Error("qByteLen must be a number");if("function"!=typeof r)throw new Error("hmacFn must be a function");let n=he(e),i=he(e),o=0;const s=()=>{n.fill(1),i.fill(0),o=0},a=(...e)=>r(i,n,...e),u=(e=he())=>{i=a(de([0]),e),n=a(),0!==e.length&&(i=a(de([1]),e),n=a())},c=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let e=0;const r=[];for(;e<t;){n=a();const t=n.slice();r.push(t),e+=n.length}return se(...r)};return(e,t)=>{let r;for(s(),u(e);!(r=t(c()));)u();return s(),r}}const pe={bigint:e=>"bigint"==typeof e,function:e=>"function"==typeof e,boolean:e=>"boolean"==typeof e,string:e=>"string"==typeof e,stringOrUint8Array:e=>"string"==typeof e||K(e),isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>"function"==typeof e&&Number.isSafeInteger(e.outputLen)};function we(e,t,r={}){const n=(t,r,n)=>{const i=pe[r];if("function"!=typeof i)throw new Error("invalid validator function");const o=e[t];if(!(n&&void 0===o||i(o,e)))throw new Error("param "+String(t)+" is invalid. Expected "+r+", got "+o)};for(const[e,r]of Object.entries(t))n(e,r,!1);for(const[e,t]of Object.entries(r))n(e,t,!0);return e}function ye(e){const t=new WeakMap;return(r,...n)=>{const i=t.get(r);if(void 0!==i)return i;const o=e(r,...n);return t.set(r,o),o}}var be={__proto__:null,isBytes:K,abytes:Z,abool:G,bytesToHex:Y,numberToHexUnpadded:X,hexToNumber:J,hexToBytes:ee,bytesToNumberBE:te,bytesToNumberLE:re,numberToBytesBE:ne,numberToBytesLE:ie,numberToVarBytesBE:function(e){return ee(X(e))},ensureBytes:oe,concatBytes:se,equalBytes:function(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return 0===r},utf8ToBytes:function(e){if("string"!=typeof e)throw new Error("string expected");return new Uint8Array((new TextEncoder).encode(e))},inRange:ue,aInRange:ce,bitLen:fe,bitGet:function(e,t){return e>>BigInt(t)&M},bitSet:function(e,t,r){return e|(r?M:V)<<BigInt(t)},bitMask:le,createHmacDrbg:ge,validateObject:we,notImplemented:()=>{throw new Error("not implemented")},memoized:ye};function me(e,t,r){return JSON.stringify(e,(e,r)=>"function"==typeof t?t(e,r):"bigint"==typeof r?r.toString()+"#__bigint":r,r)}function Ee(e,t){if(Ce(e)>t)throw new Ve({givenSize:Ce(e),maxSize:t})}function ve(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:void 0}function xe(e,t){if(ke(e)>t)throw new $e({givenSize:ke(e),maxSize:t})}function Be(e,t={}){const{dir:r,size:n=32}=t;if(0===n)return e;const i=e.replace("0x","");if(i.length>2*n)throw new Fe({size:Math.ceil(i.length/2),targetSize:n,type:"Hex"});return`0x${i["right"===r?"padEnd":"padStart"](2*n,"0")}`}const Ie=/*#__PURE__*/new TextEncoder,Ae=/*#__PURE__*/Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Se(...e){return`0x${e.reduce((e,t)=>e+t.replace("0x",""),"")}`}function Oe(e){return e instanceof Uint8Array?Pe(e):Array.isArray(e)?Pe(new Uint8Array(e)):e}function Pe(e,t={}){let r="";for(let t=0;t<e.length;t++)r+=Ae[e[t]];const n=`0x${r}`;return"number"==typeof t.size?(xe(n,t.size),Ue(n,t.size)):n}function ze(e,t={}){const{signed:r,size:n}=t,i=BigInt(e);let o;n?o=r?(1n<<8n*BigInt(n)-1n)-1n:2n**(8n*BigInt(n))-1n:"number"==typeof e&&(o=BigInt(Number.MAX_SAFE_INTEGER));const s="bigint"==typeof o&&r?-o-1n:0;if(o&&i>o||i<s){const t="bigint"==typeof e?"n":"";throw new Re({max:o?`${o}${t}`:void 0,min:`${s}${t}`,signed:r,size:n,value:`${e}${t}`})}const a=`0x${(r&&i<0?(1n<<BigInt(8*n))+BigInt(i):i).toString(16)}`;return n?function(e,t){return Be(e,{dir:"left",size:t})}(a,n):a}function Le(e,t={}){return Pe(Ie.encode(e),t)}function Ue(e,t){return Be(e,{dir:"right",size:t})}function Ne(e,t,r,n={}){const{strict:i}=n;!function(e,t){if("number"==typeof t&&t>0&&t>ke(e)-1)throw new je({offset:t,position:"start",size:ke(e)})}(e,t);const o=`0x${e.replace("0x","").slice(2*(t??0),2*(r??e.length))}`;return i&&function(e,t,r){if("number"==typeof t&&"number"==typeof r&&ke(e)!==r-t)throw new je({offset:r,position:"end",size:ke(e)})}(o,t,r),o}function ke(e){return Math.ceil((e.length-2)/2)}class Re extends p{constructor({max:e,min:t,signed:r,size:n,value:i}){super(`Number \`${i}\` is not in safe${n?` ${8*n}-bit`:""}${r?" signed":" unsigned"} integer range ${e?`(\`${t}\` to \`${e}\`)`:`(above \`${t}\`)`}`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.IntegerOutOfRangeError"})}}class He extends p{constructor(e){super(`Value \`${"object"==typeof e?me(e):e}\` of type \`${typeof e}\` is an invalid hex type.`,{metaMessages:['Hex types must be represented as `"0x${string}"`.']}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.InvalidHexTypeError"})}}class Te extends p{constructor(e){super(`Value \`${e}\` is an invalid hex value.`,{metaMessages:['Hex values must start with `"0x"` and contain only hexadecimal characters (0-9, a-f, A-F).']}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.InvalidHexValueError"})}}class $e extends p{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"})}}class je extends p{constructor({offset:e,position:t,size:r}){super(`Slice ${"start"===t?"starting":"ending"} at offset \`${e}\` is out-of-bounds (size: \`${r}\`).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.SliceOffsetOutOfBoundsError"})}}class Fe extends p{constructor({size:e,targetSize:t,type:r}){super(`${r.charAt(0).toUpperCase()}${r.slice(1).toLowerCase()} size (\`${e}\`) exceeds padding size (\`${t}\`).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.SizeExceedsPaddingSizeError"})}}const qe=/*#__PURE__*/new TextEncoder;function Ce(e){return e.length}class De extends p{constructor(e){super(`Value \`${"object"==typeof e?me(e):e}\` of type \`${typeof e}\` is an invalid Bytes value.`,{metaMessages:["Bytes values must be of type `Bytes`."]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Bytes.InvalidBytesTypeError"})}}class Ve extends p{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"})}}class Me extends p{constructor({size:e,targetSize:t,type:r}){super(`${r.charAt(0).toUpperCase()}${r.slice(1).toLowerCase()} size (\`${e}\`) exceeds padding size (\`${t}\`).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Bytes.SizeExceedsPaddingSizeError"})}}function _e(e,t={}){const{as:r=("string"==typeof e?"Hex":"Bytes")}=t,n=D(function(e){return e instanceof Uint8Array?e:"string"==typeof e?function(e,t={}){const{size:r}=t;let n=e;r&&(xe(e,r),n=Ue(e,r));let i=n.slice(2);i.length%2&&(i=`0${i}`);const o=i.length/2,s=new Uint8Array(o);for(let e=0,t=0;e<o;e++){const r=ve(i.charCodeAt(t++)),n=ve(i.charCodeAt(t++));if(void 0===r||void 0===n)throw new p(`Invalid byte sequence ("${i[t-2]}${i[t-1]}" in "${i}").`);s[e]=16*r+n}return s}(e):function(e){return e instanceof Uint8Array?e:new Uint8Array(e)}(e)}(e));return"Bytes"===r?n:Pe(n)}class Ke extends Map{constructor(e){super(),Object.defineProperty(this,"maxSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.maxSize=e}get(e){const t=super.get(e);return super.has(e)&&void 0!==t&&(this.delete(e),super.set(e,t)),t}set(e,t){if(super.set(e,t),this.maxSize&&this.size>this.maxSize){const e=this.keys().next().value;e&&this.delete(e)}return this}}const Ze=/*#__PURE__*/new Ke(8192);function Ge(e,t={}){const{compressed:r}=t,{prefix:n,x:i,y:o}=e;if(!1===r||"bigint"==typeof i&&"bigint"==typeof o){if(4!==n)throw new Xe({prefix:n,cause:new Qe})}else{if(!0!==r&&("bigint"!=typeof i||void 0!==o))throw new Ye({publicKey:e});if(3!==n&&2!==n)throw new Xe({prefix:n,cause:new Je})}}function We(e){if(132!==e.length&&130!==e.length&&68!==e.length)throw new et({publicKey:e});return 130===e.length?{prefix:4,x:BigInt(Ne(e,0,32)),y:BigInt(Ne(e,32,64))}:132===e.length?{prefix:Number(Ne(e,0,1)),x:BigInt(Ne(e,1,33)),y:BigInt(Ne(e,33,65))}:{prefix:Number(Ne(e,0,1)),x:BigInt(Ne(e,1,33))}}class Ye extends p{constructor({publicKey:e}){super(`Value \`${me(e)}\` is not a valid public key.`,{metaMessages:["Public key must contain:","- an `x` and `prefix` value (compressed)","- an `x`, `y`, and `prefix` value (uncompressed)"]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"PublicKey.InvalidError"})}}class Xe extends p{constructor({prefix:e,cause:t}){super(`Prefix "${e}" is invalid.`,{cause:t}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"PublicKey.InvalidPrefixError"})}}class Je extends p{constructor(){super("Prefix must be 2 or 3 for compressed public keys."),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"PublicKey.InvalidCompressedPrefixError"})}}class Qe extends p{constructor(){super("Prefix must be 4 for uncompressed public keys."),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"PublicKey.InvalidUncompressedPrefixError"})}}class et extends p{constructor({publicKey:e}){super(`Value \`${e}\` is an invalid public key size.`,{metaMessages:["Expected: 33 bytes (compressed + prefix), 64 bytes (uncompressed) or 65 bytes (uncompressed + prefix).",`Received ${ke(Oe(e))} bytes.`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"PublicKey.InvalidSerializedSizeError"})}}const tt=/^0x[a-fA-F0-9]{40}$/;function rt(e,t={}){const{strict:r=!0}=t;if(!tt.test(e))throw new it({address:e,cause:new ot});if(r){if(e.toLowerCase()===e)return;if(nt(e)!==e)throw new it({address:e,cause:new st})}}function nt(e){if(Ze.has(e))return Ze.get(e);rt(e,{strict:!1});const t=e.substring(2).toLowerCase(),r=_e(function(e,t={}){const{size:r}=t,n=qe.encode(e);return"number"==typeof r?(Ee(n,r),function(e,t){return function(e,t={}){const{dir:r,size:n=32}=t;if(0===n)return e;if(e.length>n)throw new Me({size:e.length,targetSize:n,type:"Bytes"});const i=new Uint8Array(n);for(let t=0;t<n;t++){const o="right"===r;i[o?t:n-t-1]=e[o?t:e.length-t-1]}return i}(e,{dir:"right",size:t})}(n,r)):n}(t),{as:"Bytes"}),n=t.split("");for(let e=0;e<40;e+=2)r[e>>1]>>4>=8&&n[e]&&(n[e]=n[e].toUpperCase()),(15&r[e>>1])>=8&&n[e+1]&&(n[e+1]=n[e+1].toUpperCase());const i=`0x${n.join("")}`;return Ze.set(e,i),i}class it extends p{constructor({address:e,cause:t}){super(`Address "${e}" is invalid.`,{cause:t}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Address.InvalidAddressError"})}}class ot extends p{constructor(){super("Address is not a 20 byte (40 hexadecimal character) value."),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Address.InvalidInputError"})}}class st extends p{constructor(){super("Address does not match its checksum counterpart."),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Address.InvalidChecksumError"})}}function at(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function ut(e,...t){if(!((r=e)instanceof Uint8Array||ArrayBuffer.isView(r)&&"Uint8Array"===r.constructor.name))throw new Error("Uint8Array expected");var r;if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function ct(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}const ft="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0,lt=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),ht=(e,t)=>e<<32-t|e>>>t;function dt(e){return"string"==typeof e&&(e=function(e){if("string"!=typeof e)throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array((new TextEncoder).encode(e))}(e)),ut(e),e}class gt{clone(){return this._cloneInto()}}function pt(e){const t=t=>e().update(dt(t)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function wt(e=32){if(ft&&"function"==typeof ft.getRandomValues)return ft.getRandomValues(new Uint8Array(e));if(ft&&"function"==typeof ft.randomBytes)return ft.randomBytes(e);throw new Error("crypto.getRandomValues must be defined")}const yt=(e,t,r)=>e&t^e&r^t&r;class bt extends gt{constructor(e,t,r,n){super(),this.blockLen=e,this.outputLen=t,this.padOffset=r,this.isLE=n,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=lt(this.buffer)}update(e){ct(this);const{view:t,buffer:r,blockLen:n}=this,i=(e=dt(e)).length;for(let o=0;o<i;){const s=Math.min(n-this.pos,i-o);if(s!==n)r.set(e.subarray(o,o+s),this.pos),this.pos+=s,o+=s,this.pos===n&&(this.process(t,0),this.pos=0);else{const t=lt(e);for(;n<=i-o;o+=n)this.process(t,o)}}return this.length+=e.length,this.roundClean(),this}digestInto(e){ct(this),function(e,t){ut(e);const r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}(e,this),this.finished=!0;const{buffer:t,view:r,blockLen:n,isLE:i}=this;let{pos:o}=this;t[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>n-o&&(this.process(r,0),o=0);for(let e=o;e<n;e++)t[e]=0;!function(e,t,r,n){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,r,n);const i=BigInt(32),o=BigInt(4294967295),s=Number(r>>i&o),a=Number(r&o),u=n?0:4;e.setUint32(t+(n?4:0),s,n),e.setUint32(t+u,a,n)}(r,n-8,BigInt(8*this.length),i),this.process(r,0);const s=lt(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const u=a/4,c=this.get();if(u>c.length)throw new Error("_sha2: outputLen bigger than state");for(let e=0;e<u;e++)s.setUint32(4*e,c[e],i)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const r=e.slice(0,t);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:r,length:n,finished:i,destroyed:o,pos:s}=this;return e.length=n,e.pos=s,e.finished=i,e.destroyed=o,n%t&&e.buffer.set(r),e}}const mt=/* @__PURE__ */new Uint32Array([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]),Et=/* @__PURE__ */new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),vt=/* @__PURE__ */new Uint32Array(64);class xt extends bt{constructor(){super(64,32,8,!1),this.A=0|Et[0],this.B=0|Et[1],this.C=0|Et[2],this.D=0|Et[3],this.E=0|Et[4],this.F=0|Et[5],this.G=0|Et[6],this.H=0|Et[7]}get(){const{A:e,B:t,C:r,D:n,E:i,F:o,G:s,H:a}=this;return[e,t,r,n,i,o,s,a]}set(e,t,r,n,i,o,s,a){this.A=0|e,this.B=0|t,this.C=0|r,this.D=0|n,this.E=0|i,this.F=0|o,this.G=0|s,this.H=0|a}process(e,t){for(let r=0;r<16;r++,t+=4)vt[r]=e.getUint32(t,!1);for(let e=16;e<64;e++){const t=vt[e-15],r=vt[e-2],n=ht(t,7)^ht(t,18)^t>>>3,i=ht(r,17)^ht(r,19)^r>>>10;vt[e]=i+vt[e-7]+n+vt[e-16]|0}let{A:r,B:n,C:i,D:o,E:s,F:a,G:u,H:c}=this;for(let e=0;e<64;e++){const t=c+(ht(s,6)^ht(s,11)^ht(s,25))+((f=s)&a^~f&u)+mt[e]+vt[e]|0,l=(ht(r,2)^ht(r,13)^ht(r,22))+yt(r,n,i)|0;c=u,u=a,a=s,s=o+t|0,o=i,i=n,n=r,r=t+l|0}var f;r=r+this.A|0,n=n+this.B|0,i=i+this.C|0,o=o+this.D|0,s=s+this.E|0,a=a+this.F|0,u=u+this.G|0,c=c+this.H|0,this.set(r,n,i,o,s,a,u,c)}roundClean(){vt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}const Bt=/* @__PURE__ */pt(()=>new xt);class It extends gt{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,function(e){if("function"!=typeof e||"function"!=typeof e.create)throw new Error("Hash should be wrapped by utils.wrapConstructor");at(e.outputLen),at(e.blockLen)}(e);const r=dt(t);if(this.iHash=e.create(),"function"!=typeof this.iHash.update)throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const n=this.blockLen,i=new Uint8Array(n);i.set(r.length>n?e.create().update(r).digest():r);for(let e=0;e<i.length;e++)i[e]^=54;this.iHash.update(i),this.oHash=e.create();for(let e=0;e<i.length;e++)i[e]^=106;this.oHash.update(i),i.fill(0)}update(e){return ct(this),this.iHash.update(e),this}digestInto(e){ct(this),ut(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:t,iHash:r,finished:n,destroyed:i,blockLen:o,outputLen:s}=this;return e.finished=n,e.destroyed=i,e.blockLen=o,e.outputLen=s,e.oHash=t._cloneInto(e.oHash),e.iHash=r._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const At=(e,t,r)=>new It(e,t).update(r).digest();At.create=(e,t)=>new It(e,t);const St=BigInt(0),Ot=BigInt(1),Pt=/* @__PURE__ */BigInt(2),zt=/* @__PURE__ */BigInt(3),Lt=/* @__PURE__ */BigInt(4),Ut=/* @__PURE__ */BigInt(5),Nt=/* @__PURE__ */BigInt(8);function kt(e,t){const r=e%t;return r>=St?r:t+r}function Rt(e,t,r){if(t<St)throw new Error("invalid exponent, negatives unsupported");if(r<=St)throw new Error("invalid modulus");if(r===Ot)return St;let n=Ot;for(;t>St;)t&Ot&&(n=n*e%r),e=e*e%r,t>>=Ot;return n}function Ht(e,t,r){let n=e;for(;t-- >St;)n*=n,n%=r;return n}function Tt(e,t){if(e===St)throw new Error("invert: expected non-zero number");if(t<=St)throw new Error("invert: expected positive modulus, got "+t);let r=kt(e,t),n=t,i=St,o=Ot;for(;r!==St;){const e=n%r,t=i-o*(n/r);n=r,r=e,i=o,o=t}if(n!==Ot)throw new Error("invert: does not exist");return kt(i,t)}const $t=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function jt(e,t){const r=void 0!==t?t:e.toString(2).length;return{nBitLength:r,nByteLength:Math.ceil(r/8)}}function Ft(e,t,r=!1,n={}){if(e<=St)throw new Error("invalid field: expected ORDER > 0, got "+e);const{nBitLength:i,nByteLength:o}=jt(e,t);if(o>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let s;const a=Object.freeze({ORDER:e,BITS:i,BYTES:o,MASK:le(i),ZERO:St,ONE:Ot,create:t=>kt(t,e),isValid:t=>{if("bigint"!=typeof t)throw new Error("invalid field element: expected bigint, got "+typeof t);return St<=t&&t<e},is0:e=>e===St,isOdd:e=>(e&Ot)===Ot,neg:t=>kt(-t,e),eql:(e,t)=>e===t,sqr:t=>kt(t*t,e),add:(t,r)=>kt(t+r,e),sub:(t,r)=>kt(t-r,e),mul:(t,r)=>kt(t*r,e),pow:(e,t)=>function(e,t,r){if(r<St)throw new Error("invalid exponent, negatives unsupported");if(r===St)return e.ONE;if(r===Ot)return t;let n=e.ONE,i=t;for(;r>St;)r&Ot&&(n=e.mul(n,i)),i=e.sqr(i),r>>=Ot;return n}(a,e,t),div:(t,r)=>kt(t*Tt(r,e),e),sqrN:e=>e*e,addN:(e,t)=>e+t,subN:(e,t)=>e-t,mulN:(e,t)=>e*t,inv:t=>Tt(t,e),sqrt:n.sqrt||(t=>(s||(s=function(e){if(e%Lt===zt){const t=(e+Ot)/Lt;return function(e,r){const n=e.pow(r,t);if(!e.eql(e.sqr(n),r))throw new Error("Cannot find square root");return n}}if(e%Nt===Ut){const t=(e-Ut)/Nt;return function(e,r){const n=e.mul(r,Pt),i=e.pow(n,t),o=e.mul(r,i),s=e.mul(e.mul(o,Pt),i),a=e.mul(o,e.sub(s,e.ONE));if(!e.eql(e.sqr(a),r))throw new Error("Cannot find square root");return a}}return function(e){const t=(e-Ot)/Pt;let r,n,i;for(r=e-Ot,n=0;r%Pt===St;r/=Pt,n++);for(i=Pt;i<e&&Rt(i,t,e)!==e-Ot;i++)if(i>1e3)throw new Error("Cannot find square root: likely non-prime P");if(1===n){const t=(e+Ot)/Lt;return function(e,r){const n=e.pow(r,t);if(!e.eql(e.sqr(n),r))throw new Error("Cannot find square root");return n}}const o=(r+Ot)/Pt;return function(e,s){if(e.pow(s,t)===e.neg(e.ONE))throw new Error("Cannot find square root");let a=n,u=e.pow(e.mul(e.ONE,i),r),c=e.pow(s,o),f=e.pow(s,r);for(;!e.eql(f,e.ONE);){if(e.eql(f,e.ZERO))return e.ZERO;let t=1;for(let r=e.sqr(f);t<a&&!e.eql(r,e.ONE);t++)r=e.sqr(r);const r=e.pow(u,Ot<<BigInt(a-t-1));u=e.sqr(r),c=e.mul(c,r),f=e.mul(f,u),a=t}return c}}(e)}(e)),s(a,t))),invertBatch:e=>function(e,t){const r=new Array(t.length),n=t.reduce((t,n,i)=>e.is0(n)?t:(r[i]=t,e.mul(t,n)),e.ONE),i=e.inv(n);return t.reduceRight((t,n,i)=>e.is0(n)?t:(r[i]=e.mul(t,r[i]),e.mul(t,n)),i),r}(a,e),cmov:(e,t,r)=>r?t:e,toBytes:e=>r?ie(e,o):ne(e,o),fromBytes:e=>{if(e.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);return r?re(e):te(e)}});return Object.freeze(a)}function qt(e){if("bigint"!=typeof e)throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function Ct(e){const t=qt(e);return t+Math.ceil(t/2)}const Dt=BigInt(0),Vt=BigInt(1);function Mt(e,t){const r=t.negate();return e?r:t}function _t(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Kt(e,t){return _t(e,t),{windows:Math.ceil(t/e)+1,windowSize:2**(e-1)}}const Zt=new WeakMap,Gt=new WeakMap;function Wt(e){return Gt.get(e)||1}function Yt(e){return we(e.Fp,$t.reduce((e,t)=>(e[t]="function",e),{ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"})),we(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...jt(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}function Xt(e){void 0!==e.lowS&&G("lowS",e.lowS),void 0!==e.prehash&&G("prehash",e.prehash)}const{bytesToNumberBE:Jt,hexToBytes:Qt}=be,er={Err:class extends Error{constructor(e=""){super(e)}},_tlv:{encode:(e,t)=>{const{Err:r}=er;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(1&t.length)throw new r("tlv.encode: unpadded data");const n=t.length/2,i=X(n);if(i.length/2&128)throw new r("tlv.encode: long form length too big");const o=n>127?X(i.length/2|128):"";return X(e)+o+i+t},decode(e,t){const{Err:r}=er;let n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");const i=t[n++];let o=0;if(128&i){const e=127&i;if(!e)throw new r("tlv.decode(long): indefinite length not supported");if(e>4)throw new r("tlv.decode(long): byte length is too big");const s=t.subarray(n,n+e);if(s.length!==e)throw new r("tlv.decode: length bytes not complete");if(0===s[0])throw new r("tlv.decode(long): zero leftmost byte");for(const e of s)o=o<<8|e;if(n+=e,o<128)throw new r("tlv.decode(long): not minimal encoding")}else o=i;const s=t.subarray(n,n+o);if(s.length!==o)throw new r("tlv.decode: wrong value length");return{v:s,l:t.subarray(n+o)}}},_int:{encode(e){const{Err:t}=er;if(e<tr)throw new t("integer: negative integers are not allowed");let r=X(e);if(8&Number.parseInt(r[0],16)&&(r="00"+r),1&r.length)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){const{Err:t}=er;if(128&e[0])throw new t("invalid signature integer: negative");if(0===e[0]&&!(128&e[1]))throw new t("invalid signature integer: unnecessary leading zero");return Jt(e)}},toSig(e){const{Err:t,_int:r,_tlv:n}=er,i="string"==typeof e?Qt(e):e;Z(i);const{v:o,l:s}=n.decode(48,i);if(s.length)throw new t("invalid signature: left bytes after parsing");const{v:a,l:u}=n.decode(2,o),{v:c,l:f}=n.decode(2,u);if(f.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(c)}},hexFromSig(e){const{_tlv:t,_int:r}=er,n=t.encode(2,r.encode(e.r)),i=t.encode(2,r.encode(e.s));return t.encode(48,n+i)}},tr=BigInt(0),rr=BigInt(1);BigInt(2);const nr=BigInt(3);function ir(e){return{hash:e,hmac:(t,...r)=>At(e,t,function(...e){let t=0;for(let r=0;r<e.length;r++){const n=e[r];ut(n),t+=n.length}const r=new Uint8Array(t);for(let t=0,n=0;t<e.length;t++){const i=e[t];r.set(i,n),n+=i.length}return r}(...r)),randomBytes:wt}}BigInt(4);const or=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),sr=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),ar=BigInt(1),ur=BigInt(2),cr=(e,t)=>(e+t/ur)/t,fr=Ft(or,void 0,void 0,{sqrt:function(e){const t=or,r=BigInt(3),n=BigInt(6),i=BigInt(11),o=BigInt(22),s=BigInt(23),a=BigInt(44),u=BigInt(88),c=e*e*e%t,f=c*c*e%t,l=Ht(f,r,t)*f%t,h=Ht(l,r,t)*f%t,d=Ht(h,ur,t)*c%t,g=Ht(d,i,t)*d%t,p=Ht(g,o,t)*g%t,w=Ht(p,a,t)*p%t,y=Ht(w,u,t)*w%t,b=Ht(y,a,t)*p%t,m=Ht(b,r,t)*f%t,E=Ht(m,s,t)*g%t,v=Ht(E,n,t)*c%t,x=Ht(v,ur,t);if(!fr.eql(fr.sqr(x),e))throw new Error("Cannot find square root");return x}}),lr=function(e){const t=t=>function(e){const t=function(e){const t=Yt(e);return we(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}(e),{Fp:r,n:n}=t,i=r.BYTES+1,o=2*r.BYTES+1;function s(e){return kt(e,n)}function a(e){return Tt(e,n)}const{ProjectivePoint:u,normPrivateKeyToScalar:c,weierstrassEquation:f,isWithinCurveOrder:l}=function(e){const t=function(e){const t=Yt(e);we(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});const{endo:r,Fp:n,a:i}=t;if(r){if(!n.eql(i,n.ZERO))throw new Error("invalid endomorphism, can only be defined for Koblitz curves that have a=0");if("object"!=typeof r||"bigint"!=typeof r.beta||"function"!=typeof r.splitScalar)throw new Error("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze({...t})}(e),{Fp:r}=t,n=Ft(t.n,t.nBitLength),i=t.toBytes||((e,t,n)=>{const i=t.toAffine();return se(Uint8Array.from([4]),r.toBytes(i.x),r.toBytes(i.y))}),o=t.fromBytes||(e=>{const t=e.subarray(1);return{x:r.fromBytes(t.subarray(0,r.BYTES)),y:r.fromBytes(t.subarray(r.BYTES,2*r.BYTES))}});function s(e){const{a:n,b:i}=t,o=r.sqr(e),s=r.mul(o,e);return r.add(r.add(s,r.mul(e,n)),i)}if(!r.eql(r.sqr(t.Gy),s(t.Gx)))throw new Error("bad generator point: equation left != right");function a(e){const{allowedPrivateKeyLengths:r,nByteLength:n,wrapPrivateKey:i,n:o}=t;if(r&&"bigint"!=typeof e){if(K(e)&&(e=Y(e)),"string"!=typeof e||!r.includes(e.length))throw new Error("invalid private key");e=e.padStart(2*n,"0")}let s;try{s="bigint"==typeof e?e:te(oe("private key",e,n))}catch(t){throw new Error("invalid private key, expected hex or "+n+" bytes, got "+typeof e)}return i&&(s=kt(s,o)),ce("private key",s,rr,o),s}function u(e){if(!(e instanceof l))throw new Error("ProjectivePoint expected")}const c=ye((e,t)=>{const{px:n,py:i,pz:o}=e;if(r.eql(o,r.ONE))return{x:n,y:i};const s=e.is0();null==t&&(t=s?r.ONE:r.inv(o));const a=r.mul(n,t),u=r.mul(i,t),c=r.mul(o,t);if(s)return{x:r.ZERO,y:r.ZERO};if(!r.eql(c,r.ONE))throw new Error("invZ was invalid");return{x:a,y:u}}),f=ye(e=>{if(e.is0()){if(t.allowInfinityPoint&&!r.is0(e.py))return;throw new Error("bad point: ZERO")}const{x:n,y:i}=e.toAffine();if(!r.isValid(n)||!r.isValid(i))throw new Error("bad point: x or y not FE");const o=r.sqr(i),a=s(n);if(!r.eql(o,a))throw new Error("bad point: equation left != right");if(!e.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class l{constructor(e,t,n){if(this.px=e,this.py=t,this.pz=n,null==e||!r.isValid(e))throw new Error("x required");if(null==t||!r.isValid(t))throw new Error("y required");if(null==n||!r.isValid(n))throw new Error("z required");Object.freeze(this)}static fromAffine(e){const{x:t,y:n}=e||{};if(!e||!r.isValid(t)||!r.isValid(n))throw new Error("invalid affine point");if(e instanceof l)throw new Error("projective point not allowed");const i=e=>r.eql(e,r.ZERO);return i(t)&&i(n)?l.ZERO:new l(t,n,r.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(e){const t=r.invertBatch(e.map(e=>e.pz));return e.map((e,r)=>e.toAffine(t[r])).map(l.fromAffine)}static fromHex(e){const t=l.fromAffine(o(oe("pointHex",e)));return t.assertValidity(),t}static fromPrivateKey(e){return l.BASE.multiply(a(e))}static msm(e,t){return function(e,t,r,n){if(function(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((e,r)=>{if(!(e instanceof t))throw new Error("invalid point at index "+r)})}(r,e),function(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((e,r)=>{if(!t.isValid(e))throw new Error("invalid scalar at index "+r)})}(n,t),r.length!==n.length)throw new Error("arrays of points and scalars must have equal length");const i=e.ZERO,o=fe(BigInt(r.length)),s=o>12?o-3:o>4?o-2:o?2:1,a=(1<<s)-1,u=new Array(a+1).fill(i);let c=i;for(let e=Math.floor((t.BITS-1)/s)*s;e>=0;e-=s){u.fill(i);for(let t=0;t<n.length;t++){const i=Number(n[t]>>BigInt(e)&BigInt(a));u[i]=u[i].add(r[t])}let t=i;for(let e=u.length-1,r=i;e>0;e--)r=r.add(u[e]),t=t.add(r);if(c=c.add(t),0!==e)for(let e=0;e<s;e++)c=c.double()}return c}(l,n,e,t)}_setWindowSize(e){d.setWindowSize(this,e)}assertValidity(){f(this)}hasEvenY(){const{y:e}=this.toAffine();if(r.isOdd)return!r.isOdd(e);throw new Error("Field doesn't support isOdd")}equals(e){u(e);const{px:t,py:n,pz:i}=this,{px:o,py:s,pz:a}=e,c=r.eql(r.mul(t,a),r.mul(o,i)),f=r.eql(r.mul(n,a),r.mul(s,i));return c&&f}negate(){return new l(this.px,r.neg(this.py),this.pz)}double(){const{a:e,b:n}=t,i=r.mul(n,nr),{px:o,py:s,pz:a}=this;let u=r.ZERO,c=r.ZERO,f=r.ZERO,h=r.mul(o,o),d=r.mul(s,s),g=r.mul(a,a),p=r.mul(o,s);return p=r.add(p,p),f=r.mul(o,a),f=r.add(f,f),u=r.mul(e,f),c=r.mul(i,g),c=r.add(u,c),u=r.sub(d,c),c=r.add(d,c),c=r.mul(u,c),u=r.mul(p,u),f=r.mul(i,f),g=r.mul(e,g),p=r.sub(h,g),p=r.mul(e,p),p=r.add(p,f),f=r.add(h,h),h=r.add(f,h),h=r.add(h,g),h=r.mul(h,p),c=r.add(c,h),g=r.mul(s,a),g=r.add(g,g),h=r.mul(g,p),u=r.sub(u,h),f=r.mul(g,d),f=r.add(f,f),f=r.add(f,f),new l(u,c,f)}add(e){u(e);const{px:n,py:i,pz:o}=this,{px:s,py:a,pz:c}=e;let f=r.ZERO,h=r.ZERO,d=r.ZERO;const g=t.a,p=r.mul(t.b,nr);let w=r.mul(n,s),y=r.mul(i,a),b=r.mul(o,c),m=r.add(n,i),E=r.add(s,a);m=r.mul(m,E),E=r.add(w,y),m=r.sub(m,E),E=r.add(n,o);let v=r.add(s,c);return E=r.mul(E,v),v=r.add(w,b),E=r.sub(E,v),v=r.add(i,o),f=r.add(a,c),v=r.mul(v,f),f=r.add(y,b),v=r.sub(v,f),d=r.mul(g,E),f=r.mul(p,b),d=r.add(f,d),f=r.sub(y,d),d=r.add(y,d),h=r.mul(f,d),y=r.add(w,w),y=r.add(y,w),b=r.mul(g,b),E=r.mul(p,E),y=r.add(y,b),b=r.sub(w,b),b=r.mul(g,b),E=r.add(E,b),w=r.mul(y,E),h=r.add(h,w),w=r.mul(v,E),f=r.mul(m,f),f=r.sub(f,w),w=r.mul(m,y),d=r.mul(v,d),d=r.add(d,w),new l(f,h,d)}subtract(e){return this.add(e.negate())}is0(){return this.equals(l.ZERO)}wNAF(e){return d.wNAFCached(this,e,l.normalizeZ)}multiplyUnsafe(e){const{endo:n,n:i}=t;ce("scalar",e,tr,i);const o=l.ZERO;if(e===tr)return o;if(this.is0()||e===rr)return this;if(!n||d.hasPrecomputes(this))return d.wNAFCachedUnsafe(this,e,l.normalizeZ);let{k1neg:s,k1:a,k2neg:u,k2:c}=n.splitScalar(e),f=o,h=o,g=this;for(;a>tr||c>tr;)a&rr&&(f=f.add(g)),c&rr&&(h=h.add(g)),g=g.double(),a>>=rr,c>>=rr;return s&&(f=f.negate()),u&&(h=h.negate()),h=new l(r.mul(h.px,n.beta),h.py,h.pz),f.add(h)}multiply(e){const{endo:n,n:i}=t;let o,s;if(ce("scalar",e,rr,i),n){const{k1neg:t,k1:i,k2neg:a,k2:u}=n.splitScalar(e);let{p:c,f:f}=this.wNAF(i),{p:h,f:g}=this.wNAF(u);c=d.constTimeNegate(t,c),h=d.constTimeNegate(a,h),h=new l(r.mul(h.px,n.beta),h.py,h.pz),o=c.add(h),s=f.add(g)}else{const{p:t,f:r}=this.wNAF(e);o=t,s=r}return l.normalizeZ([o,s])[0]}multiplyAndAddUnsafe(e,t,r){const n=l.BASE,i=(e,t)=>t!==tr&&t!==rr&&e.equals(n)?e.multiply(t):e.multiplyUnsafe(t),o=i(this,t).add(i(e,r));return o.is0()?void 0:o}toAffine(e){return c(this,e)}isTorsionFree(){const{h:e,isTorsionFree:r}=t;if(e===rr)return!0;if(r)return r(l,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:e,clearCofactor:r}=t;return e===rr?this:r?r(l,this):this.multiplyUnsafe(t.h)}toRawBytes(e=!0){return G("isCompressed",e),this.assertValidity(),i(l,this,e)}toHex(e=!0){return G("isCompressed",e),Y(this.toRawBytes(e))}}l.BASE=new l(t.Gx,t.Gy,r.ONE),l.ZERO=new l(r.ZERO,r.ONE,r.ZERO);const h=t.nBitLength,d=(g=l,p=t.endo?Math.ceil(h/2):h,{constTimeNegate:Mt,hasPrecomputes:e=>1!==Wt(e),unsafeLadder(e,t,r=g.ZERO){let n=e;for(;t>Dt;)t&Vt&&(r=r.add(n)),n=n.double(),t>>=Vt;return r},precomputeWindow(e,t){const{windows:r,windowSize:n}=Kt(t,p),i=[];let o=e,s=o;for(let e=0;e<r;e++){s=o,i.push(s);for(let e=1;e<n;e++)s=s.add(o),i.push(s);o=s.double()}return i},wNAF(e,t,r){const{windows:n,windowSize:i}=Kt(e,p);let o=g.ZERO,s=g.BASE;const a=BigInt(2**e-1),u=2**e,c=BigInt(e);for(let e=0;e<n;e++){const n=e*i;let f=Number(r&a);r>>=c,f>i&&(f-=u,r+=Vt);const l=n,h=n+Math.abs(f)-1,d=f<0;0===f?s=s.add(Mt(e%2!=0,t[l])):o=o.add(Mt(d,t[h]))}return{p:o,f:s}},wNAFUnsafe(e,t,r,n=g.ZERO){const{windows:i,windowSize:o}=Kt(e,p),s=BigInt(2**e-1),a=2**e,u=BigInt(e);for(let e=0;e<i;e++){const i=e*o;if(r===Dt)break;let c=Number(r&s);if(r>>=u,c>o&&(c-=a,r+=Vt),0===c)continue;let f=t[i+Math.abs(c)-1];c<0&&(f=f.negate()),n=n.add(f)}return n},getPrecomputes(e,t,r){let n=Zt.get(t);return n||(n=this.precomputeWindow(t,e),1!==e&&Zt.set(t,r(n))),n},wNAFCached(e,t,r){const n=Wt(e);return this.wNAF(n,this.getPrecomputes(n,e,r),t)},wNAFCachedUnsafe(e,t,r,n){const i=Wt(e);return 1===i?this.unsafeLadder(e,t,n):this.wNAFUnsafe(i,this.getPrecomputes(i,e,r),t,n)},setWindowSize(e,t){_t(t,p),Gt.set(e,t),Zt.delete(e)}});var g,p;return{CURVE:t,ProjectivePoint:l,normPrivateKeyToScalar:a,weierstrassEquation:s,isWithinCurveOrder:function(e){return ue(e,rr,t.n)}}}({...t,toBytes(e,t,n){const i=t.toAffine(),o=r.toBytes(i.x),s=se;return G("isCompressed",n),n?s(Uint8Array.from([t.hasEvenY()?2:3]),o):s(Uint8Array.from([4]),o,r.toBytes(i.y))},fromBytes(e){const t=e.length,n=e[0],s=e.subarray(1);if(t!==i||2!==n&&3!==n){if(t===o&&4===n)return{x:r.fromBytes(s.subarray(0,r.BYTES)),y:r.fromBytes(s.subarray(r.BYTES,2*r.BYTES))};throw new Error("invalid Point, expected length of "+i+", or uncompressed "+o+", got "+t)}{const e=te(s);if(!ue(e,rr,r.ORDER))throw new Error("Point is not on curve");const t=f(e);let i;try{i=r.sqrt(t)}catch(e){const t=e instanceof Error?": "+e.message:"";throw new Error("Point is not on curve"+t)}return!(1&~n)!=((i&rr)===rr)&&(i=r.neg(i)),{x:e,y:i}}}}),h=e=>Y(ne(e,t.nByteLength));function d(e){return e>n>>rr}const g=(e,t,r)=>te(e.slice(t,r));class p{constructor(e,t,r){this.r=e,this.s=t,this.recovery=r,this.assertValidity()}static fromCompact(e){const r=t.nByteLength;return e=oe("compactSignature",e,2*r),new p(g(e,0,r),g(e,r,2*r))}static fromDER(e){const{r:t,s:r}=er.toSig(oe("DER",e));return new p(t,r)}assertValidity(){ce("r",this.r,rr,n),ce("s",this.s,rr,n)}addRecoveryBit(e){return new p(this.r,this.s,e)}recoverPublicKey(e){const{r:n,s:i,recovery:o}=this,c=m(oe("msgHash",e));if(null==o||![0,1,2,3].includes(o))throw new Error("recovery id invalid");const f=2===o||3===o?n+t.n:n;if(f>=r.ORDER)throw new Error("recovery id 2 or 3 invalid");const l=u.fromHex((1&o?"03":"02")+h(f)),d=a(f),g=s(-c*d),p=s(i*d),w=u.BASE.multiplyAndAddUnsafe(l,g,p);if(!w)throw new Error("point at infinify");return w.assertValidity(),w}hasHighS(){return d(this.s)}normalizeS(){return this.hasHighS()?new p(this.r,s(-this.s),this.recovery):this}toDERRawBytes(){return ee(this.toDERHex())}toDERHex(){return er.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return ee(this.toCompactHex())}toCompactHex(){return h(this.r)+h(this.s)}}const w={isValidPrivateKey(e){try{return c(e),!0}catch(e){return!1}},normPrivateKeyToScalar:c,randomPrivateKey:()=>{const e=Ct(t.n);return function(e,t,r=!1){const n=e.length,i=qt(t),o=Ct(t);if(n<16||n<o||n>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+n);const s=kt(r?te(e):re(e),t-Ot)+Ot;return r?ie(s,i):ne(s,i)}(t.randomBytes(e),t.n)},precompute:(e=8,t=u.BASE)=>(t._setWindowSize(e),t.multiply(BigInt(3)),t)};function y(e){const t=K(e),r="string"==typeof e,n=(t||r)&&e.length;return t?n===i||n===o:r?n===2*i||n===2*o:e instanceof u}const b=t.bits2int||function(e){if(e.length>8192)throw new Error("input is too large");const r=te(e),n=8*e.length-t.nBitLength;return n>0?r>>BigInt(n):r},m=t.bits2int_modN||function(e){return s(b(e))},E=le(t.nBitLength);function v(e){return ce("num < 2^"+t.nBitLength,e,tr,E),ne(e,t.nByteLength)}const x={lowS:t.lowS,prehash:!1},B={lowS:t.lowS,prehash:!1};return u.BASE._setWindowSize(8),{CURVE:t,getPublicKey:function(e,t=!0){return u.fromPrivateKey(e).toRawBytes(t)},getSharedSecret:function(e,t,r=!0){if(y(e))throw new Error("first arg must be private key");if(!y(t))throw new Error("second arg must be public key");return u.fromHex(t).multiply(c(e)).toRawBytes(r)},sign:function(e,n,i=x){const{seed:o,k2sig:f}=function(e,n,i=x){if(["recovered","canonical"].some(e=>e in i))throw new Error("sign() legacy options not supported");const{hash:o,randomBytes:f}=t;let{lowS:h,prehash:g,extraEntropy:w}=i;null==h&&(h=!0),e=oe("msgHash",e),Xt(i),g&&(e=oe("prehashed msgHash",o(e)));const y=m(e),E=c(n),B=[v(E),v(y)];if(null!=w&&!1!==w){const e=!0===w?f(r.BYTES):w;B.push(oe("extraEntropy",e))}const I=se(...B),A=y;return{seed:I,k2sig:function(e){const t=b(e);if(!l(t))return;const r=a(t),n=u.BASE.multiply(t).toAffine(),i=s(n.x);if(i===tr)return;const o=s(r*s(A+i*E));if(o===tr)return;let c=(n.x===i?0:2)|Number(n.y&rr),f=o;return h&&d(o)&&(f=function(e){return d(e)?s(-e):e}(o),c^=1),new p(i,f,c)}}}(e,n,i);return ge(t.hash.outputLen,t.nByteLength,t.hmac)(o,f)},verify:function(e,r,n,i=B){const o=e;r=oe("msgHash",r),n=oe("publicKey",n);const{lowS:c,prehash:f,format:l}=i;if(Xt(i),"strict"in i)throw new Error("options.strict was renamed to lowS");if(void 0!==l&&"compact"!==l&&"der"!==l)throw new Error("format must be compact or der");const h="string"==typeof o||K(o),d=!h&&!l&&"object"==typeof o&&null!==o&&"bigint"==typeof o.r&&"bigint"==typeof o.s;if(!h&&!d)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let g,w;try{if(d&&(g=new p(o.r,o.s)),h){try{"compact"!==l&&(g=p.fromDER(o))}catch(e){if(!(e instanceof er.Err))throw e}g||"der"===l||(g=p.fromCompact(o))}w=u.fromHex(n)}catch(e){return!1}if(!g)return!1;if(c&&g.hasHighS())return!1;f&&(r=t.hash(r));const{r:y,s:b}=g,E=m(r),v=a(b),x=s(E*v),I=s(y*v),A=u.BASE.multiplyAndAddUnsafe(w,x,I)?.toAffine();return!!A&&s(A.x)===y},ProjectivePoint:u,Signature:p,utils:w}}({...e,...ir(t)});return Object.freeze({...t(Bt),create:t})}({a:BigInt(0),b:BigInt(7),Fp:fr,n:sr,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{const t=sr,r=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-ar*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=r,s=BigInt("0x100000000000000000000000000000000"),a=cr(o*e,t),u=cr(-n*e,t);let c=kt(e-a*r-u*i,t),f=kt(-a*n-u*o,t);const l=c>s,h=f>s;if(l&&(c=t-c),h&&(f=t-f),c>s||f>s)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:l,k1:c,k2neg:h,k2:f}}}});function hr(e){if(130!==e.length&&132!==e.length)throw new dr({signature:e});const t=BigInt(Ne(e,0,32)),r=BigInt(Ne(e,32,64)),n=(()=>{const t=Number(`0x${e.slice(130)}`);if(!Number.isNaN(t))try{return function(e){if(0===e||27===e)return 0;if(1===e||28===e)return 1;if(e>=35)return e%2==0?1:0;throw new pr({value:e})}(t)}catch{throw new gr({value:t})}})();return void 0===n?{r:t,s:r}:{r:t,s:r,yParity:n}}BigInt(0);class dr extends p{constructor({signature:e}){super(`Value \`${e}\` is an invalid signature size.`,{metaMessages:["Expected: 64 bytes or 65 bytes.",`Received ${ke(Oe(e))} bytes.`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Signature.InvalidSerializedSizeError"})}}class gr extends p{constructor({value:e}){super(`Value \`${e}\` is an invalid y-parity value. Y-parity must be 0 or 1.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Signature.InvalidYParityError"})}}class pr extends p{constructor({value:e}){super(`Value \`${e}\` is an invalid v value. v must be 27, 28 or >=35.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Signature.InvalidVError"})}}var wr=function(r){try{switch(r.type){case t.SelfDeclaration:return Promise.resolve(l({},r,{status:r.confirmed?e.VERIFIED:e.FAILED}));case t.Screenshot:return Promise.resolve(l({},r,{status:r.url?e.FLAGGED:e.FAILED}));case t.EIP191:return Promise.resolve(function(t){try{var r=t.address.split(/:/),n=r[2];if("eip155"!==r[0])return Promise.resolve(l({},t,{status:e.FAILED}));var i=function(e,t,r){try{var n=function(e){const{payload:t,signature:r}=e,{r:n,s:i,yParity:o}=r;return function(e){const t=(()=>{if(function(e,t={}){const{strict:r=!1}=t;try{return function(e,t={}){const{strict:r=!1}=t;if(!e)throw new He(e);if("string"!=typeof e)throw new He(e);if(r&&!/^0x[0-9a-fA-F]*$/.test(e))throw new Te(e);if(!e.startsWith("0x"))throw new Te(e)}(e,{strict:r}),!0}catch{return!1}}(e))return We(e);if(function(e){try{return function(e){if(!(e instanceof Uint8Array)){if(!e)throw new De(e);if("object"!=typeof e)throw new De(e);if(!("BYTES_PER_ELEMENT"in e))throw new De(e);if(1!==e.BYTES_PER_ELEMENT||"Uint8Array"!==e.constructor.name)throw new De(e)}}(e),!0}catch{return!1}}(e))return function(e){return We(Pe(e))}(e);const{prefix:t,x:r,y:n}=e;return"bigint"==typeof r&&"bigint"==typeof n?{prefix:t??4,x:r,y:n}:{prefix:t,x:r}})();return Ge(t),t}(new lr.Signature(BigInt(n),BigInt(i)).addRecoveryBit(o).recoverPublicKey(Oe(t).substring(2)))}({payload:(i=Le(t),_e(function(e){const t=Oe(e);return Se("0x19",Le("Ethereum Signed Message:\n"+ke(t)),t)}(i))),signature:hr(r)});return function(e,t={}){const r=_e(`0x${function(e,t={}){Ge(e);const{prefix:r,x:n,y:i}=e,{includePrefix:o=!0}=t;return Se(o?ze(r,{size:1}):"0x",ze(n,{size:32}),"bigint"==typeof i?ze(i,{size:32}):"0x")}(e).slice(4)}`).substring(26);return function(e,t={}){const{checksum:r=!1}=t;return rt(e),r?nt(e):e}(`0x${r}`,t)}(n).toString()===e.toString()}catch(e){return!1}var i}(n,t.attestation,t.proof);return Promise.resolve(l({},t,{status:i?e.VERIFIED:e.FAILED}))}catch(e){return Promise.reject(e)}}(r));case t.ED25519:return Promise.resolve(function(t){try{var r=t.address.split(/:/),n=r[2];if("solana"!==r[0])return Promise.resolve(l({},t,{status:e.FAILED}));try{var i=f.decode(n),o=(new TextEncoder).encode(t.attestation),s=u(t.proof),a=c.sign.detached.verify(o,s,i);return Promise.resolve(l({},t,{status:a?e.VERIFIED:e.FAILED}))}catch(r){return Promise.resolve(l({},t,{status:e.FAILED}))}}catch(e){return Promise.reject(e)}}(r));case t.EIP712:case t.BIP137:return Promise.resolve(function(t){try{var r=t.address.split(/:/),c=r[2];if("bip122"!==r[0])return Promise.resolve(l({},t,{status:e.FAILED}));try{var f=[d.SEGWIT,d.NATIVE].includes(function(e){if(e.match("^(bc1|tb1|ltc1).*"))return d.NATIVE;if(e.match("^[32M].*"))return d.SEGWIT;if(e.match("^[1nmL].*"))return d.LEGACY;if(e.match("^(D).*"))return d.DOGECOIN;throw new Error("INVALID ADDRESS: ".concat(e).concat(" is not a valid or a supported address"))}(c)),p=function(e,t,r,c){var f=function(e){var t=u(e);if(65!==t.length)throw new Error("Invalid signature length");var r=t[0]-27;if(r>15||r<0)throw new Error("Invalid signature parameter");return{compressed:!!(12&r),segwitType:8&r?4&r?h.P2WPKH:h.P2SH_P2WPKH:void 0,recovery:3&r,signature:t.slice(1)}}(r),l=f.compressed,d=f.segwitType,p=f.recovery,w=f.signature;if(c&&!l)throw new Error("checkSegwitAlways can only be used with a compressed pubkey signature flagbyte");var y=function(e){var t=(new TextEncoder).encode("Bitcoin Signed Message:\n"),r=(new TextEncoder).encode(e),n=a(r.length).buffer,i=new Uint8Array(t.length+n.byteLength+r.length);return i.set(t),i.set(new Uint8Array(n),t.length),i.set(r,t.length+n.byteLength),s(i)}(e),b=l?n.recoverPublicKeyCompressed(w,p,y):n.recoverPublicKeyUncompressed(w,p,y);if("string"==typeof b)throw new Error(b);var m=i(b),E="";if(d)E=g(m);else if(c)try{E=g(m)}catch(e){E=g(m)}else E=o(0,m);return E===t}(t.attestation,c,t.proof,f);return Promise.resolve(l({},t,{status:p?e.VERIFIED:e.FAILED}))}catch(r){return Promise.resolve(l({},t,{status:e.FAILED}))}}catch(e){return Promise.reject(e)}}(r))}return Promise.resolve(r)}catch(e){return Promise.reject(e)}};export{wr as verifyProof};
2
2
  //# sourceMappingURL=index.js.map