@swapkit/wallet-hardware 4.6.3 → 4.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/dist/chunk-3yr76n9s.js +5 -0
  2. package/dist/chunk-3yr76n9s.js.map +10 -0
  3. package/dist/chunk-3zf2pqfd.js +4 -0
  4. package/dist/chunk-3zf2pqfd.js.map +10 -0
  5. package/dist/{chunk-1jexf7qt.js → chunk-7fsaymh4.js} +3 -3
  6. package/dist/{chunk-1jexf7qt.js.map → chunk-7fsaymh4.js.map} +1 -1
  7. package/dist/{chunk-skvfn1dg.js → chunk-9tg9jj9j.js} +3 -3
  8. package/dist/{chunk-skvfn1dg.js.map → chunk-9tg9jj9j.js.map} +1 -1
  9. package/dist/chunk-mrsfcest.js +4 -0
  10. package/dist/chunk-mrsfcest.js.map +10 -0
  11. package/dist/{chunk-1jpcb30j.js → chunk-n05bv2n5.js} +3 -3
  12. package/dist/{chunk-1jpcb30j.js.map → chunk-n05bv2n5.js.map} +1 -1
  13. package/dist/chunk-px09mwnt.js +4 -0
  14. package/dist/chunk-px09mwnt.js.map +10 -0
  15. package/dist/{chunk-ybje7f3s.js → chunk-vwv6z2mk.js} +3 -3
  16. package/dist/{chunk-ybje7f3s.js.map → chunk-vwv6z2mk.js.map} +1 -1
  17. package/dist/chunk-x85da57j.js +4 -0
  18. package/dist/chunk-x85da57j.js.map +10 -0
  19. package/dist/chunk-y3yvq1zt.js +4 -0
  20. package/dist/chunk-y3yvq1zt.js.map +10 -0
  21. package/dist/keepkey/index.cjs +2 -2
  22. package/dist/keepkey/index.cjs.map +4 -4
  23. package/dist/keepkey/index.js +2 -2
  24. package/dist/keepkey/index.js.map +4 -4
  25. package/dist/ledger/index.cjs +3 -3
  26. package/dist/ledger/index.cjs.map +5 -6
  27. package/dist/ledger/index.js +3 -3
  28. package/dist/ledger/index.js.map +5 -6
  29. package/dist/trezor/index.cjs +2 -2
  30. package/dist/trezor/index.cjs.map +3 -3
  31. package/dist/trezor/index.js +2 -2
  32. package/dist/trezor/index.js.map +3 -3
  33. package/dist/types/keepkey/chains/utxo.d.ts +52 -14
  34. package/dist/types/keepkey/chains/utxo.d.ts.map +1 -1
  35. package/dist/types/keepkey/index.d.ts +2 -1
  36. package/dist/types/keepkey/index.d.ts.map +1 -1
  37. package/dist/types/ledger/clients/thorchain/lib.d.ts.map +1 -1
  38. package/dist/types/ledger/clients/utxo-legacy-adapter.d.ts +31 -0
  39. package/dist/types/ledger/clients/utxo-legacy-adapter.d.ts.map +1 -0
  40. package/dist/types/ledger/clients/utxo-psbt.d.ts +15 -0
  41. package/dist/types/ledger/clients/utxo-psbt.d.ts.map +1 -0
  42. package/dist/types/ledger/index.d.ts +2 -1
  43. package/dist/types/ledger/index.d.ts.map +1 -1
  44. package/dist/types/trezor/index.d.ts +2 -1
  45. package/dist/types/trezor/index.d.ts.map +1 -1
  46. package/package.json +5 -4
  47. package/dist/chunk-4fapcrj9.js +0 -5
  48. package/dist/chunk-4fapcrj9.js.map +0 -10
  49. package/dist/chunk-jj2v7mke.js +0 -4
  50. package/dist/chunk-jj2v7mke.js.map +0 -10
  51. package/dist/types/core.d.ts +0 -18
  52. package/dist/types/core.d.ts.map +0 -1
