Security News
PyPI’s New Archival Feature Closes a Major Security Gap
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
ndef-parser
Advanced tools
Feed me with a raw nfc card output and I will drop you tjhe ndef message if I can find one.
npm:
npm install ndef-parser
yarn:
yarn add ndef-parser
const ndef = require('ndef-parser');
// Let's mock it by creating a new buffer:
let tagBufferBlocks0to4 = new Buffer('046e38da5a215280a9480000e1106d00032ad101', 'hex');
// We want to parse this header
let tagHeaderValues = ndef.parseHeader(tagBufferBlocks0to4);
// ndef.parseHeader will return an obj containing headers statements:
console.log(tagHeaderValues);
// logs:
// { isTagFormatedAsNdef: true,
// type2TagSpecification: '6e',
// maxNdefMessageSize: 128,
// hasTagReadPermissions: true,
// hasTagANdefMessage: true,
// ndefMessageLength: 133,
// tagLengthToReadFromBlock4: 135 }
// Check if our tag is readable and has a ndef message
if(tagHeaderValues.hasTagReadPermissions && tagHeaderValues.isTagFormatedAsNdef && tagHeaderValues.hasTagANdefMessage) {
// And here is our isolated ndef message !
let tagBufferFromBlock4 = new Buffer('032ad101265402656e4865792074686572652c2069276d2061206e6465662074657874207265636f72642021', 'hex');
// ndef.parseNdef uses @taptrack/ndef which supports text and uri parsing, but you obviously can use anything to parse the ndef message
let parsedRecords = ndef.parseNdef(tagBufferFromBlock4);
console.log(parsedRecords)
// [{
// language: 'en',
// content: 'I\'m the first ndef record of this tag'
// },
// { language: 'en',
// content: 'Looks like I\'m the second record of this tag, and a plaintext type one by the way.'
// }]
}
const ndef = require('ndef-parser');
ndef.parseHeader(buffer)
In order to know where the ndef message is we parse the header:
Here is a buffer of the first 4 blocks of a nfc tag (ntag216) containg 2 ndef text records:
<Buffer 04 6e 38 da 5a 21 52 80 a9 48 00 00 e1 10 6d 00 03 85 91 01>
// Let's mock it by creating a new buffer:
let tagBufferBlocks0to4 = new Buffer('046e38da5a215280a9480000e1106d0003859101', 'hex');
console.log('tagBufferBlocks0to4', tagBufferBlocks0to4);
// logs: <Buffer 04 6e 38 da 5a 21 52 80 a9 48 00 00 e1 10 6d 00 03 85 91 01> (here we go!)
// We want to parse this header
// ndef.parseHeader will return an obj containing headers statements
let tagHeaderValues = ndef.parseHeader(tagBufferBlocks0to4);
console.log(tagHeaderValues);
// logs:
// { isTagFormatedAsNdef: true,
// type2TagSpecification: '6e',
// maxNdefMessageSize: 128,
// hasTagReadPermissions: true,
// hasTagANdefMessage: true,
// ndefMessageLength: 133,
// tagLengthToReadFromBlock4: 135 }
ndef.parseHeader(buffer) returns:
isTagFormatedAsNdef
boolean - is tag formated as ndef ?type2TagSpecification
string - hex string of the type2 tag specmaxNdefMessageSize
int - max ndef message size provided by the taghasTagReadPermissions
boolean - is tag read locked ?hasTagANdefMessage
boolean - tag has a ndef message ?ndefMessageLength
int - ndef message lengthtagLengthToReadFromBlock4
int - bytes to read starting at block 4 to get the full ndef messagendef.parseNdef(buffer)
:Now that we know if our tag contains a valid ndef message we can read one more time the tag where it's located. Just then we will be able to use a third party library to parse the ndef message.
// Check if our tag is readable and has a ndef message
if(tagHeaderValues.hasTagReadPermissions && tagHeaderValues.isTagFormatedAsNdef && tagHeaderValues.hasTagANdefMessage) {
// Ok, looks like what we've seen in the header tells us we can find a ndef message
// Here's an example using nfc-pcsc library:
// var tagBufferFromBlock4 = await reader.read(4, tagHeaderValues.tagLengthToReadFromBlock4);
// And here is our isolated ndef message !
console.log(tagBufferFromBlock4);
// logs: <Buffer 91 01 28 54 02 65 6e 49 27 6d 20 74 68 65 20 66 69 72 73 74 20 6e 64 65 66 20 72 65 63 6f 72 64 20 6f 66 20 74 68 69 73 20 74 61 67 51 01 55 54 02 65 ... >
// ndef.parseNdef uses @taptrack/ndef which supports text and uri parsing, but you obviously can use anything to parse the ndef message
let parsedRecords = ndef.parseNdef(tagBufferFromBlock4);
console.log(parsedRecords)
// [{
// language: 'en',
// content: 'I\'m the first ndef record of this tag'
// },
// { language: 'en',
// content: 'Looks like I\'m the second record of this tag, and a plaintext type one by the way.'
// }]
}
We are natively using https://github.com/TapTrack/NdefJS but you could give a try at https://github.com/andijakl/ndef-nfc or have a deep look at https://github.com/googlearchive/chrome-nfc
If you are looking for a nfc tag reading library take a look at https://github.com/pokusew/nfc-pcsc
MIT © somq
FAQs
This package has been deprecated. Use nfccard-parser instead.
We found that ndef-parser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Research
Security News
Malicious npm package postcss-optimizer delivers BeaverTail malware, targeting developer systems; similarities to past campaigns suggest a North Korean connection.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.