@swapkit/wallets 3.0.0-beta.2 → 3.0.0-beta.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-2aa1w78q.js +3 -0
- package/dist/chunk-2aa1w78q.js.map +10 -0
- package/dist/{chunk-p1kdg37m.js → chunk-38ztynv0.js} +1 -1
- package/dist/{chunk-p1kdg37m.js.map → chunk-38ztynv0.js.map} +1 -1
- package/dist/chunk-ebfkk1jn.js +4 -0
- package/dist/{chunk-czhtd6cy.js.map → chunk-ebfkk1jn.js.map} +3 -3
- package/dist/chunk-k9q04afa.js +3 -0
- package/dist/{chunk-qadd75nn.js.map → chunk-k9q04afa.js.map} +3 -3
- package/dist/chunk-x5hgx9x9.js +3 -0
- package/dist/chunk-x5hgx9x9.js.map +10 -0
- package/dist/src/bitget/index.cjs +2 -2
- package/dist/src/bitget/index.cjs.map +3 -3
- package/dist/src/bitget/index.js +2 -2
- package/dist/src/bitget/index.js.map +3 -3
- package/dist/src/coinbase/index.cjs +2 -2
- package/dist/src/coinbase/index.cjs.map +3 -3
- package/dist/src/coinbase/index.js +2 -2
- package/dist/src/coinbase/index.js.map +3 -3
- package/dist/src/cosmostation/index.cjs +3 -0
- package/dist/src/cosmostation/index.cjs.map +10 -0
- package/dist/src/cosmostation/index.js +3 -0
- package/dist/src/cosmostation/index.js.map +10 -0
- package/dist/src/ctrl/index.cjs +2 -2
- package/dist/src/ctrl/index.cjs.map +3 -3
- package/dist/src/ctrl/index.js +2 -2
- package/dist/src/ctrl/index.js.map +3 -3
- package/dist/src/evm-extensions/index.cjs +2 -2
- package/dist/src/evm-extensions/index.cjs.map +3 -3
- package/dist/src/evm-extensions/index.js +2 -2
- package/dist/src/evm-extensions/index.js.map +3 -3
- package/dist/src/exodus/index.cjs +2 -2
- package/dist/src/exodus/index.cjs.map +3 -3
- package/dist/src/exodus/index.js +2 -2
- package/dist/src/exodus/index.js.map +3 -3
- package/dist/src/index.js +1 -1
- package/dist/src/keepkey/index.cjs +2 -2
- package/dist/src/keepkey/index.cjs.map +9 -9
- package/dist/src/keepkey/index.js +2 -2
- package/dist/src/keepkey/index.js.map +9 -9
- package/dist/src/keepkey-bex/index.cjs +2 -2
- package/dist/src/keepkey-bex/index.cjs.map +4 -4
- package/dist/src/keepkey-bex/index.js +2 -2
- package/dist/src/keepkey-bex/index.js.map +4 -4
- package/dist/src/keplr/index.cjs +2 -2
- package/dist/src/keplr/index.cjs.map +3 -3
- package/dist/src/keplr/index.js +2 -2
- package/dist/src/keplr/index.js.map +3 -3
- package/dist/src/keystore/index.cjs +2 -2
- package/dist/src/keystore/index.cjs.map +4 -4
- package/dist/src/keystore/index.js +2 -2
- package/dist/src/keystore/index.js.map +4 -4
- package/dist/src/ledger/index.cjs +3 -3
- package/dist/src/ledger/index.cjs.map +16 -15
- package/dist/src/ledger/index.js +3 -3
- package/dist/src/ledger/index.js.map +16 -15
- package/dist/src/okx/index.cjs +2 -2
- package/dist/src/okx/index.cjs.map +3 -3
- package/dist/src/okx/index.js +2 -2
- package/dist/src/okx/index.js.map +3 -3
- package/dist/src/onekey/index.cjs +2 -2
- package/dist/src/onekey/index.cjs.map +3 -3
- package/dist/src/onekey/index.js +2 -2
- package/dist/src/onekey/index.js.map +3 -3
- package/dist/src/phantom/index.js +1 -1
- package/dist/src/polkadotjs/index.js +1 -1
- package/dist/src/radix/index.cjs +2 -2
- package/dist/src/radix/index.cjs.map +3 -3
- package/dist/src/radix/index.js +2 -2
- package/dist/src/radix/index.js.map +3 -3
- package/dist/src/talisman/index.js +1 -1
- package/dist/src/trezor/index.cjs +2 -2
- package/dist/src/trezor/index.cjs.map +3 -3
- package/dist/src/trezor/index.js +2 -2
- package/dist/src/trezor/index.js.map +3 -3
- package/dist/src/walletconnect/index.cjs +2 -2
- package/dist/src/walletconnect/index.cjs.map +4 -4
- package/dist/src/walletconnect/index.js +2 -2
- package/dist/src/walletconnect/index.js.map +4 -4
- package/package.json +32 -27
- package/src/bitget/helpers.ts +4 -4
- package/src/coinbase/signer.ts +4 -4
- package/src/cosmostation/index.ts +142 -0
- package/src/ctrl/walletHelpers.ts +82 -70
- package/src/evm-extensions/index.ts +4 -3
- package/src/exodus/index.ts +8 -9
- package/src/keepkey/chains/cosmos.ts +44 -50
- package/src/keepkey/chains/evm.ts +16 -8
- package/src/keepkey/chains/mayachain.ts +3 -2
- package/src/keepkey/chains/thorchain.ts +3 -2
- package/src/keepkey/chains/utxo.ts +9 -2
- package/src/keepkey/coins.ts +10 -4
- package/src/keepkey/index.ts +15 -7
- package/src/keepkey-bex/index.ts +9 -14
- package/src/keepkey-bex/walletHelpers.ts +1 -1
- package/src/keplr/index.ts +4 -3
- package/src/keystore/helpers.ts +2 -4
- package/src/keystore/index.ts +1 -0
- package/src/ledger/clients/cosmos.ts +5 -4
- package/src/ledger/clients/evm.ts +7 -6
- package/src/ledger/clients/thorchain/helpers.ts +9 -4
- package/src/ledger/clients/thorchain/index.ts +3 -3
- package/src/ledger/clients/thorchain/lib.ts +3 -2
- package/src/ledger/clients/thorchain/utils.ts +20 -9
- package/src/ledger/clients/utxo.ts +3 -5
- package/src/ledger/clients/xrp.ts +66 -0
- package/src/ledger/cosmosTypes.ts +14 -10
- package/src/ledger/helpers/getLedgerAddress.ts +12 -3
- package/src/ledger/helpers/getLedgerClient.ts +56 -45
- package/src/ledger/helpers/getLedgerTransport.ts +5 -3
- package/src/ledger/index.ts +18 -7
- package/src/ledger/interfaces/CosmosLedgerInterface.ts +1 -2
- package/src/okx/helpers.ts +11 -9
- package/src/onekey/index.ts +3 -7
- package/src/radix/index.ts +4 -4
- package/src/trezor/evmSigner.ts +4 -4
- package/src/trezor/index.ts +14 -4
- package/src/types.ts +3 -0
- package/src/utils.ts +4 -0
- package/src/walletconnect/evmSigner.ts +6 -2
- package/src/walletconnect/index.ts +4 -4
- package/dist/chunk-bhfpfqc3.js +0 -3
- package/dist/chunk-bhfpfqc3.js.map +0 -10
- package/dist/chunk-czhtd6cy.js +0 -4
- package/dist/chunk-q81hzyra.js +0 -3
- package/dist/chunk-q81hzyra.js.map +0 -10
- package/dist/chunk-qadd75nn.js +0 -3
package/dist/src/ledger/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as z0}from"../../chunk-czhtd6cy.js";import{c as Y,d as Z}from"../../chunk-p1kdg37m.js";import{Chain as $,ChainId as F2,FeeOption as X2,SKConfig as r,StagenetChain as J2,WalletOption as N0,createWallet as W2,filterSupportedChains as $2}from"@swapkit/helpers";import{Chain as m,SwapKitError as c0,WalletOption as u0}from"@swapkit/helpers";var S=async({chain:L,ledgerClient:_})=>{if(!_)return"";switch(L){case m.Cosmos:case m.THORChain:return _.connect();case m.Ethereum:case m.BinanceSmartChain:case m.Avalanche:case m.Polygon:case m.Arbitrum:case m.Optimism:case m.Base:return _.getAddress();case m.Bitcoin:case m.BitcoinCash:case m.Dash:case m.Dogecoin:case m.Litecoin:{let O=_;await O.connect();let B=await O.getAddress();return L===m.BitcoinCash?B.replace("bitcoincash:",""):B}default:throw new c0("wallet_chain_not_supported",{wallet:u0.LEDGER,chain:L})}};import{Chain as H,SwapKitError as B2,WalletOption as j2}from"@swapkit/helpers";import{NetworkDerivationPath as o0,derivationPathToString as t0}from"@swapkit/helpers";import{LedgerErrorCode as o,NetworkDerivationPath as p0,SwapKitError as t}from"@swapkit/helpers";var E=85,c=250;var K={GET_VERSION:0,INS_PUBLIC_KEY_SECP256K1:1,SIGN_SECP256K1:2,GET_ADDR_SECP256K1:4},P={INIT:0,ADD:1,LAST:2},u={ONLY_RETRIEVE:0,SHOW_ADDRESS_IN_DEVICE:1},C={JSON:0},R={NoError:36864},B0={1:"U2F: Unknown",2:"U2F: Bad request",3:"U2F: Configuration unsupported",4:"U2F: Device Ineligible",5:"U2F: Timeout",14:"Timeout",36864:"No errors",36865:"Device is busy",26626:"Error deriving keys",25600:"Execution Error",26368:"Wrong Length",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"};function U(L){if(L in B0)return B0[L];return`Unknown Status Code: ${L}`}function h0(L){return typeof L==="object"&&L!==null&&!Array.isArray(L)&&!(L instanceof Date)}function M(L){if(L){if(h0(L)){if(Object.prototype.hasOwnProperty.call(L,"statusCode"))return{return_code:L.statusCode,error_message:U(L.statusCode)};if(Object.prototype.hasOwnProperty.call(L,"return_code")&&Object.prototype.hasOwnProperty.call(L,"error_message"))return L}return{return_code:65535,error_message:L.toString()}}return{return_code:65535,error_message:L.toString()}}async function h(L){return L.send(85,K.GET_VERSION,0,0).then((_)=>{let O=_.slice(-2),B=O[0]*256+O[1],G=0;if(_.length>=9)G=(_[5]<<24)+(_[6]<<16)+(_[7]<<8)+(_[8]<<0);return{return_code:B,error_message:U(B),test_mode:_[0]!==0,major:_[1],minor:_[2],patch:_[3],device_locked:_[4]===1,target_id:G.toString(16)}},M)}function j0(L){if(L==null||L.length<3)throw new Error("Invalid path.");if(L.length>10)throw new Error("Invalid path. Length should be <= 10");let _=Buffer.alloc(1+4*L.length);_.writeUInt8(L.length,0);for(let O=0;O<L.length;O+=1){let B=L[O]||0;if(O<3)B|=2147483648;_.writeInt32LE(B,1+O*4)}return _}async function d(L,_,O,B,G=C.JSON){return L.transport.send(E,K.SIGN_SECP256K1,_,G,B,[R.NoError,27012,27264]).then((j)=>{let X=j.slice(-2),F=X[0]*256+X[1],J=U(F);if(F===27264||F===27012)J=`${J} : ${j.slice(0,j.length-2).toString("ascii")}`;let W=null;if(j.length>2)W=j.slice(0,j.length-2);return{signature:W,return_code:F,error_message:J}},M)}function d0(L){if(L.length!==65)throw new Error("decompressed public key length should be 65 bytes");let _=L.slice(33,65),O=Buffer.from([2+(_[_.length-1]&1)]);return Buffer.concat([O,L.slice(1,33)])}async function F0(L,_){return L.transport.send(E,K.INS_PUBLIC_KEY_SECP256K1,0,0,_,[R.NoError]).then((O)=>{let B=O.slice(-2),G=B[0]*256+B[1],j=Buffer.from(O.slice(0,65));return{pk:j,compressed_pk:d0(j),return_code:G,error_message:U(G)}},M)}function X0(L){if(!L||L.length!==5)throw new Error("Invalid path.");let _=Buffer.alloc(20);return _.writeUInt32LE(2147483648+L[0],0),_.writeUInt32LE(2147483648+L[1],4),_.writeUInt32LE(2147483648+L[2],8),_.writeUInt32LE(L[3],12),_.writeUInt32LE(L[4],16),_}function J0(L,_,O,B,G=C.JSON){let j=P.ADD;if(_===1)j=P.INIT;if(_===O)j=P.LAST;return d(L,j,0,B,G)}async function W0(L,_){return L.transport.send(E,K.GET_ADDR_SECP256K1,0,0,_,[R.NoError]).then((O)=>{let B=O.slice(-2),G=B[0]*256+B[1];return{pk:"OBSOLETE PROPERTY",compressed_pk:Buffer.from(O.slice(0,33)),return_code:G,error_message:U(G)}},M)}class I{transport;versionResponse;constructor(L){if(!L)throw new Error("Transport has not been defined");this.transport=L}static serializeHRP(L){if(L==null||L.length<3||L.length>83)throw new Error("Invalid HRP");let _=Buffer.alloc(1+L.length);return _.writeUInt8(L.length,0),_.write(L,1),_}async serializePath(L){if(this.versionResponse=await h(this.transport),this.versionResponse.return_code!==R.NoError)throw this.versionResponse;switch(this.versionResponse.major){case 1:return j0(L);case 2:return X0(L);default:return Buffer.alloc(0)}}async signGetChunks(L,_){let O=await this.serializePath(L),B=[];B.push(O);for(let G=0;G<_.length;G+=c){let j=G+c;if(G>_.length)j=_.length;B.push(_.slice(G,j))}return B}async getVersion(){try{return this.versionResponse=await h(this.transport),this.versionResponse}catch(L){return M(L)}}async appInfo(){return this.transport.send(176,1,0,0).then((L)=>{let _=L.slice(-2),O=_[0]*256+_[1],B="",G="",j=0,X=0;if(L[0]!==1)return{return_code:36865,error_message:"response format ID not recognized"};let F=L[1];B=L.slice(2,2+F).toString("ascii");let J=2+F,W=L[J];J+=1,G=L.slice(J,J+W).toString("ascii"),J+=W;let Q=L[J];return J+=1,j=Q,X=L[J],{return_code:O,error_message:U(O),appName:B,appVersion:G,flagLen:j,flagsValue:X,flag_recovery:(X&1)!==0,flag_signed_mcu_code:(X&2)!==0,flag_onboarded:(X&4)!==0,flag_pin_validated:(X&128)!==0}},M)}async deviceInfo(){return this.transport.send(224,1,0,0,Buffer.from([]),[R.NoError,28160]).then((L)=>{let _=L.slice(-2),O=_[0]*256+_[1];if(O===28160)return{return_code:O,error_message:"This command is only available in the Dashboard"};let B=L.slice(0,4).toString("hex"),G=4,j=L[G];G+=1;let X=L.slice(G,G+j).toString();G+=j;let F=L[G];G+=1;let J=L.slice(G,G+F).toString("hex");G+=F;let W=L[G];G+=1;let Q=L.slice(G,G+W);if(Q[W-1]===0)Q=L.slice(G,G+W-1);let T=Q.toString();return{return_code:O,error_message:U(O),targetId:B,seVersion:X,flag:J,mcuVersion:T}},M)}async publicKey(L){try{let _=await this.serializePath(L);switch(this.versionResponse.major){case 1:return F0(this,_);case 2:{let O=Buffer.concat([I.serializeHRP("thor"),_]);return W0(this,O)}default:return{return_code:25600,error_message:"App Version is not supported"}}}catch(_){return M(_)}}async getAddressAndPubKey(L,_,O=!1){return this.serializePath(L).then((B)=>{let G=Buffer.concat([I.serializeHRP(_),B]);return this.transport.send(E,K.GET_ADDR_SECP256K1,O?u.SHOW_ADDRESS_IN_DEVICE:u.ONLY_RETRIEVE,0,G,[R.NoError]).then((j)=>{let X=j.slice(-2),F=X[0]*256+X[1],J=Buffer.from(j.slice(0,33));return{bech32_address:Buffer.from(j.slice(33,-2)).toString(),compressed_pk:J,return_code:F,error_message:U(F)}},M)}).catch((B)=>M(B))}showAddressAndPubKey(L,_){return this.getAddressAndPubKey(L,_,!0)}signSendChunk(L,_,O,B=C.JSON){switch(this.versionResponse.major){case 1:return d(this,L,_,O,B);case 2:return J0(this,L,_,O,B);default:return{return_code:25600,error_message:"App Version is not supported"}}}async sign(L,_,O=C.JSON){let B=Buffer.from(_),G=[],j;try{G=await this.signGetChunks(L,B),j=await this.signSendChunk(1,G.length,G[0],O)}catch(F){M(F)}let X={return_code:j.return_code,error_message:j.error_message,signature:null};for(let F=1;F<G.length;F+=1)if(X=await this.signSendChunk(1+F,G.length,G[F],O),X.return_code!==R.NoError)break;return{return_code:X.return_code,error_message:X.error_message,signature:X.signature}}}import{SwapKitError as i}from"@swapkit/helpers";var p=()=>navigator?.usb,i0=async()=>{let L=p();if(typeof L?.getDevices!=="function")return[];let{ledgerUSBVendorId:_}=await import("@ledgerhq/devices"),B=(await L?.getDevices()).filter((G)=>G.vendorId===_);if(B.length>0)return B[0];return L?.requestDevice({filters:[{vendorId:_}]})},N=async()=>{let L=await i0();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 _=L.configurations[0].interfaces.find(({alternates:F})=>F.some(({interfaceClass:J})=>J===255));if(!_)throw await L.close(),new i("wallet_ledger_connection_error");try{await L.claimInterface(_.interfaceNumber)}catch(F){throw await L.close(),new i("wallet_ledger_connection_claimed",F)}let{default:O}=await import("@ledgerhq/hw-transport-webusb");if(!await O.isSupported())throw new Error("WebUSB not supported");let{DisconnectedDevice:G}=await import("@ledgerhq/errors"),j=new O(L,_.interfaceNumber),X=(F)=>{if(L===F.device)p()?.removeEventListener("disconnect",X),j._emitDisconnect(new G)};return p()?.addEventListener("disconnect",X),j};class l{ledgerTimeout=50000;derivationPath=p0.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 I(this.transport):this.ledgerApp;break}case"cosmos":{let{default:_}=await import("@ledgerhq/hw-app-cosmos");this.ledgerApp=L||!this.ledgerApp?new _(this.transport):this.ledgerApp}}return this.ledgerApp}catch(_){throw new t("wallet_ledger_connection_error",_)}};validateResponse=(L,_)=>{switch(L){case o.NoError:return;case o.LockedDevice:throw new t("wallet_ledger_device_locked",{message:`Ledger is locked: ${_}`});case o.TC_NotFound:throw new t("wallet_ledger_device_not_found");default:{console.error(`Ledger error: ${L} ${_}`);break}}}}class n extends l{pubKey=null;derivationPath;constructor(L=o0.GAIA){super();this.chain="cosmos",this.derivationPath=t0(L)}connect=async()=>{await this.checkOrCreateTransportAndLedger(!0);let{publicKey:L,address:_}=await this.getAddressAndPubKey();return this.pubKey=Buffer.from(L,"hex").toString("base64"),_};getAddressAndPubKey=async()=>{return await this.checkOrCreateTransportAndLedger(!0),await this.ledgerApp.getAddress(this.derivationPath,this.chain)};signTransaction=async(L,_="0")=>{await this.checkOrCreateTransportAndLedger(!0);let{return_code:O,error_message:B,signature:G}=await this.ledgerApp.sign(this.derivationPath,L);if(!this.pubKey)throw new Error("Public Key not found");return this.validateResponse(O,B),[{pub_key:{type:"tendermint/PubKeySecp256k1",value:this.pubKey},sequence:_,signature:G}]};signAmino=async(L,_)=>{await this.checkOrCreateTransportAndLedger(!0);let O=await this.getAccounts();if(O.findIndex((Q)=>Q.address===L)===-1)throw new Error(`Address ${L} not found in wallet`);let{encodeSecp256k1Signature:G,serializeSignDoc:j}=await import("@cosmjs/amino"),{Secp256k1Signature:X}=await import("@cosmjs/crypto"),F=j(_),J=await this.ledgerApp.sign(this.derivationPath,F);this.validateResponse(J.return_code,J.error_message);let W=X.fromDer(J.signature).toFixedLength();return{signed:_,signature:G(O[0].pubkey,W)}};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 w,NetworkDerivationPath as n0,derivationPathToString as a0}from"@swapkit/helpers";import{AbstractSigner as s0}from"ethers";class y extends s0{chainId=w.Ethereum;derivationPath="";ledgerApp=null;ledgerTimeout=50000;constructor({provider:L,derivationPath:_=n0.OP,chainId:O=w.Optimism}){super(L);this.chainId=O||w.Ethereum,this.derivationPath=typeof _==="string"?_:a0(_),Object.defineProperty(this,"provider",{enumerable:!0,value:L||null,writable:!1})}connect=(L)=>new y({provider:L,derivationPath:this.derivationPath,chainId:this.chainId});checkOrCreateTransportAndLedger=async()=>{if(this.ledgerApp)return;await this.createTransportAndLedger()};createTransportAndLedger=async()=>{let L=await N(),{default:_}=await import("@ledgerhq/hw-app-eth");this.ledgerApp=new _(L)};getAddress=async()=>{let L=await this.getAddressAndPubKey();if(!L)throw new Error("Could not get Address");return L.address};getAddressAndPubKey=async()=>{return await this.createTransportAndLedger(),this.ledgerApp?.getAddress(this.derivationPath)};showAddressAndPubKey=async()=>{return await this.createTransportAndLedger(),this.ledgerApp?.getAddress(this.derivationPath,!0)};signMessage=async(L)=>{let{Signature:_}=await import("ethers");await this.createTransportAndLedger();let O=await this.ledgerApp?.signPersonalMessage(this.derivationPath,L);if(!O)throw new Error("Signing failed");return O.r=`0x${O.r}`,O.s=`0x${O.s}`,_.from(O).serialized};sendTransaction=async(L)=>{if(!this.provider)throw new Error("No provider set");let _=await this.signTransaction(L);return await this.provider.broadcastTransaction(_)};signTypedData(){throw new Error("Method not implemented.")}signTransaction=async(L)=>{let{Transaction:_}=await import("ethers");await this.createTransportAndLedger();let O=await this.provider?.getTransactionCount(L.from||await this.getAddress()),B={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||O||0).toString()):O,to:L.to?.toString(),value:L.value,type:L.type&&!Number.isNaN(L.type)?L.type:L.maxFeePerGas?2:0},G=_.from(B).unsignedSerialized.slice(2),{ledgerService:j}=await import("@ledgerhq/hw-app-eth"),X=await j.resolveTransaction(G,{},{externalPlugins:!0,erc20:!0}),F=await this.ledgerApp?.signTransaction(this.derivationPath,G,X);if(!F)throw new Error("Could not sign transaction");let{r:J,s:W,v:Q}=F;return _.from({...B,signature:{v:Number(BigInt(Q)),r:`0x${J}`,s:`0x${W}`}}).serialized}}var $0=({provider:L,derivationPath:_})=>new y({chainId:w.Ethereum,provider:L,derivationPath:_}),Q0=({provider:L,derivationPath:_})=>new y({chainId:w.Avalanche,provider:L,derivationPath:_}),Y0=({provider:L,derivationPath:_})=>new y({chainId:w.BinanceSmartChain,provider:L,derivationPath:_}),Z0=({provider:L,derivationPath:_})=>new y({chainId:w.Arbitrum,provider:L,derivationPath:_}),H0=({provider:L,derivationPath:_})=>new y({chainId:w.Polygon,provider:L,derivationPath:_}),m0=({provider:L,derivationPath:_})=>new y({chainId:w.Optimism,provider:L,derivationPath:_}),M0=({provider:L,derivationPath:_})=>new y({chainId:w.Base,provider:L,derivationPath:_});import{base64 as e0}from"@scure/base";import{NetworkDerivationPath as L2}from"@swapkit/helpers";import{base64 as r0}from"@scure/base";var a=(L)=>{if(L.length<64)throw new Error("Invalid Signature: Too short");if(L[0]!==48)throw new Error("Invalid Ledger Signature TLV encoding: expected first byte 0x30");if(L[1]+2!==L.length)throw new Error("Invalid Signature: signature length does not match TLV");if(L[2]!==2)throw new Error("Invalid Ledger Signature TLV encoding: expected length type 0x02");let _=L[3],O=L.slice(4,_+4);if(O.length===33&&O[0]===0)O=O.slice(1,33);else if(O.length===33)throw new Error('Invalid signature: "r" too long');while(O.length<32)O.unshift(0);if(L[_+4]!==2)throw new Error("Invalid Ledger Signature TLV encoding: expected length type 0x02");let B=L[_+5];if(4+_+2+B!==L.length)throw new Error("Invalid Ledger Signature: TLV byte lengths do not match message length");let G=L.slice(_+6,L.length);if(G.length===33&&G[0]===0)G=G.slice(1,33);else if(G.length===33)throw new Error('Invalid signature: "s" too long');while(G.length<32)G.unshift(0);if(O.length!==32||G.length!==32)throw new Error("Invalid signatures: must be 32 bytes each");return r0.encode(Buffer.concat([O,G]))};class s extends l{pubKey=null;derivationPath;constructor(L=L2.THOR){super();this.chain="thor",this.derivationPath=L}get pubkey(){return this.pubKey}connect=async()=>{await this.checkOrCreateTransportAndLedger();let{compressed_pk:L,bech32_address:_}=await this.getAddressAndPubKey();return this.pubKey=e0.encode(L),_};getAddressAndPubKey=async()=>{await this.checkOrCreateTransportAndLedger(!0);let L=await this.ledgerApp.getAddressAndPubKey(this.derivationPath,this.chain);return this.validateResponse(L.return_code,L.error_message),L};showAddressAndPubKey=async()=>{await this.checkOrCreateTransportAndLedger(!0);let L=await this.ledgerApp.showAddressAndPubKey(this.derivationPath,this.chain);return this.validateResponse(L.return_code,L.error_message),L};signTransaction=async(L,_="0")=>{await this.checkOrCreateTransportAndLedger(!0);let{return_code:O,error_message:B,signature:G}=await this.ledgerApp.sign(this.derivationPath,L);if(!this.pubKey)throw new Error("Public Key not found");return this.validateResponse(O,B),[{pub_key:{type:"tendermint/PubKeySecp256k1",value:this.pubKey},sequence:_,signature:a(G)}]};sign=async(L)=>{await this.checkOrCreateTransportAndLedger(!0);let{return_code:_,error_message:O,signature:B}=await this.ledgerApp.sign(this.derivationPath,L);if(!this.pubKey)throw new Error("Public Key not found");return this.validateResponse(_,O),a(B)}}import{SwapKitError as T0,derivationPathToString as _2,getWalletFormatFor as O2}from"@swapkit/helpers";var G2=async({psbt:L,inputUtxos:_,btcApp:O,derivationPath:B},G)=>{let{Transaction:j}=await import("bitcoinjs-lib"),X=_.map((T)=>{let D=j.fromHex(T.txHex||"");return[O.splitTransaction(D.toHex(),D.hasWitnesses()),T.index,void 0,void 0]}),F=L.data.globalMap.unsignedTx.toBuffer().toString("hex"),J=O.splitTransaction(F,!0),W=O.serializeTransactionOutputs(J).toString("hex"),Q={additionals:["bech32"],associatedKeysets:X.map(()=>B),inputs:X,outputScriptHex:W,segwit:!0,useTrustedInputForSegwit:!0};return O.createPaymentTransaction({...Q,...G})},V=({chain:L,additionalSignParams:_})=>{let O,B=null;async function G(X=!0){if(X&&!O)new T0("wallet_ledger_connection_error",{message:`Ledger connection failed:
|
|
2
|
-
${JSON.stringify({checkBtcApp:
|
|
1
|
+
import{a as I0}from"../../chunk-ebfkk1jn.js";import{c as j,d as J}from"../../chunk-38ztynv0.js";import{Chain as F,ChainId as wL,FeeOption as DL,SKConfig as _0,StagenetChain as qL,SwapKitError as I,WalletOption as K0,createWallet as zL,filterSupportedChains as fL}from"@swapkit/helpers";import{Chain as Q,SwapKitError as a0,WalletOption as s0}from"@swapkit/helpers";var S=async({chain:L,ledgerClient:m})=>{if(!m)return"";switch(L){case Q.Cosmos:case Q.THORChain:return m.connect();case Q.Ethereum:case Q.BinanceSmartChain:case Q.Avalanche:case Q.Polygon:case Q.Arbitrum:case Q.Optimism:case Q.Base:return m.getAddress();case Q.Bitcoin:case Q.BitcoinCash:case Q.Dash:case Q.Dogecoin:case Q.Litecoin:{let _=m;await _.connect();let O=await _.getAddress();return L===Q.BitcoinCash?O.replace("bitcoincash:",""):O}case Q.Ripple:return m.address;default:throw new a0("wallet_chain_not_supported",{wallet:s0.LEDGER,chain:L})}};import{Chain as $,SwapKitError as CL,WalletOption as NL}from"@swapkit/helpers";import{NetworkDerivationPath as _L,SwapKitError as Q0,derivationPathToString as yL}from"@swapkit/helpers";import{LedgerErrorCode as s,NetworkDerivationPath as mL,SwapKitError as r}from"@swapkit/helpers";import{SwapKitError as $0}from"@swapkit/helpers";var A=85,t=250;var f={GET_VERSION:0,INS_PUBLIC_KEY_SECP256K1:1,SIGN_SECP256K1:2,GET_ADDR_SECP256K1:4},x={INIT:0,ADD:1,LAST:2},n={ONLY_RETRIEVE:0,SHOW_ADDRESS_IN_DEVICE:1},K={JSON:0},C={NoError:36864},G0={1:"U2F: Unknown",2:"U2F: Bad request",3:"U2F: Configuration unsupported",4:"U2F: Device Ineligible",5:"U2F: Timeout",14:"Timeout",36864:"No errors",36865:"Device is busy",26626:"Error deriving keys",25600:"Execution Error",26368:"Wrong Length",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"};function Z(L){if(L in G0)return G0[L];return`Unknown Status Code: ${L}`}function r0(L){return typeof L==="object"&&L!==null&&!Array.isArray(L)&&!(L instanceof Date)}function Y(L){if(L){if(r0(L)){if(Object.prototype.hasOwnProperty.call(L,"statusCode"))return{return_code:L.statusCode,error_message:Z(L.statusCode)};if(Object.prototype.hasOwnProperty.call(L,"return_code")&&Object.prototype.hasOwnProperty.call(L,"error_message"))return L}return{return_code:65535,error_message:L.toString()}}return{return_code:65535,error_message:L.toString()}}async function o(L){return L.send(85,f.GET_VERSION,0,0).then((m)=>{let _=m.slice(-2),O=_[0]*256+_[1],y=0;if(m.length>=9)y=(m[5]<<24)+(m[6]<<16)+(m[7]<<8)+(m[8]<<0);return{return_code:O,error_message:Z(O),test_mode:m[0]!==0,major:m[1],minor:m[2],patch:m[3],device_locked:m[4]===1,target_id:y.toString(16)}},Y)}import{SwapKitError as g}from"@swapkit/helpers";function F0(L){if(L==null||L.length<3)throw new g("wallet_ledger_invalid_params",{reason:"Path too short"});if(L.length>10)throw new g("wallet_ledger_invalid_params",{reason:"Path too long"});let m=Buffer.alloc(1+4*L.length);m.writeUInt8(L.length,0);for(let _=0;_<L.length;_+=1){let O=L[_]||0;if(_<3)O|=2147483648;m.writeInt32LE(O,1+_*4)}return m}async function p(L,m,_,O,y=K.JSON){return L.transport.send(A,f.SIGN_SECP256K1,m,y,O,[C.NoError,27012,27264]).then((T)=>{let B=T.slice(-2),X=B[0]*256+B[1],G=Z(X);if(X===27264||X===27012)G=`${G} : ${T.slice(0,T.length-2).toString("ascii")}`;let R=null;if(T.length>2)R=T.slice(0,T.length-2);return{signature:R,return_code:X,error_message:G}},Y)}function e0(L){if(L.length!==65)throw new g("wallet_ledger_invalid_params",{reason:"decompressed public key length should be 65 bytes"});let m=L.slice(33,65),_=Buffer.from([2+(m[m.length-1]&1)]);return Buffer.concat([_,L.slice(1,33)])}async function R0(L,m){return L.transport.send(A,f.INS_PUBLIC_KEY_SECP256K1,0,0,m,[C.NoError]).then((_)=>{let O=_.slice(-2),y=O[0]*256+O[1],T=Buffer.from(_.slice(0,65));return{pk:T,compressed_pk:e0(T),return_code:y,error_message:Z(y)}},Y)}function W0(L){if(!L||L.length!==5)throw new g("wallet_ledger_invalid_params",{reason:"Path must be exactly 5 elements"});let m=Buffer.alloc(20);return m.writeUInt32LE(2147483648+L[0],0),m.writeUInt32LE(2147483648+L[1],4),m.writeUInt32LE(2147483648+L[2],8),m.writeUInt32LE(L[3],12),m.writeUInt32LE(L[4],16),m}function j0(L,m,_,O,y=K.JSON){let T=x.ADD;if(m===1)T=x.INIT;if(m===_)T=x.LAST;return p(L,T,0,O,y)}async function J0(L,m){return L.transport.send(A,f.GET_ADDR_SECP256K1,0,0,m,[C.NoError]).then((_)=>{let O=_.slice(-2),y=O[0]*256+O[1];return{pk:"OBSOLETE PROPERTY",compressed_pk:Buffer.from(_.slice(0,33)),return_code:y,error_message:Z(y)}},Y)}class E{transport;versionResponse;constructor(L){if(!L)throw new $0("wallet_ledger_transport_not_defined");this.transport=L}static serializeHRP(L){if(L==null||L.length<3||L.length>83)throw new $0("wallet_ledger_invalid_params",{reason:"Invalid HRP"});let m=Buffer.alloc(1+L.length);return m.writeUInt8(L.length,0),m.write(L,1),m}async serializePath(L){if(this.versionResponse=await o(this.transport),this.versionResponse.return_code!==C.NoError)throw this.versionResponse;switch(this.versionResponse.major){case 1:return F0(L);case 2:return W0(L);default:return Buffer.alloc(0)}}async signGetChunks(L,m){let _=await this.serializePath(L),O=[];O.push(_);for(let y=0;y<m.length;y+=t){let T=y+t;if(y>m.length)T=m.length;O.push(m.slice(y,T))}return O}async getVersion(){try{return this.versionResponse=await o(this.transport),this.versionResponse}catch(L){return Y(L)}}async appInfo(){return this.transport.send(176,1,0,0).then((L)=>{let m=L.slice(-2),_=m[0]*256+m[1],O="",y="",T=0,B=0;if(L[0]!==1)return{return_code:36865,error_message:"response format ID not recognized"};let X=L[1];O=L.slice(2,2+X).toString("ascii");let G=2+X,R=L[G];G+=1,y=L.slice(G,G+R).toString("ascii"),G+=R;let W=L[G];return G+=1,T=W,B=L[G],{return_code:_,error_message:Z(_),appName:O,appVersion:y,flagLen:T,flagsValue:B,flag_recovery:(B&1)!==0,flag_signed_mcu_code:(B&2)!==0,flag_onboarded:(B&4)!==0,flag_pin_validated:(B&128)!==0}},Y)}async deviceInfo(){return this.transport.send(224,1,0,0,Buffer.from([]),[C.NoError,28160]).then((L)=>{let m=L.slice(-2),_=m[0]*256+m[1];if(_===28160)return{return_code:_,error_message:"This command is only available in the Dashboard"};let O=L.slice(0,4).toString("hex"),y=4,T=L[y];y+=1;let B=L.slice(y,y+T).toString();y+=T;let X=L[y];y+=1;let G=L.slice(y,y+X).toString("hex");y+=X;let R=L[y];y+=1;let W=L.slice(y,y+R);if(W[R-1]===0)W=L.slice(y,y+R-1);let M=W.toString();return{return_code:_,error_message:Z(_),targetId:O,seVersion:B,flag:G,mcuVersion:M}},Y)}async publicKey(L){try{let m=await this.serializePath(L);switch(this.versionResponse.major){case 1:return R0(this,m);case 2:{let _=Buffer.concat([E.serializeHRP("thor"),m]);return J0(this,_)}default:return{return_code:25600,error_message:"App Version is not supported"}}}catch(m){return Y(m)}}async getAddressAndPubKey(L,m,_=!1){return this.serializePath(L).then((O)=>{let y=Buffer.concat([E.serializeHRP(m),O]);return this.transport.send(A,f.GET_ADDR_SECP256K1,_?n.SHOW_ADDRESS_IN_DEVICE:n.ONLY_RETRIEVE,0,y,[C.NoError]).then((T)=>{let B=T.slice(-2),X=B[0]*256+B[1],G=Buffer.from(T.slice(0,33));return{bech32_address:Buffer.from(T.slice(33,-2)).toString(),compressed_pk:G,return_code:X,error_message:Z(X)}},Y)}).catch((O)=>Y(O))}showAddressAndPubKey(L,m){return this.getAddressAndPubKey(L,m,!0)}signSendChunk(L,m,_,O=K.JSON){switch(this.versionResponse.major){case 1:return p(this,L,m,_,O);case 2:return j0(this,L,m,_,O);default:return{return_code:25600,error_message:"App Version is not supported"}}}async sign(L,m,_=K.JSON){let O=Buffer.from(m),y=[],T;try{y=await this.signGetChunks(L,O),T=await this.signSendChunk(1,y.length,y[0],_)}catch(X){Y(X)}let B={return_code:T.return_code,error_message:T.error_message,signature:null};for(let X=1;X<y.length;X+=1)if(B=await this.signSendChunk(1+X,y.length,y[X],_),B.return_code!==C.NoError)break;return{return_code:B.return_code,error_message:B.error_message,signature:B.signature}}}import{SwapKitError as c}from"@swapkit/helpers";var a=()=>navigator?.usb,LL=async()=>{let L=a();if(typeof L?.getDevices!=="function")return[];let{ledgerUSBVendorId:m}=await import("@ledgerhq/devices"),O=(await L?.getDevices()).filter((y)=>y.vendorId===m);if(O.length>0)return O[0];return L?.requestDevice({filters:[{vendorId:m}]})},H=async()=>{let L=await LL();if(!L)throw new c("wallet_ledger_device_not_found");if(await L.open(),L.configuration===null)await L.selectConfiguration(1);try{await L.reset()}catch{}let m=L.configurations[0].interfaces.find(({alternates:X})=>X.some(({interfaceClass:G})=>G===255));if(!m)throw await L.close(),new c("wallet_ledger_connection_error");try{await L.claimInterface(m.interfaceNumber)}catch(X){throw await L.close(),new c("wallet_ledger_connection_claimed",X)}let _=(await import("@ledgerhq/hw-transport-webusb")).default;if(!await _.isSupported())throw new c("wallet_ledger_webusb_not_supported");let{DisconnectedDevice:y}=await import("@ledgerhq/errors"),T=new _(L,m.interfaceNumber),B=(X)=>{if(L===X.device)a()?.removeEventListener("disconnect",B),T._emitDisconnect(new y)};return a()?.addEventListener("disconnect",B),T};class V{ledgerTimeout=50000;derivationPath=mL.GAIA;transport;ledgerApp;chain="thor";checkOrCreateTransportAndLedger=async(L=!1)=>{if(!L&&this.transport&&this.ledgerApp)return;try{switch(this.transport=L||!this.transport?await H():this.transport,this.chain){case"thor":{this.ledgerApp=L||!this.ledgerApp?new E(this.transport):this.ledgerApp;break}case"cosmos":{let m=(await import("@ledgerhq/hw-app-cosmos")).default;this.ledgerApp=L||!this.ledgerApp?new m(this.transport):this.ledgerApp}}return this.ledgerApp}catch(m){throw new r("wallet_ledger_connection_error",m)}};validateResponse=(L,m)=>{switch(L){case s.NoError:return;case s.LockedDevice:throw new r("wallet_ledger_device_locked",{message:`Ledger is locked: ${m}`});case s.TC_NotFound:throw new r("wallet_ledger_device_not_found");default:break}}}class e extends V{pubKey=null;derivationPath;constructor(L=_L.GAIA){super();this.chain="cosmos",this.derivationPath=yL(L)}connect=async()=>{await this.checkOrCreateTransportAndLedger(!0);let{publicKey:L,address:m}=await this.getAddressAndPubKey();return this.pubKey=Buffer.from(L,"hex").toString("base64"),m};getAddressAndPubKey=async()=>{return await this.checkOrCreateTransportAndLedger(!0),await this.ledgerApp.getAddress(this.derivationPath,this.chain)};signTransaction=async(L,m="0")=>{await this.checkOrCreateTransportAndLedger(!0);let{return_code:_,error_message:O,signature:y}=await this.ledgerApp.sign(this.derivationPath,L);if(!this.pubKey)throw new Q0("wallet_ledger_pubkey_not_found");return this.validateResponse(_,O),[{pub_key:{type:"tendermint/PubKeySecp256k1",value:this.pubKey},sequence:m,signature:y}]};signAmino=async(L,m)=>{await this.checkOrCreateTransportAndLedger(!0);let _=await this.getAccounts();if(_.findIndex((W)=>W.address===L)===-1)throw new Q0("wallet_ledger_address_not_found",{address:L});let{encodeSecp256k1Signature:y,serializeSignDoc:T}=(await import("@cosmjs/amino")).default,{Secp256k1Signature:B}=(await import("@cosmjs/crypto")).default,X=T(m),G=await this.ledgerApp.sign(this.derivationPath,X);this.validateResponse(G.return_code,G.error_message);let R=B.fromDer(G.signature).toFixedLength();return{signed:m,signature:y(_[0].pubkey,R)}};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 U,NetworkDerivationPath as OL,SwapKitError as b,derivationPathToString as TL}from"@swapkit/helpers";import{AbstractSigner as XL}from"ethers";class N extends XL{chainId=U.Ethereum;derivationPath="";ledgerApp=null;ledgerTimeout=50000;constructor({provider:L,derivationPath:m=OL.OP,chainId:_=U.Optimism}){super(L);this.chainId=_||U.Ethereum,this.derivationPath=typeof m==="string"?m:TL(m),Object.defineProperty(this,"provider",{enumerable:!0,value:L||null,writable:!1})}connect=(L)=>new N({provider:L,derivationPath:this.derivationPath,chainId:this.chainId});checkOrCreateTransportAndLedger=async()=>{if(this.ledgerApp)return;await this.createTransportAndLedger()};createTransportAndLedger=async()=>{let L=await H(),m=(await import("@ledgerhq/hw-app-eth")).default;this.ledgerApp=new m(L)};getAddress=async()=>{let L=await this.getAddressAndPubKey();if(!L)throw new b("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:m}=await import("ethers");await this.createTransportAndLedger();let _=await this.ledgerApp?.signPersonalMessage(this.derivationPath,L);if(!_)throw new b("wallet_ledger_signing_error");return _.r=`0x${_.r}`,_.s=`0x${_.s}`,m.from(_).serialized};sendTransaction=async(L)=>{if(!this.provider)throw new b("wallet_ledger_no_provider");let m=await this.signTransaction(L);return await this.provider.broadcastTransaction(m)};signTypedData(){throw new b("wallet_ledger_method_not_supported",{method:"signTypedData"})}signTransaction=async(L)=>{let{Transaction:m}=await import("ethers");await this.createTransportAndLedger();let _=await this.provider?.getTransactionCount(L.from||await this.getAddress()),O={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(),value:L.value,type:L.type&&!Number.isNaN(L.type)?L.type:L.maxFeePerGas?2:0},y=m.from(O).unsignedSerialized.slice(2),{ledgerService:T}=await import("@ledgerhq/hw-app-eth"),B=await T.resolveTransaction(y,{},{externalPlugins:!0,erc20:!0}),X=await this.ledgerApp?.signTransaction(this.derivationPath,y,B);if(!X)throw new b("wallet_ledger_signing_error");let{r:G,s:R,v:W}=X;return m.from({...O,signature:{v:Number(BigInt(W)),r:`0x${G}`,s:`0x${R}`}}).serialized}}var Y0=({provider:L,derivationPath:m})=>new N({chainId:U.Ethereum,provider:L,derivationPath:m}),M0=({provider:L,derivationPath:m})=>new N({chainId:U.Avalanche,provider:L,derivationPath:m}),Z0=({provider:L,derivationPath:m})=>new N({chainId:U.BinanceSmartChain,provider:L,derivationPath:m}),H0=({provider:L,derivationPath:m})=>new N({chainId:U.Arbitrum,provider:L,derivationPath:m}),U0=({provider:L,derivationPath:m})=>new N({chainId:U.Polygon,provider:L,derivationPath:m}),C0=({provider:L,derivationPath:m})=>new N({chainId:U.Optimism,provider:L,derivationPath:m}),N0=({provider:L,derivationPath:m})=>new N({chainId:U.Base,provider:L,derivationPath:m});import{base64 as GL}from"@scure/base";import{NetworkDerivationPath as FL,SwapKitError as w0}from"@swapkit/helpers";import{base64 as BL}from"@scure/base";import{SwapKitError as w}from"@swapkit/helpers";var L0=(L)=>{if(L.length<64)throw new w("wallet_ledger_invalid_signature",{reason:"Too short"});if(L[0]!==48)throw new w("wallet_ledger_invalid_signature",{reason:"TLV encoding: expected first byte 0x30"});if(L[1]+2!==L.length)throw new w("wallet_ledger_invalid_signature",{reason:"signature length does not match TLV"});if(L[2]!==2)throw new w("wallet_ledger_invalid_signature",{reason:"TLV encoding: expected length type 0x02"});let m=L[3],_=L.slice(4,m+4);if(_.length===33&&_[0]===0)_=_.slice(1,33);else if(_.length===33)throw new w("wallet_ledger_invalid_signature",{reason:"r too long"});while(_.length<32)_.unshift(0);if(L[m+4]!==2)throw new w("wallet_ledger_invalid_signature",{reason:"TLV encoding: expected length type 0x02 for s"});let O=L[m+5];if(4+m+2+O!==L.length)throw new w("wallet_ledger_invalid_signature",{reason:"TLV byte lengths do not match message length"});let y=L.slice(m+6,L.length);if(y.length===33&&y[0]===0)y=y.slice(1,33);else if(y.length===33)throw new w("wallet_ledger_invalid_signature",{reason:"s too long"});while(y.length<32)y.unshift(0);if(_.length!==32||y.length!==32)throw new w("wallet_ledger_invalid_signature",{reason:"must be 32 bytes each"});return BL.encode(Buffer.concat([_,y]))};class m0 extends V{pubKey=null;derivationPath;constructor(L=FL.THOR){super();this.chain="thor",this.derivationPath=L}get pubkey(){return this.pubKey}connect=async()=>{await this.checkOrCreateTransportAndLedger();let{compressed_pk:L,bech32_address:m}=await this.getAddressAndPubKey();return this.pubKey=GL.encode(L),m};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,m="0")=>{await this.checkOrCreateTransportAndLedger(!0);let{return_code:_,error_message:O,signature:y}=await this.ledgerApp.sign(this.derivationPath,L);if(!this.pubKey)throw new w0("wallet_ledger_pubkey_not_found");return this.validateResponse(_,O),[{pub_key:{type:"tendermint/PubKeySecp256k1",value:this.pubKey},sequence:m,signature:L0(y)}]};sign=async(L)=>{await this.checkOrCreateTransportAndLedger(!0);let{return_code:m,error_message:_,signature:O}=await this.ledgerApp.sign(this.derivationPath,L);if(!this.pubKey)throw new w0("wallet_ledger_pubkey_not_found");return this.validateResponse(m,_),L0(O)}}import{SwapKitError as D0,derivationPathToString as RL,getWalletFormatFor as WL}from"@swapkit/helpers";import{Transaction as jL}from"bitcoinjs-lib";var JL=async({psbt:L,inputUtxos:m,btcApp:_,derivationPath:O},y)=>{let T=m.map((W)=>{let M=jL.fromHex(W.txHex||"");return[_.splitTransaction(M.toHex(),M.hasWitnesses()),W.index,void 0,void 0]}),B=L.data.globalMap.unsignedTx.toBuffer().toString("hex"),X=_.splitTransaction(B,!0),G=_.serializeTransactionOutputs(X).toString("hex"),R={additionals:["bech32"],associatedKeysets:T.map(()=>O),inputs:T,outputScriptHex:G,segwit:!0,useTrustedInputForSegwit:!0};return _.createPaymentTransaction({...R,...y})},k=({chain:L,additionalSignParams:m})=>{let _,O=null;async function y(B=!0){if(B&&!_)new D0("wallet_ledger_connection_error",{message:`Ledger connection failed:
|
|
2
|
+
${JSON.stringify({checkBtcApp:B,btcApp:_})}`});O||=await H()}async function T(){O=await H(),_=new(await import("@ledgerhq/hw-app-btc")).default({transport:O,currency:L})}return(B)=>{let X=typeof B==="string"?B:RL(B),G=WL(X);return{connect:async()=>{await y(!1),_=new(await import("@ledgerhq/hw-app-btc")).default({transport:O,currency:L})},getExtendedPublicKey:async(R="84'/0'/0'",W=76067358)=>{return await y(!1),_.getWalletXpub({path:R,xpubVersion:W})},signTransaction:async(R,W)=>{return await T(),JL({psbt:R,derivationPath:X,btcApp:_,inputUtxos:W},m)},getAddress:async()=>{let{toCashAddress:R}=await import("@swapkit/toolboxes/utxo");await y(!1);let{bitcoinAddress:W}=await _.getWalletPublicKey(X,{format:G});if(!W)throw new D0("wallet_ledger_get_address_error",{message:`Cannot get ${L} address from ledger derivation path: ${X}`});return L==="bitcoin-cash"&&G==="legacy"?R(W).replace(/(bchtest:|bitcoincash:)/,""):W}}}},q0=k({chain:"bitcoin"}),z0=k({chain:"litecoin"}),f0=k({chain:"bitcoin-cash",additionalSignParams:{segwit:!1,additionals:["abc"],sigHashType:65}}),P0=k({chain:"dogecoin",additionalSignParams:{additionals:[],segwit:!1,useTrustedInputForSegwit:!1}}),l0=k({chain:"dash",additionalSignParams:{additionals:[],segwit:!1,useTrustedInputForSegwit:!1}});import{Chain as $L,NetworkDerivationPath as QL,derivationPathToString as YL}from"@swapkit/helpers";import{encode as S0}from"ripple-binary-codec";var ML=2147483648;function ZL(L){let m={};for(let _ in L)if(L[_]!==null&&L[_]!==void 0)m[_]=L[_];return m}async function HL(L){let{default:m}=await import("@ledgerhq/hw-app-xrp");return new m(L)}function UL({instance:L,derivationPath:m}){return L.getAddress(m)}var A0=async(L)=>{let m=YL(L||QL[$L.Ripple]),_=await H(),O=await HL(_),{address:y,publicKey:T}=await UL({instance:O,derivationPath:m});async function B(X){let{hashes:G}=await import("@swapkit/toolboxes/ripple"),W={...ZL(X),Flags:X.Flags||ML,SigningPubKey:T.toUpperCase()},M=S0(W),D=await O.signTransaction(m,M),q=S0({...W,TxnSignature:D}),l=G.hashSignedTx(q);return{tx_blob:q,hash:l}}return{address:y,sign:B}};var P=async({chain:L,derivationPath:m})=>{let{match:_}=await import("ts-pattern");return _(L).returnType().with($.THORChain,()=>Promise.resolve(new m0(m))).with($.Cosmos,()=>Promise.resolve(new e(m))).with($.Bitcoin,()=>Promise.resolve(q0(m))).with($.BitcoinCash,()=>Promise.resolve(f0(m))).with($.Dash,()=>Promise.resolve(l0(m))).with($.Dogecoin,()=>Promise.resolve(P0(m))).with($.Litecoin,()=>Promise.resolve(z0(m))).with($.Ripple,()=>Promise.resolve(A0(m))).with($.Arbitrum,$.Avalanche,$.BinanceSmartChain,$.Ethereum,$.Optimism,$.Polygon,$.Base,async()=>{let{getProvider:O}=await import("@swapkit/toolboxes/evm"),y={provider:await O(L),derivationPath:m};return _(L).with($.BinanceSmartChain,()=>Z0(y)).with($.Avalanche,()=>M0(y)).with($.Arbitrum,()=>H0(y)).with($.Optimism,()=>C0(y)).with($.Polygon,()=>U0(y)).with($.Base,()=>N0(y)).otherwise(()=>Y0(y))}).otherwise(()=>{throw new CL("wallet_chain_not_supported",{wallet:NL.LEDGER,chain:L})})};var PL=zL({name:"connectLedger",supportedChains:[F.Arbitrum,F.Avalanche,F.Base,F.BinanceSmartChain,F.Bitcoin,F.BitcoinCash,F.Cosmos,F.Dash,F.Dogecoin,F.Ethereum,F.Litecoin,F.Optimism,F.Polygon,F.Ripple,F.THORChain],walletType:K0.LEDGER,connect:({addChain:L,supportedChains:m,walletType:_})=>async function O(y,T){let[B]=fL({chains:y,supportedChains:m,walletType:_});if(!B)return!1;let X=await AL({chain:B,derivationPath:T});return L({...X,chain:B,walletType:K0.LEDGER}),!0}}),Im=I0(PL);function lL(L,m="t"){if(!L?.includes("=:"))return L;let _=L.includes(`:${m}:`)?L.split(`:${m}:`)[0]:L;return _?.substring(0,_.lastIndexOf(":"))}function v(L){if(Array.isArray(L))return L.forEach((O,y)=>{L[y]=v(O)}),L;if(typeof L!=="object")return L;let m={},_=Object.keys(L).sort();for(let O of _)m[O]=v(L[O]);return m}function SL(L){return JSON.stringify(v(L))}async function AL({chain:L,derivationPath:m}){switch(L){case F.BitcoinCash:case F.Bitcoin:case F.Dash:case F.Dogecoin:case F.Litecoin:{let{getUtxoToolbox:_}=await import("@swapkit/toolboxes/utxo"),O=await _(L),y=await P({chain:L,derivationPath:m}),T=await S({chain:L,ledgerClient:y});return{...O,address:T,transfer:async(X)=>{let G=X.feeRate||(await O.getFeeRates())[DL.Average],R=[F.Bitcoin].includes(L)?X.memo:lL(X.memo),{psbt:W,inputs:M}=await O.createTransaction({...X,feeRate:G,memo:R,sender:T,fetchTxHex:!0}),D=await y.signTransaction(W,M);return await O.broadcastTx(D)}}}case F.Ethereum:case F.Avalanche:case F.Arbitrum:case F.Optimism:case F.Polygon:case F.BinanceSmartChain:case F.Base:{let{getEvmToolbox:_}=await import("@swapkit/toolboxes/evm"),O=await P({chain:L,derivationPath:m}),y=await S({chain:L,ledgerClient:O});return{...await _(L,{signer:O}),address:y}}case F.Cosmos:{let{createSigningStargateClient:_,getMsgSendDenom:O,getCosmosToolbox:y}=await import("@swapkit/toolboxes/cosmos"),T=await y(F.Cosmos),B=await P({chain:L,derivationPath:m}),X=await S({chain:L,ledgerClient:B});return{...T,address:X,transfer:async({assetValue:R,recipient:W,memo:M})=>{if(!R)throw new I("wallet_ledger_invalid_asset");let D={amount:[{amount:R.getBaseValue("string"),denom:O(`u${R.symbol}`).toLowerCase()}],fromAddress:X,toAddress:W},q=await _(_0.get("rpcUrls")[L],B,"0.007uatom"),{transactionHash:l}=await q.signAndBroadcast(X,[{typeUrl:"/cosmos.bank.v1beta1.MsgSend",value:D}],2,M);return l}}}case F.THORChain:{let{SignMode:_}=await import("cosmjs-types/cosmos/tx/signing/v1beta1/signing.js"),{TxRaw:O}=await import("cosmjs-types/cosmos/tx/v1beta1/tx.js"),{encodePubkey:y,makeAuthInfoBytes:T}=(await import("@cosmjs/proto-signing")).default,{createStargateClient:B,buildEncodedTxBody:X,getCosmosToolbox:G,buildAminoMsg:R,getDefaultChainFee:W,fromBase64:M,parseAminoMessageForDirectSigning:D}=await import("@swapkit/toolboxes/cosmos"),q=await G(L),l=await P({chain:L,derivationPath:m}),h=await S({chain:L,ledgerClient:l}),u=W(L),{pubkey:y0,signTransaction:E0,sign:V0}=l,O0=async({memo:z="",assetValue:T0,...b0})=>{let X0=await q.getAccount(h);if(!X0)throw new I("wallet_ledger_invalid_account");if(!T0)throw new I("wallet_ledger_invalid_asset");if(!y0)throw new I("wallet_ledger_pubkey_not_found");let{accountNumber:k0,sequence:x0}=X0,i=(x0||0).toString(),B0=v([R({sender:h,assetValue:T0,memo:z,...b0})]),g0=SL({account_number:k0?.toString(),chain_id:wL.THORChain,fee:u,memo:z,msgs:B0,sequence:i}),d=await E0(g0,i);if(!d)throw new I("wallet_ledger_signing_error");let c0=y({type:"tendermint/PubKeySecp256k1",value:y0}),v0=B0.map(D),h0=await X({msgs:v0,chain:L,memo:z}),u0=T([{pubkey:c0,sequence:Number(i)}],u.amount,Number.parseInt(u.gas),void 0,void 0,_.SIGN_MODE_LEGACY_AMINO_JSON),i0=d?.[0]?.signature?M(d[0].signature):Uint8Array.from([]),d0=O.fromPartial({bodyBytes:h0,authInfoBytes:u0,signatures:[i0]}),t0=O.encode(d0).finish(),{isStagenet:n0}=_0.get("envs"),o0=await B(_0.get("rpcUrls")[n0?qL.THORChain:F.THORChain]),{transactionHash:p0}=await o0.broadcastTx(t0);return p0};return{...q,address:h,deposit:(z)=>O0(z),transfer:(z)=>O0(z),signMessage:V0}}case F.Ripple:{let{getRippleToolbox:_}=await import("@swapkit/toolboxes/ripple"),O=await P({chain:L,derivationPath:m}),y=O.address;return{...await _({signer:O}),address:y}}default:throw new I("wallet_ledger_chain_not_supported",{chain:L})}}export{PL as ledgerWallet,Im as LEDGER_SUPPORTED_CHAINS};
|
|
3
3
|
|
|
4
|
-
//# debugId=
|
|
4
|
+
//# debugId=D521F100B15D2FC164756E2164756E21
|