@cityofzion/bs-neo3 0.9.3 → 0.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/BSNeo3.d.ts +8 -4
- package/dist/BSNeo3.js +38 -13
- package/dist/DoraBDSNeo3.d.ts +0 -1
- package/dist/DoraBDSNeo3.js +11 -12
- package/dist/DoraESNeo3.d.ts +1 -1
- package/dist/DoraESNeo3.js +19 -5
- package/dist/FlamingoEDSNeo3.d.ts +1 -2
- package/dist/FlamingoEDSNeo3.js +20 -5
- package/dist/GhostMarketNDSNeo3.d.ts +1 -1
- package/dist/GhostMarketNDSNeo3.js +17 -3
- package/dist/LedgerServiceNeo3.d.ts +14 -0
- package/dist/LedgerServiceNeo3.js +96 -0
- package/dist/RpcBDSNeo3.d.ts +4 -4
- package/dist/RpcBDSNeo3.js +23 -19
- package/package.json +12 -9
- package/.eslintignore +0 -13
- package/.eslintrc.cjs +0 -22
- package/.rush/temp/operation/build/all.log +0 -1
- package/.rush/temp/operation/build/state.json +0 -3
- package/.rush/temp/package-deps_build.json +0 -31
- package/.rush/temp/shrinkwrap-deps.json +0 -439
- package/CHANGELOG.json +0 -66
- package/CHANGELOG.md +0 -33
- package/bs-neo3.build.log +0 -1
- package/jest.config.ts +0 -13
- package/jest.setup.ts +0 -1
- package/src/BSNeo3.ts +0 -232
- package/src/DoraBDSNeo3.ts +0 -188
- package/src/DoraESNeo3.ts +0 -19
- package/src/FlamingoEDSNeo3.ts +0 -41
- package/src/GhostMarketNDSNeo3.ts +0 -121
- package/src/RpcBDSNeo3.ts +0 -159
- package/src/__tests__/BDSNeo3.spec.ts +0 -124
- package/src/__tests__/BSNeo3.spec.ts +0 -149
- package/src/__tests__/DoraESNeo3.spec.ts +0 -23
- package/src/__tests__/FlamingoEDSNeo3.spec.ts +0 -48
- package/src/__tests__/GhostMarketNDSNeo3.spec.ts +0 -48
- package/src/__tests__/utils/sleep.ts +0 -1
- package/src/assets/tokens/common.json +0 -14
- package/src/assets/tokens/mainnet.json +0 -116
- package/src/constants.ts +0 -29
- package/src/index.ts +0 -6
- package/tsconfig.build.json +0 -4
- package/tsconfig.json +0 -14
package/dist/BSNeo3.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { BlockchainDataService, BlockchainService, BSClaimable, Account, ExchangeDataService, BDSClaimable, Token, BSWithNameService, Network, PartialBy, TransferParam, BSCalculableFee, NftDataService, BSWithNft, AccountWithDerivationPath, BSWithExplorerService, ExplorerService } from '@cityofzion/blockchain-service';
|
|
2
|
-
|
|
1
|
+
import { BlockchainDataService, BlockchainService, BSClaimable, Account, ExchangeDataService, BDSClaimable, Token, BSWithNameService, Network, PartialBy, TransferParam, BSCalculableFee, NftDataService, BSWithNft, AccountWithDerivationPath, BSWithExplorerService, ExplorerService, BSWithLedger } from '@cityofzion/blockchain-service';
|
|
2
|
+
import { LedgerServiceNeo3 } from './LedgerServiceNeo3';
|
|
3
|
+
import Transport from '@ledgerhq/hw-transport';
|
|
4
|
+
export declare class BSNeo3<BSCustomName extends string = string> implements BlockchainService, BSClaimable, BSWithNameService, BSCalculableFee, BSWithNft, BSWithExplorerService, BSWithLedger {
|
|
3
5
|
readonly blockchainName: BSCustomName;
|
|
4
6
|
readonly feeToken: Token;
|
|
5
7
|
readonly claimToken: Token;
|
|
@@ -7,23 +9,25 @@ export declare class BSNeo3<BSCustomName extends string = string> implements Blo
|
|
|
7
9
|
readonly derivationPath: string;
|
|
8
10
|
blockchainDataService: BlockchainDataService & BDSClaimable;
|
|
9
11
|
nftDataService: NftDataService;
|
|
12
|
+
ledgerService: LedgerServiceNeo3;
|
|
10
13
|
exchangeDataService: ExchangeDataService;
|
|
11
14
|
explorerService: ExplorerService;
|
|
12
15
|
tokens: Token[];
|
|
13
16
|
network: Network;
|
|
14
|
-
constructor(blockchainName: BSCustomName, network: PartialBy<Network, 'url'>);
|
|
17
|
+
constructor(blockchainName: BSCustomName, network: PartialBy<Network, 'url'>, getLedgerTransport?: (account: Account) => Promise<Transport>);
|
|
15
18
|
setNetwork(param: PartialBy<Network, 'url'>): void;
|
|
16
19
|
validateAddress(address: string): boolean;
|
|
17
20
|
validateEncrypted(encryptedKey: string): boolean;
|
|
18
21
|
validateKey(key: string): boolean;
|
|
19
22
|
validateNameServiceDomainFormat(domainName: string): boolean;
|
|
20
23
|
generateAccountFromMnemonic(mnemonic: string[] | string, index: number): AccountWithDerivationPath;
|
|
24
|
+
generateAccountFromPublicKey(publicKey: string): Account;
|
|
21
25
|
generateAccountFromKey(key: string): Account;
|
|
22
26
|
decrypt(encryptedKey: string, password: string): Promise<Account>;
|
|
23
27
|
encrypt(key: string, password: string): Promise<string>;
|
|
24
28
|
calculateTransferFee(param: TransferParam): Promise<string>;
|
|
25
29
|
transfer(param: TransferParam): Promise<string>;
|
|
26
|
-
claim(account: Account): Promise<string>;
|
|
30
|
+
claim(account: Account, isLedger?: boolean): Promise<string>;
|
|
27
31
|
resolveNameServiceDomain(domainName: string): Promise<any>;
|
|
28
32
|
private buildTransferInvocation;
|
|
29
33
|
}
|
package/dist/BSNeo3.js
CHANGED
|
@@ -11,9 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.BSNeo3 = void 0;
|
|
13
13
|
const neon_js_1 = require("@cityofzion/neon-js");
|
|
14
|
-
const
|
|
15
|
-
const neon_parser_1 = require("@cityofzion/neon-parser");
|
|
16
|
-
const neo3_parser_1 = require("@cityofzion/neo3-parser");
|
|
14
|
+
const neon_dappkit_1 = require("@cityofzion/neon-dappkit");
|
|
17
15
|
const RpcBDSNeo3_1 = require("./RpcBDSNeo3");
|
|
18
16
|
const DoraBDSNeo3_1 = require("./DoraBDSNeo3");
|
|
19
17
|
const constants_1 = require("./constants");
|
|
@@ -21,9 +19,11 @@ const FlamingoEDSNeo3_1 = require("./FlamingoEDSNeo3");
|
|
|
21
19
|
const GhostMarketNDSNeo3_1 = require("./GhostMarketNDSNeo3");
|
|
22
20
|
const bs_asteroid_sdk_1 = require("@cityofzion/bs-asteroid-sdk");
|
|
23
21
|
const DoraESNeo3_1 = require("./DoraESNeo3");
|
|
22
|
+
const LedgerServiceNeo3_1 = require("./LedgerServiceNeo3");
|
|
24
23
|
class BSNeo3 {
|
|
25
|
-
constructor(blockchainName, network) {
|
|
24
|
+
constructor(blockchainName, network, getLedgerTransport) {
|
|
26
25
|
this.blockchainName = blockchainName;
|
|
26
|
+
this.ledgerService = new LedgerServiceNeo3_1.LedgerServiceNeo3(getLedgerTransport);
|
|
27
27
|
this.tokens = constants_1.TOKENS[network.type];
|
|
28
28
|
this.derivationPath = constants_1.DERIVATION_PATH;
|
|
29
29
|
this.feeToken = this.tokens.find(token => token.symbol === 'GAS');
|
|
@@ -70,6 +70,16 @@ class BSNeo3 {
|
|
|
70
70
|
const { address } = new neon_js_1.wallet.Account(key);
|
|
71
71
|
return { address, key, type: 'wif', derivationPath: path };
|
|
72
72
|
}
|
|
73
|
+
generateAccountFromPublicKey(publicKey) {
|
|
74
|
+
if (!neon_js_1.wallet.isPublicKey(publicKey))
|
|
75
|
+
throw new Error('Invalid public key');
|
|
76
|
+
const account = new neon_js_1.wallet.Account(publicKey);
|
|
77
|
+
return {
|
|
78
|
+
address: account.address,
|
|
79
|
+
key: account.publicKey,
|
|
80
|
+
type: 'publicKey',
|
|
81
|
+
};
|
|
82
|
+
}
|
|
73
83
|
generateAccountFromKey(key) {
|
|
74
84
|
const type = neon_js_1.wallet.isWIF(key) ? 'wif' : neon_js_1.wallet.isPrivateKey(key) ? 'privateKey' : undefined;
|
|
75
85
|
if (!type)
|
|
@@ -101,24 +111,31 @@ class BSNeo3 {
|
|
|
101
111
|
calculateTransferFee(param) {
|
|
102
112
|
return __awaiter(this, void 0, void 0, function* () {
|
|
103
113
|
const account = new neon_js_1.wallet.Account(param.senderAccount.key);
|
|
104
|
-
const invoker = yield
|
|
114
|
+
const invoker = yield neon_dappkit_1.NeonInvoker.init({
|
|
105
115
|
rpcAddress: this.network.url,
|
|
106
116
|
account,
|
|
107
117
|
});
|
|
108
118
|
const invocations = this.buildTransferInvocation(param, account);
|
|
109
|
-
const {
|
|
119
|
+
const { total } = yield invoker.calculateFee({
|
|
110
120
|
invocations,
|
|
111
121
|
signers: [],
|
|
112
122
|
});
|
|
113
|
-
return
|
|
123
|
+
return total.toString();
|
|
114
124
|
});
|
|
115
125
|
}
|
|
116
126
|
transfer(param) {
|
|
117
127
|
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
+
let ledgerTransport;
|
|
129
|
+
if (param.isLedger) {
|
|
130
|
+
if (!this.ledgerService.getLedgerTransport)
|
|
131
|
+
throw new Error('You must provide a getLedgerTransport function to use Ledger');
|
|
132
|
+
ledgerTransport = yield this.ledgerService.getLedgerTransport(param.senderAccount);
|
|
133
|
+
}
|
|
118
134
|
const account = new neon_js_1.wallet.Account(param.senderAccount.key);
|
|
119
|
-
const invoker = yield
|
|
135
|
+
const invoker = yield neon_dappkit_1.NeonInvoker.init({
|
|
120
136
|
rpcAddress: this.network.url,
|
|
121
137
|
account,
|
|
138
|
+
signingCallback: ledgerTransport ? this.ledgerService.getSigningCallback(ledgerTransport) : undefined,
|
|
122
139
|
});
|
|
123
140
|
const invocations = this.buildTransferInvocation(param, account);
|
|
124
141
|
const transactionHash = yield invoker.invokeFunction({
|
|
@@ -128,12 +145,20 @@ class BSNeo3 {
|
|
|
128
145
|
return transactionHash;
|
|
129
146
|
});
|
|
130
147
|
}
|
|
131
|
-
claim(account) {
|
|
148
|
+
claim(account, isLedger) {
|
|
132
149
|
return __awaiter(this, void 0, void 0, function* () {
|
|
150
|
+
let ledgerTransport;
|
|
151
|
+
if (isLedger) {
|
|
152
|
+
if (!this.ledgerService.getLedgerTransport)
|
|
153
|
+
throw new Error('You must provide a getLedgerTransport function to use Ledger');
|
|
154
|
+
ledgerTransport = yield this.ledgerService.getLedgerTransport(account);
|
|
155
|
+
}
|
|
133
156
|
const neoAccount = new neon_js_1.wallet.Account(account.key);
|
|
134
157
|
const facade = yield neon_js_1.api.NetworkFacade.fromConfig({ node: this.network.url });
|
|
135
158
|
const transactionHash = yield facade.claimGas(neoAccount, {
|
|
136
|
-
signingCallback:
|
|
159
|
+
signingCallback: ledgerTransport
|
|
160
|
+
? this.ledgerService.getSigningCallback(ledgerTransport)
|
|
161
|
+
: neon_js_1.api.signWithAccount(neoAccount),
|
|
137
162
|
});
|
|
138
163
|
return transactionHash;
|
|
139
164
|
});
|
|
@@ -141,8 +166,8 @@ class BSNeo3 {
|
|
|
141
166
|
resolveNameServiceDomain(domainName) {
|
|
142
167
|
var _a;
|
|
143
168
|
return __awaiter(this, void 0, void 0, function* () {
|
|
144
|
-
const parser =
|
|
145
|
-
const invoker = yield
|
|
169
|
+
const parser = neon_dappkit_1.NeonParser;
|
|
170
|
+
const invoker = yield neon_dappkit_1.NeonInvoker.init({ rpcAddress: this.network.url });
|
|
146
171
|
const response = yield invoker.testInvoke({
|
|
147
172
|
invocations: [
|
|
148
173
|
{
|
|
@@ -156,7 +181,7 @@ class BSNeo3 {
|
|
|
156
181
|
throw new Error((_a = response.exception) !== null && _a !== void 0 ? _a : 'unrecognized response');
|
|
157
182
|
}
|
|
158
183
|
const parsed = parser.parseRpcResponse(response.stack[0], {
|
|
159
|
-
type:
|
|
184
|
+
type: 'Hash160',
|
|
160
185
|
});
|
|
161
186
|
const address = parser.accountInputToAddress(parsed.replace('0x', ''));
|
|
162
187
|
return address;
|
package/dist/DoraBDSNeo3.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { BalanceResponse, ContractResponse, TransactionsByAddressParams, TransactionsByAddressResponse, TransactionResponse, Network, Token } from '@cityofzion/blockchain-service';
|
|
2
2
|
import { RPCBDSNeo3 } from './RpcBDSNeo3';
|
|
3
3
|
export declare class DoraBDSNeo3 extends RPCBDSNeo3 {
|
|
4
|
-
readonly network: Network;
|
|
5
4
|
constructor(network: Network, feeToken: Token, claimToken: Token);
|
|
6
5
|
getTransaction(hash: string): Promise<TransactionResponse>;
|
|
7
6
|
getTransactionsByAddress({ address, page, }: TransactionsByAddressParams): Promise<TransactionsByAddressResponse>;
|
package/dist/DoraBDSNeo3.js
CHANGED
|
@@ -24,20 +24,19 @@ class DoraBDSNeo3 extends RpcBDSNeo3_1.RPCBDSNeo3 {
|
|
|
24
24
|
throw new Error('DoraBDSNeo3 does not support custom networks');
|
|
25
25
|
}
|
|
26
26
|
super(network, feeToken, claimToken);
|
|
27
|
-
this.network = network;
|
|
28
27
|
}
|
|
29
28
|
getTransaction(hash) {
|
|
30
29
|
var _a, _b;
|
|
31
30
|
return __awaiter(this, void 0, void 0, function* () {
|
|
32
31
|
try {
|
|
33
|
-
const data = yield NeoRest.transaction(hash, this.
|
|
32
|
+
const data = yield NeoRest.transaction(hash, this._network.type);
|
|
34
33
|
return {
|
|
35
34
|
block: data.block,
|
|
36
35
|
time: Number(data.time),
|
|
37
36
|
hash: data.hash,
|
|
38
37
|
fee: neon_js_1.u.BigInteger.fromNumber((_a = data.netfee) !== null && _a !== void 0 ? _a : 0)
|
|
39
38
|
.add(neon_js_1.u.BigInteger.fromNumber((_b = data.sysfee) !== null && _b !== void 0 ? _b : 0))
|
|
40
|
-
.toDecimal(this.
|
|
39
|
+
.toDecimal(this._feeToken.decimals),
|
|
41
40
|
notifications: [],
|
|
42
41
|
transfers: [],
|
|
43
42
|
};
|
|
@@ -49,7 +48,7 @@ class DoraBDSNeo3 extends RpcBDSNeo3_1.RPCBDSNeo3 {
|
|
|
49
48
|
}
|
|
50
49
|
getTransactionsByAddress({ address, page = 1, }) {
|
|
51
50
|
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
-
const data = yield NeoRest.addressTXFull(address, page, this.
|
|
51
|
+
const data = yield NeoRest.addressTXFull(address, page, this._network.type);
|
|
53
52
|
const promises = data.items.map((item) => __awaiter(this, void 0, void 0, function* () {
|
|
54
53
|
var _a, _b;
|
|
55
54
|
const transferPromises = [];
|
|
@@ -97,7 +96,7 @@ class DoraBDSNeo3 extends RpcBDSNeo3_1.RPCBDSNeo3 {
|
|
|
97
96
|
hash: item.hash,
|
|
98
97
|
fee: neon_js_1.u.BigInteger.fromNumber((_a = item.netfee) !== null && _a !== void 0 ? _a : 0)
|
|
99
98
|
.add(neon_js_1.u.BigInteger.fromNumber((_b = item.sysfee) !== null && _b !== void 0 ? _b : 0))
|
|
100
|
-
.toDecimal(this.
|
|
99
|
+
.toDecimal(this._feeToken.decimals),
|
|
101
100
|
transfers,
|
|
102
101
|
notifications,
|
|
103
102
|
};
|
|
@@ -114,7 +113,7 @@ class DoraBDSNeo3 extends RpcBDSNeo3_1.RPCBDSNeo3 {
|
|
|
114
113
|
var _a, _b;
|
|
115
114
|
return __awaiter(this, void 0, void 0, function* () {
|
|
116
115
|
try {
|
|
117
|
-
const data = yield NeoRest.contract(contractHash, this.
|
|
116
|
+
const data = yield NeoRest.contract(contractHash, this._network.type);
|
|
118
117
|
return {
|
|
119
118
|
hash: data.hash,
|
|
120
119
|
methods: (_b = (_a = data.manifest.abi) === null || _a === void 0 ? void 0 : _a.methods) !== null && _b !== void 0 ? _b : [],
|
|
@@ -128,21 +127,21 @@ class DoraBDSNeo3 extends RpcBDSNeo3_1.RPCBDSNeo3 {
|
|
|
128
127
|
}
|
|
129
128
|
getTokenInfo(tokenHash) {
|
|
130
129
|
return __awaiter(this, void 0, void 0, function* () {
|
|
131
|
-
const localToken = constants_1.TOKENS[this.
|
|
130
|
+
const localToken = constants_1.TOKENS[this._network.type].find(token => token.hash === tokenHash);
|
|
132
131
|
if (localToken)
|
|
133
132
|
return localToken;
|
|
134
|
-
if (this.
|
|
135
|
-
return this.
|
|
133
|
+
if (this._tokenCache.has(tokenHash)) {
|
|
134
|
+
return this._tokenCache.get(tokenHash);
|
|
136
135
|
}
|
|
137
136
|
try {
|
|
138
|
-
const { decimals, symbol, name, scripthash } = yield NeoRest.asset(tokenHash, this.
|
|
137
|
+
const { decimals, symbol, name, scripthash } = yield NeoRest.asset(tokenHash, this._network.type);
|
|
139
138
|
const token = {
|
|
140
139
|
decimals: Number(decimals),
|
|
141
140
|
symbol,
|
|
142
141
|
name,
|
|
143
142
|
hash: scripthash,
|
|
144
143
|
};
|
|
145
|
-
this.
|
|
144
|
+
this._tokenCache.set(tokenHash, token);
|
|
146
145
|
return token;
|
|
147
146
|
}
|
|
148
147
|
catch (_a) {
|
|
@@ -152,7 +151,7 @@ class DoraBDSNeo3 extends RpcBDSNeo3_1.RPCBDSNeo3 {
|
|
|
152
151
|
}
|
|
153
152
|
getBalance(address) {
|
|
154
153
|
return __awaiter(this, void 0, void 0, function* () {
|
|
155
|
-
const response = yield NeoRest.balance(address, this.
|
|
154
|
+
const response = yield NeoRest.balance(address, this._network.type);
|
|
156
155
|
const promises = response.map((balance) => __awaiter(this, void 0, void 0, function* () {
|
|
157
156
|
try {
|
|
158
157
|
const token = yield this.getTokenInfo(balance.asset);
|
package/dist/DoraESNeo3.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ExplorerService, NetworkType, BuildNftUrlParams } from '@cityofzion/blockchain-service';
|
|
2
2
|
export declare class DoraESNeo3 implements ExplorerService {
|
|
3
|
-
private
|
|
3
|
+
#private;
|
|
4
4
|
constructor(networkType: NetworkType);
|
|
5
5
|
buildTransactionUrl(hash: string): string;
|
|
6
6
|
buildNftUrl({ contractHash, tokenId }: BuildNftUrlParams): string;
|
package/dist/DoraESNeo3.js
CHANGED
|
@@ -1,19 +1,33 @@
|
|
|
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 _DoraESNeo3_networkType;
|
|
2
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
15
|
exports.DoraESNeo3 = void 0;
|
|
4
16
|
class DoraESNeo3 {
|
|
5
17
|
constructor(networkType) {
|
|
6
|
-
this
|
|
18
|
+
_DoraESNeo3_networkType.set(this, void 0);
|
|
19
|
+
__classPrivateFieldSet(this, _DoraESNeo3_networkType, networkType, "f");
|
|
7
20
|
}
|
|
8
21
|
buildTransactionUrl(hash) {
|
|
9
|
-
if (this
|
|
22
|
+
if (__classPrivateFieldGet(this, _DoraESNeo3_networkType, "f") === 'custom')
|
|
10
23
|
throw new Error('DoraESNeo3 does not support custom network');
|
|
11
|
-
return `https://dora.coz.io/transaction/neo3/${this
|
|
24
|
+
return `https://dora.coz.io/transaction/neo3/${__classPrivateFieldGet(this, _DoraESNeo3_networkType, "f")}/${hash}`;
|
|
12
25
|
}
|
|
13
26
|
buildNftUrl({ contractHash, tokenId }) {
|
|
14
|
-
if (this
|
|
27
|
+
if (__classPrivateFieldGet(this, _DoraESNeo3_networkType, "f") === 'custom')
|
|
15
28
|
throw new Error('DoraESNeo3 does not support custom network');
|
|
16
|
-
return `https://dora.coz.io/nft/neo3/${this
|
|
29
|
+
return `https://dora.coz.io/nft/neo3/${__classPrivateFieldGet(this, _DoraESNeo3_networkType, "f")}/${contractHash}/${tokenId}`;
|
|
17
30
|
}
|
|
18
31
|
}
|
|
19
32
|
exports.DoraESNeo3 = DoraESNeo3;
|
|
33
|
+
_DoraESNeo3_networkType = new WeakMap();
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Currency, ExchangeDataService, NetworkType, TokenPricesResponse } from '@cityofzion/blockchain-service';
|
|
2
2
|
export declare class FlamingoEDSNeo3 implements ExchangeDataService {
|
|
3
|
-
|
|
4
|
-
private axiosInstance;
|
|
3
|
+
#private;
|
|
5
4
|
constructor(networkType: NetworkType);
|
|
6
5
|
getTokenPrices(currency: Currency): Promise<TokenPricesResponse[]>;
|
|
7
6
|
private getCurrencyRatio;
|
package/dist/FlamingoEDSNeo3.js
CHANGED
|
@@ -8,22 +8,36 @@ 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 _FlamingoEDSNeo3_networkType, _FlamingoEDSNeo3_axiosInstance;
|
|
14
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
27
|
exports.FlamingoEDSNeo3 = void 0;
|
|
16
28
|
const axios_1 = __importDefault(require("axios"));
|
|
17
29
|
class FlamingoEDSNeo3 {
|
|
18
30
|
constructor(networkType) {
|
|
19
|
-
this
|
|
20
|
-
|
|
31
|
+
_FlamingoEDSNeo3_networkType.set(this, void 0);
|
|
32
|
+
_FlamingoEDSNeo3_axiosInstance.set(this, void 0);
|
|
33
|
+
__classPrivateFieldSet(this, _FlamingoEDSNeo3_networkType, networkType, "f");
|
|
34
|
+
__classPrivateFieldSet(this, _FlamingoEDSNeo3_axiosInstance, axios_1.default.create({ baseURL: 'https://api.flamingo.finance' }), "f");
|
|
21
35
|
}
|
|
22
36
|
getTokenPrices(currency) {
|
|
23
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
-
if (this
|
|
38
|
+
if (__classPrivateFieldGet(this, _FlamingoEDSNeo3_networkType, "f") !== 'mainnet')
|
|
25
39
|
throw new Error('Exchange is only available on mainnet');
|
|
26
|
-
const { data: prices } = yield this.
|
|
40
|
+
const { data: prices } = yield __classPrivateFieldGet(this, _FlamingoEDSNeo3_axiosInstance, "f").get('/token-info/prices');
|
|
27
41
|
let currencyRatio = 1;
|
|
28
42
|
if (currency !== 'USD') {
|
|
29
43
|
currencyRatio = yield this.getCurrencyRatio(currency);
|
|
@@ -37,9 +51,10 @@ class FlamingoEDSNeo3 {
|
|
|
37
51
|
}
|
|
38
52
|
getCurrencyRatio(currency) {
|
|
39
53
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
-
const { data } = yield this.
|
|
54
|
+
const { data } = yield __classPrivateFieldGet(this, _FlamingoEDSNeo3_axiosInstance, "f").get(`/fiat/exchange-rate?pair=USD_${currency}`);
|
|
41
55
|
return data;
|
|
42
56
|
});
|
|
43
57
|
}
|
|
44
58
|
}
|
|
45
59
|
exports.FlamingoEDSNeo3 = FlamingoEDSNeo3;
|
|
60
|
+
_FlamingoEDSNeo3_networkType = new WeakMap(), _FlamingoEDSNeo3_axiosInstance = new WeakMap();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NftResponse, NftsResponse, NetworkType, NftDataService, GetNftParam, GetNftsByAddressParams } from '@cityofzion/blockchain-service';
|
|
2
2
|
export declare class GhostMarketNDSNeo3 implements NftDataService {
|
|
3
|
-
private
|
|
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 _GhostMarketNDSNeo3_networkType;
|
|
14
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
27
|
exports.GhostMarketNDSNeo3 = void 0;
|
|
16
28
|
const query_string_1 = __importDefault(require("query-string"));
|
|
@@ -18,7 +30,8 @@ const axios_1 = __importDefault(require("axios"));
|
|
|
18
30
|
const constants_1 = require("./constants");
|
|
19
31
|
class GhostMarketNDSNeo3 {
|
|
20
32
|
constructor(networkType) {
|
|
21
|
-
this
|
|
33
|
+
_GhostMarketNDSNeo3_networkType.set(this, void 0);
|
|
34
|
+
__classPrivateFieldSet(this, _GhostMarketNDSNeo3_networkType, networkType, "f");
|
|
22
35
|
}
|
|
23
36
|
getNftsByAddress({ address, size = 18, cursor }) {
|
|
24
37
|
var _a;
|
|
@@ -54,8 +67,8 @@ class GhostMarketNDSNeo3 {
|
|
|
54
67
|
return srcImage;
|
|
55
68
|
}
|
|
56
69
|
getUrlWithParams(params) {
|
|
57
|
-
const parameters = query_string_1.default.stringify(Object.assign({ chain: constants_1.GHOSTMARKET_CHAIN_BY_NETWORK_TYPE[this
|
|
58
|
-
return `${constants_1.GHOSTMARKET_URL_BY_NETWORK_TYPE[this
|
|
70
|
+
const parameters = query_string_1.default.stringify(Object.assign({ chain: constants_1.GHOSTMARKET_CHAIN_BY_NETWORK_TYPE[__classPrivateFieldGet(this, _GhostMarketNDSNeo3_networkType, "f")] }, params), { arrayFormat: 'bracket' });
|
|
71
|
+
return `${constants_1.GHOSTMARKET_URL_BY_NETWORK_TYPE[__classPrivateFieldGet(this, _GhostMarketNDSNeo3_networkType, "f")]}/assets?${parameters}`;
|
|
59
72
|
}
|
|
60
73
|
parse(data) {
|
|
61
74
|
var _a, _b;
|
|
@@ -77,3 +90,4 @@ class GhostMarketNDSNeo3 {
|
|
|
77
90
|
}
|
|
78
91
|
}
|
|
79
92
|
exports.GhostMarketNDSNeo3 = GhostMarketNDSNeo3;
|
|
93
|
+
_GhostMarketNDSNeo3_networkType = new WeakMap();
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Account, LedgerService } from '@cityofzion/blockchain-service';
|
|
2
|
+
import Transport from '@ledgerhq/hw-transport';
|
|
3
|
+
import { api } from '@cityofzion/neon-js';
|
|
4
|
+
export declare class LedgerServiceNeo3 implements LedgerService {
|
|
5
|
+
getLedgerTransport?: ((account: Account) => Promise<Transport>) | undefined;
|
|
6
|
+
constructor(getLedgerTransport?: ((account: Account) => Promise<Transport>) | undefined);
|
|
7
|
+
getAddress(transport: Transport): Promise<string>;
|
|
8
|
+
getSigningCallback(transport: Transport): api.SigningFunction;
|
|
9
|
+
getSignature(transport: Transport, serializedTransaction: string, networkMagic: number, addressIndex?: number): Promise<string>;
|
|
10
|
+
getPublicKey(transport: Transport, addressIndex?: number): Promise<string>;
|
|
11
|
+
private toBip44Buffer;
|
|
12
|
+
private to8BitHex;
|
|
13
|
+
private derSignatureToHex;
|
|
14
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
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.LedgerServiceNeo3 = void 0;
|
|
13
|
+
const neon_js_1 = require("@cityofzion/neon-js");
|
|
14
|
+
const neon_dappkit_1 = require("@cityofzion/neon-dappkit");
|
|
15
|
+
class LedgerServiceNeo3 {
|
|
16
|
+
constructor(getLedgerTransport) {
|
|
17
|
+
this.getLedgerTransport = getLedgerTransport;
|
|
18
|
+
}
|
|
19
|
+
getAddress(transport) {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
const publicKey = yield this.getPublicKey(transport);
|
|
22
|
+
const { address } = new neon_js_1.wallet.Account(publicKey);
|
|
23
|
+
return address;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
getSigningCallback(transport) {
|
|
27
|
+
return (transaction, { witnessIndex, network }) => __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
const publicKey = yield this.getPublicKey(transport);
|
|
29
|
+
const account = new neon_js_1.wallet.Account(publicKey);
|
|
30
|
+
const witnessScriptHash = neon_js_1.wallet.getScriptHashFromVerificationScript(transaction.witnesses[witnessIndex].verificationScript.toString());
|
|
31
|
+
if (account.scriptHash !== witnessScriptHash) {
|
|
32
|
+
throw new Error('Invalid witness script hash');
|
|
33
|
+
}
|
|
34
|
+
const signature = yield this.getSignature(transport, transaction.serialize(false), network, witnessIndex);
|
|
35
|
+
return signature;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
getSignature(transport, serializedTransaction, networkMagic, addressIndex = 0) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
const bip44Buffer = this.toBip44Buffer(addressIndex);
|
|
41
|
+
yield transport.send(0x80, 0x02, 0, 0x80, bip44Buffer, [0x9000]);
|
|
42
|
+
yield transport.send(0x80, 0x02, 1, 0x80, Buffer.from(neon_dappkit_1.NeonParser.numToHex(networkMagic, 4, true), 'hex'), [0x9000]);
|
|
43
|
+
const chunks = serializedTransaction.match(/.{1,510}/g) || [];
|
|
44
|
+
for (let i = 0; i < chunks.length - 1; i++) {
|
|
45
|
+
yield transport.send(0x80, 0x02, 2 + i, 0x80, Buffer.from(chunks[i], 'hex'), [0x9000]);
|
|
46
|
+
}
|
|
47
|
+
const response = yield transport.send(0x80, 0x02, 2 + chunks.length, 0x00, Buffer.from(chunks[chunks.length - 1], 'hex'), [0x9000]);
|
|
48
|
+
if (response.length <= 2) {
|
|
49
|
+
throw new Error(`No more data but Ledger did not return signature!`);
|
|
50
|
+
}
|
|
51
|
+
return this.derSignatureToHex(response.toString('hex'));
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
getPublicKey(transport, addressIndex = 0) {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
const bip44Buffer = this.toBip44Buffer(addressIndex);
|
|
57
|
+
const result = yield transport.send(0x80, 0x04, 0x00, 0x00, bip44Buffer, [0x9000]);
|
|
58
|
+
const publicKey = result.toString('hex').substring(0, 130);
|
|
59
|
+
return publicKey;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
toBip44Buffer(addressIndex = 0, changeIndex = 0, accountIndex = 0) {
|
|
63
|
+
const accountHex = this.to8BitHex(accountIndex + 0x80000000);
|
|
64
|
+
const changeHex = this.to8BitHex(changeIndex);
|
|
65
|
+
const addressHex = this.to8BitHex(addressIndex);
|
|
66
|
+
return Buffer.from('8000002C' + '80000378' + accountHex + changeHex + addressHex, 'hex');
|
|
67
|
+
}
|
|
68
|
+
to8BitHex(num) {
|
|
69
|
+
const hex = num.toString(16);
|
|
70
|
+
return '0'.repeat(8 - hex.length) + hex;
|
|
71
|
+
}
|
|
72
|
+
derSignatureToHex(response) {
|
|
73
|
+
const ss = new neon_js_1.u.StringStream(response);
|
|
74
|
+
// The first byte is format. It is usually 0x30 (SEQ) or 0x31 (SET)
|
|
75
|
+
// The second byte represents the total length of the DER module.
|
|
76
|
+
ss.read(2);
|
|
77
|
+
// Now we read each field off
|
|
78
|
+
// Each field is encoded with a type byte, length byte followed by the data itself
|
|
79
|
+
ss.read(1); // Read and drop the type
|
|
80
|
+
const r = ss.readVarBytes();
|
|
81
|
+
ss.read(1);
|
|
82
|
+
const s = ss.readVarBytes();
|
|
83
|
+
// We will need to ensure both integers are 32 bytes long
|
|
84
|
+
const integers = [r, s].map(i => {
|
|
85
|
+
if (i.length < 64) {
|
|
86
|
+
i = '0'.repeat(i.length - 64) + i;
|
|
87
|
+
}
|
|
88
|
+
if (i.length > 64) {
|
|
89
|
+
i = i.substr(-64);
|
|
90
|
+
}
|
|
91
|
+
return i;
|
|
92
|
+
});
|
|
93
|
+
return integers.join('');
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.LedgerServiceNeo3 = LedgerServiceNeo3;
|
package/dist/RpcBDSNeo3.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { BDSClaimable, BalanceResponse, BlockchainDataService, ContractResponse, Network, Token, TransactionResponse, TransactionsByAddressParams, TransactionsByAddressResponse } from '@cityofzion/blockchain-service';
|
|
2
2
|
export declare class RPCBDSNeo3 implements BlockchainDataService, BDSClaimable {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
readonly
|
|
3
|
+
readonly _tokenCache: Map<string, Token>;
|
|
4
|
+
readonly _feeToken: Token;
|
|
5
|
+
readonly _claimToken: Token;
|
|
6
|
+
readonly _network: Network;
|
|
7
7
|
maxTimeToConfirmTransactionInMs: number;
|
|
8
8
|
constructor(network: Network, feeToken: Token, claimToken: Token);
|
|
9
9
|
getTransaction(hash: string): Promise<TransactionResponse>;
|