0.0.6 • Published 5 years ago

keychain.js v0.0.6

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

npm version

  • keychain.js - Keychain class with ws connection initialization
  • index.js - override web3.eth.accounts.signTransaction method
  • test.js - example usage together (keychain + web3)

Usage

  • Sign ethereum transaction
const { Keychain, keychainWeb3 } = require('keychain.js');
const Web3 = require('web3');
const API_KEY = 'https://ropsten.infura.io/v3/YOUR_ID';
const web3 = new Web3(new Web3.providers.HttpProvider(API_KEY));
const transactionParams = {
  to: '0xE8899BA12578d60e4D0683a596EDaCbC85eC18CC',
  value: 100,
  gas: 21000
};
// now we are using web3 with keychain
web3.eth.accounts.signTransaction = keychainWeb3.signTransaction.bind(web3);
const keychain = new Keychain();
keychain.selectKey()
  .then(publicKey => web3.eth.accounts.signTransaction(transactionParams, publicKey));
  • Sign & build ready for broadcast bitcoin transaction
  // import library
  import { bitcoin, Keychain } from 'web3override';

  // tx - bitcoin.TransactionBuilder instance with inputs & outputs
  const keyInstance = await Keychain.create();
  const data = await keyInstance.selectKey();
  const publicKey = data.result;
  tx.inputs.forEach((input, index) => {
    tx.prepareTx(index,  publicKey)
  });
  const txRawHex = await tx.buildTxKeychain(keyInstance, publicKey);

Run tests

npm run test

Add key to your key_data:

keyname: test1@76de427d42c38be4
password: qwe

alt image

TODO bitcoin tests