@cityofzion/bs-neo3 1.10.9 → 1.11.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.
- package/dist/helpers/BSNeo3Helper.js +2 -1
- package/dist/services/exchange-data/FlamingoForthewinEDSNeo3.d.ts +3 -3
- package/dist/services/exchange-data/FlamingoForthewinEDSNeo3.js +9 -44
- package/dist/services/ledger/NeonDappKitLedgerServiceNeo3.d.ts +1 -0
- package/dist/services/ledger/NeonDappKitLedgerServiceNeo3.js +26 -1
- package/package.json +2 -2
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.BSNeo3Helper = void 0;
|
|
7
|
+
const blockchain_service_1 = require("@cityofzion/blockchain-service");
|
|
7
8
|
const native_json_1 = __importDefault(require("../assets/tokens/native.json"));
|
|
8
9
|
const BSNeo3Constants_1 = require("../constants/BSNeo3Constants");
|
|
9
10
|
class BSNeo3Helper {
|
|
@@ -23,7 +24,7 @@ class BSNeo3Helper {
|
|
|
23
24
|
return !BSNeo3Constants_1.BSNeo3Constants.ALL_NETWORK_IDS.includes(network.id);
|
|
24
25
|
}
|
|
25
26
|
static normalizeHash(hash) {
|
|
26
|
-
return
|
|
27
|
+
return (0, blockchain_service_1.normalizeHash)(hash, { lowercase: false });
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
30
|
exports.BSNeo3Helper = BSNeo3Helper;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ExchangeDataService, FlamingoForthewinEDS, GetTokenPriceHistoryParams, GetTokenPricesParams, Network, TokenPricesHistoryResponse, TokenPricesResponse } from '@cityofzion/blockchain-service';
|
|
2
2
|
import { BSNeo3NetworkId } from '../../constants/BSNeo3Constants';
|
|
3
|
-
export declare class FlamingoForthewinEDSNeo3 extends
|
|
3
|
+
export declare class FlamingoForthewinEDSNeo3 extends FlamingoForthewinEDS implements ExchangeDataService {
|
|
4
4
|
#private;
|
|
5
5
|
constructor(network: Network<BSNeo3NetworkId>);
|
|
6
|
-
getTokenPrices(
|
|
6
|
+
getTokenPrices(params: GetTokenPricesParams): Promise<TokenPricesResponse[]>;
|
|
7
7
|
getTokenPriceHistory(params: GetTokenPriceHistoryParams): Promise<TokenPricesHistoryResponse[]>;
|
|
8
8
|
}
|
|
@@ -19,60 +19,25 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
19
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
20
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
21
21
|
};
|
|
22
|
-
var
|
|
23
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
-
};
|
|
25
|
-
var _FlamingoForthewinEDSNeo3_network, _FlamingoForthewinEDSNeo3_flamingoAxiosInstance, _FlamingoForthewinEDSNeo3_forthewinAxiosInstance;
|
|
22
|
+
var _FlamingoForthewinEDSNeo3_network;
|
|
26
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
24
|
exports.FlamingoForthewinEDSNeo3 = void 0;
|
|
28
25
|
const blockchain_service_1 = require("@cityofzion/blockchain-service");
|
|
29
|
-
const axios_1 = __importDefault(require("axios"));
|
|
30
26
|
const BSNeo3Helper_1 = require("../../helpers/BSNeo3Helper");
|
|
31
|
-
class FlamingoForthewinEDSNeo3 extends blockchain_service_1.
|
|
27
|
+
class FlamingoForthewinEDSNeo3 extends blockchain_service_1.FlamingoForthewinEDS {
|
|
32
28
|
constructor(network) {
|
|
33
29
|
super();
|
|
34
30
|
_FlamingoForthewinEDSNeo3_network.set(this, void 0);
|
|
35
|
-
_FlamingoForthewinEDSNeo3_flamingoAxiosInstance.set(this, void 0);
|
|
36
|
-
_FlamingoForthewinEDSNeo3_forthewinAxiosInstance.set(this, void 0);
|
|
37
31
|
__classPrivateFieldSet(this, _FlamingoForthewinEDSNeo3_network, network, "f");
|
|
38
|
-
__classPrivateFieldSet(this, _FlamingoForthewinEDSNeo3_flamingoAxiosInstance, axios_1.default.create({ baseURL: 'https://neo-api.b-cdn.net/flamingo' }), "f");
|
|
39
|
-
__classPrivateFieldSet(this, _FlamingoForthewinEDSNeo3_forthewinAxiosInstance, axios_1.default.create({ baseURL: 'https://api.forthewin.network' }), "f");
|
|
40
32
|
}
|
|
41
|
-
getTokenPrices(
|
|
42
|
-
|
|
33
|
+
getTokenPrices(params) {
|
|
34
|
+
const _super = Object.create(null, {
|
|
35
|
+
getTokenPrices: { get: () => super.getTokenPrices }
|
|
36
|
+
});
|
|
43
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
44
38
|
if (!BSNeo3Helper_1.BSNeo3Helper.isMainnet(__classPrivateFieldGet(this, _FlamingoForthewinEDSNeo3_network, "f")))
|
|
45
39
|
throw new Error('Exchange is only available on Mainnet');
|
|
46
|
-
|
|
47
|
-
const prices = [];
|
|
48
|
-
const allTokens = BSNeo3Helper_1.BSNeo3Helper.getTokens(__classPrivateFieldGet(this, _FlamingoForthewinEDSNeo3_network, "f"));
|
|
49
|
-
const neoToken = tokens.find(({ symbol }) => symbol === 'NEO');
|
|
50
|
-
const bNeoTokenHash = BSNeo3Helper_1.BSNeo3Helper.normalizeHash((_b = (_a = allTokens.find(({ symbol }) => symbol === 'bNEO')) === null || _a === void 0 ? void 0 : _a.hash) !== null && _b !== void 0 ? _b : '');
|
|
51
|
-
if (neoToken)
|
|
52
|
-
flamingoData.forEach(item => {
|
|
53
|
-
if (bNeoTokenHash === BSNeo3Helper_1.BSNeo3Helper.normalizeHash(item.hash))
|
|
54
|
-
flamingoData.push(Object.assign(Object.assign({}, item), { symbol: neoToken.symbol, hash: neoToken.hash }));
|
|
55
|
-
});
|
|
56
|
-
flamingoData.forEach(item => {
|
|
57
|
-
const token = tokens.find(({ hash }) => BSNeo3Helper_1.BSNeo3Helper.normalizeHash(hash) === BSNeo3Helper_1.BSNeo3Helper.normalizeHash(item.hash));
|
|
58
|
-
if (!token)
|
|
59
|
-
return;
|
|
60
|
-
prices.push({ usdPrice: item.usd_price, token });
|
|
61
|
-
});
|
|
62
|
-
if (tokens.length > prices.length) {
|
|
63
|
-
const { data: forthewinData } = yield __classPrivateFieldGet(this, _FlamingoForthewinEDSNeo3_forthewinAxiosInstance, "f").get('/mainnet/prices');
|
|
64
|
-
Object.entries(forthewinData).forEach(([hash, usdPrice]) => {
|
|
65
|
-
hash = BSNeo3Helper_1.BSNeo3Helper.normalizeHash(hash);
|
|
66
|
-
const hasPrice = !!prices.find(({ token }) => BSNeo3Helper_1.BSNeo3Helper.normalizeHash(token.hash) === hash);
|
|
67
|
-
if (hasPrice)
|
|
68
|
-
return;
|
|
69
|
-
const foundToken = tokens.find(token => BSNeo3Helper_1.BSNeo3Helper.normalizeHash(token.hash) === hash);
|
|
70
|
-
if (!foundToken)
|
|
71
|
-
return;
|
|
72
|
-
prices.push({ usdPrice, token: foundToken });
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
return prices;
|
|
40
|
+
return yield _super.getTokenPrices.call(this, params);
|
|
76
41
|
});
|
|
77
42
|
}
|
|
78
43
|
getTokenPriceHistory(params) {
|
|
@@ -81,10 +46,10 @@ class FlamingoForthewinEDSNeo3 extends blockchain_service_1.CryptoCompareEDS {
|
|
|
81
46
|
});
|
|
82
47
|
return __awaiter(this, void 0, void 0, function* () {
|
|
83
48
|
if (!BSNeo3Helper_1.BSNeo3Helper.isMainnet(__classPrivateFieldGet(this, _FlamingoForthewinEDSNeo3_network, "f")))
|
|
84
|
-
throw new Error('Exchange is only available on
|
|
49
|
+
throw new Error('Exchange is only available on Mainnet');
|
|
85
50
|
return yield _super.getTokenPriceHistory.call(this, params);
|
|
86
51
|
});
|
|
87
52
|
}
|
|
88
53
|
}
|
|
89
54
|
exports.FlamingoForthewinEDSNeo3 = FlamingoForthewinEDSNeo3;
|
|
90
|
-
_FlamingoForthewinEDSNeo3_network = new WeakMap()
|
|
55
|
+
_FlamingoForthewinEDSNeo3_network = new WeakMap();
|
|
@@ -7,6 +7,7 @@ export declare class NeonDappKitLedgerServiceNeo3<BSName extends string = string
|
|
|
7
7
|
emitter: LedgerServiceEmitter;
|
|
8
8
|
getLedgerTransport?: GetLedgerTransport<BSName>;
|
|
9
9
|
constructor(blockchainService: BSNeo3<BSName>, getLedgerTransport?: GetLedgerTransport<BSName>);
|
|
10
|
+
verifyAppName(transport: Transport): Promise<boolean>;
|
|
10
11
|
getAccount(transport: Transport, index: number): Promise<Account<BSName>>;
|
|
11
12
|
getAccounts(transport: Transport, untilIndexByBlockchainService?: UntilIndexRecord<BSName>): Promise<Account<BSName>[]>;
|
|
12
13
|
getSigningCallback(transport: Transport, account: Account): api.SigningFunction;
|
|
@@ -35,6 +35,7 @@ var LedgerStatus;
|
|
|
35
35
|
})(LedgerStatus || (LedgerStatus = {}));
|
|
36
36
|
var LedgerCommand;
|
|
37
37
|
(function (LedgerCommand) {
|
|
38
|
+
LedgerCommand[LedgerCommand["GET_APP_NAME"] = 0] = "GET_APP_NAME";
|
|
38
39
|
LedgerCommand[LedgerCommand["GET_PUBLIC_KEY"] = 4] = "GET_PUBLIC_KEY";
|
|
39
40
|
LedgerCommand[LedgerCommand["SIGN"] = 2] = "SIGN";
|
|
40
41
|
})(LedgerCommand || (LedgerCommand = {}));
|
|
@@ -51,10 +52,29 @@ class NeonDappKitLedgerServiceNeo3 {
|
|
|
51
52
|
__classPrivateFieldSet(this, _NeonDappKitLedgerServiceNeo3_blockchainService, blockchainService, "f");
|
|
52
53
|
this.getLedgerTransport = getLedgerTransport;
|
|
53
54
|
}
|
|
55
|
+
// This verification is necessary because the NEO2 Ledger App also detects NEO3
|
|
56
|
+
verifyAppName(transport) {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
try {
|
|
59
|
+
const response = yield __classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_instances, "m", _NeonDappKitLedgerServiceNeo3_sendChunk).call(this, transport, LedgerCommand.GET_APP_NAME, 0x00, LedgerSecondParameter.LAST_DATA, undefined);
|
|
60
|
+
const version = response.toString('ascii');
|
|
61
|
+
const appName = version.substring(0, version.length - 2);
|
|
62
|
+
if (appName !== 'NEO N3')
|
|
63
|
+
return false;
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
catch (_a) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
54
71
|
getAccount(transport, index) {
|
|
55
72
|
return __awaiter(this, void 0, void 0, function* () {
|
|
56
73
|
const bip44Path = __classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_blockchainService, "f").bip44DerivationPath.replace('?', index.toString());
|
|
57
74
|
const bip44PathHex = __classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_instances, "m", _NeonDappKitLedgerServiceNeo3_bip44PathToHex).call(this, bip44Path);
|
|
75
|
+
const isNeoN3App = yield this.verifyAppName(transport);
|
|
76
|
+
if (!isNeoN3App)
|
|
77
|
+
throw new Error('App is not NEO N3');
|
|
58
78
|
const result = yield __classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_instances, "m", _NeonDappKitLedgerServiceNeo3_sendChunk).call(this, transport, LedgerCommand.GET_PUBLIC_KEY, 0x00, LedgerSecondParameter.LAST_DATA, bip44PathHex);
|
|
59
79
|
const publicKey = result.toString('hex').substring(0, 130);
|
|
60
80
|
const { address } = new neon_js_1.wallet.Account(publicKey);
|
|
@@ -79,6 +99,9 @@ class NeonDappKitLedgerServiceNeo3 {
|
|
|
79
99
|
}
|
|
80
100
|
getSigningCallback(transport, account) {
|
|
81
101
|
return (transaction, { witnessIndex, network }) => __awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
const isNeoN3App = yield this.verifyAppName(transport);
|
|
103
|
+
if (!isNeoN3App)
|
|
104
|
+
throw new Error('App is not NEO N3');
|
|
82
105
|
try {
|
|
83
106
|
this.emitter.emit('getSignatureStart');
|
|
84
107
|
if (!account.bip44Path) {
|
|
@@ -120,7 +143,9 @@ class NeonDappKitLedgerServiceNeo3 {
|
|
|
120
143
|
}
|
|
121
144
|
exports.NeonDappKitLedgerServiceNeo3 = NeonDappKitLedgerServiceNeo3;
|
|
122
145
|
_NeonDappKitLedgerServiceNeo3_blockchainService = new WeakMap(), _NeonDappKitLedgerServiceNeo3_instances = new WeakSet(), _NeonDappKitLedgerServiceNeo3_sendChunk = function _NeonDappKitLedgerServiceNeo3_sendChunk(transport, command, commandIndex, secondParameter, chunk) {
|
|
123
|
-
return transport.send(0x80, command, commandIndex, secondParameter, Buffer.from(chunk, 'hex'), [
|
|
146
|
+
return transport.send(0x80, command, commandIndex, secondParameter, chunk ? Buffer.from(chunk, 'hex') : undefined, [
|
|
147
|
+
LedgerStatus.OK,
|
|
148
|
+
]);
|
|
124
149
|
}, _NeonDappKitLedgerServiceNeo3_bip44PathToHex = function _NeonDappKitLedgerServiceNeo3_bip44PathToHex(path) {
|
|
125
150
|
let result = '';
|
|
126
151
|
const components = path.split('/');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cityofzion/bs-neo3",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.0",
|
|
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
|
"bignumber.js": "^9.1.2",
|
|
21
21
|
"isomorphic-ws": "^5.0.0",
|
|
22
22
|
"lodash.clonedeep": "^4.5.0",
|
|
23
|
-
"@cityofzion/blockchain-service": "1.
|
|
23
|
+
"@cityofzion/blockchain-service": "1.17.0",
|
|
24
24
|
"@cityofzion/bs-asteroid-sdk": "0.9.1"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|