🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

solady

Package Overview
Dependencies
Maintainers
1
Versions
317
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

solady - npm Package Compare versions

Comparing version

to
0.0.99

48

js/solady.js

@@ -31,23 +31,15 @@ (function(global, factory) {

function hexString(data) {
var isHexString = false;
if (typeof data === "string" || data instanceof String) {
data = data.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, "").toLowerCase();
if (data.match(/^(0x)?[0-9a-f]*$/)) {
data = data.replace(/^0x/, "");
if (data.length % 2 > 0) {
if (data = data.match(/^[\s\uFEFF\xA0]*(0[Xx])?([0-9A-Fa-f]*)[\s\uFEFF\xA0]*$/)) {
if (data[2].length % 2) {
throw new Error("Hex string length must be a multiple of 2.");
} else {
isHexString = true;
}
return data[2];
}
}
if (!isHexString) {
throw new Error("Data must be a hex string.");
}
return data;
throw new Error("Data must be a hex string.");
}
function byteToString(b) {
b = b.toString(16);
return b.length === 1 ? "0" + b : b;
return (b | 0x100).toString(16).slice(1);
}

@@ -62,8 +54,6 @@

data = hexString(data);
var o = "0x";
var z = 0;
var y = 0;
var o = "0x", z = 0, y = 0, i = 0, c;
function pushByte(b) {
o += byteToString(o.length < 4 * 2 + 2 ? 0xff ^ b : b);
o += byteToString(((o.length < 4 * 2 + 2) * 0xff) ^ b);
}

@@ -76,4 +66,4 @@

for (var i = 0; i < data.length; i += 2) {
var c = parseInt(data.slice(i, i + 2), 16);
for (; i < data.length; i += 2) {
c = parseInt(data.slice(i, i + 2), 16);
if (c === 0x00) {

@@ -105,18 +95,16 @@ if (y) rle(1, y), y = 0;

data = hexString(data);
var o = "0x";
var o = "0x", i = 0, c, s;
function getByte(data, i) {
var c = parseInt(data.slice(i, i + 2), 16);
return i < 4 * 2 ? 0xff ^ c : c;
function getByte(j) {
return ((j < 4 * 2) * 0xff) ^ parseInt(data.slice(j, j + 2), 16);
}
for (var i = 0; i < data.length;) {
var c = getByte(data, i);
while (i < data.length) {
c = getByte(i);
i += 2;
if (c === 0x00) {
var d = getByte(data, i);
var s = (d & 0x7f) + 1;
c = getByte(i);
s = (c & 0x7f) + 1;
i += 2;
var b = d < 0x80 ? 0x00 : 0xff;
for (var j = 0; j < s; ++j) o += byteToString(b);
while (s--) o += byteToString((c >> 7) * 0xff);
continue;

@@ -135,3 +123,3 @@ }

"address": "0x0000000000006396FF2a80c067f99B3d2Ab4Df24",
"abi": JSON.parse('[{0:[],1:"DeploymentFailed"96"SaltDoesNotStartWithCaller"96"Unauthorized"96"UpgradeFailed",2:3959790,9791],1:"AdminChanged",2:10959790,9792,9791],1:"Deployed",2:10959790,9792],1:"Upgraded",2:10},{0:[{90],1:"adminOf",12:[{9199{0:[{90,{91],1:"changeAdmin",12:[],13:"nonpayable",2:15},{0:[{92,{91],1:"deploy",12:[{9098,{0:[{92,{91,{94],1:"deployAndCall",12:[{9098,{0:[{92,{91,{93],1:"deployDeterministic",12:[{9098,{0:[{92,{91,{93,{94],1:"deployDeterministicAndCall",12:[{9098,{0:[],1:"initCodeHash",12:[{6:19,1:"result",2:19}99{0:[{93],1:"predictDeterministicAddress",12:[{6:7,1:"predicted",2:7}99{0:[{90,{92],1:"upgrade",12:[98,{0:[{90,{92,{94],1:"upgradeAndCall",12:[98]'.replace(/9\d/g, function (m) { return ["6:7,1:8,2:7}","6:7,1:9,2:7}","6:7,1:11,2:7}","6:19,1:20,2:19}","6:17,1:18,2:17}","},{4:false,0:[",",2:3},{0:[],1:","{5:true,","],13:16,2:15}","],13:14,2:15},"][m-90] }).replace(/\d+/g, function (m) { return '"' + ("inputs,name,type,error,anonymous,indexed,internalType,address,proxy,admin,event,implementation,outputs,stateMutability,view,function,payable,bytes,data,bytes32,salt".split(",")[~~m]) + '"' }))
"abi": JSON.parse('[{0:[],1:"DeploymentFailed"96"SaltDoesNotStartWithCaller"96"Unauthorized"96"UpgradeFailed",2:3959790,9791],1:"AdminChanged",2:10959790,9792,9791],1:"Deployed",2:10959790,9792],1:"Upgraded",2:10},{0:[{90],1:"adminOf",12:[{9199{0:[{90,{91],1:"changeAdmin",12:[],13:"nonpayable",2:15},{0:[{92,{91],1:"deploy",12:[{9098,{0:[{92,{91,{94],1:"deployAndCall",12:[{9098,{0:[{92,{91,{93],1:"deployDeterministic",12:[{9098,{0:[{92,{91,{93,{94],1:"deployDeterministicAndCall",12:[{9098,{0:[],1:"initCodeHash",12:[{6:19,1:"result",2:19}99{0:[{93],1:"predictDeterministicAddress",12:[{6:7,1:"predicted",2:7}99{0:[{90,{92],1:"upgrade",12:[98,{0:[{90,{92,{94],1:"upgradeAndCall",12:[98]'.replace(/9\d/g, function (m) { return ["6:7,1:8,2:7}","6:7,1:9,2:7}","6:7,1:11,2:7}","6:19,1:20,2:19}","6:17,1:18,2:17}","},{4:false,0:[",",2:3},{0:[],1:","{5:true,","],13:16,2:15}","],13:14,2:15},"][m-90] }).replace(/\d+/g, function (m) { return '"' + ("inputs,name,type,error,anonymous,indexed,internalType,address,proxy,admin,event,implementation,outputs,stateMutability,view,function,payable,bytes,data,bytes32,salt".split(",")[m]) + '"' }))
}

@@ -138,0 +126,0 @@

@@ -23,2 +23,8 @@ var solady = require("./solady.js");

function expectRevert(fn) {
var hasRevert = false;
try { fn() } catch (e) { hasRevert = true }
assert(hasRevert, "Revert expected.\n" + fn);
}
test("Calldata compress / decompress.", function() {

@@ -28,4 +34,4 @@ function randomData() {

var s = Math.random() < 0.5 ? "" : "0x";
var g = Math.random() < 0.5 ? 0.45 : 0.99;
var h = Math.random() < 0.5 ? 0.90 : 0.9999;
var g = Math.random() < 0.5 ? 0.45 : (Math.random() ? 0.99 : 0.999);
var h = g + 0.5 * (1.0 - g);
for (var i = 0; i < n; ++i) {

@@ -45,2 +51,10 @@ var r = Math.random();

function padRandomWhitespace(data) {
var before = "";
var after = "";
while (Math.random() < 0.5) before += Math.random() ? "\t" : " ";
while (Math.random() < 0.5) after += Math.random() ? "\t" : " ";
return before + data + after;
}
var totalDataLength = 0;

@@ -50,4 +64,4 @@ var totalCompressedLength = 0;

var data = randomData();
var compressed = solady.LibZip.cdCompress(data);
var decompressed = solady.LibZip.cdDecompress(compressed);
var compressed = solady.LibZip.cdCompress(padRandomWhitespace(data));
var decompressed = solady.LibZip.cdDecompress(padRandomWhitespace(compressed));
totalDataLength += data.length;

@@ -60,2 +74,19 @@ totalCompressedLength += compressed.length;

assert(totalCompressedLength < totalDataLength, "Compress not working as intended.");
assertEq(solady.LibZip.cdCompress(""), "0x");
assertEq(solady.LibZip.cdCompress("0x"), "0x");
assertEq(solady.LibZip.cdDecompress(""), "0x");
assertEq(solady.LibZip.cdDecompress("0x"), "0x");
function checkRevertOnInvalidInputs(fn) {
expectRevert(function () { fn("hehe") });
expectRevert(function () { fn("0xa") });
expectRevert(function () { fn("0xas") });
expectRevert(function () { fn(123) });
expectRevert(function () { fn(false) });
expectRevert(function () { fn(null) });
}
checkRevertOnInvalidInputs(solady.LibZip.cdCompress);
checkRevertOnInvalidInputs(solady.LibZip.cdDecompress);
});

@@ -62,0 +93,0 @@

{
"name": "solady",
"license": "MIT",
"version": "0.0.98",
"version": "0.0.99",
"description": "Optimized Solidity snippets.",

@@ -6,0 +6,0 @@ "files": [

@@ -67,5 +67,5 @@ # <img src="logo.svg" alt="solady" height="118"/>

While Solady has been heavily tested, there may be parts that may exhibit unexpected emergent behavior when used with other code.
While Solady has been heavily tested, there may be parts that may exhibit unexpected emergent behavior when used with other code, or may break in future Solidity versions.
Please always include your own thorough tests when using Solady to make sure it works correctly with your code.
Please always include your own thorough tests when using Solady to make sure it works correctly with your code.

@@ -72,0 +72,0 @@ ## Installation

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet