Skip to content

Commit

Permalink
fix: only create routing when toDid is undefined
Browse files Browse the repository at this point in the history
Signed-off-by: Ariel Gentile <gentilester@gmail.com>
  • Loading branch information
genaris committed Jan 29, 2024
1 parent a83bfe4 commit 70ab2ca
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
23 changes: 20 additions & 3 deletions packages/core/src/modules/connections/ConnectionsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,18 +287,35 @@ export class ConnectionsApi {
return message
}

/**
* Rotate the DID used for a given connection, notifying the other party immediately.
*
* If `toDid` is not specified, a new peer did will be created. Optionally, routing
* configuration can be set.
*
* Note: any did created or imported in agent wallet can be used as `toDid`, as long as
* there are valid DIDComm services in its DID Document.
*
* @param options connectionId and optional target did and routing configuration
* @returns object containing the new did
*/
public async rotate(options: { connectionId: string; toDid?: string; routing?: Routing }) {
const { connectionId, toDid, routing } = options
const { connectionId, toDid } = options
const connection = await this.connectionService.getById(this.agentContext, connectionId)

if (toDid && routing) {
if (toDid && options.routing) {
throw new AriesFrameworkError(`'routing' is disallowed when defining 'toDid'`)
}

let routing = options.routing
if (!toDid && !routing) {
routing = await this.routingService.getRouting(this.agentContext, {})
}

const message = await this.didRotateService.createRotate(this.agentContext, {
connection,
toDid,
routing: routing || (await this.routingService.getRouting(this.agentContext, {})),
routing,
})

const outboundMessageContext = new OutboundMessageContext(message, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class DidRotateService {

public async createRotate(
agentContext: AgentContext,
options: { connection: ConnectionRecord; toDid?: string; routing: Routing }
options: { connection: ConnectionRecord; toDid?: string; routing?: Routing }
) {
const { connection, toDid, routing } = options

Expand All @@ -60,6 +60,10 @@ export class DidRotateService {

// Otherwise, create a did:peer based on the provided routing
} else {
if (!routing) {
throw new AriesFrameworkError('Routing configuration must be defined when rotating to a new peer did')
}

didDocument = await createPeerDidFromServices(
agentContext,
routingToServices(routing),
Expand Down

0 comments on commit 70ab2ca

Please sign in to comment.