From bcb5283c42fa4f8e4b837b04a5962a3da97fc8d4 Mon Sep 17 00:00:00 2001 From: Hunain Bin Sajid Date: Wed, 26 Jun 2024 18:06:36 +0500 Subject: [PATCH] feat: add authorizeaid and authorizecred methods (#15) --- examples/web-react/src/App.tsx | 2 +- src/client.ts | 57 +++++++++++++++++++++++++++------- 2 files changed, 47 insertions(+), 12 deletions(-) diff --git a/examples/web-react/src/App.tsx b/examples/web-react/src/App.tsx index ad3853a..7166ff3 100644 --- a/examples/web-react/src/App.tsx +++ b/examples/web-react/src/App.tsx @@ -54,7 +54,7 @@ export function App() {

Request login

diff --git a/src/client.ts b/src/client.ts index 42c8347..72a865e 100644 --- a/src/client.ts +++ b/src/client.ts @@ -102,7 +102,7 @@ export interface ConfigureVendorArgs { /** * The vendor url */ - vendorUrl: string; + url: string; } export interface MessageData { @@ -251,19 +251,54 @@ export class ExtensionClient { }; /** - * Configures the extension with the specified vendor. + * Sends a /signify/authorize message to the extension. + * + * The extension should prompt the user to select a identifier, + * on success, it should send a /signify/reply message back to the browser page. + * + * This method is used to start an authorized "session" with the extension. Depending + * on the implemention, the extension can start to allow "signRequest" messages + * after a successful authorization. + * + * @param payload The arguments to pass to the extension. + * @returns {AuthorizeResult} + */ + authorizeAid = async (payload?: AuthorizeArgs): Promise => { + return this.sendMessage("/signify/authorize/aid", { payload }); + }; + + /** + * Sends a /signify/authorize message to the extension. + * + * The extension should prompt the user to select a credential, + * on success, it should send a /signify/reply message back to the browser page. + * + * This method is used to start an authorized "session" with the extension. Depending + * on the implemention, the extension can start to allow "signRequest" messages + * after a successful authorization. * + * @param payload The arguments to pass to the extension. + * @returns {AuthorizeResult} + */ + authorizeCred = async (payload?: AuthorizeArgs): Promise => { + return this.sendMessage("/signify/authorize/credential", { payload }); + }; + + /** + * Configures the extension with the specified vendor. * @param payload The vendor configuration + * @summary Tries to set the vendor url in the extension to load vendor supplied info e.g theme, logo etc. + * @example + * ```ts + * await signifyClient.provideConfigUrl({url: "https://api.npoint.io/52639f849bb31823a8c0"}); + * ``` + * @remarks + * This function is used to set the vendor url in the extension. The extension will fetch the vendor supplied info from the vendor url in json format. + * + * @see Template for [Vendor Loaded JSON](https://api.npoint.io/52639f849bb31823a8c0) */ configureVendor = async (payload?: ConfigureVendorArgs): Promise => { - window.postMessage( - { - type: "vendor-info", - subtype: "attempt-set-vendor-url", - data: payload, - }, - this.options.targetOrigin ?? "/", - ); + return this.sendMessage("/signify/configure-vendor", { payload }); }; /** @@ -299,7 +334,7 @@ export class ExtensionClient { }); }); - window.postMessage({ requestId, type, ...payload }, this.options.targetOrigin ?? "/"); + window.postMessage({ requestId, type, ...(payload ?? {}) }, this.options.targetOrigin ?? "/"); return promise; };