wative-core 1.2.2 → 2.2.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/CHANGELOG.md +136 -0
- package/LICENSE +55 -0
- package/README.md +496 -0
- package/dist/artifacts/evm/index.cjs +1 -0
- package/dist/artifacts/evm/index.d.cts +6 -0
- package/dist/artifacts/evm/index.d.ts +6 -0
- package/dist/artifacts/evm/index.js +1 -0
- package/dist/artifacts/svm/index.cjs +1 -0
- package/dist/artifacts/svm/index.d.cts +9 -0
- package/dist/artifacts/svm/index.d.ts +9 -0
- package/dist/artifacts/svm/index.js +1 -0
- package/dist/container-provider-C59yqd5Z.d.ts +48 -0
- package/dist/container-provider-i614LDE1.d.cts +48 -0
- package/dist/evm-BLml33LX.d.cts +34 -0
- package/dist/evm-DTzqGlL6.d.ts +34 -0
- package/dist/file-sink-B73MuigK.d.cts +44 -0
- package/dist/file-sink-LS4hyXXi.d.ts +44 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +194 -0
- package/dist/index.d.ts +194 -0
- package/dist/index.js +1 -0
- package/dist/index.node.cjs +1 -0
- package/dist/index.node.d.cts +6 -0
- package/dist/index.node.d.ts +6 -0
- package/dist/index.node.js +1 -0
- package/dist/node/index.cjs +1 -0
- package/dist/node/index.d.cts +7 -0
- package/dist/node/index.d.ts +7 -0
- package/dist/node/index.js +1 -0
- package/dist/svm-CCzqNAWM.d.cts +59 -0
- package/dist/svm-DieFbh9k.d.ts +59 -0
- package/dist/workspace-CamTHxso.d.cts +737 -0
- package/dist/workspace-CamTHxso.d.ts +737 -0
- package/package.json +85 -39
- package/tests/01-quick-start.test.cjs +37 -0
- package/tests/02-hd-account.test.cjs +71 -0
- package/tests/03-pk-account.test.cjs +59 -0
- package/tests/04-network-management.test.cjs +94 -0
- package/tests/05-asset-management.test.cjs +117 -0
- package/tests/06-address-signing.test.cjs +55 -0
- package/tests/07-custom-provider.test.cjs +164 -0
- package/tests/08-persistence.test.cjs +105 -0
- package/tests/09-workspace-filter.test.cjs +84 -0
- package/tests/10-default-network.test.cjs +70 -0
- package/tests/11-subpath-imports.test.cjs +21 -0
- package/tests/12-logger.test.cjs +44 -0
- package/tests/13-workspace-config.test.cjs +43 -0
- package/tests/14-esm-runtime.test.mjs +81 -0
- package/tests/15-package-resolution.test.cjs +76 -0
- package/tests/16-known-answer-vectors.test.cjs +141 -0
- package/tests/17-locked-state.test.cjs +162 -0
- package/tests/README.md +72 -0
- package/lib/account.d.ts +0 -69
- package/lib/index.d.ts +0 -6
- package/lib/index.esm.js +0 -1
- package/lib/index.umd.js +0 -1
- package/lib/mnemonic.d.ts +0 -3
- package/lib/utils.d.ts +0 -21
- package/src/account.ts +0 -749
- package/src/index.ts +0 -11
- package/src/mnemonic.ts +0 -2084
- package/src/utils.ts +0 -132
package/src/utils.ts
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import * as fs from "fs"
|
|
2
|
-
import * as path from "path"
|
|
3
|
-
import Web3 from 'web3';
|
|
4
|
-
|
|
5
|
-
import * as CryptoJS from "crypto-js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export interface Result {
|
|
9
|
-
status: boolean;
|
|
10
|
-
output: any;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const excutePromiseFunction = async (fn: Function, params: any): Promise<Result> => {
|
|
14
|
-
let result: Result;
|
|
15
|
-
try {
|
|
16
|
-
let gas_price = await fn(...params);
|
|
17
|
-
result = {
|
|
18
|
-
status: true,
|
|
19
|
-
output: gas_price
|
|
20
|
-
};
|
|
21
|
-
} catch (err: any) {
|
|
22
|
-
result = {
|
|
23
|
-
status: false,
|
|
24
|
-
output: err.toString()
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return result;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
export class EvmGasUtil {
|
|
32
|
-
private web3: any;
|
|
33
|
-
|
|
34
|
-
constructor(rpc_url: string) {
|
|
35
|
-
this.web3 = new Web3(rpc_url);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
public async getEvmGasPrice(): Promise<Result> {
|
|
39
|
-
let result: Result = await excutePromiseFunction(this.web3.eth.getGasPrice, []);
|
|
40
|
-
return result;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
public async getEvmGasLimit(tx_params: any, rpc_url: string): Promise<Result> {
|
|
44
|
-
let result: Result = await excutePromiseFunction(this.web3.eth.estimateGas, [tx_params, rpc_url]);
|
|
45
|
-
return result;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export const checkFileExistence = (file_path: string): boolean => {
|
|
50
|
-
file_path = file_path.trim()
|
|
51
|
-
return fs.existsSync(file_path);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export const checkAccountLabelsExistence = (setting_path: string, account_labels: string[]) => {
|
|
55
|
-
const account_labels_size = account_labels.length;
|
|
56
|
-
|
|
57
|
-
if (account_labels_size === 0) {
|
|
58
|
-
return true;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
for (let i = 0; i < account_labels_size; i++) {
|
|
62
|
-
const account_labels_path = path.join(setting_path, `accounts/${account_labels[i]}.json`);
|
|
63
|
-
if (!checkFileExistence(account_labels_path)) {
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return true;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export const getKeystoreSlugByAccountName = (account_name: string) => {
|
|
71
|
-
account_name = account_name.trim();
|
|
72
|
-
account_name = account_name.toLocaleLowerCase();
|
|
73
|
-
account_name = account_name.replace(/\s+/g, "-").trim();
|
|
74
|
-
account_name = account_name.replace(/\-+/g, "-").trim();
|
|
75
|
-
return account_name;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export const batchGetKeystoreSlugByAccountName = (account_name_list: string[]) => {
|
|
79
|
-
let keystore_slug_list: string[] = [];
|
|
80
|
-
for (let i = 0; i < account_name_list.length; i++) {
|
|
81
|
-
keystore_slug_list.push(
|
|
82
|
-
getKeystoreSlugByAccountName(account_name_list[i])
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
return keystore_slug_list;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
export const getAccountLabels = (setting_path: string, account_labels: string[]) => {
|
|
90
|
-
let result: any = [];
|
|
91
|
-
const config_path = path.join(setting_path, "network.json");
|
|
92
|
-
if (!checkFileExistence(config_path)) {
|
|
93
|
-
throw new Error("network.json not found");
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
let config = getJsonParams(config_path);
|
|
97
|
-
let _account_labels = config.accounts;
|
|
98
|
-
let keystore_slug = batchGetKeystoreSlugByAccountName(_account_labels);
|
|
99
|
-
|
|
100
|
-
for (let i = 0; i < account_labels.length; i++) {
|
|
101
|
-
if (keystore_slug.includes(account_labels[i])) {
|
|
102
|
-
result.push(account_labels[i]);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
return result;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export const getJsonParams = (jsonFilePath: string) => {
|
|
109
|
-
const jsonString = fs.readFileSync(jsonFilePath).toString();
|
|
110
|
-
const data = JSON.parse(jsonString);
|
|
111
|
-
return data;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export const setJsonParams = (data: any, jsonFilePath: string) => {
|
|
115
|
-
const jsonString = JSON.stringify(data);
|
|
116
|
-
fs.writeFileSync(jsonFilePath, jsonString);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export const encryptMessage = (message: string, password: string) => {
|
|
120
|
-
const ciphertext = CryptoJS.AES.encrypt(message, password).toString();
|
|
121
|
-
return ciphertext;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export const decryptMessage = (ciphertext: string, password: string) => {
|
|
125
|
-
const bytes = CryptoJS.AES.decrypt(ciphertext, password);
|
|
126
|
-
const originalText = bytes.toString(CryptoJS.enc.Utf8);
|
|
127
|
-
return originalText;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export const hexToUint8Array = (hex_string: string) => {
|
|
131
|
-
return new Uint8Array(hex_string.match(/.{1,2}/g)!.map((val) => parseInt(val, 16)));
|
|
132
|
-
}
|