Skip to content

Commit dfa1d6c

Browse files
authored
fix(cheqd): handle string serviceEndpoint for DidCommV1Service.type (#2484)
Signed-off-by: Sownak Roy <sownak@cheqd.io>
1 parent 3620dd7 commit dfa1d6c

5 files changed

Lines changed: 236 additions & 12 deletions

File tree

.changeset/chubby-rockets-grow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@credo-ts/cheqd": minor
3+
---
4+
5+
fix: handle string serviceEndpoint for DidCommV1Service.type

packages/cheqd/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"prepublishOnly": "pnpm run build"
3535
},
3636
"dependencies": {
37-
"@cheqd/sdk": "npm:@cheqd/sdk-esm@^5.3.4",
37+
"@cheqd/sdk": "npm:@cheqd/sdk-esm@^5.3.6",
3838
"@cheqd/ts-proto": "^4.1.1",
3939
"@cosmjs/crypto": "^0.33.1",
4040
"@cosmjs/proto-signing": "^0.33.1",

packages/cheqd/src/dids/didCheqdUtil.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { DirectSecp256k1HdWallet, DirectSecp256k1Wallet } from '@cosmjs/proto-si
1313
import {
1414
type AnyUint8Array,
1515
CredoError,
16+
DidCommV1Service,
1617
DidDocument,
1718
JsonEncoder,
1819
JsonTransformer,
@@ -64,7 +65,14 @@ export async function createMsgCreateDidDocPayloadToSign(didPayload: DIDDocument
6465
didPayload.service = didPayload.service?.map((e) => {
6566
return {
6667
...e,
67-
serviceEndpoint: Array.isArray(e.serviceEndpoint) ? e.serviceEndpoint : [e.serviceEndpoint],
68+
// For DIDComm V1 services (V2 already supports array), keep serviceEndpoint as string
69+
// For other services, convert to array if not already
70+
serviceEndpoint:
71+
e.type === DidCommV1Service.type
72+
? e.serviceEndpoint
73+
: Array.isArray(e.serviceEndpoint)
74+
? e.serviceEndpoint
75+
: [e.serviceEndpoint],
6876
}
6977
})
7078
const { protobufVerificationMethod, protobufService } = await DIDModule.validateSpecCompliantPayload(didPayload)

packages/cheqd/tests/cheqd-did-registrar.e2e.test.ts

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { DidDocument } from '@credo-ts/core'
22
import {
33
Agent,
4+
DidCommV1Service,
45
DidDocumentBuilder,
56
getEd25519VerificationKey2018,
67
getJsonWebKey2020,
@@ -84,7 +85,7 @@ describe('Cheqd DID registrar', () => {
8485
expect(did.didState).toMatchObject({ state: 'finished' })
8586
})
8687

87-
it('should create a did:cheqd using JsonWebKey2020', async () => {
88+
it('should create a did:cheqd using JsonWebKey2020 and update with serviceEndpoint as array', async () => {
8889
const createResult = await agent.dids.create<CheqdDidCreateOptions>({
8990
method: 'cheqd',
9091

@@ -135,6 +136,54 @@ describe('Cheqd DID registrar', () => {
135136
expect(resolvedDocument.didDocumentMetadata.deactivated).toBe(true)
136137
})
137138

139+
it('should create a did:cheqd using JsonWebKey2020 and update with DidCommV1Service', async () => {
140+
const createResult = await agent.dids.create<CheqdDidCreateOptions>({
141+
method: 'cheqd',
142+
options: {
143+
createKey: {
144+
type: {
145+
crv: 'Ed25519',
146+
kty: 'OKP',
147+
},
148+
keyId: 'another-key-id',
149+
},
150+
network: 'testnet',
151+
methodSpecificIdAlgo: 'uuid',
152+
},
153+
})
154+
expect(createResult).toMatchObject({
155+
didState: {
156+
state: 'finished',
157+
didDocument: {
158+
verificationMethod: [{ type: 'JsonWebKey2020' }],
159+
},
160+
},
161+
})
162+
expect(createResult.didState.did).toBeDefined()
163+
const did = createResult.didState.did as string
164+
const didDocument = createResult.didState.didDocument as DidDocument
165+
const verificationMethodId = didDocument.verificationMethod?.[0]?.id
166+
const service1 = new DidCommV1Service({
167+
id: `${did}#didcomm-1`,
168+
serviceEndpoint: 'https://this.endpoint.io',
169+
recipientKeys: [verificationMethodId ?? ''],
170+
accept: ['didcomm/aip2;env=rfc19'],
171+
priority: 0,
172+
})
173+
didDocument.service = [service1]
174+
const updateResult = await agent.dids.update({
175+
did,
176+
didDocument,
177+
})
178+
expect(updateResult).toMatchObject({
179+
didState: {
180+
state: 'finished',
181+
didDocument,
182+
},
183+
})
184+
expect(updateResult.didState.didDocument?.toJSON()).toMatchObject(didDocument.toJSON())
185+
})
186+
138187
it('should create a did:cheqd did using custom did document containing Ed25519 key', async () => {
139188
const did = `did:cheqd:testnet:${utils.uuid()}`
140189

0 commit comments

Comments
 (0)