Skip to content

Commit 1caba41

Browse files
authored
changes based on pr feedback (openwallet-foundation#189)
* remove indy from proof module, abstract nonce * add role names to module methods * rename build to get for schema, cred def * use records instead of maps Signed-off-by: Timo Glastra <[email protected]>
1 parent e30403a commit 1caba41

File tree

13 files changed

+141
-110
lines changed

13 files changed

+141
-110
lines changed

src/lib/__tests__/proofs.test.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -193,23 +193,19 @@ describe('Present Proof', () => {
193193
test('Faber starts with proof requests to Alice', async () => {
194194
logger.log('Faber sends presentation request to Alice');
195195

196-
const attributes = new Map();
197-
attributes.set(
198-
'name',
199-
new ProofAttributeInfo({
196+
const attributes = {
197+
name: new ProofAttributeInfo({
200198
name: 'name',
201199
restrictions: [
202200
new AttributeFilter({
203201
credentialDefinitionId: credDefId,
204202
}),
205203
],
206-
})
207-
);
204+
}),
205+
};
208206

209-
const predicates = new Map();
210-
predicates.set(
211-
'age',
212-
new ProofPredicateInfo({
207+
const predicates = {
208+
age: new ProofPredicateInfo({
213209
name: 'age',
214210
predicateType: PredicateType.GreaterThanOrEqualTo,
215211
predicateValue: 50,
@@ -218,8 +214,8 @@ describe('Present Proof', () => {
218214
credentialDefinitionId: credDefId,
219215
}),
220216
],
221-
})
222-
);
217+
}),
218+
};
223219

224220
let faberProofRecord = await faberAgent.proof.requestProof(faberConnection.id, {
225221
name: 'test-proof-request',

src/lib/agent/Agent.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ export class Agent {
202202
this.messageSender
203203
);
204204

205-
this.proof = new ProofsModule(this.proofService, this.connectionService, this.messageSender, this.indy);
205+
this.proof = new ProofsModule(this.proofService, this.connectionService, this.messageSender);
206206

207207
this.routing = new RoutingModule(
208208
this.agentConfig,
@@ -216,11 +216,6 @@ export class Agent {
216216
this.basicMessages = new BasicMessagesModule(this.basicMessageService, this.messageSender);
217217
this.ledger = new LedgerModule(this.wallet, this.ledgerService);
218218

219-
this.credentials = new CredentialsModule(
220-
this.connectionService,
221-
this.credentialService,
222-
this.ledgerService,
223-
this.messageSender
224-
);
219+
this.credentials = new CredentialsModule(this.connectionService, this.credentialService, this.messageSender);
225220
}
226221
}

src/lib/modules/ConnectionsModule.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export class ConnectionsModule {
5858
}
5959

6060
/**
61-
* Receive connection invitation and create connection. If auto accepting is enabled
61+
* Receive connection invitation as invitee and create connection. If auto accepting is enabled
6262
* via either the config passed in the function or the global agent config, a connection
6363
* request message will be send.
6464
*
@@ -88,7 +88,7 @@ export class ConnectionsModule {
8888
}
8989

9090
/**
91-
* Receive connection invitation encoded as url and create connection. If auto accepting is enabled
91+
* Receive connection invitation as invitee encoded as url and create connection. If auto accepting is enabled
9292
* via either the config passed in the function or the global agent config, a connection
9393
* request message will be send.
9494
*
@@ -108,7 +108,7 @@ export class ConnectionsModule {
108108
}
109109

110110
/**
111-
* Accept a connection invitation (by sending a connection request message) for the connection with the specified connection id.
111+
* Accept a connection invitation as invitee (by sending a connection request message) for the connection with the specified connection id.
112112
* This is not needed when auto accepting of connections is enabled.
113113
*
114114
* @param connectionId the id of the connection for which to accept the invitation
@@ -130,7 +130,7 @@ export class ConnectionsModule {
130130
}
131131

132132
/**
133-
* Accept a connection request (by sending a connection response message) for the connection with the specified connection id.
133+
* Accept a connection request as inviter (by sending a connection response message) for the connection with the specified connection id.
134134
* This is not needed when auto accepting of connection is enabled.
135135
*
136136
* @param connectionId the id of the connection for which to accept the request
@@ -146,7 +146,7 @@ export class ConnectionsModule {
146146
}
147147

148148
/**
149-
* Accept a connection response (by sending a trust ping message) for the connection with the specified connection id.
149+
* Accept a connection response as invitee (by sending a trust ping message) for the connection with the specified connection id.
150150
* This is not needed when auto accepting of connection is enabled.
151151
*
152152
* @param connectionId the id of the connection for which to accept the response

src/lib/modules/CredentialsModule.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { CredentialRecord } from '../storage/CredentialRecord';
22
import { createOutboundMessage } from '../protocols/helpers';
33
import { MessageSender } from '../agent/MessageSender';
44
import { ConnectionService } from '../protocols/connections/ConnectionService';
5-
import { LedgerService } from '../agent/LedgerService';
65
import { EventEmitter } from 'events';
76
import {
87
ProposeCredentialMessage,
@@ -16,18 +15,15 @@ import { JsonTransformer } from '../utils/JsonTransformer';
1615
export class CredentialsModule {
1716
private connectionService: ConnectionService;
1817
private credentialService: CredentialService;
19-
private ledgerService: LedgerService;
2018
private messageSender: MessageSender;
2119

2220
public constructor(
2321
connectionService: ConnectionService,
2422
credentialService: CredentialService,
25-
ledgerService: LedgerService,
2623
messageSender: MessageSender
2724
) {
2825
this.connectionService = connectionService;
2926
this.credentialService = credentialService;
30-
this.ledgerService = ledgerService;
3127
this.messageSender = messageSender;
3228
}
3329

@@ -42,7 +38,7 @@ export class CredentialsModule {
4238
}
4339

4440
/**
45-
* Initiate a new credential exchange by sending a credential proposal message
41+
* Initiate a new credential exchange as holder by sending a credential proposal message
4642
* to the connection with the specified connection id.
4743
*
4844
* @param connectionId The connection to send the credential proposal to
@@ -61,7 +57,7 @@ export class CredentialsModule {
6157
}
6258

6359
/**
64-
* Accept a credential proposal (by sending a credential offer message) to the connection
60+
* Accept a credential proposal as issuer (by sending a credential offer message) to the connection
6561
* associated with the credential record.
6662
*
6763
* @param credentialRecordId The id of the credential record for which to accept the proposal
@@ -111,7 +107,7 @@ export class CredentialsModule {
111107
}
112108

113109
/**
114-
* Initiate a new credential exchange by sending a credential offer message
110+
* Initiate a new credential exchange as issuer by sending a credential offer message
115111
* to the connection with the specified connection id.
116112
*
117113
* @param connectionId The connection to send the credential offer to
@@ -133,7 +129,7 @@ export class CredentialsModule {
133129
}
134130

135131
/**
136-
* Accept a credential offer (by sending a credential request message) to the connection
132+
* Accept a credential offer as holder (by sending a credential request message) to the connection
137133
* associated with the credential record.
138134
*
139135
* @param credentialRecordId The id of the credential record for which to accept the offer
@@ -154,7 +150,7 @@ export class CredentialsModule {
154150
}
155151

156152
/**
157-
* Accept a credential request (by sending a credential message) to the connection
153+
* Accept a credential request as issuer (by sending a credential message) to the connection
158154
* associated with the credential record.
159155
*
160156
* @param credentialRecordId The id of the credential record for which to accept the request
@@ -174,7 +170,7 @@ export class CredentialsModule {
174170
}
175171

176172
/**
177-
* Accept a credential (by sending a credential acknowledgement message) to the connection
173+
* Accept a credential as holder (by sending a credential acknowledgement message) to the connection
178174
* associated with the credential record.
179175
*
180176
* @param credentialRecordId The id of the credential record for which to accept the credential

src/lib/modules/ProofsModule.ts

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type Indy from 'indy-sdk';
21
import { createOutboundMessage } from '../protocols/helpers';
32
import { MessageSender } from '../agent/MessageSender';
43
import { ProofService } from '../protocols/present-proof/ProofService';
@@ -13,18 +12,11 @@ export class ProofsModule {
1312
private proofService: ProofService;
1413
private connectionService: ConnectionService;
1514
private messageSender: MessageSender;
16-
private indy: typeof Indy;
1715

18-
public constructor(
19-
proofService: ProofService,
20-
connectionService: ConnectionService,
21-
messageSender: MessageSender,
22-
indy: typeof Indy
23-
) {
16+
public constructor(proofService: ProofService, connectionService: ConnectionService, messageSender: MessageSender) {
2417
this.proofService = proofService;
2518
this.connectionService = connectionService;
2619
this.messageSender = messageSender;
27-
this.indy = indy;
2820
}
2921

3022
/**
@@ -38,7 +30,7 @@ export class ProofsModule {
3830
}
3931

4032
/**
41-
* Initiate a new presentation exchange by sending a presentation proposal message
33+
* Initiate a new presentation exchange as prover by sending a presentation proposal message
4234
* to the connection with the specified connection id.
4335
*
4436
* @param connectionId The connection to send the proof proposal to
@@ -65,7 +57,7 @@ export class ProofsModule {
6557
}
6658

6759
/**
68-
* Accept a presentation proposal (by sending a presentation request message) to the connection
60+
* Accept a presentation proposal as verifier (by sending a presentation request message) to the connection
6961
* associated with the proof record.
7062
*
7163
* @param proofRecordId The id of the proof record for which to accept the proposal
@@ -112,7 +104,7 @@ export class ProofsModule {
112104
}
113105

114106
/**
115-
* Initiate a new presentation exchange by sending a presentation request message
107+
* Initiate a new presentation exchange as verifier by sending a presentation request message
116108
* to the connection with the specified connection id
117109
*
118110
* @param connectionId The connection to send the proof request to
@@ -130,10 +122,12 @@ export class ProofsModule {
130122
): Promise<ProofRecord> {
131123
const connection = await this.connectionService.getById(connectionId);
132124

125+
const nonce = proofRequestOptions.nonce ?? (await this.proofService.generateProofRequestNonce());
126+
133127
const proofRequest = new ProofRequest({
134128
name: proofRequestOptions.name ?? 'proof-request',
135129
version: proofRequestOptions.name ?? '1.0',
136-
nonce: proofRequestOptions.nonce ?? (await this.indy.generateNonce()),
130+
nonce,
137131
requestedAttributes: proofRequestOptions.requestedAttributes,
138132
requestedPredicates: proofRequestOptions.requestedPredicates,
139133
});
@@ -147,7 +141,7 @@ export class ProofsModule {
147141
}
148142

149143
/**
150-
* Accept a presentation request (by sending a presentation message) to the connection
144+
* Accept a presentation request as prover (by sending a presentation message) to the connection
151145
* associated with the proof record.
152146
*
153147
* @param proofRecordId The id of the proof record for which to accept the request
@@ -175,7 +169,7 @@ export class ProofsModule {
175169
}
176170

177171
/**
178-
* Accept a presentation (by sending a presentation acknowledgement message) to the connection
172+
* Accept a presentation as prover (by sending a presentation acknowledgement message) to the connection
179173
* associated with the proof record.
180174
*
181175
* @param proofRecordId The id of the proof record for which to accept the presentation
@@ -193,6 +187,18 @@ export class ProofsModule {
193187
return proofRecord;
194188
}
195189

190+
/**
191+
* Create a RequestedCredentials object. Given input proof request and presentation proposal,
192+
* use credentials in the wallet to build indy requested credentials object for input to proof creation.
193+
* If restrictions allow, self attested attributes will be used.
194+
*
195+
* Use the return value of this method as input to {@link ProofService.createPresentation} to automatically
196+
* accept a received presentation request.
197+
*
198+
* @param proofRequest The proof request to build the requested credentials object from
199+
* @param presentationProposal Optional presentation proposal to improve credential selection algorithm
200+
* @returns Requested credentials object for use in proof creation
201+
*/
196202
public async getRequestedCredentialsForProofRequest(
197203
proofRequest: ProofRequest,
198204
presentationProposal: PresentationPreview

src/lib/protocols/issue-credential/__tests__/StubWallet.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,8 @@ export class StubWallet implements Wallet {
156156
public signRequest(myDid: string, request: LedgerRequest): Promise<LedgerRequest> {
157157
throw new Error('Method not implemented.');
158158
}
159+
160+
public async generateNonce(): Promise<string> {
161+
throw new Error('Method not implemented');
162+
}
159163
}

src/lib/protocols/issue-credential/models/CredentialInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class CredentialInfo {
2424

2525
@Expose({ name: 'attrs' })
2626
@IsString({ each: true })
27-
public attributes!: Map<string, string>;
27+
public attributes!: Record<string, string>;
2828

2929
@Expose({ name: 'schema_id' })
3030
@IsString()

0 commit comments

Comments
 (0)