Skip to content

Commit 3d44df7

Browse files
committed
feat(sdk-coin-kaspa): implement Kaspa SDK module
Ticket: CECHO-388
1 parent 8302381 commit 3d44df7

25 files changed

Lines changed: 2728 additions & 0 deletions
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
.idea
3+
public
4+
dist
5+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "../../.eslintrc.json",
3+
"rules": {
4+
"@typescript-eslint/explicit-module-boundary-types": "error",
5+
"indent": "off"
6+
}
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
require: 'tsx'
2+
timeout: '60000'
3+
reporter: 'min'
4+
reporter-option:
5+
- 'cdn=true'
6+
- 'json=false'
7+
exit: true
8+
spec: ['test/unit/**/*.ts']

modules/sdk-coin-kaspa/README.md

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
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/)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"name": "@bitgo/sdk-coin-kaspa",
3+
"version": "1.0.0",
4+
"description": "BitGo's SDK coin library for Kaspa (KASPA)",
5+
"main": "./dist/src/index.js",
6+
"types": "./dist/src/index.d.ts",
7+
"scripts": {
8+
"build": "yarn tsc --build --incremental --verbose .",
9+
"fmt": "prettier --write .",
10+
"check-fmt": "prettier --check '**/*.{ts,js,json}'",
11+
"clean": "rm -r ./dist",
12+
"lint": "eslint --quiet .",
13+
"prepare": "npm run build",
14+
"test": "npm run coverage",
15+
"coverage": "nyc -- npm run unit-test",
16+
"unit-test": "mocha"
17+
},
18+
"repository": {
19+
"type": "git",
20+
"url": "https://github.com/BitGo/BitGoJS.git",
21+
"directory": "modules/sdk-coin-kaspa"
22+
},
23+
"author": "BitGo SDK Team <sdkteam@bitgo.com>",
24+
"license": "MIT",
25+
"engines": {
26+
"node": ">=20"
27+
},
28+
"lint-staged": {
29+
"*.{js,ts}": [
30+
"yarn prettier --write",
31+
"yarn eslint --fix"
32+
]
33+
},
34+
"publishConfig": {
35+
"access": "public"
36+
},
37+
"nyc": {
38+
"extension": [
39+
".ts"
40+
]
41+
},
42+
"dependencies": {
43+
"@bitgo/sdk-core": "^36.40.0",
44+
"@bitgo/secp256k1": "^1.11.0",
45+
"@bitgo/statics": "^58.35.0",
46+
"bignumber.js": "9.0.0",
47+
"blakejs": "^1.2.1"
48+
},
49+
"files": [
50+
"dist"
51+
]
52+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export * from './kaspa';
2+
export * from './lib';
3+
export * as KaspaLib from './lib';
4+
export * from './register';

0 commit comments

Comments
 (0)