-
Notifications
You must be signed in to change notification settings - Fork 640
feat: Add Multichain API support #3759
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
base: main
Are you sure you want to change the base?
Conversation
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
917fc58 to
491f06d
Compare
packages/snaps-simulation/src/middleware/internal-methods/chain-id.ts
Outdated
Show resolved
Hide resolved
packages/snaps-simulation/src/middleware/multichain/create-session.ts
Outdated
Show resolved
Hide resolved
packages/snaps-simulation/src/middleware/multichain/invoke-method.ts
Outdated
Show resolved
Hide resolved
packages/examples/packages/multichain-provider/src/modules/base.ts
Outdated
Show resolved
Hide resolved
ef6f3be to
559f0ff
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3759 +/- ##
========================================
Coverage 98.33% 98.34%
========================================
Files 422 430 +8
Lines 12082 12252 +170
Branches 1876 1904 +28
========================================
+ Hits 11881 12049 +168
- Misses 201 203 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
packages/examples/packages/multichain-provider/src/modules/base.ts
Outdated
Show resolved
Hide resolved
| const MOCK_SIGNATURE = | ||
| '0x01b37713300d99fecf0274bcb0dfb586a23d56c4bf2ed700c5ecf4ada7a2a14825e7b1212b1cc49c9440c375337561f2b7a6e639ba25be6a6f5a16f60e6931d31c'; | ||
|
|
||
| it('returns a signature for Ethereum', async () => { |
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.
Maybe add a test to make sure it throws "method not supported" for Solana.
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 trouble with testing the Solana behavior during signMessage and signTypedData is that snaps-jest doesn't populate the accounts for Solana in the multichain session. So we don't even get to the point where it would throw the proper error 🤔
| abstract signMessage( | ||
| account: CaipAccountId, | ||
| message: string, | ||
| ): Promise<string>; | ||
|
|
||
| abstract signTypedData( | ||
| account: CaipAccountId, | ||
| message: string, | ||
| ): Promise<string>; | ||
|
|
||
| abstract getGenesisHash(): Promise<string>; |
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 you add JSDoc to these too?
| return result.signature; | ||
| } | ||
|
|
||
| async signTypedData( |
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 you add JSDoc here too? Something like "This method is not supported by Solana" is fine.
Adds support for using the multichain API in Snaps. This is accomplished by setting up a separate provider and substream called
metamask-multichain-provider. Whensnap.requestis called with a multichain request, this provider and substream is used. The clients will need to route to the proper JSON-RPC pipeline based on the substream and verify that the Snap has the proper permission.Additionally this PR adds a example Snap for usage of this API, that can leverage Ethereum and Solana APIs at once. It also adds limited simulation support for the multichain API. The simulation framework implements a basic version of the multichain API where sessions are tracked and requests are routed to supported EVM providers. There are no underlying providers for non-EVM request, but they can be mocked.