@bifold/verifier 2.4.6 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,13 +1,12 @@
1
1
  {
2
2
  "name": "@bifold/verifier",
3
- "version": "2.4.6",
3
+ "version": "2.5.0",
4
4
  "main": "build/commonjs/index.js",
5
5
  "types": "build/typescript/index.d.ts",
6
6
  "module": "build/module/index.js",
7
7
  "source": "src/index.ts",
8
8
  "react-native": "src/index.ts",
9
9
  "files": [
10
- "src",
11
10
  "build"
12
11
  ],
13
12
  "repository": {
package/src/README.md DELETED
@@ -1,4 +0,0 @@
1
- ## Verifier Module
2
-
3
- This folder contains set of helpers, type definitions, and constants allowing to add verifier capability into Aries Mobile Agent React Native.
4
- The folder is created to encourage the upcoming split of the project into sub packages.
@@ -1,72 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`Helpers Build anoncreds proof request from template containing two requested attributes 1`] = `
4
- Object {
5
- "anoncreds": Object {
6
- "name": "Student full name",
7
- "nonce": "1677766511505",
8
- "requested_attributes": Object {
9
- "referent_0": Object {
10
- "name": "student_first_name",
11
- "names": undefined,
12
- "non_revoked": undefined,
13
- "restrictions": Array [
14
- Object {
15
- "cred_def_id": "XUxBrVSALWHLeycAUhrNr9:3:CL:26293:student_card",
16
- },
17
- ],
18
- },
19
- "referent_1": Object {
20
- "name": "student_last_name",
21
- "names": undefined,
22
- "non_revoked": undefined,
23
- "restrictions": Array [
24
- Object {
25
- "cred_def_id": "XUxBrVSALWHLeycAUhrNr9:3:CL:26293:student_card",
26
- },
27
- ],
28
- },
29
- },
30
- "requested_predicates": Object {},
31
- "version": "0.0.1",
32
- },
33
- }
34
- `;
35
-
36
- exports[`Helpers Build anoncreds proof request from template containing two requested attributes and predicate 1`] = `
37
- Object {
38
- "anoncreds": Object {
39
- "name": "Student full name and expiration date",
40
- "nonce": "1677766511505",
41
- "requested_attributes": Object {
42
- "referent_0": Object {
43
- "name": undefined,
44
- "names": Array [
45
- "student_first_name",
46
- "student_last_name",
47
- ],
48
- "non_revoked": undefined,
49
- "restrictions": Array [
50
- Object {
51
- "cred_def_id": "XUxBrVSALWHLeycAUhrNr9:3:CL:26293:student_card",
52
- },
53
- ],
54
- },
55
- },
56
- "requested_predicates": Object {
57
- "referent_1": Object {
58
- "name": "expiry_date",
59
- "non_revoked": undefined,
60
- "p_type": ">=",
61
- "p_value": 20240101,
62
- "restrictions": Array [
63
- Object {
64
- "cred_def_id": "XUxBrVSALWHLeycAUhrNr9:3:CL:26293:student_card",
65
- },
66
- ],
67
- },
68
- },
69
- "version": "0.0.1",
70
- },
71
- }
72
- `;
@@ -1,135 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`Helpers Get proof identifiers 1`] = `
4
- Object {
5
- "cred_def_id": "7KuDTpQh3GJ7Gp6kErpWvM:3:CL:712167:latest",
6
- "schema_id": "7KuDTpQh3GJ7Gp6kErpWvM:2:Faber College:1.0.0",
7
- }
8
- `;
9
-
10
- exports[`Helpers Group shared proof data by credential 1`] = `
11
- Map {
12
- "7KuDTpQh3GJ7Gp6kErpWvM:3:CL:712167:latest" => Object {
13
- "data": CredentialSharedProofData {
14
- "resolvedPredicates": Array [
15
- Object {
16
- "identifiers": Object {
17
- "cred_def_id": "7KuDTpQh3GJ7Gp6kErpWvM:3:CL:712167:latest",
18
- "schema_id": "7KuDTpQh3GJ7Gp6kErpWvM:2:Faber College:1.0.0",
19
- },
20
- "name": "age",
21
- "predicateType": ">=",
22
- "predicateValue": 1,
23
- },
24
- ],
25
- "sharedAttributeGroups": Array [
26
- Object {
27
- "attributes": Array [
28
- Object {
29
- "name": "first_name",
30
- "value": "Aries",
31
- },
32
- Object {
33
- "name": "second_name",
34
- "value": "Bifold",
35
- },
36
- ],
37
- "identifiers": Object {
38
- "cred_def_id": "7KuDTpQh3GJ7Gp6kErpWvM:3:CL:712167:latest",
39
- "schema_id": "7KuDTpQh3GJ7Gp6kErpWvM:2:Faber College:1.0.0",
40
- },
41
- },
42
- ],
43
- "sharedAttributes": Array [
44
- Object {
45
- "identifiers": Object {
46
- "cred_def_id": "7KuDTpQh3GJ7Gp6kErpWvM:3:CL:712167:latest",
47
- "schema_id": "7KuDTpQh3GJ7Gp6kErpWvM:2:Faber College:1.0.0",
48
- },
49
- "name": "date",
50
- "value": "1/1/1",
51
- },
52
- ],
53
- },
54
- "identifiers": Object {
55
- "cred_def_id": "7KuDTpQh3GJ7Gp6kErpWvM:3:CL:712167:latest",
56
- "schema_id": "7KuDTpQh3GJ7Gp6kErpWvM:2:Faber College:1.0.0",
57
- },
58
- },
59
- "7KuDTpQh3GJ7Gp6kErpWvM:3:CL:712168:latest" => Object {
60
- "data": CredentialSharedProofData {
61
- "resolvedPredicates": Array [],
62
- "sharedAttributeGroups": Array [],
63
- "sharedAttributes": Array [
64
- Object {
65
- "identifiers": Object {
66
- "cred_def_id": "7KuDTpQh3GJ7Gp6kErpWvM:3:CL:712168:latest",
67
- "schema_id": "7KuDTpQh3GJ7Gp6kErpWvM:2:Passport:1.0.0",
68
- },
69
- "name": "passport_no",
70
- "value": "123123",
71
- },
72
- ],
73
- },
74
- "identifiers": Object {
75
- "cred_def_id": "7KuDTpQh3GJ7Gp6kErpWvM:3:CL:712168:latest",
76
- "schema_id": "7KuDTpQh3GJ7Gp6kErpWvM:2:Passport:1.0.0",
77
- },
78
- },
79
- }
80
- `;
81
-
82
- exports[`Helpers Parse indy proof 1`] = `
83
- ParsedAnonCredsProof {
84
- "resolvedPredicates": Array [
85
- Object {
86
- "identifiers": Object {
87
- "cred_def_id": "7KuDTpQh3GJ7Gp6kErpWvM:3:CL:712167:latest",
88
- "schema_id": "7KuDTpQh3GJ7Gp6kErpWvM:2:Faber College:1.0.0",
89
- },
90
- "name": "age",
91
- "predicateType": ">=",
92
- "predicateValue": 1,
93
- },
94
- ],
95
- "sharedAttributeGroups": Array [
96
- Object {
97
- "attributes": Array [
98
- Object {
99
- "name": "first_name",
100
- "value": "Aries",
101
- },
102
- Object {
103
- "name": "second_name",
104
- "value": "Bifold",
105
- },
106
- ],
107
- "identifiers": Object {
108
- "cred_def_id": "7KuDTpQh3GJ7Gp6kErpWvM:3:CL:712167:latest",
109
- "schema_id": "7KuDTpQh3GJ7Gp6kErpWvM:2:Faber College:1.0.0",
110
- },
111
- },
112
- ],
113
- "sharedAttributes": Array [
114
- Object {
115
- "identifiers": Object {
116
- "cred_def_id": "7KuDTpQh3GJ7Gp6kErpWvM:3:CL:712167:latest",
117
- "schema_id": "7KuDTpQh3GJ7Gp6kErpWvM:2:Faber College:1.0.0",
118
- },
119
- "name": "date",
120
- "value": "1/1/1",
121
- },
122
- Object {
123
- "identifiers": Object {
124
- "cred_def_id": "7KuDTpQh3GJ7Gp6kErpWvM:3:CL:712168:latest",
125
- "schema_id": "7KuDTpQh3GJ7Gp6kErpWvM:2:Passport:1.0.0",
126
- },
127
- "name": "passport_no",
128
- "value": "123123",
129
- },
130
- ],
131
- "unresolvedAttributeGroups": Array [],
132
- "unresolvedAttributes": Array [],
133
- "unresolvedPredicates": Array [],
134
- }
135
- `;
@@ -1,34 +0,0 @@
1
- import { getProofRequestTemplates } from '../../request-templates'
2
- import { buildProofRequestDataForTemplate, hasPredicates } from '../../utils/proof-request'
3
-
4
- import SpyInstance = jest.SpyInstance
5
-
6
- describe('Helpers', () => {
7
- let spy: SpyInstance
8
-
9
- beforeAll(() => {
10
- spy = jest.spyOn(Date, 'now').mockImplementation(() => 1677766511505)
11
- })
12
- const templates = getProofRequestTemplates(false)
13
-
14
- test('Build anoncreds proof request from template containing two requested attributes', async () => {
15
- const template = templates[0]
16
- const proofRequest = buildProofRequestDataForTemplate(template)
17
- expect(proofRequest).toMatchSnapshot()
18
- })
19
-
20
- test('Build anoncreds proof request from template containing two requested attributes and predicate', async () => {
21
- const template = templates[1]
22
- const proofRequest = buildProofRequestDataForTemplate(template)
23
- expect(proofRequest).toMatchSnapshot()
24
- })
25
-
26
- test('Check if proof has predicates', async () => {
27
- expect(hasPredicates(templates[0])).toBeFalsy()
28
- expect(hasPredicates(templates[1])).toBeTruthy()
29
- })
30
-
31
- afterAll(() => {
32
- spy.mockRestore()
33
- })
34
- })
@@ -1,99 +0,0 @@
1
- import { AnonCredsProof } from '@credo-ts/anoncreds'
2
- import { getProofIdentifiers, groupSharedProofDataByCredential, parseAnonCredsProof } from '../../utils/proof'
3
- const proof_request = {
4
- name: 'proof-request',
5
- version: '1.0',
6
- nonce: '1298236324864',
7
- requested_attributes: {
8
- attribute_1: {
9
- names: ['first_name', 'second_name'],
10
- },
11
- attribute_2: {
12
- name: 'date',
13
- },
14
- attribute_3: {
15
- name: 'passport_no',
16
- },
17
- },
18
- requested_predicates: {
19
- predicate_1: {
20
- name: 'age',
21
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
- p_type: '>=' as any,
23
- p_value: 1,
24
- },
25
- },
26
- }
27
-
28
- const proof: AnonCredsProof = {
29
- proof: {
30
- proofs: [],
31
- aggregated_proof: {
32
- c_list: [],
33
- },
34
- },
35
- requested_proof: {
36
- revealed_attrs: {
37
- attribute_2: {
38
- sub_proof_index: 0,
39
- raw: '1/1/1',
40
- encoded: '',
41
- },
42
- attribute_3: {
43
- sub_proof_index: 1,
44
- raw: '123123',
45
- encoded: '',
46
- },
47
- },
48
- revealed_attr_groups: {
49
- attribute_1: {
50
- sub_proof_index: 0,
51
- values: {
52
- first_name: {
53
- raw: 'Aries',
54
- encoded: '',
55
- },
56
- second_name: {
57
- raw: 'Bifold',
58
- encoded: '',
59
- },
60
- },
61
- },
62
- },
63
- self_attested_attrs: {},
64
- unrevealed_attrs: {},
65
- predicates: {
66
- predicate_1: {
67
- sub_proof_index: 0,
68
- },
69
- },
70
- },
71
- identifiers: [
72
- {
73
- schema_id: '7KuDTpQh3GJ7Gp6kErpWvM:2:Faber College:1.0.0',
74
- cred_def_id: '7KuDTpQh3GJ7Gp6kErpWvM:3:CL:712167:latest',
75
- },
76
- {
77
- schema_id: '7KuDTpQh3GJ7Gp6kErpWvM:2:Passport:1.0.0',
78
- cred_def_id: '7KuDTpQh3GJ7Gp6kErpWvM:3:CL:712168:latest',
79
- },
80
- ],
81
- }
82
-
83
- describe('Helpers', () => {
84
- test('Parse indy proof', async () => {
85
- const proofRequest = parseAnonCredsProof(proof_request, proof)
86
- expect(proofRequest).toMatchSnapshot()
87
- })
88
-
89
- test('Group shared proof data by credential', async () => {
90
- const data = parseAnonCredsProof(proof_request, proof)
91
- const groupedData = groupSharedProofDataByCredential(data)
92
- expect(groupedData).toMatchSnapshot()
93
- })
94
-
95
- test('Get proof identifiers', async () => {
96
- const identifiers = getProofIdentifiers(proof, 0)
97
- expect(identifiers).toMatchSnapshot()
98
- })
99
- })
package/src/constants.ts DELETED
@@ -1,2 +0,0 @@
1
- export const protocolVersion = 'v2'
2
- export const domain = 'didcomm://invite'
@@ -1,20 +0,0 @@
1
- import { ProofExchangeRecord } from '@credo-ts/core'
2
- import { useProofs } from '@credo-ts/react-hooks'
3
- import { useMemo } from 'react'
4
-
5
- import { ProofCustomMetadata, ProofMetadata } from '../types/metadata'
6
-
7
- export const useProofsByTemplateId = (templateId: string): ProofExchangeRecord[] => {
8
- const { records: proofs } = useProofs()
9
-
10
- return useMemo(
11
- () =>
12
- proofs.filter((proof: ProofExchangeRecord) => {
13
- const metadata = proof?.metadata.get(ProofMetadata.customMetadata) as ProofCustomMetadata
14
- if (metadata?.proof_request_template_id === templateId) {
15
- return proof
16
- }
17
- }),
18
- [proofs, templateId]
19
- )
20
- }
package/src/index.ts DELETED
@@ -1,45 +0,0 @@
1
- export { ProofRequestType } from './types/proof-reqeust-template'
2
- export type {
3
- ProofRequestTemplate,
4
- DifProofRequestTemplatePayload,
5
- DifProofRequestTemplatePayloadData,
6
- AnonCredsProofRequestTemplatePayload,
7
- AnonCredsProofRequestTemplatePayloadData,
8
- AnonCredsRequestedAttribute,
9
- AnonCredsRequestedPredicate,
10
- } from './types/proof-reqeust-template'
11
- export type {
12
- GroupedSharedProofData,
13
- GroupedSharedProofDataItem,
14
- CredentialSharedProofData,
15
- ParsedAnonCredsProof,
16
- UnresolvedPredicate,
17
- ResolvedPredicate,
18
- SharedAttributesGroup,
19
- SharedGroupedAttribute,
20
- SharedAttribute,
21
- MissingAttribute,
22
- } from './types/proof'
23
- export type { ProofCustomMetadata } from './types/metadata'
24
- export { ProofMetadata } from './types/metadata'
25
- export { useProofsByTemplateId } from './hooks/proofs'
26
- export {
27
- getProofIdentifiers,
28
- parseAnonCredsProof,
29
- groupSharedProofDataByCredential,
30
- getProofData,
31
- isPresentationReceived,
32
- isPresentationFailed,
33
- markProofAsViewed,
34
- linkProofWithTemplate,
35
- } from './utils/proof'
36
- export type { CreateProofRequestInvitationResult, SendProofRequestResult } from './utils/proof-request'
37
- export {
38
- findProofRequestMessage,
39
- buildProofRequestDataForTemplate,
40
- createConnectionlessProofRequestInvitation,
41
- sendProofRequest,
42
- hasPredicates,
43
- isParameterizable,
44
- } from './utils/proof-request'
45
- export { getProofRequestTemplates } from './request-templates'
@@ -1,62 +0,0 @@
1
- import { ProofRequestTemplate, ProofRequestType } from './types/proof-reqeust-template'
2
-
3
- export const getProofRequestTemplates = (useDevRestrictions: boolean) => {
4
- const studentRestrictions = [{ cred_def_id: 'XUxBrVSALWHLeycAUhrNr9:3:CL:26293:student_card' }]
5
- const studentDevRestrictions = [{ schema_name: 'student_card' }]
6
- const restrictions = useDevRestrictions ? studentDevRestrictions : studentRestrictions
7
- const defaultProofRequestTemplates: Array<ProofRequestTemplate> = [
8
- {
9
- id: 'Aries:5:StudentFullName:0.0.1:indy',
10
- name: 'Student full name',
11
- description: 'Verify the full name of a student',
12
- version: '0.0.1',
13
- payload: {
14
- type: ProofRequestType.AnonCreds,
15
- data: [
16
- {
17
- schema: 'XUxBrVSALWHLeycAUhrNr9:3:CL:26293:Student Card',
18
- requestedAttributes: [
19
- {
20
- name: 'student_first_name',
21
- restrictions,
22
- },
23
- {
24
- name: 'student_last_name',
25
- restrictions,
26
- },
27
- ],
28
- },
29
- ],
30
- },
31
- },
32
- {
33
- id: 'Aries:5:StudentFullNameAndExpirationDate:0.0.1:indy',
34
- name: 'Student full name and expiration date',
35
- description: 'Verify that full name of a student and that he/she has a not expired student card.',
36
- version: '0.0.1',
37
- payload: {
38
- type: ProofRequestType.AnonCreds,
39
- data: [
40
- {
41
- schema: 'XUxBrVSALWHLeycAUhrNr9:3:CL:26293:Student Card',
42
- requestedAttributes: [
43
- {
44
- names: ['student_first_name', 'student_last_name'],
45
- restrictions,
46
- },
47
- ],
48
- requestedPredicates: [
49
- {
50
- name: 'expiry_date',
51
- predicateType: '>=',
52
- predicateValue: 20240101,
53
- restrictions,
54
- },
55
- ],
56
- },
57
- ],
58
- },
59
- },
60
- ]
61
- return defaultProofRequestTemplates
62
- }
@@ -1,53 +0,0 @@
1
- import {
2
- AnonCredsCredentialFormatService,
3
- AnonCredsModule,
4
- AnonCredsProofFormatService,
5
- DataIntegrityCredentialFormatService,
6
- LegacyIndyCredentialFormatService,
7
- LegacyIndyProofFormatService,
8
- V1CredentialProtocol,
9
- V1ProofProtocol,
10
- } from '@credo-ts/anoncreds'
11
- import {
12
- Agent,
13
- ConnectionsModule,
14
- CredentialsModule,
15
- DifPresentationExchangeProofFormatService,
16
- MediationRecipientModule,
17
- ProofsModule,
18
- V2CredentialProtocol,
19
- V2ProofProtocol,
20
- } from '@credo-ts/core'
21
-
22
- function getAgentModules() {
23
- return null as unknown as {
24
- //askar: AskarModule
25
- //anoncredsRs: AnonCredsRsModule
26
- anoncreds: AnonCredsModule
27
- //indyVdr: IndyVdrModule
28
- connections: ConnectionsModule
29
- credentials: CredentialsModule<
30
- (
31
- | V1CredentialProtocol
32
- | V2CredentialProtocol<
33
- (
34
- | LegacyIndyCredentialFormatService
35
- | AnonCredsCredentialFormatService
36
- | DataIntegrityCredentialFormatService
37
- )[]
38
- >
39
- )[]
40
- >
41
- proofs: ProofsModule<
42
- (
43
- | V1ProofProtocol
44
- | V2ProofProtocol<
45
- (LegacyIndyProofFormatService | AnonCredsProofFormatService | DifPresentationExchangeProofFormatService)[]
46
- >
47
- )[]
48
- >
49
- mediationRecipient: MediationRecipientModule
50
- }
51
- }
52
-
53
- export type BifoldAgent = Agent<ReturnType<typeof getAgentModules>>
@@ -1,9 +0,0 @@
1
- export enum ProofMetadata {
2
- customMetadata = 'customMetadata',
3
- }
4
-
5
- export interface ProofCustomMetadata {
6
- details_seen?: boolean
7
- proof_request_template_id?: string
8
- delete_conn_after_seen?: boolean
9
- }
@@ -1,59 +0,0 @@
1
- import {
2
- AnonCredsNonRevokedInterval,
3
- AnonCredsPredicateType,
4
- AnonCredsProofRequestRestriction,
5
- } from '@credo-ts/anoncreds'
6
-
7
- export interface AnonCredsRequestedPredicate {
8
- label?: string
9
- name: string
10
- predicateType: AnonCredsPredicateType
11
- predicateValue: number
12
- restrictions?: AnonCredsProofRequestRestriction[]
13
- devRestrictions?: AnonCredsProofRequestRestriction[]
14
- nonRevoked?: AnonCredsNonRevokedInterval
15
- parameterizable?: boolean
16
- }
17
-
18
- export interface AnonCredsRequestedAttribute {
19
- label?: string
20
- name?: string
21
- names?: Array<string>
22
- restrictions?: AnonCredsProofRequestRestriction[]
23
- devRestrictions?: AnonCredsProofRequestRestriction[]
24
- revealed?: boolean
25
- nonRevoked?: AnonCredsNonRevokedInterval
26
- }
27
-
28
- export interface AnonCredsProofRequestTemplatePayloadData {
29
- schema: string
30
- requestedAttributes?: Array<AnonCredsRequestedAttribute>
31
- requestedPredicates?: Array<AnonCredsRequestedPredicate>
32
- }
33
-
34
- export enum ProofRequestType {
35
- AnonCreds = 'anoncreds',
36
- DIF = 'dif',
37
- }
38
-
39
- export interface AnonCredsProofRequestTemplatePayload {
40
- type: ProofRequestType.AnonCreds
41
- data: Array<AnonCredsProofRequestTemplatePayloadData>
42
- }
43
-
44
- // eslint-disable-next-line @typescript-eslint/no-empty-interface
45
- export interface DifProofRequestTemplatePayloadData {}
46
-
47
- export interface DifProofRequestTemplatePayload {
48
- type: ProofRequestType.DIF
49
- data: Array<DifProofRequestTemplatePayloadData>
50
- }
51
-
52
- export interface ProofRequestTemplate {
53
- id: string
54
- name: string
55
- description: string
56
- version: string
57
- devOnly?: boolean
58
- payload: AnonCredsProofRequestTemplatePayload | DifProofRequestTemplatePayload
59
- }
@@ -1,68 +0,0 @@
1
- import { AnonCredsProof } from '@credo-ts/anoncreds'
2
- type AnonCredsProofIdentifier = AnonCredsProof['identifiers'][number]
3
-
4
- export interface MissingAttribute {
5
- name: string
6
- }
7
-
8
- export interface SharedAttribute {
9
- name: string
10
- value: string
11
- identifiers: AnonCredsProofIdentifier
12
- }
13
-
14
- export interface SharedGroupedAttribute {
15
- name: string
16
- value: string
17
- }
18
-
19
- export interface SharedAttributesGroup {
20
- attributes: Array<SharedGroupedAttribute>
21
- identifiers: AnonCredsProofIdentifier
22
- }
23
-
24
- export interface ResolvedPredicate {
25
- name: string
26
- predicateType: string
27
- predicateValue: number
28
- identifiers: AnonCredsProofIdentifier
29
- }
30
-
31
- export interface UnresolvedPredicate {
32
- name: string
33
- predicateType: string
34
- predicateValue: number
35
- }
36
-
37
- export class ParsedAnonCredsProof {
38
- public sharedAttributes: Array<SharedAttribute>
39
- public sharedAttributeGroups: Array<SharedAttributesGroup>
40
- public resolvedPredicates: Array<ResolvedPredicate>
41
- public unresolvedAttributes: Array<MissingAttribute>
42
- public unresolvedAttributeGroups: Array<Array<MissingAttribute>>
43
- public unresolvedPredicates: Array<UnresolvedPredicate>
44
-
45
- public constructor() {
46
- this.sharedAttributes = []
47
- this.sharedAttributeGroups = []
48
- this.resolvedPredicates = []
49
- this.unresolvedAttributes = []
50
- this.unresolvedAttributeGroups = []
51
- this.unresolvedPredicates = []
52
- }
53
- }
54
-
55
- export class CredentialSharedProofData {
56
- public sharedAttributes: Array<SharedAttribute>
57
- public sharedAttributeGroups: Array<SharedAttributesGroup>
58
- public resolvedPredicates: Array<ResolvedPredicate>
59
-
60
- public constructor() {
61
- this.sharedAttributes = []
62
- this.sharedAttributeGroups = []
63
- this.resolvedPredicates = []
64
- }
65
- }
66
-
67
- export type GroupedSharedProofDataItem = { data: CredentialSharedProofData; identifiers: AnonCredsProofIdentifier }
68
- export type GroupedSharedProofData = Map<string, GroupedSharedProofDataItem>
@@ -1,177 +0,0 @@
1
- import {
2
- AnonCredsRequestedAttribute,
3
- AnonCredsRequestedPredicate,
4
- LegacyIndyProofRequest,
5
- V1RequestPresentationMessage,
6
- } from '@credo-ts/anoncreds'
7
- import { Agent, AgentMessage, AutoAcceptProof, ProofExchangeRecord } from '@credo-ts/core'
8
-
9
- import { BifoldAgent } from '../types/agent'
10
- import { ProofRequestTemplate, ProofRequestType } from '../types/proof-reqeust-template'
11
-
12
- const protocolVersion = 'v2'
13
- const domain = 'http://aries-mobile-agent.com'
14
-
15
- /*
16
- * Find Proof Request message in the storage by the given id
17
- * */
18
- export const findProofRequestMessage = async (
19
- agent: Agent,
20
- id: string
21
- ): Promise<LegacyIndyProofRequest | undefined> => {
22
- const message = await agent.proofs.findRequestMessage(id)
23
- if (message && message instanceof V1RequestPresentationMessage && message.indyProofRequest) {
24
- return message.indyProofRequest
25
- } else {
26
- return undefined
27
- }
28
- }
29
-
30
- /*
31
- * Build Proof Request data from for provided template
32
- * */
33
- /*
34
- * Build Proof Request data for provided template
35
- * */
36
- export const buildProofRequestDataForTemplate = (
37
- template: ProofRequestTemplate,
38
- customValues?: Record<string, Record<string, number>>
39
- ) => {
40
- if (template.payload.type === ProofRequestType.AnonCreds) {
41
- const requestedAttributes: Record<string, AnonCredsRequestedAttribute> = {}
42
- const requestedPredicates: Record<string, AnonCredsRequestedPredicate> = {}
43
- let index = 0
44
-
45
- template.payload.data.forEach((data) => {
46
- if (data.requestedAttributes?.length) {
47
- data.requestedAttributes.forEach((requestedAttribute) => {
48
- requestedAttributes[`referent_${index}`] = {
49
- name: requestedAttribute.name,
50
- names: requestedAttribute.names,
51
- non_revoked: requestedAttribute.nonRevoked,
52
- restrictions: requestedAttribute.restrictions,
53
- }
54
- index++
55
- })
56
- }
57
- if (data.requestedPredicates?.length) {
58
- data.requestedPredicates.forEach((requestedPredicate) => {
59
- const customValue =
60
- customValues && customValues[data.schema] ? customValues[data.schema][requestedPredicate.name] : undefined
61
-
62
- requestedPredicates[`referent_${index}`] = {
63
- name: requestedPredicate.name,
64
- p_value:
65
- requestedPredicate.parameterizable && customValue ? customValue : requestedPredicate.predicateValue,
66
- p_type: requestedPredicate.predicateType,
67
- non_revoked: requestedPredicate.nonRevoked,
68
- restrictions: requestedPredicate.restrictions,
69
- }
70
- index++
71
- })
72
- }
73
- })
74
- return {
75
- anoncreds: {
76
- name: template.name,
77
- version: template.version,
78
- nonce: Date.now().toString(),
79
- requested_attributes: requestedAttributes,
80
- requested_predicates: requestedPredicates,
81
- },
82
- }
83
- }
84
- if (template.payload.type === ProofRequestType.DIF) {
85
- return {}
86
- }
87
- }
88
-
89
- export interface CreateProofRequestInvitationResult {
90
- request: AgentMessage
91
- proofRecord: ProofExchangeRecord
92
- invitation: AgentMessage
93
- invitationUrl: string
94
- }
95
-
96
- /*
97
- * Create connectionless proof request invitation for provided template
98
- * */
99
- export const createConnectionlessProofRequestInvitation = async (
100
- agent: BifoldAgent,
101
- template: ProofRequestTemplate,
102
- customPredicateValues?: Record<string, Record<string, number>>
103
- ): Promise<CreateProofRequestInvitationResult | undefined> => {
104
- const proofFormats = buildProofRequestDataForTemplate(template, customPredicateValues)
105
- if (!proofFormats) {
106
- return undefined
107
- }
108
- const { message: request, proofRecord } = await agent.proofs.createRequest({
109
- protocolVersion,
110
- autoAcceptProof: AutoAcceptProof.Always,
111
- proofFormats,
112
- })
113
- const { message: invitation, invitationUrl } = await agent.oob.createLegacyConnectionlessInvitation({
114
- recordId: proofRecord.id,
115
- message: request,
116
- domain,
117
- })
118
- return {
119
- request,
120
- proofRecord,
121
- invitation,
122
- invitationUrl,
123
- }
124
- }
125
-
126
- export interface SendProofRequestResult {
127
- proofRecord: ProofExchangeRecord
128
- }
129
-
130
- /*
131
- * Build Proof Request for provided template and send it to provided connection
132
- * */
133
- export const sendProofRequest = async (
134
- agent: BifoldAgent,
135
- template: ProofRequestTemplate,
136
- connectionId: string,
137
- customPredicateValues?: Record<string, Record<string, number>>
138
- ): Promise<SendProofRequestResult | undefined> => {
139
- const proofFormats = buildProofRequestDataForTemplate(template, customPredicateValues)
140
- if (!proofFormats) {
141
- return undefined
142
- }
143
- const proofRecord = await agent.proofs.requestProof({
144
- protocolVersion,
145
- connectionId,
146
- proofFormats,
147
- })
148
- return {
149
- proofRecord,
150
- }
151
- }
152
-
153
- /*
154
- * Check if the Proof Request template contains at least one predicate
155
- * */
156
- export const hasPredicates = (record: ProofRequestTemplate): boolean => {
157
- if (record.payload.type === ProofRequestType.AnonCreds) {
158
- return record.payload.data.some((d) => d.requestedPredicates && d.requestedPredicates?.length > 0)
159
- }
160
- if (record.payload.type === ProofRequestType.DIF) {
161
- return false
162
- }
163
- return false
164
- }
165
-
166
- /*
167
- * Check if the Proof Request template contains parameterizable predicates
168
- * */
169
- export const isParameterizable = (record: ProofRequestTemplate): boolean => {
170
- if (record.payload.type === ProofRequestType.AnonCreds) {
171
- return record.payload.data.some((d) => d.requestedPredicates?.some((predicate) => predicate.parameterizable))
172
- }
173
- if (record.payload.type === ProofRequestType.DIF) {
174
- return false
175
- }
176
- return false
177
- }
@@ -1,173 +0,0 @@
1
- import { AnonCredsProof, AnonCredsProofRequest } from '@credo-ts/anoncreds'
2
- import { Agent, ProofExchangeRecord, ProofState } from '@credo-ts/core'
3
-
4
- import { BifoldAgent } from '../types/agent'
5
- import { ProofMetadata } from '../types/metadata'
6
- import {
7
- CredentialSharedProofData,
8
- GroupedSharedProofData,
9
- GroupedSharedProofDataItem,
10
- ParsedAnonCredsProof,
11
- } from '../types/proof'
12
-
13
- /*
14
- * Extract identifiers from indy proof
15
- * */
16
- export const getProofIdentifiers = (proof: AnonCredsProof, proofIndex: number) => {
17
- const identifiers = proof.identifiers[proofIndex]
18
- if (!identifiers) {
19
- throw new Error('Invalid indy proof data')
20
- }
21
- return identifiers
22
- }
23
-
24
- /*
25
- * Process anoncreds proof and return
26
- * - shared attributes
27
- * - shared attribute groups
28
- * - resolved predicates
29
- * - missing attributes
30
- * - missing attribute groups
31
- * - unresolved predicates
32
- * */
33
- export const parseAnonCredsProof = (request: AnonCredsProofRequest, proof: AnonCredsProof): ParsedAnonCredsProof => {
34
- const result = new ParsedAnonCredsProof()
35
-
36
- for (const [referent, requested_attribute] of Object.entries(request.requested_attributes)) {
37
- if (requested_attribute.name) {
38
- const shared = proof.requested_proof.revealed_attrs[referent]
39
- if (shared) {
40
- const identifiers = getProofIdentifiers(proof, shared.sub_proof_index)
41
- result.sharedAttributes.push({
42
- name: requested_attribute.name,
43
- value: shared.raw,
44
- identifiers,
45
- })
46
- } else {
47
- result.unresolvedAttributes.push({
48
- name: requested_attribute.name,
49
- })
50
- }
51
- }
52
-
53
- if (requested_attribute.names) {
54
- const shared = proof.requested_proof.revealed_attr_groups?.[referent]
55
- if (shared) {
56
- const attributes = Object.entries(shared.values).map(([name, value]) => ({
57
- name,
58
- value: value.raw,
59
- }))
60
- const identifiers = getProofIdentifiers(proof, shared.sub_proof_index)
61
- result.sharedAttributeGroups.push({
62
- attributes,
63
- identifiers,
64
- })
65
- } else {
66
- result.unresolvedAttributeGroups.push(requested_attribute.names.map((name) => ({ name })))
67
- }
68
- }
69
- }
70
-
71
- for (const [referent, requestedPredicate] of Object.entries(request.requested_predicates)) {
72
- const shared = proof.requested_proof.predicates[referent]
73
- if (shared) {
74
- const identifiers = getProofIdentifiers(proof, shared.sub_proof_index)
75
- result.resolvedPredicates.push({
76
- name: requestedPredicate.name,
77
- predicateType: requestedPredicate.p_type,
78
- predicateValue: requestedPredicate.p_value,
79
- identifiers,
80
- })
81
- } else {
82
- result.unresolvedPredicates.push({
83
- name: requestedPredicate.name,
84
- predicateType: requestedPredicate.p_type,
85
- predicateValue: requestedPredicate.p_value,
86
- })
87
- }
88
- }
89
-
90
- return result
91
- }
92
-
93
- /*
94
- * Group parsed indy proof data ( returned from `parseIndyProof`) by credential definition id
95
- * */
96
- export const groupSharedProofDataByCredential = (data: ParsedAnonCredsProof): GroupedSharedProofData => {
97
- const result: GroupedSharedProofData = new Map<string, GroupedSharedProofDataItem>()
98
- for (const item of data.sharedAttributes) {
99
- if (!result.has(item.identifiers.cred_def_id)) {
100
- result.set(item.identifiers.cred_def_id, {
101
- data: new CredentialSharedProofData(),
102
- identifiers: item.identifiers,
103
- })
104
- }
105
- result.get(item.identifiers.cred_def_id)?.data.sharedAttributes.push(item)
106
- }
107
- for (const item of data.sharedAttributeGroups) {
108
- if (!result.has(item.identifiers.cred_def_id)) {
109
- result.set(item.identifiers.cred_def_id, {
110
- data: new CredentialSharedProofData(),
111
- identifiers: item.identifiers,
112
- })
113
- }
114
- result.get(item.identifiers.cred_def_id)?.data.sharedAttributeGroups.push(item)
115
- }
116
- for (const item of data.resolvedPredicates) {
117
- if (!result.has(item.identifiers.cred_def_id)) {
118
- result.set(item.identifiers.cred_def_id, {
119
- data: new CredentialSharedProofData(),
120
- identifiers: item.identifiers,
121
- })
122
- }
123
- result.get(item.identifiers.cred_def_id)?.data.resolvedPredicates.push(item)
124
- }
125
- return result
126
- }
127
-
128
- /*
129
- * Retrieve proof details from Credo record
130
- * */
131
- export const getProofData = async (agent: BifoldAgent, recordId: string): Promise<ParsedAnonCredsProof | undefined> => {
132
- const data = await agent.proofs.getFormatData(recordId)
133
- if (data.request?.anoncreds && data.presentation?.anoncreds) {
134
- return parseAnonCredsProof(data.request.anoncreds, data.presentation.anoncreds)
135
- } else if (data.request?.indy && data.presentation?.indy) {
136
- return parseAnonCredsProof(data.request.indy, data.presentation.indy)
137
- }
138
-
139
- return undefined
140
- }
141
-
142
- /*
143
- * Check if a presentation received
144
- * */
145
- export const isPresentationReceived = (record: ProofExchangeRecord) => {
146
- return record.state === ProofState.PresentationReceived || record.state === ProofState.Done
147
- }
148
-
149
- /*
150
- * Check if a presentation failed
151
- * */
152
- export const isPresentationFailed = (record: ProofExchangeRecord) => {
153
- return record.state === ProofState.Abandoned
154
- }
155
-
156
- /*
157
- * Mark Proof record as viewed
158
- * */
159
- export const markProofAsViewed = async (agent: Agent, record: ProofExchangeRecord) => {
160
- record.metadata.set(ProofMetadata.customMetadata, { ...record.metadata.data.customMetadata, details_seen: true })
161
- return agent.proofs.update(record)
162
- }
163
-
164
- /*
165
- * Add template reference to Proof Exchange record
166
- * */
167
- export const linkProofWithTemplate = async (agent: Agent, record: ProofExchangeRecord, templateId: string) => {
168
- record.metadata.set(ProofMetadata.customMetadata, {
169
- ...record.metadata.data.customMetadata,
170
- proof_request_template_id: templateId,
171
- })
172
- return agent.proofs.update(record)
173
- }