fix: update offerGiverDid to use credentialSubject.offeredBy

The offerGiverDid function was looking for offeredBy at the root level of the
OfferVerifiableCredential, but it was moved to credentialSubject in our interface
changes. This fix updates the function to look in the correct location while
maintaining the same fallback behavior of using the issuer if offeredBy is not
available.

- Update path from claim.offeredBy to claim.credentialSubject.offeredBy
- Remove unnecessary string type cast
- Keep issuer fallback behavior unchanged
This commit is contained in:
Matthew Raymer
2025-05-28 10:41:39 +00:00
parent 7f17a3d9c7
commit e4f859a116
2 changed files with 65 additions and 6 deletions

View File

@@ -9,7 +9,6 @@ export interface AgreeVerifiableCredential {
// Note that previous VCs may have additional fields. // Note that previous VCs may have additional fields.
// https://endorser.ch/doc/html/transactions.html#id4 // https://endorser.ch/doc/html/transactions.html#id4
export interface GiveVerifiableCredential extends GenericVerifiableCredential { export interface GiveVerifiableCredential extends GenericVerifiableCredential {
"@context"?: string;
"@type": "GiveAction"; "@type": "GiveAction";
agent?: { identifier: string }; agent?: { identifier: string };
description?: string; description?: string;
@@ -19,14 +18,45 @@ export interface GiveVerifiableCredential extends GenericVerifiableCredential {
object?: { amountOfThisGood: number; unitCode: string }; object?: { amountOfThisGood: number; unitCode: string };
provider?: GenericVerifiableCredential; provider?: GenericVerifiableCredential;
recipient?: { identifier: string }; recipient?: { identifier: string };
type: string[];
issuer: string;
issuanceDate: string;
credentialSubject: {
id: string;
type: "GiveAction";
offeredBy?: {
type: "Person";
identifier: string;
};
offeredTo?: {
type: "Person";
identifier: string;
};
offeredToProject?: {
type: "Project";
identifier: string;
};
offeredToProjectVisibleToDids?: string[];
offeredToVisibleToDids?: string[];
offeredByVisibleToDids?: string[];
amount: {
type: "QuantitativeValue";
value: number;
unitCode: string;
};
startTime?: string;
endTime?: string;
};
} }
// Note that previous VCs may have additional fields. // Note that previous VCs may have additional fields.
// https://endorser.ch/doc/html/transactions.html#id8 // https://endorser.ch/doc/html/transactions.html#id8
export interface OfferVerifiableCredential extends GenericVerifiableCredential { export interface OfferVerifiableCredential extends GenericVerifiableCredential {
"@context"?: string;
"@type": "Offer"; "@type": "Offer";
description?: string; description?: string;
fulfills?: { "@type": string; identifier?: string; lastClaimId?: string }[];
identifier?: string;
image?: string;
includesObject?: { amountOfThisGood: number; unitCode: string }; includesObject?: { amountOfThisGood: number; unitCode: string };
itemOffered?: { itemOffered?: {
description?: string; description?: string;
@@ -37,9 +67,38 @@ export interface OfferVerifiableCredential extends GenericVerifiableCredential {
name?: string; name?: string;
}; };
}; };
offeredBy?: { identifier: string }; provider?: GenericVerifiableCredential;
recipient?: { identifier: string }; recipient?: { identifier: string };
validThrough?: string; validThrough?: string;
type: string[];
issuer: string;
issuanceDate: string;
credentialSubject: {
id: string;
type: "Offer";
offeredBy?: {
type: "Person";
identifier: string;
};
offeredTo?: {
type: "Person";
identifier: string;
};
offeredToProject?: {
type: "Project";
identifier: string;
};
offeredToProjectVisibleToDids?: string[];
offeredToVisibleToDids?: string[];
offeredByVisibleToDids?: string[];
amount: {
type: "QuantitativeValue";
value: number;
unitCode: string;
};
startTime?: string;
endTime?: string;
};
} }
// Note that previous VCs may have additional fields. // Note that previous VCs may have additional fields.

View File

@@ -389,10 +389,10 @@ export function offerGiverDid(
let giver; let giver;
const claim = veriClaim.claim as OfferVerifiableCredential; const claim = veriClaim.claim as OfferVerifiableCredential;
if ( if (
claim.offeredBy?.identifier && claim.credentialSubject.offeredBy?.identifier &&
!serverUtil.isHiddenDid(claim.offeredBy.identifier as string) !serverUtil.isHiddenDid(claim.credentialSubject.offeredBy.identifier)
) { ) {
giver = claim.offeredBy.identifier; giver = claim.credentialSubject.offeredBy.identifier;
} else if (veriClaim.issuer && !serverUtil.isHiddenDid(veriClaim.issuer)) { } else if (veriClaim.issuer && !serverUtil.isHiddenDid(veriClaim.issuer)) {
giver = veriClaim.issuer; giver = veriClaim.issuer;
} }