@onetokenfe/react-native-nfc-wallet-sdk 0.1.0

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.
Files changed (50) hide show
  1. package/NfcWalletSdk.podspec +22 -0
  2. package/README.md +81 -0
  3. package/android/build.gradle +59 -0
  4. package/android/src/main/AndroidManifest.xml +4 -0
  5. package/android/src/main/java/com/ziancube/reactnativenfcwalletsdk/NfcWalletEngine.kt +486 -0
  6. package/android/src/main/java/com/ziancube/reactnativenfcwalletsdk/NfcWalletSdkModule.kt +268 -0
  7. package/android/src/main/java/com/ziancube/reactnativenfcwalletsdk/NfcWalletSdkPackage.kt +14 -0
  8. package/android/src/main/java/com/ziancube/reactnativenfcwalletsdk/nfc/NfcUtils.kt +24 -0
  9. package/android/src/main/java/com/ziancube/reactnativenfcwalletsdk/utils/HexUtils.kt +24 -0
  10. package/android/src/main/java/com/ziancube/reactnativenfcwalletsdk/wallet/WalletApduClient.kt +495 -0
  11. package/android/src/main/java/com/ziancube/reactnativenfcwalletsdk/wallet/WalletConstants.kt +105 -0
  12. package/android/src/main/java/com/ziancube/reactnativenfcwalletsdk/wallet/WalletNfcController.kt +262 -0
  13. package/android/src/main/java/com/ziancube/reactnativenfcwalletsdk/wallet/WalletNfcTagHolder.kt +74 -0
  14. package/ios/Classes/NfcWalletHexUtils.h +8 -0
  15. package/ios/Classes/NfcWalletHexUtils.m +31 -0
  16. package/ios/Classes/NfcWalletNFCManager.h +58 -0
  17. package/ios/Classes/NfcWalletNFCManager.m +244 -0
  18. package/ios/Classes/NfcWalletSession.h +52 -0
  19. package/ios/Classes/NfcWalletSession.m +1109 -0
  20. package/ios/NfcWalletSdk.h +5 -0
  21. package/ios/NfcWalletSdk.mm +369 -0
  22. package/lib/module/NativeNfcWalletSdk.js +8 -0
  23. package/lib/module/NativeNfcWalletSdk.js.map +1 -0
  24. package/lib/module/constants.js +5 -0
  25. package/lib/module/constants.js.map +1 -0
  26. package/lib/module/index.js +8 -0
  27. package/lib/module/index.js.map +1 -0
  28. package/lib/module/nfc.js +81 -0
  29. package/lib/module/nfc.js.map +1 -0
  30. package/lib/module/package.json +1 -0
  31. package/lib/module/walletOperations.js +68 -0
  32. package/lib/module/walletOperations.js.map +1 -0
  33. package/lib/typescript/package.json +1 -0
  34. package/lib/typescript/src/NativeNfcWalletSdk.d.ts +166 -0
  35. package/lib/typescript/src/NativeNfcWalletSdk.d.ts.map +1 -0
  36. package/lib/typescript/src/constants.d.ts +3 -0
  37. package/lib/typescript/src/constants.d.ts.map +1 -0
  38. package/lib/typescript/src/index.d.ts +7 -0
  39. package/lib/typescript/src/index.d.ts.map +1 -0
  40. package/lib/typescript/src/nfc.d.ts +43 -0
  41. package/lib/typescript/src/nfc.d.ts.map +1 -0
  42. package/lib/typescript/src/walletOperations.d.ts +22 -0
  43. package/lib/typescript/src/walletOperations.d.ts.map +1 -0
  44. package/package.json +90 -0
  45. package/react-native.config.js +10 -0
  46. package/src/NativeNfcWalletSdk.ts +205 -0
  47. package/src/constants.ts +2 -0
  48. package/src/index.tsx +33 -0
  49. package/src/nfc.ts +80 -0
  50. package/src/walletOperations.ts +152 -0
package/src/nfc.ts ADDED
@@ -0,0 +1,80 @@
1
+ import { Platform } from 'react-native';
2
+
3
+ import NfcWalletSdk from './NativeNfcWalletSdk';
4
+ import type { PromiseResult } from './NativeNfcWalletSdk';
5
+
6
+ export type CallbackError = { code: number; message: string | null };
7
+
8
+ export enum WalletErrors {
9
+ InitChannel = 1000,
10
+ NotExistsNFC = 1001,
11
+ NotEnableNFC = 1002,
12
+ NotNFCPermission = 1003,
13
+ ConnectionFail = 2001,
14
+ /** Expected card serial mismatch (VERIFY P2 serial). Same code as Lite CardErrors. */
15
+ NotSameNFCLite = 2002,
16
+ NotSupportedCard = 2004,
17
+ PasswordWrong = 2005,
18
+ NotSetPassword = 2006,
19
+ CardLock = 2007,
20
+ /** User dismissed NFC search dialog / cancelled wait. */
21
+ UserCancel = 2008,
22
+ NoKey = 2010,
23
+ KeyExists = 2011,
24
+ /** Primary/backup already latched backupDone (SW=6A1D). */
25
+ BackupDone = 2012,
26
+ /** Backup flow state mismatch (e.g. re-enroll before applet 1.0.19). */
27
+ BackupState = 2013,
28
+ /**
29
+ * Complete Backup / step card mismatch (not the primary or backup shown on screen).
30
+ * Distinct from NotSameNFCLite — different user copy.
31
+ */
32
+ WrongCard = 2015,
33
+ /** Attestation not personalized (SW=6A21). */
34
+ AttestNotReady = 2016,
35
+ /** Factory attestation locked (SW=6A22). */
36
+ AttestLocked = 2017,
37
+ /** Invalid OTAC cert or challenge (SW=6A23). */
38
+ AttestInvalid = 2018,
39
+ /** Server / local authenticity check failed. */
40
+ AttestVerifyFailed = 2019,
41
+ }
42
+
43
+ function parseTurboModuleError(error: unknown): CallbackError {
44
+ const err = error as {
45
+ message?: string;
46
+ userInfo?: { code?: number; message?: string };
47
+ };
48
+ const code = err?.userInfo?.code;
49
+ if (typeof code === 'number') {
50
+ return { code, message: err.userInfo?.message ?? err.message ?? null };
51
+ }
52
+ return { code: WalletErrors.InitChannel, message: err?.message ?? null };
53
+ }
54
+
55
+ export function checkNFCPermission(): Promise<PromiseResult<boolean>> {
56
+ if (Platform.OS === 'ios') {
57
+ return Promise.resolve({
58
+ error: null,
59
+ data: true,
60
+ walletInfo: null,
61
+ resultCode: 0,
62
+ });
63
+ }
64
+ return NfcWalletSdk.checkNFCPermission()
65
+ .then(() => ({ error: null, data: true, walletInfo: null, resultCode: 0 }))
66
+ .catch((error: unknown) => ({
67
+ error: parseTurboModuleError(error),
68
+ data: null,
69
+ walletInfo: null,
70
+ resultCode: -1,
71
+ }));
72
+ }
73
+
74
+ export function intoSetting(): void {
75
+ NfcWalletSdk.intoSetting();
76
+ }
77
+
78
+ export function cancelNfcWait(): void {
79
+ NfcWalletSdk.cancelNfcWait();
80
+ }
@@ -0,0 +1,152 @@
1
+ import NfcWalletSdk from './NativeNfcWalletSdk';
2
+ import type { WalletOperationResult, CallbackError, WalletInfo } from './NativeNfcWalletSdk';
3
+
4
+ type RawWalletResult = {
5
+ error: CallbackError | null;
6
+ walletInfo: WalletInfo | null;
7
+ resultCode: number;
8
+ data: string | null;
9
+ };
10
+
11
+ function normalize<T>(raw: RawWalletResult): WalletOperationResult<T> {
12
+ return {
13
+ error: raw.error ?? null,
14
+ data: (raw.data ?? null) as T | null,
15
+ walletInfo: raw.walletInfo ?? null,
16
+ resultCode: raw.resultCode ?? 0,
17
+ };
18
+ }
19
+
20
+ export function getWalletInfo(): Promise<WalletOperationResult<string>> {
21
+ return NfcWalletSdk.getWalletInfo().then((raw) => normalize<string>(raw));
22
+ }
23
+
24
+ export function setPin(pin: string): Promise<WalletOperationResult<null>> {
25
+ return NfcWalletSdk.setPin(pin).then((raw) => normalize<null>(raw));
26
+ }
27
+
28
+ /** Change access code on one card (applet >= 1.0.25). Does not sync to backups. */
29
+ export function changePin(
30
+ oldPin: string,
31
+ newPin: string,
32
+ expectedSerial?: string | null,
33
+ ): Promise<WalletOperationResult<null>> {
34
+ return NfcWalletSdk.changePin(oldPin, newPin, expectedSerial ?? null).then(
35
+ (raw) => normalize<null>(raw),
36
+ );
37
+ }
38
+
39
+ export function verifyPin(
40
+ pin: string,
41
+ expectedSerial?: string | null,
42
+ ): Promise<WalletOperationResult<null>> {
43
+ return NfcWalletSdk.verifyPin(pin, expectedSerial ?? null).then((raw) =>
44
+ normalize<null>(raw),
45
+ );
46
+ }
47
+
48
+ export function logout(): Promise<WalletOperationResult<null>> {
49
+ return NfcWalletSdk.logout().then((raw) => normalize<null>(raw));
50
+ }
51
+
52
+ export function createWallet(
53
+ expectedSerial?: string | null,
54
+ ): Promise<WalletOperationResult<null>> {
55
+ return NfcWalletSdk.createWallet(expectedSerial ?? null).then((raw) =>
56
+ normalize<null>(raw),
57
+ );
58
+ }
59
+
60
+ export function createWalletWithSeed(
61
+ seedHex: string,
62
+ expectedSerial?: string | null,
63
+ ): Promise<WalletOperationResult<null>> {
64
+ return NfcWalletSdk.createWalletWithSeed(
65
+ seedHex,
66
+ expectedSerial ?? null,
67
+ ).then((raw) => normalize<null>(raw));
68
+ }
69
+
70
+ export function getPublicKey(
71
+ path?: string | null,
72
+ ): Promise<WalletOperationResult<string>> {
73
+ return NfcWalletSdk.getPublicKey(path ?? null).then((raw) => normalize<string>(raw));
74
+ }
75
+
76
+ export function signHash(
77
+ hashHex: string,
78
+ path?: string | null,
79
+ ): Promise<WalletOperationResult<string>> {
80
+ return NfcWalletSdk.signHash(hashHex, path ?? null).then((raw) => normalize<string>(raw));
81
+ }
82
+
83
+ export function wipeWallet(): Promise<WalletOperationResult<null>> {
84
+ return NfcWalletSdk.wipeWallet().then((raw) => normalize<null>(raw));
85
+ }
86
+
87
+ /** VERIFY_PIN + WIPE in one session; binds expectedSerial. */
88
+ export function wipeWalletWithPin(
89
+ pin: string,
90
+ expectedSerial: string,
91
+ ): Promise<WalletOperationResult<null>> {
92
+ return NfcWalletSdk.wipeWalletWithPin(pin, expectedSerial).then((raw) =>
93
+ normalize<null>(raw),
94
+ );
95
+ }
96
+
97
+ export function initializeWallet(
98
+ pin: string,
99
+ seedHex?: string | null,
100
+ ): Promise<WalletOperationResult<string>> {
101
+ return NfcWalletSdk.initializeWallet(pin, seedHex ?? null).then((raw) =>
102
+ normalize<string>(raw),
103
+ );
104
+ }
105
+
106
+ export function initializeWalletWithPubkeys(
107
+ pin: string,
108
+ pathsJson: string,
109
+ seedHex?: string | null,
110
+ expectedSerial?: string | null,
111
+ ): Promise<WalletOperationResult<string>> {
112
+ return NfcWalletSdk.initializeWalletWithPubkeys(
113
+ pin,
114
+ pathsJson,
115
+ seedHex ?? null,
116
+ expectedSerial ?? null,
117
+ ).then((raw) => normalize<string>(raw));
118
+ }
119
+
120
+ export function unlockAndSign(
121
+ pin: string,
122
+ hashHex: string,
123
+ path?: string | null,
124
+ ): Promise<WalletOperationResult<string>> {
125
+ return NfcWalletSdk.unlockAndSign(pin, hashHex, path ?? null).then((raw) =>
126
+ normalize<string>(raw),
127
+ );
128
+ }
129
+
130
+ /** Tangem-style backup step: begin | accept | export | import | confirm | enroll | exportPeer | completePrimary */
131
+ export function runBackupStep(
132
+ step: string,
133
+ pin?: string | null,
134
+ payloadHex?: string | null,
135
+ backupCount = 2,
136
+ ): Promise<WalletOperationResult<string>> {
137
+ return NfcWalletSdk.runBackupStep(
138
+ step,
139
+ pin ?? null,
140
+ payloadHex ?? null,
141
+ backupCount,
142
+ ).then((raw) => normalize<string>(raw));
143
+ }
144
+
145
+ /** One NFC session: GET_CERT + ATTEST_SIGN. data = JSON { serialNumber, certHex, signatureHex } */
146
+ export function attestCard(
147
+ challengeHex: string,
148
+ ): Promise<WalletOperationResult<string>> {
149
+ return NfcWalletSdk.attestCard(challengeHex).then((raw) =>
150
+ normalize<string>(raw),
151
+ );
152
+ }