dostr_signer 0.2.0
dostr_signer: ^0.2.0 copied to clipboard
The NostrSigner interface that signers implement, and the accounts and AuthPolicy that decide when one is revealed to a relay (NIP-42) or Blossom.
0.2.0 #
LocalSignerFactory.generateKeyPairreturns aKeyPair, a record with namedprivateKeyandpublicKeyfields, so that one cannot be taken for the other.LocalSignerFactory.readOnlythrows aFormatExceptionfor a public key that is not the 64 lowercase hex characters NIP-01 requires.NostrSigner.signreturns an event with the id of its payload, whatever id it was given.
0.1.0 #
- Initial release, moved out of the
ndkpackage, with theConcurrencyLimiterMixinof interactive signers, and the accounts (AuthAccounts),AuthPolicyandAuthHandlerthat decide when one is revealed to a relay (NIP-42) or a Blossom server. EventSignerofndkis nowNostrSigner, andLocalEventSignerFactoryis nowLocalSignerFactory, since a signer also encrypts and decrypts.recipientPubKeyofencryptNip44andsenderPubKeyofdecryptNip44are nowrecipientPubkeyandsenderPubkey.NostrSignerandLocalSignerFactoryare interface classes, without the default implementations that no signer inherited.requiresInteractiveSigning,requiresSignerNetworkandsignerTransportRelayUrlsare gone: nothing read them.encryptanddecryptare nowencryptNip04anddecryptNip04, and take the named parameters ofencryptNip44anddecryptNip44. The pubkey thatdecryptcalleddestPubkeywas the sender's.encryptNip04,decryptNip04,encryptNip44anddecryptNip44return aFuture<String>instead of aFuture<String?>: a signer that cannot encrypt or decrypt throws.canSignis a getter, andgetPublicKey()is thepublicKeygetter.AccountandAccountTypeare gone: an account is itsNostrSigner, which knows its pubkey and tells what it is withcanSignand its class.AuthPolicy.allowandAuthPolicy.requiretake the signer, andAuthPolicy.accountis nowsigner.AuthAccounts.getLoggedAccount()returns theNostrSignerof the logged account, andgetAccount(pubkey)replaces theaccountsmap, which exposed every account to look up one.AuthPolicyno longer hascanonical,==andhashCode: two policies for the same pubkey were equal even when one account could sign and the other could not.toStringstill names the kind and the pubkey.LocalSignerFactory.createtakes the private key alone and derives the public key, andreadOnlymakes a read-only signer from a public key.create({privateKey, publicKey})needed one of the two at run time, and kept a public key that did not match the private key.derivePublicKeyis gone:create(privateKey).publicKeygives it.SignerRequestRejectedExceptionandSignerRequestCancelledExceptionare both aSignerRequestException, a sealed class with therequestId, so a singleon SignerRequestExceptioncatches both.SignerRequestFailedException, aSignerRequestExceptiontoo, is what a request throws when no valid result came back, such as a ciphertext that does not decrypt or an event signed by another pubkey. The queued requests thatConcurrencyLimiterMixin.cancelAllQueueddrops throw it instead of aStateError.NostrSignersays what its implementations do: an operation completes with its result or throws aSignerRequestException,publicKeynever throws, andsigntakes an event of that pubkey and returns one of that pubkey. Misusing a signer throws anError: anArgumentErrorforsignwith an event of another pubkey, and any operation whilecanSignis false.PendingSignerRequestis a sealed class: aPendingSignRequesthas theevent, aPendingEncryptRequesttheplaintextandrecipientPubkey, aPendingDecryptRequesttheciphertextandsenderPubkey.counterpartyPubkeyandcontentare gone.SignerMethodandPendingSignerRequest.methodare gone: the class of a request tells what it waits for, and theschemeof an encryption or a decryption, anEncryptionScheme, tells NIP-04 from NIP-44. Only signatures, encryptions and decryptions wait inpendingRequests, since the user does not approveconnect,getPublicKey,pingorswitchRelays, and the NIP-46 method names are indostr_nip46.ConcurrencyLimiterMixinthrows aRangeErrorwhenmaxConcurrentRequestsis below 1, where it queued every request forever.