#!/bin/bash
# Build script for synor-crypto-wasm WASM module
# Outputs to pkg/ directory for use in web wallet

set -e

echo "Building synor-crypto-wasm for web..."

# Ensure wasm-pack is available
if ! command -v wasm-pack &> /dev/null; then
    echo "Installing wasm-pack..."
    curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
fi

# Build for web target (bundler - ES modules for Vite)
wasm-pack build \
    --target bundler \
    --out-dir pkg \
    --out-name synor_crypto \
    --release

# Also build for web target (direct browser usage without bundler)
wasm-pack build \
    --target web \
    --out-dir pkg-web \
    --out-name synor_crypto \
    --release

echo "WASM build complete!"
echo "  - pkg/        : For bundlers (Vite, Webpack)"
echo "  - pkg-web/    : For direct browser import"
echo ""
echo "To use in web wallet:"
echo "  1. Copy pkg/ to apps/web/src/wasm/"
echo "  2. Import: import init, { DilithiumSigningKey } from './wasm/synor_crypto'"
