aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/signature_utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/signature_utils.ts')
-rw-r--r--src/utils/signature_utils.ts44
1 files changed, 0 insertions, 44 deletions
diff --git a/src/utils/signature_utils.ts b/src/utils/signature_utils.ts
deleted file mode 100644
index d066f8bf0..000000000
--- a/src/utils/signature_utils.ts
+++ /dev/null
@@ -1,44 +0,0 @@
-import * as ethUtil from 'ethereumjs-util';
-import {ECSignature} from '../types';
-
-export const signatureUtils = {
- isValidSignature(data: string, signature: ECSignature, signerAddress: string): boolean {
- const dataBuff = ethUtil.toBuffer(data);
- const msgHashBuff = ethUtil.hashPersonalMessage(dataBuff);
- try {
- const pubKey = ethUtil.ecrecover(
- msgHashBuff,
- signature.v,
- ethUtil.toBuffer(signature.r),
- ethUtil.toBuffer(signature.s));
- const retrievedAddress = ethUtil.bufferToHex(ethUtil.pubToAddress(pubKey));
- return retrievedAddress === signerAddress;
- } catch (err) {
- return false;
- }
- },
- parseSignatureHexAsVRS(signatureHex: string): ECSignature {
- const signatureBuffer = ethUtil.toBuffer(signatureHex);
- let v = signatureBuffer[0];
- if (v < 27) {
- v += 27;
- }
- const r = signatureBuffer.slice(1, 33);
- const s = signatureBuffer.slice(33, 65);
- const ecSignature: ECSignature = {
- v,
- r: ethUtil.bufferToHex(r),
- s: ethUtil.bufferToHex(s),
- };
- return ecSignature;
- },
- parseSignatureHexAsRSV(signatureHex: string): ECSignature {
- const {v, r, s} = ethUtil.fromRpcSig(signatureHex);
- const ecSignature: ECSignature = {
- v,
- r: ethUtil.bufferToHex(r),
- s: ethUtil.bufferToHex(s),
- };
- return ecSignature;
- },
-};