fix: fix buffer types

This commit is contained in:
Justin Starry
2021-03-15 10:42:53 +08:00
committed by Justin Starry
parent a5c840e672
commit 3ea23fe736
4 changed files with 14 additions and 6 deletions

View File

@ -183,13 +183,20 @@ export class Secp256k1Program {
static createInstructionWithPrivateKey(
params: CreateSecp256k1InstructionWithPrivateKeyParams,
): TransactionInstruction {
const {privateKey, message} = params;
const {privateKey: pkey, message} = params;
assert(
privateKey.length === PRIVATE_KEY_BYTES,
`Private key must be ${PRIVATE_KEY_BYTES} bytes but received ${privateKey.length} bytes`,
pkey.length === PRIVATE_KEY_BYTES,
`Private key must be ${PRIVATE_KEY_BYTES} bytes but received ${pkey.length} bytes`,
);
let privateKey;
if (Array.isArray(pkey)) {
privateKey = Uint8Array.from(pkey);
} else {
privateKey = pkey;
}
try {
const publicKey = publicKeyCreate(privateKey, false).slice(1); // throw away leading byte
const messageHash = Buffer.from(