@cityofzion/bs-neo3 3.0.3 → 3.0.5
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 +3 -3
- package/dist/BSNeo3.js +114 -142
- package/dist/helpers/BSNeo3Helper.js +1 -2
- package/dist/services/blockchain-data/DoraBDSNeo3.js +119 -153
- package/dist/services/blockchain-data/RpcBDSNeo3.js +185 -205
- package/dist/services/chaim-data/RpcCDSNeo3.js +5 -16
- package/dist/services/exchange-data/FlamingoForthewinEDSNeo3.js +8 -27
- package/dist/services/explorer/DoraESNeo3.d.ts +1 -0
- package/dist/services/explorer/DoraESNeo3.js +5 -0
- package/dist/services/full-transactions-data/DoraFullTransactionsDataServiceNeo3.js +105 -124
- package/dist/services/ledger/NeonDappKitLedgerServiceNeo3.js +42 -57
- package/dist/services/neo3-neox-bridge/Neo3NeoXBridgeService.js +156 -171
- package/dist/services/nft-data/GhostMarketNDSNeo3.js +26 -37
- package/dist/services/vote/DoraVoteServiceNeo3.js +65 -95
- package/dist/services/wallet-connect/WalletConnectServiceNeo3.js +58 -94
- package/package.json +19 -22
package/dist/BSNeo3.d.ts
CHANGED
|
@@ -39,9 +39,9 @@ export declare class BSNeo3<N extends string = string> implements IBSNeo3<N> {
|
|
|
39
39
|
validateEncrypted(encryptedKey: string): boolean;
|
|
40
40
|
validateKey(key: string): boolean;
|
|
41
41
|
validateNameServiceDomainFormat(domainName: string): boolean;
|
|
42
|
-
generateAccountFromMnemonic(mnemonic: string[] | string, index: number): TBSAccount<N
|
|
43
|
-
generateAccountFromPublicKey(publicKey: string): TBSAccount<N
|
|
44
|
-
generateAccountFromKey(key: string): TBSAccount<N
|
|
42
|
+
generateAccountFromMnemonic(mnemonic: string[] | string, index: number): Promise<TBSAccount<N>>;
|
|
43
|
+
generateAccountFromPublicKey(publicKey: string): Promise<TBSAccount<N>>;
|
|
44
|
+
generateAccountFromKey(key: string): Promise<TBSAccount<N>>;
|
|
45
45
|
decrypt(encryptedKey: string, password: string): Promise<TBSAccount<N>>;
|
|
46
46
|
encrypt(key: string, password: string): Promise<string>;
|
|
47
47
|
calculateTransferFee(param: TTransferParam<N>): Promise<string>;
|
package/dist/BSNeo3.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
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
2
|
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
12
3
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
13
4
|
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");
|
|
@@ -50,7 +41,7 @@ class BSNeo3 {
|
|
|
50
41
|
this.claimToken = BSNeo3Constants_1.BSNeo3Constants.GAS_TOKEN;
|
|
51
42
|
this.availableNetworks = BSNeo3Constants_1.BSNeo3Constants.ALL_NETWORKS;
|
|
52
43
|
this.defaultNetwork = BSNeo3Constants_1.BSNeo3Constants.MAINNET_NETWORK;
|
|
53
|
-
this.setNetwork(network
|
|
44
|
+
this.setNetwork(network ?? this.defaultNetwork);
|
|
54
45
|
}
|
|
55
46
|
setNetwork(network) {
|
|
56
47
|
const rpcNetworkUrls = BSNeo3Constants_1.BSNeo3Constants.RPC_LIST_BY_NETWORK_ID[network.id] || [];
|
|
@@ -80,48 +71,44 @@ class BSNeo3 {
|
|
|
80
71
|
this.fullTransactionsDataService = new DoraFullTransactionsDataServiceNeo3_1.DoraFullTransactionsDataServiceNeo3(this);
|
|
81
72
|
}
|
|
82
73
|
// This method is done manually because we need to ensure that the request is aborted after timeout
|
|
83
|
-
pingNode(url) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
};
|
|
103
|
-
});
|
|
74
|
+
async pingNode(url) {
|
|
75
|
+
const abortController = new AbortController();
|
|
76
|
+
const timeout = setTimeout(() => {
|
|
77
|
+
abortController.abort();
|
|
78
|
+
}, 5000);
|
|
79
|
+
const timeStart = Date.now();
|
|
80
|
+
const response = await axios_1.default.post(url, {
|
|
81
|
+
jsonrpc: '2.0',
|
|
82
|
+
method: 'getblockcount',
|
|
83
|
+
params: [],
|
|
84
|
+
id: 1234,
|
|
85
|
+
}, { timeout: 5000, signal: abortController.signal });
|
|
86
|
+
clearTimeout(timeout);
|
|
87
|
+
const latency = Date.now() - timeStart;
|
|
88
|
+
return {
|
|
89
|
+
latency,
|
|
90
|
+
url,
|
|
91
|
+
height: response.data.result,
|
|
92
|
+
};
|
|
104
93
|
}
|
|
105
|
-
generateSigningCallback(account) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
if (
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const ledgerTransport = yield this.ledgerService.getLedgerTransport(account);
|
|
115
|
-
return {
|
|
116
|
-
neonJsAccount,
|
|
117
|
-
signingCallback: this.ledgerService.getSigningCallback(ledgerTransport, account),
|
|
118
|
-
};
|
|
119
|
-
}
|
|
94
|
+
async generateSigningCallback(account) {
|
|
95
|
+
const { wallet, api } = BSNeo3NeonJsSingletonHelper_1.BSNeo3NeonJsSingletonHelper.getInstance();
|
|
96
|
+
const neonJsAccount = new wallet.Account(account.key);
|
|
97
|
+
if (account.isHardware) {
|
|
98
|
+
if (!this.ledgerService.getLedgerTransport)
|
|
99
|
+
throw new Error('You must provide a getLedgerTransport function to use Ledger');
|
|
100
|
+
if (typeof account.bip44Path !== 'string')
|
|
101
|
+
throw new Error('Your account must have bip44 path to use Ledger');
|
|
102
|
+
const ledgerTransport = await this.ledgerService.getLedgerTransport(account);
|
|
120
103
|
return {
|
|
121
104
|
neonJsAccount,
|
|
122
|
-
signingCallback:
|
|
105
|
+
signingCallback: this.ledgerService.getSigningCallback(ledgerTransport, account),
|
|
123
106
|
};
|
|
124
|
-
}
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
neonJsAccount,
|
|
110
|
+
signingCallback: api.signWithAccount(neonJsAccount),
|
|
111
|
+
};
|
|
125
112
|
}
|
|
126
113
|
validateAddress(address) {
|
|
127
114
|
const { wallet } = BSNeo3NeonJsSingletonHelper_1.BSNeo3NeonJsSingletonHelper.getInstance();
|
|
@@ -138,7 +125,7 @@ class BSNeo3 {
|
|
|
138
125
|
validateNameServiceDomainFormat(domainName) {
|
|
139
126
|
return domainName.endsWith('.neo');
|
|
140
127
|
}
|
|
141
|
-
generateAccountFromMnemonic(mnemonic, index) {
|
|
128
|
+
async generateAccountFromMnemonic(mnemonic, index) {
|
|
142
129
|
const mnemonicStr = Array.isArray(mnemonic) ? mnemonic.join(' ') : mnemonic;
|
|
143
130
|
const bip44Path = this.bip44DerivationPath.replace('?', index.toString());
|
|
144
131
|
const key = blockchain_service_1.BSKeychainHelper.generateNeoPrivateKeyFromMnemonic(mnemonicStr, bip44Path);
|
|
@@ -146,7 +133,7 @@ class BSNeo3 {
|
|
|
146
133
|
const { address, WIF } = new wallet.Account(key);
|
|
147
134
|
return { address, key: WIF, type: 'wif', bip44Path, blockchain: this.name };
|
|
148
135
|
}
|
|
149
|
-
generateAccountFromPublicKey(publicKey) {
|
|
136
|
+
async generateAccountFromPublicKey(publicKey) {
|
|
150
137
|
const { wallet } = BSNeo3NeonJsSingletonHelper_1.BSNeo3NeonJsSingletonHelper.getInstance();
|
|
151
138
|
if (!wallet.isPublicKey(publicKey))
|
|
152
139
|
throw new Error('Invalid public key');
|
|
@@ -158,7 +145,7 @@ class BSNeo3 {
|
|
|
158
145
|
blockchain: this.name,
|
|
159
146
|
};
|
|
160
147
|
}
|
|
161
|
-
generateAccountFromKey(key) {
|
|
148
|
+
async generateAccountFromKey(key) {
|
|
162
149
|
const { wallet } = BSNeo3NeonJsSingletonHelper_1.BSNeo3NeonJsSingletonHelper.getInstance();
|
|
163
150
|
const type = wallet.isWIF(key) ? 'wif' : wallet.isPrivateKey(key) ? 'privateKey' : undefined;
|
|
164
151
|
if (!type)
|
|
@@ -166,107 +153,92 @@ class BSNeo3 {
|
|
|
166
153
|
const { address } = new wallet.Account(key);
|
|
167
154
|
return { address, key, type, blockchain: this.name };
|
|
168
155
|
}
|
|
169
|
-
decrypt(encryptedKey, password) {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
return this.generateAccountFromKey(key);
|
|
174
|
-
});
|
|
156
|
+
async decrypt(encryptedKey, password) {
|
|
157
|
+
const { wallet } = BSNeo3NeonJsSingletonHelper_1.BSNeo3NeonJsSingletonHelper.getInstance();
|
|
158
|
+
const key = await wallet.decrypt(encryptedKey, password);
|
|
159
|
+
return await this.generateAccountFromKey(key);
|
|
175
160
|
}
|
|
176
|
-
encrypt(key, password) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
161
|
+
async encrypt(key, password) {
|
|
162
|
+
const { wallet } = BSNeo3NeonJsSingletonHelper_1.BSNeo3NeonJsSingletonHelper.getInstance();
|
|
163
|
+
return await wallet.encrypt(key, password);
|
|
164
|
+
}
|
|
165
|
+
async calculateTransferFee(param) {
|
|
166
|
+
const { neonJsAccount } = await this.generateSigningCallback(param.senderAccount);
|
|
167
|
+
const { NeonInvoker } = BSNeo3NeonDappKitSingletonHelper_1.BSNeo3NeonDappKitSingletonHelper.getInstance();
|
|
168
|
+
const invoker = await NeonInvoker.init({
|
|
169
|
+
rpcAddress: this.network.url,
|
|
170
|
+
account: neonJsAccount,
|
|
180
171
|
});
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
const { NeonInvoker } = BSNeo3NeonDappKitSingletonHelper_1.BSNeo3NeonDappKitSingletonHelper.getInstance();
|
|
186
|
-
const invoker = yield NeonInvoker.init({
|
|
187
|
-
rpcAddress: this.network.url,
|
|
188
|
-
account: neonJsAccount,
|
|
189
|
-
});
|
|
190
|
-
const invocations = yield __classPrivateFieldGet(this, _BSNeo3_instances, "m", _BSNeo3_buildTransferInvocation).call(this, param, neonJsAccount);
|
|
191
|
-
const { total } = yield invoker.calculateFee({
|
|
192
|
-
invocations,
|
|
193
|
-
signers: [],
|
|
194
|
-
});
|
|
195
|
-
return total.toString();
|
|
172
|
+
const invocations = await __classPrivateFieldGet(this, _BSNeo3_instances, "m", _BSNeo3_buildTransferInvocation).call(this, param, neonJsAccount);
|
|
173
|
+
const { total } = await invoker.calculateFee({
|
|
174
|
+
invocations,
|
|
175
|
+
signers: [],
|
|
196
176
|
});
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
});
|
|
207
|
-
const invocations = yield __classPrivateFieldGet(this, _BSNeo3_instances, "m", _BSNeo3_buildTransferInvocation).call(this, param, neonJsAccount);
|
|
208
|
-
const transactionHash = yield invoker.invokeFunction({
|
|
209
|
-
invocations,
|
|
210
|
-
signers: [],
|
|
211
|
-
});
|
|
212
|
-
return param.intents.map(() => transactionHash);
|
|
177
|
+
return total.toString();
|
|
178
|
+
}
|
|
179
|
+
async transfer(param) {
|
|
180
|
+
const { neonJsAccount, signingCallback } = await this.generateSigningCallback(param.senderAccount);
|
|
181
|
+
const { NeonInvoker } = BSNeo3NeonDappKitSingletonHelper_1.BSNeo3NeonDappKitSingletonHelper.getInstance();
|
|
182
|
+
const invoker = await NeonInvoker.init({
|
|
183
|
+
rpcAddress: this.network.url,
|
|
184
|
+
account: neonJsAccount,
|
|
185
|
+
signingCallback: signingCallback,
|
|
213
186
|
});
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
187
|
+
const invocations = await __classPrivateFieldGet(this, _BSNeo3_instances, "m", _BSNeo3_buildTransferInvocation).call(this, param, neonJsAccount);
|
|
188
|
+
const transactionHash = await invoker.invokeFunction({
|
|
189
|
+
invocations,
|
|
190
|
+
signers: [],
|
|
191
|
+
});
|
|
192
|
+
return param.intents.map(() => transactionHash);
|
|
193
|
+
}
|
|
194
|
+
async claim(account) {
|
|
195
|
+
const { neonJsAccount, signingCallback } = await this.generateSigningCallback(account);
|
|
196
|
+
const { api } = BSNeo3NeonJsSingletonHelper_1.BSNeo3NeonJsSingletonHelper.getInstance();
|
|
197
|
+
const facade = await api.NetworkFacade.fromConfig({ node: this.network.url });
|
|
198
|
+
return await facade.claimGas(neonJsAccount, {
|
|
199
|
+
signingCallback: signingCallback,
|
|
223
200
|
});
|
|
224
201
|
}
|
|
225
|
-
resolveNameServiceDomain(domainName) {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
const parsed = NeonParser.parseRpcResponse(response.stack[0], {
|
|
243
|
-
type: 'Hash160',
|
|
244
|
-
});
|
|
245
|
-
return NeonParser.accountInputToAddress(parsed.replace('0x', ''));
|
|
202
|
+
async resolveNameServiceDomain(domainName) {
|
|
203
|
+
const { NeonParser, NeonInvoker } = BSNeo3NeonDappKitSingletonHelper_1.BSNeo3NeonDappKitSingletonHelper.getInstance();
|
|
204
|
+
const invoker = await NeonInvoker.init({ rpcAddress: this.network.url });
|
|
205
|
+
const response = await invoker.testInvoke({
|
|
206
|
+
invocations: [
|
|
207
|
+
{
|
|
208
|
+
scriptHash: BSNeo3Constants_1.BSNeo3Constants.NEO_NS_HASH,
|
|
209
|
+
operation: 'ownerOf',
|
|
210
|
+
args: [{ type: 'String', value: domainName }],
|
|
211
|
+
},
|
|
212
|
+
],
|
|
213
|
+
});
|
|
214
|
+
if (response.stack.length === 0) {
|
|
215
|
+
throw new Error(response.exception ?? 'unrecognized response');
|
|
216
|
+
}
|
|
217
|
+
const parsed = NeonParser.parseRpcResponse(response.stack[0], {
|
|
218
|
+
type: 'Hash160',
|
|
246
219
|
});
|
|
220
|
+
return NeonParser.accountInputToAddress(parsed.replace('0x', ''));
|
|
247
221
|
}
|
|
248
222
|
}
|
|
249
223
|
exports.BSNeo3 = BSNeo3;
|
|
250
224
|
_BSNeo3_instances = new WeakSet(), _BSNeo3_setTokens = function _BSNeo3_setTokens(network) {
|
|
251
225
|
this.tokens = BSNeo3Helper_1.BSNeo3Helper.getTokens(network);
|
|
252
|
-
}, _BSNeo3_buildTransferInvocation = function _BSNeo3_buildTransferInvocation(
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
return invocations;
|
|
271
|
-
});
|
|
226
|
+
}, _BSNeo3_buildTransferInvocation = async function _BSNeo3_buildTransferInvocation({ intents }, account) {
|
|
227
|
+
const invocations = [];
|
|
228
|
+
for (const intent of intents) {
|
|
229
|
+
invocations.push({
|
|
230
|
+
operation: 'transfer',
|
|
231
|
+
scriptHash: intent.token.hash,
|
|
232
|
+
args: [
|
|
233
|
+
{ type: 'Hash160', value: account.address },
|
|
234
|
+
{ type: 'Hash160', value: intent.receiverAddress },
|
|
235
|
+
{
|
|
236
|
+
type: 'Integer',
|
|
237
|
+
value: blockchain_service_1.BSBigNumberHelper.toDecimals(blockchain_service_1.BSBigNumberHelper.fromNumber(intent.amount), intent.token.decimals),
|
|
238
|
+
},
|
|
239
|
+
{ type: 'Any', value: null },
|
|
240
|
+
],
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
return invocations;
|
|
272
244
|
};
|
|
@@ -4,8 +4,7 @@ exports.BSNeo3Helper = void 0;
|
|
|
4
4
|
const BSNeo3Constants_1 = require("../constants/BSNeo3Constants");
|
|
5
5
|
class BSNeo3Helper {
|
|
6
6
|
static getTokens(network) {
|
|
7
|
-
|
|
8
|
-
const extraTokens = (_a = BSNeo3Constants_1.BSNeo3Constants.EXTRA_TOKENS_BY_NETWORK_ID[network.id]) !== null && _a !== void 0 ? _a : [];
|
|
7
|
+
const extraTokens = BSNeo3Constants_1.BSNeo3Constants.EXTRA_TOKENS_BY_NETWORK_ID[network.id] ?? [];
|
|
9
8
|
return [...extraTokens, ...BSNeo3Constants_1.BSNeo3Constants.NATIVE_ASSETS];
|
|
10
9
|
}
|
|
11
10
|
static isCustomNetwork(network) {
|