Introduction
@jx_code/rsimzo-client
A lightweight JavaScript client for interacting with the RsImzo provider β allowing you to authenticate users, retrieve certificates, and sign documents using EDS keys.
@jx_code/rsimzo-client
A lightweight JavaScript client for interacting with the RsImzo provider β allowing you to authenticate users, retrieve certificates, and sign content using EDS keys through secure popup and iframe communication.
π¦ Installation
# with npm
npm install @jx_code/rsimzo-client
# or with pnpm
pnpm add @jx_code/rsimzo-client
# or with yarn
yarn add @jx_code/rsimzo-client
π Getting Started
1. Import and Initialize
import { RsimzoClient } from "@jx_code/rsimzo-client";
const rsimzo = new RsimzoClient({
publicKey: "YOUR_PUBLIC_KEY",
locale: "uz", // optional, defaults to 'uz'
});
β οΈ
publicKeyis required when creating a new instance.
If not provided, the constructor throws an error.
π§© API Reference
new RsimzoClient(options)
Parameters:
| Option | Type | Required | Default | Description |
|---|---|---|---|---|
publicKey | string | β Yes | β | The public key provided by RsImzo |
locale | 'uz' | 'ru' | 'en' | β No | 'uz' | Language used for popup interfaces |
Example:
const rsimzo = new RsimzoClient({ publicKey: "ABC123", locale: "ru" });
getCertificates(options?)
Retrieves the list of available EDS certificates from the RsImzo provider using an invisible iframe.
Parameters:
| Option | Type | Required | Default | Description |
|---|---|---|---|---|
locale | 'uz' | 'ru' | 'en' | β | current instance locale | Locale for the provider interface |
Returns:
Promise<RsPostMessageResult<{ serialNumber: string; owner: string }[]>>;
Example:
const result = await rsimzo.getCertificates();
console.log(result);
sign(serialNumber, content, options?)
Opens a popup for signing a given piece of content using a certificate.
Parameters:
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
serialNumber | string | β Yes | β | The certificate serial number to use |
content | string | β Yes | β | The content (e.g., base64 string) to sign |
options.locale | 'uz' | 'ru' | 'en' | β No | instance locale | Language of the signing popup |
options.attached | boolean | β No | true | Whether the signature should be attached |
Returns:
Promise<RsPostMessageResult<string>>;
Example:
const signed = await rsimzo.sign("123456789", "Hello world!");
console.log(signed);
auth(options?)
Performs an authentication flow using RsImzo, returning an identity token or user data.
Parameters:
| Option | Type | Required | Default | Description |
|---|---|---|---|---|
locale | 'uz' | 'ru' | 'en' | β | instance locale | Locale for the authentication popup |
Returns:
Promise<RsPostMessageResult<string>>;
Example:
const authResult = await rsimzo.auth();
console.log(authResult);
βοΈ Error Handling
Every method returns a standard structure:
type RsPostMessageResult<T> = {
data: T | null;
error?: {
errorCode: number;
errorMessage: string;
};
};
| Code | Message | Description |
|---|---|---|
13 | Incorrect password | Wrong password entered during signing |
10001 | Window closed | The popup was closed by the user |
10002 | Fetch token error | Failed to fetch or validate token |
10003 | No result | Action completed with no result |
10004 | Certificate not found | No matching EDS certificate found |
10005 | Invalid token | Token validation failed |
10006 | Invalid parameters | Missing or invalid input parameters |
10008 | Timeout | Operation took longer than 60 seconds |
10009 | Popup blocked | Browser prevented opening popup window |
π Example Integration
import { RsimzoClient } from "@jx_code/rsimzo-client";
const rsimzo = new RsimzoClient({ publicKey: "ABC123", locale: "uz" });
async function run() {
const auth = await rsimzo.auth();
if (auth.error) return console.error(auth.error);
const certs = await rsimzo.getCertificates();
if (certs.error) return console.error(certs.error);
const signed = await rsimzo.sign(certs.data[0].serialNumber, "text-to-sign");
console.log("Signed data:", signed);
}
run();