From 657d14213af7baa0752a3d24fde3bbc3a18a2cb0 Mon Sep 17 00:00:00 2001 From: Maycon Mello Date: Wed, 16 Aug 2023 07:54:52 -0300 Subject: [PATCH] verification flow --- packages/core/src/account-provider.ts | 2 +- packages/core/src/helpers.ts | 11 ++++ packages/core/src/v1-helpers.ts | 2 +- .../core/src/verification-provider.test.ts | 25 +++++++++ packages/core/src/verification-provider.ts | 51 +++++++++++++++++++ 5 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 packages/core/src/helpers.ts create mode 100644 packages/core/src/verification-provider.test.ts diff --git a/packages/core/src/account-provider.ts b/packages/core/src/account-provider.ts index 711c807b..27b524e4 100644 --- a/packages/core/src/account-provider.ts +++ b/packages/core/src/account-provider.ts @@ -12,7 +12,7 @@ export function createAccountProvider({wallet}: ICreateAccountsProvider) { walletService: toV1WalletService(wallet), }); - Accounts.instance = accountsModule; + (Accounts as any).instance = accountsModule; return accountsModule; } diff --git a/packages/core/src/helpers.ts b/packages/core/src/helpers.ts new file mode 100644 index 00000000..d9f1ad15 --- /dev/null +++ b/packages/core/src/helpers.ts @@ -0,0 +1,11 @@ +function isURL(str) { + try { + // eslint-disable-next-line no-new + new URL(str); + return true; + } catch (err) { + return false; + } +} + +export function getJSONOrUrl(data) {} diff --git a/packages/core/src/v1-helpers.ts b/packages/core/src/v1-helpers.ts index 69b83677..9034de76 100644 --- a/packages/core/src/v1-helpers.ts +++ b/packages/core/src/v1-helpers.ts @@ -66,7 +66,7 @@ export async function toV1Wallet(wallet: IWallet): Promise { ...wallet, }; - accounts.wallet = newWallet; + (accounts as any).wallet = newWallet; return newWallet; } diff --git a/packages/core/src/verification-provider.test.ts b/packages/core/src/verification-provider.test.ts new file mode 100644 index 00000000..7e40fb6e --- /dev/null +++ b/packages/core/src/verification-provider.test.ts @@ -0,0 +1,25 @@ +import {IWallet} from './types'; +import {createVerificationProvider} from './verification-provider'; +import {createWallet} from './wallet'; + +describe('Verification provider', () => { + let verificationProvider; + let wallet: IWallet; + + beforeAll(async () => { + wallet = await createWallet({ + databasePath: ':memory:', + }); + verificationProvider = createVerificationProvider({ + wallet, + }); + }); + + it('expect to create verification controller', () => { + const controller = verificationProvider.start({ + template: 'https://creds-testnet.dock.io/proof/6de279ba-caf3-4979-a067-553284b40767', + }); + + console.log(controller); + }); +}); diff --git a/packages/core/src/verification-provider.ts b/packages/core/src/verification-provider.ts index e69de29b..6f554a91 100644 --- a/packages/core/src/verification-provider.ts +++ b/packages/core/src/verification-provider.ts @@ -0,0 +1,51 @@ +export function createVerificationController({wallet}) { + let templateJSON = null; + let credentials = []; + let selectedCredentials = []; + let selectedAttributes = []; + let didKeyPair = null; + + function setTemplate(template) { + // TODO: fetch URL data + templateJSON = template; + } + + function loadCredentials() { + // get wallet credentials and apply pex filter + } + + function selectCredential(credentialId: string) { + + } + + function selectCredentialAttribute(credentialId: string, attributePath: string) { + + } + + function createPresentation() { + // for the given credential selection + // it will create a presentation + } + + return { + setTemplate, + loadCredentials, + selectCredential, + selectCredentialAttribute, + createPresentation, + }; +} + +export function createVerificationProvider({wallet}) { + return { + start: ({template}) => { + const controller = createVerificationController({ + wallet, + }); + + controller.setTemplate(template); + + return controller; + }, + }; +}