aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/signature_utils.ts
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-07-08 08:43:31 +0800
committerGitHub <noreply@github.com>2017-07-08 08:43:31 +0800
commit6b80134f481d7496884d12d2a76fa8cf4f6f2875 (patch)
tree1ecd8433cda09ddfd8e6a6dbe0c0fe1adea4b157 /src/utils/signature_utils.ts
parentd5b4032b258c41dad611c6f4ebf28f42e4e6ba98 (diff)
parent68120ad1da1ee72ee11e1286698abc699c80e2cf (diff)
downloaddexon-sol-tools-6b80134f481d7496884d12d2a76fa8cf4f6f2875.tar
dexon-sol-tools-6b80134f481d7496884d12d2a76fa8cf4f6f2875.tar.gz
dexon-sol-tools-6b80134f481d7496884d12d2a76fa8cf4f6f2875.tar.bz2
dexon-sol-tools-6b80134f481d7496884d12d2a76fa8cf4f6f2875.tar.lz
dexon-sol-tools-6b80134f481d7496884d12d2a76fa8cf4f6f2875.tar.xz
dexon-sol-tools-6b80134f481d7496884d12d2a76fa8cf4f6f2875.tar.zst
dexon-sol-tools-6b80134f481d7496884d12d2a76fa8cf4f6f2875.zip
Merge pull request #100 from 0xProject/improveSignOrder
Improve signOrderHashAsync
Diffstat (limited to 'src/utils/signature_utils.ts')
-rw-r--r--src/utils/signature_utils.ts29
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;
+ },
+};