Skip to content

Latest commit

 

History

History
120 lines (89 loc) · 3.02 KB

File metadata and controls

120 lines (89 loc) · 3.02 KB

PCZT TypeScript Library

A TypeScript library that enables Bitcoin-derived transparent-only Zcash wallet users to send shielded Orchard outputs using the PCZT (Partially Constructed Zcash Transaction) API.

Overview

This library bridges the gap between transparent (Bitcoin-like) and shielded (private) Zcash ecosystems, allowing users with transparent-only wallets to easily send funds to shielded addresses.

Features

  • ✅ Implements all 8 required PCZT API functions
  • ✅ Supports transparent inputs → shielded Orchard outputs
  • ✅ Integrates with Rust pczt crate via FFI for proof generation
  • ✅ Handles ZIP 321 payment requests
  • ✅ Compatible with existing Bitcoin-derived signing infrastructure
  • ✅ Comprehensive TypeScript type definitions

Installation

npm install @zcash/pczt-typescript

Quick Start

import {
  proposeTransaction,
  proveTransaction,
  getSighash,
  appendSignature,
  finalizeAndExtract,
} from '@zcash/pczt-typescript';

async function sendToShielded() {
  // 1. Prepare transparent inputs
  const inputs = [
    [
      { txid: 'your-txid', vout: 0, sequence: 0xFFFFFFFF },
      { value: 100000000n, scriptPubKey: new Uint8Array([...]) }
    ]
  ];

  // 2. Create payment request
  const request = {
    payments: [{
      address: 'u1recipient...', // Unified address with Orchard
      amount: 95000000n,
      memo: new TextEncoder().encode('Payment')
    }]
  };

  // 3. Build and finalize transaction
  const pczt = await proposeTransaction(inputs, request);
  const proved = await proveTransaction(pczt);
  const sighash = await getSighash(proved, 0);
  const signature = await yourWallet.sign(sighash.hash);
  const signed = await appendSignature(proved, 0, signature);
  const txBytes = await finalizeAndExtract(signed);

  // 4. Broadcast transaction
  return txBytes;
}

API Documentation

See the API Documentation for detailed information about all available functions.

Development

# Install dependencies
npm install

# Build TypeScript and Rust
npm run build

# Run tests
npm test

# Run integration test (requires ~4GB RAM)
./run-all.sh

# Generate documentation
npm run docs

⚠️ System Requirements

  • Memory: Proof generation (proveTransaction) requires approximately 4GB of available RAM to build the Orchard proving key.
  • Disk: ~2GB for build artifacts.
  • Platform: macOS (ARM64/x64), Linux (x64/ARM64), Windows (x64).

Architecture

TypeScript Layer (Transaction Building)
         ↓
    FFI Bridge (napi-rs)
         ↓
Rust Native Module (Proof Generation)
         ↓
   pczt Crate (Orchard Proofs)

License

MIT

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for details.

Resources