Skip to content

Conversation

@adhan5828
Copy link

from solders.keypair import Keypair
from web3 import Web3

solana

solana_private_key = '58hvcp5Lje9us9Q1QJdWV8aATcJKeHNZudyN9jWuiNYtRGFhJrH97Qe4ew8VmxLx5VCEYEuHGWRZuaFLr6A4euqR'
kp = Keypair().from_base58_string(solana_private_key) # private key
print(kp.pubkey()) # get "MJKqp326RZCHnAAbew9MDdui3iCKWco7fsK9sVuZTX2", solana address

eth

w3 = Web3(Web3.HTTPProvider("https://cloudflare-eth.com/v1/mainnet"))
eth_private_key = '4a68dfa8cb029fb5490cb36bb9c4c6523bada89134e40d2498cf83d7b4295cfb'
ac = w3.eth.account.from_key(eth_private_key) # private_key
print(ac.address) # get "MJKqp326RZCHnAAbew9MDdui3iCKWco7fsK9sVuZTX2", eth address

Solana private key
import { PublicKey } from "@solana/web3.js";

/**
 * Check if Solana public keys are on the elliptic curve
 */
async function checkPublicKeyCurveValidity() {
    console.log("Checking Solana Public Key Curve Validity\n");

    // Example of an on-curve address
    const onCurveKey = new PublicKey("5oNDL3swdJJF1g9DzJiZ4ynHXgszjAEpUkxVYejchzrY");
    console.log(`On-curve key: ${onCurveKey.toBase58()}`);
    console.log(`Is on curve: ${PublicKey.isOnCurve(onCurveKey.toBytes())}\n`);

    // Example of an off-curve address (PDA - Program Derived Address)
    const offCurveAddress = new PublicKey("MJKqp326RZCHnAAbew9MDdui3iCKWco7fsK9sVuZTX2");
    console.log(`Off-curve key: ${offCurveAddress.toBase58()}`);
    console.log(`Is on curve: ${PublicKey.isOnCurve(offCurveAddress.toBytes())}\n`);

    // You can also check your own public key from solana-keygen
    // Replace <PUBKEY> with your actual public key from the command
    try {
        // Uncomment and replace with your actual pubkey
        // const myKey = new PublicKey("YOUR_PUBKEY_HERE");
        // console.log(`Your key: ${myKey.toBase58()}`);
        // console.log(`Is on curve: ${PublicKey.isOnCurve(myKey.toBytes())}`);
    } catch (error) {
        console.log("Add your public key to test it");
    }

    // Additional examples of different key types
    console.log("=== Additional Examples ===");
    
    // System Program ID (always on curve)
    const systemProgram = new PublicKey("11111111111111111111111111111112");
    console.log(`System Program: ${systemProgram.toBase58()}`);
    console.log(`Is on curve: ${PublicKey.isOnCurve(systemProgram.toBytes())}\n`);

    // Token Program ID
    const tokenProgram = new PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
    console.log(`Token Program: ${tokenProgram.toBase58()}`);
    console.log(`Is on curve: ${PublicKey.isOnCurve(tokenProgram.toBytes())}\n`);
}

// Run the function
checkPublicKeyCurveValidity().catch(console.error);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant