@swapkit/wallet-hardware 4.1.23 → 4.1.24

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,4 +1,4 @@
1
- import{b as z}from"./chunk-7fsaymh4.js";import"./chunk-zn26fh3j.js";import{Chain as W,DerivationPath as X,derivationPathToString as Y}from"@swapkit/helpers";import{getRippleToolbox as Z}from"@swapkit/toolboxes/ripple";var w=async({sdk:E,derivationPath:F})=>{let G=F?Y(F):`${X[W.Ripple]}/0`,{address:j}=await E.address.xrpGetAddress({address_n:z(G)}),y=await Z({signer:{getAddress:()=>Promise.resolve(j),signTransaction:()=>{throw Error("signTransaction not supported via toolbox")}}});return{...y,address:j,getAddress:()=>j,transfer:async({recipient:I,assetValue:M,memo:q})=>{let f=await y.createTransaction({assetValue:M,memo:q,recipient:I,sender:j}),O={type:"auth/StdTx",value:{fee:{amount:[{amount:"1000",denom:"drop"}],gas:"28000"},memo:q&&q.length>0?q:"",msg:[{type:"ripple-sdk/MsgSend",value:{amount:[{amount:f.Amount,denom:"drop"}],from_address:j,to_address:I}}],signatures:null}},Q={addressNList:z(G),flags:f.Flags===0?void 0:f.Flags,lastLedgerSequence:f.LastLedgerSequence?.toString(),payment:{amount:f.Amount,destination:f.Destination,destinationTag:(f.DestinationTag??"0").toString()},sequence:(f.Sequence??0).toString(),tx:O},J=JSON.parse(await E.xrp.xrpSignTransaction(Q)),K=J.tx_blob??J.value?.signatures?.[0]?.serializedTx;if(!K)throw Error("KeepKey XRP sign failed");let U=Buffer.from(K,"base64").toString("hex");return y.broadcastTransaction(U)}}};export{w as rippleWalletMethods};
1
+ import{b as z}from"./chunk-7fsaymh4.js";import"./chunk-zzfbcc7e.js";import{Chain as W,DerivationPath as X,derivationPathToString as Y}from"@swapkit/helpers";import{getRippleToolbox as Z}from"@swapkit/toolboxes/ripple";var w=async({sdk:E,derivationPath:F})=>{let G=F?Y(F):`${X[W.Ripple]}/0`,{address:j}=await E.address.xrpGetAddress({address_n:z(G)}),y=await Z({signer:{getAddress:()=>Promise.resolve(j),signTransaction:()=>{throw Error("signTransaction not supported via toolbox")}}});return{...y,address:j,getAddress:()=>j,transfer:async({recipient:I,assetValue:M,memo:q})=>{let f=await y.createTransaction({assetValue:M,memo:q,recipient:I,sender:j}),O={type:"auth/StdTx",value:{fee:{amount:[{amount:"1000",denom:"drop"}],gas:"28000"},memo:q&&q.length>0?q:"",msg:[{type:"ripple-sdk/MsgSend",value:{amount:[{amount:f.Amount,denom:"drop"}],from_address:j,to_address:I}}],signatures:null}},Q={addressNList:z(G),flags:f.Flags===0?void 0:f.Flags,lastLedgerSequence:f.LastLedgerSequence?.toString(),payment:{amount:f.Amount,destination:f.Destination,destinationTag:(f.DestinationTag??"0").toString()},sequence:(f.Sequence??0).toString(),tx:O},J=JSON.parse(await E.xrp.xrpSignTransaction(Q)),K=J.tx_blob??J.value?.signatures?.[0]?.serializedTx;if(!K)throw Error("KeepKey XRP sign failed");let U=Buffer.from(K,"base64").toString("hex");return y.broadcastTransaction(U)}}};export{w as rippleWalletMethods};
2
2
 
3
3
  //# debugId=B9E7C62A7E5CA45F64756E2164756E21
4
- //# sourceMappingURL=chunk-90868b2r.js.map
4
+ //# sourceMappingURL=chunk-37bgpz1y.js.map
@@ -1,4 +1,4 @@
1
- import{c as M,d as Q}from"./chunk-zn26fh3j.js";import{ChainId as G,derivationPathToString as $,SwapKitError as q,SwapKitNumber as w,WalletOption as E}from"@swapkit/helpers";async function l({chain:W,derivationPath:k,provider:N}){let{AbstractSigner:C,Signature:f}=await import("ethers");class Y extends C{address;chain;derivationPath;provider;constructor({chain:j,derivationPath:B,provider:D}){super(D);this.address="",this.chain=j,this.derivationPath=B,this.provider=D}getAddress=async()=>{if(!this.address){let B=await(await import("@trezor/connect-web")).default.ethereumGetAddress({path:$(this.derivationPath),showOnTrezor:!0});if(!B.success)throw new q({errorKey:"wallet_trezor_failed_to_get_address",info:{...B,chain:this.chain,derivationPath:this.derivationPath}});this.address=B.payload.address}return this.address};signMessage=async(j)=>{let D=await(await import("@trezor/connect-web")).default.ethereumSignMessage({message:j,path:$(this.derivationPath)});if(!D.success)throw new q({errorKey:"wallet_trezor_failed_to_sign_transaction",info:{...D,chain:this.chain,derivationPath:this.derivationPath,message:j}});return D.payload.signature};signTypedData(){throw new q("wallet_trezor_method_not_supported",{method:"signTypedData"})}signTransaction=async({to:j,gasLimit:B,value:D,data:_,nonce:H,maxFeePerGas:U,maxPriorityFeePerGas:V,gasPrice:X})=>{if(!j)throw new q({errorKey:"wallet_missing_params",info:{to:j}});if(!B)throw new q({errorKey:"wallet_missing_params",info:{gasLimit:B}});let R=U&&V;if(R&&!U)throw new q({errorKey:"wallet_missing_params",info:{maxFeePerGas:U}});if(R&&!V)throw new q({errorKey:"wallet_missing_params",info:{maxPriorityFeePerGas:V}});if(!(R||X))throw new q({errorKey:"wallet_missing_params",info:{gasPrice:X}});let I=(await import("@trezor/connect-web")).default,{toHexString:J}=await import("@swapkit/toolboxes/evm"),{Transaction:L}=await import("ethers"),b=R?{maxFeePerGas:J(BigInt(U?.toString()||0)),maxPriorityFeePerGas:J(BigInt(V?.toString()||0))}:X&&{gasPrice:J(BigInt(X?.toString()||0))}||{gasPrice:"0x0"},z=J(BigInt(H||await this.provider.getTransactionCount(await this.getAddress(),"pending"))),Z={chainId:Number.parseInt(G[this.chain],10),data:_?.toString()||"0x",gasLimit:J(BigInt(B?.toString()||0)),nonce:z,to:j.toString(),value:J(BigInt(D?.toString()||0)),...b},{success:u,payload:A}=await I.ethereumSignTransaction({path:$(this.derivationPath),transaction:Z});if(!u)throw new q({errorKey:"wallet_trezor_failed_to_sign_transaction",info:{...A,chain:this.chain,derivationPath:this.derivationPath}});let{r:K,s:y,v:T}=A,h=f.from({r:K,s:y,v:new w(BigInt(T)).getBaseValue("number")}),O=L.from({...Z,nonce:Number.parseInt(Z.nonce,16),signature:h,type:R?2:0}).serialized;if(!O)throw new q({errorKey:"wallet_trezor_failed_to_sign_transaction",info:{chain:this.chain,derivationPath:this.derivationPath}});return O};connect=(j)=>{if(!j)throw new q({errorKey:"wallet_provider_not_found",info:{chain:this.chain,derivationPath:this.derivationPath,wallet:E.TREZOR}});return new Y({chain:this.chain,derivationPath:this.derivationPath,provider:j})}}return new Y({chain:W,derivationPath:k,provider:N})}export{l as getEVMSigner};
1
+ import{c as M,d as Q}from"./chunk-zzfbcc7e.js";import{ChainId as G,derivationPathToString as $,SwapKitError as q,SwapKitNumber as w,WalletOption as E}from"@swapkit/helpers";async function l({chain:W,derivationPath:k,provider:N}){let{AbstractSigner:C,Signature:f}=await import("ethers");class Y extends C{address;chain;derivationPath;provider;constructor({chain:j,derivationPath:B,provider:D}){super(D);this.address="",this.chain=j,this.derivationPath=B,this.provider=D}getAddress=async()=>{if(!this.address){let B=await(await import("@trezor/connect-web")).default.ethereumGetAddress({path:$(this.derivationPath),showOnTrezor:!0});if(!B.success)throw new q({errorKey:"wallet_trezor_failed_to_get_address",info:{...B,chain:this.chain,derivationPath:this.derivationPath}});this.address=B.payload.address}return this.address};signMessage=async(j)=>{let D=await(await import("@trezor/connect-web")).default.ethereumSignMessage({message:j,path:$(this.derivationPath)});if(!D.success)throw new q({errorKey:"wallet_trezor_failed_to_sign_transaction",info:{...D,chain:this.chain,derivationPath:this.derivationPath,message:j}});return D.payload.signature};signTypedData(){throw new q("wallet_trezor_method_not_supported",{method:"signTypedData"})}signTransaction=async({to:j,gasLimit:B,value:D,data:_,nonce:H,maxFeePerGas:U,maxPriorityFeePerGas:V,gasPrice:X})=>{if(!j)throw new q({errorKey:"wallet_missing_params",info:{to:j}});if(!B)throw new q({errorKey:"wallet_missing_params",info:{gasLimit:B}});let R=U&&V;if(R&&!U)throw new q({errorKey:"wallet_missing_params",info:{maxFeePerGas:U}});if(R&&!V)throw new q({errorKey:"wallet_missing_params",info:{maxPriorityFeePerGas:V}});if(!(R||X))throw new q({errorKey:"wallet_missing_params",info:{gasPrice:X}});let I=(await import("@trezor/connect-web")).default,{toHexString:J}=await import("@swapkit/toolboxes/evm"),{Transaction:L}=await import("ethers"),b=R?{maxFeePerGas:J(BigInt(U?.toString()||0)),maxPriorityFeePerGas:J(BigInt(V?.toString()||0))}:X&&{gasPrice:J(BigInt(X?.toString()||0))}||{gasPrice:"0x0"},z=J(BigInt(H||await this.provider.getTransactionCount(await this.getAddress(),"pending"))),Z={chainId:Number.parseInt(G[this.chain],10),data:_?.toString()||"0x",gasLimit:J(BigInt(B?.toString()||0)),nonce:z,to:j.toString(),value:J(BigInt(D?.toString()||0)),...b},{success:u,payload:A}=await I.ethereumSignTransaction({path:$(this.derivationPath),transaction:Z});if(!u)throw new q({errorKey:"wallet_trezor_failed_to_sign_transaction",info:{...A,chain:this.chain,derivationPath:this.derivationPath}});let{r:K,s:y,v:T}=A,h=f.from({r:K,s:y,v:new w(BigInt(T)).getBaseValue("number")}),O=L.from({...Z,nonce:Number.parseInt(Z.nonce,16),signature:h,type:R?2:0}).serialized;if(!O)throw new q({errorKey:"wallet_trezor_failed_to_sign_transaction",info:{chain:this.chain,derivationPath:this.derivationPath}});return O};connect=(j)=>{if(!j)throw new q({errorKey:"wallet_provider_not_found",info:{chain:this.chain,derivationPath:this.derivationPath,wallet:E.TREZOR}});return new Y({chain:this.chain,derivationPath:this.derivationPath,provider:j})}}return new Y({chain:W,derivationPath:k,provider:N})}export{l as getEVMSigner};
2
2
 
3
3
  //# debugId=593C12C12DDBEF4D64756E2164756E21
4
- //# sourceMappingURL=chunk-3044kn2k.js.map
4
+ //# sourceMappingURL=chunk-takg8b37.js.map
@@ -1,5 +1,5 @@
1
1
  var g=Object.create;var{getPrototypeOf:h,defineProperty:f,getOwnPropertyNames:i}=Object;var j=Object.prototype.hasOwnProperty;var k=(a,c,b)=>{b=a!=null?g(h(a)):{};let d=c||!a||!a.__esModule?f(b,"default",{value:a,enumerable:!0}):b;for(let e of i(a))if(!j.call(d,e))f(d,e,{get:()=>a[e],enumerable:!0});return d};var l=((a)=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(a,{get:(c,b)=>(typeof require<"u"?require:c)[b]}):a)(function(a){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+a+'" is not supported')});
2
2
  export{k as c,l as d};
3
3
 
4
- //# debugId=831D6160C3B78A9D64756E2164756E21
5
- //# sourceMappingURL=chunk-zn26fh3j.js.map
4
+ //# debugId=B199D22A6B72ED5764756E2164756E21
5
+ //# sourceMappingURL=chunk-zzfbcc7e.js.map
@@ -4,6 +4,6 @@
4
4
  "sourcesContent": [
5
5
  ],
6
6
  "mappings": "",
7
- "debugId": "831D6160C3B78A9D64756E2164756E21",
7
+ "debugId": "B199D22A6B72ED5764756E2164756E21",
8
8
  "names": []
9
9
  }
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import"./chunk-zn26fh3j.js";var c=void 0;export{c as default};
1
+ import"./chunk-zzfbcc7e.js";var c=void 0;export{c as default};
2
2
 
3
3
  //# debugId=6A33823FB1BB3FA564756E2164756E21
4
4
  //# sourceMappingURL=index.js.map
