Skip to main content

Signer API

Overview

This page describes how to setup interaction with the signer iframe from the main app and what methods are available.

Communication (MessageChannel)

The signer communicates with the main app using the Channel Messaging API. This provides a direct, two-way communication pipe between the main app and the iframe, bypassing the overhead and noise of window.postMessage broadcasting.

Setup Flow

  1. Initialization: The main app creates a MessageChannel and sends the message { type: 'connect' } with port2 to the signer iframe via postMessage.
  2. Connection: The signer listens for the connect event, grabs the port, and sets up its listeners.
  3. Ready: The signer sends a { type: 'ready' } message back to the main app to signal it's ready to accept requests.

Proxy Pattern

The consumer (main app) uses a Proxy to interact with the signer. Instead of manually constructing postMessage payloads, the consumer code looks like this:

// Consumer side
await signer.signTransaction(txData);

Under the hood, the Proxy intercepts this call and converts it into a structured message:

{
"requestId": "unique-id",
"method": "signTransaction",
"args": [txData]
}

The signer receives this, resolves the method using the build-generated loader, executes it, and sends back the result.

Build System & Module Configs

The signer uses a custom build process (powered by scripts/build.ts) to discover and register modules. This allows for granular control over what gets included in the final bundle, especially for different build targets (e.g., online vs offline).

Entry Point Generation

During the build process, the script:

  1. Scans the src directory for all module.config.ts files.
  2. Filters them based on the current BUILD_TARGET (e.g., excluding online-only modules for offline builds).
  3. Generates a central entry point at src/services/safeService.ts.

This generated file contains a loadSafeServiceMethod function with a giant switch statement that maps method names to dynamic imports:

// Generated by scripts/build.ts
export async function loadSafeServiceMethod(moduleName: string) {
switch (moduleName) {
case "signTransaction": {
return import("./safeSigner/signTransaction");
}
// ... other modules
default: {
throw new Error(`Module ${moduleName} not found`);
}
}
}
Why this matters

This generation step ensures that only the modules relevant to the current build target are included, and that the runtime can resolve method names to file paths without needing a manual registry.

Every functional module in the signer must have a module.config.ts file.

👉 See the Module Integration Guide for step-by-step instructions.

Runtime & Dynamic Imports

To keep the signer lightweight, we do not bundle all logic into a single large file. Instead, we use dynamic imports.

On-Demand Loading

When the main app requests a method (e.g., signTransaction), the signer:

  1. Receives the request via MessagePort.
  2. Calls loadSafeServiceMethod('signTransaction').
  3. The generated switch statement triggers a import('./safeSigner/modules/signTransaction/signTransaction').
  4. The browser fetches the chunk containing that specific module.

This means the initial iframe load is very fast because it only contains the minimal main.ts and communication logic. Heavy cryptographic libraries or complex UI flows are loaded only when needed.

Caching

Once a module is loaded, its methods are cached in safeServiceCache (in src/main.ts). Subsequent calls to the same method use the cached version, avoiding repeated network requests or module resolution overhead.

Methods

Parameters and Return Types

Please refer to the specific method implementation for the details.

MethodDescription
signDeltaOrderSign a cross-chain order.
signTransactionSign a transaction.
addAccountsAdd accounts to a wallet.
addAddressToAddressBookAdd an entry to a portfolio address book.
editAddressBookEntryEdit an entry in a portfolio address book.
removeAddressFromAddressBookRemove an entry from a portfolio address book.
createWalletCreate a new portfolio wallet.
removeWalletRemove a wallet from a portfolio.
importWalletImport a wallet to a portfolio.
exportWalletExport a wallet without secrets.
renameWalletRename a wallet.
setWalletPasswordSet the wallet password.
importOfflineWalletImport an offline wallet to a portfolio.
showMnemonicGridVisually show a grid with mnemonic inputs.
hideMnemonicGridVisually hide a rendered mnemonic grid.
deriveAddressListSelectivelyDerive address items for every passed entry.
changeEncryptionTypeChange a portfolio and all its entities encryption type.
exitPortfolioExit a portfolio.
backupPortfolioBackup a portfolio.
removePortfolioRemove a portfolio.
renamePortfolioRename a portfolio.
getPortfolioPublicViewGet a portfolio without secrets.
importTokenImport a token to an account.
removeAccountsRemove accounts from a wallet.
setPortfolioPasswordSet the portfolio password.
removeWalletAssetRemove an asset from an account.
renameAccountRename an account.
syncAllBalanceUpdate accounts balances.
updateAccountListSave/remove a wallet accounts list.
showAutoSignShow the auto sign checkbox on auth forms.
showLoginFormShow the login form.
submitLoginFormSubmit the login form.
showRestoreFormShow the restore form.
submitRestoreFormSubmit the restore form.
showSignUpFormShow the sign up form.
submitSignUpFormSubmit the sign up form.
showChangePasswordFormShow the change password form.
submitChangePasswordFormSubmit the change password form.
destroyVisibleFormDestroy the currently rendered form.
showImportInputPKShow the private key input.
submitImportAccountImport an account by reading the private key input.
validationImportInputPKValidate the private key input.
setupPasswordModalSetup and render the password modal.
setupPasteMnemonicTextFormWordsChange the mnemonic inputs length of the currently rendered mnemonic grid.
showPasteMnemonicTextFormSetup and render the mnemonic grid along with mnemonic words.
validatePasteMnemonicFormValidate the mnemonic grid.
showReadOnlyMnemonicFormSetup and render the readonly mnemonic grid along with mnemonic words.
resetMnemonicStateReset the mnemonic grid state.
showDecryptedMnemonicShow the decrypted from a QR mnemonic.
showEncryptedInfoShow the placeholder for the secure data.
showDecryptedInfoDecrypt and display the secure data.
copyDecryptedInfoCopy the decrypted secure data to the clipboard.
showEncryptedMnemonicQrShow the wallet mnemonic encrypted QR code.
getMnemonicQrGet the wallet mnemonic encrypted QR code src.
setupQrDecryptFormRecoveryPhraseFieldRender the textarea with a hidden with dots recovery phrase.
showQrDecryptFormPasswordFieldRender the password input for the QR decrypt form.
submitQrDecryptFormSubmit the QR decrypt form and save the decrypted phrase in memory.
validateQrDecryptFormValidate the QR decrypt form.
copyQrDecryptFormRecoveryPhraseCopy the decrypted phrase to the clipboard.
submitQrEncryptFormSubmit the QR encrypt form.
showQrEncryptFormShow the QR encrypt form.
setLayoutModeSet the theme.