Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release #166

Merged
merged 12 commits into from
Oct 7, 2024
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@toruslabs/torus.js",
"version": "15.0.5",
"version": "15.1.0-0",
"description": "Handle communication with torus nodes",
"main": "dist/lib.cjs/index.js",
"module": "dist/lib.esm/index.js",
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export const JRPC_METHODS = {
GET_OR_SET_KEY: "GetPubKeyOrKeyAssign",
VERIFIER_LOOKUP: "VerifierLookupRequest",
COMMITMENT_REQUEST: "CommitmentRequest",
IMPORT_SHARES: "ImportShares",
GET_SHARE_OR_KEY_ASSIGN: "GetShareOrKeyAssign",
Expand Down
23 changes: 20 additions & 3 deletions src/helpers/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ec as EC } from "elliptic";
import { keccak256 as keccakHash } from "ethereum-cryptography/keccak";
import JsonStringify from "json-stable-stringify";

import { CommitmentRequestResult, EciesHex, KeyType, VerifierLookupResponse } from "../interfaces";
import { CommitmentRequestResult, EciesHex, GetORSetKeyResponse, KeyType, VerifierLookupResponse } from "../interfaces";

export function keccak256(a: Buffer): string {
const hash = Buffer.from(keccakHash(a)).toString("hex");
Expand All @@ -28,8 +28,8 @@ export const getKeyCurve = (keyType: KeyType) => {
// For ex: some fields returns by nodes might be different from each other
// like created_at field might vary and nonce_data might not be returned by all nodes because
// of the metadata implementation in sapphire.
export const normalizeKeysResult = (result: VerifierLookupResponse) => {
const finalResult: Pick<VerifierLookupResponse, "keys" | "is_new_key"> = {
export const normalizeKeysResult = (result: GetORSetKeyResponse) => {
const finalResult: Pick<GetORSetKeyResponse, "keys" | "is_new_key"> = {
keys: [],
is_new_key: result.is_new_key,
};
Expand All @@ -46,6 +46,23 @@ export const normalizeKeysResult = (result: VerifierLookupResponse) => {
return finalResult;
};

export const normalizeLookUpResult = (result: VerifierLookupResponse) => {
const finalResult: Pick<VerifierLookupResponse, "keys"> = {
keys: [],
};
if (result && result.keys && result.keys.length > 0) {
const finalKey = result.keys[0];
finalResult.keys = [
{
pub_key_X: finalKey.pub_key_X,
pub_key_Y: finalKey.pub_key_Y,
address: finalKey.address,
},
];
}
return finalResult;
};

export const kCombinations = (s: number | number[], k: number): number[][] => {
let set = s;
if (typeof set === "number") {
Expand Down
1 change: 1 addition & 0 deletions src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from "./keyUtils";
export * from "./langrangeInterpolatePoly";
export * from "./metadataUtils";
export * from "./nodeUtils";
export * from "./tssPubKeyUtils";
Loading