Skip to content
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

Update Keystore types #524

Merged
merged 2 commits into from
Jan 23, 2024
Merged

Update Keystore types #524

merged 2 commits into from
Jan 23, 2024

Conversation

rygine
Copy link
Collaborator

@rygine rygine commented Jan 23, 2024

in this PR:

  • created new types for keystore interfaces based on their RPC
  • deprecated existing Keystore interface

these new types allow for a single source of truth for keystore functionality and their associated types. updating a keystore's RPC definitions will automatically update its types.

i decided to export all the derivative types as well so that integrators have them. they are invaluable for creating type-safe custom keystores and their handlers.

@rygine rygine requested a review from a team January 23, 2024 00:48
if (codecs.req) {
const reqBytes = codecs.req.encode(req).finish()
if (rpc.req) {
const encoder = rpc.req.encode as SnapKeystoreApiRequestEncoders[T]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tsc needs an assist here to narrow the type

@@ -42,20 +53,21 @@ export async function snapRPC<Req, Res>(
throw new Error('Unexpected array response')
}

return codecs.res.decode(b64Decode(responseString))
const decoder = rpc.res.decode as SnapKeystoreApiResponseDecoders[T]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above: tsc needs an assist here to narrow the type

Copy link

cloudflare-workers-and-pages bot commented Jan 23, 2024

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3ea9501
Status: ✅  Deploy successful!
Preview URL: https://6c50eeb1.xmtp-js.pages.dev
Branch Preview URL: https://rygine-rpc-types.xmtp-js.pages.dev

View logs

Copy link
Contributor

@neekolas neekolas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is some very impressive Typescript wrangling.

@rygine rygine merged commit 0c638e7 into main Jan 23, 2024
7 checks passed
@rygine rygine deleted the rygine/rpc-types branch January 23, 2024 16:03
Copy link
Contributor

🎉 This PR is included in version 11.3.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants