libsignal library

Dart FFI bindings for libsignal - Signal Protocol implementation.

This package provides end-to-end encryption using the Signal Protocol, including key management, session establishment, sealed sender, and group messaging capabilities.

Getting Started

import 'package:libsignal/libsignal.dart';

void main() async {
  // Initialize the library
  await LibSignal.init();

  // Generate identity key pair
  final identity = IdentityKeyPair.generate();
  print('Public key: ${identity.publicKey}');
}

Features

See the README for more details.

Classes

Aes256GcmSiv
CiphertextMessage
An encrypted Signal Protocol message.
CreateSenderKeyDistributionResult
Result of creating a sender key distribution message.
DecryptionErrorMessage
EncryptResult
Result of encrypting a message.
Fingerprint
GroupCipher
Encrypts and decrypts messages for a group using Signal Protocol.
GroupDecryptResult
Result of decrypting a group message.
GroupEncryptResult
Result of encrypting a group message.
IdentityKeyPair
IdentityKeyStore
Abstract interface for storing identity keys.
InMemoryIdentityKeyStore
In-memory implementation of IdentityKeyStore.
InMemoryKyberPreKeyStore
In-memory implementation of KyberPreKeyStore.
InMemoryPreKeyStore
In-memory implementation of PreKeyStore.
InMemorySenderKeyStore
In-memory implementation of SenderKeyStore.
InMemorySessionStore
In-memory implementation of SessionStore.
InMemorySignedPreKeyStore
In-memory implementation of SignedPreKeyStore.
KyberKeyPair
KyberPreKeyRecord
KyberPreKeyStore
Abstract interface for storing Kyber (post-quantum) pre-keys.
KyberPublicKey
KyberSecretKey
LibSignal
Main API class for libsignal.
PreKeyBundle
PreKeyMessageIds
Pre-key IDs extracted from a pre-key message.
PreKeyRecord
PreKeyStore
Abstract interface for storing pre-keys.
PrivateKey
ProtocolAddress
PublicKey
SealedSenderCipher
Encrypts and decrypts messages using Sealed Sender protocol.
SealedSenderDecryptionResult
Result of sealed sender decryption containing plaintext and sender info.
SealedSenderDecryptResult
Result of sealed sender decryption.
SealedSenderEncryptResult
Result of sealed sender encryption.
SecureBytes
Wrapper for sensitive byte data with automatic zeroing on finalization.
SenderKeyName
Unique identifier for a sender key, combining sender address and distribution ID.
SenderKeyStore
Abstract interface for storing sender keys for group messaging.
SessionBuilder
Builds sessions with remote users using their pre-key bundles.
SessionCipher
Encrypts and decrypts messages using an established Signal Protocol session.
SessionRecord
SessionStore
Abstract interface for storing and retrieving session records.
SignalMessage
SignedPreKeyRecord
SignedPreKeyStore
Abstract interface for storing signed pre-keys.

Enums

CiphertextMessageType
The type of ciphertext message.
Direction
Direction of communication for identity verification.
IdentityTrustDecision
The trust decision for an identity key.

Mixins

LibSignalBase
Base mixin for libsignal operations.

Extensions

SecureUint8List on Uint8List
Extension for zeroing sensitive Uint8List data.

Functions

