From 2c5dc3e27833050f667053b6a8a6c2428672cd11 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Mon, 28 Sep 2026 01:00:52 +0200 Subject: [PATCH] Decode Idunn identity byte vectors --- packages/cultnet-ts/src/idunn-runtime-authority.ts | 13 ++++++++++--- .../cultnet-ts/test/idunn-runtime-authority.test.ts | 4 ++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/cultnet-ts/src/idunn-runtime-authority.ts b/packages/cultnet-ts/src/idunn-runtime-authority.ts index c6f82c27..e01be597 100644 --- a/packages/cultnet-ts/src/idunn-runtime-authority.ts +++ b/packages/cultnet-ts/src/idunn-runtime-authority.ts @@ -547,10 +547,10 @@ function openProviderHealthIdentity(credentialBytes: Buffer): crypto.KeyObject { const [schema, identityId, publicKeyValue, protectedSeedValue, protectorKind, binding, version, assurance, createdAt, enrollmentNonceValue] = fields; if (schema !== "gamecult.provider_health_identity.private.v1" || version !== "v1") throw new Error("Provider-health identity schema is unsupported."); string(createdAt, "Provider-health identity creation time"); - const enrollmentNonce = bytes(enrollmentNonceValue, "Provider-health enrollment nonce"); + const enrollmentNonce = providerIdentityByteVector(enrollmentNonceValue, "Provider-health enrollment nonce"); if (enrollmentNonce.length !== 32) throw new Error("Provider-health enrollment nonce has an invalid length."); - const publicKey = bytesValue(publicKeyValue, "Provider-health public key"); - const protectedSeed = bytesValue(protectedSeedValue, "Provider-health protected seed"); + const publicKey = Buffer.from(providerIdentityByteVector(publicKeyValue, "Provider-health public key")); + const protectedSeed = Buffer.from(providerIdentityByteVector(protectedSeedValue, "Provider-health protected seed")); const machineId = fs.readFileSync("/etc/machine-id", "utf8").trim(); if (!machineId) throw new Error("Linux machine-id is unavailable for provider-health identity."); const expectedBinding = `${PROVIDER_PROTECTOR_CONTEXT}:machine-id-sha256:${sha256Hex(Buffer.from(machineId))}`; @@ -587,6 +587,13 @@ function readProviderHealthIdentityCredential(bytes: Buffer): Uint8Array { return bytesValue(envelope[2], "Provider-health identity payload"); } +function providerIdentityByteVector(value: unknown, label: string): Uint8Array { + if (!Array.isArray(value) || value.some((byte) => typeof byte !== "number" || !Number.isInteger(byte) || byte < 0 || byte > 255)) { + throw new Error(`${label} is not a byte vector.`); + } + return Uint8Array.from(value as number[]); +} + function readAuthorityRecordBytes(bytes: Buffer, type: string, schemaId: string): Uint8Array { const decoded = decode(bytes); if (!Array.isArray(decoded) || decoded[0] !== CULTCACHE_STORE_FORMAT || !Array.isArray(decoded[1]) || !Array.isArray(decoded[2])) { diff --git a/packages/cultnet-ts/test/idunn-runtime-authority.test.ts b/packages/cultnet-ts/test/idunn-runtime-authority.test.ts index 1ffeb2ba..4b7b4865 100644 --- a/packages/cultnet-ts/test/idunn-runtime-authority.test.ts +++ b/packages/cultnet-ts/test/idunn-runtime-authority.test.ts @@ -82,9 +82,9 @@ test("opens Idunn's machine-bound identity and signs the exact Expected incarnat "gamecult-provider-health-identity", "gamecult.provider_health_identity.private.v1", Buffer.from(encode([ - "gamecult.provider_health_identity.private.v1", providerIdentity, providerPublic, protectedSeed, + "gamecult.provider_health_identity.private.v1", providerIdentity, Array.from(providerPublic), Array.from(protectedSeed), "linux_file_mode_machine_id_binding", binding, "v1", "os_installation_file_bound_cloneable_baseline", - "2026-01-01T00:00:00Z", new Uint8Array(32).fill(0x2a), + "2026-01-01T00:00:00Z", Array(32).fill(0x2a), ])), "2026-01-01T00:00:00Z", "gamecult.provider_health_identity.private.v1",