Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions KeychainExample/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,17 @@ GEM
escape (0.0.4)
ethon (0.16.0)
ffi (>= 1.15.0)
ffi (1.17.0)
ffi (1.17.0-aarch64-linux-gnu)
ffi (1.17.0-aarch64-linux-musl)
ffi (1.17.0-arm-linux-gnu)
ffi (1.17.0-arm-linux-musl)
ffi (1.17.0-arm64-darwin)
ffi (1.17.0-x86-linux-gnu)
ffi (1.17.0-x86-linux-musl)
ffi (1.17.0-x86_64-darwin)
ffi (1.17.0-x86_64-linux-gnu)
ffi (1.17.0-x86_64-linux-musl)
ffi (1.17.2)
ffi (1.17.2-aarch64-linux-gnu)
ffi (1.17.2-aarch64-linux-musl)
ffi (1.17.2-arm-linux-gnu)
ffi (1.17.2-arm-linux-musl)
ffi (1.17.2-arm64-darwin)
ffi (1.17.2-x86-linux-gnu)
ffi (1.17.2-x86-linux-musl)
ffi (1.17.2-x86_64-darwin)
ffi (1.17.2-x86_64-linux-gnu)
ffi (1.17.2-x86_64-linux-musl)
fourflusher (2.3.1)
fuzzy_match (2.0.4)
gh_inspector (1.1.3)
Expand Down
3 changes: 2 additions & 1 deletion KeychainExample/ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ENV['RCT_NEW_ARCH_ENABLED'] = '1'
ws_dir = Pathname.new(__dir__)
ws_dir = ws_dir.parent until
File.exist?("#{ws_dir}/node_modules/react-native-test-app/test_app.rb") ||
Expand All @@ -6,4 +7,4 @@ require "#{ws_dir}/node_modules/react-native-test-app/test_app.rb"

workspace 'KeychainExample.xcworkspace'

use_test_app!
use_test_app! :fabric_enabled => true, :bridgeless_enabled => true
16 changes: 9 additions & 7 deletions KeychainExample/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1467,6 +1467,7 @@ PODS:
- React-ImageManager
- React-jsi
- React-NativeModulesApple
- React-RCTAppDelegate
- React-RCTFabric
- React-rendererdebug
- React-utils
Expand All @@ -1478,7 +1479,7 @@ PODS:
- React-Core
- React-jsi
- ReactTestApp-Resources (1.0.0-dev)
- RNKeychain (9.2.3):
- RNKeychain (10.0.0):
- DoubleConversion
- glog
- RCT-Folly (= 2024.11.18.00)
Expand Down Expand Up @@ -1532,6 +1533,7 @@ DEPENDENCIES:
- React-idlecallbacksnativemodule (from `../node_modules/react-native/ReactCommon/react/nativemodule/idlecallbacks`)
- React-ImageManager (from `../node_modules/react-native/ReactCommon/react/renderer/imagemanager/platform/ios`)
- React-jsc (from `../node_modules/react-native/ReactCommon/jsc`)
- React-jsc/Fabric (from `../node_modules/react-native/ReactCommon/jsc`)
- React-jserrorhandler (from `../node_modules/react-native/ReactCommon/jserrorhandler`)
- React-jsi (from `../node_modules/react-native/ReactCommon/jsi`)
- React-jsiexecutor (from `../node_modules/react-native/ReactCommon/jsiexecutor`)
Expand Down Expand Up @@ -1758,10 +1760,10 @@ SPEC CHECKSUMS:
React-performancetimeline: 3ef4a640b56f9c7ec5f52bd93217b9b607c37cf4
React-RCTActionSheet: 0fdf55fb8724856d63ca8c63cdb4e2325e15e8ec
React-RCTAnimation: b93f5a1675cc2599e96851fec13c909fdfb1d6bb
React-RCTAppDelegate: 2dd0a42a5f6a47501a3661713c823e0bfdbc6637
React-RCTAppDelegate: e3127aff7db7100ee0000e3f67956e9c6cbaa13f
React-RCTBlob: 53dc2afa8ccdc1b6d6885d81f6862fcb918a1875
React-RCTFabric: eb45f7d8e2c6645fe043d6d6dcef5da35b9b41b4
React-RCTFBReactNativeSpec: cc43d8898158818752ee6e1986083d79803318f1
React-RCTFabric: 0a4c2a18d0ef3368f900dc08ea15ab532dd3dcf3
React-RCTFBReactNativeSpec: ec50e74af2993fb51c1f9991cc7226fea21aaa26
React-RCTImage: 028171a4d7017ea96a2e605c817cd76f01ed3836
React-RCTLinking: e3f5431ab5f8f56b82387d41a2c484a278a8e645
React-RCTNetwork: 6de20da228ffe8bd9c9e3bafe3f7d1dfe1d7bd55
Expand All @@ -1780,13 +1782,13 @@ SPEC CHECKSUMS:
ReactAppDependencyProvider: e7e92253013754a8c35ebdbf8ad700f4e8956f62
ReactCodegen: 6efd314e2f59c2eae0898c6d1e0d933876a1666c
ReactCommon: cec0154a884747940be235f16acbd4fc9c959f89
ReactNativeHost: d683c981f1c99f15ace8fc185c62b7af5197e079
ReactNativeHost: ed1bfdec90022adfb476124fbc5df536bf4a1880
ReactTestApp-DevSupport: 0580b002f78d63804f1609dce622c4f54820f3c6
ReactTestApp-Resources: 1bd9ff10e4c24f2ad87101a32023721ae923bccf
RNKeychain: 115b0ad98801a5d006cf0faf5770d39b9c25d528
RNKeychain: 321983bd3b70a343dcbc9bda36c4423791d50b2d
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
Yoga: 1fd059161b449018342943b095a6d4e69bcaa719

