Skip to content

Commit

Permalink
Merge pull request #124 from torusresearch/feat/update-endpoints
Browse files Browse the repository at this point in the history
update metadata endpoint etc.
  • Loading branch information
chaitanyapotti authored Nov 29, 2023
2 parents eb36f01 + 45cc684 commit 9da30cb
Show file tree
Hide file tree
Showing 13 changed files with 1,528 additions and 1,164 deletions.
2,518 changes: 1,451 additions & 1,067 deletions package-lock.json

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,41 @@
"@babel/runtime": "7.x"
},
"dependencies": {
"@toruslabs/constants": "^13.0.2",
"@toruslabs/constants": "^13.1.0",
"@toruslabs/eccrypto": "^4.0.0",
"@toruslabs/http-helpers": "^5.0.0",
"bn.js": "^5.2.1",
"elliptic": "^6.5.4",
"ethereum-cryptography": "^2.1.2",
"json-stable-stringify": "^1.0.2",
"json-stable-stringify": "^1.1.0",
"loglevel": "^1.8.1"
},
"devDependencies": {
"@babel/register": "^7.22.15",
"@babel/runtime": "^7.23.2",
"@babel/runtime": "^7.23.4",
"@toruslabs/config": "^2.0.2",
"@toruslabs/eslint-config-typescript": "^3.0.1",
"@toruslabs/fetch-node-details": "^13.0.2",
"@toruslabs/torus-scripts": "^5.0.5",
"@types/chai": "^4.3.8",
"@types/elliptic": "^6.4.15",
"@toruslabs/eslint-config-typescript": "^3.0.3",
"@toruslabs/fetch-node-details": "^13.1.1",
"@toruslabs/torus-scripts": "^5.1.0",
"@types/chai": "^4.3.11",
"@types/elliptic": "^6.4.18",
"@types/faker": "^5.5.3",
"@types/json-stable-stringify": "^1.0.34",
"@types/jsonwebtoken": "^9.0.3",
"@types/mocha": "^10.0.2",
"@types/json-stable-stringify": "^1.0.36",
"@types/jsonwebtoken": "^9.0.5",
"@types/mocha": "^10.0.6",
"chai": "^4.3.10",
"cross-env": "^7.0.3",
"dotenv": "^16.3.1",
"eslint": "^8.51.0",
"eslint": "^8.54.0",
"faker": "^5.5.3",
"husky": "^8.0.3",
"jsonwebtoken": "^9.0.2",
"lint-staged": "^14.0.1",
"lint-staged": "^15.1.0",
"mocha": "^10.2.0",
"prettier": "^3.0.3",
"prettier": "^3.1.0",
"rimraf": "^5.0.5",
"ts-node": "^10.9.1",
"typescript": "^5.2.2"
"typescript": "^5.3.2"
},
"repository": {
"type": "git",
Expand Down
2 changes: 0 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,3 @@ export const JRPC_METHODS = {
IMPORT_SHARE: "ImportShare",
GET_SHARE_OR_KEY_ASSIGN: "GetShareOrKeyAssign",
};

export const LEGACY_METADATA_HOST = "https://metadata.tor.us";
24 changes: 12 additions & 12 deletions src/torus.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { INodePub, JRPCResponse, LEGACY_NETWORKS_ROUTE_MAP, SIGNER_MAP, TORUS_LEGACY_NETWORK_TYPE, TORUS_NETWORK_TYPE } from "@toruslabs/constants";
import {
INodePub,
JRPCResponse,
LEGACY_NETWORKS_ROUTE_MAP,
METADATA_MAP,
SIGNER_MAP,
TORUS_LEGACY_NETWORK_TYPE,
TORUS_NETWORK_TYPE,
} from "@toruslabs/constants";
import { decrypt, Ecies, encrypt, generatePrivate, getPublic } from "@toruslabs/eccrypto";
import { generateJsonRPCObject, get, post, setAPIKey, setEmbedHost } from "@toruslabs/http-helpers";
import BN from "bn.js";
import { curve, ec as EC } from "elliptic";
import stringify from "json-stable-stringify";

import { config } from "./config";
import { LEGACY_METADATA_HOST } from "./constants";
import {
encParamsBufToHex,
generateAddressFromPrivKey,
Expand Down Expand Up @@ -63,23 +70,16 @@ class Torus {

private legacyMetadataHost: string;

constructor({
enableOneKey = false,
clientId,
network,
serverTimeOffset = 0,
allowHost = "https://signer.tor.us/api/allow",
legacyMetadataHost = LEGACY_METADATA_HOST,
}: TorusCtorOptions) {
constructor({ enableOneKey = false, clientId, network, serverTimeOffset = 0, allowHost, legacyMetadataHost }: TorusCtorOptions) {
if (!clientId) throw Error("Please provide a valid clientId in constructor");
if (!network) throw Error("Please provide a valid network in constructor");
this.ec = new EC("secp256k1");
this.serverTimeOffset = serverTimeOffset || 0; // ms
this.network = network;
this.clientId = clientId;
this.allowHost = allowHost;
this.allowHost = allowHost || `${SIGNER_MAP[network]}/api/allow`;
this.enableOneKey = enableOneKey;
this.legacyMetadataHost = legacyMetadataHost;
this.legacyMetadataHost = legacyMetadataHost || METADATA_MAP[network as TORUS_LEGACY_NETWORK_TYPE];
this.signerHost = `${SIGNER_MAP[network as TORUS_LEGACY_NETWORK_TYPE]}/api/sign`;
}

Expand Down
20 changes: 9 additions & 11 deletions test/aqua.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ describe("torus utils aqua", function () {

beforeEach("one time execution before all tests", async function () {
torus = new TorusUtils({
// signerHost: "https://signer-polygon.tor.us/api/sign",
allowHost: "https://signer-polygon.tor.us/api/allow",
network: "aqua",
clientId: "YOUR_CLIENT_ID",
});
Expand Down Expand Up @@ -48,7 +46,7 @@ describe("torus utils aqua", function () {
upgraded: false,
typeOfUser: "v1",
},
nodesData: { nodeIndexes: [] },
nodesData: result.nodesData,
});
});

Expand All @@ -57,7 +55,7 @@ describe("torus utils aqua", function () {
const verifierDetails = { verifier, verifierId: TORUS_TEST_EMAIL };
const { torusNodeEndpoints, torusNodePub } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails);
const result1 = (await torus.getUserTypeAndAddress(torusNodeEndpoints, torusNodePub, verifierDetails)) as TorusPublicKey;
expect(result1.finalKeyData.evmAddress).to.equal("0xDfA967285AC699A70DA340F60d00DB19A272639d");
expect(result1.finalKeyData.evmAddress).to.equal("0x79F06350eF34Aeed4BE68e26954D405D573f1438");
expect(result1.metadata.typeOfUser).to.equal("v1");
expect(result1).eql({
oAuthKeyData: {
Expand All @@ -76,7 +74,7 @@ describe("torus utils aqua", function () {
upgraded: false,
typeOfUser: "v1",
},
nodesData: { nodeIndexes: [] },
nodesData: result1.nodesData,
});

const v2Verifier = "tkey-google-aqua";
Expand Down Expand Up @@ -105,7 +103,7 @@ describe("torus utils aqua", function () {
upgraded: false,
typeOfUser: "v1",
},
nodesData: { nodeIndexes: [] },
nodesData: result2.nodesData,
});

// 2/n user
Expand Down Expand Up @@ -133,7 +131,7 @@ describe("torus utils aqua", function () {
upgraded: false,
typeOfUser: "v1",
},
nodesData: { nodeIndexes: [] },
nodesData: result3.nodesData,
});
});

Expand Down Expand Up @@ -170,9 +168,9 @@ describe("torus utils aqua", function () {
Y: "63795690a33e575ee12d832935d563c2b5f2e1b1ffac63c32a4674152f68cb3f",
privKey: "f726ce4ac79ae4475d72633c94769a8817aff35eebe2d4790aed7b5d8a84aa1d",
},
sessionData: { sessionTokenData: [], sessionAuthKey: "" },
sessionData: result.sessionData,
metadata: { pubNonce: undefined, nonce: new BN(0), typeOfUser: "v1", upgraded: null },
nodesData: { nodeIndexes: [] },
nodesData: result.nodesData,
});
});

Expand Down Expand Up @@ -208,9 +206,9 @@ describe("torus utils aqua", function () {
Y: "f963f2d08ed4dd0da9b8a8d74c6fdaeef7bdcde31f84fcce19fa2173d40b2c10",
privKey: "488d39ac548e15cfb0eaf161d86496e1645b09437df21311e24a56c4efd76355",
},
sessionData: { sessionTokenData: [], sessionAuthKey: "" },
sessionData: result.sessionData,
metadata: { pubNonce: undefined, nonce: new BN(0), typeOfUser: "v1", upgraded: null },
nodesData: { nodeIndexes: [] },
nodesData: result.nodesData,
});
});
});
2 changes: 0 additions & 2 deletions test/celeste.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ describe("torus utils celeste", function () {

beforeEach("one time execution before all tests", async function () {
torus = new TorusUtils({
// signerHost: "https://signer-polygon.tor.us/api/sign",
allowHost: "https://signer-polygon.tor.us/api/allow",
network: "celeste",
clientId: "YOUR_CLIENT_ID",
});
Expand Down
14 changes: 6 additions & 8 deletions test/cyan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ describe("torus utils cyan", function () {

beforeEach("one time execution before all tests", async function () {
torus = new TorusUtils({
// signerHost: "https://signer-polygon.tor.us/api/sign",
allowHost: "https://signer-polygon.tor.us/api/allow",
network: "cyan",
clientId: "YOUR_CLIENT_ID",
});
Expand Down Expand Up @@ -48,7 +46,7 @@ describe("torus utils cyan", function () {
upgraded: false,
typeOfUser: "v1",
},
nodesData: { nodeIndexes: [] },
nodesData: result.nodesData,
});
});

Expand Down Expand Up @@ -76,7 +74,7 @@ describe("torus utils cyan", function () {
upgraded: false,
typeOfUser: "v1",
},
nodesData: { nodeIndexes: [] },
nodesData: result1.nodesData,
});

const v2Verifier = "tkey-google-cyan";
Expand Down Expand Up @@ -108,7 +106,7 @@ describe("torus utils cyan", function () {
upgraded: false,
typeOfUser: "v2",
},
nodesData: { nodeIndexes: [] },
nodesData: result2.nodesData,
});
// 2/n user
const v2nTestEmail = "[email protected]";
Expand Down Expand Up @@ -138,7 +136,7 @@ describe("torus utils cyan", function () {
upgraded: false,
typeOfUser: "v2",
},
nodesData: { nodeIndexes: [] },
nodesData: result3.nodesData,
});
});

