Skip to content

Implement UniFFI proc-macro FFI bindings for uts-core#67

Draft
Copilot wants to merge 3 commits intofeat/uniffifrom
copilot/explore-sdk-usage-uniffi-wrapper
Draft

Implement UniFFI proc-macro FFI bindings for uts-core#67
Copilot wants to merge 3 commits intofeat/uniffifrom
copilot/explore-sdk-usage-uniffi-wrapper

Conversation

Copy link

Copilot AI commented Mar 18, 2026

Completes the uts-ffi-binding crate with UniFFI proc-macro bindings, replacing the stub implementation. Exposes the core timestamp codec, attestation types, and opcode execution to foreign languages (Python, Kotlin, Swift).

FFI surface

Derived from analyzing the common API surface across the TS/Python/Go/Rust SDKs:

  • ObjectDetachedTimestamp: opaque handle wrapping VersionedProof<DetachedTimestamp> behind RwLock for thread-safe mutation
    • new(data) constructor (decode from OTS bytes)
    • encode(), header(), attestations(), is_finalized(), display(), purge_pending()
  • EnumAttestation (Bitcoin/Eas/EasTimestamped/Pending/Unknown), DigestOp (Sha1/Ripemd160/Sha256/Keccak256)
  • RecordDigestHeader (kind + digest bytes)
  • ErrorUtsError as #[uniffi(flat_error)] with DecodeError/EncodeError/InvalidOperation
  • Free functionsuts_execute_op, uts_validate_pending_uri, uts_digest_output_size, uts_opcode_name, uts_magic_bytes

Usage

Pure proc-macro flavor — no UDL files, no build.rs:

uniffi::setup_scaffolding!();

#[derive(uniffi::Object)]
pub struct DetachedTimestamp {
    inner: RwLock<VersionedProof<CoreDetachedTimestamp>>,
}

#[uniffi::export]
impl DetachedTimestamp {
    #[uniffi::constructor]
    pub fn new(data: Vec<u8>) -> Result<Arc<Self>, UtsError> { /* ... */ }
    pub fn attestations(&self) -> Result<Vec<Attestation>, UtsError> { /* ... */ }
}

#[uniffi::export]
pub fn uts_execute_op(op_tag: u8, input: Vec<u8>, immediate: Vec<u8>) -> Result<Vec<u8>, UtsError> { /* ... */ }

Changes

  • crates/ffi-binding/Cargo.toml — added thiserror dep, sha2 dev-dep, "lib" crate-type for testing
  • crates/ffi-binding/src/lib.rs — full rewrite with UniFFI proc-macro annotations, type conversions between core and FFI-safe types, 20 unit tests

💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

Copilot AI and others added 2 commits March 18, 2026 09:53
- Replace stub code with complete UniFFI proc-macro based FFI bindings
- Add error types (UtsError with flat_error for clean FFI)
- Add FFI enums: DigestOp, Attestation (with Bitcoin, EAS, Pending, Unknown variants)
- Add FFI record: DigestHeader
- Add DetachedTimestamp object with decode/encode/inspect/purge methods
- Add utility functions: uts_execute_op, uts_validate_pending_uri,
  uts_digest_output_size, uts_opcode_name, uts_magic_bytes
- Add 20 tests covering decode, encode, round-trip, attestation parsing,
  opcode execution, URI validation, and builder integration

Co-authored-by: lightsing <15951701+lightsing@users.noreply.github.com>
…st module

Co-authored-by: lightsing <15951701+lightsing@users.noreply.github.com>
Copilot AI changed the title [WIP] Add uniffi wrapper for uts-core FFI binding Implement UniFFI proc-macro FFI bindings for uts-core Mar 18, 2026
Copilot AI requested a review from lightsing March 18, 2026 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants