@react-native-module/crypto 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.travis.yml ADDED
@@ -0,0 +1,31 @@
1
+ sudo: false
2
+ language: node_js
3
+ matrix:
4
+ include:
5
+ - node_js: '0.10'
6
+ env: TEST_SUITE=unit
7
+ - node_js: '0.11'
8
+ env: TEST_SUITE=unit
9
+ - node_js: '0.12'
10
+ env: TEST_SUITE=unit
11
+ - node_js: '4'
12
+ env: TEST_SUITE=unit
13
+ - node_js: '4'
14
+ env: TEST_SUITE=standard
15
+ - node_js: '4'
16
+ env: TEST_SUITE=browser BROWSER_NAME=ie BROWSER_VERSION="10..latest"
17
+ - node_js: '4'
18
+ env: TEST_SUITE=browser BROWSER_NAME=chrome BROWSER_VERSION="44..beta"
19
+ - node_js: '4'
20
+ env: TEST_SUITE=browser BROWSER_NAME=firefox BROWSER_VERSION="40..latest"
21
+ - node_js: '4'
22
+ env: TEST_SUITE=browser BROWSER_NAME=iphone BROWSER_VERSION="8.0..latest"
23
+ - node_js: '4'
24
+ env: TEST_SUITE=browser BROWSER_NAME=safari BROWSER_VERSION="5..latest"
25
+ - node_js: '4'
26
+ env: TEST_SUITE=browser BROWSER_NAME=android BROWSER_VERSION="4.0..latest"
27
+ script: "npm run-script $TEST_SUITE"
28
+ env:
29
+ global:
30
+ - secure: YHNUDQmx/WiW3gmDcRCfb6KLDeio7Mr5tqPY2kHPdZlBSytsQjNk75ytM4U6Cu8Uk8iEIoj/aFlxiVMpJNA8J4QSUyW/YkbVaIz0+1oywoV0Ht8aRBfZ1jvXfX6789+1Q9c4xaMkYYbJpXSh9JcirsiwmqWd4+IDd7hcESodsDQ=
31
+ - secure: Nhj5yejKZxUbtHGZta+GjYWqXGaOZB7ainTkOuGcpXM+OwwjeDpYlTBrwS90Q7hqens7KXVzQM09aDbadpsDCsOo1nyaEigMtomAorZ1UC1CpEoVz1ZuikF9bEhb+/7M9pzuL1fX+Ke9Dx4mPPeb8sf/2SrAu1RqXkSwZV/duAc=
package/.zuul.yml ADDED
@@ -0,0 +1 @@
1
+ ui: tape
package/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2013 Dominic Tarr
4
+
5
+ Permission is hereby granted, free of charge,
6
+ to any person obtaining a copy of this software and
7
+ associated documentation files (the "Software"), to
8
+ deal in the Software without restriction, including
9
+ without limitation the rights to use, copy, modify,
10
+ merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom
12
+ the Software is furnished to do so,
13
+ subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice
16
+ shall be included in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
22
+ ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # react-native-module/crypto
2
+
3
+ A port of node's `crypto` module to React Native.
4
+ The goal of this module is to reimplement node's crypto module so that it can run in react-native supported environments.
5
+ Features and interface must be compatible with node's crypto
6
+
7
+ this module is a clone of [crypto-browserify](https://github.com/crypto-browserify/crypto-browserify), [react-native-crypto](https://github.com/mvayngrib/react-native-crypto)
8
+
9
+ ## Why use this module and Not others
10
+
11
+ If your app is running on mobile [android, ios] only, sufficient to use module react-native-crypto
12
+ Use this module if you are considering other platforms
13
+
14
+ ## Install
15
+
16
+ A typical workflow:
17
+
18
+ ```
19
+ npm i --save @react-native-module/crypto
20
+ ```
21
+
22
+ ```
23
+ yarn add @react-native-module/crypto
24
+ ```
25
+
26
+ ## List of Support node's features
27
+
28
+ Here is the subset that is currently implemented:
29
+
30
+ - createHash (sha1, sha224, sha256, sha384, sha512, md5, rmd160)
31
+ - createHmac (sha1, sha224, sha256, sha384, sha512, md5, rmd160)
32
+ - pbkdf2
33
+ - pbkdf2Sync
34
+ - randomBytes
35
+ - pseudoRandomBytes
36
+ - createCipher (aes)
37
+ - createDecipher (aes)
38
+ - createDiffieHellman
39
+ - createSign (rsa, ecdsa)
40
+ - createVerify (rsa, ecdsa)
41
+ - createECDH (secp256k1)
42
+ - publicEncrypt/privateDecrypt (rsa)
43
+
44
+ ## Todo
45
+
46
+ these features from node's `crypto` are still unimplemented.
47
+
48
+ - createCredentials
49
+
50
+ these features would benefit from native implementations
51
+
52
+ - pbkdf2
53
+ - createSign
54
+ - createVerify
55
+ - createECDH
56
+ - publicEncrypto/privateDecrypt (rsa)
57
+
58
+ ## contributions
59
+
60
+ Thank you for investing your time in contributing to this project!
61
+
62
+ ## License
63
+
64
+ MIT
package/index.js ADDED
@@ -0,0 +1,99 @@
1
+ 'use strict'
2
+
3
+ import { randomBytes } from 'react-native-randombytes'
4
+ exports.randomBytes = exports.rng = exports.pseudoRandomBytes = exports.prng = randomBytes
5
+
6
+ // implement window.getRandomValues(), for packages that rely on it
7
+ if (typeof window === 'object') {
8
+ if (!window.crypto) window.crypto = {}
9
+ if (!window.crypto.getRandomValues) {
10
+ window.crypto.getRandomValues = function getRandomValues (arr) {
11
+ const orig = arr
12
+ if (arr.byteLength !== arr.length) {
13
+ // Get access to the underlying raw bytes
14
+ arr = new Uint8Array(arr.buffer)
15
+ }
16
+ const bytes = randomBytes(arr.length)
17
+ for (let i = 0; i < bytes.length; i++) {
18
+ arr[i] = bytes[i]
19
+ }
20
+
21
+ return orig
22
+ }
23
+ }
24
+ }
25
+
26
+ exports.createHash = exports.Hash = require('create-hash')
27
+ exports.createHmac = exports.Hmac = require('create-hmac')
28
+
29
+ const hashes = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160'].concat(Object.keys(require('browserify-sign/algos')))
30
+ exports.getHashes = function () {
31
+ return hashes
32
+ }
33
+
34
+ const p = require('pbkdf2')
35
+ exports.pbkdf2 = p.pbkdf2
36
+ exports.pbkdf2Sync = p.pbkdf2Sync
37
+
38
+ const aes = require('browserify-cipher')
39
+ ;[
40
+ 'Cipher',
41
+ 'createCipher',
42
+ 'Cipheriv',
43
+ 'createCipheriv',
44
+ 'Decipher',
45
+ 'createDecipher',
46
+ 'Decipheriv',
47
+ 'createDecipheriv',
48
+ 'getCiphers',
49
+ 'listCiphers'
50
+ ].forEach(function (key) {
51
+ exports[key] = aes[key]
52
+ })
53
+
54
+ const dh = require('diffie-hellman')
55
+ ;[
56
+ 'DiffieHellmanGroup',
57
+ 'createDiffieHellmanGroup',
58
+ 'getDiffieHellman',
59
+ 'createDiffieHellman',
60
+ 'DiffieHellman'
61
+ ].forEach(function (key) {
62
+ exports[key] = dh[key]
63
+ })
64
+
65
+ const sign = require('browserify-sign')
66
+ ;[
67
+ 'createSign',
68
+ 'Sign',
69
+ 'createVerify',
70
+ 'Verify'
71
+ ].forEach(function (key) {
72
+ exports[key] = sign[key]
73
+ })
74
+
75
+ exports.createECDH = require('create-ecdh')
76
+
77
+ const publicEncrypt = require('public-encrypt')
78
+
79
+ ;[
80
+ 'publicEncrypt',
81
+ 'privateEncrypt',
82
+ 'publicDecrypt',
83
+ 'privateDecrypt'
84
+ ].forEach(function (key) {
85
+ exports[key] = publicEncrypt[key]
86
+ })
87
+
88
+ // the least I can do is make error messages for the rest of the node.js/crypto api.
89
+ ;[
90
+ 'createCredentials'
91
+ ].forEach(function (name) {
92
+ exports[name] = function () {
93
+ throw new Error([
94
+ 'sorry, ' + name + ' is not implemented yet',
95
+ 'we accept pull requests',
96
+ 'https://github.com/crypto-browserify/crypto-browserify'
97
+ ].join('\n'))
98
+ }
99
+ })
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "author": "sacru2red <sacru2red@gmail.com>",
3
+ "name": "@react-native-module/crypto",
4
+ "description": "implementation of crypto for React Native",
5
+ "version": "2.1.1",
6
+ "homepage": "https://github.com/react-native-module/crypto",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git://github.com/react-native-module/crypto.git"
10
+ },
11
+ "scripts": {
12
+ "standard": "standard",
13
+ "test": "npm run standard && npm run unit",
14
+ "unit": "Echo 'tests not set up for React Native yet'"
15
+ },
16
+ "engines": {
17
+ "node": "*"
18
+ },
19
+ "dependencies": {
20
+ "browserify-cipher": "^1.0.0",
21
+ "browserify-sign": "^4.0.4",
22
+ "create-ecdh": "^4.0.0",
23
+ "create-hash": "^1.1.0",
24
+ "create-hmac": "^1.1.0",
25
+ "diffie-hellman": "^5.0.0",
26
+ "inherits": "^2.0.1",
27
+ "pbkdf2": "^3.1.2",
28
+ "public-encrypt": "^4.0.0"
29
+ },
30
+ "peerDependencies": {
31
+ "react-native-randombytes": ">=2.0.0 <4.0.0"
32
+ },
33
+ "devDependencies": {
34
+ "hash-test-vectors": "~1.3.2",
35
+ "pseudorandombytes": "^2.0.0",
36
+ "standard": "^16.0.4",
37
+ "tape": "~2.3.2",
38
+ "zuul": "^3.12.0"
39
+ },
40
+ "optionalDependencies": {},
41
+ "keywords": [
42
+ "react-native",
43
+ "crypto"
44
+ ],
45
+ "license": "MIT"
46
+ }