Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions packages/app-runtime/src/AppStringProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { OpenId4VciResolvedCredentialOffer } from "@credo-ts/openid4vc";
import { ILogger, ILoggerFactory } from "@js-soft/logging-abstractions";
import { Serializable } from "@js-soft/ts-serval";
import { EventBus, Result } from "@js-soft/ts-utils";
import { VerifiablePresentation } from "@nmshd/content";
import { TokenContentVerifiablePresentation } from "@nmshd/content";
import { ICoreAddress, Reference } from "@nmshd/core-types";
import { AnonymousServices, DeviceMapper, RuntimeServices } from "@nmshd/runtime";
import { BackboneIds, TokenContentDeviceSharedSecret } from "@nmshd/transport";
Expand Down Expand Up @@ -292,7 +292,7 @@ export class AppStringProcessor {
case "Token":
const tokenContent = this.parseTokenContent(result.value.value.content);

if (tokenContent instanceof VerifiablePresentation) {
if (tokenContent instanceof TokenContentVerifiablePresentation) {
// TODO: add technical validation
await uiBridge.showVerifiablePresentation(account, result.value.value, true);
break;
Expand Down
4 changes: 2 additions & 2 deletions packages/app-runtime/test/runtime/AppStringProcessor.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ArbitraryRelationshipTemplateContentJSON, AuthenticationRequestItem, RelationshipTemplateContent, VerifiablePresentation } from "@nmshd/content";
import { ArbitraryRelationshipTemplateContentJSON, AuthenticationRequestItem, RelationshipTemplateContent, TokenContentVerifiablePresentation } from "@nmshd/content";
import { CoreDate, PasswordLocationIndicatorOptions } from "@nmshd/core-types";
import { DeviceOnboardingInfoDTO, PeerRelationshipTemplateLoadedEvent } from "@nmshd/runtime";
import assert from "assert";
Expand Down Expand Up @@ -379,7 +379,7 @@ describe("AppStringProcessor", function () {

test("get a token with verifiable presentation content using a url", async function () {
const tokenResult = await runtime1Session.transportServices.tokens.createOwnToken({
content: VerifiablePresentation.from({
content: TokenContentVerifiablePresentation.from({
value: { claim: "test" },
type: "dc+sd-jwt"
}).toJSON(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DcqlValidCredential, W3cJsonCredential } from "@credo-ts/core";
import { OpenId4VciResolvedCredentialOffer, OpenId4VpResolvedAuthorizationRequest } from "@credo-ts/openid4vc";
import { VerifiableCredential, VerifiablePresentation } from "@nmshd/content";
import { TokenContentVerifiablePresentation, VerifiableCredential } from "@nmshd/content";
import { ConsumptionBaseController } from "../../consumption/ConsumptionBaseController";
import { ConsumptionController } from "../../consumption/ConsumptionController";
import { ConsumptionControllerName } from "../../consumption/ConsumptionControllerName";
Expand Down Expand Up @@ -130,7 +130,7 @@ export class OpenId4VcController extends ConsumptionBaseController {
return { status: serverResponse.status, message: serverResponse.body };
}

public async createPresentationTokenContent(credential: VerifiableCredential): Promise<VerifiablePresentation> {
public async createPresentationTokenContent(credential: VerifiableCredential): Promise<TokenContentVerifiablePresentation> {
return await this.holder.createPresentationTokenContent(credential);
}
}
6 changes: 3 additions & 3 deletions packages/consumption/src/modules/openid4vc/local/Holder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
X509Module
} from "@credo-ts/core";
import { OpenId4VciCredentialResponse, OpenId4VcModule, type OpenId4VciResolvedCredentialOffer, type OpenId4VpResolvedAuthorizationRequest } from "@credo-ts/openid4vc";
import { VerifiableCredential, VerifiablePresentation } from "@nmshd/content";
import { TokenContentVerifiablePresentation, VerifiableCredential } from "@nmshd/content";
import { AccountController } from "@nmshd/transport";
import { AttributesController, OwnIdentityAttribute } from "../../attributes";
import { BaseAgent } from "./BaseAgent";
Expand Down Expand Up @@ -204,7 +204,7 @@ export class Holder extends BaseAgent<ReturnType<typeof getOpenIdHolderModules>>

// hacky solution because credo doesn't support credentials without key binding
// TODO: use credentials without key binding once supported
public async createPresentationTokenContent(credential: VerifiableCredential): Promise<VerifiablePresentation> {
public async createPresentationTokenContent(credential: VerifiableCredential): Promise<TokenContentVerifiablePresentation> {
if (credential.type !== ClaimFormat.SdJwtDc) throw new Error("Only SD-JWT credentials have been tested so far with token presentation");

const sdJwtVcApi = this.agent.dependencyManager.resolve(SdJwtVcApi);
Expand All @@ -217,7 +217,7 @@ export class Holder extends BaseAgent<ReturnType<typeof getOpenIdHolderModules>>
}
});

return VerifiablePresentation.from({
return TokenContentVerifiablePresentation.from({
value: presentation,
type: credential.type,
displayInformation: credential.displayInformation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AbstractAttributeQuery, AbstractAttributeQueryJSON, IAbstractAttributeQ
import { AttributeValues } from "./AttributeValueTypes";
import { IValueHints, ValueHints, ValueHintsJSON } from "./hints";
import { RelationshipAttributeConfidentiality } from "./RelationshipAttributeConfidentiality";
import { PROPRIETARY_ATTRIBUTE_MAX_DESCRIPTION_LENGTH, PROPRIETARY_ATTRIBUTE_MAX_TITLE_LENGTH } from "./types/proprietary/ProprietaryAttributeValue";
import { PROPRIETARY_ATTRIBUTE_MAX_DESCRIPTION_LENGTH, PROPRIETARY_ATTRIBUTE_MAX_TITLE_LENGTH } from "./types/proprietary";

export interface RelationshipAttributeCreationHintsJSON {
title: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { serialize, type, validate } from "@js-soft/ts-serval";
import { AbstractAttributeValue, AbstractAttributeValueJSON, IAbstractAttributeValue } from "../AbstractAttributeValue";
import { RenderHints, RenderHintsEditType, RenderHintsTechnicalType, ValueHints } from "../hints";
import { PROPRIETARY_ATTRIBUTE_MAX_DESCRIPTION_LENGTH } from "./proprietary/ProprietaryAttributeValue";
import { PROPRIETARY_ATTRIBUTE_MAX_DESCRIPTION_LENGTH } from "./proprietary";

export interface VerifiableCredentialJSON extends AbstractAttributeValueJSON {
"@type": "VerifiableCredential";
Expand Down
69 changes: 0 additions & 69 deletions packages/content/src/attributes/types/VerifiablePresentation.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/content/src/attributes/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ export * from "./relationship";
export * from "./statement";
export * from "./strings";
export * from "./VerifiableCredential";
export * from "./VerifiablePresentation";
1 change: 1 addition & 0 deletions packages/content/src/attributes/types/proprietary/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./ProprietaryAttributeValue";
export * from "./ProprietaryBoolean";
export * from "./ProprietaryCountry";
export * from "./ProprietaryEMailAddress";
Expand Down
1 change: 1 addition & 0 deletions packages/content/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export * from "./messages";
export * from "./notifications";
export * from "./relationships";
export * from "./requests";
export * from "./tokens";
export * from "./ValidationErrorWithoutProperty";
57 changes: 57 additions & 0 deletions packages/content/src/tokens/TokenContentVerifiablePresentation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { ISerializable, Serializable, serialize, type, validate } from "@js-soft/ts-serval";
import { ContentJSON } from "../ContentJSON";
import { PROPRIETARY_ATTRIBUTE_MAX_DESCRIPTION_LENGTH } from "../attributes";

export interface TokenContentVerifiablePresentationJSON extends ContentJSON {
"@type": "TokenContentVerifiablePresentation";
value: string | Record<string, any>;
type: string;
displayInformation?: Record<string, any>[];
}

export interface ITokenContentVerifiablePresentation extends ISerializable {
value: string | Record<string, any>;
type: string;
displayInformation?: Record<string, any>[];
}

@type("TokenContentVerifiablePresentation")
export class TokenContentVerifiablePresentation extends Serializable implements ITokenContentVerifiablePresentation {
@serialize({ any: true })
@validate({ customValidator: validateValue })
public value: string | Record<string, any>;

@serialize()
@validate({ nullable: true })
public type: string;

@serialize()
@validate({ nullable: true, max: PROPRIETARY_ATTRIBUTE_MAX_DESCRIPTION_LENGTH })
public displayInformation?: Record<string, any>[];

public static from(value: ITokenContentVerifiablePresentation | Omit<TokenContentVerifiablePresentationJSON, "@type">): TokenContentVerifiablePresentation {
return this.fromAny(value);
}

public override toJSON(verbose?: boolean | undefined, serializeAsString?: boolean | undefined): TokenContentVerifiablePresentationJSON {
return super.toJSON(verbose, serializeAsString) as TokenContentVerifiablePresentationJSON;
}
}

function validateValue(value: any) {
try {
const string = JSON.stringify(value);
// the length corresponds to 50MB - maybe this needs to be restricted further in the future
if (string.length > 52428800) {
return "stringified value must not be longer than 52428800 characters";
}
} catch (e) {
if (e instanceof SyntaxError) {
return "must be a valid JSON object";
}

return "could not validate value";
}

return undefined;
}
1 change: 1 addition & 0 deletions packages/content/src/tokens/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./TokenContentVerifiablePresentation";
10 changes: 5 additions & 5 deletions packages/runtime/test/consumption/openid4vc.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SdJwtVcRecord } from "@credo-ts/core";
import { EudiploClient } from "@eudiplo/sdk-core";
import { AcceptProposeAttributeRequestItemParametersWithNewAttributeJSON, AcceptShareAuthorizationRequestRequestItemParametersJSON, decodeRecord } from "@nmshd/consumption";
import { RequestJSON, ShareAuthorizationRequestRequestItemJSON, VerifiableCredentialJSON, VerifiablePresentation } from "@nmshd/content";
import { RequestJSON, ShareAuthorizationRequestRequestItemJSON, TokenContentVerifiablePresentation, VerifiableCredentialJSON } from "@nmshd/content";
import { CoreDate } from "@nmshd/core-types";
import axios, { AxiosInstance } from "axios";
import * as client from "openid-client";
Expand Down Expand Up @@ -284,10 +284,10 @@ describe("EUDIPLO", () => {

const presentationTokenContent = presentationTokenResult.value.content;
expect(presentationTokenContent).toBeDefined();
expect(presentationTokenContent["@type"]).toBe("VerifiablePresentation");
expect((presentationTokenContent as VerifiablePresentation).value).toBeDefined();
expect((presentationTokenContent as VerifiablePresentation).displayInformation).toBeDefined();
expect((presentationTokenContent as VerifiablePresentation).displayInformation![0].name).toBe("test");
expect(presentationTokenContent["@type"]).toBe("TokenContentVerifiablePresentation");
expect((presentationTokenContent as TokenContentVerifiablePresentation).value).toBeDefined();
expect((presentationTokenContent as TokenContentVerifiablePresentation).displayInformation).toBeDefined();
expect((presentationTokenContent as TokenContentVerifiablePresentation).displayInformation![0].name).toBe("test");
});
});

Expand Down
Loading