Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Threshold fulfillments #119

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

future-is-present
Copy link
Contributor

@future-is-present future-is-present commented Nov 6, 2017

Implement a method to create threshold fulfillments for an input. For this purpose is needed the fulfillment in the makeCreateTransaction and makeTransferTransaction methods that was null until now.

@codecov-io
Copy link

codecov-io commented Nov 6, 2017

Codecov Report

Merging #119 into master will increase coverage by 1.44%.
The diff coverage is 96%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #119      +/-   ##
==========================================
+ Coverage    82.2%   83.64%   +1.44%     
==========================================
  Files          21       22       +1     
  Lines         281      318      +37     
==========================================
+ Hits          231      266      +35     
- Misses         50       52       +2
Impacted Files Coverage Δ
src/transaction/makeTransferTransaction.js 100% <100%> (ø) ⬆️
src/transaction/makeCreateTransaction.js 100% <100%> (ø) ⬆️
src/transaction/makeTransaction.js 100% <100%> (ø) ⬆️
src/transaction/makeFulfillment.js 100% <100%> (ø)
src/transaction/signTransaction.js 94.59% <93.1%> (-5.41%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5f2ee8c...5d217a4. Read the comment docs.

Copy link
Contributor

@TimDaub TimDaub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great start 👍

Another thing: Please add docs for this.

Added a couple more items on the list. Please let me know how I can help :)

}
return fulfillment
} else {
const subcdts = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

subcdts is not an appreviation we commonly use in the code base.
I suggest to rename to a word we also use in other implementations.

@@ -16,13 +17,19 @@ function makeTransactionTemplate() {

export default function makeTransaction(operation, asset, metadata = null, outputs = [], inputs = []) {
const tx = makeTransactionTemplate()

const realInputs = clone(inputs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest naming this to something else than real. E.g. inputsCopy etc.

const assetLink = {
'id': unspentTransaction.operation === 'CREATE' ? unspentTransaction.id
: unspentTransaction.asset.id
}
const makeT = makeTransaction('TRANSFER', assetLink, metadata, outputs, inputs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change? I suspect you don't need makeT after the return?

privateKeys.splice(0, 1)
const privateKeyBuffer = new Buffer(base58.decode(privateKey))
ed25519subFulfillment.sign(new Buffer(serializedTransaction), privateKeyBuffer)
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codecov says, this condition is not covered by tests. Please add :)

signedTx.inputs.forEach((input) => {
if (input.fulfillment.type === 'ed25519-sha-256') {
const privateKey = privateKeys[0]
privateKeys.splice(0, 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

splice returns the removed element within an array. Not sure how useful that is, but you could combine the two lines.

@@ -20,15 +20,43 @@ import serializeTransactionIntoCanonicalString from './serializeTransactionIntoC
*/
export default function signTransaction(transaction, ...privateKeys) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I'd like to see (maybe as tests):

What happens

  • if the wrong private keys get submitted to this method
  • if too little or too much keys get submitted to this method

See also my comment on having a friend sign with you


input.fulfillment = fulfillmentUri
transaction.inputs.forEach((input) => {
input.fulfillment = null // OJOOO
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does OJOOO mean?

const thresholdFulfillment = new cc.ThresholdSha256()
// m represents the number of signatures needed for this input
let m = 0
input.fulfillment.subconditions.forEach((subcdt) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

subcdts is not an appreviation we commonly use in the code base.
I suggest to rename to a word we also use in other implementations.

}
thresholdFulfillment.addSubfulfillmentUri(ed25519subFulfillment)
})
thresholdFulfillment.setThreshold(m)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of determining m ourselves, it may make sense to let the user of this method decide by themselves.
They may not be aware that this method is adjusting their fulfillment's threshold.

One suggestion would be: add threshold to parameters of sign method?
Maybe there's better ideas.

@@ -42,6 +42,24 @@ test('Valid CREATE transaction', t => {
})


test('Valid CREATE transaction with Threshold input', t => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test may not be that useful. The CREATE tx fulfillment isn't reliant on any output.

I'd instead test the following:

  1. CREATE tx with std ed25519 input and threshold output

and

  1. CREATE tx with std ed25519 input and threshold output
  2. TRANSFER tx spending the threshold output into an ed25519 output

I'd also test:

  • m-of-n
  • multi signature transactions
  • serialization of these transactions during signing.

For last point, think about a real-life scenario. You and a friend want to spend a transaction together, so you start signing with your key. They you send the half-signed tx to your friend. They sign as well and send it off to the network.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants