@ckb-ccc/core 1.18.1 → 2.0.0-next.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/CHANGELOG.md +42 -0
- package/dist/address.advanced-LxntWbev.mjs +2 -0
- package/dist/address.advanced-LxntWbev.mjs.map +1 -0
- package/dist/advanced.d.mts +1 -1
- package/dist/advanced.mjs +1 -1
- package/{dist.commonjs/advancedBarrel-CJAh6sm8.d.ts → dist/advancedBarrel-BHwnMJqR.d.mts} +749 -382
- package/dist/advancedBarrel-BHwnMJqR.d.mts.map +1 -0
- package/dist/advancedBarrel.d.mts +1 -1
- package/dist/advancedBarrel.mjs +1 -1
- package/dist/barrel-C-BaV9Pe.mjs +7 -0
- package/dist/barrel-C-BaV9Pe.mjs.map +1 -0
- package/dist/barrel.d.mts +2 -2
- package/dist/barrel.mjs +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +1 -1
- package/dist.commonjs/address.advanced-BqcYOpZn.js +2 -0
- package/dist.commonjs/address.advanced-BqcYOpZn.js.map +1 -0
- package/dist.commonjs/advanced.d.ts +1 -1
- package/dist.commonjs/advanced.js +1 -1
- package/{dist/advancedBarrel-BbbHx4z4.d.mts → dist.commonjs/advancedBarrel-DNdhwiU0.d.ts} +750 -381
- package/dist.commonjs/advancedBarrel-DNdhwiU0.d.ts.map +1 -0
- package/dist.commonjs/advancedBarrel.d.ts +1 -1
- package/dist.commonjs/advancedBarrel.js +1 -1
- package/dist.commonjs/{barrel-C_zSgXKn.js → barrel-BBOmj4RJ.js} +10 -10
- package/dist.commonjs/barrel-BBOmj4RJ.js.map +1 -0
- package/dist.commonjs/barrel.d.ts +2 -2
- package/dist.commonjs/barrel.js +1 -1
- package/dist.commonjs/index.d.ts +2 -2
- package/dist.commonjs/index.js +1 -1
- package/package.json +1 -1
- package/src/ckb/epoch.ts +44 -26
- package/src/ckb/script.ts +23 -46
- package/src/ckb/transaction.ts +200 -196
- package/src/client/client.ts +2 -2
- package/src/client/jsonRpc/client.ts +3 -7
- package/src/codec/codec.ts +65 -40
- package/src/codec/entity.ts +95 -67
- package/src/codec/predefined.ts +11 -0
- package/src/molecule/codec.ts +116 -8
- package/src/molecule/predefined.ts +1 -0
- package/src/signer/ckb/signerMultisigCkbReadonly.ts +36 -24
- package/src/signer/ckb/verifyJoyId.ts +39 -11
- package/src/signer/index.ts +17 -0
- package/src/signer/signer/index.ts +11 -0
- package/src/signer/signerFromSignature.ts +65 -0
- package/src/utils/index.ts +108 -26
- package/dist/address.advanced-Dw4qPDGb.mjs +0 -2
- package/dist/address.advanced-Dw4qPDGb.mjs.map +0 -1
- package/dist/advancedBarrel-BbbHx4z4.d.mts.map +0 -1
- package/dist/barrel-BsC1djHG.mjs +0 -7
- package/dist/barrel-BsC1djHG.mjs.map +0 -1
- package/dist.commonjs/address.advanced-DG1gpW7t.js +0 -2
- package/dist.commonjs/address.advanced-DG1gpW7t.js.map +0 -1
- package/dist.commonjs/advancedBarrel-CJAh6sm8.d.ts.map +0 -1
- package/dist.commonjs/barrel-C_zSgXKn.js.map +0 -1
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
const e=require("./rolldown-runtime-DWNI8pZO.js"),t=require("./address.advanced-DG1gpW7t.js");let n=require("bech32"),r=require("isomorphic-ws");r=e.n(r);let i=require("@joyid/ckb"),a=require("ethers");function o(e,t,n){return e&t^~e&n}function s(e,t,n){return e&t^e&n^t&n}var c=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,n,r,i){this.blockLen=e,this.outputLen=n,this.padOffset=r,this.isLE=i,this.buffer=new Uint8Array(e),this.view=t.Ir(this.buffer)}update(e){t.Er(this),t.Tr(e);let{view:n,buffer:r,blockLen:i}=this,a=e.length;for(let o=0;o<a;){let s=Math.min(i-this.pos,a-o);if(s===i){let n=t.Ir(e);for(;i<=a-o;o+=i)this.process(n,o);continue}r.set(e.subarray(o,o+s),this.pos),this.pos+=s,o+=s,this.pos===i&&(this.process(n,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){t.Er(this),t.kr(e,this),this.finished=!0;let{buffer:n,view:r,blockLen:i,isLE:a}=this,{pos:o}=this;n[o++]=128,t.Nr(this.buffer.subarray(o)),this.padOffset>i-o&&(this.process(r,0),o=0);for(let e=o;e<i;e++)n[e]=0;r.setBigUint64(i-8,BigInt(this.length*8),a),this.process(r,0);let s=t.Ir(e),c=this.outputLen;if(c%4)throw Error(`_sha2: outputLen must be aligned to 32bit`);let l=c/4,u=this.get();if(l>u.length)throw Error(`_sha2: outputLen bigger than state`);for(let e=0;e<l;e++)s.setUint32(4*e,u[e],a)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:t,buffer:n,length:r,finished:i,destroyed:a,pos:o}=this;return e.destroyed=a,e.finished=i,e.length=r,e.pos=o,r%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}};const l=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),u=BigInt(0),d=BigInt(1),f=BigInt(2),p=BigInt(7),m=BigInt(256),h=BigInt(113),g=[],_=[],v=[];for(let e=0,t=d,n=1,r=0;e<24;e++){[n,r]=[r,(2*n+3*r)%5],g.push(2*(5*r+n)),_.push((e+1)*(e+2)/2%64);let i=u;for(let e=0;e<7;e++)t=(t<<d^(t>>p)*h)%m,t&f&&(i^=d<<(d<<BigInt(e))-d);v.push(i)}const y=t.wr(v,!0),ee=y[0],b=y[1],x=(e,n,r)=>r>32?t.br(e,n,r):t.Sr(e,n,r),S=(e,n,r)=>r>32?t.xr(e,n,r):t.Cr(e,n,r);function C(e,n=24){if(t.Or(n,`rounds`),n<1||n>24)throw Error(`"rounds" expected integer 1..24`);let r=new Uint32Array(10);for(let t=24-n;t<24;t++){for(let t=0;t<10;t++)r[t]=e[t]^e[t+10]^e[t+20]^e[t+30]^e[t+40];for(let t=0;t<10;t+=2){let n=(t+8)%10,i=(t+2)%10,a=r[i],o=r[i+1],s=x(a,o,1)^r[n],c=S(a,o,1)^r[n+1];for(let n=0;n<50;n+=10)e[t+n]^=s,e[t+n+1]^=c}let n=e[2],i=e[3];for(let t=0;t<24;t++){let r=_[t],a=x(n,i,r),o=S(n,i,r),s=g[t];n=e[s],i=e[s+1],e[s]=a,e[s+1]=o}for(let t=0;t<50;t+=10){let n=e[t],r=e[t+1],i=e[t+2],a=e[t+3];e[t]^=~e[t+2]&e[t+4],e[t+1]^=~e[t+3]&e[t+5],e[t+2]^=~e[t+4]&e[t+6],e[t+3]^=~e[t+5]&e[t+7],e[t+4]^=~e[t+6]&e[t+8],e[t+5]^=~e[t+7]&e[t+9],e[t+6]^=~e[t+8]&n,e[t+7]^=~e[t+9]&r,e[t+8]^=~n&i,e[t+9]^=~r&a}e[0]^=ee[t],e[1]^=b[t]}t.Nr(r)}var w=class e{state;pos=0;posOut=0;finished=!1;state32;destroyed=!1;blockLen;suffix;outputLen;canXOF;enableXOF=!1;rounds;constructor(e,n,r,i=!1,a=24){if(this.blockLen=e,this.suffix=n,this.outputLen=r,this.enableXOF=i,this.canXOF=i,this.rounds=a,t.Or(r,`outputLen`),!(0<e&&e<200))throw Error(`only keccak-f1600 function is supported`);this.state=new Uint8Array(200),this.state32=t.Gr(this.state)}clone(){return this._cloneInto()}keccak(){t.Wr(this.state32),C(this.state32,this.rounds),t.Wr(this.state32),this.posOut=0,this.pos=0}update(e){t.Er(this),t.Tr(e);let{blockLen:n,state:r}=this,i=e.length;for(let t=0;t<i;){let a=Math.min(n-this.pos,i-t);for(let n=0;n<a;n++)r[this.pos++]^=e[t++];this.pos===n&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;let{state:e,suffix:t,pos:n,blockLen:r}=this;e[n]^=t,t&128&&n===r-1&&this.keccak(),e[r-1]^=128,this.keccak()}writeInto(e){t.Er(this,!1),t.Tr(e),this.finish();let n=this.state,{blockLen:r}=this;for(let t=0,i=e.length;t<i;){this.posOut>=r&&this.keccak();let a=Math.min(r-this.posOut,i-t);e.set(n.subarray(this.posOut,this.posOut+a),t),this.posOut+=a,t+=a}return e}xofInto(e){if(!this.enableXOF)throw Error(`XOF is not possible for this instance`);return this.writeInto(e)}xof(e){return t.Or(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(t.kr(e,this),this.finished)throw Error(`digest() was already called`);this.writeInto(e.subarray(0,this.outputLen)),this.destroy()}digest(){let e=new Uint8Array(this.outputLen);return this.digestInto(e),e}destroy(){this.destroyed=!0,t.Nr(this.state)}_cloneInto(t){let{blockLen:n,suffix:r,outputLen:i,rounds:a,enableXOF:o}=this;return t||=new e(n,r,i,o,a),t.blockLen=n,t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=a,t.suffix=r,t.outputLen=i,t.enableXOF=o,t.canXOF=this.canXOF,t.destroyed=this.destroyed,t}};const T=((e,n,r,i={})=>t.Fr(()=>new w(n,e,r),i))(1,136,32);var E=class{constructor(){this.hasher=T.create()}update(e){return this.hasher.update(t.Zr(e)),this}digest(){return t.yr(this.hasher.digest())}},D=e.t({Bool:()=>t.yn,BoolOpt:()=>t.Mt,BoolVec:()=>t.Nt,Byte:()=>t.bn,Byte16:()=>t.xn,Byte16Opt:()=>t.Pt,Byte16Vec:()=>t.Ft,Byte32:()=>t.Sn,Byte32Opt:()=>t.It,Byte32Vec:()=>t.Lt,Byte4:()=>t.Cn,Byte4Opt:()=>t.Rt,Byte4Vec:()=>t.zt,Byte8:()=>t.wn,Byte8Opt:()=>t.Bt,Byte8Vec:()=>t.Vt,ByteOpt:()=>t.Ht,ByteVec:()=>t.Ut,Bytes:()=>t.Wt,BytesOpt:()=>t.Gt,BytesVec:()=>t.Kt,Codec:()=>t.Kr,Entity:()=>t.lr,String:()=>t.qt,StringOpt:()=>t.Jt,StringVec:()=>t.Yt,Uint128:()=>t.Dn,Uint128BE:()=>t.On,Uint128LE:()=>t.kn,Uint128Opt:()=>t.Xt,Uint128Vec:()=>t.Zt,Uint16:()=>t.An,Uint16BE:()=>t.jn,Uint16LE:()=>t.Mn,Uint16Opt:()=>t.Qt,Uint16Vec:()=>t.$t,Uint256:()=>t.Nn,Uint256BE:()=>t.Pn,Uint256LE:()=>t.Fn,Uint256Opt:()=>t.en,Uint256Vec:()=>t.tn,Uint32:()=>t.In,Uint32BE:()=>t.Ln,Uint32LE:()=>t.Rn,Uint32Opt:()=>t.nn,Uint32Vec:()=>t.rn,Uint512:()=>t.zn,Uint512BE:()=>t.Bn,Uint512LE:()=>t.Vn,Uint512Opt:()=>t.in,Uint512Vec:()=>t.an,Uint64:()=>t.Hn,Uint64BE:()=>t.Un,Uint64LE:()=>t.Wn,Uint64Opt:()=>t.on,Uint64Vec:()=>t.sn,Uint8:()=>t.Gn,Uint8Opt:()=>t.cn,Uint8Vec:()=>t.ln,array:()=>t.un,byteVec:()=>t.dn,codec:()=>t.ur,dynItemVec:()=>t.fn,fixedItemVec:()=>t.pn,option:()=>t.mn,struct:()=>t.hn,table:()=>t.gn,uint:()=>t.qn,uintNumber:()=>t.Jn,union:()=>t._n,vector:()=>t.vn}),O=class{async markUsable(...e){return await this.recordCells(...e),this.markUsableNoCache(...e)}async markTransactions(...e){await Promise.all([this.recordTransactionResponses(e.flat().map(e=>({transaction:e,status:`sent`}))),...e.flat().map(e=>{let n=t._.from(e),r=n.hash();return Promise.all([...n.inputs.map(e=>this.markUnusable(e.previousOutput)),...n.outputs.map((e,t)=>this.markUsable({cellOutput:e,outputData:n.outputsData[t],outPoint:{txHash:r,index:t}}))])})])}async recordCells(...e){}async getCell(e){}async recordTransactionResponses(...e){}async getTransactionResponse(e){}async recordTransactions(...e){return this.recordTransactionResponses(e.flat().map(e=>({transaction:e,status:`unknown`})))}async getTransaction(e){return(await this.getTransactionResponse(e))?.transaction}async recordHeaders(...e){}async getHeaderByHash(e){}async getHeaderByNumber(e){}async recordBlocks(...e){}async getBlockByHash(e){}async getBlockByNumber(e){}hasHeaderConfirmed(e){return t.Zn(Date.now())-e.timestamp>=t.Y}},k=class extends O{constructor(e=512,n=256,r=128,i=t.Y){super(),this.maxCells=e,this.maxTxs=n,this.maxBlocks=r,this.cells=new t.X(this.maxCells),this.knownTransactions=new t.X(this.maxTxs),this.knownBlockHashes=new t.X(this.maxBlocks),this.knownBlocks=new t.X(this.maxBlocks),this.confirmedBlockTime=t.Zn(i)}async markUsableNoCache(...e){e.flat().forEach(e=>{let n=t.a.from(e).clone(),r=t.yr(n.outPoint.toBytes());this.cells.set(r,[!0,n])})}async markUnusable(...e){e.flat().forEach(e=>{let n=t.m.from(e),r=t.yr(n.toBytes()),i=this.cells.get(r);if(i){i[0]=!1;return}this.cells.set(r,[!1,{outPoint:n}])})}async clear(){this.cells.clear(),this.knownTransactions.clear()}async*findCells(e){for(let[n,[r,i]]of this.cells.entries())r&&t.Z(e,i)&&(this.cells.get(n),yield i.clone())}async isUnusable(e){let n=t.m.from(e);return!(this.cells.get(t.yr(n.toBytes()))?.[0]??!0)}async recordCells(...e){e.flat().map(e=>{let n=t.a.from(e),r=t.yr(n.outPoint.toBytes());this.cells.get(r)||this.cells.set(r,[void 0,n])})}async getCell(e){let n=t.m.from(e),r=this.cells.get(t.yr(n.toBytes()))?.[1];if(r&&r.cellOutput&&r.outputData)return t.a.from(r.clone())}async recordTransactionResponses(...e){e.flat().map(e=>{let n=t.lt.from(e);this.knownTransactions.set(n.transaction.hash(),n)})}async getTransactionResponse(e){let n=t.yr(e);return this.knownTransactions.get(n)?.clone()}async recordHeaders(...e){e.flat().map(e=>{let n=t.it.from(e);this.knownBlockHashes.set(n.number,n.hash),!this.knownBlocks.get(n.hash)&&this.knownBlocks.set(n.hash,{header:n})})}async getHeaderByHash(e){let n=t.yr(e),r=this.knownBlocks.get(n);return r&&this.knownBlockHashes.get(r.header.number),r?.header}async getHeaderByNumber(e){let n=t.Zn(e),r=this.knownBlockHashes.get(n);if(r)return this.getHeaderByHash(r)}async recordBlocks(...e){e.flat().map(e=>{let n=t.rt.from(e);this.knownBlockHashes.set(n.header.number,n.header.hash),this.knownBlocks.set(n.header.hash,n)})}async getBlockByHash(e){let n=t.yr(e),r=this.knownBlocks.get(n);if(r&&(this.knownBlockHashes.get(r.header.number),`transactions`in r))return r}async getBlockByNumber(e){let n=t.Zn(e),r=this.knownBlockHashes.get(n);if(r)return this.getBlockByHash(r)}hasHeaderConfirmed(e){return t.Zn(Date.now())-e.timestamp>=this.confirmedBlockTime}},A=class{constructor(e){this.cache=e?.cache??new k}async getFeeRate(e,n){let r=t.tr((await this.getFeeRateStatistics(e)).median,t.yt),i=t.Zn(n?.maxFeeRate??t.vt);return i===0n?r:t.nr(r,i)}async getBlockByNumber(e,t,n){let r=await this.cache.getBlockByNumber(e);if(r)return r;let i=await this.getBlockByNumberNoCache(e,t,n);return i&&this.cache.hasHeaderConfirmed(i.header)&&await this.cache.recordBlocks(i),i}async getBlockByHash(e,t,n){let r=await this.cache.getBlockByHash(e);if(r)return r;let i=await this.getBlockByHashNoCache(e,t,n);return i&&this.cache.hasHeaderConfirmed(i.header)&&await this.cache.recordBlocks(i),i}async getHeaderByNumber(e,t){let n=await this.cache.getHeaderByNumber(e);if(n)return n;let r=await this.getHeaderByNumberNoCache(e,t);return r&&this.cache.hasHeaderConfirmed(r)&&await this.cache.recordHeaders(r),r}async getHeaderByHash(e,t){let n=await this.cache.getHeaderByHash(e);if(n)return n;let r=await this.getHeaderByHashNoCache(e,t);return r&&this.cache.hasHeaderConfirmed(r)&&await this.cache.recordHeaders(r),r}async getCell(e){let n=t.m.from(e),r=await this.cache.getCell(n);if(r)return r;let i=await this.getTransaction(n.txHash);if(!i)return;let a=i.transaction.getOutput(n.index);if(!a)return;let o=t.a.from({...a,outPoint:n});return await this.cache.recordCells(o),o}async getCellWithHeader(e){let n=t.m.from(e),r=await this.getTransactionWithHeader(n.txHash);if(!r)return;let{transaction:i,header:a}=r,o=i.transaction.getOutput(n.index);if(!o)return;let s=t.a.from({...o,outPoint:n});return await this.cache.recordCells(s),{cell:s,header:a}}async getCellLive(e,t,n){let r=await this.getCellLiveNoCache(e,t,n);return t&&r&&await this.cache.recordCells(r),r}async findCellsPaged(e,t,n,r){let i=await this.findCellsPagedNoCache(e,t,n,r);return await this.cache.recordCells(i.cells),i}async*findCellsOnChain(e,t,n=10){let r;for(;;){let{cells:i,lastCursor:a}=await this.findCellsPaged(e,t,n,r);for(let e of i)yield e;if(i.length===0||i.length<n)return;r=a}}async*findCells(e,n,r=10){let i=t.ot.from(e),a=[];for await(let e of this.cache.findCells(i))a.push(e.outPoint),yield e;for await(let e of this.findCellsOnChain(i,n,r))await this.cache.isUnusable(e.outPoint)||a.some(t=>t.eq(e.outPoint))||(yield e)}findCellsByLock(e,t,n=!0,r,i=10){return this.findCells({script:e,scriptType:`lock`,scriptSearchMode:`exact`,filter:{script:t},withData:n},r,i)}findCellsByType(e,t=!0,n,r=10){return this.findCells({script:e,scriptType:`type`,scriptSearchMode:`exact`,withData:t},n,r)}async findSingletonCellByType(e,t=!0){for await(let n of this.findCellsByType(e,t,void 0,1))return n}async getCellDeps(...e){return Promise.all(e.flat().map(async e=>{let{cellDep:n,type:r}=t.nt.from(e);if(r===void 0)return n;let i=await this.findSingletonCellByType(r);return i?t.s.from({outPoint:i.outPoint,depType:n.depType}):n}))}async*findTransactions(e,t,n=10){let r;for(;;){let{transactions:i,lastCursor:a}=await this.findTransactionsPaged(e,t,n,r);for(let e of i)yield e;if(i.length===0||i.length<n)return;r=a}}findTransactionsByLock(e,t,n,r,i=10){return this.findTransactions({script:e,scriptType:`lock`,scriptSearchMode:`exact`,filter:{script:t},groupByTransaction:n},r,i)}findTransactionsByType(e,t,n,r=10){return this.findTransactions({script:e,scriptType:`type`,scriptSearchMode:`exact`,groupByTransaction:t},n,r)}async getBalanceSingle(e){return this.getCellsCapacity({script:e,scriptType:`lock`,scriptSearchMode:`exact`,filter:{scriptLenRange:[0,1],outputDataLenRange:[0,1]}})}async getBalance(e){return t.kt(e,async(e,t)=>e+await this.getBalanceSingle(t),t.or)}async sendTransaction(e,n,r){let i=t._.from(e),a=t.Zn(r?.maxFeeRate??t.vt),o=await i.getFeeRate(this);if(a>0n&&o>a)throw new t.ft(a,o);let s=await this.sendTransactionNoCache(i,n);return await this.cache.markTransactions(i),s}async getTransaction(e){let n=t.yr(e),r=await this.getTransactionNoCache(n);return r?(await this.cache.recordTransactionResponses(r),r):this.cache.getTransactionResponse(n)}async getTransactionWithHeader(e){let n=t.yr(e),r=await this.cache.getTransactionResponse(n);if(r?.blockHash){let e=await this.getHeaderByHash(r.blockHash);if(e&&this.cache.hasHeaderConfirmed(e))return{transaction:r,header:e}}let i=await this.getTransactionNoCache(n);if(i)return await this.cache.recordTransactionResponses(i),{transaction:i,header:i.blockHash?await this.getHeaderByHash(i.blockHash):void 0}}async waitTransaction(e,n=0,r=6e4,i=2e3){let a=Date.now(),o,s=async()=>{let t=await this.getTransaction(e);if(!(!t||t.blockNumber==null||[`sent`,`pending`,`proposed`].includes(t.status)))return o=t,t};for(;;){if(!o){if(await s())continue}else if(n===0)return o;else if((await this.getTipHeader()).number-o.blockNumber>=n)return o;if(Date.now()-a+i>=r)throw new t.gt(r);await t.At(i)}}};function j(e,t){return t?t(e):e}var M=class{constructor(e,n,r){this.url_=e,this.onError=r,this.concurrent=0,this.pending=[],this.id=0,this.maxConcurrent=n?.maxConcurrent,this.transport=n?.transport??new t.U(Array.from(new Set([e,...n?.fallbacks??[]]).values(),e=>t.W(e,n)))}get url(){return this.url_}async request(e,t,n,r){let i=this.buildPayload(e,n?await Promise.all(t.concat(Array.from(Array(Math.max(n.length-t.length,0)))).map((e,t)=>j(e,n[t]))):t);try{return await j(await this.requestPayload(i),r)}catch(e){if(!this.onError)throw e;await this.onError(e)}}async requestPayload(e){this.maxConcurrent!==void 0&&this.concurrent>=this.maxConcurrent&&await new Promise(e=>this.pending.push(e));let t=await(async()=>{this.concurrent+=1;try{return await this.transport.request(e)}finally{--this.concurrent,this.pending.shift()?.()}})();if(t.id!==e.id)throw Error(`Id mismatched, got ${t.id}, expected ${e.id}`);if(t.error!=null)throw t.error;return t.result}buildPayload(e,t){return{id:this.id++,method:e,params:t,jsonrpc:`2.0`}}};const N=[[`Resolve\\(Unknown\\(OutPoint\\((0x.*)\\)\\)\\)`,(e,n)=>new t.mt(e,t.m.fromBytes(n[1]))],[`Verification\\(Error { kind: Script, inner: TransactionScriptError { source: (Inputs|Outputs)\\[([0-9]*)\\].(Lock|Type), cause: ValidationFailure: see error code (-?[0-9]+) on page https://nervosnetwork\\.github\\.io/ckb-script-error-codes/by-(type|data)-hash/(.*)\\.html`,(e,n)=>new t.ht(e,n[3]===`Lock`?`lock`:n[1]===`Inputs`?`inputType`:`outputType`,n[2],Number(n[4]),n[5]===`data`?`data`:`type`,n[6])],[`Duplicated\\(Byte32\\((0x.*)\\)\\)`,(e,n)=>new t.dt(e,n[1])],[`RBFRejected\\("Tx's current fee is ([0-9]*), expect it to >= ([0-9]*) to replace old txs"\\)`,(e,n)=>new t.pt(e,n[1],n[2])]];var P=class extends A{constructor(e,n){super(n),this.getFeeRateStatistics=this.buildSender(`get_fee_rate_statistics`,[e=>t.Et(t.Zn,e)],e=>({mean:t.Zn(e?.mean??t.yt),median:t.Zn(e?.median??t.yt)})),this.getTip=this.buildSender(`get_tip_block_number`,[],t.Zn),this.getTipHeader=this.buildSender(`get_tip_header`,[],e=>t.Et(t.H.blockHeaderTo,e)),this.getBlockByNumberNoCache=this.buildSender(`get_block_by_number`,[e=>t.ir(t.Zn(e))],e=>t.Et(t.H.blockTo,e)),this.getBlockByHashNoCache=this.buildSender(`get_block`,[t.yr],e=>t.Et(t.H.blockTo,e)),this.getHeaderByNumberNoCache=this.buildSender(`get_header_by_number`,[e=>t.ir(t.Zn(e))],e=>t.Et(t.H.blockHeaderTo,e)),this.getHeaderByHashNoCache=this.buildSender(`get_header`,[t.yr],e=>t.Et(t.H.blockHeaderTo,e)),this.estimateCycles=this.buildSender(`estimate_cycles`,[t.H.transactionFrom],({cycles:e})=>t.Zn(e)),this.sendTransactionDry=this.buildSender(`test_tx_pool_accept`,[t.H.transactionFrom],({cycles:e})=>t.Zn(e)),this.sendTransactionNoCache=this.buildSender(`send_transaction`,[t.H.transactionFrom,e=>e??void 0],t.yr),this.getTransactionNoCache=this.buildSender(`get_transaction`,[t.yr],t.H.transactionResponseTo),this.findCellsPagedNoCache=this.buildSender(`get_cells`,[t.H.indexerSearchKeyFrom,e=>e??`asc`,e=>t.ir(e??10)],t.H.findCellsResponseTo),this.findTransactionsPaged=this.buildSender(`get_transactions`,[t.H.indexerSearchKeyTransactionFrom,e=>e??`asc`,e=>t.ir(e??10)],t.H.findTransactionsResponseTo),this.getCellsCapacity=this.buildSender(`get_cells_capacity`,[t.H.indexerSearchKeyFrom],({capacity:e})=>t.Zn(e)),this.requestor=n?.requestor??new M(e,n,e=>{if(typeof e!=`object`||!e||!(`data`in e)||typeof e.data!=`string`)throw e;let n=e;for(let[e,t]of N){let r=n.data.match(e);if(r)throw t(n,r)}throw new t.ut(n)})}get url(){return this.requestor.url}getCellLiveNoCache(e,n,r){return this.buildSender(`get_live_cell`,[t.H.outPointFrom],({cell:n})=>t.Et(({output:n,data:r})=>t.a.from({cellOutput:t.H.cellOutputTo(n),outputData:r?.content??`0x`,outPoint:e}),n))(e,n??!0,r)}buildSender(e,t,n){return async(...r)=>this.requestor.request(e,r,t,n)}},F=class extends P{constructor(e){let t=r.default!==void 0;super(e?.url??(t?`wss://mainnet.ckb.dev/ws`:`https://mainnet.ckb.dev/`),{...e,fallbacks:e?.fallbacks??(t?[`wss://mainnet.ckb.dev/ws`,`https://mainnet.ckb.dev/`,`https://mainnet.ckbapp.dev/`]:[`https://mainnet.ckb.dev/`,`https://mainnet.ckbapp.dev/`])}),this.config=e}get scripts(){return this.config?.scripts??t.q}get addressPrefix(){return`ckb`}async getKnownScript(e){let n=this.scripts[e];if(!n)throw Error(`No script information was found for ${e} on ${this.addressPrefix}`);return t._t.from(n)}},I=class extends P{constructor(e){let t=r.default!==void 0;super(e?.url??(t?`wss://testnet.ckb.dev/ws`:`https://testnet.ckb.dev/`),{...e,fallbacks:e?.fallbacks??(t?[`wss://testnet.ckb.dev/ws`,`https://testnet.ckb.dev/`,`https://testnet.ckbapp.dev/`]:[`https://testnet.ckb.dev/`,`https://testnet.ckbapp.dev/`])}),this.config=e}get scripts(){return this.config?.scripts??t.V}get addressPrefix(){return`ckt`}async getKnownScript(e){let n=this.scripts[e];if(!n)throw Error(`No script information was found for ${e} on ${this.addressPrefix}`);return t._t.from(n)}};function L(e,n){return t.mr(t.l.from(e).toBytes(),t.er(n,8))}var R=class e{constructor(e,t){this.script=e,this.prefix=t}static from(n){return n instanceof e?n:new e(t.M.from(n.script),n.prefix)}static async fromString(n,r){let{prefix:i,format:a,payload:o}=t.i(n),s=r[i]??r;if(!s)throw Error(`Unknown address prefix ${i}`);let c=s.addressPrefix;if(c!==i)throw Error(`Unknown address prefix ${i}, expected ${c}`);return e.from(await t.r(i,a,o,s))}static fromScript(t,n){return e.from({script:t,prefix:n.addressPrefix})}static async fromKnownScript(n,r,i){return e.from({script:await t.M.fromKnownScript(n,r,i),prefix:n.addressPrefix})}toString(){let e=t.Jr([0],t.Zr(this.script.codeHash),t.L(this.script.hashType),t.Zr(this.script.args));return n.bech32m.encode(this.prefix,n.bech32m.toWords(e),t.t)}};
|
|
1
|
+
const e=require("./rolldown-runtime-DWNI8pZO.js"),t=require("./address.advanced-BqcYOpZn.js");let n=require("bech32"),r=require("isomorphic-ws");r=e.n(r);let i=require("@joyid/ckb"),a=require("ethers");function o(e,t,n){return e&t^~e&n}function s(e,t,n){return e&t^e&n^t&n}var c=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,n,r,i){this.blockLen=e,this.outputLen=n,this.padOffset=r,this.isLE=i,this.buffer=new Uint8Array(e),this.view=t.Lr(this.buffer)}update(e){t.Dr(this),t.Er(e);let{view:n,buffer:r,blockLen:i}=this,a=e.length;for(let o=0;o<a;){let s=Math.min(i-this.pos,a-o);if(s===i){let n=t.Lr(e);for(;i<=a-o;o+=i)this.process(n,o);continue}r.set(e.subarray(o,o+s),this.pos),this.pos+=s,o+=s,this.pos===i&&(this.process(n,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){t.Dr(this),t.Ar(e,this),this.finished=!0;let{buffer:n,view:r,blockLen:i,isLE:a}=this,{pos:o}=this;n[o++]=128,t.Pr(this.buffer.subarray(o)),this.padOffset>i-o&&(this.process(r,0),o=0);for(let e=o;e<i;e++)n[e]=0;r.setBigUint64(i-8,BigInt(this.length*8),a),this.process(r,0);let s=t.Lr(e),c=this.outputLen;if(c%4)throw Error(`_sha2: outputLen must be aligned to 32bit`);let l=c/4,u=this.get();if(l>u.length)throw Error(`_sha2: outputLen bigger than state`);for(let e=0;e<l;e++)s.setUint32(4*e,u[e],a)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:t,buffer:n,length:r,finished:i,destroyed:a,pos:o}=this;return e.destroyed=a,e.finished=i,e.length=r,e.pos=o,r%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}};const l=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),u=BigInt(0),d=BigInt(1),f=BigInt(2),p=BigInt(7),m=BigInt(256),h=BigInt(113),g=[],_=[],v=[];for(let e=0,t=d,n=1,r=0;e<24;e++){[n,r]=[r,(2*n+3*r)%5],g.push(2*(5*r+n)),_.push((e+1)*(e+2)/2%64);let i=u;for(let e=0;e<7;e++)t=(t<<d^(t>>p)*h)%m,t&f&&(i^=d<<(d<<BigInt(e))-d);v.push(i)}const y=t.Tr(v,!0),ee=y[0],b=y[1],x=(e,n,r)=>r>32?t.xr(e,n,r):t.Cr(e,n,r),S=(e,n,r)=>r>32?t.Sr(e,n,r):t.wr(e,n,r);function C(e,n=24){if(t.kr(n,`rounds`),n<1||n>24)throw Error(`"rounds" expected integer 1..24`);let r=new Uint32Array(10);for(let t=24-n;t<24;t++){for(let t=0;t<10;t++)r[t]=e[t]^e[t+10]^e[t+20]^e[t+30]^e[t+40];for(let t=0;t<10;t+=2){let n=(t+8)%10,i=(t+2)%10,a=r[i],o=r[i+1],s=x(a,o,1)^r[n],c=S(a,o,1)^r[n+1];for(let n=0;n<50;n+=10)e[t+n]^=s,e[t+n+1]^=c}let n=e[2],i=e[3];for(let t=0;t<24;t++){let r=_[t],a=x(n,i,r),o=S(n,i,r),s=g[t];n=e[s],i=e[s+1],e[s]=a,e[s+1]=o}for(let t=0;t<50;t+=10){let n=e[t],r=e[t+1],i=e[t+2],a=e[t+3];e[t]^=~e[t+2]&e[t+4],e[t+1]^=~e[t+3]&e[t+5],e[t+2]^=~e[t+4]&e[t+6],e[t+3]^=~e[t+5]&e[t+7],e[t+4]^=~e[t+6]&e[t+8],e[t+5]^=~e[t+7]&e[t+9],e[t+6]^=~e[t+8]&n,e[t+7]^=~e[t+9]&r,e[t+8]^=~n&i,e[t+9]^=~r&a}e[0]^=ee[t],e[1]^=b[t]}t.Pr(r)}var w=class e{state;pos=0;posOut=0;finished=!1;state32;destroyed=!1;blockLen;suffix;outputLen;canXOF;enableXOF=!1;rounds;constructor(e,n,r,i=!1,a=24){if(this.blockLen=e,this.suffix=n,this.outputLen=r,this.enableXOF=i,this.canXOF=i,this.rounds=a,t.kr(r,`outputLen`),!(0<e&&e<200))throw Error(`only keccak-f1600 function is supported`);this.state=new Uint8Array(200),this.state32=t.Kr(this.state)}clone(){return this._cloneInto()}keccak(){t.Gr(this.state32),C(this.state32,this.rounds),t.Gr(this.state32),this.posOut=0,this.pos=0}update(e){t.Dr(this),t.Er(e);let{blockLen:n,state:r}=this,i=e.length;for(let t=0;t<i;){let a=Math.min(n-this.pos,i-t);for(let n=0;n<a;n++)r[this.pos++]^=e[t++];this.pos===n&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;let{state:e,suffix:t,pos:n,blockLen:r}=this;e[n]^=t,t&128&&n===r-1&&this.keccak(),e[r-1]^=128,this.keccak()}writeInto(e){t.Dr(this,!1),t.Er(e),this.finish();let n=this.state,{blockLen:r}=this;for(let t=0,i=e.length;t<i;){this.posOut>=r&&this.keccak();let a=Math.min(r-this.posOut,i-t);e.set(n.subarray(this.posOut,this.posOut+a),t),this.posOut+=a,t+=a}return e}xofInto(e){if(!this.enableXOF)throw Error(`XOF is not possible for this instance`);return this.writeInto(e)}xof(e){return t.kr(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(t.Ar(e,this),this.finished)throw Error(`digest() was already called`);this.writeInto(e.subarray(0,this.outputLen)),this.destroy()}digest(){let e=new Uint8Array(this.outputLen);return this.digestInto(e),e}destroy(){this.destroyed=!0,t.Pr(this.state)}_cloneInto(t){let{blockLen:n,suffix:r,outputLen:i,rounds:a,enableXOF:o}=this;return t||=new e(n,r,i,o,a),t.blockLen=n,t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=a,t.suffix=r,t.outputLen=i,t.enableXOF=o,t.canXOF=this.canXOF,t.destroyed=this.destroyed,t}};const T=((e,n,r,i={})=>t.Ir(()=>new w(n,e,r),i))(1,136,32);var E=class{constructor(){this.hasher=T.create()}update(e){return this.hasher.update(t.Qr(e)),this}digest(){return t.br(this.hasher.digest())}},D=e.t({Bool:()=>t.bn,BoolOpt:()=>t.Nt,BoolVec:()=>t.Pt,Byte:()=>t.xn,Byte16:()=>t.Sn,Byte16Opt:()=>t.Ft,Byte16Vec:()=>t.It,Byte32:()=>t.Cn,Byte32Opt:()=>t.Lt,Byte32Vec:()=>t.Rt,Byte4:()=>t.wn,Byte4Opt:()=>t.zt,Byte4Vec:()=>t.Bt,Byte8:()=>t.Tn,Byte8Opt:()=>t.Vt,Byte8Vec:()=>t.Ht,ByteOpt:()=>t.Ut,ByteVec:()=>t.Wt,Bytes:()=>t.Gt,BytesOpt:()=>t.Kt,BytesVec:()=>t.qt,Codec:()=>t.qr,Entity:()=>t.ur,String:()=>t.Jt,StringOpt:()=>t.Yt,StringVec:()=>t.Xt,Uint128:()=>t.On,Uint128BE:()=>t.kn,Uint128LE:()=>t.An,Uint128Opt:()=>t.Zt,Uint128Vec:()=>t.Qt,Uint16:()=>t.jn,Uint16BE:()=>t.Mn,Uint16LE:()=>t.Nn,Uint16Opt:()=>t.$t,Uint16Vec:()=>t.en,Uint256:()=>t.Pn,Uint256BE:()=>t.Fn,Uint256LE:()=>t.In,Uint256Opt:()=>t.tn,Uint256Vec:()=>t.nn,Uint32:()=>t.Ln,Uint32BE:()=>t.Rn,Uint32LE:()=>t.zn,Uint32Opt:()=>t.rn,Uint32Vec:()=>t.in,Uint512:()=>t.Bn,Uint512BE:()=>t.Vn,Uint512LE:()=>t.Hn,Uint512Opt:()=>t.an,Uint512Vec:()=>t.on,Uint64:()=>t.Un,Uint64BE:()=>t.Wn,Uint64LE:()=>t.Gn,Uint64Opt:()=>t.sn,Uint64Vec:()=>t.cn,Uint8:()=>t.Kn,Uint8Opt:()=>t.ln,Uint8Vec:()=>t.un,array:()=>t.dn,byteVec:()=>t.fn,codec:()=>t.dr,dynItemVec:()=>t.pn,fixedItemVec:()=>t.mn,option:()=>t.hn,struct:()=>t.gn,table:()=>t._n,uint:()=>t.Jn,uintNumber:()=>t.Yn,union:()=>t.vn,vector:()=>t.yn}),O=class{async markUsable(...e){return await this.recordCells(...e),this.markUsableNoCache(...e)}async markTransactions(...e){await Promise.all([this.recordTransactionResponses(e.flat().map(e=>({transaction:e,status:`sent`}))),...e.flat().map(e=>{let n=t._.from(e),r=n.hash();return Promise.all([...n.inputs.map(e=>this.markUnusable(e.previousOutput)),...n.outputs.map((e,t)=>this.markUsable({cellOutput:e,outputData:n.outputsData[t],outPoint:{txHash:r,index:t}}))])})])}async recordCells(...e){}async getCell(e){}async recordTransactionResponses(...e){}async getTransactionResponse(e){}async recordTransactions(...e){return this.recordTransactionResponses(e.flat().map(e=>({transaction:e,status:`unknown`})))}async getTransaction(e){return(await this.getTransactionResponse(e))?.transaction}async recordHeaders(...e){}async getHeaderByHash(e){}async getHeaderByNumber(e){}async recordBlocks(...e){}async getBlockByHash(e){}async getBlockByNumber(e){}hasHeaderConfirmed(e){return t.Qn(Date.now())-e.timestamp>=t.Y}},k=class extends O{constructor(e=512,n=256,r=128,i=t.Y){super(),this.maxCells=e,this.maxTxs=n,this.maxBlocks=r,this.cells=new t.X(this.maxCells),this.knownTransactions=new t.X(this.maxTxs),this.knownBlockHashes=new t.X(this.maxBlocks),this.knownBlocks=new t.X(this.maxBlocks),this.confirmedBlockTime=t.Qn(i)}async markUsableNoCache(...e){e.flat().forEach(e=>{let n=t.a.from(e).clone(),r=t.br(n.outPoint.toBytes());this.cells.set(r,[!0,n])})}async markUnusable(...e){e.flat().forEach(e=>{let n=t.m.from(e),r=t.br(n.toBytes()),i=this.cells.get(r);if(i){i[0]=!1;return}this.cells.set(r,[!1,{outPoint:n}])})}async clear(){this.cells.clear(),this.knownTransactions.clear()}async*findCells(e){for(let[n,[r,i]]of this.cells.entries())r&&t.Z(e,i)&&(this.cells.get(n),yield i.clone())}async isUnusable(e){let n=t.m.from(e);return!(this.cells.get(t.br(n.toBytes()))?.[0]??!0)}async recordCells(...e){e.flat().map(e=>{let n=t.a.from(e),r=t.br(n.outPoint.toBytes());this.cells.get(r)||this.cells.set(r,[void 0,n])})}async getCell(e){let n=t.m.from(e),r=this.cells.get(t.br(n.toBytes()))?.[1];if(r&&r.cellOutput&&r.outputData)return t.a.from(r.clone())}async recordTransactionResponses(...e){e.flat().map(e=>{let n=t.lt.from(e);this.knownTransactions.set(n.transaction.hash(),n)})}async getTransactionResponse(e){let n=t.br(e);return this.knownTransactions.get(n)?.clone()}async recordHeaders(...e){e.flat().map(e=>{let n=t.it.from(e);this.knownBlockHashes.set(n.number,n.hash),!this.knownBlocks.get(n.hash)&&this.knownBlocks.set(n.hash,{header:n})})}async getHeaderByHash(e){let n=t.br(e),r=this.knownBlocks.get(n);return r&&this.knownBlockHashes.get(r.header.number),r?.header}async getHeaderByNumber(e){let n=t.Qn(e),r=this.knownBlockHashes.get(n);if(r)return this.getHeaderByHash(r)}async recordBlocks(...e){e.flat().map(e=>{let n=t.rt.from(e);this.knownBlockHashes.set(n.header.number,n.header.hash),this.knownBlocks.set(n.header.hash,n)})}async getBlockByHash(e){let n=t.br(e),r=this.knownBlocks.get(n);if(r&&(this.knownBlockHashes.get(r.header.number),`transactions`in r))return r}async getBlockByNumber(e){let n=t.Qn(e),r=this.knownBlockHashes.get(n);if(r)return this.getBlockByHash(r)}hasHeaderConfirmed(e){return t.Qn(Date.now())-e.timestamp>=this.confirmedBlockTime}},A=class{constructor(e){this.cache=e?.cache??new k}async getFeeRate(e,n){let r=t.nr((await this.getFeeRateStatistics(e)).median??0n,t.yt),i=t.Qn(n?.maxFeeRate??t.vt);return i===0n?r:t.rr(r,i)}async getBlockByNumber(e,t,n){let r=await this.cache.getBlockByNumber(e);if(r)return r;let i=await this.getBlockByNumberNoCache(e,t,n);return i&&this.cache.hasHeaderConfirmed(i.header)&&await this.cache.recordBlocks(i),i}async getBlockByHash(e,t,n){let r=await this.cache.getBlockByHash(e);if(r)return r;let i=await this.getBlockByHashNoCache(e,t,n);return i&&this.cache.hasHeaderConfirmed(i.header)&&await this.cache.recordBlocks(i),i}async getHeaderByNumber(e,t){let n=await this.cache.getHeaderByNumber(e);if(n)return n;let r=await this.getHeaderByNumberNoCache(e,t);return r&&this.cache.hasHeaderConfirmed(r)&&await this.cache.recordHeaders(r),r}async getHeaderByHash(e,t){let n=await this.cache.getHeaderByHash(e);if(n)return n;let r=await this.getHeaderByHashNoCache(e,t);return r&&this.cache.hasHeaderConfirmed(r)&&await this.cache.recordHeaders(r),r}async getCell(e){let n=t.m.from(e),r=await this.cache.getCell(n);if(r)return r;let i=await this.getTransaction(n.txHash);if(!i)return;let a=i.transaction.getOutput(n.index);if(!a)return;let o=t.a.from({...a,outPoint:n});return await this.cache.recordCells(o),o}async getCellWithHeader(e){let n=t.m.from(e),r=await this.getTransactionWithHeader(n.txHash);if(!r)return;let{transaction:i,header:a}=r,o=i.transaction.getOutput(n.index);if(!o)return;let s=t.a.from({...o,outPoint:n});return await this.cache.recordCells(s),{cell:s,header:a}}async getCellLive(e,t,n){let r=await this.getCellLiveNoCache(e,t,n);return t&&r&&await this.cache.recordCells(r),r}async findCellsPaged(e,t,n,r){let i=await this.findCellsPagedNoCache(e,t,n,r);return await this.cache.recordCells(i.cells),i}async*findCellsOnChain(e,t,n=10){let r;for(;;){let{cells:i,lastCursor:a}=await this.findCellsPaged(e,t,n,r);for(let e of i)yield e;if(i.length===0||i.length<n)return;r=a}}async*findCells(e,n,r=10){let i=t.ot.from(e),a=[];for await(let e of this.cache.findCells(i))a.push(e.outPoint),yield e;for await(let e of this.findCellsOnChain(i,n,r))await this.cache.isUnusable(e.outPoint)||a.some(t=>t.eq(e.outPoint))||(yield e)}findCellsByLock(e,t,n=!0,r,i=10){return this.findCells({script:e,scriptType:`lock`,scriptSearchMode:`exact`,filter:{script:t},withData:n},r,i)}findCellsByType(e,t=!0,n,r=10){return this.findCells({script:e,scriptType:`type`,scriptSearchMode:`exact`,withData:t},n,r)}async findSingletonCellByType(e,t=!0){for await(let n of this.findCellsByType(e,t,void 0,1))return n}async getCellDeps(...e){return Promise.all(e.flat().map(async e=>{let{cellDep:n,type:r}=t.nt.from(e);if(r===void 0)return n;let i=await this.findSingletonCellByType(r);return i?t.s.from({outPoint:i.outPoint,depType:n.depType}):n}))}async*findTransactions(e,t,n=10){let r;for(;;){let{transactions:i,lastCursor:a}=await this.findTransactionsPaged(e,t,n,r);for(let e of i)yield e;if(i.length===0||i.length<n)return;r=a}}findTransactionsByLock(e,t,n,r,i=10){return this.findTransactions({script:e,scriptType:`lock`,scriptSearchMode:`exact`,filter:{script:t},groupByTransaction:n},r,i)}findTransactionsByType(e,t,n,r=10){return this.findTransactions({script:e,scriptType:`type`,scriptSearchMode:`exact`,groupByTransaction:t},n,r)}async getBalanceSingle(e){return this.getCellsCapacity({script:e,scriptType:`lock`,scriptSearchMode:`exact`,filter:{scriptLenRange:[0,1],outputDataLenRange:[0,1]}})}async getBalance(e){return t.At(e,async(e,t)=>e+await this.getBalanceSingle(t),t.sr)}async sendTransaction(e,n,r){let i=t._.from(e),a=t.Qn(r?.maxFeeRate??t.vt),o=await i.getFeeRate(this);if(a>0n&&o>a)throw new t.ft(a,o);let s=await this.sendTransactionNoCache(i,n);return await this.cache.markTransactions(i),s}async getTransaction(e){let n=t.br(e),r=await this.getTransactionNoCache(n);return r?(await this.cache.recordTransactionResponses(r),r):this.cache.getTransactionResponse(n)}async getTransactionWithHeader(e){let n=t.br(e),r=await this.cache.getTransactionResponse(n);if(r?.blockHash){let e=await this.getHeaderByHash(r.blockHash);if(e&&this.cache.hasHeaderConfirmed(e))return{transaction:r,header:e}}let i=await this.getTransactionNoCache(n);if(i)return await this.cache.recordTransactionResponses(i),{transaction:i,header:i.blockHash?await this.getHeaderByHash(i.blockHash):void 0}}async waitTransaction(e,n=0,r=6e4,i=2e3){let a=Date.now(),o,s=async()=>{let t=await this.getTransaction(e);if(!(!t||t.blockNumber==null||[`sent`,`pending`,`proposed`].includes(t.status)))return o=t,t};for(;;){if(!o){if(await s())continue}else if(n===0)return o;else if((await this.getTipHeader()).number-o.blockNumber>=n)return o;if(Date.now()-a+i>=r)throw new t.gt(r);await t.jt(i)}}};function j(e,t){return t?t(e):e}var M=class{constructor(e,n,r){this.url_=e,this.onError=r,this.concurrent=0,this.pending=[],this.id=0,this.maxConcurrent=n?.maxConcurrent,this.transport=n?.transport??new t.U(Array.from(new Set([e,...n?.fallbacks??[]]).values(),e=>t.W(e,n)))}get url(){return this.url_}async request(e,t,n,r){let i=this.buildPayload(e,n?await Promise.all(t.concat(Array.from(Array(Math.max(n.length-t.length,0)))).map((e,t)=>j(e,n[t]))):t);try{return await j(await this.requestPayload(i),r)}catch(e){if(!this.onError)throw e;await this.onError(e)}}async requestPayload(e){this.maxConcurrent!==void 0&&this.concurrent>=this.maxConcurrent&&await new Promise(e=>this.pending.push(e));let t=await(async()=>{this.concurrent+=1;try{return await this.transport.request(e)}finally{--this.concurrent,this.pending.shift()?.()}})();if(t.id!==e.id)throw Error(`Id mismatched, got ${t.id}, expected ${e.id}`);if(t.error!=null)throw t.error;return t.result}buildPayload(e,t){return{id:this.id++,method:e,params:t,jsonrpc:`2.0`}}};const N=[[`Resolve\\(Unknown\\(OutPoint\\((0x.*)\\)\\)\\)`,(e,n)=>new t.mt(e,t.m.fromBytes(n[1]))],[`Verification\\(Error { kind: Script, inner: TransactionScriptError { source: (Inputs|Outputs)\\[([0-9]*)\\].(Lock|Type), cause: ValidationFailure: see error code (-?[0-9]+) on page https://nervosnetwork\\.github\\.io/ckb-script-error-codes/by-(type|data)-hash/(.*)\\.html`,(e,n)=>new t.ht(e,n[3]===`Lock`?`lock`:n[1]===`Inputs`?`inputType`:`outputType`,n[2],Number(n[4]),n[5]===`data`?`data`:`type`,n[6])],[`Duplicated\\(Byte32\\((0x.*)\\)\\)`,(e,n)=>new t.dt(e,n[1])],[`RBFRejected\\("Tx's current fee is ([0-9]*), expect it to >= ([0-9]*) to replace old txs"\\)`,(e,n)=>new t.pt(e,n[1],n[2])]];var P=class extends A{constructor(e,n){super(n),this.getFeeRateStatistics=this.buildSender(`get_fee_rate_statistics`,[e=>t.Et(t.Qn,e)],e=>({mean:t.Et(t.Qn,e?.mean),median:t.Et(t.Qn,e?.median)})),this.getTip=this.buildSender(`get_tip_block_number`,[],t.Qn),this.getTipHeader=this.buildSender(`get_tip_header`,[],e=>t.Et(t.H.blockHeaderTo,e)),this.getBlockByNumberNoCache=this.buildSender(`get_block_by_number`,[e=>t.ar(t.Qn(e))],e=>t.Et(t.H.blockTo,e)),this.getBlockByHashNoCache=this.buildSender(`get_block`,[t.br],e=>t.Et(t.H.blockTo,e)),this.getHeaderByNumberNoCache=this.buildSender(`get_header_by_number`,[e=>t.ar(t.Qn(e))],e=>t.Et(t.H.blockHeaderTo,e)),this.getHeaderByHashNoCache=this.buildSender(`get_header`,[t.br],e=>t.Et(t.H.blockHeaderTo,e)),this.estimateCycles=this.buildSender(`estimate_cycles`,[t.H.transactionFrom],({cycles:e})=>t.Qn(e)),this.sendTransactionDry=this.buildSender(`test_tx_pool_accept`,[t.H.transactionFrom],({cycles:e})=>t.Qn(e)),this.sendTransactionNoCache=this.buildSender(`send_transaction`,[t.H.transactionFrom,e=>e??void 0],t.br),this.getTransactionNoCache=this.buildSender(`get_transaction`,[t.br],t.H.transactionResponseTo),this.findCellsPagedNoCache=this.buildSender(`get_cells`,[t.H.indexerSearchKeyFrom,e=>e??`asc`,e=>t.ar(e??10)],t.H.findCellsResponseTo),this.findTransactionsPaged=this.buildSender(`get_transactions`,[t.H.indexerSearchKeyTransactionFrom,e=>e??`asc`,e=>t.ar(e??10)],t.H.findTransactionsResponseTo),this.getCellsCapacity=this.buildSender(`get_cells_capacity`,[t.H.indexerSearchKeyFrom],({capacity:e})=>t.Qn(e)),this.requestor=n?.requestor??new M(e,n,e=>{if(typeof e!=`object`||!e||!(`data`in e)||typeof e.data!=`string`)throw e;let n=e;for(let[e,t]of N){let r=n.data.match(e);if(r)throw t(n,r)}throw new t.ut(n)})}get url(){return this.requestor.url}getCellLiveNoCache(e,n,r){return this.buildSender(`get_live_cell`,[t.H.outPointFrom],({cell:n})=>t.Et(({output:n,data:r})=>t.a.from({cellOutput:t.H.cellOutputTo(n),outputData:r?.content??`0x`,outPoint:e}),n))(e,n??!0,r)}buildSender(e,t,n){return async(...r)=>this.requestor.request(e,r,t,n)}},F=class extends P{constructor(e){let t=r.default!==void 0;super(e?.url??(t?`wss://mainnet.ckb.dev/ws`:`https://mainnet.ckb.dev/`),{...e,fallbacks:e?.fallbacks??(t?[`wss://mainnet.ckb.dev/ws`,`https://mainnet.ckb.dev/`,`https://mainnet.ckbapp.dev/`]:[`https://mainnet.ckb.dev/`,`https://mainnet.ckbapp.dev/`])}),this.config=e}get scripts(){return this.config?.scripts??t.q}get addressPrefix(){return`ckb`}async getKnownScript(e){let n=this.scripts[e];if(!n)throw Error(`No script information was found for ${e} on ${this.addressPrefix}`);return t._t.from(n)}},I=class extends P{constructor(e){let t=r.default!==void 0;super(e?.url??(t?`wss://testnet.ckb.dev/ws`:`https://testnet.ckb.dev/`),{...e,fallbacks:e?.fallbacks??(t?[`wss://testnet.ckb.dev/ws`,`https://testnet.ckb.dev/`,`https://testnet.ckbapp.dev/`]:[`https://testnet.ckb.dev/`,`https://testnet.ckbapp.dev/`])}),this.config=e}get scripts(){return this.config?.scripts??t.V}get addressPrefix(){return`ckt`}async getKnownScript(e){let n=this.scripts[e];if(!n)throw Error(`No script information was found for ${e} on ${this.addressPrefix}`);return t._t.from(n)}};function L(e,n){return t.hr(t.l.from(e).toBytes(),t.tr(n,8))}var R=class e{constructor(e,t){this.script=e,this.prefix=t}static from(n){return n instanceof e?n:new e(t.M.from(n.script),n.prefix)}static async fromString(n,r){let{prefix:i,format:a,payload:o}=t.i(n),s=r[i]??r;if(!s)throw Error(`Unknown address prefix ${i}`);let c=s.addressPrefix;if(c!==i)throw Error(`Unknown address prefix ${i}, expected ${c}`);return e.from(await t.r(i,a,o,s))}static fromScript(t,n){return e.from({script:t,prefix:n.addressPrefix})}static async fromKnownScript(n,r,i){return e.from({script:await t.M.fromKnownScript(n,r,i),prefix:n.addressPrefix})}toString(){let e=t.Yr([0],t.Qr(this.script.codeHash),t.L(this.script.hashType),t.Qr(this.script.args));return n.bech32m.encode(this.prefix,n.bech32m.toWords(e),t.t)}};
|
|
2
2
|
/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */
|
|
3
|
-
function te(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`&&`BYTES_PER_ELEMENT`in e&&e.BYTES_PER_ELEMENT===1}function z(e,t,n=``){let r=te(e),i=e?.length,a=t!==void 0;if(!r||a&&i!==t){let o=n&&`"${n}" `,s=a?` of length ${t}`:``,c=r?`length=${i}`:`type=${typeof e}`,l=o+`expected Uint8Array`+s+`, got `+c;throw r?RangeError(l):TypeError(l)}return e}function ne(e){return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}function re(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function ie(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}const ae=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68,oe=e=>e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255,B=ae?e=>e:e=>oe(e)>>>0,se=ae?e=>e:e=>{for(let t=0;t<e.length;t++)e[t]=oe(e[t]);return e};function ce(e,t){return!e.byteLength||!t.byteLength?!1:e.buffer===t.buffer&&e.byteOffset<t.byteOffset+t.byteLength&&t.byteOffset<e.byteOffset+e.byteLength}function le(e,t){if(ce(e,t)&&e.byteOffset<t.byteOffset)throw Error(`complex overlap of input and output is not supported`)}const ue=(e,t)=>{function n(n,...r){if(z(n,void 0,`key`),e.nonceLength!==void 0){let t=r[0];z(t,e.varSizeNonce?void 0:e.nonceLength,`nonce`)}let i=e.tagLength;i&&r[1]!==void 0&&z(r[1],void 0,`AAD`);let a=t(n,...r),o=(e,t)=>{if(t!==void 0){if(e!==2)throw Error(`cipher output not supported`);z(t,void 0,`output`)}},s=!1;return{encrypt(e,t){if(s)throw Error(`cannot encrypt() twice with same key + nonce`);return s=!0,z(e),o(a.encrypt.length,t),a.encrypt(e,t)},decrypt(e,t){if(z(e),i&&e.length<i)throw Error(`"ciphertext" expected length bigger than tagLength=`+i);return o(a.decrypt.length,t),a.decrypt(e,t)}}}return Object.assign(n,e),n};function de(e,t,n=!0){if(t===void 0)return new Uint8Array(e);if(z(t,void 0,`output`),t.length!==e)throw Error(`"output" expected Uint8Array of length `+e+`, got: `+t.length);if(n&&!fe(t))throw Error(`invalid output, must be aligned`);return t}function fe(e){return e.byteOffset%4==0}function pe(e){return Uint8Array.from(z(e))}function me(e){if(![16,24,32].includes(e.length))throw Error(`"aes key" expected Uint8Array of length 16/24/32, got length=`+e.length)}function he(e){return e<<1^283&-(e>>7)}function ge(e,t){let n=0;for(;t>0;t>>=1)n^=e&-(t&1),e=he(e);return n}const _e=(e,t,n=1)=>{if(!Number.isSafeInteger(n)||n>4294967040)throw Error(`incBytes: wrong carry `+n);z(e);for(let r=0;r<e.length;r++){let i=t?r:e.length-1-r;n=n+(e[i]&255)|0,e[i]=n&255,n>>>=8}},ve=(()=>{let e=new Uint8Array(256);for(let t=0,n=1;t<256;t++,n^=he(n))e[t]=n;let t=new Uint8Array(256);t[0]=99;for(let n=0;n<255;n++){let r=e[255-n];r|=r<<8,t[e[n]]=(r^r>>4^r>>5^r>>6^r>>7^99)&255}return ie(e),t})(),ye=e=>e<<24|e>>>8,be=e=>e<<8|e>>>24;function xe(e,t){if(e.length!==256)throw Error(`Wrong sbox length`);let n=new Uint32Array(256).map((n,r)=>t(e[r])),r=n.map(be),i=r.map(be),a=i.map(be),o=new Uint32Array(256*256),s=new Uint32Array(256*256),c=new Uint16Array(256*256);for(let t=0;t<256;t++)for(let l=0;l<256;l++){let u=t*256+l;o[u]=n[t]^r[l],s[u]=i[t]^a[l],c[u]=e[t]<<8|e[l]}return{sbox:e,sbox2:c,T0:n,T1:r,T2:i,T3:a,T01:o,T23:s}}const Se=xe(ve,e=>ge(e,3)<<24|e<<16|e<<8|ge(e,2)),Ce=(()=>{let e=new Uint8Array(16);for(let t=0,n=1;t<16;t++,n=he(n))e[t]=n;return e})();function we(e){z(e);let t=e.length;me(e);let{sbox2:n}=Se,r=[];(!ae||!fe(e))&&r.push(e=pe(e));let i=se(re(e)),a=i.length,o=e=>Ee(n,e,e,e,e),s=new Uint32Array(t+28);s.set(i);for(let e=a;e<s.length;e++){let t=s[e-1];e%a===0?t=o(ye(t))^Ce[e/a-1]:a>6&&e%a===4&&(t=o(t)),s[e]=s[e-a]^t}return ie(...r),s}function Te(e,t,n,r,i,a){return e[n<<8&65280|r>>>8&255]^t[i>>>8&65280|a>>>24&255]}function Ee(e,t,n,r,i){return e[t&255|n&65280]|e[r>>>16&255|i>>>16&65280]<<16}function De(e,t,n,r,i){let{sbox2:a,T01:o,T23:s}=Se,c=0;t^=e[c++],n^=e[c++],r^=e[c++],i^=e[c++];let l=e.length/4-2;for(let a=0;a<l;a++){let a=e[c++]^Te(o,s,t,n,r,i),l=e[c++]^Te(o,s,n,r,i,t),u=e[c++]^Te(o,s,r,i,t,n),d=e[c++]^Te(o,s,i,t,n,r);t=a,n=l,r=u,i=d}return{s0:e[c++]^Ee(a,t,n,r,i),s1:e[c++]^Ee(a,n,r,i,t),s2:e[c++]^Ee(a,r,i,t,n),s3:e[c++]^Ee(a,i,t,n,r)}}function Oe(e,t,n,r){z(t,16,`nonce`),z(n);let i=n.length;r=de(i,r),le(n,r);let a=t,o=re(a),s=re(n),c=re(r),{s0:l,s1:u,s2:d,s3:f}=De(e,B(o[0]),B(o[1]),B(o[2]),B(o[3]));for(let t=0;t+4<=s.length;t+=4)c[t+0]=s[t+0]^B(l),c[t+1]=s[t+1]^B(u),c[t+2]=s[t+2]^B(d),c[t+3]=s[t+3]^B(f),_e(a,!1,1),{s0:l,s1:u,s2:d,s3:f}=De(e,B(o[0]),B(o[1]),B(o[2]),B(o[3]));let p=16*Math.floor(s.length/4);if(p<i){let e=new Uint32Array([l,u,d,f]);se(e);let t=ne(e);for(let e=p,a=0;e<i;e++,a++)r[e]=n[e]^t[a];ie(e)}return r}const ke=ue({blockSize:16,nonceLength:16},function(e,t){function n(n,r){if(z(n),r!==void 0&&(z(r),!fe(r)))throw Error(`unaligned destination`);let i=we(e),a=pe(t),o=[i,a];fe(n)||o.push(n=pe(n));let s=Oe(i,a,n,r);return ie(...o),s}return{encrypt:(e,t)=>n(e,t),decrypt:(e,t)=>n(e,t)}});var Ae=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,n){if(t.Dr(e),t.Tr(n,void 0,`key`),this.iHash=e.create(),typeof this.iHash.update!=`function`)throw Error(`Expected instance of class which extends utils.Hash`);this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let r=this.blockLen,i=new Uint8Array(r);i.set(n.length>r?e.create().update(n).digest():n);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),t.Nr(i)}update(e){return t.Er(this),this.iHash.update(e),this}digestInto(e){t.Er(this),t.kr(e,this),this.finished=!0;let n=e.subarray(0,this.outputLen);this.iHash.digestInto(n),this.oHash.update(n),this.oHash.digestInto(n),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:t,iHash:n,finished:r,destroyed:i,blockLen:a,outputLen:o}=this;return e=e,e.finished=r,e.destroyed=i,e.blockLen=a,e.outputLen=o,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}};const je=(()=>{let e=((e,t,n)=>new Ae(e,t).update(n).digest());return e.create=(e,t)=>new Ae(e,t),e})();function Me(e,n,r,i){t.Dr(e);let{c:a,dkLen:o,asyncTick:s}=t.Mr({dkLen:32,asyncTick:10},i);if(t.Or(a,`c`),t.Or(o,`dkLen`),t.Or(s,`asyncTick`),a<1)throw Error(`iterations (c) must be >= 1`);if(o<1)throw Error(`"dkLen" must be >= 1`);if(o>(2**32-1)*e.outputLen)throw Error(`derived key too long`);let c=t.zr(n,`password`),l=t.zr(r,`salt`),u=new Uint8Array(o),d=je.create(e,c);return{c:a,dkLen:o,asyncTick:s,DK:u,PRF:d,PRFSalt:d._cloneInto().update(l)}}function Ne(e,n,r,i,a){return e.destroy(),n.destroy(),i&&i.destroy(),t.Nr(a),r}function Pe(e,n,r,i){let{c:a,dkLen:o,DK:s,PRF:c,PRFSalt:l}=Me(e,n,r,i),u,d=new Uint8Array(4),f=t.Ir(d),p=new Uint8Array(c.outputLen);for(let e=1,t=0;t<o;e++,t+=c.outputLen){let n=s.subarray(t,t+c.outputLen);f.setInt32(0,e,!1),(u=l._cloneInto(u)).update(d).digestInto(p),n.set(p.subarray(0,n.length));for(let e=1;e<a;e++){c._cloneInto(u).update(p).digestInto(p);for(let e=0;e<n.length;e++)n[e]^=p[e]}}return Ne(c,l,s,u,p)}const Fe=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]),V=new Uint32Array(64);var Ie=class extends c{constructor(e){super(64,e,8,!1)}get(){let{A:e,B:t,C:n,D:r,E:i,F:a,G:o,H:s}=this;return[e,t,n,r,i,a,o,s]}set(e,t,n,r,i,a,o,s){this.A=e|0,this.B=t|0,this.C=n|0,this.D=r|0,this.E=i|0,this.F=a|0,this.G=o|0,this.H=s|0}process(e,n){for(let t=0;t<16;t++,n+=4)V[t]=e.getUint32(n,!1);for(let e=16;e<64;e++){let n=V[e-15],r=V[e-2],i=t.Ur(n,7)^t.Ur(n,18)^n>>>3,a=t.Ur(r,17)^t.Ur(r,19)^r>>>10;V[e]=a+V[e-7]+i+V[e-16]|0}let{A:r,B:i,C:a,D:c,E:l,F:u,G:d,H:f}=this;for(let e=0;e<64;e++){let n=t.Ur(l,6)^t.Ur(l,11)^t.Ur(l,25),p=f+n+o(l,u,d)+Fe[e]+V[e]|0,m=(t.Ur(r,2)^t.Ur(r,13)^t.Ur(r,22))+s(r,i,a)|0;f=d,d=u,u=l,l=c+p|0,c=a,a=i,i=r,r=p+m|0}r=r+this.A|0,i=i+this.B|0,a=a+this.C|0,c=c+this.D|0,l=l+this.E|0,u=u+this.F|0,d=d+this.G|0,f=f+this.H|0,this.set(r,i,a,c,l,u,d,f)}roundClean(){t.Nr(V)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),t.Nr(this.buffer)}},Le=class extends Ie{A=l[0]|0;B=l[1]|0;C=l[2]|0;D=l[3]|0;E=l[4]|0;F=l[5]|0;G=l[6]|0;H=l[7]|0;constructor(){super(32)}};const H=t.Fr(()=>new Le,t.Br(1));function Re(e,n,r,i,a,o){let s=e[n++]^r[i++],c=e[n++]^r[i++],l=e[n++]^r[i++],u=e[n++]^r[i++],d=e[n++]^r[i++],f=e[n++]^r[i++],p=e[n++]^r[i++],m=e[n++]^r[i++],h=e[n++]^r[i++],g=e[n++]^r[i++],_=e[n++]^r[i++],v=e[n++]^r[i++],y=e[n++]^r[i++],ee=e[n++]^r[i++],b=e[n++]^r[i++],x=e[n++]^r[i++],S=s,C=c,w=l,T=u,E=d,D=f,O=p,k=m,A=h,j=g,M=_,N=v,P=y,F=ee,I=b,L=x;for(let e=0;e<8;e+=2)E^=t.Hr(S+P|0,7),A^=t.Hr(E+S|0,9),P^=t.Hr(A+E|0,13),S^=t.Hr(P+A|0,18),j^=t.Hr(D+C|0,7),F^=t.Hr(j+D|0,9),C^=t.Hr(F+j|0,13),D^=t.Hr(C+F|0,18),I^=t.Hr(M+O|0,7),w^=t.Hr(I+M|0,9),O^=t.Hr(w+I|0,13),M^=t.Hr(O+w|0,18),T^=t.Hr(L+N|0,7),k^=t.Hr(T+L|0,9),N^=t.Hr(k+T|0,13),L^=t.Hr(N+k|0,18),C^=t.Hr(S+T|0,7),w^=t.Hr(C+S|0,9),T^=t.Hr(w+C|0,13),S^=t.Hr(T+w|0,18),O^=t.Hr(D+E|0,7),k^=t.Hr(O+D|0,9),E^=t.Hr(k+O|0,13),D^=t.Hr(E+k|0,18),N^=t.Hr(M+j|0,7),A^=t.Hr(N+M|0,9),j^=t.Hr(A+N|0,13),M^=t.Hr(j+A|0,18),P^=t.Hr(L+I|0,7),F^=t.Hr(P+L|0,9),I^=t.Hr(F+P|0,13),L^=t.Hr(I+F|0,18);a[o++]=s+S|0,a[o++]=c+C|0,a[o++]=l+w|0,a[o++]=u+T|0,a[o++]=d+E|0,a[o++]=f+D|0,a[o++]=p+O|0,a[o++]=m+k|0,a[o++]=h+A|0,a[o++]=g+j|0,a[o++]=_+M|0,a[o++]=v+N|0,a[o++]=y+P|0,a[o++]=ee+F|0,a[o++]=b+I|0,a[o++]=x+L|0}function ze(e,t,n,r,i){let a=r+0,o=r+16*i;for(let r=0;r<16;r++)n[o+r]=e[t+(2*i-1)*16+r];for(let r=0;r<i;r++,a+=16,t+=16)Re(n,o,e,t,n,a),r>0&&(o+=16),Re(n,a,e,t+=16,n,o)}function Be(e,n,r){let{N:i,r:a,p:o,dkLen:s,asyncTick:c,maxmem:l,onProgress:u}=t.Mr({dkLen:32,asyncTick:10,maxmem:1024**3+1024},r);if(t.Or(i,`N`),t.Or(a,`r`),t.Or(o,`p`),t.Or(s,`dkLen`),t.Or(c,`asyncTick`),t.Or(l,`maxmem`),u!==void 0&&typeof u!=`function`)throw Error(`progressCb must be a function`);let d=128*a,f=d/4,p=2**32;if(i<=1||i&i-1||i>p)throw Error(`"N" expected a power of 2, and 2^1 <= N <= 2^32`);if(o<1||o>(p-1)*32/d)throw Error(`"p" expected integer 1..((2^32 - 1) * 32) / (128 * r)`);if(s<1||s>(p-1)*32)throw Error(`"dkLen" expected integer 1..(2^32 - 1) * 32`);let m=d*(i+o+1);if(m>l)throw Error(`"maxmem" limit was hit: memUsed(128*r*(N+p+1))=`+m+`, maxmem=`+l);let h=Pe(H,e,n,{c:1,dkLen:d*o}),g=t.Gr(h),_=t.Gr(new Uint8Array(d*i)),v=t.Gr(new Uint8Array(d)),y=()=>{};if(u){let e=2*i*o,t=Math.max(Math.floor(e/1e4),1),n=0;y=()=>{n++,u&&(!(n%t)||n===e)&&u(n/e)}}return{N:i,r:a,p:o,dkLen:s,blockSize32:f,V:_,B32:g,B:h,tmp:v,blockMixCb:y,asyncTick:c}}function Ve(e,n,r,i,a){let o=Pe(H,e,r,{c:1,dkLen:n});return t.Nr(r,i,a),o}async function He(e,n,r){let{N:i,r:a,p:o,dkLen:s,blockSize32:c,V:l,B32:u,B:d,tmp:f,blockMixCb:p,asyncTick:m}=Be(e,n,r);t.Wr(u);for(let e=0;e<o;e++){let n=c*e;for(let e=0;e<c;e++)l[e]=u[n+e];let r=0;await t.Ar(i-1,m,()=>{ze(l,r,l,r+=c,a),p()}),ze(l,(i-1)*c,u,n,a),p(),await t.Ar(i,m,()=>{let e=(u[n+c-16]&i-1)>>>0;for(let t=0;t<c;t++)f[t]=u[n+t]^l[e*c+t];ze(f,0,u,n,a),p()})}return t.Wr(u),Ve(e,s,d,l,f)}function Ue(e,n){return t.yr(T(t.Jr(e.slice(16,32),n))).slice(2)}async function We(e,n,r){let i=t.Vr(32),a=t.Vr(16),o={dklen:32,salt:t.yr(i).slice(2),n:262144,r:8,p:1},s=await He(t.Zr(r,`utf8`),i,{N:o.n,r:o.r,p:o.p,dkLen:o.dklen}),c=ke(s.slice(0,16),a.map(e=>e)).encrypt(t.Jr(t.Zr(e),t.Zr(n)));return{id:t.yr(t.Vr(16)).slice(2),crypto:{ciphertext:t.yr(c).slice(2),cipherparams:{iv:t.yr(a).slice(2)},cipher:`aes-128-ctr`,kdf:`scrypt`,kdfparams:o,mac:Ue(s,c)}}}async function Ge(e,n){if(typeof e!=`object`||!e||!(`crypto`in e))throw Error(`Invalid keystore`);let r=e.crypto;if(typeof r!=`object`||!r||!(`kdfparams`in r)||!(`ciphertext`in r)||typeof r.ciphertext!=`string`||!(`mac`in r)||typeof r.mac!=`string`||!(`cipherparams`in r)||typeof r.cipherparams!=`object`||r.cipherparams===null||!(`iv`in r.cipherparams)||typeof r.cipherparams.iv!=`string`)throw Error(`Invalid crypto`);let i=r.kdfparams;if(typeof i!=`object`||!i||!(`n`in i)||typeof i.n!=`number`||!(`r`in i)||typeof i.r!=`number`||!(`p`in i)||typeof i.p!=`number`||!(`dklen`in i)||typeof i.dklen!=`number`||!(`salt`in i)||typeof i.salt!=`string`)throw Error(`Invalid kdfparams`);let a=await He(t.Zr(n,`utf8`),t.Zr(i.salt),{N:i.n,r:i.r,p:i.p,dkLen:i.dklen}),o=t.Zr(r.ciphertext);if(Ue(a,o)!==r.mac)throw Error(`Invalid password`);let s=ke(a.slice(0,16),t.Zr(r.cipherparams.iv)).decrypt(o);return{privateKey:s.slice(0,32),chainCode:s.slice(32)}}var Ke=class e{constructor(e,t){this.autoFinalized=e,this.inputsToSign=t}static from(t){return t instanceof e?t:new e(t?.autoFinalized??!0,t?.inputsToSign?.map(e=>qe.from(e))??[])}},qe=class e{constructor(e,t,n,r,i){this.index=e,this.sighashTypes=t,this.disableTweakSigner=n,this.address=r,this.publicKey=i}static from(n){return n instanceof e?n:new e(n.index,n.sighashTypes,n.disableTweakSigner,n.address,n.publicKey?t.yr(n.publicKey):void 0)}};
|
|
3
|
+
function te(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`&&`BYTES_PER_ELEMENT`in e&&e.BYTES_PER_ELEMENT===1}function z(e,t,n=``){let r=te(e),i=e?.length,a=t!==void 0;if(!r||a&&i!==t){let o=n&&`"${n}" `,s=a?` of length ${t}`:``,c=r?`length=${i}`:`type=${typeof e}`,l=o+`expected Uint8Array`+s+`, got `+c;throw r?RangeError(l):TypeError(l)}return e}function ne(e){return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}function re(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function ie(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}const ae=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68,oe=e=>e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255,B=ae?e=>e:e=>oe(e)>>>0,se=ae?e=>e:e=>{for(let t=0;t<e.length;t++)e[t]=oe(e[t]);return e};function ce(e,t){return!e.byteLength||!t.byteLength?!1:e.buffer===t.buffer&&e.byteOffset<t.byteOffset+t.byteLength&&t.byteOffset<e.byteOffset+e.byteLength}function le(e,t){if(ce(e,t)&&e.byteOffset<t.byteOffset)throw Error(`complex overlap of input and output is not supported`)}const ue=(e,t)=>{function n(n,...r){if(z(n,void 0,`key`),e.nonceLength!==void 0){let t=r[0];z(t,e.varSizeNonce?void 0:e.nonceLength,`nonce`)}let i=e.tagLength;i&&r[1]!==void 0&&z(r[1],void 0,`AAD`);let a=t(n,...r),o=(e,t)=>{if(t!==void 0){if(e!==2)throw Error(`cipher output not supported`);z(t,void 0,`output`)}},s=!1;return{encrypt(e,t){if(s)throw Error(`cannot encrypt() twice with same key + nonce`);return s=!0,z(e),o(a.encrypt.length,t),a.encrypt(e,t)},decrypt(e,t){if(z(e),i&&e.length<i)throw Error(`"ciphertext" expected length bigger than tagLength=`+i);return o(a.decrypt.length,t),a.decrypt(e,t)}}}return Object.assign(n,e),n};function de(e,t,n=!0){if(t===void 0)return new Uint8Array(e);if(z(t,void 0,`output`),t.length!==e)throw Error(`"output" expected Uint8Array of length `+e+`, got: `+t.length);if(n&&!fe(t))throw Error(`invalid output, must be aligned`);return t}function fe(e){return e.byteOffset%4==0}function pe(e){return Uint8Array.from(z(e))}function me(e){if(![16,24,32].includes(e.length))throw Error(`"aes key" expected Uint8Array of length 16/24/32, got length=`+e.length)}function he(e){return e<<1^283&-(e>>7)}function ge(e,t){let n=0;for(;t>0;t>>=1)n^=e&-(t&1),e=he(e);return n}const _e=(e,t,n=1)=>{if(!Number.isSafeInteger(n)||n>4294967040)throw Error(`incBytes: wrong carry `+n);z(e);for(let r=0;r<e.length;r++){let i=t?r:e.length-1-r;n=n+(e[i]&255)|0,e[i]=n&255,n>>>=8}},ve=(()=>{let e=new Uint8Array(256);for(let t=0,n=1;t<256;t++,n^=he(n))e[t]=n;let t=new Uint8Array(256);t[0]=99;for(let n=0;n<255;n++){let r=e[255-n];r|=r<<8,t[e[n]]=(r^r>>4^r>>5^r>>6^r>>7^99)&255}return ie(e),t})(),ye=e=>e<<24|e>>>8,be=e=>e<<8|e>>>24;function xe(e,t){if(e.length!==256)throw Error(`Wrong sbox length`);let n=new Uint32Array(256).map((n,r)=>t(e[r])),r=n.map(be),i=r.map(be),a=i.map(be),o=new Uint32Array(256*256),s=new Uint32Array(256*256),c=new Uint16Array(256*256);for(let t=0;t<256;t++)for(let l=0;l<256;l++){let u=t*256+l;o[u]=n[t]^r[l],s[u]=i[t]^a[l],c[u]=e[t]<<8|e[l]}return{sbox:e,sbox2:c,T0:n,T1:r,T2:i,T3:a,T01:o,T23:s}}const Se=xe(ve,e=>ge(e,3)<<24|e<<16|e<<8|ge(e,2)),Ce=(()=>{let e=new Uint8Array(16);for(let t=0,n=1;t<16;t++,n=he(n))e[t]=n;return e})();function we(e){z(e);let t=e.length;me(e);let{sbox2:n}=Se,r=[];(!ae||!fe(e))&&r.push(e=pe(e));let i=se(re(e)),a=i.length,o=e=>Ee(n,e,e,e,e),s=new Uint32Array(t+28);s.set(i);for(let e=a;e<s.length;e++){let t=s[e-1];e%a===0?t=o(ye(t))^Ce[e/a-1]:a>6&&e%a===4&&(t=o(t)),s[e]=s[e-a]^t}return ie(...r),s}function Te(e,t,n,r,i,a){return e[n<<8&65280|r>>>8&255]^t[i>>>8&65280|a>>>24&255]}function Ee(e,t,n,r,i){return e[t&255|n&65280]|e[r>>>16&255|i>>>16&65280]<<16}function De(e,t,n,r,i){let{sbox2:a,T01:o,T23:s}=Se,c=0;t^=e[c++],n^=e[c++],r^=e[c++],i^=e[c++];let l=e.length/4-2;for(let a=0;a<l;a++){let a=e[c++]^Te(o,s,t,n,r,i),l=e[c++]^Te(o,s,n,r,i,t),u=e[c++]^Te(o,s,r,i,t,n),d=e[c++]^Te(o,s,i,t,n,r);t=a,n=l,r=u,i=d}return{s0:e[c++]^Ee(a,t,n,r,i),s1:e[c++]^Ee(a,n,r,i,t),s2:e[c++]^Ee(a,r,i,t,n),s3:e[c++]^Ee(a,i,t,n,r)}}function Oe(e,t,n,r){z(t,16,`nonce`),z(n);let i=n.length;r=de(i,r),le(n,r);let a=t,o=re(a),s=re(n),c=re(r),{s0:l,s1:u,s2:d,s3:f}=De(e,B(o[0]),B(o[1]),B(o[2]),B(o[3]));for(let t=0;t+4<=s.length;t+=4)c[t+0]=s[t+0]^B(l),c[t+1]=s[t+1]^B(u),c[t+2]=s[t+2]^B(d),c[t+3]=s[t+3]^B(f),_e(a,!1,1),{s0:l,s1:u,s2:d,s3:f}=De(e,B(o[0]),B(o[1]),B(o[2]),B(o[3]));let p=16*Math.floor(s.length/4);if(p<i){let e=new Uint32Array([l,u,d,f]);se(e);let t=ne(e);for(let e=p,a=0;e<i;e++,a++)r[e]=n[e]^t[a];ie(e)}return r}const ke=ue({blockSize:16,nonceLength:16},function(e,t){function n(n,r){if(z(n),r!==void 0&&(z(r),!fe(r)))throw Error(`unaligned destination`);let i=we(e),a=pe(t),o=[i,a];fe(n)||o.push(n=pe(n));let s=Oe(i,a,n,r);return ie(...o),s}return{encrypt:(e,t)=>n(e,t),decrypt:(e,t)=>n(e,t)}});var Ae=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,n){if(t.Or(e),t.Er(n,void 0,`key`),this.iHash=e.create(),typeof this.iHash.update!=`function`)throw Error(`Expected instance of class which extends utils.Hash`);this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let r=this.blockLen,i=new Uint8Array(r);i.set(n.length>r?e.create().update(n).digest():n);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),t.Pr(i)}update(e){return t.Dr(this),this.iHash.update(e),this}digestInto(e){t.Dr(this),t.Ar(e,this),this.finished=!0;let n=e.subarray(0,this.outputLen);this.iHash.digestInto(n),this.oHash.update(n),this.oHash.digestInto(n),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:t,iHash:n,finished:r,destroyed:i,blockLen:a,outputLen:o}=this;return e=e,e.finished=r,e.destroyed=i,e.blockLen=a,e.outputLen=o,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}};const je=(()=>{let e=((e,t,n)=>new Ae(e,t).update(n).digest());return e.create=(e,t)=>new Ae(e,t),e})();function Me(e,n,r,i){t.Or(e);let{c:a,dkLen:o,asyncTick:s}=t.Nr({dkLen:32,asyncTick:10},i);if(t.kr(a,`c`),t.kr(o,`dkLen`),t.kr(s,`asyncTick`),a<1)throw Error(`iterations (c) must be >= 1`);if(o<1)throw Error(`"dkLen" must be >= 1`);if(o>(2**32-1)*e.outputLen)throw Error(`derived key too long`);let c=t.Br(n,`password`),l=t.Br(r,`salt`),u=new Uint8Array(o),d=je.create(e,c);return{c:a,dkLen:o,asyncTick:s,DK:u,PRF:d,PRFSalt:d._cloneInto().update(l)}}function Ne(e,n,r,i,a){return e.destroy(),n.destroy(),i&&i.destroy(),t.Pr(a),r}function Pe(e,n,r,i){let{c:a,dkLen:o,DK:s,PRF:c,PRFSalt:l}=Me(e,n,r,i),u,d=new Uint8Array(4),f=t.Lr(d),p=new Uint8Array(c.outputLen);for(let e=1,t=0;t<o;e++,t+=c.outputLen){let n=s.subarray(t,t+c.outputLen);f.setInt32(0,e,!1),(u=l._cloneInto(u)).update(d).digestInto(p),n.set(p.subarray(0,n.length));for(let e=1;e<a;e++){c._cloneInto(u).update(p).digestInto(p);for(let e=0;e<n.length;e++)n[e]^=p[e]}}return Ne(c,l,s,u,p)}const Fe=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]),V=new Uint32Array(64);var Ie=class extends c{constructor(e){super(64,e,8,!1)}get(){let{A:e,B:t,C:n,D:r,E:i,F:a,G:o,H:s}=this;return[e,t,n,r,i,a,o,s]}set(e,t,n,r,i,a,o,s){this.A=e|0,this.B=t|0,this.C=n|0,this.D=r|0,this.E=i|0,this.F=a|0,this.G=o|0,this.H=s|0}process(e,n){for(let t=0;t<16;t++,n+=4)V[t]=e.getUint32(n,!1);for(let e=16;e<64;e++){let n=V[e-15],r=V[e-2],i=t.Wr(n,7)^t.Wr(n,18)^n>>>3,a=t.Wr(r,17)^t.Wr(r,19)^r>>>10;V[e]=a+V[e-7]+i+V[e-16]|0}let{A:r,B:i,C:a,D:c,E:l,F:u,G:d,H:f}=this;for(let e=0;e<64;e++){let n=t.Wr(l,6)^t.Wr(l,11)^t.Wr(l,25),p=f+n+o(l,u,d)+Fe[e]+V[e]|0,m=(t.Wr(r,2)^t.Wr(r,13)^t.Wr(r,22))+s(r,i,a)|0;f=d,d=u,u=l,l=c+p|0,c=a,a=i,i=r,r=p+m|0}r=r+this.A|0,i=i+this.B|0,a=a+this.C|0,c=c+this.D|0,l=l+this.E|0,u=u+this.F|0,d=d+this.G|0,f=f+this.H|0,this.set(r,i,a,c,l,u,d,f)}roundClean(){t.Pr(V)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),t.Pr(this.buffer)}},Le=class extends Ie{A=l[0]|0;B=l[1]|0;C=l[2]|0;D=l[3]|0;E=l[4]|0;F=l[5]|0;G=l[6]|0;H=l[7]|0;constructor(){super(32)}};const H=t.Ir(()=>new Le,t.Vr(1));function Re(e,n,r,i,a,o){let s=e[n++]^r[i++],c=e[n++]^r[i++],l=e[n++]^r[i++],u=e[n++]^r[i++],d=e[n++]^r[i++],f=e[n++]^r[i++],p=e[n++]^r[i++],m=e[n++]^r[i++],h=e[n++]^r[i++],g=e[n++]^r[i++],_=e[n++]^r[i++],v=e[n++]^r[i++],y=e[n++]^r[i++],ee=e[n++]^r[i++],b=e[n++]^r[i++],x=e[n++]^r[i++],S=s,C=c,w=l,T=u,E=d,D=f,O=p,k=m,A=h,j=g,M=_,N=v,P=y,F=ee,I=b,L=x;for(let e=0;e<8;e+=2)E^=t.Ur(S+P|0,7),A^=t.Ur(E+S|0,9),P^=t.Ur(A+E|0,13),S^=t.Ur(P+A|0,18),j^=t.Ur(D+C|0,7),F^=t.Ur(j+D|0,9),C^=t.Ur(F+j|0,13),D^=t.Ur(C+F|0,18),I^=t.Ur(M+O|0,7),w^=t.Ur(I+M|0,9),O^=t.Ur(w+I|0,13),M^=t.Ur(O+w|0,18),T^=t.Ur(L+N|0,7),k^=t.Ur(T+L|0,9),N^=t.Ur(k+T|0,13),L^=t.Ur(N+k|0,18),C^=t.Ur(S+T|0,7),w^=t.Ur(C+S|0,9),T^=t.Ur(w+C|0,13),S^=t.Ur(T+w|0,18),O^=t.Ur(D+E|0,7),k^=t.Ur(O+D|0,9),E^=t.Ur(k+O|0,13),D^=t.Ur(E+k|0,18),N^=t.Ur(M+j|0,7),A^=t.Ur(N+M|0,9),j^=t.Ur(A+N|0,13),M^=t.Ur(j+A|0,18),P^=t.Ur(L+I|0,7),F^=t.Ur(P+L|0,9),I^=t.Ur(F+P|0,13),L^=t.Ur(I+F|0,18);a[o++]=s+S|0,a[o++]=c+C|0,a[o++]=l+w|0,a[o++]=u+T|0,a[o++]=d+E|0,a[o++]=f+D|0,a[o++]=p+O|0,a[o++]=m+k|0,a[o++]=h+A|0,a[o++]=g+j|0,a[o++]=_+M|0,a[o++]=v+N|0,a[o++]=y+P|0,a[o++]=ee+F|0,a[o++]=b+I|0,a[o++]=x+L|0}function ze(e,t,n,r,i){let a=r+0,o=r+16*i;for(let r=0;r<16;r++)n[o+r]=e[t+(2*i-1)*16+r];for(let r=0;r<i;r++,a+=16,t+=16)Re(n,o,e,t,n,a),r>0&&(o+=16),Re(n,a,e,t+=16,n,o)}function Be(e,n,r){let{N:i,r:a,p:o,dkLen:s,asyncTick:c,maxmem:l,onProgress:u}=t.Nr({dkLen:32,asyncTick:10,maxmem:1024**3+1024},r);if(t.kr(i,`N`),t.kr(a,`r`),t.kr(o,`p`),t.kr(s,`dkLen`),t.kr(c,`asyncTick`),t.kr(l,`maxmem`),u!==void 0&&typeof u!=`function`)throw Error(`progressCb must be a function`);let d=128*a,f=d/4,p=2**32;if(i<=1||i&i-1||i>p)throw Error(`"N" expected a power of 2, and 2^1 <= N <= 2^32`);if(o<1||o>(p-1)*32/d)throw Error(`"p" expected integer 1..((2^32 - 1) * 32) / (128 * r)`);if(s<1||s>(p-1)*32)throw Error(`"dkLen" expected integer 1..(2^32 - 1) * 32`);let m=d*(i+o+1);if(m>l)throw Error(`"maxmem" limit was hit: memUsed(128*r*(N+p+1))=`+m+`, maxmem=`+l);let h=Pe(H,e,n,{c:1,dkLen:d*o}),g=t.Kr(h),_=t.Kr(new Uint8Array(d*i)),v=t.Kr(new Uint8Array(d)),y=()=>{};if(u){let e=2*i*o,t=Math.max(Math.floor(e/1e4),1),n=0;y=()=>{n++,u&&(!(n%t)||n===e)&&u(n/e)}}return{N:i,r:a,p:o,dkLen:s,blockSize32:f,V:_,B32:g,B:h,tmp:v,blockMixCb:y,asyncTick:c}}function Ve(e,n,r,i,a){let o=Pe(H,e,r,{c:1,dkLen:n});return t.Pr(r,i,a),o}async function He(e,n,r){let{N:i,r:a,p:o,dkLen:s,blockSize32:c,V:l,B32:u,B:d,tmp:f,blockMixCb:p,asyncTick:m}=Be(e,n,r);t.Gr(u);for(let e=0;e<o;e++){let n=c*e;for(let e=0;e<c;e++)l[e]=u[n+e];let r=0;await t.jr(i-1,m,()=>{ze(l,r,l,r+=c,a),p()}),ze(l,(i-1)*c,u,n,a),p(),await t.jr(i,m,()=>{let e=(u[n+c-16]&i-1)>>>0;for(let t=0;t<c;t++)f[t]=u[n+t]^l[e*c+t];ze(f,0,u,n,a),p()})}return t.Gr(u),Ve(e,s,d,l,f)}function Ue(e,n){return t.br(T(t.Yr(e.slice(16,32),n))).slice(2)}async function We(e,n,r){let i=t.Hr(32),a=t.Hr(16),o={dklen:32,salt:t.br(i).slice(2),n:262144,r:8,p:1},s=await He(t.Qr(r,`utf8`),i,{N:o.n,r:o.r,p:o.p,dkLen:o.dklen}),c=ke(s.slice(0,16),a.map(e=>e)).encrypt(t.Yr(t.Qr(e),t.Qr(n)));return{id:t.br(t.Hr(16)).slice(2),crypto:{ciphertext:t.br(c).slice(2),cipherparams:{iv:t.br(a).slice(2)},cipher:`aes-128-ctr`,kdf:`scrypt`,kdfparams:o,mac:Ue(s,c)}}}async function Ge(e,n){if(typeof e!=`object`||!e||!(`crypto`in e))throw Error(`Invalid keystore`);let r=e.crypto;if(typeof r!=`object`||!r||!(`kdfparams`in r)||!(`ciphertext`in r)||typeof r.ciphertext!=`string`||!(`mac`in r)||typeof r.mac!=`string`||!(`cipherparams`in r)||typeof r.cipherparams!=`object`||r.cipherparams===null||!(`iv`in r.cipherparams)||typeof r.cipherparams.iv!=`string`)throw Error(`Invalid crypto`);let i=r.kdfparams;if(typeof i!=`object`||!i||!(`n`in i)||typeof i.n!=`number`||!(`r`in i)||typeof i.r!=`number`||!(`p`in i)||typeof i.p!=`number`||!(`dklen`in i)||typeof i.dklen!=`number`||!(`salt`in i)||typeof i.salt!=`string`)throw Error(`Invalid kdfparams`);let a=await He(t.Qr(n,`utf8`),t.Qr(i.salt),{N:i.n,r:i.r,p:i.p,dkLen:i.dklen}),o=t.Qr(r.ciphertext);if(Ue(a,o)!==r.mac)throw Error(`Invalid password`);let s=ke(a.slice(0,16),t.Qr(r.cipherparams.iv)).decrypt(o);return{privateKey:s.slice(0,32),chainCode:s.slice(32)}}var Ke=class e{constructor(e,t){this.autoFinalized=e,this.inputsToSign=t}static from(t){return t instanceof e?t:new e(t?.autoFinalized??!0,t?.inputsToSign?.map(e=>qe.from(e))??[])}},qe=class e{constructor(e,t,n,r,i){this.index=e,this.sighashTypes=t,this.disableTweakSigner=n,this.address=r,this.publicKey=i}static from(n){return n instanceof e?n:new e(n.index,n.sighashTypes,n.disableTweakSigner,n.address,n.publicKey?t.br(n.publicKey):void 0)}};
|
|
4
4
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
5
|
-
const U=(e,n,r)=>t.
|
|
5
|
+
const U=(e,n,r)=>t.Er(e,n,r),Je=t.kr,Ye=t.Mr,W=(...e)=>t.Fr(...e),Xe=e=>t.Rr(e),Ze=t.zr,Qe=e=>t.Hr(e),$e=BigInt(0),et=BigInt(1);function tt(e,t=``){if(typeof e!=`boolean`){let n=t&&`"${t}" `;throw TypeError(n+`expected boolean, got type=`+typeof e)}return e}function nt(e){if(typeof e==`bigint`){if(!ft(e))throw RangeError(`positive bigint expected, got `+e)}else Je(e);return e}function rt(e,t=``){if(typeof e!=`number`){let n=t&&`"${t}" `;throw TypeError(n+`expected number, got type=`+typeof e)}if(!Number.isSafeInteger(e)){let n=t&&`"${t}" `;throw RangeError(n+`expected safe integer, got `+e)}}function it(e){let t=nt(e).toString(16);return t.length&1?`0`+t:t}function at(e){if(typeof e!=`string`)throw TypeError(`hex string expected, got `+typeof e);return e===``?$e:BigInt(`0x`+e)}function ot(e){return at(t.Mr(e))}function st(e){return at(t.Mr(ut(t.Er(e)).reverse()))}function ct(e,n){if(t.kr(n),n===0)throw RangeError(`zero length`);e=nt(e);let r=e.toString(16);if(r.length>n*2)throw RangeError(`number too large`);return t.Rr(r.padStart(n*2,`0`))}function lt(e,t){return ct(e,t).reverse()}function ut(e){return Uint8Array.from(U(e))}function dt(e){if(typeof e!=`string`)throw TypeError(`ascii string expected, got `+typeof e);return Uint8Array.from(e,(t,n)=>{let r=t.charCodeAt(0);if(t.length!==1||r>127)throw RangeError(`string contains non-ASCII character "${e[n]}" with code ${r} at position ${n}`);return r})}const ft=e=>typeof e==`bigint`&&$e<=e;function pt(e,t,n){return ft(e)&&ft(t)&&ft(n)&&t<=e&&e<n}function mt(e,t,n,r){if(!pt(t,n,r))throw RangeError(`expected valid `+e+`: `+n+` <= n < `+r+`, got `+t)}function ht(e){if(e<$e)throw Error(`expected non-negative bigint, got `+e);let t;for(t=0;e>$e;e>>=et,t+=1);return t}const gt=e=>(et<<BigInt(e))-et;function _t(e,n,r){if(t.kr(e,`hashLen`),t.kr(n,`qByteLen`),typeof r!=`function`)throw TypeError(`hmacFn must be a function`);let i=e=>new Uint8Array(e),a=Uint8Array.of(),o=Uint8Array.of(0),s=Uint8Array.of(1),c=i(e),l=i(e),u=0,d=()=>{c.fill(1),l.fill(0),u=0},f=(...e)=>r(l,W(c,...e)),p=(e=a)=>{l=f(o,e),c=f(),e.length!==0&&(l=f(s,e),c=f())},m=()=>{if(u++>=1e3)throw Error(`drbg: tried max amount of iterations`);let e=0,t=[];for(;e<n;){c=f();let n=c.slice();t.push(n),e+=c.length}return W(...t)};return(e,t)=>{d(),p(e);let n;for(;(n=t(m()))===void 0;)p();return d(),n}}function vt(e,t={},n={}){if(Object.prototype.toString.call(e)!==`[object Object]`)throw TypeError(`expected valid options object`);function r(t,n,r){if(!r&&n!==`function`&&!Object.hasOwn(e,t))throw TypeError(`param "${t}" is invalid: expected own property`);let i=e[t];if(r&&i===void 0)return;let a=typeof i;if(a!==n||i===null)throw TypeError(`param "${t}" is invalid: expected ${n}, got ${a}`)}let i=(e,t)=>Object.entries(e).forEach(([e,n])=>r(e,n,t));i(t,!1),i(n,!0)}
|
|
6
6
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
7
7
|
const G=BigInt(0),K=BigInt(1),yt=BigInt(2),bt=BigInt(3),xt=BigInt(4),St=BigInt(5),Ct=BigInt(7),wt=BigInt(8),Tt=BigInt(9),Et=BigInt(16);function q(e,t){if(t<=G)throw Error(`mod: expected positive modulus, got `+t);let n=e%t;return n>=G?n:t+n}function J(e,t,n){if(t<G)throw Error(`pow2: expected non-negative exponent, got `+t);let r=e;for(;t-->G;)r*=r,r%=n;return r}function Dt(e,t){if(e===G)throw Error(`invert: expected non-zero number`);if(t<=G)throw Error(`invert: expected positive modulus, got `+t);let n=q(e,t),r=t,i=G,a=K,o=K,s=G;for(;n!==G;){let e=r/n,t=r-n*e,c=i-o*e,l=a-s*e;r=n,n=t,i=o,a=s,o=c,s=l}if(r!==K)throw Error(`invert: does not exist`);return q(i,t)}function Ot(e,t,n){let r=e;if(!r.eql(r.sqr(t),n))throw Error(`Cannot find square root`)}function kt(e,t){let n=e,r=(n.ORDER+K)/xt,i=n.pow(t,r);return Ot(n,i,t),i}function At(e,t){let n=e,r=(n.ORDER-St)/wt,i=n.mul(t,yt),a=n.pow(i,r),o=n.mul(t,a),s=n.mul(n.mul(o,yt),a),c=n.mul(o,n.sub(s,n.ONE));return Ot(n,c,t),c}function jt(e){let t=Ht(e),n=Mt(e),r=n(t,t.neg(t.ONE)),i=n(t,r),a=n(t,t.neg(r)),o=(e+Ct)/Et;return((e,t)=>{let n=e,s=n.pow(t,o),c=n.mul(s,r),l=n.mul(s,i),u=n.mul(s,a),d=n.eql(n.sqr(c),t),f=n.eql(n.sqr(l),t);s=n.cmov(s,c,d),c=n.cmov(u,l,f);let p=n.eql(n.sqr(c),t),m=n.cmov(s,c,p);return Ot(n,m,t),m})}function Mt(e){if(e<bt)throw Error(`sqrt is not defined for small field`);let t=e-K,n=0;for(;t%yt===G;)t/=yt,n++;let r=yt,i=Ht(e);for(;Rt(i,r)===1;)if(r++>1e3)throw Error(`Cannot find square root: probably non-prime P`);if(n===1)return kt;let a=i.pow(r,t),o=(t+K)/yt;return function(e,r){let i=e;if(i.is0(r))return r;if(Rt(i,r)!==1)throw Error(`Cannot find square root`);let s=n,c=i.mul(i.ONE,a),l=i.pow(r,t),u=i.pow(r,o);for(;!i.eql(l,i.ONE);){if(i.is0(l))return i.ZERO;let e=1,t=i.sqr(l);for(;!i.eql(t,i.ONE);)if(e++,t=i.sqr(t),e===s)throw Error(`Cannot find square root`);let n=K<<BigInt(s-e-1),r=i.pow(c,n);s=e,c=i.sqr(r),l=i.mul(l,c),u=i.mul(u,r)}return u}}function Nt(e){return e%xt===bt?kt:e%wt===St?At:e%Et===Tt?jt(e):Mt(e)}const Pt=[`create`,`isValid`,`is0`,`neg`,`inv`,`sqrt`,`sqr`,`eql`,`add`,`sub`,`mul`,`pow`,`div`,`addN`,`subN`,`mulN`,`sqrN`];function Ft(e){if(vt(e,Pt.reduce((e,t)=>(e[t]=`function`,e),{ORDER:`bigint`,BYTES:`number`,BITS:`number`})),rt(e.BYTES,`BYTES`),rt(e.BITS,`BITS`),e.BYTES<1||e.BITS<1)throw Error(`invalid field: expected BYTES/BITS > 0`);if(e.ORDER<=K)throw Error(`invalid field: expected ORDER > 1, got `+e.ORDER);return e}function It(e,t,n){let r=e;if(n<G)throw Error(`invalid exponent, negatives unsupported`);if(n===G)return r.ONE;if(n===K)return t;let i=r.ONE,a=t;for(;n>G;)n&K&&(i=r.mul(i,a)),a=r.sqr(a),n>>=K;return i}function Lt(e,t,n=!1){let r=e,i=Array(t.length).fill(n?r.ZERO:void 0),a=t.reduce((e,t,n)=>r.is0(t)?e:(i[n]=e,r.mul(e,t)),r.ONE),o=r.inv(a);return t.reduceRight((e,t,n)=>r.is0(t)?e:(i[n]=r.mul(e,i[n]),r.mul(e,t)),o),i}function Rt(e,t){let n=e,r=(n.ORDER-K)/yt,i=n.pow(t,r),a=n.eql(i,n.ONE),o=n.eql(i,n.ZERO),s=n.eql(i,n.neg(n.ONE));if(!a&&!o&&!s)throw Error(`invalid Legendre symbol result`);return a?1:o?0:-1}function zt(e,t){if(t!==void 0&&Je(t),e<=G)throw Error(`invalid n length: expected positive n, got `+e);if(t!==void 0&&t<1)throw Error(`invalid n length: expected positive bit length, got `+t);let n=ht(e);if(t!==void 0&&t<n)throw Error(`invalid n length: expected bit length (${n}) >= n.length (${t})`);let r=t===void 0?n:t;return{nBitLength:r,nByteLength:Math.ceil(r/8)}}const Bt=new WeakMap;var Vt=class{ORDER;BITS;BYTES;isLE;ZERO=G;ONE=K;_lengths;_mod;constructor(e,t={}){if(e<=K)throw Error(`invalid field: expected ORDER > 1, got `+e);let n;this.isLE=!1,typeof t==`object`&&t&&(typeof t.BITS==`number`&&(n=t.BITS),typeof t.sqrt==`function`&&Object.defineProperty(this,"sqrt",{value:t.sqrt,enumerable:!0}),typeof t.isLE==`boolean`&&(this.isLE=t.isLE),t.allowedLengths&&(this._lengths=Object.freeze(t.allowedLengths.slice())),typeof t.modFromBytes==`boolean`&&(this._mod=t.modFromBytes));let{nBitLength:r,nByteLength:i}=zt(e,n);if(i>2048)throw Error(`invalid field: expected ORDER of <= 2048 bytes`);this.ORDER=e,this.BITS=r,this.BYTES=i,Object.freeze(this)}create(e){return q(e,this.ORDER)}isValid(e){if(typeof e!=`bigint`)throw TypeError(`invalid field element: expected bigint, got `+typeof e);return G<=e&&e<this.ORDER}is0(e){return e===G}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&K)===K}neg(e){return q(-e,this.ORDER)}eql(e,t){return e===t}sqr(e){return q(e*e,this.ORDER)}add(e,t){return q(e+t,this.ORDER)}sub(e,t){return q(e-t,this.ORDER)}mul(e,t){return q(e*t,this.ORDER)}pow(e,t){return It(this,e,t)}div(e,t){return q(e*Dt(t,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,t){return e+t}subN(e,t){return e-t}mulN(e,t){return e*t}inv(e){return Dt(e,this.ORDER)}sqrt(e){let t=Bt.get(this);return t||Bt.set(this,t=Nt(this.ORDER)),t(this,e)}toBytes(e){return this.isLE?lt(e,this.BYTES):ct(e,this.BYTES)}fromBytes(e,t=!1){U(e);let{_lengths:n,BYTES:r,isLE:i,ORDER:a,_mod:o}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>r)throw Error(`Field.fromBytes: expected `+n+` bytes, got `+e.length);let t=new Uint8Array(r);t.set(e,i?0:t.length-e.length),e=t}if(e.length!==r)throw Error(`Field.fromBytes: expected `+r+` bytes, got `+e.length);let s=i?st(e):ot(e);if(o&&(s=q(s,a)),!t&&!this.isValid(s))throw Error(`invalid field element: outside of range 0..ORDER`);return s}invertBatch(e){return Lt(this,e)}cmov(e,t,n){return tt(n,`condition`),n?t:e}};Object.freeze(Vt.prototype);function Ht(e,t={}){return new Vt(e,t)}function Ut(e){if(typeof e!=`bigint`)throw Error(`field order must be bigint`);if(e<=K)throw Error(`field order must be greater than 1`);let t=ht(e-K);return Math.ceil(t/8)}function Wt(e){let t=Ut(e);return t+Math.ceil(t/2)}function Gt(e,t,n=!1){U(e);let r=e.length,i=Ut(t),a=Math.max(Wt(t),16);if(r<a||r>1024)throw Error(`expected `+a+`-1024 bytes of input, got `+r);let o=q(n?st(e):ot(e),t-K)+K;return n?lt(o,i):ct(o,i)}
|
|
8
8
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
9
9
|
const Kt=BigInt(0),qt=BigInt(1);function Jt(e,t){let n=t.negate();return e?n:t}function Yt(e,t){let n=Lt(e.Fp,t.map(e=>e.Z));return t.map((t,r)=>e.fromAffine(t.toAffine(n[r])))}function Xt(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw Error(`invalid window size, expected [1..`+t+`], got W=`+e)}function Zt(e,t){Xt(e,t);let n=Math.ceil(t/e)+1,r=2**(e-1),i=2**e;return{windows:n,windowSize:r,mask:gt(e),maxNumber:i,shiftBy:BigInt(e)}}function Qt(e,t,n){let{windowSize:r,mask:i,maxNumber:a,shiftBy:o}=n,s=Number(e&i),c=e>>o;s>r&&(s-=a,c+=qt);let l=t*r,u=l+Math.abs(s)-1,d=s===0,f=s<0,p=t%2!=0;return{nextN:c,offset:u,isZero:d,isNeg:f,isNegF:p,offsetF:l}}const $t=new WeakMap,en=new WeakMap;function tn(e){return en.get(e)||1}function nn(e){if(e!==Kt)throw Error(`invalid wNAF`)}var rn=class{BASE;ZERO;Fn;bits;constructor(e,t){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=t}_unsafeLadder(e,t,n=this.ZERO){let r=e;for(;t>Kt;)t&qt&&(n=n.add(r)),r=r.double(),t>>=qt;return n}precomputeWindow(e,t){let{windows:n,windowSize:r}=Zt(t,this.bits),i=[],a=e,o=a;for(let e=0;e<n;e++){o=a,i.push(o);for(let e=1;e<r;e++)o=o.add(a),i.push(o);a=o.double()}return i}wNAF(e,t,n){if(!this.Fn.isValid(n))throw Error(`invalid scalar`);let r=this.ZERO,i=this.BASE,a=Zt(e,this.bits);for(let e=0;e<a.windows;e++){let{nextN:o,offset:s,isZero:c,isNeg:l,isNegF:u,offsetF:d}=Qt(n,e,a);n=o,c?i=i.add(Jt(u,t[d])):r=r.add(Jt(l,t[s]))}return nn(n),{p:r,f:i}}wNAFUnsafe(e,t,n,r=this.ZERO){let i=Zt(e,this.bits);for(let e=0;e<i.windows&&n!==Kt;e++){let{nextN:a,offset:o,isZero:s,isNeg:c}=Qt(n,e,i);if(n=a,!s){let e=t[o];r=r.add(c?e.negate():e)}}return nn(n),r}getPrecomputes(e,t,n){let r=$t.get(t);return r||(r=this.precomputeWindow(t,e),e!==1&&(typeof n==`function`&&(r=n(r)),$t.set(t,r))),r}cached(e,t,n){let r=tn(e);return this.wNAF(r,this.getPrecomputes(r,e,n),t)}unsafe(e,t,n,r){let i=tn(e);return i===1?this._unsafeLadder(e,t,r):this.wNAFUnsafe(i,this.getPrecomputes(i,e,n),t,r)}createCache(e,t){Xt(t,this.bits),en.set(e,t),$t.delete(e)}hasCache(e){return tn(e)!==1}};function an(e,t,n,r){let i=t,a=e.ZERO,o=e.ZERO;for(;n>Kt||r>Kt;)n&qt&&(a=a.add(i)),r&qt&&(o=o.add(i)),i=i.double(),n>>=qt,r>>=qt;return{p1:a,p2:o}}function on(e,t,n){if(t){if(t.ORDER!==e)throw Error(`Field.ORDER must match order: Fp == p, Fn == n`);return Ft(t),t}else return Ht(e,{isLE:n})}function sn(e,t,n={},r){if(r===void 0&&(r=e===`edwards`),!t||typeof t!=`object`)throw Error(`expected valid ${e} CURVE object`);for(let e of[`p`,`n`,`h`]){let n=t[e];if(!(typeof n==`bigint`&&n>Kt))throw Error(`CURVE.${e} must be positive bigint`)}let i=on(t.p,n.Fp,r),a=on(t.n,n.Fn,r),o=[`Gx`,`Gy`,`a`,e===`weierstrass`?`b`:`d`];for(let e of o)if(!i.isValid(t[e]))throw Error(`CURVE.${e} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:i,Fn:a}}function cn(e,t){return function(n){let r=e(n);return{secretKey:r,publicKey:t(r)}}}
|
|
10
10
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
11
|
-
const ln=(e,t)=>(e+(e>=0?t:-t)/mn)/t;function un(e,t,n){mt(`scalar`,e,X,n);let[[r,i],[a,o]]=t,s=ln(o*e,n),c=ln(-i*e,n),l=e-s*r-c*a,u=-s*i-c*o,d=l<X,f=u<X;d&&(l=-l),f&&(u=-u);let p=gt(Math.ceil(ht(n)/2))+pn;if(l<X||l>=p||u<X||u>=p)throw Error(`splitScalar (endomorphism): failed for k`);return{k1neg:d,k1:l,k2neg:f,k2:u}}function dn(e){if(![`compact`,`recovered`,`der`].includes(e))throw Error(`Signature format must be "compact", "recovered", or "der"`);return e}function fn(e,t){vt(e);let n={};for(let r of Object.keys(t))n[r]=e[r]===void 0?t[r]:e[r];return tt(n.lowS,`lowS`),tt(n.prehash,`prehash`),n.format!==void 0&&dn(n.format),n}const Y={Err:class extends Error{constructor(e=``){super(e)}},_tlv:{encode:(e,t)=>{let{Err:n}=Y;if(rt(e,`tag`),e<0||e>255)throw new n(`tlv.encode: wrong tag`);if(typeof t!=`string`)throw TypeError(`"data" expected string, got type=`+typeof t);if(t.length&1)throw new n(`tlv.encode: unpadded data`);let r=t.length/2,i=it(r);if(i.length/2&128)throw new n(`tlv.encode: long form length too big`);let a=r>127?it(i.length/2|128):``;return it(e)+a+i+t},decode(e,t){let{Err:n}=Y;t=U(t,void 0,`DER data`);let r=0;if(e<0||e>255)throw new n(`tlv.encode: wrong tag`);if(t.length<2||t[r++]!==e)throw new n(`tlv.decode: wrong tlv`);let i=t[r++],a=!!(i&128),o=0;if(!a)o=i;else{let e=i&127;if(!e)throw new n(`tlv.decode(long): indefinite length not supported`);if(e>4)throw new n(`tlv.decode(long): byte length is too big`);let a=t.subarray(r,r+e);if(a.length!==e)throw new n(`tlv.decode: length bytes not complete`);if(a[0]===0)throw new n(`tlv.decode(long): zero leftmost byte`);for(let e of a)o=o<<8|e;if(r+=e,o<128)throw new n(`tlv.decode(long): not minimal encoding`)}let s=t.subarray(r,r+o);if(s.length!==o)throw new n(`tlv.decode: wrong value length`);return{v:s,l:t.subarray(r+o)}}},_int:{encode(e){let{Err:t}=Y;if(nt(e),e<X)throw new t(`integer: negative integers are not allowed`);let n=it(e);if(Number.parseInt(n[0],16)&8&&(n=`00`+n),n.length&1)throw new t(`unexpected DER parsing assertion: unpadded hex`);return n},decode(e){let{Err:t}=Y;if(e.length<1)throw new t(`invalid signature integer: empty`);if(e[0]&128)throw new t(`invalid signature integer: negative`);if(e.length>1&&e[0]===0&&!(e[1]&128))throw new t(`invalid signature integer: unnecessary leading zero`);return ot(e)}},toSig(e){let{Err:t,_int:n,_tlv:r}=Y,i=U(e,void 0,`signature`),{v:a,l:o}=r.decode(48,i);if(o.length)throw new t(`invalid signature: left bytes after parsing`);let{v:s,l:c}=r.decode(2,a),{v:l,l:u}=r.decode(2,c);if(u.length)throw new t(`invalid signature: left bytes after parsing`);return{r:n.decode(s),s:n.decode(l)}},hexFromSig(e){let{_tlv:t,_int:n}=Y,r=t.encode(2,n.encode(e.r))+t.encode(2,n.encode(e.s));return t.encode(48,r)}};Object.freeze(Y._tlv),Object.freeze(Y._int),Object.freeze(Y);const X=BigInt(0),pn=BigInt(1),mn=BigInt(2),hn=BigInt(3),gn=BigInt(4);function _n(e,t={}){let n=sn(`weierstrass`,e,t),r=n.Fp,i=n.Fn,a=n.CURVE,{h:o,n:s}=a;vt(t,{},{allowInfinityPoint:`boolean`,clearCofactor:`function`,isTorsionFree:`function`,fromBytes:`function`,toBytes:`function`,endo:`object`});let{endo:c,allowInfinityPoint:l}=t;if(c&&(!r.is0(a.a)||typeof c.beta!=`bigint`||!Array.isArray(c.basises)))throw Error(`invalid endo: expected "beta": bigint and "basises": array`);let u=yn(r,i);function d(){if(!r.isOdd)throw Error(`compression is not supported: Field does not have .isOdd()`)}function f(e,t,n){if(l&&t.is0())return Uint8Array.of(0);let{x:i,y:a}=t.toAffine(),o=r.toBytes(i);return tt(n,`isCompressed`),n?(d(),W(vn(!r.isOdd(a)),o)):W(Uint8Array.of(4),o,r.toBytes(a))}function p(e){U(e,void 0,`Point`);let{publicKey:t,publicKeyUncompressed:n}=u,i=e.length,a=e[0],o=e.subarray(1);if(l&&i===1&&a===0)return{x:r.ZERO,y:r.ZERO};if(i===t&&(a===2||a===3)){let e=r.fromBytes(o);if(!r.isValid(e))throw Error(`bad point: is not on curve, wrong x`);let t=g(e),n;try{n=r.sqrt(t)}catch(e){let t=e instanceof Error?`: `+e.message:``;throw Error(`bad point: is not on curve, sqrt error`+t)}d();let i=r.isOdd(n);return(a&1)==1!==i&&(n=r.neg(n)),{x:e,y:n}}else if(i===n&&a===4){let e=r.BYTES,t=r.fromBytes(o.subarray(0,e)),n=r.fromBytes(o.subarray(e,e*2));if(!_(t,n))throw Error(`bad point: is not on curve`);return{x:t,y:n}}else throw Error(`bad point: got length ${i}, expected compressed=${t} or uncompressed=${n}`)}let m=t.toBytes===void 0?f:t.toBytes,h=t.fromBytes===void 0?p:t.fromBytes;function g(e){let t=r.sqr(e),n=r.mul(t,e);return r.add(r.add(n,r.mul(e,a.a)),a.b)}function _(e,t){let n=r.sqr(t),i=g(e);return r.eql(n,i)}if(!_(a.Gx,a.Gy))throw Error(`bad curve params: generator point`);let v=r.mul(r.pow(a.a,hn),gn),y=r.mul(r.sqr(a.b),BigInt(27));if(r.is0(r.add(v,y)))throw Error(`bad curve params: a or b`);function ee(e,t,n=!1){if(!r.isValid(t)||n&&r.is0(t))throw Error(`bad point coordinate ${e}`);return t}function b(e){if(!(e instanceof C))throw Error(`Weierstrass Point expected`)}function x(e){if(!c||!c.basises)throw Error(`no endo`);return un(e,c.basises,i.ORDER)}function S(e,t,n,i,a){return n=new C(r.mul(n.X,e),n.Y,n.Z),t=Jt(i,t),n=Jt(a,n),t.add(n)}class C{static BASE=new C(a.Gx,a.Gy,r.ONE);static ZERO=new C(r.ZERO,r.ONE,r.ZERO);static Fp=r;static Fn=i;X;Y;Z;constructor(e,t,n){this.X=ee(`x`,e),this.Y=ee(`y`,t,!0),this.Z=ee(`z`,n),Object.freeze(this)}static CURVE(){return a}static fromAffine(e){let{x:t,y:n}=e||{};if(!e||!r.isValid(t)||!r.isValid(n))throw Error(`invalid affine point`);if(e instanceof C)throw Error(`projective point not allowed`);return r.is0(t)&&r.is0(n)?C.ZERO:new C(t,n,r.ONE)}static fromBytes(e){let t=C.fromAffine(h(U(e,void 0,`point`)));return t.assertValidity(),t}static fromHex(e){return C.fromBytes(Xe(e))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(e=8,t=!0){return T.createCache(this,e),t||this.multiply(hn),this}assertValidity(){let e=this;if(e.is0()){if(t.allowInfinityPoint&&r.is0(e.X)&&r.eql(e.Y,r.ONE)&&r.is0(e.Z))return;throw Error(`bad point: ZERO`)}let{x:n,y:i}=e.toAffine();if(!r.isValid(n)||!r.isValid(i))throw Error(`bad point: x or y not field elements`);if(!_(n,i))throw Error(`bad point: equation left != right`);if(!e.isTorsionFree())throw Error(`bad point: not in prime-order subgroup`)}hasEvenY(){let{y:e}=this.toAffine();if(!r.isOdd)throw Error(`Field doesn't support isOdd`);return!r.isOdd(e)}equals(e){b(e);let{X:t,Y:n,Z:i}=this,{X:a,Y:o,Z:s}=e,c=r.eql(r.mul(t,s),r.mul(a,i)),l=r.eql(r.mul(n,s),r.mul(o,i));return c&&l}negate(){return new C(this.X,r.neg(this.Y),this.Z)}double(){let{a:e,b:t}=a,n=r.mul(t,hn),{X:i,Y:o,Z:s}=this,c=r.ZERO,l=r.ZERO,u=r.ZERO,d=r.mul(i,i),f=r.mul(o,o),p=r.mul(s,s),m=r.mul(i,o);return m=r.add(m,m),u=r.mul(i,s),u=r.add(u,u),c=r.mul(e,u),l=r.mul(n,p),l=r.add(c,l),c=r.sub(f,l),l=r.add(f,l),l=r.mul(c,l),c=r.mul(m,c),u=r.mul(n,u),p=r.mul(e,p),m=r.sub(d,p),m=r.mul(e,m),m=r.add(m,u),u=r.add(d,d),d=r.add(u,d),d=r.add(d,p),d=r.mul(d,m),l=r.add(l,d),p=r.mul(o,s),p=r.add(p,p),d=r.mul(p,m),c=r.sub(c,d),u=r.mul(p,f),u=r.add(u,u),u=r.add(u,u),new C(c,l,u)}add(e){b(e);let{X:t,Y:n,Z:i}=this,{X:o,Y:s,Z:c}=e,l=r.ZERO,u=r.ZERO,d=r.ZERO,f=a.a,p=r.mul(a.b,hn),m=r.mul(t,o),h=r.mul(n,s),g=r.mul(i,c),_=r.add(t,n),v=r.add(o,s);_=r.mul(_,v),v=r.add(m,h),_=r.sub(_,v),v=r.add(t,i);let y=r.add(o,c);return v=r.mul(v,y),y=r.add(m,g),v=r.sub(v,y),y=r.add(n,i),l=r.add(s,c),y=r.mul(y,l),l=r.add(h,g),y=r.sub(y,l),d=r.mul(f,v),l=r.mul(p,g),d=r.add(l,d),l=r.sub(h,d),d=r.add(h,d),u=r.mul(l,d),h=r.add(m,m),h=r.add(h,m),g=r.mul(f,g),v=r.mul(p,v),h=r.add(h,g),g=r.sub(m,g),g=r.mul(f,g),v=r.add(v,g),m=r.mul(h,v),u=r.add(u,m),m=r.mul(y,v),l=r.mul(_,l),l=r.sub(l,m),m=r.mul(_,h),d=r.mul(y,d),d=r.add(d,m),new C(l,u,d)}subtract(e){return b(e),this.add(e.negate())}is0(){return this.equals(C.ZERO)}multiply(e){let{endo:n}=t;if(!i.isValidNot0(e))throw RangeError(`invalid scalar: out of range`);let r,a,o=e=>T.cached(this,e,e=>Yt(C,e));if(n){let{k1neg:t,k1:i,k2neg:s,k2:c}=x(e),{p:l,f:u}=o(i),{p:d,f}=o(c);a=u.add(f),r=S(n.beta,l,d,t,s)}else{let{p:t,f:n}=o(e);r=t,a=n}return Yt(C,[r,a])[0]}multiplyUnsafe(e){let{endo:n}=t,r=this,a=e;if(!i.isValid(a))throw RangeError(`invalid scalar: out of range`);if(a===X||r.is0())return C.ZERO;if(a===pn)return r;if(T.hasCache(this))return this.multiply(a);if(n){let{k1neg:e,k1:t,k2neg:i,k2:o}=x(a),{p1:s,p2:c}=an(C,r,t,o);return S(n.beta,s,c,e,i)}else return T.unsafe(r,a)}toAffine(e){let t=this,n=e,{X:i,Y:a,Z:o}=t;if(r.eql(o,r.ONE))return{x:i,y:a};let s=t.is0();n??=s?r.ONE:r.inv(o);let c=r.mul(i,n),l=r.mul(a,n),u=r.mul(o,n);if(s)return{x:r.ZERO,y:r.ZERO};if(!r.eql(u,r.ONE))throw Error(`invZ was invalid`);return{x:c,y:l}}isTorsionFree(){let{isTorsionFree:e}=t;return o===pn?!0:e?e(C,this):T.unsafe(this,s).is0()}clearCofactor(){let{clearCofactor:e}=t;return o===pn?this:e?e(C,this):this.multiplyUnsafe(o)}isSmallOrder(){return o===pn?this.is0():this.clearCofactor().is0()}toBytes(e=!0){return tt(e,`isCompressed`),this.assertValidity(),m(C,this,e)}toHex(e=!0){return Ye(this.toBytes(e))}toString(){return`<Point ${this.is0()?`ZERO`:this.toHex()}>`}}let w=i.BITS,T=new rn(C,t.endo?Math.ceil(w/2):w);return w>=8&&C.BASE.precompute(8),Object.freeze(C.prototype),Object.freeze(C),C}function vn(e){return Uint8Array.of(e?2:3)}function yn(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function bn(e,t={}){let{Fn:n}=e,r=t.randomBytes===void 0?Qe:t.randomBytes,i=Object.assign(yn(e.Fp,n),{seed:Math.max(Wt(n.ORDER),16)});function a(e){try{let t=n.fromBytes(e);return n.isValidNot0(t)}catch{return!1}}function o(t,n){let{publicKey:r,publicKeyUncompressed:a}=i;try{let i=t.length;return n===!0&&i!==r||n===!1&&i!==a?!1:!!e.fromBytes(t)}catch{return!1}}function s(e){return e=e===void 0?r(i.seed):e,Gt(U(e,i.seed,`seed`),n.ORDER)}function c(t,r=!0){return e.BASE.multiply(n.fromBytes(t)).toBytes(r)}function l(e){let{secretKey:t,publicKey:r,publicKeyUncompressed:a}=i,o=n._lengths;if(!Ze(e))return;let s=U(e,void 0,`key`).length,c=s===r||s===a,l=s===t||!!o?.includes(s);if(!(c&&l))return c}function u(t,r,i=!0){if(l(t)===!0)throw Error(`first arg must be private key`);if(l(r)===!1)throw Error(`second arg must be public key`);let a=n.fromBytes(t);return e.fromBytes(r).multiply(a).toBytes(i)}let d={isValidSecretKey:a,isValidPublicKey:o,randomSecretKey:s},f=cn(s,c);return Object.freeze(d),Object.freeze(i),Object.freeze({getPublicKey:c,getSharedSecret:u,keygen:f,Point:e,utils:d,lengths:i})}function xn(e,n,r={}){let i=n;t.Dr(i),vt(r,{},{hmac:`function`,lowS:`boolean`,randomBytes:`function`,bits2int:`function`,bits2int_modN:`function`}),r=Object.assign({},r);let a=r.randomBytes===void 0?Qe:r.randomBytes,o=r.hmac===void 0?(e,t)=>je(i,e,t):r.hmac,{Fp:s,Fn:c}=e,{ORDER:l,BITS:u}=c,{keygen:d,getPublicKey:f,getSharedSecret:p,utils:m,lengths:h}=bn(e,r),g={prehash:!0,lowS:typeof r.lowS!=`boolean`||r.lowS,format:`compact`,extraEntropy:!1},_=l*mn+pn<s.ORDER;function v(e){return e>l>>pn}function y(e,t){if(!c.isValidNot0(t))throw Error(`invalid signature ${e}: out of range 1..Point.Fn.ORDER`);return t}function ee(){if(_)throw Error(`"recovered" sig type is not supported for cofactor >2 curves`)}function b(e,t){dn(t);let n=h.signature;return U(e,t===`compact`?n:t===`recovered`?n+1:void 0)}class x{r;s;recovery;constructor(e,t,n){if(this.r=y(`r`,e),this.s=y(`s`,t),n!=null){if(ee(),![0,1,2,3].includes(n))throw Error(`invalid recovery id`);this.recovery=n}Object.freeze(this)}static fromBytes(e,t=g.format){b(e,t);let n;if(t===`der`){let{r:t,s:n}=Y.toSig(U(e));return new x(t,n)}t===`recovered`&&(n=e[0],t=`compact`,e=e.subarray(1));let r=h.signature/2,i=e.subarray(0,r),a=e.subarray(r,r*2);return new x(c.fromBytes(i),c.fromBytes(a),n)}static fromHex(e,t){return this.fromBytes(Xe(e),t)}assertRecovery(){let{recovery:e}=this;if(e==null)throw Error(`invalid recovery id: must be present`);return e}addRecoveryBit(e){return new x(this.r,this.s,e)}recoverPublicKey(t){let{r:n,s:r}=this,i=this.assertRecovery(),a=i===2||i===3?n+l:n;if(!s.isValid(a))throw Error(`invalid recovery id: sig.r+curve.n != R.x`);let o=s.toBytes(a),u=e.fromBytes(W(vn((i&1)==0),o)),d=c.inv(a),f=C(U(t,void 0,`msgHash`)),p=c.create(-f*d),m=c.create(r*d),h=e.BASE.multiplyUnsafe(p).add(u.multiplyUnsafe(m));if(h.is0())throw Error(`invalid recovery: point at infinify`);return h.assertValidity(),h}hasHighS(){return v(this.s)}toBytes(e=g.format){if(dn(e),e===`der`)return Xe(Y.hexFromSig(this));let{r:t,s:n}=this,r=c.toBytes(t),i=c.toBytes(n);return e===`recovered`?(ee(),W(Uint8Array.of(this.assertRecovery()),r,i)):W(r,i)}toHex(e){return Ye(this.toBytes(e))}}Object.freeze(x.prototype),Object.freeze(x);let S=r.bits2int===void 0?function(e){if(e.length>8192)throw Error(`input is too large`);let t=ot(e),n=e.length*8-u;return n>0?t>>BigInt(n):t}:r.bits2int,C=r.bits2int_modN===void 0?function(e){return c.create(S(e))}:r.bits2int_modN,w=gt(u);function T(e){return mt(`num < 2^`+u,e,X,w),c.toBytes(e)}function E(e,t){return U(e,void 0,`message`),t?U(i(e),void 0,`prehashed message`):e}function D(t,n,r){let{lowS:i,prehash:o,extraEntropy:s}=fn(r,g);t=E(t,o);let l=C(t),u=c.fromBytes(n);if(!c.isValidNot0(u))throw Error(`invalid private key`);let d=[T(u),T(l)];if(s!=null&&s!==!1){let e=s===!0?a(h.secretKey):s;d.push(U(e,void 0,`extraEntropy`))}let f=W(...d),p=l;function m(t){let n=S(t);if(!c.isValidNot0(n))return;let r=c.inv(n),a=e.BASE.multiply(n).toAffine(),o=c.create(a.x);if(o===X)return;let s=c.create(r*c.create(p+o*u));if(s===X)return;let l=(a.x===o?0:2)|Number(a.y&pn),d=s;return i&&v(s)&&(d=c.neg(s),l^=1),new x(o,d,_?void 0:l)}return{seed:f,k2sig:m}}function O(e,t,n={}){let{seed:r,k2sig:a}=D(e,t,n);return _t(i.outputLen,c.BYTES,o)(r,a).toBytes(n.format)}function k(t,n,r,i={}){let{lowS:a,prehash:o,format:s}=fn(i,g);if(r=U(r,void 0,`publicKey`),n=E(n,o),!Ze(t)){let e=t instanceof x?`, use sig.toBytes()`:``;throw Error(`verify expects Uint8Array signature`+e)}b(t,s);try{let i=x.fromBytes(t,s),o=e.fromBytes(r);if(a&&i.hasHighS())return!1;let{r:l,s:u}=i,d=C(n),f=c.inv(u),p=c.create(d*f),m=c.create(l*f),h=e.BASE.multiplyUnsafe(p).add(o.multiplyUnsafe(m));return!h.is0()&&c.create(h.x)===l}catch{return!1}}function A(e,t,n={}){let{prehash:r}=fn(n,g);return t=E(t,r),x.fromBytes(e,`recovered`).recoverPublicKey(t).toBytes()}return Object.freeze({keygen:d,getPublicKey:f,getSharedSecret:p,utils:m,lengths:h,Point:e,sign:O,verify:k,recoverPublicKey:A,Signature:x,hash:i})}
|
|
11
|
+
const ln=(e,t)=>(e+(e>=0?t:-t)/mn)/t;function un(e,t,n){mt(`scalar`,e,X,n);let[[r,i],[a,o]]=t,s=ln(o*e,n),c=ln(-i*e,n),l=e-s*r-c*a,u=-s*i-c*o,d=l<X,f=u<X;d&&(l=-l),f&&(u=-u);let p=gt(Math.ceil(ht(n)/2))+pn;if(l<X||l>=p||u<X||u>=p)throw Error(`splitScalar (endomorphism): failed for k`);return{k1neg:d,k1:l,k2neg:f,k2:u}}function dn(e){if(![`compact`,`recovered`,`der`].includes(e))throw Error(`Signature format must be "compact", "recovered", or "der"`);return e}function fn(e,t){vt(e);let n={};for(let r of Object.keys(t))n[r]=e[r]===void 0?t[r]:e[r];return tt(n.lowS,`lowS`),tt(n.prehash,`prehash`),n.format!==void 0&&dn(n.format),n}const Y={Err:class extends Error{constructor(e=``){super(e)}},_tlv:{encode:(e,t)=>{let{Err:n}=Y;if(rt(e,`tag`),e<0||e>255)throw new n(`tlv.encode: wrong tag`);if(typeof t!=`string`)throw TypeError(`"data" expected string, got type=`+typeof t);if(t.length&1)throw new n(`tlv.encode: unpadded data`);let r=t.length/2,i=it(r);if(i.length/2&128)throw new n(`tlv.encode: long form length too big`);let a=r>127?it(i.length/2|128):``;return it(e)+a+i+t},decode(e,t){let{Err:n}=Y;t=U(t,void 0,`DER data`);let r=0;if(e<0||e>255)throw new n(`tlv.encode: wrong tag`);if(t.length<2||t[r++]!==e)throw new n(`tlv.decode: wrong tlv`);let i=t[r++],a=!!(i&128),o=0;if(!a)o=i;else{let e=i&127;if(!e)throw new n(`tlv.decode(long): indefinite length not supported`);if(e>4)throw new n(`tlv.decode(long): byte length is too big`);let a=t.subarray(r,r+e);if(a.length!==e)throw new n(`tlv.decode: length bytes not complete`);if(a[0]===0)throw new n(`tlv.decode(long): zero leftmost byte`);for(let e of a)o=o<<8|e;if(r+=e,o<128)throw new n(`tlv.decode(long): not minimal encoding`)}let s=t.subarray(r,r+o);if(s.length!==o)throw new n(`tlv.decode: wrong value length`);return{v:s,l:t.subarray(r+o)}}},_int:{encode(e){let{Err:t}=Y;if(nt(e),e<X)throw new t(`integer: negative integers are not allowed`);let n=it(e);if(Number.parseInt(n[0],16)&8&&(n=`00`+n),n.length&1)throw new t(`unexpected DER parsing assertion: unpadded hex`);return n},decode(e){let{Err:t}=Y;if(e.length<1)throw new t(`invalid signature integer: empty`);if(e[0]&128)throw new t(`invalid signature integer: negative`);if(e.length>1&&e[0]===0&&!(e[1]&128))throw new t(`invalid signature integer: unnecessary leading zero`);return ot(e)}},toSig(e){let{Err:t,_int:n,_tlv:r}=Y,i=U(e,void 0,`signature`),{v:a,l:o}=r.decode(48,i);if(o.length)throw new t(`invalid signature: left bytes after parsing`);let{v:s,l:c}=r.decode(2,a),{v:l,l:u}=r.decode(2,c);if(u.length)throw new t(`invalid signature: left bytes after parsing`);return{r:n.decode(s),s:n.decode(l)}},hexFromSig(e){let{_tlv:t,_int:n}=Y,r=t.encode(2,n.encode(e.r))+t.encode(2,n.encode(e.s));return t.encode(48,r)}};Object.freeze(Y._tlv),Object.freeze(Y._int),Object.freeze(Y);const X=BigInt(0),pn=BigInt(1),mn=BigInt(2),hn=BigInt(3),gn=BigInt(4);function _n(e,t={}){let n=sn(`weierstrass`,e,t),r=n.Fp,i=n.Fn,a=n.CURVE,{h:o,n:s}=a;vt(t,{},{allowInfinityPoint:`boolean`,clearCofactor:`function`,isTorsionFree:`function`,fromBytes:`function`,toBytes:`function`,endo:`object`});let{endo:c,allowInfinityPoint:l}=t;if(c&&(!r.is0(a.a)||typeof c.beta!=`bigint`||!Array.isArray(c.basises)))throw Error(`invalid endo: expected "beta": bigint and "basises": array`);let u=yn(r,i);function d(){if(!r.isOdd)throw Error(`compression is not supported: Field does not have .isOdd()`)}function f(e,t,n){if(l&&t.is0())return Uint8Array.of(0);let{x:i,y:a}=t.toAffine(),o=r.toBytes(i);return tt(n,`isCompressed`),n?(d(),W(vn(!r.isOdd(a)),o)):W(Uint8Array.of(4),o,r.toBytes(a))}function p(e){U(e,void 0,`Point`);let{publicKey:t,publicKeyUncompressed:n}=u,i=e.length,a=e[0],o=e.subarray(1);if(l&&i===1&&a===0)return{x:r.ZERO,y:r.ZERO};if(i===t&&(a===2||a===3)){let e=r.fromBytes(o);if(!r.isValid(e))throw Error(`bad point: is not on curve, wrong x`);let t=g(e),n;try{n=r.sqrt(t)}catch(e){let t=e instanceof Error?`: `+e.message:``;throw Error(`bad point: is not on curve, sqrt error`+t)}d();let i=r.isOdd(n);return(a&1)==1!==i&&(n=r.neg(n)),{x:e,y:n}}else if(i===n&&a===4){let e=r.BYTES,t=r.fromBytes(o.subarray(0,e)),n=r.fromBytes(o.subarray(e,e*2));if(!_(t,n))throw Error(`bad point: is not on curve`);return{x:t,y:n}}else throw Error(`bad point: got length ${i}, expected compressed=${t} or uncompressed=${n}`)}let m=t.toBytes===void 0?f:t.toBytes,h=t.fromBytes===void 0?p:t.fromBytes;function g(e){let t=r.sqr(e),n=r.mul(t,e);return r.add(r.add(n,r.mul(e,a.a)),a.b)}function _(e,t){let n=r.sqr(t),i=g(e);return r.eql(n,i)}if(!_(a.Gx,a.Gy))throw Error(`bad curve params: generator point`);let v=r.mul(r.pow(a.a,hn),gn),y=r.mul(r.sqr(a.b),BigInt(27));if(r.is0(r.add(v,y)))throw Error(`bad curve params: a or b`);function ee(e,t,n=!1){if(!r.isValid(t)||n&&r.is0(t))throw Error(`bad point coordinate ${e}`);return t}function b(e){if(!(e instanceof C))throw Error(`Weierstrass Point expected`)}function x(e){if(!c||!c.basises)throw Error(`no endo`);return un(e,c.basises,i.ORDER)}function S(e,t,n,i,a){return n=new C(r.mul(n.X,e),n.Y,n.Z),t=Jt(i,t),n=Jt(a,n),t.add(n)}class C{static BASE=new C(a.Gx,a.Gy,r.ONE);static ZERO=new C(r.ZERO,r.ONE,r.ZERO);static Fp=r;static Fn=i;X;Y;Z;constructor(e,t,n){this.X=ee(`x`,e),this.Y=ee(`y`,t,!0),this.Z=ee(`z`,n),Object.freeze(this)}static CURVE(){return a}static fromAffine(e){let{x:t,y:n}=e||{};if(!e||!r.isValid(t)||!r.isValid(n))throw Error(`invalid affine point`);if(e instanceof C)throw Error(`projective point not allowed`);return r.is0(t)&&r.is0(n)?C.ZERO:new C(t,n,r.ONE)}static fromBytes(e){let t=C.fromAffine(h(U(e,void 0,`point`)));return t.assertValidity(),t}static fromHex(e){return C.fromBytes(Xe(e))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(e=8,t=!0){return T.createCache(this,e),t||this.multiply(hn),this}assertValidity(){let e=this;if(e.is0()){if(t.allowInfinityPoint&&r.is0(e.X)&&r.eql(e.Y,r.ONE)&&r.is0(e.Z))return;throw Error(`bad point: ZERO`)}let{x:n,y:i}=e.toAffine();if(!r.isValid(n)||!r.isValid(i))throw Error(`bad point: x or y not field elements`);if(!_(n,i))throw Error(`bad point: equation left != right`);if(!e.isTorsionFree())throw Error(`bad point: not in prime-order subgroup`)}hasEvenY(){let{y:e}=this.toAffine();if(!r.isOdd)throw Error(`Field doesn't support isOdd`);return!r.isOdd(e)}equals(e){b(e);let{X:t,Y:n,Z:i}=this,{X:a,Y:o,Z:s}=e,c=r.eql(r.mul(t,s),r.mul(a,i)),l=r.eql(r.mul(n,s),r.mul(o,i));return c&&l}negate(){return new C(this.X,r.neg(this.Y),this.Z)}double(){let{a:e,b:t}=a,n=r.mul(t,hn),{X:i,Y:o,Z:s}=this,c=r.ZERO,l=r.ZERO,u=r.ZERO,d=r.mul(i,i),f=r.mul(o,o),p=r.mul(s,s),m=r.mul(i,o);return m=r.add(m,m),u=r.mul(i,s),u=r.add(u,u),c=r.mul(e,u),l=r.mul(n,p),l=r.add(c,l),c=r.sub(f,l),l=r.add(f,l),l=r.mul(c,l),c=r.mul(m,c),u=r.mul(n,u),p=r.mul(e,p),m=r.sub(d,p),m=r.mul(e,m),m=r.add(m,u),u=r.add(d,d),d=r.add(u,d),d=r.add(d,p),d=r.mul(d,m),l=r.add(l,d),p=r.mul(o,s),p=r.add(p,p),d=r.mul(p,m),c=r.sub(c,d),u=r.mul(p,f),u=r.add(u,u),u=r.add(u,u),new C(c,l,u)}add(e){b(e);let{X:t,Y:n,Z:i}=this,{X:o,Y:s,Z:c}=e,l=r.ZERO,u=r.ZERO,d=r.ZERO,f=a.a,p=r.mul(a.b,hn),m=r.mul(t,o),h=r.mul(n,s),g=r.mul(i,c),_=r.add(t,n),v=r.add(o,s);_=r.mul(_,v),v=r.add(m,h),_=r.sub(_,v),v=r.add(t,i);let y=r.add(o,c);return v=r.mul(v,y),y=r.add(m,g),v=r.sub(v,y),y=r.add(n,i),l=r.add(s,c),y=r.mul(y,l),l=r.add(h,g),y=r.sub(y,l),d=r.mul(f,v),l=r.mul(p,g),d=r.add(l,d),l=r.sub(h,d),d=r.add(h,d),u=r.mul(l,d),h=r.add(m,m),h=r.add(h,m),g=r.mul(f,g),v=r.mul(p,v),h=r.add(h,g),g=r.sub(m,g),g=r.mul(f,g),v=r.add(v,g),m=r.mul(h,v),u=r.add(u,m),m=r.mul(y,v),l=r.mul(_,l),l=r.sub(l,m),m=r.mul(_,h),d=r.mul(y,d),d=r.add(d,m),new C(l,u,d)}subtract(e){return b(e),this.add(e.negate())}is0(){return this.equals(C.ZERO)}multiply(e){let{endo:n}=t;if(!i.isValidNot0(e))throw RangeError(`invalid scalar: out of range`);let r,a,o=e=>T.cached(this,e,e=>Yt(C,e));if(n){let{k1neg:t,k1:i,k2neg:s,k2:c}=x(e),{p:l,f:u}=o(i),{p:d,f}=o(c);a=u.add(f),r=S(n.beta,l,d,t,s)}else{let{p:t,f:n}=o(e);r=t,a=n}return Yt(C,[r,a])[0]}multiplyUnsafe(e){let{endo:n}=t,r=this,a=e;if(!i.isValid(a))throw RangeError(`invalid scalar: out of range`);if(a===X||r.is0())return C.ZERO;if(a===pn)return r;if(T.hasCache(this))return this.multiply(a);if(n){let{k1neg:e,k1:t,k2neg:i,k2:o}=x(a),{p1:s,p2:c}=an(C,r,t,o);return S(n.beta,s,c,e,i)}else return T.unsafe(r,a)}toAffine(e){let t=this,n=e,{X:i,Y:a,Z:o}=t;if(r.eql(o,r.ONE))return{x:i,y:a};let s=t.is0();n??=s?r.ONE:r.inv(o);let c=r.mul(i,n),l=r.mul(a,n),u=r.mul(o,n);if(s)return{x:r.ZERO,y:r.ZERO};if(!r.eql(u,r.ONE))throw Error(`invZ was invalid`);return{x:c,y:l}}isTorsionFree(){let{isTorsionFree:e}=t;return o===pn?!0:e?e(C,this):T.unsafe(this,s).is0()}clearCofactor(){let{clearCofactor:e}=t;return o===pn?this:e?e(C,this):this.multiplyUnsafe(o)}isSmallOrder(){return o===pn?this.is0():this.clearCofactor().is0()}toBytes(e=!0){return tt(e,`isCompressed`),this.assertValidity(),m(C,this,e)}toHex(e=!0){return Ye(this.toBytes(e))}toString(){return`<Point ${this.is0()?`ZERO`:this.toHex()}>`}}let w=i.BITS,T=new rn(C,t.endo?Math.ceil(w/2):w);return w>=8&&C.BASE.precompute(8),Object.freeze(C.prototype),Object.freeze(C),C}function vn(e){return Uint8Array.of(e?2:3)}function yn(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function bn(e,t={}){let{Fn:n}=e,r=t.randomBytes===void 0?Qe:t.randomBytes,i=Object.assign(yn(e.Fp,n),{seed:Math.max(Wt(n.ORDER),16)});function a(e){try{let t=n.fromBytes(e);return n.isValidNot0(t)}catch{return!1}}function o(t,n){let{publicKey:r,publicKeyUncompressed:a}=i;try{let i=t.length;return n===!0&&i!==r||n===!1&&i!==a?!1:!!e.fromBytes(t)}catch{return!1}}function s(e){return e=e===void 0?r(i.seed):e,Gt(U(e,i.seed,`seed`),n.ORDER)}function c(t,r=!0){return e.BASE.multiply(n.fromBytes(t)).toBytes(r)}function l(e){let{secretKey:t,publicKey:r,publicKeyUncompressed:a}=i,o=n._lengths;if(!Ze(e))return;let s=U(e,void 0,`key`).length,c=s===r||s===a,l=s===t||!!o?.includes(s);if(!(c&&l))return c}function u(t,r,i=!0){if(l(t)===!0)throw Error(`first arg must be private key`);if(l(r)===!1)throw Error(`second arg must be public key`);let a=n.fromBytes(t);return e.fromBytes(r).multiply(a).toBytes(i)}let d={isValidSecretKey:a,isValidPublicKey:o,randomSecretKey:s},f=cn(s,c);return Object.freeze(d),Object.freeze(i),Object.freeze({getPublicKey:c,getSharedSecret:u,keygen:f,Point:e,utils:d,lengths:i})}function xn(e,n,r={}){let i=n;t.Or(i),vt(r,{},{hmac:`function`,lowS:`boolean`,randomBytes:`function`,bits2int:`function`,bits2int_modN:`function`}),r=Object.assign({},r);let a=r.randomBytes===void 0?Qe:r.randomBytes,o=r.hmac===void 0?(e,t)=>je(i,e,t):r.hmac,{Fp:s,Fn:c}=e,{ORDER:l,BITS:u}=c,{keygen:d,getPublicKey:f,getSharedSecret:p,utils:m,lengths:h}=bn(e,r),g={prehash:!0,lowS:typeof r.lowS!=`boolean`||r.lowS,format:`compact`,extraEntropy:!1},_=l*mn+pn<s.ORDER;function v(e){return e>l>>pn}function y(e,t){if(!c.isValidNot0(t))throw Error(`invalid signature ${e}: out of range 1..Point.Fn.ORDER`);return t}function ee(){if(_)throw Error(`"recovered" sig type is not supported for cofactor >2 curves`)}function b(e,t){dn(t);let n=h.signature;return U(e,t===`compact`?n:t===`recovered`?n+1:void 0)}class x{r;s;recovery;constructor(e,t,n){if(this.r=y(`r`,e),this.s=y(`s`,t),n!=null){if(ee(),![0,1,2,3].includes(n))throw Error(`invalid recovery id`);this.recovery=n}Object.freeze(this)}static fromBytes(e,t=g.format){b(e,t);let n;if(t===`der`){let{r:t,s:n}=Y.toSig(U(e));return new x(t,n)}t===`recovered`&&(n=e[0],t=`compact`,e=e.subarray(1));let r=h.signature/2,i=e.subarray(0,r),a=e.subarray(r,r*2);return new x(c.fromBytes(i),c.fromBytes(a),n)}static fromHex(e,t){return this.fromBytes(Xe(e),t)}assertRecovery(){let{recovery:e}=this;if(e==null)throw Error(`invalid recovery id: must be present`);return e}addRecoveryBit(e){return new x(this.r,this.s,e)}recoverPublicKey(t){let{r:n,s:r}=this,i=this.assertRecovery(),a=i===2||i===3?n+l:n;if(!s.isValid(a))throw Error(`invalid recovery id: sig.r+curve.n != R.x`);let o=s.toBytes(a),u=e.fromBytes(W(vn((i&1)==0),o)),d=c.inv(a),f=C(U(t,void 0,`msgHash`)),p=c.create(-f*d),m=c.create(r*d),h=e.BASE.multiplyUnsafe(p).add(u.multiplyUnsafe(m));if(h.is0())throw Error(`invalid recovery: point at infinify`);return h.assertValidity(),h}hasHighS(){return v(this.s)}toBytes(e=g.format){if(dn(e),e===`der`)return Xe(Y.hexFromSig(this));let{r:t,s:n}=this,r=c.toBytes(t),i=c.toBytes(n);return e===`recovered`?(ee(),W(Uint8Array.of(this.assertRecovery()),r,i)):W(r,i)}toHex(e){return Ye(this.toBytes(e))}}Object.freeze(x.prototype),Object.freeze(x);let S=r.bits2int===void 0?function(e){if(e.length>8192)throw Error(`input is too large`);let t=ot(e),n=e.length*8-u;return n>0?t>>BigInt(n):t}:r.bits2int,C=r.bits2int_modN===void 0?function(e){return c.create(S(e))}:r.bits2int_modN,w=gt(u);function T(e){return mt(`num < 2^`+u,e,X,w),c.toBytes(e)}function E(e,t){return U(e,void 0,`message`),t?U(i(e),void 0,`prehashed message`):e}function D(t,n,r){let{lowS:i,prehash:o,extraEntropy:s}=fn(r,g);t=E(t,o);let l=C(t),u=c.fromBytes(n);if(!c.isValidNot0(u))throw Error(`invalid private key`);let d=[T(u),T(l)];if(s!=null&&s!==!1){let e=s===!0?a(h.secretKey):s;d.push(U(e,void 0,`extraEntropy`))}let f=W(...d),p=l;function m(t){let n=S(t);if(!c.isValidNot0(n))return;let r=c.inv(n),a=e.BASE.multiply(n).toAffine(),o=c.create(a.x);if(o===X)return;let s=c.create(r*c.create(p+o*u));if(s===X)return;let l=(a.x===o?0:2)|Number(a.y&pn),d=s;return i&&v(s)&&(d=c.neg(s),l^=1),new x(o,d,_?void 0:l)}return{seed:f,k2sig:m}}function O(e,t,n={}){let{seed:r,k2sig:a}=D(e,t,n);return _t(i.outputLen,c.BYTES,o)(r,a).toBytes(n.format)}function k(t,n,r,i={}){let{lowS:a,prehash:o,format:s}=fn(i,g);if(r=U(r,void 0,`publicKey`),n=E(n,o),!Ze(t)){let e=t instanceof x?`, use sig.toBytes()`:``;throw Error(`verify expects Uint8Array signature`+e)}b(t,s);try{let i=x.fromBytes(t,s),o=e.fromBytes(r);if(a&&i.hasHighS())return!1;let{r:l,s:u}=i,d=C(n),f=c.inv(u),p=c.create(d*f),m=c.create(l*f),h=e.BASE.multiplyUnsafe(p).add(o.multiplyUnsafe(m));return!h.is0()&&c.create(h.x)===l}catch{return!1}}function A(e,t,n={}){let{prehash:r}=fn(n,g);return t=E(t,r),x.fromBytes(e,`recovered`).recoverPublicKey(t).toBytes()}return Object.freeze({keygen:d,getPublicKey:f,getSharedSecret:p,utils:m,lengths:h,Point:e,sign:O,verify:k,recoverPublicKey:A,Signature:x,hash:i})}
|
|
12
12
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
13
|
-
const Sn={p:BigInt(`0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f`),n:BigInt(`0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141`),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt(`0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798`),Gy:BigInt(`0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8`)},Cn={beta:BigInt(`0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee`),basises:[[BigInt(`0x3086d221a7d46bcde86c90e49284eb15`),-BigInt(`0xe4437ed6010e88286f547fa90abfe4c3`)],[BigInt(`0x114ca50f7a8e2f3f657c1108d9d44cfd8`),BigInt(`0x3086d221a7d46bcde86c90e49284eb15`)]]},wn=BigInt(0),Tn=BigInt(2);function En(e){let t=Sn.p,n=BigInt(3),r=BigInt(6),i=BigInt(11),a=BigInt(22),o=BigInt(23),s=BigInt(44),c=BigInt(88),l=e*e*e%t,u=l*l*e%t,d=J(J(J(u,n,t)*u%t,n,t)*u%t,Tn,t)*l%t,f=J(d,i,t)*d%t,p=J(f,a,t)*f%t,m=J(p,s,t)*p%t,h=J(J(J(J(J(J(m,c,t)*m%t,s,t)*p%t,n,t)*u%t,o,t)*f%t,r,t)*l%t,Tn,t);if(!Dn.eql(Dn.sqr(h),e))throw Error(`Cannot find square root`);return h}const Dn=Ht(Sn.p,{sqrt:En}),On=_n(Sn,{Fp:Dn,endo:Cn}),kn=xn(On,H),An={};function jn(e,...t){let n=An[e];if(n===void 0){let t=H(dt(e));n=W(t,t),An[e]=n}return H(W(n,...t))}const Mn=e=>e.toBytes(!0).slice(1),Nn=e=>e%Tn===wn;function Pn(e){let{Fn:t,BASE:n}=On,r=t.fromBytes(e),i=n.multiply(r);return{scalar:Nn(i.y)?r:t.neg(r),bytes:Mn(i)}}function Fn(e){let t=Dn;if(!t.isValidNot0(e))throw Error(`invalid x: Fail if x ≥ p`);let n=t.create(e*e),r=t.create(n*e+BigInt(7)),i=t.sqrt(r);Nn(i)||(i=t.neg(i));let a=On.fromAffine({x:e,y:i});return a.assertValidity(),a}const In=ot;function Ln(...e){return On.Fn.create(In(jn(`BIP0340/challenge`,...e)))}function Rn(e){return Pn(e).bytes}function zn(e,n,r=t.
|
|
13
|
+
const Sn={p:BigInt(`0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f`),n:BigInt(`0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141`),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt(`0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798`),Gy:BigInt(`0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8`)},Cn={beta:BigInt(`0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee`),basises:[[BigInt(`0x3086d221a7d46bcde86c90e49284eb15`),-BigInt(`0xe4437ed6010e88286f547fa90abfe4c3`)],[BigInt(`0x114ca50f7a8e2f3f657c1108d9d44cfd8`),BigInt(`0x3086d221a7d46bcde86c90e49284eb15`)]]},wn=BigInt(0),Tn=BigInt(2);function En(e){let t=Sn.p,n=BigInt(3),r=BigInt(6),i=BigInt(11),a=BigInt(22),o=BigInt(23),s=BigInt(44),c=BigInt(88),l=e*e*e%t,u=l*l*e%t,d=J(J(J(u,n,t)*u%t,n,t)*u%t,Tn,t)*l%t,f=J(d,i,t)*d%t,p=J(f,a,t)*f%t,m=J(p,s,t)*p%t,h=J(J(J(J(J(J(m,c,t)*m%t,s,t)*p%t,n,t)*u%t,o,t)*f%t,r,t)*l%t,Tn,t);if(!Dn.eql(Dn.sqr(h),e))throw Error(`Cannot find square root`);return h}const Dn=Ht(Sn.p,{sqrt:En}),On=_n(Sn,{Fp:Dn,endo:Cn}),kn=xn(On,H),An={};function jn(e,...t){let n=An[e];if(n===void 0){let t=H(dt(e));n=W(t,t),An[e]=n}return H(W(n,...t))}const Mn=e=>e.toBytes(!0).slice(1),Nn=e=>e%Tn===wn;function Pn(e){let{Fn:t,BASE:n}=On,r=t.fromBytes(e),i=n.multiply(r);return{scalar:Nn(i.y)?r:t.neg(r),bytes:Mn(i)}}function Fn(e){let t=Dn;if(!t.isValidNot0(e))throw Error(`invalid x: Fail if x ≥ p`);let n=t.create(e*e),r=t.create(n*e+BigInt(7)),i=t.sqrt(r);Nn(i)||(i=t.neg(i));let a=On.fromAffine({x:e,y:i});return a.assertValidity(),a}const In=ot;function Ln(...e){return On.Fn.create(In(jn(`BIP0340/challenge`,...e)))}function Rn(e){return Pn(e).bytes}function zn(e,n,r=t.Hr(32)){let{Fn:i,BASE:a}=On,o=U(e,void 0,`message`),{bytes:s,scalar:c}=Pn(n),l=U(r,32,`auxRand`),u=jn(`BIP0340/nonce`,i.toBytes(c^In(jn(`BIP0340/aux`,l))),s,o),d=i.create(In(u));if(d===0n)throw Error(`sign failed: k is zero`);let f=a.multiply(d),p=Nn(f.y)?d:i.neg(d),m=Mn(f),h=Ln(m,s,o),g=new Uint8Array(64);if(g.set(m,0),g.set(i.toBytes(i.create(p+h*c)),32),!Bn(g,o,s))throw Error(`sign: Invalid signature produced`);return g}function Bn(e,t,n){let{Fp:r,Fn:i,BASE:a}=On,o=U(e,64,`signature`),s=U(t,void 0,`message`),c=U(n,32,`publicKey`);try{let e=Fn(In(c)),t=In(o.subarray(0,32));if(!r.isValidNot0(t))return!1;let n=In(o.subarray(32,64));if(!i.isValidNot0(n))return!1;let l=Ln(i.toBytes(t),Mn(e),s),u=a.multiplyUnsafe(n).add(e.multiplyUnsafe(i.neg(l))),{x:d,y:f}=u.toAffine();return!(u.is0()||!Nn(f)||d!==t)}catch{return!1}}const Vn=(()=>{let e=e=>(e=e===void 0?t.Hr(48):e,Gt(e,Sn.n));return Object.freeze({keygen:cn(e,Rn),getPublicKey:Rn,sign:zn,verify:Bn,Point:On,utils:Object.freeze({randomSecretKey:e,taggedHash:jn,lift_x:Fn,pointToBytes:Mn}),lengths:Object.freeze({secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48})})})(),Hn=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),Un=Uint8Array.from(Array(16).fill(0).map((e,t)=>t)),Wn=Un.map(e=>(9*e+5)%16),Gn=(()=>{let e=[[Un],[Wn]];for(let t=0;t<4;t++)for(let n of e)n.push(n[t].map(e=>Hn[e]));return e})(),Kn=Gn[0],qn=Gn[1],Jn=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map(e=>Uint8Array.from(e)),Yn=Kn.map((e,t)=>e.map(e=>Jn[t][e])),Xn=qn.map((e,t)=>e.map(e=>Jn[t][e])),Zn=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),Qn=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function $n(e,t,n,r){return e===0?t^n^r:e===1?t&n|~t&r:e===2?(t|~n)^r:e===3?t&r|n&~r:t^(n|~r)}const er=new Uint32Array(16);var tr=class extends c{h0=1732584193;h1=-271733879;h2=-1732584194;h3=271733878;h4=-1009589776;constructor(){super(64,20,8,!0)}get(){let{h0:e,h1:t,h2:n,h3:r,h4:i}=this;return[e,t,n,r,i]}set(e,t,n,r,i){this.h0=e|0,this.h1=t|0,this.h2=n|0,this.h3=r|0,this.h4=i|0}process(e,n){for(let t=0;t<16;t++,n+=4)er[t]=e.getUint32(n,!0);let r=this.h0|0,i=r,a=this.h1|0,o=a,s=this.h2|0,c=s,l=this.h3|0,u=l,d=this.h4|0,f=d;for(let e=0;e<5;e++){let n=4-e,p=Zn[e],m=Qn[e],h=Kn[e],g=qn[e],_=Yn[e],v=Xn[e];for(let n=0;n<16;n++){let i=t.Ur(r+$n(e,a,s,l)+er[h[n]]+p,_[n])+d|0;r=d,d=l,l=t.Ur(s,10)|0,s=a,a=i}for(let e=0;e<16;e++){let r=t.Ur(i+$n(n,o,c,u)+er[g[e]]+m,v[e])+f|0;i=f,f=u,u=t.Ur(c,10)|0,c=o,o=r}}this.set(this.h1+s+u|0,this.h2+l+f|0,this.h3+d+i|0,this.h4+r+o|0,this.h0+a+c|0)}roundClean(){t.Pr(er)}destroy(){this.destroyed=!0,t.Pr(this.buffer),this.set(0,0,0,0,0)}};const nr=t.Ir(()=>new tr);
|
|
14
14
|
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
15
|
-
function rr(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`}function ir(e,...t){if(!rr(e))throw Error(`Uint8Array expected`);if(t.length>0&&!t.includes(e.length))throw Error(`Uint8Array expected of length `+t+`, got length=`+e.length)}function ar(e,t=!0){if(e.destroyed)throw Error(`Hash instance has been destroyed`);if(t&&e.finished)throw Error(`Hash#digest() has already been called`)}function or(e,t){ir(e);let n=t.outputLen;if(e.length<n)throw Error(`digestInto() expects output buffer of length at least `+n)}function sr(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function cr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Z(e,t){return e<<32-t|e>>>t}function lr(e){if(typeof e!=`string`)throw Error(`string expected`);return new Uint8Array(new TextEncoder().encode(e))}function ur(e){return typeof e==`string`&&(e=lr(e)),ir(e),e}var dr=class{};function fr(e){let t=t=>e().update(ur(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function pr(e,t,n,r){if(typeof e.setBigUint64==`function`)return e.setBigUint64(t,n,r);let i=BigInt(32),a=BigInt(4294967295),o=Number(n>>i&a),s=Number(n&a),c=r?4:0,l=r?0:4;e.setUint32(t+c,o,r),e.setUint32(t+l,s,r)}function mr(e,t,n){return e&t^~e&n}function hr(e,t,n){return e&t^e&n^t&n}var gr=class extends dr{constructor(e,t,n,r){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.buffer=new Uint8Array(e),this.view=cr(this.buffer)}update(e){ar(this),e=ur(e),ir(e);let{view:t,buffer:n,blockLen:r}=this,i=e.length;for(let a=0;a<i;){let o=Math.min(r-this.pos,i-a);if(o===r){let t=cr(e);for(;r<=i-a;a+=r)this.process(t,a);continue}n.set(e.subarray(a,a+o),this.pos),this.pos+=o,a+=o,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){ar(this),or(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:r,isLE:i}=this,{pos:a}=this;t[a++]=128,sr(this.buffer.subarray(a)),this.padOffset>r-a&&(this.process(n,0),a=0);for(let e=a;e<r;e++)t[e]=0;pr(n,r-8,BigInt(this.length*8),i),this.process(n,0);let o=cr(e),s=this.outputLen;if(s%4)throw Error(`_sha2: outputLen should be aligned to 32bit`);let c=s/4,l=this.get();if(c>l.length)throw Error(`_sha2: outputLen bigger than state`);for(let e=0;e<c;e++)o.setUint32(4*e,l[e],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:t,buffer:n,length:r,finished:i,destroyed:a,pos:o}=this;return e.destroyed=a,e.finished=i,e.length=r,e.pos=o,r%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}};const _r=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),vr=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]),yr=new Uint32Array(64);var br=class extends gr{constructor(e=32){super(64,e,8,!1),this.A=_r[0]|0,this.B=_r[1]|0,this.C=_r[2]|0,this.D=_r[3]|0,this.E=_r[4]|0,this.F=_r[5]|0,this.G=_r[6]|0,this.H=_r[7]|0}get(){let{A:e,B:t,C:n,D:r,E:i,F:a,G:o,H:s}=this;return[e,t,n,r,i,a,o,s]}set(e,t,n,r,i,a,o,s){this.A=e|0,this.B=t|0,this.C=n|0,this.D=r|0,this.E=i|0,this.F=a|0,this.G=o|0,this.H=s|0}process(e,t){for(let n=0;n<16;n++,t+=4)yr[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){let t=yr[e-15],n=yr[e-2],r=Z(t,7)^Z(t,18)^t>>>3,i=Z(n,17)^Z(n,19)^n>>>10;yr[e]=i+yr[e-7]+r+yr[e-16]|0}let{A:n,B:r,C:i,D:a,E:o,F:s,G:c,H:l}=this;for(let e=0;e<64;e++){let t=Z(o,6)^Z(o,11)^Z(o,25),u=l+t+mr(o,s,c)+vr[e]+yr[e]|0,d=(Z(n,2)^Z(n,13)^Z(n,22))+hr(n,r,i)|0;l=c,c=s,s=o,o=a+u|0,a=i,i=r,r=n,n=u+d|0}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,a=a+this.D|0,o=o+this.E|0,s=s+this.F|0,c=c+this.G|0,l=l+this.H|0,this.set(n,r,i,a,o,s,c,l)}roundClean(){sr(yr)}destroy(){this.set(0,0,0,0,0,0,0,0),sr(this.buffer)}};const xr=fr(()=>new br);function Sr(e){if(e.length>=255)throw TypeError(`Alphabet too long`);let t=new Uint8Array(256);for(let e=0;e<t.length;e++)t[e]=255;for(let n=0;n<e.length;n++){let r=e.charAt(n),i=r.charCodeAt(0);if(t[i]!==255)throw TypeError(r+` is ambiguous`);t[i]=n}let n=e.length,r=e.charAt(0),i=Math.log(n)/Math.log(256),a=Math.log(256)/Math.log(n);function o(t){if(t instanceof Uint8Array||(ArrayBuffer.isView(t)?t=new Uint8Array(t.buffer,t.byteOffset,t.byteLength):Array.isArray(t)&&(t=Uint8Array.from(t))),!(t instanceof Uint8Array))throw TypeError(`Expected Uint8Array`);if(t.length===0)return``;let i=0,o=0,s=0,c=t.length;for(;s!==c&&t[s]===0;)s++,i++;let l=(c-s)*a+1>>>0,u=new Uint8Array(l);for(;s!==c;){let e=t[s],r=0;for(let t=l-1;(e!==0||r<o)&&t!==-1;t--,r++)e+=256*u[t]>>>0,u[t]=e%n>>>0,e=e/n>>>0;if(e!==0)throw Error(`Non-zero carry`);o=r,s++}let d=l-o;for(;d!==l&&u[d]===0;)d++;let f=r.repeat(i);for(;d<l;++d)f+=e.charAt(u[d]);return f}function s(e){if(typeof e!=`string`)throw TypeError(`Expected String`);if(e.length===0)return new Uint8Array;let a=0,o=0,s=0;for(;e[a]===r;)o++,a++;let c=(e.length-a)*i+1>>>0,l=new Uint8Array(c);for(;a<e.length;){let r=e.charCodeAt(a);if(r>255)return;let i=t[r];if(i===255)return;let o=0;for(let e=c-1;(i!==0||o<s)&&e!==-1;e--,o++)i+=n*l[e]>>>0,l[e]=i%256>>>0,i=i/256>>>0;if(i!==0)throw Error(`Non-zero carry`);s=o,a++}let u=c-s;for(;u!==c&&l[u]===0;)u++;let d=new Uint8Array(o+(c-u)),f=o;for(;u!==c;)d[f++]=l[u++];return d}function c(e){let t=s(e);if(t)return t;throw Error(`Non-base`+n+` character`)}return{encode:o,decodeUnsafe:s,decode:c}}var Cr=Sr(`123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz`);function wr(e){function t(t){var n=Uint8Array.from(t),r=e(n),i=n.length+4,a=new Uint8Array(i);return a.set(n,0),a.set(r.subarray(0,4),n.length),Cr.encode(a)}function n(t){var n=t.slice(0,-4),r=t.slice(-4),i=e(n);if(!(r[0]^i[0]|r[1]^i[1]|r[2]^i[2]|r[3]^i[3]))return n}function r(e){var t=Cr.decodeUnsafe(e);if(t!=null)return n(t)}function i(e){var t=n(Cr.decode(e));if(t==null)throw Error(`Invalid checksum`);return t}return{encode:t,decode:i,decodeUnsafe:r}}function Tr(e){return xr(xr(e))}var Er=wr(Tr);function Dr(e){let n=t.
|
|
16
|
-
`,i=typeof r==`string`?t.
|
|
17
|
-
`)}function Br(e,n,r){let i=typeof e==`string`?e:t.yr(e).slice(2),a=t.Zr(n,`base64`);return a[0]-=31,jr(r)===t.yr(kr(kn.recoverPublicKey(a,zr(i),{prehash:!1})))}function Vr(e,n,r){return r.toLowerCase()===(0,a.verifyMessage)(typeof e==`string`?e:t.Zr(e),n).toLowerCase()}function Hr(e){if(typeof e==`string`)try{let t=JSON.parse(e);if(typeof t==`object`&&typeof t.created_at==`number`&&typeof t.kind==`number`&&typeof t.content==`string`&&Array.isArray(t.tags)&&t.tags.every(e=>Array.isArray(e)&&e.every(e=>typeof e==`string`)))return t}catch{}return{kind:23335,created_at:0,content:typeof e==`string`?e:t.yr(e),tags:[]}}function Ur(e){return H(t.Zr(JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content]),`utf8`))}function Wr(e,r,i){let{words:a}=n.bech32.decode(i),o=t.yr(n.bech32.fromWords(a)).slice(2),s=Ur({...Hr(e),pubkey:o});try{return Vn.verify(t.Zr(r),s,t.Zr(o))}catch{return!1}}let Gr=function(e){return e.Unknown=`Unknown`,e.BtcEcdsa=`BtcEcdsa`,e.EvmPersonal=`EvmPersonal`,e.JoyId=`JoyId`,e.NostrEvent=`NostrEvent`,e.CkbSecp256k1=`CkbSecp256k1`,e.DogeEcdsa=`DogeEcdsa`,e}({}),Kr=function(e){return e.EVM=`EVM`,e.BTC=`BTC`,e.CKB=`CKB`,e.Nostr=`Nostr`,e.Doge=`Doge`,e}({});var qr=class{constructor(e,t,n){this.signature=e,this.identity=t,this.signType=n}},Q=class e{constructor(e){this.client_=e}get client(){return this.client_}matchNetworkPreference(e,t){if(!(t!==void 0&&e.some(({signerType:e,addressPrefix:n,network:r})=>e===this.type&&n===this.client.addressPrefix&&r===t)))return e.find(({signerType:e,addressPrefix:t})=>e===this.type&&t===this.client.addressPrefix)}static async verifyMessage(e,t){switch(t.signType){case`EvmPersonal`:return Vr(e,t.signature,t.identity);case`BtcEcdsa`:return Mr(e,t.signature,t.identity);case`JoyId`:return Rr(e,t.signature,t.identity);case`NostrEvent`:return Wr(e,t.signature,t.identity);case`CkbSecp256k1`:return Lr(e,t.signature,t.identity);case`DogeEcdsa`:return Br(e,t.signature,t.identity);case`Unknown`:throw Error(`Unknown signer sign type`)}}onReplaced(e){return()=>{}}async disconnect(){}async getIdentity(){return this.getInternalAddress()}async getRecommendedAddressObj(e){return(await this.getAddressObjs())[0]}async getRecommendedAddress(e){return(await this.getRecommendedAddressObj(e)).toString()}async getAddresses(){return this.getAddressObjs().then(e=>e.map(e=>e.toString()))}async*findCellsOnChain(e,t,n,r){let i=await this.getAddressObjs();for(let{script:a}of i)for await(let i of this.client.findCellsOnChain({script:a,scriptType:`lock`,filter:e,scriptSearchMode:`exact`,withData:t},n,r))yield i}async*findCells(e,t,n,r){let i=await this.getAddressObjs();for(let{script:a}of i)for await(let i of this.client.findCells({script:a,scriptType:`lock`,filter:e,scriptSearchMode:`exact`,withData:t},n,r))yield i}async*findTransactions(e,t,n,r){let i=await this.getAddressObjs();for(let{script:a}of i)for await(let i of this.client.findTransactions({script:a,scriptType:`lock`,filter:e,scriptSearchMode:`exact`,groupByTransaction:t},n,r))yield i}async getBalance(){return this.client.getBalance((await this.getAddressObjs()).map(({script:e})=>e))}async signMessage(e){return{signature:await this.signMessageRaw(e),identity:await this.getIdentity(),signType:this.signType}}signMessageRaw(e){throw Error(`Signer.signMessageRaw not implemented`)}async verifyMessage(t,n){return typeof n==`string`?e.verifyMessage(t,{signType:this.signType,signature:n,identity:await this.getIdentity()}):n.identity!==await this.getIdentity()||![`Unknown`,this.signType].includes(n.signType)?!1:e.verifyMessage(t,n)}async sendTransaction(e){return this.client.sendTransaction(await this.signTransaction(e))}async signTransaction(e){let t=await this.prepareTransaction(e);return this.signOnlyTransaction(t)}async prepareTransaction(e){return t._.from(e)}signOnlyTransaction(e){throw Error(`Signer.signOnlyTransaction not implemented`)}},Jr=class extends Q{async sendTransaction(e){let t=await this.signTransaction(e);if(await this.needMoreSignatures(t))throw new Yr(await this.getSignaturesCount(t)??0,await this.getMemberThreshold());return this.client.sendTransaction(t)}},Yr=class extends Error{constructor(e,t){let n=`Not enough signatures: got ${e}, need ${t}`;super(n),this.name=`SignerMultisigNotEnoughSignaturesError`,this.signaturesCount=e,this.threshold=t}},Xr=class{constructor(e,t){this.name=e,this.signer=t}},Zr=class extends Q{get type(){return`BTC`}get signType(){return`BtcEcdsa`}async signAndBroadcastPsbt(e,t){let n=await this.signPsbt(e,t);return this.broadcastPsbt(n,t)}async getInternalAddress(){return this.getBtcAccount()}async getIdentity(){return t.yr(await this.getBtcPublicKey()).slice(2)}async getAddressObjs(){let e=kr(await this.getBtcPublicKey());return[await R.fromKnownScript(this.client,`OmniLock`,t.yr([4,...e,0]))]}async prepareTransaction(e){let n=t._.from(e),{script:r}=await this.getRecommendedAddressObj();return await n.addCellDepsOfKnownScripts(this.client,`OmniLock`),await n.prepareSighashAllWitness(r,85,this.client),n}async signOnlyTransaction(e){let n=t._.from(e),{script:r}=await this.getRecommendedAddressObj(),i=await n.getSignHashInfo(r,this.client);if(!i)return n;let a=t.Zr(await this.signMessageRaw(`CKB (Bitcoin Layer) transaction: ${i.message}`),`base64`);a[0]=31+(a[0]-27)%4;let o=t.v.fromBytes(n.witnesses[i.position]);return o.lock=t.yr(t.Jr(t.rr(20+a.length,4),t.rr(16,4),t.rr(20+a.length,4),t.rr(20+a.length,4),t.rr(a.length,4),a)),n.setWitnessArgs(i.position,o),n}},Qr=class extends Zr{constructor(e,n,r){super(e),this.account=n,this.publicKey=t.yr(r)}async connect(){}async isConnected(){return!0}async getBtcAccount(){return this.account}async getBtcPublicKey(){return this.publicKey}async signPsbt(e,t){throw Error(`Read-only signer does not support signPsbt`)}async broadcastPsbt(e,t){throw Error(`Read-only signer does not support broadcastPsbt`)}},$r=class extends Q{get type(){return`CKB`}get signType(){return`Unknown`}constructor(e){super(e)}async connect(){}async isConnected(){return!0}async getInternalAddress(){return this.getRecommendedAddress()}async getAddressObjs(){return[await R.fromKnownScript(this.client,`AlwaysSuccess`,`0x`)]}async prepareTransaction(e){let n=t._.from(e);return await n.addCellDepsOfKnownScripts(this.client,`AlwaysSuccess`),n}async signOnlyTransaction(e){return t._.from(e)}},ei=class extends Q{get type(){return`CKB`}get signType(){return`CkbSecp256k1`}constructor(e,n){if(super(e),this.publicKey=t.yr(n),t.Zr(this.publicKey).length!==33)throw Error(`Public key must be 33 bytes!`)}async connect(){}async isConnected(){return!0}async getInternalAddress(){return this.getRecommendedAddress()}async getIdentity(){return this.publicKey}async getAddressObjSecp256k1(){return R.fromKnownScript(this.client,`Secp256k1Blake160`,t.hr(this.publicKey))}async getRecommendedAddressObj(e){return this.getAddressObjSecp256k1()}async getAddressObjs(){let e=await this.getAddressObjSecp256k1(),n=[],r=0;for await(let i of this.client.findCells({script:await t.M.fromKnownScript(this.client,`AnyoneCanPay`,e.script.args),scriptType:`lock`,scriptSearchMode:`prefix`,withData:!1})){if(r>=10)break;r+=1,!n.some(({script:e})=>e.eq(i.cellOutput.lock))&&n.push(R.from({prefix:this.client.addressPrefix,script:i.cellOutput.lock}))}return[e,...n]}async getRelatedScripts(e){let n=t._.from(e),r=await this.getAddressObjSecp256k1(),i=await t.M.fromKnownScript(this.client,`AnyoneCanPay`,r.script.args),a=[];for(let e of n.inputs){let{cellOutput:{lock:t}}=await e.getCell(this.client);a.some(({script:e})=>e.eq(t))||(t.eq(r.script)?a.push({script:t,cellDeps:(await this.client.getKnownScript(`Secp256k1Blake160`)).cellDeps}):t.codeHash===i.codeHash&&t.hashType===i.hashType&&t.args.startsWith(i.args)&&a.push({script:t,cellDeps:(await this.client.getKnownScript(`AnyoneCanPay`)).cellDeps}))}return a}async prepareTransaction(e){let n=t._.from(e);return await Promise.all((await this.getRelatedScripts(n)).map(async({script:e,cellDeps:t})=>{await n.prepareSighashAllWitness(e,65,this.client),await n.addCellDepInfos(this.client,t)})),n}},ti=class extends ei{constructor(e,n){let r=t.yr(n);if(t.Zr(r).length!==32)throw Error(`Private key must be 32 bytes!`);super(e,kn.getPublicKey(t.Zr(r),!0)),this.privateKey=r}async _signMessage(e){return Nr(e,this.privateKey)}async signMessageRaw(e){return this._signMessage(Ir(e))}async signOnlyTransaction(e){let n=t._.from(e);for(let{script:e}of await this.getRelatedScripts(n)){let r=await n.getSignHashInfo(e,this.client);if(!r)return n;let i=await this._signMessage(r.message),a=n.getWitnessArgs(r.position)??t.v.from({});a.lock=i,n.setWitnessArgs(r.position,a)}return n}},ni=class extends Q{get type(){return`CKB`}get signType(){return`Unknown`}constructor(e,...n){if(super(e),this.scripts=n.flat().map(t.M.from),this.scripts.length===0)throw Error(`SignerCkbScriptReadonly requires at least one script.`)}async connect(){}async isConnected(){return!0}async getInternalAddress(){return this.getRecommendedAddress()}async getAddressObjs(){return this.scripts.map(e=>R.fromScript(e,this.client))}},ri;let $=ri=class extends t.lr.Base(){constructor(e,t,n,r){super(),this.publicKeyHashes=e,this.threshold=t,this.mustMatch=n,this.signatures=r;let i=e.length;if(t<=0||t>i)throw Error(`threshold should be in range from 1 to public keys length`);if(n<0||n>Math.min(i,t))throw Error(`mustMatch should be in range from 0 to min(public keys length, threshold)`);if(i>255)throw Error(`public keys length should be less than 256`)}static from(e){let n=e.publicKeyHashes?e.publicKeyHashes:e.publicKeys.map(e=>t.hr(e));return new ri(n.map(t.yr),Number(t.Zn(e.threshold)),Number(t.Zn(e.mustMatch??0)),e.signatures?.map(t.yr)??[])}get flexibleThreshold(){return this.threshold-this.mustMatch}scriptArgs(e){let n=t.hr(ri.from({...this,signatures:[]}).toBytes());return e==null?t.Zr(n):t.Jr(n,t.g.from(e).toBytes())}eqInfo(e){let t=ri.from(e);return this.publicKeyHashes.length===t.publicKeyHashes.length&&this.publicKeyHashes.every((e,n)=>e===t.publicKeyHashes[n])&&this.threshold===t.threshold&&this.mustMatch===t.mustMatch}*generatePublicKeyHashesFromSignatures(e){let n=new Set;for(let r of this.signatures.filter(e=>e!==ii.EmptySignature)){let i=(()=>{try{return Fr(e,r)}catch{return}})();if(i===void 0)continue;let a=t.hr(i);if(n.has(a))continue;let o=this.publicKeyHashes.indexOf(a);o!==-1&&(n.add(a),yield{pubkeyHash:a,signature:r,isRequired:o<this.mustMatch})}}calcMatchedSignaturesCount(e){let t=0,n=0;for(let{isRequired:r}of this.generatePublicKeyHashesFromSignatures(e))r?t+=1:n+=1;return{required:t,flexible:n}}};$=ri=t.Tt([t.ur({encode:e=>{let{publicKeyHashes:n,threshold:r,mustMatch:i,signatures:a}=$.from(e);if(a.some(e=>e.length!==132))throw Error(`MultisigCkbWitness: invalid signature length`);if(n.some(e=>e.length!==42))throw Error(`MultisigCkbWitness: invalid public key hash length`);return t.Jr(`0x00`,t.rr(i??0),t.rr(r),t.rr(n.length),...n,...a)},decode:e=>{if(e.length<4)throw Error(`MultisigCkbWitness: data length too short`);let[n,r,i,a,...o]=e;if(o.length<a*20)throw Error(`MultisigCkbWitness: invalid public key hashes length`);let s=o.slice(a*20);return $.from({publicKeyHashes:Array.from(Array(a),(e,n)=>t.yr(o.slice(n*20,(n+1)*20))),threshold:t.Zn(i),mustMatch:t.Zn(r),signatures:Array.from(Array(Math.floor(s.length/65)),(e,n)=>t.yr(s.slice(n*65,(n+1)*65)))})}})],$);var ii=class e extends Jr{static{this.EmptySignature=t.yr(`00`.repeat(65))}get type(){return`CKB`}get signType(){return`Unknown`}constructor(e,n,r){super(e),this.multisigInfo=$.from(n),this.since=t.Et(t.g.from,r?.since);let i=this.multisigInfo.scriptArgs(this.since);this.scriptInfos=Promise.all((r?.scriptInfos??[`Secp256k1MultisigV2`,`Secp256k1MultisigV2Beta`,`Secp256k1Multisig`]).map(async n=>{if(typeof n!=`string`)return t._t.from(n);try{return await e.getKnownScript(n)}catch{return}})).then(e=>e.filter(e=>e!==void 0).map(e=>({script:t.M.from({...e,args:i}),cellDeps:e.cellDeps})))}async getMemberCount(){return this.multisigInfo.publicKeyHashes.length}async getMemberThreshold(){return this.multisigInfo.threshold}async getMemberRequiredCount(){return this.multisigInfo.mustMatch}async connect(){}async isConnected(){return!0}async getInternalAddress(){return this.getRecommendedAddress()}async getAddressObjs(){return(await this.scriptInfos).map(({script:e})=>R.fromScript(e,this.client))}decodeWitnessArgsAt(e,n){let r=t._.from(e);return this.decodeWitnessArgs(r.getWitnessArgs(n))}decodeWitnessArgs(e){if(!e)return;let n=t.v.from(e);if(n.lock!=null)try{let e=$.decode(n.lock);if(e.eqInfo(this.multisigInfo))return e}catch{}}async prepareWitnessArgsAt(n,r,i){let a=t._.from(n),o=a.getWitnessArgs(r)??t.v.from({}),s=this.decodeWitnessArgs(o)??this.multisigInfo.clone(),c=$.from(await i?.(s,o)??s);return c.signatures=c.signatures.slice(0,this.multisigInfo.threshold),c.signatures.push(...Array.from(Array(this.multisigInfo.threshold-c.signatures.length),()=>e.EmptySignature)),o.lock=c.toHex(),a.setWitnessArgs(r,o),a}async prepareTransactionOneScript(e,n,r){let i=t._.from(e),a=await i.findInputIndexByLock(n,this.client);return a===void 0?i:(await i.addCellDepInfos(this.client,r),this.prepareWitnessArgsAt(i,a))}async prepareTransaction(e){return await t.kt(await this.scriptInfos,(e,{script:t,cellDeps:n})=>this.prepareTransactionOneScript(e,t,n),t._.from(e))}async getSignaturesCount(e){let n=t._.from(e),r;for(let{script:e}of await this.scriptInfos){let t=await this.getSignInfo(n,e);if(t===void 0)continue;let i=this.decodeWitnessArgsAt(n,t.position);if(!i){r=0;continue}let{required:a,flexible:o}=i.calcMatchedSignaturesCount(t.message);r=Math.min(r??256,a+Math.min(o,this.multisigInfo.flexibleThreshold))}return r}async needMoreSignatures(e){let t=await this.getSignaturesCount(e);return t!=null&&t<await this.getMemberThreshold()}async getSignInfo(n,r){let i=t._.from(n),a=await i.findInputIndexByLock(r,this.client);if(a==null)return;let o=i.getWitnessArgs(a)??t.v.from({});o.lock=$.from({...this.multisigInfo,signatures:Array.from(Array(this.multisigInfo.threshold),()=>e.EmptySignature)}).toHex();let s=i.clone();return s.setWitnessArgs(a,o),s.getSignHashInfo(r,this.client)}async aggregateTransactions(e){if(e.length===0)throw Error(`No transaction to aggregate`);let n=t._.from(e[0]);for(let{script:r}of await this.scriptInfos){let i=await this.getSignInfo(n,r);if(i===void 0)continue;let a=new Map,o=0;for(let n of e){let e=t._.from(n),r=this.decodeWitnessArgsAt(e,i.position);if(r){for(let{pubkeyHash:e,signature:t,isRequired:n}of r.generatePublicKeyHashesFromSignatures(i.message))if(!a.has(e)){if(n)o+=1;else if(a.size-o>=this.multisigInfo.flexibleThreshold)continue;if(a.set(e,t),a.size>=this.multisigInfo.threshold)break}if(a.size>=this.multisigInfo.threshold)break}}n=await this.prepareWitnessArgsAt(n,i.position,e=>{e.signatures=Array.from(a.values())})}return n}},ai=class extends ii{constructor(e,n,r,i){super(e,r,i),this.privateKey=t.yr(n),this.signer=new ti(e,this.privateKey)}async signOnlyTransaction(e){let n=t._.from(e),r=t.hr(this.signer.publicKey),i=this.multisigInfo.publicKeyHashes.indexOf(r);if(i===-1)return n;let a=i<this.multisigInfo.mustMatch;for(let{script:e}of await this.scriptInfos){let t=await this.getSignInfo(n,e);t&&(n=await this.prepareWitnessArgsAt(n,t.position,async e=>{let n=[],i=0,o=!0;for(let{pubkeyHash:a,signature:s,isRequired:c}of e.generatePublicKeyHashesFromSignatures(t.message)){if(a===r){if(!o)continue;o=!1}if(c)i+=1;else if(n.length-i>=this.multisigInfo.flexibleThreshold)continue;if(n.push(s),n.length>=this.multisigInfo.threshold){o=!1;break}}return o&&(a||n.length-i<this.multisigInfo.flexibleThreshold)&&n.push(Nr(t.message,this.privateKey)),e.signatures=n,e}))}return n}},oi=class extends Q{get type(){return`Doge`}get signType(){return`DogeEcdsa`}async getInternalAddress(){return this.getDogeAddress()}async getIdentity(){return this.getDogeAddress()}async getAddressObjs(){let e=Er.decode(await this.getDogeAddress()).slice(1);return[await R.fromKnownScript(this.client,`OmniLock`,t.yr([5,...e,0]))]}async prepareTransaction(e){let n=t._.from(e),{script:r}=await this.getRecommendedAddressObj();return await n.addCellDepsOfKnownScripts(this.client,`OmniLock`),await n.prepareSighashAllWitness(r,85,this.client),n}async signOnlyTransaction(e){let n=t._.from(e),{script:r}=await this.getRecommendedAddressObj(),i=await n.getSignHashInfo(r,this.client);if(!i)return n;let a=t.Zr(await this.signMessageRaw(i.message.slice(2)),`base64`);a[0]=31+(a[0]-27)%4;let o=t.v.fromBytes(n.witnesses[i.position]);return o.lock=t.yr(t.Jr(t.rr(20+a.length,4),t.rr(16,4),t.rr(20+a.length,4),t.rr(20+a.length,4),t.rr(a.length,4),a)),n.setWitnessArgs(i.position,o),n}},si=class extends oi{constructor(e,t){super(e),this.address=t}async connect(){}async isConnected(){return!0}async getDogeAddress(){return this.address}},ci=class extends oi{constructor(e,n,r=30){if(super(e),this.dogeNetwork=r,this.privateKey=t.Zr(n),this.privateKey.length!==32)throw Error(`Private key must be 32 bytes!`)}async connect(){}async isConnected(){return!0}async getDogePublicKey(){return t.yr(kn.getPublicKey(this.privateKey,!0))}async getDogeAddress(){return Ar(await this.getDogePublicKey(),this.dogeNetwork)}async signMessageRaw(e){let n=typeof e==`string`?e:t.yr(e).slice(2),r=kn.sign(zr(n),this.privateKey,{format:`recovered`,prehash:!1});return t.Qr(t.Jr([31+Number(r[0])],r.slice(1)),`base64`)}},li=class extends Q{get signType(){return`Unknown`}constructor(e,t){super(e),this.type=t}async isConnected(){return!1}async getInternalAddress(){throw Error(`Can't get address from SignerDummy`)}async getAddressObjs(){throw Error(`Can't get addresses from SignerDummy`)}},ui=class extends li{constructor(e,t,n){super(e,t),this.message=n}async connect(){throw Error(this.message)}},di=class extends li{constructor(e,t,n){super(e,t),this.link=n}async connect(){window.open(this.link,`_blank`)?.focus()}},fi=class extends Q{get type(){return`EVM`}get signType(){return`EvmPersonal`}async getInternalAddress(){return this.getEvmAccount()}async getAddressObjs(){let e=await this.getEvmAccount();return(await Promise.all([this._getOmniLockAddresses(e),this._getPWLockAddresses(e)])).flat()}_getOmniLockAddresses(e){return Promise.all([this._getOmniLockEvmAddressObj(e),this._getOmniLockOldEvmAddressObj(e)])}async _getPWLockAddresses(e){let t=await this._getPWLockEvmAddressObj(e);return t?[t]:[]}async _getOmniLockEvmAddressObj(e){return R.fromKnownScript(this.client,`OmniLock`,t.yr([18,...t.Zr(e),0]))}async _getOmniLockOldEvmAddressObj(e){return R.fromKnownScript(this.client,`OmniLock`,t.yr([1,...t.Zr(e),0]))}async _getPWLockEvmAddressObj(e){try{return R.fromKnownScript(this.client,`PWLock`,t.yr(t.Zr(e)))}catch{}}async prepareTransaction(e){let n=t._.from(e);await n.findInputIndexByLockId(await this.client.getKnownScript(`OmniLock`),this.client)!==void 0&&await n.addCellDepsOfKnownScripts(this.client,`OmniLock`),await n.findInputIndexByLockId(await this.client.getKnownScript(`PWLock`),this.client)!==void 0&&await n.addCellDepsOfKnownScripts(this.client,`PWLock`);let r=await this.getEvmAccount(),i=await this._getOmniLockAddresses(r);return t.kt(await this._getPWLockAddresses(r),(e,{script:t})=>e.prepareSighashAllWitness(t,65,this.client),t.kt(i,(e,{script:t})=>e.prepareSighashAllWitness(t,85,this.client),n))}async signOnlyTransaction(e){let n=t._.from(e),r=await this.getEvmAccount(),{script:i}=await this._getOmniLockEvmAddressObj(r),{script:a}=await this._getOmniLockOldEvmAddressObj(r);n=await this._signOmniLockScriptForTransaction(n,i,e=>`CKB transaction: ${e}`),n=await this._signOmniLockScriptForTransaction(n,a,e=>t.Zr(e));let o=await this._getPWLockEvmAddressObj(r);return o&&(n=await this._signPWLockScriptForTransaction(n,o.script,e=>t.Zr(e))),n}async _signOmniLockScriptForTransaction(e,n,r){let i=await this._signPersonalEvmForTransaction(e,n,r);if(!i)return e;let a=t.v.fromBytes(e.witnesses[i.position]);return a.lock=t.yr(t.Jr(t.rr(20+i.signature.length,4),t.rr(16,4),t.rr(20+i.signature.length,4),t.rr(20+i.signature.length,4),t.rr(i.signature.length,4),i.signature)),e.setWitnessArgs(i.position,a),e}async _signPWLockScriptForTransaction(e,n,r){let i=await this._signPersonalEvmForTransaction(e,n,r,new E);if(!i)return e;let a=t.v.fromBytes(e.witnesses[i.position]);return a.lock=t.yr(i.signature),e.setWitnessArgs(i.position,a),e}async _signPersonalEvmForTransaction(e,n,r,i){let a=await e.getSignHashInfo(n,this.client,i);if(!a)return;let o=t.Zr(await this.signMessageRaw(r(a.message)));return o[o.length-1]>=27&&(o[o.length-1]-=27),{signature:o,position:a.position}}},pi=class extends fi{constructor(e,n){super(e),this.address=t.yr(n)}async connect(){}async isConnected(){return!0}async getEvmAccount(){return this.address}},mi=class e extends Q{static{this.CKB_SIG_HASH_ALL_TAG=`ckb_sighash_all`}static{this.CKB_UNLOCK_EVENT_KIND=23334}static{this.CKB_UNLOCK_EVENT_CONTENT=`Signing a CKB transaction
|
|
15
|
+
function rr(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`}function ir(e,...t){if(!rr(e))throw Error(`Uint8Array expected`);if(t.length>0&&!t.includes(e.length))throw Error(`Uint8Array expected of length `+t+`, got length=`+e.length)}function ar(e,t=!0){if(e.destroyed)throw Error(`Hash instance has been destroyed`);if(t&&e.finished)throw Error(`Hash#digest() has already been called`)}function or(e,t){ir(e);let n=t.outputLen;if(e.length<n)throw Error(`digestInto() expects output buffer of length at least `+n)}function sr(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function cr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Z(e,t){return e<<32-t|e>>>t}function lr(e){if(typeof e!=`string`)throw Error(`string expected`);return new Uint8Array(new TextEncoder().encode(e))}function ur(e){return typeof e==`string`&&(e=lr(e)),ir(e),e}var dr=class{};function fr(e){let t=t=>e().update(ur(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function pr(e,t,n,r){if(typeof e.setBigUint64==`function`)return e.setBigUint64(t,n,r);let i=BigInt(32),a=BigInt(4294967295),o=Number(n>>i&a),s=Number(n&a),c=r?4:0,l=r?0:4;e.setUint32(t+c,o,r),e.setUint32(t+l,s,r)}function mr(e,t,n){return e&t^~e&n}function hr(e,t,n){return e&t^e&n^t&n}var gr=class extends dr{constructor(e,t,n,r){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.buffer=new Uint8Array(e),this.view=cr(this.buffer)}update(e){ar(this),e=ur(e),ir(e);let{view:t,buffer:n,blockLen:r}=this,i=e.length;for(let a=0;a<i;){let o=Math.min(r-this.pos,i-a);if(o===r){let t=cr(e);for(;r<=i-a;a+=r)this.process(t,a);continue}n.set(e.subarray(a,a+o),this.pos),this.pos+=o,a+=o,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){ar(this),or(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:r,isLE:i}=this,{pos:a}=this;t[a++]=128,sr(this.buffer.subarray(a)),this.padOffset>r-a&&(this.process(n,0),a=0);for(let e=a;e<r;e++)t[e]=0;pr(n,r-8,BigInt(this.length*8),i),this.process(n,0);let o=cr(e),s=this.outputLen;if(s%4)throw Error(`_sha2: outputLen should be aligned to 32bit`);let c=s/4,l=this.get();if(c>l.length)throw Error(`_sha2: outputLen bigger than state`);for(let e=0;e<c;e++)o.setUint32(4*e,l[e],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:t,buffer:n,length:r,finished:i,destroyed:a,pos:o}=this;return e.destroyed=a,e.finished=i,e.length=r,e.pos=o,r%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}};const _r=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),vr=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]),yr=new Uint32Array(64);var br=class extends gr{constructor(e=32){super(64,e,8,!1),this.A=_r[0]|0,this.B=_r[1]|0,this.C=_r[2]|0,this.D=_r[3]|0,this.E=_r[4]|0,this.F=_r[5]|0,this.G=_r[6]|0,this.H=_r[7]|0}get(){let{A:e,B:t,C:n,D:r,E:i,F:a,G:o,H:s}=this;return[e,t,n,r,i,a,o,s]}set(e,t,n,r,i,a,o,s){this.A=e|0,this.B=t|0,this.C=n|0,this.D=r|0,this.E=i|0,this.F=a|0,this.G=o|0,this.H=s|0}process(e,t){for(let n=0;n<16;n++,t+=4)yr[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){let t=yr[e-15],n=yr[e-2],r=Z(t,7)^Z(t,18)^t>>>3,i=Z(n,17)^Z(n,19)^n>>>10;yr[e]=i+yr[e-7]+r+yr[e-16]|0}let{A:n,B:r,C:i,D:a,E:o,F:s,G:c,H:l}=this;for(let e=0;e<64;e++){let t=Z(o,6)^Z(o,11)^Z(o,25),u=l+t+mr(o,s,c)+vr[e]+yr[e]|0,d=(Z(n,2)^Z(n,13)^Z(n,22))+hr(n,r,i)|0;l=c,c=s,s=o,o=a+u|0,a=i,i=r,r=n,n=u+d|0}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,a=a+this.D|0,o=o+this.E|0,s=s+this.F|0,c=c+this.G|0,l=l+this.H|0,this.set(n,r,i,a,o,s,c,l)}roundClean(){sr(yr)}destroy(){this.set(0,0,0,0,0,0,0,0),sr(this.buffer)}};const xr=fr(()=>new br);function Sr(e){if(e.length>=255)throw TypeError(`Alphabet too long`);let t=new Uint8Array(256);for(let e=0;e<t.length;e++)t[e]=255;for(let n=0;n<e.length;n++){let r=e.charAt(n),i=r.charCodeAt(0);if(t[i]!==255)throw TypeError(r+` is ambiguous`);t[i]=n}let n=e.length,r=e.charAt(0),i=Math.log(n)/Math.log(256),a=Math.log(256)/Math.log(n);function o(t){if(t instanceof Uint8Array||(ArrayBuffer.isView(t)?t=new Uint8Array(t.buffer,t.byteOffset,t.byteLength):Array.isArray(t)&&(t=Uint8Array.from(t))),!(t instanceof Uint8Array))throw TypeError(`Expected Uint8Array`);if(t.length===0)return``;let i=0,o=0,s=0,c=t.length;for(;s!==c&&t[s]===0;)s++,i++;let l=(c-s)*a+1>>>0,u=new Uint8Array(l);for(;s!==c;){let e=t[s],r=0;for(let t=l-1;(e!==0||r<o)&&t!==-1;t--,r++)e+=256*u[t]>>>0,u[t]=e%n>>>0,e=e/n>>>0;if(e!==0)throw Error(`Non-zero carry`);o=r,s++}let d=l-o;for(;d!==l&&u[d]===0;)d++;let f=r.repeat(i);for(;d<l;++d)f+=e.charAt(u[d]);return f}function s(e){if(typeof e!=`string`)throw TypeError(`Expected String`);if(e.length===0)return new Uint8Array;let a=0,o=0,s=0;for(;e[a]===r;)o++,a++;let c=(e.length-a)*i+1>>>0,l=new Uint8Array(c);for(;a<e.length;){let r=e.charCodeAt(a);if(r>255)return;let i=t[r];if(i===255)return;let o=0;for(let e=c-1;(i!==0||o<s)&&e!==-1;e--,o++)i+=n*l[e]>>>0,l[e]=i%256>>>0,i=i/256>>>0;if(i!==0)throw Error(`Non-zero carry`);s=o,a++}let u=c-s;for(;u!==c&&l[u]===0;)u++;let d=new Uint8Array(o+(c-u)),f=o;for(;u!==c;)d[f++]=l[u++];return d}function c(e){let t=s(e);if(t)return t;throw Error(`Non-base`+n+` character`)}return{encode:o,decodeUnsafe:s,decode:c}}var Cr=Sr(`123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz`);function wr(e){function t(t){var n=Uint8Array.from(t),r=e(n),i=n.length+4,a=new Uint8Array(i);return a.set(n,0),a.set(r.subarray(0,4),n.length),Cr.encode(a)}function n(t){var n=t.slice(0,-4),r=t.slice(-4),i=e(n);if(!(r[0]^i[0]|r[1]^i[1]|r[2]^i[2]|r[3]^i[3]))return n}function r(e){var t=Cr.decodeUnsafe(e);if(t!=null)return n(t)}function i(e){var t=n(Cr.decode(e));if(t==null)throw Error(`Invalid checksum`);return t}return{encode:t,decode:i,decodeUnsafe:r}}function Tr(e){return xr(xr(e))}var Er=wr(Tr);function Dr(e){let n=t.Qn(e);return n<253?t.tr(n,1):n<=65535?t.Yr([253],t.tr(n,2)):n<=4294967295?t.Yr([254],t.tr(n,4)):t.Yr([255],t.tr(n,8))}function Or(e,n){let r=n??`Bitcoin Signed Message:
|
|
16
|
+
`,i=typeof r==`string`?t.Qr(r,`utf8`):t.Qr(r),a=typeof e==`string`?t.Qr(e,`utf8`):t.Qr(e);return H(H(t.Yr(i,Dr(a.length),a)))}function kr(e){return nr(H(t.Qr(e)))}function Ar(e,n){return Er.encode(t.Yr([n],kr(e)))}function jr(e){return t.br(Er.decode(e).slice(1))}function Mr(e,n,r){let i=typeof e==`string`?e:t.br(e).slice(2),a=t.Qr(n,`base64`).slice(1);return kn.verify(t.Qr(a),Or(i),t.Qr(r),{prehash:!1})}function Nr(e,n){let r=kn.sign(t.Qr(e),t.Qr(n),{format:`recovered`,prehash:!1});return t.br(t.Yr(r.slice(1),r.slice(0,1)))}function Pr(e,n,r){let i=t.Qr(n);return kn.verify(t.Yr(i.slice(64),i.slice(0,64)),t.Qr(e),t.Qr(r),{format:`recovered`,prehash:!1})}function Fr(e,n){let r=t.Qr(n);return t.br(kn.recoverPublicKey(t.Yr(r.slice(64),r.slice(0,64)),t.Qr(e),{prehash:!1}))}function Ir(e){return t.hr(t.Qr(`Nervos Message:${typeof e==`string`?e:t.br(e)}`,`utf8`))}function Lr(e,t,n){return Pr(Ir(e),t,n)}async function Rr(e,n,r){let a=typeof e==`string`?e:t.br(e).slice(2),{address:o,publicKey:s,keyType:c}=JSON.parse(r),l=JSON.parse(n);if(!await(0,i.verifySignature)({challenge:a,pubkey:s,keyType:c,...l}))return!1;let u=o.startsWith(`ckb`)?`https://api.joy.id/api/v1/`:`https://api.testnet.joyid.dev/api/v1/`;return(0,i.verifyCredential)({pubkey:s,address:o,keyType:c,alg:l.alg},u)}function zr(e,t){return Or(e,t??`Dogecoin Signed Message:
|
|
17
|
+
`)}function Br(e,n,r){let i=typeof e==`string`?e:t.br(e).slice(2),a=t.Qr(n,`base64`);return a[0]-=31,jr(r)===t.br(kr(kn.recoverPublicKey(a,zr(i),{prehash:!1})))}function Vr(e,n,r){return r.toLowerCase()===(0,a.verifyMessage)(typeof e==`string`?e:t.Qr(e),n).toLowerCase()}function Hr(e){if(typeof e==`string`)try{let t=JSON.parse(e);if(typeof t==`object`&&typeof t.created_at==`number`&&typeof t.kind==`number`&&typeof t.content==`string`&&Array.isArray(t.tags)&&t.tags.every(e=>Array.isArray(e)&&e.every(e=>typeof e==`string`)))return t}catch{}return{kind:23335,created_at:0,content:typeof e==`string`?e:t.br(e),tags:[]}}function Ur(e){return H(t.Qr(JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content]),`utf8`))}function Wr(e,r,i){let{words:a}=n.bech32.decode(i),o=t.br(n.bech32.fromWords(a)).slice(2),s=Ur({...Hr(e),pubkey:o});try{return Vn.verify(t.Qr(r),s,t.Qr(o))}catch{return!1}}let Gr=function(e){return e.Unknown=`Unknown`,e.BtcEcdsa=`BtcEcdsa`,e.EvmPersonal=`EvmPersonal`,e.JoyId=`JoyId`,e.NostrEvent=`NostrEvent`,e.CkbSecp256k1=`CkbSecp256k1`,e.DogeEcdsa=`DogeEcdsa`,e}({}),Kr=function(e){return e.EVM=`EVM`,e.BTC=`BTC`,e.CKB=`CKB`,e.Nostr=`Nostr`,e.Doge=`Doge`,e}({});var qr=class{constructor(e,t,n){this.signature=e,this.identity=t,this.signType=n}},Q=class e{constructor(e){this.client_=e}get client(){return this.client_}matchNetworkPreference(e,t){if(!(t!==void 0&&e.some(({signerType:e,addressPrefix:n,network:r})=>e===this.type&&n===this.client.addressPrefix&&r===t)))return e.find(({signerType:e,addressPrefix:t})=>e===this.type&&t===this.client.addressPrefix)}static async verifyMessage(e,t){switch(t.signType){case`EvmPersonal`:return Vr(e,t.signature,t.identity);case`BtcEcdsa`:return Mr(e,t.signature,t.identity);case`JoyId`:return Rr(e,t.signature,t.identity);case`NostrEvent`:return Wr(e,t.signature,t.identity);case`CkbSecp256k1`:return Lr(e,t.signature,t.identity);case`DogeEcdsa`:return Br(e,t.signature,t.identity);case`Unknown`:throw Error(`Unknown signer sign type`)}}static async fromSignature(e,t,n,...r){throw Error(`Signer.fromSignature should be override to avoid circular references`)}onReplaced(e){return()=>{}}async disconnect(){}async getIdentity(){return this.getInternalAddress()}async getRecommendedAddressObj(e){return(await this.getAddressObjs())[0]}async getRecommendedAddress(e){return(await this.getRecommendedAddressObj(e)).toString()}async getAddresses(){return this.getAddressObjs().then(e=>e.map(e=>e.toString()))}async*findCellsOnChain(e,t,n,r){let i=await this.getAddressObjs();for(let{script:a}of i)for await(let i of this.client.findCellsOnChain({script:a,scriptType:`lock`,filter:e,scriptSearchMode:`exact`,withData:t},n,r))yield i}async*findCells(e,t,n,r){let i=await this.getAddressObjs();for(let{script:a}of i)for await(let i of this.client.findCells({script:a,scriptType:`lock`,filter:e,scriptSearchMode:`exact`,withData:t},n,r))yield i}async*findTransactions(e,t,n,r){let i=await this.getAddressObjs();for(let{script:a}of i)for await(let i of this.client.findTransactions({script:a,scriptType:`lock`,filter:e,scriptSearchMode:`exact`,groupByTransaction:t},n,r))yield i}async getBalance(){return this.client.getBalance((await this.getAddressObjs()).map(({script:e})=>e))}async signMessage(e){return{signature:await this.signMessageRaw(e),identity:await this.getIdentity(),signType:this.signType}}signMessageRaw(e){throw Error(`Signer.signMessageRaw not implemented`)}async verifyMessage(t,n){return typeof n==`string`?e.verifyMessage(t,{signType:this.signType,signature:n,identity:await this.getIdentity()}):n.identity!==await this.getIdentity()||![`Unknown`,this.signType].includes(n.signType)?!1:e.verifyMessage(t,n)}async sendTransaction(e){return this.client.sendTransaction(await this.signTransaction(e))}async signTransaction(e){let t=await this.prepareTransaction(e);return this.signOnlyTransaction(t)}async prepareTransaction(e){return t._.from(e)}signOnlyTransaction(e){throw Error(`Signer.signOnlyTransaction not implemented`)}},Jr=class extends Q{async sendTransaction(e){let t=await this.signTransaction(e);if(await this.needMoreSignatures(t))throw new Yr(await this.getSignaturesCount(t)??0,await this.getMemberThreshold());return this.client.sendTransaction(t)}},Yr=class extends Error{constructor(e,t){let n=`Not enough signatures: got ${e}, need ${t}`;super(n),this.name=`SignerMultisigNotEnoughSignaturesError`,this.signaturesCount=e,this.threshold=t}},Xr=class{constructor(e,t){this.name=e,this.signer=t}},Zr=class extends Q{get type(){return`BTC`}get signType(){return`BtcEcdsa`}async signAndBroadcastPsbt(e,t){let n=await this.signPsbt(e,t);return this.broadcastPsbt(n,t)}async getInternalAddress(){return this.getBtcAccount()}async getIdentity(){return t.br(await this.getBtcPublicKey()).slice(2)}async getAddressObjs(){let e=kr(await this.getBtcPublicKey());return[await R.fromKnownScript(this.client,`OmniLock`,t.br([4,...e,0]))]}async prepareTransaction(e){let n=t._.from(e),{script:r}=await this.getRecommendedAddressObj();return await n.addCellDepsOfKnownScripts(this.client,`OmniLock`),await n.prepareSighashAllWitness(r,85,this.client),n}async signOnlyTransaction(e){let n=t._.from(e),{script:r}=await this.getRecommendedAddressObj(),i=await n.getSignHashInfo(r,this.client);if(!i)return n;let a=t.Qr(await this.signMessageRaw(`CKB (Bitcoin Layer) transaction: ${i.message}`),`base64`);a[0]=31+(a[0]-27)%4;let o=t.v.fromBytes(n.witnesses[i.position]);return o.lock=t.br(t.Yr(t.ir(20+a.length,4),t.ir(16,4),t.ir(20+a.length,4),t.ir(20+a.length,4),t.ir(a.length,4),a)),n.setWitnessArgs(i.position,o),n}},Qr=class extends Zr{constructor(e,n,r){super(e),this.account=n,this.publicKey=t.br(r)}async connect(){}async isConnected(){return!0}async getBtcAccount(){return this.account}async getBtcPublicKey(){return this.publicKey}async signPsbt(e,t){throw Error(`Read-only signer does not support signPsbt`)}async broadcastPsbt(e,t){throw Error(`Read-only signer does not support broadcastPsbt`)}},$r=class extends Q{get type(){return`CKB`}get signType(){return`Unknown`}constructor(e){super(e)}async connect(){}async isConnected(){return!0}async getInternalAddress(){return this.getRecommendedAddress()}async getAddressObjs(){return[await R.fromKnownScript(this.client,`AlwaysSuccess`,`0x`)]}async prepareTransaction(e){let n=t._.from(e);return await n.addCellDepsOfKnownScripts(this.client,`AlwaysSuccess`),n}async signOnlyTransaction(e){return t._.from(e)}},ei=class extends Q{get type(){return`CKB`}get signType(){return`CkbSecp256k1`}constructor(e,n){if(super(e),this.publicKey=t.br(n),t.Qr(this.publicKey).length!==33)throw Error(`Public key must be 33 bytes!`)}async connect(){}async isConnected(){return!0}async getInternalAddress(){return this.getRecommendedAddress()}async getIdentity(){return this.publicKey}async getAddressObjSecp256k1(){return R.fromKnownScript(this.client,`Secp256k1Blake160`,t.gr(this.publicKey))}async getRecommendedAddressObj(e){return this.getAddressObjSecp256k1()}async getAddressObjs(){let e=await this.getAddressObjSecp256k1(),n=[],r=0;for await(let i of this.client.findCells({script:await t.M.fromKnownScript(this.client,`AnyoneCanPay`,e.script.args),scriptType:`lock`,scriptSearchMode:`prefix`,withData:!1})){if(r>=10)break;r+=1,!n.some(({script:e})=>e.eq(i.cellOutput.lock))&&n.push(R.from({prefix:this.client.addressPrefix,script:i.cellOutput.lock}))}return[e,...n]}async getRelatedScripts(e){let n=t._.from(e),r=await this.getAddressObjSecp256k1(),i=await t.M.fromKnownScript(this.client,`AnyoneCanPay`,r.script.args),a=[];for(let e of n.inputs){let{cellOutput:{lock:t}}=await e.getCell(this.client);a.some(({script:e})=>e.eq(t))||(t.eq(r.script)?a.push({script:t,cellDeps:(await this.client.getKnownScript(`Secp256k1Blake160`)).cellDeps}):t.codeHash===i.codeHash&&t.hashType===i.hashType&&t.args.startsWith(i.args)&&a.push({script:t,cellDeps:(await this.client.getKnownScript(`AnyoneCanPay`)).cellDeps}))}return a}async prepareTransaction(e){let n=t._.from(e);return await Promise.all((await this.getRelatedScripts(n)).map(async({script:e,cellDeps:t})=>{await n.prepareSighashAllWitness(e,65,this.client),await n.addCellDepInfos(this.client,t)})),n}},ti=class extends ei{constructor(e,n){let r=t.br(n);if(t.Qr(r).length!==32)throw Error(`Private key must be 32 bytes!`);super(e,kn.getPublicKey(t.Qr(r),!0)),this.privateKey=r}async _signMessage(e){return Nr(e,this.privateKey)}async signMessageRaw(e){return this._signMessage(Ir(e))}async signOnlyTransaction(e){let n=t._.from(e);for(let{script:e}of await this.getRelatedScripts(n)){let r=await n.getSignHashInfo(e,this.client);if(!r)return n;let i=await this._signMessage(r.message),a=n.getWitnessArgs(r.position)??t.v.from({});a.lock=i,n.setWitnessArgs(r.position,a)}return n}},ni=class extends Q{get type(){return`CKB`}get signType(){return`Unknown`}constructor(e,...n){if(super(e),this.scripts=n.flat().map(t.M.from),this.scripts.length===0)throw Error(`SignerCkbScriptReadonly requires at least one script.`)}async connect(){}async isConnected(){return!0}async getInternalAddress(){return this.getRecommendedAddress()}async getAddressObjs(){return this.scripts.map(e=>R.fromScript(e,this.client))}},ri;const ii=t.qr.from({encode:e=>{let{publicKeyHashes:n,threshold:r,mustMatch:i,signatures:a}=$.from(e);if(a.some(e=>e.length!==132))throw Error(`MultisigCkbWitness: invalid signature length`);if(n.some(e=>e.length!==42))throw Error(`MultisigCkbWitness: invalid public key hash length`);return t.Yr(`0x00`,t.ir(i??0),t.ir(r),t.ir(n.length),...n,...a)},decode:e=>{if(e.length<4)throw Error(`MultisigCkbWitness: data length too short`);let[n,r,i,a,...o]=e;if(o.length<a*20)throw Error(`MultisigCkbWitness: invalid public key hashes length`);let s=o.slice(a*20);return{publicKeyHashes:Array.from(Array(a),(e,n)=>t.br(o.slice(n*20,(n+1)*20))),threshold:i,mustMatch:r,signatures:Array.from(Array(Math.floor(s.length/65)),(e,n)=>t.br(s.slice(n*65,(n+1)*65)))}}});let $=ri=class extends t.ur.Base(){constructor({publicKeyHashes:e,threshold:t,mustMatch:n,signatures:r}){super();let i=e.length;if(t<=0||t>i)throw Error(`threshold should be in range from 1 to public keys length`);if(n<0||n>Math.min(i,t))throw Error(`mustMatch should be in range from 0 to min(public keys length, threshold)`);if(i>255)throw Error(`public keys length should be less than 256`);this.publicKeyHashes=e,this.threshold=t,this.mustMatch=n,this.signatures=r}static from(e){let n=e.publicKeyHashes?e.publicKeyHashes:e.publicKeys.map(e=>t.gr(e));return new ri({publicKeyHashes:n.map(t.br),threshold:Number(t.Qn(e.threshold)),mustMatch:Number(t.Qn(e.mustMatch??0)),signatures:e.signatures?.map(t.br)??[]})}get flexibleThreshold(){return this.threshold-this.mustMatch}scriptArgs(e){let n=t.gr(ri.from({...this,signatures:[]}).toBytes());return e==null?t.Qr(n):t.Yr(n,t.g.from(e).toBytes())}eqInfo(e){let t=ri.from(e);return this.publicKeyHashes.length===t.publicKeyHashes.length&&this.publicKeyHashes.every((e,n)=>e===t.publicKeyHashes[n])&&this.threshold===t.threshold&&this.mustMatch===t.mustMatch}*generatePublicKeyHashesFromSignatures(e){let n=new Set;for(let r of this.signatures.filter(e=>e!==ai.EmptySignature)){let i=(()=>{try{return Fr(e,r)}catch{return}})();if(i===void 0)continue;let a=t.gr(i);if(n.has(a))continue;let o=this.publicKeyHashes.indexOf(a);o!==-1&&(n.add(a),yield{pubkeyHash:a,signature:r,isRequired:o<this.mustMatch})}}calcMatchedSignaturesCount(e){let t=0,n=0;for(let{isRequired:r}of this.generatePublicKeyHashesFromSignatures(e))r?t+=1:n+=1;return{required:t,flexible:n}}};$=ri=t.Tt([t.dr(ii)],$);var ai=class e extends Jr{static{this.EmptySignature=t.br(`00`.repeat(65))}get type(){return`CKB`}get signType(){return`Unknown`}constructor(e,n,r){super(e),this.multisigInfo=$.from(n),this.since=t.Et(t.g.from,r?.since);let i=this.multisigInfo.scriptArgs(this.since);this.scriptInfos=Promise.all((r?.scriptInfos??[`Secp256k1MultisigV2`,`Secp256k1MultisigV2Beta`,`Secp256k1Multisig`]).map(async n=>{if(typeof n!=`string`)return t._t.from(n);try{return await e.getKnownScript(n)}catch{return}})).then(e=>e.filter(e=>e!==void 0).map(e=>({script:t.M.from({...e,args:i}),cellDeps:e.cellDeps})))}async getMemberCount(){return this.multisigInfo.publicKeyHashes.length}async getMemberThreshold(){return this.multisigInfo.threshold}async getMemberRequiredCount(){return this.multisigInfo.mustMatch}async connect(){}async isConnected(){return!0}async getInternalAddress(){return this.getRecommendedAddress()}async getAddressObjs(){return(await this.scriptInfos).map(({script:e})=>R.fromScript(e,this.client))}decodeWitnessArgsAt(e,n){let r=t._.from(e);return this.decodeWitnessArgs(r.getWitnessArgs(n))}decodeWitnessArgs(e){if(!e)return;let n=t.v.from(e);if(n.lock!=null)try{let e=$.decode(n.lock);if(e.eqInfo(this.multisigInfo))return e}catch{}}async prepareWitnessArgsAt(n,r,i){let a=t._.from(n),o=a.getWitnessArgs(r)??t.v.from({}),s=this.decodeWitnessArgs(o)??this.multisigInfo.clone(),c=$.from(await i?.(s,o)??s);return c.signatures=c.signatures.slice(0,this.multisigInfo.threshold),c.signatures.push(...Array.from(Array(this.multisigInfo.threshold-c.signatures.length),()=>e.EmptySignature)),o.lock=c.toHex(),a.setWitnessArgs(r,o),a}async prepareTransactionOneScript(e,n,r){let i=t._.from(e),a=await i.findInputIndexByLock(n,this.client);return a===void 0?i:(await i.addCellDepInfos(this.client,r),this.prepareWitnessArgsAt(i,a))}async prepareTransaction(e){return await t.At(await this.scriptInfos,(e,{script:t,cellDeps:n})=>this.prepareTransactionOneScript(e,t,n),t._.from(e))}async getSignaturesCount(e){let n=t._.from(e),r;for(let{script:e}of await this.scriptInfos){let t=await this.getSignInfo(n,e);if(t===void 0)continue;let i=this.decodeWitnessArgsAt(n,t.position);if(!i){r=0;continue}let{required:a,flexible:o}=i.calcMatchedSignaturesCount(t.message);r=Math.min(r??256,a+Math.min(o,this.multisigInfo.flexibleThreshold))}return r}async needMoreSignatures(e){let t=await this.getSignaturesCount(e);return t!=null&&t<await this.getMemberThreshold()}async getSignInfo(n,r){let i=t._.from(n),a=await i.findInputIndexByLock(r,this.client);if(a==null)return;let o=i.getWitnessArgs(a)??t.v.from({});o.lock=$.from({...this.multisigInfo,signatures:Array.from(Array(this.multisigInfo.threshold),()=>e.EmptySignature)}).toHex();let s=i.clone();return s.setWitnessArgs(a,o),s.getSignHashInfo(r,this.client)}async aggregateTransactions(e){if(e.length===0)throw Error(`No transaction to aggregate`);let n=t._.from(e[0]);for(let{script:r}of await this.scriptInfos){let i=await this.getSignInfo(n,r);if(i===void 0)continue;let a=new Map,o=0;for(let n of e){let e=t._.from(n),r=this.decodeWitnessArgsAt(e,i.position);if(r){for(let{pubkeyHash:e,signature:t,isRequired:n}of r.generatePublicKeyHashesFromSignatures(i.message))if(!a.has(e)){if(n)o+=1;else if(a.size-o>=this.multisigInfo.flexibleThreshold)continue;if(a.set(e,t),a.size>=this.multisigInfo.threshold)break}if(a.size>=this.multisigInfo.threshold)break}}n=await this.prepareWitnessArgsAt(n,i.position,e=>{e.signatures=Array.from(a.values())})}return n}},oi=class extends ai{constructor(e,n,r,i){super(e,r,i),this.privateKey=t.br(n),this.signer=new ti(e,this.privateKey)}async signOnlyTransaction(e){let n=t._.from(e),r=t.gr(this.signer.publicKey),i=this.multisigInfo.publicKeyHashes.indexOf(r);if(i===-1)return n;let a=i<this.multisigInfo.mustMatch;for(let{script:e}of await this.scriptInfos){let t=await this.getSignInfo(n,e);t&&(n=await this.prepareWitnessArgsAt(n,t.position,async e=>{let n=[],i=0,o=!0;for(let{pubkeyHash:a,signature:s,isRequired:c}of e.generatePublicKeyHashesFromSignatures(t.message)){if(a===r){if(!o)continue;o=!1}if(c)i+=1;else if(n.length-i>=this.multisigInfo.flexibleThreshold)continue;if(n.push(s),n.length>=this.multisigInfo.threshold){o=!1;break}}return o&&(a||n.length-i<this.multisigInfo.flexibleThreshold)&&n.push(Nr(t.message,this.privateKey)),e.signatures=n,e}))}return n}},si=class extends Q{get type(){return`Doge`}get signType(){return`DogeEcdsa`}async getInternalAddress(){return this.getDogeAddress()}async getIdentity(){return this.getDogeAddress()}async getAddressObjs(){let e=Er.decode(await this.getDogeAddress()).slice(1);return[await R.fromKnownScript(this.client,`OmniLock`,t.br([5,...e,0]))]}async prepareTransaction(e){let n=t._.from(e),{script:r}=await this.getRecommendedAddressObj();return await n.addCellDepsOfKnownScripts(this.client,`OmniLock`),await n.prepareSighashAllWitness(r,85,this.client),n}async signOnlyTransaction(e){let n=t._.from(e),{script:r}=await this.getRecommendedAddressObj(),i=await n.getSignHashInfo(r,this.client);if(!i)return n;let a=t.Qr(await this.signMessageRaw(i.message.slice(2)),`base64`);a[0]=31+(a[0]-27)%4;let o=t.v.fromBytes(n.witnesses[i.position]);return o.lock=t.br(t.Yr(t.ir(20+a.length,4),t.ir(16,4),t.ir(20+a.length,4),t.ir(20+a.length,4),t.ir(a.length,4),a)),n.setWitnessArgs(i.position,o),n}},ci=class extends si{constructor(e,t){super(e),this.address=t}async connect(){}async isConnected(){return!0}async getDogeAddress(){return this.address}},li=class extends si{constructor(e,n,r=30){if(super(e),this.dogeNetwork=r,this.privateKey=t.Qr(n),this.privateKey.length!==32)throw Error(`Private key must be 32 bytes!`)}async connect(){}async isConnected(){return!0}async getDogePublicKey(){return t.br(kn.getPublicKey(this.privateKey,!0))}async getDogeAddress(){return Ar(await this.getDogePublicKey(),this.dogeNetwork)}async signMessageRaw(e){let n=typeof e==`string`?e:t.br(e).slice(2),r=kn.sign(zr(n),this.privateKey,{format:`recovered`,prehash:!1});return t.$r(t.Yr([31+Number(r[0])],r.slice(1)),`base64`)}},ui=class extends Q{get signType(){return`Unknown`}constructor(e,t){super(e),this.type=t}async isConnected(){return!1}async getInternalAddress(){throw Error(`Can't get address from SignerDummy`)}async getAddressObjs(){throw Error(`Can't get addresses from SignerDummy`)}},di=class extends ui{constructor(e,t,n){super(e,t),this.message=n}async connect(){throw Error(this.message)}},fi=class extends ui{constructor(e,t,n){super(e,t),this.link=n}async connect(){window.open(this.link,`_blank`)?.focus()}},pi=class extends Q{get type(){return`EVM`}get signType(){return`EvmPersonal`}async getInternalAddress(){return this.getEvmAccount()}async getAddressObjs(){let e=await this.getEvmAccount();return(await Promise.all([this._getOmniLockAddresses(e),this._getPWLockAddresses(e)])).flat()}_getOmniLockAddresses(e){return Promise.all([this._getOmniLockEvmAddressObj(e),this._getOmniLockOldEvmAddressObj(e)])}async _getPWLockAddresses(e){let t=await this._getPWLockEvmAddressObj(e);return t?[t]:[]}async _getOmniLockEvmAddressObj(e){return R.fromKnownScript(this.client,`OmniLock`,t.br([18,...t.Qr(e),0]))}async _getOmniLockOldEvmAddressObj(e){return R.fromKnownScript(this.client,`OmniLock`,t.br([1,...t.Qr(e),0]))}async _getPWLockEvmAddressObj(e){try{return R.fromKnownScript(this.client,`PWLock`,t.br(t.Qr(e)))}catch{}}async prepareTransaction(e){let n=t._.from(e);await n.findInputIndexByLockId(await this.client.getKnownScript(`OmniLock`),this.client)!==void 0&&await n.addCellDepsOfKnownScripts(this.client,`OmniLock`),await n.findInputIndexByLockId(await this.client.getKnownScript(`PWLock`),this.client)!==void 0&&await n.addCellDepsOfKnownScripts(this.client,`PWLock`);let r=await this.getEvmAccount(),i=await this._getOmniLockAddresses(r);return t.At(await this._getPWLockAddresses(r),(e,{script:t})=>e.prepareSighashAllWitness(t,65,this.client),t.At(i,(e,{script:t})=>e.prepareSighashAllWitness(t,85,this.client),n))}async signOnlyTransaction(e){let n=t._.from(e),r=await this.getEvmAccount(),{script:i}=await this._getOmniLockEvmAddressObj(r),{script:a}=await this._getOmniLockOldEvmAddressObj(r);n=await this._signOmniLockScriptForTransaction(n,i,e=>`CKB transaction: ${e}`),n=await this._signOmniLockScriptForTransaction(n,a,e=>t.Qr(e));let o=await this._getPWLockEvmAddressObj(r);return o&&(n=await this._signPWLockScriptForTransaction(n,o.script,e=>t.Qr(e))),n}async _signOmniLockScriptForTransaction(e,n,r){let i=await this._signPersonalEvmForTransaction(e,n,r);if(!i)return e;let a=t.v.fromBytes(e.witnesses[i.position]);return a.lock=t.br(t.Yr(t.ir(20+i.signature.length,4),t.ir(16,4),t.ir(20+i.signature.length,4),t.ir(20+i.signature.length,4),t.ir(i.signature.length,4),i.signature)),e.setWitnessArgs(i.position,a),e}async _signPWLockScriptForTransaction(e,n,r){let i=await this._signPersonalEvmForTransaction(e,n,r,new E);if(!i)return e;let a=t.v.fromBytes(e.witnesses[i.position]);return a.lock=t.br(i.signature),e.setWitnessArgs(i.position,a),e}async _signPersonalEvmForTransaction(e,n,r,i){let a=await e.getSignHashInfo(n,this.client,i);if(!a)return;let o=t.Qr(await this.signMessageRaw(r(a.message)));return o[o.length-1]>=27&&(o[o.length-1]-=27),{signature:o,position:a.position}}},mi=class extends pi{constructor(e,n){super(e),this.address=t.br(n)}async connect(){}async isConnected(){return!0}async getEvmAccount(){return this.address}},hi=class e extends Q{static{this.CKB_SIG_HASH_ALL_TAG=`ckb_sighash_all`}static{this.CKB_UNLOCK_EVENT_KIND=23334}static{this.CKB_UNLOCK_EVENT_CONTENT=`Signing a CKB transaction
|
|
18
18
|
|
|
19
19
|
IMPORTANT: Please verify the integrity and authenticity of connected Nostr client before signing this message
|
|
20
|
-
`}get type(){return`Nostr`}get signType(){return`NostrEvent`}async signNostrEvent(e){throw Error(`SignerNostr.signNostrEvent not implemented`)}async signMessageRaw(e){return t.yr((await this.signNostrEvent(Hr(e))).sig)}async getInternalAddress(){return n.bech32.encode(`npub`,n.bech32.toWords(t.Zr(await this.getNostrPublicKey())))}async getAddressObjs(){let e=await this.getNostrPublicKey();return[await R.fromKnownScript(this.client,`NostrLock`,t.yr(t.Jr([0],t.mr(e).slice(0,42))))]}async prepareTransaction(e){let n=t._.from(e),{script:r}=await this.getRecommendedAddressObj();return await n.addCellDepsOfKnownScripts(this.client,`NostrLock`),await n.prepareSighashAllWitness(r,572,this.client),n}async signOnlyTransaction(n){let r=t._.from(n),{script:i}=await this.getRecommendedAddressObj(),a=await r.getSignHashInfo(i,this.client);if(!a)return r;let o=t.Zr(JSON.stringify(await this.signNostrEvent({pubkey:(await this.getNostrPublicKey()).slice(2),tags:[[e.CKB_SIG_HASH_ALL_TAG,a.message.slice(2)]],created_at:Math.floor(Date.now()/1e3),kind:e.CKB_UNLOCK_EVENT_KIND,content:e.CKB_UNLOCK_EVENT_CONTENT})),`utf8`),s=t.v.fromBytes(r.witnesses[a.position]);return s.lock=t.yr(o),r.setWitnessArgs(a.position,s),r}},hi=class extends mi{constructor(e,r){if(super(e),typeof r==`string`&&r.startsWith(`npub`)){let{words:e}=n.bech32.decode(r);this.publicKey=t.yr(n.bech32.fromWords(e))}else this.publicKey=t.yr(r)}async connect(){}async isConnected(){return!0}async getNostrPublicKey(){return this.publicKey}},gi=class extends hi{constructor(e,r){let i=(()=>{if(typeof r==`string`&&r.startsWith(`nsec`)){let{words:e}=n.bech32.decode(r);return t.Zr(n.bech32.fromWords(e))}return t.Zr(r)})();super(e,Vn.getPublicKey(i)),this.privateKey=i}async signNostrEvent(e){let n=(await this.getNostrPublicKey()).slice(2),r=Ur({...e,pubkey:n}),i=Vn.sign(r,this.privateKey);return{...e,id:t.yr(r).slice(2),pubkey:n,sig:t.yr(i).slice(2)}}},_i=e.t({Address:()=>R,Bytes:()=>t.qr,Cell:()=>t.a,CellAny:()=>t.o,CellDep:()=>t.s,CellDepInfo:()=>t.nt,CellDepVec:()=>t.c,CellInput:()=>t.l,CellInputVec:()=>t.u,CellOutput:()=>t.d,CellOutputVec:()=>t.f,Client:()=>A,ClientBlock:()=>t.rt,ClientBlockHeader:()=>t.it,ClientBlockUncle:()=>t.at,ClientCache:()=>O,ClientCacheMemory:()=>k,ClientIndexerSearchKey:()=>t.ot,ClientIndexerSearchKeyFilter:()=>t.st,ClientIndexerSearchKeyTransaction:()=>t.ct,ClientJsonRpc:()=>P,ClientPublicMainnet:()=>F,ClientPublicTestnet:()=>I,ClientTransactionResponse:()=>t.lt,Codec:()=>t.Kr,CodecBool:()=>t.yn,CodecByte:()=>t.bn,CodecByte16:()=>t.xn,CodecByte32:()=>t.Sn,CodecByte4:()=>t.Cn,CodecByte8:()=>t.wn,CodecBytes:()=>t.Tn,CodecRaw:()=>t.En,CodecUint128:()=>t.Dn,CodecUint128BE:()=>t.On,CodecUint128LE:()=>t.kn,CodecUint16:()=>t.An,CodecUint16BE:()=>t.jn,CodecUint16LE:()=>t.Mn,CodecUint256:()=>t.Nn,CodecUint256BE:()=>t.Pn,CodecUint256LE:()=>t.Fn,CodecUint32:()=>t.In,CodecUint32BE:()=>t.Ln,CodecUint32LE:()=>t.Rn,CodecUint512:()=>t.zn,CodecUint512BE:()=>t.Bn,CodecUint512LE:()=>t.Vn,CodecUint64:()=>t.Hn,CodecUint64BE:()=>t.Un,CodecUint64LE:()=>t.Wn,CodecUint8:()=>t.Gn,DepTypeCodec:()=>t.p,Entity:()=>t.lr,Epoch:()=>t.xt,ErrorClientBase:()=>t.ut,ErrorClientDuplicatedTransaction:()=>t.dt,ErrorClientMaxFeeRateExceeded:()=>t.ft,ErrorClientRBFRejected:()=>t.pt,ErrorClientResolveUnknown:()=>t.mt,ErrorClientVerification:()=>t.ht,ErrorClientWaitTransactionTimeout:()=>t.gt,ErrorTransactionInsufficientCapacity:()=>t.E,ErrorTransactionInsufficientCoin:()=>t.D,HASH_CKB_LENGTH:()=>32,HASH_CKB_SHORT_LENGTH:()=>20,HashTypeCodec:()=>t.j,HasherCkb:()=>t.pr,HasherKeecak256:()=>E,InputToSign:()=>qe,KnownScript:()=>t.J,MultisigCkbWitness:()=>$,One:()=>t.ar,OutPoint:()=>t.m,RawTransaction:()=>t.h,RequestorJsonRpc:()=>M,SECP256K1_SIGNATURE_LENGTH:()=>65,Script:()=>t.M,ScriptInfo:()=>t._t,ScriptOpt:()=>t.N,ScriptVec:()=>t.P,SignPsbtOptions:()=>Ke,Signature:()=>qr,Signer:()=>Q,SignerAlwaysError:()=>ui,SignerBtc:()=>Zr,SignerBtcPublicKeyReadonly:()=>Qr,SignerCkbAlwaysSuccess:()=>$r,SignerCkbPrivateKey:()=>ti,SignerCkbPublicKey:()=>ei,SignerCkbScriptReadonly:()=>ni,SignerDoge:()=>oi,SignerDogeAddressReadonly:()=>si,SignerDogePrivateKey:()=>ci,SignerDummy:()=>li,SignerEvm:()=>fi,SignerEvmAddressReadonly:()=>pi,SignerInfo:()=>Xr,SignerMultisig:()=>Jr,SignerMultisigCkbPrivateKey:()=>ai,SignerMultisigCkbReadonly:()=>ii,SignerMultisigNotEnoughSignaturesError:()=>Yr,SignerNostr:()=>mi,SignerNostrPrivateKey:()=>gi,SignerNostrPublicKeyReadonly:()=>hi,SignerOpenLink:()=>di,SignerSignType:()=>Gr,SignerType:()=>Kr,Since:()=>t.g,Transaction:()=>t._,WitnessArgs:()=>t.v,Zero:()=>t.or,apply:()=>t.Et,btcEcdsaPublicKeyHash:()=>kr,btcP2pkhAddressFromPublicKey:()=>Ar,btcPublicKeyFromP2pkhAddress:()=>jr,btcVarLengthBytesFrom:()=>Dr,buildNostrEventFromMessage:()=>Hr,bytesConcat:()=>t.Jr,bytesConcatTo:()=>t.Yr,bytesEq:()=>t.Xr,bytesFrom:()=>t.Zr,bytesLen:()=>t._r,bytesLenUnsafe:()=>t.vr,bytesTo:()=>t.Qr,calcDaoClaimEpoch:()=>t.y,calcDaoProfit:()=>t.b,codec:()=>t.ur,codecPadding:()=>t.Kn,codecUint:()=>t.qn,codecUintNumber:()=>t.Jn,depTypeFrom:()=>t.x,depTypeFromBytes:()=>t.S,depTypeToBytes:()=>t.C,epochFrom:()=>t.St,epochFromHex:()=>t.Ct,epochToHex:()=>t.wt,fixedPointFrom:()=>t.sr,fixedPointToString:()=>t.cr,gcd:()=>t.Dt,hashCkb:()=>t.mr,hashCkbShort:()=>t.hr,hashTypeFrom:()=>t.F,hashTypeFromBytes:()=>t.I,hashTypeId:()=>L,hashTypeToBytes:()=>t.L,hexFrom:()=>t.yr,isDaoOutputLimitExceeded:()=>t.w,isWebview:()=>t.Ot,keystoreDecrypt:()=>Ge,keystoreEncrypt:()=>We,messageHashBtcEcdsa:()=>Or,messageHashCkbSecp256k1:()=>Ir,messageHashDogeEcdsa:()=>zr,mol:()=>D,nostrEventHash:()=>Ur,numBeFromBytes:()=>t.Yn,numBeToBytes:()=>t.Xn,numFrom:()=>t.Zn,numFromBytes:()=>t.Qn,numLeFromBytes:()=>t.$n,numLeToBytes:()=>t.er,numMax:()=>t.tr,numMin:()=>t.nr,numToBytes:()=>t.rr,numToHex:()=>t.ir,recoverMessageSecp256k1:()=>Fr,reduceAsync:()=>t.kt,signMessageSecp256k1:()=>Nr,sleep:()=>t.At,stringify:()=>t.jt,udtBalanceFrom:()=>t.T,verifyMessageBtcEcdsa:()=>Mr,verifyMessageCkbSecp256k1:()=>Lr,verifyMessageDogeEcdsa:()=>Br,verifyMessageEvmPersonal:()=>Vr,verifyMessageJoyId:()=>Rr,verifyMessageNostrEvent:()=>Wr,verifyMessageSecp256k1:()=>Pr});Object.defineProperty(exports,"$",{enumerable:!0,get:function(){return L}}),Object.defineProperty(exports,"A",{enumerable:!0,get:function(){return Ur}}),Object.defineProperty(exports,"B",{enumerable:!0,get:function(){return Lr}}),Object.defineProperty(exports,"C",{enumerable:!0,get:function(){return Q}}),Object.defineProperty(exports,"D",{enumerable:!0,get:function(){return Gr}}),Object.defineProperty(exports,"E",{enumerable:!0,get:function(){return Yr}}),Object.defineProperty(exports,"F",{enumerable:!0,get:function(){return Rr}}),Object.defineProperty(exports,"G",{enumerable:!0,get:function(){return Dr}}),Object.defineProperty(exports,"H",{enumerable:!0,get:function(){return kr}}),Object.defineProperty(exports,"I",{enumerable:!0,get:function(){return 65}}),Object.defineProperty(exports,"J",{enumerable:!0,get:function(){return qe}}),Object.defineProperty(exports,"K",{enumerable:!0,get:function(){return Or}}),Object.defineProperty(exports,"L",{enumerable:!0,get:function(){return Ir}}),Object.defineProperty(exports,"M",{enumerable:!0,get:function(){return Vr}}),Object.defineProperty(exports,"N",{enumerable:!0,get:function(){return zr}}),Object.defineProperty(exports,"O",{enumerable:!0,get:function(){return Kr}}),Object.defineProperty(exports,"P",{enumerable:!0,get:function(){return Br}}),Object.defineProperty(exports,"Q",{enumerable:!0,get:function(){return R}}),Object.defineProperty(exports,"R",{enumerable:!0,get:function(){return Fr}}),Object.defineProperty(exports,"S",{enumerable:!0,get:function(){return qr}}),Object.defineProperty(exports,"T",{enumerable:!0,get:function(){return Jr}}),Object.defineProperty(exports,"U",{enumerable:!0,get:function(){return Ar}}),Object.defineProperty(exports,"V",{enumerable:!0,get:function(){return Pr}}),Object.defineProperty(exports,"W",{enumerable:!0,get:function(){return jr}}),Object.defineProperty(exports,"X",{enumerable:!0,get:function(){return Ge}}),Object.defineProperty(exports,"Y",{enumerable:!0,get:function(){return Ke}}),Object.defineProperty(exports,"Z",{enumerable:!0,get:function(){return We}}),Object.defineProperty(exports,"_",{enumerable:!0,get:function(){return ti}}),Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return pi}}),Object.defineProperty(exports,"at",{enumerable:!0,get:function(){return k}}),Object.defineProperty(exports,"b",{enumerable:!0,get:function(){return Qr}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return ui}}),Object.defineProperty(exports,"ct",{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return si}}),Object.defineProperty(exports,"et",{enumerable:!0,get:function(){return I}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return oi}}),Object.defineProperty(exports,"g",{enumerable:!0,get:function(){return ni}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return ii}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return mi}}),Object.defineProperty(exports,"it",{enumerable:!0,get:function(){return A}}),Object.defineProperty(exports,"j",{enumerable:!0,get:function(){return Wr}}),Object.defineProperty(exports,"k",{enumerable:!0,get:function(){return Hr}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return li}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return $}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return gi}}),Object.defineProperty(exports,"nt",{enumerable:!0,get:function(){return P}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return fi}}),Object.defineProperty(exports,"ot",{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return ai}}),Object.defineProperty(exports,"q",{enumerable:!0,get:function(){return Mr}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return hi}}),Object.defineProperty(exports,"rt",{enumerable:!0,get:function(){return M}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return di}}),Object.defineProperty(exports,"st",{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return _i}}),Object.defineProperty(exports,"tt",{enumerable:!0,get:function(){return F}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return ci}}),Object.defineProperty(exports,"v",{enumerable:!0,get:function(){return ei}}),Object.defineProperty(exports,"w",{enumerable:!0,get:function(){return Xr}}),Object.defineProperty(exports,"x",{enumerable:!0,get:function(){return Zr}}),Object.defineProperty(exports,"y",{enumerable:!0,get:function(){return $r}}),Object.defineProperty(exports,"z",{enumerable:!0,get:function(){return Nr}});
|
|
21
|
-
//# sourceMappingURL=barrel-
|
|
20
|
+
`}get type(){return`Nostr`}get signType(){return`NostrEvent`}async signNostrEvent(e){throw Error(`SignerNostr.signNostrEvent not implemented`)}async signMessageRaw(e){return t.br((await this.signNostrEvent(Hr(e))).sig)}async getInternalAddress(){return n.bech32.encode(`npub`,n.bech32.toWords(t.Qr(await this.getNostrPublicKey())))}async getAddressObjs(){let e=await this.getNostrPublicKey();return[await R.fromKnownScript(this.client,`NostrLock`,t.br(t.Yr([0],t.hr(e).slice(0,42))))]}async prepareTransaction(e){let n=t._.from(e),{script:r}=await this.getRecommendedAddressObj();return await n.addCellDepsOfKnownScripts(this.client,`NostrLock`),await n.prepareSighashAllWitness(r,572,this.client),n}async signOnlyTransaction(n){let r=t._.from(n),{script:i}=await this.getRecommendedAddressObj(),a=await r.getSignHashInfo(i,this.client);if(!a)return r;let o=t.Qr(JSON.stringify(await this.signNostrEvent({pubkey:(await this.getNostrPublicKey()).slice(2),tags:[[e.CKB_SIG_HASH_ALL_TAG,a.message.slice(2)]],created_at:Math.floor(Date.now()/1e3),kind:e.CKB_UNLOCK_EVENT_KIND,content:e.CKB_UNLOCK_EVENT_CONTENT})),`utf8`),s=t.v.fromBytes(r.witnesses[a.position]);return s.lock=t.br(o),r.setWitnessArgs(a.position,s),r}},gi=class extends hi{constructor(e,r){if(super(e),typeof r==`string`&&r.startsWith(`npub`)){let{words:e}=n.bech32.decode(r);this.publicKey=t.br(n.bech32.fromWords(e))}else this.publicKey=t.br(r)}async connect(){}async isConnected(){return!0}async getNostrPublicKey(){return this.publicKey}},_i=class extends gi{constructor(e,r){let i=(()=>{if(typeof r==`string`&&r.startsWith(`nsec`)){let{words:e}=n.bech32.decode(r);return t.Qr(n.bech32.fromWords(e))}return t.Qr(r)})();super(e,Vn.getPublicKey(i)),this.privateKey=i}async signNostrEvent(e){let n=(await this.getNostrPublicKey()).slice(2),r=Ur({...e,pubkey:n}),i=Vn.sign(r,this.privateKey);return{...e,id:t.br(r).slice(2),pubkey:n,sig:t.br(i).slice(2)}}};async function vi(e,t,n,...r){if(n!=null&&!await Q.verifyMessage(n,t))return;let i=await(async()=>{switch(t.signType){case`EvmPersonal`:return new mi(e,t.identity);case`BtcEcdsa`:return new Qr(e,``,t.identity);case`JoyId`:{let{address:n}=JSON.parse(t.identity);return new ni(e,(await R.fromString(n,e)).script)}case`NostrEvent`:return new gi(e,t.identity);case`CkbSecp256k1`:return new ei(e,t.identity);case`DogeEcdsa`:return new ci(e,t.identity);case`Unknown`:throw Error(`Unknown signer sign type`)}})(),a=await i.getAddresses();if(r.flat().every(e=>a.includes(e)))return i}var yi=class extends Q{static fromSignature(e,t,n,...r){return vi(e,t,n,...r)}},bi=e.t({Address:()=>R,Bytes:()=>t.Jr,Cell:()=>t.a,CellAny:()=>t.o,CellDep:()=>t.s,CellDepInfo:()=>t.nt,CellDepVec:()=>t.c,CellInput:()=>t.l,CellInputVec:()=>t.u,CellOutput:()=>t.d,CellOutputVec:()=>t.f,Client:()=>A,ClientBlock:()=>t.rt,ClientBlockHeader:()=>t.it,ClientBlockUncle:()=>t.at,ClientCache:()=>O,ClientCacheMemory:()=>k,ClientIndexerSearchKey:()=>t.ot,ClientIndexerSearchKeyFilter:()=>t.st,ClientIndexerSearchKeyTransaction:()=>t.ct,ClientJsonRpc:()=>P,ClientPublicMainnet:()=>F,ClientPublicTestnet:()=>I,ClientTransactionResponse:()=>t.lt,Codec:()=>t.qr,CodecBool:()=>t.bn,CodecByte:()=>t.xn,CodecByte16:()=>t.Sn,CodecByte32:()=>t.Cn,CodecByte4:()=>t.wn,CodecByte8:()=>t.Tn,CodecBytes:()=>t.En,CodecRaw:()=>t.Dn,CodecUint128:()=>t.On,CodecUint128BE:()=>t.kn,CodecUint128LE:()=>t.An,CodecUint16:()=>t.jn,CodecUint16BE:()=>t.Mn,CodecUint16LE:()=>t.Nn,CodecUint256:()=>t.Pn,CodecUint256BE:()=>t.Fn,CodecUint256LE:()=>t.In,CodecUint32:()=>t.Ln,CodecUint32BE:()=>t.Rn,CodecUint32LE:()=>t.zn,CodecUint512:()=>t.Bn,CodecUint512BE:()=>t.Vn,CodecUint512LE:()=>t.Hn,CodecUint64:()=>t.Un,CodecUint64BE:()=>t.Wn,CodecUint64LE:()=>t.Gn,CodecUint8:()=>t.Kn,DepTypeCodec:()=>t.p,Entity:()=>t.ur,Epoch:()=>t.xt,ErrorClientBase:()=>t.ut,ErrorClientDuplicatedTransaction:()=>t.dt,ErrorClientMaxFeeRateExceeded:()=>t.ft,ErrorClientRBFRejected:()=>t.pt,ErrorClientResolveUnknown:()=>t.mt,ErrorClientVerification:()=>t.ht,ErrorClientWaitTransactionTimeout:()=>t.gt,ErrorTransactionInsufficientCapacity:()=>t.E,ErrorTransactionInsufficientCoin:()=>t.D,HASH_CKB_LENGTH:()=>32,HASH_CKB_SHORT_LENGTH:()=>20,HashTypeCodec:()=>t.j,HasherCkb:()=>t.mr,HasherKeecak256:()=>E,InputToSign:()=>qe,KnownScript:()=>t.J,MultisigCkbWitness:()=>$,One:()=>t.or,OutPoint:()=>t.m,RawTransaction:()=>t.h,RequestorJsonRpc:()=>M,SECP256K1_SIGNATURE_LENGTH:()=>65,Script:()=>t.M,ScriptInfo:()=>t._t,ScriptOpt:()=>t.N,ScriptVec:()=>t.P,SignPsbtOptions:()=>Ke,Signature:()=>qr,Signer:()=>yi,SignerAlwaysError:()=>di,SignerBtc:()=>Zr,SignerBtcPublicKeyReadonly:()=>Qr,SignerCkbAlwaysSuccess:()=>$r,SignerCkbPrivateKey:()=>ti,SignerCkbPublicKey:()=>ei,SignerCkbScriptReadonly:()=>ni,SignerDoge:()=>si,SignerDogeAddressReadonly:()=>ci,SignerDogePrivateKey:()=>li,SignerDummy:()=>ui,SignerEvm:()=>pi,SignerEvmAddressReadonly:()=>mi,SignerInfo:()=>Xr,SignerMultisig:()=>Jr,SignerMultisigCkbPrivateKey:()=>oi,SignerMultisigCkbReadonly:()=>ai,SignerMultisigNotEnoughSignaturesError:()=>Yr,SignerNostr:()=>hi,SignerNostrPrivateKey:()=>_i,SignerNostrPublicKeyReadonly:()=>gi,SignerOpenLink:()=>fi,SignerSignType:()=>Gr,SignerType:()=>Kr,Since:()=>t.g,Transaction:()=>t._,WitnessArgs:()=>t.v,Zero:()=>t.sr,apply:()=>t.Et,btcEcdsaPublicKeyHash:()=>kr,btcP2pkhAddressFromPublicKey:()=>Ar,btcPublicKeyFromP2pkhAddress:()=>jr,btcVarLengthBytesFrom:()=>Dr,buildNostrEventFromMessage:()=>Hr,bytesConcat:()=>t.Yr,bytesConcatTo:()=>t.Xr,bytesEq:()=>t.Zr,bytesFrom:()=>t.Qr,bytesLen:()=>t.vr,bytesLenUnsafe:()=>t.yr,bytesTo:()=>t.$r,calcDaoClaimEpoch:()=>t.y,calcDaoProfit:()=>t.b,codec:()=>t.dr,codecPadding:()=>t.qn,codecUint:()=>t.Jn,codecUintNumber:()=>t.Yn,depTypeFrom:()=>t.x,depTypeFromBytes:()=>t.S,depTypeToBytes:()=>t.C,epochFrom:()=>t.St,epochFromHex:()=>t.Ct,epochToHex:()=>t.wt,fixedPointFrom:()=>t.cr,fixedPointToString:()=>t.lr,gcd:()=>t.Dt,hashCkb:()=>t.hr,hashCkbShort:()=>t.gr,hashTypeFrom:()=>t.F,hashTypeFromBytes:()=>t.I,hashTypeId:()=>L,hashTypeToBytes:()=>t.L,hexFrom:()=>t.br,isDaoOutputLimitExceeded:()=>t.w,isWebview:()=>t.Ot,keystoreDecrypt:()=>Ge,keystoreEncrypt:()=>We,messageHashBtcEcdsa:()=>Or,messageHashCkbSecp256k1:()=>Ir,messageHashDogeEcdsa:()=>zr,mol:()=>D,nostrEventHash:()=>Ur,numBeFromBytes:()=>t.Xn,numBeToBytes:()=>t.Zn,numFrom:()=>t.Qn,numFromBytes:()=>t.$n,numLeFromBytes:()=>t.er,numLeToBytes:()=>t.tr,numMax:()=>t.nr,numMin:()=>t.rr,numToBytes:()=>t.ir,numToHex:()=>t.ar,recoverMessageSecp256k1:()=>Fr,reduce:()=>t.kt,reduceAsync:()=>t.At,signMessageSecp256k1:()=>Nr,signerFromSignature:()=>vi,sleep:()=>t.jt,stringify:()=>t.Mt,udtBalanceFrom:()=>t.T,verifyMessageBtcEcdsa:()=>Mr,verifyMessageCkbSecp256k1:()=>Lr,verifyMessageDogeEcdsa:()=>Br,verifyMessageEvmPersonal:()=>Vr,verifyMessageJoyId:()=>Rr,verifyMessageNostrEvent:()=>Wr,verifyMessageSecp256k1:()=>Pr});Object.defineProperty(exports,"$",{enumerable:!0,get:function(){return R}}),Object.defineProperty(exports,"A",{enumerable:!0,get:function(){return Hr}}),Object.defineProperty(exports,"B",{enumerable:!0,get:function(){return Nr}}),Object.defineProperty(exports,"C",{enumerable:!0,get:function(){return Zr}}),Object.defineProperty(exports,"D",{enumerable:!0,get:function(){return Yr}}),Object.defineProperty(exports,"E",{enumerable:!0,get:function(){return Jr}}),Object.defineProperty(exports,"F",{enumerable:!0,get:function(){return Br}}),Object.defineProperty(exports,"G",{enumerable:!0,get:function(){return jr}}),Object.defineProperty(exports,"H",{enumerable:!0,get:function(){return Pr}}),Object.defineProperty(exports,"I",{enumerable:!0,get:function(){return Rr}}),Object.defineProperty(exports,"J",{enumerable:!0,get:function(){return Mr}}),Object.defineProperty(exports,"K",{enumerable:!0,get:function(){return Dr}}),Object.defineProperty(exports,"L",{enumerable:!0,get:function(){return 65}}),Object.defineProperty(exports,"M",{enumerable:!0,get:function(){return Wr}}),Object.defineProperty(exports,"N",{enumerable:!0,get:function(){return Vr}}),Object.defineProperty(exports,"O",{enumerable:!0,get:function(){return Gr}}),Object.defineProperty(exports,"P",{enumerable:!0,get:function(){return zr}}),Object.defineProperty(exports,"Q",{enumerable:!0,get:function(){return We}}),Object.defineProperty(exports,"R",{enumerable:!0,get:function(){return Ir}}),Object.defineProperty(exports,"S",{enumerable:!0,get:function(){return Qr}}),Object.defineProperty(exports,"T",{enumerable:!0,get:function(){return Xr}}),Object.defineProperty(exports,"U",{enumerable:!0,get:function(){return kr}}),Object.defineProperty(exports,"V",{enumerable:!0,get:function(){return Lr}}),Object.defineProperty(exports,"W",{enumerable:!0,get:function(){return Ar}}),Object.defineProperty(exports,"X",{enumerable:!0,get:function(){return Ke}}),Object.defineProperty(exports,"Y",{enumerable:!0,get:function(){return qe}}),Object.defineProperty(exports,"Z",{enumerable:!0,get:function(){return Ge}}),Object.defineProperty(exports,"_",{enumerable:!0,get:function(){return ai}}),Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return gi}}),Object.defineProperty(exports,"at",{enumerable:!0,get:function(){return A}}),Object.defineProperty(exports,"b",{enumerable:!0,get:function(){return ei}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return pi}}),Object.defineProperty(exports,"ct",{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return ui}}),Object.defineProperty(exports,"et",{enumerable:!0,get:function(){return L}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return li}}),Object.defineProperty(exports,"g",{enumerable:!0,get:function(){return $}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return oi}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return _i}}),Object.defineProperty(exports,"it",{enumerable:!0,get:function(){return M}}),Object.defineProperty(exports,"j",{enumerable:!0,get:function(){return Ur}}),Object.defineProperty(exports,"k",{enumerable:!0,get:function(){return Kr}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return fi}}),Object.defineProperty(exports,"lt",{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return si}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return yi}}),Object.defineProperty(exports,"nt",{enumerable:!0,get:function(){return F}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return hi}}),Object.defineProperty(exports,"ot",{enumerable:!0,get:function(){return k}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return ci}}),Object.defineProperty(exports,"q",{enumerable:!0,get:function(){return Or}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return vi}}),Object.defineProperty(exports,"rt",{enumerable:!0,get:function(){return P}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return mi}}),Object.defineProperty(exports,"st",{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return bi}}),Object.defineProperty(exports,"tt",{enumerable:!0,get:function(){return I}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return di}}),Object.defineProperty(exports,"v",{enumerable:!0,get:function(){return ni}}),Object.defineProperty(exports,"w",{enumerable:!0,get:function(){return qr}}),Object.defineProperty(exports,"x",{enumerable:!0,get:function(){return $r}}),Object.defineProperty(exports,"y",{enumerable:!0,get:function(){return ti}}),Object.defineProperty(exports,"z",{enumerable:!0,get:function(){return Fr}});
|
|
21
|
+
//# sourceMappingURL=barrel-BBOmj4RJ.js.map
|