@@ -1,4 +1,4 @@
1
- import{a as k,b as E}from"../chunk-7fsaymh4.js";import{c as F,d as b}from"../chunk-zn26fh3j.js";import{KeepKeySdk as _z}from"@keepkey/keepkey-sdk";import{Chain as Q,filterSupportedChains as Nz,NetworkDerivationPath as Hz,SKConfig as P,SwapKitError as Oz,WalletOption as r}from"@swapkit/helpers";import{createWallet as Dz,getWalletSupportedChains as Iz}from"@swapkit/wallet-core";import{Chain as g,ChainId as l,DerivationPath as i,derivationPathToString as a,getRPCUrl as e}from"@swapkit/helpers";async function m({sdk:z,derivationPath:J}){let{DEFAULT_COSMOS_FEE_MAINNET:X,getCosmosToolbox:O,getFeeRateFromSwapKit:$,createStargateClient:q}=await import("@swapkit/toolboxes/cosmos"),U=J?a(J):`${i.GAIA}/0`,{address:Z}=await z.address.cosmosGetAddress({address_n:E(U)}),j=await O(g.Cosmos);if(X.amount[0])X.amount[0].amount=String(await $(l.GAIA,500));return{...j,address:Z,transfer:async({assetValue:_,recipient:Y,memo:G})=>{let D=_.getBaseValue("string"),B=await j.getAccount(Z),W=await z.cosmos.cosmosSignAmino({signDoc:{account_number:B?.accountNumber.toString()??"",chain_id:l.GAIA,fee:X,memo:G||"",msgs:[{type:"cosmos-sdk/MsgSend",value:{amount:[{amount:D,denom:"uatom"}],from_address:Z,to_address:Y}}],sequence:B?.sequence.toString()??""},signerAddress:Z}),N=atob(W.serialized),H=new Uint8Array(N.length).map((V,w)=>N.charCodeAt(w)),L=await e(g.Cosmos);return(await(await q(L)).broadcastTx(H)).transactionHash}}}import{ChainId as zz,derivationPathToString as Jz,NetworkDerivationPath as Qz,SwapKitError as K}from"@swapkit/helpers";import{AbstractSigner as Xz}from"ethers";class T extends Xz{sdk;chain;derivationPath;address;provider;constructor({sdk:z,chain:J,derivationPath:X,provider:O}){super();this.sdk=z,this.chain=J,this.derivationPath=X||Qz.ETH,this.address="",this.provider=O}signTypedData(){throw new K("wallet_keepkey_method_not_supported",{method:"signTypedData"})}getAddress=async()=>{if(this.address)return this.address;let{address:z}=await this.sdk.address.ethereumGetAddress({address_n:E(Jz(this.derivationPath))});return this.address=z,z};signMessage=(z)=>this.sdk.eth.ethSign({address:this.address,message:z});signTransaction=async({to:z,value:J,gasLimit:X,nonce:O,data:$,maxFeePerGas:q,maxPriorityFeePerGas:U,gasPrice:Z})=>{if(!z)throw new K("wallet_keepkey_invalid_params",{reason:"Missing to address"});if(!X)throw new K("wallet_keepkey_invalid_params",{reason:"Missing gasLimit"});if(!$)throw new K("wallet_keepkey_invalid_params",{reason:"Missing data"});let j=!!((q||U)&&!Z);if(j&&!q)throw new K("wallet_keepkey_invalid_params",{reason:"Missing maxFeePerGas"});if(j&&!U)throw new K("wallet_keepkey_invalid_params",{reason:"Missing maxPriorityFeePerGas"});if(!(j||Z))throw new K("wallet_keepkey_invalid_params",{reason:"Missing gasPrice"});let{toHexString:R}=await import("@swapkit/toolboxes/evm"),_=O?BigInt(O):BigInt(await this.provider.getTransactionCount(await this.getAddress(),"pending")),Y={addressNList:[2147483692,2147483708,2147483648,0,0],chainId:R(BigInt(zz[this.chain])),data:$,from:this.address,gas:R(BigInt(X)),nonce:R(_),to:z.toString(),value:R(BigInt(J||0)),...j&&{maxFeePerGas:R(BigInt(q?.toString()||"0")),maxPriorityFeePerGas:R(BigInt(U?.toString()||"0"))},...!j&&{gasPrice:R(BigInt(Z?.toString()||"0"))}};return(await this.sdk.eth.ethSignTransaction(Y)).serialized};sendTransaction=async(z)=>{if(!this.provider)throw new K("wallet_keepkey_no_provider");let J=await this.signTransaction(z);return await this.provider.broadcastTransaction(J)};connect=(z)=>new T({chain:this.chain,derivationPath:this.derivationPath,provider:z,sdk:this.sdk})}import{Chain as u,ChainId as Yz,DerivationPath as Zz,derivationPathToString as $z,getRPCUrl as p,SwapKitError as qz}from"@swapkit/helpers";async function c({sdk:z,derivationPath:J}){let{createStargateClient:X,getCosmosToolbox:O}=await import("@swapkit/toolboxes/cosmos"),$=await O(u.Maya),q=J?$z(J):`${Zz.MAYA}/0`,{address:U}=await z.address.mayachainGetAddress({address_n:E(q)}),Z=async({assetValue:_,recipient:Y,sender:G,memo:D})=>{let B=await import("@cosmjs/amino"),W=B.makeSignDoc??B.default?.makeSignDoc,{getDenomWithChain:N}=await import("@swapkit/toolboxes/cosmos"),H=await $.getAccount(G);if(!H)throw new qz("wallet_keepkey_account_not_found");let{accountNumber:L,sequence:I=0}=H,M=_.getBaseValue("string"),V=Y&&Y!=="",w=V?{type:"mayachain/MsgSend",value:{amount:[{amount:M,denom:_.symbol.toLowerCase()}],from_address:G,to_address:Y}}:{type:"mayachain/MsgDeposit",value:{coins:[{amount:M,asset:N(_)}],memo:D,signer:G}},f=W([w],{amount:[],gas:"500000000"},Yz.MAYA,D,L?.toString(),I),y=await(V?z.mayachain.mayachainSignAminoTransfer:z.mayachain.mayachainSignAminoDeposit)({signDoc:f,signerAddress:G}),v=atob(y.serialized);return new Uint8Array(v.length).map((C,t)=>v.charCodeAt(t))};return{...$,address:U,deposit:async({assetValue:_,memo:Y})=>{let G=await p(u.Maya),D=await X(G),B=await Z({assetValue:_,memo:Y,sender:U}),{transactionHash:W}=await D.broadcastTx(B);return W},transfer:async({assetValue:_,recipient:Y,memo:G})=>{let D=await p(u.Maya),B=await X(D),W=await Z({assetValue:_,memo:G,recipient:Y,sender:U}),{transactionHash:N}=await B.broadcastTx(W);return N}}}import{Chain as S,ChainId as jz,DerivationPath as Bz,derivationPathToString as Rz,getRPCUrl as h,SwapKitError as Gz}from"@swapkit/helpers";async function d({sdk:z,derivationPath:J}){let X=await import("@cosmjs/amino"),O=X.makeSignDoc??X.default?.makeSignDoc,{buildAminoMsg:$,getDefaultChainFee:q,createStargateClient:U,getCosmosToolbox:Z}=await import("@swapkit/toolboxes/cosmos"),j=await Z(S.THORChain),R=J?Rz(J):`${Bz.THOR}/0`,{address:_}=await z.address.thorchainGetAddress({address_n:E(R)}),Y=async({assetValue:B,recipient:W,sender:N,memo:H})=>{let L=await j.getAccount(N);if(!L)throw new Gz("wallet_keepkey_account_not_found");let{accountNumber:I,sequence:M=0}=L,V=W&&W!=="",w=$({assetValue:B,memo:H,recipient:W,sender:N}),f=O([w],q(S.THORChain),jz.THOR,H,I?.toString(),M),A=V?await z.thorchain.thorchainSignAminoTransfer({signDoc:f,signerAddress:N}):await z.thorchain.thorchainSignAminoDeposit({signDoc:f,signerAddress:N}),y=atob(A.serialized);return new Uint8Array(y.length).map((v,C)=>y.charCodeAt(C))};return{...j,address:_,deposit:async({assetValue:B,memo:W})=>{let N=await h(S.THORChain),H=await U(N),L=await Y({assetValue:B,memo:W,sender:_}),{transactionHash:I}=await H.broadcastTx(L);return I},transfer:async({assetValue:B,recipient:W,memo:N})=>{let H=await h(S.THORChain),L=await U(H),I=await Y({assetValue:B,memo:N,recipient:W,sender:_}),{transactionHash:M}=await L.broadcastTx(I);return M}}}import{Chain as x,DerivationPath as Wz,derivationPathToString as Lz,FeeOption as Uz,SwapKitError as o}from"@swapkit/helpers";var n=async({sdk:z,chain:J,derivationPath:X})=>{let{getUtxoToolbox:O}=await import("@swapkit/toolboxes/utxo"),$=await O(J),q=[x.Bitcoin,x.Litecoin].includes(J)?"p2wpkh":"p2pkh",U=X?Lz(X):`${Wz[J]}/0`,Z={address_n:E(U),coin:k[J],script_type:q},j=(await z.address.utxoGetAddress(Z)).address,R=async(Y,G,D="")=>{let B=Y.txOutputs.map((H)=>{let{value:L,address:I,change:M}=H,V=J===x.BitcoinCash?$.stripToCashAddress(I):I;if(M||I===j)return{addressNList:Z.address_n,addressType:"change",amount:L,isChange:!0,scriptType:q};if(V)return{address:V,addressType:"spend",amount:L};return null}).filter(Boolean),W=(H)=>{return H.filter((L)=>L!==null&&typeof L==="object"&&Object.keys(L).length>0)};return(await z.utxo.utxoSignTransaction({coin:k[J],inputs:G,opReturnData:D,outputs:W(B)})).serializedTx?.toString()};return{...$,address:j,signTransaction:R,transfer:async({recipient:Y,feeOptionKey:G,feeRate:D,memo:B,...W})=>{if(!j)throw new o("wallet_keepkey_invalid_params",{reason:"From address must be provided"});if(!Y)throw new o("wallet_keepkey_invalid_params",{reason:"Recipient address must be provided"});let N=J===x.BitcoinCash?$.buildTx:$.createTransaction,{psbt:H,inputs:L}=await N({...W,feeRate:D||(await $.getFeeRates())[G||Uz.Fast],fetchTxHex:!0,memo:B,recipient:Y,sender:j}),I=L.map(({value:V,index:w,hash:f,txHex:A})=>({addressNList:Z.address_n,amount:V.toString(),hex:A||"",scriptType:q,txid:f,vout:w})),M=await R(H,I,B);return $.broadcastTx(M)}}};var Mz=Dz({connect:({addChain:z,supportedChains:J,walletType:X})=>async function($,q){let U=Nz({chains:$,supportedChains:J,walletType:X}),Z=P.get("integrations").keepKey;if(!Z)throw Error("KeepKey config not found");let j=P.get("apiKeys").keepKey||"1234";await s();let R={apiKey:j,pairingInfo:Z},_=await _z.create(R);if(R.apiKey&&R.apiKey!==j)P.setApiKey("keepKey",R.apiKey);return await Promise.all(U.map(async(Y)=>{let G=await Vz({chain:Y,derivationPath:q?.[Y]||Hz[Y],sdk:_}),D=await G.getAddress()||"";z({...G,address:D,chain:Y,walletType:r.KEEPKEY})})),!0},name:"connectKeepkey",supportedChains:[Q.Arbitrum,Q.Avalanche,Q.Base,Q.BinanceSmartChain,Q.Bitcoin,Q.BitcoinCash,Q.Cosmos,Q.Dogecoin,Q.Dash,Q.Ethereum,Q.Litecoin,Q.Ripple,Q.Optimism,Q.Polygon,Q.THORChain,Q.Maya],walletType:r.KEEPKEY}),rz=Iz(Mz);async function Vz({sdk:z,chain:J,derivationPath:X}){let{getProvider:O,getEvmToolbox:$}=await import("@swapkit/toolboxes/evm");switch(J){case Q.BinanceSmartChain:case Q.Arbitrum:case Q.Optimism:case Q.Polygon:case Q.Avalanche:case Q.Base:case Q.Ethereum:{let q=await O(J),U=new T({chain:J,derivationPath:X,provider:q,sdk:z});return await $(J,{provider:q,signer:U})}case Q.Cosmos:return m({derivationPath:X,sdk:z});case Q.THORChain:return d({derivationPath:X,sdk:z});case Q.Maya:return c({derivationPath:X,sdk:z});case Q.Bitcoin:case Q.BitcoinCash:case Q.Dash:case Q.Dogecoin:case Q.Litecoin:return n({chain:J,derivationPath:X,sdk:z});case Q.Ripple:{let{rippleWalletMethods:q}=await import("../chunk-90868b2r.js");return q({derivationPath:X,sdk:z})}default:throw new Oz("wallet_keepkey_chain_not_supported",{chain:J})}}async function s(z=0){if(z>=3)alert("KeepKey desktop is required for keepkey-sdk, please go to https://keepkey.com/get-started");if(!await Fz())window.location.assign("keepkey://launch"),await new Promise((X)=>setTimeout(X,30000)),await s(z+1)}async function Fz(z="http://localhost:1646/spec/swagger.json"){try{return(await fetch(z)).status===200}catch(J){return!1}}export{Mz as keepkeyWallet,rz as KEEPKEY_SUPPORTED_CHAINS};
1
+ import{a as k,b as E}from"../chunk-7fsaymh4.js";import{c as F,d as b}from"../chunk-zzfbcc7e.js";import{KeepKeySdk as _z}from"@keepkey/keepkey-sdk";import{Chain as Q,filterSupportedChains as Nz,NetworkDerivationPath as Hz,SKConfig as P,SwapKitError as Oz,WalletOption as r}from"@swapkit/helpers";import{createWallet as Dz,getWalletSupportedChains as Iz}from"@swapkit/wallet-core";import{Chain as g,ChainId as l,DerivationPath as i,derivationPathToString as a,getRPCUrl as e}from"@swapkit/helpers";async function m({sdk:z,derivationPath:J}){let{DEFAULT_COSMOS_FEE_MAINNET:X,getCosmosToolbox:O,getFeeRateFromSwapKit:$,createStargateClient:q}=await import("@swapkit/toolboxes/cosmos"),U=J?a(J):`${i.GAIA}/0`,{address:Z}=await z.address.cosmosGetAddress({address_n:E(U)}),j=await O(g.Cosmos);if(X.amount[0])X.amount[0].amount=String(await $(l.GAIA,500));return{...j,address:Z,transfer:async({assetValue:_,recipient:Y,memo:G})=>{let D=_.getBaseValue("string"),B=await j.getAccount(Z),W=await z.cosmos.cosmosSignAmino({signDoc:{account_number:B?.accountNumber.toString()??"",chain_id:l.GAIA,fee:X,memo:G||"",msgs:[{type:"cosmos-sdk/MsgSend",value:{amount:[{amount:D,denom:"uatom"}],from_address:Z,to_address:Y}}],sequence:B?.sequence.toString()??""},signerAddress:Z}),N=atob(W.serialized),H=new Uint8Array(N.length).map((V,w)=>N.charCodeAt(w)),L=await e(g.Cosmos);return(await(await q(L)).broadcastTx(H)).transactionHash}}}import{ChainId as zz,derivationPathToString as Jz,NetworkDerivationPath as Qz,SwapKitError as K}from"@swapkit/helpers";import{AbstractSigner as Xz}from"ethers";class T extends Xz{sdk;chain;derivationPath;address;provider;constructor({sdk:z,chain:J,derivationPath:X,provider:O}){super();this.sdk=z,this.chain=J,this.derivationPath=X||Qz.ETH,this.address="",this.provider=O}signTypedData(){throw new K("wallet_keepkey_method_not_supported",{method:"signTypedData"})}getAddress=async()=>{if(this.address)return this.address;let{address:z}=await this.sdk.address.ethereumGetAddress({address_n:E(Jz(this.derivationPath))});return this.address=z,z};signMessage=(z)=>this.sdk.eth.ethSign({address:this.address,message:z});signTransaction=async({to:z,value:J,gasLimit:X,nonce:O,data:$,maxFeePerGas:q,maxPriorityFeePerGas:U,gasPrice:Z})=>{if(!z)throw new K("wallet_keepkey_invalid_params",{reason:"Missing to address"});if(!X)throw new K("wallet_keepkey_invalid_params",{reason:"Missing gasLimit"});if(!$)throw new K("wallet_keepkey_invalid_params",{reason:"Missing data"});let j=!!((q||U)&&!Z);if(j&&!q)throw new K("wallet_keepkey_invalid_params",{reason:"Missing maxFeePerGas"});if(j&&!U)throw new K("wallet_keepkey_invalid_params",{reason:"Missing maxPriorityFeePerGas"});if(!(j||Z))throw new K("wallet_keepkey_invalid_params",{reason:"Missing gasPrice"});let{toHexString:R}=await import("@swapkit/toolboxes/evm"),_=O?BigInt(O):BigInt(await this.provider.getTransactionCount(await this.getAddress(),"pending")),Y={addressNList:[2147483692,2147483708,2147483648,0,0],chainId:R(BigInt(zz[this.chain])),data:$,from:this.address,gas:R(BigInt(X)),nonce:R(_),to:z.toString(),value:R(BigInt(J||0)),...j&&{maxFeePerGas:R(BigInt(q?.toString()||"0")),maxPriorityFeePerGas:R(BigInt(U?.toString()||"0"))},...!j&&{gasPrice:R(BigInt(Z?.toString()||"0"))}};return(await this.sdk.eth.ethSignTransaction(Y)).serialized};sendTransaction=async(z)=>{if(!this.provider)throw new K("wallet_keepkey_no_provider");let J=await this.signTransaction(z);return await this.provider.broadcastTransaction(J)};connect=(z)=>new T({chain:this.chain,derivationPath:this.derivationPath,provider:z,sdk:this.sdk})}import{Chain as u,ChainId as Yz,DerivationPath as Zz,derivationPathToString as $z,getRPCUrl as p,SwapKitError as qz}from"@swapkit/helpers";async function c({sdk:z,derivationPath:J}){let{createStargateClient:X,getCosmosToolbox:O}=await import("@swapkit/toolboxes/cosmos"),$=await O(u.Maya),q=J?$z(J):`${Zz.MAYA}/0`,{address:U}=await z.address.mayachainGetAddress({address_n:E(q)}),Z=async({assetValue:_,recipient:Y,sender:G,memo:D})=>{let B=await import("@cosmjs/amino"),W=B.makeSignDoc??B.default?.makeSignDoc,{getDenomWithChain:N}=await import("@swapkit/toolboxes/cosmos"),H=await $.getAccount(G);if(!H)throw new qz("wallet_keepkey_account_not_found");let{accountNumber:L,sequence:I=0}=H,M=_.getBaseValue("string"),V=Y&&Y!=="",w=V?{type:"mayachain/MsgSend",value:{amount:[{amount:M,denom:_.symbol.toLowerCase()}],from_address:G,to_address:Y}}:{type:"mayachain/MsgDeposit",value:{coins:[{amount:M,asset:N(_)}],memo:D,signer:G}},f=W([w],{amount:[],gas:"500000000"},Yz.MAYA,D,L?.toString(),I),y=await(V?z.mayachain.mayachainSignAminoTransfer:z.mayachain.mayachainSignAminoDeposit)({signDoc:f,signerAddress:G}),v=atob(y.serialized);return new Uint8Array(v.length).map((C,t)=>v.charCodeAt(t))};return{...$,address:U,deposit:async({assetValue:_,memo:Y})=>{let G=await p(u.Maya),D=await X(G),B=await Z({assetValue:_,memo:Y,sender:U}),{transactionHash:W}=await D.broadcastTx(B);return W},transfer:async({assetValue:_,recipient:Y,memo:G})=>{let D=await p(u.Maya),B=await X(D),W=await Z({assetValue:_,memo:G,recipient:Y,sender:U}),{transactionHash:N}=await B.broadcastTx(W);return N}}}import{Chain as S,ChainId as jz,DerivationPath as Bz,derivationPathToString as Rz,getRPCUrl as h,SwapKitError as Gz}from"@swapkit/helpers";async function d({sdk:z,derivationPath:J}){let X=await import("@cosmjs/amino"),O=X.makeSignDoc??X.default?.makeSignDoc,{buildAminoMsg:$,getDefaultChainFee:q,createStargateClient:U,getCosmosToolbox:Z}=await import("@swapkit/toolboxes/cosmos"),j=await Z(S.THORChain),R=J?Rz(J):`${Bz.THOR}/0`,{address:_}=await z.address.thorchainGetAddress({address_n:E(R)}),Y=async({assetValue:B,recipient:W,sender:N,memo:H})=>{let L=await j.getAccount(N);if(!L)throw new Gz("wallet_keepkey_account_not_found");let{accountNumber:I,sequence:M=0}=L,V=W&&W!=="",w=$({assetValue:B,memo:H,recipient:W,sender:N}),f=O([w],q(S.THORChain),jz.THOR,H,I?.toString(),M),A=V?await z.thorchain.thorchainSignAminoTransfer({signDoc:f,signerAddress:N}):await z.thorchain.thorchainSignAminoDeposit({signDoc:f,signerAddress:N}),y=atob(A.serialized);return new Uint8Array(y.length).map((v,C)=>y.charCodeAt(C))};return{...j,address:_,deposit:async({assetValue:B,memo:W})=>{let N=await h(S.THORChain),H=await U(N),L=await Y({assetValue:B,memo:W,sender:_}),{transactionHash:I}=await H.broadcastTx(L);return I},transfer:async({assetValue:B,recipient:W,memo:N})=>{let H=await h(S.THORChain),L=await U(H),I=await Y({assetValue:B,memo:N,recipient:W,sender:_}),{transactionHash:M}=await L.broadcastTx(I);return M}}}import{Chain as x,DerivationPath as Wz,derivationPathToString as Lz,FeeOption as Uz,SwapKitError as o}from"@swapkit/helpers";var n=async({sdk:z,chain:J,derivationPath:X})=>{let{getUtxoToolbox:O}=await import("@swapkit/toolboxes/utxo"),$=await O(J),q=[x.Bitcoin,x.Litecoin].includes(J)?"p2wpkh":"p2pkh",U=X?Lz(X):`${Wz[J]}/0`,Z={address_n:E(U),coin:k[J],script_type:q},j=(await z.address.utxoGetAddress(Z)).address,R=async(Y,G,D="")=>{let B=Y.txOutputs.map((H)=>{let{value:L,address:I,change:M}=H,V=J===x.BitcoinCash?$.stripToCashAddress(I):I;if(M||I===j)return{addressNList:Z.address_n,addressType:"change",amount:L,isChange:!0,scriptType:q};if(V)return{address:V,addressType:"spend",amount:L};return null}).filter(Boolean),W=(H)=>{return H.filter((L)=>L!==null&&typeof L==="object"&&Object.keys(L).length>0)};return(await z.utxo.utxoSignTransaction({coin:k[J],inputs:G,opReturnData:D,outputs:W(B)})).serializedTx?.toString()};return{...$,address:j,signTransaction:R,transfer:async({recipient:Y,feeOptionKey:G,feeRate:D,memo:B,...W})=>{if(!j)throw new o("wallet_keepkey_invalid_params",{reason:"From address must be provided"});if(!Y)throw new o("wallet_keepkey_invalid_params",{reason:"Recipient address must be provided"});let N=J===x.BitcoinCash?$.buildTx:$.createTransaction,{psbt:H,inputs:L}=await N({...W,feeRate:D||(await $.getFeeRates())[G||Uz.Fast],fetchTxHex:!0,memo:B,recipient:Y,sender:j}),I=L.map(({value:V,index:w,hash:f,txHex:A})=>({addressNList:Z.address_n,amount:V.toString(),hex:A||"",scriptType:q,txid:f,vout:w})),M=await R(H,I,B);return $.broadcastTx(M)}}};var Mz=Dz({connect:({addChain:z,supportedChains:J,walletType:X})=>async function($,q){let U=Nz({chains:$,supportedChains:J,walletType:X}),Z=P.get("integrations").keepKey;if(!Z)throw Error("KeepKey config not found");let j=P.get("apiKeys").keepKey||"1234";await s();let R={apiKey:j,pairingInfo:Z},_=await _z.create(R);if(R.apiKey&&R.apiKey!==j)P.setApiKey("keepKey",R.apiKey);return await Promise.all(U.map(async(Y)=>{let G=await Vz({chain:Y,derivationPath:q?.[Y]||Hz[Y],sdk:_}),D=await G.getAddress()||"";z({...G,address:D,chain:Y,walletType:r.KEEPKEY})})),!0},name:"connectKeepkey",supportedChains:[Q.Arbitrum,Q.Avalanche,Q.Base,Q.BinanceSmartChain,Q.Bitcoin,Q.BitcoinCash,Q.Cosmos,Q.Dogecoin,Q.Dash,Q.Ethereum,Q.Litecoin,Q.Ripple,Q.Optimism,Q.Polygon,Q.THORChain,Q.Maya],walletType:r.KEEPKEY}),rz=Iz(Mz);async function Vz({sdk:z,chain:J,derivationPath:X}){let{getProvider:O,getEvmToolbox:$}=await import("@swapkit/toolboxes/evm");switch(J){case Q.BinanceSmartChain:case Q.Arbitrum:case Q.Optimism:case Q.Polygon:case Q.Avalanche:case Q.Base:case Q.Ethereum:{let q=await O(J),U=new T({chain:J,derivationPath:X,provider:q,sdk:z});return await $(J,{provider:q,signer:U})}case Q.Cosmos:return m({derivationPath:X,sdk:z});case Q.THORChain:return d({derivationPath:X,sdk:z});case Q.Maya:return c({derivationPath:X,sdk:z});case Q.Bitcoin:case Q.BitcoinCash:case Q.Dash:case Q.Dogecoin:case Q.Litecoin:return n({chain:J,derivationPath:X,sdk:z});case Q.Ripple:{let{rippleWalletMethods:q}=await import("../chunk-37bgpz1y.js");return q({derivationPath:X,sdk:z})}default:throw new Oz("wallet_keepkey_chain_not_supported",{chain:J})}}async function s(z=0){if(z>=3)alert("KeepKey desktop is required for keepkey-sdk, please go to https://keepkey.com/get-started");if(!await Fz())window.location.assign("keepkey://launch"),await new Promise((X)=>setTimeout(X,30000)),await s(z+1)}async function Fz(z="http://localhost:1646/spec/swagger.json"){try{return(await fetch(z)).status===200}catch(J){return!1}}export{Mz as keepkeyWallet,rz as KEEPKEY_SUPPORTED_CHAINS};
2
2
 
