@cityofzion/bs-ethereum 2.6.2 → 2.7.1

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.
@@ -1,31 +1,31 @@
1
1
  import { Account, BSCalculableFee, BSWithExplorerService, BSWithLedger, BSWithNameService, BSWithNft, BlockchainDataService, BlockchainService, ExchangeDataService, ExplorerService, Network, NftDataService, Token, TransferParam, GetLedgerTransport } from '@cityofzion/blockchain-service';
2
2
  import { BSEthereumNetworkId } from './constants/BSEthereumConstants';
3
3
  import { EthersLedgerServiceEthereum } from './services/ledger/EthersLedgerServiceEthereum';
4
- export declare class BSEthereum<BSCustomName extends string = string> implements BlockchainService<BSCustomName, BSEthereumNetworkId>, BSWithNft, BSWithNameService, BSCalculableFee, BSWithLedger, BSWithExplorerService {
4
+ export declare class BSEthereum<BSName extends string = string> implements BlockchainService<BSName, BSEthereumNetworkId>, BSWithNft, BSWithNameService, BSCalculableFee<BSName>, BSWithLedger<BSName>, BSWithExplorerService {
5
5
  #private;
6
- readonly blockchainName: BSCustomName;
6
+ readonly name: BSName;
7
7
  readonly bip44DerivationPath: string;
8
8
  feeToken: Token;
9
9
  blockchainDataService: BlockchainDataService;
10
10
  exchangeDataService: ExchangeDataService;
11
- ledgerService: EthersLedgerServiceEthereum;
11
+ ledgerService: EthersLedgerServiceEthereum<BSName>;
12
12
  tokens: Token[];
13
13
  nftDataService: NftDataService;
14
14
  network: Network<BSEthereumNetworkId>;
15
15
  explorerService: ExplorerService;
16
- constructor(blockchainName: BSCustomName, network?: Network<BSEthereumNetworkId>, getLedgerTransport?: GetLedgerTransport);
16
+ constructor(name: BSName, network?: Network<BSEthereumNetworkId>, getLedgerTransport?: GetLedgerTransport<BSName>);
17
17
  testNetwork(network: Network<BSEthereumNetworkId>): Promise<void>;
18
18
  setNetwork(network: Network<BSEthereumNetworkId>): void;
19
19
  validateAddress(address: string): boolean;
20
20
  validateEncrypted(json: string): boolean;
21
21
  validateKey(key: string): boolean;
22
22
  validateNameServiceDomainFormat(domainName: string): boolean;
23
- generateAccountFromMnemonic(mnemonic: string[] | string, index: number): Account;
24
- generateAccountFromKey(key: string): Account;
25
- generateAccountFromPublicKey(publicKey: string): Account;
26
- decrypt(json: string, password: string): Promise<Account>;
23
+ generateAccountFromMnemonic(mnemonic: string[] | string, index: number): Account<BSName>;
24
+ generateAccountFromKey(key: string): Account<BSName>;
25
+ generateAccountFromPublicKey(publicKey: string): Account<BSName>;
26
+ decrypt(json: string, password: string): Promise<Account<BSName>>;
27
27
  encrypt(key: string, password: string): Promise<string>;
28
- transfer(param: TransferParam): Promise<string[]>;
29
- calculateTransferFee(param: TransferParam): Promise<string>;
28
+ transfer(param: TransferParam<BSName>): Promise<string[]>;
29
+ calculateTransferFee(param: TransferParam<BSName>): Promise<string>;
30
30
  resolveNameServiceDomain(domainName: string): Promise<string>;
31
31
  }
@@ -31,18 +31,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
31
31
  step((generator = generator.apply(thisArg, _arguments || [])).next());
32
32
  });
33
33
  };
34
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
35
- if (kind === "m") throw new TypeError("Private method is not writable");
36
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
37
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
38
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
39
- };
40
34
  var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
41
35
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
42
36
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
43
37
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
44
38
  };
45
- var _BSEthereum_instances, _BSEthereum_getLedgerTransport, _BSEthereum_generateSigner, _BSEthereum_buildTransferParams, _BSEthereum_setTokens;
39
+ var _BSEthereum_instances, _BSEthereum_generateSigner, _BSEthereum_buildTransferParams, _BSEthereum_setTokens;
46
40
  Object.defineProperty(exports, "__esModule", { value: true });
