Skip to main content
added 278 characters in body
Source Link
Raza
  • 51
  • 8

Using Javascript

This can be done with the ed25519-hd-key and tweetnacl libraries.

Make sure you start the path with m/44'/501', as this is required for Solana addresses.

Setup (run this in your terminal):

npm init -y && npm i @solana/web3.js bip39 tweetnacl buffer ed25519-hd-key

Create a file with this code and run it with node <FILENAME.js>:

import { Keypair } from '@solana/web3.js';
import * as bip39 from 'bip39';
import nacl from 'tweetnacl';
import { Buffer } from 'buffer';
import * as ed25519 from 'ed25519-hd-key';

// Replace with your mnemonic
const mnemonic = 'cabbage together debris chalk hammer novel wire tunnel rubber labor retire prefer';

// Convert the mnemonic to a seed
const seed = bip39.mnemonicToSeedSync(mnemonic).slice(0, 32);

// Define the derivation path
const path = `m/44'/501'/0'/0'`; // Replace with your custom path

// Derive a seed from the given path
const derivedSeed = ed25519.derivePath(path, Buffer.from(seed, 'hex')).key;

// Generate a keypair from the derived seed using tweetnacl (NaCl = Networking and Cryptography library)
const derivedUint8Keypair = nacl.sign.keyPair.fromSeed(derivedSeed);

// This is a Uint8Array, not a Solana web3.js Keypair object, so you will need to convert it
const customPathKeypair = Keypair.fromSecretKey(
  Uint8Array.from(derivedUint8Keypair.secretKey)
);

console.log('Custom Path Keypair address:', customPathKeypair.publicKey.toBase58());

Using wallets

The Backpack wallet supports arbitrary derivation paths, so you can just import your seed phrase into it and set the path.

https://backpack.app/downloads

This can be done with the ed25519-hd-key and tweetnacl libraries.

Make sure you start the path with m/44'/501', as this is required for Solana addresses.

Setup (run this in your terminal):

npm init -y && npm i @solana/web3.js bip39 tweetnacl buffer ed25519-hd-key

Create a file with this code and run it with node <FILENAME.js>:

import { Keypair } from '@solana/web3.js';
import * as bip39 from 'bip39';
import nacl from 'tweetnacl';
import { Buffer } from 'buffer';
import * as ed25519 from 'ed25519-hd-key';

// Replace with your mnemonic
const mnemonic = 'cabbage together debris chalk hammer novel wire tunnel rubber labor retire prefer';

// Convert the mnemonic to a seed
const seed = bip39.mnemonicToSeedSync(mnemonic).slice(0, 32);

// Define the derivation path
const path = `m/44'/501'/0'/0'`; // Replace with your custom path

// Derive a seed from the given path
const derivedSeed = ed25519.derivePath(path, Buffer.from(seed, 'hex')).key;

// Generate a keypair from the derived seed using tweetnacl (NaCl = Networking and Cryptography library)
const derivedUint8Keypair = nacl.sign.keyPair.fromSeed(derivedSeed);

// This is a Uint8Array, not a Solana web3.js Keypair object, so you will need to convert it
const customPathKeypair = Keypair.fromSecretKey(
  Uint8Array.from(derivedUint8Keypair.secretKey)
);

console.log('Custom Path Keypair address:', customPathKeypair.publicKey.toBase58());

Using Javascript

This can be done with the ed25519-hd-key and tweetnacl libraries.

Make sure you start the path with m/44'/501', as this is required for Solana addresses.

Setup (run this in your terminal):

npm init -y && npm i @solana/web3.js bip39 tweetnacl buffer ed25519-hd-key

Create a file with this code and run it with node <FILENAME.js>:

import { Keypair } from '@solana/web3.js';
import * as bip39 from 'bip39';
import nacl from 'tweetnacl';
import { Buffer } from 'buffer';
import * as ed25519 from 'ed25519-hd-key';

// Replace with your mnemonic
const mnemonic = 'cabbage together debris chalk hammer novel wire tunnel rubber labor retire prefer';

// Convert the mnemonic to a seed
const seed = bip39.mnemonicToSeedSync(mnemonic).slice(0, 32);

// Define the derivation path
const path = `m/44'/501'/0'/0'`; // Replace with your custom path

// Derive a seed from the given path
const derivedSeed = ed25519.derivePath(path, Buffer.from(seed, 'hex')).key;

// Generate a keypair from the derived seed using tweetnacl (NaCl = Networking and Cryptography library)
const derivedUint8Keypair = nacl.sign.keyPair.fromSeed(derivedSeed);

// This is a Uint8Array, not a Solana web3.js Keypair object, so you will need to convert it
const customPathKeypair = Keypair.fromSecretKey(
  Uint8Array.from(derivedUint8Keypair.secretKey)
);

console.log('Custom Path Keypair address:', customPathKeypair.publicKey.toBase58());

Using wallets

The Backpack wallet supports arbitrary derivation paths, so you can just import your seed phrase into it and set the path.

https://backpack.app/downloads

added 213 characters in body
Source Link
Raza
  • 51
  • 8

This can be done with the ed25519-hd-key libraryand tweetnacl libraries.

Make sure you start the path with m/44'/501', as this is required for Solana addresses.

Setup (run this in your terminal):

npm init -y && npm i @solana/web3.js bip39 tweetnacl buffer ed25519-hd-key

Create a file with this code and run it with node <FILENAME.js>:

