clawreum-sdk 1.0.0 → 1.0.1
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 +36 -36
- package/package.json +1 -1
- package/src/index.js +25 -25
package/README.md
CHANGED
|
@@ -15,24 +15,24 @@ const ClawreumMiner = require('clawreum-sdk');
|
|
|
15
15
|
|
|
16
16
|
const miner = new ClawreumMiner({
|
|
17
17
|
platform: 'telegram', // 'telegram' | 'discord' | 'whatsapp'
|
|
18
|
-
botId: '123456789', //
|
|
19
|
-
botName: 'MyMiningBot' //
|
|
18
|
+
botId: '123456789', // Platform bot ID
|
|
19
|
+
botName: 'MyMiningBot' // Bot display name
|
|
20
20
|
});
|
|
21
21
|
|
|
22
|
-
//
|
|
22
|
+
// Event listeners
|
|
23
23
|
miner.on('reward', (data) => {
|
|
24
24
|
console.log(`+${data.reward.toFixed(4)} CLAWREUM`);
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
miner.on('balance', (data) => {
|
|
28
|
-
console.log(
|
|
28
|
+
console.log(`Refining: ${data.refining}, Claimable: ${data.claimable}`);
|
|
29
29
|
});
|
|
30
30
|
|
|
31
31
|
miner.on('error', (err) => {
|
|
32
|
-
console.error('
|
|
32
|
+
console.error('Error:', err.message);
|
|
33
33
|
});
|
|
34
34
|
|
|
35
|
-
//
|
|
35
|
+
// Start mining
|
|
36
36
|
miner.start();
|
|
37
37
|
```
|
|
38
38
|
|
|
@@ -40,41 +40,41 @@ miner.start();
|
|
|
40
40
|
|
|
41
41
|
| Option | Type | Required | Default | Description |
|
|
42
42
|
|--------|------|----------|---------|-------------|
|
|
43
|
-
| `platform` | string |
|
|
44
|
-
| `botId` | string |
|
|
45
|
-
| `botName` | string |
|
|
46
|
-
| `server` | string | | `wss://api.clawreum.com` | WebSocket
|
|
47
|
-
| `ownerWallet` | string | | - |
|
|
48
|
-
| `autoReconnect` | boolean | | `true` |
|
|
49
|
-
| `miningInterval` | number | | `250` |
|
|
43
|
+
| `platform` | string | Yes | - | Bot platform (`telegram`, `discord`, `whatsapp`) |
|
|
44
|
+
| `botId` | string | Yes | - | Platform bot ID |
|
|
45
|
+
| `botName` | string | Yes | - | Bot display name |
|
|
46
|
+
| `server` | string | No | `wss://api.clawreum.com` | WebSocket server URL |
|
|
47
|
+
| `ownerWallet` | string | No | - | Wallet address for rewards |
|
|
48
|
+
| `autoReconnect` | boolean | No | `true` | Auto reconnect on disconnect |
|
|
49
|
+
| `miningInterval` | number | No | `250` | Mining action interval (ms) |
|
|
50
50
|
|
|
51
51
|
## Events
|
|
52
52
|
|
|
53
53
|
| Event | Data | Description |
|
|
54
54
|
|-------|------|-------------|
|
|
55
|
-
| `registered` | `{ botId, characterName }` |
|
|
56
|
-
| `authenticated` | `{ botName }` |
|
|
57
|
-
| `joined` | `{ room, botId }` |
|
|
58
|
-
| `mining` | `{ started: true }` |
|
|
59
|
-
| `progress` | `{ progress }` |
|
|
60
|
-
| `reward` | `{ reward, base, bonus, packId }` |
|
|
61
|
-
| `balance` | `{ refining, claimable, world, boost }` |
|
|
62
|
-
| `block` | `{ block, pack, difficulty }` |
|
|
63
|
-
| `disconnected` | `{ code, reason }` |
|
|
64
|
-
| `stopped` | - |
|
|
65
|
-
| `error` | `Error` |
|
|
66
|
-
| `log` | `string` |
|
|
55
|
+
| `registered` | `{ botId, characterName }` | Bot registration complete |
|
|
56
|
+
| `authenticated` | `{ botName }` | Authentication successful |
|
|
57
|
+
| `joined` | `{ room, botId }` | Joined mining room |
|
|
58
|
+
| `mining` | `{ started: true }` | Mining loop started |
|
|
59
|
+
| `progress` | `{ progress }` | Mining progress (0~1) |
|
|
60
|
+
| `reward` | `{ reward, base, bonus, packId }` | Mining reward received |
|
|
61
|
+
| `balance` | `{ refining, claimable, world, boost }` | Balance sync |
|
|
62
|
+
| `block` | `{ block, pack, difficulty }` | Block update |
|
|
63
|
+
| `disconnected` | `{ code, reason }` | Connection closed |
|
|
64
|
+
| `stopped` | - | Mining stopped |
|
|
65
|
+
| `error` | `Error` | Error occurred |
|
|
66
|
+
| `log` | `string` | Log message |
|
|
67
67
|
|
|
68
68
|
## Methods
|
|
69
69
|
|
|
70
70
|
### `start()`
|
|
71
|
-
|
|
71
|
+
Start mining.
|
|
72
72
|
|
|
73
73
|
### `stop()`
|
|
74
|
-
|
|
74
|
+
Stop mining and close connection.
|
|
75
75
|
|
|
76
76
|
### `getStatus()`
|
|
77
|
-
|
|
77
|
+
Get current status.
|
|
78
78
|
|
|
79
79
|
```javascript
|
|
80
80
|
const status = miner.getStatus();
|
|
@@ -104,27 +104,27 @@ miner.on('log', console.log);
|
|
|
104
104
|
miner.on('error', console.error);
|
|
105
105
|
|
|
106
106
|
miner.on('registered', ({ botId }) => {
|
|
107
|
-
console.log(
|
|
107
|
+
console.log(`Bot registered: ${botId}`);
|
|
108
108
|
});
|
|
109
109
|
|
|
110
110
|
miner.on('reward', ({ reward, bonus }) => {
|
|
111
|
-
console.log(
|
|
111
|
+
console.log(`Mining success! +${reward.toFixed(4)} (bonus: ${bonus.toFixed(4)})`);
|
|
112
112
|
});
|
|
113
113
|
|
|
114
114
|
miner.on('balance', ({ refining, claimable }) => {
|
|
115
|
-
console.log(
|
|
115
|
+
console.log(`Balance - Refining: ${refining.toFixed(2)}, Claimable: ${claimable.toFixed(2)}`);
|
|
116
116
|
});
|
|
117
117
|
|
|
118
|
-
//
|
|
118
|
+
// Start
|
|
119
119
|
miner.start();
|
|
120
120
|
|
|
121
|
-
//
|
|
121
|
+
// Check status after 10 minutes
|
|
122
122
|
setTimeout(() => {
|
|
123
123
|
const status = miner.getStatus();
|
|
124
|
-
console.log(
|
|
124
|
+
console.log(`Total mined: ${status.stats.totalMined.toFixed(4)} CLAWREUM`);
|
|
125
125
|
}, 600000);
|
|
126
126
|
|
|
127
|
-
//
|
|
127
|
+
// Graceful shutdown
|
|
128
128
|
process.on('SIGINT', () => {
|
|
129
129
|
miner.stop();
|
|
130
130
|
process.exit();
|
|
@@ -134,7 +134,7 @@ process.on('SIGINT', () => {
|
|
|
134
134
|
## Requirements
|
|
135
135
|
|
|
136
136
|
- Node.js 18+
|
|
137
|
-
-
|
|
137
|
+
- Registered bot (Telegram/Discord/WhatsApp)
|
|
138
138
|
|
|
139
139
|
## License
|
|
140
140
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Clawreum Mining SDK
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Usage:
|
|
5
5
|
* const ClawreumMiner = require('clawreum-sdk');
|
|
6
6
|
*
|
|
7
7
|
* const miner = new ClawreumMiner({
|
|
@@ -25,18 +25,18 @@ class ClawreumMiner extends EventEmitter {
|
|
|
25
25
|
/**
|
|
26
26
|
* @param {Object} options
|
|
27
27
|
* @param {string} options.platform - 'telegram' | 'discord' | 'whatsapp'
|
|
28
|
-
* @param {string} options.botId -
|
|
29
|
-
* @param {string} options.botName -
|
|
30
|
-
* @param {string} [options.server] - WebSocket
|
|
31
|
-
* @param {string} [options.ownerWallet] -
|
|
32
|
-
* @param {boolean} [options.autoReconnect] -
|
|
33
|
-
* @param {number} [options.miningInterval] -
|
|
28
|
+
* @param {string} options.botId - Platform bot ID
|
|
29
|
+
* @param {string} options.botName - Bot display name
|
|
30
|
+
* @param {string} [options.server] - WebSocket server URL (default: wss://api.clawreum.com)
|
|
31
|
+
* @param {string} [options.ownerWallet] - Wallet address for rewards
|
|
32
|
+
* @param {boolean} [options.autoReconnect] - Auto reconnect (default: true)
|
|
33
|
+
* @param {number} [options.miningInterval] - Mining action interval in ms (default: 250)
|
|
34
34
|
*/
|
|
35
35
|
constructor(options = {}) {
|
|
36
36
|
super();
|
|
37
37
|
|
|
38
38
|
if (!options.platform || !options.botId || !options.botName) {
|
|
39
|
-
throw new Error('
|
|
39
|
+
throw new Error('Required options: platform, botId, botName');
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
this.options = {
|
|
@@ -55,7 +55,7 @@ class ClawreumMiner extends EventEmitter {
|
|
|
55
55
|
this.maxReconnectAttempts = 10;
|
|
56
56
|
this.botId = null;
|
|
57
57
|
|
|
58
|
-
//
|
|
58
|
+
// Stats
|
|
59
59
|
this.stats = {
|
|
60
60
|
totalMined: 0,
|
|
61
61
|
miningCount: 0,
|
|
@@ -65,15 +65,15 @@ class ClawreumMiner extends EventEmitter {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
|
-
*
|
|
68
|
+
* Start mining
|
|
69
69
|
*/
|
|
70
70
|
async start() {
|
|
71
71
|
if (this.isConnected) {
|
|
72
|
-
this.emit('warn', '
|
|
72
|
+
this.emit('warn', 'Already connected');
|
|
73
73
|
return;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
this.emit('log',
|
|
76
|
+
this.emit('log', `Connecting to server: ${this.options.server}`);
|
|
77
77
|
|
|
78
78
|
try {
|
|
79
79
|
const wsToken = await this._registerBot();
|
|
@@ -87,7 +87,7 @@ class ClawreumMiner extends EventEmitter {
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
/**
|
|
90
|
-
*
|
|
90
|
+
* Stop mining
|
|
91
91
|
*/
|
|
92
92
|
stop() {
|
|
93
93
|
this._stopMiningLoop();
|
|
@@ -102,7 +102,7 @@ class ClawreumMiner extends EventEmitter {
|
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
/**
|
|
105
|
-
*
|
|
105
|
+
* Get current status
|
|
106
106
|
*/
|
|
107
107
|
getStatus() {
|
|
108
108
|
return {
|
|
@@ -147,7 +147,7 @@ class ClawreumMiner extends EventEmitter {
|
|
|
147
147
|
const result = await response.json();
|
|
148
148
|
|
|
149
149
|
if (!result.success) {
|
|
150
|
-
throw new Error(result.message || '
|
|
150
|
+
throw new Error(result.message || 'Bot registration failed');
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
this.botId = result.botId;
|
|
@@ -162,13 +162,13 @@ class ClawreumMiner extends EventEmitter {
|
|
|
162
162
|
this.ws = new WebSocket(wsUrl);
|
|
163
163
|
|
|
164
164
|
const timeout = setTimeout(() => {
|
|
165
|
-
reject(new Error('
|
|
165
|
+
reject(new Error('Connection timeout'));
|
|
166
166
|
this.ws.close();
|
|
167
167
|
}, 30000);
|
|
168
168
|
|
|
169
169
|
this.ws.on('open', () => {
|
|
170
170
|
clearTimeout(timeout);
|
|
171
|
-
this.emit('log', 'WebSocket
|
|
171
|
+
this.emit('log', 'WebSocket connected');
|
|
172
172
|
this.reconnectAttempts = 0;
|
|
173
173
|
});
|
|
174
174
|
|
|
@@ -177,7 +177,7 @@ class ClawreumMiner extends EventEmitter {
|
|
|
177
177
|
const msg = JSON.parse(data.toString());
|
|
178
178
|
this._handleMessage(msg, resolve, reject);
|
|
179
179
|
} catch (err) {
|
|
180
|
-
this.emit('error', new Error(
|
|
180
|
+
this.emit('error', new Error(`Message parsing failed: ${err.message}`));
|
|
181
181
|
}
|
|
182
182
|
});
|
|
183
183
|
|
|
@@ -218,7 +218,7 @@ class ClawreumMiner extends EventEmitter {
|
|
|
218
218
|
break;
|
|
219
219
|
|
|
220
220
|
case 'attestFail':
|
|
221
|
-
this.emit('error', new Error(
|
|
221
|
+
this.emit('error', new Error(`Authentication failed: ${data.reason}`));
|
|
222
222
|
if (rejectConnect) rejectConnect(new Error(data.reason));
|
|
223
223
|
break;
|
|
224
224
|
|
|
@@ -264,11 +264,11 @@ class ClawreumMiner extends EventEmitter {
|
|
|
264
264
|
|
|
265
265
|
case 'reAttestSuccess':
|
|
266
266
|
this.sessionSecret = data.sessionSecret;
|
|
267
|
-
this.emit('log', '
|
|
267
|
+
this.emit('log', 'Re-authentication successful');
|
|
268
268
|
break;
|
|
269
269
|
|
|
270
270
|
case 'sessionRevoked':
|
|
271
|
-
this.emit('error', new Error(
|
|
271
|
+
this.emit('error', new Error(`Session revoked: ${data.reason}`));
|
|
272
272
|
this.stop();
|
|
273
273
|
break;
|
|
274
274
|
|
|
@@ -285,7 +285,7 @@ class ClawreumMiner extends EventEmitter {
|
|
|
285
285
|
break;
|
|
286
286
|
|
|
287
287
|
default:
|
|
288
|
-
//
|
|
288
|
+
// Other messages
|
|
289
289
|
break;
|
|
290
290
|
}
|
|
291
291
|
}
|
|
@@ -293,7 +293,7 @@ class ClawreumMiner extends EventEmitter {
|
|
|
293
293
|
_handleChallenge(challenge, isReAttest = false) {
|
|
294
294
|
const { challengeId, nonce, difficulty } = challenge;
|
|
295
295
|
|
|
296
|
-
this.emit('log', `${isReAttest ? '
|
|
296
|
+
this.emit('log', `${isReAttest ? 'Re-' : ''}Authentication challenge (difficulty: ${difficulty})`);
|
|
297
297
|
|
|
298
298
|
const solution = this._solveChallenge(nonce, difficulty);
|
|
299
299
|
|
|
@@ -354,14 +354,14 @@ class ClawreumMiner extends EventEmitter {
|
|
|
354
354
|
|
|
355
355
|
_scheduleReconnect() {
|
|
356
356
|
if (this.reconnectAttempts >= this.maxReconnectAttempts) {
|
|
357
|
-
this.emit('error', new Error('
|
|
357
|
+
this.emit('error', new Error('Max reconnection attempts exceeded'));
|
|
358
358
|
return;
|
|
359
359
|
}
|
|
360
360
|
|
|
361
361
|
const delay = Math.min(1000 * Math.pow(2, this.reconnectAttempts), 30000);
|
|
362
362
|
this.reconnectAttempts++;
|
|
363
363
|
|
|
364
|
-
this.emit('log',
|
|
364
|
+
this.emit('log', `Reconnecting in ${delay / 1000}s (${this.reconnectAttempts}/${this.maxReconnectAttempts})`);
|
|
365
365
|
|
|
366
366
|
setTimeout(() => {
|
|
367
367
|
this.start();
|