Giter Club home page Giter Club logo

tonweb-mnemonic's Introduction

tonweb-mnemonic

NPM

Mnemonic code for generating deterministic keys for TON blockchain.

Features

  • library interface is similar to the library bitcoinjs/bip39 (mnemonic for Bitcoin),
  • there is only one dependency: tweetnacl,
  • supports both Browser (UMD) and Node.js (>=15, CommonJS)
  • written in TypeScript and provides typing declarations

Install

npm install --save tonweb-mnemonic

Usage in browser

`<script src="libs/tonweb.js"></script>`
`<script src="libs/tonweb-mnemonic.js"></script>`

<script type="application/javascript">
    // mnemonic is set to window.TonWeb object if it exists:
    const tonMnemonic = window.TonWeb.mnemonic;    
</script>

Usage in Node.js

import tonMnemonic from "tonweb-mnemonic";

async function example() {
    tonMnemonic.wordlists.EN;
    // -> array of all words

    const mnemonic = await tonMnemonic.generateMnemonic();
    // -> ["vintage", "nice", "initial", ... ]  24 words by default

    await tonMnemonic.validateMnemonic(mnemonic);
    // -> true

    await tonMnemonic.isPasswordNeeded(mnemonic);
    // -> false

    await tonMnemonic.mnemonicToSeed(mnemonic);
    // -> Uint8Array(32) [183, 90, 187, 181, .. ]

    const keyPair = await tonMnemonic.mnemonicToKeyPair(mnemonic);
    // -> {publicKey: Uint8Array(32), secretKey: Uint8Array(64)}

    toHexString(keyPair.publicKey);
    // -> "8c8dfc9f9f58badd76151775ff0699bb2498939f669eaef2de16f95a52888c65"

    toHexString(keyPair.secretKey);
    // -> "b75abbb599feed077c8e11cc8cadecfce4945a7869a56d3d38b59cce057a3e0f8c8dfc9f9f58badd76151775ff0699bb2498939f669eaef2de16f95a52888c65"
}

function toHexString(byteArray) {
    return Array.prototype.map.call(byteArray, function(byte) {
        return ('0' + (byte & 0xFF).toString(16)).slice(-2);
    }).join('');
}

Contributing

We will gladly accept any useful contributions.

TO DO:

  • write tests for all functions (improve tests coverage)
  • implement tests execution on all OSes in Node
  • implement tests execution in Browser (i.e. headless Chrome)

Development guide

npm install — to install dependencies

npm run build — to make a development build

npm run build:ci — to make a production build

npm run test:manual — to run manual tests in the browser

Contributors

tonweb-mnemonic's People

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.