UNPKG

@bsv/wallet-toolbox-client

Version:
80 lines 2.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.WABClient = void 0; const sdk_1 = require("@bsv/sdk"); class WABClient { constructor(serverUrl) { this.serverUrl = serverUrl; } /** * Return the WAB server info */ async getInfo() { const res = await fetch(`${this.serverUrl}/info`); return res.json(); } /** * Generate a random 256-bit presentation key as a hex string (client side). */ generateRandomPresentationKey() { return sdk_1.PrivateKey.fromRandom().toHex(); } /** * Start an Auth Method flow */ async startAuthMethod(authMethod, presentationKey, payload) { return authMethod.startAuth(this.serverUrl, presentationKey, payload); } /** * Complete an Auth Method flow */ async completeAuthMethod(authMethod, presentationKey, payload) { return authMethod.completeAuth(this.serverUrl, presentationKey, payload); } /** * List user-linked methods */ async listLinkedMethods(presentationKey) { const res = await fetch(`${this.serverUrl}/user/linkedMethods`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ presentationKey }) }); return res.json(); } /** * Unlink a given Auth Method by ID */ async unlinkMethod(presentationKey, authMethodId) { const res = await fetch(`${this.serverUrl}/user/unlinkMethod`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ presentationKey, authMethodId }) }); return res.json(); } /** * Request faucet */ async requestFaucet(presentationKey) { const res = await fetch(`${this.serverUrl}/faucet/request`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ presentationKey }) }); return res.json(); } /** * Delete user */ async deleteUser(presentationKey) { const res = await fetch(`${this.serverUrl}/user/delete`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ presentationKey }) }); return res.json(); } } exports.WABClient = WABClient; //# sourceMappingURL=WABClient.js.map