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

Adding the method signWithKeypair #769

Merged
merged 1 commit into from
Apr 3, 2018
Merged

Conversation

amougel
Copy link
Contributor

@amougel amougel commented Jun 2, 2017

New method :
signWithKeypair(txJSON: string, keypair: {privateKey: string, publicKey: string}, options: Object): {signedTransaction: string, id: string}

Allow transaction signing for accounts that have not been created through a secret.

@wilsonianb
Copy link
Collaborator

It'd be great if we could just overload sign to take either a secret or keypair, in order to avoid code duplication between sign and signWithKeypair.

@sublimator
Copy link
Contributor

sublimator commented Jun 2, 2017 via email

@amougel amougel force-pushed the develop branch 7 times, most recently from f22e0c9 to b257c9b Compare June 5, 2017 09:45
Copy link
Collaborator

@wilsonianb wilsonianb left a comment

Choose a reason for hiding this comment

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

Thanks for making those changes. This is looking better.
It looks like the call to validate.sign got removed.
This commit re-adds it in a way that should work (and includes some cleanup)
wilsonianb@57fa70b

"description": "The uppercase hexadecimal representation of a secp256k1 or Ed25519 private key."
},
"publicKey": {
"type": "string",
Copy link
Collaborator

Choose a reason for hiding this comment

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

"string" --> "publicKey"

"type": "object",
"properties": {
"privateKey": {
"type": "string",
Copy link
Collaborator

Choose a reason for hiding this comment

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

"string" --> "publicKey"

"type": "object",
"properties": {
"privateKey": {
"type": "string",
Copy link
Collaborator

Choose a reason for hiding this comment

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

"string" --> "publicKey"

"description": "The uppercase hexadecimal representation of the secp256k1 or Ed25519 private key of the account that is initiating the transaction."
},
"publicKey": {
"type": "string",
Copy link
Collaborator

Choose a reason for hiding this comment

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

"string" --> "publicKey"

"description": "The secret of the account that is initiating the transaction.(This field is exclusive with keypair)."
},
"keypair": {
"type": "object",
Copy link
Collaborator

Choose a reason for hiding this comment

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

You don't need this definition and src/common/schemas/objects/keypair.json
You can either ditch that file or just put "type": "keypair" here (and add keypair.json to src/common/schema-validator.js)

}
},
"description": "The private and public key of the account that is initiating the transaction.(This field is exclusive with keypair).",
"required": ["privateKey", "publicKey"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

add

"additionalProperties": false

"properties": {
"privateKey": {
"type": "string",
"description": "The uppercase hexadecimal representation of the secp256k1 or Ed25519 private key of the account that is initiating the transaction."
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this would be fine without of the account that is initiating the transaction
Same with publicKey below

"description": "The uppercase hexadecimal representation of the secp256k1 or Ed25519 public key of the account that is initiating the transaction."
}
},
"description": "The private and public key of the account that is initiating the transaction.(This field is exclusive with keypair).",
Copy link
Collaborator

Choose a reason for hiding this comment

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

exclusive with keypair --> exclusive with secret

Copy link
Collaborator

@wilsonianb wilsonianb left a comment

Choose a reason for hiding this comment

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

An integration test is failing on circleci since it is calling sign using named parameters
https://github.com/ripple/ripple-lib/blob/develop/test/integration/http-integration-test.js#L163-L168
https://circleci.com/gh/ripple/ripple-lib/1708#tests/containers/0
I was able to get it to work with this:
fc5d2b1

@@ -0,0 +1,17 @@
{
Copy link
Collaborator

Choose a reason for hiding this comment

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

This file can be removed

@@ -45,4 +50,4 @@ function sign(txJSON: string, secret: string, options: Object = {}
}
}

module.exports = sign
module.exports = sign
Copy link
Collaborator

Choose a reason for hiding this comment

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

Missing newline at end of file

@@ -1,4 +1,4 @@
{
"signedTransaction": "12000322800000002400000017201B0086955368400000000000000C732102F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D874473045022100BDE09A1F6670403F341C21A77CF35BA47E45CDE974096E1AA5FC39811D8269E702203D60291B9A27F1DCABA9CF5DED307B4F23223E0B6F156991DB601DFB9C41CE1C770A726970706C652E636F6D81145E7B112523F68D2F5E879DB4EAC51C6698A69304",
"id": "02ACE87F1996E3A23690A5BB7F1774BF71CCBA68F79805831B42ABAD5913D6F4"
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Missing newline at end of file

Copy link
Collaborator

@wilsonianb wilsonianb left a comment

Choose a reason for hiding this comment

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

👍 LGTM
Can you fold the changes into a single commit?

@intelliot
Copy link
Collaborator

intelliot commented Sep 28, 2017

@amougel This looks good to me; if you can merge or rebase on develop, that should enable CI to pass.

Edit: Actually I'm not sure if CI will work when the branch is on a fork; regardless, you'll need to resolve the conflict before I can merge this PR. Thanks!

@matejr
Copy link

matejr commented Oct 10, 2017

What is the format of private and public key and how can one specify the type of signature scheme (ECDSA secp256k1/Ed25519)?

@amougel
Copy link
Contributor Author

amougel commented Oct 10, 2017

@matejr The doc details it all. From memory the format is Hexadecimal.

@sublimator
Copy link
Contributor

sublimator commented Oct 10, 2017 via email

@matejr
Copy link

matejr commented Oct 10, 2017

@amougel documentation doesn't specify byte order, whether public key is compressed or not, size (in bytes) of private key and how to potentially deal with zeros in most significant bytes (can you e.g. omit leading zero bytes when you convert private key, represented as number, to hexadecimal string?), etc. It is still not clear to me how code distinguishes between secp256k1 and Ed25519 private keys.

function sign(txJSON: string, secret?: any, options?: Object, keypair?: Object
): {signedTransaction: string; id: string} {
if(typeof(secret) === 'string') {
// we can't validate that the secret matches the account because
Copy link

Choose a reason for hiding this comment

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

I'd say "we don't..." rather than "can't".

Wondering aloud, is there any reason to validate that the publicKey and privateKey match each other?

Copy link
Collaborator

Choose a reason for hiding this comment

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

👍 I think it would only be useful in a world where the ledger would only accept a signature from the secret that matches the account. However, there can be other keys that could sign for the account, I don't think there's a reason to validate here.

@intelliot
Copy link
Collaborator

@matejr Thanks for the questions!

  1. Keys are byte arrays which should have no byte order.
  2. At 33 bytes, I believe the public key is compressed.
  3. The private key is 33 bytes.
  4. We would not omit leading zero bytes, but it should be feasible.
  5. If the public key begins with 0xED then it's an Ed25519 Key.

@sublimator
Copy link
Contributor

sublimator commented Nov 7, 2017 via email

@darkmemo
Copy link
Collaborator

darkmemo commented Feb 7, 2018

@amougel: Are you considering to rebase and resolve conflicts to get this PR merged?

@amougel
Copy link
Contributor Author

amougel commented Feb 7, 2018

@darkmemo Yes, maybe not in the near future but eventually yes.

@amougel amougel force-pushed the develop branch 5 times, most recently from 929cd9c to 8ed476c Compare March 23, 2018 13:12
@amougel
Copy link
Contributor Author

amougel commented Mar 23, 2018

@wilsonianb

Copy link
Collaborator

@intelliot intelliot left a comment

Choose a reason for hiding this comment

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

LGTM

@FredKSchott
Copy link
Contributor

Woah, the https://github.com/ripple/ripple-lib/pull/769/files#diff-12042bcf08631e33198bb47382ee4813 file got crazy-reformatted. Can you revert? (For the sake of PR diff readability, and anyone who already has open work on that test file that would have to deal with merge conflicts)

@amougel
Copy link
Contributor Author

amougel commented Apr 3, 2018

@FredKSchott amended the hicup

@intelliot intelliot merged commit 2570e2a into XRPLF:develop Apr 3, 2018
@intelliot
Copy link
Collaborator

Thanks, @amougel !

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.

8 participants