0.1.19
See README.md for getting started tutorial.
The Core library of PN532. A Pn532 instance must register exactly one adapter plugin to communication to PN532 hardware.
// setup
const {
_, // lodash: https://cdn.jsdelivr.net/npm/lodash@4/lodash.min.js
Pn532: { Pn532, Packet, utils: Pn532utils },
Crypto1,
Pn532Hf14a,
Pn532WebbleAdapter,
Pn532WebserialAdapter,
} = window
const pn532usb = new Pn532()
pn532usb.use(new Pn532WebserialAdapter())
Internal parameters of the PN532 to configure its behavior regarding different cases.
Type: number
Stores registered middlewares to be compose. Middleware is similar to hooks. middleware
will be compose and execute in order at specific key
hook.
Type: object
A TransformStream
to send frame to Adapter
Type: TransformStream
A TransformStream
to read frame from Adapter
Type: TransformStream
install a plugin instance to this PN532 instance.
(object)
A plugin instance to install
this
:
this
// setup
const {
_, // lodash: https://cdn.jsdelivr.net/npm/lodash@4/lodash.min.js
Pn532: { Pn532, Packet, utils: Pn532utils },
Crypto1,
Pn532Hf14a,
Pn532WebbleAdapter,
Pn532WebserialAdapter,
} = window
const pn532usb = new Pn532()
pn532usb.use(new Pn532WebserialAdapter())
Middleware is similar to hooks. middleware
will be compose and execute in order at specific key
hook.
(string)
which key to be add
(any)
middleware function with format
async (ctx, next) => {}
Send a command to adapter via PN532 noraml frame.
Promise<null>
:
Resolve after finish.
Send a command to adapter via PN532 extended frame.
Promise<null>
:
Resolve after finish.
Reset parameters and internal registers of PN532 to default value.
Promise<null>
:
Resolve after finish.
Clear the buffer of unhandled response.
Read any response or specific response from adapter.
(object)
Name | Description |
---|---|
args.cmd number
(default null )
|
Expected cmd of response. Response will be skipped when
cmd
is not
null
and cmd of response is not equals to
cmd
.
|
args.timeout number
(default 5e3 )
|
The maxinum timeout for waiting response. |
args.respValidator function
(default null )
|
Custom validator of resp. |
Promise<Pn532Frame>
:
Resolve with raw response need to be parsed.
This command is designed for self-diagnosis.
Promise<Pn532Frame>
:
Resolve with raw response (contains from 1 to 262 bytes data) need to be parsed.
This test is for communication test between host controller and the PN532. "Parameter Length" and "Parameters" in response packet are same as "Parameter Length" and "Parameter" in command packet.
(string
= 'ping'
)
A utf8 string to test
Promise<boolean>
:
Resolve with test result.
This test is for checking the percentage of failure regarding response packet receiving after polling command transmission. In this test, the PN532 sends a FeliCa polling command packet 128 times to target. The PN532 counts the number of fails and returns the failed number to host controller. This test doesn’t require specific system code for target.
Polling is done with system code (0xFF, 0xFF). The baud rate used is either 212 kbps or 424 kbps.
One polling is considered as defective after no correct polling response within 4 ms. During this test, the analog settings used are those defined in command RFConfiguration within the item n°7 (§7.3.1, p: 101).
(integer
= 0x01
)
0x01: 212 kbps, 0x02: 424 kbps
Promise<number>
:
Resolve with Number of fails (Maximum 128).
This test can be used by an initiator to ensure that a target/card is still in the field:
Promise<boolean>
:
Resolve with a boolean indicating whether or not the target is present.
The PN532 sends back the version of the embedded firmware.
Promise<object>
:
Resolve with object
res
:
res.firmware
(string): Version and revision of the firmware.res.ic
(string): Version of the IC. For PN532, the value is PN532
.res.iso14443a
(boolean): Indicating whether or not support ISO/IEC 14443 TypeAres.iso14443b
(boolean): Indicating whether or not support ISO/IEC 14443 TypeBres.iso18092
(boolean): Indicating whether or not support ISO18092This command is used to update the masked value of several internal registers of the PN532 (located either in the SFR area or in the XRAM memory space).
Promise<null>
:
Resolve after finish.
The PN532 reads the value for each port and returns the information to the host controller.
Promise<Pn532~Gpio>
:
See
Pn532~Gpio
for more description.
The PN532 applies the value for each port that is validated by the host controller.
Promise<null>
:
Resolve after finish.
This command is used to set internal parameters of the PN532, and then to configure its behavior regarding different cases.
(number)
A 8-bit unsigned integer indicates new internal parameters of PN532.
flags
is a bit-field byte which individual definition is the following:
Bit | Value | Name | Definition |
---|---|---|---|
0 | 0x01 | PARAM_NAD_USED | Use of the NAD information in case of initiator configuration (DEP and ISO/IEC14443-4 PCD). |
1 | 0x02 | PARAM_DID_USED | Use of the DID information in case of initiator configuration (or CID in case of ISO/IEC14443-4 PCD configuration). |
2 | 0x04 | PARAM_AUTO_ATR_RES | Automatic generation of the ATR_RES in case of target configuration. |
3 | 0x08 | RFU | Must be set to 0. |
4 | 0x10 | PARAM_AUTO_RATS | Automatic generation of the RATS in case of ISO/IEC14443-4 PCD mode. |
5 | 0x20 | PARAM_14443_4_PICC | The emulation of a ISO/IEC14443-4 PICC is enabled. |
6 | 0x40 | PARAM_NO_AMBLE | The PN532 does not send Preamble and Postamble. |
7 | 0x80 | RFU | Must be set to 0. |
Promise<null>
:
Resolve after finish.
This command is used to select the data flow path by configuring the internal serial data switch.
(object
= {}
)
Name | Description |
---|---|
args.mode number
(default 1 )
|
defines the way of using the SAM (Security Access Module):
Virtual, Wired and Dual Card mode are only valid with 106kbps ISO14443-3 and 4 type A and Mifare. |
args.timeout number
(default 0x14 )
|
Defines the timeout only in Virtual card configuration (Mode =
0x02
). In Virtual Card mode, this field is required; whereas in the other mode, it is optional. This parameter indicates the timeout value with a LSB of 50ms. There is no timeout control if the value is
null
(Timeout = 0). The maximum value for the timeout is 12.75 sec (Timeout =
0xFF
).
|
args.irq number
(default null )
|
Specifies if the PN532 takes care of the
P70_IRQ
pin or not.
|
Promise<null>
:
Resolve after finish.
This command is used to configure the different settings of the PN532 as described in the input section of this command.
Promise<null>
:
Resolve after finish.
Switching on or off the RF field immediately.
When the bit AutoRFCA is off, the PN532 does not need to take care of external field before switching on its own field. In other words, if the bit AutoRFCA is off and RFon/off is on, the PN532 will generate RF field whatever external field is (present or not).
Promise<null>
:
Resolve after finish.
Set timeouts of PN532.
Byte Value | Timeout Value |
---|---|
0x00 | no timeout |
0x01 | 100 μs |
0x02 | 200 μs |
0x03 | 400 μs |
0x04 | 800 μs |
0x05 | 1.6 ms |
0x06 | 3.2 ms |
0x07 | 6.4 ms |
0x08 | 12.8 ms |
0x09 | 25.6 ms |
0x0A | 51.2 ms |
0x0B | 102.4 ms |
0x0C | 204.8 ms |
0x0D | 409.6 ms |
0x0E | 819.2 ms |
0x0F | 1.64 sec |
0x0A | 3.28 sec |
Promise<null>
:
Resolve after finish.
Define the number of retries that the PN532 will use in case of the following processes.
(object
= {}
)
Name | Description |
---|---|
args.atr object
(default 0xFF )
|
A byte containing the number of times that the PN532 will retry to send the
ATR_REQ
in case of incorrect reception of the
ATR_RES
(or no reception at all - timeout).
|
args.psl object
(default 0x01 )
|
A byte containing the number of times. Value
0xFF
means to try eternally,
0x00
means only once (no retry, only one try). The default value of this parameter is
0x01
(the
PSL_REQ/PPS
request is sent twice in case of need).
|
args.passiveActivation object
(default 0xFF )
|
A byte containing the number of times that the PN532 will retry to activate a target in
InListPassiveTarget
command (§7.3.5, p: 115). Value
0xFF
means to try eternally,
0x00
means only once (no retry, only one try). The default value of this parameter is
0xFF
(infinitely).
|
Promise<null>
:
Resolve after finish.
This command is used to detect as many targets (maximum MaxTg
) as possible in passive mode.
(object
= {}
)
Name | Description |
---|---|
args.maxTg number
(default 1 )
|
The maximum number of targets to be initialized by the PN532. The PN532 is capable of handling 2 targets maximum at once, so this field should not exceed
0x02
. For Jewel card, only one target can be initialized.
|
args.brTy number
(default 0 )
|
The baud rate and the modulation type to be used during the initialization.
|
args.data Packet
(default new Packet() )
|
InitiatorData to be used during the initialization of the target(s). Depending on the Baud Rate specified, the content of this field is different:
|
args.timeout number
(default 3e4 )
|
The maxinum timeout for waiting response. |
Promise<Pn532Frame>
:
Resolve with raw response need to be parsed.
This command is used to support protocol data exchanges between the PN532 as initiator and a target.
(object
= {}
)
Name | Description |
---|---|
args.tg number
(default 1 )
|
A byte containing the logical number of the relevant target. This byte contains also a More Information (MI) bit (bit 6) indicating, when set to 1, that the host controller wants to send more data that all the data contained in the DataOut array (see Chaining mechanism §7.4.5, p: 178). This bit is only valid for a TPE target. |
args.data Packet
(default new Packet() )
|
An array of raw data to be sent to the target by the PN532 (max. 263 bytes, see §7.4.7, p:186). |
args.timeout number
|
The maxinum timeout for waiting response. |
args.respValidator function
|
Custom validator of resp. |
Promise<Pn532Frame>
:
Resolve with raw response need to be parsed.
This command is used to support basic data exchanges between the PN532 and a target.
Promise<Pn532Frame>
:
Resolve with raw response need to be parsed.
This command is used to deselect the target(s) Tg. The PN532 keeps all the information relative to this target.
Promise<null>
:
Resolve after finish.
This command is used to release the target(s) Tg.
Promise<null>
:
Resolve after finish.
This command is used to poll card(s) / target(s) of specified Type present in the RF field.
(object
= {}
)
Name | Description |
---|---|
args.pollNr number
|
specifies the number of polling (one polling is a polling for each Type).
|
args.period number
|
(
0x01
~
0x0F
) Indicates the polling period in units of
150 ms
.
|
args.types Array<number>
(default [] )
|
Indicates the target types to be polled. Format for each type as following:
The possible types are listed below:
|
args.timeout number
|
The maxinum timeout for waiting response. |
Promise<Pn532Frame>
:
Resolve with raw response need to be parsed.
The Packet class extends Uint8Array, contains some member function of DataView and add some helper function.
Extends Uint8Array
(...any)
// new Packet()
const pack = new Packet()
// new Packet(length)
// @param {!number} length When called with a `length` argument, an internal array buffer is created in memory, of size `length` multiplied by `BYTES_PER_ELEMENT` bytes, containing zeros.
const pack = new Packet(1)
// new Packet(typedArray)
// @param {!TypedArray} typedArray When called with a `typedArray` argument, which can be an object of any of the non-bigint typed-array types (such as `Int32Array`), the `typedArray` get copied into a new typed array. Each value in `typedArray` is converted to the corresponding type of the constructor before being copied into the new array. The length of the new typed array will be same as the length of the `typedArray` argument.
const pack = new Packet(new Uint8Array([1]))
// new Packet(buffer, byteOffset=, length=)
// @param {!ArrayBuffer} buffer When called with a `buffer`, and optionally a `byteOffset` and a `length` argument, a new typed array view is created that views the specified [`ArrayBuffer`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer). The `byteOffset` and `length` parameters specify the memory range that will be exposed by the typed array view. If both are omitted, all of `buffer` is viewed; if only `length` is omitted, the remainder of `buffer` is viewed.
// @param {number} [byteOffset=0] must be a integer, default to 0
// @param {number} [length=buffer.byteLength] must be a integer, default to `buffer.byteLength`
const pack = new Packet((new Uint8Array([1])).buffer)
Returns a new Packet object initialized from one of the ArrayBuffer
views
((TypedArray | DataView))
one of the
ArrayBuffer
views, such as
typed array objects
or a
DataView
.
Packet
:
a new Packet object initialized from one of the
ArrayBuffer
views
const pack = Packet.fromView(new Uint8Array([1]))
Returns a new Packet object initialized from a string of hex numbers.
(!string)
String containing hex numbers.
Packet
:
a new Packet object initialized from a string of hex numbers.
console.log(Packet.fromHex('01020304').hex)
// 01020304
console.log(Packet.fromHex('01020304', true).hex)
// 04030201
Returns a new Packet
which is the result of concatenating all the Packet
instances in the packs
together.
If the packs
has no items, then a new zero-length Packet
is returned.
Packet
:
a new Packet object merge from two or more Packets
const pack = Packet.merge(Packet.fromUtf8('Hello '), Packet.fromUtf8('world.'))
Determines whether pack
is instance of Packet
and pack.length
is equal to len
. pack.length
will not be validated if len
is null
.
(any)
a data to be validate
(number
= null
)
pack.length
should be integer or
null
.
pack.length
will not be validated if
len
is
null
.
boolean
:
Indicating whether or not
pack
is an instance of
Packet
and the
pack.length
equals to
len
.
if (!Packet.isLen(key, 6)) throw new TypeError('invalid key')
Determines whether the two Packet has the same data.
(any)
The other value to compare.
boolean
:
Indicating whether or not the other value has the same data.
const pack1 = new Packet([1, 2])
const pack2 = new Packet([3, 4])
if (!pack1.isEqual(pack2)) throw new Error('not equal')
Creates a new array of Packet with length of bytesPerChunk
. The final chunk will be the remaining data if length
isn't multiple of bytesPerChunk
.
(number)
must be a integer.
Array<Packet>
:
A new array of Packet
console.log(JSON.stringify(Packet.fromHex('00010203040506').chunk(3)))
// ["Packet(3): 000102","Packet(3): 030405","Packet(1): 06"]
The xor value of every byte in the Packet.
Type: number
console.log(Packet.fromHex('01020304').xor)
// 4
hex string of the Packet
Type: string
console.log(Packet.fromHex('123456').hex)
// 123456
reversed hex string of the Packet
Type: string
console.log(Packet.fromHex('123456').rhex)
// 563412
A string with format Packet(length): hex
Type: string
console.log(Packet.fromHex('123456').inspect)
// Packet(3): 12 34 56
utf8 string of the Packet
Type: string
console.log(Packet.fromHex('616263').utf8)
// abc
base64 string of the Packet
Type: string
console.log(Packet.fromHex('616263').base64)
// YWJj
base64url string of the Packet
Type: string
console.log(Packet.fromHex('616263').base64url)
// YWJj
The byteOffset
of the Packets
underlying ArrayBuffer
object.
Type: number
console.log(Packet.fromHex('616263').offset)
// 0
Get a signed 64-bit integer (long long) at the specified byte offset from the start of the Packet.
(number)
The offset, in bytes, from the start of the Packet to read the data from.
(boolean
= true
)
Indicates whether the 64-bit int is stored in
little- or big-endian
format. If
false
or
undefined
, a big-endian value is read.
BigInt
:
A BigInt.
Get an unsigned 64-bit integer (unsigned long long) at the specified byte offset from the start of the Packet.
(number)
The offset, in bytes, from the start of the Packet to read the data from.
(boolean
= true
)
Indicates whether the 64-bit int is stored in
little- or big-endian
format. If
false
or
undefined
, a big-endian value is read.
BigInt
:
A BigInt.
Get a signed 32-bit float (float) at the specified byte offset from the start of the Packet.
(number)
The offset, in bytes, from the start of the Packet to read the data from.
(boolean
= true
)
Indicates whether the 32-bit float is stored in
little- or big-endian
format. If
false
or
undefined
, a big-endian value is read.
number
:
A signed 32-bit float number.
Get a signed 64-bit float (double) at the specified byte offset from the start of the Packet.
(number)
The offset, in bytes, from the start of the Packet to read the data from.
(boolean
= true
)
Indicates whether the 64-bit float is stored in
little- or big-endian
format. If
false
or
undefined
, a big-endian value is read.
number
:
A signed 64-bit float number.
Get a signed 16-bit integer (short) at the specified byte offset from the start of the Packet.
(number)
The offset, in bytes, from the start of the Packet to read the data from.
(boolean
= true
)
Indicates whether the 16-bit int is stored in
little- or big-endian
format. If
false
or
undefined
, a big-endian value is read.
number
:
A signed 16-bit integer number.
Get a signed 32-bit integer (long) at the specified byte offset from the start of the Packet.
(number)
The offset, in bytes, from the start of the Packet to read the data from.
(boolean
= true
)
Indicates whether the 32-bit int is stored in
little- or big-endian
format. If
false
or
undefined
, a big-endian value is read.
number
:
A signed 32-bit integer number.
Get an unsigned 16-bit integer (unsigned short) at the specified byte offset from the start of the Packet.
(number)
The offset, in byte, from the start of the Packet where to read the data.
(boolean
= true
)
Indicates whether the 16-bit int is stored in
little- or big-endian
format. If
false
or
undefined
, a big-endian value is read.
number
:
An unsigned 16-bit integer number.
Get an unsigned 32-bit integer (unsigned long) at the specified byte offset from the start of the Packet.
(number)
The offset, in byte, from the start of the Packet where to read the data.
(boolean
= true
)
Indicates whether the 32-bit int is stored in
little- or big-endian
format. If
false
or
undefined
, a big-endian value is read.
number
:
An unsigned 32-bit integer number.
Store a signed 64-bit integer (long long) value at the specified byte offset from the start of the Packet.
(number)
The offset, in bytes, from the start of the Packet to store the data from.
(BigInt)
The value to set as a
BigInt
. The highest possible value that fits in a signed 64-bit integer is
2n ** (64n -1n) - 1n
(
9223372036854775807n
). Upon overflow, it will be negative (
-9223372036854775808n
).
(boolean
= true
)
Indicates whether the 64-bit int is stored in
little- or big-endian
format. If
false
or
undefined
, a big-endian value is written.
Store an unsigned 64-bit integer (unsigned long long) value at the specified byte offset from the start of the Packet.
(number)
The offset, in bytes, from the start of the Packet to store the data from.
(BigInt)
The highest possible value that fits in an unsigned 64-bit integer is
2n ** 64n - 1n
(
18446744073709551615n
). Upon overflow, it will be zero (
0n
).
(boolean
= true
)
Indicates whether the 64-bit int is stored in
little- or big-endian
format. If
false
or
undefined
, a big-endian value is written.
Store a signed 32-bit float (float) value at the specified byte offset from the start of the Packet.
(number)
The offset, in bytes, from the start of the Packet to store the data from.
(number)
The value to set.
(boolean
= true
)
Indicates whether the 32-bit float is stored in
little- or big-endian
format. If
false
or
undefined
, a big-endian value is written.
Store a signed 64-bit float (double) value at the specified byte offset from the start of the Packet.
(number)
The offset, in bytes, from the start of the Packet to store the data from.
(number)
The value to set.
(boolean
= true
)
Indicates whether the 64-bit float is stored in
little- or big-endian
format. If
false
or
undefined
, a big-endian value is written.
Store a signed 16-bit integer (short) value at the specified byte offset from the start of the Packet.
(number)
The offset, in bytes, from the start of the Packet to store the data from.
(number)
The value to set.
(boolean
= true
)
Indicates whether the 16-bit int is stored in
little- or big-endian
format. If
false
or
undefined
, a big-endian value is written.
Store a signed 32-bit integer (long) value at the specified byte offset from the start of the Packet.
(number)
The offset, in bytes, from the start of the Packet to store the data from.
(number)
The value to set.
(boolean
= true
)
Indicates whether the 32-bit int is stored in
little- or big-endian
format. If
false
or
undefined
, a big-endian value is written.
Store a signed 8-bit integer (byte) value at the specified byte offset from the start of the Packet.
Store an unsigned 16-bit integer (unsigned short) value at the specified byte offset from the start of the Packet.
(number)
The offset, in bytes, from the start of the Packet to store the data from.
(number)
The value to set.
(boolean
= true
)
Indicates whether the 16-bit int is stored in
little- or big-endian
format. If
false
or
undefined
, a big-endian value is written.
Store an unsigned 32-bit integer (unsigned long) value at the specified byte offset from the start of the Packet.
(number)
The offset, in bytes, from the start of the Packet to store the data from.
(number)
The value to set.
(boolean
= true
)
Indicates whether the 32-bit int is stored in
little- or big-endian
format. If
false
or
undefined
, a big-endian value is written.
Store an unsigned 8-bit integer (unsigned byte) value at the specified byte offset from the start of the Packet.
Get an unsigned 24-bit integer at the specified byte offset from the start of the Packet.
(number)
The offset, in byte, from the start of the Packet where to read the data.
(boolean
= true
)
Indicates whether the 24-bit int is stored in
little- or big-endian
format. If
false
or
undefined
, a big-endian value is written.
number
:
An unsigned 24-bit integer number.
Store an unsigned 24-bit integer value at the specified byte offset from the start of the Packet.
(number)
The offset, in bytes, from the start of the Packet to store the data from.
(number)
The value to set.
(boolean
= true
)
Indicates whether the 24-bit int is stored in
little- or big-endian
format. If
false
or
undefined
, a big-endian value is written.
Get a signed 24-bit integer at the specified byte offset from the start of the Packet.
(number)
The offset, in bytes, from the start of the Packet to read the data from.
(boolean
= true
)
Indicates whether the 24-bit int is stored in
little- or big-endian
format. If
false
or
undefined
, a big-endian value is read.
number
:
A signed 24-bit integer number.
Store a signed 24-bit integer value at the specified byte offset from the start of the Packet.
(number)
The offset, in bytes, from the start of the Packet to store the data from.
(number)
The value to set.
(boolean
= true
)
Indicates whether the 24-bit int is stored in
little- or big-endian
format. If
false
or
undefined
, a big-endian value is written.
Get a bit value at the specified bit offset from the Packet.
(number)
The offset, in bits, from the Packet to read the data from.
(number
= false
)
Indicates whether the bit value is stored in LSB (Least Significant Bit) format. If
false
a MSB (Most Significant Bit) format is used.
number
:
A bit value.
Store a bit value at the specified bit offset from the Packet.
JavaScript implementation of the Crypto1 cipher. This script should be load after the PN532 Core script.
const { Crypto1 } = window
const state1 = new Crypto1()
const state2 = new Crypto1({ even: 0, odd: 0 })
Get bit of the unsigned reversed endian 32-bit integer x
at position n
.
number
:
The bit at position
n
.
const { Crypto1 } = window
console.log(Crypto1.beBit(0x01000000, 0)) // 1
Using a bit of the keystream extend the table of possible lfsr states. (complex version)
(number)
An array of the even/odd bits of lfsr.
(number)
Size of array.
(number)
The bit of the keystream.
(number)
mask1
(number)
mask2
(number)
The value that was fed into the lfsr at the time the keystream was generated.
number
:
The new size of array.
Recursively narrow down the search space, 4 bits of keystream at a time.
Recover the key with the two authentication attempts from reader.
(object)
Name | Description |
---|---|
args.uid (number | Packet | string)
|
The 4-bytes uid in the authentication attempt. |
args.nt0 (number | Packet | string)
|
The nonce from tag in the first authentication attempt. |
args.nr0 (number | Packet | string)
|
The calculated nonce response from reader in the first authentication attempt. |
args.ar0 (number | Packet | string)
|
The random challenge from reader in the first authentication attempt. |
args.nt1 (number | Packet | string)
|
The nonce from tag in the second authentication attempt. |
args.nr1 (number | Packet | string)
|
The calculated nonce response from reader in the second authentication attempt. |
args.ar1 (number | Packet | string)
|
The random challenge from reader in the second authentication attempt. |
Packet
:
The recovered key.
const { Crypto1, Pn532: { Packet } } = window
console.log(Crypto1.mfkey32v2({
uid: 0x65535D33,
nt0: 0xCB7B9ED9,
nr0: 0x5A8FFEC6,
ar0: 0x5C7C6F89,
nt1: 0x1E6D9228,
nr1: 0x6FB8B4A8,
ar1: 0xEF4039FB,
}).hex) // A9AC67832330
console.log(Crypto1.mfkey32v2({
uid: Packet.fromHex('65535D33'),
nt0: Packet.fromHex('CB7B9ED9'),
nr0: Packet.fromHex('5A8FFEC6'),
ar0: Packet.fromHex('5C7C6F89'),
nt1: Packet.fromHex('1E6D9228'),
nr1: Packet.fromHex('6FB8B4A8'),
ar1: Packet.fromHex('EF4039FB'),
}).hex) // A9AC67832330
console.log(Crypto1.mfkey32v2({
uid: '65535D33',
nt0: 'CB7B9ED9',
nr0: '5A8FFEC6',
ar0: '5C7C6F89',
nt1: '1E6D9228',
nr1: '6FB8B4A8',
ar1: 'EF4039FB',
}).hex) // A9AC67832330
Recover the key with the successfully authentication between the reader and the tag.
(object)
Name | Description |
---|---|
args.uid (number | Packet | string)
|
The 4-bytes uid in the authentication. |
args.nt (number | Packet | string)
|
The nonce from tag in the authentication. |
args.nr (number | Packet | string)
|
The calculated response of
args.nt
from reader in the authentication.
|
args.ar (number | Packet | string)
|
The random challenge from reader in the authentication. |
args.at (number | Packet | string)
|
The calculated response of
args.ar
from tag in the authentication.
|
Packet
:
The recovered key.
const { Crypto1, Pn532: { Packet } } = window
console.log(Crypto1.mfkey32v2({
uid: 0x65535D33,
nt: 0x2C198BE4,
nr: 0xFEDAC6D2,
ar: 0xCF0A3C7E,
at: 0xF4A81AF8,
}).hex) // A9AC67832330
console.log(Crypto1.mfkey32v2({
uid: Packet.fromHex('65535D33'),
nt: Packet.fromHex('2C198BE4'),
nr: Packet.fromHex('FEDAC6D2'),
ar: Packet.fromHex('CF0A3C7E'),
at: Packet.fromHex('F4A81AF8'),
}).hex) // A9AC67832330
console.log(Crypto1.mfkey32v2({
uid: '65535D33',
nt: '2C198BE4',
nr: 'FEDAC6D2',
ar: 'CF0A3C7E',
at: 'F4A81AF8',
}).hex) // A9AC67832330
Decrypt the data.
(object)
Name | Description |
---|---|
args.nr (number | Packet | string)
|
The calculated response of
args.nt
from reader in the authentication.
|
args.nt (number | Packet | string)
|
The nonce from tag in the authentication. |
args.uid (number | Packet | string)
|
The 4-bytes uid in the authentication. |
args.data Packet
|
The encrypted data. |
args.key Packet
|
The 6-bytes key to decrypt the data. |
Packet
:
The decrypted data.
Reset the internal lfsr.
this
:
this
const { Crypto1 } = window
const state1 = new Crypto1({ even: 1, odd: 1 })
state1.reset()
The Hf14a plugin for PN532. After register to PN532 instance, this plugin will expose plugin functions under pn532.$hf14a
.
const pn532 = new Pn532()
pn532.use(new Pn532WebserialAdapter()) // A pn532 instance must register exactly one adapter plugin
pn532.use(new Pn532Hf14a())
This command is used to detect as many mifare targets (maximum MaxTg
) as possible in passive mode.
(object
= {}
)
Name | Description |
---|---|
args.maxTg number
(default 1 )
|
The maximum number of mifare targets to be initialized by the PN532. The PN532 is capable of handling 2 targets maximum at once, so this field should not exceed
0x02
.
|
args.uid Packet
(default new Packet() )
|
Set to UID of card if wants to initialize a target with a known UID. |
args.timeout any
|
Promise<Array<Pn532Hf14a~MifareTarget>>
:
Resolve with an array of detected mifare targets.
Because Pn532#testTargetPresent failed to detect JCOP31 target so we need to do it manually.
Promise<boolean>
:
Resolve with a boolean indicating whether or not the ISO/IEC14443-4 card is present.
This function is used to detect one mifare target in passive mode. It will release the target if reader connection is opened.
(object
= {}
)
Name | Description |
---|---|
args.timeout any
|
Promise<Pn532Hf14a~MifareTarget>
:
Resolve with detected mifare target.
This function is used to authenticate block with a specific key type and key.
(object
= {}
)
Name | Description |
---|---|
args.block number
(default 0 )
|
Which block to be authenticated. |
args.isKb boolean
(default 0 )
|
Type of the key.
0
: key A,
1
: key B.
|
args.key Packet
|
6 bytes key to authenticate the block. |
args.tg number
(default 1 )
|
A byte containing the logical number of the relevant target. |
args.uid Packet
|
Uid of the target to be authenticated. Currently only accepted 4 bytes uid. |
args.blocksPerSector number
(default 4 )
|
A integer represent how many blocks per sector. |
Promise<null>
:
Resolve after finish.
Read sector data from target by key B and key A.
Promise<object>
:
Resolve with
res
:
res.data
(Packet): 64 bytes sector data. Block data that failed to read will be filled with 0x00
.res.success.read
(Array<boolean>): Indicating whether or not the block read successfully. There are 4 blocks in sector.res.success.key
(Array<boolean>): Indicating whether or not the key has authenticated successfully.Read all sector data from target. This function will try to auth sector by keys
.
Promise<object>
:
Resolve with
res
:
res.data
(Packet): All sector data. Block data that failed to read will be filled with 0x00
.res.success.read
(Array<boolean>): Indicating whether or not the block read successfully. There are 4 blocks in sector.res.success.key
(Array<Packet, null>): Key A and Key B of all sector. Array may contains null
if sector key not found.Write block data to target by specific key type and key.
Promise<null>
:
Resolve after finished.
Write block data from target by key B and key A.
Promise<null>
:
Resolve after finished.
Set uid
of chinese magic card gen2 (aka CUID).
Promise<null>
:
Resolve after finished.
Increment from value block src
by int32
and transfer to dist
block.
Promise<null>
:
Resolve after finished.
Decrement from value block src
by int32
and transfer to dist
block.
Promise<null>
:
Resolve after finished.
Copy from value block src
and transfer to dist
block.
Promise<null>
:
Resolve after finished.
Write block data to chinese magic card gen1a (aka UID).
Promise<null>
:
Resolve after finished.
Set uid
of chinese magic card gen1a (aka UID).
Promise<null>
:
Resolve after finished.
This plugin is used to debug adapter commucation.
const pn532 = new Pn532()
pn532.use(new Pn532LoggerRxTx())
This is a web bluetooth adapter of Pn532
. A pn532 instance must register exactly one adapter plugin. After register to PN532 instance, this plugin will expose plugin functions under pn532.$adapter
.
const pn532ble = new Pn532()
pn532ble.use(new Pn532WebbleAdapter())
console.log(JSON.stringify(await pn532ble.getFirmwareVersion()))
// {"firmware":"1.6","ic":"PN532","iso14443a":true,"iso14443b":true,"iso18092":true}
This is a web serial adapter of Pn532
. A pn532 instance must register exactly one adapter plugin. After register to PN532 instance, this plugin will expose plugin functions under pn532.$adapter
.
const pn532ble = new Pn532()
pn532ble.use(new Pn532WebserialAdapter())
console.log(JSON.stringify(await pn532ble.getFirmwareVersion()))
// {"firmware":"1.6","ic":"PN532","iso14443a":true,"iso14443b":true,"iso18092":true}
URL: http://taichunmin.idv.tw/pn532.js/m1-uid4b-writer.html
This tools can write 4 bytes UID to Chinese Magic Card (support UID and CUID) via Web Bluetooth or Web Serial.
URL: http://taichunmin.idv.tw/pn532.js/m1-eml-toolkit.html
This tools can read or write data from Mifare Classic 1k (support UID and CUID) via Web Bluetooth or Web Serial.
URL: http://taichunmin.idv.tw/pn532.js/m1-uid-scanner.html
This tools can scan UID of NFC Type A Tags via Web Bluetooth or Web Serial.
URL: http://taichunmin.idv.tw/pn532.js/mfkey.html
An online tool for mfkey32v2 and mfkey64 that recover mifare key from encrypted data obtained from reader-only attack or sniff communications between reader and card.
URL: http://taichunmin.idv.tw/pn532.js/detector-shop143630998.html
This tools is only support supercard 單卡嗅探王. It can change uid and type of supercard, or do reader-only attack to recover key.
URL: http://taichunmin.idv.tw/pn532.js/detector-furui.html
This tools is only support supercard 福睿偵測卡. It can change uid and type of supercard, or do reader-only attack to recover key.
Interface of PN532 Frame. Please use Pn532Frame.create to create a new instance.
(Packet)
A PN532 Frame Data.
Create a new Pn532FrameNormal
or Pn532FrameExtended
instance depends on data in pack
.
(Packet)
A PN532 Frame Packet.
(Pn532FrameNormal | Pn532FrameExtended)
:
A
Pn532Frame
initialized from
pack
Class of PN532 ACK/NACK Frame
Extends Pn532Frame
(Packet)
A PN532 Frame Data.
Class of PN532 Normal Frame
Extends Pn532Frame
(any)
Class of PN532 Extended Frame
Extends Pn532Frame
(any)
import Packet from 'pn532.js/Packet'
import Pn532Hf14a from 'pn532.js/plugin/Hf14a'
import Pn532LoggerRxTx from 'pn532.js/plugin/LoggerRxTx'
import Pn532WebbleAdapter from 'pn532.js/plugin/WebbleAdapter'
import Pn532WebserialAdapter from 'pn532.js/plugin/WebserialAdapter'
import Pn532 from 'pn532.js/pn532'
import * as Pn532Utils from 'pn532.js/utils'
Type: object
(number)
: Representing the pin P32_INT0. P32 can be used as standard GPIO and is therefore not used as external interrupt trigger. Nevertheless, for the PowerDown command (§7.2.11, p:98), this pin can be used for the waking up. Moreover, when configured to use the handshake mechanism (§6.3, p:48), this pin may be used for the H_REQ line.
(number)
: Representing the pin P33_INT1. P33 can be used as standard GPIO and is therefore not used as external interrupt trigger. Nevertheless, for the PowerDown command (§7.2.11, p:98), this pin can be used for the waking up.
(number)
: Representing the pin P34/SIC_CLK. When configured to use the SAM companion chip (see
SAMConfiguration
command (§7.2.10 p:89)), P34 is used for the CLAD line.
(number)
: Representing the pins MISO/P71 of the SPI bus. P71 and P72 can be used as GPIO when the PN532 is not configured to use the SPI interface to communicate with the host controller.
(number)
: Representing the pin SCK/P72 of the SPI bus. P71 and P72 can be used as GPIO when the PN532 is not configured to use the SPI interface to communicate with the host controller.
(number)
: I0 and I1 (see § 6.1.1, p:24) are used to select the host controller interface. Once the selection has been done by the firmware, these two pins can be used as GPIOs.
(number)
: I0 and I1 (see § 6.1.1, p:24) are used to select the host controller interface. Once the selection has been done by the firmware, these two pins can be used as GPIOs.
import Crypto1 from 'pn532.js/Crypto1'
import Pn532SerialPortAdapter from 'pn532.js/plugin/SerialPortAdapter'
// Run serialport-list to list port, see https://serialport.io/docs/bin-list
pn532.use(new Pn532SerialPortAdapter(), { path: '/dev/tty.usbserial-120' })