-
Notifications
You must be signed in to change notification settings - Fork 19
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
Feature/storage adapter #16
Changes from 10 commits
a179a29
e5b369f
0dbb8c6
f51a8ce
3ccd9e4
c5ffecb
cafecc9
4a5f592
12382c7
41dcb46
dd1d34d
82ddc48
b572346
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
example | ||
node_modules |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const path = require('path'); | ||
const noPythiaCryptoPath = require.resolve('virgil-crypto'); | ||
const pythiaCryptoPath = path.resolve(noPythiaCryptoPath, '../virgil-crypto-pythia.es.js'); | ||
const pythiaCryptoBrowserPath = path.resolve(noPythiaCryptoPath, '../virgil-crypto-pythia.browser.es.js'); | ||
|
||
class Paths { | ||
constructor() { | ||
this.PLATFORM = process.env.PLATFORM || 'node'; | ||
this.IS_BROWSER = this.PLATFORM === 'browser'; | ||
this.NAME = 'e3kit'; | ||
|
||
this.input = path.join(process.cwd(), 'src', 'index.ts'); | ||
this.outputDir = path.join(process.cwd(), 'dist'); | ||
|
||
this.formats = { | ||
umd: 'umd', | ||
es: 'es', | ||
cjs: 'cjs' | ||
} | ||
this.pythiaCryptoPath = this.IS_BROWSER ? pythiaCryptoBrowserPath : pythiaCryptoPath; | ||
} | ||
|
||
getFileName(format) { | ||
const parts = [this.NAME, this.PLATFORM, format]; | ||
|
||
if (format === this.formats.umd) { | ||
parts.push('min'); | ||
} | ||
const ext = (format === this.formats.es && this.PLATFORM === 'node') ? 'mjs' : 'js'; | ||
parts.push(ext); | ||
return parts.join('.'); | ||
} | ||
} | ||
|
||
module.exports = new Paths(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const paths = require('./paths'); | ||
|
||
const commonjs = require('rollup-plugin-commonjs'); | ||
const inject = require('rollup-plugin-inject'); | ||
const nodeGlobals = require('rollup-plugin-node-globals'); | ||
const resolve = require('rollup-plugin-node-resolve'); | ||
const typescript = require('rollup-plugin-typescript2'); | ||
const { uglify } = require('rollup-plugin-uglify'); | ||
const sourcemap = require('rollup-plugin-sourcemaps'); | ||
|
||
|
||
function resolveVirgilCrypto () { | ||
return { | ||
name: 'resolve-virgil-crypto', | ||
resolveId (importee, b) { | ||
if (importee === 'virgil-crypto') { | ||
console.log(importee, b); | ||
return paths.pythiaCryptoPath; | ||
} | ||
return null; | ||
} | ||
} | ||
} | ||
|
||
class RollupPluginsResolver { | ||
|
||
constructor() { | ||
this.commonjs = commonjs; | ||
this.nodeGlobals = nodeGlobals; | ||
this.resolve = resolve; | ||
this.sourcemap = sourcemap; | ||
this.uglify = uglify; | ||
this.resolveVirgilCrypto = resolveVirgilCrypto; | ||
this.typescriptResolved = typescript({ | ||
exclude: ['**/*.test.ts', '**/*.spec.ts', '**/__mocks__/*.ts'], | ||
useTsconfigDeclarationDir: true, | ||
}); | ||
} | ||
} | ||
|
||
module.exports = new RollupPluginsResolver(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const paths = require('./paths'); | ||
const plugins = require('./rollup-plugins'); | ||
|
||
const format = paths.formats.es; | ||
|
||
module.exports = { | ||
input: paths.input, | ||
output: { | ||
format: format, | ||
file: paths.getFileName(format, false), | ||
dir: paths.outputDir, | ||
sourcemap: true, | ||
}, | ||
plugins: [ | ||
plugins.resolveVirgilCrypto(), | ||
plugins.resolve({ browser: true }), | ||
plugins.commonjs(), | ||
plugins.typescriptResolved, | ||
], | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const paths = require('./paths'); | ||
const plugins = require('./rollup-plugins'); | ||
|
||
const UMD_NAME = 'E3kit'; | ||
|
||
module.exports = { | ||
input: paths.input, | ||
output: { | ||
format: paths.formats.umd, | ||
file: paths.getFileName(paths.formats.umd, true), | ||
dir: paths.outputDir, | ||
sourcemap: true, | ||
name: UMD_NAME | ||
}, | ||
plugins: [ | ||
plugins.sourcemap(), | ||
plugins.resolveVirgilCrypto(), | ||
plugins.resolve({ browser: true }), | ||
plugins.commonjs(), | ||
plugins.typescriptResolved, | ||
plugins.uglify(), | ||
], | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["module:metro-react-native-babel-preset"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
[android] | ||
target = Google Inc.:Google APIs:23 | ||
|
||
[maven_repositories] | ||
central = https://repo1.maven.org/maven2 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
[ignore] | ||
; We fork some components by platform | ||
.*/*[.]android.js | ||
|
||
; Ignore "BUCK" generated dirs | ||
<PROJECT_ROOT>/\.buckd/ | ||
|
||
; Ignore unexpected extra "@providesModule" | ||
.*/node_modules/.*/node_modules/fbjs/.* | ||
|
||
; Ignore duplicate module providers | ||
; For RN Apps installed via npm, "Libraries" folder is inside | ||
; "node_modules/react-native" but in the source repo it is in the root | ||
.*/Libraries/react-native/React.js | ||
|
||
; Ignore polyfills | ||
.*/Libraries/polyfills/.* | ||
|
||
; Ignore metro | ||
.*/node_modules/metro/.* | ||
|
||
[include] | ||
|
||
[libs] | ||
node_modules/react-native/Libraries/react-native/react-native-interface.js | ||
node_modules/react-native/flow/ | ||
node_modules/react-native/flow-github/ | ||
|
||
[options] | ||
emoji=true | ||
|
||
esproposal.optional_chaining=enable | ||
esproposal.nullish_coalescing=enable | ||
|
||
module.system=haste | ||
module.system.haste.use_name_reducers=true | ||
# get basename | ||
module.system.haste.name_reducers='^.*/\([a-zA-Z0-9$_.-]+\.js\(\.flow\)?\)$' -> '\1' | ||
# strip .js or .js.flow suffix | ||
module.system.haste.name_reducers='^\(.*\)\.js\(\.flow\)?$' -> '\1' | ||
# strip .ios suffix | ||
module.system.haste.name_reducers='^\(.*\)\.ios$' -> '\1' | ||
module.system.haste.name_reducers='^\(.*\)\.android$' -> '\1' | ||
module.system.haste.name_reducers='^\(.*\)\.native$' -> '\1' | ||
module.system.haste.paths.blacklist=.*/__tests__/.* | ||
module.system.haste.paths.blacklist=.*/__mocks__/.* | ||
module.system.haste.paths.blacklist=<PROJECT_ROOT>/node_modules/react-native/Libraries/Animated/src/polyfills/.* | ||
module.system.haste.paths.whitelist=<PROJECT_ROOT>/node_modules/react-native/Libraries/.* | ||
|
||
munge_underscores=true | ||
|
||
module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub' | ||
|
||
module.file_ext=.js | ||
module.file_ext=.jsx | ||
module.file_ext=.json | ||
module.file_ext=.native.js | ||
|
||
suppress_type=$FlowIssue | ||
suppress_type=$FlowFixMe | ||
suppress_type=$FlowFixMeProps | ||
suppress_type=$FlowFixMeState | ||
|
||
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\) | ||
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+ | ||
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy | ||
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError | ||
|
||
[version] | ||
^0.78.0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.pbxproj -text |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# OSX | ||
# | ||
.DS_Store | ||
|
||
# Xcode | ||
# | ||
build/ | ||
*.pbxuser | ||
!default.pbxuser | ||
*.mode1v3 | ||
!default.mode1v3 | ||
*.mode2v3 | ||
!default.mode2v3 | ||
*.perspectivev3 | ||
!default.perspectivev3 | ||
xcuserdata | ||
*.xccheckout | ||
*.moved-aside | ||
DerivedData | ||
*.hmap | ||
*.ipa | ||
*.xcuserstate | ||
project.xcworkspace | ||
|
||
# Android/IntelliJ | ||
# | ||
build/ | ||
.idea | ||
.gradle | ||
local.properties | ||
*.iml | ||
|
||
# node.js | ||
# | ||
node_modules/ | ||
npm-debug.log | ||
yarn-error.log | ||
|
||
# BUCK | ||
buck-out/ | ||
\.buckd/ | ||
*.keystore | ||
|
||
# fastlane | ||
# | ||
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the | ||
# screenshots whenever they are needed. | ||
# For more information about the recommended setup visit: | ||
# https://docs.fastlane.tools/best-practices/source-control/ | ||
|
||
*/fastlane/report.xml | ||
*/fastlane/Preview.html | ||
*/fastlane/screenshots | ||
|
||
# Bundle artifact | ||
*.jsbundle |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
* Sample React Native App | ||
* https://github.com/facebook/react-native | ||
* | ||
* @format | ||
* @flow | ||
*/ | ||
|
||
import React, {Component} from 'react'; | ||
import {Platform, StyleSheet, Text, View} from 'react-native'; | ||
import { EThree } from '@virgilsecurity/e3kit'; | ||
import createNativeKeyEntryStorage from '@virgilsecurity/key-storage-rn/native'; | ||
const keyEntryStorage = createNativeKeyEntryStorage(); | ||
import 'whatwg-fetch'; | ||
import 'es6-symbol' | ||
|
||
const instructions = Platform.select({ | ||
ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu', | ||
android: | ||
'Double tap R on your keyboard to reload,\n' + | ||
'Shake or press menu button for dev menu', | ||
}); | ||
|
||
export default class App extends Component { | ||
|
||
state = { | ||
message: null | ||
} | ||
|
||
componentDidMount() { | ||
const getToken = () => fetch("http://192.168.1.125:3000/get-virgil-jwt") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it will not work on android, but it is just examples, so |
||
.then(res => res.json()) | ||
.then(data => data.token); | ||
|
||
console.log('keyEntryStorage', keyEntryStorage); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can probably remove this as well. |
||
EThree.initialize(getToken, { keyEntryStorage: keyEntryStorage }) | ||
.then(client => sdk = client) | ||
.then(() => sdk.register()) | ||
.then(() => sdk.encrypt('success!')) | ||
.then((encryptedMessage) => sdk.decrypt(encryptedMessage)) | ||
.then((message) => this.setState({ message: message })) | ||
.then(() => sdk.cleanup()) | ||
.catch((error) => { | ||
this.setState({ message: error.toString() }) | ||
}); | ||
} | ||
render() { | ||
return ( | ||
<View style={styles.container}> | ||
<Text style={styles.welcome}>Welcome to React Native!</Text> | ||
<Text style={styles.instructions}>To get started, edit App.js</Text> | ||
<Text style={styles.instructions}>{instructions}</Text> | ||
{this.state.message && <Text style={styles.instructions}>{this.state.message}</Text>} | ||
</View> | ||
); | ||
} | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
backgroundColor: '#F5FCFF', | ||
}, | ||
welcome: { | ||
fontSize: 20, | ||
textAlign: 'center', | ||
margin: 10, | ||
}, | ||
instructions: { | ||
textAlign: 'center', | ||
color: '#333333', | ||
marginBottom: 5, | ||
}, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this was meant for debugging purposes, it can be removed