Installation for frontend
Open your terminal and use the following command to install the plugin into your project.
npm install @jx_code/rsimzo-client
Usage
new RsimzoClient(options)
Class initialization
import { RsimzoClient, RsOptions } from "@jx_code/rsimzo-client"; const options: RsOptions = { paths: { fetchToken: '/path/to/generate/token' } } const rsimzo = new RsimzoClient(options)
Possible parameters options: RsOptions
baseURL
- Type:
string
- Default:
window.location.origin
Base URL used for all HTTP requests in the application.
locale
- Type:
string
- Default:
en
Specifies the supported languages of the application. Possible values:
en
, ru
, uz
, uz-kr
.headers
- Type:
Record<string, string>
- Default:
{}
Metadata for requests containing information about the request or transmitted data. For example, can be used to pass
Authorization
headers.paths.generateTokenrequired
- Type:
string
URL for the API used to generate tokens.
instantCertsFetch
- Type:
boolean
- Default:
false
If set to true,
rsimzo.getCertificates()
method will return a list of all certificates without user confirmation.storage
- Type:
boolean | StorageOptions
- Default:
true
Controls whether the results of
rsimzo.getCertificates()
method are saved in localStorage
. Value can be boolean or StorageOptions object.storage.prefix
- Type:
string
- Default:
rs.
Prefix used for saving data in
localStorage
Fields
rsimzo.certificates
- Type:
RsCertificate[]
List of certificates stored in
localStorage
. If no data is present in localStorage
, returns an empty array []
const list = rsimzo.certificates console.log(list)
interface RsCertificate { pin?: string tin?: string address: string country: string expireAt: number expireFrom: number fullName: string serial: string uid: string isLegalEntity: boolean orgName?: string isExpired: boolean }
Methods
rsimzo.getCertificates(options?: {locale: string, instantCertsFetch: boolean})
- Type:
RsCertificate[] | null
Opens the rs-imzo.uz window to synchronize keys. After calling the method, a window will open where the user must select EDS keys to upload to your site. Key data can be saved in
localStorage
. If instantCertsFetch
is set to true
, the window closes automatically after saving all client certificates.const { data: list } = await rsimzo.getCertificates() if (list) { console.log(list) }
If the client closes the window, the method will return null
Possible parameters options
locale
- Type:
string
Specifies the supported languages of the application. Possible values:
en
, ru
, uz
, uz-kr
.instantCertsFetch
- Type:
boolean
If set to true,
rsimzo.getCertificates()
method will return a list of all certificates without user confirmation.rsimzo.sign(serial: string, content: string, options?: RsSignOptions)
- Type:
string | null
Opens the rs-imzo.uz window to sign a document. After calling the method, a window opens where the user must enter a password. Method result is
pkcs7
const content = 'string you want to sign' const serial = 'get serial number from rsimzo.getCertificates() method' const { data: pkcs7 } = await rsimzo.sign(serial, btoa(content)) console.log(pkcs7)
The content to be signed must be in base64
format.
Possible parameters options: RsSignOptions
locale
- Type:
string
Specifies the supported languages of the application. Possible values:
en
, ru
, uz
, uz-kr
.attached
- Type:
boolean
- Default:
true
Attaches the signed content to the final
pkcs7
.rsimzo.auth(options?: RsAuthOptions)
- Type:
string | null
Opens the rs-imzo.uz window to authenticate a document. After calling the method, a window opens where the user must select a key and enter a password. Method result is
pkcs7
const { data: pkcs7 } = await rsimzo.auth() console.log(pkcs7)
Possible parameters options: RsAuthOptions
locale
- Type:
string
Specifies the supported languages of the application. Possible values:
en
, ru
, uz
, uz-kr
.Error Handling
For each request, you should check for errors
const { error } = await rsimzo.sign(serial, btoa(content)) if(error && error.errorCode === 13) { console.log('Invalid password') }
error
parameters
errorCode
- Type:
number
Unique error code
13
- Invalid password10001
- Window closed10002
- HTTP request error10003
- Action completed with no result10004
- Certificate not found10005
- Invalid token10006
- Incorrect parameters received
errorMessage
- Type:
string
Error message. The text is always in English. If a translation is needed, use
errorCode
rawError
- Type:
any
Raw error