@pagopa/io-react-native-wallet 0.24.1 → 0.26.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 +0 -32
- package/lib/commonjs/client/generated/wallet-provider.js +39 -16
- package/lib/commonjs/client/generated/wallet-provider.js.map +1 -1
- package/lib/commonjs/client/index.js +25 -10
- package/lib/commonjs/client/index.js.map +1 -1
- package/lib/commonjs/credential/issuance/03-start-user-authorization.js +2 -2
- package/lib/commonjs/credential/issuance/04-complete-user-authorization.js +36 -67
- package/lib/commonjs/credential/issuance/04-complete-user-authorization.js.map +1 -1
- package/lib/commonjs/credential/issuance/05-authorize-access.js +5 -2
- package/lib/commonjs/credential/issuance/05-authorize-access.js.map +1 -1
- package/lib/commonjs/credential/issuance/06-obtain-credential.js +26 -17
- package/lib/commonjs/credential/issuance/06-obtain-credential.js.map +1 -1
- package/lib/commonjs/credential/issuance/README.md +8 -14
- package/lib/commonjs/credential/issuance/errors.js +52 -0
- package/lib/commonjs/credential/issuance/errors.js.map +1 -0
- package/lib/commonjs/credential/issuance/index.js +13 -2
- package/lib/commonjs/credential/issuance/index.js.map +1 -1
- package/lib/commonjs/credential/issuance/types.js +1 -5
- package/lib/commonjs/credential/issuance/types.js.map +1 -1
- package/lib/commonjs/credential/presentation/01-start-flow.js +1 -1
- package/lib/commonjs/credential/presentation/01-start-flow.js.map +1 -1
- package/lib/commonjs/credential/presentation/03-get-request-object.js +2 -2
- package/lib/commonjs/credential/presentation/03-get-request-object.js.map +1 -1
- package/lib/commonjs/credential/presentation/04-send-authorization-response.js +2 -2
- package/lib/commonjs/credential/presentation/04-send-authorization-response.js.map +1 -1
- package/lib/commonjs/credential/presentation/errors.js +49 -0
- package/lib/commonjs/credential/presentation/errors.js.map +1 -0
- package/lib/commonjs/credential/presentation/index.js +5 -0
- package/lib/commonjs/credential/presentation/index.js.map +1 -1
- package/lib/commonjs/credential/status/02-status-attestation.js +8 -6
- package/lib/commonjs/credential/status/02-status-attestation.js.map +1 -1
- package/lib/commonjs/credential/status/README.md +5 -2
- package/lib/commonjs/credential/status/types.js +1 -14
- package/lib/commonjs/credential/status/types.js.map +1 -1
- package/lib/commonjs/sd-jwt/errors.js +40 -0
- package/lib/commonjs/sd-jwt/errors.js.map +1 -0
- package/lib/commonjs/sd-jwt/index.js +8 -4
- package/lib/commonjs/sd-jwt/index.js.map +1 -1
- package/lib/commonjs/sd-jwt/verifier.js +5 -1
- package/lib/commonjs/sd-jwt/verifier.js.map +1 -1
- package/lib/commonjs/trust/index.js +2 -2
- package/lib/commonjs/trust/index.js.map +1 -1
- package/lib/commonjs/utils/decoder.js +3 -1
- package/lib/commonjs/utils/decoder.js.map +1 -1
- package/lib/commonjs/utils/error-codes.js +51 -0
- package/lib/commonjs/utils/error-codes.js.map +1 -0
- package/lib/commonjs/utils/errors.js +119 -463
- package/lib/commonjs/utils/errors.js.map +1 -1
- package/lib/commonjs/utils/misc.js +23 -55
- package/lib/commonjs/utils/misc.js.map +1 -1
- package/lib/commonjs/utils/par.js +2 -1
- package/lib/commonjs/utils/par.js.map +1 -1
- package/lib/commonjs/wallet-instance/README.md +26 -5
- package/lib/commonjs/wallet-instance/index.js +33 -7
- package/lib/commonjs/wallet-instance/index.js.map +1 -1
- package/lib/commonjs/wallet-instance-attestation/README.md +8 -2
- package/lib/commonjs/wallet-instance-attestation/issuing.js +13 -10
- package/lib/commonjs/wallet-instance-attestation/issuing.js.map +1 -1
- package/lib/module/client/generated/wallet-provider.js +31 -11
- package/lib/module/client/generated/wallet-provider.js.map +1 -1
- package/lib/module/client/index.js +22 -8
- package/lib/module/client/index.js.map +1 -1
- package/lib/module/credential/issuance/03-start-user-authorization.js +2 -2
- package/lib/module/credential/issuance/04-complete-user-authorization.js +33 -65
- package/lib/module/credential/issuance/04-complete-user-authorization.js.map +1 -1
- package/lib/module/credential/issuance/05-authorize-access.js +7 -4
- package/lib/module/credential/issuance/05-authorize-access.js.map +1 -1
- package/lib/module/credential/issuance/06-obtain-credential.js +29 -20
- package/lib/module/credential/issuance/06-obtain-credential.js.map +1 -1
- package/lib/module/credential/issuance/README.md +8 -14
- package/lib/module/credential/issuance/errors.js +44 -0
- package/lib/module/credential/issuance/errors.js.map +1 -0
- package/lib/module/credential/issuance/index.js +3 -2
- package/lib/module/credential/issuance/index.js.map +1 -1
- package/lib/module/credential/issuance/types.js +0 -3
- package/lib/module/credential/issuance/types.js.map +1 -1
- package/lib/module/credential/presentation/01-start-flow.js +1 -1
- package/lib/module/credential/presentation/01-start-flow.js.map +1 -1
- package/lib/module/credential/presentation/03-get-request-object.js +3 -3
- package/lib/module/credential/presentation/03-get-request-object.js.map +1 -1
- package/lib/module/credential/presentation/04-send-authorization-response.js +3 -3
- package/lib/module/credential/presentation/04-send-authorization-response.js.map +1 -1
- package/lib/module/credential/presentation/errors.js +42 -0
- package/lib/module/credential/presentation/errors.js.map +1 -0
- package/lib/module/credential/presentation/index.js +2 -1
- package/lib/module/credential/presentation/index.js.map +1 -1
- package/lib/module/credential/status/02-status-attestation.js +11 -9
- package/lib/module/credential/status/02-status-attestation.js.map +1 -1
- package/lib/module/credential/status/README.md +5 -2
- package/lib/module/credential/status/types.js +0 -12
- package/lib/module/credential/status/types.js.map +1 -1
- package/lib/module/sd-jwt/errors.js +32 -0
- package/lib/module/sd-jwt/errors.js.map +1 -0
- package/lib/module/sd-jwt/index.js +5 -5
- package/lib/module/sd-jwt/index.js.map +1 -1
- package/lib/module/sd-jwt/verifier.js +5 -1
- package/lib/module/sd-jwt/verifier.js.map +1 -1
- package/lib/module/trust/index.js +3 -3
- package/lib/module/trust/index.js.map +1 -1
- package/lib/module/utils/decoder.js +3 -1
- package/lib/module/utils/decoder.js.map +1 -1
- package/lib/module/utils/error-codes.js +43 -0
- package/lib/module/utils/error-codes.js.map +1 -0
- package/lib/module/utils/errors.js +98 -438
- package/lib/module/utils/errors.js.map +1 -1
- package/lib/module/utils/misc.js +19 -49
- package/lib/module/utils/misc.js.map +1 -1
- package/lib/module/utils/par.js +3 -2
- package/lib/module/utils/par.js.map +1 -1
- package/lib/module/wallet-instance/README.md +26 -5
- package/lib/module/wallet-instance/index.js +32 -7
- package/lib/module/wallet-instance/index.js.map +1 -1
- package/lib/module/wallet-instance-attestation/README.md +8 -2
- package/lib/module/wallet-instance-attestation/issuing.js +15 -12
- package/lib/module/wallet-instance-attestation/issuing.js.map +1 -1
- package/lib/typescript/client/generated/wallet-provider.d.ts +138 -27
- package/lib/typescript/client/generated/wallet-provider.d.ts.map +1 -1
- package/lib/typescript/client/index.d.ts +7 -1
- package/lib/typescript/client/index.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/03-start-user-authorization.d.ts +2 -2
- package/lib/typescript/credential/issuance/04-complete-user-authorization.d.ts +17 -16
- package/lib/typescript/credential/issuance/04-complete-user-authorization.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/05-authorize-access.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/06-obtain-credential.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/errors.d.ts +28 -0
- package/lib/typescript/credential/issuance/errors.d.ts.map +1 -0
- package/lib/typescript/credential/issuance/index.d.ts +4 -3
- package/lib/typescript/credential/issuance/index.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/types.d.ts +0 -8
- package/lib/typescript/credential/issuance/types.d.ts.map +1 -1
- package/lib/typescript/credential/presentation/03-get-request-object.d.ts.map +1 -1
- package/lib/typescript/credential/presentation/04-send-authorization-response.d.ts.map +1 -1
- package/lib/typescript/credential/presentation/errors.d.ts +25 -0
- package/lib/typescript/credential/presentation/errors.d.ts.map +1 -0
- package/lib/typescript/credential/presentation/index.d.ts +2 -1
- package/lib/typescript/credential/presentation/index.d.ts.map +1 -1
- package/lib/typescript/credential/status/02-status-attestation.d.ts.map +1 -1
- package/lib/typescript/credential/status/types.d.ts +0 -15
- package/lib/typescript/credential/status/types.d.ts.map +1 -1
- package/lib/typescript/sd-jwt/errors.d.ts +20 -0
- package/lib/typescript/sd-jwt/errors.d.ts.map +1 -0
- package/lib/typescript/sd-jwt/index.d.ts +3 -2
- package/lib/typescript/sd-jwt/index.d.ts.map +1 -1
- package/lib/typescript/utils/error-codes.d.ts +45 -0
- package/lib/typescript/utils/error-codes.d.ts.map +1 -0
- package/lib/typescript/utils/errors.d.ts +88 -225
- package/lib/typescript/utils/errors.d.ts.map +1 -1
- package/lib/typescript/utils/misc.d.ts +9 -24
- package/lib/typescript/utils/misc.d.ts.map +1 -1
- package/lib/typescript/utils/par.d.ts.map +1 -1
- package/lib/typescript/wallet-instance/index.d.ts +17 -1
- package/lib/typescript/wallet-instance/index.d.ts.map +1 -1
- package/lib/typescript/wallet-instance-attestation/issuing.d.ts.map +1 -1
- package/lib/typescript/wallet-instance-attestation/types.d.ts +4 -4
- package/package.json +1 -1
- package/src/client/generated/wallet-provider.ts +43 -13
- package/src/client/index.ts +28 -15
- package/src/credential/issuance/03-start-user-authorization.ts +2 -2
- package/src/credential/issuance/04-complete-user-authorization.ts +57 -118
- package/src/credential/issuance/05-authorize-access.ts +7 -4
- package/src/credential/issuance/06-obtain-credential.ts +39 -39
- package/src/credential/issuance/README.md +8 -14
- package/src/credential/issuance/errors.ts +44 -0
- package/src/credential/issuance/index.ts +8 -2
- package/src/credential/issuance/types.ts +0 -8
- package/src/credential/presentation/01-start-flow.ts +1 -1
- package/src/credential/presentation/03-get-request-object.ts +3 -3
- package/src/credential/presentation/04-send-authorization-response.ts +3 -3
- package/src/credential/presentation/errors.ts +41 -0
- package/src/credential/presentation/index.ts +2 -0
- package/src/credential/status/02-status-attestation.ts +17 -25
- package/src/credential/status/README.md +5 -2
- package/src/credential/status/types.ts +0 -15
- package/src/sd-jwt/errors.ts +39 -0
- package/src/sd-jwt/index.ts +5 -8
- package/src/sd-jwt/verifier.ts +5 -5
- package/src/trust/index.ts +3 -3
- package/src/utils/decoder.ts +3 -3
- package/src/utils/error-codes.ts +50 -0
- package/src/utils/errors.ts +152 -476
- package/src/utils/misc.ts +21 -65
- package/src/utils/par.ts +3 -2
- package/src/wallet-instance/README.md +26 -5
- package/src/wallet-instance/index.ts +40 -18
- package/src/wallet-instance-attestation/README.md +8 -2
- package/src/wallet-instance-attestation/issuing.ts +28 -36
package/src/utils/misc.ts
CHANGED
|
@@ -2,25 +2,36 @@ import { IoWalletError, UnexpectedStatusCodeError } from "./errors";
|
|
|
2
2
|
import { sha256 } from "js-sha256";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Check if a response is in the expected status,
|
|
5
|
+
* Check if a response is in the expected status, otherwise throw an error
|
|
6
6
|
* @param status - The expected status
|
|
7
|
-
* @
|
|
7
|
+
* @param customError - A custom error compatible with {@link UnexpectedStatusCodeError}
|
|
8
|
+
* @throws UnexpectedStatusCodeError if the status is different from the one expected
|
|
8
9
|
* @returns The given response object
|
|
9
10
|
*/
|
|
10
|
-
export const
|
|
11
|
-
(status: number) =>
|
|
11
|
+
export const hasStatusOrThrow =
|
|
12
|
+
(status: number, customError?: typeof UnexpectedStatusCodeError) =>
|
|
12
13
|
async (res: Response): Promise<Response> => {
|
|
13
14
|
if (res.status !== status) {
|
|
14
|
-
const
|
|
15
|
-
throw new
|
|
16
|
-
`Http request failed. Expected ${status}, got ${res.status}, url: ${res.url}
|
|
17
|
-
res.status,
|
|
18
|
-
|
|
19
|
-
);
|
|
15
|
+
const ErrorClass = customError ?? UnexpectedStatusCodeError;
|
|
16
|
+
throw new ErrorClass({
|
|
17
|
+
message: `Http request failed. Expected ${status}, got ${res.status}, url: ${res.url}`,
|
|
18
|
+
statusCode: res.status,
|
|
19
|
+
reason: await parseRawHttpResponse(res), // Pass the response body as reason so the original error can surface
|
|
20
|
+
});
|
|
20
21
|
}
|
|
21
22
|
return res;
|
|
22
23
|
};
|
|
23
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Utility function to parse a raw HTTP response as JSON if supported, otherwise as text.
|
|
27
|
+
*/
|
|
28
|
+
export const parseRawHttpResponse = <T extends Record<string, unknown>>(
|
|
29
|
+
response: Response
|
|
30
|
+
) =>
|
|
31
|
+
response.headers.get("content-type")?.includes("application/json")
|
|
32
|
+
? (response.json() as Promise<T>)
|
|
33
|
+
: response.text();
|
|
34
|
+
|
|
24
35
|
// extract a type from an async function output
|
|
25
36
|
// helpful to bind the input of a function to the output of another
|
|
26
37
|
export type Out<FN> = FN extends (...args: any[]) => Promise<any>
|
|
@@ -39,39 +50,6 @@ export const generateRandomAlphaNumericString = (size: number) =>
|
|
|
39
50
|
Math.floor(Math.random() * 36).toString(36)
|
|
40
51
|
).join("");
|
|
41
52
|
|
|
42
|
-
/**
|
|
43
|
-
* Repeatedly checks a condition function until it returns true,
|
|
44
|
-
* then resolves the returned promise. If the condition function does not return true
|
|
45
|
-
* within the specified timeout, the promise is rejected.
|
|
46
|
-
*
|
|
47
|
-
* @param conditionFunction - A function that returns a boolean value.
|
|
48
|
-
* The promise resolves when this function returns true.
|
|
49
|
-
* @param timeout - An optional timeout in seconds. The promise is rejected if the
|
|
50
|
-
* condition function does not return true within this time.
|
|
51
|
-
* @returns A promise that resolves once the conditionFunction returns true or rejects if timed out.
|
|
52
|
-
*/
|
|
53
|
-
export const until = (
|
|
54
|
-
conditionFunction: () => boolean,
|
|
55
|
-
timeoutSeconds?: number
|
|
56
|
-
): Promise<void> =>
|
|
57
|
-
new Promise<void>((resolve, reject) => {
|
|
58
|
-
const start = Date.now();
|
|
59
|
-
const poll = () => {
|
|
60
|
-
if (conditionFunction()) {
|
|
61
|
-
resolve();
|
|
62
|
-
} else if (
|
|
63
|
-
timeoutSeconds !== undefined &&
|
|
64
|
-
Date.now() - start >= timeoutSeconds * 1000
|
|
65
|
-
) {
|
|
66
|
-
reject(new Error("Timeout exceeded"));
|
|
67
|
-
} else {
|
|
68
|
-
setTimeout(poll, 400);
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
poll();
|
|
73
|
-
});
|
|
74
|
-
|
|
75
53
|
/**
|
|
76
54
|
* Get the hash of a credential without discloures.
|
|
77
55
|
* A credential is a string like `header.body.sign~sd1~sd2....` where `~` is the separator between the credential and the discloures.
|
|
@@ -88,28 +66,6 @@ export const getCredentialHashWithouDiscloures = async (
|
|
|
88
66
|
return sha256(credential.slice(0, tildeIndex));
|
|
89
67
|
};
|
|
90
68
|
|
|
91
|
-
/**
|
|
92
|
-
* Creates a promise that waits until the provided signal is aborted.
|
|
93
|
-
* @returns {Object} An object with `listen` and `remove` methods to handle subscribing and unsubscribing.
|
|
94
|
-
*/
|
|
95
|
-
export const createAbortPromiseFromSignal = (signal: AbortSignal) => {
|
|
96
|
-
let listener: () => void;
|
|
97
|
-
return {
|
|
98
|
-
listen: () =>
|
|
99
|
-
new Promise<"OPERATION_ABORTED">((resolve) => {
|
|
100
|
-
if (signal.aborted) {
|
|
101
|
-
return resolve("OPERATION_ABORTED");
|
|
102
|
-
}
|
|
103
|
-
listener = () => resolve("OPERATION_ABORTED");
|
|
104
|
-
signal.addEventListener("abort", listener);
|
|
105
|
-
}),
|
|
106
|
-
remove: () => signal.removeEventListener("abort", listener),
|
|
107
|
-
};
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
export const isDefined = <T>(x: T | undefined | null | ""): x is T =>
|
|
111
|
-
Boolean(x);
|
|
112
|
-
|
|
113
69
|
export const safeJsonParse = <T>(text: string, withDefault?: T): T | null => {
|
|
114
70
|
try {
|
|
115
71
|
return JSON.parse(text);
|
package/src/utils/par.ts
CHANGED
|
@@ -6,8 +6,9 @@ import {
|
|
|
6
6
|
import uuid from "react-native-uuid";
|
|
7
7
|
import * as z from "zod";
|
|
8
8
|
import * as WalletInstanceAttestation from "../wallet-instance-attestation";
|
|
9
|
-
import { generateRandomAlphaNumericString,
|
|
9
|
+
import { generateRandomAlphaNumericString, hasStatusOrThrow } from "./misc";
|
|
10
10
|
import { createPopToken } from "./pop";
|
|
11
|
+
import { IssuerResponseError } from "./errors";
|
|
11
12
|
|
|
12
13
|
export type AuthorizationDetail = z.infer<typeof AuthorizationDetail>;
|
|
13
14
|
export const AuthorizationDetail = z.object({
|
|
@@ -109,7 +110,7 @@ export const makeParRequest =
|
|
|
109
110
|
},
|
|
110
111
|
body: formBody.toString(),
|
|
111
112
|
})
|
|
112
|
-
.then(
|
|
113
|
+
.then(hasStatusOrThrow(201, IssuerResponseError))
|
|
113
114
|
.then((res) => res.json())
|
|
114
115
|
.then((result) => result.request_uri);
|
|
115
116
|
};
|
|
@@ -6,7 +6,8 @@ The suggested way to implement this service is to use [io-react-native-integrity
|
|
|
6
6
|
|
|
7
7
|
The following methods are available:
|
|
8
8
|
- `createWalletInstance` creates a new wallet instance;
|
|
9
|
-
- `
|
|
9
|
+
- `revokeWalletInstance` revokes a wallet instance by ID;
|
|
10
|
+
- `getWalletInstanceStatus` fetches the status of a wallet instance by ID without the need to require an attestation.
|
|
10
11
|
|
|
11
12
|
Examples are provided as follows:
|
|
12
13
|
|
|
@@ -35,12 +36,29 @@ return integrityKeyTag;
|
|
|
35
36
|
|
|
36
37
|
The returned `integrityKeyTag` is supposed to be stored and used to verify the integrity of the device in the future when using an `IntegrityContext` object. It must be regenerated if another wallet instance is created.
|
|
37
38
|
|
|
38
|
-
### Wallet
|
|
39
|
+
### Wallet Instance revocation
|
|
40
|
+
|
|
41
|
+
Revoke a Wallet Instance by ID. The ID matches the hardware/integrity key tag used for creation.
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
const { WALLET_PROVIDER_BASE_URL } = env;
|
|
45
|
+
|
|
46
|
+
await WalletInstance.revokeWalletInstance({
|
|
47
|
+
id: "495e5bec-b93f-4fd7-952a-94b27233abdb"
|
|
48
|
+
walletProviderBaseUrl: WALLET_PROVIDER_BASE_URL,
|
|
49
|
+
appFetch,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
### Wallet Instance status
|
|
54
|
+
|
|
55
|
+
Get the status of a Wallet Instance by ID. The ID matches the hardware/integrity key tag used for creation.
|
|
39
56
|
|
|
40
57
|
```ts
|
|
41
58
|
const { WALLET_PROVIDER_BASE_URL } = env;
|
|
42
59
|
|
|
43
|
-
await WalletInstance.
|
|
60
|
+
const status = await WalletInstance.getWalletInstanceStatus({
|
|
61
|
+
id: "495e5bec-b93f-4fd7-952a-94b27233abdb"
|
|
44
62
|
walletProviderBaseUrl: WALLET_PROVIDER_BASE_URL,
|
|
45
63
|
appFetch,
|
|
46
64
|
});
|
|
@@ -48,6 +66,9 @@ await WalletInstance.revokeCurrentWalletInstance({
|
|
|
48
66
|
|
|
49
67
|
## Mapped results
|
|
50
68
|
|
|
51
|
-
|
|
69
|
+
The following errors are mapped to a `WalletProviderResponseError` with specific codes.
|
|
52
70
|
|
|
53
|
-
|
|
71
|
+
|HTTP Status|Error Code|Description|
|
|
72
|
+
|-----------|----------|-----------|
|
|
73
|
+
|`409 Conflict`|`ERR_IO_WALLET_INSTANCE_INTEGRITY_FAILED`|This response is returned by the wallet provider when an integrity check fails.|
|
|
74
|
+
|`*`|`ERR_IO_WALLET_PROVIDER_GENERIC_ERROR`|This is a generic error code to map unexpected errors that occurred when interacting with the Wallet Provider.|
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { getWalletProviderClient } from "../client";
|
|
2
|
-
import type { IntegrityContext } from "..";
|
|
3
2
|
import {
|
|
4
|
-
|
|
5
|
-
WalletInstanceCreationIntegrityError,
|
|
3
|
+
ResponseErrorBuilder,
|
|
6
4
|
WalletProviderResponseError,
|
|
5
|
+
WalletProviderResponseErrorCodes,
|
|
7
6
|
} from "../utils/errors";
|
|
7
|
+
import type { WalletInstanceData } from "../client/generated/wallet-provider";
|
|
8
|
+
import type { IntegrityContext } from "..";
|
|
8
9
|
|
|
9
10
|
export async function createWalletInstance(context: {
|
|
10
11
|
integrityContext: IntegrityContext;
|
|
@@ -40,28 +41,49 @@ const handleCreateWalletInstanceError = (e: unknown) => {
|
|
|
40
41
|
throw e;
|
|
41
42
|
}
|
|
42
43
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
e
|
|
54
|
-
e.reason
|
|
55
|
-
);
|
|
44
|
+
throw new ResponseErrorBuilder(WalletProviderResponseError)
|
|
45
|
+
.handle(409, {
|
|
46
|
+
code: WalletProviderResponseErrorCodes.WalletInstanceIntegrityFailed,
|
|
47
|
+
message:
|
|
48
|
+
"Unable to create a wallet instance with a device that failed the integrity check",
|
|
49
|
+
})
|
|
50
|
+
.handle("*", {
|
|
51
|
+
code: WalletProviderResponseErrorCodes.WalletInstanceCreationFailed,
|
|
52
|
+
message: "Unable to create wallet instance",
|
|
53
|
+
})
|
|
54
|
+
.buildFrom(e);
|
|
56
55
|
};
|
|
57
56
|
|
|
58
|
-
|
|
57
|
+
/**
|
|
58
|
+
* Revoke a Wallet Instance by ID.
|
|
59
|
+
* @param context.id The Wallet Instance ID. It matches the hardware key tag used for creation.
|
|
60
|
+
*/
|
|
61
|
+
export async function revokeWalletInstance(context: {
|
|
62
|
+
id: string;
|
|
59
63
|
walletProviderBaseUrl: string;
|
|
60
64
|
appFetch?: GlobalFetch["fetch"];
|
|
61
65
|
}): Promise<void> {
|
|
62
66
|
const api = getWalletProviderClient(context);
|
|
63
67
|
|
|
64
|
-
await api.put("/wallet-instances/
|
|
68
|
+
await api.put("/wallet-instances/{id}/status", {
|
|
69
|
+
path: { id: context.id },
|
|
65
70
|
body: { status: "REVOKED" },
|
|
66
71
|
});
|
|
67
72
|
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Get the status of a Wallet Instance by ID.
|
|
76
|
+
* @param context.id The Wallet Instance ID. It matches the hardware key tag used for creation.
|
|
77
|
+
* @returns Details on the status of the Wallet Instance
|
|
78
|
+
*/
|
|
79
|
+
export async function getWalletInstanceStatus(context: {
|
|
80
|
+
id: string;
|
|
81
|
+
walletProviderBaseUrl: string;
|
|
82
|
+
appFetch?: GlobalFetch["fetch"];
|
|
83
|
+
}): Promise<WalletInstanceData> {
|
|
84
|
+
const api = getWalletProviderClient(context);
|
|
85
|
+
|
|
86
|
+
return api.get("/wallet-instances/{id}/status", {
|
|
87
|
+
path: { id: context.id },
|
|
88
|
+
});
|
|
89
|
+
}
|
|
@@ -36,6 +36,12 @@ The returned `issuedAttestation` is supposed to be stored and used for any futur
|
|
|
36
36
|
|
|
37
37
|
## Mapped results
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
The following errors are mapped to a `WalletProviderResponseError` with specific codes.
|
|
40
|
+
|
|
41
|
+
|HTTP Status|Error Code|Description|
|
|
42
|
+
|-----------|----------|-----------|
|
|
43
|
+
|`403 Forbidden`|`ERR_IO_WALLET_INSTANCE_REVOKED`|This response is returned by the wallet provider when the wallet instance has been revoked.|
|
|
44
|
+
|`404 Not Found`|`ERR_IO_WALLET_INSTANCE_NOT_FOUND`|This response is returned by the wallet provider when the wallet instance does not exist.|
|
|
45
|
+
|`409 Conflict`|`ERR_IO_WALLET_INSTANCE_INTEGRITY_FAILED`|This response is returned by the wallet provider when an integrity check fails.|
|
|
46
|
+
|`*`|`ERR_IO_WALLET_PROVIDER_GENERIC_ERROR`|This is a generic error code to map unexpected errors that occurred when interacting with the Wallet Provider.|
|
|
40
47
|
|
|
41
|
-
A `409 Conflict` response is returned by the wallet provider when an integrity check fails.
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
type CryptoContext,
|
|
3
|
+
SignJWT,
|
|
4
|
+
thumbprint,
|
|
5
|
+
} from "@pagopa/io-react-native-jwt";
|
|
6
|
+
import { fixBase64EncodingOnKey, JWK } from "../utils/jwk";
|
|
4
7
|
import { getWalletProviderClient } from "../client";
|
|
5
8
|
import type { IntegrityContext } from "..";
|
|
6
9
|
import {
|
|
10
|
+
ResponseErrorBuilder,
|
|
7
11
|
WalletProviderResponseError,
|
|
8
|
-
|
|
9
|
-
WalletInstanceNotFoundError,
|
|
10
|
-
WalletInstanceAttestationIssuingError,
|
|
11
|
-
WalletInstanceIntegrityFailedError,
|
|
12
|
+
WalletProviderResponseErrorCodes,
|
|
12
13
|
} from "../utils/errors";
|
|
13
14
|
import { TokenResponse } from "./types";
|
|
14
15
|
|
|
@@ -120,33 +121,24 @@ const handleAttestationCreationError = (e: unknown) => {
|
|
|
120
121
|
throw e;
|
|
121
122
|
}
|
|
122
123
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
e.reason
|
|
144
|
-
);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
throw new WalletInstanceAttestationIssuingError(
|
|
148
|
-
`Unable to obtain wallet instance attestation [response status code: ${e.statusCode}]`,
|
|
149
|
-
e.claim,
|
|
150
|
-
e.reason
|
|
151
|
-
);
|
|
124
|
+
throw new ResponseErrorBuilder(WalletProviderResponseError)
|
|
125
|
+
.handle(403, {
|
|
126
|
+
code: WalletProviderResponseErrorCodes.WalletInstanceRevoked,
|
|
127
|
+
message: "Unable to get an attestation for a revoked Wallet Instance",
|
|
128
|
+
})
|
|
129
|
+
.handle(404, {
|
|
130
|
+
code: WalletProviderResponseErrorCodes.WalletInstanceNotFound,
|
|
131
|
+
message:
|
|
132
|
+
"Unable to get an attestation for a Wallet Instance that does not exist",
|
|
133
|
+
})
|
|
134
|
+
.handle(409, {
|
|
135
|
+
code: WalletProviderResponseErrorCodes.WalletInstanceIntegrityFailed,
|
|
136
|
+
message:
|
|
137
|
+
"Unable to get an attestation for a Wallet Instance that failed the integrity check",
|
|
138
|
+
})
|
|
139
|
+
.handle("*", {
|
|
140
|
+
code: WalletProviderResponseErrorCodes.WalletInstanceAttestationIssuingFailed,
|
|
141
|
+
message: "Unable to obtain wallet instance attestation",
|
|
142
|
+
})
|
|
143
|
+
.buildFrom(e);
|
|
152
144
|
};
|