carbon-js-sdk 0.4.14 → 0.4.16

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/CarbonSDK.js CHANGED
@@ -236,6 +236,10 @@ class CarbonSDK {
236
236
  });
237
237
  }
238
238
  disconnect() {
239
+ var _a;
240
+ if ((_a = this.wallet) === null || _a === void 0 ? void 0 : _a.isLedgerSigner()) {
241
+ this.wallet.signer.ledger.disconnect();
242
+ }
239
243
  return new CarbonSDK(Object.assign(Object.assign({}, this), { wallet: null, skipInit: true }));
240
244
  }
241
245
  connectWithPrivateKey(privateKey, opts) {
@@ -12,8 +12,8 @@ export interface ETHClientOpts {
12
12
  blockchain: typeof ETHClient.SUPPORTED_BLOCKCHAINS[number];
13
13
  }
14
14
  interface ETHTxParams {
15
- gasPriceGwei: BigNumber;
16
- gasLimit: BigNumber;
15
+ gasPriceGwei?: BigNumber;
16
+ gasLimit?: BigNumber;
17
17
  ethAddress: string;
18
18
  signer: ethers.Signer;
19
19
  nonce?: number;
@@ -26,8 +26,8 @@ export interface BridgeParams {
26
26
  recoveryAddress: string;
27
27
  toAddress: string;
28
28
  feeAmount: BigNumber;
29
- gasPriceGwei: BigNumber;
30
- gasLimit: BigNumber;
29
+ gasPriceGwei?: BigNumber;
30
+ gasLimit?: BigNumber;
31
31
  signer: ethers.Signer;
32
32
  signCompleteCallback?: () => void;
33
33
  nonce?: number;
@@ -75,11 +75,7 @@ class ETHClient {
75
75
  const rpcProvider = this.getProvider();
76
76
  const contract = new ethers_1.ethers.Contract(contractAddress, eth_1.ABIs.erc20, rpcProvider);
77
77
  const nonce = yield this.getTxNonce(ethAddress, params.nonce, rpcProvider);
78
- const approveResultTx = yield contract.connect(signer).approve(spenderAddress !== null && spenderAddress !== void 0 ? spenderAddress : token.bridgeAddress, ethers_1.ethers.constants.MaxUint256, {
79
- nonce,
80
- gasPrice: gasPriceGwei.shiftedBy(9).toString(10),
81
- gasLimit: gasLimit.toString(10),
82
- });
78
+ const approveResultTx = yield contract.connect(signer).approve(spenderAddress !== null && spenderAddress !== void 0 ? spenderAddress : token.bridgeAddress, ethers_1.ethers.constants.MaxUint256, Object.assign(Object.assign({ nonce }, gasPriceGwei && ({ gasPrice: gasPriceGwei.shiftedBy(9).toString(10) })), gasLimit && ({ gasLimit: gasLimit.toString(10) })));
83
79
  return approveResultTx;
84
80
  });
85
81
  }
@@ -127,13 +123,7 @@ class ETHClient {
127
123
  amount.toString(10),
128
124
  feeAmount.toString(10),
129
125
  amount.toString(10),
130
- ], // callAmount
131
- {
132
- gasLimit: gasLimit.toString(10),
133
- gasPrice: gasPriceGwei.shiftedBy(9).toString(10),
134
- nonce,
135
- value: ethAmount.toString(10),
136
- });
126
+ ], Object.assign(Object.assign(Object.assign({}, gasPriceGwei && ({ gasPrice: gasPriceGwei.shiftedBy(9).toString(10) })), gasLimit && ({ gasLimit: gasLimit.toString(10) })), { nonce, value: ethAmount.toString(10) }));
137
127
  signCompleteCallback === null || signCompleteCallback === void 0 ? void 0 : signCompleteCallback();
138
128
  return bridgeResultTx;
139
129
  });
