-
Notifications
You must be signed in to change notification settings - Fork 43
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
refactor: remove enc_publish functions and create separate encoding functions instead #635
Conversation
@Ivansete-status i tagged you as a reviewer since this PR would introduce a change in the c-bindings, and would like your blessings / thoughts about them. In the c-bindings example you can see how encryption is done with the proposed changes |
Jenkins Builds
|
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.
Hey ! Thanks for inviting me to the party ! I like it very much !
Is a great API simplification where the encryption and signing are protocol-agnostic, and also the error cases are well considered within the library/encoding.go
.
Not a big deal at all but maybe in the future we could also split the encryption and signing a bit more.
Thanks for that !
return "", err | ||
} | ||
|
||
pubkey, signature := extractPubKeyAndSignature(payload) |
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 wonder if we could return better feedback in case of an error
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.
Hm. I think it should be fine. the err
variable will contain enough information to determine the cause of the error, i.e.:
symmetric key is required
couldn't decrypt using symmetric key
private key is required
couldn't decrypt using asymmetric key
invalid message length
non supported KeyKind
unsupported wakumessage version
return "", err | ||
} | ||
|
||
pubkey, signature := extractPubKeyAndSignature(payload) |
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.
Likewise as per the previous comment
Nice PR! But I am wondering, this change would make it a 2 step API to the caller/user who want to send/receive encrypted messages. Wouldn't it be better to do encrypt/decrypt under the hood when the user invokes enc_publish(relay/lightpush)? |
Good question. I do have the following concerns if we follow that approach:
|
I do agree that it makes the interface less elegant, can we have them pass a struct for the encryption params and another struct for publish params? That would make this cleaner. If we don't have a good solution for your concerns, then we can go ahead with this approach of splitting. |
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 apart from the comment.
4e14073
to
dcd13f3
Compare
Description
Current c-bindings have encoding functions for both lightpush and relay that while at first view they appear to simplify the process of encoding messages using v1 encryption, in practice, they don't introduce benefits that make their existence worthy of the duplication of code and coupling lightpush and relay bindings to encoding functionality.
This PR refactors away this issue by removing the encryption functions for lightpush and relay, and instead create two functions to perform this operation, similar to how decoding is done.
Changes
waku_relay_publish_enc_asymmetric
,waku_relay_publish_enc_symmetric
,waku_lightpush_publish_enc_asymmetric
andwaku_lightpush_publish_enc_symmetric
waku_encode_symmetric
andwaku_encode_asymmetric
whose output can be used directly in the publish functions of relay and lightpush