@sphereon/oid4vci-common 0.10.4-unstable.2 → 0.10.4-unstable.6
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.
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { DecodeURIAsJsonOpts, EncodeJsonAsURIOpts } from '../types';
|
|
2
2
|
/**
|
|
3
|
-
* @
|
|
4
|
-
* @param
|
|
5
|
-
* @param opts
|
|
3
|
+
* @type {(json: {[s:string]: never} | ArrayLike<never> | string | object, opts?: EncodeJsonAsURIOpts)} encodes a Json object into a URI
|
|
4
|
+
* @param { {[s:string]: never} | ArrayLike<never> | string | object } json
|
|
5
|
+
* @param {EncodeJsonAsURIOpts} [opts] Option to encode json as uri
|
|
6
6
|
* - urlTypeProperties: a list of properties of which the value is a URL
|
|
7
7
|
* - arrayTypeProperties: a list of properties which are an array
|
|
8
8
|
*/
|
|
@@ -10,11 +10,12 @@ export declare function convertJsonToURI(json: {
|
|
|
10
10
|
[s: string]: never;
|
|
11
11
|
} | ArrayLike<never> | string | object, opts?: EncodeJsonAsURIOpts): string;
|
|
12
12
|
/**
|
|
13
|
-
* @
|
|
14
|
-
* @param uri
|
|
15
|
-
* @param opts
|
|
13
|
+
* @type {(uri: string, opts?: DecodeURIAsJsonOpts): unknown} convertURIToJsonObject converts an URI into a Json object decoding its properties
|
|
14
|
+
* @param {string} uri
|
|
15
|
+
* @param {DecodeURIAsJsonOpts} [opts]
|
|
16
16
|
* - requiredProperties: the required properties
|
|
17
17
|
* - arrayTypeProperties: properties that can show up more that once
|
|
18
|
+
* @returns JSON object
|
|
18
19
|
*/
|
|
19
20
|
export declare function convertURIToJsonObject(uri: string, opts?: DecodeURIAsJsonOpts): unknown;
|
|
20
21
|
//# sourceMappingURL=Encoding.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Encoding.d.ts","sourceRoot":"","sources":["../../lib/functions/Encoding.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"Encoding.d.ts","sourceRoot":"","sources":["../../lib/functions/Encoding.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,mBAAmB,EACnB,mBAAmB,EAIpB,MAAM,UAAU,CAAA;AAEjB;;;;;;GAMG;AAGH,wBAAgB,gBAAgB,CAC9B,IAAI,EACA;IACE,CAAC,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;CACpB,GACD,SAAS,CAAC,KAAK,CAAC,GAChB,MAAM,GACN,MAAM,EACV,IAAI,CAAC,EAAE,mBAAmB,GACzB,MAAM,CA4DR;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAevF"}
|
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.convertURIToJsonObject = exports.convertJsonToURI = void 0;
|
|
4
4
|
const types_1 = require("../types");
|
|
5
5
|
/**
|
|
6
|
-
* @
|
|
7
|
-
* @param
|
|
8
|
-
* @param opts
|
|
6
|
+
* @type {(json: {[s:string]: never} | ArrayLike<never> | string | object, opts?: EncodeJsonAsURIOpts)} encodes a Json object into a URI
|
|
7
|
+
* @param { {[s:string]: never} | ArrayLike<never> | string | object } json
|
|
8
|
+
* @param {EncodeJsonAsURIOpts} [opts] Option to encode json as uri
|
|
9
9
|
* - urlTypeProperties: a list of properties of which the value is a URL
|
|
10
10
|
* - arrayTypeProperties: a list of properties which are an array
|
|
11
11
|
*/
|
|
@@ -77,21 +77,43 @@ function convertJsonToURI(json, opts) {
|
|
|
77
77
|
}
|
|
78
78
|
exports.convertJsonToURI = convertJsonToURI;
|
|
79
79
|
/**
|
|
80
|
-
* @
|
|
81
|
-
* @param uri
|
|
82
|
-
* @param opts
|
|
80
|
+
* @type {(uri: string, opts?: DecodeURIAsJsonOpts): unknown} convertURIToJsonObject converts an URI into a Json object decoding its properties
|
|
81
|
+
* @param {string} uri
|
|
82
|
+
* @param {DecodeURIAsJsonOpts} [opts]
|
|
83
83
|
* - requiredProperties: the required properties
|
|
84
84
|
* - arrayTypeProperties: properties that can show up more that once
|
|
85
|
+
* @returns JSON object
|
|
85
86
|
*/
|
|
86
87
|
function convertURIToJsonObject(uri, opts) {
|
|
87
88
|
var _a;
|
|
88
89
|
if (!uri || ((opts === null || opts === void 0 ? void 0 : opts.requiredProperties) && !((_a = opts.requiredProperties) === null || _a === void 0 ? void 0 : _a.every((p) => uri.includes(p))))) {
|
|
89
90
|
throw new Error(types_1.BAD_PARAMS);
|
|
90
91
|
}
|
|
92
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.arrayTypeProperties) && opts.arrayTypeProperties.includes('credential_offer_uri')) {
|
|
93
|
+
return encodedCredentialOfferUri2Json({ uri });
|
|
94
|
+
}
|
|
95
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.arrayTypeProperties) && opts.arrayTypeProperties.includes('credential_offer')) {
|
|
96
|
+
return encodedCredentialOffer2Json({ uri });
|
|
97
|
+
}
|
|
91
98
|
const uriComponents = getURIComponentsAsArray(uri, opts === null || opts === void 0 ? void 0 : opts.arrayTypeProperties);
|
|
92
99
|
return decodeJsonProperties(uriComponents);
|
|
93
100
|
}
|
|
94
101
|
exports.convertURIToJsonObject = convertURIToJsonObject;
|
|
102
|
+
function encodedCredentialOfferUri2Json(args) {
|
|
103
|
+
const { uri } = args;
|
|
104
|
+
const value = uri.includes('?') ? uri.split('?')[1].split('=') : uri;
|
|
105
|
+
return {
|
|
106
|
+
credential_offer_uri: value[1]
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function encodedCredentialOffer2Json(args) {
|
|
110
|
+
const { uri } = args;
|
|
111
|
+
const decodedUri = decodeURIComponent(uri);
|
|
112
|
+
const value = decodedUri.includes('?') ? decodedUri.split('?')[1].split('=') : decodedUri;
|
|
113
|
+
return {
|
|
114
|
+
credential_offer: JSON.parse(value[1])
|
|
115
|
+
};
|
|
116
|
+
}
|
|
95
117
|
function decodeJsonProperties(parts) {
|
|
96
118
|
const json = {};
|
|
97
119
|
for (const key in parts) {
|
|
@@ -126,8 +148,8 @@ function decodeJsonProperties(parts) {
|
|
|
126
148
|
}
|
|
127
149
|
/**
|
|
128
150
|
* @function get URI Components as Array
|
|
129
|
-
* @param uri
|
|
130
|
-
* @param arrayTypes array of string containing array like keys
|
|
151
|
+
* @param {string} uri uri
|
|
152
|
+
* @param {string[]} [arrayTypes] array of string containing array like keys
|
|
131
153
|
*/
|
|
132
154
|
function getURIComponentsAsArray(uri, arrayTypes) {
|
|
133
155
|
const parts = uri.includes('?') ? uri.split('?')[1] : uri.includes('://') ? uri.split('://')[1] : uri;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Encoding.js","sourceRoot":"","sources":["../../lib/functions/Encoding.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"Encoding.js","sourceRoot":"","sources":["../../lib/functions/Encoding.ts"],"names":[],"mappings":";;;AAAA,oCAQiB;AAEjB;;;;;;GAMG;AAEH,0DAA0D;AAC1D,SAAgB,gBAAgB,CAC9B,IAMU,EACV,IAA0B;;IAE1B,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,OAAO,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;IAClD,CAAC;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,CAAC,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,KAAI,IAAI,CAAC,OAAO,GAAG,yBAAiB,CAAC,UAAU,IAAI,CAAC,IAAI,C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MS,
|
|
3
|
+
CredentialOfferV1_0_11,
|
|
4
|
+
DecodeURIAsJsonOpts,
|
|
5
|
+
EncodeJsonAsURIOpts,
|
|
6
|
+
JsonURIMode,
|
|
7
|
+
OpenId4VCIVersion,
|
|
8
|
+
SearchValue
|
|
9
|
+
} from '../types'
|
|
2
10
|
|
|
3
11
|
/**
|
|
4
|
-
* @
|
|
5
|
-
* @param
|
|
6
|
-
* @param opts
|
|
12
|
+
* @type {(json: {[s:string]: never} | ArrayLike<never> | string | object, opts?: EncodeJsonAsURIOpts)} encodes a Json object into a URI
|
|
13
|
+
* @param { {[s:string]: never} | ArrayLike<never> | string | object } json
|
|
14
|
+
* @param {EncodeJsonAsURIOpts} [opts] Option to encode json as uri
|
|
7
15
|
* - urlTypeProperties: a list of properties of which the value is a URL
|
|
8
16
|
* - arrayTypeProperties: a list of properties which are an array
|
|
9
17
|
*/
|
|
@@ -81,20 +89,47 @@ export function convertJsonToURI(
|
|
|
81
89
|
}
|
|
82
90
|
|
|
83
91
|
/**
|
|
84
|
-
* @
|
|
85
|
-
* @param uri
|
|
86
|
-
* @param opts
|
|
92
|
+
* @type {(uri: string, opts?: DecodeURIAsJsonOpts): unknown} convertURIToJsonObject converts an URI into a Json object decoding its properties
|
|
93
|
+
* @param {string} uri
|
|
94
|
+
* @param {DecodeURIAsJsonOpts} [opts]
|
|
87
95
|
* - requiredProperties: the required properties
|
|
88
96
|
* - arrayTypeProperties: properties that can show up more that once
|
|
97
|
+
* @returns JSON object
|
|
89
98
|
*/
|
|
90
99
|
export function convertURIToJsonObject(uri: string, opts?: DecodeURIAsJsonOpts): unknown {
|
|
91
100
|
if (!uri || (opts?.requiredProperties && !opts.requiredProperties?.every((p) => uri.includes(p)))) {
|
|
92
101
|
throw new Error(BAD_PARAMS);
|
|
93
102
|
}
|
|
103
|
+
|
|
104
|
+
if (opts?.arrayTypeProperties && opts.arrayTypeProperties.includes('credential_offer_uri')) {
|
|
105
|
+
return encodedCredentialOfferUri2Json({ uri })
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (opts?.arrayTypeProperties && opts.arrayTypeProperties.includes('credential_offer')) {
|
|
109
|
+
return encodedCredentialOffer2Json({ uri })
|
|
110
|
+
}
|
|
111
|
+
|
|
94
112
|
const uriComponents = getURIComponentsAsArray(uri, opts?.arrayTypeProperties);
|
|
95
113
|
return decodeJsonProperties(uriComponents);
|
|
96
114
|
}
|
|
97
115
|
|
|
116
|
+
function encodedCredentialOfferUri2Json(args: { uri: string }): Pick<CredentialOfferV1_0_11, 'credential_offer_uri'> {
|
|
117
|
+
const { uri } = args
|
|
118
|
+
const value = uri.includes('?') ? uri.split('?')[1].split('=') : uri
|
|
119
|
+
return {
|
|
120
|
+
credential_offer_uri: value[1]
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function encodedCredentialOffer2Json(args: { uri: string }): Pick<CredentialOfferV1_0_11, 'credential_offer'> {
|
|
125
|
+
const { uri } = args
|
|
126
|
+
const decodedUri = decodeURIComponent(uri)
|
|
127
|
+
const value = decodedUri.includes('?') ? decodedUri.split('?')[1].split('=') : decodedUri
|
|
128
|
+
return {
|
|
129
|
+
credential_offer: JSON.parse(value[1])
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
98
133
|
function decodeJsonProperties(parts: string[] | string[][]): unknown {
|
|
99
134
|
const json: { [s: string]: unknown } | ArrayLike<unknown> = {};
|
|
100
135
|
for (const key in parts) {
|
|
@@ -128,8 +163,8 @@ function decodeJsonProperties(parts: string[] | string[][]): unknown {
|
|
|
128
163
|
|
|
129
164
|
/**
|
|
130
165
|
* @function get URI Components as Array
|
|
131
|
-
* @param uri
|
|
132
|
-
* @param arrayTypes array of string containing array like keys
|
|
166
|
+
* @param {string} uri uri
|
|
167
|
+
* @param {string[]} [arrayTypes] array of string containing array like keys
|
|
133
168
|
*/
|
|
134
169
|
function getURIComponentsAsArray(uri: string, arrayTypes?: string[]): string[] | string[][] {
|
|
135
170
|
const parts = uri.includes('?') ? uri.split('?')[1] : uri.includes('://') ? uri.split('://')[1] : uri;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/oid4vci-common",
|
|
3
|
-
"version": "0.10.4-unstable.
|
|
3
|
+
"version": "0.10.4-unstable.6+f6c4d31",
|
|
4
4
|
"description": "OpenID 4 Verifiable Credential Issuance Common Types",
|
|
5
5
|
"source": "lib/index.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"publishConfig": {
|
|
58
58
|
"access": "public"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "f6c4d319a04cc9bcdf513c34f2141abdb76e281a"
|
|
61
61
|
}
|