@@ -76,6 +76,7 @@ import {
7676 bytesToHex ,
7777 fromUtf8 ,
7878 hexToBytes ,
79+ isUint8Array ,
7980 numberToHex ,
8081 randomBytes ,
8182 sha3Raw ,
@@ -126,7 +127,7 @@ export const parseAndValidatePrivateKey = (data: Bytes, ignoreLength?: boolean):
126127 }
127128
128129 try {
129- privateKeyUint8Array = data instanceof Uint8Array ? data : bytesToUint8Array ( data ) ;
130+ privateKeyUint8Array = isUint8Array ( data ) ? ( data ) : bytesToUint8Array ( data ) ;
130131 } catch {
131132 throw new InvalidPrivateKeyError ( ) ;
132133 }
@@ -406,7 +407,7 @@ export const recover = (
406407 const V_INDEX = 130 ; // r = first 32 bytes, s = second 32 bytes, v = last byte of signature
407408 const hashedMessage = prefixedOrR ? data : hashMessage ( data ) ;
408409
409- let v = parseInt ( signatureOrV . substring ( V_INDEX ) , 16 ) ; // 0x + r + s + v
410+ let v = parseInt ( signatureOrV . substring ( V_INDEX ) , 16 ) ; // 0x + r + s + v
410411 if ( v > 26 ) {
411412 v -= 27 ;
412413 }
@@ -421,7 +422,7 @@ export const recover = (
421422 const address = toChecksumAddress ( `0x${ publicHash . slice ( - 40 ) } ` ) ;
422423
423424 return address ;
424- } ;
425+ } ; ;
425426
426427/**
427428 * Get the ethereum Address from a private key
@@ -456,7 +457,7 @@ export const privateKeyToAddress = (privateKey: Bytes): string => {
456457 * Get the public key from a private key
457458 *
458459 * @param privateKey - String or Uint8Array of 32 bytes
459- * @param isCompressed - if true, will generate a 33 byte compressed public key instead of a 65 byte public key
460+ * @param isCompressed - if true, will generate a 33 byte compressed public key instead of a 65 byte public key
460461 * @returns The public key
461462 * @example
462463 * ```ts
@@ -465,7 +466,7 @@ export const privateKeyToAddress = (privateKey: Bytes): string => {
465466 * > "0x42beb65f179720abaa3ec9a70a539629cbbc5ec65bb57e7fc78977796837e537662dd17042e6449dc843c281067a4d6d8d1a1775a13c41901670d5de7ee6503a" // uncompressed public key
466467 * ```
467468 */
468- export const privateKeyToPublicKey = ( privateKey : Bytes , isCompressed : boolean ) : string => {
469+ export const privateKeyToPublicKey = ( privateKey : Bytes , isCompressed : boolean ) : string => {
469470 const privateKeyUint8Array = parseAndValidatePrivateKey ( privateKey ) ;
470471
471472 // Get public key from private key in compressed format
@@ -562,7 +563,7 @@ export const encrypt = async (
562563 salt = randomBytes ( 32 ) ;
563564 }
564565
565- if ( ! ( isString ( password ) || password instanceof Uint8Array ) ) {
566+ if ( ! ( isString ( password ) || isUint8Array ( password ) ) ) {
566567 throw new InvalidPasswordError ( ) ;
567568 }
568569
0 commit comments