Blockchain e-sign library
npm install 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.
npm install opensig-lib
javascript
const opensig = require('opensig-lib')
`Usage
$3
Returns a KeyPair object containing a random private key and its associated wif and public keys.
`javascript
opensig.create( [label] ) // returns a KeyPair object
`
label optional label to populate the key's label property$3
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 ).`javascript
opensig.sign( , , [publish], [payment], [fee] ); // 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)_$3
Returns a promise to resolve an array of Signature objects containing the list of signatures for the given file.`javascript
opensig.verify( ) // 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)_.$3
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.
`javascript
opensig.send( , , , [fee], [publish] ); // 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)_$3
Returns a promise to resolve the sum of unspent transaction outputs retrieved from the blockchain for the given public key.
`javascript
opensig.balance( ) // returns an integer
`
key Public key. _(string containing a public key, hex64 private key, WIF or file. Can also accept a KeyPair object)_ $3
Returns a promise to resolve a KeyPair object from the given private key, WIF or file.
`javascript
opensig.getKey( ) // returns a promise
`
key Private key. _(string containing a hex64 private key, WIF or file)_ Examples
Require opensig-lib
`javascript
opensig = require('opensig-lib');
`
Create a new random private key and log its information to the console in various formats...
`javascript
var key = opensig.create();
console.log( key.toString() );
console.log( key.toString("") );
console.log( key.toString("") );
console.log( key.toString("") );
console.log( key.toString("id: , public key: , wif: , private key: ") );
console.log( key.toString("compressed keys: ") );
console.log( key.toString("uncompressed keys: ") );
`
Send 100000 satoshis from another address to your new key using the WIF of the other address. Use the default miner's fee...
`javascript
const myWellFundedWIF = "L1FpYdmkgXyRHQrMjy4ChBmJ4dbgJmr5Y1h5eX9LmsPWKBZBqkUg";
opensig.send( myWellFundedWIF, key, 100000, undefined, true )
.then( function log(response){ console.log(response); } )
.catch( function logError(err){ console.error(err.message); } );
`
Get the blockchain balance for the key...
`javascript
opensig.balance( key )
.then( function log(balance){ console.log(balance); } )
.catch( function logError(err){ console.error(err.message); } );
`
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...
`javascript
opensig.sign( "my_file.doc", key, true )
.then( function log(receipt){ console.log(receipt); } )
.catch( function logError(err){ console.error(err.message); } );
`
Verify my_file.doc and output the signatures to the console...
`javascript
opensig.verify( "my_file.doc" )
.then( function log(signatures){
for( var i in signatures ){
console.log( signatures[i].toString() );
} } )
.catch( function logError(err){ console.error(err.message); } );
`
Publish a transaction taken from a Receipt obtained from a previous call to send, logging the blockchain api response or error to the console...
`javascript
opensig.publish( myReceipt.txnHex )
.then( function log(response){ console.log(response); } )
.catch( function logError(err){ console.error(err.message); } );
`
Get a KeyPair object from a file and output its public key...
`javascript
opensig.getKey( "my_file.doc" )
.then( function log(keyPair){ console.log( keyPair.publicKey ); } )
.catch( function logError(err){ console.error(err.message); } );
``- OpenSig
If you have a project that you feel could be listed here, please ask for it!
$ npm test
$ npm run-script test-cov
OpenSig (c) 2016 D N Potter
Released under the MIT license