PODFILE CHECKSUM: 8daf094af2120901c020904ed4ae6b82bfbd5642
PODFILE CHECKSUM: 1c897424f85ad1d61479dd5c3cd2cf10505acd55

COCOAPODS: 1.15.2
2 changes: 1 addition & 1 deletion KeychainExample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"build:android": "npm run mkdist && react-native bundle --entry-file index.js --platform android --dev false --bundle-output dist/main.android.jsbundle --assets-dest dist/res",
"build:ios": "npm run mkdist && react-native bundle --entry-file index.js --platform ios --dev false --bundle-output dist/main.ios.jsbundle --assets-dest dist/assets",
"mkdist": "node -e \"require('node:fs').mkdirSync('dist', { recursive: true, mode: 0o755 })\"",
"start": "react-native start",
"start": "react-native start --reset-cache",
"test:android": "yarn test:android:build && yarn test:android:run",
"test:android:build": "detox build --configuration android.emu.release",
"test:android:run": "detox test --configuration android.emu.release",
Expand Down
2 changes: 1 addition & 1 deletion RNKeychain.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
s.osx.deployment_target = '10.13'
s.visionos.deployment_target = '1.0' if s.respond_to?(:visionos)
s.source = { :git => "https://github.com/oblador/react-native-keychain.git", :tag => "v#{s.version}" }
s.source_files = 'ios/RNKeychainManager/**/*.{h,m}'
s.source_files = 'ios/RNKeychainManager/**/*.{h,m,mm,cpp}'
s.preserve_paths = "**/*.js"

if respond_to?(:install_modules_dependencies, true)
Expand Down
11 changes: 9 additions & 2 deletions ios/RNKeychainManager/RNKeychainManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@
// Copyright (c) 2015 Joel Arvidsson. All rights reserved.
//

#import <React/RCTBridgeModule.h>
#import <React/RCTLog.h>

#ifdef RCT_NEW_ARCH_ENABLED
#import "RNKeychainSpec.h"

@interface RNKeychainManager : NSObject <NativeKeychainManagerSpec>
#else
#import <React/RCTBridgeModule.h>

