Skip to content

Commit

Permalink
refactor(core): validate pk earlier in address validation
Browse files Browse the repository at this point in the history
  • Loading branch information
capt-nemo429 committed May 7, 2023
1 parent 0f1ffe5 commit 051387c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/core/src/models/ergoAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,6 @@ export class ErgoAddress {
return false;
}

const script = bytes.subarray(0, bytes.length - CHECKSUM_LENGTH);
const checksum = bytes.subarray(bytes.length - CHECKSUM_LENGTH, bytes.length);
const blakeHash = blake2b256(script);
const calculatedChecksum = blakeHash.subarray(0, CHECKSUM_LENGTH);

if (_getEncodedAddressType(bytes) === AddressType.P2PK) {
const pk = bytes.subarray(1, bytes.length - CHECKSUM_LENGTH);

Expand All @@ -193,6 +188,11 @@ export class ErgoAddress {
}
}

const script = bytes.subarray(0, bytes.length - CHECKSUM_LENGTH);
const checksum = bytes.subarray(bytes.length - CHECKSUM_LENGTH, bytes.length);
const blakeHash = blake2b256(script);
const calculatedChecksum = blakeHash.subarray(0, CHECKSUM_LENGTH);

return areEqual(calculatedChecksum, checksum);
}

Expand Down

0 comments on commit 051387c

Please sign in to comment.