@mybucks.online/core 1.0.5 → 1.0.6
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/README.md +6 -2
- package/index.js +14 -1
- package/package.json +3 -2
- package/test/index.test.js +28 -5
package/README.md
CHANGED
|
@@ -24,6 +24,7 @@ npm install @mybucks.online/core
|
|
|
24
24
|
import {
|
|
25
25
|
getEvmPrivateKey,
|
|
26
26
|
getEvmWalletAddress,
|
|
27
|
+
getTronWalletAddress,
|
|
27
28
|
generateHash
|
|
28
29
|
} from "@mybucks.online/core";
|
|
29
30
|
|
|
@@ -36,8 +37,11 @@ const hash = await generateHash(password, passcode, showProgress);
|
|
|
36
37
|
const privateKey = getEvmPrivateKey(hash);
|
|
37
38
|
console.log("Private key: ", privateKey);
|
|
38
39
|
|
|
39
|
-
const
|
|
40
|
-
console.log("Address: ",
|
|
40
|
+
const address1 = getEvmWalletAddress(hash);
|
|
41
|
+
console.log("EVM Address: ", address1);
|
|
42
|
+
|
|
43
|
+
const address2 = getTronWalletAddress(hash);
|
|
44
|
+
console.log("TRON Address: ", address2);
|
|
41
45
|
```
|
|
42
46
|
|
|
43
47
|
### 3. Generate and parse (transfer-link's)token
|
package/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import { Buffer } from "buffer";
|
|
|
2
2
|
import { ethers } from "ethers";
|
|
3
3
|
import scryptJS from "scrypt-js";
|
|
4
4
|
import { nanoid } from "nanoid";
|
|
5
|
+
import { TronWeb } from "tronweb";
|
|
5
6
|
|
|
6
7
|
const { scrypt } = scryptJS;
|
|
7
8
|
const abi = new ethers.AbiCoder();
|
|
@@ -59,10 +60,21 @@ export function getEvmPrivateKey(hash) {
|
|
|
59
60
|
* @returns address as string format
|
|
60
61
|
*/
|
|
61
62
|
export function getEvmWalletAddress(hash) {
|
|
62
|
-
const
|
|
63
|
+
const privateKey = getEvmPrivateKey(hash);
|
|
64
|
+
const wallet = new ethers.Wallet(privateKey);
|
|
63
65
|
return wallet.address;
|
|
64
66
|
}
|
|
65
67
|
|
|
68
|
+
/**
|
|
69
|
+
* This function returns the TRON wallet address from a result of the scrypt hash.
|
|
70
|
+
* @param {*} hash scrypt hash result
|
|
71
|
+
* @returns address as string format
|
|
72
|
+
*/
|
|
73
|
+
export function getTronWalletAddress(hash) {
|
|
74
|
+
const privateKey = getEvmPrivateKey(hash);
|
|
75
|
+
return TronWeb.address.fromPrivateKey(privateKey.slice(2));
|
|
76
|
+
}
|
|
77
|
+
|
|
66
78
|
const URL_DELIMITER = "\u0002";
|
|
67
79
|
const NETWORKS = [
|
|
68
80
|
"ethereum",
|
|
@@ -71,6 +83,7 @@ const NETWORKS = [
|
|
|
71
83
|
"optimism",
|
|
72
84
|
"bsc",
|
|
73
85
|
"avalanche",
|
|
86
|
+
"base",
|
|
74
87
|
"tron",
|
|
75
88
|
];
|
|
76
89
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mybucks.online/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "Core module for mybucks.online crypto wallet",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"buffer": "^6.0.3",
|
|
37
37
|
"ethers": "^6.13.5",
|
|
38
38
|
"nanoid": "^5.0.9",
|
|
39
|
-
"scrypt-js": "^3.0.1"
|
|
39
|
+
"scrypt-js": "^3.0.1",
|
|
40
|
+
"tronweb": "^6.0.1"
|
|
40
41
|
}
|
|
41
42
|
}
|
package/test/index.test.js
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
generateHash,
|
|
5
5
|
getEvmPrivateKey,
|
|
6
6
|
getEvmWalletAddress,
|
|
7
|
+
getTronWalletAddress,
|
|
7
8
|
generateToken,
|
|
8
9
|
parseToken,
|
|
9
10
|
} from "../index.js";
|
|
@@ -11,12 +12,15 @@ import {
|
|
|
11
12
|
const DEMO_PASSWORD = "DemoAccount5&";
|
|
12
13
|
const DEMO_PASSCODE = "112324";
|
|
13
14
|
const DEMO_NETWORK = "optimism";
|
|
15
|
+
|
|
14
16
|
const DEMO_HASH =
|
|
15
17
|
"af9a22d75f8f69d33fe8fc294e8f413219d9c75374dec07fda2e4a66868599609887a10e04981e17356d2c07432fc89c11089172fdf91c0015b9a4beef11e447";
|
|
16
18
|
const DEMO_PRIVATE_KEY =
|
|
17
19
|
"0x71743de900c63ed741263a2a4513c1b1829e80bd9f18d5d3a593e651b914cb3b";
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
+
const DEMO_WALLET_EVM_ADDRESS = "0x347CEB6Bf002Ee1819009bA07d8dCAA95Efe6465";
|
|
21
|
+
const DEMO_WALLET_TRON_ADDRESS = "TEkjnbpr2cTgRFgmrbv2Gb7GdgupZ5Sh3A";
|
|
22
|
+
|
|
23
|
+
const DEMO_TRANSFER_TOKEN =
|
|
20
24
|
"VWnsSGRGVtb0FjY291bnQ1JgIxMTIzMjQCb3B0aW1pc20=_wNovT";
|
|
21
25
|
|
|
22
26
|
describe("generateHash", () => {
|
|
@@ -45,23 +49,42 @@ describe("getEvmWalletAddress", () => {
|
|
|
45
49
|
const hash = await generateHash(DEMO_PASSWORD, DEMO_PASSCODE);
|
|
46
50
|
const address = getEvmWalletAddress(hash);
|
|
47
51
|
|
|
48
|
-
assert.strictEqual(address,
|
|
52
|
+
assert.strictEqual(address, DEMO_WALLET_EVM_ADDRESS);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe("getTronWalletAddress", () => {
|
|
57
|
+
test("should return a valid wallet address", async () => {
|
|
58
|
+
const hash = await generateHash(DEMO_PASSWORD, DEMO_PASSCODE);
|
|
59
|
+
const address = getTronWalletAddress(hash);
|
|
60
|
+
|
|
61
|
+
assert.strictEqual(address, DEMO_WALLET_TRON_ADDRESS);
|
|
49
62
|
});
|
|
50
63
|
});
|
|
51
64
|
|
|
52
65
|
describe("generateToken", () => {
|
|
53
|
-
test("should return null if password, passcode or network is invalid",
|
|
66
|
+
test("should return null if password, passcode or network is invalid", () => {
|
|
54
67
|
assert.strictEqual(generateToken("", "123345", "ethereum"), null);
|
|
55
68
|
assert.strictEqual(generateToken("", "123345"), null);
|
|
56
69
|
assert.strictEqual(generateToken("password", "", "ethereum"), null);
|
|
57
70
|
assert.strictEqual(generateToken("password", "123456", ""), null);
|
|
58
71
|
assert.strictEqual(generateToken("password", "123456", "invalid"), null);
|
|
59
72
|
});
|
|
73
|
+
|
|
74
|
+
test("should return valid token", async () => {
|
|
75
|
+
const token = generateToken(DEMO_PASSWORD, DEMO_PASSCODE, DEMO_NETWORK);
|
|
76
|
+
|
|
77
|
+
// The first and last 6 characters serve as random padding.
|
|
78
|
+
assert.strictEqual(
|
|
79
|
+
token.slice(6, token.length - 6),
|
|
80
|
+
DEMO_TRANSFER_TOKEN.slice(6, DEMO_TRANSFER_TOKEN.length - 6)
|
|
81
|
+
);
|
|
82
|
+
});
|
|
60
83
|
});
|
|
61
84
|
|
|
62
85
|
describe("parseToken", () => {
|
|
63
86
|
test("should return array of password, passcode, and network", () => {
|
|
64
|
-
const [password, passcode, network] = parseToken(
|
|
87
|
+
const [password, passcode, network] = parseToken(DEMO_TRANSFER_TOKEN);
|
|
65
88
|
|
|
66
89
|
assert.strictEqual(password, DEMO_PASSWORD);
|
|
67
90
|
assert.strictEqual(passcode, DEMO_PASSCODE);
|