@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.
Files changed (99) hide show
  1. package/.rush/temp/operation/build/all.log +1 -0
  2. package/.rush/temp/operation/build/state.json +1 -1
  3. package/.rush/temp/package-deps_build.json +9 -7
  4. package/.rush/temp/shrinkwrap-deps.json +354 -130
  5. package/CHANGELOG.json +22 -0
  6. package/CHANGELOG.md +11 -0
  7. package/bs-neo3.build.log +1 -2
  8. package/dist/BSNeo3.d.ts +29 -28
  9. package/dist/BSNeo3.js +187 -184
  10. package/dist/DoraBDSNeo3.d.ts +12 -12
  11. package/dist/DoraBDSNeo3.js +169 -169
  12. package/dist/DoraESNeo3.d.ts +7 -7
  13. package/dist/DoraESNeo3.js +19 -19
  14. package/dist/FlamingoEDSNeo3.d.ts +8 -8
  15. package/dist/FlamingoEDSNeo3.js +45 -44
  16. package/dist/GhostMarketNDSNeo3.d.ts +10 -10
  17. package/dist/GhostMarketNDSNeo3.js +75 -75
  18. package/dist/RpcBDSNeo3.d.ts +16 -16
  19. package/dist/RpcBDSNeo3.js +153 -153
  20. package/dist/assets/tokens/common.json +14 -14
  21. package/dist/assets/tokens/mainnet.json +116 -116
  22. package/dist/constants.d.ts +7 -7
  23. package/dist/constants.js +28 -28
  24. package/dist/index.d.ts +6 -6
  25. package/dist/index.js +22 -22
  26. package/jest.config.ts +13 -13
  27. package/jest.setup.ts +1 -1
  28. package/package.json +33 -32
  29. package/src/BSNeo3.ts +232 -228
  30. package/src/DoraBDSNeo3.ts +180 -180
  31. package/src/DoraESNeo3.ts +19 -19
  32. package/src/FlamingoEDSNeo3.ts +47 -45
  33. package/src/GhostMarketNDSNeo3.ts +117 -117
  34. package/src/RpcBDSNeo3.ts +157 -157
  35. package/src/__tests__/BDSNeo3.spec.ts +126 -126
  36. package/src/__tests__/BSNeo3.spec.ts +150 -142
  37. package/src/__tests__/DoraESNeo3.spec.ts +23 -23
  38. package/src/__tests__/FlamingoEDSNeo3.spec.ts +48 -45
  39. package/src/__tests__/GhostMarketNDSNeo3.spec.ts +43 -43
  40. package/src/__tests__/utils/sleep.ts +1 -1
  41. package/src/assets/tokens/common.json +13 -13
  42. package/src/assets/tokens/mainnet.json +115 -115
  43. package/src/constants.ts +29 -29
  44. package/src/index.ts +6 -6
  45. package/tsconfig.build.json +4 -4
  46. package/tsconfig.json +14 -14
  47. package/dist/BDSNeo3.d.ts +0 -15
  48. package/dist/BDSNeo3.js +0 -211
  49. package/dist/assets/tokens.json +0 -128
  50. package/dist/exceptions.d.ts +0 -3
  51. package/dist/exceptions.js +0 -8
  52. package/dist/explorer/dora/DoraNeo3Responses.d.ts +0 -174
  53. package/dist/explorer/dora/DoraNeo3Responses.js +0 -3
  54. package/dist/explorer/dora/DoraNeo3Routes.d.ts +0 -6
  55. package/dist/explorer/dora/DoraNeo3Routes.js +0 -9
  56. package/dist/explorer/index.d.ts +0 -6
  57. package/dist/explorer/index.js +0 -23
  58. package/docs/.nojekyll +0 -1
  59. package/docs/assets/highlight.css +0 -22
  60. package/docs/assets/main.js +0 -58
  61. package/docs/assets/search.js +0 -1
  62. package/docs/assets/style.css +0 -1280
  63. package/docs/classes/BDSNeo3.html +0 -253
  64. package/docs/classes/BSNeo3.html +0 -442
  65. package/docs/index.html +0 -82
  66. package/docs/interfaces/DoraNeo3Abi.html +0 -78
  67. package/docs/interfaces/DoraNeo3Asset.html +0 -117
  68. package/docs/interfaces/DoraNeo3AssetState.html +0 -96
  69. package/docs/interfaces/DoraNeo3Balance.html +0 -89
  70. package/docs/interfaces/DoraNeo3ConsensusNode.html +0 -75
  71. package/docs/interfaces/DoraNeo3Contract.html +0 -110
  72. package/docs/interfaces/DoraNeo3Event.html +0 -75
  73. package/docs/interfaces/DoraNeo3Features.html +0 -84
  74. package/docs/interfaces/DoraNeo3HistoryState.html +0 -75
  75. package/docs/interfaces/DoraNeo3Invocation.html +0 -75
  76. package/docs/interfaces/DoraNeo3Item.html +0 -131
  77. package/docs/interfaces/DoraNeo3Manifest.html +0 -117
  78. package/docs/interfaces/DoraNeo3Metadata.html +0 -138
  79. package/docs/interfaces/DoraNeo3Method.html +0 -102
  80. package/docs/interfaces/DoraNeo3Nef.html +0 -103
  81. package/docs/interfaces/DoraNeo3Notification.html +0 -82
  82. package/docs/interfaces/DoraNeo3Parameter.html +0 -75
  83. package/docs/interfaces/DoraNeo3Permission.html +0 -75
  84. package/docs/interfaces/DoraNeo3Signer.html +0 -75
  85. package/docs/interfaces/DoraNeo3Token.html +0 -96
  86. package/docs/interfaces/DoraNeo3Transaction.html +0 -166
  87. package/docs/interfaces/DoraNeo3TransactionHistory.html +0 -75
  88. package/docs/interfaces/DoraNeo3Transfer.html +0 -117
  89. package/docs/interfaces/DoraNeo3Witness.html +0 -75
  90. package/docs/modules.html +0 -122
  91. package/docs/variables/DORA_ASSET.html +0 -81
  92. package/docs/variables/DORA_BALANCE.html +0 -81
  93. package/docs/variables/DORA_CONTRACT.html +0 -81
  94. package/docs/variables/DORA_NODES.html +0 -81
  95. package/docs/variables/DORA_TRANSACTION.html +0 -81
  96. package/docs/variables/DORA_TRANSACTIONS.html +0 -81
  97. package/docs/variables/explorerOptions.html +0 -86
  98. package/docs/variables/gasInfoNeo3.html +0 -90
  99. 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