47
41
  exports.BSEthereum = void 0;
48
42
  const ethers_1 = require("ethers");
@@ -60,13 +54,11 @@ const GhostMarketNDSEthereum_1 = require("./services/nft-data/GhostMarketNDSEthe
60
54
  const BlockscoutESEthereum_1 = require("./services/explorer/BlockscoutESEthereum");
61
55
  const RpcBDSEthereum_1 = require("./services/blockchain-data/RpcBDSEthereum");
62
56
  class BSEthereum {
63
- constructor(blockchainName, network, getLedgerTransport) {
57
+ constructor(name, network, getLedgerTransport) {
64
58
  _BSEthereum_instances.add(this);
65
- _BSEthereum_getLedgerTransport.set(this, void 0);
66
59
  network = network !== null && network !== void 0 ? network : BSEthereumConstants_1.BSEthereumConstants.DEFAULT_NETWORK;
67
- this.blockchainName = blockchainName;
60
+ this.name = name;
68
61
  this.ledgerService = new EthersLedgerServiceEthereum_1.EthersLedgerServiceEthereum(this, getLedgerTransport);
69
- __classPrivateFieldSet(this, _BSEthereum_getLedgerTransport, getLedgerTransport, "f");
70
62
  this.bip44DerivationPath = BSEthereumConstants_1.BSEthereumConstants.DEFAULT_BIP44_DERIVATION_PATH;
71
63
  this.setNetwork(network);
72
64
  }
@@ -118,6 +110,7 @@ class BSEthereum {
118
110
  key: wallet.privateKey,
119
111
  type: 'privateKey',
120
112
  bip44Path,
113
+ blockchain: this.name,
121
114
  };
122
115
  }
123
116
  generateAccountFromKey(key) {
@@ -126,6 +119,7 @@ class BSEthereum {
126
119
  address: wallet.address,
127
120
  key,
128
121
  type: 'privateKey',
122
+ blockchain: this.name,
129
123
  };
130
124
  }
131
125
  generateAccountFromPublicKey(publicKey) {
@@ -134,6 +128,7 @@ class BSEthereum {
134
128
  address,
135
129
  key: publicKey,
136
130
  type: 'publicKey',
131
+ blockchain: this.name,
137
132
  };
138
133
  }
139
134
  decrypt(json, password) {
@@ -143,6 +138,7 @@ class BSEthereum {
143
138
  address: wallet.address,
144
139
  key: wallet.privateKey,
145
140
  type: 'privateKey',
141
+ blockchain: this.name,
146
142
  };
147
143
  });
148
144
  }
@@ -154,7 +150,7 @@ class BSEthereum {
154
150
  }
