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(ci): create workflow for lint #2

Merged
merged 5 commits into from
Jul 26, 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
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "npm" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "monthly"
24 changes: 24 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
name: Node.js lint
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.x, 22.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/previous-releases
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: yarn
- run: yarn run lint
6 changes: 6 additions & 0 deletions .idea/jsLinters/eslint.xml

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

30 changes: 15 additions & 15 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { useEffect } from 'react';
import RNFS from 'react-native-fs';
import { useState } from 'react';
import {
StyleSheet,
View,
TouchableOpacity,
Text,
ScrollView,
Dimensions,
Platform,
ScrollView,
StyleSheet,
Text,
TouchableOpacity,
View,
} from 'react-native';

import { AbrevvaCrypto, AbrevvaNfc } from 'react-native-example-app';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { useState } from 'react';
import RNFS from 'react-native-fs';

import { BleScreen } from './BleScreenComponents';

const Stack = createNativeStackNavigator();
Expand Down Expand Up @@ -47,12 +47,12 @@ const HomeScreen = ({ navigation }) => {
);
};

const NfcScreen = ({ navigation }) => {
const NfcScreen = () => {
useEffect(() => {
if (Platform.OS === 'ios' || Platform.OS === 'android') {
RNFS.exists(`${RNFS.DocumentDirectoryPath}/client-${Platform.OS}.p12`).then((exists) => {
if (!exists) {
RNFS.copyFile(
void RNFS.copyFile(
RNFS.MainBundlePath + `/client-${Platform.OS}.p12`,
`${RNFS.DocumentDirectoryPath}/client-${Platform.OS}.p12`,
);
Expand All @@ -69,7 +69,7 @@ const NfcScreen = ({ navigation }) => {
);
};

const CryptoScreen = ({ navigation }) => {
const CryptoScreen = () => {
const [result, setResult] = useState('');
return (
<View style={styles.cryptoContainer}>
Expand All @@ -80,15 +80,15 @@ const CryptoScreen = ({ navigation }) => {
<Button
text="generateKeyPair"
onPressFunction={() => {
AbrevvaCrypto.generateKeyPair().then((ret) => {
AbrevvaCrypto.generateKeyPair().then((ret: any) => {
setResult(`Privat Key:\n${ret.privateKey}\n\nPublic Key\n:${ret.publicKey}`);
});
}}
/>
<Button
text="random"
onPressFunction={() => {
AbrevvaCrypto.random({ numBytes: 4 }).then((ret) => {
AbrevvaCrypto.random({ numBytes: 4 }).then((ret: any) => {
setResult(`random:\n${ret.value}\n\n`);
});
}}
Expand Down
53 changes: 21 additions & 32 deletions example/src/BleScreenComponents.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
import { hex } from '@scure/base';
import { Parser } from 'binary-parser-encoder';
import { useEffect } from 'react';
import { useState } from 'react';
import {
StyleSheet,
TouchableOpacity,
Text,
FlatList,
Alert,
Dimensions,
FlatList,
RefreshControl,
SafeAreaView,
Alert,
StyleSheet,
Text,
TouchableOpacity,
} from 'react-native';
import {
AbrevvaBle,
AbrevvaCrypto,
dataViewToNumbers,
numbersToDataView,
dataViewToHexString,
dataViewToNumbers,
hexStringToDataView,
type ScanResult,
numbersToDataView,
type ReadResult,
type ScanResult,
} from 'react-native-example-app';
import { useState } from 'react';
import { Parser } from 'binary-parser-encoder';
import { hex } from '@scure/base';

global.Buffer = require('buffer').Buffer;

const SCAN_TIMEOUT = 3000; // ms
const SERVICE = '9DB2CA57-D890-46D5-A142-59F3C1164B10';

enum CHARACTERISTICS {
MOBILE_GROUPS = '9DB2CA58-D890-46D5-A142-59F3C1164B10',
MOBILE_ACCESS_DATA = '9DB2CA5A-D890-46D5-A142-59F3C1164B10',
ACCESS_STATUS = '9DB2CA5B-D890-46D5-A142-59F3C1164B10',
CHALLENGE = '9DB2CA59-D890-46D5-A142-59F3C1164B10',
Expand Down Expand Up @@ -79,7 +78,7 @@ const advManufacturerDataParser = new Parser()
defaultChoice: advParseDone,
});

export const BleScreen = ({ navigation }) => {
export const BleScreen = () => {
const [statusCode, setStatusCode] = useState('none');

return (
Expand All @@ -102,7 +101,7 @@ const ScanResults = ({ setStatus }) => {
setdeviceList([]);

AbrevvaBle.stopLEScan().then(() => {
AbrevvaBle.requestLEScan({ timeout: SCAN_TIMEOUT }, scanRequestCallback);
void AbrevvaBle.requestLEScan({ timeout: SCAN_TIMEOUT }, scanRequestCallback);
});
setTimeout(() => {
setRefreshing(false);
Expand All @@ -114,7 +113,7 @@ const ScanResults = ({ setStatus }) => {
const md = new Uint8Array(data.manufacturerData!['2153'].buffer);
const mfData = advManufacturerDataParser.parse(md);
if (mfData.identifier) {
const deviceId = mfData.identifier.reduce((t, x): string => {
const deviceId = mfData.identifier.reduce((t: any, x: any): string => {
return t + x.toString(16).padStart(2, '0').toLowerCase();
}, '');
if (deviceId === '5464de1ac537') {
Expand All @@ -128,7 +127,7 @@ const ScanResults = ({ setStatus }) => {

useEffect(() => {
AbrevvaBle.initialize({ androidNeverForLocation: true }).then(() => {
AbrevvaBle.requestLEScan({ timeout: SCAN_TIMEOUT }, scanRequestCallback);
void AbrevvaBle.requestLEScan({ timeout: SCAN_TIMEOUT }, scanRequestCallback);
});
}, []);

Expand All @@ -141,7 +140,7 @@ const ScanResults = ({ setStatus }) => {
<SafeAreaView style={bleStyles.BleScanResult}>
<TouchableOpacity
onPress={() => {
mobileIdentificationMediumService(item.item, setStatus);
void mobileIdentificationMediumService(item.item, setStatus);
}}
>
<Text>{item.item.device.deviceId}</Text>
Expand All @@ -153,7 +152,7 @@ const ScanResults = ({ setStatus }) => {
);
};

var serviceIsActive = false;
let serviceIsActive = false;

async function mobileIdentificationMediumService(data: ScanResult, setStatus: any) {
if (serviceIsActive) {
Expand All @@ -170,24 +169,14 @@ async function mobileIdentificationMediumService(data: ScanResult, setStatus: an
timeout: 10000,
});

const mobileGroupsData = (
await AbrevvaBle.read({
deviceId: data.device.deviceId,
service: SERVICE,
characteristic: CHARACTERISTICS.MOBILE_GROUPS,
timeout: 10000,
})
).value;

await AbrevvaBle.startNotifications(
{
deviceId: data.device.deviceId,
service: SERVICE,
characteristic: CHARACTERISTICS.ACCESS_STATUS,
timeout: 1000,
},
(event: ReadResult) => {
newStatus = event;
newStatus = event.value!;
},
);

Expand All @@ -198,7 +187,7 @@ async function mobileIdentificationMediumService(data: ScanResult, setStatus: an
timeout: 10000,
});

const challengeDataView = hexStringToDataView(challenge.value);
const challengeDataView = hexStringToDataView(challenge.value!);
const challengeBuffer = Buffer.from(dataViewToNumbers(challengeDataView));
const challengeHex = challengeBuffer.toString('hex');

Expand Down Expand Up @@ -246,15 +235,15 @@ async function mobileIdentificationMediumService(data: ScanResult, setStatus: an
authTag: authTagBuffer,
});

AbrevvaBle.write({
void AbrevvaBle.write({
deviceId: data.device.deviceId,
service: SERVICE,
characteristic: CHARACTERISTICS.MOBILE_ACCESS_DATA,
value: dataViewToHexString(numbersToDataView(mdf)),
timeout: 1000,
});
} catch (error: any) {
AbrevvaBle.disconnect({ deviceId: data.device.deviceId });
void AbrevvaBle.disconnect({ deviceId: data.device.deviceId });
serviceIsActive = false;
Alert.alert('Error', error.code, [
{
Expand Down
Loading
Loading