MCPcopy Index your code
hub / github.com/chatch/stellar-hd-wallet

github.com/chatch/stellar-hd-wallet @v1.0.2

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.0.2 ↗ · + Follow
23 symbols 56 edges 4 files 10 documented · 43%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

stellar-hd-wallet

NPM Package Node.js CI

Key derivation for Stellar (SEP-0005)

Usage

import StellarHDWallet from 'stellar-hd-wallet';

const mnemonic = StellarHDWallet.generateMnemonic();
const wallet = StellarHDWallet.fromMnemonic(mnemonic);

wallet.getPublicKey(0); // => GDKYMXOAJ5MK4EVIHHNWRGAAOUZMNZYAETMHFCD6JCVBPZ77TUAZFPKT
wallet.getSecret(0); // => SCVVKNLBHOWBNJYHD3CNROOA2P3K35I5GNTYUHLLMUHMHWQYNEI7LVED
wallet.getKeypair(0); // => StellarBase.Keypair for account 0
wallet.derive(`m/44'/148'/0'`); // => raw key for account 0 as a Buffer

// wallet instance from seeds
const seedHex =
  '794fc27373add3ac7676358e868a787bcbf1edfac83edcecdb34d7f1068c645dbadba563f3f3a4287d273ac4f052d2fc650ba953e7af1a016d7b91f4d273378f';
const seedBuffer = Buffer.from(seedHex);
StellarHDWallet.fromSeed(seedHex);
StellarHDWallet.fromSeed(seedBuffer);

// mnemonics with different lengths
StellarHDWallet.generateMnemonic(); // 24 words
StellarHDWallet.generateMnemonic({entropyBits: 224}); // 21 words
StellarHDWallet.generateMnemonic({entropyBits: 160}); // 18 words
StellarHDWallet.generateMnemonic({entropyBits: 128}); // 12 words

// validate a mnemonic
StellarHDWallet.validateMnemonic('too short and non wordlist words'); // false

Mnemonic Language

Mnemonics can be generated in any language supported by the underlying bip39 npm module.

The full list of language keys are under exports 'wordlists' here.

Usage

import StellarHDWallet from 'stellar-hd-wallet';

// traditional chinese - 24 words
StellarHDWallet.generateMnemonic({
  language: 'chinese_traditional',
});
// => '省 从 唯 芽 激 顿 埋 愤 碳 它 炸 如 青 领 涨 骤 度 牲 朱 师 即 姓 讲 蒋'

// french - 12 words
StellarHDWallet.generateMnemonic({language: 'french', entropyBits: 128});
// => 'directif terrible légume dérober science vision venimeux exulter abrasif vague mutuel innocent'

Randomness

  • NodeJs: crypto.randomBytes
  • Browser: window.crypto.getRandomValues

(using randombytes npm module)

Development

Setup

npm install

Build

npm run build

Test

npm test

Tests

All SEP-0005 test cases are exercised here against these.

Extension points exported contracts — how you extend this code

TestCase (Interface)
(no doc)
test/sep0005.ts
MnemonicOptions (Interface)
(no doc)
src/stellar-hd-wallet.ts
KeyData (Interface)
(no doc)
src/hd-key.ts

Core symbols most depended-on inside this repo

generateMnemonic
called by 8
src/stellar-hd-wallet.ts
fromMnemonic
called by 7
src/stellar-hd-wallet.ts
getPublicKey
called by 6
src/stellar-hd-wallet.ts
getSecret
called by 6
src/stellar-hd-wallet.ts
expectInvalidMnemonicFailure
called by 5
test/stellar-hd-wallet.ts
specTestCase
called by 5
test/sep0005.ts
assertInvalidEntropy
called by 4
test/stellar-hd-wallet.ts
getKeypair
called by 3
src/stellar-hd-wallet.ts

Shape

Function 9
Method 9
Interface 3
Class 2

Languages

TypeScript100%

Modules by API surface

src/stellar-hd-wallet.ts12 symbols
src/hd-key.ts6 symbols
test/sep0005.ts3 symbols
test/stellar-hd-wallet.ts2 symbols

For agents

$ claude mcp add stellar-hd-wallet \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact