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: Add context only for linkedDomains #381

Merged
merged 13 commits into from
Sep 10, 2024
29 changes: 16 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"cosmjs-types": "^0.9.0",
"did-jwt": "^8.0.4",
"did-resolver": "^4.1.0",
"file-type": "^19.4.1",
"file-type": "^19.5.0",
"multiformats": "^13.2.2",
"secp256k1": "^5.0.0",
"uuid": "^10.0.0"
Expand All @@ -79,16 +79,16 @@
"@semantic-release/npm": "^12.0.1",
"@semantic-release/release-notes-generator": "^14.0.1",
"@types/jest": "^29.5.12",
"@types/node": "^20.16.1",
"@types/node": "^20.16.5",
"@types/uuid": "^10.0.0",
"conventional-changelog-conventionalcommits": "^8.0.0",
"cross-env": "^7.0.3",
"jest": "^29.7.0",
"prettier": "^3.3.3",
"semantic-release": "^24.0.0",
"semantic-release": "^24.1.0",
"ts-jest": "^29.1.2",
"ts-node": "^10.9.2",
"typescript": "^5.5.4",
"typescript": "^5.6.2",
"uint8arrays": "^5.1.0"
},
"publishConfig": {
Expand Down
12 changes: 5 additions & 7 deletions src/modules/did.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
SpecValidationResult,
VerificationMethods,
DIDDocumentWithMetadata,
ServiceType,
} from '../types.js';
import {
MsgCreateDidDoc,
Expand Down Expand Up @@ -45,7 +46,7 @@ export const contexts = {
W3CSuiteEd255192020: 'https://w3id.org/security/suites/ed25519-2020/v1',
W3CSuiteEd255192018: 'https://w3id.org/security/suites/ed25519-2018/v1',
W3CSuiteJws2020: 'https://w3id.org/security/suites/jws-2020/v1',
DIFDIDConfiguration: 'https://identity.foundation/.well-known/did-configuration/v1',
LinkedDomainsContext: 'https://identity.foundation/.well-known/did-configuration/v1',
} as const;

export const protobufLiterals = {
Expand Down Expand Up @@ -538,6 +539,9 @@ export class DIDModule extends AbstractCheqdSDKModule {
});

const service = protobufDidDocument.service.map((s) => {
if (s.serviceType === ServiceType.LinkedDomains)
protobufDidDocument.context = [...protobufDidDocument.context, contexts.LinkedDomainsContext];

return {
id: s.id,
type: s.serviceType,
Expand All @@ -546,12 +550,6 @@ export class DIDModule extends AbstractCheqdSDKModule {
});

const context = (function () {
if (
protobufDidDocument.service.length &&
!protobufDidDocument.context.includes(contexts.DIFDIDConfiguration)
)
protobufDidDocument.context.push(contexts.DIFDIDConfiguration);

if (protobufDidDocument.context.includes(contexts.W3CDIDv1)) return protobufDidDocument.context;

return [contexts.W3CDIDv1, ...protobufDidDocument.context];
Expand Down
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,7 @@ export const ISignInputs = {
return object.some((x) => 'privateKeyHex' in x);
},
};

export enum ServiceType {
LinkedDomains = 'LinkedDomains',
}