Skip to content

feat(rtn-passkeys): scaffold native package - 1 #14390

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: feat/rtn-passkeys/main
Choose a base branch
from
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
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ xcuserdata/
!*.xcworkspace/contents.xcworkspacedata
/*.gcno
**/xcshareddata/WorkspaceSettings.xcsettings
**/.xcode.env.local
*.xcode.env.local

### Coverage ###
coverage/
Expand All @@ -65,7 +65,12 @@ coverage-ts/
**/example/ios/Podfile.lock
**/example/.bundle
**/example/yarn.lock
**/example/amplify_outputs.json

# rollup
**/.rollup.cache
**/buildMeta

# ruby
vendor/
Gemfile.lock
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ export default [
'**/__tests__/**',
'**/packages/adapter-nextjs/**',
'**/packages/react-native/example/**',
'**/packages/rtn-passkeys/example/**',
],
rules: {
'import/no-extraneous-dependencies': 'error',
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
"packages/rtn-web-browser",
"packages/react-native",
"packages/react-native/example",
"packages/rtn-passkeys",
"packages/rtn-passkeys/example",
"scripts/tsc-compliance-test"
],
"nohoist": [
Expand Down
30 changes: 30 additions & 0 deletions packages/rtn-passkeys/AmplifyRtnPasskeys.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

require "json"

package = JSON.parse(File.read(File.join(__dir__, "package.json")))
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'

Pod::Spec.new do |s|
s.name = "AmplifyRtnPasskeys"
s.version = package["version"]
s.summary = package["description"]
s.homepage = package["homepage"]
s.license = package["license"]
s.authors = package["author"]

s.platforms = { :ios => '15.1' }
s.source = { :git => "https://github.com/aws-amplify/amplify-js.git", :tag => "#{s.version}" }

s.source_files = "ios/**/*.{h,m,mm,cpp,swift}"
s.exclude_files = [ 'ios/tests' ]
s.private_header_files = "ios/generated/**/*.h"

install_modules_dependencies(s)

s.test_spec 'tests' do |test_spec|
test_spec.source_files = 'ios/tests/*.swift'
test_spec.frameworks ='XCTest'
end
end
92 changes: 92 additions & 0 deletions packages/rtn-passkeys/android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
buildscript {
ext.getExtOrDefault = { name ->
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['AmplifyRtnPasskeys_' + name]
}

repositories {
google()
mavenCentral()
}

dependencies {
classpath "com.android.tools.build:gradle:8.7.3"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe minor but the gradle version seems to be newer than other RTN packages in the repo, which is "8.0.2"

// noinspection DifferentKotlinGradleVersion
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
}
}


apply plugin: "com.android.library"
apply plugin: "kotlin-android"
apply plugin: "com.facebook.react"

def getExtOrIntegerDefault(name) {
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["AmplifyRtnPasskeys_" + name]).toInteger()
}


