@sphereon/oid4vci-client 0.2.0 → 0.4.1-unstable.247

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.
Files changed (116) hide show
  1. package/LICENSE +201 -201
  2. package/README.md +494 -371
  3. package/dist/AccessTokenClient.d.ts +30 -0
  4. package/dist/AccessTokenClient.d.ts.map +1 -0
  5. package/dist/AccessTokenClient.js +226 -0
  6. package/dist/AccessTokenClient.js.map +1 -0
  7. package/dist/AuthorizationDetailsBuilder.d.ts +11 -0
  8. package/dist/AuthorizationDetailsBuilder.d.ts.map +1 -0
  9. package/dist/AuthorizationDetailsBuilder.js +44 -0
  10. package/dist/AuthorizationDetailsBuilder.js.map +1 -0
  11. package/dist/CredentialOffer.d.ts +6 -0
  12. package/dist/CredentialOffer.d.ts.map +1 -0
  13. package/dist/CredentialOffer.js +49 -0
  14. package/dist/CredentialOffer.js.map +1 -0
  15. package/dist/CredentialRequestClient.d.ts +29 -0
  16. package/dist/CredentialRequestClient.d.ts.map +1 -0
  17. package/dist/CredentialRequestClient.js +63 -0
  18. package/dist/CredentialRequestClient.js.map +1 -0
  19. package/dist/CredentialRequestClientBuilderV1_0_09.d.ts +29 -0
  20. package/dist/CredentialRequestClientBuilderV1_0_09.d.ts.map +1 -0
  21. package/dist/CredentialRequestClientBuilderV1_0_09.js +63 -0
  22. package/dist/CredentialRequestClientBuilderV1_0_09.js.map +1 -0
  23. package/dist/{main/lib/MetadataClient.d.ts → MetadataClient.d.ts} +39 -38
  24. package/dist/MetadataClient.d.ts.map +1 -0
  25. package/dist/MetadataClient.js +148 -0
  26. package/dist/MetadataClient.js.map +1 -0
  27. package/dist/OpenID4VCIClient.d.ts +72 -0
  28. package/dist/OpenID4VCIClient.d.ts.map +1 -0
  29. package/dist/OpenID4VCIClient.js +361 -0
  30. package/dist/OpenID4VCIClient.js.map +1 -0
  31. package/dist/ProofOfPossessionBuilder.d.ts +35 -0
  32. package/dist/ProofOfPossessionBuilder.d.ts.map +1 -0
  33. package/dist/ProofOfPossessionBuilder.js +120 -0
  34. package/dist/ProofOfPossessionBuilder.js.map +1 -0
  35. package/dist/{main/lib/functions → functions}/Encoding.d.ts +20 -17
  36. package/dist/functions/Encoding.d.ts.map +1 -0
  37. package/dist/functions/Encoding.js +144 -0
  38. package/dist/functions/Encoding.js.map +1 -0
  39. package/dist/functions/HttpUtils.d.ts +24 -0
  40. package/dist/functions/HttpUtils.d.ts.map +1 -0
  41. package/dist/functions/HttpUtils.js +93 -0
  42. package/dist/functions/HttpUtils.js.map +1 -0
  43. package/dist/functions/ProofUtil.d.ts +29 -0
  44. package/dist/functions/ProofUtil.d.ts.map +1 -0
  45. package/dist/functions/ProofUtil.js +103 -0
  46. package/dist/functions/ProofUtil.js.map +1 -0
  47. package/dist/functions/index.d.ts +4 -0
  48. package/dist/functions/index.d.ts.map +1 -0
  49. package/dist/{main/lib/functions → functions}/index.js +20 -20
  50. package/dist/functions/index.js.map +1 -0
  51. package/dist/index.d.ts +9 -0
  52. package/dist/index.d.ts.map +1 -0
  53. package/dist/{main/lib/index.js → index.js} +25 -24
  54. package/dist/index.js.map +1 -0
  55. package/lib/AccessTokenClient.ts +270 -0
  56. package/lib/AuthorizationDetailsBuilder.ts +46 -0
  57. package/lib/CredentialOffer.ts +55 -0
  58. package/lib/CredentialRequestClient.ts +77 -0
  59. package/lib/CredentialRequestClientBuilderV1_0_09.ts +99 -0
  60. package/lib/MetadataClient.ts +147 -0
  61. package/lib/OpenID4VCIClient.ts +477 -0
  62. package/lib/ProofOfPossessionBuilder.ts +156 -0
  63. package/lib/__tests__/AccessTokenClient.spec.ts +221 -0
  64. package/lib/__tests__/AuthorizationDetailsBuilder.spec.ts +65 -0
  65. package/lib/__tests__/AuthzFlowType.spec.ts +39 -0
  66. package/lib/__tests__/CredentialRequestClient.spec.ts +261 -0
  67. package/lib/__tests__/CredentialRequestClientBuilder.spec.ts +103 -0
  68. package/lib/__tests__/HttpUtils.spec.ts +37 -0
  69. package/lib/__tests__/IT.spec.ts +155 -0
  70. package/lib/__tests__/IssuanceInitiation.spec.ts +37 -0
  71. package/lib/__tests__/JsonURIConversions.spec.ts +86 -0
  72. package/lib/__tests__/MetadataClient.spec.ts +198 -0
  73. package/lib/__tests__/MetadataMocks.ts +428 -0
  74. package/lib/__tests__/OpenID4VCIClient.spec.ts +166 -0
  75. package/lib/__tests__/OpenID4VCIClientPAR.spec.ts +112 -0
  76. package/lib/__tests__/ProofOfPossessionBuilder.spec.ts +109 -0
  77. package/lib/__tests__/data/VciDataFixtures.ts +744 -0
  78. package/lib/functions/Encoding.ts +138 -0
  79. package/lib/functions/HttpUtils.ts +106 -0
  80. package/lib/functions/ProofUtil.ts +128 -0
  81. package/{dist/main/lib/functions/index.d.ts → lib/functions/index.ts} +3 -3
  82. package/lib/index.ts +8 -0
  83. package/package.json +68 -71
  84. package/CHANGELOG.md +0 -21
  85. package/dist/main/index.d.ts +0 -1
  86. package/dist/main/index.js +0 -18
  87. package/dist/main/lib/AccessTokenClient.d.ts +0 -20
  88. package/dist/main/lib/AccessTokenClient.js +0 -141
  89. package/dist/main/lib/CredentialRequestClient.d.ts +0 -31
  90. package/dist/main/lib/CredentialRequestClient.js +0 -66
  91. package/dist/main/lib/CredentialRequestClientBuilder.d.ts +0 -21
  92. package/dist/main/lib/CredentialRequestClientBuilder.js +0 -56
  93. package/dist/main/lib/IssuanceInitiation.d.ts +0 -5
  94. package/dist/main/lib/IssuanceInitiation.js +0 -29
  95. package/dist/main/lib/MetadataClient.js +0 -127
  96. package/dist/main/lib/functions/Encoding.js +0 -138
  97. package/dist/main/lib/functions/HttpUtils.d.ts +0 -17
  98. package/dist/main/lib/functions/HttpUtils.js +0 -133
  99. package/dist/main/lib/functions/ProofUtil.d.ts +0 -9
  100. package/dist/main/lib/functions/ProofUtil.js +0 -76
  101. package/dist/main/lib/index.d.ts +0 -7
  102. package/dist/main/lib/types/Authorization.types.d.ts +0 -66
  103. package/dist/main/lib/types/Authorization.types.js +0 -35
  104. package/dist/main/lib/types/CredentialIssuance.types.d.ts +0 -88
  105. package/dist/main/lib/types/CredentialIssuance.types.js +0 -8
  106. package/dist/main/lib/types/Generic.types.d.ts +0 -19
  107. package/dist/main/lib/types/Generic.types.js +0 -11
  108. package/dist/main/lib/types/OAuth2ASMetadata.d.ts +0 -37
  109. package/dist/main/lib/types/OAuth2ASMetadata.js +0 -3
  110. package/dist/main/lib/types/OID4VCIServerMetadata.d.ts +0 -65
  111. package/dist/main/lib/types/OID4VCIServerMetadata.js +0 -3
  112. package/dist/main/lib/types/Oidc4vciErrors.d.ts +0 -3
  113. package/dist/main/lib/types/Oidc4vciErrors.js +0 -7
  114. package/dist/main/lib/types/index.d.ts +0 -6
  115. package/dist/main/lib/types/index.js +0 -23
  116. package/dist/main/tsconfig.build.tsbuildinfo +0 -1
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convertURIToJsonObject = exports.convertJsonToURI = void 0;
4
+ const oid4vci_common_1 = require("@sphereon/oid4vci-common");
5
+ /**
6
+ * @function encodeJsonAsURI encodes a Json object into a URI
7
+ * @param json object
8
+ * @param opts:
9
+ * - urlTypeProperties: a list of properties of which the value is a URL
10
+ * - arrayTypeProperties: a list of properties which are an array
11
+ */
12
+ /* eslint-disable @typescript-eslint/no-explicit-any */
13
+ function convertJsonToURI(json, opts) {
14
+ var _a, _b;
15
+ if (typeof json === 'string') {
16
+ return convertJsonToURI(JSON.parse(json), opts);
17
+ }
18
+ const results = [];
19
+ function encodeAndStripWhitespace(key) {
20
+ return encodeURIComponent(key.replace(' ', ''));
21
+ }
22
+ for (const [key, value] of Object.entries(json)) {
23
+ if (!value) {
24
+ continue;
25
+ }
26
+ //Skip properties that are not of URL type
27
+ if (!((_a = opts === null || opts === void 0 ? void 0 : opts.uriTypeProperties) === null || _a === void 0 ? void 0 : _a.includes(key))) {
28
+ results.push(`${key}=${value}`);
29
+ continue;
30
+ }
31
+ if (((_b = opts === null || opts === void 0 ? void 0 : opts.arrayTypeProperties) === null || _b === void 0 ? void 0 : _b.includes(key)) && Array.isArray(value)) {
32
+ results.push(value.map((v) => `${encodeAndStripWhitespace(key)}=${customEncodeURIComponent(v, /\./g)}`).join('&'));
33
+ continue;
34
+ }
35
+ const isBool = typeof value == 'boolean';
36
+ const isNumber = typeof value == 'number';
37
+ const isString = typeof value == 'string';
38
+ let encoded;
39
+ if (isBool || isNumber) {
40
+ encoded = `${encodeAndStripWhitespace(key)}=${value}`;
41
+ }
42
+ else if (isString) {
43
+ encoded = `${encodeAndStripWhitespace(key)}=${customEncodeURIComponent(value, /\./g)}`;
44
+ }
45
+ else {
46
+ encoded = `${encodeAndStripWhitespace(key)}=${customEncodeURIComponent(JSON.stringify(value), /\./g)}`;
47
+ }
48
+ results.push(encoded);
49
+ }
50
+ const components = results.join('&');
51
+ if (opts === null || opts === void 0 ? void 0 : opts.baseUrl) {
52
+ return `${opts.baseUrl}?${components}`;
53
+ }
54
+ return components;
55
+ }
56
+ exports.convertJsonToURI = convertJsonToURI;
57
+ /**
58
+ * @function decodeUriAsJson decodes a URI into a Json object
59
+ * @param uri string
60
+ * @param opts:
61
+ * - requiredProperties: the required properties
62
+ * - arrayTypeProperties: properties that can show up more that once
63
+ */
64
+ function convertURIToJsonObject(uri, opts) {
65
+ var _a;
66
+ if (!uri || !((_a = opts === null || opts === void 0 ? void 0 : opts.requiredProperties) === null || _a === void 0 ? void 0 : _a.every((p) => uri.includes(p)))) {
67
+ throw new Error(oid4vci_common_1.BAD_PARAMS);
68
+ }
69
+ const uriComponents = getURIComponentsAsArray(uri, opts === null || opts === void 0 ? void 0 : opts.arrayTypeProperties);
70
+ return decodeJsonProperties(uriComponents);
71
+ }
72
+ exports.convertURIToJsonObject = convertURIToJsonObject;
73
+ function decodeJsonProperties(parts) {
74
+ const json = {};
75
+ for (const key in parts) {
76
+ const value = parts[key];
77
+ if (!value) {
78
+ continue;
79
+ }
80
+ if (Array.isArray(value)) {
81
+ if (value.length > 1) {
82
+ json[decodeURIComponent(key)] = value.map((v) => decodeURIComponent(v));
83
+ }
84
+ else {
85
+ json[decodeURIComponent(key)] = decodeURIComponent(value[0]);
86
+ }
87
+ }
88
+ const isBool = typeof value == 'boolean';
89
+ const isNumber = typeof value == 'number';
90
+ const isString = typeof value == 'string';
91
+ if (isBool || isNumber) {
92
+ json[decodeURIComponent(key)] = value;
93
+ }
94
+ else if (isString) {
95
+ const decoded = decodeURIComponent(value);
96
+ if (decoded.startsWith('{') && decoded.endsWith('}')) {
97
+ json[decodeURIComponent(key)] = JSON.parse(decoded);
98
+ }
99
+ else {
100
+ json[decodeURIComponent(key)] = decoded;
101
+ }
102
+ }
103
+ }
104
+ return json;
105
+ }
106
+ /**
107
+ * @function get URI Components as Array
108
+ * @param uri string
109
+ * @param arrayTypes array of string containing array like keys
110
+ */
111
+ function getURIComponentsAsArray(uri, arrayTypes) {
112
+ const parts = uri.includes('?') ? uri.split('?')[1] : uri.includes('://') ? uri.split('://')[1] : uri;
113
+ const json = [];
114
+ const dict = parts.split('&');
115
+ for (const entry of dict) {
116
+ const pair = entry.split('=');
117
+ const p0 = pair[0];
118
+ const p1 = pair[1];
119
+ if (arrayTypes === null || arrayTypes === void 0 ? void 0 : arrayTypes.includes(p0)) {
120
+ const key = json[p0];
121
+ if (Array.isArray(key)) {
122
+ key.push(p1);
123
+ }
124
+ else {
125
+ json[p0] = [p1];
126
+ }
127
+ continue;
128
+ }
129
+ json[p0] = p1;
130
+ }
131
+ return json;
132
+ }
133
+ /* eslint-enable @typescript-eslint/no-explicit-any */
134
+ /**
135
+ * @function customEncodeURIComponent is used to encode chars that are not encoded by default
136
+ * @param searchValue The pattern/regexp to find the char(s) to be encoded
137
+ * @param uriComponent query string
138
+ */
139
+ function customEncodeURIComponent(uriComponent, searchValue) {
140
+ // -_.!~*'() are not escaped because they are considered safe.
141
+ // Add them to the regex as you need
142
+ return encodeURIComponent(uriComponent).replace(searchValue, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`);
143
+ }
144
+ //# sourceMappingURL=Encoding.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Encoding.js","sourceRoot":"","sources":["../../lib/functions/Encoding.ts"],"names":[],"mappings":";;;AAAA,6DAA6G;AAE7G;;;;;;GAMG;AACH,uDAAuD;AACvD,SAAgB,gBAAgB,CAAC,IAAoD,EAAE,IAA0B;;IAC/G,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC5B,OAAO,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;KACjD;IACD,MAAM,OAAO,GAAG,EAAE,CAAC;IAEnB,SAAS,wBAAwB,CAAC,GAAW;QAC3C,OAAO,kBAAkB,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC;IAClD,CAAC;IAED,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QAC/C,IAAI,CAAC,KAAK,EAAE;YACV,SAAS;SACV;QACD,0CAA0C;QAC1C,IAAI,CAAC,CAAA,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,iBAAiB,0CAAE,QAAQ,CAAC,GAAG,CAAC,CAAA,EAAE;YAC3C,OAAO,CAAC,IAAI,CAAC,GAAG,GAAG,IAAI,KAAK,EAAE,CAAC,CAAC;YAChC,SAAS;SACV;QACD,IAAI,CAAA,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,mBAAmB,0CAAE,QAAQ,CAAC,GAAG,CAAC,KAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YACpE,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,wBAAwB,CAAC,GAAG,CAAC,IAAI,wBAAwB,CAAC,CAAC,E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;gBACL,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;aACjB;YACD,SAAS;SACV;QACD,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC;KACf;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,sDAAsD;AAEtD;;;;GAIG;AACH,SAAS,wBAAwB,CAAC,YAAoB,EAAE,WAAwB;IAC9E,8DAA8D;IAC9D,oCAAoC;IACpC,OAAO,kBAAkB,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;AACxH,CAAC"}
@@ -0,0 +1,24 @@
1
+ import { OpenIDResponse } from '@sphereon/oid4vci-common';
2
+ export declare const getJson: <T>(URL: string, opts?: {
3
+ bearerToken?: string;
4
+ contentType?: string;
5
+ accept?: string;
6
+ customHeaders?: Record<string, string>;
7
+ exceptionOnHttpErrorStatus?: boolean;
8
+ }) => Promise<OpenIDResponse<T>>;
9
+ export declare const formPost: <T>(url: string, body: BodyInit, opts?: {
10
+ bearerToken?: string;
11
+ contentType?: string;
12
+ accept?: string;
13
+ customHeaders?: Record<string, string>;
14
+ exceptionOnHttpErrorStatus?: boolean;
15
+ }) => Promise<OpenIDResponse<T>>;
16
+ export declare const post: <T>(url: string, body?: BodyInit, opts?: {
17
+ bearerToken?: string;
18
+ contentType?: string;
19
+ accept?: string;
20
+ customHeaders?: Record<string, string>;
21
+ exceptionOnHttpErrorStatus?: boolean;
22
+ }) => Promise<OpenIDResponse<T>>;
23
+ export declare const isValidURL: (url: string) => boolean;
24
+ //# sourceMappingURL=HttpUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HttpUtils.d.ts","sourceRoot":"","sources":["../../lib/functions/HttpUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAMpE,eAAO,MAAM,OAAO,WACb,MAAM,SACJ;IAAE,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,OAAO,MAAM,EAAE,MAAM,CAAC,CAAC;IAAC,0BAA0B,CAAC,EAAE,OAAO,CAAA;CAAE,+BAGrJ,CAAC;AAEF,eAAO,MAAM,QAAQ,WACd,MAAM,QACL,QAAQ,SACP;IAAE,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,OAAO,MAAM,EAAE,MAAM,CAAC,CAAC;IAAC,0BAA0B,CAAC,EAAE,OAAO,CAAA;CAAE,+BAGrJ,CAAC;AAEF,eAAO,MAAM,IAAI,WACV,MAAM,SACJ,QAAQ,SACR;IAAE,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,OAAO,MAAM,EAAE,MAAM,CAAC,CAAC;IAAC,0BAA0B,CAAC,EAAE,OAAO,CAAA;CAAE,+BAGrJ,CAAC;AAkEF,eAAO,MAAM,UAAU,QAAS,MAAM,KAAG,OAYxC,CAAC"}
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.isValidURL = exports.post = exports.formPost = exports.getJson = void 0;
16
+ const oid4vci_common_1 = require("@sphereon/oid4vci-common");
17
+ const cross_fetch_1 = require("cross-fetch");
18
+ const debug_1 = __importDefault(require("debug"));
19
+ const debug = (0, debug_1.default)('sphereon:openid4vci:http');
20
+ const getJson = (URL, opts) => __awaiter(void 0, void 0, void 0, function* () {
21
+ return yield openIdFetch(URL, undefined, Object.assign({ method: 'GET' }, opts));
22
+ });
23
+ exports.getJson = getJson;
24
+ const formPost = (url, body, opts) => __awaiter(void 0, void 0, void 0, function* () {
25
+ return yield (0, exports.post)(url, body, (opts === null || opts === void 0 ? void 0 : opts.contentType) ? Object.assign({}, opts) : Object.assign({ contentType: oid4vci_common_1.Encoding.FORM_URL_ENCODED }, opts));
26
+ });
27
+ exports.formPost = formPost;
28
+ const post = (url, body, opts) => __awaiter(void 0, void 0, void 0, function* () {
29
+ return yield openIdFetch(url, body, Object.assign({ method: 'POST' }, opts));
30
+ });
31
+ exports.post = post;
32
+ const openIdFetch = (url, body, opts) => __awaiter(void 0, void 0, void 0, function* () {
33
+ var _a;
34
+ const headers = (_a = opts === null || opts === void 0 ? void 0 : opts.customHeaders) !== null && _a !== void 0 ? _a : {};
35
+ if (opts === null || opts === void 0 ? void 0 : opts.bearerToken) {
36
+ headers['Authorization'] = `Bearer ${opts.bearerToken}`;
37
+ }
38
+ const method = (opts === null || opts === void 0 ? void 0 : opts.method) ? opts.method : body ? 'POST' : 'GET';
39
+ const accept = (opts === null || opts === void 0 ? void 0 : opts.accept) ? opts.accept : 'application/json';
40
+ headers['Accept'] = accept;
41
+ if (headers['Content-Type']) {
42
+ if ((opts === null || opts === void 0 ? void 0 : opts.contentType) && opts.contentType !== headers['Content-Type']) {
43
+ throw Error(`Mismatch in content-types from custom headers (${headers['Content-Type']}) and supplied content type option (${opts.contentType})`);
44
+ }
45
+ }
46
+ else {
47
+ if (opts === null || opts === void 0 ? void 0 : opts.contentType) {
48
+ headers['Content-Type'] = opts.contentType;
49
+ }
50
+ else if (method !== 'GET') {
51
+ headers['Content-Type'] = 'application/json';
52
+ }
53
+ }
54
+ const payload = {
55
+ method,
56
+ headers,
57
+ body,
58
+ };
59
+ debug(`START fetching url: ${url}`);
60
+ if (body) {
61
+ debug(`Body:\r\n${JSON.stringify(body)}`);
62
+ }
63
+ debug(`Headers:\r\n${JSON.stringify(payload.headers)}`);
64
+ const origResponse = yield (0, cross_fetch_1.fetch)(url, payload);
65
+ const isJSONResponse = accept === 'application/json' || origResponse.headers.get('Content-Type') === 'application/json';
66
+ const success = origResponse && origResponse.status >= 200 && origResponse.status < 400;
67
+ const responseText = yield origResponse.text();
68
+ const responseBody = isJSONResponse ? JSON.parse(responseText) : responseText;
69
+ debug(`${success ? 'success' : 'error'} status: ${origResponse.status}, body:\r\n${JSON.stringify(responseBody)}`);
70
+ if (!success && (opts === null || opts === void 0 ? void 0 : opts.exceptionOnHttpErrorStatus)) {
71
+ const error = JSON.stringify(responseBody);
72
+ throw new Error(error === '{}' ? '{"error": "not found"}' : error);
73
+ }
74
+ debug(`END fetching url: ${url}`);
75
+ return {
76
+ origResponse,
77
+ successBody: success ? responseBody : undefined,
78
+ errorBody: !success ? responseBody : undefined,
79
+ };
80
+ });
81
+ const isValidURL = (url) => {
82
+ const urlPattern = new RegExp('^(https?:\\/\\/)' + // validate protocol
83
+ '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // validate domain name
84
+ '((localhost))|' + // validate OR localhost
85
+ '((\\d{1,3}\\.){3}\\d{1,3}))' + // validate OR ip (v4) address
86
+ '(\\:\\d+)?(\\/[-a-z\\d%_.~+:]*)*' + // validate port and path
87
+ '(\\?[;&a-z\\d%_.~+=-]*)?' + // validate query string
88
+ '(\\#[-a-z\\d_]*)?$', // validate fragment locator
89
+ 'i');
90
+ return !!urlPattern.test(url);
91
+ };
92
+ exports.isValidURL = isValidURL;
93
+ //# sourceMappingURL=HttpUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HttpUtils.js","sourceRoot":"","sources":["../../lib/functions/HttpUtils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,6DAAoE;AACpE,6CAAoC;AACpC,kDAA0B;AAE1B,MAAM,KAAK,GAAG,IAAA,eAAK,EAAC,0BAA0B,CAAC,CAAC;AAEzC,MAAM,OAAO,GAAG,CACrB,GAAW,EACX,IAAoJ,EACxH,EAAE;IAC9B,OAAO,MAAM,WAAW,CAAC,GAAG,EAAE,SAAS,kBAAI,MAAM,EAAE,KAAK,IAAK,IAAI,EAAG,CAAC;AACvE,CAAC,CAAA,CAAC;AALW,QAAA,OAAO,WAKlB;AAEK,MAAM,QAAQ,GAAG,CACtB,GAAW,EACX,IAAc,EACd,IAAoJ,EACxH,EAAE;IAC9B,OAAO,MAAM,IAAA,YAAI,EAAC,GAAG,EAAE,IAAI,EAAE,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,WAAW,EAAC,CAAC,mBAAM,IAAI,EAAG,CAAC,iBAAG,WAAW,EAAE,yBAAQ,CAAC,gBAAgB,IAAK,IAAI,CAAE,CAAC,CAAC;AACtH,CAAC,CAAA,CAAC;AANW,QAAA,QAAQ,YAMnB;AAEK,MAAM,IAAI,GAAG,CAClB,GAAW,EACX,IAAe,EACf,IAAoJ,EACxH,EAAE;IAC9B,OAAO,MAAM,WAAW,CAAC,GAAG,EAAE,IAAI,kBAAI,MAAM,EAAE,MAAM,IAAK,IAAI,EAAG,CAAC;AACnE,CAAC,CAAA,CAAC;AANW,QAAA,IAAI,QAMf;AAEF,MAAM,WAAW,GAAG,CAClB,GAAW,EACX,IAAe,EACf,IAOC,EAC2B,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AW,EAAE,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS;QAC/C,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS;KAC/C,CAAC;AACJ,CAAC,CAAA,CAAC;AAEK,MAAM,UAAU,GAAG,CAAC,GAAW,EAAW,EAAE;IACjD,MAAM,UAAU,GAAG,IAAI,MAAM,CAC3B,kBAAkB,GAAG,oBAAoB;QACvC,kDAAkD,GAAG,uBAAuB;QAC5E,gBAAgB,GAAG,wBAAwB;QAC3C,6BAA6B,GAAG,8BAA8B;QAC9D,kCAAkC,GAAG,yBAAyB;QAC9D,0BAA0B,GAAG,wBAAwB;QACrD,oBAAoB,EAAE,4BAA4B;IACpD,GAAG,CACJ,CAAC;IACF,OAAO,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAChC,CAAC,CAAC;AAZW,QAAA,UAAU,cAYrB"}
@@ -0,0 +1,29 @@
1
+ import { Jwt, ProofOfPossession, ProofOfPossessionCallbacks } from '@sphereon/oid4vci-common';
2
+ /**
3
+ *
4
+ * - proofOfPossessionCallback: JWTSignerCallback
5
+ * Mandatory if you want to create (sign) ProofOfPossession
6
+ * - proofOfPossessionVerifierCallback?: JWTVerifyCallback
7
+ * If exists, verifies the ProofOfPossession
8
+ * - proofOfPossessionCallbackArgs: ProofOfPossessionCallbackArgs
9
+ * arguments needed for signing ProofOfPossession
10
+ * @param callbacks:
11
+ * - proofOfPossessionCallback: JWTSignerCallback
12
+ * Mandatory to create (sign) ProofOfPossession
13
+ * - proofOfPossessionVerifierCallback?: JWTVerifyCallback
14
+ * If exists, verifies the ProofOfPossession
15
+ * @param jwtProps
16
+ * @param existingJwt
17
+ * - Optional, clientId of the party requesting the credential
18
+ */
19
+ export declare const createProofOfPossession: (callbacks: ProofOfPossessionCallbacks, jwtProps?: JwtProps, existingJwt?: Jwt) => Promise<ProofOfPossession>;
20
+ export interface JwtProps {
21
+ typ?: string;
22
+ kid?: string;
23
+ issuer?: string;
24
+ clientId?: string;
25
+ alg?: string;
26
+ jti?: string;
27
+ nonce?: string;
28
+ }
29
+ //# sourceMappingURL=ProofUtil.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProofUtil.d.ts","sourceRoot":"","sources":["../../lib/functions/ProofUtil.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,GAAG,EAGH,iBAAiB,EACjB,0BAA0B,EAG3B,MAAM,0BAA0B,CAAC;AAKlC;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,uBAAuB,cACvB,0BAA0B,aAC1B,QAAQ,gBACL,GAAG,KAChB,QAAQ,iBAAiB,CAyB3B,CAAC;AAQF,MAAM,WAAW,QAAQ;IACvB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.createProofOfPossession = void 0;
16
+ const oid4vci_common_1 = require("@sphereon/oid4vci-common");
17
+ const debug_1 = __importDefault(require("debug"));
18
+ const debug = (0, debug_1.default)('sphereon:openid4vci:token');
19
+ /**
20
+ *
21
+ * - proofOfPossessionCallback: JWTSignerCallback
22
+ * Mandatory if you want to create (sign) ProofOfPossession
23
+ * - proofOfPossessionVerifierCallback?: JWTVerifyCallback
24
+ * If exists, verifies the ProofOfPossession
25
+ * - proofOfPossessionCallbackArgs: ProofOfPossessionCallbackArgs
26
+ * arguments needed for signing ProofOfPossession
27
+ * @param callbacks:
28
+ * - proofOfPossessionCallback: JWTSignerCallback
29
+ * Mandatory to create (sign) ProofOfPossession
30
+ * - proofOfPossessionVerifierCallback?: JWTVerifyCallback
31
+ * If exists, verifies the ProofOfPossession
32
+ * @param jwtProps
33
+ * @param existingJwt
34
+ * - Optional, clientId of the party requesting the credential
35
+ */
36
+ const createProofOfPossession = (callbacks, jwtProps, existingJwt) => __awaiter(void 0, void 0, void 0, function* () {
37
+ if (!callbacks.signCallback) {
38
+ debug(`no jwt signer callback or arguments supplied!`);
39
+ throw new Error(oid4vci_common_1.BAD_PARAMS);
40
+ }
41
+ const signerArgs = createJWT(jwtProps, existingJwt);
42
+ const jwt = yield callbacks.signCallback(signerArgs, signerArgs.header.kid);
43
+ const proof = {
44
+ proof_type: oid4vci_common_1.ProofType.JWT,
45
+ jwt,
46
+ };
47
+ try {
48
+ partiallyValidateJWS(jwt);
49
+ if (callbacks.verifyCallback) {
50
+ debug(`Calling supplied verify callback....`);
51
+ yield callbacks.verifyCallback({ jwt, kid: signerArgs.header.kid });
52
+ debug(`Supplied verify callback return success result`);
53
+ }
54
+ }
55
+ catch (_a) {
56
+ debug(`JWS was not valid`);
57
+ throw new Error(oid4vci_common_1.JWS_NOT_VALID);
58
+ }
59
+ debug(`Proof of Possession JWT:\r\n${jwt}`);
60
+ return proof;
61
+ });
62
+ exports.createProofOfPossession = createProofOfPossession;
63
+ const partiallyValidateJWS = (jws) => {
64
+ if (jws.split('.').length !== 3 || !jws.startsWith('ey')) {
65
+ throw new Error(oid4vci_common_1.JWS_NOT_VALID);
66
+ }
67
+ };
68
+ const createJWT = (jwtProps, existingJwt) => {
69
+ var _a, _b, _c, _d, _e, _f, _g, _h;
70
+ const aud = getJwtProperty('aud', true, jwtProps === null || jwtProps === void 0 ? void 0 : jwtProps.issuer, (_a = existingJwt === null || existingJwt === void 0 ? void 0 : existingJwt.payload) === null || _a === void 0 ? void 0 : _a.aud);
71
+ const iss = getJwtProperty('iss', false, jwtProps === null || jwtProps === void 0 ? void 0 : jwtProps.clientId, (_b = existingJwt === null || existingJwt === void 0 ? void 0 : existingJwt.payload) === null || _b === void 0 ? void 0 : _b.iss);
72
+ const jti = getJwtProperty('jti', false, jwtProps === null || jwtProps === void 0 ? void 0 : jwtProps.jti, (_c = existingJwt === null || existingJwt === void 0 ? void 0 : existingJwt.payload) === null || _c === void 0 ? void 0 : _c.jti);
73
+ const nonce = getJwtProperty('nonce', false, jwtProps === null || jwtProps === void 0 ? void 0 : jwtProps.nonce, (_d = existingJwt === null || existingJwt === void 0 ? void 0 : existingJwt.payload) === null || _d === void 0 ? void 0 : _d.nonce); // Officially this is required, but some implementations don't have it
74
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
75
+ const alg = getJwtProperty('alg', false, jwtProps === null || jwtProps === void 0 ? void 0 : jwtProps.alg, (_e = existingJwt === null || existingJwt === void 0 ? void 0 : existingJwt.header) === null || _e === void 0 ? void 0 : _e.alg, 'ES256');
76
+ const kid = getJwtProperty('kid', true, jwtProps === null || jwtProps === void 0 ? void 0 : jwtProps.kid, (_f = existingJwt === null || existingJwt === void 0 ? void 0 : existingJwt.header) === null || _f === void 0 ? void 0 : _f.kid);
77
+ const jwt = existingJwt ? existingJwt : {};
78
+ const now = +new Date();
79
+ const jwtPayload = Object.assign(Object.assign({ aud, iat: ((_g = jwt.payload) === null || _g === void 0 ? void 0 : _g.iat) ? jwt.payload.iat : now / 1000 - 60, exp: ((_h = jwt.payload) === null || _h === void 0 ? void 0 : _h.exp) ? jwt.payload.exp : now / 1000 + 10 * 60, nonce }, (iss ? { iss } : {})), (jti ? { jti } : {}));
80
+ const jwtHeader = {
81
+ typ: oid4vci_common_1.Typ.JWT,
82
+ alg,
83
+ kid,
84
+ };
85
+ return {
86
+ payload: Object.assign(Object.assign({}, jwt.payload), jwtPayload),
87
+ header: Object.assign(Object.assign({}, jwt.header), jwtHeader),
88
+ };
89
+ };
90
+ const getJwtProperty = (propertyName, required, option, jwtProperty, defaultValue) => {
91
+ if (option && jwtProperty && option !== jwtProperty) {
92
+ throw Error(`Cannot have a property '${propertyName}' with value '${option}' and different JWT value '${jwtProperty}' at the same time`);
93
+ }
94
+ let result = jwtProperty ? jwtProperty : option;
95
+ if (!result) {
96
+ if (required) {
97
+ throw Error(`No ${propertyName} property provided either in a JWT or as option`);
98
+ }
99
+ result = defaultValue;
100
+ }
101
+ return result;
102
+ };
103
+ //# sourceMappingURL=ProofUtil.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProofUtil.js","sourceRoot":"","sources":["../../lib/functions/ProofUtil.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,6DAUkC;AAClC,kDAA0B;AAE1B,MAAM,KAAK,GAAG,IAAA,eAAK,EAAC,2BAA2B,CAAC,CAAC;AAEjD;;;;;;;;;;;;;;;;GAgBG;AACI,MAAM,uBAAuB,GAAG,CACrC,SAAqC,EACrC,QAAmB,EACnB,WAAiB,EACW,EAAE;IAC9B,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE;QAC3B,KAAK,CAAC,+CAA+C,CAAC,CAAC;QACvD,MAAM,IAAI,KAAK,CAAC,2BAAU,CAAC,CAAC;KAC7B;IACD,MAAM,UAAU,GAAG,SAAS,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;IACpD,MAAM,GAAG,GAAG,MAAM,SAAS,CAAC,YAAY,CAAC,UAAU,EAAE,UAAU,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d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/functions/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC"}
@@ -1,20 +1,20 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./Encoding"), exports);
18
- __exportStar(require("./HttpUtils"), exports);
19
- __exportStar(require("./ProofUtil"), exports);
20
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9saWIvZnVuY3Rpb25zL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7QUFBQSw2Q0FBMkI7QUFDM0IsOENBQTRCO0FBQzVCLDhDQUE0QiJ9
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./Encoding"), exports);
18
+ __exportStar(require("./HttpUtils"), exports);
19
+ __exportStar(require("./ProofUtil"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/functions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,8CAA4B;AAC5B,8CAA4B"}
@@ -0,0 +1,9 @@
1
+ export * from './AccessTokenClient';
2
+ export * from './CredentialOffer';
3
+ export * from './CredentialRequestClient';
4
+ export * from './CredentialRequestClientBuilderV1_0_09';
5
+ export * from './functions';
6
+ export * from './MetadataClient';
7
+ export * from './OpenID4VCIClient';
8
+ export * from './ProofOfPossessionBuilder';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yCAAyC,CAAC;AACxD,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC"}
@@ -1,24 +1,25 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./functions"), exports);
18
- __exportStar(require("./types"), exports);
19
- __exportStar(require("./MetadataClient"), exports);
20
- __exportStar(require("./IssuanceInitiation"), exports);
21
- __exportStar(require("./AccessTokenClient"), exports);
22
- __exportStar(require("./CredentialRequestClient"), exports);
23
- __exportStar(require("./CredentialRequestClientBuilder"), exports);
24
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9saWIvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7OztBQUFBLDhDQUE0QjtBQUM1QiwwQ0FBd0I7QUFDeEIsbURBQWlDO0FBQ2pDLHVEQUFxQztBQUNyQyxzREFBb0M7QUFDcEMsNERBQTBDO0FBQzFDLG1FQUFpRCJ9
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./AccessTokenClient"), exports);
18
+ __exportStar(require("./CredentialOffer"), exports);
19
+ __exportStar(require("./CredentialRequestClient"), exports);
20
+ __exportStar(require("./CredentialRequestClientBuilderV1_0_09"), exports);
21
+ __exportStar(require("./functions"), exports);
22
+ __exportStar(require("./MetadataClient"), exports);
23
+ __exportStar(require("./OpenID4VCIClient"), exports);
24
+ __exportStar(require("./ProofOfPossessionBuilder"), exports);
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAoC;AACpC,oDAAkC;AAClC,4DAA0C;AAC1C,0EAAwD;AACxD,8CAA4B;AAC5B,mDAAiC;AACjC,qDAAmC;AACnC,6DAA2C"}