Registry / security / smart-id-rest

smart-id-rest

JSON →
library1.2.4jsnpmunverified

smart-id-rest is a Node.js client for the Smart-ID authentication and signing API. Version 1.2.4 is the current stable release. It provides methods for authentication and digital signing using Estonian e-residency Smart-ID certificates. The library abstracts the REST API, handling session creation and status polling. It is particularly useful for integrating Smart-ID into Node.js applications requiring strong authentication or digital signatures. The package is maintained by CitizenOS and has a small footprint with no required dependencies.

npm install smart-id-rest
INSTALL
IMPORT
SIG · SMART-ID-REST
S
smart-id-rest
securityjavascriptv1.2.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

smartIdClient
const smartIdClient = require('smart-id-rest')();
import smartIdClient from 'smart-id-rest';
The package exports a factory function that must be invoked. ESM import is not supported natively.
init
smartIdClient.init({ hostname, apiPath, relyingPartyUUID, replyingPartyName, issuers });
init must be called with an object containing all required fields before any other methods.
authenticate
const result = await smartIdClient.authenticate(nationalIdentityNumber, countryCode);
Returns a promise with sessionId and sessionHash. The countryCode is the two-letter country code (e.g., 'EE').
signature
const result = await smartIdClient.signature(nationalIdentityNumber, countryCode, hashBase64);
hashBase64 must be a base64-encoded SHA-256 hash of the data to sign.
statusAuth
const authStatus = await smartIdClient.statusAuth(sessionId, sessionHash);
Polls the authentication session status. Returns the API response object.
statusSign
const signStatus = await smartIdClient.statusSign(sessionId);
Polls the signing session status. Returns the API response object.

Configures the Smart-ID client with environment variables, authenticates a test user, and retrieves personal information from the certificate.

const smartIdClient = require('smart-id-rest')(); smartIdClient.init({ hostname: process.env.SMART_ID_HOSTNAME || 'https://sid.demo.sk.ee', apiPath: process.env.SMART_ID_API_PATH || '/smart-id/v1', relyingPartyUUID: process.env.SMART_ID_RELYING_PARTY_UUID || '', replyingPartyName: process.env.SMART_ID_RELYING_PARTY_NAME || '', issuers: [ { C: 'EE', O: 'AS Sertifitseerimiskeskus', OID: 'NTREE-10747013', CN: 'TEST of EID-SK 2015' } ] }); async function main() { try { const authResult = await smartIdClient.authenticate('30303039914', 'EE'); console.log('Session ID:', authResult.sessionId); const status = await smartIdClient.statusAuth(authResult.sessionId, authResult.sessionHash); const personalInfo = await smartIdClient.getCertUserData(status.cert.value); console.log('Personal info:', personalInfo); } catch (error) { console.error('Error:', error); } } main();
Debug
Known issues
gotchaThe package uses CommonJS require(). ESM import or dynamic import may not work.
fix
Use const smartIdClient = require('smart-id-rest')();
affects: >=1.0
gotchaThe init() method must be called before any other methods, and all properties (hostname, apiPath, relyingPartyUUID, replyingPartyName, issuers) are required.
fix
Ensure the configuration object has all required fields.
affects: >=1.0
gotchaThe hash for signing must be SHA-256, base64-encoded. Using other hash algorithms or encoding may cause errors.
fix
Use crypto.createHash('SHA256').update(data).digest('base64') and then convert to base64 if needed.
affects: >=1.0
gotchaThe example uses 'replyingPartyName' (typo) but the property is 'relyingPartyName'. Using the wrong name may silently fail.
fix
Use the correct property name: relyingPartyName.
affects: >=1.0
gotchaThe issuers array must contain objects with all four fields: C, O, OID, CN. Missing fields may cause validation errors.
fix
Ensure each issuer object has all required fields.
affects: >=1.0
Errors
Common errors & fixes
TypeError: smartIdClient.authenticate is not a function
init() was not called or was called incorrectly.
fix
Ensure smartIdClient.init(config) is called before using authenticate.
Error: Request failed with status code 400
Missing or incorrect configuration parameters (hostname, apiPath, etc.) or invalid authentication parameters.
fix
Check that env variables are set correctly and that nationalIdentityNumber and countryCode are valid.
Error: Certificate validation failed
The issuer certificate is not in the trusted list or the certificate chain is invalid.
fix
Verify that the issuers array contains the correct certificate authorities for the Smart-ID environment.
Upgrade
Version history
1.2.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
23 hits · last 30 days
node
20
OpenAI (training)
2
Resources
smart-id-rest — npm install smart-id-rest · libregistry