@xchainjs/xchain-thorchain 1.0.11 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.esm.js CHANGED
@@ -1,22 +1,23 @@
1
1
  import * as crypto$2 from '@cosmjs/crypto';
2
2
  import { EnglishMnemonic, Bip39, Slip10, Slip10Curve, Secp256k1 } from '@cosmjs/crypto';
3
3
  import * as encoding from '@cosmjs/encoding';
4
- import { fromBase64, toBase64 } from '@cosmjs/encoding';
4
+ import { toBase64, fromBase64 } from '@cosmjs/encoding';
5
5
  import * as protoSigning from '@cosmjs/proto-signing';
6
- import { decodeTxRaw, DirectSecp256k1HdWallet } from '@cosmjs/proto-signing';
6
+ import { decodeTxRaw, DirectSecp256k1HdWallet, encodePubkey, makeAuthInfoBytes } from '@cosmjs/proto-signing';
7
7
  import * as amino from '@cosmjs/amino';
8
8
  import * as axios from 'axios';
9
9
  import axios__default from 'axios';
10
- import { Client as Client$1, MsgTypes, makeClientPath, bech32ToBase64 } from '@xchainjs/xchain-cosmos-sdk';
10
+ import { Client as Client$1, bech32ToBase64, MsgTypes, makeClientPath, base64ToBech32 } from '@xchainjs/xchain-cosmos-sdk';
11
11
  import { createHash } from 'crypto';
12
12
  import * as buffer from 'buffer';
13
13
  import * as bignumber from 'bignumber.js';
14
14
  import { BigNumber } from 'bignumber.js';
15
15
  import { toWords as toWords$1, encode as encode$2 } from 'bech32';
16
- import { assetToString, isSynthAsset, assetToBase, assetAmount, eqAsset, assetFromString } from '@xchainjs/xchain-util';
17
16
  import { fromSeed } from 'bip32';
18
17
  import { publicKeyCreate } from 'secp256k1';
18
+ import { assetToString, isSynthAsset, assetToBase, assetAmount, eqAsset, assetFromString, assetFromStringEx } from '@xchainjs/xchain-util';
19
19
  import { Network } from '@xchainjs/xchain-client';
20
+ import THORChainApp, { extractSignatureFromTLV } from '@xchainjs/ledger-thorchain';
20
21
 
