@swapkit/wallet-hardware 4.9.8 → 4.9.9

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.
@@ -1,5 +1,5 @@
1
- var P0={};Y0(P0,{ledgerWallet:()=>B0,LEDGER_SUPPORTED_CHAINS:()=>H0});module.exports=Q0(P0);var w=require("@swapkit/helpers"),Y=require("@swapkit/toolboxes/utxo"),WL=require("@swapkit/wallet-core");var J=require("@swapkit/helpers"),v=async({chain:L,ledgerClient:y})=>{if(!y)return"";switch(L){case J.Chain.Cosmos:case J.Chain.THORChain:return y.connect();case J.Chain.Ethereum:case J.Chain.BinanceSmartChain:case J.Chain.Avalanche:case J.Chain.Polygon:case J.Chain.Arbitrum:case J.Chain.Berachain:case J.Chain.Optimism:case J.Chain.Base:case J.Chain.Aurora:case J.Chain.Gnosis:case J.Chain.Monad:case J.Chain.XLayer:return y.getAddress();case J.Chain.Bitcoin:case J.Chain.BitcoinCash:case J.Chain.Dash:case J.Chain.Dogecoin:case J.Chain.Litecoin:case J.Chain.Zcash:{let _=y;await _.connect();let R=await _.getAddress();return L===J.Chain.BitcoinCash?R.replace("bitcoincash:",""):R}case J.Chain.Near:return await y.getAddress();case J.Chain.Ripple:return y.getAddress();case J.Chain.Tron:return y.getAddress();case J.Chain.Sui:return y.connect();default:throw new J.SwapKitError("wallet_chain_not_supported",{chain:L,wallet:J.WalletOption.LEDGER})}};var N=require("@swapkit/helpers");var h=require("@swapkit/helpers");var c=require("@swapkit/helpers");var ML=require("@swapkit/helpers");var n=85,UL=250;var x={GET_ADDR_SECP256K1:4,GET_VERSION:0,INS_PUBLIC_KEY_SECP256K1:1,SIGN_SECP256K1:2},jL={ADD:1,INIT:0,LAST:2},ZL={ONLY_RETRIEVE:0,SHOW_ADDRESS_IN_DEVICE:1},o={JSON:0},g={NoError:36864},AL={1:"U2F: Unknown",2:"U2F: Bad request",3:"U2F: Configuration unsupported",4:"U2F: Device Ineligible",5:"U2F: Timeout",14:"Timeout",25600:"Execution Error",26368:"Wrong Length",26626:"Error deriving keys",27010:"Empty Buffer",27011:"Output buffer too small",27012:"Data is invalid",27013:"Conditions not satisfied",27014:"Transaction rejected",27264:"Bad key handle",27392:"Invalid P1/P2",27904:"Instruction not supported",28160:"App does not seem to be open",28416:"Unknown error",28417:"Sign/verify error",36864:"No errors",36865:"Device is busy"};function k(L){if(L in AL)return AL[L];return`Unknown Status Code: ${L}`}function W0(L){return typeof L==="object"&&L!==null&&!Array.isArray(L)&&!(L instanceof Date)}function z(L){if(L){if(W0(L)){if(Object.hasOwn(L,"statusCode"))return{error_message:k(L.statusCode),return_code:L.statusCode};if(Object.hasOwn(L,"return_code")&&Object.hasOwn(L,"error_message"))return L}return{error_message:L.toString(),return_code:65535}}return{error_message:L.toString(),return_code:65535}}function $L(L){return L.send(85,x.GET_VERSION,0,0).then((y)=>{let _=y.slice(-2),R=_[0]*256+_[1],T=0;if(y.length>=9)T=(y[5]<<24)+(y[6]<<16)+(y[7]<<8)+(y[8]<<0);return{device_locked:y[4]===1,error_message:k(R),major:y[1],minor:y[2],patch:y[3],return_code:R,target_id:T.toString(16),test_mode:y[0]!==0}},z)}var _L=require("@swapkit/helpers");function PL(L){if(L==null||L.length<3)throw new _L.SwapKitError("wallet_ledger_invalid_params",{reason:"Path too short"});if(L.length>10)throw new _L.SwapKitError("wallet_ledger_invalid_params",{reason:"Path too long"});let y=Buffer.alloc(1+4*L.length);y.writeUInt8(L.length,0);for(let _=0;_<L.length;_+=1){let R=L[_]||0;if(_<3)R|=2147483648;y.writeInt32LE(R,1+_*4)}return y}function CL(L,y,_,R,T=o.JSON){return L.transport.send(n,x.SIGN_SECP256K1,y,T,R,[g.NoError,27012,27264]).then((m)=>{let G=m.slice(-2),O=G[0]*256+G[1],B=k(O);if(O===27264||O===27012)B=`${B} : ${m.slice(0,m.length-2).toString("ascii")}`;let W=null;if(m.length>2)W=m.slice(0,m.length-2);return{error_message:B,return_code:O,signature:W}},z)}function D0(L){if(L.length!==65)throw new _L.SwapKitError("wallet_ledger_invalid_params",{reason:"decompressed public key length should be 65 bytes"});let y=L.slice(33,65),_=Buffer.from([2+(y[y.length-1]&1)]);return Buffer.concat([_,L.slice(1,33)])}function SL(L,y){return L.transport.send(n,x.INS_PUBLIC_KEY_SECP256K1,0,0,y,[g.NoError]).then((_)=>{let R=_.slice(-2),T=R[0]*256+R[1],m=Buffer.from(_.slice(0,65));return{compressed_pk:D0(m),error_message:k(T),pk:m,return_code:T}},z)}function zL(L){if(!L||L.length!==5)throw new _L.SwapKitError("wallet_ledger_invalid_params",{reason:"Path must be exactly 5 elements"});let y=Buffer.alloc(20);return y.writeUInt32LE(2147483648+L[0],0),y.writeUInt32LE(2147483648+L[1],4),y.writeUInt32LE(2147483648+L[2],8),y.writeUInt32LE(L[3],12),y.writeUInt32LE(L[4],16),y}function KL(L,y,_,R,T=o.JSON){let m=jL.ADD;if(y===1)m=jL.INIT;if(y===_)m=jL.LAST;return CL(L,m,0,R,T)}function VL(L,y){return L.transport.send(n,x.GET_ADDR_SECP256K1,0,0,y,[g.NoError]).then((_)=>{let R=_.slice(-2),T=R[0]*256+R[1];return{compressed_pk:Buffer.from(_.slice(0,33)),error_message:k(T),pk:"OBSOLETE PROPERTY",return_code:T}},z)}class TL{transport;versionResponse;constructor(L){if(!L)throw new ML.SwapKitError("wallet_ledger_transport_not_defined");this.transport=L}static serializeHRP(L){if(L==null||L.length<3||L.length>83)throw new ML.SwapKitError("wallet_ledger_invalid_params",{reason:"Invalid HRP"});let y=Buffer.alloc(1+L.length);return y.writeUInt8(L.length,0),y.write(L,1),y}async serializePath(L){if(this.versionResponse=await $L(this.transport),this.versionResponse.return_code!==g.NoError)throw this.versionResponse;switch(this.versionResponse.major){case 1:return PL(L);case 2:return zL(L);default:return Buffer.alloc(0)}}async signGetChunks(L,y){let _=await this.serializePath(L),R=[];R.push(_);for(let T=0;T<y.length;T+=UL){let m=T+UL;if(T>y.length)m=y.length;R.push(y.slice(T,m))}return R}async getVersion(){try{return this.versionResponse=await $L(this.transport),this.versionResponse}catch(L){return z(L)}}appInfo(){return this.transport.send(176,1,0,0).then((L)=>{let y=L.readUInt16BE(L.length-2),_="",R="",T=0,m=0;if(L[0]!==1)return{error_message:"response format ID not recognized",return_code:36865};let G=L[1];_=L.slice(2,2+G).toString("ascii");let O=2+G,B=L[O];O+=1,R=L.slice(O,O+B).toString("ascii"),O+=B;let W=L[O];return O+=1,T=W,m=L[O],{appName:_,appVersion:R,error_message:k(y),flag_onboarded:(m&4)!==0,flag_pin_validated:(m&128)!==0,flag_recovery:(m&1)!==0,flag_signed_mcu_code:(m&2)!==0,flagLen:T,flagsValue:m,return_code:y}},z)}deviceInfo(){return this.transport.send(224,1,0,0,Buffer.from([]),[g.NoError,28160]).then((L)=>{let y=L.slice(-2),_=y[0]*256+y[1];if(_===28160)return{error_message:"This command is only available in the Dashboard",return_code:_};let R=L.slice(0,4).toString("hex"),T=4,m=L[T];T+=1;let G=L.slice(T,T+m).toString();T+=m;let O=L[T];T+=1;let B=L.slice(T,T+O).toString("hex");T+=O;let W=L[T];T+=1;let X=L.slice(T,T+W);if(X[W-1]===0)X=L.slice(T,T+W-1);let j=X.toString();return{error_message:k(_),flag:B,mcuVersion:j,return_code:_,seVersion:G,targetId:R}},z)}async publicKey(L){try{let y=await this.serializePath(L);switch(this.versionResponse.major){case 1:return SL(this,y);case 2:{let _=Buffer.concat([TL.serializeHRP("thor"),y]);return VL(this,_)}default:return{error_message:"App Version is not supported",return_code:25600}}}catch(y){return z(y)}}async getAddressAndPubKey(L,y,_=!1){try{let R=await this.serializePath(L),T=Buffer.concat([TL.serializeHRP(y),R]),m=await this.transport.send(n,x.GET_ADDR_SECP256K1,_?ZL.SHOW_ADDRESS_IN_DEVICE:ZL.ONLY_RETRIEVE,0,T,[g.NoError]),G=Buffer.from(m.slice(0,33)),O=Buffer.from(m.slice(33,-2)).toString(),B=m.readUInt16BE(m.length-2);return{bech32_address:O,compressed_pk:G,error_message:k(B),return_code:B}}catch(R){return z(R)}}showAddressAndPubKey(L,y){return this.getAddressAndPubKey(L,y,!0)}signSendChunk(L,y,_,R=o.JSON){switch(this.versionResponse.major){case 1:return CL(this,L,y,_,R);case 2:return KL(this,L,y,_,R);default:return{error_message:"App Version is not supported",return_code:25600}}}async sign(L,y,_=o.JSON){let R=Buffer.from(y),T=[],m;try{T=await this.signGetChunks(L,R),m=await this.signSendChunk(1,T.length,T[0],_)}catch(O){z(O)}let G={error_message:m.error_message,return_code:m.return_code,signature:null};for(let O=1;O<T.length;O+=1)if(G=await this.signSendChunk(1+O,T.length,T[O],_),G.return_code!==g.NoError)break;return{error_message:G.error_message,return_code:G.return_code,signature:G.signature}}}class wL{ledgerTimeout=50000;derivationPath=c.NetworkDerivationPath.GAIA;transport;ledgerApp;chain="thor";injectedTransport;constructor(L){if(this.injectedTransport=L,L)this.transport=L}checkOrCreateTransportAndLedger=async(L=!1)=>{if(!L&&this.transport&&this.ledgerApp)return;try{if(!this.transport||L&&!this.injectedTransport)this.transport=this.injectedTransport??await q();switch(this.chain){case"thor":{this.ledgerApp=L||!this.ledgerApp?new TL(this.transport):this.ledgerApp;break}case"cosmos":{let _=(await import("@ledgerhq/hw-app-cosmos")).default;this.ledgerApp=L||!this.ledgerApp?new _(this.transport):this.ledgerApp}}return this.ledgerApp}catch(y){throw new c.SwapKitError("wallet_ledger_connection_error",y)}};validateResponse=(L,y)=>{switch(L){case c.LedgerErrorCode.NoError:return;case c.LedgerErrorCode.LockedDevice:throw new c.SwapKitError("wallet_ledger_device_locked",{message:`Ledger is locked: ${y}`});case c.LedgerErrorCode.TC_NotFound:throw new c.SwapKitError("wallet_ledger_device_not_found");default:break}}}class QL extends wL{pubKey=null;derivationPath;constructor(L=h.NetworkDerivationPath.GAIA,y){super(y);this.chain="cosmos",this.derivationPath=h.derivationPathToString(L)}connect=async()=>{await this.checkOrCreateTransportAndLedger(!0);let{publicKey:L,address:y}=await this.getAddressAndPubKey();return this.pubKey=Buffer.from(L,"hex").toString("base64"),y};getAddressAndPubKey=async()=>{return await this.checkOrCreateTransportAndLedger(!0),await this.ledgerApp.getAddress(this.derivationPath,this.chain)};signTransaction=async(L,y="0")=>{await this.checkOrCreateTransportAndLedger(!0);let{return_code:_,error_message:R,signature:T}=await this.ledgerApp.sign(this.derivationPath,L);if(!this.pubKey)throw new h.SwapKitError("wallet_ledger_pubkey_not_found");return this.validateResponse(_,R),[{pub_key:{type:"tendermint/PubKeySecp256k1",value:this.pubKey},sequence:y,signature:T}]};signAmino=async(L,y)=>{await this.checkOrCreateTransportAndLedger(!0);let _=await this.getAccounts();if(_.findIndex((Z)=>Z.address===L)===-1)throw new h.SwapKitError("wallet_ledger_address_not_found",{address:L});let T=await import("@cosmjs/amino"),m=T.encodeSecp256k1Signature??T.default?.encodeSecp256k1Signature,G=T.serializeSignDoc??T.default?.serializeSignDoc,O=await import("@cosmjs/crypto"),B=O.Secp256k1Signature??O.default?.Secp256k1Signature,W=G(y),X=await this.ledgerApp.sign(this.derivationPath,W);this.validateResponse(X.return_code,X.error_message);let j=B.fromDer(X.signature).toFixedLength();return{signature:m(_[0].pubkey,j),signed:y}};getAccounts=async()=>{await this.checkOrCreateTransportAndLedger(!0);let L=await this.getAddressAndPubKey();return[{address:L.address,algo:"secp256k1",pubkey:Buffer.from(L.publicKey,"hex")}]}}var $=require("@swapkit/helpers"),kL=require("ethers");class S extends kL.AbstractSigner{chainId=$.ChainId.Ethereum;derivationPath="";ledgerApp=null;ledgerTimeout=50000;injectedTransport;constructor({provider:L,derivationPath:y=$.NetworkDerivationPath.OP,chainId:_=$.ChainId.Optimism,transport:R}){super(L);this.chainId=_||$.ChainId.Ethereum,this.derivationPath=typeof y==="string"?y:$.derivationPathToString(y),this.injectedTransport=R,Object.defineProperty(this,"provider",{enumerable:!0,value:L||null,writable:!1})}connect=(L)=>new S({chainId:this.chainId,derivationPath:this.derivationPath,provider:L,transport:this.injectedTransport});checkOrCreateTransportAndLedger=async()=>{if(this.ledgerApp)return;await this.createTransportAndLedger()};createTransportAndLedger=async()=>{let L=this.injectedTransport??await q(),y=(await import("@ledgerhq/hw-app-eth")).default;this.ledgerApp=new y(L)};getAddress=async()=>{let L=await this.getAddressAndPubKey();if(!L)throw new $.SwapKitError("wallet_ledger_failed_to_get_address");return L.address};getAddressAndPubKey=async()=>{return await this.createTransportAndLedger(),this.ledgerApp?.getAddress(this.derivationPath)};showAddressAndPubKey=async()=>{return await this.createTransportAndLedger(),this.ledgerApp?.getAddress(this.derivationPath,!0)};signMessage=async(L)=>{let{Signature:y}=await import("ethers");await this.createTransportAndLedger();let _=await this.ledgerApp?.signPersonalMessage(this.derivationPath,L);if(!_)throw new $.SwapKitError("wallet_ledger_signing_error");return _.r=`0x${_.r}`,_.s=`0x${_.s}`,y.from(_).serialized};sendTransaction=async(L)=>{if(!this.provider)throw new $.SwapKitError("wallet_ledger_no_provider");let y=await this.signTransaction(L);return await this.provider.broadcastTransaction(y)};signTypedData=async(L,y,_,R)=>{let{buildEIP712DomainType:T}=await import("@swapkit/toolboxes/evm"),{Signature:m,TypedDataEncoder:G}=await import("ethers");await this.createTransportAndLedger();let{EIP712Domain:O,...B}=y,W=R??G.from(B).primaryType,X;try{X=await this.ledgerApp?.signEIP712Message(this.derivationPath,{domain:L,message:_,primaryType:W,types:{EIP712Domain:T(L),...B}})}catch(j){let Z=j instanceof Error&&"statusCode"in j;if(!Z||Z&&j.statusCode===27013)throw j;let Q=G.hashDomain(L).slice(2),H=G.from(B).hash(_).slice(2);X=await this.ledgerApp?.signEIP712HashedMessage(this.derivationPath,Q,H)}if(!X)throw new $.SwapKitError("wallet_ledger_signing_error");return X.r=`0x${X.r}`,X.s=`0x${X.s}`,m.from(X).serialized};signTransaction=async(L)=>{let{Transaction:y}=await import("ethers");await this.createTransportAndLedger();let _=await this.provider?.getTransactionCount(L.from||await this.getAddress()),R={chainId:L.chainId||this.chainId,data:L.data,gasLimit:L.gasLimit,...L.gasPrice&&{gasPrice:L.gasPrice},...!L.gasPrice&&L.maxFeePerGas&&{maxFeePerGas:L.maxFeePerGas,maxPriorityFeePerGas:L.maxPriorityFeePerGas},nonce:L.nonce!==void 0?Number((L.nonce||_||0).toString()):_,to:L.to?.toString(),type:L.type&&!Number.isNaN(L.type)?L.type:L.maxFeePerGas?2:0,value:L.value},T=y.from(R).unsignedSerialized.slice(2),{ledgerService:m}=await import("@ledgerhq/hw-app-eth"),G=await m.resolveTransaction(T,{},{erc20:!0,externalPlugins:!0}),O=await this.ledgerApp?.signTransaction(this.derivationPath,T,G);if(!O)throw new $.SwapKitError("wallet_ledger_signing_error");let{r:B,s:W,v:X}=O;return y.from({...R,signature:{r:`0x${B}`,s:`0x${W}`,v:Number(BigInt(X))}}).serialized}}var cL=(L)=>new S({...L,chainId:$.ChainId.Arbitrum}),IL=(L)=>new S({...L,chainId:$.ChainId.Aurora}),EL=(L)=>new S({...L,chainId:$.ChainId.Avalanche}),vL=(L)=>new S({...L,chainId:$.ChainId.Base}),gL=(L)=>new S({...L,chainId:$.ChainId.Ethereum}),bL=(L)=>new S({...L,chainId:$.ChainId.Gnosis}),lL=(L)=>new S({...L,chainId:$.ChainId.Optimism}),xL=(L)=>new S({...L,chainId:$.ChainId.Polygon}),hL=(L)=>new S({...L,chainId:$.ChainId.BinanceSmartChain}),dL=(L)=>new S({...L,chainId:$.ChainId.Monad}),iL=(L)=>new S({...L,chainId:$.ChainId.XLayer}),uL=(L)=>new S({...L,chainId:$.ChainId.Berachain});async function nL(L,y){let _=(await import("@ledgerhq/hw-app-near")).default,{Chain:R,NetworkDerivationPath:T,SwapKitError:m}=await import("@swapkit/helpers"),G=y??await q(),O=new _(G),B=(L||T[R.Near]).join("'/").concat("'"),{address:W,publicKey:X}=await O.getAddress(B);return{getAddress(){return Promise.resolve(W)},async getPublicKey(){let{PublicKey:Z}=await import("@near-js/crypto");return Z.fromString(`ed25519:${X}`)},signDelegateAction(Z){return Promise.reject(new m("wallet_ledger_method_not_supported",{method:"signDelegateAction",wallet:"Ledger"}))},signNep413Message(Z,Q,H,f,F){return Promise.reject(new m("wallet_ledger_method_not_supported",{method:"signNep413Message",wallet:"Ledger"}))},async signTransaction(Z){let{Signature:Q,SignedTransaction:H}=await import("@near-js/transactions");try{let f=await O.signTransaction(Z.encode(),B);if(!f)throw Error("Signature undefined");let F=new Q({data:f,keyType:0}),C=new H({signature:F,transaction:Z});return[f,C]}catch(f){throw new m("wallet_ledger_signing_error",{error:f})}}}}var A=require("@swapkit/helpers");class oL{derivationPath;ledgerApp=null;address=null;publicKey=null;injectedTransport;constructor(L,y){this.derivationPath=typeof L==="string"?L:A.derivationPathToString(L||A.NetworkDerivationPath[A.Chain.Sui]),this.injectedTransport=y}getLedgerPath(){return this.derivationPath.replace(/^m\//,"").replace(/\/(\d+)\/(\d+)$/,"/$1'/$2'")}async createTransportAndLedger(){if(this.ledgerApp)return;let L=this.injectedTransport??await q(),y=(await import("@ledgerhq/hw-app-sui")).default;this.ledgerApp=new y(L)}async connect(){if(await this.createTransportAndLedger(),!this.ledgerApp)throw new A.SwapKitError("wallet_ledger_transport_error");let L=this.getLedgerPath(),y=await this.ledgerApp.getPublicKey(L);if(!y?.publicKey)throw new A.SwapKitError("wallet_ledger_failed_to_get_address");return this.publicKey=y.publicKey,this.address=`0x${Buffer.from(y.address).toString("hex")}`,this.address}toSuiAddress(){if(!this.address)throw new A.SwapKitError("wallet_ledger_failed_to_get_address");return this.address}async getAddress(){if(this.address)return this.address;return await this.connect()}async signTransaction(L){let y=L instanceof Uint8Array?L:L.transaction;if(await this.createTransportAndLedger(),!this.ledgerApp)throw new A.SwapKitError("wallet_ledger_transport_error");if(!this.publicKey)throw new A.SwapKitError("wallet_ledger_failed_to_get_address");try{let _=this.getLedgerPath(),R=new Uint8Array(3+y.length);R[0]=0,R[1]=0,R[2]=0,R.set(y,3);let T=await this.ledgerApp.signTransaction(_,R);if(!T?.signature)throw new A.SwapKitError("wallet_ledger_signing_error");let m=this.publicKey.length===33?this.publicKey.slice(1):this.publicKey;if(m.length!==32)throw new A.SwapKitError("wallet_ledger_signing_error",{error:"Invalid public key length"});let G=new Uint8Array(97);G[0]=0,G.set(T.signature,1),G.set(m,65);let O=Buffer.from(G).toString("base64");return{bytes:Buffer.from(y).toString("base64"),signature:O}}catch(_){throw new A.SwapKitError("wallet_ledger_signing_error",{error:_})}}}var tL=(L,y)=>new oL(L,y);var aL=require("@scure/base"),mL=require("@swapkit/helpers");var pL=require("@scure/base"),I=require("@swapkit/helpers"),YL=(L)=>{if(L.length<64)throw new I.SwapKitError("wallet_ledger_invalid_signature",{reason:"Too short"});if(L[0]!==48)throw new I.SwapKitError("wallet_ledger_invalid_signature",{reason:"TLV encoding: expected first byte 0x30"});if(L[1]+2!==L.length)throw new I.SwapKitError("wallet_ledger_invalid_signature",{reason:"signature length does not match TLV"});if(L[2]!==2)throw new I.SwapKitError("wallet_ledger_invalid_signature",{reason:"TLV encoding: expected length type 0x02"});let y=L[3],_=L.slice(4,y+4);if(_.length===33&&_[0]===0)_=_.slice(1,33);else if(_.length===33)throw new I.SwapKitError("wallet_ledger_invalid_signature",{reason:"r too long"});while(_.length<32)_.unshift(0);if(L[y+4]!==2)throw new I.SwapKitError("wallet_ledger_invalid_signature",{reason:"TLV encoding: expected length type 0x02 for s"});let R=L[y+5];if(4+y+2+R!==L.length)throw new I.SwapKitError("wallet_ledger_invalid_signature",{reason:"TLV byte lengths do not match message length"});let T=L.slice(y+6,L.length);if(T.length===33&&T[0]===0)T=T.slice(1,33);else if(T.length===33)throw new I.SwapKitError("wallet_ledger_invalid_signature",{reason:"s too long"});while(T.length<32)T.unshift(0);if(_.length!==32||T.length!==32)throw new I.SwapKitError("wallet_ledger_invalid_signature",{reason:"must be 32 bytes each"});return pL.base64.encode(Buffer.concat([_,T]))};class HL extends wL{pubKey=null;derivationPath;constructor(L=mL.NetworkDerivationPath.THOR,y){super(y);this.chain="thor",this.derivationPath=L}get pubkey(){return this.pubKey}connect=async()=>{await this.checkOrCreateTransportAndLedger();let{compressed_pk:L,bech32_address:y}=await this.getAddressAndPubKey();return this.pubKey=aL.base64.encode(L),y};getAddressAndPubKey=async()=>{await this.checkOrCreateTransportAndLedger(!0);let L=await this.ledgerApp.getAddressAndPubKey(this.derivationPath,this.chain);return this.validateResponse(L.return_code,L.error_message),L};showAddressAndPubKey=async()=>{await this.checkOrCreateTransportAndLedger(!0);let L=await this.ledgerApp.showAddressAndPubKey(this.derivationPath,this.chain);return this.validateResponse(L.return_code,L.error_message),L};signTransaction=async(L,y="0")=>{await this.checkOrCreateTransportAndLedger(!0);let{return_code:_,error_message:R,signature:T}=await this.ledgerApp.sign(this.derivationPath,L);if(!this.pubKey)throw new mL.SwapKitError("wallet_ledger_pubkey_not_found");return this.validateResponse(_,R),[{pub_key:{type:"tendermint/PubKeySecp256k1",value:this.pubKey},sequence:y,signature:YL(T)}]};sign=async(L)=>{await this.checkOrCreateTransportAndLedger(!0);let{return_code:y,error_message:_,signature:R}=await this.ledgerApp.sign(this.derivationPath,L);if(!this.pubKey)throw new mL.SwapKitError("wallet_ledger_pubkey_not_found");return this.validateResponse(y,_),YL(R)}}var E=require("@swapkit/helpers");class eL{derivationPath;ledgerApp=null;ledgerTimeout=50000;injectedTransport;constructor(L,y){this.derivationPath=typeof L==="string"?L:E.derivationPathToString(L||E.NetworkDerivationPath.TRON),this.injectedTransport=y}checkOrCreateTransportAndLedger=async()=>{if(this.ledgerApp)return;await this.createTransportAndLedger()};createTransportAndLedger=async()=>{let L=this.injectedTransport??await q(),y=(await import("@ledgerhq/hw-app-trx")).default;this.ledgerApp=new y(L)};getAddress=async()=>{let L=await this.getAddressAndPubKey();if(!L)throw new E.SwapKitError("wallet_ledger_failed_to_get_address");return L.address};getAddressAndPubKey=async()=>{await this.createTransportAndLedger();let L=await this.ledgerApp?.getAddress(this.derivationPath);if(!L)throw new E.SwapKitError("wallet_ledger_failed_to_get_address");return{address:L.address,publicKey:L.publicKey}};showAddressAndPubKey=async()=>{return await this.createTransportAndLedger(),this.ledgerApp?.getAddress(this.derivationPath,!0)};signTransaction=async(L)=>{if(await this.createTransportAndLedger(),!this.ledgerApp)throw new E.SwapKitError("wallet_ledger_transport_error");let y=JSON.stringify(L);try{let _=await this.ledgerApp.signTransaction(this.derivationPath,y,[]);if(!_)throw new E.SwapKitError("wallet_ledger_signing_error");return{...L,signature:[_]}}catch(_){throw new E.SwapKitError("wallet_ledger_signing_error",{error:_})}}}var sL=(L,y)=>new eL(L,y);var RL=require("@scure/base"),b=require("@swapkit/helpers");var L0=["bitcoin-cash","dash","dogecoin","zcash"],rL=({tx:L,inputUtxos:y,btcApp:_,derivationPath:R,chain:T},m)=>{let G=y.map((j)=>{return[_.splitTransaction(j.txHex||"",!L0.includes(T),T==="zcash"),j.index,void 0,void 0]}),O=RL.hex.encode(L.unsignedTx),B=_.splitTransaction(O,!0),W=_.serializeTransactionOutputs(B).toString("hex"),X={additionals:["bech32"],associatedKeysets:G.map(()=>R),inputs:G,outputScriptHex:W,segwit:!0,useTrustedInputForSegwit:!0};return _.createPaymentTransaction({...X,...m})},J0=({tx:L,inputUtxos:y,btcApp:_,derivationPaths:R,chain:T},m)=>{if(R.length!==y.length)throw new b.SwapKitError("wallet_ledger_invalid_params",{message:`Derivation paths count (${R.length}) must match inputs count (${y.length})`});let G=y.map((j)=>{return[_.splitTransaction(j.txHex||"",!L0.includes(T),T==="zcash"),j.index,void 0,void 0]}),O=RL.hex.encode(L.unsignedTx),B=_.splitTransaction(O,!0),W=_.serializeTransactionOutputs(B).toString("hex"),X={additionals:["bech32"],associatedKeysets:R,inputs:G,outputScriptHex:W,segwit:!0,useTrustedInputForSegwit:!0};return _.createPaymentTransaction({...X,...m})},t=({chain:L,additionalSignParams:y})=>{return(_,R)=>{let T,m=null;async function G(X=!0){if(X&&!T)new b.SwapKitError("wallet_ledger_connection_error",{message:`Ledger connection failed:
2
- ${JSON.stringify({btcApp:T,checkBtcApp:X})}`});m||=R??await q()}async function O(){m=R??await q(),T=new(await import("@ledgerhq/hw-app-btc")).default({currency:L,transport:m})}let B=typeof _==="string"?_:b.derivationPathToString(_),W=b.getWalletFormatFor(B);return{connect:async()=>{await G(!1),T=new(await import("@ledgerhq/hw-app-btc")).default({currency:L,transport:m})},getAddress:async()=>{let{toCashAddress:X}=await import("@swapkit/toolboxes/utxo");await G(!1);let{bitcoinAddress:j}=await T.getWalletPublicKey(B,{format:W});if(!j)throw new b.SwapKitError("wallet_ledger_get_address_error",{message:`Cannot get ${L} address from ledger derivation path: ${B}`});return L==="bitcoin-cash"&&W==="legacy"?X(j).replace(/(bchtest:|bitcoincash:)/,""):j},getExtendedPublicKey:async(X="84'/0'/0'",j=76067358)=>{return await G(!1),T.getWalletXpub({path:X,xpubVersion:j})},signPCZT:async(X)=>{if(L!=="zcash")throw new b.SwapKitError("wallet_ledger_chain_not_supported",{message:"PCZT signing is only supported for Zcash"});await O();let{ZcashTransaction:j,Script:Z}=await import("@swapkit/utxo-signer"),Q=X.getGlobal(),H=new j({consensusBranchId:Q.consensusBranchId,expiryHeight:Q.expiryHeight,lockTime:Q.lockTime,version:Q.txVersion,versionGroupId:Q.versionGroupId}),f=[];for(let D=0;D<X.inputsLength;D++){let U=X.getInput(D);H.addInput({index:U.index,script:new Uint8Array,sequence:U.sequence??4294967295,txid:U.txid,value:U.value}),f.push({hash:RL.hex.encode(new Uint8Array([...U.txid].reverse())),index:U.index,txHex:U0(U,Q),value:Number(U.value),witnessUtxo:{script:U.scriptPubkey,value:Number(U.value)}})}for(let D=0;D<X.outputsLength;D++){let U=X.getOutput(D);H.addOutput({amount:U.value,script:U.scriptPubkey})}let F=await rL({btcApp:T,chain:L,derivationPath:B,inputUtxos:f,tx:H},{...y,expiryHeight:(()=>{let D=Buffer.alloc(4);return D.writeUInt32LE(Q.expiryHeight),D})(),lockTime:Q.lockTime}),C=j.fromHex(F,{allowUnknownOutputs:!0}),M=X.clone();for(let D=0;D<C.inputsLength;D++){let U=C.getInput(D);if(U.script&&U.script.length>0){let P=Z.decode(U.script);if(P.length>=2)M.addSignature(D,P[1],P[0])}}return M},signTransaction:async(X,j)=>{return await O(),rL({btcApp:T,chain:L,derivationPath:B,inputUtxos:j,tx:X},y)},signTransactionWithMultiplePaths:async(X,j,Z)=>{return await O(),J0({btcApp:T,chain:L,derivationPaths:Z,inputUtxos:j,tx:X},y)}}}};function U0(L,y){let _=[],R=(y.txVersion|2147483648)>>>0;_.push(R&255,R>>8&255,R>>16&255,R>>24&255);let T=y.versionGroupId;_.push(T&255,T>>8&255,T>>16&255,T>>24&255),_.push(0);let m=L.index+1;if(m<253)_.push(m);else _.push(253,m&255,m>>8&255);for(let B=0;B<L.index;B++)_.push(0,0,0,0,0,0,0,0),_.push(0);let G=L.value;_.push(Number(G&0xffn),Number(G>>8n&0xffn),Number(G>>16n&0xffn),Number(G>>24n&0xffn),Number(G>>32n&0xffn),Number(G>>40n&0xffn),Number(G>>48n&0xffn),Number(G>>56n&0xffn));let O=L.scriptPubkey;if(O.length<253)_.push(O.length);else _.push(253,O.length&255,O.length>>8&255);for(let B of O)_.push(B);return _.push(y.lockTime&255,y.lockTime>>8&255,y.lockTime>>16&255,y.lockTime>>24&255),_.push(y.expiryHeight&255,y.expiryHeight>>8&255,y.expiryHeight>>16&255,y.expiryHeight>>24&255),_.push(0,0,0,0,0,0,0,0),_.push(0),_.push(0),_.push(0),RL.hex.encode(new Uint8Array(_))}var y0=t({chain:"bitcoin"}),_0=t({chain:"litecoin"}),T0=t({additionalSignParams:{additionals:["abc"],segwit:!1,sigHashType:65},chain:"bitcoin-cash"}),w0=t({additionalSignParams:{additionals:[],segwit:!1,useTrustedInputForSegwit:!1},chain:"dogecoin"}),m0=t({additionalSignParams:{additionals:[],segwit:!1,useTrustedInputForSegwit:!1},chain:"dash"}),R0=t({additionalSignParams:{additionals:["zcash","sapling"],expiryHeight:(()=>{let L=Buffer.alloc(4);return L.writeUInt32LE(0),L})(),lockTime:0,segwit:!1,useTrustedInputForSegwit:!1},chain:"zcash"});var O0=Z0(require("@ledgerhq/hw-app-xrp")),p=require("@swapkit/helpers"),fL=require("ripple-binary-codec");var $0=2147483648;function C0(L){let y={};for(let _ in L)if(L[_]!==null&&L[_]!==void 0)y[_]=L[_];return y}function M0(L){return new O0.default(L)}var G0=async(L,y)=>{let _=p.derivationPathToString(L||p.NetworkDerivationPath[p.Chain.Ripple]),R=y??await q(),T=M0(R),{address:m,publicKey:G}=await T.getAddress(_);async function O(B){let{hashes:W}=await import("@swapkit/toolboxes/ripple"),j={...C0(B),Flags:B.Flags||$0,SigningPubKey:G.toUpperCase()},Z=fL.encode(j),Q=await T.signTransaction(_,Z),H=fL.encode({...j,TxnSignature:Q});return{hash:W.hashSignedTx(H),tx_blob:H}}return{getAddress:()=>m,signTransaction:O}};var K=async({chain:L,derivationPath:y,transport:_})=>{let{match:R}=await import("ts-pattern");return R(L).returnType().with(N.Chain.THORChain,()=>Promise.resolve(new HL(y,_))).with(N.Chain.Cosmos,()=>Promise.resolve(new QL(y,_))).with(N.Chain.Bitcoin,()=>Promise.resolve(y0(y,_))).with(N.Chain.BitcoinCash,()=>Promise.resolve(T0(y,_))).with(N.Chain.Dash,()=>Promise.resolve(m0(y,_))).with(N.Chain.Dogecoin,()=>Promise.resolve(w0(y,_))).with(N.Chain.Litecoin,()=>Promise.resolve(_0(y,_))).with(N.Chain.Zcash,()=>Promise.resolve(R0(y,_))).with(N.Chain.Ripple,()=>Promise.resolve(G0(y,_))).with(N.Chain.Tron,()=>Promise.resolve(sL(y,_))).with(N.Chain.Sui,()=>Promise.resolve(tL(y,_))).with(N.Chain.Near,()=>{return Promise.resolve(nL(y,_))}).with(N.Chain.Arbitrum,N.Chain.Aurora,N.Chain.Avalanche,N.Chain.Berachain,N.Chain.BinanceSmartChain,N.Chain.Ethereum,N.Chain.Gnosis,N.Chain.Monad,N.Chain.Optimism,N.Chain.Polygon,N.Chain.Base,N.Chain.XLayer,async()=>{let{getProvider:T}=await import("@swapkit/toolboxes/evm"),m={derivationPath:y,provider:await T(L),transport:_};return R(L).with(N.Chain.BinanceSmartChain,()=>hL(m)).with(N.Chain.Avalanche,()=>EL(m)).with(N.Chain.Arbitrum,()=>cL(m)).with(N.Chain.Berachain,()=>uL(m)).with(N.Chain.Optimism,()=>lL(m)).with(N.Chain.Polygon,()=>xL(m)).with(N.Chain.Base,()=>vL(m)).with(N.Chain.Aurora,()=>IL(m)).with(N.Chain.Gnosis,()=>bL(m)).with(N.Chain.Monad,()=>dL(m)).with(N.Chain.XLayer,()=>iL(m)).otherwise(()=>gL(m))}).otherwise(()=>{throw new N.SwapKitError("wallet_chain_not_supported",{chain:L,wallet:N.WalletOption.LEDGER})})};var B0=WL.createWallet({connect:({addChain:L,supportedChains:y,walletType:_})=>async function(T,m,{transport:G}={}){let[O]=w.filterSupportedChains({chains:T,supportedChains:y,walletType:_});if(!O)return!1;let B=m??w.NetworkDerivationPath[O],W=await A0({chain:O,derivationPath:B,transport:G});return L({...W,chain:O,walletType:w.WalletOption.LEDGER}),!0},directSigningSupport:{[w.Chain.Arbitrum]:!0,[w.Chain.Aurora]:!0,[w.Chain.Avalanche]:!0,[w.Chain.Base]:!0,[w.Chain.Berachain]:!0,[w.Chain.BinanceSmartChain]:!0,[w.Chain.Ethereum]:!0,[w.Chain.Gnosis]:!0,[w.Chain.Monad]:!0,[w.Chain.Bitcoin]:!0,[w.Chain.BitcoinCash]:!0,[w.Chain.Cosmos]:!0,[w.Chain.Dash]:!0,[w.Chain.Dogecoin]:!0,[w.Chain.Litecoin]:!0,[w.Chain.Near]:!0,[w.Chain.Optimism]:!0,[w.Chain.Polygon]:!0,[w.Chain.Ripple]:!0,[w.Chain.Sui]:!0,[w.Chain.Tron]:!0,[w.Chain.XLayer]:!0},name:"connectLedger",supportedChains:[w.Chain.Arbitrum,w.Chain.Aurora,w.Chain.Avalanche,w.Chain.Base,w.Chain.Berachain,w.Chain.BinanceSmartChain,w.Chain.Bitcoin,w.Chain.BitcoinCash,w.Chain.Cosmos,w.Chain.Dash,w.Chain.Dogecoin,w.Chain.Ethereum,w.Chain.Gnosis,w.Chain.Litecoin,w.Chain.Monad,w.Chain.Near,w.Chain.Optimism,w.Chain.Polygon,w.Chain.Ripple,w.Chain.Sui,w.Chain.THORChain,w.Chain.XLayer,w.Chain.Tron,w.Chain.Zcash],walletType:w.WalletOption.LEDGER}),H0=WL.getWalletSupportedChains(B0);function f0(L,y="t"){if(!L?.includes("=:"))return L;let _=L.includes(`:${y}:`)?L.split(`:${y}:`)[0]:L;return _?.substring(0,_.lastIndexOf(":"))}function FL(L){if(Array.isArray(L))return L.forEach((R,T)=>{L[T]=FL(R)}),L;if(typeof L!=="object")return L;let y={},_=Object.keys(L).sort();for(let R of _)y[R]=FL(L[R]);return y}function q0(L){return JSON.stringify(FL(L))}async function A0({chain:L,derivationPath:y,transport:_}){switch(L){case w.Chain.BitcoinCash:case w.Chain.Bitcoin:case w.Chain.Dash:case w.Chain.Dogecoin:case w.Chain.Litecoin:case w.Chain.Zcash:{let j=function(F={}){return X(F)},{getUtxoToolbox:R}=await import("@swapkit/toolboxes/utxo"),T=L,m=await K({chain:L,derivationPath:y,transport:_}),G=await v({chain:L,ledgerClient:m}),O;if(L===w.Chain.Bitcoin||L===w.Chain.Litecoin){let{BitcoinPsbtLedger:F,LitecoinPsbtLedger:C}=await import("../chunk-3gajmdgz.js"),M=L===w.Chain.Bitcoin?F(y,_):C(y,_);O={getAddress:M.getAddress,signTransaction:M.signTransaction}}else if(L===w.Chain.BitcoinCash||L===w.Chain.Dogecoin||L===w.Chain.Dash){let{createLegacyPsbtSigner:F}=await import("../chunk-mrsfcest.js");O=F({address:G,chain:T,legacyClient:m})}let B=O?await R(T,{signer:O}):R(T),W=async(F)=>{let C=F.feeRate||(await B.getFeeRates())[w.FeeOption.Average],M=[w.Chain.Bitcoin].includes(L)?F.memo:f0(F.memo),{tx:D,inputs:U}=await B.createTransaction({...F,feeRate:C,fetchTxHex:!0,memo:M,sender:G}),P=await m.signTransaction(D,U);return await B.broadcastTx(P)};async function X({accountIndex:F}={}){if(!m.getExtendedPublicKey)return;let C=Y.getUTXOAccountPath({accountIndex:F,chain:T,derivationPath:y}),M=w.derivationPathToString(C),D=L===w.Chain.Bitcoin||L===w.Chain.Litecoin?M:M.replace(/^m\//,""),U=await m.getExtendedPublicKey(D);return{accountIndex:Y.getUTXOAccountIndexFromPath(C),path:M,xpub:U}}async function Z({accountIndex:F,index:C,change:M=!1}){try{let D=Y.getUTXOAddressPath({accountIndex:F,chain:T,change:M,derivationPath:y,index:C}),U=await K({chain:T,derivationPath:D,transport:_}),P=await v({chain:T,ledgerClient:U});return{accountIndex:Y.getUTXOAccountIndexFromPath(D),address:P,change:M,index:C,path:w.derivationPathToString(D),pubkey:""}}catch{return}}async function Q({accountIndex:F,count:C,startIndex:M=0,change:D=!1}){return Y.assertDerivationIndex("count",C),Y.assertDerivationIndex("startIndex",M),(await Promise.all(Array.from({length:C},(P,l)=>Z({accountIndex:F,change:D,index:M+l})))).filter((P)=>!!P)}let H=Y.createHDWalletHelpers({chain:T,deriveAddress:Z,getBalance:B.getBalance,getUtxos:(F)=>Y.getUtxoApi(T).getUtxos({address:F,fetchTxHex:!0})});async function f({utxos:F,recipient:C,assetValue:M,memo:D,feeRate:U,feeOptionKey:P,changeAddress:l}){if(!F.length)throw new w.SwapKitError("wallet_ledger_invalid_params",{message:"No UTXOs provided for multi-address transfer"});let qL=U||(await B.getFeeRates())[P||w.FeeOption.Fast],OL=D?Y.compileMemo(D):null,V=[{address:C,value:M.getBaseValue("number")}];if(OL)V.push({script:OL,value:0});let GL=F.map(({hash:i,index:u,value:r,txHex:LL,witnessUtxo:yL})=>({hash:i,index:u,txHex:LL,value:r,witnessUtxo:yL})),{inputs:d,outputs:a}=B.accumulative({chain:T,feeRate:qL,inputs:GL,outputs:V});if(!(d&&a))throw new w.SwapKitError("wallet_ledger_connection_error",{message:"Insufficient balance for multi-address transfer"});let{Transaction:DL}=await import("@swapkit/utxo-signer"),BL=new DL({allowLegacyWitnessUtxo:!0,version:1}),e=l||F[0]?.address||C;Y.addInputsAndOutputs({chain:T,compiledMemo:OL,inputs:d,outputs:a,sender:e,tx:BL});let XL=Y.getUTXOAccountPath({chain:T,derivationPath:y}),JL=d.map((i)=>{let u=F.find((NL)=>NL.hash===i.hash&&NL.index===i.index),r=u?.derivationIndex??0,LL=u?.isChange??!1,yL=[...XL,Number(LL),r];return w.derivationPathToString(yL)});if(!m.signTransactionWithMultiplePaths)throw new w.SwapKitError("wallet_ledger_method_not_supported",{method:"signTransactionWithMultiplePaths"});let s=await m.signTransactionWithMultiplePaths(BL,d,JL);return B.broadcastTx(s)}return{...B,...H,address:G,deriveAddressAtIndex:Z,deriveAddresses:Q,getExtendedPublicKey:j,getExtendedPublicKeyInfo:X,transfer:W,transferFromMultipleAddresses:f}}case w.Chain.Ethereum:case w.Chain.Avalanche:case w.Chain.Arbitrum:case w.Chain.Berachain:case w.Chain.Optimism:case w.Chain.Polygon:case w.Chain.BinanceSmartChain:case w.Chain.Base:case w.Chain.Aurora:case w.Chain.Gnosis:case w.Chain.Monad:case w.Chain.XLayer:{let{getEvmToolboxAsync:R}=await import("@swapkit/toolboxes/evm"),T=await K({chain:L,derivationPath:y,transport:_}),m=await v({chain:L,ledgerClient:T});return{...await R(L,{signer:T}),address:m}}case w.Chain.Cosmos:{let{createSigningStargateClient:R,getMsgSendDenom:T,getCosmosToolbox:m}=await import("@swapkit/toolboxes/cosmos"),G=await K({chain:L,derivationPath:y,transport:_}),O=await v({chain:L,ledgerClient:G});return{...await m(w.Chain.Cosmos,{signer:G}),address:O,transfer:async({assetValue:X,recipient:j,memo:Z})=>{if(!X)throw new w.SwapKitError("wallet_ledger_invalid_asset");let Q={amount:[{amount:X.getBaseValue("string"),denom:T(`u${X.symbol}`).toLowerCase()}],fromAddress:O,toAddress:j},H=await w.getRPCUrl(L),f=await R(H,G,"0.007uatom"),{transactionHash:F}=await f.signAndBroadcast(O,[{typeUrl:"/cosmos.bank.v1beta1.MsgSend",value:Q}],2,Z);return F}}}case w.Chain.THORChain:{let{SignMode:R}=await import("cosmjs-types/cosmos/tx/signing/v1beta1/signing.js"),{TxRaw:T}=await import("cosmjs-types/cosmos/tx/v1beta1/tx.js"),m=await import("@cosmjs/proto-signing"),G=m.encodePubkey??m.default?.encodePubkey,O=m.makeAuthInfoBytes??m.default?.makeAuthInfoBytes,{createStargateClient:B,buildEncodedTxBody:W,getCosmosToolbox:X,buildAminoMsg:j,getDefaultChainFee:Z,fromBase64:Q,parseAminoMessageForDirectSigning:H}=await import("@swapkit/toolboxes/cosmos"),f=X(L),F=await K({chain:L,derivationPath:y,transport:_}),C=await v({chain:L,ledgerClient:F}),M=Z(L),{pubkey:D,signTransaction:U,sign:P}=F,l=async({memo:V="",assetValue:GL,...d})=>{let a=await f.getAccount(C);if(!a)throw new w.SwapKitError("wallet_ledger_invalid_account");if(!GL)throw new w.SwapKitError("wallet_ledger_invalid_asset");if(!D)throw new w.SwapKitError("wallet_ledger_pubkey_not_found");let{accountNumber:DL,sequence:BL}=a,e=(BL||0).toString(),XL=FL([j({assetValue:GL,memo:V,sender:C,...d})]),JL=q0({account_number:DL?.toString(),chain_id:w.THORConfig.chainId,fee:M,memo:V,msgs:XL,sequence:e}),s=await U(JL,e);if(!s)throw new w.SwapKitError("wallet_ledger_signing_error");let i=G({type:"tendermint/PubKeySecp256k1",value:D}),u=XL.map(H),r=await W({chain:L,memo:V,msgs:u}),LL=O([{pubkey:i,sequence:Number(e)}],M.amount,Number.parseInt(M.gas,10),void 0,void 0,R.SIGN_MODE_LEGACY_AMINO_JSON),yL=s?.[0]?.signature?Q(s[0].signature):Uint8Array.from([]),NL=T.fromPartial({authInfoBytes:LL,bodyBytes:r,signatures:[yL]}),X0=T.encode(NL).finish(),N0=await w.getRPCUrl(w.Chain.THORChain),j0=await B(N0),{transactionHash:F0}=await j0.broadcastTx(X0);return F0};return{...f,address:C,deposit:(V)=>l(V),signMessage:P,transfer:(V)=>l(V)}}case w.Chain.Near:{let{getNearToolbox:R}=await import("@swapkit/toolboxes/near"),T=await K({chain:L,derivationPath:y,transport:_}),m=await T.getAddress();return{...R({signer:T}),address:m}}case w.Chain.Ripple:{let{getRippleToolbox:R}=await import("@swapkit/toolboxes/ripple"),T=await K({chain:L,derivationPath:y,transport:_}),m=T.getAddress();return{...R({signer:T}),address:m}}case w.Chain.Tron:{let{getTronToolbox:R}=await import("@swapkit/toolboxes/tron"),T=await K({chain:L,derivationPath:y,transport:_}),m=await v({chain:L,ledgerClient:T});return{...R({signer:T}),address:m}}case w.Chain.Sui:{let{getSuiToolbox:R}=await import("@swapkit/toolboxes/sui"),T=await K({chain:L,derivationPath:y,transport:_}),m=await v({chain:L,ledgerClient:T});return{...R({signer:T}),address:m}}default:throw new w.SwapKitError("wallet_ledger_chain_not_supported",{chain:L})}}
1
+ var Uy={};wy(Uy,{ledgerWallet:()=>Ly,LEDGER_SUPPORTED_CHAINS:()=>Wy});module.exports=My(Uy);var R=require("@swapkit/helpers"),H=require("@swapkit/toolboxes/utxo"),B0=require("@swapkit/wallet-core");var Q=require("@swapkit/helpers"),v=async({chain:y,ledgerClient:L})=>{if(!L)return"";switch(y){case Q.Chain.Cosmos:case Q.Chain.THORChain:return L.connect();case Q.Chain.Ethereum:case Q.Chain.BinanceSmartChain:case Q.Chain.Avalanche:case Q.Chain.Polygon:case Q.Chain.Arbitrum:case Q.Chain.Berachain:case Q.Chain.Optimism:case Q.Chain.Base:case Q.Chain.Aurora:case Q.Chain.Gnosis:case Q.Chain.Monad:case Q.Chain.XLayer:return L.getAddress();case Q.Chain.Bitcoin:case Q.Chain.BitcoinCash:case Q.Chain.Dash:case Q.Chain.Dogecoin:case Q.Chain.Litecoin:case Q.Chain.Zcash:{let _=L;await _.connect();let T=await _.getAddress();return y===Q.Chain.BitcoinCash?T.replace("bitcoincash:",""):T}case Q.Chain.Near:return await L.getAddress();case Q.Chain.Ripple:return L.getAddress();case Q.Chain.Tron:return L.getAddress();case Q.Chain.Sui:return L.connect();default:throw new Q.SwapKitError("wallet_chain_not_supported",{chain:y,wallet:Q.WalletOption.LEDGER})}};var J=require("@swapkit/helpers");var x=require("@swapkit/helpers");var P=require("@swapkit/helpers");var O0=require("@swapkit/helpers");var c=85,X0=250;var l={GET_ADDR_SECP256K1:4,GET_VERSION:0,INS_PUBLIC_KEY_SECP256K1:1,SIGN_SECP256K1:2},y0={ADD:1,INIT:0,LAST:2},j0={ONLY_RETRIEVE:0,SHOW_ADDRESS_IN_DEVICE:1},u={JSON:0},C={NoError:36864},q0={1:"U2F: Unknown",2:"U2F: Bad request",3:"U2F: Configuration unsupported",4:"U2F: Device Ineligible",5:"U2F: Timeout",14:"Timeout",25600:"Execution Error",26368:"Wrong Length",26626:"Error deriving keys",27010:"Empty Buffer",27011:"Output buffer too small",27012:"Data is invalid",27013:"Conditions not satisfied",27014:"Transaction rejected",27264:"Bad key handle",27392:"Invalid P1/P2",27904:"Instruction not supported",28160:"App does not seem to be open",28416:"Unknown error",28417:"Sign/verify error",36864:"No errors",36865:"Device is busy"};function E(y){if(y in q0)return q0[y];return`Unknown Status Code: ${y}`}function jy(y){return typeof y==="object"&&y!==null&&!Array.isArray(y)&&!(y instanceof Date)}function V(y){if(y){if(jy(y)){if(Object.hasOwn(y,"statusCode"))return{error_message:E(y.statusCode),return_code:y.statusCode};if(Object.hasOwn(y,"return_code")&&Object.hasOwn(y,"error_message"))return y}return{error_message:y.toString(),return_code:65535}}return{error_message:y.toString(),return_code:65535}}function F0(y){return y.send(85,l.GET_VERSION,0,0).then((L)=>{let _=L.slice(-2),T=_[0]*256+_[1],B=0;if(L.length>=9)B=(L[5]<<24)+(L[6]<<16)+(L[7]<<8)+(L[8]<<0);return{device_locked:L[4]===1,error_message:E(T),major:L[1],minor:L[2],patch:L[3],return_code:T,target_id:B.toString(16),test_mode:L[0]!==0}},V)}var p=require("@swapkit/helpers");function D0(y){if(y==null||y.length<3)throw new p.SwapKitError("wallet_ledger_invalid_params",{reason:"Path too short"});if(y.length>10)throw new p.SwapKitError("wallet_ledger_invalid_params",{reason:"Path too long"});let L=Buffer.alloc(1+4*y.length);L.writeUInt8(y.length,0);for(let _=0;_<y.length;_+=1){let T=y[_]||0;if(_<3)T|=2147483648;L.writeInt32LE(T,1+_*4)}return L}function J0(y,L,_,T,B=u.JSON){return y.transport.send(c,l.SIGN_SECP256K1,L,B,T,[C.NoError,27012,27264]).then((G)=>{let X=G.slice(-2),N=X[0]*256+X[1],j=E(N);if(N===27264||N===27012)j=`${j} : ${G.slice(0,G.length-2).toString("ascii")}`;let Z=null;if(G.length>2)Z=G.slice(0,G.length-2);return{error_message:j,return_code:N,signature:Z}},V)}function Fy(y){if(y.length!==65)throw new p.SwapKitError("wallet_ledger_invalid_params",{reason:"decompressed public key length should be 65 bytes"});let L=y.slice(33,65),_=Buffer.from([2+(L[L.length-1]&1)]);return Buffer.concat([_,y.slice(1,33)])}function U0(y,L){return y.transport.send(c,l.INS_PUBLIC_KEY_SECP256K1,0,0,L,[C.NoError]).then((_)=>{let T=_.slice(-2),B=T[0]*256+T[1],G=Buffer.from(_.slice(0,65));return{compressed_pk:Fy(G),error_message:E(B),pk:G,return_code:B}},V)}function H0(y){if(!y||y.length!==5)throw new p.SwapKitError("wallet_ledger_invalid_params",{reason:"Path must be exactly 5 elements"});let L=Buffer.alloc(20);return L.writeUInt32LE(2147483648+y[0],0),L.writeUInt32LE(2147483648+y[1],4),L.writeUInt32LE(2147483648+y[2],8),L.writeUInt32LE(y[3],12),L.writeUInt32LE(y[4],16),L}function f0(y,L,_,T,B=u.JSON){let G=y0.ADD;if(L===1)G=y0.INIT;if(L===_)G=y0.LAST;return J0(y,G,0,T,B)}function z0(y,L){return y.transport.send(c,l.GET_ADDR_SECP256K1,0,0,L,[C.NoError]).then((_)=>{let T=_.slice(-2),B=T[0]*256+T[1];return{compressed_pk:Buffer.from(_.slice(0,33)),error_message:E(B),pk:"OBSOLETE PROPERTY",return_code:B}},V)}class i{transport;versionResponse;constructor(y){if(!y)throw new O0.SwapKitError("wallet_ledger_transport_not_defined");this.transport=y}static serializeHRP(y){if(y==null||y.length<3||y.length>83)throw new O0.SwapKitError("wallet_ledger_invalid_params",{reason:"Invalid HRP"});let L=Buffer.alloc(1+y.length);return L.writeUInt8(y.length,0),L.write(y,1),L}async serializePath(y){if(this.versionResponse=await F0(this.transport),this.versionResponse.return_code!==C.NoError)throw this.versionResponse;switch(this.versionResponse.major){case 1:return D0(y);case 2:return H0(y);default:return Buffer.alloc(0)}}async signGetChunks(y,L){let _=await this.serializePath(y),T=[];T.push(_);for(let B=0;B<L.length;B+=X0){let G=B+X0;if(B>L.length)G=L.length;T.push(L.slice(B,G))}return T}async getVersion(){try{return this.versionResponse=await F0(this.transport),this.versionResponse}catch(y){return V(y)}}appInfo(){return this.transport.send(176,1,0,0).then((y)=>{let L=y.readUInt16BE(y.length-2),_="",T="",B=0,G=0;if(y[0]!==1)return{error_message:"response format ID not recognized",return_code:36865};let X=y[1];_=y.slice(2,2+X).toString("ascii");let N=2+X,j=y[N];N+=1,T=y.slice(N,N+j).toString("ascii"),N+=j;let Z=y[N];return N+=1,B=Z,G=y[N],{appName:_,appVersion:T,error_message:E(L),flag_onboarded:(G&4)!==0,flag_pin_validated:(G&128)!==0,flag_recovery:(G&1)!==0,flag_signed_mcu_code:(G&2)!==0,flagLen:B,flagsValue:G,return_code:L}},V)}deviceInfo(){return this.transport.send(224,1,0,0,Buffer.from([]),[C.NoError,28160]).then((y)=>{let L=y.slice(-2),_=L[0]*256+L[1];if(_===28160)return{error_message:"This command is only available in the Dashboard",return_code:_};let T=y.slice(0,4).toString("hex"),B=4,G=y[B];B+=1;let X=y.slice(B,B+G).toString();B+=G;let N=y[B];B+=1;let j=y.slice(B,B+N).toString("hex");B+=N;let Z=y[B];B+=1;let F=y.slice(B,B+Z);if(F[Z-1]===0)F=y.slice(B,B+Z-1);let O=F.toString();return{error_message:E(_),flag:j,mcuVersion:O,return_code:_,seVersion:X,targetId:T}},V)}async publicKey(y){try{let L=await this.serializePath(y);switch(this.versionResponse.major){case 1:return U0(this,L);case 2:{let _=Buffer.concat([i.serializeHRP("thor"),L]);return z0(this,_)}default:return{error_message:"App Version is not supported",return_code:25600}}}catch(L){return V(L)}}async getAddressAndPubKey(y,L,_=!1){try{let T=await this.serializePath(y),B=Buffer.concat([i.serializeHRP(L),T]),G=await this.transport.send(c,l.GET_ADDR_SECP256K1,_?j0.SHOW_ADDRESS_IN_DEVICE:j0.ONLY_RETRIEVE,0,B,[C.NoError]),X=Buffer.from(G.slice(0,33)),N=Buffer.from(G.slice(33,-2)).toString(),j=G.readUInt16BE(G.length-2);return{bech32_address:N,compressed_pk:X,error_message:E(j),return_code:j}}catch(T){return V(T)}}showAddressAndPubKey(y,L){return this.getAddressAndPubKey(y,L,!0)}signSendChunk(y,L,_,T=u.JSON){switch(this.versionResponse.major){case 1:return J0(this,y,L,_,T);case 2:return f0(this,y,L,_,T);default:return{error_message:"App Version is not supported",return_code:25600}}}async sign(y,L,_=u.JSON){let T=Buffer.from(L),B=[],G;try{B=await this.signGetChunks(y,T),G=await this.signSendChunk(1,B.length,B[0],_)}catch(N){V(N)}let X={error_message:G.error_message,return_code:G.return_code,signature:null};for(let N=1;N<B.length;N+=1)if(X=await this.signSendChunk(1+N,B.length,B[N],_),X.return_code!==C.NoError)break;return{error_message:X.error_message,return_code:X.return_code,signature:X.signature}}}class n{ledgerTimeout=50000;derivationPath=P.NetworkDerivationPath.GAIA;transport;ledgerApp;chain="thor";injectedTransport;constructor(y){if(this.injectedTransport=y,y)this.transport=y}checkOrCreateTransportAndLedger=async(y=!1)=>{if(!y&&this.transport&&this.ledgerApp)return;try{if(!this.transport||y&&!this.injectedTransport)this.transport=this.injectedTransport??await f();switch(this.chain){case"thor":{this.ledgerApp=y||!this.ledgerApp?new i(this.transport):this.ledgerApp;break}case"cosmos":{let _=(await import("@ledgerhq/hw-app-cosmos")).default;this.ledgerApp=y||!this.ledgerApp?new _(this.transport):this.ledgerApp}}return this.ledgerApp}catch(L){throw new P.SwapKitError("wallet_ledger_connection_error",L)}};validateResponse=(y,L)=>{switch(y){case P.LedgerErrorCode.NoError:return;case P.LedgerErrorCode.LockedDevice:throw new P.SwapKitError("wallet_ledger_device_locked",{message:`Ledger is locked: ${L}`});case P.LedgerErrorCode.TC_NotFound:throw new P.SwapKitError("wallet_ledger_device_not_found");default:break}}}class Z0 extends n{pubKey=null;derivationPath;constructor(y=x.NetworkDerivationPath.GAIA,L){super(L);this.chain="cosmos",this.derivationPath=x.derivationPathToString(y)}connect=async()=>{await this.checkOrCreateTransportAndLedger(!0);let{publicKey:y,address:L}=await this.getAddressAndPubKey();return this.pubKey=Buffer.from(y,"hex").toString("base64"),L};getAddressAndPubKey=async()=>{return await this.checkOrCreateTransportAndLedger(!0),await this.ledgerApp.getAddress(this.derivationPath,this.chain)};signTransaction=async(y,L="0")=>{await this.checkOrCreateTransportAndLedger(!0);let{return_code:_,error_message:T,signature:B}=await this.ledgerApp.sign(this.derivationPath,y);if(!this.pubKey)throw new x.SwapKitError("wallet_ledger_pubkey_not_found");return this.validateResponse(_,T),[{pub_key:{type:"tendermint/PubKeySecp256k1",value:this.pubKey},sequence:L,signature:B}]};signAmino=async(y,L)=>{await this.checkOrCreateTransportAndLedger(!0);let _=await this.getAccounts();if(_.findIndex((W)=>W.address===y)===-1)throw new x.SwapKitError("wallet_ledger_address_not_found",{address:y});let B=await import("@cosmjs/amino"),G=B.encodeSecp256k1Signature??B.default?.encodeSecp256k1Signature,X=B.serializeSignDoc??B.default?.serializeSignDoc,N=await import("@cosmjs/crypto"),j=N.Secp256k1Signature??N.default?.Secp256k1Signature,Z=X(L),F=await this.ledgerApp.sign(this.derivationPath,Z);this.validateResponse(F.return_code,F.error_message);let O=j.fromDer(F.signature).toFixedLength();return{signature:G(_[0].pubkey,O),signed:L}};getAccounts=async()=>{await this.checkOrCreateTransportAndLedger(!0);let y=await this.getAddressAndPubKey();return[{address:y.address,algo:"secp256k1",pubkey:Buffer.from(y.publicKey,"hex")}]}}var w=require("@swapkit/helpers"),m0=require("ethers");class A extends m0.AbstractSigner{chainId=w.ChainId.Ethereum;derivationPath="";ledgerApp=null;ledgerTimeout=50000;injectedTransport;constructor({provider:y,derivationPath:L=w.NetworkDerivationPath.OP,chainId:_=w.ChainId.Optimism,transport:T}){super(y);this.chainId=_||w.ChainId.Ethereum,this.derivationPath=typeof L==="string"?L:w.derivationPathToString(L),this.injectedTransport=T,Object.defineProperty(this,"provider",{enumerable:!0,value:y||null,writable:!1})}connect=(y)=>new A({chainId:this.chainId,derivationPath:this.derivationPath,provider:y,transport:this.injectedTransport});checkOrCreateTransportAndLedger=async()=>{if(this.ledgerApp)return;await this.createTransportAndLedger()};createTransportAndLedger=async()=>{let y=this.injectedTransport??await f(),L=(await import("@ledgerhq/hw-app-eth")).default;this.ledgerApp=new L(y)};getAddress=async()=>{let y=await this.getAddressAndPubKey();if(!y)throw new w.SwapKitError("wallet_ledger_failed_to_get_address");return y.address};getAddressAndPubKey=async()=>{return await this.createTransportAndLedger(),this.ledgerApp?.getAddress(this.derivationPath)};showAddressAndPubKey=async()=>{return await this.createTransportAndLedger(),this.ledgerApp?.getAddress(this.derivationPath,!0)};signMessage=async(y)=>{let{Signature:L}=await import("ethers");await this.createTransportAndLedger();let _=await this.ledgerApp?.signPersonalMessage(this.derivationPath,y);if(!_)throw new w.SwapKitError("wallet_ledger_signing_error");return _.r=`0x${_.r}`,_.s=`0x${_.s}`,L.from(_).serialized};sendTransaction=async(y)=>{if(!this.provider)throw new w.SwapKitError("wallet_ledger_no_provider");let L=await this.signTransaction(y);return await this.provider.broadcastTransaction(L)};signTypedData=async(y,L,_,T)=>{let{buildEIP712DomainType:B}=await import("@swapkit/toolboxes/evm"),{Signature:G,TypedDataEncoder:X}=await import("ethers");await this.createTransportAndLedger();let{EIP712Domain:N,...j}=L,Z=T??X.from(j).primaryType,F;try{F=await this.ledgerApp?.signEIP712Message(this.derivationPath,{domain:y,message:_,primaryType:Z,types:{EIP712Domain:B(y),...j}})}catch(O){let W=O instanceof Error&&"statusCode"in O;if(!W||W&&O.statusCode===27013)throw O;let D=X.hashDomain(y).slice(2),z=X.from(j).hash(_).slice(2);F=await this.ledgerApp?.signEIP712HashedMessage(this.derivationPath,D,z)}if(!F)throw new w.SwapKitError("wallet_ledger_signing_error");return F.r=`0x${F.r}`,F.s=`0x${F.s}`,G.from(F).serialized};signTransaction=async(y)=>{let{Transaction:L}=await import("ethers");await this.createTransportAndLedger();let _=await this.provider?.getTransactionCount(y.from||await this.getAddress()),T={chainId:y.chainId||this.chainId,data:y.data,gasLimit:y.gasLimit,...y.gasPrice&&{gasPrice:y.gasPrice},...!y.gasPrice&&y.maxFeePerGas&&{maxFeePerGas:y.maxFeePerGas,maxPriorityFeePerGas:y.maxPriorityFeePerGas},nonce:y.nonce!==void 0?Number((y.nonce||_||0).toString()):_,to:y.to?.toString(),type:y.type&&!Number.isNaN(y.type)?y.type:y.maxFeePerGas?2:0,value:y.value},B=L.from(T).unsignedSerialized.slice(2),{ledgerService:G}=await import("@ledgerhq/hw-app-eth"),X=await G.resolveTransaction(B,{},{erc20:!0,externalPlugins:!0}),N=await this.ledgerApp?.signTransaction(this.derivationPath,B,X);if(!N)throw new w.SwapKitError("wallet_ledger_signing_error");let{r:j,s:Z,v:F}=N;return L.from({...T,signature:{r:`0x${j}`,s:`0x${Z}`,v:Number(BigInt(F))}}).serialized}}var S0=(y)=>new A({...y,chainId:w.ChainId.Arbitrum}),A0=(y)=>new A({...y,chainId:w.ChainId.Aurora}),K0=(y)=>new A({...y,chainId:w.ChainId.Avalanche}),V0=(y)=>new A({...y,chainId:w.ChainId.Base}),k0=(y)=>new A({...y,chainId:w.ChainId.Ethereum}),E0=(y)=>new A({...y,chainId:w.ChainId.Gnosis}),P0=(y)=>new A({...y,chainId:w.ChainId.Optimism}),I0=(y)=>new A({...y,chainId:w.ChainId.Polygon}),b0=(y)=>new A({...y,chainId:w.ChainId.BinanceSmartChain}),v0=(y)=>new A({...y,chainId:w.ChainId.Monad}),C0=(y)=>new A({...y,chainId:w.ChainId.XLayer}),g0=(y)=>new A({...y,chainId:w.ChainId.Berachain});async function l0(y,L){let _=(await import("@ledgerhq/hw-app-near")).default,{Chain:T,NetworkDerivationPath:B,SwapKitError:G}=await import("@swapkit/helpers"),X=L??await f(),N=new _(X),j=(y||B[T.Near]).join("'/").concat("'"),{address:Z,publicKey:F}=await N.getAddress(j);return{getAddress(){return Promise.resolve(Z)},async getPublicKey(){let{PublicKey:W}=await import("@near-js/crypto");return W.fromString(`ed25519:${F}`)},signDelegateAction(W){return Promise.reject(new G("wallet_ledger_method_not_supported",{method:"signDelegateAction",wallet:"Ledger"}))},signNep413Message(W,D,z,S,$){return Promise.reject(new G("wallet_ledger_method_not_supported",{method:"signNep413Message",wallet:"Ledger"}))},async signTransaction(W){let{Signature:D,SignedTransaction:z}=await import("@near-js/transactions");try{let S=await N.signTransaction(W.encode(),j);if(!S)throw Error("Signature undefined");let $=new D({data:S,keyType:0}),q=new z({signature:$,transaction:W});return[S,q]}catch(S){throw new G("wallet_ledger_signing_error",{error:S})}}}}var m=require("@swapkit/helpers");class x0{derivationPath;ledgerApp=null;address=null;publicKey=null;injectedTransport;constructor(y,L){this.derivationPath=typeof y==="string"?y:m.derivationPathToString(y||m.NetworkDerivationPath[m.Chain.Sui]),this.injectedTransport=L}getLedgerPath(){return this.derivationPath.replace(/^m\//,"").replace(/\/(\d+)\/(\d+)$/,"/$1'/$2'")}async createTransportAndLedger(){if(this.ledgerApp)return;let y=this.injectedTransport??await f(),L=(await import("@ledgerhq/hw-app-sui")).default;this.ledgerApp=new L(y)}async connect(){if(await this.createTransportAndLedger(),!this.ledgerApp)throw new m.SwapKitError("wallet_ledger_transport_error");let y=this.getLedgerPath(),L=await this.ledgerApp.getPublicKey(y);if(!L?.publicKey)throw new m.SwapKitError("wallet_ledger_failed_to_get_address");return this.publicKey=L.publicKey,this.address=`0x${Buffer.from(L.address).toString("hex")}`,this.address}toSuiAddress(){if(!this.address)throw new m.SwapKitError("wallet_ledger_failed_to_get_address");return this.address}async getAddress(){if(this.address)return this.address;return await this.connect()}async signTransaction(y){let L=y instanceof Uint8Array?y:y.transaction;if(await this.createTransportAndLedger(),!this.ledgerApp)throw new m.SwapKitError("wallet_ledger_transport_error");if(!this.publicKey)throw new m.SwapKitError("wallet_ledger_failed_to_get_address");try{let _=this.getLedgerPath(),T=new Uint8Array(3+L.length);T[0]=0,T[1]=0,T[2]=0,T.set(L,3);let B=await this.ledgerApp.signTransaction(_,T);if(!B?.signature)throw new m.SwapKitError("wallet_ledger_signing_error");let G=this.publicKey.length===33?this.publicKey.slice(1):this.publicKey;if(G.length!==32)throw new m.SwapKitError("wallet_ledger_signing_error",{error:"Invalid public key length"});let X=new Uint8Array(97);X[0]=0,X.set(B.signature,1),X.set(G,65);let N=Buffer.from(X).toString("base64");return{bytes:Buffer.from(L).toString("base64"),signature:N}}catch(_){throw new m.SwapKitError("wallet_ledger_signing_error",{error:_})}}}var c0=(y,L)=>new x0(y,L);var _0=require("@scure/base"),d=require("@swapkit/helpers");var u0=require("@scure/base"),I=require("@swapkit/helpers"),L0=(y)=>{if(y.length<64)throw new I.SwapKitError("wallet_ledger_invalid_signature",{reason:"Too short"});if(y[0]!==48)throw new I.SwapKitError("wallet_ledger_invalid_signature",{reason:"TLV encoding: expected first byte 0x30"});if(y[1]+2!==y.length)throw new I.SwapKitError("wallet_ledger_invalid_signature",{reason:"signature length does not match TLV"});if(y[2]!==2)throw new I.SwapKitError("wallet_ledger_invalid_signature",{reason:"TLV encoding: expected length type 0x02"});let L=y[3],_=y.slice(4,L+4);if(_.length===33&&_[0]===0)_=_.slice(1,33);else if(_.length===33)throw new I.SwapKitError("wallet_ledger_invalid_signature",{reason:"r too long"});while(_.length<32)_.unshift(0);if(y[L+4]!==2)throw new I.SwapKitError("wallet_ledger_invalid_signature",{reason:"TLV encoding: expected length type 0x02 for s"});let T=y[L+5];if(4+L+2+T!==y.length)throw new I.SwapKitError("wallet_ledger_invalid_signature",{reason:"TLV byte lengths do not match message length"});let B=y.slice(L+6,y.length);if(B.length===33&&B[0]===0)B=B.slice(1,33);else if(B.length===33)throw new I.SwapKitError("wallet_ledger_invalid_signature",{reason:"s too long"});while(B.length<32)B.unshift(0);if(_.length!==32||B.length!==32)throw new I.SwapKitError("wallet_ledger_invalid_signature",{reason:"must be 32 bytes each"});return u0.base64.encode(Buffer.concat([_,B]))};class $0 extends n{pubKey=null;derivationPath;constructor(y=d.NetworkDerivationPath.THOR,L){super(L);this.chain="thor",this.derivationPath=y}get pubkey(){return this.pubKey}connect=async()=>{await this.checkOrCreateTransportAndLedger();let{compressed_pk:y,bech32_address:L}=await this.getAddressAndPubKey();return this.pubKey=_0.base64.encode(y),L};getAddressAndPubKey=async()=>{await this.checkOrCreateTransportAndLedger(!0);let y=await this.ledgerApp.getAddressAndPubKey(this.derivationPath,this.chain);return this.validateResponse(y.return_code,y.error_message),y};showAddressAndPubKey=async()=>{await this.checkOrCreateTransportAndLedger(!0);let y=await this.ledgerApp.showAddressAndPubKey(this.derivationPath,this.chain);return this.validateResponse(y.return_code,y.error_message),y};signTransaction=async(y,L="0")=>{await this.checkOrCreateTransportAndLedger(!0);let{return_code:_,error_message:T,signature:B}=await this.ledgerApp.sign(this.derivationPath,y);if(!this.pubKey)throw new d.SwapKitError("wallet_ledger_pubkey_not_found");return this.validateResponse(_,T),[{pub_key:{type:"tendermint/PubKeySecp256k1",value:this.pubKey},sequence:L,signature:L0(B)}]};signAmino=async(y,L)=>{await this.checkOrCreateTransportAndLedger(!0);let _=(await this.getAccounts()).find((Z)=>Z.address===y);if(!_)throw new d.SwapKitError("wallet_ledger_address_not_found",{address:y});let T=await import("@cosmjs/amino"),B=T.encodeSecp256k1Signature??T.default?.encodeSecp256k1Signature,G=T.serializeSignDoc??T.default?.serializeSignDoc,{return_code:X,error_message:N,signature:j}=await this.ledgerApp.sign(this.derivationPath,G(L));return this.validateResponse(X,N),{signature:B(_.pubkey,_0.base64.decode(L0(j))),signed:L}};getAccounts=async()=>{await this.checkOrCreateTransportAndLedger(!0);let{bech32_address:y,compressed_pk:L}=await this.getAddressAndPubKey();return this.pubKey=_0.base64.encode(L),[{address:y,algo:"secp256k1",pubkey:L}]};sign=async(y)=>{await this.checkOrCreateTransportAndLedger(!0);let{return_code:L,error_message:_,signature:T}=await this.ledgerApp.sign(this.derivationPath,y);if(!this.pubKey)throw new d.SwapKitError("wallet_ledger_pubkey_not_found");return this.validateResponse(L,_),L0(T)}}var b=require("@swapkit/helpers");class d0{derivationPath;ledgerApp=null;ledgerTimeout=50000;injectedTransport;constructor(y,L){this.derivationPath=typeof y==="string"?y:b.derivationPathToString(y||b.NetworkDerivationPath.TRON),this.injectedTransport=L}checkOrCreateTransportAndLedger=async()=>{if(this.ledgerApp)return;await this.createTransportAndLedger()};createTransportAndLedger=async()=>{let y=this.injectedTransport??await f(),L=(await import("@ledgerhq/hw-app-trx")).default;this.ledgerApp=new L(y)};getAddress=async()=>{let y=await this.getAddressAndPubKey();if(!y)throw new b.SwapKitError("wallet_ledger_failed_to_get_address");return y.address};getAddressAndPubKey=async()=>{await this.createTransportAndLedger();let y=await this.ledgerApp?.getAddress(this.derivationPath);if(!y)throw new b.SwapKitError("wallet_ledger_failed_to_get_address");return{address:y.address,publicKey:y.publicKey}};showAddressAndPubKey=async()=>{return await this.createTransportAndLedger(),this.ledgerApp?.getAddress(this.derivationPath,!0)};signTransaction=async(y)=>{if(await this.createTransportAndLedger(),!this.ledgerApp)throw new b.SwapKitError("wallet_ledger_transport_error");let L=JSON.stringify(y);try{let _=await this.ledgerApp.signTransaction(this.derivationPath,L,[]);if(!_)throw new b.SwapKitError("wallet_ledger_signing_error");return{...y,signature:[_]}}catch(_){throw new b.SwapKitError("wallet_ledger_signing_error",{error:_})}}}var h0=(y,L)=>new d0(y,L);var s=require("@scure/base"),g=require("@swapkit/helpers");var p0=["bitcoin-cash","dash","dogecoin","zcash"],o0=({tx:y,inputUtxos:L,btcApp:_,derivationPath:T,chain:B},G)=>{let X=L.map((O)=>{return[_.splitTransaction(O.txHex||"",!p0.includes(B),B==="zcash"),O.index,void 0,void 0]}),N=s.hex.encode(y.unsignedTx),j=_.splitTransaction(N,!0),Z=_.serializeTransactionOutputs(j).toString("hex"),F={additionals:["bech32"],associatedKeysets:X.map(()=>T),inputs:X,outputScriptHex:Z,segwit:!0,useTrustedInputForSegwit:!0};return _.createPaymentTransaction({...F,...G})},Jy=({tx:y,inputUtxos:L,btcApp:_,derivationPaths:T,chain:B},G)=>{if(T.length!==L.length)throw new g.SwapKitError("wallet_ledger_invalid_params",{message:`Derivation paths count (${T.length}) must match inputs count (${L.length})`});let X=L.map((O)=>{return[_.splitTransaction(O.txHex||"",!p0.includes(B),B==="zcash"),O.index,void 0,void 0]}),N=s.hex.encode(y.unsignedTx),j=_.splitTransaction(N,!0),Z=_.serializeTransactionOutputs(j).toString("hex"),F={additionals:["bech32"],associatedKeysets:T,inputs:X,outputScriptHex:Z,segwit:!0,useTrustedInputForSegwit:!0};return _.createPaymentTransaction({...F,...G})},h=({chain:y,additionalSignParams:L})=>{return(_,T)=>{let B,G=null;async function X(F=!0){if(F&&!B)new g.SwapKitError("wallet_ledger_connection_error",{message:`Ledger connection failed:
2
+ ${JSON.stringify({btcApp:B,checkBtcApp:F})}`});G||=T??await f()}async function N(){G=T??await f(),B=new(await import("@ledgerhq/hw-app-btc")).default({currency:y,transport:G})}let j=typeof _==="string"?_:g.derivationPathToString(_),Z=g.getWalletFormatFor(j);return{connect:async()=>{await X(!1),B=new(await import("@ledgerhq/hw-app-btc")).default({currency:y,transport:G})},getAddress:async()=>{let{toCashAddress:F}=await import("@swapkit/toolboxes/utxo");await X(!1);let{bitcoinAddress:O}=await B.getWalletPublicKey(j,{format:Z});if(!O)throw new g.SwapKitError("wallet_ledger_get_address_error",{message:`Cannot get ${y} address from ledger derivation path: ${j}`});return y==="bitcoin-cash"&&Z==="legacy"?F(O).replace(/(bchtest:|bitcoincash:)/,""):O},getExtendedPublicKey:async(F="84'/0'/0'",O=76067358)=>{return await X(!1),B.getWalletXpub({path:F,xpubVersion:O})},signPCZT:async(F)=>{if(y!=="zcash")throw new g.SwapKitError("wallet_ledger_chain_not_supported",{message:"PCZT signing is only supported for Zcash"});await N();let{ZcashTransaction:O,Script:W}=await import("@swapkit/utxo-signer"),D=F.getGlobal(),z=new O({consensusBranchId:D.consensusBranchId,expiryHeight:D.expiryHeight,lockTime:D.lockTime,version:D.txVersion,versionGroupId:D.versionGroupId}),S=[];for(let Y=0;Y<F.inputsLength;Y++){let M=F.getInput(Y);z.addInput({index:M.index,script:new Uint8Array,sequence:M.sequence??4294967295,txid:M.txid,value:M.value}),S.push({hash:s.hex.encode(new Uint8Array([...M.txid].reverse())),index:M.index,txHex:Oy(M,D),value:Number(M.value),witnessUtxo:{script:M.scriptPubkey,value:Number(M.value)}})}for(let Y=0;Y<F.outputsLength;Y++){let M=F.getOutput(Y);z.addOutput({amount:M.value,script:M.scriptPubkey})}let $=await o0({btcApp:B,chain:y,derivationPath:j,inputUtxos:S,tx:z},{...L,expiryHeight:(()=>{let Y=Buffer.alloc(4);return Y.writeUInt32LE(D.expiryHeight),Y})(),lockTime:D.lockTime}),q=O.fromHex($,{allowUnknownOutputs:!0}),U=F.clone();for(let Y=0;Y<q.inputsLength;Y++){let M=q.getInput(Y);if(M.script&&M.script.length>0){let K=W.decode(M.script);if(K.length>=2)U.addSignature(Y,K[1],K[0])}}return U},signTransaction:async(F,O)=>{return await N(),o0({btcApp:B,chain:y,derivationPath:j,inputUtxos:O,tx:F},L)},signTransactionWithMultiplePaths:async(F,O,W)=>{return await N(),Jy({btcApp:B,chain:y,derivationPaths:W,inputUtxos:O,tx:F},L)}}}};function Oy(y,L){let _=[],T=(L.txVersion|2147483648)>>>0;_.push(T&255,T>>8&255,T>>16&255,T>>24&255);let B=L.versionGroupId;_.push(B&255,B>>8&255,B>>16&255,B>>24&255),_.push(0);let G=y.index+1;if(G<253)_.push(G);else _.push(253,G&255,G>>8&255);for(let j=0;j<y.index;j++)_.push(0,0,0,0,0,0,0,0),_.push(0);let X=y.value;_.push(Number(X&0xffn),Number(X>>8n&0xffn),Number(X>>16n&0xffn),Number(X>>24n&0xffn),Number(X>>32n&0xffn),Number(X>>40n&0xffn),Number(X>>48n&0xffn),Number(X>>56n&0xffn));let N=y.scriptPubkey;if(N.length<253)_.push(N.length);else _.push(253,N.length&255,N.length>>8&255);for(let j of N)_.push(j);return _.push(L.lockTime&255,L.lockTime>>8&255,L.lockTime>>16&255,L.lockTime>>24&255),_.push(L.expiryHeight&255,L.expiryHeight>>8&255,L.expiryHeight>>16&255,L.expiryHeight>>24&255),_.push(0,0,0,0,0,0,0,0),_.push(0),_.push(0),_.push(0),s.hex.encode(new Uint8Array(_))}var i0=h({chain:"bitcoin"}),n0=h({chain:"litecoin"}),s0=h({additionalSignParams:{additionals:["abc"],segwit:!1,sigHashType:65},chain:"bitcoin-cash"}),t0=h({additionalSignParams:{additionals:[],segwit:!1,useTrustedInputForSegwit:!1},chain:"dogecoin"}),r0=h({additionalSignParams:{additionals:[],segwit:!1,useTrustedInputForSegwit:!1},chain:"dash"}),a0=h({additionalSignParams:{additionals:["zcash","sapling"],expiryHeight:(()=>{let y=Buffer.alloc(4);return y.writeUInt32LE(0),y})(),lockTime:0,segwit:!1,useTrustedInputForSegwit:!1},chain:"zcash"});var e0=Zy(require("@ledgerhq/hw-app-xrp")),o=require("@swapkit/helpers"),Q0=require("ripple-binary-codec");var $y=2147483648;function Qy(y){let L={};for(let _ in y)if(y[_]!==null&&y[_]!==void 0)L[_]=y[_];return L}function Yy(y){return new e0.default(y)}var yy=async(y,L)=>{let _=o.derivationPathToString(y||o.NetworkDerivationPath[o.Chain.Ripple]),T=L??await f(),B=Yy(T),{address:G,publicKey:X}=await B.getAddress(_);async function N(j){let{hashes:Z}=await import("@swapkit/toolboxes/ripple"),O={...Qy(j),Flags:j.Flags||$y,SigningPubKey:X.toUpperCase()},W=Q0.encode(O),D=await B.signTransaction(_,W),z=Q0.encode({...O,TxnSignature:D});return{hash:Z.hashSignedTx(z),tx_blob:z}}return{getAddress:()=>G,signTransaction:N}};var k=async({chain:y,derivationPath:L,transport:_})=>{let{match:T}=await import("ts-pattern");return T(y).returnType().with(J.Chain.THORChain,()=>Promise.resolve(new $0(L,_))).with(J.Chain.Cosmos,()=>Promise.resolve(new Z0(L,_))).with(J.Chain.Bitcoin,()=>Promise.resolve(i0(L,_))).with(J.Chain.BitcoinCash,()=>Promise.resolve(s0(L,_))).with(J.Chain.Dash,()=>Promise.resolve(r0(L,_))).with(J.Chain.Dogecoin,()=>Promise.resolve(t0(L,_))).with(J.Chain.Litecoin,()=>Promise.resolve(n0(L,_))).with(J.Chain.Zcash,()=>Promise.resolve(a0(L,_))).with(J.Chain.Ripple,()=>Promise.resolve(yy(L,_))).with(J.Chain.Tron,()=>Promise.resolve(h0(L,_))).with(J.Chain.Sui,()=>Promise.resolve(c0(L,_))).with(J.Chain.Near,()=>{return Promise.resolve(l0(L,_))}).with(J.Chain.Arbitrum,J.Chain.Aurora,J.Chain.Avalanche,J.Chain.Berachain,J.Chain.BinanceSmartChain,J.Chain.Ethereum,J.Chain.Gnosis,J.Chain.Monad,J.Chain.Optimism,J.Chain.Polygon,J.Chain.Base,J.Chain.XLayer,async()=>{let{getProvider:B}=await import("@swapkit/toolboxes/evm"),G={derivationPath:L,provider:await B(y),transport:_};return T(y).with(J.Chain.BinanceSmartChain,()=>b0(G)).with(J.Chain.Avalanche,()=>K0(G)).with(J.Chain.Arbitrum,()=>S0(G)).with(J.Chain.Berachain,()=>g0(G)).with(J.Chain.Optimism,()=>P0(G)).with(J.Chain.Polygon,()=>I0(G)).with(J.Chain.Base,()=>V0(G)).with(J.Chain.Aurora,()=>A0(G)).with(J.Chain.Gnosis,()=>E0(G)).with(J.Chain.Monad,()=>v0(G)).with(J.Chain.XLayer,()=>C0(G)).otherwise(()=>k0(G))}).otherwise(()=>{throw new J.SwapKitError("wallet_chain_not_supported",{chain:y,wallet:J.WalletOption.LEDGER})})};var Ly=B0.createWallet({connect:({addChain:y,supportedChains:L,walletType:_})=>async function(B,G,{transport:X}={}){let[N]=R.filterSupportedChains({chains:B,supportedChains:L,walletType:_});if(!N)return!1;let j=G??R.NetworkDerivationPath[N],Z=await Dy({chain:N,derivationPath:j,transport:X});return y({...Z,chain:N,walletType:R.WalletOption.LEDGER}),!0},directSigningSupport:{[R.Chain.Arbitrum]:!0,[R.Chain.Aurora]:!0,[R.Chain.Avalanche]:!0,[R.Chain.Base]:!0,[R.Chain.Berachain]:!0,[R.Chain.BinanceSmartChain]:!0,[R.Chain.Ethereum]:!0,[R.Chain.Gnosis]:!0,[R.Chain.Monad]:!0,[R.Chain.Bitcoin]:!0,[R.Chain.BitcoinCash]:!0,[R.Chain.Cosmos]:!0,[R.Chain.Dash]:!0,[R.Chain.Dogecoin]:!0,[R.Chain.Litecoin]:!0,[R.Chain.Near]:!0,[R.Chain.Optimism]:!0,[R.Chain.Polygon]:!0,[R.Chain.Ripple]:!0,[R.Chain.Sui]:!0,[R.Chain.THORChain]:!0,[R.Chain.Tron]:!0,[R.Chain.XLayer]:!0},name:"connectLedger",supportedChains:[R.Chain.Arbitrum,R.Chain.Aurora,R.Chain.Avalanche,R.Chain.Base,R.Chain.Berachain,R.Chain.BinanceSmartChain,R.Chain.Bitcoin,R.Chain.BitcoinCash,R.Chain.Cosmos,R.Chain.Dash,R.Chain.Dogecoin,R.Chain.Ethereum,R.Chain.Gnosis,R.Chain.Litecoin,R.Chain.Monad,R.Chain.Near,R.Chain.Optimism,R.Chain.Polygon,R.Chain.Ripple,R.Chain.Sui,R.Chain.THORChain,R.Chain.XLayer,R.Chain.Tron,R.Chain.Zcash],walletType:R.WalletOption.LEDGER}),Wy=B0.getWalletSupportedChains(Ly);function qy(y,L="t"){if(!y?.includes("=:"))return y;let _=y.includes(`:${L}:`)?y.split(`:${L}:`)[0]:y;return _?.substring(0,_.lastIndexOf(":"))}async function Dy({chain:y,derivationPath:L,transport:_}){switch(y){case R.Chain.BitcoinCash:case R.Chain.Bitcoin:case R.Chain.Dash:case R.Chain.Dogecoin:case R.Chain.Litecoin:case R.Chain.Zcash:{let O=function($={}){return F($)},{getUtxoToolbox:T}=await import("@swapkit/toolboxes/utxo"),B=y,G=await k({chain:y,derivationPath:L,transport:_}),X=await v({chain:y,ledgerClient:G}),N;if(y===R.Chain.Bitcoin||y===R.Chain.Litecoin){let{BitcoinPsbtLedger:$,LitecoinPsbtLedger:q}=await import("../chunk-3gajmdgz.js"),U=y===R.Chain.Bitcoin?$(L,_):q(L,_);N={getAddress:U.getAddress,signTransaction:U.signTransaction}}else if(y===R.Chain.BitcoinCash||y===R.Chain.Dogecoin||y===R.Chain.Dash){let{createLegacyPsbtSigner:$}=await import("../chunk-mrsfcest.js");N=$({address:X,chain:B,legacyClient:G})}let j=N?await T(B,{signer:N}):T(B),Z=async($)=>{let q=$.feeRate||(await j.getFeeRates())[R.FeeOption.Average],U=[R.Chain.Bitcoin].includes(y)?$.memo:qy($.memo),{tx:Y,inputs:M}=await j.createTransaction({...$,feeRate:q,fetchTxHex:!0,memo:U,sender:X}),K=await G.signTransaction(Y,M);return await j.broadcastTx(K)};async function F({accountIndex:$}={}){if(!G.getExtendedPublicKey)return;let q=H.getUTXOAccountPath({accountIndex:$,chain:B,derivationPath:L}),U=R.derivationPathToString(q),Y=y===R.Chain.Bitcoin||y===R.Chain.Litecoin?U:U.replace(/^m\//,""),M=await G.getExtendedPublicKey(Y);return{accountIndex:H.getUTXOAccountIndexFromPath(q),path:U,xpub:M}}async function W({accountIndex:$,index:q,change:U=!1}){try{let Y=H.getUTXOAddressPath({accountIndex:$,chain:B,change:U,derivationPath:L,index:q}),M=await k({chain:B,derivationPath:Y,transport:_}),K=await v({chain:B,ledgerClient:M});return{accountIndex:H.getUTXOAccountIndexFromPath(Y),address:K,change:U,index:q,path:R.derivationPathToString(Y),pubkey:""}}catch{return}}async function D({accountIndex:$,count:q,startIndex:U=0,change:Y=!1}){return H.assertDerivationIndex("count",q),H.assertDerivationIndex("startIndex",U),(await Promise.all(Array.from({length:q},(K,t)=>W({accountIndex:$,change:Y,index:U+t})))).filter((K)=>!!K)}let z=H.createHDWalletHelpers({chain:B,deriveAddress:W,getBalance:j.getBalance,getUtxos:($)=>H.getUtxoApi(B).getUtxos({address:$,fetchTxHex:!0})});async function S({utxos:$,recipient:q,assetValue:U,memo:Y,feeRate:M,feeOptionKey:K,changeAddress:t}){if(!$.length)throw new R.SwapKitError("wallet_ledger_invalid_params",{message:"No UTXOs provided for multi-address transfer"});let _y=M||(await j.getFeeRates())[K||R.FeeOption.Fast],T0=Y?H.compileMemo(Y):null,Y0=[{address:q,value:U.getBaseValue("number")}];if(T0)Y0.push({script:T0,value:0});let By=$.map(({hash:a,index:e,value:G0,txHex:R0,witnessUtxo:N0})=>({hash:a,index:e,txHex:R0,value:G0,witnessUtxo:N0})),{inputs:r,outputs:M0}=j.accumulative({chain:B,feeRate:_y,inputs:By,outputs:Y0});if(!(r&&M0))throw new R.SwapKitError("wallet_ledger_connection_error",{message:"Insufficient balance for multi-address transfer"});let{Transaction:Ty}=await import("@swapkit/utxo-signer"),w0=new Ty({allowLegacyWitnessUtxo:!0,version:1}),Gy=t||$[0]?.address||q;H.addInputsAndOutputs({chain:B,compiledMemo:T0,inputs:r,outputs:M0,sender:Gy,tx:w0});let Ry=H.getUTXOAccountPath({chain:B,derivationPath:L}),Ny=r.map((a)=>{let e=$.find((W0)=>W0.hash===a.hash&&W0.index===a.index),G0=e?.derivationIndex??0,R0=e?.isChange??!1,N0=[...Ry,Number(R0),G0];return R.derivationPathToString(N0)});if(!G.signTransactionWithMultiplePaths)throw new R.SwapKitError("wallet_ledger_method_not_supported",{method:"signTransactionWithMultiplePaths"});let Xy=await G.signTransactionWithMultiplePaths(w0,r,Ny);return j.broadcastTx(Xy)}return{...j,...z,address:X,deriveAddressAtIndex:W,deriveAddresses:D,getExtendedPublicKey:O,getExtendedPublicKeyInfo:F,transfer:Z,transferFromMultipleAddresses:S}}case R.Chain.Ethereum:case R.Chain.Avalanche:case R.Chain.Arbitrum:case R.Chain.Berachain:case R.Chain.Optimism:case R.Chain.Polygon:case R.Chain.BinanceSmartChain:case R.Chain.Base:case R.Chain.Aurora:case R.Chain.Gnosis:case R.Chain.Monad:case R.Chain.XLayer:{let{getEvmToolboxAsync:T}=await import("@swapkit/toolboxes/evm"),B=await k({chain:y,derivationPath:L,transport:_}),G=await v({chain:y,ledgerClient:B});return{...await T(y,{signer:B}),address:G}}case R.Chain.Cosmos:{let{createSigningStargateClient:T,getMsgSendDenom:B,getCosmosToolbox:G}=await import("@swapkit/toolboxes/cosmos"),X=await k({chain:y,derivationPath:L,transport:_}),N=await v({chain:y,ledgerClient:X});return{...await G(R.Chain.Cosmos,{signer:X}),address:N,transfer:async({assetValue:F,recipient:O,memo:W})=>{if(!F)throw new R.SwapKitError("wallet_ledger_invalid_asset");let D={amount:[{amount:F.getBaseValue("string"),denom:B(`u${F.symbol}`).toLowerCase()}],fromAddress:N,toAddress:O},z=await R.getRPCUrl(y),S=await T(z,X,"0.007uatom"),{transactionHash:$}=await S.signAndBroadcast(N,[{typeUrl:"/cosmos.bank.v1beta1.MsgSend",value:D}],2,W);return $}}}case R.Chain.THORChain:{let T=await k({chain:y,derivationPath:L,transport:_}),{getCosmosToolbox:B}=await import("@swapkit/toolboxes/cosmos"),G=B(y,{signer:T}),X=await v({chain:y,ledgerClient:T}),{sign:N}=T;return{...G,address:X,signMessage:N}}case R.Chain.Near:{let{getNearToolbox:T}=await import("@swapkit/toolboxes/near"),B=await k({chain:y,derivationPath:L,transport:_}),G=await B.getAddress();return{...T({signer:B}),address:G}}case R.Chain.Ripple:{let{getRippleToolbox:T}=await import("@swapkit/toolboxes/ripple"),B=await k({chain:y,derivationPath:L,transport:_}),G=B.getAddress();return{...T({signer:B}),address:G}}case R.Chain.Tron:{let{getTronToolbox:T}=await import("@swapkit/toolboxes/tron"),B=await k({chain:y,derivationPath:L,transport:_}),G=await v({chain:y,ledgerClient:B});return{...T({signer:B}),address:G}}case R.Chain.Sui:{let{getSuiToolbox:T}=await import("@swapkit/toolboxes/sui"),B=await k({chain:y,derivationPath:L,transport:_}),G=await v({chain:y,ledgerClient:B});return{...T({signer:B}),address:G}}default:throw new R.SwapKitError("wallet_ledger_chain_not_supported",{chain:y})}}
3
3
 
4
- //# debugId=29B9644D31CAD27364756E2164756E21
4
+ //# debugId=8BF0593F9A74C7E064756E2164756E21
5
5
  //# sourceMappingURL=index.cjs.map