This repository has been archived by the owner on Sep 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 119
Adding react-native environment #187
Open
happymaskterriblefate
wants to merge
2
commits into
alik0211:master
Choose a base branch
from
happymaskterriblefate:react-native
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const { AsyncStorage } = require('react-native'); | ||
|
||
function getLocalStorage() { | ||
return { | ||
set: AsyncStorage.setItem, | ||
get: AsyncStorage.getItem | ||
} | ||
} | ||
|
||
module.exports = getLocalStorage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require('react-native-get-random-values'); | ||
|
||
function getRandomBytes(length) { | ||
const bytes = new Uint8Array(length); | ||
crypto.getRandomValues(bytes); | ||
return bytes; | ||
} | ||
|
||
module.exports = getRandomBytes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const { polyfillGlobal } = require("react-native/Libraries/Utilities/PolyfillFunctions"); | ||
const { TextEncoder, TextDecoder } = require("text-encoding"); | ||
const makeMTProto = require('../../src'); | ||
const SHA1 = require('./sha1'); | ||
const SHA256 = require('./sha256'); | ||
const PBKDF2 = require('./pbkdf2'); | ||
const Transport = require('./transport'); | ||
const getRandomBytes = require('./get-random-bytes'); | ||
const getLocalStorage = require('./get-local-storage'); | ||
|
||
polyfillGlobal("TextEncoder", () => TextEncoder); | ||
polyfillGlobal("TextDecoder", () => TextDecoder); | ||
|
||
function createTransport(dc, crypto) { | ||
return new Transport(dc, crypto); | ||
} | ||
|
||
const MTProto = makeMTProto({ | ||
SHA1, | ||
SHA256, | ||
PBKDF2, | ||
getRandomBytes, | ||
getLocalStorage, | ||
createTransport, | ||
}); | ||
|
||
module.exports = MTProto; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const sha256 = require("fast-sha256"); | ||
|
||
async function PBKDF2(password, salt, iterations) { | ||
return sha256.pbkdf2(password, salt, iterations, 512); | ||
} | ||
|
||
module.exports = PBKDF2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const jsSHA = require("jssha"); | ||
|
||
async function SHA1(data) { | ||
const format = data instanceof Uint8Array ? "UINT8ARRAY" : "ARRAYBUFFER"; | ||
const digest = new jsSHA("SHA-1", format) | ||
digest.update(data) | ||
return digest.getHash("UINT8ARRAY") | ||
} | ||
|
||
module.exports = SHA1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const jsSHA = require("jssha"); | ||
|
||
async function SHA256(data) { | ||
const format = data instanceof Uint8Array ? "UINT8ARRAY" : "ARRAYBUFFER"; | ||
const digest = new jsSHA("SHA-256", format) | ||
digest.update(data) | ||
return digest.getHash("UINT8ARRAY") | ||
} | ||
|
||
module.exports = SHA256; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('../browser/transport'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
"/src" | ||
], | ||
"main": "./envs/node/index.js", | ||
"react-native": "./envs/react-native/index.js", | ||
"engines": { | ||
"node": ">=12" | ||
}, | ||
|
@@ -54,5 +55,12 @@ | |
"devDependencies": { | ||
"jest": "26.6.3", | ||
"npm-run-all": "4.1.5" | ||
}, | ||
"peerDependencies": { | ||
"react-native": "*", | ||
"fast-sha256": "^1.3.0", | ||
"jssha": "^3.2.0", | ||
"react-native-get-random-values": "^1.7.0", | ||
"text-encoding": "^0.7.0" | ||
} | ||
Comment on lines
+59
to
65
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. The package file.json is used for all environments, so I think it's better to remove peerDependencies for react-native from here. Instead, I will add instructions for installing these dependencies to the documentation |
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
May return incorrect string. Also sometimes getting
SRP_ID_INVALID
error