@pagopa/io-react-native-wallet 2.0.0-next.4 → 2.0.0-next.5
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/lib/commonjs/credential/issuance/07-verify-and-parse-credential.js +3 -3
- package/lib/commonjs/credential/issuance/07-verify-and-parse-credential.js.map +1 -1
- package/lib/commonjs/credential/status/{02-status-attestation.js → 02-status-assertion.js} +28 -22
- package/lib/commonjs/credential/status/02-status-assertion.js.map +1 -0
- package/lib/commonjs/credential/status/03-verify-and-parse-status-assertion.js +85 -0
- package/lib/commonjs/credential/status/03-verify-and-parse-status-assertion.js.map +1 -0
- package/lib/commonjs/credential/status/README.md +22 -20
- package/lib/commonjs/credential/status/index.js +6 -6
- package/lib/commonjs/credential/status/index.js.map +1 -1
- package/lib/commonjs/credential/status/types.js +48 -15
- package/lib/commonjs/credential/status/types.js.map +1 -1
- package/lib/commonjs/utils/credentials.js +33 -0
- package/lib/commonjs/utils/credentials.js.map +1 -0
- package/lib/commonjs/utils/crypto.js +1 -7
- package/lib/commonjs/utils/crypto.js.map +1 -1
- package/lib/commonjs/utils/jwk.js +12 -0
- package/lib/commonjs/utils/jwk.js.map +1 -1
- package/lib/module/credential/issuance/07-verify-and-parse-credential.js +4 -4
- package/lib/module/credential/issuance/07-verify-and-parse-credential.js.map +1 -1
- package/lib/module/credential/status/{02-status-attestation.js → 02-status-assertion.js} +28 -22
- package/lib/module/credential/status/02-status-assertion.js.map +1 -0
- package/lib/module/credential/status/03-verify-and-parse-status-assertion.js +78 -0
- package/lib/module/credential/status/03-verify-and-parse-status-assertion.js.map +1 -0
- package/lib/module/credential/status/README.md +22 -20
- package/lib/module/credential/status/index.js +3 -3
- package/lib/module/credential/status/index.js.map +1 -1
- package/lib/module/credential/status/types.js +43 -12
- package/lib/module/credential/status/types.js.map +1 -1
- package/lib/module/utils/credentials.js +26 -0
- package/lib/module/utils/credentials.js.map +1 -0
- package/lib/module/utils/crypto.js +2 -8
- package/lib/module/utils/crypto.js.map +1 -1
- package/lib/module/utils/jwk.js +11 -1
- package/lib/module/utils/jwk.js.map +1 -1
- package/lib/typescript/credential/issuance/07-verify-and-parse-credential.d.ts.map +1 -1
- package/lib/typescript/credential/status/02-status-assertion.d.ts +23 -0
- package/lib/typescript/credential/status/02-status-assertion.d.ts.map +1 -0
- package/lib/typescript/credential/status/03-verify-and-parse-status-assertion.d.ts +21 -0
- package/lib/typescript/credential/status/03-verify-and-parse-status-assertion.d.ts.map +1 -0
- package/lib/typescript/credential/status/index.d.ts +4 -4
- package/lib/typescript/credential/status/index.d.ts.map +1 -1
- package/lib/typescript/credential/status/types.d.ts +495 -18
- package/lib/typescript/credential/status/types.d.ts.map +1 -1
- package/lib/typescript/utils/credentials.d.ts +11 -0
- package/lib/typescript/utils/credentials.d.ts.map +1 -0
- package/lib/typescript/utils/crypto.d.ts.map +1 -1
- package/lib/typescript/utils/jwk.d.ts +7 -0
- package/lib/typescript/utils/jwk.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/credential/issuance/07-verify-and-parse-credential.ts +4 -6
- package/src/credential/status/{02-status-attestation.ts → 02-status-assertion.ts} +37 -28
- package/src/credential/status/03-verify-and-parse-status-assertion.ts +109 -0
- package/src/credential/status/README.md +22 -20
- package/src/credential/status/index.ts +7 -14
- package/src/credential/status/types.ts +62 -15
- package/src/utils/credentials.ts +29 -0
- package/src/utils/crypto.ts +12 -20
- package/src/utils/jwk.ts +15 -1
- package/lib/commonjs/credential/status/02-status-attestation.js.map +0 -1
- package/lib/commonjs/credential/status/03-verify-and-parse-status-attestation.js +0 -55
- package/lib/commonjs/credential/status/03-verify-and-parse-status-attestation.js.map +0 -1
- package/lib/module/credential/status/02-status-attestation.js.map +0 -1
- package/lib/module/credential/status/03-verify-and-parse-status-attestation.js +0 -49
- package/lib/module/credential/status/03-verify-and-parse-status-attestation.js.map +0 -1
- package/lib/typescript/credential/status/02-status-attestation.d.ts +0 -19
- package/lib/typescript/credential/status/02-status-attestation.d.ts.map +0 -1
- package/lib/typescript/credential/status/03-verify-and-parse-status-attestation.d.ts +0 -24
- package/lib/typescript/credential/status/03-verify-and-parse-status-attestation.d.ts.map +0 -1
- package/src/credential/status/03-verify-and-parse-status-attestation.ts +0 -70
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["getCredentialHashWithouDiscloures","hasStatusOrThrow","SignJWT","v4","uuidv4","StatusAttestationResponse","IssuerResponseError","IssuerResponseErrorCodes","ResponseErrorBuilder","UnexpectedStatusCodeError","LogLevel","Logger","statusAttestation","issuerConf","credential","credentialCryptoContext","appFetch","arguments","length","undefined","fetch","jwk","getPublicKey","credentialHash","statusAttUrl","openid_credential_issuer","status_attestation_endpoint","credentialPop","setPayload","aud","jti","toString","credential_hash","credential_hash_alg","setProtectedHeader","alg","typ","kid","setIssuedAt","setExpirationTime","sign","body","credential_pop","log","DEBUG","result","method","headers","JSON","stringify","then","raw","json","parse","catch","handleStatusAttestationError","status_attestation","e","handle","code","CredentialInvalidStatus","message","StatusAttestationRequestFailed","buildFrom"],"sourceRoot":"../../../../src","sources":["credential/status/02-status-attestation.ts"],"mappings":"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"}
|
@@ -1,49 +0,0 @@
|
|
1
|
-
import { IoWalletError } from "../../utils/errors";
|
2
|
-
import { verify } from "@pagopa/io-react-native-jwt";
|
3
|
-
import { ParsedStatusAttestation } from "./types";
|
4
|
-
import { decode as decodeJwt } from "@pagopa/io-react-native-jwt";
|
5
|
-
import { LogLevel, Logger } from "../../utils/logging";
|
6
|
-
/**
|
7
|
-
* Given a status attestation, verifies that:
|
8
|
-
* - It's in the supported format;
|
9
|
-
* - The attestation is correctly signed;
|
10
|
-
* - It's bound to the given key.
|
11
|
-
* @param issuerConf The Issuer configuration returned by {@link evaluateIssuerTrust}
|
12
|
-
* @param statusAttestation The encoded status attestation returned by {@link statusAttestation}
|
13
|
-
* @param context.credentialCryptoContext The crypto context used to obtain the credential in {@link obtainCredential}
|
14
|
-
* @returns A parsed status attestation
|
15
|
-
* @throws {IoWalletError} If the credential signature is not verified with the Issuer key set
|
16
|
-
* @throws {IoWalletError} If the credential is not bound to the provided user key
|
17
|
-
* @throws {IoWalletError} If the credential data fail to parse
|
18
|
-
*/
|
19
|
-
export const verifyAndParseStatusAttestation = async (issuerConf, rawStatusAttestation, context) => {
|
20
|
-
try {
|
21
|
-
const {
|
22
|
-
statusAttestation
|
23
|
-
} = rawStatusAttestation;
|
24
|
-
const {
|
25
|
-
credentialCryptoContext
|
26
|
-
} = context;
|
27
|
-
await verify(statusAttestation, issuerConf.openid_credential_issuer.jwks.keys);
|
28
|
-
const decodedJwt = decodeJwt(statusAttestation);
|
29
|
-
const parsedStatusAttestation = ParsedStatusAttestation.parse({
|
30
|
-
header: decodedJwt.protectedHeader,
|
31
|
-
payload: decodedJwt.payload
|
32
|
-
});
|
33
|
-
Logger.log(LogLevel.DEBUG, `Parsed status attestation: ${JSON.stringify(parsedStatusAttestation)}`);
|
34
|
-
const holderBindingKey = await credentialCryptoContext.getPublicKey();
|
35
|
-
const {
|
36
|
-
cnf
|
37
|
-
} = parsedStatusAttestation.payload;
|
38
|
-
if (!cnf.jwk.kid || cnf.jwk.kid !== holderBindingKey.kid) {
|
39
|
-
Logger.log(LogLevel.ERROR, `Failed to verify holder binding for status attestation, expected kid: ${holderBindingKey.kid}, got: ${parsedStatusAttestation.payload.cnf.jwk.kid}`);
|
40
|
-
throw new IoWalletError(`Failed to verify holder binding for status attestation, expected kid: ${holderBindingKey.kid}, got: ${parsedStatusAttestation.payload.cnf.jwk.kid}`);
|
41
|
-
}
|
42
|
-
return {
|
43
|
-
parsedStatusAttestation
|
44
|
-
};
|
45
|
-
} catch (e) {
|
46
|
-
throw new IoWalletError(`Failed to verify status attestation: ${JSON.stringify(e)}`);
|
47
|
-
}
|
48
|
-
};
|
49
|
-
//# sourceMappingURL=03-verify-and-parse-status-attestation.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["IoWalletError","verify","ParsedStatusAttestation","decode","decodeJwt","LogLevel","Logger","verifyAndParseStatusAttestation","issuerConf","rawStatusAttestation","context","statusAttestation","credentialCryptoContext","openid_credential_issuer","jwks","keys","decodedJwt","parsedStatusAttestation","parse","header","protectedHeader","payload","log","DEBUG","JSON","stringify","holderBindingKey","getPublicKey","cnf","jwk","kid","ERROR","e"],"sourceRoot":"../../../../src","sources":["credential/status/03-verify-and-parse-status-attestation.ts"],"mappings":"AACA,SAASA,aAAa,QAAQ,oBAAoB;AAClD,SAASC,MAAM,QAA4B,6BAA6B;AAExE,SAASC,uBAAuB,QAAQ,SAAS;AACjD,SAASC,MAAM,IAAIC,SAAS,QAAQ,6BAA6B;AACjE,SAASC,QAAQ,EAAEC,MAAM,QAAQ,qBAAqB;AAUtD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,+BAAgE,GAC3E,MAAAA,CAAOC,UAAU,EAAEC,oBAAoB,EAAEC,OAAO,KAAK;EACnD,IAAI;IACF,MAAM;MAAEC;IAAkB,CAAC,GAAGF,oBAAoB;IAClD,MAAM;MAAEG;IAAwB,CAAC,GAAGF,OAAO;IAE3C,MAAMT,MAAM,CACVU,iBAAiB,EACjBH,UAAU,CAACK,wBAAwB,CAACC,IAAI,CAACC,IAC3C,CAAC;IAED,MAAMC,UAAU,GAAGZ,SAAS,CAACO,iBAAiB,CAAC;IAC/C,MAAMM,uBAAuB,GAAGf,uBAAuB,CAACgB,KAAK,CAAC;MAC5DC,MAAM,EAAEH,UAAU,CAACI,eAAe;MAClCC,OAAO,EAAEL,UAAU,CAACK;IACtB,CAAC,CAAC;IAEFf,MAAM,CAACgB,GAAG,CACRjB,QAAQ,CAACkB,KAAK,EACb,8BAA6BC,IAAI,CAACC,SAAS,CAACR,uBAAuB,CAAE,EACxE,CAAC;IAED,MAAMS,gBAAgB,GAAG,MAAMd,uBAAuB,CAACe,YAAY,CAAC,CAAC;IACrE,MAAM;MAAEC;IAAI,CAAC,GAAGX,uBAAuB,CAACI,OAAO;IAC/C,IAAI,CAACO,GAAG,CAACC,GAAG,CAACC,GAAG,IAAIF,GAAG,CAACC,GAAG,CAACC,GAAG,KAAKJ,gBAAgB,CAACI,GAAG,EAAE;MACxDxB,MAAM,CAACgB,GAAG,CACRjB,QAAQ,CAAC0B,KAAK,EACb,yEAAwEL,gBAAgB,CAACI,GAAI,UAASb,uBAAuB,CAACI,OAAO,CAACO,GAAG,CAACC,GAAG,CAACC,GAAI,EACrJ,CAAC;MACD,MAAM,IAAI9B,aAAa,CACpB,yEAAwE0B,gBAAgB,CAACI,GAAI,UAASb,uBAAuB,CAACI,OAAO,CAACO,GAAG,CAACC,GAAG,CAACC,GAAI,EACrJ,CAAC;IACH;IAEA,OAAO;MAAEb;IAAwB,CAAC;EACpC,CAAC,CAAC,OAAOe,CAAC,EAAE;IACV,MAAM,IAAIhC,aAAa,CACpB,wCAAuCwB,IAAI,CAACC,SAAS,CAACO,CAAC,CAAE,EAC5D,CAAC;EACH;AACF,CAAC"}
|
@@ -1,19 +0,0 @@
|
|
1
|
-
import { type Out } from "../../utils/misc";
|
2
|
-
import type { EvaluateIssuerTrust, ObtainCredential } from "../issuance";
|
3
|
-
import { type CryptoContext } from "@pagopa/io-react-native-jwt";
|
4
|
-
import { StatusAttestationResponse } from "./types";
|
5
|
-
export type StatusAttestation = (issuerConf: Out<EvaluateIssuerTrust>["issuerConf"], credential: Out<ObtainCredential>["credential"], credentialCryptoContext: CryptoContext, appFetch?: GlobalFetch["fetch"]) => Promise<{
|
6
|
-
statusAttestation: StatusAttestationResponse["status_attestation"];
|
7
|
-
}>;
|
8
|
-
/**
|
9
|
-
* WARNING: This function must be called after {@link startFlow}.
|
10
|
-
* Verify the status of the credential attestation.
|
11
|
-
* @param issuerConf - The issuer's configuration
|
12
|
-
* @param credential - The credential to be verified
|
13
|
-
* @param credentialCryptoContext - The credential's crypto context
|
14
|
-
* @param context.appFetch (optional) fetch api implementation. Default: built-in fetch
|
15
|
-
* @throws {IssuerResponseError} with a specific code for more context
|
16
|
-
* @returns The credential status attestation
|
17
|
-
*/
|
18
|
-
export declare const statusAttestation: StatusAttestation;
|
19
|
-
//# sourceMappingURL=02-status-attestation.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"02-status-attestation.d.ts","sourceRoot":"","sources":["../../../../src/credential/status/02-status-attestation.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,GAAG,EACT,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EAAE,KAAK,aAAa,EAAW,MAAM,6BAA6B,CAAC;AAE1E,OAAO,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AASpD,MAAM,MAAM,iBAAiB,GAAG,CAC9B,UAAU,EAAE,GAAG,CAAC,mBAAmB,CAAC,CAAC,YAAY,CAAC,EAClD,UAAU,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAC,YAAY,CAAC,EAC/C,uBAAuB,EAAE,aAAa,EACtC,QAAQ,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,KAC5B,OAAO,CAAC;IACX,iBAAiB,EAAE,yBAAyB,CAAC,oBAAoB,CAAC,CAAC;CACpE,CAAC,CAAC;AAEH;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,EAAE,iBA6C/B,CAAC"}
|
@@ -1,24 +0,0 @@
|
|
1
|
-
import type { Out } from "../../utils/misc";
|
2
|
-
import { type CryptoContext } from "@pagopa/io-react-native-jwt";
|
3
|
-
import type { EvaluateIssuerTrust, StatusAttestation } from "../status";
|
4
|
-
import { ParsedStatusAttestation } from "./types";
|
5
|
-
export type VerifyAndParseStatusAttestation = (issuerConf: Out<EvaluateIssuerTrust>["issuerConf"], statusAttestation: Out<StatusAttestation>, context: {
|
6
|
-
credentialCryptoContext: CryptoContext;
|
7
|
-
}) => Promise<{
|
8
|
-
parsedStatusAttestation: ParsedStatusAttestation;
|
9
|
-
}>;
|
10
|
-
/**
|
11
|
-
* Given a status attestation, verifies that:
|
12
|
-
* - It's in the supported format;
|
13
|
-
* - The attestation is correctly signed;
|
14
|
-
* - It's bound to the given key.
|
15
|
-
* @param issuerConf The Issuer configuration returned by {@link evaluateIssuerTrust}
|
16
|
-
* @param statusAttestation The encoded status attestation returned by {@link statusAttestation}
|
17
|
-
* @param context.credentialCryptoContext The crypto context used to obtain the credential in {@link obtainCredential}
|
18
|
-
* @returns A parsed status attestation
|
19
|
-
* @throws {IoWalletError} If the credential signature is not verified with the Issuer key set
|
20
|
-
* @throws {IoWalletError} If the credential is not bound to the provided user key
|
21
|
-
* @throws {IoWalletError} If the credential data fail to parse
|
22
|
-
*/
|
23
|
-
export declare const verifyAndParseStatusAttestation: VerifyAndParseStatusAttestation;
|
24
|
-
//# sourceMappingURL=03-verify-and-parse-status-attestation.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"03-verify-and-parse-status-attestation.d.ts","sourceRoot":"","sources":["../../../../src/credential/status/03-verify-and-parse-status-attestation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAE5C,OAAO,EAAU,KAAK,aAAa,EAAE,MAAM,6BAA6B,CAAC;AACzE,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AACxE,OAAO,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAIlD,MAAM,MAAM,+BAA+B,GAAG,CAC5C,UAAU,EAAE,GAAG,CAAC,mBAAmB,CAAC,CAAC,YAAY,CAAC,EAClD,iBAAiB,EAAE,GAAG,CAAC,iBAAiB,CAAC,EACzC,OAAO,EAAE;IACP,uBAAuB,EAAE,aAAa,CAAC;CACxC,KACE,OAAO,CAAC;IAAE,uBAAuB,EAAE,uBAAuB,CAAA;CAAE,CAAC,CAAC;AAEnE;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,+BAA+B,EAAE,+BAwC3C,CAAC"}
|
@@ -1,70 +0,0 @@
|
|
1
|
-
import type { Out } from "../../utils/misc";
|
2
|
-
import { IoWalletError } from "../../utils/errors";
|
3
|
-
import { verify, type CryptoContext } from "@pagopa/io-react-native-jwt";
|
4
|
-
import type { EvaluateIssuerTrust, StatusAttestation } from "../status";
|
5
|
-
import { ParsedStatusAttestation } from "./types";
|
6
|
-
import { decode as decodeJwt } from "@pagopa/io-react-native-jwt";
|
7
|
-
import { LogLevel, Logger } from "../../utils/logging";
|
8
|
-
|
9
|
-
export type VerifyAndParseStatusAttestation = (
|
10
|
-
issuerConf: Out<EvaluateIssuerTrust>["issuerConf"],
|
11
|
-
statusAttestation: Out<StatusAttestation>,
|
12
|
-
context: {
|
13
|
-
credentialCryptoContext: CryptoContext;
|
14
|
-
}
|
15
|
-
) => Promise<{ parsedStatusAttestation: ParsedStatusAttestation }>;
|
16
|
-
|
17
|
-
/**
|
18
|
-
* Given a status attestation, verifies that:
|
19
|
-
* - It's in the supported format;
|
20
|
-
* - The attestation is correctly signed;
|
21
|
-
* - It's bound to the given key.
|
22
|
-
* @param issuerConf The Issuer configuration returned by {@link evaluateIssuerTrust}
|
23
|
-
* @param statusAttestation The encoded status attestation returned by {@link statusAttestation}
|
24
|
-
* @param context.credentialCryptoContext The crypto context used to obtain the credential in {@link obtainCredential}
|
25
|
-
* @returns A parsed status attestation
|
26
|
-
* @throws {IoWalletError} If the credential signature is not verified with the Issuer key set
|
27
|
-
* @throws {IoWalletError} If the credential is not bound to the provided user key
|
28
|
-
* @throws {IoWalletError} If the credential data fail to parse
|
29
|
-
*/
|
30
|
-
export const verifyAndParseStatusAttestation: VerifyAndParseStatusAttestation =
|
31
|
-
async (issuerConf, rawStatusAttestation, context) => {
|
32
|
-
try {
|
33
|
-
const { statusAttestation } = rawStatusAttestation;
|
34
|
-
const { credentialCryptoContext } = context;
|
35
|
-
|
36
|
-
await verify(
|
37
|
-
statusAttestation,
|
38
|
-
issuerConf.openid_credential_issuer.jwks.keys
|
39
|
-
);
|
40
|
-
|
41
|
-
const decodedJwt = decodeJwt(statusAttestation);
|
42
|
-
const parsedStatusAttestation = ParsedStatusAttestation.parse({
|
43
|
-
header: decodedJwt.protectedHeader,
|
44
|
-
payload: decodedJwt.payload,
|
45
|
-
});
|
46
|
-
|
47
|
-
Logger.log(
|
48
|
-
LogLevel.DEBUG,
|
49
|
-
`Parsed status attestation: ${JSON.stringify(parsedStatusAttestation)}`
|
50
|
-
);
|
51
|
-
|
52
|
-
const holderBindingKey = await credentialCryptoContext.getPublicKey();
|
53
|
-
const { cnf } = parsedStatusAttestation.payload;
|
54
|
-
if (!cnf.jwk.kid || cnf.jwk.kid !== holderBindingKey.kid) {
|
55
|
-
Logger.log(
|
56
|
-
LogLevel.ERROR,
|
57
|
-
`Failed to verify holder binding for status attestation, expected kid: ${holderBindingKey.kid}, got: ${parsedStatusAttestation.payload.cnf.jwk.kid}`
|
58
|
-
);
|
59
|
-
throw new IoWalletError(
|
60
|
-
`Failed to verify holder binding for status attestation, expected kid: ${holderBindingKey.kid}, got: ${parsedStatusAttestation.payload.cnf.jwk.kid}`
|
61
|
-
);
|
62
|
-
}
|
63
|
-
|
64
|
-
return { parsedStatusAttestation };
|
65
|
-
} catch (e) {
|
66
|
-
throw new IoWalletError(
|
67
|
-
`Failed to verify status attestation: ${JSON.stringify(e)}`
|
68
|
-
);
|
69
|
-
}
|
70
|
-
};
|