@notabene/verify-proof 1.0.0-preview.6 → 1.0.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/dist/bitcoin.d.ts CHANGED
@@ -1,12 +1,2 @@
1
- import { SignatureProof } from "@notabene/javascript-sdk/src/types";
2
- export declare enum DerivationMode {
3
- LEGACY = "Legacy",
4
- NATIVE = "Native SegWit",
5
- SEGWIT = "SegWit",
6
- P2SH_SEGWIT = "p2sh",
7
- BCH = "Bitcoin Cash",
8
- ETHEREUM = "Ethereum",
9
- DOGECOIN = "Dogecoin",
10
- UNKNOWN = "Unknown"
11
- }
1
+ import { SignatureProof } from "@notabene/javascript-sdk";
12
2
  export declare function verifyBTCSignature(proof: SignatureProof): Promise<SignatureProof>;
package/dist/eth.d.ts CHANGED
@@ -1,2 +1,4 @@
1
- import { SignatureProof } from "@notabene/javascript-sdk/src/types";
1
+ import { SignatureProof } from "@notabene/javascript-sdk";
2
+ import { Hex } from "ox";
3
+ export declare function verifyEIP191(address: Hex.Hex, message: string, proof: Hex.Hex): boolean;
2
4
  export declare function verifyPersonalSignEIP191(proof: SignatureProof): Promise<SignatureProof>;
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- var e=require("@notabene/javascript-sdk/src/types"),r=require("bitcoinjs-message"),t=require("viem"),o=require("@solana/web3.js"),s=require("tweetnacl"),a=require("@stablelib/base64");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function u(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach(function(t){if("default"!==t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})}}),r.default=e,r}var i,c=/*#__PURE__*/u(r),f=/*#__PURE__*/n(s);function P(){return P=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var o in t)({}).hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},P.apply(null,arguments)}!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"}(i||(i={})),exports.verifyProof=function(r){try{switch(r.type){case e.ProofTypes.SelfDeclaration:return Promise.resolve(P({},r,{status:r.confirmed?e.ProofStatus.VERIFIED:e.ProofStatus.FAILED}));case e.ProofTypes.Screenshot:return Promise.resolve(P({},r,{status:r.url?e.ProofStatus.FLAGGED:e.ProofStatus.FAILED}));case e.ProofTypes.EIP191:return Promise.resolve(function(r){try{var o=r.address.split(/:/),s=o[2];return"eip155"!==o[0]?Promise.resolve(P({},r,{status:e.ProofStatus.FAILED})):Promise.resolve(t.verifyMessage({address:s,message:r.attestation,signature:r.proof})).then(function(t){return P({},r,{status:t?e.ProofStatus.VERIFIED:e.ProofStatus.FAILED})})}catch(e){return Promise.reject(e)}}(r));case e.ProofTypes.ED25519:return Promise.resolve(function(r){try{var t=r.address.split(/:/),s=t[2];if("solana"!==t[0])return Promise.resolve(P({},r,{status:e.ProofStatus.FAILED}));try{var n=new o.PublicKey(s),u=(new TextEncoder).encode(r.attestation),i=a.decode(r.proof),c=f.default.sign.detached.verify(u,i,n.toBytes());return Promise.resolve(P({},r,{status:c?e.ProofStatus.VERIFIED:e.ProofStatus.FAILED}))}catch(t){return Promise.resolve(P({},r,{status:e.ProofStatus.FAILED}))}}catch(e){return Promise.reject(e)}}(r));case e.ProofTypes.EIP712:case e.ProofTypes.BIP137:return Promise.resolve(function(r){try{var t=r.address.split(/:/),o=t[2];if("bip122"!==t[0])return Promise.resolve(P({},r,{status:e.ProofStatus.FAILED}));try{var s=[i.SEGWIT,i.NATIVE].includes(function(e){if(e.match("^(bc1|tb1|ltc1).*"))return i.NATIVE;if(e.match("^[32M].*"))return i.SEGWIT;if(e.match("^[1nmL].*"))return i.LEGACY;if(e.match("^(D).*"))return i.DOGECOIN;throw new Error("INVALID ADDRESS: ".concat(e).concat(" is not a valid or a supported address"))}(o)),a=c.verify(r.attestation,o,r.proof,void 0,s);return Promise.resolve(P({},r,{status:a?e.ProofStatus.VERIFIED:e.ProofStatus.FAILED}))}catch(t){return Promise.resolve(P({},r,{status:e.ProofStatus.FAILED}))}}catch(e){return Promise.reject(e)}}(r))}return Promise.resolve(r)}catch(e){return Promise.reject(e)}};
1
+ var e=require("@notabene/javascript-sdk"),t=require("bech32"),r=require("@bitauth/libauth"),n=require("varuint-bitcoin"),i=require("@stablelib/base64"),o=require("tweetnacl"),s=require("bs58");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u,c,f=/*#__PURE__*/a(o),l=/*#__PURE__*/a(s);function h(){return h=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},h.apply(null,arguments)}function d(e){var r=t.bech32.toWords(e);return r.unshift(0),t.bech32.encode("bc",r)}!function(e){e.P2WPKH="p2wpkh",e.P2SH_P2WPKH="p2sh(p2wpkh)"}(u||(u={})),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"}(c||(c={}));class g extends Error{constructor(e,t={}){const r=(()=>{if(t.cause instanceof g){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 g&&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 p(this,e)}}function p(e,t){return t?.(e)?e:e&&"object"==typeof e&&"cause"in e&&e.cause?p(e.cause,t):t?null:e}function w(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function y(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 b(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 m=/* @__PURE__ */(()=>68===new Uint8Array(new Uint32Array([287454020]).buffer)[0])();function E(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 v(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)),y(e),e}class x{clone(){return this._cloneInto()}}const B=/* @__PURE__ */BigInt(2**32-1),I=/* @__PURE__ */BigInt(32);function S(e,t=!1){return t?{h:Number(e&B),l:Number(e>>I&B)}:{h:0|Number(e>>I&B),l:0|Number(e&B)}}function A(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=[],O=[],z=[],L=/* @__PURE__ */BigInt(0),U=/* @__PURE__ */BigInt(1),N=/* @__PURE__ */BigInt(2),k=/* @__PURE__ */BigInt(7),R=/* @__PURE__ */BigInt(256),T=/* @__PURE__ */BigInt(113);for(let e=0,t=U,r=1,n=0;e<24;e++){[r,n]=[n,(2*r+3*n)%5],P.push(2*(5*n+r)),O.push((e+1)*(e+2)/2%64);let i=L;for(let e=0;e<7;e++)t=(t<<U^(t>>k)*T)%R,t&N&&(i^=U<<(U<</* @__PURE__ */BigInt(e))-U);z.push(i)}const[H,q]=/* @__PURE__ */A(z,!0),j=(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),$=(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 F extends x{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,w(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(){m||E(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=j(o,s,1)^r[n],u=$(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=O[r],o=j(t,i,n),s=$(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]^=H[n],e[1]^=q[n]}r.fill(0)}(this.state32,this.rounds),m||E(this.state32),this.posOut=0,this.pos=0}update(e){b(this);const{blockLen:t,state:r}=this,n=(e=v(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){b(this,!1),y(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 w(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(function(e,t){y(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 F(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 C=/* @__PURE__ */(()=>function(e){const t=t=>e().update(v(t)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}(()=>new F(136,1,32)))(),D=/* @__PURE__ */BigInt(0),V=/* @__PURE__ */BigInt(1),M=/* @__PURE__ */BigInt(2);function _(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function K(e){if(!_(e))throw new Error("Uint8Array expected")}function Z(e,t){if("boolean"!=typeof t)throw new Error(e+" boolean expected, got "+t)}const G=/* @__PURE__ */Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function W(e){K(e);let t="";for(let r=0;r<e.length;r++)t+=G[e[r]];return t}function Y(e){const t=e.toString(16);return 1&t.length?"0"+t:t}function X(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);return""===e?D:BigInt("0x"+e)}function J(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:void 0}function Q(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=J(e.charCodeAt(i)),o=J(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 ee(e){return X(W(e))}function te(e){return K(e),X(W(Uint8Array.from(e).reverse()))}function re(e,t){return Q(e.toString(16).padStart(2*t,"0"))}function ne(e,t){return re(e,t).reverse()}function ie(e,t,r){let n;if("string"==typeof t)try{n=Q(t)}catch(t){throw new Error(e+" must be hex string or Uint8Array, cause: "+t)}else{if(!_(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 oe(...e){let t=0;for(let r=0;r<e.length;r++){const n=e[r];K(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 se=e=>"bigint"==typeof e&&D<=e;function ae(e,t,r){return se(e)&&se(t)&&se(r)&&t<=e&&e<r}function ue(e,t,r,n){if(!ae(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function ce(e){let t;for(t=0;e>D;e>>=V,t+=1);return t}const fe=e=>(M<<BigInt(e-1))-V,le=e=>new Uint8Array(e),he=e=>Uint8Array.from(e);function de(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=le(e),i=le(e),o=0;const s=()=>{n.fill(1),i.fill(0),o=0},a=(...e)=>r(i,n,...e),u=(e=le())=>{i=a(he([0]),e),n=a(),0!==e.length&&(i=a(he([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 oe(...r)};return(e,t)=>{let r;for(s(),u(e);!(r=t(c()));)u();return s(),r}}const ge={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||_(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 pe(e,t,r={}){const n=(t,r,n)=>{const i=ge[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 we(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 ye={__proto__:null,isBytes:_,abytes:K,abool:Z,bytesToHex:W,numberToHexUnpadded:Y,hexToNumber:X,hexToBytes:Q,bytesToNumberBE:ee,bytesToNumberLE:te,numberToBytesBE:re,numberToBytesLE:ne,numberToVarBytesBE:function(e){return Q(Y(e))},ensureBytes:ie,concatBytes:oe,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:ae,aInRange:ue,bitLen:ce,bitGet:function(e,t){return e>>BigInt(t)&V},bitSet:function(e,t,r){return e|(r?V:D)<<BigInt(t)},bitMask:fe,createHmacDrbg:de,validateObject:pe,notImplemented:()=>{throw new Error("not implemented")},memoized:we};function be(e,t,r){return JSON.stringify(e,(e,r)=>"function"==typeof t?t(e,r):"bigint"==typeof r?r.toString()+"#__bigint":r,r)}function me(e,t){if(Fe(e)>t)throw new De({givenSize:Fe(e),maxSize:t})}function Ee(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:void 0}function ve(e,t){if(Ne(e)>t)throw new He({givenSize:Ne(e),maxSize:t})}function xe(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 je({size:Math.ceil(i.length/2),targetSize:n,type:"Hex"});return`0x${i["right"===r?"padEnd":"padStart"](2*n,"0")}`}const Be=/*#__PURE__*/new TextEncoder,Ie=/*#__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 Ae(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+=Ie[e[t]];const n=`0x${r}`;return"number"==typeof t.size?(ve(n,t.size),Le(n,t.size)):n}function Oe(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 ke({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 xe(e,{dir:"left",size:t})}(a,n):a}function ze(e,t={}){return Pe(Be.encode(e),t)}function Le(e,t){return xe(e,{dir:"right",size:t})}function Ue(e,t,r,n={}){const{strict:i}=n;!function(e,t){if("number"==typeof t&&t>0&&t>Ne(e)-1)throw new qe({offset:t,position:"start",size:Ne(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&&Ne(e)!==r-t)throw new qe({offset:r,position:"end",size:Ne(e)})}(o,t,r),o}function Ne(e){return Math.ceil((e.length-2)/2)}class ke extends g{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 Re extends g{constructor(e){super(`Value \`${"object"==typeof e?be(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 g{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 He extends g{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 qe extends g{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 je extends g{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 $e=/*#__PURE__*/new TextEncoder;function Fe(e){return e.length}class Ce extends g{constructor(e){super(`Value \`${"object"==typeof e?be(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 De extends g{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 Ve extends g{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 Me(e,t={}){const{as:r=("string"==typeof e?"Hex":"Bytes")}=t,n=C(function(e){return e instanceof Uint8Array?e:"string"==typeof e?function(e,t={}){const{size:r}=t;let n=e;r&&(ve(e,r),n=Le(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=Ee(i.charCodeAt(t++)),n=Ee(i.charCodeAt(t++));if(void 0===r||void 0===n)throw new g(`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 _e 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 Ke=/*#__PURE__*/new _e(8192);function Ze(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 Ye({prefix:n,cause:new Je})}else{if(!0!==r&&("bigint"!=typeof i||void 0!==o))throw new We({publicKey:e});if(3!==n&&2!==n)throw new Ye({prefix:n,cause:new Xe})}}function Ge(e){if(132!==e.length&&130!==e.length&&68!==e.length)throw new Qe({publicKey:e});return 130===e.length?{prefix:4,x:BigInt(Ue(e,0,32)),y:BigInt(Ue(e,32,64))}:132===e.length?{prefix:Number(Ue(e,0,1)),x:BigInt(Ue(e,1,33)),y:BigInt(Ue(e,33,65))}:{prefix:Number(Ue(e,0,1)),x:BigInt(Ue(e,1,33))}}class We extends g{constructor({publicKey:e}){super(`Value \`${be(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 Ye extends g{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 Xe extends g{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 Je extends g{constructor(){super("Prefix must be 4 for uncompressed public keys."),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"PublicKey.InvalidUncompressedPrefixError"})}}class Qe extends g{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 ${Ne(Ae(e))} bytes.`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"PublicKey.InvalidSerializedSizeError"})}}const et=/^0x[a-fA-F0-9]{40}$/;function tt(e,t={}){const{strict:r=!0}=t;if(!et.test(e))throw new nt({address:e,cause:new it});if(r){if(e.toLowerCase()===e)return;if(rt(e)!==e)throw new nt({address:e,cause:new ot})}}function rt(e){if(Ke.has(e))return Ke.get(e);tt(e,{strict:!1});const t=e.substring(2).toLowerCase(),r=Me(function(e,t={}){const{size:r}=t,n=$e.encode(e);return"number"==typeof r?(me(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 Ve({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 Ke.set(e,i),i}class nt extends g{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 it extends g{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 ot extends g{constructor(){super("Address does not match its checksum counterpart."),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Address.InvalidChecksumError"})}}function st(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function at(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 ut(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 ct="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0,ft=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),lt=(e,t)=>e<<32-t|e>>>t;function ht(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)),at(e),e}class dt{clone(){return this._cloneInto()}}function gt(e){const t=t=>e().update(ht(t)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function pt(e=32){if(ct&&"function"==typeof ct.getRandomValues)return ct.getRandomValues(new Uint8Array(e));if(ct&&"function"==typeof ct.randomBytes)return ct.randomBytes(e);throw new Error("crypto.getRandomValues must be defined")}const wt=(e,t,r)=>e&t^e&r^t&r;class yt extends dt{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=ft(this.buffer)}update(e){ut(this);const{view:t,buffer:r,blockLen:n}=this,i=(e=ht(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=ft(e);for(;n<=i-o;o+=n)this.process(t,o)}}return this.length+=e.length,this.roundClean(),this}digestInto(e){ut(this),function(e,t){at(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=ft(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 bt=/* @__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]),mt=/* @__PURE__ */new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Et=/* @__PURE__ */new Uint32Array(64);class vt extends yt{constructor(){super(64,32,8,!1),this.A=0|mt[0],this.B=0|mt[1],this.C=0|mt[2],this.D=0|mt[3],this.E=0|mt[4],this.F=0|mt[5],this.G=0|mt[6],this.H=0|mt[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)Et[r]=e.getUint32(t,!1);for(let e=16;e<64;e++){const t=Et[e-15],r=Et[e-2],n=lt(t,7)^lt(t,18)^t>>>3,i=lt(r,17)^lt(r,19)^r>>>10;Et[e]=i+Et[e-7]+n+Et[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+(lt(s,6)^lt(s,11)^lt(s,25))+((f=s)&a^~f&u)+bt[e]+Et[e]|0,l=(lt(r,2)^lt(r,13)^lt(r,22))+wt(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(){Et.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}const xt=/* @__PURE__ */gt(()=>new vt);class Bt extends dt{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");st(e.outputLen),st(e.blockLen)}(e);const r=ht(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 ut(this),this.iHash.update(e),this}digestInto(e){ut(this),at(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 It=(e,t,r)=>new Bt(e,t).update(r).digest();It.create=(e,t)=>new Bt(e,t);const St=BigInt(0),At=BigInt(1),Pt=/* @__PURE__ */BigInt(2),Ot=/* @__PURE__ */BigInt(3),zt=/* @__PURE__ */BigInt(4),Lt=/* @__PURE__ */BigInt(5),Ut=/* @__PURE__ */BigInt(8);function Nt(e,t){const r=e%t;return r>=St?r:t+r}function kt(e,t,r){if(t<St)throw new Error("invalid exponent, negatives unsupported");if(r<=St)throw new Error("invalid modulus");if(r===At)return St;let n=At;for(;t>St;)t&At&&(n=n*e%r),e=e*e%r,t>>=At;return n}function Rt(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=Nt(e,t),n=t,i=St,o=At;for(;r!==St;){const e=n%r,t=i-o*(n/r);n=r,r=e,i=o,o=t}if(n!==At)throw new Error("invert: does not exist");return Nt(i,t)}const Ht=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function qt(e,t){const r=void 0!==t?t:e.toString(2).length;return{nBitLength:r,nByteLength:Math.ceil(r/8)}}function jt(e,t,r=!1,n={}){if(e<=St)throw new Error("invalid field: expected ORDER > 0, got "+e);const{nBitLength:i,nByteLength:o}=qt(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:fe(i),ZERO:St,ONE:At,create:t=>Nt(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&At)===At,neg:t=>Nt(-t,e),eql:(e,t)=>e===t,sqr:t=>Nt(t*t,e),add:(t,r)=>Nt(t+r,e),sub:(t,r)=>Nt(t-r,e),mul:(t,r)=>Nt(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===At)return t;let n=e.ONE,i=t;for(;r>St;)r&At&&(n=e.mul(n,i)),i=e.sqr(i),r>>=At;return n}(a,e,t),div:(t,r)=>Nt(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%zt===Ot){const t=(e+At)/zt;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%Ut===Lt){const t=(e-Lt)/Ut;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-At)/Pt;let r,n,i;for(r=e-At,n=0;r%Pt===St;r/=Pt,n++);for(i=Pt;i<e&&kt(i,t,e)!==e-At;i++)if(i>1e3)throw new Error("Cannot find square root: likely non-prime P");if(1===n){const t=(e+At)/zt;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+At)/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,At<<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?ne(e,o):re(e,o),fromBytes:e=>{if(e.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);return r?te(e):ee(e)}});return Object.freeze(a)}function $t(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 Ft(e){const t=$t(e);return t+Math.ceil(t/2)}const Ct=BigInt(0),Dt=BigInt(1);function Vt(e,t){const r=t.negate();return e?r:t}function Mt(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function _t(e,t){return Mt(e,t),{windows:Math.ceil(t/e)+1,windowSize:2**(e-1)}}const Kt=new WeakMap,Zt=new WeakMap;function Gt(e){return Zt.get(e)||1}function Wt(e){return pe(e.Fp,Ht.reduce((e,t)=>(e[t]="function",e),{ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"})),pe(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...qt(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}function Yt(e){void 0!==e.lowS&&Z("lowS",e.lowS),void 0!==e.prehash&&Z("prehash",e.prehash)}const{bytesToNumberBE:Xt,hexToBytes:Jt}=ye,Qt={Err:class extends Error{constructor(e=""){super(e)}},_tlv:{encode:(e,t)=>{const{Err:r}=Qt;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=Y(n);if(i.length/2&128)throw new r("tlv.encode: long form length too big");const o=n>127?Y(i.length/2|128):"";return Y(e)+o+i+t},decode(e,t){const{Err:r}=Qt;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}=Qt;if(e<er)throw new t("integer: negative integers are not allowed");let r=Y(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}=Qt;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 Xt(e)}},toSig(e){const{Err:t,_int:r,_tlv:n}=Qt,i="string"==typeof e?Jt(e):e;K(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}=Qt,n=t.encode(2,r.encode(e.r)),i=t.encode(2,r.encode(e.s));return t.encode(48,n+i)}},er=BigInt(0),tr=BigInt(1);BigInt(2);const rr=BigInt(3);function nr(e){return{hash:e,hmac:(t,...r)=>It(e,t,function(...e){let t=0;for(let r=0;r<e.length;r++){const n=e[r];at(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:pt}}BigInt(4);const ir=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),or=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),sr=BigInt(1),ar=BigInt(2),ur=(e,t)=>(e+t/ar)/t,cr=jt(ir,void 0,void 0,{sqrt:function(e){const t=ir,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=Rt(f,r,t)*f%t,h=Rt(l,r,t)*f%t,d=Rt(h,ar,t)*c%t,g=Rt(d,i,t)*d%t,p=Rt(g,o,t)*g%t,w=Rt(p,a,t)*p%t,y=Rt(w,u,t)*w%t,b=Rt(y,a,t)*p%t,m=Rt(b,r,t)*f%t,E=Rt(m,s,t)*g%t,v=Rt(E,n,t)*c%t,x=Rt(v,ar,t);if(!cr.eql(cr.sqr(x),e))throw new Error("Cannot find square root");return x}}),fr=function(e){const t=t=>function(e){const t=function(e){const t=Wt(e);return pe(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 Nt(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=Wt(e);pe(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=jt(t.n,t.nBitLength),i=t.toBytes||((e,t,n)=>{const i=t.toAffine();return oe(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(_(e)&&(e=W(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:ee(ie("private key",e,n))}catch(t){throw new Error("invalid private key, expected hex or "+n+" bytes, got "+typeof e)}return i&&(s=Nt(s,o)),ue("private key",s,tr,o),s}function u(e){if(!(e instanceof l))throw new Error("ProjectivePoint expected")}const c=we((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=we(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(ie("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=ce(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,rr),{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,rr);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;ue("scalar",e,er,i);const o=l.ZERO;if(e===er)return o;if(this.is0()||e===tr)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>er||c>er;)a&tr&&(f=f.add(g)),c&tr&&(h=h.add(g)),g=g.double(),a>>=tr,c>>=tr;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(ue("scalar",e,tr,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!==er&&t!==tr&&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===tr)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===tr?this:r?r(l,this):this.multiplyUnsafe(t.h)}toRawBytes(e=!0){return Z("isCompressed",e),this.assertValidity(),i(l,this,e)}toHex(e=!0){return Z("isCompressed",e),W(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:Vt,hasPrecomputes:e=>1!==Gt(e),unsafeLadder(e,t,r=g.ZERO){let n=e;for(;t>Ct;)t&Dt&&(r=r.add(n)),n=n.double(),t>>=Dt;return r},precomputeWindow(e,t){const{windows:r,windowSize:n}=_t(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}=_t(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+=Dt);const l=n,h=n+Math.abs(f)-1,d=f<0;0===f?s=s.add(Vt(e%2!=0,t[l])):o=o.add(Vt(d,t[h]))}return{p:o,f:s}},wNAFUnsafe(e,t,r,n=g.ZERO){const{windows:i,windowSize:o}=_t(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===Ct)break;let c=Number(r&s);if(r>>=u,c>o&&(c-=a,r+=Dt),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=Kt.get(t);return n||(n=this.precomputeWindow(t,e),1!==e&&Kt.set(t,r(n))),n},wNAFCached(e,t,r){const n=Gt(e);return this.wNAF(n,this.getPrecomputes(n,e,r),t)},wNAFCachedUnsafe(e,t,r,n){const i=Gt(e);return 1===i?this.unsafeLadder(e,t,n):this.wNAFUnsafe(i,this.getPrecomputes(i,e,r),t,n)},setWindowSize(e,t){Mt(t,p),Zt.set(e,t),Kt.delete(e)}});var g,p;return{CURVE:t,ProjectivePoint:l,normPrivateKeyToScalar:a,weierstrassEquation:s,isWithinCurveOrder:function(e){return ae(e,tr,t.n)}}}({...t,toBytes(e,t,n){const i=t.toAffine(),o=r.toBytes(i.x),s=oe;return Z("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=ee(s);if(!ae(e,tr,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&tr)===tr)&&(i=r.neg(i)),{x:e,y:i}}}}),h=e=>W(re(e,t.nByteLength));function d(e){return e>n>>tr}const g=(e,t,r)=>ee(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=ie("compactSignature",e,2*r),new p(g(e,0,r),g(e,r,2*r))}static fromDER(e){const{r:t,s:r}=Qt.toSig(ie("DER",e));return new p(t,r)}assertValidity(){ue("r",this.r,tr,n),ue("s",this.s,tr,n)}addRecoveryBit(e){return new p(this.r,this.s,e)}recoverPublicKey(e){const{r:n,s:i,recovery:o}=this,c=m(ie("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 Q(this.toDERHex())}toDERHex(){return Qt.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Q(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=Ft(t.n);return function(e,t,r=!1){const n=e.length,i=$t(t),o=Ft(t);if(n<16||n<o||n>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+n);const s=Nt(r?ee(e):te(e),t-At)+At;return r?ne(s,i):re(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=_(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=ee(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=fe(t.nBitLength);function v(e){return ue("num < 2^"+t.nBitLength,e,er,E),re(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=ie("msgHash",e),Yt(i),g&&(e=ie("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(ie("extraEntropy",e))}const I=oe(...B),S=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===er)return;const o=s(r*s(S+i*E));if(o===er)return;let c=(n.x===i?0:2)|Number(n.y&tr),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 de(t.hash.outputLen,t.nByteLength,t.hmac)(o,f)},verify:function(e,r,n,i=B){const o=e;r=ie("msgHash",r),n=ie("publicKey",n);const{lowS:c,prehash:f,format:l}=i;if(Yt(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||_(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 Qt.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),S=u.BASE.multiplyAndAddUnsafe(w,x,I)?.toAffine();return!!S&&s(S.x)===y},ProjectivePoint:u,Signature:p,utils:w}}({...e,...nr(t)});return Object.freeze({...t(xt),create:t})}({a:BigInt(0),b:BigInt(7),Fp:cr,n:or,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{const t=or,r=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-sr*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=r,s=BigInt("0x100000000000000000000000000000000"),a=ur(o*e,t),u=ur(-n*e,t);let c=Nt(e-a*r-u*i,t),f=Nt(-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 lr(e){if(130!==e.length&&132!==e.length)throw new hr({signature:e});const t=BigInt(Ue(e,0,32)),r=BigInt(Ue(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 gr({value:e})}(t)}catch{throw new dr({value:t})}})();return void 0===n?{r:t,s:r}:{r:t,s:r,yParity:n}}BigInt(0);class hr extends g{constructor({signature:e}){super(`Value \`${e}\` is an invalid signature size.`,{metaMessages:["Expected: 64 bytes or 65 bytes.",`Received ${Ne(Ae(e))} bytes.`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Signature.InvalidSerializedSizeError"})}}class dr extends g{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 gr extends g{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"})}}exports.verifyProof=function(t){try{switch(t.type){case e.ProofTypes.SelfDeclaration:return Promise.resolve(h({},t,{status:t.confirmed?e.ProofStatus.VERIFIED:e.ProofStatus.FAILED}));case e.ProofTypes.Screenshot:return Promise.resolve(h({},t,{status:t.url?e.ProofStatus.FLAGGED:e.ProofStatus.FAILED}));case e.ProofTypes.EIP191:return Promise.resolve(function(t){try{var r=t.address.split(/:/),n=r[2];if("eip155"!==r[0])return Promise.resolve(h({},t,{status:e.ProofStatus.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 Re(e);if("string"!=typeof e)throw new Re(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 Ge(e);if(function(e){try{return function(e){if(!(e instanceof Uint8Array)){if(!e)throw new Ce(e);if("object"!=typeof e)throw new Ce(e);if(!("BYTES_PER_ELEMENT"in e))throw new Ce(e);if(1!==e.BYTES_PER_ELEMENT||"Uint8Array"!==e.constructor.name)throw new Ce(e)}}(e),!0}catch{return!1}}(e))return function(e){return Ge(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 Ze(t),t}(new fr.Signature(BigInt(n),BigInt(i)).addRecoveryBit(o).recoverPublicKey(Ae(t).substring(2)))}({payload:(i=ze(t),Me(function(e){const t=Ae(e);return Se("0x19",ze("Ethereum Signed Message:\n"+Ne(t)),t)}(i))),signature:lr(r)});return function(e,t={}){const r=Me(`0x${function(e,t={}){Ze(e);const{prefix:r,x:n,y:i}=e,{includePrefix:o=!0}=t;return Se(o?Oe(r,{size:1}):"0x",Oe(n,{size:32}),"bigint"==typeof i?Oe(i,{size:32}):"0x")}(e).slice(4)}`).substring(26);return function(e,t={}){const{checksum:r=!1}=t;return tt(e),r?rt(e):e}(`0x${r}`,t)}(n).toString()===e.toString()}catch(e){return!1}var i}(n,t.attestation,t.proof);return Promise.resolve(h({},t,{status:i?e.ProofStatus.VERIFIED:e.ProofStatus.FAILED}))}catch(e){return Promise.reject(e)}}(t));case e.ProofTypes.ED25519:return Promise.resolve(function(t){try{var r=t.address.split(/:/),n=r[2];if("solana"!==r[0])return Promise.resolve(h({},t,{status:e.ProofStatus.FAILED}));try{var o=l.default.decode(n),s=(new TextEncoder).encode(t.attestation),a=i.decode(t.proof),u=f.default.sign.detached.verify(s,a,o);return Promise.resolve(h({},t,{status:u?e.ProofStatus.VERIFIED:e.ProofStatus.FAILED}))}catch(r){return Promise.resolve(h({},t,{status:e.ProofStatus.FAILED}))}}catch(e){return Promise.reject(e)}}(t));case e.ProofTypes.EIP712:case e.ProofTypes.BIP137:return Promise.resolve(function(t){try{var o=t.address.split(/:/),s=o[2];if("bip122"!==o[0])return Promise.resolve(h({},t,{status:e.ProofStatus.FAILED}));try{var a=[c.SEGWIT,c.NATIVE].includes(function(e){if(e.match("^(bc1|tb1|ltc1).*"))return c.NATIVE;if(e.match("^[32M].*"))return c.SEGWIT;if(e.match("^[1nmL].*"))return c.LEGACY;if(e.match("^(D).*"))return c.DOGECOIN;throw new Error("INVALID ADDRESS: ".concat(e).concat(" is not a valid or a supported address"))}(s)),f=function(e,t,o,s){var a=function(e){var t=i.decode(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?u.P2WPKH:u.P2SH_P2WPKH:void 0,recovery:3&r,signature:t.slice(1)}}(o),c=a.compressed,f=a.segwitType,l=a.recovery,h=a.signature;if(s&&!c)throw new Error("checkSegwitAlways can only be used with a compressed pubkey signature flagbyte");var g=function(e){var t=(new TextEncoder).encode("Bitcoin Signed Message:\n"),i=(new TextEncoder).encode(e),o=n.encode(i.length).buffer,s=new Uint8Array(t.length+o.byteLength+i.length);return s.set(t),s.set(new Uint8Array(o),t.length),s.set(i,t.length+o.byteLength),r.hash256(s)}(e),p=c?r.secp256k1.recoverPublicKeyCompressed(h,l,g):r.secp256k1.recoverPublicKeyUncompressed(h,l,g);if("string"==typeof p)throw new Error(p);var w=r.hash160(p),y="";if(f)y=d(w);else if(s)try{y=d(w)}catch(e){y=d(w)}else y=r.encodeBase58AddressFormat(0,w);return y===t}(t.attestation,s,t.proof,a);return Promise.resolve(h({},t,{status:f?e.ProofStatus.VERIFIED:e.ProofStatus.FAILED}))}catch(r){return Promise.resolve(h({},t,{status:e.ProofStatus.FAILED}))}}catch(e){return Promise.reject(e)}}(t))}return Promise.resolve(t)}catch(e){return Promise.reject(e)}};
2
2
  //# sourceMappingURL=index.cjs.map