feat: use crypto-hash instead of hasha

This commit is contained in:
Justin Starry
2020-03-16 17:44:12 +08:00
committed by Michael Vines
parent bd7e802e46
commit 402c160ae9
12 changed files with 75 additions and 78 deletions

View File

@@ -2,7 +2,7 @@
import BN from 'bn.js';
import bs58 from 'bs58';
import hasha from 'hasha';
import {sha256} from 'crypto-hash';
/**
* A public key
@@ -80,17 +80,17 @@ export class PublicKey {
/**
* Derive a public key from another key, a seed, and a programId.
*/
static createWithSeed(
static async createWithSeed(
fromPublicKey: PublicKey,
seed: string,
programId: PublicKey,
): PublicKey {
): Promise<PublicKey> {
const buffer = Buffer.concat([
fromPublicKey.toBuffer(),
Buffer.from(seed),
programId.toBuffer(),
]);
const hash = hasha(buffer, {algorithm: 'sha256'});
const hash = await sha256(new Uint8Array(buffer));
return new PublicKey('0x' + hash);
}
}