@ynhcj/xiaoyi 2.1.4 → 2.1.6

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/dist/auth.d.ts CHANGED
@@ -2,6 +2,8 @@ import { AuthCredentials } from "./types";
2
2
  /**
3
3
  * Generate authentication signature using AK/SK mechanism
4
4
  * Based on: https://developer.huawei.com/consumer/cn/doc/service/pushmessage-0000002505761436
5
+ *
6
+ * Signature format: Base64(HMAC-SHA256(secretKey, ts))
5
7
  */
6
8
  export declare class XiaoYiAuth {
7
9
  private ak;
@@ -14,7 +16,9 @@ export declare class XiaoYiAuth {
14
16
  generateAuthCredentials(): AuthCredentials;
15
17
  /**
16
18
  * Generate HMAC-SHA256 signature
17
- * Format: HMAC-SHA256(SK, "ak={AK}&timestamp={TIMESTAMP}")
19
+ * Format: Base64(HMAC-SHA256(secretKey, ts))
20
+ * Reference: https://developer.huawei.com/consumer/cn/doc/service/pushmessage-0000002505761436
21
+ * @param timestamp - Timestamp as string (e.g., "1514764800000")
18
22
  */
19
23
  private generateSignature;
20
24
  /**
package/dist/auth.js CHANGED
@@ -38,6 +38,8 @@ const crypto = __importStar(require("crypto"));
38
38
  /**
39
39
  * Generate authentication signature using AK/SK mechanism
40
40
  * Based on: https://developer.huawei.com/consumer/cn/doc/service/pushmessage-0000002505761436
41
+ *
42
+ * Signature format: Base64(HMAC-SHA256(secretKey, ts))
41
43
  */
42
44
  class XiaoYiAuth {
43
45
  constructor(ak, sk, agentId) {
@@ -50,7 +52,7 @@ class XiaoYiAuth {
50
52
  */
51
53
  generateAuthCredentials() {
52
54
  const timestamp = Date.now();
53
- const signature = this.generateSignature(timestamp);
55
+ const signature = this.generateSignature(timestamp.toString());
54
56
  return {
55
57
  ak: this.ak,
56
58
  sk: this.sk,
@@ -60,19 +62,23 @@ class XiaoYiAuth {
60
62
  }
61
63
  /**
62
64
  * Generate HMAC-SHA256 signature
63
- * Format: HMAC-SHA256(SK, "ak={AK}&timestamp={TIMESTAMP}")
65
+ * Format: Base64(HMAC-SHA256(secretKey, ts))
66
+ * Reference: https://developer.huawei.com/consumer/cn/doc/service/pushmessage-0000002505761436
67
+ * @param timestamp - Timestamp as string (e.g., "1514764800000")
64
68
  */
65
69
  generateSignature(timestamp) {
66
- const stringToSign = `ak=${this.ak}&timestamp=${timestamp}`;
70
+ // HMAC-SHA256(secretKey, ts)
67
71
  const hmac = crypto.createHmac("sha256", this.sk);
68
- hmac.update(stringToSign);
69
- return hmac.digest("hex");
72
+ hmac.update(timestamp);
73
+ const digest = hmac.digest();
74
+ // Base64 encode
75
+ return digest.toString("base64");
70
76
  }
71
77
  /**
72
78
  * Verify if credentials are valid
73
79
  */
74
80
  verifyCredentials(credentials) {
75
- const expectedSignature = this.generateSignature(credentials.timestamp);
81
+ const expectedSignature = this.generateSignature(credentials.timestamp.toString());
76
82
  return credentials.signature === expectedSignature;
77
83
  }
78
84
  /**
@@ -80,7 +86,7 @@ class XiaoYiAuth {
80
86
  */
81
87
  generateAuthHeaders() {
82
88
  const timestamp = Date.now();
83
- const signature = this.generateSignature(timestamp);
89
+ const signature = this.generateSignature(timestamp.toString());
84
90
  return {
85
91
  "x-access-key": this.ak,
86
92
  "x-sign": signature,
package/dist/websocket.js CHANGED
@@ -297,6 +297,11 @@ class XiaoYiWebSocketManager extends events_1.EventEmitter {
297
297
  * Handle incoming WebSocket messages
298
298
  */
299
299
  handleMessage(message) {
300
+ // 打印完整的接收消息
301
+ console.log("\n" + "=".repeat(80));
302
+ console.log(`[XiaoYi WS] Received message from server:`);
303
+ console.log(JSON.stringify(message, null, 2));
304
+ console.log("=".repeat(80) + "\n");
300
305
  // Validate agentId
301
306
  if (message.agentId && message.agentId !== this.config.agentId) {
302
307
  console.warn(`Received message with mismatched agentId: ${message.agentId}, expected: ${this.config.agentId}. Discarding.`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ynhcj/xiaoyi",
3
- "version": "2.1.4",
3
+ "version": "2.1.6",
4
4
  "description": "XiaoYi channel plugin for OpenClaw",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",