Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
build:
strategy:
matrix:
node: ["22.x"]
node: ["24.x"]
os: [ubuntu-latest]

runs-on: ${{ matrix.os }}
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
>=20.x
>=24.x
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ This module is distributed in 3 formats

- `esm` build `dist/lib.esm/index.js` in es6 format
- `commonjs` build `dist/lib.cjs/index.js` in es5 format
- `umd` build `dist/customauth.umd.min.js` in es5 format without polyfilling corejs minified

By default, the appropriate format is used for your specified usecase
You can use a different format (if you know what you're doing) by referencing the correct file
Expand Down
6,689 changes: 2,220 additions & 4,469 deletions package-lock.json

Large diffs are not rendered by default.

44 changes: 22 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
"description": "CustomAuth login with torus to get user private key",
"main": "dist/lib.cjs/index.js",
"module": "dist/lib.esm/index.js",
"unpkg": "dist/customauth.umd.min.js",
"jsdelivr": "dist/customauth.umd.min.js",
"unpkg": "dist/lib.esm/index.js",
"jsdelivr": "dist/lib.esm/index.js",
"types": "dist/lib.cjs/types/index.d.ts",
"sideEffects": false,
"scripts": {
"build": "torus-scripts build",
"start": "torus-scripts start",
"release": "torus-scripts release",
"lint:ts": "eslint --fix 'src/**/*.ts'",
"lint:ts": "torus-scripts lint",
"prepack": "npm run build",
"test": "echo \"Error: no test specified\" && exit 1",
"prepare": "husky"
Expand All @@ -23,7 +23,7 @@
],
"peerDependencies": {
"@babel/runtime": "^7.x",
"@sentry/core": "^9.x"
"@sentry/core": "^10.x"
},
"peerDependenciesMeta": {
"@sentry/core": {
Expand All @@ -32,30 +32,30 @@
},
"dependencies": {
"@chaitanyapotti/register-service-worker": "^1.7.4",
"@toruslabs/broadcast-channel": "^12.0.0",
"@toruslabs/constants": "^15.0.0",
"@toruslabs/eccrypto": "^6.2.0",
"@toruslabs/fetch-node-details": "^15.0.0",
"@toruslabs/http-helpers": "^8.1.1",
"@toruslabs/metadata-helpers": "^7.0.2",
"@toruslabs/session-manager": "^4.0.2",
"@toruslabs/torus.js": "^16.0.0",
"@toruslabs/broadcast-channel": "^13.0.0",
"@toruslabs/constants": "^16.0.0",
"@toruslabs/eccrypto": "^7.0.0",
"@toruslabs/fetch-node-details": "^16.0.0",
"@toruslabs/http-helpers": "^9.0.0",
"@toruslabs/metadata-helpers": "^8.0.0",
"@toruslabs/torus.js": "file:toruslabs-torus.js-16.0.0.tgz",
"base64url": "^3.0.1",
"bowser": "^2.12.1",
"bowser": "^2.14.1",
"deepmerge": "^4.3.1",
"events": "^3.3.0",
"loglevel": "^1.9.2"
},
"devDependencies": {
"@sentry/core": "^9.12.0",
"@toruslabs/config": "^3.1.0",
"@toruslabs/eslint-config-typescript": "^4.1.4",
"@toruslabs/torus-scripts": "^7.1.6",
"@sentry/core": "^10.38.0",
"@toruslabs/config": "^4.0.0",
"@toruslabs/eslint-config-typescript": "^5.0.0",
"@toruslabs/torus-scripts": "^8.0.0",
"@types/events": "^3.0.3",
"eslint": "^9.39.1",
"husky": "^9.1.7",
"lint-staged": "^16.2.6",
"prettier": "^3.6.2",
"rimraf": "^6.1.0",
"lint-staged": "^16.2.7",
"prettier": "^3.8.1",
"rimraf": "^6.1.2",
"typed-emitter": "^2.1.0",
"typescript": "^5.9.3"
},
Expand Down Expand Up @@ -87,7 +87,7 @@
"direct auth"
],
"engines": {
"node": ">=20.x",
"npm": ">=9.x"
"node": ">=22.x",
"npm": ">=10.x"
}
}
4 changes: 2 additions & 2 deletions src/login.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type INodeDetails, TORUS_NETWORK_TYPE } from "@toruslabs/constants";
import { NodeDetailManager } from "@toruslabs/fetch-node-details";
import { keccak256, type KeyType, Torus, TorusKey } from "@toruslabs/torus.js";
import { keccak256, type KeyType, Torus, TorusKey, utf8ToBytes } from "@toruslabs/torus.js";

