Update to secp356k1 version 4.0.1

Also update new Buffer -> Buffer.from and fix solhint config format
pull/242/head
Wil Wade 5 years ago committed by Wil Wade
parent f670bc2fe5
commit 34d4542c2f
No known key found for this signature in database
GPG Key ID: E4E03A24ABE7504A
  1. 4
      .solhint.json
  2. 10
      dist/es/cipher.js
  3. 10
      dist/es/decrypt-with-private-key.js
  4. 2
      dist/es/encrypt-with-public-key.js
  5. 4
      dist/es/hex.js
  6. 11
      dist/es/public-key.js
  7. 6
      dist/es/recover-public-key.js
  8. 2
      dist/es/sign-transaction.js
  9. 8
      dist/es/sign.js
  10. 8
      dist/es/util.js
  11. 10
      dist/lib/cipher.js
  12. 10
      dist/lib/decrypt-with-private-key.js
  13. 2
      dist/lib/encrypt-with-public-key.js
  14. 4
      dist/lib/hex.js
  15. 12
      dist/lib/public-key.js
  16. 2
      dist/lib/recover-public-key.js
  17. 2
      dist/lib/sign-transaction.js
  18. 6
      dist/lib/sign.js
  19. 10
      dist/lib/util.js
  20. 2
      package.json
  21. 10
      src/cipher.js
  22. 10
      src/decrypt-with-private-key.js
  23. 4
      src/encrypt-with-public-key.js
  24. 4
      src/hex.js
  25. 22
      src/public-key.js
  26. 14
      src/recover-public-key.js
  27. 2
      src/sign-transaction.js
  28. 10
      src/sign.js
  29. 8
      src/util.js
  30. 2
      test/unit.test.js

@ -1,7 +1,7 @@
{
"extends": "solhint:default",
"rules": {
"func-order": false,
"not-rely-on-time": false
"func-order": "off",
"not-rely-on-time": "off"
}
}

10
dist/es/cipher.js vendored

