@dubsdotapp/node 0.1.1 → 0.1.2

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.
Files changed (2) hide show
  1. package/README.md +96 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,96 @@
1
+ # @dubsdotapp/node
2
+
3
+ Server-side Node.js SDK for the [Dubs](https://dubs.app) betting platform on Solana.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @dubsdotapp/node
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```ts
14
+ import { Dubs } from '@dubsdotapp/node';
15
+
16
+ const dubs = new Dubs({
17
+ apiKey: process.env.DUBS_API_KEY!,
18
+ resolutionSecret: process.env.DUBS_RESOLUTION_SECRET!,
19
+ network: 'mainnet-beta', // or 'devnet'
20
+ });
21
+ ```
22
+
23
+ ## Resolve a Game
24
+
25
+ Resolve a custom game (game_mode=6) by declaring a winner. The SDK automatically computes the HMAC-SHA256 signature using your resolution secret.
26
+
27
+ ```ts
28
+ const result = await dubs.resolveGame('game-id-here', {
29
+ winner: 'home', // 'home' | 'away' | 'draw' | null (null = refund)
30
+ metadata: { source: 'my-oracle' }, // optional
31
+ });
32
+
33
+ console.log(result);
34
+ // {
35
+ // success: true,
36
+ // gameId: 'game-id-here',
37
+ // winner: 'home',
38
+ // signature: '5K2t...',
39
+ // explorerUrl: 'https://explorer.solana.com/tx/5K2t...'
40
+ // }
41
+ ```
42
+
43
+ ## Verify Webhooks
44
+
45
+ Verify incoming webhook requests from Dubs using your webhook secret.
46
+
47
+ ```ts
48
+ import { Dubs } from '@dubsdotapp/node';
49
+
50
+ // In your webhook handler (e.g. Express)
51
+ app.post('/webhooks/dubs', (req, res) => {
52
+ const event = Dubs.verifyWebhook(
53
+ req.body, // raw body (string or Buffer)
54
+ req.headers['x-dubs-signature'], // signature header
55
+ process.env.DUBS_WEBHOOK_SECRET!, // your webhook secret
56
+ );
57
+
58
+ console.log(event);
59
+ // { event: 'game.resolved', timestamp: '...', data: { ... } }
60
+
61
+ res.sendStatus(200);
62
+ });
63
+ ```
64
+
65
+ ## Configuration
66
+
67
+ | Option | Type | Description |
68
+ | ------------------ | ------------- | -------------------------------------------------------- |
69
+ | `apiKey` | `string` | Your Dubs API key (from the developer portal) |
70
+ | `resolutionSecret` | `string?` | Secret for signing `resolveGame` requests |
71
+ | `network` | `string?` | `'mainnet-beta'` or `'devnet'` — sets the base URL |
72
+ | `baseUrl` | `string?` | Explicit base URL (overrides `network` if both provided) |
73
+
74
+ ## Error Handling
75
+
76
+ All API errors throw a `DubsApiError` with `code`, `message`, and `httpStatus` properties.
77
+
78
+ ```ts
79
+ import { Dubs, DubsApiError } from '@dubsdotapp/node';
80
+
81
+ try {
82
+ await dubs.resolveGame(gameId, { winner: 'home' });
83
+ } catch (err) {
84
+ if (err instanceof DubsApiError) {
85
+ console.error(err.code, err.message, err.httpStatus);
86
+ }
87
+ }
88
+ ```
89
+
90
+ ## Requirements
91
+
92
+ - Node.js >= 18
93
+
94
+ ## License
95
+
96
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dubsdotapp/node",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Server-side Node.js SDK for the Dubs betting platform",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",