Skip to content

Commit

Permalink
Dedupe signature splitting
Browse files Browse the repository at this point in the history
  • Loading branch information
sisou committed Jan 5, 2024
1 parent dda1b64 commit 166daa3
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/lib/polygon/PolygonKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,7 @@ class PolygonKey { // eslint-disable-line no-unused-vars
message,
);

const sigR = signature.slice(0, 66); // 0x prefix plus 32 bytes = 66 characters
const sigS = `0x${signature.slice(66, 130)}`; // 32 bytes = 64 characters
const sigV = parseInt(signature.slice(130, 132), 16); // last byte = 2 characters

return { sigR, sigS, sigV };
return this._signatureToParts(signature);
}

/**
Expand Down Expand Up @@ -139,11 +135,7 @@ class PolygonKey { // eslint-disable-line no-unused-vars
message,
);

const sigR = signature.slice(0, 66); // 0x prefix plus 32 bytes = 66 characters
const sigS = `0x${signature.slice(66, 130)}`; // 32 bytes = 64 characters
const sigV = parseInt(signature.slice(130, 132), 16); // last byte = 2 characters

return { sigR, sigS, sigV };
return this._signatureToParts(signature);
}

/**
Expand Down Expand Up @@ -171,6 +163,18 @@ class PolygonKey { // eslint-disable-line no-unused-vars
return this._key;
}

/**
* @param {string} signature
* @returns {{sigR: string, sigS: string, sigV: number}}
*/
_signatureToParts(signature) {
const sigR = signature.slice(0, 66); // 0x prefix plus 32 bytes = 66 characters
const sigS = `0x${signature.slice(66, 130)}`; // 32 bytes = 64 characters
const sigV = parseInt(signature.slice(130, 132), 16); // last byte = 2 characters

return { sigR, sigS, sigV };
}

/**
* @type {string}
*/
Expand Down

0 comments on commit 166daa3

Please sign in to comment.