Skip to content

Commit

Permalink
Merge pull request #1222 from LimeChain/randombytes-fix
Browse files Browse the repository at this point in the history
Replace crypto-browserify with randombytes
  • Loading branch information
vikinatora authored Jan 2, 2024
2 parents f2085fe + 3c7de82 commit 6a60afa
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/swift-plums-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@near-js/crypto": minor
---

replaced crypto-browserify with randombytes
2 changes: 1 addition & 1 deletion packages/crypto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"bn.js": "5.2.1",
"borsh": "1.0.0",
"@noble/curves": "1.2.0",
"crypto-browserify": "3.12.0"
"randombytes": "2.1.0"
},
"devDependencies": {
"@types/node": "18.11.18",
Expand Down
4 changes: 2 additions & 2 deletions packages/crypto/src/key_pair_ed25519.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { baseEncode, baseDecode } from '@near-js/utils';
import { ed25519 } from '@noble/curves/ed25519';
import crypto from 'crypto-browserify';
import randombytes from 'randombytes';

import { KeySize, KeyType } from './constants';
import { KeyPairBase, Signature } from './key_pair_base';
Expand Down Expand Up @@ -41,7 +41,7 @@ export class KeyPairEd25519 extends KeyPairBase {
* // returns [SECRET_KEY]
*/
static fromRandom() {
const secretKey = crypto.randomBytes(KeySize.SECRET_KEY);
const secretKey = randombytes(KeySize.SECRET_KEY);
const publicKey = ed25519.getPublicKey(secretKey);
const extendedSecretKey = new Uint8Array([...secretKey, ...publicKey]);
return new KeyPairEd25519(baseEncode(extendedSecretKey));
Expand Down
32 changes: 30 additions & 2 deletions pnpm-lock.yaml

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

0 comments on commit 6a60afa

Please sign in to comment.