Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eth-lib

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eth-lib - npm Package Compare versions

Comparing version 0.1.17 to 0.1.18

src/a.js

5

package.json
{
"name": "eth-lib",
"version": "0.1.17",
"version": "0.1.18",
"description": "Lightweight Ethereum libraries",

@@ -32,6 +32,5 @@ "main": "src/index.js",

"nano-json-stream-parser": "^0.1.2",
"reqwest": "^2.0.5",
"ws": "^3.0.0",
"xhr2": "^0.1.4"
"xhr-request-promise": "^0.1.2"
}
}

43

src/api.js

@@ -11,2 +11,18 @@ const Api = provider => {

// TODO check inputs
// TODO move to proper file
const encodeABI = (type, value) => {
if (type === "bytes") {
const length = Bytes.length(value);
const nextMul32 = (((length - 1) / 32 | 0) + 1) * 32;
const lengthEncoded = encodeABI("uint256", Nat.fromNumber(length));
const bytesEncoded = Bytes.padRight(nextMul32, value);
return Bytes.concat(lengthEncoded, bytesEncoded);
} else if (type === "uint256") {
return Bytes.pad(32, value);
} else {
throw "Eth-lib can't encode ABI type " + type + " yet.";
}
}
const sendTransaction = send("eth_sendTransaction");

@@ -50,3 +66,5 @@ const sendRawTransaction = send("eth_sendRawTransaction");

const methodSig = method.name + "(" + method.inputs.map(i => i.type).join(",") + ")";
return Bytes.concat(keccak256s(methodSig).slice(0,10), Bytes.flatten(params));
const methodHash = keccak256s(methodSig).slice(0,10);
const encodedParams = params.map((param,i) => encodeABI(method.inputs[i].type, param));
return Bytes.concat(methodHash, Bytes.flatten(encodedParams));
}

@@ -62,3 +80,3 @@

if (method && method.name) {
const call = (waitReceipt, value) => (...params) => {
const call = (type, value) => (...params) => {
const transaction = {

@@ -68,14 +86,17 @@ from: from,

value: value,
data: callMethodData(method)(...params.map(p => Bytes.pad(32,p)))
data: callMethodData(method)(...params)
};
return method.constant
? callWithDefaults(transaction)
: sendTransactionWithDefaults(transaction)
.then(waitReceipt ? waitTransactionReceipt : (x => x));
return type === "data"
? Promise.resolve(transaction)
: method.constant
? callWithDefaults(transaction)
: sendTransactionWithDefaults(transaction)
.then(type === "receipt" ? waitTransactionReceipt : (x => x));
};
contract[method.name] = call(true, "0x0");
contract[method.name] = call("receipt", "0x0");
if (!method.constant) {
contract[method.name+"_pay"] = value => (...params) => call(true, value)(...params);
contract[method.name+"_pay_txHash"] = value => (...params) => call(false, value)(...params);
contract[method.name+"_txHash"] = call(false, "0x0");
contract[method.name+"_data"] = call("data", "0x0");
contract[method.name+"_pay"] = value => (...params) => call("receipt", value)(...params);
contract[method.name+"_pay_txHash"] = value => (...params) => call("txHash", value)(...params);
contract[method.name+"_txHash"] = call("txHash", "0x0");
}

@@ -82,0 +103,0 @@ }

@@ -64,2 +64,7 @@ const A = require("./array.js");

const padRight = (l,hex) =>
hex.length === l*2+2 ? hex : padRight(l,hex+"0");
console.log(padRight(32, "0x123456"));
const fromNat = bn =>

@@ -78,2 +83,3 @@ bn === "0x0" ? "0x" : bn.length % 2 === 0 ? bn : "0x0" + bn.slice(2);

pad,
padRight,
fromAscii,

@@ -80,0 +86,0 @@ toAscii,

const njsp = require("nano-json-stream-parser");
const rw = require("reqwest");
const request = require("xhr-request-promise");

@@ -61,8 +61,8 @@ const EthereumProvider = (url, intercept) => {

api.send = makeSender((method, params, callback) => {
rw({
url: url,
method: "post",
request(url, {
method: "POST",
contentType: "application/json-rpc",
data: JSON.stringify(genPayload(method,params))})
.then(resp => {
body: JSON.stringify(genPayload(method,params))})
.then(answer => {
var resp = JSON.parse(answer);
if (resp.error) {

@@ -69,0 +69,0 @@ callback(resp.error.message);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc