|
| 1 | +--- |
| 2 | +title: Ironfish Wasm |
| 3 | +--- |
| 4 | + |
| 5 | +Iron Fish WASM package that compiles native Iron Fish code to WebAssembly with TypeScript bindings. This package allows you to use Iron Fish cryptographic functionality in browser extensions, web applications, or any JavaScript environment. |
| 6 | + |
| 7 | +## Installation |
| 8 | + |
| 9 | +```bash |
| 10 | +npm install @ironfish/ironfish-wasm |
| 11 | +``` |
| 12 | + |
| 13 | +## Features |
| 14 | + |
| 15 | +- Native Iron Fish code compiled to WebAssembly |
| 16 | +- TypeScript bindings for better developer experience |
| 17 | +- Compatible with browser extensions and web applications |
| 18 | +- High-performance cryptographic operations |
| 19 | +- Cross-platform compatibility |
| 20 | + |
| 21 | +## Usage |
| 22 | + |
| 23 | +```typescript |
| 24 | +import { SaplingKey, Note, AssetIdentifier, UnsignedTransaction } from '@ironfish/ironfish-wasm'; |
| 25 | + |
| 26 | +// Generate new keys |
| 27 | +const senderKey = SaplingKey.random(); |
| 28 | +const recipientKey = SaplingKey.random(); |
| 29 | + |
| 30 | +// Create a native asset note (IRON) |
| 31 | +const note = Note.fromParts( |
| 32 | + recipientKey.publicAddress, |
| 33 | + BigInt(100), // Amount |
| 34 | + "Transfer memo", |
| 35 | + AssetIdentifier.native, |
| 36 | + senderKey.publicAddress |
| 37 | +); |
| 38 | + |
| 39 | +// Create an unsigned transaction |
| 40 | +const bytes = new Uint8Array([/* transaction bytes */]); |
| 41 | +const unsignedTx = new UnsignedTransaction(bytes); |
| 42 | + |
| 43 | +// Sign the transaction |
| 44 | +const signedTx = unsignedTx.sign(senderKey); |
| 45 | + |
| 46 | +// Get transaction details |
| 47 | +console.log({ |
| 48 | + fee: signedTx.fee, |
| 49 | + expiration: signedTx.expiration, |
| 50 | + outputs: signedTx.outputs.length, |
| 51 | + spends: signedTx.spends.length |
| 52 | +}); |
| 53 | + |
| 54 | +// Export keys as hex for storage |
| 55 | +const exportedKey = senderKey.toHex(); |
| 56 | + |
| 57 | +// Import key from hex |
| 58 | +const importedKey = SaplingKey.fromHex(exportedKey); |
| 59 | +``` |
| 60 | + |
| 61 | +## Requirements |
| 62 | + |
| 63 | +- Node.js 20.0.0 or higher |
| 64 | +- A JavaScript environment with WebAssembly support |
0 commit comments