mirror of
https://gitlab.com/veilid/veilid.git
synced 2025-10-17 21:11:11 -04:00
Variable Length Keys
This commit is contained in:
parent
b52e64e56a
commit
67be63c91c
171 changed files with 12847 additions and 10261 deletions
|
@ -5,7 +5,7 @@ import 'package:flutter_test/flutter_test.dart';
|
|||
import 'package:veilid/veilid.dart';
|
||||
|
||||
final bogusKey =
|
||||
PublicKey.fromString('VLD0:qD10lHHPD1_Qr23_Qy-1JnxTht12eaWwENVG_m2v7II');
|
||||
RecordKey.fromString('VLD0:qD10lHHPD1_Qr23_Qy-1JnxTht12eaWwENVG_m2v7II');
|
||||
|
||||
Future<void> testGetDHTValueUnopened() async {
|
||||
final rc = await Veilid.instance.routingContext();
|
||||
|
@ -106,7 +106,8 @@ Future<void> testSetGetDHTValueWithOwner() async {
|
|||
final rc = await Veilid.instance.routingContext();
|
||||
try {
|
||||
final cs = await Veilid.instance.bestCryptoSystem();
|
||||
final ownerKeyPair = await cs.generateKeyPair();
|
||||
final ownerKeyPair =
|
||||
KeyPair.fromBareKeyPair(cs.kind(), await cs.generateKeyPair());
|
||||
|
||||
final rec = await rc.createDHTRecord(const DHTSchema.dflt(oCnt: 2),
|
||||
owner: ownerKeyPair);
|
||||
|
@ -129,6 +130,32 @@ Future<void> testSetGetDHTValueWithOwner() async {
|
|||
}
|
||||
}
|
||||
|
||||
Future<void> testCreateDHTRecordWithDeterministicKey() async {
|
||||
final rc = await Veilid.instance.routingContext();
|
||||
try {
|
||||
final bestCryptoSystem = await Veilid.instance.bestCryptoSystem();
|
||||
final bestCryptoKind = bestCryptoSystem.kind();
|
||||
final ownerKeyPair = await bestCryptoSystem.generateKeyPair();
|
||||
final owner = ownerKeyPair.key;
|
||||
final secret = ownerKeyPair.secret;
|
||||
const schema = DHTSchema.dflt(oCnt: 1);
|
||||
final dhtRecordKey = await rc.getDHTRecordKey(
|
||||
schema, PublicKey(kind: bestCryptoKind, value: owner));
|
||||
final dhtRecord = await rc.createDHTRecord(const DHTSchema.dflt(oCnt: 1),
|
||||
owner: KeyPair.fromBareKeyPair(bestCryptoKind, ownerKeyPair),
|
||||
kind: bestCryptoKind);
|
||||
expect(dhtRecord.key, equals(dhtRecordKey));
|
||||
expect(
|
||||
dhtRecord.owner, equals(PublicKey(kind: bestCryptoKind, value: owner)));
|
||||
expect(dhtRecord.ownerSecret, equals(secret));
|
||||
expect(dhtRecord.schema, equals(schema));
|
||||
await rc.closeDHTRecord(dhtRecord.key);
|
||||
await rc.deleteDHTRecord(dhtRecord.key);
|
||||
} finally {
|
||||
rc.close();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> testOpenWriterDHTValue() async {
|
||||
final rc = await Veilid.instance.routingContext();
|
||||
try {
|
||||
|
@ -138,8 +165,9 @@ Future<void> testOpenWriterDHTValue() async {
|
|||
final secret = rec.ownerSecret!;
|
||||
|
||||
final cs = await Veilid.instance.getCryptoSystem(rec.key.kind);
|
||||
expect(await cs.validateKeyPair(owner, secret), isTrue);
|
||||
final otherKeyPair = await cs.generateKeyPair();
|
||||
expect(await cs.validateKeyPair(owner.value, secret), isTrue);
|
||||
final otherKeyPair =
|
||||
KeyPair.fromBareKeyPair(cs.kind(), await cs.generateKeyPair());
|
||||
|
||||
final va = utf8.encode('Qwertyuiop Asdfghjkl Zxcvbnm');
|
||||
final vb = utf8.encode('1234567890');
|
||||
|
@ -193,7 +221,7 @@ Future<void> testOpenWriterDHTValue() async {
|
|||
await rc.deleteDHTRecord(key);
|
||||
|
||||
rec = await rc.openDHTRecord(key,
|
||||
writer: BareKeyPair(key: owner, secret: secret));
|
||||
writer: KeyPair.fromPublicAndBareSecret(owner, secret));
|
||||
expect(rec, isNotNull);
|
||||
expect(rec.key, equals(key));
|
||||
expect(rec.owner, equals(owner));
|
||||
|
@ -245,7 +273,7 @@ Future<void> testOpenWriterDHTValue() async {
|
|||
// exists online at seq 0
|
||||
vdtemp = await rc.setDHTValue(key, 0, va,
|
||||
options: SetDHTValueOptions(
|
||||
writer: BareKeyPair(key: owner, secret: secret)));
|
||||
writer: KeyPair.fromPublicAndBareSecret(owner, secret)));
|
||||
expect(vdtemp, isNotNull);
|
||||
expect(vdtemp!.data, equals(vb));
|
||||
expect(vdtemp.seq, equals(0));
|
||||
|
@ -254,7 +282,7 @@ Future<void> testOpenWriterDHTValue() async {
|
|||
// Should update the second time to seq 1
|
||||
vdtemp = await rc.setDHTValue(key, 0, va,
|
||||
options: SetDHTValueOptions(
|
||||
writer: BareKeyPair(key: owner, secret: secret)));
|
||||
writer: KeyPair.fromPublicAndBareSecret(owner, secret)));
|
||||
expect(vdtemp, isNull);
|
||||
|
||||
// Clean up
|
||||
|
@ -265,7 +293,7 @@ Future<void> testOpenWriterDHTValue() async {
|
|||
}
|
||||
}
|
||||
|
||||
Future<void> settle(VeilidRoutingContext rc, PublicKey key, int subkey) async {
|
||||
Future<void> settle(VeilidRoutingContext rc, RecordKey key, int subkey) async {
|
||||
// Wait for set to settle
|
||||
do {
|
||||
await Future<void>.delayed(const Duration(milliseconds: 100));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue