@@ -3,7 +3,6 @@ import { validateOrReject } from 'class-validator';
3
3
4
4
import { AgentConfig } from '../../agent/AgentConfig' ;
5
5
import { ConnectionState } from './domain/ConnectionState' ;
6
- import { DidDoc , Service , PublicKey , PublicKeyType , Authentication } from './domain/DidDoc' ;
7
6
import { ConnectionRecord , ConnectionTags } from '../../storage/ConnectionRecord' ;
8
7
import { Repository } from '../../storage/Repository' ;
9
8
import { Wallet } from '../../wallet/Wallet' ;
@@ -18,6 +17,10 @@ import { ConnectionRole } from './domain/ConnectionRole';
18
17
import { TrustPingMessage } from '../trustping/TrustPingMessage' ;
19
18
import { JsonTransformer } from '../../utils/JsonTransformer' ;
20
19
import { AgentMessage } from '../../agent/AgentMessage' ;
20
+ import { Ed25119Sig2018 } from './domain/did/publicKey' ;
21
+ import { IndyAgentService } from './domain/did/service' ;
22
+ import { DidDoc } from './domain/did/DidDoc' ;
23
+ import { authenticationTypes , ReferencedAuthentication } from './domain/did/authentication' ;
21
24
22
25
export enum ConnectionEventType {
23
26
StateChanged = 'stateChanged' ,
@@ -64,11 +67,12 @@ export class ConnectionService extends EventEmitter {
64
67
} ) ;
65
68
66
69
const { didDoc } = connectionRecord ;
70
+ const [ service ] = didDoc . getServicesByClassType ( IndyAgentService ) ;
67
71
const invitation = new ConnectionInvitationMessage ( {
68
72
label : this . config . label ,
69
- recipientKeys : didDoc . service [ 0 ] . recipientKeys ,
70
- serviceEndpoint : didDoc . service [ 0 ] . serviceEndpoint ,
71
- routingKeys : didDoc . service [ 0 ] . routingKeys ,
73
+ recipientKeys : service . recipientKeys ,
74
+ serviceEndpoint : service . serviceEndpoint ,
75
+ routingKeys : service . routingKeys ,
72
76
} ) ;
73
77
74
78
connectionRecord . invitation = invitation ;
@@ -249,6 +253,7 @@ export class ConnectionService extends EventEmitter {
249
253
const connectionJson = await unpackAndVerifySignatureDecorator ( message . connectionSig , this . wallet ) ;
250
254
251
255
const connection = JsonTransformer . fromJSON ( connectionJson , Connection ) ;
256
+ // TODO: throw framework error stating the connection object is invalid
252
257
await validateOrReject ( connection ) ;
253
258
254
259
// Per the Connection RFC we must check if the key used to sign the connection~sig is the same key
@@ -345,18 +350,31 @@ export class ConnectionService extends EventEmitter {
345
350
autoAcceptConnection ?: boolean ;
346
351
tags ?: ConnectionTags ;
347
352
} ) : Promise < ConnectionRecord > {
348
- const [ did , verkey ] = await this . wallet . createDid ( ) ;
349
- const publicKey = new PublicKey ( `${ did } #1` , PublicKeyType . ED25519_SIG_2018 , did , verkey ) ;
350
- const service = new Service (
351
- `${ did } ;indy` ,
352
- this . config . getEndpoint ( ) ,
353
- [ verkey ] ,
354
- this . config . getRoutingKeys ( ) ,
355
- 0 ,
356
- 'IndyAgent'
357
- ) ;
358
- const auth = new Authentication ( publicKey ) ;
359
- const didDoc = new DidDoc ( did , [ auth ] , [ publicKey ] , [ service ] ) ;
353
+ const [ did , verkey ] = await this . wallet . createDid ( { method_name : 'sov' } ) ;
354
+
355
+ const publicKey = new Ed25119Sig2018 ( {
356
+ id : `${ did } #1` ,
357
+ controller : did ,
358
+ publicKeyBase58 : verkey ,
359
+ } ) ;
360
+
361
+ const service = new IndyAgentService ( {
362
+ id : `${ did } ;indy` ,
363
+ serviceEndpoint : this . config . getEndpoint ( ) ,
364
+ recipientKeys : [ verkey ] ,
365
+ routingKeys : this . config . getRoutingKeys ( ) ,
366
+ } ) ;
367
+
368
+ // TODO: abstract the second paramater for ReferencedAuthentication away. This can be
369
+ // inferred from the publicKey class instance
370
+ const auth = new ReferencedAuthentication ( publicKey , authenticationTypes [ publicKey . type ] ) ;
371
+
372
+ const didDoc = new DidDoc ( {
373
+ id : did ,
374
+ authentication : [ auth ] ,
375
+ service : [ service ] ,
376
+ publicKey : [ publicKey ] ,
377
+ } ) ;
360
378
361
379
const connectionRecord = new ConnectionRecord ( {
362
380
did,
@@ -377,7 +395,7 @@ export class ConnectionService extends EventEmitter {
377
395
return connectionRecord ;
378
396
}
379
397
380
- public async getConnections ( ) {
398
+ public getConnections ( ) {
381
399
return this . connectionRepository . findAll ( ) ;
382
400
}
383
401
0 commit comments