astroxnetwork / agent_dart Goto Github PK
View Code? Open in Web Editor NEWAgent library for Internet Computer, in Dart
Home Page: https://pub.dev/packages/agent_dart
License: MIT License
Agent library for Internet Computer, in Dart
Home Page: https://pub.dev/packages/agent_dart
License: MIT License
I'm encountering this error when calling fetchRootKey() of HttpAgent in _initAgent():
E/flutter (23155): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: http request failed because SocketException: OS Error: Connection refused, errno = 111, address = localhost, port = 46950
E/flutter (23155): #0 HttpAgent._defaultFetch (package:agent_dart/agent/agent/http/index.dart:433:7)
E/flutter (23155):
E/flutter (23155): #1 HttpAgent.status (package:agent_dart/agent/agent/http/index.dart:362:20)
E/flutter (23155):
E/flutter (23155): #2 HttpAgent.fetchRootKey (package:agent_dart/agent/agent/http/index.dart:246:20)
E/flutter (23155):
E/flutter (23155): #3 AgentFactory._initAgent (package:agent_dart_example/init.dart:63:7)
E/flutter (23155):
E/flutter (23155):
This means that the port somehow gets changed since I specified port 40161 in the url of the AgentFactory (this is where my local replica runs).
I also tried to directly set the port with the host parameter of HttpAgentOptions but still get the same error.
Am I missing something?
Right now the project has a dependency on flutter thus it's not possible to use the package on a pure dart environment like a server-side dart.
Package behaves more like agent_flutter rather than agent_dart.
Update:
Try this branch https://github.com/AstroxNetwork/agent_dart/tree/feat/web
Worth trying for further experiment:
https://github.com/EPNW/web_ffi
TODO:
Error (Xcode): ../../../.pub-cache/hosted/pub.dev/agent_dart-1.0.0-dev.22/lib/archiver/encoder.dart:162:8: Error: The return type of the method 'SingingBlockZipFileEncoder.close' is 'void', which does not match the return type, 'Future', of the overridden method, 'ZipFileEncoder.close'.
This is the error that I am getting while creating an actor
ArgumentError: Invalid argument(s): Failed to lookup symbol 'bls_verify': dlsym(RTLD_DEFAULT, bls_verify): symbol not found
Full Stack Trace:
ArgumentError: Invalid argument(s): Failed to lookup symbol 'bls_verify': dlsym(RTLD_DEFAULT, bls_verify): symbol not found
File "ffi_dynamic_library_patch.dart", line 34, in DynamicLibrary.lookup
File "ffi_base.dart", line 23, in rustBlsVerify
File "bls.ffi.dart", in FFIBls.blsVerifySync
File "certificate.dart", line 155, in Certificate.verify
File "<asynchronous suspension>"
File "certificate.dart", line 179, in Certificate._checkDelegation
File "<asynchronous suspension>"
File "certificate.dart", line 149, in Certificate.verify
File "<asynchronous suspension>"
File "index.dart", line 17, in pollForResponse
File "<asynchronous suspension>"
File "actor.dart", line 432, in _createActorMethod.<fn>
If it helps, my app communicates with a dozen dynamic canisters and creates dozen of actors using this common method
Future<CanisterActor> getVideoCanisterActor(String canisterId) async {
if (_canisters[canisterId] == null) {
AgentFactory _videoCanisterAgent = await AgentFactory.createAgent(
canisterId: canisterId,
url: backendUrl,
idl: videoCanisterIDL,
);
_canisters[canisterId] = _videoCanisterAgent.actor!;
}
return _canisters[canisterId]!;
}
Documentation for agent_dart apis
To have better understanding of internet computer, for client developers, it is the best way to understand how the sdk works.
Though we have ported most agent-js features to agent_dart, we don't have enough resources to complete the api docs. Which is really important work for community developers.
Thus, we need to cover as many apis as possible, we need someone to comment on code like we do for dart code.
[20 ICPs, with 10 ICPs bonus for docs site]
Error
1 โ application/cbor, application/cbor
Description:
While execute with update and query call using flutter web, the IC behaves differently between Native and Web, which is on the Web, IC (mainnet) may return dual headers to the client, somehow it's
However, agent_dart using flutter/dart's official http package to make the requests internally. Although the Response
class from Http returns normally, however, while using Response.body
to get a string( in order to display non-bytes error or message), the MediaType.parse
function will throw error since it only supports single type Media type.
Fix:
To set Response.headers manually ,only accept the first content-type and discard the rest, before getting the body string.
Hi,
My name is Eduard, I work in Dfinity's product security team. During one of our internal reviews we've found some security issues in agent_dart. What would be the best way to share the findings with you?
Thanks in advance!
To build a candid builder for agent dart
Candid is used to describe IDL for canister functions.
Candid builder is used to transform candid files to usable functions/classes for agent clients in different languages.
For dart language, all interfaces are classes. To make a workable builder, like we do json decoding classes, candid builder should also transform all those interfaces into classes.
Candid files are trans-compiled into typescript and javascript using didc
, link is here
There are repos maintained by community for other languages:
Since agent_dart is ported agains agent-js
, all IDL interfaces and styles are very similar to javascript/typescript.
for example , in generarted javascript:
const Purpose = IDL.Variant({
'authentication' : IDL.Null,
'recovery' : IDL.Null,
});
const CredentialId = IDL.Vec(IDL.Nat8);
in agent_dart, we can almost simply copy paste
final Purpose = IDL.Variant({
'authentication' : IDL.Null,
'recovery' : IDL.Null,
});
final CredentialId = IDL.Vec(IDL.Nat8);
So we might be able to :
didc
to generate those idl
,To see working classes in dart, please refer to wallet/ledger.dart
didc
to builder to generate idl
s30 ICPs
There are differences between agent_dart
and agent-js
, we can not rely developers understand all features of agent-js
.
updates
Hence we have to make documentation for reference, usage, example.
So we have to document or lit on the code, and later we may use github page to host a example code static site.
[ ] lit the code with comments and usage code.
[ ] write a static doc site and publish with github page
Feel free to submit your projects here, and we will move them to README, and later to doc site
Template below:
My very cool project
Defi DApp/Wallet/Metaverse/Social DApps/Open Service/Tooling....
Your project description
If available
If available, Google Play/ Apple AppStore/ other URL
Hello,
When I try to use IC identity (using local page), I got a normal identity, and the result is like in the example project in this lib. After that, I am calling the IC canister, and I got an error.
Error:
Unhandled Exception: Unhandled error Server returned an error: Code: 403 (Forbidden)
Body: Failed to authenticate request 0x5f5b53a270e40c4558549975f54c17163b24b337054255bc1c2e56705fab9860 due to: Invalid delegation: Invalid canister signature: IcCanisterSignature signature could not be verified: public key 0a000000000000000701012ad6fa197bcc32c16f588d58ccb0468c9bd039c9b60302ad08e03cda98f6243f, signature d9d9f7a26b63657a9.......678301820458200e729de08c6bfa677847fb8d7bcc79efc892045aed2c4b350f7c7446085257f5830182045820b71837514f52507ff04caee7b05a920f1d5ac8863b9d65d3489951ff33b1187e83025820f487586c5bdaaa19d6f10abc3626e44af4624a386c64832659da432f265a61f5830258208b8ee0cf244a56d1b8fa863141be1b473f9e0576d941282124d41e2b44793519820340, error: the signature tree doesn't contain sig/f487586c5bdaaa19d6f10abc3626e44af4624a386c64832659da432f265a61f5/2baf862838777c8dfc951a5b4b3768b5ce23bc641ea0a1172f3e0726de7ae936
I don't have any problem with normal identity (created by myself), but this Delegation one made this error.
Do you have some idea how to solve this problem?
๐ We had a couple of our Flutter SDK developers bring up the parseErrorData
issue #70 and ask us to upgrade to the latest version of agent_dart: ^1.0.0-dev.18
to bypass the error.
Unfortunately, doing so leads to the following error with Xcode:
Here's how the error looks like on my terminal ๐ :
Error (Xcode): Linker command failed with exit code 1 (use -v to see invocation)
Could not build the application for the simulator.
Error launching application on iPhone 15 Pro Max.
When I attempt to add CoreAudioTypes.framework
to the flutter project inside of Xcode I'm met with this warning: CoreAudioTypes.framework is not supported on Mac Catalyst
. ๐ค
We've tried every which way to bypass the above error:
agent_dart
directly vs the Runner targetAs it stands we are unable to run our demo flutter app on iOS (Android works fine ๐) with agent_dart: ^1.0.0-dev.18
and switching back to the older version brings back issue #70. Please help ๐
The error is as follows, but the official agent-js will not have this problem.
I/flutter ( 8497): PollingResponseRejectedException
I/flutter ( 8497): Call was rejected:
I/flutter ( 8497): Request ID: f940e19fa2301477b4e46de087195d03b36105aadc35961feb95a880fb9684d8
I/flutter ( 8497): Reject code: ๏ฟฝ
I/flutter ( 8497): Reject msg: Canister rdmx6-jaaaa-aaaaa-aaadq-cai trapped explicitly: IDL error: did not find tuple field in record
Hi, we upgraded to latest flutter and use magic sdk which depends on agent_dart. We ran into the following issue:
../../../../../.pub-cache/hosted/pub.dev/agent_dart-1.0.0-dev.17/lib/bridge/ffi/ffi_bridge.dart:461:57: Error:
Required named parameter 'parseErrorData' must be provided.
This comes from agent_dart which is referenced in the magic sdk. I tried to pinpoint the agent_dart version and this error shows up for the first time in '1.0.0-dev.15' - Also posted within the magic sdk -> magiclabs/magic-flutter#45
agent_dart is v 1.0.0-dev.17
magic is 4.1.3
[โ] Flutter (Channel stable, 3.13.7, on macOS 13.5.1 22G90 darwin-arm64, locale en-US)
[โ] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[โ] Xcode - develop for iOS and macOS (Xcode 15.0)
[โ] Chrome - develop for the web
[โ] Android Studio (version 2021.2)
[โ] VS Code (version 1.83.0)
[โ] Connected device (3 available)
[โ] Network resources
In agent_dart v1.0.0-dev.17, 'const identityProviderDefault = 'https://identity.icp0.io'' is used in auth_client for Internet Identity login.
However, this setting causes Internet Identity to throw an error stating '...did not resolve to a canister ID.' I confirmed this by comparing it with the latest versions of agent-js and agent_dart 0.1.24+1, both of which use 'https://identity.ic0.app/' and it function as expected.
See the attached screenshot for reference."
I want to send icp to account: 1586275a55430abba47862989da56f2c9ac31bc9f1c58739d6637a33714f307a
Here is my code:
var mne ='xxx';
var p = RosettaApi();
var key = fromMnemonicWithoutValidation(mne, []);
await p.init();
var pre = await p.transferPreCombine(
key.getPublicKey().toRaw(),
hex.HEX.decode(
'1586275a55430abba47862989da56f2c9ac31bc9f1c58739d6637a33714f307a'),
BigInt.from(90000),
BigInt.from(10000),
{});
var s = await transferCombine(key, pre);
var res = await p.transfer_post_combine(s);
print(res);
But when I run code above, I get some error. Could you please give me a code example, thanks.
agent_dart
Branch: 1.0.0-dev
Commit: 0b39334
Stack Trace:
_Exception: Exception: Subclasses of `FlutterRustBridgeBase` should be singletons - there should not be two instances (runtimeType=AgentDartImpl)
File "basic.dart", line 28, in FlutterRustBridgeBase._sanityCheckSingleton
File "basic.dart", line 19, in new FlutterRustBridgeBase
File "ffi_bridge.dart", line 314, in new AgentDartImpl.raw
File "ffi_bridge.dart", line 312, in new AgentDartImpl
File "ffi_helper.dart", line 40, in new AgentDartFFI._
File "ffi_helper.dart", line 50, in AgentDartFFI._instance
File "ed25519.dart", in Ed25519KeyIdentity.generate
File "auth_client.dart", line 212, in AuthClient.login
File "login.dart", line 61, in _LoginScreenState._loginUsingII
The exact function that caused the issue is Ed25519KeyIdentity.generate
from AuthClient package.
After just:
flutter pub add agent_dart
flutter pub add agent_dart_auth
flutter pub add file
I get the following error
../../.pub-cache/hosted/pub.dev/agent_dart-0.1.24+1/lib/archiver/encoder.dart:74:8: Error: The method 'SingingBlockZipFileEncoder.zipDirectory' has fewer named arguments than those of overridden method 'ZipFileEncoder.zipDirectory'.
void zipDirectory(Directory dir,
My env:
Flutter 3.19.0 โข channel stable โข https://github.com/flutter/flutter.git
Framework โข revision bae5e49bc2 (4 weeks ago) โข 2024-02-13 17:46:18 -0800
Engine โข revision 04817c99c9
Tools โข Dart 3.3.0 โข DevTools 2.31.1
Thinking about the keystore file format compatible to ethereum's system, however is not so efficiency. But it still worth finding a replacement to the format.
In dart, to implement the keystore encode/decode, one has to combine the scrypt
and pbkdf2
to it. The easiest way to complete the job is to borrow the code from web3dart
or laksadart
I previously built for Zilliqa. However the encoding speed is too slow because of scrypt algorithm is slow.
Another option is to use FFI from other native
library like ethsign
, it is fast and run smoothly when I tried to bind it to the dynamic library. However, in rust we generally use serde_json
to encode the Crypto
object, the serde_json
will be binded too, which will largely increase the bundle's size.
I don't have enough time to do enough search to finish the task. So if you have idea or solution, please comment or reply.
** updates**
TODO:
[x] auth-client, used for authenticate a flutter app from Internet Identity authing app. tracking this issue: Changes will be required for Internet Identity, adapt to use a web pop window to receive callback
[x] wallet, keysmith, rosetta-api packages implemented
[] candid-ui/candid core, used for generating default ui like the web version
[] candid-parser, used for automated generating Candid file to dart code. Either we use candid-rs
build script or use source_gen
of flutter tool chain.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.