Skip to content
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

Seed Vault React Native Lib #140

Merged
merged 6 commits into from
Feb 27, 2024
Merged
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
2 changes: 2 additions & 0 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ name: Android CI
on:
push:
branches: [ main ]
paths: [ '.github/**', 'android/**' ]
pull_request:
branches: [ main ]
paths: [ '.github/**', 'android/**' ]
release:
types: [ published ]

Expand Down
22 changes: 22 additions & 0 deletions js/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint",
"react-hooks",
"require-extensions",
"simple-import-sort"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react-hooks/recommended",
"plugin:require-extensions/recommended"
],
"rules": {
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
"simple-import-sort/imports": "error",
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn"
}
}
1 change: 1 addition & 0 deletions js/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
6 changes: 6 additions & 0 deletions js/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"printWidth": 120,
"singleQuote": true,
"tabWidth": 4,
"trailingComma": "all"
}
8 changes: 8 additions & 0 deletions js/lerna.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"npmClient": "yarn",
"packages": [
"packages/*"
],
"useWorkspaces": true,
"version": "0.1.0"
}
33 changes: 33 additions & 0 deletions js/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "root",
"private": true,
"scripts": {
"install": "lerna bootstrap",
"build": "lerna run build",
"clean": "lerna run clean"
},
"devDependencies": {
"@rollup/plugin-alias": "^3.1.9",
"@rollup/plugin-commonjs": "^22.0.0",
"@rollup/plugin-node-resolve": "^13.3.0",
"@rollup/plugin-replace": "^4.0.0",
"@types/node": "17.0.35",
"@types/node-fetch": "^2.6.1",
"@typescript-eslint/eslint-plugin": "^5.27.0",
"@typescript-eslint/parser": "^5.27.0",
"eslint": "^8.17.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-require-extensions": "^0.1.1",
"eslint-plugin-simple-import-sort": "^7.0.0",
"lerna": "^5.1.8",
"rollup": "^2.75.6",
"rollup-plugin-node-externals": "^4.0.0",
"rollup-plugin-ts": "^3.0.2",
"shx": "^0.3.4",
"typescript": "^4.7.3",
"typescript-esm": "^2.0.0"
},
"workspaces": [
"packages/*"
]
}
2 changes: 2 additions & 0 deletions js/packages/seed-vault/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lib/
android/build
13 changes: 13 additions & 0 deletions js/packages/seed-vault/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright 2022 Solana Mobile Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
3 changes: 3 additions & 0 deletions js/packages/seed-vault/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `@solana-mobile/seedvaultlib`

A React Native wrapper of the Seed Vault SDK.
14 changes: 14 additions & 0 deletions js/packages/seed-vault/android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# OSX
#
.DS_Store

# Android/IJ
#
.classpath
.cxx
.gradle
.idea
.project
.settings
local.properties
android.iml
150 changes: 150 additions & 0 deletions js/packages/seed-vault/android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
buildscript {
// Buildscript is evaluated before everything else so we can't use getExtOrDefault
def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['SolanaMobileSeedVaultLibModule_kotlinVersion']

repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.4.2'
// noinspection DifferentKotlinGradleVersion
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
}
}

def isNewArchitectureEnabled() {
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlinx-serialization'

if (isNewArchitectureEnabled()) {
apply plugin: 'com.facebook.react'
}

def getExtOrDefault(name) {
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['SolanaMobileSeedVaultLibModule_' + name]
}

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

android {
namespace "com.solanamobile.seedvault.reactnative"
compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')

defaultConfig {
minSdkVersion getExtOrIntegerDefault('minSdkVersion')
targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
}
buildTypes {
release {
minifyEnabled false
}
}

lintOptions {
disable 'GradleCompatible'
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

repositories {
mavenCentral()
google()

def found = false
def defaultDir = null
def androidSourcesName = 'React Native sources'

if (rootProject.ext.has('reactNativeAndroidRoot')) {
defaultDir = rootProject.ext.get('reactNativeAndroidRoot')
} else {
defaultDir = new File(
projectDir,
'/../../../node_modules/react-native/android'
)
}

if (defaultDir.exists()) {
maven {
url defaultDir.toString()
name androidSourcesName
}

logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}")
found = true
} else {
def parentDir = rootProject.projectDir

1.upto(5, {
if (found) return true
parentDir = parentDir.parentFile

def androidSourcesDir = new File(
parentDir,
'node_modules/react-native'
)

def androidPrebuiltBinaryDir = new File(
parentDir,
'node_modules/react-native/android'
)

if (androidPrebuiltBinaryDir.exists()) {
maven {
url androidPrebuiltBinaryDir.toString()
name androidSourcesName
}

logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}")
found = true
} else if (androidSourcesDir.exists()) {
maven {
url androidSourcesDir.toString()
name androidSourcesName
}

logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}")
found = true
}
})
}

if (!found) {
throw new GradleException(
"${project.name}: unable to locate React Native android sources. " +
"Ensure you have you installed React Native as a dependency in your project and try again."
)
}
}

def kotlin_version = getExtOrDefault('kotlinVersion')

dependencies {
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+" // From node_modules
implementation 'com.solanamobile:seedvault-wallet-sdk:0.2.8'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1"
}

if (isNewArchitectureEnabled()) {
react {
jsRootDir = file("../src/")
libraryName = "SolanaMobileWSeedVaultLibModule"
codegenJavaPackageName = "com.solanamobile.SeedVault.reactnative"
}
}
5 changes: 5 additions & 0 deletions js/packages/seed-vault/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SolanaMobileSeedVaultLibModule_kotlinVersion=1.7.0
SolanaMobileSeedVaultLibModule_minSdkVersion=21
SolanaMobileSeedVaultLibModule_targetSdkVersion=33
SolanaMobileSeedVaultLibModule_compileSdkVersion=33
SolanaMobileSeedVaultLibModule_ndkversion=21.4.7075529
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading