From a89abc7a4f8740f9427c492700ce445a128da817 Mon Sep 17 00:00:00 2001 From: Mohammad Shahbaz Alam Date: Mon, 8 Apr 2024 10:11:06 +0530 Subject: [PATCH 1/2] Fix: Update parseToken to use safeatob --- package-lock.json | 83 ++++++++++++++++++++++++++++++++++++++++++----- package.json | 1 + src/utils.ts | 6 ++-- 3 files changed, 79 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index 77c55fe9..f38d2c47 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,6 +22,7 @@ "@toruslabs/fnd-base": "^13.1.1", "@toruslabs/metadata-helpers": "^5.x", "@toruslabs/openlogin-session-manager": "^3.0.0", + "@toruslabs/openlogin-utils": "^8.0.0", "@toruslabs/torus.js": "^12.1.0", "@toruslabs/tss-client": "^2.1.0", "@toruslabs/tss-lib": "^2.0.0", @@ -4640,6 +4641,20 @@ "@babel/runtime": "7.x" } }, + "node_modules/@toruslabs/openlogin-jrpc/node_modules/@toruslabs/openlogin-utils": { + "version": "2.13.0", + "resolved": "https://registry.npmjs.org/@toruslabs/openlogin-utils/-/openlogin-utils-2.13.0.tgz", + "integrity": "sha512-g4pj6hIdKcuyetVsUWqiAJmCooTS9hOADL31m7LTqgdXzX9oR437A+c8Dw8gzFVcHmkK16Yt2//GvlKnSsGILg==", + "deprecated": "Not supported. Pls upgrade", + "dependencies": { + "base64url": "^3.0.1", + "keccak": "^3.0.3", + "randombytes": "^2.1.0" + }, + "peerDependencies": { + "@babel/runtime": "7.x" + } + }, "node_modules/@toruslabs/openlogin-session-manager": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/@toruslabs/openlogin-session-manager/-/openlogin-session-manager-3.0.0.tgz", @@ -4677,14 +4692,17 @@ } }, "node_modules/@toruslabs/openlogin-utils": { - "version": "2.13.0", - "resolved": "https://registry.npmjs.org/@toruslabs/openlogin-utils/-/openlogin-utils-2.13.0.tgz", - "integrity": "sha512-g4pj6hIdKcuyetVsUWqiAJmCooTS9hOADL31m7LTqgdXzX9oR437A+c8Dw8gzFVcHmkK16Yt2//GvlKnSsGILg==", - "deprecated": "Not supported. Pls upgrade", + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/@toruslabs/openlogin-utils/-/openlogin-utils-8.0.0.tgz", + "integrity": "sha512-e0o29VfXttRfaCIxGq5Hg8bhyTbw/6a8d54LDf5l1sMMSYLiHpE8ezooak7eQlxVgveEOynGgr4mbAOK290axA==", "dependencies": { + "@toruslabs/constants": "^13.1.0", "base64url": "^3.0.1", - "keccak": "^3.0.3", - "randombytes": "^2.1.0" + "color": "^4.2.3" + }, + "engines": { + "node": ">=18.x", + "npm": ">=9.x" }, "peerDependencies": { "@babel/runtime": "7.x" @@ -7506,6 +7524,18 @@ "node": ">=6" } }, + "node_modules/color": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/color/-/color-4.2.3.tgz", + "integrity": "sha512-1rXeuUUiGGrykh+CeBdu5Ie7OJwinCgQY0bc7GCRxy5xVHy+moaqkpL/jqQq0MtQOeYcrqEz4abc5f0KtU7W4A==", + "dependencies": { + "color-convert": "^2.0.1", + "color-string": "^1.9.0" + }, + "engines": { + "node": ">=12.5.0" + } + }, "node_modules/color-convert": { "version": "1.9.3", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", @@ -7518,8 +7548,32 @@ "node_modules/color-name": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", - "dev": true + "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==" + }, + "node_modules/color-string": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/color-string/-/color-string-1.9.1.tgz", + "integrity": "sha512-shrVawQFojnZv6xM40anx4CkoDP+fZsw/ZerEMsW/pyzsRbElpsL/DBVW7q3ExxwusdNXI3lXpuhEZkzs8p5Eg==", + "dependencies": { + "color-name": "^1.0.0", + "simple-swizzle": "^0.2.2" + } + }, + "node_modules/color/node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "node_modules/color/node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" }, "node_modules/colorette": { "version": "2.0.20", @@ -15404,6 +15458,19 @@ "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==", "dev": true }, + "node_modules/simple-swizzle": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/simple-swizzle/-/simple-swizzle-0.2.2.tgz", + "integrity": "sha512-JA//kQgZtbuY83m+xT+tXJkmJncGMTFT+C+g2h2R9uxkYIrE2yy9sgmcLhCnw57/WSD+Eh3J97FPEDFnbXnDUg==", + "dependencies": { + "is-arrayish": "^0.3.1" + } + }, + "node_modules/simple-swizzle/node_modules/is-arrayish": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.3.2.tgz", + "integrity": "sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ==" + }, "node_modules/sirv": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/sirv/-/sirv-2.0.4.tgz", diff --git a/package.json b/package.json index 5d066acb..9ac98273 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "@toruslabs/fnd-base": "^13.1.1", "@toruslabs/metadata-helpers": "^5.x", "@toruslabs/openlogin-session-manager": "^3.0.0", + "@toruslabs/openlogin-utils": "^8.0.0", "@toruslabs/torus.js": "^12.1.0", "@toruslabs/tss-client": "^2.1.0", "@toruslabs/tss-lib": "^2.0.0", diff --git a/src/utils.ts b/src/utils.ts index 595fceec..3eca4aad 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,6 +1,7 @@ import { getPubKeyPoint, Point, Point as TkeyPoint, randomSelection } from "@tkey-mpc/common-types"; import ThresholdKey from "@tkey-mpc/core"; import { generatePrivate } from "@toruslabs/eccrypto"; +import { safeatob } from "@toruslabs/openlogin-utils"; import { keccak256 } from "@toruslabs/torus.js"; import BN from "bn.js"; @@ -59,9 +60,8 @@ export function storageAvailable(type: string): boolean { * @returns Extracted JSON payload from the token */ export function parseToken(token: string) { - const base64Url = token.split(".")[1]; - const base64 = base64Url.replace("-", "+").replace("_", "/"); - return JSON.parse(atob(base64 || "")); + const payload = token.split(".")[1]; + return JSON.parse(safeatob(payload)); } /** From 8061bb1d786d0ca8d4eb685af5c0570c78fd234a Mon Sep 17 00:00:00 2001 From: Mohammad Shahbaz Alam Date: Mon, 8 Apr 2024 13:14:49 +0530 Subject: [PATCH 2/2] Update DEFAULT_CHAIN_CONFIG to sepolia --- src/constants.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 5fb6f3a8..872851eb 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -4,10 +4,10 @@ import { ec as EllipticCurve } from "elliptic"; export const DEFAULT_CHAIN_CONFIG: CustomChainConfig = { chainNamespace: CHAIN_NAMESPACES.EIP155, - chainId: "0x5", - rpcTarget: "https://rpc.ankr.com/eth_goerli", - displayName: "Goerli Testnet", - blockExplorer: "https://goerli.etherscan.io", + chainId: "0xaa36a7", + rpcTarget: "https://rpc.ankr.com/eth_sepolia", + displayName: "Ethereum Sepolia Testnet", + blockExplorer: "https://sepolia.etherscan.io", ticker: "ETH", tickerName: "Ethereum", decimals: 18,