Skip to content

Commit e8eb80e

Browse files
authored
Merge pull request #12 from mybucks-online/feat/update-dependency
upgrade @mybucks.online/core
2 parents 322461a + 4989575 commit e8eb80e

File tree

5 files changed

+13
-34
lines changed

5 files changed

+13
-34
lines changed

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,14 @@
3030
"preview": "vite preview"
3131
},
3232
"dependencies": {
33-
"@mybucks.online/core": "^1.0.2",
33+
"@mybucks.online/core": "^1.0.3",
3434
"@sushiswap/default-token-list": "^43.3.0",
3535
"alchemy-sdk": "^3.5.0",
3636
"buffer": "^6.0.3",
3737
"clipboard-copy": "^4.0.1",
3838
"date-fns": "^4.1.0",
3939
"ethers": "^6.13.0",
4040
"focus-trap-react": "^10.2.3",
41-
"nanoid": "^5.0.9",
4241
"react": "^18.2.0",
4342
"react-dom": "^18.2.0",
4443
"react-idle-timer": "^5.7.2",

src/lib/conf.js

-21
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import { Network } from "alchemy-sdk";
2-
import { Buffer } from "buffer";
3-
import { nanoid } from "nanoid";
42

53
export const PASSWORD_MIN_LENGTH = 12;
64
export const PASSWORD_MAX_LENGTH = 128;
@@ -9,25 +7,6 @@ export const PASSCODE_MAX_LENGTH = 16;
97

108
export const PASSCODE_MAX_TRY = 3;
119

12-
const URL_DELIMITER = "\u0002";
13-
14-
export function generateUrl(password, passcode, network) {
15-
const merged = Buffer.from(
16-
password + URL_DELIMITER + passcode + URL_DELIMITER + network,
17-
"utf-8"
18-
);
19-
const base64Encoded = merged.toString("base64");
20-
const padding = nanoid(12);
21-
return padding.slice(0, 6) + base64Encoded + padding.slice(6);
22-
}
23-
24-
export function parseUrl(token) {
25-
const payload = token.slice(6, token.length - 6);
26-
const base64Decoded = Buffer.from(payload, "base64").toString("utf-8");
27-
const [password, passcode, network] = base64Decoded.split(URL_DELIMITER);
28-
return [password, passcode, network];
29-
}
30-
3110
export const NETWORK = Object.freeze({
3211
EVM: "evm",
3312
TRON: "tron",

src/pages/Menu/index.jsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useContext, useState } from "react";
22
import { toast } from "react-toastify";
3+
import { generateToken } from "@mybucks.online/core";
34
import copy from "clipboard-copy";
45
import styled from "styled-components";
56

@@ -9,7 +10,7 @@ import ConfirmPasscodeModal from "@mybucks/components/ConfirmPasscodeModal";
910
import { Box as BaseBox, Container } from "@mybucks/components/Containers";
1011
import { H3 } from "@mybucks/components/Texts";
1112
import { StoreContext } from "@mybucks/contexts/Store";
12-
import { findNetworkNameByChainId, generateUrl } from "@mybucks/lib/conf";
13+
import { findNetworkNameByChainId } from "@mybucks/lib/conf";
1314

1415
const Box = styled(BaseBox)`
1516
display: flex;
@@ -82,7 +83,7 @@ const Menu = () => {
8283
toast("Private key copied into clipboard.");
8384
} else if (nextStep === BACKUP_TRANSFER_LINK) {
8485
const networkName = findNetworkNameByChainId(network, chainId);
85-
const link = generateUrl(password, passcode, networkName);
86+
const link = generateToken(password, passcode, networkName);
8687
copy(
8788
window.location.origin + window.location.pathname + "?wallet=" + link
8889
);

src/pages/Signin/index.jsx

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useContext, useEffect, useMemo, useState } from "react";
2-
import { generateHash } from "@mybucks.online/core";
2+
import { generateHash, parseToken } from "@mybucks.online/core";
33
import styled from "styled-components";
44

55
import Button from "@mybucks/components/Button";
@@ -13,7 +13,6 @@ import { H1 } from "@mybucks/components/Texts";
1313
import { StoreContext } from "@mybucks/contexts/Store";
1414
import {
1515
findNetworkByName,
16-
parseUrl,
1716
PASSCODE_MAX_LENGTH,
1817
PASSCODE_MIN_LENGTH,
1918
PASSWORD_MAX_LENGTH,
@@ -188,7 +187,7 @@ const SignIn = () => {
188187
);
189188

190189
useEffect(() => {
191-
const parseUrlAndSubmit = async () => {
190+
const parseTokenAndSubmit = async () => {
192191
// get "secret" param from URL
193192
const url = new URL(window.location.href);
194193
const params = new URLSearchParams(url.search);
@@ -198,7 +197,7 @@ const SignIn = () => {
198197
}
199198

200199
// parse password, passcode, network name from "secret" param
201-
const [pwd, pc, nn] = parseUrl(secret);
200+
const [pwd, pc, nn] = parseToken(secret);
202201
if (!pwd || !pc || !nn) {
203202
return;
204203
}
@@ -213,7 +212,7 @@ const SignIn = () => {
213212
setDisabled(false);
214213
};
215214

216-
parseUrlAndSubmit();
215+
parseTokenAndSubmit();
217216
}, []);
218217

219218
const onSubmit = async () => {

yarn.lock

+5-4
Original file line numberDiff line numberDiff line change
@@ -769,13 +769,14 @@
769769
"@jridgewell/resolve-uri" "^3.1.0"
770770
"@jridgewell/sourcemap-codec" "^1.4.14"
771771

772-
"@mybucks.online/core@^1.0.2":
773-
version "1.0.2"
774-
resolved "https://registry.yarnpkg.com/@mybucks.online/core/-/core-1.0.2.tgz#6a671b68e7c9c20e6ff04fd4d2351ccd38aa3af1"
775-
integrity sha512-Ptbn9L8A6yFU5+NlK1plqu5/Y6RgLyZB6VPsHVjExJjHLiMUiGWX8/8Lmdhfsx/lTmLECtZl65zmG91rkbjYYA==
772+
"@mybucks.online/core@^1.0.3":
773+
version "1.0.3"
774+
resolved "https://registry.yarnpkg.com/@mybucks.online/core/-/core-1.0.3.tgz#1fd4e0bf37584afc3dc8c319e175741f5dba5f32"
775+
integrity sha512-zBXVUbiGAGgkDK90KjF1sJisuLWuEhGRO9sBVAPGjpZqtrPlVYDjX/ieWJmQ6alWdX3UYG4y7lsSITVura85RA==
776776
dependencies:
777777
buffer "^6.0.3"
778778
ethers "^6.13.5"
779+
nanoid "^5.0.9"
779780
scrypt-js "^3.0.1"
780781

781782
"@noble/curves@1.2.0":

0 commit comments

Comments
 (0)