A rust library containing typings and utility functions dealing with the Public specification of the Internet Computer.

Overview

IC Types

Contributing

Please follow the guidelines in the CONTRIBUTING.md document.

Goal

This library contains typings and utility functions dealing with the Public specification of the Internet Computer and the HTTP client. It might be shared in the future but for now is separated for the purpose of testing and development.

Running Tests

Regular tests can be run by anyone using cargo test. This will not run a special version of the tests that runs against a server implementation of the public specification, though those tests can be run against a compatible Replica.

References

See https://sdk.dfinity.org/docs/interface-spec/index.html

Comments
  • Revert

    Revert "Fix Principal serde_json"

    This reverts commit a3339a3950825cc69cf53d37fb786b41e793088b.

    The above commit seems to be the cause of internal errors when used: deserialize_str trying to deserialize a principal.

    Caused by:
        0: input: 4449444c016c01b3c4b1f204680100_0109010400000000000001
           table: type table0 = record { 1_313_628_723 : principal }
           wire_type: principal, expect_type: principal
        1: Deserialize error: Internal error at /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/candid-0.7.3/src/de.rs:459. Please file a bug.))', /home/runner/work/agent-rs/agent-rs/main/ref-tests/src/utils.rs:96:23
    
    opened by ericswanson-dfinity 6
  • Principal can't transfer from the bytes

    Principal can't transfer from the bytes

    data=[10, 116, 105, 100, 0, 0, 0, 0, 0, 144, 0, 51, 1, 1, 0, 0, 0, 4] javascript codePrincipal.fromUint8Array(data) that works well, rust code Principal::try_from_slice(data) that will throw a error(BufferTooLong)

    "dependencies": { (javascript)
    "@dfinity/principal": "^0.10.2"
    }
    
    [dependencies](rust)
    ic-types = "0.3.0"
    
    opened by JesseChing 2
  • refactor!: remove principal

    refactor!: remove principal

    We believe candid is a better place for Principal. It makes dependency management easier. The relevant PR for candid is: https://github.com/dfinity/candid/pull/378

    ic-types now only has hash_tree module.

    opened by lwshang 1
  • refactor: Principal overhaul

    refactor: Principal overhaul

    This refactor introduced breaking changes, so bumped up version to 0.4.0-beta.0.

    Breaking changes

    • Remove PrincipalInner
      • Principal directly holds len and bytes fields
    • PrincipalError enum has different set of variants reflecting changes in from_text logic.
    • from_text accepts input containing uppercase letters which results in Err before.
    • from_text verifies CRC32 check sequence

    Implementation details

    • Mark Principal::from_slice as deprecated
      • It panics if input longer than 29 bytes
      • recommend to use try_from_slice
    • Move all tests to root/tests folder so that we only test public visible behavior
    • Use data-encoding instead of base32
      • base32 wrongly accepts invalid base32 string which makes error handling in from_text not clear
      • data-encoding is better maintained and has more dependents and downloads
    • Use serde_test
      • serde_json and serde_cbor are kept in dev-dependencies because of doc-tests
    • Use impl::impl! macro to verify the necessary traits are implemented

    Discussion about data layout

    struct Principal(PrincipleInner);
    #[repr(packed)]
    struct PrincipleInner {
      len: u8,
      bytes: [u8; 29],
    }
    

    After removing the layer of PrincipalInner, it becomes:

    #[repr(packed)]
    struct Principal {
      len: u8,
      bytes: [u8; 29],
    }
    

    I'm not sure whether we should keep the repr(packed) here. The Rust Nomicon says:

    repr(packed) forces Rust to strip any padding, and only align the type to a byte. This may improve the memory footprint, but will likely have other negative side-effects.

    https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=8b19c6d46a7600f575cc936c9dd746ca With or without repr(packed), the type always has size of 30.

    opened by lwshang 1
  • refactor: Faster copy loop

    refactor: Faster copy loop

    The cost of using a recursive function in copying some bytes is not negligible and actually shows up as a cost center in flamegraph.

    The fix is simple: use a while loop to do the copy.

    opened by ninegua 1
  • Add ledger-related types

    Add ledger-related types

    A stable Candid interface is coming, so it'd be nice to have the related types publicly available. Types we might want to expose:

    • Vocabulary types: AccountIdentifier, Subaccount, ICPTs, etc.
    • Request types: AccountBalanceArgs, TransferArgs, etc.
    • Error variants (TransferError).
    opened by roman-kashitsyn 1
  • fix: undo deprecate from_slice

    fix: undo deprecate from_slice

    from_slice is still useful when creating global const value:

    pub const MAINNET_LEDGER_CANISTER_ID: Principal =
        Principal::from_slice(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x01, 0x01]);
    

    try_from_slice needs unwrap() which is not allowed here.

    opened by lwshang 0
  • feat: More efficient deserializer for Principal

    feat: More efficient deserializer for Principal

    The deserialization path shows up in flamegraph analysis when we ran performance test.

    So maybe it is worth special casing since it doesn't need to go through the const function.

    opened by ninegua 0
  • fix: specify repository field so that crates.io links to it

    fix: specify repository field so that crates.io links to it

    Otherwise one might think it comes from https://github.com/dfinity/ic/tree/master/rs/types

    See https://doc.rust-lang.org/cargo/reference/manifest.html#the-repository-field

    opened by ericswanson-dfinity 0
  • fix: display only ASCII graphic blobs as strings

    fix: display only ASCII graphic blobs as strings

    This change changes the display tree labels to be more concervative.

    Before, we printed everything that is valid UTF-8 as strings. This causes problems if the input is a byte string with lots of zeros.

    For example, canister id 0x00000000000000070101 gets printed as "" in my terminal.

    After this change, we will only print blobs as strings if all the bytes are graphic ASCII characters.

    opened by roman-kashitsyn 0
  • chore: update outdated dependencies

    chore: update outdated dependencies

    Before:

    $ cargo outdated -R
    Name        Project  Compat   Latest   Kind         Platform
    ----        -------  ------   ------   ----         --------
    serde       1.0.126  1.0.127  1.0.127  Normal       ---
    serde_cbor  0.11.1   0.11.2   0.11.2   Development  ---
    serde_json  1.0.64   1.0.66   1.0.66   Development  ---
    thiserror   1.0.25   1.0.26   1.0.26   Normal       ---
    

    After:

    $ cargo outdated -R
    All dependencies are up to date, yay!
    
    
    opened by ericswanson-dfinity 0
