-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
abe797f
commit 785b000
Showing
8 changed files
with
344 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {IWallet} from './types'; | ||
|
||
export interface ICredentialProvider { | ||
getCredentials(type?: string): any; | ||
} | ||
|
||
export function createCredentialProvider({wallet}: {wallet: IWallet}) { | ||
function getCredentials(type: string = 'VerifiableCredential') { | ||
return wallet.getDocumentsByType(type); | ||
} | ||
|
||
return { | ||
getCredentials, | ||
// TODO: move credential validity check to this provider | ||
// TODO: move import credential from json or URL to this provider | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"@context": [ | ||
"https://www.w3.org/2018/credentials/v1", | ||
{ | ||
"dk": "https://ld.dock.io/credentials#", | ||
"CustomerCredential": "dk:CustomerCredential", | ||
"name": "dk:name", | ||
"email": "dk:email", | ||
"dateOfBirth": "dk:dateOfBirth", | ||
"phone": "dk:phone", | ||
"description": "dk:description", | ||
"logo": "dk:logo" | ||
} | ||
], | ||
"id": "https://creds-testnet.dock.io/986dccbe32eb61a0abb9678fd51aca796caa3d9f72088f66d60c9495b3d71174", | ||
"type": ["VerifiableCredential", "CustomerCredential"], | ||
"credentialSubject": { | ||
"id": "did:key:z6MkoQzWru66w91EH7U9Xsv5eYXQabw9U3ZJd5GkatMWkmZT", | ||
"name": "Alice Doe", | ||
"email": "[email protected]", | ||
"dateOfBirth": "1990-01-01", | ||
"phone": "555-555-5555" | ||
}, | ||
"issuanceDate": "2023-08-09T13:16:08.991Z", | ||
"issuer": { | ||
"name": "Test123", | ||
"description": "", | ||
"logo": "", | ||
"id": "did:dock:5CgR1iELH33Qm8CN7LLXiEdTnrPTFKHgdxZgTuDwxgiyokjB" | ||
}, | ||
"name": "Customer Credential", | ||
"proof": { | ||
"type": "Ed25519Signature2018", | ||
"created": "2023-08-09T13:16:09Z", | ||
"verificationMethod": "did:dock:5CgR1iELH33Qm8CN7LLXiEdTnrPTFKHgdxZgTuDwxgiyokjB#keys-1", | ||
"proofPurpose": "assertionMethod", | ||
"jws": "eyJhbGciOiJFZERTQSIsImI2NCI6ZmFsc2UsImNyaXQiOlsiYjY0Il19..2NJhT4Kx8W-q0pws4y86zsWMDkFrXz6Sfb5XRrJO_aRhvzhDZLsbXqvtRzRgGIrJKCBvTEDNiKBCicKT9f8hDA" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,89 @@ | ||
import {IWallet} from './types'; | ||
import {createVerificationProvider} from './verification-provider'; | ||
import {createWallet} from './wallet'; | ||
import customerCredentialJSON from './fixtures/customer-credential.json'; | ||
|
||
describe('Verification provider', () => { | ||
let verificationProvider; | ||
let wallet: IWallet; | ||
const verificationTemplateJSON = { | ||
qr: 'https://creds-testnet.dock.io/proof/6de279ba-caf3-4979-a067-553284b40767', | ||
id: '6de279ba-caf3-4979-a067-553284b40767', | ||
name: 'Any credential', | ||
nonce: 'b75fab9a5006216173500bfd3df5d0c5', | ||
created: '2023-08-09T20:19:46.278Z', | ||
updated: '2023-08-09T20:19:46.278Z', | ||
verified: false, | ||
response_url: | ||
'https://api-testnet.dock.io/proof-requests/6de279ba-caf3-4979-a067-553284b40767/send-presentation', | ||
request: { | ||
id: '6de279ba-caf3-4979-a067-553284b40767', | ||
input_descriptors: [ | ||
{ | ||
id: 'Credential 1', | ||
name: 'Any credential', | ||
purpose: 'Any credential', | ||
constraints: { | ||
fields: [ | ||
{ | ||
path: ['$.id'], | ||
}, | ||
], | ||
}, | ||
}, | ||
], | ||
}, | ||
type: 'proof-request', | ||
}; | ||
|
||
beforeAll(async () => { | ||
wallet = await createWallet({ | ||
databasePath: ':memory:', | ||
}); | ||
|
||
await wallet.addDocument(customerCredentialJSON); | ||
|
||
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', | ||
it('expect to create verification controller and fetch template JSON', async () => { | ||
const controller = await verificationProvider.start({ | ||
template: | ||
'https://creds-testnet.dock.io/proof/6de279ba-caf3-4979-a067-553284b40767', | ||
}); | ||
|
||
expect(controller.getTemplateJSON()).toEqual(verificationTemplateJSON); | ||
}); | ||
|
||
it('expect to load credentials for a given template', async () => { | ||
const controller = await verificationProvider.start({ | ||
template: | ||
'https://creds-testnet.dock.io/proof/6de279ba-caf3-4979-a067-553284b40767', | ||
}); | ||
|
||
await controller.loadCredentials(); | ||
|
||
expect(controller.getFilteredCredentials()).toEqual([ | ||
customerCredentialJSON, | ||
]); | ||
}); | ||
|
||
it('expect to load credentials and generate presentation for a selected credential', async () => { | ||
const controller = await verificationProvider.start({ | ||
template: | ||
'https://creds-testnet.dock.io/proof/6de279ba-caf3-4979-a067-553284b40767', | ||
}); | ||
|
||
console.log(controller); | ||
await controller.loadCredentials(); | ||
const credentials = controller.getFilteredCredentials(); | ||
|
||
// select the first credential in the filtered list | ||
controller.setSelectedCredentialIds([credentials[0].id]); | ||
|
||
const presentation = await controller.createPresentation(); | ||
|
||
expect(presentation).toEqual([]); | ||
}); | ||
}); |
Oops, something went wrong.