Need help to setup web3auth for internet computer blockchain

i am making a project on icp blockchain in which i want to use web3auth for authentication.
my final need is principal id of authenticated user through which they can transfer tokens.

can anyone help me how to setup web3auth.

@kktimepass7 Welcome Aboard!

For Non-EVM Chains like ICP, you can refer to the below link to implement:

You may follow the guides for any of the non-evm available chains like Tezos, ImmutableX, etc and add the chainconfig for ICP instead.

const userInfo = await web3authInstance.getUserInfo();

using this i am getting userInfo with some attributes.
but i want principal id for icp blockchain.
so how to get it from userInfo?

hi @kktimepass7

I’m not very familiar with how to do it. It’s better to post a question in their forum: https://forum.dfinity.org/

You can obtain the privateKey for sure, and there are plenty of examples on our GitHub to do it.

I asked ChatGPT (didn’t test it), please double-check it.

const { Principal } = require('@dfinity/principal');
const nacl = require('tweetnacl');
const bs58 = require('bs58');

// Your private key (32 bytes)
const privateKeyHex = 'your_private_key_hex';
const privateKeyBytes = Buffer.from(privateKeyHex, 'hex');

// Generate the public key from the private key using Ed25519
const keyPair = nacl.sign.keyPair.fromSeed(privateKeyBytes);
const publicKeyBytes = keyPair.publicKey;

// Derive the Principal ID from the public key
const principal = Principal.selfAuthenticating(publicKeyBytes);
console.log(principal.toText());

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.