-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
34 changed files
with
6,721 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: Rust | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v1 | ||
- name: Run installation | ||
run: make install | ||
- name: Run CI | ||
run: make ci | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,11 @@ | ||
# Generated by Cargo | ||
# will have compiled files and executables | ||
debug/ | ||
target/ | ||
# Rust | ||
target | ||
.cache/.cargo/* | ||
|
||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries | ||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html | ||
Cargo.lock | ||
# C | ||
contracts/c/build/* | ||
|
||
# These are backup files generated by rustfmt | ||
**/*.rs.bk | ||
|
||
# MSVC Windows builds of rustc generate these, which store debugging information | ||
*.pdb | ||
# others | ||
build/* | ||
!.gitkeep | ||
.tmp/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"rust-analyzer.cargo.target": "riscv64imac-unknown-none-elf" | ||
} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[workspace] | ||
members = ["ckb-typed-message", "contracts/typed-message-lock-demo"] | ||
exclude = ["tests"] | ||
|
||
[profile.release] | ||
overflow-checks = true | ||
opt-level = 3 | ||
panic = 'abort' | ||
strip = true | ||
lto = true | ||
debug-assertions = true | ||
|
||
[profile.dev] | ||
strip = true | ||
opt-level = 1 | ||
debug = false | ||
panic = 'abort' | ||
debug-assertions = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[build] | ||
default-target = "riscv64imac-unknown-none-elf" | ||
|
||
[target.riscv64imac-unknown-none-elf] | ||
image = "nervos/ckb-riscv-gnu-toolchain:focal-20230214" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
|
||
all: | ||
capsule build --release | ||
|
||
mol: | ||
moleculec --language rust --schema-file schemas/basic.mol > ckb-typed-message/src/schemas/basic.rs | ||
moleculec --language rust --schema-file schemas/top_level.mol > ckb-typed-message/src/schemas/top_level.rs | ||
cargo fmt | ||
|
||
install: | ||
rustup target add riscv64imac-unknown-none-elf | ||
cargo install cross --git https://github.com/cross-rs/cross | ||
wget 'https://github.com/nervosnetwork/capsule/releases/download/v0.10.2/capsule_v0.10.2_x86_64-linux.tar.gz' | ||
tar zxvf capsule_v0.10.2_x86_64-linux.tar.gz | ||
mv capsule_v0.10.2_x86_64-linux/capsule ~/.cargo/bin | ||
cargo install [email protected] --locked | ||
|
||
ci: | ||
capsule build --release | ||
cd tests && cargo test && cd .. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# ckb-typed-message(PoC) | ||
This project is a proof of concept that aims to demonstrate how to adopt typed | ||
messages (similar to EIP-712) in scripts. It also includes extended witnesses to | ||
simplify signing and DApp interoperability. | ||
|
||
|
||
## Build | ||
Build contracts: | ||
|
||
``` sh | ||
capsule build | ||
``` | ||
|
||
Run tests: | ||
|
||
``` sh | ||
capsule test | ||
``` |
Empty file.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# [rust] | ||
# # path of rust contracts workspace directory, | ||
# # a `Cargo.toml` file is expected under the directory. | ||
# workspace_dir = "." | ||
|
||
# capsule version | ||
version = "0.10.2 5e49142" | ||
# path of deployment config file | ||
deployment = "deployment.toml" | ||
|
||
[[contracts]] | ||
name = "typed-message-lock-demo" | ||
template_type = "Rust" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "ckb-typed-message" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
blake2b-ref = "0.3.1" | ||
ckb-std = { version = "0.14.3", default-features = false, features = ["ckb-types", "calc-hash"] } | ||
molecule = { version = "0.7.5", default-features = false } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
This is a library used for writing scripts that are intended to support typed | ||
messages on CKB. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
pub use blake2b_ref::{Blake2b, Blake2bBuilder}; | ||
|
||
pub const CKB_PERSONALIZATION: &[u8] = b"ckb-default-hash"; | ||
|
||
pub fn new_blake2b() -> Blake2b { | ||
Blake2bBuilder::new(32) | ||
.personal(CKB_PERSONALIZATION) | ||
.build() | ||
} | ||
|
||
pub fn hash(bytes: &[u8]) -> [u8; 32] { | ||
let mut hasher = new_blake2b(); | ||
hasher.update(bytes); | ||
|
||
let mut hash = [0u8; 32]; | ||
hasher.finalize(&mut hash); | ||
hash | ||
} |
Oops, something went wrong.