Skip to content

JavaScript API for using keos as Signature Provider to replace the JsSignatureProvider.

License

Notifications You must be signed in to change notification settings

Leask/eosjs-keos

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

eosjs-keos

JavaScript API for using keos as Signature Provider to replace the JsSignatureProvider.

Install

$ npm install eosjs-keos

Import

The official distribution package can be found at npm.

const { Api, JsonRpc, RpcError } = require('eosjs');
const { KeosSignatureProvider } = require('eosjs-keos/sig');
const fetch = require('node-fetch');                         // node only; not needed in browsers
const { TextEncoder, TextDecoder } = require('util');        // node only; native TextEncoder/Decoder

Basic Usage

The Signature Provider HOLDS the wallet password to unlock the wallet to signing transactions.

The Signature Provider DOES NOT HOLD any private keys directly.

const options = {
    keosApi: 'http://127.0.0.1:8900',
    wallet: 'keosjs_test',
    password: 'PWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
};
const signatureProvider = new KeosSignatureProvider(options);

It should be a drop in replacement. After these config, you can use native eosjs APIs smoothly. The Signature Provider will do the rest under the hood. More details can be found here.

Advance Options

skipUnlock

skipUnlock: false by default. You can enable this option skipUnlock: true to turn off the auto-unlock feature for extreme security. The Signature Provider can be run WITHOUT any password or key configurations. You have to lock/unlock the wallet all by yourself.

checkBeforeUnlock

checkBeforeUnlock: false by default. This means the Signature Provider will try to unlock the wallet whenever needed. It's fast and stable but will case annoying logs in the keosd console.

Example:

thread-0  http_plugin.cpp:932  handle_exception  ] FC Exception encountered while processing wallet.unlock

Set checkBeforeUnlock: true will force The Signature Provider to query and determine if the wallet needs to be unlocked, before actually unlock runs. It's a little bit slower but you can get a cleaner keosd console. It might cause issues when the wallet-unlock timeouts after check-action and before sign-action.

Complete Implementation of keos APIs

const KEOS = require('eosjs-keos');
const keos = new KEOS({ /* options */ });

API available:

  • getRpcUrl: AsyncFunction
  • rpcRequest: AsyncFunction
  • getSupportedApis: AsyncFunction
  • createWallet: AsyncFunction
  • listWallet: AsyncFunction
  • unlock: AsyncFunction
  • lock: AsyncFunction
  • lockAll: AsyncFunction
  • createKey: AsyncFunction
  • getPublicKeys: AsyncFunction
  • importKey: AsyncFunction
  • stop: AsyncFunction
  • openWallet: AsyncFunction
  • listKeys: AsyncFunction
  • removeKey: AsyncFunction
  • setTimeout: AsyncFunction
  • signDigest: AsyncFunction
  • signTransaction: AsyncFunction

Required chain access APIs

const CHAIN = require('eosjs-keos/chain');
const chain = new CHAIN({ /* options */ });

API available:

  • getRpcUrl: AsyncFunction
  • rpcRequest: AsyncFunction
  • makeActions: Function
  • getExpiration: Function
  • makeTransaction: AsyncFunction
  • getInfo: AsyncFunction
  • getAbiByAccountName: AsyncFunction
  • abiJsonToBin: AsyncFunction
  • getAbiBin: AsyncFunction
  • makeAbiActions: AsyncFunction
  • getRequiredKeys: AsyncFunction
  • getBlock: AsyncFunction
  • pushTransaction: AsyncFunction

Test

$ npm test

About

JavaScript API for using keos as Signature Provider to replace the JsSignatureProvider.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published