You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
dateKeys-dart/test/wordkey_vm_test.dart

74 lines
2.5 KiB

// The key of words against files and at full strength: the copy of
// test/vectors/wordkey_vectors.json that wordkey_test.dart reads, a Dart
// constant for the tests compiled to JavaScript, is the JSON file byte for
// byte; and wordKey, with the 600 000 iterations of PBKDF2-HMAC-SHA256 of
// spec §38.1, and wordIdentity give the key and the recipient of Go's
// wordkey.Key and wordkey.Identity, the vector of §38.1 first. About a
// second each: on the VM only.
@TestOn('vm')
library;
import 'dart:convert';
import 'dart:io';
import 'package:datekeys/src/bytes.dart';
import 'package:datekeys/src/wordkey.dart';
import 'package:test/test.dart';
import 'vectors/wordkey_vectors.g.dart';
import 'wordkey_support.dart';
void main() {
test('wordkey_vectors.g.dart holds wordkey_vectors.json', () {
final file = File('test/vectors/wordkey_vectors.json').readAsStringSync();
expect(wordkeyVectorsJson, file);
});
final vectors = jsonDecode(wordkeyVectorsJson) as Map<String, Object?>;
final keys = (vectors['keys']! as List).cast<Map<String, Object?>>();
test('the vector of spec §38.1', () {
// «perro luna casa verde tren mar», the chain hash of Quicknet, round
// 1000 and capsule_id 000102…0f.
final c = keys.first;
expect(
c['chain_hash'],
'52db9ba70e0cc0f6eaf7803dd07447a1f5477735fd3f661792ba94600c84e971',
);
expect(c['round'], 1000);
expect(c['capsule_id'], '000102030405060708090a0b0c0d0e0f');
expect(
c['key'],
'fceec4d8ca8de86c85a1f26ed49f82a2b38431bd0ce36db995ae7dfd49b96e41',
);
final words = normalizeWords('perro luna casa verde tren mar');
expect(words, [for (final w in wordBytes(c)) decodeUtf8(w)]);
checkWords(words);
});
test('wordKey of the vector of spec §38.1', () {
final c = keys.first;
final key = wordKey(
normalizeWords('perro luna casa verde tren mar'),
fromHex(c['chain_hash']! as String),
1000,
fromHex(c['capsule_id']! as String),
);
expect(toHex(key), c['key']);
});
// wordIdentity derives its secret key with wordKey: one PBKDF2 per case.
for (final c in keys) {
test('wordIdentity: ${c['name']}', () {
final id = wordIdentity(
[for (final w in wordBytes(c)) fromWtf8(w)!],
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']);
});
}
}

Powered by TurnKey Linux.