Skip to content

Commit

Permalink
Add support for multiple wallets for SOL
Browse files Browse the repository at this point in the history
  • Loading branch information
yerofey committed Feb 4, 2024
1 parent 13eee87 commit bacb030
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/Wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,25 +436,25 @@ class Wallet {
};
}

let addresses = [];
const mnemonic = mnemonicString || generateMnemonicString(24);
const seed = await bip39.mnemonicToSeed(mnemonic);
const derivationPath = "m/44'/501'/0'/0'";
const derivedSeed = derivePath(derivationPath, seed.toString('hex')).key;
const keypair = SolanaKeypair.fromSeed(derivedSeed);
const publicKey = new SolanaPublickey(keypair.publicKey);
const publicKeyString = publicKey.toString();
const secretKeyString = bs58.encode(keypair.secretKey);

// TODO: add support for multiple addresses
for (let i = 0; i < number; i++) {
const derivationPath = `m/44'/501'/${i}'/0'`;
const derivedSeed = derivePath(derivationPath, seed.toString('hex')).key;
const keypair = SolanaKeypair.fromSeed(derivedSeed);
const publicKey = new SolanaPublickey(keypair.publicKey);
const privateKey = bs58.encode(keypair.secretKey);
addresses.push({
index: i,
address: publicKey.toBase58(),
privateKey,
});
}

Object.assign(result, {
addresses: [
{
index: 0,
address: publicKeyString,
privateKey: secretKeyString,
},
],
addresses,
mnemonic,
});
} else if (chain == 'TON') {
Expand Down

0 comments on commit bacb030

Please sign in to comment.