@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.js CHANGED
@@ -12,10 +12,11 @@ var crypto$3 = require('crypto');
12
12
  var buffer = require('buffer');
13
13
  var bignumber = require('bignumber.js');
14
14
  var bech32$1 = require('bech32');
15
- var xchainUtil = require('@xchainjs/xchain-util');
16
15
  var bip32 = require('bip32');
17
16
  var secp256k1 = require('secp256k1');
17
+ var xchainUtil = require('@xchainjs/xchain-util');
18
18
  var xchainClient = require('@xchainjs/xchain-client');
19
+ var THORChainApp = require('@xchainjs/ledger-thorchain');
19
20
 
20
21
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
21
22
 
@@ -45,6 +46,7 @@ var axios__namespace = /*#__PURE__*/_interopNamespace(axios);
45
46
  var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
46
47
  var buffer__namespace = /*#__PURE__*/_interopNamespace(buffer);
47
48
  var bignumber__namespace = /*#__PURE__*/_interopNamespace(bignumber);
49
+ var THORChainApp__default = /*#__PURE__*/_interopDefaultLegacy(THORChainApp);
48
50
 
49
51
  /******************************************************************************
50
52
  Copyright (c) Microsoft Corporation.
@@ -127658,6 +127660,58 @@ const getPrefix = (network) => {
127658
127660
  return 'tthor';
127659
127661
  }
127660
127662
  };
127663
+ /**
127664
+ * Parse the derivation path from a string to an Array of numbers
127665
+ * @param {string} path - Path to parse
127666
+ * @returns {number[]} - The derivation path as Array of numbers
127667
+ */
127668
+ const parseDerivationPath = (path) => {
127669
+ if (!path.startsWith('m'))
127670
+ throw new Error("Path string must start with 'm'");
127671
+ let rest = path.slice(1);
127672
+ const out = new Array();
127673
+ while (rest) {
127674
+ const match = rest.match(/^\/([0-9]+)('?)/);
127675
+ if (!match)
127676
+ throw new Error('Syntax error while reading path component');
127677
+ const [fullMatch, numberString] = match;
127678
+ const value = build$6.Uint53.fromString(numberString).toNumber();
127679
+ if (value >= Math.pow(2, 31))
127680
+ throw new Error('Component value too high. Must not exceed 2**31-1.');
127681
+ out.push(value);
127682
+ rest = rest.slice(fullMatch.length);
127683
+ }
127684
+ return out;
127685
+ };
127686
+ /**
127687
+ * Sort JSON object
127688
+ * @param {any} obj - JSON object
127689
+ * @returns {any} JSON object sorted
127690
+ */
127691
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
127692
+ function sortedObject(obj) {
127693
+ if (typeof obj !== 'object' || obj === null) {
127694
+ return obj;
127695
+ }
127696
+ if (Array.isArray(obj)) {
127697
+ return obj.map(sortedObject);
127698
+ }
127699
+ const sortedKeys = Object.keys(obj).sort();
127700
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
127701
+ const result = {};
127702
+ // NOTE: Use forEach instead of reduce for performance with large objects eg Wasm code
127703
+ sortedKeys.forEach((key) => {
127704
+ result[key] = sortedObject(obj[key]);
127705
+ });
127706
+ return result;
127707
+ }
127708
+ /**
127709
+ * Returns a JSON string with objects sorted by key
127710
+ * */
127711
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
127712
+ function sortAndStringifyJson(obj) {
127713
+ return JSON.stringify(sortedObject(obj));
127714
+ }
127661
127715
 
127662
127716
  /**
127663
127717
  * Import necessary modules and types for the Thorchain client configuration.
@@ -127727,7 +127781,7 @@ const defaultClientConfig = {
127727
127781
  };
127728
127782
 
127729
127783
  /**
127730
- * Thorchain client
127784
+ * Thorchain base client
127731
127785
  */
127732
127786
  class Client extends xchainCosmosSdk.Client {
127733
127787
  /**
@@ -127738,53 +127792,6 @@ class Client extends xchainCosmosSdk.Client {
127738
127792
  constructor(config = defaultClientConfig) {
127739
127793
  super(Object.assign(Object.assign({}, defaultClientConfig), config));
127740
127794
  }
127741
- /**
127742
- * Asynchronous version of getAddress method.
127743
- * @param {number} index Derivation path index of the address to be generated.
127744
- * @returns {string} A promise that resolves to the generated address.
127745
- */
127746
- getAddressAsync(index = 0) {
127747
- return __awaiter(this, void 0, void 0, function* () {
127748
- return this.getAddress(index);
127749
- });
127750
- }
127751
- /**
127752
- * Get the address derived from the provided phrase.
127753
- * @param {number | undefined} walletIndex The index of the address derivation path. Default is 0.
127754
- * @returns {string} The user address at the specified walletIndex.
127755
- */
127756
- getAddress(walletIndex) {
127757
- const seed = getSeed(this.phrase);
127758
- const node = bip32.fromSeed(seed);
127759
- const child = node.derivePath(this.getFullDerivationPath(walletIndex || 0));
127760
- if (!child.privateKey)
127761
- throw new Error('child does not have a privateKey');
127762
- // TODO: Make this method async and use CosmosJS official address generation strategy
127763
- const pubKey = secp256k1.publicKeyCreate(child.privateKey);
127764
- const rawAddress = this.hash160(Uint8Array.from(pubKey));
127765
- const words = bech32$1.toWords(Buffer.from(rawAddress));
127766
- const address = bech32$1.encode(this.prefix, words);
127767
- return address;
127768
- }
127769
- transfer(params) {
127770
- return __awaiter(this, void 0, void 0, function* () {
127771
- const sender = yield this.getAddressAsync(params.walletIndex || 0);
127772
- const { rawUnsignedTx } = yield this.prepareTx({
127773
- sender,
127774
- recipient: params.recipient,
127775
- asset: params.asset,
127776
- amount: params.amount,
127777
- memo: params.memo,
127778
- });
127779
- const unsignedTx = protoSigning.decodeTxRaw(encoding.fromBase64(rawUnsignedTx));
127780
- const signer = yield protoSigning.DirectSecp256k1HdWallet.fromMnemonic(this.phrase, {
127781
- prefix: this.prefix,
127782
- hdPaths: [xchainCosmosSdk.makeClientPath(this.getFullDerivationPath(params.walletIndex || 0))],
127783
- });
127784
- const tx = yield this.roundRobinSignAndBroadcastTx(sender, unsignedTx, signer);
127785
- return tx.transactionHash;
127786
- });
127787
- }
127788
127795
  /**
127789
127796
  * Get address prefix by network
127790
127797
  * @param {Network} network The network of which return the prefix
@@ -127905,60 +127912,70 @@ class Client extends xchainCosmosSdk.Client {
127905
127912
  });
127906
127913
  }
127907
127914
  /**
127908
- * Make a deposit
127915
+ * Get deposit transaction
127909
127916
  *
127910
- * @param {number} param.walletIndex Optional - The index to use to generate the address from the transaction will be done.
127911
- * If it is not set, address associated with index 0 will be used
127912
- * @param {Asset} param.asset Optional - The asset that will be deposit. If it is not set, Thorchain native asset will be
127913
- * used
127914
- * @param {BaseAmount} param.amount The amount that will be deposit
127915
- * @param {string} param.memo Optional - The memo associated with the deposit
127916
- * @param {BigNumber} param.gasLimit Optional - The limit amount of gas allowed to spend in the deposit. If not set, default
127917
- * value of 600000000 will be used
127918
- * @returns {string} The deposit hash
127917
+ * @deprecated Use getTransactionData instead
127918
+ * @param {string} txId The transaction ID for which to get the deposit transaction
127919
127919
  */
127920
- deposit({ walletIndex = 0, asset = AssetRuneNative, amount, memo, gasLimit = new bignumber.BigNumber(DEPOSIT_GAS_LIMIT_VALUE), }) {
127920
+ getDepositTransaction(txId) {
127921
127921
  return __awaiter(this, void 0, void 0, function* () {
127922
- // Get sender address
127923
- const sender = yield this.getAddressAsync(walletIndex);
127924
- // Create signer
127925
- const signer = yield protoSigning.DirectSecp256k1HdWallet.fromMnemonic(this.phrase, {
127926
- prefix: this.prefix,
127927
- hdPaths: [xchainCosmosSdk.makeClientPath(this.getFullDerivationPath(walletIndex || 0))],
127928
- });
127929
- const tx = yield this.roundRobinSignAndBroadcastDeposit(sender, signer, gasLimit, amount, memo, asset);
127930
- return tx.transactionHash;
127922
+ return this.getTransactionData(txId);
127931
127923
  });
127932
127924
  }
127933
127925
  /**
127934
- * Create and sign transaction without broadcasting it
127926
+ * Get the message type url by type used by the cosmos-sdk client to make certain actions
127935
127927
  *
127936
- * @deprecated Use prepare Tx instead
127928
+ * @param {MsgTypes} msgType The message type of which return the type url
127929
+ * @returns {string} the type url of the message
127937
127930
  */
127938
- transferOffline({ walletIndex = 0, recipient, asset, amount, memo, gasLimit = new bignumber.BigNumber(DEFAULT_GAS_LIMIT_VALUE), }) {
127931
+ getMsgTypeUrlByType(msgType) {
127932
+ const messageTypeUrls = {
127933
+ [xchainCosmosSdk.MsgTypes.TRANSFER]: MSG_SEND_TYPE_URL,
127934
+ };
127935
+ return messageTypeUrls[msgType];
127936
+ }
127937
+ /**
127938
+ * Returns the standard fee used by the client
127939
+ *
127940
+ * @returns {StdFee} the standard fee
127941
+ */
127942
+ getStandardFee() {
127943
+ return { amount: [], gas: '6000000' };
127944
+ }
127945
+ }
127946
+
127947
+ /**
127948
+ * Thorchain Keystore client
127949
+ */
127950
+ class ClientKeystore extends Client {
127951
+ /**
127952
+ * Asynchronous version of getAddress method.
127953
+ * @param {number} index Derivation path index of the address to be generated.
127954
+ * @returns {string} A promise that resolves to the generated address.
127955
+ */
127956
+ getAddressAsync(index = 0) {
127939
127957
  return __awaiter(this, void 0, void 0, function* () {
127940
- // Get sender address
127941
- const sender = yield this.getAddressAsync(walletIndex);
127942
- // Prepare unsigned transaction
127943
- const { rawUnsignedTx } = yield this.prepareTx({
127944
- sender,
127945
- recipient: recipient,
127946
- asset: asset,
127947
- amount: amount,
127948
- memo: memo,
127949
- });
127950
- // Decode unsigned transaction
127951
- const unsignedTx = protoSigning.decodeTxRaw(encoding.fromBase64(rawUnsignedTx));
127952
- // Create signer
127953
- const signer = yield protoSigning.DirectSecp256k1HdWallet.fromMnemonic(this.phrase, {
127954
- prefix: this.prefix,
127955
- hdPaths: [xchainCosmosSdk.makeClientPath(this.getFullDerivationPath(walletIndex))],
127956
- });
127957
- const rawTx = yield this.roundRobinSign(sender, unsignedTx, signer, gasLimit);
127958
- // Return encoded signed transaction
127959
- return encoding.toBase64(tx$1.TxRaw.encode(rawTx).finish());
127958
+ return this.getAddress(index);
127960
127959
  });
127961
127960
  }
127961
+ /**
127962
+ * Get the address derived from the provided phrase.
127963
+ * @param {number | undefined} walletIndex The index of the address derivation path. Default is 0.
127964
+ * @returns {string} The user address at the specified walletIndex.
127965
+ */
127966
+ getAddress(walletIndex) {
127967
+ const seed = getSeed(this.phrase);
127968
+ const node = bip32.fromSeed(seed);
127969
+ const child = node.derivePath(this.getFullDerivationPath(walletIndex || 0));
127970
+ if (!child.privateKey)
127971
+ throw new Error('child does not have a privateKey');
127972
+ // TODO: Make this method async and use CosmosJS official address generation strategy
127973
+ const pubKey = secp256k1.publicKeyCreate(child.privateKey);
127974
+ const rawAddress = this.hash160(Uint8Array.from(pubKey));
127975
+ const words = bech32$1.toWords(Buffer.from(rawAddress));
127976
+ const address = bech32$1.encode(this.prefix, words);
127977
+ return address;
127978
+ }
127962
127979
  /**
127963
127980
  * Returns the private key associated with an index
127964
127981
  *
@@ -127992,36 +128009,79 @@ class Client extends xchainCosmosSdk.Client {
127992
128009
  return crypto$2.Secp256k1.compressPubkey(pubkey);
127993
128010
  });
127994
128011
  }
127995
- /**
127996
- * Get deposit transaction
127997
- *
127998
- * @deprecated Use getTransactionData instead
127999
- * @param {string} txId The transaction ID for which to get the deposit transaction
128000
- */
128001
- getDepositTransaction(txId) {
128012
+ transfer(params) {
128002
128013
  return __awaiter(this, void 0, void 0, function* () {
128003
- return this.getTransactionData(txId);
128014
+ const sender = yield this.getAddressAsync(params.walletIndex || 0);
128015
+ const { rawUnsignedTx } = yield this.prepareTx({
128016
+ sender,
128017
+ recipient: params.recipient,
128018
+ asset: params.asset,
128019
+ amount: params.amount,
128020
+ memo: params.memo,
128021
+ });
128022
+ const unsignedTx = protoSigning.decodeTxRaw(encoding.fromBase64(rawUnsignedTx));
128023
+ const signer = yield protoSigning.DirectSecp256k1HdWallet.fromMnemonic(this.phrase, {
128024
+ prefix: this.prefix,
128025
+ hdPaths: [xchainCosmosSdk.makeClientPath(this.getFullDerivationPath(params.walletIndex || 0))],
128026
+ });
128027
+ const tx = yield this.roundRobinSignAndBroadcastTx(sender, unsignedTx, signer);
128028
+ return tx.transactionHash;
128004
128029
  });
128005
128030
  }
128006
128031
  /**
128007
- * Get the message type url by type used by the cosmos-sdk client to make certain actions
128032
+ * Make a deposit
128008
128033
  *
128009
- * @param {MsgTypes} msgType The message type of which return the type url
128010
- * @returns {string} the type url of the message
128034
+ * @param {number} param.walletIndex Optional - The index to use to generate the address from the transaction will be done.
128035
+ * If it is not set, address associated with index 0 will be used
128036
+ * @param {Asset} param.asset Optional - The asset that will be deposit. If it is not set, Thorchain native asset will be
128037
+ * used
128038
+ * @param {BaseAmount} param.amount The amount that will be deposit
128039
+ * @param {string} param.memo Optional - The memo associated with the deposit
128040
+ * @param {BigNumber} param.gasLimit Optional - The limit amount of gas allowed to spend in the deposit. If not set, default
128041
+ * value of 600000000 will be used
128042
+ * @returns {string} The deposit hash
128011
128043
  */
128012
- getMsgTypeUrlByType(msgType) {
128013
- const messageTypeUrls = {
128014
- [xchainCosmosSdk.MsgTypes.TRANSFER]: MSG_SEND_TYPE_URL,
128015
- };
128016
- return messageTypeUrls[msgType];
128044
+ deposit({ walletIndex = 0, asset = AssetRuneNative, amount, memo, gasLimit = new bignumber.BigNumber(DEPOSIT_GAS_LIMIT_VALUE), }) {
128045
+ return __awaiter(this, void 0, void 0, function* () {
128046
+ // Get sender address
128047
+ const sender = yield this.getAddressAsync(walletIndex);
128048
+ // Create signer
128049
+ const signer = yield protoSigning.DirectSecp256k1HdWallet.fromMnemonic(this.phrase, {
128050
+ prefix: this.prefix,
128051
+ hdPaths: [xchainCosmosSdk.makeClientPath(this.getFullDerivationPath(walletIndex || 0))],
128052
+ });
128053
+ const tx = yield this.roundRobinSignAndBroadcastDeposit(sender, signer, gasLimit, amount, memo, asset);
128054
+ return tx.transactionHash;
128055
+ });
128017
128056
  }
128018
128057
  /**
128019
- * Returns the standard fee used by the client
128058
+ * Create and sign transaction without broadcasting it
128020
128059
  *
128021
- * @returns {StdFee} the standard fee
128060
+ * @deprecated Use prepare Tx instead
128022
128061
  */
128023
- getStandardFee() {
128024
- return { amount: [], gas: '6000000' };
128062
+ transferOffline({ walletIndex = 0, recipient, asset, amount, memo, gasLimit = new bignumber.BigNumber(DEFAULT_GAS_LIMIT_VALUE), }) {
128063
+ return __awaiter(this, void 0, void 0, function* () {
128064
+ // Get sender address
128065
+ const sender = yield this.getAddressAsync(walletIndex);
128066
+ // Prepare unsigned transaction
128067
+ const { rawUnsignedTx } = yield this.prepareTx({
128068
+ sender,
128069
+ recipient: recipient,
128070
+ asset: asset,
128071
+ amount: amount,
128072
+ memo: memo,
128073
+ });
128074
+ // Decode unsigned transaction
128075
+ const unsignedTx = protoSigning.decodeTxRaw(encoding.fromBase64(rawUnsignedTx));
128076
+ // Create signer
128077
+ const signer = yield protoSigning.DirectSecp256k1HdWallet.fromMnemonic(this.phrase, {
128078
+ prefix: this.prefix,
128079
+ hdPaths: [xchainCosmosSdk.makeClientPath(this.getFullDerivationPath(walletIndex))],
128080
+ });
128081
+ const rawTx = yield this.roundRobinSign(sender, unsignedTx, signer, gasLimit);
128082
+ // Return encoded signed transaction
128083
+ return encoding.toBase64(tx$1.TxRaw.encode(rawTx).finish());
128084
+ });
128025
128085
  }
128026
128086
  /**
128027
128087
  * Hashes a buffer using SHA256 followed by RIPEMD160 or RMD160.
@@ -128050,18 +128110,21 @@ class Client extends xchainCosmosSdk.Client {
128050
128110
  return __awaiter(this, void 0, void 0, function* () {
128051
128111
  // Connect to signing client
128052
128112
  for (const url of this.clientUrls[this.network]) {
128053
- const signingClient = yield build$7.SigningStargateClient.connectWithSigner(url, signer, {
128054
- registry: this.registry,
128055
- });
128056
- // Prepare messages
128057
- const messages = unsignedTx.body.messages.map((message) => {
128058
- return { typeUrl: this.getMsgTypeUrlByType(xchainCosmosSdk.MsgTypes.TRANSFER), value: signingClient.registry.decode(message) };
128059
- });
128060
- // Sign transaction
128061
- return yield signingClient.sign(sender, messages, {
128062
- amount: [],
128063
- gas: gasLimit.toString(),
128064
- }, unsignedTx.body.memo);
128113
+ try {
128114
+ const signingClient = yield build$7.SigningStargateClient.connectWithSigner(url, signer, {
128115
+ registry: this.registry,
128116
+ });
128117
+ // Prepare messages
128118
+ const messages = unsignedTx.body.messages.map((message) => {
128119
+ return { typeUrl: this.getMsgTypeUrlByType(xchainCosmosSdk.MsgTypes.TRANSFER), value: signingClient.registry.decode(message) };
128120
+ });
128121
+ // Sign transaction
128122
+ return yield signingClient.sign(sender, messages, {
128123
+ amount: [],
128124
+ gas: gasLimit.toString(),
128125
+ }, unsignedTx.body.memo);
128126
+ }
128127
+ catch (_a) { }
128065
128128
  }
128066
128129
  throw Error('No clients available. Can not sign transaction');
128067
128130
  });
@@ -128133,8 +128196,230 @@ class Client extends xchainCosmosSdk.Client {
128133
128196
  }
128134
128197
  }
128135
128198
 
128199
+ /**
128200
+ * Thorchain Ledger client
128201
+ */
128202
+ class ClientLedger extends Client {
128203
+ constructor(params) {
128204
+ super(Object.assign(Object.assign({}, defaultClientConfig), params));
128205
+ this.app = new THORChainApp__default["default"](params.transport);
128206
+ }
128207
+ /**
128208
+ * Asynchronous version of getAddress method.
128209
+ * @param {number} index Derivation path index of the address to be generated.
128210
+ * @param {boolean} verify True to check the address against the Ledger device, otherwise false
128211
+ * @returns {string} A promise that resolves to the generated address.
128212
+ */
128213
+ getAddressAsync(index, verify = false) {
128214
+ return __awaiter(this, void 0, void 0, function* () {
128215
+ const derivationPath = parseDerivationPath(this.getFullDerivationPath(index || 0));
128216
+ const { bech32Address } = verify
128217
+ ? yield this.app.showAddressAndPubKey(derivationPath, this.getPrefix(this.network))
128218
+ : yield this.app.getAddressAndPubKey(derivationPath, this.getPrefix(this.network));
128219
+ return bech32Address;
128220
+ });
128221
+ }
128222
+ /**
128223
+ * @deprecated
128224
+ * Asynchronous version of getAddress method. Not supported for ledger client
128225
+ * @throws {Error} Not supported method
128226
+ */
128227
+ getAddress() {
128228
+ throw Error('Sync method not supported for Ledger');
128229
+ }
128230
+ /**
128231
+ * Transfers RUNE or synth token
128232
+ *
128233
+ * @param {TxParams} params The transfer options.
128234
+ * @param {number} params.walletIndex Optional - The index to use to generate the address from the transaction will be done.
128235
+ * If it is not set, address associated with index 0 will be used
128236
+ * @param {asset} params.asset Optional - The asset that will be deposit. If it is not set, Thorchain native asset will be
128237
+ * used
128238
+ * @param {BaseAmount} params.amount The amount that will be transfer
128239
+ * @param {string} params.recipient Recipient of the transfer
128240
+ * @param {string} params.memo Optional - The memo associated with the transfer
128241
+ * @returns {TxHash} The transaction hash.
128242
+ */
128243
+ transfer(params) {
128244
+ return __awaiter(this, void 0, void 0, function* () {
128245
+ const signedTx = yield this.transferOffline(params);
128246
+ return this.broadcastTx(signedTx);
128247
+ });
128248
+ }
128249
+ /**
128250
+ * Make a deposit
128251
+ *
128252
+ * @param {number} param.walletIndex Optional - The index to use to generate the address from the transaction will be done.
128253
+ * If it is not set, address associated with index 0 will be used
128254
+ * @param {Asset} param.asset Optional - The asset that will be deposit. If it is not set, Thorchain native asset will be
128255
+ * used
128256
+ * @param {BaseAmount} param.amount The amount that will be deposit
128257
+ * @param {string} param.memo Optional - The memo associated with the deposit
128258
+ * @param {BigNumber} param.gasLimit Optional - The limit amount of gas allowed to spend in the deposit. If not set, default
128259
+ * value of 600000000 will be used
128260
+ * @returns {string} The deposit hash
128261
+ */
128262
+ deposit({ walletIndex = 0, asset = AssetRuneNative, amount, memo, gasLimit = new bignumber.BigNumber(DEPOSIT_GAS_LIMIT_VALUE), }) {
128263
+ return __awaiter(this, void 0, void 0, function* () {
128264
+ const sender = yield this.getAddressAsync(walletIndex || 0);
128265
+ const account = yield this.getAccount(sender);
128266
+ const formattedDP = parseDerivationPath(this.getFullDerivationPath(walletIndex || 0));
128267
+ const { compressedPk } = yield this.app.getAddressAndPubKey(formattedDP, this.getPrefix(this.getNetwork()));
128268
+ const pubkey = protoSigning.encodePubkey({
128269
+ type: 'tendermint/PubKeySecp256k1',
128270
+ value: encoding.toBase64(compressedPk),
128271
+ });
128272
+ const msgs = sortedObject([
128273
+ {
128274
+ type: 'thorchain/MsgDeposit',
128275
+ value: {
128276
+ signer: sender,
128277
+ memo,
128278
+ coins: [
128279
+ {
128280
+ amount: amount.amount().toString(),
128281
+ asset: xchainUtil.assetToString(asset),
128282
+ },
128283
+ ],
128284
+ },
128285
+ },
128286
+ ]);
128287
+ const fee = { amount: [], gas: gasLimit.toString() };
128288
+ const { signature, returnCode, errorMessage } = yield this.app.sign(formattedDP, sortAndStringifyJson({
128289
+ account_number: account.accountNumber.toString(),
128290
+ chain_id: yield this.getChainId(),
128291
+ fee,
128292
+ memo,
128293
+ msgs,
128294
+ sequence: account.sequence.toString(),
128295
+ }));
128296
+ if (!signature)
128297
+ throw Error(`Can not sign deposit transaction. Return code ${returnCode}. Error: ${errorMessage}`);
128298
+ const aminoTypes = this.getProtocolAminoMessages();
128299
+ const rawTx = tx$1.TxRaw.fromPartial({
128300
+ bodyBytes: yield this.registry.encodeTxBody({
128301
+ memo,
128302
+ messages: msgs.map((msg) => aminoTypes.fromAmino(msg)),
128303
+ }),
128304
+ authInfoBytes: protoSigning.makeAuthInfoBytes([
128305
+ {
128306
+ pubkey,
128307
+ sequence: account.sequence,
128308
+ },
128309
+ ], fee.amount, Number.parseInt(fee.gas), undefined, undefined, signing.SignMode.SIGN_MODE_LEGACY_AMINO_JSON),
128310
+ signatures: [THORChainApp.extractSignatureFromTLV(signature)],
128311
+ });
128312
+ return this.broadcastTx(encoding.toBase64(tx$1.TxRaw.encode(rawTx).finish()));
128313
+ });
128314
+ }
128315
+ /**
128316
+ * @deprecated
128317
+ * Create a transaction and sign it without broadcasting it
128318
+ *
128319
+ * @param {TxParams} params The transfer options.
128320
+ * @param {number} params.walletIndex Optional - The index to use to generate the address from the transaction will be done.
128321
+ * If it is not set, address associated with index 0 will be used
128322
+ * @param {asset} params.asset Optional - The asset that will be deposit. If it is not set, Thorchain native asset will be
128323
+ * used
128324
+ * @param {BaseAmount} params.amount The amount that will be transfer
128325
+ * @param {string} params.recipient Recipient of the transfer
128326
+ * @param {string} params.memo Optional - The memo associated with the transfer
128327
+ * @returns {TxHash} The transaction hash.
128328
+ */
128329
+ transferOffline(params) {
128330
+ return __awaiter(this, void 0, void 0, function* () {
128331
+ const sender = yield this.getAddressAsync(params.walletIndex || 0);
128332
+ const account = yield this.getAccount(sender);
128333
+ const formattedDP = parseDerivationPath(this.getFullDerivationPath(params.walletIndex || 0));
128334
+ const { compressedPk } = yield this.app.getAddressAndPubKey(formattedDP, this.getPrefix(this.getNetwork()));
128335
+ const pubkey = protoSigning.encodePubkey({
128336
+ type: 'tendermint/PubKeySecp256k1',
128337
+ value: encoding.toBase64(compressedPk),
128338
+ });
128339
+ const msgs = sortedObject([
128340
+ {
128341
+ type: 'thorchain/MsgSend',
128342
+ value: {
128343
+ from_address: sender,
128344
+ to_address: params.recipient,
128345
+ amount: [
128346
+ {
128347
+ amount: params.amount.amount().toString(),
128348
+ denom: this.getDenom(params.asset || AssetRuneNative),
128349
+ },
128350
+ ],
128351
+ },
128352
+ },
128353
+ ]);
128354
+ const fee = this.getStandardFee();
128355
+ const { signature, returnCode, errorMessage } = yield this.app.sign(formattedDP, sortAndStringifyJson({
128356
+ account_number: account.accountNumber.toString(),
128357
+ chain_id: yield this.getChainId(),
128358
+ fee,
128359
+ memo: params.memo || '',
128360
+ msgs,
128361
+ sequence: account.sequence.toString(),
128362
+ }));
128363
+ if (!signature)
128364
+ throw Error(`Can not sign transfer transaction. Return code ${returnCode}. Error: ${errorMessage}`);
128365
+ const aminoTypes = this.getProtocolAminoMessages();
128366
+ const rawTx = tx$1.TxRaw.fromPartial({
128367
+ bodyBytes: yield this.registry.encodeTxBody({
128368
+ messages: msgs.map((msg) => aminoTypes.fromAmino(msg)),
128369
+ memo: params.memo,
128370
+ }),
128371
+ authInfoBytes: protoSigning.makeAuthInfoBytes([
128372
+ {
128373
+ pubkey,
128374
+ sequence: account.sequence,
128375
+ },
128376
+ ], fee.amount, Number.parseInt(fee.gas), undefined, undefined, signing.SignMode.SIGN_MODE_LEGACY_AMINO_JSON),
128377
+ signatures: [THORChainApp.extractSignatureFromTLV(signature)],
128378
+ });
128379
+ return encoding.toBase64(tx$1.TxRaw.encode(rawTx).finish());
128380
+ });
128381
+ }
128382
+ getProtocolAminoMessages() {
128383
+ const prefix = this.getPrefix(this.network);
128384
+ return new build$7.AminoTypes({
128385
+ '/types.MsgSend': {
128386
+ aminoType: `thorchain/MsgSend`,
128387
+ toAmino: (params) => ({
128388
+ from_address: xchainCosmosSdk.base64ToBech32(params.fromAddress, prefix),
128389
+ to_address: xchainCosmosSdk.base64ToBech32(params.toAddress, prefix),
128390
+ amount: [...params.amount],
128391
+ }),
128392
+ fromAmino: (params) => ({
128393
+ fromAddress: xchainCosmosSdk.bech32ToBase64(params.from_address),
128394
+ toAddress: xchainCosmosSdk.bech32ToBase64(params.to_address),
128395
+ amount: [...params.amount],
128396
+ }),
128397
+ },
128398
+ '/types.MsgDeposit': {
128399
+ aminoType: `thorchain/MsgDeposit`,
128400
+ toAmino: (params) => ({
128401
+ signer: xchainCosmosSdk.base64ToBech32(params.signer, prefix),
128402
+ memo: params.memo,
128403
+ coins: params.coins.map((coin) => {
128404
+ return Object.assign(Object.assign({}, coin), { asset: xchainUtil.assetToString(coin.asset) });
128405
+ }),
128406
+ }),
128407
+ fromAmino: (params) => ({
128408
+ signer: xchainCosmosSdk.bech32ToBase64(params.signer),
128409
+ memo: params.memo,
128410
+ coins: params.coins.map((coin) => {
128411
+ return Object.assign(Object.assign({}, coin), { asset: xchainUtil.assetFromStringEx(coin.asset) });
128412
+ }),
128413
+ }),
128414
+ },
128415
+ });
128416
+ }
128417
+ }
128418
+
128136
128419
  exports.AssetRuneNative = AssetRuneNative;
128137
- exports.Client = Client;
128420
+ exports.Client = ClientKeystore;
128421
+ exports.ClientKeystore = ClientKeystore;
128422
+ exports.ClientLedger = ClientLedger;
128138
128423
  exports.DEFAULT_EXPLORER_URL = DEFAULT_EXPLORER_URL;
128139
128424
  exports.DEFAULT_FEE = DEFAULT_FEE;
128140
128425
  exports.DEFAULT_GAS_LIMIT_VALUE = DEFAULT_GAS_LIMIT_VALUE;
@@ -128155,4 +128440,7 @@ exports.getExplorerAddressUrl = getExplorerAddressUrl;
128155
128440
  exports.getExplorerTxUrl = getExplorerTxUrl;
128156
128441
  exports.getPrefix = getPrefix;
128157
128442
  exports.isAssetRuneNative = isAssetRuneNative;
128443
+ exports.parseDerivationPath = parseDerivationPath;
128444
+ exports.sortAndStringifyJson = sortAndStringifyJson;
128445
+ exports.sortedObject = sortedObject;
128158
128446
  //# sourceMappingURL=index.js.map