Skip to content

Latest commit

 

History

40 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Smart-ID rest client for Node.js

A modern, TypeScript-based client for the Smart-ID REST API.

Features

  • Full TypeScript support with type definitions.
  • Class-based API with backward-compatible factory function.
  • Uses axios for robust HTTP requests.
  • Comprehensive certificate and signature validation.
  • Supports both RSA and ECC (Elliptic Curve) signatures.

Installation

npm install smart-id-rest

Usage

TypeScript / ES Modules

import { SmartId, SmartIdOptions } from 'smart-id-rest';

const options: SmartIdOptions = {
    hostname: "sid.demo.sk.ee",
    apiPath: "/smart-id-rp/v1",
    relyingPartyUUID: "00000000-0000-0000-0000-000000000000",
    relyingPartyName: "DEMO",
    issuers: [
        {
          "C": "EE",
          "O": "AS Sertifitseerimiskeskus",
          "OID": "NTREE-10747013",
          "CN": "TEST of EID-SK 2015"
        }
    ]
};

const smartId = new SmartId(options);

CommonJS (Backward Compatible)

const smartId = require('smart-id-rest')();

smartId.init({
    hostname: "sid.demo.sk.ee",
    apiPath: "/smart-id-rp/v1",
    relyingPartyUUID: "00000000-0000-0000-0000-000000000000",
    relyingPartyName: "DEMO", // Corrected typo (relying vs replying)
    issuers: [...]
});

Authenticate

try {
    const result = await smartId.authenticate(nationalIdentityNumber, countryCode);
    console.log(`Challenge ID: ${result.challengeID}`);
    
    // Poll for status
    const authResult = await smartId.statusAuth(result.sessionId, result.sessionHash);
    
    if (authResult.result.endResult === 'OK') {
        console.log('Authentication successful');
        console.log('User Info:', authResult.personalInfo);
    }
} catch (error) {
    if (error.name === 'SmartIdError') {
        console.error(`Smart-ID error: ${error.message} (Code: ${error.code})`);
    } else {
        console.error('Unexpected error:', error);
    }
}

Sign

const crypto = require('crypto');
const hash = crypto.createHash('sha256').update('Sign this text').digest();
const sessionHash = hash.toString('base64');

const result = await smartId.signature(nationalIdentityNumber, countryCode, sessionHash);
const signResult = await smartId.statusSign(result.sessionId);

if (signResult.result.endResult === 'OK') {
    console.log('Signature successful');
    console.log('Signature value:', signResult.signature.value);
}

API

SmartId Class

  • constructor(options?: SmartIdOptions)
  • init(options: SmartIdOptions): void
  • authenticate(pid: string, countryCode?: string): Promise<AuthenticationResponse>
  • getSessionStatus(sessionId: string, timeoutMs?: number): Promise<SessionStatusResponse>
  • statusAuth(sessionId: string, sessionHash: string, timeoutMs?: number): Promise<SessionStatusResponse>
  • getUserCertificate(pid: string, countryCode?: string): Promise<string>
  • signature(pid: string, countryCode: string, sessionHash: string): Promise<SignatureResponse>
  • statusSign(sessionId: string, timeoutMs?: number): Promise<SessionStatusResponse>

Development

Run tests

npm test

Build

npm run build

Credits

About

smart-id-rest

Resources

Stars

2 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages