From a4d8ff531b5e327f0e6400be8aa3bb48f4be50ec Mon Sep 17 00:00:00 2001 From: getlarge Date: Thu, 10 Dec 2020 13:04:23 +0100 Subject: [PATCH] add example usage Signed-off-by: getlarge --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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)