npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@reixtech/smartid-ts

v0.0.4

Published

Typescript client for Smart-ID V2

Downloads

5

Readme

SMART-ID Node typescript client for version 2

This is a Node client for the SMART-ID API version 2.

Important

  • Note that this package is in early development.
  • The API for this package is subject to change.

Updates

Version 0.0.4 - To provide flexibility, added two new methods that can be used separately from the initial authenticateWithPNO.

  • createAuthData - Creates the hash and verification code for the authentication request. You can store and use them later to trigger actual authentication flow using triggerAuth.
  • triggerAuth - Triggers the actual authentication flow using the hash and verification code created by createAuthData.

Installation

pnpm install @reixtech/smartid-ts

Smart-ID Documentation

https://github.com/SK-EID/smart-id-documentation

Usage

Create smartid client

import {
    createSmartIDClient,
    makeAllowedInteractionsBuilder,
} from '@reixtech/smartid-ts';

// Helper function to create allowed interactions.
// Keep in mind that duplicate interactions are not allowed and will throw an error.
const allowedInteractionsOrder = makeAllowedInteractionsBuilder()
    .add(
        'confirmationMessageAndVerificationCodeChoice',
        'Message to display in the Smart-ID app.',
    )
    .add('confirmationMessage', 'Message to display in the Smart-ID app.')
    .add('verificationCodeChoice', 'Message to display in the Smart-ID app.')
    .build();

const smartIdClient = createSmartIDClient(
    {
        // URL of the Smart-ID API
        host: 'https://sid.demo.sk.ee/smart-id-rp/v2',
        // UUID of the relying party
        relyingPartyUUID: '00000000-0000-0000-0000-000000000000',
        // Name of the relying party
        relyingPartyName: 'DEMO',
        // Allowed interactions
        allowedInteractionsOrder,
    },
);

Authenticate with personal identification code and PIN callback

import {
    createSmartIDClient,
    makeAllowedInteractionsBuilder,
    isEndResultError,
    isRequestError,
} from '@reixtech/smartid-ts';

// ... create smartid client

try {
    const response = await smartIdClient.authenticateWithPNO(
        {
            // Country code for person (EE, LT, LV)
            countryCode: 'EE',
            // National identity number for person
            nationalIdentityNumber: '39303292707',
        },
        async (pin) => {
            // You can use this callback to show the verification code to the user
            // once this promise resolves, then actual request is sent to the users phone.
            // Without it Smart ID app will popup a dialog before user can see the verification code.
            await new Promise((resolve) => setTimeout(resolve, 5000));
        },
    );
    
    // You can use the response to do something with the authentication result
    console.log('Authentication response:', response);
} catch (e) {
    if (isEndResultError(e)) {
        // Error is now in the form of EndResultError
        // Triggered when the user cancels the request, or the request times out etc
    }

    if (isRequestError(e)) {
        // Error is now in the form of RequestError
        // Triggered when the request to the API fails, NOT FOUND, UNDER MAINTENANCE, etc.
    }
    
    // Handle other errors
    // Like certificate validation errors, etc.
}

Create authentication data and trigger authentication request separately

import {
    createSmartIDClient,
    makeAllowedInteractionsBuilder,
    isEndResultError,
    isRequestError,
} from '@reixtech/smartid-ts';

// ... create smartid client

try {
    const { hash, verificationCode, randomBytes, identifier } =
        smartIdClient.createAuthData({
            countryCode: 'EE',
            nationalIdentityNumber: '39303292707',
        });

    // Show the verificationCode to user and do any magic you like...

    // ...

    // Trigger the authentication request using previously generated data.

    const { parsedSubject, response } = await smartIdClient.triggerAuth({
        hash,
        randomBytes,
        identifier,
    });

    // Do something with the parsedSubject and response...
} catch (e) {
    if (isEndResultError(e)) {
        // Error is now in the form of EndResultError
        // Triggered when the user cancels the request, or the request times out etc
    }

    if (isRequestError(e)) {
        // Error is now in the form of RequestError
        // Triggered when the request to the API fails, NOT FOUND, UNDER MAINTENANCE, etc.
    }
    
    // Handle other errors
    // Like certificate validation errors, etc.
}