nostr_bunker 1.4.0
nostr_bunker: ^1.4.0 copied to clipboard
With this package your app can act as a bunker and will be able to sign events from others Nostr apps.
With this package your app can act as a bunker and will be able to sign events from others Nostr apps.
Usage #
This package is stateless so you need to store the apps and the signers (private keys) yourself.
final bunker = Bunker(
ndk: yourNdk,
privateKeys: ["private_key"],
);
bunker.start();
bunker.stop();
bunker.restart();
// add and remove accounts
bunker.addPrivateKey("private_key");
bunker.removePrivateKey("public_key")
// connect an app with bunker://
final bunkerUrl = bunker.getBunkerUrl(signerPubkey: "public_key_to_connect");
// connect an app with nostrconnect://
final nostrConnect = NostrConnectUrl.fromUrl("nostrconnect://");
nostrConnect.name = "new_name"; // rename the app
nostrConnect.permissions.first.isAllowed = false; // remove a permission
bunker.connectApp(
signerPubkey: "public_key_to_connect",
nostrConnect: nostrConnect,
);
// listen to pending requests
bunker.pendingRequestsStream.listen((request) {
// process them conditionaly
if (request.useNip44) bunker.processRequest(request);
});
// store this
bunker.apps;
bunker.privateKeys;
bunker.dispose();
Additional information #
This package use NDK internally, so you have to provide the Ndk instance yourself.
final bunker = Bunker(ndk: Ndk.defaultConfig());
In a Flutter app, use the platform aware verifier from ndk_flutter, it is much faster than Bip340EventVerifier on web.
final ndk = Ndk(
NdkConfig(
cache: MemCacheManager(),
eventVerifier: NdkEventVerifier(),
),
);
final bunker = Bunker(ndk: ndk);