mirror of https://github.com/openclaw/openclaw.git
55 lines
1.3 KiB
TypeScript
55 lines
1.3 KiB
TypeScript
import { normalizeDeviceMetadataForAuth } from "./device-metadata-normalization.js";
|
|
export { normalizeDeviceMetadataForAuth };
|
|
|
|
export type DeviceAuthPayloadParams = {
|
|
deviceId: string;
|
|
clientId: string;
|
|
clientMode: string;
|
|
role: string;
|
|
scopes: string[];
|
|
signedAtMs: number;
|
|
token?: string | null;
|
|
nonce: string;
|
|
};
|
|
|
|
export type DeviceAuthPayloadV3Params = DeviceAuthPayloadParams & {
|
|
platform?: string | null;
|
|
deviceFamily?: string | null;
|
|
};
|
|
|
|
export function buildDeviceAuthPayload(params: DeviceAuthPayloadParams): string {
|
|
const scopes = params.scopes.join(",");
|
|
const token = params.token ?? "";
|
|
return [
|
|
"v2",
|
|
params.deviceId,
|
|
params.clientId,
|
|
params.clientMode,
|
|
params.role,
|
|
scopes,
|
|
String(params.signedAtMs),
|
|
token,
|
|
params.nonce,
|
|
].join("|");
|
|
}
|
|
|
|
export function buildDeviceAuthPayloadV3(params: DeviceAuthPayloadV3Params): string {
|
|
const scopes = params.scopes.join(",");
|
|
const token = params.token ?? "";
|
|
const platform = normalizeDeviceMetadataForAuth(params.platform);
|
|
const deviceFamily = normalizeDeviceMetadataForAuth(params.deviceFamily);
|
|
return [
|
|
"v3",
|
|
params.deviceId,
|
|
params.clientId,
|
|
params.clientMode,
|
|
params.role,
|
|
scopes,
|
|
String(params.signedAtMs),
|
|
token,
|
|
params.nonce,
|
|
platform,
|
|
deviceFamily,
|
|
].join("|");
|
|
}
|