admin: updated dist files
This commit is contained in:
parent
8f99601df1
commit
e66ce74835
@ -3,12 +3,12 @@ Change Log
|
||||
|
||||
This change log is maintained by `src.ts/_admin/update-changelog.ts` but may also be manually updated.
|
||||
|
||||
ethers/v6.10.1 (2024-01-15 23:07)
|
||||
ethers/v6.10.1 (2024-01-16 17:43)
|
||||
---------------------------------
|
||||
|
||||
- Updated third-party provider network URLs ([#4542](https://github.com/ethers-io/ethers.js/issues/4542); [84ca14f](https://github.com/ethers-io/ethers.js/commit/84ca14f1ffc5afbdd7f4c26a9b734ec5951eee3c)).
|
||||
- Added additional sepolia testnets ([4efef76](https://github.com/ethers-io/ethers.js/commit/4efef76e8cab0acaf1b2ba231a0148f9381bb1ee)).
|
||||
- Fix EIP-712 type aliases for uint and int ([#4541](https://github.com/ethers-io/ethers.js/issues/4541); [43fb9c2](https://github.com/ethers-io/ethers.js/commit/43fb9c233696aeaa80b1c2b0e5fafce90e0ad508)).
|
||||
- Fix EIP-712 type aliases for uint and int ([#4541](https://github.com/ethers-io/ethers.js/issues/4541); [43fb9c2](https://github.com/ethers-io/ethers.js/commit/43fb9c233696aeaa80b1c2b0e5fafce90e0ad508), [8f99601](https://github.com/ethers-io/ethers.js/commit/8f99601df1f26a8ba4d6d9dea5e033e7f688107e)).
|
||||
- Fixed typo in Error string ([#4539](https://github.com/ethers-io/ethers.js/issues/4539); [7882905](https://github.com/ethers-io/ethers.js/commit/78829050853093bc5291ae78fc5a904044759aa0)).
|
||||
- Better debugging output on fetch errors ([bee07a0](https://github.com/ethers-io/ethers.js/commit/bee07a0750b448a9d13c2d57014bcf27f43e2ed7)).
|
||||
|
||||
|
48
dist/ethers.js
vendored
48
dist/ethers.js
vendored
@ -10552,6 +10552,23 @@ function getBaseEncoder(type) {
|
||||
function encodeType(name, fields) {
|
||||
return `${name}(${fields.map(({ name, type }) => (type + " " + name)).join(",")})`;
|
||||
}
|
||||
// foo[][3] => { base: "foo", index: "[][3]", array: {
|
||||
// base: "foo", prefix: "foo[]", count: 3 } }
|
||||
function splitArray(type) {
|
||||
const match = type.match(/^([^\x5b]*)((\x5b\d*\x5d)*)(\x5b(\d*)\x5d)$/);
|
||||
if (match) {
|
||||
return {
|
||||
base: match[1],
|
||||
index: (match[2] + match[4]),
|
||||
array: {
|
||||
base: match[1],
|
||||
prefix: (match[1] + match[2]),
|
||||
count: (match[5] ? parseInt(match[5]) : -1),
|
||||
}
|
||||
};
|
||||
}
|
||||
return { base: type };
|
||||
}
|
||||
/**
|
||||
* A **TypedDataEncode** prepares and encodes [[link-eip-712]] payloads
|
||||
* for signed typed data.
|
||||
@ -10597,15 +10614,16 @@ class TypedDataEncoder {
|
||||
const subtypes = new Map();
|
||||
const types = {};
|
||||
Object.keys(_types).forEach((type) => {
|
||||
// Normalize int/uint unless they are a complex type themselves
|
||||
types[type] = _types[type].map(({ name, type }) => {
|
||||
if (type === "int" && !_types["int"]) {
|
||||
type = "int256";
|
||||
// Normalize the base type (unless name conflict)
|
||||
let { base, index } = splitArray(type);
|
||||
if (base === "int" && !_types["int"]) {
|
||||
base = "int256";
|
||||
}
|
||||
if (type === "uint" && !_types["uint"]) {
|
||||
type = "uint256";
|
||||
if (base === "uint" && !_types["uint"]) {
|
||||
base = "uint256";
|
||||
}
|
||||
return { name, type };
|
||||
return { name, type: (base + (index || "")) };
|
||||
});
|
||||
links.set(type, new Set());
|
||||
parents.set(type, []);
|
||||
@ -10619,7 +10637,7 @@ class TypedDataEncoder {
|
||||
assertArgument(!uniqueNames.has(field.name), `duplicate variable name ${JSON.stringify(field.name)} in ${JSON.stringify(name)}`, "types", _types);
|
||||
uniqueNames.add(field.name);
|
||||
// Get the base type (drop any array specifiers)
|
||||
const baseType = (field.type.match(/^([^\x5b]*)(\x5b|$)/))[1] || null;
|
||||
const baseType = splitArray(field.type).base;
|
||||
assertArgument(baseType !== name, `circular type reference to ${JSON.stringify(baseType)}`, "types", _types);
|
||||
// Is this a base encoding type?
|
||||
const encoder = getBaseEncoder(baseType);
|
||||
@ -10682,12 +10700,12 @@ class TypedDataEncoder {
|
||||
}
|
||||
}
|
||||
// Array
|
||||
const match = type.match(/^(.*)(\x5b(\d*)\x5d)$/);
|
||||
if (match) {
|
||||
const subtype = match[1];
|
||||
const array = splitArray(type).array;
|
||||
if (array) {
|
||||
const subtype = array.prefix;
|
||||
const subEncoder = this.getEncoder(subtype);
|
||||
return (value) => {
|
||||
assertArgument(!match[3] || parseInt(match[3]) === value.length, `array length mismatch; expected length ${parseInt(match[3])}`, "value", value);
|
||||
assertArgument(array.count === -1 || array.count === value.length, `array length mismatch; expected length ${array.count}`, "value", value);
|
||||
let result = value.map(subEncoder);
|
||||
if (this.#fullTypes.has(subtype)) {
|
||||
result = result.map(keccak256);
|
||||
@ -10757,10 +10775,10 @@ class TypedDataEncoder {
|
||||
}
|
||||
}
|
||||
// Array
|
||||
const match = type.match(/^(.*)(\x5b(\d*)\x5d)$/);
|
||||
if (match) {
|
||||
assertArgument(!match[3] || parseInt(match[3]) === value.length, `array length mismatch; expected length ${parseInt(match[3])}`, "value", value);
|
||||
return value.map((v) => this._visit(match[1], v, callback));
|
||||
const array = splitArray(type).array;
|
||||
if (array) {
|
||||
assertArgument(array.count === -1 || array.count === value.length, `array length mismatch; expected length ${array.count}`, "value", value);
|
||||
return value.map((v) => this._visit(array.prefix, v, callback));
|
||||
}
|
||||
// Struct
|
||||
const fields = this.types[type];
|
||||
|
2
dist/ethers.js.map
vendored
2
dist/ethers.js.map
vendored
File diff suppressed because one or more lines are too long
2
dist/ethers.min.js
vendored
2
dist/ethers.min.js
vendored
File diff suppressed because one or more lines are too long
48
dist/ethers.umd.js
vendored
48
dist/ethers.umd.js
vendored
@ -10558,6 +10558,23 @@ const __$G = (typeof globalThis !== 'undefined' ? globalThis: typeof window !==
|
||||
function encodeType(name, fields) {
|
||||
return `${name}(${fields.map(({ name, type }) => (type + " " + name)).join(",")})`;
|
||||
}
|
||||
// foo[][3] => { base: "foo", index: "[][3]", array: {
|
||||
// base: "foo", prefix: "foo[]", count: 3 } }
|
||||
function splitArray(type) {
|
||||
const match = type.match(/^([^\x5b]*)((\x5b\d*\x5d)*)(\x5b(\d*)\x5d)$/);
|
||||
if (match) {
|
||||
return {
|
||||
base: match[1],
|
||||
index: (match[2] + match[4]),
|
||||
array: {
|
||||
base: match[1],
|
||||
prefix: (match[1] + match[2]),
|
||||
count: (match[5] ? parseInt(match[5]) : -1),
|
||||
}
|
||||
};
|
||||
}
|
||||
return { base: type };
|
||||
}
|
||||
/**
|
||||
* A **TypedDataEncode** prepares and encodes [[link-eip-712]] payloads
|
||||
* for signed typed data.
|
||||
@ -10603,15 +10620,16 @@ const __$G = (typeof globalThis !== 'undefined' ? globalThis: typeof window !==
|
||||
const subtypes = new Map();
|
||||
const types = {};
|
||||
Object.keys(_types).forEach((type) => {
|
||||
// Normalize int/uint unless they are a complex type themselves
|
||||
types[type] = _types[type].map(({ name, type }) => {
|
||||
if (type === "int" && !_types["int"]) {
|
||||
type = "int256";
|
||||
// Normalize the base type (unless name conflict)
|
||||
let { base, index } = splitArray(type);
|
||||
if (base === "int" && !_types["int"]) {
|
||||
base = "int256";
|
||||
}
|
||||
if (type === "uint" && !_types["uint"]) {
|
||||
type = "uint256";
|
||||
if (base === "uint" && !_types["uint"]) {
|
||||
base = "uint256";
|
||||
}
|
||||
return { name, type };
|
||||
return { name, type: (base + (index || "")) };
|
||||
});
|
||||
links.set(type, new Set());
|
||||
parents.set(type, []);
|
||||
@ -10625,7 +10643,7 @@ const __$G = (typeof globalThis !== 'undefined' ? globalThis: typeof window !==
|
||||
assertArgument(!uniqueNames.has(field.name), `duplicate variable name ${JSON.stringify(field.name)} in ${JSON.stringify(name)}`, "types", _types);
|
||||
uniqueNames.add(field.name);
|
||||
// Get the base type (drop any array specifiers)
|
||||
const baseType = (field.type.match(/^([^\x5b]*)(\x5b|$)/))[1] || null;
|
||||
const baseType = splitArray(field.type).base;
|
||||
assertArgument(baseType !== name, `circular type reference to ${JSON.stringify(baseType)}`, "types", _types);
|
||||
// Is this a base encoding type?
|
||||
const encoder = getBaseEncoder(baseType);
|
||||
@ -10688,12 +10706,12 @@ const __$G = (typeof globalThis !== 'undefined' ? globalThis: typeof window !==
|
||||
}
|
||||
}
|
||||
// Array
|
||||
const match = type.match(/^(.*)(\x5b(\d*)\x5d)$/);
|
||||
if (match) {
|
||||
const subtype = match[1];
|
||||
const array = splitArray(type).array;
|
||||
if (array) {
|
||||
const subtype = array.prefix;
|
||||
const subEncoder = this.getEncoder(subtype);
|
||||
return (value) => {
|
||||
assertArgument(!match[3] || parseInt(match[3]) === value.length, `array length mismatch; expected length ${parseInt(match[3])}`, "value", value);
|
||||
assertArgument(array.count === -1 || array.count === value.length, `array length mismatch; expected length ${array.count}`, "value", value);
|
||||
let result = value.map(subEncoder);
|
||||
if (this.#fullTypes.has(subtype)) {
|
||||
result = result.map(keccak256);
|
||||
@ -10763,10 +10781,10 @@ const __$G = (typeof globalThis !== 'undefined' ? globalThis: typeof window !==
|
||||
}
|
||||
}
|
||||
// Array
|
||||
const match = type.match(/^(.*)(\x5b(\d*)\x5d)$/);
|
||||
if (match) {
|
||||
assertArgument(!match[3] || parseInt(match[3]) === value.length, `array length mismatch; expected length ${parseInt(match[3])}`, "value", value);
|
||||
return value.map((v) => this._visit(match[1], v, callback));
|
||||
const array = splitArray(type).array;
|
||||
if (array) {
|
||||
assertArgument(array.count === -1 || array.count === value.length, `array length mismatch; expected length ${array.count}`, "value", value);
|
||||
return value.map((v) => this._visit(array.prefix, v, callback));
|
||||
}
|
||||
// Struct
|
||||
const fields = this.types[type];
|
||||
|
2
dist/ethers.umd.js.map
vendored
2
dist/ethers.umd.js.map
vendored
File diff suppressed because one or more lines are too long
2
dist/ethers.umd.min.js
vendored
2
dist/ethers.umd.min.js
vendored
File diff suppressed because one or more lines are too long
@ -58,6 +58,66 @@ describe("Tests Typed Data (EIP-712) aliases", function () {
|
||||
},
|
||||
encoded: "0xa272ada5f88085e4cb18acdb87bd057a8cbfec249fee53de0149409080947cf500000000000000000000000000000000000000000000000000000000000000231c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac8"
|
||||
},
|
||||
{
|
||||
name: "array-uint",
|
||||
types: {
|
||||
foo: [
|
||||
{ name: "a", type: "uint256[]" },
|
||||
{ name: "b", type: "string" },
|
||||
],
|
||||
},
|
||||
typesAlias: {
|
||||
foo: [
|
||||
{ name: "a", type: "uint[]" },
|
||||
{ name: "b", type: "string" },
|
||||
],
|
||||
},
|
||||
data: {
|
||||
a: [35, 36, 37],
|
||||
b: "hello"
|
||||
},
|
||||
encoded: "0x1a961843d0002bdd66ec21afd6e4a5b0aac34a4b6112890378c6e3a38b752e0b0c22b846886e98aeffc1f1166d4b35868da4d4da853dcb3b2856cfc233fd10c81c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac8"
|
||||
},
|
||||
{
|
||||
name: "array-int",
|
||||
types: {
|
||||
foo: [
|
||||
{ name: "a", type: "int256[]" },
|
||||
{ name: "b", type: "string" },
|
||||
],
|
||||
},
|
||||
typesAlias: {
|
||||
foo: [
|
||||
{ name: "a", type: "int[]" },
|
||||
{ name: "b", type: "string" },
|
||||
],
|
||||
},
|
||||
data: {
|
||||
a: [35, 36, 37],
|
||||
b: "hello"
|
||||
},
|
||||
encoded: "0x0b89085a01a3b67d2231c6a136f9c8eea75d7d479a83a127356f8540ee15af010c22b846886e98aeffc1f1166d4b35868da4d4da853dcb3b2856cfc233fd10c81c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac8"
|
||||
},
|
||||
{
|
||||
name: "nested-array-uint",
|
||||
types: {
|
||||
foo: [
|
||||
{ name: "a", type: "uint256[][]" },
|
||||
{ name: "b", type: "string" },
|
||||
],
|
||||
},
|
||||
typesAlias: {
|
||||
foo: [
|
||||
{ name: "a", type: "uint[][]" },
|
||||
{ name: "b", type: "string" },
|
||||
],
|
||||
},
|
||||
data: {
|
||||
a: [[35, 36], [37]],
|
||||
b: "hello"
|
||||
},
|
||||
encoded: "0x5efa7c4b66979cf78fcc7c3e71cbfa04ec2c7529002642082bf20a91552c1147fa5ffe3a0504d850bc7c9eeda1cf960b596b73f4dc0272a6fa89dace08e320291c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac8"
|
||||
},
|
||||
];
|
||||
for (const test of tests) {
|
||||
it(`tests encoding typed-data: ${test.name}`, function () {
|
||||
|
@ -1 +1 @@
|
||||
{"version":3,"file":"test-hash-typeddata.js","sourceRoot":"","sources":["../../src.ts/_tests/test-hash-typeddata.ts"],"names":[],"mappings":";;;AAAA,4DAA4B;AAC5B,yCAAuC;AAEvC,0CAA+C;AAG/C,QAAQ,CAAC,4BAA4B,EAAE;IACnC,MAAM,KAAK,GAAG,IAAA,oBAAS,EAAoB,YAAY,CAAC,CAAC;IACzD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;QACtB,EAAE,CAAC,8BAA+B,IAAI,CAAC,IAAK,EAAE,EAAE;YAC5C,MAAM,OAAO,GAAG,2BAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAClD,gBAAM,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;YACnE,gBAAM,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;YAEjE,gBAAM,CAAC,KAAK,CAAC,2BAAgB,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;YAC3F,gBAAM,CAAC,KAAK,CAAC,2BAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QACnG,CAAC,CA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M,CAAC,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,eAAe,CAAC;QAAC,KAAK,EAAE,GAAG,CAAA;KAAE,CAAC;IAiD9N;;;OAGG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG;CAuD5H;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,SAAS,EAAE,aAAa,GAAG,MAAM,CAEnK"}
|
@ -114,6 +114,23 @@ function getBaseEncoder(type) {
|
||||
function encodeType(name, fields) {
|
||||
return `${name}(${fields.map(({ name, type }) => (type + " " + name)).join(",")})`;
|
||||
}
|
||||
// foo[][3] => { base: "foo", index: "[][3]", array: {
|
||||
// base: "foo", prefix: "foo[]", count: 3 } }
|
||||
function splitArray(type) {
|
||||
const match = type.match(/^([^\x5b]*)((\x5b\d*\x5d)*)(\x5b(\d*)\x5d)$/);
|
||||
if (match) {
|
||||
return {
|
||||
base: match[1],
|
||||
index: (match[2] + match[4]),
|
||||
array: {
|
||||
base: match[1],
|
||||
prefix: (match[1] + match[2]),
|
||||
count: (match[5] ? parseInt(match[5]) : -1),
|
||||
}
|
||||
};
|
||||
}
|
||||
return { base: type };
|
||||
}
|
||||
/**
|
||||
* A **TypedDataEncode** prepares and encodes [[link-eip-712]] payloads
|
||||
* for signed typed data.
|
||||
@ -159,15 +176,16 @@ class TypedDataEncoder {
|
||||
const subtypes = new Map();
|
||||
const types = {};
|
||||
Object.keys(_types).forEach((type) => {
|
||||
// Normalize int/uint unless they are a complex type themselves
|
||||
types[type] = _types[type].map(({ name, type }) => {
|
||||
if (type === "int" && !_types["int"]) {
|
||||
type = "int256";
|
||||
// Normalize the base type (unless name conflict)
|
||||
let { base, index } = splitArray(type);
|
||||
if (base === "int" && !_types["int"]) {
|
||||
base = "int256";
|
||||
}
|
||||
if (type === "uint" && !_types["uint"]) {
|
||||
type = "uint256";
|
||||
if (base === "uint" && !_types["uint"]) {
|
||||
base = "uint256";
|
||||
}
|
||||
return { name, type };
|
||||
return { name, type: (base + (index || "")) };
|
||||
});
|
||||
links.set(type, new Set());
|
||||
parents.set(type, []);
|
||||
@ -181,7 +199,7 @@ class TypedDataEncoder {
|
||||
(0, index_js_4.assertArgument)(!uniqueNames.has(field.name), `duplicate variable name ${JSON.stringify(field.name)} in ${JSON.stringify(name)}`, "types", _types);
|
||||
uniqueNames.add(field.name);
|
||||
// Get the base type (drop any array specifiers)
|
||||
const baseType = (field.type.match(/^([^\x5b]*)(\x5b|$)/))[1] || null;
|
||||
const baseType = splitArray(field.type).base;
|
||||
(0, index_js_4.assertArgument)(baseType !== name, `circular type reference to ${JSON.stringify(baseType)}`, "types", _types);
|
||||
// Is this a base encoding type?
|
||||
const encoder = getBaseEncoder(baseType);
|
||||
@ -244,12 +262,12 @@ class TypedDataEncoder {
|
||||
}
|
||||
}
|
||||
// Array
|
||||
const match = type.match(/^(.*)(\x5b(\d*)\x5d)$/);
|
||||
if (match) {
|
||||
const subtype = match[1];
|
||||
const array = splitArray(type).array;
|
||||
if (array) {
|
||||
const subtype = array.prefix;
|
||||
const subEncoder = this.getEncoder(subtype);
|
||||
return (value) => {
|
||||
(0, index_js_4.assertArgument)(!match[3] || parseInt(match[3]) === value.length, `array length mismatch; expected length ${parseInt(match[3])}`, "value", value);
|
||||
(0, index_js_4.assertArgument)(array.count === -1 || array.count === value.length, `array length mismatch; expected length ${array.count}`, "value", value);
|
||||
let result = value.map(subEncoder);
|
||||
if (this.#fullTypes.has(subtype)) {
|
||||
result = result.map(index_js_2.keccak256);
|
||||
@ -319,10 +337,10 @@ class TypedDataEncoder {
|
||||
}
|
||||
}
|
||||
// Array
|
||||
const match = type.match(/^(.*)(\x5b(\d*)\x5d)$/);
|
||||
if (match) {
|
||||
(0, index_js_4.assertArgument)(!match[3] || parseInt(match[3]) === value.length, `array length mismatch; expected length ${parseInt(match[3])}`, "value", value);
|
||||
return value.map((v) => this._visit(match[1], v, callback));
|
||||
const array = splitArray(type).array;
|
||||
if (array) {
|
||||
(0, index_js_4.assertArgument)(array.count === -1 || array.count === value.length, `array length mismatch; expected length ${array.count}`, "value", value);
|
||||
return value.map((v) => this._visit(array.prefix, v, callback));
|
||||
}
|
||||
// Struct
|
||||
const fields = this.types[type];
|
||||
|
File diff suppressed because one or more lines are too long
@ -55,6 +55,66 @@ describe("Tests Typed Data (EIP-712) aliases", function () {
|
||||
},
|
||||
encoded: "0xa272ada5f88085e4cb18acdb87bd057a8cbfec249fee53de0149409080947cf500000000000000000000000000000000000000000000000000000000000000231c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac8"
|
||||
},
|
||||
{
|
||||
name: "array-uint",
|
||||
types: {
|
||||
foo: [
|
||||
{ name: "a", type: "uint256[]" },
|
||||
{ name: "b", type: "string" },
|
||||
],
|
||||
},
|
||||
typesAlias: {
|
||||
foo: [
|
||||
{ name: "a", type: "uint[]" },
|
||||
{ name: "b", type: "string" },
|
||||
],
|
||||
},
|
||||
data: {
|
||||
a: [35, 36, 37],
|
||||
b: "hello"
|
||||
},
|
||||
encoded: "0x1a961843d0002bdd66ec21afd6e4a5b0aac34a4b6112890378c6e3a38b752e0b0c22b846886e98aeffc1f1166d4b35868da4d4da853dcb3b2856cfc233fd10c81c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac8"
|
||||
},
|
||||
{
|
||||
name: "array-int",
|
||||
types: {
|
||||
foo: [
|
||||
{ name: "a", type: "int256[]" },
|
||||
{ name: "b", type: "string" },
|
||||
],
|
||||
},
|
||||
typesAlias: {
|
||||
foo: [
|
||||
{ name: "a", type: "int[]" },
|
||||
{ name: "b", type: "string" },
|
||||
],
|
||||
},
|
||||
data: {
|
||||
a: [35, 36, 37],
|
||||
b: "hello"
|
||||
},
|
||||
encoded: "0x0b89085a01a3b67d2231c6a136f9c8eea75d7d479a83a127356f8540ee15af010c22b846886e98aeffc1f1166d4b35868da4d4da853dcb3b2856cfc233fd10c81c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac8"
|
||||
},
|
||||
{
|
||||
name: "nested-array-uint",
|
||||
types: {
|
||||
foo: [
|
||||
{ name: "a", type: "uint256[][]" },
|
||||
{ name: "b", type: "string" },
|
||||
],
|
||||
},
|
||||
typesAlias: {
|
||||
foo: [
|
||||
{ name: "a", type: "uint[][]" },
|
||||
{ name: "b", type: "string" },
|
||||
],
|
||||
},
|
||||
data: {
|
||||
a: [[35, 36], [37]],
|
||||
b: "hello"
|
||||
},
|
||||
encoded: "0x5efa7c4b66979cf78fcc7c3e71cbfa04ec2c7529002642082bf20a91552c1147fa5ffe3a0504d850bc7c9eeda1cf960b596b73f4dc0272a6fa89dace08e320291c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac8"
|
||||
},
|
||||
];
|
||||
for (const test of tests) {
|
||||
it(`tests encoding typed-data: ${test.name}`, function () {
|
||||
|
@ -1 +1 @@
|
||||
{"version":3,"file":"test-hash-typeddata.js","sourceRoot":"","sources":["../../src.ts/_tests/test-hash-typeddata.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAG/C,QAAQ,CAAC,4BAA4B,EAAE;IACnC,MAAM,KAAK,GAAG,SAAS,CAAoB,YAAY,CAAC,CAAC;IACzD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;QACtB,EAAE,CAAC,8BAA+B,IAAI,CAAC,IAAK,EAAE,EA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K"}
|
@ -111,6 +111,23 @@ function getBaseEncoder(type) {
|
||||
function encodeType(name, fields) {
|
||||
return `${name}(${fields.map(({ name, type }) => (type + " " + name)).join(",")})`;
|
||||
}
|
||||
// foo[][3] => { base: "foo", index: "[][3]", array: {
|
||||
// base: "foo", prefix: "foo[]", count: 3 } }
|
||||
function splitArray(type) {
|
||||
const match = type.match(/^([^\x5b]*)((\x5b\d*\x5d)*)(\x5b(\d*)\x5d)$/);
|
||||
if (match) {
|
||||
return {
|
||||
base: match[1],
|
||||
index: (match[2] + match[4]),
|
||||
array: {
|
||||
base: match[1],
|
||||
prefix: (match[1] + match[2]),
|
||||
count: (match[5] ? parseInt(match[5]) : -1),
|
||||
}
|
||||
};
|
||||
}
|
||||
return { base: type };
|
||||
}
|
||||
/**
|
||||
* A **TypedDataEncode** prepares and encodes [[link-eip-712]] payloads
|
||||
* for signed typed data.
|
||||
@ -156,15 +173,16 @@ export class TypedDataEncoder {
|
||||
const subtypes = new Map();
|
||||
const types = {};
|
||||
Object.keys(_types).forEach((type) => {
|
||||
// Normalize int/uint unless they are a complex type themselves
|
||||
types[type] = _types[type].map(({ name, type }) => {
|
||||
if (type === "int" && !_types["int"]) {
|
||||
type = "int256";
|
||||
// Normalize the base type (unless name conflict)
|
||||
let { base, index } = splitArray(type);
|
||||
if (base === "int" && !_types["int"]) {
|
||||
base = "int256";
|
||||
}
|
||||
if (type === "uint" && !_types["uint"]) {
|
||||
type = "uint256";
|
||||
if (base === "uint" && !_types["uint"]) {
|
||||
base = "uint256";
|
||||
}
|
||||
return { name, type };
|
||||
return { name, type: (base + (index || "")) };
|
||||
});
|
||||
links.set(type, new Set());
|
||||
parents.set(type, []);
|
||||
@ -178,7 +196,7 @@ export class TypedDataEncoder {
|
||||
assertArgument(!uniqueNames.has(field.name), `duplicate variable name ${JSON.stringify(field.name)} in ${JSON.stringify(name)}`, "types", _types);
|
||||
uniqueNames.add(field.name);
|
||||
// Get the base type (drop any array specifiers)
|
||||
const baseType = (field.type.match(/^([^\x5b]*)(\x5b|$)/))[1] || null;
|
||||
const baseType = splitArray(field.type).base;
|
||||
assertArgument(baseType !== name, `circular type reference to ${JSON.stringify(baseType)}`, "types", _types);
|
||||
// Is this a base encoding type?
|
||||
const encoder = getBaseEncoder(baseType);
|
||||
@ -241,12 +259,12 @@ export class TypedDataEncoder {
|
||||
}
|
||||
}
|
||||
// Array
|
||||
const match = type.match(/^(.*)(\x5b(\d*)\x5d)$/);
|
||||
if (match) {
|
||||
const subtype = match[1];
|
||||
const array = splitArray(type).array;
|
||||
if (array) {
|
||||
const subtype = array.prefix;
|
||||
const subEncoder = this.getEncoder(subtype);
|
||||
return (value) => {
|
||||
assertArgument(!match[3] || parseInt(match[3]) === value.length, `array length mismatch; expected length ${parseInt(match[3])}`, "value", value);
|
||||
assertArgument(array.count === -1 || array.count === value.length, `array length mismatch; expected length ${array.count}`, "value", value);
|
||||
let result = value.map(subEncoder);
|
||||
if (this.#fullTypes.has(subtype)) {
|
||||
result = result.map(keccak256);
|
||||
@ -316,10 +334,10 @@ export class TypedDataEncoder {
|
||||
}
|
||||
}
|
||||
// Array
|
||||
const match = type.match(/^(.*)(\x5b(\d*)\x5d)$/);
|
||||
if (match) {
|
||||
assertArgument(!match[3] || parseInt(match[3]) === value.length, `array length mismatch; expected length ${parseInt(match[3])}`, "value", value);
|
||||
return value.map((v) => this._visit(match[1], v, callback));
|
||||
const array = splitArray(type).array;
|
||||
if (array) {
|
||||
assertArgument(array.count === -1 || array.count === value.length, `array length mismatch; expected length ${array.count}`, "value", value);
|
||||
return value.map((v) => this._visit(array.prefix, v, callback));
|
||||
}
|
||||
// Struct
|
||||
const fields = this.types[type];
|
||||
|
File diff suppressed because one or more lines are too long
@ -93,7 +93,7 @@
|
||||
"url": "https://www.buymeacoffee.com/ricmoo"
|
||||
}
|
||||
],
|
||||
"gitHead": "84ca14f1ffc5afbdd7f4c26a9b734ec5951eee3c",
|
||||
"gitHead": "8f99601df1f26a8ba4d6d9dea5e033e7f688107e",
|
||||
"homepage": "https://ethers.org",
|
||||
"keywords": [
|
||||
"ethereum",
|
||||
|
Loading…
Reference in New Issue
Block a user