-
Notifications
You must be signed in to change notification settings - Fork 21
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
Showing
4 changed files
with
726 additions
and
1,929 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 |
---|---|---|
@@ -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(); |
Oops, something went wrong.