Skip to content

Commit 9da30cb

Browse files
Merge pull request #124 from torusresearch/feat/update-endpoints
update metadata endpoint etc.
2 parents eb36f01 + 45cc684 commit 9da30cb

File tree

13 files changed

+1528
-1164
lines changed

13 files changed

+1528
-1164
lines changed

package-lock.json

Lines changed: 1451 additions & 1067 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,41 +24,41 @@
2424
"@babel/runtime": "7.x"
2525
},
2626
"dependencies": {
27-
"@toruslabs/constants": "^13.0.2",
27+
"@toruslabs/constants": "^13.1.0",
2828
"@toruslabs/eccrypto": "^4.0.0",
2929
"@toruslabs/http-helpers": "^5.0.0",
3030
"bn.js": "^5.2.1",
3131
"elliptic": "^6.5.4",
3232
"ethereum-cryptography": "^2.1.2",
33-
"json-stable-stringify": "^1.0.2",
33+
"json-stable-stringify": "^1.1.0",
3434
"loglevel": "^1.8.1"
3535
},
3636
"devDependencies": {
3737
"@babel/register": "^7.22.15",
38-
"@babel/runtime": "^7.23.2",
38+
"@babel/runtime": "^7.23.4",
3939
"@toruslabs/config": "^2.0.2",
40-
"@toruslabs/eslint-config-typescript": "^3.0.1",
41-
"@toruslabs/fetch-node-details": "^13.0.2",
42-
"@toruslabs/torus-scripts": "^5.0.5",
43-
"@types/chai": "^4.3.8",
44-
"@types/elliptic": "^6.4.15",
40+
"@toruslabs/eslint-config-typescript": "^3.0.3",
41+
"@toruslabs/fetch-node-details": "^13.1.1",
42+
"@toruslabs/torus-scripts": "^5.1.0",
43+
"@types/chai": "^4.3.11",
44+
"@types/elliptic": "^6.4.18",
4545
"@types/faker": "^5.5.3",
46-
"@types/json-stable-stringify": "^1.0.34",
47-
"@types/jsonwebtoken": "^9.0.3",
48-
"@types/mocha": "^10.0.2",
46+
"@types/json-stable-stringify": "^1.0.36",
47+
"@types/jsonwebtoken": "^9.0.5",
48+
"@types/mocha": "^10.0.6",
4949
"chai": "^4.3.10",
5050
"cross-env": "^7.0.3",
5151
"dotenv": "^16.3.1",
52-
"eslint": "^8.51.0",
52+
"eslint": "^8.54.0",
5353
"faker": "^5.5.3",
5454
"husky": "^8.0.3",
5555
"jsonwebtoken": "^9.0.2",
56-
"lint-staged": "^14.0.1",
56+
"lint-staged": "^15.1.0",
5757
"mocha": "^10.2.0",
58-
"prettier": "^3.0.3",
58+
"prettier": "^3.1.0",
5959
"rimraf": "^5.0.5",
6060
"ts-node": "^10.9.1",
61-
"typescript": "^5.2.2"
61+
"typescript": "^5.3.2"
6262
},
6363
"repository": {
6464
"type": "git",

src/constants.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,3 @@ export const JRPC_METHODS = {
44
IMPORT_SHARE: "ImportShare",
55
GET_SHARE_OR_KEY_ASSIGN: "GetShareOrKeyAssign",
66
};
7-
8-
export const LEGACY_METADATA_HOST = "https://metadata.tor.us";

src/torus.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
import { INodePub, JRPCResponse, LEGACY_NETWORKS_ROUTE_MAP, SIGNER_MAP, TORUS_LEGACY_NETWORK_TYPE, TORUS_NETWORK_TYPE } from "@toruslabs/constants";
1+
import {
2+
INodePub,
3+
JRPCResponse,
4+
LEGACY_NETWORKS_ROUTE_MAP,
5+
METADATA_MAP,
6+
SIGNER_MAP,
7+
TORUS_LEGACY_NETWORK_TYPE,
8+
TORUS_NETWORK_TYPE,
9+
} from "@toruslabs/constants";
210
import { decrypt, Ecies, encrypt, generatePrivate, getPublic } from "@toruslabs/eccrypto";
311
import { generateJsonRPCObject, get, post, setAPIKey, setEmbedHost } from "@toruslabs/http-helpers";
412
import BN from "bn.js";
513
import { curve, ec as EC } from "elliptic";
614
import stringify from "json-stable-stringify";
715

816
import { config } from "./config";
9-
import { LEGACY_METADATA_HOST } from "./constants";
1017
import {
1118
encParamsBufToHex,
1219
generateAddressFromPrivKey,
@@ -63,23 +70,16 @@ class Torus {
6370

6471
private legacyMetadataHost: string;
6572

66-
constructor({
67-
enableOneKey = false,
68-
clientId,
69-
network,
70-
serverTimeOffset = 0,
71-
allowHost = "https://signer.tor.us/api/allow",
72-
legacyMetadataHost = LEGACY_METADATA_HOST,
73-
}: TorusCtorOptions) {
73+
constructor({ enableOneKey = false, clientId, network, serverTimeOffset = 0, allowHost, legacyMetadataHost }: TorusCtorOptions) {
7474
if (!clientId) throw Error("Please provide a valid clientId in constructor");
7575
if (!network) throw Error("Please provide a valid network in constructor");
7676
this.ec = new EC("secp256k1");
7777
this.serverTimeOffset = serverTimeOffset || 0; // ms
7878
this.network = network;
7979
this.clientId = clientId;
80-
this.allowHost = allowHost;
80+
this.allowHost = allowHost || `${SIGNER_MAP[network]}/api/allow`;
8181
this.enableOneKey = enableOneKey;
82-
this.legacyMetadataHost = legacyMetadataHost;
82+
this.legacyMetadataHost = legacyMetadataHost || METADATA_MAP[network as TORUS_LEGACY_NETWORK_TYPE];
8383
this.signerHost = `${SIGNER_MAP[network as TORUS_LEGACY_NETWORK_TYPE]}/api/sign`;
8484
}
8585

test/aqua.test.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ describe("torus utils aqua", function () {
1818

1919
beforeEach("one time execution before all tests", async function () {
2020
torus = new TorusUtils({
21-
// signerHost: "https://signer-polygon.tor.us/api/sign",
22-
allowHost: "https://signer-polygon.tor.us/api/allow",
2321
network: "aqua",
2422
clientId: "YOUR_CLIENT_ID",
2523
});
@@ -48,7 +46,7 @@ describe("torus utils aqua", function () {
4846
upgraded: false,
4947
typeOfUser: "v1",
5048
},
51-
nodesData: { nodeIndexes: [] },
49+
nodesData: result.nodesData,
5250
});
5351
});
5452

@@ -57,7 +55,7 @@ describe("torus utils aqua", function () {
5755
const verifierDetails = { verifier, verifierId: TORUS_TEST_EMAIL };
5856
const { torusNodeEndpoints, torusNodePub } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails);
5957
const result1 = (await torus.getUserTypeAndAddress(torusNodeEndpoints, torusNodePub, verifierDetails)) as TorusPublicKey;
60-
expect(result1.finalKeyData.evmAddress).to.equal("0xDfA967285AC699A70DA340F60d00DB19A272639d");
58+
expect(result1.finalKeyData.evmAddress).to.equal("0x79F06350eF34Aeed4BE68e26954D405D573f1438");
6159
expect(result1.metadata.typeOfUser).to.equal("v1");
6260
expect(result1).eql({
6361
oAuthKeyData: {
@@ -76,7 +74,7 @@ describe("torus utils aqua", function () {
7674
upgraded: false,
7775
typeOfUser: "v1",
7876
},
79-
nodesData: { nodeIndexes: [] },
77+
nodesData: result1.nodesData,
8078
});
8179

8280
const v2Verifier = "tkey-google-aqua";
@@ -105,7 +103,7 @@ describe("torus utils aqua", function () {
105103
upgraded: false,
106104
typeOfUser: "v1",
107105
},
108-
nodesData: { nodeIndexes: [] },
106+
nodesData: result2.nodesData,
109107
});
110108

111109
// 2/n user
@@ -133,7 +131,7 @@ describe("torus utils aqua", function () {
133131
upgraded: false,
134132
typeOfUser: "v1",
135133
},
136-
nodesData: { nodeIndexes: [] },
134+
nodesData: result3.nodesData,
137135
});
138136
});
139137

@@ -170,9 +168,9 @@ describe("torus utils aqua", function () {
170168
Y: "63795690a33e575ee12d832935d563c2b5f2e1b1ffac63c32a4674152f68cb3f",
171169
privKey: "f726ce4ac79ae4475d72633c94769a8817aff35eebe2d4790aed7b5d8a84aa1d",
172170
},
173-
sessionData: { sessionTokenData: [], sessionAuthKey: "" },
171+
sessionData: result.sessionData,
174172
metadata: { pubNonce: undefined, nonce: new BN(0), typeOfUser: "v1", upgraded: null },
175-
nodesData: { nodeIndexes: [] },
173+
nodesData: result.nodesData,
176174
});
177175
});
178176

@@ -208,9 +206,9 @@ describe("torus utils aqua", function () {
208206
Y: "f963f2d08ed4dd0da9b8a8d74c6fdaeef7bdcde31f84fcce19fa2173d40b2c10",
209207
privKey: "488d39ac548e15cfb0eaf161d86496e1645b09437df21311e24a56c4efd76355",
210208
},
211-
sessionData: { sessionTokenData: [], sessionAuthKey: "" },
209+
sessionData: result.sessionData,
212210
metadata: { pubNonce: undefined, nonce: new BN(0), typeOfUser: "v1", upgraded: null },
213-
nodesData: { nodeIndexes: [] },
211+
nodesData: result.nodesData,
214212
});
215213
});
216214
});

