@openid4vc/openid4vp 0.3.0-alpha-20250304095426 → 0.3.0-alpha-20250307131618

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as zod from 'zod';
2
2
  import zod__default, { z } from 'zod';
3
3
  import * as _openid4vc_oauth2 from '@openid4vc/oauth2';
4
- import { CallbackContext, JwtSigner, Jwk, JwtSignerWithJwk } from '@openid4vc/oauth2';
4
+ import { CallbackContext, JwtSigner, Jwk, JwtSignerWithJwk, HashAlgorithm } from '@openid4vc/oauth2';
5
5
 
6
6
  declare const zClientIdScheme: z.ZodEnum<["pre-registered", "redirect_uri", "https", "verifier_attestation", "did", "x509_san_dns", "x509_san_uri", "web-origin"]>;
7
7
  type ClientIdScheme = z.infer<typeof zClientIdScheme>;
@@ -11688,32 +11688,28 @@ type ParsedClientIdentifier = {
11688
11688
 
11689
11689
  declare const zTransactionEntry: z.ZodObject<{
11690
11690
  type: z.ZodString;
11691
- credential_ids: z.ZodArray<z.ZodString, "many">;
11691
+ credential_ids: z.ZodArray<z.ZodString, "atleastone">;
11692
11692
  transaction_data_hashes_alg: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
11693
11693
  }, "strip", z.ZodTypeAny, {
11694
11694
  type: string;
11695
- credential_ids: string[];
11695
+ credential_ids: [string, ...string[]];
11696
11696
  transaction_data_hashes_alg?: string[] | undefined;
11697
11697
  }, {
11698
11698
  type: string;
11699
- credential_ids: string[];
11699
+ credential_ids: [string, ...string[]];
11700
11700
  transaction_data_hashes_alg?: string[] | undefined;
11701
11701
  }>;
11702
11702
  type TransactionDataEntry = z.infer<typeof zTransactionEntry>;
11703
- declare const zTransactionData: z.ZodArray<z.ZodObject<{
11704
- type: z.ZodString;
11705
- credential_ids: z.ZodArray<z.ZodString, "many">;
11706
- transaction_data_hashes_alg: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
11707
- }, "strip", z.ZodTypeAny, {
11708
- type: string;
11709
- credential_ids: string[];
11710
- transaction_data_hashes_alg?: string[] | undefined;
11711
- }, {
11712
- type: string;
11713
- credential_ids: string[];
11714
- transaction_data_hashes_alg?: string[] | undefined;
11715
- }>, "many">;
11716
- type TransactionData = z.infer<typeof zTransactionData>;
11703
+
11704
+ interface ParseTransactionDataOptions {
11705
+ transactionData: string[];
11706
+ }
11707
+ interface ParsedTransactionDataEntry {
11708
+ transactionData: TransactionDataEntry;
11709
+ transactionDataIndex: number;
11710
+ encoded: string;
11711
+ }
11712
+ declare function parseTransactionData(options: ParseTransactionDataOptions): ParsedTransactionDataEntry[];
11717
11713
 
11718
11714
  interface ResolveOpenid4vpAuthorizationRequestOptions {
11719
11715
  requestPayload: Openid4vpAuthorizationRequest | JarAuthRequest;
@@ -11723,7 +11719,7 @@ interface ResolveOpenid4vpAuthorizationRequestOptions {
11723
11719
  callbacks: Pick<CallbackContext, 'verifyJwt' | 'decryptJwe' | 'getX509CertificateMetadata'>;
11724
11720
  }
11725
11721
  type ResolvedOpenid4vpAuthRequest = {
11726
- transactionData?: TransactionData;
11722
+ transactionData?: ParsedTransactionDataEntry[];
11727
11723
  requestPayload: Openid4vpAuthorizationRequest | Openid4vpAuthorizationRequestDcApi;
11728
11724
  jar: VerifiedJarRequest | undefined;
11729
11725
  client: ParsedClientIdentifier;
@@ -11871,11 +11867,6 @@ interface ValidateOpenid4vpAuthorizationResponseOptions {
11871
11867
  */
11872
11868
  declare function validateOpenid4vpAuthorizationResponsePayload(options: ValidateOpenid4vpAuthorizationResponseOptions): ValidateOpenid4VpAuthorizationResponseResult;
11873
11869
 
11874
- interface ParseTransactionDataOptions {
11875
- transactionData: string[];
11876
- }
11877
- declare function parseTransactionData(options: ParseTransactionDataOptions): TransactionData;
11878
-
11879
11870
  declare function parsePexVpToken(vpToken: unknown): [VpTokenPexEntry, ...VpTokenPexEntry[]];
11880
11871
  declare function parseDcqlVpToken(vpToken: unknown): VpTokenDcql;
11881
11872
 
@@ -11925,6 +11916,39 @@ declare class Openid4vpClient {
11925
11916
  }>;
11926
11917
  }
11927
11918
 
11919
+ interface TransactionDataHashesCredentials {
11920
+ /**
11921
+ * credentialId is the pex input descriptor id
11922
+ * or dcql credential query id
11923
+ *
11924
+ * The values must be an array of transaction data hashes
11925
+ */
11926
+ [credentialId: string]: {
11927
+ /**
11928
+ * The hashes of the transaction data
11929
+ */
11930
+ transaction_data_hashes: string[];
11931
+ /**
11932
+ * The transaction data hash alg. If not provided
11933
+ * in the presentation, the default value of sha256
11934
+ * is used.
11935
+ */
11936
+ transaction_data_hashes_alg?: string;
11937
+ } | undefined;
11938
+ }
11939
+ interface VerifyTransactionDataOptions {
11940
+ transactionData: string[];
11941
+ credentials: TransactionDataHashesCredentials;
11942
+ callbacks: Pick<CallbackContext, 'hash'>;
11943
+ }
11944
+ interface VerifiedTransactionDataEntry {
11945
+ transactionDataEntry: ParsedTransactionDataEntry;
11946
+ credentialId: string;
11947
+ hash: string;
11948
+ hashAlg: HashAlgorithm;
11949
+ credentialHashIndex: number;
11950
+ }
11951
+
11928
11952
  interface Openid4vpVerifierOptions {
11929
11953
  /**
11930
11954
  * Callbacks required for the openid4vp verifier
@@ -13445,11 +13469,8 @@ declare class Openid4vpVerifier {
13445
13469
  validateOpenid4vpAuthorizationResponsePayload(options: ValidateOpenid4vpAuthorizationResponseOptions): ValidateOpenid4VpAuthorizationResponseResult;
13446
13470
  parsePexVpToken(vpToken: unknown): [string | Record<string, any>, ...(string | Record<string, any>)[]];
13447
13471
  parseDcqlVpToken(vpToken: unknown): Record<string, string | Record<string, any>>;
13448
- parseTransactionData(options: ParseTransactionDataOptions): {
13449
- type: string;
13450
- credential_ids: string[];
13451
- transaction_data_hashes_alg?: string[] | undefined;
13452
- }[];
13472
+ parseTransactionData(options: ParseTransactionDataOptions): ParsedTransactionDataEntry[];
13473
+ verifyTransactionData(options: VerifyTransactionDataOptions): Promise<VerifiedTransactionDataEntry[]>;
13453
13474
  }
13454
13475
 
13455
13476
  declare const jarmResponseMode: readonly ["jwt", "query.jwt", "fragment.jwt", "form_post.jwt", "direct_post.jwt", "dc_api.jwt"];
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as zod from 'zod';
2
2
  import zod__default, { z } from 'zod';
3
3
  import * as _openid4vc_oauth2 from '@openid4vc/oauth2';
4
- import { CallbackContext, JwtSigner, Jwk, JwtSignerWithJwk } from '@openid4vc/oauth2';
4
+ import { CallbackContext, JwtSigner, Jwk, JwtSignerWithJwk, HashAlgorithm } from '@openid4vc/oauth2';
5
5
 
6
6
  declare const zClientIdScheme: z.ZodEnum<["pre-registered", "redirect_uri", "https", "verifier_attestation", "did", "x509_san_dns", "x509_san_uri", "web-origin"]>;
7
7
  type ClientIdScheme = z.infer<typeof zClientIdScheme>;
@@ -11688,32 +11688,28 @@ type ParsedClientIdentifier = {
11688
11688
 
11689
11689
  declare const zTransactionEntry: z.ZodObject<{
11690
11690
  type: z.ZodString;
11691
- credential_ids: z.ZodArray<z.ZodString, "many">;
11691
+ credential_ids: z.ZodArray<z.ZodString, "atleastone">;
11692
11692
  transaction_data_hashes_alg: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
11693
11693
  }, "strip", z.ZodTypeAny, {
11694
11694
  type: string;
11695
- credential_ids: string[];
11695
+ credential_ids: [string, ...string[]];
11696
11696
  transaction_data_hashes_alg?: string[] | undefined;
11697
11697
  }, {
11698
11698
  type: string;
11699
- credential_ids: string[];
11699
+ credential_ids: [string, ...string[]];
11700
11700
  transaction_data_hashes_alg?: string[] | undefined;
11701
11701
  }>;
11702
11702
  type TransactionDataEntry = z.infer<typeof zTransactionEntry>;
11703
- declare const zTransactionData: z.ZodArray<z.ZodObject<{
11704
- type: z.ZodString;
11705
- credential_ids: z.ZodArray<z.ZodString, "many">;
11706
- transaction_data_hashes_alg: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
11707
- }, "strip", z.ZodTypeAny, {
11708
- type: string;
11709
- credential_ids: string[];
11710
- transaction_data_hashes_alg?: string[] | undefined;
11711
- }, {
11712
- type: string;
11713
- credential_ids: string[];
11714
- transaction_data_hashes_alg?: string[] | undefined;
11715
- }>, "many">;
11716
- type TransactionData = z.infer<typeof zTransactionData>;
11703
+
11704
+ interface ParseTransactionDataOptions {
11705
+ transactionData: string[];
11706
+ }
11707
+ interface ParsedTransactionDataEntry {
11708
+ transactionData: TransactionDataEntry;
11709
+ transactionDataIndex: number;
11710
+ encoded: string;
11711
+ }
11712
+ declare function parseTransactionData(options: ParseTransactionDataOptions): ParsedTransactionDataEntry[];
11717
11713
 
11718
11714
  interface ResolveOpenid4vpAuthorizationRequestOptions {
11719
11715
  requestPayload: Openid4vpAuthorizationRequest | JarAuthRequest;
@@ -11723,7 +11719,7 @@ interface ResolveOpenid4vpAuthorizationRequestOptions {
11723
11719
  callbacks: Pick<CallbackContext, 'verifyJwt' | 'decryptJwe' | 'getX509CertificateMetadata'>;
11724
11720
  }
11725
11721
  type ResolvedOpenid4vpAuthRequest = {
11726
- transactionData?: TransactionData;
11722
+ transactionData?: ParsedTransactionDataEntry[];
11727
11723
  requestPayload: Openid4vpAuthorizationRequest | Openid4vpAuthorizationRequestDcApi;
11728
11724
  jar: VerifiedJarRequest | undefined;
11729
11725
  client: ParsedClientIdentifier;
@@ -11871,11 +11867,6 @@ interface ValidateOpenid4vpAuthorizationResponseOptions {
11871
11867
  */
11872
11868
  declare function validateOpenid4vpAuthorizationResponsePayload(options: ValidateOpenid4vpAuthorizationResponseOptions): ValidateOpenid4VpAuthorizationResponseResult;
11873
11869
 
11874
- interface ParseTransactionDataOptions {
11875
- transactionData: string[];
11876
- }
11877
- declare function parseTransactionData(options: ParseTransactionDataOptions): TransactionData;
11878
-
11879
11870
  declare function parsePexVpToken(vpToken: unknown): [VpTokenPexEntry, ...VpTokenPexEntry[]];
11880
11871
  declare function parseDcqlVpToken(vpToken: unknown): VpTokenDcql;
11881
11872
 
@@ -11925,6 +11916,39 @@ declare class Openid4vpClient {
11925
11916
  }>;
11926
11917
  }
11927
11918
 
11919
+ interface TransactionDataHashesCredentials {
11920
+ /**
11921
+ * credentialId is the pex input descriptor id
11922
+ * or dcql credential query id
11923
+ *
11924
+ * The values must be an array of transaction data hashes
11925
+ */
11926
+ [credentialId: string]: {
11927
+ /**
11928
+ * The hashes of the transaction data
11929
+ */
11930
+ transaction_data_hashes: string[];
11931
+ /**
11932
+ * The transaction data hash alg. If not provided
11933
+ * in the presentation, the default value of sha256
11934
+ * is used.
11935
+ */
11936
+ transaction_data_hashes_alg?: string;
11937
+ } | undefined;
11938
+ }
11939
+ interface VerifyTransactionDataOptions {
11940
+ transactionData: string[];
11941
+ credentials: TransactionDataHashesCredentials;
11942
+ callbacks: Pick<CallbackContext, 'hash'>;
11943
+ }
11944
+ interface VerifiedTransactionDataEntry {
11945
+ transactionDataEntry: ParsedTransactionDataEntry;
11946
+ credentialId: string;
11947
+ hash: string;
11948
+ hashAlg: HashAlgorithm;
11949
+ credentialHashIndex: number;
11950
+ }
11951
+
11928
11952
  interface Openid4vpVerifierOptions {
11929
11953
  /**
11930
11954
  * Callbacks required for the openid4vp verifier
@@ -13445,11 +13469,8 @@ declare class Openid4vpVerifier {
13445
13469
  validateOpenid4vpAuthorizationResponsePayload(options: ValidateOpenid4vpAuthorizationResponseOptions): ValidateOpenid4VpAuthorizationResponseResult;
13446
13470
  parsePexVpToken(vpToken: unknown): [string | Record<string, any>, ...(string | Record<string, any>)[]];
13447
13471
  parseDcqlVpToken(vpToken: unknown): Record<string, string | Record<string, any>>;
13448
- parseTransactionData(options: ParseTransactionDataOptions): {
13449
- type: string;
13450
- credential_ids: string[];
13451
- transaction_data_hashes_alg?: string[] | undefined;
13452
- }[];
13472
+ parseTransactionData(options: ParseTransactionDataOptions): ParsedTransactionDataEntry[];
13473
+ verifyTransactionData(options: VerifyTransactionDataOptions): Promise<VerifiedTransactionDataEntry[]>;
13453
13474
  }
13454
13475
 
13455
13476
  declare const jarmResponseMode: readonly ["jwt", "query.jwt", "fragment.jwt", "form_post.jwt", "direct_post.jwt", "dc_api.jwt"];
package/dist/index.js CHANGED
@@ -1096,7 +1096,7 @@ var import_utils12 = require("@openid4vc/utils");
1096
1096
  var import_zod14 = require("zod");
1097
1097
  var zTransactionEntry = import_zod14.z.object({
1098
1098
  type: import_zod14.z.string(),
1099
- credential_ids: import_zod14.z.array(import_zod14.z.string()).min(1),
1099
+ credential_ids: import_zod14.z.array(import_zod14.z.string()).nonempty(),
1100
1100
  transaction_data_hashes_alg: import_zod14.z.array(import_zod14.z.string()).optional()
1101
1101
  });
1102
1102
  var zTransactionData = import_zod14.z.array(zTransactionEntry);
@@ -1112,7 +1112,11 @@ function parseTransactionData(options) {
1112
1112
  error_description: "Failed to parse transaction data."
1113
1113
  });
1114
1114
  }
1115
- return parsedResult.data;
1115
+ return parsedResult.data.map((decoded2, index) => ({
1116
+ transactionData: decoded2,
1117
+ encoded: transactionData[index],
1118
+ transactionDataIndex: index
1119
+ }));
1116
1120
  }
1117
1121
 
1118
1122
  // src/authorization-request/resolve-authorization-request.ts
@@ -1674,6 +1678,71 @@ var Openid4vpClient = class {
1674
1678
  }
1675
1679
  };
1676
1680
 
1681
+ // src/transaction-data/verify-transaction-data.ts
1682
+ var import_oauth228 = require("@openid4vc/oauth2");
1683
+ var import_utils21 = require("@openid4vc/utils");
1684
+ async function verifyTransactionData(options) {
1685
+ const parsedTransactionData = parseTransactionData({
1686
+ transactionData: options.transactionData
1687
+ });
1688
+ const matchedEntries = [];
1689
+ for (const parsedEntry of parsedTransactionData) {
1690
+ const matchedEntry = await verifyTransactionDataEntry({
1691
+ entry: parsedEntry,
1692
+ callbacks: options.callbacks,
1693
+ credentials: options.credentials
1694
+ });
1695
+ matchedEntries.push(matchedEntry);
1696
+ }
1697
+ return matchedEntries;
1698
+ }
1699
+ async function verifyTransactionDataEntry({
1700
+ entry,
1701
+ credentials,
1702
+ callbacks
1703
+ }) {
1704
+ const allowedAlgs = entry.transactionData.transaction_data_hashes_alg ?? ["sha-256"];
1705
+ const supportedAlgs = allowedAlgs.filter(
1706
+ (alg) => Object.values(import_oauth228.HashAlgorithm).includes(alg)
1707
+ );
1708
+ const hashes = {};
1709
+ for (const alg of supportedAlgs) {
1710
+ hashes[alg] = (0, import_utils21.encodeToBase64Url)(await callbacks.hash((0, import_utils21.decodeUtf8String)(entry.encoded), alg));
1711
+ }
1712
+ for (const credentialId of entry.transactionData.credential_ids) {
1713
+ const transactionDataHashesCredential = credentials[credentialId];
1714
+ if (!transactionDataHashesCredential) continue;
1715
+ const alg = transactionDataHashesCredential.transaction_data_hashes_alg ?? "sha-256";
1716
+ const hash = hashes[alg];
1717
+ if (!allowedAlgs.includes(alg)) {
1718
+ throw new import_oauth228.Oauth2ServerErrorResponseError({
1719
+ error: import_oauth228.Oauth2ErrorCodes.InvalidTransactionData,
1720
+ error_description: `Transaction data entry with index ${entry.transactionDataIndex} is hashed using alg '${alg}'. However transaction data only allows alg values ${allowedAlgs.join(", ")}.`
1721
+ });
1722
+ }
1723
+ if (!hash) {
1724
+ throw new import_oauth228.Oauth2ServerErrorResponseError({
1725
+ error: import_oauth228.Oauth2ErrorCodes.InvalidTransactionData,
1726
+ error_description: `Transaction data entry with index ${entry.transactionDataIndex} is hashed using unsupported alg '${alg}'. This library only supports verification of transaction data hashes using alg values ${Object.values(import_oauth228.HashAlgorithm).join(", ")}. Either verify the hashes outside of this library, or limit the allowed alg values to the ones supported by this library.`
1727
+ });
1728
+ }
1729
+ const credentialHashIndex = transactionDataHashesCredential.transaction_data_hashes.indexOf(hash);
1730
+ if (credentialHashIndex !== -1) {
1731
+ return {
1732
+ transactionDataEntry: entry,
1733
+ credentialId,
1734
+ hash,
1735
+ hashAlg: alg,
1736
+ credentialHashIndex
1737
+ };
1738
+ }
1739
+ }
1740
+ throw new import_oauth228.Oauth2ServerErrorResponseError({
1741
+ error: import_oauth228.Oauth2ErrorCodes.InvalidTransactionData,
1742
+ error_description: `Transaction data entry with index ${entry.transactionDataIndex} does not have a matching hash in any of the submitted credentials`
1743
+ });
1744
+ }
1745
+
1677
1746
  // src/Openid4vpVerifier.ts
1678
1747
  var Openid4vpVerifier = class {
1679
1748
  constructor(options) {
@@ -1700,6 +1769,9 @@ var Openid4vpVerifier = class {
1700
1769
  parseTransactionData(options) {
1701
1770
  return parseTransactionData(options);
1702
1771
  }
1772
+ verifyTransactionData(options) {
1773
+ return verifyTransactionData(options);
1774
+ }
1703
1775
  };
1704
1776
 
1705
1777
  // src/models/z-credential-formats.ts