webycash SDK
Native webcash protocol integration for every major platform. One Rust core, platform bindings on top.
Overview
The webycash SDK provides a complete interface to the webcash protocol: wallet create / insert / pay / merge / recover, snapshot backup & restore, password encryption, master secret management, output listing, HD key derivation, and server communication.
The core is written in Rust (webylib) for safety and performance. Native FFI bindings expose the same API through idiomatic wrappers for 9 target platforms. A WebAssembly build enables browser and universal JavaScript usage alongside the native FFI.
Prerequisites
Python
ctypes binding; pip install webycash-sdk.
Install Expand
pip install webycash-sdkAmount helpers (parse / format) Expand
from webycash_sdk import amount_parse, amount_format
wats = amount_parse("1.5") # 150_000_000
print(amount_format(wats)) # "1.5"Open or create wallet Expand
from webycash_sdk import Wallet
# Open or create an HD wallet (SQLite storage)
with Wallet("wallet.db") as w:
print("Balance:", w.balance())Deterministic wallet (from seed) Expand
from webycash_sdk import Wallet
# Create a deterministic wallet from a known 32-byte seed
seed = bytes.fromhex("ab" * 32)
with Wallet("wallet.db", seed=seed) as w:
print("Master secret:", w.master_secret)Balance & stats Expand
import json
from webycash_sdk import Wallet
with Wallet("wallet.db") as w:
print("Balance:", w.balance())
stats = json.loads(w.stats())
print("Unspent outputs:", stats["unspent_webcash"])
print("Total balance:", stats["total_balance"])List unspent outputs Expand
import json
from webycash_sdk import Wallet
with Wallet("wallet.db") as w:
outputs = json.loads(w.list_webcash())
print(f"{len(outputs)} unspent outputs")
for wc in outputs:
print(f" {wc}")Master secret (backup key) Expand
from webycash_sdk import Wallet
with Wallet("wallet.db") as w:
# 64-char hex — this is the recovery key. Back it up safely.
secret = w.master_secret
print(f"Master secret: {secret[:16]}…")Insert (receive payment) Expand
from webycash_sdk import Wallet
# Receive a payment: insert the bearer secret string
with Wallet("wallet.db") as w:
w.insert("e1.00000000:secret:abcdef0123456789…")
print("New balance:", w.balance())Pay (send to recipient) Expand
from webycash_sdk import Wallet
# Send a payment: creates a bearer string for the recipient
with Wallet("wallet.db") as w:
payment = w.pay("0.5", "coffee payment")
print("Send this to recipient:", payment)Check (verify with server) Expand
from webycash_sdk import Wallet
# Verify all outputs are still valid on the server
with Wallet("wallet.db") as w:
w.check()
print("All outputs verified")Merge (consolidate outputs) Expand
from webycash_sdk import Wallet
# Consolidate many small outputs into fewer large ones
with Wallet("wallet.db") as w:
result = w.merge(20)
print(result)Recover (HD scan) Expand
from webycash_sdk import Wallet
# Recover outputs from a master secret hex (from backup)
with Wallet("new_wallet.db") as w:
result = w.recover("aabb…64_hex_chars…", gap_limit=20)
print(result)
# Or recover using the wallet's own stored master secret
with Wallet("wallet.db") as w:
result = w.recover_from_wallet(gap_limit=20)
print(result)Snapshot backup & restore Expand
import json
from webycash_sdk import Wallet
with Wallet("wallet.db") as w:
# Export full wallet state as JSON backup
backup = w.export_snapshot()
print(f"Backup: {len(backup)} bytes")
# Restore into another wallet
with Wallet("restored.db") as w2:
w2.import_snapshot(backup)
print("Restored balance:", w2.balance())Encrypt / decrypt wallet Expand
from webycash_sdk import Wallet
with Wallet("wallet.db") as w:
# Encrypt wallet data with a password (Argon2id + AES-256-GCM)
encrypted = w.encrypt_with_password("strongPassword123")
print(f"Encrypted blob: {len(encrypted)} chars")
# Decrypt and restore
w.decrypt_with_password(encrypted, "strongPassword123")
print("Balance after decrypt:", w.balance())
# Legacy: encrypt the SQLite database seed
w.encrypt_seed("strong-password")TypeScript / Node.js
Async API with FFI (native) + WASM (browser) backends. npm install webycash-sdk.
Install Expand
npm install webycash-sdkAmount helpers (parse / format) Expand
import { amountParse, amountFormat } from "webycash-sdk";
const wats = await amountParse("1.5"); // 150_000_000n (BigInt)
console.log(await amountFormat(wats)); // "1.5"Open or create wallet Expand
import { Wallet } from "webycash-sdk";
// Async factory — auto-detects FFI (Node.js) or WASM (browser)
const w = await Wallet.open("wallet.db");
try {
console.log(await w.balance());
} finally {
w.close();
}Deterministic wallet (from seed) Expand
import { Wallet } from "webycash-sdk";
// Deterministic wallet from a known seed
const seed = new Uint8Array(32).fill(0xab);
const w = await Wallet.open("wallet.db", { seed });
console.log(await w.masterSecret());
w.close();WASM backend (browser / universal) Expand
import { Wallet } from "webycash-sdk";
// Force WASM backend (works in browser + Node.js)
const w = await Wallet.open("wallet", { backend: "wasm" });
console.log(await w.balance());
w.close();Balance & stats Expand
const w = await Wallet.open("wallet.db");
console.log(await w.balance());
const stats = await w.stats();
console.log("Unspent:", stats.unspentWebcash);
console.log("Total:", stats.totalBalance);
w.close();List unspent outputs Expand
const w = await Wallet.open("wallet.db");
const outputs = await w.listWebcash();
console.log(`${outputs.length} unspent outputs`);
for (const wc of outputs) console.log(` ${wc}`);
w.close();Master secret (backup key) Expand
const w = await Wallet.open("wallet.db");
// 64-char hex — back this up for recovery
const secret = await w.masterSecret();
console.log(`Master secret: ${secret.slice(0, 16)}…`);
w.close();Insert (receive payment) Expand
const w = await Wallet.open("wallet.db");
await w.insert("e1.00000000:secret:abcdef0123456789…");
console.log("Balance:", await w.balance());
w.close();Pay (send to recipient) Expand
const w = await Wallet.open("wallet.db");
const payment = await w.pay("0.5", "coffee");
console.log("Send to recipient:", payment);
w.close();Check (verify with server) Expand
const w = await Wallet.open("wallet.db");
const result = await w.check();
console.log(`Valid: ${result.validCount}, Spent: ${result.spentCount}`);
w.close();Merge (consolidate outputs) Expand
const w = await Wallet.open("wallet.db");
const msg = await w.merge(20);
console.log(msg);
w.close();Recover (HD scan) Expand
const w = await Wallet.open("wallet.db");
// Recover using the wallet's own master secret
const result = await w.recoverFromWallet(20);
console.log(`Recovered: ${result.recoveredCount}`);
w.close();Snapshot backup & restore Expand
const w = await Wallet.open("wallet.db");
const backup = await w.exportSnapshot();
const w2 = await Wallet.open("restored.db");
await w2.importSnapshot(backup);
console.log("Restored:", await w2.balance());
w.close(); w2.close();Encrypt / decrypt wallet Expand
const w = await Wallet.open("wallet.db");
const encrypted = await w.encryptWithPassword("strongPassword123");
await w.decryptWithPassword(encrypted, "strongPassword123");
console.log("Balance:", await w.balance());
w.close();Standalone crypto utilities Expand
import { deriveSecret, generateMasterSecret, sha256Hex, secretToPublic,
parseWebcash, formatWebcash } from "webycash-sdk";
const secret = await generateMasterSecret(); // 64-char hex
const derived = await deriveSecret(secret, 0, 0); // HD derivation
const hash = await sha256Hex("data");
const pub = await secretToPublic(derived);
const wc = await formatWebcash(derived, 100000000n); // "e1:secret:…"
const parsed = await parseWebcash(wc); // { secret, amountWats, … }Rust (webylib)
Use webylib directly for the full async API. FFI crate is webycash-sdk.
Install Expand
cargo add webylib
# Tokio async runtime required — add tokio with "macros", "rt-multi-thread"Amount helpers (parse / format) Expand
use webylib::Amount;
use std::str::FromStr;
let a = Amount::from_str("1.5")?;
assert_eq!(a.wats, 150_000_000);
println!("{}", a); // "1.5"Open or create wallet Expand
use webylib::Wallet;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let w = Wallet::open("wallet.db").await?;
println!("{}", w.balance().await?);
w.close().await?;
Ok(())
}Balance & stats Expand
let w = Wallet::open("wallet.db").await?;
println!("Balance: {}", w.balance().await?);
let s = w.stats().await?;
println!("Unspent: {}, Total: {}", s.unspent_webcash, s.total_balance);List unspent outputs Expand
let w = Wallet::open("wallet.db").await?;
let outputs = w.list_webcash().await?;
for wc in &outputs {
println!(" {}", wc);
}Master secret (backup key) Expand
let w = Wallet::open("wallet.db").await?;
let secret = w.master_secret_hex()?;
println!("Master secret: {}…", &secret[..16]);Insert (receive payment) Expand
use webylib::{SecretWebcash, Wallet};
let w = Wallet::open("wallet.db").await?;
let wc = SecretWebcash::parse("e1.00000000:secret:…")?;
w.insert(wc).await?;
println!("Balance: {}", w.balance().await?);Pay (send to recipient) Expand
use webylib::{Amount, Wallet};
use std::str::FromStr;
let w = Wallet::open("wallet.db").await?;
let payment = w.pay(Amount::from_str("0.5")?, "coffee").await?;
println!("Send to recipient: {}", payment);Check (verify with server) Expand
let w = Wallet::open("wallet.db").await?;
let r = w.check().await?;
println!("Valid: {}, Spent: {}", r.valid_count, r.spent_count);Merge (consolidate outputs) Expand
let w = Wallet::open("wallet.db").await?;
println!("{}", w.merge(20).await?);Recover (HD scan) Expand
let w = Wallet::open("wallet.db").await?;
// From external secret
let r = w.recover("aabb…64_hex…", 20).await?;
println!("Recovered: {}", r.recovered_count);
// From wallet's own stored secret
let r = w.recover_from_wallet(20).await?;
println!("Recovered: {}", r.recovered_count);Snapshot backup & restore Expand
let w = Wallet::open("wallet.db").await?;
let snap = w.export_snapshot()?;
let json = serde_json::to_string(&snap)?;
// Restore
let w2 = Wallet::open("restored.db").await?;
let snap2: WalletSnapshot = serde_json::from_str(&json)?;
w2.import_snapshot(&snap2)?;Encrypt / decrypt wallet Expand
let w = Wallet::open("wallet.db").await?;
// Full wallet encryption (Argon2id + AES-256-GCM)
let encrypted = w.encrypt_with_password("strong").await?;
w.decrypt_with_password(&encrypted, "strong").await?;
// SQLite database encryption
w.encrypt_database_with_password("strong").await?;Swift
SwiftPM target WebycashSDK; iOS 15+, macOS 13+, watchOS 8+, tvOS 15+, visionOS 1+.
Install Expand
// Package.swift
.package(url: "https://github.com/webycash/webycash-sdk", from: "0.2.16")Open or create wallet Expand
import WebycashSDK
let w = try Wallet(path: "wallet.db")
defer { w.close() }
print(try w.balance())Balance & stats Expand
print("Balance:", try w.balance())
print("Stats:", try w.stats())List unspent outputs Expand
let outputs = try w.listWebcash()
print("Outputs:", outputs)Master secret (backup key) Expand
let secret = try w.masterSecret()
print("Master secret: \(secret.prefix(16))…")Insert (receive payment) Expand
try w.insert("e1.00000000:secret:…")Pay (send to recipient) Expand
let payment = try w.pay(amount: "0.5", memo: "coffee")
print("Send to recipient:", payment)Check (verify with server) Expand
try w.check()Merge (consolidate outputs) Expand
print(try w.merge(maxOutputs: 20))Recover (HD scan) Expand
// From external master secret hex
print(try w.recover(masterSecretHex: "aabb…64_hex…", gapLimit: 20))
// From wallet's own stored secret
print(try w.recoverFromWallet(gapLimit: 20))Snapshot backup & restore Expand
let backup = try w.exportSnapshot()
// Restore into another wallet
let w2 = try Wallet(path: "restored.db")
try w2.importSnapshot(backup)
print("Restored:", try w2.balance())Encrypt / decrypt wallet Expand
let encrypted = try w.encryptWithPassword("strongPassword123")
try w.decryptWithPassword(encryptedJSON: encrypted, password: "strongPassword123")
print("Balance:", try w.balance())Kotlin / JVM
JNA; Gradle dependency cash.weby:webycash-sdk.
Install Expand
implementation("cash.weby:webycash-sdk:0.2.16")Open or create wallet Expand
import cash.weby.sdk.Wallet
Wallet.open("wallet.db").use { w ->
println(w.balance())
}Balance & stats Expand
Wallet.open("wallet.db").use { w ->
println("Balance: " + w.balance())
println("Stats: " + w.stats())
}List unspent outputs Expand
Wallet.open("wallet.db").use { w ->
println("Outputs: " + w.listWebcash())
}Master secret (backup key) Expand
Wallet.open("wallet.db").use { w ->
val secret = w.masterSecret()
println("Master secret: ${secret.take(16)}…")
}Insert (receive payment) Expand
w.insert("e1.00000000:secret:…")Pay (send to recipient) Expand
val payment = w.pay("0.5", "coffee")
println("Send to recipient: $payment")Check (verify with server) Expand
w.check()Merge (consolidate outputs) Expand
println(w.merge(20))Recover (HD scan) Expand
// From external master secret
println(w.recover("aabb…64_hex…", 20))
// From wallet's own stored secret
println(w.recoverFromWallet(20))Snapshot backup & restore Expand
val backup = w.exportSnapshot()
Wallet.open("restored.db").use { w2 ->
w2.importSnapshot(backup)
println("Restored: " + w2.balance())
}Encrypt / decrypt wallet Expand
val encrypted = w.encryptWithPassword("strongPassword123")
w.decryptWithPassword(encrypted, "strongPassword123")
println("Balance: " + w.balance())Java
Same JAR as Kotlin; JNA loads webycash_sdk.
Install Expand
<!-- Maven -->
<dependency>
<groupId>cash.weby</groupId>
<artifactId>webycash-sdk</artifactId>
<version>0.2.16</version>
</dependency>Open or create wallet Expand
import cash.weby.sdk.WebycashSDK;
try (var w = new WebycashSDK.Wallet("wallet.db")) {
System.out.println(w.balance());
}Balance & stats Expand
System.out.println("Balance: " + w.balance());
System.out.println("Stats: " + w.stats());List unspent outputs Expand
System.out.println("Outputs: " + w.listWebcash());Master secret (backup key) Expand
String secret = w.masterSecret();
System.out.println("Master secret: " + secret.substring(0, 16) + "…");Insert (receive payment) Expand
w.insert("e1.00000000:secret:…");Pay (send to recipient) Expand
String payment = w.pay("0.5", "coffee");
System.out.println("Send to recipient: " + payment);Check (verify with server) Expand
w.check();Merge (consolidate outputs) Expand
System.out.println(w.merge(20));Recover (HD scan) Expand
// From external master secret
System.out.println(w.recover("aabb…64_hex…", 20));
// From wallet's own stored secret
System.out.println(w.recoverFromWallet(20));Snapshot backup & restore Expand
String backup = w.exportSnapshot();
try (var w2 = new WebycashSDK.Wallet("restored.db")) {
w2.importSnapshot(backup);
System.out.println("Restored: " + w2.balance());
}Encrypt / decrypt wallet Expand
String encrypted = w.encryptWithPassword("strongPassword123");
w.decryptWithPassword(encrypted, "strongPassword123");
System.out.println("Balance: " + w.balance());Go
cgo; set CGO_LDFLAGS to find libwebycash_sdk.
Install Expand
go get github.com/webycash/webycash-sdk/goOpen or create wallet Expand
package main
import (
"fmt"
webcash "github.com/webycash/webycash-sdk/go"
)
func main() {
w, _ := webcash.Open("wallet.db")
defer w.Close()
b, _ := w.Balance()
fmt.Println(b)
}Balance & stats Expand
b, _ := w.Balance()
fmt.Println("Balance:", b)
s, _ := w.Stats()
fmt.Println("Stats:", s)List unspent outputs Expand
outputs, _ := w.ListWebcash()
fmt.Println("Outputs:", outputs)Master secret (backup key) Expand
secret, _ := w.MasterSecret()
fmt.Printf("Master secret: %s…\n", secret[:16])Insert (receive payment) Expand
_ = w.Insert("e1.00000000:secret:…")Pay (send to recipient) Expand
payment, _ := w.Pay("0.5", "coffee")
fmt.Println("Send to recipient:", payment)Check (verify with server) Expand
_ = w.Check()Merge (consolidate outputs) Expand
out, _ := w.Merge(20)
fmt.Println(out)Recover (HD scan) Expand
// From external master secret
out, _ := w.Recover("aabb…64_hex…", 20)
fmt.Println(out)
// From wallet's own stored secret
out, _ = w.RecoverFromWallet(20)
fmt.Println(out)Snapshot backup & restore Expand
snap, _ := w.ExportSnapshot()
w2, _ := webcash.Open("restored.db")
_ = w2.ImportSnapshot(snap)
b, _ := w2.Balance()
fmt.Println("Restored:", b)
w2.Close()Encrypt / decrypt wallet Expand
encrypted, _ := w.EncryptWithPassword("strongPassword123")
_ = w.DecryptWithPassword(encrypted, "strongPassword123")
b, _ := w.Balance()
fmt.Println("Balance:", b)C# / .NET
NuGet Webycash.SDK; .NET 8+.
Install Expand
dotnet add package Webycash.SDKOpen or create wallet Expand
using WebycashSDK;
using var w = new Wallet("wallet.db");
Console.WriteLine(w.Balance());Balance & stats Expand
Console.WriteLine("Balance: " + w.Balance());
Console.WriteLine("Stats: " + w.Stats());List unspent outputs Expand
Console.WriteLine("Outputs: " + w.ListWebcash());Master secret (backup key) Expand
var secret = w.MasterSecret();
Console.WriteLine($"Master secret: {secret[..16]}…");Insert (receive payment) Expand
w.Insert("e1.00000000:secret:…");Pay (send to recipient) Expand
var payment = w.Pay("0.5", "coffee");
Console.WriteLine($"Send to recipient: {payment}");Check (verify with server) Expand
w.Check();Merge (consolidate outputs) Expand
Console.WriteLine(w.Merge(20));Recover (HD scan) Expand
// From external master secret
Console.WriteLine(w.Recover("aabb…64_hex…", 20));
// From wallet's own stored secret
Console.WriteLine(w.RecoverFromWallet(20));Snapshot backup & restore Expand
var backup = w.ExportSnapshot();
using var w2 = new Wallet("restored.db");
w2.ImportSnapshot(backup);
Console.WriteLine($"Restored: {w2.Balance()}");Encrypt / decrypt wallet Expand
var encrypted = w.EncryptWithPassword("strongPassword123");
w.DecryptWithPassword(encrypted, "strongPassword123");
Console.WriteLine($"Balance: {w.Balance()}");C++
Header webycash_sdk.hpp; C++17; link webycash_sdk.
Install Expand
# Link libwebycash_sdk + include webycash.h / webycash_sdk.hpp
# See webycash-sdk/examples/cppOpen or create wallet Expand
#include <webycash_sdk.hpp>
webcash::Wallet w("wallet.db");
std::cout << w.balance() << "\n";Balance & stats Expand
std::cout << "Balance: " << w.balance() << "\n";
std::cout << "Stats: " << w.stats() << "\n";List unspent outputs Expand
std::cout << "Outputs: " << w.list_webcash() << "\n";Master secret (backup key) Expand
auto secret = w.master_secret();
std::cout << "Master secret: " << secret.substr(0, 16) << "…\n";Insert (receive payment) Expand
w.insert("e1.00000000:secret:…");Pay (send to recipient) Expand
auto payment = w.pay("0.5", "coffee");
std::cout << "Send to recipient: " << payment << "\n";Check (verify with server) Expand
w.check_wallet();Merge (consolidate outputs) Expand
std::cout << w.merge(20) << "\n";Recover (HD scan) Expand
// From external master secret
std::cout << w.recover("aabb…64_hex…", 20) << "\n";
// From wallet's own stored secret
std::cout << w.recover_from_wallet(20) << "\n";Snapshot backup & restore Expand
auto backup = w.export_snapshot();
webcash::Wallet w2("restored.db");
w2.import_snapshot(backup);
std::cout << "Restored: " << w2.balance() << "\n";Encrypt / decrypt wallet Expand
auto encrypted = w.encrypt_with_password("strongPassword123");
w.decrypt_with_password(encrypted, "strongPassword123");
std::cout << "Balance: " << w.balance() << "\n";Core capabilities
Payments
Insert (receive) and pay (send) bearer webcash strings. Full HD key derivation with 4-chain architecture (receive, pay, change, mining).
Backup & recovery
Export / import JSON snapshots. Recover wallet from master secret hex. Password encryption with Argon2id + AES-256-GCM.
Server protocol
Health check, replace (split / merge), mining reports, and target difficulty via the webcash.org server API.
Wallet storage
SQLite with WAL mode (native), in-memory MemStore (WASM), or JSON format. Secrets never leave the client.
WebAssembly
Full WASM build for browser wallets, Node.js fallback, and universal JavaScript. Auto-detects best backend.
9 languages
Python, TypeScript, Rust, Swift, Kotlin, Java, Go, C#, C++. Same API surface, idiomatic wrappers, comprehensive tests.