GithubHelp home page GithubHelp logo

chatch / stellar-hd-wallet Goto Github PK

View Code? Open in Web Editor NEW
82.0 9.0 47.0 85 KB

🔐 Key derivation for Stellar (SEP-0005) 🚀

Home Page: https://www.npmjs.com/package/stellar-hd-wallet

License: Apache License 2.0

JavaScript 100.00%
stellar sep-0005 bip39 bip32 nodejs npm ed25519 bip44 javascript

stellar-hd-wallet's Introduction

stellar-hd-wallet

NPM Package Build Status

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)

Tests

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

stellar-hd-wallet's People

Contributors

chatch avatar johansten avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

stellar-hd-wallet's Issues

Aarry length and seceret key length i different

When i use
var secret_key=wallet.getSecret(0);
console.log("secret_key",secret_key);

"SCVVKNLBHOWBNJYHD3CNROOA2P3K35I5GNTYUHLLMUHMHWQYNEI7LVED"
its generating 28 byte of hash value.

but when the get the keypair value
var keyPair=wallet.getKeypair(0);

i ll get secret_key 32 bytes,

why hash and key-pair array is different..?

Signing issue using nacl

I am generating new key pair its working,But when i try to use signing function its throws the error Uncaught Error: bad secret key size

//Generate new keyPair
function generateNewKeyPair(menomic)
{
var Password=""
const wallet = HDWallet.fromMnemonic(menomic);
var publickey=wallet.getPublicKey(0)
var seceretkey=wallet.getSecret(0)
var keyPair=wallet.getKeypair(0);
signTransaction(keyPair.rawSecretKey(),publickey);
}

//signTransaction
function signTransaction(seceretkey,publicKey)
{
var data = 'data to sign';
var signature = steller.sign(data,seceretkey);
if (steller.verify(data, signature,publicKey)) {
console.log('OK!');
} else {
console.log('Bad signature!');
}
}
generateNewKeyPair();

update stellar-base dependency

Tried to use the wallet for an angular 6 project and could not build it because the angular cli started complaining about the crypto library. I then found out that wallet is currently using the stellar-base 0.11. The guys from stellar have removed the crypto library in version 0.13 of the stellar-base sdk which should have fixed the issue. More details can be found here

fromMnemonic should validate the mnemonic parameter

So currently invalid (words not in wordlist, too short, etc.) and empty mnemonics work perfectly fine.

Change this to call validateMnemonic on the mnemonic parameter before continuing. Throw an error if mnemonic is not valid.

Steller account does not address hex

I was checking "stellar-hd-wallet" ,It generate only secret Key and public key, I cant find the address hex. Does the public keys is receive address.?

Error when including both stellar-hd-wallet and stellar-sdk in my project

When I include both stellar-hd-wallet and stellar-sdk in my project I get errors when requiring them both as stellar-base is included twice, not sure if stellar-base should instead be a peerDependency or how to solve this...

Any suggestions?

Error: XDR Error:Value is already defined
    at TypeBuilder.define (/code/blockchain-client/node_modules/js-xdr/lib/config.js:341:17)
    at TypeBuilder.typedef (/code/blockchain-client/node_modules/js-xdr/lib/config.js:247:14)
    at /code/blockchain-client/node_modules/stellar-hd-wallet/node_modules/stellar-base/lib/generated/stellar-xdr_generated.js:1:259
    at Object.config (/code/blockchain-client/node_modules/js-xdr/lib/config.js:38:5)
    at Object.<anonymous> (//code/blockchain-client/node_modules/stellar-hd-wallet/node_modules/stellar-base/lib/generated/stellar-xdr_generated.js:1:234)

These are the related deps in my package.json:

"stellar-hd-wallet": "0.0.6",
"stellar-sdk": "^0.9.2"

Cannot retrieve secret key from mneumonic

`const StellarHDWallet = require("stellar-hd-wallet");
const { Keypair } = require("stellar-sdk");

function privateKeyToMnemonic(privateKey) {
const mnemonic = StellarHDWallet.generateMnemonic(privateKey);
return mnemonic;
}

const privateKey = "SBT4B2Y4VN33OCHVPRSD6JXXNPZ2UDXQFLRS7B5C4MLRMLOTEZS4UDY5";
console.log("Private key before: ", privateKey);

const mneumonic = privateKeyToMnemonic(privateKey);
console.log("Mneumonic is ", mneumonic);

const wallet = StellarHDWallet.fromMnemonic(mneumonic);
console.log(wallet.getSecret(0));
`
The key keeps changing

Private key before: SBT4B2Y4VN33OCHVPRSD6JXXNPZ2UDXQFLRS7B5C4MLRMLOTEZS4UDY5 Mneumonic is decline come potato citizen visual awkward owner illness pigeon save apple snake ordinary salmon twenty uphold toss must put primary oak hollow people ivory SBCNTVPPHD2GDWQTKA7CNCMLI53QDZK7JWKHTDZGTVCV4OIHTSGR5GQI

Private key before: SBT4B2Y4VN33OCHVPRSD6JXXNPZ2UDXQFLRS7B5C4MLRMLOTEZS4UDY5 Mneumonic is dance scatter cry recycle rookie day wage culture fly expect wolf mirror market approve soon before test sleep heavy connect unknown lawsuit lake idle SDZGV6NYGR7BNCWMJV2EUPXSGGGUEZ3C47Y2RPCFF7J7RHC6XZIUEVPU

no types!

Please either rebuild with TypeScript (highly recommend! it's so great!) or add a types file. Thanks"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.