refactor: move brother_node development artifact to dev/test-nodes subdirectory

Development Artifact Cleanup:
 BROTHER_NODE REORGANIZATION: Moved development test node to appropriate location
- dev/test-nodes/brother_node/: Moved from root directory for better organization
- Contains development configuration, test logs, and test chain data
- No impact on production systems - purely development/testing artifact

 DEVELOPMENT ARTIFACTS IDENTIFIED:
- Chain ID: aitbc-brother-chain (test/development chain)
- Ports: 8010 (P2P) and 8011 (RPC) - different from production
- Environment: .env file with test configuration
- Logs: rpc.log and node.log from development testing session (March 15, 2026)

 ROOT DIRECTORY CLEANUP: Removed development clutter from production directory
- brother_node/ moved to dev/test-nodes/brother_node/
- Root directory now contains only production-ready components
- Development artifacts properly organized in dev/ subdirectory

DIRECTORY STRUCTURE IMPROVEMENT:
📁 dev/test-nodes/: Development and testing node configurations
🏗️ Root Directory: Clean production structure with only essential components
🧪 Development Isolation: Test environments separated from production

BENEFITS:
 Clean Production Directory: No development artifacts in root
 Better Organization: Development nodes grouped in dev/ subdirectory
 Clear Separation: Production vs development environments clearly distinguished
 Maintainability: Easier to identify and manage development components

RESULT: Successfully moved brother_node development artifact to dev/test-nodes/ subdirectory, cleaning up the root directory while preserving development testing environment for future use.
This commit is contained in:
2026-03-30 17:09:06 +02:00
parent bf730dcb4a
commit 816e258d4c
11734 changed files with 2001707 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
import type { Addressable } from "../address/index.js";
import type { SignatureLike } from "../crypto/index.js";
import type { BigNumberish, Numeric } from "../utils/index.js";
export interface AuthorizationRequest {
address: string | Addressable;
nonce?: Numeric;
chainId?: BigNumberish;
}
/**
* Computes the [[link-eip-7702]] authorization digest to sign.
*/
export declare function hashAuthorization(auth: AuthorizationRequest): string;
/**
* Return the address of the private key that produced
* the signature %%sig%% during signing for %%message%%.
*/
export declare function verifyAuthorization(auth: AuthorizationRequest, sig: SignatureLike): string;
//# sourceMappingURL=authorization.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"authorization.d.ts","sourceRoot":"","sources":["../../src.ts/hash/authorization.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE/D,MAAM,WAAW,oBAAoB;IACjC,OAAO,EAAE,MAAM,GAAG,WAAW,CAAC;IAC9B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,YAAY,CAAC;CAC1B;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,oBAAoB,GAAG,MAAM,CASpE;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,oBAAoB,EAAE,GAAG,EAAE,aAAa,GAAG,MAAM,CAE1F"}

View File

@@ -0,0 +1,30 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.verifyAuthorization = exports.hashAuthorization = void 0;
const index_js_1 = require("../address/index.js");
const index_js_2 = require("../crypto/index.js");
const index_js_3 = require("../transaction/index.js");
const index_js_4 = require("../utils/index.js");
/**
* Computes the [[link-eip-7702]] authorization digest to sign.
*/
function hashAuthorization(auth) {
(0, index_js_4.assertArgument)(typeof (auth.address) === "string", "invalid address for hashAuthorization", "auth.address", auth);
return (0, index_js_2.keccak256)((0, index_js_4.concat)([
"0x05", (0, index_js_4.encodeRlp)([
(auth.chainId != null) ? (0, index_js_4.toBeArray)(auth.chainId) : "0x",
(0, index_js_1.getAddress)(auth.address),
(auth.nonce != null) ? (0, index_js_4.toBeArray)(auth.nonce) : "0x",
])
]));
}
exports.hashAuthorization = hashAuthorization;
/**
* Return the address of the private key that produced
* the signature %%sig%% during signing for %%message%%.
*/
function verifyAuthorization(auth, sig) {
return (0, index_js_3.recoverAddress)(hashAuthorization(auth), sig);
}
exports.verifyAuthorization = verifyAuthorization;
//# sourceMappingURL=authorization.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"authorization.js","sourceRoot":"","sources":["../../src.ts/hash/authorization.ts"],"names":[],"mappings":";;;AAAA,kDAAiD;AACjD,iDAA+C;AAC/C,sDAAyD;AACzD,gDAE2B;AAY3B;;GAEG;AACH,SAAgB,iBAAiB,CAAC,IAA0B;IACxD,IAAA,yBAAc,EAAC,OAAM,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,QAAQ,EAAE,uCAAuC,EAAE,cAAc,EAAE,IAAI,CAAC,CAAC;IACjH,OAAO,IAAA,oBAAS,EAAC,IAAA,iBAAM,EAAC;QACpB,MAAM,EAAE,IAAA,oBAAS,EAAC;YACd,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,IAAA,oBAAS,EAAC,IAAI,CAAC,OAAO,CAAC,CAAA,CAAC,CAAC,IAAI;YACtD,IAAA,qBAAU,EAAC,IAAI,CAAC,OAAO,CAAC;YACxB,CAAC,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,IAAA,oBAAS,EAAC,IAAI,CAAC,KAAK,CAAC,CAAA,CAAC,CAAC,IAAI;SACrD,CAAC;KACL,CAAC,CAAC,CAAC;AACR,CAAC;AATD,8CASC;AAED;;;GAGG;AACH,SAAgB,mBAAmB,CAAC,IAA0B,EAAE,GAAkB;IAC9E,OAAO,IAAA,yBAAc,EAAC,iBAAiB,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC;AACxD,CAAC;AAFD,kDAEC"}

13
dev/env/node_modules/ethers/lib.commonjs/hash/id.d.ts generated vendored Executable file
View File

@@ -0,0 +1,13 @@
/**
* A simple hashing function which operates on UTF-8 strings to
* compute an 32-byte identifier.
*
* This simply computes the [UTF-8 bytes](toUtf8Bytes) and computes
* the [[keccak256]].
*
* @example:
* id("hello world")
* //_result:
*/
export declare function id(value: string): string;
//# sourceMappingURL=id.d.ts.map

1
dev/env/node_modules/ethers/lib.commonjs/hash/id.d.ts.map generated vendored Executable file
View File

