Git Product home page Git Product logo

ssp's Introduction

NPM Version Codecov GitHub Actions Workflow Status GitHub License

@kybarg/ssp

Node.JS implemenation of Encrypted Smiley ® Secure Protocol (eSSP, SSP)

Supported devices: NV9USB, NV10USB, BV20, BV50, BV100, NV200, NV200 Spectral, SMART Hopper, SMART Payout, NV11, NV22

Warning

NV11 is not fully tested and supported. Maintainer is required.

Table of Contents

  1. Basis usage
  2. Methods
  3. Documentation

Basis usage

const sspLib = require('@kybarg/ssp')

let eSSP = new sspLib({
  id: 0x00,
  timeout: 3000,
  fixedKey: '0123456701234567',
})

eSSP.on('READ_NOTE', result => {
  console.log('READ_NOTE', result)
})

eSSP.command('GET_SERIAL_NUMBER').then(result => {
  console.log('Serial number:', result.info.serial_number)
  return
})

const portOptions = { baudRate: 9600 }

eSSP.open('COM1', portOptions)

Config values

const options = {
  fixedKey: '123', // device internal encryption key
  encryptAllCommand: true, // should command commands also be encrypted
  id: 0, // device id in case multiple acceptors connected to the host
  timeout: 1000, // command response timeout after wich command considered failed
  commandRetries: 20, // how many time to retry before throwing error or emitting ERROR event
}

Methods

All methods return Promise

  • eSSP.open('COM1') - Connect device
  • eSSP.close() - Disconnect device
  • eSSP.initEncryption() - Initializing Diffie-Hellman key exchange and enable encryption
  • eSSP.enable() - Enable device and start listen events
  • eSSP.disable() - Disable device and stop listen events
  • eSSP.poll() - Start/Stop polling the device
  • eSSP.command('COMMAND_NAME') - Execute command and get answer

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

ssp's People

Contributors

kybarg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

ssp's Issues

COMMAND_CANNOT_BE_PROCESSED

I have a problem with the Smart Payout, I tried to use the comand SET_DENOMINATION_ROUTE but always get this error:

{
  command: 'SET_DENOMINATION_ROUTE',
  tx: {
    createdAt: 1715715364874,
    encrypted: <Buffer 7f 00 11 7e 3c 07 6d f5 89 ed 64 2e d1 69 43 3d 8a 4b 53 c9 ff 01>,
    plain: <Buffer 7f 00 09 3b 00 14 00 00 00 4d 58 4e 3c d2>
  },
  rx: {
    createdAt: 1715715364936,
    encrypted: <Buffer 7f 00 11 7e 6e a9 43 1b fd 45 b1 47 b4 34 24 82 46 51 b0 11 73 97>,
    plain: <Buffer 7f 00 01 f5 3e 0a>
  }
}
{
  success: false,
  status: 'COMMAND_CANNOT_BE_PROCESSED',
  command: 'SET_DENOMINATION_ROUTE',
  info: { errorCode: undefined, error: 'Unknown error' }
}

This is the code:

const SSP = require('./lib/index.js')
const channels = [{ value: 0, country_code: 'XXX' }]

const serialPortConfig = {
  baudRate: 9600, // default: 9600
  dataBits: 8, // default: 8
  stopBits: 2, // default: 2
  parity: 'none', // default: 'none'
}

const eSSP = new SSP({
  id: 0x00,
  timeout: 1000, // default: 3000
  encryptAllCommand: true, // default: true
  fixedKey: '0123456701234567', // default: '0123456701234567'
})

eSSP.on('DATA_RECEIVED', data => {
  console.log(data)
})

eSSP.on('DEBUG', data => {
  console.log(data)
})

eSSP.on('OPEN', () => {
  console.log('Port opened!')
})

eSSP.on('CLOSE', () => {
  console.log('Port closed!')
})

eSSP.on('READ_NOTE', result => {
  console.log('READ_NOTE', result)
  console.log(channels[result.channel])

  if (channels[result.channel].value === 500) {
    eSSP.command('REJECT_BANKNOTE')
  }
})

eSSP.on('NOTE_REJECTED', result => {
  console.log('NOTE_REJECTED', result)

  eSSP.command('LAST_REJECT_CODE').then(result => {
    console.log(result)
  })
})

