@cityofzion/bs-neo3 1.16.3 → 1.17.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/BSNeo3.d.ts +40 -30
- package/dist/BSNeo3.js +104 -54
- package/dist/constants/BSNeo3Constants.d.ts +12 -17
- package/dist/constants/BSNeo3Constants.js +221 -37
- package/dist/helpers/BSNeo3Helper.d.ts +5 -6
- package/dist/helpers/BSNeo3Helper.js +9 -8
- package/dist/helpers/BSNeo3NeonDappKitSingletonHelper.d.ts +6 -0
- package/dist/helpers/BSNeo3NeonDappKitSingletonHelper.js +26 -0
- package/dist/helpers/BSNeo3NeonJsSingletonHelper.d.ts +7 -0
- package/dist/helpers/BSNeo3NeonJsSingletonHelper.js +26 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- package/dist/services/blockchain-data/DoraBDSNeo3.d.ts +13 -12
- package/dist/services/blockchain-data/DoraBDSNeo3.js +131 -141
- package/dist/services/blockchain-data/RpcBDSNeo3.d.ts +13 -19
- package/dist/services/blockchain-data/RpcBDSNeo3.js +28 -62
- package/dist/services/chaim-data/RpcCDSNeo3.d.ts +7 -0
- package/dist/services/chaim-data/RpcCDSNeo3.js +27 -0
- package/dist/services/exchange-data/FlamingoForthewinEDSNeo3.d.ts +6 -7
- package/dist/services/exchange-data/FlamingoForthewinEDSNeo3.js +4 -19
- package/dist/services/explorer/DoraESNeo3.d.ts +5 -5
- package/dist/services/explorer/DoraESNeo3.js +19 -22
- package/dist/services/ledger/NeonDappKitLedgerServiceNeo3.d.ts +10 -10
- package/dist/services/ledger/NeonDappKitLedgerServiceNeo3.js +28 -38
- package/dist/services/neo3neoXBridge/Neo3NeoXBridgeService.d.ts +10 -9
- package/dist/services/neo3neoXBridge/Neo3NeoXBridgeService.js +26 -25
- package/dist/services/nft-data/GhostMarketNDSNeo3.d.ts +7 -11
- package/dist/services/nft-data/GhostMarketNDSNeo3.js +41 -79
- package/dist/services/vote/DoraVoteServiceNeo3.d.ts +8 -29
- package/dist/services/vote/DoraVoteServiceNeo3.js +81 -21
- package/dist/services/wallet-connect/WalletConnectServiceNeo3.d.ts +45 -0
- package/dist/services/wallet-connect/WalletConnectServiceNeo3.js +163 -0
- package/dist/types.d.ts +84 -0
- package/dist/types.js +18 -0
- package/package.json +25 -25
- package/dist/assets/tokens/mainnet.json +0 -194
- package/dist/assets/tokens/native.json +0 -14
- package/dist/builder/invocation/NeonDappKitInvocationBuilderNeo3.d.ts +0 -34
- package/dist/builder/invocation/NeonDappKitInvocationBuilderNeo3.js +0 -102
- package/dist/interfaces.d.ts +0 -41
- package/dist/interfaces.js +0 -2
- package/dist/services/nft-data/RpcNDSNeo3.d.ts +0 -9
- package/dist/services/nft-data/RpcNDSNeo3.js +0 -59
- package/dist/services/vote/RpcVoteServiceNeo3.d.ts +0 -10
- package/dist/services/vote/RpcVoteServiceNeo3.js +0 -88
|
@@ -10,32 +10,27 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.RpcBDSNeo3 = void 0;
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const BSNeo3Helper_1 = require("../../helpers/BSNeo3Helper");
|
|
13
|
+
const BSNeo3NeonJsSingletonHelper_1 = require("../../helpers/BSNeo3NeonJsSingletonHelper");
|
|
14
|
+
const BSNeo3NeonDappKitSingletonHelper_1 = require("../../helpers/BSNeo3NeonDappKitSingletonHelper");
|
|
16
15
|
class RpcBDSNeo3 {
|
|
17
|
-
constructor(
|
|
16
|
+
constructor(service) {
|
|
17
|
+
this.maxTimeToConfirmTransactionInMs = 1000 * 60 * 2; // 2 minutes
|
|
18
18
|
this._tokenCache = new Map();
|
|
19
|
-
this.
|
|
20
|
-
this.maxTimeToConfirmTransactionInMs = 1000 * 60 * 2;
|
|
21
|
-
this._network = network;
|
|
22
|
-
this._feeToken = feeToken;
|
|
23
|
-
this._claimToken = claimToken;
|
|
24
|
-
this._tokens = tokens;
|
|
25
|
-
this._tokenService = tokenService;
|
|
19
|
+
this._service = service;
|
|
26
20
|
}
|
|
27
21
|
getTransaction(hash) {
|
|
28
|
-
var _a, _b;
|
|
29
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
var _a, _b;
|
|
30
24
|
try {
|
|
31
|
-
const
|
|
25
|
+
const { rpc, u } = BSNeo3NeonJsSingletonHelper_1.BSNeo3NeonJsSingletonHelper.getInstance();
|
|
26
|
+
const rpcClient = new rpc.RPCClient(this._service.network.url);
|
|
32
27
|
const response = yield rpcClient.getRawTransaction(hash, true);
|
|
33
28
|
return {
|
|
34
29
|
hash: response.hash,
|
|
35
30
|
block: response.validuntilblock,
|
|
36
|
-
fee:
|
|
37
|
-
.add(
|
|
38
|
-
.toDecimal(this.
|
|
31
|
+
fee: u.BigInteger.fromNumber((_a = response.netfee) !== null && _a !== void 0 ? _a : 0)
|
|
32
|
+
.add(u.BigInteger.fromNumber((_b = response.sysfee) !== null && _b !== void 0 ? _b : 0))
|
|
33
|
+
.toDecimal(this._service.feeToken.decimals),
|
|
39
34
|
notifications: [],
|
|
40
35
|
transfers: [],
|
|
41
36
|
time: response.blocktime,
|
|
@@ -65,7 +60,8 @@ class RpcBDSNeo3 {
|
|
|
65
60
|
getContract(contractHash) {
|
|
66
61
|
return __awaiter(this, void 0, void 0, function* () {
|
|
67
62
|
try {
|
|
68
|
-
const
|
|
63
|
+
const { rpc } = BSNeo3NeonJsSingletonHelper_1.BSNeo3NeonJsSingletonHelper.getInstance();
|
|
64
|
+
const rpcClient = new rpc.RPCClient(this._service.network.url);
|
|
69
65
|
const contractState = yield rpcClient.getContractState(contractHash);
|
|
70
66
|
const methods = contractState.manifest.abi.methods.map(method => ({
|
|
71
67
|
name: method.name,
|
|
@@ -92,12 +88,14 @@ class RpcBDSNeo3 {
|
|
|
92
88
|
if (cachedToken) {
|
|
93
89
|
return cachedToken;
|
|
94
90
|
}
|
|
95
|
-
let token = this.
|
|
91
|
+
let token = this._service.tokens.find(token => this._service.tokenService.predicateByHash(tokenHash, token));
|
|
96
92
|
if (!token) {
|
|
97
|
-
const
|
|
93
|
+
const { rpc, u } = BSNeo3NeonJsSingletonHelper_1.BSNeo3NeonJsSingletonHelper.getInstance();
|
|
94
|
+
const rpcClient = new rpc.RPCClient(this._service.network.url);
|
|
98
95
|
const contractState = yield rpcClient.getContractState(tokenHash);
|
|
99
|
-
const
|
|
100
|
-
|
|
96
|
+
const { TypeChecker, NeonInvoker } = BSNeo3NeonDappKitSingletonHelper_1.BSNeo3NeonDappKitSingletonHelper.getInstance();
|
|
97
|
+
const invoker = yield NeonInvoker.init({
|
|
98
|
+
rpcAddress: this._service.network.url,
|
|
101
99
|
});
|
|
102
100
|
const response = yield invoker.testInvoke({
|
|
103
101
|
invocations: [
|
|
@@ -109,13 +107,13 @@ class RpcBDSNeo3 {
|
|
|
109
107
|
{ scriptHash: tokenHash, operation: 'symbol', args: [] },
|
|
110
108
|
],
|
|
111
109
|
});
|
|
112
|
-
if (!
|
|
110
|
+
if (!TypeChecker.isStackTypeInteger(response.stack[0]))
|
|
113
111
|
throw new Error('Invalid decimals');
|
|
114
|
-
if (!
|
|
112
|
+
if (!TypeChecker.isStackTypeByteString(response.stack[1]))
|
|
115
113
|
throw new Error('Invalid symbol');
|
|
116
114
|
const decimals = Number(response.stack[0].value);
|
|
117
|
-
const symbol =
|
|
118
|
-
token = this.
|
|
115
|
+
const symbol = u.base642utf8(response.stack[1].value);
|
|
116
|
+
token = this._service.tokenService.normalizeToken({
|
|
119
117
|
name: contractState.manifest.name,
|
|
120
118
|
symbol,
|
|
121
119
|
hash: contractState.hash,
|
|
@@ -132,7 +130,8 @@ class RpcBDSNeo3 {
|
|
|
132
130
|
}
|
|
133
131
|
getBalance(address) {
|
|
134
132
|
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
-
const
|
|
133
|
+
const { rpc, u } = BSNeo3NeonJsSingletonHelper_1.BSNeo3NeonJsSingletonHelper.getInstance();
|
|
134
|
+
const rpcClient = new rpc.RPCClient(this._service.network.url);
|
|
136
135
|
const response = yield rpcClient.getNep17Balances(address);
|
|
137
136
|
const promises = response.balance.map((balance) => __awaiter(this, void 0, void 0, function* () {
|
|
138
137
|
var _a;
|
|
@@ -149,7 +148,7 @@ class RpcBDSNeo3 {
|
|
|
149
148
|
// Empty Block
|
|
150
149
|
}
|
|
151
150
|
return {
|
|
152
|
-
amount:
|
|
151
|
+
amount: u.BigInteger.fromNumber(balance.amount).toDecimal((_a = token === null || token === void 0 ? void 0 : token.decimals) !== null && _a !== void 0 ? _a : 8),
|
|
153
152
|
token,
|
|
154
153
|
};
|
|
155
154
|
}));
|
|
@@ -158,43 +157,10 @@ class RpcBDSNeo3 {
|
|
|
158
157
|
}
|
|
159
158
|
getBlockHeight() {
|
|
160
159
|
return __awaiter(this, void 0, void 0, function* () {
|
|
161
|
-
const
|
|
160
|
+
const { rpc } = BSNeo3NeonJsSingletonHelper_1.BSNeo3NeonJsSingletonHelper.getInstance();
|
|
161
|
+
const rpcClient = new rpc.RPCClient(this._service.network.url);
|
|
162
162
|
return yield rpcClient.getBlockCount();
|
|
163
163
|
});
|
|
164
164
|
}
|
|
165
|
-
getUnclaimed(address) {
|
|
166
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
167
|
-
const rpcClient = new neon_core_1.rpc.RPCClient(this._network.url);
|
|
168
|
-
const response = yield rpcClient.getUnclaimedGas(address);
|
|
169
|
-
return neon_core_1.u.BigInteger.fromNumber(response).toDecimal(this._claimToken.decimals);
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
getRpcList() {
|
|
173
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
174
|
-
const list = [];
|
|
175
|
-
const urls = BSNeo3Helper_1.BSNeo3Helper.getRpcList(this._network);
|
|
176
|
-
const promises = urls.map(url => {
|
|
177
|
-
// eslint-disable-next-line no-async-promise-executor
|
|
178
|
-
return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
|
|
179
|
-
const timeout = setTimeout(() => {
|
|
180
|
-
resolve();
|
|
181
|
-
}, 5000);
|
|
182
|
-
try {
|
|
183
|
-
const rpcClient = new neon_core_1.rpc.RPCClient(url);
|
|
184
|
-
const timeStart = Date.now();
|
|
185
|
-
const height = yield rpcClient.getBlockCount();
|
|
186
|
-
const latency = Date.now() - timeStart;
|
|
187
|
-
list.push({ url, latency, height });
|
|
188
|
-
}
|
|
189
|
-
finally {
|
|
190
|
-
resolve();
|
|
191
|
-
clearTimeout(timeout);
|
|
192
|
-
}
|
|
193
|
-
}));
|
|
194
|
-
});
|
|
195
|
-
yield Promise.allSettled(promises);
|
|
196
|
-
return list;
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
165
|
}
|
|
200
166
|
exports.RpcBDSNeo3 = RpcBDSNeo3;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { IClaimDataService } from '@cityofzion/blockchain-service';
|
|
2
|
+
import { IBSNeo3 } from '../../types';
|
|
3
|
+
export declare class RpcCDSNeo3<N extends string> implements IClaimDataService {
|
|
4
|
+
readonly _service: IBSNeo3<N>;
|
|
5
|
+
constructor(service: IBSNeo3<N>);
|
|
6
|
+
getUnclaimed(address: string): Promise<string>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.RpcCDSNeo3 = void 0;
|
|
13
|
+
const BSNeo3NeonJsSingletonHelper_1 = require("../../helpers/BSNeo3NeonJsSingletonHelper");
|
|
14
|
+
class RpcCDSNeo3 {
|
|
15
|
+
constructor(service) {
|
|
16
|
+
this._service = service;
|
|
17
|
+
}
|
|
18
|
+
getUnclaimed(address) {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
const { rpc, u } = BSNeo3NeonJsSingletonHelper_1.BSNeo3NeonJsSingletonHelper.getInstance();
|
|
21
|
+
const rpcClient = new rpc.RPCClient(this._service.network.url);
|
|
22
|
+
const response = yield rpcClient.getUnclaimedGas(address);
|
|
23
|
+
return u.BigInteger.fromNumber(response).toDecimal(this._service.claimToken.decimals);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.RpcCDSNeo3 = RpcCDSNeo3;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export declare class FlamingoForthewinEDSNeo3 extends
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
getTokenPriceHistory(params: GetTokenPriceHistoryParams): Promise<TokenPricesHistoryResponse[]>;
|
|
1
|
+
import { FlamingoForthewinEDS, TGetTokenPriceHistoryParams, TGetTokenPricesParams, TTokenPricesHistoryResponse, TTokenPricesResponse } from '@cityofzion/blockchain-service';
|
|
2
|
+
import { IBSNeo3 } from '../../types';
|
|
3
|
+
export declare class FlamingoForthewinEDSNeo3<N extends string> extends FlamingoForthewinEDS<N> {
|
|
4
|
+
constructor(service: IBSNeo3<N>);
|
|
5
|
+
getTokenPrices(params: TGetTokenPricesParams): Promise<TTokenPricesResponse[]>;
|
|
6
|
+
getTokenPriceHistory(params: TGetTokenPriceHistoryParams): Promise<TTokenPricesHistoryResponse[]>;
|
|
8
7
|
}
|
|
@@ -8,34 +8,20 @@ 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 _FlamingoForthewinEDSNeo3_network;
|
|
23
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
12
|
exports.FlamingoForthewinEDSNeo3 = void 0;
|
|
25
13
|
const blockchain_service_1 = require("@cityofzion/blockchain-service");
|
|
26
14
|
const BSNeo3Helper_1 = require("../../helpers/BSNeo3Helper");
|
|
27
15
|
class FlamingoForthewinEDSNeo3 extends blockchain_service_1.FlamingoForthewinEDS {
|
|
28
|
-
constructor(
|
|
29
|
-
super(
|
|
30
|
-
_FlamingoForthewinEDSNeo3_network.set(this, void 0);
|
|
31
|
-
__classPrivateFieldSet(this, _FlamingoForthewinEDSNeo3_network, network, "f");
|
|
16
|
+
constructor(service) {
|
|
17
|
+
super(service);
|
|
32
18
|
}
|
|
33
19
|
getTokenPrices(params) {
|
|
34
20
|
const _super = Object.create(null, {
|
|
35
21
|
getTokenPrices: { get: () => super.getTokenPrices }
|
|
36
22
|
});
|
|
37
23
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
if (!BSNeo3Helper_1.BSNeo3Helper.
|
|
24
|
+
if (!BSNeo3Helper_1.BSNeo3Helper.isMainnetNetwork(this._service.network))
|
|
39
25
|
throw new Error('Exchange is only available on Mainnet');
|
|
40
26
|
return yield _super.getTokenPrices.call(this, params);
|
|
41
27
|
});
|
|
@@ -45,11 +31,10 @@ class FlamingoForthewinEDSNeo3 extends blockchain_service_1.FlamingoForthewinEDS
|
|
|
45
31
|
getTokenPriceHistory: { get: () => super.getTokenPriceHistory }
|
|
46
32
|
});
|
|
47
33
|
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
-
if (!BSNeo3Helper_1.BSNeo3Helper.
|
|
34
|
+
if (!BSNeo3Helper_1.BSNeo3Helper.isMainnetNetwork(this._service.network))
|
|
49
35
|
throw new Error('Exchange is only available on Mainnet');
|
|
50
36
|
return yield _super.getTokenPriceHistory.call(this, params);
|
|
51
37
|
});
|
|
52
38
|
}
|
|
53
39
|
}
|
|
54
40
|
exports.FlamingoForthewinEDSNeo3 = FlamingoForthewinEDSNeo3;
|
|
55
|
-
_FlamingoForthewinEDSNeo3_network = new WeakMap();
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export declare class DoraESNeo3 implements
|
|
1
|
+
import { TBuildNftUrlParams, IExplorerService } from '@cityofzion/blockchain-service';
|
|
2
|
+
import { IBSNeo3 } from '../../types';
|
|
3
|
+
export declare class DoraESNeo3<N extends string> implements IExplorerService {
|
|
4
4
|
#private;
|
|
5
|
-
constructor(
|
|
5
|
+
constructor(service: IBSNeo3<N>);
|
|
6
6
|
buildTransactionUrl(hash: string): string;
|
|
7
7
|
buildContractUrl(contractHash: string): string;
|
|
8
|
-
buildNftUrl({ collectionHash, tokenHash }:
|
|
8
|
+
buildNftUrl({ collectionHash, tokenHash }: TBuildNftUrlParams): string;
|
|
9
9
|
getAddressTemplateUrl(): string | undefined;
|
|
10
10
|
getTxTemplateUrl(): string | undefined;
|
|
11
11
|
getNftTemplateUrl(): string | undefined;
|
|
@@ -10,54 +10,51 @@ 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
|
|
13
|
+
var _DoraESNeo3_service;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.DoraESNeo3 = void 0;
|
|
16
16
|
const blockchain_service_1 = require("@cityofzion/blockchain-service");
|
|
17
17
|
const BSNeo3Helper_1 = require("../../helpers/BSNeo3Helper");
|
|
18
18
|
class DoraESNeo3 {
|
|
19
|
-
constructor(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
_DoraESNeo3_tokenService.set(this, void 0);
|
|
23
|
-
__classPrivateFieldSet(this, _DoraESNeo3_network, network, "f");
|
|
24
|
-
__classPrivateFieldSet(this, _DoraESNeo3_tokenService, tokenService, "f");
|
|
19
|
+
constructor(service) {
|
|
20
|
+
_DoraESNeo3_service.set(this, void 0);
|
|
21
|
+
__classPrivateFieldSet(this, _DoraESNeo3_service, service, "f");
|
|
25
22
|
}
|
|
26
23
|
buildTransactionUrl(hash) {
|
|
27
|
-
if (BSNeo3Helper_1.BSNeo3Helper.
|
|
24
|
+
if (BSNeo3Helper_1.BSNeo3Helper.isCustomNetwork(__classPrivateFieldGet(this, _DoraESNeo3_service, "f").network))
|
|
28
25
|
throw new Error('DoraESNeo3 is only available on mainnet and testnet');
|
|
29
|
-
return `${
|
|
26
|
+
return `${blockchain_service_1.BSCommonConstants.DORA_URL}/transaction/neo3/${__classPrivateFieldGet(this, _DoraESNeo3_service, "f").network.id}/${__classPrivateFieldGet(this, _DoraESNeo3_service, "f").tokenService.normalizeHash(hash)}`;
|
|
30
27
|
}
|
|
31
28
|
buildContractUrl(contractHash) {
|
|
32
|
-
if (BSNeo3Helper_1.BSNeo3Helper.
|
|
29
|
+
if (BSNeo3Helper_1.BSNeo3Helper.isCustomNetwork(__classPrivateFieldGet(this, _DoraESNeo3_service, "f").network))
|
|
33
30
|
throw new Error('DoraESNeo3 is only available on mainnet and testnet');
|
|
34
|
-
return `${
|
|
31
|
+
return `${blockchain_service_1.BSCommonConstants.DORA_URL}/contract/neo3/${__classPrivateFieldGet(this, _DoraESNeo3_service, "f").network.id}/${__classPrivateFieldGet(this, _DoraESNeo3_service, "f").tokenService.normalizeHash(contractHash)}`;
|
|
35
32
|
}
|
|
36
33
|
buildNftUrl({ collectionHash, tokenHash }) {
|
|
37
|
-
if (BSNeo3Helper_1.BSNeo3Helper.
|
|
34
|
+
if (BSNeo3Helper_1.BSNeo3Helper.isCustomNetwork(__classPrivateFieldGet(this, _DoraESNeo3_service, "f").network))
|
|
38
35
|
throw new Error('DoraESNeo3 is only available on mainnet and testnet');
|
|
39
|
-
return `${
|
|
36
|
+
return `${blockchain_service_1.BSCommonConstants.DORA_URL}/nft/neo3/${__classPrivateFieldGet(this, _DoraESNeo3_service, "f").network.id}/${collectionHash}/${tokenHash}`;
|
|
40
37
|
}
|
|
41
38
|
getAddressTemplateUrl() {
|
|
42
|
-
if (BSNeo3Helper_1.BSNeo3Helper.
|
|
39
|
+
if (BSNeo3Helper_1.BSNeo3Helper.isCustomNetwork(__classPrivateFieldGet(this, _DoraESNeo3_service, "f").network))
|
|
43
40
|
return undefined;
|
|
44
|
-
return `${
|
|
41
|
+
return `${blockchain_service_1.BSCommonConstants.DORA_URL}/address/neo3/${__classPrivateFieldGet(this, _DoraESNeo3_service, "f").network.id}/{address}`;
|
|
45
42
|
}
|
|
46
43
|
getTxTemplateUrl() {
|
|
47
|
-
if (BSNeo3Helper_1.BSNeo3Helper.
|
|
44
|
+
if (BSNeo3Helper_1.BSNeo3Helper.isCustomNetwork(__classPrivateFieldGet(this, _DoraESNeo3_service, "f").network))
|
|
48
45
|
return undefined;
|
|
49
|
-
return `${
|
|
46
|
+
return `${blockchain_service_1.BSCommonConstants.DORA_URL}/transaction/neo3/${__classPrivateFieldGet(this, _DoraESNeo3_service, "f").network.id}/{txId}`;
|
|
50
47
|
}
|
|
51
48
|
getNftTemplateUrl() {
|
|
52
|
-
if (BSNeo3Helper_1.BSNeo3Helper.
|
|
49
|
+
if (BSNeo3Helper_1.BSNeo3Helper.isCustomNetwork(__classPrivateFieldGet(this, _DoraESNeo3_service, "f").network))
|
|
53
50
|
return undefined;
|
|
54
|
-
return `${
|
|
51
|
+
return `${blockchain_service_1.BSCommonConstants.DORA_URL}/nft/neo3/${__classPrivateFieldGet(this, _DoraESNeo3_service, "f").network.id}/{collectionHash}/{tokenHash}`;
|
|
55
52
|
}
|
|
56
53
|
getContractTemplateUrl() {
|
|
57
|
-
if (BSNeo3Helper_1.BSNeo3Helper.
|
|
54
|
+
if (BSNeo3Helper_1.BSNeo3Helper.isCustomNetwork(__classPrivateFieldGet(this, _DoraESNeo3_service, "f").network))
|
|
58
55
|
return undefined;
|
|
59
|
-
return `${
|
|
56
|
+
return `${blockchain_service_1.BSCommonConstants.DORA_URL}/contract/neo3/${__classPrivateFieldGet(this, _DoraESNeo3_service, "f").network.id}/{hash}`;
|
|
60
57
|
}
|
|
61
58
|
}
|
|
62
59
|
exports.DoraESNeo3 = DoraESNeo3;
|
|
63
|
-
|
|
60
|
+
_DoraESNeo3_service = new WeakMap();
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { api } from '@cityofzion/neon-js';
|
|
1
|
+
import { TBSAccount, TGetLedgerTransport, ILedgerService, TLedgerServiceEmitter, TUntilIndexRecord } from '@cityofzion/blockchain-service';
|
|
3
2
|
import Transport from '@ledgerhq/hw-transport';
|
|
4
|
-
import {
|
|
5
|
-
|
|
3
|
+
import { IBSNeo3 } from '../../types';
|
|
4
|
+
import { api } from '../../helpers/BSNeo3NeonJsSingletonHelper';
|
|
5
|
+
export declare class NeonDappKitLedgerServiceNeo3<N extends string = string> implements ILedgerService<N> {
|
|
6
6
|
#private;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
constructor(blockchainService:
|
|
7
|
+
readonly getLedgerTransport?: TGetLedgerTransport<N>;
|
|
8
|
+
emitter: TLedgerServiceEmitter;
|
|
9
|
+
constructor(blockchainService: IBSNeo3<N>, getLedgerTransport?: TGetLedgerTransport<N>);
|
|
10
10
|
verifyAppName(transport: Transport): Promise<boolean>;
|
|
11
|
-
getAccount(transport: Transport, index: number): Promise<
|
|
12
|
-
getAccounts(transport: Transport, untilIndexByBlockchainService?:
|
|
13
|
-
getSigningCallback(transport: Transport, account:
|
|
11
|
+
getAccount(transport: Transport, index: number): Promise<TBSAccount<N>>;
|
|
12
|
+
getAccounts(transport: Transport, untilIndexByBlockchainService?: TUntilIndexRecord<N>): Promise<TBSAccount<N>[]>;
|
|
13
|
+
getSigningCallback(transport: Transport, account: TBSAccount): api.SigningFunction;
|
|
14
14
|
}
|
|
@@ -22,41 +22,27 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
22
22
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
23
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
24
|
};
|
|
25
|
-
var _NeonDappKitLedgerServiceNeo3_instances,
|
|
25
|
+
var _NeonDappKitLedgerServiceNeo3_instances, _NeonDappKitLedgerServiceNeo3_service, _NeonDappKitLedgerServiceNeo3_sendChunk, _NeonDappKitLedgerServiceNeo3_bip44PathToHex, _NeonDappKitLedgerServiceNeo3_derSignatureToHex;
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
27
|
exports.NeonDappKitLedgerServiceNeo3 = void 0;
|
|
28
28
|
const blockchain_service_1 = require("@cityofzion/blockchain-service");
|
|
29
|
-
const neon_dappkit_1 = require("@cityofzion/neon-dappkit");
|
|
30
|
-
const neon_js_1 = require("@cityofzion/neon-js");
|
|
31
29
|
const events_1 = __importDefault(require("events"));
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
})(LedgerStatus || (LedgerStatus = {}));
|
|
36
|
-
var LedgerCommand;
|
|
37
|
-
(function (LedgerCommand) {
|
|
38
|
-
LedgerCommand[LedgerCommand["GET_APP_NAME"] = 0] = "GET_APP_NAME";
|
|
39
|
-
LedgerCommand[LedgerCommand["GET_PUBLIC_KEY"] = 4] = "GET_PUBLIC_KEY";
|
|
40
|
-
LedgerCommand[LedgerCommand["SIGN"] = 2] = "SIGN";
|
|
41
|
-
})(LedgerCommand || (LedgerCommand = {}));
|
|
42
|
-
var LedgerSecondParameter;
|
|
43
|
-
(function (LedgerSecondParameter) {
|
|
44
|
-
LedgerSecondParameter[LedgerSecondParameter["MORE_DATA"] = 128] = "MORE_DATA";
|
|
45
|
-
LedgerSecondParameter[LedgerSecondParameter["LAST_DATA"] = 0] = "LAST_DATA";
|
|
46
|
-
})(LedgerSecondParameter || (LedgerSecondParameter = {}));
|
|
30
|
+
const types_1 = require("../../types");
|
|
31
|
+
const BSNeo3NeonJsSingletonHelper_1 = require("../../helpers/BSNeo3NeonJsSingletonHelper");
|
|
32
|
+
const BSNeo3NeonDappKitSingletonHelper_1 = require("../../helpers/BSNeo3NeonDappKitSingletonHelper");
|
|
47
33
|
class NeonDappKitLedgerServiceNeo3 {
|
|
48
34
|
constructor(blockchainService, getLedgerTransport) {
|
|
49
35
|
_NeonDappKitLedgerServiceNeo3_instances.add(this);
|
|
50
|
-
|
|
36
|
+
_NeonDappKitLedgerServiceNeo3_service.set(this, void 0);
|
|
51
37
|
this.emitter = new events_1.default();
|
|
52
|
-
__classPrivateFieldSet(this,
|
|
38
|
+
__classPrivateFieldSet(this, _NeonDappKitLedgerServiceNeo3_service, blockchainService, "f");
|
|
53
39
|
this.getLedgerTransport = getLedgerTransport;
|
|
54
40
|
}
|
|
55
41
|
// This verification is necessary because the NEO2 Ledger App also detects NEO3
|
|
56
42
|
verifyAppName(transport) {
|
|
57
43
|
return __awaiter(this, void 0, void 0, function* () {
|
|
58
44
|
try {
|
|
59
|
-
const response = yield __classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_instances, "m", _NeonDappKitLedgerServiceNeo3_sendChunk).call(this, transport,
|
|
45
|
+
const response = yield __classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_instances, "m", _NeonDappKitLedgerServiceNeo3_sendChunk).call(this, transport, types_1.ENeonDappKitLedgerServiceNeo3Command.GET_APP_NAME, 0x00, types_1.ENeonDappKitLedgerServiceNeo3SecondParameter.LAST_DATA, undefined);
|
|
60
46
|
const version = response.toString('ascii');
|
|
61
47
|
const appName = version.substring(0, version.length - 2);
|
|
62
48
|
if (appName !== 'NEO N3')
|
|
@@ -70,53 +56,56 @@ class NeonDappKitLedgerServiceNeo3 {
|
|
|
70
56
|
}
|
|
71
57
|
getAccount(transport, index) {
|
|
72
58
|
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
-
const bip44Path = __classPrivateFieldGet(this,
|
|
59
|
+
const bip44Path = __classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_service, "f").bip44DerivationPath.replace('?', index.toString());
|
|
74
60
|
const bip44PathHex = __classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_instances, "m", _NeonDappKitLedgerServiceNeo3_bip44PathToHex).call(this, bip44Path);
|
|
75
61
|
const isNeoN3App = yield this.verifyAppName(transport);
|
|
76
62
|
if (!isNeoN3App)
|
|
77
63
|
throw new Error('App is not NEO N3');
|
|
78
|
-
const result = yield __classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_instances, "m", _NeonDappKitLedgerServiceNeo3_sendChunk).call(this, transport,
|
|
64
|
+
const result = yield __classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_instances, "m", _NeonDappKitLedgerServiceNeo3_sendChunk).call(this, transport, types_1.ENeonDappKitLedgerServiceNeo3Command.GET_PUBLIC_KEY, 0x00, types_1.ENeonDappKitLedgerServiceNeo3SecondParameter.LAST_DATA, bip44PathHex);
|
|
79
65
|
const publicKey = result.toString('hex').substring(0, 130);
|
|
80
|
-
const {
|
|
66
|
+
const { wallet } = BSNeo3NeonJsSingletonHelper_1.BSNeo3NeonJsSingletonHelper.getInstance();
|
|
67
|
+
const { address } = new wallet.Account(publicKey);
|
|
81
68
|
return {
|
|
82
69
|
address,
|
|
83
70
|
key: publicKey,
|
|
84
71
|
type: 'publicKey',
|
|
85
72
|
bip44Path,
|
|
86
|
-
blockchain: __classPrivateFieldGet(this,
|
|
73
|
+
blockchain: __classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_service, "f").name,
|
|
87
74
|
isHardware: true,
|
|
88
75
|
};
|
|
89
76
|
});
|
|
90
77
|
}
|
|
91
78
|
getAccounts(transport, untilIndexByBlockchainService) {
|
|
92
79
|
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
-
const accountsByBlockchainService = yield (0, blockchain_service_1.generateAccountForBlockchainService)([__classPrivateFieldGet(this,
|
|
80
|
+
const accountsByBlockchainService = yield (0, blockchain_service_1.generateAccountForBlockchainService)([__classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_service, "f")], (_service, index) => __awaiter(this, void 0, void 0, function* () {
|
|
94
81
|
return this.getAccount(transport, index);
|
|
95
82
|
}), untilIndexByBlockchainService);
|
|
96
|
-
const accounts = accountsByBlockchainService.get(__classPrivateFieldGet(this,
|
|
83
|
+
const accounts = accountsByBlockchainService.get(__classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_service, "f").name);
|
|
97
84
|
return accounts !== null && accounts !== void 0 ? accounts : [];
|
|
98
85
|
});
|
|
99
86
|
}
|
|
100
87
|
getSigningCallback(transport, account) {
|
|
101
|
-
return (
|
|
88
|
+
return (transaction_1, _a) => __awaiter(this, [transaction_1, _a], void 0, function* (transaction, { witnessIndex, network }) {
|
|
102
89
|
const isNeoN3App = yield this.verifyAppName(transport);
|
|
103
90
|
if (!isNeoN3App)
|
|
104
91
|
throw new Error('App is not NEO N3');
|
|
105
92
|
try {
|
|
106
93
|
this.emitter.emit('getSignatureStart');
|
|
107
94
|
if (!account.bip44Path) {
|
|
108
|
-
throw new Error('
|
|
95
|
+
throw new Error('TBSAccount must have a bip 44 path to sign with Ledger');
|
|
109
96
|
}
|
|
110
|
-
const
|
|
111
|
-
const
|
|
97
|
+
const { wallet } = BSNeo3NeonJsSingletonHelper_1.BSNeo3NeonJsSingletonHelper.getInstance();
|
|
98
|
+
const neonJsAccount = new wallet.Account(account.key);
|
|
99
|
+
const witnessScriptHash = wallet.getScriptHashFromVerificationScript(transaction.witnesses[witnessIndex].verificationScript.toString());
|
|
112
100
|
if (neonJsAccount.scriptHash !== witnessScriptHash) {
|
|
113
101
|
throw new Error('Invalid witness script hash');
|
|
114
102
|
}
|
|
115
103
|
const bip44PathHex = __classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_instances, "m", _NeonDappKitLedgerServiceNeo3_bip44PathToHex).call(this, account.bip44Path);
|
|
116
104
|
// Send the BIP44 account as first chunk
|
|
117
|
-
yield __classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_instances, "m", _NeonDappKitLedgerServiceNeo3_sendChunk).call(this, transport,
|
|
105
|
+
yield __classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_instances, "m", _NeonDappKitLedgerServiceNeo3_sendChunk).call(this, transport, types_1.ENeonDappKitLedgerServiceNeo3Command.SIGN, 0, types_1.ENeonDappKitLedgerServiceNeo3SecondParameter.MORE_DATA, bip44PathHex);
|
|
106
|
+
const { NeonParser } = BSNeo3NeonDappKitSingletonHelper_1.BSNeo3NeonDappKitSingletonHelper.getInstance();
|
|
118
107
|
// Send the network magic as second chunk
|
|
119
|
-
yield __classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_instances, "m", _NeonDappKitLedgerServiceNeo3_sendChunk).call(this, transport,
|
|
108
|
+
yield __classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_instances, "m", _NeonDappKitLedgerServiceNeo3_sendChunk).call(this, transport, types_1.ENeonDappKitLedgerServiceNeo3Command.SIGN, 1, types_1.ENeonDappKitLedgerServiceNeo3SecondParameter.MORE_DATA, NeonParser.numToHex(network, 4, true));
|
|
120
109
|
const serializedTransaction = transaction.serialize(false);
|
|
121
110
|
// Split the serialized transaction into chunks of 510 bytes
|
|
122
111
|
const chunks = serializedTransaction.match(/.{1,510}/g) || [];
|
|
@@ -124,12 +113,12 @@ class NeonDappKitLedgerServiceNeo3 {
|
|
|
124
113
|
for (let i = 0; i < chunks.length - 1; i++) {
|
|
125
114
|
// We plus 2 because we already sent 2 chunks before
|
|
126
115
|
const commandIndex = 2 + i;
|
|
127
|
-
yield __classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_instances, "m", _NeonDappKitLedgerServiceNeo3_sendChunk).call(this, transport,
|
|
116
|
+
yield __classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_instances, "m", _NeonDappKitLedgerServiceNeo3_sendChunk).call(this, transport, types_1.ENeonDappKitLedgerServiceNeo3Command.SIGN, commandIndex, types_1.ENeonDappKitLedgerServiceNeo3SecondParameter.MORE_DATA, chunks[i]);
|
|
128
117
|
}
|
|
129
118
|
// Again, we plus 2 because we already sent 2 chunks before getting the chunks
|
|
130
119
|
const lastChunkIndex = 2 + chunks.length;
|
|
131
120
|
// Send the last chunk signaling that it is the last one and get the signature
|
|
132
|
-
const response = yield __classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_instances, "m", _NeonDappKitLedgerServiceNeo3_sendChunk).call(this, transport,
|
|
121
|
+
const response = yield __classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_instances, "m", _NeonDappKitLedgerServiceNeo3_sendChunk).call(this, transport, types_1.ENeonDappKitLedgerServiceNeo3Command.SIGN, lastChunkIndex, types_1.ENeonDappKitLedgerServiceNeo3SecondParameter.LAST_DATA, chunks[chunks.length - 1]);
|
|
133
122
|
if (response.length <= 2) {
|
|
134
123
|
throw new Error('Invalid signature returned from Ledger');
|
|
135
124
|
}
|
|
@@ -142,9 +131,9 @@ class NeonDappKitLedgerServiceNeo3 {
|
|
|
142
131
|
}
|
|
143
132
|
}
|
|
144
133
|
exports.NeonDappKitLedgerServiceNeo3 = NeonDappKitLedgerServiceNeo3;
|
|
145
|
-
|
|
134
|
+
_NeonDappKitLedgerServiceNeo3_service = new WeakMap(), _NeonDappKitLedgerServiceNeo3_instances = new WeakSet(), _NeonDappKitLedgerServiceNeo3_sendChunk = function _NeonDappKitLedgerServiceNeo3_sendChunk(transport, command, commandIndex, secondParameter, chunk) {
|
|
146
135
|
return transport.send(0x80, command, commandIndex, secondParameter, chunk ? Buffer.from(chunk, 'hex') : undefined, [
|
|
147
|
-
|
|
136
|
+
types_1.ENeonDappKitLedgerServiceNeo3Status.OK,
|
|
148
137
|
]);
|
|
149
138
|
}, _NeonDappKitLedgerServiceNeo3_bip44PathToHex = function _NeonDappKitLedgerServiceNeo3_bip44PathToHex(path) {
|
|
150
139
|
let result = '';
|
|
@@ -161,7 +150,8 @@ _NeonDappKitLedgerServiceNeo3_blockchainService = new WeakMap(), _NeonDappKitLed
|
|
|
161
150
|
});
|
|
162
151
|
return result;
|
|
163
152
|
}, _NeonDappKitLedgerServiceNeo3_derSignatureToHex = function _NeonDappKitLedgerServiceNeo3_derSignatureToHex(response) {
|
|
164
|
-
const
|
|
153
|
+
const { u } = BSNeo3NeonJsSingletonHelper_1.BSNeo3NeonJsSingletonHelper.getInstance();
|
|
154
|
+
const ss = new u.StringStream(response);
|
|
165
155
|
// The first byte is format. It is usually 0x30 (SEQ) or 0x31 (SET)
|
|
166
156
|
// The second byte represents the total length of the DER module.
|
|
167
157
|
ss.read(2);
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { INeo3NeoXBridgeService, TBridgeToken, TNeo3NeoXBridgeServiceBridgeParam, TNeo3NeoXBridgeServiceConstants, TNeo3NeoXBridgeServiceGetNonceParams, TNeo3NeoXBridgeServiceGetTransactionHashByNonceParams } from '@cityofzion/blockchain-service';
|
|
2
|
-
import {
|
|
3
|
-
export declare class Neo3NeoXBridgeService<
|
|
2
|
+
import { IBSNeo3 } from '../../types';
|
|
3
|
+
export declare class Neo3NeoXBridgeService<N extends string> implements INeo3NeoXBridgeService<N> {
|
|
4
4
|
#private;
|
|
5
|
-
readonly BRIDGE_SCRIPT_HASH
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
static readonly BRIDGE_SCRIPT_HASH: string;
|
|
6
|
+
readonly gasToken: TBridgeToken<N>;
|
|
7
|
+
readonly neoToken: TBridgeToken<N>;
|
|
8
|
+
constructor(service: IBSNeo3<N>);
|
|
8
9
|
getApprovalFee(): Promise<string>;
|
|
9
|
-
getBridgeConstants(token: TBridgeToken<
|
|
10
|
-
bridge(params: TNeo3NeoXBridgeServiceBridgeParam<
|
|
11
|
-
getNonce(params: TNeo3NeoXBridgeServiceGetNonceParams<
|
|
12
|
-
getTransactionHashByNonce(params: TNeo3NeoXBridgeServiceGetTransactionHashByNonceParams<
|
|
10
|
+
getBridgeConstants(token: TBridgeToken<N>): Promise<TNeo3NeoXBridgeServiceConstants>;
|
|
11
|
+
bridge(params: TNeo3NeoXBridgeServiceBridgeParam<N>): Promise<string>;
|
|
12
|
+
getNonce(params: TNeo3NeoXBridgeServiceGetNonceParams<N>): Promise<string>;
|
|
13
|
+
getTransactionHashByNonce(params: TNeo3NeoXBridgeServiceGetTransactionHashByNonceParams<N>): Promise<string>;
|
|
13
14
|
}
|