How get public key from a wallet using custom auth verifier

When asking for help in this category, please make sure to provide the following details:

  • SDK Version: ^3.1.0
  • Platform: NodeJS
  • Browser Console Screenshots:
  • If the issue is related to Custom Authentication, please include the following information (optional):
    • Verifier Name: w3a-key
    • JWKS Endpoint: https://staging-ws.origos.io/.well-known/jwks.json
    • Sample idToken (JWT):
      eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImNiZmU0YTc4LTkxNzEtNDMwMy04ODRkLWFmMmQ1MDI0YmZlNyJ9.eyJ1c2VySWQiOiJmMzhiNTg5ZS05Y2I5LTRjYWMtODA5Yy05MmI1NGVhMjRkNzEiLCJhdWQiOiJCTHFyQUI1MmU2RmUySE1SWC12NVVqVjZxWFR3bHgxVHBvVDFMQW01Mk1kX08wU1RfNVA3QmxYZjdBVmZmVlNvNUJYRTZ6UjVLSlVSU1FpZ3Z3UGRtWGsiLCJpc3MiOiJodHRwczovL2FwaS1hdXRoLndlYjNhdXRoLmlvIiwibmFtZSI6ImFwaS13ZWIzYXV0aCIsImlhdCI6MTcwNjU2ODgxNSwiZXhwIjoxNzA2NTcyNDE1LCJ3YWxsZXRzIjpbeyJ0eXBlIjoidzNhLWtleSIsImFkZHJlc3MiOiIweGI2YTdkYWZlMDA2YzM4OTU4Y2Y1NmZjNmQ4MzU2YWFiMTFmYjY1ZjAifV19.rPOSaxIhOn_yJ0BlupRY1WWi834EM4GtLS_r6tVO7-RCYgoGzMLDV6ZisCl22KixgfdPYKJJnAo7J1WOnmYSHNM6m7-ZfFTfqCQ4joDW6m8n6tuG5WSxzmMei54Jp7px8l-L0JMmd7aczDHHCxHEYeKCBHTpeV4s1aV3p7pCXVGF_tnuIT_JH2xaZcguzgLajytoZd-DfFmF2aS6EX6AT24F9yHtaay6X6G6grkyJjYfbfmEoWhZwZkcm6Yf8kvB09JIYnTDmyhPDz_mL2KjfNQilGhE4608LlFMv6S8t9t717yRDZ3GrgOU_C0gs4tG4jZpOc4jHLBPgnrs3c99ew

Also, kindly provide the Web3Auth initialization and login code snippet below. This will help us better understand your issue and provide you with the necessary assistance.

const { Web3Auth } = require(“@web3auth/node-sdk”);
const { EthereumPrivateKeyProvider } = require(“@web3auth/ethereum-provider”);
const jwt = require(‘jsonwebtoken’);
const fs = require(‘fs’);

const clientId = “BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ”; // Get your Client ID from Web3Auth Dashboard

const verifier = “w3a-node-demo”;

const web3auth = new Web3Auth({
clientId,
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({ provider: ethereumProvider });

var privateKey = fs.readFileSync(‘privateKey.pem’);

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

var token = jwt.sign(
{
sub: sub,
name: ‘Agrawal Alam Mishra Rawski Bherwani’,
email: ‘devrel@web3auth.io’,
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: “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 PrivateKey: ", eth_private_key);
const eth_address = await provider.request({ method: “eth_accounts” });
console.log("ETH Address: ", eth_address[0]);
process.exit(0);
};
connect();

I need get wallet eth_public_key

@rsaquicela Welcome Aboard!

Your request is under review and we will get back with further updates.

Thanks for your patience.

You can get the idToken from Web3Auth by calling authenticateUser() function and
decode the idToken to get the wallet-> public_key

You may refer to the below documentation for the sample payload for social login and external wallets

@rsaquicela Are you able to see my previous message? You need to decode the idToken to get the wallet public_key.

Hello, Yes i read it.

But, I’m using custom auth verifier.

DOC:

So the method authenticateUser not exists.

@rsaquicela Ok, we will get back with further updates on how to do this.

@rsaquicela You can use this code snippet for eth_public_key:

const eth_private_key = await provider.request({ method: “eth_private_key” });
console.log("ETH PrivateKey: ", eth_private_key);
const eth_public_key = await provider.request({ method: “eth_public_key” });
console.log("ETH PublicKey: ", eth_public_key);
const eth_address = await provider.request({ method: “eth_accounts” });
console.log("ETH Address: ", eth_address[0]);

Yes, I used it but I get an error:

**node:internal/process/promises:288
            triggerUncaughtException(err, true /* fromPromise */);
            ^

JsonRpcError: Internal JSON-RPC error.
    at getJsonRpcError (/node_modules/@metamask/rpc-errors/dist/errors.js:176:12)
    at Object.internal (/node_modules/@metamask/rpc-errors/dist/errors.js:42:24)
    at provider.sendAsync (/node_modules/@toruslabs/openlogin-jrpc/dist/openloginJrpc.cjs.js:739:50)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async provider.request (/node_modules/@toruslabs/openlogin-jrpc/dist/openloginJrpc.cjs.js:760:17)
    at {
  code: -32603,
  data: {
    code: -32601,
    message: 'the method eth_public_key does not exist/is not available',
    cause: null
  }
}**

Hi @rsaquicela,

“eth_public_key” is not an JSON RPC method.

You can see the list of methods in this link: JSON-RPC API | ethereum.org

If you are looking for the public address, you should do :

const ethAddress = await provider.request({ method: “eth_accounts” });
console.log("ETH Address: ", eth_address);

Please contact me if the problem persist.