Expand Down Expand Up @@ -177,7 +175,7 @@ describe("torus utils cyan", function () {
privKey: "5db51619684b32a2ff2375b4c03459d936179dfba401cb1c176b621e8a2e4ac8",
},
metadata: { pubNonce: undefined, nonce: new BN(0), typeOfUser: "v1", upgraded: null },
nodesData: { nodeIndexes: result.nodesData.nodeIndexes },
nodesData: result.nodesData,
});
});

Expand Down Expand Up @@ -215,7 +213,7 @@ describe("torus utils cyan", function () {
privKey: "45a5b62c4ff5490baa75d33bf4f03ba6c5b0095678b0f4055312eef7b780b7bf",
},
metadata: { pubNonce: undefined, nonce: new BN(0), typeOfUser: "v1", upgraded: null },
nodesData: { nodeIndexes: result.nodesData.nodeIndexes },
nodesData: result.nodesData,
});
});
});
12 changes: 6 additions & 6 deletions test/mainnet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe("torus utils mainnet", function () {
upgraded: false,
typeOfUser: "v1",
},
nodesData: { nodeIndexes: [] },
nodesData: result.nodesData,
});
});

Expand Down Expand Up @@ -74,7 +74,7 @@ describe("torus utils mainnet", function () {
upgraded: false,
typeOfUser: "v1",
},
nodesData: { nodeIndexes: [] },
nodesData: result1.nodesData,
});

