Skip to content

Commit

Permalink
fix: improve imports
Browse files Browse the repository at this point in the history
Signed-off-by: getlarge <ed@getlarge.eu>
  • Loading branch information
getlarge committed Mar 10, 2021
1 parent 9b395c1 commit f020a35
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
Expand Down
6 changes: 4 additions & 2 deletions src/sha256Hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
10 changes: 5 additions & 5 deletions src/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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) => {
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit f020a35

Please sign in to comment.