Giter Club home page Giter Club logo

filsnap's Introduction

⨎ FilSnap Monorepo

Filecoin Metamask Snap and related packages to enable developers to add Filecoin integration to their dapps.

This Snap enables storage of native Filecoin private keys in Metamask's local vault, to support native Filecoin addresses (e.g. f1 addresses or t1 testnet addresses).

For FEVM (Filecoin EVM) address support using Ethereum-style 0x addresses, you can also use regular Metamask directly without installing this Snap.

  • If you're using FEVM, the Snap can also show your 0x address info and its equivalent Filecoin f410 address. (More info about 0x / f410 addresses can be found in the Filecoin Docs - Ethereum Address Manager.)

Resources

Packages

Examples

Checkout examples

You can use Codesandbox and start hacking right away.

To clone it locally:

npx tiged filecoin-project/filsnap/examples/demo filsnap-demo
cd filsnap-demo
pnpm install
pnpm dev

You can try any of the examples by replacing demo with the name of the example you want to try.

Contributing

Read contributing guidelines here.

Open in GitHub Codespaces

License

Dual-licensed: MIT, Apache Software License v2, by way of the Permissive License Stack.

Security Audits

Filsnap v1.0.1 - The FilSnap v0.5.0 was audited by ConsenSys Diligence in August 2023 with a follow-up assessment of fixes conducted in October 2023, leading to the release of filsnap-v1.0.1. The complete audit report is available here in the audits/ directory as well as on the ConsenSys Diligence website.

filsnap's People

Contributors

agostbiro avatar avivash avatar beroburny avatar dependabot[bot] avatar eriknson avatar eshon avatar github-actions[bot] avatar hugomrdias avatar irubido avatar kumavis avatar makmuftic avatar meandavejustice avatar mpetrun5 avatar mpetrunic avatar omahs avatar rekmarks avatar renovate[bot] avatar schwartz10 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

filsnap's Issues

No explanation of how Filsnap operates

We should add a description of what is actually happening here. Its intuitive enough for seasoned users, but if we want to be more affective at onboarding and keeping users on task, a short description and links would be helpful.

filsnap-send-before-connect

We could also detect when TESTNET is selected and link to how to fund your testnet wallet with a faucet

Filsnap demo page does not connect to Metamask

