|
| 1 | +# @bitgo/sdk-coin-kaspa |
| 2 | + |
| 3 | +BitGo's SDK module for the **Kaspa (KASPA)** blockchain. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +Kaspa is a proof-of-work blockchain based on the GHOSTDAG protocol (a generalization of Nakamoto consensus), enabling high block rates. This module implements Kaspa's UTXO model with **secp256k1 Schnorr signatures** (BIP-143-like sighash) and the custom **kaspa/kaspatest** bech32 address format. |
| 8 | + |
| 9 | +Supported coin identifiers: |
| 10 | + |
| 11 | +- `kaspa` — Kaspa mainnet |
| 12 | +- `tkaspa` — Kaspa testnet |
| 13 | + |
| 14 | +## Features |
| 15 | + |
| 16 | +- Key pair generation (secp256k1) |
| 17 | +- Address derivation (kaspa bech32 P2PK Schnorr) |
| 18 | +- UTXO transaction building |
| 19 | +- Schnorr signing and verification (Blake2b-256 sighash) |
| 20 | +- TSS/MPC support (ECDSA algorithm) |
| 21 | +- Full serialization round-trip (hex/JSON) |
| 22 | + |
| 23 | +## Installation |
| 24 | + |
| 25 | +```bash |
| 26 | +yarn add @bitgo/sdk-coin-kaspa |
| 27 | +``` |
| 28 | + |
| 29 | +## Usage |
| 30 | + |
| 31 | +### Register with BitGo SDK |
| 32 | + |
| 33 | +```typescript |
| 34 | +import { register } from '@bitgo/sdk-coin-kaspa'; |
| 35 | +register(bitgo); |
| 36 | +``` |
| 37 | + |
| 38 | +### Key Pair |
| 39 | + |
| 40 | +```typescript |
| 41 | +import { KeyPair } from '@bitgo/sdk-coin-kaspa'; |
| 42 | + |
| 43 | +// Generate a random key pair |
| 44 | +const kp = new KeyPair(); |
| 45 | +const { pub, prv } = kp.getKeys(); |
| 46 | + |
| 47 | +// Derive address |
| 48 | +const mainnetAddress = kp.getAddress('mainnet'); |
| 49 | +const testnetAddress = kp.getAddress('testnet'); |
| 50 | +``` |
| 51 | + |
| 52 | +### Build and Sign a Transaction |
| 53 | + |
| 54 | +```typescript |
| 55 | +import { TransactionBuilderFactory } from '@bitgo/sdk-coin-kaspa'; |
| 56 | +import { coins } from '@bitgo/statics'; |
| 57 | + |
| 58 | +const factory = new TransactionBuilderFactory(coins.get('kaspa')); |
| 59 | +const builder = factory.getBuilder(); |
| 60 | + |
| 61 | +builder |
| 62 | + .addInput({ |
| 63 | + transactionId: '<prev-tx-id>', |
| 64 | + transactionIndex: 0, |
| 65 | + amount: '100000000', // 1 KASPA in sompi |
| 66 | + scriptPublicKey: '<spk>', |
| 67 | + sequence: '0', |
| 68 | + sigOpCount: 1, |
| 69 | + }) |
| 70 | + .to('<recipient-kaspa-address>', '99998000') |
| 71 | + .fee('2000'); |
| 72 | + |
| 73 | +const tx = await builder.build(); |
| 74 | +tx.sign(Buffer.from(privateKeyHex, 'hex')); |
| 75 | + |
| 76 | +const broadcastPayload = tx.toBroadcastFormat(); // JSON string for RPC |
| 77 | +``` |
| 78 | + |
| 79 | +## Module Structure |
| 80 | + |
| 81 | +``` |
| 82 | +src/ |
| 83 | +├── kaspa.ts # Kaspa mainnet coin class |
| 84 | +├── tkaspa.ts # Kaspa testnet coin class |
| 85 | +├── register.ts # SDK registration |
| 86 | +├── index.ts |
| 87 | +└── lib/ |
| 88 | + ├── constants.ts # Chain constants (prefixes, decimals, fees) |
| 89 | + ├── iface.ts # TypeScript interfaces |
| 90 | + ├── keyPair.ts # secp256k1 key pair |
| 91 | + ├── sighash.ts # Blake2b-256 Schnorr sighash |
| 92 | + ├── transaction.ts # Transaction class (sign/verify/explain) |
| 93 | + ├── transactionBuilder.ts # UTXO transaction builder |
| 94 | + ├── transactionBuilderFactory.ts |
| 95 | + ├── utils.ts # Address validation and encoding |
| 96 | + └── index.ts |
| 97 | +test/ |
| 98 | +├── fixtures/ |
| 99 | +│ ├── kaspa.fixtures.ts # Deterministic test vectors |
| 100 | +│ └── kaspaFixtures.ts # Synthetic test fixtures |
| 101 | +└── unit/ |
| 102 | + ├── coin.test.ts |
| 103 | + ├── keyPair.test.ts |
| 104 | + ├── transaction.test.ts |
| 105 | + ├── transactionBuilder.test.ts |
| 106 | + ├── transactionFlow.test.ts |
| 107 | + └── utils.test.ts |
| 108 | +``` |
| 109 | + |
| 110 | +## Address Format |
| 111 | + |
| 112 | +Kaspa uses a custom cashaddr-like bech32 encoding: |
| 113 | + |
| 114 | +- Mainnet: `kaspa:<bech32-encoded-data>` |
| 115 | +- Testnet: `kaspatest:<bech32-encoded-data>` |
| 116 | +- Version byte `0` = Schnorr P2PK (x-only secp256k1 pubkey) |
| 117 | + |
| 118 | +## Signing |
| 119 | + |
| 120 | +Kaspa uses **Schnorr signatures over secp256k1** with a **Blake2b-256** sighash. The sighash preimage follows the Kaspa BIP-143-like specification. Each input is signed independently, producing a 65-byte signature: 64 bytes Schnorr + 1 byte sighash type. |
| 121 | + |
| 122 | +## References |
| 123 | + |
| 124 | +- [Kaspa Website](https://kaspa.org/) |
| 125 | +- [Kaspa BIP-143-like SigHashes](https://github.com/kaspanet/docs/blob/main/Specs/BIP143-like%20SigHashes.md) |
| 126 | +- [Kaspa RPC API](https://kaspa.aspectron.org/docs/) |
0 commit comments