@ckb-ccc/core 1.20.0 → 1.20.1
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 +10 -0
- package/dist/advanced.d.mts +1 -1
- package/dist/advanced.mjs +1 -1
- package/dist/{advancedBarrel-CZxkR1dk.d.mts → advancedBarrel-Di0YBlWc.d.mts} +8 -4
- package/dist/{advancedBarrel-CZxkR1dk.d.mts.map → advancedBarrel-Di0YBlWc.d.mts.map} +1 -1
- package/dist/advancedBarrel.d.mts +1 -1
- package/dist/advancedBarrel.mjs +1 -1
- package/dist/{barrel-CqiwnGqc.mjs → barrel-G6e8gZrB.mjs} +3 -3
- package/dist/{barrel-CqiwnGqc.mjs.map → barrel-G6e8gZrB.mjs.map} +1 -1
- package/dist/barrel.d.mts +1 -1
- package/dist/barrel.mjs +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{transformers-BJyj6caX.mjs → transformers-DxPrDQko.mjs} +2 -2
- package/dist/{transformers-BJyj6caX.mjs.map → transformers-DxPrDQko.mjs.map} +1 -1
- package/dist.commonjs/advanced.d.ts +1 -1
- package/dist.commonjs/advanced.js +1 -1
- package/dist.commonjs/{advancedBarrel-Czsr2VlG.d.ts → advancedBarrel-B57gAzdK.d.ts} +8 -4
- package/dist.commonjs/{advancedBarrel-Czsr2VlG.d.ts.map → advancedBarrel-B57gAzdK.d.ts.map} +1 -1
- package/dist.commonjs/advancedBarrel.d.ts +1 -1
- package/dist.commonjs/advancedBarrel.js +1 -1
- package/dist.commonjs/{barrel-BCS94_-c.js → barrel-BOCFtFjq.js} +3 -3
- package/dist.commonjs/{barrel-BCS94_-c.js.map → barrel-BOCFtFjq.js.map} +1 -1
- package/dist.commonjs/barrel.d.ts +1 -1
- package/dist.commonjs/barrel.js +1 -1
- package/dist.commonjs/index.d.ts +1 -1
- package/dist.commonjs/index.js +1 -1
- package/dist.commonjs/{transformers-Cue1Z8Up.js → transformers-0FqvcPy2.js} +2 -2
- package/dist.commonjs/{transformers-Cue1Z8Up.js.map → transformers-0FqvcPy2.js.map} +1 -1
- package/package.json +1 -1
- package/src/ckb/transaction.ts +2 -0
- package/src/signer/jsonRpc/signer.ts +61 -8
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const e=require("./rolldown-runtime-Chgba0Kb.js"),t=require("./transformers-Cue1Z8Up.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,o=!1;for(let s=0;s<a;){let c=Math.min(i-this.pos,a-s);if(c===i){let n=t.Lr(e);for(;i<=a-s;s+=i)this.process(n,s);o=!0;continue}r.set(s===0&&c===a?e:e.subarray(s,s+c),this.pos),this.pos+=c,s+=c,this.pos===i&&(this.process(n,0),this.pos=0,o=!0)}return this.length+=e.length,o&&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,n.fill(0,o),this.padOffset>i-o&&(this.process(r,0),n.fill(0)),t.Cr(r,i-8,this.length*8,a),this.process(r,0),this.roundClean();let s=e===n?r:t.Lr(e),c=this.outputLen,l=c/4,u=this.get();if(c%4||l>u.length)throw Error(`invalid outputLen`);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}_cloneIntoMeta(e){let{buffer:t,length:n,finished:r,destroyed:i,pos:a}=this;return e.destroyed=i,e.finished=r,e.length=n,e.pos=a,a&&e.buffer.set(t),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],te=y[1],b=(e,t,n)=>e<<n|t>>>32-n,x=(e,t,n)=>t<<n|e>>>32-n,S=(e,t,n)=>t<<n-32|e>>>64-n,C=(e,t,n)=>e<<n-32|t>>>64-n,w=(e,t,n)=>n>32?S(e,t,n):b(e,t,n),T=(e,t,n)=>n>32?C(e,t,n):x(e,t,n),E=new Uint32Array(10);function D(e,n=24){if(!(e instanceof Uint32Array))throw TypeError(`"s" expected Uint32Array(50), got type=`+typeof e);if(e.length!==50)throw RangeError(`"s" expected Uint32Array(50), got length=`+e.length);if(t.kr(n,`rounds`),n<1||n>24)throw Error(`"rounds" expected integer 1..24`);for(let t=24-n;t<24;t++){for(let t=0;t<10;t++)E[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,r=(t+2)%10,i=E[r],a=E[r+1],o=w(i,a,1)^E[n],s=T(i,a,1)^E[n+1];for(let n=0;n<50;n+=10)e[t+n]^=o,e[t+n+1]^=s}let n=e[2],r=e[3];for(let t=0;t<24;t++){let i=_[t],a=w(n,r,i),o=T(n,r,i),s=g[t];n=e[s],r=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]^=te[t]}t.Pr(E)}var O=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(t.kr(e,`blockLen`),t.kr(n,`suffix`),t.kr(a,`rounds`),t.Tr(i,`enableXOF`),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(`"blockLen" must be 1..199`);this.state=new Uint8Array(200),this.state32=t.Kr(this.state)}clone(){return this._cloneInto()}keccak(){t.Gr(this.state32),D(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,state32:i}=this,a=e.length,o=n%4==0&&e.byteOffset%4==0,s=n/4,c=o&&a>=n?t.Kr(e):void 0;for(let t=0;t<a;){if(c!==void 0&&this.pos===0&&t%4==0&&a-t>=n){for(let e=0,n=t/4;e<s;e++)i[e]^=c[n+e];t+=n,this.pos=n,this.keccak();continue}let o=Math.min(n-this.pos,a-t);for(let n=0;n<o;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 enabled`);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.length===this.outputLen?e: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 k=((e,n,r,i={})=>t.Ir(()=>new O(n,e,r),i))(1,136,32);var A=class{constructor(){this.hasher=k.create()}update(e){return this.hasher.update(t.Qr(e)),this}digest(){return t.Sr(this.hasher.digest())}},j=e.t({Bool:()=>t.Sn,BoolOpt:()=>t.Ft,BoolVec:()=>t.It,Byte:()=>t.Cn,Byte16:()=>t.wn,Byte16Opt:()=>t.Lt,Byte16Vec:()=>t.Rt,Byte32:()=>t.Tn,Byte32Opt:()=>t.zt,Byte32Vec:()=>t.Bt,Byte4:()=>t.En,Byte4Opt:()=>t.Vt,Byte4Vec:()=>t.Ht,Byte8:()=>t.Dn,Byte8Opt:()=>t.Ut,Byte8Vec:()=>t.Wt,ByteOpt:()=>t.Gt,ByteVec:()=>t.Kt,Bytes:()=>t.qt,BytesOpt:()=>t.Jt,BytesVec:()=>t.Yt,Codec:()=>t.qr,Entity:()=>t.fr,String:()=>t.Xt,StringOpt:()=>t.Zt,StringVec:()=>t.Qt,Uint128:()=>t.An,Uint128BE:()=>t.jn,Uint128LE:()=>t.Mn,Uint128Opt:()=>t.$t,Uint128Vec:()=>t.en,Uint16:()=>t.Nn,Uint16BE:()=>t.Pn,Uint16LE:()=>t.Fn,Uint16Opt:()=>t.tn,Uint16Vec:()=>t.nn,Uint256:()=>t.In,Uint256BE:()=>t.Ln,Uint256LE:()=>t.Rn,Uint256Opt:()=>t.rn,Uint256Vec:()=>t.in,Uint32:()=>t.zn,Uint32BE:()=>t.Bn,Uint32LE:()=>t.Vn,Uint32Opt:()=>t.an,Uint32Vec:()=>t.on,Uint512:()=>t.Hn,Uint512BE:()=>t.Un,Uint512LE:()=>t.Wn,Uint512Opt:()=>t.sn,Uint512Vec:()=>t.cn,Uint64:()=>t.Gn,Uint64BE:()=>t.Kn,Uint64LE:()=>t.qn,Uint64Opt:()=>t.ln,Uint64Vec:()=>t.un,Uint8:()=>t.Jn,Uint8Opt:()=>t.dn,Uint8Vec:()=>t.fn,array:()=>t.pn,byteVec:()=>t.mn,codec:()=>t.pr,dynItemVec:()=>t.hn,fixedItemVec:()=>t.gn,option:()=>t._n,struct:()=>t.vn,table:()=>t.yn,uint:()=>t.Xn,uintNumber:()=>t.Zn,union:()=>t.bn,vector:()=>t.xn});function M(e){if(typeof AbortSignal.any==`function`)return AbortSignal.any([...e]);let t=new AbortController,n=new Map,r=()=>{for(let[e,t]of n)e.removeEventListener(`abort`,t);n.clear()},i=e=>{r(),t.abort(e.reason)};for(let t of e){if(t.aborted){i(t);break}if(n.has(t))continue;let e=()=>i(t);n.set(t,e),t.addEventListener(`abort`,e,{once:!0})}return t.signal}var N=class e extends t.Nt{constructor(e,t){super(),this.value_=e,this.owners=t}static from(t){if(new Set(t).size!==t.length)throw Error(`Cannot aggregate the same Owner more than once`);let n=t.map(e=>e.value),r=t.map(e=>this.moveFrom(e));return new e(n,r)}async release(){let e=await Promise.allSettled(this.owners.map(e=>e.dispose())),t=[];for(let n of e)n.status===`rejected`&&t.push(n.reason);if(t.length!==0)throw AggregateError(t,`Failed to dispose aggregated Owners`)}},P=class e extends t.Nt{constructor(e){super(),this.state=e}get value_(){return this.state.owner.value}static new(n,r){return new e({owner:new t.Pt(n,r),referenceCount:1})}static from(t){return new e({owner:this.moveFrom(t),referenceCount:1})}clone(){return this.value,this.state.referenceCount+=1,new e(this.state)}release(){if(--this.state.referenceCount,this.state.referenceCount===0)return this.state.owner.dispose()}};let F;(function(e){let t=e.inner=`@ckb-ccc/core.Proxy.inner`,n=e.localKeys=Symbol.for(`@ckb-ccc/core.Proxy.localKeys`);function r(e){class r{constructor(e){this[t]=e;let i=new Set([t]),a=new Map;for(let e=new.target.prototype;e!==null&&e!==r.prototype;e=Reflect.getPrototypeOf(e)){for(let t of Reflect.ownKeys(e))i.add(t);let t=Object.getOwnPropertyDescriptor(e,`constructor`)?.value;try{let e=Object.getOwnPropertyDescriptor(t,n)?.value;for(let t of e??[])i.add(t)}catch{}}let o=(e,t)=>i.has(t)||Reflect.getOwnPropertyDescriptor(e,t)!==void 0;return new globalThis.Proxy(this,{deleteProperty:(t,n)=>Reflect.deleteProperty(o(t,n)?t:e,n),get:(t,n,r)=>{let i=o(t,n),s=Reflect.get(i?t:e,n,i?r:e);if(i||typeof s!=`function`)return s;let c=a.get(n);return c?.value!==s&&(c={value:s,wrapper:(...t)=>Reflect.apply(s,e,t)},a.set(n,c)),c.wrapper},has:(t,n)=>Reflect.has(o(t,n)?t:e,n),set:(t,n,r,i)=>{let a=o(t,n);return Reflect.set(a?t:e,n,r,a?i:e)}})}}let i=e.prototype;return Object.setPrototypeOf(r.prototype,i),Object.setPrototypeOf(r,e),r}e.Base=r})(F||={});function I(e,n){return t._r(t.C.from(e).toBytes(),t.rr(n,8))}var ne=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.j.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.er(Date.now())-e.timestamp>=t.f}},re=class extends ne{constructor(e=512,n=256,r=128,i=t.f){super(),this.maxCells=e,this.maxTxs=n,this.maxBlocks=r,this.cells=new t.p(this.maxCells),this.knownTransactions=new t.p(this.maxTxs),this.knownBlockHashes=new t.p(this.maxBlocks),this.knownBlocks=new t.p(this.maxBlocks),this.confirmedBlockTime=t.er(i)}async markUsableNoCache(...e){e.flat().forEach(e=>{let n=t.y.from(e).clone(),r=t.Sr(n.outPoint.toBytes());this.cells.set(r,[!0,n])})}async markUnusable(...e){e.flat().forEach(e=>{let n=t.O.from(e),r=t.Sr(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.m(e,i)&&(this.cells.get(n),yield i.clone())}async isUnusable(e){let n=t.O.from(e);return!(this.cells.get(t.Sr(n.toBytes()))?.[0]??!0)}async recordCells(...e){e.flat().map(e=>{let n=t.y.from(e),r=t.Sr(n.outPoint.toBytes());this.cells.get(r)||this.cells.set(r,[void 0,n])})}async getCell(e){let n=t.O.from(e),r=this.cells.get(t.Sr(n.toBytes()))?.[1];if(r&&r.cellOutput&&r.outputData)return t.y.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.Sr(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.Sr(e),r=this.knownBlocks.get(n);return r&&this.knownBlockHashes.get(r.header.number),r?.header}async getHeaderByNumber(e){let n=t.er(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.Sr(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.er(e),r=this.knownBlockHashes.get(n);if(r)return this.getBlockByHash(r)}hasHeaderConfirmed(e){return t.er(Date.now())-e.timestamp>=this.confirmedBlockTime}},ie=class{constructor(e){this.cache=e?.cache??new re,this.scripts=e?.scripts??{}}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)}async getFeeRate(e,n){let r=t.ir((await this.getFeeRateStatistics(e)).median,t.yt),i=t.er(n?.maxFeeRate??t.vt);return i===0n?r:t.ar(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.O.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.y.from({...a,outPoint:n});return await this.cache.recordCells(o),o}async getCellWithHeader(e){let n=t.O.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.y.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.x.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.lr)}async sendTransaction(e,n,r){let i=t.j.from(e),a=t.er(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.Sr(e),r=await this.getTransactionNoCache(n);return r?(await this.cache.recordTransactionResponses(r),r):this.cache.getTransactionResponse(n)}async getTransactionWithHeader(e){let n=t.Sr(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)}}},ae=class{constructor(e){this.transports=e,this.i=0}async request(e){let t=this.i,n=Error(`JsonRpcTransportFallback requires at least one transport`);for(let r=0;r<this.transports.length;r+=1){let i=(t+r)%this.transports.length;try{let t=await this.transports[i].request(e);return this.i=i,t}catch(e){n=e}}throw n}};function oe(e,n){let r=Array.from(new Set(e),e=>t.c(e,n));return N.from(r).map(e=>new ae([...e]))}function se(e,t){return t?t(e):e}var ce=class e{constructor(e,t,n){this.url_=e,this.onError=n,this.concurrent=0,this.pending=[],this.id=0,this.maxConcurrent=t?.maxConcurrent,this.transport=t?.transport?t.transport:oe([e,...t?.fallbacks??[]],t).value}static new({transport:t,maxConcurrent:n,onError:r}){return new e(``,{transport:t,maxConcurrent:n},r)}static open({urls:[t,...n],onError:r,...i}){return oe([t,...n],i).map(t=>e.new({transport:t,...i,onError:r}))}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)=>se(e,n[t]))):t);try{return await se(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 le=[[`Resolve\\(Unknown\\(OutPoint\\((0x.*)\\)\\)\\)`,(e,n)=>new t.mt(e,t.O.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])]];function ue(e){if(typeof e!=`object`||!e||!(`data`in e)||typeof e.data!=`string`)throw e;let n=e;for(let[e,t]of le){let r=n.data.match(e);if(r)throw t(n,r)}throw new t.ut(n)}var de=class extends ie{constructor(e,n){super(n),this.url_=e,this.getFeeRateStatistics=this.buildSender(`get_fee_rate_statistics`,[e=>t.Et(t.er,e)],e=>({mean:t.er(e?.mean??t.yt),median:t.er(e?.median??t.yt)})),this.getTip=this.buildSender(`get_tip_block_number`,[],t.er),this.getTipHeader=this.buildSender(`get_tip_header`,[],e=>t.Et(t.s.blockHeaderTo,e)),this.getBlockByNumberNoCache=this.buildSender(`get_block_by_number`,[e=>t.sr(t.er(e))],e=>t.Et(t.s.blockTo,e)),this.getBlockByHashNoCache=this.buildSender(`get_block`,[t.Sr],e=>t.Et(t.s.blockTo,e)),this.getHeaderByNumberNoCache=this.buildSender(`get_header_by_number`,[e=>t.sr(t.er(e))],e=>t.Et(t.s.blockHeaderTo,e)),this.getHeaderByHashNoCache=this.buildSender(`get_header`,[t.Sr],e=>t.Et(t.s.blockHeaderTo,e)),this.estimateCycles=this.buildSender(`estimate_cycles`,[t.s.transactionFrom],({cycles:e})=>t.er(e)),this.sendTransactionDry=this.buildSender(`test_tx_pool_accept`,[t.s.transactionFrom],({cycles:e})=>t.er(e)),this.sendTransactionNoCache=this.buildSender(`send_transaction`,[t.s.transactionFrom,e=>e??void 0],t.Sr),this.getTransactionNoCache=this.buildSender(`get_transaction`,[t.Sr],t.s.transactionResponseTo),this.findCellsPagedNoCache=this.buildSender(`get_cells`,[t.s.indexerSearchKeyFrom,e=>e??`asc`,e=>t.sr(e??10)],t.s.findCellsResponseTo),this.findTransactionsPaged=this.buildSender(`get_transactions`,[t.s.indexerSearchKeyTransactionFrom,e=>e??`asc`,e=>t.sr(e??10)],t.s.findTransactionsResponseTo),this.getCellsCapacity=this.buildSender(`get_cells_capacity`,[t.s.indexerSearchKeyFrom],({capacity:e})=>t.er(e));let r=n?.requestor;this.requestor=r||(n?.transport?ce.new({transport:n.transport,maxConcurrent:n.maxConcurrent,onError:ue}):ce.open({urls:[e,...n?.fallbacks??[]],timeout:n?.timeout,maxConcurrent:n?.maxConcurrent,onError:ue}).value)}static newRequestor(e){return ce.new({...e,onError:ue})}static openRequestor(e){return ce.open({...e,onError:ue})}get url(){return this.url_}getCellLiveNoCache(e,n,r){return this.buildSender(`get_live_cell`,[t.s.outPointFrom],({cell:n})=>t.Et(({output:n,data:r})=>t.y.from({cellOutput:t.s.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)}},fe=class e extends de{static defaultUrls(){return r.default===void 0?[`https://mainnet.ckb.dev/`,`https://mainnet.ckbapp.dev/`]:[`wss://mainnet.ckb.dev/ws`,`https://mainnet.ckb.dev/`,`https://mainnet.ckbapp.dev/`]}static resolveConfig(e){let n=this.defaultUrls();return{...e,url:e?.url??n[0],fallbacks:e?.fallbacks??[...n],scripts:e?.scripts??t.d}}constructor(t){let n=e.resolveConfig(t);super(n.url,n)}static new(t){let{cache:n,scripts:r,...i}=t,a=this.newRequestor(i);return new e({cache:n,scripts:r,requestor:a})}static open(t){let{cache:n,scripts:r,urls:i=this.defaultUrls(),...a}=t??{};return this.openRequestor({...a,urls:i}).map(t=>new e({cache:n,scripts:r,requestor:t,url:i[0],fallbacks:[...i.slice(1)]}))}get addressPrefix(){return`ckb`}},pe=class e extends de{static defaultUrls(){return r.default===void 0?[`https://testnet.ckb.dev/`,`https://testnet.ckbapp.dev/`]:[`wss://testnet.ckb.dev/ws`,`https://testnet.ckb.dev/`,`https://testnet.ckbapp.dev/`]}static resolveConfig(e){let n=this.defaultUrls();return{...e,url:e?.url??n[0],fallbacks:e?.fallbacks??[...n],scripts:e?.scripts??t.o}}constructor(t){let n=e.resolveConfig(t);super(n.url,n)}static new(t){let{cache:n,scripts:r,...i}=t,a=this.newRequestor(i);return new e({cache:n,scripts:r,requestor:a})}static open(t){let{cache:n,scripts:r,urls:i=this.defaultUrls(),...a}=t??{};return this.openRequestor({...a,urls:i}).map(t=>new e({cache:n,scripts:r,requestor:t,url:i[0],fallbacks:[...i.slice(1)]}))}get addressPrefix(){return`ckt`}},L=class e{constructor(e,t){this.script=e,this.prefix=t}static from(n){return n instanceof e?n:new e(t.K.from(n.script),n.prefix)}static async fromString(n,r){let{prefix:i,format:a,payload:o}=t.a(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.i(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.K.fromKnownScript(n,r,i),prefix:n.addressPrefix})}toString(){let e=t.Yr([0],t.Qr(this.script.codeHash),t.Z(this.script.hashType),t.Qr(this.script.args));return n.bech32m.encode(this.prefix,n.bech32m.toWords(e),t.n)}},R=class extends Error{constructor(e){super(e.message),this.name=`JsonRpcError`,this.code=e.code,this.data=e.data}};
|
|
1
|
+
const e=require("./rolldown-runtime-Chgba0Kb.js"),t=require("./transformers-0FqvcPy2.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,o=!1;for(let s=0;s<a;){let c=Math.min(i-this.pos,a-s);if(c===i){let n=t.Lr(e);for(;i<=a-s;s+=i)this.process(n,s);o=!0;continue}r.set(s===0&&c===a?e:e.subarray(s,s+c),this.pos),this.pos+=c,s+=c,this.pos===i&&(this.process(n,0),this.pos=0,o=!0)}return this.length+=e.length,o&&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,n.fill(0,o),this.padOffset>i-o&&(this.process(r,0),n.fill(0)),t.Cr(r,i-8,this.length*8,a),this.process(r,0),this.roundClean();let s=e===n?r:t.Lr(e),c=this.outputLen,l=c/4,u=this.get();if(c%4||l>u.length)throw Error(`invalid outputLen`);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}_cloneIntoMeta(e){let{buffer:t,length:n,finished:r,destroyed:i,pos:a}=this;return e.destroyed=i,e.finished=r,e.length=n,e.pos=a,a&&e.buffer.set(t),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],te=y[1],b=(e,t,n)=>e<<n|t>>>32-n,x=(e,t,n)=>t<<n|e>>>32-n,S=(e,t,n)=>t<<n-32|e>>>64-n,C=(e,t,n)=>e<<n-32|t>>>64-n,w=(e,t,n)=>n>32?S(e,t,n):b(e,t,n),T=(e,t,n)=>n>32?C(e,t,n):x(e,t,n),E=new Uint32Array(10);function D(e,n=24){if(!(e instanceof Uint32Array))throw TypeError(`"s" expected Uint32Array(50), got type=`+typeof e);if(e.length!==50)throw RangeError(`"s" expected Uint32Array(50), got length=`+e.length);if(t.kr(n,`rounds`),n<1||n>24)throw Error(`"rounds" expected integer 1..24`);for(let t=24-n;t<24;t++){for(let t=0;t<10;t++)E[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,r=(t+2)%10,i=E[r],a=E[r+1],o=w(i,a,1)^E[n],s=T(i,a,1)^E[n+1];for(let n=0;n<50;n+=10)e[t+n]^=o,e[t+n+1]^=s}let n=e[2],r=e[3];for(let t=0;t<24;t++){let i=_[t],a=w(n,r,i),o=T(n,r,i),s=g[t];n=e[s],r=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]^=te[t]}t.Pr(E)}var O=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(t.kr(e,`blockLen`),t.kr(n,`suffix`),t.kr(a,`rounds`),t.Tr(i,`enableXOF`),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(`"blockLen" must be 1..199`);this.state=new Uint8Array(200),this.state32=t.Kr(this.state)}clone(){return this._cloneInto()}keccak(){t.Gr(this.state32),D(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,state32:i}=this,a=e.length,o=n%4==0&&e.byteOffset%4==0,s=n/4,c=o&&a>=n?t.Kr(e):void 0;for(let t=0;t<a;){if(c!==void 0&&this.pos===0&&t%4==0&&a-t>=n){for(let e=0,n=t/4;e<s;e++)i[e]^=c[n+e];t+=n,this.pos=n,this.keccak();continue}let o=Math.min(n-this.pos,a-t);for(let n=0;n<o;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 enabled`);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.length===this.outputLen?e: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 k=((e,n,r,i={})=>t.Ir(()=>new O(n,e,r),i))(1,136,32);var A=class{constructor(){this.hasher=k.create()}update(e){return this.hasher.update(t.Qr(e)),this}digest(){return t.Sr(this.hasher.digest())}},j=e.t({Bool:()=>t.Sn,BoolOpt:()=>t.Ft,BoolVec:()=>t.It,Byte:()=>t.Cn,Byte16:()=>t.wn,Byte16Opt:()=>t.Lt,Byte16Vec:()=>t.Rt,Byte32:()=>t.Tn,Byte32Opt:()=>t.zt,Byte32Vec:()=>t.Bt,Byte4:()=>t.En,Byte4Opt:()=>t.Vt,Byte4Vec:()=>t.Ht,Byte8:()=>t.Dn,Byte8Opt:()=>t.Ut,Byte8Vec:()=>t.Wt,ByteOpt:()=>t.Gt,ByteVec:()=>t.Kt,Bytes:()=>t.qt,BytesOpt:()=>t.Jt,BytesVec:()=>t.Yt,Codec:()=>t.qr,Entity:()=>t.fr,String:()=>t.Xt,StringOpt:()=>t.Zt,StringVec:()=>t.Qt,Uint128:()=>t.An,Uint128BE:()=>t.jn,Uint128LE:()=>t.Mn,Uint128Opt:()=>t.$t,Uint128Vec:()=>t.en,Uint16:()=>t.Nn,Uint16BE:()=>t.Pn,Uint16LE:()=>t.Fn,Uint16Opt:()=>t.tn,Uint16Vec:()=>t.nn,Uint256:()=>t.In,Uint256BE:()=>t.Ln,Uint256LE:()=>t.Rn,Uint256Opt:()=>t.rn,Uint256Vec:()=>t.in,Uint32:()=>t.zn,Uint32BE:()=>t.Bn,Uint32LE:()=>t.Vn,Uint32Opt:()=>t.an,Uint32Vec:()=>t.on,Uint512:()=>t.Hn,Uint512BE:()=>t.Un,Uint512LE:()=>t.Wn,Uint512Opt:()=>t.sn,Uint512Vec:()=>t.cn,Uint64:()=>t.Gn,Uint64BE:()=>t.Kn,Uint64LE:()=>t.qn,Uint64Opt:()=>t.ln,Uint64Vec:()=>t.un,Uint8:()=>t.Jn,Uint8Opt:()=>t.dn,Uint8Vec:()=>t.fn,array:()=>t.pn,byteVec:()=>t.mn,codec:()=>t.pr,dynItemVec:()=>t.hn,fixedItemVec:()=>t.gn,option:()=>t._n,struct:()=>t.vn,table:()=>t.yn,uint:()=>t.Xn,uintNumber:()=>t.Zn,union:()=>t.bn,vector:()=>t.xn});function M(e){if(typeof AbortSignal.any==`function`)return AbortSignal.any([...e]);let t=new AbortController,n=new Map,r=()=>{for(let[e,t]of n)e.removeEventListener(`abort`,t);n.clear()},i=e=>{r(),t.abort(e.reason)};for(let t of e){if(t.aborted){i(t);break}if(n.has(t))continue;let e=()=>i(t);n.set(t,e),t.addEventListener(`abort`,e,{once:!0})}return t.signal}var N=class e extends t.Nt{constructor(e,t){super(),this.value_=e,this.owners=t}static from(t){if(new Set(t).size!==t.length)throw Error(`Cannot aggregate the same Owner more than once`);let n=t.map(e=>e.value),r=t.map(e=>this.moveFrom(e));return new e(n,r)}async release(){let e=await Promise.allSettled(this.owners.map(e=>e.dispose())),t=[];for(let n of e)n.status===`rejected`&&t.push(n.reason);if(t.length!==0)throw AggregateError(t,`Failed to dispose aggregated Owners`)}},P=class e extends t.Nt{constructor(e){super(),this.state=e}get value_(){return this.state.owner.value}static new(n,r){return new e({owner:new t.Pt(n,r),referenceCount:1})}static from(t){return new e({owner:this.moveFrom(t),referenceCount:1})}clone(){return this.value,this.state.referenceCount+=1,new e(this.state)}release(){if(--this.state.referenceCount,this.state.referenceCount===0)return this.state.owner.dispose()}};let F;(function(e){let t=e.inner=`@ckb-ccc/core.Proxy.inner`,n=e.localKeys=Symbol.for(`@ckb-ccc/core.Proxy.localKeys`);function r(e){class r{constructor(e){this[t]=e;let i=new Set([t]),a=new Map;for(let e=new.target.prototype;e!==null&&e!==r.prototype;e=Reflect.getPrototypeOf(e)){for(let t of Reflect.ownKeys(e))i.add(t);let t=Object.getOwnPropertyDescriptor(e,`constructor`)?.value;try{let e=Object.getOwnPropertyDescriptor(t,n)?.value;for(let t of e??[])i.add(t)}catch{}}let o=(e,t)=>i.has(t)||Reflect.getOwnPropertyDescriptor(e,t)!==void 0;return new globalThis.Proxy(this,{deleteProperty:(t,n)=>Reflect.deleteProperty(o(t,n)?t:e,n),get:(t,n,r)=>{let i=o(t,n),s=Reflect.get(i?t:e,n,i?r:e);if(i||typeof s!=`function`)return s;let c=a.get(n);return c?.value!==s&&(c={value:s,wrapper:(...t)=>Reflect.apply(s,e,t)},a.set(n,c)),c.wrapper},has:(t,n)=>Reflect.has(o(t,n)?t:e,n),set:(t,n,r,i)=>{let a=o(t,n);return Reflect.set(a?t:e,n,r,a?i:e)}})}}let i=e.prototype;return Object.setPrototypeOf(r.prototype,i),Object.setPrototypeOf(r,e),r}e.Base=r})(F||={});function I(e,n){return t._r(t.C.from(e).toBytes(),t.rr(n,8))}var ne=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.j.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.er(Date.now())-e.timestamp>=t.f}},re=class extends ne{constructor(e=512,n=256,r=128,i=t.f){super(),this.maxCells=e,this.maxTxs=n,this.maxBlocks=r,this.cells=new t.p(this.maxCells),this.knownTransactions=new t.p(this.maxTxs),this.knownBlockHashes=new t.p(this.maxBlocks),this.knownBlocks=new t.p(this.maxBlocks),this.confirmedBlockTime=t.er(i)}async markUsableNoCache(...e){e.flat().forEach(e=>{let n=t.y.from(e).clone(),r=t.Sr(n.outPoint.toBytes());this.cells.set(r,[!0,n])})}async markUnusable(...e){e.flat().forEach(e=>{let n=t.O.from(e),r=t.Sr(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.m(e,i)&&(this.cells.get(n),yield i.clone())}async isUnusable(e){let n=t.O.from(e);return!(this.cells.get(t.Sr(n.toBytes()))?.[0]??!0)}async recordCells(...e){e.flat().map(e=>{let n=t.y.from(e),r=t.Sr(n.outPoint.toBytes());this.cells.get(r)||this.cells.set(r,[void 0,n])})}async getCell(e){let n=t.O.from(e),r=this.cells.get(t.Sr(n.toBytes()))?.[1];if(r&&r.cellOutput&&r.outputData)return t.y.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.Sr(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.Sr(e),r=this.knownBlocks.get(n);return r&&this.knownBlockHashes.get(r.header.number),r?.header}async getHeaderByNumber(e){let n=t.er(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.Sr(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.er(e),r=this.knownBlockHashes.get(n);if(r)return this.getBlockByHash(r)}hasHeaderConfirmed(e){return t.er(Date.now())-e.timestamp>=this.confirmedBlockTime}},ie=class{constructor(e){this.cache=e?.cache??new re,this.scripts=e?.scripts??{}}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)}async getFeeRate(e,n){let r=t.ir((await this.getFeeRateStatistics(e)).median,t.yt),i=t.er(n?.maxFeeRate??t.vt);return i===0n?r:t.ar(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.O.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.y.from({...a,outPoint:n});return await this.cache.recordCells(o),o}async getCellWithHeader(e){let n=t.O.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.y.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.x.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.lr)}async sendTransaction(e,n,r){let i=t.j.from(e),a=t.er(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.Sr(e),r=await this.getTransactionNoCache(n);return r?(await this.cache.recordTransactionResponses(r),r):this.cache.getTransactionResponse(n)}async getTransactionWithHeader(e){let n=t.Sr(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)}}},ae=class{constructor(e){this.transports=e,this.i=0}async request(e){let t=this.i,n=Error(`JsonRpcTransportFallback requires at least one transport`);for(let r=0;r<this.transports.length;r+=1){let i=(t+r)%this.transports.length;try{let t=await this.transports[i].request(e);return this.i=i,t}catch(e){n=e}}throw n}};function oe(e,n){let r=Array.from(new Set(e),e=>t.c(e,n));return N.from(r).map(e=>new ae([...e]))}function se(e,t){return t?t(e):e}var ce=class e{constructor(e,t,n){this.url_=e,this.onError=n,this.concurrent=0,this.pending=[],this.id=0,this.maxConcurrent=t?.maxConcurrent,this.transport=t?.transport?t.transport:oe([e,...t?.fallbacks??[]],t).value}static new({transport:t,maxConcurrent:n,onError:r}){return new e(``,{transport:t,maxConcurrent:n},r)}static open({urls:[t,...n],onError:r,...i}){return oe([t,...n],i).map(t=>e.new({transport:t,...i,onError:r}))}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)=>se(e,n[t]))):t);try{return await se(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 le=[[`Resolve\\(Unknown\\(OutPoint\\((0x.*)\\)\\)\\)`,(e,n)=>new t.mt(e,t.O.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])]];function ue(e){if(typeof e!=`object`||!e||!(`data`in e)||typeof e.data!=`string`)throw e;let n=e;for(let[e,t]of le){let r=n.data.match(e);if(r)throw t(n,r)}throw new t.ut(n)}var de=class extends ie{constructor(e,n){super(n),this.url_=e,this.getFeeRateStatistics=this.buildSender(`get_fee_rate_statistics`,[e=>t.Et(t.er,e)],e=>({mean:t.er(e?.mean??t.yt),median:t.er(e?.median??t.yt)})),this.getTip=this.buildSender(`get_tip_block_number`,[],t.er),this.getTipHeader=this.buildSender(`get_tip_header`,[],e=>t.Et(t.s.blockHeaderTo,e)),this.getBlockByNumberNoCache=this.buildSender(`get_block_by_number`,[e=>t.sr(t.er(e))],e=>t.Et(t.s.blockTo,e)),this.getBlockByHashNoCache=this.buildSender(`get_block`,[t.Sr],e=>t.Et(t.s.blockTo,e)),this.getHeaderByNumberNoCache=this.buildSender(`get_header_by_number`,[e=>t.sr(t.er(e))],e=>t.Et(t.s.blockHeaderTo,e)),this.getHeaderByHashNoCache=this.buildSender(`get_header`,[t.Sr],e=>t.Et(t.s.blockHeaderTo,e)),this.estimateCycles=this.buildSender(`estimate_cycles`,[t.s.transactionFrom],({cycles:e})=>t.er(e)),this.sendTransactionDry=this.buildSender(`test_tx_pool_accept`,[t.s.transactionFrom],({cycles:e})=>t.er(e)),this.sendTransactionNoCache=this.buildSender(`send_transaction`,[t.s.transactionFrom,e=>e??void 0],t.Sr),this.getTransactionNoCache=this.buildSender(`get_transaction`,[t.Sr],t.s.transactionResponseTo),this.findCellsPagedNoCache=this.buildSender(`get_cells`,[t.s.indexerSearchKeyFrom,e=>e??`asc`,e=>t.sr(e??10)],t.s.findCellsResponseTo),this.findTransactionsPaged=this.buildSender(`get_transactions`,[t.s.indexerSearchKeyTransactionFrom,e=>e??`asc`,e=>t.sr(e??10)],t.s.findTransactionsResponseTo),this.getCellsCapacity=this.buildSender(`get_cells_capacity`,[t.s.indexerSearchKeyFrom],({capacity:e})=>t.er(e));let r=n?.requestor;this.requestor=r||(n?.transport?ce.new({transport:n.transport,maxConcurrent:n.maxConcurrent,onError:ue}):ce.open({urls:[e,...n?.fallbacks??[]],timeout:n?.timeout,maxConcurrent:n?.maxConcurrent,onError:ue}).value)}static newRequestor(e){return ce.new({...e,onError:ue})}static openRequestor(e){return ce.open({...e,onError:ue})}get url(){return this.url_}getCellLiveNoCache(e,n,r){return this.buildSender(`get_live_cell`,[t.s.outPointFrom],({cell:n})=>t.Et(({output:n,data:r})=>t.y.from({cellOutput:t.s.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)}},fe=class e extends de{static defaultUrls(){return r.default===void 0?[`https://mainnet.ckb.dev/`,`https://mainnet.ckbapp.dev/`]:[`wss://mainnet.ckb.dev/ws`,`https://mainnet.ckb.dev/`,`https://mainnet.ckbapp.dev/`]}static resolveConfig(e){let n=this.defaultUrls();return{...e,url:e?.url??n[0],fallbacks:e?.fallbacks??[...n],scripts:e?.scripts??t.d}}constructor(t){let n=e.resolveConfig(t);super(n.url,n)}static new(t){let{cache:n,scripts:r,...i}=t,a=this.newRequestor(i);return new e({cache:n,scripts:r,requestor:a})}static open(t){let{cache:n,scripts:r,urls:i=this.defaultUrls(),...a}=t??{};return this.openRequestor({...a,urls:i}).map(t=>new e({cache:n,scripts:r,requestor:t,url:i[0],fallbacks:[...i.slice(1)]}))}get addressPrefix(){return`ckb`}},pe=class e extends de{static defaultUrls(){return r.default===void 0?[`https://testnet.ckb.dev/`,`https://testnet.ckbapp.dev/`]:[`wss://testnet.ckb.dev/ws`,`https://testnet.ckb.dev/`,`https://testnet.ckbapp.dev/`]}static resolveConfig(e){let n=this.defaultUrls();return{...e,url:e?.url??n[0],fallbacks:e?.fallbacks??[...n],scripts:e?.scripts??t.o}}constructor(t){let n=e.resolveConfig(t);super(n.url,n)}static new(t){let{cache:n,scripts:r,...i}=t,a=this.newRequestor(i);return new e({cache:n,scripts:r,requestor:a})}static open(t){let{cache:n,scripts:r,urls:i=this.defaultUrls(),...a}=t??{};return this.openRequestor({...a,urls:i}).map(t=>new e({cache:n,scripts:r,requestor:t,url:i[0],fallbacks:[...i.slice(1)]}))}get addressPrefix(){return`ckt`}},L=class e{constructor(e,t){this.script=e,this.prefix=t}static from(n){return n instanceof e?n:new e(t.K.from(n.script),n.prefix)}static async fromString(n,r){let{prefix:i,format:a,payload:o}=t.a(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.i(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.K.fromKnownScript(n,r,i),prefix:n.addressPrefix})}toString(){let e=t.Yr([0],t.Qr(this.script.codeHash),t.Z(this.script.hashType),t.Qr(this.script.args));return n.bech32m.encode(this.prefix,n.bech32m.toWords(e),t.n)}},R=class extends Error{constructor(e){super(e.message),this.name=`JsonRpcError`,this.code=e.code,this.data=e.data}};
|
|
2
2
|
/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */
|
|
3
3
|
function me(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`&&`BYTES_PER_ELEMENT`in e&&e.BYTES_PER_ELEMENT===1}const he=e=>e?`"${e}" `:``;function ge(e,t=``){if(typeof e!=`number`)throw TypeError(he(t)+`expected number, got `+typeof e);if(!Number.isSafeInteger(e)||e<0)throw RangeError(he(t)+`expected integer >= 0, got `+e);return e}function z(e,t,n=``){if(me(e)&&(t===void 0||e.length===t))return e;t!==void 0&&ge(t,`length`);let r=me(e),i=t===void 0?``:` of length ${t}`,a=r?`length=${e.length}`:`type=${typeof e}`,o=he(n)+`expected Uint8Array`+i+`, got `+a;throw r?RangeError(o):TypeError(o)}function _e(e){return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}function ve(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function ye(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}const be=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function xe(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}const B=be?e=>e:e=>xe(e)>>>0;function Se(e){for(let t=0;t<e.length;t++)e[t]=xe(e[t]);return e}const Ce=be?e=>e:Se;function we(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 Te(e,t){if(we(e,t)&&e.byteOffset<t.byteOffset)throw Error(`complex overlap of input and output is not supported`)}const Ee=(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,a=e.nonceLength===void 0?0:1;if(!e.withAAD){for(let e=a;e<r.length;e++)if(me(r[e]))throw Error(`AAD not supported`)}e.withAAD&&r[a]!==void 0&&z(r[a],void 0,`AAD`);let o=t(n,...r),s=(e,t)=>{if(t!==void 0){if(e!==2)throw Error(`cipher output not supported`);z(t,void 0,`output`)}},c=!1;return{encrypt(e,t){if(c)throw Error(`cannot encrypt() twice with same key + nonce`);return c=!0,z(e,void 0,`data`),s(o.encrypt.length,t),o.encrypt(e,t)},decrypt(e,t){if(z(e,void 0,`data`),i&&e.length<i)throw Error(`"ciphertext" expected length >= tagLength=`+i);return s(o.decrypt.length,t),o.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,e,`output`),n&&!Oe(t))throw Error(`invalid output, must be aligned`);return t}function Oe(e){return e.byteOffset%4==0}function ke(e){return Uint8Array.from(z(e))}function Ae(e){if(![16,24,32].includes(e.length))throw Error(`"aes key" expected Uint8Array of length 16/24/32, got length=`+e.length)}function je(e){return e<<1^283&-(e>>7)}function Me(e,t){let n=0;for(;t>0;t>>=1)n^=e&-(t&1),e=je(e);return n}const Ne=(()=>{let e=new Uint8Array(256);for(let t=0,n=1;t<256;t++,n^=je(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 ye(e),t})(),Pe=e=>e<<24|e>>>8,Fe=e=>e<<8|e>>>24;function Ie(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(Fe),i=r.map(Fe),a=i.map(Fe),o=new Uint32Array(65536),s=new Uint32Array(65536),c=new Uint16Array(65536);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 Le=Ie(Ne,e=>Me(e,3)<<24|e<<16|e<<8|Me(e,2)),Re=(()=>{let e=new Uint8Array(16);for(let t=0,n=1;t<16;t++,n=je(n))e[t]=n;return e})();function ze(e){z(e);let t=e.length;Ae(e);let{sbox2:n}=Le,r=[];(!be||!Oe(e))&&r.push(e=ke(e));let i=Ce(ve(e)),a=i.length,o=e=>Ve(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(Pe(t))^Re[e/a-1]:a>6&&e%a===4&&(t=o(t)),s[e]=s[e-a]^t}return ye(...r),s}function Be(e,t,n,r,i,a){return e[n<<8&65280|r>>>8&255]^t[i>>>8&65280|a>>>24&255]}function Ve(e,t,n,r,i){return e[t&255|n&65280]|e[r>>>16&255|i>>>16&65280]<<16}function He(e,t,n,r,i){let{sbox2:a,T01:o,T23:s}=Le,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++]^Be(o,s,t,n,r,i),l=e[c++]^Be(o,s,n,r,i,t),u=e[c++]^Be(o,s,r,i,t,n),d=e[c++]^Be(o,s,i,t,n,r);t=a,n=l,r=u,i=d}return{s0:e[c++]^Ve(a,t,n,r,i),s1:e[c++]^Ve(a,n,r,i,t),s2:e[c++]^Ve(a,r,i,t,n),s3:e[c++]^Ve(a,i,t,n,r)}}function Ue(e,t,n,r){z(t,16,`nonce`),z(n);let i=n.length;r=De(i,r),Te(n,r);let a=t,o=ve(a),s=ve(n),c=ve(r);for(let t=0;t+4<=s.length;t+=4){let{s0:n,s1:r,s2:i,s3:l}=He(e,B(o[0]),B(o[1]),B(o[2]),B(o[3]));c[t+0]=s[t+0]^B(n),c[t+1]=s[t+1]^B(r),c[t+2]=s[t+2]^B(i),c[t+3]=s[t+3]^B(l);for(let e=15,t=1;e>=0;e--)t=t+a[e]|0,a[e]=t&255,t>>>=8}let l=16*Math.floor(s.length/4);if(l<i){let{s0:t,s1:a,s2:s,s3:c}=He(e,B(o[0]),B(o[1]),B(o[2]),B(o[3])),u=new Uint32Array([t,a,s,c]);Ce(u);let d=_e(u);for(let e=l,t=0;e<i;e++,t++)r[e]=n[e]^d[t];ye(u)}return r}const We=Ee({blockSize:16,nonceLength:16},function(e,t){function n(n,r){if(z(n),r!==void 0&&(z(r),!Oe(r)))throw Error(`unaligned destination`);let i=ze(e),a=ke(t),o=[i,a];Oe(n)||o.push(n=ke(n));let s=Ue(i,a,n,r);return ye(...o),s}return{encrypt:(e,t)=>n(e,t),decrypt:(e,t)=>n(e,t)}});var Ge=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 Hash instance`);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,canXOF:s}=this;return e=e,e.finished=r,e.destroyed=i,e.blockLen=a,e.outputLen=o,e.canXOF=s,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 Ke=(()=>{let e=((e,t,n)=>new Ge(e,t).update(n).digest());return e.create=(e,t)=>new Ge(e,t),e})();function qe(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(`"c" (iterations) 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`);try{let n=t.Br(r,`salt`);try{let t=new Uint8Array(o),{iHash:r,oHash:i,outputLen:l}=Ke.create(e,c);return{c:a,dkLen:o,asyncTick:s,DK:t,outputLen:l,eng:Je(r,i,n,new Uint8Array(l))}}finally{typeof r==`string`&&t.Pr(n)}}finally{typeof n==`string`&&t.Pr(c)}}function Je(e,n,r,i){let a=new Uint8Array(4),o=t.Lr(a),s=e._cloneInto().update(r),c=n._cloneInto(),l=e._cloneInto,u=n._cloneInto;return{u1:(e,t)=>{o.setInt32(0,e,!1),s._cloneInto(c).update(a).digestInto(i),n._cloneInto(c).update(i).digestInto(i),t.set(i.subarray(0,t.length))},rounds:(t,r)=>{for(let a=1;a<t;a++){l.call(e,c).update(i).digestInto(i),u.call(n,c).update(i).digestInto(i);for(let e=0;e<r.length;e++)r[e]^=i[e]}},output:r=>(e.destroy(),n.destroy(),s.destroy(),c.destroy(),t.Pr(i),r)}}function Ye(e,t,n,r){let{c:i,dkLen:a,DK:o,outputLen:s,eng:c}=qe(e,t,n,r);for(let e=1,t=0;t<a;e++,t+=s){let n=o.subarray(t,t+s);c.u1(e,n),c.rounds(i,n)}return c.output(o)}const Xe=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]),Ze=new Uint32Array(64);var Qe=class extends c{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(e,t){super(64,e,8,!1),this.A=t[0]|0,this.B=t[1]|0,this.C=t[2]|0,this.D=t[3]|0,this.E=t[4]|0,this.F=t[5]|0,this.G=t[6]|0,this.H=t[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}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,n){for(let t=0;t<16;t++,n+=4)Ze[t]=e.getUint32(n,!1);for(let e=16;e<64;e++){let n=Ze[e-15],r=Ze[e-2],i=t.Wr(n,7)^t.Wr(n,18)^n>>>3,a=t.Wr(r,17)^t.Wr(r,19)^r>>>10;Ze[e]=a+Ze[e-7]+i+Ze[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)+Xe[e]+Ze[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(Ze)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),t.Pr(this.buffer)}},$e=class extends Qe{constructor(){super(32,l)}};const V=t.Ir(()=>new $e,t.Vr(1));function et(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++],te=e[n++]^r[i++],b=e[n++]^r[i++],x=s,S=c,C=l,w=u,T=d,E=f,D=p,O=m,k=h,A=g,j=_,M=v,N=y,P=ee,F=te,I=b;for(let e=0;e<8;e+=2)T^=t.Ur(x+N|0,7),k^=t.Ur(T+x|0,9),N^=t.Ur(k+T|0,13),x^=t.Ur(N+k|0,18),A^=t.Ur(E+S|0,7),P^=t.Ur(A+E|0,9),S^=t.Ur(P+A|0,13),E^=t.Ur(S+P|0,18),F^=t.Ur(j+D|0,7),C^=t.Ur(F+j|0,9),D^=t.Ur(C+F|0,13),j^=t.Ur(D+C|0,18),w^=t.Ur(I+M|0,7),O^=t.Ur(w+I|0,9),M^=t.Ur(O+w|0,13),I^=t.Ur(M+O|0,18),S^=t.Ur(x+w|0,7),C^=t.Ur(S+x|0,9),w^=t.Ur(C+S|0,13),x^=t.Ur(w+C|0,18),D^=t.Ur(E+T|0,7),O^=t.Ur(D+E|0,9),T^=t.Ur(O+D|0,13),E^=t.Ur(T+O|0,18),M^=t.Ur(j+A|0,7),k^=t.Ur(M+j|0,9),A^=t.Ur(k+M|0,13),j^=t.Ur(A+k|0,18),N^=t.Ur(I+F|0,7),P^=t.Ur(N+I|0,9),F^=t.Ur(P+N|0,13),I^=t.Ur(F+P|0,18);a[o++]=s+x|0,a[o++]=c+S|0,a[o++]=l+C|0,a[o++]=u+w|0,a[o++]=d+T|0,a[o++]=f+E|0,a[o++]=p+D|0,a[o++]=m+O|0,a[o++]=h+k|0,a[o++]=g+A|0,a[o++]=_+j|0,a[o++]=v+M|0,a[o++]=y+N|0,a[o++]=ee+P|0,a[o++]=te+F|0,a[o++]=b+I|0}function tt(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)et(n,o,e,t,n,a),r>0&&(o+=16),et(n,a,e,t+=16,n,o)}const nt=1024*(2**20+1+1);function rt(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:nt},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(`"onProgress" must be a function`);if(a<1)throw Error(`"r" expected integer >= 1`);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=Ye(V,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,n=Math.max(Math.floor(e/1e4),1),r=0;y=()=>{if(r++,u&&(!(r%n)||r===e))try{u(r/e)}catch(e){throw t.Pr(h,_,v),e}}}return{N:i,r:a,p:o,dkLen:s,blockSize32:f,V:_,B32:g,B:h,tmp:v,blockMixCb:y,asyncTick:c}}function it(e,n,r,i,a){let o=Ye(V,e,r,{c:1,dkLen:n});return t.Pr(r,i,a),o}async function at(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}=rt(e,n,r),h=()=>t.Pr(d,l,f);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,()=>{tt(l,r,l,r+=c,a),p()},h),tt(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];tt(f,0,u,n,a),p()},h)}return t.Gr(u),it(e,s,d,l,f)}function ot(e,n){return t.Sr(k(t.Yr(e.subarray(16,32),n))).slice(2)}async function st(e,n,r){let i=t.Hr(32),a=t.Hr(16),o={dklen:32,salt:t.Sr(i).slice(2),n:262144,r:8,p:1},s=await at(t.Qr(r,`utf8`),i,{N:o.n,r:o.r,p:o.p,dkLen:o.dklen}),c=We(s.subarray(0,16),a.map(e=>e)).encrypt(t.Yr(t.Qr(e),t.Qr(n)));return{id:t.Sr(t.Hr(16)).slice(2),crypto:{ciphertext:t.Sr(c).slice(2),cipherparams:{iv:t.Sr(a).slice(2)},cipher:`aes-128-ctr`,kdf:`scrypt`,kdfparams:o,mac:ot(s,c)}}}async function ct(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 at(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(ot(a,o)!==r.mac)throw Error(`Invalid password`);let s=We(a.subarray(0,16),t.Qr(r.cipherparams.iv)).decrypt(o);return{privateKey:s.slice(0,32),chainCode:s.slice(32)}}var lt=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=>ut.from(e))??[])}},ut=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.Sr(n.publicKey):void 0)}};
|
|
4
4
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
@@ -16,8 +16,8 @@ const nr={p:BigInt(`0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffeff
|
|
|
16
16
|
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
17
17
|
function Rr(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`}function zr(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 Br(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 Vr(e,t){zr(e);let n=t.outputLen;if(e.length<n)throw Error(`digestInto() expects output buffer of length at least `+n)}function Hr(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Ur(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function X(e,t){return e<<32-t|e>>>t}function Wr(e){if(typeof e!=`string`)throw Error(`string expected`);return new Uint8Array(new TextEncoder().encode(e))}function Gr(e){return typeof e==`string`&&(e=Wr(e)),zr(e),e}var Kr=class{};function qr(e){let t=t=>e().update(Gr(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function Jr(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 Yr(e,t,n){return e&t^~e&n}function Xr(e,t,n){return e&t^e&n^t&n}var Zr=class extends Kr{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=Ur(this.buffer)}update(e){Br(this),e=Gr(e),zr(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=Ur(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){Br(this),Vr(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:r,isLE:i}=this,{pos:a}=this;t[a++]=128,Hr(this.buffer.subarray(a)),this.padOffset>r-a&&(this.process(n,0),a=0);for(let e=a;e<r;e++)t[e]=0;Jr(n,r-8,BigInt(this.length*8),i),this.process(n,0);let o=Ur(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 Qr=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),$r=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]),ei=new Uint32Array(64);var ti=class extends Zr{constructor(e=32){super(64,e,8,!1),this.A=Qr[0]|0,this.B=Qr[1]|0,this.C=Qr[2]|0,this.D=Qr[3]|0,this.E=Qr[4]|0,this.F=Qr[5]|0,this.G=Qr[6]|0,this.H=Qr[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)ei[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){let t=ei[e-15],n=ei[e-2],r=X(t,7)^X(t,18)^t>>>3,i=X(n,17)^X(n,19)^n>>>10;ei[e]=i+ei[e-7]+r+ei[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=X(o,6)^X(o,11)^X(o,25),u=l+t+Yr(o,s,c)+$r[e]+ei[e]|0,d=(X(n,2)^X(n,13)^X(n,22))+Xr(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(){Hr(ei)}destroy(){this.set(0,0,0,0,0,0,0,0),Hr(this.buffer)}};const ni=qr(()=>new ti);function ri(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 ii=ri(`123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz`);function ai(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),ii.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=ii.decodeUnsafe(e);if(t!=null)return n(t)}function i(e){var t=n(ii.decode(e));if(t==null)throw Error(`Invalid checksum`);return t}return{encode:t,decode:i,decodeUnsafe:r}}function oi(e){return ni(ni(e))}var si=ai(oi);function ci(e){let n=t.er(e);return n<253?t.rr(n,1):n<=65535?t.Yr([253],t.rr(n,2)):n<=4294967295?t.Yr([254],t.rr(n,4)):t.Yr([255],t.rr(n,8))}function li(e,n){let r=n??`Bitcoin Signed Message:
|
|
18
18
|
`,i=typeof r==`string`?t.Qr(r,`utf8`):t.Qr(r),a=typeof e==`string`?t.Qr(e,`utf8`):t.Qr(e);return V(V(t.Yr(i,ci(a.length),a)))}function ui(e){return Lr(V(t.Qr(e)))}function di(e,n){return si.encode(t.Yr([n],ui(e)))}function fi(e){return t.Sr(si.decode(e).subarray(1))}function pi(e,n,r){let i=typeof e==`string`?e:t.Sr(e).slice(2),a=t.Qr(n,`base64`).subarray(1);return lr.verify(t.Qr(a),li(i),t.Qr(r),{prehash:!1})}function mi(e,n){let r=lr.sign(t.Qr(e),t.Qr(n),{format:`recovered`,prehash:!1});return t.Sr(t.Yr(r.subarray(1),r.subarray(0,1)))}function hi(e,n,r){let i=t.Qr(n);return lr.verify(t.Yr(i.subarray(64),i.subarray(0,64)),t.Qr(e),t.Qr(r),{format:`recovered`,prehash:!1})}function gi(e,n){let r=t.Qr(n);return t.Sr(lr.recoverPublicKey(t.Yr(r.subarray(64),r.subarray(0,64)),t.Qr(e),{prehash:!1}))}function _i(e){let n=typeof e==`string`?e:t.Sr(e),r=t.Qr(`Nervos Message:${n}`,`utf8`);return t._r(r)}function vi(e,t,n){return hi(_i(e),t,n)}function yi(e,n,r){let a=typeof e==`string`?e:t.Sr(e).slice(2),{publicKey:o,keyType:s}=JSON.parse(r);return(0,i.verifySignature)({challenge:a,pubkey:o,keyType:s,...JSON.parse(n)})}function bi(e,t){return li(e,t??`Dogecoin Signed Message:
|
|
19
|
-
`)}function xi(e,n,r){let i=typeof e==`string`?e:t.Sr(e).slice(2),a=t.Qr(n,`base64`);return a[0]-=31,fi(r)===t.Sr(ui(lr.recoverPublicKey(a,bi(i),{prehash:!1})))}function Si(e,n,r){return r.toLowerCase()===(0,a.verifyMessage)(typeof e==`string`?e:t.Qr(e),n).toLowerCase()}function Ci(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.Sr(e),tags:[]}}function wi(e){let n=JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content]);return V(t.Qr(n,`utf8`))}function Ti(e,r,i){let{words:a}=n.bech32.decode(i),o=t.Sr(n.bech32.fromWords(a)).slice(2),s=wi({...Ci(e),pubkey:o});try{return Sr.verify(t.Qr(r),s,t.Qr(o))}catch{return!1}}let Ei=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}({}),Di=function(e){return e.EVM=`EVM`,e.BTC=`BTC`,e.CKB=`CKB`,e.Nostr=`Nostr`,e.Doge=`Doge`,e}({});var Oi=class{constructor(e,t,n){this.signature=e,this.identity=t,this.signType=n}},Z=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 Si(e,t.signature,t.identity);case`BtcEcdsa`:return pi(e,t.signature,t.identity);case`JoyId`:return yi(e,t.signature,t.identity);case`NostrEvent`:return Ti(e,t.signature,t.identity);case`CkbSecp256k1`:return vi(e,t.signature,t.identity);case`DogeEcdsa`:return xi(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.j.from(e)}signOnlyTransaction(e){throw Error(`Signer.signOnlyTransaction not implemented`)}},ki=class extends Z{async sendTransaction(e){let t=await this.signTransaction(e);if(await this.needMoreSignatures(t))throw new Ai(await this.getSignaturesCount(t)??0,await this.getMemberThreshold());return this.client.sendTransaction(t)}},Ai=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}},ji=class{constructor(e,t){this.name=e,this.signer=t}},Mi=class extends Z{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.Sr(await this.getBtcPublicKey()).slice(2)}async getAddressObjs(){let e=ui(await this.getBtcPublicKey());return[await L.fromKnownScript(this.client,`OmniLock`,t.Sr([4,...e,0]))]}async prepareTransaction(e){let n=t.j.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.j.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.M.fromBytes(n.witnesses[i.position]);return o.lock=t.Sr(t.Yr(t.or(20+a.length,4),t.or(16,4),t.or(20+a.length,4),t.or(20+a.length,4),t.or(a.length,4),a)),n.setWitnessArgs(i.position,o),n}},Ni=class extends Mi{constructor(e,n,r){super(e),this.account=n,this.publicKey=t.Sr(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`)}},Pi=class extends Z{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 L.fromKnownScript(this.client,`AlwaysSuccess`,`0x`)]}async prepareTransaction(e){let n=t.j.from(e);return await n.addCellDepsOfKnownScripts(this.client,`AlwaysSuccess`),n}async signOnlyTransaction(e){return t.j.from(e)}},Fi=class extends Z{get type(){return`CKB`}get signType(){return`CkbSecp256k1`}constructor(e,n){if(super(e),this.publicKey=t.Sr(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 L.fromKnownScript(this.client,`Secp256k1Blake160`,t.vr(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.K.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(L.from({prefix:this.client.addressPrefix,script:i.cellOutput.lock}))}return[e,...n]}async getRelatedScripts(e){let n=t.j.from(e),r=await this.getAddressObjSecp256k1(),i=await t.K.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.j.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}},Ii=class extends Fi{constructor(e,n){let r=t.Sr(n);if(t.Qr(r).length!==32)throw Error(`Private key must be 32 bytes!`);super(e,lr.getPublicKey(t.Qr(r),!0)),this.privateKey=r}async _signMessage(e){return mi(e,this.privateKey)}async signMessageRaw(e){return this._signMessage(_i(e))}async signOnlyTransaction(e){let n=t.j.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.M.from({});a.lock=i,n.setWitnessArgs(r.position,a)}return n}},Li=class extends Z{get type(){return`CKB`}get signType(){return`Unknown`}constructor(e,...n){if(super(e),this.scripts=n.flat().map(t.K.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=>L.fromScript(e,this.client))}},Ri;let Q=Ri=class extends t.fr.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.vr(e));return new Ri(n.map(t.Sr),Number(t.er(e.threshold)),Number(t.er(e.mustMatch??0)),e.signatures?.map(t.Sr)??[])}get flexibleThreshold(){return this.threshold-this.mustMatch}scriptArgs(e){let n=t.vr(Ri.from({...this,signatures:[]}).toBytes());return e==null?t.Qr(n):t.Yr(n,t.A.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!==zi.EmptySignature)){let i=(()=>{try{return gi(e,r)}catch{return}})();if(i===void 0)continue;let a=t.vr(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}}};Q=Ri=t.Tt([t.pr({encode:e=>{let{publicKeyHashes:n,threshold:r,mustMatch:i,signatures:a}=Q.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.or(i??0),t.or(r),t.or(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 Q.from({publicKeyHashes:Array.from(Array(a),(e,n)=>t.Sr(o.slice(n*20,(n+1)*20))),threshold:t.er(i),mustMatch:t.er(r),signatures:Array.from(Array(Math.floor(s.length/65)),(e,n)=>t.Sr(s.slice(n*65,(n+1)*65)))})}})],Q);var zi=class e extends ki{static{this.EmptySignature=t.Sr(`00`.repeat(65))}get type(){return`CKB`}get signType(){return`Unknown`}constructor(e,n,r){super(e),this.multisigInfo=Q.from(n),this.since=t.Et(t.A.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.K.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})=>L.fromScript(e,this.client))}decodeWitnessArgsAt(e,n){let r=t.j.from(e);return this.decodeWitnessArgs(r.getWitnessArgs(n))}decodeWitnessArgs(e){if(!e)return;let n=t.M.from(e);if(n.lock!=null)try{let e=Q.decode(n.lock);if(e.eqInfo(this.multisigInfo))return e}catch{}}async prepareWitnessArgsAt(n,r,i){let a=t.j.from(n),o=a.getWitnessArgs(r)??t.M.from({}),s=this.decodeWitnessArgs(o)??this.multisigInfo.clone(),c=Q.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.j.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.j.from(e))}async getSignaturesCount(e){let n=t.j.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.j.from(n),a=await i.findInputIndexByLock(r,this.client);if(a==null)return;let o=i.getWitnessArgs(a)??t.M.from({});o.lock=Q.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.j.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.j.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}},Bi=class extends zi{constructor(e,n,r,i){super(e,r,i),this.privateKey=t.Sr(n),this.signer=new Ii(e,this.privateKey)}async signOnlyTransaction(e){let n=t.j.from(e),r=t.vr(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(mi(t.message,this.privateKey)),e.signatures=n,e}))}return n}},Vi=class extends Z{get type(){return`Doge`}get signType(){return`DogeEcdsa`}async getInternalAddress(){return this.getDogeAddress()}async getIdentity(){return this.getDogeAddress()}async getAddressObjs(){let e=si.decode(await this.getDogeAddress()).subarray(1);return[await L.fromKnownScript(this.client,`OmniLock`,t.Sr([5,...e,0]))]}async prepareTransaction(e){let n=t.j.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.j.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.M.fromBytes(n.witnesses[i.position]);return o.lock=t.Sr(t.Yr(t.or(20+a.length,4),t.or(16,4),t.or(20+a.length,4),t.or(20+a.length,4),t.or(a.length,4),a)),n.setWitnessArgs(i.position,o),n}},Hi=class extends Vi{constructor(e,t){super(e),this.address=t}async connect(){}async isConnected(){return!0}async getDogeAddress(){return this.address}},Ui=class extends Vi{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.Sr(lr.getPublicKey(this.privateKey,!0))}async getDogeAddress(){return di(await this.getDogePublicKey(),this.dogeNetwork)}async signMessageRaw(e){let n=typeof e==`string`?e:t.Sr(e).slice(2),r=lr.sign(bi(n),this.privateKey,{format:`recovered`,prehash:!1});return t.$r(t.Yr([31+Number(r[0])],r.subarray(1)),`base64`)}},Wi=class extends Z{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`)}},Gi=class extends Wi{constructor(e,t,n){super(e,t),this.message=n}async connect(){throw Error(this.message)}},Ki=class extends Wi{constructor(e,t,n){super(e,t),this.link=n}async connect(){window.open(this.link,`_blank`)?.focus()}},qi=class extends Z{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 L.fromKnownScript(this.client,`OmniLock`,t.Sr([18,...t.Qr(e),0]))}async _getOmniLockOldEvmAddressObj(e){return L.fromKnownScript(this.client,`OmniLock`,t.Sr([1,...t.Qr(e),0]))}async _getPWLockEvmAddressObj(e){try{return L.fromKnownScript(this.client,`PWLock`,t.Sr(t.Qr(e)))}catch{}}async prepareTransaction(e){let n=t.j.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),a=await this._getPWLockAddresses(r),o=t.kt(i,(e,{script:t})=>e.prepareSighashAllWitness(t,85,this.client),n);return t.kt(a,(e,{script:t})=>e.prepareSighashAllWitness(t,65,this.client),o)}async signOnlyTransaction(e){let n=t.j.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.M.fromBytes(e.witnesses[i.position]);return a.lock=t.Sr(t.Yr(t.or(20+i.signature.length,4),t.or(16,4),t.or(20+i.signature.length,4),t.or(20+i.signature.length,4),t.or(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 A);if(!i)return e;let a=t.M.fromBytes(e.witnesses[i.position]);return a.lock=t.Sr(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}}},Ji=class extends qi{constructor(e,n){super(e),this.address=t.Sr(n)}async connect(){}async isConnected(){return!0}async getEvmAccount(){return this.address}};function Yi(e){if(e===`ckb`)return`ckb-mainnet`;if(e===`ckt`)return`ckb-testnet`;throw Error(`Unsupported address prefix: ${e}`)}function Xi({connect:e,confirmRequest:n,getSigner:r,getSignerMetadata:i=()=>({})}){let a=()=>{let e=r();if(!e)throw new R({code:-32e3,message:`No signer is connected`});return e},o=new Map([[`get_info`,e=>($(e,0),ea(a(),i()))],[`connect`,async t=>{let[r]=$(t,1);if(typeof r!=`string`||!r)throw new R({code:-32602,message:`Invalid network ID`});await Zi(n,{method:`connect`,networkId:r});let i=Yi((await e(r)).client.addressPrefix);if(i!==r)throw new R({code:-32002,message:`Signer uses ${i}, expected ${r}`});return null}],[`get_scripts`,async e=>($(e,0),(await a().getAddressObjs()).map(({script:e})=>t.s.scriptFrom(e)))],[`get_native_address`,e=>($(e,0),a().getInternalAddress())],[`get_identity`,e=>($(e,0),a().getIdentity())],[`sign_message`,async e=>{let[r]=$(e,1),i=Qi(r);return await Zi(n,{method:`sign_message`,message:t.t.messageFrom(i)}),a().signMessageRaw(i)}],[`prepare_transaction`,async e=>{let[n]=$(e,1);return t.s.transactionFrom(await a().prepareTransaction($i(n)))}],[`sign_transaction`,async e=>{let[r]=$(e,1),i=$i(r);return await Zi(n,{method:`sign_transaction`,transaction:i}),t.s.transactionFrom(await a().signOnlyTransaction(i))}]]);return e=>{let t=o.get(e.method);if(!t)throw new R({code:-32601,message:`Unsupported method: ${e.method}`});return t(e)}}async function Zi(e,t){if(!await e(t))throw new R({code:-32003,message:`User rejected request`})}function Qi(e){try{return t.t.messageTo(e)}catch(e){throw new R({code:-32602,message:e instanceof Error?e.message:`Invalid signer message`})}}function $i(e){try{return t.s.transactionTo(e)}catch(e){throw new R({code:-32602,message:e instanceof Error?e.message:`Invalid signer transaction`})}}function $(e,t){if(!Array.isArray(e.params)||e.params.length!==t)throw new R({code:-32602,message:`${e.method} expects ${t} parameter${t===1?``:`s`}`});return e.params}function ea(e,n){return t.t.infoFrom({type:e.type,signType:e.signType,name:n.name,icon:n.icon})}var ta=class e extends Z{constructor(e,n,r,i){super(e),this.requestor=n,this.info=r,this.disconnectHandler=i,this.replacedListeners=new Set,this.getScripts=this.buildSender(`get_scripts`,[],e=>e.map(e=>t.s.scriptTo(e))),this.getInternalAddress=this.buildSender(`get_native_address`,[]),this.getIdentity=this.buildSender(`get_identity`,[]),this.signMessageRaw=this.buildSender(`sign_message`,[t.t.messageFrom]),this.prepareTransaction=this.buildSender(`prepare_transaction`,[t.s.transactionFrom],t.s.transactionTo),this.signOnlyTransaction=this.buildSender(`sign_transaction`,[t.s.transactionFrom],t.s.transactionTo),this.requestConnect=this.buildSender(`connect`,[])}static async new(n,r){let{disconnectHandler:i,...a}=r,o=ce.new(a),s=await o.request(`get_info`,[],[],t.t.infoTo);return new e(n,o,s,i)}get type(){return this.info.type}get signType(){return this.info.signType}get url(){return this.requestor.url}get name(){return this.info.name}get icon(){return this.info.icon}connect(){if(this.disconnecting)return this.disconnecting.then(()=>this.connect());if(this.connecting)return this.connecting;let e=this.requestConnect(Yi(this.client.addressPrefix)).catch(t=>{throw this.connecting===e&&(this.connecting=void 0),t});return this.connecting=e,e}disconnect(){return this.disconnecting?this.disconnecting:this.connecting?(this.connecting=void 0,this.disconnecting=Promise.resolve().then(()=>this.disconnectHandler?.()).finally(()=>{this.replace(),this.disconnecting=void 0}),this.disconnecting):Promise.resolve()}onReplaced(e){return this.replacedListeners.add(e),()=>this.replacedListeners.delete(e)}replace(){this.connecting=void 0;let e=[...this.replacedListeners];this.replacedListeners.clear(),e.forEach(e=>e())}async isConnected(){return this.connecting?.then(()=>!0,()=>!1)??!1}async getAddressObjs(){return(await this.getScripts()).map(e=>L.fromScript(e,this.client))}buildSender(e,t,n){return async(...r)=>this.requestor.request(e,r,t,n)}},na=class e extends Z{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
|
|
19
|
+
`)}function xi(e,n,r){let i=typeof e==`string`?e:t.Sr(e).slice(2),a=t.Qr(n,`base64`);return a[0]-=31,fi(r)===t.Sr(ui(lr.recoverPublicKey(a,bi(i),{prehash:!1})))}function Si(e,n,r){return r.toLowerCase()===(0,a.verifyMessage)(typeof e==`string`?e:t.Qr(e),n).toLowerCase()}function Ci(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.Sr(e),tags:[]}}function wi(e){let n=JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content]);return V(t.Qr(n,`utf8`))}function Ti(e,r,i){let{words:a}=n.bech32.decode(i),o=t.Sr(n.bech32.fromWords(a)).slice(2),s=wi({...Ci(e),pubkey:o});try{return Sr.verify(t.Qr(r),s,t.Qr(o))}catch{return!1}}let Ei=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}({}),Di=function(e){return e.EVM=`EVM`,e.BTC=`BTC`,e.CKB=`CKB`,e.Nostr=`Nostr`,e.Doge=`Doge`,e}({});var Oi=class{constructor(e,t,n){this.signature=e,this.identity=t,this.signType=n}},Z=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 Si(e,t.signature,t.identity);case`BtcEcdsa`:return pi(e,t.signature,t.identity);case`JoyId`:return yi(e,t.signature,t.identity);case`NostrEvent`:return Ti(e,t.signature,t.identity);case`CkbSecp256k1`:return vi(e,t.signature,t.identity);case`DogeEcdsa`:return xi(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.j.from(e)}signOnlyTransaction(e){throw Error(`Signer.signOnlyTransaction not implemented`)}},ki=class extends Z{async sendTransaction(e){let t=await this.signTransaction(e);if(await this.needMoreSignatures(t))throw new Ai(await this.getSignaturesCount(t)??0,await this.getMemberThreshold());return this.client.sendTransaction(t)}},Ai=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}},ji=class{constructor(e,t){this.name=e,this.signer=t}},Mi=class extends Z{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.Sr(await this.getBtcPublicKey()).slice(2)}async getAddressObjs(){let e=ui(await this.getBtcPublicKey());return[await L.fromKnownScript(this.client,`OmniLock`,t.Sr([4,...e,0]))]}async prepareTransaction(e){let n=t.j.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.j.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.M.fromBytes(n.witnesses[i.position]);return o.lock=t.Sr(t.Yr(t.or(20+a.length,4),t.or(16,4),t.or(20+a.length,4),t.or(20+a.length,4),t.or(a.length,4),a)),n.setWitnessArgs(i.position,o),n}},Ni=class extends Mi{constructor(e,n,r){super(e),this.account=n,this.publicKey=t.Sr(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`)}},Pi=class extends Z{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 L.fromKnownScript(this.client,`AlwaysSuccess`,`0x`)]}async prepareTransaction(e){let n=t.j.from(e);return await n.addCellDepsOfKnownScripts(this.client,`AlwaysSuccess`),n}async signOnlyTransaction(e){return t.j.from(e)}},Fi=class extends Z{get type(){return`CKB`}get signType(){return`CkbSecp256k1`}constructor(e,n){if(super(e),this.publicKey=t.Sr(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 L.fromKnownScript(this.client,`Secp256k1Blake160`,t.vr(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.K.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(L.from({prefix:this.client.addressPrefix,script:i.cellOutput.lock}))}return[e,...n]}async getRelatedScripts(e){let n=t.j.from(e),r=await this.getAddressObjSecp256k1(),i=await t.K.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.j.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}},Ii=class extends Fi{constructor(e,n){let r=t.Sr(n);if(t.Qr(r).length!==32)throw Error(`Private key must be 32 bytes!`);super(e,lr.getPublicKey(t.Qr(r),!0)),this.privateKey=r}async _signMessage(e){return mi(e,this.privateKey)}async signMessageRaw(e){return this._signMessage(_i(e))}async signOnlyTransaction(e){let n=t.j.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.M.from({});a.lock=i,n.setWitnessArgs(r.position,a)}return n}},Li=class extends Z{get type(){return`CKB`}get signType(){return`Unknown`}constructor(e,...n){if(super(e),this.scripts=n.flat().map(t.K.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=>L.fromScript(e,this.client))}},Ri;let Q=Ri=class extends t.fr.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.vr(e));return new Ri(n.map(t.Sr),Number(t.er(e.threshold)),Number(t.er(e.mustMatch??0)),e.signatures?.map(t.Sr)??[])}get flexibleThreshold(){return this.threshold-this.mustMatch}scriptArgs(e){let n=t.vr(Ri.from({...this,signatures:[]}).toBytes());return e==null?t.Qr(n):t.Yr(n,t.A.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!==zi.EmptySignature)){let i=(()=>{try{return gi(e,r)}catch{return}})();if(i===void 0)continue;let a=t.vr(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}}};Q=Ri=t.Tt([t.pr({encode:e=>{let{publicKeyHashes:n,threshold:r,mustMatch:i,signatures:a}=Q.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.or(i??0),t.or(r),t.or(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 Q.from({publicKeyHashes:Array.from(Array(a),(e,n)=>t.Sr(o.slice(n*20,(n+1)*20))),threshold:t.er(i),mustMatch:t.er(r),signatures:Array.from(Array(Math.floor(s.length/65)),(e,n)=>t.Sr(s.slice(n*65,(n+1)*65)))})}})],Q);var zi=class e extends ki{static{this.EmptySignature=t.Sr(`00`.repeat(65))}get type(){return`CKB`}get signType(){return`Unknown`}constructor(e,n,r){super(e),this.multisigInfo=Q.from(n),this.since=t.Et(t.A.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.K.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})=>L.fromScript(e,this.client))}decodeWitnessArgsAt(e,n){let r=t.j.from(e);return this.decodeWitnessArgs(r.getWitnessArgs(n))}decodeWitnessArgs(e){if(!e)return;let n=t.M.from(e);if(n.lock!=null)try{let e=Q.decode(n.lock);if(e.eqInfo(this.multisigInfo))return e}catch{}}async prepareWitnessArgsAt(n,r,i){let a=t.j.from(n),o=a.getWitnessArgs(r)??t.M.from({}),s=this.decodeWitnessArgs(o)??this.multisigInfo.clone(),c=Q.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.j.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.j.from(e))}async getSignaturesCount(e){let n=t.j.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.j.from(n),a=await i.findInputIndexByLock(r,this.client);if(a==null)return;let o=i.getWitnessArgs(a)??t.M.from({});o.lock=Q.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.j.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.j.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}},Bi=class extends zi{constructor(e,n,r,i){super(e,r,i),this.privateKey=t.Sr(n),this.signer=new Ii(e,this.privateKey)}async signOnlyTransaction(e){let n=t.j.from(e),r=t.vr(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(mi(t.message,this.privateKey)),e.signatures=n,e}))}return n}},Vi=class extends Z{get type(){return`Doge`}get signType(){return`DogeEcdsa`}async getInternalAddress(){return this.getDogeAddress()}async getIdentity(){return this.getDogeAddress()}async getAddressObjs(){let e=si.decode(await this.getDogeAddress()).subarray(1);return[await L.fromKnownScript(this.client,`OmniLock`,t.Sr([5,...e,0]))]}async prepareTransaction(e){let n=t.j.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.j.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.M.fromBytes(n.witnesses[i.position]);return o.lock=t.Sr(t.Yr(t.or(20+a.length,4),t.or(16,4),t.or(20+a.length,4),t.or(20+a.length,4),t.or(a.length,4),a)),n.setWitnessArgs(i.position,o),n}},Hi=class extends Vi{constructor(e,t){super(e),this.address=t}async connect(){}async isConnected(){return!0}async getDogeAddress(){return this.address}},Ui=class extends Vi{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.Sr(lr.getPublicKey(this.privateKey,!0))}async getDogeAddress(){return di(await this.getDogePublicKey(),this.dogeNetwork)}async signMessageRaw(e){let n=typeof e==`string`?e:t.Sr(e).slice(2),r=lr.sign(bi(n),this.privateKey,{format:`recovered`,prehash:!1});return t.$r(t.Yr([31+Number(r[0])],r.subarray(1)),`base64`)}},Wi=class extends Z{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`)}},Gi=class extends Wi{constructor(e,t,n){super(e,t),this.message=n}async connect(){throw Error(this.message)}},Ki=class extends Wi{constructor(e,t,n){super(e,t),this.link=n}async connect(){window.open(this.link,`_blank`)?.focus()}},qi=class extends Z{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 L.fromKnownScript(this.client,`OmniLock`,t.Sr([18,...t.Qr(e),0]))}async _getOmniLockOldEvmAddressObj(e){return L.fromKnownScript(this.client,`OmniLock`,t.Sr([1,...t.Qr(e),0]))}async _getPWLockEvmAddressObj(e){try{return L.fromKnownScript(this.client,`PWLock`,t.Sr(t.Qr(e)))}catch{}}async prepareTransaction(e){let n=t.j.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),a=await this._getPWLockAddresses(r),o=t.kt(i,(e,{script:t})=>e.prepareSighashAllWitness(t,85,this.client),n);return t.kt(a,(e,{script:t})=>e.prepareSighashAllWitness(t,65,this.client),o)}async signOnlyTransaction(e){let n=t.j.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.M.fromBytes(e.witnesses[i.position]);return a.lock=t.Sr(t.Yr(t.or(20+i.signature.length,4),t.or(16,4),t.or(20+i.signature.length,4),t.or(20+i.signature.length,4),t.or(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 A);if(!i)return e;let a=t.M.fromBytes(e.witnesses[i.position]);return a.lock=t.Sr(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}}},Ji=class extends qi{constructor(e,n){super(e),this.address=t.Sr(n)}async connect(){}async isConnected(){return!0}async getEvmAccount(){return this.address}};function Yi(e){if(e===`ckb`)return`ckb-mainnet`;if(e===`ckt`)return`ckb-testnet`;throw Error(`Unsupported address prefix: ${e}`)}function Xi({connect:e,confirmRequest:n,getSigner:r,getSignerMetadata:i=()=>({})}){let a=()=>{let e=r();if(!e)throw new R({code:-32e3,message:`No signer is connected`});return e},o=new Map([[`get_info`,e=>($(e,0),ea(a(),i()))],[`connect`,async t=>{let[r]=$(t,1);if(typeof r!=`string`||!r)throw new R({code:-32602,message:`Invalid network ID`});await Zi(n,{method:`connect`,networkId:r});let i=Yi((await e(r)).client.addressPrefix);if(i!==r)throw new R({code:-32002,message:`Signer uses ${i}, expected ${r}`});return null}],[`get_scripts`,async e=>($(e,0),(await a().getAddressObjs()).map(({script:e})=>t.s.scriptFrom(e)))],[`get_native_address`,e=>($(e,0),a().getInternalAddress())],[`get_identity`,e=>($(e,0),a().getIdentity())],[`sign_message`,async e=>{let[r]=$(e,1),i=Qi(r);return await Zi(n,{method:`sign_message`,message:t.t.messageFrom(i)}),a().signMessageRaw(i)}],[`prepare_transaction`,async e=>{let[n]=$(e,1);return t.s.transactionFrom(await a().prepareTransaction($i(n)))}],[`sign_transaction`,async e=>{let[r]=$(e,1),i=$i(r);return await Zi(n,{method:`sign_transaction`,transaction:i}),t.s.transactionFrom(await a().signOnlyTransaction(i))}]]);return e=>{let t=o.get(e.method);if(!t)throw new R({code:-32601,message:`Unsupported method: ${e.method}`});return t(e)}}async function Zi(e,t){if(!await e(t))throw new R({code:-32003,message:`User rejected request`})}function Qi(e){try{return t.t.messageTo(e)}catch(e){throw new R({code:-32602,message:e instanceof Error?e.message:`Invalid signer message`})}}function $i(e){try{return t.s.transactionTo(e)}catch(e){throw new R({code:-32602,message:e instanceof Error?e.message:`Invalid signer transaction`})}}function $(e,t){if(!Array.isArray(e.params)||e.params.length!==t)throw new R({code:-32602,message:`${e.method} expects ${t} parameter${t===1?``:`s`}`});return e.params}function ea(e,n){return t.t.infoFrom({type:e.type,signType:e.signType,name:n.name,icon:n.icon})}var ta=class e extends Z{constructor(e,n,r,i){super(e),this.requestor=n,this.info=r,this.disconnectHandler=i,this.replacedListeners=new Set,this.signMessageRaw=this.buildSender(`sign_message`,[t.t.messageFrom]),this.prepareTransaction=this.buildSender(`prepare_transaction`,[t.s.transactionFrom],t.s.transactionTo),this.signOnlyTransaction=this.buildSender(`sign_transaction`,[t.s.transactionFrom],t.s.transactionTo),this.requestConnect=this.buildSender(`connect`,[])}static async new(n,r){let{disconnectHandler:i,...a}=r,o=ce.new(a),s=await o.request(`get_info`,[],[],t.t.infoTo);return new e(n,o,s,i)}get type(){return this.info.type}get signType(){return this.info.signType}get url(){return this.requestor.url}get name(){return this.info.name}get icon(){return this.info.icon}connect(){if(this.disconnecting)return this.disconnecting.then(()=>this.connect());if(this.connecting)return this.connecting;let e=this.requestConnect(Yi(this.client.addressPrefix)).catch(t=>{throw this.connecting===e&&(this.connecting=void 0),t});return this.connecting=e,e}disconnect(){return this.clearReadCache(),this.disconnecting?this.disconnecting:this.connecting?(this.connecting=void 0,this.disconnecting=Promise.resolve().then(()=>this.disconnectHandler?.()).finally(()=>{this.replace(),this.disconnecting=void 0}),this.disconnecting):Promise.resolve()}onReplaced(e){return this.replacedListeners.add(e),()=>this.replacedListeners.delete(e)}replace(){this.connecting=void 0,this.clearReadCache();let e=[...this.replacedListeners];this.replacedListeners.clear(),e.forEach(e=>e())}async isConnected(){return this.connecting?.then(()=>!0,()=>!1)??!1}getScripts(){if(this.scriptsPromise)return this.scriptsPromise.then(e=>[...e]);let e=this.requestor.request(`get_scripts`,[],[],e=>e.map(e=>t.s.scriptTo(e))).catch(t=>{throw this.scriptsPromise===e&&(this.scriptsPromise=void 0),t});return this.scriptsPromise=e,e.then(e=>[...e])}async getAddressObjs(){return(await this.getScripts()).map(e=>L.fromScript(e,this.client))}getInternalAddress(){if(this.internalAddressPromise)return this.internalAddressPromise;let e=this.requestor.request(`get_native_address`,[],[]).catch(t=>{throw this.internalAddressPromise===e&&(this.internalAddressPromise=void 0),t});return this.internalAddressPromise=e,e}getIdentity(){if(this.identityPromise)return this.identityPromise;let e=this.requestor.request(`get_identity`,[],[]).catch(t=>{throw this.identityPromise===e&&(this.identityPromise=void 0),t});return this.identityPromise=e,e}buildSender(e,t,n){return async(...r)=>this.requestor.request(e,r,t,n)}clearReadCache(){this.scriptsPromise=void 0,this.internalAddressPromise=void 0,this.identityPromise=void 0}},na=class e extends Z{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
|
|
20
20
|
|
|
21
21
|
IMPORTANT: Please verify the integrity and authenticity of connected Nostr client before signing this message
|
|
22
22
|
`}get type(){return`Nostr`}get signType(){return`NostrEvent`}async signNostrEvent(e){throw Error(`SignerNostr.signNostrEvent not implemented`)}async signMessageRaw(e){return t.Sr((await this.signNostrEvent(Ci(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 L.fromKnownScript(this.client,`NostrLock`,t.Sr(t.Yr([0],t._r(e).slice(0,42))))]}async prepareTransaction(e){let n=t.j.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.j.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.M.fromBytes(r.witnesses[a.position]);return s.lock=t.Sr(o),r.setWitnessArgs(a.position,s),r}},ra=class extends na{constructor(e,r){if(super(e),typeof r==`string`&&r.startsWith(`npub`)){let{words:e}=n.bech32.decode(r);this.publicKey=t.Sr(n.bech32.fromWords(e))}else this.publicKey=t.Sr(r)}async connect(){}async isConnected(){return!0}async getNostrPublicKey(){return this.publicKey}},ia=class extends ra{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,Sr.getPublicKey(i)),this.privateKey=i}async signNostrEvent(e){let n=(await this.getNostrPublicKey()).slice(2),r=wi({...e,pubkey:n}),i=Sr.sign(r,this.privateKey);return{...e,id:t.Sr(r).slice(2),pubkey:n,sig:t.Sr(i).slice(2)}}},aa=e.t({Address:()=>L,Bytes:()=>t.Jr,Cell:()=>t.y,CellAny:()=>t.b,CellDep:()=>t.x,CellDepInfo:()=>t.nt,CellDepVec:()=>t.S,CellInput:()=>t.C,CellInputVec:()=>t.w,CellOutput:()=>t.T,CellOutputVec:()=>t.E,Client:()=>ie,ClientBlock:()=>t.rt,ClientBlockHeader:()=>t.it,ClientBlockUncle:()=>t.at,ClientCache:()=>ne,ClientCacheMemory:()=>re,ClientIndexerSearchKey:()=>t.ot,ClientIndexerSearchKeyFilter:()=>t.st,ClientIndexerSearchKeyTransaction:()=>t.ct,ClientJsonRpc:()=>de,ClientPublicMainnet:()=>fe,ClientPublicTestnet:()=>pe,ClientTransactionResponse:()=>t.lt,Codec:()=>t.qr,CodecBool:()=>t.Sn,CodecByte:()=>t.Cn,CodecByte16:()=>t.wn,CodecByte32:()=>t.Tn,CodecByte4:()=>t.En,CodecByte8:()=>t.Dn,CodecBytes:()=>t.On,CodecRaw:()=>t.kn,CodecUint128:()=>t.An,CodecUint128BE:()=>t.jn,CodecUint128LE:()=>t.Mn,CodecUint16:()=>t.Nn,CodecUint16BE:()=>t.Pn,CodecUint16LE:()=>t.Fn,CodecUint256:()=>t.In,CodecUint256BE:()=>t.Ln,CodecUint256LE:()=>t.Rn,CodecUint32:()=>t.zn,CodecUint32BE:()=>t.Bn,CodecUint32LE:()=>t.Vn,CodecUint512:()=>t.Hn,CodecUint512BE:()=>t.Un,CodecUint512LE:()=>t.Wn,CodecUint64:()=>t.Gn,CodecUint64BE:()=>t.Kn,CodecUint64LE:()=>t.qn,CodecUint8:()=>t.Jn,DepTypeCodec:()=>t.D,Entity:()=>t.fr,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.B,ErrorTransactionInsufficientCoin:()=>t.V,HASH_CKB_LENGTH:()=>32,HASH_CKB_SHORT_LENGTH:()=>20,HashTypeCodec:()=>t.G,HasherCkb:()=>t.gr,HasherKeecak256:()=>A,InputToSign:()=>ut,JsonRpcError:()=>R,JsonRpcTransportFallback:()=>ae,JsonRpcTransportHttp:()=>t.u,JsonRpcTransportWebSocket:()=>t.l,KnownScript:()=>t.tt,MultisigCkbWitness:()=>Q,One:()=>t.cr,OutPoint:()=>t.O,Owner:()=>t.Nt,OwnerAggregated:()=>N,OwnerMoved:()=>t.Pt,OwnerRefCount:()=>P,OwnerUnique:()=>t.Mt,Proxy:()=>F,RawTransaction:()=>t.k,RequestorJsonRpc:()=>ce,SECP256K1_SIGNATURE_LENGTH:()=>65,Script:()=>t.K,ScriptInfo:()=>t._t,ScriptOpt:()=>t.q,ScriptVec:()=>t.J,SignPsbtOptions:()=>lt,Signature:()=>Oi,Signer:()=>Z,SignerAlwaysError:()=>Gi,SignerBtc:()=>Mi,SignerBtcPublicKeyReadonly:()=>Ni,SignerCkbAlwaysSuccess:()=>Pi,SignerCkbPrivateKey:()=>Ii,SignerCkbPublicKey:()=>Fi,SignerCkbScriptReadonly:()=>Li,SignerDoge:()=>Vi,SignerDogeAddressReadonly:()=>Hi,SignerDogePrivateKey:()=>Ui,SignerDummy:()=>Wi,SignerEvm:()=>qi,SignerEvmAddressReadonly:()=>Ji,SignerInfo:()=>ji,SignerJsonRpc:()=>ta,SignerMultisig:()=>ki,SignerMultisigCkbPrivateKey:()=>Bi,SignerMultisigCkbReadonly:()=>zi,SignerMultisigNotEnoughSignaturesError:()=>Ai,SignerNostr:()=>na,SignerNostrPrivateKey:()=>ia,SignerNostrPublicKeyReadonly:()=>ra,SignerOpenLink:()=>Ki,SignerSignType:()=>Ei,SignerType:()=>Di,Since:()=>t.A,Transaction:()=>t.j,WitnessArgs:()=>t.M,Zero:()=>t.lr,abortSignalAny:()=>M,apply:()=>t.Et,btcEcdsaPublicKeyHash:()=>ui,btcP2pkhAddressFromPublicKey:()=>di,btcPublicKeyFromP2pkhAddress:()=>fi,btcVarLengthBytesFrom:()=>ci,buildNostrEventFromMessage:()=>Ci,buildSignerJsonRpcHandler:()=>Xi,bytesConcat:()=>t.Yr,bytesConcatTo:()=>t.Xr,bytesEq:()=>t.Zr,bytesFrom:()=>t.Qr,bytesLen:()=>t.br,bytesLenUnsafe:()=>t.xr,bytesTo:()=>t.$r,calcDaoClaimEpoch:()=>t.N,calcDaoProfit:()=>t.P,codec:()=>t.pr,codecPadding:()=>t.Yn,codecUint:()=>t.Xn,codecUintNumber:()=>t.Zn,depTypeFrom:()=>t.F,depTypeFromBytes:()=>t.I,depTypeToBytes:()=>t.L,epochFrom:()=>t.St,epochFromHex:()=>t.Ct,epochToHex:()=>t.wt,fixedPointFrom:()=>t.ur,fixedPointToString:()=>t.dr,gcd:()=>t.Dt,hashCkb:()=>t._r,hashCkbShort:()=>t.vr,hashTypeFrom:()=>t.Y,hashTypeFromBytes:()=>t.X,hashTypeId:()=>I,hashTypeToBytes:()=>t.Z,hexFrom:()=>t.Sr,isDaoOutputLimitExceeded:()=>t.R,isWebview:()=>t.Ot,keystoreDecrypt:()=>ct,keystoreEncrypt:()=>st,messageHashBtcEcdsa:()=>li,messageHashCkbSecp256k1:()=>_i,messageHashDogeEcdsa:()=>bi,mol:()=>j,nostrEventHash:()=>wi,numBeFromBytes:()=>t.Qn,numBeToBytes:()=>t.$n,numFrom:()=>t.er,numFromBytes:()=>t.tr,numLeFromBytes:()=>t.nr,numLeToBytes:()=>t.rr,numMax:()=>t.ir,numMin:()=>t.ar,numToBytes:()=>t.or,numToHex:()=>t.sr,recoverMessageSecp256k1:()=>gi,reduceAsync:()=>t.kt,signMessageSecp256k1:()=>mi,sleep:()=>t.At,stringify:()=>t.jt,udtBalanceFrom:()=>t.z,verifyMessageBtcEcdsa:()=>pi,verifyMessageCkbSecp256k1:()=>vi,verifyMessageDogeEcdsa:()=>xi,verifyMessageEvmPersonal:()=>Si,verifyMessageJoyId:()=>yi,verifyMessageNostrEvent:()=>Ti,verifyMessageSecp256k1:()=>hi});Object.defineProperty(exports,"$",{enumerable:!0,get:function(){return st}}),Object.defineProperty(exports,"A",{enumerable:!0,get:function(){return Di}}),Object.defineProperty(exports,"B",{enumerable:!0,get:function(){return gi}}),Object.defineProperty(exports,"C",{enumerable:!0,get:function(){return Mi}}),Object.defineProperty(exports,"D",{enumerable:!0,get:function(){return ki}}),Object.defineProperty(exports,"E",{enumerable:!0,get:function(){return ji}}),Object.defineProperty(exports,"F",{enumerable:!0,get:function(){return bi}}),Object.defineProperty(exports,"G",{enumerable:!0,get:function(){return di}}),Object.defineProperty(exports,"H",{enumerable:!0,get:function(){return vi}}),Object.defineProperty(exports,"I",{enumerable:!0,get:function(){return xi}}),Object.defineProperty(exports,"J",{enumerable:!0,get:function(){return li}}),Object.defineProperty(exports,"K",{enumerable:!0,get:function(){return fi}}),Object.defineProperty(exports,"L",{enumerable:!0,get:function(){return yi}}),Object.defineProperty(exports,"M",{enumerable:!0,get:function(){return wi}}),Object.defineProperty(exports,"N",{enumerable:!0,get:function(){return Ti}}),Object.defineProperty(exports,"O",{enumerable:!0,get:function(){return Ai}}),Object.defineProperty(exports,"P",{enumerable:!0,get:function(){return Si}}),Object.defineProperty(exports,"Q",{enumerable:!0,get:function(){return ct}}),Object.defineProperty(exports,"R",{enumerable:!0,get:function(){return 65}}),Object.defineProperty(exports,"S",{enumerable:!0,get:function(){return Ni}}),Object.defineProperty(exports,"T",{enumerable:!0,get:function(){return Z}}),Object.defineProperty(exports,"U",{enumerable:!0,get:function(){return hi}}),Object.defineProperty(exports,"V",{enumerable:!0,get:function(){return mi}}),Object.defineProperty(exports,"W",{enumerable:!0,get:function(){return ui}}),Object.defineProperty(exports,"X",{enumerable:!0,get:function(){return ut}}),Object.defineProperty(exports,"Y",{enumerable:!0,get:function(){return pi}}),Object.defineProperty(exports,"Z",{enumerable:!0,get:function(){return lt}}),Object.defineProperty(exports,"_",{enumerable:!0,get:function(){return zi}}),Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return ta}}),Object.defineProperty(exports,"at",{enumerable:!0,get:function(){return ce}}),Object.defineProperty(exports,"b",{enumerable:!0,get:function(){return Fi}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return qi}}),Object.defineProperty(exports,"ct",{enumerable:!0,get:function(){return re}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return Wi}}),Object.defineProperty(exports,"dt",{enumerable:!0,get:function(){return F}}),Object.defineProperty(exports,"et",{enumerable:!0,get:function(){return R}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return Ui}}),Object.defineProperty(exports,"ft",{enumerable:!0,get:function(){return P}}),Object.defineProperty(exports,"g",{enumerable:!0,get:function(){return Q}}),Object.defineProperty(exports,"gt",{enumerable:!0,get:function(){return A}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return Bi}}),Object.defineProperty(exports,"ht",{enumerable:!0,get:function(){return j}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return na}}),Object.defineProperty(exports,"it",{enumerable:!0,get:function(){return de}}),Object.defineProperty(exports,"j",{enumerable:!0,get:function(){return Ci}}),Object.defineProperty(exports,"k",{enumerable:!0,get:function(){return Ei}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return Ki}}),Object.defineProperty(exports,"lt",{enumerable:!0,get:function(){return ne}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return Vi}}),Object.defineProperty(exports,"mt",{enumerable:!0,get:function(){return M}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return ia}}),Object.defineProperty(exports,"nt",{enumerable:!0,get:function(){return pe}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return Xi}}),Object.defineProperty(exports,"ot",{enumerable:!0,get:function(){return ae}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return Hi}}),Object.defineProperty(exports,"pt",{enumerable:!0,get:function(){return N}}),Object.defineProperty(exports,"q",{enumerable:!0,get:function(){return ci}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return ra}}),Object.defineProperty(exports,"rt",{enumerable:!0,get:function(){return fe}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return Ji}}),Object.defineProperty(exports,"st",{enumerable:!0,get:function(){return ie}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return aa}}),Object.defineProperty(exports,"tt",{enumerable:!0,get:function(){return L}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return Gi}}),Object.defineProperty(exports,"ut",{enumerable:!0,get:function(){return I}}),Object.defineProperty(exports,"v",{enumerable:!0,get:function(){return Li}}),Object.defineProperty(exports,"w",{enumerable:!0,get:function(){return Oi}}),Object.defineProperty(exports,"x",{enumerable:!0,get:function(){return Pi}}),Object.defineProperty(exports,"y",{enumerable:!0,get:function(){return Ii}}),Object.defineProperty(exports,"z",{enumerable:!0,get:function(){return _i}});
|
|
23
|
-
//# sourceMappingURL=barrel-
|
|
23
|
+
//# sourceMappingURL=barrel-BOCFtFjq.js.map
|