@@ -0,0 +1 @@
{"version":3,"file":"id.d.ts","sourceRoot":"","sources":["../../src.ts/hash/id.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;GAUG;AACH,wBAAgB,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAExC"}

21
dev/env/node_modules/ethers/lib.commonjs/hash/id.js generated vendored Executable file
View File

@@ -0,0 +1,21 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.id = void 0;
const index_js_1 = require("../crypto/index.js");
const index_js_2 = require("../utils/index.js");
/**
* A simple hashing function which operates on UTF-8 strings to
* compute an 32-byte identifier.
*
* This simply computes the [UTF-8 bytes](toUtf8Bytes) and computes
* the [[keccak256]].
*
* @example:
* id("hello world")
* //_result:
*/
function id(value) {
return (0, index_js_1.keccak256)((0, index_js_2.toUtf8Bytes)(value));
}
exports.id = id;
//# sourceMappingURL=id.js.map

1
dev/env/node_modules/ethers/lib.commonjs/hash/id.js.map generated vendored Executable file
View File

@@ -0,0 +1 @@
{"version":3,"file":"id.js","sourceRoot":"","sources":["../../src.ts/hash/id.ts"],"names":[],"mappings":";;;AAAA,iDAA+C;AAC/C,gDAAgD;AAEhD;;;;;;;;;;GAUG;AACH,SAAgB,EAAE,CAAC,KAAa;IAC5B,OAAO,IAAA,oBAAS,EAAC,IAAA,sBAAW,EAAC,KAAK,CAAC,CAAC,CAAC;AACzC,CAAC;AAFD,gBAEC"}

15
dev/env/node_modules/ethers/lib.commonjs/hash/index.d.ts generated vendored Executable file
View File

@@ -0,0 +1,15 @@
/**
* Utilities for common tasks involving hashing. Also see
* [cryptographic hashing](about-crypto-hashing).
*
* @_section: api/hashing:Hashing Utilities [about-hashing]
*/
export { hashAuthorization, verifyAuthorization } from "./authorization.js";
export { id } from "./id.js";
export { ensNormalize, isValidName, namehash, dnsEncode } from "./namehash.js";
export { hashMessage, verifyMessage } from "./message.js";
export { solidityPacked, solidityPackedKeccak256, solidityPackedSha256 } from "./solidity.js";
export { TypedDataEncoder, verifyTypedData } from "./typed-data.js";
export type { AuthorizationRequest } from "./authorization.js";
export type { TypedDataDomain, TypedDataField } from "./typed-data.js";
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src.ts/hash/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/E,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EACH,cAAc,EAAE,uBAAuB,EAAE,oBAAoB,EAChE,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEpE,YAAY,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC"}

30
dev/env/node_modules/ethers/lib.commonjs/hash/index.js generated vendored Executable file
View File

@@ -0,0 +1,30 @@
"use strict";
/**
* Utilities for common tasks involving hashing. Also see
* [cryptographic hashing](about-crypto-hashing).
*
* @_section: api/hashing:Hashing Utilities [about-hashing]
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.verifyTypedData = exports.TypedDataEncoder = exports.solidityPackedSha256 = exports.solidityPackedKeccak256 = exports.solidityPacked = exports.verifyMessage = exports.hashMessage = exports.dnsEncode = exports.namehash = exports.isValidName = exports.ensNormalize = exports.id = exports.verifyAuthorization = exports.hashAuthorization = void 0;
var authorization_js_1 = require("./authorization.js");
Object.defineProperty(exports, "hashAuthorization", { enumerable: true, get: function () { return authorization_js_1.hashAuthorization; } });
Object.defineProperty(exports, "verifyAuthorization", { enumerable: true, get: function () { return authorization_js_1.verifyAuthorization; } });
var id_js_1 = require("./id.js");
Object.defineProperty(exports, "id", { enumerable: true, get: function () { return id_js_1.id; } });
var namehash_js_1 = require("./namehash.js");
Object.defineProperty(exports, "ensNormalize", { enumerable: true, get: function () { return namehash_js_1.ensNormalize; } });
Object.defineProperty(exports, "isValidName", { enumerable: true, get: function () { return namehash_js_1.isValidName; } });
Object.defineProperty(exports, "namehash", { enumerable: true, get: function () { return namehash_js_1.namehash; } });
Object.defineProperty(exports, "dnsEncode", { enumerable: true, get: function () { return namehash_js_1.dnsEncode; } });
var message_js_1 = require("./message.js");
Object.defineProperty(exports, "hashMessage", { enumerable: true, get: function () { return message_js_1.hashMessage; } });
Object.defineProperty(exports, "verifyMessage", { enumerable: true, get: function () { return message_js_1.verifyMessage; } });
var solidity_js_1 = require("./solidity.js");
Object.defineProperty(exports, "solidityPacked", { enumerable: true, get: function () { return solidity_js_1.solidityPacked; } });
Object.defineProperty(exports, "solidityPackedKeccak256", { enumerable: true, get: function () { return solidity_js_1.solidityPackedKeccak256; } });
Object.defineProperty(exports, "solidityPackedSha256", { enumerable: true, get: function () { return solidity_js_1.solidityPackedSha256; } });
var typed_data_js_1 = require("./typed-data.js");
Object.defineProperty(exports, "TypedDataEncoder", { enumerable: true, get: function () { return typed_data_js_1.TypedDataEncoder; } });
Object.defineProperty(exports, "verifyTypedData", { enumerable: true, get: function () { return typed_data_js_1.verifyTypedData; } });
//# sourceMappingURL=index.js.map

1
dev/env/node_modules/ethers/lib.commonjs/hash/index.js.map generated vendored Executable file
View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src.ts/hash/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,uDAA4E;AAAnE,qHAAA,iBAAiB,OAAA;AAAE,uHAAA,mBAAmB,OAAA;AAC/C,iCAA4B;AAAnB,2FAAA,EAAE,OAAA;AACX,6CAA+E;AAAtE,2GAAA,YAAY,OAAA;AAAE,0GAAA,WAAW,OAAA;AAAE,uGAAA,QAAQ,OAAA;AAAE,wGAAA,SAAS,OAAA;AACvD,2CAA0D;AAAjD,yGAAA,WAAW,OAAA;AAAE,2GAAA,aAAa,OAAA;AACnC,6CAEuB;AADnB,6GAAA,cAAc,OAAA;AAAE,sHAAA,uBAAuB,OAAA;AAAE,mHAAA,oBAAoB,OAAA;AAEjE,iDAAoE;AAA3D,iHAAA,gBAAgB,OAAA;AAAE,gHAAA,eAAe,OAAA"}

36
dev/env/node_modules/ethers/lib.commonjs/hash/message.d.ts generated vendored Executable file
View File

@@ -0,0 +1,36 @@
import type { SignatureLike } from "../crypto/index.js";
/**
* Computes the [[link-eip-191]] personal-sign message digest to sign.
*
* This prefixes the message with [[MessagePrefix]] and the decimal length
* of %%message%% and computes the [[keccak256]] digest.
*
* If %%message%% is a string, it is converted to its UTF-8 bytes
* first. To compute the digest of a [[DataHexString]], it must be converted
* to [bytes](getBytes).
*
* @example:
* hashMessage("Hello World")
* //_result:
*
* // Hashes the SIX (6) string characters, i.e.
* // [ "0", "x", "4", "2", "4", "3" ]
* hashMessage("0x4243")
* //_result:
*
* // Hashes the TWO (2) bytes [ 0x42, 0x43 ]...
* hashMessage(getBytes("0x4243"))
* //_result:
*
* // ...which is equal to using data
* hashMessage(new Uint8Array([ 0x42, 0x43 ]))
* //_result:
*
*/
export declare function hashMessage(message: Uint8Array | string): string;
/**
* Return the address of the private key that produced
* the signature %%sig%% during signing for %%message%%.
*/
export declare function verifyMessage(message: Uint8Array | string, sig: SignatureLike): string;
//# sourceMappingURL=message.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../src.ts/hash/message.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM,GAAG,MAAM,CAOhE;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM,EAAE,GAAG,EAAE,aAAa,GAAG,MAAM,CAGtF"}

56
dev/env/node_modules/ethers/lib.commonjs/hash/message.js generated vendored Executable file
View File

@@ -0,0 +1,56 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.verifyMessage = exports.hashMessage = void 0;
const index_js_1 = require("../crypto/index.js");
const index_js_2 = require("../constants/index.js");
const index_js_3 = require("../transaction/index.js");
const index_js_4 = require("../utils/index.js");
/**
* Computes the [[link-eip-191]] personal-sign message digest to sign.
*
* This prefixes the message with [[MessagePrefix]] and the decimal length
* of %%message%% and computes the [[keccak256]] digest.
*
* If %%message%% is a string, it is converted to its UTF-8 bytes
* first. To compute the digest of a [[DataHexString]], it must be converted
* to [bytes](getBytes).
*
* @example:
* hashMessage("Hello World")
* //_result:
*
* // Hashes the SIX (6) string characters, i.e.
* // [ "0", "x", "4", "2", "4", "3" ]
* hashMessage("0x4243")
* //_result:
*
* // Hashes the TWO (2) bytes [ 0x42, 0x43 ]...
* hashMessage(getBytes("0x4243"))
* //_result:
*
* // ...which is equal to using data
* hashMessage(new Uint8Array([ 0x42, 0x43 ]))
* //_result:
*
*/
function hashMessage(message) {
if (typeof (message) === "string") {
message = (0, index_js_4.toUtf8Bytes)(message);
}
return (0, index_js_1.keccak256)((0, index_js_4.concat)([
(0, index_js_4.toUtf8Bytes)(index_js_2.MessagePrefix),
(0, index_js_4.toUtf8Bytes)(String(message.length)),
message
]));
}
exports.hashMessage = hashMessage;
/**
* Return the address of the private key that produced
* the signature %%sig%% during signing for %%message%%.
*/
function verifyMessage(message, sig) {
const digest = hashMessage(message);
return (0, index_js_3.recoverAddress)(digest, sig);
}
exports.verifyMessage = verifyMessage;
//# sourceMappingURL=message.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"message.js","sourceRoot":"","sources":["../../src.ts/hash/message.ts"],"names":[],"mappings":";;;AAAA,iDAA+C;AAC/C,oDAAsD;AACtD,sDAAyD;AACzD,gDAAwD;AAGxD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,SAAgB,WAAW,CAAC,OAA4B;IACpD,IAAI,OAAM,CAAC,OAAO,CAAC,KAAK,QAAQ,EAAE;QAAE,OAAO,GAAG,IAAA,sBAAW,EAAC,OAAO,CAAC,CAAC;KAAE;IACrE,OAAO,IAAA,oBAAS,EAAC,IAAA,iBAAM,EAAC;QACpB,IAAA,sBAAW,EAAC,wBAAa,CAAC;QAC1B,IAAA,sBAAW,EAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACnC,OAAO;KACV,CAAC,CAAC,CAAC;AACR,CAAC;AAPD,kCAOC;AAED;;;GAGG;AACH,SAAgB,aAAa,CAAC,OAA4B,EAAE,GAAkB;IAC1E,MAAM,MAAM,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;IACpC,OAAO,IAAA,yBAAc,EAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AACvC,CAAC;AAHD,sCAGC"}

20
dev/env/node_modules/ethers/lib.commonjs/hash/namehash.d.ts generated vendored Executable file
View File

@@ -0,0 +1,20 @@
/**
* Returns the ENS %%name%% normalized.
*/
export declare function ensNormalize(name: string): string;
/**
* Returns ``true`` if %%name%% is a valid ENS name.
*/
export declare function isValidName(name: string): name is string;
/**
* Returns the [[link-namehash]] for %%name%%.
*/
export declare function namehash(name: string): string;
/**
* Returns the DNS encoded %%name%%.
*
* This is used for various parts of ENS name resolution, such
* as the wildcard resolution.
*/
export declare function dnsEncode(name: string, _maxLength?: number): string;
//# sourceMappingURL=namehash.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"namehash.d.ts","sourceRoot":"","sources":["../../src.ts/hash/namehash.ts"],"names":[],"mappings":"AAyCA;;GAEG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAOjD;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,MAAM,CAKxD;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAa7C;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAanE"}

91
dev/env/node_modules/ethers/lib.commonjs/hash/namehash.js generated vendored Executable file
View File

@@ -0,0 +1,91 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.dnsEncode = exports.namehash = exports.isValidName = exports.ensNormalize = void 0;
const index_js_1 = require("../crypto/index.js");
const index_js_2 = require("../utils/index.js");
const ens_normalize_1 = require("@adraffy/ens-normalize");
const Zeros = new Uint8Array(32);
Zeros.fill(0);
function checkComponent(comp) {
(0, index_js_2.assertArgument)(comp.length !== 0, "invalid ENS name; empty component", "comp", comp);
return comp;
}
function ensNameSplit(name) {
const bytes = (0, index_js_2.toUtf8Bytes)(ensNormalize(name));
const comps = [];
if (name.length === 0) {
return comps;
}
let last = 0;
for (let i = 0; i < bytes.length; i++) {
const d = bytes[i];
// A separator (i.e. "."); copy this component
if (d === 0x2e) {
comps.push(checkComponent(bytes.slice(last, i)));
last = i + 1;
}
}
// There was a stray separator at the end of the name
(0, index_js_2.assertArgument)(last < bytes.length, "invalid ENS name; empty component", "name", name);
comps.push(checkComponent(bytes.slice(last)));
return comps;
}
/**
* Returns the ENS %%name%% normalized.
*/
function ensNormalize(name) {
try {
if (name.length === 0) {
throw new Error("empty label");
}
return (0, ens_normalize_1.ens_normalize)(name);
}
catch (error) {
(0, index_js_2.assertArgument)(false, `invalid ENS name (${error.message})`, "name", name);
}
}
exports.ensNormalize = ensNormalize;
/**
* Returns ``true`` if %%name%% is a valid ENS name.
*/
function isValidName(name) {
try {
return (ensNameSplit(name).length !== 0);
}
catch (error) { }
return false;
}
exports.isValidName = isValidName;
/**
* Returns the [[link-namehash]] for %%name%%.
*/
function namehash(name) {
(0, index_js_2.assertArgument)(typeof (name) === "string", "invalid ENS name; not a string", "name", name);
(0, index_js_2.assertArgument)(name.length, `invalid ENS name (empty label)`, "name", name);
let result = Zeros;
const comps = ensNameSplit(name);
while (comps.length) {
result = (0, index_js_1.keccak256)((0, index_js_2.concat)([result, (0, index_js_1.keccak256)((comps.pop()))]));
}
return (0, index_js_2.hexlify)(result);
}
exports.namehash = namehash;
/**
* Returns the DNS encoded %%name%%.
*
* This is used for various parts of ENS name resolution, such
* as the wildcard resolution.
*/
function dnsEncode(name, _maxLength) {
const length = (_maxLength != null) ? _maxLength : 63;
(0, index_js_2.assertArgument)(length <= 255, "DNS encoded label cannot exceed 255", "length", length);
return (0, index_js_2.hexlify)((0, index_js_2.concat)(ensNameSplit(name).map((comp) => {
(0, index_js_2.assertArgument)(comp.length <= length, `label ${JSON.stringify(name)} exceeds ${length} bytes`, "name", name);
const bytes = new Uint8Array(comp.length + 1);
bytes.set(comp, 1);
bytes[0] = bytes.length - 1;
return bytes;
}))) + "00";
}
exports.dnsEncode = dnsEncode;
//# sourceMappingURL=namehash.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"namehash.js","sourceRoot":"","sources":["../../src.ts/hash/namehash.ts"],"names":[],"mappings":";;;AACA,iDAA+C;AAC/C,gDAE2B;AAG3B,0DAAuD;AAEvD,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;AACjC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAEd,SAAS,cAAc,CAAC,IAAgB;IACpC,IAAA,yBAAc,EAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,mCAAmC,EAAE,MAAM,EAAE,IAAI,CAAC,CAAA;IACpF,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,SAAS,YAAY,CAAC,IAAY;IAC9B,MAAM,KAAK,GAAG,IAAA,sBAAW,EA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SAAU,IAAI,CAAC,SAAS,CAAC,IAAI,CAAE,YAAa,MAAO,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;QAEjH,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAC9C,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;QACnB,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;QAC5B,OAAO,KAAK,CAAC;IACjB,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;AAChB,CAAC;AAbD,8BAaC"}

31
dev/env/node_modules/ethers/lib.commonjs/hash/solidity.d.ts generated vendored Executable file
View File

@@ -0,0 +1,31 @@
/**
* Computes the [[link-solc-packed]] representation of %%values%%
* respectively to their %%types%%.
*
* @example:
* addr = "0x8ba1f109551bd432803012645ac136ddd64dba72"
* solidityPacked([ "address", "uint" ], [ addr, 45 ]);
* //_result:
*/
export declare function solidityPacked(types: ReadonlyArray<string>, values: ReadonlyArray<any>): string;
/**
* Computes the [[link-solc-packed]] [[keccak256]] hash of %%values%%
* respectively to their %%types%%.
*
* @example:
* addr = "0x8ba1f109551bd432803012645ac136ddd64dba72"
* solidityPackedKeccak256([ "address", "uint" ], [ addr, 45 ]);
* //_result:
*/
export declare function solidityPackedKeccak256(types: ReadonlyArray<string>, values: ReadonlyArray<any>): string;
/**
* Computes the [[link-solc-packed]] [[sha256]] hash of %%values%%
* respectively to their %%types%%.
*
* @example:
* addr = "0x8ba1f109551bd432803012645ac136ddd64dba72"
* solidityPackedSha256([ "address", "uint" ], [ addr, 45 ]);
* //_result:
*/
export declare function solidityPackedSha256(types: ReadonlyArray<string>, values: ReadonlyArray<any>): string;
//# sourceMappingURL=solidity.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"solidity.d.ts","sourceRoot":"","sources":["../../src.ts/hash/solidity.ts"],"names":[],"mappings":"AAyEA;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,GAAG,CAAC,GAAG,MAAM,CAQ/F;AAED;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,GAAG,CAAC,GAAG,MAAM,CAExG;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,GAAG,CAAC,GAAG,MAAM,CAErG"}

109
dev/env/node_modules/ethers/lib.commonjs/hash/solidity.js generated vendored Executable file
View File

@@ -0,0 +1,109 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.solidityPackedSha256 = exports.solidityPackedKeccak256 = exports.solidityPacked = void 0;
const index_js_1 = require("../address/index.js");
const index_js_2 = require("../crypto/index.js");
const index_js_3 = require("../utils/index.js");
const regexBytes = new RegExp("^bytes([0-9]+)$");
const regexNumber = new RegExp("^(u?int)([0-9]*)$");
const regexArray = new RegExp("^(.*)\\[([0-9]*)\\]$");
function _pack(type, value, isArray) {
switch (type) {
case "address":
if (isArray) {
return (0, index_js_3.getBytes)((0, index_js_3.zeroPadValue)(value, 32));
}
return (0, index_js_3.getBytes)((0, index_js_1.getAddress)(value));
case "string":
return (0, index_js_3.toUtf8Bytes)(value);
case "bytes":
return (0, index_js_3.getBytes)(value);
case "bool":
value = (!!value ? "0x01" : "0x00");
if (isArray) {
return (0, index_js_3.getBytes)((0, index_js_3.zeroPadValue)(value, 32));
}
return (0, index_js_3.getBytes)(value);
}
let match = type.match(regexNumber);
if (match) {
let signed = (match[1] === "int");
let size = parseInt(match[2] || "256");
(0, index_js_3.assertArgument)((!match[2] || match[2] === String(size)) && (size % 8 === 0) && size !== 0 && size <= 256, "invalid number type", "type", type);
if (isArray) {
size = 256;
}
if (signed) {
value = (0, index_js_3.toTwos)(value, size);
}
return (0, index_js_3.getBytes)((0, index_js_3.zeroPadValue)((0, index_js_3.toBeArray)(value), size / 8));
}
match = type.match(regexBytes);
if (match) {
const size = parseInt(match[1]);
(0, index_js_3.assertArgument)(String(size) === match[1] && size !== 0 && size <= 32, "invalid bytes type", "type", type);
(0, index_js_3.assertArgument)((0, index_js_3.dataLength)(value) === size, `invalid value for ${type}`, "value", value);
if (isArray) {
return (0, index_js_3.getBytes)((0, index_js_3.zeroPadBytes)(value, 32));
}
return value;
}
match = type.match(regexArray);
if (match && Array.isArray(value)) {
const baseType = match[1];
const count = parseInt(match[2] || String(value.length));
(0, index_js_3.assertArgument)(count === value.length, `invalid array length for ${type}`, "value", value);
const result = [];
value.forEach(function (value) {
result.push(_pack(baseType, value, true));
});
return (0, index_js_3.getBytes)((0, index_js_3.concat)(result));
}
(0, index_js_3.assertArgument)(false, "invalid type", "type", type);
}
// @TODO: Array Enum
/**
* Computes the [[link-solc-packed]] representation of %%values%%
* respectively to their %%types%%.
*
* @example:
* addr = "0x8ba1f109551bd432803012645ac136ddd64dba72"
* solidityPacked([ "address", "uint" ], [ addr, 45 ]);
* //_result:
*/
function solidityPacked(types, values) {
(0, index_js_3.assertArgument)(types.length === values.length, "wrong number of values; expected ${ types.length }", "values", values);
const tight = [];
types.forEach(function (type, index) {
tight.push(_pack(type, values[index]));
});
return (0, index_js_3.hexlify)((0, index_js_3.concat)(tight));
}
exports.solidityPacked = solidityPacked;
/**
* Computes the [[link-solc-packed]] [[keccak256]] hash of %%values%%
* respectively to their %%types%%.
*
* @example:
* addr = "0x8ba1f109551bd432803012645ac136ddd64dba72"
* solidityPackedKeccak256([ "address", "uint" ], [ addr, 45 ]);
* //_result:
*/
function solidityPackedKeccak256(types, values) {
return (0, index_js_2.keccak256)(solidityPacked(types, values));
}
exports.solidityPackedKeccak256 = solidityPackedKeccak256;
/**
* Computes the [[link-solc-packed]] [[sha256]] hash of %%values%%
* respectively to their %%types%%.
*
* @example:
* addr = "0x8ba1f109551bd432803012645ac136ddd64dba72"
* solidityPackedSha256([ "address", "uint" ], [ addr, 45 ]);
* //_result:
*/
function solidityPackedSha256(types, values) {
return (0, index_js_2.sha256)(solidityPacked(types, values));
}
exports.solidityPackedSha256 = solidityPackedSha256;
//# sourceMappingURL=solidity.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"solidity.js","sourceRoot":"","sources":["../../src.ts/hash/solidity.ts"],"names":[],"mappings":";;;AAAA,kDAAiD;AACjD,iDAE4B;AAC5B,gDAG2B;AAG3B,MAAM,UAAU,GAAG,IAAI,MAAM,CAAC,iBAAiB,CAAC,CAAC;AACjD,MAAM,WAAW,GAAG,IAAI,MAAM,CAAC,mBAAmB,CAAC,CAAC;AACpD,MAAM,UAAU,GAAG,IAAI,MAAM,CAAC,sBAAsB,CAAC,CAAC;AAGtD,SAAS,KAAK,CAAC,IAAY,EAAE,KAAU,EAAE,OAAiB;IACtD,QAAO,IAAI,EAAE;QACT,KAAK,SAAS;YACV,IAAI,OAAO,EAAE;gBAAE,OAAO,IAAA,mBAAQ,EAAC,IAAA,uBAAY,EAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC;aAAE;YAC1D,OAAO,IAAA,mBAAQ,EAAC,IAAA,qBAAU,EAAC,KAAK,CAAC,CAAC,CAAC;QACvC,KAAK,QAAQ;YACT,OAAO,IAAA,sBAAW,EAAC,KAAK,CAAC,CAAC;QAC9B,KAAK,OAAO;YACR,OAAO,IAAA,mBAAQ,EAAC,KAAK,CAAC,CAAC;QAC3B,KAAK,MAAM;YACP,KAAK,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAA,CAAC,CAAC,MAAM,CAAC,CAAC;YACnC,IAAI,OAAO,EAAE;gBAAE,OAAO,IAAA,mBAAQ,EAAC,IAAA,uBAAY,EAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC;aAAE;YAC1D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CAAC,CAAC;IAEvH,MAAM,KAAK,GAAsB,EAAE,CAAC;IACpC,KAAK,CAAC,OAAO,CAAC,UAAS,IAAI,EAAE,KAAK;QAC9B,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;IACH,OAAO,IAAA,kBAAO,EAAC,IAAA,iBAAM,EAAC,KAAK,CAAC,CAAC,CAAC;AAClC,CAAC;AARD,wCAQC;AAED;;;;;;;;GAQG;AACH,SAAgB,uBAAuB,CAAC,KAA4B,EAAE,MAA0B;IAC5F,OAAO,IAAA,oBAAU,EAAC,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;AACrD,CAAC;AAFD,0DAEC;AAED;;;;;;;;GAQG;AACH,SAAgB,oBAAoB,CAAC,KAA4B,EAAE,MAA0B;IACzF,OAAO,IAAA,iBAAO,EAAC,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;AAClD,CAAC;AAFD,oDAEC"}

150
dev/env/node_modules/ethers/lib.commonjs/hash/typed-data.d.ts generated vendored Executable file
View File

@@ -0,0 +1,150 @@
import type { SignatureLike } from "../crypto/index.js";
import type { BigNumberish, BytesLike } from "../utils/index.js";
/**
* The domain for an [[link-eip-712]] payload.
*/
export interface TypedDataDomain {
/**
* The human-readable name of the signing domain.
*/
name?: null | string;
/**
* The major version of the signing domain.
*/
version?: null | string;
/**
* The chain ID of the signing domain.
*/
chainId?: null | BigNumberish;
/**
* The the address of the contract that will verify the signature.
*/
verifyingContract?: null | string;
/**
* A salt used for purposes decided by the specific domain.
*/
salt?: null | BytesLike;
}
/**
* A specific field of a structured [[link-eip-712]] type.
*/
export interface TypedDataField {
/**
* The field name.
*/
name: string;
/**
* The type of the field.
*/
type: string;
}
/**
* A **TypedDataEncode** prepares and encodes [[link-eip-712]] payloads
* for signed typed data.
*
* This is useful for those that wish to compute various components of a
* typed data hash, primary types, or sub-components, but generally the
* higher level [[Signer-signTypedData]] is more useful.
*/
export declare class TypedDataEncoder {
#private;
/**
* The primary type for the structured [[types]].
*
* This is derived automatically from the [[types]], since no
* recursion is possible, once the DAG for the types is consturcted
* internally, the primary type must be the only remaining type with
* no parent nodes.
*/
readonly primaryType: string;
/**
* The types.
*/
get types(): Record<string, Array<TypedDataField>>;
/**
* Create a new **TypedDataEncoder** for %%types%%.
*
* This performs all necessary checking that types are valid and
* do not violate the [[link-eip-712]] structural constraints as
* well as computes the [[primaryType]].
*/
constructor(_types: Record<string, Array<TypedDataField>>);
/**
* Returnthe encoder for the specific %%type%%.
*/
getEncoder(type: string): (value: any) => string;
/**
* Return the full type for %%name%%.
*/
encodeType(name: string): string;
/**
* Return the encoded %%value%% for the %%type%%.
*/
encodeData(type: string, value: any): string;
/**
* Returns the hash of %%value%% for the type of %%name%%.
*/
hashStruct(name: string, value: Record<string, any>): string;
/**
* Return the fulled encoded %%value%% for the [[types]].
*/
encode(value: Record<string, any>): string;
/**
* Return the hash of the fully encoded %%value%% for the [[types]].
*/
hash(value: Record<string, any>): string;
/**
* @_ignore:
*/
_visit(type: string, value: any, callback: (type: string, data: any) => any): any;
/**
* Call %%calback%% for each value in %%value%%, passing the type and
* component within %%value%%.
*
* This is useful for replacing addresses or other transformation that
* may be desired on each component, based on its type.
*/
visit(value: Record<string, any>, callback: (type: string, data: any) => any): any;
/**
* Create a new **TypedDataEncoder** for %%types%%.
*/
static from(types: Record<string, Array<TypedDataField>>): TypedDataEncoder;
/**
* Return the primary type for %%types%%.
*/
static getPrimaryType(types: Record<string, Array<TypedDataField>>): string;
/**
* Return the hashed struct for %%value%% using %%types%% and %%name%%.
*/
static hashStruct(name: string, types: Record<string, Array<TypedDataField>>, value: Record<string, any>): string;
/**
* Return the domain hash for %%domain%%.
*/
static hashDomain(domain: TypedDataDomain): string;
/**
* Return the fully encoded [[link-eip-712]] %%value%% for %%types%% with %%domain%%.
*/
static encode(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, value: Record<string, any>): string;
/**
* Return the hash of the fully encoded [[link-eip-712]] %%value%% for %%types%% with %%domain%%.
*/
static hash(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, value: Record<string, any>): string;
/**
* Resolves to the value from resolving all addresses in %%value%% for
* %%types%% and the %%domain%%.
*/
static resolveNames(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, value: Record<string, any>, resolveName: (name: string) => Promise<string>): Promise<{
domain: TypedDataDomain;
value: any;
}>;
/**
* Returns the JSON-encoded payload expected by nodes which implement
* the JSON-RPC [[link-eip-712]] method.
*/
static getPayload(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, value: Record<string, any>): any;
}
/**
* Compute the address used to sign the typed data for the %%signature%%.
*/
export declare function verifyTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, value: Record<string, any>, signature: SignatureLike): string;
//# sourceMappingURL=typed-data.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"typed-data.d.ts","sourceRoot":"","sources":["../../src.ts/hash/typed-data.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAajE;;GAEG;AACH,MAAM,WAAW,eAAe;IAC5B;;OAEG;IACH,IAAI,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;IAErB;;OAEG;IACH,OAAO,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;IAExB;;OAEG;IACH,OAAO,CAAC,EAAE,IAAI,GAAG,YAAY,CAAC;IAE9B;;OAEG;IACH,iBAAiB,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;IAElC;;OAEG;IACH,IAAI,CAAC,EAAE,IAAI,GAAG,SAAS,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC3B;;OAEG;IACH,IAAI,EAAE,MAA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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;CA0D5H;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"}

