dostr_nip46 0.1.0
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
ndkpackage. Keys come from theLocalSignerFactoryonly, so it does not depend ondostr_bip340:Bunkers.createNostrConnectreplacesNostrConnect(relays:, clientMetadata:), andNostrConnecthasprivateKeyandpublicKeyinstead of aKeyPair. Nip46EventSigneris nowNip46Signer, after theNostrSignerit implements.BunkersandNip46Signertake their factory assignerFactoryinstead ofeventSignerFactory, andlocalEventSignerofNip46Signeris private.encryptNip44anddecryptNip44takerecipientPubkeyandsenderPubkey, as inNostrSigner, instead ofrecipientPubKeyandsenderPubKey.- As in
NostrSigner,encryptanddecryptare nowencryptNip04anddecryptNip04, with named parameters, the four encryption methods return aFuture<String>instead of aFuture<String?>,canSignis a getter,getPublicKey()is thepublicKeygetter, andrequiresInteractiveSigning,requiresSignerNetworkandsignerTransportRelayUrlsare gone. BunkerRequest.methodis the NIP-46 method name, such assign_event, instead of aSignerMethod, andremoteRequestis private:pingandswitchRelayssend the NIP-46 methods that are not inNostrSigner.- BREAKING A
Nip46Signerknows the user's pubkey from the start, sopublicKeynever throws:Bunkers.createSignercompletes once the bunker sent it, andNip46Signer.connectdoes the same withoutBunkers.Nip46Signer(publicKey: ...)takes it, for an account restored from storage, instead ofcachedPublicKey.getPublicKeyAsyncis gone. signthrows anArgumentErrorfor an event of another pubkey, and aSignerRequestFailedExceptionwhen the bunker returns an invalid event or one signed by another pubkey, instead of a plainExceptionfor an invalid event only.- The pending requests are the
PendingSignRequest,PendingEncryptRequestandPendingDecryptRequestofdostr_signer: a ping,switchRelaysand the request for the user's pubkey are no longer inpendingRequests. - The relays of
BunkerConnection,NostrConnect,Bunkers.createNostrConnectandNip46Signer.switchRelaysareRelayUrls, fromdostr_core. The relays of abunker://url and ofBunkerConnection.fromJsonare normalized, and a url that is not a relay's is dropped. Nip46Signer.switchRelayskeeps the current relays when the remote signer sends none that is a relay url.connectWithBunkerUrlandconnectWithNostrConnectreturn aBunkerConnectioninstead of aBunkerConnection?. A refusedconnectthrows aSignerRequestRejectedExceptionat once, where it waited for the timeout, and no answer withintimeoutaSignerRequestFailedException, where it threw aTimeoutException.Nip46Signer.defaultConnectTimeout, 10 minutes, replacesBunkers.kMaxWaitingTimeForConnectionSecondsandNip46Signer.defaultPublicKeyTimeout, and each wait takes atimeout.- The
secretof abunker://url is optional, as in NIP-46, andconnecttakes the secret as an answer as well asack. connectWithNostrConnecttakes noauthCallback, which it never called: a remote signer answers anostrconnect://url without a request to challenge, and anauth_urlfrom 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 failsconnectWithNostrConnect. Nip46Signer.logoutsends the NIP-46logoutand disposes the signer. Adisposemeanwhile waits for it instead of dropping it.Nip46Signer,Nip46Signer.connectandBunkers.createSignertake an optionalverifier, which checks the signature of every event the bunker signs, as inNip07Signer.Nip46Signer.connectionis read-only, andswitchRelaysreplaces it instead of changing theBunkerConnectionit was given. The fields ofBunkerConnectionandNostrConnectare final.listenRelays,onEvent,subscription,relayReqs,relayPublishesandsignerFactoryofNip46Signer, andsomeTimeAgoofBunkers, are private.authCallbackis avoid Function(String url)?.cancelRequestfails a request at once, also one that waits for its turn behindmaxConcurrentRequests, whose caller waited for that turn, and leaves no uncaughtSignerRequestCancelledExceptionbehind. A request that cannot be sent, such as one the local signer fails to encrypt, leavespendingRequests.disposefails every request the bunker has not answered with aSignerRequestFailedException, 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 aconnectwhere it waited for itstimeout. A relay whose OK times out may still pass it on, so the request keeps waiting for it. pingandswitchRelaystake atimeout, 10 seconds by default, and fail with aSignerRequestFailedExceptiononce it passes, where they could wait forever. The request then frees its slot amongmaxConcurrentRequests, aslogoutand the request for the user's pubkey now do too.switchRelaysthrows aSignerRequestFailedExceptionfor an answer that is neither a list nor null, where it threw aFormatExceptionor kept the relays. Disposing the signer as it gets its answer no longer reopens a subscription.authCallbackonly gets https urls, as abunker://url can come from anyone, andNip46Signeronly calls it for a request it waits for.connectWithBunkerUrlthrows anArgumentErrorfor a url whose pubkey is not in hex, before it sends anything.Nip46SignerandconnectWithBunkerUrlsend 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 aSignerRequestFailedExceptionwhen no relay serves that subscription.- A request already sent when every relay dropped the subscription of
Nip46Signerfails with aSignerRequestFailedException, where it waited forever, and the next request subscribes again. - A request to a disposed
Nip46Signerfails at once with aSignerRequestFailedException, where it waited forever.