CodeSampleX

샘플

wasm-bindgen 0.2.128

검증된 샘플 — cargo wasm-bindgen 0.2.128. rust 1 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: #[wasm_bindgen] exports Rust enums, structs, constructors…

sha256:17c0faafd14513f63daa1d70edd905ad01f27733869a31504add683064847908

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 linux x64 rust cargo

검증 실행 환경

환경 컨트랙트 단계 실행일
rust 1 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · cargo@1rust:1-alpine@sha256:a10e64dd139b…
2026-10-17

케이스

HOW
목표
verify pkg:cargo/wasm-bindgen@0.2.128
패키지
생성일
2026-10-17T09:54:49Z

컨트랙트

  1. #[wasm_bindgen] exports Rust enums, structs, constructors, getters, setters, and functions that compile and execute on host targets when they do not invoke imported JS bindings
  2. Counter::new(10, Mode::Fast) initializes value to 10 and mode to Mode::Fast, increment(5) returns 15, set_value(20) updates value to 20, and add_values(20, 7) returns 27
  3. JsValue::null() and JsValue::undefined() construct singleton JsValue constants safe to drop on non-wasm targets without calling imported JS functions
  4. UnwrapThrowExt::unwrap_throw and expect_throw unwrap Ok(42) and Some(99) on host targets without invoking JS throw imports

파일

  • Cargo.lock
  • Cargo.toml
  • PROMPT.md
  • csx.json
  • spec.json
  • src/main.rs

소스 아티팩트 내려받기 (tar.gz)

소스

Cargo.lock
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4

[[package]]
name = "bumpalo"
version = "3.20.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649"

[[package]]
name = "cfg-if"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"

[[package]]
name = "once_cell"
version = "1.21.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"

[[package]]
name = "proc-macro2"
version = "1.0.107"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
dependencies = [
 "unicode-ident",
]

[[package]]
name = "quote"
version = "1.0.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
dependencies = [
 "proc-macro2",
]

[[package]]
name = "rustversion"
version = "1.0.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f"

[[package]]
name = "sample-wasm-bindgen"
version = "0.1.0"
dependencies = [
 "wasm-bindgen",
]

[[package]]
name = "syn"
version = "3.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d78c8dee4c7bf0e14673097256fed6142ce9d3b85a408189d07482442145823b"
dependencies = [
 "proc-macro2",
 "quote",
 "unicode-ident",
]

[[package]]
name = "unicode-ident"
version = "1.0.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"

[[package]]
name = "wasm-bindgen"
version = "0.2.128"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aecb87a33d3b0c5e3b7aa46336eaf486cffafbd281b195e4c8b80d50df2351bf"
dependencies = [
 "cfg-if",
 "once_cell",
 "rustversion",
 "wasm-bindgen-macro",
 "wasm-bindgen-shared",
]

[[package]]
name = "wasm-bindgen-macro"
version = "0.2.128"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a690d511e3c1a8b3a55e33511e3c2c00c78415cd23650f32b808627f5696b9ed"
dependencies = [
 "quote",
 "wasm-bindgen-macro-support",
]

[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.128"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "411e4887f0071ef2d2164a9d5fdf2d20efbef78fccd3a78b0c10a1dc5295e48a"
dependencies = [
 "bumpalo",
 "proc-macro2",
 "quote",
 "syn",
 "wasm-bindgen-shared",
]

[[package]]
name = "wasm-bindgen-shared"
version = "0.2.128"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81941cd78d0c92026c33e5e01312845a4cb1e9af3407f9134b100dd03144103e"
dependencies = [
 "unicode-ident",
]
Cargo.toml
[package]
name = "sample-wasm-bindgen"
version = "0.1.0"
edition = "2021"

[dependencies]
wasm-bindgen = "=0.2.128"
PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify pkg:cargo/wasm-bindgen@0.2.128
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/wasm-bindgen@0.2.128

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:518d716bae94738b53b61adb3bfa0756547f2080f574d2fe00a0f4f3398ea0de","contract":["#[wasm_bindgen] exports Rust enums, structs, constructors, getters, setters, and functions that compile and execute on host targets when they do not invoke imported JS bindings","Counter::new(10, Mode::Fast) initializes value to 10 and mode to Mode::Fast, increment(5) returns 15, set_value(20) updates value to 20, and add_values(20, 7) returns 27","JsValue::null() and JsValue::undefined() construct singleton JsValue constants safe to drop on non-wasm targets without calling imported JS functions","UnwrapThrowExt::unwrap_throw and expect_throw unwrap Ok(42) and Some(99) on host targets without invoking JS throw imports"],"goal":"verify pkg:cargo/wasm-bindgen@0.2.128","kind":"HOW","packages":["pkg:cargo/wasm-bindgen@0.2.128"],"schemaVersion":1,"symbols":["wasm_bindgen::prelude::wasm_bindgen","wasm_bindgen::JsValue","wasm_bindgen::UnwrapThrowExt"]},"contractCommand":["cargo","run","--offline"],"environment":{"arch":"x64","ecosystem":"cargo","language":"rust","os":"linux","packageManager":"cargo","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/wasm-bindgen@0.2.128"],"schemaVersion":1,"subject":"pkg:cargo/wasm-bindgen@0.2.128","verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:cargo/wasm-bindgen@0.2.128",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/wasm-bindgen@0.2.128"
  ]
}
src/main.rs
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsValue;

#[wasm_bindgen]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Mode {
    Fast = 1,
    Safe = 2,
}

#[wasm_bindgen]
pub struct Counter {
    value: u32,
    mode: Mode,
}

#[wasm_bindgen]
impl Counter {
    #[wasm_bindgen(constructor)]
    pub fn new(initial: u32, mode: Mode) -> Counter {
        Counter {
            value: initial,
            mode,
        }
    }

    pub fn increment(&mut self, delta: u32) -> u32 {
        self.value += delta;
        self.value
    }

    #[wasm_bindgen(getter)]
    pub fn value(&self) -> u32 {
        self.value
    }

    #[wasm_bindgen(setter)]
    pub fn set_value(&mut self, value: u32) {
        self.value = value;
    }

    #[wasm_bindgen(getter)]
    pub fn mode(&self) -> Mode {
        self.mode
    }
}

#[wasm_bindgen]
pub fn add_values(a: u32, b: u32) -> u32 {
    a + b
}

fn main() {
    let mut counter = Counter::new(10, Mode::Fast);
    assert_eq!(counter.value(), 10);
    assert_eq!(counter.mode(), Mode::Fast);
    assert_eq!(counter.increment(5), 15);
    counter.set_value(20);
    assert_eq!(counter.value(), 20);
    assert_eq!(add_values(counter.value(), 7), 27);

    let _null_val: JsValue = JsValue::null();
    let _undef_val: JsValue = JsValue::undefined();

    let ok_val: Result<u32, &str> = Ok(42);
    assert_eq!(ok_val.unwrap_throw(), 42);
    let some_val: Option<u32> = Some(99);
    assert_eq!(some_val.expect_throw("present"), 99);
}

오리진 시더

익명