@nexiel/credentials-widget
v0.1.0
Published
Drop-in embeddable widget for Nexiel Credentials' external B2B verification API (an employer verifying a Nexiel-vetted academic credential) — a script-tag build for any customer site, plus an ESM/React build for npm consumers. See README.md for this packa
Maintainers
Readme
@nexiel/credentials-widget
A drop-in embeddable widget for Nexiel Credentials' external B2B verification API: an employer verifying a Nexiel-vetted academic credential (academic-credential, an awarded degree) or enrolment status (academic-enrolment-status, still studying). Renders a QR code, polls the session for you, and calls back with the final result.
This package's data contract is honestly different from @nexiel/verify-widget
@nexiel/verify-widget's own README states plainly that its callback shape is PII-free by construction: no name, DOB, or nationality ever passes through it.
This widget is different, on purpose: for Nexiel Credentials, the disclosed academic record (degree title, institution, ECTS, award date, ...) is the product an employer is paying to see.
result.decision.disclosedClaims can therefore be non-null. It is never plaintext, and this widget never decrypts it. It is a JWE ciphertext, encrypted server-side by credentials-api to your own registered public key (the same client-side-generated-keypair flow already used for AML evidence packs; see the Nexiel dashboard's evidence-keys page). Nexiel's server never holds the matching private key, and this widget, running in an end user's browser on whatever page embeds it, has no legitimate way to hold it either.
What to do with disclosedClaims: decryption is always a server-side concern for your own application. Either:
- Have your backend receive the ciphertext relayed from
onComplete(over your own authenticated channel, never a public one) and decrypt it there, or - More robustly, and without relaying a one-time-delivery value through client-side JS at all, have your backend independently call
GET /v1/credentials/verify/sessions/:iditself, server-to-server, with its own real API key, and claim the delivery directly.
This widget's own code never imports a decryption primitive. It renders only non-PII, structural facts on completion: the issuer's verified domain, its legalWeightNotice (a fixed sentence; see apps/credentials-api/src/legal-weight-notice.ts), and a live revocationStatus badge.
Why a sibling package, not a shared dependency of @nexiel/verify-widget
These are two independently embeddable artifacts with genuinely different security contracts (PII-free vs. ciphertext-bearing). A customer embedding one should never pull in the other's bundle, and a future audit of "does this widget ever touch PII" should be answerable by reading one small package, not by tracing a shared one. qr.ts/styles.ts are therefore small, deliberate duplicates, not imports; see each file's own header comment.
Ships as two things from one source file (src/index.ts):
- A script-tag build (
dist/nexiel-credentials.iife.js) for any customer site, no bundler or npm required. - An ESM/React build (
dist/index.js,dist/react.js) for npm consumers.
Installation
npm install @nexiel/credentials-widgetThe package contains dist/nexiel-credentials.iife.js (the script-tag bundle), dist/nexiel-credentials.esm.js (a single-file ESM bundle) and dist/index.js / dist/react.js for bundlers.
Script-tag usage
<div id="nexiel-credentials"></div>
<script src="/nexiel-credentials.iife.js"></script>
<script>
NexielCredentials.mount('#nexiel-credentials', {
checkType: 'academic-credential',
apiBaseUrl: 'http://localhost:3002', // your credentials-api instance
clientId: 'your-employer-client-id',
onComplete: (result) => {
if (result.status === 'completed' && result.decision) {
console.log('issuer:', result.decision.issuer.verifiedDomain);
console.log('legal weight:', result.decision.issuer.legalWeightNotice);
console.log('revocation status:', result.decision.revocationStatus);
// Never decrypted here; see this README's "data contract" section above.
if (result.decision.disclosedClaims) {
fetch('/api/your-own-backend/relay-evidence', {
method: 'POST',
body: JSON.stringify({ sessionId: result.sessionId, ciphertext: result.decision.disclosedClaims }),
});
}
}
},
onError: (error) => console.error('verification failed:', error.code, error.message),
});
</script>mount throws synchronously if target doesn't resolve to an element, or if options is missing a field the selected mode needs, so a misconfiguration surfaces immediately rather than as a confusing failed request a moment later.
React usage
import { NexielCredentials } from '@nexiel/credentials-widget/react';
function VerifyDegreeStep() {
return (
<NexielCredentials
checkType="academic-credential"
apiBaseUrl="http://localhost:3002"
clientId="your-employer-client-id"
onComplete={(result) => {
if (result.status === 'completed' && result.decision?.revocationStatus === 'revoked') {
// A currently-revoked credential -- surface this prominently, never silently accept it.
}
}}
/>
);
}The widget mounts on first render and unmounts cleanly. It only restarts the verification flow when a session-shaping prop changes (checkType, mode, clientId, apiBaseUrl), never just because the parent re-rendered with a fresh onComplete closure.
Languages, accessibility and errors
The same model as @nexiel/verify-widget: locale (en, de, fr, es, it, pl; default the page's <html lang>), cspNonce, an optional verifierName ("Share your degree or qualification with {verifierName}"), a persistent live region, focus kept inside the widget, a named QR code, plain error messages with a reference (API messages only under "Developer details" in sandbox), and a result that follows the credential's live status: a revoked or suspended credential is never shown with a success tick. The script-tag build loads nexiel-credentials.locale.<lc>.js and nexiel-credentials.qr.js from its own directory on demand; publish them next to nexiel-credentials.iife.js. The bundle carries each file's SHA-384 digest and sets it as integrity (always for a same-origin file, and for a cross-origin one when the widget's own tag has integrity).
What the widget actually does
Under the hood, the widget calls POST /v1/credentials/verify/sessions and GET /v1/credentials/verify/sessions/:id (real Fastify routes registered in apps/credentials-api/src/routes/verify.ts, reusing @nexiel/verify's existing OpenID4VP session pattern unchanged), running its own poll loop so you never write one yourself.
Tests
src/*.test.ts (run via pnpm --filter @nexiel/credentials-widget test) cover the QR rendering and wire-type logic that don't need a real network call.
