carbon-js-sdk 0.7.1-beta.4 → 0.7.1-beta.6

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.
@@ -17,9 +17,13 @@ export * as Carbon from "./codec/carbon-models";
17
17
  export interface CarbonSDKOpts {
18
18
  network: Network;
19
19
  tmClient: Tendermint34Client;
20
+ wallet?: CarbonWallet;
20
21
  chainId?: string;
21
22
  evmChainId?: string;
22
23
  token?: TokenClient;
24
+ query?: CarbonQueryClient;
25
+ hydrogen?: HydrogenClient;
26
+ insights?: InsightsQueryClient;
23
27
  config?: Partial<NetworkConfig>;
24
28
  grpcQueryClient?: GrpcQueryClient;
25
29
  useTmAbciQuery?: boolean;
package/lib/CarbonSDK.js CHANGED
@@ -63,29 +63,33 @@ const DEFAULT_SDK_INIT_OPTS = {
63
63
  */
64
64
  class CarbonSDK {
65
65
  constructor(opts) {
66
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
66
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
67
67
  this.network = (_a = opts.network) !== null && _a !== void 0 ? _a : constant_1.DEFAULT_NETWORK;
68
68
  this.configOverride = (_b = opts.config) !== null && _b !== void 0 ? _b : {};
69
69
  this.networkConfig = util_1.GenericUtils.overrideConfig(constant_1.NetworkConfigs[this.network], this.configOverride);
70
70
  this.useTmAbciQuery = (_c = opts.useTmAbciQuery) !== null && _c !== void 0 ? _c : false;
71
71
  this.tmClient = opts.tmClient;
72
+ this.wallet = opts.wallet;
72
73
  this.chainId = (_e = (_d = opts.chainId) !== null && _d !== void 0 ? _d : constant_1.CarbonChainIDs[this.network]) !== null && _e !== void 0 ? _e : constant_1.CarbonChainIDs[constant_1.Network.MainNet];
73
74
  this.evmChainId = (_g = (_f = opts.evmChainId) !== null && _f !== void 0 ? _f : constant_1.CarbonEvmChainIDs[this.network]) !== null && _g !== void 0 ? _g : constant_1.CarbonEvmChainIDs[constant_1.Network.MainNet];
74
- let grpcClient;
75
- if (opts.useTmAbciQuery !== true && this.networkConfig.grpcUrl) {
76
- const transport = typeof window === "undefined" ? grpc_web_node_http_transport_1.NodeHttpTransport() : undefined;
77
- grpcClient = (_h = opts.grpcQueryClient) !== null && _h !== void 0 ? _h : new GrpcQueryClient_1.default(this.networkConfig.grpcWebUrl, {
78
- transport,
75
+ let carbonQueryClient;
76
+ if (!opts.query) {
77
+ let grpcClient;
78
+ if (opts.useTmAbciQuery !== true && this.networkConfig.grpcUrl) {
79
+ const transport = typeof window === "undefined" ? grpc_web_node_http_transport_1.NodeHttpTransport() : undefined;
80
+ grpcClient = (_h = opts.grpcQueryClient) !== null && _h !== void 0 ? _h : new GrpcQueryClient_1.default(this.networkConfig.grpcWebUrl, {
81
+ transport,
82
+ });
83
+ }
84
+ carbonQueryClient = new clients_1.CarbonQueryClient({
85
+ tmClient: this.tmClient,
86
+ grpcClient,
79
87
  });
80
88
  }
81
- this.query = new clients_1.CarbonQueryClient({
82
- tmClient: this.tmClient,
83
- grpcClient,
84
- });
85
- this.insights = new clients_1.InsightsQueryClient(this.networkConfig);
86
- this.token = (_j = opts.token) !== null && _j !== void 0 ? _j : clients_1.TokenClient.instance(this.query, this);
87
- this.hydrogen = new clients_1.HydrogenClient(this.networkConfig, this.token);
88
- this.hydrogen = clients_1.HydrogenClient.instance(this.networkConfig, this.token);
89
+ this.query = ((_j = opts.query) !== null && _j !== void 0 ? _j : carbonQueryClient);
90
+ this.insights = (_k = opts.insights) !== null && _k !== void 0 ? _k : new clients_1.InsightsQueryClient(this.networkConfig);
91
+ this.token = (_l = opts.token) !== null && _l !== void 0 ? _l : clients_1.TokenClient.instance(this.query, this);
92
+ this.hydrogen = (_m = opts.hydrogen) !== null && _m !== void 0 ? _m : new clients_1.HydrogenClient(this.networkConfig, this.token);
89
93
  this.admin = new modules_1.AdminModule(this);
90
94
  this.alliance = new modules_1.AllianceModule(this);
91
95
  this.order = new modules_1.OrderModule(this);
@@ -250,9 +254,15 @@ class CarbonSDK {
250
254
  return {
251
255
  network: this.network,
252
256
  config: this.configOverride,
253
- tmClient: this.tmClient,
254
257
  chainId: this.chainId,
258
+ evmChainId: this.evmChainId,
255
259
  useTmAbciQuery: this.useTmAbciQuery,
260
+ wallet: this.wallet,
261
+ tmClient: this.tmClient,
262
+ token: this.token,
263
+ query: this.query,
264
+ hydrogen: this.hydrogen,
265
+ insights: this.insights,
256
266
  };
257
267
  }
258
268
  connect(wallet) {
@@ -280,7 +290,9 @@ class CarbonSDK {
280
290
  if ((_a = this.wallet) === null || _a === void 0 ? void 0 : _a.isLedgerSigner()) {
281
291
  this.wallet.signer.ledger.disconnect();
282
292
  }
283
- return new CarbonSDK(Object.assign(Object.assign({}, this), { wallet: null, skipInit: true }));
293
+ const opts = this.generateOpts();
294
+ delete opts.wallet;
295
+ return new CarbonSDK(opts);
284
296
  }
285
297
  connectWithPrivateKey(privateKey, opts) {
286
298
  return __awaiter(this, void 0, void 0, function* () {
@@ -2,6 +2,13 @@ import { TokenClient } from '../clients';
2
2
  import { Coin } from '../codec/carbon-models';
3
3
  import { Network } from "../constant/network";
4
4
  import { SimpleMap } from "./type";
5
+ export declare enum SmartWalletBlockchain {
6
+ Neo = "neo",
7
+ Ethereum = "eth",
8
+ BinanceSmartChain = "bsc",
9
+ Arbitrum = "arbitrum",
10
+ Polygon = "polygon"
11
+ }
5
12
  export declare enum Blockchain {
6
13
  Neo = "neo",
7
14
  Ethereum = "eth",
@@ -1,8 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isEvmChain = exports.EvmChains = exports.blockchainForChainIdV2 = exports.getBlockchainFromChainV2 = exports.blockchainForChainId = exports.getBlockchainFromChain = exports.getChainFromID = exports.parseBlockchain = exports.chainIdsByBlockchain = exports.CHAIN_IDS_TEST = exports.CHAIN_IDS_DEV = exports.CHAIN_IDS = exports.ChainNames = exports.isIbcBridge = exports.BRIDGE_IDS = exports.BLOCKCHAIN_V2_TO_V1_MAPPING = exports.Blockchain = void 0;
3
+ exports.isEvmChain = exports.EvmChains = exports.blockchainForChainIdV2 = exports.getBlockchainFromChainV2 = exports.blockchainForChainId = exports.getBlockchainFromChain = exports.getChainFromID = exports.parseBlockchain = exports.chainIdsByBlockchain = exports.CHAIN_IDS_TEST = exports.CHAIN_IDS_DEV = exports.CHAIN_IDS = exports.ChainNames = exports.isIbcBridge = exports.BRIDGE_IDS = exports.BLOCKCHAIN_V2_TO_V1_MAPPING = exports.Blockchain = exports.SmartWalletBlockchain = void 0;
4
4
  const network_1 = require("../constant/network");
5
5
  const ethermint_1 = require("./ethermint");
6
+ var SmartWalletBlockchain;
7
+ (function (SmartWalletBlockchain) {
8
+ SmartWalletBlockchain["Neo"] = "neo";
9
+ SmartWalletBlockchain["Ethereum"] = "eth";
10
+ SmartWalletBlockchain["BinanceSmartChain"] = "bsc";
11
+ SmartWalletBlockchain["Arbitrum"] = "arbitrum";
12
+ SmartWalletBlockchain["Polygon"] = "polygon";
13
+ })(SmartWalletBlockchain = exports.SmartWalletBlockchain || (exports.SmartWalletBlockchain = {}));
6
14
  var Blockchain;
7
15
  (function (Blockchain) {
8
16
  Blockchain["Neo"] = "neo";
@@ -5,15 +5,16 @@ import { ProviderAgent } from "../constant/walletProvider";
5
5
  import { ChainInfo, CosmosLedger, Keplr, MetaMask } from "../provider";
6
6
  import { CarbonTx } from "../util";
7
7
  import { SWTHAddressOptions } from "../util/address";
8
+ import { SmartWalletBlockchain } from "../util/blockchain";
8
9
  import { SimpleMap } from "../util/type";
9
10
  import { StdSignature } from "@cosmjs/amino";
10
11
  import { EncodeObject, OfflineDirectSigner, OfflineSigner } from "@cosmjs/proto-signing";
11
12
  import { Account, DeliverTxResponse } from "@cosmjs/stargate";
12
13
  import { Tendermint34Client } from "@cosmjs/tendermint-rpc";
13
14
  import { BroadcastTxSyncResponse } from "@cosmjs/tendermint-rpc/build/tendermint34/responses";
15
+ import { Key as LeapKey } from "@cosmos-kit/core";
14
16
  import { Leap } from "@cosmos-kit/leap";
15
17
  import { Key } from "@keplr-wallet/types";
16
- import { Key as LeapKey } from "@cosmos-kit/core";
17
18
  import BigNumber from "bignumber.js";
18
19
  import { TxRaw as StargateTxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
19
20
  import { CarbonSigner, CarbonSignerTypes } from "./CarbonSigner";
@@ -166,7 +167,7 @@ export declare class CarbonWallet {
166
167
  isPrivateKeySigner(): boolean;
167
168
  isBrowserInjectedSigner(): boolean;
168
169
  isSmartWalletEnabled(): boolean;
169
- getSmartWalletPrivateKey(): Buffer | null;
170
+ getSmartWalletPrivateKey(blockchain?: SmartWalletBlockchain): Buffer | null;
170
171
  getGasCost(msgTypeUrl: string): BigNumber;
171
172
  getGasPrice(denom: string): BigNumber;
172
173
  getFee(msgTypeUrl: string, denom?: string): BigNumber;
@@ -10,11 +10,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.CarbonWallet = void 0;
13
+ const codec_1 = require("../codec");
14
+ const auth_1 = require("../codec/cosmos/auth/v1beta1/auth");
15
+ const web3_1 = require("../codec/ethermint/types/v1/web3");
13
16
  const constant_1 = require("../constant");
14
17
  const walletProvider_1 = require("../constant/walletProvider");
15
18
  const provider_1 = require("../provider");
16
19
  const util_1 = require("../util");
17
20
  const address_1 = require("../util/address");
21
+ const blockchain_1 = require("../util/blockchain");
22
+ const ethermint_1 = require("../util/ethermint");
18
23
  const fetch_1 = require("../util/fetch");
19
24
  const generic_1 = require("../util/generic");
20
25
  const number_1 = require("../util/number");
@@ -25,10 +30,6 @@ const tendermint_rpc_1 = require("@cosmjs/tendermint-rpc");
25
30
  const tx_2 = require("cosmjs-types/cosmos/tx/v1beta1/tx");
26
31
  const CarbonSigner_1 = require("./CarbonSigner");
27
32
  const CarbonSigningClient_1 = require("./CarbonSigningClient");
28
- const ethermint_1 = require("../util/ethermint");
29
- const web3_1 = require("../codec/ethermint/types/v1/web3");
30
- const auth_1 = require("../codec/cosmos/auth/v1beta1/auth");
31
- const codec_1 = require("../codec");
32
33
  class CarbonWallet {
33
34
  constructor(opts) {
34
35
  var _a, _b, _c, _d, _e;
@@ -426,9 +427,20 @@ class CarbonWallet {
426
427
  isSmartWalletEnabled() {
427
428
  return !!(this.mnemonic || this.privateKey);
428
429
  }
429
- getSmartWalletPrivateKey() {
430
- if (this.mnemonic)
431
- return address_1.ETHAddress.mnemonicToPrivateKey(this.mnemonic);
430
+ getSmartWalletPrivateKey(blockchain = blockchain_1.SmartWalletBlockchain.Ethereum) {
431
+ if (this.mnemonic) {
432
+ switch (blockchain) {
433
+ case blockchain_1.SmartWalletBlockchain.Ethereum:
434
+ case blockchain_1.SmartWalletBlockchain.Arbitrum:
435
+ case blockchain_1.SmartWalletBlockchain.BinanceSmartChain:
436
+ case blockchain_1.SmartWalletBlockchain.Polygon:
437
+ return address_1.ETHAddress.mnemonicToPrivateKey(this.mnemonic);
438
+ case blockchain_1.SmartWalletBlockchain.Neo:
439
+ return address_1.NEOAddress.mnemonicToPrivateKey(this.mnemonic);
440
+ default:
441
+ return null;
442
+ }
443
+ }
432
444
  if (this.privateKey)
433
445
  return this.privateKey;
434
446
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-js-sdk",
3
- "version": "0.7.1-beta.4",
3
+ "version": "0.7.1-beta.6",
4
4
  "description": "TypeScript SDK for Carbon blockchain",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",