Skip to content

Commit

Permalink
prevent throwing if value is null when checking value.constructor.name
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammad-Altabba committed Oct 6, 2023
1 parent 1eed66d commit 5f195bb
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/web3-eth-accounts/src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const parseAndValidatePrivateKey = (data: Bytes, ignoreLength?: boolean):

try {
privateKeyUint8Array =
data instanceof Uint8Array || data.constructor.name === 'Uint8Array'
data instanceof Uint8Array || data?.constructor?.name === 'Uint8Array'
? (data as Uint8Array)
: bytesToUint8Array(data);
} catch {
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-eth-accounts/src/tx/transactionFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class TransactionFactory {
* @param txOptions - The transaction options
*/
public static fromBlockBodyData(data: Uint8Array | Uint8Array[], txOptions: TxOptions = {}) {
if (data instanceof Uint8Array || data.constructor.name === 'Uint8Array') {
if (data instanceof Uint8Array || data?.constructor?.name === 'Uint8Array') {
return this.fromSerializedData(data as Uint8Array, txOptions);
}
if (Array.isArray(data)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-utils/src/converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export type EtherUnits = keyof typeof ethUnitMap;
export const bytesToUint8Array = (data: Bytes): Uint8Array | never => {
validator.validate(['bytes'], [data]);

if (data instanceof Uint8Array || data.constructor.name === 'Uint8Array') {
if (data instanceof Uint8Array || data?.constructor?.name === 'Uint8Array') {
return data as Uint8Array;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/web3-validator/src/validation/bytes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { isHexStrict } from './string.js';
* checks input if typeof data is valid Uint8Array input
*/
export const isUint8Array = (data: ValidInputTypes) =>
data instanceof Uint8Array || data.constructor.name === 'Uint8Array';
data instanceof Uint8Array || data?.constructor?.name === 'Uint8Array';

export const isBytes = (
value: ValidInputTypes | Uint8Array | number[],
Expand All @@ -35,7 +35,7 @@ export const isBytes = (
typeof value !== 'string' &&
!Array.isArray(value) &&
!(value instanceof Uint8Array) &&
value.constructor.name !== 'Uint8Array'
value?.constructor?.name !== 'Uint8Array'
) {
return false;
}
Expand Down

0 comments on commit 5f195bb

Please sign in to comment.