-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathNativeFRWBridge.ts
More file actions
243 lines (222 loc) · 8.58 KB
/
Copy pathNativeFRWBridge.ts
File metadata and controls
243 lines (222 loc) · 8.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
import type {
NewKeyInfo as SharedNewKeyInfo,
RecentContactsResponse,
AccountKeySignature as SharedAccountKeySignature,
Currency as SharedCurrency,
EnvironmentVariables as SharedEnvironmentVariables,
WalletAccount,
WalletAccountsResponse,
WalletProfilesResponse,
CreateAccountResponse as SharedCreateAccountResponse,
SeedPhraseGenerationResponse as SharedSeedPhraseGenerationResponse,
MigrationAssetsData as SharedMigrationAssetsData,
} from '@onflow/frw-types';
import { type NativeScreenName as SharedNativeScreenName } from '@onflow/frw-types';
import type { TurboModule } from 'react-native';
import { TurboModuleRegistry } from 'react-native';
/**
* Local interfaces for Codegen - must be defined in the same file
* @see {@link SharedEnvironmentVariables}, {@link SharedCurrency}, {@link SharedCreateAccountResponse}, {@link SharedSeedPhraseGenerationResponse}, and {@link SharedNativeScreenName} in @onflow/frw-types
*
* React Native Codegen limitation: Cannot resolve imported types.
* These must stay in sync with the source types manually.
*/
interface EnvironmentVariables {
NODE_API_URL: string;
GO_API_URL: string;
INSTABUG_TOKEN: string;
MIXPANEL_TOKEN?: string;
CADENCE_INBOX?: boolean;
}
interface Currency {
name: string;
symbol: string;
rate: string;
}
interface AccountKey {
publicKey: string;
signAlgo?: number;
hashAlgo?: number;
weight?: number;
}
interface AccountKeySignature {
public_key: string;
hash_algo: number;
sign_algo: number;
signature: string;
sign_message?: string;
weight?: number;
}
interface PendingRotationState {
address: string;
publicKey: string;
seedphrase: string;
timestamp: number;
txId?: string;
phase: 'pre-tx' | 'key-added' | 'key-verified' | 'api-registered' | 'tx-confirmed';
}
interface NewKeyInfo {
seedphrase: string;
flowKey: AccountKey;
}
/**
* Response from getV4RegistrationSignatures containing all signatures needed for v4 API
*/
interface V4RegistrationSignaturesResponse {
flowSignature: string;
evmSignature: string;
eoaAddress: string;
}
interface CreateAccountResponse {
success: boolean;
address: string | null;
username: string | null;
accountType: 'full' | 'hardware' | null; // full = mnemonic-based account, hardware = secure enclave
txId: string | null;
error: string | null;
}
interface SeedPhraseGenerationResponse {
mnemonic: string;
accountKey: AccountKey;
drivepath: string;
/** Pre-derived EVM/EOA address from BIP44 path m/44'/60'/0'/0/0 for faster display */
evmAddress?: string;
}
interface MigrationAssetsData {
erc20: Array<{ address: string; amount: string }>;
erc721: Array<{ address: string; id: string }>;
erc1155: Array<{ address: string; id: string; amount: string }>;
}
/**
* Local type for NativeScreenName - must match enum values from @onflow/frw-types
* @see {@link SharedNativeScreenName}
*/
type NativeScreenName =
| 'multiBackup'
| 'deviceBackup'
| 'seedPhraseBackup'
| 'backupOptions'
| 'walletRestore'
| 'recoveryPhraseRestore'
| 'keyStoreRestore'
| 'privateKeyRestore'
| 'googleDriveRestore'
| 'icloudRestore'
| 'multiRestore';
// Compile-time sync validation
const _syncCheck: EnvironmentVariables = {} as SharedEnvironmentVariables;
const _reverseSyncCheck: SharedEnvironmentVariables = {} as EnvironmentVariables;
const _currencySyncCheck: Currency = {} as SharedCurrency;
const _currencyReverseSyncCheck: SharedCurrency = {} as Currency;
const _newKeyInfoSyncCheck: NewKeyInfo = {} as SharedNewKeyInfo;
const _newKeyInfoReverseSyncCheck: SharedNewKeyInfo = {} as NewKeyInfo;
const _accountKeySignatureSyncCheck: AccountKeySignature = {} as SharedAccountKeySignature;
const _accountKeySignatureReverseSyncCheck: SharedAccountKeySignature = {} as AccountKeySignature;
const _createAccountSyncCheck: CreateAccountResponse = {} as SharedCreateAccountResponse;
const _createAccountReverseSyncCheck: SharedCreateAccountResponse = {} as CreateAccountResponse;
const _seedPhraseSyncCheck: SeedPhraseGenerationResponse = {} as SharedSeedPhraseGenerationResponse;
const _migrationAssetsSyncCheck: MigrationAssetsData = {} as SharedMigrationAssetsData;
const _migrationAssetsReverseSyncCheck: SharedMigrationAssetsData = {} as MigrationAssetsData;
// NativeScreenName validation - ensures local union matches SharedNativeScreenName enum values
type SharedNativeScreenNameValues = `${SharedNativeScreenName}`;
const _nativeScreenNameSyncCheck: NativeScreenName = {} as SharedNativeScreenNameValues;
const _nativeScreenNameReverseSyncCheck: SharedNativeScreenNameValues = {} as NativeScreenName;
export interface Spec extends TurboModule {
getSelectedAddress(): string | null;
getDebugAddress(): string | null;
getNetwork(): string;
getJWT(): Promise<string>;
getVersion(): string;
getBuildNumber(): string;
getLanguage(): string;
// Turbo Modules do not support Uint8Array or ArrayBuffer, so we need to convert to hex string instead
sign(hexData: string): Promise<string>;
ethSign(hexData: string, address: string | null): Promise<string>;
getRecentContacts(): Promise<RecentContactsResponse>;
// Wallet accounts method
getWalletAccounts(): Promise<WalletAccountsResponse>;
getSignKeyIndex(): number;
// QR code scanning method
scanQRCode(): Promise<string>;
// Close react native method
closeRN(id?: string | null): void;
// Update dialog action click callback
onUpdateDialogActionPress(
actionType: 'external' | 'internal' | 'deeplink',
actionUrl?: string | null,
actionText?: string | null
): void;
// Close react native and enable NFT collection storage
closeRNWithNFT(id?: string | null): void;
// Free gas settings method
isFreeGasEnabled(): Promise<boolean>;
// Listen to a transaction
listenTransaction(txid: string): void;
// Get environment variables
getEnv(): EnvironmentVariables;
// Get selected account
getSelectedAccount(): Promise<WalletAccount>;
getMigrationAssets(sourceAddress: string): Promise<MigrationAssetsData>;
refreshCoaAfterMigration(): Promise<void>;
getCurrency(): Currency;
getTokenRate(token: string): string;
getWalletProfiles(): Promise<WalletProfilesResponse>;
// Profile management - recovery flow
getRecoverableProfiles(): Promise<WalletProfilesResponse>;
switchToProfile(userId: string): Promise<void>;
// Device info method
getDeviceId(): string;
// Toast methods
showToast(
title: string,
message?: string | null,
type?: 'success' | 'error' | 'warning' | 'info',
duration?: number | null
): void;
hideToast(id: string): void;
clearAllToasts(): void;
// Native logging method for additional platform-specific logging
logToNative(
level: 'debug' | 'info' | 'warn' | 'error',
message: string,
args: ReadonlyArray<string>
): void;
// Key rotation methods
createSeedKey(strength: number): Promise<NewKeyInfo>;
saveNewKey(key: NewKeyInfo): Promise<void>;
removeOldKey(address: string, publicKey: string): Promise<void>;
savePendingRotation(state: PendingRotationState): Promise<void>;
getPendingRotation(address: string): Promise<PendingRotationState | null>;
clearPendingRotation(address: string): Promise<void>;
signRotationRequest(address: string, signatureData: string): Promise<AccountKeySignature>;
// Onboarding methods
registerSecureTypeAccount(username: string): Promise<CreateAccountResponse>;
initSecureEnclaveWallet(
txId: string
): Promise<{ success: boolean; address: string | null; error: string | null }>;
generateSeedPhrase(strength?: number | null): Promise<SeedPhraseGenerationResponse>;
/**
* Get all signatures needed for v4 API registration
* Signs in anonymously to Firebase, gets JWT, and signs it with both Flow and EVM keys derived from mnemonic
* @param mnemonic - The recovery phrase to derive signing keys from
* @returns Promise with flowSignature, evmSignature, and eoaAddress
*/
getV4RegistrationSignatures(mnemonic: string): Promise<V4RegistrationSignaturesResponse>;
signInWithCustomToken(customToken: string): Promise<void>;
saveMnemonic(
mnemonic: string,
customToken: string,
txId: string,
username: string,
evmAddress?: string | null
): Promise<void>;
requestNotificationPermission(): Promise<boolean>;
checkNotificationPermission(): Promise<boolean>;
// Keystore migration
keystoreMigration?(): Promise<void>;
// Screen security
setScreenSecurityLevel(level: 'normal' | 'secure'): void;
// Launch native screen method - uses local NativeScreenName type for Codegen compatibility
launchNativeScreen(screenName: NativeScreenName, params?: string | null): void;
}
export default TurboModuleRegistry.getEnforcing<Spec>('NativeFRWBridge');