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
| export class Signature { | ||
|
|
||
| constructor(private signature: Key) {} | ||
| constructor(private signature: Key, private ec: EC) {} |
There was a problem hiding this comment.
Since this wasn't a required parameter before, is it possible to add a default?
There was a problem hiding this comment.
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.
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.
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) {} |
| /** 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) {} |
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