@ -6,10 +6,10 @@ export function stringify(cipher) {
// use compressed key because it's smaller
var compressedKey = compress(cipher.ephemPublicKey);
var ret = Buffer.concat([new Buffer(cipher.iv, 'hex'), // 16bit
new Buffer(compressedKey, 'hex'), // 33bit
new Buffer(cipher.mac, 'hex'), // 32bit
new Buffer(cipher.ciphertext, 'hex') // var bit
var ret = Buffer.concat([Buffer.from(cipher.iv, 'hex'), // 16bit
Buffer.from(compressedKey, 'hex'), // 33bit
Buffer.from(cipher.mac, 'hex'), // 32bit
Buffer.from(cipher.ciphertext, 'hex') // var bit
]);
return ret.toString('hex');
@ -18,7 +18,7 @@ export function stringify(cipher) {
export function parse(str) {
if (typeof str !== 'string') return str;
var buf = new Buffer(str, 'hex');
var buf = Buffer.from(str, 'hex');
var ret = {
iv: buf.toString('hex', 0, 16),

@ -10,13 +10,13 @@ export default function decryptWithPrivateKey(privateKey, encrypted) {
var twoStripped = removeTrailing0x(privateKey);
var encryptedBuffer = {
iv: new Buffer(encrypted.iv, 'hex'),
ephemPublicKey: new Buffer(encrypted.ephemPublicKey, 'hex'),
ciphertext: new Buffer(encrypted.ciphertext, 'hex'),
mac: new Buffer(encrypted.mac, 'hex')
iv: Buffer.from(encrypted.iv, 'hex'),
ephemPublicKey: Buffer.from(encrypted.ephemPublicKey, 'hex'),
ciphertext: Buffer.from(encrypted.ciphertext, 'hex'),
mac: Buffer.from(encrypted.mac, 'hex')
};
return decrypt(new Buffer(twoStripped, 'hex'), encryptedBuffer).then(function (decryptedBuffer) {
return decrypt(Buffer.from(twoStripped, 'hex'), encryptedBuffer).then(function (decryptedBuffer) {
return decryptedBuffer.toString();
});
}

@ -9,7 +9,7 @@ export default function encryptWithPublicKey(publicKey, message) {
// re-add the compression-flag
var pubString = '04' + publicKey;
return encrypt(new Buffer(pubString, 'hex'), Buffer(message)).then(function (encryptedBuffers) {
return encrypt(Buffer.from(pubString, 'hex'), Buffer.from(message)).then(function (encryptedBuffers) {
var encrypted = {
iv: encryptedBuffers.iv.toString('hex'),
ephemPublicKey: encryptedBuffers.ephemPublicKey.toString('hex'),

4
dist/es/hex.js vendored

@ -12,7 +12,7 @@ export function compress(hex) {
hex = removeTrailing0x(hex);
// if base64:true, we use our own function because it results in a smaller output
if (base64 === true) return new Buffer(hex, 'hex').toString('base64');
if (base64 === true) return Buffer.from(hex, 'hex').toString('base64');
var string = '';
while (hex.length % 4 != 0) {
@ -32,7 +32,7 @@ export function decompress(compressedString) {
// if base64:true, we use our own function because it results in a smaller output
if (base64 === true) {
var ret = new Buffer(compressedString, 'base64').toString('hex');
var ret = Buffer.from(compressedString, 'base64').toString('hex');
return addTrailing0x(ret);
}

@ -1,22 +1,23 @@
import { publicKeyConvert } from 'secp256k1';
import { pubToAddress, toChecksumAddress } from 'ethereumjs-util';
import { hexToUnit8Array, uint8ArrayToHex } from './util';
export function compress(startsWith04) {
// add trailing 04 if not done before
var testBuffer = new Buffer(startsWith04, 'hex');
var testBuffer = Buffer.from(startsWith04, 'hex');
if (testBuffer.length === 64) startsWith04 = '04' + startsWith04;
return publicKeyConvert(new Buffer(startsWith04, 'hex'), true).toString('hex');
return uint8ArrayToHex(publicKeyConvert(hexToUnit8Array(startsWith04), true));
}
export function decompress(startsWith02Or03) {
// if already decompressed an not has trailing 04
var testBuffer = new Buffer(startsWith02Or03, 'hex');
var testBuffer = Buffer.from(startsWith02Or03, 'hex');
if (testBuffer.length === 64) startsWith02Or03 = '04' + startsWith02Or03;
var decompressed = publicKeyConvert(new Buffer(startsWith02Or03, 'hex'), false).toString('hex');
var decompressed = uint8ArrayToHex(publicKeyConvert(hexToUnit8Array(startsWith02Or03), false));
// remove trailing 04
decompressed = decompressed.substring(2);
@ -33,7 +34,7 @@ export function toAddress(publicKey) {
// normalize key
publicKey = decompress(publicKey);
var addressBuffer = pubToAddress(new Buffer(publicKey, 'hex'));
var addressBuffer = pubToAddress(Buffer.from(publicKey, 'hex'));
var checkSumAdress = toChecksumAddress(addressBuffer.toString('hex'));
return checkSumAdress;
}

@ -1,5 +1,5 @@
import { recover } from 'secp256k1';
import { removeTrailing0x } from './util';
import { ecdsaRecover } from 'secp256k1';
import { removeTrailing0x, hexToUnit8Array, uint8ArrayToHex } from './util';
/**
* returns the publicKey for the privateKey with which the messageHash was signed
@ -16,7 +16,7 @@ export default function recoverPublicKey(signature, hash) {
var recoveryNumber = vValue === '1c' ? 1 : 0;
var pubKey = recover(new Buffer(removeTrailing0x(hash), 'hex'), new Buffer(sigOnly, 'hex'), recoveryNumber, false).toString('hex');
var pubKey = uint8ArrayToHex(ecdsaRecover(hexToUnit8Array(sigOnly), recoveryNumber, hexToUnit8Array(removeTrailing0x(hash)), false));
// remove trailing '04'
pubKey = pubKey.slice(2);

@ -9,7 +9,7 @@ export default function signTransaction(rawTx, privateKey) {
var address = addressByPublicKey(publicKey);
if (address != rawTx.from) throw new Error('EthCrypto.signTransaction(): rawTx.from does not match the address of the privateKey');
var privateKeyBuffer = new Buffer(privateKey.replace(/^.{2}/g, ''), 'hex');
var privateKeyBuffer = Buffer.from(privateKey.replace(/^.{2}/g, ''), 'hex');
var tx = new Transaction(rawTx);
tx.sign(privateKeyBuffer);

8
dist/es/sign.js vendored

@ -1,4 +1,4 @@
import { sign as secp256k1_sign } from 'secp256k1';
import { ecdsaSign as secp256k1_sign } from 'secp256k1';
import { addTrailing0x, removeTrailing0x } from './util';
/**
@ -12,10 +12,10 @@ export default function sign(privateKey, hash) {
hash = addTrailing0x(hash);
if (hash.length !== 66) throw new Error('EthCrypto.sign(): Can only sign hashes, given: ' + hash);
var sigObj = secp256k1_sign(new Buffer(removeTrailing0x(hash), 'hex'), new Buffer(removeTrailing0x(privateKey), 'hex'));
var sigObj = secp256k1_sign(new Uint8Array(Buffer.from(removeTrailing0x(hash), 'hex')), new Uint8Array(Buffer.from(removeTrailing0x(privateKey), 'hex')));
var recoveryId = sigObj.recovery === 1 ? '1c' : '1b';
var recoveryId = sigObj.recid === 1 ? '1c' : '1b';
var newSignature = '0x' + sigObj.signature.toString('hex') + recoveryId;
var newSignature = '0x' + Buffer.from(sigObj.signature).toString('hex') + recoveryId;
return newSignature;
}

8
dist/es/util.js vendored

@ -5,3 +5,11 @@ export function removeTrailing0x(str) {
export function addTrailing0x(str) {
if (!str.startsWith('0x')) return '0x' + str;else return str;
}
export function uint8ArrayToHex(arr) {
return Buffer.from(arr).toString('hex');
}
export function hexToUnit8Array(str) {
return new Uint8Array(Buffer.from(str, 'hex'));
}

10
dist/lib/cipher.js vendored

@ -14,10 +14,10 @@ function stringify(cipher) {
// use compressed key because it's smaller
var compressedKey = (0, _publicKey.compress)(cipher.ephemPublicKey);
var ret = Buffer.concat([new Buffer(cipher.iv, 'hex'), // 16bit
new Buffer(compressedKey, 'hex'), // 33bit
new Buffer(cipher.mac, 'hex'), // 32bit
new Buffer(cipher.ciphertext, 'hex') // var bit
var ret = Buffer.concat([Buffer.from(cipher.iv, 'hex'), // 16bit
Buffer.from(compressedKey, 'hex'), // 33bit
Buffer.from(cipher.mac, 'hex'), // 32bit
Buffer.from(cipher.ciphertext, 'hex') // var bit
]);
return ret.toString('hex');
@ -26,7 +26,7 @@ function stringify(cipher) {
function parse(str) {
if (typeof str !== 'string') return str;
var buf = new Buffer(str, 'hex');
var buf = Buffer.from(str, 'hex');
var ret = {
iv: buf.toString('hex', 0, 16),

@ -19,13 +19,13 @@ function decryptWithPrivateKey(privateKey, encrypted) {
var twoStripped = (0, _util.removeTrailing0x)(privateKey);
var encryptedBuffer = {
iv: new Buffer(encrypted.iv, 'hex'),
ephemPublicKey: new Buffer(encrypted.ephemPublicKey, 'hex'),
ciphertext: new Buffer(encrypted.ciphertext, 'hex'),
mac: new Buffer(encrypted.mac, 'hex')
iv: Buffer.from(encrypted.iv, 'hex'),
ephemPublicKey: Buffer.from(encrypted.ephemPublicKey, 'hex'),
ciphertext: Buffer.from(encrypted.ciphertext, 'hex'),
mac: Buffer.from(encrypted.mac, 'hex')
};
return (0, _eccrypto.decrypt)(new Buffer(twoStripped, 'hex'), encryptedBuffer).then(function (decryptedBuffer) {
return (0, _eccrypto.decrypt)(Buffer.from(twoStripped, 'hex'), encryptedBuffer).then(function (decryptedBuffer) {
return decryptedBuffer.toString();
});
}

@ -17,7 +17,7 @@ function encryptWithPublicKey(publicKey, message) {
// re-add the compression-flag
var pubString = '04' + publicKey;
return (0, _eccrypto.encrypt)(new Buffer(pubString, 'hex'), Buffer(message)).then(function (encryptedBuffers) {
return (0, _eccrypto.encrypt)(Buffer.from(pubString, 'hex'), Buffer.from(message)).then(function (encryptedBuffers) {
var encrypted = {
iv: encryptedBuffers.iv.toString('hex'),
ephemPublicKey: encryptedBuffers.ephemPublicKey.toString('hex'),

4
dist/lib/hex.js vendored

@ -14,7 +14,7 @@ function compress(hex) {
hex = (0, _util.removeTrailing0x)(hex);
// if base64:true, we use our own function because it results in a smaller output
if (base64 === true) return new Buffer(hex, 'hex').toString('base64');
if (base64 === true) return Buffer.from(hex, 'hex').toString('base64');
var string = '';
while (hex.length % 4 != 0) {
@ -38,7 +38,7 @@ function decompress(compressedString) {
// if base64:true, we use our own function because it results in a smaller output
if (base64 === true) {
var ret = new Buffer(compressedString, 'base64').toString('hex');
var ret = Buffer.from(compressedString, 'base64').toString('hex');
return (0, _util.addTrailing0x)(ret);
}

@ -11,22 +11,24 @@ var _secp256k = require('secp256k1');
var _ethereumjsUtil = require('ethereumjs-util');
var _util = require('./util');
function compress(startsWith04) {
// add trailing 04 if not done before
var testBuffer = new Buffer(startsWith04, 'hex');
var testBuffer = Buffer.from(startsWith04, 'hex');
if (testBuffer.length === 64) startsWith04 = '04' + startsWith04;
return (0, _secp256k.publicKeyConvert)(new Buffer(startsWith04, 'hex'), true).toString('hex');
return (0, _util.uint8ArrayToHex)((0, _secp256k.publicKeyConvert)((0, _util.hexToUnit8Array)(startsWith04), true));
}
function decompress(startsWith02Or03) {
// if already decompressed an not has trailing 04
var testBuffer = new Buffer(startsWith02Or03, 'hex');
var testBuffer = Buffer.from(startsWith02Or03, 'hex');
if (testBuffer.length === 64) startsWith02Or03 = '04' + startsWith02Or03;
var decompressed = (0, _secp256k.publicKeyConvert)(new Buffer(startsWith02Or03, 'hex'), false).toString('hex');
var decompressed = (0, _util.uint8ArrayToHex)((0, _secp256k.publicKeyConvert)((0, _util.hexToUnit8Array)(startsWith02Or03), false));
// remove trailing 04
decompressed = decompressed.substring(2);
@ -43,7 +45,7 @@ function toAddress(publicKey) {
// normalize key
publicKey = decompress(publicKey);
var addressBuffer = (0, _ethereumjsUtil.pubToAddress)(new Buffer(publicKey, 'hex'));
var addressBuffer = (0, _ethereumjsUtil.pubToAddress)(Buffer.from(publicKey, 'hex'));
var checkSumAdress = (0, _ethereumjsUtil.toChecksumAddress)(addressBuffer.toString('hex'));
return checkSumAdress;
}

@ -24,7 +24,7 @@ function recoverPublicKey(signature, hash) {
var recoveryNumber = vValue === '1c' ? 1 : 0;
var pubKey = (0, _secp256k.recover)(new Buffer((0, _util.removeTrailing0x)(hash), 'hex'), new Buffer(sigOnly, 'hex'), recoveryNumber, false).toString('hex');
var pubKey = (0, _util.uint8ArrayToHex)((0, _secp256k.ecdsaRecover)((0, _util.hexToUnit8Array)(sigOnly), recoveryNumber, (0, _util.hexToUnit8Array)((0, _util.removeTrailing0x)(hash)), false));
// remove trailing '04'
pubKey = pubKey.slice(2);

@ -22,7 +22,7 @@ function signTransaction(rawTx, privateKey) {
var address = (0, _publicKey.toAddress)(publicKey);
if (address != rawTx.from) throw new Error('EthCrypto.signTransaction(): rawTx.from does not match the address of the privateKey');
var privateKeyBuffer = new Buffer(privateKey.replace(/^.{2}/g, ''), 'hex');
var privateKeyBuffer = Buffer.from(privateKey.replace(/^.{2}/g, ''), 'hex');
var tx = new _ethereumjsTx.Transaction(rawTx);
tx.sign(privateKeyBuffer);

6
dist/lib/sign.js vendored

@ -20,10 +20,10 @@ function sign(privateKey, hash) {
hash = (0, _util.addTrailing0x)(hash);
if (hash.length !== 66) throw new Error('EthCrypto.sign(): Can only sign hashes, given: ' + hash);
var sigObj = (0, _secp256k.sign)(new Buffer((0, _util.removeTrailing0x)(hash), 'hex'), new Buffer((0, _util.removeTrailing0x)(privateKey), 'hex'));
var sigObj = (0, _secp256k.ecdsaSign)(new Uint8Array(Buffer.from((0, _util.removeTrailing0x)(hash), 'hex')), new Uint8Array(Buffer.from((0, _util.removeTrailing0x)(privateKey), 'hex')));
var recoveryId = sigObj.recovery === 1 ? '1c' : '1b';
var recoveryId = sigObj.recid === 1 ? '1c' : '1b';
var newSignature = '0x' + sigObj.signature.toString('hex') + recoveryId;
var newSignature = '0x' + Buffer.from(sigObj.signature).toString('hex') + recoveryId;
return newSignature;
}

10
dist/lib/util.js vendored

@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
});
exports.removeTrailing0x = removeTrailing0x;
exports.addTrailing0x = addTrailing0x;
exports.uint8ArrayToHex = uint8ArrayToHex;
exports.hexToUnit8Array = hexToUnit8Array;
function removeTrailing0x(str) {
if (str.startsWith('0x')) return str.substring(2);else return str;
}
@ -12,3 +14,11 @@ function removeTrailing0x(str) {
function addTrailing0x(str) {
if (!str.startsWith('0x')) return '0x' + str;else return str;
}
function uint8ArrayToHex(arr) {
return Buffer.from(arr).toString('hex');
}
function hexToUnit8Array(str) {
return new Uint8Array(Buffer.from(str, 'hex'));
}

@ -115,6 +115,6 @@
"ethereumjs-tx": "2.1.2",
"ethereumjs-util": "6.2.0",
"ethers": "4.0.47",
"secp256k1": "3.8.0"
"secp256k1": "4.0.1"
}
}

@ -10,10 +10,10 @@ export function stringify(cipher) {
const compressedKey = compress(cipher.ephemPublicKey);
const ret = Buffer.concat([
new Buffer(cipher.iv, 'hex'), // 16bit
new Buffer(compressedKey, 'hex'), // 33bit
new Buffer(cipher.mac, 'hex'), // 32bit
new Buffer(cipher.ciphertext, 'hex') // var bit
Buffer.from(cipher.iv, 'hex'), // 16bit
Buffer.from(compressedKey, 'hex'), // 33bit
Buffer.from(cipher.mac, 'hex'), // 32bit
Buffer.from(cipher.ciphertext, 'hex') // var bit
]);
return ret.toString('hex');
@ -25,7 +25,7 @@ export function parse(str) {
if (typeof str !== 'string')
return str;
const buf = new Buffer(str, 'hex');
const buf = Buffer.from(str, 'hex');
const ret = {
iv: buf.toString('hex', 0, 16),

@ -16,15 +16,15 @@ export default function decryptWithPrivateKey(privateKey, encrypted) {
const twoStripped = removeTrailing0x(privateKey);
const encryptedBuffer = {
iv: new Buffer(encrypted.iv, 'hex'),
ephemPublicKey: new Buffer(encrypted.ephemPublicKey, 'hex'),
ciphertext: new Buffer(encrypted.ciphertext, 'hex'),
mac: new Buffer(encrypted.mac, 'hex')
iv: Buffer.from(encrypted.iv, 'hex'),
ephemPublicKey: Buffer.from(encrypted.ephemPublicKey, 'hex'),
ciphertext: Buffer.from(encrypted.ciphertext, 'hex'),
mac: Buffer.from(encrypted.mac, 'hex')
};
return decrypt(
new Buffer(twoStripped, 'hex'),
Buffer.from(twoStripped, 'hex'),
encryptedBuffer
).then(decryptedBuffer => decryptedBuffer.toString());
}

@ -15,8 +15,8 @@ export default function encryptWithPublicKey(publicKey, message) {
return encrypt(
new Buffer(pubString, 'hex'),
Buffer(message)
Buffer.from(pubString, 'hex'),
Buffer.from(message)
).then(encryptedBuffers => {
const encrypted = {
iv: encryptedBuffers.iv.toString('hex'),

@ -14,7 +14,7 @@ export function compress(hex, base64 = false) {
// if base64:true, we use our own function because it results in a smaller output
if (base64 === true)
return new Buffer(hex, 'hex').toString('base64');
return Buffer.from(hex, 'hex').toString('base64');
let string = '';
while (hex.length % 4 != 0) { // we need it to be multiple of 4
@ -31,7 +31,7 @@ export function decompress(compressedString, base64 = false) {
// if base64:true, we use our own function because it results in a smaller output
if (base64 === true) {
const ret = new Buffer(compressedString, 'base64').toString('hex');
const ret = Buffer.from(compressedString, 'base64').toString('hex');
return addTrailing0x(ret);
}

@ -5,30 +5,34 @@ import {
pubToAddress,
toChecksumAddress
} from 'ethereumjs-util';
import {
hexToUnit8Array,
uint8ArrayToHex
} from './util';
export function compress(startsWith04) {
// add trailing 04 if not done before
const testBuffer = new Buffer(startsWith04, 'hex');
const testBuffer = Buffer.from(startsWith04, 'hex');
if (testBuffer.length === 64) startsWith04 = '04' + startsWith04;
return publicKeyConvert(
new Buffer(startsWith04, 'hex'),
return uint8ArrayToHex(publicKeyConvert(
hexToUnit8Array(startsWith04),
true
).toString('hex');
));
}
export function decompress(startsWith02Or03) {
// if already decompressed an not has trailing 04
const testBuffer = new Buffer(startsWith02Or03, 'hex');
const testBuffer = Buffer.from(startsWith02Or03, 'hex');
if (testBuffer.length === 64) startsWith02Or03 = '04' + startsWith02Or03;
let decompressed = publicKeyConvert(
new Buffer(startsWith02Or03, 'hex'),
let decompressed = uint8ArrayToHex(publicKeyConvert(
hexToUnit8Array(startsWith02Or03),
false
).toString('hex');
));
// remove trailing 04
decompressed = decompressed.substring(2);
@ -45,7 +49,7 @@ export function toAddress(publicKey) {
// normalize key
publicKey = decompress(publicKey);
const addressBuffer = pubToAddress(new Buffer(publicKey, 'hex'));
const addressBuffer = pubToAddress(Buffer.from(publicKey, 'hex'));
const checkSumAdress = toChecksumAddress(addressBuffer.toString('hex'));
return checkSumAdress;
}

@ -1,8 +1,10 @@
import {
recover
ecdsaRecover
} from 'secp256k1';
import {
removeTrailing0x
removeTrailing0x,
hexToUnit8Array,
uint8ArrayToHex
} from './util';
@ -21,12 +23,12 @@ export default function recoverPublicKey(signature, hash) {
const recoveryNumber = vValue === '1c' ? 1 : 0;
let pubKey = recover(
new Buffer(removeTrailing0x(hash), 'hex'),
new Buffer(sigOnly, 'hex'),
let pubKey = uint8ArrayToHex(ecdsaRecover(
hexToUnit8Array(sigOnly),
recoveryNumber,
hexToUnit8Array(removeTrailing0x(hash)),
false
).toString('hex');
));
// remove trailing '04'
pubKey = pubKey.slice(2);

@ -15,7 +15,7 @@ export default function signTransaction(
if (address != rawTx.from)
throw new Error('EthCrypto.signTransaction(): rawTx.from does not match the address of the privateKey');
const privateKeyBuffer = new Buffer(privateKey.replace(/^.{2}/g, ''), 'hex');
const privateKeyBuffer = Buffer.from(privateKey.replace(/^.{2}/g, ''), 'hex');
const tx = new Transaction(rawTx);
tx.sign(privateKeyBuffer);

@ -1,5 +1,5 @@
import {
sign as secp256k1_sign
ecdsaSign as secp256k1_sign
} from 'secp256k1';
import {
addTrailing0x,
@ -19,12 +19,12 @@ export default function sign(privateKey, hash) {
throw new Error('EthCrypto.sign(): Can only sign hashes, given: ' + hash);
const sigObj = secp256k1_sign(
new Buffer(removeTrailing0x(hash), 'hex'),
new Buffer(removeTrailing0x(privateKey), 'hex')
new Uint8Array(Buffer.from(removeTrailing0x(hash), 'hex')),
new Uint8Array(Buffer.from(removeTrailing0x(privateKey), 'hex'))
);
const recoveryId = sigObj.recovery === 1 ? '1c' : '1b';
const recoveryId = sigObj.recid === 1 ? '1c' : '1b';
const newSignature = '0x' + sigObj.signature.toString('hex') + recoveryId;
const newSignature = '0x' + Buffer.from(sigObj.signature).toString('hex') + recoveryId;
return newSignature;
}

@ -9,3 +9,11 @@ export function addTrailing0x(str) {
return '0x' + str;
else return str;
}
export function uint8ArrayToHex(arr) {
return Buffer.from(arr).toString('hex');
}
export function hexToUnit8Array(str) {
return new Uint8Array(Buffer.from(str, 'hex'));
}

@ -170,7 +170,7 @@ describe('unit.test.js', () => {
AsyncTestUtil.randomString(12),
message
),
'RangeError'
'Error'
);
});
});

Loading…
Cancel
Save