mirror of
https://github.com/bigchaindb/js-bigchaindb-driver.git
synced 2024-11-22 01:36:56 +01:00
add example usage
Signed-off-by: getlarge <ed@getlarge.eu>
This commit is contained in:
parent
54ecf63a82
commit
a4d8ff531b
17
README.md
17
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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user