Skip to content

Commit 5c8f2cb

Browse files
author
RN SDK Release User
committed
v10.3.1 release
1 parent 005fba7 commit 5c8f2cb

File tree

9 files changed

+168
-81
lines changed

9 files changed

+168
-81
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8+
## [10.3.1] - 2023-09-21
9+
10+
### Added:
11+
12+
- Added a helper function `byteArrayStringToBase64` for converting the `fileData` attribute of a `MediaFile`, from a String representation of byte array data, to a Base64 format - in the custom media callbacks use case.
13+
14+
### Changed:
15+
16+
- Updated the `OnfidoMediaResult` type so that `captureType` is visible. This refers to the type of the media capture in each case, which can be `DOCUMENT`, `FACE` or `VIDEO`.
17+
- Updated the Media Callbacks documentation.
18+
819
## [10.3.0] - 2023-09-11
920

1021
### Added:

README.md

Lines changed: 85 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,17 @@
1919
- [4.4 Update your iOS configuration files](#44-update-your-ios-configuration-files)
2020
- [Enabling NFC extraction](#enabling-nfc-extraction)
2121
- [Usage](#usage)
22-
- [User data](#user-data)
2322
- [1. Creating the SDK configuration](#1-creating-the-sdk-configuration)
2423
- [2. Parameter details](#2-parameter-details)
2524
- [3. Success Response](#3-success-response)
2625
- [4. Failure Response](#4-failure-response)
2726
- [5. Localization](#5-localization)
2827
- [Android](#android)
2928
- [iOS](#ios)
29+
- [Media Callbacks](#media-callbacks)
30+
- [Introduction](#introduction)
31+
- [Implementation](#implementation)
32+
- [User data](#user-data)
3033
- [Creating checks](#creating-checks)
3134
- [1. Obtaining an API token](#1-obtaining-an-api-token-1)
3235
- [2. Creating a check](#2-creating-a-check)
@@ -341,73 +344,6 @@ export default class App extends Component {
341344
);
342345
}
343346
}
344-
345-
### Media Callbacks (beta)
346-
347-
### Introduction
348-
Onfido provides the possibility to integrate with our Smart Capture SDK, without the requirement of using this data only through the Onfido API. Media callbacks enable you to control the end user data collected by the SDK after the end user has submitted their captured media. As a result, you can leverage Onfido’s advanced on-device technology, including image quality validations, while still being able to handle end users’ data directly. This unlocks additional use cases, including compliance requirements and multi-vendor configurations, that require this additional flexibility.
349-
350-
**This feature must be enabled for your account.** Please contact your Onfido Solution Engineer or Customer Success Manager.
351-
352-
### Implementation
353-
To use this feature, use `Onfido.addCustomMediaCallback` and provide the callback.
354-
355-
```javascript
356-
Onfido.addCustomMediaCallback(
357-
mediaResult => {
358-
if (mediaResult.captureType === 'DOCUMENT') {
359-
// Callback code here
360-
} else if (mediaResult.captureType === 'FACE') {
361-
// Callback code here
362-
} else if (mediaResult.captureType === 'VIDEO') {
363-
// Callback code here
364-
}
365-
}
366-
);
367-
```
368-
369-
### User data
370-
The callbacks return an object including the information that the SDK normally sends directly to Onfido. The callbacks are invoked when the end user confirms submission of their image through the SDK’s user interface.
371-
372-
**Note:** Currently, end user data will still automatically be sent to the Onfido backend, but you are not required to use Onfido to process this data.
373-
374-
The callback returns 3 possible objects. Please note, `captureType` refers to the type of the media capture in each case.
375-
These can be `DOCUMENT`, `FACE` or `VIDEO`.
376-
377-
1. For documents(`captureType` is `DOCUMENT`), the callback returns:
378-
```json5
379-
{
380-
captureType: String
381-
side: String
382-
type: String
383-
issuingCountry: String?
384-
fileData: Data
385-
fileName: String
386-
fileType: String
387-
}
388-
```
389-
390-
**Note:** `issuingCountry` is optional based on end-user selection, and can be `null`.
391-
**Note:** If a document was scanned using NFC, the callback will return the passport photo in `file` but no additional data.
392-
393-
2. For live photos (`captureType` is `FACE`), the callback returns:
394-
```json5
395-
{
396-
captureType: String
397-
fileData: Data
398-
fileName: String
399-
fileType: String
400-
}
401-
```
402-
403-
3. For videos(`captureType` is `VIDEO`), the callback returns:
404-
```json5
405-
{
406-
captureType: String
407-
fileData: Data
408-
fileName: String
409-
fileType: String
410-
}
411347
```
412348

413349
### 1. Creating the SDK configuration
@@ -457,7 +393,9 @@ config = {
457393
* Valid values in `OnfidoFaceSelfieCapture`: `type`: OnfidoCaptureType.PHOTO
458394
* Valid values in `OnfidoFaceVideoCapture`: `type`: OnfidoCaptureType.VIDEO
459395

460-
**Note**: In the scenario that the Motion variant is not supported on the user's device, if you configure the `motionCaptureFallback` appropriately it will allow the user to capture a Selfie or a Video as a fallback.
396+
In the scenario that the Motion variant is not supported on the user's device, if you configure the `motionCaptureFallback` appropriately it will allow the user to capture a Selfie or a Video as a fallback.
397+
398+
**Note**: Fallback is not used in Android anymore as Motion is supported in all devices and OS versions specified by the SDK.
461399
* **`recordAudio`**: Required if captureFace is specified as MOTION.
462400
* Valid values: `true`, `false`
463401
* **`localisation`**: Optional. This object contains localisation configuration. See section [Localization](#localization) for the details.
@@ -584,6 +522,84 @@ localisation: {
584522
3. Follow the instructions for [iOS Localisation](https://medium.com/lean-localization/ios-localization-tutorial-938231f9f881) to add a new custom language or override existing translations.
585523
4. You can find the keys that need to be translated in the [iOS SDK repo](https://github.com/onfido/onfido-ios-sdk/blob/master/localization/Localizable_EN.strings).
586524

525+
## Media Callbacks
526+
527+
### Introduction
528+
Onfido provides the possibility to integrate with our Smart Capture SDK, without the requirement of using this data only through the Onfido API. Media callbacks enable you to control the end user data collected by the SDK after the end user has submitted their captured media. As a result, you can leverage Onfido’s advanced on-device technology, including image quality validations, while still being able to handle end users’ data directly. This unlocks additional use cases, including compliance requirements and multi-vendor configurations, that require this additional flexibility.
529+
530+
**This feature must be enabled for your account.** Please contact your Onfido Solution Engineer or Customer Success Manager.
531+
532+
### Implementation
533+
To use this feature, use `Onfido.addCustomMediaCallback` and provide the callback.
534+
535+
```javascript
536+
Onfido.addCustomMediaCallback(
537+
mediaResult => {
538+
if (mediaResult.captureType === 'DOCUMENT') {
539+
// Callback code here
540+
} else if (mediaResult.captureType === 'FACE') {
541+
// Callback code here
542+
} else if (mediaResult.captureType === 'VIDEO') {
543+
// Callback code here
544+
}
545+
}
546+
);
547+
```
548+
549+
### User data
550+
The callbacks return an object including the information that the SDK normally sends directly to Onfido. The callbacks are invoked when the end user confirms submission of their image through the SDK’s user interface.
551+
552+
**Note:** Currently, end user data will still automatically be sent to the Onfido backend, but you are not required to use Onfido to process this data.
553+
554+
The callback returns 3 possible objects. Please note that `captureType` refers to the type of the media capture in each case.
555+
These can be `DOCUMENT`, `FACE` or `VIDEO`.
556+
557+
1. For documents (`captureType` is `DOCUMENT`), the callback returns:
558+
```json5
559+
{
560+
captureType: String
561+
side: String
562+
type: String
563+
issuingCountry: String?
564+
fileData: String
565+
fileName: String
566+
fileType: String
567+
}
568+
```
569+
570+
**Notes:**
571+
- `issuingCountry` is optional based on end-user selection, and can be `null`.
572+
- `fileData` is a String representation of the byte array data corresponding to the captured photo of the document.
573+
- If a document was scanned using NFC, the callback will return the passport photo in `fileData` but no additional data.
574+
575+
2. For live photos (`captureType` is `FACE`), the callback returns:
576+
```json5
577+
{
578+
captureType: String
579+
fileData: String
580+
fileName: String
581+
fileType: String
582+
}
583+
```
584+
**Note:** `fileData` is a String representation of the byte array data corresponding to the captured live photo.
585+
586+
3. For videos(`captureType` is `VIDEO`), the callback returns:
587+
```json5
588+
{
589+
captureType: String
590+
fileData: String
591+
fileName: String
592+
fileType: String
593+
}
594+
```
595+
**Note:** `fileData` is a String representation of the byte array data corresponding to the captured video.
596+
597+
Please note that, for your convenience, Onfido provides the `byteArrayStringToBase64` helper function to convert the `fileData` from String to a Base64 format. Here is an example of how to use it:
598+
```javascript
599+
let byteArrayString = mediaResult.fileData;
600+
let base64FileData = Onfido.byteArrayStringToBase64(byteArrayString);
601+
```
602+
587603
## Creating checks
588604

589605
As the SDK is only responsible for capturing and uploading photos/videos, you would need to start a check on your backend server using the [Onfido API](https://documentation.onfido.com/).

android/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88

99
<meta-data
1010
android:name="onfido_integration_version"
11-
android:value="10.3.0" />
11+
android:value="10.3.1" />
1212
</application>
1313
</manifest>

ios/CallbackReceiver.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ extension CallbackReceiver: MediaCallback {
4040
}
4141

4242
private func send(dictionary: [String: Any], mediaFile file: MediaFile) {
43+
let fileData = getArrayOfBytesFromImage(data: file.fileData as NSData).description
44+
4345
var newDict = dictionary
4446
newDict[Keys.MediaCallback.fileName] = file.fileName
45-
newDict[Keys.MediaCallback.fileData] = file.fileData
47+
newDict[Keys.MediaCallback.fileData] = fileData
4648
newDict[Keys.MediaCallback.fileType] = file.fileType
4749

4850
guard let onMediaCallback = onMediaCallback else {
@@ -51,4 +53,18 @@ extension CallbackReceiver: MediaCallback {
5153
}
5254
onMediaCallback(newDict)
5355
}
56+
57+
// TODO: Temporary. Removed when introducing breaking change to return Base64 encoded string.
58+
// https://stackoverflow.com/a/65265130
59+
private func getArrayOfBytesFromImage(data: NSData) -> Array<Int8> {
60+
let count = data.length / MemoryLayout<Int8>.size
61+
var bytes = [Int8](repeating: 0, count: count)
62+
data.getBytes(&bytes, length:count * MemoryLayout<Int8>.size)
63+
64+
var byteArray:Array = Array<Int8>()
65+
for i in 0 ..< count {
66+
byteArray.append(bytes[i])
67+
}
68+
return byteArray
69+
}
5470
}

js/Onfido.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
OnfidoMediaResult,
1010
OnfidoResult
1111
} from "./config_constants";
12+
import { Base64 } from 'js-base64';
1213

1314
const {OnfidoSdk} = NativeModules;
1415

@@ -86,6 +87,7 @@ const Onfido = {
8687
if (config.flowSteps.captureFace && !(config.flowSteps.captureFace.type in OnfidoCaptureType)) {
8788
return configError("Capture Face type is invalid");
8889
}
90+
8991
}
9092

9193
return OnfidoSdk.start(config).catch((error: any) => {
@@ -101,6 +103,30 @@ const Onfido = {
101103
eventEmitter.removeAllListeners('onfidoMediaCallback');
102104

103105
return eventEmitter.addListener('onfidoMediaCallback', callback);
106+
},
107+
108+
byteArrayStringToBase64(byteArrayString: String) {
109+
let charString = '';
110+
111+
// Iterate through the string and convert each number to string
112+
// Iteration starts from the 1st element to ignore brackets
113+
let currentNumber = '';
114+
for (let i = 1; i < byteArrayString.length; i++) {
115+
const char = byteArrayString.charAt(i);
116+
if ((char >= '0' && char <= '9') || char === '-') {
117+
currentNumber += char;
118+
} else {
119+
// Convert the collected number to string
120+
if (currentNumber) {
121+
const number = parseInt(currentNumber, 10);
122+
charString += String.fromCharCode(number & 0xFF);
123+
currentNumber = '';
124+
}
125+
}
126+
}
127+
128+
// Convert to base64
129+
return Base64.btoa(charString);
104130
}
105131
};
106132

js/__tests__/Onfido.spec.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ const REJECTED = 'rejected';
2222

2323
const start = (config: OnfidoConfig) => {
2424
return Onfido.start(config)
25-
.then(() => {
26-
return RESOLVED
27-
})
28-
.catch(() => {
29-
return REJECTED
30-
});
25+
.then(() => {
26+
return RESOLVED
27+
})
28+
.catch(() => {
29+
return REJECTED
30+
});
3131
};
3232

3333
const flowSteps = {
@@ -71,7 +71,7 @@ testCases.forEach((platform) => {
7171
test('resolve a capture document object with explicitly null attributes', () => {
7272
return start({ ...baseConfig, flowSteps: { ...flowSteps, captureDocument: { docType: null, countryCode: null } } } as unknown as OnfidoConfig).then(result => expect(result).toBe(RESOLVED))
7373
});
74-
74+
7575
test('resolve with a valid workflow runId', () => {
7676
return start({ ...baseConfig, workflowRunId: workflowRunId }).then(result => expect(result).toBe(RESOLVED))
7777
});
@@ -116,5 +116,15 @@ testCases.forEach((platform) => {
116116
test('reject with an empty captureDocument and captureFace', () => {
117117
return start({ ...baseConfig, flowSteps: { ...flowSteps, captureDocument: {}, captureFace: {} } } as unknown as OnfidoConfig).then(result => expect(result).toBe(REJECTED))
118118
});
119+
120+
test('base 64 helper function converts data array correctly to base64', () => {
121+
// pass nothing, see nothing
122+
const base64DataNothing = Onfido.byteArrayStringToBase64("")
123+
expect(base64DataNothing).toBe("")
124+
125+
// intended use case for this method is that it must contain brackets as well
126+
const base64DataFilled = Onfido.byteArrayStringToBase64("[104, 101, 108, 108, 111, 32, 76, 117, 107, 97, 115]")
127+
expect(base64DataFilled).toBe("aGVsbG8gTHVrYXM=")
128+
});
119129
});
120-
});
130+
});

js/config_constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export interface OnfidoError extends Error {
4747
}
4848

4949
export interface OnfidoMediaResult {
50+
captureType: "DOCUMENT" | "FACE" | "VIDEO";
5051
}
5152

5253
export interface OnfidoDocumentResult extends OnfidoMediaResult {

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@onfido/react-native-sdk",
33
"title": "React Native Onfido Sdk",
4-
"version": "10.3.0",
4+
"version": "10.3.1",
55
"description": "Onfido React Native SDK",
66
"main": "index.ts",
77
"scripts": {
@@ -82,7 +82,9 @@
8282
"react-native": "0.72.1",
8383
"typescript": "^4.6.4"
8484
},
85-
"dependencies": {},
85+
"dependencies": {
86+
"js-base64": "3.7.5"
87+
},
8688
"engines": {
8789
"node": ">=16"
8890
}

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4902,6 +4902,11 @@ joi@^17.2.1:
49024902
"@sideway/formula" "^3.0.0"
49034903
"@sideway/pinpoint" "^2.0.0"
49044904

4905+
4906+
version "3.7.5"
4907+
resolved "https://registry.npmjs.org/js-base64/-/js-base64-3.7.5.tgz#21e24cf6b886f76d6f5f165bfcd69cc55b9e3fca"
4908+
integrity sha512-3MEt5DTINKqfScXKfJFrRbxkrnk2AxPWGBL/ycjz4dK8iqiSJ06UxD8jh8xuh6p10TX4t2+7FsBYVxxQbMg+qA==
4909+
49054910
js-tokens@^3.0.0:
49064911
version "3.0.2"
49074912
resolved "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz"

0 commit comments

Comments
 (0)