32 lines
1.1 KiB
Dart
32 lines
1.1 KiB
Dart
|
|
import 'dart:convert';
|
||
|
|
import 'dart:typed_data';
|
||
|
|
|
||
|
|
import 'package:halkyon_content/halkyon_content.dart';
|
||
|
|
import 'package:test/test.dart';
|
||
|
|
|
||
|
|
/// An agent's keys (Halkyon's ADR 0044, D6): made where it runs, each
|
||
|
|
/// agent's its own, and what a cipher unlocks to seal and open with.
|
||
|
|
void main() {
|
||
|
|
test("new keys are an account's own, and seal what they open", () async {
|
||
|
|
final one = await newAccountKeys();
|
||
|
|
final other = await newAccountKeys();
|
||
|
|
expect(one.encryptionSecretKey, hasLength(32));
|
||
|
|
expect(one.signingSecretKey, hasLength(64));
|
||
|
|
expect(one.encryptionPublicKey, isNot(other.encryptionPublicKey));
|
||
|
|
expect(one.signingPublicKey, isNot(other.signingPublicKey));
|
||
|
|
|
||
|
|
final cipher = SodiumContentCipher();
|
||
|
|
addTearDown(cipher.dispose);
|
||
|
|
await cipher.unlock(one);
|
||
|
|
cipher.newKey('k-1');
|
||
|
|
final sealed = cipher.seal(
|
||
|
|
Uint8List.fromList(utf8.encode('猫')),
|
||
|
|
keyId: 'k-1',
|
||
|
|
context: utf8.encode('card|1'),
|
||
|
|
);
|
||
|
|
expect(
|
||
|
|
utf8.decode(cipher.unseal(sealed, context: utf8.encode('card|1'))!),
|
||
|
|
'猫',
|
||
|
|
);
|
||
|
|
});
|
||
|
|
}
|