diff --git a/README.md b/README.md index af5d23b..ad89e6a 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,8 @@ import driver from 'bigchaindb-driver' ```js const driver = require('bigchaindb-driver') +const base58 = require('bs58'); +const { Ed25519Sha256 } = require('crypto-conditions'); // BigchainDB server instance (e.g. https://example.com/api/v1/) const API_PATH = 'http://localhost:9984/api/v1/' @@ -89,6 +91,21 @@ const tx = driver.Transaction.makeCreateTransaction( // Sign the transaction with private keys const txSigned = driver.Transaction.signTransaction(tx, alice.privateKey) +// Or use delegateSignTransaction to provide your own signature function +function signTransaction() { + // get privateKey from somewhere + const privateKeyBuffer = Buffer.from(base58.decode(alice.privateKey)) + return function sign(transaction, input, transactionHash) { + const ed25519Fulfillment = new Ed25519Sha256(); + ed25519Fulfillment.sign( + Buffer.from(transactionHash, 'hex'), + privateKeyBuffer + ); + return ed25519Fulfillment.serializeUri(); + }; +} +const txSigned = driver.Transaction.delegateSignTransaction(tx, signTransaction()) + // Send the transaction off to BigchainDB const conn = new driver.Connection(API_PATH)