- calculateTransferFee(param: TransferParam): Promise<string>;
24
- transfer(param: TransferParam): Promise<string>;
25
- claim(account: Account): Promise<string>;
26
- resolveNameServiceDomain(domainName: string): Promise<any>;
27
- private buildTransferInvocation;
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
- calculateTransferFee(param) {
99
- return __awaiter(this, void 0, void 0, function* () {
100
- const account = new neon_js_1.wallet.Account(param.senderAccount.key);
101
- const invoker = yield neon_invoker_1.NeonInvoker.init({
102
- rpcAddress: this.network.url,
103
- account,
104
- });
105
- const invocations = this.buildTransferInvocation(param, account);
106
- const { networkFee, systemFee } = yield invoker.calculateFee({
107
- invocations,
108
- signers: [],
109
- });
110
- return networkFee.add(systemFee).toDecimal(this.feeToken.decimals);
111
- });
112
- }
113
- transfer(param) {
114
- return __awaiter(this, void 0, void 0, function* () {
115
- const account = new neon_js_1.wallet.Account(param.senderAccount.key);
116
- const invoker = yield neon_invoker_1.NeonInvoker.init({
117
- rpcAddress: this.network.url,
118
- account,
119
- });
120
- const invocations = this.buildTransferInvocation(param, account);
121
- const transactionHash = yield invoker.invokeFunction({
122
- invocations,
123
- signers: [],
124
- });
125
- return transactionHash;
126
- });
127
- }
128
- claim(account) {
129
- return __awaiter(this, void 0, void 0, function* () {
130
- const neoAccount = new neon_js_1.wallet.Account(account.key);
131
- const facade = yield neon_js_1.api.NetworkFacade.fromConfig({ node: this.network.url });
132
- const transactionHash = yield facade.claimGas(neoAccount, {
133
- signingCallback: neon_js_1.api.signWithAccount(neoAccount),
134
- });
135
- return transactionHash;
136
- });
137
- }
138
- resolveNameServiceDomain(domainName) {
139
- var _a;
140
- return __awaiter(this, void 0, void 0, function* () {
141
- const parser = neon_parser_1.NeonParser;
142
- const invoker = yield neon_invoker_1.NeonInvoker.init({ rpcAddress: this.network.url });
143
- const response = yield invoker.testInvoke({
144
- invocations: [
145
- {
146
- scriptHash: constants_1.NEO_NS_HASH,
147
- operation: 'ownerOf',
148
- args: [{ type: 'String', value: domainName }],
149
- },
150
- ],
151
- });
152
- if (response.stack.length === 0) {
153
- throw new Error((_a = response.exception) !== null && _a !== void 0 ? _a : 'unrecognized response');
154
- }
155
- const parsed = parser.parseRpcResponse(response.stack[0], {
156
- type: neo3_parser_1.ABI_TYPES.HASH160.name,
157
- });
158
- const address = parser.accountInputToAddress(parsed.replace('0x', ''));
159
- return address;
160
- });
161
- }
162
- buildTransferInvocation({ intent, tipIntent }, account) {
163
- const intents = [intent, ...(tipIntent ? [tipIntent] : [])];
164
- const invocations = intents.map(intent => {
165
- return {
166
- operation: 'transfer',
167
- scriptHash: intent.tokenHash,
168
- args: [
169
- { type: 'Hash160', value: account.address },
170
- { type: 'Hash160', value: intent.receiverAddress },
171
- {
172
- type: 'Integer',
173
- value: intent.tokenDecimals
174
- ? neon_js_1.u.BigInteger.fromDecimal(intent.amount, intent.tokenDecimals).toString()
175
- : intent.amount,
176
- },
177
- { type: 'Any', value: '' },
178
- ],
179
- };
180
- });
181
- return invocations;
182
- }
183
- }
184
- exports.BSNeo3 = BSNeo3;
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;
@@ -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
+ }