OpenSig Library (opensig-lib)
Blockchain digital signature library. A javascript library that implements the OpenSig digitial signature scheme providing functions to digitally sign and verify files, recording signatures on the bitcoin blockchain.
opensig-lib is built using bitcoinjs-lib.
Primary Features
- Create: generate a new private key.
- Sign: sign any file with your private key and record your signature on the blockchain.
- Verify: retrieve a list of a file's signatures from the blockchain.
Secondary Features
- Send: create and publish a transaction to spend any amount from one address to another.
- Publish: publish a transaction on the blockchain.
- Balance: retrieve the balance of your key (or any public key) from the blockchain.
- Get Key: obtain private key, wif and public keys from any private key, WIF or file.
Installation
npm install opensig-lib
Setup
Node.js
const opensig =
Usage
Create
Returns a KeyPair object containing a random private key and its associated wif and public keys.
opensig // returns a KeyPair object
label
optional label to populate the key's label property
Sign
Returns a promise to resolve a Receipt object containing a transaction to sign the given file with the given key, and, optionally, to publish the transaction on the blockchain.
Equivalent to opensig.send( key, file, payment, fee, publish )
.
opensig; // returns a promise
file
File to sign. (string containing a file path or a file's hex64 private key or WIF. Can also accept a KeyPair object).
key
Key to sign with. (KeyPair, or a string containing a hex64 private key, a WIF or a file)
publish
If true the transaction will be published on the blockchain. (boolean)
payment
Amount to send in the transaction. Defaults to 5430 satoshis. (positive integer)
fee
Amount to include as the miner's fee. Defaults to 10000 satoshis. (positive integer)
Verify
Returns a promise to resolve an array of Signature objects containing the list of signatures for the given file.
opensig // returns a promise
file
File to verify. (string containing a file path or a file's hex64 private key or WIF. Can also accept a KeyPair object).
Send
Returns a promise to resolve a Receipt object containing a transaction to send the given amount or amounts from the from
key to the to
address, and, optionally, to publish the transaction on the blockchain.
opensig; // returns a promise
from
Private key or wif of the address to spend from. (string containing a hex64 private key, WIF or file. Can also accept a KeyPair object).
to
Address to send to. (string containing a public key, hex64 private key, WIF or file. Can also accept a KeyPair object)
amount
Amount to spend in the transaction. If an array is passed then a transaction output for each element will be created. (positive integer or array of positive integers)
fee
Amount to include as the miner's fee in addition to the amount. Defaults to 10000 satoshis. (positive integer)
publish
If true the transaction will be published on the blockchain. Defaults to false. (boolean)
Balance
Returns a promise to resolve the sum of unspent transaction outputs retrieved from the blockchain for the given public key.
opensig // returns an integer
key
Public key. (string containing a public key, hex64 private key, WIF or file. Can also accept a KeyPair object)
Get Key
Returns a promise to resolve a KeyPair object from the given private key, WIF or file.
opensig // returns a promise
key
Private key. (string containing a hex64 private key, WIF or file)
Examples
Require opensig-lib
opensig = ;
Create a new random private key and log its information to the console in various formats...
var key = opensig;console;console;console;console;console;console;console;
Send 100000 satoshis from another address to your new key using the WIF of the other address. Use the default miner's fee...
const myWellFundedWIF = "L1FpYdmkgXyRHQrMjy4ChBmJ4dbgJmr5Y1h5eX9LmsPWKBZBqkUg";opensig ;
Get the blockchain balance for the key...
opensig ;
Generate a transaction to sign my_file.doc, including publishing it to the blockchain, and log the resulting Receipt object or error to the console...
opensig ;
Verify my_file.doc and output the signatures to the console...
opensig ;
Publish a transaction taken from a Receipt obtained from a previous call to send
, logging the blockchain api response or error to the console...
opensig ;
Get a KeyPair object from a file and output its public key...
opensig ;
Projects utilizing opensig-lib
If you have a project that you feel could be listed here, please ask for it!
Run the tests
$ npm test
$ npm run-script test-cov
Copyright
OpenSig (c) 2016 D N Potter
Released under the MIT license