eth-lib
Advanced tools
Comparing version 0.2.3 to 0.2.4
10
lib/a.js
@@ -1,8 +0,4 @@ | ||
var kek = require("./hash").keccak256; | ||
var abi = require("./abi"); | ||
var data = "0x"; | ||
var r = data; | ||
for (var i = 0; i < 200000; ++i) { | ||
r = kek(r); | ||
}console.log(r); | ||
console.log(abi.encode("bytes", "0xab1299dd36c5ac28d9631112131415161718192200aabbccdd").data); | ||
console.log("0x0000000000000000000000000000000000000000000000000000000000000019ab1299dd36c5ac28d9631112131415161718192200aabbccdd00000000000000"); |
@@ -15,2 +15,3 @@ // type Var = { | ||
var Bytes = require("./bytes"); | ||
var Nat = require("./nat"); | ||
var keccak256s = require("./hash").keccak256s; | ||
@@ -24,3 +25,3 @@ | ||
var nextMul32 = (((length - 1) / 32 | 0) + 1) * 32; | ||
var lengthEncoded = encodeABI("uint256", Nat.fromNumber(length)).data; | ||
var lengthEncoded = encode("uint256", Nat.fromNumber(length)).data; | ||
var bytesEncoded = Bytes.padRight(nextMul32, value); | ||
@@ -27,0 +28,0 @@ return { data: Bytes.concat(lengthEncoded, bytesEncoded), dynamic: true }; |
@@ -50,3 +50,3 @@ var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); | ||
var decodeSignature = function decodeSignature(hex) { | ||
return [Bytes.slice(64, 65, hex), Bytes.slice(0, 32, hex), Bytes.slice(32, 64, hex)]; | ||
return [Bytes.slice(64, Bytes.length(hex), hex), Bytes.slice(0, 32, hex), Bytes.slice(32, 64, hex)]; | ||
}; | ||
@@ -57,3 +57,3 @@ | ||
var signature = secp256k1.keyFromPrivate(new Buffer(privateKey.slice(2), "hex")).sign(new Buffer(hash.slice(2), "hex"), { canonical: true }); | ||
return encodeSignature([Bytes.pad(1, Bytes.fromNumber(addToV + signature.recoveryParam)), Bytes.pad(32, Bytes.fromNat("0x" + signature.r.toString(16))), Bytes.pad(32, Bytes.fromNat("0x" + signature.s.toString(16)))]); | ||
return encodeSignature([Nat.fromString(Bytes.fromNumber(addToV + signature.recoveryParam)), Bytes.pad(32, Bytes.fromNat("0x" + signature.r.toString(16))), Bytes.pad(32, Bytes.fromNat("0x" + signature.s.toString(16)))]); | ||
}; | ||
@@ -60,0 +60,0 @@ }; |
{ | ||
"name": "eth-lib", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "Lightweight Ethereum libraries", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -15,2 +15,3 @@ // type Var = { | ||
const Bytes = require("./bytes"); | ||
const Nat = require("./nat"); | ||
const keccak256s = require("./hash").keccak256s; | ||
@@ -24,3 +25,3 @@ | ||
const nextMul32 = (((length - 1) / 32 | 0) + 1) * 32; | ||
const lengthEncoded = encodeABI("uint256", Nat.fromNumber(length)).data; | ||
const lengthEncoded = encode("uint256", Nat.fromNumber(length)).data; | ||
const bytesEncoded = Bytes.padRight(nextMul32, value); | ||
@@ -27,0 +28,0 @@ return {data: Bytes.concat(lengthEncoded, bytesEncoded), dynamic: true}; |
@@ -40,4 +40,6 @@ const Bytes = require("./bytes"); | ||
const decodeSignature = (hex) => | ||
[Bytes.slice(64,65,hex), Bytes.slice(0,32,hex), Bytes.slice(32,64,hex)]; | ||
const decodeSignature = (hex) => [ | ||
Bytes.slice(64, Bytes.length(hex), hex), | ||
Bytes.slice(0, 32, hex), | ||
Bytes.slice(32, 64, hex)]; | ||
@@ -49,3 +51,3 @@ const makeSigner = addToV => (hash, privateKey) => { | ||
return encodeSignature([ | ||
Bytes.pad(1, Bytes.fromNumber(addToV + signature.recoveryParam)), | ||
Nat.fromString(Bytes.fromNumber(addToV + signature.recoveryParam)), | ||
Bytes.pad(32, Bytes.fromNat("0x" + signature.r.toString(16))), | ||
@@ -52,0 +54,0 @@ Bytes.pad(32, Bytes.fromNat("0x" + signature.s.toString(16)))]); |
87840
41
2486