[Archive] Get wallet address (public key) of email without getting the private key

:classical_building: Archived Content from Web3Auth Community

This topic was originally posted by mikeherbig on 9/25/2023.
This content has been migrated from our previous community forum to preserve valuable discussions.


Get wallet address (public key) of email without getting the private key

@mikeherbig Welcome Aboard!

To accomplish it, you can use an external package and implement the following code snippet in your project:

For Ethereum (EVM), please follow the below code:

import publicKeyToAddress from 'ethereum-public-key-to-address';

const parseTokenAndReturnAddress = (token) => {
if (!token) return null
const base64Url = token.split(β€˜.’)[1]
const base64 = base64Url.replace(/-/g, β€˜+’).replace(/_/g, β€˜/’)
const jsonPayload = decodeURIComponent(
atob(base64)
.split(β€˜β€™)
.map((c) => %${00${c.charCodeAt(0).toString(16)}.slice(-2)})
.join(β€˜β€™)
)
console.log(JSON.parse(jsonPayload).wallets[0].public_key)
return publicKeyToAddress(JSON.parse(jsonPayload)?.wallets[0]?.public_key || β€˜β€™)
}

For Solana(Ed25519 keys), please follow the below code:

const bs58 = require('bs58')

function publicKeyToSolanaAddress(publicKey) {
let buffer = Buffer.from(publicKey, β€œhex”)
let address = bs58.encode(buffer)
return address
}

You can simply pass the Web3Auth token to this function.

No, it is not possible as we get the address only after authentication.