@xchainjs/xchain-thorchain 0.19.3 → 0.19.4
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/CHANGELOG.md +10 -0
- package/README.md +11 -1
- package/lib/client.d.ts +15 -3
- package/lib/index.esm.js +19 -5
- package/lib/index.js +19 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -48,7 +48,17 @@ const client = new Client({ network: Network.Testnet, phrase: 'my secret phrase'
|
|
|
48
48
|
|
|
49
49
|
// get address
|
|
50
50
|
const address = client.getAddress()
|
|
51
|
-
console.log('address:',
|
|
51
|
+
console.log('address:', address) // address: tthor13gym97tmw3axj3hpewdggy2cr288d3qffr8skg
|
|
52
|
+
|
|
53
|
+
// get private key
|
|
54
|
+
const privKey = client.getPrivKey()
|
|
55
|
+
console.log('privKey:', privKey.toBase64()) // privKey: {your-private-key} base64 encoded
|
|
56
|
+
console.log('privKey:', privKey.toBuffer()) // privKey: {your-private-key} as `Buffer`
|
|
57
|
+
|
|
58
|
+
// get public key
|
|
59
|
+
const pubKey = client.getPubKey()
|
|
60
|
+
console.log('pubKey:', pubKey.toBase64()) // pubKey: {your-public-key} base64 encoded
|
|
61
|
+
console.log('pubKey:', pubKey.toBuffer()) // pubKey: {your-public-key} as `Buffer`
|
|
52
62
|
|
|
53
63
|
// get balances
|
|
54
64
|
const balances = await client.getBalance(address)
|
package/lib/client.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Address, Balance, Fees, Network, Tx, TxHash, TxHistoryParams, TxParams, TxsPage, XChainClient, XChainClientParams } from '@xchainjs/xchain-client';
|
|
2
2
|
import { CosmosSDKClient, RPCTxResult } from '@xchainjs/xchain-cosmos';
|
|
3
3
|
import { Asset } from '@xchainjs/xchain-util';
|
|
4
|
+
import { PrivKey, PubKey } from 'cosmos-client';
|
|
4
5
|
import { ClientUrl, DepositParam, ExplorerUrls, NodeUrl, ThorchainClientParams } from './types';
|
|
5
6
|
/**
|
|
6
7
|
* Interface for custom Thorchain client
|
|
@@ -118,15 +119,26 @@ declare class Client implements ThorchainClient, XChainClient {
|
|
|
118
119
|
*/
|
|
119
120
|
getFullDerivationPath(index: number): string;
|
|
120
121
|
/**
|
|
121
|
-
*
|
|
122
|
-
* Get private key.
|
|
122
|
+
* Get private key
|
|
123
123
|
*
|
|
124
|
+
* @param {number} index the HD wallet index (optional)
|
|
124
125
|
* @returns {PrivKey} The private key generated from the given phrase
|
|
125
126
|
*
|
|
126
127
|
* @throws {"Phrase not set"}
|
|
127
128
|
* Throws an error if phrase has not been set before
|
|
128
129
|
* */
|
|
129
|
-
|
|
130
|
+
getPrivKey(index?: number): PrivKey;
|
|
131
|
+
/**
|
|
132
|
+
* Get public key
|
|
133
|
+
*
|
|
134
|
+
* @param {number} index the HD wallet index (optional)
|
|
135
|
+
*
|
|
136
|
+
* @returns {PubKey} The public key generated from the given phrase
|
|
137
|
+
*
|
|
138
|
+
* @throws {"Phrase not set"}
|
|
139
|
+
* Throws an error if phrase has not been set before
|
|
140
|
+
**/
|
|
141
|
+
getPubKey(index?: number): PubKey;
|
|
130
142
|
/**
|
|
131
143
|
* Get the current address.
|
|
132
144
|
*
|
package/lib/index.esm.js
CHANGED
|
@@ -653,18 +653,32 @@ var Client = /** @class */ (function () {
|
|
|
653
653
|
return this.rootDerivationPaths[this.network] + ("" + index);
|
|
654
654
|
};
|
|
655
655
|
/**
|
|
656
|
-
*
|
|
657
|
-
* Get private key.
|
|
656
|
+
* Get private key
|
|
658
657
|
*
|
|
658
|
+
* @param {number} index the HD wallet index (optional)
|
|
659
659
|
* @returns {PrivKey} The private key generated from the given phrase
|
|
660
660
|
*
|
|
661
661
|
* @throws {"Phrase not set"}
|
|
662
662
|
* Throws an error if phrase has not been set before
|
|
663
663
|
* */
|
|
664
|
-
Client.prototype.
|
|
664
|
+
Client.prototype.getPrivKey = function (index) {
|
|
665
665
|
if (index === void 0) { index = 0; }
|
|
666
666
|
return this.cosmosClient.getPrivKeyFromMnemonic(this.phrase, this.getFullDerivationPath(index));
|
|
667
667
|
};
|
|
668
|
+
/**
|
|
669
|
+
* Get public key
|
|
670
|
+
*
|
|
671
|
+
* @param {number} index the HD wallet index (optional)
|
|
672
|
+
*
|
|
673
|
+
* @returns {PubKey} The public key generated from the given phrase
|
|
674
|
+
*
|
|
675
|
+
* @throws {"Phrase not set"}
|
|
676
|
+
* Throws an error if phrase has not been set before
|
|
677
|
+
**/
|
|
678
|
+
Client.prototype.getPubKey = function (index) {
|
|
679
|
+
if (index === void 0) { index = 0; }
|
|
680
|
+
return this.getPrivKey(index).getPubKey();
|
|
681
|
+
};
|
|
668
682
|
/**
|
|
669
683
|
* Get the current address.
|
|
670
684
|
*
|
|
@@ -811,7 +825,7 @@ var Client = /** @class */ (function () {
|
|
|
811
825
|
return [4 /*yield*/, buildDepositTx(msgNativeTx, this.getClientUrl().node)];
|
|
812
826
|
case 2:
|
|
813
827
|
unsignedStdTx = _f.sent();
|
|
814
|
-
privateKey = this.
|
|
828
|
+
privateKey = this.getPrivKey(walletIndex);
|
|
815
829
|
accAddress = AccAddress.fromBech32(signer);
|
|
816
830
|
return [4 /*yield*/, this.cosmosClient.signAndBroadcast(unsignedStdTx, privateKey, accAddress)];
|
|
817
831
|
case 3: return [2 /*return*/, (_c = (_b = (_f.sent())) === null || _b === void 0 ? void 0 : _b.txhash) !== null && _c !== void 0 ? _c : ''];
|
|
@@ -844,7 +858,7 @@ var Client = /** @class */ (function () {
|
|
|
844
858
|
throw new Error('insufficient funds');
|
|
845
859
|
}
|
|
846
860
|
return [4 /*yield*/, this.cosmosClient.transfer({
|
|
847
|
-
privkey: this.
|
|
861
|
+
privkey: this.getPrivKey(walletIndex),
|
|
848
862
|
from: this.getAddress(walletIndex),
|
|
849
863
|
to: recipient,
|
|
850
864
|
amount: amount.amount().toString(),
|
package/lib/index.js
CHANGED
|
@@ -661,18 +661,32 @@ var Client = /** @class */ (function () {
|
|
|
661
661
|
return this.rootDerivationPaths[this.network] + ("" + index);
|
|
662
662
|
};
|
|
663
663
|
/**
|
|
664
|
-
*
|
|
665
|
-
* Get private key.
|
|
664
|
+
* Get private key
|
|
666
665
|
*
|
|
666
|
+
* @param {number} index the HD wallet index (optional)
|
|
667
667
|
* @returns {PrivKey} The private key generated from the given phrase
|
|
668
668
|
*
|
|
669
669
|
* @throws {"Phrase not set"}
|
|
670
670
|
* Throws an error if phrase has not been set before
|
|
671
671
|
* */
|
|
672
|
-
Client.prototype.
|
|
672
|
+
Client.prototype.getPrivKey = function (index) {
|
|
673
673
|
if (index === void 0) { index = 0; }
|
|
674
674
|
return this.cosmosClient.getPrivKeyFromMnemonic(this.phrase, this.getFullDerivationPath(index));
|
|
675
675
|
};
|
|
676
|
+
/**
|
|
677
|
+
* Get public key
|
|
678
|
+
*
|
|
679
|
+
* @param {number} index the HD wallet index (optional)
|
|
680
|
+
*
|
|
681
|
+
* @returns {PubKey} The public key generated from the given phrase
|
|
682
|
+
*
|
|
683
|
+
* @throws {"Phrase not set"}
|
|
684
|
+
* Throws an error if phrase has not been set before
|
|
685
|
+
**/
|
|
686
|
+
Client.prototype.getPubKey = function (index) {
|
|
687
|
+
if (index === void 0) { index = 0; }
|
|
688
|
+
return this.getPrivKey(index).getPubKey();
|
|
689
|
+
};
|
|
676
690
|
/**
|
|
677
691
|
* Get the current address.
|
|
678
692
|
*
|
|
@@ -819,7 +833,7 @@ var Client = /** @class */ (function () {
|
|
|
819
833
|
return [4 /*yield*/, buildDepositTx(msgNativeTx, this.getClientUrl().node)];
|
|
820
834
|
case 2:
|
|
821
835
|
unsignedStdTx = _f.sent();
|
|
822
|
-
privateKey = this.
|
|
836
|
+
privateKey = this.getPrivKey(walletIndex);
|
|
823
837
|
accAddress = cosmosClient.AccAddress.fromBech32(signer);
|
|
824
838
|
return [4 /*yield*/, this.cosmosClient.signAndBroadcast(unsignedStdTx, privateKey, accAddress)];
|
|
825
839
|
case 3: return [2 /*return*/, (_c = (_b = (_f.sent())) === null || _b === void 0 ? void 0 : _b.txhash) !== null && _c !== void 0 ? _c : ''];
|
|
@@ -852,7 +866,7 @@ var Client = /** @class */ (function () {
|
|
|
852
866
|
throw new Error('insufficient funds');
|
|
853
867
|
}
|
|
854
868
|
return [4 /*yield*/, this.cosmosClient.transfer({
|
|
855
|
-
privkey: this.
|
|
869
|
+
privkey: this.getPrivKey(walletIndex),
|
|
856
870
|
from: this.getAddress(walletIndex),
|
|
857
871
|
to: recipient,
|
|
858
872
|
amount: amount.amount().toString(),
|