-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b7495b3
commit a717bc8
Showing
13 changed files
with
193 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,11 +74,11 @@ const fetchNodeDetails = new FetchNodeDetails(); | |
const torus = new TorusUtils({ network: "mainnet", clientId: "YOUR_CLIENT_ID" }); // get your Client ID from Web3Auth Dashboard | ||
const verifier = "google"; | ||
const verifierId = "[email protected]"; | ||
const { torusNodeEndpoints } = await fetchNodeDetails.getNodeDetails(); | ||
const publicAddress = await torus.getPublicAddress(torusNodeEndpoints, { verifier, verifierId }); | ||
const { torusNodeEndpoints, torusNodePub, torusIndexes } = await fetchNodeDetails.getNodeDetails(); | ||
const publicAddress = await torus.getPublicAddress(torusNodeEndpoints, torusNodePub, { verifier, verifierId }); | ||
|
||
const idToken = "YOUR_ID_TOKEN"; | ||
const keyData = await torus.retrieveShares(torusNodeEndpoints, verifier, { verifier_id: verifierId }, idToken); | ||
const keyData = await torus.retrieveShares(torusNodeEndpoints, torusIndexes, verifier, { verifier_id: verifierId }, idToken); | ||
``` | ||
|
||
```js | ||
|
@@ -91,13 +91,15 @@ const verifier = "google"; // any verifier | |
const verifierId = "[email protected]"; // any verifier id | ||
fetchNodeDetails | ||
.getNodeDetails() | ||
.then(({ torusNodeEndpoints }) => torus.getPublicAddress(torusNodeEndpoints, { verifier, verifierId })) | ||
.then(({ torusNodeEndpoints, torusNodePub }) => torus.getPublicAddress(torusNodeEndpoints, torusNodePub, { verifier, verifierId })) | ||
.then((publicAddress) => console.log(publicAddress)); | ||
|
||
const idToken = "YOUR_ID_TOKEN"; | ||
fetchNodeDetails | ||
.getNodeDetails() | ||
.then(({ torusNodeEndpoints }) => torus.retrieveShares(torusNodeEndpoints, verifier, { verifier_id: verifierId }, idToken)) | ||
.then(({ torusNodeEndpoints, torusIndexes }) => | ||
torus.retrieveShares(torusNodeEndpoints, torusIndexes, verifier, { verifier_id: verifierId }, idToken) | ||
) | ||
.then((keyData) => console.log(keyData)); | ||
``` | ||
|
||
|
@@ -112,11 +114,11 @@ const verifier = "google"; // any verifier | |
const verifierId = "[email protected]"; // any verifier id | ||
fetchNodeDetails | ||
.getNodeDetails() | ||
.then(({ torusNodeEndpoints }) => torus.getPublicAddress(torusNodeEndpoints, { verifier, verifierId })) | ||
.then(({ torusNodeEndpoints, torusNodePub }) => torus.getPublicAddress(torusNodeEndpoints, torusNodePub, { verifier, verifierId })) | ||
.then((publicAddress) => console.log(publicAddress)); | ||
``` | ||
|
||
## Requirements | ||
|
||
- This package requires a peer dependency of `@babel/runtime` | ||
- Node 20+ | ||
- Node 16+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,8 +27,8 @@ describe("torus utils aqua", function () { | |
it("should fetch public address", async function () { | ||
const verifier = "tkey-google-aqua"; // any verifier | ||
const verifierDetails = { verifier, verifierId: TORUS_TEST_EMAIL }; | ||
const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); | ||
const result = await torus.getPublicAddress(torusNodeEndpoints, verifierDetails); | ||
const { torusNodeEndpoints, torusNodePub } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); | ||
const result = await torus.getPublicAddress(torusNodeEndpoints, torusNodePub, verifierDetails); | ||
expect(result.finalKeyData.evmAddress).to.equal("0xDfA967285AC699A70DA340F60d00DB19A272639d"); | ||
expect(result.metadata.serverTimeOffset).lessThan(20); | ||
delete result.metadata.serverTimeOffset; | ||
|
@@ -57,8 +57,8 @@ describe("torus utils aqua", function () { | |
it("should fetch user type and public address", async function () { | ||
const verifier = "tkey-google-aqua"; // any verifier | ||
const verifierDetails = { verifier, verifierId: TORUS_TEST_EMAIL }; | ||
const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); | ||
const result1 = (await torus.getUserTypeAndAddress(torusNodeEndpoints, verifierDetails)) as TorusPublicKey; | ||
const { torusNodeEndpoints, torusNodePub } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); | ||
const result1 = (await torus.getUserTypeAndAddress(torusNodeEndpoints, torusNodePub, verifierDetails)) as TorusPublicKey; | ||
expect(result1.metadata.typeOfUser).to.equal("v2"); | ||
expect(result1.metadata.serverTimeOffset).lessThan(20); | ||
delete result1.metadata.serverTimeOffset; | ||
|
@@ -89,7 +89,7 @@ describe("torus utils aqua", function () { | |
const v2Verifier = "tkey-google-aqua"; | ||
// 1/1 user | ||
const v2TestEmail = "[email protected]"; | ||
const result2 = (await torus.getUserTypeAndAddress(torusNodeEndpoints, { | ||
const result2 = (await torus.getUserTypeAndAddress(torusNodeEndpoints, torusNodePub, { | ||
verifier: v2Verifier, | ||
verifierId: v2TestEmail, | ||
})) as TorusPublicKey; | ||
|
@@ -122,7 +122,7 @@ describe("torus utils aqua", function () { | |
|
||
// 2/n user | ||
const v2nTestEmail = "[email protected]"; | ||
const result3 = (await torus.getUserTypeAndAddress(torusNodeEndpoints, { | ||
const result3 = (await torus.getUserTypeAndAddress(torusNodeEndpoints, torusNodePub, { | ||
verifier: v2Verifier, | ||
verifierId: v2nTestEmail, | ||
})) as TorusPublicKey; | ||
|
@@ -158,8 +158,8 @@ describe("torus utils aqua", function () { | |
const verifier = "tkey-google-aqua"; // any verifier | ||
const email = faker.internet.email(); | ||
const verifierDetails = { verifier, verifierId: email }; | ||
const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); | ||
const { finalKeyData, oAuthKeyData, metadata } = await torus.getPublicAddress(torusNodeEndpoints, verifierDetails); | ||
const { torusNodeEndpoints, torusNodePub } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); | ||
const { finalKeyData, oAuthKeyData, metadata } = await torus.getPublicAddress(torusNodeEndpoints, torusNodePub, verifierDetails); | ||
expect(finalKeyData.evmAddress).to.not.equal(""); | ||
expect(finalKeyData.evmAddress).to.not.equal(null); | ||
expect(oAuthKeyData.evmAddress).to.not.equal(""); | ||
|
@@ -171,8 +171,8 @@ describe("torus utils aqua", function () { | |
it("should be able to login", async function () { | ||
const token = generateIdToken(TORUS_TEST_EMAIL, "ES256"); | ||
const verifierDetails = { verifier: TORUS_TEST_VERIFIER, verifierId: TORUS_TEST_EMAIL }; | ||
const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); | ||
const result = await torus.retrieveShares(torusNodeEndpoints, TORUS_TEST_VERIFIER, { verifier_id: TORUS_TEST_EMAIL }, token); | ||
const { torusNodeEndpoints, torusIndexes } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); | ||
const result = await torus.retrieveShares(torusNodeEndpoints, torusIndexes, TORUS_TEST_VERIFIER, { verifier_id: TORUS_TEST_EMAIL }, token); | ||
expect(result.finalKeyData.privKey).to.be.equal("f726ce4ac79ae4475d72633c94769a8817aff35eebe2d4790aed7b5d8a84aa1d"); | ||
expect(result.metadata.serverTimeOffset).lessThan(20); | ||
delete result.metadata.serverTimeOffset; | ||
|
@@ -200,9 +200,10 @@ describe("torus utils aqua", function () { | |
const idToken = generateIdToken(TORUS_TEST_EMAIL, "ES256"); | ||
const hashedIdToken = keccak256(Buffer.from(idToken, "utf8")); | ||
const verifierDetails = { verifier: TORUS_TEST_AGGREGATE_VERIFIER, verifierId: TORUS_TEST_EMAIL }; | ||
const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); | ||
const { torusNodeEndpoints, torusIndexes } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); | ||
const result = await torus.retrieveShares( | ||
torusNodeEndpoints, | ||
torusIndexes, | ||
TORUS_TEST_AGGREGATE_VERIFIER, | ||
{ | ||
verify_params: [{ verifier_id: TORUS_TEST_EMAIL, idtoken: idToken }], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,8 +27,8 @@ describe("torus utils celeste", function () { | |
it("should fetch public address", async function () { | ||
const verifier = "tkey-google-celeste"; // any verifier | ||
const verifierDetails = { verifier, verifierId: TORUS_TEST_EMAIL }; | ||
const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); | ||
const result = await torus.getPublicAddress(torusNodeEndpoints, verifierDetails); | ||
const { torusNodeEndpoints, torusNodePub } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); | ||
const result = await torus.getPublicAddress(torusNodeEndpoints, torusNodePub, verifierDetails); | ||
expect(result.finalKeyData.evmAddress).to.equal("0xC3115b9d6FaB99739b23DA9dfcBA47A4Ec4Cd113"); | ||
expect(result.metadata.serverTimeOffset).lessThan(20); | ||
delete result.metadata.serverTimeOffset; | ||
|
@@ -57,8 +57,8 @@ describe("torus utils celeste", function () { | |
it("should fetch user type and public address", async function () { | ||
const verifier = "tkey-google-celeste"; // any verifier | ||
const verifierDetails = { verifier, verifierId: TORUS_TEST_EMAIL }; | ||
const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); | ||
const result1 = await torus.getUserTypeAndAddress(torusNodeEndpoints, verifierDetails); | ||
const { torusNodeEndpoints, torusNodePub } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); | ||
const result1 = await torus.getUserTypeAndAddress(torusNodeEndpoints, torusNodePub, verifierDetails); | ||
expect(result1.finalKeyData.evmAddress).to.equal("0xC3115b9d6FaB99739b23DA9dfcBA47A4Ec4Cd113"); | ||
expect(result1.metadata.typeOfUser).to.equal("v1"); | ||
expect(result1.metadata.serverTimeOffset).lessThan(20); | ||
|
@@ -87,7 +87,7 @@ describe("torus utils celeste", function () { | |
const v2Verifier = "tkey-google-celeste"; | ||
// 1/1 user | ||
const v2TestEmail = "[email protected]"; | ||
const result2 = await torus.getUserTypeAndAddress(torusNodeEndpoints, { | ||
const result2 = await torus.getUserTypeAndAddress(torusNodeEndpoints, torusNodePub, { | ||
verifier: v2Verifier, | ||
verifierId: v2TestEmail, | ||
}); | ||
|
@@ -120,7 +120,7 @@ describe("torus utils celeste", function () { | |
|
||
// 2/n user | ||
const v2nTestEmail = "[email protected]"; | ||
const result3 = await torus.getUserTypeAndAddress(torusNodeEndpoints, { | ||
const result3 = await torus.getUserTypeAndAddress(torusNodeEndpoints, torusNodePub, { | ||
verifier: v2Verifier, | ||
verifierId: v2nTestEmail, | ||
}); | ||
|
@@ -156,8 +156,8 @@ describe("torus utils celeste", function () { | |
const verifier = "tkey-google-celeste"; // any verifier | ||
const email = faker.internet.email(); | ||
const verifierDetails = { verifier, verifierId: email }; | ||
const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); | ||
const { finalKeyData, metadata, oAuthKeyData } = await torus.getPublicAddress(torusNodeEndpoints, verifierDetails); | ||
const { torusNodeEndpoints, torusNodePub } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); | ||
const { finalKeyData, metadata, oAuthKeyData } = await torus.getPublicAddress(torusNodeEndpoints, torusNodePub, verifierDetails); | ||
expect(finalKeyData.evmAddress).to.not.equal(""); | ||
expect(finalKeyData.evmAddress).to.not.equal(null); | ||
expect(oAuthKeyData.evmAddress).to.not.equal(""); | ||
|
@@ -169,8 +169,8 @@ describe("torus utils celeste", function () { | |
it("should be able to login", async function () { | ||
const token = generateIdToken(TORUS_TEST_EMAIL, "ES256"); | ||
const verifierDetails = { verifier: TORUS_TEST_VERIFIER, verifierId: TORUS_TEST_EMAIL }; | ||
const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); | ||
const result = await torus.retrieveShares(torusNodeEndpoints, TORUS_TEST_VERIFIER, { verifier_id: TORUS_TEST_EMAIL }, token); | ||
const { torusNodeEndpoints, torusIndexes } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); | ||
const result = await torus.retrieveShares(torusNodeEndpoints, torusIndexes, TORUS_TEST_VERIFIER, { verifier_id: TORUS_TEST_EMAIL }, token); | ||
expect(result.finalKeyData.privKey).to.be.equal("0ae056aa938080c9e8bf6641261619e09fd510c91bb5aad14b0de9742085a914"); | ||
expect(result.metadata.serverTimeOffset).lessThan(20); | ||
|
||
|
@@ -199,9 +199,10 @@ describe("torus utils celeste", function () { | |
const idToken = generateIdToken(TORUS_TEST_EMAIL, "ES256"); | ||
const hashedIdToken = keccak256(Buffer.from(idToken, "utf8")); | ||
const verifierDetails = { verifier: TORUS_TEST_AGGREGATE_VERIFIER, verifierId: TORUS_TEST_EMAIL }; | ||
const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); | ||
const { torusNodeEndpoints, torusIndexes } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); | ||
const result = await torus.retrieveShares( | ||
torusNodeEndpoints, | ||
torusIndexes, | ||
TORUS_TEST_AGGREGATE_VERIFIER, | ||
{ | ||
verify_params: [{ verifier_id: TORUS_TEST_EMAIL, idtoken: idToken }], | ||
|
Oops, something went wrong.