PostgresSecureStorage class
PostgreSQL-based secure storage that ONLY supports xpub storage.
This implementation is designed for server-side xpub-only wallets. It encrypts xpubs using AES-256-GCM before storing them in PostgreSQL.
Security Constraint: All private key methods throw UnimplementedError. This prevents accidental private key storage on server-side deployments.
Example:
final storage = PostgresSecureStorage(
pool: postgresPool,
encryptionService: EncryptionService.fromBase64(
masterKeyBase64: Platform.environment['LIBSPIFFY_MASTER_KEY']!,
),
);
// This works
await storage.setXPub('wallet123', 'xpub6...');
final xpub = await storage.getXPub('wallet123');
// This throws UnimplementedError
await storage.setPrivateKey('wallet123', '...'); // THROWS!
- Implemented types
Constructors
-
PostgresSecureStorage({required Pool pool, required EncryptionService encryptionService, Iterable<
EncryptionService> previousKeys = const []}) - Creates a new PostgreSQL secure storage.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
containsKey(
String key) → Future< bool> -
Check if a key exists in secure storage.
override
-
delete(
String key) → Future< void> -
Delete a key-value pair from secure storage.
override
-
deleteAccountMetadata(
String accountId) → Future< void> -
Delete all metadata for a specific account.
override
-
deleteAll(
) → Future< void> -
Delete all data from secure storage.
override
-
deleteXPub(
String walletId) → Future< void> - Deletes the xpub for a wallet.
-
getAccountMetadata(
String accountId) → Future< Map< String, String> > -
Get metadata for a specific account.
override
-
getAll(
) → Future< Map< String, String> > -
Returns every xpub and hdpubkey secret, decrypted.
override
-
getIdentityIds(
) → Future< List< String> > -
Get all identity IDs that have stored keys.
override
-
getIdentityKey(
String identityId) → Future< String?> -
Get the private key for a specific identity.
override
-
getMnemonic(
String walletId) → Future< String?> -
Get the mnemonic phrase for a specific wallet.
override
-
getPrivateKey(
String walletId) → Future< String?> -
Get the private key for a specific wallet.
override
-
getString(
String key) → Future< String?> -
Get a string value by key.
override
-
getWIF(
String walletId) → Future< String?> -
Get the WIF private key for a specific wallet.
override
-
getXPriv(
String walletId) → Future< String?> -
Get the XPRIV extended private key for a specific wallet.
override
-
getXPub(
String walletId) → Future< String?> -
Get the extended public key (xpub) for a watch-only wallet.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
reencryptToCurrentKey(
) → Future< int> - Re-encrypts every xpub and hdpubkey row that is not under the current key version with the current key, and returns how many rows changed.
-
setAccountMetadata(
String accountId, Map< String, String> metadata) → Future<void> -
Store metadata for a specific account.
override
-
setIdentityKey(
String identityId, String privateKey) → Future< void> -
Store the private key for a specific identity.
override
-
setMnemonic(
String walletId, String mnemonic) → Future< void> -
Store the mnemonic phrase for a specific wallet.
override
-
setPrivateKey(
String walletId, String privateKey) → Future< void> -
Store the private key for a specific wallet.
override
-
setString(
String key, String value) → Future< void> -
Store a string value with the given key.
override
-
setWIF(
String walletId, String wif) → Future< void> -
Store the WIF private key for a specific wallet.
override
-
setXPriv(
String walletId, String xpriv) → Future< void> -
Store the XPRIV extended private key for a specific wallet.
override
-
setXPub(
String walletId, String xpub) → Future< void> -
Store the extended public key (xpub) for a watch-only wallet.
override
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited