@ukeyfe/react-native-nfc-litecard 1.0.7 → 1.0.9
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.js +17 -48
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -262,47 +262,20 @@ function validateMnemonicPayload(data) {
|
|
|
262
262
|
}
|
|
263
263
|
|
|
264
264
|
// src/crypto.ts
|
|
265
|
-
var
|
|
265
|
+
var import_aes_js = __toESM(require("aes-js"));
|
|
266
|
+
var import_js_sha256 = require("js-sha256");
|
|
266
267
|
function passwordToAesKey(password) {
|
|
267
268
|
const safePassword = password || "";
|
|
268
|
-
const
|
|
269
|
-
|
|
270
|
-
for (let i = 0; i < 16; i++) {
|
|
271
|
-
key[i] = parseInt(hash.substring(i * 2, i * 2 + 2), 16);
|
|
272
|
-
}
|
|
273
|
-
return key;
|
|
269
|
+
const hashBytes = import_js_sha256.sha256.arrayBuffer(String(safePassword));
|
|
270
|
+
return new Uint8Array(hashBytes).slice(0, 16);
|
|
274
271
|
}
|
|
275
272
|
function aesDecrypt(key, data, iv) {
|
|
276
|
-
const
|
|
277
|
-
|
|
278
|
-
const dataWords = import_crypto_js.default.lib.WordArray.create(data);
|
|
279
|
-
const decrypted = import_crypto_js.default.AES.decrypt(
|
|
280
|
-
{ ciphertext: dataWords },
|
|
281
|
-
keyWords,
|
|
282
|
-
{ iv: ivWords, mode: import_crypto_js.default.mode.CBC, padding: import_crypto_js.default.pad.NoPadding }
|
|
283
|
-
);
|
|
284
|
-
const hex = decrypted.toString();
|
|
285
|
-
const result = new Uint8Array(16);
|
|
286
|
-
for (let i = 0; i < 16; i++) {
|
|
287
|
-
result[i] = parseInt(hex.substring(i * 2, i * 2 + 2), 16);
|
|
288
|
-
}
|
|
289
|
-
return result;
|
|
273
|
+
const aesCbc = new import_aes_js.default.ModeOfOperation.cbc(Array.from(key), Array.from(iv));
|
|
274
|
+
return new Uint8Array(aesCbc.decrypt(Array.from(data)));
|
|
290
275
|
}
|
|
291
276
|
function aesEncrypt(key, data, iv) {
|
|
292
|
-
const
|
|
293
|
-
|
|
294
|
-
const dataWords = import_crypto_js.default.lib.WordArray.create(data);
|
|
295
|
-
const encrypted = import_crypto_js.default.AES.encrypt(dataWords, keyWords, {
|
|
296
|
-
iv: ivWords,
|
|
297
|
-
mode: import_crypto_js.default.mode.CBC,
|
|
298
|
-
padding: import_crypto_js.default.pad.NoPadding
|
|
299
|
-
});
|
|
300
|
-
const hex = encrypted.ciphertext.toString();
|
|
301
|
-
const result = new Uint8Array(hex.length / 2);
|
|
302
|
-
for (let i = 0; i < result.length; i++) {
|
|
303
|
-
result[i] = parseInt(hex.substring(i * 2, i * 2 + 2), 16);
|
|
304
|
-
}
|
|
305
|
-
return result;
|
|
277
|
+
const aesCbc = new import_aes_js.default.ModeOfOperation.cbc(Array.from(key), Array.from(iv));
|
|
278
|
+
return new Uint8Array(aesCbc.encrypt(Array.from(data)));
|
|
306
279
|
}
|
|
307
280
|
function rotateLeft8(data) {
|
|
308
281
|
const result = new Uint8Array(data.length);
|
|
@@ -320,18 +293,8 @@ function arraysEqual(a, b) {
|
|
|
320
293
|
return true;
|
|
321
294
|
}
|
|
322
295
|
function aesEcbEncrypt(key, data) {
|
|
323
|
-
const
|
|
324
|
-
|
|
325
|
-
const encrypted = import_crypto_js.default.AES.encrypt(dataWords, keyWords, {
|
|
326
|
-
mode: import_crypto_js.default.mode.ECB,
|
|
327
|
-
padding: import_crypto_js.default.pad.NoPadding
|
|
328
|
-
});
|
|
329
|
-
const hex = encrypted.ciphertext.toString();
|
|
330
|
-
const result = new Uint8Array(16);
|
|
331
|
-
for (let i = 0; i < 16; i++) {
|
|
332
|
-
result[i] = parseInt(hex.substring(i * 2, i * 2 + 2), 16);
|
|
333
|
-
}
|
|
334
|
-
return result;
|
|
296
|
+
const aesEcb = new import_aes_js.default.ModeOfOperation.ecb(Array.from(key));
|
|
297
|
+
return new Uint8Array(aesEcb.encrypt(Array.from(data)));
|
|
335
298
|
}
|
|
336
299
|
var CONST_RB = 135;
|
|
337
300
|
function shiftLeft1(data) {
|
|
@@ -1053,6 +1016,9 @@ async function writeUserMemory(data) {
|
|
|
1053
1016
|
const offset = i * PAGE_SIZE;
|
|
1054
1017
|
const pageData = Array.from(buffer.slice(offset, offset + PAGE_SIZE));
|
|
1055
1018
|
await writePage(page, pageData);
|
|
1019
|
+
if (import_react_native3.Platform.OS === "android" && i < totalPages - 1) {
|
|
1020
|
+
await new Promise((r) => setTimeout(r, 10));
|
|
1021
|
+
}
|
|
1056
1022
|
}
|
|
1057
1023
|
}
|
|
1058
1024
|
async function writeAesKey(key) {
|
|
@@ -1061,7 +1027,10 @@ async function writeAesKey(key) {
|
|
|
1061
1027
|
const off = (3 - i) * 4;
|
|
1062
1028
|
const pageData = [key[off + 3], key[off + 2], key[off + 1], key[off + 0]];
|
|
1063
1029
|
await writePage(page, pageData);
|
|
1064
|
-
if (
|
|
1030
|
+
if (i < 3) {
|
|
1031
|
+
const delay = import_react_native3.Platform.OS === "ios" ? DELAY.IOS_KEY_WRITE : 10;
|
|
1032
|
+
await new Promise((r) => setTimeout(r, delay));
|
|
1033
|
+
}
|
|
1065
1034
|
}
|
|
1066
1035
|
}
|
|
1067
1036
|
async function writeNicknameToCard(nickname) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ukeyfe/react-native-nfc-litecard",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "NFC read/write for MIFARE Ultralight AES (LiteCard mnemonic storage)",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
"url": "git+https://github.com/bestyourwallet/react-native-nfc-litecard.git"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
+
"aes-js": "^3.1.2",
|
|
13
14
|
"bip39": "^3.1.0",
|
|
14
|
-
"
|
|
15
|
+
"js-sha256": "^0.11.1"
|
|
15
16
|
},
|
|
16
17
|
"devDependencies": {
|
|
17
|
-
"@types/crypto-js": "^4",
|
|
18
18
|
"tsup": "^8.5.1",
|
|
19
19
|
"typescript": "^5.0.0"
|
|
20
20
|
},
|