Skip to content

Commit

Permalink
fix: replace @ethersproject/sha2 with @noble/hashes/sha256
Browse files Browse the repository at this point in the history
  • Loading branch information
steveluscher committed Aug 25, 2022
1 parent 2da93bd commit b8a47d0
Show file tree
Hide file tree
Showing 4 changed files with 7,448 additions and 7,593 deletions.
26 changes: 24 additions & 2 deletions web3.js/package-lock.json

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

2 changes: 1 addition & 1 deletion web3.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
},
"dependencies": {
"@babel/runtime": "^7.12.5",
"@ethersproject/sha2": "^5.5.0",
"@noble/hashes": "^1.1.2",
"@solana/buffer-layout": "^4.0.0",
"bigint-buffer": "^1.1.5",
"bn.js": "^5.0.0",
Expand Down
9 changes: 4 additions & 5 deletions web3.js/src/publickey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import BN from 'bn.js';
import bs58 from 'bs58';
import {Buffer} from 'buffer';
import nacl from 'tweetnacl';
import {sha256} from '@ethersproject/sha2';
import {sha256} from '@noble/hashes/sha256';

import {Struct, SOLANA_SCHEMA} from './utils/borsh-schema';
import {toBuffer} from './utils/to-buffer';
Expand Down Expand Up @@ -140,8 +140,8 @@ export class PublicKey extends Struct {
Buffer.from(seed),
programId.toBuffer(),
]);
const hash = sha256(new Uint8Array(buffer)).slice(2);
return new PublicKey(Buffer.from(hash, 'hex'));
const publicKeyBytes = sha256(buffer);
return new PublicKey(publicKeyBytes);
}

/**
Expand All @@ -164,8 +164,7 @@ export class PublicKey extends Struct {
programId.toBuffer(),
Buffer.from('ProgramDerivedAddress'),
]);
let hash = sha256(new Uint8Array(buffer)).slice(2);
let publicKeyBytes = new BN(hash, 16).toArray(undefined, 32);
const publicKeyBytes = sha256(buffer);
if (is_on_curve(publicKeyBytes)) {
throw new Error(`Invalid seeds, address must fall off the curve`);
}
Expand Down
Loading

0 comments on commit b8a47d0

Please sign in to comment.