Skip to content

Commit

Permalink
fix: minor transaction module improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
getlarge committed Mar 9, 2021
1 parent 41ce117 commit 317bdd4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"buffer": "^6.0.3",
"clone": "^2.1.2",
"core-js": "^3.9.1",
"crypto-conditions": "^2.0.3",
"crypto-conditions": "^2.1.1",
"decamelize": "^5.0.0",
"es6-promise": "^4.2.8",
"fetch-ponyfill": "^7.1.0",
Expand Down
19 changes: 8 additions & 11 deletions src/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default class Transaction {
* @returns {Object} Ed25519 Condition (that will need to wrapped in an Output)
*/
static makeEd25519Condition(publicKey, json = true) {
const publicKeyBuffer = Buffer.from(base58.decode(publicKey))
const publicKeyBuffer = base58.decode(publicKey)

const ed25519Fulfillment = new cc.Ed25519Sha256()
ed25519Fulfillment.setPublicKey(publicKeyBuffer)
Expand Down Expand Up @@ -144,7 +144,7 @@ export default class Transaction {
*/
static makeSha256Condition(preimage, json = true) {
const sha256Fulfillment = new cc.PreimageSha256()
sha256Fulfillment.preimage = Buffer.from(preimage)
sha256Fulfillment.setPreimage(Buffer.from(preimage))

if (json) {
return ccJsonify(sha256Fulfillment)
Expand All @@ -161,11 +161,12 @@ export default class Transaction {
*/
static makeThresholdCondition(threshold, subconditions = [], json = true) {
const thresholdCondition = new cc.ThresholdSha256()
thresholdCondition.threshold = threshold
thresholdCondition.setThreshold(threshold)

subconditions.forEach((subcondition) => {
// TODO: add support for Condition and URIs
// TODO: add support for Condition
thresholdCondition.addSubfulfillment(subcondition)
//? Should be thresholdCondition.addSubcondition(subcondition)
})

if (json) {
Expand Down Expand Up @@ -237,7 +238,7 @@ export default class Transaction {

signedTx.inputs.forEach((input, index) => {
const privateKey = privateKeys[index]
const privateKeyBuffer = Buffer.from(base58.decode(privateKey))
const privateKeyBuffer = base58.decode(privateKey)

const transactionUniqueFulfillment = input.fulfills ? serializedTransaction
.concat(input.fulfills.transaction_id)
Expand Down Expand Up @@ -268,12 +269,8 @@ export default class Transaction {
const serializedTransaction =
Transaction.serializeTransactionIntoCanonicalString(transaction)

signedTx.inputs.forEach((input) => {
const transactionUniqueFulfillment = input.fulfills ? serializedTransaction
.concat(input.fulfills.transaction_id)
.concat(input.fulfills.output_index) : serializedTransaction
const transactionHash = sha256Hash(transactionUniqueFulfillment)
const fulfillmentUri = signFn(input, transactionHash)
signedTx.inputs.forEach((input, index) => {
const fulfillmentUri = signFn(serializedTransaction, input, index)
input.fulfillment = fulfillmentUri
})

Expand Down

0 comments on commit 317bdd4

Please sign in to comment.