Owner
DFINITY
The Internet Computer aims to reinvent the internet as a computer to host secure software and a new breed of open internet services.
DFINITY
Call Swift functions from Rust with ease!

swift-rs Call Swift functions from Rust with ease! Setup After adding swift-rs to your project's Cargo.toml, some setup work must be done. Ensure your

null 68 Dec 26, 2022
A collection of unsound rust functions using entirly *safe* code

A collection of unsound rust functions using entirly *safe* code

null 2 Sep 6, 2022
Pedersen hashing functions with JS <> Rust interoperability

Pedersen Hash This library exposes the following functions: pub fn pedersen(x: &str, y: &str) -> String: Geometry version. pub fn starknet_pedersen(x:

Herodotus 2 Nov 17, 2022
Unstable wrapper API for winapi's Console Functions

maulingmonkey-console-winapi-wrappers Unstable wrapper API for winapi's Console Functions Quickstart # Cargo.toml [dependencies] maulingmonkey-console

null 3 Nov 26, 2021
A notebook app integrated with todo lists utility. Developed with Rust, WebAssembly, Yew and Trunk.

Flow.er A notebook app integrated with todo-list utility. Project flow.er is a Rust WASM app running in browser. Taking advantage of Yew and Trunk, it

null 45 Dec 31, 2022
ruby-build is a command-line utility that makes it easy to install virtually any version of Ruby, from source.

ruby-build ruby-build is a command-line utility that makes it easy to install virtually any version of Ruby, from source. It is available as a plugin

null 3.7k Jan 5, 2023
Rust Attribute-Based Encryption library rabe's C FFI binding , support CP-ABE and KP-ABE encrypt and decrypt, submodule of Rabe.Core c# library.

Rabe-ffi Rust Attribute-Based Encryption library rabe's C FFI binding , support CP-ABE and KP-ABE encrypt and decrypt, submodule of Rabe.Core c# libra

Aya0wind 2 Oct 10, 2022
Rust library for build scripts to compile C/C++ code into a Rust library

A library to compile C/C++/assembly into a Rust library/application.

Alex Crichton 1.3k Dec 21, 2022
Robust and Fast tokenizations alignment library for Rust and Python

Robust and Fast tokenizations alignment library for Rust and Python Demo: demo Rust document: docs.rs Blog post: How to calculate the alignment betwee

Explosion 157 Dec 28, 2022
A minimalist and safe ECS library for rust!

The full ECS (Entity-Component-System) library. Support an Open Source Developer! ♥️ Composed of two smaller libraries: world_dispatcher: the System p

Joël Lupien 124 Dec 19, 2022
Fastest lz4 compression library in Node.js, powered by napi-rs and lz4-flex.

Lz4 Fastest lz4 compression library in Node.js, powered by napi-rs and lz4-flex. Install this package yarn add lz4-napi API export function compress:

Antonio Musolino 34 Nov 22, 2022
Rust library to interface with Lua

hlua This library is a high-level binding for Lua 5.2. You don't have access to the Lua stack, all you can do is read/write variables (including callb

Pierre Krieger 488 Dec 26, 2022
A library for functional programming in Rust

It contains purely functional data structures to supplement the functional programming needs alongside with the Rust Standard Library.

Jason Shin 1.1k Dec 30, 2022
Lineiform is a meta-JIT library for Rust interpreters

Lineiform Lineiform is a meta-JIT library for Rust interpreters. Given an interpreter that uses closure generation, it allows an author to add minimal

null 112 Jan 4, 2023
libnotcurses-sys is a low-level Rust wrapper for the notcurses C library

libnotcurses-sys is a low-level Rust wrapper for the notcurses C library This library is built with several layers of zero-overhead abstractions over

nick black 29 Nov 26, 2022
A minimal library for building compiled Node.js add-ons in Rust via Node-API

A minimal library for building compiled Node.js add-ons in Rust via Node-API

Node-API (N-API) for Rust 3.1k Dec 29, 2022
Stack unwinding library in Rust

Unwinding library in Rust and for Rust This library serves two purposes: Provide a pure Rust alternative to libgcc_eh or libunwind. Provide easier unw

Gary Guo 51 Nov 4, 2022
witgen is a library to generate .wit files for WebAssembly in Rust

witgen witgen is a library to help you generate wit definitions in a wit file for WebAssembly. Using this lib in addition to wit-bindgen will help you

Coenen Benjamin 28 Nov 9, 2022
A simple library to allow for easy use of python from rust.

Rustpy A simple library to allow for easy use of python from rust. Status Currently this library has not received much love (pull requests welcome for

Luke 74 Jun 20, 2022