Skip to content

Commit 5881a07

Browse files
Merge pull request #163 from torusresearch/feat/remove-commitments
make commitment request optional
2 parents 7df0374 + 09a5c8d commit 5881a07

13 files changed

+2163
-1377
lines changed

package-lock.json

+1,102-819
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@toruslabs/torus.js",
3-
"version": "15.0.0-alpha.1",
3+
"version": "15.0.2",
44
"description": "Handle communication with torus nodes",
55
"main": "dist/lib.cjs/index.js",
66
"module": "dist/lib.esm/index.js",
@@ -25,23 +25,23 @@
2525
},
2626
"dependencies": {
2727
"@toruslabs/constants": "^14.0.0",
28+
"@toruslabs/bs58": "^1.0.0",
2829
"@toruslabs/eccrypto": "^5.0.4",
2930
"@toruslabs/http-helpers": "^7.0.0",
3031
"bn.js": "^5.2.1",
3132
"elliptic": "^6.5.6",
32-
"bs58": "^6.0.0",
3333
"ethereum-cryptography": "^2.2.1",
3434
"json-stable-stringify": "^1.1.1",
3535
"loglevel": "^1.9.1"
3636
},
3737
"devDependencies": {
3838
"@babel/register": "^7.24.6",
3939
"@babel/runtime": "^7.25.0",
40-
"@toruslabs/config": "^2.1.0",
41-
"@toruslabs/eslint-config-typescript": "^3.3.1",
40+
"@toruslabs/config": "^2.2.0",
41+
"@toruslabs/eslint-config-typescript": "^3.3.3",
4242
"@toruslabs/fetch-node-details": "^14.0.1",
43-
"@toruslabs/torus-scripts": "^6.0.1",
44-
"@types/chai": "^4.3.16",
43+
"@toruslabs/torus-scripts": "^6.1.1",
44+
"@types/chai": "^4.3.17",
4545
"@types/elliptic": "^6.4.18",
4646
"@types/faker": "^5.5.3",
4747
"@types/json-stable-stringify": "^1.0.36",
@@ -55,7 +55,7 @@
5555
"faker": "^5.5.3",
5656
"husky": "^9.1.4",
5757
"jsonwebtoken": "^9.0.2",
58-
"lint-staged": "^15.2.7",
58+
"lint-staged": "^15.2.8",
5959
"mocha": "^10.7.0",
6060
"prettier": "^3.3.3",
6161
"rimraf": "^6.0.1",

src/constants.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export const JRPC_METHODS = {
22
GET_OR_SET_KEY: "GetPubKeyOrKeyAssign",
3+
VERIFIER_LOOKUP: "VerifierLookupRequest",
34
COMMITMENT_REQUEST: "CommitmentRequest",
45
IMPORT_SHARES: "ImportShares",
56
GET_SHARE_OR_KEY_ASSIGN: "GetShareOrKeyAssign",

src/helpers/common.ts

+20-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { ec as EC } from "elliptic";
55
import { keccak256 as keccakHash } from "ethereum-cryptography/keccak";
66
import JsonStringify from "json-stable-stringify";
77

8-
import { CommitmentRequestResult, EciesHex, KeyType, VerifierLookupResponse } from "../interfaces";
8+
import { CommitmentRequestResult, EciesHex, GetORSetKeyResponse, KeyType, VerifierLookupResponse } from "../interfaces";
99

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

49+
export const normalizeLookUpResult = (result: VerifierLookupResponse) => {
50+
const finalResult: Pick<VerifierLookupResponse, "keys"> = {
51+
keys: [],
52+
};
53+
if (result && result.keys && result.keys.length > 0) {
54+
const finalKey = result.keys[0];
55+
finalResult.keys = [
56+
{
57+
pub_key_X: finalKey.pub_key_X,
58+
pub_key_Y: finalKey.pub_key_Y,
59+
address: finalKey.address,
60+
},
61+
];
62+
}
63+
return finalResult;
64+
};
65+
4966
export const kCombinations = (s: number | number[], k: number): number[][] => {
5067
let set = s;
5168
if (typeof set === "number") {

src/helpers/keyUtils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import { bs58 } from "@toruslabs/bs58";
12
import { INodePub, KEY_TYPE } from "@toruslabs/constants";
23
import { Ecies, encrypt } from "@toruslabs/eccrypto";
34
import BN from "bn.js";
4-
import base58 from "bs58";
55
import { curve, ec as EC } from "elliptic";
66
import { keccak256 as keccakHash } from "ethereum-cryptography/keccak";
77
import { sha512 } from "ethereum-cryptography/sha512";
@@ -142,7 +142,7 @@ function generateAddressFromEcKey(keyType: KeyType, key: EC.KeyPair): string {
142142
return toChecksumAddress(evmAddressLower);
143143
} else if (keyType === KEY_TYPE.ED25519) {
144144
const publicKey = encodeEd25519Point(key.getPublic());
145-
const address = base58.encode(publicKey);
145+
const address = bs58.encode(publicKey);
146146
return address;
147147
}
148148
throw new Error(`Invalid keyType: ${keyType}`);

0 commit comments

Comments
 (0)