createSenderCertificate({required String senderUuid, required int senderDeviceId, required List<int> senderIdentityKey, required BigInt expiration, required List<int> serverCertificate, required List<int> serverPrivateKey}) Uint8List
Create a sender certificate for testing.
createSenderKeyDistributionMessageWithCallbacks({required String senderName, required int senderDeviceId, required String distributionId, required FutureOr<Uint8List?> loadSenderKey(String, int, String), required FutureOr<void> storeSenderKey(String, int, String, Uint8List), required FutureOr<Uint8List> getIdentityKeyPair()}) Future<CreateSenderKeyDistributionResult>
Create a new sender key distribution message with callbacks.
createServerCertificate({required int keyId, required List<int> serverPublicKey, required List<int> trustRootPrivateKey}) Uint8List
Create a server certificate for testing.
extractPrekeyMessageIds({required List<int> message}) PreKeyMessageIds
Extract pre-key IDs from a serialized pre-key message.
fingerprintCompare({required List<int> fingerprint1, required List<int> fingerprint2}) bool
Compare two scannable fingerprint encodings.
groupDecryptWithCallbacks({required String senderName, required int senderDeviceId, required String distributionId, required List<int> ciphertext, required FutureOr<Uint8List?> loadSenderKey(String, int, String), required FutureOr<void> storeSenderKey(String, int, String, Uint8List)}) Future<GroupDecryptResult>
Decrypt a message from a group member with callbacks.
groupEncryptWithCallbacks({required String senderName, required int senderDeviceId, required String distributionId, required List<int> plaintext, required FutureOr<Uint8List?> loadSenderKey(String, int, String), required FutureOr<void> storeSenderKey(String, int, String, Uint8List), required FutureOr<Uint8List> getIdentityKeyPair()}) Future<GroupEncryptResult>
Encrypt a message to a group with callbacks.
hkdfDerive({required int outputLength, required List<int> inputKeyMaterial, required List<int> salt, required List<int> info}) Uint8List
Derive keys using HKDF (HMAC-based Key Derivation Function).
identityKeypairSerializeRaw({required PublicKey publicKey, required PrivateKey privateKey}) Uint8List
Serialize an identity key pair from separate keys.
identityKeypairSignAlternateIdentityRaw({required PublicKey publicKey, required PrivateKey privateKey, required PublicKey otherIdentity}) Uint8List
Sign an alternate identity key using separate keys.
messageDecryptPrekeyWithCallbacks({required String remoteName, required int remoteDeviceId, required List<int> ciphertext, required FutureOr<Uint8List?> loadSession(String, int), required FutureOr<void> storeSession(String, int, Uint8List), required FutureOr<Uint8List> getIdentityKeyPair(), required FutureOr<int> getLocalRegistrationId(), required FutureOr<void> saveIdentity(String, int, Uint8List), required FutureOr<Uint8List?> loadSignedPreKey(int), required FutureOr<Uint8List?> loadPreKey(int), required FutureOr<void> removePreKey(int), required FutureOr<Uint8List?> loadKyberPreKey(int), required FutureOr<void> markKyberPreKeyUsed(int)}) Future<Uint8List>
Decrypt a pre-key Signal message (first message in a new session) with DartFn callbacks.
messageDecryptSignalWithCallbacks({required String remoteName, required int remoteDeviceId, required List<int> ciphertext, required FutureOr<Uint8List?> loadSession(String, int), required FutureOr<void> storeSession(String, int, Uint8List), required FutureOr<Uint8List> getIdentityKeyPair(), required FutureOr<int> getLocalRegistrationId(), required FutureOr<void> saveIdentity(String, int, Uint8List)}) Future<Uint8List>
Decrypt a Signal message (not a pre-key message) with DartFn callbacks.
messageEncryptWithCallbacks({required String remoteName, required int remoteDeviceId, required List<int> plaintext, required FutureOr<Uint8List?> loadSession(String, int), required FutureOr<void> storeSession(String, int, Uint8List), required FutureOr<Uint8List> getIdentityKeyPair(), required FutureOr<int> getLocalRegistrationId()}) Future<EncryptResult>
Encrypt a message using an established session with DartFn callbacks.
processPrekeyBundleWithCallbacks({required String remoteName, required int remoteDeviceId, required PreKeyBundle bundle, required FutureOr<Uint8List?> loadSession(String, int), required FutureOr<void> storeSession(String, int, Uint8List), required FutureOr<Uint8List> getIdentityKeyPair(), required FutureOr<int> getLocalRegistrationId(), required FutureOr<void> saveIdentity(String, int, Uint8List)}) Future<void>
Process a pre-key bundle to establish a new session with DartFn callbacks.
processSenderKeyDistributionMessageWithCallbacks({required String senderName, required int senderDeviceId, required String distributionId, required List<int> distributionMessage, required FutureOr<Uint8List?> loadSenderKey(String, int, String), required FutureOr<void> storeSenderKey(String, int, String, Uint8List)}) Future<Uint8List>
Process a sender key distribution message with callbacks.
sealedSenderDecryptWithCallbacks({required List<int> ciphertext, required List<int> trustRoot, required BigInt timestamp, required FutureOr<Uint8List?> loadSession(String, int), required FutureOr<void> storeSession(String, int, Uint8List), required FutureOr<Uint8List> getIdentityKeyPair(), required FutureOr<int> getLocalRegistrationId(), required FutureOr<void> saveIdentity(String, int, Uint8List), required FutureOr<Uint8List?> loadSignedPreKey(int), required FutureOr<Uint8List?> loadPreKey(int), required FutureOr<Uint8List?> loadKyberPreKey(int)}) Future<SealedSenderDecryptResult>
Decrypt a Sealed Sender message.
sealedSenderEncryptWithCallbacks({required String recipientName, required int recipientDeviceId, required List<int> plaintext, required List<int> senderCertificate, required FutureOr<Uint8List?> loadSession(String, int), required FutureOr<void> storeSession(String, int, Uint8List), required FutureOr<Uint8List> getIdentityKeyPair(), required FutureOr<int> getLocalRegistrationId()}) Future<SealedSenderEncryptResult>
Encrypt a message using Sealed Sender (anonymous delivery).
senderCertificateGetExpiration({required List<int> certificate}) BigInt
Get the expiration timestamp from a sender certificate.
senderCertificateGetKey({required List<int> certificate}) Uint8List
Get the sender public key from a sender certificate.
senderCertificateGetSenderDeviceId({required List<int> certificate}) int
Get the sender device ID from a sender certificate.
senderCertificateGetSenderName({required List<int> certificate}) String
Get the sender name from a sender certificate.
validateSenderCertificate({required List<int> certificate, required List<int> trustRoot, required BigInt timestamp}) bool
Validate a sender certificate.