Nip44Encrypt test and error return
This commit is contained in:
parent
1fee9e5d34
commit
6e0c1e0f0b
2 changed files with 45 additions and 3 deletions
|
|
@ -104,4 +104,30 @@ void main() {
|
|||
expect(ts, greaterThanOrEqualTo(before));
|
||||
expect(ts, lessThanOrEqualTo(after + 2));
|
||||
});
|
||||
|
||||
test('Nip44Encrypt round-trips to self', () async {
|
||||
final plaintext = jsonEncode({'blur_content_warnings': 'false', 'x': '1'});
|
||||
final encrypted = await signer.handle(Nip44Encrypt(plaintext)) as Nip44Text;
|
||||
expect(encrypted.value, isNot(equals(plaintext)));
|
||||
|
||||
// Payload is base64 with the NIP-44 v2 version byte (0x02) first.
|
||||
final bytes = base64.decode(encrypted.value);
|
||||
expect(bytes.first, equals(0x02));
|
||||
|
||||
final decrypted =
|
||||
await signer.handle(Nip44Decrypt(encrypted.value)) as Nip44Text;
|
||||
expect(decrypted.value, equals(plaintext));
|
||||
});
|
||||
|
||||
test('Nip44Decrypt with a foreign key fails', () async {
|
||||
final encrypted =
|
||||
await signer.handle(const Nip44Encrypt('secret')) as Nip44Text;
|
||||
final other = NostrSignerActor(
|
||||
'0000000000000000000000000000000000000000000000000000000000000002',
|
||||
);
|
||||
expect(
|
||||
() => other.handle(Nip44Decrypt(encrypted.value)),
|
||||
throwsA(anything),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue