Skip to content

Commit bcb5283

Browse files
authored
feat: add authorizeaid and authorizecred methods (#15)
1 parent 1ca8aab commit bcb5283

File tree

2 files changed

+47
-12
lines changed

2 files changed

+47
-12
lines changed

examples/web-react/src/App.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export function App() {
5454
<h1>Request login</h1>
5555
<form id="login-form" onSubmit={handleAuthorize}>
5656
<button type="submit" disabled={pending}>
57-
Request Credential
57+
Request AID or Credential
5858
</button>
5959
</form>
6060
</section>

src/client.ts

+46-11
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export interface ConfigureVendorArgs {
102102
/**
103103
* The vendor url
104104
*/
105-
vendorUrl: string;
105+
url: string;
106106
}
107107

108108
export interface MessageData<T = unknown> {
@@ -251,19 +251,54 @@ export class ExtensionClient {
251251
};
252252

253253
/**
254-
* Configures the extension with the specified vendor.
254+
* Sends a /signify/authorize message to the extension.
255+
*
256+
* The extension should prompt the user to select a identifier,
257+
* on success, it should send a /signify/reply message back to the browser page.
258+
*
259+
* This method is used to start an authorized "session" with the extension. Depending
260+
* on the implemention, the extension can start to allow "signRequest" messages
261+
* after a successful authorization.
262+
*
263+
* @param payload The arguments to pass to the extension.
264+
* @returns {AuthorizeResult}
265+
*/
266+
authorizeAid = async (payload?: AuthorizeArgs): Promise<AuthorizeResult> => {
267+
return this.sendMessage("/signify/authorize/aid", { payload });
268+
};
269+
270+
/**
271+
* Sends a /signify/authorize message to the extension.
272+
*
273+
* The extension should prompt the user to select a credential,
274+
* on success, it should send a /signify/reply message back to the browser page.
275+
*
276+
* This method is used to start an authorized "session" with the extension. Depending
277+
* on the implemention, the extension can start to allow "signRequest" messages
278+
* after a successful authorization.
255279
*
280+
* @param payload The arguments to pass to the extension.
281+
* @returns {AuthorizeResult}
282+
*/
283+
authorizeCred = async (payload?: AuthorizeArgs): Promise<AuthorizeResult> => {
284+
return this.sendMessage("/signify/authorize/credential", { payload });
285+
};
286+
287+
/**
288+
* Configures the extension with the specified vendor.
256289
* @param payload The vendor configuration
290+
* @summary Tries to set the vendor url in the extension to load vendor supplied info e.g theme, logo etc.
291+
* @example
292+
* ```ts
293+
* await signifyClient.provideConfigUrl({url: "https://api.npoint.io/52639f849bb31823a8c0"});
294+
* ```
295+
* @remarks
296+
* 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.
297+
*
298+
* @see Template for [Vendor Loaded JSON](https://api.npoint.io/52639f849bb31823a8c0)
257299
*/
258300
configureVendor = async (payload?: ConfigureVendorArgs): Promise<void> => {
259-
window.postMessage(
260-
{
261-
type: "vendor-info",
262-
subtype: "attempt-set-vendor-url",
263-
data: payload,
264-
},
265-
this.options.targetOrigin ?? "/",
266-
);
301+
return this.sendMessage("/signify/configure-vendor", { payload });
267302
};
268303

269304
/**
@@ -299,7 +334,7 @@ export class ExtensionClient {
299334
});
300335
});
301336

302-
window.postMessage({ requestId, type, ...payload }, this.options.targetOrigin ?? "/");
337+
window.postMessage({ requestId, type, ...(payload ?? {}) }, this.options.targetOrigin ?? "/");
303338

304339
return promise;
305340
};

0 commit comments

Comments
 (0)