1
0
mirror of https://github.com/bigchaindb/js-bigchaindb-driver.git synced 2024-11-22 09:46:58 +01:00

add example usage

Signed-off-by: getlarge <ed@getlarge.eu>
This commit is contained in:
getlarge 2020-12-10 13:04:23 +01:00
parent 54ecf63a82
commit a4d8ff531b

View File

@ -62,6 +62,8 @@ import driver from 'bigchaindb-driver'
```js ```js
const driver = require('bigchaindb-driver') const driver = require('bigchaindb-driver')
const base58 = require('bs58');
const { Ed25519Sha256 } = require('crypto-conditions');
// BigchainDB server instance (e.g. https://example.com/api/v1/) // BigchainDB server instance (e.g. https://example.com/api/v1/)
const API_PATH = 'http://localhost:9984/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 // Sign the transaction with private keys
const txSigned = driver.Transaction.signTransaction(tx, alice.privateKey) 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 // Send the transaction off to BigchainDB
const conn = new driver.Connection(API_PATH) const conn = new driver.Connection(API_PATH)