Skip to content

Commit 2f30890

Browse files
committed
FIX #2 - verify signature function
1. change publicKey parameter to publicAccount 2. omit "_" from variable names 3. remove "!" from error messages
1 parent 9d1c0d7 commit 2f30890

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

src/model/account/PublicAccount.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,43 +57,39 @@ export class PublicAccount {
5757
/**
5858
* Verify a signature.
5959
*
60-
* @param {string} publicKey - The public key to use for verification.
60+
* @param {PublicAccount} publicAccount - The public account to use for verification.
6161
* @param {string} data - The data to verify.
6262
* @param {string} signature - The signature to verify.
6363
*
6464
* @return {boolean} - True if the signature is valid, false otherwise.
6565
*/
66-
static verifySignature(publicKey: string, data: string, signature: string): boolean {
67-
if (!publicKey || !data || !signature) {
68-
throw new Error('Missing argument !');
69-
}
70-
71-
if (publicKey.length !== 64 && publicKey.length !== 66) {
72-
throw new Error('Not a valid public key');
66+
static verifySignature(publicAccount: PublicAccount, data: string, signature: string): boolean {
67+
if (!publicAccount || !data || !signature) {
68+
throw new Error('Missing argument');
7369
}
7470

7571
if (convert.isHexString(signature)) {
76-
throw new Error('Signature must be hexadecimal only !');
72+
throw new Error('Signature must be hexadecimal only');
7773
}
7874

7975
if (signature.length !== 128) {
80-
throw new Error('Signature length is incorrect !');
76+
throw new Error('Signature length is incorrect');
8177
}
8278

8379
// Convert signature key to Uint8Array
84-
const _signature = convert.hexToUint8(signature);
80+
const convertedSignature = convert.hexToUint8(signature);
8581

86-
let _data;
82+
let convertedData;
8783

8884
// Convert data to hex if data is not hex
8985
if (!convert.isHexString(data)) {
90-
_data = convert.utf8ToHex(data);
86+
convertedData = convert.utf8ToHex(data);
9187
}
9288

9389
// Convert to Uint8Array
94-
_data = convert.hexToUint8(_data);
90+
convertedData = convert.hexToUint8(convertedData);
9591

96-
return KeyPair.verify(publicKey, _data, _signature);
92+
return KeyPair.verify(publicAccount.publicKey, convertedData, convertedSignature);
9793
}
9894

9995
/**

0 commit comments

Comments
 (0)