The Coconut_lib is a development tool for mobile air gap Bitcoin wallets. It is written in Dart.
Coconut Vault and Coconut Wallet were created using this library.
Download from Appstore and Play Store.
- Coconut Vault (for iOS)
- Coconut Wallet (for iOS)
- Coconut Vault (for Android)
- Coconut Wallet (for Android)
And visit tutorial page for Self-custody we provided. (www.coconut.onl)
⚠ The Coconut_lib is still a project under development. Therefore, we are not responsible for any problems that may arise while using it. Please review it carefully and use it.
The Coconut_lib provides the base code for developing Bitcoin vaults and wallets based on Bitcoin airgap.
Since coconut_lib is developed in Dart, it is specialized for developing applications for iPhone and Android by utilizing the Flutter.
In particular, The Coconut_lib designed to develop air-gap-based vault and wallet apps separately by clearly distinguishing the vault area and wallet area.
You can use the Coconut_lib to create your own air-gap based vault and wallet.
"Don't trust, verify and develop!"
Coconut_lib is fully open source. The entire source code is publicly available for anyone to inspect, verify, use, modify, and redistribute under the MIT License. There are no closed-source or proprietary parts of this library.
- wallet: Provides a cryptography-based key management method. Create two apps instancing the Wallet and Vault classes.

- transaction: Provides code related to Bitcoin scripts and transactions. Also use PSBT(BIP-0174) to communicate vaults and wallets.

For more development information, visit the coconut_lib docs.
This example uses Regtest and a public test mnemonic. Never use this mnemonic or the sample transaction ID with real funds.
import 'dart:convert';
import 'package:coconut_lib/coconut_lib.dart';
void main() {
// 1. Choose a Bitcoin network.
NetworkType.setNetworkType(NetworkType.regtest);
// 2. Create a vault. It owns the seed and signs transactions.
final vault = SingleSignatureVault.fromMnemonic(
utf8.encode(
'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about',
),
addressType: AddressType.p2wpkh,
);
// 3. Create a watch-only wallet from the vault's public descriptor.
final wallet = SingleSignatureWallet.fromDescriptor(vault.descriptor);
print('Receive address: ${wallet.getAddress(0)}');
// 4. Describe a spendable UTXO belonging to receive address index 0.
// Replace these sample values with data from your Bitcoin node or indexer.
final utxo = Utxo(
// Transaction ID
'0000000000000000000000000000000000000000000000000000000000000000',
0, // Output index
100000, // Value in satoshis
"${wallet.derivationPath}/0/0", // Address derivation path
);
// This demo sends to another address in the same wallet.
// Replace it with the actual recipient address in your application.
final recipientAddress = wallet.getAddress(1);
final transaction = Transaction.forSinglePayment(
[utxo],
recipientAddress,
"${wallet.derivationPath}/1/0",
50000, // Amount in satoshis
2, // Fee rate in sat/vB
wallet,
);
// 5. Build a PSBT in the wallet, sign it in the vault, and finalize it.
final unsignedPsbt = Psbt.fromTransaction(transaction, wallet);
final signedPsbt = vault.addSignatureToPsbt(unsignedPsbt.serialize());
final signedTransaction =
Psbt.parse(signedPsbt).getSignedTransaction(wallet.addressType);
print('Signed transaction: ${signedTransaction.serialize()}');
}Support is scoped to the wallet, address, transaction, PSBT, and descriptor features implemented by this library. Legacy P2PKH, legacy P2SH multisig, and bare multisig wallets are not supported. Nested SegWit (P2WPKH-in-P2SH) is also not supported.
- BIP-32: Hierarchical Deterministic Wallets
- BIP-39: Mnemonic code for generating deterministic keys
- BIP-48: Multi-Script Hierarchy for Multi-Signature Wallets
- BIP-84: Derivation Scheme for Native SegWit P2WPKH Accounts
- BIP-86: Key Derivation for Single-Key P2TR Outputs
- BIP-67: Deterministic Multisig Key Sorting
- BIP-141: Segregated Witness
- BIP-143: Transaction Signature Verification for Version 0 Witness Programs
- BIP-173: Bech32 Addresses for Native SegWit Version 0 Outputs
- BIP-350: Bech32m Addresses for SegWit Version 1+ Outputs
- BIP-327: MuSig2 for BIP340-Compatible Multi-Signatures
- BIP-340: Schnorr Signatures for secp256k1
- BIP-341: Taproot Spending Rules
- BIP-342: Tapscript
- BIP-129: Bitcoin Secure Multisig Setup (BSMS)
- BIP-174: Partially Signed Bitcoin Transaction Format
- BIP-370: PSBT Version 2
- BIP-371: Taproot Fields for PSBT
- BIP-373: MuSig2 PSBT Fields
- BIP-380: Output Script Descriptors General Operation
- BIP-382: SegWit Output Script Descriptors
- BIP-383: Multisig Output Script Descriptors
- BIP-386: Taproot Output Script Descriptors
- BIP-389: Multipath Descriptor Key Expressions
Install the package dependencies before running the test suite.
dart pub getRun all unit and scenario tests:
dart testRun only one test group:
# Unit tests
dart test test/unit_test
# Scenario tests
dart test test/scenario_testReference CONTRIBUTING
- Github Issue, PR
- hello@noncelab.com
- coconut.onl
Coconut_lib is fully open source and distributed under the MIT License.