@honor-claw/yoyo 1.1.2 → 1.1.4-beta.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/index.ts +25 -25
- package/package.json +5 -5
- package/src/apis/claw-cloud.ts +124 -124
- package/src/apis/helpers.ts +10 -10
- package/src/apis/honor-auth.ts +158 -158
- package/src/apis/http-client.ts +239 -239
- package/src/apis/index.ts +8 -8
- package/src/apis/types.ts +77 -73
- package/src/cloud-channel/channel.ts +117 -117
- package/src/cloud-channel/client.ts +3 -3
- package/src/cloud-channel/index.ts +4 -4
- package/src/cloud-channel/message-handler.ts +50 -42
- package/src/cloud-channel/session-manager.ts +14 -9
- package/src/cloud-channel/types.ts +115 -115
- package/src/commands/env/impl.ts +58 -58
- package/src/commands/env/index.ts +1 -1
- package/src/commands/index.ts +30 -30
- package/src/commands/login/impl.ts +30 -30
- package/src/commands/login/index.ts +1 -1
- package/src/commands/logout/index.ts +1 -1
- package/src/commands/status/index.ts +194 -194
- package/src/gateway-client/client.ts +90 -90
- package/src/gateway-client/device/auth.ts +57 -57
- package/src/gateway-client/device/builder.ts +105 -105
- package/src/gateway-client/device/helpers.ts +40 -40
- package/src/gateway-client/device/identity.ts +251 -251
- package/src/gateway-client/device/index.ts +40 -40
- package/src/gateway-client/device/types.ts +57 -57
- package/src/gateway-client/index.ts +5 -5
- package/src/gateway-client/protocol-client.ts +49 -34
- package/src/honor-auth/browser.ts +2 -2
- package/src/honor-auth/callback-server.ts +109 -109
- package/src/honor-auth/cloud.ts +57 -57
- package/src/honor-auth/config.ts +43 -43
- package/src/honor-auth/index.ts +3 -3
- package/src/honor-auth/token-manager.ts +90 -90
- package/src/honor-auth/types.ts +50 -50
- package/src/index.ts +10 -10
- package/src/modules/claw-configs/config-manager.ts +409 -409
- package/src/modules/claw-configs/hosts.ts +48 -48
- package/src/modules/claw-configs/index.ts +8 -8
- package/src/modules/claw-configs/provider.ts +394 -394
- package/src/modules/claw-configs/types.ts +34 -34
- package/src/modules/device/device-info.ts +1 -1
- package/src/modules/device/index.ts +3 -3
- package/src/modules/device/providers/base.ts +32 -32
- package/src/modules/device/providers/pad.ts +107 -107
- package/src/modules/device/providers/windows.ts +130 -130
- package/src/modules/device/registry.ts +48 -43
- package/src/modules/login/impl.ts +31 -26
- package/src/modules/login/index.ts +6 -6
- package/src/schemas.ts +23 -23
- package/src/services/connection/impl.ts +339 -339
- package/src/services/connection/status-tracker/events.ts +127 -127
- package/src/services/connection/status-tracker/index.ts +31 -31
- package/src/services/connection/status-tracker/storage.ts +133 -133
- package/src/services/connection/status-tracker/tracker.ts +370 -370
- package/src/services/connection/status-tracker/types.ts +131 -131
- package/src/services/connection/types.ts +20 -20
- package/src/types.ts +64 -64
- package/src/utils/id.ts +8 -8
- package/src/utils/jwt.ts +37 -37
- package/src/utils/logger.ts +20 -20
- package/src/utils/proxy.ts +58 -58
- package/src/utils/version.ts +29 -29
- package/src/utils/ws.ts +21 -21
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import { normalizeDeviceMetadataForAuth } from "./helpers.js";
|
|
2
|
-
import type {
|
|
3
|
-
DeviceAuthPayloadParams,
|
|
4
|
-
DeviceAuthPayloadV3Params,
|
|
5
|
-
} from "./types.js";
|
|
6
|
-
|
|
7
|
-
export { normalizeDeviceMetadataForAuth };
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Build device authentication payload (v2)
|
|
11
|
-
* @param params - Authentication parameters
|
|
12
|
-
* @returns Pipe-delimited payload string
|
|
13
|
-
*/
|
|
14
|
-
export function buildDeviceAuthPayload(
|
|
15
|
-
params: DeviceAuthPayloadParams
|
|
16
|
-
): string {
|
|
17
|
-
const scopes = params.scopes.join(",");
|
|
18
|
-
const token = params.token ?? "";
|
|
19
|
-
return [
|
|
20
|
-
"v2",
|
|
21
|
-
params.deviceId,
|
|
22
|
-
params.clientId,
|
|
23
|
-
params.clientMode,
|
|
24
|
-
params.role,
|
|
25
|
-
scopes,
|
|
26
|
-
String(params.signedAtMs),
|
|
27
|
-
token,
|
|
28
|
-
params.nonce,
|
|
29
|
-
].join("|");
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Build device authentication payload (v3) with platform and device family
|
|
34
|
-
* @param params - Authentication parameters including platform and device family
|
|
35
|
-
* @returns Pipe-delimited payload string
|
|
36
|
-
*/
|
|
37
|
-
export function buildDeviceAuthPayloadV3(
|
|
38
|
-
params: DeviceAuthPayloadV3Params
|
|
39
|
-
): string {
|
|
40
|
-
const scopes = params.scopes.join(",");
|
|
41
|
-
const token = params.token ?? "";
|
|
42
|
-
const platform = normalizeDeviceMetadataForAuth(params.platform);
|
|
43
|
-
const deviceFamily = normalizeDeviceMetadataForAuth(params.deviceFamily);
|
|
44
|
-
return [
|
|
45
|
-
"v3",
|
|
46
|
-
params.deviceId,
|
|
47
|
-
params.clientId,
|
|
48
|
-
params.clientMode,
|
|
49
|
-
params.role,
|
|
50
|
-
scopes,
|
|
51
|
-
String(params.signedAtMs),
|
|
52
|
-
token,
|
|
53
|
-
params.nonce,
|
|
54
|
-
platform,
|
|
55
|
-
deviceFamily,
|
|
56
|
-
].join("|");
|
|
57
|
-
}
|
|
1
|
+
import { normalizeDeviceMetadataForAuth } from "./helpers.js";
|
|
2
|
+
import type {
|
|
3
|
+
DeviceAuthPayloadParams,
|
|
4
|
+
DeviceAuthPayloadV3Params,
|
|
5
|
+
} from "./types.js";
|
|
6
|
+
|
|
7
|
+
export { normalizeDeviceMetadataForAuth };
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Build device authentication payload (v2)
|
|
11
|
+
* @param params - Authentication parameters
|
|
12
|
+
* @returns Pipe-delimited payload string
|
|
13
|
+
*/
|
|
14
|
+
export function buildDeviceAuthPayload(
|
|
15
|
+
params: DeviceAuthPayloadParams
|
|
16
|
+
): string {
|
|
17
|
+
const scopes = params.scopes.join(",");
|
|
18
|
+
const token = params.token ?? "";
|
|
19
|
+
return [
|
|
20
|
+
"v2",
|
|
21
|
+
params.deviceId,
|
|
22
|
+
params.clientId,
|
|
23
|
+
params.clientMode,
|
|
24
|
+
params.role,
|
|
25
|
+
scopes,
|
|
26
|
+
String(params.signedAtMs),
|
|
27
|
+
token,
|
|
28
|
+
params.nonce,
|
|
29
|
+
].join("|");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Build device authentication payload (v3) with platform and device family
|
|
34
|
+
* @param params - Authentication parameters including platform and device family
|
|
35
|
+
* @returns Pipe-delimited payload string
|
|
36
|
+
*/
|
|
37
|
+
export function buildDeviceAuthPayloadV3(
|
|
38
|
+
params: DeviceAuthPayloadV3Params
|
|
39
|
+
): string {
|
|
40
|
+
const scopes = params.scopes.join(",");
|
|
41
|
+
const token = params.token ?? "";
|
|
42
|
+
const platform = normalizeDeviceMetadataForAuth(params.platform);
|
|
43
|
+
const deviceFamily = normalizeDeviceMetadataForAuth(params.deviceFamily);
|
|
44
|
+
return [
|
|
45
|
+
"v3",
|
|
46
|
+
params.deviceId,
|
|
47
|
+
params.clientId,
|
|
48
|
+
params.clientMode,
|
|
49
|
+
params.role,
|
|
50
|
+
scopes,
|
|
51
|
+
String(params.signedAtMs),
|
|
52
|
+
token,
|
|
53
|
+
params.nonce,
|
|
54
|
+
platform,
|
|
55
|
+
deviceFamily,
|
|
56
|
+
].join("|");
|
|
57
|
+
}
|
|
@@ -1,105 +1,105 @@
|
|
|
1
|
-
import { GATEWAY_CLIENT_MODES, GATEWAY_CLIENT_IDS } from "../protocol/index.js";
|
|
2
|
-
import { buildDeviceAuthPayloadV3 } from "./auth.js";
|
|
3
|
-
import {
|
|
4
|
-
publicKeyRawBase64UrlFromPem,
|
|
5
|
-
signDevicePayload,
|
|
6
|
-
} from "./identity.js";
|
|
7
|
-
import {
|
|
8
|
-
type DeviceBuilderOptions,
|
|
9
|
-
type DeviceInfo,
|
|
10
|
-
} from "./types.js";
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Build device information for gateway connection
|
|
14
|
-
* This is the main function to generate device authentication data
|
|
15
|
-
*
|
|
16
|
-
* @param options - Device builder options
|
|
17
|
-
* @returns Device information object or undefined if no device identity provided
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```typescript
|
|
21
|
-
* const deviceInfo = buildDeviceInfo({
|
|
22
|
-
* deviceIdentity: loadOrCreateDeviceIdentity(),
|
|
23
|
-
* clientName: "my-client",
|
|
24
|
-
* role: "node",
|
|
25
|
-
* scopes: ["node.invoke"],
|
|
26
|
-
* nonce: "challenge-nonce",
|
|
27
|
-
* platform: "ios",
|
|
28
|
-
* deviceFamily: "iPhone"
|
|
29
|
-
* });
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
export function buildDeviceInfo(options: DeviceBuilderOptions): DeviceInfo | undefined {
|
|
33
|
-
const {
|
|
34
|
-
deviceIdentity,
|
|
35
|
-
clientName = GATEWAY_CLIENT_IDS.GATEWAY_CLIENT,
|
|
36
|
-
clientMode = GATEWAY_CLIENT_MODES.BACKEND,
|
|
37
|
-
role = "operator",
|
|
38
|
-
scopes = ["operator.admin"],
|
|
39
|
-
platform = process.platform,
|
|
40
|
-
deviceFamily,
|
|
41
|
-
authToken = null,
|
|
42
|
-
nonce,
|
|
43
|
-
signedAtMs = Date.now(),
|
|
44
|
-
} = options;
|
|
45
|
-
|
|
46
|
-
if (!deviceIdentity) {
|
|
47
|
-
return undefined;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Build authentication payload
|
|
51
|
-
const payload = buildDeviceAuthPayloadV3({
|
|
52
|
-
deviceId: deviceIdentity.deviceId,
|
|
53
|
-
clientId: clientName,
|
|
54
|
-
clientMode,
|
|
55
|
-
role,
|
|
56
|
-
scopes,
|
|
57
|
-
signedAtMs,
|
|
58
|
-
token: authToken,
|
|
59
|
-
nonce,
|
|
60
|
-
platform,
|
|
61
|
-
deviceFamily,
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
// Sign the payload
|
|
65
|
-
const signature = signDevicePayload(deviceIdentity.privateKeyPem, payload);
|
|
66
|
-
|
|
67
|
-
// Return device information
|
|
68
|
-
return {
|
|
69
|
-
id: deviceIdentity.deviceId,
|
|
70
|
-
publicKey: publicKeyRawBase64UrlFromPem(deviceIdentity.publicKeyPem),
|
|
71
|
-
signature,
|
|
72
|
-
signedAt: signedAtMs,
|
|
73
|
-
nonce,
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Build device information for node role
|
|
79
|
-
* Convenience function for node connections
|
|
80
|
-
*
|
|
81
|
-
* @param options - Device builder options
|
|
82
|
-
* @returns Device information object or undefined
|
|
83
|
-
*/
|
|
84
|
-
export function buildNodeDeviceInfo(options: Omit<DeviceBuilderOptions, "role">): DeviceInfo | undefined {
|
|
85
|
-
return buildDeviceInfo({
|
|
86
|
-
...options,
|
|
87
|
-
role: "node",
|
|
88
|
-
scopes: options.scopes ?? ["node.invoke"],
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Build device information for operator role
|
|
94
|
-
* Convenience function for operator connections
|
|
95
|
-
*
|
|
96
|
-
* @param options - Device builder options
|
|
97
|
-
* @returns Device information object or undefined
|
|
98
|
-
*/
|
|
99
|
-
export function buildOperatorDeviceInfo(options: Omit<DeviceBuilderOptions, "role">): DeviceInfo | undefined {
|
|
100
|
-
return buildDeviceInfo({
|
|
101
|
-
...options,
|
|
102
|
-
role: "operator",
|
|
103
|
-
scopes: options.scopes ?? ["operator.admin"],
|
|
104
|
-
});
|
|
105
|
-
}
|
|
1
|
+
import { GATEWAY_CLIENT_MODES, GATEWAY_CLIENT_IDS } from "../protocol/index.js";
|
|
2
|
+
import { buildDeviceAuthPayloadV3 } from "./auth.js";
|
|
3
|
+
import {
|
|
4
|
+
publicKeyRawBase64UrlFromPem,
|
|
5
|
+
signDevicePayload,
|
|
6
|
+
} from "./identity.js";
|
|
7
|
+
import {
|
|
8
|
+
type DeviceBuilderOptions,
|
|
9
|
+
type DeviceInfo,
|
|
10
|
+
} from "./types.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Build device information for gateway connection
|
|
14
|
+
* This is the main function to generate device authentication data
|
|
15
|
+
*
|
|
16
|
+
* @param options - Device builder options
|
|
17
|
+
* @returns Device information object or undefined if no device identity provided
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const deviceInfo = buildDeviceInfo({
|
|
22
|
+
* deviceIdentity: loadOrCreateDeviceIdentity(),
|
|
23
|
+
* clientName: "my-client",
|
|
24
|
+
* role: "node",
|
|
25
|
+
* scopes: ["node.invoke"],
|
|
26
|
+
* nonce: "challenge-nonce",
|
|
27
|
+
* platform: "ios",
|
|
28
|
+
* deviceFamily: "iPhone"
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export function buildDeviceInfo(options: DeviceBuilderOptions): DeviceInfo | undefined {
|
|
33
|
+
const {
|
|
34
|
+
deviceIdentity,
|
|
35
|
+
clientName = GATEWAY_CLIENT_IDS.GATEWAY_CLIENT,
|
|
36
|
+
clientMode = GATEWAY_CLIENT_MODES.BACKEND,
|
|
37
|
+
role = "operator",
|
|
38
|
+
scopes = ["operator.admin"],
|
|
39
|
+
platform = process.platform,
|
|
40
|
+
deviceFamily,
|
|
41
|
+
authToken = null,
|
|
42
|
+
nonce,
|
|
43
|
+
signedAtMs = Date.now(),
|
|
44
|
+
} = options;
|
|
45
|
+
|
|
46
|
+
if (!deviceIdentity) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Build authentication payload
|
|
51
|
+
const payload = buildDeviceAuthPayloadV3({
|
|
52
|
+
deviceId: deviceIdentity.deviceId,
|
|
53
|
+
clientId: clientName,
|
|
54
|
+
clientMode,
|
|
55
|
+
role,
|
|
56
|
+
scopes,
|
|
57
|
+
signedAtMs,
|
|
58
|
+
token: authToken,
|
|
59
|
+
nonce,
|
|
60
|
+
platform,
|
|
61
|
+
deviceFamily,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// Sign the payload
|
|
65
|
+
const signature = signDevicePayload(deviceIdentity.privateKeyPem, payload);
|
|
66
|
+
|
|
67
|
+
// Return device information
|
|
68
|
+
return {
|
|
69
|
+
id: deviceIdentity.deviceId,
|
|
70
|
+
publicKey: publicKeyRawBase64UrlFromPem(deviceIdentity.publicKeyPem),
|
|
71
|
+
signature,
|
|
72
|
+
signedAt: signedAtMs,
|
|
73
|
+
nonce,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Build device information for node role
|
|
79
|
+
* Convenience function for node connections
|
|
80
|
+
*
|
|
81
|
+
* @param options - Device builder options
|
|
82
|
+
* @returns Device information object or undefined
|
|
83
|
+
*/
|
|
84
|
+
export function buildNodeDeviceInfo(options: Omit<DeviceBuilderOptions, "role">): DeviceInfo | undefined {
|
|
85
|
+
return buildDeviceInfo({
|
|
86
|
+
...options,
|
|
87
|
+
role: "node",
|
|
88
|
+
scopes: options.scopes ?? ["node.invoke"],
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Build device information for operator role
|
|
94
|
+
* Convenience function for operator connections
|
|
95
|
+
*
|
|
96
|
+
* @param options - Device builder options
|
|
97
|
+
* @returns Device information object or undefined
|
|
98
|
+
*/
|
|
99
|
+
export function buildOperatorDeviceInfo(options: Omit<DeviceBuilderOptions, "role">): DeviceInfo | undefined {
|
|
100
|
+
return buildDeviceInfo({
|
|
101
|
+
...options,
|
|
102
|
+
role: "operator",
|
|
103
|
+
scopes: options.scopes ?? ["operator.admin"],
|
|
104
|
+
});
|
|
105
|
+
}
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Normalize device metadata for authentication payloads
|
|
3
|
-
* Keeps cross-runtime normalization deterministic (TS/Swift/Kotlin)
|
|
4
|
-
* by only lowercasing ASCII metadata fields used in auth payloads.
|
|
5
|
-
*/
|
|
6
|
-
function normalizeTrimmedMetadata(value?: string | null): string {
|
|
7
|
-
if (typeof value !== "string") {
|
|
8
|
-
return "";
|
|
9
|
-
}
|
|
10
|
-
const trimmed = value.trim();
|
|
11
|
-
return trimmed ? trimmed : "";
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function toLowerAscii(input: string): string {
|
|
15
|
-
return input.replace(/[A-Z]/g, (char) => String.fromCharCode(char.charCodeAt(0) + 32));
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function normalizeDeviceMetadataForAuth(value?: string | null): string {
|
|
19
|
-
const trimmed = normalizeTrimmedMetadata(value);
|
|
20
|
-
if (!trimmed) {
|
|
21
|
-
return "";
|
|
22
|
-
}
|
|
23
|
-
// Keep cross-runtime normalization deterministic (TS/Swift/Kotlin) by only
|
|
24
|
-
// lowercasing ASCII metadata fields used in auth payloads.
|
|
25
|
-
return toLowerAscii(trimmed);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Normalize device metadata for policy classification
|
|
30
|
-
* Collapses Unicode confusables to stable ASCII-like tokens before matching platform/family rules.
|
|
31
|
-
*/
|
|
32
|
-
export function normalizeDeviceMetadataForPolicy(value?: string | null): string {
|
|
33
|
-
const trimmed = normalizeTrimmedMetadata(value);
|
|
34
|
-
if (!trimmed) {
|
|
35
|
-
return "";
|
|
36
|
-
}
|
|
37
|
-
// Policy classification should collapse Unicode confusables to stable ASCII-ish
|
|
38
|
-
// tokens where possible before matching platform/family rules.
|
|
39
|
-
return trimmed.normalize("NFKD").replace(/\p{M}/gu, "").toLowerCase();
|
|
40
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Normalize device metadata for authentication payloads
|
|
3
|
+
* Keeps cross-runtime normalization deterministic (TS/Swift/Kotlin)
|
|
4
|
+
* by only lowercasing ASCII metadata fields used in auth payloads.
|
|
5
|
+
*/
|
|
6
|
+
function normalizeTrimmedMetadata(value?: string | null): string {
|
|
7
|
+
if (typeof value !== "string") {
|
|
8
|
+
return "";
|
|
9
|
+
}
|
|
10
|
+
const trimmed = value.trim();
|
|
11
|
+
return trimmed ? trimmed : "";
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function toLowerAscii(input: string): string {
|
|
15
|
+
return input.replace(/[A-Z]/g, (char) => String.fromCharCode(char.charCodeAt(0) + 32));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function normalizeDeviceMetadataForAuth(value?: string | null): string {
|
|
19
|
+
const trimmed = normalizeTrimmedMetadata(value);
|
|
20
|
+
if (!trimmed) {
|
|
21
|
+
return "";
|
|
22
|
+
}
|
|
23
|
+
// Keep cross-runtime normalization deterministic (TS/Swift/Kotlin) by only
|
|
24
|
+
// lowercasing ASCII metadata fields used in auth payloads.
|
|
25
|
+
return toLowerAscii(trimmed);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Normalize device metadata for policy classification
|
|
30
|
+
* Collapses Unicode confusables to stable ASCII-like tokens before matching platform/family rules.
|
|
31
|
+
*/
|
|
32
|
+
export function normalizeDeviceMetadataForPolicy(value?: string | null): string {
|
|
33
|
+
const trimmed = normalizeTrimmedMetadata(value);
|
|
34
|
+
if (!trimmed) {
|
|
35
|
+
return "";
|
|
36
|
+
}
|
|
37
|
+
// Policy classification should collapse Unicode confusables to stable ASCII-ish
|
|
38
|
+
// tokens where possible before matching platform/family rules.
|
|
39
|
+
return trimmed.normalize("NFKD").replace(/\p{M}/gu, "").toLowerCase();
|
|
40
|
+
}
|