fix: improve imports

Signed-off-by: getlarge <ed@getlarge.eu>
This commit is contained in:
getlarge 2021-03-10 16:31:43 +01:00
parent 9b395c14a6
commit f020a35ea2
No known key found for this signature in database
GPG Key ID: E4E13243600F9566
3 changed files with 10 additions and 8 deletions

View File

@ -124,7 +124,7 @@ conn.postTransactionCommit(txSigned)
<meta charset="utf-8">
<title>BigchainDB boilerplate</title>
<!-- Adjust version to your needs -->
<script src="https://unpkg.com/bigchaindb-driver@4.0.0/dist/browser/bigchaindb-driver.window.min.js"></script>
<script src="https://unpkg.com/bigchaindb-driver@4.2.0/dist/browser/bigchaindb-driver.window.min.js"></script>
<script>
// BigchainDB server instance (e.g. https://example.com/api/v1/)

View File

@ -2,11 +2,13 @@
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
import sha3 from 'js-sha3'
/* eslint-disable camelcase */
import { sha3_256 } from 'js-sha3'
export default function sha256Hash(data) {
return sha3.sha3_256
return sha3_256
.create()
.update(data)
.hex()
}
/* eslint-enable camelcase */

View File

@ -6,7 +6,7 @@ import { Buffer } from 'buffer'
import stableStringify from 'json-stable-stringify'
import clone from 'clone'
import base58 from 'bs58'
import cc from 'crypto-conditions'
import { Ed25519Sha256, PreimageSha256, ThresholdSha256 } from 'crypto-conditions'
import ccJsonify from './utils/ccJsonify'
import sha256Hash from './sha256Hash'
@ -96,7 +96,7 @@ export default class Transaction {
static makeEd25519Condition(publicKey, json = true) {
const publicKeyBuffer = base58.decode(publicKey)
const ed25519Fulfillment = new cc.Ed25519Sha256()
const ed25519Fulfillment = new Ed25519Sha256()
ed25519Fulfillment.setPublicKey(publicKeyBuffer)
if (json) {
@ -143,7 +143,7 @@ export default class Transaction {
* @returns {Object} Preimage-Sha256 Condition (that will need to wrapped in an Output)
*/
static makeSha256Condition(preimage, json = true) {
const sha256Fulfillment = new cc.PreimageSha256()
const sha256Fulfillment = new PreimageSha256()
sha256Fulfillment.setPreimage(Buffer.from(preimage))
if (json) {
@ -160,7 +160,7 @@ export default class Transaction {
* @returns {Object} Sha256 Threshold Condition (that will need to wrapped in an Output)
*/
static makeThresholdCondition(threshold, subconditions = [], json = true) {
const thresholdCondition = new cc.ThresholdSha256()
const thresholdCondition = new ThresholdSha256()
thresholdCondition.setThreshold(threshold)
subconditions.forEach((subcondition) => {
@ -244,7 +244,7 @@ export default class Transaction {
.concat(input.fulfills.transaction_id)
.concat(input.fulfills.output_index) : serializedTransaction
const transactionHash = sha256Hash(transactionUniqueFulfillment)
const ed25519Fulfillment = new cc.Ed25519Sha256()
const ed25519Fulfillment = new Ed25519Sha256()
ed25519Fulfillment.sign(Buffer.from(transactionHash, 'hex'), privateKeyBuffer)
const fulfillmentUri = ed25519Fulfillment.serializeUri()