@pagopa/io-react-native-wallet 2.2.0 → 2.3.0
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/README.md +4 -3
- package/lib/commonjs/credential/index.js +3 -1
- package/lib/commonjs/credential/index.js.map +1 -1
- package/lib/commonjs/credential/offer/01-start-flow.js +75 -0
- package/lib/commonjs/credential/offer/01-start-flow.js.map +1 -0
- package/lib/commonjs/credential/offer/02-fetch-credential-offer.js +45 -0
- package/lib/commonjs/credential/offer/02-fetch-credential-offer.js.map +1 -0
- package/lib/commonjs/credential/offer/README.md +174 -0
- package/lib/commonjs/credential/offer/errors.js +22 -0
- package/lib/commonjs/credential/offer/errors.js.map +1 -0
- package/lib/commonjs/credential/offer/index.js +25 -0
- package/lib/commonjs/credential/offer/index.js.map +1 -0
- package/lib/commonjs/credential/offer/types.js +51 -0
- package/lib/commonjs/credential/offer/types.js.map +1 -0
- package/lib/commonjs/credential/presentation/01-start-flow.js +1 -1
- package/lib/commonjs/credentials-catalogue/README.md +15 -0
- package/lib/commonjs/credentials-catalogue/fetch-and-parse-catalogue.js +42 -0
- package/lib/commonjs/credentials-catalogue/fetch-and-parse-catalogue.js.map +1 -0
- package/lib/commonjs/credentials-catalogue/index.js +13 -0
- package/lib/commonjs/credentials-catalogue/index.js.map +1 -0
- package/lib/commonjs/credentials-catalogue/types.js +99 -0
- package/lib/commonjs/credentials-catalogue/types.js.map +1 -0
- package/lib/commonjs/index.js +3 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/utils/zod.js +28 -0
- package/lib/commonjs/utils/zod.js.map +1 -0
- package/lib/module/credential/index.js +2 -1
- package/lib/module/credential/index.js.map +1 -1
- package/lib/module/credential/offer/01-start-flow.js +66 -0
- package/lib/module/credential/offer/01-start-flow.js.map +1 -0
- package/lib/module/credential/offer/02-fetch-credential-offer.js +38 -0
- package/lib/module/credential/offer/02-fetch-credential-offer.js.map +1 -0
- package/lib/module/credential/offer/README.md +174 -0
- package/lib/module/credential/offer/errors.js +14 -0
- package/lib/module/credential/offer/errors.js.map +1 -0
- package/lib/module/credential/offer/index.js +5 -0
- package/lib/module/credential/offer/index.js.map +1 -0
- package/lib/module/credential/offer/types.js +41 -0
- package/lib/module/credential/offer/types.js.map +1 -0
- package/lib/module/credential/presentation/01-start-flow.js +1 -1
- package/lib/module/credentials-catalogue/README.md +15 -0
- package/lib/module/credentials-catalogue/fetch-and-parse-catalogue.js +35 -0
- package/lib/module/credentials-catalogue/fetch-and-parse-catalogue.js.map +1 -0
- package/lib/module/credentials-catalogue/index.js +2 -0
- package/lib/module/credentials-catalogue/index.js.map +1 -0
- package/lib/module/credentials-catalogue/types.js +89 -0
- package/lib/module/credentials-catalogue/types.js.map +1 -0
- package/lib/module/index.js +2 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/utils/zod.js +20 -0
- package/lib/module/utils/zod.js.map +1 -0
- package/lib/typescript/credential/index.d.ts +2 -1
- package/lib/typescript/credential/index.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/01-start-flow.d.ts +1 -1
- package/lib/typescript/credential/offer/01-start-flow.d.ts +172 -0
- package/lib/typescript/credential/offer/01-start-flow.d.ts.map +1 -0
- package/lib/typescript/credential/offer/02-fetch-credential-offer.d.ts +20 -0
- package/lib/typescript/credential/offer/02-fetch-credential-offer.d.ts.map +1 -0
- package/lib/typescript/credential/offer/errors.d.ts +10 -0
- package/lib/typescript/credential/offer/errors.d.ts.map +1 -0
- package/lib/typescript/credential/offer/index.d.ts +7 -0
- package/lib/typescript/credential/offer/index.d.ts.map +1 -0
- package/lib/typescript/credential/offer/types.d.ts +264 -0
- package/lib/typescript/credential/offer/types.d.ts.map +1 -0
- package/lib/typescript/credential/presentation/01-start-flow.d.ts +1 -1
- package/lib/typescript/credentials-catalogue/fetch-and-parse-catalogue.d.ts +15 -0
- package/lib/typescript/credentials-catalogue/fetch-and-parse-catalogue.d.ts.map +1 -0
- package/lib/typescript/credentials-catalogue/index.d.ts +3 -0
- package/lib/typescript/credentials-catalogue/index.d.ts.map +1 -0
- package/lib/typescript/credentials-catalogue/types.d.ts +844 -0
- package/lib/typescript/credentials-catalogue/types.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +2 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/utils/zod.d.ts +15 -0
- package/lib/typescript/utils/zod.d.ts.map +1 -0
- package/package.json +21 -2
- package/src/credential/index.ts +2 -1
- package/src/credential/issuance/01-start-flow.ts +1 -1
- package/src/credential/offer/01-start-flow.ts +89 -0
- package/src/credential/offer/02-fetch-credential-offer.ts +54 -0
- package/src/credential/offer/README.md +174 -0
- package/src/credential/offer/errors.ts +17 -0
- package/src/credential/offer/index.ts +16 -0
- package/src/credential/offer/types.ts +59 -0
- package/src/credential/presentation/01-start-flow.ts +1 -1
- package/src/credentials-catalogue/README.md +15 -0
- package/src/credentials-catalogue/fetch-and-parse-catalogue.ts +54 -0
- package/src/credentials-catalogue/index.ts +2 -0
- package/src/credentials-catalogue/types.ts +97 -0
- package/src/index.ts +2 -0
- package/src/utils/zod.ts +28 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.DigitalCredentialsCatalogue = exports.DigitalCredential = void 0;
|
|
7
|
+
var z = _interopRequireWildcard(require("zod"));
|
|
8
|
+
var _types = require("../sd-jwt/types");
|
|
9
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
10
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
11
|
+
const CredentialPurpose = z.object({
|
|
12
|
+
id: z.string(),
|
|
13
|
+
description: z.string(),
|
|
14
|
+
category: z.string(),
|
|
15
|
+
subcategory: z.string(),
|
|
16
|
+
claims_required: z.array(z.string()),
|
|
17
|
+
claim_recommended: z.array(z.string())
|
|
18
|
+
});
|
|
19
|
+
const CredentialIssuer = z.object({
|
|
20
|
+
id: z.string(),
|
|
21
|
+
organization_name: z.string(),
|
|
22
|
+
organization_code: z.string(),
|
|
23
|
+
organization_country: z.string(),
|
|
24
|
+
contacts: z.array(z.string()).optional(),
|
|
25
|
+
homepage_uri: z.string().optional(),
|
|
26
|
+
logo_uri: z.string().optional(),
|
|
27
|
+
policy_uri: z.string().optional(),
|
|
28
|
+
tos_uri: z.string().optional()
|
|
29
|
+
});
|
|
30
|
+
const AuthenticSource = z.object({
|
|
31
|
+
id: z.string(),
|
|
32
|
+
organization_name: z.string(),
|
|
33
|
+
organization_code: z.string(),
|
|
34
|
+
organization_country: z.string(),
|
|
35
|
+
source_type: z.enum(["public", "private"]),
|
|
36
|
+
contacts: z.array(z.string()).optional(),
|
|
37
|
+
homepage_uri: z.string().optional(),
|
|
38
|
+
logo_uri: z.string().optional(),
|
|
39
|
+
user_information: z.string().optional()
|
|
40
|
+
});
|
|
41
|
+
const CredentialFormat = z.object({
|
|
42
|
+
configuration_id: z.string(),
|
|
43
|
+
format: z.enum(["dc+sd-jwt", "mso_mdoc"]),
|
|
44
|
+
vct: z.string().url().optional(),
|
|
45
|
+
docType: z.string().optional(),
|
|
46
|
+
schema_uri: z.string().url().optional(),
|
|
47
|
+
"schema_uri#integrity": z.string().optional()
|
|
48
|
+
});
|
|
49
|
+
const Claim = z.object({
|
|
50
|
+
name: z.string(),
|
|
51
|
+
taxonomy_ref: z.string(),
|
|
52
|
+
display_name: z.string()
|
|
53
|
+
});
|
|
54
|
+
const DigitalCredential = z.object({
|
|
55
|
+
version: z.string(),
|
|
56
|
+
credential_type: z.string(),
|
|
57
|
+
legal_type: z.string(),
|
|
58
|
+
name: z.string(),
|
|
59
|
+
description: z.string(),
|
|
60
|
+
validity_info: z.object({
|
|
61
|
+
max_validity_days: z.number(),
|
|
62
|
+
status_methods: z.array(z.string()),
|
|
63
|
+
allowed_states: z.array(z.string())
|
|
64
|
+
}),
|
|
65
|
+
authentication: z.object({
|
|
66
|
+
user_auth_required: z.boolean(),
|
|
67
|
+
min_loa: z.string(),
|
|
68
|
+
supported_eid_schemes: z.array(z.string())
|
|
69
|
+
}),
|
|
70
|
+
purposes: z.array(CredentialPurpose),
|
|
71
|
+
issuers: z.array(CredentialIssuer),
|
|
72
|
+
authentic_sources: z.array(AuthenticSource),
|
|
73
|
+
formats: z.array(CredentialFormat),
|
|
74
|
+
claims: z.array(Claim)
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The Digital Credentials Catalogue published by the Trust Anchor
|
|
79
|
+
*
|
|
80
|
+
* @version 1.1.0
|
|
81
|
+
* @see https://italia.github.io/eid-wallet-it-docs/releases/1.1.0/en/registry-catalogue.html
|
|
82
|
+
*/
|
|
83
|
+
exports.DigitalCredential = DigitalCredential;
|
|
84
|
+
const DigitalCredentialsCatalogue = z.object({
|
|
85
|
+
header: z.object({
|
|
86
|
+
typ: z.string(),
|
|
87
|
+
alg: z.string(),
|
|
88
|
+
kid: z.string()
|
|
89
|
+
}),
|
|
90
|
+
payload: z.object({
|
|
91
|
+
catalog_version: z.string(),
|
|
92
|
+
taxonomy_uri: z.string().url(),
|
|
93
|
+
credentials: z.array(DigitalCredential),
|
|
94
|
+
iat: _types.UnixTime,
|
|
95
|
+
exp: _types.UnixTime
|
|
96
|
+
})
|
|
97
|
+
});
|
|
98
|
+
exports.DigitalCredentialsCatalogue = DigitalCredentialsCatalogue;
|
|
99
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["z","_interopRequireWildcard","require","_types","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","CredentialPurpose","object","id","string","description","category","subcategory","claims_required","array","claim_recommended","CredentialIssuer","organization_name","organization_code","organization_country","contacts","optional","homepage_uri","logo_uri","policy_uri","tos_uri","AuthenticSource","source_type","enum","user_information","CredentialFormat","configuration_id","format","vct","url","docType","schema_uri","Claim","name","taxonomy_ref","display_name","DigitalCredential","version","credential_type","legal_type","validity_info","max_validity_days","number","status_methods","allowed_states","authentication","user_auth_required","boolean","min_loa","supported_eid_schemes","purposes","issuers","authentic_sources","formats","claims","exports","DigitalCredentialsCatalogue","header","typ","alg","kid","payload","catalog_version","taxonomy_uri","credentials","iat","UnixTime","exp"],"sourceRoot":"../../../src","sources":["credentials-catalogue/types.ts"],"mappings":";;;;;;AAAA,IAAAA,CAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAA2C,SAAAE,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAJ,wBAAAQ,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,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,MAAM,EAAElF,CAAC,CAAC2B,MAAM,CAAC;IACfwD,GAAG,EAAEnF,CAAC,CAAC6B,MAAM,CAAC,CAAC;IACfuD,GAAG,EAAEpF,CAAC,CAAC6B,MAAM,CAAC,CAAC;IACfwD,GAAG,EAAErF,CAAC,CAAC6B,MAAM,CAAC;EAChB,CAAC,CAAC;EACFyD,OAAO,EAAEtF,CAAC,CAAC2B,MAAM,CAAC;IAChB4D,eAAe,EAAEvF,CAAC,CAAC6B,MAAM,CAAC,CAAC;IAC3B2D,YAAY,EAAExF,CAAC,CAAC6B,MAAM,CAAC,CAAC,CAACyB,GAAG,CAAC,CAAC;IAC9BmC,WAAW,EAAEzF,CAAC,CAACkC,KAAK,CAAC2B,iBAAiB,CAAC;IACvC6B,GAAG,EAAEC,eAAQ;IACbC,GAAG,EAAED;EACP,CAAC;AACH,CAAC,CAAC;AAACX,OAAA,CAAAC,2BAAA,GAAAA,2BAAA"}
|
package/lib/commonjs/index.js
CHANGED
|
@@ -15,7 +15,7 @@ Object.defineProperty(exports, "AuthorizationDetails", {
|
|
|
15
15
|
return _par.AuthorizationDetails;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
-
exports.WalletInstanceAttestation = exports.WalletInstance = exports.Trust = exports.SdJwt = exports.PID = exports.Mdoc = exports.Logging = exports.Errors = exports.Credential = void 0;
|
|
18
|
+
exports.WalletInstanceAttestation = exports.WalletInstance = exports.Trust = exports.SdJwt = exports.PID = exports.Mdoc = exports.Logging = exports.Errors = exports.CredentialsCatalogue = exports.Credential = void 0;
|
|
19
19
|
Object.defineProperty(exports, "createCryptoContextFor", {
|
|
20
20
|
enumerable: true,
|
|
21
21
|
get: function () {
|
|
@@ -32,6 +32,8 @@ var _jwk = require("./utils/jwk");
|
|
|
32
32
|
require("react-native-url-polyfill/auto");
|
|
33
33
|
var Credential = _interopRequireWildcard(require("./credential"));
|
|
34
34
|
exports.Credential = Credential;
|
|
35
|
+
var CredentialsCatalogue = _interopRequireWildcard(require("./credentials-catalogue"));
|
|
36
|
+
exports.CredentialsCatalogue = CredentialsCatalogue;
|
|
35
37
|
var PID = _interopRequireWildcard(require("./pid"));
|
|
36
38
|
exports.PID = PID;
|
|
37
39
|
var SdJwt = _interopRequireWildcard(require("./sd-jwt"));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_jwk","require","Credential","_interopRequireWildcard","exports","PID","SdJwt","Mdoc","Errors","WalletInstanceAttestation","Trust","WalletInstance","Logging","_par","_crypto","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,IAAAA,IAAA,GAAAC,OAAA;AAGAA,OAAA;AAEA,IAAAC,UAAA,GAAAC,uBAAA,CAAAF,OAAA;AAA2CG,OAAA,CAAAF,UAAA,GAAAA,UAAA;AAC3C,IAAAG,
|
|
1
|
+
{"version":3,"names":["_jwk","require","Credential","_interopRequireWildcard","exports","CredentialsCatalogue","PID","SdJwt","Mdoc","Errors","WalletInstanceAttestation","Trust","WalletInstance","Logging","_par","_crypto","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,IAAAA,IAAA,GAAAC,OAAA;AAGAA,OAAA;AAEA,IAAAC,UAAA,GAAAC,uBAAA,CAAAF,OAAA;AAA2CG,OAAA,CAAAF,UAAA,GAAAA,UAAA;AAC3C,IAAAG,oBAAA,GAAAF,uBAAA,CAAAF,OAAA;AAAgEG,OAAA,CAAAC,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A,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,CAAAL,GAAA,SAAAM,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAX,GAAA,QAAAW,GAAA,kBAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAd,GAAA,EAAAW,GAAA,SAAAI,IAAA,GAAAR,qBAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAV,GAAA,EAAAW,GAAA,cAAAI,IAAA,KAAAA,IAAA,CAAAV,GAAA,IAAAU,IAAA,CAAAC,GAAA,KAAAR,MAAA,CAAAC,cAAA,CAAAH,MAAA,EAAAK,GAAA,EAAAI,IAAA,YAAAT,MAAA,CAAAK,GAAA,IAAAX,GAAA,CAAAW,GAAA,SAAAL,MAAA,CAAAJ,OAAA,GAAAF,GAAA,MAAAG,KAAA,IAAAA,KAAA,CAAAa,GAAA,CAAAhB,GAAA,EAAAM,MAAA,YAAAA,MAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.stringToJSONSchema = exports.json = void 0;
|
|
7
|
+
var _zod = require("zod");
|
|
8
|
+
/**
|
|
9
|
+
* @see https://github.com/JacobWeisenburger/zod_utilz/blob/main/src/stringToJSON.ts
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const literalSchema = _zod.z.union([_zod.z.string(), _zod.z.number(), _zod.z.boolean(), _zod.z.null()]);
|
|
13
|
+
const jsonSchema = _zod.z.lazy(() => _zod.z.union([literalSchema, _zod.z.array(jsonSchema), _zod.z.record(jsonSchema)]));
|
|
14
|
+
const json = () => jsonSchema;
|
|
15
|
+
exports.json = json;
|
|
16
|
+
const stringToJSONSchema = _zod.z.string().transform((str, ctx) => {
|
|
17
|
+
try {
|
|
18
|
+
return JSON.parse(str);
|
|
19
|
+
} catch (e) {
|
|
20
|
+
ctx.addIssue({
|
|
21
|
+
code: "custom",
|
|
22
|
+
message: "Invalid JSON"
|
|
23
|
+
});
|
|
24
|
+
return _zod.z.NEVER;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
exports.stringToJSONSchema = stringToJSONSchema;
|
|
28
|
+
//# sourceMappingURL=zod.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_zod","require","literalSchema","z","union","string","number","boolean","null","jsonSchema","lazy","array","record","json","exports","stringToJSONSchema","transform","str","ctx","JSON","parse","e","addIssue","code","message","NEVER"],"sourceRoot":"../../../src","sources":["utils/zod.ts"],"mappings":";;;;;;AAIA,IAAAA,IAAA,GAAAC,OAAA;AAJA;AACA;AACA;;AAIA,MAAMC,aAAa,GAAGC,MAAC,CAACC,KAAK,CAAC,CAACD,MAAC,CAACE,MAAM,CAAC,CAAC,EAAEF,MAAC,CAACG,MAAM,CAAC,CAAC,EAAEH,MAAC,CAACI,OAAO,CAAC,CAAC,EAAEJ,MAAC,CAACK,IAAI,CAAC,CAAC,CAAC,CAAC;AAM9E,MAAMC,UAA2B,GAAGN,MAAC,CAACO,IAAI,CAAC,MACzCP,MAAC,CAACC,KAAK,CAAC,CAACF,aAAa,EAAEC,MAAC,CAACQ,KAAK,CAACF,UAAU,CAAC,EAAEN,MAAC,CAACS,MAAM,CAACH,UAAU,CAAC,CAAC,CACpE,CAAC;AAEM,MAAMI,IAAI,GAAGA,CAAA,KAAMJ,UAAU;AAACK,OAAA,CAAAD,IAAA,GAAAA,IAAA;AAE9B,MAAME,kBAAkB,GAAGZ,MAAC,CAChCE,MAAM,CAAC,CAAC,CACRW,SAAS,CAAC,CAACC,GAAG,EAAEC,GAAG,KAAuC;EACzD,IAAI;IACF,OAAOC,IAAI,CAACC,KAAK,CAACH,GAAG,CAAC;EACxB,CAAC,CAAC,OAAOI,CAAC,EAAE;IACVH,GAAG,CAACI,QAAQ,CAAC;MAAEC,IAAI,EAAE,QAAQ;MAAEC,OAAO,EAAE;IAAe,CAAC,CAAC;IACzD,OAAOrB,MAAC,CAACsB,KAAK;EAChB;AACF,CAAC,CAAC;AAACX,OAAA,CAAAC,kBAAA,GAAAA,kBAAA"}
|
|
@@ -2,5 +2,6 @@ import * as Issuance from "./issuance";
|
|
|
2
2
|
import * as Presentation from "./presentation";
|
|
3
3
|
import * as Status from "./status";
|
|
4
4
|
import * as Trustmark from "./trustmark";
|
|
5
|
-
|
|
5
|
+
import * as Offer from "./offer";
|
|
6
|
+
export { Issuance, Presentation, Status, Trustmark, Offer };
|
|
6
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Issuance","Presentation","Status","Trustmark"],"sourceRoot":"../../../src","sources":["credential/index.ts"],"mappings":"AAAA,OAAO,KAAKA,QAAQ,MAAM,YAAY;AACtC,OAAO,KAAKC,YAAY,MAAM,gBAAgB;AAC9C,OAAO,KAAKC,MAAM,MAAM,UAAU;AAClC,OAAO,KAAKC,SAAS,MAAM,aAAa;
|
|
1
|
+
{"version":3,"names":["Issuance","Presentation","Status","Trustmark","Offer"],"sourceRoot":"../../../src","sources":["credential/index.ts"],"mappings":"AAAA,OAAO,KAAKA,QAAQ,MAAM,YAAY;AACtC,OAAO,KAAKC,YAAY,MAAM,gBAAgB;AAC9C,OAAO,KAAKC,MAAM,MAAM,UAAU;AAClC,OAAO,KAAKC,SAAS,MAAM,aAAa;AACxC,OAAO,KAAKC,KAAK,MAAM,SAAS;AAEhC,SAASJ,QAAQ,EAAEC,YAAY,EAAEC,MAAM,EAAEC,SAAS,EAAEC,KAAK"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
import { Logger, LogLevel } from "../../utils/logging";
|
|
3
|
+
import { stringToJSONSchema } from "../../utils/zod";
|
|
4
|
+
import { InvalidQRCodeError } from "./errors";
|
|
5
|
+
import { CredentialOfferSchema } from "./types";
|
|
6
|
+
const CREDENTIAL_OFFER_SCHEMES = ["openid-credential-offer://", "haip://"];
|
|
7
|
+
const CREDENTIAL_OFFER_PARAM = "credential_offer";
|
|
8
|
+
const CREDENTIAL_OFFER_URI_PARAM = "credential_offer_uri";
|
|
9
|
+
const CredentialOfferParams = z.union([z.object({
|
|
10
|
+
credential_offer: stringToJSONSchema.pipe(CredentialOfferSchema),
|
|
11
|
+
credential_offer_uri: z.undefined()
|
|
12
|
+
}), z.object({
|
|
13
|
+
credential_offer: z.undefined(),
|
|
14
|
+
credential_offer_uri: z.string().url()
|
|
15
|
+
})]);
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The beginning of the credential offer flow.
|
|
19
|
+
* To be implemented according to the user touchpoint
|
|
20
|
+
*
|
|
21
|
+
* @param params Credential offer encoded url
|
|
22
|
+
* @returns Object containing the credential offer by reference or by value
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Start a credential offer flow by validating and parse an encoded url
|
|
27
|
+
* extracted from a QR code or a deep link.
|
|
28
|
+
*
|
|
29
|
+
* @param params The encoded url to be validated and parsed
|
|
30
|
+
* @returns Object containing the credential offer by reference or by value
|
|
31
|
+
* @throws If the provided encoded url is not valid
|
|
32
|
+
*/
|
|
33
|
+
export const startFlowFromQR = encodedUrl => {
|
|
34
|
+
const hasValidScheme = CREDENTIAL_OFFER_SCHEMES.some(prefix => encodedUrl.startsWith(prefix));
|
|
35
|
+
if (!hasValidScheme) {
|
|
36
|
+
throw new InvalidQRCodeError("Url must have one of the supported schemes");
|
|
37
|
+
}
|
|
38
|
+
const url = new URL(encodedUrl);
|
|
39
|
+
const offerParam = url.searchParams.get(CREDENTIAL_OFFER_PARAM);
|
|
40
|
+
const offerUriParam = url.searchParams.get(CREDENTIAL_OFFER_URI_PARAM);
|
|
41
|
+
if (offerParam) {
|
|
42
|
+
const decoded = decodeURIComponent(offerParam);
|
|
43
|
+
const result = CredentialOfferParams.safeParse({
|
|
44
|
+
credential_offer: decoded
|
|
45
|
+
});
|
|
46
|
+
if (result.success) {
|
|
47
|
+
return result.data;
|
|
48
|
+
}
|
|
49
|
+
Logger.log(LogLevel.ERROR, `Invalid credential offer object found in QR Code: ${result.error.message}`);
|
|
50
|
+
throw new InvalidQRCodeError(result.error.message);
|
|
51
|
+
}
|
|
52
|
+
if (offerUriParam) {
|
|
53
|
+
const decoded = decodeURIComponent(offerUriParam);
|
|
54
|
+
const result = CredentialOfferParams.safeParse({
|
|
55
|
+
credential_offer_uri: decoded
|
|
56
|
+
});
|
|
57
|
+
if (result.success) {
|
|
58
|
+
return result.data;
|
|
59
|
+
}
|
|
60
|
+
Logger.log(LogLevel.ERROR, `Invalid credential offer URI found in QR Code: ${result.error.message}`);
|
|
61
|
+
throw new InvalidQRCodeError(result.error.message);
|
|
62
|
+
}
|
|
63
|
+
Logger.log(LogLevel.ERROR, `Invalid credential offer QR Code:`);
|
|
64
|
+
throw new InvalidQRCodeError("QR Code does not contain valid params");
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=01-start-flow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["z","Logger","LogLevel","stringToJSONSchema","InvalidQRCodeError","CredentialOfferSchema","CREDENTIAL_OFFER_SCHEMES","CREDENTIAL_OFFER_PARAM","CREDENTIAL_OFFER_URI_PARAM","CredentialOfferParams","union","object","credential_offer","pipe","credential_offer_uri","undefined","string","url","startFlowFromQR","encodedUrl","hasValidScheme","some","prefix","startsWith","URL","offerParam","searchParams","get","offerUriParam","decoded","decodeURIComponent","result","safeParse","success","data","log","ERROR","error","message"],"sourceRoot":"../../../../src","sources":["credential/offer/01-start-flow.ts"],"mappings":"AAAA,OAAO,KAAKA,CAAC,MAAM,KAAK;AACxB,SAASC,MAAM,EAAEC,QAAQ,QAAQ,qBAAqB;AACtD,SAASC,kBAAkB,QAAQ,iBAAiB;AACpD,SA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B,qBAAqB,CAACuB,SAAS,CAAC;MAC7CpB,gBAAgB,EAAEiB;IACpB,CAAC,CAAC;IAEF,IAAIE,MAAM,CAACE,OAAO,EAAE;MAClB,OAAOF,MAAM,CAACG,IAAI;IACpB;IAEAjC,MAAM,CAACkC,GAAG,CACRjC,QAAQ,CAACkC,KAAK,EACb,qDAAoDL,MAAM,CAACM,KAAK,CAACC,OAAQ,EAC5E,CAAC;IACD,MAAM,IAAIlC,kBAAkB,CAAC2B,MAAM,CAACM,KAAK,CAACC,OAAO,CAAC;EACpD;EAEA,IAAIV,aAAa,EAAE;IACjB,MAAMC,OAAO,GAAGC,kBAAkB,CAACF,aAAa,CAAC;IACjD,MAAMG,MAAM,GAAGtB,qBAAqB,CAACuB,SAAS,CAAC;MAC7ClB,oBAAoB,EAAEe;IACxB,CAAC,CAAC;IAEF,IAAIE,MAAM,CAACE,OAAO,EAAE;MAClB,OAAOF,MAAM,CAACG,IAAI;IACpB;IAEAjC,MAAM,CAACkC,GAAG,CACRjC,QAAQ,CAACkC,KAAK,EACb,kDAAiDL,MAAM,CAACM,KAAK,CAACC,OAAQ,EACzE,CAAC;IACD,MAAM,IAAIlC,kBAAkB,CAAC2B,MAAM,CAACM,KAAK,CAACC,OAAO,CAAC;EACpD;EAEArC,MAAM,CAACkC,GAAG,CAACjC,QAAQ,CAACkC,KAAK,EAAG,mCAAkC,CAAC;EAC/D,MAAM,IAAIhC,kBAAkB,CAAC,uCAAuC,CAAC;AACvE,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { IssuerResponseError } from "../../utils/errors";
|
|
2
|
+
import { Logger, LogLevel } from "../../utils/logging";
|
|
3
|
+
import { hasStatusOrThrow } from "../../utils/misc";
|
|
4
|
+
import { InvalidCredentialOfferError } from "./errors";
|
|
5
|
+
import { CredentialOfferSchema } from "./types";
|
|
6
|
+
/**
|
|
7
|
+
* Fetches and validates a credential offer from a given URI.
|
|
8
|
+
*
|
|
9
|
+
* This function performs an HTTP GET request to the specified `credentialOfferUri`,
|
|
10
|
+
* expecting a JSON response that matches the `CredentialOfferSchema`. If the response
|
|
11
|
+
* is invalid or does not conform to the schema, an error is logged and an
|
|
12
|
+
* `InvalidCredentialOfferError` is thrown.
|
|
13
|
+
*
|
|
14
|
+
* @param credentialOfferUri - The URI from which to fetch the credential offer.
|
|
15
|
+
* @param context - Optional context object that may provide a custom `appFetch` implementation.
|
|
16
|
+
* @returns The validated credential offer data.
|
|
17
|
+
* @throws {IssuerResponseError} If the HTTP response status is not 200.
|
|
18
|
+
* @throws {InvalidCredentialOfferError} If the response does not match the expected schema.
|
|
19
|
+
*/
|
|
20
|
+
export const fetchCredentialOffer = async function (uri) {
|
|
21
|
+
let context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
22
|
+
const {
|
|
23
|
+
appFetch = fetch
|
|
24
|
+
} = context;
|
|
25
|
+
const response = await appFetch(uri, {
|
|
26
|
+
method: "GET",
|
|
27
|
+
headers: {
|
|
28
|
+
Accept: "application/json"
|
|
29
|
+
}
|
|
30
|
+
}).then(hasStatusOrThrow(200, IssuerResponseError)).then(reqUri => reqUri.json());
|
|
31
|
+
const credentialOffer = CredentialOfferSchema.safeParse(response);
|
|
32
|
+
if (!credentialOffer.success) {
|
|
33
|
+
Logger.log(LogLevel.ERROR, `Invalid credential offer fetched from URI: ${uri} - ${credentialOffer.error.message}`);
|
|
34
|
+
throw new InvalidCredentialOfferError(`Invalid credential offer fetched from URI: ${uri} - ${credentialOffer.error.message}`);
|
|
35
|
+
}
|
|
36
|
+
return credentialOffer.data;
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=02-fetch-credential-offer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["IssuerResponseError","Logger","LogLevel","hasStatusOrThrow","InvalidCredentialOfferError","CredentialOfferSchema","fetchCredentialOffer","uri","context","arguments","length","undefined","appFetch","fetch","response","method","headers","Accept","then","reqUri","json","credentialOffer","safeParse","success","log","ERROR","error","message","data"],"sourceRoot":"../../../../src","sources":["credential/offer/02-fetch-credential-offer.ts"],"mappings":"AAAA,SAASA,mBAAmB,QAAQ,oBAAoB;AACxD,SAASC,MAAM,EAAEC,QAAQ,QAAQ,qBAAqB;AACtD,SAASC,gBAAgB,QAAQ,kBAAkB;AACnD,SAASC,2BAA2B,QAAQ,UAAU;AAEtD,SAASC,qBAAqB,QAAQ,SAAS;AAS/C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,oBAAwC,GAAG,eAAAA,CACtDC,GAAW,EAER;EAAA,IADHC,OAAO,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAEZ,MAAM;IAAEG,QAAQ,GAAGC;EAAM,CAAC,GAAGL,OAAO;EAEpC,MAAMM,QAAQ,GAAG,MAAMF,QAAQ,CAACL,GAAG,EAAE;IACnCQ,MAAM,EAAE,KAAK;IACbC,OAAO,EAAE;MAAEC,MAAM,EAAE;IAAmB;EACxC,CAAC,CAAC,CACCC,IAAI,CAACf,gBAAgB,CAAC,GAAG,EAAEH,mBAAmB,CAAC,CAAC,CAChDkB,IAAI,CAAEC,MAAM,IAAKA,MAAM,CAACC,IAAI,CAAC,CAAC,CAAC;EAElC,MAAMC,eAAe,GAAGhB,qBAAqB,CAACiB,SAAS,CAACR,QAAQ,CAAC;EACjE,IAAI,CAACO,eAAe,CAACE,OAAO,EAAE;IAC5BtB,MAAM,CAACuB,GAAG,CACRtB,QAAQ,CAACuB,KAAK,EACb,8CAA6ClB,GAAI,MAAKc,eAAe,CAACK,KAAK,CAACC,OAAQ,EACvF,CAAC;IACD,MAAM,IAAIvB,2BAA2B,CAClC,8CAA6CG,GAAI,MAAKc,eAAe,CAACK,KAAK,CAACC,OAAQ,EACvF,CAAC;EACH;EAEA,OAAON,eAAe,CAACO,IAAI;AAC7B,CAAC"}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# Credential Offer
|
|
2
|
+
|
|
3
|
+
This flow handles the initial step of credential issuance by processing Credential Offers from Credential Issuers. The Credential Offer contains information about what credentials are available and how they can be obtained. Each step in the flow is imported from the related file which is named with a sequential number.
|
|
4
|
+
|
|
5
|
+
A Credential Offer can be received by the Wallet in two ways: **by value** (complete offer embedded in the URL) or **by reference** (URL pointing to the offer endpoint). The offer specifies which credentials are available and what authorization flows are supported by the issuer.
|
|
6
|
+
|
|
7
|
+
The implementation follows the [OpenID for Verifiable Credential Issuance 1.0](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html#name-credential-offer-endpoint) specification and supports both Authorization Code flow and Pre-Authorized Code flow.
|
|
8
|
+
|
|
9
|
+
## Sequence Diagram
|
|
10
|
+
|
|
11
|
+
```mermaid
|
|
12
|
+
sequenceDiagram
|
|
13
|
+
autonumber
|
|
14
|
+
participant U as User
|
|
15
|
+
participant W as Wallet
|
|
16
|
+
participant CI as Credential Issuer
|
|
17
|
+
|
|
18
|
+
CI->>U: QR Code / Deep Link with Credential Offer
|
|
19
|
+
U->>W: Scan QR / Click Link
|
|
20
|
+
W->>W: startFlowFromQR: Parse offer parameters
|
|
21
|
+
alt Credential Offer by Reference
|
|
22
|
+
W->>CI: fetchCredentialOffer: Fetch offer from URI
|
|
23
|
+
CI->>W: Return Credential Offer JSON
|
|
24
|
+
end
|
|
25
|
+
W->>W: Validate Credential Offer schema
|
|
26
|
+
W->>W: Determine available grant types
|
|
27
|
+
Note over W: Flow continues with credential issuance
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Grant Types
|
|
31
|
+
|
|
32
|
+
The Credential Offer supports two OAuth 2.0 grant types that determine how authorization is handled:
|
|
33
|
+
|
|
34
|
+
### Authorization Code Flow
|
|
35
|
+
|
|
36
|
+
Used for interactive flows where user authentication and consent are required at the Authorization Server.
|
|
37
|
+
|
|
38
|
+
- **`issuer_state`** (optional): Binds the authorization request to a specific issuer context
|
|
39
|
+
- **`authorization_server`** (optional): Identifies which authorization server to use when multiple are available
|
|
40
|
+
|
|
41
|
+
### Pre-Authorized Code Flow
|
|
42
|
+
|
|
43
|
+
Used when the user has already been authenticated and authorized out-of-band. The issuer provides a pre-authorized code that can be exchanged directly for credentials.
|
|
44
|
+
|
|
45
|
+
- **`pre-authorized_code`**: Short-lived single-use authorization code
|
|
46
|
+
- **`tx_code`** (optional): Additional transaction code requirements for security
|
|
47
|
+
- **`authorization_server`** (optional): Identifies which authorization server to use
|
|
48
|
+
|
|
49
|
+
## Transaction Code Requirements
|
|
50
|
+
|
|
51
|
+
When a transaction code is required for Pre-Authorized Code flow, the following parameters control the user experience:
|
|
52
|
+
|
|
53
|
+
| Parameter | Type | Description |
|
|
54
|
+
| ------------- | ----------------------- | ---------------------------------------------------- |
|
|
55
|
+
| `input_mode` | `"numeric"` \| `"text"` | Character set for the code (default: `"numeric"`) |
|
|
56
|
+
| `length` | number | Expected code length to optimize input UI |
|
|
57
|
+
| `description` | string | User guidance (max 300 chars) for obtaining the code |
|
|
58
|
+
|
|
59
|
+
## Credential Offer Transmission
|
|
60
|
+
|
|
61
|
+
### By Value
|
|
62
|
+
|
|
63
|
+
The complete Credential Offer is embedded in the URL parameter:
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
openid-credential-offer://?credential_offer=%7B%22credential_issuer%22...
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### By Reference
|
|
70
|
+
|
|
71
|
+
A URL points to an endpoint serving the Credential Offer:
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
openid-credential-offer://?credential_offer_uri=https%3A%2F%2Fserver.example.com%2Foffer
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
When using by reference, the Wallet fetches the offer via HTTP GET with `Accept: application/json`.
|
|
78
|
+
|
|
79
|
+
## Mapped Results
|
|
80
|
+
|
|
81
|
+
The following errors are mapped during credential offer processing:
|
|
82
|
+
|
|
83
|
+
| Error | Description |
|
|
84
|
+
| ----------------------------- | ---------------------------------------------------------------------------------- |
|
|
85
|
+
| `InvalidQRCodeError` | The QR code format is invalid or doesn't contain valid credential offer parameters |
|
|
86
|
+
| `InvalidCredentialOfferError` | The credential offer schema validation failed or contains invalid data |
|
|
87
|
+
|
|
88
|
+
## Examples
|
|
89
|
+
|
|
90
|
+
<details>
|
|
91
|
+
<summary>Credential Offer processing flow</summary>
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
// Parse QR code or deep link
|
|
95
|
+
const qrCode =
|
|
96
|
+
"openid-credential-offer://?credential_offer_uri=https%3A%2F%2Fissuer.example.com%2Foffer";
|
|
97
|
+
const { credential_offer_uri } = startFlowFromQR(qrCode);
|
|
98
|
+
|
|
99
|
+
// Fetch the credential offer if by reference
|
|
100
|
+
const offer = await fetchCredentialOffer(credential_offer_uri, { appFetch });
|
|
101
|
+
|
|
102
|
+
console.log(offer);
|
|
103
|
+
// {
|
|
104
|
+
// credential_issuer: "https://issuer.example.com",
|
|
105
|
+
// credential_configuration_ids: ["UniversityDegree", "DriverLicense"],
|
|
106
|
+
// grants: {
|
|
107
|
+
// authorization_code: {
|
|
108
|
+
// issuer_state: "xyz123"
|
|
109
|
+
// },
|
|
110
|
+
// "urn:ietf:params:oauth:grant-type:pre-authorized_code": {
|
|
111
|
+
// "pre-authorized_code": "SplxlOBeZQQYbYS6WxSbIA",
|
|
112
|
+
// tx_code: {
|
|
113
|
+
// length: 6,
|
|
114
|
+
// input_mode: "numeric",
|
|
115
|
+
// description: "Enter the code sent to your email"
|
|
116
|
+
// }
|
|
117
|
+
// }
|
|
118
|
+
// }
|
|
119
|
+
// }
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
</details>
|
|
123
|
+
|
|
124
|
+
<details>
|
|
125
|
+
<summary>Pre-Authorized Code with Transaction Code</summary>
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
const offer: CredentialOffer = {
|
|
129
|
+
credential_issuer: "https://university.example.edu",
|
|
130
|
+
credential_configuration_ids: ["DiplomaCredential"],
|
|
131
|
+
grants: {
|
|
132
|
+
"urn:ietf:params:oauth:grant-type:pre-authorized_code": {
|
|
133
|
+
"pre-authorized_code": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9",
|
|
134
|
+
tx_code: {
|
|
135
|
+
length: 4,
|
|
136
|
+
input_mode: "numeric",
|
|
137
|
+
description: "Check your email for the verification code",
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
// The user would need to:
|
|
144
|
+
// 1. Check their email for a 4-digit numeric code
|
|
145
|
+
// 2. Enter it in the wallet when prompted
|
|
146
|
+
// 3. The wallet uses both pre-authorized_code and tx_code in the token request
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
</details>
|
|
150
|
+
|
|
151
|
+
<details>
|
|
152
|
+
<summary>Authorization Code Flow</summary>
|
|
153
|
+
|
|
154
|
+
```ts
|
|
155
|
+
const offer: CredentialOffer = {
|
|
156
|
+
credential_issuer: "https://dmv.example.gov",
|
|
157
|
+
credential_configuration_ids: ["org.iso.18013.5.1.mDL"],
|
|
158
|
+
grants: {
|
|
159
|
+
authorization_code: {
|
|
160
|
+
issuer_state: "af0ifjsldkj",
|
|
161
|
+
authorization_server: "https://auth.dmv.example.gov",
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
// This would lead to:
|
|
167
|
+
// 1. User authentication at the authorization server
|
|
168
|
+
// 2. User consent for credential issuance
|
|
169
|
+
// 3. Authorization code returned to wallet
|
|
170
|
+
// 4. Wallet exchanges code for access token
|
|
171
|
+
// 5. Wallet uses access token to request credential
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
</details>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { IoWalletError } from "../../utils/errors";
|
|
2
|
+
export class InvalidCredentialOfferError extends IoWalletError {
|
|
3
|
+
code = "ERR_INVALID_CREDENTIAL_OFFER";
|
|
4
|
+
constructor(message) {
|
|
5
|
+
super(message);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export class InvalidQRCodeError extends IoWalletError {
|
|
9
|
+
code = "ERR_INVALID_QR_CODE";
|
|
10
|
+
constructor(message) {
|
|
11
|
+
super(message);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["IoWalletError","InvalidCredentialOfferError","code","constructor","message","InvalidQRCodeError"],"sourceRoot":"../../../../src","sources":["credential/offer/errors.ts"],"mappings":"AAAA,SAASA,aAAa,QAAQ,oBAAoB;AAElD,OAAO,MAAMC,2BAA2B,SAASD,aAAa,CAAC;EAC7DE,IAAI,GAAG,8BAA8B;EAErCC,WAAWA,CAACC,OAAgB,EAAE;IAC5B,KAAK,CAACA,OAAO,CAAC;EAChB;AACF;AAEA,OAAO,MAAMC,kBAAkB,SAASL,aAAa,CAAC;EACpDE,IAAI,GAAG,qBAAqB;EAE5BC,WAAWA,CAACC,OAAgB,EAAE;IAC5B,KAAK,CAACA,OAAO,CAAC;EAChB;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["startFlowFromQR","fetchCredentialOffer","Errors"],"sourceRoot":"../../../../src","sources":["credential/offer/index.ts"],"mappings":"AAAA,SAASA,eAAe,QAAwB,iBAAiB;AACjE,SACEC,oBAAoB,QAEf,6BAA6B;AACpC,OAAO,KAAKC,MAAM,MAAM,UAAU;AASlC,SAASA,MAAM,EAAED,oBAAoB,EAAED,eAAe"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* OAuth 2.0 Authorization Code flow parameters.
|
|
5
|
+
*/
|
|
6
|
+
export const AuthorizationCodeGrantSchema = z.object({
|
|
7
|
+
issuer_state: z.string().optional(),
|
|
8
|
+
authorization_server: z.string().url().optional()
|
|
9
|
+
});
|
|
10
|
+
/**
|
|
11
|
+
* Transaction Code requirements for Pre-Authorized Code flow.
|
|
12
|
+
*/
|
|
13
|
+
export const TransactionCodeSchema = z.object({
|
|
14
|
+
input_mode: z.enum(["numeric", "text"]).optional(),
|
|
15
|
+
length: z.number().int().positive().optional(),
|
|
16
|
+
description: z.string().max(300).optional()
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* Pre-Authorized Code flow parameters.
|
|
20
|
+
*/
|
|
21
|
+
export const PreAuthorizedCodeGrantSchema = z.object({
|
|
22
|
+
"pre-authorized_code": z.string(),
|
|
23
|
+
tx_code: TransactionCodeSchema.optional(),
|
|
24
|
+
authorization_server: z.string().url().optional()
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* Supported grant types for Credential Offer.
|
|
28
|
+
*/
|
|
29
|
+
export const GrantsSchema = z.object({
|
|
30
|
+
authorization_code: AuthorizationCodeGrantSchema.optional(),
|
|
31
|
+
"urn:ietf:params:oauth:grant-type:pre-authorized_code": PreAuthorizedCodeGrantSchema.optional()
|
|
32
|
+
});
|
|
33
|
+
/**
|
|
34
|
+
* Credential Offer object as defined in OpenID4VCI Section 4.1.1.
|
|
35
|
+
*/
|
|
36
|
+
export const CredentialOfferSchema = z.object({
|
|
37
|
+
credential_issuer: z.string().url(),
|
|
38
|
+
credential_configuration_ids: z.array(z.string()).min(1),
|
|
39
|
+
grants: GrantsSchema.optional()
|
|
40
|
+
});
|
|
41
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["z","AuthorizationCodeGrantSchema","object","issuer_state","string","optional","authorization_server","url","TransactionCodeSchema","input_mode","enum","length","number","int","positive","description","max","PreAuthorizedCodeGrantSchema","tx_code","GrantsSchema","authorization_code","CredentialOfferSchema","credential_issuer","credential_configuration_ids","array","min","grants"],"sourceRoot":"../../../../src","sources":["credential/offer/types.ts"],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AACA;AACA;AACA,OAAO,MAAMgB,qBAAqB,GAAGrB,CAAC,CAACE,MAAM,CAAC;EAC5CoB,iBAAiB,EAAEtB,CAAC,CAACI,MAAM,CAAC,CAAC,CAACG,GAAG,CAAC,CAAC;EACnCgB,4BAA4B,EAAEvB,CAAC,CAACwB,KAAK,CAACxB,CAAC,CAACI,MAAM,CAAC,CAAC,CAAC,CAACqB,GAAG,CAAC,CAAC,CAAC;EACxDC,MAAM,EAAEP,YAAY,CAACd,QAAQ,CAAC;AAChC,CAAC,CAAC"}
|
|
@@ -9,7 +9,7 @@ const PresentationParams = z.object({
|
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* The beginning of the presentation flow.
|
|
12
|
-
* To be implemented
|
|
12
|
+
* To be implemented according to the user touchpoint
|
|
13
13
|
*
|
|
14
14
|
* @param params Presentation parameters, depending on the starting touchpoint
|
|
15
15
|
* @returns The url for the Relying Party to connect with
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Digital Credentials Catalogue
|
|
2
|
+
|
|
3
|
+
Module that manages the [**Digital Credentials Catalogue**](https://italia.github.io/eid-wallet-it-docs/releases/1.1.0/en/registry-catalogue.html) published by the Trust Anchor.
|
|
4
|
+
|
|
5
|
+
The module allows:
|
|
6
|
+
- Fetching, verifying and parsing the catalogue's JWT.
|
|
7
|
+
|
|
8
|
+
## Usage
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
// Fetch the catalogue
|
|
12
|
+
const TRUST_ANCHOR_BASE_URL = "https://pre.ta.wallet.ipzs.it";
|
|
13
|
+
const credentialsCatalogue =
|
|
14
|
+
await CredentialsCatalogue.fetchAndParseCatalogue(TRUST_ANCHOR_BASE_URL);
|
|
15
|
+
```
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { decode as decodeJwt, verify } from "@pagopa/io-react-native-jwt";
|
|
2
|
+
import { hasStatusOrThrow } from "../utils/misc";
|
|
3
|
+
import { IoWalletError } from "../utils/errors";
|
|
4
|
+
import { DigitalCredentialsCatalogue } from "./types";
|
|
5
|
+
import { getTrustAnchorEntityConfiguration } from "../trust/build-chain";
|
|
6
|
+
/**
|
|
7
|
+
* Fetch and parse the Digital Credential Catalogue from the Trust Anchor.
|
|
8
|
+
* The catalogue's JWT signature is verified against the Trust Anchor's JWKs.
|
|
9
|
+
*
|
|
10
|
+
* @param trustAnchorUrl Base URL of the Trust Anchor
|
|
11
|
+
* @param context.appFetch (optional) fetch API implementation. Default: built-in fetch
|
|
12
|
+
* @returns The Digital Credential Catalogue payload
|
|
13
|
+
*/
|
|
14
|
+
export const fetchAndParseCatalogue = async function (trustAnchorBaseUrl) {
|
|
15
|
+
let {
|
|
16
|
+
appFetch = fetch
|
|
17
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
18
|
+
const trustAnchorConfig = await getTrustAnchorEntityConfiguration(trustAnchorBaseUrl);
|
|
19
|
+
const responseText = await appFetch(`${trustAnchorConfig.payload.sub}/.well-known/credential-catalogue`, {
|
|
20
|
+
method: "GET"
|
|
21
|
+
}).then(hasStatusOrThrow(200)).then(res => res.text());
|
|
22
|
+
const responseJwt = decodeJwt(responseText);
|
|
23
|
+
const catalogueKid = responseJwt.protectedHeader.kid;
|
|
24
|
+
const trustAnchorJwk = trustAnchorConfig.payload.jwks.keys.find(jwk => jwk.kid === catalogueKid);
|
|
25
|
+
if (!trustAnchorJwk) {
|
|
26
|
+
throw new IoWalletError(`Could not find JWK with kid ${catalogueKid} in Trust Anchor's Entity Configuration`);
|
|
27
|
+
}
|
|
28
|
+
await verify(responseText, trustAnchorJwk);
|
|
29
|
+
const parsedDigitalCredentialsCatalogue = DigitalCredentialsCatalogue.parse({
|
|
30
|
+
header: responseJwt.protectedHeader,
|
|
31
|
+
payload: responseJwt.payload
|
|
32
|
+
});
|
|
33
|
+
return parsedDigitalCredentialsCatalogue.payload;
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=fetch-and-parse-catalogue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["decode","decodeJwt","verify","hasStatusOrThrow","IoWalletError","DigitalCredentialsCatalogue","getTrustAnchorEntityConfiguration","fetchAndParseCatalogue","trustAnchorBaseUrl","appFetch","fetch","arguments","length","undefined","trustAnchorConfig","responseText","payload","sub","method","then","res","text","responseJwt","catalogueKid","protectedHeader","kid","trustAnchorJwk","jwks","keys","find","jwk","parsedDigitalCredentialsCatalogue","parse","header"],"sourceRoot":"../../../src","sources":["credentials-catalogue/fetch-and-parse-catalogue.ts"],"mappings":"AAAA,SAASA,MAAM,IAAIC,SAAS,EAAEC,MAAM,QAAQ,6BAA6B;AACzE,SAASC,gBAAgB,QAAQ,eAAe;AAChD,SAASC,aAAa,QAAQ,iBAAiB;AAC/C,SAASC,2BAA2B,QAAQ,SAAS;AACrD,SAASC,iCAAiC,QAAQ,sBAAsB;AAMxE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,sBAAsB,GAAG,eAAAA,CACpCC,kBAA0B,EAE0B;EAAA,IADpD;IAAEC,QAAQ,GAAGC;EAA2B,CAAC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAE9C,MAAMG,iBAAiB,GACrB,MAAMR,iCAAiC,CAACE,kBAAkB,CAAC;EAE7D,MAAMO,YAAY,GAAG,MAAMN,QAAQ,CAChC,GAAEK,iBAAiB,CAACE,OAAO,CAACC,GAAI,mCAAkC,EACnE;IAAEC,MAAM,EAAE;EAAM,CAClB,CAAC,CACEC,IAAI,CAAChB,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAC3BgB,IAAI,CAAEC,GAAG,IAAKA,GAAG,CAACC,IAAI,CAAC,CAAC,CAAC;EAE5B,MAAMC,WAAW,GAAGrB,SAAS,CAACc,YAAY,CAAC;EAC3C,MAAMQ,YAAY,GAAGD,WAAW,CAACE,eAAe,CAACC,GAAG;EAEpD,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