@spencerls/react-native-nfc 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/API.md +214 -0
- package/README.md +150 -39
- package/dist/index.d.mts +97 -89
- package/dist/index.d.ts +97 -89
- package/dist/index.js +191 -104
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +193 -106
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,82 +1,6 @@
|
|
|
1
1
|
import * as react_native_nfc_manager from 'react-native-nfc-manager';
|
|
2
2
|
import { TagEvent, NfcTech, NdefRecord } from 'react-native-nfc-manager';
|
|
3
3
|
|
|
4
|
-
type StrictTagEvent = TagEvent & {
|
|
5
|
-
id: string;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
type NfcMode = "idle" | "starting" | "active" | "stopping" | "technology";
|
|
9
|
-
|
|
10
|
-
interface NfcState {
|
|
11
|
-
mode: NfcMode;
|
|
12
|
-
tag: TagEvent | null;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
type NfcListener = (state: NfcState) => void;
|
|
16
|
-
declare class NfcService {
|
|
17
|
-
private state;
|
|
18
|
-
private listeners;
|
|
19
|
-
constructor();
|
|
20
|
-
private setState;
|
|
21
|
-
getState(): NfcState;
|
|
22
|
-
subscribe(fn: NfcListener): () => void;
|
|
23
|
-
startReader(readerModeFlags: number, onTag?: (tag: TagEvent) => void): Promise<void>;
|
|
24
|
-
stopReader(): Promise<void>;
|
|
25
|
-
withTechnology<T>(tech: NfcTech | NfcTech[], handler: () => Promise<T>): Promise<T>;
|
|
26
|
-
}
|
|
27
|
-
declare const nfcService: NfcService;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* NFC root namespace providing access to:
|
|
31
|
-
* - NfcService
|
|
32
|
-
* - ISO15693 NFC-V ops
|
|
33
|
-
* - NFC-A ops
|
|
34
|
-
* - NDEF operations
|
|
35
|
-
*/
|
|
36
|
-
declare const nfc: {
|
|
37
|
-
readonly service: NfcService;
|
|
38
|
-
/** ISO15693 protocol helpers and high-level operations */
|
|
39
|
-
readonly v: {
|
|
40
|
-
readonly utils: {
|
|
41
|
-
readonly tech: react_native_nfc_manager.NfcTech.NfcV | react_native_nfc_manager.NfcTech[];
|
|
42
|
-
readonly Flags: {
|
|
43
|
-
readonly HIGH_DATA_RATE: 2;
|
|
44
|
-
readonly ADDRESSED: 32;
|
|
45
|
-
};
|
|
46
|
-
readonly Commands: {
|
|
47
|
-
readonly READ_SINGLE_BLOCK: 32;
|
|
48
|
-
readonly WRITE_SINGLE_BLOCK: 33;
|
|
49
|
-
readonly GET_SYSTEM_INFO: 43;
|
|
50
|
-
};
|
|
51
|
-
readonly flags: (...bits: number[]) => number;
|
|
52
|
-
readonly reverseUid: (tagIdHex: string) => number[];
|
|
53
|
-
readonly buildReadBlock: (uidReversed: number[], blockNumber: number) => number[];
|
|
54
|
-
readonly buildWriteBlock: (uidReversed: number[], blockNumber: number, data: Uint8Array) => number[];
|
|
55
|
-
readonly buildGetSystemInfo: (uidReversed: number[]) => number[];
|
|
56
|
-
readonly parseReadResponse: (resp: number[]) => Uint8Array;
|
|
57
|
-
readonly parseWriteResponse: (resp: number[]) => void;
|
|
58
|
-
readonly parseSystemInfo: (resp: number[]) => any;
|
|
59
|
-
readonly detectManufacturer: (uid: string) => string;
|
|
60
|
-
};
|
|
61
|
-
readonly withVTag: <T>(handler: (tag: StrictTagEvent) => Promise<T>) => Promise<T>;
|
|
62
|
-
readonly writeBlockNfcV: (blockNumber: number, data: Uint8Array) => Promise<void>;
|
|
63
|
-
readonly readBlockNfcV: (blockNumber: number) => Promise<Uint8Array<ArrayBufferLike>>;
|
|
64
|
-
readonly getSystemInfoNfcV: () => Promise<any>;
|
|
65
|
-
};
|
|
66
|
-
/** NFC-A / Type 2 helpers and operations */
|
|
67
|
-
readonly a: {
|
|
68
|
-
readonly utils: {};
|
|
69
|
-
readonly transceive: (data: number[]) => Promise<number[]>;
|
|
70
|
-
};
|
|
71
|
-
/** NDEF read/write utilities and operations */
|
|
72
|
-
readonly ndef: {
|
|
73
|
-
readonly utils: {};
|
|
74
|
-
readonly writeNdef: (records: react_native_nfc_manager.NdefRecord[]) => Promise<void>;
|
|
75
|
-
readonly writeTextNdef: (text: string) => Promise<void>;
|
|
76
|
-
readonly writeUriNdef: (uri: string) => Promise<void>;
|
|
77
|
-
};
|
|
78
|
-
};
|
|
79
|
-
|
|
80
4
|
declare const operations$2: {
|
|
81
5
|
transceive(data: number[]): Promise<number[]>;
|
|
82
6
|
};
|
|
@@ -87,26 +11,18 @@ declare namespace index$2 {
|
|
|
87
11
|
export { operations$2 as operations, utils$2 as utils };
|
|
88
12
|
}
|
|
89
13
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
writeTextNdef(text: string): Promise<void>;
|
|
93
|
-
writeUriNdef(uri: string): Promise<void>;
|
|
14
|
+
type StrictTagEvent = TagEvent & {
|
|
15
|
+
id: string;
|
|
94
16
|
};
|
|
95
17
|
|
|
96
|
-
declare const
|
|
97
|
-
|
|
98
|
-
declare namespace index$1 {
|
|
99
|
-
export { operations$1 as operations, utils$1 as utils };
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
declare const operations: {
|
|
18
|
+
declare const operations$1: {
|
|
103
19
|
withVTag<T>(handler: (tag: StrictTagEvent) => Promise<T>): Promise<T>;
|
|
104
20
|
writeBlockNfcV(blockNumber: number, data: Uint8Array): Promise<void>;
|
|
105
21
|
readBlockNfcV(blockNumber: number): Promise<Uint8Array<ArrayBufferLike>>;
|
|
106
22
|
getSystemInfoNfcV(): Promise<any>;
|
|
107
23
|
};
|
|
108
24
|
|
|
109
|
-
declare const utils: {
|
|
25
|
+
declare const utils$1: {
|
|
110
26
|
readonly tech: NfcTech.NfcV | NfcTech[];
|
|
111
27
|
readonly Flags: {
|
|
112
28
|
readonly HIGH_DATA_RATE: 2;
|
|
@@ -162,10 +78,102 @@ declare const utils: {
|
|
|
162
78
|
readonly detectManufacturer: (uid: string) => string;
|
|
163
79
|
};
|
|
164
80
|
|
|
81
|
+
declare namespace index$1 {
|
|
82
|
+
export { operations$1 as operations, utils$1 as utils };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
declare const operations: {
|
|
86
|
+
writeNdef(records: NdefRecord[]): Promise<void>;
|
|
87
|
+
writeTextNdef(text: string): Promise<void>;
|
|
88
|
+
writeUriNdef(uri: string): Promise<void>;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
declare const utils: {};
|
|
92
|
+
|
|
165
93
|
declare const index_operations: typeof operations;
|
|
166
94
|
declare const index_utils: typeof utils;
|
|
167
95
|
declare namespace index {
|
|
168
96
|
export { index_operations as operations, index_utils as utils };
|
|
169
97
|
}
|
|
170
98
|
|
|
171
|
-
|
|
99
|
+
type NfcMode = "idle" | "starting" | "active" | "stopping" | "technology";
|
|
100
|
+
|
|
101
|
+
interface NfcState {
|
|
102
|
+
mode: NfcMode;
|
|
103
|
+
tag: TagEvent | null;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
type NfcListener = (state: NfcState) => void;
|
|
107
|
+
declare class NfcService {
|
|
108
|
+
private state;
|
|
109
|
+
private listeners;
|
|
110
|
+
private isProcessingTag;
|
|
111
|
+
private currentOnTag?;
|
|
112
|
+
private currentCooldownMs;
|
|
113
|
+
private lastUsedReaderFlags;
|
|
114
|
+
constructor();
|
|
115
|
+
private setState;
|
|
116
|
+
getState(): NfcState;
|
|
117
|
+
subscribe(fn: NfcListener): () => void;
|
|
118
|
+
startReader(readerModeFlags: number, onTag?: (tag: TagEvent) => Promise<void> | void, options?: {
|
|
119
|
+
cooldownMs?: number;
|
|
120
|
+
}): Promise<void>;
|
|
121
|
+
stopReader(): Promise<void>;
|
|
122
|
+
private _resetReaderState;
|
|
123
|
+
private _restartIosReader;
|
|
124
|
+
withTechnology<T>(tech: NfcTech | NfcTech[], handler: () => Promise<T>): Promise<T>;
|
|
125
|
+
}
|
|
126
|
+
declare const nfcService: NfcService;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* NFC root namespace providing access to:
|
|
130
|
+
* - NfcService
|
|
131
|
+
* - ISO15693 NFC-V ops
|
|
132
|
+
* - NFC-A ops
|
|
133
|
+
* - NDEF operations
|
|
134
|
+
*/
|
|
135
|
+
declare const nfc: {
|
|
136
|
+
readonly service: NfcService;
|
|
137
|
+
/** ISO15693 protocol helpers and high-level operations */
|
|
138
|
+
readonly v: {
|
|
139
|
+
readonly utils: {
|
|
140
|
+
readonly tech: react_native_nfc_manager.NfcTech.NfcV | react_native_nfc_manager.NfcTech[];
|
|
141
|
+
readonly Flags: {
|
|
142
|
+
readonly HIGH_DATA_RATE: 2;
|
|
143
|
+
readonly ADDRESSED: 32;
|
|
144
|
+
};
|
|
145
|
+
readonly Commands: {
|
|
146
|
+
readonly READ_SINGLE_BLOCK: 32;
|
|
147
|
+
readonly WRITE_SINGLE_BLOCK: 33;
|
|
148
|
+
readonly GET_SYSTEM_INFO: 43;
|
|
149
|
+
};
|
|
150
|
+
readonly flags: (...bits: number[]) => number;
|
|
151
|
+
readonly reverseUid: (tagIdHex: string) => number[];
|
|
152
|
+
readonly buildReadBlock: (uidReversed: number[], blockNumber: number) => number[];
|
|
153
|
+
readonly buildWriteBlock: (uidReversed: number[], blockNumber: number, data: Uint8Array) => number[];
|
|
154
|
+
readonly buildGetSystemInfo: (uidReversed: number[]) => number[];
|
|
155
|
+
readonly parseReadResponse: (resp: number[]) => Uint8Array;
|
|
156
|
+
readonly parseWriteResponse: (resp: number[]) => void;
|
|
157
|
+
readonly parseSystemInfo: (resp: number[]) => any;
|
|
158
|
+
readonly detectManufacturer: (uid: string) => string;
|
|
159
|
+
};
|
|
160
|
+
readonly withVTag: <T>(handler: (tag: StrictTagEvent) => Promise<T>) => Promise<T>;
|
|
161
|
+
readonly writeBlockNfcV: (blockNumber: number, data: Uint8Array) => Promise<void>;
|
|
162
|
+
readonly readBlockNfcV: (blockNumber: number) => Promise<Uint8Array<ArrayBufferLike>>;
|
|
163
|
+
readonly getSystemInfoNfcV: () => Promise<any>;
|
|
164
|
+
};
|
|
165
|
+
/** NFC-A / Type 2 helpers and operations */
|
|
166
|
+
readonly a: {
|
|
167
|
+
readonly utils: {};
|
|
168
|
+
readonly transceive: (data: number[]) => Promise<number[]>;
|
|
169
|
+
};
|
|
170
|
+
/** NDEF read/write utilities and operations */
|
|
171
|
+
readonly ndef: {
|
|
172
|
+
readonly utils: {};
|
|
173
|
+
readonly writeNdef: (records: react_native_nfc_manager.NdefRecord[]) => Promise<void>;
|
|
174
|
+
readonly writeTextNdef: (text: string) => Promise<void>;
|
|
175
|
+
readonly writeUriNdef: (uri: string) => Promise<void>;
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
export { type NfcMode, type NfcState, nfc, index$2 as nfcA, index as nfcNdef, nfcService, index$1 as nfcV };
|
package/dist/index.js
CHANGED
|
@@ -27,27 +27,43 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
|
|
30
|
-
// src/
|
|
30
|
+
// src/nfc/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
-
ndef: () => ndef_exports,
|
|
34
33
|
nfc: () => nfc,
|
|
35
34
|
nfcA: () => a_exports,
|
|
35
|
+
nfcNdef: () => ndef_exports,
|
|
36
36
|
nfcService: () => nfcService,
|
|
37
37
|
nfcV: () => v_exports
|
|
38
38
|
});
|
|
39
39
|
module.exports = __toCommonJS(index_exports);
|
|
40
40
|
|
|
41
|
-
// src/
|
|
41
|
+
// src/nfc/a/index.ts
|
|
42
|
+
var a_exports = {};
|
|
43
|
+
__export(a_exports, {
|
|
44
|
+
operations: () => operations,
|
|
45
|
+
utils: () => utils
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// src/nfc/a/operations.ts
|
|
49
|
+
var import_react_native_nfc_manager2 = __toESM(require("react-native-nfc-manager"));
|
|
50
|
+
|
|
51
|
+
// src/nfc/service.ts
|
|
42
52
|
var import_react_native = require("react-native");
|
|
43
53
|
var import_react_native_nfc_manager = __toESM(require("react-native-nfc-manager"));
|
|
44
54
|
var NfcService = class {
|
|
55
|
+
// needed for iOS restart
|
|
45
56
|
constructor() {
|
|
46
57
|
this.state = { mode: "idle", tag: null };
|
|
47
58
|
this.listeners = /* @__PURE__ */ new Set();
|
|
59
|
+
this.isProcessingTag = false;
|
|
60
|
+
this.currentCooldownMs = 1500;
|
|
61
|
+
this.lastUsedReaderFlags = null;
|
|
48
62
|
import_react_native_nfc_manager.default.start();
|
|
49
63
|
}
|
|
50
|
-
//
|
|
64
|
+
// -----------------------------
|
|
65
|
+
// Internal state management
|
|
66
|
+
// -----------------------------
|
|
51
67
|
setState(partial) {
|
|
52
68
|
this.state = { ...this.state, ...partial };
|
|
53
69
|
for (const listener of this.listeners) listener(this.state);
|
|
@@ -62,17 +78,45 @@ var NfcService = class {
|
|
|
62
78
|
this.listeners.delete(fn);
|
|
63
79
|
};
|
|
64
80
|
}
|
|
65
|
-
//
|
|
66
|
-
|
|
81
|
+
// -----------------------------
|
|
82
|
+
// START READER
|
|
83
|
+
// -----------------------------
|
|
84
|
+
async startReader(readerModeFlags, onTag, options) {
|
|
85
|
+
var _a;
|
|
67
86
|
if (this.state.mode !== "idle") {
|
|
68
87
|
console.warn(`[NFC] Cannot start reader while ${this.state.mode}`);
|
|
69
88
|
return;
|
|
70
89
|
}
|
|
71
|
-
this.
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
});
|
|
90
|
+
this.currentOnTag = onTag;
|
|
91
|
+
this.currentCooldownMs = (_a = options == null ? void 0 : options.cooldownMs) != null ? _a : 1500;
|
|
92
|
+
this.lastUsedReaderFlags = readerModeFlags;
|
|
93
|
+
this.isProcessingTag = false;
|
|
94
|
+
this.setState({ mode: "starting", tag: null });
|
|
95
|
+
import_react_native_nfc_manager.default.setEventListener(
|
|
96
|
+
import_react_native_nfc_manager.NfcEvents.DiscoverTag,
|
|
97
|
+
async (tag) => {
|
|
98
|
+
if (!tag) return;
|
|
99
|
+
if (this.isProcessingTag) return;
|
|
100
|
+
this.isProcessingTag = true;
|
|
101
|
+
this.setState({ tag, mode: "active" });
|
|
102
|
+
try {
|
|
103
|
+
if (this.currentOnTag) {
|
|
104
|
+
await this.currentOnTag(tag);
|
|
105
|
+
}
|
|
106
|
+
} catch (err) {
|
|
107
|
+
console.warn("[NFC] onTag handler error:", err);
|
|
108
|
+
} finally {
|
|
109
|
+
const cooldown = this.currentCooldownMs;
|
|
110
|
+
setTimeout(async () => {
|
|
111
|
+
this.isProcessingTag = false;
|
|
112
|
+
this.setState({ tag: null, mode: "active" });
|
|
113
|
+
if (import_react_native.Platform.OS === "ios") {
|
|
114
|
+
await this._restartIosReader();
|
|
115
|
+
}
|
|
116
|
+
}, cooldown);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
);
|
|
76
120
|
try {
|
|
77
121
|
await import_react_native_nfc_manager.default.registerTagEvent({
|
|
78
122
|
isReaderModeEnabled: true,
|
|
@@ -83,23 +127,53 @@ var NfcService = class {
|
|
|
83
127
|
}
|
|
84
128
|
} catch (err) {
|
|
85
129
|
console.warn("[NFC] startReader error:", err);
|
|
86
|
-
this.
|
|
130
|
+
this._resetReaderState();
|
|
87
131
|
}
|
|
88
132
|
}
|
|
133
|
+
// -----------------------------
|
|
134
|
+
// STOP READER
|
|
135
|
+
// -----------------------------
|
|
89
136
|
async stopReader() {
|
|
90
137
|
if (["idle", "stopping"].includes(this.state.mode)) return;
|
|
91
138
|
this.setState({ mode: "stopping" });
|
|
92
139
|
try {
|
|
93
140
|
await import_react_native_nfc_manager.default.unregisterTagEvent();
|
|
94
|
-
} catch {
|
|
141
|
+
} catch (err) {
|
|
142
|
+
console.warn("[NFC] unregisterTagEvent error:", err);
|
|
95
143
|
}
|
|
96
|
-
this.
|
|
144
|
+
this._resetReaderState();
|
|
97
145
|
}
|
|
146
|
+
_resetReaderState() {
|
|
147
|
+
this.setState({ mode: "idle", tag: null });
|
|
148
|
+
this.currentOnTag = void 0;
|
|
149
|
+
this.isProcessingTag = false;
|
|
150
|
+
}
|
|
151
|
+
// -----------------------------
|
|
152
|
+
// iOS RESTART
|
|
153
|
+
// -----------------------------
|
|
154
|
+
async _restartIosReader() {
|
|
155
|
+
if (import_react_native.Platform.OS !== "ios") return;
|
|
156
|
+
if (this.lastUsedReaderFlags == null) return;
|
|
157
|
+
try {
|
|
158
|
+
await import_react_native_nfc_manager.default.unregisterTagEvent();
|
|
159
|
+
await import_react_native_nfc_manager.default.registerTagEvent({
|
|
160
|
+
isReaderModeEnabled: true,
|
|
161
|
+
readerModeFlags: this.lastUsedReaderFlags
|
|
162
|
+
});
|
|
163
|
+
this.setState({ mode: "active" });
|
|
164
|
+
} catch (err) {
|
|
165
|
+
console.warn("[NFC] iOS restart error:", err);
|
|
166
|
+
this._resetReaderState();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
// -----------------------------
|
|
170
|
+
// Technology sessions (NDEF, NfcV, etc.)
|
|
171
|
+
// -----------------------------
|
|
98
172
|
async withTechnology(tech, handler) {
|
|
99
173
|
if (this.state.mode === "technology") {
|
|
100
|
-
throw new Error(
|
|
174
|
+
throw new Error("[NFC] Technology is already in use!");
|
|
101
175
|
}
|
|
102
|
-
if (
|
|
176
|
+
if (["starting", "active", "stopping"].includes(this.state.mode)) {
|
|
103
177
|
await this.stopReader();
|
|
104
178
|
}
|
|
105
179
|
if (this.state.mode !== "idle") {
|
|
@@ -107,15 +181,15 @@ var NfcService = class {
|
|
|
107
181
|
`[NFC] Cannot start technology session in mode ${this.state.mode}`
|
|
108
182
|
);
|
|
109
183
|
}
|
|
110
|
-
this.setState({ mode: "technology" });
|
|
184
|
+
this.setState({ mode: "technology", tag: null });
|
|
111
185
|
try {
|
|
112
186
|
await import_react_native_nfc_manager.default.requestTechnology(tech, {
|
|
113
187
|
alertMessage: "Hold near NFC tag"
|
|
114
|
-
// iOS
|
|
115
188
|
});
|
|
116
189
|
const result = await handler();
|
|
117
|
-
if (import_react_native.Platform.OS === "ios")
|
|
190
|
+
if (import_react_native.Platform.OS === "ios") {
|
|
118
191
|
await import_react_native_nfc_manager.default.setAlertMessageIOS("Success!");
|
|
192
|
+
}
|
|
119
193
|
return result;
|
|
120
194
|
} catch (err) {
|
|
121
195
|
const message = typeof err === "string" ? err : (err == null ? void 0 : err.message) || "Unknown NFC error";
|
|
@@ -123,24 +197,15 @@ var NfcService = class {
|
|
|
123
197
|
} finally {
|
|
124
198
|
try {
|
|
125
199
|
await import_react_native_nfc_manager.default.cancelTechnologyRequest();
|
|
126
|
-
} catch
|
|
127
|
-
console.warn("[NFC] cancelTechnologyRequest failed:", cancelErr);
|
|
200
|
+
} catch {
|
|
128
201
|
}
|
|
129
|
-
this.setState({ mode: "idle" });
|
|
202
|
+
this.setState({ mode: "idle", tag: null });
|
|
130
203
|
}
|
|
131
204
|
}
|
|
132
205
|
};
|
|
133
206
|
var nfcService = new NfcService();
|
|
134
207
|
|
|
135
|
-
// src/
|
|
136
|
-
var a_exports = {};
|
|
137
|
-
__export(a_exports, {
|
|
138
|
-
operations: () => operations,
|
|
139
|
-
utils: () => utils
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
// src/services/nfc/a/operations.ts
|
|
143
|
-
var import_react_native_nfc_manager2 = __toESM(require("react-native-nfc-manager"));
|
|
208
|
+
// src/nfc/a/operations.ts
|
|
144
209
|
var operations = {
|
|
145
210
|
async transceive(data) {
|
|
146
211
|
return nfcService.withTechnology(import_react_native_nfc_manager2.NfcTech.NfcA, async () => {
|
|
@@ -149,56 +214,27 @@ var operations = {
|
|
|
149
214
|
}
|
|
150
215
|
};
|
|
151
216
|
|
|
152
|
-
// src/
|
|
217
|
+
// src/nfc/a/utils.ts
|
|
153
218
|
var utils = {};
|
|
154
219
|
|
|
155
|
-
// src/
|
|
156
|
-
var ndef_exports = {};
|
|
157
|
-
__export(ndef_exports, {
|
|
158
|
-
operations: () => operations2,
|
|
159
|
-
utils: () => utils2
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
// src/services/nfc/ndef/operations.ts
|
|
163
|
-
var import_react_native_nfc_manager3 = __toESM(require("react-native-nfc-manager"));
|
|
164
|
-
var operations2 = {
|
|
165
|
-
async writeNdef(records) {
|
|
166
|
-
await nfcService.withTechnology([import_react_native_nfc_manager3.NfcTech.Ndef, import_react_native_nfc_manager3.NfcTech.NfcA], async () => {
|
|
167
|
-
const bytes = import_react_native_nfc_manager3.Ndef.encodeMessage(records);
|
|
168
|
-
await import_react_native_nfc_manager3.default.ndefHandler.writeNdefMessage(bytes);
|
|
169
|
-
});
|
|
170
|
-
},
|
|
171
|
-
writeTextNdef(text) {
|
|
172
|
-
const record = import_react_native_nfc_manager3.Ndef.textRecord(text);
|
|
173
|
-
return this.writeNdef([record]);
|
|
174
|
-
},
|
|
175
|
-
writeUriNdef(uri) {
|
|
176
|
-
const record = import_react_native_nfc_manager3.Ndef.uriRecord(uri);
|
|
177
|
-
return this.writeNdef([record]);
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
// src/services/nfc/ndef/utils.ts
|
|
182
|
-
var utils2 = {};
|
|
183
|
-
|
|
184
|
-
// src/services/nfc/v/index.ts
|
|
220
|
+
// src/nfc/v/index.ts
|
|
185
221
|
var v_exports = {};
|
|
186
222
|
__export(v_exports, {
|
|
187
|
-
operations: () =>
|
|
188
|
-
utils: () =>
|
|
223
|
+
operations: () => operations2,
|
|
224
|
+
utils: () => utils2
|
|
189
225
|
});
|
|
190
226
|
|
|
191
|
-
// src/
|
|
192
|
-
var import_react_native_nfc_manager6 = __toESM(require("react-native-nfc-manager"));
|
|
193
|
-
|
|
194
|
-
// src/services/nfc/v/internal.ts
|
|
227
|
+
// src/nfc/v/operations.ts
|
|
195
228
|
var import_react_native_nfc_manager5 = __toESM(require("react-native-nfc-manager"));
|
|
196
229
|
|
|
197
|
-
// src/
|
|
230
|
+
// src/nfc/v/internal.ts
|
|
231
|
+
var import_react_native_nfc_manager4 = __toESM(require("react-native-nfc-manager"));
|
|
232
|
+
|
|
233
|
+
// src/nfc/v/utils.ts
|
|
198
234
|
var import_react_native2 = require("react-native");
|
|
199
|
-
var
|
|
200
|
-
var
|
|
201
|
-
tech: import_react_native2.Platform.OS === "ios" ? [
|
|
235
|
+
var import_react_native_nfc_manager3 = require("react-native-nfc-manager");
|
|
236
|
+
var utils2 = {
|
|
237
|
+
tech: import_react_native2.Platform.OS === "ios" ? [import_react_native_nfc_manager3.NfcTech.Iso15693IOS] : import_react_native_nfc_manager3.NfcTech.NfcV,
|
|
202
238
|
Flags: {
|
|
203
239
|
HIGH_DATA_RATE: 2,
|
|
204
240
|
ADDRESSED: 32
|
|
@@ -223,7 +259,7 @@ var utils3 = {
|
|
|
223
259
|
reverseUid(tagIdHex) {
|
|
224
260
|
const bytes = [];
|
|
225
261
|
for (let i = 0; i < tagIdHex.length; i += 2) {
|
|
226
|
-
bytes.unshift(parseInt(tagIdHex.substring(i, i + 2), 16));
|
|
262
|
+
bytes.unshift(Number.parseInt(tagIdHex.substring(i, i + 2), 16));
|
|
227
263
|
}
|
|
228
264
|
return bytes;
|
|
229
265
|
},
|
|
@@ -270,8 +306,12 @@ var utils3 = {
|
|
|
270
306
|
if (!resp || resp.length === 0) {
|
|
271
307
|
throw new Error("Empty NFC-V response");
|
|
272
308
|
}
|
|
273
|
-
|
|
274
|
-
|
|
309
|
+
const status = resp[0];
|
|
310
|
+
if (status === void 0) {
|
|
311
|
+
throw new Error("Invalid NFC-V response: missing status byte");
|
|
312
|
+
}
|
|
313
|
+
if (status !== 0) {
|
|
314
|
+
throw new Error(`Read failed. Status: 0x${status.toString(16)}`);
|
|
275
315
|
}
|
|
276
316
|
return new Uint8Array(resp.slice(1));
|
|
277
317
|
},
|
|
@@ -283,8 +323,12 @@ var utils3 = {
|
|
|
283
323
|
if (!resp || resp.length === 0) {
|
|
284
324
|
throw new Error("Empty NFC-V response");
|
|
285
325
|
}
|
|
286
|
-
|
|
287
|
-
|
|
326
|
+
const status = resp[0];
|
|
327
|
+
if (status === void 0) {
|
|
328
|
+
throw new Error("Invalid NFC-V response: missing status byte");
|
|
329
|
+
}
|
|
330
|
+
if (status !== 0) {
|
|
331
|
+
throw new Error(`Write failed. Status: 0x${status.toString(16)}`);
|
|
288
332
|
}
|
|
289
333
|
},
|
|
290
334
|
/**
|
|
@@ -293,10 +337,18 @@ var utils3 = {
|
|
|
293
337
|
*/
|
|
294
338
|
parseSystemInfo(resp) {
|
|
295
339
|
var _a;
|
|
296
|
-
if (!resp || resp.length < 2
|
|
340
|
+
if (!resp || resp.length < 2) {
|
|
297
341
|
throw new Error("Invalid System Info response");
|
|
298
342
|
}
|
|
299
|
-
const
|
|
343
|
+
const status = resp[0];
|
|
344
|
+
if (status === void 0 || status !== 0) {
|
|
345
|
+
throw new Error("Invalid System Info response");
|
|
346
|
+
}
|
|
347
|
+
const flagsByte = resp[1];
|
|
348
|
+
if (flagsByte === void 0) {
|
|
349
|
+
throw new Error("Invalid System Info response: missing flags byte");
|
|
350
|
+
}
|
|
351
|
+
const infoFlags = flagsByte & 15;
|
|
300
352
|
let offset = 2;
|
|
301
353
|
const result = {};
|
|
302
354
|
if (resp.length >= offset + 8) {
|
|
@@ -311,8 +363,14 @@ var utils3 = {
|
|
|
311
363
|
result.afi = resp[offset++];
|
|
312
364
|
}
|
|
313
365
|
if (infoFlags & 4 && resp.length >= offset + 2) {
|
|
314
|
-
|
|
315
|
-
|
|
366
|
+
const numBlocks = resp[offset++];
|
|
367
|
+
const blkSize = resp[offset++];
|
|
368
|
+
if (numBlocks !== void 0) {
|
|
369
|
+
result.numberOfBlocks = numBlocks + 1;
|
|
370
|
+
}
|
|
371
|
+
if (blkSize !== void 0) {
|
|
372
|
+
result.blockSize = blkSize + 1;
|
|
373
|
+
}
|
|
316
374
|
}
|
|
317
375
|
if (infoFlags & 8 && resp.length > offset) {
|
|
318
376
|
result.icReference = resp[offset++];
|
|
@@ -332,31 +390,31 @@ var utils3 = {
|
|
|
332
390
|
}
|
|
333
391
|
};
|
|
334
392
|
|
|
335
|
-
// src/
|
|
393
|
+
// src/nfc/v/internal.ts
|
|
336
394
|
async function readBlockRaw(tag, blockNumber) {
|
|
337
|
-
const uid =
|
|
338
|
-
const cmd =
|
|
339
|
-
const resp = await
|
|
340
|
-
return
|
|
395
|
+
const uid = utils2.reverseUid(tag.id);
|
|
396
|
+
const cmd = utils2.buildReadBlock(uid, blockNumber);
|
|
397
|
+
const resp = await import_react_native_nfc_manager4.default.transceive(cmd);
|
|
398
|
+
return utils2.parseReadResponse(resp);
|
|
341
399
|
}
|
|
342
400
|
async function writeBlockRaw(tag, blockNumber, data) {
|
|
343
|
-
const uid =
|
|
344
|
-
const cmd =
|
|
345
|
-
const resp = await
|
|
346
|
-
return
|
|
401
|
+
const uid = utils2.reverseUid(tag.id);
|
|
402
|
+
const cmd = utils2.buildWriteBlock(uid, blockNumber, data);
|
|
403
|
+
const resp = await import_react_native_nfc_manager4.default.transceive(cmd);
|
|
404
|
+
return utils2.parseWriteResponse(resp);
|
|
347
405
|
}
|
|
348
406
|
async function getSystemInfoRaw(tag) {
|
|
349
|
-
const uid =
|
|
350
|
-
const cmd =
|
|
351
|
-
const resp = await
|
|
352
|
-
return
|
|
407
|
+
const uid = utils2.reverseUid(tag.id);
|
|
408
|
+
const cmd = utils2.buildGetSystemInfo(uid);
|
|
409
|
+
const resp = await import_react_native_nfc_manager4.default.transceive(cmd);
|
|
410
|
+
return utils2.parseSystemInfo(resp);
|
|
353
411
|
}
|
|
354
412
|
|
|
355
|
-
// src/
|
|
356
|
-
var
|
|
413
|
+
// src/nfc/v/operations.ts
|
|
414
|
+
var operations2 = {
|
|
357
415
|
async withVTag(handler) {
|
|
358
|
-
return nfcService.withTechnology(
|
|
359
|
-
const tag = await
|
|
416
|
+
return nfcService.withTechnology(utils2.tech, async () => {
|
|
417
|
+
const tag = await import_react_native_nfc_manager5.default.getTag();
|
|
360
418
|
if (!(tag == null ? void 0 : tag.id)) throw new Error("No NFC-V tag detected");
|
|
361
419
|
return handler(tag);
|
|
362
420
|
});
|
|
@@ -372,14 +430,43 @@ var operations3 = {
|
|
|
372
430
|
}
|
|
373
431
|
};
|
|
374
432
|
|
|
375
|
-
// src/
|
|
433
|
+
// src/nfc/ndef/index.ts
|
|
434
|
+
var ndef_exports = {};
|
|
435
|
+
__export(ndef_exports, {
|
|
436
|
+
operations: () => operations3,
|
|
437
|
+
utils: () => utils3
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
// src/nfc/ndef/operations.ts
|
|
441
|
+
var import_react_native_nfc_manager6 = __toESM(require("react-native-nfc-manager"));
|
|
442
|
+
var operations3 = {
|
|
443
|
+
async writeNdef(records) {
|
|
444
|
+
await nfcService.withTechnology([import_react_native_nfc_manager6.NfcTech.Ndef, import_react_native_nfc_manager6.NfcTech.NfcA], async () => {
|
|
445
|
+
const bytes = import_react_native_nfc_manager6.Ndef.encodeMessage(records);
|
|
446
|
+
await import_react_native_nfc_manager6.default.ndefHandler.writeNdefMessage(bytes);
|
|
447
|
+
});
|
|
448
|
+
},
|
|
449
|
+
writeTextNdef(text) {
|
|
450
|
+
const record = import_react_native_nfc_manager6.Ndef.textRecord(text);
|
|
451
|
+
return this.writeNdef([record]);
|
|
452
|
+
},
|
|
453
|
+
writeUriNdef(uri) {
|
|
454
|
+
const record = import_react_native_nfc_manager6.Ndef.uriRecord(uri);
|
|
455
|
+
return this.writeNdef([record]);
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
|
|
459
|
+
// src/nfc/ndef/utils.ts
|
|
460
|
+
var utils3 = {};
|
|
461
|
+
|
|
462
|
+
// src/nfc/namespace.ts
|
|
376
463
|
var nfc = {
|
|
377
464
|
service: nfcService,
|
|
378
465
|
/** ISO15693 protocol helpers and high-level operations */
|
|
379
466
|
v: {
|
|
380
|
-
...
|
|
467
|
+
...operations2,
|
|
381
468
|
// NfcVOperations, nfcV
|
|
382
|
-
utils:
|
|
469
|
+
utils: utils2
|
|
383
470
|
},
|
|
384
471
|
/** NFC-A / Type 2 helpers and operations */
|
|
385
472
|
a: {
|
|
@@ -388,15 +475,15 @@ var nfc = {
|
|
|
388
475
|
},
|
|
389
476
|
/** NDEF read/write utilities and operations */
|
|
390
477
|
ndef: {
|
|
391
|
-
...
|
|
392
|
-
utils:
|
|
478
|
+
...operations3,
|
|
479
|
+
utils: utils3
|
|
393
480
|
}
|
|
394
481
|
};
|
|
395
482
|
// Annotate the CommonJS export names for ESM import in node:
|
|
396
483
|
0 && (module.exports = {
|
|
397
|
-
ndef,
|
|
398
484
|
nfc,
|
|
399
485
|
nfcA,
|
|
486
|
+
nfcNdef,
|
|
400
487
|
nfcService,
|
|
401
488
|
nfcV
|
|
402
489
|
});
|