UNPKG

@bsv/wallet-toolbox-client

Version:
70 lines 2.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DevConsoleInteractor = void 0; const AuthMethodInteractor_1 = require("./AuthMethodInteractor"); /** * DevConsoleInteractor * * A client-side class that knows how to call the WAB server for DevConsole-based authentication. * This is a development-only auth method that generates OTP codes and logs them to the console. */ class DevConsoleInteractor extends AuthMethodInteractor_1.AuthMethodInteractor { constructor() { super(...arguments); this.methodType = 'DevConsole'; } /** * Start the DevConsole authentication on the server. * - The server will generate an OTP code and log it to the console for development use. * @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 } (identifier for the authentication) * @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 DevConsole authentication on the server. * - The server will verify the OTP code that was generated and logged to the console. * @param serverUrl - The base URL of the WAB server * @param presentationKey - The 256-bit key * @param payload - { phoneNumber: string, otp: string } (the identifier and OTP code from console) * @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.DevConsoleInteractor = DevConsoleInteractor; //# sourceMappingURL=DevConsoleInteractor.js.map