Skip to content

Commit

Permalink
Update Node.js example
Browse files Browse the repository at this point in the history
  • Loading branch information
shahbaz17 committed Oct 13, 2023
1 parent 5f6ed9a commit 9fbac49
Show file tree
Hide file tree
Showing 4 changed files with 726 additions and 1,929 deletions.
48 changes: 37 additions & 11 deletions node-sdk/node-backend-example/index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,49 @@
const { Web3Auth } = require("@web3auth/node-sdk");
const { EthereumPrivateKeyProvider } = require("@web3auth/ethereum-provider");
const jwt = require('jsonwebtoken');
const fs = require('fs');

const web3auth = new Web3Auth({
clientId: "BEglQSgt4cUWcj6SKRdu5QkOXTsePmMcusG5EAoyjyOYKlVRjIF1iCNnMOTfpzCiunHRrMui8TIwQPXdkQ8Yxuk", // Get your Client ID from Web3Auth Dashboard
chainConfig: {
chainNamespace: "eip155",
chainId: "0x1",
rpcTarget: "https://rpc.ankr.com/eth",
},
clientId: "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ", // Get your Client ID from Web3Auth Dashboard
web3AuthNetwork: "sapphire_mainnet", // Get your Network ID from Web3Auth Dashboard
});

const ethereumProvider = new EthereumPrivateKeyProvider({
config: {
chainConfig: {
chainId: "0x1",
rpcTarget: "https://rpc.ankr.com/eth"
}
}
});

web3auth.init({ network: "cyan" });
web3auth.init({ provider: ethereumProvider });

var privateKey = fs.readFileSync('privateKey.pem');

var sub = Math.random().toString(36).substring(7);

var token = jwt.sign(
{
sub: sub,
name: 'Mohammad Yashovardhan Mishra Jang',
email: '[email protected]',
aud: 'urn:api-web3auth-io',
iss: 'https://web3auth.io',
iat: Math.floor(Date.now() / 1000),
exp: Math.floor(Date.now() / 1000) + 60 * 60,
},
privateKey,
{ algorithm: 'RS256', keyid: '2ma4enu1kdvw5bo9xsfpi3gcjzrt6q78yl0h' },
);

const connect = async () => {
const provider = await web3auth.connect({
verifier: "verifier-name", // replace with your verifier name
verifierId: "verifier-Id", // replace with your verifier id, setup while creating the verifier on Web3Auth's Dashboard
idToken: "JWT Token", // replace with your newly created unused JWT Token.
verifier: "w3a-node-demo", // replace with your verifier name
verifierId: sub, // replace with your verifier id's value, for example, sub value of JWT Token, or email address.
idToken: token, // replace with your newly created unused JWT Token.
});
const eth_private_key = await provider.request({ method: "eth_private_key" });
console.log("ETH Private Key", eth_private_key);
console.log("ETH Private Key: ", eth_private_key);
};
connect();
Loading

0 comments on commit 9fbac49

Please sign in to comment.