@hdwallet/core
Version:
A complete Hierarchical Deterministic (HD) Wallet generator for 200+ cryptocurrencies, built with TypeScript.
1 lines • 1.24 MB
JavaScript
const __$G=typeof globalThis!=="undefined"?globalThis:typeof window!=="undefined"?window:typeof global!=="undefined"?global:typeof self!=="undefined"?self:{};const __name__="hdwallet";const __version__="1.0.0-beta.10";const __license__="MIT";const __author__="Meheret Tesfaye Batu";const __email__="meherett.batu@gmail.com";const __description__="A complete Hierarchical Deterministic (HD) Wallet generator for 200+ cryptocurrencies, built with TypeScript.";const __url__="https://hdwallet.io";const __source__="https://github.com/hdwallet-io/hdwallet.js";const __changelog__=`${__source__}/blob/master/CHANGELOG.md`;const __tracker__=`${__source__}/issues`;const __keywords__=["ecc","kholaw","slip10","ed25519","nist256p1","secp256k1","hd","bip32","bip44","bip49","bip84","bip86","bip141","monero","cardano","entropy","mnemonic","seed","bip39","algorand","electrum","cryptocurrencies","bitcoin","ethereum","cryptography","cli","cip1852"];const __websites__=["https://talonlab.org","https://talonlab.gitbook.io/hdwallet","https://hdwallet.online","https://hd.wallet",__url__];var info=Object.freeze({__proto__:null,__name__:__name__,__version__:__version__,__license__:__license__,__author__:__author__,__email__:__email__,__description__:__description__,__url__:__url__,__source__:__source__,__changelog__:__changelog__,__tracker__:__tracker__,__keywords__:__keywords__,__websites__:__websites__});class BaseError extends Error{constructor(message,options){if((options?.expected||options?.got)&&options?.detail){super(`${message}, (expected: ${options?.expected} | got: ${options?.got}) ${options?.detail}`)}else if(options?.expected||options?.got){super(`${message}, (expected: ${options?.expected} | got: ${options?.got})`)}else if(options?.detail){super(`${message} ${options?.detail}`)}else{super(`${message}`)}}}class TypeError$1 extends BaseError{}class EntropyError extends BaseError{}class MnemonicError extends BaseError{}class SeedError extends BaseError{}class ECCError extends BaseError{}class ExtendedKeyError extends BaseError{}class XPrivateKeyError extends BaseError{}class XPublicKeyError extends BaseError{}class PrivateKeyError extends BaseError{}class WIFError extends BaseError{}class PublicKeyError extends BaseError{}class ChecksumError extends BaseError{}class SemanticError extends BaseError{}class NetworkError extends BaseError{}class AddressError extends BaseError{}class CryptocurrencyError extends BaseError{}class SymbolError extends BaseError{}class HDError extends BaseError{}class DerivationError extends BaseError{}const crypto$2=typeof globalThis==="object"&&"crypto"in globalThis?globalThis.crypto:undefined;function isBytes(a){return a instanceof Uint8Array||ArrayBuffer.isView(a)&&a.constructor.name==="Uint8Array"}function anumber(n){if(!Number.isSafeInteger(n)||n<0)throw new Error("positive integer expected, got "+n)}function abytes(b,...lengths){if(!isBytes(b))throw new Error("Uint8Array expected");if(lengths.length>0&&!lengths.includes(b.length))throw new Error("Uint8Array expected of length "+lengths+", got length="+b.length)}function ahash(h){if(typeof h!=="function"||typeof h.create!=="function")throw new Error("Hash should be wrapped by utils.createHasher");anumber(h.outputLen);anumber(h.blockLen)}function aexists(instance,checkFinished=true){if(instance.destroyed)throw new Error("Hash instance has been destroyed");if(checkFinished&&instance.finished)throw new Error("Hash#digest() has already been called")}function aoutput(out,instance){abytes(out);const min=instance.outputLen;if(out.length<min){throw new Error("digestInto() expects output buffer of length at least "+min)}}function u32(arr){return new Uint32Array(arr.buffer,arr.byteOffset,Math.floor(arr.byteLength/4))}function clean(...arrays){for(let i=0;i<arrays.length;i++){arrays[i].fill(0)}}function createView(arr){return new DataView(arr.buffer,arr.byteOffset,arr.byteLength)}function rotr(word,shift){return word<<32-shift|word>>>shift}function rotl(word,shift){return word<<shift|word>>>32-shift>>>0}const isLE=(()=>new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68)();function byteSwap(word){return word<<24&4278190080|word<<8&16711680|word>>>8&65280|word>>>24&255}const swap8IfBE=isLE?n=>n:n=>byteSwap(n);function byteSwap32(arr){for(let i=0;i<arr.length;i++){arr[i]=byteSwap(arr[i])}return arr}const swap32IfBE=isLE?u=>u:byteSwap32;const hasHexBuiltin=(()=>typeof Uint8Array.from([]).toHex==="function"&&typeof Uint8Array.fromHex==="function")();const hexes=Array.from({length:256},(_,i)=>i.toString(16).padStart(2,"0"));function bytesToHex$1(bytes){abytes(bytes);if(hasHexBuiltin)return bytes.toHex();let hex="";for(let i=0;i<bytes.length;i++){hex+=hexes[bytes[i]]}return hex}const asciis={_0:48,_9:57,A:65,F:70,a:97,f:102};function asciiToBase16(ch){if(ch>=asciis._0&&ch<=asciis._9)return ch-asciis._0;if(ch>=asciis.A&&ch<=asciis.F)return ch-(asciis.A-10);if(ch>=asciis.a&&ch<=asciis.f)return ch-(asciis.a-10);return}function hexToBytes$1(hex){if(typeof hex!=="string")throw new Error("hex string expected, got "+typeof hex);if(hasHexBuiltin)return Uint8Array.fromHex(hex);const hl=hex.length;const al=hl/2;if(hl%2)throw new Error("hex string expected, got unpadded hex of length "+hl);const array=new Uint8Array(al);for(let ai=0,hi=0;ai<al;ai++,hi+=2){const n1=asciiToBase16(hex.charCodeAt(hi));const n2=asciiToBase16(hex.charCodeAt(hi+1));if(n1===undefined||n2===undefined){const char=hex[hi]+hex[hi+1];throw new Error('hex string expected, got non-hex character "'+char+'" at index '+hi)}array[ai]=n1*16+n2}return array}function utf8ToBytes(str){if(typeof str!=="string")throw new Error("string expected");return new Uint8Array((new TextEncoder).encode(str))}function toBytes(data){if(typeof data==="string")data=utf8ToBytes(data);abytes(data);return data}function kdfInputToBytes(data){if(typeof data==="string")data=utf8ToBytes(data);abytes(data);return data}function concatBytes$1(...arrays){let sum=0;for(let i=0;i<arrays.length;i++){const a=arrays[i];abytes(a);sum+=a.length}const res=new Uint8Array(sum);for(let i=0,pad=0;i<arrays.length;i++){const a=arrays[i];res.set(a,pad);pad+=a.length}return res}function checkOpts(defaults,opts){if(opts!==undefined&&{}.toString.call(opts)!=="[object Object]")throw new Error("options should be object or undefined");const merged=Object.assign(defaults,opts);return merged}class Hash{}function createHasher(hashCons){const hashC=msg=>hashCons().update(toBytes(msg)).digest();const tmp=hashCons();hashC.outputLen=tmp.outputLen;hashC.blockLen=tmp.blockLen;hashC.create=()=>hashCons();return hashC}function createOptHasher(hashCons){const hashC=(msg,opts)=>hashCons(opts).update(toBytes(msg)).digest();const tmp=hashCons({});hashC.outputLen=tmp.outputLen;hashC.blockLen=tmp.blockLen;hashC.create=opts=>hashCons(opts);return hashC}function randomBytes$1(bytesLength=32){if(crypto$2&&typeof crypto$2.getRandomValues==="function"){return crypto$2.getRandomValues(new Uint8Array(bytesLength))}if(crypto$2&&typeof crypto$2.randomBytes==="function"){return Uint8Array.from(crypto$2.randomBytes(bytesLength))}throw new Error("crypto.getRandomValues must be defined")}function getBytes(data,encoding="hex"){if(data==null){return new Uint8Array}if(data instanceof Uint8Array){return data}if(Array.isArray(data)){return new Uint8Array(data)}const str=data;switch(encoding){case"hex":{let s=str.startsWith("0x")||str.startsWith("0X")?str.slice(2):str;if(s.length%2===1)s="0"+s;return Uint8Array.from(s.match(/.{1,2}/g).map(b=>parseInt(b,16)))}case"utf8":return(new TextEncoder).encode(str);case"base64":return Uint8Array.from(atob(str),c=>c.charCodeAt(0));default:throw new Error(`Unsupported encoding: ${encoding}`)}}function toBuffer(input,encoding="utf8"){if(typeof input==="string"){switch(encoding){case"utf8":return(new TextEncoder).encode(input);case"base64":return Uint8Array.from(atob(input),c=>c.charCodeAt(0));case"hex":return Uint8Array.from(input.match(/.{1,2}/g).map(byte=>parseInt(byte,16)));default:throw new Error(`Unsupported encoding: ${encoding}`)}}if(input instanceof ArrayBuffer){return new Uint8Array(input)}if(ArrayBuffer.isView(input)){return new Uint8Array(input.buffer,input.byteOffset,input.byteLength)}return Uint8Array.from(input)}function hexToBytes(hex){const normalized=hex.startsWith("0x")?hex.slice(2):hex;if(normalized.length%2!==0){throw new Error(`Invalid hex string length: ${normalized.length}`)}const bytes=new Uint8Array(normalized.length/2);for(let i=0;i<bytes.length;i++){bytes[i]=parseInt(normalized.substr(i*2,2),16)}return bytes}function bytesToHex(bytes,prefix=false){const hex=Array.from(bytes).map(b=>b.toString(16).padStart(2,"0")).join("");return prefix?`0x${hex}`:hex}function bytesToString(data){if(data==null||typeof data==="string"&&data.length===0||data instanceof Uint8Array&&data.length===0){return""}if(typeof data==="string"){if(data.length%2===0&&/^[0-9A-Fa-f]+$/.test(data)){return data.toLowerCase()}const encoder=new TextEncoder;const bytes=encoder.encode(data);return bytesToHex(bytes)}return bytesToHex(data)}function randomBytes(len){if(!Number.isInteger(len)||len<=0){throw new Error("randomBytes: length must be a positive integer")}return randomBytes$1(len)}function bytesToInteger(bytes,littleEndian=false){const data=littleEndian?bytes.slice().reverse():bytes;return data.reduce((acc,b)=>(acc<<BigInt(8))+BigInt(b),BigInt(0))}function ensureString(data){if(data instanceof Uint8Array){return(new TextDecoder).decode(data)}if(typeof data==="string"){return data}throw new TypeError$1("Invalid value for string")}function stringToInteger(data){let buf;if(typeof data==="string"){buf=hexToBytes(data)}else{buf=data}let val=BigInt(0);for(let i=0;i<buf.length;i++){val=(val<<BigInt(8))+BigInt(buf[i])}return val}function equalBytes(a,b){if(a.length!==b.length)return false;for(let i=0;i<a.length;i++){if(a[i]!==b[i])return false}return true}function integerToBytes(value,length,endianness="big"){let val=typeof value==="number"?BigInt(value):value;if(val<BigInt(0)){throw new Error(`Cannot convert negative integers: ${val}`)}const bytes=[];const ZERO=BigInt(0);const SHIFT=BigInt(8);const MASK=BigInt(255);while(val>ZERO){bytes.unshift(Number(val&MASK));val=val>>SHIFT}if(bytes.length===0){bytes.push(0)}if(length!==undefined){if(bytes.length>length){throw new Error(`Integer too large to fit in ${length} bytes`)}while(bytes.length<length){bytes.unshift(0)}}const result=new Uint8Array(bytes);return endianness==="little"?result.reverse():result}function concatBytes(...chunks){const totalLength=chunks.reduce((sum,arr)=>sum+arr.length,0);const result=new Uint8Array(totalLength);let offset=0;for(const chunk of chunks){result.set(chunk,offset);offset+=chunk.length}return result}function bytesToBinaryString(data,zeroPadBits=0){const bits=Array.from(data).map(b=>b.toString(2).padStart(8,"0")).join("");return bits.length<zeroPadBits?bits.padStart(zeroPadBits,"0"):bits}function binaryStringToInteger(data){const bin=typeof data==="string"?data:bytesToBinaryString(data);const clean=bin.trim();return BigInt("0b"+clean)}function integerToBinaryString(data,zeroPadBits=0){const big=typeof data==="bigint"?data:BigInt(data);const bits=big.toString(2);return bits.length<zeroPadBits?bits.padStart(zeroPadBits,"0"):bits}function binaryStringToBytes(data,zeroPadByteLen=0){const bits=typeof data==="string"?data.trim():bytesToBinaryString(data);const bitLen=bits.length;const val=BigInt("0b"+bits);let hex=val.toString(16);if(hex.length%2===1){hex="0"+hex}const byteLen=zeroPadByteLen>0?zeroPadByteLen:Math.ceil(bitLen/8);const expectedHexLen=byteLen*2;if(hex.length<expectedHexLen){hex=hex.padStart(expectedHexLen,"0")}return hexToBytes(hex)}function isAllEqual(...inputs){if(inputs.length<2)return true;const getTag=v=>{if(typeof v==="string")return"string";if(typeof v==="number")return"number";if(typeof v==="boolean")return"boolean";if(Array.isArray(v)){if(v.every(i=>typeof i==="number"))return"array:number";if(v.every(i=>typeof i==="string"))return"array:string";if(v.every(i=>typeof i==="boolean"))return"array:boolean";return"array:unknown"}if(v instanceof Uint8Array)return"uint8array";if(v instanceof ArrayBuffer)return"arraybuffer";if(ArrayBuffer.isView(v))return"view";return"unknown"};const firstTag=getTag(inputs[0]);if(firstTag==="unknown"||firstTag==="array:unknown")return false;for(const v of inputs.slice(1)){if(getTag(v)!==firstTag)return false}if(firstTag==="string"||firstTag==="number"||firstTag==="boolean"){const first=inputs[0];return inputs.every(v=>v===first)}if(firstTag.startsWith("array:")){const firstArr=inputs[0];const len=firstArr.length;return inputs.slice(1).every(item=>{const arr=item;if(arr.length!==len)return false;for(let i=0;i<len;i++){if(arr[i]!==firstArr[i])return false}return true})}const normalize=v=>{if(v instanceof Uint8Array)return v;if(v instanceof ArrayBuffer)return new Uint8Array(v);return new Uint8Array(v.buffer,v.byteOffset,v.byteLength)};const firstArr=normalize(inputs[0]);const len=firstArr.byteLength;return inputs.slice(1).every(item=>{const arr=normalize(item);if(arr.byteLength!==len)return false;for(let i=0;i<len;i++){if(arr[i]!==firstArr[i])return false}return true})}function generatePassphrase(length=32,chars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"){const bytes=randomBytes(length);let result="";for(let i=0;i<length;i++){result+=chars[bytes[i]%chars.length]}return result}function getHmac(eccName){const encoder=new TextEncoder;if(["Kholaw-Ed25519","SLIP10-Ed25519","SLIP10-Ed25519-Blake2b","SLIP10-Ed25519-Monero"].includes(eccName)){return encoder.encode("ed25519 seed")}else if(eccName==="SLIP10-Nist256p1"){return encoder.encode("Nist256p1 seed")}else if(eccName==="SLIP10-Secp256k1"){return encoder.encode("Bitcoin seed")}throw new DerivationError("Unknown ECC name")}function excludeKeys(nested,keys){const out={};const keySet=new Set(keys);for(const[k,v]of Object.entries(nested)){const normKey=k.replace(/-/g,"_");if(keySet.has(normKey))continue;if(v&&typeof v==="object"&&!Array.isArray(v)&&!(v instanceof Uint8Array)&&!(v instanceof Uint8Array)){out[k]=excludeKeys(v,keys)}else{out[k]=v}}return out}function pathToIndexes(path){if(path==="m"||path==="m/")return[];if(!path.startsWith("m/")){throw new DerivationError(`Bad path format, expected 'm/0'/0', got '${path}'`)}return path.slice(2).split("/").map(i=>i.endsWith("'")?parseInt(i.slice(0,-1),10)+2147483648:parseInt(i,10))}function indexesToPath(indexes){return"m"+indexes.map(i=>i&2147483648?`/${(i&~2147483648).toString()}'`:`/${i.toString()}`).join("")}function normalizeIndex(index,hardened=false){if(typeof index==="number"){if(index<0)throw new DerivationError(`Bad index: ${index}`);return[index,hardened]}if(typeof index==="string"){const m=index.match(/^(\d+)(?:-(\d+))?$/);if(!m){throw new DerivationError(`Bad index format, got '${index}'`)}const from=parseInt(m[1],10);const to=m[2]?parseInt(m[2],10):undefined;if(to===undefined)return[from,hardened];if(from>to){throw new DerivationError(`Range start ${from} > end ${to}`)}return[from,to,hardened]}if(Array.isArray(index)){const[a,b]=index;if(index.length!==2||typeof a!=="number"||typeof b!=="number"){throw new DerivationError(`Bad index tuple: ${JSON.stringify(index)}`)}if(a<0||b<0){throw new DerivationError(`Negative in tuple: ${index}`)}if(a>b){throw new DerivationError(`Range start ${a} > end ${b}`)}return[a,b,hardened]}throw new DerivationError(`Invalid index instance, got ${typeof index}`)}function normalizeDerivation(path,indexes){let _path="m";const _indexes=[];const _deriv=[];if(indexes&&path){throw new DerivationError("Provide either path or indexes, not both")}if(indexes){path=indexesToPath(indexes)}if(!path||path==="m"||path==="m/"){return[`${_path}/`,_indexes,_deriv]}if(!path.startsWith("m/")){throw new DerivationError(`Bad path format, got '${path}'`)}for(const seg of path.slice(2).split("/")){const hardened=seg.endsWith("'");const core=hardened?seg.slice(0,-1):seg;const parts=core.split("-").map(x=>parseInt(x,10));if(parts.length===2){const[from,to]=parts;if(from>to){throw new DerivationError(`Range start ${from} > end ${to}`)}_deriv.push([from,to,hardened]);_indexes.push(to+(hardened?2147483648:0));_path+=hardened?`/${to}'`:`/${to}`}else{const idx=parts[0];_deriv.push([idx,hardened]);_indexes.push(idx+(hardened?2147483648:0));_path+=hardened?`/${idx}'`:`/${idx}`}}return[_path,_indexes,_deriv]}function indexTupleToInteger(idx){if(idx.length===2){const[i,h]=idx;return i+(h?2147483648:0)}else{const[from,to,h]=idx;return to+(h?2147483648:0)}}function indexTupleToString(idx){if(idx.length===2){const[i,h]=idx;return`${i}${h?"'":""}`}else{const[from,to,h]=idx;return`${from}-${to}${h?"'":""}`}}function indexStringToTuple(i){const hardened=i.endsWith("'");const num=parseInt(hardened?i.slice(0,-1):i,10);return[num,hardened]}function xor(a,b){if(a.length!==b.length)throw new DerivationError("Uint8Arrays must match length for XOR");return getBytes(a.map((x,i)=>x^b[i]))}function addNoCarry(a,b){if(a.length!==b.length)throw new DerivationError("Uint8Arrays must match length for addNoCarry");return getBytes(a.map((x,i)=>x+b[i]&255))}function multiplyScalarNoCarry(data,scalar){return getBytes(data.map(x=>x*scalar&255))}function isBitsSet(value,bitNum){return(value&1<<bitNum)!==0}function areBitsSet(value,mask){return(value&mask)!==0}function setBit(value,bitNum){return value|1<<bitNum}function setBits(value,mask){return value|mask}function resetBit(value,bitNum){return value&~(1<<bitNum)}function resetBits(value,mask){return value&~mask}function bytesReverse(data){return getBytes(data).reverse()}function convertBits$2(data,fromBits,toBits){const input=Array.isArray(data)?data:Array.from(data);const maxVal=(1<<toBits)-1;let acc=0;let bits=0;const out=[];for(const val of input){if(val<0||val>>fromBits){return null}acc|=val<<bits;bits+=fromBits;while(bits>=toBits){out.push(acc&maxVal);acc>>=toBits;bits-=toBits}}if(bits>0){out.push(acc&maxVal)}return out}function bytesChunkToWords(bytesChunk,wordsList,endianness){const len=BigInt(wordsList.length);let chunkNum=bytesToInteger(new Uint8Array(bytesChunk),endianness!=="big");const i1=Number(chunkNum%len);const i2=Number((chunkNum/len+BigInt(i1))%len);const i3=Number((chunkNum/len/len+BigInt(i2))%len);return[wordsList[i1],wordsList[i2],wordsList[i3]]}function wordsToBytesChunk(w1,w2,w3,wordsList,endianness){const len=BigInt(wordsList.length);const idxMap=new Map(wordsList.map((w,i)=>[w,BigInt(i)]));const i1=idxMap.get(w1);const i2=idxMap.get(w2);const i3=idxMap.get(w3);const chunk=i1+len*((i2-i1+len)%len)+len*len*((i3-i2+len)%len);const u8=integerToBytes(chunk,4,endianness);return getBytes(u8)}function toCamelCase(input){return input.toLowerCase().replace(/-([a-z])/g,(_,char)=>char.toUpperCase())}function ensureTypeMatch(instanceOrClass,expectedType,options={}){const tryMatch=type=>{if(type==="any")return true;if(type==="null")return instanceOrClass===null;if(type==="array")return Array.isArray(instanceOrClass);if(typeof type==="string")return typeof instanceOrClass===type;if(typeof type==="function"){if(typeof instanceOrClass==="function"){let proto=instanceOrClass;while(proto&&proto!==Function.prototype){if(proto===type)return true;proto=Object.getPrototypeOf(proto)}return false}return options.strict?instanceOrClass?.constructor===type:instanceOrClass instanceof type}return false};const allExpectedTypes=[expectedType,...options.otherTypes||[]];const matched=allExpectedTypes.find(tryMatch);if(!matched&&(options.errorClass||options.otherTypes)){const expectedNames=allExpectedTypes.map(type=>typeof type==="function"?type.name:String(type));const gotName=typeof instanceOrClass==="function"?instanceOrClass.name:instanceOrClass?.constructor?.name??typeof instanceOrClass;if(options.errorClass){throw new options.errorClass(`Invalid type`,{expected:expectedNames,got:gotName})}else{throw new TypeError$1(`Invalid type`,{expected:expectedNames,got:gotName})}}return matched&&options.errorClass?instanceOrClass:{value:instanceOrClass,isValid:tryMatch(expectedType)}}var utils=Object.freeze({__proto__:null,getBytes:getBytes,toBuffer:toBuffer,hexToBytes:hexToBytes,bytesToHex:bytesToHex,bytesToString:bytesToString,randomBytes:randomBytes,bytesToInteger:bytesToInteger,ensureString:ensureString,stringToInteger:stringToInteger,equalBytes:equalBytes,integerToBytes:integerToBytes,concatBytes:concatBytes,bytesToBinaryString:bytesToBinaryString,binaryStringToInteger:binaryStringToInteger,integerToBinaryString:integerToBinaryString,binaryStringToBytes:binaryStringToBytes,isAllEqual:isAllEqual,generatePassphrase:generatePassphrase,getHmac:getHmac,excludeKeys:excludeKeys,pathToIndexes:pathToIndexes,indexesToPath:indexesToPath,normalizeIndex:normalizeIndex,normalizeDerivation:normalizeDerivation,indexTupleToInteger:indexTupleToInteger,indexTupleToString:indexTupleToString,indexStringToTuple:indexStringToTuple,xor:xor,addNoCarry:addNoCarry,multiplyScalarNoCarry:multiplyScalarNoCarry,isBitsSet:isBitsSet,areBitsSet:areBitsSet,setBit:setBit,setBits:setBits,resetBit:resetBit,resetBits:resetBits,bytesReverse:bytesReverse,convertBits:convertBits$2,bytesChunkToWords:bytesChunkToWords,wordsToBytesChunk:wordsToBytesChunk,toCamelCase:toCamelCase,ensureTypeMatch:ensureTypeMatch});class NestedNamespace{constructor(data){if(data instanceof Set){data.forEach(item=>{this[item]=item})}else if(Array.isArray(data)){data.forEach(item=>{if(item!=null&&typeof item==="object"&&!Array.isArray(item)){Object.entries(item).forEach(([key,value])=>{this[key]=value!=null&&typeof value==="object"?new NestedNamespace(value):value})}else{this[item]=item}})}else{Object.entries(data).forEach(([key,value])=>{this[key]=value!=null&&typeof value==="object"?new NestedNamespace(value):value})}}}const SLIP10_ED25519_CONST={PRIVATE_KEY_BYTE_LENGTH:32,PUBLIC_KEY_PREFIX:integerToBytes(0),PUBLIC_KEY_BYTE_LENGTH:32};const KHOLAW_ED25519_CONST={...SLIP10_ED25519_CONST,PRIVATE_KEY_BYTE_LENGTH:64};const SLIP10_SECP256K1_CONST={POINT_COORDINATE_BYTE_LENGTH:32,PRIVATE_KEY_BYTE_LENGTH:32,PRIVATE_KEY_UNCOMPRESSED_PREFIX:0,PRIVATE_KEY_COMPRESSED_PREFIX:1,PUBLIC_KEY_UNCOMPRESSED_PREFIX:integerToBytes(4),PUBLIC_KEY_COMPRESSED_BYTE_LENGTH:33,PUBLIC_KEY_UNCOMPRESSED_BYTE_LENGTH:65,CHECKSUM_BYTE_LENGTH:4};class Info extends NestedNamespace{SOURCE_CODE;WHITEPAPER;WEBSITES;constructor(data){super(data)}}class WitnessVersions extends NestedNamespace{getWitnessVersion(address){return this[address.toUpperCase()]}}class Entropies extends NestedNamespace{isEntropy(entropy){return this.getEntropies().includes(entropy)}getEntropies(){return Object.values(this)}}class Mnemonics extends NestedNamespace{isMnemonic(mnemonic){return this.getMnemonics().includes(mnemonic)}getMnemonics(){return Object.values(this)}}class Seeds extends NestedNamespace{isSeed(seed){return this.getSeeds().includes(seed)}getSeeds(){return Object.values(this)}}class HDs extends NestedNamespace{isHD(hd){return this.getHDS().includes(hd)}getHDS(){return Object.values(this)}}class Addresses extends NestedNamespace{isAddress(address){return this.getAddresses().includes(address)}getAddresses(){return Object.values(this)}length(){return this.getAddresses().length}}class AddressTypes extends NestedNamespace{isAddressType(addressType){return this.getAddressTypes().includes(addressType)}getAddressTypes(){return Object.values(this)}}class AddressPrefixes extends NestedNamespace{isAddressPrefix(addressPrefix){return this.getAddressPrefixes().includes(addressPrefix)}getAddressPrefixes(){return Object.values(this)}}class Networks extends NestedNamespace{isNetwork(network){return this.getNetworks().includes(network.toLowerCase())}getNetworks(){return Object.keys(this).map(k=>k.toLowerCase())}getNetwork(network){if(!this.isNetwork(network)){throw new NetworkError(`${network} network is not available`)}return this[network.toUpperCase()]}}class Params extends NestedNamespace{}class ExtendedKeyVersions extends NestedNamespace{isVersion(version){return Object.values(this).includes(Number(bytesToInteger(version)))}getVersions(){return Object.keys(this).map(k=>k.toLowerCase().replace(/_/g,"-"))}getVersion(name){return this[name.toUpperCase().replace(/-/g,"_")]}getName(version){const intVer=bytesToInteger(version);return Object.entries(this).find(([,v])=>v===intVer)?.[0]}}class XPrivateKeyVersions extends ExtendedKeyVersions{}class XPublicKeyVersions extends ExtendedKeyVersions{}class PUBLIC_KEY_TYPES{static UNCOMPRESSED="uncompressed";static COMPRESSED="compressed";static getTypes(){return[this.UNCOMPRESSED,this.COMPRESSED]}}class WIF_TYPES{static WIF="wif";static WIF_COMPRESSED="wif-compressed";static getTypes(){return[this.WIF,this.WIF_COMPRESSED]}}class SEMANTICS{static P2WPKH="p2wpkh";static P2WPKH_IN_P2SH="p2wpkh-in-p2sh";static P2WSH="p2wsh";static P2WSH_IN_P2SH="p2wsh-in-p2sh";static getTypes(){return[this.P2WPKH,this.P2WPKH_IN_P2SH,this.P2WSH,this.P2WSH_IN_P2SH]}}class MODES{static STANDARD="standard";static SEGWIT="segwit";static getTypes(){return[this.STANDARD,this.SEGWIT]}}var consts=Object.freeze({__proto__:null,NestedNamespace:NestedNamespace,SLIP10_ED25519_CONST:SLIP10_ED25519_CONST,KHOLAW_ED25519_CONST:KHOLAW_ED25519_CONST,SLIP10_SECP256K1_CONST:SLIP10_SECP256K1_CONST,Info:Info,WitnessVersions:WitnessVersions,Entropies:Entropies,Mnemonics:Mnemonics,Seeds:Seeds,HDs:HDs,Addresses:Addresses,AddressTypes:AddressTypes,AddressPrefixes:AddressPrefixes,Networks:Networks,Params:Params,ExtendedKeyVersions:ExtendedKeyVersions,XPrivateKeyVersions:XPrivateKeyVersions,XPublicKeyVersions:XPublicKeyVersions,PUBLIC_KEY_TYPES:PUBLIC_KEY_TYPES,WIF_TYPES:WIF_TYPES,SEMANTICS:SEMANTICS,MODES:MODES});class HMAC extends Hash{constructor(hash,_key){super();this.finished=false;this.destroyed=false;ahash(hash);const key=toBytes(_key);this.iHash=hash.create();if(typeof this.iHash.update!=="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen;this.outputLen=this.iHash.outputLen;const blockLen=this.blockLen;const pad=new Uint8Array(blockLen);pad.set(key.length>blockLen?hash.create().update(key).digest():key);for(let i=0;i<pad.length;i++)pad[i]^=54;this.iHash.update(pad);this.oHash=hash.create();for(let i=0;i<pad.length;i++)pad[i]^=54^92;this.oHash.update(pad);clean(pad)}update(buf){aexists(this);this.iHash.update(buf);return this}digestInto(out){aexists(this);abytes(out,this.outputLen);this.finished=true;this.iHash.digestInto(out);this.oHash.update(out);this.oHash.digestInto(out);this.destroy()}digest(){const out=new Uint8Array(this.oHash.outputLen);this.digestInto(out);return out}_cloneInto(to){to||(to=Object.create(Object.getPrototypeOf(this),{}));const{oHash,iHash,finished,destroyed,blockLen,outputLen}=this;to=to;to.finished=finished;to.destroyed=destroyed;to.blockLen=blockLen;to.outputLen=outputLen;to.oHash=oHash._cloneInto(to.oHash);to.iHash=iHash._cloneInto(to.iHash);return to}clone(){return this._cloneInto()}destroy(){this.destroyed=true;this.oHash.destroy();this.iHash.destroy()}}const hmac=(hash,key,message)=>new HMAC(hash,key).update(message).digest();hmac.create=(hash,key)=>new HMAC(hash,key);var D$1=new Uint32Array(1);var n$1=new Uint32Array([0,1996959894,3993919788,2567524794,124634137,1886057615,3915621685,2657392035,249268274,2044508324,3772115230,2547177864,162941995,2125561021,3887607047,2428444049,498536548,1789927666,4089016648,2227061214,450548861,1843258603,4107580753,2211677639,325883990,1684777152,4251122042,2321926636,335633487,1661365465,4195302755,2366115317,997073096,1281953886,3579855332,2724688242,1006888145,1258607687,3524101629,2768942443,901097722,1119000684,3686517206,2898065728,853044451,1172266101,3705015759,2882616665,651767980,1373503546,3369554304,3218104598,565507253,1454621731,3485111705,3099436303,671266974,1594198024,3322730930,2970347812,795835527,1483230225,3244367275,3060149565,1994146192,31158534,2563907772,4023717930,1907459465,112637215,2680153253,3904427059,2013776290,251722036,2517215374,3775830040,2137656763,141376813,2439277719,3865271297,1802195444,476864866,2238001368,4066508878,1812370925,453092731,2181625025,4111451223,1706088902,314042704,2344532202,4240017532,1658658271,366619977,2362670323,4224994405,1303535960,984961486,2747007092,3569037538,1256170817,1037604311,2765210733,3554079995,1131014506,879679996,2909243462,3663771856,1141124467,855842277,2852801631,3708648649,1342533948,654459306,3188396048,3373015174,1466479909,544179635,3110523913,3462522015,1591671054,702138776,2966460450,3352799412,1504918807,783551873,3082640443,3233442989,3988292384,2596254646,62317068,1957810842,3939845945,2647816111,81470997,1943803523,3814918930,2489596804,225274430,2053790376,3826175755,2466906013,167816743,2097651377,4027552580,2265490386,503444072,1762050814,4150417245,2154129355,426522225,1852507879,4275313526,2312317920,282753626,1742555852,4189708143,2394877945,397917763,1622183637,3604390888,2714866558,953729732,1340076626,3518719985,2797360999,1068828381,1219638859,3624741850,2936675148,906185462,1090812512,3747672003,2825379669,829329135,1181335161,3412177804,3160834842,628085408,1382605366,3423369109,3138078467,570562233,1426400815,3317316542,2998733608,733239954,1555261956,3268935591,3050360625,752459403,1541320221,2607071920,3965973030,1969922972,40735498,2617837225,3943577151,1913087877,83908371,2512341634,3803740692,2075208622,213261112,2463272603,3855990285,2094854071,198958881,2262029012,4057260610,1759359992,534414190,2176718541,4139329115,1873836001,414664567,2282248934,4279200368,1711684554,285281116,2405801727,4167216745,1634467795,376229701,2685067896,3608007406,1308918612,956543938,2808555105,3495958263,1231636301,1047427035,2932959818,3654703836,1088359270,936918e3,2847714899,3736837829,1202900863,817233897,3183342108,3401237130,1404277552,615818150,3134207493,3453421203,1423857449,601450431,3009837614,3294710456,1567103746,711928724,3020668471,3272380065,1510334235,755167117]);function t$2(x=new Uint8Array,B=0){D$1[0]=B^4294967295;for(let A of x)D$1[0]=n$1[(D$1[0]^A)&255]^D$1[0]>>>8;return(D$1[0]^4294967295)>>>0}var B$1=new Uint16Array(1);var n=new Uint16Array([0,4129,8258,12387,16516,20645,24774,28903,33032,37161,41290,45419,49548,53677,57806,61935,4657,528,12915,8786,21173,17044,29431,25302,37689,33560,45947,41818,54205,50076,62463,58334,9314,13379,1056,5121,25830,29895,17572,21637,42346,46411,34088,38153,58862,62927,50604,54669,13907,9842,5649,1584,30423,26358,22165,18100,46939,42874,38681,34616,63455,59390,55197,51132,18628,22757,26758,30887,2112,6241,10242,14371,51660,55789,59790,63919,35144,39273,43274,47403,23285,19156,31415,27286,6769,2640,14899,10770,56317,52188,64447,60318,39801,35672,47931,43802,27814,31879,19684,23749,11298,15363,3168,7233,60846,64911,52716,56781,44330,48395,36200,40265,32407,28342,24277,20212,15891,11826,7761,3696,65439,61374,57309,53244,48923,44858,40793,36728,37256,33193,45514,41451,53516,49453,61774,57711,4224,161,12482,8419,20484,16421,28742,24679,33721,37784,41979,46042,49981,54044,58239,62302,689,4752,8947,13010,16949,21012,25207,29270,46570,42443,38312,34185,62830,58703,54572,50445,13538,9411,5280,1153,29798,25671,21540,17413,42971,47098,34713,38840,59231,63358,50973,55100,9939,14066,1681,5808,26199,30326,17941,22068,55628,51565,63758,59695,39368,35305,47498,43435,22596,18533,30726,26663,6336,2273,14466,10403,52093,56156,60223,64286,35833,39896,43963,48026,19061,23124,27191,31254,2801,6864,10931,14994,64814,60687,56684,52557,48554,44427,40424,36297,31782,27655,23652,19525,15522,11395,7392,3265,61215,65342,53085,57212,44955,49082,36825,40952,28183,32310,20053,24180,11923,16050,3793,7920]);function t$1(x=new Uint8Array,A=0){B$1[0]=A;for(let C of x)B$1[0]=n[B$1[0]>>>8^C]^B$1[0]<<8;return B$1[0]}function setBigUint64(view,byteOffset,value,isLE){if(typeof view.setBigUint64==="function")return view.setBigUint64(byteOffset,value,isLE);const _32n=BigInt(32);const _u32_max=BigInt(4294967295);const wh=Number(value>>_32n&_u32_max);const wl=Number(value&_u32_max);const h=isLE?4:0;const l=isLE?0:4;view.setUint32(byteOffset+h,wh,isLE);view.setUint32(byteOffset+l,wl,isLE)}function Chi(a,b,c){return a&b^~a&c}function Maj(a,b,c){return a&b^a&c^b&c}class HashMD extends Hash{constructor(blockLen,outputLen,padOffset,isLE){super();this.finished=false;this.length=0;this.pos=0;this.destroyed=false;this.blockLen=blockLen;this.outputLen=outputLen;this.padOffset=padOffset;this.isLE=isLE;this.buffer=new Uint8Array(blockLen);this.view=createView(this.buffer)}update(data){aexists(this);data=toBytes(data);abytes(data);const{view,buffer,blockLen}=this;const len=data.length;for(let pos=0;pos<len;){const take=Math.min(blockLen-this.pos,len-pos);if(take===blockLen){const dataView=createView(data);for(;blockLen<=len-pos;pos+=blockLen)this.process(dataView,pos);continue}buffer.set(data.subarray(pos,pos+take),this.pos);this.pos+=take;pos+=take;if(this.pos===blockLen){this.process(view,0);this.pos=0}}this.length+=data.length;this.roundClean();return this}digestInto(out){aexists(this);aoutput(out,this);this.finished=true;const{buffer,view,blockLen,isLE}=this;let{pos}=this;buffer[pos++]=128;clean(this.buffer.subarray(pos));if(this.padOffset>blockLen-pos){this.process(view,0);pos=0}for(let i=pos;i<blockLen;i++)buffer[i]=0;setBigUint64(view,blockLen-8,BigInt(this.length*8),isLE);this.process(view,0);const oview=createView(out);const len=this.outputLen;if(len%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const outLen=len/4;const state=this.get();if(outLen>state.length)throw new Error("_sha2: outputLen bigger than state");for(let i=0;i<outLen;i++)oview.setUint32(4*i,state[i],isLE)}digest(){const{buffer,outputLen}=this;this.digestInto(buffer);const res=buffer.slice(0,outputLen);this.destroy();return res}_cloneInto(to){to||(to=new this.constructor);to.set(...this.get());const{blockLen,buffer,length,finished,destroyed,pos}=this;to.destroyed=destroyed;to.finished=finished;to.length=length;to.pos=pos;if(length%blockLen)to.buffer.set(buffer);return to}clone(){return this._cloneInto()}}const SHA256_IV=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);const SHA384_IV=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]);const SHA512_IV=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);const U32_MASK64=BigInt(2**32-1);const _32n=BigInt(32);function fromBig(n,le=false){if(le)return{h:Number(n&U32_MASK64),l:Number(n>>_32n&U32_MASK64)};return{h:Number(n>>_32n&U32_MASK64)|0,l:Number(n&U32_MASK64)|0}}function split(lst,le=false){const len=lst.length;let Ah=new Uint32Array(len);let Al=new Uint32Array(len);for(let i=0;i<len;i++){const{h,l}=fromBig(lst[i],le);[Ah[i],Al[i]]=[h,l]}return[Ah,Al]}const shrSH=(h,_l,s)=>h>>>s;const shrSL=(h,l,s)=>h<<32-s|l>>>s;const rotrSH=(h,l,s)=>h>>>s|l<<32-s;const rotrSL=(h,l,s)=>h<<32-s|l>>>s;const rotrBH=(h,l,s)=>h<<64-s|l>>>s-32;const rotrBL=(h,l,s)=>h>>>s-32|l<<64-s;const rotr32H=(_h,l)=>l;const rotr32L=(h,_l)=>h;const rotlSH=(h,l,s)=>h<<s|l>>>32-s;const rotlSL=(h,l,s)=>l<<s|h>>>32-s;const rotlBH=(h,l,s)=>l<<s-32|h>>>64-s;const rotlBL=(h,l,s)=>h<<s-32|l>>>64-s;function add(Ah,Al,Bh,Bl){const l=(Al>>>0)+(Bl>>>0);return{h:Ah+Bh+(l/2**32|0)|0,l:l|0}}const add3L=(Al,Bl,Cl)=>(Al>>>0)+(Bl>>>0)+(Cl>>>0);const add3H=(low,Ah,Bh,Ch)=>Ah+Bh+Ch+(low/2**32|0)|0;const add4L=(Al,Bl,Cl,Dl)=>(Al>>>0)+(Bl>>>0)+(Cl>>>0)+(Dl>>>0);const add4H=(low,Ah,Bh,Ch,Dh)=>Ah+Bh+Ch+Dh+(low/2**32|0)|0;const add5L=(Al,Bl,Cl,Dl,El)=>(Al>>>0)+(Bl>>>0)+(Cl>>>0)+(Dl>>>0)+(El>>>0);const add5H=(low,Ah,Bh,Ch,Dh,Eh)=>Ah+Bh+Ch+Dh+Eh+(low/2**32|0)|0;const SHA256_K=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]);const SHA256_W=new Uint32Array(64);class SHA256 extends HashMD{constructor(outputLen=32){super(64,outputLen,8,false);this.A=SHA256_IV[0]|0;this.B=SHA256_IV[1]|0;this.C=SHA256_IV[2]|0;this.D=SHA256_IV[3]|0;this.E=SHA256_IV[4]|0;this.F=SHA256_IV[5]|0;this.G=SHA256_IV[6]|0;this.H=SHA256_IV[7]|0}get(){const{A,B,C,D,E,F,G,H}=this;return[A,B,C,D,E,F,G,H]}set(A,B,C,D,E,F,G,H){this.A=A|0;this.B=B|0;this.C=C|0;this.D=D|0;this.E=E|0;this.F=F|0;this.G=G|0;this.H=H|0}process(view,offset){for(let i=0;i<16;i++,offset+=4)SHA256_W[i]=view.getUint32(offset,false);for(let i=16;i<64;i++){const W15=SHA256_W[i-15];const W2=SHA256_W[i-2];const s0=rotr(W15,7)^rotr(W15,18)^W15>>>3;const s1=rotr(W2,17)^rotr(W2,19)^W2>>>10;SHA256_W[i]=s1+SHA256_W[i-7]+s0+SHA256_W[i-16]|0}let{A,B,C,D,E,F,G,H}=this;for(let i=0;i<64;i++){const sigma1=rotr(E,6)^rotr(E,11)^rotr(E,25);const T1=H+sigma1+Chi(E,F,G)+SHA256_K[i]+SHA256_W[i]|0;const sigma0=rotr(A,2)^rotr(A,13)^rotr(A,22);const T2=sigma0+Maj(A,B,C)|0;H=G;G=F;F=E;E=D+T1|0;D=C;C=B;B=A;A=T1+T2|0}A=A+this.A|0;B=B+this.B|0;C=C+this.C|0;D=D+this.D|0;E=E+this.E|0;F=F+this.F|0;G=G+this.G|0;H=H+this.H|0;this.set(A,B,C,D,E,F,G,H)}roundClean(){clean(SHA256_W)}destroy(){this.set(0,0,0,0,0,0,0,0);clean(this.buffer)}}const K512=(()=>split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(n=>BigInt(n))))();const SHA512_Kh=(()=>K512[0])();const SHA512_Kl=(()=>K512[1])();const SHA512_W_H=new Uint32Array(80);const SHA512_W_L=new Uint32Array(80);class SHA512 extends HashMD{constructor(outputLen=64){super(128,outputLen,16,false);this.Ah=SHA512_IV[0]|0;this.Al=SHA512_IV[1]|0;this.Bh=SHA512_IV[2]|0;this.Bl=SHA512_IV[3]|0;this.Ch=SHA512_IV[4]|0;this.Cl=SHA512_IV[5]|0;this.Dh=SHA512_IV[6]|0;this.Dl=SHA512_IV[7]|0;this.Eh=SHA512_IV[8]|0;this.El=SHA512_IV[9]|0;this.Fh=SHA512_IV[10]|0;this.Fl=SHA512_IV[11]|0;this.Gh=SHA512_IV[12]|0;this.Gl=SHA512_IV[13]|0;this.Hh=SHA512_IV[14]|0;this.Hl=SHA512_IV[15]|0}get(){const{Ah,Al,Bh,Bl,Ch,Cl,Dh,Dl,Eh,El,Fh,Fl,Gh,Gl,Hh,Hl}=this;return[Ah,Al,Bh,Bl,Ch,Cl,Dh,Dl,Eh,El,Fh,Fl,Gh,Gl,Hh,Hl]}set(Ah,Al,Bh,Bl,Ch,Cl,Dh,Dl,Eh,El,Fh,Fl,Gh,Gl,Hh,Hl){this.Ah=Ah|0;this.Al=Al|0;this.Bh=Bh|0;this.Bl=Bl|0;this.Ch=Ch|0;this.Cl=Cl|0;this.Dh=Dh|0;this.Dl=Dl|0;this.Eh=Eh|0;this.El=El|0;this.Fh=Fh|0;this.Fl=Fl|0;this.Gh=Gh|0;this.Gl=Gl|0;this.Hh=Hh|0;this.Hl=Hl|0}process(view,offset){for(let i=0;i<16;i++,offset+=4){SHA512_W_H[i]=view.getUint32(offset);SHA512_W_L[i]=view.getUint32(offset+=4)}for(let i=16;i<80;i++){const W15h=SHA512_W_H[i-15]|0;const W15l=SHA512_W_L[i-15]|0;const s0h=rotrSH(W15h,W15l,1)^rotrSH(W15h,W15l,8)^shrSH(W15h,W15l,7);const s0l=rotrSL(W15h,W15l,1)^rotrSL(W15h,W15l,8)^shrSL(W15h,W15l,7);const W2h=SHA512_W_H[i-2]|0;const W2l=SHA512_W_L[i-2]|0;const s1h=rotrSH(W2h,W2l,19)^rotrBH(W2h,W2l,61)^shrSH(W2h,W2l,6);const s1l=rotrSL(W2h,W2l,19)^rotrBL(W2h,W2l,61)^shrSL(W2h,W2l,6);const SUMl=add4L(s0l,s1l,SHA512_W_L[i-7],SHA512_W_L[i-16]);const SUMh=add4H(SUMl,s0h,s1h,SHA512_W_H[i-7],SHA512_W_H[i-16]);SHA512_W_H[i]=SUMh|0;SHA512_W_L[i]=SUMl|0}let{Ah,Al,Bh,Bl,Ch,Cl,Dh,Dl,Eh,El,Fh,Fl,Gh,Gl,Hh,Hl}=this;for(let i=0;i<80;i++){const sigma1h=rotrSH(Eh,El,14)^rotrSH(Eh,El,18)^rotrBH(Eh,El,41);const sigma1l=rotrSL(Eh,El,14)^rotrSL(Eh,El,18)^rotrBL(Eh,El,41);const CHIh=Eh&Fh^~Eh&Gh;const CHIl=El&Fl^~El&Gl;const T1ll=add5L(Hl,sigma1l,CHIl,SHA512_Kl[i],SHA512_W_L[i]);const T1h=add5H(T1ll,Hh,sigma1h,CHIh,SHA512_Kh[i],SHA512_W_H[i]);const T1l=T1ll|0;const sigma0h=rotrSH(Ah,Al,28)^rotrBH(Ah,Al,34)^rotrBH(Ah,Al,39);const sigma0l=rotrSL(Ah,Al,28)^rotrBL(Ah,Al,34)^rotrBL(Ah,Al,39);const MAJh=Ah&Bh^Ah&Ch^Bh&Ch;const MAJl=Al&Bl^Al&Cl^Bl&Cl;Hh=Gh|0;Hl=Gl|0;Gh=Fh|0;Gl=Fl|0;Fh=Eh|0;Fl=El|0;({h:Eh,l:El}=add(Dh|0,Dl|0,T1h|0,T1l|0));Dh=Ch|0;Dl=Cl|0;Ch=Bh|0;Cl=Bl|0;Bh=Ah|0;Bl=Al|0;const All=add3L(T1l,sigma0l,MAJl);Ah=add3H(All,T1h,sigma0h,MAJh);Al=All|0}({h:Ah,l:Al}=add(this.Ah|0,this.Al|0,Ah|0,Al|0));({h:Bh,l:Bl}=add(this.Bh|0,this.Bl|0,Bh|0,Bl|0));({h:Ch,l:Cl}=add(this.Ch|0,this.Cl|0,Ch|0,Cl|0));({h:Dh,l:Dl}=add(this.Dh|0,this.Dl|0,Dh|0,Dl|0));({h:Eh,l:El}=add(this.Eh|0,this.El|0,Eh|0,El|0));({h:Fh,l:Fl}=add(this.Fh|0,this.Fl|0,Fh|0,Fl|0));({h:Gh,l:Gl}=add(this.Gh|0,this.Gl|0,Gh|0,Gl|0));({h:Hh,l:Hl}=add(this.Hh|0,this.Hl|0,Hh|0,Hl|0));this.set(Ah,Al,Bh,Bl,Ch,Cl,Dh,Dl,Eh,El,Fh,Fl,Gh,Gl,Hh,Hl)}roundClean(){clean(SHA512_W_H,SHA512_W_L)}destroy(){clean(this.buffer);this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}class SHA384 extends SHA512{constructor(){super(48);this.Ah=SHA384_IV[0]|0;this.Al=SHA384_IV[1]|0;this.Bh=SHA384_IV[2]|0;this.Bl=SHA384_IV[3]|0;this.Ch=SHA384_IV[4]|0;this.Cl=SHA384_IV[5]|0;this.Dh=SHA384_IV[6]|0;this.Dl=SHA384_IV[7]|0;this.Eh=SHA384_IV[8]|0;this.El=SHA384_IV[9]|0;this.Fh=SHA384_IV[10]|0;this.Fl=SHA384_IV[11]|0;this.Gh=SHA384_IV[12]|0;this.Gl=SHA384_IV[13]|0;this.Hh=SHA384_IV[14]|0;this.Hl=SHA384_IV[15]|0}}const T256_IV=Uint32Array.from([573645204,4230739756,2673172387,3360449730,596883563,1867755857,2520282905,1497426621,2519219938,2827943907,3193839141,1401305490,721525244,746961066,246885852,2177182882]);class SHA512_256 extends SHA512{constructor(){super(32);this.Ah=T256_IV[0]|0;this.Al=T256_IV[1]|0;this.Bh=T256_IV[2]|0;this.Bl=T256_IV[3]|0;this.Ch=T256_IV[4]|0;this.Cl=T256_IV[5]|0;this.Dh=T256_IV[6]|0;this.Dl=T256_IV[7]|0;this.Eh=T256_IV[8]|0;this.El=T256_IV[9]|0;this.Fh=T256_IV[10]|0;this.Fl=T256_IV[11]|0;this.Gh=T256_IV[12]|0;this.Gl=T256_IV[13]|0;this.Hh=T256_IV[14]|0;this.Hl=T256_IV[15]|0}}const sha256$1=createHasher(()=>new SHA256);const sha512$1=createHasher(()=>new SHA512);const sha384=createHasher(()=>new SHA384);const sha512_256$1=createHasher(()=>new SHA512_256);const _0n$5=BigInt(0);const _1n$7=BigInt(1);const _2n$5=BigInt(2);const _7n=BigInt(7);const _256n=BigInt(256);const _0x71n=BigInt(113);const SHA3_PI=[];const SHA3_ROTL=[];const _SHA3_IOTA=[];for(let round=0,R=_1n$7,x=1,y=0;round<24;round++){[x,y]=[y,(2*x+3*y)%5];SHA3_PI.push(2*(5*y+x));SHA3_ROTL.push((round+1)*(round+2)/2%64);let t=_0n$5;for(let j=0;j<7;j++){R=(R<<_1n$7^(R>>_7n)*_0x71n)%_256n;if(R&_2n$5)t^=_1n$7<<(_1n$7<<BigInt(j))-_1n$7}_SHA3_IOTA.push(t)}const IOTAS=split(_SHA3_IOTA,true);const SHA3_IOTA_H=IOTAS[0];const SHA3_IOTA_L=IOTAS[1];const rotlH=(h,l,s)=>s>32?rotlBH(h,l,s):rotlSH(h,l,s);const rotlL=(h,l,s)=>s>32?rotlBL(h,l,s):rotlSL(h,l,s);function keccakP(s,rounds=24){const B=new Uint32Array(5*2);for(let round=24-rounds;round<24;round++){for(let x=0;x<10;x++)B[x]=s[x]^s[x+10]^s[x+20]^s[x+30]^s[x+40];for(let x=0;x<10;x+=2){const idx1=(x+8)%10;const idx0=(x+2)%10;const B0=B[idx0];const B1=B[idx0+1];const Th=rotlH(B0,B1,1)^B[idx1];const Tl=rotlL(B0,B1,1)^B[idx1+1];for(let y=0;y<50;y+=10){s[x+y]^=Th;s[x+y+1]^=Tl}}let curH=s[2];let curL=s[3];for(let t=0;t<24;t++){const shift=SHA3_ROTL[t];const Th=rotlH(curH,curL,shift);const Tl=rotlL(curH,curL,shift);const PI=SHA3_PI[t];curH=s[PI];curL=s[PI+1];s[PI]=Th;s[PI+1]=Tl}for(let y=0;y<50;y+=10){for(let x=0;x<10;x++)B[x]=s[y+x];for(let x=0;x<10;x++)s[y+x]^=~B[(x+2)%10]&B[(x+4)%10]}s[0]^=SHA3_IOTA_H[round];s[1]^=SHA3_IOTA_L[round]}clean(B)}class Keccak extends Hash{constructor(blockLen,suffix,outputLen,enableXOF=false,rounds=24){super();this.pos=0;this.posOut=0;this.finished=false;this.destroyed=false;this.enableXOF=false;this.blockLen=blockLen;this.suffix=suffix;this.outputLen=outputLen;this.enableXOF=enableXOF;this.rounds=rounds;anumber(outputLen);if(!(0<blockLen&&blockLen<200))throw new Error("only keccak-f1600 function is supported");this.state=new Uint8Array(200);this.state32=u32(this.state)}clone(){return this._cloneInto()}keccak(){swap32IfBE(this.state32);keccakP(this.state32,this.rounds);swap32IfBE(this.state32);this.posOut=0;this.pos=0}update(data){aexists(this);data=toBytes(data);abytes(data);const{blockLen,state}=this;const len=data.length;for(let pos=0;pos<len;){const take=Math.min(blockLen-this.pos,len-pos);for(let i=0;i<take;i++)state[this.pos++]^=data[pos++];if(this.pos===blockLen)this.keccak()}return this}finish(){if(this.finished)return;this.finished=true;const{state,suffix,pos,blockLen}=this;state[pos]^=suffix;if((suffix&128)!==0&&pos===blockLen-1)this.keccak();state[blockLen-1]^=128;this.keccak()}writeInto(out){aexists(this,false);abytes(out);this.finish();const bufferOut=this.state;const{blockLen}=this;for(let pos=0,len=out.length;pos<len;){if(this.posOut>=blockLen)this.keccak();const take=Math.min(blockLen-this.posOut,len-pos);out.set(bufferOut.subarray(this.posOut,this.posOut+take),pos);this.posOut+=take;pos+=take}return out}xofInto(out){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(out)}xof(bytes){anumber(bytes);return this.xofInto(new Uint8Array(bytes))}digestInto(out){aoutput(out,this);if(this.finished)throw new Error("digest() was already called");this.writeInto(out);this.destroy();return out}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=true;clean(this.state)}_cloneInto(to){const{blockLen,suffix,outputLen,rounds,enableXOF}=this;to||(to=new Keccak(blockLen,suffix,outputLen,enableXOF,rounds));to.state32.set(this.state32);to.pos=this.pos;to.posOut=this.posOut;to.finished=this.finished;to.rounds=rounds;to.suffix=suffix;to.outputLen=outputLen;to.enableXOF=enableXOF;to.destroyed=this.destroyed;return to}}const gen=(suffix,blockLen,outputLen)=>createHasher(()=>new Keccak(blockLen,suffix,outputLen));const sha3_256$1=(()=>gen(6,136,256/8))();const keccak_256=(()=>gen(1,136,256/8))();const BSIGMA=Uint8Array.from([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9]);const B2B_IV=Uint32Array.from([4089235720,1779033703,2227873595,3144134277,4271175723,1013904242,1595750129,2773480762,2917565137,1359893119,725511199,2600822924,4215389547,528734635,327033209,1541459225]);const BBUF=new Uint32Array(32);function G1b(a,b,c,d,msg,x){const Xl=msg[x],Xh=msg[x+1];let Al=BBUF[2*a],Ah=BBUF[2*a+1];let Bl=BBUF[2*b],Bh=BBUF[2*b+1];let Cl=BBUF[2*c],Ch=BBUF[2*c+1];let Dl=BBUF[2*d],Dh=BBUF[2*d+1];let ll=add3L(Al,Bl,Xl);Ah=add3H(ll,Ah,Bh,Xh);Al=ll|0;({Dh,Dl}={Dh:Dh^Ah,Dl:Dl^Al});({Dh,Dl}={Dh:rotr32H(Dh,Dl),Dl:rotr32L(Dh)});({h:Ch,l:Cl}=add(Ch,Cl,Dh,Dl));({Bh,Bl}={Bh:Bh^Ch,Bl:Bl^Cl});({Bh,Bl}={Bh:rotrSH(Bh,Bl,24),Bl:rotrSL(Bh,Bl,24)});BBUF[2*a]=Al,BBUF[2*a+1]=Ah;BBUF[2*b]=Bl,BBUF[2*b+1]=Bh;BBUF[2*c]=Cl,BBUF[2*c+1]=Ch;BBUF[2*d]=Dl,BBUF[2*d+1]=Dh}function G2b(a,b,c,d,msg,x){const Xl=msg[x],Xh=msg[x+1];let Al=BBUF[2*a],Ah=BBUF[2*a+1];let Bl=BBUF[2*b],Bh=BBUF[2*b+1];let Cl=BBUF[2*c],Ch=BBUF[2*c+1];let Dl=BBUF[2*d],Dh=BBUF[2*d+1];let ll=add3L(Al,Bl,Xl);Ah=add3H(ll,Ah,Bh,Xh);Al=ll|0;({Dh,Dl}={Dh:Dh^Ah,Dl:Dl^Al});({Dh,Dl}={Dh:rotrSH(Dh,Dl,16),Dl:rotrSL(Dh,Dl,16)});({h:Ch,l:Cl}=add(Ch,Cl,Dh,Dl));({Bh,Bl}={Bh:Bh^Ch,Bl:Bl^Cl});({Bh,Bl}={Bh:rotrBH(Bh,Bl,63),Bl:rotrBL(Bh,Bl,63)});BBUF[2*a]=Al,BBUF[2*a+1]=Ah;BBUF[2*b]=Bl,BBUF[2*b+1]=Bh;BBUF[2*c]=Cl,BBUF[2*c+1]=Ch;BBUF[2*d]=Dl,BBUF[2*d+1]=Dh}function checkBlake2Opts(outputLen,opts={},keyLen,saltLen,persLen){anumber(keyLen);if(outputLen<0||outputLen>keyLen)throw new Error("outputLen bigger than keyLen");const{key,salt,personalization}=opts;if(key!==undefined&&(key.length<1||key.length>keyLen))throw new Error("key length must be undefined or 1.."+keyLen);if(salt!==undefined&&salt.length!==saltLen)throw new Error("salt must be undefined or "+saltLen);if(personalization