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
3 changed files with 5 additions and 1105 deletions

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`);