Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions packages/delegation-toolkit/src/webAuthn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
encodePacked,
keccak256,
concat,
hexToBytes,
} from 'viem';
import { parseSignature } from 'webauthn-p256';

Expand Down Expand Up @@ -37,7 +38,7 @@ export const splitOnChallenge = (
"challenge": "{userOpHash}",
"origin": "{Domain}",
"crossOrigin": boolean
}
}
*/
try {
const { challenge } = JSON.parse(clientDataJson);
Expand Down Expand Up @@ -146,14 +147,12 @@ export type AuthenticatorFlags = {
export function parseAuthenticatorFlags(
authenticatorData: Hex,
): AuthenticatorFlags {
// eslint-disable-next-line no-restricted-globals
const authenticatorDataBuffer = Buffer.from(
authenticatorData.slice(2),
'hex',
);
const flags = authenticatorDataBuffer.readUInt8(
AUTHENTICATOR_DATA_FLAGS_OFFSET,
);
const authenticatorDataBuffer = hexToBytes(authenticatorData);
const dataBufferUint8 = new Uint8Array(authenticatorDataBuffer);
const flags = dataBufferUint8[AUTHENTICATOR_DATA_FLAGS_OFFSET];
if (flags === undefined) {
throw new Error('Authenticator flags not found in authenticator data');
}

// Bit 0 is the least significant bit in the flags byte, so we left shift 0b1 by the bit index
// eslint-disable-next-line no-bitwise
Expand Down
7 changes: 7 additions & 0 deletions packages/delegation-toolkit/test/webAuthn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,5 +283,12 @@ describe('webAuthn', () => {

expect(userVerified).to.equal(false);
});
it('should throw an error if the authenticator flags are not found at the expected offset', () => {
const flags = 0b11111011;

expect(() => parseAuthenticatorFlags(toHex(flags))).to.throw(
'Authenticator flags not found in authenticator data',
);
});
});
});
Loading