@sqds/fuse-wallet
v0.1.3
Published
Types and helpers for interacting with the Fuse wallet through the Wallet Standard interface.
Downloads
3
Keywords
Readme
@sqds/fuse-wallet
Types and helpers for interacting with the Fuse wallet through the Wallet Standard interface.
Installation
yarn add @sqds/fuse-wallet
Motivation
The Fuse wallet is a browser extension that implements the Wallet Standard interface. Unlike regular wallets that can only sign transactions using an imported private key, Fuse is a Smart Wallet powered by the Squads Multisig Program. With Fuse, users can create and manage multisig accounts, as well as effortlessly create multisig transactions by interacting with dapps as they used to using regular wallets.
Multisig transactions are different from regular transactions in that they require multiple parties to approve them before they can be executed. This means that creating and executing a transaction is a multi-step process that is separated in space and time. To ensure that their apps are 100% compatible with Fuse and other Smart Wallets, app developers sometimes need to take special considerations.
To help with this, Fuse exposes a set of custom features through the Wallet Standard interface. These features can be detected and used by the app developers even without this package. This package just provides a set of types and helpers to make it easier to work with these features.
Usage
import {hasGetEphemeralSignersFeature, FuseGetEphemeralSignersFeatureIdentifier} from "@sqds/fuse-wallet";
// walletAdapter: Adapter = ...
if ("standard" in walletAdapter && hasGetEphemeralSignersFeature(walletAdapter.wallet)) {
// Get two ephemeral signer addresses.
const ephemeralSigners = await walletAdapter.wallet
.features[FuseGetEphemeralSignersFeatureIdentifier /* "fuse:getEphemeralSigners" */]
.getEphemeralSigners(2)
const ephemeralSigner1 = new PublicKey(ephemeralSigners[0])
const ephemeralSigner2 = new PublicKey(ephemeralSigners[1])
// Use `ephemeralSigner1` and `ephemeralSigner2` public keys in your transaction.
// You can assume that they will sign the transaction, so you don't need to add them as signers explicitly.
}
Usage without this package
If you have concerns regarding adding another dependency to your project, we got you covered. The API is exposed by the Fuse extension through the Wallet Standard interface, so you can detect it yourself with the code below. The only downside is that you will have no TypeScript completion for the features.
// walletAdapter: Adapter = ...
if ("standard" in walletAdapter && ("fuse:getEphemeralSigners" in walletAdapter.wallet.features)) {
// Get two ephemeral signer addresses.
const [ephemeralSigner] = await walletAdapter.wallet
.features["fuse:getEphemeralSigners"]
.getEphemeralSigners(1)
}
Features
fuse:getEphemeralSigners
This feature allows the app to request a set of ephemeral signers from the wallet.
Ephemeral signers are keys that are expected to sign the transaction and be discarded right after.
An example of when such ephemeral signers are needed is the SystemProgram.createAccount
instruction.
This instruction requires the new account to be a signer to verify that whoever calls this instruction actually holds authority over this account.
The Keypair.generate()
method is typically used by app developers to create ephemeral signers,
but this mechanism doesn't work with Smart Wallets that don't execute the transaction immediately.
In these cases, the ephemeral keypair will not be available to sign the "execute" transaction because it has already been "forgotten".
To solve this problem, getEphemeralSigners(numberOfSigners)
allows apps to request any number of ephemeral signers from the wallet.
The wallet returns an array of public keys that the app developer can use in their transactions.
The implementation of this feature can vary depending on the type of wallet being used. For instance, for a Multisig wallet, an ephemeral signer is a PDA owned by the Multisig Program, enabling the Program to sign the transaction on behalf of that account. Meanwhile, for a regular wallet, it can be a keypair generated by the wallet itself and stored securely in the extension's background storage over the course of the browser session.
Regardless of the implementation, the app developer doesn't have to worry about how an ephemeral signer was generated; they can assume that the public key will be a signer of the transaction.