import { createHandler } from "./handlers/HandlerFactory";
import { registerServiceWorker } from "./registerServiceWorker";
Expand Down Expand Up @@ -214,7 +214,7 @@ export class CustomAuth {
if (groupedAuthConnectionId) {
verifierParams["verify_params"] = [{ verifier_id: userId, idtoken: finalIdToken }];
verifierParams["sub_verifier_ids"] = [authConnectionId];
aggregateIdToken = keccak256(Buffer.from(finalIdToken, "utf8")).slice(2);
aggregateIdToken = keccak256(utf8ToBytes(finalIdToken)).slice(2);
}

const nodeDetails = await this.sentryHandler.startSpan(
Expand Down
16 changes: 8 additions & 8 deletions src/utils/StorageHelper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SESSION_SERVER_API_URL } from "@toruslabs/constants";
import { getPublic, sign } from "@toruslabs/eccrypto";
import { post } from "@toruslabs/http-helpers";
import { decryptData, encryptData, keccak256 } from "@toruslabs/metadata-helpers";
import { bytesToHex, decryptData, encryptData, keccak256, utf8ToBytes } from "@toruslabs/metadata-helpers";

import { REDIRECT_PARAMS_STORAGE_METHOD, REDIRECT_PARAMS_STORAGE_METHOD_TYPE } from "./enums";
import { storageAvailable } from "./helpers";
Expand Down Expand Up @@ -42,11 +42,11 @@ export class StorageHelper<T> {
if (!this.isInitialized) throw new Error("StorageHelper is not initialized");
if (this.localStorageAvailable) window.localStorage.setItem(key, JSON.stringify(params));
// if (this.currentStorageMethod === REDIRECT_PARAMS_STORAGE_METHOD.SERVER) {
const privKey = keccak256(Buffer.from(key, "utf8"));
const privKeyHex = privKey.toString("hex");
const publicKeyHex = getPublic(privKey).toString("hex");
const privKey = keccak256(utf8ToBytes(key));
const privKeyHex = bytesToHex(privKey);
const publicKeyHex = bytesToHex(getPublic(privKey));
const encData = await encryptData(privKeyHex, params);
const signature = (await sign(privKey, keccak256(Buffer.from(encData, "utf8")))).toString("hex");
const signature = bytesToHex(await sign(privKey, keccak256(utf8ToBytes(encData))));
await post(`${this.storageServerUrl}/v2/store/set`, { key: publicKeyHex, data: encData, signature, allowedOrigin: true });
// }
}
Expand All @@ -62,9 +62,9 @@ export class StorageHelper<T> {
}
// if (this.currentStorageMethod === REDIRECT_PARAMS_STORAGE_METHOD.SERVER) {
this.currentStorageMethod = REDIRECT_PARAMS_STORAGE_METHOD.SERVER;
const privKey = keccak256(Buffer.from(key, "utf8"));
const privKeyHex = privKey.toString("hex");
const publicKeyHex = getPublic(privKey).toString("hex");
const privKey = keccak256(utf8ToBytes(key));
const privKeyHex = bytesToHex(privKey);
const publicKeyHex = bytesToHex(getPublic(privKey));
try {
const encData: { message: string; success: boolean } = await post(`${this.storageServerUrl}/v2/store/get`, { key: publicKeyHex });
if (encData.message) {
Expand Down
16 changes: 7 additions & 9 deletions src/utils/sessionHelper.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { SessionManager } from "@toruslabs/session-manager";
import log from "loglevel";
import { SESSION_SERVER_API_URL } from "@toruslabs/constants";

import log from "./loglevel";
import { StorageHelper } from "./StorageHelper";

export async function fetchDataFromBroadcastServer<T>(identifier: string, storageServerUrl?: string) {
try {
const configManager = new SessionManager<T>({
sessionId: identifier,
sessionServerBaseUrl: storageServerUrl,
allowedOrigin: true,
});

const data = await configManager.authorizeSession();
const storageHelper = new StorageHelper<T>(storageServerUrl || SESSION_SERVER_API_URL);
storageHelper.init();
const data = await storageHelper.retrieveData(identifier);
return data;
} catch (error: unknown) {
log.error("fetch data from storage server error", error);
Expand Down
Loading