DEPRECIATED. This original version of OpenSig is no longer supported. The new standard has moved to EVM-based blockchains to allow for more advanced features.
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
const opensig = require('opensig-lib')
Returns a KeyPair object containing a random private key and its associated wif and public keys.
opensig.create( [label] ) // returns a KeyPair object
label
optional label to populate the key's label property
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.sign( <file>, <key>, [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)
Returns a promise to resolve an array of Signature objects containing the list of signatures for the given file.
opensig.verify( <file> ) // 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).
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.send( <from>, <to>, <amount>, [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 (in satoshis). 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)
Returns a promise to resolve the sum of unspent transaction outputs retrieved from the blockchain for the given public key.
opensig.balance( <key> ) // returns an integer
key
Public key. (string containing a public key, hex64 private key, WIF or file. Can also accept a KeyPair object)
Returns a promise to resolve a KeyPair object from the given private key, WIF or file.
opensig.getKey( <key> ) // returns a promise
key
Private key. (string containing a hex64 private key, WIF or file)
Require opensig-lib
opensig = require('opensig-lib');
Create a new random private key and log its information to the console in various formats...
var key = opensig.create();
console.log( key.toString() );
console.log( key.toString("<full>") );
console.log( key.toString("<id>") );
console.log( key.toString("<pub>") );
console.log( key.toString("id: <id>, public key: <pub>, wif: <wif>, private key: <priv>") );
console.log( key.toString("compressed keys: <pubc> <wifc>") );
console.log( key.toString("uncompressed keys: <pubu> <wifu>") );
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.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...
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...
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...
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...
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...
opensig.getKey( "my_file.doc" )
.then( function log(keyPair){ console.log( keyPair.publicKey ); } )
.catch( function logError(err){ console.error(err.message); } );
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