fix: replace ethers dependency with @ethersproject/sha2 (#20920)

This commit is contained in:
Johanna Johansson 2021-10-25 11:51:24 -04:00 committed by GitHub
parent 43ea579f63
commit b825390752
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 1105 deletions

1102
web3.js/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -63,13 +63,13 @@
},
"dependencies": {
"@babel/runtime": "^7.12.5",
"@ethersproject/sha2": "^5.5.0",
"@solana/buffer-layout": "^3.0.0",
"bn.js": "^5.0.0",
"borsh": "^0.4.0",
"bs58": "^4.0.1",
"buffer": "6.0.1",
"cross-fetch": "^3.1.4",
"ethers": "^5.5.1",
"jayson": "^3.4.4",
"js-sha3": "^0.8.0",
"rpc-websockets": "^7.4.2",

View File

@ -2,7 +2,7 @@ import BN from 'bn.js';
import bs58 from 'bs58';
import {Buffer} from 'buffer';
import nacl from 'tweetnacl';
import {ethers} from 'ethers';
import {sha256} from '@ethersproject/sha2';
import {Struct, SOLANA_SCHEMA} from './util/borsh-schema';
import {toBuffer} from './util/to-buffer';
@ -131,7 +131,7 @@ export class PublicKey extends Struct {
Buffer.from(seed),
programId.toBuffer(),
]);
const hash = ethers.utils.sha256(new Uint8Array(buffer)).slice(2);
const hash = sha256(new Uint8Array(buffer)).slice(2);
return new PublicKey(Buffer.from(hash, 'hex'));
}
@ -155,7 +155,7 @@ export class PublicKey extends Struct {
programId.toBuffer(),
Buffer.from('ProgramDerivedAddress'),
]);
let hash = ethers.utils.sha256(new Uint8Array(buffer)).slice(2);
let hash = sha256(new Uint8Array(buffer)).slice(2);
let publicKeyBytes = new BN(hash, 16).toArray(undefined, 32);
if (is_on_curve(publicKeyBytes)) {
throw new Error(`Invalid seeds, address must fall off the curve`);