fix: fix buffer types
This commit is contained in:
		
				
					committed by
					
						
						Justin Starry
					
				
			
			
				
	
			
			
			
						parent
						
							a5c840e672
						
					
				
				
					commit
					3ea23fe736
				
			@@ -38,6 +38,6 @@ export class Account {
 | 
			
		||||
   * The **unencrypted** secret key for this account
 | 
			
		||||
   */
 | 
			
		||||
  get secretKey(): Buffer {
 | 
			
		||||
    return this._keypair.secretKey;
 | 
			
		||||
    return toBuffer(this._keypair.secretKey);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -113,7 +113,7 @@ export class PublicKey {
 | 
			
		||||
      Buffer.from('ProgramDerivedAddress'),
 | 
			
		||||
    ]);
 | 
			
		||||
    let hash = await sha256(new Uint8Array(buffer));
 | 
			
		||||
    let publicKeyBytes = new BN(hash, 16).toArray(null, 32);
 | 
			
		||||
    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`);
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -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(
 | 
			
		||||
 
 | 
			
		||||
@@ -11,6 +11,7 @@ import {PublicKey} from './publickey';
 | 
			
		||||
import {Account} from './account';
 | 
			
		||||
import * as shortvec from './util/shortvec-encoding';
 | 
			
		||||
import type {Blockhash} from './blockhash';
 | 
			
		||||
import {toBuffer} from './util/to-buffer';
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @typedef {string} TransactionSignature
 | 
			
		||||
@@ -522,7 +523,7 @@ export class Transaction {
 | 
			
		||||
    const signData = message.serialize();
 | 
			
		||||
    signers.forEach(signer => {
 | 
			
		||||
      const signature = nacl.sign.detached(signData, signer.secretKey);
 | 
			
		||||
      this._addSignature(signer.publicKey, signature);
 | 
			
		||||
      this._addSignature(signer.publicKey, toBuffer(signature));
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user