Skip to content

Commit

Permalink
🔥 Clean (#82)
Browse files Browse the repository at this point in the history
1. Reorg exports/imports so people can directly import
`agent_dart_base/agent_dart_base.dart` or `agent_dart/agent_dart.dart`
without conflicts as much as possible.
2. Improve test equality checks.
3. Remove unnecessary deps.
  • Loading branch information
AlexV525 authored Oct 9, 2024
2 parents 42125eb + aae0ea1 commit f432d82
Show file tree
Hide file tree
Showing 74 changed files with 346 additions and 272 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ that can be found in the LICENSE file. -->

# Changelog

## 1.0.0-dev.26

- Reorg exports/imports so people can directly import `agent_dart_base/agent_dart_base.dart`
or `agent_dart/agent_dart.dart` without conflicts as much as possible.
- Improve test equality checks.
- Remove unnecessary deps.

## 1.0.0-dev.25

- Prepare for monorepo.
Expand Down
2 changes: 1 addition & 1 deletion packages/agent_dart/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: agent_dart
version: 1.0.0-dev.25
version: 1.0.0-dev.26

description: |
An agent library built for Internet Computer,
Expand Down
11 changes: 5 additions & 6 deletions packages/agent_dart_base/lib/agent/actor.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import 'dart:convert';
import 'dart:typed_data';

import 'package:agent_dart_base/agent/agent/api.dart';
import 'package:agent_dart_base/agent/canisters/management.dart';
import 'package:agent_dart_base/agent/polling/polling.dart';
import 'package:agent_dart_base/candid/idl.dart';
import 'package:agent_dart_base/principal/principal.dart';

import '../candid/idl.dart';
import '../principal/principal.dart';
import 'agent/api.dart';
import 'canisters/management.dart';
import 'errors.dart';
import 'polling/polling.dart';
import 'request_id.dart';
import 'types.dart';

Expand Down
1 change: 1 addition & 0 deletions packages/agent_dart_base/lib/agent/agent.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export './utils/index.dart';

export 'actor.dart';
export 'auth.dart';
export 'bls.dart';
export 'cbor.dart';
export 'certificate.dart';
export 'errors.dart';
Expand Down
7 changes: 4 additions & 3 deletions packages/agent_dart_base/lib/agent/agent/api.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import 'package:agent_dart_base/agent/auth.dart';
import 'package:agent_dart_base/agent/types.dart';
import 'package:agent_dart_base/principal/principal.dart';
import 'package:meta/meta.dart';

import '../../principal/principal.dart';
import '../auth.dart';
import '../types.dart';

/// Codes used by the replica for rejecting a message.
/// See https://sdk.dfinity.org/docs/interface-spec/#reject-codes
/// for the interface spec.
Expand Down
6 changes: 3 additions & 3 deletions packages/agent_dart_base/lib/agent/agent/factory.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:agent_dart_base/agent/agent.dart';
import 'package:agent_dart_base/candid/idl.dart';
import 'package:agent_dart_base/principal/principal.dart';
import '../../candid/idl.dart';
import '../../principal/principal.dart';
import '../agent.dart';

class AgentFactory {
AgentFactory({
Expand Down
4 changes: 3 additions & 1 deletion packages/agent_dart_base/lib/agent/agent/http/fetch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import 'dart:typed_data';

import 'package:http/http.dart' as http;

import 'index.dart';
import '../../types.dart';

// import 'index.dart';

const defaultTimeout = Duration(seconds: 30);

Expand Down
40 changes: 12 additions & 28 deletions packages/agent_dart_base/lib/agent/agent/http/index.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import 'dart:async';
import 'dart:typed_data';

import 'package:agent_dart_base/agent/agent/http/fetch.dart';
import 'package:agent_dart_base/agent/cbor.dart' as cbor;
import 'package:agent_dart_base/agent_dart_base.dart';
import 'package:meta/meta.dart';
import 'package:typed_data/typed_data.dart';

import '../../../principal/principal.dart';
import '../../../utils/base64.dart';
import '../../auth.dart';
import '../../cbor.dart' as cbor;
import '../../errors.dart';
import '../../request_id.dart';
import '../../types.dart';
import '../api.dart';
import 'fetch.dart';
import 'transform.dart';
import 'types.dart';

const btoa = base64Encode;

Future<T> withRetry<T>(
Expand All @@ -30,31 +39,6 @@ Future<T> withRetry<T>(
}
}

enum FetchMethod {
get,
head,
post,
put,
delete,
connect,
options,
trace,
patch,
}

enum RequestStatusResponseStatus {
received,
processing,
replied,
rejected,
unknown,
done;

factory RequestStatusResponseStatus.fromName(String value) {
return values.singleWhere((e) => e.name == value);
}
}

/// Default delta for ingress expiry is 5 minutes.
const _defaultIngressExpiryDeltaInMilliseconds = 5 * 60 * 1000;

Expand Down
6 changes: 3 additions & 3 deletions packages/agent_dart_base/lib/agent/agent/http/transform.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'dart:typed_data';

import 'package:agent_dart_base/agent/cbor.dart';
import 'package:agent_dart_base/agent/types.dart';
import 'package:agent_dart_base/agent/utils/leb128.dart';
import 'package:cbor/cbor.dart' as cbor;
import 'package:typed_data/typed_data.dart';

import '../../cbor.dart';
import '../../types.dart';
import '../../utils/leb128.dart';
import 'types.dart';

final _nanoSecondsPerMilliseconds = BigInt.from(1000000);
Expand Down
5 changes: 3 additions & 2 deletions packages/agent_dart_base/lib/agent/agent/http/types.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import 'dart:convert';
import 'dart:typed_data';

import 'package:agent_dart_base/agent/types.dart';
import 'package:agent_dart_base/principal/principal.dart';
import 'package:meta/meta.dart';
import 'package:typed_data/typed_buffers.dart';

import '../../../principal/principal.dart';
import '../../types.dart';
import '../api.dart';
import 'transform.dart';

Expand Down
7 changes: 4 additions & 3 deletions packages/agent_dart_base/lib/agent/agent/index.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export './http/index.dart';
export './http/transform.dart';
export './http/types.dart';
export 'api.dart';
export 'factory.dart';
export 'http/fetch.dart';
export 'http/index.dart';
export 'http/transform.dart';
export 'http/types.dart';
export 'proxy.dart';
6 changes: 3 additions & 3 deletions packages/agent_dart_base/lib/agent/agent/proxy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import 'dart:async';
import 'dart:convert';
import 'dart:typed_data';

import 'package:agent_dart_base/agent/auth.dart';
import 'package:agent_dart_base/agent/types.dart';
import 'package:agent_dart_base/principal/principal.dart';
import 'package:meta/meta.dart';

import '../../principal/principal.dart';
import '../auth.dart';
import '../types.dart';
import 'api.dart';

class ProxyMessageKind {
Expand Down
6 changes: 3 additions & 3 deletions packages/agent_dart_base/lib/agent/auth.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'dart:typed_data';

import 'package:agent_dart_base/principal/principal.dart';
import 'package:agent_dart_base/utils/extension.dart';
import 'package:agent_dart_base/utils/u8a.dart';
import 'package:meta/meta.dart';

import '../../utils/extension.dart';
import '../../utils/u8a.dart';
import '../principal/principal.dart';
import 'agent/http/types.dart';
import 'request_id.dart';
import 'types.dart';
Expand Down
3 changes: 1 addition & 2 deletions packages/agent_dart_base/lib/agent/canisters/asset.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:agent_dart_base/agent/actor.dart';

import '../actor.dart';
import 'asset_idl.dart';

/// Create a management canister actor.
Expand Down
4 changes: 2 additions & 2 deletions packages/agent_dart_base/lib/agent/canisters/asset_idl.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:typed_data';

import 'package:agent_dart_base/agent/actor.dart';
import 'package:agent_dart_base/candid/idl.dart';
import '../../candid/idl.dart';
import '../actor.dart';

Service assetIDL() {
return IDL.Service({
Expand Down
5 changes: 2 additions & 3 deletions packages/agent_dart_base/lib/agent/canisters/management.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:agent_dart_base/agent/actor.dart';
import 'package:agent_dart_base/principal/principal.dart';

import '../../principal/principal.dart';
import '../actor.dart';
import 'management_idl.dart';

// : ActorSubclass<ManagementCanisterRecord>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:agent_dart_base/candid/idl.dart';
import '../../candid/idl.dart';

Service managementIDL() {
const canisterId = IDL.Principal;
Expand Down
2 changes: 1 addition & 1 deletion packages/agent_dart_base/lib/agent/cbor.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'dart:math' as math;
import 'dart:typed_data';

import 'package:agent_dart_base/principal/principal.dart';
import 'package:cbor/cbor.dart' as cbor;
import 'package:meta/meta.dart' show immutable;
import 'package:typed_data/typed_data.dart';

import '../principal/principal.dart';
import 'types.dart';

const _kIsWeb = bool.hasEnvironment('dart.library.js_util')
Expand Down
24 changes: 12 additions & 12 deletions packages/agent_dart_base/lib/agent/certificate.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import 'dart:convert';
import 'dart:typed_data';

import 'package:agent_dart_base/agent/cbor.dart';
import 'package:agent_dart_base/agent/request_id.dart';
import 'package:agent_dart_base/agent/types.dart';
import 'package:agent_dart_base/utils/extension.dart';
import 'package:agent_dart_base/utils/u8a.dart';
import 'package:typed_data/typed_data.dart';

import '../../utils/extension.dart';
import '../../utils/u8a.dart';
import 'agent/api.dart';
import 'bls.dart';
import 'cbor.dart';
import 'errors.dart';
import 'request_id.dart';
import 'types.dart';

final AgentBLS _bls = AgentBLS();

Expand Down Expand Up @@ -52,7 +52,7 @@ class Cert {
factory Cert.fromJson(Map json) {
return Cert(
delegation: json['delegation'] != null
? Delegation.fromJson(Map<String, dynamic>.from(json['delegation']))
? CertDelegation.fromJson(Map<String, dynamic>.from(json['delegation']))
: null,
signature: json['signature'] != null
? (json['signature'] as Uint8Buffer).buffer.asUint8List()
Expand All @@ -63,7 +63,7 @@ class Cert {

final List? tree;
final Uint8List? signature;
final Delegation? delegation;
final CertDelegation? delegation;

Map<String, dynamic> toJson() {
return {
Expand Down Expand Up @@ -99,14 +99,14 @@ String hashTreeToString(List tree) {
}
}

class Delegation extends ReadStateResponse {
const Delegation(
class CertDelegation extends ReadStateResponse {
const CertDelegation(
this.subnetId,
BinaryBlob certificate,
) : super(certificate: certificate);

factory Delegation.fromJson(Map<String, dynamic> json) {
return Delegation(
factory CertDelegation.fromJson(Map<String, dynamic> json) {
return CertDelegation(
Uint8List.fromList(json['subnet_id'] as List<int>),
json['certificate'] is Uint8List || json['certificate'] is Uint8Buffer
? Uint8List.fromList(json['certificate'])
Expand Down Expand Up @@ -159,7 +159,7 @@ class Certificate {
}
}

Future<Uint8List> _checkDelegation(Delegation? d) async {
Future<Uint8List> _checkDelegation(CertDelegation? d) async {
if (d == null) {
if (_rootKey == null) {
if (_agent.rootKey != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@ import 'dart:convert';
import 'dart:core';
import 'dart:typed_data';

import 'package:agent_dart_base/agent/cbor.dart';
import 'package:agent_dart_base/agent/crypto/random.dart';
import 'package:agent_dart_base/identity/p256.dart';
import 'package:agent_dart_base/identity/secp256k1.dart';
import 'package:agent_dart_base/principal/utils/sha256.dart';
import 'package:agent_dart_base/utils/extension.dart';
import 'package:agent_dart_base/utils/u8a.dart';
import 'package:agent_dart_ffi/agent_dart_ffi.dart';
import 'package:collection/collection.dart';
import 'package:meta/meta.dart';
import 'package:pointycastle/export.dart';
import 'package:uuid/uuid.dart';

import '../../../identity/p256.dart';
import '../../../identity/secp256k1.dart';
import '../../../principal/utils/sha256.dart';
import '../../../utils/extension.dart';
import '../../../utils/u8a.dart';
import '../../cbor.dart';
import '../random.dart';

part 'function.dart';
part 'key_derivator.dart';
part 'util.dart';
Expand Down
8 changes: 4 additions & 4 deletions packages/agent_dart_base/lib/agent/crypto/random.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'dart:math' as math;
import 'dart:typed_data';

import 'package:agent_dart_base/utils/extension.dart';
import 'package:agent_dart_base/utils/hex.dart';
import 'package:agent_dart_base/utils/number.dart';
import 'package:agent_dart_base/utils/u8a.dart';
import '../../utils/extension.dart';
import '../../utils/hex.dart';
import '../../utils/number.dart';
import '../../utils/u8a.dart';

const _defaultLength = 32;

Expand Down
2 changes: 1 addition & 1 deletion packages/agent_dart_base/lib/agent/errors.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:typed_data';

import 'package:agent_dart_base/utils/extension.dart';
import '../../utils/extension.dart';

/// An fetch error when using agent to make HTTP/S requests.
class AgentFetchError extends Error {
Expand Down
11 changes: 8 additions & 3 deletions packages/agent_dart_base/lib/agent/polling/polling.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import 'package:agent_dart_base/agent/agent.dart';
import 'package:agent_dart_base/principal/principal.dart';
import 'package:agent_dart_base/utils/extension.dart';
import '../../../principal/principal.dart';
import '../../../utils/extension.dart';
import '../agent/api.dart';
import '../agent/http/index.dart';
import '../certificate.dart';
import '../request_id.dart';
import '../types.dart';
import 'strategy.dart';

export 'strategy.dart';

Expand Down
Loading

0 comments on commit f432d82

Please sign in to comment.