const v2Verifier = "tkey-google";
Expand Down Expand Up @@ -106,7 +106,7 @@ describe("torus utils mainnet", function () {
upgraded: false,
typeOfUser: "v2",
},
nodesData: { nodeIndexes: [] },
nodesData: result2.nodesData,
});

// 2/n user
Expand Down Expand Up @@ -134,7 +134,7 @@ describe("torus utils mainnet", function () {
upgraded: false,
typeOfUser: "v1",
},
nodesData: { nodeIndexes: [] },
nodesData: result3.nodesData,
});
});

Expand Down Expand Up @@ -178,7 +178,7 @@ describe("torus utils mainnet", function () {
privKey: "0129494416ab5d5f674692b39fa49680e07d3aac01b9683ee7650e40805d4c44",
},
metadata: { pubNonce: undefined, nonce: new BN(0), typeOfUser: "v1", upgraded: null },
nodesData: { nodeIndexes: result.nodesData.nodeIndexes },
nodesData: result.nodesData,
});
});

Expand Down Expand Up @@ -216,7 +216,7 @@ describe("torus utils mainnet", function () {
privKey: "f55d89088a0c491d797c00da5b2ed6dc9c269c960ff121e45f255d06a91c6534",
},
metadata: { pubNonce: undefined, nonce: new BN(0), typeOfUser: "v1", upgraded: null },
nodesData: { nodeIndexes: result.nodesData.nodeIndexes },
nodesData: result.nodesData,
});
});
});
8 changes: 4 additions & 4 deletions test/onekey.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe("torus onekey", function () {
upgraded: false,
typeOfUser: "v1",
},
nodesData: { nodeIndexes: [] },
nodesData: publicAddress.nodesData,
});
});

Expand Down Expand Up @@ -91,7 +91,7 @@ describe("torus onekey", function () {
typeOfUser: "v2",
upgraded: false,
},
nodesData: { nodeIndexes: retrieveSharesResponse.nodesData.nodeIndexes },
nodesData: retrieveSharesResponse.nodesData,
});
});

Expand Down Expand Up @@ -138,7 +138,7 @@ describe("torus onekey", function () {
typeOfUser: "v2",
upgraded: false,
},
nodesData: { nodeIndexes: retrieveSharesResponse.nodesData.nodeIndexes },
nodesData: retrieveSharesResponse.nodesData,
});
});

Expand Down Expand Up @@ -210,7 +210,7 @@ describe("torus onekey", function () {
typeOfUser: "v2",
upgraded: false,
},
nodesData: { nodeIndexes: retrieveSharesResponse.nodesData.nodeIndexes },
nodesData: retrieveSharesResponse.nodesData,
});
});
});
Loading

0 comments on commit 9da30cb

Please sign in to comment.