-
Notifications
You must be signed in to change notification settings - Fork 88
Fix/remove unused case 218 for bls encrypt #682
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
Changes from 2 commits
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 |
|---|---|---|
|
|
@@ -104,6 +104,7 @@ export const unloadModules = () => { | |
|
|
||
| /** | ||
| * Encrypt data with a BLS public key. | ||
| * We are using G1 for encryption and G2 for signatures | ||
| * | ||
| * @param publicKey hex-encoded string of the BLS public key to encrypt with | ||
| * @param data Uint8Array of the data to encrypt | ||
|
|
@@ -114,12 +115,34 @@ export const encrypt = ( | |
| publicKey: string, | ||
| data: Uint8Array, | ||
| identity: Uint8Array | ||
| ): string => { | ||
| return blsSdk.encrypt( | ||
| publicKey, | ||
| uint8arrayToString(data, 'base64'), | ||
| uint8arrayToString(identity, 'base64') | ||
| ); | ||
| ): Promise<string> => { | ||
|
|
||
| const publicKey = Buffer.from(publicKeyHex, 'hex'); | ||
|
|
||
| /** | ||
| * Our system uses BLS12-381 on the G1 curve for encryption. | ||
| * However, on the SDK side (this function), we expect the public key | ||
| * to use the G2 curve for signature purposes, hence the switch on public key length. | ||
| * | ||
| * The G2 curve, `Bls12381G2`, is typically associated with signature generation/verification, | ||
| * while G1 is associated with encryption. Here, the length of the public key determines how | ||
| * we handle the encryption and the format of the returned encrypted message. | ||
| */ | ||
|
|
||
| if (publicKeyHex.replace('0x', '').length !== 96) { | ||
| throw new InvalidParamType( | ||
| { | ||
| info: { | ||
| publicKeyHex, | ||
| }, | ||
| }, | ||
| `Invalid public key length. Expecting 96 characters, got ${publicKeyHex.replace('0x', '').length} instead.` | ||
| ); | ||
| } | ||
| return Buffer.from( | ||
| await blsEncrypt('Bls12381G2', publicKey, message, identity) | ||
|
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. The Spotted by Graphite Reviewer |
||
| ).toString('base64'); | ||
|
|
||
| }; | ||
|
|
||
| /** | ||
|
|
||
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.
The parameter
messagein theblsEncryptfunction call should be replaced withdatato correctly use the function parameter defined in the method signature. This ensures consistency with the input parameters and prevents potential errors. Consider updating the line to:This change aligns the function call with the method's declared parameters.
Spotted by Graphite Reviewer
Is this helpful? React 👍 or 👎 to let us know.