Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Sign, recover, verify, and validate functions #653

Merged
merged 4 commits into from
Jan 23, 2020
Merged

Conversation

bradlhart
Copy link
Contributor

@bradlhart bradlhart commented Jan 22, 2020

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

  • API Changes

PrivateKey.getPublicKey(): Retrieve the public key from a private key
PrivateKey.sign(): Sign a message digest with private key

PublicKey.validate(): Validate a public key

Signature.verify(): Verify a signature with a message digest and public key
Signature.recoverPublicKey(): Recover a public key from a message digest and signature

constructElliptic() in eosjs-key-conversions.js: Used for PrivateKey, PublicKey, Signature

Documentation Additions

  • Documentation Additions

Bradley Hart added 4 commits January 22, 2020 14:15
Added/adjusted tests

Adjusted JsSignatureProvider to use new sign method
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) {}
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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) {}
Copy link
Contributor

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) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as below

@bradlhart bradlhart merged commit 443b8c8 into develop Jan 23, 2020
@bradlhart bradlhart deleted the ecc-pkg-functions branch January 23, 2020 20:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants