Skip to main content

dostr_nip46 0.1.0 copy "dostr_nip46: ^0.1.0" to clipboard
dostr_nip46: ^0.1.0 copied to clipboard

NIP-46 remote signing for Nostr, to connect to a bunker with a bunker:// or nostrconnect:// URL and sign and encrypt through it.

0.1.0 #

  • Initial release, moved out of the ndk package. Keys come from the LocalSignerFactory only, so it does not depend on dostr_bip340: Bunkers.createNostrConnect replaces NostrConnect(relays:, clientMetadata:), and NostrConnect has privateKey and publicKey instead of a KeyPair.
  • Nip46EventSigner is now Nip46Signer, after the NostrSigner it implements. Bunkers and Nip46Signer take their factory as signerFactory instead of eventSignerFactory, and localEventSigner of Nip46Signer is private.
  • encryptNip44 and decryptNip44 take recipientPubkey and senderPubkey, as in NostrSigner, instead of recipientPubKey and senderPubKey.
  • As in NostrSigner, encrypt and decrypt are now encryptNip04 and decryptNip04, with named parameters, the four encryption methods return a Future<String> instead of a Future<String?>, canSign is a getter, getPublicKey() is the publicKey getter, and requiresInteractiveSigning, requiresSignerNetwork and signerTransportRelayUrls are gone.
  • BunkerRequest.method is the NIP-46 method name, such as sign_event, instead of a SignerMethod, and remoteRequest is private: ping and switchRelays send the NIP-46 methods that are not in NostrSigner.
  • BREAKING A Nip46Signer knows the user's pubkey from the start, so publicKey never throws: Bunkers.createSigner completes once the bunker sent it, and Nip46Signer.connect does the same without Bunkers. Nip46Signer(publicKey: ...) takes it, for an account restored from storage, instead of cachedPublicKey. getPublicKeyAsync is gone.
  • sign throws an ArgumentError for an event of another pubkey, and a SignerRequestFailedException when the bunker returns an invalid event or one signed by another pubkey, instead of a plain Exception for an invalid event only.
  • The pending requests are the PendingSignRequest, PendingEncryptRequest and PendingDecryptRequest of dostr_signer: a ping, switchRelays and the request for the user's pubkey are no longer in pendingRequests.
  • The relays of BunkerConnection, NostrConnect, Bunkers.createNostrConnect and Nip46Signer.switchRelays are RelayUrls, from dostr_core. The relays of a bunker:// url and of BunkerConnection.fromJson are normalized, and a url that is not a relay's is dropped.
  • Nip46Signer.switchRelays keeps the current relays when the remote signer sends none that is a relay url.
  • connectWithBunkerUrl and connectWithNostrConnect return a BunkerConnection instead of a BunkerConnection?. A refused connect throws a SignerRequestRejectedException at once, where it waited for the timeout, and no answer within timeout a SignerRequestFailedException, where it threw a TimeoutException. Nip46Signer.defaultConnectTimeout, 10 minutes, replaces Bunkers.kMaxWaitingTimeForConnectionSeconds and Nip46Signer.defaultPublicKeyTimeout, and each wait takes a timeout.
  • The secret of a bunker:// url is optional, as in NIP-46, and connect takes the secret as an answer as well as ack.
  • connectWithNostrConnect takes no authCallback, which it never called: a remote signer answers a nostrconnect:// url without a request to challenge, and an auth_url from a pubkey not known yet could come from anyone who saw the url.
  • A message that does not decrypt to a JSON object is skipped. It no longer throws an uncaught error out of Nip46Signer, nor fails connectWithNostrConnect.
  • Nip46Signer.logout sends the NIP-46 logout and disposes the signer. A dispose meanwhile waits for it instead of dropping it.
  • Nip46Signer, Nip46Signer.connect and Bunkers.createSigner take an optional verifier, which checks the signature of every event the bunker signs, as in Nip07Signer.
  • Nip46Signer.connection is read-only, and switchRelays replaces it instead of changing the BunkerConnection it was given. The fields of BunkerConnection and NostrConnect are final.
  • listenRelays, onEvent, subscription, relayReqs, relayPublishes and signerFactory of Nip46Signer, and someTimeAgo of Bunkers, are private. authCallback is a void Function(String url)?.
  • cancelRequest fails a request at once, also one that waits for its turn behind maxConcurrentRequests, whose caller waited for that turn, and leaves no uncaught SignerRequestCancelledException behind. A request that cannot be sent, such as one the local signer fails to encrypt, leaves pendingRequests.
  • dispose fails every request the bunker has not answered with a SignerRequestFailedException, where a request already sent never completed, and a request cancelled or disposed while it is prepared is not sent.
  • A request that every relay refuses or never gets fails at once with a SignerRequestFailedException, where it waited forever, and a connect where it waited for its timeout. A relay whose OK times out may still pass it on, so the request keeps waiting for it.
  • ping and switchRelays take a timeout, 10 seconds by default, and fail with a SignerRequestFailedException once it passes, where they could wait forever. The request then frees its slot among maxConcurrentRequests, as logout and the request for the user's pubkey now do too.
  • switchRelays throws a SignerRequestFailedException for an answer that is neither a list nor null, where it threw a FormatException or kept the relays. Disposing the signer as it gets its answer no longer reopens a subscription.
  • authCallback only gets https urls, as a bunker:// url can come from anyone, and Nip46Signer only calls it for a request it waits for.
  • connectWithBunkerUrl throws an ArgumentError for a url whose pubkey is not in hex, before it sends anything.
  • Nip46Signer and connectWithBunkerUrl send a request once a relay serves the subscription that gets its answer, where an answer to a REQ held back by a full connection or an AUTH was lost, as no relay keeps an ephemeral event. A request fails at once with a SignerRequestFailedException when no relay serves that subscription.
  • A request already sent when every relay dropped the subscription of Nip46Signer fails with a SignerRequestFailedException, where it waited forever, and the next request subscribes again.
  • A request to a disposed Nip46Signer fails at once with a SignerRequestFailedException, where it waited forever.
0
likes
160
points
--
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

NIP-46 remote signing for Nostr, to connect to a bunker with a bunker:// or nostrconnect:// URL and sign and encrypt through it.

Repository (GitHub)
View/report issues

Topics

#nostr #dostr #nip46 #signer

License

MIT (license)

Dependencies

dostr_core, rxdart

More

Packages that depend on dostr_nip46