@xchainjs/xchain-thorchain 0.19.2-alpha1 → 0.19.5

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 CHANGED
@@ -1,4 +1,26 @@
1
- # Pre-release v.0.19.2-alpha1 (2021-09-27)
1
+ # v.0.19.5 (2021-11-22)
2
+
3
+ ## Add
4
+
5
+ - Provide `transferOffline` method
6
+
7
+ # v.0.19.4 (2021-11-22)
8
+
9
+ ## Add
10
+
11
+ - Provide `getPubKey` method to access public key
12
+
13
+ ## Change
14
+
15
+ - Make `getPrivKey` method `public` to access private key
16
+
17
+ # v.0.19.3 (2021-10-31)
18
+
19
+ ## Update
20
+
21
+ - Use latest `xchain-cosmos@0.13.8` to use `sync` mode for broadcasting txs
22
+
23
+ # v.0.19.2 (2021-09-27)
2
24
 
3
25
  ## Fix
4
26
 
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:', client.getAddress()) // address: tthor13gym97tmw3axj3hpewdggy2cr288d3qffr8skg
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,8 @@
1
1
  import { Address, Balance, Fees, Network, Tx, TxHash, TxHistoryParams, TxParams, TxsPage, XChainClient, XChainClientParams } from '@xchainjs/xchain-client';
2
- import { CosmosSDKClient, RPCTxResult } from '@xchainjs/xchain-cosmos';
2
+ import { CosmosSDKClient, RPCTxResult, TxOfflineParams } from '@xchainjs/xchain-cosmos';
3
3
  import { Asset } from '@xchainjs/xchain-util';
4
+ import { PrivKey, PubKey } from 'cosmos-client';
5
+ import { StdTx } from 'cosmos-client/x/auth';
4
6
  import { ClientUrl, DepositParam, ExplorerUrls, NodeUrl, ThorchainClientParams } from './types';
5
7
  /**
6
8
  * Interface for custom Thorchain client
@@ -118,15 +120,26 @@ declare class Client implements ThorchainClient, XChainClient {
118
120
  */
119
121
  getFullDerivationPath(index: number): string;
120
122
  /**
121
- * @private
122
- * Get private key.
123
+ * Get private key
123
124
  *
125
+ * @param {number} index the HD wallet index (optional)
124
126
  * @returns {PrivKey} The private key generated from the given phrase
125
127
  *
126
128
  * @throws {"Phrase not set"}
127
129
  * Throws an error if phrase has not been set before
128
130
  * */
129
- private getPrivateKey;
131
+ getPrivKey(index?: number): PrivKey;
132
+ /**
133
+ * Get public key
134
+ *
135
+ * @param {number} index the HD wallet index (optional)
136
+ *
137
+ * @returns {PubKey} The public key generated from the given phrase
138
+ *
139
+ * @throws {"Phrase not set"}
140
+ * Throws an error if phrase has not been set before
141
+ **/
142
+ getPubKey(index?: number): PubKey;
130
143
  /**
131
144
  * Get the current address.
132
145
  *
@@ -193,6 +206,13 @@ declare class Client implements ThorchainClient, XChainClient {
193
206
  * @returns {TxHash} The transaction hash.
194
207
  */
195
208
  transfer({ walletIndex, asset, amount, recipient, memo }: TxParams): Promise<TxHash>;
209
+ /**
210
+ * Transfer without broadcast balances with MsgSend
211
+ *
212
+ * @param {TxOfflineParams} params The transfer offline options.
213
+ * @returns {StdTx} The signed transaction.
214
+ */
215
+ transferOffline({ walletIndex, asset, amount, recipient, memo, from_balance, from_account_number, from_sequence, }: TxOfflineParams): Promise<StdTx>;
196
216
  /**
197
217
  * Get the fees.
198
218
  *
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
- * @private
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.getPrivateKey = function (index) {
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.getPrivateKey(walletIndex);
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.getPrivateKey(walletIndex),
861
+ privkey: this.getPrivKey(walletIndex),
848
862
  from: this.getAddress(walletIndex),
849
863
  to: recipient,
850
864
  amount: amount.amount().toString(),
@@ -865,6 +879,48 @@ var Client = /** @class */ (function () {
865
879
  });
866
880
  });
867
881
  };
