MCPcopy
hub / github.com/BlockRunAI/ClawRouter / deriveSolanaKeyBytes

Function deriveSolanaKeyBytes

src/wallet.ts:66–91  ·  view source on GitHub ↗
(mnemonic: string)

Source from the content-addressed store, hash-verified

64 * 3. Final IL (32 bytes) = Ed25519 private key seed
65 */
66export function deriveSolanaKeyBytes(mnemonic: string): Uint8Array {
67 const seed = mnemonicToSeedSync(mnemonic);
68
69 // Master key from SLIP-10
70 // @noble/hashes v2 requires Uint8Array keys (v1 accepted strings)
71 let I = hmac(sha512, new TextEncoder().encode("ed25519 seed"), seed);
72 let key = I.slice(0, 32);
73 let chainCode = I.slice(32);
74
75 // Derive each hardened child: m/44'/501'/0'/0'
76 for (const index of SOLANA_HARDENED_INDICES) {
77 const data = new Uint8Array(37);
78 data[0] = 0x00;
79 data.set(key, 1);
80 // ser32 big-endian
81 data[33] = (index >>> 24) & 0xff;
82 data[34] = (index >>> 16) & 0xff;
83 data[35] = (index >>> 8) & 0xff;
84 data[36] = index & 0xff;
85 I = hmac(sha512, chainCode, data);
86 key = I.slice(0, 32);
87 chainCode = I.slice(32);
88 }
89
90 return new Uint8Array(key);
91}
92
93/**
94 * Derive both EVM and Solana keys from a single mnemonic.

Callers 10

runFunction · 0.85
analyzeWithAIFunction · 0.85
deriveAllKeysFunction · 0.85
createWalletCommandFunction · 0.85
wallet.test.tsFile · 0.85
setupSolanaFunction · 0.85
mainFunction · 0.85

Calls 1

setMethod · 0.80

Tested by

no test coverage detected