21
22
  /******************************************************************************
22
23
  Copyright (c) Microsoft Corporation.
@@ -127630,6 +127631,58 @@ const getPrefix = (network) => {
127630
127631
  return 'tthor';
127631
127632
  }
127632
127633
  };
127634
+ /**
127635
+ * Parse the derivation path from a string to an Array of numbers
127636
+ * @param {string} path - Path to parse
127637
+ * @returns {number[]} - The derivation path as Array of numbers
127638
+ */
127639
+ const parseDerivationPath = (path) => {
127640
+ if (!path.startsWith('m'))
127641
+ throw new Error("Path string must start with 'm'");
127642
+ let rest = path.slice(1);
127643
+ const out = new Array();
127644
+ while (rest) {
127645
+ const match = rest.match(/^\/([0-9]+)('?)/);
127646
+ if (!match)
127647
+ throw new Error('Syntax error while reading path component');
127648
+ const [fullMatch, numberString] = match;
127649
+ const value = build$6.Uint53.fromString(numberString).toNumber();
127650
+ if (value >= Math.pow(2, 31))
127651
+ throw new Error('Component value too high. Must not exceed 2**31-1.');
127652
+ out.push(value);
127653
+ rest = rest.slice(fullMatch.length);
127654
+ }
127655
+ return out;
127656
+ };
127657
+ /**
127658
+ * Sort JSON object
127659
+ * @param {any} obj - JSON object
127660
+ * @returns {any} JSON object sorted
127661
+ */
127662
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
127663
+ function sortedObject(obj) {
127664
+ if (typeof obj !== 'object' || obj === null) {
127665
+ return obj;
127666
+ }
127667
+ if (Array.isArray(obj)) {
127668
+ return obj.map(sortedObject);
127669
+ }
127670
+ const sortedKeys = Object.keys(obj).sort();
127671
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
127672
+ const result = {};
127673
+ // NOTE: Use forEach instead of reduce for performance with large objects eg Wasm code
127674
+ sortedKeys.forEach((key) => {
127675
+ result[key] = sortedObject(obj[key]);
127676
+ });
127677
+ return result;
127678
+ }
127679
+ /**
127680
+ * Returns a JSON string with objects sorted by key
127681
+ * */
127682
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
127683
+ function sortAndStringifyJson(obj) {
127684
+ return JSON.stringify(sortedObject(obj));
127685
+ }
127633
127686
 
127634
127687
  /**
127635
127688
  * Import necessary modules and types for the Thorchain client configuration.
@@ -127699,7 +127752,7 @@ const defaultClientConfig = {
127699
127752
  };
127700
127753
 
127701
127754
  /**
127702
- * Thorchain client
127755
+ * Thorchain base client
127703
127756
  */
127704
127757
  class Client extends Client$1 {
127705
127758
  /**
@@ -127710,53 +127763,6 @@ class Client extends Client$1 {
127710
127763
  constructor(config = defaultClientConfig) {
127711
127764
  super(Object.assign(Object.assign({}, defaultClientConfig), config));
127712
127765
  }
127713
- /**
127714
- * Asynchronous version of getAddress method.
127715
- * @param {number} index Derivation path index of the address to be generated.
127716
- * @returns {string} A promise that resolves to the generated address.
127717
- */
127718
- getAddressAsync(index = 0) {
127719
- return __awaiter(this, void 0, void 0, function* () {
127720
- return this.getAddress(index);
127721
- });
127722
- }
127723
- /**
127724
- * Get the address derived from the provided phrase.
127725
- * @param {number | undefined} walletIndex The index of the address derivation path. Default is 0.
127726
- * @returns {string} The user address at the specified walletIndex.
127727
- */
127728
- getAddress(walletIndex) {
127729
- const seed = getSeed(this.phrase);
127730
- const node = fromSeed(seed);
127731
- const child = node.derivePath(this.getFullDerivationPath(walletIndex || 0));
127732
- if (!child.privateKey)
127733
- throw new Error('child does not have a privateKey');
127734
- // TODO: Make this method async and use CosmosJS official address generation strategy
127735
- const pubKey = publicKeyCreate(child.privateKey);
127736
- const rawAddress = this.hash160(Uint8Array.from(pubKey));
127737
- const words = toWords$1(Buffer.from(rawAddress));
127738
- const address = encode$2(this.prefix, words);
127739
- return address;
127740
- }
127741
- transfer(params) {
127742
- return __awaiter(this, void 0, void 0, function* () {
127743
- const sender = yield this.getAddressAsync(params.walletIndex || 0);
127744
- const { rawUnsignedTx } = yield this.prepareTx({
127745
- sender,
127746
- recipient: params.recipient,
127747
- asset: params.asset,
127748
- amount: params.amount,
127749
- memo: params.memo,
127750
- });
127751
- const unsignedTx = decodeTxRaw(fromBase64(rawUnsignedTx));
127752
- const signer = yield DirectSecp256k1HdWallet.fromMnemonic(this.phrase, {
127753
- prefix: this.prefix,
127754
- hdPaths: [makeClientPath(this.getFullDerivationPath(params.walletIndex || 0))],
127755
- });
127756
- const tx = yield this.roundRobinSignAndBroadcastTx(sender, unsignedTx, signer);
127757
- return tx.transactionHash;
127758
- });
127759
- }
127760
127766
  /**
127761
127767
  * Get address prefix by network
127762
127768
  * @param {Network} network The network of which return the prefix
@@ -127877,60 +127883,70 @@ class Client extends Client$1 {
127877
127883
  });
127878
127884
  }
127879
127885
  /**
127880
- * Make a deposit
127886
+ * Get deposit transaction
127881
127887
  *
127882
- * @param {number} param.walletIndex Optional - The index to use to generate the address from the transaction will be done.
127883
- * If it is not set, address associated with index 0 will be used
127884
- * @param {Asset} param.asset Optional - The asset that will be deposit. If it is not set, Thorchain native asset will be
127885
- * used
127886
- * @param {BaseAmount} param.amount The amount that will be deposit
127887
- * @param {string} param.memo Optional - The memo associated with the deposit
127888
- * @param {BigNumber} param.gasLimit Optional - The limit amount of gas allowed to spend in the deposit. If not set, default
127889
- * value of 600000000 will be used
127890
- * @returns {string} The deposit hash
127888
+ * @deprecated Use getTransactionData instead
127889
+ * @param {string} txId The transaction ID for which to get the deposit transaction
127891
127890
  */
127892
- deposit({ walletIndex = 0, asset = AssetRuneNative, amount, memo, gasLimit = new BigNumber(DEPOSIT_GAS_LIMIT_VALUE), }) {
127891
+ getDepositTransaction(txId) {
127893
127892
  return __awaiter(this, void 0, void 0, function* () {
127894
- // Get sender address
127895
- const sender = yield this.getAddressAsync(walletIndex);
127896
- // Create signer
127897
- const signer = yield DirectSecp256k1HdWallet.fromMnemonic(this.phrase, {
127898
- prefix: this.prefix,
127899
- hdPaths: [makeClientPath(this.getFullDerivationPath(walletIndex || 0))],
127900
- });
127901
- const tx = yield this.roundRobinSignAndBroadcastDeposit(sender, signer, gasLimit, amount, memo, asset);
127902
- return tx.transactionHash;
127893
+ return this.getTransactionData(txId);
127903
127894
  });
127904
127895
  }
127905
127896
  /**
127906
- * Create and sign transaction without broadcasting it
127897
+ * Get the message type url by type used by the cosmos-sdk client to make certain actions
127907
127898
  *
127908
- * @deprecated Use prepare Tx instead
127899
+ * @param {MsgTypes} msgType The message type of which return the type url
127900
+ * @returns {string} the type url of the message
127909
127901
  */
127910
- transferOffline({ walletIndex = 0, recipient, asset, amount, memo, gasLimit = new BigNumber(DEFAULT_GAS_LIMIT_VALUE), }) {
127902
+ getMsgTypeUrlByType(msgType) {
127903
+ const messageTypeUrls = {
127904
+ [MsgTypes.TRANSFER]: MSG_SEND_TYPE_URL,
127905
+ };
127906
+ return messageTypeUrls[msgType];
127907
+ }
127908
+ /**
127909
+ * Returns the standard fee used by the client
127910
+ *
127911
+ * @returns {StdFee} the standard fee
127912
+ */
127913
+ getStandardFee() {
127914
+ return { amount: [], gas: '6000000' };
127915
+ }
127916
+ }
127917
+
127918
+ /**
127919
+ * Thorchain Keystore client
127920
+ */
127921
+ class ClientKeystore extends Client {
127922
+ /**
127923
+ * Asynchronous version of getAddress method.
127924
+ * @param {number} index Derivation path index of the address to be generated.
127925
+ * @returns {string} A promise that resolves to the generated address.
127926
+ */
127927
+ getAddressAsync(index = 0) {
127911
127928
  return __awaiter(this, void 0, void 0, function* () {
127912
- // Get sender address
127913
- const sender = yield this.getAddressAsync(walletIndex);
127914
- // Prepare unsigned transaction
127915
- const { rawUnsignedTx } = yield this.prepareTx({
127916
- sender,
127917
- recipient: recipient,
127918
- asset: asset,
127919
- amount: amount,
127920
- memo: memo,
127921
- });
127922
- // Decode unsigned transaction
127923
- const unsignedTx = decodeTxRaw(fromBase64(rawUnsignedTx));
127924
- // Create signer
127925
- const signer = yield DirectSecp256k1HdWallet.fromMnemonic(this.phrase, {
127926
- prefix: this.prefix,
127927
- hdPaths: [makeClientPath(this.getFullDerivationPath(walletIndex))],
127928
- });
127929
- const rawTx = yield this.roundRobinSign(sender, unsignedTx, signer, gasLimit);
127930
- // Return encoded signed transaction
127931
- return toBase64(tx$1.TxRaw.encode(rawTx).finish());
127929
+ return this.getAddress(index);
127932
127930
  });
127933
127931
  }
127932
+ /**
127933
+ * Get the address derived from the provided phrase.
127934
+ * @param {number | undefined} walletIndex The index of the address derivation path. Default is 0.
127935
+ * @returns {string} The user address at the specified walletIndex.
127936
+ */
127937
+ getAddress(walletIndex) {
127938
+ const seed = getSeed(this.phrase);
127939
+ const node = fromSeed(seed);
127940
+ const child = node.derivePath(this.getFullDerivationPath(walletIndex || 0));
127941
+ if (!child.privateKey)
127942
+ throw new Error('child does not have a privateKey');
127943
+ // TODO: Make this method async and use CosmosJS official address generation strategy
127944
+ const pubKey = publicKeyCreate(child.privateKey);
127945
+ const rawAddress = this.hash160(Uint8Array.from(pubKey));
127946
+ const words = toWords$1(Buffer.from(rawAddress));
127947
+ const address = encode$2(this.prefix, words);
127948
+ return address;
127949
+ }
127934
127950
  /**
127935
127951
  * Returns the private key associated with an index
127936
127952
  *
@@ -127964,36 +127980,79 @@ class Client extends Client$1 {
127964
127980
  return Secp256k1.compressPubkey(pubkey);
127965
127981
  });
127966
127982
  }
127967
- /**
127968
- * Get deposit transaction
127969
- *
127970
- * @deprecated Use getTransactionData instead
127971
- * @param {string} txId The transaction ID for which to get the deposit transaction
127972
- */
127973
- getDepositTransaction(txId) {
127983
+ transfer(params) {
127974
127984
  return __awaiter(this, void 0, void 0, function* () {
127975
- return this.getTransactionData(txId);
127985
+ const sender = yield this.getAddressAsync(params.walletIndex || 0);
127986
+ const { rawUnsignedTx } = yield this.prepareTx({
127987
+ sender,
127988
+ recipient: params.recipient,
127989
+ asset: params.asset,
127990
+ amount: params.amount,
127991
+ memo: params.memo,
127992
+ });
127993
+ const unsignedTx = decodeTxRaw(fromBase64(rawUnsignedTx));
127994
+ const signer = yield DirectSecp256k1HdWallet.fromMnemonic(this.phrase, {
127995
+ prefix: this.prefix,
127996
+ hdPaths: [makeClientPath(this.getFullDerivationPath(params.walletIndex || 0))],
127997
+ });
127998
+ const tx = yield this.roundRobinSignAndBroadcastTx(sender, unsignedTx, signer);
127999
+ return tx.transactionHash;
127976
128000
  });
127977
128001
  }
127978
128002
  /**
127979
- * Get the message type url by type used by the cosmos-sdk client to make certain actions
128003
+ * Make a deposit
127980
128004
  *
127981
- * @param {MsgTypes} msgType The message type of which return the type url
127982
- * @returns {string} the type url of the message
128005
+ * @param {number} param.walletIndex Optional - The index to use to generate the address from the transaction will be done.
128006
+ * If it is not set, address associated with index 0 will be used
128007
+ * @param {Asset} param.asset Optional - The asset that will be deposit. If it is not set, Thorchain native asset will be
128008
+ * used
128009
+ * @param {BaseAmount} param.amount The amount that will be deposit
128010
+ * @param {string} param.memo Optional - The memo associated with the deposit
128011
+ * @param {BigNumber} param.gasLimit Optional - The limit amount of gas allowed to spend in the deposit. If not set, default
128012
+ * value of 600000000 will be used
128013
+ * @returns {string} The deposit hash
127983
128014
  */
127984
- getMsgTypeUrlByType(msgType) {
127985
- const messageTypeUrls = {
127986
- [MsgTypes.TRANSFER]: MSG_SEND_TYPE_URL,
127987
- };
127988
- return messageTypeUrls[msgType];
128015
+ deposit({ walletIndex = 0, asset = AssetRuneNative, amount, memo, gasLimit = new BigNumber(DEPOSIT_GAS_LIMIT_VALUE), }) {
128016
+ return __awaiter(this, void 0, void 0, function* () {
128017
+ // Get sender address
128018
+ const sender = yield this.getAddressAsync(walletIndex);
128019
+ // Create signer
128020
+ const signer = yield DirectSecp256k1HdWallet.fromMnemonic(this.phrase, {
128021
+ prefix: this.prefix,
128022
+ hdPaths: [makeClientPath(this.getFullDerivationPath(walletIndex || 0))],
128023
+ });
128024
+ const tx = yield this.roundRobinSignAndBroadcastDeposit(sender, signer, gasLimit, amount, memo, asset);
128025
+ return tx.transactionHash;
128026
+ });
127989
128027
  }
127990
128028
  /**
127991
- * Returns the standard fee used by the client
128029
+ * Create and sign transaction without broadcasting it
127992
128030
  *
127993
- * @returns {StdFee} the standard fee
128031
+ * @deprecated Use prepare Tx instead
127994
128032
  */
127995
- getStandardFee() {
127996
- return { amount: [], gas: '6000000' };
128033
+ transferOffline({ walletIndex = 0, recipient, asset, amount, memo, gasLimit = new BigNumber(DEFAULT_GAS_LIMIT_VALUE), }) {
128034
+ return __awaiter(this, void 0, void 0, function* () {
128035
+ // Get sender address
128036
+ const sender = yield this.getAddressAsync(walletIndex);
128037
+ // Prepare unsigned transaction
128038
+ const { rawUnsignedTx } = yield this.prepareTx({
128039
+ sender,
128040
+ recipient: recipient,
128041
+ asset: asset,
128042
+ amount: amount,
128043
+ memo: memo,
128044
+ });
128045
+ // Decode unsigned transaction
128046
+ const unsignedTx = decodeTxRaw(fromBase64(rawUnsignedTx));
128047
+ // Create signer
128048
+ const signer = yield DirectSecp256k1HdWallet.fromMnemonic(this.phrase, {
128049
+ prefix: this.prefix,
128050
+ hdPaths: [makeClientPath(this.getFullDerivationPath(walletIndex))],
128051
+ });
128052
+ const rawTx = yield this.roundRobinSign(sender, unsignedTx, signer, gasLimit);
128053
+ // Return encoded signed transaction
128054
+ return toBase64(tx$1.TxRaw.encode(rawTx).finish());
128055
+ });
127997
128056
  }
127998
128057
  /**
127999
128058
  * Hashes a buffer using SHA256 followed by RIPEMD160 or RMD160.
@@ -128022,18 +128081,21 @@ class Client extends Client$1 {
128022
128081
  return __awaiter(this, void 0, void 0, function* () {
128023
128082
  // Connect to signing client
128024
128083
  for (const url of this.clientUrls[this.network]) {
128025
- const signingClient = yield build$7.SigningStargateClient.connectWithSigner(url, signer, {
128026
- registry: this.registry,
128027
- });
128028
- // Prepare messages
128029
- const messages = unsignedTx.body.messages.map((message) => {
128030
- return { typeUrl: this.getMsgTypeUrlByType(MsgTypes.TRANSFER), value: signingClient.registry.decode(message) };
128031
- });
128032
- // Sign transaction
128033
- return yield signingClient.sign(sender, messages, {
128034
- amount: [],
128035
- gas: gasLimit.toString(),
128036
- }, unsignedTx.body.memo);
128084
+ try {
128085
+ const signingClient = yield build$7.SigningStargateClient.connectWithSigner(url, signer, {
128086
+ registry: this.registry,
128087
+ });
128088
+ // Prepare messages
128089
+ const messages = unsignedTx.body.messages.map((message) => {
128090
+ return { typeUrl: this.getMsgTypeUrlByType(MsgTypes.TRANSFER), value: signingClient.registry.decode(message) };
128091
+ });
128092
+ // Sign transaction
128093
+ return yield signingClient.sign(sender, messages, {
128094
+ amount: [],
128095
+ gas: gasLimit.toString(),
128096
+ }, unsignedTx.body.memo);
128097
+ }
128098
+ catch (_a) { }
128037
128099
  }
128038
128100
  throw Error('No clients available. Can not sign transaction');
128039
128101
  });
@@ -128105,5 +128167,225 @@ class Client extends Client$1 {
128105
128167
  }
128106
128168
  }
128107
128169
 
128108
- export { AssetRuneNative, Client, DEFAULT_EXPLORER_URL, DEFAULT_FEE, DEFAULT_GAS_LIMIT_VALUE, DEPOSIT_GAS_LIMIT_VALUE, MSG_DEPOSIT_TYPE_URL, MSG_SEND_TYPE_URL, RUNE_DECIMAL, RUNE_DENOM, RUNE_TICKER, THORChain, defaultClientConfig, getChainId, getDefaultClientUrls, getDefaultExplorers, getDefaultRootDerivationPaths, getDenom, getExplorerAddressUrl, getExplorerTxUrl, getPrefix, isAssetRuneNative };
128170
+ /**
128171
+ * Thorchain Ledger client
128172
+ */
128173
+ class ClientLedger extends Client {
128174
+ constructor(params) {
128175
+ super(Object.assign(Object.assign({}, defaultClientConfig), params));
128176
+ this.app = new THORChainApp(params.transport);
128177
+ }
128178
+ /**
128179
+ * Asynchronous version of getAddress method.
128180
+ * @param {number} index Derivation path index of the address to be generated.
128181
+ * @param {boolean} verify True to check the address against the Ledger device, otherwise false
128182
+ * @returns {string} A promise that resolves to the generated address.
128183
+ */
128184
+ getAddressAsync(index, verify = false) {
128185
+ return __awaiter(this, void 0, void 0, function* () {
128186
+ const derivationPath = parseDerivationPath(this.getFullDerivationPath(index || 0));
128187
+ const { bech32Address } = verify
128188
+ ? yield this.app.showAddressAndPubKey(derivationPath, this.getPrefix(this.network))
128189
+ : yield this.app.getAddressAndPubKey(derivationPath, this.getPrefix(this.network));
128190
+ return bech32Address;
128191
+ });
128192
+ }
128193
+ /**
128194
+ * @deprecated
128195
+ * Asynchronous version of getAddress method. Not supported for ledger client
128196
+ * @throws {Error} Not supported method
128197
+ */
128198
+ getAddress() {
128199
+ throw Error('Sync method not supported for Ledger');
128200
+ }
128201
+ /**
128202
+ * Transfers RUNE or synth token
128203
+ *
128204
+ * @param {TxParams} params The transfer options.
128205
+ * @param {number} params.walletIndex Optional - The index to use to generate the address from the transaction will be done.
128206
+ * If it is not set, address associated with index 0 will be used
128207
+ * @param {asset} params.asset Optional - The asset that will be deposit. If it is not set, Thorchain native asset will be
128208
+ * used
128209
+ * @param {BaseAmount} params.amount The amount that will be transfer
128210
+ * @param {string} params.recipient Recipient of the transfer
128211
+ * @param {string} params.memo Optional - The memo associated with the transfer
128212
+ * @returns {TxHash} The transaction hash.
128213
+ */
128214
+ transfer(params) {
128215
+ return __awaiter(this, void 0, void 0, function* () {
128216
+ const signedTx = yield this.transferOffline(params);
128217
+ return this.broadcastTx(signedTx);
128218
+ });
128219
+ }
128220
+ /**
128221
+ * Make a deposit
128222
+ *
128223
+ * @param {number} param.walletIndex Optional - The index to use to generate the address from the transaction will be done.
128224
+ * If it is not set, address associated with index 0 will be used
128225
+ * @param {Asset} param.asset Optional - The asset that will be deposit. If it is not set, Thorchain native asset will be
128226
+ * used
128227
+ * @param {BaseAmount} param.amount The amount that will be deposit
128228
+ * @param {string} param.memo Optional - The memo associated with the deposit
128229
+ * @param {BigNumber} param.gasLimit Optional - The limit amount of gas allowed to spend in the deposit. If not set, default
128230
+ * value of 600000000 will be used
128231
+ * @returns {string} The deposit hash
128232
+ */
128233
+ deposit({ walletIndex = 0, asset = AssetRuneNative, amount, memo, gasLimit = new BigNumber(DEPOSIT_GAS_LIMIT_VALUE), }) {
128234
+ return __awaiter(this, void 0, void 0, function* () {
128235
+ const sender = yield this.getAddressAsync(walletIndex || 0);
128236
+ const account = yield this.getAccount(sender);
128237
+ const formattedDP = parseDerivationPath(this.getFullDerivationPath(walletIndex || 0));
128238
+ const { compressedPk } = yield this.app.getAddressAndPubKey(formattedDP, this.getPrefix(this.getNetwork()));
128239
+ const pubkey = encodePubkey({
128240
+ type: 'tendermint/PubKeySecp256k1',
128241
+ value: toBase64(compressedPk),
128242
+ });
128243
+ const msgs = sortedObject([
128244
+ {
128245
+ type: 'thorchain/MsgDeposit',
128246
+ value: {
128247
+ signer: sender,
128248
+ memo,
128249
+ coins: [
128250
+ {
128251
+ amount: amount.amount().toString(),
128252
+ asset: assetToString(asset),
128253
+ },
128254
+ ],
128255
+ },
128256
+ },
128257
+ ]);
128258
+ const fee = { amount: [], gas: gasLimit.toString() };
128259
+ const { signature, returnCode, errorMessage } = yield this.app.sign(formattedDP, sortAndStringifyJson({
128260
+ account_number: account.accountNumber.toString(),
128261
+ chain_id: yield this.getChainId(),
128262
+ fee,
128263
+ memo,
128264
+ msgs,
128265
+ sequence: account.sequence.toString(),
128266
+ }));
128267
+ if (!signature)
128268
+ throw Error(`Can not sign deposit transaction. Return code ${returnCode}. Error: ${errorMessage}`);
128269
+ const aminoTypes = this.getProtocolAminoMessages();
128270
+ const rawTx = tx$1.TxRaw.fromPartial({
128271
+ bodyBytes: yield this.registry.encodeTxBody({
128272
+ memo,
128273
+ messages: msgs.map((msg) => aminoTypes.fromAmino(msg)),
128274
+ }),
128275
+ authInfoBytes: makeAuthInfoBytes([
128276
+ {
128277
+ pubkey,
128278
+ sequence: account.sequence,
128279
+ },
128280
+ ], fee.amount, Number.parseInt(fee.gas), undefined, undefined, signing.SignMode.SIGN_MODE_LEGACY_AMINO_JSON),
128281
+ signatures: [extractSignatureFromTLV(signature)],
128282
+ });
128283
+ return this.broadcastTx(toBase64(tx$1.TxRaw.encode(rawTx).finish()));
128284
+ });
128285
+ }
128286
+ /**
128287
+ * @deprecated
128288
+ * Create a transaction and sign it without broadcasting it
128289
+ *
128290
+ * @param {TxParams} params The transfer options.
128291
+ * @param {number} params.walletIndex Optional - The index to use to generate the address from the transaction will be done.
128292
+ * If it is not set, address associated with index 0 will be used
128293
+ * @param {asset} params.asset Optional - The asset that will be deposit. If it is not set, Thorchain native asset will be
128294
+ * used
128295
+ * @param {BaseAmount} params.amount The amount that will be transfer
128296
+ * @param {string} params.recipient Recipient of the transfer
128297
+ * @param {string} params.memo Optional - The memo associated with the transfer
128298
+ * @returns {TxHash} The transaction hash.
128299
+ */
128300
+ transferOffline(params) {
128301
+ return __awaiter(this, void 0, void 0, function* () {
128302
+ const sender = yield this.getAddressAsync(params.walletIndex || 0);
128303
+ const account = yield this.getAccount(sender);
128304
+ const formattedDP = parseDerivationPath(this.getFullDerivationPath(params.walletIndex || 0));
128305
+ const { compressedPk } = yield this.app.getAddressAndPubKey(formattedDP, this.getPrefix(this.getNetwork()));
128306
+ const pubkey = encodePubkey({
128307
+ type: 'tendermint/PubKeySecp256k1',
128308
+ value: toBase64(compressedPk),
128309
+ });
128310
+ const msgs = sortedObject([
128311
+ {
128312
+ type: 'thorchain/MsgSend',
128313
+ value: {
128314
+ from_address: sender,
128315
+ to_address: params.recipient,
128316
+ amount: [
128317
+ {
128318
+ amount: params.amount.amount().toString(),
128319
+ denom: this.getDenom(params.asset || AssetRuneNative),
128320
+ },
128321
+ ],
128322
+ },
128323
+ },
128324
+ ]);
128325
+ const fee = this.getStandardFee();
128326
+ const { signature, returnCode, errorMessage } = yield this.app.sign(formattedDP, sortAndStringifyJson({
128327
+ account_number: account.accountNumber.toString(),
128328
+ chain_id: yield this.getChainId(),
128329
+ fee,
128330
+ memo: params.memo || '',
128331
+ msgs,
128332
+ sequence: account.sequence.toString(),
128333
+ }));
128334
+ if (!signature)
128335
+ throw Error(`Can not sign transfer transaction. Return code ${returnCode}. Error: ${errorMessage}`);
128336
+ const aminoTypes = this.getProtocolAminoMessages();
128337
+ const rawTx = tx$1.TxRaw.fromPartial({
128338
+ bodyBytes: yield this.registry.encodeTxBody({
128339
+ messages: msgs.map((msg) => aminoTypes.fromAmino(msg)),
128340
+ memo: params.memo,
128341
+ }),
128342
+ authInfoBytes: makeAuthInfoBytes([
128343
+ {
128344
+ pubkey,
128345
+ sequence: account.sequence,
128346
+ },
128347
+ ], fee.amount, Number.parseInt(fee.gas), undefined, undefined, signing.SignMode.SIGN_MODE_LEGACY_AMINO_JSON),
128348
+ signatures: [extractSignatureFromTLV(signature)],
128349
+ });
128350
+ return toBase64(tx$1.TxRaw.encode(rawTx).finish());
128351
+ });
128352
+ }
128353
+ getProtocolAminoMessages() {
128354
+ const prefix = this.getPrefix(this.network);
128355
+ return new build$7.AminoTypes({
128356
+ '/types.MsgSend': {
128357
+ aminoType: `thorchain/MsgSend`,
128358
+ toAmino: (params) => ({
128359
+ from_address: base64ToBech32(params.fromAddress, prefix),
128360
+ to_address: base64ToBech32(params.toAddress, prefix),
128361
+ amount: [...params.amount],
128362
+ }),
128363
+ fromAmino: (params) => ({
128364
+ fromAddress: bech32ToBase64(params.from_address),
128365
+ toAddress: bech32ToBase64(params.to_address),
128366
+ amount: [...params.amount],
128367
+ }),
128368
+ },
128369
+ '/types.MsgDeposit': {
128370
+ aminoType: `thorchain/MsgDeposit`,
128371
+ toAmino: (params) => ({
128372
+ signer: base64ToBech32(params.signer, prefix),
128373
+ memo: params.memo,
128374
+ coins: params.coins.map((coin) => {
128375
+ return Object.assign(Object.assign({}, coin), { asset: assetToString(coin.asset) });
128376
+ }),
128377
+ }),
128378
+ fromAmino: (params) => ({
128379
+ signer: bech32ToBase64(params.signer),
128380
+ memo: params.memo,
128381
+ coins: params.coins.map((coin) => {
128382
+ return Object.assign(Object.assign({}, coin), { asset: assetFromStringEx(coin.asset) });
128383
+ }),
128384
+ }),
128385
+ },
128386
+ });
128387
+ }
128388
+ }
128389
+
128390
+ export { AssetRuneNative, ClientKeystore as Client, ClientKeystore, ClientLedger, DEFAULT_EXPLORER_URL, DEFAULT_FEE, DEFAULT_GAS_LIMIT_VALUE, DEPOSIT_GAS_LIMIT_VALUE, MSG_DEPOSIT_TYPE_URL, MSG_SEND_TYPE_URL, RUNE_DECIMAL, RUNE_DENOM, RUNE_TICKER, THORChain, defaultClientConfig, getChainId, getDefaultClientUrls, getDefaultExplorers, getDefaultRootDerivationPaths, getDenom, getExplorerAddressUrl, getExplorerTxUrl, getPrefix, isAssetRuneNative, parseDerivationPath, sortAndStringifyJson, sortedObject };
128109
128391
  //# sourceMappingURL=index.esm.js.map