@sphereon/oid4vci-common 0.4.1-next.285

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 (108) hide show
  1. package/LICENSE +201 -0
  2. package/dist/functions/CredentialOfferUtil.d.ts +25 -0
  3. package/dist/functions/CredentialOfferUtil.d.ts.map +1 -0
  4. package/dist/functions/CredentialOfferUtil.js +303 -0
  5. package/dist/functions/CredentialOfferUtil.js.map +1 -0
  6. package/dist/functions/CredentialRequestUtil.d.ts +3 -0
  7. package/dist/functions/CredentialRequestUtil.d.ts.map +1 -0
  8. package/dist/functions/CredentialRequestUtil.js +8 -0
  9. package/dist/functions/CredentialRequestUtil.js.map +1 -0
  10. package/dist/functions/Encoding.d.ts +20 -0
  11. package/dist/functions/Encoding.d.ts.map +1 -0
  12. package/dist/functions/Encoding.js +164 -0
  13. package/dist/functions/Encoding.js.map +1 -0
  14. package/dist/functions/HttpUtils.d.ts +33 -0
  15. package/dist/functions/HttpUtils.d.ts.map +1 -0
  16. package/dist/functions/HttpUtils.js +146 -0
  17. package/dist/functions/HttpUtils.js.map +1 -0
  18. package/dist/functions/IssuerMetadataUtils.d.ts +10 -0
  19. package/dist/functions/IssuerMetadataUtils.d.ts.map +1 -0
  20. package/dist/functions/IssuerMetadataUtils.js +89 -0
  21. package/dist/functions/IssuerMetadataUtils.js.map +1 -0
  22. package/dist/functions/TypeConversionUtils.d.ts +2 -0
  23. package/dist/functions/TypeConversionUtils.d.ts.map +1 -0
  24. package/dist/functions/TypeConversionUtils.js +8 -0
  25. package/dist/functions/TypeConversionUtils.js.map +1 -0
  26. package/dist/functions/index.d.ts +4 -0
  27. package/dist/functions/index.d.ts.map +1 -0
  28. package/dist/functions/index.js +20 -0
  29. package/dist/functions/index.js.map +1 -0
  30. package/dist/index.d.ts +3 -0
  31. package/dist/index.d.ts.map +1 -0
  32. package/dist/index.js +19 -0
  33. package/dist/index.js.map +1 -0
  34. package/dist/types/Authorization.types.d.ts +198 -0
  35. package/dist/types/Authorization.types.d.ts.map +1 -0
  36. package/dist/types/Authorization.types.js +40 -0
  37. package/dist/types/Authorization.types.js.map +1 -0
  38. package/dist/types/CredentialIssuance.types.d.ts +139 -0
  39. package/dist/types/CredentialIssuance.types.d.ts.map +1 -0
  40. package/dist/types/CredentialIssuance.types.js +10 -0
  41. package/dist/types/CredentialIssuance.types.js.map +1 -0
  42. package/dist/types/Generic.types.d.ts +156 -0
  43. package/dist/types/Generic.types.d.ts.map +1 -0
  44. package/dist/types/Generic.types.js +11 -0
  45. package/dist/types/Generic.types.js.map +1 -0
  46. package/dist/types/OAuth2ASMetadata.d.ts +41 -0
  47. package/dist/types/OAuth2ASMetadata.d.ts.map +1 -0
  48. package/dist/types/OAuth2ASMetadata.js +3 -0
  49. package/dist/types/OAuth2ASMetadata.js.map +1 -0
  50. package/dist/types/OpenID4VCIErrors.d.ts +34 -0
  51. package/dist/types/OpenID4VCIErrors.d.ts.map +1 -0
  52. package/dist/types/OpenID4VCIErrors.js +38 -0
  53. package/dist/types/OpenID4VCIErrors.js.map +1 -0
  54. package/dist/types/OpenID4VCIServerMetadata.d.ts +4 -0
  55. package/dist/types/OpenID4VCIServerMetadata.d.ts.map +1 -0
  56. package/dist/types/OpenID4VCIServerMetadata.js +17 -0
  57. package/dist/types/OpenID4VCIServerMetadata.js.map +1 -0
  58. package/dist/types/OpenID4VCIVersions.types.d.ts +11 -0
  59. package/dist/types/OpenID4VCIVersions.types.d.ts.map +1 -0
  60. package/dist/types/OpenID4VCIVersions.types.js +16 -0
  61. package/dist/types/OpenID4VCIVersions.types.js.map +1 -0
  62. package/dist/types/StateManager.types.d.ts +33 -0
  63. package/dist/types/StateManager.types.d.ts.map +1 -0
  64. package/dist/types/StateManager.types.js +3 -0
  65. package/dist/types/StateManager.types.js.map +1 -0
  66. package/dist/types/Token.types.d.ts +15 -0
  67. package/dist/types/Token.types.d.ts.map +1 -0
  68. package/dist/types/Token.types.js +30 -0
  69. package/dist/types/Token.types.js.map +1 -0
  70. package/dist/types/index.d.ts +13 -0
  71. package/dist/types/index.d.ts.map +1 -0
  72. package/dist/types/index.js +29 -0
  73. package/dist/types/index.js.map +1 -0
  74. package/dist/types/v1_0_08.types.d.ts +38 -0
  75. package/dist/types/v1_0_08.types.d.ts.map +1 -0
  76. package/dist/types/v1_0_08.types.js +3 -0
  77. package/dist/types/v1_0_08.types.js.map +1 -0
  78. package/dist/types/v1_0_09.types.d.ts +29 -0
  79. package/dist/types/v1_0_09.types.d.ts.map +1 -0
  80. package/dist/types/v1_0_09.types.js +9 -0
  81. package/dist/types/v1_0_09.types.js.map +1 -0
  82. package/dist/types/v1_0_11.types.d.ts +49 -0
  83. package/dist/types/v1_0_11.types.d.ts.map +1 -0
  84. package/dist/types/v1_0_11.types.js +9 -0
  85. package/dist/types/v1_0_11.types.js.map +1 -0
  86. package/lib/__tests__/CredentialOfferUtil.spec.ts +55 -0
  87. package/lib/functions/CredentialOfferUtil.ts +338 -0
  88. package/lib/functions/CredentialRequestUtil.ts +5 -0
  89. package/lib/functions/Encoding.ts +166 -0
  90. package/lib/functions/HttpUtils.ts +168 -0
  91. package/lib/functions/IssuerMetadataUtils.ts +101 -0
  92. package/lib/functions/TypeConversionUtils.ts +3 -0
  93. package/lib/functions/index.ts +3 -0
  94. package/lib/index.ts +2 -0
  95. package/lib/types/Authorization.types.ts +234 -0
  96. package/lib/types/CredentialIssuance.types.ts +167 -0
  97. package/lib/types/Generic.types.ts +234 -0
  98. package/lib/types/OAuth2ASMetadata.ts +49 -0
  99. package/lib/types/OpenID4VCIErrors.ts +35 -0
  100. package/lib/types/OpenID4VCIServerMetadata.ts +20 -0
  101. package/lib/types/OpenID4VCIVersions.types.ts +11 -0
  102. package/lib/types/StateManager.types.ts +45 -0
  103. package/lib/types/Token.types.ts +29 -0
  104. package/lib/types/index.ts +12 -0
  105. package/lib/types/v1_0_08.types.ts +44 -0
  106. package/lib/types/v1_0_09.types.ts +36 -0
  107. package/lib/types/v1_0_11.types.ts +68 -0
  108. package/package.json +49 -0
