@pagopa/io-react-native-iso18013 0.1.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/IoReactNativeIso18013.podspec +29 -0
- package/LICENSE +20 -0
- package/README.md +30 -0
- package/android/build.gradle +83 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/com/ioreactnativeiso18013/Base64Utils.kt +56 -0
- package/android/src/main/java/com/ioreactnativeiso18013/IoReactNativeCborModule.kt +209 -0
- package/android/src/main/java/com/ioreactnativeiso18013/IoReactNativeIso18013Module.kt +439 -0
- package/android/src/main/java/com/ioreactnativeiso18013/IoReactNativeIso18013Package.kt +17 -0
- package/ios/Base64Utils.swift +47 -0
- package/ios/IoReactNativeCbor.mm +32 -0
- package/ios/IoReactNativeCbor.swift +188 -0
- package/ios/IoReactNativeIso18013-Bridging-Header.h +2 -0
- package/ios/IoReactNativeIso18013.mm +43 -0
- package/ios/IoReactNativeIso18013.swift +491 -0
- package/lib/module/cbor/cbor/README.md +95 -0
- package/lib/module/cbor/cbor/decoder.js +51 -0
- package/lib/module/cbor/cbor/decoder.js.map +1 -0
- package/lib/module/cbor/cbor/failure.js +2 -0
- package/lib/module/cbor/cbor/failure.js.map +1 -0
- package/lib/module/cbor/cbor/index.js +5 -0
- package/lib/module/cbor/cbor/index.js.map +1 -0
- package/lib/module/cbor/cbor/schema.js +117 -0
- package/lib/module/cbor/cbor/schema.js.map +1 -0
- package/lib/module/cbor/cbor/schema.utils.js +16 -0
- package/lib/module/cbor/cbor/schema.utils.js.map +1 -0
- package/lib/module/cbor/cose/README.md +53 -0
- package/lib/module/cbor/cose/failure.js +2 -0
- package/lib/module/cbor/cose/failure.js.map +1 -0
- package/lib/module/cbor/cose/index.js +4 -0
- package/lib/module/cbor/cose/index.js.map +1 -0
- package/lib/module/cbor/cose/sign.js +23 -0
- package/lib/module/cbor/cose/sign.js.map +1 -0
- package/lib/module/cbor/index.js +13 -0
- package/lib/module/cbor/index.js.map +1 -0
- package/lib/module/index.js +8 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/iso18013/index.js +14 -0
- package/lib/module/iso18013/index.js.map +1 -0
- package/lib/module/iso18013/iso18013-5/README.md +234 -0
- package/lib/module/iso18013/iso18013-5/index.js +5 -0
- package/lib/module/iso18013/iso18013-5/index.js.map +1 -0
- package/lib/module/iso18013/iso18013-5/proximity.js +112 -0
- package/lib/module/iso18013/iso18013-5/proximity.js.map +1 -0
- package/lib/module/iso18013/iso18013-5/schema.js +79 -0
- package/lib/module/iso18013/iso18013-5/schema.js.map +1 -0
- package/lib/module/iso18013/iso18013-7/README.md +59 -0
- package/lib/module/iso18013/iso18013-7/index.js +4 -0
- package/lib/module/iso18013/iso18013-7/index.js.map +1 -0
- package/lib/module/iso18013/iso18013-7/remote.js +31 -0
- package/lib/module/iso18013/iso18013-7/remote.js.map +1 -0
- package/lib/module/iso18013/types.js +2 -0
- package/lib/module/iso18013/types.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/cbor/cbor/decoder.d.ts +35 -0
- package/lib/typescript/src/cbor/cbor/decoder.d.ts.map +1 -0
- package/lib/typescript/src/cbor/cbor/failure.d.ts +15 -0
- package/lib/typescript/src/cbor/cbor/failure.d.ts.map +1 -0
- package/lib/typescript/src/cbor/cbor/index.d.ts +4 -0
- package/lib/typescript/src/cbor/cbor/index.d.ts.map +1 -0
- package/lib/typescript/src/cbor/cbor/schema.d.ts +2420 -0
- package/lib/typescript/src/cbor/cbor/schema.d.ts.map +1 -0
- package/lib/typescript/src/cbor/cbor/schema.utils.d.ts +8 -0
- package/lib/typescript/src/cbor/cbor/schema.utils.d.ts.map +1 -0
- package/lib/typescript/src/cbor/cose/failure.d.ts +15 -0
- package/lib/typescript/src/cbor/cose/failure.d.ts.map +1 -0
- package/lib/typescript/src/cbor/cose/index.d.ts +3 -0
- package/lib/typescript/src/cbor/cose/index.d.ts.map +1 -0
- package/lib/typescript/src/cbor/cose/sign.d.ts +19 -0
- package/lib/typescript/src/cbor/cose/sign.d.ts.map +1 -0
- package/lib/typescript/src/cbor/index.d.ts +2 -0
- package/lib/typescript/src/cbor/index.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +6 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/iso18013/index.d.ts +3 -0
- package/lib/typescript/src/iso18013/index.d.ts.map +1 -0
- package/lib/typescript/src/iso18013/iso18013-5/index.d.ts +4 -0
- package/lib/typescript/src/iso18013/iso18013-5/index.d.ts.map +1 -0
- package/lib/typescript/src/iso18013/iso18013-5/proximity.d.ts +88 -0
- package/lib/typescript/src/iso18013/iso18013-5/proximity.d.ts.map +1 -0
- package/lib/typescript/src/iso18013/iso18013-5/schema.d.ts +85 -0
- package/lib/typescript/src/iso18013/iso18013-5/schema.d.ts.map +1 -0
- package/lib/typescript/src/iso18013/iso18013-7/index.d.ts +3 -0
- package/lib/typescript/src/iso18013/iso18013-7/index.d.ts.map +1 -0
- package/lib/typescript/src/iso18013/iso18013-7/remote.d.ts +29 -0
- package/lib/typescript/src/iso18013/iso18013-7/remote.d.ts.map +1 -0
- package/lib/typescript/src/iso18013/types.d.ts +16 -0
- package/lib/typescript/src/iso18013/types.d.ts.map +1 -0
- package/package.json +163 -0
- package/src/cbor/cbor/README.md +95 -0
- package/src/cbor/cbor/decoder.ts +56 -0
- package/src/cbor/cbor/failure.ts +18 -0
- package/src/cbor/cbor/index.ts +9 -0
- package/src/cbor/cbor/schema.ts +150 -0
- package/src/cbor/cbor/schema.utils.ts +13 -0
- package/src/cbor/cose/README.md +53 -0
- package/src/cbor/cose/failure.ts +20 -0
- package/src/cbor/cose/index.ts +2 -0
- package/src/cbor/cose/sign.ts +25 -0
- package/src/cbor/index.ts +18 -0
- package/src/index.tsx +5 -0
- package/src/iso18013/index.ts +25 -0
- package/src/iso18013/iso18013-5/README.md +234 -0
- package/src/iso18013/iso18013-5/index.ts +23 -0
- package/src/iso18013/iso18013-5/proximity.ts +134 -0
- package/src/iso18013/iso18013-5/schema.ts +87 -0
- package/src/iso18013/iso18013-7/README.md +59 -0
- package/src/iso18013/iso18013-7/index.ts +7 -0
- package/src/iso18013/iso18013-7/remote.ts +54 -0
- package/src/iso18013/types.ts +16 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { NativeEventEmitter, Platform } from 'react-native';
|
|
2
|
+
import { IoReactNativeProximity } from '..';
|
|
3
|
+
import type { AcceptedFields } from './schema';
|
|
4
|
+
import type { RequestedDocument } from '../types';
|
|
5
|
+
|
|
6
|
+
const eventEmitter = new NativeEventEmitter(IoReactNativeProximity);
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Events emitted by the native module:
|
|
10
|
+
* - `onDeviceConnecting`: (iOS only) Emitted when the device is connecting to the verifier app.
|
|
11
|
+
* - `onDeviceConnected`: Emitted when the device is connected to the verifier app.
|
|
12
|
+
* - `onDocumentRequestReceived`: Emitted when a document request is received from the verifier app. Carries a payload containing the request data.
|
|
13
|
+
* - `onDeviceDisconnected`: Emitted when the device is disconnected from the verifier app.
|
|
14
|
+
* - `onError`: Emitted when an error occurs. Carries a payload containing the error data.
|
|
15
|
+
*/
|
|
16
|
+
export type EventsPayload = {
|
|
17
|
+
onDeviceConnecting: undefined;
|
|
18
|
+
onDeviceConnected: undefined;
|
|
19
|
+
// The message payload is a JSON string that can be parsed into a `VerifierRequest` structure via `parseVerifierRequest`.
|
|
20
|
+
onDocumentRequestReceived: { data?: string } | undefined;
|
|
21
|
+
onDeviceDisconnected: undefined;
|
|
22
|
+
onError: { error?: string } | undefined;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Events emitted by the native module.
|
|
27
|
+
*/
|
|
28
|
+
export type Events = keyof EventsPayload;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Error codes that can be used with the `sendErrorResponse` method.
|
|
32
|
+
* These are defined based on the SessionData status code defined in the table 20 of the ISO 18013-5 standard
|
|
33
|
+
* and mirror codes defined in the native module.
|
|
34
|
+
*/
|
|
35
|
+
export enum ErrorCode {
|
|
36
|
+
SESSION_ENCRYPTION = 10,
|
|
37
|
+
CBOR_DECODING = 11,
|
|
38
|
+
SESSION_TERMINATED = 20,
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Starts the proximity flow by allocating the necessary resources and initializing the Bluetooth stack.
|
|
43
|
+
* @param config.peripheralMode (Android only) - Whether the device is in peripheral mode. Defaults to true
|
|
44
|
+
* @param config.centralClientMode (Android only) - Whether the device is in central client mode. Defaults to false
|
|
45
|
+
* @param config.clearBleCache (Android only) - Whether the BLE cache should be cleared. Defaults to true
|
|
46
|
+
* @param config.certificates - Array of base64 representing DER encoded X.509 certificate which are used to authenticate the verifier app
|
|
47
|
+
*/
|
|
48
|
+
export function start(
|
|
49
|
+
config: {
|
|
50
|
+
peripheralMode?: boolean;
|
|
51
|
+
centralClientMode?: boolean;
|
|
52
|
+
clearBleCache?: boolean;
|
|
53
|
+
certificates?: string[];
|
|
54
|
+
} = {}
|
|
55
|
+
): Promise<boolean> {
|
|
56
|
+
const { peripheralMode, centralClientMode, clearBleCache, certificates } =
|
|
57
|
+
config;
|
|
58
|
+
if (Platform.OS === 'ios') {
|
|
59
|
+
return IoReactNativeProximity.start(certificates ? certificates : []);
|
|
60
|
+
} else {
|
|
61
|
+
return IoReactNativeProximity.start(
|
|
62
|
+
peripheralMode ? peripheralMode : true,
|
|
63
|
+
centralClientMode ? centralClientMode : false,
|
|
64
|
+
clearBleCache ? clearBleCache : true,
|
|
65
|
+
certificates ? certificates : []
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Gets the QR code string this method is responsible for initializing the connection and retrieving the QR code string
|
|
72
|
+
*/
|
|
73
|
+
export function getQrCodeString(): Promise<string> {
|
|
74
|
+
return IoReactNativeProximity.getQrCodeString();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Closes the QR engagement
|
|
79
|
+
*/
|
|
80
|
+
export function close(): Promise<boolean> {
|
|
81
|
+
return IoReactNativeProximity.close();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Sends an error response to the verifier app.
|
|
86
|
+
* The error code must be one of the `ErrorCode` enum values.
|
|
87
|
+
* @param code - The error code to be sent to the verifier app.
|
|
88
|
+
*/
|
|
89
|
+
export function sendErrorResponse(code: ErrorCode): Promise<boolean> {
|
|
90
|
+
return IoReactNativeProximity.sendErrorResponse(code);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Generates a response that will be sent to the verifier app containing the requested data
|
|
95
|
+
* @param documents - An array of `Document` which contains the requested data received from the `onDocumentRequestReceived` event
|
|
96
|
+
* @param acceptedFields - The accepted fields which will be presented to the verifier app. See the type definition for more details.
|
|
97
|
+
* @returns A base64 encoded response to be sent to the verifier app via `sendResponse`
|
|
98
|
+
*/
|
|
99
|
+
export function generateResponse(
|
|
100
|
+
documents: Array<RequestedDocument>,
|
|
101
|
+
acceptedFields: AcceptedFields
|
|
102
|
+
): Promise<string> {
|
|
103
|
+
return IoReactNativeProximity.generateResponse(documents, acceptedFields);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Sends the response generated through the `generateResponse` method to the verifier app.
|
|
108
|
+
* Currently there's not evidence of the verifier app responding to this request, thus we don't handle the response.
|
|
109
|
+
* @param response - The base64 encoded response to be sent to the verifier app.
|
|
110
|
+
*/
|
|
111
|
+
export function sendResponse(response: string): Promise<boolean> {
|
|
112
|
+
return IoReactNativeProximity.sendResponse(response);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Adds a listener for a `QrEngagementEvents` event which will be emitted by the native module.
|
|
117
|
+
* The callback will be called with the event payload when the event is emitted.
|
|
118
|
+
* @param event - The event to listen for. The available events are defined in the `QrEngagementEvents` type.
|
|
119
|
+
* @param callback - The callback to be called when the event is emitted. The callback will receive the event payload as an argument.
|
|
120
|
+
*/
|
|
121
|
+
export function addListener<E extends Events>(
|
|
122
|
+
event: E,
|
|
123
|
+
callback: (data: EventsPayload[E]) => void
|
|
124
|
+
) {
|
|
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);
|
|
134
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
// Inner data: a record of booleans with the attributes and the intent to retain flag
|
|
4
|
+
const booleanFieldGroup = z.record(z.boolean());
|
|
5
|
+
|
|
6
|
+
const credentialEntrySchema = z
|
|
7
|
+
.object({
|
|
8
|
+
isAuthenticated: z.boolean(),
|
|
9
|
+
})
|
|
10
|
+
.catchall(booleanFieldGroup);
|
|
11
|
+
|
|
12
|
+
const VerifierRequest = z.object({
|
|
13
|
+
request: z.record(credentialEntrySchema),
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* VerifierRequest type returned by the `onDocumentRequestReceived` event in `Events`.
|
|
18
|
+
* The outermost key represents the credential doctype, the inner key represents the namespace and the innermost key represents the requested fields with a boolean value
|
|
19
|
+
* indicating whether the verifier app wants to retain the field or not. The isAuthenticated field is present for each requested credentials and indicates wether or not the verifier is authenticated.
|
|
20
|
+
* Example:
|
|
21
|
+
* `{
|
|
22
|
+
* "org.iso.18013.5.1.mDL": {
|
|
23
|
+
* "isAuthenticated": true,
|
|
24
|
+
* "org.iso.18013.5.1": {
|
|
25
|
+
* "hair_colour": true,
|
|
26
|
+
* "given_name_national_character": true,
|
|
27
|
+
* "family_name_national_character": true,
|
|
28
|
+
* "given_name": true,
|
|
29
|
+
* }
|
|
30
|
+
* }
|
|
31
|
+
* }`
|
|
32
|
+
* The request type can be also be used as input for the `generateResponse` method. The structure is the same, however the boolean value for each claim
|
|
33
|
+
* indicates the willing to present the claim.
|
|
34
|
+
*/
|
|
35
|
+
export type VerifierRequest = z.infer<typeof VerifierRequest>;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Parses the input to a VerifierRequest object.
|
|
39
|
+
* This function is used to parse the request received from the verifier app.
|
|
40
|
+
* @param input - The input to be parsed
|
|
41
|
+
* @returns The parsed VerifierRequest object
|
|
42
|
+
*/
|
|
43
|
+
export const parseVerifierRequest = (input: unknown): VerifierRequest => {
|
|
44
|
+
return VerifierRequest.parse(input);
|
|
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
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
## ISO18013-7
|
|
2
|
+
|
|
3
|
+
This module provides methods to obtain data structures necessary for the processes defined in the `ISO-18013` standard.
|
|
4
|
+
|
|
5
|
+
```typescript
|
|
6
|
+
import { ISO18013_7 } from '@pagopa/io-react-native-cbor';
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
### Methods
|
|
10
|
+
|
|
11
|
+
#### `generateOID4VPDeviceResponse`
|
|
12
|
+
|
|
13
|
+
Generates CBOR of the _Device Response_ containing all the claims that have been chosen to be presented during an _OID4VP_ session.
|
|
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.
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
try {
|
|
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
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
type RequestedDocument = {
|
|
36
|
+
issuerSignedContent : string,
|
|
37
|
+
alias : string,
|
|
38
|
+
docType : string
|
|
39
|
+
}
|
|
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
|
+
```
|
|
50
|
+
|
|
51
|
+
### Error Codes
|
|
52
|
+
|
|
53
|
+
| Type | Platform | Description |
|
|
54
|
+
| --------------------------------- | ----------- | ------------------------------------------------------------------ |
|
|
55
|
+
| UNABLE_TO_GENERATE_RESPONSE | Android/iOS | Failure during the generation of a response |
|
|
56
|
+
| DOC_REQUESTED_PARSING_EXCEPTION | Android/iOS | The passed documents where in a bad format or contained wrong data |
|
|
57
|
+
| REQUESTED_ITEMS_PARSING_EXCEPTION | iOS | The passed items where in a bad format |
|
|
58
|
+
| UNABLE_TO_GENERATE_TRANSCRIPT | Android | There has been an error generating the session transcript |
|
|
59
|
+
| UNKNOWN_EXCEPTION | Android/iOS | Unexpected failure |
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { IoReactNativeProximity } from '..';
|
|
2
|
+
import type { RequestedDocument } from '../types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* All error codes that the module could return.
|
|
6
|
+
*/
|
|
7
|
+
export type OID4VPFailureCodes =
|
|
8
|
+
| 'UNABLE_TO_GENERATE_RESPONSE'
|
|
9
|
+
| 'UNABLE_TO_GENERATE_TRANSCRIPT'
|
|
10
|
+
| 'INVALID_DOC_REQUESTED'
|
|
11
|
+
| 'GENERATE_OID4VP_DEVICE_RESPONSE_FAILED';
|
|
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
|
|
35
|
+
*/
|
|
36
|
+
export const generateOID4VPDeviceResponse = async (
|
|
37
|
+
clientId: string,
|
|
38
|
+
responseUri: string,
|
|
39
|
+
authorizationRequestNonce: string,
|
|
40
|
+
mdocGeneratedNonce: string,
|
|
41
|
+
documents: Array<RequestedDocument>,
|
|
42
|
+
fieldRequestedAndAccepted: Record<string, any> | string
|
|
43
|
+
): Promise<string> => {
|
|
44
|
+
return await IoReactNativeProximity.generateOID4VPDeviceResponse(
|
|
45
|
+
clientId,
|
|
46
|
+
responseUri,
|
|
47
|
+
authorizationRequestNonce,
|
|
48
|
+
mdocGeneratedNonce,
|
|
49
|
+
documents,
|
|
50
|
+
typeof fieldRequestedAndAccepted === 'string'
|
|
51
|
+
? fieldRequestedAndAccepted
|
|
52
|
+
: JSON.stringify(fieldRequestedAndAccepted)
|
|
53
|
+
);
|
|
54
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common types definition for ISO 18013-5 and ISO 18013-7 modules.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Documents type to be used in the {@link generateResponse} for ISO18013-5 and {@link generateOID4VPDeviceResponse} for ISO18013-7.
|
|
7
|
+
* It contains:
|
|
8
|
+
* - issuerSignedContent which is a base64 or base64url encoded string representing the credential;
|
|
9
|
+
* - alias which is the alias of the key used to sign the credential;
|
|
10
|
+
* - docType which is the document type.
|
|
11
|
+
*/
|
|
12
|
+
export type RequestedDocument = {
|
|
13
|
+
issuerSignedContent: string;
|
|
14
|
+
alias: string;
|
|
15
|
+
docType: string;
|
|
16
|
+
};
|