Interface.ClientShareProvider
Represents a storage provider for the client share.
The purpose of ClientShareProvider
is to provide an interface that allows integrators
to save and restore the client share of their customers. The integrator has the
responsibility to securely store the client share.
Remarks
The client share is not considered sensitive data because only the client can use it, and its usage is secured by strong authentication between the client and the Keyban services.
Example Implementation
Below is a basic implementation of a CustomClientShareProvider
using a fetch-based provider:
class CustomClientShareProvider implements ClientShareProvider {
// Retrieves the client share data.
// @returns - A promise resolving to the client share string or `null` if unavailable.
async get(): Promise<string | null> {
try {
const response = await fetch("/api/clientShare", {
method: "GET",
headers: { "Content-Type": "application/json" },
});
if (!response.ok) {
console.error("Failed to fetch client share:", response.statusText);
return null;
}
return response.text();
} catch (error) {
console.error("Error retrieving client share:", error);
return null;
}
}
// Saves the client share data.
// @param clientShare - The client share string to store.
// @returns - A promise that resolves when the operation is complete.
async set(clientShare: string): Promise<void> {
try {
const response = await fetch("/api/clientShare", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ clientShare }),
});
if (!response.ok) {
throw new Error(`Failed to save client share: ${response.statusText}`);
}
} catch (error) {
console.error("Error saving client share:", error);
throw error;
}
}
}
This implementation assumes the existence of an API endpoint /api/clientShare
to manage the client share on the server side. The integrator should ensure that
the endpoint is appropriately secured.
Methods
get()
get(): Promise<null | string>
Retrieves the client share information.
Returns
Promise
<null
| string
>
- A promise that resolves to a string containing the client share, or null if not available.
set()
set(clientShare: string): Promise<unknown>
Sets the client share information.
Parameters
Parameter | Type | Description |
---|---|---|
clientShare | string | The client share string to set. |
Returns
Promise
<unknown
>
- A promise that resolves when the client share has been set.