@ukeyfe/react-native-nfc-litecard 1.0.5 → 1.0.7
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/dist/index.d.ts +239 -7
- package/dist/index.js +1486 -49
- package/package.json +4 -2
- package/dist/constants.d.ts +0 -87
- package/dist/constants.js +0 -117
- package/dist/crypto.d.ts +0 -55
- package/dist/crypto.js +0 -271
- package/dist/nfc-core.d.ts +0 -74
- package/dist/nfc-core.js +0 -376
- package/dist/reader.d.ts +0 -98
- package/dist/reader.js +0 -619
- package/dist/types.d.ts +0 -80
- package/dist/types.js +0 -113
- package/dist/utils.d.ts +0 -43
- package/dist/utils.js +0 -124
- package/dist/writer.d.ts +0 -46
- package/dist/writer.js +0 -623
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,242 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Unified result codes, NfcResult interface, and error mapping helpers.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* All codes are unique across reader and writer to prevent ambiguity.
|
|
5
|
+
* - Reader success : 101xx
|
|
6
|
+
* - Writer success : 102xx
|
|
7
|
+
* - Failure : 4xxxx (shared)
|
|
8
|
+
*
|
|
9
|
+
* This library does NOT provide user-facing messages.
|
|
10
|
+
* The caller should map NfcStatusCode to their own localised strings.
|
|
11
|
+
*/
|
|
12
|
+
declare const NfcStatusCode: {
|
|
13
|
+
readonly READ_SUCCESS: 10102;
|
|
14
|
+
readonly READ_NICKNAME_SUCCESS: 10103;
|
|
15
|
+
readonly CHECK_EMPTY: 10104;
|
|
16
|
+
readonly CHECK_HAS_DATA: 10105;
|
|
17
|
+
readonly READ_RETRY_COUNT_SUCCESS: 10106;
|
|
18
|
+
readonly GET_VERSION_SUCCESS: 10107;
|
|
19
|
+
readonly READ_SIG_SUCCESS: 10108;
|
|
20
|
+
readonly INIT_SUCCESS: 10201;
|
|
21
|
+
readonly WRITE_SUCCESS: 10203;
|
|
22
|
+
readonly UPDATE_PASSWORD_SUCCESS: 10204;
|
|
23
|
+
readonly WRITE_NICKNAME_SUCCESS: 10205;
|
|
24
|
+
readonly RESET_SUCCESS: 10206;
|
|
25
|
+
/** Card already has a valid mnemonic backup; write was skipped */
|
|
26
|
+
readonly PRECHECK_HAS_BACKUP: 10207;
|
|
27
|
+
readonly NFC_CONNECT_FAILED: 40001;
|
|
28
|
+
readonly AUTH_WRONG_PASSWORD: 40002;
|
|
29
|
+
readonly AUTH_INVALID_RESPONSE: 40003;
|
|
30
|
+
readonly AUTH_VERIFY_FAILED: 40004;
|
|
31
|
+
readonly READ_FAILED: 40005;
|
|
32
|
+
readonly WRITE_FAILED: 40006;
|
|
33
|
+
readonly INVALID_MNEMONIC: 40007;
|
|
34
|
+
readonly UNSUPPORTED_MNEMONIC_LENGTH: 40008;
|
|
35
|
+
readonly INVALID_CARD_DATA: 40009;
|
|
36
|
+
readonly UNKNOWN_ERROR: 40010;
|
|
37
|
+
readonly NFC_USER_CANCELED: 40011;
|
|
38
|
+
readonly READ_TIMEOUT: 40012;
|
|
39
|
+
readonly NFC_LOCK_TIMEOUT: 40013;
|
|
40
|
+
readonly CRC16_CHECK_FAILED: 40014;
|
|
41
|
+
/** PIN retry counter is 0; no authentication attempts left */
|
|
42
|
+
readonly RETRY_COUNT_EXHAUSTED: 40015;
|
|
43
|
+
/** CMAC verification failed – response integrity compromised */
|
|
44
|
+
readonly CMAC_VERIFY_FAILED: 40016;
|
|
45
|
+
};
|
|
46
|
+
interface NfcResult {
|
|
47
|
+
/** Numeric result code – compare against NfcStatusCode constants */
|
|
48
|
+
code: number;
|
|
49
|
+
/** Whether the operation succeeded */
|
|
50
|
+
success: boolean;
|
|
51
|
+
/** Returned data (optional, only present for some operations) */
|
|
52
|
+
data?: {
|
|
53
|
+
mnemonic?: string;
|
|
54
|
+
type?: string;
|
|
55
|
+
entropyHex?: string;
|
|
56
|
+
rawBytes?: string;
|
|
57
|
+
nickname?: string;
|
|
58
|
+
retryCount?: number;
|
|
59
|
+
aesKeyHex?: string;
|
|
60
|
+
crc16?: number;
|
|
61
|
+
version?: {
|
|
62
|
+
vendorId: number;
|
|
63
|
+
productType: number;
|
|
64
|
+
productSubtype: number;
|
|
65
|
+
majorVersion: number;
|
|
66
|
+
minorVersion: number;
|
|
67
|
+
storageSize: number;
|
|
68
|
+
protocolType: number;
|
|
69
|
+
};
|
|
70
|
+
signature?: string;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Unified failure result when the PIN retry counter has reached 0.
|
|
75
|
+
* Used by readMnemonic, updateCard, updatePassword, and resetCard.
|
|
76
|
+
*/
|
|
77
|
+
declare function nfcResultRetryCountExhausted(): NfcResult;
|
|
78
|
+
|
|
79
|
+
/** Default retry limit, restored after a successful authentication */
|
|
80
|
+
declare const DEFAULT_PIN_RETRY_COUNT = 10;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Core NFC communication layer – shared by reader and writer.
|
|
84
|
+
*
|
|
85
|
+
* Provides:
|
|
86
|
+
* - A single global operation lock (prevents reader/writer concurrency)
|
|
87
|
+
* - Page-cleanup cancellation flags
|
|
88
|
+
* - Low-level transceive with platform-aware retries
|
|
89
|
+
* - NFC technology request / release
|
|
90
|
+
* - AES 3-pass mutual authentication (MF0AES(H)20 §8.6.1)
|
|
91
|
+
* - PIN retry-counter helpers (session-level read/write)
|
|
92
|
+
*/
|
|
93
|
+
|
|
94
|
+
declare function isNfcOperationLocked(): boolean;
|
|
95
|
+
declare function releaseNfcOperationLock(): void;
|
|
96
|
+
declare function markNfcOperationCancelledByCleanup(): void;
|
|
97
|
+
declare function consumeNfcOperationCancelledByCleanup(): boolean;
|
|
98
|
+
declare function getNfcOperationCancelledByCleanupTimestamp(): number;
|
|
99
|
+
declare function clearNfcOperationCancelledByCleanup(): void;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* NFC Reader Module
|
|
103
|
+
*
|
|
104
|
+
* Public API:
|
|
105
|
+
* - checkCard() – detect whether a card is empty or contains data
|
|
106
|
+
* - readMnemonic() – read mnemonic (password required)
|
|
107
|
+
* - readUserNickname() – read user nickname (password optional)
|
|
108
|
+
* - readMnemonicRetryCount() – read the PIN retry counter
|
|
109
|
+
* - resetRetryCountTo10() – reset the retry counter to default
|
|
110
|
+
* - cardInfoToJson() – serialise card-info to JSON
|
|
111
|
+
*
|
|
112
|
+
* Based on MIFARE Ultralight AES (MF0AES(H)20) datasheet.
|
|
113
|
+
*/
|
|
114
|
+
|
|
115
|
+
declare function parseCardInfo(data: Uint8Array): {
|
|
116
|
+
version: number;
|
|
117
|
+
cardType: number;
|
|
118
|
+
rawBytes: string;
|
|
119
|
+
infoBytes: Uint8Array<ArrayBuffer>;
|
|
120
|
+
json: {
|
|
121
|
+
pageInfo: {
|
|
122
|
+
startPage: number;
|
|
123
|
+
endPage: number;
|
|
124
|
+
totalPages: number;
|
|
125
|
+
totalBytes: number;
|
|
126
|
+
};
|
|
127
|
+
version: {
|
|
128
|
+
value: number;
|
|
129
|
+
hex: string;
|
|
130
|
+
};
|
|
131
|
+
cardType: {
|
|
132
|
+
value: number;
|
|
133
|
+
hex: string;
|
|
134
|
+
description: string;
|
|
135
|
+
known: boolean;
|
|
136
|
+
};
|
|
137
|
+
additionalInfo: {
|
|
138
|
+
hex: string;
|
|
139
|
+
bytes: number[];
|
|
140
|
+
};
|
|
141
|
+
rawData: {
|
|
142
|
+
hex: string;
|
|
143
|
+
bytes: number[];
|
|
144
|
+
length: number;
|
|
145
|
+
};
|
|
146
|
+
pageBreakdown: {
|
|
147
|
+
page: number;
|
|
148
|
+
bytes: number[];
|
|
149
|
+
hex: string;
|
|
150
|
+
}[];
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
/** Serialise parseCardInfo result to JSON. */
|
|
154
|
+
declare function cardInfoToJson(cardInfo: ReturnType<typeof parseCardInfo>, pretty?: boolean): string;
|
|
155
|
+
/**
|
|
156
|
+
* Detect whether the card is empty or already contains data.
|
|
157
|
+
*
|
|
158
|
+
* Without password: tries to read without auth.
|
|
159
|
+
* - Read succeeds & first byte is a valid mnemonic type → HAS_DATA
|
|
160
|
+
* - Read succeeds & first byte is other → EMPTY
|
|
161
|
+
* - Read fails (auth required) → HAS_DATA (read-protection is on, cannot determine)
|
|
162
|
+
*
|
|
163
|
+
* With password: authenticates first, then reads and validates with CRC16.
|
|
164
|
+
* - Valid mnemonic payload → HAS_DATA (with type info)
|
|
165
|
+
* - Empty or invalid data → EMPTY
|
|
166
|
+
* - Auth failure → AUTH_WRONG_PASSWORD
|
|
167
|
+
*/
|
|
168
|
+
declare function checkCard(password?: string, onCardIdentified?: () => void): Promise<NfcResult>;
|
|
169
|
+
/**
|
|
170
|
+
* Read the mnemonic from a password-protected card.
|
|
171
|
+
*
|
|
172
|
+
* Flow: connect → pre-decrement retry counter → authenticate → read →
|
|
173
|
+
* decode entropy → read nickname → reset retry counter → release
|
|
174
|
+
*/
|
|
175
|
+
declare function readMnemonic(password: string, onCardIdentified?: () => void): Promise<NfcResult>;
|
|
176
|
+
/**
|
|
177
|
+
* Read the user nickname from the card.
|
|
178
|
+
* @param password – supply if the card has read-protection enabled.
|
|
179
|
+
*/
|
|
180
|
+
declare function readUserNickname(password?: string, onCardIdentified?: () => void): Promise<NfcResult>;
|
|
181
|
+
/** Read the current PIN retry counter from the card. */
|
|
182
|
+
declare function readMnemonicRetryCount(onCardIdentified?: () => void): Promise<NfcResult>;
|
|
183
|
+
/** Reset the PIN retry counter to the default value (10). */
|
|
184
|
+
declare function resetRetryCountTo10(onCardIdentified?: () => void): Promise<NfcResult>;
|
|
185
|
+
/**
|
|
186
|
+
* Read card product version info (GET_VERSION command).
|
|
187
|
+
* No authentication required.
|
|
188
|
+
*/
|
|
189
|
+
declare function getCardVersion(onCardIdentified?: () => void): Promise<NfcResult>;
|
|
190
|
+
/**
|
|
191
|
+
* Read the ECC originality signature (READ_SIG command).
|
|
192
|
+
* Verifies the card is a genuine NXP product.
|
|
193
|
+
* No authentication required (unless Random ID is enabled).
|
|
194
|
+
*/
|
|
195
|
+
declare function readOriginality(onCardIdentified?: () => void): Promise<NfcResult>;
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* NFC Writer Module
|
|
199
|
+
*
|
|
200
|
+
* Public API:
|
|
201
|
+
* - initializeCard() – write mnemonic + set password on a blank card
|
|
202
|
+
* - updateCard() – update mnemonic & password (old password required)
|
|
203
|
+
* - updatePassword() – change password only
|
|
204
|
+
* - writeUserNickname() – write user nickname (password required)
|
|
205
|
+
* - resetCard() – wipe card and set password to "000000"
|
|
206
|
+
*
|
|
207
|
+
* Based on MIFARE Ultralight AES (MF0AES(H)20) datasheet.
|
|
208
|
+
*/
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Initialize a card: authenticate with the default password, then write
|
|
212
|
+
* mnemonic and set a new password.
|
|
213
|
+
*
|
|
214
|
+
* @param mnemonic BIP-39 mnemonic to write.
|
|
215
|
+
* @param newPassword Password to protect the card with after initialization.
|
|
216
|
+
* @param defaultPassword Current (factory-default) password on the card.
|
|
217
|
+
*/
|
|
218
|
+
declare function initializeCard(mnemonic: string, newPassword: string, defaultPassword: string, onCardIdentified?: () => void): Promise<NfcResult>;
|
|
219
|
+
/**
|
|
220
|
+
* Update card: authenticate with old password, then write new mnemonic + new password.
|
|
221
|
+
*
|
|
222
|
+
* When `options.precheckExistingMnemonic` is true, the card is read after authentication.
|
|
223
|
+
* If a valid mnemonic backup already exists, the write is skipped and PRECHECK_HAS_BACKUP
|
|
224
|
+
* is returned (`success: true` — operation completed; distinguish outcome by `code`).
|
|
225
|
+
* Otherwise the normal write flow proceeds.
|
|
226
|
+
*/
|
|
227
|
+
declare function updateCard(oldPassword: string, newPassword: string, newMnemonic: string, onCardIdentified?: () => void, options?: {
|
|
228
|
+
precheckExistingMnemonic?: boolean;
|
|
229
|
+
}): Promise<NfcResult>;
|
|
230
|
+
/** Change password only (old password required). */
|
|
231
|
+
declare function updatePassword(oldPassword: string, newPassword: string, onCardIdentified?: () => void): Promise<NfcResult>;
|
|
232
|
+
/** Write a user nickname (password required for authentication). */
|
|
233
|
+
declare function writeUserNickname(password: string, nickname: string, onCardIdentified?: () => void): Promise<NfcResult>;
|
|
234
|
+
/**
|
|
235
|
+
* Reset card: wipe mnemonic data and set a new password.
|
|
236
|
+
* @param password – current card password (required if protection is enabled).
|
|
237
|
+
* @param newPassword – password to set after reset.
|
|
238
|
+
* @param onCardIdentified – callback when card is identified.
|
|
5
239
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export { initializeCard,
|
|
9
|
-
export { isNfcOperationLocked, releaseNfcOperationLock, markNfcOperationCancelledByCleanup, consumeNfcOperationCancelledByCleanup, getNfcOperationCancelledByCleanupTimestamp, clearNfcOperationCancelledByCleanup, } from './nfc-core';
|
|
10
|
-
export { DEFAULT_PIN_RETRY_COUNT } from './constants';
|
|
240
|
+
declare function resetCard(password: string | undefined, newPassword: string, onCardIdentified?: () => void): Promise<NfcResult>;
|
|
241
|
+
|
|
242
|
+
export { DEFAULT_PIN_RETRY_COUNT, type NfcResult, NfcStatusCode, cardInfoToJson, checkCard, clearNfcOperationCancelledByCleanup, consumeNfcOperationCancelledByCleanup, getCardVersion, getNfcOperationCancelledByCleanupTimestamp, initializeCard, isNfcOperationLocked, markNfcOperationCancelledByCleanup, nfcResultRetryCountExhausted, readMnemonic, readMnemonicRetryCount, readOriginality, readUserNickname, releaseNfcOperationLock, resetCard, resetRetryCountTo10, updateCard, updatePassword, writeUserNickname };
|