@interface RNKeychainManager : NSObject <RCTBridgeModule>
#endif

@end
@end
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
#import "RNKeychainManager.h"
#import <React/RCTConvert.h>
#import <React/RCTBridge.h>

#if __has_include("RCTUtils.h")
#import "RCTUtils.h"
#else
#import <React/RCTUtils.h>
#endif

#if TARGET_OS_IOS || TARGET_OS_VISION
#import <LocalAuthentication/LAContext.h>
Expand Down Expand Up @@ -651,7 +656,7 @@ - (OSStatus)deleteCredentialsForServer:(NSString *)server withOptions:(NSDiction
}

if (CFArrayGetCount(credentials) > 0) {
CFDictionaryRef credentialDict = CFArrayGetValueAtIndex(credentials, 0);
CFDictionaryRef credentialDict = static_cast<CFDictionaryRef>(CFArrayGetValueAtIndex(credentials, 0));
NSString *server = (__bridge NSString *)CFDictionaryGetValue(credentialDict, kSecAttrServer);
NSString *username = (__bridge NSString *)CFDictionaryGetValue(credentialDict, kSecAttrAccount);
NSString *password = (__bridge NSString *)CFDictionaryGetValue(credentialDict, kSecSharedPassword);
Expand Down Expand Up @@ -706,4 +711,10 @@ - (OSStatus)deleteCredentialsForServer:(NSString *)server withOptions:(NSDiction
}
}

#ifdef RCT_NEW_ARCH_ENABLED
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const facebook::react::ObjCTurboModule::InitParams &)params {
return std::make_shared<facebook::react::NativeKeychainManagerSpecJSI>(params);
}
#endif

@end
49 changes: 49 additions & 0 deletions src/NativeKeychainManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* eslint-disable @typescript-eslint/ban-types */
// RNKeychainManager.ts
import type { TurboModule } from 'react-native';
import { TurboModuleRegistry } from 'react-native';

import type { Result, UserCredentials, SharedWebCredentials } from './types';
import type { BIOMETRY_TYPE, SECURITY_LEVEL } from './enums';

export interface Spec extends TurboModule {
setGenericPasswordForOptions(
options: Object | null | undefined,
username: string,
password: string
): Promise<false | Result>;
getGenericPasswordForOptions(
options?: Object | null
): Promise<false | UserCredentials>;
hasGenericPasswordForOptions(options?: Object | null): Promise<boolean>;
resetGenericPasswordForOptions(options?: Object | null): Promise<boolean>;
getAllGenericPasswordServices(options?: Object | null): Promise<string[]>;
hasInternetCredentialsForOptions(options: string | Object): Promise<boolean>;
setInternetCredentialsForServer(
server: string,
username: string,
password: string,
options?: Object | null
): Promise<false | Result>;
getInternetCredentialsForServer(
server: string,
options?: Object | null
): Promise<false | UserCredentials>;
resetInternetCredentialsForOptions(options: Object): Promise<void>;
getSupportedBiometryType?(): Promise<null | BIOMETRY_TYPE>;
canCheckAuthentication?(options?: Object | null): Promise<boolean>;
getSecurityLevel?(options?: Object | null): Promise<null | SECURITY_LEVEL>;
isPasscodeAuthAvailable?(): Promise<boolean>;
requestSharedWebCredentials?(): Promise<false | SharedWebCredentials>;
setSharedWebCredentialsForServer?(
server: string,
username: string,
password?: string
): Promise<void>;
addListener?(eventName: string): void;
removeListeners?(count: number): void;
}

export default TurboModuleRegistry.getEnforcing<Spec>(
'RNKeychainManager'
) as Spec;
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ import type {
} from './types';
import { normalizeAuthPrompt } from './normalizeOptions';

const { RNKeychainManager } = NativeModules;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
const RNKeychainManager = global.__turboModuleProxy
? require('./NativeKeychainManager').default
: NativeModules.RNKeychainManager;

/**
* Saves the `username` and `password` combination for the given service.
Expand Down