// The key of words against testdata/vectors/wordkey.json, the shared cases // of spec §38.1 that §64 of v0.11 asks for: the words of each text, what a // writer does with them, with the error of Go's wordkey.Check, and the // identity and the recipient that the words derive. Each key is 600 000 // iterations of PBKDF2: on the VM only. @TestOn('vm') library; import 'dart:convert'; import 'dart:io'; import 'package:datekeys/datekeys.dart'; import 'package:datekeys/src/wordkey.dart'; import 'package:test/test.dart'; typedef Json = Map; List _strings(Object? v) => (v! as List).cast(); void main() { final f = jsonDecode( File('testdata/vectors/wordkey.json').readAsStringSync(), ) as Json; final normalize = (f['normalize']! as List).cast(); final check = (f['check']! as List).cast(); final keys = (f['keys']! as List).cast(); test('wordkey.json names this specification and has the cases of README', () { expect(f['spec'], specVersion); expect( normalize.where((c) => (c['name']! as String).endsWith(' is a space')), hasLength(25), ); expect(check.where((c) => c['result'] == 'ok'), isNotEmpty); expect( check.where((c) => '${c['error']}'.contains('U+200B')), hasLength(1), ); expect( keys.first['key'], 'fceec4d8ca8de86c85a1f26ed49f82a2b38431bd0ce36db995ae7dfd49b96e41', ); }); group('normalize', () { for (final c in normalize) { test('${c['name']}', () { expect(normalizeWords(c['text']! as String), _strings(c['words'])); }); } }); group('check', () { for (final c in check) { test('${c['name']}', () { final words = normalizeWords(c['text']! as String); expect(words, _strings(c['words'])); if (c['result'] == 'ok') { checkWords(words); } else { expect(c['result'], 'error'); expect( () => checkWords(words), throwsA( isA().having( (e) => e.message, 'message', c['error'], ), ), ); } }); } }); group('keys', () { for (final c in keys) { test('${c['name']}', () { final id = wordIdentity( _strings(c['words']), fromHex(c['chain_hash']! as String), c['round']! as int, fromHex(c['capsule_id']! as String), ); expect(toHex(id.secretKey), c['key']); expect(id.recipientString, c['recipient']); }); } }); }