Newer
Older
import type {
EventAnonCredsProofsDeleteById,
EventAnonCredsProofsDeleteByIdInput,
EventAnonCredsProofsGetAll,
EventAnonCredsProofsGetAllInput,
EventAnonCredsProofsGetById,
EventAnonCredsProofsGetByIdInput,
EventDidcommAnonCredsProofsRequest,
EventDidcommAnonCredsProofsRequestInput,
} from '@ocm/shared';
import { Injectable } from '@nestjs/common';
import { WithTenantService } from '../withTenantService.js';
@Injectable()
export class AnonCredsProofsService {
public constructor(private withTenantService: WithTenantService) {}
public async getAll({
tenantId,
}: EventAnonCredsProofsGetAllInput): Promise<
EventAnonCredsProofsGetAll['data']
> {
return this.withTenantService.invoke(tenantId, (t) => t.proofs.getAll());
}
public async getById({
tenantId,
proofRecordId,
}: EventAnonCredsProofsGetByIdInput): Promise<
EventAnonCredsProofsGetById['data']
> {
return this.withTenantService.invoke(tenantId, (t) =>
t.proofs.findById(proofRecordId),
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
);
}
public async deleteById({
tenantId,
proofRecordId,
}: EventAnonCredsProofsDeleteByIdInput): Promise<
EventAnonCredsProofsDeleteById['data']
> {
return this.withTenantService.invoke(tenantId, async (t) => {
await t.proofs.deleteById(proofRecordId);
return {};
});
}
public async request({
tenantId,
connectionId,
name,
requestedAttributes,
requestedPredicates,
}: EventDidcommAnonCredsProofsRequestInput): Promise<
EventDidcommAnonCredsProofsRequest['data']
> {
const transformedPredicates = Object.entries(requestedPredicates).reduce(
(prev, [key, value]) => ({
...prev,
[key]: {
name: value.name,
restrictions: value.restrictions,
p_type: value.predicateType,
p_value: value.predicateValue,
},
}),
{},
);
return this.withTenantService.invoke(tenantId, (t) =>
t.proofs.requestProof({
connectionId,
protocolVersion: 'v2',
proofFormats: {
anoncreds: {
name,
version: '1.0',
requested_attributes: requestedAttributes,
requested_predicates: transformedPredicates,
},
},
}),
);
}
}