test/celeste.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ describe("torus utils celeste", function () {
1818

1919
beforeEach("one time execution before all tests", async function () {
2020
torus = new TorusUtils({
21-
// signerHost: "https://signer-polygon.tor.us/api/sign",
22-
allowHost: "https://signer-polygon.tor.us/api/allow",
2321
network: "celeste",
2422
clientId: "YOUR_CLIENT_ID",
2523
});

test/cyan.test.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ describe("torus utils cyan", function () {
1818

1919
beforeEach("one time execution before all tests", async function () {
2020
torus = new TorusUtils({
21-
// signerHost: "https://signer-polygon.tor.us/api/sign",
22-
allowHost: "https://signer-polygon.tor.us/api/allow",
2321
network: "cyan",
2422
clientId: "YOUR_CLIENT_ID",
2523
});
@@ -48,7 +46,7 @@ describe("torus utils cyan", function () {
4846
upgraded: false,
4947
typeOfUser: "v1",
5048
},
51-
nodesData: { nodeIndexes: [] },
49+
nodesData: result.nodesData,
5250
});
5351
});
5452

@@ -76,7 +74,7 @@ describe("torus utils cyan", function () {
7674
upgraded: false,
7775
typeOfUser: "v1",
7876
},
79-
nodesData: { nodeIndexes: [] },
77+
nodesData: result1.nodesData,
8078
});
8179

8280
const v2Verifier = "tkey-google-cyan";
@@ -108,7 +106,7 @@ describe("torus utils cyan", function () {
108106
upgraded: false,
109107
typeOfUser: "v2",
110108
},
111-
nodesData: { nodeIndexes: [] },
109+
nodesData: result2.nodesData,
112110
});
113111
// 2/n user
114112
const v2nTestEmail = "caspertorus@gmail.com";
@@ -138,7 +136,7 @@ describe("torus utils cyan", function () {
138136
upgraded: false,
139137
typeOfUser: "v2",
140138
},
141-
nodesData: { nodeIndexes: [] },
139+
nodesData: result3.nodesData,
142140
});
143141
});
144142

