@cityofzion/bs-neo-legacy 0.10.5 → 1.0.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.
@@ -1,5 +1,6 @@
1
- import { Account, BDSClaimable, BlockchainDataService, BlockchainService, BSClaimable, ExchangeDataService, Token, Network, PartialBy, TransferParam, AccountWithDerivationPath, BSWithExplorerService, ExplorerService } from '@cityofzion/blockchain-service';
2
- export declare class BSNeoLegacy<BSCustomName extends string = string> implements BlockchainService, BSClaimable, BSWithExplorerService {
1
+ import { Account, BDSClaimable, BlockchainDataService, BlockchainService, BSClaimable, ExchangeDataService, Token, Network, TransferParam, AccountWithDerivationPath, BSWithExplorerService, ExplorerService, PartialNetwork } from '@cityofzion/blockchain-service';
2
+ import { AvailableNetworkIds } from './constants';
3
+ export declare class BSNeoLegacy<BSCustomName extends string = string> implements BlockchainService<BSCustomName, AvailableNetworkIds>, BSClaimable, BSWithExplorerService {
3
4
  readonly blockchainName: BSCustomName;
4
5
  readonly feeToken: Token;
5
6
  readonly claimToken: Token;
@@ -9,10 +10,10 @@ export declare class BSNeoLegacy<BSCustomName extends string = string> implement
9
10
  exchangeDataService: ExchangeDataService;
10
11
  explorerService: ExplorerService;
11
12
  tokens: Token[];
12
- network: Network;
13
+ network: Network<AvailableNetworkIds>;
13
14
  legacyNetwork: string;
14
- constructor(blockchainName: BSCustomName, network: PartialBy<Network, 'url'>);
15
- setNetwork(param: PartialBy<Network, 'url'>): void;
15
+ constructor(blockchainName: BSCustomName, network: PartialNetwork<AvailableNetworkIds>);
16
+ setNetwork(param: PartialNetwork<AvailableNetworkIds>): void;
16
17
  validateAddress(address: string): boolean;
17
18
  validateEncrypted(key: string): boolean;
18
19
  validateKey(key: string): boolean;
@@ -29,29 +29,26 @@ const bs_asteroid_sdk_1 = require("@cityofzion/bs-asteroid-sdk");
29
29
  const DoraESNeoLegacy_1 = require("./DoraESNeoLegacy");
30
30
  class BSNeoLegacy {
31
31
  constructor(blockchainName, network) {
32
- if (network.type === 'custom')
33
- throw new Error('Custom network is not supported for NEO Legacy');
34
32
  this.blockchainName = blockchainName;
35
- this.legacyNetwork = constants_1.LEGACY_NETWORK_BY_NETWORK_TYPE[network.type];
33
+ this.legacyNetwork = constants_1.LEGACY_NETWORK_BY_NETWORK_TYPE[network.id];
36
34
  this.derivationPath = constants_1.DERIVATION_PATH;
37
- this.tokens = constants_1.TOKENS[network.type];
35
+ this.tokens = constants_1.TOKENS[network.id];
38
36
  this.claimToken = this.tokens.find(token => token.symbol === 'GAS');
39
37
  this.burnToken = this.tokens.find(token => token.symbol === 'NEO');
40
38
  this.feeToken = this.tokens.find(token => token.symbol === 'GAS');
41
39
  this.setNetwork(network);
42
40
  }
43
41
  setNetwork(param) {
44
- var _a;
45
- if (param.type === 'custom')
46
- throw new Error('Custom network is not supported for NEO Legacy');
42
+ var _a, _b;
47
43
  const network = {
48
- type: param.type,
49
- url: (_a = param.url) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_URL_BY_NETWORK_TYPE[param.type],
44
+ id: param.id,
45
+ name: (_a = param.name) !== null && _a !== void 0 ? _a : param.id,
46
+ url: (_b = param.url) !== null && _b !== void 0 ? _b : constants_1.DEFAULT_URL_BY_NETWORK_TYPE[param.id],
50
47
  };
51
48
  this.network = network;
52
49
  this.blockchainDataService = new DoraBDSNeoLegacy_1.DoraBDSNeoLegacy(network, this.feeToken, this.claimToken);
53
- this.exchangeDataService = new CryptoCompareEDSNeoLegacy_1.CryptoCompareEDSNeoLegacy(network.type);
54
- this.explorerService = new DoraESNeoLegacy_1.DoraESNeoLegacy(network.type);
50
+ this.exchangeDataService = new CryptoCompareEDSNeoLegacy_1.CryptoCompareEDSNeoLegacy(network.id);
51
+ this.explorerService = new DoraESNeoLegacy_1.DoraESNeoLegacy(network.id);
55
52
  }
56
53
  validateAddress(address) {
57
54
  return neon_js_1.wallet.isAddress(address);
@@ -79,20 +76,8 @@ class BSNeoLegacy {
79
76
  }
80
77
  decrypt(encryptedKey, password) {
81
78
  return __awaiter(this, void 0, void 0, function* () {
82
- let BsReactNativeDecrypt;
83
- try {
84
- const { NativeModules } = require('react-native');
85
- BsReactNativeDecrypt = NativeModules.BsReactNativeDecrypt;
86
- if (!BsReactNativeDecrypt) {
87
- throw new Error('@CityOfZion/bs-react-native-decrypt is not installed');
88
- }
89
- }
90
- catch (_a) {
91
- const key = yield neon_js_1.wallet.decrypt(encryptedKey, password);
92
- return this.generateAccountFromKey(key);
93
- }
94
- const privateKey = yield BsReactNativeDecrypt.decryptNeoLegacy(encryptedKey, password);
95
- return this.generateAccountFromKey(privateKey);
79
+ const key = yield neon_js_1.wallet.decrypt(encryptedKey, password);
80
+ return this.generateAccountFromKey(key);
96
81
  });
97
82
  }
98
83
  encrypt(key, password) {
@@ -1,4 +1,8 @@
1
- import { CryptoCompareEDS, ExchangeDataService, NetworkType } from '@cityofzion/blockchain-service';
1
+ import { CryptoCompareEDS, Currency, ExchangeDataService, GetTokenPriceHistory, TokenPricesHistoryResponse, TokenPricesResponse } from '@cityofzion/blockchain-service';
2
+ import { AvailableNetworkIds } from './constants';
2
3
  export declare class CryptoCompareEDSNeoLegacy extends CryptoCompareEDS implements ExchangeDataService {
3
- constructor(networkType: NetworkType);
4
+ #private;
5
+ constructor(networkId: AvailableNetworkIds);
6
+ getTokenPriceHistory(params: GetTokenPriceHistory): Promise<TokenPricesHistoryResponse[]>;
7
+ getTokenPrices(currency: Currency): Promise<TokenPricesResponse[]>;
4
8
  }
@@ -1,11 +1,36 @@
1
1
  "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ 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");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ 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");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _CryptoCompareEDSNeoLegacy_networkId;
2
14
  Object.defineProperty(exports, "__esModule", { value: true });
3
15
  exports.CryptoCompareEDSNeoLegacy = void 0;
4
16
  const blockchain_service_1 = require("@cityofzion/blockchain-service");
5
17
  const constants_1 = require("./constants");
6
18
  class CryptoCompareEDSNeoLegacy extends blockchain_service_1.CryptoCompareEDS {
7
- constructor(networkType) {
8
- super(networkType, constants_1.TOKENS[networkType]);
19
+ constructor(networkId) {
20
+ super(constants_1.TOKENS[networkId]);
21
+ _CryptoCompareEDSNeoLegacy_networkId.set(this, void 0);
22
+ __classPrivateFieldSet(this, _CryptoCompareEDSNeoLegacy_networkId, networkId, "f");
23
+ }
24
+ getTokenPriceHistory(params) {
25
+ if (__classPrivateFieldGet(this, _CryptoCompareEDSNeoLegacy_networkId, "f") !== 'mainnet')
26
+ throw new Error('Exchange is only available on mainnet');
27
+ return super.getTokenPriceHistory(params);
28
+ }
29
+ getTokenPrices(currency) {
30
+ if (__classPrivateFieldGet(this, _CryptoCompareEDSNeoLegacy_networkId, "f") !== 'mainnet')
31
+ throw new Error('Exchange is only available on mainnet');
32
+ return super.getTokenPrices(currency);
9
33
  }
10
34
  }
11
35
  exports.CryptoCompareEDSNeoLegacy = CryptoCompareEDSNeoLegacy;
36
+ _CryptoCompareEDSNeoLegacy_networkId = new WeakMap();
@@ -1,8 +1,9 @@
1
1
  import { BalanceResponse, BlockchainDataService, ContractResponse, TransactionsByAddressParams, TransactionsByAddressResponse, TransactionResponse, BDSClaimable, Token, Network, RpcResponse } from '@cityofzion/blockchain-service';
2
+ import { AvailableNetworkIds } from './constants';
2
3
  export declare class DoraBDSNeoLegacy implements BlockchainDataService, BDSClaimable {
3
4
  #private;
4
5
  maxTimeToConfirmTransactionInMs: number;
5
- constructor(network: Network, feeToken: Token, claimToken: Token);
6
+ constructor(network: Network<AvailableNetworkIds>, feeToken: Token, claimToken: Token);
6
7
  getTransaction(hash: string): Promise<TransactionResponse>;
7
8
  getTransactionsByAddress({ address, page, }: TransactionsByAddressParams): Promise<TransactionsByAddressResponse>;
8
9
  getContract(contractHash: string): Promise<ContractResponse>;
@@ -32,8 +32,6 @@ class DoraBDSNeoLegacy {
32
32
  _DoraBDSNeoLegacy_feeToken.set(this, void 0);
33
33
  _DoraBDSNeoLegacy_tokenCache.set(this, new Map());
34
34
  this.maxTimeToConfirmTransactionInMs = 1000 * 60 * 2;
35
- if (network.type === 'custom')
36
- throw new Error('Custom network is not supported for NEO Legacy');
37
35
  __classPrivateFieldSet(this, _DoraBDSNeoLegacy_network, network, "f");
38
36
  __classPrivateFieldSet(this, _DoraBDSNeoLegacy_claimToken, claimToken, "f");
39
37
  __classPrivateFieldSet(this, _DoraBDSNeoLegacy_feeToken, feeToken, "f");
@@ -41,7 +39,7 @@ class DoraBDSNeoLegacy {
41
39
  getTransaction(hash) {
42
40
  var _a, _b, _c;
43
41
  return __awaiter(this, void 0, void 0, function* () {
44
- const data = yield dora_ts_1.api.NeoLegacyREST.transaction(hash, __classPrivateFieldGet(this, _DoraBDSNeoLegacy_network, "f").type);
42
+ const data = yield dora_ts_1.api.NeoLegacyREST.transaction(hash, __classPrivateFieldGet(this, _DoraBDSNeoLegacy_network, "f").id);
45
43
  if (!data || 'error' in data)
46
44
  throw new Error(`Transaction ${hash} not found`);
47
45
  const vout = (_a = data.vout) !== null && _a !== void 0 ? _a : [];
@@ -70,7 +68,7 @@ class DoraBDSNeoLegacy {
70
68
  }
71
69
  getTransactionsByAddress({ address, page = 1, }) {
72
70
  return __awaiter(this, void 0, void 0, function* () {
73
- const data = yield dora_ts_1.api.NeoLegacyREST.getAddressAbstracts(address, page, __classPrivateFieldGet(this, _DoraBDSNeoLegacy_network, "f").type);
71
+ const data = yield dora_ts_1.api.NeoLegacyREST.getAddressAbstracts(address, page, __classPrivateFieldGet(this, _DoraBDSNeoLegacy_network, "f").id);
74
72
  const transactions = new Map();
75
73
  const promises = data.entries.map((entry) => __awaiter(this, void 0, void 0, function* () {
76
74
  var _a, _b;
@@ -108,7 +106,7 @@ class DoraBDSNeoLegacy {
108
106
  }
109
107
  getContract(contractHash) {
110
108
  return __awaiter(this, void 0, void 0, function* () {
111
- const response = yield dora_ts_1.api.NeoLegacyREST.contract(contractHash, __classPrivateFieldGet(this, _DoraBDSNeoLegacy_network, "f").type);
109
+ const response = yield dora_ts_1.api.NeoLegacyREST.contract(contractHash, __classPrivateFieldGet(this, _DoraBDSNeoLegacy_network, "f").id);
112
110
  if (!response || 'error' in response)
113
111
  throw new Error(`Contract ${contractHash} not found`);
114
112
  return {
@@ -120,13 +118,13 @@ class DoraBDSNeoLegacy {
120
118
  }
121
119
  getTokenInfo(tokenHash) {
122
120
  return __awaiter(this, void 0, void 0, function* () {
123
- const localToken = constants_1.TOKENS[__classPrivateFieldGet(this, _DoraBDSNeoLegacy_network, "f").type].find(token => token.hash === tokenHash);
121
+ const localToken = constants_1.TOKENS[__classPrivateFieldGet(this, _DoraBDSNeoLegacy_network, "f").id].find(token => token.hash === tokenHash);
124
122
  if (localToken)
125
123
  return localToken;
126
124
  if (__classPrivateFieldGet(this, _DoraBDSNeoLegacy_tokenCache, "f").has(tokenHash)) {
127
125
  return __classPrivateFieldGet(this, _DoraBDSNeoLegacy_tokenCache, "f").get(tokenHash);
128
126
  }
129
- const data = yield dora_ts_1.api.NeoLegacyREST.asset(tokenHash, __classPrivateFieldGet(this, _DoraBDSNeoLegacy_network, "f").type);
127
+ const data = yield dora_ts_1.api.NeoLegacyREST.asset(tokenHash, __classPrivateFieldGet(this, _DoraBDSNeoLegacy_network, "f").id);
130
128
  if (!data || 'error' in data)
131
129
  throw new Error(`Token ${tokenHash} not found`);
132
130
  const token = {
@@ -141,7 +139,7 @@ class DoraBDSNeoLegacy {
141
139
  }
142
140
  getBalance(address) {
143
141
  return __awaiter(this, void 0, void 0, function* () {
144
- const data = yield dora_ts_1.api.NeoLegacyREST.balance(address, __classPrivateFieldGet(this, _DoraBDSNeoLegacy_network, "f").type);
142
+ const data = yield dora_ts_1.api.NeoLegacyREST.balance(address, __classPrivateFieldGet(this, _DoraBDSNeoLegacy_network, "f").id);
145
143
  const promises = data.map((balance) => __awaiter(this, void 0, void 0, function* () {
146
144
  const hash = balance.asset.replace('0x', '');
147
145
  let token = {
@@ -167,7 +165,7 @@ class DoraBDSNeoLegacy {
167
165
  }
168
166
  getUnclaimed(address) {
169
167
  return __awaiter(this, void 0, void 0, function* () {
170
- const { unclaimed } = yield dora_ts_1.api.NeoLegacyREST.getUnclaimed(address, __classPrivateFieldGet(this, _DoraBDSNeoLegacy_network, "f").type);
168
+ const { unclaimed } = yield dora_ts_1.api.NeoLegacyREST.getUnclaimed(address, __classPrivateFieldGet(this, _DoraBDSNeoLegacy_network, "f").id);
171
169
  return (unclaimed / Math.pow(10, __classPrivateFieldGet(this, _DoraBDSNeoLegacy_claimToken, "f").decimals)).toFixed(__classPrivateFieldGet(this, _DoraBDSNeoLegacy_claimToken, "f").decimals);
172
170
  });
173
171
  }
@@ -180,7 +178,7 @@ class DoraBDSNeoLegacy {
180
178
  getRpcList() {
181
179
  return __awaiter(this, void 0, void 0, function* () {
182
180
  const list = [];
183
- const networkType = __classPrivateFieldGet(this, _DoraBDSNeoLegacy_network, "f").type;
181
+ const networkType = __classPrivateFieldGet(this, _DoraBDSNeoLegacy_network, "f").id;
184
182
  const promises = constants_1.RPC_LIST_BY_NETWORK_TYPE[networkType].map(url => {
185
183
  // eslint-disable-next-line no-async-promise-executor
186
184
  return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
@@ -1,7 +1,8 @@
1
- import { BuildNftUrlParams, ExplorerService, NetworkType } from '@cityofzion/blockchain-service';
1
+ import { BuildNftUrlParams, ExplorerService } from '@cityofzion/blockchain-service';
2
+ import { AvailableNetworkIds } from './constants';
2
3
  export declare class DoraESNeoLegacy implements ExplorerService {
3
4
  #private;
4
- constructor(networkType: NetworkType);
5
+ constructor(networkId: AvailableNetworkIds);
5
6
  buildTransactionUrl(hash: string): string;
6
7
  buildNftUrl(_params: BuildNftUrlParams): string;
7
8
  }
@@ -10,22 +10,20 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  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");
11
11
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
12
  };
13
- var _DoraESNeoLegacy_networkType;
13
+ var _DoraESNeoLegacy_networkId;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.DoraESNeoLegacy = void 0;
16
16
  class DoraESNeoLegacy {
17
- constructor(networkType) {
18
- _DoraESNeoLegacy_networkType.set(this, void 0);
19
- __classPrivateFieldSet(this, _DoraESNeoLegacy_networkType, networkType, "f");
17
+ constructor(networkId) {
18
+ _DoraESNeoLegacy_networkId.set(this, void 0);
19
+ __classPrivateFieldSet(this, _DoraESNeoLegacy_networkId, networkId, "f");
20
20
  }
21
21
  buildTransactionUrl(hash) {
22
- if (__classPrivateFieldGet(this, _DoraESNeoLegacy_networkType, "f") === 'custom')
23
- throw new Error('DoraESNeoLegacy does not support custom network');
24
- return `https://dora.coz.io/transaction/neo2/${__classPrivateFieldGet(this, _DoraESNeoLegacy_networkType, "f")}/${hash}`;
22
+ return `https://dora.coz.io/transaction/neo2/${__classPrivateFieldGet(this, _DoraESNeoLegacy_networkId, "f")}/${hash}`;
25
23
  }
26
24
  buildNftUrl(_params) {
27
25
  throw new Error('DoraESNeoLegacy does not support nft');
28
26
  }
29
27
  }
30
28
  exports.DoraESNeoLegacy = DoraESNeoLegacy;
31
- _DoraESNeoLegacy_networkType = new WeakMap();
29
+ _DoraESNeoLegacy_networkId = new WeakMap();
@@ -1,6 +1,7 @@
1
- import { NetworkType, Token } from '@cityofzion/blockchain-service';
2
- export declare const TOKENS: Record<NetworkType, Token[]>;
3
- export declare const LEGACY_NETWORK_BY_NETWORK_TYPE: Record<Exclude<NetworkType, 'custom'>, string>;
1
+ import { Token } from '@cityofzion/blockchain-service';
2
+ export type AvailableNetworkIds = 'mainnet' | 'testnet';
3
+ export declare const TOKENS: Record<AvailableNetworkIds, Token[]>;
4
+ export declare const LEGACY_NETWORK_BY_NETWORK_TYPE: Record<Exclude<AvailableNetworkIds, 'custom'>, string>;
4
5
  export declare const NATIVE_ASSETS: {
5
6
  symbol: string;
6
7
  name: string;
@@ -8,5 +9,5 @@ export declare const NATIVE_ASSETS: {
8
9
  decimals: number;
9
10
  }[];
10
11
  export declare const DERIVATION_PATH = "m/44'/888'/0'/0/?";
11
- export declare const RPC_LIST_BY_NETWORK_TYPE: Record<Exclude<NetworkType, 'custom'>, string[]>;
12
- export declare const DEFAULT_URL_BY_NETWORK_TYPE: Record<Exclude<NetworkType, 'custom'>, string>;
12
+ export declare const RPC_LIST_BY_NETWORK_TYPE: Record<Exclude<AvailableNetworkIds, 'custom'>, string[]>;
13
+ export declare const DEFAULT_URL_BY_NETWORK_TYPE: Record<Exclude<AvailableNetworkIds, 'custom'>, string>;
package/dist/constants.js CHANGED
@@ -9,7 +9,6 @@ const mainnet_json_1 = __importDefault(require("./assets/tokens/mainnet.json"));
9
9
  exports.TOKENS = {
10
10
  mainnet: [...common_json_1.default, ...mainnet_json_1.default],
11
11
  testnet: common_json_1.default,
12
- custom: common_json_1.default,
13
12
  };
14
13
  exports.LEGACY_NETWORK_BY_NETWORK_TYPE = {
15
14
  mainnet: 'MainNet',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cityofzion/bs-neo-legacy",
3
- "version": "0.10.5",
3
+ "version": "1.0.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "author": "Coz",
@@ -11,7 +11,7 @@
11
11
  "dependencies": {
12
12
  "@cityofzion/dora-ts": "0.0.11",
13
13
  "@cityofzion/neon-js": "4.8.3",
14
- "@cityofzion/blockchain-service": "0.13.0",
14
+ "@cityofzion/blockchain-service": "1.0.0",
15
15
  "@cityofzion/bs-asteroid-sdk": "0.9.0"
16
16
  },
17
17
  "devDependencies": {