code-payments / code-sdk

Permissionless micropayments for the web
https://sdk.getcode.com
MIT License
20 stars 7 forks source link

Feature: Request Login with Payment #14

Closed zfedoran closed 10 months ago

zfedoran commented 10 months ago

This pull request aims to implement the core SDK functionality needed for requesting a public key for a user that has completed a payment. The public key is tied to the verifier / domain (unique to each domain) and signed to prove ownership.

Not yet supported on the mobile app but we're getting close.

RPC layer

The proto messages for this feature can be found here:

https://github.com/code-payments/code-sdk/blob/main/packages/rpc/src/generated/messaging/v1/messaging_service_pb.ts#L661-L689

Message Signatures

A known issue is that protobuf signatures are typically not recommended. The wire format (binary) produced by individual protobuf implementations are not byte stable or deterministic according to the specification. We are considering adding another serialization library but that seems like excessive overhead as we're already committed to using GRPC.

Other projects have encountered similar issues. Borsh may be an interesting option.

For the time being, it seems that the golang protobuf implementation is the only outlier and is knowingly producing different serializations from both the iOS and Typescript counterparts. We will use a custom marshal implementation that uses NumberFieldOrder instead.

Custom Marshaller

In the short term we will continue using protobuf with canonical encoding rules.

The golang changes required to make the wire messages consistent can be found here: https://github.com/code-payments/code-server/pull/27