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

API for directly adding signatures to transactions #161

Merged
merged 13 commits into from
Feb 21, 2019
Merged

API for directly adding signatures to transactions #161

merged 13 commits into from
Feb 21, 2019

Conversation

morleyzhi
Copy link
Contributor

@morleyzhi morleyzhi commented Feb 13, 2019

* Add a signature to the transaction. Useful when a party wants to pre-sign
* a transaction but doesn't want to give access to their secret keys.
* @param {string} publicKey The public key of the signer
* @param {string} signature The base64 value of the signature XDR
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it doesn't work with base64 encoded signatures. Tests seem to add byte arrays instead of b64 encoded strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, should be fixed now!


try {
hint = Keypair.fromPublicKey(publicKey).signatureHint();
console.log('calculated hint: ', hint);
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove console.log.

@morleyzhi
Copy link
Contributor Author

@bartekn Now that I think about this... I'm not sure the method I employed is going to work because the pre-signer would need to guess the user's next sequence number.

The docs mention a different strategy for pre-signing a transaction:
https://www.stellar.org/developers/guides/concepts/multi-sig.html#pre-authorized-transaction

I'm guessing that's already implemented in the JS SDK, if Stellar Lab already implements it? If that's the case, can we close this PR without merging since the use case we're trying to solve already has a solution?

@bartekn
Copy link
Contributor

bartekn commented Feb 19, 2019

Preauthorized transaction signer is a different thing. It's basically a transaction that unlocks the account. For example, you can design bonds using preauthorized transactions:

  • Tx1 sends the first payment, is valid only after Jan 1st and sets the Tx2 as the signer.
  • Tx2 sends the second payment, is valid only after Feb 1st and sets the Tx3 as the signer.
  • and so on...

What we want to do in this PR is something like: You and me have a shared account, I sign a transaction and send it to you, you sign it and send a signature back, I add a signature using the method in this PR.

I agree that this is kind of redundant, because instead of sending me a signature you could send me a full transaction that I can later import and use sign method. But the new method can be useful in same cases. For example, sending a transaction to multiple signers requires the whole process to be sequential (person A signs, sends to B; person B signs, sends to C...). Adding ready signatures can be done in a simultaneous way (A sends transaction to B, C, D, E... they send back signatures and A appends them to the transaction).

@morleyzhi
Copy link
Contributor Author

@bartekn So does it seem like this PR will accomplish the use case you described? The documentation (898096d#diff-42d8d2088a96641b563b25ad908b0c0f) should describe how end-users can use this.

Copy link
Contributor

@tomquisel tomquisel left a comment

Choose a reason for hiding this comment

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

@bartekn this looks good to me. Any more thoughts before Morley merges it in?

test/unit/transaction_test.js Show resolved Hide resolved
@morleyzhi morleyzhi merged commit 0a6635b into stellar:master Feb 21, 2019
@morleyzhi morleyzhi deleted the mz-addsignature branch March 7, 2019 16:42
@blueskytoday
Copy link

Hi I see you work with adding signatures to an existing XDR.

I have a special interest to let a third party sign the transaction without passing the transaction as XDR. I heard it should be possible just to hand over the transaction-hash, let this get signed and add the signature to the XDR.

What is your view on this is this possible? If yes, an example would be awesome. Thanks.

@abuiles
Copy link
Contributor

abuiles commented Apr 16, 2020

Hi, the following should do it

txHash = tx.hash();
signature = signer.sign(presignHash).toString('base64')

Once you get back the signature, you can append it to the transaction

tx.addSignature(signer.publicKey(), signature);

Also, https://stellar.stackexchange.com/ might be a better place for this kind of questions.

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.

Docs unclear, error when creating an account Add signatures to transaction builder
5 participants