UNPKG

@ledgerhq/hw-transport-mocker

Version:

Ledger Hardware Wallet mocker utilities used for tests

160 lines (99 loc) 4.98 kB
<img src="https://user-images.githubusercontent.com/211411/34776833-6f1ef4da-f618-11e7-8b13-f0697901d6a8.png" height="100" /> ## @ledgerhq/hw-transport-mocker Library for Ledger Hardware Wallets. [Github](https://github.com/LedgerHQ/ledgerjs/), [Ledger Devs Slack](https://ledger-dev.slack.com/) ## API <!-- Generated by documentation.js. Update this documentation by updating the source code. --> #### Table of Contents - [createTransportRecorder](#createtransportrecorder) - [Parameters](#parameters) - [createTransportReplayer](#createtransportreplayer) - [Parameters](#parameters-1) - [RecordStoreInvalidSynthax](#recordstoreinvalidsynthax) - [Parameters](#parameters-2) - [RecordStoreQueueEmpty](#recordstorequeueempty) - [RecordStoreWrongAPDU](#recordstorewrongapdu) - [Parameters](#parameters-3) - [RecordStoreRemainingAPDU](#recordstoreremainingapdu) - [Parameters](#parameters-4) - [RecordStoreOptions](#recordstoreoptions) - [Properties](#properties) - [RecordStore](#recordstore) - [Parameters](#parameters-5) - [isEmpty](#isempty) - [recordExchange](#recordexchange) - [Parameters](#parameters-6) - [replayExchange](#replayexchange) - [Parameters](#parameters-7) - [ensureQueueEmpty](#ensurequeueempty) - [toString](#tostring) - [fromString](#fromstring) - [Parameters](#parameters-8) ### createTransportRecorder decorate a real transport and proxy it to record the APDUs. #### Parameters - `DecoratedTransport` **Class&lt;Transport&lt;any>>** : an actual transport class. Like @ledgerhq/hw-transport-webusb - `recordStore` **[RecordStore](#recordstore)** : a record store to record the apdu in. Returns **Class&lt;Transport&lt;any>>** ### createTransportReplayer create a transport replayer with a record store. #### Parameters - `recordStore` **[RecordStore](#recordstore)** Returns **Class&lt;Transport&lt;any>>** ### RecordStoreInvalidSynthax thrown by the RecordStore.fromString parser. #### Parameters - `message` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** ### RecordStoreQueueEmpty thrown by the replayer if the queue is empty ### RecordStoreWrongAPDU thrown by replayer if it meets an unexpected apdu #### Parameters - `expected` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** - `got` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** - `line` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** ### RecordStoreRemainingAPDU thrown by ensureQueueEmpty #### Parameters - `expected` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** ### RecordStoreOptions - autoSkipUnknownApdu: smart mechanism that would skip an apdu un-recognize to the next one that does this is meant to be used when you have refactored/dropped some APDUs it will produces warnings for you to fix the APDUs queue - warning: allows to override the warning function (defaults to console.warn) #### Properties - `autoSkipUnknownApdu` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** - `warning` **function ([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)): void** ### RecordStore a RecordStore is a stateful object that represents a queue of APDUs. It is both used by replayer and recorder transports and is the basic for writing Ledger tests with a mock device. #### Parameters - `queue` **Queue??** - `opts` **$Shape&lt;[RecordStoreOptions](#recordstoreoptions)>?** #### isEmpty check if there is no more APDUs to replay #### recordExchange Record an APDU (used by createTransportRecorder) ##### Parameters - `apdu` **[Buffer](https://nodejs.org/api/buffer.html)** input - `out` **[Buffer](https://nodejs.org/api/buffer.html)** response #### replayExchange Replay an APDU (used by createTransportReplayer) ##### Parameters - `apdu` **[Buffer](https://nodejs.org/api/buffer.html)** Returns **[Buffer](https://nodejs.org/api/buffer.html)** #### ensureQueueEmpty Check all APDUs was replayed. Throw if it's not the case. #### toString Print out the series of apdus Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** #### fromString Create a RecordStore by parsing a string (a series of => HEX\\n&lt;= HEX) ##### Parameters - `str` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** - `opts` **$Shape&lt;[RecordStoreOptions](#recordstoreoptions)>** - `series` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** of APDUs Returns **[RecordStore](#recordstore)**