155
151
  transfer(param) {
156
152
  return __awaiter(this, void 0, void 0, function* () {
157
- const signer = yield __classPrivateFieldGet(this, _BSEthereum_instances, "m", _BSEthereum_generateSigner).call(this, param.senderAccount, param.isLedger);
153
+ const signer = yield __classPrivateFieldGet(this, _BSEthereum_instances, "m", _BSEthereum_generateSigner).call(this, param.senderAccount);
158
154
  const sentTransactionHashes = [];
159
155
  for (const intent of param.intents) {
160
156
  let transactionHash = '';
@@ -180,7 +176,7 @@ class BSEthereum {
180
176
  }
181
177
  calculateTransferFee(param) {
182
178
  return __awaiter(this, void 0, void 0, function* () {
183
- const signer = yield __classPrivateFieldGet(this, _BSEthereum_instances, "m", _BSEthereum_generateSigner).call(this, param.senderAccount, param.isLedger);
179
+ const signer = yield __classPrivateFieldGet(this, _BSEthereum_instances, "m", _BSEthereum_generateSigner).call(this, param.senderAccount);
184
180
  let fee = ethers_1.ethers.utils.parseEther('0');
185
181
  for (const intent of param.intents) {
186
182
  const { gasPrice, transactionParams } = yield __classPrivateFieldGet(this, _BSEthereum_instances, "m", _BSEthereum_buildTransferParams).call(this, intent);
@@ -202,10 +198,10 @@ class BSEthereum {
202
198
  }
203
199
  }
204
200
  exports.BSEthereum = BSEthereum;
205
- _BSEthereum_getLedgerTransport = new WeakMap(), _BSEthereum_instances = new WeakSet(), _BSEthereum_generateSigner = function _BSEthereum_generateSigner(account, isLedger) {
201
+ _BSEthereum_instances = new WeakSet(), _BSEthereum_generateSigner = function _BSEthereum_generateSigner(account) {
206
202
  return __awaiter(this, void 0, void 0, function* () {
207
203
  const provider = new ethers_1.ethers.providers.JsonRpcProvider(this.network.url);
208
- if (isLedger) {
204
+ if (account.isHardware) {
209
205
  if (!this.ledgerService.getLedgerTransport)
210
206
  throw new Error('You must provide getLedgerTransport function to use Ledger');
211
207
  if (typeof account.bip44Path !== 'string')
@@ -216,10 +212,18 @@ _BSEthereum_getLedgerTransport = new WeakMap(), _BSEthereum_instances = new Weak
216
212
  return new ethers_1.ethers.Wallet(account.key, provider);
217
213
  });
218
214
  }, _BSEthereum_buildTransferParams = function _BSEthereum_buildTransferParams(intent) {
219
- var _a;
220
215
  return __awaiter(this, void 0, void 0, function* () {
221
216
  const provider = new ethers_1.ethers.providers.JsonRpcProvider(this.network.url);
222
- const decimals = (_a = intent.tokenDecimals) !== null && _a !== void 0 ? _a : 18;
217
+ let decimals = intent.tokenDecimals;
218
+ if (!decimals) {
219
+ try {
220
+ const token = yield this.blockchainDataService.getTokenInfo(intent.tokenHash);
221
+ decimals = token.decimals;
222
+ }
223
+ catch (error) {
224
+ decimals = 18;
225
+ }
226
+ }
223
227
  const amount = ethersBigNumber.parseFixed(intent.amount, decimals);
224
228
  const gasPrice = yield provider.getGasPrice();
225
229
  let transactionParams = {
@@ -1,9 +1,8 @@
1
- import { Network, NetworkId, Token } from '@cityofzion/blockchain-service';
1
+ import { Network, NetworkId } from '@cityofzion/blockchain-service';
2
2
  export type BSEthereumNetworkId = NetworkId<'1' | '10' | '25' | '56' | '137' | '250' | '1101' | '8453' | '80002' | '42161' | '42220' | '43114' | '59144' | '11155111' | '47763' | '12227332'>;
3
3
  export declare class BSEthereumConstants {
4
4
  static DEFAULT_DECIMALS: number;
5
5
  static DEFAULT_GAS_LIMIT: number;
6
- static NATIVE_ASSET: Token;
7
6
  static NATIVE_SYMBOL_BY_NETWORK_ID: Record<BSEthereumNetworkId, string>;
8
7
  static RPC_LIST_BY_NETWORK_ID: Record<BSEthereumNetworkId, string[]>;
9
8
  static DEFAULT_BIP44_DERIVATION_PATH: string;
@@ -8,12 +8,6 @@ exports.BSEthereumConstants = BSEthereumConstants;
8
8
  _a = BSEthereumConstants;
9
9
  BSEthereumConstants.DEFAULT_DECIMALS = 18;
10
10
  BSEthereumConstants.DEFAULT_GAS_LIMIT = 0x5208;
11
- BSEthereumConstants.NATIVE_ASSET = {
12
- decimals: 18,
13
- hash: '-',
14
- name: 'ETH',
15
- symbol: 'ETH',
16
- };
17
11
  BSEthereumConstants.NATIVE_SYMBOL_BY_NETWORK_ID = {
18
12
  '1': 'ETH',
19
13
  '10': 'ETH',
@@ -4,8 +4,8 @@ export declare class BSEthereumHelper {
4
4
  static getNativeAsset(network: Network<BSEthereumNetworkId>): {
5
5
  symbol: string;
6
6
  name: string;
7
- hash: string;
8
7
  decimals: number;
8
+ hash: string;
9
9
  };
10
10
  static getNativeSymbol(network: Network<BSEthereumNetworkId>): string;
11
11
  static getRpcList(network: Network<BSEthereumNetworkId>): string[];
@@ -14,7 +14,7 @@ const BSEthereumConstants_1 = require("../constants/BSEthereumConstants");
14
14
  class BSEthereumHelper {
15
15
  static getNativeAsset(network) {
16
16
  const symbol = this.getNativeSymbol(network);
17
- return Object.assign(Object.assign({}, BSEthereumConstants_1.BSEthereumConstants.NATIVE_ASSET), { symbol, name: symbol });
17
+ return { symbol, name: symbol, decimals: 18, hash: '-' };
18
18
  }
19
19
  static getNativeSymbol(network) {
20
20
  var _a;
@@ -12,12 +12,12 @@ export declare class EthersLedgerSigner extends Signer implements TypedDataSigne
12
12
  signTransaction(transaction: ethers.utils.Deferrable<ethers.providers.TransactionRequest>): Promise<string>;
13
13
  _signTypedData(domain: ethers.TypedDataDomain, types: Record<string, ethers.TypedDataField[]>, value: Record<string, any>): Promise<string>;
14
14
  }
15
- export declare class EthersLedgerServiceEthereum implements LedgerService {
15
+ export declare class EthersLedgerServiceEthereum<BSName extends string = string> implements LedgerService<BSName> {
16
16
  #private;
17
17
  emitter: LedgerServiceEmitter;
18
- getLedgerTransport?: GetLedgerTransport;
19
- constructor(blockchainService: BSEthereum, getLedgerTransport?: GetLedgerTransport);
20
- getAccounts(transport: Transport): Promise<Account[]>;
21
- getAccount(transport: Transport, index: number): Promise<Account>;
18
+ getLedgerTransport?: GetLedgerTransport<BSName>;
19
+ constructor(blockchainService: BSEthereum<BSName>, getLedgerTransport?: GetLedgerTransport<BSName>);
20
+ getAccounts(transport: Transport): Promise<Account<BSName>[]>;
21
+ getAccount(transport: Transport, index: number): Promise<Account<BSName>>;
22
22
  getSigner(transport: Transport, path: string, provider?: ethers.providers.Provider): EthersLedgerSigner;
23
23
  }
@@ -178,7 +178,7 @@ class EthersLedgerServiceEthereum {
178
178
  const accountsByBlockchainService = yield (0, blockchain_service_1.fetchAccountsForBlockchainServices)([__classPrivateFieldGet(this, _EthersLedgerServiceEthereum_blockchainService, "f")], (_service, index) => __awaiter(this, void 0, void 0, function* () {
179
179
  return this.getAccount(transport, index);
180
180
  }));
181
- const accounts = accountsByBlockchainService.get(__classPrivateFieldGet(this, _EthersLedgerServiceEthereum_blockchainService, "f").blockchainName);
181
+ const accounts = accountsByBlockchainService.get(__classPrivateFieldGet(this, _EthersLedgerServiceEthereum_blockchainService, "f").name);
182
182
  return accounts !== null && accounts !== void 0 ? accounts : [];
183
183
  });
184
184
  }
@@ -193,6 +193,7 @@ class EthersLedgerServiceEthereum {
193
193
  key: publicKeyWithPrefix,
194
194
  type: 'publicKey',
195
195
  bip44Path,
196
+ blockchain: __classPrivateFieldGet(this, _EthersLedgerServiceEthereum_blockchainService, "f").name,
196
197
  };
197
198
  });
198
199
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cityofzion/bs-ethereum",
3
- "version": "2.6.2",
3
+ "version": "2.7.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": "https://github.com/CityOfZion/blockchain-services",
@@ -20,7 +20,7 @@
20
20
  "@ledgerhq/hw-app-eth": "~6.35.7",
21
21
  "@ethersproject/abstract-signer": "~5.7.0",
22
22
  "@ethersproject/properties": "~5.7.0",
23
- "@cityofzion/blockchain-service": "1.7.0"
23
+ "@cityofzion/blockchain-service": "1.9.0"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@ledgerhq/hw-transport-node-hid": "~6.28.5",