aviary_dart
Aviary is a ledger you embed in your own app or service. A chain runs in process, finalizes every block with BFT consensus, and lets anyone who holds only its 32 byte state root verify what it contains. Money is one use; the same engine keeps tamper evident application data. This package is the Dart API, driven over dart:ffi. Cryptography comes from the CipherBird engine.
What you get
- Application records. A signed key value store with owners, versions and values up to 64 KiB, each provable on its own. Use it for audit logs, asset and device registries, document notarization or shared app state.
- Transfers with instant finality. Accounts with balances and nonces, or UTXOs with multisig, finalized by Tendermint style rounds with BLS commit certificates. A finalized block never reverts.
- Proofs and light clients. Prove a balance or a record against a state root. A light client follows a chain from its genesis validators, across validator rotations, without running a full node.
- Networking you control. A consensus node with no sockets and no clock, so it runs over whatever transport the app picks, with Noise and SecureSession encrypted links, signed peer records and credential gated admission.
- Composable chains. Choose the consensus engine (BFT, PoS, VRF PoS, PoW), the state model and the proposer policy at genesis, plug in an engine written in Dart, anchor subchains to a parent and drive whole chain trees.
- Key custody. A passphrase sealed key store that signs inside the engine, portable encrypted accounts, threshold accounts and hybrid post quantum signatures (Ed25519 plus ML-DSA-65).
- Privacy. Sealed mempools that hide transactions until a block includes them, and BBS membership credentials that admit a member without revealing who it is.
- Interop. The same keys derive Ethereum, Bitcoin and Solana addresses, and the engine builds and signs real transactions for each.
- Operations. Typed event streams, metrics, and snapshots that resume a chain at once or replay it for an audit.
The same engine backs the Go, Node.js, JVM and Swift bindings, and every binding computes byte identical state.
Flutter apps should depend on aviary (shares the engine with the
cipherbird package) or aviary_lite (self contained) instead; both
re-export this API.
Install
dependencies:
aviary_dart: ^1.1.0
The engine ships inside the package under native/darwin-arm64,
native/linux-x64 and native/linux-arm64, and the package's build hook
(hook/build.dart) bundles it as a code asset. dart build cli therefore
produces a bundle that carries libaviary_c in bundle/lib and runs on any
machine with no package config and no setup; dart run and dart test load
the same asset. On macOS the hook skips the asset when the application
depends on the aviary or aviary_lite plugin, because those link the
engine into the app themselves and a second copy would be dead weight.
dart compile exe does not run build hooks, so use dart build cli for
executables. The hook also bundles native/windows-x64/aviary_c.dll when
that file exists; no Windows binary ships yet because the CipherBird engine
has no Windows build. Anywhere else, point AVIARY_DYLIB at a built
libaviary_c library. Aviary.loadedFrom reports which path won.
Use
import 'package:aviary_dart/aviary.dart';
void main() {
final bc = Aviary.instance;
final node = bc.createNode(7);
final alice = node.fundAccount(1000);
final bob = node.fundAccount(0);
node.sendTo(alice, bob, 250);
node.commit();
print(node.balance(bob.address));
print(node.verifyAccountProof(node.proveAccount(bob.address)));
print(node.stateRoot().hex);
node.dispose();
}
Every call above has an explicit counterpart (newAccount plus credit,
submitTransfer with a nonce, produceBlock with a timestamp) for code
that needs full control. sendTo takes its nonce from nextNonce, which
counts transfers still waiting in the mempool, so several transfers from one
account can be queued before a block.
Shortcuts
Extensions that collapse the common flows into one call:
| On | Members |
|---|---|
Uint8List |
hex, shortHex, equalsBytes |
String |
hexBytes (with or without 0x), utf8Bytes |
Account |
addressHex, isHybrid |
Node |
fundAccount, fundHybridAccount, send, sendTo (nonce from nextNonce, scheme follows the account), sendFromStore, submitTx, submitTransferFromStore, commit, events, eventStream, metricValues, verifyAccountProof, snapshot, blockAt, saveTo |
Aviary |
newValidator, assembleSingleValidator, assembleRecordChain, signRecordTx, addressOf, recordFromProof, signWithShares, restoreNode, restoreNodeFrom, newNetNode, generateSecureIdentity, initiateSecureSession, acceptSecureSession, withNode, withKeyStore, withTree, sealShareAsync, unsealShareAsync, sealAccountPassphraseAsync, openAccountPassphraseAsync |
KeyPairBytes |
entry(power), treeValidator(power) |
Chain |
produceBlock(timestamp, justify:), events, eventStream, metrics, metricValues, addTx, write, record, proveRecord, recordNonce, pendingCount |
NetNode |
events, eventStream, metrics, metricValues |
TreeNode |
withChild, find, chainIds |
KeyStore |
signTransfer, publicKey, has, addresses, lock |
ChainTree |
produceRound |
final validator = bc.newValidator();
final chain = bc.assembleSingleValidator(chainId: 9, validator: validator);
chain.produceBlock(1);
final root = TreeNode(chainId: 1, validators: [validator.treeValidator(1)])
.withChild(TreeNode(chainId: 2, validators: [validator.treeValidator(1)]));
final tree = bc.buildChainTree(root);
tree.produceRound(1);
final shares = bc.createThresholdAccount(3, 2);
final signature = bc.signWithShares([shares[0], shares[2]], 'pay'.utf8Bytes);
Surfaces
Node: a single validator chain; accounts, transfers, blocks, proofs.- Mixtures:
makeBlueprint,buildGenesis,assembleChain,Chain. - Foreign components:
registerEngine,registerProposer. - Subchains: registrations, policies, anchors,
verifySubchainProof. - Unreleased, needs an engine built from source: children registered after
genesis (
encodeDynamicSubchainPolicy,signOp,proposeSubchain), child proofs (childProof,verifyChildProof) and chain snapshots (Chain.snapshot,restoreChain). - Validator rotation:
Chain.scheduleValidators,Chain.validators. - Light clients:
newLightClient,acceptSkipping,syncTo. - Networking:
newNetNode,NetNode,PeerMesh,SecureSession,generateSecureIdentity,signPeerRecord,AddressBook,NoiseSession,generateNoiseIdentity, and the admission handshake onCredentialGateandCredentialPolicy. - Records:
assembleRecordChain,ChainRecords(write,record,proveRecord,addTx),RecordOp,recordFromProof. - Chain trees:
TreeNode,buildChainTree,ChainTree. - Custody:
KeyStore, portable accounts, threshold accounts,Ceremony. - Assurance and sealed mempools; anonymous membership credentials.
Records
A chain does not have to carry money. assembleRecordChain builds a chain
whose state is a signed key value store: each record has a 32 byte key the
application chooses, an owner, a version and an opaque value of up to 64 KiB.
chain.write(secret, key, op, value) signs and queues a write (the nonce
comes from the chain, so several writes can be queued before a block);
produceBlock finalizes them. Only the owner may put, transfer or
delete. record(key) reads the committed record, proveRecord(key) proves
it to someone who holds only the state root, and recordFromProof reads it
back out of a verified proof.
final chain = bc.assembleRecordChain(chainId: 31, validator: bc.newValidator());
final key = bc.hash(utf8.encode('asset:PUMP-0042'));
chain.write(owner.secret, key, RecordOp.put, utf8.encode('{"status":"in service"}'));
chain.produceBlock(1);
final proof = chain.proveRecord(key);
assert(bc.verifyStateProof(chain.stateRoot(), proof));
print(bc.recordFromProof(proof).version); // 1
writeFromStore(store, author, key, op, value) signs inside the engine from
a KeyStore, and signRecordTxHybrid signs with a hybrid post quantum
account. addTx queues any signed, encoded transaction on any assembled
chain, for the account and UTXO models as well, and each queued and included
transaction arrives as a TxAdmitted and TxRemoved event.
Events
Chain events are typed. node.events() drains the buffer as a
List<ChainEvent>; node.eventStream is a broadcast Stream<ChainEvent>
fed by a native hook, so nothing is polled. Chain and NetNode carry the
same events(), eventStream, metrics() and metricValues(): a chain
reports a BlockFinalized or BlockRejected per submit, a networked node a
BlockFinalized per committed height plus gossip, timeout and ban counters.
The sealed ChainEvent has five subtypes, so a switch is exhaustive:
node.eventStream.listen((event) {
switch (event) {
case BlockFinalized(:final height, :final txCount):
print('block $height with $txCount txs');
case TxAdmitted(:final txid):
print('pending ${txid.shortHex}');
case TxRemoved():
case BlockRejected():
case UnknownEvent():
break;
}
});
Listeners run on the microtask after the node call that caused the event, so they may call the node again. Disposing the node closes the stream.
Custody signing
A KeyStore seals signing secrets at rest. Signing from it keeps the secret
inside the engine: store.signTransfer(...) returns an encoded transaction,
node.sendFromStore(store, from, to, amount) signs and admits in one call,
and node.submitTx(bytes) admits anything already signed. The scheme follows
the stored key, Ed25519 or hybrid post quantum, and the secret is wiped after
use. Lock the store with lock() when the app goes to the background and
unlock(passphrase) when it returns. reveal still exists for migrations,
but nothing in the signing path needs it.
final store = bc.createKeyStore(passphrase);
final alice = store.addAccount(account.publicKey, account.secret);
node.sendFromStore(store, alice, bob.address, 250);
net.setTransactions([
store.signTransfer(chainId: 9, from: alice, to: bob.address, amount: 4, nonce: 0),
]);
Networking
Consensus runs over a network the app owns. A NetNode is a validator (or
an observer) running BFT over a gossip mesh with no socket and no clock:
every input returns an Outbound with the relays to send and the timeouts
to arm, and the app feeds what arrives back in. Dart sockets, Flutter's
connectivity rules and the app's own retry policy stay in Dart.
final node = bc.newNetNode(genesis: genesis, me: 0, blsKey: myKey, peers: [1, 2]);
void apply(Outbound out) {
for (final relay in out.relays) {
sockets[relay.to].add(frame(sessions[relay.to].encrypt(relay.message)));
}
for (final t in out.timeouts) {
Timer(Duration(milliseconds: 500 * (t.round + 1)), () => apply(node.onTimeout(t)));
}
}
apply(node.start());
// on a frame from peer p: apply(node.onGossip(p, sessions[p].decrypt(frame)));
// once node.committed: apply(node.advance());
For tests, simulations and a single process network, PeerMesh is that
loop: it delivers relays in order and fires a timeout only when no relay is
pending, earliest round first, so the same inputs always reach the same
commit. settle runs until the validators commit and then drains the mesh
so observers catch up.
final mesh = PeerMesh([
for (var i = 0; i < 4; i++)
bc.newNetNode(genesis: genesis, me: i, blsKey: keys[i]),
])..linkAll();
mesh.start();
mesh.settle();
mesh.advance();
mesh.settle();
print(mesh.nodes.first.height); // 2
mesh.free();
Each link is protected by a SecureSession: a mutually authenticated, post
quantum hybrid channel. The dialer calls initiateSecureSession with the
peer's KEM public key, the listener acceptSecureSession with its own
generateSecureIdentity(), the two handshake messages cross, then encrypt
and decrypt wrap every frame. Always compare peerIdentity with the key
you expected. Blocks carry the encoded transactions passed to
setTransactions when this node is the proposer. The list is cleared when
the height commits, so hand over the next height's transactions after the
commit and before advance. replayLog catches up a peer that connects
after consensus started.
On a record model network (buildGenesis(stateModel: 2)) every node answers
record(key), recordNonce(address) and proveRecord(key), observers
included; examples/registry/bin/network.dart runs a registry that way on
four validators and an auditor.
Persistence
A node's whole chain travels as one blob: node.snapshot() holds the chain
id, the genesis credits and every finalized block with its certificate.
bc.restoreNode(bytes) rebuilds the node from the ledger state the snapshot
carries and resumes from the tip at once, however long the chain is;
restoreNode(bytes, replay: true) replays every block through consensus
instead, verifying each certificate, which audits the archive at the cost of
startup time. Both yield the same node, byte for byte. saveTo(path) writes the blob atomically and
restoreNodeFrom(path) reads it back, returning null when no file exists.
Pending mempool transactions are not part of a snapshot. blockAt(height)
returns any archived block.
final path = '${appDocuments.path}/chain.bin';
final node = await bc.restoreNodeFrom(path) ?? bc.createNode(7);
node.fundAccount(1000);
node.commit();
await node.saveTo(path);
Lifecycle and errors
Handles (Node, Chain, KeyStore, LightClient, Ceremony,
SealedMempool, CredentialGate, ChainTree) own native memory. Release
them with dispose or free, or let the garbage collector do it: every
handle has a finalizer, releasing twice is harmless, and isReleased tells
you where you stand. The withNode, withKeyStore and withTree helpers
release at the end of a scope. Errors are AviaryException with a
status from the C ABI (AviaryStatus.genesisSealed, badInput,
failure). The Argon2 bound custody calls have Async variants that run
on a worker isolate.
Testing
dart test
The suites run one at a time (dart_test.yaml), because each drives the
same native engine from its own isolate. The GitHub workflow Dart packages
runs format, analysis, the suites and the pub.dev score on macOS and Linux
for aviary_dart, and analysis plus tests for the two Flutter packages.
Releases are published from tags (aviary_dart-v1.0.0, aviary_lite-v1.0.0,
aviary-v1.0.0) by the Publish to pub.dev workflow through pub.dev's
GitHub Actions trust; see that workflow's header for the pub.dev settings.
pub.dev enables that trust only for a package that already exists, so each
package's first release (1.0.0) was published by hand; the workflow skips a
version that is already on pub.dev.
Determinism
Every canonical byte string (hashes, transaction ids, headers, proofs) is identical across the Go, npm, JVM, Swift and Dart bindings.
Libraries
- aviary
- Aviary for Dart: the whole Aviary ledger C ABI over dart:ffi, plus shortcuts. In a browser the same import gives the stateless part of the API over the WebAssembly engine: hashing, header hashes, and proof and certificate checks.
- aviary_dart
- Alias of
aviary.dartso both import paths work.