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

chore: some improvements #9

Merged
merged 3 commits into from
Aug 25, 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
5 changes: 0 additions & 5 deletions .eslintrc.js

This file was deleted.

6 changes: 6 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,15 @@ jobs:
- name: Install dependencies
run: pnpm install

- name: Style
run: pnpm style:check

- name: Build
run: pnpm build

- name: Check types
run: pnpm types:check

continuous-deployment:
if: github.event_name == 'workflow_dispatch'

Expand Down
1 change: 1 addition & 0 deletions .release-it.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
},
"npm": {
"skipChecks": true,
"ignoreVersion": true,
"tag": "latest"
},
"git": {
Expand Down
35 changes: 35 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"$schema": "https://biomejs.dev/schemas/1.8.1/schema.json",
"formatter": {
"lineWidth": 120,
"indentStyle": "space"
},
"javascript": {
"parser": {
"unsafeParameterDecoratorsEnabled": true
},
"formatter": {
"semicolons": "asNeeded",
"quoteStyle": "single",
"trailingCommas": "es5",
"lineWidth": 120,
"indentStyle": "space"
}
},
"json": {
"parser": {
"allowComments": true
}
},
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true
},
"vcs": {
"useIgnoreFile": true,
"clientKind": "git",
"enabled": true
}
}
104 changes: 50 additions & 54 deletions example/App.tsx
Original file line number Diff line number Diff line change
@@ -1,74 +1,70 @@
import {
ariesAskar,
KeyAlgs,
LocalKeyHandle,
} from "@hyperledger/aries-askar-react-native";
import {
sign,
generateKeypair,
getPublicBytesForKeyId,
} from "expo-secure-environment";
import { Button } from "react-native";
import { StyleSheet, View } from "react-native";
import { generateKeypair, getPublicBytesForKeyId, sign } from '@animo-id/expo-secure-environment'
import { KeyAlgs, LocalKeyHandle, ariesAskar } from '@hyperledger/aries-askar-react-native'
import { Button } from 'react-native'
import { StyleSheet, View } from 'react-native'

export default function App() {
const testBiometrics = async () => {
try{
const id = new Date().toString();
generateKeypair(id, true);
const publicKey = getPublicBytesForKeyId(id);
const key = ariesAskar.keyFromPublicBytes({
algorithm: KeyAlgs.EcSecp256r1,
publicKey,
});
const kHandle = new LocalKeyHandle(key.handle);
const message = new Uint8Array(10).fill(10);
const signature = await sign(id, new Uint8Array(message), true);
const isValid = ariesAskar.keyVerifySignature({
message,
signature,
localKeyHandle: kHandle,
});
try {
const id = new Date().toString()
generateKeypair(id, true)
const publicKey = getPublicBytesForKeyId(id)
const key = ariesAskar.keyFromPublicBytes({
algorithm: KeyAlgs.EcSecp256r1,
publicKey,
})
const kHandle = new LocalKeyHandle(key.handle)
const message = new Uint8Array(10).fill(10)
const signature = await sign(id, new Uint8Array(message), true)
const isValid = ariesAskar.keyVerifySignature({
message,
signature,
localKeyHandle: kHandle,
})

console.log(isValid);
}catch(e) {
console.error('ERRRRRR', e)
console.log('Signing with biometrics enabled isValid: ', isValid)
} catch (e) {
console.error('Error signing with biometrics enabled', e)
}
};
}

const testNoBiometrics = async () => {
const id = new Date().toString();
generateKeypair(id, false);
const publicKey = getPublicBytesForKeyId(id);
const key = ariesAskar.keyFromPublicBytes({
algorithm: KeyAlgs.EcSecp256r1,
publicKey,
});
const kHandle = new LocalKeyHandle(key.handle);
const message = new Uint8Array(10).fill(10);
const signature = await sign(id, new Uint8Array(message), false);
const isValid = ariesAskar.keyVerifySignature({
message,
signature,
localKeyHandle: kHandle,
});
try {
const id = new Date().toString()
generateKeypair(id, false)
const publicKey = getPublicBytesForKeyId(id)
const key = ariesAskar.keyFromPublicBytes({
algorithm: KeyAlgs.EcSecp256r1,
publicKey,
})
const kHandle = new LocalKeyHandle(key.handle)
const message = new Uint8Array(10).fill(10)
const signature = await sign(id, new Uint8Array(message), false)
const isValid = ariesAskar.keyVerifySignature({
message,
signature,
localKeyHandle: kHandle,
})

console.log(isValid);
};
console.log('Signing with biometrics disabled isValid: ', isValid)
} catch (e) {
console.error('Error signing with biometrics disabled', e)
}
}

return (
<View style={styles.container}>
<Button title="test biometrics" onPress={testBiometrics} />
<Button title="test without biometrics" onPress={testNoBiometrics} />
</View>
);
)
}

