aioz-js

1.0.15 • Public • Published

AIOZ Keytool

A javascript library allows to manipulate keys/wallet on browser.

Features

The code is ported from aiozd keytool, written in Javascript in order to:

  • generate new wallet
  • restore wallet from mnemonic
  • support generating ECDH key from private key JSON
  • generate shared key of ECDH

Installation

    npm install aioz-js

And use in code:

    const aioz = require('aioz-js');

Usage

Generate private/public key with a random 24-word mnemonic, encrypted with or without a passphrase:

    const key1 = aioz.newKey("12345678");   // encrypt private key with passphrase
    const key2 = aioz.newKey();   // no encryption for private key 

Recover wallet and private/public keys from 24-word mnemonic:

    const recoveredKeys = aioz.recover("pair that turn trash leave problem snap fork innocent symptom case please party stomach fly mirror panel stand possible decade soul strike poem feature");

From aioz key, create corresponding ECDH key:

    const ecdh1 = aioz.generateEcdhFromKeytool(key1.priv_key);
    const ecdh2 = aioz.generateEcdhFromKeytool(key2.priv_key);

Exchange public key to get shared key between 2 partners:

    const shared12 = ecdh1.derive(ecdh2.pub);
    const shared21 = ecdh2.derive(ecdh1.pub);
    console.log(shared12.toString(16);  // this should be the same as shared21
    console.log(shared21.toString(16);

Two partners can derive shared key using other's public key under JSON format

    const sharedKeyUsingJSON = ecdh1.deriveFromJSON("{\"type\":\"tendermint/PubKeySecp256k1\",\"value\":\"A6g+QlHU9iFpJNeAEtmCOD0wTw3jfDRpiHn4ARe8MGBz\"}");

Package Sidebar

Install

npm i aioz-js

Weekly Downloads

16

Version

1.0.15

License

MIT

Unpacked Size

23.3 kB

Total Files

9

Last publish

Collaborators

  • glacial_boy