fix: convert strings to Uint8Array for @noble/hashes v2
@noble/hashes v2 no longer accepts strings directly, only Uint8Array. Added utf8() helper to encode strings before hashing. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
d01c37522f
commit
53376fe5b0
3 changed files with 11 additions and 5 deletions
|
|
@ -10,8 +10,10 @@ import { bytesToHex as toHex } from "@noble/hashes/utils.js"
|
||||||
// HELPERS
|
// HELPERS
|
||||||
// ============================================
|
// ============================================
|
||||||
|
|
||||||
|
const utf8 = (s: string) => new TextEncoder().encode(s)
|
||||||
|
|
||||||
function hashToken(token: string) {
|
function hashToken(token: string) {
|
||||||
return toHex(sha256(token))
|
return toHex(sha256(utf8(token)))
|
||||||
}
|
}
|
||||||
|
|
||||||
async function validateMachineToken(
|
async function validateMachineToken(
|
||||||
|
|
|
||||||
|
|
@ -92,6 +92,8 @@ function toHex(input: Uint8Array) {
|
||||||
.join("")
|
.join("")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const utf8 = (s: string) => new TextEncoder().encode(s)
|
||||||
|
|
||||||
function computeFingerprint(tenantId: string, companySlug: string | undefined, hostname: string, ids: NormalizedIdentifiers) {
|
function computeFingerprint(tenantId: string, companySlug: string | undefined, hostname: string, ids: NormalizedIdentifiers) {
|
||||||
const payload = JSON.stringify({
|
const payload = JSON.stringify({
|
||||||
tenantId,
|
tenantId,
|
||||||
|
|
@ -100,7 +102,7 @@ function computeFingerprint(tenantId: string, companySlug: string | undefined, h
|
||||||
macs: ids.macs,
|
macs: ids.macs,
|
||||||
serials: ids.serials,
|
serials: ids.serials,
|
||||||
})
|
})
|
||||||
return toHex(sha256(payload))
|
return toHex(sha256(utf8(payload)))
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateManualFingerprint(tenantId: string, displayName: string) {
|
function generateManualFingerprint(tenantId: string, displayName: string) {
|
||||||
|
|
@ -110,7 +112,7 @@ function generateManualFingerprint(tenantId: string, displayName: string) {
|
||||||
nonce: toHex(randomBytes(16)),
|
nonce: toHex(randomBytes(16)),
|
||||||
createdAt: Date.now(),
|
createdAt: Date.now(),
|
||||||
})
|
})
|
||||||
return toHex(sha256(payload))
|
return toHex(sha256(utf8(payload)))
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatDeviceCustomFieldDisplay(
|
function formatDeviceCustomFieldDisplay(
|
||||||
|
|
@ -180,7 +182,7 @@ function matchesExistingHardware(existing: Doc<"machines">, identifiers: Normali
|
||||||
}
|
}
|
||||||
|
|
||||||
function hashToken(token: string) {
|
function hashToken(token: string) {
|
||||||
return toHex(sha256(token))
|
return toHex(sha256(utf8(token)))
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRemoteAccessTokenGraceMs() {
|
function getRemoteAccessTokenGraceMs() {
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,10 @@ function toHex(input: Uint8Array) {
|
||||||
.join("")
|
.join("")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const utf8 = (s: string) => new TextEncoder().encode(s)
|
||||||
|
|
||||||
function hashToken(token: string) {
|
function hashToken(token: string) {
|
||||||
return toHex(sha256(token))
|
return toHex(sha256(utf8(token)))
|
||||||
}
|
}
|
||||||
|
|
||||||
export const USB_POLICY_VALUES = ["ALLOW", "BLOCK_ALL", "READONLY"] as const
|
export const USB_POLICY_VALUES = ["ALLOW", "BLOCK_ALL", "READONLY"] as const
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue