CodeSampleX

Sample

wasm-bindgen-shared 0.2.130

Verified sample for cargo wasm-bindgen-shared 0.2.130. The contract ran on rust 1 · linux alpine/x64 · docker and passed: SCHEMA_VERSION and version() both…

sha256:f80e0ec83e6c14c33430a8d9c73ec748b8e89aed33ca6de266333d5c5f95503a

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment linux x64 cargo

Verification-run environments

Environment Contract Stages Run
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-11-22

Case

HOW
Goal
verify pkg:cargo/wasm-bindgen-shared@0.2.130
Packages
Created
2026-11-22T22:42:55Z

Contract

  1. SCHEMA_VERSION and version() both report "0.2.130"
  2. qualified_name joins non-empty JS namespaces with double underscores and preserves names when namespace is None or empty
  3. mangled_symbol, module_mangled_symbol, const fn module_path_hash, crate_name, and crate_hash build and split per-crate and per-module identifiers
  4. wasm export naming helpers lowercase struct names, prefix __wbg_ helpers, and normalize bracket/dot names like [Symbol.iterator]
  5. escape_string escapes backslashes, newlines, carriage returns, single quotes, and double quotes
  6. identifier module validates JS identifiers, distinguishes value-like vs non-value JS keywords, and normalizes invalid or reserved strings via to_valid_ident
  7. tys exposes distinct descriptor opcodes and SEQ_MODE_* bit flags, and shared_api! expands the shared AST schema

Files

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

Download the source artifact (tar.gz)

Source

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

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

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

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

[dependencies]
wasm-bindgen-shared = "=0.2.130"
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-shared@0.2.130
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/wasm-bindgen-shared@0.2.130
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

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:b107fa133c9cc9eb64ad3e35fbdd73d1fbc4c5aa17f207dea8aa7c16f522d10d","contract":["SCHEMA_VERSION and version() both report \"0.2.130\"","qualified_name joins non-empty JS namespaces with double underscores and preserves names when namespace is None or empty","mangled_symbol, module_mangled_symbol, const fn module_path_hash, crate_name, and crate_hash build and split per-crate and per-module identifiers","wasm export naming helpers lowercase struct names, prefix __wbg_ helpers, and normalize bracket/dot names like [Symbol.iterator]","escape_string escapes backslashes, newlines, carriage returns, single quotes, and double quotes","identifier module validates JS identifiers, distinguishes value-like vs non-value JS keywords, and normalizes invalid or reserved strings via to_valid_ident","tys exposes distinct descriptor opcodes and SEQ_MODE_* bit flags, and shared_api! expands the shared AST schema"],"goal":"verify pkg:cargo/wasm-bindgen-shared@0.2.130","kind":"HOW","packages":["pkg:cargo/wasm-bindgen-shared@0.2.130"],"schemaVersion":1},"contractCommand":["cargo","test","--offline"],"environment":{"arch":"x64","ecosystem":"cargo","os":"linux","packageManager":"cargo","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/wasm-bindgen-shared@0.2.130"],"schemaVersion":1,"subject":"pkg:cargo/wasm-bindgen-shared@0.2.130","verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:cargo/wasm-bindgen-shared@0.2.130",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/wasm-bindgen-shared@0.2.130"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/main.rs
use wasm_bindgen_shared::{
    crate_hash, crate_name, escape_string, identifier, mangled_symbol, module_mangled_symbol,
    module_path_hash, new_function, qualified_name, struct_function_export_name, tys, version,
    SCHEMA_VERSION,
};

fn main() {
    let qn = qualified_name(Some(&["app", "math"]), "add");
    let mangled = mangled_symbol("add", "a1b2c3");
    let mod_mangled = module_mangled_symbol("add", "a1b2c3", "demo::math");
    let hash = module_path_hash("demo::math");
    let cname = crate_name("my-crate-a1b2c3");
    let chash = crate_hash("my-crate-a1b2c3");
    let ctor = new_function("Counter");
    let sym = struct_function_export_name("Counter", "[Symbol.iterator]");
    let escaped = escape_string("line1\n\"ok\"");
    let ident = identifier::to_valid_ident("class");

    println!(
        "schema={} version={} qn={} mangled={} mod_mangled={} hash={:#x} crate={}#{} ctor={} sym={} escaped={} ident={} seq_flags={}",
        SCHEMA_VERSION,
        version(),
        qn,
        mangled,
        mod_mangled,
        hash,
        cname,
        chash,
        ctor,
        sym,
        escaped,
        ident,
        tys::SEQ_MODE_COPY | tys::SEQ_MODE_VEC,
    );
}
tests/contract.rs
use wasm_bindgen_shared::{
    crate_hash, crate_name, dynamic_union_variant, escape_string, free_function,
    free_function_export_name, identifier, mangled_symbol, module_mangled_symbol, module_path_hash,
    new_function, qualified_name, shared_api, struct_field_get, struct_field_set,
    struct_function_export_name, tys, unwrap_function, upcast_function, version, SCHEMA_VERSION,
};

#[test]
fn schema_and_crate_version_match_0_2_130() {
    assert_eq!(SCHEMA_VERSION, "0.2.130");
    assert_eq!(version(), "0.2.130");
}

#[test]
fn qualified_name_joins_namespaces_with_double_underscores() {
    let none: Option<&[&str]> = None;
    let empty: &[&str] = &[];
    assert_eq!(qualified_name(none, "render"), "render");
    assert_eq!(qualified_name(Some(empty), "render"), "render");
    assert_eq!(qualified_name(Some(&["ui"]), "render"), "ui__render");
    assert_eq!(
        qualified_name(Some(&["app", "ui", "canvas"]), "render"),
        "app__ui__canvas__render"
    );
}