page.js:1 MetaMask - RPC Error: Expected caveat to have a value property of a non-empty object of snap IDs.: At path: value.npm:@chainsafe/filsnap.version -- Expected a valid SemVer range. {code: -32602, message: 'Expected caveat to have a value property of a non-…filsnap.version -- Expected a valid SemVer range.'}
(anonymous) @ inpage.js:1
(anonymous) @ inpage.js:17
_runReturnHandlers @ inpage.js:17
_processRequest @ inpage.js:17
await in _processRequest (async)
_handle @ inpage.js:17
handle @ inpage.js:17
_rpcRequest @ inpage.js:1
(anonymous) @ inpage.js:1
request @ inpage.js:1
(anonymous) @ main.d5849c3e.chunk.js:1
(anonymous) @ main.d5849c3e.chunk.js:1
(anonymous) @ main.d5849c3e.chunk.js:1
i @ main.d5849c3e.chunk.js:1
Promise.then (async)
o @ main.d5849c3e.chunk.js:1
i @ main.d5849c3e.chunk.js:1
Promise.then (async)
o @ main.d5849c3e.chunk.js:1
(anonymous) @ main.d5849c3e.chunk.js:1
s @ main.d5849c3e.chunk.js:1
t.enableFilecoinSnap @ main.d5849c3e.chunk.js:1
(anonymous) @ metamask.ts:29
d @ regeneratorRuntime.js:44
(anonymous) @ regeneratorRuntime.js:125
(anonymous) @ regeneratorRuntime.js:69
r @ asyncToGenerator.js:3
l @ asyncToGenerator.js:22
(anonymous) @ asyncToGenerator.js:27
(anonymous) @ asyncToGenerator.js:19
P @ metamask.ts:25
(anonymous) @ MetaMaskConnector.tsx:36
d @ regeneratorRuntime.js:44
(anonymous) @ regeneratorRuntime.js:125
(anonymous) @ regeneratorRuntime.js:69
r @ asyncToGenerator.js:3
l @ asyncToGenerator.js:22
(anonymous) @ asyncToGenerator.js:27
(anonymous) @ asyncToGenerator.js:19
Ae @ react-dom.production.min.js:54
Ue @ react-dom.production.min.js:54
(anonymous) @ react-dom.production.min.js:55
zr @ react-dom.production.min.js:105
Dr @ react-dom.production.min.js:106
(anonymous) @ react-dom.production.min.js:117
cs @ react-dom.production.min.js:274
_e @ react-dom.production.min.js:52
Vr @ react-dom.production.min.js:109
Gt @ react-dom.production.min.js:74
Ht @ react-dom.production.min.js:73
metamask.ts:34 {code: -32602, message: 'Expected caveat to have a value property of a non-…filsnap.version -- Expected a valid SemVer range.', stack: '{\n  "code": -32602,\n  "message": "Expected caveat …paedjfecbmggjgodbgkmjkjk/background-3.js:4:252579'}
(

image

FVM Transaction Support

As mentioned in #1 support for the following FVM transactions is needed, as confirmed by @honghaoq from the FVM Product team:

Top priority:

  • Send from f1 to 0x/f410
  • Send from 0x/f410 to f1

The above would help resolve current issues from users trying to send to/from FEVM wallets and Coinbase, which currently requires complex workarounds using a Glif Burner Wallet or FilForwarder contract.

Question:

  • Will the seed phrase for a native f1 and 0x/f410 wallet be the same?
    • (i.e., do they have different derivation paths/SLIP-0044 using the same seed?)

Related features to support:

  • Create a new 0x/f410 account
  • Export keys from 0x/f410 account
  • Import keys from existing 0x/f410 account
  • Use Filecoin Eth JSON RPC
  • Gas for Eth JSON RPC Tx's
  • Ledger support for 0x/f410 and f1??

Send FIL from from 0x in MetaMask to f1

We want to support sending FIL from a 0x/f410 address to f1 as explained in #8.

It’s already possible to transfer FIL from an 0x address created in MetaMask to an f1 address using the FILForwarder contract with Glif as explained in this article.

As discussed with @hugomrdias, we should implement the same thing in the demo that Glif does and call the FilForwarder contract running on FEVM from the demo using the native MetaMask API (i.e. bypassing the snap) in order to prevent duplicating MetaMask functionality in the snap.

This would create a prompt like this in MetaMask:

image

Adapter

Add support for transferring FIL from an 0x address created in MetaMask to an

  • f1 address
  • 0x/f410 address

Demo

  • Update UI

Related: #11

[feature]: Move to entirely static front-end, hosted on GH or Fleek

Is your feature request related to a problem? Please describe.

The URL home of the app has already changed once. It's currently hosted on Fission's domain, but they're shutting down.

Describe the solution you'd like

The URL home of the app could be Github pages.

Benefits:

  • Build trust that the site has not been fucked with (inasmuch as you trust Github)
  • Has a pointer to the source code built-in to the URL itself
  • Doesn't require whoever is developing it to also be responsible for hosting it

Describe alternatives you've considered

We've tried hosting it on the URL of several companies who were paid to develop it, which has resulted in an unstable URL.

Additional context

Follow-up issue will be filed for moving to an app-specific domain for DNSlink+IPFS which we can propose to be managed by the Filecoin Foundation.

Add address protection

Main metamask connects dapps to a specific address, the snap doesn't all address may be exposed by just changing the derivation path.

This may require a bunch of work to restrict addresses per origin given that account derivation is done programmatically (from the dapp) and not through the UI.

Steps may be to:

  • specific derivation API endpoints to create and get accounts
  • these endpoints need to save some state to restrict dapps

Update code to stop detecting flask

Hello snap devs! For launch it is very important that you update your dapps to stop detecting MetaMask Flask. Instead, you should detect for the existence of the Snaps API so your dapp is ready to work with the stable release. This will work with Flask and with the stable extension.

We have updated our documentation with a guide on connecting to a snap from your dapp: https://docs.metamask.io/snaps/how-to/work-with-existing-snaps/

However, you may encounter issues when a user is running multiple wallets in the same browser (such as Phantom and Coinbase Wallet). I have published example code for working around these issues here: https://github.com/Montoya/snap-connect-test

Please reach out if you have questions or issues with your dapps.

[bug]: Should detect switching accounts in MM, and reinitialize app

Describe the bug

If I connect to the app with an account, and then in MM switch accounts, the app should reinitialize itself instead of leaving previous-connected account up.

To Reproduce
Steps to reproduce the behavior:

  1. Connect to an account
  2. Open MM
  3. Switch to a different account

Expected behavior

The app reinitializes, shows the 'connect' button.

Actual behavior

The app does not change, still shows information of previously connected account.

Add additional contributors

We want to add a few people for basic UI, docs, and description updates.

@eshon please list the GitHub accounts other than yourself that should be added.

[bug]: Filsnap adapter fails to connect when multiple wallet providers are installed

Describe the bug
Filsnap does not connect to MetaMask when multiple wallet browser extensions are installed. This seems to be due to the snap communicating with the wrong provider on the window.ethereum object. Might be related to missing support for EIP-6963, could help to look at the mpid package for identifying the right provider.

To Reproduce

  1. Install other wallet browser extension next to MetaMask (e.g. Rainbow, OKX Wallet)
  2. Try to connect FilSnap to MetaMask
  3. Connection fails with the error that MetaMask does not support snaps
  4. Disable the other browerser extensions and connect again, it works

Expected behavior
FilSnap should connect to MetaMask even when multiple wallet providers are installed.

Tracking Issue

Tasks

  1. enhancement help wanted
  2. enhancement help wanted
  3. bug help wanted
  4. bug help wanted
  5. bug help wanted
  6. enhancement help wanted
  7. enhancement help wanted

[feature]: Reduce the amount of approval dialogs in Metamask by caching approvals

Is your feature request related to a problem? Please describe.
Since updating to filsnap-adapter version 1.0.0 and using the official Metamask instead of Flask, we're subject to a lot more approval dialogs in Metamask. Basically when we call const snap = FilsnapAdapter.connect(...) and for every subsequent snap.configure(...) call, Metamask pops up a dialog to approve the requested path:

image

With Metamask Flask, it seems like the approval was cached so that the user only need to do it once.

Describe the solution you'd like
Ideally, approvals should be cached in Metamask so that the user doesn't need to re-approve.

Describe alternatives you've considered
After connecting the adapter, we need to configure the snap to derive the address for each account in the user's wallet. We consider caching those derivations in local storage instead of deriving them with the adapter, but it's still not ideal for the user having to approve the same information for each FilsnapAdapter.connect(...), or when switching accounts to sign transactions.

[feature]: Move to app-specific domain

Is your feature request related to a problem? Please describe.

The front-end is currently hosted via HTTP and IPNS/DNSlink at a Fission.com domain.

Once #189 is fixed, it should move to a new domain that's specific to the app, not a specific company.

Describe the solution you'd like

  • decide on a domain name
  • register it, managed by Filecoin Foundation
  • point domain to URL from #189

Describe alternatives you've considered

We tried domains of the companies who were leading development at the time, but that changes.

[bug]: Errors in deploy-docs workflow

Describe the bug


Run pnpm run docs

> root@ docs /home/runner/work/filsnap/filsnap
> typedoc --out docs --plugin typedoc-plugin-missing-exports --plugin typedoc-plugin-zod

[info] Loaded plugin typedoc-plugin-missing-exports
[info] Loaded plugin typedoc-plugin-zod
[error] Project at ./packages/snap has entryPointStrategy set to packages, but nested packages are not supported.
[error] Project at ./packages/adapter has entryPointStrategy set to packages, but nested packages are not supported.
[error] Project at ./packages/adapter-react has entryPointStrategy set to packages, but nested packages are not supported.
[error] Failed to convert one or more packages, result will not be merged together.
[info] Merging converted projects
 ELIFECYCLE  Command failed with exit code 3.
Error: Process completed with exit code 1.

To Reproduce
Steps to reproduce the behavior:

Make a release

Expected behavior
A clear and concise description of what you expected to happen.

Additional context
Add any other context about the problem here.

Add more context to the signing UI

Display the user account used for signing and the origin domain of the RPC call during the signing dialog, ensuring users have full context before confirming any transactions.

[bug]: Clicking "cancel" in Metamask when connecting results in broken app state

Describe the bug

After canceling sign-in in MM, app should handle and reset to initial state.

To Reproduce
Steps to reproduce the behavior:

  1. Open fil snap page
  2. Click on 'connect'
  3. Wait for MM connection panel to load
  4. See that you're on testnet
  5. Click 'cancel'

Expected behavior

The app returns to initial state, with 'connect' button visible and ready to go.

Actual behavior

The app shows some funkily-laid-out error text where the 'connect' button should be.

Screenshot:

CleanShot 2024-04-11 at 10 08 32@2x

TRACKING: Filsnap Updates

Tasks

Developer tooling and experience improvements

Code Improvements

  • Zod schemas with validations and types for RPC messages and metamask state
  • RPC client for lotus using zod schemas
  • onRpcRequest should check if fil_configure was called already and build up a "context" for other methods with snap, config, api client, keypair etc avoiding multiple instances and async tasks to get snap state.
  • Remove dependency on @zondax/filecoin-signing-tools and Buffer
  • Swap all the validation in src/utils/params.ts for zod schemas
  • Check new snaps UI https://docs.metamask.io/snaps/reference/rpc-api/#snap_dialog and src/util/confirmation.ts
  • Add pnpm patch to snaps-cli/dist/utils/misc.js changing config file to snap.config.cjs
  • Write new RPC or use some other client like izari-filecoin
  • compress snap bundle https://github.com/terser/terser
  • flask now forces semver in the snap version option change metamask-testing-tools to account for that
  • tests need to have the snap version injected from the snap manifest
  • export private key MM popup needs rework
  • sign raw popup rework
  • send message popup rework

Metamask 10.28+ compatibility

  • Research metamask new flask/snap permissions system (caveats based) and plan changes needed in filsnap.
  • Update filsnap to the new permissions system
  • Document changes and how it works to make future changes easier. (metamask said it may change again multiples until 10.29.0/end of the year)
  • Unit and e2e tests for these changes.
  • Check snap config type and check if we need to refactor it and where all the properties are used.
  • Make sure the snap manifest gets updated and committed in the CI

Filsnap adapter

  • Merge #6
  • Make sure there are no breaking changes to the adapter API
  • Rework the demo
  • Publish demo
  • Check filsnap icons for the install snap popup
  • Publish new package to npm
  • e2e tests running against the demo app
  • Fix selection highlight in the demo app
  • deploy with npm:filsnap SNAP_ID

Support FEVM transactions

  • Research FVM/FEVM transactions, requirements, flows and tools.
  • Support send FIL to f410 addrs
  • Handle FEVM transactions (cbor encoded)
  • New unit and e2e tests for FEVM features
  • Update demo page with FEVM features
  • Collaborate with Glif to validate filsnap works as expected

Others

  • Write up about moving aways from zondax dependencies
  • Improve packages readme and add a few examples
  • Improve js docs descriptions
  • #35 (not possible)
  • #36
  • #37
  • #38

References

Notes

Send FIL from from f1 to 0x/f410

We want to support sending FIL/tFIL from f1 addresses to 0x/f410 addresses in the snap for better FEVM support as requested in #8.

The demo already has a transfer form, but the recipient field only accepts f1 addresses:

image

We could change this to accept 0x/f410 addresses as well in the recipient field, similar to how Glif burner wallets work:

image

As far as I can tell, this would need the changes listed below.

Demo

  • Convert 0x addresses to f410 addresses in the demo app for the transaction's to field before calling the snap RPC.1
  • Update the UI.

Snap

  • Support signing a message where the to field is an f410 address.2

Footnotes

  1. We could use the delegatedFromEthAddress function for this from the @glif/filecoin-address package or we could add this functionality to the iso-filecoin package that is already used by the demo.

  2. This currently fails with the Invalid protocol indicator: 4 message in the snap. The error comes from the iso-filecoin package that doesn't support converting delegated addresses to bytes yet. Adding support for delegated addresses in the iso-filecoin package would probably allow signing a message in the snap where the to field is an f410 address. This seems like a small change based on the @zondax/filecoin-signing-tools package's implementation.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.