Skip to content
Merged
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
5 changes: 0 additions & 5 deletions .mocharc.yaml

This file was deleted.

24 changes: 2 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@toruslabs/torus.js",
"version": "17.1.0",
"version": "17.1.1",
"description": "Handle communication with torus nodes",
"main": "dist/lib.cjs/index.js",
"module": "dist/lib.esm/index.js",
Expand All @@ -24,7 +24,6 @@
"@babel/runtime": "7.x"
},
"dependencies": {
"@noble/curves": "^2.0.1",
"@toruslabs/constants": "^16.0.0",
"@toruslabs/eccrypto": "^7.0.0",
"@toruslabs/http-helpers": "^9.0.0",
Expand Down
23 changes: 9 additions & 14 deletions src/helpers/common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { bytesToHex as nobleBytesToHex, concatBytes as nobleConcatBytes, hexToBytes as nobleHexToBytes } from "@noble/curves/utils.js";
import { JRPCResponse } from "@toruslabs/constants";
import { Ecies } from "@toruslabs/eccrypto";
import {
Expand All @@ -9,6 +8,7 @@ import {
bytesToNumberBE,
bytesToNumberLE,
calculateMedian,
concatBytes,
Curve,
derivePubKey,
generatePrivateKey,
Expand Down Expand Up @@ -36,6 +36,7 @@ export {
bytesToNumberBE,
bytesToNumberLE,
calculateMedian,
concatBytes,
derivePubKey,
generatePrivateKey,
getEd25519,
Expand All @@ -56,11 +57,6 @@ export type { Curve };

export const bytesToBase64 = mhBytesToBase64;
export const base64ToBytes = mhBase64ToBytes;
export const concatBytes = nobleConcatBytes;

// ---------------------------------------------------------------------------
// Torus-specific helpers (NOT migrated to metadata-helpers)
// ---------------------------------------------------------------------------

export const normalizeKeysResult = (result: GetORSetKeyResponse) => {
const finalResult: Pick<GetORSetKeyResponse, "keys" | "is_new_key"> = {
Expand Down Expand Up @@ -97,23 +93,22 @@ export const normalizeLookUpResult = (result: VerifierLookupResponse) => {
return finalResult;
};

/** ECIES params: bytes → hex. Uses noble bytesToHex so round-trip with encParamsHexToBuf (noble hexToBytes) is consistent. */
export function encParamsBufToHex(encParams: Ecies): EciesHex {
return {
iv: nobleBytesToHex(encParams.iv),
ephemPublicKey: nobleBytesToHex(encParams.ephemPublicKey),
ciphertext: nobleBytesToHex(encParams.ciphertext),
mac: nobleBytesToHex(encParams.mac),
iv: bytesToHex(encParams.iv),
ephemPublicKey: bytesToHex(encParams.ephemPublicKey),
ciphertext: bytesToHex(encParams.ciphertext),
mac: bytesToHex(encParams.mac),
mode: "AES256",
};
}

/** ECIES params: hex → bytes. */
export function encParamsHexToBuf(eciesData: Omit<EciesHex, "ciphertext">): Omit<Ecies, "ciphertext"> {
return {
ephemPublicKey: nobleHexToBytes(eciesData.ephemPublicKey),
iv: nobleHexToBytes(eciesData.iv),
mac: nobleHexToBytes(eciesData.mac),
ephemPublicKey: hexToBytes(eciesData.ephemPublicKey),
iv: hexToBytes(eciesData.iv),
mac: hexToBytes(eciesData.mac),
};
}

Expand Down
4 changes: 2 additions & 2 deletions src/helpers/keyUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { mod } from "@noble/curves/abstract/modular.js";
import { hexToBytes } from "@noble/curves/utils.js";
import { INodePub, KEY_TYPE } from "@toruslabs/constants";
import { Ecies, encrypt } from "@toruslabs/eccrypto";
import {
Expand All @@ -20,8 +18,10 @@ import {
getSecp256k1,
getSecp256k1PublicKeyFromAffinePoint,
getSecpKeyFromEd25519,
hexToBytes,
keccak256,
KeyType,
mod,
toBigIntBE,
utf8ToBytes,
} from "@toruslabs/metadata-helpers";
Expand Down
6 changes: 3 additions & 3 deletions src/helpers/metadataUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export function generateMetadataParams(ecCurve: Curve, serverTimeOffset: number,
pub_key_X: pubKey.x.toString(16), // DO NOT PAD THIS. BACKEND DOESN'T
pub_key_Y: pubKey.y.toString(16), // DO NOT PAD THIS. BACKEND DOESN'T
set_data: setData,
signature: bytesToBase64(concatBytes(sig, hexToBytes("00"))),
signature: bytesToBase64(concatBytes([sig, hexToBytes("00")])),
};
}

Expand Down Expand Up @@ -137,7 +137,7 @@ export function generateNonceMetadataParams(
pub_key_Y: bigintToHex(pubKey.y),
set_data: setData,
key_type: keyType,
signature: bytesToBase64(concatBytes(sig, hexToBytes("00"))),
signature: bytesToBase64(concatBytes([sig, hexToBytes("00")])),
};
}

Expand Down Expand Up @@ -249,7 +249,7 @@ export async function getOrSetSapphireMetadataNonce(
pub_key_X: bigintToHex(pubKey.x),
pub_key_Y: bigintToHex(pubKey.y),
set_data: setData,
signature: bytesToBase64(concatBytes(sig, hexToBytes("00"))),
signature: bytesToBase64(concatBytes([sig, hexToBytes("00")])),
};
}

Expand Down
5 changes: 2 additions & 3 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type { AffinePoint as AffinePointCurve } from "@noble/curves/abstract/curve.js";
import type { INodePub, TORUS_NETWORK_TYPE } from "@toruslabs/constants";
import { Ecies } from "@toruslabs/eccrypto";
import { AffinePoint } from "@toruslabs/metadata-helpers";

import { TorusUtilsExtraParams } from "./TorusUtilsExtraParams";

export type AffinePoint = AffinePointCurve<bigint>;
export type { AffinePoint };

export interface KeyIndex {
index: string;
Expand Down
2 changes: 1 addition & 1 deletion test/configs/node.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
reporters: "verbose",
testTimeout: 10000,
testTimeout: 60000,
coverage: {
reporter: ["text"],
provider: "istanbul",
Expand Down
2 changes: 1 addition & 1 deletion test/onekey.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ describe("torus onekey", () => {
});
});

it("should be able to key assign", { timeout: 15000 }, async () => {
it("should be able to key assign", async () => {
const verifier = TORUS_TEST_VERIFIER;
const email = faker.internet.email();
const verifierDetails = { verifier, verifierId: email };
Expand Down
Loading