@pagopa/io-react-native-iso18013 0.4.0 → 0.6.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 +8 -2
- 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,5 +1,4 @@
|
|
|
1
|
-
import type { AcceptedFields } from '
|
|
2
|
-
import type { RequestedDocument } from '../types';
|
|
1
|
+
import type { AcceptedFields, RequestedDocument } from '../types';
|
|
3
2
|
/**
|
|
4
3
|
* Events emitted by the native module:
|
|
5
4
|
* - `onDeviceConnecting`: (iOS only) Emitted when the device is connecting to the verifier app.
|
|
@@ -35,10 +34,12 @@ export declare enum ErrorCode {
|
|
|
35
34
|
}
|
|
36
35
|
/**
|
|
37
36
|
* Starts the proximity flow by allocating the necessary resources and initializing the Bluetooth stack.
|
|
37
|
+
* Resolves to true or rejects in case of error.
|
|
38
38
|
* @param config.peripheralMode (Android only) - Whether the device is in peripheral mode. Defaults to true
|
|
39
39
|
* @param config.centralClientMode (Android only) - Whether the device is in central client mode. Defaults to false
|
|
40
40
|
* @param config.clearBleCache (Android only) - Whether the BLE cache should be cleared. Defaults to true
|
|
41
41
|
* @param config.certificates - Two-dimensional array of base64 strings representing DER encoded X.509 certificate which are used to authenticate the verifier app
|
|
42
|
+
* @throws {ModuleError} in case of error which can be parsed with {@link ModuleErrorSchema}
|
|
42
43
|
*/
|
|
43
44
|
export declare function start(config?: {
|
|
44
45
|
peripheralMode?: boolean;
|
|
@@ -47,30 +48,41 @@ export declare function start(config?: {
|
|
|
47
48
|
certificates?: Array<Array<String>>;
|
|
48
49
|
}): Promise<boolean>;
|
|
49
50
|
/**
|
|
50
|
-
*
|
|
51
|
+
* Creates a QR code to be scanned in order to initialize the presentation.
|
|
52
|
+
* Resolves with a string containing the QR code or rejects in case of error.
|
|
53
|
+
* @throws {ModuleError} in case of error which can be parsed with {@link ModuleErrorSchema}
|
|
51
54
|
*/
|
|
52
55
|
export declare function getQrCodeString(): Promise<string>;
|
|
53
56
|
/**
|
|
54
|
-
* Closes the
|
|
57
|
+
* Closes the bluetooth connection and clears any resource.
|
|
58
|
+
* Resolves to true after closing the connection or rejects in case of error.
|
|
59
|
+
* @throws {ModuleError} in case of error which can be parsed with {@link ModuleErrorSchema}
|
|
55
60
|
*/
|
|
56
61
|
export declare function close(): Promise<boolean>;
|
|
57
62
|
/**
|
|
58
|
-
* Sends an error response to the
|
|
63
|
+
* Sends an error response during the presentation according to the SessionData status codes
|
|
64
|
+
* defined in table 20 of the ISO18013-5 standard.
|
|
65
|
+
* Resolves to true or rejects in case of error.
|
|
59
66
|
* The error code must be one of the `ErrorCode` enum values.
|
|
60
67
|
* @param code - The error code to be sent to the verifier app.
|
|
68
|
+
* @throws {ModuleError} in case of error which can be parsed with {@link ModuleErrorSchema}
|
|
61
69
|
*/
|
|
62
70
|
export declare function sendErrorResponse(code: ErrorCode): Promise<boolean>;
|
|
63
71
|
/**
|
|
64
|
-
* Generates a response
|
|
65
|
-
*
|
|
72
|
+
* Generates a response which can later be sent with {sendResponse} with the provided CBOR documents and the requested attributes.
|
|
73
|
+
* Resolves with a base64 encoded response or rejects in case of error.
|
|
74
|
+
* @param documents - An array of `RequestedDocument` which contains the requested data received from the `onDocumentRequestReceived` event
|
|
66
75
|
* @param acceptedFields - The accepted fields which will be presented to the verifier app. See the type definition for more details.
|
|
76
|
+
* @throws {ModuleError} in case of error which can be parsed with {@link ModuleErrorSchema}
|
|
67
77
|
* @returns A base64 encoded response to be sent to the verifier app via `sendResponse`
|
|
68
78
|
*/
|
|
69
79
|
export declare function generateResponse(documents: Array<RequestedDocument>, acceptedFields: AcceptedFields): Promise<string>;
|
|
70
80
|
/**
|
|
71
|
-
* Sends
|
|
81
|
+
* Sends a response containing the documents and the fields which the user decided to present generated by {@link generateResponse}.
|
|
72
82
|
* Currently there's not evidence of the verifier app responding to this request, thus we don't handle the response.
|
|
83
|
+
* Resolves with a true boolean in case of success or rejects in case of error.
|
|
73
84
|
* @param response - The base64 encoded response to be sent to the verifier app.
|
|
85
|
+
* @throws {ModuleError} in case of failure which can be parsed with {@link ModuleErrorSchema}
|
|
74
86
|
*/
|
|
75
87
|
export declare function sendResponse(response: string): Promise<boolean>;
|
|
76
88
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proximity.d.ts","sourceRoot":"","sources":["../../../../../src/iso18013/iso18013-5/proximity.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"proximity.d.ts","sourceRoot":"","sources":["../../../../../src/iso18013/iso18013-5/proximity.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAIlE;;;;;;;GAOG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,kBAAkB,EAAE,SAAS,CAAC;IAC9B,iBAAiB,EAAE,SAAS,CAAC;IAE7B,yBAAyB,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC;IACzD,oBAAoB,EAAE,SAAS,CAAC;IAChC,OAAO,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC;CACzC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC;AAEzC;;;;GAIG;AACH,oBAAY,SAAS;IACnB,kBAAkB,KAAK;IACvB,aAAa,KAAK;IAClB,kBAAkB,KAAK;CACxB;AAED;;;;;;;;GAQG;AACH,wBAAgB,KAAK,CACnB,MAAM,GAAE;IACN,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,YAAY,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;CAChC,GACL,OAAO,CAAC,OAAO,CAAC,CAalB;AAED;;;;GAIG;AACH,wBAAgB,eAAe,IAAI,OAAO,CAAC,MAAM,CAAC,CAEjD;AAED;;;;GAIG;AACH,wBAAgB,KAAK,IAAI,OAAO,CAAC,OAAO,CAAC,CAExC;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,CAEnE;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,KAAK,CAAC,iBAAiB,CAAC,EACnC,cAAc,EAAE,cAAc,GAC7B,OAAO,CAAC,MAAM,CAAC,CAEjB;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAE/D;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,EAC1C,KAAK,EAAE,CAAC,EACR,QAAQ,EAAE,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,KAAK,IAAI,8CAG3C"}
|
|
@@ -43,28 +43,5 @@ export type VerifierRequest = z.infer<typeof VerifierRequest>;
|
|
|
43
43
|
* @returns The parsed VerifierRequest object
|
|
44
44
|
*/
|
|
45
45
|
export declare const parseVerifierRequest: (input: unknown) => VerifierRequest;
|
|
46
|
-
/**
|
|
47
|
-
* This is the type definition for the accepted fields that will be presented to the verifier app.
|
|
48
|
-
* It contains of a nested object structure, where the outermost key represents the credential doctype.
|
|
49
|
-
* The inner dictionary contains namespaces, and for each namespace, there is another dictionary mapping requested claims to a boolean value,
|
|
50
|
-
* which indicates whether the user is willing to present the corresponding claim. Example:
|
|
51
|
-
* `{
|
|
52
|
-
* "org.iso.18013.5.1.mDL": {
|
|
53
|
-
* "org.iso.18013.5.1": {
|
|
54
|
-
* "hair_colour": true, // Indicates the user is willing to present this claim
|
|
55
|
-
* "given_name_national_character": true,
|
|
56
|
-
* "family_name_national_character": true,
|
|
57
|
-
* "given_name": true,
|
|
58
|
-
* }
|
|
59
|
-
* }
|
|
60
|
-
* }`
|
|
61
|
-
**/
|
|
62
|
-
export type AcceptedFields = {
|
|
63
|
-
[credential: string]: {
|
|
64
|
-
[namespace: string]: {
|
|
65
|
-
[field: string]: boolean;
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
};
|
|
69
46
|
export {};
|
|
70
47
|
//# sourceMappingURL=request.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../../../../src/iso18013/iso18013-5/request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAWxB,QAAA,MAAM,eAAe;;;;;;;;;;;;;;;;EAEnB,CAAC;AAEH;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAE9D;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,GAAI,OAAO,OAAO,KAAG,eAErD,CAAC
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../../../../src/iso18013/iso18013-5/request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAWxB,QAAA,MAAM,eAAe;;;;;;;;;;;;;;;;EAEnB,CAAC;AAEH;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAE9D;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,GAAI,OAAO,OAAO,KAAG,eAErD,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { generateOID4VPDeviceResponse } from './remote';
|
|
2
2
|
export { ModuleErrorSchema, type ModuleError, type ModuleErrorCodes, } from './error';
|
|
3
|
-
export { type RequestedDocument } from '../types';
|
|
3
|
+
export { type RequestedDocument, type AcceptedFields } from '../types';
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/iso18013/iso18013-7/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAC;AACxD,OAAO,EACL,iBAAiB,EACjB,KAAK,WAAW,EAChB,KAAK,gBAAgB,GACtB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/iso18013/iso18013-7/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAC;AACxD,OAAO,EACL,iBAAiB,EACjB,KAAK,WAAW,EAChB,KAAK,gBAAgB,GACtB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,KAAK,iBAAiB,EAAE,KAAK,cAAc,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
+
import type { AcceptedFields } from '../iso18013-5';
|
|
1
2
|
import type { RequestedDocument } from '../types';
|
|
2
3
|
/**
|
|
3
|
-
*
|
|
4
|
-
* @param clientId extracted from OID4VP session
|
|
5
|
-
* @param responseUri extracted from OID4VP session
|
|
6
|
-
* @param authorizationRequestNonce extracted from OID4VP session
|
|
7
|
-
* @param mdocGeneratedNonce
|
|
8
|
-
* @param documents
|
|
9
|
-
* @param
|
|
10
|
-
*
|
|
11
|
-
* @
|
|
12
|
-
* @returns the Device Response in CBOR format
|
|
4
|
+
* Generates a CBOR device response for ISO 18013-7 mDL remote presentation using OID4VP.
|
|
5
|
+
* @param clientId - the client id extracted from OID4VP session
|
|
6
|
+
* @param responseUri - the response URI extracted from OID4VP session
|
|
7
|
+
* @param authorizationRequestNonce - the authorization request nonce extracted from OID4VP session
|
|
8
|
+
* @param mdocGeneratedNonce - the mdoc generated nonce to be generated
|
|
9
|
+
* @param documents - an array of {@link RequestedDocument}
|
|
10
|
+
* @param acceptedFields - a record of claims accepted for disclosure or its stringification extracted from OID4VP session
|
|
11
|
+
* @throws {ModuleError} in case of failure which can be parsed with {@link ModuleErrorSchema}
|
|
12
|
+
* @returns a base64 encoded device response
|
|
13
13
|
*/
|
|
14
|
-
export declare const generateOID4VPDeviceResponse: (clientId: string, responseUri: string, authorizationRequestNonce: string, mdocGeneratedNonce: string, documents: Array<RequestedDocument>,
|
|
14
|
+
export declare const generateOID4VPDeviceResponse: (clientId: string, responseUri: string, authorizationRequestNonce: string, mdocGeneratedNonce: string, documents: Array<RequestedDocument>, acceptedFields: AcceptedFields) => Promise<string>;
|
|
15
15
|
//# sourceMappingURL=remote.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote.d.ts","sourceRoot":"","sources":["../../../../../src/iso18013/iso18013-7/remote.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAElD
|
|
1
|
+
{"version":3,"file":"remote.d.ts","sourceRoot":"","sources":["../../../../../src/iso18013/iso18013-7/remote.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAElD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,4BAA4B,GACvC,UAAU,MAAM,EAChB,aAAa,MAAM,EACnB,2BAA2B,MAAM,EACjC,oBAAoB,MAAM,EAC1B,WAAW,KAAK,CAAC,iBAAiB,CAAC,EACnC,gBAAgB,cAAc,KAC7B,OAAO,CAAC,MAAM,CAShB,CAAC"}
|
|
@@ -13,4 +13,29 @@ export type RequestedDocument = {
|
|
|
13
13
|
alias: string;
|
|
14
14
|
docType: string;
|
|
15
15
|
};
|
|
16
|
+
/**
|
|
17
|
+
* This is the type definition for the accepted fields that will be presented to the verifier app.
|
|
18
|
+
* It contains of a nested object structure, where the outermost key represents the credential doctype.
|
|
19
|
+
* The inner dictionary contains namespaces, and for each namespace, there is another dictionary mapping requested claims to a boolean value,
|
|
20
|
+
* which indicates whether the user is willing to present the corresponding claim. Example:
|
|
21
|
+
* `{
|
|
22
|
+
* "org.iso.18013.5.1.mDL": {
|
|
23
|
+
* "org.iso.18013.5.1": {
|
|
24
|
+
* "hair_colour": true, // Indicates the user is willing to present this claim
|
|
25
|
+
* "given_name_national_character": true,
|
|
26
|
+
* "family_name_national_character": true,
|
|
27
|
+
* "given_name": true,
|
|
28
|
+
* },
|
|
29
|
+
* {...}
|
|
30
|
+
* },
|
|
31
|
+
* {...}
|
|
32
|
+
* }`
|
|
33
|
+
**/
|
|
34
|
+
export type AcceptedFields = {
|
|
35
|
+
[credential: string]: {
|
|
36
|
+
[namespace: string]: {
|
|
37
|
+
[field: string]: boolean;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
};
|
|
16
41
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/iso18013/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/iso18013/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF;;;;;;;;;;;;;;;;;IAiBI;AACJ,MAAM,MAAM,cAAc,GAAG;IAC3B,CAAC,UAAU,EAAE,MAAM,GAAG;QACpB,CAAC,SAAS,EAAE,MAAM,GAAG;YAAE,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAA;SAAE,CAAC;KACnD,CAAC;CACH,CAAC"}
|
package/package.json
CHANGED
package/src/cbor/cbor/README.md
CHANGED
|
@@ -1,92 +1,40 @@
|
|
|
1
|
-
|
|
1
|
+
# CBOR
|
|
2
2
|
|
|
3
3
|
This module provides methods to decode CBOR data into readable objects.
|
|
4
4
|
|
|
5
5
|
```typescript
|
|
6
|
-
import { CBOR } from '@pagopa/io-react-native-
|
|
6
|
+
import { CBOR } from '@pagopa/io-react-native-iso18013';
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
## Methods
|
|
10
10
|
|
|
11
11
|
#### `decode`
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
Returns a `Promise` which resolves to a JSON object, or rejects with an instance of `CborFailure` in case of failure.
|
|
13
|
+
Decodes CBOR data into readable JSON objects.
|
|
15
14
|
|
|
16
15
|
**Note**: this method does not decode nested CBOR objects and therefore complex objects needs additional manual decoding
|
|
17
16
|
|
|
18
17
|
```typescript
|
|
19
|
-
|
|
20
|
-
const decoded = await CBOR.decode('...');
|
|
21
|
-
} catch (e) {
|
|
22
|
-
const { message, userInfo } = e as CborFailure;
|
|
23
|
-
}
|
|
18
|
+
const decoded = await CBOR.decode('...');
|
|
24
19
|
```
|
|
25
20
|
|
|
26
21
|
#### `decodeDocuments`
|
|
27
22
|
|
|
28
|
-
|
|
29
|
-
Returns a promise wich resolves to a [Documents](#documents) object, or rejects with an instance of `CborFailure` in case of failure.
|
|
30
|
-
|
|
31
|
-
```typescript
|
|
32
|
-
try {
|
|
33
|
-
const decoded = await CBOR.decodeDocuments('...');
|
|
34
|
-
} catch (e) {
|
|
35
|
-
const { message, userInfo } = e as CborFailure;
|
|
36
|
-
}
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
### Types
|
|
40
|
-
|
|
41
|
-
#### `Documents`
|
|
42
|
-
|
|
43
|
-
```typescript
|
|
44
|
-
type Documents = {
|
|
45
|
-
status?: number;
|
|
46
|
-
version?: string;
|
|
47
|
-
documents?: Array<MDOC>;
|
|
48
|
-
};
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
#### `MDOC`
|
|
23
|
+
Decodes CBOR data containing MDOC objects.
|
|
52
24
|
|
|
53
25
|
```typescript
|
|
54
|
-
|
|
55
|
-
docType?: DocumentType;
|
|
56
|
-
issuerSigned?: IssuerSigned;
|
|
57
|
-
};
|
|
26
|
+
const decoded = await CBOR.decodeDocuments('...');
|
|
58
27
|
```
|
|
59
28
|
|
|
60
|
-
#### `
|
|
61
|
-
|
|
62
|
-
```typescript
|
|
63
|
-
type IssuerSigned = {
|
|
64
|
-
nameSpaces?: Record<string, Array<DocumentValue>>;
|
|
65
|
-
issuerAuth?: string;
|
|
66
|
-
};
|
|
67
|
-
```
|
|
29
|
+
#### `decodeIssuerSigned`
|
|
68
30
|
|
|
69
|
-
|
|
31
|
+
Decodes CBOR data containing an Issuer Signed object.
|
|
70
32
|
|
|
71
33
|
```typescript
|
|
72
|
-
|
|
73
|
-
digestID?: number;
|
|
74
|
-
random?: string;
|
|
75
|
-
elementIdentifier?: string;
|
|
76
|
-
elementValue?: string;
|
|
77
|
-
};
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
#### `DocumentType`
|
|
81
|
-
|
|
82
|
-
```typescript
|
|
83
|
-
enum DocumentTypeEnum {
|
|
84
|
-
MDL = 'org.iso.18013.5.1.mDL',
|
|
85
|
-
EU_PID = 'eu.europa.ec.eudi.pid.1',
|
|
86
|
-
}
|
|
34
|
+
const decoded = await CBOR.decodeIssuerSigned('...');
|
|
87
35
|
```
|
|
88
36
|
|
|
89
|
-
|
|
37
|
+
## Errors
|
|
90
38
|
|
|
91
39
|
This table contains the list of error codes that can be thrown by the `CBOR` module which are mapped via the `ModuleErrorCodes` type:
|
|
92
40
|
| Type | Platform | Description |
|
package/src/cbor/cbor/decoder.ts
CHANGED
|
@@ -8,15 +8,11 @@ import {
|
|
|
8
8
|
import { coerceToJSON } from './schema.utils';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* Decode base64 encoded CBOR data to JSON object.
|
|
11
|
+
* Decode base64 or base64url encoded CBOR data to JSON object.
|
|
12
|
+
* This method does not handle nested CBOR data, which will need additional parsing.
|
|
12
13
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* **NOTE**: this method does not handle nested CBOR data, which will need additional
|
|
17
|
-
* parsing.
|
|
18
|
-
*
|
|
19
|
-
* @param data - The base64 or base64url encoded CBOR data
|
|
14
|
+
* @param data - The base64 or base64url encoded CBOR string
|
|
15
|
+
* @throws {ModuleError} in case of failure which can be parsed with {@link ModuleErrorSchema}
|
|
20
16
|
* @returns The decoded data as JSON object
|
|
21
17
|
*/
|
|
22
18
|
export const decode = async (data: string): Promise<any> => {
|
|
@@ -25,12 +21,9 @@ export const decode = async (data: string): Promise<any> => {
|
|
|
25
21
|
};
|
|
26
22
|
|
|
27
23
|
/**
|
|
28
|
-
* Decode base64 or base64url encoded CBOR data to
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* an instance of {@link CborFailure}.
|
|
32
|
-
*
|
|
33
|
-
* @param data - The base64 encoded MDOC data
|
|
24
|
+
* Decode base64 or base64url encoded mDOC-CBOR data to a JSON object
|
|
25
|
+
* @param data - The base64 or base64url encoded mDOC-CBOR string
|
|
26
|
+
* @throws {ModuleError} in case of failure which can be parsed with {@link ModuleErrorSchema}
|
|
34
27
|
* @returns The decoded data as mDOC object
|
|
35
28
|
*/
|
|
36
29
|
export const decodeDocuments = async (data: string): Promise<Documents> => {
|
|
@@ -39,18 +32,15 @@ export const decodeDocuments = async (data: string): Promise<Documents> => {
|
|
|
39
32
|
};
|
|
40
33
|
|
|
41
34
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* @param issuerSigned - The base64 or base64url encoded MDOC data
|
|
48
|
-
* @returns The decoded {@link IssuerSigned} contained in the mDOC object
|
|
35
|
+
* Decode base64 or base64url encoded issuerSigned attribute part of an mDOC-CBOR.
|
|
36
|
+
* @param data - The base64 or base64url encoded mDOC-CBOR containing the issuerSigned
|
|
37
|
+
* @throws {ModuleError} in case of failure which can be parsed with {@link ModuleErrorSchema}
|
|
38
|
+
* @returns The decoded {@link IssuerSigned}
|
|
49
39
|
*/
|
|
50
40
|
export const decodeIssuerSigned = async (
|
|
51
|
-
|
|
41
|
+
data: string
|
|
52
42
|
): Promise<IssuerSigned> => {
|
|
53
43
|
const decodedIssuerSignedString =
|
|
54
|
-
await IoReactNativeCbor.decodeIssuerSigned(
|
|
44
|
+
await IoReactNativeCbor.decodeIssuerSigned(data);
|
|
55
45
|
return await IssuerSignedFromString.parseAsync(decodedIssuerSignedString);
|
|
56
46
|
};
|
package/src/cbor/cose/README.md
CHANGED
package/src/cbor/cose/sign.ts
CHANGED
|
@@ -4,19 +4,20 @@ import { IoReactNativeCbor } from '..';
|
|
|
4
4
|
/**
|
|
5
5
|
* Sign base64 encoded data with COSE and return the COSE-Sign1 object in base64 encoding
|
|
6
6
|
*
|
|
7
|
-
* @param
|
|
7
|
+
* @param data - The base64 or base64url encoded payload to sign
|
|
8
8
|
* @param keyTag - The alias of the key to use for signing.
|
|
9
|
-
* @throws {
|
|
9
|
+
* @throws {ModuleError} in case of failure which can be parsed with {@link ModuleErrorSchema}
|
|
10
10
|
* @returns The COSE-Sign1 object in base64 encoding
|
|
11
11
|
*/
|
|
12
|
-
export const sign = async (
|
|
13
|
-
await IoReactNativeCbor.sign(
|
|
12
|
+
export const sign = async (data: string, keyTag: string): Promise<string> =>
|
|
13
|
+
await IoReactNativeCbor.sign(data, keyTag);
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Verifies a COSE-Sign1 object with the provided public key
|
|
17
17
|
*
|
|
18
18
|
* @param data - The COSE-Sign1 object in base64 or base64url encoding
|
|
19
19
|
* @param publicKey - The public key in JWK format
|
|
20
|
+
* @throws {ModuleError} in case of failure which can be parsed with {@link ModuleErrorSchema}
|
|
20
21
|
* @returns true if the signature is valid, false otherwise
|
|
21
22
|
*/
|
|
22
23
|
export const verify = async (
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
# ISO18013-5
|
|
2
2
|
|
|
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 proximity presentation according to the
|
|
4
|
-
ISO 18013-5 standard and remote presentation according to the ISO 18013-7 standard.
|
|
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 proximity presentation according to the ISO 18013-5 standard.
|
|
5
4
|
|
|
6
5
|
## Installation
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
```
|
|
8
|
+
yarn add @pagopa/io-react-native-iso18013
|
|
9
|
+
cd ios && bundle exec pod install && cd ..
|
|
10
|
+
```
|
|
9
11
|
|
|
10
|
-
|
|
12
|
+
## Events
|
|
11
13
|
|
|
12
14
|
This library emits the following events:
|
|
13
15
|
| Event | Payload | Description |
|
|
@@ -15,9 +17,29 @@ This library emits the following events:
|
|
|
15
17
|
| onDeviceConnecting (iOS only) | `undefined` | Event dispatched when the verifier app is connecting |
|
|
16
18
|
| onDeviceConnected | `undefined` | Event dispatched when the verifier app is connected. |
|
|
17
19
|
| onDocumentRequestReceived | `{ data: string } \| undefined` | Event dispatched when the consumer app receives a new request, contained in the data payload. It can be parsed via the `parseVerifierRequest` provided [here](src/schema.ts). |
|
|
18
|
-
| onDeviceDisconnected | `undefined` | Event dispatched when the verifier app disconnects. |
|
|
20
|
+
| onDeviceDisconnected | `undefined` | Event dispatched when the verifier app disconnects by sending the END (0x02) flag. |
|
|
19
21
|
| onError | `{ error: string } \| undefined` | Event dispatched when an error occurs which is contained in the error payload. It can be parsed via the `parseError` provided [here](src/schema.ts). |
|
|
20
22
|
|
|
23
|
+
The events flow is described in the following diagram:
|
|
24
|
+
|
|
25
|
+
```mermaid
|
|
26
|
+
flowchart LR
|
|
27
|
+
onDeviceConnecting["onDeviceConnecting *(iOS only)*"]
|
|
28
|
+
onDeviceConnected["onDeviceConnected"]
|
|
29
|
+
onDocumentRequestReceived["onDocumentRequestReceived"]
|
|
30
|
+
onDeviceDisconnected["onDeviceDisconnected"]
|
|
31
|
+
onError["onError"]
|
|
32
|
+
|
|
33
|
+
onDeviceConnecting -- "Verifier app connects" --> onDeviceConnected
|
|
34
|
+
|
|
35
|
+
onDeviceConnected -- "Verifier app sends request" --> onDocumentRequestReceived
|
|
36
|
+
onDeviceConnected -- "Verifier sends END (0x02)" --> onDeviceDisconnected
|
|
37
|
+
onDeviceConnected -- "Error status or abrupt disconnection" --> onError
|
|
38
|
+
|
|
39
|
+
onDocumentRequestReceived -- "Verifier sends END (0x02)" --> onDeviceDisconnected
|
|
40
|
+
onDocumentRequestReceived -- "Error status or abrupt disconnection" --> onError
|
|
41
|
+
```
|
|
42
|
+
|
|
21
43
|
Listeners can be added using the `addListener` method and removed by using the returned reference by calling the `remove` method.
|
|
22
44
|
|
|
23
45
|
```typescript
|
|
@@ -107,7 +129,9 @@ ISO18013_5.addListener(
|
|
|
107
129
|
);
|
|
108
130
|
```
|
|
109
131
|
|
|
110
|
-
|
|
132
|
+
## Methods
|
|
133
|
+
|
|
134
|
+
#### `start`
|
|
111
135
|
|
|
112
136
|
Starts the proximity flow and starts the bluetooth service. This method also accepts optional parameters to configure the initialization on Android, along with the possibility
|
|
113
137
|
to specify a certificates of array to verify the reader app.
|
|
@@ -118,7 +142,7 @@ import { ISO18013_5 } from '@pagopa/io-react-native-iso18013';
|
|
|
118
142
|
await ISO18013_5.start();
|
|
119
143
|
```
|
|
120
144
|
|
|
121
|
-
|
|
145
|
+
#### `getQrCodeString`
|
|
122
146
|
|
|
123
147
|
Returns the QR code string which contains a base64url encoded CBOR object which encodes the bluetooth engagement data.
|
|
124
148
|
It can be used to display the QR code in the UI which will be scanned by the verifier app.
|
|
@@ -130,25 +154,37 @@ const qrCodeString = await ISO18013_5.getQrCodeString();
|
|
|
130
154
|
console.log(qrCodeString);
|
|
131
155
|
```
|
|
132
156
|
|
|
133
|
-
|
|
157
|
+
#### `generateResponse`
|
|
134
158
|
|
|
135
159
|
Generates a response that will be sent to the verifier app containing the requested documents.
|
|
136
160
|
|
|
137
161
|
```typescript
|
|
138
162
|
import { ISO18013_5 } from '@pagopa/io-react-native-iso18013';
|
|
139
163
|
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
164
|
+
const documents = [
|
|
165
|
+
{
|
|
166
|
+
issuerSignedContent: 'base64url-or-base64-encoded-content',
|
|
167
|
+
alias: 'key-alias',
|
|
168
|
+
docType: 'docType',
|
|
169
|
+
},
|
|
170
|
+
];
|
|
171
|
+
|
|
172
|
+
const acceptedFields = {
|
|
173
|
+
'org.iso.18013.5.1.mDL': {
|
|
174
|
+
'org.iso.18013.5.1': {
|
|
175
|
+
hair_colour: true,
|
|
176
|
+
given_name_national_character: true,
|
|
177
|
+
family_name_national_character: true,
|
|
178
|
+
given_name: true,
|
|
145
179
|
},
|
|
146
|
-
|
|
147
|
-
}
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
const response = await ISO18013_5.generateResponse(documents, acceptedFields);
|
|
148
184
|
console.log(response);
|
|
149
185
|
```
|
|
150
186
|
|
|
151
|
-
|
|
187
|
+
#### `sendResponse`
|
|
152
188
|
|
|
153
189
|
Sends the response generate by `generateResponse` to the verifier app.
|
|
154
190
|
|
|
@@ -158,20 +194,17 @@ import { ISO18013_5 } from '@pagopa/io-react-native-iso18013';
|
|
|
158
194
|
await ISO18013_5.sendResponse(response);
|
|
159
195
|
```
|
|
160
196
|
|
|
161
|
-
|
|
197
|
+
#### `sendErrorResponse`
|
|
162
198
|
|
|
163
199
|
Sends an error response to the verifier app. The supported error codes are defined in the Table 20 of the ISO 18013-5 standard and are coded in the `ErrorCode` enum.
|
|
164
200
|
|
|
165
201
|
```typescript
|
|
166
202
|
import { ISO18013_5, ErrorCode } from '@pagopa/io-react-native-iso18013';
|
|
167
203
|
|
|
168
|
-
await ISO18013_5.sendErrorResponse(
|
|
169
|
-
errorCode: ErrorCode.SESSION_ENCRYPTION,
|
|
170
|
-
errorMessage: 'An error occurred while encrypting the session',
|
|
171
|
-
});
|
|
204
|
+
await ISO18013_5.sendErrorResponse(ErrorCode.SESSION_ENCRYPTION);
|
|
172
205
|
```
|
|
173
206
|
|
|
174
|
-
|
|
207
|
+
#### `close`
|
|
175
208
|
|
|
176
209
|
Closes the QR engagement by releasing the resources allocated during the `start` method.
|
|
177
210
|
Before starting a new flow, it is necessary to call this method to ensure that the previous flow is properly closed.
|
|
@@ -183,9 +216,9 @@ import { ISO18013_5 } from '@pagopa/io-react-native-iso18013';
|
|
|
183
216
|
await ISO18013_5.close();
|
|
184
217
|
```
|
|
185
218
|
|
|
186
|
-
## Proximity
|
|
219
|
+
## Proximity Sequence Diagram
|
|
187
220
|
|
|
188
|
-
This section describes a high level overview of the interactions between an app implementing the `io-react-native-proximity` library and a verifier app.
|
|
221
|
+
This section describes a high level overview of the happy flow interactions between an app implementing the `io-react-native-proximity` library and a verifier app.
|
|
189
222
|
|
|
190
223
|
```mermaid
|
|
191
224
|
sequenceDiagram
|
|
@@ -218,8 +251,15 @@ sequenceDiagram
|
|
|
218
251
|
proximity->>+verifier: Sends the error response code
|
|
219
252
|
verifier->>+verifier: Shows the received error response code
|
|
220
253
|
end
|
|
221
|
-
verifier
|
|
222
|
-
|
|
254
|
+
alt The verifier sends the END (0x02) termination flag
|
|
255
|
+
verifier->>+app: Closes the connection
|
|
256
|
+
proximity->>+app: Calls the onDeviceDisconnected callback
|
|
257
|
+
app->>+proximity: Calls close()
|
|
258
|
+
else The verifier app closes the connection without the END (0x02) termination flag
|
|
259
|
+
verifier->>+app: Closes the connection
|
|
260
|
+
proximity->>+app: Calls the onError callback
|
|
261
|
+
app->>+proximity: Calls close()
|
|
262
|
+
end
|
|
223
263
|
```
|
|
224
264
|
|
|
225
265
|
## Errors
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
type AcceptedFields,
|
|
3
|
-
type VerifierRequest,
|
|
4
|
-
parseVerifierRequest,
|
|
5
|
-
} from './request';
|
|
1
|
+
export { type VerifierRequest, parseVerifierRequest } from './request';
|
|
6
2
|
|
|
7
3
|
export {
|
|
8
4
|
type OnErrorPayload,
|
|
@@ -25,4 +21,4 @@ export {
|
|
|
25
21
|
start,
|
|
26
22
|
} from './proximity';
|
|
27
23
|
|
|
28
|
-
export { type RequestedDocument } from '../types';
|
|
24
|
+
export { type RequestedDocument, type AcceptedFields } from '../types';
|