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
vjgee
September 25, 2023, 4:43pm
2
@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.
vjgee
September 25, 2023, 5:25pm
3
No, it is not possible as we get the address only after authentication.