@codevibe_technology/sign-aadhaar
v0.1.1
Published
Aadhaar eSign through a licensed eSign provider, with your own provider account.
Maintainers
Readme
@codevibe_technology/sign-aadhaar
Aadhaar eSign for Codevibe Sign, through an eSign provider you hold an account with. It defines a
small EsignProvider interface and ships an adapter for Leegality.
The Codevibe Sign server runs it for you: pass a provider as the server's esign option and
a recipient with auth: 'aadhaar' is sent to the provider, the callback is verified, the
signed file is kept and sealed, and the audit trail records it (see "Aadhaar eSign" in the
server README). The web app does the same from its settings. You can also call the provider
from your own backend, as shown below, and store the signed file yourself.
What Aadhaar eSign is
Under the Information Technology Act, 2000, an electronic record can be authenticated with an electronic signature using a technique listed in the Second Schedule (s.3A). The Second Schedule lists e-authentication using Aadhaar e-KYC: the signer proves who they are with an Aadhaar OTP or biometric, and an eSign Service Provider (ESP) issues a short-lived signing certificate and signs the document hash with it.
ESPs are Certifying Authorities licensed by the Controller of Certifying Authorities (CCA). Most products reach them through an Application Service Provider such as Leegality, which runs the signing page and talks to the ESP.
Use this when a law asks for a document to be "signed" in the statutory sense. For offer letters, policies, NDAs and most business documents, the built-in electronic signature in Codevibe Sign (IT Act s.10A, with its audit trail) is usually enough.
This is not legal advice. Ask your own counsel which documents need which kind of signature.
You need a provider account
This package talks to the provider with the API credentials you give it, and each eSign is billed to that account. When you run the server yourself, that is your own account with the provider. The hosted Codevibe Sign app can also sign through Codevibe's account with prepaid credits.
Install
pnpm add @codevibe_technology/sign-aadhaar @codevibe_technology/sign-coreNode 22 or later. The package uses fetch and node:crypto.
How the flow works
- Your server calls
createRequestwith the PDF and the signer. The provider returns aproviderRefand asignUrl. - You send the signer to
signUrl. They review the document and sign with Aadhaar OTP on the provider's page. - The provider calls your webhook.
parseWebhookverifies it and returns{ providerRef, status }, wherestatusissigned,declined,expiredorfailed. - When the status is
signed,fetchSignedDocument(providerRef)returns the signed PDF. Store it and record the event in the envelope's audit trail.fetchAuditTrail(providerRef)returns the provider's own audit trail PDF, to keep as evidence next to it.
The signed PDF carries the provider's digital signature. Do not draw on it or add pages to it
afterwards: any change other than another signature breaks that signature. To seal it, use
countersign from @codevibe_technology/sign-pdf.
Usage
import { createLeegalityProvider } from '@codevibe_technology/sign-aadhaar';
const esign = createLeegalityProvider({
environment: 'sandbox',
authToken: process.env.LEEGALITY_API_KEY!,
privateSalt: process.env.LEEGALITY_PRIVATE_SALT!,
profileId: process.env.LEEGALITY_WORKFLOW_ID!,
});
const { providerRef, signUrl } = await esign.createRequest({
envelopeId: envelope.id,
recipient: { name: 'Asha Rao', email: '[email protected]' },
documentBytes: pdf,
documentName: 'Appointment letter.pdf',
callbackUrl: 'https://sign.example.com/hooks/leegality',
redirectUrl: 'https://sign.example.com/done',
});
// In your webhook route, pass the raw body exactly as received.
const event = await esign.parseWebhook(request.headers, rawBody);
if (event?.status === 'signed') {
const signed = await esign.fetchSignedDocument(event.providerRef);
const providerAuditTrail = await esign.fetchAuditTrail?.(event.providerRef);
}API
| Export | What it is |
| ---------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| EsignProvider | createRequest, parseWebhook, fetchSignedDocument, and optionally fetchAuditTrail, webhookRef and checkCredentials. Implement it to add a provider. |
| EsignRequest | envelopeId, reference, recipient, documentBytes, documentName, callbackUrl, redirectUrl, optional signaturePositions. |
| EsignEvent | { providerRef, status, signerName?, signedAt? }. |
| createLeegalityProvider | The Leegality adapter. Options below. |
| computeLeegalityMac | The webhook mac for a document id, for tests and tooling. |
| leegalityWebhookRef | The provider reference a Leegality webhook body names (document id, or v4:<packId>:<documentId>), read without verifying it. |
| SignaturePosition, PageBox | { page, rect, pageBox? }; pageBox is the page's crop box in user space and its rotation. |
| leegalityV4WorkflowFromPayload | The workflow id and part ids from a v4 workflow's downloaded API payload (object or JSON text). |
| toLeegalityRect | The v4 rect for a position under a LeegalityCoordinateMapping. |
| parseLeegalityCoordinateUnits, parseLeegalityCoordinateOrigin, describeLeegalityCoordinates, LEEGALITY_DEFAULT_COORDINATES | Read and show the coordinate setting (points or pixels@<dpi>; bottom-left or top-left). |
reference is your own id for one request, sent to Leegality as the irn; it defaults to
envelopeId. Give each attempt its own when a signer can start again.
webhookRef(rawBody) reads the provider reference from a callback without checking anything.
A server that holds several provider accounts uses it to find whose credentials must verify
the callback; never act on it before parseWebhook has accepted the same body.
checkCredentials() makes one read-only call and resolves when the provider accepts the
credentials. The Leegality adapter asks for the status of a document id that cannot exist:
an account Leegality recognises is told there is no such document, and any other answer
throws SignError('PROVIDER_ERROR').
parseWebhook throws SignError('WEBHOOK_INVALID') for any body it cannot verify, and returns
null for a verified callback that does not change the signer's status (such as a reviewer
approval). Provider failures throw SignError('PROVIDER_ERROR') with details.reason
(timeout, network, unauthorized, unavailable, rejected, not_found, ...) and
details.retryable; HTTP 429 throws RATE_LIMITED. Errors never contain the document or your
credentials, and the package does not log.
Limits: webhook bodies over 256 KB are refused before parsing, provider JSON responses over 2 MB
and signed files over maxSignedDocumentBytes are cut off while streaming, and a signing link
that is not https is treated as missing. Webhooks are not replay-protected by Leegality, so make
your handler idempotent on (providerRef, status).
Leegality options
| Option | Required | Notes |
| ------------------------ | -------- | ------------------------------------------------------------------------------------------------------------- |
| environment | yes | sandbox (https://sandbox.leegality.com/api) or production (https://app1.leegality.com/api). |
| authToken | yes | Dashboard, API Settings. Sent as X-Auth-Token. |
| privateSalt | yes | Dashboard, API Settings. Verifies webhook mac. |
| profileId | yes | The Workflow ID, or a function (request) => workflowId. |
| confirmWebhooks | no | Default true. Confirms each webhook with the Check transaction status API. |
| webhookHeader | no | { name, value } of a static header Leegality support adds to your webhooks. |
| timeoutMs | no | Default 30 000, covering the response body as well. Whole milliseconds, at most 10 minutes. |
| maxSignedDocumentBytes | no | Default 50 MB. |
| positionApi | no | Which API places signaturePositions: v2.1 (default without v4), v4 (default with v4) or off. |
| v4 | no | A v4 workflow (leegalityV4WorkflowFromPayload), for positionApi: 'v4'. |
| coordinates | no | { units: 'points' \| { pixelsPerInch }, origin: 'bottom-left' \| 'top-left' }. Default points, bottom-left. |
| baseUrl, fetch | no | Overrides for proxies and tests. baseUrl must be https (plain http only for localhost). |
Set up the Leegality workflow
Leegality's API runs a published Workflow; several settings live only in that workflow, not in the
API request. In the Leegality dashboard, for the workflow you pass as profileId:
- choose Aadhaar eSign as the signature type for the invitee;
- place the signature box (if you need different layouts, create a workflow per layout and pass
profileIdas a function); - under the invitee's custom URLs and webhooks, set the Webhook and Error Webhook to your
callbackUrl, choose webhook version 2.5, and set the Redirect URL to yourredirectUrl.
Placing the signature per request (2.1)
Leegality's v3.0 request has no field for a signature position, but its 2.1 Create API takes one
per invitee: "pass the eSign coordinates in the appearances array of the payload"
(Coordinate Picker).
By default (positionApi: 'v2.1') a request that carries signaturePositions goes to
POST /api/v2.1/sign/request with the same Auth Token (the dashboard calls it the legacy Auth
Token). The body follows the v2.1 OpenAPI schema (SignRequest, Invitee, Appearance; published
copy at https://github.com/prakharmittal/leegality-apidocs/blob/master/api_2_1.json): the file,
the irn, and one invitee with appearances (page from 1, x1/y1 lower-left and x2/y2
upper-right, whole numbers), signatures: [{ type: 'AADHAAR', config: { authTypes: ['OTP'] } }],
webhook { success, failure, version: 2.5 } set to callbackUrl, and redirectUrl. The 2.1
API takes no workflow, so profileId is not sent and the workflow's other settings do not
apply to such a request. The response is the usual wrapper with data.documentId and
data.invitations[].signUrl; the document is then followed with the same v3.x status and
download calls and verified Webhook 2.5 bodies as a v3.0 one, and providerRef is its document
id.
Placing the signature per request (v4)
Leegality's v3.0 request has no field for a signature position. Its v4 Pack API has one:
coordinates[] per invitee, with appearances[] of pageNo (from 1) and
rect { x1Axis, y1Axis, x2Axis, y2Axis }
(Send Pack for eSigning (Sync)).
With the v4 option (and positionApi: 'v4', its default then), a request that carries
signaturePositions is sent to
POST /api/v4/pack/sync with the signer's appearances at those positions, its success and
error webhooks set to callbackUrl with version 4.0, and redirectUrl as the invitee's
redirect URL. Its providerRef is v4:<packId>:<documentId>. Webhook 4.0 bodies are verified
with the same mac (HMAC-SHA1 of document.documentId) and confirmed with
Check Pack Details;
files come from Download files.
Requests without positions keep using v3.0, so both kinds of providerRef work side by side.
The v4 API refers to the workflow's document, sub-document, signer and combination by UUID.
leegalityV4WorkflowFromPayload(json) reads them, and the full workflow id, from the file the
dashboard's Download API Payload gives
(Download the v4 API payload);
nothing else of the file is kept. Ids left out are generated per request.
A position is { page, rect, pageBox }: the zero-based page, the box in PDF points from the
top-left of the page as displayed (as Field.rect), and the page's crop box in user space with
its /Rotate. Leegality does not document the unit or origin of rect; the default, PDF
points from the bottom-left of the unrotated page, follows its earlier API, which named the
corners "lower-left" and "upper-right". toLeegalityRect(position, coordinates) gives the
rectangle that is sent; check it once with a sandbox eSign and change coordinates if the
seal lands elsewhere.
What Leegality's public documentation does not cover
The adapter only does what Leegality's published API reference confirms. These gaps are handled by configuration rather than guessed:
- Signature positions, callback URL and redirect URL are not fields of the v3.0 Create eSigning request API. They come from the workflow (see above), so a v3.0 request sends none of them. Without coordinates in the workflow, Leegality puts the signature at the bottom left of every page. A v4 request sends all three.
- Units and origin of v4 coordinates are not documented; see
coordinatesabove. - Choosing Aadhaar per request is not documented; the workflow decides the eSign type.
- Webhook authenticity: the documented
macis HMAC-SHA1 of thedocumentIdonly, keyed by the Private Salt. The rest of the body is not covered, and no timestamp or replay protection is documented. That is whyconfirmWebhooksis on by default. The hex encoding is taken from the documented examples. - Signing time: no webhook or status field gives the time of signing, so
signedAtis not set. Record the time you received the verified event instead. - HTTP status codes: the reference says errors usually come back as HTTP 200 with
status: 0. Other status codes and rate limits ("fair use limits may apply") are not specified, so they are mapped generically. - Response
statuson success: the published sample showsstatus: 0beside a success message, so a returneddocumentIdis treated as success. - Webhook versions: v3.0 requests rely on version 2.5 set in the workflow; v4 requests ask for 4.0 themselves.
Roadmap
eMudhra as a second provider is planned. The EsignProvider interface is what it will
implement, so nothing in your code changes when you switch.
Docs
Guides and the full API reference are at sign.codevibe.in.
Licence
Apache-2.0 © Codevibe
The Codevibe Sign packages
| Package | What it does | Licence |
| ---------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | ---------- |
| codevibe-sign | The one library to install: API client, PDF tools, core rules, React components and a command line. | Apache-2.0 |
| @codevibe_technology/sign-core | Envelopes, routing, reminders, expiry and a hash-chained audit log. No I/O. | Apache-2.0 |
| @codevibe_technology/sign-pdf | Draws fields, appends the certificate page, seals with PAdES and verifies the seal. | Apache-2.0 |
| @codevibe_technology/sign-client | Typed client for the HTTP API, signing sessions and webhook checks. No dependencies. | Apache-2.0 |
| @codevibe_technology/sign-react | Signature pad, signing view and field placer for your own React app. | Apache-2.0 |
| @codevibe_technology/sign-templates | Templates with roles and prefilled fields, and bulk send from CSV. | Apache-2.0 |
| @codevibe_technology/sign-aadhaar | Aadhaar eSign through a licensed eSign provider (Leegality). Used by the server and the web app. | Apache-2.0 |
| @codevibe_technology/sign-server | The HTTP API and runtime: storage, mail, one-time codes, webhooks and sealing. | AGPL-3.0 |
The web app, the Docker image and the docs live in the Codevibe Sign repository. Try it free at sign.codevibe.in, or self-host it with no limits.
