@cityofzion/bs-ethereum 1.0.4 → 1.2.0

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.
Files changed (40) hide show
  1. package/dist/BSEthereum.d.ts +10 -6
  2. package/dist/BSEthereum.js +60 -23
  3. package/dist/BitqueryBDSEthereum.d.ts +1 -2
  4. package/dist/BitqueryBDSEthereum.js +27 -12
  5. package/dist/BitqueryEDSEthereum.d.ts +1 -2
  6. package/dist/BitqueryEDSEthereum.js +20 -5
  7. package/dist/GhostMarketNDSEthereum.d.ts +1 -1
  8. package/dist/GhostMarketNDSEthereum.js +17 -3
  9. package/dist/LedgerServiceEthereum.d.ts +11 -0
  10. package/dist/LedgerServiceEthereum.js +81 -0
  11. package/dist/RpcBDSEthereum.d.ts +1 -1
  12. package/dist/RpcBDSEthereum.js +21 -7
  13. package/dist/constants.js +1 -1
  14. package/package.json +8 -2
  15. package/.eslintignore +0 -13
  16. package/.eslintrc.cjs +0 -22
  17. package/.rush/temp/operation/build/all.log +0 -1
  18. package/.rush/temp/operation/build/state.json +0 -3
  19. package/.rush/temp/package-deps_build.json +0 -28
  20. package/.rush/temp/shrinkwrap-deps.json +0 -449
  21. package/CHANGELOG.json +0 -104
  22. package/CHANGELOG.md +0 -57
  23. package/bs-ethereum.build.log +0 -1
  24. package/jest.config.ts +0 -13
  25. package/jest.setup.ts +0 -1
  26. package/src/BSEthereum.ts +0 -190
  27. package/src/BitqueryBDSEthereum.ts +0 -231
  28. package/src/BitqueryEDSEthereum.ts +0 -67
  29. package/src/GhostMarketNDSEthereum.ts +0 -125
  30. package/src/RpcBDSEthereum.ts +0 -88
  31. package/src/__tests__/BDSEthereum.spec.ts +0 -126
  32. package/src/__tests__/BSEthereum.spec.ts +0 -131
  33. package/src/__tests__/BitqueryEDSEthereum.spec.ts +0 -55
  34. package/src/__tests__/GhostMarketNDSEthereum.spec.ts +0 -49
  35. package/src/assets/tokens/common.json +0 -8
  36. package/src/constants.ts +0 -36
  37. package/src/graphql.ts +0 -288
  38. package/src/index.ts +0 -6
  39. package/tsconfig.build.json +0 -4
  40. package/tsconfig.json +0 -15
@@ -1,15 +1,18 @@
1
- import { Account, AccountWithDerivationPath, BSCalculableFee, BSWithNameService, BSWithNft, BlockchainDataService, BlockchainService, ExchangeDataService, Network, NftDataService, PartialBy, Token, TransferParam } from '@cityofzion/blockchain-service';
2
- export declare class BSEthereum<BSCustomName extends string = string> implements BlockchainService, BSWithNft, BSWithNameService, BSCalculableFee {
1
+ import { Account, AccountWithDerivationPath, BSCalculableFee, BSWithLedger, BSWithNameService, BSWithNft, BlockchainDataService, BlockchainService, ExchangeDataService, Network, NftDataService, PartialBy, Token, TransferParam } from '@cityofzion/blockchain-service';
2
+ import { LedgerServiceEthereum } from './LedgerServiceEthereum';
3
+ import Transport from '@ledgerhq/hw-transport';
4
+ export declare class BSEthereum<BSCustomName extends string = string> implements BlockchainService, BSWithNft, BSWithNameService, BSCalculableFee, BSWithLedger {
5
+ #private;
3
6
  readonly blockchainName: BSCustomName;
4
7
  readonly feeToken: Token;
5
8
  readonly derivationPath: string;
6
- private readonly bitqueryApiKey;
7
9
  blockchainDataService: BlockchainDataService;
8
10
  exchangeDataService: ExchangeDataService;
11
+ ledgerService: LedgerServiceEthereum;
9
12
  tokens: Token[];
10
13
  nftDataService: NftDataService;
11
14
  network: Network;
12
- constructor(blockchainName: BSCustomName, network: PartialBy<Network, 'url'>, bitqueryApiKey: string);
15
+ constructor(blockchainName: BSCustomName, network: PartialBy<Network, 'url'>, bitqueryApiKey: string, getLedgerTransport?: (account: Account) => Promise<Transport>);
13
16
  setNetwork(param: PartialBy<Network, 'url'>): void;
14
17
  validateAddress(address: string): boolean;
15
18
  validateEncrypted(json: string): boolean;
@@ -17,9 +20,10 @@ export declare class BSEthereum<BSCustomName extends string = string> implements
17
20
  validateNameServiceDomainFormat(domainName: string): boolean;
18
21
  generateAccountFromMnemonic(mnemonic: string[] | string, index: number): AccountWithDerivationPath;
19
22
  generateAccountFromKey(key: string): Account;
23
+ generateAccountFromPublicKey(publicKey: string): Account;
20
24
  decrypt(json: string, password: string): Promise<Account>;
21
25
  encrypt(key: string, password: string): Promise<string>;
22
- transfer({ senderAccount, intent }: TransferParam): Promise<string>;
23
- calculateTransferFee({ senderAccount, intent }: TransferParam): Promise<string>;
26
+ transfer(param: TransferParam): Promise<string>;
27
+ calculateTransferFee({ intent }: TransferParam): Promise<string>;
24
28
  resolveNameServiceDomain(domainName: string): Promise<string>;
25
29
  }
@@ -31,6 +31,18 @@ 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
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
41
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
42
+ 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
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
44
+ };
45
+ var _BSEthereum_bitqueryApiKey;
34
46
  Object.defineProperty(exports, "__esModule", { value: true });
