@ethersproject/solidity
Advanced tools
Comparing version 5.0.9 to 5.7.0
@@ -1,2 +0,2 @@ | ||
export declare const version = "solidity/5.0.9"; | ||
export declare const version = "solidity/5.7.0"; | ||
//# sourceMappingURL=_version.d.ts.map |
@@ -1,2 +0,2 @@ | ||
export const version = "solidity/5.0.9"; | ||
export const version = "solidity/5.7.0"; | ||
//# sourceMappingURL=_version.js.map |
@@ -1,4 +0,4 @@ | ||
export declare function pack(types: Array<string>, values: Array<any>): string; | ||
export declare function keccak256(types: Array<string>, values: Array<any>): string; | ||
export declare function sha256(types: Array<string>, values: Array<any>): string; | ||
export declare function pack(types: ReadonlyArray<string>, values: ReadonlyArray<any>): string; | ||
export declare function keccak256(types: ReadonlyArray<string>, values: ReadonlyArray<any>): string; | ||
export declare function sha256(types: ReadonlyArray<string>, values: ReadonlyArray<any>): string; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -11,2 +11,5 @@ "use strict"; | ||
const Zeros = "0000000000000000000000000000000000000000000000000000000000000000"; | ||
import { Logger } from "@ethersproject/logger"; | ||
import { version } from "./_version"; | ||
const logger = new Logger(version); | ||
function _pack(type, value, isArray) { | ||
@@ -35,3 +38,3 @@ switch (type) { | ||
if ((match[2] && String(size) !== match[2]) || (size % 8 !== 0) || size === 0 || size > 256) { | ||
throw new Error("invalid number type - " + type); | ||
logger.throwArgumentError("invalid number type", "type", type); | ||
} | ||
@@ -48,6 +51,6 @@ if (isArray) { | ||
if (String(size) !== match[1] || size === 0 || size > 32) { | ||
throw new Error("invalid bytes type - " + type); | ||
logger.throwArgumentError("invalid bytes type", "type", type); | ||
} | ||
if (arrayify(value).byteLength !== size) { | ||
throw new Error("invalid value for " + type); | ||
logger.throwArgumentError(`invalid value for ${type}`, "value", value); | ||
} | ||
@@ -64,3 +67,3 @@ if (isArray) { | ||
if (count != value.length) { | ||
throw new Error("invalid value for " + type); | ||
logger.throwArgumentError(`invalid array length for ${type}`, "value", value); | ||
} | ||
@@ -73,3 +76,3 @@ const result = []; | ||
} | ||
throw new Error("invalid type - " + type); | ||
return logger.throwArgumentError("invalid type", "type", type); | ||
} | ||
@@ -79,3 +82,3 @@ // @TODO: Array Enum | ||
if (types.length != values.length) { | ||
throw new Error("type/value count mismatch"); | ||
logger.throwArgumentError("wrong number of values; expected ${ types.length }", "values", values); | ||
} | ||
@@ -82,0 +85,0 @@ const tight = []; |
@@ -1,2 +0,2 @@ | ||
export declare const version = "solidity/5.0.9"; | ||
export declare const version = "solidity/5.7.0"; | ||
//# sourceMappingURL=_version.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.version = "solidity/5.0.9"; | ||
exports.version = void 0; | ||
exports.version = "solidity/5.7.0"; | ||
//# sourceMappingURL=_version.js.map |
@@ -1,4 +0,4 @@ | ||
export declare function pack(types: Array<string>, values: Array<any>): string; | ||
export declare function keccak256(types: Array<string>, values: Array<any>): string; | ||
export declare function sha256(types: Array<string>, values: Array<any>): string; | ||
export declare function pack(types: ReadonlyArray<string>, values: ReadonlyArray<any>): string; | ||
export declare function keccak256(types: ReadonlyArray<string>, values: ReadonlyArray<any>): string; | ||
export declare function sha256(types: ReadonlyArray<string>, values: ReadonlyArray<any>): string; | ||
//# sourceMappingURL=index.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.sha256 = exports.keccak256 = exports.pack = void 0; | ||
var bignumber_1 = require("@ethersproject/bignumber"); | ||
@@ -12,2 +13,5 @@ var bytes_1 = require("@ethersproject/bytes"); | ||
var Zeros = "0000000000000000000000000000000000000000000000000000000000000000"; | ||
var logger_1 = require("@ethersproject/logger"); | ||
var _version_1 = require("./_version"); | ||
var logger = new logger_1.Logger(_version_1.version); | ||
function _pack(type, value, isArray) { | ||
@@ -17,15 +21,15 @@ switch (type) { | ||
if (isArray) { | ||
return bytes_1.zeroPad(value, 32); | ||
return (0, bytes_1.zeroPad)(value, 32); | ||
} | ||
return bytes_1.arrayify(value); | ||
return (0, bytes_1.arrayify)(value); | ||
case "string": | ||
return strings_1.toUtf8Bytes(value); | ||
return (0, strings_1.toUtf8Bytes)(value); | ||
case "bytes": | ||
return bytes_1.arrayify(value); | ||
return (0, bytes_1.arrayify)(value); | ||
case "bool": | ||
value = (value ? "0x01" : "0x00"); | ||
if (isArray) { | ||
return bytes_1.zeroPad(value, 32); | ||
return (0, bytes_1.zeroPad)(value, 32); | ||
} | ||
return bytes_1.arrayify(value); | ||
return (0, bytes_1.arrayify)(value); | ||
} | ||
@@ -37,3 +41,3 @@ var match = type.match(regexNumber); | ||
if ((match[2] && String(size) !== match[2]) || (size % 8 !== 0) || size === 0 || size > 256) { | ||
throw new Error("invalid number type - " + type); | ||
logger.throwArgumentError("invalid number type", "type", type); | ||
} | ||
@@ -44,3 +48,3 @@ if (isArray) { | ||
value = bignumber_1.BigNumber.from(value).toTwos(size); | ||
return bytes_1.zeroPad(value, size / 8); | ||
return (0, bytes_1.zeroPad)(value, size / 8); | ||
} | ||
@@ -51,9 +55,9 @@ match = type.match(regexBytes); | ||
if (String(size) !== match[1] || size === 0 || size > 32) { | ||
throw new Error("invalid bytes type - " + type); | ||
logger.throwArgumentError("invalid bytes type", "type", type); | ||
} | ||
if (bytes_1.arrayify(value).byteLength !== size) { | ||
throw new Error("invalid value for " + type); | ||
if ((0, bytes_1.arrayify)(value).byteLength !== size) { | ||
logger.throwArgumentError("invalid value for " + type, "value", value); | ||
} | ||
if (isArray) { | ||
return bytes_1.arrayify((value + Zeros).substring(0, 66)); | ||
return (0, bytes_1.arrayify)((value + Zeros).substring(0, 66)); | ||
} | ||
@@ -67,3 +71,3 @@ return value; | ||
if (count != value.length) { | ||
throw new Error("invalid value for " + type); | ||
logger.throwArgumentError("invalid array length for " + type, "value", value); | ||
} | ||
@@ -74,5 +78,5 @@ var result_1 = []; | ||
}); | ||
return bytes_1.concat(result_1); | ||
return (0, bytes_1.concat)(result_1); | ||
} | ||
throw new Error("invalid type - " + type); | ||
return logger.throwArgumentError("invalid type", "type", type); | ||
} | ||
@@ -82,3 +86,3 @@ // @TODO: Array Enum | ||
if (types.length != values.length) { | ||
throw new Error("type/value count mismatch"); | ||
logger.throwArgumentError("wrong number of values; expected ${ types.length }", "values", values); | ||
} | ||
@@ -89,13 +93,13 @@ var tight = []; | ||
}); | ||
return bytes_1.hexlify(bytes_1.concat(tight)); | ||
return (0, bytes_1.hexlify)((0, bytes_1.concat)(tight)); | ||
} | ||
exports.pack = pack; | ||
function keccak256(types, values) { | ||
return keccak256_1.keccak256(pack(types, values)); | ||
return (0, keccak256_1.keccak256)(pack(types, values)); | ||
} | ||
exports.keccak256 = keccak256; | ||
function sha256(types, values) { | ||
return sha2_1.sha256(pack(types, values)); | ||
return (0, sha2_1.sha256)(pack(types, values)); | ||
} | ||
exports.sha256 = sha256; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"author": "Richard Moore <me@ricmoo.com>", | ||
"dependencies": { | ||
"@ethersproject/bignumber": "^5.0.13", | ||
"@ethersproject/bytes": "^5.0.9", | ||
"@ethersproject/keccak256": "^5.0.7", | ||
"@ethersproject/sha2": "^5.0.7", | ||
"@ethersproject/strings": "^5.0.8" | ||
"@ethersproject/bignumber": "^5.7.0", | ||
"@ethersproject/bytes": "^5.7.0", | ||
"@ethersproject/keccak256": "^5.7.0", | ||
"@ethersproject/logger": "^5.7.0", | ||
"@ethersproject/sha2": "^5.7.0", | ||
"@ethersproject/strings": "^5.7.0" | ||
}, | ||
@@ -22,3 +23,3 @@ "description": "Solidity coder for non-standard (tight) packing.", | ||
], | ||
"gitHead": "4f67ecdf628268724077ffbbde4b188cd48579ec", | ||
"gitHead": "ec1b9583039a14a0e0fa15d0a2a6082a2f41cf5b", | ||
"keywords": [ | ||
@@ -44,5 +45,5 @@ "Ethereum", | ||
"sideEffects": false, | ||
"tarballHash": "0x7a77632b6340e64cfdce1fdd00d585417e4d522ca829aa34026956175db8bead", | ||
"tarballHash": "0x75a79894ba701f9d0f631c861579808118e58b2127b0256100c2e2da169ea759", | ||
"types": "./lib/index.d.ts", | ||
"version": "5.0.9" | ||
"version": "5.7.0" | ||
} |
@@ -1,1 +0,1 @@ | ||
export const version = "solidity/5.0.9"; | ||
export const version = "solidity/5.7.0"; |
@@ -15,2 +15,7 @@ "use strict"; | ||
import { Logger } from "@ethersproject/logger"; | ||
import { version } from "./_version"; | ||
const logger = new Logger(version); | ||
function _pack(type: string, value: any, isArray?: boolean): Uint8Array { | ||
@@ -37,3 +42,3 @@ switch(type) { | ||
if ((match[2] && String(size) !== match[2]) || (size % 8 !== 0) || size === 0 || size > 256) { | ||
throw new Error("invalid number type - " + type); | ||
logger.throwArgumentError("invalid number type", "type", type) | ||
} | ||
@@ -53,5 +58,7 @@ | ||
if (String(size) !== match[1] || size === 0 || size > 32) { | ||
throw new Error("invalid bytes type - " + type); | ||
logger.throwArgumentError("invalid bytes type", "type", type) | ||
} | ||
if (arrayify(value).byteLength !== size) { throw new Error("invalid value for " + type); } | ||
if (arrayify(value).byteLength !== size) { | ||
logger.throwArgumentError(`invalid value for ${ type }`, "value", value) | ||
} | ||
if (isArray) { return arrayify((value + Zeros).substring(0, 66)); } | ||
@@ -65,3 +72,5 @@ return value; | ||
const count = parseInt(match[2] || String(value.length)); | ||
if (count != value.length) { throw new Error("invalid value for " + type); } | ||
if (count != value.length) { | ||
logger.throwArgumentError(`invalid array length for ${ type }`, "value", value) | ||
} | ||
const result: Array<Uint8Array> = []; | ||
@@ -74,3 +83,3 @@ value.forEach(function(value) { | ||
throw new Error("invalid type - " + type); | ||
return logger.throwArgumentError("invalid type", "type", type) | ||
} | ||
@@ -80,4 +89,6 @@ | ||
export function pack(types: Array<string>, values: Array<any>) { | ||
if (types.length != values.length) { throw new Error("type/value count mismatch"); } | ||
export function pack(types: ReadonlyArray<string>, values: ReadonlyArray<any>) { | ||
if (types.length != values.length) { | ||
logger.throwArgumentError("wrong number of values; expected ${ types.length }", "values", values) | ||
} | ||
const tight: Array<Uint8Array> = []; | ||
@@ -90,8 +101,8 @@ types.forEach(function(type, index) { | ||
export function keccak256(types: Array<string>, values: Array<any>) { | ||
export function keccak256(types: ReadonlyArray<string>, values: ReadonlyArray<any>) { | ||
return hashKeccak256(pack(types, values)); | ||
} | ||
export function sha256(types: Array<string>, values: Array<any>) { | ||
export function sha256(types: ReadonlyArray<string>, values: ReadonlyArray<any>) { | ||
return hashSha256(pack(types, values)); | ||
} |
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
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23237
281
6