882
+ /**
883
+ * Transfer without broadcast balances with MsgSend
884
+ *
885
+ * @param {TxOfflineParams} params The transfer offline options.
886
+ * @returns {StdTx} The signed transaction.
887
+ */
888
+ Client.prototype.transferOffline = function (_a) {
889
+ var _b = _a.walletIndex, walletIndex = _b === void 0 ? 0 : _b, _c = _a.asset, asset = _c === void 0 ? AssetRuneNative : _c, amount = _a.amount, recipient = _a.recipient, memo = _a.memo, _d = _a.from_balance, from_balance = _d === void 0 ? baseAmount('0', DECIMAL) : _d, _e = _a.from_account_number, from_account_number = _e === void 0 ? '0' : _e, _f = _a.from_sequence, from_sequence = _f === void 0 ? '0' : _f;
890
+ return __awaiter(this, void 0, void 0, function () {
891
+ var fee, result;
892
+ return __generator(this, function (_g) {
893
+ switch (_g.label) {
894
+ case 0:
895
+ registerCodecs(getPrefix(this.network));
896
+ return [4 /*yield*/, this.getFees()];
897
+ case 1:
898
+ fee = _g.sent();
899
+ if (from_balance === baseAmount('0', DECIMAL) ||
900
+ from_balance.amount().lt(amount.amount().plus(fee[FeeOption.Average].amount()))) {
901
+ throw new Error('insufficient funds');
902
+ }
903
+ return [4 /*yield*/, this.cosmosClient.transferSignedOffline({
904
+ privkey: this.getPrivKey(walletIndex),
905
+ from: this.getAddress(walletIndex),
906
+ from_account_number: from_account_number,
907
+ from_sequence: from_sequence,
908
+ to: recipient,
909
+ amount: amount.amount().toString(),
910
+ asset: getDenom(asset),
911
+ memo: memo,
912
+ fee: {
913
+ amount: [],
914
+ gas: DEFAULT_GAS_VALUE,
915
+ },
916
+ })];
917
+ case 2:
918
+ result = _g.sent();
919
+ return [2 /*return*/, JSON.parse(codec.toJSONString(result)).value];
920
+ }
921
+ });
922
+ });
923
+ };
868
924
  /**
869
925
  * Get the fees.
870
926
  *
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
- * @private
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.getPrivateKey = function (index) {
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.getPrivateKey(walletIndex);
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.getPrivateKey(walletIndex),
869
+ privkey: this.getPrivKey(walletIndex),
856
870
  from: this.getAddress(walletIndex),
857
871
  to: recipient,
858
872
  amount: amount.amount().toString(),
@@ -873,6 +887,48 @@ var Client = /** @class */ (function () {
873
887
  });
874
888
  });
875
889
  };
890
+ /**
891
+ * Transfer without broadcast balances with MsgSend
892
+ *
893
+ * @param {TxOfflineParams} params The transfer offline options.
894
+ * @returns {StdTx} The signed transaction.
895
+ */
896
+ Client.prototype.transferOffline = function (_a) {
897
+ var _b = _a.walletIndex, walletIndex = _b === void 0 ? 0 : _b, _c = _a.asset, asset = _c === void 0 ? xchainUtil.AssetRuneNative : _c, amount = _a.amount, recipient = _a.recipient, memo = _a.memo, _d = _a.from_balance, from_balance = _d === void 0 ? xchainUtil.baseAmount('0', DECIMAL) : _d, _e = _a.from_account_number, from_account_number = _e === void 0 ? '0' : _e, _f = _a.from_sequence, from_sequence = _f === void 0 ? '0' : _f;
898
+ return __awaiter(this, void 0, void 0, function () {
899
+ var fee, result;
900
+ return __generator(this, function (_g) {
901
+ switch (_g.label) {
902
+ case 0:
903
+ registerCodecs(getPrefix(this.network));
904
+ return [4 /*yield*/, this.getFees()];
905
+ case 1:
906
+ fee = _g.sent();
907
+ if (from_balance === xchainUtil.baseAmount('0', DECIMAL) ||
908
+ from_balance.amount().lt(amount.amount().plus(fee[xchainClient.FeeOption.Average].amount()))) {
909
+ throw new Error('insufficient funds');
910
+ }
911
+ return [4 /*yield*/, this.cosmosClient.transferSignedOffline({
912
+ privkey: this.getPrivKey(walletIndex),
913
+ from: this.getAddress(walletIndex),
914
+ from_account_number: from_account_number,
915
+ from_sequence: from_sequence,
916
+ to: recipient,
917
+ amount: amount.amount().toString(),
918
+ asset: getDenom(asset),
919
+ memo: memo,
920
+ fee: {
921
+ amount: [],
922
+ gas: DEFAULT_GAS_VALUE,
923
+ },
924
+ })];
925
+ case 2:
926
+ result = _g.sent();
927
+ return [2 /*return*/, JSON.parse(cosmosClient.codec.toJSONString(result)).value];
928
+ }
929
+ });
930
+ });
931
+ };
876
932
  /**
877
933
  * Get the fees.
878
934
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xchainjs/xchain-thorchain",
3
- "version": "0.19.2-alpha1",
3
+ "version": "0.19.5",
4
4
  "description": "Custom Thorchain client and utilities used by XChainJS clients",
5
5
  "keywords": [
6
6
  "THORChain",
@@ -33,8 +33,8 @@
33
33
  },
34
34
  "devDependencies": {
35
35
  "@types/big.js": "^6.0.0",
36
- "@xchainjs/xchain-client": "^0.10.1",
37
- "@xchainjs/xchain-cosmos": "^0.13.7",
36
+ "@xchainjs/xchain-client": "0.10.3",
37
+ "@xchainjs/xchain-cosmos": "0.14.0",
38
38
  "@xchainjs/xchain-crypto": "^0.2.4",
39
39
  "@xchainjs/xchain-util": "^0.3.0",
40
40
  "axios": "^0.21.0",
@@ -45,8 +45,8 @@
45
45
  "access": "public"
46
46
  },
47
47
  "peerDependencies": {
48
- "@xchainjs/xchain-client": "^0.10.1",
49
- "@xchainjs/xchain-cosmos": "^0.13.7",
48
+ "@xchainjs/xchain-client": "0.10.3",
49
+ "@xchainjs/xchain-cosmos": "0.14.0",
50
50
  "@xchainjs/xchain-crypto": "^0.2.4",
51
51
  "@xchainjs/xchain-util": "^0.3.0",
52
52
  "axios": "^0.21.0",