@mybucks.online/core 1.0.4 → 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 +15 -3
- package/index.js +26 -3
- package/package.json +3 -2
- package/test/index.test.js +37 -3
package/README.md
CHANGED
|
@@ -18,19 +18,30 @@ It fully runs on your **browser side** without using any storage or invoking any
|
|
|
18
18
|
npm install @mybucks.online/core
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
### 2. Generate hash
|
|
21
|
+
### 2. Generate hash, private-key and wallet address
|
|
22
22
|
|
|
23
23
|
```javascript
|
|
24
|
-
import {
|
|
24
|
+
import {
|
|
25
|
+
getEvmPrivateKey,
|
|
26
|
+
getEvmWalletAddress,
|
|
27
|
+
getTronWalletAddress,
|
|
28
|
+
generateHash
|
|
29
|
+
} from "@mybucks.online/core";
|
|
25
30
|
|
|
26
31
|
const showProgress = (p) => {
|
|
27
32
|
console.log(`progress: ${p * 100}%`);
|
|
28
33
|
};
|
|
29
34
|
|
|
30
35
|
const hash = await generateHash(password, passcode, showProgress);
|
|
31
|
-
const privateKey = getEvmPrivateKey(hash);
|
|
32
36
|
|
|
37
|
+
const privateKey = getEvmPrivateKey(hash);
|
|
33
38
|
console.log("Private key: ", privateKey);
|
|
39
|
+
|
|
40
|
+
const address1 = getEvmWalletAddress(hash);
|
|
41
|
+
console.log("EVM Address: ", address1);
|
|
42
|
+
|
|
43
|
+
const address2 = getTronWalletAddress(hash);
|
|
44
|
+
console.log("TRON Address: ", address2);
|
|
34
45
|
```
|
|
35
46
|
|
|
36
47
|
### 3. Generate and parse (transfer-link's)token
|
|
@@ -64,3 +75,4 @@ Find the docs [here](https://docs.mybucks.online).
|
|
|
64
75
|
password: **DemoAccount5&**
|
|
65
76
|
passcode: **112324**
|
|
66
77
|
- https://app.mybucks.online/?wallet=VWnsSGRGVtb0FjY291bnQ1JgIxMTIzMjQCb3B0aW1pc20=_wNovT
|
|
78
|
+
- https://app.mybucks.online/?wallet=1jpFD8RGVtb0FjY291bnQ1JgIxMTIzMjQCYmFzZQ==fhk-GL
|
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();
|
|
@@ -45,14 +46,35 @@ export async function generateHash(password, passcode, cb = () => {}) {
|
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
/**
|
|
48
|
-
* This function derives the EVM private key from
|
|
49
|
-
* @param {*} hash
|
|
49
|
+
* This function derives the EVM private key from a result of the scrypt hash.
|
|
50
|
+
* @param {*} hash scrypt hash result
|
|
50
51
|
* @returns private key as string format
|
|
51
52
|
*/
|
|
52
53
|
export function getEvmPrivateKey(hash) {
|
|
53
54
|
return ethers.keccak256(abi.encode(["string"], [hash]));
|
|
54
55
|
}
|
|
55
56
|
|
|
57
|
+
/**
|
|
58
|
+
* This function returns the EVM wallet address from a result of the scrypt hash.
|
|
59
|
+
* @param {*} hash scrypt hash result
|
|
60
|
+
* @returns address as string format
|
|
61
|
+
*/
|
|
62
|
+
export function getEvmWalletAddress(hash) {
|
|
63
|
+
const privateKey = getEvmPrivateKey(hash);
|
|
64
|
+
const wallet = new ethers.Wallet(privateKey);
|
|
65
|
+
return wallet.address;
|
|
66
|
+
}
|
|
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
|
+
|
|
56
78
|
const URL_DELIMITER = "\u0002";
|
|
57
79
|
const NETWORKS = [
|
|
58
80
|
"ethereum",
|
|
@@ -61,6 +83,7 @@ const NETWORKS = [
|
|
|
61
83
|
"optimism",
|
|
62
84
|
"bsc",
|
|
63
85
|
"avalanche",
|
|
86
|
+
"base",
|
|
64
87
|
"tron",
|
|
65
88
|
];
|
|
66
89
|
/**
|
|
@@ -68,7 +91,7 @@ const NETWORKS = [
|
|
|
68
91
|
* The transfer-link introduces a nice feature that enables the transfer of full ownership of a wallet account.
|
|
69
92
|
* @param {*} password
|
|
70
93
|
* @param {*} passcode
|
|
71
|
-
* @param {*} network ethereum | polygon | arbitrum | optimism | bsc | avalanche | tron
|
|
94
|
+
* @param {*} network ethereum | polygon | arbitrum | optimism | bsc | avalanche | base | tron
|
|
72
95
|
* @returns A string formatted as a transfer-link token, which can be appended to `https://app.mybucks.online?wallet=`
|
|
73
96
|
*/
|
|
74
97
|
export function generateToken(password, passcode, network) {
|
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
|
@@ -3,6 +3,8 @@ import { describe, test } from "node:test";
|
|
|
3
3
|
import {
|
|
4
4
|
generateHash,
|
|
5
5
|
getEvmPrivateKey,
|
|
6
|
+
getEvmWalletAddress,
|
|
7
|
+
getTronWalletAddress,
|
|
6
8
|
generateToken,
|
|
7
9
|
parseToken,
|
|
8
10
|
} from "../index.js";
|
|
@@ -10,11 +12,15 @@ import {
|
|
|
10
12
|
const DEMO_PASSWORD = "DemoAccount5&";
|
|
11
13
|
const DEMO_PASSCODE = "112324";
|
|
12
14
|
const DEMO_NETWORK = "optimism";
|
|
15
|
+
|
|
13
16
|
const DEMO_HASH =
|
|
14
17
|
"af9a22d75f8f69d33fe8fc294e8f413219d9c75374dec07fda2e4a66868599609887a10e04981e17356d2c07432fc89c11089172fdf91c0015b9a4beef11e447";
|
|
15
18
|
const DEMO_PRIVATE_KEY =
|
|
16
19
|
"0x71743de900c63ed741263a2a4513c1b1829e80bd9f18d5d3a593e651b914cb3b";
|
|
17
|
-
const
|
|
20
|
+
const DEMO_WALLET_EVM_ADDRESS = "0x347CEB6Bf002Ee1819009bA07d8dCAA95Efe6465";
|
|
21
|
+
const DEMO_WALLET_TRON_ADDRESS = "TEkjnbpr2cTgRFgmrbv2Gb7GdgupZ5Sh3A";
|
|
22
|
+
|
|
23
|
+
const DEMO_TRANSFER_TOKEN =
|
|
18
24
|
"VWnsSGRGVtb0FjY291bnQ1JgIxMTIzMjQCb3B0aW1pc20=_wNovT";
|
|
19
25
|
|
|
20
26
|
describe("generateHash", () => {
|
|
@@ -38,19 +44,47 @@ describe("getEvmPrivateKey", () => {
|
|
|
38
44
|
});
|
|
39
45
|
});
|
|
40
46
|
|
|
47
|
+
describe("getEvmWalletAddress", () => {
|
|
48
|
+
test("should return a valid wallet address", async () => {
|
|
49
|
+
const hash = await generateHash(DEMO_PASSWORD, DEMO_PASSCODE);
|
|
50
|
+
const address = getEvmWalletAddress(hash);
|
|
51
|
+
|
|
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);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
41
65
|
describe("generateToken", () => {
|
|
42
|
-
test("should return null if password, passcode or network is invalid",
|
|
66
|
+
test("should return null if password, passcode or network is invalid", () => {
|
|
43
67
|
assert.strictEqual(generateToken("", "123345", "ethereum"), null);
|
|
44
68
|
assert.strictEqual(generateToken("", "123345"), null);
|
|
45
69
|
assert.strictEqual(generateToken("password", "", "ethereum"), null);
|
|
46
70
|
assert.strictEqual(generateToken("password", "123456", ""), null);
|
|
47
71
|
assert.strictEqual(generateToken("password", "123456", "invalid"), null);
|
|
48
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
|
+
});
|
|
49
83
|
});
|
|
50
84
|
|
|
51
85
|
describe("parseToken", () => {
|
|
52
86
|
test("should return array of password, passcode, and network", () => {
|
|
53
|
-
const [password, passcode, network] = parseToken(
|
|
87
|
+
const [password, passcode, network] = parseToken(DEMO_TRANSFER_TOKEN);
|
|
54
88
|
|
|
55
89
|
assert.strictEqual(password, DEMO_PASSWORD);
|
|
56
90
|
assert.strictEqual(passcode, DEMO_PASSCODE);
|