├── packages ├── agent_dart │ ├── LICENSE │ ├── README.md │ ├── CHANGELOG.md │ ├── linux │ │ ├── .gitignore │ │ └── CMakeLists.txt │ ├── native │ ├── example │ │ ├── linux │ │ │ ├── .gitignore │ │ │ ├── main.cc │ │ │ ├── flutter │ │ │ │ ├── generated_plugin_registrant.cc │ │ │ │ ├── generated_plugin_registrant.h │ │ │ │ └── generated_plugins.cmake │ │ │ └── my_application.h │ │ ├── ios │ │ │ ├── Runner │ │ │ │ ├── Runner-Bridging-Header.h │ │ │ │ ├── Assets.xcassets │ │ │ │ │ ├── LaunchImage.imageset │ │ │ │ │ │ ├── LaunchImage.png │ │ │ │ │ │ ├── LaunchImage@2x.png │ │ │ │ │ │ ├── LaunchImage@3x.png │ │ │ │ │ │ ├── README.md │ │ │ │ │ │ └── Contents.json │ │ │ │ │ └── AppIcon.appiconset │ │ │ │ │ │ ├── Icon-App-20x20@1x.png │ │ │ │ │ │ ├── Icon-App-20x20@2x.png │ │ │ │ │ │ ├── Icon-App-20x20@3x.png │ │ │ │ │ │ ├── Icon-App-29x29@1x.png │ │ │ │ │ │ ├── Icon-App-29x29@2x.png │ │ │ │ │ │ ├── Icon-App-29x29@3x.png │ │ │ │ │ │ ├── Icon-App-40x40@1x.png │ │ │ │ │ │ ├── Icon-App-40x40@2x.png │ │ │ │ │ │ ├── Icon-App-40x40@3x.png │ │ │ │ │ │ ├── Icon-App-60x60@2x.png │ │ │ │ │ │ ├── Icon-App-60x60@3x.png │ │ │ │ │ │ ├── Icon-App-76x76@1x.png │ │ │ │ │ │ ├── Icon-App-76x76@2x.png │ │ │ │ │ │ ├── Icon-App-1024x1024@1x.png │ │ │ │ │ │ └── Icon-App-83.5x83.5@2x.png │ │ │ │ ├── AppDelegate.swift │ │ │ │ ├── Base.lproj │ │ │ │ │ ├── Main.storyboard │ │ │ │ │ └── LaunchScreen.storyboard │ │ │ │ └── Info.plist │ │ │ ├── Flutter │ │ │ │ ├── Debug.xcconfig │ │ │ │ ├── Release.xcconfig │ │ │ │ └── AppFrameworkInfo.plist │ │ │ ├── Runner.xcodeproj │ │ │ │ └── project.xcworkspace │ │ │ │ │ ├── contents.xcworkspacedata │ │ │ │ │ └── xcshareddata │ │ │ │ │ ├── WorkspaceSettings.xcsettings │ │ │ │ │ └── IDEWorkspaceChecks.plist │ │ │ ├── Runner.xcworkspace │ │ │ │ ├── contents.xcworkspacedata │ │ │ │ └── xcshareddata │ │ │ │ │ ├── WorkspaceSettings.xcsettings │ │ │ │ │ └── IDEWorkspaceChecks.plist │ │ │ ├── .gitignore │ │ │ └── Podfile │ │ ├── macos │ │ │ ├── Runner │ │ │ │ ├── Configs │ │ │ │ │ ├── Debug.xcconfig │ │ │ │ │ ├── Release.xcconfig │ │ │ │ │ ├── Warnings.xcconfig │ │ │ │ │ └── AppInfo.xcconfig │ │ │ │ ├── Assets.xcassets │ │ │ │ │ └── AppIcon.appiconset │ │ │ │ │ │ ├── app_icon_16.png │ │ │ │ │ │ ├── app_icon_32.png │ │ │ │ │ │ ├── app_icon_64.png │ │ │ │ │ │ ├── app_icon_1024.png │ │ │ │ │ │ ├── app_icon_128.png │ │ │ │ │ │ ├── app_icon_256.png │ │ │ │ │ │ ├── app_icon_512.png │ │ │ │ │ │ └── Contents.json │ │ │ │ ├── Release.entitlements │ │ │ │ ├── AppDelegate.swift │ │ │ │ ├── DebugProfile.entitlements │ │ │ │ ├── MainFlutterWindow.swift │ │ │ │ └── Info.plist │ │ │ ├── .gitignore │ │ │ ├── Flutter │ │ │ │ ├── Flutter-Debug.xcconfig │ │ │ │ ├── Flutter-Release.xcconfig │ │ │ │ └── GeneratedPluginRegistrant.swift │ │ │ ├── Runner.xcworkspace │ │ │ │ ├── contents.xcworkspacedata │ │ │ │ └── xcshareddata │ │ │ │ │ └── IDEWorkspaceChecks.plist │ │ │ ├── Runner.xcodeproj │ │ │ │ └── project.xcworkspace │ │ │ │ │ └── xcshareddata │ │ │ │ │ └── IDEWorkspaceChecks.plist │ │ │ ├── Podfile.lock │ │ │ └── Podfile │ │ ├── windows │ │ │ ├── runner │ │ │ │ ├── resources │ │ │ │ │ └── app_icon.ico │ │ │ │ ├── resource.h │ │ │ │ ├── utils.h │ │ │ │ ├── runner.exe.manifest │ │ │ │ ├── flutter_window.h │ │ │ │ ├── main.cpp │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── utils.cpp │ │ │ │ └── flutter_window.cpp │ │ │ ├── flutter │ │ │ │ ├── generated_plugin_registrant.cc │ │ │ │ ├── generated_plugin_registrant.h │ │ │ │ └── generated_plugins.cmake │ │ │ └── .gitignore │ │ ├── android │ │ │ ├── gradle.properties │ │ │ ├── app │ │ │ │ ├── src │ │ │ │ │ ├── main │ │ │ │ │ │ ├── res │ │ │ │ │ │ │ ├── mipmap-hdpi │ │ │ │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ │ │ ├── mipmap-mdpi │ │ │ │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ │ │ ├── mipmap-xhdpi │ │ │ │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ │ │ ├── drawable │ │ │ │ │ │ │ │ └── launch_background.xml │ │ │ │ │ │ │ ├── drawable-v21 │ │ │ │ │ │ │ │ └── launch_background.xml │ │ │ │ │ │ │ ├── values │ │ │ │ │ │ │ │ └── styles.xml │ │ │ │ │ │ │ └── values-night │ │ │ │ │ │ │ │ └── styles.xml │ │ │ │ │ │ ├── kotlin │ │ │ │ │ │ │ └── com │ │ │ │ │ │ │ │ └── astrox │ │ │ │ │ │ │ │ └── agent_dart │ │ │ │ │ │ │ │ └── flutter_agent_dart_example │ │ │ │ │ │ │ │ └── MainActivity.kt │ │ │ │ │ │ └── AndroidManifest.xml │ │ │ │ │ ├── debug │ │ │ │ │ │ └── AndroidManifest.xml │ │ │ │ │ └── profile │ │ │ │ │ │ └── AndroidManifest.xml │ │ │ │ └── build.gradle │ │ │ ├── gradle │ │ │ │ └── wrapper │ │ │ │ │ └── gradle-wrapper.properties │ │ │ ├── .gitignore │ │ │ ├── build.gradle │ │ │ └── settings.gradle │ │ ├── README.md │ │ ├── .gitignore │ │ ├── analysis_options.yaml │ │ └── lib │ │ │ └── main.dart │ ├── cargokit │ │ ├── .gitignore │ │ ├── build_tool │ │ │ ├── README.md │ │ │ ├── bin │ │ │ │ └── build_tool.dart │ │ │ ├── lib │ │ │ │ ├── build_tool.dart │ │ │ │ └── src │ │ │ │ │ ├── build_cmake.dart │ │ │ │ │ ├── logging.dart │ │ │ │ │ ├── cargo.dart │ │ │ │ │ ├── build_gradle.dart │ │ │ │ │ ├── environment.dart │ │ │ │ │ └── verify_binaries.dart │ │ │ ├── pubspec.yaml │ │ │ └── analysis_options.yaml │ │ ├── README │ │ ├── cmake │ │ │ └── resolve_symlinks.ps1 │ │ ├── LICENSE │ │ ├── build_pod.sh │ │ ├── run_build_tool.sh │ │ └── run_build_tool.cmd │ ├── android │ │ ├── settings.gradle │ │ ├── src │ │ │ └── main │ │ │ │ └── AndroidManifest.xml │ │ ├── .gitignore │ │ └── build.gradle │ ├── lib │ │ ├── frb.dart │ │ └── agent_dart.dart │ ├── macos │ │ ├── .gitignore │ │ ├── Classes │ │ │ └── dummy_file.c │ │ └── agent_dart.podspec │ ├── ios │ │ ├── Classes │ │ │ └── dummy_file.c │ │ ├── .gitignore │ │ └── agent_dart.podspec │ ├── analysis_options.yaml │ ├── windows │ │ ├── .gitignore │ │ └── CMakeLists.txt │ ├── .gitignore │ ├── pubspec.yaml │ ├── .metadata │ └── agent_dart.iml ├── agent_dart_base │ ├── LICENSE │ ├── README.md │ ├── CHANGELOG.md │ ├── native │ ├── lib │ │ ├── agent │ │ │ ├── crypto │ │ │ │ ├── index.dart │ │ │ │ ├── keystore │ │ │ │ │ ├── key_store.dart │ │ │ │ │ └── key_derivator.dart │ │ │ │ └── random.dart │ │ │ ├── utils │ │ │ │ ├── index.dart │ │ │ │ ├── hash.dart │ │ │ │ └── buffer_pipe.dart │ │ │ ├── canisters │ │ │ │ ├── index.dart │ │ │ │ ├── asset.dart │ │ │ │ ├── asset_idl.dart │ │ │ │ ├── management.dart │ │ │ │ └── management_idl.dart │ │ │ ├── agent │ │ │ │ ├── index.dart │ │ │ │ ├── http │ │ │ │ │ └── transform.dart │ │ │ │ └── factory.dart │ │ │ ├── agent.dart │ │ │ ├── bls.dart │ │ │ ├── errors.dart │ │ │ └── types.dart │ │ ├── frb.dart │ │ ├── principal │ │ │ └── utils │ │ │ │ ├── utils.dart │ │ │ │ ├── sha256.dart │ │ │ │ ├── sha224.dart │ │ │ │ └── base32.dart │ │ ├── identity │ │ │ └── identity.dart │ │ ├── wallet │ │ │ └── wallet.dart │ │ ├── utils │ │ │ ├── map.dart │ │ │ ├── base64.dart │ │ │ └── string.dart │ │ ├── protobuf │ │ │ ├── ic_ledger │ │ │ │ └── pb │ │ │ │ │ └── v1 │ │ │ │ │ ├── types.pbenum.dart │ │ │ │ │ └── types.pbserver.dart │ │ │ └── ic_base_types │ │ │ │ └── pb │ │ │ │ └── v1 │ │ │ │ ├── types.pbenum.dart │ │ │ │ ├── types.pbserver.dart │ │ │ │ └── types.pbjson.dart │ │ └── agent_dart_base.dart │ ├── test │ │ ├── fixture │ │ │ ├── counter │ │ │ │ └── counter.wasm │ │ │ ├── ed25519.pem │ │ │ ├── dfx12.pem │ │ │ └── secp256k1.pem │ │ ├── wallet │ │ │ ├── index.dart │ │ │ ├── pem.dart │ │ │ └── aes.dart │ │ ├── principal │ │ │ ├── index.dart │ │ │ └── utils │ │ │ │ ├── get_crc.dart │ │ │ │ └── base32.dart │ │ ├── identity │ │ │ ├── identity.dart │ │ │ ├── schnorr.dart │ │ │ └── p256.dart │ │ ├── utils │ │ │ └── utils_test.dart │ │ ├── agent │ │ │ ├── agent.dart │ │ │ ├── utils │ │ │ │ ├── bls.dart │ │ │ │ └── hash.dart │ │ │ ├── actor.dart │ │ │ ├── cbor.dart │ │ │ ├── polling.dart │ │ │ ├── http │ │ │ │ └── http.dart │ │ │ └── request_id.dart │ │ ├── agent_dart_base_test.dart │ │ ├── authentication │ │ │ └── authentication.dart │ │ └── test_utils.dart │ ├── analysis_options.yaml │ ├── scripts │ │ └── compile_protobuf.sh │ ├── agent_dart_base.iml │ ├── protobuf │ │ └── ic_base_types │ │ │ └── pb │ │ │ └── v1 │ │ │ └── types.proto │ └── pubspec.yaml └── agent_dart_ffi │ ├── LICENSE │ ├── README.md │ ├── CHANGELOG.md │ ├── analysis_options.yaml │ ├── flutter_rust_bridge.yaml │ ├── native │ ├── agent_dart │ │ ├── src │ │ │ ├── bls │ │ │ │ ├── mod.rs │ │ │ │ ├── arch.rs │ │ │ │ ├── bls12381 │ │ │ │ │ └── mod.rs │ │ │ │ ├── README.md │ │ │ │ └── mod copy.rs │ │ │ ├── errors.rs │ │ │ ├── bls_ffi.rs │ │ │ ├── lib.rs │ │ │ ├── keyring.rs │ │ │ └── ed25519.rs │ │ └── Cargo.toml │ ├── cbindgen.toml │ └── ed_compact │ │ ├── Cargo.toml │ │ └── src │ │ └── error.rs │ ├── lib │ ├── agent_dart_ffi.dart │ └── src │ │ ├── lib.dart │ │ ├── schnorr.dart │ │ ├── p256.dart │ │ └── secp256k1.dart │ ├── pubspec.yaml │ └── agent_dart_ffi.iml ├── CODEOWNERS ├── pubspec.yaml ├── scripts └── replace_symlinks_before_publish.sh ├── .metadata ├── Cargo.toml ├── .github ├── ISSUE_TEMPLATE │ └── bounty.md └── workflows │ ├── publish.yml │ └── runnable.yml ├── .gitignore ├── agent_dart_workspace.iml ├── melos.yaml ├── analysis_options.yaml └── LICENSE /packages/agent_dart/LICENSE: -------------------------------------------------------------------------------- 1 | ../../LICENSE -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @AstroxNetwork/flutter-dart 2 | -------------------------------------------------------------------------------- /packages/agent_dart/README.md: -------------------------------------------------------------------------------- 1 | ../../README.md -------------------------------------------------------------------------------- /packages/agent_dart_base/LICENSE: -------------------------------------------------------------------------------- 1 | ../../LICENSE -------------------------------------------------------------------------------- /packages/agent_dart_ffi/LICENSE: -------------------------------------------------------------------------------- 1 | ../../LICENSE -------------------------------------------------------------------------------- /packages/agent_dart_ffi/README.md: -------------------------------------------------------------------------------- 1 | ../../README.md -------------------------------------------------------------------------------- /packages/agent_dart/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ../../CHANGELOG.md -------------------------------------------------------------------------------- /packages/agent_dart/linux/.gitignore: -------------------------------------------------------------------------------- 1 | *.tar.gz 2 | -------------------------------------------------------------------------------- /packages/agent_dart/native: -------------------------------------------------------------------------------- 1 | ../agent_dart_ffi/native -------------------------------------------------------------------------------- /packages/agent_dart_base/README.md: -------------------------------------------------------------------------------- 1 | ../../README.md -------------------------------------------------------------------------------- /packages/agent_dart_base/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ../../CHANGELOG.md -------------------------------------------------------------------------------- /packages/agent_dart_base/native: -------------------------------------------------------------------------------- 1 | ../agent_dart_ffi/native -------------------------------------------------------------------------------- /packages/agent_dart_ffi/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ../../CHANGELOG.md -------------------------------------------------------------------------------- /packages/agent_dart/example/linux/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ephemeral 2 | -------------------------------------------------------------------------------- /packages/agent_dart/cargokit/.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | .dart_tool 3 | *.iml 4 | -------------------------------------------------------------------------------- /packages/agent_dart/android/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'agent_dart' 2 | -------------------------------------------------------------------------------- /packages/agent_dart/lib/frb.dart: -------------------------------------------------------------------------------- 1 | export 'package:agent_dart_base/frb.dart'; 2 | -------------------------------------------------------------------------------- /packages/agent_dart/lib/agent_dart.dart: -------------------------------------------------------------------------------- 1 | export 'package:agent_dart_base/agent_dart_base.dart'; 2 | -------------------------------------------------------------------------------- /packages/agent_dart/macos/.gitignore: -------------------------------------------------------------------------------- 1 | Flutter/ 2 | Runner/ 3 | Frameworks/* 4 | !Frameworks/.gitkeep -------------------------------------------------------------------------------- /packages/agent_dart/example/ios/Runner/Runner-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | #import "GeneratedPluginRegistrant.h" 2 | -------------------------------------------------------------------------------- /packages/agent_dart/ios/Classes/dummy_file.c: -------------------------------------------------------------------------------- 1 | // This is an empty file to force CocoaPods to create a framework. 2 | -------------------------------------------------------------------------------- /packages/agent_dart/macos/Classes/dummy_file.c: -------------------------------------------------------------------------------- 1 | // This is an empty file to force CocoaPods to create a framework. 2 | -------------------------------------------------------------------------------- /packages/agent_dart_base/lib/agent/crypto/index.dart: -------------------------------------------------------------------------------- 1 | export 'keystore/key_store.dart'; 2 | export 'random.dart'; 3 | -------------------------------------------------------------------------------- /packages/agent_dart_base/lib/agent/utils/index.dart: -------------------------------------------------------------------------------- 1 | export 'buffer_pipe.dart'; 2 | export 'hash.dart'; 3 | export 'leb128.dart'; 4 | -------------------------------------------------------------------------------- /packages/agent_dart_base/lib/frb.dart: -------------------------------------------------------------------------------- 1 | export 'package:agent_dart_ffi/agent_dart_ffi.dart' 2 | show AnyhowException, ExternalLibrary; 3 | -------------------------------------------------------------------------------- /packages/agent_dart_ffi/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | include: ../../analysis_options.yaml 2 | 3 | analyzer: 4 | exclude: 5 | - 'lib/src/**' 6 | -------------------------------------------------------------------------------- /packages/agent_dart/example/macos/Runner/Configs/Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include "../../Flutter/Flutter-Debug.xcconfig" 2 | #include "Warnings.xcconfig" 3 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: agent_dart_workspace 2 | 3 | environment: 4 | sdk: ^3.4.0 5 | 6 | dev_dependencies: 7 | melos: ^6.0.0 8 | lints: any 9 | -------------------------------------------------------------------------------- /packages/agent_dart/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | include: ../../analysis_options.yaml 2 | 3 | analyzer: 4 | exclude: 5 | - cargokit/build_tool/** 6 | -------------------------------------------------------------------------------- /packages/agent_dart/example/macos/Runner/Configs/Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include "../../Flutter/Flutter-Release.xcconfig" 2 | #include "Warnings.xcconfig" 3 | -------------------------------------------------------------------------------- /packages/agent_dart/example/ios/Flutter/Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" 2 | #include "Generated.xcconfig" 3 | -------------------------------------------------------------------------------- /packages/agent_dart/example/ios/Flutter/Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" 2 | #include "Generated.xcconfig" 3 | -------------------------------------------------------------------------------- /packages/agent_dart_base/lib/agent/canisters/index.dart: -------------------------------------------------------------------------------- 1 | export 'asset.dart'; 2 | export 'asset_idl.dart'; 3 | export 'management.dart'; 4 | export 'management_idl.dart'; 5 | -------------------------------------------------------------------------------- /packages/agent_dart/example/macos/.gitignore: -------------------------------------------------------------------------------- 1 | # Flutter-related 2 | **/Flutter/ephemeral/ 3 | **/Pods/ 4 | 5 | # Xcode-related 6 | **/dgph 7 | **/xcuserdata/ 8 | DerivedData/ 9 | -------------------------------------------------------------------------------- /packages/agent_dart_base/test/fixture/counter/counter.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AstroxNetwork/agent_dart/HEAD/packages/agent_dart_base/test/fixture/counter/counter.wasm -------------------------------------------------------------------------------- /packages/agent_dart_ffi/flutter_rust_bridge.yaml: -------------------------------------------------------------------------------- 1 | dart_entrypoint_class_name: AgentDart 2 | rust_input: crate::api 3 | rust_root: native/agent_dart 4 | dart_output: lib/src 5 | -------------------------------------------------------------------------------- /packages/agent_dart/android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | -------------------------------------------------------------------------------- /packages/agent_dart/example/windows/runner/resources/app_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AstroxNetwork/agent_dart/HEAD/packages/agent_dart/example/windows/runner/resources/app_icon.ico -------------------------------------------------------------------------------- /packages/agent_dart/example/macos/Flutter/Flutter-Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" 2 | #include "ephemeral/Flutter-Generated.xcconfig" 3 | -------------------------------------------------------------------------------- /packages/agent_dart_base/lib/principal/utils/utils.dart: -------------------------------------------------------------------------------- 1 | library principal_utils; 2 | 3 | export 'base32.dart'; 4 | export 'get_crc.dart'; 5 | export 'sha224.dart'; 6 | export 'sha256.dart'; 7 | -------------------------------------------------------------------------------- /packages/agent_dart/example/android/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx4G -XX:MaxMetaspaceSize=2G -XX:+HeapDumpOnOutOfMemoryError 2 | android.useAndroidX=true 3 | android.enableJetifier=true 4 | -------------------------------------------------------------------------------- /packages/agent_dart/example/macos/Flutter/Flutter-Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" 2 | #include "ephemeral/Flutter-Generated.xcconfig" 3 | -------------------------------------------------------------------------------- /packages/agent_dart_base/lib/identity/identity.dart: -------------------------------------------------------------------------------- 1 | export 'delegation.dart'; 2 | export 'der.dart'; 3 | export 'ed25519.dart'; 4 | export 'p256.dart'; 5 | export 'schnorr.dart'; 6 | export 'secp256k1.dart'; 7 | -------------------------------------------------------------------------------- /packages/agent_dart/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AstroxNetwork/agent_dart/HEAD/packages/agent_dart/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /packages/agent_dart/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AstroxNetwork/agent_dart/HEAD/packages/agent_dart/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /packages/agent_dart/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AstroxNetwork/agent_dart/HEAD/packages/agent_dart/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /packages/agent_dart/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AstroxNetwork/agent_dart/HEAD/packages/agent_dart/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /packages/agent_dart/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AstroxNetwork/agent_dart/HEAD/packages/agent_dart/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /packages/agent_dart_base/lib/wallet/wallet.dart: -------------------------------------------------------------------------------- 1 | export 'hashing.dart'; 2 | export 'keysmith.dart'; 3 | export 'ledger.dart'; 4 | export 'pem.dart'; 5 | export 'phrase.dart'; 6 | export 'rosetta.dart'; 7 | export 'signer.dart'; 8 | -------------------------------------------------------------------------------- /packages/agent_dart/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AstroxNetwork/agent_dart/HEAD/packages/agent_dart/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png -------------------------------------------------------------------------------- /packages/agent_dart/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AstroxNetwork/agent_dart/HEAD/packages/agent_dart/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png -------------------------------------------------------------------------------- /packages/agent_dart/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AstroxNetwork/agent_dart/HEAD/packages/agent_dart/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png -------------------------------------------------------------------------------- /packages/agent_dart/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AstroxNetwork/agent_dart/HEAD/packages/agent_dart/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png -------------------------------------------------------------------------------- /packages/agent_dart_base/test/fixture/ed25519.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MFMCAQEwBQYDK2VwBCIEIJTpTCaKwi0FtuE9+We+6QynpAtnbqqD9U009RGKx2uw 3 | oSMDIQBhrxKQuKf45AneI1BfAGENcHvYwJrVpv2xFoQ/A9kwvg== 4 | -----END PRIVATE KEY----- 5 | -------------------------------------------------------------------------------- /packages/agent_dart/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AstroxNetwork/agent_dart/HEAD/packages/agent_dart/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png -------------------------------------------------------------------------------- /packages/agent_dart/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AstroxNetwork/agent_dart/HEAD/packages/agent_dart/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png -------------------------------------------------------------------------------- /packages/agent_dart/example/linux/main.cc: -------------------------------------------------------------------------------- 1 | #include "my_application.h" 2 | 3 | int main(int argc, char** argv) { 4 | g_autoptr(MyApplication) app = my_application_new(); 5 | return g_application_run(G_APPLICATION(app), argc, argv); 6 | } 7 | -------------------------------------------------------------------------------- /packages/agent_dart/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AstroxNetwork/agent_dart/HEAD/packages/agent_dart/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png -------------------------------------------------------------------------------- /packages/agent_dart/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AstroxNetwork/agent_dart/HEAD/packages/agent_dart/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png -------------------------------------------------------------------------------- /packages/agent_dart/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AstroxNetwork/agent_dart/HEAD/packages/agent_dart/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png -------------------------------------------------------------------------------- /packages/agent_dart/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AstroxNetwork/agent_dart/HEAD/packages/agent_dart/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png -------------------------------------------------------------------------------- /packages/agent_dart/android/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | /.cxx 10 | 11 | # Ignore Rust binaries 12 | src/main/jniLibs/ 13 | *.tar.gz -------------------------------------------------------------------------------- /packages/agent_dart/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AstroxNetwork/agent_dart/HEAD/packages/agent_dart/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png -------------------------------------------------------------------------------- /packages/agent_dart/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AstroxNetwork/agent_dart/HEAD/packages/agent_dart/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png -------------------------------------------------------------------------------- /packages/agent_dart/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AstroxNetwork/agent_dart/HEAD/packages/agent_dart/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png -------------------------------------------------------------------------------- /packages/agent_dart/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AstroxNetwork/agent_dart/HEAD/packages/agent_dart/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png -------------------------------------------------------------------------------- /packages/agent_dart/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AstroxNetwork/agent_dart/HEAD/packages/agent_dart/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png -------------------------------------------------------------------------------- /packages/agent_dart/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AstroxNetwork/agent_dart/HEAD/packages/agent_dart/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png -------------------------------------------------------------------------------- /packages/agent_dart/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AstroxNetwork/agent_dart/HEAD/packages/agent_dart/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png -------------------------------------------------------------------------------- /packages/agent_dart/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AstroxNetwork/agent_dart/HEAD/packages/agent_dart/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png -------------------------------------------------------------------------------- /packages/agent_dart/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AstroxNetwork/agent_dart/HEAD/packages/agent_dart/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png -------------------------------------------------------------------------------- /packages/agent_dart/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AstroxNetwork/agent_dart/HEAD/packages/agent_dart/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png -------------------------------------------------------------------------------- /packages/agent_dart/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AstroxNetwork/agent_dart/HEAD/packages/agent_dart/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png -------------------------------------------------------------------------------- /packages/agent_dart/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AstroxNetwork/agent_dart/HEAD/packages/agent_dart/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png -------------------------------------------------------------------------------- /packages/agent_dart/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AstroxNetwork/agent_dart/HEAD/packages/agent_dart/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png -------------------------------------------------------------------------------- /packages/agent_dart_base/lib/agent/agent/index.dart: -------------------------------------------------------------------------------- 1 | export 'api.dart'; 2 | export 'factory.dart'; 3 | export 'http/fetch.dart'; 4 | export 'http/index.dart'; 5 | export 'http/transform.dart'; 6 | export 'http/types.dart'; 7 | export 'proxy.dart'; 8 | -------------------------------------------------------------------------------- /packages/agent_dart/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /packages/agent_dart/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AstroxNetwork/agent_dart/HEAD/packages/agent_dart/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png -------------------------------------------------------------------------------- /packages/agent_dart/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AstroxNetwork/agent_dart/HEAD/packages/agent_dart/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png -------------------------------------------------------------------------------- /packages/agent_dart_base/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | include: ../../analysis_options.yaml 2 | 3 | analyzer: 4 | exclude: 5 | - lib/**.freezed.dart 6 | - lib/**.g.dart 7 | 8 | linter: 9 | rules: 10 | constant_identifier_names: false 11 | -------------------------------------------------------------------------------- /packages/agent_dart/example/macos/Flutter/GeneratedPluginRegistrant.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | import FlutterMacOS 6 | import Foundation 7 | 8 | 9 | func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { 10 | } 11 | -------------------------------------------------------------------------------- /packages/agent_dart_base/test/fixture/dfx12.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN EC PRIVATE KEY----- 2 | MHQCAQEEICJxApEbuZznKFpV+VKACRK30i6+7u5Z13/DOl18cIC+oAcGBSuBBAAK 3 | oUQDQgAEPas6Iag4TUx+Uop+3NhE6s3FlayFtbwdhRVjvOar0kPTfE/N8N6btRnd 4 | 74ly5xXEBNSXiENyxhEuzOZrIWMCNQ== 5 | -----END EC PRIVATE KEY----- -------------------------------------------------------------------------------- /packages/agent_dart/example/linux/flutter/generated_plugin_registrant.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #include "generated_plugin_registrant.h" 8 | 9 | 10 | void fl_register_plugins(FlPluginRegistry* registry) { 11 | } 12 | -------------------------------------------------------------------------------- /packages/agent_dart_base/test/wallet/index.dart: -------------------------------------------------------------------------------- 1 | import '../test_utils.dart'; 2 | import 'aes.dart' as aes; 3 | import 'pem.dart' as pem; 4 | import 'signer.dart' as signer; 5 | 6 | void main() { 7 | ffiInit(); 8 | aes.main(); 9 | pem.main(); 10 | signer.main(); 11 | } 12 | -------------------------------------------------------------------------------- /packages/agent_dart/example/android/app/src/main/kotlin/com/astrox/agent_dart/flutter_agent_dart_example/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.astrox.agent_dart.flutter_agent_dart_example 2 | 3 | import io.flutter.embedding.android.FlutterActivity 4 | 5 | class MainActivity: FlutterActivity() { 6 | } 7 | -------------------------------------------------------------------------------- /packages/agent_dart/example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip 6 | -------------------------------------------------------------------------------- /packages/agent_dart/example/windows/flutter/generated_plugin_registrant.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #include "generated_plugin_registrant.h" 8 | 9 | 10 | void RegisterPlugins(flutter::PluginRegistry* registry) { 11 | } 12 | -------------------------------------------------------------------------------- /packages/agent_dart_ffi/native/agent_dart/src/bls/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod aes; 2 | pub mod arch; 3 | pub mod bls12381; 4 | pub mod gcm; 5 | pub mod hash256; 6 | pub mod hash384; 7 | pub mod hash512; 8 | pub mod hmac; 9 | pub mod nhs; 10 | pub mod rand; 11 | pub mod sha3; 12 | pub mod share; 13 | -------------------------------------------------------------------------------- /packages/agent_dart_base/lib/agent/canisters/asset.dart: -------------------------------------------------------------------------------- 1 | import '../actor.dart'; 2 | import 'asset_idl.dart'; 3 | 4 | /// Create a management canister actor. 5 | /// @param config 6 | CanisterActor createAssetCanisterActor(ActorConfig config) { 7 | return Actor.createActor(assetIDL(), config); 8 | } 9 | -------------------------------------------------------------------------------- /scripts/replace_symlinks_before_publish.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cd packages 4 | rm agent_dart/native agent_dart_base/native 5 | cp -r agent_dart_ffi/native agent_dart/native 6 | git rm --cached agent_dart/native 7 | cp -r agent_dart_ffi/native agent_dart_base/native 8 | git rm --cached agent_dart_base/native 9 | -------------------------------------------------------------------------------- /packages/agent_dart_ffi/native/cbindgen.toml: -------------------------------------------------------------------------------- 1 | language = "C" 2 | autogen_warning = "// NOTE: Append the lines below to ios/Classes/Plugin.h" 3 | #namespace = "ffi" 4 | #include_guard = "CBINDGEN_BINDINGS_H" 5 | 6 | [defines] 7 | "target_os = ios" = "TARGET_OS_IOS" 8 | "target_os = macos" = "TARGET_OS_MACOS" 9 | -------------------------------------------------------------------------------- /packages/agent_dart/example/macos/Runner/Release.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /packages/agent_dart_base/test/principal/index.dart: -------------------------------------------------------------------------------- 1 | import '../test_utils.dart'; 2 | import 'principal.dart' as principal; 3 | import 'utils/base32.dart' as base32; 4 | import 'utils/get_crc.dart' as get_crc; 5 | 6 | void main() { 7 | ffiInit(); 8 | principal.main(); 9 | base32.main(); 10 | get_crc.main(); 11 | } 12 | -------------------------------------------------------------------------------- /packages/agent_dart/example/ios/Runner.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /packages/agent_dart/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreviewsEnabled 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /packages/agent_dart/example/macos/Runner.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /packages/agent_dart_base/scripts/compile_protobuf.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cd $(dirname "$0") 4 | cd ../ 5 | # brew install cproto 6 | # dart pub global activate protoc_plugin 7 | protoc --proto_path=protobuf \ 8 | --dart_out=lib/protobuf \ 9 | protobuf/ic_base_types/pb/v1/types.proto \ 10 | protobuf/ic_ledger/pb/v1/types.proto 11 | -------------------------------------------------------------------------------- /packages/agent_dart/cargokit/build_tool/README.md: -------------------------------------------------------------------------------- 1 | /// This is copied from Cargokit (which is the official way to use it currently) 2 | /// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin 3 | 4 | A sample command-line application with an entrypoint in `bin/`, library code 5 | in `lib/`, and example unit test in `test/`. 6 | -------------------------------------------------------------------------------- /packages/agent_dart/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /packages/agent_dart/example/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled and should not be manually edited. 5 | 6 | version: 7 | revision: fa5883b78e566877613ad1ccb48dd92075cb5c23 8 | channel: dev 9 | 10 | project_type: plugin 11 | -------------------------------------------------------------------------------- /packages/agent_dart/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreviewsEnabled 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | resolver = "1" 3 | members = [ 4 | "packages/agent_dart_ffi/native/agent_dart", 5 | "packages/agent_dart_ffi/native/ed_compact", 6 | ] 7 | exclude = [ 8 | "packages/agent_dart/native", 9 | "packages/agent_dart_base/native", 10 | ] 11 | 12 | [profile.release] 13 | debug = false 14 | lto = true 15 | opt-level = "z" 16 | -------------------------------------------------------------------------------- /packages/agent_dart/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /packages/agent_dart/example/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /packages/agent_dart_base/test/fixture/secp256k1.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN EC PARAMETERS----- 2 | BgUrgQQACg== 3 | -----END EC PARAMETERS----- 4 | -----BEGIN EC PRIVATE KEY----- 5 | MHQCAQEEIH0ncVBfM91+tPxqjpVRjphrnYlEizak78qPZQGZB2YQoAcGBSuBBAAK 6 | oUQDQgAELWzLmnTEX6IyczLvVSoDG7ZBNbqfxbb+05VBJq72E8tvw+/RnWx/kHV+ 7 | VTKpW9pG5S4LFmw8ukzGI+euAFpFAg== 8 | -----END EC PRIVATE KEY----- 9 | -------------------------------------------------------------------------------- /packages/agent_dart/cargokit/build_tool/bin/build_tool.dart: -------------------------------------------------------------------------------- 1 | /// This is copied from Cargokit (which is the official way to use it currently) 2 | /// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin 3 | 4 | import 'package:build_tool/build_tool.dart' as build_tool; 5 | 6 | void main(List arguments) { 7 | build_tool.runMain(arguments); 8 | } 9 | -------------------------------------------------------------------------------- /packages/agent_dart/cargokit/build_tool/lib/build_tool.dart: -------------------------------------------------------------------------------- 1 | /// This is copied from Cargokit (which is the official way to use it currently) 2 | /// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin 3 | 4 | import 'src/build_tool.dart' as build_tool; 5 | 6 | Future runMain(List args) async { 7 | return build_tool.runMain(args); 8 | } 9 | -------------------------------------------------------------------------------- /packages/agent_dart/example/android/.gitignore: -------------------------------------------------------------------------------- 1 | gradle-wrapper.jar 2 | /.gradle 3 | /captures/ 4 | /gradlew 5 | /gradlew.bat 6 | /local.properties 7 | GeneratedPluginRegistrant.java 8 | 9 | # Remember to never publicly share your keystore. 10 | # See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app 11 | key.properties 12 | **/*.keystore 13 | **/*.jks 14 | -------------------------------------------------------------------------------- /packages/agent_dart_ffi/lib/agent_dart_ffi.dart: -------------------------------------------------------------------------------- 1 | export 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart' 2 | show AnyhowException, ExternalLibrary; 3 | 4 | export 'src/api.dart'; 5 | export 'src/frb_generated.dart' show AgentDart; 6 | export 'src/lib.dart'; 7 | export 'src/p256.dart'; 8 | export 'src/schnorr.dart'; 9 | export 'src/secp256k1.dart'; 10 | export 'src/types.dart'; 11 | -------------------------------------------------------------------------------- /packages/agent_dart/example/windows/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ephemeral/ 2 | 3 | # Visual Studio user-specific files. 4 | *.suo 5 | *.user 6 | *.userosscache 7 | *.sln.docstates 8 | 9 | # Visual Studio build-related files. 10 | x64/ 11 | x86/ 12 | 13 | # Visual Studio cache files 14 | # files ending in .cache can be ignored 15 | *.[Cc]ache 16 | # but keep track of directories ending in .cache 17 | !*.[Cc]ache/ 18 | -------------------------------------------------------------------------------- /packages/agent_dart/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md: -------------------------------------------------------------------------------- 1 | # Launch Screen Assets 2 | 3 | You can customize the launch screen with your own desired assets by replacing the image files in this directory. 4 | 5 | You can also do it by opening your Flutter project's Xcode project with `open ios/Runner.xcworkspace`, selecting `Runner/Assets.xcassets` in the Project Navigator and dropping in the desired images. -------------------------------------------------------------------------------- /packages/agent_dart/example/macos/Runner/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | import FlutterMacOS 3 | 4 | @main 5 | class AppDelegate: FlutterAppDelegate { 6 | override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { 7 | return true 8 | } 9 | 10 | override func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool { 11 | return true 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/agent_dart_base/lib/agent/agent.dart: -------------------------------------------------------------------------------- 1 | export './agent/index.dart'; 2 | export './canisters/index.dart'; 3 | export './crypto/index.dart'; 4 | export './polling/polling.dart'; 5 | export './utils/index.dart'; 6 | 7 | export 'actor.dart'; 8 | export 'auth.dart'; 9 | export 'bls.dart'; 10 | export 'cbor.dart'; 11 | export 'certificate.dart'; 12 | export 'errors.dart'; 13 | export 'request_id.dart'; 14 | export 'types.dart'; 15 | -------------------------------------------------------------------------------- /packages/agent_dart/example/linux/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 8 | #define GENERATED_PLUGIN_REGISTRANT_ 9 | 10 | #include 11 | 12 | // Registers Flutter plugins. 13 | void fl_register_plugins(FlPluginRegistry* registry); 14 | 15 | #endif // GENERATED_PLUGIN_REGISTRANT_ 16 | -------------------------------------------------------------------------------- /packages/agent_dart/example/windows/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 8 | #define GENERATED_PLUGIN_REGISTRANT_ 9 | 10 | #include 11 | 12 | // Registers Flutter plugins. 13 | void RegisterPlugins(flutter::PluginRegistry* registry); 14 | 15 | #endif // GENERATED_PLUGIN_REGISTRANT_ 16 | -------------------------------------------------------------------------------- /packages/agent_dart_base/test/identity/identity.dart: -------------------------------------------------------------------------------- 1 | import '../test_utils.dart'; 2 | import 'delegation.dart' as delegation; 3 | import 'ed25519.dart' as ed25519; 4 | import 'p256.dart' as p256; 5 | import 'schnorr.dart' as schnorr; 6 | import 'secp256k1.dart' as secp256k1; 7 | 8 | void main() { 9 | ffiInit(); 10 | delegation.main(); 11 | ed25519.main(); 12 | p256.main(); 13 | schnorr.main(); 14 | secp256k1.main(); 15 | } 16 | -------------------------------------------------------------------------------- /packages/agent_dart_ffi/native/agent_dart/src/errors.rs: -------------------------------------------------------------------------------- 1 | /// Error information 2 | use serde::*; 3 | #[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Serialize)] 4 | pub struct ErrorInfo { 5 | /// Error code 6 | pub code: u32, 7 | /// Error message 8 | pub message: String, 9 | } 10 | 11 | impl ErrorInfo { 12 | pub fn to_json(&self) -> String { 13 | serde_json::to_string(self).unwrap() 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /packages/agent_dart/example/android/build.gradle: -------------------------------------------------------------------------------- 1 | allprojects { 2 | repositories { 3 | google() 4 | mavenCentral() 5 | } 6 | } 7 | 8 | rootProject.buildDir = '../build' 9 | subprojects { 10 | project.buildDir = "${rootProject.buildDir}/${project.name}" 11 | } 12 | subprojects { 13 | project.evaluationDependsOn(':app') 14 | } 15 | 16 | tasks.register("clean", Delete) { 17 | delete rootProject.buildDir 18 | } 19 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bounty.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bounty 3 | about: Bounty Spec 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | # Description 11 | [a short paragraph to describe the bounty] 12 | 13 | ## Context 14 | [background and why] 15 | 16 | # Acceptance Criteria 17 | * [ ] [description on how this bounty can be completed] 18 | * [ ] [quantifiable criteria is better] 19 | 20 | # Reward 21 | [amount of tokens in ICP/ETH/Crypto] -------------------------------------------------------------------------------- /packages/agent_dart/example/macos/Runner/DebugProfile.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | com.apple.security.cs.allow-jit 8 | 9 | com.apple.security.network.server 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /packages/agent_dart_base/lib/utils/map.dart: -------------------------------------------------------------------------------- 1 | Map makeBigIntToString(Map input) { 2 | final newX = {}; 3 | for (final index in input.entries) { 4 | newX.putIfAbsent( 5 | index.key is BigInt ? index.key.toString() : index.key, 6 | () => index.value is BigInt 7 | ? index.value.toString() 8 | : index.value is Map 9 | ? makeBigIntToString(index.value) 10 | : index.value, 11 | ); 12 | } 13 | return newX; 14 | } 15 | -------------------------------------------------------------------------------- /packages/agent_dart/windows/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ 2 | 3 | # Visual Studio user-specific files. 4 | *.suo 5 | *.user 6 | *.userosscache 7 | *.sln.docstates 8 | 9 | # Visual Studio build-related files. 10 | x64/ 11 | x86/ 12 | 13 | # Visual Studio cache files 14 | # files ending in .cache can be ignored 15 | *.[Cc]ache 16 | # but keep track of directories ending in .cache 17 | !*.[Cc]ache/ 18 | 19 | # Set up as allowlist 20 | * 21 | 22 | # Allowed files 23 | !.gitignore 24 | !CMakeLists.txt -------------------------------------------------------------------------------- /packages/agent_dart_ffi/lib/src/lib.dart: -------------------------------------------------------------------------------- 1 | // This file is automatically generated, so please do not edit it. 2 | // Generated by `flutter_rust_bridge`@ 2.0.0. 3 | 4 | // ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import 5 | 6 | import 'frb_generated.dart'; 7 | import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart'; 8 | 9 | // Rust type: RustOpaqueMoi 10 | abstract class WalletInstance implements RustOpaqueInterface {} 11 | -------------------------------------------------------------------------------- /packages/agent_dart/example/ios/Runner/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import Flutter 3 | 4 | @main 5 | @objc class AppDelegate: FlutterAppDelegate { 6 | override func application( 7 | _ application: UIApplication, 8 | didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? 9 | ) -> Bool { 10 | GeneratedPluginRegistrant.register(with: self) 11 | return super.application(application, didFinishLaunchingWithOptions: launchOptions) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/agent_dart_base/lib/protobuf/ic_ledger/pb/v1/types.pbenum.dart: -------------------------------------------------------------------------------- 1 | // 2 | // Generated code. Do not modify. 3 | // source: ic_ledger/pb/v1/types.proto 4 | // 5 | // @dart = 3.3 6 | 7 | // ignore_for_file: annotate_overrides, camel_case_types, comment_references 8 | // ignore_for_file: constant_identifier_names, library_prefixes 9 | // ignore_for_file: non_constant_identifier_names, prefer_final_fields 10 | // ignore_for_file: unnecessary_import, unnecessary_this, unused_import 11 | 12 | -------------------------------------------------------------------------------- /packages/agent_dart_base/test/utils/utils_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:agent_dart_base/agent_dart_base.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | import '../test_utils.dart'; 5 | import 'is.dart' as is_test; 6 | 7 | void main() { 8 | ffiInit(); 9 | is_test.main(); 10 | 11 | test('Hex string to u8', () { 12 | final u8 = 'efcdab000000000001'.toU8a(); 13 | expect(u8.length, equals(9)); 14 | expect(u8.toString(), '[239, 205, 171, 0, 0, 0, 0, 0, 1]'); 15 | }); 16 | } 17 | -------------------------------------------------------------------------------- /packages/agent_dart_base/lib/protobuf/ic_base_types/pb/v1/types.pbenum.dart: -------------------------------------------------------------------------------- 1 | // 2 | // Generated code. Do not modify. 3 | // source: ic_base_types/pb/v1/types.proto 4 | // 5 | // @dart = 3.3 6 | 7 | // ignore_for_file: annotate_overrides, camel_case_types, comment_references 8 | // ignore_for_file: constant_identifier_names, library_prefixes 9 | // ignore_for_file: non_constant_identifier_names, prefer_final_fields 10 | // ignore_for_file: unnecessary_import, unnecessary_this, unused_import 11 | 12 | -------------------------------------------------------------------------------- /packages/agent_dart/example/linux/my_application.h: -------------------------------------------------------------------------------- 1 | #ifndef FLUTTER_MY_APPLICATION_H_ 2 | #define FLUTTER_MY_APPLICATION_H_ 3 | 4 | #include 5 | 6 | G_DECLARE_FINAL_TYPE(MyApplication, my_application, MY, APPLICATION, 7 | GtkApplication) 8 | 9 | /** 10 | * my_application_new: 11 | * 12 | * Creates a new Flutter-based application. 13 | * 14 | * Returns: a new #MyApplication. 15 | */ 16 | MyApplication* my_application_new(); 17 | 18 | #endif // FLUTTER_MY_APPLICATION_H_ 19 | -------------------------------------------------------------------------------- /packages/agent_dart/example/macos/Runner/MainFlutterWindow.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | import FlutterMacOS 3 | 4 | class MainFlutterWindow: NSWindow { 5 | override func awakeFromNib() { 6 | let flutterViewController = FlutterViewController.init() 7 | let windowFrame = self.frame 8 | self.contentViewController = flutterViewController 9 | self.setFrame(windowFrame, display: true) 10 | 11 | RegisterGeneratedPlugins(registry: flutterViewController) 12 | 13 | super.awakeFromNib() 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /packages/agent_dart/example/android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /packages/agent_dart/example/android/app/src/profile/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /packages/agent_dart/example/windows/runner/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by Runner.rc 4 | // 5 | #define IDI_APP_ICON 101 6 | 7 | // Next default values for new objects 8 | // 9 | #ifdef APSTUDIO_INVOKED 10 | #ifndef APSTUDIO_READONLY_SYMBOLS 11 | #define _APS_NEXT_RESOURCE_VALUE 102 12 | #define _APS_NEXT_COMMAND_VALUE 40001 13 | #define _APS_NEXT_CONTROL_VALUE 1001 14 | #define _APS_NEXT_SYMED_VALUE 101 15 | #endif 16 | #endif 17 | -------------------------------------------------------------------------------- /packages/agent_dart_base/test/agent/agent.dart: -------------------------------------------------------------------------------- 1 | import '../test_utils.dart'; 2 | import 'actor.dart' as actor; 3 | import 'cbor.dart' as cbor; 4 | import 'certificate.dart' as certificate; 5 | import 'request_id.dart' as request_id; 6 | import 'utils/bls.dart' as bls; 7 | import 'utils/hash.dart' as hash; 8 | import 'utils/leb128.dart' as leb128; 9 | 10 | void main() { 11 | ffiInit(); 12 | actor.main(); 13 | cbor.main(); 14 | certificate.main(); 15 | request_id.main(); 16 | bls.main(); 17 | hash.main(); 18 | leb128.main(); 19 | } 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .dart_tool/ 3 | .idea/ 4 | .vscode/ 5 | 6 | .packages 7 | .pub/ 8 | 9 | build/ 10 | 11 | .env 12 | 13 | # Miscellaneous 14 | *.class 15 | *.log 16 | *.pyc 17 | *.swp 18 | .atom/ 19 | .buildlog/ 20 | .history 21 | .svn/ 22 | 23 | # IntelliJ related 24 | *.ipr 25 | *.iws 26 | 27 | # Flutter/Dart/Pub related 28 | pubspec_overrides.yaml 29 | **/doc/api/ 30 | .pub-cache/ 31 | .flutter-plugins 32 | .flutter-plugins-dependencies 33 | **/pubspec.lock 34 | 35 | # build files 36 | /platform-build/ 37 | /target/ 38 | /platform-build 39 | -------------------------------------------------------------------------------- /packages/agent_dart/cargokit/README: -------------------------------------------------------------------------------- 1 | /// This is copied from Cargokit (which is the official way to use it currently) 2 | /// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin 3 | 4 | Experimental repository to provide glue for seamlessly integrating cargo build 5 | with flutter plugins and packages. 6 | 7 | See https://matejknopp.com/post/flutter_plugin_in_rust_with_no_prebuilt_binaries/ 8 | for a tutorial on how to use Cargokit. 9 | 10 | Example plugin available at https://github.com/irondash/hello_rust_ffi_plugin. 11 | 12 | -------------------------------------------------------------------------------- /packages/agent_dart/example/android/app/src/main/res/drawable/launch_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /packages/agent_dart/example/android/app/src/main/res/drawable-v21/launch_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /packages/agent_dart_ffi/native/agent_dart/src/bls_ffi.rs: -------------------------------------------------------------------------------- 1 | use crate::bls::bls12381::bls::{core_verify, init, BLS_OK}; 2 | use crate::types::BLSVerifyReq; 3 | 4 | pub struct BlsFFI {} 5 | 6 | impl BlsFFI { 7 | pub fn bls_init() -> bool { 8 | init() == BLS_OK 9 | } 10 | 11 | pub fn bls_verify(req: BLSVerifyReq) -> bool { 12 | let verify = core_verify( 13 | req.signature.as_slice(), 14 | req.message.as_slice(), 15 | req.public_key.as_slice(), 16 | ); 17 | verify == BLS_OK 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /packages/agent_dart_base/test/principal/utils/get_crc.dart: -------------------------------------------------------------------------------- 1 | import 'dart:typed_data'; 2 | 3 | import 'package:agent_dart_base/agent_dart_base.dart'; 4 | import 'package:test/test.dart'; 5 | 6 | void main() { 7 | getCrc32Test(); 8 | } 9 | 10 | void getCrc32Test() { 11 | test('getCrc32', () { 12 | expect(getCrc32(Uint8List.fromList([]).buffer), 0); 13 | expect(getCrc32(Uint8List.fromList([1, 2, 3]).buffer), 0x55bc801d); 14 | expect( 15 | getCrc32(Uint8List.fromList([100, 99, 98, 1, 2, 3]).buffer), 16 | 0xc7e787f5, 17 | ); 18 | }); 19 | } 20 | -------------------------------------------------------------------------------- /packages/agent_dart/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "LaunchImage.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "LaunchImage@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "filename" : "LaunchImage@3x.png", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /packages/agent_dart_base/lib/protobuf/ic_ledger/pb/v1/types.pbserver.dart: -------------------------------------------------------------------------------- 1 | // 2 | // Generated code. Do not modify. 3 | // source: ic_ledger/pb/v1/types.proto 4 | // 5 | // @dart = 3.3 6 | 7 | // ignore_for_file: annotate_overrides, camel_case_types, comment_references 8 | // ignore_for_file: constant_identifier_names 9 | // ignore_for_file: deprecated_member_use_from_same_package, library_prefixes 10 | // ignore_for_file: non_constant_identifier_names, prefer_final_fields 11 | // ignore_for_file: unnecessary_import, unnecessary_this, unused_import 12 | 13 | export 'types.pb.dart'; 14 | 15 | -------------------------------------------------------------------------------- /packages/agent_dart_ffi/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: agent_dart_ffi 2 | version: 1.0.0-dev.40 3 | 4 | description: The FFI plugin that bridges Rust implementation for agent_dart. 5 | repository: https://github.com/AstroxNetwork/agent_dart 6 | issue_tracker: https://github.com/AstroxNetwork/agent_dart/issues 7 | 8 | environment: 9 | sdk: '>=3.4.0 <4.0.0' 10 | 11 | dependencies: 12 | flutter_rust_bridge: ^2.11.1 13 | 14 | dev_dependencies: 15 | lints: # transparent 16 | build_runner: ^2.1.11 17 | ffi: ^2.1.0 18 | ffigen: ^18.0.0 19 | 20 | false_secrets: 21 | - 'native/ed_compact/src/pem.rs' 22 | -------------------------------------------------------------------------------- /packages/agent_dart_base/lib/protobuf/ic_base_types/pb/v1/types.pbserver.dart: -------------------------------------------------------------------------------- 1 | // 2 | // Generated code. Do not modify. 3 | // source: ic_base_types/pb/v1/types.proto 4 | // 5 | // @dart = 3.3 6 | 7 | // ignore_for_file: annotate_overrides, camel_case_types, comment_references 8 | // ignore_for_file: constant_identifier_names 9 | // ignore_for_file: deprecated_member_use_from_same_package, library_prefixes 10 | // ignore_for_file: non_constant_identifier_names, prefer_final_fields 11 | // ignore_for_file: unnecessary_import, unnecessary_this, unused_import 12 | 13 | export 'types.pb.dart'; 14 | 15 | -------------------------------------------------------------------------------- /packages/agent_dart_base/test/agent_dart_base_test.dart: -------------------------------------------------------------------------------- 1 | import './test_utils.dart'; 2 | import 'agent/agent.dart' as agent; 3 | import 'authentication/authentication.dart' as auth; 4 | import 'candid/idl.dart' as candid; 5 | import 'identity/identity.dart' as identity; 6 | import 'principal/index.dart' as principal; 7 | import 'utils/utils_test.dart' as utils; 8 | import 'wallet/index.dart' as wallet; 9 | 10 | void main() async { 11 | ffiInit(); 12 | agent.main(); 13 | auth.main(); 14 | candid.main(); 15 | identity.main(); 16 | principal.main(); 17 | utils.main(); 18 | wallet.main(); 19 | } 20 | -------------------------------------------------------------------------------- /packages/agent_dart_base/lib/agent/bls.dart: -------------------------------------------------------------------------------- 1 | import 'dart:typed_data'; 2 | 3 | import 'package:agent_dart_ffi/agent_dart_ffi.dart' as ffi; 4 | 5 | class AgentBLS { 6 | AgentBLS(); 7 | 8 | bool get isInit => _isInit; 9 | late bool _isInit = false; 10 | 11 | Future blsInit() async { 12 | _isInit = await ffi.blsInit(); 13 | return _isInit; 14 | } 15 | 16 | Future blsVerify( 17 | Uint8List pk, 18 | Uint8List sig, 19 | Uint8List msg, 20 | ) { 21 | return ffi.blsVerify( 22 | req: ffi.BLSVerifyReq(publicKey: pk, signature: sig, message: msg), 23 | ); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /packages/agent_dart_ffi/native/agent_dart/src/lib.rs: -------------------------------------------------------------------------------- 1 | mod frb_generated; /* AUTO INJECTED BY flutter_rust_bridge. This line may not be accurate, and you can change it according to your needs. */ 2 | 3 | #[allow(clippy::all)] 4 | #[allow(dead_code)] 5 | mod api; 6 | mod bls_ffi; 7 | mod ed25519; 8 | mod errors; 9 | mod keyring; 10 | mod keystore; 11 | mod p256; 12 | mod schnorr; 13 | mod secp256k1; 14 | mod types; 15 | 16 | #[allow(clippy::all)] 17 | #[allow(dead_code)] 18 | mod bls; 19 | 20 | #[cfg(test)] 21 | mod tests { 22 | #[test] 23 | fn it_works() { 24 | let result = 2 + 2; 25 | assert_eq!(result, 4); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /packages/agent_dart_base/test/principal/utils/base32.dart: -------------------------------------------------------------------------------- 1 | import 'package:agent_dart_base/agent_dart_base.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | void main() { 5 | base32Test(); 6 | } 7 | 8 | void base32Test() { 9 | test('base32Decode', () { 10 | expect( 11 | base32Decode('irswgzloorzgc3djpjssazlwmvzhs5dinfxgoijb').u8aToString(), 12 | 'Decentralize everything!!', 13 | ); 14 | }); 15 | 16 | test('base32Encode', () { 17 | expect( 18 | base32Encode( 19 | 'Decentralize everything!!'.plainToU8a(useDartEncode: true), 20 | ), 21 | 'irswgzloorzgc3djpjssazlwmvzhs5dinfxgoijb', 22 | ); 23 | }); 24 | } 25 | -------------------------------------------------------------------------------- /packages/agent_dart/.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | migrate_working_dir/ 12 | 13 | # IntelliJ related 14 | *.ipr 15 | *.iws 16 | .idea/ 17 | 18 | # The .vscode folder contains launch configuration and tasks you configure in 19 | # VS Code which you may wish to be included in version control, so this line 20 | # is commented out by default. 21 | #.vscode/ 22 | 23 | # Flutter/Dart/Pub related 24 | # Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. 25 | /pubspec.lock 26 | **/doc/api/ 27 | .dart_tool/ 28 | .packages 29 | build/ 30 | -------------------------------------------------------------------------------- /packages/agent_dart/example/macos/Runner/Configs/Warnings.xcconfig: -------------------------------------------------------------------------------- 1 | WARNING_CFLAGS = -Wall -Wconditional-uninitialized -Wnullable-to-nonnull-conversion -Wmissing-method-return-type -Woverlength-strings 2 | GCC_WARN_UNDECLARED_SELECTOR = YES 3 | CLANG_UNDEFINED_BEHAVIOR_SANITIZER_NULLABILITY = YES 4 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE 5 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES 6 | CLANG_WARN_PRAGMA_PACK = YES 7 | CLANG_WARN_STRICT_PROTOTYPES = YES 8 | CLANG_WARN_COMMA = YES 9 | GCC_WARN_STRICT_SELECTOR_MATCH = YES 10 | CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES 11 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES 12 | GCC_WARN_SHADOW = YES 13 | CLANG_WARN_UNREACHABLE_CODE = YES 14 | -------------------------------------------------------------------------------- /packages/agent_dart/example/macos/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - agent_dart (1.0.0): 3 | - FlutterMacOS 4 | - FlutterMacOS (1.0.0) 5 | 6 | DEPENDENCIES: 7 | - agent_dart (from `Flutter/ephemeral/.symlinks/plugins/agent_dart/macos`) 8 | - FlutterMacOS (from `Flutter/ephemeral`) 9 | 10 | EXTERNAL SOURCES: 11 | agent_dart: 12 | :path: Flutter/ephemeral/.symlinks/plugins/agent_dart/macos 13 | FlutterMacOS: 14 | :path: Flutter/ephemeral 15 | 16 | SPEC CHECKSUMS: 17 | agent_dart: c5f3c84df4c0bc1173e4d60ec5e0a3be7cb4c91d 18 | FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24 19 | 20 | PODFILE CHECKSUM: 137ddf7b4dbe5a83427ebf04ae8dea674cfd87fa 21 | 22 | COCOAPODS: 1.16.2 23 | -------------------------------------------------------------------------------- /packages/agent_dart/ios/.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | .vagrant/ 3 | .sconsign.dblite 4 | .svn/ 5 | 6 | .DS_Store 7 | *.swp 8 | profile 9 | 10 | DerivedData/ 11 | build/ 12 | GeneratedPluginRegistrant.h 13 | GeneratedPluginRegistrant.m 14 | 15 | .generated/ 16 | 17 | *.pbxuser 18 | *.mode1v3 19 | *.mode2v3 20 | *.perspectivev3 21 | 22 | !default.pbxuser 23 | !default.mode1v3 24 | !default.mode2v3 25 | !default.perspectivev3 26 | 27 | xcuserdata 28 | 29 | *.moved-aside 30 | 31 | *.pyc 32 | *sync/ 33 | Icon? 34 | .tags* 35 | 36 | /Flutter/Generated.xcconfig 37 | /Flutter/ephemeral/ 38 | /Flutter/flutter_export_environment.sh 39 | 40 | Flutter/ 41 | Runner/ 42 | Frameworks/* 43 | !Frameworks/.gitkeep -------------------------------------------------------------------------------- /packages/agent_dart/example/README.md: -------------------------------------------------------------------------------- 1 | # flutter_agent_dart_example 2 | 3 | Demonstrates how to use the flutter_agent_dart plugin. 4 | 5 | ## Getting Started 6 | 7 | This project is a starting point for a Flutter application. 8 | 9 | A few resources to get you started if this is your first Flutter project: 10 | 11 | - [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab) 12 | - [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook) 13 | 14 | For help getting started with Flutter development, view the 15 | [online documentation](https://docs.flutter.dev/), which offers tutorials, 16 | samples, guidance on mobile development, and a full API reference. 17 | -------------------------------------------------------------------------------- /packages/agent_dart_ffi/native/ed_compact/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ed_compact" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | [features] 8 | default = ["random", "std"] 9 | pem = ["ct-codecs"] 10 | random = ["getrandom"] 11 | traits = ["ed25519"] 12 | self-verify = [] 13 | blind-keys = [] 14 | std = [] 15 | opt_size = [] 16 | 17 | [dependencies] 18 | ct-codecs = { version = "1.1.5", optional = true } 19 | getrandom = { version = "0.3.3", optional = true } 20 | ed25519 = { version = "1.5.3", optional = true } 21 | 22 | [dev-dependencies] 23 | getrandom = "0.3.3" 24 | ct-codecs = "1.1.5" 25 | -------------------------------------------------------------------------------- /packages/agent_dart/example/macos/Runner/Configs/AppInfo.xcconfig: -------------------------------------------------------------------------------- 1 | // Application-level settings for the Runner target. 2 | // 3 | // This may be replaced with something auto-generated from metadata (e.g., pubspec.yaml) in the 4 | // future. If not, the values below would default to using the project name when this becomes a 5 | // 'flutter create' template. 6 | 7 | // The application's name. By default this is also the title of the Flutter window. 8 | PRODUCT_NAME = flutter_agent_dart_example 9 | 10 | // The application's bundle identifier 11 | PRODUCT_BUNDLE_IDENTIFIER = com.astrox.agentdart.flutterAgentDartExample 12 | 13 | // The copyright displayed in application information 14 | PRODUCT_COPYRIGHT = Copyright © 2023 com.astrox.agent_dart. All rights reserved. 15 | -------------------------------------------------------------------------------- /packages/agent_dart/example/ios/.gitignore: -------------------------------------------------------------------------------- 1 | **/dgph 2 | *.mode1v3 3 | *.mode2v3 4 | *.moved-aside 5 | *.pbxuser 6 | *.perspectivev3 7 | **/*sync/ 8 | .sconsign.dblite 9 | .tags* 10 | **/.vagrant/ 11 | **/DerivedData/ 12 | Icon? 13 | **/Pods/ 14 | **/.symlinks/ 15 | profile 16 | xcuserdata 17 | **/.generated/ 18 | Flutter/App.framework 19 | Flutter/Flutter.framework 20 | Flutter/Flutter.podspec 21 | Flutter/Generated.xcconfig 22 | Flutter/ephemeral/ 23 | Flutter/app.flx 24 | Flutter/app.zip 25 | Flutter/flutter_assets/ 26 | Flutter/flutter_export_environment.sh 27 | ServiceDefinitions.json 28 | Runner/GeneratedPluginRegistrant.* 29 | Podfile.lock 30 | 31 | # Exceptions to above rules. 32 | !default.mode1v3 33 | !default.mode2v3 34 | !default.pbxuser 35 | !default.perspectivev3 36 | -------------------------------------------------------------------------------- /packages/agent_dart_base/lib/agent/utils/hash.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | import 'dart:math'; 3 | 4 | int idlHash(String s) { 5 | final arr = utf8.encode(s); 6 | int h = 0; 7 | for (final c in arr) { 8 | h = (h * 223 + c) % pow(2, 32).toInt(); 9 | } 10 | return h; 11 | } 12 | 13 | num idlLabelToId(String label) { 14 | final reg1 = RegExp(r'^_\d+_$'); 15 | final reg2 = RegExp(r'^_0x[\da-fA-F]+_$'); 16 | if (reg1.hasMatch(label) || reg2.hasMatch(label)) { 17 | final lb = label.substring(1, label.length - 1); 18 | final result = num.tryParse(lb); 19 | if (result != null && 20 | result is! BigInt && 21 | result >= 0 && 22 | result < pow(2, 32)) { 23 | return result; 24 | } 25 | } 26 | return idlHash(label); 27 | } 28 | -------------------------------------------------------------------------------- /packages/agent_dart/example/windows/runner/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_UTILS_H_ 2 | #define RUNNER_UTILS_H_ 3 | 4 | #include 5 | #include 6 | 7 | // Creates a console for the process, and redirects stdout and stderr to 8 | // it for both the runner and the Flutter library. 9 | void CreateAndAttachConsole(); 10 | 11 | // Takes a null-terminated wchar_t* encoded in UTF-16 and returns a std::string 12 | // encoded in UTF-8. Returns an empty std::string on failure. 13 | std::string Utf8FromUtf16(const wchar_t* utf16_string); 14 | 15 | // Gets the command line arguments passed in as a std::vector, 16 | // encoded in UTF-8. Returns an empty std::vector on failure. 17 | std::vector GetCommandLineArguments(); 18 | 19 | #endif // RUNNER_UTILS_H_ 20 | -------------------------------------------------------------------------------- /agent_dart_workspace.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /packages/agent_dart_base/lib/agent_dart_base.dart: -------------------------------------------------------------------------------- 1 | export 'package:agent_dart_ffi/agent_dart_ffi.dart'; 2 | 3 | export 'agent/agent.dart'; 4 | // auth_clinet; 5 | export 'auth_client/auth_client.dart'; 6 | // authentication 7 | export 'authentication/authentication.dart'; 8 | // candid 9 | export 'candid/idl.dart'; 10 | // identity 11 | export 'identity/identity.dart'; 12 | // principal; 13 | export 'principal/principal.dart'; 14 | export 'principal/utils/utils.dart'; 15 | // utils 16 | export 'utils/base64.dart'; 17 | export 'utils/bech32.dart'; 18 | export 'utils/bn.dart'; 19 | export 'utils/extension.dart'; 20 | export 'utils/hex.dart'; 21 | export 'utils/is.dart'; 22 | export 'utils/map.dart'; 23 | export 'utils/number.dart'; 24 | export 'utils/string.dart'; 25 | export 'utils/u8a.dart'; 26 | // wallet 27 | export 'wallet/wallet.dart'; 28 | -------------------------------------------------------------------------------- /packages/agent_dart_base/agent_dart_base.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /packages/agent_dart/cargokit/cmake/resolve_symlinks.ps1: -------------------------------------------------------------------------------- 1 | function Resolve-Symlinks { 2 | [CmdletBinding()] 3 | [OutputType([string])] 4 | param( 5 | [Parameter(Position = 0, Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)] 6 | [string] $Path 7 | ) 8 | 9 | [string] $separator = '/' 10 | [string[]] $parts = $Path.Split($separator) 11 | 12 | [string] $realPath = '' 13 | foreach ($part in $parts) { 14 | if ($realPath -and !$realPath.EndsWith($separator)) { 15 | $realPath += $separator 16 | } 17 | $realPath += $part 18 | $item = Get-Item $realPath 19 | if ($item.Target) { 20 | $realPath = $item.Target.Replace('\', '/') 21 | } 22 | } 23 | $realPath 24 | } 25 | 26 | $path=Resolve-Symlinks -Path $args[0] 27 | Write-Host $path 28 | -------------------------------------------------------------------------------- /packages/agent_dart/linux/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # The Flutter tooling requires that developers have CMake 3.10 or later 2 | # installed. You should not increase this version, as doing so will cause 3 | # the plugin to fail to compile for some customers of the plugin. 4 | cmake_minimum_required(VERSION 3.10) 5 | 6 | # Project-level configuration. 7 | set(PROJECT_NAME "agent_dart") 8 | project(${PROJECT_NAME} LANGUAGES CXX) 9 | 10 | include("../cargokit/cmake/cargokit.cmake") 11 | apply_cargokit(${PROJECT_NAME} ../native/agent_dart agent_dart "") 12 | 13 | # List of absolute paths to libraries that should be bundled with the plugin. 14 | # This list could contain prebuilt libraries, or libraries created by an 15 | # external build triggered from this build file. 16 | set(agent_dart_bundled_libraries 17 | "${${PROJECT_NAME}_cargokit_lib}" 18 | PARENT_SCOPE 19 | ) 20 | -------------------------------------------------------------------------------- /packages/agent_dart/example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | def flutterSdkPath = { 3 | def properties = new Properties() 4 | file("local.properties").withInputStream { properties.load(it) } 5 | def flutterSdkPath = properties.getProperty("flutter.sdk") 6 | assert flutterSdkPath != null, "flutter.sdk not set in local.properties" 7 | return flutterSdkPath 8 | }() 9 | 10 | includeBuild("$flutterSdkPath/packages/flutter_tools/gradle") 11 | 12 | repositories { 13 | google() 14 | mavenCentral() 15 | gradlePluginPortal() 16 | } 17 | } 18 | 19 | plugins { 20 | id "dev.flutter.flutter-plugin-loader" version "1.0.0" 21 | id "com.android.application" version "8.6.1" apply false 22 | id "org.jetbrains.kotlin.android" version "2.1.10" apply false 23 | } 24 | 25 | include ":app" 26 | -------------------------------------------------------------------------------- /packages/agent_dart_base/lib/agent/errors.dart: -------------------------------------------------------------------------------- 1 | import 'dart:typed_data'; 2 | 3 | import '../../utils/extension.dart'; 4 | 5 | /// An fetch error when using agent to make HTTP/S requests. 6 | class AgentFetchError extends Error { 7 | /// Creates an agent error with the provided [message]. 8 | AgentFetchError({this.statusCode, this.statusText, this.body}); 9 | 10 | final Object? statusCode; 11 | final Object? statusText; 12 | final Object? body; 13 | 14 | @override 15 | String toString() { 16 | if (statusCode == null && statusText == null && body == null) { 17 | return 'Agent failed'; 18 | } 19 | final b = body; 20 | return 'Agent failed: Server returned an error:\n' 21 | ' Code: $statusCode ($statusText)\n' 22 | ' Body: ${b is Uint8List ? b.u8aToString() : b}\n'; 23 | } 24 | } 25 | 26 | class UnreachableError extends Error {} 27 | -------------------------------------------------------------------------------- /packages/agent_dart_base/lib/agent/crypto/keystore/key_store.dart: -------------------------------------------------------------------------------- 1 | library key_store; 2 | 3 | import 'dart:convert'; 4 | import 'dart:core'; 5 | import 'dart:typed_data'; 6 | 7 | import 'package:agent_dart_ffi/agent_dart_ffi.dart'; 8 | import 'package:collection/collection.dart'; 9 | import 'package:meta/meta.dart'; 10 | import 'package:pointycastle/export.dart'; 11 | import 'package:uuid/uuid.dart'; 12 | 13 | import '../../../identity/p256.dart'; 14 | import '../../../identity/secp256k1.dart'; 15 | import '../../../principal/utils/sha256.dart'; 16 | import '../../../utils/extension.dart'; 17 | import '../../../utils/u8a.dart'; 18 | import '../../cbor.dart'; 19 | import '../random.dart'; 20 | 21 | part 'function.dart'; 22 | part 'key_derivator.dart'; 23 | part 'util.dart'; 24 | 25 | @immutable 26 | abstract class KeyStore { 27 | const KeyStore(); 28 | 29 | Map get keyStoreMap; 30 | } 31 | -------------------------------------------------------------------------------- /packages/agent_dart_base/protobuf/ic_base_types/pb/v1/types.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package ic_base_types.pb.v1; 4 | 5 | import "google/protobuf/descriptor.proto"; 6 | 7 | // The annotated message is supported by hardware wallet signing. 8 | // The numbering was chosen as the range 19000-19999 is anyway reserved in protobuf. 9 | extend google.protobuf.MessageOptions { 10 | bool tui_signed_message = 20000; 11 | } 12 | 13 | // The annotated field is displayed on the hardware wallet in the specification 14 | // used by launch of the Internet Computer. 15 | extend google.protobuf.FieldOptions { 16 | bool tui_signed_display_q2_2021 = 20001; 17 | } 18 | 19 | // A PB container for a PrincipalId, which uniquely identifies 20 | // a principal. 21 | message PrincipalId { 22 | option (tui_signed_message) = true; 23 | bytes serialized_id = 1 [(tui_signed_display_q2_2021) = true]; 24 | } 25 | -------------------------------------------------------------------------------- /packages/agent_dart_ffi/native/agent_dart/src/bls/arch.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2020 MIRACL UK Ltd. 3 | * 4 | * This file is part of MIRACL Core 5 | * (see https://github.com/miracl/core). 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | pub type Chunk = i64; 21 | pub type DChunk = i128; 22 | pub const CHUNK: usize = 64; 23 | -------------------------------------------------------------------------------- /packages/agent_dart/example/linux/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | ) 7 | 8 | list(APPEND FLUTTER_FFI_PLUGIN_LIST 9 | agent_dart 10 | ) 11 | 12 | set(PLUGIN_BUNDLED_LIBRARIES) 13 | 14 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 15 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/linux plugins/${plugin}) 16 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 17 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 18 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 19 | endforeach(plugin) 20 | 21 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) 22 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin}) 23 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) 24 | endforeach(ffi_plugin) 25 | -------------------------------------------------------------------------------- /packages/agent_dart/windows/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # The Flutter tooling requires that developers have a version of Visual Studio 2 | # installed that includes CMake 3.14 or later. You should not increase this 3 | # version, as doing so will cause the plugin to fail to compile for some 4 | # customers of the plugin. 5 | cmake_minimum_required(VERSION 3.14) 6 | 7 | # Project-level configuration. 8 | set(PROJECT_NAME "agent_dart") 9 | project(${PROJECT_NAME} LANGUAGES CXX) 10 | 11 | include("../cargokit/cmake/cargokit.cmake") 12 | apply_cargokit(${PROJECT_NAME} ../native/agent_dart agent_dart "") 13 | 14 | # List of absolute paths to libraries that should be bundled with the plugin. 15 | # This list could contain prebuilt libraries, or libraries created by an 16 | # external build triggered from this build file. 17 | set(agent_dart_bundled_libraries 18 | "${${PROJECT_NAME}_cargokit_lib}" 19 | PARENT_SCOPE 20 | ) 21 | -------------------------------------------------------------------------------- /packages/agent_dart/example/windows/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | ) 7 | 8 | list(APPEND FLUTTER_FFI_PLUGIN_LIST 9 | agent_dart 10 | ) 11 | 12 | set(PLUGIN_BUNDLED_LIBRARIES) 13 | 14 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 15 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin}) 16 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 17 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 18 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 19 | endforeach(plugin) 20 | 21 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) 22 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin}) 23 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) 24 | endforeach(ffi_plugin) 25 | -------------------------------------------------------------------------------- /packages/agent_dart_base/lib/principal/utils/sha256.dart: -------------------------------------------------------------------------------- 1 | import 'dart:typed_data'; 2 | 3 | import 'package:crypto/crypto.dart'; 4 | 5 | // ignore: implementation_imports 6 | import 'package:crypto/src/digest_sink.dart'; 7 | 8 | import '../../utils/number.dart'; 9 | 10 | Uint8List sha256Hash(ByteBuffer buf) { 11 | return SHA256().update(buf.asUint8List()).toUint8List(); 12 | } 13 | 14 | class SHA256 { 15 | SHA256(); 16 | 17 | late final ds = DigestSink(); 18 | late final sha = sha256.startChunkedConversion(ds); 19 | 20 | SHA256 update(List bytes) { 21 | sha.add(bytes); 22 | return this; 23 | } 24 | 25 | List _digest() { 26 | sha.close(); 27 | return ds.value.bytes; 28 | } 29 | 30 | Uint8List toUint8List() => Uint8List.fromList(_digest()); 31 | 32 | Uint8List digest() => toUint8List(); 33 | 34 | @override 35 | String toString() => bytesToHex(_digest()); 36 | } 37 | -------------------------------------------------------------------------------- /melos.yaml: -------------------------------------------------------------------------------- 1 | name: agent_dart_workspace 2 | repository: https://github.com/AstroxNetwork/agent_dart 3 | 4 | packages: 5 | - packages/** 6 | 7 | ignore: 8 | - 'packages/agent_dart/cargokit/build_tool' 9 | 10 | ide: 11 | intellij: 12 | enabled: true 13 | moduleNamePrefix: '' 14 | 15 | command: 16 | bootstrap: 17 | runPubGetInParallel: false 18 | 19 | scripts: 20 | analyze: 21 | exec: flutter analyze . 22 | description: Analyze a specific package in this project. 23 | 24 | check-format: 25 | exec: dart format --set-exit-if-changed . 26 | description: Check the format of a specific package in this project. 27 | 28 | format: 29 | exec: dart format . 30 | description: Format a specific package in this project. 31 | 32 | publish-dry-run: 33 | description: Publish dry-run all packages 34 | exec: dart pub publish --dry-run 35 | packageFilters: 36 | noPrivate: true 37 | -------------------------------------------------------------------------------- /packages/agent_dart_base/lib/principal/utils/sha224.dart: -------------------------------------------------------------------------------- 1 | import 'dart:typed_data'; 2 | 3 | import 'package:crypto/crypto.dart'; 4 | 5 | // ignore: implementation_imports 6 | import 'package:crypto/src/digest_sink.dart'; 7 | 8 | import '../../utils/number.dart'; 9 | 10 | Uint8List sha224Hash(ByteBuffer buf) { 11 | return SHA224().update(buf.asUint8List()).toUint8List(); 12 | } 13 | 14 | class SHA224 { 15 | SHA224() : ds = DigestSink(); 16 | 17 | final DigestSink ds; 18 | late final sha = sha224.startChunkedConversion(ds); 19 | 20 | SHA224 update(List bytes) { 21 | sha.add(bytes); 22 | return this; 23 | } 24 | 25 | List _digest() { 26 | sha.close(); 27 | return ds.value.bytes; 28 | } 29 | 30 | Uint8List toUint8List() => Uint8List.fromList(_digest()); 31 | 32 | Uint8List digest() => toUint8List(); 33 | 34 | @override 35 | String toString() => bytesToHex(_digest()); 36 | } 37 | -------------------------------------------------------------------------------- /packages/agent_dart_base/test/agent/utils/bls.dart: -------------------------------------------------------------------------------- 1 | import 'package:agent_dart_base/agent_dart_base.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | void main() { 5 | blsTest(); 6 | } 7 | 8 | void blsTest() { 9 | test('verify', () async { 10 | const pk = 11 | 'a7623a93cdb56c4d23d99c14216afaab3dfd6d4f9eb3db23d038280b6d5cb2caaee2a19dd92c9df7001dede23bf036bc0f33982dfb41e8fa9b8e96b5dc3e83d55ca4dd146c7eb2e8b6859cb5a5db815db86810b8d12cee1588b5dbf34a4dc9a5'; 12 | const sig = 13 | 'b89e13a212c830586eaa9ad53946cd968718ebecc27eda849d9232673dcd4f440e8b5df39bf14a88048c15e16cbcaabe'; 14 | const msg = 'hello'; 15 | final AgentBLS bls = AgentBLS(); 16 | expect( 17 | await bls.blsVerify(pk.toU8a(), sig.toU8a(), msg.plainToU8a()), 18 | true, 19 | ); 20 | expect( 21 | await bls.blsVerify(pk.toU8a(), sig.toU8a(), 'Hallo'.plainToU8a()), 22 | false, 23 | ); 24 | }); 25 | } 26 | -------------------------------------------------------------------------------- /packages/agent_dart/example/ios/Flutter/AppFrameworkInfo.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | App 9 | CFBundleIdentifier 10 | io.flutter.flutter.app 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | App 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1.0 23 | MinimumOSVersion 24 | 12.0 25 | 26 | 27 | -------------------------------------------------------------------------------- /packages/agent_dart/example/.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .build/ 9 | .buildlog/ 10 | .history 11 | .svn/ 12 | .swiftpm/ 13 | migrate_working_dir/ 14 | 15 | # IntelliJ related 16 | *.ipr 17 | *.iws 18 | .idea/ 19 | 20 | # The .vscode folder contains launch configuration and tasks you configure in 21 | # VS Code which you may wish to be included in version control, so this line 22 | # is commented out by default. 23 | #.vscode/ 24 | 25 | # Flutter/Dart/Pub related 26 | **/doc/api/ 27 | **/ios/Flutter/.last_build_id 28 | .dart_tool/ 29 | .flutter-plugins 30 | .flutter-plugins-dependencies 31 | .packages 32 | .pub-cache/ 33 | .pub/ 34 | /build/ 35 | 36 | # Symbolication related 37 | app.*.symbols 38 | 39 | # Obfuscation related 40 | app.*.map.json 41 | 42 | # Android Studio will place build artifacts here 43 | /android/app/debug 44 | /android/app/profile 45 | /android/app/release 46 | -------------------------------------------------------------------------------- /packages/agent_dart_base/lib/agent/utils/buffer_pipe.dart: -------------------------------------------------------------------------------- 1 | import 'dart:collection'; 2 | 3 | class BufferPipe { 4 | BufferPipe(Iterable list) { 5 | write(list); 6 | } 7 | 8 | final DoubleLinkedQueue _buffer = DoubleLinkedQueue(); 9 | int _bytesRead = 0; 10 | int _bytesWrote = 0; 11 | 12 | bool get end => _buffer.isEmpty; 13 | 14 | int get bytesRead => _bytesRead; 15 | 16 | int get bytesWrote => _bytesWrote; 17 | 18 | int get length => _buffer.length; 19 | 20 | List get buffer => _buffer.toList(); 21 | 22 | List read(int length) { 23 | final list = []; 24 | 25 | for (int i = 0; i < length && _buffer.isNotEmpty; i++) { 26 | list.add(_buffer.removeFirst()); 27 | _bytesRead++; 28 | } 29 | 30 | return list; 31 | } 32 | 33 | void write(Iterable data) { 34 | final oldLength = _buffer.length; 35 | _buffer.addAll(data); 36 | _bytesWrote += _buffer.length - oldLength; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /packages/agent_dart_base/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: agent_dart_base 2 | version: 1.0.0-dev.40 3 | 4 | description: The Dart plugin that bridges Rust implementation for agent_dart. 5 | repository: https://github.com/AstroxNetwork/agent_dart 6 | issue_tracker: https://github.com/AstroxNetwork/agent_dart/issues 7 | 8 | environment: 9 | sdk: '>=3.4.0 <4.0.0' 10 | 11 | dependencies: 12 | agent_dart_ffi: ^1.0.0-0 13 | 14 | bip32_plus: ^1.0.0 15 | bip39_mnemonic: ^3.0.9 16 | cbor: ^4.1.0 17 | collection: ^1.16.0 18 | convert: ^3.0.1 19 | crypto: ^3.0.2 20 | http: ^1.0.0 21 | meta: ^1.7.0 22 | pointycastle: ^4.0.0 23 | typed_data: ^1.3.1 24 | uuid: '>=3.0.0 <5.0.0' 25 | validators: ^3.0.0 26 | 27 | # Protocol Buffers 28 | protobuf: ^4.0.0 29 | fixnum: ^1.0.1 30 | 31 | dev_dependencies: 32 | lints: # transparent 33 | test: ^1.24.0 34 | build_runner: ^2.4.5 35 | 36 | false_secrets: 37 | - 'native/ed_compact/src/pem.rs' 38 | - 'test/fixture/*.pem' 39 | -------------------------------------------------------------------------------- /packages/agent_dart/cargokit/build_tool/pubspec.yaml: -------------------------------------------------------------------------------- 1 | # This is copied from Cargokit (which is the official way to use it currently) 2 | # Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin 3 | 4 | name: build_tool 5 | description: Cargokit build_tool. Facilitates the build of Rust crate during Flutter application build. 6 | publish_to: none 7 | version: 1.0.0 8 | 9 | environment: 10 | sdk: ">=3.0.0 <4.0.0" 11 | 12 | # Add regular dependencies here. 13 | dependencies: 14 | # these are pinned on purpose because the bundle_tool_runner doesn't have 15 | # pubspec.lock. See run_build_tool.sh 16 | logging: 1.2.0 17 | path: 1.8.0 18 | version: 3.0.0 19 | collection: 1.18.0 20 | ed25519_edwards: 0.3.1 21 | hex: 0.2.0 22 | yaml: 3.1.2 23 | source_span: 1.10.0 24 | github: 9.17.0 25 | args: 2.4.2 26 | crypto: 3.0.3 27 | convert: 3.1.1 28 | http: 1.1.0 29 | toml: 0.14.0 30 | 31 | dev_dependencies: 32 | lints: ^2.1.0 33 | test: ^1.24.0 34 | -------------------------------------------------------------------------------- /packages/agent_dart/example/windows/runner/runner.exe.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PerMonitorV2 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /packages/agent_dart_base/lib/agent/canisters/asset_idl.dart: -------------------------------------------------------------------------------- 1 | import 'dart:typed_data'; 2 | 3 | import '../../candid/idl.dart'; 4 | import '../actor.dart'; 5 | 6 | Service assetIDL() { 7 | return IDL.Service({ 8 | 'retrieve': IDL.Func([IDL.Text], [IDL.Vec(IDL.Nat8)], ['query']), 9 | 'store': IDL.Func([IDL.Text, IDL.Vec(IDL.Nat8)], [], []), 10 | }); 11 | } 12 | 13 | enum AssetMethod { retrieve, store } 14 | 15 | /// Try to understand how idl can be transformed. 16 | class AssetActor { 17 | AssetActor(); 18 | 19 | late final CanisterActor actor; 20 | 21 | Future retrieve(String key) async { 22 | final res = await actor.getFunc(AssetMethod.retrieve.name)?.call([key]); 23 | if (res != null) { 24 | return res as Uint8List; 25 | } 26 | throw StateError('Request failed with the result: $res.'); 27 | } 28 | 29 | Future store(String key, Uint8List value) async { 30 | await actor.getFunc(AssetMethod.store.name)?.call([key, value]); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /packages/agent_dart_ffi/lib/src/schnorr.dart: -------------------------------------------------------------------------------- 1 | // This file is automatically generated, so please do not edit it. 2 | // @generated by `flutter_rust_bridge`@ 2.11.1. 3 | 4 | // ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import 5 | 6 | import 'frb_generated.dart'; 7 | import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart'; 8 | 9 | class SchnorrIdentityExport { 10 | final Uint8List privateKeyHash; 11 | final Uint8List publicKeyHash; 12 | 13 | const SchnorrIdentityExport({ 14 | required this.privateKeyHash, 15 | required this.publicKeyHash, 16 | }); 17 | 18 | @override 19 | int get hashCode => privateKeyHash.hashCode ^ publicKeyHash.hashCode; 20 | 21 | @override 22 | bool operator ==(Object other) => 23 | identical(this, other) || 24 | other is SchnorrIdentityExport && 25 | runtimeType == other.runtimeType && 26 | privateKeyHash == other.privateKeyHash && 27 | publicKeyHash == other.publicKeyHash; 28 | } 29 | -------------------------------------------------------------------------------- /packages/agent_dart_ffi/native/agent_dart/src/bls/bls12381/mod.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2020 MIRACL UK Ltd. 3 | * 4 | * This file is part of MIRACL Core 5 | * (see https://github.com/miracl/core). 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | pub mod big; 20 | pub mod bls; 21 | pub mod dbig; 22 | pub mod ecp; 23 | pub mod ecp2; 24 | pub mod fp; 25 | pub mod fp12; 26 | pub mod fp2; 27 | pub mod fp4; 28 | pub mod mpin; 29 | pub mod pair; 30 | pub mod rom; 31 | -------------------------------------------------------------------------------- /packages/agent_dart_ffi/lib/src/p256.dart: -------------------------------------------------------------------------------- 1 | // This file is automatically generated, so please do not edit it. 2 | // @generated by `flutter_rust_bridge`@ 2.11.1. 3 | 4 | // ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import 5 | 6 | import 'frb_generated.dart'; 7 | import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart'; 8 | 9 | class P256IdentityExport { 10 | final Uint8List privateKeyHash; 11 | final Uint8List derEncodedPublicKey; 12 | 13 | const P256IdentityExport({ 14 | required this.privateKeyHash, 15 | required this.derEncodedPublicKey, 16 | }); 17 | 18 | @override 19 | int get hashCode => privateKeyHash.hashCode ^ derEncodedPublicKey.hashCode; 20 | 21 | @override 22 | bool operator ==(Object other) => 23 | identical(this, other) || 24 | other is P256IdentityExport && 25 | runtimeType == other.runtimeType && 26 | privateKeyHash == other.privateKeyHash && 27 | derEncodedPublicKey == other.derEncodedPublicKey; 28 | } 29 | -------------------------------------------------------------------------------- /packages/agent_dart_ffi/native/agent_dart/src/bls/README.md: -------------------------------------------------------------------------------- 1 | This is a convenience copy of the code in https://github.com/miracl/core 2 | produced from revision f9de005e0168f59a56afe177498b19f4d43f054f with these steps: 3 | 4 | * `cd rust/` 5 | * `python3 config64.py` 6 | * Select BLS12381 (enter 31, then enter 0) 7 | * Copy the files listed under `core/src` to this directory. 8 | * Remove `main.rs`; Rename `lib.rs` to `mod.rs`. 9 | * `sed -i .bak 's/crate::/crate::bls::/g' *.rs` 10 | * Patch the `bls12381/` directory as follows: 11 | * `ecp.rs`: Set `ALLOW_ALT_COMPRESS` to true 12 | * `bls.rs`: Change the domain separator to `BLS_SIG_BLS12381G1_XMD:SHA-256_SSWU_RO_NUL_` (in `bls_hash_to_point` function) 13 | * `bls.rs`: Do not use the "new multi-pairing mechanism", but the alternative in `core_verify` function. 14 | (The commented code is out dated. We need the following patch before master fix it) 15 | ``` 16 | //.. or alternatively 17 | let g = ECP2::generator(); 18 | let mut v = pair::ate2(&g, &d, &pk, &hm); 19 | ``` 20 | -------------------------------------------------------------------------------- /packages/agent_dart_base/test/wallet/pem.dart: -------------------------------------------------------------------------------- 1 | import 'package:agent_dart_base/agent_dart_base.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | void main() { 5 | pemTest(); 6 | } 7 | 8 | void pemTest() { 9 | const ed25519File = './test/fixture/ed25519.pem'; 10 | const secp256k1File = './test/fixture/secp256k1.pem'; 11 | test('from ed25519 pem', () async { 12 | final pem = await getPemFile(ed25519File); 13 | expect(pem.keyType, KeyType.ed25519); 14 | final id = await ed25519KeyIdentityFromPem(pem.rawString); 15 | expect( 16 | id.getPrincipal().toText(), 17 | 'uz7u7-ut6sf-gx45r-pb3ww-ntxjp-y4lv2-bdobd-65xa3-7yt6t-ti2lz-aqe', 18 | ); 19 | }); 20 | test('from secp256k1 pem', () async { 21 | final pem = await getPemFile(secp256k1File); 22 | expect(pem.keyType, KeyType.secp265k1); 23 | final id = await secp256k1KeyIdentityFromPem(pem.rawString); 24 | expect( 25 | id.getPrincipal().toText(), 26 | '4tu7k-esetu-2lfo6-zzg45-ivl5m-77h3d-gjszr-uoeg4-zh24n-jly75-dqe', 27 | ); 28 | }); 29 | } 30 | -------------------------------------------------------------------------------- /packages/agent_dart_ffi/lib/src/secp256k1.dart: -------------------------------------------------------------------------------- 1 | // This file is automatically generated, so please do not edit it. 2 | // @generated by `flutter_rust_bridge`@ 2.11.1. 3 | 4 | // ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import 5 | 6 | import 'frb_generated.dart'; 7 | import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart'; 8 | 9 | class Secp256k1IdentityExport { 10 | final Uint8List privateKeyHash; 11 | final Uint8List derEncodedPublicKey; 12 | 13 | const Secp256k1IdentityExport({ 14 | required this.privateKeyHash, 15 | required this.derEncodedPublicKey, 16 | }); 17 | 18 | @override 19 | int get hashCode => privateKeyHash.hashCode ^ derEncodedPublicKey.hashCode; 20 | 21 | @override 22 | bool operator ==(Object other) => 23 | identical(this, other) || 24 | other is Secp256k1IdentityExport && 25 | runtimeType == other.runtimeType && 26 | privateKeyHash == other.privateKeyHash && 27 | derEncodedPublicKey == other.derEncodedPublicKey; 28 | } 29 | -------------------------------------------------------------------------------- /packages/agent_dart_base/lib/agent/canisters/management.dart: -------------------------------------------------------------------------------- 1 | import '../../principal/principal.dart'; 2 | import '../actor.dart'; 3 | import 'management_idl.dart'; 4 | 5 | // : ActorSubclass 6 | CanisterActor getManagementCanister(CallConfig config) { 7 | CallConfig transform(String methodName, List args, CallConfig callConfig) { 8 | final first = args[0]; 9 | Principal effectiveCanisterId = Principal.fromHex(''); 10 | if (first != null && first is Map && first['canister_id'] != null) { 11 | effectiveCanisterId = Principal.from(first['canister_id']); 12 | } 13 | return CallConfig(effectiveCanisterId: effectiveCanisterId); 14 | } 15 | 16 | final newConfig = ActorConfig( 17 | agent: config.agent, 18 | pollingStrategyFactory: config.pollingStrategyFactory, 19 | effectiveCanisterId: config.effectiveCanisterId, 20 | canisterId: Principal.fromHex(''), 21 | callTransform: transform, 22 | queryTransform: transform, 23 | ); 24 | return Actor.createActor(managementIDL(), newConfig); 25 | } 26 | -------------------------------------------------------------------------------- /packages/agent_dart/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: agent_dart 2 | version: 1.0.0-dev.40 3 | 4 | description: | 5 | An agent library built for Internet Computer, 6 | a plugin package for dart and flutter apps. 7 | Developers can build ones to interact with Dfinity's blockchain directly. 8 | repository: https://github.com/AstroxNetwork/agent_dart 9 | issue_tracker: https://github.com/AstroxNetwork/agent_dart/issues 10 | 11 | environment: 12 | sdk: '>=3.4.0 <4.0.0' 13 | flutter: '>=3.22.0' 14 | 15 | dependencies: 16 | flutter: 17 | sdk: flutter 18 | 19 | agent_dart_base: ^1.0.0-0 20 | 21 | dev_dependencies: 22 | flutter_lints: any 23 | flutter_test: 24 | sdk: flutter 25 | integration_test: 26 | sdk: flutter 27 | 28 | flutter: 29 | plugin: 30 | platforms: 31 | android: 32 | ffiPlugin: true 33 | ios: 34 | ffiPlugin: true 35 | linux: 36 | ffiPlugin: true 37 | macos: 38 | ffiPlugin: true 39 | windows: 40 | ffiPlugin: true 41 | 42 | false_secrets: 43 | - 'native/ed_compact/src/pem.rs' 44 | -------------------------------------------------------------------------------- /packages/agent_dart_base/test/agent/utils/hash.dart: -------------------------------------------------------------------------------- 1 | import 'package:agent_dart_base/agent_dart_base.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | void main() { 5 | hashTest(); 6 | } 7 | 8 | void hashTest() { 9 | test('IDL label', () { 10 | void testLabel(String str, int expected) { 11 | expect(idlLabelToId(str), expected); 12 | } 13 | 14 | testLabel('', 0); 15 | testLabel('id', 23515); 16 | testLabel('description', 1595738364); 17 | testLabel('short_name', 3261810734); 18 | testLabel('Hi ☃', 1419229646); 19 | testLabel('_0_', 0); 20 | testLabel('_1_', 1); 21 | testLabel('_+1_', 1055658234); 22 | testLabel('_-1_', 1055757692); 23 | testLabel('_123_', 123); 24 | testLabel('_4294967295_', 4294967295); 25 | testLabel('_4294967296_', 1569808370); 26 | testLabel('_0xa_', 10); 27 | testLabel('_0d_', 1055918252); 28 | testLabel('_1.23_', 1360503298); 29 | testLabel('_1e2_', 3552665568); 30 | testLabel('_', 95); 31 | testLabel('__', 21280); 32 | testLabel('___', 4745535); 33 | }); 34 | } 35 | -------------------------------------------------------------------------------- /packages/agent_dart_base/test/agent/actor.dart: -------------------------------------------------------------------------------- 1 | import 'package:agent_dart_base/agent_dart_base.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | void main() { 5 | actorTest(); 6 | } 7 | 8 | void actorTest() { 9 | test('actor', () async { 10 | final agent = HttpAgent( 11 | defaultHost: 'icp-api.io', 12 | defaultPort: 443, 13 | options: const HttpAgentOptions(identity: AnonymousIdentity()), 14 | ); 15 | final idl = IDL.Service({ 16 | 'create_challenge': IDL.Func( 17 | [], 18 | [ 19 | IDL.Record({ 20 | 'png_base64': IDL.Text, 21 | 'challenge_key': IDL.Text, 22 | }), 23 | ], 24 | [], 25 | ), 26 | }); 27 | final actor = CanisterActor( 28 | ActorConfig( 29 | canisterId: Principal.fromText('rdmx6-jaaaa-aaaaa-aaadq-cai'), 30 | agent: agent, 31 | ), 32 | idl, 33 | ); 34 | final result = await actor.getFunc('create_challenge')!.call([]); 35 | expect(result, isA()); 36 | expect(result['challenge_key'], isA()); 37 | }); 38 | } 39 | -------------------------------------------------------------------------------- /packages/agent_dart/example/windows/runner/flutter_window.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_FLUTTER_WINDOW_H_ 2 | #define RUNNER_FLUTTER_WINDOW_H_ 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include "win32_window.h" 10 | 11 | // A window that does nothing but host a Flutter view. 12 | class FlutterWindow : public Win32Window { 13 | public: 14 | // Creates a new FlutterWindow hosting a Flutter view running |project|. 15 | explicit FlutterWindow(const flutter::DartProject& project); 16 | virtual ~FlutterWindow(); 17 | 18 | protected: 19 | // Win32Window: 20 | bool OnCreate() override; 21 | void OnDestroy() override; 22 | LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam, 23 | LPARAM const lparam) noexcept override; 24 | 25 | private: 26 | // The project to run. 27 | flutter::DartProject project_; 28 | 29 | // The Flutter instance hosted by this window. 30 | std::unique_ptr flutter_controller_; 31 | }; 32 | 33 | #endif // RUNNER_FLUTTER_WINDOW_H_ 34 | -------------------------------------------------------------------------------- /packages/agent_dart/example/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 15 | 18 | 19 | -------------------------------------------------------------------------------- /analysis_options.yaml: -------------------------------------------------------------------------------- 1 | include: package:lints/recommended.yaml 2 | 3 | analyzer: 4 | errors: 5 | invalid_annotation_target: ignore 6 | exclude: 7 | - 'packages/**/**.g.dart' 8 | - 'packages/**/**.freezed.dart' 9 | - 'packages/**/bridge_generated.dart' 10 | - 'packages/**/types.pb*.dart' 11 | 12 | # Additional information about this file can be found at 13 | # https://dart.dev/guides/language/analysis-options 14 | linter: 15 | rules: 16 | avoid_print: false 17 | avoid_redundant_argument_values: false 18 | always_declare_return_types: true 19 | directives_ordering: true 20 | prefer_const_constructors: true 21 | prefer_const_constructors_in_immutables: true 22 | prefer_const_declarations: true 23 | prefer_final_fields: true 24 | prefer_final_in_for_each: true 25 | prefer_final_locals: true 26 | prefer_single_quotes: true 27 | require_trailing_commas: false 28 | sort_constructors_first: true 29 | sort_unnamed_constructors_first: true 30 | unnecessary_await_in_return: true 31 | unnecessary_library_name: false 32 | unnecessary_parenthesis: true 33 | -------------------------------------------------------------------------------- /packages/agent_dart/example/android/app/src/main/res/values-night/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 15 | 18 | 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 AstroxNetwork 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/agent_dart_base/lib/protobuf/ic_base_types/pb/v1/types.pbjson.dart: -------------------------------------------------------------------------------- 1 | // 2 | // Generated code. Do not modify. 3 | // source: ic_base_types/pb/v1/types.proto 4 | // 5 | // @dart = 3.3 6 | 7 | // ignore_for_file: annotate_overrides, camel_case_types, comment_references 8 | // ignore_for_file: constant_identifier_names, library_prefixes 9 | // ignore_for_file: non_constant_identifier_names, prefer_final_fields 10 | // ignore_for_file: unnecessary_import, unnecessary_this, unused_import 11 | 12 | import 'dart:convert' as $convert; 13 | import 'dart:core' as $core; 14 | import 'dart:typed_data' as $typed_data; 15 | 16 | @$core.Deprecated('Use principalIdDescriptor instead') 17 | const PrincipalId$json = { 18 | '1': 'PrincipalId', 19 | '2': [ 20 | {'1': 'serialized_id', '3': 1, '4': 1, '5': 12, '8': {}, '10': 'serializedId'}, 21 | ], 22 | '7': {}, 23 | }; 24 | 25 | /// Descriptor for `PrincipalId`. Decode as a `google.protobuf.DescriptorProto`. 26 | final $typed_data.Uint8List principalIdDescriptor = $convert.base64Decode( 27 | 'CgtQcmluY2lwYWxJZBIpCg1zZXJpYWxpemVkX2lkGAEgASgMQgSI4gkBUgxzZXJpYWxpemVkSW' 28 | 'Q6BIDiCQE='); 29 | 30 | -------------------------------------------------------------------------------- /packages/agent_dart_base/lib/utils/base64.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert' as convert; 2 | import 'dart:typed_data'; 3 | 4 | import 'u8a.dart'; 5 | 6 | bool base64Validate(String? value) { 7 | assert(value != null, 'expected non-null & non-empty base64 input.'); 8 | return RegExp( 9 | r'^(?:[A-Za-z\d+/]{4})*(?:[A-Za-z\d+/]{2}==|[A-Za-z\d+/]{3}=|[A-Za-z\d+/]{4})$', 10 | ).hasMatch(value!); 11 | } 12 | 13 | String base64Trim(String value) { 14 | while (value.isNotEmpty && value[value.length - 1] == '=') { 15 | final len = value.length; 16 | value = value.substring(0, len - 1); 17 | } 18 | return value; 19 | } 20 | 21 | String base64Pad(String value) { 22 | return value.padRight(value.length + (value.length % 4), '='); 23 | } 24 | 25 | bool isBase64(String value) { 26 | try { 27 | return base64Validate(value); 28 | } catch (e) { 29 | return false; 30 | } 31 | } 32 | 33 | String base64Encode(dynamic value) { 34 | return convert.base64Encode(u8aToU8a(value).toList()); 35 | } 36 | 37 | Uint8List base64Decode(String value) { 38 | assert(base64Validate(value), 'invalid base64 string'); 39 | return convert.base64Decode(value); 40 | } 41 | -------------------------------------------------------------------------------- /packages/agent_dart/example/macos/Runner/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | $(FLUTTER_BUILD_NAME) 21 | CFBundleVersion 22 | $(FLUTTER_BUILD_NUMBER) 23 | LSMinimumSystemVersion 24 | $(MACOSX_DEPLOYMENT_TARGET) 25 | NSHumanReadableCopyright 26 | $(PRODUCT_COPYRIGHT) 27 | NSMainNibFile 28 | MainMenu 29 | NSPrincipalClass 30 | NSApplication 31 | 32 | 33 | -------------------------------------------------------------------------------- /packages/agent_dart_ffi/agent_dart_ffi.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /packages/agent_dart_ffi/native/agent_dart/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "agent_dart" 3 | version = "1.0.0" 4 | authors = ["AstroX Dev "] 5 | edition = "2021" 6 | 7 | [lib] 8 | name = "agent_dart" 9 | crate-type = ["staticlib", "cdylib"] 10 | 11 | [dependencies] 12 | aes = { version = "0.7.5", default-features = false, features = ["ctr"] } 13 | bip32 = "=0.4.0" 14 | bip39 = "2.0.0" 15 | ed_compact = { path = "../ed_compact" } 16 | pbkdf2 = "0.12.2" 17 | scrypt = "0.11.0" 18 | sha2 = "0.10.2" 19 | hmac = "0.12.1" 20 | block-modes = "0.8.1" 21 | aes-gcm = "0.10.1" 22 | serde_json = "1.0.79" 23 | lazy_static = "1.4.0" 24 | 25 | flutter_rust_bridge = "=2.11.1" 26 | 27 | [dependencies.base64ct] 28 | version = "=1.6.0" 29 | 30 | [dependencies.k256] 31 | version = "0.11.6" 32 | default-features = false 33 | features = ["ecdsa", "sha256", "pem", "keccak256", "ecdh", "schnorr"] 34 | 35 | [dependencies.p256] 36 | version = "0.11.1" 37 | default-features = false 38 | features = ["ecdsa", "ecdh", "pem"] 39 | 40 | [dependencies.serde] 41 | version = "1.0.137" 42 | features = ["derive"] 43 | 44 | [dependencies.tokio] 45 | version = "1.45.0" 46 | default-features = false 47 | features = ["rt-multi-thread", "time", "sync"] 48 | -------------------------------------------------------------------------------- /packages/agent_dart_base/test/identity/schnorr.dart: -------------------------------------------------------------------------------- 1 | import 'dart:typed_data'; 2 | 3 | import 'package:agent_dart_base/agent_dart_base.dart'; 4 | import 'package:test/test.dart'; 5 | 6 | void main() { 7 | schnorrTest(); 8 | } 9 | 10 | void schnorrTest() { 11 | const prv = 12 | '4af1bceebf7f3634ec3cff8a2c38e51178d5d4ce585c52d6043e5e2cc3418bb0'; 13 | const msg = 'Hello World'; 14 | 15 | test('sign', () async { 16 | final res = await signSchnorrAsync( 17 | msg.plainToU8a(), 18 | prv.toU8a(), 19 | auxRand: Uint8List(32)..fillRange(0, 32, 0), 20 | ); 21 | expect(res.length, 64); 22 | 23 | final isValid = await verifySchnorrAsync( 24 | msg.plainToU8a(), 25 | res, 26 | (await SchnorrIdentity.fromSecretKey(prv.toU8a())).getPublicKey(), 27 | ); 28 | expect(isValid, true); 29 | }); 30 | 31 | test('ffi', () async { 32 | final key = await getECKeysAsync(generateMnemonic()); 33 | 34 | final derExpect = 35 | Secp256k1PublicKey.fromRaw(key.ecSchnorrPublicKey!).toDer(); 36 | expect( 37 | derExpect.toHex(), 38 | Secp256k1PublicKey.fromRaw(await getSchnorrPubFromFFI(key.ecPrivateKey!)) 39 | .toDer() 40 | .toHex(), 41 | ); 42 | }); 43 | } 44 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish 2 | 3 | on: 4 | release: 5 | types: [published] 6 | workflow_dispatch: 7 | 8 | jobs: 9 | publish: 10 | runs-on: ubuntu-22.04 11 | steps: 12 | - name: Checkout 13 | uses: actions/checkout@v3 14 | - name: Replace symlinks before publish 15 | run: ./scripts/replace_symlinks_before_publish.sh 16 | 17 | - name: Publish agent_dart 18 | uses: k-paxian/dart-package-publisher@master 19 | with: 20 | credentialJson: ${{ secrets.CREDENTIAL_JSON }} 21 | force: true 22 | relativePath: packages/agent_dart 23 | skipTests: true 24 | suppressBuildRunner: true 25 | 26 | - name: Publish agent_dart_base 27 | uses: k-paxian/dart-package-publisher@master 28 | with: 29 | credentialJson: ${{ secrets.CREDENTIAL_JSON }} 30 | force: true 31 | relativePath: packages/agent_dart_base 32 | skipTests: true 33 | suppressBuildRunner: true 34 | 35 | - name: Publish agent_dart_ffi 36 | uses: k-paxian/dart-package-publisher@master 37 | with: 38 | credentialJson: ${{ secrets.CREDENTIAL_JSON }} 39 | force: true 40 | relativePath: packages/agent_dart_ffi 41 | skipTests: true 42 | suppressBuildRunner: true 43 | -------------------------------------------------------------------------------- /packages/agent_dart_base/test/authentication/authentication.dart: -------------------------------------------------------------------------------- 1 | import 'dart:typed_data'; 2 | 3 | import 'package:agent_dart_base/agent_dart_base.dart'; 4 | import 'package:test/test.dart'; 5 | 6 | import '../test_utils.dart'; 7 | 8 | Future createIdentity(int seed) async { 9 | final seed1 = List.filled(32, 0); 10 | seed1[0] = seed; 11 | return Ed25519KeyIdentity.generate(Uint8List.fromList(seed1)); 12 | } 13 | 14 | void main() { 15 | ffiInit(); 16 | authenticationTest(); 17 | } 18 | 19 | void authenticationTest() { 20 | test('checks expiration', () async { 21 | final root = await createIdentity(0); 22 | final session = await createIdentity(1); 23 | final future = DateTime.fromMillisecondsSinceEpoch( 24 | DateTime.now().millisecondsSinceEpoch + 1000, 25 | ); 26 | final past = DateTime.fromMillisecondsSinceEpoch( 27 | DateTime.now().millisecondsSinceEpoch - 1000, 28 | ); 29 | 30 | // Create a valid delegation. 31 | expect( 32 | isDelegationValid( 33 | await DelegationChain.create(root, session.getPublicKey(), future), 34 | null, 35 | ), 36 | true, 37 | ); 38 | expect( 39 | isDelegationValid( 40 | await DelegationChain.create(root, session.getPublicKey(), past), 41 | null, 42 | ), 43 | false, 44 | ); 45 | }); 46 | } 47 | -------------------------------------------------------------------------------- /packages/agent_dart/cargokit/build_tool/lib/src/build_cmake.dart: -------------------------------------------------------------------------------- 1 | /// This is copied from Cargokit (which is the official way to use it currently) 2 | /// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin 3 | 4 | import 'dart:io'; 5 | 6 | import 'package:path/path.dart' as path; 7 | 8 | import 'artifacts_provider.dart'; 9 | import 'builder.dart'; 10 | import 'environment.dart'; 11 | import 'options.dart'; 12 | import 'target.dart'; 13 | 14 | class BuildCMake { 15 | final CargokitUserOptions userOptions; 16 | 17 | BuildCMake({required this.userOptions}); 18 | 19 | Future build() async { 20 | final targetPlatform = Environment.targetPlatform; 21 | final target = Target.forFlutterName(Environment.targetPlatform); 22 | if (target == null) { 23 | throw Exception("Unknown target platform: $targetPlatform"); 24 | } 25 | 26 | final environment = BuildEnvironment.fromEnvironment(isAndroid: false); 27 | final provider = 28 | ArtifactProvider(environment: environment, userOptions: userOptions); 29 | final artifacts = await provider.getArtifacts([target]); 30 | 31 | final libs = artifacts[target]!; 32 | 33 | for (final lib in libs) { 34 | if (lib.type == AritifactType.dylib) { 35 | File(lib.path) 36 | .copySync(path.join(Environment.outputDir, lib.finalFileName)); 37 | } 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /packages/agent_dart/cargokit/build_tool/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | # This is copied from Cargokit (which is the official way to use it currently) 2 | # Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin 3 | 4 | # This file configures the static analysis results for your project (errors, 5 | # warnings, and lints). 6 | # 7 | # This enables the 'recommended' set of lints from `package:lints`. 8 | # This set helps identify many issues that may lead to problems when running 9 | # or consuming Dart code, and enforces writing Dart using a single, idiomatic 10 | # style and format. 11 | # 12 | # If you want a smaller set of lints you can change this to specify 13 | # 'package:lints/core.yaml'. These are just the most critical lints 14 | # (the recommended set includes the core lints). 15 | # The core lints are also what is used by pub.dev for scoring packages. 16 | 17 | include: package:lints/recommended.yaml 18 | 19 | # Uncomment the following section to specify additional rules. 20 | 21 | linter: 22 | rules: 23 | - prefer_relative_imports 24 | - directives_ordering 25 | 26 | # analyzer: 27 | # exclude: 28 | # - path/to/excluded/files/** 29 | 30 | # For more information about the core and recommended set of lints, see 31 | # https://dart.dev/go/core-lints 32 | 33 | # For additional information about configuring this file, see 34 | # https://dart.dev/guides/language/analysis-options 35 | -------------------------------------------------------------------------------- /packages/agent_dart/example/android/app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id "com.android.application" 3 | id "kotlin-android" 4 | // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins. 5 | id "dev.flutter.flutter-gradle-plugin" 6 | } 7 | 8 | android { 9 | namespace = 'com.astrox.agent_dart.flutter_agent_dart_example' 10 | compileSdk = flutter.compileSdkVersion 11 | ndkVersion = flutter.ndkVersion 12 | 13 | compileOptions { 14 | sourceCompatibility JavaVersion.VERSION_17 15 | targetCompatibility JavaVersion.VERSION_17 16 | } 17 | 18 | kotlinOptions { 19 | jvmTarget = '17' 20 | } 21 | 22 | sourceSets { 23 | main.java.srcDirs += 'src/main/kotlin' 24 | } 25 | 26 | defaultConfig { 27 | applicationId "com.astrox.agent_dart.flutter_agent_dart_example" 28 | minSdk 24 29 | targetSdk = flutter.targetSdkVersion 30 | versionCode = flutter.versionCode 31 | versionName = flutter.versionName 32 | } 33 | 34 | buildTypes { 35 | release { 36 | // TODO: Add your own signing config for the release build. 37 | // Signing with the debug keys for now, so `flutter run --release` works. 38 | signingConfig signingConfigs.debug 39 | } 40 | } 41 | } 42 | 43 | flutter { 44 | source '../..' 45 | } 46 | 47 | dependencies { 48 | } 49 | -------------------------------------------------------------------------------- /packages/agent_dart/example/windows/runner/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "flutter_window.h" 6 | #include "utils.h" 7 | 8 | int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, 9 | _In_ wchar_t *command_line, _In_ int show_command) { 10 | // Attach to console when present (e.g., 'flutter run') or create a 11 | // new console when running with a debugger. 12 | if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) { 13 | CreateAndAttachConsole(); 14 | } 15 | 16 | // Initialize COM, so that it is available for use in the library and/or 17 | // plugins. 18 | ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); 19 | 20 | flutter::DartProject project(L"data"); 21 | 22 | std::vector command_line_arguments = 23 | GetCommandLineArguments(); 24 | 25 | project.set_dart_entrypoint_arguments(std::move(command_line_arguments)); 26 | 27 | FlutterWindow window(project); 28 | Win32Window::Point origin(10, 10); 29 | Win32Window::Size size(1280, 720); 30 | if (!window.CreateAndShow(L"flutter_agent_dart_example", origin, size)) { 31 | return EXIT_FAILURE; 32 | } 33 | window.SetQuitOnClose(true); 34 | 35 | ::MSG msg; 36 | while (::GetMessage(&msg, nullptr, 0, 0)) { 37 | ::TranslateMessage(&msg); 38 | ::DispatchMessage(&msg); 39 | } 40 | 41 | ::CoUninitialize(); 42 | return EXIT_SUCCESS; 43 | } 44 | -------------------------------------------------------------------------------- /packages/agent_dart/example/macos/Podfile: -------------------------------------------------------------------------------- 1 | platform :osx, '13.0' 2 | 3 | # CocoaPods analytics sends network stats synchronously affecting flutter build latency. 4 | ENV['COCOAPODS_DISABLE_STATS'] = 'true' 5 | 6 | project 'Runner', { 7 | 'Debug' => :debug, 8 | 'Profile' => :release, 9 | 'Release' => :release, 10 | } 11 | 12 | def flutter_root 13 | generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'ephemeral', 'Flutter-Generated.xcconfig'), __FILE__) 14 | unless File.exist?(generated_xcode_build_settings_path) 15 | raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure \"flutter pub get\" is executed first" 16 | end 17 | 18 | File.foreach(generated_xcode_build_settings_path) do |line| 19 | matches = line.match(/FLUTTER_ROOT\=(.*)/) 20 | return matches[1].strip if matches 21 | end 22 | raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Flutter-Generated.xcconfig, then run \"flutter pub get\"" 23 | end 24 | 25 | require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) 26 | 27 | flutter_macos_podfile_setup 28 | 29 | target 'Runner' do 30 | use_frameworks! 31 | use_modular_headers! 32 | 33 | flutter_install_all_macos_pods File.dirname(File.realpath(__FILE__)) 34 | end 35 | 36 | post_install do |installer| 37 | installer.pods_project.targets.each do |target| 38 | flutter_additional_macos_build_settings(target) 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /packages/agent_dart_base/lib/agent/canisters/management_idl.dart: -------------------------------------------------------------------------------- 1 | import '../../candid/idl.dart'; 2 | 3 | Service managementIDL() { 4 | const canisterId = IDL.Principal; 5 | final wasmModule = IDL.Vec(IDL.Nat8); 6 | final canisterSettings = IDL.Record({ 7 | 'compute_allocation': IDL.Opt(IDL.Nat), 8 | 'memory_allocation': IDL.Opt(IDL.Nat), 9 | }); 10 | return IDL.Service({ 11 | 'provisional_create_canister_with_cycles': IDL.Func( 12 | [ 13 | IDL.Record( 14 | {'amount': IDL.Opt(IDL.Nat), 'settings': IDL.Opt(canisterSettings)}, 15 | ), 16 | ], 17 | [ 18 | IDL.Record({'canister_id': canisterId}), 19 | ], 20 | [], 21 | ), 22 | 'create_canister': IDL.Func( 23 | [], 24 | [ 25 | IDL.Record({'canister_id': canisterId}), 26 | ], 27 | [], 28 | ), 29 | 'install_code': IDL.Func( 30 | [ 31 | IDL.Record({ 32 | 'mode': IDL.Variant({ 33 | 'install': IDL.Null, 34 | 'reinstall': IDL.Null, 35 | 'upgrade': IDL.Null, 36 | }), 37 | 'canister_id': canisterId, 38 | 'wasm_module': wasmModule, 39 | 'arg': IDL.Vec(IDL.Nat8), 40 | }), 41 | ], 42 | [], 43 | [], 44 | ), 45 | 'set_controller': IDL.Func( 46 | [ 47 | IDL.Record( 48 | {'canister_id': canisterId, 'new_controller': IDL.Principal}, 49 | ), 50 | ], 51 | [], 52 | [], 53 | ), 54 | }); 55 | } 56 | -------------------------------------------------------------------------------- /packages/agent_dart/example/ios/Podfile: -------------------------------------------------------------------------------- 1 | # Uncomment this line to define a global platform for your project 2 | # platform :ios, '12.0' 3 | 4 | # CocoaPods analytics sends network stats synchronously affecting flutter build latency. 5 | ENV['COCOAPODS_DISABLE_STATS'] = 'true' 6 | 7 | project 'Runner', { 8 | 'Debug' => :debug, 9 | 'Profile' => :release, 10 | 'Release' => :release, 11 | } 12 | 13 | def flutter_root 14 | generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__) 15 | unless File.exist?(generated_xcode_build_settings_path) 16 | raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first" 17 | end 18 | 19 | File.foreach(generated_xcode_build_settings_path) do |line| 20 | matches = line.match(/FLUTTER_ROOT\=(.*)/) 21 | return matches[1].strip if matches 22 | end 23 | raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get" 24 | end 25 | 26 | require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) 27 | 28 | flutter_ios_podfile_setup 29 | 30 | target 'Runner' do 31 | use_frameworks! 32 | use_modular_headers! 33 | 34 | flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) 35 | end 36 | 37 | post_install do |installer| 38 | installer.pods_project.targets.each do |target| 39 | flutter_additional_ios_build_settings(target) 40 | end 41 | end 42 | -------------------------------------------------------------------------------- /packages/agent_dart_base/test/agent/cbor.dart: -------------------------------------------------------------------------------- 1 | import 'dart:typed_data'; 2 | 3 | import 'package:agent_dart_base/agent_dart_base.dart'; 4 | import 'package:test/test.dart'; 5 | import 'package:typed_data/typed_data.dart'; 6 | 7 | void main() { 8 | cborTest(); 9 | } 10 | 11 | void cborTest() { 12 | test('encode decode', () { 13 | final input = { 14 | 'a': 1, 15 | 'b': 'two', 16 | 'c': Uint8List.fromList([3]), 17 | 'd': {'four': 'four'}, 18 | 'e': Principal.fromHex('FfFfFfFfFfFfFfFfd7'), 19 | 'f': Uint8List.fromList([]), 20 | 'g': BigInt.parse('ffffffffffffffff', radix: 16), 21 | }; 22 | 23 | final output = cborDecode(cborEncode(input)); 24 | 25 | expect( 26 | blobToHex((output['c'] as Uint8Buffer).toU8a()), 27 | blobToHex(input['c'] as Uint8List), 28 | ); 29 | expect( 30 | (output['e'] as Uint8Buffer).toHex().toUpperCase(), 31 | (input['e'] as Principal).toHex(), 32 | ); 33 | expect(output['b'], input['b']); 34 | expect(output['a'], input['a']); 35 | expect(output['d'], input['d']); 36 | expect(output['g'], input['g']); 37 | }); 38 | test('empty canister ID', () { 39 | final input = { 40 | 'a': Principal.fromText('aaaaa-aa'), 41 | }; 42 | 43 | final output = cborDecode(cborEncode(input)); 44 | 45 | final inputA = input['a'] as Principal; 46 | final outputA = output['a'] as Uint8Buffer; 47 | 48 | expect(outputA.toHex(), inputA.toHex()); 49 | expect(Principal(outputA.toU8a()).toText(), 'aaaaa-aa'); 50 | }); 51 | } 52 | -------------------------------------------------------------------------------- /packages/agent_dart/cargokit/build_tool/lib/src/logging.dart: -------------------------------------------------------------------------------- 1 | /// This is copied from Cargokit (which is the official way to use it currently) 2 | /// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin 3 | 4 | import 'dart:io'; 5 | 6 | import 'package:logging/logging.dart'; 7 | 8 | const String kSeparator = "--"; 9 | const String kDoubleSeparator = "=="; 10 | 11 | bool _lastMessageWasSeparator = false; 12 | 13 | void _log(LogRecord rec) { 14 | final prefix = '${rec.level.name}: '; 15 | final out = rec.level == Level.SEVERE ? stderr : stdout; 16 | if (rec.message == kSeparator) { 17 | if (!_lastMessageWasSeparator) { 18 | out.write(prefix); 19 | out.writeln('-' * 80); 20 | _lastMessageWasSeparator = true; 21 | } 22 | return; 23 | } else if (rec.message == kDoubleSeparator) { 24 | out.write(prefix); 25 | out.writeln('=' * 80); 26 | _lastMessageWasSeparator = true; 27 | return; 28 | } 29 | out.write(prefix); 30 | out.writeln(rec.message); 31 | _lastMessageWasSeparator = false; 32 | } 33 | 34 | void initLogging() { 35 | Logger.root.level = Level.INFO; 36 | Logger.root.onRecord.listen((LogRecord rec) { 37 | final lines = rec.message.split('\n'); 38 | for (final line in lines) { 39 | if (line.isNotEmpty || lines.length == 1 || line != lines.last) { 40 | _log(LogRecord( 41 | rec.level, 42 | line, 43 | rec.loggerName, 44 | )); 45 | } 46 | } 47 | }); 48 | } 49 | 50 | void enableVerboseLogging() { 51 | Logger.root.level = Level.ALL; 52 | } 53 | -------------------------------------------------------------------------------- /packages/agent_dart/example/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | # This file configures the analyzer, which statically analyzes Dart code to 2 | # check for errors, warnings, and lints. 3 | # 4 | # The issues identified by the analyzer are surfaced in the UI of Dart-enabled 5 | # IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be 6 | # invoked from the command line by running `flutter analyze`. 7 | 8 | # The following line activates a set of recommended lints for Flutter apps, 9 | # packages, and plugins designed to encourage good coding practices. 10 | include: package:flutter_lints/flutter.yaml 11 | 12 | linter: 13 | # The lint rules applied to this project can be customized in the 14 | # section below to disable rules from the `package:flutter_lints/flutter.yaml` 15 | # included above or to enable additional rules. A list of all available lints 16 | # and their documentation is published at 17 | # https://dart-lang.github.io/linter/lints/index.html. 18 | # 19 | # Instead of disabling a lint rule for the entire project in the 20 | # section below, it can also be suppressed for a single line of code 21 | # or a specific dart file by using the `// ignore: name_of_lint` and 22 | # `// ignore_for_file: name_of_lint` syntax on the line or in the file 23 | # producing the lint. 24 | rules: 25 | # avoid_print: false # Uncomment to disable the `avoid_print` rule 26 | # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule 27 | 28 | # Additional information about this file can be found at 29 | # https://dart.dev/guides/language/analysis-options 30 | -------------------------------------------------------------------------------- /packages/agent_dart_base/test/test_utils.dart: -------------------------------------------------------------------------------- 1 | import 'dart:ffi'; 2 | 3 | import 'package:agent_dart_ffi/agent_dart_ffi.dart'; 4 | import 'package:test/test.dart'; 5 | 6 | Future ffiInit() async { 7 | // ignore: invalid_use_of_internal_member 8 | if (AgentDart.instance.initialized) { 9 | return; 10 | } 11 | final [os, arch] = Abi.current().toString().split('_'); 12 | final libName = switch ((os, arch)) { 13 | ('macos', _) || ('linux', 'arm64') => 'libagent_dart.dylib', 14 | ('linux', _) => 'libagent_dart.so', 15 | ('windows', _) => 'agent_dart.dll', 16 | _ => throw UnsupportedError('$os $arch is not a supported platform.'), 17 | }; 18 | return AgentDart.init( 19 | externalLibrary: ExternalLibrary.open('../../target/debug/$libName'), 20 | ); 21 | } 22 | 23 | const isAssertionError = TypeMatcher(); 24 | 25 | Matcher assertionThrowsContains(String str) { 26 | return isAssertionError.having((e) => e.toString(), 'message', contains(str)); 27 | } 28 | 29 | Matcher rangeThrowsContains(String str) { 30 | return isRangeError.having((e) => e.end, 'end', contains(str)); 31 | } 32 | 33 | ErrorMessageMatcher isError([String? message]) => 34 | ErrorMessageMatcher(message); 35 | 36 | class ErrorMessageMatcher extends TypeMatcher { 37 | const ErrorMessageMatcher([String? message]) : _message = message; 38 | 39 | final String? _message; 40 | 41 | @override 42 | bool matches(Object? item, Map matchState) => 43 | item is T && (_message == null || (item as dynamic).message == _message); 44 | } 45 | -------------------------------------------------------------------------------- /packages/agent_dart/android/build.gradle: -------------------------------------------------------------------------------- 1 | // The Android Gradle Plugin builds the native code with the Android NDK. 2 | 3 | group 'com.astrox.agent_dart' 4 | version '1.0.0-SNAPSHOT' 5 | 6 | buildscript { 7 | repositories { 8 | google() 9 | mavenCentral() 10 | } 11 | 12 | dependencies { 13 | // The Android Gradle Plugin knows how to build native code with the NDK. 14 | classpath 'com.android.tools.build:gradle:7.3.0' 15 | } 16 | } 17 | 18 | rootProject.allprojects { 19 | repositories { 20 | google() 21 | mavenCentral() 22 | } 23 | } 24 | 25 | apply plugin: 'com.android.library' 26 | 27 | android { 28 | if (project.android.hasProperty("namespace")) { 29 | namespace 'com.astrox.agent_dart' 30 | } 31 | 32 | // Bumping the plugin compileSdkVersion requires all clients of this plugin 33 | // to bump the version in their app. 34 | compileSdkVersion 33 35 | 36 | defaultConfig { 37 | minSdkVersion 19 38 | } 39 | 40 | // Use the NDK version 41 | // declared in /android/app/build.gradle file of the Flutter project. 42 | // Replace it with a version number if this plugin requires a specfic NDK version. 43 | // (e.g. ndkVersion "23.1.7779620") 44 | ndkVersion android.ndkVersion 45 | 46 | compileOptions { 47 | sourceCompatibility JavaVersion.VERSION_1_8 48 | targetCompatibility JavaVersion.VERSION_1_8 49 | } 50 | } 51 | 52 | dependencies { 53 | } 54 | 55 | apply from: "../cargokit/gradle/plugin.gradle" 56 | cargokit { 57 | manifestDir = "../native/agent_dart" 58 | libname = "agent_dart" 59 | } 60 | -------------------------------------------------------------------------------- /packages/agent_dart_ffi/native/ed_compact/src/error.rs: -------------------------------------------------------------------------------- 1 | use core::fmt::{self, Display}; 2 | 3 | #[derive(Debug, Copy, Clone, Eq, PartialEq)] 4 | pub enum Error { 5 | /// The signature doesn't verify. 6 | SignatureMismatch, 7 | /// A weak public key was used. 8 | WeakPublicKey, 9 | /// The public key is invalid. 10 | InvalidPublicKey, 11 | /// The secret key is invalid. 12 | InvalidSecretKey, 13 | /// The signature is invalid. 14 | InvalidSignature, 15 | /// The seed doesn't have the expected length. 16 | InvalidSeed, 17 | /// The blind doesn't have the expected length. 18 | InvalidBlind, 19 | /// The noise doesn't have the expected length. 20 | InvalidNoise, 21 | /// Parse error 22 | ParseError, 23 | } 24 | 25 | #[cfg(feature = "std")] 26 | impl std::error::Error for Error {} 27 | 28 | impl Display for Error { 29 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 30 | match self { 31 | Error::SignatureMismatch => write!(f, "Signature doesn't verify"), 32 | Error::WeakPublicKey => write!(f, "Weak public key"), 33 | Error::InvalidPublicKey => write!(f, "Invalid public key"), 34 | Error::InvalidSecretKey => write!(f, "Invalid secret key"), 35 | Error::InvalidSignature => write!(f, "Invalid signature"), 36 | Error::InvalidSeed => write!(f, "Invalid seed length"), 37 | Error::InvalidBlind => write!(f, "Invalid blind length"), 38 | Error::InvalidNoise => write!(f, "Invalid noise length"), 39 | Error::ParseError => write!(f, "Parse error"), 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /packages/agent_dart/cargokit/build_tool/lib/src/cargo.dart: -------------------------------------------------------------------------------- 1 | /// This is copied from Cargokit (which is the official way to use it currently) 2 | /// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin 3 | 4 | import 'dart:io'; 5 | 6 | import 'package:path/path.dart' as path; 7 | import 'package:toml/toml.dart'; 8 | 9 | class ManifestException { 10 | ManifestException(this.message, {required this.fileName}); 11 | 12 | final String? fileName; 13 | final String message; 14 | 15 | @override 16 | String toString() { 17 | if (fileName != null) { 18 | return 'Failed to parse package manifest at $fileName: $message'; 19 | } else { 20 | return 'Failed to parse package manifest: $message'; 21 | } 22 | } 23 | } 24 | 25 | class CrateInfo { 26 | CrateInfo({required this.packageName}); 27 | 28 | final String packageName; 29 | 30 | static CrateInfo parseManifest(String manifest, {final String? fileName}) { 31 | final toml = TomlDocument.parse(manifest); 32 | final package = toml.toMap()['package']; 33 | if (package == null) { 34 | throw ManifestException('Missing package section', fileName: fileName); 35 | } 36 | final name = package['name']; 37 | if (name == null) { 38 | throw ManifestException('Missing package name', fileName: fileName); 39 | } 40 | return CrateInfo(packageName: name); 41 | } 42 | 43 | static CrateInfo load(String manifestDir) { 44 | final manifestFile = File(path.join(manifestDir, 'Cargo.toml')); 45 | final manifest = manifestFile.readAsStringSync(); 46 | return parseManifest(manifest, fileName: manifestFile.path); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /packages/agent_dart/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "16x16", 5 | "idiom" : "mac", 6 | "filename" : "app_icon_16.png", 7 | "scale" : "1x" 8 | }, 9 | { 10 | "size" : "16x16", 11 | "idiom" : "mac", 12 | "filename" : "app_icon_32.png", 13 | "scale" : "2x" 14 | }, 15 | { 16 | "size" : "32x32", 17 | "idiom" : "mac", 18 | "filename" : "app_icon_32.png", 19 | "scale" : "1x" 20 | }, 21 | { 22 | "size" : "32x32", 23 | "idiom" : "mac", 24 | "filename" : "app_icon_64.png", 25 | "scale" : "2x" 26 | }, 27 | { 28 | "size" : "128x128", 29 | "idiom" : "mac", 30 | "filename" : "app_icon_128.png", 31 | "scale" : "1x" 32 | }, 33 | { 34 | "size" : "128x128", 35 | "idiom" : "mac", 36 | "filename" : "app_icon_256.png", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "size" : "256x256", 41 | "idiom" : "mac", 42 | "filename" : "app_icon_256.png", 43 | "scale" : "1x" 44 | }, 45 | { 46 | "size" : "256x256", 47 | "idiom" : "mac", 48 | "filename" : "app_icon_512.png", 49 | "scale" : "2x" 50 | }, 51 | { 52 | "size" : "512x512", 53 | "idiom" : "mac", 54 | "filename" : "app_icon_512.png", 55 | "scale" : "1x" 56 | }, 57 | { 58 | "size" : "512x512", 59 | "idiom" : "mac", 60 | "filename" : "app_icon_1024.png", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /packages/agent_dart_ffi/native/agent_dart/src/bls/mod copy.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2020 MIRACL UK Ltd. 3 | * 4 | * This file is part of MIRACL Core 5 | * (see https://github.com/miracl/core). 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | pub mod aes; 20 | pub mod arch; 21 | pub mod gcm; 22 | pub mod hash256; 23 | pub mod hash384; 24 | pub mod hash512; 25 | pub mod hmac; 26 | pub mod nhs; 27 | pub mod rand; 28 | pub mod sha3; 29 | pub mod share; 30 | 31 | pub mod bls12381; 32 | 33 | #[test] 34 | fn bls_verify() { 35 | use bls12381::bls::{core_verify, init, BLS_FAIL, BLS_OK}; 36 | let pk = hex::decode("a7623a93cdb56c4d23d99c14216afaab3dfd6d4f9eb3db23d038280b6d5cb2caaee2a19dd92c9df7001dede23bf036bc0f33982dfb41e8fa9b8e96b5dc3e83d55ca4dd146c7eb2e8b6859cb5a5db815db86810b8d12cee1588b5dbf34a4dc9a5").unwrap(); 37 | let sig = hex::decode("b89e13a212c830586eaa9ad53946cd968718ebecc27eda849d9232673dcd4f440e8b5df39bf14a88048c15e16cbcaabe").unwrap(); 38 | assert_eq!(init(), BLS_OK); 39 | assert_eq!(core_verify(&sig, b"hello".as_ref(), &pk), BLS_OK); 40 | assert_eq!(core_verify(&sig, b"hallo".as_ref(), &pk), BLS_FAIL); 41 | } 42 | -------------------------------------------------------------------------------- /packages/agent_dart/.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled. 5 | 6 | version: 7 | revision: 135454af32477f815a7525073027a3ff9eff1bfd 8 | channel: stable 9 | 10 | project_type: plugin_ffi 11 | 12 | # Tracks metadata for the flutter migrate command 13 | migration: 14 | platforms: 15 | - platform: root 16 | create_revision: 135454af32477f815a7525073027a3ff9eff1bfd 17 | base_revision: 135454af32477f815a7525073027a3ff9eff1bfd 18 | - platform: android 19 | create_revision: 135454af32477f815a7525073027a3ff9eff1bfd 20 | base_revision: 135454af32477f815a7525073027a3ff9eff1bfd 21 | - platform: ios 22 | create_revision: 135454af32477f815a7525073027a3ff9eff1bfd 23 | base_revision: 135454af32477f815a7525073027a3ff9eff1bfd 24 | - platform: linux 25 | create_revision: 135454af32477f815a7525073027a3ff9eff1bfd 26 | base_revision: 135454af32477f815a7525073027a3ff9eff1bfd 27 | - platform: macos 28 | create_revision: 135454af32477f815a7525073027a3ff9eff1bfd 29 | base_revision: 135454af32477f815a7525073027a3ff9eff1bfd 30 | - platform: windows 31 | create_revision: 135454af32477f815a7525073027a3ff9eff1bfd 32 | base_revision: 135454af32477f815a7525073027a3ff9eff1bfd 33 | 34 | # User provided section 35 | 36 | # List of Local paths (relative to this file) that should be 37 | # ignored by the migrate tool. 38 | # 39 | # Files that are not part of the templates will be ignored by default. 40 | unmanaged_files: 41 | - 'lib/main.dart' 42 | - 'ios/Runner.xcodeproj/project.pbxproj' 43 | -------------------------------------------------------------------------------- /.github/workflows/runnable.yml: -------------------------------------------------------------------------------- 1 | name: Runnable (stable) 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | pull_request: 8 | branches: 9 | - main 10 | 11 | jobs: 12 | test: 13 | name: Analyze on ${{ matrix.os }} 14 | runs-on: ${{ matrix.os }} 15 | strategy: 16 | matrix: 17 | os: [ubuntu-latest, macos-latest, windows-latest] 18 | steps: 19 | - uses: actions/checkout@v4 20 | - uses: dtolnay/rust-toolchain@stable 21 | with: 22 | toolchain: stable 23 | components: rustfmt, clippy 24 | - uses: actions/setup-java@v4 25 | with: 26 | distribution: 'zulu' 27 | java-version: '17' 28 | - uses: flutter-actions/setup-flutter@v4 29 | with: 30 | channel: stable 31 | cache: true 32 | - uses: bluefireteam/melos-action@v3 33 | - name: Replace symlinks 34 | run: ./scripts/replace_symlinks_before_publish.sh 35 | - run: cargo build --package=agent_dart 36 | - run: cd packages/agent_dart_base && dart test ./test/agent_dart_base_test.dart 37 | - name: Publish dry run 38 | run: melos run publish-dry-run 39 | if: ${{ github.repository == 'AstroxNetwork/agent_dart' && matrix.os == 'ubuntu-latest' }} 40 | - name: Build example 41 | working-directory: packages/agent_dart/example 42 | shell: bash 43 | run: | 44 | if [[ "${{ matrix.os }}" == 'macos-latest' ]]; then 45 | flutter build ios --debug --no-codesign 46 | elif [[ "${{ matrix.os }}" == 'ubuntu-latest' ]]; then 47 | flutter build apk --debug 48 | else 49 | echo "Well, nothing." 50 | fi 51 | -------------------------------------------------------------------------------- /packages/agent_dart/example/ios/Runner/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /packages/agent_dart/cargokit/build_tool/lib/src/build_gradle.dart: -------------------------------------------------------------------------------- 1 | /// This is copied from Cargokit (which is the official way to use it currently) 2 | /// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin 3 | 4 | import 'dart:io'; 5 | 6 | import 'package:logging/logging.dart'; 7 | import 'package:path/path.dart' as path; 8 | 9 | import 'artifacts_provider.dart'; 10 | import 'builder.dart'; 11 | import 'environment.dart'; 12 | import 'options.dart'; 13 | import 'target.dart'; 14 | 15 | final log = Logger('build_gradle'); 16 | 17 | class BuildGradle { 18 | BuildGradle({required this.userOptions}); 19 | 20 | final CargokitUserOptions userOptions; 21 | 22 | Future build() async { 23 | final targets = Environment.targetPlatforms.map((arch) { 24 | final target = Target.forFlutterName(arch); 25 | if (target == null) { 26 | throw Exception( 27 | "Unknown darwin target or platform: $arch, ${Environment.darwinPlatformName}"); 28 | } 29 | return target; 30 | }).toList(); 31 | 32 | final environment = BuildEnvironment.fromEnvironment(isAndroid: true); 33 | final provider = 34 | ArtifactProvider(environment: environment, userOptions: userOptions); 35 | final artifacts = await provider.getArtifacts(targets); 36 | 37 | for (final target in targets) { 38 | final libs = artifacts[target]!; 39 | final outputDir = path.join(Environment.outputDir, target.android!); 40 | Directory(outputDir).createSync(recursive: true); 41 | 42 | for (final lib in libs) { 43 | if (lib.type == AritifactType.dylib) { 44 | File(lib.path).copySync(path.join(outputDir, lib.finalFileName)); 45 | } 46 | } 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /packages/agent_dart_ffi/native/agent_dart/src/keyring.rs: -------------------------------------------------------------------------------- 1 | use crate::errors::ErrorInfo; 2 | use crate::types::{PhraseToSeedReq, SeedToKeyReq}; 3 | use bip32::XPrv; 4 | use bip39::{Language, Mnemonic}; 5 | 6 | #[derive(Clone, Debug)] 7 | pub struct KeyRingFFI {} 8 | 9 | impl KeyRingFFI { 10 | pub fn phrase_to_seed(req: PhraseToSeedReq) -> Vec { 11 | match Mnemonic::parse_in_normalized(Language::English, req.phrase.as_str()) { 12 | Ok(r) => r.to_seed(&req.password).to_vec(), 13 | Err(_) => { 14 | panic!( 15 | "{}", 16 | ErrorInfo { 17 | code: 0u32, 18 | message: "Phrase To Seed Error".to_string(), 19 | } 20 | .to_json() 21 | ) 22 | } 23 | } 24 | } 25 | 26 | pub fn seed_to_key(req: SeedToKeyReq) -> Vec { 27 | match XPrv::derive_from_path( 28 | &req.seed, 29 | &req.path 30 | .as_str() 31 | .parse() 32 | .map_err(|_| { 33 | panic!( 34 | "{}", 35 | ErrorInfo { 36 | code: 0u32, 37 | message: "path is not correct".to_string(), 38 | } 39 | .to_json() 40 | ) 41 | }) 42 | .unwrap(), 43 | ) { 44 | Ok(r) => r.private_key().to_bytes().to_vec(), 45 | Err(e) => panic!( 46 | "{}", 47 | ErrorInfo { 48 | code: 0u32, 49 | message: e.to_string(), 50 | } 51 | .to_json() 52 | ), 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /packages/agent_dart/example/lib/main.dart: -------------------------------------------------------------------------------- 1 | import 'package:agent_dart/agent_dart.dart'; 2 | import 'package:flutter/material.dart'; 3 | 4 | void main() async { 5 | WidgetsFlutterBinding.ensureInitialized(); 6 | await AgentDart.init(); 7 | runApp(const MyApp()); 8 | } 9 | 10 | class MyApp extends StatefulWidget { 11 | const MyApp({super.key}); 12 | 13 | @override 14 | State createState() => _MyAppState(); 15 | } 16 | 17 | class _MyAppState extends State { 18 | String phrase = generateMnemonic(); 19 | 20 | void _refreshMnemonic() { 21 | phrase = generateMnemonic(); 22 | } 23 | 24 | @override 25 | Widget build(BuildContext context) { 26 | const textStyle = TextStyle(fontSize: 25); 27 | return MaterialApp( 28 | home: Scaffold( 29 | appBar: AppBar( 30 | title: const Text('Native Packages'), 31 | ), 32 | body: SingleChildScrollView( 33 | child: Container( 34 | padding: const EdgeInsets.all(10), 35 | child: Column( 36 | children: [ 37 | Text( 38 | 'Phrase: $phrase', 39 | style: textStyle, 40 | textAlign: TextAlign.center, 41 | ), 42 | FutureBuilder( 43 | future: mnemonicPhraseToSeed( 44 | req: PhraseToSeedReq(phrase: phrase, password: ''), 45 | ), 46 | builder: (context, snapshot) => 47 | Text('Seed: ${snapshot.data?.toHex()}'), 48 | ), 49 | ], 50 | ), 51 | ), 52 | ), 53 | floatingActionButton: FloatingActionButton( 54 | onPressed: () { 55 | _refreshMnemonic(); 56 | }, 57 | child: const Icon(Icons.refresh), 58 | ), 59 | ), 60 | ); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /packages/agent_dart/example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 7 | 15 | 19 | 23 | 24 | 25 | 26 | 27 | 28 | 30 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /packages/agent_dart/example/windows/runner/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | project(runner LANGUAGES CXX) 3 | 4 | # Define the application target. To change its name, change BINARY_NAME in the 5 | # top-level CMakeLists.txt, not the value here, or `flutter run` will no longer 6 | # work. 7 | # 8 | # Any new source files that you add to the application should be added here. 9 | add_executable(${BINARY_NAME} WIN32 10 | "flutter_window.cpp" 11 | "main.cpp" 12 | "utils.cpp" 13 | "win32_window.cpp" 14 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" 15 | "Runner.rc" 16 | "runner.exe.manifest" 17 | ) 18 | 19 | # Apply the standard set of build settings. This can be removed for applications 20 | # that need different build settings. 21 | apply_standard_settings(${BINARY_NAME}) 22 | 23 | # Add preprocessor definitions for the build version. 24 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION=\"${FLUTTER_VERSION}\"") 25 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MAJOR=${FLUTTER_VERSION_MAJOR}") 26 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MINOR=${FLUTTER_VERSION_MINOR}") 27 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_PATCH=${FLUTTER_VERSION_PATCH}") 28 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_BUILD=${FLUTTER_VERSION_BUILD}") 29 | 30 | # Disable Windows macros that collide with C++ standard library functions. 31 | target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") 32 | 33 | # Add dependency libraries and include directories. Add any application-specific 34 | # dependencies here. 35 | target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) 36 | target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") 37 | 38 | # Run the Flutter tool portions of the build. This must not be removed. 39 | add_dependencies(${BINARY_NAME} flutter_assemble) 40 | -------------------------------------------------------------------------------- /packages/agent_dart_base/lib/agent/agent/http/transform.dart: -------------------------------------------------------------------------------- 1 | import 'dart:typed_data'; 2 | 3 | import 'package:cbor/cbor.dart' as cbor; 4 | import 'package:typed_data/typed_data.dart'; 5 | 6 | import '../../cbor.dart'; 7 | import '../../types.dart'; 8 | import '../../utils/leb128.dart'; 9 | import 'types.dart'; 10 | 11 | final _nanoSecondsPerMilliseconds = BigInt.from(1000000); 12 | final _replicaPermittedDriftMilliseconds = BigInt.from(60 * 1000); 13 | const _kIsWeb = bool.hasEnvironment('dart.library.js_util') 14 | ? bool.fromEnvironment('dart.library.js_util') 15 | : identical(0, 0.0); 16 | 17 | class Expiry extends ToCborable { 18 | Expiry( 19 | int deltaInMSec, 20 | ) : _value = (BigInt.from(DateTime.now().millisecondsSinceEpoch) + 21 | BigInt.from(deltaInMSec) - 22 | _replicaPermittedDriftMilliseconds) * 23 | _nanoSecondsPerMilliseconds; 24 | 25 | final BigInt _value; 26 | 27 | BigInt get value => _value; 28 | 29 | Uint8List toHash() { 30 | return lebEncode(_value); 31 | } 32 | 33 | @override 34 | void write(cbor.Encoder encoder) { 35 | if (_kIsWeb) { 36 | final data = serializeValue(0, 27, _value.toRadixString(16)); 37 | final buf = Uint8Buffer(); 38 | buf.addAll(data.asUint8List()); 39 | encoder.addBuilderOutput(buf); 40 | } else { 41 | encoder.writeInt(_value.toInt()); 42 | } 43 | } 44 | } 45 | 46 | HttpAgentRequestTransformFnCall makeNonceTransform([ 47 | NonceFunc nonceFn = makeNonce, 48 | ]) { 49 | return (HttpAgentRequest request) async { 50 | // Nonce are only useful for async calls, to prevent replay attacks. Other types of 51 | // calls don't need Nonce so we just skip creating one. 52 | if (request.endpoint == Endpoint.call) { 53 | (request as HttpAgentSubmitRequest).body.nonce = nonceFn(); 54 | } 55 | return request; 56 | }; 57 | } 58 | 59 | typedef NonceFunc = Nonce Function(); 60 | -------------------------------------------------------------------------------- /packages/agent_dart/example/ios/Runner/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleDisplayName 8 | Flutter Agent Dart 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | flutter_agent_dart_example 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | $(FLUTTER_BUILD_NAME) 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | $(FLUTTER_BUILD_NUMBER) 25 | LSRequiresIPhoneOS 26 | 27 | UILaunchStoryboardName 28 | LaunchScreen 29 | UIMainStoryboardFile 30 | Main 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | UIViewControllerBasedStatusBarAppearance 45 | 46 | CADisableMinimumFrameDurationOnPhone 47 | 48 | UIApplicationSupportsIndirectInputEvents 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /packages/agent_dart/example/windows/runner/utils.cpp: -------------------------------------------------------------------------------- 1 | #include "utils.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | void CreateAndAttachConsole() { 11 | if (::AllocConsole()) { 12 | FILE *unused; 13 | if (freopen_s(&unused, "CONOUT$", "w", stdout)) { 14 | _dup2(_fileno(stdout), 1); 15 | } 16 | if (freopen_s(&unused, "CONOUT$", "w", stderr)) { 17 | _dup2(_fileno(stdout), 2); 18 | } 19 | std::ios::sync_with_stdio(); 20 | FlutterDesktopResyncOutputStreams(); 21 | } 22 | } 23 | 24 | std::vector GetCommandLineArguments() { 25 | // Convert the UTF-16 command line arguments to UTF-8 for the Engine to use. 26 | int argc; 27 | wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc); 28 | if (argv == nullptr) { 29 | return std::vector(); 30 | } 31 | 32 | std::vector command_line_arguments; 33 | 34 | // Skip the first argument as it's the binary name. 35 | for (int i = 1; i < argc; i++) { 36 | command_line_arguments.push_back(Utf8FromUtf16(argv[i])); 37 | } 38 | 39 | ::LocalFree(argv); 40 | 41 | return command_line_arguments; 42 | } 43 | 44 | std::string Utf8FromUtf16(const wchar_t* utf16_string) { 45 | if (utf16_string == nullptr) { 46 | return std::string(); 47 | } 48 | int target_length = ::WideCharToMultiByte( 49 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, 50 | -1, nullptr, 0, nullptr, nullptr); 51 | std::string utf8_string; 52 | if (target_length == 0 || target_length > utf8_string.max_size()) { 53 | return utf8_string; 54 | } 55 | utf8_string.resize(target_length); 56 | int converted_length = ::WideCharToMultiByte( 57 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, 58 | -1, utf8_string.data(), 59 | target_length, nullptr, nullptr); 60 | if (converted_length == 0) { 61 | return std::string(); 62 | } 63 | return utf8_string; 64 | } 65 | -------------------------------------------------------------------------------- /packages/agent_dart_base/test/identity/p256.dart: -------------------------------------------------------------------------------- 1 | import 'package:agent_dart_base/agent_dart_base.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | void main() { 5 | p256Test(); 6 | } 7 | 8 | void p256Test() { 9 | const prv = 10 | '4af1bceebf7f3634ec3cff8a2c38e51178d5d4ce585c52d6043e5e2cc3418bb0'; 11 | const msg = 'Hello world'; 12 | 13 | test('sign', () async { 14 | final res = await signP256Async( 15 | msg.plainToU8a(), 16 | prv.toU8a(), 17 | ); 18 | final derSig = bytesWrapDerSignature(res); 19 | final unWrapDer = bytesUnwrapDerSignature(derSig); 20 | expect(unWrapDer.toHex(), res.toHex()); 21 | final pub = (await P256Identity.fromSecretKey(prv.toU8a())).getPublicKey(); 22 | 23 | expect(res.length, 64); 24 | 25 | final isValid = await verifyP256Async( 26 | msg.plainToU8a(), 27 | res, 28 | pub, 29 | ); 30 | expect(isValid, true); 31 | }); 32 | 33 | test('ffi', () async { 34 | final key = await getECKeysAsync(generateMnemonic()); 35 | 36 | final derExpect = P256PublicKey.fromRaw(key.ecP256PublicKey!).toDer(); 37 | print(derExpect.toHex()); 38 | 39 | expect( 40 | derExpect.toHex(), 41 | P256PublicKey.fromDer(await getP256DerPubFromFFI(key.ecPrivateKey!)) 42 | .toDer() 43 | .toHex(), 44 | ); 45 | 46 | final testSig = 47 | '3045022063de4381640b62f0f563ebd1723faacb5d147262b1ab9ae2cf174ea0e096bc3a022100a8dcc496fb5d92ab2c91455773d21fc42933ed3231e6d66889c3b4252cf852b4' 48 | .toU8a(); 49 | 50 | final rawSig = bytesUnwrapDerSignature(testSig); 51 | print( 52 | await verifyP256Async( 53 | 'Hello world'.plainToU8a(), 54 | rawSig, // rawSig, 55 | P256PublicKey.fromDer( 56 | '3059301306072a8648ce3d020106082a8648ce3d030107034200047c453323484efff2779f0c050dd7681a99134c70b9dea729f455f27f7eee7b6e87db17cb4b9541b67f260d713b881f320356da02d9d1747bcd2935f7e3d8f14f' 57 | .toU8a(), 58 | ), 59 | ), 60 | ); 61 | }); 62 | } 63 | -------------------------------------------------------------------------------- /packages/agent_dart/example/windows/runner/flutter_window.cpp: -------------------------------------------------------------------------------- 1 | #include "flutter_window.h" 2 | 3 | #include 4 | 5 | #include "flutter/generated_plugin_registrant.h" 6 | 7 | FlutterWindow::FlutterWindow(const flutter::DartProject& project) 8 | : project_(project) {} 9 | 10 | FlutterWindow::~FlutterWindow() {} 11 | 12 | bool FlutterWindow::OnCreate() { 13 | if (!Win32Window::OnCreate()) { 14 | return false; 15 | } 16 | 17 | RECT frame = GetClientArea(); 18 | 19 | // The size here must match the window dimensions to avoid unnecessary surface 20 | // creation / destruction in the startup path. 21 | flutter_controller_ = std::make_unique( 22 | frame.right - frame.left, frame.bottom - frame.top, project_); 23 | // Ensure that basic setup of the controller was successful. 24 | if (!flutter_controller_->engine() || !flutter_controller_->view()) { 25 | return false; 26 | } 27 | RegisterPlugins(flutter_controller_->engine()); 28 | SetChildContent(flutter_controller_->view()->GetNativeWindow()); 29 | return true; 30 | } 31 | 32 | void FlutterWindow::OnDestroy() { 33 | if (flutter_controller_) { 34 | flutter_controller_ = nullptr; 35 | } 36 | 37 | Win32Window::OnDestroy(); 38 | } 39 | 40 | LRESULT 41 | FlutterWindow::MessageHandler(HWND hwnd, UINT const message, 42 | WPARAM const wparam, 43 | LPARAM const lparam) noexcept { 44 | // Give Flutter, including plugins, an opportunity to handle window messages. 45 | if (flutter_controller_) { 46 | std::optional result = 47 | flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam, 48 | lparam); 49 | if (result) { 50 | return *result; 51 | } 52 | } 53 | 54 | switch (message) { 55 | case WM_FONTCHANGE: 56 | flutter_controller_->engine()->ReloadSystemFonts(); 57 | break; 58 | } 59 | 60 | return Win32Window::MessageHandler(hwnd, message, wparam, lparam); 61 | } 62 | -------------------------------------------------------------------------------- /packages/agent_dart_base/lib/agent/crypto/keystore/key_derivator.dart: -------------------------------------------------------------------------------- 1 | part of 'key_store.dart'; 2 | 3 | @immutable 4 | abstract class KeyDerivator { 5 | const KeyDerivator(); 6 | 7 | Uint8List deriveKey(List password); 8 | 9 | String getName(); 10 | 11 | Map encode(); 12 | } 13 | 14 | class _PBDKDF2KeyDerivator extends KeyDerivator { 15 | const _PBDKDF2KeyDerivator(this.iterations, this.salt, this.dklen); 16 | 17 | final int iterations; 18 | final Uint8List salt; 19 | final int dklen; 20 | 21 | /// The docs (https://github.com/ethereum/wiki/wiki/Web3-Secret-Storage-Definition) 22 | /// say that HMAC with SHA-256 is the only mac supported at the moment. 23 | static final Mac mac = HMac(SHA256Digest(), 64); 24 | 25 | @override 26 | Uint8List deriveKey(List password) { 27 | final impl = PBKDF2KeyDerivator(mac) 28 | ..init(Pbkdf2Parameters(salt, iterations, dklen)); 29 | return impl.process(Uint8List.fromList(password)); 30 | } 31 | 32 | @override 33 | Map encode() { 34 | return { 35 | 'c': iterations, 36 | 'dklen': dklen, 37 | 'prf': 'hmac-sha256', 38 | 'salt': salt.toHex(), 39 | }; 40 | } 41 | 42 | @override 43 | String getName() => 'pbkdf2'; 44 | } 45 | 46 | class _ScryptKeyDerivator extends KeyDerivator { 47 | const _ScryptKeyDerivator(this.dklen, this.n, this.r, this.p, this.salt); 48 | 49 | final int dklen; 50 | final int n; 51 | final int r; 52 | final int p; 53 | final List salt; 54 | 55 | @override 56 | Uint8List deriveKey(List password) { 57 | final impl = Scrypt() 58 | ..init(ScryptParameters(n, r, p, dklen, Uint8List.fromList(salt))); 59 | return impl.process(Uint8List.fromList(password)); 60 | } 61 | 62 | @override 63 | Map encode() { 64 | return { 65 | 'dklen': dklen, 66 | 'n': n, 67 | 'r': r, 68 | 'p': p, 69 | 'salt': Uint8List.fromList(salt).toHex(), 70 | }; 71 | } 72 | 73 | @override 74 | String getName() => 'scrypt'; 75 | } 76 | -------------------------------------------------------------------------------- /packages/agent_dart/agent_dart.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /packages/agent_dart_ffi/native/agent_dart/src/ed25519.rs: -------------------------------------------------------------------------------- 1 | use crate::types::{ED25519FromSeedReq, ED25519Res, ED25519SignReq, ED25519VerifyReq}; 2 | use ed_compact::{KeyPair, PublicKey, Seed, Signature}; 3 | 4 | pub struct ED25519FFI {} 5 | 6 | impl ED25519FFI { 7 | pub fn ed25519_from_blob(req: ED25519FromSeedReq) -> ED25519Res { 8 | ED25519Res { 9 | seed: req.seed.clone(), 10 | public_key: KeyPair::from_seed( 11 | Seed::from_slice(req.seed.clone().as_slice()).unwrap_or_else(|e| { 12 | panic!( 13 | "{}", 14 | format!("ed25519 seed from slice error: {}", e.to_string()) 15 | ) 16 | }), 17 | ) 18 | .pk 19 | .as_ref() 20 | .to_vec(), 21 | } 22 | } 23 | 24 | pub fn ed25519_sign(req: ED25519SignReq) -> Vec { 25 | KeyPair::from_seed(Seed::from_slice(req.seed.as_slice()).unwrap_or_else(|e| { 26 | panic!( 27 | "{}", 28 | format!("ed25519 seed from slice error: {}", e.to_string()) 29 | ) 30 | })) 31 | .sk 32 | .sign(req.message.as_slice(), None) 33 | .as_ref() 34 | .to_vec() 35 | } 36 | 37 | pub fn ed25519_verify(req: ED25519VerifyReq) -> bool { 38 | let peer_public_key = PublicKey::from_slice(req.pub_key.as_slice()).unwrap_or_else(|e| { 39 | panic!( 40 | "{}", 41 | format!("ed25519 public key from error: {}", e.to_string()) 42 | ) 43 | }); 44 | match peer_public_key.verify( 45 | req.message.as_slice(), 46 | &Signature::from_slice(req.sig.as_slice()).unwrap_or_else(|e| { 47 | panic!( 48 | "{}", 49 | format!("ed25519 signature from error: {}", e.to_string()) 50 | ) 51 | }), 52 | ) { 53 | Ok(_) => true, 54 | Err(_) => false, 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /packages/agent_dart/cargokit/LICENSE: -------------------------------------------------------------------------------- 1 | /// This is copied from Cargokit (which is the official way to use it currently) 2 | /// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin 3 | 4 | Copyright 2022 Matej Knopp 5 | 6 | ================================================================================ 7 | 8 | MIT LICENSE 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining a copy 11 | of this software and associated documentation files (the "Software"), to deal 12 | in the Software without restriction, including without limitation the rights 13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 14 | of the Software, and to permit persons to whom the Software is furnished to do 15 | so, subject to the following conditions: 16 | 17 | The above copyright notice and this permission notice shall be included in all 18 | copies or substantial portions of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 22 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 23 | OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 25 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 | 27 | ================================================================================ 28 | 29 | APACHE LICENSE, VERSION 2.0 30 | 31 | Licensed under the Apache License, Version 2.0 (the "License"); 32 | you may not use this file except in compliance with the License. 33 | You may obtain a copy of the License at 34 | 35 | http://www.apache.org/licenses/LICENSE-2.0 36 | 37 | Unless required by applicable law or agreed to in writing, software 38 | distributed under the License is distributed on an "AS IS" BASIS, 39 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 40 | See the License for the specific language governing permissions and 41 | limitations under the License. 42 | 43 | -------------------------------------------------------------------------------- /packages/agent_dart/macos/agent_dart.podspec: -------------------------------------------------------------------------------- 1 | # 2 | # To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html. 3 | # Run `pod lib lint agent_dart.podspec` to validate before publishing. 4 | # 5 | Pod::Spec.new do |s| 6 | s.name = 'agent_dart' 7 | s.version = '1.0.0' 8 | s.license = { :file => '../LICENSE' } 9 | s.homepage = 'https://github.com/AstroxNetwork/agent_dart' 10 | s.authors = { 'AstroX Dev' => 'dev@astrox.network' } 11 | s.summary = 'iOS/macOS Flutter bindings for agent_dart' 12 | 13 | # This will ensure the source files in Classes/ are included in the native 14 | # builds of apps using this FFI plugin. Podspec does not support relative 15 | # paths, so Classes contains a forwarder C file that relatively imports 16 | # `../src/*` so that the C sources can be shared among all target platforms. 17 | s.source = { :path => '.' } 18 | s.source_files = 'Classes/**/*' 19 | 20 | s.dependency 'FlutterMacOS' 21 | s.platform = :osx, '10.11' 22 | s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' } 23 | s.swift_version = '5.0' 24 | 25 | s.ios.deployment_target = '11.0' 26 | s.osx.deployment_target = '10.11' 27 | 28 | s.script_phase = { 29 | :name => 'Build Rust library', 30 | :execution_position => :before_compile, 31 | :input_files => ['${BUILT_PRODUCTS_DIR}/cargokit_phony'], 32 | # Let XCode know that the static library referenced in -force_load below is 33 | # created by this build step. 34 | :output_files => ["${BUILT_PRODUCTS_DIR}/libagent_dart.a"], 35 | :shell_path => '/bin/bash', 36 | :script => <<-SCRIPT 37 | [ -f "$HOME/.profile" ] && source "$HOME/.profile" 38 | [ -f "$HOME/.bash_profile" ] && source "$HOME/.bash_profile" 39 | "$PODS_TARGET_SRCROOT/../cargokit/build_pod.sh" ../native/agent_dart agent_dart 40 | SCRIPT 41 | } 42 | s.pod_target_xcconfig = { 43 | 'DEFINES_MODULE' => 'YES', 44 | # Flutter.framework does not contain a i386 slice. 45 | 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386', 46 | 'OTHER_LDFLAGS' => '-force_load ${BUILT_PRODUCTS_DIR}/libagent_dart.a', 47 | } 48 | end 49 | -------------------------------------------------------------------------------- /packages/agent_dart/cargokit/build_pod.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | BASEDIR=$(dirname "$0") 5 | 6 | # Workaround for https://github.com/dart-lang/pub/issues/4010 7 | BASEDIR=$(cd "$BASEDIR" ; pwd -P) 8 | 9 | # Remove XCode SDK from path. Otherwise this breaks tool compilation when building iOS project 10 | NEW_PATH=`echo $PATH | tr ":" "\n" | grep -v "Contents/Developer/" | tr "\n" ":"` 11 | 12 | export PATH=${NEW_PATH%?} # remove trailing : 13 | 14 | env 15 | 16 | # Platform name (macosx, iphoneos, iphonesimulator) 17 | export CARGOKIT_DARWIN_PLATFORM_NAME=$PLATFORM_NAME 18 | 19 | # Arctive architectures (arm64, armv7, x86_64), space separated. 20 | export CARGOKIT_DARWIN_ARCHS=$ARCHS 21 | 22 | # Current build configuration (Debug, Release) 23 | export CARGOKIT_CONFIGURATION=$CONFIGURATION 24 | 25 | # Path to directory containing Cargo.toml. 26 | export CARGOKIT_MANIFEST_DIR=$PODS_TARGET_SRCROOT/$1 27 | 28 | # Temporary directory for build artifacts. 29 | export CARGOKIT_TARGET_TEMP_DIR=$TARGET_TEMP_DIR 30 | 31 | # Output directory for final artifacts. 32 | export CARGOKIT_OUTPUT_DIR=$PODS_CONFIGURATION_BUILD_DIR/$PRODUCT_NAME 33 | 34 | # Directory to store built tool artifacts. 35 | export CARGOKIT_TOOL_TEMP_DIR=$TARGET_TEMP_DIR/build_tool 36 | 37 | # Directory inside root project. Not necessarily the top level directory of root project. 38 | export CARGOKIT_ROOT_PROJECT_DIR=$SRCROOT 39 | 40 | FLUTTER_EXPORT_BUILD_ENVIRONMENT=( 41 | "$PODS_ROOT/../Flutter/ephemeral/flutter_export_environment.sh" # macOS 42 | "$PODS_ROOT/../Flutter/flutter_export_environment.sh" # iOS 43 | ) 44 | 45 | for path in "${FLUTTER_EXPORT_BUILD_ENVIRONMENT[@]}" 46 | do 47 | if [[ -f "$path" ]]; then 48 | source "$path" 49 | fi 50 | done 51 | 52 | sh "$BASEDIR/run_build_tool.sh" build-pod "$@" 53 | 54 | # Make a symlink from built framework to phony file, which will be used as input to 55 | # build script. This should force rebuild (podspec currently doesn't support alwaysOutOfDate 56 | # attribute on custom build phase) 57 | ln -fs "$OBJROOT/XCBuildData/build.db" "${BUILT_PRODUCTS_DIR}/cargokit_phony" 58 | ln -fs "${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}" "${BUILT_PRODUCTS_DIR}/cargokit_phony_out" 59 | -------------------------------------------------------------------------------- /packages/agent_dart_base/lib/agent/agent/factory.dart: -------------------------------------------------------------------------------- 1 | import '../../candid/idl.dart'; 2 | import '../../principal/principal.dart'; 3 | import '../agent.dart'; 4 | 5 | class AgentFactory { 6 | AgentFactory({ 7 | required String canisterId, 8 | required String url, 9 | required this.idl, 10 | Identity? identity, 11 | bool? debug = true, 12 | }) : canisterId = Principal.fromText(canisterId), 13 | identity = identity ?? const AnonymousIdentity(), 14 | _debug = debug ?? true, 15 | _url = url; 16 | 17 | static CanisterActor createActor( 18 | Service idl, 19 | HttpAgent agent, 20 | Principal canisterId, 21 | ) { 22 | return Actor.createActor( 23 | idl, 24 | ActorConfig(canisterId: canisterId, agent: agent), 25 | ); 26 | } 27 | 28 | static Future createAgent({ 29 | required String canisterId, 30 | required String url, 31 | required Service idl, 32 | Identity? identity, 33 | bool? debug = true, 34 | }) async { 35 | final agentFactory = AgentFactory( 36 | canisterId: canisterId, 37 | url: url, 38 | idl: idl, 39 | identity: identity ?? const AnonymousIdentity(), 40 | debug: debug, 41 | ); 42 | await agentFactory.initAgent(url); 43 | agentFactory.setActor(); 44 | return agentFactory; 45 | } 46 | 47 | final Principal canisterId; 48 | final Identity identity; 49 | final bool _debug; 50 | final Service idl; 51 | final String _url; 52 | 53 | HttpAgent getAgent() => _agent; 54 | late HttpAgent _agent; 55 | 56 | CanisterActor? get actor => _actor; 57 | CanisterActor? _actor; 58 | 59 | String get agentUrl => _url; 60 | 61 | Future initAgent(String url) async { 62 | _agent = HttpAgent.fromUri( 63 | Uri.parse(url), 64 | options: HttpAgentOptions(identity: identity), 65 | ); 66 | if (_debug) { 67 | await _agent.fetchRootKey(); 68 | } 69 | _agent.addTransform( 70 | HttpAgentRequestTransformFn(call: makeNonceTransform()), 71 | ); 72 | } 73 | 74 | void setActor() { 75 | _actor = Actor.createActor( 76 | idl, 77 | ActorConfig.fromJson({'canisterId': canisterId, 'agent': _agent}), 78 | ); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /packages/agent_dart/ios/agent_dart.podspec: -------------------------------------------------------------------------------- 1 | # 2 | # To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html. 3 | # Run `pod lib lint agent_dart.podspec` to validate before publishing. 4 | # 5 | Pod::Spec.new do |s| 6 | s.name = 'agent_dart' 7 | s.version = '1.0.0' 8 | s.license = { :file => '../LICENSE' } 9 | s.homepage = 'https://github.com/AstroxNetwork/agent_dart' 10 | s.authors = { 'AstroX Dev' => 'dev@astrox.network' } 11 | s.summary = 'iOS/macOS Flutter bindings for agent_dart' 12 | 13 | # This will ensure the source files in Classes/ are included in the native 14 | # builds of apps using this FFI plugin. Podspec does not support relative 15 | # paths, so Classes contains a forwarder C file that relatively imports 16 | # `../src/*` so that the C sources can be shared among all target platforms. 17 | s.source = { :path => '.' } 18 | s.source_files = 'Classes/**/*' 19 | 20 | s.dependency 'Flutter' 21 | s.platform = :ios, '11.0' 22 | # Flutter.framework does not contain a i386 slice. 23 | s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' } 24 | s.swift_version = '5.0' 25 | 26 | s.ios.deployment_target = '11.0' 27 | s.osx.deployment_target = '10.11' 28 | 29 | s.script_phase = { 30 | :name => 'Build Rust library', 31 | :execution_position => :before_compile, 32 | :input_files => ['${BUILT_PRODUCTS_DIR}/cargokit_phony'], 33 | # Let XCode know that the static library referenced in -force_load below is 34 | # created by this build step. 35 | :output_files => ["${BUILT_PRODUCTS_DIR}/libagent_dart.a"], 36 | :shell_path => '/bin/bash', 37 | :script => <<-SCRIPT 38 | [ -f "$HOME/.profile" ] && source "$HOME/.profile" 39 | [ -f "$HOME/.bash_profile" ] && source "$HOME/.bash_profile" 40 | "$PODS_TARGET_SRCROOT/../cargokit/build_pod.sh" ../native/agent_dart agent_dart 41 | SCRIPT 42 | } 43 | s.pod_target_xcconfig = { 44 | 'DEFINES_MODULE' => 'YES', 45 | # Flutter.framework does not contain a i386 slice. 46 | 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386', 47 | 'OTHER_LDFLAGS' => '-force_load ${BUILT_PRODUCTS_DIR}/libagent_dart.a', 48 | } 49 | end 50 | -------------------------------------------------------------------------------- /packages/agent_dart_base/test/wallet/aes.dart: -------------------------------------------------------------------------------- 1 | import 'package:agent_dart_base/agent_dart_base.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | void main() { 5 | test('encodes properly', () async { 6 | const mne = 7 | 'drama catch young miss please high blanket animal armor outdoor capital page'; 8 | 9 | final key1 = await getECKeysAsync(mne); 10 | final key2 = await getECKeysAsync(mne, index: 1); 11 | 12 | final id1 = await Secp256k1KeyIdentity.fromSecretKey(key1.ecPrivateKey!); 13 | final id2 = await Secp256k1KeyIdentity.fromSecretKey(key2.ecPrivateKey!); 14 | 15 | print(id1.getPrincipal().toText()); 16 | print(id2.getPrincipal().toText()); 17 | 18 | const message = 19 | 'usage depart wait tiny depart edit another rebuild ginger panel injury share'; 20 | 21 | final encryptedResult = await encryptMessage( 22 | identity: id1, 23 | theirPublicKey: id2.getPublicKey(), 24 | text: message, 25 | ); 26 | 27 | final decryptedResult = await decryptMessage( 28 | identity: id2, 29 | theirPublicKey: id1.getPublicKey(), 30 | cipherText: encryptedResult.content, 31 | ); 32 | expect(message, decryptedResult); 33 | }); 34 | test('p256 encrypt/decrypt ECIES', () async { 35 | const mne = 36 | 'drama catch young miss please high blanket animal armor outdoor capital page'; 37 | 38 | final key1 = await getECKeysAsync(mne); 39 | final key2 = await getECKeysAsync(mne, index: 1); 40 | 41 | final id1 = await P256Identity.fromSecretKey(key1.ecPrivateKey!); 42 | final id2 = await P256Identity.fromSecretKey(key2.ecPrivateKey!); 43 | 44 | print(id1.getPrincipal().toText()); 45 | print(id2.getPrincipal().toText()); 46 | 47 | const message = 48 | 'usage depart wait tiny depart edit another rebuild ginger panel injury share'; 49 | 50 | final encryptedResult = await encryptP256Message( 51 | identity: id1, 52 | theirPublicKey: id2.getPublicKey(), 53 | text: message, 54 | ); 55 | 56 | final decryptedResult = await decryptP256Message( 57 | identity: id2, 58 | theirPublicKey: id1.getPublicKey(), 59 | cipherText: encryptedResult.content, 60 | ); 61 | expect(message, decryptedResult); 62 | }); 63 | } 64 | -------------------------------------------------------------------------------- /packages/agent_dart_base/test/agent/polling.dart: -------------------------------------------------------------------------------- 1 | import 'package:agent_dart_base/agent_dart_base.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | void main() { 5 | group(PollingResponseException, () { 6 | test('toString() equalization', () { 7 | final canisterId = Principal.fromText('vmyqj-fzaaa-aaaaa-qaaga-cai'); 8 | const requestId = 'test_id'; 9 | const status = RequestStatusResponseStatus.rejected; 10 | const method = 'test_method'; 11 | final caller = Principal.anonymous(); 12 | 13 | final e1 = PollingResponseException( 14 | canisterId: canisterId, 15 | requestId: requestId, 16 | status: status, 17 | method: method, 18 | caller: caller, 19 | ); 20 | expect( 21 | e1.toString(), 22 | equals('''Call was rejected: 23 | |- Canister ID: vmyqj-fzaaa-aaaaa-qaaga-cai 24 | |-- Request ID: test_id 25 | |------ Caller: 2vxsx-fae 26 | |------ Method: test_method'''), 27 | ); 28 | 29 | final e2 = PollingResponseNoReplyException( 30 | canisterId: canisterId, 31 | requestId: requestId, 32 | status: status, 33 | method: method, 34 | caller: caller, 35 | ); 36 | expect( 37 | e2.toString(), 38 | equals('''Call was marked as rejected but never replied: 39 | |- Canister ID: vmyqj-fzaaa-aaaaa-qaaga-cai 40 | |-- Request ID: test_id 41 | |------ Caller: 2vxsx-fae 42 | |------ Method: test_method'''), 43 | ); 44 | 45 | final rejectCode = BigInt.from(5); 46 | const rejectMessage = 47 | 'Canister vmyqj-fzaaa-aaaaa-qaaga-cai trapped explicitly'; 48 | final e3 = PollingResponseRejectedException( 49 | canisterId: canisterId, 50 | requestId: requestId, 51 | status: status, 52 | method: method, 53 | caller: caller, 54 | rejectCode: rejectCode, 55 | rejectMessage: rejectMessage, 56 | ); 57 | expect( 58 | e3.toString(), 59 | equals('''Call was rejected: 60 | |- Canister ID: vmyqj-fzaaa-aaaaa-qaaga-cai 61 | |-- Request ID: test_id 62 | |------ Caller: 2vxsx-fae 63 | |------ Method: test_method 64 | |-------- Code: 5 65 | |----- Message: Canister vmyqj-fzaaa-aaaaa-qaaga-cai trapped explicitly'''), 66 | ); 67 | }); 68 | }); 69 | } 70 | -------------------------------------------------------------------------------- /packages/agent_dart_base/test/agent/http/http.dart: -------------------------------------------------------------------------------- 1 | import 'dart:typed_data'; 2 | 3 | import 'package:agent_dart_base/agent_dart_base.dart'; 4 | import 'package:test/test.dart'; 5 | 6 | void main() { 7 | httpTest(); 8 | } 9 | 10 | void httpTest() { 11 | group('description 1', () { 12 | test('some', () async { 13 | final Principal canisterId = 14 | Principal.fromText('2chl6-4hpzw-vqaaa-aaaaa-c'); 15 | final nonce = Uint8List.fromList([0, 1, 2, 3, 4, 5, 6, 7]); 16 | final principal = Principal.anonymous(); 17 | 18 | final agent = HttpAgent( 19 | options: const HttpAgentOptions(identity: AnonymousIdentity()), 20 | ); 21 | 22 | agent.addTransform( 23 | HttpAgentRequestTransformFn(call: makeNonceTransform(() => nonce)), 24 | ); 25 | 26 | const methodName = 'greet'; 27 | final arg = Uint8List.fromList([]); 28 | 29 | agent.setFetch(({ 30 | body, 31 | endpoint = 'https://localhost:8000', 32 | headers, 33 | host, 34 | method = FetchMethod.post, 35 | }) { 36 | return Future.value({ 37 | 'body': null, 38 | 'ok': true, 39 | 'statusCode': 200, 40 | 'statusText': '', 41 | 'arrayBuffer': null, 42 | }); 43 | }); 44 | 45 | final res = await agent.callRequest( 46 | canisterId, 47 | CallOptions(arg: arg, methodName: methodName), 48 | null, 49 | ); 50 | print(res.toJson()); 51 | 52 | final mockPartialRequest = { 53 | 'request_type': SubmitRequestType.call, 54 | 'canister_id': canisterId, 55 | 'method_name': methodName, 56 | // We need a request id for the signature and at the same time we 57 | // are checking that signature does not impact the request id. 58 | 'arg': arg, 59 | 'nonce': nonce, 60 | 'sender': principal, 61 | 'ingress_expiry': Expiry(300000), 62 | }; 63 | 64 | final mockPartialsRequestId = requestIdOf(mockPartialRequest); 65 | final expectedRequest = { 66 | 'content': mockPartialRequest, 67 | }; 68 | final expectedRequestId = requestIdOf( 69 | expectedRequest['content'] as Map, 70 | ); 71 | expect(expectedRequestId, mockPartialsRequestId); 72 | }); 73 | }); 74 | 75 | group('description 2 ', () {}); 76 | } 77 | -------------------------------------------------------------------------------- /packages/agent_dart_base/lib/agent/crypto/random.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math' as math; 2 | import 'dart:typed_data'; 3 | 4 | import '../../utils/extension.dart'; 5 | import '../../utils/hex.dart'; 6 | import '../../utils/number.dart'; 7 | import '../../utils/u8a.dart'; 8 | 9 | const _defaultLength = 32; 10 | 11 | final bn53 = BigInt.parse( 12 | '11111111111111111111111111111111111111111111111111111', 13 | radix: 2, 14 | ); 15 | 16 | class DartRandom { 17 | const DartRandom(this.dartRandom); 18 | 19 | final math.Random dartRandom; 20 | 21 | String get algorithmName => 'DartRandom'; 22 | 23 | BigInt nextBigInteger(int bitLength) { 24 | final int fullBytes = bitLength ~/ 8; 25 | // Generate a number from the full bytes. 26 | // Then, prepend a smaller number covering the remaining bits. 27 | final BigInt main = bytesToInt(nextBytes(fullBytes)); 28 | // Forcing remaining bits to be calculate with bits length. 29 | final int remainingBits = bitLength - main.bitLength; 30 | final int additional = remainingBits < 4 31 | ? dartRandom.nextInt(math.pow(2, remainingBits).toInt()) 32 | : remainingBits; 33 | final BigInt additionalBit = BigInt.from(additional) << (fullBytes * 8); 34 | final BigInt result = main + additionalBit; 35 | return result; 36 | } 37 | 38 | Uint8List nextBytes(int count) { 39 | return Uint8List.fromList(List.generate(count, (_) => nextUint8())); 40 | } 41 | 42 | int nextUint16() => dartRandom.nextInt(math.pow(2, 32).toInt()); 43 | 44 | int nextUint32() => dartRandom.nextInt(math.pow(2, 32).toInt()); 45 | 46 | int nextUint8() => dartRandom.nextInt(math.pow(2, 8).toInt()); 47 | } 48 | 49 | Uint8List getRandomValues([int length = _defaultLength]) { 50 | final DartRandom rn = DartRandom(math.Random.secure()); 51 | String entropy = rn.nextBigInteger(length * 8).toRadixString(16); 52 | 53 | if (entropy.length > length * 2) { 54 | entropy = entropy.substring(0, length * 2); 55 | } 56 | 57 | String randomPers = rn.nextBigInteger(length * 8).toRadixString(16); 58 | 59 | if (randomPers.length > length * 2) { 60 | randomPers = randomPers.substring(0, length * 2); 61 | } 62 | return randomPers.toU8a(); 63 | } 64 | 65 | Uint8List randomAsU8a([int length = _defaultLength]) { 66 | return getRandomValues(length); 67 | } 68 | 69 | String randomAsHex([int length = 32]) { 70 | return u8aToHex(randomAsU8a(length)); 71 | } 72 | 73 | int randomAsNumber() { 74 | return (hexToBn(randomAsHex(8)) & bn53).toInt(); 75 | } 76 | -------------------------------------------------------------------------------- /packages/agent_dart_base/lib/utils/string.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | import 'dart:typed_data'; 3 | 4 | import 'package:convert/convert.dart'; 5 | 6 | import 'number.dart'; 7 | 8 | String strip0xHex(String hex) { 9 | if (hex.startsWith('0x')) { 10 | return hex.substring(2); 11 | } 12 | return hex; 13 | } 14 | 15 | Uint8List stringToU8a(String msg, {String? enc, bool useDartEncode = true}) { 16 | if (useDartEncode == false) { 17 | if (enc == 'hex') { 18 | msg = strip0xHex(msg); 19 | final List hexRes = []; 20 | msg = msg.replaceAll(RegExp('[^a-z0-9]'), ''); 21 | if (msg.length % 2 != 0) msg = '0$msg'; 22 | for (int i = 0; i < msg.length; i += 2) { 23 | final cul = msg[i] + msg[i + 1]; 24 | final result = int.parse(cul, radix: 16); 25 | hexRes.add(result); 26 | } 27 | return Uint8List.fromList(hexRes); 28 | } else { 29 | final List noHexRes = []; 30 | for (int i = 0; i < msg.length; i++) { 31 | final c = msg.codeUnitAt(i); 32 | final hi = c >> 8; 33 | final lo = c & 0xff; 34 | if (hi > 0) { 35 | noHexRes.add(hi); 36 | } 37 | noHexRes.add(lo); 38 | } 39 | return Uint8List.fromList(noHexRes); 40 | } 41 | } else { 42 | return Uint8List.fromList(utf8.encode(msg)); 43 | } 44 | } 45 | 46 | Uint8List textEncoder(String value) { 47 | final u8a = Uint8List(value.length); 48 | for (int i = 0; i < value.length; i++) { 49 | u8a[i] = value.codeUnitAt(i); 50 | } 51 | return u8a; 52 | } 53 | 54 | String textDecoder(Uint8List value) { 55 | return value.fold('', (p, e) => p += String.fromCharCode(e)); 56 | } 57 | 58 | String plainTextToHex(String plainText) { 59 | final u8a = stringToU8a(plainText); 60 | return bytesToHex(u8a); 61 | } 62 | 63 | String hexToPlainText(String hex) { 64 | return utf8.decode(stringToU8a(hex, enc: 'hex')); 65 | } 66 | 67 | /// Converts the hexadecimal string, which can be prefixed with 0x, 68 | /// to a byte sequence. 69 | List hexToBytes(String hexStr) { 70 | return hex.decode(strip0xHex(hexStr)); 71 | } 72 | 73 | String stringShorten(String value, {int prefixLength = 6}) { 74 | if (value.length <= 2 + 2 * prefixLength) { 75 | return value.toString(); 76 | } 77 | final tLength = value.length; 78 | final secStart = value.length - prefixLength; 79 | final firstPart = value.substring(0, prefixLength); 80 | final secondPart = value.substring(secStart, tLength); 81 | return '$firstPart…$secondPart'; 82 | } 83 | -------------------------------------------------------------------------------- /packages/agent_dart/example/ios/Runner/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /packages/agent_dart_base/lib/principal/utils/base32.dart: -------------------------------------------------------------------------------- 1 | import 'dart:typed_data'; 2 | 3 | const _alphabet = 'abcdefghijklmnopqrstuvwxyz234567'; 4 | 5 | String base32Encode(Uint8List input) { 6 | // How many bits will we skip from the first byte. 7 | int skip = 0; 8 | // 5 high bits, carry from one byte to the next. 9 | int bits = 0; 10 | 11 | // The output string in base32. 12 | String output = ''; 13 | 14 | int encodeByte(int byte) { 15 | if (skip < 0) { 16 | // we have a carry from the previous byte 17 | bits |= byte >> -skip; 18 | } else { 19 | // no carry 20 | bits = (byte << skip) & 248; 21 | } 22 | 23 | if (skip > 3) { 24 | // Not enough data to produce a character, get us another one 25 | skip -= 8; 26 | return 1; 27 | } 28 | 29 | if (skip < 4) { 30 | // produce a character 31 | output += _alphabet[bits >> 3]; 32 | skip += 5; 33 | } 34 | 35 | return 0; 36 | } 37 | 38 | for (int i = 0; i < input.length;) { 39 | i += encodeByte(input[i]); 40 | } 41 | 42 | return output + (skip < 0 ? _alphabet[bits >> 3] : ''); 43 | } 44 | 45 | Uint8List base32Decode(String input) { 46 | // how many bits we have from the previous character. 47 | int skip = 0; 48 | // current byte we're producing. 49 | int byte = 0; 50 | 51 | final output = Uint8List(((input.length * 4) / 3).ceil() | 0); 52 | int o = 0; 53 | 54 | final Map lookupTable = _alphabet.split('').fold({}, (p, e) { 55 | p[e] = _alphabet.indexOf(e); 56 | return p; 57 | }); 58 | // Add aliases for rfc4648. 59 | lookupTable 60 | ..putIfAbsent('0', () => lookupTable['o']!) 61 | ..putIfAbsent('1', () => lookupTable['i']!); 62 | 63 | void decodeChar(String char) { 64 | // Consume a character from the stream, store 65 | // the output in this.output. As before, better 66 | // to use update(). 67 | final found = lookupTable[char.toLowerCase()]; 68 | assert(found != null, 'Invalid character: $char'); 69 | int val = found!; 70 | // move to the high bits 71 | val <<= 3; 72 | // 32 bit shift? 73 | byte |= (val & 0xffffffff) >> skip; 74 | 75 | skip += 5; 76 | 77 | if (skip >= 8) { 78 | // We have enough bytes to produce an output 79 | output[o++] = byte; 80 | skip -= 8; 81 | 82 | if (skip > 0) { 83 | byte = (val << (5 - skip)) & 255; 84 | } else { 85 | byte = 0; 86 | } 87 | } 88 | } 89 | 90 | for (int i = 0; i < input.length; i += 1) { 91 | decodeChar(input[i]); 92 | } 93 | return output.sublist(0, o); 94 | } 95 | -------------------------------------------------------------------------------- /packages/agent_dart/cargokit/build_tool/lib/src/environment.dart: -------------------------------------------------------------------------------- 1 | /// This is copied from Cargokit (which is the official way to use it currently) 2 | /// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin 3 | 4 | import 'dart:io'; 5 | 6 | extension on String { 7 | String resolveSymlink() => File(this).resolveSymbolicLinksSync(); 8 | } 9 | 10 | class Environment { 11 | /// Current build configuration (debug or release). 12 | static String get configuration => 13 | _getEnv("CARGOKIT_CONFIGURATION").toLowerCase(); 14 | 15 | static bool get isDebug => configuration == 'debug'; 16 | static bool get isRelease => configuration == 'release'; 17 | 18 | /// Temporary directory where Rust build artifacts are placed. 19 | static String get targetTempDir => _getEnv("CARGOKIT_TARGET_TEMP_DIR"); 20 | 21 | /// Final output directory where the build artifacts are placed. 22 | static String get outputDir => _getEnvPath('CARGOKIT_OUTPUT_DIR'); 23 | 24 | /// Path to the crate manifest (containing Cargo.toml). 25 | static String get manifestDir => _getEnvPath('CARGOKIT_MANIFEST_DIR'); 26 | 27 | /// Directory inside root project. Not necessarily root folder. Symlinks are 28 | /// not resolved on purpose. 29 | static String get rootProjectDir => _getEnv('CARGOKIT_ROOT_PROJECT_DIR'); 30 | 31 | // Pod 32 | 33 | /// Platform name (macosx, iphoneos, iphonesimulator). 34 | static String get darwinPlatformName => 35 | _getEnv("CARGOKIT_DARWIN_PLATFORM_NAME"); 36 | 37 | /// List of architectures to build for (arm64, armv7, x86_64). 38 | static List get darwinArchs => 39 | _getEnv("CARGOKIT_DARWIN_ARCHS").split(' '); 40 | 41 | // Gradle 42 | static String get minSdkVersion => _getEnv("CARGOKIT_MIN_SDK_VERSION"); 43 | static String get ndkVersion => _getEnv("CARGOKIT_NDK_VERSION"); 44 | static String get sdkPath => _getEnvPath("CARGOKIT_SDK_DIR"); 45 | static String get javaHome => _getEnvPath("CARGOKIT_JAVA_HOME"); 46 | static List get targetPlatforms => 47 | _getEnv("CARGOKIT_TARGET_PLATFORMS").split(','); 48 | 49 | // CMAKE 50 | static String get targetPlatform => _getEnv("CARGOKIT_TARGET_PLATFORM"); 51 | 52 | static String _getEnv(String key) { 53 | final res = Platform.environment[key]; 54 | if (res == null) { 55 | throw Exception("Missing environment variable $key"); 56 | } 57 | return res; 58 | } 59 | 60 | static String _getEnvPath(String key) { 61 | final res = _getEnv(key); 62 | if (Directory(res).existsSync()) { 63 | return res.resolveSymlink(); 64 | } else { 65 | return res; 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /packages/agent_dart/cargokit/run_build_tool.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | BASEDIR=$(dirname "$0") 6 | 7 | mkdir -p "$CARGOKIT_TOOL_TEMP_DIR" 8 | 9 | cd "$CARGOKIT_TOOL_TEMP_DIR" 10 | 11 | # Write a very simple bin package in temp folder that depends on build_tool package 12 | # from Cargokit. This is done to ensure that we don't pollute Cargokit folder 13 | # with .dart_tool contents. 14 | 15 | BUILD_TOOL_PKG_DIR="$BASEDIR/build_tool" 16 | 17 | if [[ -z $FLUTTER_ROOT ]]; then # not defined 18 | DART=dart 19 | else 20 | DART="$FLUTTER_ROOT/bin/cache/dart-sdk/bin/dart" 21 | fi 22 | 23 | cat << EOF > "pubspec.yaml" 24 | name: build_tool_runner 25 | version: 1.0.0 26 | publish_to: none 27 | 28 | environment: 29 | sdk: '>=3.0.0 <4.0.0' 30 | 31 | dependencies: 32 | build_tool: 33 | path: "$BUILD_TOOL_PKG_DIR" 34 | EOF 35 | 36 | mkdir -p "bin" 37 | 38 | cat << EOF > "bin/build_tool_runner.dart" 39 | import 'package:build_tool/build_tool.dart' as build_tool; 40 | void main(List args) { 41 | build_tool.runMain(args); 42 | } 43 | EOF 44 | 45 | # Create alias for `shasum` if it does not exist and `sha1sum` exists 46 | if ! [ -x "$(command -v shasum)" ] && [ -x "$(command -v sha1sum)" ]; then 47 | shopt -s expand_aliases 48 | alias shasum="sha1sum" 49 | fi 50 | 51 | # Dart run will not cache any package that has a path dependency, which 52 | # is the case for our build_tool_runner. So instead we precompile the package 53 | # ourselves. 54 | # To invalidate the cached kernel we use the hash of ls -LR of the build_tool 55 | # package directory. This should be good enough, as the build_tool package 56 | # itself is not meant to have any path dependencies. 57 | 58 | if [[ "$OSTYPE" == "darwin"* ]]; then 59 | PACKAGE_HASH=$(ls -lTR "$BUILD_TOOL_PKG_DIR" | shasum) 60 | else 61 | PACKAGE_HASH=$(ls -lR --full-time "$BUILD_TOOL_PKG_DIR" | shasum) 62 | fi 63 | 64 | PACKAGE_HASH_FILE=".package_hash" 65 | 66 | if [ -f "$PACKAGE_HASH_FILE" ]; then 67 | EXISTING_HASH=$(cat "$PACKAGE_HASH_FILE") 68 | if [ "$PACKAGE_HASH" != "$EXISTING_HASH" ]; then 69 | rm "$PACKAGE_HASH_FILE" 70 | fi 71 | fi 72 | 73 | # Run pub get if needed. 74 | if [ ! -f "$PACKAGE_HASH_FILE" ]; then 75 | "$DART" pub get --no-precompile 76 | "$DART" compile kernel bin/build_tool_runner.dart 77 | echo "$PACKAGE_HASH" > "$PACKAGE_HASH_FILE" 78 | fi 79 | 80 | set +e 81 | 82 | "$DART" bin/build_tool_runner.dill "$@" 83 | 84 | exit_code=$? 85 | 86 | # 253 means invalid snapshot version. 87 | if [ $exit_code == 253 ]; then 88 | "$DART" pub get --no-precompile 89 | "$DART" compile kernel bin/build_tool_runner.dart 90 | "$DART" bin/build_tool_runner.dill "$@" 91 | exit_code=$? 92 | fi 93 | 94 | exit $exit_code 95 | -------------------------------------------------------------------------------- /packages/agent_dart_base/lib/agent/types.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | import 'dart:typed_data'; 3 | 4 | import 'package:meta/meta.dart'; 5 | 6 | import '../../utils/extension.dart'; 7 | import 'utils/leb128.dart'; 8 | 9 | enum FetchMethod { 10 | get, 11 | head, 12 | post, 13 | put, 14 | delete, 15 | connect, 16 | options, 17 | trace, 18 | patch, 19 | } 20 | 21 | enum RequestStatusResponseStatus { 22 | received, 23 | processing, 24 | replied, 25 | rejected, 26 | unknown, 27 | done; 28 | 29 | factory RequestStatusResponseStatus.fromName(String value) { 30 | return values.singleWhere((e) => e.name == value); 31 | } 32 | } 33 | 34 | enum BlobType { binary, der, nonce, requestId } 35 | 36 | @immutable 37 | abstract class BaseBlob { 38 | const BaseBlob( 39 | Uint8List buffer, 40 | this.blobType, 41 | this.blobName, 42 | ) : _buffer = buffer; 43 | 44 | final Uint8List _buffer; 45 | final BlobType blobType; 46 | final String blobName; 47 | 48 | Uint8List get buffer => _buffer; 49 | 50 | int get byteLength; 51 | } 52 | 53 | typedef BinaryBlob = Uint8List; 54 | typedef DerEncodedBlob = BinaryBlob; 55 | typedef Nonce = BinaryBlob; 56 | typedef RequestId = BinaryBlob; 57 | 58 | extension ExtBinaryBlob on BinaryBlob { 59 | String get name => '__BLOB'; 60 | 61 | BlobType get blobType => BlobType.binary; 62 | 63 | int get byteLength => lengthInBytes; 64 | 65 | static Uint8List from(Uint8List other) => Uint8List.fromList(other); 66 | } 67 | 68 | BinaryBlob blobFromBuffer(ByteBuffer b) { 69 | return BinaryBlob.fromList(b.asUint8List()); 70 | } 71 | 72 | BinaryBlob blobFromUint8Array(Uint8List arr) { 73 | return BinaryBlob.fromList(arr); 74 | } 75 | 76 | BinaryBlob blobFromText(String text) { 77 | return BinaryBlob.fromList(text.plainToU8a(useDartEncode: true)); 78 | } 79 | 80 | BinaryBlob blobFromUint32Array(Uint32List arr) { 81 | return BinaryBlob.fromList(arr.buffer.asUint8List()); 82 | } 83 | 84 | DerEncodedBlob derBlobFromBlob(BinaryBlob blob) { 85 | return DerEncodedBlob.fromList(blob); 86 | } 87 | 88 | BinaryBlob blobFromHex(String hex) { 89 | return BinaryBlob.fromList(hex.toU8a()); 90 | } 91 | 92 | String blobToHex(BinaryBlob blob) { 93 | return blob.toHex(); 94 | } 95 | 96 | Uint8List blobToUint8Array(BinaryBlob blob) { 97 | return Uint8List.fromList(blob.sublist(0, blob.byteLength)); 98 | } 99 | 100 | Nonce makeNonce() { 101 | return Nonce.fromList( 102 | lebEncode( 103 | BigInt.from(DateTime.now().millisecondsSinceEpoch) * BigInt.from(100000) + 104 | BigInt.from((Random.secure().nextInt(1) * 100000).floor()), 105 | ), 106 | ); 107 | } 108 | -------------------------------------------------------------------------------- /packages/agent_dart_base/test/agent/request_id.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:agent_dart_base/agent_dart_base.dart'; 4 | import 'package:test/test.dart'; 5 | 6 | void main() { 7 | hashTest(); 8 | } 9 | 10 | void hashTest() { 11 | test('IDL label', () async { 12 | void testHashOfBlob(BinaryBlob input, String expected) { 13 | final hashed = hash(input); 14 | final hex = blobToHex(hashed); 15 | expect(hex, expected); 16 | } 17 | 18 | void testHashOfString(String input, String expected) { 19 | final encoded = utf8.encode(input); 20 | testHashOfBlob(BinaryBlob.fromList(encoded), expected); 21 | } 22 | 23 | testHashOfString( 24 | 'request_type', 25 | '769e6f87bdda39c859642b74ce9763cdd37cb1cd672733e8c54efaa33ab78af9', 26 | ); 27 | testHashOfString( 28 | 'call', 29 | '7edb360f06acaef2cc80dba16cf563f199d347db4443da04da0c8173e3f9e4ed', 30 | ); 31 | testHashOfString( 32 | 'callee', // The "canister_id" field was previously named "callee" 33 | '92ca4c0ced628df1e7b9f336416ead190bd0348615b6f71a64b21d1b68d4e7e2', 34 | ); 35 | testHashOfString( 36 | 'canister_id', 37 | '0a3eb2ba16702a387e6321066dd952db7a31f9b5cc92981e0a92dd56802d3df9', 38 | ); 39 | testHashOfBlob( 40 | BinaryBlob.fromList([0, 0, 0, 0, 0, 0, 4, 210]), 41 | '4d8c47c3c1c837964011441882d745f7e92d10a40cef0520447c63029eafe396', 42 | ); 43 | testHashOfString( 44 | 'method_name', 45 | '293536232cf9231c86002f4ee293176a0179c002daa9fc24be9bb51acdd642b6', 46 | ); 47 | testHashOfString( 48 | 'hello', 49 | '2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824', 50 | ); 51 | testHashOfString( 52 | 'arg', 53 | 'b25f03dedd69be07f356a06fe35c1b0ddc0de77dcd9066c4be0c6bbde14b23ff', 54 | ); 55 | testHashOfBlob( 56 | BinaryBlob.fromList([68, 73, 68, 76, 0, 253, 42]), 57 | '6c0b2ae49718f6995c02ac5700c9c789d7b7862a0d53e6d40a73f1fcd2f70189', 58 | ); 59 | }); 60 | 61 | test('requestIdOf', () async { 62 | final request = { 63 | 'request_type': 'call', 64 | 'method_name': 'hello', 65 | 66 | // 0x00000000000004D2 67 | // \x00\x00\x00\x00\x00\x00\x04\xD2 68 | // 0 0 0 0 0 0 4 210 69 | 'canister_id': BinaryBlob.fromList([0, 0, 0, 0, 0, 0, 4, 210]), 70 | 71 | // DIDL\x00\xFD* 72 | // D I D L \x00 \253 * 73 | // 68 73 68 76 0 253 42 74 | 'arg': BinaryBlob.fromList([68, 73, 68, 76, 0, 253, 42]), 75 | }; 76 | 77 | final requestId = requestIdOf(request); 78 | 79 | expect( 80 | blobToHex(requestId), 81 | '8781291c347db32a9d8c10eb62b710fce5a93be676474c42babc74c51858f94b', 82 | ); 83 | }); 84 | } 85 | -------------------------------------------------------------------------------- /packages/agent_dart/cargokit/build_tool/lib/src/verify_binaries.dart: -------------------------------------------------------------------------------- 1 | /// This is copied from Cargokit (which is the official way to use it currently) 2 | /// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin 3 | 4 | import 'dart:io'; 5 | 6 | import 'package:ed25519_edwards/ed25519_edwards.dart'; 7 | import 'package:http/http.dart'; 8 | 9 | import 'artifacts_provider.dart'; 10 | import 'cargo.dart'; 11 | import 'crate_hash.dart'; 12 | import 'options.dart'; 13 | import 'precompile_binaries.dart'; 14 | import 'target.dart'; 15 | 16 | class VerifyBinaries { 17 | VerifyBinaries({ 18 | required this.manifestDir, 19 | }); 20 | 21 | final String manifestDir; 22 | 23 | Future run() async { 24 | final crateInfo = CrateInfo.load(manifestDir); 25 | 26 | final config = CargokitCrateOptions.load(manifestDir: manifestDir); 27 | final precompiledBinaries = config.precompiledBinaries; 28 | if (precompiledBinaries == null) { 29 | stdout.writeln('Crate does not support precompiled binaries.'); 30 | } else { 31 | final crateHash = CrateHash.compute(manifestDir); 32 | stdout.writeln('Crate hash: $crateHash'); 33 | 34 | for (final target in Target.all) { 35 | final message = 'Checking ${target.rust}...'; 36 | stdout.write(message.padRight(40)); 37 | stdout.flush(); 38 | 39 | final artifacts = getArtifactNames( 40 | target: target, 41 | libraryName: crateInfo.packageName, 42 | remote: true, 43 | ); 44 | 45 | final prefix = precompiledBinaries.uriPrefix; 46 | 47 | bool ok = true; 48 | 49 | for (final artifact in artifacts) { 50 | final fileName = PrecompileBinaries.fileName(target, artifact); 51 | final signatureFileName = 52 | PrecompileBinaries.signatureFileName(target, artifact); 53 | 54 | final url = Uri.parse('$prefix$crateHash/$fileName'); 55 | final signatureUrl = 56 | Uri.parse('$prefix$crateHash/$signatureFileName'); 57 | 58 | final signature = await get(signatureUrl); 59 | if (signature.statusCode != 200) { 60 | stdout.writeln('MISSING'); 61 | ok = false; 62 | break; 63 | } 64 | final asset = await get(url); 65 | if (asset.statusCode != 200) { 66 | stdout.writeln('MISSING'); 67 | ok = false; 68 | break; 69 | } 70 | 71 | if (!verify(precompiledBinaries.publicKey, asset.bodyBytes, 72 | signature.bodyBytes)) { 73 | stdout.writeln('INVALID SIGNATURE'); 74 | ok = false; 75 | } 76 | } 77 | 78 | if (ok) { 79 | stdout.writeln('OK'); 80 | } 81 | } 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /packages/agent_dart/cargokit/run_build_tool.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal 3 | 4 | setlocal ENABLEDELAYEDEXPANSION 5 | 6 | SET BASEDIR=%~dp0 7 | 8 | if not exist "%CARGOKIT_TOOL_TEMP_DIR%" ( 9 | mkdir "%CARGOKIT_TOOL_TEMP_DIR%" 10 | ) 11 | cd /D "%CARGOKIT_TOOL_TEMP_DIR%" 12 | 13 | SET BUILD_TOOL_PKG_DIR=%BASEDIR%build_tool 14 | SET DART=%FLUTTER_ROOT%\bin\cache\dart-sdk\bin\dart 15 | 16 | set BUILD_TOOL_PKG_DIR_POSIX=%BUILD_TOOL_PKG_DIR:\=/% 17 | 18 | ( 19 | echo name: build_tool_runner 20 | echo version: 1.0.0 21 | echo publish_to: none 22 | echo. 23 | echo environment: 24 | echo sdk: '^>=3.0.0 ^<4.0.0' 25 | echo. 26 | echo dependencies: 27 | echo build_tool: 28 | echo path: %BUILD_TOOL_PKG_DIR_POSIX% 29 | ) >pubspec.yaml 30 | 31 | if not exist bin ( 32 | mkdir bin 33 | ) 34 | 35 | ( 36 | echo import 'package:build_tool/build_tool.dart' as build_tool; 37 | echo void main^(List^ args^) ^{ 38 | echo build_tool.runMain^(args^); 39 | echo ^} 40 | ) >bin\build_tool_runner.dart 41 | 42 | SET PRECOMPILED=bin\build_tool_runner.dill 43 | 44 | REM To detect changes in package we compare output of DIR /s (recursive) 45 | set PREV_PACKAGE_INFO=.dart_tool\package_info.prev 46 | set CUR_PACKAGE_INFO=.dart_tool\package_info.cur 47 | 48 | DIR "%BUILD_TOOL_PKG_DIR%" /s > "%CUR_PACKAGE_INFO%_orig" 49 | 50 | REM Last line in dir output is free space on harddrive. That is bound to 51 | REM change between invocation so we need to remove it 52 | ( 53 | Set "Line=" 54 | For /F "UseBackQ Delims=" %%A In ("%CUR_PACKAGE_INFO%_orig") Do ( 55 | SetLocal EnableDelayedExpansion 56 | If Defined Line Echo !Line! 57 | EndLocal 58 | Set "Line=%%A") 59 | ) >"%CUR_PACKAGE_INFO%" 60 | DEL "%CUR_PACKAGE_INFO%_orig" 61 | 62 | REM Compare current directory listing with previous 63 | FC /B "%CUR_PACKAGE_INFO%" "%PREV_PACKAGE_INFO%" > nul 2>&1 64 | 65 | If %ERRORLEVEL% neq 0 ( 66 | REM Changed - copy current to previous and remove precompiled kernel 67 | if exist "%PREV_PACKAGE_INFO%" ( 68 | DEL "%PREV_PACKAGE_INFO%" 69 | ) 70 | MOVE /Y "%CUR_PACKAGE_INFO%" "%PREV_PACKAGE_INFO%" 71 | if exist "%PRECOMPILED%" ( 72 | DEL "%PRECOMPILED%" 73 | ) 74 | ) 75 | 76 | REM There is no CUR_PACKAGE_INFO it was renamed in previous step to %PREV_PACKAGE_INFO% 77 | REM which means we need to do pub get and precompile 78 | if not exist "%PRECOMPILED%" ( 79 | echo Running pub get in "%cd%" 80 | "%DART%" pub get --no-precompile 81 | "%DART%" compile kernel bin/build_tool_runner.dart 82 | ) 83 | 84 | "%DART%" "%PRECOMPILED%" %* 85 | 86 | REM 253 means invalid snapshot version. 87 | If %ERRORLEVEL% equ 253 ( 88 | "%DART%" pub get --no-precompile 89 | "%DART%" compile kernel bin/build_tool_runner.dart 90 | "%DART%" "%PRECOMPILED%" %* 91 | ) 92 | --------------------------------------------------------------------------------