Function: toUint8Array()
toUint8Array(
value):Uint8Array
Defined in: auth/src/auth/shared.ts:618
Coerces a stored credential public key back into a Uint8Array.
StoredPasskeyCredential.publicKey is a Uint8Array when it's first produced by the
registration ceremony, but by the time it's read back here it's been round-tripped through
whatever the Secret datastore (and cache) uses to persist data, which doesn't preserve typed
arrays. Reconstruct a real Uint8Array from whichever shape it comes back as, so verification
always sees the actual key bytes:
- a
Uint8Array(including a NodeBuffer) — returned as is; - a BSON
Binary(MongoDB stores aUint8Arrayas one) — itsbufferholds the bytes, butpositionmarks how much of it is in use; - a base64 string (
Binary'stoJSON(), as written by a JSON-serialized cache); { type: "Buffer", data: number[] }(aBuffer'stoJSON());- a plain object keyed by numeric index (
{"0":1,"1":2,...}), which is what TypeORM'ssimple-jsoncolumn gives back for aUint8Array.
Passing any of the non-Uint8Array shapes on to @simplewebauthn/server unconverted (or, as this
once did for a Binary, converted wrongly) makes its CBOR/COSE key decoder read the wrong bytes and
fail with an opaque "No data" or "decodedPublicKey.get is not a function" error.
Parameters
value
unknown
Returns
Uint8Array