@pagopa/io-react-native-iso18013 0.3.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 +69 -134
- package/android/src/main/java/com/ioreactnativeiso18013/IoReactNativeIso18013Module.kt +254 -183
- package/android/src/test/java/com/ioreactnativeiso18013/Base64UtilsTest.kt +66 -0
- package/android/src/test/java/com/ioreactnativeiso18013/IoReactNativeIso18013Test.kt +508 -0
- package/ios/Base64Utils.swift +10 -3
- package/ios/IoReactNativeCbor.mm +21 -21
- package/ios/IoReactNativeCbor.swift +116 -138
- package/ios/IoReactNativeIso18013.mm +10 -10
- package/ios/IoReactNativeIso18013.swift +172 -193
- package/lib/module/cbor/cbor/README.md +39 -59
- package/lib/module/cbor/cbor/decoder.js +13 -23
- package/lib/module/cbor/cbor/decoder.js.map +1 -1
- package/lib/module/cbor/cbor/error.js +15 -0
- package/lib/module/cbor/cbor/error.js.map +1 -0
- package/lib/module/cbor/cbor/index.js +1 -0
- package/lib/module/cbor/cbor/index.js.map +1 -1
- package/lib/module/cbor/cose/README.md +39 -9
- package/lib/module/cbor/cose/error.js +17 -0
- package/lib/module/cbor/cose/error.js.map +1 -0
- package/lib/module/cbor/cose/index.js +1 -0
- package/lib/module/cbor/cose/index.js.map +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/index.js +0 -1
- package/lib/module/iso18013/index.js.map +1 -1
- package/lib/module/iso18013/iso18013-5/README.md +120 -44
- package/lib/module/iso18013/iso18013-5/error.js +25 -0
- package/lib/module/iso18013/iso18013-5/error.js.map +1 -0
- package/lib/module/iso18013/iso18013-5/index.js +3 -2
- package/lib/module/iso18013/iso18013-5/index.js.map +1 -1
- package/lib/module/iso18013/iso18013-5/proximity.js +20 -15
- package/lib/module/iso18013/iso18013-5/proximity.js.map +1 -1
- package/lib/module/iso18013/iso18013-5/{schema.js → request.js} +1 -37
- package/lib/module/iso18013/iso18013-5/request.js.map +1 -0
- package/lib/module/iso18013/iso18013-7/README.md +66 -41
- package/lib/module/iso18013/iso18013-7/error.js +15 -0
- package/lib/module/iso18013/iso18013-7/error.js.map +1 -0
- package/lib/module/iso18013/iso18013-7/index.js +1 -0
- package/lib/module/iso18013/iso18013-7/index.js.map +1 -1
- package/lib/module/iso18013/iso18013-7/remote.js +11 -24
- package/lib/module/iso18013/iso18013-7/remote.js.map +1 -1
- package/lib/module/schema.js +46 -0
- package/lib/module/schema.js.map +1 -0
- 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/cbor/error.d.ts +68 -0
- package/lib/typescript/src/cbor/cbor/error.d.ts.map +1 -0
- package/lib/typescript/src/cbor/cbor/index.d.ts +1 -1
- package/lib/typescript/src/cbor/cbor/index.d.ts.map +1 -1
- package/lib/typescript/src/cbor/cose/error.d.ts +68 -0
- package/lib/typescript/src/cbor/cose/error.d.ts.map +1 -0
- package/lib/typescript/src/cbor/cose/index.d.ts +1 -1
- package/lib/typescript/src/cbor/cose/index.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/index.d.ts +0 -1
- package/lib/typescript/src/iso18013/index.d.ts.map +1 -1
- package/lib/typescript/src/iso18013/iso18013-5/error.d.ts +73 -0
- package/lib/typescript/src/iso18013/iso18013-5/error.d.ts.map +1 -0
- package/lib/typescript/src/iso18013/iso18013-5/index.d.ts +4 -3
- package/lib/typescript/src/iso18013/iso18013-5/index.d.ts.map +1 -1
- package/lib/typescript/src/iso18013/iso18013-5/proximity.d.ts +21 -14
- package/lib/typescript/src/iso18013/iso18013-5/proximity.d.ts.map +1 -1
- package/lib/typescript/src/iso18013/iso18013-5/{schema.d.ts → request.d.ts} +1 -39
- package/lib/typescript/src/iso18013/iso18013-5/request.d.ts.map +1 -0
- package/lib/typescript/src/iso18013/iso18013-7/error.d.ts +68 -0
- package/lib/typescript/src/iso18013/iso18013-7/error.d.ts.map +1 -0
- package/lib/typescript/src/iso18013/iso18013-7/index.d.ts +3 -2
- package/lib/typescript/src/iso18013/iso18013-7/index.d.ts.map +1 -1
- package/lib/typescript/src/iso18013/iso18013-7/remote.d.ts +11 -25
- 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/lib/typescript/src/schema.d.ts +76 -0
- package/lib/typescript/src/schema.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/cbor/cbor/README.md +39 -59
- package/src/cbor/cbor/decoder.ts +13 -23
- package/src/cbor/cbor/error.ts +23 -0
- package/src/cbor/cbor/index.ts +5 -1
- package/src/cbor/cose/README.md +39 -9
- package/src/cbor/cose/error.ts +23 -0
- package/src/cbor/cose/index.ts +5 -1
- package/src/cbor/cose/sign.ts +5 -4
- package/src/iso18013/index.ts +0 -7
- package/src/iso18013/iso18013-5/README.md +120 -44
- package/src/iso18013/iso18013-5/error.ts +35 -0
- package/src/iso18013/iso18013-5/index.ts +9 -8
- package/src/iso18013/iso18013-5/proximity.ts +21 -17
- package/src/iso18013/iso18013-5/{schema.ts → request.ts} +0 -42
- package/src/iso18013/iso18013-7/README.md +66 -41
- package/src/iso18013/iso18013-7/error.ts +21 -0
- package/src/iso18013/iso18013-7/index.ts +6 -5
- package/src/iso18013/iso18013-7/remote.ts +12 -34
- package/src/iso18013/types.ts +24 -0
- package/src/schema.ts +55 -0
- package/lib/module/cbor/cbor/failure.js +0 -2
- package/lib/module/cbor/cbor/failure.js.map +0 -1
- package/lib/module/cbor/cose/failure.js +0 -2
- package/lib/module/cbor/cose/failure.js.map +0 -1
- package/lib/module/iso18013/iso18013-5/schema.js.map +0 -1
- package/lib/typescript/src/cbor/cbor/failure.d.ts +0 -15
- package/lib/typescript/src/cbor/cbor/failure.d.ts.map +0 -1
- package/lib/typescript/src/cbor/cose/failure.d.ts +0 -15
- package/lib/typescript/src/cbor/cose/failure.d.ts.map +0 -1
- package/lib/typescript/src/iso18013/iso18013-5/schema.d.ts.map +0 -1
- package/src/cbor/cbor/failure.ts +0 -18
- package/src/cbor/cose/failure.ts +0 -20
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
export { type VerifierRequest, parseVerifierRequest } from './request';
|
|
2
|
+
|
|
1
3
|
export {
|
|
2
|
-
type
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from './
|
|
4
|
+
type OnErrorPayload,
|
|
5
|
+
OnErrorPayloadSchema,
|
|
6
|
+
ModuleErrorSchema,
|
|
7
|
+
type ModuleErrorCodes,
|
|
8
|
+
type ModuleError,
|
|
9
|
+
} from './error';
|
|
8
10
|
|
|
9
11
|
export {
|
|
10
12
|
ErrorCode,
|
|
@@ -14,10 +16,9 @@ export {
|
|
|
14
16
|
close,
|
|
15
17
|
generateResponse,
|
|
16
18
|
getQrCodeString,
|
|
17
|
-
removeListener,
|
|
18
19
|
sendErrorResponse,
|
|
19
20
|
sendResponse,
|
|
20
21
|
start,
|
|
21
22
|
} from './proximity';
|
|
22
23
|
|
|
23
|
-
export { type RequestedDocument } from '../types';
|
|
24
|
+
export { type RequestedDocument, type AcceptedFields } from '../types';
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { NativeEventEmitter, Platform } from 'react-native';
|
|
2
2
|
import { IoReactNativeIso18013 } from '..';
|
|
3
|
-
import type { AcceptedFields } 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);
|
|
@@ -122,13 +134,5 @@ export function addListener<E extends Events>(
|
|
|
122
134
|
event: E,
|
|
123
135
|
callback: (data: EventsPayload[E]) => void
|
|
124
136
|
) {
|
|
125
|
-
eventEmitter.addListener(event, callback);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Removes a listener for a `QrEngagementEvents` event.
|
|
130
|
-
* @param event - The event to remove the listener for. The available events are defined in the `QrEngagementEvents` type.
|
|
131
|
-
*/
|
|
132
|
-
export function removeListener(event: Events) {
|
|
133
|
-
eventEmitter.removeAllListeners(event);
|
|
137
|
+
return eventEmitter.addListener(event, callback);
|
|
134
138
|
}
|
|
@@ -43,45 +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
|
-
* Zod schema for the type returned by the `onError` event in Proximity `Events`.
|
|
49
|
-
*/
|
|
50
|
-
const EventError = z.string().catch('Unknown error');
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Error type returned by the `onError` event in Proximity `Events`.
|
|
54
|
-
*/
|
|
55
|
-
export type EventError = z.infer<typeof EventError>;
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Parses the input to an Error object.
|
|
59
|
-
* This function is used to parse the error received from the verifier app via the `onError` event.
|
|
60
|
-
* @param input - The input to be parsed
|
|
61
|
-
* @returns The parsed Error object or a default error message if parsing fails
|
|
62
|
-
*/
|
|
63
|
-
export const parseEventError = (input: unknown): EventError => {
|
|
64
|
-
return EventError.parse(input);
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* This is the type definition for the accepted fields that will be presented to the verifier app.
|
|
69
|
-
* It contains of a nested object structure, where the outermost key represents the credential doctype.
|
|
70
|
-
* The inner dictionary contains namespaces, and for each namespace, there is another dictionary mapping requested claims to a boolean value,
|
|
71
|
-
* which indicates whether the user is willing to present the corresponding claim. Example:
|
|
72
|
-
* `{
|
|
73
|
-
* "org.iso.18013.5.1.mDL": {
|
|
74
|
-
* "org.iso.18013.5.1": {
|
|
75
|
-
* "hair_colour": true, // Indicates the user is willing to present this claim
|
|
76
|
-
* "given_name_national_character": true,
|
|
77
|
-
* "family_name_national_character": true,
|
|
78
|
-
* "given_name": true,
|
|
79
|
-
* }
|
|
80
|
-
* }
|
|
81
|
-
* }`
|
|
82
|
-
**/
|
|
83
|
-
export type AcceptedFields = {
|
|
84
|
-
[credential: string]: {
|
|
85
|
-
[namespace: string]: { [field: string]: boolean };
|
|
86
|
-
};
|
|
87
|
-
};
|
|
@@ -1,59 +1,84 @@
|
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
16
|
+
import { ISO18013_7 } from '@pagopa/io-react-native-iso18013';
|
|
17
|
+
|
|
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
|
+
};
|
|
36
|
+
|
|
37
|
+
const result = await ISO18013_7.generateOID4VPDeviceResponse(
|
|
38
|
+
clientId,
|
|
39
|
+
responseUri,
|
|
40
|
+
authorizationRequestNonce,
|
|
41
|
+
mdocGeneratedNonce,
|
|
42
|
+
documents,
|
|
43
|
+
acceptedFields
|
|
44
|
+
);
|
|
30
45
|
```
|
|
31
46
|
|
|
32
|
-
|
|
47
|
+
## Errors
|
|
48
|
+
|
|
49
|
+
This table contains the list of error codes that can be thrown by the `ISO18013_7` module which are mapped via the `ModuleErrorCodes` type:
|
|
50
|
+
|
|
51
|
+
| Type | Platform | Description |
|
|
52
|
+
| ------------------------------ | ----------- | ----------------------------------------------- |
|
|
53
|
+
| GENERATE_OID4VP_RESPONSE_ERROR | Android/iOS | An error occurred while generating the response |
|
|
54
|
+
|
|
55
|
+
An error can be parsed using the `ModuleErrorSchema` with type `ModuleErrorCodes` exposed by the `ISO18013_5` module. The error can be parsed as follows:
|
|
33
56
|
|
|
34
57
|
```typescript
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
58
|
+
import { ISO18013_7 } from '@pagopa/io-react-native-iso18013';
|
|
59
|
+
try {
|
|
60
|
+
await ISO18013_7.func();
|
|
61
|
+
} catch (error) {
|
|
62
|
+
const parsedError = ISO18013_7.ModuleErrorSchema.parse(error); // Or ModuleErrorSchema.safeParse(error) for safe parsing
|
|
63
|
+
console.log(JSON.stringify(parsedError, null, 2));
|
|
39
64
|
}
|
|
40
|
-
|
|
41
|
-
export const generateOID4VPDeviceResponse = async (
|
|
42
|
-
clientId: string,
|
|
43
|
-
responseUri: string,
|
|
44
|
-
authorizationRequestNonce: string,
|
|
45
|
-
mdocGeneratedNonce: string,
|
|
46
|
-
documents: Array<RequestedDocument>,
|
|
47
|
-
fieldRequestedAndAccepted: Record<string, any> | string
|
|
48
|
-
) : Promise<string> => {...};
|
|
49
65
|
```
|
|
50
66
|
|
|
51
|
-
|
|
67
|
+
The parsed object will contain properties from both iOS and Android platforms:
|
|
52
68
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
69
|
+
```typescript
|
|
70
|
+
{
|
|
71
|
+
code: string; // Defined in ModuleErrorCodes
|
|
72
|
+
message: string;
|
|
73
|
+
name: string;
|
|
74
|
+
userInfo?: Record<string, any> | null;
|
|
75
|
+
nativeStackAndroid?: Array<{
|
|
76
|
+
lineNumber: number;
|
|
77
|
+
file: string;
|
|
78
|
+
methodName: string;
|
|
79
|
+
class: string;
|
|
80
|
+
}>;
|
|
81
|
+
domain?: string;
|
|
82
|
+
nativeStackIOS?: Array<string>;
|
|
83
|
+
};
|
|
84
|
+
```
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
import { GenericModuleErrorSchema } from '../../schema';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Error codes which the ISO18013_7 module uses to reject a promise.
|
|
6
|
+
*/
|
|
7
|
+
const ModuleErrorCodesSchema = z.enum([
|
|
8
|
+
'GENERATE_OID4VP_RESPONSE_ERROR',
|
|
9
|
+
'EUNSPECIFIED', // Android only default when no other error is specified
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
export type ModuleErrorCodes = z.infer<typeof ModuleErrorCodesSchema>;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Schema which can be used to parse a rejected promise error by the ISO18013_7 module.
|
|
16
|
+
*/
|
|
17
|
+
export const ModuleErrorSchema = GenericModuleErrorSchema(
|
|
18
|
+
ModuleErrorCodesSchema
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
export type ModuleError = z.infer<typeof ModuleErrorSchema>;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
export { generateOID4VPDeviceResponse } from './remote';
|
|
1
2
|
export {
|
|
2
|
-
|
|
3
|
-
type
|
|
4
|
-
type
|
|
5
|
-
} from './
|
|
3
|
+
ModuleErrorSchema,
|
|
4
|
+
type ModuleError,
|
|
5
|
+
type ModuleErrorCodes,
|
|
6
|
+
} from './error';
|
|
6
7
|
|
|
7
|
-
export { type RequestedDocument } from '../types';
|
|
8
|
+
export { type RequestedDocument, type AcceptedFields } from '../types';
|
|
@@ -1,37 +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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
* Error type returned by a rejected promise.
|
|
15
|
-
*
|
|
16
|
-
* If additional error information are available,
|
|
17
|
-
* they are stored in the {@link OID4VPFailure["userInfo"]} field.
|
|
18
|
-
*/
|
|
19
|
-
export type OID4VPFailure = {
|
|
20
|
-
message: OID4VPFailureCodes;
|
|
21
|
-
userInfo: Record<string, string>;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
*
|
|
26
|
-
* @param clientId extracted from OID4VP session
|
|
27
|
-
* @param responseUri extracted from OID4VP session
|
|
28
|
-
* @param authorizationRequestNonce extracted from OID4VP session
|
|
29
|
-
* @param mdocGeneratedNonce To be generated
|
|
30
|
-
* @param documents An Array of {@link DocRequested}
|
|
31
|
-
* @param fieldRequestedAndAccepted extracted from OID4VP session, it's a record of claims
|
|
32
|
-
* accepted for disclosure or its stringification
|
|
33
|
-
* @throws {OID4VPFailure} in case of failure
|
|
34
|
-
* @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
|
|
35
15
|
*/
|
|
36
16
|
export const generateOID4VPDeviceResponse = async (
|
|
37
17
|
clientId: string,
|
|
@@ -39,7 +19,7 @@ export const generateOID4VPDeviceResponse = async (
|
|
|
39
19
|
authorizationRequestNonce: string,
|
|
40
20
|
mdocGeneratedNonce: string,
|
|
41
21
|
documents: Array<RequestedDocument>,
|
|
42
|
-
|
|
22
|
+
acceptedFields: AcceptedFields
|
|
43
23
|
): Promise<string> => {
|
|
44
24
|
return await IoReactNativeIso18013.generateOID4VPDeviceResponse(
|
|
45
25
|
clientId,
|
|
@@ -47,8 +27,6 @@ export const generateOID4VPDeviceResponse = async (
|
|
|
47
27
|
authorizationRequestNonce,
|
|
48
28
|
mdocGeneratedNonce,
|
|
49
29
|
documents,
|
|
50
|
-
|
|
51
|
-
? fieldRequestedAndAccepted
|
|
52
|
-
: JSON.stringify(fieldRequestedAndAccepted)
|
|
30
|
+
acceptedFields
|
|
53
31
|
);
|
|
54
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
|
+
};
|
package/src/schema.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Schema for parsing a nativeStackAndroid object of a rejected promise error in an Android native module.
|
|
5
|
+
*/
|
|
6
|
+
const StackTraceElementSchema = z.object({
|
|
7
|
+
lineNumber: z.number(),
|
|
8
|
+
file: z.string(),
|
|
9
|
+
methodName: z.string(),
|
|
10
|
+
class: z.string(),
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Schema for parsing specific parameters of a rejected promise error in an Android native module.
|
|
15
|
+
* It's defined as partial to allow merging with the common schema and it must be checked at runtime.
|
|
16
|
+
*/
|
|
17
|
+
const ModuleErrorAndroidSchema = z
|
|
18
|
+
.object({
|
|
19
|
+
nativeStackAndroid: z.array(StackTraceElementSchema),
|
|
20
|
+
})
|
|
21
|
+
.partial();
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Schema for parsing specific parameters of a rejected promise error in an iOS native module.
|
|
25
|
+
* It's defined as partial to allow merging with the common schema and it must be checked at runtime.
|
|
26
|
+
*/
|
|
27
|
+
const ModuleErrorIosSchema = z
|
|
28
|
+
.object({
|
|
29
|
+
domain: z.string(),
|
|
30
|
+
nativeStackIOS: z.array(z.string()),
|
|
31
|
+
})
|
|
32
|
+
.partial();
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Schema for parsing common parameters of a rejected promise error in a native module.
|
|
36
|
+
* This schema contains the common parameters that are shared across both Android and iOS native modules.
|
|
37
|
+
* Parameters which are platform specific are defined as optional and must be checked at runtime.
|
|
38
|
+
* It accepts a generic code schema to allow for different error codes which can be defined in each module.
|
|
39
|
+
* @param codeSchema - The Zod schema for the error codes used by the module.
|
|
40
|
+
* @returns A schema for the common parameters of a rejected promise error in a native module.
|
|
41
|
+
*/
|
|
42
|
+
export const GenericModuleErrorSchema = <
|
|
43
|
+
CodeType extends z.ZodEnum<[string, ...string[]]>,
|
|
44
|
+
>(
|
|
45
|
+
codeSchema: CodeType
|
|
46
|
+
) =>
|
|
47
|
+
z
|
|
48
|
+
.object({
|
|
49
|
+
code: codeSchema,
|
|
50
|
+
message: z.string(),
|
|
51
|
+
name: z.string(),
|
|
52
|
+
userInfo: z.record(z.string(), z.any()).optional().or(z.null()),
|
|
53
|
+
})
|
|
54
|
+
.and(ModuleErrorAndroidSchema)
|
|
55
|
+
.and(ModuleErrorIosSchema);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sourceRoot":"../../../../src","sources":["cbor/cbor/failure.ts"],"mappings":"","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sourceRoot":"../../../../src","sources":["cbor/cose/failure.ts"],"mappings":"","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["z","booleanFieldGroup","record","boolean","credentialEntrySchema","object","isAuthenticated","catchall","VerifierRequest","request","parseVerifierRequest","input","parse","EventError","string","catch","parseEventError"],"sourceRoot":"../../../../src","sources":["iso18013/iso18013-5/schema.ts"],"mappings":";;AAAA,SAASA,CAAC,QAAQ,KAAK;;AAEvB;AACA,MAAMC,iBAAiB,GAAGD,CAAC,CAACE,MAAM,CAACF,CAAC,CAACG,OAAO,CAAC,CAAC,CAAC;AAE/C,MAAMC,qBAAqB,GAAGJ,CAAC,CAC5BK,MAAM,CAAC;EACNC,eAAe,EAAEN,CAAC,CAACG,OAAO,CAAC;AAC7B,CAAC,CAAC,CACDI,QAAQ,CAACN,iBAAiB,CAAC;AAE9B,MAAMO,eAAe,GAAGR,CAAC,CAACK,MAAM,CAAC;EAC/BI,OAAO,EAAET,CAAC,CAACE,MAAM,CAACE,qBAAqB;AACzC,CAAC,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMM,oBAAoB,GAAIC,KAAc,IAAsB;EACvE,OAAOH,eAAe,CAACI,KAAK,CAACD,KAAK,CAAC;AACrC,CAAC;;AAED;AACA;AACA;AACA,MAAME,UAAU,GAAGb,CAAC,CAACc,MAAM,CAAC,CAAC,CAACC,KAAK,CAAC,eAAe,CAAC;;AAEpD;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,eAAe,GAAIL,KAAc,IAAiB;EAC7D,OAAOE,UAAU,CAACD,KAAK,CAACD,KAAK,CAAC;AAChC,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* All error codes that the module could return.
|
|
3
|
-
*/
|
|
4
|
-
export type CborFailureCodes = 'UNABLE_TO_DECODE' | 'INVALID_ENCODING' | 'UNKNOWN_EXCEPTION';
|
|
5
|
-
/**
|
|
6
|
-
* Error type returned by a rejected promise.
|
|
7
|
-
*
|
|
8
|
-
* If additional error information are available,
|
|
9
|
-
* they are stored in the {@link CborFailure["userInfo"]} field.
|
|
10
|
-
*/
|
|
11
|
-
export type CborFailure = {
|
|
12
|
-
message: CborFailureCodes;
|
|
13
|
-
userInfo: Record<string, string>;
|
|
14
|
-
};
|
|
15
|
-
//# sourceMappingURL=failure.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"failure.d.ts","sourceRoot":"","sources":["../../../../../src/cbor/cbor/failure.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,gBAAgB,GACxB,kBAAkB,GAClB,kBAAkB,GAClB,mBAAmB,CAAC;AAExB;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,EAAE,gBAAgB,CAAC;IAC1B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC,CAAC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* All error codes that the module could return.
|
|
3
|
-
*/
|
|
4
|
-
export type CoseFailureCodes = 'PUBLIC_KEY_NOT_FOUND' | 'UNABLE_TO_SIGN' | 'INVALID_ENCODING' | 'THREADING_ERROR' | 'UNKNOWN_EXCEPTION';
|
|
5
|
-
/**
|
|
6
|
-
* Error type returned by a rejected promise.
|
|
7
|
-
*
|
|
8
|
-
* If additional error information are available,
|
|
9
|
-
* they are stored in the {@link CoseError["userInfo"]} field.
|
|
10
|
-
*/
|
|
11
|
-
export type CoseFailure = {
|
|
12
|
-
message: CoseFailureCodes;
|
|
13
|
-
userInfo: Record<string, string>;
|
|
14
|
-
};
|
|
15
|
-
//# sourceMappingURL=failure.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"failure.d.ts","sourceRoot":"","sources":["../../../../../src/cbor/cose/failure.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,gBAAgB,GACxB,sBAAsB,GACtB,gBAAgB,GAChB,kBAAkB,GAClB,iBAAiB,GACjB,mBAAmB,CAAC;AAExB;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,EAAE,gBAAgB,CAAC;IAC1B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../../src/iso18013/iso18013-5/schema.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;AAEF;;GAEG;AACH,QAAA,MAAM,UAAU,yBAAoC,CAAC;AAErD;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,UAAU,CAAC,CAAC;AAEpD;;;;;GAKG;AACH,eAAO,MAAM,eAAe,GAAI,OAAO,OAAO,KAAG,UAEhD,CAAC;AAEF;;;;;;;;;;;;;;;IAeI;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/src/cbor/cbor/failure.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* All error codes that the module could return.
|
|
3
|
-
*/
|
|
4
|
-
export type CborFailureCodes =
|
|
5
|
-
| 'UNABLE_TO_DECODE'
|
|
6
|
-
| 'INVALID_ENCODING'
|
|
7
|
-
| 'UNKNOWN_EXCEPTION';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Error type returned by a rejected promise.
|
|
11
|
-
*
|
|
12
|
-
* If additional error information are available,
|
|
13
|
-
* they are stored in the {@link CborFailure["userInfo"]} field.
|
|
14
|
-
*/
|
|
15
|
-
export type CborFailure = {
|
|
16
|
-
message: CborFailureCodes;
|
|
17
|
-
userInfo: Record<string, string>;
|
|
18
|
-
};
|
package/src/cbor/cose/failure.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* All error codes that the module could return.
|
|
3
|
-
*/
|
|
4
|
-
export type CoseFailureCodes =
|
|
5
|
-
| 'PUBLIC_KEY_NOT_FOUND'
|
|
6
|
-
| 'UNABLE_TO_SIGN'
|
|
7
|
-
| 'INVALID_ENCODING'
|
|
8
|
-
| 'THREADING_ERROR'
|
|
9
|
-
| 'UNKNOWN_EXCEPTION';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Error type returned by a rejected promise.
|
|
13
|
-
*
|
|
14
|
-
* If additional error information are available,
|
|
15
|
-
* they are stored in the {@link CoseError["userInfo"]} field.
|
|
16
|
-
*/
|
|
17
|
-
export type CoseFailure = {
|
|
18
|
-
message: CoseFailureCodes;
|
|
19
|
-
userInfo: Record<string, string>;
|
|
20
|
-
};
|