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