@@ -177,7 +175,7 @@ describe("torus utils cyan", function () {
177175
privKey: "5db51619684b32a2ff2375b4c03459d936179dfba401cb1c176b621e8a2e4ac8",
178176
},
179177
metadata: { pubNonce: undefined, nonce: new BN(0), typeOfUser: "v1", upgraded: null },
180-
nodesData: { nodeIndexes: result.nodesData.nodeIndexes },
178+
nodesData: result.nodesData,
181179
});
182180
});
183181

@@ -215,7 +213,7 @@ describe("torus utils cyan", function () {
215213
privKey: "45a5b62c4ff5490baa75d33bf4f03ba6c5b0095678b0f4055312eef7b780b7bf",
216214
},
217215
metadata: { pubNonce: undefined, nonce: new BN(0), typeOfUser: "v1", upgraded: null },
218-
nodesData: { nodeIndexes: result.nodesData.nodeIndexes },
216+
nodesData: result.nodesData,
219217
});
220218
});
221219
});

test/mainnet.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe("torus utils mainnet", function () {
4646
upgraded: false,
4747
typeOfUser: "v1",
4848
},
49-
nodesData: { nodeIndexes: [] },
49+
nodesData: result.nodesData,
5050
});
5151
});
5252

@@ -74,7 +74,7 @@ describe("torus utils mainnet", function () {
7474
upgraded: false,
7575
typeOfUser: "v1",
7676
},
77-
nodesData: { nodeIndexes: [] },
77+
nodesData: result1.nodesData,
7878
});
7979

