Skip to content

sebdeveloper6952/amberflutter

Repository files navigation

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({
  'id': '',
  'pubkey': Nip19.decodePubkey(_npub),
  'kind': 1,
  'content': 'Hello from Amber Flutter!',
  'created_at':
      (DateTime.now().millisecondsSinceEpoch / 1000).round(),
  'tags': [],
  'sig': '',
});

amber.signEvent(
  currentUser: "<your_npub_here>",
  eventJson: eventJson,
).then((value) {
  print("signed event: ${value['event']}");
});

Nip 04 Encrypt

final amber = Amberflutter();

amber.nip04Encrypt(
  plaintext: "Hello from Amber Flutter, Nip 04!",
  currentUser: "<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!",
  currentUser: "<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>",
  currentUser: "<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>",
  currentUser: "<your_npub_here>",
  pubKey: "<hex_pubkey_to_decrypt>",
).then((value) {
  print("plaintext: ${value['signature']}")
});

About

Flutter wrapper for Amber (Nostr Signer)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •