@revibase/ctap2-js
v0.1.1
Published
Passkeys over NFC directly
Readme
@revibase/ctap2-js
This library is for apps that want to talk to a physical FIDO2/passkey authenticator over NFC by sending APDUs directly.
License: MIT
Install
pnpm add @revibase/ctap2-jsOptional peer (for types): @simplewebauthn/browser
pnpm add @simplewebauthn/browserUsage
React Native
Use a library that can send NFC commands like react-native-nfc-manager with NfcTech.IsoDep.
import { authenticateWithNfc } from "@revibase/ctap2-js";
import NfcManager, { NfcTech } from "react-native-nfc-manager";
async function withIsoDep<T>(
fn: (tx: (apdu: Uint8Array) => Promise<Uint8Array>) => Promise<T>,
): Promise<T> {
const store = useNfcAuthPromptStore.getState();
await NfcManager.start();
if (Platform.OS === "android") {
store.setVisible(true);
store.setCancelSession(() => {
NfcManager.cancelTechnologyRequest().catch(() => {});
});
}
await NfcManager.requestTechnology(NfcTech.IsoDep, {
alertMessage: "Hold your security key near the phone",
});
const tx = async (apdu: Uint8Array) => {
return new Uint8Array(await NfcManager.isoDepHandler.transceive([...apdu]));
};
try {
return await fn(tx);
} finally {
if (Platform.OS === "android") {
store.setCancelSession(null);
}
await NfcManager.cancelTechnologyRequest().catch(() => {});
}
}
const request = {
origin: "your_origin",
crossOrigin: false,
rpId: "your_rp_id",
challenge: "random_challenge_in_base64_url",
};
await withIsoDep((tx) => authenticateWithNfc(request, tx));