8080
const v2Verifier = "tkey-google";
@@ -106,7 +106,7 @@ describe("torus utils mainnet", function () {
106106
upgraded: false,
107107
typeOfUser: "v2",
108108
},
109-
nodesData: { nodeIndexes: [] },
109+
nodesData: result2.nodesData,
110110
});
111111

112112
// 2/n user
@@ -134,7 +134,7 @@ describe("torus utils mainnet", function () {
134134
upgraded: false,
135135
typeOfUser: "v1",
136136
},
137-
nodesData: { nodeIndexes: [] },
137+
nodesData: result3.nodesData,
138138
});
139139
});
140140

@@ -178,7 +178,7 @@ describe("torus utils mainnet", function () {
178178
privKey: "0129494416ab5d5f674692b39fa49680e07d3aac01b9683ee7650e40805d4c44",
179179
},
180180
metadata: { pubNonce: undefined, nonce: new BN(0), typeOfUser: "v1", upgraded: null },
181-
nodesData: { nodeIndexes: result.nodesData.nodeIndexes },
181+
nodesData: result.nodesData,
182182
});
183183
});
184184

@@ -216,7 +216,7 @@ describe("torus utils mainnet", function () {
216216
privKey: "f55d89088a0c491d797c00da5b2ed6dc9c269c960ff121e45f255d06a91c6534",
217217
},
218218
metadata: { pubNonce: undefined, nonce: new BN(0), typeOfUser: "v1", upgraded: null },
219-
nodesData: { nodeIndexes: result.nodesData.nodeIndexes },
219+
nodesData: result.nodesData,
220220
});
221221
});
222222
});

test/onekey.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe("torus onekey", function () {
4949
upgraded: false,
5050
typeOfUser: "v1",
5151
},
52-
nodesData: { nodeIndexes: [] },
52+
nodesData: publicAddress.nodesData,
5353
});
5454
});
5555

@@ -91,7 +91,7 @@ describe("torus onekey", function () {
9191
typeOfUser: "v2",
9292
upgraded: false,
9393
},
94-
nodesData: { nodeIndexes: retrieveSharesResponse.nodesData.nodeIndexes },
94+
nodesData: retrieveSharesResponse.nodesData,
9595
});
9696
});
9797

@@ -138,7 +138,7 @@ describe("torus onekey", function () {
138138
typeOfUser: "v2",
139139
upgraded: false,
140140
},
141-
nodesData: { nodeIndexes: retrieveSharesResponse.nodesData.nodeIndexes },
141+
nodesData: retrieveSharesResponse.nodesData,
142142
});
143143
});
144144

@@ -210,7 +210,7 @@ describe("torus onekey", function () {
210210
typeOfUser: "v2",
211211
upgraded: false,
212212
},
213-
nodesData: { nodeIndexes: retrieveSharesResponse.nodesData.nodeIndexes },
213+
nodesData: retrieveSharesResponse.nodesData,
214214
});
215215
});
216216
});

0 commit comments

Comments
 (0)