Skip to content

Commit

Permalink
fix: add crypto-browserify
Browse files Browse the repository at this point in the history
  • Loading branch information
gtsonevv committed Dec 19, 2023
1 parent eac860d commit 0d88bfd
Show file tree
Hide file tree
Showing 3 changed files with 2,009 additions and 2,201 deletions.
3 changes: 2 additions & 1 deletion packages/crypto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"@near-js/utils": "workspace:*",
"bn.js": "5.2.1",
"borsh": "1.0.0",
"@noble/curves": "1.2.0"
"@noble/curves": "1.2.0",
"crypto-browserify": "^3.12.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 { webcrypto } from 'crypto';
import crypto from 'crypto-browserify';

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 = webcrypto.getRandomValues(new Uint8Array(KeySize.SECRET_KEY));
const secretKey = crypto.randomBytes(KeySize.SECRET_KEY);
const publicKey = ed25519.getPublicKey(secretKey);
const extendedSecretKey = new Uint8Array([...secretKey, ...publicKey]);
return new KeyPairEd25519(baseEncode(extendedSecretKey));
Expand Down
Loading

0 comments on commit 0d88bfd

Please sign in to comment.