@pagopa/io-react-native-iso18013 0.4.0 → 0.5.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 +10 -5
- package/android/build.gradle +7 -1
- package/android/src/main/java/com/ioreactnativeiso18013/IoReactNativeCborModule.kt +90 -58
- package/android/src/main/java/com/ioreactnativeiso18013/IoReactNativeIso18013Module.kt +216 -100
- package/android/src/test/java/com/ioreactnativeiso18013/Base64UtilsTest.kt +66 -0
- package/android/src/test/java/com/ioreactnativeiso18013/IoReactNativeIso18013Test.kt +508 -0
- package/ios/IoReactNativeCbor.mm +21 -21
- package/ios/IoReactNativeCbor.swift +70 -22
- package/ios/IoReactNativeIso18013.mm +10 -10
- package/ios/IoReactNativeIso18013.swift +89 -81
- package/lib/module/cbor/cbor/README.md +11 -63
- package/lib/module/cbor/cbor/decoder.js +13 -23
- package/lib/module/cbor/cbor/decoder.js.map +1 -1
- package/lib/module/cbor/cose/README.md +1 -1
- package/lib/module/cbor/cose/sign.js +4 -3
- package/lib/module/cbor/cose/sign.js.map +1 -1
- package/lib/module/iso18013/iso18013-5/README.md +66 -26
- package/lib/module/iso18013/iso18013-5/index.js.map +1 -1
- package/lib/module/iso18013/iso18013-5/proximity.js +19 -6
- package/lib/module/iso18013/iso18013-5/proximity.js.map +1 -1
- package/lib/module/iso18013/iso18013-5/request.js +0 -17
- package/lib/module/iso18013/iso18013-5/request.js.map +1 -1
- package/lib/module/iso18013/iso18013-7/README.md +32 -36
- package/lib/module/iso18013/iso18013-7/remote.js +11 -12
- package/lib/module/iso18013/iso18013-7/remote.js.map +1 -1
- package/lib/typescript/src/cbor/cbor/decoder.d.ts +12 -22
- package/lib/typescript/src/cbor/cbor/decoder.d.ts.map +1 -1
- package/lib/typescript/src/cbor/cose/sign.d.ts +4 -3
- package/lib/typescript/src/cbor/cose/sign.d.ts.map +1 -1
- package/lib/typescript/src/iso18013/iso18013-5/index.d.ts +2 -2
- package/lib/typescript/src/iso18013/iso18013-5/index.d.ts.map +1 -1
- package/lib/typescript/src/iso18013/iso18013-5/proximity.d.ts +20 -8
- package/lib/typescript/src/iso18013/iso18013-5/proximity.d.ts.map +1 -1
- package/lib/typescript/src/iso18013/iso18013-5/request.d.ts +0 -23
- package/lib/typescript/src/iso18013/iso18013-5/request.d.ts.map +1 -1
- package/lib/typescript/src/iso18013/iso18013-7/index.d.ts +1 -1
- package/lib/typescript/src/iso18013/iso18013-7/index.d.ts.map +1 -1
- package/lib/typescript/src/iso18013/iso18013-7/remote.d.ts +11 -11
- package/lib/typescript/src/iso18013/iso18013-7/remote.d.ts.map +1 -1
- package/lib/typescript/src/iso18013/types.d.ts +25 -0
- package/lib/typescript/src/iso18013/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/cbor/cbor/README.md +11 -63
- package/src/cbor/cbor/decoder.ts +13 -23
- package/src/cbor/cose/README.md +1 -1
- package/src/cbor/cose/sign.ts +5 -4
- package/src/iso18013/iso18013-5/README.md +66 -26
- package/src/iso18013/iso18013-5/index.ts +2 -6
- package/src/iso18013/iso18013-5/proximity.ts +20 -8
- package/src/iso18013/iso18013-5/request.ts +0 -22
- package/src/iso18013/iso18013-7/README.md +32 -36
- package/src/iso18013/iso18013-7/index.ts +1 -1
- package/src/iso18013/iso18013-7/remote.ts +12 -14
- package/src/iso18013/types.ts +24 -0
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { NativeEventEmitter, Platform } from 'react-native';
|
|
2
|
-
import type { AcceptedFields } from './request';
|
|
3
2
|
import { IoReactNativeIso18013 } from '..';
|
|
4
|
-
import type { RequestedDocument } from '../types';
|
|
3
|
+
import type { AcceptedFields, RequestedDocument } from '../types';
|
|
5
4
|
|
|
6
5
|
const eventEmitter = new NativeEventEmitter(IoReactNativeIso18013);
|
|
7
6
|
|
|
@@ -40,10 +39,12 @@ export enum ErrorCode {
|
|
|
40
39
|
|
|
41
40
|
/**
|
|
42
41
|
* Starts the proximity flow by allocating the necessary resources and initializing the Bluetooth stack.
|
|
42
|
+
* Resolves to true or rejects in case of error.
|
|
43
43
|
* @param config.peripheralMode (Android only) - Whether the device is in peripheral mode. Defaults to true
|
|
44
44
|
* @param config.centralClientMode (Android only) - Whether the device is in central client mode. Defaults to false
|
|
45
45
|
* @param config.clearBleCache (Android only) - Whether the BLE cache should be cleared. Defaults to true
|
|
46
46
|
* @param config.certificates - Two-dimensional array of base64 strings representing DER encoded X.509 certificate which are used to authenticate the verifier app
|
|
47
|
+
* @throws {ModuleError} in case of error which can be parsed with {@link ModuleErrorSchema}
|
|
47
48
|
*/
|
|
48
49
|
export function start(
|
|
49
50
|
config: {
|
|
@@ -68,32 +69,41 @@ export function start(
|
|
|
68
69
|
}
|
|
69
70
|
|
|
70
71
|
/**
|
|
71
|
-
*
|
|
72
|
+
* Creates a QR code to be scanned in order to initialize the presentation.
|
|
73
|
+
* Resolves with a string containing the QR code or rejects in case of error.
|
|
74
|
+
* @throws {ModuleError} in case of error which can be parsed with {@link ModuleErrorSchema}
|
|
72
75
|
*/
|
|
73
76
|
export function getQrCodeString(): Promise<string> {
|
|
74
77
|
return IoReactNativeIso18013.getQrCodeString();
|
|
75
78
|
}
|
|
76
79
|
|
|
77
80
|
/**
|
|
78
|
-
* Closes the
|
|
81
|
+
* Closes the bluetooth connection and clears any resource.
|
|
82
|
+
* Resolves to true after closing the connection or rejects in case of error.
|
|
83
|
+
* @throws {ModuleError} in case of error which can be parsed with {@link ModuleErrorSchema}
|
|
79
84
|
*/
|
|
80
85
|
export function close(): Promise<boolean> {
|
|
81
86
|
return IoReactNativeIso18013.close();
|
|
82
87
|
}
|
|
83
88
|
|
|
84
89
|
/**
|
|
85
|
-
* Sends an error response to the
|
|
90
|
+
* Sends an error response during the presentation according to the SessionData status codes
|
|
91
|
+
* defined in table 20 of the ISO18013-5 standard.
|
|
92
|
+
* Resolves to true or rejects in case of error.
|
|
86
93
|
* The error code must be one of the `ErrorCode` enum values.
|
|
87
94
|
* @param code - The error code to be sent to the verifier app.
|
|
95
|
+
* @throws {ModuleError} in case of error which can be parsed with {@link ModuleErrorSchema}
|
|
88
96
|
*/
|
|
89
97
|
export function sendErrorResponse(code: ErrorCode): Promise<boolean> {
|
|
90
98
|
return IoReactNativeIso18013.sendErrorResponse(code);
|
|
91
99
|
}
|
|
92
100
|
|
|
93
101
|
/**
|
|
94
|
-
* Generates a response
|
|
95
|
-
*
|
|
102
|
+
* Generates a response which can later be sent with {sendResponse} with the provided CBOR documents and the requested attributes.
|
|
103
|
+
* Resolves with a base64 encoded response or rejects in case of error.
|
|
104
|
+
* @param documents - An array of `RequestedDocument` which contains the requested data received from the `onDocumentRequestReceived` event
|
|
96
105
|
* @param acceptedFields - The accepted fields which will be presented to the verifier app. See the type definition for more details.
|
|
106
|
+
* @throws {ModuleError} in case of error which can be parsed with {@link ModuleErrorSchema}
|
|
97
107
|
* @returns A base64 encoded response to be sent to the verifier app via `sendResponse`
|
|
98
108
|
*/
|
|
99
109
|
export function generateResponse(
|
|
@@ -104,9 +114,11 @@ export function generateResponse(
|
|
|
104
114
|
}
|
|
105
115
|
|
|
106
116
|
/**
|
|
107
|
-
* Sends
|
|
117
|
+
* Sends a response containing the documents and the fields which the user decided to present generated by {@link generateResponse}.
|
|
108
118
|
* Currently there's not evidence of the verifier app responding to this request, thus we don't handle the response.
|
|
119
|
+
* Resolves with a true boolean in case of success or rejects in case of error.
|
|
109
120
|
* @param response - The base64 encoded response to be sent to the verifier app.
|
|
121
|
+
* @throws {ModuleError} in case of failure which can be parsed with {@link ModuleErrorSchema}
|
|
110
122
|
*/
|
|
111
123
|
export function sendResponse(response: string): Promise<boolean> {
|
|
112
124
|
return IoReactNativeIso18013.sendResponse(response);
|
|
@@ -43,25 +43,3 @@ export type VerifierRequest = z.infer<typeof VerifierRequest>;
|
|
|
43
43
|
export const parseVerifierRequest = (input: unknown): VerifierRequest => {
|
|
44
44
|
return VerifierRequest.parse(input);
|
|
45
45
|
};
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* This is the type definition for the accepted fields that will be presented to the verifier app.
|
|
49
|
-
* It contains of a nested object structure, where the outermost key represents the credential doctype.
|
|
50
|
-
* The inner dictionary contains namespaces, and for each namespace, there is another dictionary mapping requested claims to a boolean value,
|
|
51
|
-
* which indicates whether the user is willing to present the corresponding claim. Example:
|
|
52
|
-
* `{
|
|
53
|
-
* "org.iso.18013.5.1.mDL": {
|
|
54
|
-
* "org.iso.18013.5.1": {
|
|
55
|
-
* "hair_colour": true, // Indicates the user is willing to present this claim
|
|
56
|
-
* "given_name_national_character": true,
|
|
57
|
-
* "family_name_national_character": true,
|
|
58
|
-
* "given_name": true,
|
|
59
|
-
* }
|
|
60
|
-
* }
|
|
61
|
-
* }`
|
|
62
|
-
**/
|
|
63
|
-
export type AcceptedFields = {
|
|
64
|
-
[credential: string]: {
|
|
65
|
-
[namespace: string]: { [field: string]: boolean };
|
|
66
|
-
};
|
|
67
|
-
};
|
|
@@ -1,51 +1,47 @@
|
|
|
1
|
-
|
|
1
|
+
# ISO18013-7
|
|
2
2
|
|
|
3
|
-
This
|
|
3
|
+
This library provides a React Native module based on [iso18013-android](https://github.com/pagopa/iso18013-android) and [iso18013-ios](https://github.com/pagopa/iso18013-ios) which allows mDL remote presentation according to the ISO 18013-7 standard.
|
|
4
4
|
|
|
5
5
|
```typescript
|
|
6
|
-
import { ISO18013_7 } from '@pagopa/io-react-native-
|
|
6
|
+
import { ISO18013_7 } from '@pagopa/io-react-native-iso18013';
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
## Methods
|
|
10
10
|
|
|
11
11
|
#### `generateOID4VPDeviceResponse`
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
Returns a `Promise` which resolves to a `string` containing the CBOR of the **Device Response** object or rejects with an instance of `CoseFailure` in case of failures.
|
|
13
|
+
Returns a string containing the CBOR of the **Device Response** object.
|
|
16
14
|
|
|
17
15
|
```typescript
|
|
18
|
-
|
|
19
|
-
const result = await ISO18013_7.generateOID4VPDeviceResponse(
|
|
20
|
-
clientId,
|
|
21
|
-
responseUri,
|
|
22
|
-
authorizationRequestNonce,
|
|
23
|
-
mdocGeneratedNonce,
|
|
24
|
-
documents,
|
|
25
|
-
fieldRequestedAndAccepted
|
|
26
|
-
);
|
|
27
|
-
} catch (error: any) {
|
|
28
|
-
const { message, userInfo } = e as CoseFailure;
|
|
29
|
-
}
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
#### Signature
|
|
16
|
+
import { ISO18013_7 } from '@pagopa/io-react-native-iso18013';
|
|
33
17
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
issuerSignedContent
|
|
37
|
-
alias
|
|
38
|
-
docType
|
|
39
|
-
}
|
|
18
|
+
const documents = [
|
|
19
|
+
{
|
|
20
|
+
issuerSignedContent: 'base64url-or-base64-encoded-content',
|
|
21
|
+
alias: 'key-alias',
|
|
22
|
+
docType: 'docType',
|
|
23
|
+
},
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
const acceptedFields = {
|
|
27
|
+
'org.iso.18013.5.1.mDL': {
|
|
28
|
+
'org.iso.18013.5.1': {
|
|
29
|
+
hair_colour: true,
|
|
30
|
+
given_name_national_character: true,
|
|
31
|
+
family_name_national_character: true,
|
|
32
|
+
given_name: true,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
};
|
|
40
36
|
|
|
41
|
-
|
|
42
|
-
clientId
|
|
43
|
-
responseUri
|
|
44
|
-
authorizationRequestNonce
|
|
45
|
-
mdocGeneratedNonce
|
|
46
|
-
documents
|
|
47
|
-
|
|
48
|
-
)
|
|
37
|
+
const result = await ISO18013_7.generateOID4VPDeviceResponse(
|
|
38
|
+
clientId,
|
|
39
|
+
responseUri,
|
|
40
|
+
authorizationRequestNonce,
|
|
41
|
+
mdocGeneratedNonce,
|
|
42
|
+
documents,
|
|
43
|
+
acceptedFields
|
|
44
|
+
);
|
|
49
45
|
```
|
|
50
46
|
|
|
51
47
|
## Errors
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { IoReactNativeIso18013 } from '..';
|
|
2
|
+
import type { AcceptedFields } from '../iso18013-5';
|
|
2
3
|
import type { RequestedDocument } from '../types';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
|
-
*
|
|
6
|
-
* @param clientId extracted from OID4VP session
|
|
7
|
-
* @param responseUri extracted from OID4VP session
|
|
8
|
-
* @param authorizationRequestNonce extracted from OID4VP session
|
|
9
|
-
* @param mdocGeneratedNonce
|
|
10
|
-
* @param documents
|
|
11
|
-
* @param
|
|
12
|
-
*
|
|
13
|
-
* @
|
|
14
|
-
* @returns the Device Response in CBOR format
|
|
6
|
+
* Generates a CBOR device response for ISO 18013-7 mDL remote presentation using OID4VP.
|
|
7
|
+
* @param clientId - the client id extracted from OID4VP session
|
|
8
|
+
* @param responseUri - the response URI extracted from OID4VP session
|
|
9
|
+
* @param authorizationRequestNonce - the authorization request nonce extracted from OID4VP session
|
|
10
|
+
* @param mdocGeneratedNonce - the mdoc generated nonce to be generated
|
|
11
|
+
* @param documents - an array of {@link RequestedDocument}
|
|
12
|
+
* @param acceptedFields - a record of claims accepted for disclosure or its stringification extracted from OID4VP session
|
|
13
|
+
* @throws {ModuleError} in case of failure which can be parsed with {@link ModuleErrorSchema}
|
|
14
|
+
* @returns a base64 encoded device response
|
|
15
15
|
*/
|
|
16
16
|
export const generateOID4VPDeviceResponse = async (
|
|
17
17
|
clientId: string,
|
|
@@ -19,7 +19,7 @@ export const generateOID4VPDeviceResponse = async (
|
|
|
19
19
|
authorizationRequestNonce: string,
|
|
20
20
|
mdocGeneratedNonce: string,
|
|
21
21
|
documents: Array<RequestedDocument>,
|
|
22
|
-
|
|
22
|
+
acceptedFields: AcceptedFields
|
|
23
23
|
): Promise<string> => {
|
|
24
24
|
return await IoReactNativeIso18013.generateOID4VPDeviceResponse(
|
|
25
25
|
clientId,
|
|
@@ -27,8 +27,6 @@ export const generateOID4VPDeviceResponse = async (
|
|
|
27
27
|
authorizationRequestNonce,
|
|
28
28
|
mdocGeneratedNonce,
|
|
29
29
|
documents,
|
|
30
|
-
|
|
31
|
-
? fieldRequestedAndAccepted
|
|
32
|
-
: JSON.stringify(fieldRequestedAndAccepted)
|
|
30
|
+
acceptedFields
|
|
33
31
|
);
|
|
34
32
|
};
|
package/src/iso18013/types.ts
CHANGED
|
@@ -14,3 +14,27 @@ export type RequestedDocument = {
|
|
|
14
14
|
alias: string;
|
|
15
15
|
docType: string;
|
|
16
16
|
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* This is the type definition for the accepted fields that will be presented to the verifier app.
|
|
20
|
+
* It contains of a nested object structure, where the outermost key represents the credential doctype.
|
|
21
|
+
* The inner dictionary contains namespaces, and for each namespace, there is another dictionary mapping requested claims to a boolean value,
|
|
22
|
+
* which indicates whether the user is willing to present the corresponding claim. Example:
|
|
23
|
+
* `{
|
|
24
|
+
* "org.iso.18013.5.1.mDL": {
|
|
25
|
+
* "org.iso.18013.5.1": {
|
|
26
|
+
* "hair_colour": true, // Indicates the user is willing to present this claim
|
|
27
|
+
* "given_name_national_character": true,
|
|
28
|
+
* "family_name_national_character": true,
|
|
29
|
+
* "given_name": true,
|
|
30
|
+
* },
|
|
31
|
+
* {...}
|
|
32
|
+
* },
|
|
33
|
+
* {...}
|
|
34
|
+
* }`
|
|
35
|
+
**/
|
|
36
|
+
export type AcceptedFields = {
|
|
37
|
+
[credential: string]: {
|
|
38
|
+
[namespace: string]: { [field: string]: boolean };
|
|
39
|
+
};
|
|
40
|
+
};
|