@zkfold/smart-wallet-sdk
v0.1.1
Published
Browser-safe Rust/WASM SDK for zkFold Smart Wallet v2.
Downloads
70
Readme
smart-wallet-sdk
Browser-safe Rust/WASM SDK for Smart Wallet v2.
The SDK contains the client-side protocol helpers needed by applications that integrate Smart Wallet:
- API request and response data types.
- Gmail address canonicalization and email hash helpers.
- Google JWT parsing for the proof flow.
- Sigma proof generation for escrow claims.
- Opaque-byte 2-of-3 key-share split and combine helpers.
The SDK does not generate wallet keys, derive blockchain addresses, validate public keys, integrate with browser wallets, store custody data, submit transactions, query RPC providers, or send API requests.
Rust
let email = smart_wallet_sdk::email::canonicalize_email(" [email protected] ")?;
let shares = smart_wallet_sdk::key_share::split_secret(b"ordinary wallet secret")?;
let secret = smart_wallet_sdk::key_share::combine_shares(&shares[0], &shares[1])?;WASM
Install the published browser package with:
npm install @zkfold/smart-wallet-sdkUse the generated module from browser code:
import init, { canonicalize_email, prove_claim } from "@zkfold/smart-wallet-sdk";
await init();
const email = canonicalize_email(" [email protected] ");Build the browser package with:
wasm-pack build --scope zkfold --target web --out-dir pkg --out-name smart_wallet_sdk --features wasmThe WASM facade exports JSON-oriented functions for browser callers:
canonicalize_email(email)email_hash(email)key_share_email_hash(email)split_secret(secretBase64url)combine_secret_shares(firstShare, secondShare)parse_google_jwt(compactJwt)prove_claim(inputJson)prove_key_share(inputJson)
Browser Function Contracts
canonicalize_email(email) trims ASCII whitespace, lowercases ASCII
characters, rejects unsupported characters, and returns the canonical Gmail
address string.
email_hash(email) returns the 0x-prefixed Keccak-256 hash of the supplied
email string. Call canonicalize_email first for user-entered send and balance
inputs.
key_share_email_hash(email) canonicalizes the email and returns the
0x-prefixed SHA-256 hash used to key optional key-share storage.
parse_google_jwt(compactJwt) accepts a compact Google ID token and returns a
JSON string with headerB64, payloadB64, kid, email, emailHash, and the
public JWT offset data needed by the proof flow. The JWT signature remains local
to the browser.
prove_claim(inputJson) accepts:
{
"compactJwt": "header.payload.signature",
"googleKey": {
"kid": "google-key-id",
"modulus": "0x...",
"exponent": 65537
},
"chain": {
"type": "evm",
"chainId": 11155111,
"escrow": "0x1111111111111111111111111111111111111111"
},
"refs": [
"0xcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
],
"to": "0x3333333333333333333333333333333333333333",
"relayer": "0x2222222222222222222222222222222222222222"
}For Cardano, use:
{
"type": "cardano",
"network": "preprod"
}with Cardano refs in txHash#index form and Cardano to and relayer
addresses. The function returns the JSON request body for /v1/claim.
prove_key_share(inputJson) accepts:
{
"compactJwt": "header.payload.signature",
"googleKey": {
"kid": "google-key-id",
"modulus": "0x...",
"exponent": 65537
},
"operation": "store",
"keyShareEmailHash": "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"clientId": "partner-app",
"challenge": "base64url-32-byte-challenge",
"share": "serialized-share-for-store"
}For retrieve proofs, set operation to retrieve and omit share. The
function returns the proof object used by /v1/key-share or
/v1/key-share/retrieve.
