-
Notifications
You must be signed in to change notification settings - Fork 0
/
solana.wallet.ts
51 lines (39 loc) · 1.65 KB
/
solana.wallet.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { Keypair } from "@solana/web3.js";
import { mnemonicToSeed } from "bip39"
export async function createHDWalletSolana(): Promise<any> {
let mnemonic = "deny coach horror slim task pact pole half coil bottom shine supply";
const seed = await mnemonicToSeed(mnemonic);
let publicKey: any;
let publicKeyWithPassword: any;
const ed = require('ed25519-hd-key');
const solanaDerivationPaths = [
"m/501'",
"m/44'/501'",
"m/44'/501'/0'",
"m/44'/501'/0'/0'",
"m/44'/501'/0'/0'/0'",
"m/44'/501'/0'/1'",
"m/501'/0'/0'/0'",
"m/501'/0'/0'",
];
let passwords = ["test1234", "test12345"];
console.log(mnemonic);
console.dir({publicKeyNoDerivationPath: Keypair.fromSeed(seed.slice(0,32)).publicKey.toBase58()}, { colors: true, depth: 1})
for (const password of passwords) {
const seedWithPassword = await mnemonicToSeed(mnemonic!, password);
console.dir({publicKeyNoDerivationPath: Keypair.fromSeed(seedWithPassword.slice(0,32)).publicKey.toBase58()}, { colors: true, depth: 1});
for (const derivationPath of solanaDerivationPaths) {
const derivedSeed = ed.derivePath(derivationPath, seed.toString('hex')).key;
const derivedSeedWithPassword = ed.derivePath(derivationPath, seedWithPassword.toString('hex')).key;
publicKey = Keypair.fromSeed(derivedSeed).publicKey;
publicKeyWithPassword = Keypair.fromSeed(derivedSeedWithPassword).publicKey;
console.dir({
password,
derivationPath,
publicKey: publicKey.toString('hex'),
publicKeyWithPassword: publicKeyWithPassword.toString('hex')
}, { colors:true, depth: 2});
}
}
}
createHDWalletSolana()