UNPKG

@bsv/wallet-toolbox-client

Version:
69 lines 2.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TwilioPhoneInteractor = void 0; const AuthMethodInteractor_1 = require("./AuthMethodInteractor"); /** * TwilioPhoneInteractor * * A client-side class that knows how to call the WAB server for Twilio-based phone verification. */ class TwilioPhoneInteractor extends AuthMethodInteractor_1.AuthMethodInteractor { constructor() { super(...arguments); this.methodType = 'TwilioPhone'; } /** * Start the Twilio phone verification on the server. * - The server will send an SMS code to the user’s phone, using Twilio Verify. * @param serverUrl - The base URL of the WAB server (e.g. http://localhost:3000) * @param presentationKey - The 256-bit key the client is attempting to authenticate with * @param payload - { phoneNumber: string } (the phone number to verify) * @returns - { success, message, data } */ async startAuth(serverUrl, presentationKey, payload) { const res = await fetch(`${serverUrl}/auth/start`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ methodType: this.methodType, presentationKey, payload }) }); if (!res.ok) { return { success: false, message: `HTTP error ${res.status}` }; } return res.json(); } /** * Complete the Twilio phone verification on the server. * - The server will verify the code with Twilio Verify’s verificationChecks endpoint. * @param serverUrl - The base URL of the WAB server * @param presentationKey - The 256-bit key * @param payload - { phoneNumber: string, otp: string } (the code that was received via SMS) * @returns - { success, message, presentationKey } */ async completeAuth(serverUrl, presentationKey, payload) { const res = await fetch(`${serverUrl}/auth/complete`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ methodType: this.methodType, presentationKey, payload }) }); if (!res.ok) { return { success: false, message: `HTTP error ${res.status}` }; } return res.json(); } } exports.TwilioPhoneInteractor = TwilioPhoneInteractor; //# sourceMappingURL=TwilioPhoneInteractor.js.map