524
dev/env/node_modules/ethers/lib.commonjs/hash/typed-data.js generated vendored Executable file
View File

@@ -0,0 +1,524 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.verifyTypedData = exports.TypedDataEncoder = void 0;
//import { TypedDataDomain, TypedDataField } from "@ethersproject/providerabstract-signer";
const index_js_1 = require("../address/index.js");
const index_js_2 = require("../crypto/index.js");
const index_js_3 = require("../transaction/index.js");
const index_js_4 = require("../utils/index.js");
const id_js_1 = require("./id.js");
const padding = new Uint8Array(32);
padding.fill(0);
const BN__1 = BigInt(-1);
const BN_0 = BigInt(0);
const BN_1 = BigInt(1);
const BN_MAX_UINT256 = BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
;
;
function hexPadRight(value) {
const bytes = (0, index_js_4.getBytes)(value);
const padOffset = bytes.length % 32;
if (padOffset) {
return (0, index_js_4.concat)([bytes, padding.slice(padOffset)]);
}
return (0, index_js_4.hexlify)(bytes);
}
const hexTrue = (0, index_js_4.toBeHex)(BN_1, 32);
const hexFalse = (0, index_js_4.toBeHex)(BN_0, 32);
const domainFieldTypes = {
name: "string",
version: "string",
chainId: "uint256",
verifyingContract: "address",
salt: "bytes32"
};
const domainFieldNames = [
"name", "version", "chainId", "verifyingContract", "salt"
];
function checkString(key) {
return function (value) {
(0, index_js_4.assertArgument)(typeof (value) === "string", `invalid domain value for ${JSON.stringify(key)}`, `domain.${key}`, value);
return value;
};
}
const domainChecks = {
name: checkString("name"),
version: checkString("version"),
chainId: function (_value) {
const value = (0, index_js_4.getBigInt)(_value, "domain.chainId");
(0, index_js_4.assertArgument)(value >= 0, "invalid chain ID", "domain.chainId", _value);
if (Number.isSafeInteger(value)) {
return Number(value);
}
return (0, index_js_4.toQuantity)(value);
},
verifyingContract: function (value) {
try {
return (0, index_js_1.getAddress)(value).toLowerCase();
}
catch (error) { }
(0, index_js_4.assertArgument)(false, `invalid domain value "verifyingContract"`, "domain.verifyingContract", value);
},
salt: function (value) {
const bytes = (0, index_js_4.getBytes)(value, "domain.salt");
(0, index_js_4.assertArgument)(bytes.length === 32, `invalid domain value "salt"`, "domain.salt", value);
return (0, index_js_4.hexlify)(bytes);
}
};
function getBaseEncoder(type) {
// intXX and uintXX
{
const match = type.match(/^(u?)int(\d+)$/);
if (match) {
const signed = (match[1] === "");
const width = parseInt(match[2]);
(0, index_js_4.assertArgument)(width % 8 === 0 && width !== 0 && width <= 256 && match[2] === String(width), "invalid numeric width", "type", type);
const boundsUpper = (0, index_js_4.mask)(BN_MAX_UINT256, signed ? (width - 1) : width);
const boundsLower = signed ? ((boundsUpper + BN_1) * BN__1) : BN_0;
return function (_value) {
const value = (0, index_js_4.getBigInt)(_value, "value");
(0, index_js_4.assertArgument)(value >= boundsLower && value <= boundsUpper, `value out-of-bounds for ${type}`, "value", value);
return (0, index_js_4.toBeHex)(signed ? (0, index_js_4.toTwos)(value, 256) : value, 32);
};
}
}
// bytesXX
{
const match = type.match(/^bytes(\d+)$/);
if (match) {
const width = parseInt(match[1]);
(0, index_js_4.assertArgument)(width !== 0 && width <= 32 && match[1] === String(width), "invalid bytes width", "type", type);
return function (value) {
const bytes = (0, index_js_4.getBytes)(value);
(0, index_js_4.assertArgument)(bytes.length === width, `invalid length for ${type}`, "value", value);
return hexPadRight(value);
};
}
}
switch (type) {
case "address": return function (value) {
return (0, index_js_4.zeroPadValue)((0, index_js_1.getAddress)(value), 32);
};
case "bool": return function (value) {
return ((!value) ? hexFalse : hexTrue);
};
case "bytes": return function (value) {
return (0, index_js_2.keccak256)(value);
};
case "string": return function (value) {
return (0, id_js_1.id)(value);
};
}
return null;
}
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.
*
* This is useful for those that wish to compute various components of a
* typed data hash, primary types, or sub-components, but generally the
* higher level [[Signer-signTypedData]] is more useful.
*/
class TypedDataEncoder {
/**
* The primary type for the structured [[types]].
*
* This is derived automatically from the [[types]], since no
* recursion is possible, once the DAG for the types is consturcted
* internally, the primary type must be the only remaining type with
* no parent nodes.
*/
primaryType;
#types;
/**
* The types.
*/
get types() {
return JSON.parse(this.#types);
}
#fullTypes;
#encoderCache;
/**
* Create a new **TypedDataEncoder** for %%types%%.
*
* This performs all necessary checking that types are valid and
* do not violate the [[link-eip-712]] structural constraints as
* well as computes the [[primaryType]].
*/
constructor(_types) {
this.#fullTypes = new Map();
this.#encoderCache = new Map();
// Link struct types to their direct child structs
const links = new Map();
// Link structs to structs which contain them as a child
const parents = new Map();
// Link all subtypes within a given struct
const subtypes = new Map();
const types = {};
Object.keys(_types).forEach((type) => {
types[type] = _types[type].map(({ name, type }) => {
// Normalize the base type (unless name conflict)
let { base, index } = splitArray(type);
if (base === "int" && !_types["int"]) {
base = "int256";
}
if (base === "uint" && !_types["uint"]) {
base = "uint256";
}
return { name, type: (base + (index || "")) };
});
links.set(type, new Set());
parents.set(type, []);
subtypes.set(type, new Set());
});
this.#types = JSON.stringify(types);
for (const name in types) {
const uniqueNames = new Set();
for (const field of types[name]) {
// Check each field has a unique name
(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 = 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);
if (encoder) {
continue;
}
(0, index_js_4.assertArgument)(parents.has(baseType), `unknown type ${JSON.stringify(baseType)}`, "types", _types);
// Add linkage
parents.get(baseType).push(name);
links.get(name).add(baseType);
}
}
// Deduce the primary type
const primaryTypes = Array.from(parents.keys()).filter((n) => (parents.get(n).length === 0));
(0, index_js_4.assertArgument)(primaryTypes.length !== 0, "missing primary type", "types", _types);
(0, index_js_4.assertArgument)(primaryTypes.length === 1, `ambiguous primary types or unused types: ${primaryTypes.map((t) => (JSON.stringify(t))).join(", ")}`, "types", _types);
(0, index_js_4.defineProperties)(this, { primaryType: primaryTypes[0] });
// Check for circular type references
function checkCircular(type, found) {
(0, index_js_4.assertArgument)(!found.has(type), `circular type reference to ${JSON.stringify(type)}`, "types", _types);
found.add(type);
for (const child of links.get(type)) {
if (!parents.has(child)) {
continue;
}
// Recursively check children
checkCircular(child, found);
// Mark all ancestors as having this decendant
for (const subtype of found) {
subtypes.get(subtype).add(child);
}
}
found.delete(type);
}
checkCircular(this.primaryType, new Set());
// Compute each fully describe type
for (const [name, set] of subtypes) {
const st = Array.from(set);
st.sort();
this.#fullTypes.set(name, encodeType(name, types[name]) + st.map((t) => encodeType(t, types[t])).join(""));
}
}
/**
* Returnthe encoder for the specific %%type%%.
*/
getEncoder(type) {
let encoder = this.#encoderCache.get(type);
if (!encoder) {
encoder = this.#getEncoder(type);
this.#encoderCache.set(type, encoder);
}
return encoder;
}
#getEncoder(type) {
// Basic encoder type (address, bool, uint256, etc)
{
const encoder = getBaseEncoder(type);
if (encoder) {
return encoder;
}
}
// Array
const array = splitArray(type).array;
if (array) {
const subtype = array.prefix;
const subEncoder = this.getEncoder(subtype);
return (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);
}
return (0, index_js_2.keccak256)((0, index_js_4.concat)(result));
};
}
// Struct
const fields = this.types[type];
if (fields) {
const encodedType = (0, id_js_1.id)(this.#fullTypes.get(type));
return (value) => {
const values = fields.map(({ name, type }) => {
const result = this.getEncoder(type)(value[name]);
if (this.#fullTypes.has(type)) {
return (0, index_js_2.keccak256)(result);
}
return result;
});
values.unshift(encodedType);
return (0, index_js_4.concat)(values);
};
}
(0, index_js_4.assertArgument)(false, `unknown type: ${type}`, "type", type);
}
/**
* Return the full type for %%name%%.
*/
encodeType(name) {
const result = this.#fullTypes.get(name);
(0, index_js_4.assertArgument)(result, `unknown type: ${JSON.stringify(name)}`, "name", name);
return result;
}
/**
* Return the encoded %%value%% for the %%type%%.
*/
encodeData(type, value) {
return this.getEncoder(type)(value);
}
/**
* Returns the hash of %%value%% for the type of %%name%%.
*/
hashStruct(name, value) {
return (0, index_js_2.keccak256)(this.encodeData(name, value));
}
/**
* Return the fulled encoded %%value%% for the [[types]].
*/
encode(value) {
return this.encodeData(this.primaryType, value);
}
/**
* Return the hash of the fully encoded %%value%% for the [[types]].
*/
hash(value) {
return this.hashStruct(this.primaryType, value);
}
/**
* @_ignore:
*/
_visit(type, value, callback) {
// Basic encoder type (address, bool, uint256, etc)
{
const encoder = getBaseEncoder(type);
if (encoder) {
return callback(type, value);
}
}
// Array
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];
if (fields) {
return fields.reduce((accum, { name, type }) => {
accum[name] = this._visit(type, value[name], callback);
return accum;
}, {});
}
(0, index_js_4.assertArgument)(false, `unknown type: ${type}`, "type", type);
}
/**
* Call %%calback%% for each value in %%value%%, passing the type and
* component within %%value%%.
*
* This is useful for replacing addresses or other transformation that
* may be desired on each component, based on its type.
*/
visit(value, callback) {
return this._visit(this.primaryType, value, callback);
}
/**
* Create a new **TypedDataEncoder** for %%types%%.
*/
static from(types) {
return new TypedDataEncoder(types);
}
/**
* Return the primary type for %%types%%.
*/
static getPrimaryType(types) {
return TypedDataEncoder.from(types).primaryType;
}
/**
* Return the hashed struct for %%value%% using %%types%% and %%name%%.
*/
static hashStruct(name, types, value) {
return TypedDataEncoder.from(types).hashStruct(name, value);
}
/**
* Return the domain hash for %%domain%%.
*/
static hashDomain(domain) {
const domainFields = [];
for (const name in domain) {
if (domain[name] == null) {
continue;
}
const type = domainFieldTypes[name];
(0, index_js_4.assertArgument)(type, `invalid typed-data domain key: ${JSON.stringify(name)}`, "domain", domain);
domainFields.push({ name, type });
}
domainFields.sort((a, b) => {
return domainFieldNames.indexOf(a.name) - domainFieldNames.indexOf(b.name);
});
return TypedDataEncoder.hashStruct("EIP712Domain", { EIP712Domain: domainFields }, domain);
}
/**
* Return the fully encoded [[link-eip-712]] %%value%% for %%types%% with %%domain%%.
*/
static encode(domain, types, value) {
return (0, index_js_4.concat)([
"0x1901",
TypedDataEncoder.hashDomain(domain),
TypedDataEncoder.from(types).hash(value)
]);
}
/**
* Return the hash of the fully encoded [[link-eip-712]] %%value%% for %%types%% with %%domain%%.
*/
static hash(domain, types, value) {
return (0, index_js_2.keccak256)(TypedDataEncoder.encode(domain, types, value));
}
// Replaces all address types with ENS names with their looked up address
/**
* Resolves to the value from resolving all addresses in %%value%% for
* %%types%% and the %%domain%%.
*/
static async resolveNames(domain, types, value, resolveName) {
// Make a copy to isolate it from the object passed in
domain = Object.assign({}, domain);
// Allow passing null to ignore value
for (const key in domain) {
if (domain[key] == null) {
delete domain[key];
}
}
// Look up all ENS names
const ensCache = {};
// Do we need to look up the domain's verifyingContract?
if (domain.verifyingContract && !(0, index_js_4.isHexString)(domain.verifyingContract, 20)) {
ensCache[domain.verifyingContract] = "0x";
}
// We are going to use the encoder to visit all the base values
const encoder = TypedDataEncoder.from(types);
// Get a list of all the addresses
encoder.visit(value, (type, value) => {
if (type === "address" && !(0, index_js_4.isHexString)(value, 20)) {
ensCache[value] = "0x";
}
return value;
});
// Lookup each name
for (const name in ensCache) {
ensCache[name] = await resolveName(name);
}
// Replace the domain verifyingContract if needed
if (domain.verifyingContract && ensCache[domain.verifyingContract]) {
domain.verifyingContract = ensCache[domain.verifyingContract];
}
// Replace all ENS names with their address
value = encoder.visit(value, (type, value) => {
if (type === "address" && ensCache[value]) {
return ensCache[value];
}
return value;
});
return { domain, value };
}
/**
* Returns the JSON-encoded payload expected by nodes which implement
* the JSON-RPC [[link-eip-712]] method.
*/
static getPayload(domain, types, value) {
// Validate the domain fields
TypedDataEncoder.hashDomain(domain);
// Derive the EIP712Domain Struct reference type
const domainValues = {};
const domainTypes = [];
domainFieldNames.forEach((name) => {
const value = domain[name];
if (value == null) {
return;
}
domainValues[name] = domainChecks[name](value);
domainTypes.push({ name, type: domainFieldTypes[name] });
});
const encoder = TypedDataEncoder.from(types);
// Get the normalized types
types = encoder.types;
const typesWithDomain = Object.assign({}, types);
(0, index_js_4.assertArgument)(typesWithDomain.EIP712Domain == null, "types must not contain EIP712Domain type", "types.EIP712Domain", types);
typesWithDomain.EIP712Domain = domainTypes;
// Validate the data structures and types
encoder.encode(value);
return {
types: typesWithDomain,
domain: domainValues,
primaryType: encoder.primaryType,
message: encoder.visit(value, (type, value) => {
// bytes
if (type.match(/^bytes(\d*)/)) {
return (0, index_js_4.hexlify)((0, index_js_4.getBytes)(value));
}
// uint or int
if (type.match(/^u?int/)) {
return (0, index_js_4.getBigInt)(value).toString();
}
switch (type) {
case "address":
return value.toLowerCase();
case "bool":
return !!value;
case "string":
(0, index_js_4.assertArgument)(typeof (value) === "string", "invalid string", "value", value);
return value;
}
(0, index_js_4.assertArgument)(false, "unsupported type", "type", type);
})
};
}
}
exports.TypedDataEncoder = TypedDataEncoder;
/**
* Compute the address used to sign the typed data for the %%signature%%.
*/
function verifyTypedData(domain, types, value, signature) {
return (0, index_js_3.recoverAddress)(TypedDataEncoder.hash(domain, types, value), signature);
}
exports.verifyTypedData = verifyTypedData;
//# sourceMappingURL=typed-data.js.map

File diff suppressed because one or more lines are too long