@@ -141,7 +131,7 @@ class ETHClient {
141
131
  lockDeposit(params) {
142
132
  return __awaiter(this, void 0, void 0, function* () {
143
133
  const { address, token, amount, gasPriceGwei, gasLimit, ethAddress, signer, signCompleteCallback } = params;
144
- if (gasLimit.lt(150000)) {
134
+ if (gasLimit === null || gasLimit === void 0 ? void 0 : gasLimit.lt(150000)) {
145
135
  throw new Error("Minimum gas required: 150,000");
146
136
  }
147
137
  const networkConfig = this.getNetworkConfig();
@@ -164,7 +154,7 @@ class ETHClient {
164
154
  amount.toString(),
165
155
  "0",
166
156
  amount.toString(), // callAmount
167
- ], Object.assign({ nonce, value: "0", gasPrice: gasPriceGwei.shiftedBy(9).toString(10), gasLimit: gasLimit.toString(10) }, (token.tokenAddress === "0000000000000000000000000000000000000000" && {
157
+ ], Object.assign(Object.assign(Object.assign({ nonce, value: "0" }, gasPriceGwei && ({ gasPrice: gasPriceGwei.shiftedBy(9).toString(10) })), gasLimit && ({ gasLimit: gasLimit.toString(10) })), (token.tokenAddress === "0000000000000000000000000000000000000000" && {
168
158
  value: amount.toString(),
169
159
  })));
170
160
  signCompleteCallback === null || signCompleteCallback === void 0 ? void 0 : signCompleteCallback();
@@ -16,6 +16,7 @@ declare class KeplrAccount {
16
16
  } | undefined;
17
17
  };
18
18
  static createKeplrSigner(keplr: Keplr, chainInfo: ChainInfo, account: Key): CarbonSigner;
19
+ static createKeplrSignerAmino(keplr: Keplr, chainInfo: ChainInfo, account: Key): CarbonSigner;
19
20
  static queryFeeCurrencies(configProvider: SDKProvider): Promise<FeeCurrency[]>;
20
21
  static processCurrencies(feeCurrencies: FeeCurrency[]): AppCurrency[];
21
22
  static getChainInfo(configProvider: SDKProvider): Promise<ChainInfo>;
@@ -45,6 +45,26 @@ class KeplrAccount {
45
45
  getAccounts,
46
46
  };
47
47
  }
48
+ static createKeplrSignerAmino(keplr, chainInfo, account) {
49
+ const signAmino = (signerAddress, doc) => __awaiter(this, void 0, void 0, function* () {
50
+ const signOpts = { preferNoSetFee: true };
51
+ return yield keplr.signAmino(chainInfo.chainId, signerAddress, doc, signOpts);
52
+ });
53
+ const getAccounts = () => __awaiter(this, void 0, void 0, function* () {
54
+ return [
55
+ {
56
+ algo: "secp256k1",
57
+ address: account.bech32Address,
58
+ pubkey: account.pubKey,
59
+ },
60
+ ];
61
+ });
62
+ return {
63
+ type: wallet_1.CarbonSignerTypes.BrowserInjected,
64
+ signAmino,
65
+ getAccounts,
66
+ };
67
+ }
48
68
  static queryFeeCurrencies(configProvider) {
49
69
  return __awaiter(this, void 0, void 0, function* () {
50
70
  const tokenClient = configProvider.getTokenClient();
@@ -11,6 +11,7 @@ declare class CosmosLedger {
11
11
  testDevice(): Promise<this>;
12
12
  private isReady;
13
13
  connect(timeout?: number): Promise<this>;
14
+ disconnect(): Promise<void>;
14
15
  getCosmosAppVersion(): Promise<string>;
15
16
  isCosmosAppOpen(): Promise<void>;
16
17
  getOpenApp(): Promise<any>;
@@ -141,6 +141,11 @@ class CosmosLedger {
141
141
  return this;
142
142
  });
143
143
  }
144
+ disconnect() {
145
+ return __awaiter(this, void 0, void 0, function* () {
146
+ yield this.cosmosApp.transport.close();
147
+ });
148
+ }
144
149
  // returns the cosmos app version as a string like "1.1.0"
145
150
  getCosmosAppVersion() {
146
151
  return __awaiter(this, void 0, void 0, function* () {
@@ -110,7 +110,7 @@ class CarbonWallet {
110
110
  publicKeyBase64 }));
111
111
  }
112
112
  static withKeplr(keplr, chainInfo, keplrKey, opts = {}) {
113
- const signer = provider_1.KeplrAccount.createKeplrSigner(keplr, chainInfo, keplrKey);
113
+ const signer = keplrKey.isNanoLedger ? provider_1.KeplrAccount.createKeplrSignerAmino(keplr, chainInfo, keplrKey) : provider_1.KeplrAccount.createKeplrSigner(keplr, chainInfo, keplrKey);
114
114
  const publicKeyBase64 = Buffer.from(keplrKey.pubKey).toString("base64");
115
115
  const wallet = CarbonWallet.withSigner(signer, publicKeyBase64, Object.assign(Object.assign({}, opts), { providerAgent: 'keplr-extension' }));
116
116
  return wallet;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-js-sdk",
3
- "version": "0.4.14",
3
+ "version": "0.4.16",
4
4
  "description": "TypeScript SDK for Carbon blockchain",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",