Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(connections): allow ; to convert legacy did #882

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ describe('ConnectionService', () => {
const processedConnection = await connectionService.processRequest(messageContext, outOfBand)

expect(processedConnection.state).toBe(DidExchangeState.RequestReceived)
expect(processedConnection.theirDid).toBe('did:peer:1zQmfPPbuG8vajHvYjGUW8CN5k9rLuuMmYSGBYwJqJDDUS72')
expect(processedConnection.theirDid).toBe('did:peer:1zQmW2esSyEVGzrh3CFt1eQZUHEAb3Li1hyPudPhSoFevrFY')
expect(processedConnection.theirLabel).toBe('test-label')
expect(processedConnection.threadId).toBe(connectionRequest.id)
expect(processedConnection.imageUrl).toBe(connectionImageUrl)
Expand Down Expand Up @@ -267,7 +267,7 @@ describe('ConnectionService', () => {
const processedConnection = await connectionService.processRequest(messageContext, outOfBand)

expect(processedConnection.state).toBe(DidExchangeState.RequestReceived)
expect(processedConnection.theirDid).toBe('did:peer:1zQmfPPbuG8vajHvYjGUW8CN5k9rLuuMmYSGBYwJqJDDUS72')
expect(processedConnection.theirDid).toBe('did:peer:1zQmW2esSyEVGzrh3CFt1eQZUHEAb3Li1hyPudPhSoFevrFY')
expect(processedConnection.theirLabel).toBe('test-label')
expect(processedConnection.threadId).toBe(connectionRequest.id)

Expand Down
28 changes: 28 additions & 0 deletions packages/core/src/modules/connections/__tests__/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,32 @@ describe('convertToNewDidDocument', () => {
}),
])
})

test('will use ; as an id mark instead of # if the # is missing in a service id', () => {
const oldDocument = new DidDoc({
id: 'did:sov:LjgpST2rjsoxYegQDRm7EL',
authentication: [],
publicKey: [],
service: [
new IndyAgentService({
id: 'did:sov:SKJVx2kn373FNgvff1SbJo;service-1',
serviceEndpoint: 'did:sov:SKJVx2kn373FNgvff1SbJo',
recipientKeys: ['EoGusetSxDJktp493VCyh981nUnzMamTRjvBaHZAy68d'],
routingKeys: ['EoGusetSxDJktp493VCyh981nUnzMamTRjvBaHZAy68d'],
priority: 5,
}),
],
})
const newDocument = convertToNewDidDocument(oldDocument)

expect(newDocument.service).toEqual([
new IndyAgentService({
id: '#service-1',
serviceEndpoint: 'did:sov:SKJVx2kn373FNgvff1SbJo',
recipientKeys: ['EoGusetSxDJktp493VCyh981nUnzMamTRjvBaHZAy68d'],
routingKeys: ['EoGusetSxDJktp493VCyh981nUnzMamTRjvBaHZAy68d'],
priority: 5,
}),
])
})
})
8 changes: 7 additions & 1 deletion packages/core/src/modules/connections/services/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,14 @@ export function convertToNewDidDocument(didDoc: DidDoc): DidDocument {
}

function normalizeId(fullId: string): `#${string}` {
const [, id] = fullId.split('#')
// Some old dids use `;` as the delimiter for the id. If we can't find a `#`
// and a `;` exists, we will parse everything after `;` as the id.
if (!fullId.includes('#') && fullId.includes(';')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This parser only works if there is a single ; in the id. Is that correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only usage I've seen is with one ;. I think it was used before the # and you can only include one. What we could do is leave the other ones in place (like url parsers do):

image

So we would get #indy;anotherword instead of #indy if the id was something;indy;anotherword. Do you think that is better?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think leaving them behind, which follows the url parser you showed, is good. I am very unaware of the security implications (likely none) here though.

const [, id] = fullId.split(';')
return `#${id ?? fullId}`
}

const [, id] = fullId.split('#')
return `#${id ?? fullId}`
}

Expand Down