From 18b37c56338358d262ea73bc02e3bdac28551c2f Mon Sep 17 00:00:00 2001 From: Hunain Bin Sajid Date: Mon, 8 Apr 2024 19:56:17 +0500 Subject: [PATCH 1/2] docs: add ISignature type --- GETTING_STARTED_WEB_CLI.md | 10 +++++++--- src/components/credentialCard.tsx | 21 +++++---------------- src/config/types.ts | 23 ++++++++++++++--------- 3 files changed, 26 insertions(+), 28 deletions(-) diff --git a/GETTING_STARTED_WEB_CLI.md b/GETTING_STARTED_WEB_CLI.md index 7d8cd243..902e71e1 100644 --- a/GETTING_STARTED_WEB_CLI.md +++ b/GETTING_STARTED_WEB_CLI.md @@ -12,7 +12,7 @@ ``` ### Usage -import following methods from `polaris-web` +import following methods from `signify-polaris-web` ``` import { @@ -22,14 +22,14 @@ import { requestCredential, // call to select credential for signing in requestAidORCred, // call to select either aid of credential requestAutoSignin, // call for auto signin -} from "polaris-web"; +} from "signify-polaris-web"; ``` ### Usage subscribeToSignature `subscribeToSignature` is a mandatory subscription call that receives a function to return signature, e.g: ``` -const handleSignifyData = (data) => { +const handleSignifyData = (data: ISignature) => { console.log("signature", data); }; @@ -41,6 +41,10 @@ useEffect(() => { }, []); ``` +#### [ISignature](./src/config/types.ts) data type +The callback from **subscribeToSignature** receives signature that contains header and credential(optional) + + ### Usage unsubscribeFromSignature `unsubscribeFromSignature` to unsubscription e.g: ``` diff --git a/src/components/credentialCard.tsx b/src/components/credentialCard.tsx index 16df803a..be6c4a38 100644 --- a/src/components/credentialCard.tsx +++ b/src/components/credentialCard.tsx @@ -1,26 +1,15 @@ import { useIntl } from "react-intl"; +import { ICredential } from "@config/types"; import { Text, Subtext, Card, Flex, Box } from "@components/ui"; import CredentialIcon from "@components/shared/icons/credential"; import ValidIcon from "@components/shared/icons/valid"; import RevokedIcon from "@components/shared/icons/revoked"; -interface ICredential { - issueeName: string; - schema: { - title: string; - credentialType: string; - description: string; - }; - status: { - et: string; - }; -} - -interface ICredentialCard { +export function CredentialCard({ + credential, +}: { credential: ICredential; -} - -export function CredentialCard({ credential }: ICredentialCard): JSX.Element { +}): JSX.Element { const { formatMessage } = useIntl(); return ( diff --git a/src/config/types.ts b/src/config/types.ts index f1c480ae..436837b6 100644 --- a/src/config/types.ts +++ b/src/config/types.ts @@ -7,7 +7,6 @@ export interface IHandler { tabId?: number; url?: string; data?: any; - } export interface IMessage { type: string; @@ -47,13 +46,7 @@ export interface ISignin { name?: string; prefix?: string; }; - credential?: { - issueeName?: string; - sad: { d: string }; - schema?: { - title: string; - }; - }; + credential?: ICredential; createdAt: number; updatedAt: number; autoSignin?: boolean; @@ -66,7 +59,8 @@ export interface IIdentifier { export interface ICredential { issueeName: string; - sad: { a: { i: string }, d: string }; + ancatc: string[]; + sad: { a: { i: string }; d: string }; schema: { title: string; credentialType: string; @@ -76,3 +70,14 @@ export interface ICredential { et: string; }; } + +export interface ISignature { + headers: { + origin: string; + signature: string; + "signature-input": string; + "signify-resource": string; + "signify-timestamp": string; + }; + credential?: ICredential; +} From 4ba07a5f858eb9315275c35cb5a27743580bd6c3 Mon Sep 17 00:00:00 2001 From: Hunain Bin Sajid Date: Mon, 8 Apr 2024 20:02:40 +0500 Subject: [PATCH 2/2] fix: add generic type for headers in iSignature --- src/config/types.ts | 6 +----- src/pages/background/services/signify.ts | 14 ++++++++++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/config/types.ts b/src/config/types.ts index 436837b6..603eaa5e 100644 --- a/src/config/types.ts +++ b/src/config/types.ts @@ -73,11 +73,7 @@ export interface ICredential { export interface ISignature { headers: { - origin: string; - signature: string; - "signature-input": string; - "signify-resource": string; - "signify-timestamp": string; + [key: string]: string; }; credential?: ICredential; } diff --git a/src/pages/background/services/signify.ts b/src/pages/background/services/signify.ts index 7cc937b5..0ed07fe7 100644 --- a/src/pages/background/services/signify.ts +++ b/src/pages/background/services/signify.ts @@ -8,7 +8,7 @@ import { import { userService } from "@pages/background/services/user"; import { configService } from "@pages/background/services/config"; import { removeSlash } from "@pages/background/utils"; -import { IIdentifier, ISignin } from "@config/types"; +import { IIdentifier, ISignin, ISignature } from "@config/types"; const PASSCODE_TIMEOUT = 5; @@ -169,7 +169,13 @@ const Signify = () => { return signed_headers; }; - const getSignedHeaders = async ({ url, signin } : { url: string, signin: ISignin }) => { + const getSignedHeaders = async ({ + url, + signin, + }: { + url: string; + signin: ISignin; + }): Promise => { const origin = removeSlash(url!); const signedHeaders = await signHeaders( signin.identifier @@ -184,7 +190,7 @@ const Signify = () => { return { headers: jsonHeaders, - credential: signin?.credential ?? null, + credential: signin?.credential, }; }; @@ -210,7 +216,7 @@ const Signify = () => { generatePasscode, bootAndConnect, getControllerID, - getSignedHeaders + getSignedHeaders, }; };