const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center",
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
})
5 changes: 4 additions & 1 deletion example/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
},
"ios": {
"supportsTablet": true,
"bundleIdentifier": "id.animo.secure.environment.example"
"bundleIdentifier": "id.animo.secure.environment.example",
"infoPlist": {
"NSFaceIDUsageDescription": "FaceID is used to securely sign data"
}
},
"android": {
"adaptiveIcon": {
Expand Down
8 changes: 4 additions & 4 deletions example/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = function (api) {
api.cache(true);
module.exports = (api) => {
api.cache(true)
return {
presets: ['babel-preset-expo'],
};
};
}
}
6 changes: 3 additions & 3 deletions example/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { registerRootComponent } from "expo";
import { registerRootComponent } from 'expo'

import App from "./App";
import App from './App'

registerRootComponent(App);
registerRootComponent(App)
20 changes: 10 additions & 10 deletions example/metro.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Learn more https://docs.expo.io/guides/customizing-metro
const { getDefaultConfig } = require('expo/metro-config');
const path = require('path');
const { getDefaultConfig } = require('expo/metro-config')
const path = require('node:path')

const config = getDefaultConfig(__dirname);
const config = getDefaultConfig(__dirname)

// npm v7+ will install ../node_modules/react and ../node_modules/react-native because of peerDependencies.
// To prevent the incompatible react-native between ./node_modules/react-native and ../node_modules/react-native,
Expand All @@ -11,24 +11,24 @@ config.resolver.blockList = [
...Array.from(config.resolver.blockList ?? []),
new RegExp(path.resolve('..', 'node_modules', 'react')),
new RegExp(path.resolve('..', 'node_modules', 'react-native')),
];
]

config.resolver.nodeModulesPaths = [
path.resolve(__dirname, './node_modules'),
path.resolve(__dirname, '../node_modules'),
];
]

config.resolver.extraNodeModules = {
'expo-secure-environment': '..',
};
'@animo-id/expo-secure-environment': '..',
}

config.watchFolders = [path.resolve(__dirname, '..')];
config.watchFolders = [path.resolve(__dirname, '..')]

config.transformer.getTransformOptions = async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: true,
},
});
})

module.exports = config;
module.exports = config
4 changes: 1 addition & 3 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@
"start": "expo start",
"android": "expo run:android",
"ios": "expo run:ios",
"web": "expo start --web"
"prebuild": "expo prebuild --no-install"
},
"dependencies": {
"@babel/runtime": "^7.24.8",
"@hyperledger/aries-askar-react-native": "^0.2.3",
"@react-native/assets-registry": "^0.74.85",
"expo": "~51.0.22",
"react": "18.2.0",
"react-native": "0.74.3"
},
"devDependencies": {
"@babel/core": "^7.20.0",
"@types/react": "~18.2.45",
"typescript": "^5.1.3"
},
Expand Down
6 changes: 0 additions & 6 deletions example/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions example/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"compilerOptions": {
"strict": true,
"paths": {
"expo-secure-environment": ["../src/index"],
"expo-secure-environment/*": ["../src/*"]
"@animo-id/expo-secure-environment": ["../src/index"]
}
}
}
19 changes: 10 additions & 9 deletions ios/SecureEnvironment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@ struct SecureEnvironment {
kSecAttrApplicationTag as String: Bundle.main.bundleIdentifier.unsafelyUnwrapped,
],
]


var flags: SecAccessControlCreateFlags = [.privateKeyUsage]
if biometricsBacked {
let accessControl = SecAccessControlCreateWithFlags(
kCFAllocatorDefault,
kSecAttrAccessibleWhenUnlockedThisDeviceOnly,
[.privateKeyUsage, .biometryCurrentSet],
nil
)

attributes[kSecAttrAccessControl as String] = accessControl
flags.insert(.biometryCurrentSet)
}

attributes[kSecAttrAccessControl as String] = SecAccessControlCreateWithFlags(
kCFAllocatorDefault,
kSecAttrAccessibleWhenUnlockedThisDeviceOnly,
flags,
nil
)

var error: Unmanaged<CFError>?
guard SecKeyCreateRandomKey(attributes as CFDictionary, &error) != nil else {
throw error!.takeRetainedValue() as Error
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@animo-id/expo-secure-environment",
"version": "0.1.0-alpha.3",
"version": "0.0.0",
"description": "Expo Secure Environment",
"main": "build/index.js",
"types": "build/index.d.ts",
Expand All @@ -9,17 +9,15 @@
},
"scripts": {
"build": "EXPO_NONINTERACTIVE=1 expo-module build",
"style:check": "biome check --unsafe",
"style:fix": "biome check --write --unsafe",
"types:check": "EXPO_NONINTERACTIVE=1 expo-module typecheck",
"expo-module": "expo-module",
"open:ios": "xed example/ios",
"open:android": "open -a \"Android Studio\" example/android",
"release": "release-it"
},
"keywords": [
"react-native",
"expo",
"expo-secure-environment",
"ExpoSecureEnvironment"
],
"keywords": ["react-native", "expo", "expo-secure-environment", "ExpoSecureEnvironment"],
"repository": "https://github.com/animo/expo-secure-environment",
"bugs": {
"url": "https://github.com/animo/expo-secure-environment/issues"
Expand All @@ -33,10 +31,12 @@
"@peculiar/asn1-x509": "^2.3.8"
},
"devDependencies": {
"@biomejs/biome": "^1.8.3",
"@types/react": "^18.0.25",
"expo-module-scripts": "^3.5.2",
"expo-modules-core": "^1.12.19",
"release-it": "^17.4.1"
"release-it": "^17.4.1",
"typescript": "^5.5.4"
},
"peerDependencies": {
"expo": "*",
Expand Down
Loading