@mybucks.online/core 1.0.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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +39 -0
  3. package/index.js +62 -0
  4. package/package.json +35 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 mybucks.online
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # @mybucks.online/core
2
+
3
+ This is a core part of mybucks.online crypto wallet, involving hashing and private key generation.
4
+
5
+ ## mybucks.online
6
+
7
+ Mybucks.online is a **password-only, self-custodial and browser-based cryptocurrency wallet** built with Javascript. It generates a private key from your password and passcode 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 permanently.
8
+
9
+ ## Quick start
10
+
11
+ ### 1. Install
12
+
13
+ ```bash
14
+ npm install @mybucks.online/core
15
+ ```
16
+
17
+ ### 2. Generate hash and private-key
18
+
19
+ ```javascript
20
+ import { getEvmPrivateKey, generateHash } from "@mybucks.online/core";
21
+
22
+ const showProgress = (p) => {
23
+ console.log(`progress: ${p * 100}%`);
24
+ };
25
+
26
+ const hash = await generateHash(password, passcode, showProgress);
27
+ const privateKey = getEvmPrivateKey(hash);
28
+
29
+ console.log("Private key: ", privateKey);
30
+ ```
31
+
32
+ ## Docs
33
+
34
+ Find the docs [here](https://docs.mybucks.online).
35
+
36
+ ## Live example
37
+
38
+ - https://github.com/mybucks.online/app
39
+ - https://app.mybucks.online
package/index.js ADDED
@@ -0,0 +1,62 @@
1
+ const { Buffer } = require("buffer");
2
+ const { ethers } = require("ethers");
3
+ const { scrypt } = require("scrypt-js");
4
+
5
+ const abi = new ethers.AbiCoder();
6
+
7
+ /**
8
+ * [CRITICAL] DON'T CHANGE FOREVER!!!
9
+ * Reference:
10
+ * https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#scrypt
11
+ */
12
+ const HASH_OPTIONS = {
13
+ N: 32768, // CPU/memory cost parameter, 2^15
14
+ r: 8, // block size parameter
15
+ p: 5, // parallelization parameter
16
+ keyLen: 64,
17
+ };
18
+
19
+ /**
20
+ * This function computes the scrypt hash using provided password and passcode inputs.
21
+ *
22
+ * @param {*} password
23
+ * @param {*} passcode
24
+ * @param {*} cb a callback function designed to receive the progress updates during the scrypt hashing process.
25
+ * @returns hash result as string format
26
+ */
27
+ async function generateHash(password, passcode, cb = () => {}) {
28
+ if (!password || !passcode) {
29
+ return "";
30
+ }
31
+
32
+ const salt = `${password.slice(-4)}${passcode}`;
33
+
34
+ const passwordBuffer = Buffer.from(password);
35
+ const saltBuffer = Buffer.from(salt);
36
+
37
+ const hashBuffer = await scrypt(
38
+ passwordBuffer,
39
+ saltBuffer,
40
+ HASH_OPTIONS.N,
41
+ HASH_OPTIONS.r,
42
+ HASH_OPTIONS.p,
43
+ HASH_OPTIONS.keyLen,
44
+ cb
45
+ );
46
+
47
+ return Buffer.from(hashBuffer).toString("hex");
48
+ }
49
+
50
+ /**
51
+ * This function derives the EVM private key from the result of the scrypt hash.
52
+ * @param {*} hash
53
+ * @returns private key as string format
54
+ */
55
+ function getEvmPrivateKey(hash) {
56
+ return ethers.keccak256(abi.encode(["string"], [hash]));
57
+ }
58
+
59
+ module.exports = {
60
+ generateHash,
61
+ getEvmPrivateKey,
62
+ };
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@mybucks.online/core",
3
+ "version": "1.0.0",
4
+ "description": "Core module for mybucks.online crypto wallet",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/mybucks-online/core.git"
12
+ },
13
+ "keywords": [
14
+ "wallet",
15
+ "crypto",
16
+ "password-only",
17
+ "multi-chain",
18
+ "self-custodial",
19
+ "browser-based",
20
+ "ethereum",
21
+ "tron",
22
+ "open-source"
23
+ ],
24
+ "author": "koko37",
25
+ "license": "MIT",
26
+ "bugs": {
27
+ "url": "https://github.com/mybucks-online/core/issues"
28
+ },
29
+ "homepage": "https://github.com/mybucks-online/core#readme",
30
+ "dependencies": {
31
+ "buffer": "^6.0.3",
32
+ "ethers": "^6.13.5",
33
+ "scrypt-js": "^3.0.1"
34
+ }
35
+ }