Skip to main content

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 Node Buffer) — returned as is;
  • a BSON Binary (MongoDB stores a Uint8Array as one) — its buffer holds the bytes, but position marks how much of it is in use;
  • a base64 string (Binary's toJSON(), as written by a JSON-serialized cache);
  • { type: "Buffer", data: number[] } (a Buffer's toJSON());
  • a plain object keyed by numeric index ({"0":1,"1":2,...}), which is what TypeORM's simple-json column gives back for a Uint8Array.

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