diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-07-08 08:43:52 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-07-08 08:43:52 +0800 |
commit | 305b98ee21bcfa733390b157c187d2ab88e122b2 (patch) | |
tree | 84b6d381d63f046fdc14047195250856c7ef5dae /src/utils | |
parent | 39daf6f963a3abd5086007e38818f3af087e220b (diff) | |
parent | 6b80134f481d7496884d12d2a76fa8cf4f6f2875 (diff) | |
download | dexon-sol-tools-305b98ee21bcfa733390b157c187d2ab88e122b2.tar dexon-sol-tools-305b98ee21bcfa733390b157c187d2ab88e122b2.tar.gz dexon-sol-tools-305b98ee21bcfa733390b157c187d2ab88e122b2.tar.bz2 dexon-sol-tools-305b98ee21bcfa733390b157c187d2ab88e122b2.tar.lz dexon-sol-tools-305b98ee21bcfa733390b157c187d2ab88e122b2.tar.xz dexon-sol-tools-305b98ee21bcfa733390b157c187d2ab88e122b2.tar.zst dexon-sol-tools-305b98ee21bcfa733390b157c187d2ab88e122b2.zip |
Merge branch 'master' of github.com:0xProject/0x.js
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/signature_utils.ts | 29 |
1 files changed, 29 insertions, 0 deletions
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; + }, +}; |