From 68120ad1da1ee72ee11e1286698abc699c80e2cf Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 7 Jul 2017 14:21:47 -0700 Subject: Move private helper methods into signatureUtils so that they don't show up in the ZeroEx classes auto-complete list --- src/utils/signature_utils.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/utils/signature_utils.ts (limited to 'src/utils') diff --git a/src/utils/signature_utils.ts b/src/utils/signature_utils.ts new file mode 100644 index 000000000..b312b5554 --- /dev/null +++ b/src/utils/signature_utils.ts @@ -0,0 +1,29 @@ +import * as ethUtil from 'ethereumjs-util'; +import {ECSignature} from '../types'; + +export const signatureUtils = { + 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; + }, +}; -- cgit v1.2.3