Skip to content

Commit

Permalink
fix review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshu committed Dec 21, 2023
1 parent 6760d85 commit 0b9aff1
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 12 deletions.
6 changes: 5 additions & 1 deletion src/Point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ class Point {
encode(enc: string): Buffer {
switch (enc) {
case "arr":
return Buffer.concat([Buffer.from("04", "hex"), Buffer.from(this.x.toString("hex"), "hex"), Buffer.from(this.y.toString("hex"), "hex")]);
return Buffer.concat([
Buffer.from("04", "hex"),
Buffer.from(this.x.toString("hex", 64), "hex"),
Buffer.from(this.y.toString("hex", 64), "hex"),
]);
case "elliptic-compressed": {
const key = this.ecCurve.keyFromPublic({ x: this.x.toString("hex", 64), y: this.y.toString("hex", 64) }, "hex");
return Buffer.from(key.getPublic(true, "hex"));
Expand Down
4 changes: 2 additions & 2 deletions src/Share.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class Share {

toJSON(): StringifiedType {
return {
share: this.share.toString("hex"),
shareIndex: this.shareIndex.toString("hex"),
share: this.share.toString("hex", 64),
shareIndex: this.shareIndex.toString("hex", 64),
};
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/helpers/common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Ecies } from "@toruslabs/eccrypto";
import { BN } from "bn.js";
import JsonStringify from "json-stable-stringify";

import { EciesHex, VerifierLookupResponse } from "../interfaces";
Expand Down Expand Up @@ -89,6 +90,6 @@ export function encParamsHexToBuf(eciesData: Omit<EciesHex, "ciphertext">): Omit
export function getProxyCoordinatorEndpointIndex(endpoints: string[], verifier: string, verifierId: string) {
const verifierIdStr = `${verifier}${verifierId}`;
const hashedVerifierId = keccak256(Buffer.from(verifierIdStr, "utf8"));
const proxyEndpointNum = parseInt(hashedVerifierId, 16) % endpoints.length;
const proxyEndpointNum = new BN(hashedVerifierId, "hex").mod(new BN(endpoints.length)).toNumber();
return proxyEndpointNum;
}
10 changes: 5 additions & 5 deletions src/torus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class Torus {

// generate temporary private and public key that is used to secure receive shares
const tmpKey = generatePrivate();
const pubKey = getPublic(tmpKey).toString("hex");
const pubKey = getPublic(tmpKey).toString("hex", 64);
const pubKeyX = pubKey.slice(2, 66);
const pubKeyY = pubKey.slice(66);
const tokenCommitment = keccak256(Buffer.from(idToken, "utf8"));
Expand Down Expand Up @@ -431,8 +431,8 @@ class Torus {
if (!oAuthKey) throw new Error("Invalid private key returned");

const oAuthPubKey = derivePubKey(this.ec, oAuthKey);
const oAuthKeyX = oAuthPubKey.getX().toString("hex");
const oAuthKeyY = oAuthPubKey.getY().toString("hex");
const oAuthKeyX = oAuthPubKey.getX().toString("hex", 64);
const oAuthKeyY = oAuthPubKey.getY().toString("hex", 64);

let metadataNonce: BN;
let finalPubKey: curve.base.BasePoint;
Expand All @@ -456,13 +456,13 @@ class Torus {
// for imported keys in legacy networks
metadataNonce = await getMetadata(this.legacyMetadataHost, { pub_key_X: oAuthKeyX, pub_key_Y: oAuthKeyY });
const privateKeyWithNonce = oAuthKey.add(metadataNonce).umod(this.ec.curve.n);
finalPubKey = this.ec.keyFromPrivate(privateKeyWithNonce.toString("hex"), "hex").getPublic();
finalPubKey = this.ec.keyFromPrivate(privateKeyWithNonce.toString("hex", 64), "hex").getPublic();
}
} else {
// for imported keys in legacy networks
metadataNonce = await getMetadata(this.legacyMetadataHost, { pub_key_X: oAuthKeyX, pub_key_Y: oAuthKeyY });
const privateKeyWithNonce = oAuthKey.add(metadataNonce).umod(this.ec.curve.n);
finalPubKey = this.ec.keyFromPrivate(privateKeyWithNonce.toString("hex"), "hex").getPublic();
finalPubKey = this.ec.keyFromPrivate(privateKeyWithNonce.toString("hex", 64), "hex").getPublic();
}

const oAuthKeyAddress = generateAddressFromPrivKey(this.ec, oAuthKey);
Expand Down
3 changes: 1 addition & 2 deletions test/sapphire_devnet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const TORUS_TEST_VERIFIER = "torus-test-health";
const TORUS_TEST_AGGREGATE_VERIFIER = "torus-test-health-aggregate";
const HashEnabledVerifier = "torus-test-verifierid-hash";

describe.only("torus utils sapphire devnet", function () {
describe("torus utils sapphire devnet", function () {
let torus: TorusUtils;
let TORUS_NODE_MANAGER: NodeManager;

Expand Down Expand Up @@ -226,7 +226,6 @@ describe.only("torus utils sapphire devnet", function () {
nodesData: result.nodesData,
});
});
// we are working on a new implementation for import sss keys, so skipping it for now.
it("should fetch public address of imported user", async function () {
const verifierDetails = { verifier: TORUS_TEST_VERIFIER, verifierId: TORUS_IMPORT_EMAIL };
const nodeDetails = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails);
Expand Down
1 change: 0 additions & 1 deletion test/sapphire_devnet_ed25519.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ describe.skip("torus utils ed25519 sapphire devnet", function () {
nodesData: result.nodesData,
});
});
// we are working on a new implementation for import sss keys, so skipping it for now.
it("should fetch public address of imported user", async function () {
const verifierDetails = { verifier: TORUS_TEST_VERIFIER, verifierId: TORUS_IMPORT_EMAIL };
const nodeDetails = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails);
Expand Down

0 comments on commit 0b9aff1

Please sign in to comment.