-
Notifications
You must be signed in to change notification settings - Fork 463
Sign, recover, verify, and validate functions #653
Conversation
Added/adjusted tests Adjusted JsSignatureProvider to use new sign method
Add PublicKey.fromPrivateKey() test
Moving constructElliptic to a central location
|
||
/** Represents/stores a Signature and provides easy conversion for use with `elliptic` lib */ | ||
export class Signature { | ||
|
||
constructor(private signature: Key) {} | ||
constructor(private signature: Key, private ec: EC) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this wasn't a required parameter before, is it possible to add a default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be set during the creation of the Signature and it depends on whether the Signature is a k1, r1, or wa type, which is derived from fromString or fromElliptic operations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Constructing the elliptic object is an expensive operation so if a default is set (secp256k1 is the most likely default) then it would cause two elliptic operations if the type is not k1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it 👍 Since this is already a major version change, its a good time to break the API, but I'm just generally hesitant to without a good reason. Sounds like a good enough reason to though.
|
||
/** Represents/stores a public key and provides easy conversion for use with `elliptic` lib */ | ||
export class PublicKey { | ||
constructor(private key: Key) {} | ||
constructor(private key: Key, private ec: EC) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as below
|
||
/** Represents/stores a private key and provides easy conversion for use with `elliptic` lib */ | ||
export class PrivateKey { | ||
constructor(private key: Key) {} | ||
constructor(private key: Key, private ec: EC) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as below
Change Description
Adding functions that were available in eosjs-ecc to PrivateKey/PublicKey/Signature classes to handle the format conversions and call elliptic functions.
API Changes
PrivateKey.getPublicKey()
: Retrieve the public key from a private keyPrivateKey.sign()
: Sign a message digest with private keyPublicKey.validate()
: Validate a public keySignature.verify()
: Verify a signature with a message digest and public keySignature.recoverPublicKey()
: Recover a public key from a message digest and signatureconstructElliptic()
ineosjs-key-conversions.js
: Used for PrivateKey, PublicKey, SignatureDocumentation Additions