What are custom signature hooks?
Custom signature hooks allow companies to trigger approval business logic based on parameters including transaction value, transaction volume, types of signature, and more. The business logic can be anything that helps the company and/or end user make good decisions during the signing request process. A couple examples are auto-approvals (eg, auto-approving transactions below a certain value or volume) and two-factor authentication (eg, requiring approval for transactions above a certain limit). Another option are security checks, either internal or external, to prevent malicious activity.Why use custom signature hooks?
There are a few common reasons developers use custom signature hooks. For example:- Approving transactions - Most developers will prompt a user for approval before signing a message from a dApp or Wallet Connect
- Adding additional authentication - Developers can add extra authentication steps such as MFA to riskier transactions
- Checking transaction sizes - Developers can perform checks on transaction sizes to trigger specific authentication steps
An active flow is visible to the user and can be used to offer a superior user experience. For example, companies can trigger MFA for transactions above a certain size, an example we will dive into at the end of this guide.
How do custom signature hooks work?
The Portal approval flow is driven by a series of event hooks that take place throughout the lifecycle of a Provider requests. These hooks are as follows:portal_signingRequested
- Emitted by the Provider when a new signing request is received by the Providerportal_signingApproved
- Emitted by you when signing a given request is approvedportal_signingRejected
- Emitted by you when signing a given request is rejected
Designing your flow
The expectation of this flow is that your code binds to theportal_signingRequested
event using the following pattern:
portal_signingRejected
or portal_signingApproved
event.
NOTE: When emitting these events, the Provider uses the method
and params
to determine if we are indeed approving or rejecting the correct request, so it is vital that you pass the request data to your emit()
calls.
A more real-world example: MFA for large transactions
A common use case is to trigger additional approval from users for large transactions. The implementation of this using custom signature hooks might look something like this:portal.provider.on("portal_signingRequested")
function.