Giter VIP home page Giter VIP 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
})

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

İrem "Siren" Kuyucu avatar Víctor Hugo Baez González avatar Victor Manuel Jacobo Perez 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)
  })`

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.