mirror of
https://github.com/bigchaindb/js-bigchaindb-driver.git
synced 2024-11-22 09:46:58 +01:00
fix: minor transaction module improvements
This commit is contained in:
parent
41ce1178c7
commit
317bdd4d0f
@ -76,7 +76,7 @@
|
|||||||
"buffer": "^6.0.3",
|
"buffer": "^6.0.3",
|
||||||
"clone": "^2.1.2",
|
"clone": "^2.1.2",
|
||||||
"core-js": "^3.9.1",
|
"core-js": "^3.9.1",
|
||||||
"crypto-conditions": "^2.0.3",
|
"crypto-conditions": "^2.1.1",
|
||||||
"decamelize": "^5.0.0",
|
"decamelize": "^5.0.0",
|
||||||
"es6-promise": "^4.2.8",
|
"es6-promise": "^4.2.8",
|
||||||
"fetch-ponyfill": "^7.1.0",
|
"fetch-ponyfill": "^7.1.0",
|
||||||
|
@ -94,7 +94,7 @@ export default class Transaction {
|
|||||||
* @returns {Object} Ed25519 Condition (that will need to wrapped in an Output)
|
* @returns {Object} Ed25519 Condition (that will need to wrapped in an Output)
|
||||||
*/
|
*/
|
||||||
static makeEd25519Condition(publicKey, json = true) {
|
static makeEd25519Condition(publicKey, json = true) {
|
||||||
const publicKeyBuffer = Buffer.from(base58.decode(publicKey))
|
const publicKeyBuffer = base58.decode(publicKey)
|
||||||
|
|
||||||
const ed25519Fulfillment = new cc.Ed25519Sha256()
|
const ed25519Fulfillment = new cc.Ed25519Sha256()
|
||||||
ed25519Fulfillment.setPublicKey(publicKeyBuffer)
|
ed25519Fulfillment.setPublicKey(publicKeyBuffer)
|
||||||
@ -144,7 +144,7 @@ export default class Transaction {
|
|||||||
*/
|
*/
|
||||||
static makeSha256Condition(preimage, json = true) {
|
static makeSha256Condition(preimage, json = true) {
|
||||||
const sha256Fulfillment = new cc.PreimageSha256()
|
const sha256Fulfillment = new cc.PreimageSha256()
|
||||||
sha256Fulfillment.preimage = Buffer.from(preimage)
|
sha256Fulfillment.setPreimage(Buffer.from(preimage))
|
||||||
|
|
||||||
if (json) {
|
if (json) {
|
||||||
return ccJsonify(sha256Fulfillment)
|
return ccJsonify(sha256Fulfillment)
|
||||||
@ -161,11 +161,12 @@ export default class Transaction {
|
|||||||
*/
|
*/
|
||||||
static makeThresholdCondition(threshold, subconditions = [], json = true) {
|
static makeThresholdCondition(threshold, subconditions = [], json = true) {
|
||||||
const thresholdCondition = new cc.ThresholdSha256()
|
const thresholdCondition = new cc.ThresholdSha256()
|
||||||
thresholdCondition.threshold = threshold
|
thresholdCondition.setThreshold(threshold)
|
||||||
|
|
||||||
subconditions.forEach((subcondition) => {
|
subconditions.forEach((subcondition) => {
|
||||||
// TODO: add support for Condition and URIs
|
// TODO: add support for Condition
|
||||||
thresholdCondition.addSubfulfillment(subcondition)
|
thresholdCondition.addSubfulfillment(subcondition)
|
||||||
|
//? Should be thresholdCondition.addSubcondition(subcondition)
|
||||||
})
|
})
|
||||||
|
|
||||||
if (json) {
|
if (json) {
|
||||||
@ -237,7 +238,7 @@ export default class Transaction {
|
|||||||
|
|
||||||
signedTx.inputs.forEach((input, index) => {
|
signedTx.inputs.forEach((input, index) => {
|
||||||
const privateKey = privateKeys[index]
|
const privateKey = privateKeys[index]
|
||||||
const privateKeyBuffer = Buffer.from(base58.decode(privateKey))
|
const privateKeyBuffer = base58.decode(privateKey)
|
||||||
|
|
||||||
const transactionUniqueFulfillment = input.fulfills ? serializedTransaction
|
const transactionUniqueFulfillment = input.fulfills ? serializedTransaction
|
||||||
.concat(input.fulfills.transaction_id)
|
.concat(input.fulfills.transaction_id)
|
||||||
@ -268,12 +269,8 @@ export default class Transaction {
|
|||||||
const serializedTransaction =
|
const serializedTransaction =
|
||||||
Transaction.serializeTransactionIntoCanonicalString(transaction)
|
Transaction.serializeTransactionIntoCanonicalString(transaction)
|
||||||
|
|
||||||
signedTx.inputs.forEach((input) => {
|
signedTx.inputs.forEach((input, index) => {
|
||||||
const transactionUniqueFulfillment = input.fulfills ? serializedTransaction
|
const fulfillmentUri = signFn(serializedTransaction, input, index)
|
||||||
.concat(input.fulfills.transaction_id)
|
|
||||||
.concat(input.fulfills.output_index) : serializedTransaction
|
|
||||||
const transactionHash = sha256Hash(transactionUniqueFulfillment)
|
|
||||||
const fulfillmentUri = signFn(input, transactionHash)
|
|
||||||
input.fulfillment = fulfillmentUri
|
input.fulfillment = fulfillmentUri
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user