android {
namespace "com.amazonaws.amplify.rtnpasskeys"

compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")

defaultConfig {
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
}

buildFeatures {
buildConfig true
}

buildTypes {
release {
minifyEnabled false
}
}

lintOptions {
disable "GradleCompatible"
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

sourceSets {
main {
java.srcDirs += [
"generated/java",
"generated/jni"
]
}
}
}

repositories {
mavenCentral()
google()
}

def kotlin_version = getExtOrDefault("kotlinVersion")

dependencies {
implementation "com.facebook.react:react-android"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

implementation "androidx.credentials:credentials:1.5.0"
implementation "androidx.credentials:credentials-play-services-auth:1.5.0"

testImplementation "junit:junit:4.13.2"
testImplementation "org.robolectric:robolectric:4.14.1"
testImplementation "io.mockk:mockk:1.14.2"
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2"
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.10.2"
Comment on lines +78 to +85
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are manual changes required to support webauthn and enable unit testing.

}

react {
jsRootDir = file("../src/")
libraryName = "AmplifyRtnPasskeys"
codegenJavaPackageName = "com.amazonaws.amplify.rtnpasskeys"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

/**
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* Do not edit this file as changes may cause incorrect behavior and will be lost
* once the code is regenerated.
*
* @generated by codegen project: GenerateModuleJavaSpec.js
*
* @nolint
*/

package com.facebook.fbreact.specs;

import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
import javax.annotation.Nonnull;

public abstract class NativeAmplifyRtnPasskeysSpec extends ReactContextBaseJavaModule implements TurboModule {
public static final String NAME = "AmplifyRtnPasskeys";

public NativeAmplifyRtnPasskeysSpec(ReactApplicationContext reactContext) {
super(reactContext);
}

@Override
public @Nonnull String getName() {
return NAME;
}

@ReactMethod(isBlockingSynchronousMethod = true)
@DoNotStrip
public abstract boolean getIsPasskeySupported();

@ReactMethod
@DoNotStrip
public abstract void createPasskey(ReadableMap input, Promise promise);

@ReactMethod
@DoNotStrip
public abstract void getPasskey(ReadableMap input, Promise promise);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

/**
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* Do not edit this file as changes may cause incorrect behavior and will be lost
* once the code is regenerated.
*
* @generated by codegen project: GenerateModuleJniCpp.js
*/

#include "AmplifyRtnPasskeysSpec.h"

namespace facebook::react {

static facebook::jsi::Value __hostFunction_NativeAmplifyRtnPasskeysSpecJSI_getIsPasskeySupported(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
static jmethodID cachedMethodId = nullptr;
return static_cast<JavaTurboModule &>(turboModule).invokeJavaMethod(rt, BooleanKind, "getIsPasskeySupported", "()Z", args, count, cachedMethodId);
}

static facebook::jsi::Value __hostFunction_NativeAmplifyRtnPasskeysSpecJSI_createPasskey(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
static jmethodID cachedMethodId = nullptr;
return static_cast<JavaTurboModule &>(turboModule).invokeJavaMethod(rt, PromiseKind, "createPasskey", "(Lcom/facebook/react/bridge/ReadableMap;Lcom/facebook/react/bridge/Promise;)V", args, count, cachedMethodId);
}

static facebook::jsi::Value __hostFunction_NativeAmplifyRtnPasskeysSpecJSI_getPasskey(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
static jmethodID cachedMethodId = nullptr;
return static_cast<JavaTurboModule &>(turboModule).invokeJavaMethod(rt, PromiseKind, "getPasskey", "(Lcom/facebook/react/bridge/ReadableMap;Lcom/facebook/react/bridge/Promise;)V", args, count, cachedMethodId);
}

NativeAmplifyRtnPasskeysSpecJSI::NativeAmplifyRtnPasskeysSpecJSI(const JavaTurboModule::InitParams &params)
: JavaTurboModule(params) {
methodMap_["getIsPasskeySupported"] = MethodMetadata {0, __hostFunction_NativeAmplifyRtnPasskeysSpecJSI_getIsPasskeySupported};
methodMap_["createPasskey"] = MethodMetadata {1, __hostFunction_NativeAmplifyRtnPasskeysSpecJSI_createPasskey};
methodMap_["getPasskey"] = MethodMetadata {1, __hostFunction_NativeAmplifyRtnPasskeysSpecJSI_getPasskey};
}

std::shared_ptr<TurboModule> AmplifyRtnPasskeysSpec_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams &params) {
if (moduleName == "AmplifyRtnPasskeys") {
return std::make_shared<NativeAmplifyRtnPasskeysSpecJSI>(params);
}
return nullptr;
}

} // namespace facebook::react
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

/**
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* Do not edit this file as changes may cause incorrect behavior and will be lost
* once the code is regenerated.
*
* @generated by codegen project: GenerateModuleJniH.js
*/

#pragma once

#include <ReactCommon/JavaTurboModule.h>
#include <ReactCommon/TurboModule.h>
#include <jsi/jsi.h>

namespace facebook::react {

/**
* JNI C++ class for module 'NativeAmplifyRtnPasskeys'
*/
class JSI_EXPORT NativeAmplifyRtnPasskeysSpecJSI : public JavaTurboModule {
public:
NativeAmplifyRtnPasskeysSpecJSI(const JavaTurboModule::InitParams &params);
};


JSI_EXPORT
std::shared_ptr<TurboModule> AmplifyRtnPasskeysSpec_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams &params);

} // namespace facebook::react
36 changes: 36 additions & 0 deletions packages/rtn-passkeys/android/generated/jni/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

cmake_minimum_required(VERSION 3.13)
set(CMAKE_VERBOSE_MAKEFILE on)

file(GLOB react_codegen_SRCS CONFIGURE_DEPENDS *.cpp react/renderer/components/AmplifyRtnPasskeysSpec/*.cpp)

add_library(
react_codegen_AmplifyRtnPasskeysSpec
OBJECT
${react_codegen_SRCS}
)

target_include_directories(react_codegen_AmplifyRtnPasskeysSpec PUBLIC . react/renderer/components/AmplifyRtnPasskeysSpec)

target_link_libraries(
react_codegen_AmplifyRtnPasskeysSpec
fbjni
jsi
# We need to link different libraries based on whether we are building rncore or not, that's necessary
# because we want to break a circular dependency between react_codegen_rncore and reactnative
reactnative
)

target_compile_options(
react_codegen_AmplifyRtnPasskeysSpec
PRIVATE
-DLOG_TAG=\"ReactNative\"
-fexceptions
-frtti
-std=c++20
-Wall
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* Do not edit this file as changes may cause incorrect behavior and will be lost
* once the code is regenerated.
*
* @generated by codegen project: GenerateModuleCpp.js
*/

#include "AmplifyRtnPasskeysSpecJSI.h"

namespace facebook::react {

static jsi::Value __hostFunction_NativeAmplifyRtnPasskeysCxxSpecJSI_getIsPasskeySupported(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
return static_cast<NativeAmplifyRtnPasskeysCxxSpecJSI *>(&turboModule)->getIsPasskeySupported(
rt
);
}
static jsi::Value __hostFunction_NativeAmplifyRtnPasskeysCxxSpecJSI_createPasskey(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
return static_cast<NativeAmplifyRtnPasskeysCxxSpecJSI *>(&turboModule)->createPasskey(
rt,
count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asObject(rt)
);
}
static jsi::Value __hostFunction_NativeAmplifyRtnPasskeysCxxSpecJSI_getPasskey(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
return static_cast<NativeAmplifyRtnPasskeysCxxSpecJSI *>(&turboModule)->getPasskey(
rt,
count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asObject(rt)
);
}

NativeAmplifyRtnPasskeysCxxSpecJSI::NativeAmplifyRtnPasskeysCxxSpecJSI(std::shared_ptr<CallInvoker> jsInvoker)
: TurboModule("AmplifyRtnPasskeys", jsInvoker) {
methodMap_["getIsPasskeySupported"] = MethodMetadata {0, __hostFunction_NativeAmplifyRtnPasskeysCxxSpecJSI_getIsPasskeySupported};
methodMap_["createPasskey"] = MethodMetadata {1, __hostFunction_NativeAmplifyRtnPasskeysCxxSpecJSI_createPasskey};
methodMap_["getPasskey"] = MethodMetadata {1, __hostFunction_NativeAmplifyRtnPasskeysCxxSpecJSI_getPasskey};
}


} // namespace facebook::react
Loading
Loading