Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return bytes_1.zeroPad(value, 32);
}
return bytes_1.arrayify(value);
}
var match = type.match(regexNumber);
if (match) {
//let signed = (match[1] === "int")
var size = parseInt(match[2] || "256");
if ((size % 8 != 0) || size === 0 || size > 256) {
throw new Error("invalid number type - " + type);
}
if (isArray) {
size = 256;
}
value = bignumber_1.BigNumber.from(value).toTwos(size);
return bytes_1.zeroPad(value, size / 8);
}
match = type.match(regexBytes);
if (match) {
var size = parseInt(match[1]);
if (String(size) != match[1] || size === 0 || size > 32) {
throw new Error("invalid number type - " + type);
}
if (bytes_1.arrayify(value).byteLength !== size) {
throw new Error("invalid value for " + type);
}
if (isArray) {
return bytes_1.arrayify((value + Zeros).substring(0, 66));
}
return value;
}
match = type.match(regexArray);
function _pack(type, value, isArray) {
switch (type) {
case "address":
if (isArray) {
return zeroPad(value, 32);
}
return arrayify(value);
case "string":
return toUtf8Bytes(value);
case "bytes":
return arrayify(value);
case "bool":
value = (value ? "0x01" : "0x00");
if (isArray) {
return zeroPad(value, 32);
}
return arrayify(value);
}
let match = type.match(regexNumber);
if (match) {
//let signed = (match[1] === "int")
function _pack(type, value, isArray) {
switch (type) {
case "address":
if (isArray) {
return bytes_1.zeroPad(value, 32);
}
return bytes_1.arrayify(value);
case "string":
return strings_1.toUtf8Bytes(value);
case "bytes":
return bytes_1.arrayify(value);
case "bool":
value = (value ? "0x01" : "0x00");
if (isArray) {
return bytes_1.zeroPad(value, 32);
}
return bytes_1.arrayify(value);
}
var match = type.match(regexNumber);
if (match) {
//let signed = (match[1] === "int")
function _pack(type: string, value: any, isArray?: boolean): Uint8Array {
switch(type) {
case "address":
if (isArray) { return zeroPad(value, 32); }
return arrayify(value);
case "string":
return toUtf8Bytes(value);
case "bytes":
return arrayify(value);
case "bool":
value = (value ? "0x01": "0x00");
if (isArray) { return zeroPad(value, 32); }
return arrayify(value);
}
let match = type.match(regexNumber);
if (match) {
//let signed = (match[1] === "int")
let size = parseInt(match[2] || "256")
if ((size % 8 != 0) || size === 0 || size > 256) {
function _pack(type: string, value: any, isArray?: boolean): Uint8Array {
switch(type) {
case "address":
if (isArray) { return zeroPad(value, 32); }
return arrayify(value);
case "string":
return toUtf8Bytes(value);
case "bytes":
return arrayify(value);
case "bool":
value = (value ? "0x01": "0x00");
if (isArray) { return zeroPad(value, 32); }
return arrayify(value);
}
let match = type.match(regexNumber);
if (match) {
//let signed = (match[1] === "int")
let size = parseInt(match[2] || "256")
if ((size % 8 != 0) || size === 0 || size > 256) {
throw new Error("invalid number type - " + type);
}
if (isArray) { size = 256; }
value = BigNumber.from(value).toTwos(size);
return zeroPad(value, size / 8);
return arrayify(value);
}
let match = type.match(regexNumber);
if (match) {
//let signed = (match[1] === "int")
let size = parseInt(match[2] || "256")
if ((size % 8 != 0) || size === 0 || size > 256) {
throw new Error("invalid number type - " + type);
}
if (isArray) { size = 256; }
value = BigNumber.from(value).toTwos(size);
return zeroPad(value, size / 8);
}
match = type.match(regexBytes);
if (match) {
const size = parseInt(match[1]);
if (String(size) != match[1] || size === 0 || size > 32) {
throw new Error("invalid number type - " + type);
}
if (arrayify(value).byteLength !== size) { throw new Error("invalid value for " + type); }
if (isArray) { return arrayify((value + Zeros).substring(0, 66)); }
return value;
}
match = type.match(regexArray);
if (match && Array.isArray(value)) {
const baseType = match[1];
function _pack(type, value, isArray) {
switch (type) {
case "address":
if (isArray) {
return bytes_1.zeroPad(value, 32);
}
return bytes_1.arrayify(value);
case "string":
return strings_1.toUtf8Bytes(value);
case "bytes":
return bytes_1.arrayify(value);
case "bool":
value = (value ? "0x01" : "0x00");
if (isArray) {
return bytes_1.zeroPad(value, 32);
}
return bytes_1.arrayify(value);
}
var match = type.match(regexNumber);
if (match) {
//let signed = (match[1] === "int")
var size = parseInt(match[2] || "256");
if ((size % 8 != 0) || size === 0 || size > 256) {
throw new Error("invalid number type - " + type);
}
if (isArray) {
size = 256;
}
value = bignumber_1.BigNumber.from(value).toTwos(size);
return bytes_1.zeroPad(value, size / 8);
}