-
Notifications
You must be signed in to change notification settings - Fork 140
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 new crypto features #852
Changes from all commits
2ae2f7b
d141b6b
85f5ff3
5a74178
3d5d799
69edf41
cc2547f
901542d
7864c8f
a68b529
647288a
3c7601b
d166880
b35f673
3546cd9
56db090
38517a6
d77a9ab
702a98c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -167,6 +167,16 @@ struct AccountKey { | |
struct PublicKey { | ||
let publicKey: [UInt8] | ||
let signatureAlgorithm: SignatureAlgorithm | ||
let isValid: Bool | ||
|
||
/// Verifies a signature. Checks whether the signature was produced by signing | ||
/// the given tag and data, using this public key and the given hash algorithm | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not quite what the verification checks, I suggest updating the text to be more precise:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another point, I'm not sure if this is right place to mention that all verifications with an invalid public key will fail. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it should be fine to add it here, or we can also add it as a note outside of the code block. |
||
pub fun verify( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As @turbolent mentioned about breaking changes, I think the change from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, both were added, so this isn't a breaking change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah my bad, I somehow though |
||
signature: [UInt8], | ||
signedData: [UInt8], | ||
domainSeparationTag: String, | ||
hashAlgorithm: HashAlgorithm | ||
): Bool | ||
} | ||
``` | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,10 @@ pub enum HashAlgorithm: UInt8 { | |
|
||
/// SHA3_384 is Secure Hashing Algorithm 3 (SHA-3) with a 384-bit digest. | ||
pub case SHA3_384 = 4 | ||
|
||
/// KMAC128_BLS_BLS12_381 is an instance of KMAC128 mac algorithm, that can be used | ||
/// as the hashing algorithm for BLS signature scheme on the curve BLS12-381. | ||
pub case KMAC128_BLS_BLS12_381 = 5 | ||
} | ||
``` | ||
|
||
|
@@ -31,8 +35,11 @@ pub enum SignatureAlgorithm: UInt8 { | |
/// ECDSA_P256 is Elliptic Curve Digital Signature Algorithm (ECDSA) on the NIST P-256 curve. | ||
pub case ECDSA_P256 = 1 | ||
|
||
/// ECDSA_Secp256k1 is Elliptic Curve Digital Signature Algorithm (ECDSA) on the secp256k1 curve. | ||
pub case ECDSA_Secp256k1 = 2 | ||
/// ECDSA_secp256k1 is Elliptic Curve Digital Signature Algorithm (ECDSA) on the secp256k1 curve. | ||
pub case ECDSA_secp256k1 = 2 | ||
|
||
/// BLS_BLS12_381 is BLS signature scheme on the BLS12-381 curve. | ||
pub case BLS_BLS12_381 = 3 | ||
} | ||
``` | ||
|
||
|
@@ -99,13 +106,12 @@ The API of the Crypto contract is: | |
```cadence | ||
pub contract Crypto { | ||
|
||
pub struct SignatureAlgorithm { | ||
pub let name: String | ||
} | ||
|
||
// Hash the data using the given hashing algorithm and returns the hashed data. | ||
pub fun hash(_ data: [UInt8], algorithm: HashAlgorithm): [UInt8] | ||
|
||
// Hash the data using the given hashing algorithm and the tag. Returns the hashed data. | ||
pub fun hashWithTag(_ data: [UInt8], tag: string, algorithm: HashAlgorithm): [UInt8] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have suggested |
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I leave this comment here, it's about the function at this line: Shouldn't we also update |
||
pub struct KeyListEntry { | ||
pub let keyIndex: Int | ||
pub let publicKey: PublicKey | ||
|
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.
Can
PublicKey
fields (data, signature algo, isValid..) be updated after the creation of the object?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.
No, they are defined as constant fields (i.e. read-only).