@rougechain/sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,334 @@
1
+ # @rougechain/sdk
2
+
3
+ Official SDK for **RougeChain** — a post-quantum Layer 1 blockchain secured by ML-DSA-65 (CRYSTALS-Dilithium) signatures.
4
+
5
+ Build dApps on RougeChain from any JavaScript/TypeScript environment: browser, Node.js, or React Native.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @rougechain/sdk
11
+ ```
12
+
13
+ ## Quick Start
14
+
15
+ ```typescript
16
+ import { RougeChain, Wallet } from '@rougechain/sdk';
17
+
18
+ // Connect to a RougeChain node
19
+ const rc = new RougeChain('https://testnet.rougechain.io/api');
20
+
21
+ // Generate a new post-quantum wallet
22
+ const wallet = Wallet.generate();
23
+ console.log('Public key:', wallet.publicKey);
24
+
25
+ // Request testnet tokens
26
+ await rc.faucet(wallet);
27
+
28
+ // Check balance
29
+ const balance = await rc.getBalance(wallet.publicKey);
30
+ console.log('Balance:', balance);
31
+
32
+ // Transfer tokens
33
+ await rc.transfer(wallet, { to: recipientPubKey, amount: 100 });
34
+ ```
35
+
36
+ ## Core Concepts
37
+
38
+ ### Wallet
39
+
40
+ All signing happens client-side. Private keys never leave your application.
41
+
42
+ ```typescript
43
+ import { Wallet } from '@rougechain/sdk';
44
+
45
+ // Generate a new ML-DSA-65 keypair
46
+ const wallet = Wallet.generate();
47
+
48
+ // Restore from saved keys
49
+ const restored = Wallet.fromKeys(publicKey, privateKey);
50
+
51
+ // Export for storage (your responsibility to store securely)
52
+ const keys = wallet.toJSON(); // { publicKey, privateKey }
53
+
54
+ // Verify keypair integrity
55
+ const valid = wallet.verify(); // true
56
+ ```
57
+
58
+ ### Client
59
+
60
+ The `RougeChain` client handles all API communication. Pass a wallet to any write method to sign transactions automatically.
61
+
62
+ ```typescript
63
+ import { RougeChain } from '@rougechain/sdk';
64
+
65
+ const rc = new RougeChain('https://testnet.rougechain.io/api');
66
+
67
+ // With API key (if the node requires it)
68
+ const rc = new RougeChain('https://testnet.rougechain.io/api', {
69
+ apiKey: 'your-api-key',
70
+ });
71
+
72
+ // Custom fetch (useful for Node.js < 18 or React Native)
73
+ const rc = new RougeChain('https://testnet.rougechain.io/api', {
74
+ fetch: customFetchFn,
75
+ });
76
+ ```
77
+
78
+ ## API Reference
79
+
80
+ ### Queries (no wallet needed)
81
+
82
+ ```typescript
83
+ // Node
84
+ const stats = await rc.getStats();
85
+ const health = await rc.getHealth();
86
+
87
+ // Blocks
88
+ const blocks = await rc.getBlocks({ limit: 10 });
89
+ const summary = await rc.getBlocksSummary('24h');
90
+
91
+ // Balance
92
+ const balance = await rc.getBalance(publicKey);
93
+ const tokenBal = await rc.getTokenBalance(publicKey, 'MYTOKEN');
94
+
95
+ // Tokens
96
+ const tokens = await rc.getTokens();
97
+ const meta = await rc.getTokenMetadata('MYTOKEN');
98
+ const holders = await rc.getTokenHolders('MYTOKEN');
99
+
100
+ // Validators
101
+ const validators = await rc.getValidators();
102
+ const finality = await rc.getFinality();
103
+
104
+ // Burned tokens
105
+ const burned = await rc.getBurnedTokens();
106
+ ```
107
+
108
+ ### Transfers & Tokens
109
+
110
+ ```typescript
111
+ // Transfer XRGE
112
+ await rc.transfer(wallet, { to: recipient, amount: 100 });
113
+
114
+ // Transfer custom token
115
+ await rc.transfer(wallet, { to: recipient, amount: 50, token: 'MYTOKEN' });
116
+
117
+ // Create a new token
118
+ await rc.createToken(wallet, {
119
+ name: 'My Token',
120
+ symbol: 'MTK',
121
+ totalSupply: 1_000_000,
122
+ });
123
+
124
+ // Burn tokens
125
+ await rc.burn(wallet, 500, 1, 'XRGE');
126
+
127
+ // Faucet (testnet only)
128
+ await rc.faucet(wallet);
129
+ ```
130
+
131
+ ### Staking
132
+
133
+ ```typescript
134
+ await rc.stake(wallet, { amount: 1000 });
135
+ await rc.unstake(wallet, { amount: 500 });
136
+ ```
137
+
138
+ ### DEX (rc.dex)
139
+
140
+ ```typescript
141
+ // List pools
142
+ const pools = await rc.dex.getPools();
143
+
144
+ // Get pool details
145
+ const pool = await rc.dex.getPool('XRGE-MTK');
146
+
147
+ // Get swap quote
148
+ const quote = await rc.dex.quote({
149
+ poolId: 'XRGE-MTK',
150
+ tokenIn: 'XRGE',
151
+ amountIn: 100,
152
+ });
153
+
154
+ // Execute swap
155
+ await rc.dex.swap(wallet, {
156
+ tokenIn: 'XRGE',
157
+ tokenOut: 'MTK',
158
+ amountIn: 100,
159
+ minAmountOut: 95,
160
+ });
161
+
162
+ // Create pool
163
+ await rc.dex.createPool(wallet, {
164
+ tokenA: 'XRGE',
165
+ tokenB: 'MTK',
166
+ amountA: 10000,
167
+ amountB: 5000,
168
+ });
169
+
170
+ // Add / remove liquidity
171
+ await rc.dex.addLiquidity(wallet, { poolId: 'XRGE-MTK', amountA: 1000, amountB: 500 });
172
+ await rc.dex.removeLiquidity(wallet, { poolId: 'XRGE-MTK', lpAmount: 100 });
173
+
174
+ // Pool analytics
175
+ const events = await rc.dex.getPoolEvents('XRGE-MTK');
176
+ const stats = await rc.dex.getPoolStats('XRGE-MTK');
177
+ ```
178
+
179
+ ### NFTs (rc.nft)
180
+
181
+ RougeChain implements the RC-721 NFT standard with collections, royalties, freezing, and batch minting.
182
+
183
+ ```typescript
184
+ // Create a collection
185
+ await rc.nft.createCollection(wallet, {
186
+ symbol: 'ART',
187
+ name: 'My Art Collection',
188
+ royaltyBps: 500, // 5% royalty
189
+ maxSupply: 10000,
190
+ description: 'A post-quantum NFT collection',
191
+ });
192
+
193
+ // Mint an NFT
194
+ await rc.nft.mint(wallet, {
195
+ collectionId: 'abc123',
196
+ name: 'Piece #1',
197
+ metadataUri: 'https://example.com/nft/1.json',
198
+ attributes: { rarity: 'legendary' },
199
+ });
200
+
201
+ // Batch mint (up to 50)
202
+ await rc.nft.batchMint(wallet, {
203
+ collectionId: 'abc123',
204
+ names: ['#1', '#2', '#3'],
205
+ uris: ['https://example.com/1.json', 'https://example.com/2.json', 'https://example.com/3.json'],
206
+ });
207
+
208
+ // Transfer with optional sale price (triggers royalty)
209
+ await rc.nft.transfer(wallet, {
210
+ collectionId: 'abc123',
211
+ tokenId: 1,
212
+ to: buyerPubKey,
213
+ salePrice: 100, // triggers royalty payment to creator
214
+ });
215
+
216
+ // Burn, lock, freeze
217
+ await rc.nft.burn(wallet, { collectionId: 'abc123', tokenId: 1 });
218
+ await rc.nft.lock(wallet, { collectionId: 'abc123', tokenId: 2, locked: true });
219
+ await rc.nft.freezeCollection(wallet, { collectionId: 'abc123', frozen: true });
220
+
221
+ // Queries
222
+ const collections = await rc.nft.getCollections();
223
+ const collection = await rc.nft.getCollection('abc123');
224
+ const tokens = await rc.nft.getTokens('abc123', { limit: 20, offset: 0 });
225
+ const token = await rc.nft.getToken('abc123', 1);
226
+ const myNfts = await rc.nft.getByOwner(wallet.publicKey);
227
+ ```
228
+
229
+ ### Bridge (rc.bridge)
230
+
231
+ Bridge between Base Sepolia ETH and RougeChain qETH.
232
+
233
+ ```typescript
234
+ // Check bridge status
235
+ const config = await rc.bridge.getConfig();
236
+ // { enabled: true, custodyAddress: '0x...', chainId: 84532 }
237
+
238
+ // Withdraw qETH to receive ETH on Base Sepolia
239
+ await rc.bridge.withdraw(wallet, {
240
+ amount: 500000, // in qETH units
241
+ evmAddress: '0xYourBaseSepoliaAddress',
242
+ });
243
+
244
+ // Claim (after depositing ETH to custody address)
245
+ await rc.bridge.claim({
246
+ evmTxHash: '0x...',
247
+ evmAddress: '0x...',
248
+ evmSignature: '0x...', // personal_sign from MetaMask
249
+ recipientPubkey: wallet.publicKey,
250
+ });
251
+
252
+ // List pending withdrawals
253
+ const withdrawals = await rc.bridge.getWithdrawals();
254
+ ```
255
+
256
+ ### Low-Level Signing
257
+
258
+ For advanced use cases, sign transactions manually:
259
+
260
+ ```typescript
261
+ import { signTransaction, verifyTransaction, generateNonce } from '@rougechain/sdk';
262
+
263
+ const payload = {
264
+ type: 'transfer' as const,
265
+ from: wallet.publicKey,
266
+ to: recipient,
267
+ amount: 100,
268
+ fee: 1,
269
+ token: 'XRGE',
270
+ timestamp: Date.now(),
271
+ nonce: generateNonce(),
272
+ };
273
+
274
+ const signedTx = signTransaction(payload, wallet.privateKey, wallet.publicKey);
275
+ const valid = verifyTransaction(signedTx); // true
276
+ ```
277
+
278
+ ## Environment Setup
279
+
280
+ ### Browser
281
+
282
+ Works out of the box with any bundler (Vite, webpack, etc.).
283
+
284
+ ### Node.js 18+
285
+
286
+ Works out of the box (native `fetch` and `crypto.getRandomValues`).
287
+
288
+ ### Node.js < 18
289
+
290
+ Provide a fetch polyfill:
291
+
292
+ ```typescript
293
+ import fetch from 'node-fetch';
294
+ const rc = new RougeChain('https://testnet.rougechain.io/api', { fetch });
295
+ ```
296
+
297
+ ### React Native
298
+
299
+ Install a `crypto.getRandomValues` polyfill before importing the SDK:
300
+
301
+ ```typescript
302
+ import 'react-native-get-random-values';
303
+ import { RougeChain, Wallet } from '@rougechain/sdk';
304
+ ```
305
+
306
+ ## TypeScript
307
+
308
+ The SDK is written in TypeScript and ships with full type declarations. All interfaces are exported:
309
+
310
+ ```typescript
311
+ import type {
312
+ Block,
313
+ Transaction,
314
+ TokenMetadata,
315
+ NftCollection,
316
+ NftToken,
317
+ LiquidityPool,
318
+ BalanceResponse,
319
+ Validator,
320
+ BridgeConfig,
321
+ WalletKeys,
322
+ ApiResponse,
323
+ } from '@rougechain/sdk';
324
+ ```
325
+
326
+ ## Security
327
+
328
+ - **Post-quantum cryptography**: All signatures use ML-DSA-65 (CRYSTALS-Dilithium), resistant to quantum attacks.
329
+ - **Client-side signing**: Private keys never leave your application. Transactions are signed locally and submitted to the node pre-signed.
330
+ - **No key storage**: The SDK does not store keys. Persistence is your application's responsibility.
331
+
332
+ ## License
333
+
334
+ MIT