spb/os-vault Public
Self-custody, multi-chain crypto wallet for macOS. One recovery phrase, six chain families, zero API keys — nothing leaves your Mac.
Swift 96%
Shell 3.4%
Makefile 0.6%
1#!/bin/bash2#3# vendor-walletcore.sh4# OS Vault5#6# Author: Simon-Pierre Boucher7# Mail: contact@spboucher.ai8#9# Vendors Trust wallet-core as a local SwiftPM package with native macOS10# support — the signing engine for the non-EVM expansion (Tron, TON, XRPL,11# Solana fallback…). Upstream's SPM package is iOS-only, but the official12# CocoaPods tarball ships a macos-arm64_x86_64 slice; this script repackages13# it, fully automated (proven working on this machine — see14# docs/RESEARCH-MULTICHAIN.md §wallet-core).15#16# Usage: scripts/vendor-walletcore.sh [version] (default 4.7.2)1718set -euo pipefail19cd "$(dirname "$0")/.."2021VERSION="${1:-4.7.2}"22URL="https://github.com/trustwallet/wallet-core/releases/download/${VERSION}/TrustWalletCore-${VERSION}.tar.xz"23DEST="vendor/WalletCoreSPM"24WORK="$(mktemp -d)"25trap 'rm -rf "$WORK"' EXIT2627echo "=== Downloading official wallet-core ${VERSION} tarball ==="28curl -fL --retry 3 -o "$WORK/twc.tar.xz" "$URL"29tar -xJf "$WORK/twc.tar.xz" -C "$WORK"30# The tarball extracts flat: include/ Sources/ WalletCoreCommon.xcframework31SRC="$WORK"32[ -d "$SRC/include/TrustWalletCore" ] && [ -d "$SRC/Sources" ] && [ -d "$SRC/WalletCoreCommon.xcframework" ] ||33 { echo "ERROR: tarball layout unexpected" >&2; exit 1; }3435echo "=== Assembling local SwiftPM package in $DEST ==="36rm -rf "$DEST"37mkdir -p "$DEST/Sources/WalletCoreC/include" "$DEST/Sources/WalletCore"3839# C target: public headers + the Security.framework RNG shim (SECURITY-CRITICAL:40# trezor-crypto takes entropy from these consumer-provided symbols).41cp -R "$SRC/include/TrustWalletCore" "$DEST/Sources/WalletCoreC/include/"42find "$SRC" -name 'SecRandom.m' -exec cp {} "$DEST/Sources/WalletCoreC/" \;43[ -f "$DEST/Sources/WalletCoreC/SecRandom.m" ] || { echo "ERROR: SecRandom.m missing" >&2; exit 1; }4445# Swift wrappers: rename the protobuf module, inject imports SPM needs.46cp -R "$SRC/Sources/." "$DEST/Sources/WalletCore/"47# Swift target must be Swift-only (SecRandom.m lives in WalletCoreC).48find "$DEST/Sources/WalletCore" \( -name '*.m' -o -name '*.h' \) -delete49# Global rename: the generated code also uses the module as a type qualifier.50find "$DEST/Sources/WalletCore" -name '*.swift' -exec sed -i '' \51 -e 's/WalletCoreSwiftProtobuf/SwiftProtobuf/g' {} \;52find "$DEST/Sources/WalletCore" -name '*.swift' -exec sed -i '' \53 -e '1s/^/import WalletCoreC\nimport Foundation\n/' {} \;5455# Native binary (contains the macos-arm64_x86_64 slice).56cp -R "$SRC/WalletCoreCommon.xcframework" "$DEST/"57plutil -p "$DEST/WalletCoreCommon.xcframework/Info.plist" | grep -q macos ||58 { echo "ERROR: no macOS slice in xcframework" >&2; exit 1; }5960# De-duplicate the Rust runtime: both wallet-core and bdkFFI (Bitcoin Dev Kit)61# statically embed Rust's std, and the linker rejects the duplicate global62# `_rust_eh_personality`. Demote wallet-core's copy to private in the single63# archive member that defines it (surgical — merging the whole archive breaks64# unused-member semantics).65echo "=== Demoting duplicate _rust_eh_personality in the macOS slice ==="66BIN="$DEST/WalletCoreCommon.xcframework/macos-arm64_x86_64/WalletCoreCommon.framework/Versions/A/WalletCoreCommon"67FIX="$WORK/rustfix"68mkdir -p "$FIX"69for arch in arm64 x86_64; do70 mkdir -p "$FIX/$arch"71 ( cd "$FIX/$arch"72 lipo "$BIN" -thin "$arch" -output slice.a73 MEMBER=$(nm -gU -A slice.a 2>/dev/null | grep " T _rust_eh_personality" | head -1 | cut -d: -f2)74 [ -n "$MEMBER" ] || { echo "no duplicate in $arch (upstream fixed?) — skipping"; exit 0; }75 ar -x slice.a "$MEMBER"76 ld -r -arch "$arch" -platform_version macos 13.0 15.5 "$MEMBER" -o patched.o \77 -unexported_symbol _rust_eh_personality 2>/dev/null78 mv patched.o "$MEMBER"79 ar -r -s slice.a "$MEMBER" 2>/dev/null )80done81lipo -create "$FIX/arm64/slice.a" "$FIX/x86_64/slice.a" -output "$BIN"8283cat > "$DEST/Package.swift" <<'EOF'84// swift-tools-version:5.1085// Auto-generated by scripts/vendor-walletcore.sh — do not edit by hand.86// The prebuilt static framework is exposed as a local binaryTarget (no87// unsafeFlags — those would make the package unusable as a dependency).88import PackageDescription8990let package = Package(91 name: "WalletCoreSPM",92 platforms: [.macOS(.v13)],93 products: [94 .library(name: "WalletCore", targets: ["WalletCore"])95 ],96 dependencies: [97 .package(url: "https://github.com/apple/swift-protobuf.git", from: "1.29.0")98 ],99 targets: [100 .binaryTarget(101 name: "WalletCoreBinary",102 path: "WalletCoreCommon.xcframework"103 ),104 .target(105 name: "WalletCoreC",106 dependencies: ["WalletCoreBinary"],107 path: "Sources/WalletCoreC",108 publicHeadersPath: "include"109 ),110 .target(111 name: "WalletCore",112 dependencies: [113 "WalletCoreC",114 .product(name: "SwiftProtobuf", package: "swift-protobuf")115 ],116 path: "Sources/WalletCore",117 linkerSettings: [118 .linkedLibrary("c++"),119 .linkedFramework("Security")120 ]121 )122 ]123)124EOF125126echo "=== Done ==="127echo "Vendored wallet-core ${VERSION} → $DEST"128echo "Add to Package.swift deps: .package(path: \"vendor/WalletCoreSPM\") and"129echo "product .product(name: \"WalletCore\", package: \"WalletCoreSPM\")."