Skip to content
This repository has been archived by the owner on May 26, 2023. It is now read-only.

feat: use sodium-native only #330

Merged
merged 1 commit into from
Aug 13, 2021
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
1 change: 0 additions & 1 deletion jest-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ if (process.env.TEST_ENV === 'unit') {
window.fetch = global.fetch = require('jest-fetch-mock');
}

window.crypto = global.crypto = require('@trust/webcrypto');
require('dotenv').config('.env');
2 changes: 1 addition & 1 deletion packages/zilliqa-js-crypto/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

### `randomBytes(bytes: number): string`

Safely generates bytes using [`Window.crypto`](https://developer.mozilla.org/en-US/docs/Web/API/Window/crypto) in the browser or the built-in `crypto` in node.
Safely generates bytes using [sodium-native](https://github.com/sodium-friends/sodium-native).

**Parameters**

Expand Down
8 changes: 1 addition & 7 deletions packages/zilliqa-js-crypto/src/random.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,7 @@
export const randomBytes = (bytes: number) => {
let randBz: number[] | Uint8Array;

if (
typeof window !== 'undefined' &&
window.crypto &&
window.crypto.getRandomValues
) {
randBz = window.crypto.getRandomValues(new Uint8Array(bytes));
} else if (typeof require !== 'undefined') {
if (typeof require !== 'undefined') {
const b = Buffer.allocUnsafe(bytes);
const sodium = require('sodium-native');
sodium.randombytes_buf(b);
Expand Down
53 changes: 1 addition & 52 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1911,26 +1911,6 @@
resolved "https://registry.npmjs.org/@protobufjs/utf8/-/utf8-1.1.0.tgz#a777360b5b39a1a2e5106f8e858f2fd2d060c570"
integrity sha1-p3c2C1s5oaLlEG+OhY8v0tBgxXA=

"@trust/keyto@^0.3.4":
version "0.3.7"
resolved "https://registry.npmjs.org/@trust/keyto/-/keyto-0.3.7.tgz#e251264e302a7a6be64a3e208dacb2ef6268c946"
integrity sha512-t5kWWCTkPgg24JWVuCTPMx7l13F7YHdxBeJkT1vmoHjROgiOIEAN8eeY+iRmP1Hwsx+S7U55HyuqSsECr08a8A==
dependencies:
asn1.js "^5.0.1"
base64url "^3.0.1"
elliptic "^6.4.1"

"@trust/webcrypto@^0.9.2":
version "0.9.2"
resolved "https://registry.npmjs.org/@trust/webcrypto/-/webcrypto-0.9.2.tgz#c699d4c026a4446b04faa54d5389a81888ba713c"
integrity sha512-5iMAVcGYKhqLJGjefB1nzuQSqUJTru0nG4CytpBT/GGp1Piz/MVnj2jORdYf4JBYzggCIa8WZUr2rchP2Ngn/w==
dependencies:
"@trust/keyto" "^0.3.4"
base64url "^3.0.0"
elliptic "^6.4.0"
node-rsa "^0.4.0"
text-encoding "^0.6.1"

"@types/anymatch@*":
version "1.3.1"
resolved "https://registry.npmjs.org/@types/anymatch/-/anymatch-1.3.1.tgz#336badc1beecb9dacc38bea2cf32adf627a8421a"
Expand Down Expand Up @@ -2741,15 +2721,6 @@ asap@^2.0.0:
resolved "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz#e50347611d7e690943208bbdafebcbc2fb866d46"
integrity sha1-5QNHYR1+aQlDIIu9r+vLwvuGbUY=

asn1.js@^5.0.1:
version "5.2.0"
resolved "https://registry.npmjs.org/asn1.js/-/asn1.js-5.2.0.tgz#292c0357f26a47802ac9727e8772c09c7fc9bd85"
integrity sha512-Q7hnYGGNYbcmGrCPulXfkEw7oW7qjWeM4ZTALmgpuIcZLxyqqKYWxCZg2UBm8bklrnB4m2mGyJPWfoktdORD8A==
dependencies:
bn.js "^4.0.0"
inherits "^2.0.1"
minimalistic-assert "^1.0.0"

asn1.js@^5.2.0:
version "5.4.1"
resolved "https://registry.npmjs.org/asn1.js/-/asn1.js-5.4.1.tgz#11a980b84ebb91781ce35b0fdc2ee294e3783f07"
Expand All @@ -2760,11 +2731,6 @@ asn1.js@^5.2.0:
minimalistic-assert "^1.0.0"
safer-buffer "^2.1.0"

asn1@0.2.3:
version "0.2.3"
resolved "https://registry.npmjs.org/asn1/-/asn1-0.2.3.tgz#dac8787713c9966849fc8180777ebe9c1ddf3b86"
integrity sha1-2sh4dxPJlmhJ/IGAd36+nB3fO4Y=

asn1@~0.2.3:
version "0.2.4"
resolved "https://registry.npmjs.org/asn1/-/asn1-0.2.4.tgz#8d2475dfab553bb33e77b54e59e880bb8ce23136"
Expand Down Expand Up @@ -3033,11 +2999,6 @@ base64-js@^1.0.2:
resolved "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a"
integrity sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==

base64url@^3.0.0, base64url@^3.0.1:
version "3.0.1"
resolved "https://registry.npmjs.org/base64url/-/base64url-3.0.1.tgz#6399d572e2bc3f90a9a8b22d5dbb0a32d33f788d"
integrity sha512-ir1UPr3dkwexU7FdV8qBBbNDRUhMmIekYMFZfi+C/sLNnRESKPl23nB9b2pltqfOQNnGzsDdId90AEtG5tCx4A==

base@^0.11.1:
version "0.11.2"
resolved "https://registry.npmjs.org/base/-/base-0.11.2.tgz#7bde5ced145b6d551a90db87f83c558b4eb48a8f"
Expand Down Expand Up @@ -4374,7 +4335,7 @@ electron-to-chromium@^1.3.47:
resolved "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.280.tgz#5f8950c8329e3e11b59c705fd59b4b8d9b3de5b9"
integrity sha512-qYWNMjKLEfQAWZF2Sarvo+ahigu0EArnpCFSoUuZJS3W5wIeVfeEvsgmT2mgIrieQkeQ0+xFmykK3nx2ezekPQ==

elliptic@^6.4.0, elliptic@^6.4.1, elliptic@^6.5.0, elliptic@^6.5.3:
elliptic@^6.4.1, elliptic@^6.5.0, elliptic@^6.5.3:
version "6.5.4"
resolved "https://registry.npmjs.org/elliptic/-/elliptic-6.5.4.tgz#da37cebd31e79a1367e941b592ed1fbebd58abbb"
integrity sha512-iLhC6ULemrljPZb+QutR5TQGB+pdW6KGD5RSegS+8sorOZT+rdQFbsQFJgvN3eRqNALqJer4oQ16YvJHlU8hzQ==
Expand Down Expand Up @@ -7993,13 +7954,6 @@ node-pre-gyp@^0.12.0:
semver "^5.3.0"
tar "^4"

node-rsa@^0.4.0:
version "0.4.2"
resolved "https://registry.npmjs.org/node-rsa/-/node-rsa-0.4.2.tgz#d6391729ec16a830ed5a38042b3157d2d5d72530"
integrity sha1-1jkXKewWqDDtWjgEKzFX0tXXJTA=
dependencies:
asn1 "0.2.3"

"nopt@2 || 3":
version "3.0.6"
resolved "https://registry.npmjs.org/nopt/-/nopt-3.0.6.tgz#c6465dbf08abcd4db359317f79ac68a646b28ff9"
Expand Down Expand Up @@ -10435,11 +10389,6 @@ test-exclude@^4.2.1:
read-pkg-up "^1.0.1"
require-main-filename "^1.0.1"

text-encoding@^0.6.1:
version "0.6.4"
resolved "https://registry.npmjs.org/text-encoding/-/text-encoding-0.6.4.tgz#e399a982257a276dae428bb92845cb71bdc26d19"
integrity sha1-45mpgiV6J22uQou5KEXLcb3CbRk=

text-extensions@^2.0.0:
version "2.0.0"
resolved "https://registry.npmjs.org/text-extensions/-/text-extensions-2.0.0.tgz#43eabd1b495482fae4a2bf65e5f56c29f69220f6"
Expand Down