import { Keypair } from '@solana/web3.js';
import * as bip39 from 'bip39';
import nacl from 'tweetnacl';
import { Buffer } from 'buffer';
import * as ed25519 from 'ed25519-hd-key';

// Replace with your mnemonic
const mnemonic = 'cabbage together debris chalk hammer novel wire tunnel rubber labor retire prefer';

// Convert the mnemonic to a seed
const seed = bip39.mnemonicToSeedSync(mnemonic).slice(0, 32);

// Define the derivation path
const path = `m/44'/501'/0'/0'`; // Replace with your custom path

// Derive a seed from the given path
const derivedSeed = ed25519.derivePath(path, Buffer.from(seed, 'hex')).key;

// Generate a keypair from the derived seed using tweetnacl (NaCl = Networking and Cryptography library)
const derivedUint8Keypair = nacl.sign.keyPair.fromSeed(derivedSeed);

// This is a Uint8Array, not a Solana web3.js Keypair object, so you will need to convert it
const customPathKeypair = Keypair.fromSecretKey(
  Uint8Array.from(derivedUint8Keypair.secretKey)
);

console.log('Custom Path Keypair address:', customPathKeypair.publicKey.toBase58());

This can be done with the ed25519-hd-key library.

Make sure you start the path with m/44'/501', as this is required for Solana addresses.

import { Keypair } from '@solana/web3.js';
import * as bip39 from 'bip39';
import nacl from 'tweetnacl';
import { Buffer } from 'buffer';
import * as ed25519 from 'ed25519-hd-key';

// Replace with your mnemonic
const mnemonic = 'cabbage together debris chalk hammer novel wire tunnel rubber labor retire prefer';

// Convert the mnemonic to a seed
const seed = bip39.mnemonicToSeedSync(mnemonic).slice(0, 32);

// Define the derivation path
const path = `m/44'/501'/0'/0'`; // Replace with your custom path

// Derive a seed from the given path
const derivedSeed = ed25519.derivePath(path, Buffer.from(seed, 'hex')).key;

// Generate a keypair from the derived seed using tweetnacl (NaCl = Networking and Cryptography library)
const derivedUint8Keypair = nacl.sign.keyPair.fromSeed(derivedSeed);

// This is a Uint8Array, not a Solana web3.js Keypair object, so you will need to convert it
const customPathKeypair = Keypair.fromSecretKey(
  Uint8Array.from(derivedUint8Keypair.secretKey)
);

console.log('Custom Path Keypair address:', customPathKeypair.publicKey.toBase58());

This can be done with the ed25519-hd-key and tweetnacl libraries.

Make sure you start the path with m/44'/501', as this is required for Solana addresses.

Setup (run this in your terminal):

npm init -y && npm i @solana/web3.js bip39 tweetnacl buffer ed25519-hd-key

Create a file with this code and run it with node <FILENAME.js>:

import { Keypair } from '@solana/web3.js';
import * as bip39 from 'bip39';
import nacl from 'tweetnacl';
import { Buffer } from 'buffer';
import * as ed25519 from 'ed25519-hd-key';

// Replace with your mnemonic
const mnemonic = 'cabbage together debris chalk hammer novel wire tunnel rubber labor retire prefer';

// Convert the mnemonic to a seed
const seed = bip39.mnemonicToSeedSync(mnemonic).slice(0, 32);

// Define the derivation path
const path = `m/44'/501'/0'/0'`; // Replace with your custom path

// Derive a seed from the given path
const derivedSeed = ed25519.derivePath(path, Buffer.from(seed, 'hex')).key;

// Generate a keypair from the derived seed using tweetnacl (NaCl = Networking and Cryptography library)
const derivedUint8Keypair = nacl.sign.keyPair.fromSeed(derivedSeed);

// This is a Uint8Array, not a Solana web3.js Keypair object, so you will need to convert it
const customPathKeypair = Keypair.fromSecretKey(
  Uint8Array.from(derivedUint8Keypair.secretKey)
);

console.log('Custom Path Keypair address:', customPathKeypair.publicKey.toBase58());
Source Link
Raza
  • 51
  • 8

This can be done with the ed25519-hd-key library.

Make sure you start the path with m/44'/501', as this is required for Solana addresses.

import { Keypair } from '@solana/web3.js';
import * as bip39 from 'bip39';
import nacl from 'tweetnacl';
import { Buffer } from 'buffer';
import * as ed25519 from 'ed25519-hd-key';

// Replace with your mnemonic
const mnemonic = 'cabbage together debris chalk hammer novel wire tunnel rubber labor retire prefer';

// Convert the mnemonic to a seed
const seed = bip39.mnemonicToSeedSync(mnemonic).slice(0, 32);

// Define the derivation path
const path = `m/44'/501'/0'/0'`; // Replace with your custom path

// Derive a seed from the given path
const derivedSeed = ed25519.derivePath(path, Buffer.from(seed, 'hex')).key;

// Generate a keypair from the derived seed using tweetnacl (NaCl = Networking and Cryptography library)
const derivedUint8Keypair = nacl.sign.keyPair.fromSeed(derivedSeed);

// This is a Uint8Array, not a Solana web3.js Keypair object, so you will need to convert it
const customPathKeypair = Keypair.fromSecretKey(
  Uint8Array.from(derivedUint8Keypair.secretKey)
);

console.log('Custom Path Keypair address:', customPathKeypair.publicKey.toBase58());