-
Notifications
You must be signed in to change notification settings - Fork 90
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
Add X25519 key and verification method support #735
Conversation
KeyPair::try_from_private_key_bytes
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.
LGTM
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.
Looks good to me!
Some comments regarding the outstanding questions.
// TODO: refactor with exact types for each key type? E.g. Ed25519KeyPair, X25519KeyPair etc. | ||
// Maybe a KeyPair trait with associated types? Might need typed key structs | ||
// like Ed25519Public, X25519Private etc. to avoid exposing pre-1.0 dependency types. |
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.
I think that makes sense, at least in the current situation. Typically, we cannot use a KeyPair
interchangeably, e.g. a document can only be created from an Ed25519KeyPair
. On the other hand, for generation or storage we don't care about the type, so perhaps we have to retain the KeyPair
type as an abstraction? (Not thought through.)
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.
Yeah I'm hesitant to do a KeyPair
refactor at this point since it has sweeping implications everywhere. One concern I have is that with introducing specific types we multiply the number of structs we have to make bindings for.
E.g. currently we have KeyPair
with Public
and Private
keys represented as strings/UInt8Array
soon, so basically one type exposed to the bindings. With a refactor we might have 6 different structs:
Ed25519KeyPair
Ed25519Private
Ed25519Public
X25519KeyPair
X25519Private
X25519Public
And more for each new KeyType
we choose to support. Note that the specific types for keys may be important for places where we only want/need the public key, such as creating a new verification method or only allowing Ed25519
for creating a new IotaDocument
or IotaDID
. We've largely moved away from requiring KeyPairs
in function parameters where the private key is not required.
If we do go ahead with such a refactor I think a KeyPair
trait would be useful for generalization, e.g.
trait KeyPair {
type Public;
type Private;
fn public(&self) -> &Self::Public;
fn private(&self) -> &Self::Private;
fn key_type(&self) -> KeyType;
}
I don't think that will be in this PR, however.
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.
Thanks for the explanations. It's fine to leave this for a future PR. Turning KeyPair
into a trait is what I had in mind, too, that sounds good! I agree that we need to carefully consider the impact before going ahead, specifically for Wasm.
Description of change
Adds support for
X25519
cryptographic key pairs for performing Elliptic Curve Diffie-Hellman (ECDH) key exchange operations and theX25519KeyAgreementKey2019
verification method type.There are some open questions about the design of the
KeyExchange
trait which usesPhantomData
rather than generics (in line with current conventions forSign
andVerify
) and several TODOs related to removingMerkleKeyCollections
in #715.Added
MethodType::X25519KeyAgreementKey2019
.KeyType::X25519
.MethodSecret::X25519
.X25519
KeyExchange
implementation.MethodData
Wasm bindings.Changed
KeyPair::try_from_ed25519_bytes
totry_from_private_key_bytes
.MethodData::new_b58
tonew_base58
.VerificationMethod::key_type
totype_
.VerificationMethod::key_data
todata
.Removed
KeyPair::new_ed25519
.Links to any relevant issues
Fixes #671.
Type of change
How the change has been tested
Local tests and new examples work.
Change checklist