Ic-agent Whether the package cannot be used on the IC chain

I did it after importing ic-agent = “0.22.0” package
An error will be reported after the dfx deploy command

The specific error information is as follows

I searched for some projects in dfinity and found that quill and dfx etc. used this module
As far as I know, the cycles-wallet project should exist in the form of a container on the chain. I did not find any reference to the ic-agent package in this project [it may also be that this project does not use this package]
And I created a clean rust project locally and no errors occurred when importing the same module, so I guess whether the ic-agent package is not allowed on the chain or requires some special configuration to use this package on the chain


serde = "1"
candid = "0.8.4"
ic-cdk = "0.7.1"
hex = "0.4.3"
sha2 = "0.10.6"
serde_json = "1.0.94"
k256 = { version = "0.12.0", features = ["ecdsa"] }
# Enable `custom` feature of k256's getrandom dependency. See lib.rs for more details.
getrandom = { version = "0.2", features = ["custom"] }
ic-agent = "0.22.0"

The information during deploy is

Deploying all canisters.
All canisters have already been created.
Building canisters...
WARN: Cannot check for vulnerabilities in rust canisters because cargo-audit is not installed. Please run 'cargo install cargo-audit' so that vulnerabilities can be detected.
Executing: cargo build --target wasm32-unknown-unknown --release -p ecdsa_example --locked
   Compiling mio v0.8.6
   Compiling socket2 v0.4.9
   Compiling rustls-native-certs v0.6.2
error[E0433]: failed to resolve: use of undeclared crate or module `platform`
  --> /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/rustls-native-certs-0.6.2/src/lib.rs:50:42
50 |     load_certs_from_env().unwrap_or_else(platform::load_native_certs)
   |                                          ^^^^^^^^ use of undeclared crate or module `platform`

error[E0583]: file not found for module `sys`
   --> /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.4.9/src/lib.rs:124:1
124 | mod sys;
    | ^^^^^^^^
    = help: to create the module `sys`, create file "/home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.4.9/src/sys.rs" or "/home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.4.9/src/sys/mod.rs"

error: Socket2 doesn't support the compile target
   --> /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.4.9/src/lib.rs:127:1
127 | compile_error!("Socket2 doesn't support the compile target");
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0433`.
error: could not compile `rustls-native-certs` due to previous error
warning: build failed, waiting for other jobs to finish...
error[E0432]: unresolved import `crate::sys::IoSourceState`
  --> /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.8.6/src/io_source.rs:12:5
12 | use crate::sys::IoSourceState;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^ no `IoSourceState` in `sys`

error[E0432]: unresolved import `crate::sys::tcp`
  --> /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.8.6/src/net/tcp/listener.rs:15:17
15 | use crate::sys::tcp::{bind, listen, new_for_addr};
   |                 ^^^ could not find `tcp` in `sys`

error[E0432]: unresolved import `crate::sys::tcp`
  --> /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.8.6/src/net/tcp/stream.rs:13:17
13 | use crate::sys::tcp::{connect, new_for_addr};
   |                 ^^^ could not find `tcp` in `sys`

error[E0432]: unresolved imports `crate::sys::sa_family_t`, `crate::sys::sockaddr`, `crate::sys::sockaddr_in`, `crate::sys::sockaddr_in6`, `crate::sys::sockaddr_storage`, `crate::sys::socklen_t`, `crate::sys::AF_INET`, `crate::sys::AF_INET6`
 --> /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.4.9/src/sockaddr.rs:6:5
6 |     sa_family_t, sockaddr, sockaddr_in, sockaddr_in6, sockaddr_storage, socklen_t, AF_INET,
  |     ^^^^^^^^^^^  ^^^^^^^^  ^^^^^^^^^^^  ^^^^^^^^^^^^  ^^^^^^^^^^^^^^^^  ^^^^^^^^^  ^^^^^^^ no `AF_INET` in `sys`
  |     |            |         |            |             |                 |
  |     |            |         |            |             |                 no `socklen_t` in `sys`
  |     |            |         |            |             no `sockaddr_storage` in `sys`
  |     |            |         |            no `sockaddr_in6` in `sys`
  |     |            |         no `sockaddr_in` in `sys`
  |     |            no `sockaddr` in `sys`
  |     no `sa_family_t` in `sys`
7 |     AF_INET6,
  |     ^^^^^^^^ no `AF_INET6` in `sys`
help: consider importing this module instead
6 |     sa_family_t, crate::sockaddr;
  |                  ~~~~~~~~~~~~~~~~

error[E0432]: unresolved imports `crate::sys::c_int`, `crate::sys::getsockopt`, `crate::sys::setsockopt`, `crate::sys::Bool`
  --> /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.4.9/src/socket.rs:23:24
23 | use crate::sys::{self, c_int, getsockopt, setsockopt, Bool};
   |                        ^^^^^  ^^^^^^^^^^  ^^^^^^^^^^  ^^^^ no `Bool` in `sys`
   |                        |      |           |
   |                        |      |           no `setsockopt` in `sys`
   |                        |      no `getsockopt` in `sys`
   |                        no `c_int` in `sys`
help: consider importing one of these items instead

Hey @ic_axb,

you are right. ic-agent is a client library to be used in Rust programs running outside the IC that want to interact with canisters on the IC. ic-agent interacts with the HTTPS API of the Internet Computer through the Boundary Nodes.

Inside the IC, i.e. in a canister, you use ic_cdk to interact with other canisters.

1 Like

The cycles wallet is in this repo, and it uses ic-cdk since it is a canister and not ic-agent

For some reasons it is necessary to use the functionality of the ic-agent package inside the container
Reason [Target container rejects request for non-user principal]

I don’t know how to describe here, what I know is
The main body of the container is about (ryjl3-tyaaa-aaaaa-aaaba-cai) 27-bit length
The user’s principal is (q7dr5-woneo-gshtg-fukia-nvlyp-ykdlo-mecic-ufdw2-jj475-sxpxi-wax) 63 bits in length

My idea is to use tecdsa to create a user principal, and then manipulate the user to perform corresponding operations

I read most of the source code of ic-agent and found that only the nonce generation needs to be modified. Here I use the raw_rand method of the aaaaa-aa container

and identity in
The sender uses the ecdsa_public_key method instead to get the public key
sign instead use the sign_with_ecdsa method for signing

Do you have any suggestions? Or is there an easier-to-use package or method

I don’t have a good suggestion. In addition to the changes you mentioned, you’d also need to change the HTTP request implementation to use Internet Computer Content Validation Bootstrap.