@pagopa/io-react-native-wallet 0.10.2 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/commonjs/credential/issuance/06-obtain-credential.js +19 -5
- package/lib/commonjs/credential/issuance/06-obtain-credential.js.map +1 -1
- package/lib/commonjs/credential/issuance/07-verify-and-parse-credential.js +7 -1
- package/lib/commonjs/credential/issuance/07-verify-and-parse-credential.js.map +1 -1
- package/lib/commonjs/credential/issuance/const.js +1 -1
- package/lib/commonjs/credential/issuance/const.js.map +1 -1
- package/lib/module/credential/issuance/06-obtain-credential.js +19 -5
- package/lib/module/credential/issuance/06-obtain-credential.js.map +1 -1
- package/lib/module/credential/issuance/07-verify-and-parse-credential.js +7 -1
- package/lib/module/credential/issuance/07-verify-and-parse-credential.js.map +1 -1
- package/lib/module/credential/issuance/const.js +1 -1
- package/lib/module/credential/issuance/const.js.map +1 -1
- package/lib/typescript/credential/issuance/06-obtain-credential.d.ts +3 -1
- package/lib/typescript/credential/issuance/06-obtain-credential.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/07-verify-and-parse-credential.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/const.d.ts +1 -1
- package/lib/typescript/credential/issuance/const.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/credential/issuance/06-obtain-credential.ts +34 -4
- package/src/credential/issuance/07-verify-and-parse-credential.ts +21 -2
- package/src/credential/issuance/const.ts +4 -1
@@ -27,8 +27,16 @@ const createNonceProof = async (nonce, issuer, audience, ctx) => {
|
|
27
27
|
exports.createNonceProof = createNonceProof;
|
28
28
|
const CredentialEndpointResponse = z.object({
|
29
29
|
credential: z.string(),
|
30
|
-
format: _const.SupportedCredentialFormat
|
30
|
+
format: _const.SupportedCredentialFormat,
|
31
|
+
// nonce used to perform multiple credential requests
|
32
|
+
// re-using the same authorization profile
|
33
|
+
c_nonce: z.string(),
|
34
|
+
c_nonce_expires_in: z.number()
|
31
35
|
});
|
36
|
+
// Checks whether in the Entity confoguration at least one credential
|
37
|
+
// is defined for the given type and format
|
38
|
+
const isCredentialAvailable = (issuerConf, credentialType, credentialFormat) => issuerConf.openid_credential_issuer.credentials_supported.some(c => c.format === credentialFormat && c.credential_definition.type.includes(credentialType));
|
39
|
+
|
32
40
|
/**
|
33
41
|
* Fetch a credential from the issuer
|
34
42
|
*
|
@@ -37,17 +45,21 @@ const CredentialEndpointResponse = z.object({
|
|
37
45
|
* @param nonce The nonce value to prevent reply attacks, obtained with the access authorization step
|
38
46
|
* @param clientId Identifies the current client across all the requests of the issuing flow
|
39
47
|
* @param credentialType The type of the credential to be requested
|
48
|
+
* @param credentialFormat The format of the requested credential. @see {SupportedCredentialFormat}
|
40
49
|
* @param context.credentialCryptoContext The context to access the key the Credential will be bound to
|
41
50
|
* @param context.walletProviderBaseUrl The base url of the Wallet Provider
|
42
51
|
* @param context.appFetch (optional) fetch api implementation. Default: built-in fetch
|
43
52
|
* @returns The signed credential token
|
44
53
|
*/
|
45
|
-
const obtainCredential = async (issuerConf, accessToken, nonce, clientId, credentialType, context) => {
|
54
|
+
const obtainCredential = async (issuerConf, accessToken, nonce, clientId, credentialType, credentialFormat, context) => {
|
46
55
|
const {
|
47
56
|
credentialCryptoContext,
|
48
57
|
walletProviderBaseUrl,
|
49
58
|
appFetch = fetch
|
50
59
|
} = context;
|
60
|
+
if (!isCredentialAvailable(issuerConf, credentialType, credentialFormat)) {
|
61
|
+
throw new Error(`The Issuer provides no credential for type ${credentialType} and format ${credentialFormat}`);
|
62
|
+
}
|
51
63
|
const credentialUrl = issuerConf.openid_credential_issuer.credential_endpoint;
|
52
64
|
|
53
65
|
/** DPoP token for demonstating the possession
|
@@ -69,7 +81,7 @@ const obtainCredential = async (issuerConf, accessToken, nonce, clientId, creden
|
|
69
81
|
credential_definition: JSON.stringify({
|
70
82
|
type: [credentialType]
|
71
83
|
}),
|
72
|
-
format:
|
84
|
+
format: credentialFormat,
|
73
85
|
proof: JSON.stringify({
|
74
86
|
jwt: signedNonceProof,
|
75
87
|
proof_type: "jwt"
|
@@ -77,7 +89,8 @@ const obtainCredential = async (issuerConf, accessToken, nonce, clientId, creden
|
|
77
89
|
});
|
78
90
|
const {
|
79
91
|
credential,
|
80
|
-
format
|
92
|
+
format,
|
93
|
+
c_nonce
|
81
94
|
} = await appFetch(credentialUrl, {
|
82
95
|
method: "POST",
|
83
96
|
headers: {
|
@@ -89,7 +102,8 @@ const obtainCredential = async (issuerConf, accessToken, nonce, clientId, creden
|
|
89
102
|
}).then((0, _misc.hasStatus)(200)).then(res => res.json()).then(CredentialEndpointResponse.parse);
|
90
103
|
return {
|
91
104
|
credential,
|
92
|
-
format
|
105
|
+
format,
|
106
|
+
nonce: c_nonce
|
93
107
|
};
|
94
108
|
};
|
95
109
|
exports.obtainCredential = obtainCredential;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["z","_interopRequireWildcard","require","_reactNativeUuid","_interopRequireDefault","_ioReactNativeJwt","_dpop","_misc","_const","obj","__esModule","default","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","createNonceProof","nonce","issuer","audience","ctx","SignJWT","setPayload","jwk","getPublicKey","setProtectedHeader","type","setAudience","setIssuer","setIssuedAt","setExpirationTime","sign","exports","CredentialEndpointResponse","object","credential","string","format","SupportedCredentialFormat","
|
1
|
+
{"version":3,"names":["z","_interopRequireWildcard","require","_reactNativeUuid","_interopRequireDefault","_ioReactNativeJwt","_dpop","_misc","_const","obj","__esModule","default","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","createNonceProof","nonce","issuer","audience","ctx","SignJWT","setPayload","jwk","getPublicKey","setProtectedHeader","type","setAudience","setIssuer","setIssuedAt","setExpirationTime","sign","exports","CredentialEndpointResponse","object","credential","string","format","SupportedCredentialFormat","c_nonce","c_nonce_expires_in","number","isCredentialAvailable","issuerConf","credentialType","credentialFormat","openid_credential_issuer","credentials_supported","some","c","credential_definition","includes","obtainCredential","accessToken","clientId","context","credentialCryptoContext","walletProviderBaseUrl","appFetch","fetch","Error","credentialUrl","credential_endpoint","signedDPopForPid","createDPopToken","htm","htu","jti","uuid","v4","signedNonceProof","formBody","URLSearchParams","JSON","stringify","proof","jwt","proof_type","method","headers","DPoP","Authorization","body","toString","then","hasStatus","res","json","parse"],"sourceRoot":"../../../../src","sources":["credential/issuance/06-obtain-credential.ts"],"mappings":";;;;;;AAAA,IAAAA,CAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,iBAAA,GAAAH,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AAGA,IAAAK,KAAA,GAAAL,OAAA;AAGA,IAAAM,MAAA,GAAAN,OAAA;AAAoD,SAAAE,uBAAAK,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,SAAAG,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,SAAAZ,wBAAAQ,GAAA,EAAAI,WAAA,SAAAA,WAAA,IAAAJ,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAQ,KAAA,GAAAL,wBAAA,CAAAC,WAAA,OAAAI,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAT,GAAA,YAAAQ,KAAA,CAAAE,GAAA,CAAAV,GAAA,SAAAW,M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G,qBAAqB,EACrBD,uBACF,CAAC;;EAED;EACA,MAAMe,QAAQ,GAAG,IAAIC,eAAe,CAAC;IACnCtB,qBAAqB,EAAEuB,IAAI,CAACC,SAAS,CAAC;MACpChD,IAAI,EAAE,CAACkB,cAAc;IACvB,CAAC,CAAC;IACFP,MAAM,EAAEQ,gBAAgB;IACxB8B,KAAK,EAAEF,IAAI,CAACC,SAAS,CAAC;MACpBE,GAAG,EAAEN,gBAAgB;MACrBO,UAAU,EAAE;IACd,CAAC;EACH,CAAC,CAAC;EAEF,MAAM;IAAE1C,UAAU;IAAEE,MAAM;IAAEE;EAAQ,CAAC,GAAG,MAAMmB,QAAQ,CAACG,aAAa,EAAE;IACpEiB,MAAM,EAAE,MAAM;IACdC,OAAO,EAAE;MACP,cAAc,EAAE,mCAAmC;MACnDC,IAAI,EAAEjB,gBAAgB;MACtBkB,aAAa,EAAE5B;IACjB,CAAC;IACD6B,IAAI,EAAEX,QAAQ,CAACY,QAAQ,CAAC;EAC1B,CAAC,CAAC,CACCC,IAAI,CAAC,IAAAC,eAAS,EAAC,GAAG,CAAC,CAAC,CACpBD,IAAI,CAAEE,GAAG,IAAKA,GAAG,CAACC,IAAI,CAAC,CAAC,CAAC,CACzBH,IAAI,CAACnD,0BAA0B,CAACuD,KAAK,CAAC;EAEzC,OAAO;IAAErD,UAAU;IAAEE,MAAM;IAAEpB,KAAK,EAAEsB;EAAQ,CAAC;AAC/C,CAAC;AAACP,OAAA,CAAAoB,gBAAA,GAAAA,gBAAA"}
|
@@ -20,7 +20,7 @@ const parseCredentialSdJwt = function (credentials_supported, _ref) {
|
|
20
20
|
let ignoreMissingAttributes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
21
21
|
// find the definition that matches the received credential's type
|
22
22
|
// warning: if more then a defintion is found, the first is retrieved
|
23
|
-
const credentialSubject = (_credentials_supporte = credentials_supported.find(c => c.credential_definition.type.includes(sdJwt.payload.type))) === null || _credentials_supporte === void 0 ? void 0 : _credentials_supporte.credential_definition.credentialSubject;
|
23
|
+
const credentialSubject = (_credentials_supporte = credentials_supported.find(c => c.format === "vc+sd-jwt" && c.credential_definition.type.includes(sdJwt.payload.type))) === null || _credentials_supporte === void 0 ? void 0 : _credentials_supporte.credential_definition.credentialSubject;
|
24
24
|
|
25
25
|
// the received credential matches no supported credential, throw an exception
|
26
26
|
if (!credentialSubject) {
|
@@ -144,6 +144,10 @@ const verifyAndParseCredentialSdJwt = async (issuerConf, credential, _, _ref8) =
|
|
144
144
|
parsedCredential
|
145
145
|
};
|
146
146
|
};
|
147
|
+
const verifyAndParseCredentialMdoc = async (_issuerConf, _credential, _, _ctx) => {
|
148
|
+
// TODO: [SIW-686] decode MDOC credentials
|
149
|
+
throw new Error("verifyAndParseCredentialMdoc not implemented yet");
|
150
|
+
};
|
147
151
|
|
148
152
|
/**
|
149
153
|
* Verify and parse an encoded credential
|
@@ -161,6 +165,8 @@ const verifyAndParseCredentialSdJwt = async (issuerConf, credential, _, _ref8) =
|
|
161
165
|
const verifyAndParseCredential = async (issuerConf, credential, format, context) => {
|
162
166
|
if (format === "vc+sd-jwt") {
|
163
167
|
return verifyAndParseCredentialSdJwt(issuerConf, credential, format, context);
|
168
|
+
} else if (format === "vc+mdoc-cbor") {
|
169
|
+
return verifyAndParseCredentialMdoc(issuerConf, credential, format, context);
|
164
170
|
}
|
165
171
|
const _ = format;
|
166
172
|
throw new _errors.IoWalletError(`Unsupported credential format: ${_}`);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_errors","require","_types","_sdJwt","parseCredentialSdJwt","credentials_supported","_ref","_credentials_supporte","sdJwt","disclosures","ignoreMissingAttributes","arguments","length","undefined","credentialSubject","find","c","credential_definition","type","includes","payload","expected","flatMap","_","join","IoWalletError","attrDefinitions","Object","entries","attrsNotInDisclosures","filter","_ref2","attrKey","mandatory","some","_ref3","name","missing","map","received","definedValues","_ref4","_disclosures$find","definition","value","_ref5","display","reduce","names","_ref6","locale","undefinedValues","keys","_ref7","key","fromEntries","verifyCredentialSdJwt","rawCredential","issuerKeys","holderBindingContext","decodedCredential","holderBindingKey","Promise","all","verifySdJwt","SdJwt4VC","getPublicKey","cnf","jwk","kid","verifyAndParseCredentialSdJwt","issuerConf","credential","_ref8","credentialCryptoContext","decoded","openid_credential_issuer","jwks","parsedCredential","
|
1
|
+
{"version":3,"names":["_errors","require","_types","_sdJwt","parseCredentialSdJwt","credentials_supported","_ref","_credentials_supporte","sdJwt","disclosures","ignoreMissingAttributes","arguments","length","undefined","credentialSubject","find","c","format","credential_definition","type","includes","payload","expected","flatMap","_","join","IoWalletError","attrDefinitions","Object","entries","attrsNotInDisclosures","filter","_ref2","attrKey","mandatory","some","_ref3","name","missing","map","received","definedValues","_ref4","_disclosures$find","definition","value","_ref5","display","reduce","names","_ref6","locale","undefinedValues","keys","_ref7","key","fromEntries","verifyCredentialSdJwt","rawCredential","issuerKeys","holderBindingContext","decodedCredential","holderBindingKey","Promise","all","verifySdJwt","SdJwt4VC","getPublicKey","cnf","jwk","kid","verifyAndParseCredentialSdJwt","issuerConf","credential","_ref8","credentialCryptoContext","decoded","openid_credential_issuer","jwks","parsedCredential","verifyAndParseCredentialMdoc","_issuerConf","_credential","_ctx","Error","verifyAndParseCredential","context","exports"],"sourceRoot":"../../../../src","sources":["credential/issuance/07-verify-and-parse-credential.ts"],"mappings":";;;;;;AAGA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAcA;;AAmBA;;AAKA,MAAMG,oBAAoB,GAAG,SAAAA,CAE3BC,qBAAkH,EAAAC,IAAA,EAG7F;EAAA,IAAAC,qBAAA;EAAA,IAFrB;IAAEC,KAAK;IAAEC;EAAoC,CAAC,GAAAH,IAAA;EAAA,IAC9CI,uBAAgC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,KAAK;EAExC;EACA;EACA,MAAMG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,CACzCgB,UAAU,EACVD,UAAU,CAACK,wBAAwB,CAACC,IAAI,CAACzB,IAAI,EAC7CsB,uBACF,CAAC;EAED,MAAMI,gBAAgB,GAAG3E,oBAAoB,CAC3CoE,UAAU,CAACK,wBAAwB,CAACxE,qBAAqB,EACzDuE,OAAO,EACPlE,uBACF,CAAC;EAED,OAAO;IAAEqE;EAAiB,CAAC;AAC7B,CAAC;AAED,MAAMC,4BAAwD,GAAG,MAAAA,CAC/DC,WAAW,EACXC,WAAW,EACX1D,CAAC,EACD2D,IAAI,KACD;EACH;EACA,MAAM,IAAIC,KAAK,CAAC,kDAAkD,CAAC;AACrE,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,wBAAkD,GAAG,MAAAA,CAChEb,UAAU,EACVC,UAAU,EACVxD,MAAM,EACNqE,OAAO,KACJ;EACH,IAAIrE,MAAM,KAAK,WAAW,EAAE;IAC1B,OAAOsD,6BAA6B,CAClCC,UAAU,EACVC,UAAU,EACVxD,MAAM,EACNqE,OACF,CAAC;EACH,CAAC,MAAM,IAAIrE,MAAM,KAAK,cAAc,EAAE;IACpC,OAAO+D,4BAA4B,CACjCR,UAAU,EACVC,UAAU,EACVxD,MAAM,EACNqE,OACF,CAAC;EACH;EAEA,MAAM9D,CAAQ,GAAGP,MAAM;EACvB,MAAM,IAAIS,qBAAa,CAAE,kCAAiCF,CAAE,EAAC,CAAC;AAChE,CAAC;AAAC+D,OAAA,CAAAF,wBAAA,GAAAA,wBAAA"}
|
@@ -9,6 +9,6 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
9
9
|
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; }
|
10
10
|
const ASSERTION_TYPE = "urn:ietf:params:oauth:client-assertion-type:jwt-client-attestation";
|
11
11
|
exports.ASSERTION_TYPE = ASSERTION_TYPE;
|
12
|
-
const SupportedCredentialFormat = z.literal("vc+sd-jwt");
|
12
|
+
const SupportedCredentialFormat = z.union([z.literal("vc+sd-jwt"), z.literal("vc+mdoc-cbor")]);
|
13
13
|
exports.SupportedCredentialFormat = SupportedCredentialFormat;
|
14
14
|
//# sourceMappingURL=const.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["z","_interopRequireWildcard","require","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","ASSERTION_TYPE","exports","SupportedCredentialFormat","literal"],"sourceRoot":"../../../../src","sources":["credential/issuance/const.ts"],"mappings":";;;;;;AAAA,IAAAA,CAAA,GAAAC,uBAAA,CAAAC,OAAA;AAAyB,SAAAC,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,SAAAH,wBAAAO,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,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;AAClB,MAAMW,cAAc,GACzB,oEAAoE;AAACC,OAAA,CAAAD,cAAA,GAAAA,cAAA;AAKhE,MAAME,yBAAyB,GAAG3B,CAAC,CAAC4B,OAAO,CAAC,WAAW,CAAC;
|
1
|
+
{"version":3,"names":["z","_interopRequireWildcard","require","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","ASSERTION_TYPE","exports","SupportedCredentialFormat","union","literal"],"sourceRoot":"../../../../src","sources":["credential/issuance/const.ts"],"mappings":";;;;;;AAAA,IAAAA,CAAA,GAAAC,uBAAA,CAAAC,OAAA;AAAyB,SAAAC,yBAAA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AAC,WAAW,CAAC,EACtB7B,CAAC,CAAC6B,OAAO,CAAC,cAAc,CAAC,CAC1B,CAAC;AAACH,OAAA,CAAAC,yBAAA,GAAAA,yBAAA"}
|
@@ -18,8 +18,16 @@ export const createNonceProof = async (nonce, issuer, audience, ctx) => {
|
|
18
18
|
};
|
19
19
|
const CredentialEndpointResponse = z.object({
|
20
20
|
credential: z.string(),
|
21
|
-
format: SupportedCredentialFormat
|
21
|
+
format: SupportedCredentialFormat,
|
22
|
+
// nonce used to perform multiple credential requests
|
23
|
+
// re-using the same authorization profile
|
24
|
+
c_nonce: z.string(),
|
25
|
+
c_nonce_expires_in: z.number()
|
22
26
|
});
|
27
|
+
// Checks whether in the Entity confoguration at least one credential
|
28
|
+
// is defined for the given type and format
|
29
|
+
const isCredentialAvailable = (issuerConf, credentialType, credentialFormat) => issuerConf.openid_credential_issuer.credentials_supported.some(c => c.format === credentialFormat && c.credential_definition.type.includes(credentialType));
|
30
|
+
|
23
31
|
/**
|
24
32
|
* Fetch a credential from the issuer
|
25
33
|
*
|
@@ -28,17 +36,21 @@ const CredentialEndpointResponse = z.object({
|
|
28
36
|
* @param nonce The nonce value to prevent reply attacks, obtained with the access authorization step
|
29
37
|
* @param clientId Identifies the current client across all the requests of the issuing flow
|
30
38
|
* @param credentialType The type of the credential to be requested
|
39
|
+
* @param credentialFormat The format of the requested credential. @see {SupportedCredentialFormat}
|
31
40
|
* @param context.credentialCryptoContext The context to access the key the Credential will be bound to
|
32
41
|
* @param context.walletProviderBaseUrl The base url of the Wallet Provider
|
33
42
|
* @param context.appFetch (optional) fetch api implementation. Default: built-in fetch
|
34
43
|
* @returns The signed credential token
|
35
44
|
*/
|
36
|
-
export const obtainCredential = async (issuerConf, accessToken, nonce, clientId, credentialType, context) => {
|
45
|
+
export const obtainCredential = async (issuerConf, accessToken, nonce, clientId, credentialType, credentialFormat, context) => {
|
37
46
|
const {
|
38
47
|
credentialCryptoContext,
|
39
48
|
walletProviderBaseUrl,
|
40
49
|
appFetch = fetch
|
41
50
|
} = context;
|
51
|
+
if (!isCredentialAvailable(issuerConf, credentialType, credentialFormat)) {
|
52
|
+
throw new Error(`The Issuer provides no credential for type ${credentialType} and format ${credentialFormat}`);
|
53
|
+
}
|
42
54
|
const credentialUrl = issuerConf.openid_credential_issuer.credential_endpoint;
|
43
55
|
|
44
56
|
/** DPoP token for demonstating the possession
|
@@ -60,7 +72,7 @@ export const obtainCredential = async (issuerConf, accessToken, nonce, clientId,
|
|
60
72
|
credential_definition: JSON.stringify({
|
61
73
|
type: [credentialType]
|
62
74
|
}),
|
63
|
-
format:
|
75
|
+
format: credentialFormat,
|
64
76
|
proof: JSON.stringify({
|
65
77
|
jwt: signedNonceProof,
|
66
78
|
proof_type: "jwt"
|
@@ -68,7 +80,8 @@ export const obtainCredential = async (issuerConf, accessToken, nonce, clientId,
|
|
68
80
|
});
|
69
81
|
const {
|
70
82
|
credential,
|
71
|
-
format
|
83
|
+
format,
|
84
|
+
c_nonce
|
72
85
|
} = await appFetch(credentialUrl, {
|
73
86
|
method: "POST",
|
74
87
|
headers: {
|
@@ -80,7 +93,8 @@ export const obtainCredential = async (issuerConf, accessToken, nonce, clientId,
|
|
80
93
|
}).then(hasStatus(200)).then(res => res.json()).then(CredentialEndpointResponse.parse);
|
81
94
|
return {
|
82
95
|
credential,
|
83
|
-
format
|
96
|
+
format,
|
97
|
+
nonce: c_nonce
|
84
98
|
};
|
85
99
|
};
|
86
100
|
//# sourceMappingURL=06-obtain-credential.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["z","uuid","SignJWT","createDPopToken","hasStatus","SupportedCredentialFormat","createNonceProof","nonce","issuer","audience","ctx","setPayload","jwk","getPublicKey","setProtectedHeader","type","setAudience","setIssuer","setIssuedAt","setExpirationTime","sign","CredentialEndpointResponse","object","credential","string","format","
|
1
|
+
{"version":3,"names":["z","uuid","SignJWT","createDPopToken","hasStatus","SupportedCredentialFormat","createNonceProof","nonce","issuer","audience","ctx","setPayload","jwk","getPublicKey","setProtectedHeader","type","setAudience","setIssuer","setIssuedAt","setExpirationTime","sign","CredentialEndpointResponse","object","credential","string","format","c_nonce","c_nonce_expires_in","number","isCredentialAvailable","issuerConf","credentialType","credentialFormat","openid_credential_issuer","credentials_supported","some","c","credential_definition","includes","obtainCredential","accessToken","clientId","context","credentialCryptoContext","walletProviderBaseUrl","appFetch","fetch","Error","credentialUrl","credential_endpoint","signedDPopForPid","htm","htu","jti","v4","signedNonceProof","formBody","URLSearchParams","JSON","stringify","proof","jwt","proof_type","method","headers","DPoP","Authorization","body","toString","then","res","json","parse"],"sourceRoot":"../../../../src","sources":["credential/issuance/06-obtain-credential.ts"],"mappings":"AAAA,OAAO,KAAKA,CAAC,MAAM,KAAK;AACxB,OAAOC,IAAI,MAAM,mBAAmB;AACpC,SAASC,OAAO,QAA4B,6BAA6B;AACzE,SAASC,eAAe,QAAQ,kBAAkB;AAGlD,SAASC,SAAS,QAAkB,kBAAkB;AAGtD,SAASC,yBAAyB,QAAQ,SAAS;;AAEnD;AACA;AACA;AACA,OAAO,MAAMC,gBAAgB,GAAG,MAAAA,CAC9BC,KAAa,EACbC,MAAc,EACdC,QAAgB,EAChBC,GAAkB,KACE;EACpB,OAAO,IAAIR,OAAO,CAACQ,GAAG,CAAC,CACpBC,UAAU,CAAC;IACVJ,KAAK;IACLK,GAAG,EAAE,MAAMF,GAAG,CAACG,YAAY,CAAC;EAC9B,CAAC,CAAC,CACDC,kBAAkB,CAAC;IAClBC,IAAI,EAAE;EACR,CAAC,CAAC,CACDC,WAAW,CAACP,QAAQ,CAAC,CACrBQ,SAAS,CAACT,MAAM,CAAC,CACjBU,WAAW,CAAC,CAAC,CACbC,iBAAiB,CAAC,IAAI,CAAC,CACvBC,IAAI,CAAC,CAAC;AACX,CAAC;AAED,MAAMC,0BAA0B,GAAGrB,CAAC,CAACsB,MAAM,CAAC;EAC1CC,UAAU,EAAEvB,CAAC,CAACwB,MAAM,CAAC,CAAC;EACtBC,MAA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EACLkC,QAAQ,EACRG,qBAAqB,EACrBD,uBACF,CAAC;;EAED;EACA,MAAMa,QAAQ,GAAG,IAAIC,eAAe,CAAC;IACnCpB,qBAAqB,EAAEqB,IAAI,CAACC,SAAS,CAAC;MACpC5C,IAAI,EAAE,CAACgB,cAAc;IACvB,CAAC,CAAC;IACFN,MAAM,EAAEO,gBAAgB;IACxB4B,KAAK,EAAEF,IAAI,CAACC,SAAS,CAAC;MACpBE,GAAG,EAAEN,gBAAgB;MACrBO,UAAU,EAAE;IACd,CAAC;EACH,CAAC,CAAC;EAEF,MAAM;IAAEvC,UAAU;IAAEE,MAAM;IAAEC;EAAQ,CAAC,GAAG,MAAMmB,QAAQ,CAACG,aAAa,EAAE;IACpEe,MAAM,EAAE,MAAM;IACdC,OAAO,EAAE;MACP,cAAc,EAAE,mCAAmC;MACnDC,IAAI,EAAEf,gBAAgB;MACtBgB,aAAa,EAAE1B;IACjB,CAAC;IACD2B,IAAI,EAAEX,QAAQ,CAACY,QAAQ,CAAC;EAC1B,CAAC,CAAC,CACCC,IAAI,CAACjE,SAAS,CAAC,GAAG,CAAC,CAAC,CACpBiE,IAAI,CAAEC,GAAG,IAAKA,GAAG,CAACC,IAAI,CAAC,CAAC,CAAC,CACzBF,IAAI,CAAChD,0BAA0B,CAACmD,KAAK,CAAC;EAEzC,OAAO;IAAEjD,UAAU;IAAEE,MAAM;IAAElB,KAAK,EAAEmB;EAAQ,CAAC;AAC/C,CAAC"}
|
@@ -15,7 +15,7 @@ const parseCredentialSdJwt = function (credentials_supported, _ref) {
|
|
15
15
|
let ignoreMissingAttributes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
16
16
|
// find the definition that matches the received credential's type
|
17
17
|
// warning: if more then a defintion is found, the first is retrieved
|
18
|
-
const credentialSubject = (_credentials_supporte = credentials_supported.find(c => c.credential_definition.type.includes(sdJwt.payload.type))) === null || _credentials_supporte === void 0 ? void 0 : _credentials_supporte.credential_definition.credentialSubject;
|
18
|
+
const credentialSubject = (_credentials_supporte = credentials_supported.find(c => c.format === "vc+sd-jwt" && c.credential_definition.type.includes(sdJwt.payload.type))) === null || _credentials_supporte === void 0 ? void 0 : _credentials_supporte.credential_definition.credentialSubject;
|
19
19
|
|
20
20
|
// the received credential matches no supported credential, throw an exception
|
21
21
|
if (!credentialSubject) {
|
@@ -139,6 +139,10 @@ const verifyAndParseCredentialSdJwt = async (issuerConf, credential, _, _ref8) =
|
|
139
139
|
parsedCredential
|
140
140
|
};
|
141
141
|
};
|
142
|
+
const verifyAndParseCredentialMdoc = async (_issuerConf, _credential, _, _ctx) => {
|
143
|
+
// TODO: [SIW-686] decode MDOC credentials
|
144
|
+
throw new Error("verifyAndParseCredentialMdoc not implemented yet");
|
145
|
+
};
|
142
146
|
|
143
147
|
/**
|
144
148
|
* Verify and parse an encoded credential
|
@@ -156,6 +160,8 @@ const verifyAndParseCredentialSdJwt = async (issuerConf, credential, _, _ref8) =
|
|
156
160
|
export const verifyAndParseCredential = async (issuerConf, credential, format, context) => {
|
157
161
|
if (format === "vc+sd-jwt") {
|
158
162
|
return verifyAndParseCredentialSdJwt(issuerConf, credential, format, context);
|
163
|
+
} else if (format === "vc+mdoc-cbor") {
|
164
|
+
return verifyAndParseCredentialMdoc(issuerConf, credential, format, context);
|
159
165
|
}
|
160
166
|
const _ = format;
|
161
167
|
throw new IoWalletError(`Unsupported credential format: ${_}`);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["IoWalletError","SdJwt4VC","verify","verifySdJwt","parseCredentialSdJwt","credentials_supported","_ref","_credentials_supporte","sdJwt","disclosures","ignoreMissingAttributes","arguments","length","undefined","credentialSubject","find","c","credential_definition","type","includes","payload","expected","flatMap","_","join","attrDefinitions","Object","entries","attrsNotInDisclosures","filter","_ref2","attrKey","mandatory","some","_ref3","name","missing","map","received","definedValues","_ref4","_disclosures$find","definition","value","_ref5","display","reduce","names","_ref6","locale","undefinedValues","keys","_ref7","key","fromEntries","verifyCredentialSdJwt","rawCredential","issuerKeys","holderBindingContext","decodedCredential","holderBindingKey","Promise","all","getPublicKey","cnf","jwk","kid","verifyAndParseCredentialSdJwt","issuerConf","credential","_ref8","credentialCryptoContext","decoded","openid_credential_issuer","jwks","parsedCredential","
|
1
|
+
{"version":3,"names":["IoWalletError","SdJwt4VC","verify","verifySdJwt","parseCredentialSdJwt","credentials_supported","_ref","_credentials_supporte","sdJwt","disclosures","ignoreMissingAttributes","arguments","length","undefined","credentialSubject","find","c","format","credential_definition","type","includes","payload","expected","flatMap","_","join","attrDefinitions","Object","entries","attrsNotInDisclosures","filter","_ref2","attrKey","mandatory","some","_ref3","name","missing","map","received","definedValues","_ref4","_disclosures$find","definition","value","_ref5","display","reduce","names","_ref6","locale","undefinedValues","keys","_ref7","key","fromEntries","verifyCredentialSdJwt","rawCredential","issuerKeys","holderBindingContext","decodedCredential","holderBindingKey","Promise","all","getPublicKey","cnf","jwk","kid","verifyAndParseCredentialSdJwt","issuerConf","credential","_ref8","credentialCryptoContext","decoded","openid_credential_issuer","jwks","parsedCredential","verifyAndParseCredentialMdoc","_issuerConf","_credential","_ctx","Error","verifyAndParseCredential","context"],"sourceRoot":"../../../../src","sources":["credential/issuance/07-verify-and-parse-credential.ts"],"mappings":"AAGA,SAASA,aAAa,QAAQ,oBAAoB;AAClD,SAASC,QAAQ,QAAQ,oBAAoB;AAC7C,SAASC,MAAM,IAAIC,WAAW,QAAQ,cAAc;;AAcpD;;AAmBA;;AAKA,MAAMC,oBAAoB,GAAG,SAAAA,CAE3BC,qBAAkH,EAAAC,IAAA,EAG7F;EAAA,IAAAC,qBAAA;EAAA,IAFrB;IAAEC,KAAK;IAAEC;EAAoC,CAAC,GAAAH,IAAA;EAAA,IAC9CI,uBAAgC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,KAAK;EAExC;EACA;EACA,MAAMG,iBAAiB,IAAAP,qBAAA,GAAGF,qBAAqB,CAACU,IAAI,CAC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AAI,EAC7CoB,uBACF,CAAC;EAED,MAAMI,gBAAgB,GAAGxE,oBAAoB,CAC3CiE,UAAU,CAACK,wBAAwB,CAACrE,qBAAqB,EACzDoE,OAAO,EACP/D,uBACF,CAAC;EAED,OAAO;IAAEkE;EAAiB,CAAC;AAC7B,CAAC;AAED,MAAMC,4BAAwD,GAAG,MAAAA,CAC/DC,WAAW,EACXC,WAAW,EACXvD,CAAC,EACDwD,IAAI,KACD;EACH;EACA,MAAM,IAAIC,KAAK,CAAC,kDAAkD,CAAC;AACrE,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,wBAAkD,GAAG,MAAAA,CAChEb,UAAU,EACVC,UAAU,EACVrD,MAAM,EACNkE,OAAO,KACJ;EACH,IAAIlE,MAAM,KAAK,WAAW,EAAE;IAC1B,OAAOmD,6BAA6B,CAClCC,UAAU,EACVC,UAAU,EACVrD,MAAM,EACNkE,OACF,CAAC;EACH,CAAC,MAAM,IAAIlE,MAAM,KAAK,cAAc,EAAE;IACpC,OAAO4D,4BAA4B,CACjCR,UAAU,EACVC,UAAU,EACVrD,MAAM,EACNkE,OACF,CAAC;EACH;EAEA,MAAM3D,CAAQ,GAAGP,MAAM;EACvB,MAAM,IAAIjB,aAAa,CAAE,kCAAiCwB,CAAE,EAAC,CAAC;AAChE,CAAC"}
|
@@ -1,4 +1,4 @@
|
|
1
1
|
import * as z from "zod";
|
2
2
|
export const ASSERTION_TYPE = "urn:ietf:params:oauth:client-assertion-type:jwt-client-attestation";
|
3
|
-
export const SupportedCredentialFormat = z.literal("vc+sd-jwt");
|
3
|
+
export const SupportedCredentialFormat = z.union([z.literal("vc+sd-jwt"), z.literal("vc+mdoc-cbor")]);
|
4
4
|
//# sourceMappingURL=const.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["z","ASSERTION_TYPE","SupportedCredentialFormat","literal"],"sourceRoot":"../../../../src","sources":["credential/issuance/const.ts"],"mappings":"AAAA,OAAO,KAAKA,CAAC,MAAM,KAAK;AACxB,OAAO,MAAMC,cAAc,GACzB,oEAAoE;AAKtE,OAAO,MAAMC,yBAAyB,GAAGF,CAAC,CAACG,OAAO,CAAC,WAAW,CAAC"}
|
1
|
+
{"version":3,"names":["z","ASSERTION_TYPE","SupportedCredentialFormat","union","literal"],"sourceRoot":"../../../../src","sources":["credential/issuance/const.ts"],"mappings":"AAAA,OAAO,KAAKA,CAAC,MAAM,KAAK;AACxB,OAAO,MAAMC,cAAc,GACzB,oEAAoE;AAKtE,OAAO,MAAMC,yBAAyB,GAAGF,CAAC,CAACG,KAAK,CAAC,CAC/CH,CAAC,CAACI,OAAO,CAAC,WAAW,CAAC,EACtBJ,CAAC,CAACI,OAAO,CAAC,cAAc,CAAC,CAC1B,CAAC"}
|
@@ -8,13 +8,14 @@ import { SupportedCredentialFormat } from "./const";
|
|
8
8
|
* Return the signed jwt for nonce proof of possession
|
9
9
|
*/
|
10
10
|
export declare const createNonceProof: (nonce: string, issuer: string, audience: string, ctx: CryptoContext) => Promise<string>;
|
11
|
-
export type ObtainCredential = (issuerConf: Out<EvaluateIssuerTrust>["issuerConf"], accessToken: Out<AuthorizeAccess>["accessToken"], nonce: Out<AuthorizeAccess>["nonce"], clientId: Out<AuthorizeAccess>["clientId"], credentialType: Out<StartFlow>["credentialType"], context: {
|
11
|
+
export type ObtainCredential = (issuerConf: Out<EvaluateIssuerTrust>["issuerConf"], accessToken: Out<AuthorizeAccess>["accessToken"], nonce: Out<AuthorizeAccess>["nonce"], clientId: Out<AuthorizeAccess>["clientId"], credentialType: Out<StartFlow>["credentialType"], credentialFormat: SupportedCredentialFormat, context: {
|
12
12
|
credentialCryptoContext: CryptoContext;
|
13
13
|
walletProviderBaseUrl: string;
|
14
14
|
appFetch?: GlobalFetch["fetch"];
|
15
15
|
}) => Promise<{
|
16
16
|
credential: string;
|
17
17
|
format: SupportedCredentialFormat;
|
18
|
+
nonce: string;
|
18
19
|
}>;
|
19
20
|
/**
|
20
21
|
* Fetch a credential from the issuer
|
@@ -24,6 +25,7 @@ export type ObtainCredential = (issuerConf: Out<EvaluateIssuerTrust>["issuerConf
|
|
24
25
|
* @param nonce The nonce value to prevent reply attacks, obtained with the access authorization step
|
25
26
|
* @param clientId Identifies the current client across all the requests of the issuing flow
|
26
27
|
* @param credentialType The type of the credential to be requested
|
28
|
+
* @param credentialFormat The format of the requested credential. @see {SupportedCredentialFormat}
|
27
29
|
* @param context.credentialCryptoContext The context to access the key the Credential will be bound to
|
28
30
|
* @param context.walletProviderBaseUrl The base url of the Wallet Provider
|
29
31
|
* @param context.appFetch (optional) fetch api implementation. Default: built-in fetch
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"06-obtain-credential.d.ts","sourceRoot":"","sources":["../../../../src/credential/issuance/06-obtain-credential.ts"],"names":[],"mappings":"AAEA,OAAO,EAAW,KAAK,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAG1E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAa,KAAK,GAAG,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AAEpD;;GAEG;AACH,eAAO,MAAM,gBAAgB,UACpB,MAAM,UACL,MAAM,YACJ,MAAM,OACX,aAAa,KACjB,QAAQ,MAAM,CAchB,CAAC;
|
1
|
+
{"version":3,"file":"06-obtain-credential.d.ts","sourceRoot":"","sources":["../../../../src/credential/issuance/06-obtain-credential.ts"],"names":[],"mappings":"AAEA,OAAO,EAAW,KAAK,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAG1E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAa,KAAK,GAAG,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AAEpD;;GAEG;AACH,eAAO,MAAM,gBAAgB,UACpB,MAAM,UACL,MAAM,YACJ,MAAM,OACX,aAAa,KACjB,QAAQ,MAAM,CAchB,CAAC;AAWF,MAAM,MAAM,gBAAgB,GAAG,CAC7B,UAAU,EAAE,GAAG,CAAC,mBAAmB,CAAC,CAAC,YAAY,CAAC,EAClD,WAAW,EAAE,GAAG,CAAC,eAAe,CAAC,CAAC,aAAa,CAAC,EAChD,KAAK,EAAE,GAAG,CAAC,eAAe,CAAC,CAAC,OAAO,CAAC,EACpC,QAAQ,EAAE,GAAG,CAAC,eAAe,CAAC,CAAC,UAAU,CAAC,EAC1C,cAAc,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC,gBAAgB,CAAC,EAChD,gBAAgB,EAAE,yBAAyB,EAC3C,OAAO,EAAE;IACP,uBAAuB,EAAE,aAAa,CAAC;IACvC,qBAAqB,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;CACjC,KACE,OAAO,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,yBAAyB,CAAC;IAClC,KAAK,EAAE,MAAM,CAAC;CACf,CAAC,CAAC;AAeH;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gBAAgB,EAAE,gBAuE9B,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"07-verify-and-parse-credential.d.ts","sourceRoot":"","sources":["../../../../src/credential/issuance/07-verify-and-parse-credential.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAK/D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAEjE,MAAM,MAAM,wBAAwB,GAAG,CACrC,UAAU,EAAE,GAAG,CAAC,mBAAmB,CAAC,CAAC,YAAY,CAAC,EAClD,UAAU,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAC,YAAY,CAAC,EAC/C,MAAM,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAC,QAAQ,CAAC,EACvC,OAAO,EAAE;IACP,uBAAuB,EAAE,aAAa,CAAC;IACvC,uBAAuB,CAAC,EAAE,OAAO,CAAC;CACnC,KACE,OAAO,CAAC;IAAE,gBAAgB,EAAE,gBAAgB,CAAA;CAAE,CAAC,CAAC;AAGrD,KAAK,gBAAgB,GAAG,MAAM;AAC5B,oBAAoB;AACpB,MAAM,EACN;IACE,2CAA2C;IAC3C,IAAI,EACA,yBAAyB,CAAC,MAAM,CAC9B,MAAM,EACN,MAAM,CACP,GACD,4BAA4B,CAAC,MAAM,CAAC;IACxC,+CAA+C;IAC/C,SAAS,EAAE,OAAO,CAAC;IACnB,wCAAwC;IACxC,KAAK,EAAE,OAAO,CAAC;CAChB,CACF,CAAC;
|
1
|
+
{"version":3,"file":"07-verify-and-parse-credential.d.ts","sourceRoot":"","sources":["../../../../src/credential/issuance/07-verify-and-parse-credential.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAK/D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAEjE,MAAM,MAAM,wBAAwB,GAAG,CACrC,UAAU,EAAE,GAAG,CAAC,mBAAmB,CAAC,CAAC,YAAY,CAAC,EAClD,UAAU,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAC,YAAY,CAAC,EAC/C,MAAM,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAC,QAAQ,CAAC,EACvC,OAAO,EAAE;IACP,uBAAuB,EAAE,aAAa,CAAC;IACvC,uBAAuB,CAAC,EAAE,OAAO,CAAC;CACnC,KACE,OAAO,CAAC;IAAE,gBAAgB,EAAE,gBAAgB,CAAA;CAAE,CAAC,CAAC;AAGrD,KAAK,gBAAgB,GAAG,MAAM;AAC5B,oBAAoB;AACpB,MAAM,EACN;IACE,2CAA2C;IAC3C,IAAI,EACA,yBAAyB,CAAC,MAAM,CAC9B,MAAM,EACN,MAAM,CACP,GACD,4BAA4B,CAAC,MAAM,CAAC;IACxC,+CAA+C;IAC/C,SAAS,EAAE,OAAO,CAAC;IACnB,wCAAwC;IACxC,KAAK,EAAE,OAAO,CAAC;CAChB,CACF,CAAC;AA8KF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,wBAAwB,EAAE,wBAwBtC,CAAC"}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import * as z from "zod";
|
2
2
|
export declare const ASSERTION_TYPE = "urn:ietf:params:oauth:client-assertion-type:jwt-client-attestation";
|
3
3
|
export type SupportedCredentialFormat = z.infer<typeof SupportedCredentialFormat>;
|
4
|
-
export declare const SupportedCredentialFormat: z.ZodLiteral<"vc+sd-jwt">;
|
4
|
+
export declare const SupportedCredentialFormat: z.ZodUnion<[z.ZodLiteral<"vc+sd-jwt">, z.ZodLiteral<"vc+mdoc-cbor">]>;
|
5
5
|
//# sourceMappingURL=const.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"const.d.ts","sourceRoot":"","sources":["../../../../src/credential/issuance/const.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AACzB,eAAO,MAAM,cAAc,uEAC2C,CAAC;AAEvE,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAC7C,OAAO,yBAAyB,CACjC,CAAC;AACF,eAAO,MAAM,yBAAyB,
|
1
|
+
{"version":3,"file":"const.d.ts","sourceRoot":"","sources":["../../../../src/credential/issuance/const.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AACzB,eAAO,MAAM,cAAc,uEAC2C,CAAC;AAEvE,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAC7C,OAAO,yBAAyB,CACjC,CAAC;AACF,eAAO,MAAM,yBAAyB,uEAGpC,CAAC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@pagopa/io-react-native-wallet",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.11.0",
|
4
4
|
"description": "Provide data structures, helpers and API for IO Wallet",
|
5
5
|
"main": "lib/commonjs/index",
|
6
6
|
"module": "lib/module/index",
|
@@ -82,7 +82,7 @@
|
|
82
82
|
"engines": {
|
83
83
|
"node": ">= 16.0.0"
|
84
84
|
},
|
85
|
-
"packageManager": "
|
85
|
+
"packageManager": "yarn@1.22.19",
|
86
86
|
"jest": {
|
87
87
|
"preset": "react-native",
|
88
88
|
"modulePathIgnorePatterns": [
|
@@ -36,6 +36,10 @@ export const createNonceProof = async (
|
|
36
36
|
const CredentialEndpointResponse = z.object({
|
37
37
|
credential: z.string(),
|
38
38
|
format: SupportedCredentialFormat,
|
39
|
+
// nonce used to perform multiple credential requests
|
40
|
+
// re-using the same authorization profile
|
41
|
+
c_nonce: z.string(),
|
42
|
+
c_nonce_expires_in: z.number(),
|
39
43
|
});
|
40
44
|
|
41
45
|
export type ObtainCredential = (
|
@@ -44,12 +48,30 @@ export type ObtainCredential = (
|
|
44
48
|
nonce: Out<AuthorizeAccess>["nonce"],
|
45
49
|
clientId: Out<AuthorizeAccess>["clientId"],
|
46
50
|
credentialType: Out<StartFlow>["credentialType"],
|
51
|
+
credentialFormat: SupportedCredentialFormat,
|
47
52
|
context: {
|
48
53
|
credentialCryptoContext: CryptoContext;
|
49
54
|
walletProviderBaseUrl: string;
|
50
55
|
appFetch?: GlobalFetch["fetch"];
|
51
56
|
}
|
52
|
-
) => Promise<{
|
57
|
+
) => Promise<{
|
58
|
+
credential: string;
|
59
|
+
format: SupportedCredentialFormat;
|
60
|
+
nonce: string;
|
61
|
+
}>;
|
62
|
+
|
63
|
+
// Checks whether in the Entity confoguration at least one credential
|
64
|
+
// is defined for the given type and format
|
65
|
+
const isCredentialAvailable = (
|
66
|
+
issuerConf: Out<EvaluateIssuerTrust>["issuerConf"],
|
67
|
+
credentialType: Out<StartFlow>["credentialType"],
|
68
|
+
credentialFormat: SupportedCredentialFormat
|
69
|
+
): boolean =>
|
70
|
+
issuerConf.openid_credential_issuer.credentials_supported.some(
|
71
|
+
(c) =>
|
72
|
+
c.format === credentialFormat &&
|
73
|
+
c.credential_definition.type.includes(credentialType)
|
74
|
+
);
|
53
75
|
|
54
76
|
/**
|
55
77
|
* Fetch a credential from the issuer
|
@@ -59,6 +81,7 @@ export type ObtainCredential = (
|
|
59
81
|
* @param nonce The nonce value to prevent reply attacks, obtained with the access authorization step
|
60
82
|
* @param clientId Identifies the current client across all the requests of the issuing flow
|
61
83
|
* @param credentialType The type of the credential to be requested
|
84
|
+
* @param credentialFormat The format of the requested credential. @see {SupportedCredentialFormat}
|
62
85
|
* @param context.credentialCryptoContext The context to access the key the Credential will be bound to
|
63
86
|
* @param context.walletProviderBaseUrl The base url of the Wallet Provider
|
64
87
|
* @param context.appFetch (optional) fetch api implementation. Default: built-in fetch
|
@@ -70,6 +93,7 @@ export const obtainCredential: ObtainCredential = async (
|
|
70
93
|
nonce,
|
71
94
|
clientId,
|
72
95
|
credentialType,
|
96
|
+
credentialFormat,
|
73
97
|
context
|
74
98
|
) => {
|
75
99
|
const {
|
@@ -78,6 +102,12 @@ export const obtainCredential: ObtainCredential = async (
|
|
78
102
|
appFetch = fetch,
|
79
103
|
} = context;
|
80
104
|
|
105
|
+
if (!isCredentialAvailable(issuerConf, credentialType, credentialFormat)) {
|
106
|
+
throw new Error(
|
107
|
+
`The Issuer provides no credential for type ${credentialType} and format ${credentialFormat}`
|
108
|
+
);
|
109
|
+
}
|
110
|
+
|
81
111
|
const credentialUrl = issuerConf.openid_credential_issuer.credential_endpoint;
|
82
112
|
|
83
113
|
/** DPoP token for demonstating the possession
|
@@ -107,14 +137,14 @@ export const obtainCredential: ObtainCredential = async (
|
|
107
137
|
credential_definition: JSON.stringify({
|
108
138
|
type: [credentialType],
|
109
139
|
}),
|
110
|
-
format:
|
140
|
+
format: credentialFormat,
|
111
141
|
proof: JSON.stringify({
|
112
142
|
jwt: signedNonceProof,
|
113
143
|
proof_type: "jwt",
|
114
144
|
}),
|
115
145
|
});
|
116
146
|
|
117
|
-
const { credential, format } = await appFetch(credentialUrl, {
|
147
|
+
const { credential, format, c_nonce } = await appFetch(credentialUrl, {
|
118
148
|
method: "POST",
|
119
149
|
headers: {
|
120
150
|
"Content-Type": "application/x-www-form-urlencoded",
|
@@ -127,5 +157,5 @@ export const obtainCredential: ObtainCredential = async (
|
|
127
157
|
.then((res) => res.json())
|
128
158
|
.then(CredentialEndpointResponse.parse);
|
129
159
|
|
130
|
-
return { credential, format };
|
160
|
+
return { credential, format, nonce: c_nonce };
|
131
161
|
};
|
@@ -49,8 +49,10 @@ const parseCredentialSdJwt = (
|
|
49
49
|
): ParsedCredential => {
|
50
50
|
// find the definition that matches the received credential's type
|
51
51
|
// warning: if more then a defintion is found, the first is retrieved
|
52
|
-
const credentialSubject = credentials_supported.find(
|
53
|
-
c
|
52
|
+
const credentialSubject = credentials_supported.find(
|
53
|
+
(c) =>
|
54
|
+
c.format === "vc+sd-jwt" &&
|
55
|
+
c.credential_definition.type.includes(sdJwt.payload.type)
|
54
56
|
)?.credential_definition.credentialSubject;
|
55
57
|
|
56
58
|
// the received credential matches no supported credential, throw an exception
|
@@ -196,6 +198,16 @@ const verifyAndParseCredentialSdJwt: WithFormat<"vc+sd-jwt"> = async (
|
|
196
198
|
return { parsedCredential };
|
197
199
|
};
|
198
200
|
|
201
|
+
const verifyAndParseCredentialMdoc: WithFormat<"vc+mdoc-cbor"> = async (
|
202
|
+
_issuerConf,
|
203
|
+
_credential,
|
204
|
+
_,
|
205
|
+
_ctx
|
206
|
+
) => {
|
207
|
+
// TODO: [SIW-686] decode MDOC credentials
|
208
|
+
throw new Error("verifyAndParseCredentialMdoc not implemented yet");
|
209
|
+
};
|
210
|
+
|
199
211
|
/**
|
200
212
|
* Verify and parse an encoded credential
|
201
213
|
*
|
@@ -222,6 +234,13 @@ export const verifyAndParseCredential: VerifyAndParseCredential = async (
|
|
222
234
|
format,
|
223
235
|
context
|
224
236
|
);
|
237
|
+
} else if (format === "vc+mdoc-cbor") {
|
238
|
+
return verifyAndParseCredentialMdoc(
|
239
|
+
issuerConf,
|
240
|
+
credential,
|
241
|
+
format,
|
242
|
+
context
|
243
|
+
);
|
225
244
|
}
|
226
245
|
|
227
246
|
const _: never = format;
|
@@ -5,4 +5,7 @@ export const ASSERTION_TYPE =
|
|
5
5
|
export type SupportedCredentialFormat = z.infer<
|
6
6
|
typeof SupportedCredentialFormat
|
7
7
|
>;
|
8
|
-
export const SupportedCredentialFormat = z.
|
8
|
+
export const SupportedCredentialFormat = z.union([
|
9
|
+
z.literal("vc+sd-jwt"),
|
10
|
+
z.literal("vc+mdoc-cbor"),
|
11
|
+
]);
|