3
3
  //# debugId=75C40C0BF28A6BE764756E2164756E21
4
4
  //# sourceMappingURL=index.js.map
@@ -1,4 +1,4 @@
1
- import{c as X,d as F}from"../chunk-zn26fh3j.js";import{Chain as w,ChainId as S0,FeeOption as K0,filterSupportedChains as I0,getRPCUrl as bL,SwapKitError as V,WalletOption as vL}from"@swapkit/helpers";import{createWallet as E0,getWalletSupportedChains as V0}from"@swapkit/wallet-core";import{Chain as l,SwapKitError as m0,WalletOption as y0}from"@swapkit/helpers";var P=async({chain:L,ledgerClient:T})=>{if(!T)return"";switch(L){case l.Cosmos:case l.THORChain:return T.connect();case l.Ethereum:case l.BinanceSmartChain:case l.Avalanche:case l.Polygon:case l.Arbitrum:case l.Optimism:case l.Base:case l.Aurora:case l.Gnosis:return T.getAddress();case l.Bitcoin:case l.BitcoinCash:case l.Dash:case l.Dogecoin:case l.Litecoin:case l.Zcash:{let _=T;await _.connect();let y=await _.getAddress();return L===l.BitcoinCash?y.replace("bitcoincash:",""):y}case l.Near:return await T.getAddress();case l.Ripple:return T.getAddress();case l.Tron:return T.getAddress();default:throw new m0("wallet_chain_not_supported",{chain:L,wallet:y0.LEDGER})}};import{Chain as W,SwapKitError as P0,WalletOption as g0}from"@swapkit/helpers";import{derivationPathToString as C0,NetworkDerivationPath as B0,SwapKitError as JL}from"@swapkit/helpers";import{LedgerErrorCode as r,NetworkDerivationPath as w0,SwapKitError as LL}from"@swapkit/helpers";import{SwapKitError as lL}from"@swapkit/helpers";var K=85,n=250;var g={GET_ADDR_SECP256K1:4,GET_VERSION:0,INS_PUBLIC_KEY_SECP256K1:1,SIGN_SECP256K1:2},h={ADD:1,INIT:0,LAST:2},p={ONLY_RETRIEVE:0,SHOW_ADDRESS_IN_DEVICE:1},I={JSON:0},D={NoError:36864},CL={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 H(L){if(L in CL)return CL[L];return`Unknown Status Code: ${L}`}function O0(L){return typeof L==="object"&&L!==null&&!Array.isArray(L)&&!(L instanceof Date)}function f(L){if(L){if(O0(L)){if(Object.hasOwn(L,"statusCode"))return{error_message:H(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 a(L){return L.send(85,g.GET_VERSION,0,0).then((T)=>{let _=T.slice(-2),y=_[0]*256+_[1],m=0;if(T.length>=9)m=(T[5]<<24)+(T[6]<<16)+(T[7]<<8)+(T[8]<<0);return{device_locked:T[4]===1,error_message:H(y),major:T[1],minor:T[2],patch:T[3],return_code:y,target_id:m.toString(16),test_mode:T[0]!==0}},f)}import{SwapKitError as d}from"@swapkit/helpers";function BL(L){if(L==null||L.length<3)throw new d("wallet_ledger_invalid_params",{reason:"Path too short"});if(L.length>10)throw new d("wallet_ledger_invalid_params",{reason:"Path too long"});let T=Buffer.alloc(1+4*L.length);T.writeUInt8(L.length,0);for(let _=0;_<L.length;_+=1){let y=L[_]||0;if(_<3)y|=2147483648;T.writeInt32LE(y,1+_*4)}return T}function s(L,T,_,y,m=I.JSON){return L.transport.send(K,g.SIGN_SECP256K1,T,m,y,[D.NoError,27012,27264]).then((O)=>{let R=O.slice(-2),G=R[0]*256+R[1],C=H(G);if(G===27264||G===27012)C=`${C} : ${O.slice(0,O.length-2).toString("ascii")}`;let B=null;if(O.length>2)B=O.slice(0,O.length-2);return{error_message:C,return_code:G,signature:B}},f)}function G0(L){if(L.length!==65)throw new d("wallet_ledger_invalid_params",{reason:"decompressed public key length should be 65 bytes"});let T=L.slice(33,65),_=Buffer.from([2+(T[T.length-1]&1)]);return Buffer.concat([_,L.slice(1,33)])}function XL(L,T){return L.transport.send(K,g.INS_PUBLIC_KEY_SECP256K1,0,0,T,[D.NoError]).then((_)=>{let y=_.slice(-2),m=y[0]*256+y[1],O=Buffer.from(_.slice(0,65));return{compressed_pk:G0(O),error_message:H(m),pk:O,return_code:m}},f)}function FL(L){if(!L||L.length!==5)throw new d("wallet_ledger_invalid_params",{reason:"Path must be exactly 5 elements"});let T=Buffer.alloc(20);return T.writeUInt32LE(2147483648+L[0],0),T.writeUInt32LE(2147483648+L[1],4),T.writeUInt32LE(2147483648+L[2],8),T.writeUInt32LE(L[3],12),T.writeUInt32LE(L[4],16),T}function ZL(L,T,_,y,m=I.JSON){let O=h.ADD;if(T===1)O=h.INIT;if(T===_)O=h.LAST;return s(L,O,0,y,m)}function WL(L,T){return L.transport.send(K,g.GET_ADDR_SECP256K1,0,0,T,[D.NoError]).then((_)=>{let y=_.slice(-2),m=y[0]*256+y[1];return{compressed_pk:Buffer.from(_.slice(0,33)),error_message:H(m),pk:"OBSOLETE PROPERTY",return_code:m}},f)}class c{transport;versionResponse;constructor(L){if(!L)throw new lL("wallet_ledger_transport_not_defined");this.transport=L}static serializeHRP(L){if(L==null||L.length<3||L.length>83)throw new lL("wallet_ledger_invalid_params",{reason:"Invalid HRP"});let T=Buffer.alloc(1+L.length);return T.writeUInt8(L.length,0),T.write(L,1),T}async serializePath(L){if(this.versionResponse=await a(this.transport),this.versionResponse.return_code!==D.NoError)throw this.versionResponse;switch(this.versionResponse.major){case 1:return BL(L);case 2:return FL(L);default:return Buffer.alloc(0)}}async signGetChunks(L,T){let _=await this.serializePath(L),y=[];y.push(_);for(let m=0;m<T.length;m+=n){let O=m+n;if(m>T.length)O=T.length;y.push(T.slice(m,O))}return y}async getVersion(){try{return this.versionResponse=await a(this.transport),this.versionResponse}catch(L){return f(L)}}appInfo(){return this.transport.send(176,1,0,0).then((L)=>{let T=L.slice(-2),_=T[0]*256+T[1],y="",m="",O=0,R=0;if(L[0]!==1)return{error_message:"response format ID not recognized",return_code:36865};let G=L[1];y=L.slice(2,2+G).toString("ascii");let C=2+G,B=L[C];C+=1,m=L.slice(C,C+B).toString("ascii"),C+=B;let Z=L[C];return C+=1,O=Z,R=L[C],{appName:y,appVersion:m,error_message:H(_),flag_onboarded:(R&4)!==0,flag_pin_validated:(R&128)!==0,flag_recovery:(R&1)!==0,flag_signed_mcu_code:(R&2)!==0,flagLen:O,flagsValue:R,return_code:_}},f)}deviceInfo(){return this.transport.send(224,1,0,0,Buffer.from([]),[D.NoError,28160]).then((L)=>{let T=L.slice(-2),_=T[0]*256+T[1];if(_===28160)return{error_message:"This command is only available in the Dashboard",return_code:_};let y=L.slice(0,4).toString("hex"),m=4,O=L[m];m+=1;let R=L.slice(m,m+O).toString();m+=O;let G=L[m];m+=1;let C=L.slice(m,m+G).toString("hex");m+=G;let B=L[m];m+=1;let Z=L.slice(m,m+B);if(Z[B-1]===0)Z=L.slice(m,m+B-1);let $=Z.toString();return{error_message:H(_),flag:C,mcuVersion:$,return_code:_,seVersion:R,targetId:y}},f)}async publicKey(L){try{let T=await this.serializePath(L);switch(this.versionResponse.major){case 1:return XL(this,T);case 2:{let _=Buffer.concat([c.serializeHRP("thor"),T]);return WL(this,_)}default:return{error_message:"App Version is not supported",return_code:25600}}}catch(T){return f(T)}}getAddressAndPubKey(L,T,_=!1){return this.serializePath(L).then((y)=>{let m=Buffer.concat([c.serializeHRP(T),y]);return this.transport.send(K,g.GET_ADDR_SECP256K1,_?p.SHOW_ADDRESS_IN_DEVICE:p.ONLY_RETRIEVE,0,m,[D.NoError]).then((O)=>{let R=O.slice(-2),G=R[0]*256+R[1],C=Buffer.from(O.slice(0,33));return{bech32_address:Buffer.from(O.slice(33,-2)).toString(),compressed_pk:C,error_message:H(G),return_code:G}},f)}).catch((y)=>f(y))}showAddressAndPubKey(L,T){return this.getAddressAndPubKey(L,T,!0)}signSendChunk(L,T,_,y=I.JSON){switch(this.versionResponse.major){case 1:return s(this,L,T,_,y);case 2:return ZL(this,L,T,_,y);default:return{error_message:"App Version is not supported",return_code:25600}}}async sign(L,T,_=I.JSON){let y=Buffer.from(T),m=[],O;try{m=await this.signGetChunks(L,y),O=await this.signSendChunk(1,m.length,m[0],_)}catch(G){f(G)}let R={error_message:O.error_message,return_code:O.return_code,signature:null};for(let G=1;G<m.length;G+=1)if(R=await this.signSendChunk(1+G,m.length,m[G],_),R.return_code!==D.NoError)break;return{error_message:R.error_message,return_code:R.return_code,signature:R.signature}}}import{SwapKitError as i}from"@swapkit/helpers";var e=()=>navigator?.usb,R0=async()=>{let L=e();if(typeof L?.getDevices!=="function")return[];let{ledgerUSBVendorId:T}=await import("@ledgerhq/devices"),y=(await L?.getDevices()).filter((m)=>m.vendorId===T);if(y.length>0)return y[0];return L?.requestDevice({filters:[{vendorId:T}]})},N=async()=>{let L=await R0();if(!L)throw new i("wallet_ledger_device_not_found");if(await L.open(),L.configuration===null)await L.selectConfiguration(1);try{await L.reset()}catch{}let T=L.configurations[0].interfaces.find(({alternates:G})=>G.some(({interfaceClass:C})=>C===255));if(!T)throw await L.close(),new i("wallet_ledger_connection_error");try{await L.claimInterface(T.interfaceNumber)}catch(G){throw await L.close(),new i("wallet_ledger_connection_claimed",G)}let _=(await import("@ledgerhq/hw-transport-webusb")).default;if(!await _.isSupported())throw new i("wallet_ledger_webusb_not_supported");let{DisconnectedDevice:m}=await import("@ledgerhq/errors"),O=new _(L,T.interfaceNumber),R=(G)=>{if(L===G.device)e()?.removeEventListener("disconnect",R),O._emitDisconnect(new m)};return e()?.addEventListener("disconnect",R),O};class b{ledgerTimeout=50000;derivationPath=w0.GAIA;transport;ledgerApp;chain="thor";checkOrCreateTransportAndLedger=async(L=!1)=>{if(!L&&this.transport&&this.ledgerApp)return;try{switch(this.transport=L||!this.transport?await N():this.transport,this.chain){case"thor":{this.ledgerApp=L||!this.ledgerApp?new c(this.transport):this.ledgerApp;break}case"cosmos":{let T=(await import("@ledgerhq/hw-app-cosmos")).default;this.ledgerApp=L||!this.ledgerApp?new T(this.transport):this.ledgerApp}}return this.ledgerApp}catch(T){throw new LL("wallet_ledger_connection_error",T)}};validateResponse=(L,T)=>{switch(L){case r.NoError:return;case r.LockedDevice:throw new LL("wallet_ledger_device_locked",{message:`Ledger is locked: ${T}`});case r.TC_NotFound:throw new LL("wallet_ledger_device_not_found");default:break}}}class TL extends b{pubKey=null;derivationPath;constructor(L=B0.GAIA){super();this.chain="cosmos",this.derivationPath=C0(L)}connect=async()=>{await this.checkOrCreateTransportAndLedger(!0);let{publicKey:L,address:T}=await this.getAddressAndPubKey();return this.pubKey=Buffer.from(L,"hex").toString("base64"),T};getAddressAndPubKey=async()=>{return await this.checkOrCreateTransportAndLedger(!0),await this.ledgerApp.getAddress(this.derivationPath,this.chain)};signTransaction=async(L,T="0")=>{await this.checkOrCreateTransportAndLedger(!0);let{return_code:_,error_message:y,signature:m}=await this.ledgerApp.sign(this.derivationPath,L);if(!this.pubKey)throw new JL("wallet_ledger_pubkey_not_found");return this.validateResponse(_,y),[{pub_key:{type:"tendermint/PubKeySecp256k1",value:this.pubKey},sequence:T,signature:m}]};signAmino=async(L,T)=>{await this.checkOrCreateTransportAndLedger(!0);let _=await this.getAccounts();if(_.findIndex((J)=>J.address===L)===-1)throw new JL("wallet_ledger_address_not_found",{address:L});let m=await import("@cosmjs/amino"),O=m.encodeSecp256k1Signature??m.default?.encodeSecp256k1Signature,R=m.serializeSignDoc??m.default?.serializeSignDoc,G=await import("@cosmjs/crypto"),C=G.Secp256k1Signature??G.default?.Secp256k1Signature,B=R(T),Z=await this.ledgerApp.sign(this.derivationPath,B);this.validateResponse(Z.return_code,Z.error_message);let $=C.fromDer(Z.signature).toFixedLength();return{signature:O(_[0].pubkey,$),signed:T}};getAccounts=async()=>{await this.checkOrCreateTransportAndLedger(!0);let L=await this.getAddressAndPubKey();return[{address:L.address,algo:"secp256k1",pubkey:Buffer.from(L.publicKey,"hex")}]}}import{ChainId as j,derivationPathToString as X0,NetworkDerivationPath as F0,SwapKitError as v}from"@swapkit/helpers";import{AbstractSigner as Z0}from"ethers";class Y extends Z0{chainId=j.ETH;derivationPath="";ledgerApp=null;ledgerTimeout=50000;constructor({provider:L,derivationPath:T=F0.OP,chainId:_=j.OP}){super(L);this.chainId=_||j.ETH,this.derivationPath=typeof T==="string"?T:X0(T),Object.defineProperty(this,"provider",{enumerable:!0,value:L||null,writable:!1})}connect=(L)=>new Y({chainId:this.chainId,derivationPath:this.derivationPath,provider:L});checkOrCreateTransportAndLedger=async()=>{if(this.ledgerApp)return;await this.createTransportAndLedger()};createTransportAndLedger=async()=>{let L=await N(),T=(await import("@ledgerhq/hw-app-eth")).default;this.ledgerApp=new T(L)};getAddress=async()=>{let L=await this.getAddressAndPubKey();if(!L)throw new v("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:T}=await import("ethers");await this.createTransportAndLedger();let _=await this.ledgerApp?.signPersonalMessage(this.derivationPath,L);if(!_)throw new v("wallet_ledger_signing_error");return _.r=`0x${_.r}`,_.s=`0x${_.s}`,T.from(_).serialized};sendTransaction=async(L)=>{if(!this.provider)throw new v("wallet_ledger_no_provider");let T=await this.signTransaction(L);return await this.provider.broadcastTransaction(T)};signTypedData(){throw new v("wallet_ledger_method_not_supported",{method:"signTypedData"})}signTransaction=async(L)=>{let{Transaction:T}=await import("ethers");await this.createTransportAndLedger();let _=await this.provider?.getTransactionCount(L.from||await this.getAddress()),y={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},m=T.from(y).unsignedSerialized.slice(2),{ledgerService:O}=await import("@ledgerhq/hw-app-eth"),R=await O.resolveTransaction(m,{},{erc20:!0,externalPlugins:!0}),G=await this.ledgerApp?.signTransaction(this.derivationPath,m,R);if(!G)throw new v("wallet_ledger_signing_error");let{r:C,s:B,v:Z}=G;return T.from({...y,signature:{r:`0x${C}`,s:`0x${B}`,v:Number(BigInt(Z))}}).serialized}}var $L=(L)=>new Y({...L,chainId:j.ARB}),NL=(L)=>new Y({...L,chainId:j.AURORA}),fL=(L)=>new Y({...L,chainId:j.AVAX}),jL=(L)=>new Y({...L,chainId:j.BASE}),QL=(L)=>new Y({...L,chainId:j.ETH}),YL=(L)=>new Y({...L,chainId:j.GNO}),ML=(L)=>new Y({...L,chainId:j.OP}),HL=(L)=>new Y({...L,chainId:j.POL}),DL=(L)=>new Y({...L,chainId:j.BSC});async function UL(L,T){let _=await import("@ledgerhq/hw-app-near"),{Chain:y,DerivationPath:m,derivationPathToString:O,SwapKitError:R}=await import("@swapkit/helpers"),G=new _.default(L),C=T?O(T):m[y.Near],{address:B,publicKey:Z}=await G.getAddress(C);return{getAddress(){return Promise.resolve(B)},async getPublicKey(){let{utils:J}=await import("near-api-js");return J.PublicKey.fromString(`ed25519:${Z}`)},signDelegateAction(J){return Promise.reject(new R("wallet_ledger_method_not_supported",{method:"signDelegateAction",wallet:"Ledger"}))},signNep413Message(J,M,q,Q,S){return Promise.reject(new R("wallet_ledger_method_not_supported",{method:"signNep413Message",wallet:"Ledger"}))},async signTransaction(J){let{Signature:M,SignedTransaction:q}=await import("near-api-js/lib/transaction");try{let Q=await G.signTransaction(J.encode(),C);if(!Q)throw Error("Signature undefined");let S=new M({data:Q,keyType:0}),k=new q({signature:S,transaction:J});return[Q,k]}catch(Q){throw new R("wallet_ledger_signing_error",{error:Q})}}}}import{base64 as l0}from"@scure/base";import{NetworkDerivationPath as J0,SwapKitError as zL}from"@swapkit/helpers";import{base64 as W0}from"@scure/base";import{SwapKitError as U}from"@swapkit/helpers";var _L=(L)=>{if(L.length<64)throw new U("wallet_ledger_invalid_signature",{reason:"Too short"});if(L[0]!==48)throw new U("wallet_ledger_invalid_signature",{reason:"TLV encoding: expected first byte 0x30"});if(L[1]+2!==L.length)throw new U("wallet_ledger_invalid_signature",{reason:"signature length does not match TLV"});if(L[2]!==2)throw new U("wallet_ledger_invalid_signature",{reason:"TLV encoding: expected length type 0x02"});let T=L[3],_=L.slice(4,T+4);if(_.length===33&&_[0]===0)_=_.slice(1,33);else if(_.length===33)throw new U("wallet_ledger_invalid_signature",{reason:"r too long"});while(_.length<32)_.unshift(0);if(L[T+4]!==2)throw new U("wallet_ledger_invalid_signature",{reason:"TLV encoding: expected length type 0x02 for s"});let y=L[T+5];if(4+T+2+y!==L.length)throw new U("wallet_ledger_invalid_signature",{reason:"TLV byte lengths do not match message length"});let m=L.slice(T+6,L.length);if(m.length===33&&m[0]===0)m=m.slice(1,33);else if(m.length===33)throw new U("wallet_ledger_invalid_signature",{reason:"s too long"});while(m.length<32)m.unshift(0);if(_.length!==32||m.length!==32)throw new U("wallet_ledger_invalid_signature",{reason:"must be 32 bytes each"});return W0.encode(Buffer.concat([_,m]))};class mL extends b{pubKey=null;derivationPath;constructor(L=J0.THOR){super();this.chain="thor",this.derivationPath=L}get pubkey(){return this.pubKey}connect=async()=>{await this.checkOrCreateTransportAndLedger();let{compressed_pk:L,bech32_address:T}=await this.getAddressAndPubKey();return this.pubKey=l0.encode(L),T};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,T="0")=>{await this.checkOrCreateTransportAndLedger(!0);let{return_code:_,error_message:y,signature:m}=await this.ledgerApp.sign(this.derivationPath,L);if(!this.pubKey)throw new zL("wallet_ledger_pubkey_not_found");return this.validateResponse(_,y),[{pub_key:{type:"tendermint/PubKeySecp256k1",value:this.pubKey},sequence:T,signature:_L(m)}]};sign=async(L)=>{await this.checkOrCreateTransportAndLedger(!0);let{return_code:T,error_message:_,signature:y}=await this.ledgerApp.sign(this.derivationPath,L);if(!this.pubKey)throw new zL("wallet_ledger_pubkey_not_found");return this.validateResponse(T,_),_L(y)}}import{derivationPathToString as $0,NetworkDerivationPath as N0,SwapKitError as x}from"@swapkit/helpers";class qL{derivationPath;ledgerApp=null;ledgerTimeout=50000;constructor(L){this.derivationPath=typeof L==="string"?L:$0(L||N0.TRON)}checkOrCreateTransportAndLedger=async()=>{if(this.ledgerApp)return;await this.createTransportAndLedger()};createTransportAndLedger=async()=>{let L=await N(),T=(await import("@ledgerhq/hw-app-trx")).default;this.ledgerApp=new T(L)};getAddress=async()=>{let L=await this.getAddressAndPubKey();if(!L)throw new x("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 x("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 x("wallet_ledger_transport_error");let T=JSON.stringify(L);try{let _=await this.ledgerApp.signTransaction(this.derivationPath,T,[]);if(!_)throw new x("wallet_ledger_signing_error");return{...L,signature:[_]}}catch(_){throw new x("wallet_ledger_signing_error",{error:_})}}}var AL=(L)=>new qL(L);import{derivationPathToString as f0,getWalletFormatFor as j0,SwapKitError as PL}from"@swapkit/helpers";var Q0=["bitcoin-cash","dash","dogecoin","zcash"],Y0=({psbt:L,inputUtxos:T,btcApp:_,derivationPath:y,chain:m},O)=>{let R=T.map(($)=>{return[_.splitTransaction($.txHex||"",!Q0.includes(m),m==="zcash"),$.index,void 0,void 0]}),G=L.data.globalMap.unsignedTx.toBuffer().toString("hex"),C=_.splitTransaction(G,!0),B=_.serializeTransactionOutputs(C).toString("hex"),Z={additionals:["bech32"],associatedKeysets:R.map(()=>y),inputs:R,outputScriptHex:B,segwit:!0,useTrustedInputForSegwit:!0};return _.createPaymentTransaction({...Z,...O})},E=({chain:L,additionalSignParams:T})=>{let _,y=null;async function m(R=!0){if(R&&!_)new PL("wallet_ledger_connection_error",{message:`Ledger connection failed:
1
+ import{c as X,d as F}from"../chunk-zzfbcc7e.js";import{Chain as w,ChainId as S0,FeeOption as K0,filterSupportedChains as I0,getRPCUrl as bL,SwapKitError as V,WalletOption as vL}from"@swapkit/helpers";import{createWallet as E0,getWalletSupportedChains as V0}from"@swapkit/wallet-core";import{Chain as l,SwapKitError as m0,WalletOption as y0}from"@swapkit/helpers";var P=async({chain:L,ledgerClient:T})=>{if(!T)return"";switch(L){case l.Cosmos:case l.THORChain:return T.connect();case l.Ethereum:case l.BinanceSmartChain:case l.Avalanche:case l.Polygon:case l.Arbitrum:case l.Optimism:case l.Base:case l.Aurora:case l.Gnosis:return T.getAddress();case l.Bitcoin:case l.BitcoinCash:case l.Dash:case l.Dogecoin:case l.Litecoin:case l.Zcash:{let _=T;await _.connect();let y=await _.getAddress();return L===l.BitcoinCash?y.replace("bitcoincash:",""):y}case l.Near:return await T.getAddress();case l.Ripple:return T.getAddress();case l.Tron:return T.getAddress();default:throw new m0("wallet_chain_not_supported",{chain:L,wallet:y0.LEDGER})}};import{Chain as W,SwapKitError as P0,WalletOption as g0}from"@swapkit/helpers";import{derivationPathToString as C0,NetworkDerivationPath as B0,SwapKitError as JL}from"@swapkit/helpers";import{LedgerErrorCode as r,NetworkDerivationPath as w0,SwapKitError as LL}from"@swapkit/helpers";import{SwapKitError as lL}from"@swapkit/helpers";var K=85,n=250;var g={GET_ADDR_SECP256K1:4,GET_VERSION:0,INS_PUBLIC_KEY_SECP256K1:1,SIGN_SECP256K1:2},h={ADD:1,INIT:0,LAST:2},p={ONLY_RETRIEVE:0,SHOW_ADDRESS_IN_DEVICE:1},I={JSON:0},D={NoError:36864},CL={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 H(L){if(L in CL)return CL[L];return`Unknown Status Code: ${L}`}function O0(L){return typeof L==="object"&&L!==null&&!Array.isArray(L)&&!(L instanceof Date)}function f(L){if(L){if(O0(L)){if(Object.hasOwn(L,"statusCode"))return{error_message:H(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 a(L){return L.send(85,g.GET_VERSION,0,0).then((T)=>{let _=T.slice(-2),y=_[0]*256+_[1],m=0;if(T.length>=9)m=(T[5]<<24)+(T[6]<<16)+(T[7]<<8)+(T[8]<<0);return{device_locked:T[4]===1,error_message:H(y),major:T[1],minor:T[2],patch:T[3],return_code:y,target_id:m.toString(16),test_mode:T[0]!==0}},f)}import{SwapKitError as d}from"@swapkit/helpers";function BL(L){if(L==null||L.length<3)throw new d("wallet_ledger_invalid_params",{reason:"Path too short"});if(L.length>10)throw new d("wallet_ledger_invalid_params",{reason:"Path too long"});let T=Buffer.alloc(1+4*L.length);T.writeUInt8(L.length,0);for(let _=0;_<L.length;_+=1){let y=L[_]||0;if(_<3)y|=2147483648;T.writeInt32LE(y,1+_*4)}return T}function s(L,T,_,y,m=I.JSON){return L.transport.send(K,g.SIGN_SECP256K1,T,m,y,[D.NoError,27012,27264]).then((O)=>{let R=O.slice(-2),G=R[0]*256+R[1],C=H(G);if(G===27264||G===27012)C=`${C} : ${O.slice(0,O.length-2).toString("ascii")}`;let B=null;if(O.length>2)B=O.slice(0,O.length-2);return{error_message:C,return_code:G,signature:B}},f)}function G0(L){if(L.length!==65)throw new d("wallet_ledger_invalid_params",{reason:"decompressed public key length should be 65 bytes"});let T=L.slice(33,65),_=Buffer.from([2+(T[T.length-1]&1)]);return Buffer.concat([_,L.slice(1,33)])}function XL(L,T){return L.transport.send(K,g.INS_PUBLIC_KEY_SECP256K1,0,0,T,[D.NoError]).then((_)=>{let y=_.slice(-2),m=y[0]*256+y[1],O=Buffer.from(_.slice(0,65));return{compressed_pk:G0(O),error_message:H(m),pk:O,return_code:m}},f)}function FL(L){if(!L||L.length!==5)throw new d("wallet_ledger_invalid_params",{reason:"Path must be exactly 5 elements"});let T=Buffer.alloc(20);return T.writeUInt32LE(2147483648+L[0],0),T.writeUInt32LE(2147483648+L[1],4),T.writeUInt32LE(2147483648+L[2],8),T.writeUInt32LE(L[3],12),T.writeUInt32LE(L[4],16),T}function ZL(L,T,_,y,m=I.JSON){let O=h.ADD;if(T===1)O=h.INIT;if(T===_)O=h.LAST;return s(L,O,0,y,m)}function WL(L,T){return L.transport.send(K,g.GET_ADDR_SECP256K1,0,0,T,[D.NoError]).then((_)=>{let y=_.slice(-2),m=y[0]*256+y[1];return{compressed_pk:Buffer.from(_.slice(0,33)),error_message:H(m),pk:"OBSOLETE PROPERTY",return_code:m}},f)}class c{transport;versionResponse;constructor(L){if(!L)throw new lL("wallet_ledger_transport_not_defined");this.transport=L}static serializeHRP(L){if(L==null||L.length<3||L.length>83)throw new lL("wallet_ledger_invalid_params",{reason:"Invalid HRP"});let T=Buffer.alloc(1+L.length);return T.writeUInt8(L.length,0),T.write(L,1),T}async serializePath(L){if(this.versionResponse=await a(this.transport),this.versionResponse.return_code!==D.NoError)throw this.versionResponse;switch(this.versionResponse.major){case 1:return BL(L);case 2:return FL(L);default:return Buffer.alloc(0)}}async signGetChunks(L,T){let _=await this.serializePath(L),y=[];y.push(_);for(let m=0;m<T.length;m+=n){let O=m+n;if(m>T.length)O=T.length;y.push(T.slice(m,O))}return y}async getVersion(){try{return this.versionResponse=await a(this.transport),this.versionResponse}catch(L){return f(L)}}appInfo(){return this.transport.send(176,1,0,0).then((L)=>{let T=L.slice(-2),_=T[0]*256+T[1],y="",m="",O=0,R=0;if(L[0]!==1)return{error_message:"response format ID not recognized",return_code:36865};let G=L[1];y=L.slice(2,2+G).toString("ascii");let C=2+G,B=L[C];C+=1,m=L.slice(C,C+B).toString("ascii"),C+=B;let Z=L[C];return C+=1,O=Z,R=L[C],{appName:y,appVersion:m,error_message:H(_),flag_onboarded:(R&4)!==0,flag_pin_validated:(R&128)!==0,flag_recovery:(R&1)!==0,flag_signed_mcu_code:(R&2)!==0,flagLen:O,flagsValue:R,return_code:_}},f)}deviceInfo(){return this.transport.send(224,1,0,0,Buffer.from([]),[D.NoError,28160]).then((L)=>{let T=L.slice(-2),_=T[0]*256+T[1];if(_===28160)return{error_message:"This command is only available in the Dashboard",return_code:_};let y=L.slice(0,4).toString("hex"),m=4,O=L[m];m+=1;let R=L.slice(m,m+O).toString();m+=O;let G=L[m];m+=1;let C=L.slice(m,m+G).toString("hex");m+=G;let B=L[m];m+=1;let Z=L.slice(m,m+B);if(Z[B-1]===0)Z=L.slice(m,m+B-1);let $=Z.toString();return{error_message:H(_),flag:C,mcuVersion:$,return_code:_,seVersion:R,targetId:y}},f)}async publicKey(L){try{let T=await this.serializePath(L);switch(this.versionResponse.major){case 1:return XL(this,T);case 2:{let _=Buffer.concat([c.serializeHRP("thor"),T]);return WL(this,_)}default:return{error_message:"App Version is not supported",return_code:25600}}}catch(T){return f(T)}}getAddressAndPubKey(L,T,_=!1){return this.serializePath(L).then((y)=>{let m=Buffer.concat([c.serializeHRP(T),y]);return this.transport.send(K,g.GET_ADDR_SECP256K1,_?p.SHOW_ADDRESS_IN_DEVICE:p.ONLY_RETRIEVE,0,m,[D.NoError]).then((O)=>{let R=O.slice(-2),G=R[0]*256+R[1],C=Buffer.from(O.slice(0,33));return{bech32_address:Buffer.from(O.slice(33,-2)).toString(),compressed_pk:C,error_message:H(G),return_code:G}},f)}).catch((y)=>f(y))}showAddressAndPubKey(L,T){return this.getAddressAndPubKey(L,T,!0)}signSendChunk(L,T,_,y=I.JSON){switch(this.versionResponse.major){case 1:return s(this,L,T,_,y);case 2:return ZL(this,L,T,_,y);default:return{error_message:"App Version is not supported",return_code:25600}}}async sign(L,T,_=I.JSON){let y=Buffer.from(T),m=[],O;try{m=await this.signGetChunks(L,y),O=await this.signSendChunk(1,m.length,m[0],_)}catch(G){f(G)}let R={error_message:O.error_message,return_code:O.return_code,signature:null};for(let G=1;G<m.length;G+=1)if(R=await this.signSendChunk(1+G,m.length,m[G],_),R.return_code!==D.NoError)break;return{error_message:R.error_message,return_code:R.return_code,signature:R.signature}}}import{SwapKitError as i}from"@swapkit/helpers";var e=()=>navigator?.usb,R0=async()=>{let L=e();if(typeof L?.getDevices!=="function")return[];let{ledgerUSBVendorId:T}=await import("@ledgerhq/devices"),y=(await L?.getDevices()).filter((m)=>m.vendorId===T);if(y.length>0)return y[0];return L?.requestDevice({filters:[{vendorId:T}]})},N=async()=>{let L=await R0();if(!L)throw new i("wallet_ledger_device_not_found");if(await L.open(),L.configuration===null)await L.selectConfiguration(1);try{await L.reset()}catch{}let T=L.configurations[0].interfaces.find(({alternates:G})=>G.some(({interfaceClass:C})=>C===255));if(!T)throw await L.close(),new i("wallet_ledger_connection_error");try{await L.claimInterface(T.interfaceNumber)}catch(G){throw await L.close(),new i("wallet_ledger_connection_claimed",G)}let _=(await import("@ledgerhq/hw-transport-webusb")).default;if(!await _.isSupported())throw new i("wallet_ledger_webusb_not_supported");let{DisconnectedDevice:m}=await import("@ledgerhq/errors"),O=new _(L,T.interfaceNumber),R=(G)=>{if(L===G.device)e()?.removeEventListener("disconnect",R),O._emitDisconnect(new m)};return e()?.addEventListener("disconnect",R),O};class b{ledgerTimeout=50000;derivationPath=w0.GAIA;transport;ledgerApp;chain="thor";checkOrCreateTransportAndLedger=async(L=!1)=>{if(!L&&this.transport&&this.ledgerApp)return;try{switch(this.transport=L||!this.transport?await N():this.transport,this.chain){case"thor":{this.ledgerApp=L||!this.ledgerApp?new c(this.transport):this.ledgerApp;break}case"cosmos":{let T=(await import("@ledgerhq/hw-app-cosmos")).default;this.ledgerApp=L||!this.ledgerApp?new T(this.transport):this.ledgerApp}}return this.ledgerApp}catch(T){throw new LL("wallet_ledger_connection_error",T)}};validateResponse=(L,T)=>{switch(L){case r.NoError:return;case r.LockedDevice:throw new LL("wallet_ledger_device_locked",{message:`Ledger is locked: ${T}`});case r.TC_NotFound:throw new LL("wallet_ledger_device_not_found");default:break}}}class TL extends b{pubKey=null;derivationPath;constructor(L=B0.GAIA){super();this.chain="cosmos",this.derivationPath=C0(L)}connect=async()=>{await this.checkOrCreateTransportAndLedger(!0);let{publicKey:L,address:T}=await this.getAddressAndPubKey();return this.pubKey=Buffer.from(L,"hex").toString("base64"),T};getAddressAndPubKey=async()=>{return await this.checkOrCreateTransportAndLedger(!0),await this.ledgerApp.getAddress(this.derivationPath,this.chain)};signTransaction=async(L,T="0")=>{await this.checkOrCreateTransportAndLedger(!0);let{return_code:_,error_message:y,signature:m}=await this.ledgerApp.sign(this.derivationPath,L);if(!this.pubKey)throw new JL("wallet_ledger_pubkey_not_found");return this.validateResponse(_,y),[{pub_key:{type:"tendermint/PubKeySecp256k1",value:this.pubKey},sequence:T,signature:m}]};signAmino=async(L,T)=>{await this.checkOrCreateTransportAndLedger(!0);let _=await this.getAccounts();if(_.findIndex((J)=>J.address===L)===-1)throw new JL("wallet_ledger_address_not_found",{address:L});let m=await import("@cosmjs/amino"),O=m.encodeSecp256k1Signature??m.default?.encodeSecp256k1Signature,R=m.serializeSignDoc??m.default?.serializeSignDoc,G=await import("@cosmjs/crypto"),C=G.Secp256k1Signature??G.default?.Secp256k1Signature,B=R(T),Z=await this.ledgerApp.sign(this.derivationPath,B);this.validateResponse(Z.return_code,Z.error_message);let $=C.fromDer(Z.signature).toFixedLength();return{signature:O(_[0].pubkey,$),signed:T}};getAccounts=async()=>{await this.checkOrCreateTransportAndLedger(!0);let L=await this.getAddressAndPubKey();return[{address:L.address,algo:"secp256k1",pubkey:Buffer.from(L.publicKey,"hex")}]}}import{ChainId as j,derivationPathToString as X0,NetworkDerivationPath as F0,SwapKitError as v}from"@swapkit/helpers";import{AbstractSigner as Z0}from"ethers";class Y extends Z0{chainId=j.ETH;derivationPath="";ledgerApp=null;ledgerTimeout=50000;constructor({provider:L,derivationPath:T=F0.OP,chainId:_=j.OP}){super(L);this.chainId=_||j.ETH,this.derivationPath=typeof T==="string"?T:X0(T),Object.defineProperty(this,"provider",{enumerable:!0,value:L||null,writable:!1})}connect=(L)=>new Y({chainId:this.chainId,derivationPath:this.derivationPath,provider:L});checkOrCreateTransportAndLedger=async()=>{if(this.ledgerApp)return;await this.createTransportAndLedger()};createTransportAndLedger=async()=>{let L=await N(),T=(await import("@ledgerhq/hw-app-eth")).default;this.ledgerApp=new T(L)};getAddress=async()=>{let L=await this.getAddressAndPubKey();if(!L)throw new v("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:T}=await import("ethers");await this.createTransportAndLedger();let _=await this.ledgerApp?.signPersonalMessage(this.derivationPath,L);if(!_)throw new v("wallet_ledger_signing_error");return _.r=`0x${_.r}`,_.s=`0x${_.s}`,T.from(_).serialized};sendTransaction=async(L)=>{if(!this.provider)throw new v("wallet_ledger_no_provider");let T=await this.signTransaction(L);return await this.provider.broadcastTransaction(T)};signTypedData(){throw new v("wallet_ledger_method_not_supported",{method:"signTypedData"})}signTransaction=async(L)=>{let{Transaction:T}=await import("ethers");await this.createTransportAndLedger();let _=await this.provider?.getTransactionCount(L.from||await this.getAddress()),y={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},m=T.from(y).unsignedSerialized.slice(2),{ledgerService:O}=await import("@ledgerhq/hw-app-eth"),R=await O.resolveTransaction(m,{},{erc20:!0,externalPlugins:!0}),G=await this.ledgerApp?.signTransaction(this.derivationPath,m,R);if(!G)throw new v("wallet_ledger_signing_error");let{r:C,s:B,v:Z}=G;return T.from({...y,signature:{r:`0x${C}`,s:`0x${B}`,v:Number(BigInt(Z))}}).serialized}}var $L=(L)=>new Y({...L,chainId:j.ARB}),NL=(L)=>new Y({...L,chainId:j.AURORA}),fL=(L)=>new Y({...L,chainId:j.AVAX}),jL=(L)=>new Y({...L,chainId:j.BASE}),QL=(L)=>new Y({...L,chainId:j.ETH}),YL=(L)=>new Y({...L,chainId:j.GNO}),ML=(L)=>new Y({...L,chainId:j.OP}),HL=(L)=>new Y({...L,chainId:j.POL}),DL=(L)=>new Y({...L,chainId:j.BSC});async function UL(L,T){let _=await import("@ledgerhq/hw-app-near"),{Chain:y,DerivationPath:m,derivationPathToString:O,SwapKitError:R}=await import("@swapkit/helpers"),G=new _.default(L),C=T?O(T):m[y.Near],{address:B,publicKey:Z}=await G.getAddress(C);return{getAddress(){return Promise.resolve(B)},async getPublicKey(){let{utils:J}=await import("near-api-js");return J.PublicKey.fromString(`ed25519:${Z}`)},signDelegateAction(J){return Promise.reject(new R("wallet_ledger_method_not_supported",{method:"signDelegateAction",wallet:"Ledger"}))},signNep413Message(J,M,q,Q,S){return Promise.reject(new R("wallet_ledger_method_not_supported",{method:"signNep413Message",wallet:"Ledger"}))},async signTransaction(J){let{Signature:M,SignedTransaction:q}=await import("near-api-js/lib/transaction");try{let Q=await G.signTransaction(J.encode(),C);if(!Q)throw Error("Signature undefined");let S=new M({data:Q,keyType:0}),k=new q({signature:S,transaction:J});return[Q,k]}catch(Q){throw new R("wallet_ledger_signing_error",{error:Q})}}}}import{base64 as l0}from"@scure/base";import{NetworkDerivationPath as J0,SwapKitError as zL}from"@swapkit/helpers";import{base64 as W0}from"@scure/base";import{SwapKitError as U}from"@swapkit/helpers";var _L=(L)=>{if(L.length<64)throw new U("wallet_ledger_invalid_signature",{reason:"Too short"});if(L[0]!==48)throw new U("wallet_ledger_invalid_signature",{reason:"TLV encoding: expected first byte 0x30"});if(L[1]+2!==L.length)throw new U("wallet_ledger_invalid_signature",{reason:"signature length does not match TLV"});if(L[2]!==2)throw new U("wallet_ledger_invalid_signature",{reason:"TLV encoding: expected length type 0x02"});let T=L[3],_=L.slice(4,T+4);if(_.length===33&&_[0]===0)_=_.slice(1,33);else if(_.length===33)throw new U("wallet_ledger_invalid_signature",{reason:"r too long"});while(_.length<32)_.unshift(0);if(L[T+4]!==2)throw new U("wallet_ledger_invalid_signature",{reason:"TLV encoding: expected length type 0x02 for s"});let y=L[T+5];if(4+T+2+y!==L.length)throw new U("wallet_ledger_invalid_signature",{reason:"TLV byte lengths do not match message length"});let m=L.slice(T+6,L.length);if(m.length===33&&m[0]===0)m=m.slice(1,33);else if(m.length===33)throw new U("wallet_ledger_invalid_signature",{reason:"s too long"});while(m.length<32)m.unshift(0);if(_.length!==32||m.length!==32)throw new U("wallet_ledger_invalid_signature",{reason:"must be 32 bytes each"});return W0.encode(Buffer.concat([_,m]))};class mL extends b{pubKey=null;derivationPath;constructor(L=J0.THOR){super();this.chain="thor",this.derivationPath=L}get pubkey(){return this.pubKey}connect=async()=>{await this.checkOrCreateTransportAndLedger();let{compressed_pk:L,bech32_address:T}=await this.getAddressAndPubKey();return this.pubKey=l0.encode(L),T};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,T="0")=>{await this.checkOrCreateTransportAndLedger(!0);let{return_code:_,error_message:y,signature:m}=await this.ledgerApp.sign(this.derivationPath,L);if(!this.pubKey)throw new zL("wallet_ledger_pubkey_not_found");return this.validateResponse(_,y),[{pub_key:{type:"tendermint/PubKeySecp256k1",value:this.pubKey},sequence:T,signature:_L(m)}]};sign=async(L)=>{await this.checkOrCreateTransportAndLedger(!0);let{return_code:T,error_message:_,signature:y}=await this.ledgerApp.sign(this.derivationPath,L);if(!this.pubKey)throw new zL("wallet_ledger_pubkey_not_found");return this.validateResponse(T,_),_L(y)}}import{derivationPathToString as $0,NetworkDerivationPath as N0,SwapKitError as x}from"@swapkit/helpers";class qL{derivationPath;ledgerApp=null;ledgerTimeout=50000;constructor(L){this.derivationPath=typeof L==="string"?L:$0(L||N0.TRON)}checkOrCreateTransportAndLedger=async()=>{if(this.ledgerApp)return;await this.createTransportAndLedger()};createTransportAndLedger=async()=>{let L=await N(),T=(await import("@ledgerhq/hw-app-trx")).default;this.ledgerApp=new T(L)};getAddress=async()=>{let L=await this.getAddressAndPubKey();if(!L)throw new x("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 x("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 x("wallet_ledger_transport_error");let T=JSON.stringify(L);try{let _=await this.ledgerApp.signTransaction(this.derivationPath,T,[]);if(!_)throw new x("wallet_ledger_signing_error");return{...L,signature:[_]}}catch(_){throw new x("wallet_ledger_signing_error",{error:_})}}}var AL=(L)=>new qL(L);import{derivationPathToString as f0,getWalletFormatFor as j0,SwapKitError as PL}from"@swapkit/helpers";var Q0=["bitcoin-cash","dash","dogecoin","zcash"],Y0=({psbt:L,inputUtxos:T,btcApp:_,derivationPath:y,chain:m},O)=>{let R=T.map(($)=>{return[_.splitTransaction($.txHex||"",!Q0.includes(m),m==="zcash"),$.index,void 0,void 0]}),G=L.data.globalMap.unsignedTx.toBuffer().toString("hex"),C=_.splitTransaction(G,!0),B=_.serializeTransactionOutputs(C).toString("hex"),Z={additionals:["bech32"],associatedKeysets:R.map(()=>y),inputs:R,outputScriptHex:B,segwit:!0,useTrustedInputForSegwit:!0};return _.createPaymentTransaction({...Z,...O})},E=({chain:L,additionalSignParams:T})=>{let _,y=null;async function m(R=!0){if(R&&!_)new PL("wallet_ledger_connection_error",{message:`Ledger connection failed:
2
2
  ${JSON.stringify({btcApp:_,checkBtcApp:R})}`});y||=await N()}async function O(){y=await N(),_=new(await import("@ledgerhq/hw-app-btc")).default({currency:L,transport:y})}return(R)=>{let G=typeof R==="string"?R:f0(R),C=j0(G);return{connect:async()=>{await m(!1),_=new(await import("@ledgerhq/hw-app-btc")).default({currency:L,transport:y})},getAddress:async()=>{let{toCashAddress:B}=await import("@swapkit/toolboxes/utxo");await m(!1);let{bitcoinAddress:Z}=await _.getWalletPublicKey(G,{format:C});if(!Z)throw new PL("wallet_ledger_get_address_error",{message:`Cannot get ${L} address from ledger derivation path: ${G}`});return L==="bitcoin-cash"&&C==="legacy"?B(Z).replace(/(bchtest:|bitcoincash:)/,""):Z},getExtendedPublicKey:async(B="84'/0'/0'",Z=76067358)=>{return await m(!1),_.getWalletXpub({path:B,xpubVersion:Z})},signTransaction:async(B,Z)=>{return await O(),Y0({btcApp:_,chain:L,derivationPath:G,inputUtxos:Z,psbt:B},T)}}}},gL=E({chain:"bitcoin"}),SL=E({chain:"litecoin"}),KL=E({additionalSignParams:{additionals:["abc"],segwit:!1,sigHashType:65},chain:"bitcoin-cash"}),IL=E({additionalSignParams:{additionals:[],segwit:!1,useTrustedInputForSegwit:!1},chain:"dogecoin"}),EL=E({additionalSignParams:{additionals:[],segwit:!1,useTrustedInputForSegwit:!1},chain:"dash"}),VL=E({additionalSignParams:{additionals:["zcash","sapling"],expiryHeight:(()=>{let L=Buffer.allocUnsafe(4);return L.writeUInt32LE(0),L})(),lockTime:0,segwit:!1,useTrustedInputForSegwit:!1},chain:"zcash"});import M0 from"@ledgerhq/hw-app-xrp";import{Chain as H0,derivationPathToString as D0,NetworkDerivationPath as U0}from"@swapkit/helpers";import{encode as kL}from"ripple-binary-codec";var z0=2147483648;function q0(L){let T={};for(let _ in L)if(L[_]!==null&&L[_]!==void 0)T[_]=L[_];return T}function A0(L){return new M0(L)}var cL=async(L)=>{let T=D0(L||U0[H0.Ripple]),_=await N(),y=A0(_),{address:m,publicKey:O}=await y.getAddress(T);async function R(G){let{hashes:C}=await import("@swapkit/toolboxes/ripple"),Z={...q0(G),Flags:G.Flags||z0,SigningPubKey:O.toUpperCase()},$=kL(Z),J=await y.signTransaction(T,$),M=kL({...Z,TxnSignature:J});return{hash:C.hashSignedTx(M),tx_blob:M}}return{getAddress:()=>m,signTransaction:R}};var z=async({chain:L,derivationPath:T})=>{let{match:_}=await import("ts-pattern");return _(L).returnType().with(W.THORChain,()=>Promise.resolve(new mL(T))).with(W.Cosmos,()=>Promise.resolve(new TL(T))).with(W.Bitcoin,()=>Promise.resolve(gL(T))).with(W.BitcoinCash,()=>Promise.resolve(KL(T))).with(W.Dash,()=>Promise.resolve(EL(T))).with(W.Dogecoin,()=>Promise.resolve(IL(T))).with(W.Litecoin,()=>Promise.resolve(SL(T))).with(W.Zcash,()=>Promise.resolve(VL(T))).with(W.Ripple,()=>Promise.resolve(cL(T))).with(W.Tron,()=>Promise.resolve(AL(T))).with(W.Near,async()=>{let y=await N();return UL(y,T)}).with(W.Arbitrum,W.Aurora,W.Avalanche,W.BinanceSmartChain,W.Ethereum,W.Gnosis,W.Optimism,W.Polygon,W.Base,async()=>{let{getProvider:y}=await import("@swapkit/toolboxes/evm"),m={derivationPath:T,provider:await y(L)};return _(L).with(W.BinanceSmartChain,()=>DL(m)).with(W.Avalanche,()=>fL(m)).with(W.Arbitrum,()=>$L(m)).with(W.Optimism,()=>ML(m)).with(W.Polygon,()=>HL(m)).with(W.Base,()=>jL(m)).with(W.Aurora,()=>NL(m)).with(W.Gnosis,()=>YL(m)).otherwise(()=>QL(m))}).otherwise(()=>{throw new P0("wallet_chain_not_supported",{chain:L,wallet:g0.LEDGER})})};var k0=E0({connect:({addChain:L,supportedChains:T,walletType:_})=>async function(m,O){let[R]=I0({chains:m,supportedChains:T,walletType:_});if(!R)return!1;let G=await v0({chain:R,derivationPath:O});return L({...G,chain:R,walletType:vL.LEDGER}),!0},name:"connectLedger",supportedChains:[w.Arbitrum,w.Aurora,w.Avalanche,w.Base,w.BinanceSmartChain,w.Bitcoin,w.BitcoinCash,w.Cosmos,w.Dash,w.Dogecoin,w.Ethereum,w.Gnosis,w.Litecoin,w.Near,w.Optimism,w.Polygon,w.Ripple,w.THORChain,w.Tron,w.Zcash],walletType:vL.LEDGER}),pT=V0(k0);function c0(L,T="t"){if(!L?.includes("=:"))return L;let _=L.includes(`:${T}:`)?L.split(`:${T}:`)[0]:L;return _?.substring(0,_.lastIndexOf(":"))}function o(L){if(Array.isArray(L))return L.forEach((y,m)=>{L[m]=o(y)}),L;if(typeof L!=="object")return L;let T={},_=Object.keys(L).sort();for(let y of _)T[y]=o(L[y]);return T}function b0(L){return JSON.stringify(o(L))}async function v0({chain:L,derivationPath:T}){switch(L){case w.BitcoinCash:case w.Bitcoin:case w.Dash:case w.Dogecoin:case w.Litecoin:case w.Zcash:{let{getUtxoToolbox:_}=await import("@swapkit/toolboxes/utxo"),y=await _(L),m=await z({chain:L,derivationPath:T}),O=await P({chain:L,ledgerClient:m});return{...y,address:O,transfer:async(G)=>{let C=G.feeRate||(await y.getFeeRates())[K0.Average],B=[w.Bitcoin].includes(L)?G.memo:c0(G.memo),{psbt:Z,inputs:$}=await y.createTransaction({...G,feeRate:C,fetchTxHex:!0,memo:B,sender:O}),J=await m.signTransaction(Z,$);return await y.broadcastTx(J)}}}case w.Ethereum:case w.Avalanche:case w.Arbitrum:case w.Optimism:case w.Polygon:case w.BinanceSmartChain:case w.Base:case w.Aurora:case w.Gnosis:{let{getEvmToolbox:_}=await import("@swapkit/toolboxes/evm"),y=await z({chain:L,derivationPath:T}),m=await P({chain:L,ledgerClient:y});return{...await _(L,{signer:y}),address:m}}case w.Cosmos:{let{createSigningStargateClient:_,getMsgSendDenom:y,getCosmosToolbox:m}=await import("@swapkit/toolboxes/cosmos"),O=await m(w.Cosmos),R=await z({chain:L,derivationPath:T}),G=await P({chain:L,ledgerClient:R});return{...O,address:G,transfer:async({assetValue:B,recipient:Z,memo:$})=>{if(!B)throw new V("wallet_ledger_invalid_asset");let J={amount:[{amount:B.getBaseValue("string"),denom:y(`u${B.symbol}`).toLowerCase()}],fromAddress:G,toAddress:Z},M=await bL(L),q=await _(M,R,"0.007uatom"),{transactionHash:Q}=await q.signAndBroadcast(G,[{typeUrl:"/cosmos.bank.v1beta1.MsgSend",value:J}],2,$);return Q}}}case w.THORChain:{let{SignMode:_}=await import("cosmjs-types/cosmos/tx/signing/v1beta1/signing.js"),{TxRaw:y}=await import("cosmjs-types/cosmos/tx/v1beta1/tx.js"),m=await import("@cosmjs/proto-signing"),O=m.encodePubkey??m.default?.encodePubkey,R=m.makeAuthInfoBytes??m.default?.makeAuthInfoBytes,{createStargateClient:G,buildEncodedTxBody:C,getCosmosToolbox:B,buildAminoMsg:Z,getDefaultChainFee:$,fromBase64:J,parseAminoMessageForDirectSigning:M}=await import("@swapkit/toolboxes/cosmos"),q=await B(L),Q=await z({chain:L,derivationPath:T}),S=await P({chain:L,ledgerClient:Q}),k=$(L),{pubkey:yL,signTransaction:xL,sign:hL}=Q,OL=async({memo:A="",assetValue:GL,...dL})=>{let RL=await q.getAccount(S);if(!RL)throw new V("wallet_ledger_invalid_account");if(!GL)throw new V("wallet_ledger_invalid_asset");if(!yL)throw new V("wallet_ledger_pubkey_not_found");let{accountNumber:iL,sequence:oL}=RL,u=(oL||0).toString(),wL=o([Z({assetValue:GL,memo:A,sender:S,...dL})]),uL=b0({account_number:iL?.toString(),chain_id:S0.THOR,fee:k,memo:A,msgs:wL,sequence:u}),t=await xL(uL,u);if(!t)throw new V("wallet_ledger_signing_error");let tL=O({type:"tendermint/PubKeySecp256k1",value:yL}),nL=wL.map(M),pL=await C({chain:L,memo:A,msgs:nL}),aL=R([{pubkey:tL,sequence:Number(u)}],k.amount,Number.parseInt(k.gas,10),void 0,void 0,_.SIGN_MODE_LEGACY_AMINO_JSON),sL=t?.[0]?.signature?J(t[0].signature):Uint8Array.from([]),eL=y.fromPartial({authInfoBytes:aL,bodyBytes:pL,signatures:[sL]}),rL=y.encode(eL).finish(),L0=await bL(w.THORChain),T0=await G(L0),{transactionHash:_0}=await T0.broadcastTx(rL);return _0};return{...q,address:S,deposit:(A)=>OL(A),signMessage:hL,transfer:(A)=>OL(A)}}case w.Near:{let{getNearToolbox:_}=await import("@swapkit/toolboxes/near"),y=await z({chain:L,derivationPath:T}),m=await y.getAddress();return{...await _({signer:y}),address:m}}case w.Ripple:{let{getRippleToolbox:_}=await import("@swapkit/toolboxes/ripple"),y=await z({chain:L,derivationPath:T}),m=y.getAddress();return{...await _({signer:y}),address:m}}case w.Tron:{let{createTronToolbox:_}=await import("@swapkit/toolboxes/tron"),y=await z({chain:L,derivationPath:T}),m=await P({chain:L,ledgerClient:y});return{...await _({signer:y}),address:m}}default:throw new V("wallet_ledger_chain_not_supported",{chain:L})}}export{k0 as ledgerWallet,pT as LEDGER_SUPPORTED_CHAINS};
3
3
 
4
4
  //# debugId=8A9EFF3AF059274064756E2164756E21
@@ -1,4 +1,4 @@
1
- import{c as $,d as V}from"../chunk-zn26fh3j.js";import{Chain as q,derivationPathToString as y,FeeOption as S,filterSupportedChains as w,SKConfig as T,SwapKitError as F,WalletOption as f}from"@swapkit/helpers";import{createWallet as g,getWalletSupportedChains as P}from"@swapkit/wallet-core";import{script as E}from"bitcoinjs-lib";function v(B){switch(B[0]){case 84:return{input:"SPENDWITNESS",output:"PAYTOWITNESS"};case 49:return{input:"SPENDP2SHWITNESS",output:"PAYTOP2SHWITNESS"};case 44:return{input:"SPENDADDRESS",output:"PAYTOADDRESS"};default:return null}}async function x({chain:B,derivationPath:j}){switch(B){case q.Arbitrum:case q.Aurora:case q.Avalanche:case q.Base:case q.BinanceSmartChain:case q.Ethereum:case q.Gnosis:case q.Optimism:case q.Polygon:{let{getProvider:_,getEvmToolbox:H}=await import("@swapkit/toolboxes/evm"),{getEVMSigner:U}=await import("../chunk-3044kn2k.js"),L=await _(B),X=await U({chain:B,derivationPath:j,provider:L}),I=await X.getAddress();return{...await H(B,{provider:L,signer:X}),address:I}}case q.Zcash:{let{getUtxoToolbox:_}=await import("@swapkit/toolboxes/utxo"),H=y(j),L=await(async()=>{let J=(await import("@trezor/connect-web")).default,{success:Y,payload:G}=await J.getAddress({coin:"zcash",path:H});if(!Y)throw new F({errorKey:"wallet_trezor_failed_to_get_address",info:{chain:B,error:G.error||"Unknown error"}});return G.address})(),X={getAddress:async()=>L,signTransaction:async(J)=>{let Y=(await import("@trezor/connect-web")).default,{address:G,networks:M}=await import("@bitgo/utxo-lib"),A=j.map((D,k)=>k<3?(D|2147483648)>>>0:D),Z=5,K=648488714,O=3370586197,W=J.txInputs.map((D,k)=>({address_n:A,amount:J.data.inputs[k]?.witnessUtxo?.value?.toString()||"0",prev_hash:D.hash.reverse().toString("hex"),prev_index:D.index,script_type:"SPENDADDRESS"})),N=J.txOutputs.map((D)=>{if(D.value===0n&&D.script.length>0&&D.script[0]===106&&E.decompile(D.script))return{amount:"0",op_return_data:E.decompile(D.script)[1].toString("hex"),script_type:"PAYTOOPRETURN"};let k=G.fromOutputScript(D.script,M.zcash);return k===L?{address_n:A,amount:D.value.toString(),script_type:"PAYTOADDRESS"}:{address:k,amount:D.value.toString(),script_type:"PAYTOADDRESS"}}),Q=await Y.signTransaction({branchId:3370586197,coin:"zcash",expiry:0,inputs:W,locktime:0,outputs:N,overwintered:!0,version:5,versionGroupId:648488714});if(Q.success)return Q.payload.serializedTx;throw new F({errorKey:"wallet_trezor_failed_to_sign_transaction",info:{chain:B,error:Q.payload.error}})}},I=await _(q.Zcash),R=async(J)=>{if(!(L&&J.recipient))throw new F({errorKey:"wallet_missing_params",info:{address:L,recipient:J.recipient,wallet:f.TREZOR}});let Y=J.feeRate||(await I.getFeeRates())[J.feeOptionKey||S.Fast],{psbt:G}=await I.createTransaction({...J,feeRate:Y,fetchTxHex:!1,sender:L}),M=await X.signTransaction(G);return await I.broadcastTx(M)};return{...I,address:L,signTransaction:X.signTransaction,transfer:R}}case q.Bitcoin:case q.BitcoinCash:case q.Dash:case q.Dogecoin:case q.Litecoin:{let{toCashAddress:_,getUtxoToolbox:H}=await import("@swapkit/toolboxes/utxo"),U=v(j);if(!U)throw new F({errorKey:"wallet_trezor_derivation_path_not_supported",info:{derivationPath:j}});let L=B.toLowerCase(),I=await(async(G=j)=>{let M=(await import("@trezor/connect-web")).default,{success:A,payload:Z}=await M.getAddress({coin:L,path:y(G)});if(!A)throw new F({errorKey:"wallet_trezor_failed_to_get_address",info:{chain:B,error:Z.error||"Unknown error"}});if(B===q.BitcoinCash)return(await H(B)).stripPrefix(Z.address);return Z.address})(),R=async(G,M,A="")=>{let Z=(await import("@trezor/connect-web")).default,K=j.map((N,Q)=>Q<3?(N|2147483648)>>>0:N),O=await H(B),W=await Z.signTransaction({coin:L,inputs:M.map(({hash:N,index:Q,value:D})=>({address_n:K,amount:D,prev_hash:N,prev_index:Q,script_type:U.input})),outputs:G.txOutputs.map((N)=>{if(!N.address)return{amount:"0",op_return_data:Buffer.from(A).toString("hex"),script_type:"PAYTOOPRETURN"};let Q=B===q.BitcoinCash?O.stripPrefix(_(N.address)):N.address;return Q===I?{address_n:K,amount:N.value,script_type:U.output}:{address:Q,amount:N.value,script_type:"PAYTOADDRESS"}})});if(W.success)return W.payload.serializedTx;throw new F({errorKey:"wallet_trezor_failed_to_sign_transaction",info:{chain:B,error:W.payload.error}})},J=async({recipient:G,feeOptionKey:M,feeRate:A,memo:Z,...K})=>{if(!(I&&G))throw new F({errorKey:"wallet_missing_params",info:{address:I,memo:Z,recipient:G,wallet:f.TREZOR}});let O=await H(B),W=A||(await O.getFeeRates())[M||S.Fast],N=B===q.BitcoinCash?O.buildTx:O.createTransaction,{psbt:Q,inputs:D}=await N({...K,feeRate:W,fetchTxHex:!0,memo:Z,recipient:G,sender:I}),k=await R(Q,D,Z);return await O.broadcastTx(k)};return{...await H(B),address:I,signTransaction:R,transfer:J}}default:throw new F({errorKey:"wallet_chain_not_supported",info:{chain:B,wallet:f.TREZOR}})}}var b=g({connect:({addChain:B,supportedChains:j,walletType:_})=>async function(U,L){let[X]=w({chains:U,supportedChains:j,walletType:_});if(!X)throw new F({errorKey:"wallet_chain_not_supported",info:{chain:X,wallet:f.TREZOR}});let I=(await import("@trezor/connect-web")).default,{success:R}=await I.getDeviceState();if(!R){let Y=T.get("integrations").trezor,G=Y?{...Y,appName:Y.appName||"SwapKit"}:{appName:"SwapKit",appUrl:"",email:""};I.init({lazyLoad:!0,manifest:G})}let J=await x({chain:X,derivationPath:L});return B({...J,chain:X,walletType:_}),!0},name:"connectTrezor",supportedChains:[q.Arbitrum,q.Aurora,q.Avalanche,q.Base,q.BinanceSmartChain,q.Bitcoin,q.BitcoinCash,q.Dash,q.Dogecoin,q.Ethereum,q.Gnosis,q.Litecoin,q.Optimism,q.Polygon,q.Zcash],walletType:f.TREZOR}),u=P(b);export{b as trezorWallet,u as TREZOR_SUPPORTED_CHAINS};
1
+ import{c as $,d as V}from"../chunk-zzfbcc7e.js";import{Chain as q,derivationPathToString as y,FeeOption as S,filterSupportedChains as w,SKConfig as T,SwapKitError as F,WalletOption as f}from"@swapkit/helpers";import{createWallet as g,getWalletSupportedChains as P}from"@swapkit/wallet-core";import{script as E}from"bitcoinjs-lib";function v(B){switch(B[0]){case 84:return{input:"SPENDWITNESS",output:"PAYTOWITNESS"};case 49:return{input:"SPENDP2SHWITNESS",output:"PAYTOP2SHWITNESS"};case 44:return{input:"SPENDADDRESS",output:"PAYTOADDRESS"};default:return null}}async function x({chain:B,derivationPath:j}){switch(B){case q.Arbitrum:case q.Aurora:case q.Avalanche:case q.Base:case q.BinanceSmartChain:case q.Ethereum:case q.Gnosis:case q.Optimism:case q.Polygon:{let{getProvider:_,getEvmToolbox:H}=await import("@swapkit/toolboxes/evm"),{getEVMSigner:U}=await import("../chunk-takg8b37.js"),L=await _(B),X=await U({chain:B,derivationPath:j,provider:L}),I=await X.getAddress();return{...await H(B,{provider:L,signer:X}),address:I}}case q.Zcash:{let{getUtxoToolbox:_}=await import("@swapkit/toolboxes/utxo"),H=y(j),L=await(async()=>{let J=(await import("@trezor/connect-web")).default,{success:Y,payload:G}=await J.getAddress({coin:"zcash",path:H});if(!Y)throw new F({errorKey:"wallet_trezor_failed_to_get_address",info:{chain:B,error:G.error||"Unknown error"}});return G.address})(),X={getAddress:async()=>L,signTransaction:async(J)=>{let Y=(await import("@trezor/connect-web")).default,{address:G,networks:M}=await import("@bitgo/utxo-lib"),A=j.map((D,k)=>k<3?(D|2147483648)>>>0:D),Z=5,K=648488714,O=3370586197,W=J.txInputs.map((D,k)=>({address_n:A,amount:J.data.inputs[k]?.witnessUtxo?.value?.toString()||"0",prev_hash:D.hash.reverse().toString("hex"),prev_index:D.index,script_type:"SPENDADDRESS"})),N=J.txOutputs.map((D)=>{if(D.value===0n&&D.script.length>0&&D.script[0]===106&&E.decompile(D.script))return{amount:"0",op_return_data:E.decompile(D.script)[1].toString("hex"),script_type:"PAYTOOPRETURN"};let k=G.fromOutputScript(D.script,M.zcash);return k===L?{address_n:A,amount:D.value.toString(),script_type:"PAYTOADDRESS"}:{address:k,amount:D.value.toString(),script_type:"PAYTOADDRESS"}}),Q=await Y.signTransaction({branchId:3370586197,coin:"zcash",expiry:0,inputs:W,locktime:0,outputs:N,overwintered:!0,version:5,versionGroupId:648488714});if(Q.success)return Q.payload.serializedTx;throw new F({errorKey:"wallet_trezor_failed_to_sign_transaction",info:{chain:B,error:Q.payload.error}})}},I=await _(q.Zcash),R=async(J)=>{if(!(L&&J.recipient))throw new F({errorKey:"wallet_missing_params",info:{address:L,recipient:J.recipient,wallet:f.TREZOR}});let Y=J.feeRate||(await I.getFeeRates())[J.feeOptionKey||S.Fast],{psbt:G}=await I.createTransaction({...J,feeRate:Y,fetchTxHex:!1,sender:L}),M=await X.signTransaction(G);return await I.broadcastTx(M)};return{...I,address:L,signTransaction:X.signTransaction,transfer:R}}case q.Bitcoin:case q.BitcoinCash:case q.Dash:case q.Dogecoin:case q.Litecoin:{let{toCashAddress:_,getUtxoToolbox:H}=await import("@swapkit/toolboxes/utxo"),U=v(j);if(!U)throw new F({errorKey:"wallet_trezor_derivation_path_not_supported",info:{derivationPath:j}});let L=B.toLowerCase(),I=await(async(G=j)=>{let M=(await import("@trezor/connect-web")).default,{success:A,payload:Z}=await M.getAddress({coin:L,path:y(G)});if(!A)throw new F({errorKey:"wallet_trezor_failed_to_get_address",info:{chain:B,error:Z.error||"Unknown error"}});if(B===q.BitcoinCash)return(await H(B)).stripPrefix(Z.address);return Z.address})(),R=async(G,M,A="")=>{let Z=(await import("@trezor/connect-web")).default,K=j.map((N,Q)=>Q<3?(N|2147483648)>>>0:N),O=await H(B),W=await Z.signTransaction({coin:L,inputs:M.map(({hash:N,index:Q,value:D})=>({address_n:K,amount:D,prev_hash:N,prev_index:Q,script_type:U.input})),outputs:G.txOutputs.map((N)=>{if(!N.address)return{amount:"0",op_return_data:Buffer.from(A).toString("hex"),script_type:"PAYTOOPRETURN"};let Q=B===q.BitcoinCash?O.stripPrefix(_(N.address)):N.address;return Q===I?{address_n:K,amount:N.value,script_type:U.output}:{address:Q,amount:N.value,script_type:"PAYTOADDRESS"}})});if(W.success)return W.payload.serializedTx;throw new F({errorKey:"wallet_trezor_failed_to_sign_transaction",info:{chain:B,error:W.payload.error}})},J=async({recipient:G,feeOptionKey:M,feeRate:A,memo:Z,...K})=>{if(!(I&&G))throw new F({errorKey:"wallet_missing_params",info:{address:I,memo:Z,recipient:G,wallet:f.TREZOR}});let O=await H(B),W=A||(await O.getFeeRates())[M||S.Fast],N=B===q.BitcoinCash?O.buildTx:O.createTransaction,{psbt:Q,inputs:D}=await N({...K,feeRate:W,fetchTxHex:!0,memo:Z,recipient:G,sender:I}),k=await R(Q,D,Z);return await O.broadcastTx(k)};return{...await H(B),address:I,signTransaction:R,transfer:J}}default:throw new F({errorKey:"wallet_chain_not_supported",info:{chain:B,wallet:f.TREZOR}})}}var b=g({connect:({addChain:B,supportedChains:j,walletType:_})=>async function(U,L){let[X]=w({chains:U,supportedChains:j,walletType:_});if(!X)throw new F({errorKey:"wallet_chain_not_supported",info:{chain:X,wallet:f.TREZOR}});let I=(await import("@trezor/connect-web")).default,{success:R}=await I.getDeviceState();if(!R){let Y=T.get("integrations").trezor,G=Y?{...Y,appName:Y.appName||"SwapKit"}:{appName:"SwapKit",appUrl:"",email:""};I.init({lazyLoad:!0,manifest:G})}let J=await x({chain:X,derivationPath:L});return B({...J,chain:X,walletType:_}),!0},name:"connectTrezor",supportedChains:[q.Arbitrum,q.Aurora,q.Avalanche,q.Base,q.BinanceSmartChain,q.Bitcoin,q.BitcoinCash,q.Dash,q.Dogecoin,q.Ethereum,q.Gnosis,q.Litecoin,q.Optimism,q.Polygon,q.Zcash],walletType:f.TREZOR}),u=P(b);export{b as trezorWallet,u as TREZOR_SUPPORTED_CHAINS};
2
2
 
3
3
  //# debugId=852D90BDC926E2F164756E2164756E21
4
4
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -13,8 +13,8 @@
13
13
  "@ledgerhq/hw-transport": "~6.31.0",
14
14
  "@ledgerhq/hw-transport-webusb": "~6.29.0",
15
15
  "@ledgerhq/wallet-api-client": "~1.11.0",
16
- "@swapkit/helpers": "4.0.24",
17
- "@swapkit/toolboxes": "4.0.24",
16
+ "@swapkit/helpers": "4.0.25",
17
+ "@swapkit/toolboxes": "4.0.25",
18
18
  "ethers": "^6.14.0",
19
19
  "ts-pattern": "^5.7.0"
20
20
  },
@@ -72,5 +72,5 @@
72
72
  "type-check:go": "tsgo"
73
73
  },
74
74
  "type": "module",
75
- "version": "4.1.23"
75
+ "version": "4.1.24"
76
76
  }