eimzo-ts

API reference

import { createEimzo, createFetchBackend, DEV_API_KEYS, isEimzoError } from 'eimzo-ts';
import type { EimzoKey, EimzoOptions, EimzoBackend, EimzoErrorCode } from 'eimzo-ts';

Without a bundler: <script src="https://unpkg.com/eimzo-ts@0.4/dist/index.global.js"></script> exposes the same exports on window.EimzoClient.

createEimzo(options)

OptionDefaultDescription
apiKeys—{ domain: key } or [domain, key, …]. DEV_API_KEYS covers localhost and 127.0.0.1. If omitted, the apikey call is skipped.
backend—{ getChallenge?, login?, timestamp? } or createFetchBackend(…).
minVersion'4.86'Older E-IMZO → OUTDATED_VERSION.
locale'ru''ru', 'uz-Latn', 'uz-Cyrl', 'kaa', 'en', or a custom code with messages.
messages—Override or add texts: { en: { WRONG_PASSWORD: '…' } } (strings with {param} placeholders; JSON catalogs are published as eimzo-ts/locales/ru.json etc.). Missing texts fall back to messages.ru, then to built-in Russian.
autoReloadKeytrueWhen E-IMZO no longer knows the keyId, load the same key again and retry once.
timeoutMsnoneTimeout of every E-IMZO call. Signing waits for the user; for one operation use signal: AbortSignal.timeout(ms).
url, WebSocketImpl, transport—Custom WebSocket URL or implementation, or a (request, { signal }) => Promise<response> function for tests.

Methods

MethodReturnsDescription
init(){ major, minor }Version check and API keys. Called automatically; cached.
getVersion(){ major, minor }Installed E-IMZO version.
listKeys()EimzoKey[]CN, TIN, PINFL, UID, O, T, serialNumber, validFrom, validTo, expired. Keys without TIN and PINFL are skipped.
listDevices(){ idcard, baikey, ckc }Connected hardware devices.
loadKey(key, { verifyPassword })keyIdLoads a key or 'idcard' | 'baikey' | 'ckc'. Unloads the previous key.
sign(data, { detached, base64, keyId })base64 PKCS#7data: string (UTF-8), Uint8Array, ArrayBuffer. Attached by default.
signFile(blob, { detached, maxSize, keyId })base64 PKCS#7Detached by default; 10 MB limit by default.
login(key)backend resultgetChallenge → loadKey → sign → backend.login.
signDocument(data, options)base64 PKCS#7sign → backend.timestamp.
unloadKey()—Removes the key from E-IMZO. Call on logout.
call(plugin, name, args)raw responseAny E-IMZO function.
keyId, locale, setLocale(), t(error)Current key; error message language.

loadKey, unloadKey, sign, signFile, login and signDocument run one at a time.

Cancellation

Every method except unloadKey accepts { signal } (an AbortSignal), like fetch. An aborted call rejects with signal.reason (an AbortError by default), not with EimzoError.

const controller = new AbortController();
const keys = await eimzo.listKeys({ signal: controller.signal });
await eimzo.sign(data, { signal: AbortSignal.timeout(60_000) });

A call that is still queued, or still waiting for init(), never reaches E-IMZO. A password window that E-IMZO has already opened stays open; the next queued operation waits for it, so a second window never appears. A key loaded by an aborted loadKey() or login() is unloaded again.

createFetchBackend(options)

OptionRequestExpected response
challengeUrlGET, not cached{"status":1,"challenge":"..."}
loginUrlPOST, PKCS#7 as text/plainany JSON, returned from login() as is; 204 → null
timestampUrlPOST, PKCS#7 as text/plain{"status":1,"pkcs7b64":"..."}
initMerged into every request: headers, credentials.
fetchCustom fetch implementation.

→ BACKEND_ERROR: a non-2xx response, a network failure, a non-JSON 200 response, and for challenge and timestamp also a status other than 1 (when present) or an empty challenge / pkcs7b64. The login response belongs to your app and is not inspected.

Errors

Every error is an EimzoError: code, params, localized message, E-IMZO's reason and status, WebSocket wsCode, backend httpStatus. Check with isEimzoError(e, 'CODE').

Codes: NOT_INSTALLED, WEBSOCKET_UNSUPPORTED, NOT_IN_BROWSER, TIMEOUT, OUTDATED_VERSION, API_KEY_REJECTED, WRONG_PASSWORD, CANCELLED, KEY_NOT_FOUND, FILE_TOO_LARGE, KEY_NOT_LOADED, BACKEND_NOT_CONFIGURED, BACKEND_ERROR, EIMZO_ERROR. What each one means: troubleshooting.

Other exports

formatEimzoError(error, locale, overrides), parseX500, parseCertificateInfo, createWebSocketTransport, createCapiwsTransport, createDefaultTransport, defaultEimzoUrl, DEFAULT_MAX_FILE_SIZE, locale objects ru, uzLatn, uzCyrl, kaa, en, builtinMessages, DEFAULT_LOCALE.