#[test]
fn crate_and_module_mangling_and_hashing() {
    assert_eq!(mangled_symbol("init", "deadbeef"), "init_deadbeef");
    assert_eq!(
        module_mangled_symbol("init", "deadbeef", "demo::net"),
        "init_deadbeef_demo::net"
    );

    const HASH_EMPTY: u32 = module_path_hash("");
    const HASH_A: u32 = module_path_hash("demo::alpha");
    const HASH_B: u32 = module_path_hash("demo::beta");
    assert_eq!(HASH_EMPTY, 0x811c_9dc5);
    assert_eq!(HASH_A, module_path_hash("demo::alpha"));
    assert_ne!(HASH_A, HASH_B);

    assert_eq!(crate_name("my-wasm-lib-9f8e7d"), "my-wasm-lib");
    assert_eq!(crate_hash("my-wasm-lib-9f8e7d"), "9f8e7d");
    assert_eq!(crate_name("single"), "single");
    assert_eq!(crate_hash("single"), "single");
}

#[test]
fn wasm_export_naming_helpers_normalize_names() {
    assert_eq!(new_function("HttpClient"), "__wbg_httpclient_new");
    assert_eq!(free_function("HttpClient"), "__wbg_httpclient_free");
    assert_eq!(unwrap_function("HttpClient"), "__wbg_httpclient_unwrap");
    assert_eq!(
        upcast_function("SubNode", "BaseNode"),
        "__wbg_upcast_subnode_to_basenode"
    );

    assert_eq!(free_function_export_name("compute"), "compute");
    assert_eq!(
        free_function_export_name("[Symbol.asyncIterator]"),
        "Symbol_asyncIterator"
    );
    assert_eq!(
        struct_function_export_name("Stream", "[Symbol.iterator]"),
        "stream_Symbol_iterator"
    );
    assert_eq!(
        struct_function_export_name("Point", "distance-2d"),
        "point_distance_2d"
    );
    assert_eq!(struct_field_get("Point", "x"), "__wbg_get_point_x");
    assert_eq!(struct_field_set("Point", "y"), "__wbg_set_point_y");
    assert_eq!(
        dynamic_union_variant("Payload", 2),
        "__wbg_dynamic_union_payload_2"
    );
}

#[test]
fn escape_string_escapes_control_quotes_and_backslashes() {
    assert_eq!(escape_string("plain text 123"), "plain text 123");
    assert_eq!(
        escape_string("a\\b\nc\rd'e\"f"),
        "a\\\\b\\nc\\rd\\'e\\\"f"
    );
}

#[test]
fn identifier_validation_keywords_and_normalization() {
    assert!(identifier::is_valid_ident("validName_1"));
    assert!(identifier::is_valid_ident("$dollar"));
    assert!(!identifier::is_valid_ident(""));
    assert!(!identifier::is_valid_ident("9startsWithDigit"));
    assert!(!identifier::is_valid_ident("kebab-case"));

    assert!(identifier::is_js_keyword("class"));
    assert!(identifier::is_js_keyword("this"));
    assert!(!identifier::is_js_keyword("widget"));

    assert!(identifier::is_non_value_js_keyword("class"));
    assert!(identifier::is_non_value_js_keyword("return"));
    assert!(!identifier::is_non_value_js_keyword("this"));
    assert!(!identifier::is_non_value_js_keyword("true"));
    assert!(!identifier::is_non_value_js_keyword("eval"));

    assert_eq!(identifier::to_valid_ident(""), "_");
    assert_eq!(identifier::to_valid_ident("1abc-def"), "_abc_def");
    assert_eq!(identifier::to_valid_ident("class"), "_class");
    assert_eq!(identifier::to_valid_ident("this"), "_this");
    assert_eq!(identifier::to_valid_ident("ok_ident"), "ok_ident");
}

#[test]
fn tys_opcodes_and_seq_mode_flags() {
    assert_eq!(tys::I8, 0);
    assert_ne!(tys::STRING, tys::CACHED_STRING);
    assert_ne!(tys::DYNAMIC_UNION, tys::ENUM);
    assert_ne!(tys::SEQ_MODE, tys::NULLABLE);

    assert_eq!(tys::SEQ_MODE_VIEW, 0);
    assert_eq!(tys::SEQ_MODE_COPY, 1);
    assert_eq!(tys::SEQ_MODE_ARRAY, 2);
    assert_eq!(tys::SEQ_MODE_VEC, 4);
    assert_eq!(tys::SEQ_MODE_EXPLICIT, 8);
}

macro_rules! collect_shared_api_names {
    (@acc [$($names:expr),*]) => {
        &[$($names),*] as &[&str]
    };
    (@acc [$($names:expr),*] struct $name:ident $(<$lt:lifetime>)? { $($body:tt)* } $($rest:tt)*) => {
        collect_shared_api_names!(@acc [$($names,)* stringify!($name)] $($rest)*)
    };
    (@acc [$($names:expr),*] enum $name:ident $(<$lt:lifetime>)? { $($body:tt)* } $($rest:tt)*) => {
        collect_shared_api_names!(@acc [$($names,)* stringify!($name)] $($rest)*)
    };
    ($($tt:tt)*) => {
        collect_shared_api_names!(@acc [] $($tt)*)
    };
}

#[test]
fn shared_api_macro_expands_schema_definitions() {
    let names = shared_api!(collect_shared_api_names);
    assert!(names.contains(&"Program"));
    assert!(names.contains(&"ImportKind"));
    assert!(names.contains(&"DynamicUnion"));
    assert!(names.contains(&"StartKind"));
    assert!(names.contains(&"LocalModule"));
}

Origin Seeder

anonymous