amberflutter 0.0.7 amberflutter: ^0.0.7 copied to clipboard
Flutter wrapper for Amber (Nostr Signer). Allows Flutter android apps to interact with Amber.
amberflutter #
A Flutter wrapper for Amber (Nostr Signer).
Rationale #
Provide a bridge between your app and Amber, to enable app developers to easily use the functionality provided by Amber.
Installation #
With flutter:
flutter pub add amberflutter
Or add to your pubspec.yaml
:
dependencies:
amberflutter: ^0.0.1
Usage #
Documentation is taken from Amber Docs. Please refer to them if you have any question about how to use Amber.
Import in your code
import 'package:amberflutter/amberflutter.dart';
Get Public Key
Get the current user public key (npub). This request also allows to send permissions so the user can approve them forever. See the Amber Docs for the list of available permissions.
final amber = Amberflutter();
amber.getPublicKey(
permissions: [
Permission(
type: "sign_event",
),
],
).then((value) {
print("npub: ${value['signature']}");
});
Sign Event
final amber = Amberflutter();
final eventJson = jsonEncode({
'kind': 1,
'content': 'Hello from Amber Flutter!',
'created_at': DateTime.now().millisecondsSinceEpoch / 1000,
});
amber.signEvent(
npub: "<your_npub_here>",
event: eventJson,
).then((value) {
print("signed event: ${value['event']}");
});
Nip 04 Encrypt
final amber = Amberflutter();
amber.nip04Encrypt(
plaintext: "Hello from Amber Flutter, Nip 04!",
npub: "<your_npub_here>",
pubkey: "<hex_pubkey_to_encrypt>",
).then((value) {
print("ciphertext: ${value['signature']}")
});
Nip 44 Encrypt
amber.nip44Encrypt(
plaintext: "Hello from Amber Flutter, Nip 44!",
npub: "<your_npub_here>",
pubkey: "<hex_pubkey_to_encrypt>",
).then((value) {
print("ciphertext: ${value['signature']}")
});
Nip 04 Decrypt
final amber = Amberflutter();
amber.nip04Decrypt(
ciphertext: "<message_encrypted_with_nip04_here>",
npub: "<your_npub_here>",
pubkey: "<hex_pubkey_to_decrypt>",
).then((value) {
print("plaintext: ${value['signature']}")
});
Nip 44 Decrypt
final amber = Amberflutter();
amber.nip44Decrypt(
ciphertext: "<message_encrypted_with_nip44_here>",
npub: "<your_npub_here>",
pubkey: "<hex_pubkey_to_decrypt>",
).then((value) {
print("plaintext: ${value['signature']}")
});