Can i use Web3Auth on the server side for ex: NodeJS?

I would like to get the private key for my client ID on the server side, how can i do this ?



Originally posted by: metallicalfa2

Check the discussion at: https://github.com/orgs/Web3Auth/discussions/315

Note: This only works for people who have not upgraded to add MFA.

You can use the below code to get clientID on the server side:

@toruslabs/fetch-node-details/dist/fetchNodeDetails-node").default;
const TorusUtils = require("@toruslabs/torus.js/dist/torusUtils-node").default;

const fetchNodeDetails = new FetchNodeDetails({ network: "ropsten", proxyAddress: "0x6258c9d6c12ed3edda59a1a6527e469517744aa7" });
const torusUtils = new TorusUtils({ enableOneKey: true, network: "testnet" });

async function getTorusPublicAddress(verifier, verifierId) {
const { torusNodeEndpoints, torusNodePub } = await fetchNodeDetails.getNodeDetails({ verifier, verifierId });
const publicAddress = await torusUtils.getPublicAddress(torusNodeEndpoints, torusNodePub, { verifier, verifierId });
return publicAddress;
}

async function getTorusKey(verifier, verifierId, idToken) {
const { torusNodeEndpoints, torusIndexes } = await fetchNodeDetails.getNodeDetails({ verifier, verifierId });
const { ethAddress, privKey } = await torusUtils.retrieveShares(torusNodeEndpoints, torusIndexes, verifier, { verifier_id: verifierId }, idToken);
return { ethAddress, privKey };
}">

global.fetch = require(“node-fetch”);
global.atob = require(“atob”);

// Please install node-fetch@2

const FetchNodeDetails = require(@toruslabs/fetch-node-details/dist/fetchNodeDetails-node”).default;
const TorusUtils = require(@toruslabs/torus.js/dist/torusUtils-node”).default;

const fetchNodeDetails = new FetchNodeDetails({ network: “ropsten”, proxyAddress: “0x6258c9d6c12ed3edda59a1a6527e469517744aa7” });
const torusUtils = new TorusUtils({ enableOneKey: true, network: “testnet” });

async function getTorusPublicAddress(verifier, verifierId) {
const { torusNodeEndpoints, torusNodePub } = await fetchNodeDetails.getNodeDetails({ verifier, verifierId });
const publicAddress = await torusUtils.getPublicAddress(torusNodeEndpoints, torusNodePub, { verifier, verifierId });
return publicAddress;
}

async function getTorusKey(verifier, verifierId, idToken) {
const { torusNodeEndpoints, torusIndexes } = await fetchNodeDetails.getNodeDetails({ verifier, verifierId });
const { ethAddress, privKey } = await torusUtils.retrieveShares(torusNodeEndpoints, torusIndexes, verifier, { verifier_id: verifierId }, idToken);
return { ethAddress, privKey };
}



Originally posted by: shahbaz17