0.1.19
SeeREADME.md for getting started tutorial.
The Core library of PN532. A Pn532 instance must register exactly one adapter plugin to communication to PN532 hardware.
// setupconst { _,// lodash: https://cdn.jsdelivr.net/npm/lodash@4/lodash.min.jsPn532: {Pn532,Packet,utils:Pn532utils },Crypto1,Pn532Hf14a,Pn532WebbleAdapter,Pn532WebserialAdapter,} =windowconst pn532usb =newPn532()pn532usb.use(newPn532WebserialAdapter())
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 specifickey
hook.
Type:object
ATransformStream
to send frame to Adapter
Type: TransformStream
ATransformStream
to read frame from Adapter
Type: TransformStream
install a plugin instance to this PN532 instance.
this
:this
// setupconst { _,// lodash: https://cdn.jsdelivr.net/npm/lodash@4/lodash.min.jsPn532: {Pn532,Packet,utils:Pn532utils },Crypto1,Pn532Hf14a,Pn532WebbleAdapter,Pn532WebserialAdapter,} =windowconst pn532usb =newPn532()pn532usb.use(newPn532WebserialAdapter())
Middleware is similar to hooks.middleware
will be compose and execute in order at specifickey
hook.
(string)
which key to be add(any)
middleware function with formatasync (ctx, next) => {}
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.cmdnumber (defaultnull ) | Expected cmd of response. Response will be skipped whencmd is notnull and cmd of response is not equals tocmd . |
args.timeoutnumber (default5e3 ) | The maxinum timeout for waiting response. |
args.respValidatorfunction (defaultnull ) | 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 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 kbpsPromise<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 objectres
:res.firmware
(string): Version and revision of the firmware.res.ic
(string): Version of the IC. For PN532, the value isPN532
.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>
: SeePn532~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.modenumber (default1 ) | 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.timeoutnumber (default0x14 ) | 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 isnull (Timeout = 0). The maximum value for the timeout is 12.75 sec (Timeout =0xFF ). |
args.irqnumber (defaultnull ) | Specifies if the PN532 takes care of theP70_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.atrobject (default0xFF ) | A byte containing the number of times that the PN532 will retry to send theATR_REQ in case of incorrect reception of theATR_RES (or no reception at all - timeout).
|
args.pslobject (default0x01 ) | A byte containing the number of times. Value0xFF means to try eternally,0x00 means only once (no retry, only one try). The default value of this parameter is0x01 (thePSL_REQ/PPS request is sent twice in case of need).
|
args.passiveActivationobject (default0xFF ) | A byte containing the number of times that the PN532 will retry to activate a target inInListPassiveTarget command (§7.3.5, p: 115). Value0xFF means to try eternally,0x00 means only once (no retry, only one try). The default value of this parameter is0xFF (infinitely). |
Promise<null>
: Resolve after finish.This command is used to detect as many targets (maximumMaxTg
) as possible in passive mode.
(object ={}
)
Name | Description |
---|---|
args.maxTgnumber (default1 ) | 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 exceed0x02 . For Jewel card, only one target can be initialized. |
args.brTynumber (default0 ) | The baud rate and the modulation type to be used during the initialization.
|
args.dataPacket (defaultnew 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.timeoutnumber (default3e4 ) | 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.tgnumber (default1 ) | 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.dataPacket (defaultnew 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.timeoutnumber | The maxinum timeout for waiting response. |
args.respValidatorfunction | 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.pollNrnumber | specifies the number of polling (one polling is a polling for each Type).
|
args.periodnumber | (0x01 ~0x0F ) Indicates the polling period in units of150 ms . |
args.typesArray<number> (default[] ) | Indicates the target types to be polled. Format for each type as following:
The possible types are listed below:
|
args.timeoutnumber | 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.
ExtendsUint8Array
(...any)
// new Packet()const pack =newPacket()
// 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 =newPacket(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 =newPacket(newUint8Array([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 =newPacket((newUint8Array([1])).buffer)
Returns a new Packet object initialized from one of theArrayBuffer
views
Packet
: a new Packet object initialized from one of theArrayBuffer
viewsconst pack =Packet.fromView(newUint8Array([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)// 01020304console.log(Packet.fromHex('01020304',true).hex)// 04030201
Returns a newPacket
which is the result of concatenating all thePacket
instances in thepacks
together.
If thepacks
has no items, then a new zero-lengthPacket
is returned.
Packet
: a new Packet object merge from two or more Packetsconst pack =Packet.merge(Packet.fromUtf8('Hello '),Packet.fromUtf8('world.'))
Determines whetherpack
is instance ofPacket
andpack.length
is equal tolen
.pack.length
will not be validated iflen
isnull
.
(any)
a data to be validate(number =null
)
pack.length
should be integer ornull
.pack.length
will not be validated iflen
isnull
.boolean
: Indicating whether or notpack
is an instance ofPacket
and thepack.length
equals tolen
.if (!Packet.isLen(key,6))thrownewTypeError('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 =newPacket([1,2])const pack2 =newPacket([3,4])if (!pack1.isEqual(pack2))thrownewError('not equal')
Creates a new array of Packet with length ofbytesPerChunk
. The final chunk will be the remaining data iflength
isn't multiple ofbytesPerChunk
.
(number)
must be a integer.Array<Packet>
: A new array of Packetconsole.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 formatPacket(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
ThebyteOffset
of thePackets
underlyingArrayBuffer
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 inlittle- or big-endian format. Iffalse
orundefined
, 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 inlittle- or big-endian format. Iffalse
orundefined
, 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 inlittle- or big-endian format. Iffalse
orundefined
, 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 inlittle- or big-endian format. Iffalse
orundefined
, 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 inlittle- or big-endian format. Iffalse
orundefined
, 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 inlittle- or big-endian format. Iffalse
orundefined
, 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 inlittle- or big-endian format. Iffalse
orundefined
, 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 inlittle- or big-endian format. Iffalse
orundefined
, 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 aBigInt. The highest possible value that fits in a signed 64-bit integer is2n ** (64n -1n) - 1n
(9223372036854775807n
). Upon overflow, it will be negative (-9223372036854775808n
).(boolean =true
)
Indicates whether the 64-bit int is stored inlittle- or big-endian format. Iffalse
orundefined
, 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 is2n ** 64n - 1n
(18446744073709551615n
). Upon overflow, it will be zero (0n
).(boolean =true
)
Indicates whether the 64-bit int is stored inlittle- or big-endian format. Iffalse
orundefined
, 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 inlittle- or big-endian format. Iffalse
orundefined
, 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 inlittle- or big-endian format. Iffalse
orundefined
, 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 inlittle- or big-endian format. Iffalse
orundefined
, 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 inlittle- or big-endian format. Iffalse
orundefined
, 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 inlittle- or big-endian format. Iffalse
orundefined
, 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 inlittle- or big-endian format. Iffalse
orundefined
, 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 inlittle- or big-endian format. Iffalse
orundefined
, 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 inlittle- or big-endian format. Iffalse
orundefined
, 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 inlittle- or big-endian format. Iffalse
orundefined
, 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 inlittle- or big-endian format. Iffalse
orundefined
, 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. Iffalse
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 } =windowconst state1 =newCrypto1()const state2 =newCrypto1({even:0,odd:0 })
Get bit of the unsigned reversed endian 32-bit integerx
at positionn
.
number
: The bit at positionn
.const {Crypto1 } =windowconsole.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 } } =windowconsole.log(Crypto1.mfkey32v2({uid:0x65535D33,nt0:0xCB7B9ED9,nr0:0x5A8FFEC6,ar0:0x5C7C6F89,nt1:0x1E6D9228,nr1:0x6FB8B4A8,ar1:0xEF4039FB,}).hex)// A9AC67832330console.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)// A9AC67832330console.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 ofargs.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 ofargs.ar from tag in the authentication. |
Packet
: The recovered key.const {Crypto1,Pn532: {Packet } } =windowconsole.log(Crypto1.mfkey32v2({uid:0x65535D33,nt:0x2C198BE4,nr:0xFEDAC6D2,ar:0xCF0A3C7E,at:0xF4A81AF8,}).hex)// A9AC67832330console.log(Crypto1.mfkey32v2({uid:Packet.fromHex('65535D33'),nt:Packet.fromHex('2C198BE4'),nr:Packet.fromHex('FEDAC6D2'),ar:Packet.fromHex('CF0A3C7E'),at:Packet.fromHex('F4A81AF8'),}).hex)// A9AC67832330console.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 ofargs.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.dataPacket | The encrypted data. |
args.keyPacket | The 6-bytes key to decrypt the data. |
Packet
: The decrypted data.Reset the internal lfsr.
this
:this
const {Crypto1 } =windowconst state1 =newCrypto1({even:1,odd:1 })state1.reset()
The Hf14a plugin for PN532. After register to PN532 instance, this plugin will expose plugin functions underpn532.$hf14a
.
const pn532 =newPn532()pn532.use(newPn532WebserialAdapter())// A pn532 instance must register exactly one adapter pluginpn532.use(newPn532Hf14a())
This command is used to detect as many mifare targets (maximumMaxTg
) as possible in passive mode.
(object ={}
)
Name | Description |
---|---|
args.maxTgnumber (default1 ) | 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 exceed0x02 . |
args.uidPacket (defaultnew Packet() ) | Set to UID of card if wants to initialize a target with a known UID. |
args.timeoutany |
Promise<Array<Pn532Hf14a~MifareTarget>>
: Resolve with an array of detected mifare targets.BecausePn532#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.timeoutany |
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.blocknumber (default0 ) | Which block to be authenticated. |
args.isKbboolean (default0 ) | Type of the key.0 : key A,1 : key B. |
args.keyPacket | 6 bytes key to authenticate the block. |
args.tgnumber (default1 ) | A byte containing the logical number of the relevant target. |
args.uidPacket | Uid of the target to be authenticated. Currently only accepted 4 bytes uid. |
args.blocksPerSectornumber (default4 ) | 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 withres
:res.data
(Packet): 64 bytes sector data. Block data that failed to read will be filled with0x00
.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 bykeys
.
Promise<object>
: Resolve withres
:res.data
(Packet): All sector data. Block data that failed to read will be filled with0x00
.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 containsnull
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.Setuid
of chinese magic card gen2 (aka CUID).
Promise<null>
: Resolve after finished.Increment from value blocksrc
byint32
and transfer todist
block.
Promise<null>
: Resolve after finished.Decrement from value blocksrc
byint32
and transfer todist
block.
Promise<null>
: Resolve after finished.Copy from value blocksrc
and transfer todist
block.
Promise<null>
: Resolve after finished.Setuid
of chinese magic card gen1a (aka UID).
Promise<null>
: Resolve after finished.This plugin is used to debug adapter commucation.
const pn532 =newPn532()pn532.use(newPn532LoggerRxTx())
This is a web bluetooth adapter ofPn532
. A pn532 instance must register exactly one adapter plugin. After register to PN532 instance, this plugin will expose plugin functions underpn532.$adapter
.
const pn532ble =newPn532()pn532ble.use(newPn532WebbleAdapter())console.log(JSON.stringify(await pn532ble.getFirmwareVersion()))// {"firmware":"1.6","ic":"PN532","iso14443a":true,"iso14443b":true,"iso18092":true}
This is a web serial adapter ofPn532
. A pn532 instance must register exactly one adapter plugin. After register to PN532 instance, this plugin will expose plugin functions underpn532.$adapter
.
const pn532ble =newPn532()pn532ble.use(newPn532WebserialAdapter())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 usePn532Frame.create to create a new instance.
(Packet)
A PN532 Frame Data.Create a newPn532FrameNormal
orPn532FrameExtended
instance depends on data inpack
.
(Packet)
A PN532 Frame Packet.(Pn532FrameNormal |Pn532FrameExtended)
: APn532Frame
initialized frompack
Class of PN532 ACK/NACK Frame
ExtendsPn532Frame
(Packet)
A PN532 Frame Data.Class of PN532 Normal Frame
ExtendsPn532Frame
(any)
Class of PN532 Extended Frame
ExtendsPn532Frame
(any)
importPacketfrom'pn532.js/Packet'
importPn532Hf14afrom'pn532.js/plugin/Hf14a'
importPn532LoggerRxTxfrom'pn532.js/plugin/LoggerRxTx'
importPn532WebbleAdapterfrom'pn532.js/plugin/WebbleAdapter'
importPn532WebserialAdapterfrom'pn532.js/plugin/WebserialAdapter'
importPn532from'pn532.js/pn532'
import *asPn532Utilsfrom'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 (seeSAMConfiguration
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.importCrypto1from'pn532.js/Crypto1'
importPn532SerialPortAdapterfrom'pn532.js/plugin/SerialPortAdapter'// Run serialport-list to list port, see https://serialport.io/docs/bin-listpn532.use(newPn532SerialPortAdapter(), {path:'/dev/tty.usbserial-120' })