eSSP
  .open('COM5', serialPortConfig)
  .then(() => eSSP.command('SYNC'))
  .then(() => eSSP.command('HOST_PROTOCOL_VERSION', { version: 6 }))
  .then(() => eSSP.initEncryption())
  .then(() => eSSP.command('GET_SERIAL_NUMBER'))
  .then(result => {
    console.log(eSSP.keys.encryptKey)
    console.log('SERIAL NUMBER:', result.info.serial_number)
    return
  })
  .then(() => eSSP.command('UNIT_DATA'))
  .then(() => eSSP.command('SETUP_REQUEST'))
  .then(result => {
    for (let i = 0; i < result.info.channel_value.length; i++) {
      channels[i + 1] = {
        value: result.info.expanded_channel_value[i],
        country_code: result.info.expanded_channel_country_code[i],
      }
    }
    console.log('channels', channels)
    return
  })
  .then(() =>
    eSSP.command('SET_CHANNEL_INHIBITS', {
      channels: Array(channels.length).fill(1),
    }),
  )
  .then(() => eSSP.command('SET_DENOMINATION_ROUTE', { route: 'payout', value: 20, country_code: 'MXN', isHopper: false }))
  .then(() => eSSP.command('SET_DENOMINATION_ROUTE', { route: 'payout', value: 50, country_code: 'MXN', isHopper: false }))
  .then(() => eSSP.command('SET_DENOMINATION_ROUTE', { route: 'payout', value: 100, country_code: 'MXN', isHopper: false }))
  .then(() => eSSP.enable())
  .then(() => {
    console.log('GO!!!')
  })
  .catch(error => {
    console.log(error)
  })`

COMMAND_CANNOT_BE_PROCESSED

Hi,

I'm encountering an issue where I cannot payout money. Using ITL Validator Manager I am able to do that.

eSSP.command('PAYOUT_AMOUNT', {
            amount: 100,
            country_code: 'EUR',
            test: false,
        })
COM <- 7f90117eb80592fe362a534ed53005778bb6cb4acaa2 SET_CHANNEL_INHIBITS 3
COM -> 7f90117e67b8b87b349df26aae8cbb855d715d522c83 ENABLE
Decrypted: 0104000000f0d8482da8660f6b2b390c
{ success: true, status: 'OK', command: 'ENABLE', info: {} }
COM <- 7f10117e7b5acc4cbe318ab26e8d46ad5e684868cfb1 ENABLE 4
[
  { value: 0, country_code: 'EUR' },
  { value: 1, country_code: 'EUR' },
  { value: 2, country_code: 'EUR' },
  { value: 3, country_code: 'EUR' },
  { value: 4, country_code: 'EUR' },
  { value: 5, country_code: 'EUR' },
  { value: 6, country_code: 'EUR' },
  { value: 7, country_code: 'EUR' }
]
{ success: true, status: 'OK', command: 'ENABLE', info: {} }
Device is active
COM -> 7f10117e6742abeb71567470fa7e34a722da284ceb65 POLL
Decrypted: 0105000000f01f52ccc84c7c2b7e467c
{ success: true, status: 'OK', command: 'POLL', info: {} }
COM <- 7f90117e55997e56ba741910f02dc5eeda58473eef04 POLL 5
COM -> 7f90117e238435165d76cb3ac4523341916941b20bef PAYOUT_AMOUNT
Decrypted: 0206000000f502f444a932e784def63f
{
  success: false,
  status: 'COMMAND_CANNOT_BE_PROCESSED',
  command: 'PAYOUT_AMOUNT',
  info: { errorCode: 2, error: 'Cannot pay exact amount' }
}
COM <- 7f10117ee7c054dcca0fc7e8e13cf6a93d07b9bccb8f PAYOUT_AMOUNT 6
COM -> 7f10117e51b9222b7d083bc5079fb1ba0991ce36059e POLL
Decrypted: 0107000000f0141ebe17cefdf15d0d52
{ success: true, status: 'OK', command: 'POLL', info: {} }
COM <- 7f90117ea9389940a5ebd8af20462e82d396f8f35719 POLL 7
{
  success: false,
  status: 'COMMAND_CANNOT_BE_PROCESSED',
  command: 'PAYOUT_AMOUNT',
  info: { errorCode: 2, error: 'Cannot pay exact amount' }
}

However, using Payout by Denomination it works:

then(() => eSSP.command('PAYOUT_BY_DENOMINATION', {
        value: [{
            number: 1,
            denomination: 100,
            country_code: 'EUR',
        }, ],
        test: false,
    }))
    .then(result => {
        console.log(result)

        return
    })
    .catch(error =>

eSSP address

hello partners how is possible define a address on the case of smart coint hopper is running on address 16

regards!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.