Created
October 9, 2024 06:53
-
-
Save nissan/e771cf313e8ca6eaa54c58a3ba09fb2f to your computer and use it in GitHub Desktop.
Convert Phantom BS58 private key format to Solana byte array
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
import bs58 from 'bs58'; | |
import promptSync from 'prompt-sync'; | |
// Initialize prompt | |
const prompt = promptSync(); | |
// Prompt the user for the base58 private key | |
const privateKeyBase58 = prompt('Enter your base58-encoded private key: '); | |
// Decode the base58-encoded private key from Phantom | |
const decodedKey = bs58.decode(privateKeyBase58); | |
// Convert the decoded key into a Uint8Array | |
const uint8ArrayKey = new Uint8Array(decodedKey.buffer, decodedKey.byteOffset, decodedKey.byteLength / Uint8Array.BYTES_PER_ELEMENT); | |
// Output the key as a JSON array to the console | |
console.log('Decoded Private Key:', JSON.stringify(Array.from(uint8ArrayKey))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment