New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More →

react-native-nfc-sdk

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-nfc-sdk - npm Package Compare versions

Comparing version

to
0.3.4-beta

@@ -1,6 +0,6 @@

import { HCESession, HCESessionEventListenerCancel } from 'react-native-hce';
import { NdefTagInfo } from './src/types/NdefTypes';
import { HceOptions, HceReadHandler } from './src/types/HceTypes';
import { HCESession, HCESessionEventListenerCancel } from "react-native-hce";
import { NdefTagInfo } from "./src/types/NdefTypes";
import { HceOptions, HceReadHandler } from "./src/types/HceTypes";
declare module 'react-native-nfc-sdk' {
declare module "react-native-nfc-sdk" {
/**

@@ -11,4 +11,4 @@ * Class that provides methods for reading and writing ndef tags

/**
* Method for cancelling the current listener
*/
* Method for cancelling the current listener
*/
cancelRequest: () => void;

@@ -19,6 +19,6 @@

* Ndef tag and its decoded payload (as "content")
*
*
* @return {Promise<NdefTagInfo | undefined>} An object containing the id and the decoded payload of the NFC tag or undefined in case there was an error reading the tag (The error will be thrown).
*/
readTag (): Promise<NdefTagInfo | undefined>;
readTag(): Promise<NdefTagInfo | undefined>;

@@ -28,13 +28,13 @@ /**

* successfully, errors may be thrown
*
*
* @param value The value that will be written to the Ndef card
*
*
* @returns A boolean wether the card was written successfully or not
*/
writeTag (value: string): Promise<boolean>;
*/
writeTag(value: string): Promise<boolean>;
}
/**
* Class that provides methods for emulating a Ndef card with your phone
*/
* Class that provides methods for emulating a Ndef card with your phone
*/
class HceTools {

@@ -61,4 +61,4 @@ /**

*/
startEmulation (options: HceOptions, onRead: HceReadHandler): Promise<void>;
startEmulation(options: HceOptions, onRead: HceReadHandler): Promise<void>;
}
}
}
{
"name": "react-native-nfc-sdk",
"version": "0.3.3beta",
"version": "0.3.4beta",
"description": "A package which pretends to make NFC and HCE operations accessible to everyone on react native. Based on react-native-nfc-manager and react-native-hce",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

# react-native-nfc-sdk
[![NPM Version](https://badgen.net/badge/npm/v0.3.3-beta/yellow)](https://www.npmjs.com/package/react-native-nfc-sdk)
[![NPM Version](https://badgen.net/badge/npm/v0.3.4-beta/yellow)](https://www.npmjs.com/package/react-native-nfc-sdk)
[![Dev supported?](https://badgen.net/badge/dev_support/yes/green)](https://github.com/loridev/react-native-nfc-sdk/graphs/commit-activity)

@@ -228,2 +228,4 @@ [![License](https://badgen.net/badge/licence/GPL-3.0/orange)](https://github.com/loridev/react-native-nfc-sdk/blob/main/LICENSE)

- `0.3.4`: Code formatting for readibility
- `0.3.3`: Aclaration on expo in the documentation for new React Native versions

@@ -230,0 +232,0 @@

@@ -1,2 +0,7 @@

import { HCESessionEventListenerCancel, HCESession, NFCTagType4, NFCTagType4NDEFContentType } from "react-native-hce";
import {
HCESessionEventListenerCancel,
HCESession,
NFCTagType4,
NFCTagType4NDEFContentType,
} from "react-native-hce";
import { HceOptions, HceReadHandler } from "../types/HceTypes";

@@ -12,5 +17,4 @@

constructor () {
HCESession.getInstance()
.then(instance => this.hceSession = instance)
constructor() {
HCESession.getInstance().then((instance) => (this.hceSession = instance));
this.stopEmulation = async () => {

@@ -23,10 +27,10 @@ try {

}
}
};
}
async startEmulation (options: HceOptions, onRead: HceReadHandler) {
async startEmulation(options: HceOptions, onRead: HceReadHandler) {
const tag = new NFCTagType4({
type: NFCTagType4NDEFContentType.Text,
content: options.content,
writable: options.writable
writable: options.writable,
});

@@ -38,6 +42,9 @@

await this.hceSession.setEnabled(true);
this.removeListener = this.hceSession.on(HCESession.Events.HCE_STATE_READ, () => {
onRead();
this.stopEmulation();
});
this.removeListener = this.hceSession.on(
HCESession.Events.HCE_STATE_READ,
() => {
onRead();
this.stopEmulation();
}
);
} catch (err) {

@@ -47,2 +54,2 @@ throw err;

}
}
}

@@ -1,2 +0,2 @@

import NfcManager, { Ndef, NfcTech } from "react-native-nfc-manager";
import NfcManager, { Ndef, NfcTech } from "react-native-nfc-manager";
import { NdefTagInfo } from "../types/NdefTypes";

@@ -12,3 +12,3 @@

cancelRequest: () => void;
constructor () {
constructor() {
this.cancelRequest = () => NfcManager.cancelTechnologyRequest();

@@ -20,6 +20,6 @@ }

* Ndef tag and its decoded payload (as "content")
*
*
* @return { Promise<NdefTagInfo | undefined> } An object containing the id and the decoded payload of the NFC tag or undefined in case there was an error reading the tag (The error will be logged).
*/
async readTag (): Promise<NdefTagInfo | undefined> {
async readTag(): Promise<NdefTagInfo | undefined> {
try {

@@ -32,7 +32,8 @@ await NfcManager.requestTechnology(NfcTech.Ndef); // Request the hardware to listen for a specific technology

id: tag.id,
content: Ndef.uri.decodePayload(tag.ndefMessage[0].payload as unknown as Uint8Array)
.replace('https://www.en', ''), // Decoding the payload since is a buffer and we want to return the decoded payload
}
content: Ndef.uri
.decodePayload(tag.ndefMessage[0].payload as unknown as Uint8Array)
.replace("https://www.en", ""), // Decoding the payload since is a buffer and we want to return the decoded payload
};
} else {
throw new Error('Reading the tag was not possible.')
throw new Error("Reading the tag was not possible.");
}

@@ -46,15 +47,14 @@ } catch (err) {

/**
* Function that writes a value as the payload of a Ndef tag and returns a boolean wether the card was written
* successfully
*
*
* @param value The value that will be written to the Ndef card
*
*
* @returns A boolean wether the card was written successfully or not
*/
async writeTag (value: string): Promise<boolean> {
async writeTag(value: string): Promise<boolean> {
try {
await NfcManager.requestTechnology(NfcTech.Ndef);
const bytes = Ndef.encodeMessage([Ndef.textRecord(value)]); // Encoding as buffer the string we recieved

@@ -74,2 +74,2 @@

}
}
}
import NdefTools from "./classes/NdefTools";
import HceTools from "./classes/HceTools";
module.exports = { NdefTools, HceTools };
module.exports = { NdefTools, HceTools };
export type HceOptions = {
content: string,
writable: boolean
content: string;
writable: boolean;
};
export type HceReadHandler = () => void;
export type HceReadHandler = () => void;
export type NdefTagInfo = {
id: string,
content: string,
}
id: string;
content: string;
};