import { http, HttpResponse } from "msw"; import { setupServer } from "msw/node"; import { CredentialCreationOptionsRequest, PasskeyAuthenticate, RegistrationResponseJSON, State, } from "../types"; export const handlers = [ http.post( "https://api.opensocial.co/v2/webauthn/register/verify", async ({ request }) => { const registration = (await request.json()) as RegistrationResponseJSON & { walletId: string; walletPassword: string; }; return HttpResponse.json({ ...registration, success: true, code: 200, msg: 'success' }); } ), // step1 generate options and challenge http.post( "https://api.opensocial.co/v2/webauthn/register/generate-options", async ({ request }) => { const creationRequest = (await request.json()) as CredentialCreationOptionsRequest; //const registrationOption = await generateRegistrationOptions(prepareRegistrationOptions({rpName: "osp", rpId: "login.osp.co"}, creationRequest.displayName)); // save the challenge to db return HttpResponse.json({code: 200, msg: 'success', data: { challenge: "1PhpJ7wtbGsveE3hWSLQOChYSpVntvR9Bm4-h9MGRKk", rp: { name: "WebAuthn Demo", id: "localhost", }, user: { id: "ljXgfUebLTgv4HTjklLUFeLG51555w9MJondeZNG60Y", name: "hao.holly@gmail.com", displayName: "Lei HAO", }, pubKeyCredParams: [ { alg: -8, type: "public-key", }, { alg: -7, type: "public-key", }, { alg: -257, type: "public-key", }, ], timeout: 300000, attestation: "none", excludeCredentials: [], authenticatorSelection: {}, extensions: { credProps: true, }, }}); } ), // step2 verify http.get( "https://api.opensocial.co/v2/webauthn/authenticate/generate-options", async ({ request }) => { // should also set up the challenge in the session return HttpResponse.json({code: 200, msg: 'success', data: { rpId: "try-webauthn.appspot.com", challenge: "8WxiouuEoZBfMrFeCWY2p39XcJyoQfFakOEVE88j24c", timeout: 300000, userVerification: "preferred", extensions: {}, }}); } ), http.post( "https://api.opensocial.co/v2/webauthn/authenticate/verify", async ({ request }) => { // should also verify the challenge in the session return HttpResponse.json({code: 200, msg: 'success', data: { success: true, password: globalThis.passwd, // after verification return the password to client authenticatorAttachment: "undefined", aaguid: "01020304-0506-0708-0102-030405060708", os: "OS X", user_verifying: true, registered: 1725435858025, counter: 2, platform: "Apple Mac", transports: ["internal"], credentialBackedUp: false, user_id: "RIjrLPkLZJW8va7f5im2U5dkGqL2", browser: "Chrome", credentialID: "MMHjh_KhgG4ToxY81JBYRGiulXI_p5JbyjW9z5IfMXk", credentialPublicKey: "pAEBAycgBiFYIAnvJqNiUog6V2QKvaFQ9n6D7QX-UBvf6_lVPCa7HDoR", credentialDeviceType: "singleDevice", clientExtensionResults: { credProps: { rk: false, }, }, last_used: 1725435926909, }}); } ), ];