feat: improve esm compatibility (#21373)

This commit is contained in:
Vladimir Guguiev 2021-11-24 15:41:37 +01:00 committed by GitHub
parent c68a11f715
commit 1aebe655b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 7 deletions

View File

@ -1,4 +1,4 @@
import * as nacl from 'tweetnacl';
import nacl from 'tweetnacl';
import type {SignKeyPair as KeyPair} from 'tweetnacl';
import type {Buffer} from 'buffer';

View File

@ -1,4 +1,4 @@
import * as nacl from 'tweetnacl';
import nacl from 'tweetnacl';
import {PublicKey} from './publickey';

View File

@ -1,7 +1,7 @@
import {Buffer} from 'buffer';
import * as BufferLayout from '@solana/buffer-layout';
import secp256k1 from 'secp256k1';
import {keccak_256} from 'js-sha3';
import sha3 from 'js-sha3';
import {PublicKey} from './publickey';
import {TransactionInstruction} from './transaction';
@ -86,9 +86,9 @@ export class Secp256k1Program {
);
try {
return Buffer.from(keccak_256.update(toBuffer(publicKey)).digest()).slice(
-ETHEREUM_ADDRESS_BYTES,
);
return Buffer.from(
sha3.keccak_256.update(toBuffer(publicKey)).digest(),
).slice(-ETHEREUM_ADDRESS_BYTES);
} catch (error) {
throw new Error(`Error constructing Ethereum address: ${error}`);
}
@ -197,7 +197,7 @@ export class Secp256k1Program {
const privateKey = toBuffer(pkey);
const publicKey = publicKeyCreate(privateKey, false).slice(1); // throw away leading byte
const messageHash = Buffer.from(
keccak_256.update(toBuffer(message)).digest(),
sha3.keccak_256.update(toBuffer(message)).digest(),
);
const {signature, recid: recoveryId} = ecdsaSign(messageHash, privateKey);