2022-01-16 11:19:01 -05:00
|
|
|
import 'dart:async';
|
2022-09-30 22:37:55 -04:00
|
|
|
import 'dart:typed_data';
|
2022-02-06 21:18:42 -05:00
|
|
|
|
|
|
|
import 'veilid_stub.dart'
|
2022-02-09 09:47:36 -05:00
|
|
|
if (dart.library.io) 'veilid_ffi.dart'
|
|
|
|
if (dart.library.js) 'veilid_js.dart';
|
2022-02-06 21:18:42 -05:00
|
|
|
|
2022-06-15 21:51:38 -04:00
|
|
|
//////////////////////////////////////////////////////////
|
|
|
|
|
2023-05-29 15:24:57 -04:00
|
|
|
import 'routing_context.dart';
|
|
|
|
import 'veilid_config.dart';
|
|
|
|
import 'veilid_crypto.dart';
|
|
|
|
import 'veilid_table_db.dart';
|
|
|
|
import 'veilid_state.dart';
|
2022-06-15 21:51:38 -04:00
|
|
|
|
2023-05-29 15:24:57 -04:00
|
|
|
export 'default_config.dart';
|
|
|
|
export 'routing_context.dart';
|
|
|
|
export 'veilid_config.dart';
|
|
|
|
export 'veilid_crypto.dart';
|
|
|
|
export 'veilid_table_db.dart';
|
|
|
|
export 'veilid_api_exception.dart';
|
|
|
|
export 'veilid_state.dart';
|
|
|
|
export 'veilid.dart';
|
2022-06-15 21:51:38 -04:00
|
|
|
|
2022-02-09 09:47:36 -05:00
|
|
|
//////////////////////////////////////
|
|
|
|
/// JSON Encode Helper
|
2022-06-15 21:51:38 -04:00
|
|
|
|
2022-02-09 09:47:36 -05:00
|
|
|
Object? veilidApiToEncodable(Object? value) {
|
|
|
|
if (value == null) {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
switch (value.runtimeType) {
|
2023-05-29 15:24:57 -04:00
|
|
|
// case KeyPair:
|
|
|
|
// return (value as KeyPair).json;
|
2022-02-09 09:47:36 -05:00
|
|
|
}
|
|
|
|
throw UnsupportedError('Cannot convert to JSON: $value');
|
|
|
|
}
|
|
|
|
|
2023-05-29 15:24:57 -04:00
|
|
|
T? Function(dynamic) optFromJson<T>(T Function(dynamic) jsonConstructor) {
|
|
|
|
return (dynamic j) {
|
|
|
|
if (j == null) {
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
return jsonConstructor(j);
|
2022-02-09 09:47:36 -05:00
|
|
|
}
|
2023-05-29 15:24:57 -04:00
|
|
|
};
|
2022-02-09 09:47:36 -05:00
|
|
|
}
|
|
|
|
|
2023-05-29 15:24:57 -04:00
|
|
|
List<T> Function(dynamic) jsonListConstructor<T>(
|
|
|
|
T Function(dynamic) jsonConstructor) {
|
|
|
|
return (dynamic j) {
|
|
|
|
return (j as List<dynamic>).map((e) => jsonConstructor(e)).toList();
|
|
|
|
};
|
2022-12-03 18:08:53 -05:00
|
|
|
}
|
|
|
|
|
2022-02-09 09:47:36 -05:00
|
|
|
//////////////////////////////////////
|
|
|
|
/// VeilidVersion
|
|
|
|
|
|
|
|
class VeilidVersion {
|
|
|
|
final int major;
|
|
|
|
final int minor;
|
|
|
|
final int patch;
|
|
|
|
|
|
|
|
VeilidVersion(this.major, this.minor, this.patch);
|
|
|
|
}
|
|
|
|
|
2022-11-26 14:16:02 -05:00
|
|
|
//////////////////////////////////////
|
2023-05-29 15:24:57 -04:00
|
|
|
/// Timestamp
|
|
|
|
class Timestamp {
|
|
|
|
final BigInt value;
|
|
|
|
Timestamp({required this.value});
|
2022-11-26 14:16:02 -05:00
|
|
|
|
2023-05-29 15:24:57 -04:00
|
|
|
@override
|
|
|
|
String toString() {
|
|
|
|
return value.toString();
|
2022-11-26 14:16:02 -05:00
|
|
|
}
|
|
|
|
|
2023-05-29 15:24:57 -04:00
|
|
|
Timestamp.fromString(String s) : value = BigInt.parse(s);
|
2022-11-26 14:16:02 -05:00
|
|
|
|
2023-05-29 15:24:57 -04:00
|
|
|
Timestamp.fromJson(dynamic json) : this.fromString(json as String);
|
|
|
|
String toJson() {
|
|
|
|
return toString();
|
2022-11-26 14:16:02 -05:00
|
|
|
}
|
|
|
|
|
2023-05-29 15:24:57 -04:00
|
|
|
TimestampDuration diff(Timestamp other) {
|
|
|
|
return TimestampDuration(value: value - other.value);
|
2022-12-28 22:53:58 -05:00
|
|
|
}
|
2023-01-04 14:51:13 -05:00
|
|
|
|
2023-05-29 15:24:57 -04:00
|
|
|
Timestamp offset(TimestampDuration dur) {
|
|
|
|
return Timestamp(value: value + dur.value);
|
2023-01-04 14:51:13 -05:00
|
|
|
}
|
2022-12-28 12:12:04 -05:00
|
|
|
}
|
|
|
|
|
2023-05-29 15:24:57 -04:00
|
|
|
class TimestampDuration {
|
|
|
|
final BigInt value;
|
|
|
|
TimestampDuration({required this.value});
|
2022-12-28 22:53:58 -05:00
|
|
|
|
2023-05-29 15:24:57 -04:00
|
|
|
@override
|
|
|
|
String toString() {
|
|
|
|
return value.toString();
|
2022-12-28 22:53:58 -05:00
|
|
|
}
|
|
|
|
|
2023-05-29 15:24:57 -04:00
|
|
|
TimestampDuration.fromString(String s) : value = BigInt.parse(s);
|
|
|
|
|
|
|
|
TimestampDuration.fromJson(dynamic json) : this.fromString(json as String);
|
|
|
|
String toJson() {
|
|
|
|
return toString();
|
2023-01-03 09:13:18 -05:00
|
|
|
}
|
|
|
|
|
2023-05-29 15:24:57 -04:00
|
|
|
int toMillis() {
|
|
|
|
return (value ~/ BigInt.from(1000)).toInt();
|
2023-01-03 09:13:18 -05:00
|
|
|
}
|
|
|
|
|
2023-05-29 15:24:57 -04:00
|
|
|
BigInt toMicros(Timestamp other) {
|
|
|
|
return value;
|
2022-12-28 22:53:58 -05:00
|
|
|
}
|
2022-12-28 09:48:25 -05:00
|
|
|
}
|
|
|
|
|
2022-02-09 09:47:36 -05:00
|
|
|
//////////////////////////////////////
|
|
|
|
/// Veilid singleton factory
|
|
|
|
|
|
|
|
abstract class Veilid {
|
2023-05-29 15:24:57 -04:00
|
|
|
static Veilid instance = getVeilid();
|
2022-01-29 13:23:10 -05:00
|
|
|
|
2022-07-01 16:20:43 -04:00
|
|
|
void initializeVeilidCore(Map<String, dynamic> platformConfigJson);
|
2022-07-01 12:13:52 -04:00
|
|
|
void changeLogLevel(String layer, VeilidConfigLogLevel logLevel);
|
2022-09-09 16:27:13 -04:00
|
|
|
Future<Stream<VeilidUpdate>> startupVeilidCore(VeilidConfig config);
|
2022-02-09 09:47:36 -05:00
|
|
|
Future<VeilidState> getVeilidState();
|
2022-09-06 18:59:41 -04:00
|
|
|
Future<void> attach();
|
|
|
|
Future<void> detach();
|
2022-02-09 09:47:36 -05:00
|
|
|
Future<void> shutdownVeilidCore();
|
2022-11-26 14:16:02 -05:00
|
|
|
|
2023-05-29 15:24:57 -04:00
|
|
|
// Crypto
|
|
|
|
List<CryptoKind> validCryptoKinds();
|
|
|
|
Future<VeilidCryptoSystem> getCryptoSystem(CryptoKind kind);
|
|
|
|
Future<VeilidCryptoSystem> bestCryptoSystem();
|
|
|
|
Future<List<TypedKey>> verifySignatures(
|
|
|
|
List<TypedKey> nodeIds, Uint8List data, List<TypedSignature> signatures);
|
|
|
|
Future<List<TypedSignature>> generateSignatures(
|
|
|
|
Uint8List data, List<TypedKeyPair> keyPairs);
|
|
|
|
Future<TypedKeyPair> generateKeyPair(CryptoKind kind);
|
|
|
|
|
2022-11-26 14:16:02 -05:00
|
|
|
// Routing context
|
|
|
|
Future<VeilidRoutingContext> routingContext();
|
|
|
|
|
|
|
|
// Private route allocation
|
2023-03-01 15:50:30 -05:00
|
|
|
Future<RouteBlob> newPrivateRoute();
|
|
|
|
Future<RouteBlob> newCustomPrivateRoute(
|
2022-11-26 14:16:02 -05:00
|
|
|
Stability stability, Sequencing sequencing);
|
|
|
|
Future<String> importRemotePrivateRoute(Uint8List blob);
|
|
|
|
Future<void> releasePrivateRoute(String key);
|
|
|
|
|
|
|
|
// App calls
|
2022-09-30 22:37:55 -04:00
|
|
|
Future<void> appCallReply(String id, Uint8List message);
|
2022-11-26 14:16:02 -05:00
|
|
|
|
2022-12-28 09:48:25 -05:00
|
|
|
// TableStore
|
|
|
|
Future<VeilidTableDB> openTableDB(String name, int columnCount);
|
|
|
|
Future<bool> deleteTableDB(String name);
|
|
|
|
|
2022-11-26 14:16:02 -05:00
|
|
|
// Misc
|
2023-05-29 15:24:57 -04:00
|
|
|
Timestamp now();
|
2022-03-17 10:31:10 -04:00
|
|
|
String veilidVersionString();
|
|
|
|
VeilidVersion veilidVersion();
|
2022-11-26 14:16:02 -05:00
|
|
|
Future<String> debug(String command);
|
2022-01-16 11:19:01 -05:00
|
|
|
}
|