Registry / security / lcs-usbtoken

lcs-usbtoken

JSON →
library1.3.0jsnpmunverified

A Node.js client library for interacting with USB tokens via WebSocket, version 1.3.0. Developed by LCS, it provides methods to connect to a WebSocket server, check health, verify PIN, list connected USB tokens, and sign documents. The library exposes a CommonJS API with callbacks, and appears to be focused on LCS-CA hardware tokens commonly used in Vietnamese digital signing. The package has no recent updates and minimal documentation, limited to a single README with example usage.

npm install lcs-usbtoken
INSTALL
IMPORT
SIG · LCS-USBTOKEN
L
lcs-usbtoken
securityjavascriptv1.3.0
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.

default
const client = require('lcs-usbtoken');
import client from 'lcs-usbtoken';
Library uses CommonJS; ESM import may not work directly without a default export.
connectWs
client.connectWs(url, callback);
Connects to a WebSocket endpoint. Callback receives connection status.
checkLogin
client.checkLogin(url, params, callback);
client.checkLogin(params, callback); // missing url
Verifies USB token PIN. params must include tokenSerial, tokenPin, listUid, certSerial, version.

Demonstrates connecting via WebSocket, health check, PIN verification, token listing, and document signing using the lcs-usbtoken library.

const client = require('lcs-usbtoken'); const wsUrl = 'ws://localhost:8080/ws'; // Connect to WebSocket client.connectWs(wsUrl, (err, response) => { if (err) { console.error('Connection failed:', err); return; } console.log('Connected:', response); // Check health client.healthcheck(wsUrl, (err, alive) => { console.log('Healthcheck:', alive); }); // Check login (verify PIN) const loginParams = { tokenSerial: 'ABC123', tokenPin: '123456', listUid: [], certSerial: '', version: '1.0.0' }; client.checkLogin(wsUrl, loginParams, (err, result) => { console.log('Login result:', result); }); // Get USB token info const getTokenParams = { GetUsbToken: { tokenSerial: '', version: '1.0.0' } }; client.getUsbToken(wsUrl, getTokenParams, (err, tokens) => { console.log('USB tokens:', tokens); }); // Sign a document const signParams = { tokenInfoDto: { tokenSerial: 'ABC123', tokenPin: '123456', version: '1.0.0' }, dataList: [ { originalFileName: 'doc.pdf', originalFile: 'base64encodedContent' } ] }; client.signDoc(wsUrl, signParams, (err, signed) => { console.log('Signed document:', signed); }); });
Debug
Known issues
gotchaAll methods require a WebSocket URL as the first argument; omitting it will cause undefined behavior.
fix
Always pass the WebSocket URL as the first argument to each function.
affects: >=1.0.0
gotchaThe library uses callback-based async patterns; promises or async/await are not supported natively.
fix
Wrap calls in a Promise or use util.promisify for modern JavaScript.
affects: >=1.0.0
breakingThe input parameters for 'checkLogin' require a 'listUid' array; passing a non-array may throw an error.
fix
Always provide an empty array '[]' if no UIDs are needed.
affects: >=1.0.0
gotchaToken serial must match exactly as reported by getUsbToken; case-sensitive.
fix
Retrieve token serial from getUsbToken response and use it exactly.
affects: >=1.0.0
gotchaThe 'signDoc' method expects 'originalFile' to be base64-encoded content; passing raw binary will result in errors.
fix
Base64-encode the file content before passing to signDoc.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: client.connectWs is not a function
Incorrect import or require path; library not installed properly.
fix
Ensure the package is installed: 'npm install lcs-usbtoken' and require with correct casing.
Error: getaddrinfo ENOTFOUND ws://localhost:8080/ws
WebSocket URL incorrectly formatted or server not running.
fix
Use a valid WebSocket URL without 'ws://' in the hostname part; e.g., 'ws://localhost:8080/ws'.
MsgCode: SERIAL_USB_NOT_MATCH
Token serial provided does not match any connected USB token.
fix
Call getUsbToken first to list available tokens and use the exact serial.
MsgCode: CKR_PIN_INCORRECT
PIN provided is incorrect for the specified token.
fix
Verify the PIN and try again; note that the library does not expose a way to unblock PIN.
Upgrade
Version history
1.3.0latest on npm
Audit
Dependencies
websocketrequiredWebSocket client implementation used for communication with the token signing service
Agent activity
6 hits · last 30 days
node
6
Resources
lcs-usbtoken — npm install lcs-usbtoken · libregistry