@mybucks.online/core 1.0.11 → 1.0.12
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 +10 -10
- package/index.js +15 -15
- package/package.json +1 -1
- package/test/index.test.js +30 -30
package/README.md
CHANGED
|
@@ -4,11 +4,11 @@ This is a core part of [mybucks.online](https://mybucks.online) crypto wallet, i
|
|
|
4
4
|
|
|
5
5
|
## mybucks.online
|
|
6
6
|
|
|
7
|
-
[Mybucks.online](https://mybucks.online) is a **seedless, disposable crypto wallet** designed for **speed and convenience**. It generates a private key from your
|
|
7
|
+
[Mybucks.online](https://mybucks.online) is a **seedless, disposable crypto wallet** designed for **speed and convenience**. It generates a private key from your **passphrase and PIN** using an industry-standard, verified **one-way hash function**. Your private key forms your account, allowing you to transfer, receive, and hold your crypto assets instantly.
|
|
8
8
|
|
|
9
|
-
As a hash function, the **
|
|
9
|
+
As a hash function, the **Scrypt** Key Derivation Function (KDF) increases the computational effort required to crack credentials, effectively delaying **brute-force** attacks and making them impractical.
|
|
10
10
|
|
|
11
|
-
It fully runs on your **browser side** without using any storage or invoking any 3rd-party APIs for key management. It instantly generates your private key from your
|
|
11
|
+
It fully runs on your **browser side** without using any storage or invoking any 3rd-party APIs for key management. It instantly generates your private key from your credentials input, and whenever you close or refresh, there is **no footprint**. This absolutely protects your privacy.
|
|
12
12
|
|
|
13
13
|
### Zero Footprint
|
|
14
14
|
- No servers, no databases, no storage and no tracking.
|
|
@@ -19,7 +19,7 @@ It fully runs on your **browser side** without using any storage or invoking any
|
|
|
19
19
|
### Fast and Easy
|
|
20
20
|
- No app installs, no browser extensions, no registration and no KYC.
|
|
21
21
|
- You can create or open your wallet in seconds - all you need is your browser.
|
|
22
|
-
-
|
|
22
|
+
- Passphrase is easier to handle and remember than seed phrases.
|
|
23
23
|
|
|
24
24
|
### 1-Click Gifting
|
|
25
25
|
- Stop asking your friends for their wallet addresses.
|
|
@@ -51,7 +51,7 @@ const showProgress = (p) => {
|
|
|
51
51
|
console.log(`progress: ${p * 100}%`);
|
|
52
52
|
};
|
|
53
53
|
|
|
54
|
-
const hash = await generateHash(
|
|
54
|
+
const hash = await generateHash(passphrase, pin, showProgress);
|
|
55
55
|
|
|
56
56
|
const privateKey = getEvmPrivateKey(hash);
|
|
57
57
|
console.log("Private key: ", privateKey);
|
|
@@ -66,15 +66,15 @@ console.log("TRON Address: ", address2);
|
|
|
66
66
|
### 3. Generate and parse (transfer-link's)token
|
|
67
67
|
```javascript
|
|
68
68
|
import { generateToken } from "@mybucks.online/core";
|
|
69
|
-
const token = generateToken(
|
|
69
|
+
const token = generateToken(passphrase, pin, network);
|
|
70
70
|
|
|
71
71
|
console.log("https://app.mybucks.online/#wallet=" + token);
|
|
72
72
|
```
|
|
73
73
|
|
|
74
74
|
```javascript
|
|
75
75
|
import { parseToken } from "@mybucks.online/core";
|
|
76
|
-
const [
|
|
77
|
-
console.log("Account credentials are: ",
|
|
76
|
+
const [passphrase, pin, network] = parseToken(token);
|
|
77
|
+
console.log("Account credentials are: ", passphrase, pin);
|
|
78
78
|
console.log("Network: ", network);
|
|
79
79
|
```
|
|
80
80
|
|
|
@@ -91,8 +91,8 @@ Find the docs [here](https://docs.mybucks.online).
|
|
|
91
91
|
|
|
92
92
|
- https://github.com/mybucks-online/app
|
|
93
93
|
- https://app.mybucks.online
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
passphrase: **DemoAccount5&**
|
|
95
|
+
PIN: **112324**
|
|
96
96
|
- https://app.mybucks.online/#wallet=VWnsSGRGVtb0FjY291bnQ1JgIxMTIzMjQCb3B0aW1pc20=_wNovT
|
|
97
97
|
- https://app.mybucks.online/#wallet=1jpFD8RGVtb0FjY291bnQ1JgIxMTIzMjQCYmFzZQ==fhk-GL
|
|
98
98
|
- https://codesandbox.io/p/sandbox/mybucks-online-key-generation-sandbox-lt53c3
|
package/index.js
CHANGED
|
@@ -15,21 +15,21 @@ const HASH_OPTIONS = {
|
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
* This function computes the scrypt hash using provided
|
|
18
|
+
* This function computes the scrypt hash using provided passphrase and pin inputs.
|
|
19
19
|
*
|
|
20
|
-
* @param {*}
|
|
21
|
-
* @param {*}
|
|
20
|
+
* @param {*} passphrase
|
|
21
|
+
* @param {*} pin
|
|
22
22
|
* @param {*} cb a callback function designed to receive the progress updates during the scrypt hashing process.
|
|
23
23
|
* @returns hash result as string format
|
|
24
24
|
*/
|
|
25
|
-
export async function generateHash(
|
|
26
|
-
if (!
|
|
25
|
+
export async function generateHash(passphrase, pin, cb = () => {}) {
|
|
26
|
+
if (!passphrase || !pin) {
|
|
27
27
|
return "";
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
const salt = `${
|
|
30
|
+
const salt = `${passphrase.slice(-4)}${pin}`;
|
|
31
31
|
|
|
32
|
-
const passwordBuffer = Buffer.from(
|
|
32
|
+
const passwordBuffer = Buffer.from(passphrase);
|
|
33
33
|
const saltBuffer = Buffer.from(salt);
|
|
34
34
|
|
|
35
35
|
const hashBuffer = await scrypt(
|
|
@@ -89,13 +89,13 @@ const NETWORKS = [
|
|
|
89
89
|
/**
|
|
90
90
|
* This function generates a transfer-link by combining credentials and randomly generated padding.
|
|
91
91
|
* The transfer-link introduces a nice feature that enables the transfer of full ownership of a wallet account.
|
|
92
|
-
* @param {*}
|
|
93
|
-
* @param {*}
|
|
92
|
+
* @param {*} passphrase
|
|
93
|
+
* @param {*} pin
|
|
94
94
|
* @param {*} network ethereum | polygon | arbitrum | optimism | bsc | avalanche | base | tron
|
|
95
95
|
* @returns A string formatted as a transfer-link token, which can be appended to `https://app.mybucks.online?wallet=`
|
|
96
96
|
*/
|
|
97
|
-
export function generateToken(
|
|
98
|
-
if (!
|
|
97
|
+
export function generateToken(passphrase, pin, network) {
|
|
98
|
+
if (!passphrase || !pin || !network) {
|
|
99
99
|
return null;
|
|
100
100
|
}
|
|
101
101
|
if (!NETWORKS.find((n) => n === network)) {
|
|
@@ -103,7 +103,7 @@ export function generateToken(password, passcode, network) {
|
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
const merged = Buffer.from(
|
|
106
|
-
|
|
106
|
+
passphrase + URL_DELIMITER + pin + URL_DELIMITER + network,
|
|
107
107
|
"utf-8"
|
|
108
108
|
);
|
|
109
109
|
const base64Encoded = merged.toString("base64");
|
|
@@ -114,11 +114,11 @@ export function generateToken(password, passcode, network) {
|
|
|
114
114
|
/**
|
|
115
115
|
* This function parses a transfer-link token generated by generateToken().
|
|
116
116
|
* @param {*} token
|
|
117
|
-
* @returns an array of strings, including the
|
|
117
|
+
* @returns an array of strings, including the passphrase, pin and network.
|
|
118
118
|
*/
|
|
119
119
|
export function parseToken(token) {
|
|
120
120
|
const payload = token.slice(6, token.length - 6);
|
|
121
121
|
const base64Decoded = Buffer.from(payload, "base64").toString("utf-8");
|
|
122
|
-
const [
|
|
123
|
-
return [
|
|
122
|
+
const [passphrase, pin, network] = base64Decoded.split(URL_DELIMITER);
|
|
123
|
+
return [passphrase, pin, network];
|
|
124
124
|
}
|
package/package.json
CHANGED
package/test/index.test.js
CHANGED
|
@@ -9,8 +9,8 @@ import {
|
|
|
9
9
|
parseToken,
|
|
10
10
|
} from "../index.js";
|
|
11
11
|
|
|
12
|
-
const
|
|
13
|
-
const
|
|
12
|
+
const DEMO_PASSPHRASE = "DemoAccount5&";
|
|
13
|
+
const DEMO_PIN = "112324";
|
|
14
14
|
const DEMO_NETWORK = "optimism";
|
|
15
15
|
|
|
16
16
|
const DEMO_HASH =
|
|
@@ -24,20 +24,20 @@ const DEMO_TRANSFER_TOKEN =
|
|
|
24
24
|
"VWnsSGRGVtb0FjY291bnQ1JgIxMTIzMjQCb3B0aW1pc20=_wNovT";
|
|
25
25
|
|
|
26
26
|
describe("generateHash", () => {
|
|
27
|
-
test("should return empty string if
|
|
27
|
+
test("should return empty string if passphrase or pin is blank", async () => {
|
|
28
28
|
const hash = await generateHash("", "");
|
|
29
29
|
assert.strictEqual(hash, "");
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
test("should return scrypt hash result", async () => {
|
|
33
|
-
const hash = await generateHash(
|
|
33
|
+
const hash = await generateHash(DEMO_PASSPHRASE, DEMO_PIN);
|
|
34
34
|
assert.strictEqual(hash, DEMO_HASH);
|
|
35
35
|
});
|
|
36
36
|
});
|
|
37
37
|
|
|
38
38
|
describe("getEvmPrivateKey", () => {
|
|
39
39
|
test("should return 256bit private key", async () => {
|
|
40
|
-
const hash = await generateHash(
|
|
40
|
+
const hash = await generateHash(DEMO_PASSPHRASE, DEMO_PIN);
|
|
41
41
|
const privateKey = getEvmPrivateKey(hash);
|
|
42
42
|
|
|
43
43
|
assert.strictEqual(privateKey, DEMO_PRIVATE_KEY);
|
|
@@ -46,7 +46,7 @@ describe("getEvmPrivateKey", () => {
|
|
|
46
46
|
|
|
47
47
|
describe("getEvmWalletAddress", () => {
|
|
48
48
|
test("should return a valid wallet address", async () => {
|
|
49
|
-
const hash = await generateHash(
|
|
49
|
+
const hash = await generateHash(DEMO_PASSPHRASE, DEMO_PIN);
|
|
50
50
|
const address = getEvmWalletAddress(hash);
|
|
51
51
|
|
|
52
52
|
assert.strictEqual(address, DEMO_WALLET_EVM_ADDRESS);
|
|
@@ -55,7 +55,7 @@ describe("getEvmWalletAddress", () => {
|
|
|
55
55
|
|
|
56
56
|
describe("getTronWalletAddress", () => {
|
|
57
57
|
test("should return a valid wallet address", async () => {
|
|
58
|
-
const hash = await generateHash(
|
|
58
|
+
const hash = await generateHash(DEMO_PASSPHRASE, DEMO_PIN);
|
|
59
59
|
const address = getTronWalletAddress(hash);
|
|
60
60
|
|
|
61
61
|
assert.strictEqual(address, DEMO_WALLET_TRON_ADDRESS);
|
|
@@ -63,16 +63,16 @@ describe("getTronWalletAddress", () => {
|
|
|
63
63
|
});
|
|
64
64
|
|
|
65
65
|
describe("generateToken", () => {
|
|
66
|
-
test("should return null if
|
|
66
|
+
test("should return null if passphrase, pin or network is invalid", () => {
|
|
67
67
|
assert.strictEqual(generateToken("", "123345", "ethereum"), null);
|
|
68
68
|
assert.strictEqual(generateToken("", "123345"), null);
|
|
69
|
-
assert.strictEqual(generateToken("
|
|
70
|
-
assert.strictEqual(generateToken("
|
|
71
|
-
assert.strictEqual(generateToken("
|
|
69
|
+
assert.strictEqual(generateToken("passphrase", "", "ethereum"), null);
|
|
70
|
+
assert.strictEqual(generateToken("passphrase", "123456", ""), null);
|
|
71
|
+
assert.strictEqual(generateToken("passphrase", "123456", "invalid"), null);
|
|
72
72
|
});
|
|
73
73
|
|
|
74
74
|
test("should return valid token", async () => {
|
|
75
|
-
const token = generateToken(
|
|
75
|
+
const token = generateToken(DEMO_PASSPHRASE, DEMO_PIN, DEMO_NETWORK);
|
|
76
76
|
|
|
77
77
|
// The first and last 6 characters serve as random padding.
|
|
78
78
|
assert.strictEqual(
|
|
@@ -83,60 +83,60 @@ describe("generateToken", () => {
|
|
|
83
83
|
|
|
84
84
|
test("should return valid token for all networks", async () => {
|
|
85
85
|
assert.notStrictEqual(
|
|
86
|
-
generateToken(
|
|
86
|
+
generateToken(DEMO_PASSPHRASE, DEMO_PIN, "ethereum"),
|
|
87
87
|
null
|
|
88
88
|
);
|
|
89
89
|
assert.notStrictEqual(
|
|
90
|
-
generateToken(
|
|
90
|
+
generateToken(DEMO_PASSPHRASE, DEMO_PIN, "polygon"),
|
|
91
91
|
null
|
|
92
92
|
);
|
|
93
93
|
assert.notStrictEqual(
|
|
94
|
-
generateToken(
|
|
94
|
+
generateToken(DEMO_PASSPHRASE, DEMO_PIN, "arbitrum"),
|
|
95
95
|
null
|
|
96
96
|
);
|
|
97
97
|
assert.notStrictEqual(
|
|
98
|
-
generateToken(
|
|
98
|
+
generateToken(DEMO_PASSPHRASE, DEMO_PIN, "optimism"),
|
|
99
99
|
null
|
|
100
100
|
);
|
|
101
101
|
assert.notStrictEqual(
|
|
102
|
-
generateToken(
|
|
102
|
+
generateToken(DEMO_PASSPHRASE, DEMO_PIN, "bsc"),
|
|
103
103
|
null
|
|
104
104
|
);
|
|
105
105
|
assert.notStrictEqual(
|
|
106
|
-
generateToken(
|
|
106
|
+
generateToken(DEMO_PASSPHRASE, DEMO_PIN, "avalanche"),
|
|
107
107
|
null
|
|
108
108
|
);
|
|
109
109
|
assert.notStrictEqual(
|
|
110
|
-
generateToken(
|
|
110
|
+
generateToken(DEMO_PASSPHRASE, DEMO_PIN, "base"),
|
|
111
111
|
null
|
|
112
112
|
);
|
|
113
113
|
assert.notStrictEqual(
|
|
114
|
-
generateToken(
|
|
114
|
+
generateToken(DEMO_PASSPHRASE, DEMO_PIN, "tron"),
|
|
115
115
|
null
|
|
116
116
|
);
|
|
117
117
|
});
|
|
118
118
|
});
|
|
119
119
|
|
|
120
120
|
describe("parseToken", () => {
|
|
121
|
-
test("should return array of
|
|
122
|
-
const [
|
|
121
|
+
test("should return array of passphrase, pin, and network", () => {
|
|
122
|
+
const [passphrase, pin, network] = parseToken(DEMO_TRANSFER_TOKEN);
|
|
123
123
|
|
|
124
|
-
assert.strictEqual(
|
|
125
|
-
assert.strictEqual(
|
|
124
|
+
assert.strictEqual(passphrase, DEMO_PASSPHRASE);
|
|
125
|
+
assert.strictEqual(pin, DEMO_PIN);
|
|
126
126
|
assert.strictEqual(network, DEMO_NETWORK);
|
|
127
127
|
});
|
|
128
128
|
});
|
|
129
129
|
|
|
130
130
|
describe("generateToken and parseToken", () => {
|
|
131
131
|
test("should be compatible and return correct result", () => {
|
|
132
|
-
const
|
|
133
|
-
const
|
|
132
|
+
const testPassphrase = "My-1st-car-was-a-red-Ford-2005!";
|
|
133
|
+
const testPin = "909011";
|
|
134
134
|
const testNetwork = "polygon";
|
|
135
|
-
const token = generateToken(
|
|
135
|
+
const token = generateToken(testPassphrase, testPin, testNetwork);
|
|
136
136
|
|
|
137
|
-
const [
|
|
138
|
-
assert.strictEqual(
|
|
139
|
-
assert.strictEqual(
|
|
137
|
+
const [passphrase, pin, network] = parseToken(token);
|
|
138
|
+
assert.strictEqual(passphrase, testPassphrase);
|
|
139
|
+
assert.strictEqual(pin, testPin);
|
|
140
140
|
assert.strictEqual(network, testNetwork);
|
|
141
141
|
});
|
|
142
142
|
});
|