mirror of
https://github.com/bigchaindb/js-bigchaindb-driver.git
synced 2024-12-29 08:07:51 +01:00
load condition details and test transfer and sign
This commit is contained in:
parent
35944d6d75
commit
ce523e703f
@ -24,7 +24,7 @@ export default function signTransaction(transaction, ...privateKeys) {
|
||||
const privateKey = privateKeys[index]
|
||||
const privateKeyBuffer = new Buffer(base58.decode(privateKey))
|
||||
const serializedTransaction = serializeTransactionIntoCanonicalString(transaction)
|
||||
const ed25519Fulfillment = new cc.Ed25519()
|
||||
const ed25519Fulfillment = new cc.Ed25519Sha256()
|
||||
ed25519Fulfillment.sign(new Buffer(serializedTransaction), privateKeyBuffer)
|
||||
const fulfillmentUri = ed25519Fulfillment.serializeUri()
|
||||
|
||||
|
@ -19,7 +19,7 @@ export default function ccJsonLoad(conditionJson) {
|
||||
} else {
|
||||
let fulfillment
|
||||
|
||||
if (conditionJson.type_id === 2) {
|
||||
if (conditionJson.type === 'threshold-sha-256') {
|
||||
fulfillment = new cc.ThresholdSha256()
|
||||
fulfillment.threshold = conditionJson.threshold
|
||||
conditionJson.subfulfillments.forEach((subfulfillmentJson) => {
|
||||
@ -32,13 +32,8 @@ export default function ccJsonLoad(conditionJson) {
|
||||
})
|
||||
}
|
||||
|
||||
if (conditionJson.type_id === 0) {
|
||||
fulfillment = new cc.PreimageSha256()
|
||||
fulfillment.preimage = new Buffer(conditionJson.preimage)
|
||||
}
|
||||
|
||||
if (conditionJson.type_id === 4) {
|
||||
fulfillment = new cc.Ed25519()
|
||||
if (conditionJson.type === 'ed25519-sha-256') {
|
||||
fulfillment = new cc.Ed25519Sha256()
|
||||
fulfillment.publicKey = new Buffer(base58.decode(conditionJson.public_key))
|
||||
if (conditionJson.signature) {
|
||||
fulfillment.signature = new Buffer(base58.decode(conditionJson.signature))
|
||||
|
27
test/test.js
27
test/test.js
@ -1,4 +1,5 @@
|
||||
import test from 'ava'
|
||||
import cc from 'five-bells-condition'
|
||||
import { Ed25519Keypair, Transaction, Connection } from '../src'
|
||||
|
||||
const API_PATH = 'http://localhost:9984/api/v1/'
|
||||
@ -28,6 +29,11 @@ test('Valid CREATE transaction is evaluated by BigchainDB', t => {
|
||||
.then(resTx => t.truthy(resTx))
|
||||
})
|
||||
|
||||
|
||||
/*
|
||||
* CryptoConditions support tests
|
||||
*/
|
||||
|
||||
test('Ed25519 condition encoding', t => {
|
||||
const publicKey = '4zvwRjXUKGfvwnParsHAS3HuSVzV5cA4McphgmoCtajS'
|
||||
const target = {
|
||||
@ -59,3 +65,24 @@ test('Threshold condition encoding', t => {
|
||||
}
|
||||
t.deepEqual(target, condition)
|
||||
})
|
||||
|
||||
test('Fulfillment correctly formed', t => {
|
||||
const alice = new Ed25519Keypair()
|
||||
const txCreate = Transaction.makeCreateTransaction(
|
||||
{},
|
||||
{},
|
||||
[Transaction.makeOutput(Transaction.makeEd25519Condition(alice.publicKey))],
|
||||
alice.publicKey
|
||||
)
|
||||
const txTransfer = Transaction.makeTransferTransaction(
|
||||
txCreate,
|
||||
{},
|
||||
[Transaction.makeOutput(Transaction.makeEd25519Condition(alice.publicKey))],
|
||||
[0]
|
||||
)
|
||||
const msg = Transaction.serializeTransactionIntoCanonicalString(txTransfer)
|
||||
const txSigned = Transaction.signTransaction(txTransfer, alice.privateKey)
|
||||
t.truthy(cc.validateFulfillment(txSigned.inputs[0].fulfillment,
|
||||
txCreate.outputs[0].condition.uri,
|
||||
new Buffer(msg)))
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user