@@ -0,0 +1,164 @@
1
+ "use strict";
2
+ // import * as u8a from 'uint8arrays'
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.convertURIToJsonObject = exports.convertJsonToURI = void 0;
5
+ const types_1 = require("../types");
6
+ /**
7
+ * @function encodeJsonAsURI encodes a Json object into a URI
8
+ * @param json object
9
+ * @param opts:
10
+ * - urlTypeProperties: a list of properties of which the value is a URL
11
+ * - arrayTypeProperties: a list of properties which are an array
12
+ */
13
+ // /* eslint-disable @typescript-eslint/no-explicit-any */
14
+ function convertJsonToURI(json, opts) {
15
+ var _a, _b;
16
+ if (typeof json === 'string') {
17
+ return convertJsonToURI(JSON.parse(json), opts);
18
+ }
19
+ const results = [];
20
+ function encodeAndStripWhitespace(key) {
21
+ return encodeURIComponent(key.replace(' ', ''));
22
+ }
23
+ let components;
24
+ if ((opts === null || opts === void 0 ? void 0 : opts.version) && opts.version > types_1.OpenId4VCIVersion.VER_1_0_08) {
25
+ // v11 changed from encoding every param to a encoded json object with a credential_offer param key
26
+ components = encodeAndStripWhitespace(JSON.stringify(json));
27
+ }
28
+ else {
29
+ for (const [key, value] of Object.entries(json)) {
30
+ if (!value) {
31
+ continue;
32
+ }
33
+ //Skip properties that are not of URL type
34
+ if (!((_a = opts === null || opts === void 0 ? void 0 : opts.uriTypeProperties) === null || _a === void 0 ? void 0 : _a.includes(key))) {
35
+ results.push(`${key}=${value}`);
36
+ continue;
37
+ }
38
+ if (((_b = opts === null || opts === void 0 ? void 0 : opts.arrayTypeProperties) === null || _b === void 0 ? void 0 : _b.includes(key)) && Array.isArray(value)) {
39
+ results.push(value.map((v) => `${encodeAndStripWhitespace(key)}=${customEncodeURIComponent(v, /\./g)}`).join('&'));
40
+ continue;
41
+ }
42
+ const isBool = typeof value == 'boolean';
43
+ const isNumber = typeof value == 'number';
44
+ const isString = typeof value == 'string';
45
+ let encoded;
46
+ if (isBool || isNumber) {
47
+ encoded = `${encodeAndStripWhitespace(key)}=${value}`;
48
+ }
49
+ else if (isString) {
50
+ encoded = `${encodeAndStripWhitespace(key)}=${customEncodeURIComponent(value, /\./g)}`;
51
+ }
52
+ else {
53
+ encoded = `${encodeAndStripWhitespace(key)}=${customEncodeURIComponent(JSON.stringify(value), /\./g)}`;
54
+ }
55
+ results.push(encoded);
56
+ }
57
+ components = results.join('&');
58
+ }
59
+ if (opts === null || opts === void 0 ? void 0 : opts.baseUrl) {
60
+ if (opts.baseUrl.endsWith('=')) {
61
+ if (opts.param) {
62
+ throw Error('Cannot combine param with an url ending in =');
63
+ }
64
+ return `${opts.baseUrl}${components}`;
65
+ }
66
+ else if (!opts.baseUrl.includes('?')) {
67
+ return `${opts.baseUrl}?${opts.param ? opts.param + '=' : ''}${components}`;
68
+ }
69
+ else if (opts.baseUrl.endsWith('?')) {
70
+ return `${opts.baseUrl}${opts.param ? opts.param + '=' : ''}${components}`;
71
+ }
72
+ else {
73
+ return `${opts.baseUrl}${opts.param ? '&' + opts.param : ''}=${components}`;
74
+ }
75
+ }
76
+ return components;
77
+ }
78
+ exports.convertJsonToURI = convertJsonToURI;
79
+ /**
80
+ * @function decodeUriAsJson decodes a URI into a Json object
81
+ * @param uri string
82
+ * @param opts:
83
+ * - requiredProperties: the required properties
84
+ * - arrayTypeProperties: properties that can show up more that once
85
+ */
86
+ function convertURIToJsonObject(uri, opts) {
87
+ var _a;
88
+ if (!uri || !((_a = opts === null || opts === void 0 ? void 0 : opts.requiredProperties) === null || _a === void 0 ? void 0 : _a.every((p) => uri.includes(p)))) {
89
+ throw new Error(types_1.BAD_PARAMS);
90
+ }
91
+ const uriComponents = getURIComponentsAsArray(uri, opts === null || opts === void 0 ? void 0 : opts.arrayTypeProperties);
92
+ return decodeJsonProperties(uriComponents);
93
+ }
94
+ exports.convertURIToJsonObject = convertURIToJsonObject;
95
+ function decodeJsonProperties(parts) {
96
+ const json = {};
97
+ for (const key in parts) {
98
+ const value = parts[key];
99
+ if (!value) {
100
+ continue;
101
+ }
102
+ if (Array.isArray(value)) {
103
+ // if (value.length > 1) {
104
+ json[decodeURIComponent(key)] = value.map((v) => decodeURIComponent(v));
105
+ /*} else {
106
+ json[decodeURIComponent(key)] = decodeURIComponent(value[0]);
107
+ }*/
108
+ }
109
+ const isBool = typeof value == 'boolean';
110
+ const isNumber = typeof value == 'number';
111
+ const isString = typeof value == 'string';
112
+ if (isBool || isNumber) {
113
+ json[decodeURIComponent(key)] = value;
114
+ }
115
+ else if (isString) {
116
+ const decoded = decodeURIComponent(value);
117
+ if (decoded.startsWith('{') && decoded.endsWith('}')) {
118
+ json[decodeURIComponent(key)] = JSON.parse(decoded);
119
+ }
120
+ else {
121
+ json[decodeURIComponent(key)] = decoded;
122
+ }
123
+ }
124
+ }
125
+ return json;
126
+ }
127
+ /**
128
+ * @function get URI Components as Array
129
+ * @param uri string
130
+ * @param arrayTypes array of string containing array like keys
131
+ */
132
+ function getURIComponentsAsArray(uri, arrayTypes) {
133
+ const parts = uri.includes('?') ? uri.split('?')[1] : uri.includes('://') ? uri.split('://')[1] : uri;
134
+ const json = [];
135
+ const dict = parts.split('&');
136
+ for (const entry of dict) {
137
+ const pair = entry.split('=');
138
+ const p0 = pair[0];
139
+ const p1 = pair[1];
140
+ if (arrayTypes === null || arrayTypes === void 0 ? void 0 : arrayTypes.includes(p0)) {
141
+ const key = json[p0];
142
+ if (Array.isArray(key)) {
143
+ key.push(p1);
144
+ }
145
+ else {
146
+ json[p0] = [p1];
147
+ }
148
+ continue;
149
+ }
150
+ json[p0] = p1;
151
+ }
152
+ return json;
153
+ }
154
+ /**
155
+ * @function customEncodeURIComponent is used to encode chars that are not encoded by default
156
+ * @param searchValue The pattern/regexp to find the char(s) to be encoded
157
+ * @param uriComponent query string
158
+ */
159
+ function customEncodeURIComponent(uriComponent, searchValue) {
160
+ // -_.!~*'() are not escaped because they are considered safe.
161
+ // Add them to the regex as you need
162
+ return encodeURIComponent(uriComponent).replace(searchValue, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`);
163
+ }
164
+ //# sourceMappingURL=Encoding.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Encoding.js","sourceRoot":"","sources":["../../lib/functions/Encoding.ts"],"names":[],"mappings":";AAAA,qCAAqC;;;AAErC,oCAAgH;AAEhH;;;;;;GAMG;AAEH,0DAA0D;AAC1D,SAAgB,gBAAgB,CAC9B,IAMU,EACV,IAA0B;;IAE1B,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC5B,OAAO,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;KACjD;IAED,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,IAAI,UAAkB,CAAC;IACvB,IAAI,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,KAAI,IAAI,CAAC,OAAO,GAAG,yBAAiB,CAAC,UAAU,EAAE;QAChE,mGAAmG;QACnG,UAAU,GAAG,wBAAwB,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;KAC7D;SAAM;QACL,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YAC/C,IAAI,CAAC,KAAK,EAAE;gBACV,SAAS;aACV;YACD,0CAA0C;YAC1C,IAAI,CAAC,CAAA,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,iBAAiB,0CAAE,QAAQ,CAAC,GAAG,CAAC,CAAA,EAAE;gBAC3C,OAAO,CAAC,IAAI,CAAC,GAAG,GAAG,IAAI,KAAK,EAAE,CAAC,CAAC;gBAChC,SAAS;aACV;YACD,IAAI,CAAA,MAAA,IAAI,aAAJ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C,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,33 @@
1
+ import { OpenIDResponse } from '../types';
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
+ export declare const trimBoth: (value: string, trim: string) => string;
25
+ export declare const trimEnd: (value: string, trim: string) => string;
26
+ export declare const trimStart: (value: string, trim: string) => string;
27
+ export declare const adjustUrl: <T extends string | URL>(urlOrPath: T, opts?: {
28
+ stripSlashEnd?: boolean;
29
+ stripSlashStart?: boolean;
30
+ prepend?: string;
31
+ append?: string;
32
+ }) => T;
33
+ //# sourceMappingURL=HttpUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HttpUtils.d.ts","sourceRoot":"","sources":["../../lib/functions/HttpUtils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAY,cAAc,EAAE,MAAM,UAAU,CAAC;AAIpD,eAAO,MAAM,OAAO,WACb,MAAM,SACJ;IAAE,WAAW,CAAC,EAAE,MAAM,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1,146 @@
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.adjustUrl = exports.trimStart = exports.trimEnd = exports.trimBoth = exports.isValidURL = exports.post = exports.formPost = exports.getJson = void 0;
16
+ const cross_fetch_1 = require("cross-fetch");
17
+ const debug_1 = __importDefault(require("debug"));
18
+ const types_1 = require("../types");
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: types_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
+ console.log(`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 && responseText.includes('{') ? JSON.parse(responseText) : responseText;
69
+ console.log(`${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
+ const trimBoth = (value, trim) => {
94
+ return (0, exports.trimEnd)((0, exports.trimStart)(value, trim), trim);
95
+ };
96
+ exports.trimBoth = trimBoth;
97
+ const trimEnd = (value, trim) => {
98
+ return value.endsWith(trim) ? value.substring(0, value.length - trim.length) : value;
99
+ };
100
+ exports.trimEnd = trimEnd;
101
+ const trimStart = (value, trim) => {
102
+ return value.startsWith(trim) ? value.substring(trim.length) : value;
103
+ };
104
+ exports.trimStart = trimStart;
105
+ const adjustUrl = (urlOrPath, opts) => {
106
+ let url = typeof urlOrPath === 'object' ? urlOrPath.toString() : urlOrPath;
107
+ if (opts === null || opts === void 0 ? void 0 : opts.append) {
108
+ url = (0, exports.trimEnd)(url, '/') + '/' + (0, exports.trimStart)(opts.append, '/');
109
+ }
110
+ if (opts === null || opts === void 0 ? void 0 : opts.prepend) {
111
+ if (opts.prepend.includes('://')) {
112
+ // includes domain/hostname
113
+ if (!url.startsWith(opts.prepend)) {
114
+ url = (0, exports.trimEnd)(opts.prepend, '/') + '/' + (0, exports.trimStart)(url, '/');
115
+ }
116
+ }
117
+ else {
118
+ // path only for prepend
119
+ let host = '';
120
+ let path = url;
121
+ if (url.includes('://')) {
122
+ // includes domain/hostname
123
+ host = new URL(url).host;
124
+ path = new URL(url).pathname;
125
+ }
126
+ if (!path.startsWith(opts.prepend)) {
127
+ if (host && host !== '') {
128
+ url = (0, exports.trimEnd)(host, '/');
129
+ }
130
+ url += (0, exports.trimEnd)(url, '/') + '/' + (0, exports.trimBoth)(opts.prepend, '/') + '/' + (0, exports.trimStart)(path, '/');
131
+ }
132
+ }
133
+ }
134
+ if (opts === null || opts === void 0 ? void 0 : opts.stripSlashStart) {
135
+ url = (0, exports.trimStart)(url, '/');
136
+ }
137
+ if (opts === null || opts === void 0 ? void 0 : opts.stripSlashEnd) {
138
+ url = (0, exports.trimEnd)(url, '/');
139
+ }
140
+ if (typeof urlOrPath === 'string') {
141
+ return url;
142
+ }
143
+ return new URL(url);
144
+ };
145
+ exports.adjustUrl = adjustUrl;
146
+ //# sourceMappingURL=HttpUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HttpUtils.js","sourceRoot":"","sources":["../../lib/functions/HttpUtils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,6CAAoC;AACpC,kDAA0B;AAE1B,oCAAoD;AAEpD,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,gBAAQ,CAAC,gBAAgB,IAAK,IAAI,CAAE,CAAC,CAAC;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etadata, CredentialOfferFormat, CredentialSupported, CredentialSupportedTypeV1_0_08, CredentialSupportedV1_0_08, IssuerMetadataV1_0_08, OpenId4VCIVersion } from '../types';
2
+ export declare function getSupportedCredentials(opts?: {
3
+ issuerMetadata?: CredentialIssuerMetadata | IssuerMetadataV1_0_08;
4
+ version: OpenId4VCIVersion;
5
+ credentialTypes?: (CredentialOfferFormat | string)[];
6
+ supportedType?: CredentialOfferFormat | string;
7
+ }): CredentialSupported[];
8
+ export declare function credentialsSupportedV8ToV11(supportedV8: CredentialSupportedTypeV1_0_08): CredentialSupported[];
9
+ export declare function credentialSupportedV8ToV11(key: string, supportedV8: CredentialSupportedV1_0_08): CredentialSupported[];
10
+ //# sourceMappingURL=IssuerMetadataUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IssuerMetadataUtils.d.ts","sourceRoot":"","sources":["../../lib/functions/IssuerMetadataUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,qBAAqB,EACrB,mBAAmB,EACnB,8BAA8B,EAC9B,0BAA0B,EAC1B,qBAAqB,EACrB,iBAAiB,EAClB,MAAM,UAAU,CAAC;AAElB,wBAAgB,uBAAuB,CAAC,IAAI,CAAC,EAAE;IAC7C,cAAc,CAAC,EAAE,wBAAwB,GAAG,qBAAqB,CAAC;IAClE,OAAO,EAAE,iBAAiB,CAAC;IAC3B,eAAe,CAAC,EAAE,CAAC,qBAAqB,GAAG,MAAM,CAAC,EAAE,CAAC;IACrD,aAAa,CAAC,EAAE,qBAAqB,GAAG,MAAM,CAAC;CAChD,GAAG,mBAAmB,EAAE,CAgDxB;AAaD,wBAAgB,2BAA2B,CAAC,WAAW,EAAE,8BAA8B,GAAG,mBAAmB,EAAE,CAM9G;AAED,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,0BAA0B,GAAG,mBAAmB,EAAE,CAgBtH"}
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.credentialSupportedV8ToV11 = exports.credentialsSupportedV8ToV11 = exports.getSupportedCredentials = void 0;
4
+ const types_1 = require("../types");
5
+ function getSupportedCredentials(opts) {
6
+ const { issuerMetadata } = opts !== null && opts !== void 0 ? opts : {};
7
+ let credentialsSupported;
8
+ if (!issuerMetadata) {
9
+ return [];
10
+ }
11
+ const { version, credentialTypes, supportedType } = opts !== null && opts !== void 0 ? opts : { version: types_1.OpenId4VCIVersion.VER_1_0_11 };
12
+ if (version === types_1.OpenId4VCIVersion.VER_1_0_08 || !Array.isArray(issuerMetadata.credentials_supported)) {
13
+ credentialsSupported = credentialsSupportedV8ToV11(issuerMetadata.credentials_supported);
14
+ /* const credentialsSupportedV8: CredentialSupportedV1_0_08 = credentialsSupported as CredentialSupportedV1_0_08
15
+ // const initiationTypes = credentialTypes.map(type => typeof type === 'string' ? [type] : type.types)
16
+ const supported: IssuerCredentialSubject = {}
17
+ for (const [key, value] of Object.entries(credentialsSupportedV8)) {
18
+ if (initiationTypes.find((type) => (typeof type === 'string' ? type === key : type.types.includes(key)))) {
19
+ supported[key] = value
20
+ }
21
+ }
22
+ // todo: fix this later. we're returning CredentialSupportedV1_0_08 as a list of CredentialSupported (for v09 onward)
23
+ return supported as unknown as CredentialSupported[]*/
24
+ }
25
+ else {
26
+ credentialsSupported = issuerMetadata.credentials_supported;
27
+ }
28
+ if (credentialsSupported === undefined || credentialsSupported.length === 0) {
29
+ return [];
30
+ }
31
+ else if (!credentialTypes || credentialTypes.length === 0) {
32
+ return credentialsSupported;
33
+ }
34
+ /**
35
+ * the following (not array part is a legacy code from version 1_0-08 which JFF plugfest 2 implementors used)
36
+ */
37
+ const initiationTypes = supportedType ? [supportedType] : credentialTypes;
38
+ const credentialSupportedOverlap = [];
39
+ for (const offerType of initiationTypes) {
40
+ if (typeof offerType === 'string') {
41
+ const supported = credentialsSupported.find((sup) => sup.id === offerType || sup.types.includes(offerType));
42
+ if (supported) {
43
+ credentialSupportedOverlap.push(supported);
44
+ }
45
+ }
46
+ else {
47
+ const supported = credentialsSupported.find((sup) => arrayEqualsIgnoreOrder(sup.types, offerType.types) && sup.format === offerType.format);
48
+ if (supported) {
49
+ credentialSupportedOverlap.push(supported);
50
+ }
51
+ }
52
+ }
53
+ return credentialSupportedOverlap;
54
+ }
55
+ exports.getSupportedCredentials = getSupportedCredentials;
56
+ function arrayEqualsIgnoreOrder(a, b) {
57
+ if (a.length !== b.length)
58
+ return false;
59
+ const uniqueValues = new Set([...a, ...b]);
60
+ for (const v of uniqueValues) {
61
+ const aCount = a.filter((e) => e === v).length;
62
+ const bCount = b.filter((e) => e === v).length;
63
+ if (aCount !== bCount)
64
+ return false;
65
+ }
66
+ return true;
67
+ }
68
+ function credentialsSupportedV8ToV11(supportedV8) {
69
+ return Object.entries(supportedV8).flatMap((entry) => {
70
+ const type = entry[0];
71
+ const supportedV8 = entry[1];
72
+ return credentialSupportedV8ToV11(type, supportedV8);
73
+ });
74
+ }
75
+ exports.credentialsSupportedV8ToV11 = credentialsSupportedV8ToV11;
76
+ function credentialSupportedV8ToV11(key, supportedV8) {
77
+ return Object.entries(supportedV8.formats).map((entry) => {
78
+ const format = entry[0];
79
+ const credentialSupportBrief = entry[1];
80
+ if (typeof format !== 'string') {
81
+ throw Error(`Unknown format received ${JSON.stringify(format)}`);
82
+ }
83
+ let credentialSupport = {};
84
+ credentialSupport = Object.assign(Object.assign({ format, display: supportedV8.display }, credentialSupportBrief), { credentialSubject: supportedV8.claims });
85
+ return credentialSupport;
86
+ });
87
+ }
88
+ exports.credentialSupportedV8ToV11 = credentialSupportedV8ToV11;
89
+ //# sourceMappingURL=IssuerMetadataUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IssuerMetadataUtils.js","sourceRoot":"","sources":["../../lib/functions/IssuerMetadataUtils.ts"],"names":[],"mappings":";;;AAAA,oCAQkB;AAElB,SAAgB,uBAAuB,CAAC,IAKvC;IACC,MAAM,EAAE,cAAc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C7B,OAAO,0BAA0B,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;AACL,CAAC;AAND,kEAMC;AAED,SAAgB,0BAA0B,CAAC,GAAW,EAAE,WAAuC;IAC7F,OAAO,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QACvD,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACxB,MAAM,sBAAsB,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACxC,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;YAC9B,MAAM,KAAK,CAAC,2BAA2B,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;SAClE;QACD,IAAI,iBAAiB,GAAiC,EAAE,CAAC;QACzD,iBAAiB,iCACf,MAAM,EACN,OAAO,EAAE,WAAW,CAAC,OAAO,IACzB,sBAAsB,KACzB,iBAAiB,EAAE,WAAW,CAAC,MAAM,GACtC,CAAC;QACF,OAAO,iBAAwC,CAAC;IAClD,CAAC,CAAC,CAAC;AACL,CAAC;AAhBD,gEAgBC"}
@@ -0,0 +1,2 @@
1
+ export declare const getNumberOrUndefined: (input?: string) => number | undefined;
2
+ //# sourceMappingURL=TypeConversionUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TypeConversionUtils.d.ts","sourceRoot":"","sources":["../../lib/functions/TypeConversionUtils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,WAAY,MAAM,KAAG,MAAM,GAAG,SAE9D,CAAC"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getNumberOrUndefined = void 0;
4
+ const getNumberOrUndefined = (input) => {
5
+ return input && !isNaN(+input) ? +input : undefined;
6
+ };
7
+ exports.getNumberOrUndefined = getNumberOrUndefined;
8
+ //# sourceMappingURL=TypeConversionUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TypeConversionUtils.js","sourceRoot":"","sources":["../../lib/functions/TypeConversionUtils.ts"],"names":[],"mappings":";;;AAAO,MAAM,oBAAoB,GAAG,CAAC,KAAc,EAAsB,EAAE;IACzE,OAAO,KAAK,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACtD,CAAC,CAAC;AAFW,QAAA,oBAAoB,wBAE/B"}
@@ -0,0 +1,4 @@
1
+ export * from './CredentialOfferUtil';
2
+ export * from './Encoding';
3
+ export * from './TypeConversionUtils';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/functions/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,YAAY,CAAC;AAC3B,cAAc,uBAAuB,CAAC"}
@@ -0,0 +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("./CredentialOfferUtil"), exports);
18
+ __exportStar(require("./Encoding"), exports);
19
+ __exportStar(require("./TypeConversionUtils"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/functions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAsC;AACtC,6CAA2B;AAC3B,wDAAsC"}
@@ -0,0 +1,3 @@
1
+ export * from './functions';
2
+ export * from './types';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
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
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,0CAAwB"}