Bitcoin
Asigna Bitcoin Connect SDK
The Asigna SDK allows you to connect user multisig wallets directly to your Bitcoin application, seamlessly embedding it within the Asigna interface. This SDK provides the full logic required to connect a user's multisig wallet, build, sign, and execute a Partially Signed Bitcoin Transaction (PSBT), as well as sign messages and verify signatures. Within the Asigna SDK, the BitcoinJS Lib package is used for PSBTs.
Installation
To install the Bitcoin Connect SDK, run:
Workflow
1. Connect Asigna Extension with the Asigna Web Interface
To begin, download the Asigna extension and connect it to the Asigna web interface at https://btc.asigna.io. If you don’t already have a multisig wallet, create one to connect it to your Bitcoin application on your desired network.
2. Connect Bitcoin Application to the Asigna Multisig
To connect your application (similar to other Bitcoin wallets), use the useAsignaExtension
hook:
connect()
- opens the connection modal:
disconnect()
- disconnects the extension from your application:
3. Retrieve Multisig Information
useAsignaAddress
- returns the connected multisig address:
useAsignaSafeInfo
- returns connected multisig data:
Example:
4. UI Modals for Signing PSBT or Messages
To display UI modals for signing a PSBT or message and wait for signatures, use the <AsignaSignActionModals />
component:
5. Sign Messages
Multisig wallets don't have a single private key to sign messages. Therefore, multiple owners must sign, and their signatures are merged for verification.
openSignMessage(message: string)
- opens the modal to sign a message:
signMessage(message: string)
- requests a message signature without waiting for the modal:
validateMessage
- validates the message signature using the full multisig construction information:
6. Create Transactions
To create a multisig PSBT, it's crucial to correctly add inputs and calculate fees:
useAsignaFee
- calculates gas:
useAsignaInputs
- maps UTXOs to PSBT inputs based on the multisig type:
Example:
7. Sign PSBT
A PSBT requires multiple owner signatures, which may take time. There are two signing options:
signPsbt(psbt: bitcoin.Psbt)
- creates a transaction for signature gathering in the multisig queue (does not return the signed PSBT):
openSignPsbt(psbt: bitcoin.Psbt, execute?: boolean)
- opens a waiting modal until enough signatures are gathered and the signed PSBT is returned to the app. Execute flag can send the transaction to mempool once there's enough signatures gathered and returns thetxId
back to the application.
This method is recommended when the application needs to retrieve the signed PSBT, otherwise better to use the signPsbt
approach.
8. Demo application
A simple app which has all the integration features can be found here:
It is also deployed at https://asigna-btc-connect-demo.vercel.app/
Last updated