@@ -1,5 +1,5 @@
1
- var K0={};f0(K0,{ledgerWallet:()=>G0,LEDGER_SUPPORTED_CHAINS:()=>q0});module.exports=D0(K0);var T=require("@swapkit/helpers"),l=require("@swapkit/toolboxes/utxo");var C=require("@swapkit/helpers"),g=async({chain:L,ledgerClient:_})=>{if(!_)return"";switch(L){case C.Chain.Cosmos:case C.Chain.THORChain:return _.connect();case C.Chain.Ethereum:case C.Chain.BinanceSmartChain:case C.Chain.Avalanche:case C.Chain.Polygon:case C.Chain.Arbitrum:case C.Chain.Berachain:case C.Chain.Optimism:case C.Chain.Base:case C.Chain.Aurora:case C.Chain.Gnosis:case C.Chain.Monad:case C.Chain.XLayer:return _.getAddress();case C.Chain.Bitcoin:case C.Chain.BitcoinCash:case C.Chain.Dash:case C.Chain.Dogecoin:case C.Chain.Litecoin:case C.Chain.Zcash:{let y=_;await y.connect();let m=await y.getAddress();return L===C.Chain.BitcoinCash?m.replace("bitcoincash:",""):m}case C.Chain.Near:return await _.getAddress();case C.Chain.Ripple:return _.getAddress();case C.Chain.Tron:return _.getAddress();case C.Chain.Sui:return _.connect();default:throw new C.SwapKitError("wallet_chain_not_supported",{chain:L,wallet:C.WalletOption.LEDGER})}};var j=require("@swapkit/helpers");var x=require("@swapkit/helpers");var K=require("@swapkit/helpers");var JL=require("@swapkit/helpers");var o=85,jL=250;var v={GET_ADDR_SECP256K1:4,GET_VERSION:0,INS_PUBLIC_KEY_SECP256K1:1,SIGN_SECP256K1:2},XL={ADD:1,INIT:0,LAST:2},AL={ONLY_RETRIEVE:0,SHOW_ADDRESS_IN_DEVICE:1},n={JSON:0},I={NoError:36864},HL={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 S(L){if(L in HL)return HL[L];return`Unknown Status Code: ${L}`}function $0(L){return typeof L==="object"&&L!==null&&!Array.isArray(L)&&!(L instanceof Date)}function f(L){if(L){if($0(L)){if(Object.hasOwn(L,"statusCode"))return{error_message:S(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 CL(L){return L.send(85,v.GET_VERSION,0,0).then((_)=>{let y=_.slice(-2),m=y[0]*256+y[1],w=0;if(_.length>=9)w=(_[5]<<24)+(_[6]<<16)+(_[7]<<8)+(_[8]<<0);return{device_locked:_[4]===1,error_message:S(m),major:_[1],minor:_[2],patch:_[3],return_code:m,target_id:w.toString(16),test_mode:_[0]!==0}},f)}var LL=require("@swapkit/helpers");function DL(L){if(L==null||L.length<3)throw new LL.SwapKitError("wallet_ledger_invalid_params",{reason:"Path too short"});if(L.length>10)throw new LL.SwapKitError("wallet_ledger_invalid_params",{reason:"Path too long"});let _=Buffer.alloc(1+4*L.length);_.writeUInt8(L.length,0);for(let y=0;y<L.length;y+=1){let m=L[y]||0;if(y<3)m|=2147483648;_.writeInt32LE(m,1+y*4)}return _}function $L(L,_,y,m,w=n.JSON){return L.transport.send(o,v.SIGN_SECP256K1,_,w,m,[I.NoError,27012,27264]).then((R)=>{let O=R.slice(-2),G=O[0]*256+O[1],N=S(G);if(G===27264||G===27012)N=`${N} : ${R.slice(0,R.length-2).toString("ascii")}`;let B=null;if(R.length>2)B=R.slice(0,R.length-2);return{error_message:N,return_code:G,signature:B}},f)}function J0(L){if(L.length!==65)throw new LL.SwapKitError("wallet_ledger_invalid_params",{reason:"decompressed public key length should be 65 bytes"});let _=L.slice(33,65),y=Buffer.from([2+(_[_.length-1]&1)]);return Buffer.concat([y,L.slice(1,33)])}function fL(L,_){return L.transport.send(o,v.INS_PUBLIC_KEY_SECP256K1,0,0,_,[I.NoError]).then((y)=>{let m=y.slice(-2),w=m[0]*256+m[1],R=Buffer.from(y.slice(0,65));return{compressed_pk:J0(R),error_message:S(w),pk:R,return_code:w}},f)}function qL(L){if(!L||L.length!==5)throw new LL.SwapKitError("wallet_ledger_invalid_params",{reason:"Path must be exactly 5 elements"});let _=Buffer.alloc(20);return _.writeUInt32LE(2147483648+L[0],0),_.writeUInt32LE(2147483648+L[1],4),_.writeUInt32LE(2147483648+L[2],8),_.writeUInt32LE(L[3],12),_.writeUInt32LE(L[4],16),_}function PL(L,_,y,m,w=n.JSON){let R=XL.ADD;if(_===1)R=XL.INIT;if(_===y)R=XL.LAST;return $L(L,R,0,m,w)}function zL(L,_){return L.transport.send(o,v.GET_ADDR_SECP256K1,0,0,_,[I.NoError]).then((y)=>{let m=y.slice(-2),w=m[0]*256+m[1];return{compressed_pk:Buffer.from(y.slice(0,33)),error_message:S(w),pk:"OBSOLETE PROPERTY",return_code:w}},f)}class _L{transport;versionResponse;constructor(L){if(!L)throw new JL.SwapKitError("wallet_ledger_transport_not_defined");this.transport=L}static serializeHRP(L){if(L==null||L.length<3||L.length>83)throw new JL.SwapKitError("wallet_ledger_invalid_params",{reason:"Invalid HRP"});let _=Buffer.alloc(1+L.length);return _.writeUInt8(L.length,0),_.write(L,1),_}async serializePath(L){if(this.versionResponse=await CL(this.transport),this.versionResponse.return_code!==I.NoError)throw this.versionResponse;switch(this.versionResponse.major){case 1:return DL(L);case 2:return qL(L);default:return Buffer.alloc(0)}}async signGetChunks(L,_){let y=await this.serializePath(L),m=[];m.push(y);for(let w=0;w<_.length;w+=jL){let R=w+jL;if(w>_.length)R=_.length;m.push(_.slice(w,R))}return m}async getVersion(){try{return this.versionResponse=await CL(this.transport),this.versionResponse}catch(L){return f(L)}}appInfo(){return this.transport.send(176,1,0,0).then((L)=>{let _=L.slice(-2),y=_[0]*256+_[1],m="",w="",R=0,O=0;if(L[0]!==1)return{error_message:"response format ID not recognized",return_code:36865};let G=L[1];m=L.slice(2,2+G).toString("ascii");let N=2+G,B=L[N];N+=1,w=L.slice(N,N+B).toString("ascii"),N+=B;let X=L[N];return N+=1,R=X,O=L[N],{appName:m,appVersion:w,error_message:S(y),flag_onboarded:(O&4)!==0,flag_pin_validated:(O&128)!==0,flag_recovery:(O&1)!==0,flag_signed_mcu_code:(O&2)!==0,flagLen:R,flagsValue:O,return_code:y}},f)}deviceInfo(){return this.transport.send(224,1,0,0,Buffer.from([]),[I.NoError,28160]).then((L)=>{let _=L.slice(-2),y=_[0]*256+_[1];if(y===28160)return{error_message:"This command is only available in the Dashboard",return_code:y};let m=L.slice(0,4).toString("hex"),w=4,R=L[w];w+=1;let O=L.slice(w,w+R).toString();w+=R;let G=L[w];w+=1;let N=L.slice(w,w+G).toString("hex");w+=G;let B=L[w];w+=1;let X=L.slice(w,w+B);if(X[B-1]===0)X=L.slice(w,w+B-1);let A=X.toString();return{error_message:S(y),flag:N,mcuVersion:A,return_code:y,seVersion:O,targetId:m}},f)}async publicKey(L){try{let _=await this.serializePath(L);switch(this.versionResponse.major){case 1:return fL(this,_);case 2:{let y=Buffer.concat([_L.serializeHRP("thor"),_]);return zL(this,y)}default:return{error_message:"App Version is not supported",return_code:25600}}}catch(_){return f(_)}}getAddressAndPubKey(L,_,y=!1){return this.serializePath(L).then((m)=>{let w=Buffer.concat([_L.serializeHRP(_),m]);return this.transport.send(o,v.GET_ADDR_SECP256K1,y?AL.SHOW_ADDRESS_IN_DEVICE:AL.ONLY_RETRIEVE,0,w,[I.NoError]).then((R)=>{let O=R.slice(-2),G=O[0]*256+O[1],N=Buffer.from(R.slice(0,33));return{bech32_address:Buffer.from(R.slice(33,-2)).toString(),compressed_pk:N,error_message:S(G),return_code:G}},f)}).catch((m)=>f(m))}showAddressAndPubKey(L,_){return this.getAddressAndPubKey(L,_,!0)}signSendChunk(L,_,y,m=n.JSON){switch(this.versionResponse.major){case 1:return $L(this,L,_,y,m);case 2:return PL(this,L,_,y,m);default:return{error_message:"App Version is not supported",return_code:25600}}}async sign(L,_,y=n.JSON){let m=Buffer.from(_),w=[],R;try{w=await this.signGetChunks(L,m),R=await this.signSendChunk(1,w.length,w[0],y)}catch(G){f(G)}let O={error_message:R.error_message,return_code:R.return_code,signature:null};for(let G=1;G<w.length;G+=1)if(O=await this.signSendChunk(1+G,w.length,w[G],y),O.return_code!==I.NoError)break;return{error_message:O.error_message,return_code:O.return_code,signature:O.signature}}}var i=require("@swapkit/helpers"),ZL=()=>navigator?.usb,Z0=async()=>{let L=ZL();if(typeof L?.getDevices!=="function")return{};let{ledgerUSBVendorId:_}=await import("@ledgerhq/devices"),m=(await L?.getDevices()).filter((w)=>w.vendorId===_);if(m.length>0)return m[0];return L?.requestDevice({filters:[{vendorId:_}]})},Y=async()=>{let L=await Z0();if(!L)throw new i.SwapKitError("wallet_ledger_device_not_found");if(L.opened||await L.open(),L.configuration===null)await L.selectConfiguration(1);try{await L.reset()}catch{}let _=L.configuration??L.configurations?.[0],y=_?.interfaces.find(({alternates:X})=>X.some(({interfaceClass:A})=>A===255))||_?.interfaces.find(({alternates:X})=>X.some(({interfaceClass:A})=>A===3));if(!y)throw await L.close(),new i.SwapKitError("wallet_ledger_connection_error");let m=y.alternates?.find(({interfaceClass:X})=>X===3)?.interfaceClass,w=y.alternates?.find(({interfaceClass:X})=>X===255)?.interfaceClass;if(m&&!w){let X=(await import("@ledgerhq/hw-transport-webhid")).default;if(!await X.isSupported())throw await L.close(),new i.SwapKitError("wallet_ledger_webhid_not_supported");return await X.create()}try{await L.claimInterface(y.interfaceNumber)}catch(X){throw await L.close(),new i.SwapKitError("wallet_ledger_connection_claimed",X)}let R=(await import("@ledgerhq/hw-transport-webusb")).default;if(!await R.isSupported())throw new i.SwapKitError("wallet_ledger_webusb_not_supported");let{DisconnectedDevice:G}=await import("@ledgerhq/errors"),N=new R(L,y.interfaceNumber),B=(X)=>{if(L===X.device)ZL()?.removeEventListener("disconnect",B),N._emitDisconnect(new G)};return ZL()?.addEventListener("disconnect",B),N};class yL{ledgerTimeout=50000;derivationPath=K.NetworkDerivationPath.GAIA;transport;ledgerApp;chain="thor";checkOrCreateTransportAndLedger=async(L=!1)=>{if(!L&&this.transport&&this.ledgerApp)return;try{switch(this.transport=L||!this.transport?await Y():this.transport,this.chain){case"thor":{this.ledgerApp=L||!this.ledgerApp?new _L(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(_){throw new K.SwapKitError("wallet_ledger_connection_error",_)}};validateResponse=(L,_)=>{switch(L){case K.LedgerErrorCode.NoError:return;case K.LedgerErrorCode.LockedDevice:throw new K.SwapKitError("wallet_ledger_device_locked",{message:`Ledger is locked: ${_}`});case K.LedgerErrorCode.TC_NotFound:throw new K.SwapKitError("wallet_ledger_device_not_found");default:break}}}class ML extends yL{pubKey=null;derivationPath;constructor(L=x.NetworkDerivationPath.GAIA){super();this.chain="cosmos",this.derivationPath=x.derivationPathToString(L)}connect=async()=>{await this.checkOrCreateTransportAndLedger(!0);let{publicKey:L,address:_}=await this.getAddressAndPubKey();return this.pubKey=Buffer.from(L,"hex").toString("base64"),_};getAddressAndPubKey=async()=>{return await this.checkOrCreateTransportAndLedger(!0),await this.ledgerApp.getAddress(this.derivationPath,this.chain)};signTransaction=async(L,_="0")=>{await this.checkOrCreateTransportAndLedger(!0);let{return_code:y,error_message:m,signature:w}=await this.ledgerApp.sign(this.derivationPath,L);if(!this.pubKey)throw new x.SwapKitError("wallet_ledger_pubkey_not_found");return this.validateResponse(y,m),[{pub_key:{type:"tendermint/PubKeySecp256k1",value:this.pubKey},sequence:_,signature:w}]};signAmino=async(L,_)=>{await this.checkOrCreateTransportAndLedger(!0);let y=await this.getAccounts();if(y.findIndex((F)=>F.address===L)===-1)throw new x.SwapKitError("wallet_ledger_address_not_found",{address:L});let w=await import("@cosmjs/amino"),R=w.encodeSecp256k1Signature??w.default?.encodeSecp256k1Signature,O=w.serializeSignDoc??w.default?.serializeSignDoc,G=await import("@cosmjs/crypto"),N=G.Secp256k1Signature??G.default?.Secp256k1Signature,B=O(_),X=await this.ledgerApp.sign(this.derivationPath,B);this.validateResponse(X.return_code,X.error_message);let A=N.fromDer(X.signature).toFixedLength();return{signature:R(y[0].pubkey,A),signed:_}};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"),SL=require("ethers");class D extends SL.AbstractSigner{chainId=$.ChainId.Ethereum;derivationPath="";ledgerApp=null;ledgerTimeout=50000;constructor({provider:L,derivationPath:_=$.NetworkDerivationPath.OP,chainId:y=$.ChainId.Optimism}){super(L);this.chainId=y||$.ChainId.Ethereum,this.derivationPath=typeof _==="string"?_:$.derivationPathToString(_),Object.defineProperty(this,"provider",{enumerable:!0,value:L||null,writable:!1})}connect=(L)=>new D({chainId:this.chainId,derivationPath:this.derivationPath,provider:L});checkOrCreateTransportAndLedger=async()=>{if(this.ledgerApp)return;await this.createTransportAndLedger()};createTransportAndLedger=async()=>{let L=await Y(),_=(await import("@ledgerhq/hw-app-eth")).default;this.ledgerApp=new _(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:_}=await import("ethers");await this.createTransportAndLedger();let y=await this.ledgerApp?.signPersonalMessage(this.derivationPath,L);if(!y)throw new $.SwapKitError("wallet_ledger_signing_error");return y.r=`0x${y.r}`,y.s=`0x${y.s}`,_.from(y).serialized};sendTransaction=async(L)=>{if(!this.provider)throw new $.SwapKitError("wallet_ledger_no_provider");let _=await this.signTransaction(L);return await this.provider.broadcastTransaction(_)};signTypedData=async(L,_,y,m)=>{let{buildEIP712DomainType:w}=await import("@swapkit/toolboxes/evm"),{Signature:R,TypedDataEncoder:O}=await import("ethers");await this.createTransportAndLedger();let{EIP712Domain:G,...N}=_,B=m??O.from(N).primaryType,X;try{X=await this.ledgerApp?.signEIP712Message(this.derivationPath,{domain:L,message:y,primaryType:B,types:{EIP712Domain:w(L),...N}})}catch(A){let F=A instanceof Error&&"statusCode"in A;if(!F||F&&A.statusCode===27013)throw A;let J=O.hashDomain(L).slice(2),Z=O.from(N).hash(y).slice(2);X=await this.ledgerApp?.signEIP712HashedMessage(this.derivationPath,J,Z)}if(!X)throw new $.SwapKitError("wallet_ledger_signing_error");return X.r=`0x${X.r}`,X.s=`0x${X.s}`,R.from(X).serialized};signTransaction=async(L)=>{let{Transaction:_}=await import("ethers");await this.createTransportAndLedger();let y=await this.provider?.getTransactionCount(L.from||await this.getAddress()),m={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||y||0).toString()):y,to:L.to?.toString(),type:L.type&&!Number.isNaN(L.type)?L.type:L.maxFeePerGas?2:0,value:L.value},w=_.from(m).unsignedSerialized.slice(2),{ledgerService:R}=await import("@ledgerhq/hw-app-eth"),O=await R.resolveTransaction(w,{},{erc20:!0,externalPlugins:!0}),G=await this.ledgerApp?.signTransaction(this.derivationPath,w,O);if(!G)throw new $.SwapKitError("wallet_ledger_signing_error");let{r:N,s:B,v:X}=G;return _.from({...m,signature:{r:`0x${N}`,s:`0x${B}`,v:Number(BigInt(X))}}).serialized}}var KL=(L)=>new D({...L,chainId:$.ChainId.Arbitrum}),kL=(L)=>new D({...L,chainId:$.ChainId.Aurora}),cL=(L)=>new D({...L,chainId:$.ChainId.Avalanche}),VL=(L)=>new D({...L,chainId:$.ChainId.Base}),gL=(L)=>new D({...L,chainId:$.ChainId.Ethereum}),IL=(L)=>new D({...L,chainId:$.ChainId.Gnosis}),EL=(L)=>new D({...L,chainId:$.ChainId.Optimism}),lL=(L)=>new D({...L,chainId:$.ChainId.Polygon}),hL=(L)=>new D({...L,chainId:$.ChainId.BinanceSmartChain}),bL=(L)=>new D({...L,chainId:$.ChainId.Monad}),vL=(L)=>new D({...L,chainId:$.ChainId.XLayer}),xL=(L)=>new D({...L,chainId:$.ChainId.Berachain});async function dL(L){let _=(await import("@ledgerhq/hw-app-near")).default,{Chain:y,NetworkDerivationPath:m,SwapKitError:w}=await import("@swapkit/helpers"),R=await Y(),O=new _(R),G=(L||m[y.Near]).join("'/").concat("'"),{address:N,publicKey:B}=await O.getAddress(G);return{getAddress(){return Promise.resolve(N)},async getPublicKey(){let{PublicKey:A}=await import("@near-js/crypto");return A.fromString(`ed25519:${B}`)},signDelegateAction(A){return Promise.reject(new w("wallet_ledger_method_not_supported",{method:"signDelegateAction",wallet:"Ledger"}))},signNep413Message(A,F,J,Z,W){return Promise.reject(new w("wallet_ledger_method_not_supported",{method:"signNep413Message",wallet:"Ledger"}))},async signTransaction(A){let{Signature:F,SignedTransaction:J}=await import("@near-js/transactions");try{let Z=await O.signTransaction(A.encode(),G);if(!Z)throw Error("Signature undefined");let W=new F({data:Z,keyType:0}),H=new J({signature:W,transaction:A});return[Z,H]}catch(Z){throw new w("wallet_ledger_signing_error",{error:Z})}}}}var U=require("@swapkit/helpers");class oL{derivationPath;ledgerApp=null;address=null;publicKey=null;constructor(L){this.derivationPath=typeof L==="string"?L:U.derivationPathToString(L||U.NetworkDerivationPath[U.Chain.Sui])}getLedgerPath(){return this.derivationPath.replace(/^m\//,"").replace(/\/(\d+)\/(\d+)$/,"/$1'/$2'")}async createTransportAndLedger(){if(this.ledgerApp)return;let L=await Y(),_=(await import("@ledgerhq/hw-app-sui")).default;this.ledgerApp=new _(L)}async connect(){if(await this.createTransportAndLedger(),!this.ledgerApp)throw new U.SwapKitError("wallet_ledger_transport_error");let L=this.getLedgerPath(),_=await this.ledgerApp.getPublicKey(L);if(!_?.publicKey)throw new U.SwapKitError("wallet_ledger_failed_to_get_address");return this.publicKey=_.publicKey,this.address=`0x${Buffer.from(_.address).toString("hex")}`,this.address}toSuiAddress(){if(!this.address)throw new U.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 _=L instanceof Uint8Array?L:L.transaction;if(await this.createTransportAndLedger(),!this.ledgerApp)throw new U.SwapKitError("wallet_ledger_transport_error");if(!this.publicKey)throw new U.SwapKitError("wallet_ledger_failed_to_get_address");try{let y=this.getLedgerPath(),m=new Uint8Array(3+_.length);m[0]=0,m[1]=0,m[2]=0,m.set(_,3);let w=await this.ledgerApp.signTransaction(y,m);if(!w?.signature)throw new U.SwapKitError("wallet_ledger_signing_error");let R=this.publicKey.length===33?this.publicKey.slice(1):this.publicKey;if(R.length!==32)throw new U.SwapKitError("wallet_ledger_signing_error",{error:"Invalid public key length"});let O=new Uint8Array(97);O[0]=0,O.set(w.signature,1),O.set(R,65);let G=Buffer.from(O).toString("base64");return{bytes:Buffer.from(_).toString("base64"),signature:G}}catch(y){throw new U.SwapKitError("wallet_ledger_signing_error",{error:y})}}}var nL=(L)=>new oL(L);var uL=require("@scure/base"),wL=require("@swapkit/helpers");var iL=require("@scure/base"),k=require("@swapkit/helpers"),QL=(L)=>{if(L.length<64)throw new k.SwapKitError("wallet_ledger_invalid_signature",{reason:"Too short"});if(L[0]!==48)throw new k.SwapKitError("wallet_ledger_invalid_signature",{reason:"TLV encoding: expected first byte 0x30"});if(L[1]+2!==L.length)throw new k.SwapKitError("wallet_ledger_invalid_signature",{reason:"signature length does not match TLV"});if(L[2]!==2)throw new k.SwapKitError("wallet_ledger_invalid_signature",{reason:"TLV encoding: expected length type 0x02"});let _=L[3],y=L.slice(4,_+4);if(y.length===33&&y[0]===0)y=y.slice(1,33);else if(y.length===33)throw new k.SwapKitError("wallet_ledger_invalid_signature",{reason:"r too long"});while(y.length<32)y.unshift(0);if(L[_+4]!==2)throw new k.SwapKitError("wallet_ledger_invalid_signature",{reason:"TLV encoding: expected length type 0x02 for s"});let m=L[_+5];if(4+_+2+m!==L.length)throw new k.SwapKitError("wallet_ledger_invalid_signature",{reason:"TLV byte lengths do not match message length"});let w=L.slice(_+6,L.length);if(w.length===33&&w[0]===0)w=w.slice(1,33);else if(w.length===33)throw new k.SwapKitError("wallet_ledger_invalid_signature",{reason:"s too long"});while(w.length<32)w.unshift(0);if(y.length!==32||w.length!==32)throw new k.SwapKitError("wallet_ledger_invalid_signature",{reason:"must be 32 bytes each"});return iL.base64.encode(Buffer.concat([y,w]))};class WL extends yL{pubKey=null;derivationPath;constructor(L=wL.NetworkDerivationPath.THOR){super();this.chain="thor",this.derivationPath=L}get pubkey(){return this.pubKey}connect=async()=>{await this.checkOrCreateTransportAndLedger();let{compressed_pk:L,bech32_address:_}=await this.getAddressAndPubKey();return this.pubKey=uL.base64.encode(L),_};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,_="0")=>{await this.checkOrCreateTransportAndLedger(!0);let{return_code:y,error_message:m,signature:w}=await this.ledgerApp.sign(this.derivationPath,L);if(!this.pubKey)throw new wL.SwapKitError("wallet_ledger_pubkey_not_found");return this.validateResponse(y,m),[{pub_key:{type:"tendermint/PubKeySecp256k1",value:this.pubKey},sequence:_,signature:QL(w)}]};sign=async(L)=>{await this.checkOrCreateTransportAndLedger(!0);let{return_code:_,error_message:y,signature:m}=await this.ledgerApp.sign(this.derivationPath,L);if(!this.pubKey)throw new wL.SwapKitError("wallet_ledger_pubkey_not_found");return this.validateResponse(_,y),QL(m)}}var c=require("@swapkit/helpers");class tL{derivationPath;ledgerApp=null;ledgerTimeout=50000;constructor(L){this.derivationPath=typeof L==="string"?L:c.derivationPathToString(L||c.NetworkDerivationPath.TRON)}checkOrCreateTransportAndLedger=async()=>{if(this.ledgerApp)return;await this.createTransportAndLedger()};createTransportAndLedger=async()=>{let L=await Y(),_=(await import("@ledgerhq/hw-app-trx")).default;this.ledgerApp=new _(L)};getAddress=async()=>{let L=await this.getAddressAndPubKey();if(!L)throw new c.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 c.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 c.SwapKitError("wallet_ledger_transport_error");let _=JSON.stringify(L);try{let y=await this.ledgerApp.signTransaction(this.derivationPath,_,[]);if(!y)throw new c.SwapKitError("wallet_ledger_signing_error");return{...L,signature:[y]}}catch(y){throw new c.SwapKitError("wallet_ledger_signing_error",{error:y})}}}var pL=(L)=>new tL(L);var mL=require("@scure/base"),E=require("@swapkit/helpers");var aL=["bitcoin-cash","dash","dogecoin","zcash"],eL=({tx:L,inputUtxos:_,btcApp:y,derivationPath:m,chain:w},R)=>{let O=_.map((A)=>{return[y.splitTransaction(A.txHex||"",!aL.includes(w),w==="zcash"),A.index,void 0,void 0]}),G=mL.hex.encode(L.unsignedTx),N=y.splitTransaction(G,!0),B=y.serializeTransactionOutputs(N).toString("hex"),X={additionals:["bech32"],associatedKeysets:O.map(()=>m),inputs:O,outputScriptHex:B,segwit:!0,useTrustedInputForSegwit:!0};return y.createPaymentTransaction({...X,...R})},M0=({tx:L,inputUtxos:_,btcApp:y,derivationPaths:m,chain:w},R)=>{if(m.length!==_.length)throw new E.SwapKitError("wallet_ledger_invalid_params",{message:`Derivation paths count (${m.length}) must match inputs count (${_.length})`});let O=_.map((A)=>{return[y.splitTransaction(A.txHex||"",!aL.includes(w),w==="zcash"),A.index,void 0,void 0]}),G=mL.hex.encode(L.unsignedTx),N=y.splitTransaction(G,!0),B=y.serializeTransactionOutputs(N).toString("hex"),X={additionals:["bech32"],associatedKeysets:m,inputs:O,outputScriptHex:B,segwit:!0,useTrustedInputForSegwit:!0};return y.createPaymentTransaction({...X,...R})},u=({chain:L,additionalSignParams:_})=>{let y,m=null;async function w(O=!0){if(O&&!y)new E.SwapKitError("wallet_ledger_connection_error",{message:`Ledger connection failed:
2
- ${JSON.stringify({btcApp:y,checkBtcApp:O})}`});m||=await Y()}async function R(){m=await Y(),y=new(await import("@ledgerhq/hw-app-btc")).default({currency:L,transport:m})}return(O)=>{let G=typeof O==="string"?O:E.derivationPathToString(O),N=E.getWalletFormatFor(G);return{connect:async()=>{await w(!1),y=new(await import("@ledgerhq/hw-app-btc")).default({currency:L,transport:m})},getAddress:async()=>{let{toCashAddress:B}=await import("@swapkit/toolboxes/utxo");await w(!1);let{bitcoinAddress:X}=await y.getWalletPublicKey(G,{format:N});if(!X)throw new E.SwapKitError("wallet_ledger_get_address_error",{message:`Cannot get ${L} address from ledger derivation path: ${G}`});return L==="bitcoin-cash"&&N==="legacy"?B(X).replace(/(bchtest:|bitcoincash:)/,""):X},getExtendedPublicKey:async(B="84'/0'/0'",X=76067358)=>{return await w(!1),y.getWalletXpub({path:B,xpubVersion:X})},signPCZT:async(B)=>{if(L!=="zcash")throw new E.SwapKitError("wallet_ledger_chain_not_supported",{message:"PCZT signing is only supported for Zcash"});await R();let{ZcashTransaction:X,Script:A}=await import("@swapkit/utxo-signer"),F=B.getGlobal(),J=new X({consensusBranchId:F.consensusBranchId,expiryHeight:F.expiryHeight,lockTime:F.lockTime,version:F.txVersion,versionGroupId:F.versionGroupId}),Z=[];for(let M=0;M<B.inputsLength;M++){let Q=B.getInput(M);J.addInput({index:Q.index,script:new Uint8Array,sequence:Q.sequence??4294967295,txid:Q.txid,value:Q.value}),Z.push({hash:mL.hex.encode(new Uint8Array([...Q.txid].reverse())),index:Q.index,txHex:Q0(Q,F),value:Number(Q.value),witnessUtxo:{script:Q.scriptPubkey,value:Number(Q.value)}})}for(let M=0;M<B.outputsLength;M++){let Q=B.getOutput(M);J.addOutput({amount:Q.value,script:Q.scriptPubkey})}let W=await eL({btcApp:y,chain:L,derivationPath:G,inputUtxos:Z,tx:J},{..._,expiryHeight:(()=>{let M=Buffer.alloc(4);return M.writeUInt32LE(F.expiryHeight),M})(),lockTime:F.lockTime}),H=X.fromHex(W,{allowUnknownOutputs:!0}),q=B.clone();for(let M=0;M<H.inputsLength;M++){let Q=H.getInput(M);if(Q.script&&Q.script.length>0){let V=A.decode(Q.script);if(V.length>=2)q.addSignature(M,V[1],V[0])}}return q},signTransaction:async(B,X)=>{return await R(),eL({btcApp:y,chain:L,derivationPath:G,inputUtxos:X,tx:B},_)},signTransactionWithMultiplePaths:async(B,X,A)=>{return await R(),M0({btcApp:y,chain:L,derivationPaths:A,inputUtxos:X,tx:B},_)}}}};function Q0(L,_){let y=[],m=(_.txVersion|2147483648)>>>0;y.push(m&255,m>>8&255,m>>16&255,m>>24&255);let w=_.versionGroupId;y.push(w&255,w>>8&255,w>>16&255,w>>24&255),y.push(0);let R=L.index+1;if(R<253)y.push(R);else y.push(253,R&255,R>>8&255);for(let N=0;N<L.index;N++)y.push(0,0,0,0,0,0,0,0),y.push(0);let O=L.value;y.push(Number(O&0xffn),Number(O>>8n&0xffn),Number(O>>16n&0xffn),Number(O>>24n&0xffn),Number(O>>32n&0xffn),Number(O>>40n&0xffn),Number(O>>48n&0xffn),Number(O>>56n&0xffn));let G=L.scriptPubkey;if(G.length<253)y.push(G.length);else y.push(253,G.length&255,G.length>>8&255);for(let N of G)y.push(N);return y.push(_.lockTime&255,_.lockTime>>8&255,_.lockTime>>16&255,_.lockTime>>24&255),y.push(_.expiryHeight&255,_.expiryHeight>>8&255,_.expiryHeight>>16&255,_.expiryHeight>>24&255),y.push(0,0,0,0,0,0,0,0),y.push(0),y.push(0),y.push(0),mL.hex.encode(new Uint8Array(y))}var sL=u({chain:"bitcoin"}),rL=u({chain:"litecoin"}),L0=u({additionalSignParams:{additionals:["abc"],segwit:!1,sigHashType:65},chain:"bitcoin-cash"}),_0=u({additionalSignParams:{additionals:[],segwit:!1,useTrustedInputForSegwit:!1},chain:"dogecoin"}),y0=u({additionalSignParams:{additionals:[],segwit:!1,useTrustedInputForSegwit:!1},chain:"dash"}),w0=u({additionalSignParams:{additionals:["zcash","sapling"],expiryHeight:(()=>{let L=Buffer.alloc(4);return L.writeUInt32LE(0),L})(),lockTime:0,segwit:!1,useTrustedInputForSegwit:!1},chain:"zcash"});var m0=W0(require("@ledgerhq/hw-app-xrp")),t=require("@swapkit/helpers"),YL=require("ripple-binary-codec");var Y0=2147483648;function U0(L){let _={};for(let y in L)if(L[y]!==null&&L[y]!==void 0)_[y]=L[y];return _}function H0(L){return new m0.default(L)}var T0=async(L)=>{let _=t.derivationPathToString(L||t.NetworkDerivationPath[t.Chain.Ripple]),y=await Y(),m=H0(y),{address:w,publicKey:R}=await m.getAddress(_);async function O(G){let{hashes:N}=await import("@swapkit/toolboxes/ripple"),X={...U0(G),Flags:G.Flags||Y0,SigningPubKey:R.toUpperCase()},A=YL.encode(X),F=await m.signTransaction(_,A),J=YL.encode({...X,TxnSignature:F});return{hash:N.hashSignedTx(J),tx_blob:J}}return{getAddress:()=>w,signTransaction:O}};var P=async({chain:L,derivationPath:_})=>{let{match:y}=await import("ts-pattern");return y(L).returnType().with(j.Chain.THORChain,()=>Promise.resolve(new WL(_))).with(j.Chain.Cosmos,()=>Promise.resolve(new ML(_))).with(j.Chain.Bitcoin,()=>Promise.resolve(sL(_))).with(j.Chain.BitcoinCash,()=>Promise.resolve(L0(_))).with(j.Chain.Dash,()=>Promise.resolve(y0(_))).with(j.Chain.Dogecoin,()=>Promise.resolve(_0(_))).with(j.Chain.Litecoin,()=>Promise.resolve(rL(_))).with(j.Chain.Zcash,()=>Promise.resolve(w0(_))).with(j.Chain.Ripple,()=>Promise.resolve(T0(_))).with(j.Chain.Tron,()=>Promise.resolve(pL(_))).with(j.Chain.Sui,()=>Promise.resolve(nL(_))).with(j.Chain.Near,()=>{return Promise.resolve(dL(_))}).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:m}=await import("@swapkit/toolboxes/evm"),w={derivationPath:_,provider:await m(L)};return y(L).with(j.Chain.BinanceSmartChain,()=>hL(w)).with(j.Chain.Avalanche,()=>cL(w)).with(j.Chain.Arbitrum,()=>KL(w)).with(j.Chain.Berachain,()=>xL(w)).with(j.Chain.Optimism,()=>EL(w)).with(j.Chain.Polygon,()=>lL(w)).with(j.Chain.Base,()=>VL(w)).with(j.Chain.Aurora,()=>kL(w)).with(j.Chain.Gnosis,()=>IL(w)).with(j.Chain.Monad,()=>bL(w)).with(j.Chain.XLayer,()=>vL(w)).otherwise(()=>gL(w))}).otherwise(()=>{throw new j.SwapKitError("wallet_chain_not_supported",{chain:L,wallet:j.WalletOption.LEDGER})})};var G0=R0({connect:({addChain:L,supportedChains:_,walletType:y})=>async function(w,R){let[O]=T.filterSupportedChains({chains:w,supportedChains:_,walletType:y});if(!O)return!1;let G=await S0({chain:O,derivationPath:R});return L({...G,chain:O,walletType:T.WalletOption.LEDGER}),!0},name:"connectLedger",supportedChains:[T.Chain.Arbitrum,T.Chain.Aurora,T.Chain.Avalanche,T.Chain.Base,T.Chain.Berachain,T.Chain.BinanceSmartChain,T.Chain.Bitcoin,T.Chain.BitcoinCash,T.Chain.Cosmos,T.Chain.Dash,T.Chain.Dogecoin,T.Chain.Ethereum,T.Chain.Gnosis,T.Chain.Litecoin,T.Chain.Monad,T.Chain.Near,T.Chain.Optimism,T.Chain.Polygon,T.Chain.Ripple,T.Chain.Sui,T.Chain.THORChain,T.Chain.XLayer,T.Chain.Tron,T.Chain.Zcash],walletType:T.WalletOption.LEDGER}),q0=O0(G0);function P0(L,_="t"){if(!L?.includes("=:"))return L;let y=L.includes(`:${_}:`)?L.split(`:${_}:`)[0]:L;return y?.substring(0,y.lastIndexOf(":"))}function BL(L){if(Array.isArray(L))return L.forEach((m,w)=>{L[w]=BL(m)}),L;if(typeof L!=="object")return L;let _={},y=Object.keys(L).sort();for(let m of y)_[m]=BL(L[m]);return _}function z0(L){return JSON.stringify(BL(L))}async function S0({chain:L,derivationPath:_}){switch(L){case T.Chain.BitcoinCash:case T.Chain.Bitcoin:case T.Chain.Dash:case T.Chain.Dogecoin:case T.Chain.Litecoin:case T.Chain.Zcash:{let{getUtxoToolbox:y}=await import("@swapkit/toolboxes/utxo"),m=L,w=y(m),R=await P({chain:L,derivationPath:_}),O=await g({chain:L,ledgerClient:R}),G=async(F)=>{let J=F.feeRate||(await w.getFeeRates())[T.FeeOption.Average],Z=[T.Chain.Bitcoin].includes(L)?F.memo:P0(F.memo),{tx:W,inputs:H}=await w.createTransaction({...F,feeRate:J,fetchTxHex:!0,memo:Z,sender:O}),q=await R.signTransaction(W,H);return await w.broadcastTx(q)};async function N(){if(!R.getExtendedPublicKey)return;let F=await R.getExtendedPublicKey(),J=_?.slice(0,3)??T.NetworkDerivationPath[L].slice(0,3);return{path:T.derivationPathToString(J),xpub:F}}async function B({index:F,change:J=!1}){try{let W=[..._?.slice(0,3)??T.NetworkDerivationPath[L].slice(0,3),Number(J),F],H=await P({chain:m,derivationPath:W});return{address:await g({chain:m,ledgerClient:H}),change:J,index:F,pubkey:""}}catch{return}}let X=l.createHDWalletHelpers({chain:m,deriveAddress:B,getBalance:w.getBalance,getUtxos:(F)=>l.getUtxoApi(m).getUtxos({address:F,fetchTxHex:!0})});async function A({utxos:F,recipient:J,assetValue:Z,memo:W,feeRate:H,feeOptionKey:q,changeAddress:M}){if(!F.length)throw new T.SwapKitError("wallet_ledger_invalid_params",{message:"No UTXOs provided for multi-address transfer"});let Q=H||(await w.getFeeRates())[q||T.FeeOption.Fast],V=W?l.compileMemo(W):null,p=[{address:J,value:Z.getBaseValue("number")}];if(V)p.push({script:V,value:0});let UL=F.map(({hash:h,index:d,value:b,txHex:s,witnessUtxo:r})=>({hash:h,index:d,txHex:s,value:b,witnessUtxo:r})),{inputs:e,outputs:z}=w.accumulative({chain:m,feeRate:Q,inputs:UL,outputs:p});if(!(e&&z))throw new T.SwapKitError("wallet_ledger_connection_error",{message:"Insufficient balance for multi-address transfer"});let{Transaction:TL}=await import("@swapkit/utxo-signer"),RL=new TL({allowLegacyWitnessUtxo:!0,version:1}),OL=M||F[0]?.address||J;l.addInputsAndOutputs({chain:m,compiledMemo:V,inputs:e,outputs:z,sender:OL,tx:RL});let NL=_?.slice(0,3)??T.NetworkDerivationPath[L].slice(0,3),FL=e.map((h)=>{let d=F.find((GL)=>GL.hash===h.hash&&GL.index===h.index),b=d?.derivationIndex??0,s=d?.isChange??!1,r=[...NL,Number(s),b];return T.derivationPathToString(r)});if(!R.signTransactionWithMultiplePaths)throw new T.SwapKitError("wallet_ledger_method_not_supported",{method:"signTransactionWithMultiplePaths"});let a=await R.signTransactionWithMultiplePaths(RL,e,FL);return w.broadcastTx(a)}return{...w,...X,address:O,deriveAddressAtIndex:B,getExtendedPublicKey:N,transfer:G,transferFromMultipleAddresses:A}}case T.Chain.Ethereum:case T.Chain.Avalanche:case T.Chain.Arbitrum:case T.Chain.Berachain:case T.Chain.Optimism:case T.Chain.Polygon:case T.Chain.BinanceSmartChain:case T.Chain.Base:case T.Chain.Aurora:case T.Chain.Gnosis:case T.Chain.Monad:case T.Chain.XLayer:{let{getEvmToolboxAsync:y}=await import("@swapkit/toolboxes/evm"),m=await P({chain:L,derivationPath:_}),w=await g({chain:L,ledgerClient:m});return{...await y(L,{signer:m}),address:w}}case T.Chain.Cosmos:{let{createSigningStargateClient:y,getMsgSendDenom:m,getCosmosToolbox:w}=await import("@swapkit/toolboxes/cosmos"),R=w(T.Chain.Cosmos),O=await P({chain:L,derivationPath:_}),G=await g({chain:L,ledgerClient:O});return{...R,address:G,transfer:async({assetValue:B,recipient:X,memo:A})=>{if(!B)throw new T.SwapKitError("wallet_ledger_invalid_asset");let F={amount:[{amount:B.getBaseValue("string"),denom:m(`u${B.symbol}`).toLowerCase()}],fromAddress:G,toAddress:X},J=await T.getRPCUrl(L),Z=await y(J,O,"0.007uatom"),{transactionHash:W}=await Z.signAndBroadcast(G,[{typeUrl:"/cosmos.bank.v1beta1.MsgSend",value:F}],2,A);return W}}}case T.Chain.THORChain:{let{SignMode:y}=await import("cosmjs-types/cosmos/tx/signing/v1beta1/signing.js"),{TxRaw:m}=await import("cosmjs-types/cosmos/tx/v1beta1/tx.js"),w=await import("@cosmjs/proto-signing"),R=w.encodePubkey??w.default?.encodePubkey,O=w.makeAuthInfoBytes??w.default?.makeAuthInfoBytes,{createStargateClient:G,buildEncodedTxBody:N,getCosmosToolbox:B,buildAminoMsg:X,getDefaultChainFee:A,fromBase64:F,parseAminoMessageForDirectSigning:J}=await import("@swapkit/toolboxes/cosmos"),Z=B(L),W=await P({chain:L,derivationPath:_}),H=await g({chain:L,ledgerClient:W}),q=A(L),{pubkey:M,signTransaction:Q,sign:V}=W,p=async({memo:z="",assetValue:TL,...RL})=>{let OL=await Z.getAccount(H);if(!OL)throw new T.SwapKitError("wallet_ledger_invalid_account");if(!TL)throw new T.SwapKitError("wallet_ledger_invalid_asset");if(!M)throw new T.SwapKitError("wallet_ledger_pubkey_not_found");let{accountNumber:NL,sequence:FL}=OL,a=(FL||0).toString(),h=BL([X({assetValue:TL,memo:z,sender:H,...RL})]),d=z0({account_number:NL?.toString(),chain_id:T.THORConfig.chainId,fee:q,memo:z,msgs:h,sequence:a}),b=await Q(d,a);if(!b)throw new T.SwapKitError("wallet_ledger_signing_error");let s=R({type:"tendermint/PubKeySecp256k1",value:M}),r=h.map(J),GL=await N({chain:L,memo:z,msgs:r}),X0=O([{pubkey:s,sequence:Number(a)}],q.amount,Number.parseInt(q.gas,10),void 0,void 0,y.SIGN_MODE_LEGACY_AMINO_JSON),B0=b?.[0]?.signature?F(b[0].signature):Uint8Array.from([]),N0=m.fromPartial({authInfoBytes:X0,bodyBytes:GL,signatures:[B0]}),F0=m.encode(N0).finish(),j0=await T.getRPCUrl(T.Chain.THORChain),A0=await G(j0),{transactionHash:C0}=await A0.broadcastTx(F0);return C0};return{...Z,address:H,deposit:(z)=>p(z),signMessage:V,transfer:(z)=>p(z)}}case T.Chain.Near:{let{getNearToolbox:y}=await import("@swapkit/toolboxes/near"),m=await P({chain:L,derivationPath:_}),w=await m.getAddress();return{...y({signer:m}),address:w}}case T.Chain.Ripple:{let{getRippleToolbox:y}=await import("@swapkit/toolboxes/ripple"),m=await P({chain:L,derivationPath:_}),w=m.getAddress();return{...y({signer:m}),address:w}}case T.Chain.Tron:{let{getTronToolbox:y}=await import("@swapkit/toolboxes/tron"),m=await P({chain:L,derivationPath:_}),w=await g({chain:L,ledgerClient:m});return{...y({signer:m}),address:w}}case T.Chain.Sui:{let{getSuiToolbox:y}=await import("@swapkit/toolboxes/sui"),m=await P({chain:L,derivationPath:_}),w=await g({chain:L,ledgerClient:m});return{...y({signer:m}),address:w}}default:throw new T.SwapKitError("wallet_ledger_chain_not_supported",{chain:L})}}
1
+ var c0={};Z0(c0,{ledgerWallet:()=>G0,LEDGER_SUPPORTED_CHAINS:()=>M0});module.exports=U0(c0);var m=require("@swapkit/helpers"),M=require("@swapkit/toolboxes/utxo"),DL=require("@swapkit/wallet-core");var j=require("@swapkit/helpers"),V=async({chain:L,ledgerClient:_})=>{if(!_)return"";switch(L){case j.Chain.Cosmos:case j.Chain.THORChain:return _.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 _.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 y.connect();let T=await y.getAddress();return L===j.Chain.BitcoinCash?T.replace("bitcoincash:",""):T}case j.Chain.Near:return await _.getAddress();case j.Chain.Ripple:return _.getAddress();case j.Chain.Tron:return _.getAddress();case j.Chain.Sui:return _.connect();default:throw new j.SwapKitError("wallet_chain_not_supported",{chain:L,wallet:j.WalletOption.LEDGER})}};var N=require("@swapkit/helpers");var o=require("@swapkit/helpers");var g=require("@swapkit/helpers");var JL=require("@swapkit/helpers");var i=85,jL=250;var h={GET_ADDR_SECP256K1:4,GET_VERSION:0,INS_PUBLIC_KEY_SECP256K1:1,SIGN_SECP256K1:2},XL={ADD:1,INIT:0,LAST:2},AL={ONLY_RETRIEVE:0,SHOW_ADDRESS_IN_DEVICE:1},n={JSON:0},E={NoError:36864},HL={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 HL)return HL[L];return`Unknown Status Code: ${L}`}function D0(L){return typeof L==="object"&&L!==null&&!Array.isArray(L)&&!(L instanceof Date)}function S(L){if(L){if(D0(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 WL(L){return L.send(85,h.GET_VERSION,0,0).then((_)=>{let y=_.slice(-2),T=y[0]*256+y[1],w=0;if(_.length>=9)w=(_[5]<<24)+(_[6]<<16)+(_[7]<<8)+(_[8]<<0);return{device_locked:_[4]===1,error_message:K(T),major:_[1],minor:_[2],patch:_[3],return_code:T,target_id:w.toString(16),test_mode:_[0]!==0}},S)}var _L=require("@swapkit/helpers");function cL(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 _=Buffer.alloc(1+4*L.length);_.writeUInt8(L.length,0);for(let y=0;y<L.length;y+=1){let T=L[y]||0;if(y<3)T|=2147483648;_.writeInt32LE(T,1+y*4)}return _}function $L(L,_,y,T,w=n.JSON){return L.transport.send(i,h.SIGN_SECP256K1,_,w,T,[E.NoError,27012,27264]).then((R)=>{let O=R.slice(-2),G=O[0]*256+O[1],X=K(G);if(G===27264||G===27012)X=`${X} : ${R.slice(0,R.length-2).toString("ascii")}`;let C=null;if(R.length>2)C=R.slice(0,R.length-2);return{error_message:X,return_code:G,signature:C}},S)}function F0(L){if(L.length!==65)throw new _L.SwapKitError("wallet_ledger_invalid_params",{reason:"decompressed public key length should be 65 bytes"});let _=L.slice(33,65),y=Buffer.from([2+(_[_.length-1]&1)]);return Buffer.concat([y,L.slice(1,33)])}function qL(L,_){return L.transport.send(i,h.INS_PUBLIC_KEY_SECP256K1,0,0,_,[E.NoError]).then((y)=>{let T=y.slice(-2),w=T[0]*256+T[1],R=Buffer.from(y.slice(0,65));return{compressed_pk:F0(R),error_message:K(w),pk:R,return_code:w}},S)}function SL(L){if(!L||L.length!==5)throw new _L.SwapKitError("wallet_ledger_invalid_params",{reason:"Path must be exactly 5 elements"});let _=Buffer.alloc(20);return _.writeUInt32LE(2147483648+L[0],0),_.writeUInt32LE(2147483648+L[1],4),_.writeUInt32LE(2147483648+L[2],8),_.writeUInt32LE(L[3],12),_.writeUInt32LE(L[4],16),_}function PL(L,_,y,T,w=n.JSON){let R=XL.ADD;if(_===1)R=XL.INIT;if(_===y)R=XL.LAST;return $L(L,R,0,T,w)}function zL(L,_){return L.transport.send(i,h.GET_ADDR_SECP256K1,0,0,_,[E.NoError]).then((y)=>{let T=y.slice(-2),w=T[0]*256+T[1];return{compressed_pk:Buffer.from(y.slice(0,33)),error_message:K(w),pk:"OBSOLETE PROPERTY",return_code:w}},S)}class yL{transport;versionResponse;constructor(L){if(!L)throw new JL.SwapKitError("wallet_ledger_transport_not_defined");this.transport=L}static serializeHRP(L){if(L==null||L.length<3||L.length>83)throw new JL.SwapKitError("wallet_ledger_invalid_params",{reason:"Invalid HRP"});let _=Buffer.alloc(1+L.length);return _.writeUInt8(L.length,0),_.write(L,1),_}async serializePath(L){if(this.versionResponse=await WL(this.transport),this.versionResponse.return_code!==E.NoError)throw this.versionResponse;switch(this.versionResponse.major){case 1:return cL(L);case 2:return SL(L);default:return Buffer.alloc(0)}}async signGetChunks(L,_){let y=await this.serializePath(L),T=[];T.push(y);for(let w=0;w<_.length;w+=jL){let R=w+jL;if(w>_.length)R=_.length;T.push(_.slice(w,R))}return T}async getVersion(){try{return this.versionResponse=await WL(this.transport),this.versionResponse}catch(L){return S(L)}}appInfo(){return this.transport.send(176,1,0,0).then((L)=>{let _=L.readUInt16BE(L.length-2),y="",T="",w=0,R=0;if(L[0]!==1)return{error_message:"response format ID not recognized",return_code:36865};let O=L[1];y=L.slice(2,2+O).toString("ascii");let G=2+O,X=L[G];G+=1,T=L.slice(G,G+X).toString("ascii"),G+=X;let C=L[G];return G+=1,w=C,R=L[G],{appName:y,appVersion:T,error_message:K(_),flag_onboarded:(R&4)!==0,flag_pin_validated:(R&128)!==0,flag_recovery:(R&1)!==0,flag_signed_mcu_code:(R&2)!==0,flagLen:w,flagsValue:R,return_code:_}},S)}deviceInfo(){return this.transport.send(224,1,0,0,Buffer.from([]),[E.NoError,28160]).then((L)=>{let _=L.slice(-2),y=_[0]*256+_[1];if(y===28160)return{error_message:"This command is only available in the Dashboard",return_code:y};let T=L.slice(0,4).toString("hex"),w=4,R=L[w];w+=1;let O=L.slice(w,w+R).toString();w+=R;let G=L[w];w+=1;let X=L.slice(w,w+G).toString("hex");w+=G;let C=L[w];w+=1;let B=L.slice(w,w+C);if(B[C-1]===0)B=L.slice(w,w+C-1);let D=B.toString();return{error_message:K(y),flag:X,mcuVersion:D,return_code:y,seVersion:O,targetId:T}},S)}async publicKey(L){try{let _=await this.serializePath(L);switch(this.versionResponse.major){case 1:return qL(this,_);case 2:{let y=Buffer.concat([yL.serializeHRP("thor"),_]);return zL(this,y)}default:return{error_message:"App Version is not supported",return_code:25600}}}catch(_){return S(_)}}async getAddressAndPubKey(L,_,y=!1){try{let T=await this.serializePath(L),w=Buffer.concat([yL.serializeHRP(_),T]),R=await this.transport.send(i,h.GET_ADDR_SECP256K1,y?AL.SHOW_ADDRESS_IN_DEVICE:AL.ONLY_RETRIEVE,0,w,[E.NoError]),O=Buffer.from(R.slice(0,33)),G=Buffer.from(R.slice(33,-2)).toString(),X=R.readUInt16BE(R.length-2);return{bech32_address:G,compressed_pk:O,error_message:K(X),return_code:X}}catch(T){return S(T)}}showAddressAndPubKey(L,_){return this.getAddressAndPubKey(L,_,!0)}signSendChunk(L,_,y,T=n.JSON){switch(this.versionResponse.major){case 1:return $L(this,L,_,y,T);case 2:return PL(this,L,_,y,T);default:return{error_message:"App Version is not supported",return_code:25600}}}async sign(L,_,y=n.JSON){let T=Buffer.from(_),w=[],R;try{w=await this.signGetChunks(L,T),R=await this.signSendChunk(1,w.length,w[0],y)}catch(G){S(G)}let O={error_message:R.error_message,return_code:R.return_code,signature:null};for(let G=1;G<w.length;G+=1)if(O=await this.signSendChunk(1+G,w.length,w[G],y),O.return_code!==E.NoError)break;return{error_message:O.error_message,return_code:O.return_code,signature:O.signature}}}class wL{ledgerTimeout=50000;derivationPath=g.NetworkDerivationPath.GAIA;transport;ledgerApp;chain="thor";checkOrCreateTransportAndLedger=async(L=!1)=>{if(!L&&this.transport&&this.ledgerApp)return;try{switch(this.transport=L||!this.transport?await Y():this.transport,this.chain){case"thor":{this.ledgerApp=L||!this.ledgerApp?new yL(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(_){throw new g.SwapKitError("wallet_ledger_connection_error",_)}};validateResponse=(L,_)=>{switch(L){case g.LedgerErrorCode.NoError:return;case g.LedgerErrorCode.LockedDevice:throw new g.SwapKitError("wallet_ledger_device_locked",{message:`Ledger is locked: ${_}`});case g.LedgerErrorCode.TC_NotFound:throw new g.SwapKitError("wallet_ledger_device_not_found");default:break}}}class UL extends wL{pubKey=null;derivationPath;constructor(L=o.NetworkDerivationPath.GAIA){super();this.chain="cosmos",this.derivationPath=o.derivationPathToString(L)}connect=async()=>{await this.checkOrCreateTransportAndLedger(!0);let{publicKey:L,address:_}=await this.getAddressAndPubKey();return this.pubKey=Buffer.from(L,"hex").toString("base64"),_};getAddressAndPubKey=async()=>{return await this.checkOrCreateTransportAndLedger(!0),await this.ledgerApp.getAddress(this.derivationPath,this.chain)};signTransaction=async(L,_="0")=>{await this.checkOrCreateTransportAndLedger(!0);let{return_code:y,error_message:T,signature:w}=await this.ledgerApp.sign(this.derivationPath,L);if(!this.pubKey)throw new o.SwapKitError("wallet_ledger_pubkey_not_found");return this.validateResponse(y,T),[{pub_key:{type:"tendermint/PubKeySecp256k1",value:this.pubKey},sequence:_,signature:w}]};signAmino=async(L,_)=>{await this.checkOrCreateTransportAndLedger(!0);let y=await this.getAccounts();if(y.findIndex((W)=>W.address===L)===-1)throw new o.SwapKitError("wallet_ledger_address_not_found",{address:L});let w=await import("@cosmjs/amino"),R=w.encodeSecp256k1Signature??w.default?.encodeSecp256k1Signature,O=w.serializeSignDoc??w.default?.serializeSignDoc,G=await import("@cosmjs/crypto"),X=G.Secp256k1Signature??G.default?.Secp256k1Signature,C=O(_),B=await this.ledgerApp.sign(this.derivationPath,C);this.validateResponse(B.return_code,B.error_message);let D=X.fromDer(B.signature).toFixedLength();return{signature:R(y[0].pubkey,D),signed:_}};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 q extends KL.AbstractSigner{chainId=$.ChainId.Ethereum;derivationPath="";ledgerApp=null;ledgerTimeout=50000;constructor({provider:L,derivationPath:_=$.NetworkDerivationPath.OP,chainId:y=$.ChainId.Optimism}){super(L);this.chainId=y||$.ChainId.Ethereum,this.derivationPath=typeof _==="string"?_:$.derivationPathToString(_),Object.defineProperty(this,"provider",{enumerable:!0,value:L||null,writable:!1})}connect=(L)=>new q({chainId:this.chainId,derivationPath:this.derivationPath,provider:L});checkOrCreateTransportAndLedger=async()=>{if(this.ledgerApp)return;await this.createTransportAndLedger()};createTransportAndLedger=async()=>{let L=await Y(),_=(await import("@ledgerhq/hw-app-eth")).default;this.ledgerApp=new _(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:_}=await import("ethers");await this.createTransportAndLedger();let y=await this.ledgerApp?.signPersonalMessage(this.derivationPath,L);if(!y)throw new $.SwapKitError("wallet_ledger_signing_error");return y.r=`0x${y.r}`,y.s=`0x${y.s}`,_.from(y).serialized};sendTransaction=async(L)=>{if(!this.provider)throw new $.SwapKitError("wallet_ledger_no_provider");let _=await this.signTransaction(L);return await this.provider.broadcastTransaction(_)};signTypedData=async(L,_,y,T)=>{let{buildEIP712DomainType:w}=await import("@swapkit/toolboxes/evm"),{Signature:R,TypedDataEncoder:O}=await import("ethers");await this.createTransportAndLedger();let{EIP712Domain:G,...X}=_,C=T??O.from(X).primaryType,B;try{B=await this.ledgerApp?.signEIP712Message(this.derivationPath,{domain:L,message:y,primaryType:C,types:{EIP712Domain:w(L),...X}})}catch(D){let W=D instanceof Error&&"statusCode"in D;if(!W||W&&D.statusCode===27013)throw D;let Q=O.hashDomain(L).slice(2),Z=O.from(X).hash(y).slice(2);B=await this.ledgerApp?.signEIP712HashedMessage(this.derivationPath,Q,Z)}if(!B)throw new $.SwapKitError("wallet_ledger_signing_error");return B.r=`0x${B.r}`,B.s=`0x${B.s}`,R.from(B).serialized};signTransaction=async(L)=>{let{Transaction:_}=await import("ethers");await this.createTransportAndLedger();let y=await this.provider?.getTransactionCount(L.from||await this.getAddress()),T={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||y||0).toString()):y,to:L.to?.toString(),type:L.type&&!Number.isNaN(L.type)?L.type:L.maxFeePerGas?2:0,value:L.value},w=_.from(T).unsignedSerialized.slice(2),{ledgerService:R}=await import("@ledgerhq/hw-app-eth"),O=await R.resolveTransaction(w,{},{erc20:!0,externalPlugins:!0}),G=await this.ledgerApp?.signTransaction(this.derivationPath,w,O);if(!G)throw new $.SwapKitError("wallet_ledger_signing_error");let{r:X,s:C,v:B}=G;return _.from({...T,signature:{r:`0x${X}`,s:`0x${C}`,v:Number(BigInt(B))}}).serialized}}var gL=(L)=>new q({...L,chainId:$.ChainId.Arbitrum}),kL=(L)=>new q({...L,chainId:$.ChainId.Aurora}),lL=(L)=>new q({...L,chainId:$.ChainId.Avalanche}),VL=(L)=>new q({...L,chainId:$.ChainId.Base}),EL=(L)=>new q({...L,chainId:$.ChainId.Ethereum}),IL=(L)=>new q({...L,chainId:$.ChainId.Gnosis}),vL=(L)=>new q({...L,chainId:$.ChainId.Optimism}),hL=(L)=>new q({...L,chainId:$.ChainId.Polygon}),oL=(L)=>new q({...L,chainId:$.ChainId.BinanceSmartChain}),dL=(L)=>new q({...L,chainId:$.ChainId.Monad}),bL=(L)=>new q({...L,chainId:$.ChainId.XLayer}),xL=(L)=>new q({...L,chainId:$.ChainId.Berachain});async function iL(L){let _=(await import("@ledgerhq/hw-app-near")).default,{Chain:y,NetworkDerivationPath:T,SwapKitError:w}=await import("@swapkit/helpers"),R=await Y(),O=new _(R),G=(L||T[y.Near]).join("'/").concat("'"),{address:X,publicKey:C}=await O.getAddress(G);return{getAddress(){return Promise.resolve(X)},async getPublicKey(){let{PublicKey:D}=await import("@near-js/crypto");return D.fromString(`ed25519:${C}`)},signDelegateAction(D){return Promise.reject(new w("wallet_ledger_method_not_supported",{method:"signDelegateAction",wallet:"Ledger"}))},signNep413Message(D,W,Q,Z,F){return Promise.reject(new w("wallet_ledger_method_not_supported",{method:"signNep413Message",wallet:"Ledger"}))},async signTransaction(D){let{Signature:W,SignedTransaction:Q}=await import("@near-js/transactions");try{let Z=await O.signTransaction(D.encode(),G);if(!Z)throw Error("Signature undefined");let F=new W({data:Z,keyType:0}),J=new Q({signature:F,transaction:D});return[Z,J]}catch(Z){throw new w("wallet_ledger_signing_error",{error:Z})}}}}var H=require("@swapkit/helpers");class nL{derivationPath;ledgerApp=null;address=null;publicKey=null;constructor(L){this.derivationPath=typeof L==="string"?L:H.derivationPathToString(L||H.NetworkDerivationPath[H.Chain.Sui])}getLedgerPath(){return this.derivationPath.replace(/^m\//,"").replace(/\/(\d+)\/(\d+)$/,"/$1'/$2'")}async createTransportAndLedger(){if(this.ledgerApp)return;let L=await Y(),_=(await import("@ledgerhq/hw-app-sui")).default;this.ledgerApp=new _(L)}async connect(){if(await this.createTransportAndLedger(),!this.ledgerApp)throw new H.SwapKitError("wallet_ledger_transport_error");let L=this.getLedgerPath(),_=await this.ledgerApp.getPublicKey(L);if(!_?.publicKey)throw new H.SwapKitError("wallet_ledger_failed_to_get_address");return this.publicKey=_.publicKey,this.address=`0x${Buffer.from(_.address).toString("hex")}`,this.address}toSuiAddress(){if(!this.address)throw new H.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 _=L instanceof Uint8Array?L:L.transaction;if(await this.createTransportAndLedger(),!this.ledgerApp)throw new H.SwapKitError("wallet_ledger_transport_error");if(!this.publicKey)throw new H.SwapKitError("wallet_ledger_failed_to_get_address");try{let y=this.getLedgerPath(),T=new Uint8Array(3+_.length);T[0]=0,T[1]=0,T[2]=0,T.set(_,3);let w=await this.ledgerApp.signTransaction(y,T);if(!w?.signature)throw new H.SwapKitError("wallet_ledger_signing_error");let R=this.publicKey.length===33?this.publicKey.slice(1):this.publicKey;if(R.length!==32)throw new H.SwapKitError("wallet_ledger_signing_error",{error:"Invalid public key length"});let O=new Uint8Array(97);O[0]=0,O.set(w.signature,1),O.set(R,65);let G=Buffer.from(O).toString("base64");return{bytes:Buffer.from(_).toString("base64"),signature:G}}catch(y){throw new H.SwapKitError("wallet_ledger_signing_error",{error:y})}}}var tL=(L)=>new nL(L);var eL=require("@scure/base"),TL=require("@swapkit/helpers");var uL=require("@scure/base"),k=require("@swapkit/helpers"),ZL=(L)=>{if(L.length<64)throw new k.SwapKitError("wallet_ledger_invalid_signature",{reason:"Too short"});if(L[0]!==48)throw new k.SwapKitError("wallet_ledger_invalid_signature",{reason:"TLV encoding: expected first byte 0x30"});if(L[1]+2!==L.length)throw new k.SwapKitError("wallet_ledger_invalid_signature",{reason:"signature length does not match TLV"});if(L[2]!==2)throw new k.SwapKitError("wallet_ledger_invalid_signature",{reason:"TLV encoding: expected length type 0x02"});let _=L[3],y=L.slice(4,_+4);if(y.length===33&&y[0]===0)y=y.slice(1,33);else if(y.length===33)throw new k.SwapKitError("wallet_ledger_invalid_signature",{reason:"r too long"});while(y.length<32)y.unshift(0);if(L[_+4]!==2)throw new k.SwapKitError("wallet_ledger_invalid_signature",{reason:"TLV encoding: expected length type 0x02 for s"});let T=L[_+5];if(4+_+2+T!==L.length)throw new k.SwapKitError("wallet_ledger_invalid_signature",{reason:"TLV byte lengths do not match message length"});let w=L.slice(_+6,L.length);if(w.length===33&&w[0]===0)w=w.slice(1,33);else if(w.length===33)throw new k.SwapKitError("wallet_ledger_invalid_signature",{reason:"s too long"});while(w.length<32)w.unshift(0);if(y.length!==32||w.length!==32)throw new k.SwapKitError("wallet_ledger_invalid_signature",{reason:"must be 32 bytes each"});return uL.base64.encode(Buffer.concat([y,w]))};class ML extends wL{pubKey=null;derivationPath;constructor(L=TL.NetworkDerivationPath.THOR){super();this.chain="thor",this.derivationPath=L}get pubkey(){return this.pubKey}connect=async()=>{await this.checkOrCreateTransportAndLedger();let{compressed_pk:L,bech32_address:_}=await this.getAddressAndPubKey();return this.pubKey=eL.base64.encode(L),_};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,_="0")=>{await this.checkOrCreateTransportAndLedger(!0);let{return_code:y,error_message:T,signature:w}=await this.ledgerApp.sign(this.derivationPath,L);if(!this.pubKey)throw new TL.SwapKitError("wallet_ledger_pubkey_not_found");return this.validateResponse(y,T),[{pub_key:{type:"tendermint/PubKeySecp256k1",value:this.pubKey},sequence:_,signature:ZL(w)}]};sign=async(L)=>{await this.checkOrCreateTransportAndLedger(!0);let{return_code:_,error_message:y,signature:T}=await this.ledgerApp.sign(this.derivationPath,L);if(!this.pubKey)throw new TL.SwapKitError("wallet_ledger_pubkey_not_found");return this.validateResponse(_,y),ZL(T)}}var l=require("@swapkit/helpers");class pL{derivationPath;ledgerApp=null;ledgerTimeout=50000;constructor(L){this.derivationPath=typeof L==="string"?L:l.derivationPathToString(L||l.NetworkDerivationPath.TRON)}checkOrCreateTransportAndLedger=async()=>{if(this.ledgerApp)return;await this.createTransportAndLedger()};createTransportAndLedger=async()=>{let L=await Y(),_=(await import("@ledgerhq/hw-app-trx")).default;this.ledgerApp=new _(L)};getAddress=async()=>{let L=await this.getAddressAndPubKey();if(!L)throw new l.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 l.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 l.SwapKitError("wallet_ledger_transport_error");let _=JSON.stringify(L);try{let y=await this.ledgerApp.signTransaction(this.derivationPath,_,[]);if(!y)throw new l.SwapKitError("wallet_ledger_signing_error");return{...L,signature:[y]}}catch(y){throw new l.SwapKitError("wallet_ledger_signing_error",{error:y})}}}var aL=(L)=>new pL(L);var mL=require("@scure/base"),I=require("@swapkit/helpers");var sL=["bitcoin-cash","dash","dogecoin","zcash"],rL=({tx:L,inputUtxos:_,btcApp:y,derivationPath:T,chain:w},R)=>{let O=_.map((D)=>{return[y.splitTransaction(D.txHex||"",!sL.includes(w),w==="zcash"),D.index,void 0,void 0]}),G=mL.hex.encode(L.unsignedTx),X=y.splitTransaction(G,!0),C=y.serializeTransactionOutputs(X).toString("hex"),B={additionals:["bech32"],associatedKeysets:O.map(()=>T),inputs:O,outputScriptHex:C,segwit:!0,useTrustedInputForSegwit:!0};return y.createPaymentTransaction({...B,...R})},f0=({tx:L,inputUtxos:_,btcApp:y,derivationPaths:T,chain:w},R)=>{if(T.length!==_.length)throw new I.SwapKitError("wallet_ledger_invalid_params",{message:`Derivation paths count (${T.length}) must match inputs count (${_.length})`});let O=_.map((D)=>{return[y.splitTransaction(D.txHex||"",!sL.includes(w),w==="zcash"),D.index,void 0,void 0]}),G=mL.hex.encode(L.unsignedTx),X=y.splitTransaction(G,!0),C=y.serializeTransactionOutputs(X).toString("hex"),B={additionals:["bech32"],associatedKeysets:T,inputs:O,outputScriptHex:C,segwit:!0,useTrustedInputForSegwit:!0};return y.createPaymentTransaction({...B,...R})},t=({chain:L,additionalSignParams:_})=>{let y,T=null;async function w(O=!0){if(O&&!y)new I.SwapKitError("wallet_ledger_connection_error",{message:`Ledger connection failed:
2
+ ${JSON.stringify({btcApp:y,checkBtcApp:O})}`});T||=await Y()}async function R(){T=await Y(),y=new(await import("@ledgerhq/hw-app-btc")).default({currency:L,transport:T})}return(O)=>{let G=typeof O==="string"?O:I.derivationPathToString(O),X=I.getWalletFormatFor(G);return{connect:async()=>{await w(!1),y=new(await import("@ledgerhq/hw-app-btc")).default({currency:L,transport:T})},getAddress:async()=>{let{toCashAddress:C}=await import("@swapkit/toolboxes/utxo");await w(!1);let{bitcoinAddress:B}=await y.getWalletPublicKey(G,{format:X});if(!B)throw new I.SwapKitError("wallet_ledger_get_address_error",{message:`Cannot get ${L} address from ledger derivation path: ${G}`});return L==="bitcoin-cash"&&X==="legacy"?C(B).replace(/(bchtest:|bitcoincash:)/,""):B},getExtendedPublicKey:async(C="84'/0'/0'",B=76067358)=>{return await w(!1),y.getWalletXpub({path:C,xpubVersion:B})},signPCZT:async(C)=>{if(L!=="zcash")throw new I.SwapKitError("wallet_ledger_chain_not_supported",{message:"PCZT signing is only supported for Zcash"});await R();let{ZcashTransaction:B,Script:D}=await import("@swapkit/utxo-signer"),W=C.getGlobal(),Q=new B({consensusBranchId:W.consensusBranchId,expiryHeight:W.expiryHeight,lockTime:W.lockTime,version:W.txVersion,versionGroupId:W.versionGroupId}),Z=[];for(let f=0;f<C.inputsLength;f++){let A=C.getInput(f);Q.addInput({index:A.index,script:new Uint8Array,sequence:A.sequence??4294967295,txid:A.txid,value:A.value}),Z.push({hash:mL.hex.encode(new Uint8Array([...A.txid].reverse())),index:A.index,txHex:j0(A,W),value:Number(A.value),witnessUtxo:{script:A.scriptPubkey,value:Number(A.value)}})}for(let f=0;f<C.outputsLength;f++){let A=C.getOutput(f);Q.addOutput({amount:A.value,script:A.scriptPubkey})}let F=await rL({btcApp:y,chain:L,derivationPath:G,inputUtxos:Z,tx:Q},{..._,expiryHeight:(()=>{let f=Buffer.alloc(4);return f.writeUInt32LE(W.expiryHeight),f})(),lockTime:W.lockTime}),J=B.fromHex(F,{allowUnknownOutputs:!0}),U=C.clone();for(let f=0;f<J.inputsLength;f++){let A=J.getInput(f);if(A.script&&A.script.length>0){let c=D.decode(A.script);if(c.length>=2)U.addSignature(f,c[1],c[0])}}return U},signTransaction:async(C,B)=>{return await R(),rL({btcApp:y,chain:L,derivationPath:G,inputUtxos:B,tx:C},_)},signTransactionWithMultiplePaths:async(C,B,D)=>{return await R(),f0({btcApp:y,chain:L,derivationPaths:D,inputUtxos:B,tx:C},_)}}}};function j0(L,_){let y=[],T=(_.txVersion|2147483648)>>>0;y.push(T&255,T>>8&255,T>>16&255,T>>24&255);let w=_.versionGroupId;y.push(w&255,w>>8&255,w>>16&255,w>>24&255),y.push(0);let R=L.index+1;if(R<253)y.push(R);else y.push(253,R&255,R>>8&255);for(let X=0;X<L.index;X++)y.push(0,0,0,0,0,0,0,0),y.push(0);let O=L.value;y.push(Number(O&0xffn),Number(O>>8n&0xffn),Number(O>>16n&0xffn),Number(O>>24n&0xffn),Number(O>>32n&0xffn),Number(O>>40n&0xffn),Number(O>>48n&0xffn),Number(O>>56n&0xffn));let G=L.scriptPubkey;if(G.length<253)y.push(G.length);else y.push(253,G.length&255,G.length>>8&255);for(let X of G)y.push(X);return y.push(_.lockTime&255,_.lockTime>>8&255,_.lockTime>>16&255,_.lockTime>>24&255),y.push(_.expiryHeight&255,_.expiryHeight>>8&255,_.expiryHeight>>16&255,_.expiryHeight>>24&255),y.push(0,0,0,0,0,0,0,0),y.push(0),y.push(0),y.push(0),mL.hex.encode(new Uint8Array(y))}var L0=t({chain:"bitcoin"}),_0=t({chain:"litecoin"}),y0=t({additionalSignParams:{additionals:["abc"],segwit:!1,sigHashType:65},chain:"bitcoin-cash"}),w0=t({additionalSignParams:{additionals:[],segwit:!1,useTrustedInputForSegwit:!1},chain:"dogecoin"}),T0=t({additionalSignParams:{additionals:[],segwit:!1,useTrustedInputForSegwit:!1},chain:"dash"}),m0=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 R0=A0(require("@ledgerhq/hw-app-xrp")),u=require("@swapkit/helpers"),QL=require("ripple-binary-codec");var W0=2147483648;function $0(L){let _={};for(let y in L)if(L[y]!==null&&L[y]!==void 0)_[y]=L[y];return _}function J0(L){return new R0.default(L)}var O0=async(L)=>{let _=u.derivationPathToString(L||u.NetworkDerivationPath[u.Chain.Ripple]),y=await Y(),T=J0(y),{address:w,publicKey:R}=await T.getAddress(_);async function O(G){let{hashes:X}=await import("@swapkit/toolboxes/ripple"),B={...$0(G),Flags:G.Flags||W0,SigningPubKey:R.toUpperCase()},D=QL.encode(B),W=await T.signTransaction(_,D),Q=QL.encode({...B,TxnSignature:W});return{hash:X.hashSignedTx(Q),tx_blob:Q}}return{getAddress:()=>w,signTransaction:O}};var P=async({chain:L,derivationPath:_})=>{let{match:y}=await import("ts-pattern");return y(L).returnType().with(N.Chain.THORChain,()=>Promise.resolve(new ML(_))).with(N.Chain.Cosmos,()=>Promise.resolve(new UL(_))).with(N.Chain.Bitcoin,()=>Promise.resolve(L0(_))).with(N.Chain.BitcoinCash,()=>Promise.resolve(y0(_))).with(N.Chain.Dash,()=>Promise.resolve(T0(_))).with(N.Chain.Dogecoin,()=>Promise.resolve(w0(_))).with(N.Chain.Litecoin,()=>Promise.resolve(_0(_))).with(N.Chain.Zcash,()=>Promise.resolve(m0(_))).with(N.Chain.Ripple,()=>Promise.resolve(O0(_))).with(N.Chain.Tron,()=>Promise.resolve(aL(_))).with(N.Chain.Sui,()=>Promise.resolve(tL(_))).with(N.Chain.Near,()=>{return Promise.resolve(iL(_))}).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"),w={derivationPath:_,provider:await T(L)};return y(L).with(N.Chain.BinanceSmartChain,()=>oL(w)).with(N.Chain.Avalanche,()=>lL(w)).with(N.Chain.Arbitrum,()=>gL(w)).with(N.Chain.Berachain,()=>xL(w)).with(N.Chain.Optimism,()=>vL(w)).with(N.Chain.Polygon,()=>hL(w)).with(N.Chain.Base,()=>VL(w)).with(N.Chain.Aurora,()=>kL(w)).with(N.Chain.Gnosis,()=>IL(w)).with(N.Chain.Monad,()=>dL(w)).with(N.Chain.XLayer,()=>bL(w)).otherwise(()=>EL(w))}).otherwise(()=>{throw new N.SwapKitError("wallet_chain_not_supported",{chain:L,wallet:N.WalletOption.LEDGER})})};var G0=DL.createWallet({connect:({addChain:L,supportedChains:_,walletType:y})=>async function(w,R){let[O]=m.filterSupportedChains({chains:w,supportedChains:_,walletType:y});if(!O)return!1;let G=R??m.NetworkDerivationPath[O],X=await H0({chain:O,derivationPath:G});return L({...X,chain:O,walletType:m.WalletOption.LEDGER}),!0},directSigningSupport:{[m.Chain.Arbitrum]:!0,[m.Chain.Aurora]:!0,[m.Chain.Avalanche]:!0,[m.Chain.Base]:!0,[m.Chain.Berachain]:!0,[m.Chain.BinanceSmartChain]:!0,[m.Chain.Ethereum]:!0,[m.Chain.Gnosis]:!0,[m.Chain.Monad]:!0,[m.Chain.Bitcoin]:!0,[m.Chain.BitcoinCash]:!0,[m.Chain.Cosmos]:!0,[m.Chain.Dash]:!0,[m.Chain.Dogecoin]:!0,[m.Chain.Litecoin]:!0,[m.Chain.Near]:!0,[m.Chain.Optimism]:!0,[m.Chain.Polygon]:!0,[m.Chain.Ripple]:!0,[m.Chain.Sui]:!0,[m.Chain.Tron]:!0,[m.Chain.XLayer]:!0},name:"connectLedger",supportedChains:[m.Chain.Arbitrum,m.Chain.Aurora,m.Chain.Avalanche,m.Chain.Base,m.Chain.Berachain,m.Chain.BinanceSmartChain,m.Chain.Bitcoin,m.Chain.BitcoinCash,m.Chain.Cosmos,m.Chain.Dash,m.Chain.Dogecoin,m.Chain.Ethereum,m.Chain.Gnosis,m.Chain.Litecoin,m.Chain.Monad,m.Chain.Near,m.Chain.Optimism,m.Chain.Polygon,m.Chain.Ripple,m.Chain.Sui,m.Chain.THORChain,m.Chain.XLayer,m.Chain.Tron,m.Chain.Zcash],walletType:m.WalletOption.LEDGER}),M0=DL.getWalletSupportedChains(G0);function Q0(L,_="t"){if(!L?.includes("=:"))return L;let y=L.includes(`:${_}:`)?L.split(`:${_}:`)[0]:L;return y?.substring(0,y.lastIndexOf(":"))}function NL(L){if(Array.isArray(L))return L.forEach((T,w)=>{L[w]=NL(T)}),L;if(typeof L!=="object")return L;let _={},y=Object.keys(L).sort();for(let T of y)_[T]=NL(L[T]);return _}function Y0(L){return JSON.stringify(NL(L))}async function H0({chain:L,derivationPath:_}){switch(L){case m.Chain.BitcoinCash:case m.Chain.Bitcoin:case m.Chain.Dash:case m.Chain.Dogecoin:case m.Chain.Litecoin:case m.Chain.Zcash:{let B=function(){return C()},{getUtxoToolbox:y}=await import("@swapkit/toolboxes/utxo"),T=L,w=await P({chain:L,derivationPath:_}),R=await V({chain:L,ledgerClient:w}),O;if(L===m.Chain.Bitcoin||L===m.Chain.Litecoin){let{BitcoinPsbtLedger:F,LitecoinPsbtLedger:J}=await import("../chunk-x85da57j.js"),U=L===m.Chain.Bitcoin?F(_):J(_);O={getAddress:U.getAddress,signTransaction:U.signTransaction}}else if(L===m.Chain.BitcoinCash||L===m.Chain.Dogecoin||L===m.Chain.Dash){let{createLegacyPsbtSigner:F}=await import("../chunk-mrsfcest.js");O=F({address:R,chain:T,legacyClient:w})}let G=O?await y(T,{signer:O}):y(T),X=async(F)=>{let J=F.feeRate||(await G.getFeeRates())[m.FeeOption.Average],U=[m.Chain.Bitcoin].includes(L)?F.memo:Q0(F.memo),{tx:f,inputs:A}=await G.createTransaction({...F,feeRate:J,fetchTxHex:!0,memo:U,sender:R}),c=await w.signTransaction(f,A);return await G.broadcastTx(c)};async function C({accountIndex:F}={}){if(!w.getExtendedPublicKey)return;let J=M.getUTXOAccountPath({accountIndex:F,chain:T,derivationPath:_}),U=m.derivationPathToString(J),f=L===m.Chain.Bitcoin||L===m.Chain.Litecoin?U:U.replace(/^m\//,""),A=await w.getExtendedPublicKey(f);return{accountIndex:M.getUTXOAccountIndexFromPath(J),path:U,xpub:A}}async function D({accountIndex:F,index:J,change:U=!1}){try{let f=M.getUTXOAddressPath({accountIndex:F,chain:T,change:U,derivationPath:_,index:J}),A=await P({chain:T,derivationPath:f}),c=await V({chain:T,ledgerClient:A});return{accountIndex:M.getUTXOAccountIndexFromPath(f),address:c,change:U,index:J,path:m.derivationPathToString(f),pubkey:""}}catch{return}}async function W({accountIndex:F,count:J,startIndex:U=0,change:f=!1}){return M.assertDerivationIndex("count",J),M.assertDerivationIndex("startIndex",U),(await Promise.all(Array.from({length:J},(c,v)=>D({accountIndex:F,change:f,index:U+v})))).filter((c)=>!!c)}let Q=M.createHDWalletHelpers({chain:T,deriveAddress:D,getBalance:G.getBalance,getUtxos:(F)=>M.getUtxoApi(T).getUtxos({address:F,fetchTxHex:!0})});async function Z({utxos:F,recipient:J,assetValue:U,memo:f,feeRate:A,feeOptionKey:c,changeAddress:v}){if(!F.length)throw new m.SwapKitError("wallet_ledger_invalid_params",{message:"No UTXOs provided for multi-address transfer"});let YL=A||(await G.getFeeRates())[c||m.FeeOption.Fast],RL=f?M.compileMemo(f):null,z=[{address:J,value:U.getBaseValue("number")}];if(RL)z.push({script:RL,value:0});let OL=F.map(({hash:b,index:x,value:r,txHex:s,witnessUtxo:LL})=>({hash:b,index:x,txHex:s,value:r,witnessUtxo:LL})),{inputs:d,outputs:e}=G.accumulative({chain:T,feeRate:YL,inputs:OL,outputs:z});if(!(d&&e))throw new m.SwapKitError("wallet_ledger_connection_error",{message:"Insufficient balance for multi-address transfer"});let{Transaction:FL}=await import("@swapkit/utxo-signer"),GL=new FL({allowLegacyWitnessUtxo:!0,version:1}),p=v||F[0]?.address||J;M.addInputsAndOutputs({chain:T,compiledMemo:RL,inputs:d,outputs:e,sender:p,tx:GL});let CL=M.getUTXOAccountPath({chain:T,derivationPath:_}),fL=d.map((b)=>{let x=F.find((BL)=>BL.hash===b.hash&&BL.index===b.index),r=x?.derivationIndex??0,s=x?.isChange??!1,LL=[...CL,Number(s),r];return m.derivationPathToString(LL)});if(!w.signTransactionWithMultiplePaths)throw new m.SwapKitError("wallet_ledger_method_not_supported",{method:"signTransactionWithMultiplePaths"});let a=await w.signTransactionWithMultiplePaths(GL,d,fL);return G.broadcastTx(a)}return{...G,...Q,address:R,deriveAddressAtIndex:D,deriveAddresses:W,getExtendedPublicKey:B,getExtendedPublicKeyInfo:C,transfer:X,transferFromMultipleAddresses:Z}}case m.Chain.Ethereum:case m.Chain.Avalanche:case m.Chain.Arbitrum:case m.Chain.Berachain:case m.Chain.Optimism:case m.Chain.Polygon:case m.Chain.BinanceSmartChain:case m.Chain.Base:case m.Chain.Aurora:case m.Chain.Gnosis:case m.Chain.Monad:case m.Chain.XLayer:{let{getEvmToolboxAsync:y}=await import("@swapkit/toolboxes/evm"),T=await P({chain:L,derivationPath:_}),w=await V({chain:L,ledgerClient:T});return{...await y(L,{signer:T}),address:w}}case m.Chain.Cosmos:{let{createSigningStargateClient:y,getMsgSendDenom:T,getCosmosToolbox:w}=await import("@swapkit/toolboxes/cosmos"),R=await P({chain:L,derivationPath:_}),O=await V({chain:L,ledgerClient:R});return{...await w(m.Chain.Cosmos,{signer:R}),address:O,transfer:async({assetValue:C,recipient:B,memo:D})=>{if(!C)throw new m.SwapKitError("wallet_ledger_invalid_asset");let W={amount:[{amount:C.getBaseValue("string"),denom:T(`u${C.symbol}`).toLowerCase()}],fromAddress:O,toAddress:B},Q=await m.getRPCUrl(L),Z=await y(Q,R,"0.007uatom"),{transactionHash:F}=await Z.signAndBroadcast(O,[{typeUrl:"/cosmos.bank.v1beta1.MsgSend",value:W}],2,D);return F}}}case m.Chain.THORChain:{let{SignMode:y}=await import("cosmjs-types/cosmos/tx/signing/v1beta1/signing.js"),{TxRaw:T}=await import("cosmjs-types/cosmos/tx/v1beta1/tx.js"),w=await import("@cosmjs/proto-signing"),R=w.encodePubkey??w.default?.encodePubkey,O=w.makeAuthInfoBytes??w.default?.makeAuthInfoBytes,{createStargateClient:G,buildEncodedTxBody:X,getCosmosToolbox:C,buildAminoMsg:B,getDefaultChainFee:D,fromBase64:W,parseAminoMessageForDirectSigning:Q}=await import("@swapkit/toolboxes/cosmos"),Z=C(L),F=await P({chain:L,derivationPath:_}),J=await V({chain:L,ledgerClient:F}),U=D(L),{pubkey:f,signTransaction:A,sign:c}=F,v=async({memo:z="",assetValue:OL,...d})=>{let e=await Z.getAccount(J);if(!e)throw new m.SwapKitError("wallet_ledger_invalid_account");if(!OL)throw new m.SwapKitError("wallet_ledger_invalid_asset");if(!f)throw new m.SwapKitError("wallet_ledger_pubkey_not_found");let{accountNumber:FL,sequence:GL}=e,p=(GL||0).toString(),CL=NL([B({assetValue:OL,memo:z,sender:J,...d})]),fL=Y0({account_number:FL?.toString(),chain_id:m.THORConfig.chainId,fee:U,memo:z,msgs:CL,sequence:p}),a=await A(fL,p);if(!a)throw new m.SwapKitError("wallet_ledger_signing_error");let b=R({type:"tendermint/PubKeySecp256k1",value:f}),x=CL.map(Q),r=await X({chain:L,memo:z,msgs:x}),s=O([{pubkey:b,sequence:Number(p)}],U.amount,Number.parseInt(U.gas,10),void 0,void 0,y.SIGN_MODE_LEGACY_AMINO_JSON),LL=a?.[0]?.signature?W(a[0].signature):Uint8Array.from([]),BL=T.fromPartial({authInfoBytes:s,bodyBytes:r,signatures:[LL]}),C0=T.encode(BL).finish(),B0=await m.getRPCUrl(m.Chain.THORChain),X0=await G(B0),{transactionHash:N0}=await X0.broadcastTx(C0);return N0};return{...Z,address:J,deposit:(z)=>v(z),signMessage:c,transfer:(z)=>v(z)}}case m.Chain.Near:{let{getNearToolbox:y}=await import("@swapkit/toolboxes/near"),T=await P({chain:L,derivationPath:_}),w=await T.getAddress();return{...y({signer:T}),address:w}}case m.Chain.Ripple:{let{getRippleToolbox:y}=await import("@swapkit/toolboxes/ripple"),T=await P({chain:L,derivationPath:_}),w=T.getAddress();return{...y({signer:T}),address:w}}case m.Chain.Tron:{let{getTronToolbox:y}=await import("@swapkit/toolboxes/tron"),T=await P({chain:L,derivationPath:_}),w=await V({chain:L,ledgerClient:T});return{...y({signer:T}),address:w}}case m.Chain.Sui:{let{getSuiToolbox:y}=await import("@swapkit/toolboxes/sui"),T=await P({chain:L,derivationPath:_}),w=await V({chain:L,ledgerClient:T});return{...y({signer:T}),address:w}}default:throw new m.SwapKitError("wallet_ledger_chain_not_supported",{chain:L})}}
3
3
 
4
- //# debugId=B741DA28F592D77364756E2164756E21
4
+ //# debugId=ECB9CE3992D70D7C64756E2164756E21
5
5
  //# sourceMappingURL=index.cjs.map