dostr_bip340 0.1.0
dostr_bip340: ^0.1.0 copied to clipboard
Pure Dart BIP-340 Schnorr signing and verification for Nostr, with a signer and an event verifier.
0.1.0 #
- Initial release, moved out of the
ndkpackage. Bip340EventSigneris nowBip340Signer, andBip340EventSignerFactoryis nowBip340SignerFactory, after theNostrSignerthey implement.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. - An encryption or a decryption that fails throws a
SignerRequestFailedException, whosecauseis the error ofdostr_nip44, asNostrSignersays:decryptNip04used to return an empty string for a NIP-04 payload without?iv=. signthrows anArgumentErrorfor an event of another pubkey, and every operation of a read-onlyBip340Signerthrows aStateError.signsigns the payload and sets the id, asBip340.signEventdoes, whatever id the event holds.Bip340Signerkeeps the NIP-44 conversation keys of its last 256 peers, soencryptNip44anddecryptNip44run the key agreement once per peer instead of once per message.Bip340Signer(privateKey)derives the public key, andBip340Signer.readOnly(publicKey)makes a read-only signer.Bip340EventSigner(privateKey:, publicKey:)took any pair of keys, and a null or blank private key for a read-only signer.privateKeyandpublicKeyare final.Bip340Signer.readOnlythrows aFormatExceptionfor a public key that is not the 64 lowercase hex characters NIP-01 requires.- As in
LocalSignerFactory,Bip340SignerFactory.createtakes the private key alone,readOnlytakes a public key,generateKeyPairreturns aKeyPair, andderivePublicKeyis gone. Bip340can no longer be instantiated, extended or implemented: it only holds static members.Bip340runs on theSchnorrsignatures ofdostr_secp256k1instead of thebip340package and the pointycastle curve: on native platforms,verifyis about 12 times faster, andsign,getPublicKeyandgenerateKeyPairabout 23 times.Bip340.signandBip340.verifytake a message of any length, as BIP-340 allows since 2022, instead of reading its first 32 bytes only, andBip340.signtakes an optionalauxRandfor test vectors.Bip340.signandBip340.verifytake named parameters, since the message, the key and the signature are all hex strings, and thepublicKeyofverifyis not nullable.Bip340.generatePrivateKeyis nowBip340.generateKeyPair, which returns theKeyPairrecord ofdostr_signer, exported here too, whoseprivateKeyis never null. TheKeyPairclass is gone, with itsjustPublicKeyand its==that only compared the public keys.Bip340.signandBip340.getPublicKeythrow aFormatExceptionfor a private key that is not 64 hex characters or not between 1 and n - 1, andBip340.verifyreturns false instead of throwing on malformed input.Nip01Utils.signWithPrivateKeyis nowBip340.signEvent, which throws anArgumentErrorfor an event whose pubkey is not the one of the private key, assigndoes.Bip340EventVerifierverifies on the calling isolate:useIsolateis gone. Its constructor isconst.Bip340EventVerifierreturns false, instead of throwing, on a malformed event, and rejects a sig or a pubkey that is not lowercase hex of the length NIP-01 sets. It used to accept a sig with extra characters after the first 128, and an uppercase pubkey.dostr_bip340no longer depends onrxdart: thependingRequestsStreamof aBip340Signeremits an empty list and closes.