35
47
  exports.BSEthereum = void 0;
36
48
  const ethers_1 = require("ethers");
@@ -42,12 +54,15 @@ const BitqueryEDSEthereum_1 = require("./BitqueryEDSEthereum");
42
54
  const GhostMarketNDSEthereum_1 = require("./GhostMarketNDSEthereum");
43
55
  const RpcBDSEthereum_1 = require("./RpcBDSEthereum");
44
56
  const BitqueryBDSEthereum_1 = require("./BitqueryBDSEthereum");
57
+ const LedgerServiceEthereum_1 = require("./LedgerServiceEthereum");
45
58
  class BSEthereum {
46
- constructor(blockchainName, network, bitqueryApiKey) {
59
+ constructor(blockchainName, network, bitqueryApiKey, getLedgerTransport) {
60
+ _BSEthereum_bitqueryApiKey.set(this, void 0);
47
61
  this.blockchainName = blockchainName;
62
+ this.ledgerService = new LedgerServiceEthereum_1.LedgerServiceEthereum(getLedgerTransport);
48
63
  this.derivationPath = constants_1.DERIVATION_PATH;
49
64
  this.tokens = constants_1.TOKENS[network.type];
50
- this.bitqueryApiKey = bitqueryApiKey;
65
+ __classPrivateFieldSet(this, _BSEthereum_bitqueryApiKey, bitqueryApiKey, "f");
51
66
  this.feeToken = this.tokens.find(token => token.symbol === 'ETH');
52
67
  this.setNetwork(network);
53
68
  }
@@ -58,13 +73,13 @@ class BSEthereum {
58
73
  url: (_a = param.url) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_URL_BY_NETWORK_TYPE[param.type],
59
74
  };
60
75
  this.network = network;
61
- if (network.type === 'custom') {
76
+ if (network.type !== 'mainnet') {
62
77
  this.blockchainDataService = new RpcBDSEthereum_1.RpcBDSEthereum(network);
63
78
  }
64
79
  else {
65
- this.blockchainDataService = new BitqueryBDSEthereum_1.BitqueryBDSEthereum(network, this.bitqueryApiKey);
80
+ this.blockchainDataService = new BitqueryBDSEthereum_1.BitqueryBDSEthereum(network, __classPrivateFieldGet(this, _BSEthereum_bitqueryApiKey, "f"));
66
81
  }
67
- this.exchangeDataService = new BitqueryEDSEthereum_1.BitqueryEDSEthereum(network.type, this.bitqueryApiKey);
82
+ this.exchangeDataService = new BitqueryEDSEthereum_1.BitqueryEDSEthereum(network.type, __classPrivateFieldGet(this, _BSEthereum_bitqueryApiKey, "f"));
68
83
  this.nftDataService = new GhostMarketNDSEthereum_1.GhostMarketNDSEthereum(network.type);
69
84
  }
70
85
  validateAddress(address) {
@@ -109,6 +124,14 @@ class BSEthereum {
109
124
  type: 'privateKey',
110
125
  };
111
126
  }
127
+ generateAccountFromPublicKey(publicKey) {
128
+ const address = ethers_1.ethers.utils.computeAddress(publicKey);
129
+ return {
130
+ address,
131
+ key: publicKey,
132
+ type: 'publicKey',
133
+ };
134
+ }
112
135
  decrypt(json, password) {
113
136
  return __awaiter(this, void 0, void 0, function* () {
114
137
  const wallet = yield ethers_1.ethers.Wallet.fromEncryptedJson(json, password);
@@ -125,44 +148,57 @@ class BSEthereum {
125
148
  return wallet.encrypt(password);
126
149
  });
127
150
  }
128
- transfer({ senderAccount, intent }) {
151
+ transfer(param) {
129
152
  var _a;
130
153
  return __awaiter(this, void 0, void 0, function* () {
131
154
  const provider = new ethers_1.ethers.providers.JsonRpcProvider(this.network.url);
132
- const wallet = new ethers_1.ethers.Wallet(senderAccount.key, provider);
133
- let transaction;
134
- const decimals = (_a = intent.tokenDecimals) !== null && _a !== void 0 ? _a : 18;
135
- const amount = ethersBigNumber.parseFixed(intent.amount, decimals);
136
- const isNative = constants_1.NATIVE_ASSETS.some(asset => asset.hash === intent.tokenHash);
137
- if (!isNative) {
138
- const contract = new ethers_1.ethers.Contract(intent.tokenHash, ['function transfer(address to, uint amount) returns (bool)'], wallet);
139
- transaction = yield contract.transfer(intent.receiverAddress, amount);
155
+ let ledgerTransport;
156
+ if (param.isLedger) {
157
+ if (!this.ledgerService.getLedgerTransport)
158
+ throw new Error('You must provide getLedgerTransport function to use Ledger');
159
+ ledgerTransport = yield this.ledgerService.getLedgerTransport(param.senderAccount);
140
160
  }
141
- else {
142
- transaction = yield wallet.sendTransaction({
143
- to: intent.receiverAddress,
161
+ const signTransactionFunction = ledgerTransport
162
+ ? yield this.ledgerService.getSignTransactionFunction(ledgerTransport)
163
+ : new ethers_1.ethers.Wallet(param.senderAccount.key, provider).signTransaction;
164
+ const decimals = (_a = param.intent.tokenDecimals) !== null && _a !== void 0 ? _a : 18;
165
+ const amount = ethersBigNumber.parseFixed(param.intent.amount, decimals);
166
+ let transactionParams;
167
+ const isNative = constants_1.NATIVE_ASSETS.some(asset => asset.hash === param.intent.tokenHash);
168
+ if (isNative) {
169
+ transactionParams = {
170
+ to: param.intent.receiverAddress,
144
171
  value: amount,
145
- });
172
+ };
173
+ }
174
+ else {
175
+ const contract = new ethers_1.ethers.Contract(param.intent.tokenHash, [
176
+ 'function transfer(address to, uint amount) returns (bool)',
177
+ ]);
178
+ transactionParams = yield contract.populateTransaction.transfer(param.intent.receiverAddress, amount);
146
179
  }
147
- return transaction.hash;
180
+ const voidSigner = new ethers_1.ethers.VoidSigner(param.senderAccount.address, provider);
181
+ const transaction = yield voidSigner.populateTransaction(transactionParams);
182
+ const signedTransaction = yield signTransactionFunction(transaction);
183
+ const transactionResponse = yield provider.sendTransaction(signedTransaction);
184
+ return transactionResponse.hash;
148
185
  });
149
186
  }
150
- calculateTransferFee({ senderAccount, intent }) {
187
+ calculateTransferFee({ intent }) {
151
188
  var _a;
152
189
  return __awaiter(this, void 0, void 0, function* () {
153
190
  const provider = new ethers_1.ethers.providers.JsonRpcProvider(this.network.url);
154
- const wallet = new ethers_1.ethers.Wallet(senderAccount.key, provider);
155
191
  const gasPrice = yield provider.getGasPrice();
156
192
  let estimated;
157
193
  const isNative = constants_1.NATIVE_ASSETS.some(asset => asset.hash === intent.tokenHash);
158
194
  const decimals = (_a = intent.tokenDecimals) !== null && _a !== void 0 ? _a : 18;
159
195
  const amount = ethersBigNumber.parseFixed(intent.amount, decimals);
160
196
  if (!isNative) {
161
- const contract = new ethers_1.ethers.Contract(intent.tokenHash, ['function transfer(address to, uint amount) returns (bool)'], wallet);
197
+ const contract = new ethers_1.ethers.Contract(intent.tokenHash, ['function transfer(address to, uint amount) returns (bool)'], provider);
162
198
  estimated = yield contract.estimateGas.transfer(intent.receiverAddress, amount);
163
199
  }
164
200
  else {
165
- estimated = yield wallet.estimateGas({
201
+ estimated = yield provider.estimateGas({
166
202
  to: intent.receiverAddress,
167
203
  value: amount,
168
204
  });
@@ -181,3 +217,4 @@ class BSEthereum {
181
217
  }
182
218
  }
183
219
  exports.BSEthereum = BSEthereum;
220
+ _BSEthereum_bitqueryApiKey = new WeakMap();
@@ -1,8 +1,7 @@
1
1
  import { BalanceResponse, ContractResponse, Token, TransactionsByAddressParams, TransactionsByAddressResponse, TransactionResponse, Network } from '@cityofzion/blockchain-service';
2
2
  import { RpcBDSEthereum } from './RpcBDSEthereum';
3
3
  export declare class BitqueryBDSEthereum extends RpcBDSEthereum {
4
- private readonly client;
5
- private readonly networkType;
4
+ #private;
6
5
  maxTimeToConfirmTransactionInMs: number;
7
6
  constructor(network: Network, apiKey: string);
8
7
  getTransaction(hash: string): Promise<TransactionResponse>;
@@ -8,9 +8,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
12
+ if (kind === "m") throw new TypeError("Private method is not writable");
13
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
14
+ 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");
15
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
16
+ };
17
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
18
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
19
+ 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");
20
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
21
+ };
11
22
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
23
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
24
  };
25
+ var _BitqueryBDSEthereum_client, _BitqueryBDSEthereum_networkType;
14
26
  Object.defineProperty(exports, "__esModule", { value: true });
15
27
  exports.BitqueryBDSEthereum = void 0;
16
28
  const core_1 = require("@urql/core");
@@ -21,11 +33,13 @@ const RpcBDSEthereum_1 = require("./RpcBDSEthereum");
21
33
  class BitqueryBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
22
34
  constructor(network, apiKey) {
23
35
  super(network);
36
+ _BitqueryBDSEthereum_client.set(this, void 0);
37
+ _BitqueryBDSEthereum_networkType.set(this, void 0);
24
38
  this.maxTimeToConfirmTransactionInMs = 1000 * 60 * 8;
25
39
  if (network.type === 'custom')
26
40
  throw new Error('Custom network not supported');
27
- this.networkType = network.type;
28
- this.client = new core_1.Client({
41
+ __classPrivateFieldSet(this, _BitqueryBDSEthereum_networkType, network.type, "f");
42
+ __classPrivateFieldSet(this, _BitqueryBDSEthereum_client, new core_1.Client({
29
43
  url: constants_1.BITQUERY_URL,
30
44
  exchanges: [core_1.fetchExchange],
31
45
  fetch: node_fetch_1.default,
@@ -34,14 +48,14 @@ class BitqueryBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
34
48
  'X-API-KEY': apiKey,
35
49
  },
36
50
  },
37
- });
51
+ }), "f");
38
52
  }
39
53
  getTransaction(hash) {
40
54
  return __awaiter(this, void 0, void 0, function* () {
41
- const result = yield this.client
55
+ const result = yield __classPrivateFieldGet(this, _BitqueryBDSEthereum_client, "f")
42
56
  .query(graphql_1.bitqueryGetTransactionQuery, {
43
57
  hash,
44
- network: constants_1.BITQUERY_NETWORK_BY_NETWORK_TYPE[this.networkType],
58
+ network: constants_1.BITQUERY_NETWORK_BY_NETWORK_TYPE[__classPrivateFieldGet(this, _BitqueryBDSEthereum_networkType, "f")],
45
59
  })
46
60
  .toPromise();
47
61
  if (result.error)
@@ -65,12 +79,12 @@ class BitqueryBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
65
79
  return __awaiter(this, void 0, void 0, function* () {
66
80
  const limit = 10;
67
81
  const offset = limit * (page - 1);
68
- const result = yield this.client
82
+ const result = yield __classPrivateFieldGet(this, _BitqueryBDSEthereum_client, "f")
69
83
  .query(graphql_1.bitqueryGetTransactionsByAddressQuery, {
70
84
  address,
71
85
  limit,
72
86
  offset,
73
- network: constants_1.BITQUERY_NETWORK_BY_NETWORK_TYPE[this.networkType],
87
+ network: constants_1.BITQUERY_NETWORK_BY_NETWORK_TYPE[__classPrivateFieldGet(this, _BitqueryBDSEthereum_networkType, "f")],
74
88
  })
75
89
  .toPromise();
76
90
  if (result.error)
@@ -110,13 +124,13 @@ class BitqueryBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
110
124
  }
111
125
  getTokenInfo(hash) {
112
126
  return __awaiter(this, void 0, void 0, function* () {
113
- const localToken = constants_1.TOKENS[this.networkType].find(token => token.hash === hash);
127
+ const localToken = constants_1.TOKENS[__classPrivateFieldGet(this, _BitqueryBDSEthereum_networkType, "f")].find(token => token.hash === hash);
114
128
  if (localToken)
115
129
  return localToken;
116
- const result = yield this.client
130
+ const result = yield __classPrivateFieldGet(this, _BitqueryBDSEthereum_client, "f")
117
131
  .query(graphql_1.bitqueryGetTokenInfoQuery, {
118
132
  hash,
119
- network: constants_1.BITQUERY_NETWORK_BY_NETWORK_TYPE[this.networkType],
133
+ network: constants_1.BITQUERY_NETWORK_BY_NETWORK_TYPE[__classPrivateFieldGet(this, _BitqueryBDSEthereum_networkType, "f")],
120
134
  })
121
135
  .toPromise();
122
136
  if (result.error)
@@ -137,10 +151,10 @@ class BitqueryBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
137
151
  getBalance(address) {
138
152
  var _a, _b, _c, _d;
139
153
  return __awaiter(this, void 0, void 0, function* () {
140
- const result = yield this.client
154
+ const result = yield __classPrivateFieldGet(this, _BitqueryBDSEthereum_client, "f")
141
155
  .query(graphql_1.bitqueryGetBalanceQuery, {
142
156
  address,
143
- network: constants_1.BITQUERY_NETWORK_BY_NETWORK_TYPE[this.networkType],
157
+ network: constants_1.BITQUERY_NETWORK_BY_NETWORK_TYPE[__classPrivateFieldGet(this, _BitqueryBDSEthereum_networkType, "f")],
144
158
  })
145
159
  .toPromise();
146
160
  if (result.error)
@@ -196,3 +210,4 @@ class BitqueryBDSEthereum extends RpcBDSEthereum_1.RpcBDSEthereum {
196
210
  }
197
211
  }
198
212
  exports.BitqueryBDSEthereum = BitqueryBDSEthereum;
213
+ _BitqueryBDSEthereum_client = new WeakMap(), _BitqueryBDSEthereum_networkType = new WeakMap();
@@ -1,7 +1,6 @@
1
1
  import { Currency, ExchangeDataService, NetworkType, TokenPricesResponse } from '@cityofzion/blockchain-service';
2
2
  export declare class BitqueryEDSEthereum implements ExchangeDataService {
3
- private readonly client;
4
- private readonly networkType;
3
+ #private;
5
4
  constructor(networkType: NetworkType, apiKey: string);
6
5
  getTokenPrices(currency: Currency): Promise<TokenPricesResponse[]>;
7
6
  private getCurrencyRatio;
@@ -8,9 +8,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
12
+ if (kind === "m") throw new TypeError("Private method is not writable");
13
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
14
+ 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");
15
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
16
+ };
17
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
18
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
19
+ 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");
20
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
21
+ };
11
22
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
23
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
24
  };
25
+ var _BitqueryEDSEthereum_client, _BitqueryEDSEthereum_networkType;
14
26
  Object.defineProperty(exports, "__esModule", { value: true });
15
27
  exports.BitqueryEDSEthereum = void 0;
16
28
  const core_1 = require("@urql/core");
@@ -22,8 +34,10 @@ const graphql_1 = require("./graphql");
22
34
  dayjs_1.default.extend(utc_1.default);
23
35
  class BitqueryEDSEthereum {
24
36
  constructor(networkType, apiKey) {
25
- this.networkType = networkType;
26
- this.client = new core_1.Client({
37
+ _BitqueryEDSEthereum_client.set(this, void 0);
38
+ _BitqueryEDSEthereum_networkType.set(this, void 0);
39
+ __classPrivateFieldSet(this, _BitqueryEDSEthereum_networkType, networkType, "f");
40
+ __classPrivateFieldSet(this, _BitqueryEDSEthereum_client, new core_1.Client({
27
41
  url: constants_1.BITQUERY_URL,
28
42
  exchanges: [core_1.fetchExchange],
29
43
  fetch: node_fetch_1.default,
@@ -32,14 +46,14 @@ class BitqueryEDSEthereum {
32
46
  'X-API-KEY': apiKey,
33
47
  },
34
48
  },
35
- });
49
+ }), "f");
36
50
  }
37
51
  getTokenPrices(currency) {
38
52
  return __awaiter(this, void 0, void 0, function* () {
39
- if (this.networkType !== 'mainnet')
53
+ if (__classPrivateFieldGet(this, _BitqueryEDSEthereum_networkType, "f") !== 'mainnet')
40
54
  throw new Error('Exchange is only available on mainnet');
41
55
  const twoDaysAgo = dayjs_1.default.utc().subtract(2, 'day').startOf('date').toISOString();
42
- const result = yield this.client
56
+ const result = yield __classPrivateFieldGet(this, _BitqueryEDSEthereum_client, "f")
43
57
  .query(graphql_1.bitqueryGetPricesQuery, { after: twoDaysAgo, network: 'ethereum' })
44
58
  .toPromise();
45
59
  if (result.error) {
@@ -71,3 +85,4 @@ class BitqueryEDSEthereum {
71
85
  }
72
86
  }
73
87
  exports.BitqueryEDSEthereum = BitqueryEDSEthereum;
88
+ _BitqueryEDSEthereum_client = new WeakMap(), _BitqueryEDSEthereum_networkType = new WeakMap();
@@ -1,6 +1,6 @@
1
1
  import { NftResponse, NftsResponse, NetworkType, NftDataService, GetNftParam, GetNftsByAddressParams } from '@cityofzion/blockchain-service';
2
2
  export declare class GhostMarketNDSEthereum implements NftDataService {
3
- private networkType;
3
+ #private;
4
4
  constructor(networkType: NetworkType);
5
5
  getNftsByAddress({ address, size, cursor }: GetNftsByAddressParams): Promise<NftsResponse>;
6
6
  getNft({ contractHash, tokenId }: GetNftParam): Promise<NftResponse>;
@@ -8,9 +8,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
12
+ if (kind === "m") throw new TypeError("Private method is not writable");
13
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
14
+ 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");
15
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
16
+ };
17
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
18
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
19
+ 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");
20
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
21
+ };
11
22
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
23
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
24
  };
25
+ var _GhostMarketNDSEthereum_networkType;
14
26
  Object.defineProperty(exports, "__esModule", { value: true });
15
27
  exports.GhostMarketNDSEthereum = void 0;
16
28
  const query_string_1 = __importDefault(require("query-string"));
@@ -18,7 +30,8 @@ const constants_1 = require("./constants");
18
30
  const node_fetch_1 = __importDefault(require("node-fetch"));
19
31
  class GhostMarketNDSEthereum {
20
32
  constructor(networkType) {
21
- this.networkType = networkType;
33
+ _GhostMarketNDSEthereum_networkType.set(this, void 0);
34
+ __classPrivateFieldSet(this, _GhostMarketNDSEthereum_networkType, networkType, "f");
22
35
  }
23
36
  getNftsByAddress({ address, size = 18, cursor }) {
24
37
  var _a;
@@ -56,8 +69,8 @@ class GhostMarketNDSEthereum {
56
69
  return srcImage;
57
70
  }
58
71
  getUrlWithParams(params) {
59
- const parameters = query_string_1.default.stringify(Object.assign({ chain: constants_1.GHOSTMARKET_CHAIN_BY_NETWORK_TYPE[this.networkType] }, params), { arrayFormat: 'bracket' });
60
- return `${constants_1.GHOSTMARKET_URL_BY_NETWORK_TYPE[this.networkType]}/assets?${parameters}`;
72
+ const parameters = query_string_1.default.stringify(Object.assign({ chain: constants_1.GHOSTMARKET_CHAIN_BY_NETWORK_TYPE[__classPrivateFieldGet(this, _GhostMarketNDSEthereum_networkType, "f")] }, params), { arrayFormat: 'bracket' });
73
+ return `${constants_1.GHOSTMARKET_URL_BY_NETWORK_TYPE[__classPrivateFieldGet(this, _GhostMarketNDSEthereum_networkType, "f")]}/assets?${parameters}`;
61
74
  }
62
75
  parse(data) {
63
76
  var _a, _b;
@@ -79,3 +92,4 @@ class GhostMarketNDSEthereum {
79
92
  }
80
93
  }
81
94
  exports.GhostMarketNDSEthereum = GhostMarketNDSEthereum;
95
+ _GhostMarketNDSEthereum_networkType = new WeakMap();
@@ -0,0 +1,11 @@
1
+ import { Account, LedgerService } from '@cityofzion/blockchain-service';
2
+ import Transport from '@ledgerhq/hw-transport';
3
+ import { ethers } from 'ethers';
4
+ export declare class LedgerServiceEthereum implements LedgerService {
5
+ #private;
6
+ getLedgerTransport?: ((account: Account) => Promise<Transport>) | undefined;
7
+ constructor(getLedgerTransport?: ((account: Account) => Promise<Transport>) | undefined);
8
+ getAddress(transport: Transport): Promise<string>;
9
+ getPublicKey(transport: Transport): Promise<string>;
10
+ getSignTransactionFunction(transport: Transport): Promise<(transaction: ethers.providers.TransactionRequest) => Promise<string>>;
11
+ }
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
35
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
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");
37
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
38
+ };
39
+ var _LedgerServiceEthereum_defaultPath;
40
+ Object.defineProperty(exports, "__esModule", { value: true });
41
+ exports.LedgerServiceEthereum = void 0;
42
+ const hw_app_eth_1 = __importStar(require("@ledgerhq/hw-app-eth"));
43
+ const ethers_1 = require("ethers");
44
+ class LedgerServiceEthereum {
45
+ constructor(getLedgerTransport) {
46
+ this.getLedgerTransport = getLedgerTransport;
47
+ _LedgerServiceEthereum_defaultPath.set(this, "44'/60'/0'/0/0");
48
+ }
49
+ getAddress(transport) {
50
+ return __awaiter(this, void 0, void 0, function* () {
51
+ const ledgerApp = new hw_app_eth_1.default(transport);
52
+ const { address } = yield ledgerApp.getAddress(__classPrivateFieldGet(this, _LedgerServiceEthereum_defaultPath, "f"));
53
+ return address;
54
+ });
55
+ }
56
+ getPublicKey(transport) {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ const ledgerApp = new hw_app_eth_1.default(transport);
59
+ const { publicKey } = yield ledgerApp.getAddress(__classPrivateFieldGet(this, _LedgerServiceEthereum_defaultPath, "f"));
60
+ return '0x' + publicKey;
61
+ });
62
+ }
63
+ getSignTransactionFunction(transport) {
64
+ return __awaiter(this, void 0, void 0, function* () {
65
+ return (transaction) => __awaiter(this, void 0, void 0, function* () {
66
+ const ledgerApp = new hw_app_eth_1.default(transport);
67
+ const unsignedTransaction = Object.assign(Object.assign({}, transaction), { nonce: transaction.nonce ? ethers_1.ethers.BigNumber.from(transaction.nonce).toNumber() : undefined });
68
+ const serializedUnsignedTransaction = ethers_1.ethers.utils.serializeTransaction(unsignedTransaction).substring(2);
69
+ const resolution = yield hw_app_eth_1.ledgerService.resolveTransaction(serializedUnsignedTransaction, {}, {});
70
+ const signature = yield ledgerApp.signTransaction(__classPrivateFieldGet(this, _LedgerServiceEthereum_defaultPath, "f"), serializedUnsignedTransaction, resolution);
71
+ return ethers_1.ethers.utils.serializeTransaction(unsignedTransaction, {
72
+ v: ethers_1.ethers.BigNumber.from('0x' + signature.v).toNumber(),
73
+ r: '0x' + signature.r,
74
+ s: '0x' + signature.s,
75
+ });
76
+ });
77
+ });
78
+ }
79
+ }
80
+ exports.LedgerServiceEthereum = LedgerServiceEthereum;
81
+ _LedgerServiceEthereum_defaultPath = new WeakMap();
@@ -1,6 +1,6 @@
1
1
  import { BalanceResponse, BlockchainDataService, ContractResponse, Network, Token, TransactionResponse, TransactionsByAddressParams, TransactionsByAddressResponse } from '@cityofzion/blockchain-service';
2
2
  export declare class RpcBDSEthereum implements BlockchainDataService {
3
- private readonly network;
3
+ #private;
4
4
  maxTimeToConfirmTransactionInMs: number;
5
5
  constructor(network: Network);
6
6
  getTransaction(hash: string): Promise<TransactionResponse>;
@@ -8,25 +8,38 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
12
+ if (kind === "m") throw new TypeError("Private method is not writable");
13
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
14
+ 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");
15
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
16
+ };
17
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
18
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
19
+ 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");
20
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
21
+ };
22
+ var _RpcBDSEthereum_network;
11
23
  Object.defineProperty(exports, "__esModule", { value: true });
12
24
  exports.RpcBDSEthereum = void 0;
13
25
  const ethers_1 = require("ethers");
14
26
  const constants_1 = require("./constants");
15
27
  class RpcBDSEthereum {
16
28
  constructor(network) {
29
+ _RpcBDSEthereum_network.set(this, void 0);
17
30
  this.maxTimeToConfirmTransactionInMs = 1000 * 60 * 5;
18
- this.network = network;
31
+ __classPrivateFieldSet(this, _RpcBDSEthereum_network, network, "f");
19
32
  }
20
33
  getTransaction(hash) {
21
34
  return __awaiter(this, void 0, void 0, function* () {
22
- const provider = new ethers_1.ethers.providers.JsonRpcProvider(this.network.url);
35
+ const provider = new ethers_1.ethers.providers.JsonRpcProvider(__classPrivateFieldGet(this, _RpcBDSEthereum_network, "f").url);
23
36
  const transaction = yield provider.getTransaction(hash);
24
37
  if (!transaction || !transaction.blockHash || !transaction.to)
25
38
  throw new Error('Transaction not found');
26
39
  const block = yield provider.getBlock(transaction.blockHash);
27
40
  if (!block)
28
41
  throw new Error('Block not found');
29
- const tokens = constants_1.TOKENS[this.network.type];
42
+ const tokens = constants_1.TOKENS[__classPrivateFieldGet(this, _RpcBDSEthereum_network, "f").type];
30
43
  const token = tokens.find(token => token.symbol === 'ETH');
31
44
  return {
32
45
  block: block.number,
@@ -58,7 +71,7 @@ class RpcBDSEthereum {
58
71
  }
59
72
  getTokenInfo(hash) {
60
73
  return __awaiter(this, void 0, void 0, function* () {
61
- const tokens = constants_1.TOKENS[this.network.type];
74
+ const tokens = constants_1.TOKENS[__classPrivateFieldGet(this, _RpcBDSEthereum_network, "f").type];
62
75
  const token = tokens.find(token => token.hash === hash);
63
76
  if (!token)
64
77
  throw new Error('Token not found');
@@ -67,9 +80,9 @@ class RpcBDSEthereum {
67
80
  }
68
81
  getBalance(address) {
69
82
  return __awaiter(this, void 0, void 0, function* () {
70
- const provider = new ethers_1.ethers.providers.JsonRpcProvider(this.network.url);
83
+ const provider = new ethers_1.ethers.providers.JsonRpcProvider(__classPrivateFieldGet(this, _RpcBDSEthereum_network, "f").url);
71
84
  const balance = yield provider.getBalance(address);
72
- const tokens = constants_1.TOKENS[this.network.type];
85
+ const tokens = constants_1.TOKENS[__classPrivateFieldGet(this, _RpcBDSEthereum_network, "f").type];
73
86
  const token = tokens.find(token => token.symbol === 'ETH');
74
87
  return [
75
88
  {
@@ -81,9 +94,10 @@ class RpcBDSEthereum {
81
94
  }
82
95
  getBlockHeight() {
83
96
  return __awaiter(this, void 0, void 0, function* () {
84
- const provider = new ethers_1.ethers.providers.JsonRpcProvider(this.network.url);
97
+ const provider = new ethers_1.ethers.providers.JsonRpcProvider(__classPrivateFieldGet(this, _RpcBDSEthereum_network, "f").url);
85
98
  return yield provider.getBlockNumber();
86
99
  });
87
100
  }
88
101
  }
89
102
  exports.RpcBDSEthereum = RpcBDSEthereum;
103
+ _RpcBDSEthereum_network = new WeakMap();
package/dist/constants.js CHANGED
@@ -13,7 +13,7 @@ exports.TOKENS = {
13
13
  exports.NATIVE_ASSETS = common_json_1.default;
14
14
  exports.DEFAULT_URL_BY_NETWORK_TYPE = {
15
15
  mainnet: 'https://ethereum-mainnet-rpc.allthatnode.com',
16
- testnet: 'https://ethereum-goerli.publicnode.com',
16
+ testnet: 'https://ethereum-sepolia-rpc.publicnode.com',
17
17
  custom: 'http://127.0.0.1:8545',
18
18
  };
19
19
  exports.BITQUERY_URL = 'https://graphql.bitquery.io';