@cityofzion/bs-neo3 0.7.3 → 0.9.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/.rush/temp/operation/build/all.log +1 -0
- package/.rush/temp/operation/build/state.json +1 -1
- package/.rush/temp/package-deps_build.json +9 -7
- package/.rush/temp/shrinkwrap-deps.json +354 -130
- package/CHANGELOG.json +22 -0
- package/CHANGELOG.md +11 -0
- package/bs-neo3.build.log +1 -2
- package/dist/BSNeo3.d.ts +29 -28
- package/dist/BSNeo3.js +187 -184
- package/dist/DoraBDSNeo3.d.ts +12 -12
- package/dist/DoraBDSNeo3.js +169 -169
- package/dist/DoraESNeo3.d.ts +7 -7
- package/dist/DoraESNeo3.js +19 -19
- package/dist/FlamingoEDSNeo3.d.ts +8 -8
- package/dist/FlamingoEDSNeo3.js +45 -44
- package/dist/GhostMarketNDSNeo3.d.ts +10 -10
- package/dist/GhostMarketNDSNeo3.js +75 -75
- package/dist/RpcBDSNeo3.d.ts +16 -16
- package/dist/RpcBDSNeo3.js +153 -153
- package/dist/assets/tokens/common.json +14 -14
- package/dist/assets/tokens/mainnet.json +116 -116
- package/dist/constants.d.ts +7 -7
- package/dist/constants.js +28 -28
- package/dist/index.d.ts +6 -6
- package/dist/index.js +22 -22
- package/jest.config.ts +13 -13
- package/jest.setup.ts +1 -1
- package/package.json +33 -32
- package/src/BSNeo3.ts +232 -228
- package/src/DoraBDSNeo3.ts +180 -180
- package/src/DoraESNeo3.ts +19 -19
- package/src/FlamingoEDSNeo3.ts +47 -45
- package/src/GhostMarketNDSNeo3.ts +117 -117
- package/src/RpcBDSNeo3.ts +157 -157
- package/src/__tests__/BDSNeo3.spec.ts +126 -126
- package/src/__tests__/BSNeo3.spec.ts +150 -142
- package/src/__tests__/DoraESNeo3.spec.ts +23 -23
- package/src/__tests__/FlamingoEDSNeo3.spec.ts +48 -45
- package/src/__tests__/GhostMarketNDSNeo3.spec.ts +43 -43
- package/src/__tests__/utils/sleep.ts +1 -1
- package/src/assets/tokens/common.json +13 -13
- package/src/assets/tokens/mainnet.json +115 -115
- package/src/constants.ts +29 -29
- package/src/index.ts +6 -6
- package/tsconfig.build.json +4 -4
- package/tsconfig.json +14 -14
- package/dist/BDSNeo3.d.ts +0 -15
- package/dist/BDSNeo3.js +0 -211
- package/dist/assets/tokens.json +0 -128
- package/dist/exceptions.d.ts +0 -3
- package/dist/exceptions.js +0 -8
- package/dist/explorer/dora/DoraNeo3Responses.d.ts +0 -174
- package/dist/explorer/dora/DoraNeo3Responses.js +0 -3
- package/dist/explorer/dora/DoraNeo3Routes.d.ts +0 -6
- package/dist/explorer/dora/DoraNeo3Routes.js +0 -9
- package/dist/explorer/index.d.ts +0 -6
- package/dist/explorer/index.js +0 -23
- package/docs/.nojekyll +0 -1
- package/docs/assets/highlight.css +0 -22
- package/docs/assets/main.js +0 -58
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1280
- package/docs/classes/BDSNeo3.html +0 -253
- package/docs/classes/BSNeo3.html +0 -442
- package/docs/index.html +0 -82
- package/docs/interfaces/DoraNeo3Abi.html +0 -78
- package/docs/interfaces/DoraNeo3Asset.html +0 -117
- package/docs/interfaces/DoraNeo3AssetState.html +0 -96
- package/docs/interfaces/DoraNeo3Balance.html +0 -89
- package/docs/interfaces/DoraNeo3ConsensusNode.html +0 -75
- package/docs/interfaces/DoraNeo3Contract.html +0 -110
- package/docs/interfaces/DoraNeo3Event.html +0 -75
- package/docs/interfaces/DoraNeo3Features.html +0 -84
- package/docs/interfaces/DoraNeo3HistoryState.html +0 -75
- package/docs/interfaces/DoraNeo3Invocation.html +0 -75
- package/docs/interfaces/DoraNeo3Item.html +0 -131
- package/docs/interfaces/DoraNeo3Manifest.html +0 -117
- package/docs/interfaces/DoraNeo3Metadata.html +0 -138
- package/docs/interfaces/DoraNeo3Method.html +0 -102
- package/docs/interfaces/DoraNeo3Nef.html +0 -103
- package/docs/interfaces/DoraNeo3Notification.html +0 -82
- package/docs/interfaces/DoraNeo3Parameter.html +0 -75
- package/docs/interfaces/DoraNeo3Permission.html +0 -75
- package/docs/interfaces/DoraNeo3Signer.html +0 -75
- package/docs/interfaces/DoraNeo3Token.html +0 -96
- package/docs/interfaces/DoraNeo3Transaction.html +0 -166
- package/docs/interfaces/DoraNeo3TransactionHistory.html +0 -75
- package/docs/interfaces/DoraNeo3Transfer.html +0 -117
- package/docs/interfaces/DoraNeo3Witness.html +0 -75
- package/docs/modules.html +0 -122
- package/docs/variables/DORA_ASSET.html +0 -81
- package/docs/variables/DORA_BALANCE.html +0 -81
- package/docs/variables/DORA_CONTRACT.html +0 -81
- package/docs/variables/DORA_NODES.html +0 -81
- package/docs/variables/DORA_TRANSACTION.html +0 -81
- package/docs/variables/DORA_TRANSACTIONS.html +0 -81
- package/docs/variables/explorerOptions.html +0 -86
- package/docs/variables/gasInfoNeo3.html +0 -90
- package/docs/variables/neoInfoNeo3.html +0 -90
package/CHANGELOG.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cityofzion/bs-neo3",
|
|
3
|
+
"entries": [
|
|
4
|
+
{
|
|
5
|
+
"version": "0.9.0",
|
|
6
|
+
"tag": "@cityofzion/bs-neo3_v0.9.0",
|
|
7
|
+
"date": "Tue, 05 Dec 2023 18:42:10 GMT",
|
|
8
|
+
"comments": {
|
|
9
|
+
"minor": [
|
|
10
|
+
{
|
|
11
|
+
"comment": "Inserted within the TokenPricesResponse type the token hash"
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"dependency": [
|
|
15
|
+
{
|
|
16
|
+
"comment": "Updating dependency \"@cityofzion/blockchain-service\" to `0.9.0`"
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
}
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Change Log - @cityofzion/bs-neo3
|
|
2
|
+
|
|
3
|
+
This log was last generated on Tue, 05 Dec 2023 18:42:10 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 0.9.0
|
|
6
|
+
Tue, 05 Dec 2023 18:42:10 GMT
|
|
7
|
+
|
|
8
|
+
### Minor changes
|
|
9
|
+
|
|
10
|
+
- Inserted within the TokenPricesResponse type the token hash
|
|
11
|
+
|
package/bs-neo3.build.log
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
Invoking: tsc --project tsconfig.build.json
|
|
2
|
-
|
|
1
|
+
Invoking: tsc --project tsconfig.build.json
|
package/dist/BSNeo3.d.ts
CHANGED
|
@@ -1,28 +1,29 @@
|
|
|
1
|
-
import { BlockchainDataService, BlockchainService, BSClaimable, Account, ExchangeDataService, BDSClaimable, Token, BSWithNameService, Network, PartialBy, TransferParam, BSCalculableFee, NftDataService, BSWithNft, AccountWithDerivationPath, BSWithExplorerService, ExplorerService } from '@cityofzion/blockchain-service';
|
|
2
|
-
export declare class BSNeo3<BSCustomName extends string = string> implements BlockchainService, BSClaimable, BSWithNameService, BSCalculableFee, BSWithNft, BSWithExplorerService {
|
|
3
|
-
readonly blockchainName: BSCustomName;
|
|
4
|
-
readonly feeToken: Token;
|
|
5
|
-
readonly claimToken: Token;
|
|
6
|
-
readonly burnToken: Token;
|
|
7
|
-
readonly derivationPath: string;
|
|
8
|
-
blockchainDataService: BlockchainDataService & BDSClaimable;
|
|
9
|
-
nftDataService: NftDataService;
|
|
10
|
-
exchangeDataService: ExchangeDataService;
|
|
11
|
-
explorerService: ExplorerService;
|
|
12
|
-
tokens: Token[];
|
|
13
|
-
network: Network;
|
|
14
|
-
constructor(blockchainName: BSCustomName, network: PartialBy<Network, 'url'>);
|
|
15
|
-
setNetwork(param: PartialBy<Network, 'url'>): void;
|
|
16
|
-
validateAddress(address: string): boolean;
|
|
17
|
-
validateEncrypted(encryptedKey: string): boolean;
|
|
18
|
-
validateKey(key: string): boolean;
|
|
19
|
-
validateNameServiceDomainFormat(domainName: string): boolean;
|
|
20
|
-
generateAccountFromMnemonic(mnemonic: string[] | string, index: number): AccountWithDerivationPath;
|
|
21
|
-
generateAccountFromKey(key: string): Account;
|
|
22
|
-
decrypt(encryptedKey: string, password: string): Promise<Account>;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
1
|
+
import { BlockchainDataService, BlockchainService, BSClaimable, Account, ExchangeDataService, BDSClaimable, Token, BSWithNameService, Network, PartialBy, TransferParam, BSCalculableFee, NftDataService, BSWithNft, AccountWithDerivationPath, BSWithExplorerService, ExplorerService } from '@cityofzion/blockchain-service';
|
|
2
|
+
export declare class BSNeo3<BSCustomName extends string = string> implements BlockchainService, BSClaimable, BSWithNameService, BSCalculableFee, BSWithNft, BSWithExplorerService {
|
|
3
|
+
readonly blockchainName: BSCustomName;
|
|
4
|
+
readonly feeToken: Token;
|
|
5
|
+
readonly claimToken: Token;
|
|
6
|
+
readonly burnToken: Token;
|
|
7
|
+
readonly derivationPath: string;
|
|
8
|
+
blockchainDataService: BlockchainDataService & BDSClaimable;
|
|
9
|
+
nftDataService: NftDataService;
|
|
10
|
+
exchangeDataService: ExchangeDataService;
|
|
11
|
+
explorerService: ExplorerService;
|
|
12
|
+
tokens: Token[];
|
|
13
|
+
network: Network;
|
|
14
|
+
constructor(blockchainName: BSCustomName, network: PartialBy<Network, 'url'>);
|
|
15
|
+
setNetwork(param: PartialBy<Network, 'url'>): void;
|
|
16
|
+
validateAddress(address: string): boolean;
|
|
17
|
+
validateEncrypted(encryptedKey: string): boolean;
|
|
18
|
+
validateKey(key: string): boolean;
|
|
19
|
+
validateNameServiceDomainFormat(domainName: string): boolean;
|
|
20
|
+
generateAccountFromMnemonic(mnemonic: string[] | string, index: number): AccountWithDerivationPath;
|
|
21
|
+
generateAccountFromKey(key: string): Account;
|
|
22
|
+
decrypt(encryptedKey: string, password: string): Promise<Account>;
|
|
23
|
+
encrypt(key: string, password: string): Promise<string>;
|
|
24
|
+
calculateTransferFee(param: TransferParam): Promise<string>;
|
|
25
|
+
transfer(param: TransferParam): Promise<string>;
|
|
26
|
+
claim(account: Account): Promise<string>;
|
|
27
|
+
resolveNameServiceDomain(domainName: string): Promise<any>;
|
|
28
|
+
private buildTransferInvocation;
|
|
29
|
+
}
|
package/dist/BSNeo3.js
CHANGED
|
@@ -1,184 +1,187 @@
|
|
|
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.BSNeo3 = void 0;
|
|
13
|
-
const neon_js_1 = require("@cityofzion/neon-js");
|
|
14
|
-
const neon_invoker_1 = require("@cityofzion/neon-invoker");
|
|
15
|
-
const neon_parser_1 = require("@cityofzion/neon-parser");
|
|
16
|
-
const neo3_parser_1 = require("@cityofzion/neo3-parser");
|
|
17
|
-
const RpcBDSNeo3_1 = require("./RpcBDSNeo3");
|
|
18
|
-
const DoraBDSNeo3_1 = require("./DoraBDSNeo3");
|
|
19
|
-
const constants_1 = require("./constants");
|
|
20
|
-
const FlamingoEDSNeo3_1 = require("./FlamingoEDSNeo3");
|
|
21
|
-
const GhostMarketNDSNeo3_1 = require("./GhostMarketNDSNeo3");
|
|
22
|
-
const bs_asteroid_sdk_1 = require("@cityofzion/bs-asteroid-sdk");
|
|
23
|
-
const DoraESNeo3_1 = require("./DoraESNeo3");
|
|
24
|
-
class BSNeo3 {
|
|
25
|
-
constructor(blockchainName, network) {
|
|
26
|
-
this.blockchainName = blockchainName;
|
|
27
|
-
this.tokens = constants_1.TOKENS[network.type];
|
|
28
|
-
this.derivationPath = constants_1.DERIVATION_PATH;
|
|
29
|
-
this.feeToken = this.tokens.find(token => token.symbol === 'GAS');
|
|
30
|
-
this.burnToken = this.tokens.find(token => token.symbol === 'NEO');
|
|
31
|
-
this.claimToken = this.tokens.find(token => token.symbol === 'GAS');
|
|
32
|
-
this.setNetwork(network);
|
|
33
|
-
}
|
|
34
|
-
setNetwork(param) {
|
|
35
|
-
var _a;
|
|
36
|
-
const network = {
|
|
37
|
-
type: param.type,
|
|
38
|
-
url: (_a = param.url) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_URL_BY_NETWORK_TYPE[param.type],
|
|
39
|
-
};
|
|
40
|
-
this.network = network;
|
|
41
|
-
if (network.type === 'custom') {
|
|
42
|
-
this.blockchainDataService = new RpcBDSNeo3_1.RPCBDSNeo3(network, this.feeToken, this.claimToken);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
this.blockchainDataService = new DoraBDSNeo3_1.DoraBDSNeo3(network, this.feeToken, this.claimToken);
|
|
46
|
-
}
|
|
47
|
-
this.exchangeDataService = new FlamingoEDSNeo3_1.FlamingoEDSNeo3(network.type);
|
|
48
|
-
this.nftDataService = new GhostMarketNDSNeo3_1.GhostMarketNDSNeo3(network.type);
|
|
49
|
-
this.explorerService = new DoraESNeo3_1.DoraESNeo3(network.type);
|
|
50
|
-
}
|
|
51
|
-
validateAddress(address) {
|
|
52
|
-
return neon_js_1.wallet.isAddress(address, 53);
|
|
53
|
-
}
|
|
54
|
-
validateEncrypted(encryptedKey) {
|
|
55
|
-
return neon_js_1.wallet.isNEP2(encryptedKey);
|
|
56
|
-
}
|
|
57
|
-
validateKey(key) {
|
|
58
|
-
return neon_js_1.wallet.isWIF(key) || neon_js_1.wallet.isPrivateKey(key);
|
|
59
|
-
}
|
|
60
|
-
validateNameServiceDomainFormat(domainName) {
|
|
61
|
-
if (!domainName.endsWith('.neo'))
|
|
62
|
-
return false;
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
65
|
-
generateAccountFromMnemonic(mnemonic, index) {
|
|
66
|
-
bs_asteroid_sdk_1.keychain.importMnemonic(Array.isArray(mnemonic) ? mnemonic.join(' ') : mnemonic);
|
|
67
|
-
const path = this.derivationPath.replace('?', index.toString());
|
|
68
|
-
const childKey = bs_asteroid_sdk_1.keychain.generateChildKey('neo', path);
|
|
69
|
-
const key = childKey.getWIF();
|
|
70
|
-
const { address } = new neon_js_1.wallet.Account(key);
|
|
71
|
-
return { address, key, type: 'wif', derivationPath: path };
|
|
72
|
-
}
|
|
73
|
-
generateAccountFromKey(key) {
|
|
74
|
-
const type = neon_js_1.wallet.isWIF(key) ? 'wif' : neon_js_1.wallet.isPrivateKey(key) ? 'privateKey' : undefined;
|
|
75
|
-
if (!type)
|
|
76
|
-
throw new Error('Invalid key');
|
|
77
|
-
const { address } = new neon_js_1.wallet.Account(key);
|
|
78
|
-
return { address, key, type };
|
|
79
|
-
}
|
|
80
|
-
decrypt(encryptedKey, password) {
|
|
81
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
-
let BsReactNativeDecrypt;
|
|
83
|
-
try {
|
|
84
|
-
const { NativeModules } = require('react-native');
|
|
85
|
-
BsReactNativeDecrypt = NativeModules.BsReactNativeDecrypt;
|
|
86
|
-
}
|
|
87
|
-
catch (_a) {
|
|
88
|
-
const key = yield neon_js_1.wallet.decrypt(encryptedKey, password);
|
|
89
|
-
return this.generateAccountFromKey(key);
|
|
90
|
-
}
|
|
91
|
-
if (!BsReactNativeDecrypt) {
|
|
92
|
-
throw new Error('@CityOfZion/bs-react-native-decrypt is not installed');
|
|
93
|
-
}
|
|
94
|
-
const privateKey = yield BsReactNativeDecrypt.decryptNeo3(encryptedKey, password);
|
|
95
|
-
return this.generateAccountFromKey(privateKey);
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
|
|
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.BSNeo3 = void 0;
|
|
13
|
+
const neon_js_1 = require("@cityofzion/neon-js");
|
|
14
|
+
const neon_invoker_1 = require("@cityofzion/neon-invoker");
|
|
15
|
+
const neon_parser_1 = require("@cityofzion/neon-parser");
|
|
16
|
+
const neo3_parser_1 = require("@cityofzion/neo3-parser");
|
|
17
|
+
const RpcBDSNeo3_1 = require("./RpcBDSNeo3");
|
|
18
|
+
const DoraBDSNeo3_1 = require("./DoraBDSNeo3");
|
|
19
|
+
const constants_1 = require("./constants");
|
|
20
|
+
const FlamingoEDSNeo3_1 = require("./FlamingoEDSNeo3");
|
|
21
|
+
const GhostMarketNDSNeo3_1 = require("./GhostMarketNDSNeo3");
|
|
22
|
+
const bs_asteroid_sdk_1 = require("@cityofzion/bs-asteroid-sdk");
|
|
23
|
+
const DoraESNeo3_1 = require("./DoraESNeo3");
|
|
24
|
+
class BSNeo3 {
|
|
25
|
+
constructor(blockchainName, network) {
|
|
26
|
+
this.blockchainName = blockchainName;
|
|
27
|
+
this.tokens = constants_1.TOKENS[network.type];
|
|
28
|
+
this.derivationPath = constants_1.DERIVATION_PATH;
|
|
29
|
+
this.feeToken = this.tokens.find(token => token.symbol === 'GAS');
|
|
30
|
+
this.burnToken = this.tokens.find(token => token.symbol === 'NEO');
|
|
31
|
+
this.claimToken = this.tokens.find(token => token.symbol === 'GAS');
|
|
32
|
+
this.setNetwork(network);
|
|
33
|
+
}
|
|
34
|
+
setNetwork(param) {
|
|
35
|
+
var _a;
|
|
36
|
+
const network = {
|
|
37
|
+
type: param.type,
|
|
38
|
+
url: (_a = param.url) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_URL_BY_NETWORK_TYPE[param.type],
|
|
39
|
+
};
|
|
40
|
+
this.network = network;
|
|
41
|
+
if (network.type === 'custom') {
|
|
42
|
+
this.blockchainDataService = new RpcBDSNeo3_1.RPCBDSNeo3(network, this.feeToken, this.claimToken);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
this.blockchainDataService = new DoraBDSNeo3_1.DoraBDSNeo3(network, this.feeToken, this.claimToken);
|
|
46
|
+
}
|
|
47
|
+
this.exchangeDataService = new FlamingoEDSNeo3_1.FlamingoEDSNeo3(network.type);
|
|
48
|
+
this.nftDataService = new GhostMarketNDSNeo3_1.GhostMarketNDSNeo3(network.type);
|
|
49
|
+
this.explorerService = new DoraESNeo3_1.DoraESNeo3(network.type);
|
|
50
|
+
}
|
|
51
|
+
validateAddress(address) {
|
|
52
|
+
return neon_js_1.wallet.isAddress(address, 53);
|
|
53
|
+
}
|
|
54
|
+
validateEncrypted(encryptedKey) {
|
|
55
|
+
return neon_js_1.wallet.isNEP2(encryptedKey);
|
|
56
|
+
}
|
|
57
|
+
validateKey(key) {
|
|
58
|
+
return neon_js_1.wallet.isWIF(key) || neon_js_1.wallet.isPrivateKey(key);
|
|
59
|
+
}
|
|
60
|
+
validateNameServiceDomainFormat(domainName) {
|
|
61
|
+
if (!domainName.endsWith('.neo'))
|
|
62
|
+
return false;
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
generateAccountFromMnemonic(mnemonic, index) {
|
|
66
|
+
bs_asteroid_sdk_1.keychain.importMnemonic(Array.isArray(mnemonic) ? mnemonic.join(' ') : mnemonic);
|
|
67
|
+
const path = this.derivationPath.replace('?', index.toString());
|
|
68
|
+
const childKey = bs_asteroid_sdk_1.keychain.generateChildKey('neo', path);
|
|
69
|
+
const key = childKey.getWIF();
|
|
70
|
+
const { address } = new neon_js_1.wallet.Account(key);
|
|
71
|
+
return { address, key, type: 'wif', derivationPath: path };
|
|
72
|
+
}
|
|
73
|
+
generateAccountFromKey(key) {
|
|
74
|
+
const type = neon_js_1.wallet.isWIF(key) ? 'wif' : neon_js_1.wallet.isPrivateKey(key) ? 'privateKey' : undefined;
|
|
75
|
+
if (!type)
|
|
76
|
+
throw new Error('Invalid key');
|
|
77
|
+
const { address } = new neon_js_1.wallet.Account(key);
|
|
78
|
+
return { address, key, type };
|
|
79
|
+
}
|
|
80
|
+
decrypt(encryptedKey, password) {
|
|
81
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
let BsReactNativeDecrypt;
|
|
83
|
+
try {
|
|
84
|
+
const { NativeModules } = require('react-native');
|
|
85
|
+
BsReactNativeDecrypt = NativeModules.BsReactNativeDecrypt;
|
|
86
|
+
}
|
|
87
|
+
catch (_a) {
|
|
88
|
+
const key = yield neon_js_1.wallet.decrypt(encryptedKey, password);
|
|
89
|
+
return this.generateAccountFromKey(key);
|
|
90
|
+
}
|
|
91
|
+
if (!BsReactNativeDecrypt) {
|
|
92
|
+
throw new Error('@CityOfZion/bs-react-native-decrypt is not installed');
|
|
93
|
+
}
|
|
94
|
+
const privateKey = yield BsReactNativeDecrypt.decryptNeo3(encryptedKey, password);
|
|
95
|
+
return this.generateAccountFromKey(privateKey);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
encrypt(key, password) {
|
|
99
|
+
return neon_js_1.wallet.encrypt(key, password);
|
|
100
|
+
}
|
|
101
|
+
calculateTransferFee(param) {
|
|
102
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
const account = new neon_js_1.wallet.Account(param.senderAccount.key);
|
|
104
|
+
const invoker = yield neon_invoker_1.NeonInvoker.init({
|
|
105
|
+
rpcAddress: this.network.url,
|
|
106
|
+
account,
|
|
107
|
+
});
|
|
108
|
+
const invocations = this.buildTransferInvocation(param, account);
|
|
109
|
+
const { networkFee, systemFee } = yield invoker.calculateFee({
|
|
110
|
+
invocations,
|
|
111
|
+
signers: [],
|
|
112
|
+
});
|
|
113
|
+
return networkFee.add(systemFee).toDecimal(this.feeToken.decimals);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
transfer(param) {
|
|
117
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
+
const account = new neon_js_1.wallet.Account(param.senderAccount.key);
|
|
119
|
+
const invoker = yield neon_invoker_1.NeonInvoker.init({
|
|
120
|
+
rpcAddress: this.network.url,
|
|
121
|
+
account,
|
|
122
|
+
});
|
|
123
|
+
const invocations = this.buildTransferInvocation(param, account);
|
|
124
|
+
const transactionHash = yield invoker.invokeFunction({
|
|
125
|
+
invocations,
|
|
126
|
+
signers: [],
|
|
127
|
+
});
|
|
128
|
+
return transactionHash;
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
claim(account) {
|
|
132
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
133
|
+
const neoAccount = new neon_js_1.wallet.Account(account.key);
|
|
134
|
+
const facade = yield neon_js_1.api.NetworkFacade.fromConfig({ node: this.network.url });
|
|
135
|
+
const transactionHash = yield facade.claimGas(neoAccount, {
|
|
136
|
+
signingCallback: neon_js_1.api.signWithAccount(neoAccount),
|
|
137
|
+
});
|
|
138
|
+
return transactionHash;
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
resolveNameServiceDomain(domainName) {
|
|
142
|
+
var _a;
|
|
143
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
144
|
+
const parser = neon_parser_1.NeonParser;
|
|
145
|
+
const invoker = yield neon_invoker_1.NeonInvoker.init({ rpcAddress: this.network.url });
|
|
146
|
+
const response = yield invoker.testInvoke({
|
|
147
|
+
invocations: [
|
|
148
|
+
{
|
|
149
|
+
scriptHash: constants_1.NEO_NS_HASH,
|
|
150
|
+
operation: 'ownerOf',
|
|
151
|
+
args: [{ type: 'String', value: domainName }],
|
|
152
|
+
},
|
|
153
|
+
],
|
|
154
|
+
});
|
|
155
|
+
if (response.stack.length === 0) {
|
|
156
|
+
throw new Error((_a = response.exception) !== null && _a !== void 0 ? _a : 'unrecognized response');
|
|
157
|
+
}
|
|
158
|
+
const parsed = parser.parseRpcResponse(response.stack[0], {
|
|
159
|
+
type: neo3_parser_1.ABI_TYPES.HASH160.name,
|
|
160
|
+
});
|
|
161
|
+
const address = parser.accountInputToAddress(parsed.replace('0x', ''));
|
|
162
|
+
return address;
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
buildTransferInvocation({ intent, tipIntent }, account) {
|
|
166
|
+
const intents = [intent, ...(tipIntent ? [tipIntent] : [])];
|
|
167
|
+
const invocations = intents.map(intent => {
|
|
168
|
+
return {
|
|
169
|
+
operation: 'transfer',
|
|
170
|
+
scriptHash: intent.tokenHash,
|
|
171
|
+
args: [
|
|
172
|
+
{ type: 'Hash160', value: account.address },
|
|
173
|
+
{ type: 'Hash160', value: intent.receiverAddress },
|
|
174
|
+
{
|
|
175
|
+
type: 'Integer',
|
|
176
|
+
value: intent.tokenDecimals
|
|
177
|
+
? neon_js_1.u.BigInteger.fromDecimal(intent.amount, intent.tokenDecimals).toString()
|
|
178
|
+
: intent.amount,
|
|
179
|
+
},
|
|
180
|
+
{ type: 'Any', value: '' },
|
|
181
|
+
],
|
|
182
|
+
};
|
|
183
|
+
});
|
|
184
|
+
return invocations;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
exports.BSNeo3 = BSNeo3;
|
package/dist/DoraBDSNeo3.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { BalanceResponse, ContractResponse, TransactionsByAddressParams, TransactionsByAddressResponse, TransactionResponse, Network, Token } from '@cityofzion/blockchain-service';
|
|
2
|
-
import { RPCBDSNeo3 } from './RpcBDSNeo3';
|
|
3
|
-
export declare class DoraBDSNeo3 extends RPCBDSNeo3 {
|
|
4
|
-
readonly network: Network;
|
|
5
|
-
constructor(network: Network, feeToken: Token, claimToken: Token);
|
|
6
|
-
getTransaction(hash: string): Promise<TransactionResponse>;
|
|
7
|
-
getTransactionsByAddress({ address, page, }: TransactionsByAddressParams): Promise<TransactionsByAddressResponse>;
|
|
8
|
-
getContract(contractHash: string): Promise<ContractResponse>;
|
|
9
|
-
getTokenInfo(tokenHash: string): Promise<Token>;
|
|
10
|
-
getBalance(address: string): Promise<BalanceResponse[]>;
|
|
11
|
-
private convertByteStringToAddress;
|
|
12
|
-
}
|
|
1
|
+
import { BalanceResponse, ContractResponse, TransactionsByAddressParams, TransactionsByAddressResponse, TransactionResponse, Network, Token } from '@cityofzion/blockchain-service';
|
|
2
|
+
import { RPCBDSNeo3 } from './RpcBDSNeo3';
|
|
3
|
+
export declare class DoraBDSNeo3 extends RPCBDSNeo3 {
|
|
4
|
+
readonly network: Network;
|
|
5
|
+
constructor(network: Network, feeToken: Token, claimToken: Token);
|
|
6
|
+
getTransaction(hash: string): Promise<TransactionResponse>;
|
|
7
|
+
getTransactionsByAddress({ address, page, }: TransactionsByAddressParams): Promise<TransactionsByAddressResponse>;
|
|
8
|
+
getContract(contractHash: string): Promise<ContractResponse>;
|
|
9
|
+
getTokenInfo(tokenHash: string): Promise<Token>;
|
|
10
|
+
getBalance(address: string): Promise<BalanceResponse[]>;
|
|
11
|
+
private convertByteStringToAddress;
|
|
12
|
+
}
|