@scandit/web-id-bolt
v2.7.0
Published
ID Bolt is a pre-built ID scanning workflow that seamlessly integrates into any website allowing users to scan their identity documentation in just one second. ID Bolt works on-device, via desktop and mobile in a unified solution, ensuring no identity inf
Keywords
Readme
Scandit ID Bolt
ID Bolt is a pre-built ID scanning workflow that seamlessly integrates into any website allowing users to scan their identity documentation in just one second. ID Bolt works on-device, via desktop and mobile in a unified solution, ensuring no identity information is collected by third-party servers and reduces latency for quick scanning performance.
Learn more about ID Bolt at https://www.scandit.com/products/id-bolt/.
Get started
Add the ID Bolt client as a dependency:
npm i @scandit/web-id-boltCopy the following snippet to get started.
Your application defines when the ID Bolt pop-up is opened. In this snippet, we open it after a click on a button present in the page:
import {
Passport,
IdCard,
DriverLicense,
VisaIcao,
DocumentSelection,
IdBoltSession,
Region,
ReturnDataMode,
Validators,
} from "@scandit/web-id-bolt";
const ID_BOLT_URL = "https://app.id-scanning.com";
async function startIdBolt() {
// initialization of the ID Bolt session
const idBoltSession = IdBoltSession.create(ID_BOLT_URL, {
licenseKey: "<<YOUR LICENSE KEY>>",
// define which documents are allowed to be scanned. More complex rules can be added.
documentSelection: DocumentSelection.create({
accepted: [
new Passport(Region.Any),
new IdCard(Region.Any),
new DriverLicense(Region.Any),
new VisaIcao(Region.Any),
],
}),
// define what data you expect in the onCompletion listener (set below)
returnDataMode: ReturnDataMode.Full,
// add validation rules on the scanned document
validation: [Validators.notExpired()],
locale: "en-US",
onCompletion: (result) => {
// the ID has been captured and validation was successful. In this example the result
// will contain the document data because `returnDataMode` was set to ReturnDataMode.Full.
alert(`Thank you ${result.capturedId?.fullName ?? ""}`);
},
onCancellation: (reason) => {
// the ID Bolt pop-up has been terminated without a succesful scan
},
});
// open the pop-up
await idBoltSession.start();
}
// open ID Bolt when some button is clicked
const someButton = document.getElementById("someButton");
someButton.addEventListener("click", startIdBolt);For completeness this is the HTML you will need for the example:
<button id="someButton">Start ID Bolt</button>If you have Content-Security-Policy headers (CSP) which prevent loading iframes on your page, you need to adapt the value like so:
frame-src 'self' https://app.id-scanning.com https://id-service.scandit.comCustom domains: launch tokens
If ID Bolt runs on your own domain (for example https://scan.yourbrand.com instead of
https://app.id-scanning.com), every session must be started with a launch token
minted by your backend. This proves the session was started by you and not by someone
embedding your domain elsewhere. Sessions without a valid token are refused on custom
domains. Nothing changes for the shared app.id-scanning.com domain.
You need an API key from Scandit. It is a secret: keep it on your server, never in the browser. Each API key is bound to one domain.
Your backend mints a launch: the token and the session configuration it was minted for, as a JSON string. The page starts ID Bolt with that launch, without building the configuration again. The service refuses the session if the configuration string changes on the way.
The configuration never reaches the Scandit servers: your backend sends only the SHA-256 of the configuration string, and ID Bolt checks the digest of the string it receives in the browser. Text overrides can hold personal data (for example "Scan the passport of Jane Doe"), and they stay between your backend, your page and the user's devices.
1. Mint a launch in your backend
With Node.js 20 or newer, use the server entry of this package:
import { IdBoltServer } from "@scandit/web-id-bolt/server";
import { DocumentSelection, Passport, Region, ReturnDataMode } from "@scandit/web-id-bolt";
const idBoltServer = new IdBoltServer({
apiKey: process.env.ID_BOLT_API_KEY,
serviceUrl: "https://scan.yourbrand.com",
});
// once per page view that will show ID Bolt
const launch = await idBoltServer.createLaunch({
// the options of IdBoltSession.create, minus the functions (validation, onCompletion,
// onCancellation) and the browser-only options (locale, keepAliveForNextSession,
// disableCloseOnBrowserBack)
configuration: {
licenseKey: "<<YOUR LICENSE KEY>>",
documentSelection: DocumentSelection.create({ accepted: [new Passport(Region.Any)] }),
returnDataMode: ReturnDataMode.Full,
},
});
// send `launch` to the page as it is: it is plain JSONFrom a backend without this package
- Write the configuration as a JSON string, with any JSON library. Its fields are described
below;
licenseKey,documentSelection.acceptedDocumentsandnonceare required. - Compute the SHA-256 of the UTF-8 bytes of that string, as lowercase hex.
- Post only the digest. The body is a
LaunchTokenRequest(the type is exported from@scandit/web-id-bolt/server). - Add the string, unchanged, to the response as
configuration, and send the result to the page.
import hashlib, json, secrets, requests
configuration = json.dumps({
"licenseKey": "<<YOUR LICENSE KEY>>",
"documentSelection": {"acceptedDocuments": [{"type": "Passport", "region": "Any"}]},
"returnDataMode": "Full",
"textOverrides": {"titles.SCANNER_HEADER": "Scan the passport of Jane Doe"},
"nonce": secrets.token_hex(16),
})
response = requests.post(
"https://scan.yourbrand.com/api/v1/launch-tokens",
headers={"Authorization": f"Bearer {ID_BOLT_API_KEY}"},
json={"configurationDigest": hashlib.sha256(configuration.encode("utf-8")).hexdigest()},
)
launch = response.json()
launch["configuration"] = configuration # the string itself: never parse it and serialize it againThe string is opaque: ID Bolt hashes its exact bytes, so any spacing and any valid JSON escape
works, but a string that is parsed and serialized again on the way is refused. To check your
implementation, the SHA-256 of this string (as Python's json.dumps writes it)
{"licenseKey": "YOUR-LICENSE-KEY", "documentSelection": {"acceptedDocuments": [{"type": "Passport", "region": "Any"}]}, "textOverrides": {"titles.SCANNER_HEADER": "Scan the passport of Jos\u00e9"}, "nonce": "6f1c0e2a9b7d4c3e8a5f1b2d3c4e5f60"}is 24ba90f450f9b4f249104112514fbd0de76314ae6e2780e136573c1e619fac84.
The nonce is at least 16 random characters, new for each launch. Without it, the digest of a
configuration whose other fields are known could be reversed by guessing its text overrides.
The fields of the configuration have the same names and values as the options of
IdBoltSession.create, except:
- a document is
{ "type": "Passport", "region": "DEU" }, withregionan ISO 3166-1 alpha-3 code or"Any". ARegionSpecificdocument is{ "type": "RegionSpecific", "region": "Any", "subtype": "usNexusCard" }. scanneris{ "type": "full" }, or{ "type": "singleSide", "barcode": true, "machineReadableZone": true, "visualInspectionZone": true }with an optional"enforceVizForPassportScan".
ID Bolt fills in the defaults of the other fields, the same as IdBoltSession.create does. It
refuses unknown fields and invalid values, and its error page names each field, for example
Invalid launch configuration: documentSelection.acceptedDocuments.0.region: Invalid region: expected an ISO 3166-1 alpha-3 code or "Any".
The response of the service is:
{
"success": true,
"serviceUrl": "https://scan.yourbrand.com",
"launchToken": "…",
"sessionId": "…",
"expiresAt": "2026-01-01T12:15:00.000Z"
}On failure the response is { "success": false, "error": "…" } with status 400 for an
invalid body, or 401 for an invalid API key.
A launch token is valid for one session and for 30 minutes. Mint it when you render the
page, not ahead of time. Keep the sessionId if you want to match the scan result to your
own records later.
2. Start ID Bolt with the launch
Send the launch to your page and pass it to IdBoltSession.createFromLaunch, with the
functions and the browser-only options:
const idBoltSession = IdBoltSession.createFromLaunch(launch, {
onCompletion: (result) => {
/* ... */
},
});
await idBoltSession.start();ID Bolt runs on launch.serviceUrl with launch.configuration. Do not change the launch. If
the token is missing, expired, was minted for another domain, or the configuration string was
changed (configuration_mismatch), ID Bolt shows an error instead of the scanner, on both
the desktop page and the phone. A session started from a launch cannot change its
configuration afterwards (__patchSessionConfiguration does nothing).
UMD build (no package manager)
For hosts where npm/yarn isn't available (e.g. ServiceNow), a self-contained UMD
bundle is shipped at @scandit/web-id-bolt/umd (dist/index.umd.js). Upload it as
a static file and reference it from a <script> tag; it exposes every export on the
ScanditIdBolt global:
<button id="someButton">Start ID Bolt</button>
<script src="/path/to/index.umd.js"></script>
<script>
const { IdBoltSession, DocumentSelection, Passport, IdCard, Region, ReturnDataMode } = ScanditIdBolt;
document.getElementById("someButton").addEventListener("click", async () => {
const idBoltSession = IdBoltSession.create("https://app.id-scanning.com", {
licenseKey: "<<YOUR LICENSE KEY>>",
documentSelection: DocumentSelection.create({
accepted: [new Passport(Region.Any), new IdCard(Region.Any)],
}),
returnDataMode: ReturnDataMode.Full,
onCompletion: (result) => alert(`Thank you ${result.capturedId?.fullName ?? ""}`),
});
await idBoltSession.start();
});
</script>Full documentation
Find the complete documentation on the ID Bolt documentation website.
