admin: updated dist files.
This commit is contained in:
parent
12ed855a2e
commit
2740976d8b
17096
dist/ethers.js
vendored
Normal file
17096
dist/ethers.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
dist/ethers.min.js
vendored
Normal file
1
dist/ethers.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1344
dist/wordlists-extra.js
vendored
Normal file
1344
dist/wordlists-extra.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
dist/wordlists-extra.min.js
vendored
Normal file
1
dist/wordlists-extra.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
46
lib.commonjs/_tests/test-abi.js
Normal file
46
lib.commonjs/_tests/test-abi.js
Normal file
@ -0,0 +1,46 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const assert_1 = __importDefault(require("assert"));
|
||||
const utils_js_1 = require("./utils.js");
|
||||
const index_js_1 = require("../index.js");
|
||||
function equal(actual, expected) {
|
||||
switch (expected.type) {
|
||||
case "address":
|
||||
case "boolean":
|
||||
case "hexstring":
|
||||
case "string":
|
||||
assert_1.default.equal(actual, expected.value);
|
||||
return;
|
||||
case "number":
|
||||
assert_1.default.equal(actual, BigInt(expected.value));
|
||||
return;
|
||||
case "array":
|
||||
case "object":
|
||||
assert_1.default.ok(Array.isArray(actual), "!array");
|
||||
assert_1.default.equal(actual.length, expected.value.length, ".length mismatch");
|
||||
for (let i = 0; i < actual.length; i++) {
|
||||
equal(actual[i], expected.value[i]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
throw new Error(`unsupported: ${expected}`);
|
||||
}
|
||||
describe("Tests ABI Coder", function () {
|
||||
const tests = (0, utils_js_1.loadTests)("abi");
|
||||
for (const test of tests) {
|
||||
it(`tests ABI encoding: (${test.name})`, function () {
|
||||
const encoded = index_js_1.defaultAbiCoder.encode([test.type], [test.value]);
|
||||
assert_1.default.equal(encoded, test.encoded, "encoded");
|
||||
});
|
||||
}
|
||||
for (const test of tests) {
|
||||
it(`tests ABI decoding: (${test.name})`, function () {
|
||||
const decoded = index_js_1.defaultAbiCoder.decode([test.type], test.encoded)[0];
|
||||
equal(decoded, test.verbose);
|
||||
});
|
||||
}
|
||||
});
|
||||
//# sourceMappingURL=test-abi.js.map
|
1
lib.commonjs/_tests/test-abi.js.map
Normal file
1
lib.commonjs/_tests/test-abi.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"test-abi.js","sourceRoot":"","sources":["../../src.ts/_tests/test-abi.ts"],"names":[],"mappings":";;;;;AAAA,oDAA4B;AAC5B,yCAAuC;AAIvC,0CAA8C;AAE9C,SAAS,KAAK,CAAC,MAAW,EAAE,QAA4B;IACpD,QAAQ,QAAQ,CAAC,IAAI,EAAE;QACnB,KAAK,SAAS,CAAC;QAAC,KAAK,SAAS,CAAC;QAAC,KAAK,WAAW,CAAC;QAAC,KAAK,QAAQ;YAC3D,gBAAM,CAAC,KAAK,CAAC,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;YACrC,OAAO;QACX,KAAK,QAAQ;YACT,gBAAM,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;YAC7C,OAAM;QACV,KAAK,OAAO,CAAC;QAAC,KAAK,QAAQ;YACvB,gBAAM,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,CAAC;YAC3C,gBAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;YACvE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;gBACpC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;aACvC;YACD,OAAO;KACd;IACD,MAAM,IAAI,KAAK,CAAC,gBAAiB,QAAS,EAAE,CAAC,CAAC;AAClD,CAAC;AAED,QAAQ,CAAC,iBAAiB,EAAE;IACxB,MAAM,KAAK,GAAG,IAAA,oBAAS,EAAc,KAAK,CAAC,CAAC;IAE5C,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;QACtB,EAAE,CAAC,wBAAyB,IAAI,CAAC,IAAK,GAAG,EAAE;YACvC,MAAM,OAAO,GAAG,0BAAe,CAAC,MAAM,CAAC,CAAE,IAAI,CAAC,IAAI,CAAE,EAAE,CAAE,IAAI,CAAC,KAAK,CAAE,CAAC,CAAC;YACtE,gBAAM,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QACnD,CAAC,CAAC,CAAC;KACN;IAED,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;QACtB,EAAE,CAAC,wBAAyB,IAAI,CAAC,IAAK,GAAG,EAAE;YACvC,MAAM,OAAO,GAAG,0BAAe,CAAC,MAAM,CAAC,CAAE,IAAI,CAAC,IAAI,CAAE,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;YACvE,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QACjC,CAAC,CAAC,CAAC;KACN;AACL,CAAC,CAAC,CAAC"}
|
115
lib.commonjs/_tests/test-address.js
Normal file
115
lib.commonjs/_tests/test-address.js
Normal file
@ -0,0 +1,115 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const assert_1 = __importDefault(require("assert"));
|
||||
const utils_js_1 = require("./utils.js");
|
||||
const index_js_1 = require("../index.js");
|
||||
describe("computes checksum address", function () {
|
||||
const tests = (0, utils_js_1.loadTests)("accounts");
|
||||
for (const test of tests) {
|
||||
it(`computes the checksum address: ${test.name}`, function () {
|
||||
assert_1.default.equal((0, index_js_1.getAddress)(test.address), test.address);
|
||||
assert_1.default.equal((0, index_js_1.getAddress)(test.icap), test.address);
|
||||
assert_1.default.equal((0, index_js_1.getAddress)(test.address.substring(2)), test.address);
|
||||
assert_1.default.equal((0, index_js_1.getAddress)(test.address.toLowerCase()), test.address);
|
||||
assert_1.default.equal((0, index_js_1.getAddress)("0x" + test.address.substring(2).toUpperCase()), test.address);
|
||||
});
|
||||
}
|
||||
const invalidAddresses = [
|
||||
{ name: "null", value: null },
|
||||
{ name: "number", value: 1234 },
|
||||
{ name: "emtpy bytes", value: "0x" },
|
||||
{ name: "too short", value: "0x8ba1f109551bd432803012645ac136ddd64dba" },
|
||||
{ name: "too long", value: "0x8ba1f109551bd432803012645ac136ddd64dba7200" },
|
||||
];
|
||||
invalidAddresses.forEach(({ name, value }) => {
|
||||
it(`fails on invalid address: ${name}`, function () {
|
||||
assert_1.default.throws(function () {
|
||||
(0, index_js_1.getAddress)(value);
|
||||
}, function (error) {
|
||||
return (error.code === "INVALID_ARGUMENT" &&
|
||||
error.message.match(/^invalid address/) &&
|
||||
error.argument === "address" &&
|
||||
error.value === value);
|
||||
});
|
||||
});
|
||||
});
|
||||
it("fails on invalid checksum", function () {
|
||||
const value = "0x8ba1f109551bD432803012645Ac136ddd64DBa72";
|
||||
assert_1.default.throws(function () {
|
||||
(0, index_js_1.getAddress)(value);
|
||||
}, function (error) {
|
||||
return (error.code === "INVALID_ARGUMENT" &&
|
||||
error.message.match(/^bad address checksum/) &&
|
||||
error.argument === "address" &&
|
||||
error.value === value);
|
||||
});
|
||||
});
|
||||
it("fails on invalid IBAN checksum", function () {
|
||||
const value = "XE65GB6LDNXYOFTX0NSV3FUWKOWIXAMJK37";
|
||||
assert_1.default.throws(function () {
|
||||
(0, index_js_1.getAddress)(value);
|
||||
}, function (error) {
|
||||
return (error.code === "INVALID_ARGUMENT" &&
|
||||
error.message.match(/^bad icap checksum/) &&
|
||||
error.argument === "address" &&
|
||||
error.value === value);
|
||||
});
|
||||
});
|
||||
});
|
||||
describe("computes ICAP address", function () {
|
||||
const tests = (0, utils_js_1.loadTests)("accounts");
|
||||
for (const test of tests) {
|
||||
it(`computes the ICAP address: ${test.name}`, function () {
|
||||
assert_1.default.equal((0, index_js_1.getIcapAddress)(test.address), test.icap);
|
||||
assert_1.default.equal((0, index_js_1.getAddress)(test.address.toLowerCase()), test.address);
|
||||
assert_1.default.equal((0, index_js_1.getAddress)("0x" + test.address.substring(2).toUpperCase()), test.address);
|
||||
});
|
||||
}
|
||||
});
|
||||
describe("computes create address", function () {
|
||||
const tests = (0, utils_js_1.loadTests)("create");
|
||||
for (const { sender, creates } of tests) {
|
||||
for (const { name, nonce, address } of creates) {
|
||||
it(`computes the create address: ${name}`, function () {
|
||||
assert_1.default.equal((0, index_js_1.getCreateAddress)({ from: sender, nonce }), address);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
describe("computes create2 address", function () {
|
||||
const tests = (0, utils_js_1.loadTests)("create2");
|
||||
for (const { sender, creates } of tests) {
|
||||
for (const { name, salt, initCodeHash, address } of creates) {
|
||||
it(`computes the create2 address: ${name}`, function () {
|
||||
assert_1.default.equal((0, index_js_1.getCreate2Address)(sender, salt, initCodeHash), address);
|
||||
});
|
||||
}
|
||||
}
|
||||
const sender = "0x8ba1f109551bD432803012645Ac136ddd64DBA72";
|
||||
const salt = "0x1c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac8";
|
||||
const initCodeHash = "0x8452c9b9140222b08593a26daa782707297be9f7b3e8281d7b4974769f19afd0";
|
||||
it("fails on invalid salt", function () {
|
||||
const badSalt = "0x1c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36dea";
|
||||
assert_1.default.throws(function () {
|
||||
(0, index_js_1.getCreate2Address)(sender, badSalt, initCodeHash);
|
||||
}, function (error) {
|
||||
return (error.code === "INVALID_ARGUMENT" &&
|
||||
error.argument === "salt" &&
|
||||
error.value === badSalt);
|
||||
});
|
||||
});
|
||||
it("fails on invalid initCodeHash", function () {
|
||||
const badInitCodeHash = "0x8452c9b9140222b08593a26daa782707297be9f7b3e8281d7b4974769f19af";
|
||||
assert_1.default.throws(function () {
|
||||
(0, index_js_1.getCreate2Address)(sender, salt, badInitCodeHash);
|
||||
}, function (error) {
|
||||
return (error.code === "INVALID_ARGUMENT" &&
|
||||
error.argument === "initCodeHash" &&
|
||||
error.value === badInitCodeHash);
|
||||
});
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=test-address.js.map
|
1
lib.commonjs/_tests/test-address.js.map
Normal file
1
lib.commonjs/_tests/test-address.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"test-address.js","sourceRoot":"","sources":["../../src.ts/_tests/test-address.ts"],"names":[],"mappings":";;;;;AAAA,oDAA4B;AAE5B,yCAAuC;AAQvC,0CAGqB;AAGrB,QAAQ,CAAC,2BAA2B,EAAE;IAClC,MAAM,KAAK,GAAG,IAAA,oBAAS,EAAkB,UAAU,CAAC,CAAC;IACrD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;QACtB,EAAE,CAAC,kCAAmC,IAAI,CAAC,IAAK,EAAE,EAAE;YAChD,gBAAM,CAAC,KAAK,CAAC,IAAA,qBAAU,EAAC,IAAI,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;YACrD,gBAAM,CAAC,KAAK,CAAC,IAAA,qBAAU,EAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;YAClD,gBAAM,CAAC,KAAK,CAAC,IAAA,qBAAU,EAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;YAClE,gBAAM,CAAC,KAAK,CAAC,IAAA,qBA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;IAE1F,EAAE,CAAC,uBAAuB,EAAE;QACxB,MAAM,OAAO,GAAG,kEAAkE,CAAC;QACnF,gBAAM,CAAC,MAAM,CAAC;YACV,IAAA,4BAAiB,EAAC,MAAM,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;QACrD,CAAC,EAAE,UAAS,KAAU;YAClB,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,kBAAkB;gBACrC,KAAK,CAAC,QAAQ,KAAK,MAAM;gBACzB,KAAK,CAAC,KAAK,KAAK,OAAO,CAAC,CAAC;QACjC,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,+BAA+B,EAAE;QAChC,MAAM,eAAe,GAAG,kEAAkE,CAAC;QAC3F,gBAAM,CAAC,MAAM,CAAC;YACV,IAAA,4BAAiB,EAAC,MAAM,EAAE,IAAI,EAAE,eAAe,CAAC,CAAC;QACrD,CAAC,EAAE,UAAS,KAAU;YAClB,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,kBAAkB;gBACrC,KAAK,CAAC,QAAQ,KAAK,cAAc;gBACjC,KAAK,CAAC,KAAK,KAAK,eAAe,CAAC,CAAC;QACzC,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
99
lib.commonjs/_tests/test-contract.js
Normal file
99
lib.commonjs/_tests/test-contract.js
Normal file
@ -0,0 +1,99 @@
|
||||
"use strict";
|
||||
/*
|
||||
import { Typed } from "../abi/index.js";
|
||||
import * as providers from "../providers/index.js";
|
||||
|
||||
import { Contract } from "../index.js";
|
||||
|
||||
import { log } from "./utils.js";
|
||||
*/
|
||||
//import type { Addressable } from "@ethersproject/address";
|
||||
//import type { BigNumberish } from "@ethersproject/logger";
|
||||
/*
|
||||
import type {
|
||||
ConstantContractMethod, ContractMethod, ContractEvent
|
||||
} from "../index.js";
|
||||
*/
|
||||
// @TODO
|
||||
/*
|
||||
describe("Test Contract Calls", function() {
|
||||
it("finds typed methods", async function() {
|
||||
const contract = new Contract("0xC18360217D8F7Ab5e7c516566761Ea12Ce7F9D72", [
|
||||
"function foo(string s) view returns (uint)",
|
||||
"function foo(uint8) view returns (uint)",
|
||||
"function foo(uint u, bool b) view returns (uint)",
|
||||
]);
|
||||
const value = Typed.string("42");
|
||||
await contract.foo.populateTransaction(value, Typed.overrides({ value: 100 }))
|
||||
contract["foo(string)"].fragment
|
||||
});
|
||||
});
|
||||
*/
|
||||
/*
|
||||
describe("Test Contract Interface", function() {
|
||||
it("builds contract interfaces", async function() {
|
||||
this.timeout(60000);
|
||||
|
||||
interface Erc20Interface {
|
||||
// Constant Methods
|
||||
balanceOf: ConstantContractMethod<[ address: string | Addressable ], bigint>;
|
||||
decimals: ConstantContractMethod<[ ], bigint>;
|
||||
|
||||
name: ConstantContractMethod<[ ], string>;
|
||||
symbol: ConstantContractMethod<[ ], string>;
|
||||
|
||||
// Mutation Methods
|
||||
transferFrom: ContractMethod<[ address: string | Addressable,
|
||||
address: string | Addressable, amount: BigNumberish ], boolean>;
|
||||
|
||||
// Events
|
||||
filters: {
|
||||
Transfer: ContractEvent<[ from: Addressable | string, to: BigNumberish ]>;
|
||||
}
|
||||
}
|
||||
|
||||
const erc20Abi = [
|
||||
"function balanceOf(address owner) view returns (uint)",
|
||||
"function decimals() view returns (uint)",
|
||||
"function name() view returns (string)",
|
||||
"function symbol() view returns (string)",
|
||||
|
||||
"function transferFrom(address from, address to, uint amount) returns (boolean)",
|
||||
|
||||
"event Transfer(address indexed from, address indexed to, uint amount)"
|
||||
];
|
||||
|
||||
class Erc20Contract extends BaseContract.buildClass<Erc20Interface>(erc20Abi) { };
|
||||
|
||||
const provider = new providers.InfuraProvider();
|
||||
// ENS
|
||||
//const addr = "0xC18360217D8F7Ab5e7c516566761Ea12Ce7F9D72";
|
||||
// DAI
|
||||
const addr = "0x6B175474E89094C44Da98b954EedeAC495271d0F";
|
||||
const contract = new Erc20Contract(addr, provider);
|
||||
console.log("SYMBOL", await contract.symbol());
|
||||
console.log("DECIMALS", await contract.decimals());
|
||||
console.log(await contract.balanceOf("0x5555763613a12D8F3e73be831DFf8598089d3dCa"));
|
||||
console.log(await contract.balanceOf("ricmoo.eth"));
|
||||
|
||||
await contract.on(contract.filters.Transfer, (from, to, value, event) => {
|
||||
console.log("HELLO!", { from, to, value, event });
|
||||
event.removeListener();
|
||||
});
|
||||
const logs = await contract.queryFilter("Transfer", -10);
|
||||
console.log(logs, logs[0], logs[0].args.from);
|
||||
});
|
||||
});
|
||||
*/
|
||||
/*
|
||||
describe("Test Contract Calls", function() {
|
||||
it("calls ERC-20 methods", async function() {
|
||||
const provider = new providers.AnkrProvider();
|
||||
const contract = new Contract("0xC18360217D8F7Ab5e7c516566761Ea12Ce7F9D72", [
|
||||
"function balanceOf(address owner) view returns (uint)",
|
||||
], provider);
|
||||
log(this, `balance: ${ await contract.balanceOf("0x5555763613a12D8F3e73be831DFf8598089d3dCa") }`);
|
||||
});
|
||||
});
|
||||
*/
|
||||
//# sourceMappingURL=test-contract.js.map
|
1
lib.commonjs/_tests/test-contract.js.map
Normal file
1
lib.commonjs/_tests/test-contract.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"test-contract.js","sourceRoot":"","sources":["../../src.ts/_tests/test-contract.ts"],"names":[],"mappings":";AAAA;;;;;;;EAOE;AACF,4DAA4D;AAC5D,4DAA4D;AAE5D;;;;EAIE;AAEF,QAAQ;AACR;;;;;;;;;;;;;EAaE;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuDE;AACF;;;;;;;;;;EAUE"}
|
87
lib.commonjs/_tests/test-crypto-algoswap.js
Normal file
87
lib.commonjs/_tests/test-crypto-algoswap.js
Normal file
@ -0,0 +1,87 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const assert_1 = __importDefault(require("assert"));
|
||||
const index_js_1 = require("../index.js");
|
||||
describe("test registration", function () {
|
||||
let hijack = "";
|
||||
function getHijack(algo) {
|
||||
return function (...args) {
|
||||
hijack = `hijacked ${algo}: ${JSON.stringify(args)}`;
|
||||
return "0x42";
|
||||
};
|
||||
}
|
||||
const tests = [
|
||||
{
|
||||
name: "keccak256",
|
||||
params: ["0x"],
|
||||
hijackTag: 'hijacked keccak256: [{}]',
|
||||
algorithm: index_js_1.keccak256
|
||||
},
|
||||
{
|
||||
name: "sha256",
|
||||
params: ["0x"],
|
||||
hijackTag: 'hijacked sha256: [{}]',
|
||||
algorithm: index_js_1.sha256
|
||||
},
|
||||
{
|
||||
name: "sha512",
|
||||
params: ["0x"],
|
||||
hijackTag: 'hijacked sha512: [{}]',
|
||||
algorithm: index_js_1.sha512
|
||||
},
|
||||
{
|
||||
name: "ripemd160",
|
||||
params: ["0x"],
|
||||
hijackTag: 'hijacked ripemd160: [{}]',
|
||||
algorithm: index_js_1.ripemd160
|
||||
},
|
||||
{
|
||||
name: "pbkdf2",
|
||||
params: ["0x", "0x", 1024, 32, "sha256"],
|
||||
hijackTag: 'hijacked pbkdf2: [{},{},1024,32,"sha256"]',
|
||||
algorithm: index_js_1.pbkdf2
|
||||
},
|
||||
{
|
||||
name: "scryptSync",
|
||||
params: ["0x", "0x", 1024, 8, 1, 32],
|
||||
hijackTag: 'hijacked scryptSync: [{},{},1024,8,1,32]',
|
||||
algorithm: index_js_1.scryptSync
|
||||
},
|
||||
{
|
||||
name: "scrypt",
|
||||
params: ["0x", "0x", 1024, 8, 1, 32],
|
||||
hijackTag: 'hijacked scrypt: [{},{},1024,8,1,32,null]',
|
||||
algorithm: index_js_1.scrypt
|
||||
},
|
||||
{
|
||||
name: "computeHmac",
|
||||
params: ["sha256", "0x", "0x"],
|
||||
hijackTag: 'hijacked computeHmac: ["sha256",{},{}]',
|
||||
algorithm: index_js_1.computeHmac
|
||||
},
|
||||
];
|
||||
tests.forEach(({ name, params, hijackTag, algorithm }) => {
|
||||
it(`swaps in hijacked callback: ${name}`, async function () {
|
||||
const initial = await algorithm(...params);
|
||||
algorithm.register(getHijack(name));
|
||||
assert_1.default.equal(await algorithm(...params), "0x42");
|
||||
assert_1.default.equal(hijack, hijackTag);
|
||||
algorithm.register(algorithm._);
|
||||
assert_1.default.equal(await algorithm(...params), initial);
|
||||
});
|
||||
});
|
||||
it("prevents swapping after locked", function () {
|
||||
(0, index_js_1.lock)();
|
||||
tests.forEach(({ name, params, hijackTag, algorithm }) => {
|
||||
assert_1.default.throws(function () {
|
||||
algorithm.register(getHijack("test"));
|
||||
}, function (error) {
|
||||
return (error.message === `${name} is locked`);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=test-crypto-algoswap.js.map
|
1
lib.commonjs/_tests/test-crypto-algoswap.js.map
Normal file
1
lib.commonjs/_tests/test-crypto-algoswap.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"test-crypto-algoswap.js","sourceRoot":"","sources":["../../src.ts/_tests/test-crypto-algoswap.ts"],"names":[],"mappings":";;;;;AAAA,oDAA4B;AAE5B,0CAQqB;AAkBrB,QAAQ,CAAC,mBAAmB,EAAE;IAE1B,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,SAAS,SAAS,CAAC,IAAY;QAC3B,OAAO,UAAS,GAAG,IAAgB;YAC/B,MAAM,GAAG,YAAa,IAAK,KAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAE,EAAE,CAAC;YACzD,OAAO,MAAM,CAAC;QAClB,CAAC,CAAA;IACL,CAAC;IAED,MAAM,KAAK,GAAoB;QAC3B;YACI,IAAI,EAAE,WAAW;YACjB,MAAM,EAAE,CAAE,IAAI,CAAE;YAChB,SAAS,EAAE,0BAA0B;YACrC,SAAS,EAAE,oBAAS;SACvB;QACD;YACI,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE,CAAE,IAAI,CAAE;YACh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AAQ,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;YAEpC,gBAAM,CAAC,KAAK,CAAC,MAAM,SAAS,CAAC,GAAG,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC;YACjD,gBAAM,CAAC,KAAK,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;YAEhC,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;YAChC,gBAAM,CAAC,KAAK,CAAC,MAAM,SAAS,CAAC,GAAG,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC;QACtD,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,gCAAgC,EAAE;QACjC,IAAA,eAAI,GAAE,CAAC;QAEP,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,EAAE;YACrD,gBAAM,CAAC,MAAM,CAAC;gBACV,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;YAC1C,CAAC,EAAE,UAAS,KAAU;gBAClB,OAAO,CAAC,KAAK,CAAC,OAAO,KAAK,GAAI,IAAK,YAAY,CAAC,CAAC;YACrD,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AAEP,CAAC,CAAC,CAAC"}
|
219
lib.commonjs/_tests/test-crypto.js
Normal file
219
lib.commonjs/_tests/test-crypto.js
Normal file
@ -0,0 +1,219 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const assert_1 = __importDefault(require("assert"));
|
||||
const utils_js_1 = require("./utils.js");
|
||||
const index_js_1 = require("../index.js");
|
||||
describe("test hashing", function () {
|
||||
const tests = (0, utils_js_1.loadTests)("hashes");
|
||||
tests.forEach((test) => {
|
||||
it(`computes sha2-256: ${test.name}`, function () {
|
||||
assert_1.default.equal((0, index_js_1.sha256)(test.data), test.sha256);
|
||||
});
|
||||
});
|
||||
tests.forEach((test) => {
|
||||
it(`computes sha2-512: ${test.name}`, function () {
|
||||
assert_1.default.equal((0, index_js_1.sha512)(test.data), test.sha512);
|
||||
});
|
||||
});
|
||||
tests.forEach((test) => {
|
||||
it(`computes ripemd160: ${test.name}`, function () {
|
||||
assert_1.default.equal((0, index_js_1.ripemd160)(test.data), test.ripemd160);
|
||||
});
|
||||
});
|
||||
tests.forEach((test) => {
|
||||
it(`computes keccak256: ${test.name}`, function () {
|
||||
assert_1.default.equal((0, index_js_1.keccak256)(test.data), test.keccak256);
|
||||
});
|
||||
});
|
||||
});
|
||||
describe("test password-based key derivation", function () {
|
||||
const tests = (0, utils_js_1.loadTests)("pbkdf");
|
||||
tests.forEach((test) => {
|
||||
it(`computes pbkdf2: ${test.name}`, function () {
|
||||
const password = Buffer.from(test.password.substring(2), "hex");
|
||||
const salt = Buffer.from(test.salt.substring(2), "hex");
|
||||
const { iterations, algorithm, key } = test.pbkdf2;
|
||||
const result = (0, index_js_1.pbkdf2)(password, salt, iterations, test.dkLen, algorithm);
|
||||
assert_1.default.equal(result, key);
|
||||
});
|
||||
});
|
||||
tests.forEach((test) => {
|
||||
it(`computes scrypt (sync): ${test.name}`, function () {
|
||||
this.timeout(1000);
|
||||
const password = Buffer.from(test.password.substring(2), "hex");
|
||||
const salt = Buffer.from(test.salt.substring(2), "hex");
|
||||
const { N, r, p, key } = test.scrypt;
|
||||
const result = (0, index_js_1.scryptSync)(password, salt, N, r, p, test.dkLen);
|
||||
assert_1.default.equal(result, key);
|
||||
});
|
||||
});
|
||||
tests.forEach((test) => {
|
||||
it(`computes scrypt (async): ${test.name}`, async function () {
|
||||
this.timeout(1000);
|
||||
const password = Buffer.from(test.password.substring(2), "hex");
|
||||
const salt = Buffer.from(test.salt.substring(2), "hex");
|
||||
const { N, r, p, key } = test.scrypt;
|
||||
let progressCount = 0, progressOk = true, lastProgress = -1;
|
||||
const result = await (0, index_js_1.scrypt)(password, salt, N, r, p, test.dkLen, (progress) => {
|
||||
if (progress < lastProgress) {
|
||||
progressOk = false;
|
||||
}
|
||||
lastProgress = progress;
|
||||
progressCount++;
|
||||
});
|
||||
assert_1.default.ok(progressOk, "progress was not monotonically increasing");
|
||||
assert_1.default.ok(progressCount > 100, "progress callback was called at leat 100 times");
|
||||
assert_1.default.equal(result, key);
|
||||
});
|
||||
});
|
||||
});
|
||||
describe("test hmac", function () {
|
||||
const tests = (0, utils_js_1.loadTests)("hmac");
|
||||
tests.forEach((test) => {
|
||||
it(`computes hmac: ${test.name}`, async function () {
|
||||
const { algorithm, key, data } = test;
|
||||
assert_1.default.equal((0, index_js_1.computeHmac)(algorithm, key, data), test.hmac);
|
||||
});
|
||||
});
|
||||
});
|
||||
/*
|
||||
describe("test registration", function() {
|
||||
let hijack = "";
|
||||
function getHijack(algo: string) {
|
||||
return function(...args: Array<any>) {
|
||||
hijack = `hijacked ${ algo }: ${ JSON.stringify(args) }`;
|
||||
return "0x42";
|
||||
}
|
||||
}
|
||||
|
||||
it("hijacks keccak256", function() {
|
||||
const initial = keccak256("0x");
|
||||
|
||||
keccak256.register(getHijack("kecak256"));
|
||||
assert.equal(keccak256("0x"), "0x42");
|
||||
assert.equal(hijack, 'hijacked kecak256: [{}]');
|
||||
|
||||
keccak256.register(keccak256._);
|
||||
assert.equal(keccak256("0x"), initial);
|
||||
|
||||
keccak256.lock();
|
||||
|
||||
assert.throws(function() {
|
||||
keccak256.register(getHijack("test"));
|
||||
}, function(error) {
|
||||
return (error.message === "keccak256 is locked");
|
||||
});
|
||||
});
|
||||
|
||||
it("hijacks sha256", function() {
|
||||
const initial = sha256("0x");
|
||||
|
||||
sha256.register(getHijack("sha256"));
|
||||
assert.equal(sha256("0x"), "0x42");
|
||||
assert.equal(hijack, 'hijacked sha256: [{}]');
|
||||
|
||||
sha256.register(sha256._);
|
||||
assert.equal(sha256("0x"), initial);
|
||||
|
||||
sha256.lock();
|
||||
|
||||
assert.throws(function() {
|
||||
sha256.register(getHijack("test"));
|
||||
}, function(error) {
|
||||
return (error.message === "sha256 is locked");
|
||||
});
|
||||
});
|
||||
|
||||
it("hijacks sha512", function() {
|
||||
const initial = sha512("0x");
|
||||
|
||||
sha512.register(getHijack("sha512"));
|
||||
assert.equal(sha512("0x"), "0x42");
|
||||
assert.equal(hijack, 'hijacked sha512: [{}]');
|
||||
|
||||
sha512.register(sha512._);
|
||||
assert.equal(sha512("0x"), initial);
|
||||
|
||||
sha512.lock();
|
||||
|
||||
assert.throws(function() {
|
||||
sha512.register(getHijack("test"));
|
||||
}, function(error) {
|
||||
return (error.message === "sha512 is locked");
|
||||
});
|
||||
});
|
||||
|
||||
it("hijacks pbkdf2", function() {
|
||||
const initial = pbkdf2("0x", "0x", 1024, 32, "sha256");
|
||||
|
||||
pbkdf2.register(getHijack("pbkdf2"));
|
||||
assert.equal(pbkdf2("0x", "0x", 1024, 32, "sha256"), "0x42");
|
||||
assert.equal(hijack, 'hijacked pbkdf2: [{},{},1024,32,"sha256"]');
|
||||
|
||||
pbkdf2.register(pbkdf2._);
|
||||
assert.equal(pbkdf2("0x", "0x", 1024, 32, "sha256"), initial);
|
||||
|
||||
pbkdf2.lock();
|
||||
|
||||
assert.throws(function() {
|
||||
pbkdf2.register(getHijack("test"));
|
||||
}, function(error) {
|
||||
return (error.message === "pbkdf2 is locked");
|
||||
});
|
||||
});
|
||||
|
||||
it("hijacks scryptSync", function() {
|
||||
|
||||
function getHijack(...args: Array<any>) {
|
||||
hijack = `hijacked scryptSync: ${ JSON.stringify(args) }`;
|
||||
return new Uint8Array([ 0x42 ]);
|
||||
}
|
||||
|
||||
const initial = scryptSync("0x", "0x", 1024, 8, 1, 32);
|
||||
|
||||
scryptSync.register(getHijack);
|
||||
assert.equal(scryptSync("0x", "0x", 1024, 8, 1, 32), "0x42");
|
||||
assert.equal(hijack, 'hijacked scryptSync: [{},{},1024,8,1,32]');
|
||||
|
||||
scryptSync.register(scryptSync._);
|
||||
assert.equal(scryptSync("0x", "0x", 1024, 8, 1, 32), initial);
|
||||
|
||||
scryptSync.lock();
|
||||
|
||||
assert.throws(function() {
|
||||
scryptSync.register(getHijack);
|
||||
}, function(error) {
|
||||
return (error.message === "scryptSync is locked");
|
||||
});
|
||||
});
|
||||
|
||||
it("hijacks scrypt", async function() {
|
||||
function getHijack(...args: Array<any>) {
|
||||
hijack = `hijacked scrypt: ${ JSON.stringify(args) }`;
|
||||
return Promise.resolve(new Uint8Array([ 0x42 ]));
|
||||
}
|
||||
|
||||
const initial = await scrypt("0x", "0x", 1024, 8, 1, 32);
|
||||
|
||||
scrypt.register(getHijack);
|
||||
assert.equal(await scrypt("0x", "0x", 1024, 8, 1, 32), "0x42");
|
||||
assert.equal(hijack, 'hijacked scrypt: [{},{},1024,8,1,32,null]');
|
||||
|
||||
scrypt.register(scrypt._);
|
||||
assert.equal(await scrypt("0x", "0x", 1024, 8, 1, 32), initial);
|
||||
|
||||
scrypt.lock();
|
||||
|
||||
assert.throws(function() {
|
||||
scrypt.register(getHijack);
|
||||
}, function(error) {
|
||||
return (error.message === "scrypt is locked");
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
*/
|
||||
//# sourceMappingURL=test-crypto.js.map
|
1
lib.commonjs/_tests/test-crypto.js.map
Normal file
1
lib.commonjs/_tests/test-crypto.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"test-crypto.js","sourceRoot":"","sources":["../../src.ts/_tests/test-crypto.ts"],"names":[],"mappings":";;;;;AAAA,oDAA4B;AAE5B,yCAAuC;AAIvC,0CAIqB;AAGrB,QAAQ,CAAC,cAAc,EAAE;IACrB,MAAM,KAAK,GAAG,IAAA,oBAAS,EAAe,QAAQ,CAAC,CAAC;IAEhD,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACnB,EAAE,CAAC,sBAAuB,IAAI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,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,WAAW,EAAE;IAClB,MAAM,KAAK,GAAG,IAAA,oBAAS,EAAe,MAAM,CAAC,CAAC;IAE9C,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACnB,EAAE,CAAC,kBAAmB,IAAI,CAAC,IAAI,EAAE,EAAE,KAAK;YACpC,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;YACtC,gBAAM,CAAC,KAAK,CAAC,IAAA,sBAAW,EAAC,SAAS,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QAC/D,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAwIE"}
|
21
lib.commonjs/_tests/test-hash-typeddata.js
Normal file
21
lib.commonjs/_tests/test-hash-typeddata.js
Normal file
@ -0,0 +1,21 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const assert_1 = __importDefault(require("assert"));
|
||||
const utils_js_1 = require("./utils.js");
|
||||
const index_js_1 = require("../index.js");
|
||||
describe("Tests Typed Data (EIP-712)", function () {
|
||||
const tests = (0, utils_js_1.loadTests)("typed-data");
|
||||
for (const test of tests) {
|
||||
it(`tests encoding typed-data: ${test.name}`, function () {
|
||||
const encoder = index_js_1.TypedDataEncoder.from(test.types);
|
||||
assert_1.default.equal(encoder.primaryType, test.primaryType, "primaryType");
|
||||
assert_1.default.equal(encoder.encode(test.data), test.encoded, "encoded");
|
||||
assert_1.default.equal(index_js_1.TypedDataEncoder.getPrimaryType(test.types), test.primaryType, "primaryType");
|
||||
assert_1.default.equal(index_js_1.TypedDataEncoder.hash(test.domain, test.types, test.data), test.digest, "digest");
|
||||
});
|
||||
}
|
||||
});
|
||||
//# sourceMappingURL=test-hash-typeddata.js.map
|
1
lib.commonjs/_tests/test-hash-typeddata.js.map
Normal file
1
lib.commonjs/_tests/test-hash-typeddata.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"test-hash-typeddata.js","sourceRoot":"","sources":["../../src.ts/_tests/test-hash-typeddata.ts"],"names":[],"mappings":";;;;;AAAA,oDAA4B;AAC5B,yCAAuC;AAGvC,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,CAAC,CAAC;KACN;AACL,CAAC,CAAC,CAAC"}
|
112
lib.commonjs/_tests/test-hash.js
Normal file
112
lib.commonjs/_tests/test-hash.js
Normal file
@ -0,0 +1,112 @@
|
||||
"use strict";
|
||||
/*
|
||||
import assert from "assert";
|
||||
import { loadTests } from "./utils.js"
|
||||
import type { TestCaseNamehash } from "./types.js";
|
||||
|
||||
import { dnsEncode, isValidName, namehash } from "../index.js";
|
||||
|
||||
describe("Tests Namehash", function() {
|
||||
const tests = loadTests<TestCaseNamehash>("namehash");
|
||||
for (const test of tests) {
|
||||
it(`hashes ENS names: ${ JSON.stringify(test.ensName) }`, function() {
|
||||
const actual = namehash(test.ensName);
|
||||
|
||||
assert.equal(actual, test.namehash, "namehash");
|
||||
|
||||
// The empty string is not a valid ENS name
|
||||
if (test.ensName) {
|
||||
assert.ok(isValidName(test.ensName), "isValidName");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
describe("Tests Bad ENS Names", function() {
|
||||
const badTests: Array<{ ensName: any, prefix: string }> = [
|
||||
{ ensName: ".", prefix: "missing component" },
|
||||
{ ensName:"..", prefix: "missing component" },
|
||||
{ ensName:"ricmoo..eth", prefix: "missing component" },
|
||||
{ ensName:"ricmoo...eth", prefix: "missing component" },
|
||||
{ ensName:".foo", prefix: "missing component" },
|
||||
{ ensName:"foo.", prefix: "missing component" },
|
||||
{ ensName: 1234, prefix: "not a string" },
|
||||
{ ensName: true, prefix: "not a string" },
|
||||
];
|
||||
|
||||
// The empty string is not a valid name, but has a valid namehash
|
||||
// (the zero hash) as it is the base case for recursion
|
||||
it("empty ENS name", function() {
|
||||
assert.ok(!isValidName(""), "!isValidName");
|
||||
});
|
||||
|
||||
for (const { ensName, prefix } of badTests) {
|
||||
it(`fails on bad ENS name: ${ JSON.stringify(ensName) }`, function() {
|
||||
assert.ok(!isValidName(ensName), "!isValidName");
|
||||
assert.throws(() => {
|
||||
const result = namehash(ensName);
|
||||
console.log(result);
|
||||
}, (error) => {
|
||||
const errorPrefix = `invalid ENS name; ${ prefix }`;
|
||||
return (error.code === "INVALID_ARGUMENT" &&
|
||||
error.argument === "name" && error.value === ensName &&
|
||||
error.message.substring(0, errorPrefix.length) === errorPrefix);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
describe("Tests DNS Encoding", function() {
|
||||
const tests: Array<{ ensName: string, dnsEncoded: string}> = [
|
||||
{ ensName: "", dnsEncoded: "0x00" },
|
||||
{ ensName: "ricmoo.eth", dnsEncoded: "0x067269636d6f6f0365746800" },
|
||||
];
|
||||
|
||||
for (const { ensName, dnsEncoded } of tests) {
|
||||
it(`computes the DNS Encoding: ${ JSON.stringify(ensName) }`, function() {
|
||||
assert.equal(dnsEncode(ensName), dnsEncoded, "dnsEncoded");
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
describe("Tests DNS Names", function() {
|
||||
const badTests: Array<{ ensName: any, prefix: string}> = [
|
||||
{ ensName: ".", prefix: "invalid DNS name; missing component" },
|
||||
{ ensName: "foo..bar", prefix: "invalid DNS name; missing component" },
|
||||
{ ensName: ".foo", prefix: "invalid DNS name; missing component" },
|
||||
{ ensName: "foo.", prefix: "invalid DNS name; missing component" },
|
||||
{ ensName: 1234, prefix: "invalid DNS name; not a string" },
|
||||
{ ensName: true, prefix: "invalid DNS name; not a string" },
|
||||
];
|
||||
|
||||
for (const { ensName, prefix } of badTests) {
|
||||
it(`fails on bad DNS name: ${ JSON.stringify(ensName) }`, function() {
|
||||
assert.throws(() => {
|
||||
const result = dnsEncode(ensName);
|
||||
console.log(result);
|
||||
}, (error) => {
|
||||
return (error.code === "INVALID_ARGUMENT" &&
|
||||
error.argument === "name" && error.value === ensName &&
|
||||
error.message.substring(0, prefix.length) === prefix);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
const ensName = "foobar012345678901234567890123456789012345678901234567890123456789";
|
||||
const prefix = "too long";
|
||||
it(`fails on bad DNS name: ${ JSON.stringify(ensName) }`, function() {
|
||||
assert.throws(() => {
|
||||
const result = dnsEncode(ensName);
|
||||
console.log(result);
|
||||
}, (error) => {
|
||||
return (error.code === "INVALID_ARGUMENT" &&
|
||||
error.argument === "value" && error.value === ensName &&
|
||||
error.message.substring(0, prefix.length) === prefix);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
*/
|
||||
//# sourceMappingURL=test-hash.js.map
|
1
lib.commonjs/_tests/test-hash.js.map
Normal file
1
lib.commonjs/_tests/test-hash.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"test-hash.js","sourceRoot":"","sources":["../../src.ts/_tests/test-hash.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6GE"}
|
93
lib.commonjs/_tests/test-rlp.js
Normal file
93
lib.commonjs/_tests/test-rlp.js
Normal file
@ -0,0 +1,93 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const assert_1 = __importDefault(require("assert"));
|
||||
const utils_js_1 = require("./utils.js");
|
||||
const index_js_1 = require("../index.js");
|
||||
describe("Test RLP Coder", function () {
|
||||
const tests = (0, utils_js_1.loadTests)("rlp");
|
||||
tests.forEach(({ name, encoded, decoded }) => {
|
||||
it(`encodes RLP: ${name}`, function () {
|
||||
assert_1.default.equal((0, index_js_1.encodeRlp)(decoded), encoded);
|
||||
});
|
||||
});
|
||||
tests.forEach(({ name, encoded, decoded }) => {
|
||||
it(`decodes RLP: ${name}`, function () {
|
||||
assert_1.default.deepStrictEqual((0, index_js_1.decodeRlp)(encoded), decoded);
|
||||
});
|
||||
});
|
||||
});
|
||||
describe("Test bad RLP Data", function () {
|
||||
it("fails encoding data with invalid values", function () {
|
||||
assert_1.default.throws(() => {
|
||||
(0, index_js_1.encodeRlp)(["0x1234", 1234]);
|
||||
}, (error) => {
|
||||
return (error.code === "INVALID_ARGUMENT" &&
|
||||
error.argument === "object" &&
|
||||
error.value === 1234);
|
||||
});
|
||||
});
|
||||
it("fails decoding data with trailing junk", function () {
|
||||
assert_1.default.throws(() => {
|
||||
// Zeros_1
|
||||
(0, index_js_1.decodeRlp)("0x0042");
|
||||
}, (error) => {
|
||||
return (error.code === "INVALID_ARGUMENT" &&
|
||||
error.message.match(/^unexpected junk after rlp payload/) &&
|
||||
error.argument === "data" &&
|
||||
error.value === "0x0042");
|
||||
});
|
||||
});
|
||||
it("fails decoding short data", function () {
|
||||
assert_1.default.throws(() => {
|
||||
(0, index_js_1.decodeRlp)("0x");
|
||||
}, (error) => {
|
||||
return (error.code === "BUFFER_OVERRUN" &&
|
||||
error.message.match(/^data too short/) &&
|
||||
Buffer.from(error.buffer).toString("hex") === "" &&
|
||||
error.offset === 1 &&
|
||||
error.length === 0);
|
||||
});
|
||||
});
|
||||
it("fails decoding short data in child", function () {
|
||||
assert_1.default.throws(() => {
|
||||
(0, index_js_1.decodeRlp)("0xc8880102030405060708");
|
||||
}, (error) => {
|
||||
return (error.code === "BUFFER_OVERRUN" &&
|
||||
error.message.match(/^child data too short/) &&
|
||||
Buffer.from(error.buffer).toString("hex") === "c8880102030405060708" &&
|
||||
error.offset === 0 &&
|
||||
error.length === 8);
|
||||
});
|
||||
});
|
||||
it("fails decoding short segment data", function () {
|
||||
assert_1.default.throws(() => {
|
||||
// [["0x4243"], ["0x3145"]] = 0xc8 c3 82 4243 c3 82 3145
|
||||
// XXXX
|
||||
(0, index_js_1.decodeRlp)("0xc8c382c3823145");
|
||||
}, (error) => {
|
||||
return (error.code === "BUFFER_OVERRUN" &&
|
||||
error.message.match(/^data short segment too short/) &&
|
||||
Buffer.from(error.buffer).toString("hex") === "c8c382c3823145" &&
|
||||
error.offset === 9 &&
|
||||
error.length === 7);
|
||||
});
|
||||
});
|
||||
});
|
||||
/*
|
||||
utils.RLP.encode([["0x4243"], ["0x3145"]])
|
||||
|
||||
0xc8 c3 82 4243 c3 82 3145
|
||||
|
||||
{
|
||||
"name": "arrayShort2",
|
||||
"decoded": [
|
||||
"0x48656c6c6f20576f726c64",
|
||||
"0x48656c6c6f20576f726c64"
|
||||
],
|
||||
"encoded": "0xd8 8b 48656c6c6f20576f726c64 8b 48656c6c6f20576f726c64"
|
||||
},
|
||||
*/
|
||||
//# sourceMappingURL=test-rlp.js.map
|
1
lib.commonjs/_tests/test-rlp.js.map
Normal file
1
lib.commonjs/_tests/test-rlp.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"test-rlp.js","sourceRoot":"","sources":["../../src.ts/_tests/test-rlp.ts"],"names":[],"mappings":";;;;;AAAA,oDAA4B;AAE5B,yCAAuC;AAEvC,0CAAmD;AAInD,QAAQ,CAAC,gBAAgB,EAAE;IAEvB,MAAM,KAAK,GAAG,IAAA,oBAAS,EAAc,KAAK,CAAC,CAAC;IAE5C,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE;QACzC,EAAE,CAAC,gBAAiB,IAAK,EAAE,EAAE;YACzB,gBAAM,CAAC,KAAK,CAAC,IAAA,oBAAS,EAAC,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC;QAC9C,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE;QACzC,EAAE,CAAC,gBAAiB,IAAK,EAAE,EAAE;YACzB,gBAAM,CAAC,eAAe,CAAC,IAAA,oBAAS,EAAC,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC;QACxD,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAA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ests/test-transaction.js
Normal file
263
lib.commonjs/_tests/test-transaction.js
Normal file
@ -0,0 +1,263 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const assert_1 = __importDefault(require("assert"));
|
||||
const utils_js_1 = require("./utils.js");
|
||||
const index_js_1 = require("../index.js");
|
||||
const BN_0 = BigInt(0);
|
||||
describe("Tests Unsigned Transaction Serializing", function () {
|
||||
const tests = (0, utils_js_1.loadTests)("transactions");
|
||||
for (const test of tests) {
|
||||
it(`serialized unsigned legacy transaction: ${test.name}`, function () {
|
||||
const txData = Object.assign({}, test.transaction, {
|
||||
type: 0,
|
||||
accessList: undefined,
|
||||
maxFeePerGas: undefined,
|
||||
maxPriorityFeePerGas: undefined
|
||||
});
|
||||
// Use the testcase sans the chainId for a legacy test
|
||||
if (txData.chainId != null && parseInt(txData.chainId) != 0) {
|
||||
txData.chainId = "0x00";
|
||||
}
|
||||
const tx = index_js_1.Transaction.from(txData);
|
||||
assert_1.default.equal(tx.unsignedSerialized, test.unsignedLegacy, "unsignedLegacy");
|
||||
});
|
||||
}
|
||||
for (const test of tests) {
|
||||
// Unsupported parameters for EIP-155; i.e. unspecified chain ID
|
||||
if (!test.unsignedEip155) {
|
||||
continue;
|
||||
}
|
||||
it(`serialized unsigned EIP-155 transaction: ${test.name}`, function () {
|
||||
const txData = Object.assign({}, test.transaction, {
|
||||
type: 0,
|
||||
accessList: undefined,
|
||||
maxFeePerGas: undefined,
|
||||
maxPriorityFeePerGas: undefined
|
||||
});
|
||||
const tx = index_js_1.Transaction.from(txData);
|
||||
assert_1.default.equal(tx.unsignedSerialized, test.unsignedEip155, "unsignedEip155");
|
||||
});
|
||||
}
|
||||
for (const test of tests) {
|
||||
it(`serialized unsigned Berlin transaction: ${test.name}`, function () {
|
||||
const txData = Object.assign({}, test.transaction, {
|
||||
type: 1,
|
||||
maxFeePerGas: undefined,
|
||||
maxPriorityFeePerGas: undefined
|
||||
});
|
||||
const tx = index_js_1.Transaction.from(txData);
|
||||
assert_1.default.equal(tx.unsignedSerialized, test.unsignedBerlin, "unsignedBerlin");
|
||||
});
|
||||
}
|
||||
for (const test of tests) {
|
||||
it(`serialized unsigned London transaction: ${test.name}`, function () {
|
||||
const txData = Object.assign({}, test.transaction, { type: 2 });
|
||||
const tx = index_js_1.Transaction.from(txData);
|
||||
assert_1.default.equal(tx.unsignedSerialized, test.unsignedLondon, "unsignedLondon");
|
||||
});
|
||||
}
|
||||
});
|
||||
describe("Tests Signed Transaction Serializing", function () {
|
||||
const tests = (0, utils_js_1.loadTests)("transactions");
|
||||
for (const test of tests) {
|
||||
it(`serialized signed legacy transaction: ${test.name}`, function () {
|
||||
const txData = Object.assign({}, test.transaction, {
|
||||
type: 0,
|
||||
accessList: undefined,
|
||||
maxFeePerGas: undefined,
|
||||
maxPriorityFeePerGas: undefined,
|
||||
signature: test.signatureLegacy
|
||||
});
|
||||
// Use the testcase sans the chainId for a legacy test
|
||||
if (txData.chainId != null && parseInt(txData.chainId) != 0) {
|
||||
txData.chainId = "0x00";
|
||||
}
|
||||
const tx = index_js_1.Transaction.from(txData);
|
||||
assert_1.default.equal(tx.serialized, test.signedLegacy, "signedLegacy");
|
||||
});
|
||||
}
|
||||
for (const test of tests) {
|
||||
if (!test.unsignedEip155) {
|
||||
continue;
|
||||
}
|
||||
it(`serialized signed EIP-155 transaction: ${test.name}`, function () {
|
||||
const txData = Object.assign({}, test.transaction, {
|
||||
type: 0,
|
||||
accessList: undefined,
|
||||
maxFeePerGas: undefined,
|
||||
maxPriorityFeePerGas: undefined,
|
||||
signature: test.signatureEip155
|
||||
});
|
||||
const tx = index_js_1.Transaction.from(txData);
|
||||
assert_1.default.equal(tx.serialized, test.signedEip155, "signedEip155");
|
||||
});
|
||||
}
|
||||
for (const test of tests) {
|
||||
it(`serialized signed Berlin transaction: ${test.name}`, function () {
|
||||
const txData = Object.assign({}, test.transaction, {
|
||||
type: 1,
|
||||
maxFeePerGas: undefined,
|
||||
maxPriorityFeePerGas: undefined
|
||||
}, { signature: test.signatureBerlin });
|
||||
const tx = index_js_1.Transaction.from(txData);
|
||||
assert_1.default.equal(tx.serialized, test.signedBerlin, "signedBerlin");
|
||||
});
|
||||
}
|
||||
for (const test of tests) {
|
||||
it(`serialized signed London transaction: ${test.name}`, function () {
|
||||
const txData = Object.assign({}, test.transaction, {
|
||||
type: 2,
|
||||
signature: test.signatureLondon
|
||||
});
|
||||
const tx = index_js_1.Transaction.from(txData);
|
||||
assert_1.default.equal(tx.serialized, test.signedLondon, "signedLondon");
|
||||
});
|
||||
}
|
||||
});
|
||||
function assertTxUint(actual, _expected, name) {
|
||||
const expected = (_expected != null ? BigInt(_expected) : null);
|
||||
assert_1.default.equal(actual, expected, name);
|
||||
}
|
||||
function assertTxEqual(actual, expected) {
|
||||
assert_1.default.equal(actual.to, expected.to, "to");
|
||||
assert_1.default.equal(actual.nonce, expected.nonce, "nonce");
|
||||
assertTxUint(actual.gasLimit, expected.gasLimit, "gasLimit");
|
||||
assertTxUint(actual.gasPrice, expected.gasPrice, "gasPrice");
|
||||
assertTxUint(actual.maxFeePerGas, expected.maxFeePerGas, "maxFeePerGas");
|
||||
assertTxUint(actual.maxPriorityFeePerGas, expected.maxPriorityFeePerGas, "maxPriorityFeePerGas");
|
||||
assert_1.default.equal(actual.data, expected.data, "data");
|
||||
assertTxUint(actual.value, expected.value, "value");
|
||||
if (expected.accessList) {
|
||||
assert_1.default.equal(JSON.stringify(actual.accessList), JSON.stringify(expected.accessList), "accessList");
|
||||
}
|
||||
else {
|
||||
assert_1.default.equal(actual.accessList, null, "accessList:!null");
|
||||
}
|
||||
assertTxUint(actual.chainId, expected.chainId, "chainId");
|
||||
}
|
||||
function addDefault(tx, key, defaultValue) {
|
||||
if (tx[key] == null) {
|
||||
tx[key] = defaultValue;
|
||||
}
|
||||
}
|
||||
function addDefaults(tx) {
|
||||
tx = Object.assign({}, tx);
|
||||
addDefault(tx, "nonce", 0);
|
||||
addDefault(tx, "gasLimit", BN_0);
|
||||
addDefault(tx, "gasPrice", BN_0);
|
||||
addDefault(tx, "maxFeePerGas", BN_0);
|
||||
addDefault(tx, "maxPriorityFeePerGas", BN_0);
|
||||
addDefault(tx, "value", BN_0);
|
||||
addDefault(tx, "data", "0x");
|
||||
addDefault(tx, "accessList", []);
|
||||
addDefault(tx, "chainId", BN_0);
|
||||
return tx;
|
||||
}
|
||||
describe("Tests Unsigned Transaction Parsing", function () {
|
||||
const tests = (0, utils_js_1.loadTests)("transactions");
|
||||
for (const test of tests) {
|
||||
it(`parses unsigned legacy transaction: ${test.name}`, function () {
|
||||
const tx = index_js_1.Transaction.from(test.unsignedLegacy);
|
||||
const expected = addDefaults(test.transaction);
|
||||
expected.maxFeePerGas = null;
|
||||
expected.maxPriorityFeePerGas = null;
|
||||
expected.accessList = null;
|
||||
expected.chainId = BN_0;
|
||||
assertTxEqual(tx, expected);
|
||||
});
|
||||
}
|
||||
for (const test of tests) {
|
||||
if (!test.unsignedEip155) {
|
||||
continue;
|
||||
}
|
||||
it(`parses unsigned EIP-155 transaction: ${test.name}`, function () {
|
||||
const tx = index_js_1.Transaction.from(test.unsignedEip155);
|
||||
const expected = addDefaults(test.transaction);
|
||||
expected.maxFeePerGas = null;
|
||||
expected.maxPriorityFeePerGas = null;
|
||||
expected.accessList = null;
|
||||
assertTxEqual(tx, expected);
|
||||
});
|
||||
}
|
||||
for (const test of tests) {
|
||||
it(`parses unsigned Berlin transaction: ${test.name}`, function () {
|
||||
const tx = index_js_1.Transaction.from(test.unsignedBerlin);
|
||||
const expected = addDefaults(test.transaction);
|
||||
expected.maxFeePerGas = null;
|
||||
expected.maxPriorityFeePerGas = null;
|
||||
assertTxEqual(tx, expected);
|
||||
});
|
||||
}
|
||||
for (const test of tests) {
|
||||
it(`parses unsigned London transaction: ${test.name}`, function () {
|
||||
const tx = index_js_1.Transaction.from(test.unsignedLondon);
|
||||
const expected = addDefaults(test.transaction);
|
||||
expected.gasPrice = null;
|
||||
assertTxEqual(tx, expected);
|
||||
});
|
||||
}
|
||||
});
|
||||
describe("Tests Signed Transaction Parsing", function () {
|
||||
const tests = (0, utils_js_1.loadTests)("transactions");
|
||||
for (const test of tests) {
|
||||
it(`parses signed legacy transaction: ${test.name}`, function () {
|
||||
const tx = index_js_1.Transaction.from(test.signedLegacy);
|
||||
const expected = addDefaults(test.transaction);
|
||||
expected.maxFeePerGas = null;
|
||||
expected.maxPriorityFeePerGas = null;
|
||||
expected.accessList = null;
|
||||
expected.chainId = BN_0;
|
||||
assertTxEqual(tx, expected);
|
||||
assert_1.default.ok(!!tx.signature, "signature:!null");
|
||||
assert_1.default.equal(tx.signature.r, test.signatureLegacy.r, "signature.r");
|
||||
assert_1.default.equal(tx.signature.s, test.signatureLegacy.s, "signature.s");
|
||||
assert_1.default.equal(BigInt(tx.signature.v), BigInt(test.signatureLegacy.v), "signature.v");
|
||||
});
|
||||
}
|
||||
for (const test of tests) {
|
||||
if (!test.unsignedEip155) {
|
||||
continue;
|
||||
}
|
||||
it(`parses signed EIP-155 transaction: ${test.name}`, function () {
|
||||
const tx = index_js_1.Transaction.from(test.signedEip155);
|
||||
const expected = addDefaults(test.transaction);
|
||||
expected.maxFeePerGas = null;
|
||||
expected.maxPriorityFeePerGas = null;
|
||||
expected.accessList = null;
|
||||
assertTxEqual(tx, expected);
|
||||
assert_1.default.ok(!!tx.signature, "signature:!null");
|
||||
assert_1.default.equal(tx.signature.r, test.signatureEip155.r, "signature.r");
|
||||
assert_1.default.equal(tx.signature.s, test.signatureEip155.s, "signature.s");
|
||||
assert_1.default.equal(tx.signature.networkV, BigInt(test.signatureEip155.v), "signature.v");
|
||||
});
|
||||
}
|
||||
for (const test of tests) {
|
||||
it(`parses signed Berlin transaction: ${test.name}`, function () {
|
||||
const tx = index_js_1.Transaction.from(test.signedBerlin);
|
||||
const expected = addDefaults(test.transaction);
|
||||
expected.maxFeePerGas = null;
|
||||
expected.maxPriorityFeePerGas = null;
|
||||
assertTxEqual(tx, expected);
|
||||
assert_1.default.ok(!!tx.signature, "signature:!null");
|
||||
assert_1.default.equal(tx.signature.r, test.signatureBerlin.r, "signature.r");
|
||||
assert_1.default.equal(tx.signature.s, test.signatureBerlin.s, "signature.s");
|
||||
assert_1.default.equal(tx.signature.yParity, parseInt(test.signatureBerlin.v), "signature.v");
|
||||
});
|
||||
}
|
||||
for (const test of tests) {
|
||||
it(`parses signed London transaction: ${test.name}`, function () {
|
||||
const tx = index_js_1.Transaction.from(test.signedLondon);
|
||||
const expected = addDefaults(test.transaction);
|
||||
expected.gasPrice = null;
|
||||
assertTxEqual(tx, expected);
|
||||
assert_1.default.ok(!!tx.signature, "signature:!null");
|
||||
assert_1.default.equal(tx.signature.r, test.signatureLondon.r, "signature.r");
|
||||
assert_1.default.equal(tx.signature.s, test.signatureLondon.s, "signature.s");
|
||||
assert_1.default.equal(tx.signature.yParity, parseInt(test.signatureLondon.v), "signature.v");
|
||||
});
|
||||
}
|
||||
});
|
||||
//# sourceMappingURL=test-transaction.js.map
|
1
lib.commonjs/_tests/test-transaction.js.map
Normal file
1
lib.commonjs/_tests/test-transaction.js.map
Normal file
File diff suppressed because one or more lines are too long
125
lib.commonjs/_tests/test-wallet-hd.js
Normal file
125
lib.commonjs/_tests/test-wallet-hd.js
Normal file
@ -0,0 +1,125 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const assert_1 = __importDefault(require("assert"));
|
||||
const wordlists_js_1 = require("../wordlists/wordlists.js");
|
||||
const utils_js_1 = require("./utils.js");
|
||||
const index_js_1 = require("../index.js");
|
||||
const decoder = new TextDecoder();
|
||||
function fromHex(hex) {
|
||||
const data = Buffer.from(hex.substring(2), "hex");
|
||||
return decoder.decode(data);
|
||||
}
|
||||
describe("Test HDWallets", function () {
|
||||
function checkWallet(wallet, test) {
|
||||
assert_1.default.equal(wallet.chainCode, test.chainCode, "chainCode");
|
||||
assert_1.default.equal(wallet.depth, test.depth, "depth");
|
||||
assert_1.default.equal(wallet.index, test.index, "index");
|
||||
assert_1.default.equal(wallet.fingerprint, test.fingerprint, "fingerprint");
|
||||
assert_1.default.equal(wallet.parentFingerprint, test.parentFingerprint, "parentFingerprint");
|
||||
assert_1.default.equal(wallet.publicKey, test.publicKey, "publicKey");
|
||||
if (wallet instanceof index_js_1.HDNodeWallet) {
|
||||
assert_1.default.equal(wallet.extendedKey, test.xpriv, "xpriv");
|
||||
assert_1.default.equal(wallet.privateKey, test.privateKey, "privateKey");
|
||||
assert_1.default.equal(wallet.neuter().extendedKey, test.xpub, "xpub");
|
||||
}
|
||||
else if (wallet instanceof index_js_1.HDNodeVoidWallet) {
|
||||
assert_1.default.equal(wallet.extendedKey, test.xpub, "xpub");
|
||||
}
|
||||
}
|
||||
const tests = (0, utils_js_1.loadTests)("mnemonics");
|
||||
const checks = [];
|
||||
tests.forEach((test) => {
|
||||
// The phrase and password are stored in the test as hex so they
|
||||
// are safe as ascii7 values for viewing, printing, etc.
|
||||
const phrase = fromHex(test.phrase);
|
||||
const password = fromHex(test.password);
|
||||
const wordlist = wordlists_js_1.wordlists[test.locale];
|
||||
if (wordlist == null) {
|
||||
it(`tests ${test.name}`, function () {
|
||||
this.skip();
|
||||
});
|
||||
return;
|
||||
}
|
||||
const mnemonic = index_js_1.Mnemonic.fromPhrase(phrase, password, wordlist);
|
||||
function checkMnemonic(actual) {
|
||||
assert_1.default.equal(actual.phrase, phrase, "phrase");
|
||||
assert_1.default.equal(actual.password, password, "password");
|
||||
assert_1.default.equal(actual.wordlist.locale, test.locale, "locale");
|
||||
assert_1.default.equal(actual.entropy, mnemonic.entropy, "entropy");
|
||||
assert_1.default.equal(actual.computeSeed(), mnemonic.computeSeed(), "seed");
|
||||
}
|
||||
checks.push({
|
||||
phrase, password, wordlist, mnemonic, checkMnemonic, test
|
||||
});
|
||||
});
|
||||
for (const { test, checkMnemonic, phrase, password, wordlist } of checks) {
|
||||
it(`computes the HD keys by mnemonic: ${test.name}`, function () {
|
||||
for (const subtest of test.nodes) {
|
||||
const w = index_js_1.HDNodeWallet.fromPhrase(phrase, password, subtest.path, wordlist);
|
||||
assert_1.default.ok(w instanceof index_js_1.HDNodeWallet, "instanceof HDNodeWallet");
|
||||
assert_1.default.equal(w.path, subtest.path, "path");
|
||||
checkWallet(w, subtest);
|
||||
assert_1.default.ok(!!w.mnemonic, "has mnemonic");
|
||||
checkMnemonic(w.mnemonic);
|
||||
}
|
||||
});
|
||||
}
|
||||
for (const { test } of checks) {
|
||||
it(`computes the HD keys by entropy: ${test.name}`, function () {
|
||||
const seedRoot = index_js_1.HDNodeWallet.fromSeed(test.seed);
|
||||
for (const subtest of test.nodes) {
|
||||
const w = seedRoot.derivePath(subtest.path);
|
||||
assert_1.default.ok(w instanceof index_js_1.HDNodeWallet, "instanceof HDNodeWallet");
|
||||
assert_1.default.equal(w.path, subtest.path, "path");
|
||||
checkWallet(w, subtest);
|
||||
assert_1.default.equal(w.mnemonic, null);
|
||||
}
|
||||
});
|
||||
}
|
||||
for (const { test } of checks) {
|
||||
it(`computes the HD keys by enxtended private key: ${test.name}`, function () {
|
||||
for (const subtest of test.nodes) {
|
||||
const w = index_js_1.HDNodeWallet.fromExtendedKey(subtest.xpriv);
|
||||
assert_1.default.ok(w instanceof index_js_1.HDNodeWallet, "instanceof HDNodeWallet");
|
||||
checkWallet(w, subtest);
|
||||
assert_1.default.equal(w.mnemonic, null);
|
||||
}
|
||||
});
|
||||
}
|
||||
for (const { test, phrase, password, wordlist } of checks) {
|
||||
it(`computes the neutered HD keys by paths: ${test.name}`, function () {
|
||||
const root = index_js_1.HDNodeWallet.fromPhrase(phrase, password, "m", wordlist).neuter();
|
||||
for (const subtest of test.nodes) {
|
||||
if (subtest.path.indexOf("'") >= 0) {
|
||||
assert_1.default.throws(() => {
|
||||
const w = root.derivePath(subtest.path);
|
||||
console.log(w);
|
||||
}, (error) => {
|
||||
return (error.code === "UNSUPPORTED_OPERATION" &&
|
||||
error.message.match(/^cannot derive child of neutered node/) &&
|
||||
error.operation === "deriveChild");
|
||||
});
|
||||
}
|
||||
else {
|
||||
const w = root.derivePath(subtest.path);
|
||||
assert_1.default.ok(w instanceof index_js_1.HDNodeVoidWallet, "instanceof HDNodeVoidWallet");
|
||||
assert_1.default.equal(w.path, subtest.path, "path");
|
||||
checkWallet(w, subtest);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
for (const { test } of checks) {
|
||||
it(`computes the neutered HD keys by enxtended public key: ${test.name}`, function () {
|
||||
for (const subtest of test.nodes) {
|
||||
const w = index_js_1.HDNodeWallet.fromExtendedKey(subtest.xpub);
|
||||
assert_1.default.ok(w instanceof index_js_1.HDNodeVoidWallet, "instanceof HDNodeVoidWallet");
|
||||
checkWallet(w, subtest);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
//# sourceMappingURL=test-wallet-hd.js.map
|
1
lib.commonjs/_tests/test-wallet-hd.js.map
Normal file
1
lib.commonjs/_tests/test-wallet-hd.js.map
Normal file
File diff suppressed because one or more lines are too long
64
lib.commonjs/_tests/test-wallet-json.js
Normal file
64
lib.commonjs/_tests/test-wallet-json.js
Normal file
@ -0,0 +1,64 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const assert_1 = __importDefault(require("assert"));
|
||||
const utils_js_1 = require("./utils.js");
|
||||
const index_js_1 = require("../index.js");
|
||||
describe("Tests JSON Wallet Formats", function () {
|
||||
const tests = (0, utils_js_1.loadTests)("wallets");
|
||||
tests.forEach((test) => {
|
||||
if (test.type !== "crowdsale") {
|
||||
return;
|
||||
}
|
||||
it(`tests decrypting Crowdsale JSON: ${test.name}`, async function () {
|
||||
const password = Buffer.from(test.password.substring(2), "hex");
|
||||
const account = (0, index_js_1.decryptCrowdsaleJson)(test.content, password);
|
||||
assert_1.default.equal(account.address, test.address, "address");
|
||||
});
|
||||
});
|
||||
tests.forEach((test) => {
|
||||
if (test.type !== "keystore") {
|
||||
return;
|
||||
}
|
||||
it(`tests decrypting Keystore JSON (sync): ${test.name}`, function () {
|
||||
this.timeout(20000);
|
||||
const password = Buffer.from(test.password.substring(2), "hex");
|
||||
const account = (0, index_js_1.decryptKeystoreJsonSync)(test.content, password);
|
||||
//console.log(account);
|
||||
assert_1.default.equal(account.address, test.address, "address");
|
||||
});
|
||||
});
|
||||
tests.forEach((test) => {
|
||||
if (test.type !== "keystore") {
|
||||
return;
|
||||
}
|
||||
it(`tests decrypting Keystore JSON (async): ${test.name}`, async function () {
|
||||
this.timeout(20000);
|
||||
const password = Buffer.from(test.password.substring(2), "hex");
|
||||
const account = await (0, index_js_1.decryptKeystoreJson)(test.content, password);
|
||||
//console.log(account);
|
||||
assert_1.default.equal(account.address, test.address, "address");
|
||||
});
|
||||
});
|
||||
tests.forEach((test) => {
|
||||
it(`tests decrypting JSON (sync): ${test.name}`, function () {
|
||||
this.timeout(20000);
|
||||
const password = Buffer.from(test.password.substring(2), "hex");
|
||||
const wallet = index_js_1.Wallet.fromEncryptedJsonSync(test.content, password);
|
||||
//console.log(wallet);
|
||||
assert_1.default.equal(wallet.address, test.address, "address");
|
||||
});
|
||||
});
|
||||
tests.forEach((test) => {
|
||||
it(`tests decrypting JSON (async): ${test.name}`, async function () {
|
||||
this.timeout(20000);
|
||||
const password = Buffer.from(test.password.substring(2), "hex");
|
||||
const wallet = await index_js_1.Wallet.fromEncryptedJson(test.content, password);
|
||||
//console.log(wallet);
|
||||
assert_1.default.equal(wallet.address, test.address, "address");
|
||||
});
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=test-wallet-json.js.map
|
1
lib.commonjs/_tests/test-wallet-json.js.map
Normal file
1
lib.commonjs/_tests/test-wallet-json.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"test-wallet-json.js","sourceRoot":"","sources":["../../src.ts/_tests/test-wallet-json.ts"],"names":[],"mappings":";;;;;AAAA,oDAA4B;AAE5B,yCAAuC;AAIvC,0CAIqB;AAErB,QAAQ,CAAC,2BAA2B,EAAE;IACjC,MAAM,KAAK,GAAG,IAAA,oBAAS,EAAiB,SAAS,CAAC,CAAC;IACnD,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACnB,IAAI,IAAI,CAAC,IAAI,KAAK,WAAW,EAAE;YAAE,OAAO;SAAE;QAC1C,EAAE,CAAC,oCAAqC,IAAI,CAAC,IAAK,EAAE,EAAE,KAAK;YACvD,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;YAChE,MAAM,OAAO,GAAG,IAAA,+BAAoB,EAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;YAC7D,gBAAM,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QAC3D,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACnB,IAAI,IAAI,CAAC,IAAI,KAAK,UAAU,EAAE;YAAE,OAAO;SAAE;QACzC,EAAE,CAAC,0CAA2C,IAAI,CAAC,IAAK,EAAE,EAAE;YACxD,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YACpB,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;YAChE,MAAM,OAAO,GAAG,IAAA,kCAAuB,EAAC,IAAI,C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M,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QAC1D,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACnB,EAAE,CAAC,kCAAmC,IAAI,CAAC,IAAK,EAAE,EAAE,KAAK;YACrD,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YACpB,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;YAChE,MAAM,MAAM,GAAG,MAAM,iBAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;YACtE,sBAAsB;YACtB,gBAAM,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QAC1D,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACR,CAAC,CAAC,CAAC"}
|
126
lib.commonjs/_tests/test-wallet-mnemonic.js
Normal file
126
lib.commonjs/_tests/test-wallet-mnemonic.js
Normal file
@ -0,0 +1,126 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const assert_1 = __importDefault(require("assert"));
|
||||
const index_js_1 = require("../crypto/index.js");
|
||||
const utf8_js_1 = require("../utils/utf8.js");
|
||||
const wordlists_js_1 = require("../wordlists/wordlists.js");
|
||||
const index_js_2 = require("../index.js");
|
||||
const utils_js_1 = require("./utils.js");
|
||||
const decoder = new TextDecoder();
|
||||
function fromHex(hex) {
|
||||
const data = Buffer.from(hex.substring(2), "hex");
|
||||
return decoder.decode(data);
|
||||
}
|
||||
function repeat(text, length) {
|
||||
const result = [];
|
||||
while (result.length < length) {
|
||||
result.push(text);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
describe("Tests Mnemonics", function () {
|
||||
const tests = (0, utils_js_1.loadTests)("mnemonics");
|
||||
function runTest(phrase, mnemonic, test) {
|
||||
assert_1.default.ok(index_js_2.Mnemonic.isValidMnemonic(phrase, mnemonic.wordlist), "isValidMnemonic");
|
||||
if (test.locale === "en") {
|
||||
assert_1.default.ok(index_js_2.Mnemonic.isValidMnemonic(phrase), "isValidMnemonic (default)");
|
||||
}
|
||||
assert_1.default.equal(mnemonic.wordlist.locale, test.locale, "locale");
|
||||
assert_1.default.equal(mnemonic.entropy, test.entropy, "entropy");
|
||||
assert_1.default.equal(mnemonic.computeSeed(), test.seed, "seed");
|
||||
assert_1.default.equal((0, index_js_1.sha256)((0, utf8_js_1.toUtf8Bytes)(phrase)), test.phraseHash, "phraseHash");
|
||||
}
|
||||
for (const test of tests) {
|
||||
const wordlist = wordlists_js_1.wordlists[test.locale];
|
||||
it(`computes mnemonic from phrase: ${test.name}`, function () {
|
||||
if (wordlist == null) {
|
||||
this.skip();
|
||||
return;
|
||||
}
|
||||
const phrase = fromHex(test.phrase);
|
||||
const password = fromHex(test.password);
|
||||
const mnemonic = index_js_2.Mnemonic.fromPhrase(phrase, password, wordlist);
|
||||
runTest(phrase, mnemonic, test);
|
||||
});
|
||||
}
|
||||
for (const test of tests) {
|
||||
const wordlist = wordlists_js_1.wordlists[test.locale];
|
||||
it(`computes mnemonic from entropy: ${test.name}`, function () {
|
||||
if (wordlist == null) {
|
||||
this.skip();
|
||||
return;
|
||||
}
|
||||
const phrase = fromHex(test.phrase);
|
||||
const password = fromHex(test.password);
|
||||
const mnemonic = index_js_2.Mnemonic.fromEntropy(test.entropy, password, wordlist);
|
||||
runTest(phrase, mnemonic, test);
|
||||
});
|
||||
}
|
||||
});
|
||||
describe("Tests Bad Mnemonics Fail", function () {
|
||||
const badLengths = [
|
||||
repeat("abandon", 9),
|
||||
repeat("abandon", 16),
|
||||
repeat("abandon", 27), // 27 words; too long
|
||||
];
|
||||
for (const _phrase of badLengths) {
|
||||
const phrase = _phrase.join(" ");
|
||||
it(`fails on invalid mnemonic length: ${_phrase.length}`, function () {
|
||||
assert_1.default.ok(!index_js_2.Mnemonic.isValidMnemonic(phrase));
|
||||
assert_1.default.throws(function () {
|
||||
index_js_2.Mnemonic.fromPhrase(phrase);
|
||||
}, function (error) {
|
||||
return (error.code === "INVALID_ARGUMENT" &&
|
||||
error.message.match(/^invalid mnemonic length/) &&
|
||||
error.argument === "mnemonic" &&
|
||||
error.value === "[ REDACTED ]");
|
||||
});
|
||||
});
|
||||
}
|
||||
it("fails on invalid mnemonic word", function () {
|
||||
const phrase = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon wagmi";
|
||||
assert_1.default.ok(!index_js_2.Mnemonic.isValidMnemonic(phrase));
|
||||
assert_1.default.throws(function () {
|
||||
index_js_2.Mnemonic.fromPhrase(phrase);
|
||||
}, function (error) {
|
||||
return (error.code === "INVALID_ARGUMENT" &&
|
||||
error.message.match(/^invalid mnemonic word at index 11/) &&
|
||||
error.argument === "mnemonic" &&
|
||||
error.value === "[ REDACTED ]");
|
||||
});
|
||||
});
|
||||
it("fails on invalid mnemonic checksum", function () {
|
||||
const phrase = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon";
|
||||
assert_1.default.ok(!index_js_2.Mnemonic.isValidMnemonic(phrase));
|
||||
assert_1.default.throws(function () {
|
||||
index_js_2.Mnemonic.fromPhrase(phrase);
|
||||
}, function (error) {
|
||||
return (error.code === "INVALID_ARGUMENT" &&
|
||||
error.message.match(/^invalid mnemonic checksum/) &&
|
||||
error.argument === "mnemonic" &&
|
||||
error.value === "[ REDACTED ]");
|
||||
});
|
||||
});
|
||||
const badEntropyLengths = [
|
||||
repeat("42", 12),
|
||||
repeat("42", 15),
|
||||
repeat("42", 36), // 36 bytes; too long
|
||||
];
|
||||
for (const _entropy of badEntropyLengths) {
|
||||
const entropy = "0x" + _entropy.join("");
|
||||
it(`fails on invalid entropy length: ${_entropy.length}`, function () {
|
||||
assert_1.default.throws(function () {
|
||||
index_js_2.Mnemonic.fromEntropy(entropy);
|
||||
}, function (error) {
|
||||
return (error.code === "INVALID_ARGUMENT" &&
|
||||
error.message.match(/^invalid entropy size/) &&
|
||||
error.argument === "entropy" &&
|
||||
error.value === "[ REDACTED ]");
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
//# sourceMappingURL=test-wallet-mnemonic.js.map
|
1
lib.commonjs/_tests/test-wallet-mnemonic.js.map
Normal file
1
lib.commonjs/_tests/test-wallet-mnemonic.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"test-wallet-mnemonic.js","sourceRoot":"","sources":["../../src.ts/_tests/test-wallet-mnemonic.ts"],"names":[],"mappings":";;;;;AACA,oDAA4B;AAE5B,iDAA4C;AAC5C,8CAA+C;AAE/C,4DAAsD;AAEtD,0CAAuC;AAEvC,yCAAuC;AAGvC,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAClC,SAAS,OAAO,CAAC,GAAW;IACxB,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IAClD,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAChC,CAAC;AAED,SAAS,MAAM,CAAC,IAAY,EAAE,MAAc;IACxC,MAAM,MAAM,GAAG,EAAG,CAAC;IACnB,OAAO,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE;QAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;KAAE;IACrD,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,QAAQ,CAAC,iBAAiB,EAAE;IACxB,MAAM,KAAK,GAAG,IAAA,oBAAS,EAAmB,WAAW,CAAC,CAAC;IAEvD,SAAS,OAAO,CAAC,MAAc,EAAE,QAAkB,E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AK,UAAU;gBAC7B,KAAK,CAAC,KAAK,KAAK,cAAc,CAAC,CAAC;QACxC,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAGH,MAAM,iBAAiB,GAAG;QACtB,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;QAChB,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;QAChB,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,EAAG,qBAAqB;KAC3C,CAAC;IAEF,KAAK,MAAM,QAAQ,IAAI,iBAAiB,EAAE;QACtC,MAAM,OAAO,GAAG,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACzC,EAAE,CAAC,oCAAqC,QAAQ,CAAC,MAAO,EAAE,EAAE;YACxD,gBAAM,CAAC,MAAM,CAAC;gBACV,mBAAQ,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;YAClC,CAAC,EAAE,UAAS,KAAU;gBAClB,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,kBAAkB;oBACrC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,uBAAuB,CAAC;oBAC5C,KAAK,CAAC,QAAQ,KAAK,SAAS;oBAC5B,KAAK,CAAC,KAAK,KAAK,cAAc,CAAC,CAAC;YACxC,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;KACN;AACL,CAAC,CAAC,CAAA"}
|
77
lib.commonjs/_tests/test-wallet.js
Normal file
77
lib.commonjs/_tests/test-wallet.js
Normal file
@ -0,0 +1,77 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const assert_1 = __importDefault(require("assert"));
|
||||
const utils_js_1 = require("./utils.js");
|
||||
const index_js_1 = require("../index.js");
|
||||
describe("Test Private Key Wallet", function () {
|
||||
const tests = (0, utils_js_1.loadTests)("accounts");
|
||||
tests.forEach(({ name, privateKey, address }) => {
|
||||
it(`creates wallet: ${name}`, function () {
|
||||
const wallet = new index_js_1.Wallet(privateKey);
|
||||
assert_1.default.equal(wallet.privateKey, privateKey);
|
||||
assert_1.default.equal(wallet.address, address);
|
||||
});
|
||||
});
|
||||
});
|
||||
describe("Test Transaction Signing", function () {
|
||||
const tests = (0, utils_js_1.loadTests)("transactions");
|
||||
for (const test of tests) {
|
||||
it(`tests signing a legacy transaction: ${test.name}`, async function () {
|
||||
const wallet = new index_js_1.Wallet(test.privateKey);
|
||||
const txData = Object.assign({}, test.transaction, { type: 0, accessList: undefined, maxFeePerGas: undefined, maxPriorityFeePerGas: undefined });
|
||||
// Use the testcase sans the chainId for a legacy test
|
||||
if (txData.chainId != null && parseInt(txData.chainId) != 0) {
|
||||
txData.chainId = "0x00";
|
||||
}
|
||||
const signed = await wallet.signTransaction(txData);
|
||||
assert_1.default.equal(signed, test.signedLegacy, "signedLegacy");
|
||||
});
|
||||
}
|
||||
for (const test of tests) {
|
||||
if (!test.signedEip155) {
|
||||
continue;
|
||||
}
|
||||
it(`tests signing an EIP-155 transaction: ${test.name}`, async function () {
|
||||
const wallet = new index_js_1.Wallet(test.privateKey);
|
||||
const txData = Object.assign({}, test.transaction, { type: 0, accessList: undefined, maxFeePerGas: undefined, maxPriorityFeePerGas: undefined });
|
||||
const signed = await wallet.signTransaction(txData);
|
||||
assert_1.default.equal(signed, test.signedEip155, "signedEip155");
|
||||
});
|
||||
}
|
||||
for (const test of tests) {
|
||||
it(`tests signing a Berlin transaction: ${test.name}`, async function () {
|
||||
const wallet = new index_js_1.Wallet(test.privateKey);
|
||||
const txData = Object.assign({}, test.transaction, { type: 1, maxFeePerGas: undefined, maxPriorityFeePerGas: undefined });
|
||||
const signed = await wallet.signTransaction(txData);
|
||||
assert_1.default.equal(signed, test.signedBerlin, "signedBerlin");
|
||||
});
|
||||
}
|
||||
for (const test of tests) {
|
||||
it(`tests signing a London transaction: ${test.name}`, async function () {
|
||||
const wallet = new index_js_1.Wallet(test.privateKey);
|
||||
const txData = Object.assign({}, test.transaction, { type: 2 });
|
||||
const signed = await wallet.signTransaction(txData);
|
||||
assert_1.default.equal(signed, test.signedLondon, "signedLondon");
|
||||
});
|
||||
}
|
||||
});
|
||||
describe("Test Message Signing (EIP-191)", function () {
|
||||
});
|
||||
describe("Test Typed-Data Signing (EIP-712)", function () {
|
||||
const tests = (0, utils_js_1.loadTests)("typed-data");
|
||||
for (const test of tests) {
|
||||
const { privateKey, signature } = test;
|
||||
if (privateKey == null || signature == null) {
|
||||
continue;
|
||||
}
|
||||
it(`tests signing typed-data: ${test.name}`, async function () {
|
||||
const wallet = new index_js_1.Wallet(privateKey);
|
||||
const sig = await wallet.signTypedData(test.domain, test.types, test.data);
|
||||
assert_1.default.equal(sig, signature, "signature");
|
||||
});
|
||||
}
|
||||
});
|
||||
//# sourceMappingURL=test-wallet.js.map
|
1
lib.commonjs/_tests/test-wallet.js.map
Normal file
1
lib.commonjs/_tests/test-wallet.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"test-wallet.js","sourceRoot":"","sources":["../../src.ts/_tests/test-wallet.ts"],"names":[],"mappings":";;;;;AAAA,oDAA4B;AAE5B,yCAAuC;AAOvC,0CAAqC;AAGrC,QAAQ,CAAC,yBAAyB,EAAE;IAChC,MAAM,KAAK,GAAG,IAAA,oBAAS,EAAkB,UAAU,CAAC,CAAC;IAErD,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE,EAAE;QAC5C,EAAE,CAAC,mBAAoB,IAAK,EAAE,EAAE;YAC5B,MAAM,MAAM,GAAG,IAAI,iBAAM,CAAC,UAAU,CAAC,CAAC;YACtC,gBAAM,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;YAC5C,gBAAM,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC1C,CA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AAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC;QAC5D,CAAC,CAAC,CAAC;KACN;AACL,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,gCAAgC,EAAE;AAC3C,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,mCAAmC,EAAE;IAC1C,MAAM,KAAK,GAAG,IAAA,oBAAS,EAAoB,YAAY,CAAC,CAAC;IACzD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;QACtB,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;QACvC,IAAI,UAAU,IAAI,IAAI,IAAI,SAAS,IAAI,IAAI,EAAE;YAAE,SAAS;SAAE;QAC1D,EAAE,CAAC,6BAA8B,IAAI,CAAC,IAAK,EAAE,EAAE,KAAK;YAChD,MAAM,MAAM,GAAG,IAAI,iBAAM,CAAC,UAAU,CAAC,CAAC;YACtC,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;YAC3E,gBAAM,CAAC,KAAK,CAAC,GAAG,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC;QAC9C,CAAC,CAAC,CAAC;KACN;AACL,CAAC,CAAC,CAAC"}
|
71
lib.commonjs/_tests/test-wordlists.js
Normal file
71
lib.commonjs/_tests/test-wordlists.js
Normal file
@ -0,0 +1,71 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const assert_1 = __importDefault(require("assert"));
|
||||
const index_js_1 = require("../index.js");
|
||||
const utils_js_1 = require("./utils.js");
|
||||
describe('Check Wordlists', function () {
|
||||
const tests = (0, utils_js_1.loadTests)("wordlists");
|
||||
tests.forEach((test) => {
|
||||
let wordlist = index_js_1.wordlists[test.locale];
|
||||
if (wordlist == null) {
|
||||
return;
|
||||
}
|
||||
it(`matches wordlists: ${test.locale}`, function () {
|
||||
const words = test.content.split('\n');
|
||||
let check = "";
|
||||
for (let i = 0; i < 2048; i++) {
|
||||
let word = wordlist.getWord(i);
|
||||
check += (word + "\n");
|
||||
assert_1.default.equal(word, words[i]);
|
||||
assert_1.default.equal(wordlist.getWordIndex(word), i);
|
||||
}
|
||||
assert_1.default.equal(check, test.content);
|
||||
});
|
||||
});
|
||||
tests.forEach((test) => {
|
||||
let wordlist = index_js_1.wordlists[test.locale];
|
||||
if (wordlist == null) {
|
||||
return;
|
||||
}
|
||||
it(`splitting and joining are equivalent: ${test.locale}`, function () {
|
||||
const words = [];
|
||||
for (let i = 0; i < 12; i++) {
|
||||
words.push(wordlist.getWord(i));
|
||||
}
|
||||
const phrase = wordlist.join(words);
|
||||
const words2 = wordlist.split(phrase);
|
||||
const phrase2 = wordlist.join(words2);
|
||||
assert_1.default.deepStrictEqual(words2, words, "split words");
|
||||
assert_1.default.deepStrictEqual(phrase2, phrase, "re-joined words");
|
||||
});
|
||||
});
|
||||
tests.forEach((test) => {
|
||||
let wordlist = index_js_1.wordlists[test.locale];
|
||||
if (wordlist == null) {
|
||||
return;
|
||||
}
|
||||
it(`handles out-of-range values: ${test.locale}`, function () {
|
||||
assert_1.default.equal(wordlist.getWordIndex("foobar"), -1);
|
||||
assert_1.default.throws(() => {
|
||||
wordlist.getWord(-1);
|
||||
}, (error) => {
|
||||
return (error.code === "INVALID_ARGUMENT" &&
|
||||
error.message.match(/^invalid word index/) &&
|
||||
error.argument === "index" &&
|
||||
error.value === -1);
|
||||
});
|
||||
assert_1.default.throws(() => {
|
||||
wordlist.getWord(2048);
|
||||
}, (error) => {
|
||||
return (error.code === "INVALID_ARGUMENT" &&
|
||||
error.message.match(/^invalid word index/) &&
|
||||
error.argument === "index" &&
|
||||
error.value === 2048);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=test-wordlists.js.map
|
1
lib.commonjs/_tests/test-wordlists.js.map
Normal file
1
lib.commonjs/_tests/test-wordlists.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"test-wordlists.js","sourceRoot":"","sources":["../../src.ts/_tests/test-wordlists.ts"],"names":[],"mappings":";;;;;AAAA,oDAA4B;AAE5B,0CAAwC;AAExC,yCAAuC;AAKvC,QAAQ,CAAC,iBAAiB,EAAE;IACxB,MAAM,KAAK,GAAG,IAAA,oBAAS,EAAmB,WAAW,CAAC,CAAC;IAEvD,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACnB,IAAI,QAAQ,GAAG,oBAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACtC,IAAI,QAAQ,IAAI,IAAI,EAAE;YAAE,OAAO;SAAE;QAEjC,EAAE,CAAC,sBAAuB,IAAI,CAAC,MAAO,EAAE,EAAE;YACtC,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAEvC,IAAI,KAAK,GAAG,EAAE,CAAC;YACf,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE,EAAE;gBAC3B,IAAI,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;gBAC/B,KAAK,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;gBACvB,gBAAM,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC7B,gBAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;aAChD;YAED,gBAAM,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,KA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AC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;YACzB,CAAC,EAAE,CAAC,KAAU,EAAE,EAAE;gBACd,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,kBAAkB;oBACrC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,qBAAqB,CAAC;oBAC1C,KAAK,CAAC,QAAQ,KAAK,OAAO;oBAC1B,KAAK,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC;YAC5B,CAAC,CAAC,CAAC;YAEH,gBAAM,CAAC,MAAM,CAAC,GAAG,EAAE;gBACf,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAC3B,CAAC,EAAE,CAAC,KAAU,EAAE,EAAE;gBACd,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,kBAAkB;oBACrC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,qBAAqB,CAAC;oBAC1C,KAAK,CAAC,QAAQ,KAAK,OAAO;oBAC1B,KAAK,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC;YAC9B,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IAEP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
4
lib.commonjs/_tests/types.js
Normal file
4
lib.commonjs/_tests/types.js
Normal file
@ -0,0 +1,4 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
;
|
||||
//# sourceMappingURL=types.js.map
|
1
lib.commonjs/_tests/types.js.map
Normal file
1
lib.commonjs/_tests/types.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src.ts/_tests/types.ts"],"names":[],"mappings":";;AAiOC,CAAC"}
|
40
lib.commonjs/_tests/utils.js
Normal file
40
lib.commonjs/_tests/utils.js
Normal file
@ -0,0 +1,40 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.log = exports.loadTests = void 0;
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const zlib_1 = __importDefault(require("zlib"));
|
||||
// Find the package root (based on the nyc output/ folder)
|
||||
const root = (function () {
|
||||
let root = process.cwd();
|
||||
while (true) {
|
||||
if (fs_1.default.existsSync(path_1.default.join(root, "output"))) {
|
||||
return root;
|
||||
}
|
||||
const parent = path_1.default.join(root, "..");
|
||||
if (parent === root) {
|
||||
break;
|
||||
}
|
||||
root = parent;
|
||||
}
|
||||
throw new Error("could not find root");
|
||||
})();
|
||||
// Load the tests
|
||||
function loadTests(tag) {
|
||||
const filename = path_1.default.resolve(root, "testcases", tag + ".json.gz");
|
||||
return JSON.parse(zlib_1.default.gunzipSync(fs_1.default.readFileSync(filename)).toString());
|
||||
}
|
||||
exports.loadTests = loadTests;
|
||||
function log(context, text) {
|
||||
if (context && context.test && typeof (context.test._ethersLog) === "function") {
|
||||
context.test._ethersLog(text);
|
||||
}
|
||||
else {
|
||||
console.log(text);
|
||||
}
|
||||
}
|
||||
exports.log = log;
|
||||
//# sourceMappingURL=utils.js.map
|
1
lib.commonjs/_tests/utils.js.map
Normal file
1
lib.commonjs/_tests/utils.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src.ts/_tests/utils.ts"],"names":[],"mappings":";;;;;;AACA,4CAAmB;AACnB,gDAAwB;AACxB,gDAAwB;AAExB,0DAA0D;AAC1D,MAAM,IAAI,GAAG,CAAC;IACV,IAAI,IAAI,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAEzB,OAAO,IAAI,EAAE;QACT,IAAI,YAAE,CAAC,UAAU,CAAC,cAAI,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,EAAE;YAAE,OAAO,IAAI,CAAC;SAAE;QAC9D,MAAM,MAAM,GAAG,cAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACrC,IAAI,MAAM,KAAK,IAAI,EAAE;YAAE,MAAM;SAAE;QAC/B,IAAI,GAAG,MAAM,CAAC;KACjB;IAED,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;AAC3C,CAAC,CAAC,EAAE,CAAC;AAEL,iBAAiB;AACjB,SAAgB,SAAS,CAAI,GAAW;IACrC,MAAM,QAAQ,GAAG,cAAI,CAAC,OAAO,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,GAAG,UAAU,CAAC,CAAC;IACnE,OAAO,IAAI,CAAC,KAAK,CAAC,cAAI,CAAC,UAAU,CAAC,YAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;AAC5E,CAAC;AAHD,8BAGC;AAED,SAAgB,GAAG,CAAC,OAAY,EAAE,IAAY;IAC1C,IAAI,OAAO,IAAI,OAAO,CAAC,IAAI,IAAI,OAAM,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,UAAU,EAAE;QAC3E,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;KACjC;SAAM;QACH,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;KACrB;AACL,CAAC;AAND,kBAMC"}
|
5
lib.commonjs/_version.js
Normal file
5
lib.commonjs/_version.js
Normal file
@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.version = void 0;
|
||||
exports.version = "6.0.0-beta-exports.0";
|
||||
//# sourceMappingURL=_version.js.map
|
1
lib.commonjs/_version.js.map
Normal file
1
lib.commonjs/_version.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"_version.js","sourceRoot":"","sources":["../src.ts/_version.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG,sBAAsB,CAAC"}
|
80
lib.commonjs/abi/abi-coder.js
Normal file
80
lib.commonjs/abi/abi-coder.js
Normal file
@ -0,0 +1,80 @@
|
||||
"use strict";
|
||||
// See: https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.defaultAbiCoder = exports.AbiCoder = void 0;
|
||||
const logger_js_1 = require("../utils/logger.js");
|
||||
const abstract_coder_js_1 = require("./coders/abstract-coder.js");
|
||||
const address_js_1 = require("./coders/address.js");
|
||||
const array_js_1 = require("./coders/array.js");
|
||||
const boolean_js_1 = require("./coders/boolean.js");
|
||||
const bytes_js_1 = require("./coders/bytes.js");
|
||||
const fixed_bytes_js_1 = require("./coders/fixed-bytes.js");
|
||||
const null_js_1 = require("./coders/null.js");
|
||||
const number_js_1 = require("./coders/number.js");
|
||||
const string_js_1 = require("./coders/string.js");
|
||||
const tuple_js_1 = require("./coders/tuple.js");
|
||||
const fragments_js_1 = require("./fragments.js");
|
||||
const paramTypeBytes = new RegExp(/^bytes([0-9]*)$/);
|
||||
const paramTypeNumber = new RegExp(/^(u?int)([0-9]*)$/);
|
||||
class AbiCoder {
|
||||
#getCoder(param) {
|
||||
if (param.isArray()) {
|
||||
return new array_js_1.ArrayCoder(this.#getCoder(param.arrayChildren), param.arrayLength, param.name);
|
||||
}
|
||||
if (param.isTuple()) {
|
||||
return new tuple_js_1.TupleCoder(param.components.map((c) => this.#getCoder(c)), param.name);
|
||||
}
|
||||
switch (param.baseType) {
|
||||
case "address":
|
||||
return new address_js_1.AddressCoder(param.name);
|
||||
case "bool":
|
||||
return new boolean_js_1.BooleanCoder(param.name);
|
||||
case "string":
|
||||
return new string_js_1.StringCoder(param.name);
|
||||
case "bytes":
|
||||
return new bytes_js_1.BytesCoder(param.name);
|
||||
case "":
|
||||
return new null_js_1.NullCoder(param.name);
|
||||
}
|
||||
// u?int[0-9]*
|
||||
let match = param.type.match(paramTypeNumber);
|
||||
if (match) {
|
||||
let size = parseInt(match[2] || "256");
|
||||
if (size === 0 || size > 256 || (size % 8) !== 0) {
|
||||
logger_js_1.logger.throwArgumentError("invalid " + match[1] + " bit length", "param", param);
|
||||
}
|
||||
return new number_js_1.NumberCoder(size / 8, (match[1] === "int"), param.name);
|
||||
}
|
||||
// bytes[0-9]+
|
||||
match = param.type.match(paramTypeBytes);
|
||||
if (match) {
|
||||
let size = parseInt(match[1]);
|
||||
if (size === 0 || size > 32) {
|
||||
logger_js_1.logger.throwArgumentError("invalid bytes length", "param", param);
|
||||
}
|
||||
return new fixed_bytes_js_1.FixedBytesCoder(size, param.name);
|
||||
}
|
||||
return logger_js_1.logger.throwArgumentError("invalid type", "type", param.type);
|
||||
}
|
||||
getDefaultValue(types) {
|
||||
const coders = types.map((type) => this.#getCoder(fragments_js_1.ParamType.from(type)));
|
||||
const coder = new tuple_js_1.TupleCoder(coders, "_");
|
||||
return coder.defaultValue();
|
||||
}
|
||||
encode(types, values) {
|
||||
logger_js_1.logger.assertArgumentCount(values.length, types.length, "types/values length mismatch");
|
||||
const coders = types.map((type) => this.#getCoder(fragments_js_1.ParamType.from(type)));
|
||||
const coder = (new tuple_js_1.TupleCoder(coders, "_"));
|
||||
const writer = new abstract_coder_js_1.Writer();
|
||||
coder.encode(writer, values);
|
||||
return writer.data;
|
||||
}
|
||||
decode(types, data, loose) {
|
||||
const coders = types.map((type) => this.#getCoder(fragments_js_1.ParamType.from(type)));
|
||||
const coder = new tuple_js_1.TupleCoder(coders, "_");
|
||||
return coder.decode(new abstract_coder_js_1.Reader(data, loose));
|
||||
}
|
||||
}
|
||||
exports.AbiCoder = AbiCoder;
|
||||
exports.defaultAbiCoder = new AbiCoder();
|
||||
//# sourceMappingURL=abi-coder.js.map
|
1
lib.commonjs/abi/abi-coder.js.map
Normal file
1
lib.commonjs/abi/abi-coder.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"abi-coder.js","sourceRoot":"","sources":["../../src.ts/abi/abi-coder.ts"],"names":[],"mappings":";AAA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@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.parseBytes32String = exports.formatBytes32String = void 0;
|
||||
const data_js_1 = require("../utils/data.js");
|
||||
const logger_js_1 = require("../utils/logger.js");
|
||||
const utf8_js_1 = require("../utils/utf8.js");
|
||||
function formatBytes32String(text) {
|
||||
// Get the bytes
|
||||
const bytes = (0, utf8_js_1.toUtf8Bytes)(text);
|
||||
// Check we have room for null-termination
|
||||
if (bytes.length > 31) {
|
||||
throw new Error("bytes32 string must be less than 32 bytes");
|
||||
}
|
||||
// Zero-pad (implicitly null-terminates)
|
||||
return (0, data_js_1.zeroPadBytes)(bytes, 32);
|
||||
}
|
||||
exports.formatBytes32String = formatBytes32String;
|
||||
function parseBytes32String(_bytes) {
|
||||
const data = logger_js_1.logger.getBytes(_bytes, "bytes");
|
||||
// Must be 32 bytes with a null-termination
|
||||
if (data.length !== 32) {
|
||||
throw new Error("invalid bytes32 - not 32 bytes long");
|
||||
}
|
||||
if (data[31] !== 0) {
|
||||
throw new Error("invalid bytes32 string - no null terminator");
|
||||
}
|
||||
// Find the null termination
|
||||
let length = 31;
|
||||
while (data[length - 1] === 0) {
|
||||
length--;
|
||||
}
|
||||
// Determine the string value
|
||||
return (0, utf8_js_1.toUtf8String)(data.slice(0, length));
|
||||
}
|
||||
exports.parseBytes32String = parseBytes32String;
|
||||
//# sourceMappingURL=bytes32.js.map
|
1
lib.commonjs/abi/bytes32.js.map
Normal file
1
lib.commonjs/abi/bytes32.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"bytes32.js","sourceRoot":"","sources":["../../src.ts/abi/bytes32.ts"],"names":[],"mappings":";;;AACA,8CAAgD;AAEhD,kDAA4C;AAE5C,8CAA6D;AAK7D,SAAgB,mBAAmB,CAAC,IAAY;IAE5C,gBAAgB;IAChB,MAAM,KAAK,GAAG,IAAA,qBAAW,EAAC,IAAI,CAAC,CAAC;IAEhC,0CAA0C;IAC1C,IAAI,KAAK,CAAC,MAAM,GAAG,EAAE,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;KAAE;IAExF,wCAAwC;IACxC,OAAO,IAAA,sBAAY,EAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AACnC,CAAC;AAVD,kDAUC;AAED,SAAgB,kBAAkB,CAAC,MAAiB;IAChD,MAAM,IAAI,GAAG,kBAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAE9C,2CAA2C;IAC3C,IAAI,IAAI,CAAC,MAAM,KAAK,EAAE,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;KAAE;IACnF,IAAI,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;KAAE;IAEvF,4BAA4B;IAC5B,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,OAAO,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,EAAE;QAAE,MAAM,EAAE,CAAC;KAAE;IAE5C,6BAA6B;IAC7B,OAAO,IAAA,sBAAY,EAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;AAC/C,CAAC;AAbD,gDAaC"}
|
273
lib.commonjs/abi/coders/abstract-coder.js
Normal file
273
lib.commonjs/abi/coders/abstract-coder.js
Normal file
@ -0,0 +1,273 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Reader = exports.Writer = exports.Coder = exports.checkResultErrors = exports.Result = exports.WordSize = void 0;
|
||||
const maths_js_1 = require("../../utils/maths.js");
|
||||
const data_js_1 = require("../../utils/data.js");
|
||||
const properties_js_1 = require("../../utils/properties.js");
|
||||
const logger_js_1 = require("../../utils/logger.js");
|
||||
exports.WordSize = 32;
|
||||
const Padding = new Uint8Array(exports.WordSize);
|
||||
// Properties used to immediate pass through to the underlying object
|
||||
// - `then` is used to detect if an object is a Promise for await
|
||||
const passProperties = ["then"];
|
||||
const _guard = {};
|
||||
class Result extends Array {
|
||||
#indices;
|
||||
constructor(guard, items, keys) {
|
||||
logger_js_1.logger.assertPrivate(guard, _guard, "Result");
|
||||
super(...items);
|
||||
// Name lookup table
|
||||
this.#indices = new Map();
|
||||
if (keys) {
|
||||
keys.forEach((key, index) => {
|
||||
if (key == null) {
|
||||
return;
|
||||
}
|
||||
if (this.#indices.has(key)) {
|
||||
(this.#indices.get(key)).push(index);
|
||||
}
|
||||
else {
|
||||
this.#indices.set(key, [index]);
|
||||
}
|
||||
});
|
||||
}
|
||||
Object.freeze(this);
|
||||
return new Proxy(this, {
|
||||
get: (target, prop, receiver) => {
|
||||
if (typeof (prop) === "string") {
|
||||
if (prop.match(/^[0-9]+$/)) {
|
||||
const index = logger_js_1.logger.getNumber(prop, "%index");
|
||||
if (index < 0 || index >= this.length) {
|
||||
throw new RangeError("out of result range");
|
||||
}
|
||||
const item = target[index];
|
||||
if (item instanceof Error) {
|
||||
this.#throwError(`index ${index}`, item);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
// Pass important checks (like `then` for Promise) through
|
||||
if (prop in target || passProperties.indexOf(prop) >= 0) {
|
||||
return Reflect.get(target, prop, receiver);
|
||||
}
|
||||
// Something that could be a result keyword value
|
||||
if (!(prop in target)) {
|
||||
return target.getValue(prop);
|
||||
}
|
||||
}
|
||||
return Reflect.get(target, prop, receiver);
|
||||
}
|
||||
});
|
||||
}
|
||||
/*
|
||||
toJSON(): any {
|
||||
if (this.#indices.length === this.length) {
|
||||
const result: Record<string, any> = { };
|
||||
for (const key of this.#indices.keys()) {
|
||||
result[key] = ths.getValue(key);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
*/
|
||||
slice(start, end) {
|
||||
if (start == null) {
|
||||
start = 0;
|
||||
}
|
||||
if (end == null) {
|
||||
end = this.length;
|
||||
}
|
||||
const result = [];
|
||||
for (let i = start; i < end; i++) {
|
||||
let value;
|
||||
try {
|
||||
value = this[i];
|
||||
}
|
||||
catch (error) {
|
||||
value = error.error;
|
||||
}
|
||||
result.push(value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#throwError(name, error) {
|
||||
const wrapped = new Error(`deferred error during ABI decoding triggered accessing ${name}`);
|
||||
wrapped.error = error;
|
||||
throw wrapped;
|
||||
}
|
||||
getValue(name) {
|
||||
const index = this.#indices.get(name);
|
||||
if (index != null && index.length === 1) {
|
||||
const item = this[index[0]];
|
||||
if (item instanceof Error) {
|
||||
this.#throwError(`property ${JSON.stringify(name)}`, item);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
throw new Error(`no named parameter: ${JSON.stringify(name)}`);
|
||||
}
|
||||
static fromItems(items, keys) {
|
||||
return new Result(_guard, items, keys);
|
||||
}
|
||||
}
|
||||
exports.Result = Result;
|
||||
function checkResultErrors(result) {
|
||||
// Find the first error (if any)
|
||||
const errors = [];
|
||||
const checkErrors = function (path, object) {
|
||||
if (!Array.isArray(object)) {
|
||||
return;
|
||||
}
|
||||
for (let key in object) {
|
||||
const childPath = path.slice();
|
||||
childPath.push(key);
|
||||
try {
|
||||
checkErrors(childPath, object[key]);
|
||||
}
|
||||
catch (error) {
|
||||
errors.push({ path: childPath, error: error });
|
||||
}
|
||||
}
|
||||
};
|
||||
checkErrors([], result);
|
||||
return errors;
|
||||
}
|
||||
exports.checkResultErrors = checkResultErrors;
|
||||
function getValue(value) {
|
||||
let bytes = (0, maths_js_1.toArray)(value);
|
||||
if (bytes.length > exports.WordSize) {
|
||||
logger_js_1.logger.throwError("value out-of-bounds", "BUFFER_OVERRUN", {
|
||||
buffer: bytes,
|
||||
length: exports.WordSize,
|
||||
offset: bytes.length
|
||||
});
|
||||
}
|
||||
if (bytes.length !== exports.WordSize) {
|
||||
bytes = logger_js_1.logger.getBytesCopy((0, data_js_1.concat)([Padding.slice(bytes.length % exports.WordSize), bytes]));
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
class Coder {
|
||||
// The coder name:
|
||||
// - address, uint256, tuple, array, etc.
|
||||
name;
|
||||
// The fully expanded type, including composite types:
|
||||
// - address, uint256, tuple(address,bytes), uint256[3][4][], etc.
|
||||
type;
|
||||
// The localName bound in the signature, in this example it is "baz":
|
||||
// - tuple(address foo, uint bar) baz
|
||||
localName;
|
||||
// Whether this type is dynamic:
|
||||
// - Dynamic: bytes, string, address[], tuple(boolean[]), etc.
|
||||
// - Not Dynamic: address, uint256, boolean[3], tuple(address, uint8)
|
||||
dynamic;
|
||||
constructor(name, type, localName, dynamic) {
|
||||
(0, properties_js_1.defineProperties)(this, { name, type, localName, dynamic }, {
|
||||
name: "string", type: "string", localName: "string", dynamic: "boolean"
|
||||
});
|
||||
}
|
||||
_throwError(message, value) {
|
||||
return logger_js_1.logger.throwArgumentError(message, this.localName, value);
|
||||
}
|
||||
}
|
||||
exports.Coder = Coder;
|
||||
class Writer {
|
||||
// An array of WordSize lengthed objects to concatenation
|
||||
#data;
|
||||
#dataLength;
|
||||
constructor() {
|
||||
this.#data = [];
|
||||
this.#dataLength = 0;
|
||||
}
|
||||
get data() {
|
||||
return (0, data_js_1.concat)(this.#data);
|
||||
}
|
||||
get length() { return this.#dataLength; }
|
||||
#writeData(data) {
|
||||
this.#data.push(data);
|
||||
this.#dataLength += data.length;
|
||||
return data.length;
|
||||
}
|
||||
appendWriter(writer) {
|
||||
return this.#writeData(logger_js_1.logger.getBytesCopy(writer.data));
|
||||
}
|
||||
// Arrayish item; pad on the right to *nearest* WordSize
|
||||
writeBytes(value) {
|
||||
let bytes = logger_js_1.logger.getBytesCopy(value);
|
||||
const paddingOffset = bytes.length % exports.WordSize;
|
||||
if (paddingOffset) {
|
||||
bytes = logger_js_1.logger.getBytesCopy((0, data_js_1.concat)([bytes, Padding.slice(paddingOffset)]));
|
||||
}
|
||||
return this.#writeData(bytes);
|
||||
}
|
||||
// Numeric item; pad on the left *to* WordSize
|
||||
writeValue(value) {
|
||||
return this.#writeData(getValue(value));
|
||||
}
|
||||
// Inserts a numeric place-holder, returning a callback that can
|
||||
// be used to asjust the value later
|
||||
writeUpdatableValue() {
|
||||
const offset = this.#data.length;
|
||||
this.#data.push(Padding);
|
||||
this.#dataLength += exports.WordSize;
|
||||
return (value) => {
|
||||
this.#data[offset] = getValue(value);
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.Writer = Writer;
|
||||
class Reader {
|
||||
// Allows incomplete unpadded data to be read; otherwise an error
|
||||
// is raised if attempting to overrun the buffer. This is required
|
||||
// to deal with an old Solidity bug, in which event data for
|
||||
// external (not public thoguh) was tightly packed.
|
||||
allowLoose;
|
||||
#data;
|
||||
#offset;
|
||||
constructor(data, allowLoose) {
|
||||
(0, properties_js_1.defineProperties)(this, { allowLoose: !!allowLoose });
|
||||
this.#data = logger_js_1.logger.getBytesCopy(data);
|
||||
this.#offset = 0;
|
||||
}
|
||||
get data() { return (0, data_js_1.hexlify)(this.#data); }
|
||||
get dataLength() { return this.#data.length; }
|
||||
get consumed() { return this.#offset; }
|
||||
get bytes() { return new Uint8Array(this.#data); }
|
||||
#peekBytes(offset, length, loose) {
|
||||
let alignedLength = Math.ceil(length / exports.WordSize) * exports.WordSize;
|
||||
if (this.#offset + alignedLength > this.#data.length) {
|
||||
if (this.allowLoose && loose && this.#offset + length <= this.#data.length) {
|
||||
alignedLength = length;
|
||||
}
|
||||
else {
|
||||
logger_js_1.logger.throwError("data out-of-bounds", "BUFFER_OVERRUN", {
|
||||
buffer: logger_js_1.logger.getBytesCopy(this.#data),
|
||||
length: this.#data.length,
|
||||
offset: this.#offset + alignedLength
|
||||
});
|
||||
}
|
||||
}
|
||||
return this.#data.slice(this.#offset, this.#offset + alignedLength);
|
||||
}
|
||||
// Create a sub-reader with the same underlying data, but offset
|
||||
subReader(offset) {
|
||||
return new Reader(this.#data.slice(this.#offset + offset), this.allowLoose);
|
||||
}
|
||||
// Read bytes
|
||||
readBytes(length, loose) {
|
||||
let bytes = this.#peekBytes(0, length, !!loose);
|
||||
this.#offset += bytes.length;
|
||||
// @TODO: Make sure the length..end bytes are all 0?
|
||||
return bytes.slice(0, length);
|
||||
}
|
||||
// Read a numeric values
|
||||
readValue() {
|
||||
return (0, maths_js_1.toBigInt)(this.readBytes(exports.WordSize));
|
||||
}
|
||||
readIndex() {
|
||||
return (0, maths_js_1.toNumber)(this.readBytes(exports.WordSize));
|
||||
}
|
||||
}
|
||||
exports.Reader = Reader;
|
||||
//# sourceMappingURL=abstract-coder.js.map
|
1
lib.commonjs/abi/coders/abstract-coder.js.map
Normal file
1
lib.commonjs/abi/coders/abstract-coder.js.map
Normal file
File diff suppressed because one or more lines are too long
30
lib.commonjs/abi/coders/address.js
Normal file
30
lib.commonjs/abi/coders/address.js
Normal file
@ -0,0 +1,30 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AddressCoder = void 0;
|
||||
const index_js_1 = require("../../address/index.js");
|
||||
const maths_js_1 = require("../../utils/maths.js");
|
||||
const typed_js_1 = require("../typed.js");
|
||||
const abstract_coder_js_1 = require("./abstract-coder.js");
|
||||
class AddressCoder extends abstract_coder_js_1.Coder {
|
||||
constructor(localName) {
|
||||
super("address", "address", localName, false);
|
||||
}
|
||||
defaultValue() {
|
||||
return "0x0000000000000000000000000000000000000000";
|
||||
}
|
||||
encode(writer, _value) {
|
||||
let value = typed_js_1.Typed.dereference(_value, "string");
|
||||
try {
|
||||
value = (0, index_js_1.getAddress)(value);
|
||||
}
|
||||
catch (error) {
|
||||
return this._throwError(error.message, _value);
|
||||
}
|
||||
return writer.writeValue(value);
|
||||
}
|
||||
decode(reader) {
|
||||
return (0, index_js_1.getAddress)((0, maths_js_1.toHex)(reader.readValue(), 20));
|
||||
}
|
||||
}
|
||||
exports.AddressCoder = AddressCoder;
|
||||
//# sourceMappingURL=address.js.map
|
1
lib.commonjs/abi/coders/address.js.map
Normal file
1
lib.commonjs/abi/coders/address.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"address.js","sourceRoot":"","sources":["../../../src.ts/abi/coders/address.ts"],"names":[],"mappings":";;;AAAA,qDAAoD;AACpD,mDAA6C;AAE7C,0CAAoC;AACpC,2DAA4C;AAK5C,MAAa,YAAa,SAAQ,yBAAK;IAEnC,YAAY,SAAiB;QACzB,KAAK,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;IAClD,CAAC;IAED,YAAY;QACR,OAAO,4CAA4C,CAAC;IACxD,CAAC;IAED,MAAM,CAAC,MAAc,EAAE,MAAsB;QACzC,IAAI,KAAK,GAAG,gBAAK,CAAC,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QAChD,IAAI;YACA,KAAK,GAAG,IAAA,qBAAU,EAAC,KAAK,CAAC,CAAC;SAC7B;QAAC,OAAO,KAAU,EAAE;YACjB,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;SAClD;QACD,OAAO,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;IAED,MAAM,CAAC,MAAc;QACjB,OAAO,IAAA,qBAAU,EAAC,IAAA,gBAAK,EAAC,MAAM,CAAC,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;IACrD,CAAC;CACJ;AAvBD,oCAuBC"}
|
23
lib.commonjs/abi/coders/anonymous.js
Normal file
23
lib.commonjs/abi/coders/anonymous.js
Normal file
@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AnonymousCoder = void 0;
|
||||
const abstract_coder_js_1 = require("./abstract-coder.js");
|
||||
// Clones the functionality of an existing Coder, but without a localName
|
||||
class AnonymousCoder extends abstract_coder_js_1.Coder {
|
||||
coder;
|
||||
constructor(coder) {
|
||||
super(coder.name, coder.type, "_", coder.dynamic);
|
||||
this.coder = coder;
|
||||
}
|
||||
defaultValue() {
|
||||
return this.coder.defaultValue();
|
||||
}
|
||||
encode(writer, value) {
|
||||
return this.coder.encode(writer, value);
|
||||
}
|
||||
decode(reader) {
|
||||
return this.coder.decode(reader);
|
||||
}
|
||||
}
|
||||
exports.AnonymousCoder = AnonymousCoder;
|
||||
//# sourceMappingURL=anonymous.js.map
|
1
lib.commonjs/abi/coders/anonymous.js.map
Normal file
1
lib.commonjs/abi/coders/anonymous.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"anonymous.js","sourceRoot":"","sources":["../../../src.ts/abi/coders/anonymous.ts"],"names":[],"mappings":";;;AAAA,2DAA4C;AAI5C,yEAAyE;AACzE,MAAa,cAAe,SAAQ,yBAAK;IAC7B,KAAK,CAAQ;IAErB,YAAY,KAAY;QACpB,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;QAClD,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;IAED,YAAY;QACR,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE,CAAC;IACrC,CAAC;IAED,MAAM,CAAC,MAAc,EAAE,KAAU;QAC7B,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC5C,CAAC;IAED,MAAM,CAAC,MAAc;QACjB,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACrC,CAAC;CACJ;AAnBD,wCAmBC"}
|
178
lib.commonjs/abi/coders/array.js
Normal file
178
lib.commonjs/abi/coders/array.js
Normal file
@ -0,0 +1,178 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ArrayCoder = exports.unpack = exports.pack = void 0;
|
||||
const properties_js_1 = require("../../utils/properties.js");
|
||||
const errors_js_1 = require("../../utils/errors.js");
|
||||
const logger_js_1 = require("../../utils/logger.js");
|
||||
const typed_js_1 = require("../typed.js");
|
||||
const abstract_coder_js_1 = require("./abstract-coder.js");
|
||||
const anonymous_js_1 = require("./anonymous.js");
|
||||
function pack(writer, coders, values) {
|
||||
let arrayValues = [];
|
||||
if (Array.isArray(values)) {
|
||||
arrayValues = values;
|
||||
}
|
||||
else if (values && typeof (values) === "object") {
|
||||
let unique = {};
|
||||
arrayValues = coders.map((coder) => {
|
||||
const name = coder.localName;
|
||||
if (!name) {
|
||||
logger_js_1.logger.throwError("cannot encode object for signature with missing names", "INVALID_ARGUMENT", {
|
||||
argument: "values",
|
||||
info: { coder },
|
||||
value: values
|
||||
});
|
||||
}
|
||||
if (unique[name]) {
|
||||
logger_js_1.logger.throwError("cannot encode object for signature with duplicate names", "INVALID_ARGUMENT", {
|
||||
argument: "values",
|
||||
info: { coder },
|
||||
value: values
|
||||
});
|
||||
}
|
||||
unique[name] = true;
|
||||
return values[name];
|
||||
});
|
||||
}
|
||||
else {
|
||||
logger_js_1.logger.throwArgumentError("invalid tuple value", "tuple", values);
|
||||
}
|
||||
if (coders.length !== arrayValues.length) {
|
||||
logger_js_1.logger.throwArgumentError("types/value length mismatch", "tuple", values);
|
||||
}
|
||||
let staticWriter = new abstract_coder_js_1.Writer();
|
||||
let dynamicWriter = new abstract_coder_js_1.Writer();
|
||||
let updateFuncs = [];
|
||||
coders.forEach((coder, index) => {
|
||||
let value = arrayValues[index];
|
||||
if (coder.dynamic) {
|
||||
// Get current dynamic offset (for the future pointer)
|
||||
let dynamicOffset = dynamicWriter.length;
|
||||
// Encode the dynamic value into the dynamicWriter
|
||||
coder.encode(dynamicWriter, value);
|
||||
// Prepare to populate the correct offset once we are done
|
||||
let updateFunc = staticWriter.writeUpdatableValue();
|
||||
updateFuncs.push((baseOffset) => {
|
||||
updateFunc(baseOffset + dynamicOffset);
|
||||
});
|
||||
}
|
||||
else {
|
||||
coder.encode(staticWriter, value);
|
||||
}
|
||||
});
|
||||
// Backfill all the dynamic offsets, now that we know the static length
|
||||
updateFuncs.forEach((func) => { func(staticWriter.length); });
|
||||
let length = writer.appendWriter(staticWriter);
|
||||
length += writer.appendWriter(dynamicWriter);
|
||||
return length;
|
||||
}
|
||||
exports.pack = pack;
|
||||
function unpack(reader, coders) {
|
||||
let values = [];
|
||||
let keys = [];
|
||||
// A reader anchored to this base
|
||||
let baseReader = reader.subReader(0);
|
||||
coders.forEach((coder) => {
|
||||
let value = null;
|
||||
if (coder.dynamic) {
|
||||
let offset = reader.readIndex();
|
||||
let offsetReader = baseReader.subReader(offset);
|
||||
try {
|
||||
value = coder.decode(offsetReader);
|
||||
}
|
||||
catch (error) {
|
||||
// Cannot recover from this
|
||||
if ((0, errors_js_1.isError)(error, "BUFFER_OVERRUN")) {
|
||||
throw error;
|
||||
}
|
||||
value = error;
|
||||
value.baseType = coder.name;
|
||||
value.name = coder.localName;
|
||||
value.type = coder.type;
|
||||
}
|
||||
}
|
||||
else {
|
||||
try {
|
||||
value = coder.decode(reader);
|
||||
}
|
||||
catch (error) {
|
||||
// Cannot recover from this
|
||||
if ((0, errors_js_1.isError)(error, "BUFFER_OVERRUN")) {
|
||||
throw error;
|
||||
}
|
||||
value = error;
|
||||
value.baseType = coder.name;
|
||||
value.name = coder.localName;
|
||||
value.type = coder.type;
|
||||
}
|
||||
}
|
||||
if (value == undefined) {
|
||||
throw new Error("investigate");
|
||||
}
|
||||
values.push(value);
|
||||
keys.push(coder.localName || null);
|
||||
});
|
||||
return abstract_coder_js_1.Result.fromItems(values, keys);
|
||||
}
|
||||
exports.unpack = unpack;
|
||||
class ArrayCoder extends abstract_coder_js_1.Coder {
|
||||
coder;
|
||||
length;
|
||||
constructor(coder, length, localName) {
|
||||
const type = (coder.type + "[" + (length >= 0 ? length : "") + "]");
|
||||
const dynamic = (length === -1 || coder.dynamic);
|
||||
super("array", type, localName, dynamic);
|
||||
(0, properties_js_1.defineProperties)(this, { coder, length });
|
||||
}
|
||||
defaultValue() {
|
||||
// Verifies the child coder is valid (even if the array is dynamic or 0-length)
|
||||
const defaultChild = this.coder.defaultValue();
|
||||
const result = [];
|
||||
for (let i = 0; i < this.length; i++) {
|
||||
result.push(defaultChild);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
encode(writer, _value) {
|
||||
const value = typed_js_1.Typed.dereference(_value, "array");
|
||||
if (!Array.isArray(value)) {
|
||||
this._throwError("expected array value", value);
|
||||
}
|
||||
let count = this.length;
|
||||
if (count === -1) {
|
||||
count = value.length;
|
||||
writer.writeValue(value.length);
|
||||
}
|
||||
logger_js_1.logger.assertArgumentCount(value.length, count, "coder array" + (this.localName ? (" " + this.localName) : ""));
|
||||
let coders = [];
|
||||
for (let i = 0; i < value.length; i++) {
|
||||
coders.push(this.coder);
|
||||
}
|
||||
return pack(writer, coders, value);
|
||||
}
|
||||
decode(reader) {
|
||||
let count = this.length;
|
||||
if (count === -1) {
|
||||
count = reader.readIndex();
|
||||
// Check that there is *roughly* enough data to ensure
|
||||
// stray random data is not being read as a length. Each
|
||||
// slot requires at least 32 bytes for their value (or 32
|
||||
// bytes as a link to the data). This could use a much
|
||||
// tighter bound, but we are erroring on the side of safety.
|
||||
if (count * abstract_coder_js_1.WordSize > reader.dataLength) {
|
||||
logger_js_1.logger.throwError("insufficient data length", "BUFFER_OVERRUN", {
|
||||
buffer: reader.bytes,
|
||||
offset: count * abstract_coder_js_1.WordSize,
|
||||
length: reader.dataLength
|
||||
});
|
||||
}
|
||||
}
|
||||
let coders = [];
|
||||
for (let i = 0; i < count; i++) {
|
||||
coders.push(new anonymous_js_1.AnonymousCoder(this.coder));
|
||||
}
|
||||
return unpack(reader, coders);
|
||||
}
|
||||
}
|
||||
exports.ArrayCoder = ArrayCoder;
|
||||
//# sourceMappingURL=array.js.map
|
1
lib.commonjs/abi/coders/array.js.map
Normal file
1
lib.commonjs/abi/coders/array.js.map
Normal file
File diff suppressed because one or more lines are too long
22
lib.commonjs/abi/coders/boolean.js
Normal file
22
lib.commonjs/abi/coders/boolean.js
Normal file
@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.BooleanCoder = void 0;
|
||||
const typed_js_1 = require("../typed.js");
|
||||
const abstract_coder_js_1 = require("./abstract-coder.js");
|
||||
class BooleanCoder extends abstract_coder_js_1.Coder {
|
||||
constructor(localName) {
|
||||
super("bool", "bool", localName, false);
|
||||
}
|
||||
defaultValue() {
|
||||
return false;
|
||||
}
|
||||
encode(writer, _value) {
|
||||
const value = typed_js_1.Typed.dereference(_value, "bool");
|
||||
return writer.writeValue(value ? 1 : 0);
|
||||
}
|
||||
decode(reader) {
|
||||
return !!reader.readValue();
|
||||
}
|
||||
}
|
||||
exports.BooleanCoder = BooleanCoder;
|
||||
//# sourceMappingURL=boolean.js.map
|
1
lib.commonjs/abi/coders/boolean.js.map
Normal file
1
lib.commonjs/abi/coders/boolean.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"boolean.js","sourceRoot":"","sources":["../../../src.ts/abi/coders/boolean.ts"],"names":[],"mappings":";;;AAAA,0CAAoC;AACpC,2DAA4C;AAK5C,MAAa,YAAa,SAAQ,yBAAK;IAEnC,YAAY,SAAiB;QACzB,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;IAC5C,CAAC;IAED,YAAY;QACR,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,MAAM,CAAC,MAAc,EAAE,MAAuB;QAC1C,MAAM,KAAK,GAAG,gBAAK,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAChD,OAAO,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3C,CAAC;IAED,MAAM,CAAC,MAAc;QACjB,OAAO,CAAC,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;IAChC,CAAC;CACJ;AAlBD,oCAkBC"}
|
34
lib.commonjs/abi/coders/bytes.js
Normal file
34
lib.commonjs/abi/coders/bytes.js
Normal file
@ -0,0 +1,34 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.BytesCoder = exports.DynamicBytesCoder = void 0;
|
||||
const logger_js_1 = require("../../utils/logger.js");
|
||||
const data_js_1 = require("../../utils/data.js");
|
||||
const abstract_coder_js_1 = require("./abstract-coder.js");
|
||||
class DynamicBytesCoder extends abstract_coder_js_1.Coder {
|
||||
constructor(type, localName) {
|
||||
super(type, type, localName, true);
|
||||
}
|
||||
defaultValue() {
|
||||
return "0x";
|
||||
}
|
||||
encode(writer, value) {
|
||||
value = logger_js_1.logger.getBytesCopy(value);
|
||||
let length = writer.writeValue(value.length);
|
||||
length += writer.writeBytes(value);
|
||||
return length;
|
||||
}
|
||||
decode(reader) {
|
||||
return reader.readBytes(reader.readIndex(), true);
|
||||
}
|
||||
}
|
||||
exports.DynamicBytesCoder = DynamicBytesCoder;
|
||||
class BytesCoder extends DynamicBytesCoder {
|
||||
constructor(localName) {
|
||||
super("bytes", localName);
|
||||
}
|
||||
decode(reader) {
|
||||
return (0, data_js_1.hexlify)(super.decode(reader));
|
||||
}
|
||||
}
|
||||
exports.BytesCoder = BytesCoder;
|
||||
//# sourceMappingURL=bytes.js.map
|
1
lib.commonjs/abi/coders/bytes.js.map
Normal file
1
lib.commonjs/abi/coders/bytes.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"bytes.js","sourceRoot":"","sources":["../../../src.ts/abi/coders/bytes.ts"],"names":[],"mappings":";;;AAAA,qDAA+C;AAC/C,iDAA8C;AAE9C,2DAA4C;AAK5C,MAAa,iBAAkB,SAAQ,yBAAK;IACxC,YAAY,IAAY,EAAE,SAAiB;QACxC,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;IACtC,CAAC;IAED,YAAY;QACR,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,MAAM,CAAC,MAAc,EAAE,KAAU;QAC7B,KAAK,GAAG,kBAAM,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QACnC,IAAI,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC7C,MAAM,IAAI,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QACnC,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,MAAM,CAAC,MAAc;QACjB,OAAO,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,IAAI,CAAC,CAAC;IACtD,CAAC;CACJ;AAnBD,8CAmBC;AAED,MAAa,UAAW,SAAQ,iBAAiB;IAC7C,YAAY,SAAiB;QACzB,KAAK,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IAC9B,CAAC;IAED,MAAM,CAAC,MAAc;QACjB,OAAO,IAAA,iBAAO,EAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;IACzC,CAAC;CACJ;AARD,gCAQC"}
|
31
lib.commonjs/abi/coders/fixed-bytes.js
Normal file
31
lib.commonjs/abi/coders/fixed-bytes.js
Normal file
@ -0,0 +1,31 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.FixedBytesCoder = void 0;
|
||||
const logger_js_1 = require("../../utils/logger.js");
|
||||
const data_js_1 = require("../../utils/data.js");
|
||||
const properties_js_1 = require("../../utils/properties.js");
|
||||
const typed_js_1 = require("../typed.js");
|
||||
const abstract_coder_js_1 = require("./abstract-coder.js");
|
||||
class FixedBytesCoder extends abstract_coder_js_1.Coder {
|
||||
size;
|
||||
constructor(size, localName) {
|
||||
let name = "bytes" + String(size);
|
||||
super(name, name, localName, false);
|
||||
(0, properties_js_1.defineProperties)(this, { size }, { size: "number" });
|
||||
}
|
||||
defaultValue() {
|
||||
return ("0x0000000000000000000000000000000000000000000000000000000000000000").substring(0, 2 + this.size * 2);
|
||||
}
|
||||
encode(writer, _value) {
|
||||
let data = logger_js_1.logger.getBytesCopy(typed_js_1.Typed.dereference(_value, this.type));
|
||||
if (data.length !== this.size) {
|
||||
this._throwError("incorrect data length", _value);
|
||||
}
|
||||
return writer.writeBytes(data);
|
||||
}
|
||||
decode(reader) {
|
||||
return (0, data_js_1.hexlify)(reader.readBytes(this.size));
|
||||
}
|
||||
}
|
||||
exports.FixedBytesCoder = FixedBytesCoder;
|
||||
//# sourceMappingURL=fixed-bytes.js.map
|
1
lib.commonjs/abi/coders/fixed-bytes.js.map
Normal file
1
lib.commonjs/abi/coders/fixed-bytes.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"fixed-bytes.js","sourceRoot":"","sources":["../../../src.ts/abi/coders/fixed-bytes.ts"],"names":[],"mappings":";;;AACA,qDAA+C;AAC/C,iDAA8C;AAC9C,6DAA6D;AAE7D,0CAAoC;AACpC,2DAA4C;AAO5C,MAAa,eAAgB,SAAQ,yBAAK;IAC7B,IAAI,CAAU;IAEvB,YAAY,IAAY,EAAE,SAAiB;QACvC,IAAI,IAAI,GAAG,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;QAClC,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;QACpC,IAAA,gCAAgB,EAAkB,IAAI,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;IAC1E,CAAC;IAED,YAAY;QACR,OAAO,CAAC,oEAAoE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC;IAClH,CAAC;IAED,MAAM,CAAC,MAAc,EAAE,MAAyB;QAC5C,IAAI,IAAI,GAAG,kBAAM,CAAC,YAAY,CAAC,gBAAK,CAAC,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACrE,IAAI,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC,IAAI,EAAE;YAAE,IAAI,CAAC,WAAW,CAAC,uBAAuB,EAAE,MAAM,CAAC,CAAC;SAAE;QACrF,OAAO,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IAED,MAAM,CAAC,MAAc;QACjB,OAAO,IAAA,iBAAO,EAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAChD,CAAC;CACJ;AAtBD,0CAsBC"}
|
25
lib.commonjs/abi/coders/null.js
Normal file
25
lib.commonjs/abi/coders/null.js
Normal file
@ -0,0 +1,25 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.NullCoder = void 0;
|
||||
const abstract_coder_js_1 = require("./abstract-coder.js");
|
||||
const Empty = new Uint8Array([]);
|
||||
class NullCoder extends abstract_coder_js_1.Coder {
|
||||
constructor(localName) {
|
||||
super("null", "", localName, false);
|
||||
}
|
||||
defaultValue() {
|
||||
return null;
|
||||
}
|
||||
encode(writer, value) {
|
||||
if (value != null) {
|
||||
this._throwError("not null", value);
|
||||
}
|
||||
return writer.writeBytes(Empty);
|
||||
}
|
||||
decode(reader) {
|
||||
reader.readBytes(0);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
exports.NullCoder = NullCoder;
|
||||
//# sourceMappingURL=null.js.map
|
1
lib.commonjs/abi/coders/null.js.map
Normal file
1
lib.commonjs/abi/coders/null.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"null.js","sourceRoot":"","sources":["../../../src.ts/abi/coders/null.ts"],"names":[],"mappings":";;;AAAA,2DAA4C;AAG5C,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,EAAG,CAAC,CAAC;AAElC,MAAa,SAAU,SAAQ,yBAAK;IAEhC,YAAY,SAAiB;QACzB,KAAK,CAAC,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;IACxC,CAAC;IAED,YAAY;QACR,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,MAAM,CAAC,MAAc,EAAE,KAAU;QAC7B,IAAI,KAAK,IAAI,IAAI,EAAE;YAAE,IAAI,CAAC,WAAW,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;SAAE;QAC3D,OAAO,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;IAED,MAAM,CAAC,MAAc;QACjB,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QACpB,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AAnBD,8BAmBC"}
|
51
lib.commonjs/abi/coders/number.js
Normal file
51
lib.commonjs/abi/coders/number.js
Normal file
@ -0,0 +1,51 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.NumberCoder = void 0;
|
||||
const maths_js_1 = require("../../utils/maths.js");
|
||||
const properties_js_1 = require("../../utils/properties.js");
|
||||
const logger_js_1 = require("../../utils/logger.js");
|
||||
const typed_js_1 = require("../typed.js");
|
||||
const abstract_coder_js_1 = require("./abstract-coder.js");
|
||||
const BN_0 = BigInt(0);
|
||||
const BN_1 = BigInt(1);
|
||||
const BN_MAX_UINT256 = BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
|
||||
class NumberCoder extends abstract_coder_js_1.Coder {
|
||||
size;
|
||||
signed;
|
||||
constructor(size, signed, localName) {
|
||||
const name = ((signed ? "int" : "uint") + (size * 8));
|
||||
super(name, name, localName, false);
|
||||
(0, properties_js_1.defineProperties)(this, { size, signed }, { size: "number", signed: "boolean" });
|
||||
}
|
||||
defaultValue() {
|
||||
return 0;
|
||||
}
|
||||
encode(writer, _value) {
|
||||
let value = logger_js_1.logger.getBigInt(typed_js_1.Typed.dereference(_value, this.type));
|
||||
// Check bounds are safe for encoding
|
||||
let maxUintValue = (0, maths_js_1.mask)(BN_MAX_UINT256, abstract_coder_js_1.WordSize * 8);
|
||||
if (this.signed) {
|
||||
let bounds = (0, maths_js_1.mask)(maxUintValue, (this.size * 8) - 1);
|
||||
if (value > bounds || value < -(bounds + BN_1)) {
|
||||
this._throwError("value out-of-bounds", _value);
|
||||
}
|
||||
}
|
||||
else if (value < BN_0 || value > (0, maths_js_1.mask)(maxUintValue, this.size * 8)) {
|
||||
this._throwError("value out-of-bounds", _value);
|
||||
}
|
||||
value = (0, maths_js_1.mask)((0, maths_js_1.toTwos)(value, this.size * 8), this.size * 8);
|
||||
if (this.signed) {
|
||||
value = (0, maths_js_1.toTwos)((0, maths_js_1.fromTwos)(value, this.size * 8), 8 * abstract_coder_js_1.WordSize);
|
||||
}
|
||||
return writer.writeValue(value);
|
||||
}
|
||||
decode(reader) {
|
||||
let value = (0, maths_js_1.mask)(reader.readValue(), this.size * 8);
|
||||
if (this.signed) {
|
||||
value = (0, maths_js_1.fromTwos)(value, this.size * 8);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
exports.NumberCoder = NumberCoder;
|
||||
//# sourceMappingURL=number.js.map
|
1
lib.commonjs/abi/coders/number.js.map
Normal file
1
lib.commonjs/abi/coders/number.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"number.js","sourceRoot":"","sources":["../../../src.ts/abi/coders/number.ts"],"names":[],"mappings":";;;AAAA,mDAA8D;AAC9D,6DAA6D;AAE7D,qDAA+C;AAC/C,0CAAoC;AACpC,2DAAsD;AAOtD,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;AACvB,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;AACvB,MAAM,cAAc,GAAG,MAAM,CAAC,oEAAoE,CAAC,CAAC;AAEpG,MAAa,WAAY,SAAQ,yBAAK;IACzB,IAAI,CAAU;IACd,MAAM,CAAW;IAE1B,YAAY,IAAY,EAAE,MAAe,EAAE,SAAiB;QACxD,MAAM,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAA,CAAC,C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AAI,GAAG,CAAC,CAAC,CAAC;QAE1D,IAAI,IAAI,CAAC,MAAM,EAAE;YACb,KAAK,GAAG,IAAA,iBAAM,EAAC,IAAA,mBAAQ,EAAC,KAAK,EAAE,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,4BAAQ,CAAC,CAAC;SAChE;QAED,OAAO,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;IAED,MAAM,CAAC,MAAc;QACjB,IAAI,KAAK,GAAG,IAAA,eAAI,EAAC,MAAM,CAAC,SAAS,EAAE,EAAE,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC;QAEpD,IAAI,IAAI,CAAC,MAAM,EAAE;YACb,KAAK,GAAG,IAAA,mBAAQ,EAAC,KAAK,EAAE,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC;SAC1C;QAED,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ;AA/CD,kCA+CC"}
|
22
lib.commonjs/abi/coders/string.js
Normal file
22
lib.commonjs/abi/coders/string.js
Normal file
@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.StringCoder = void 0;
|
||||
const utf8_js_1 = require("../../utils/utf8.js");
|
||||
const typed_js_1 = require("../typed.js");
|
||||
const bytes_js_1 = require("./bytes.js");
|
||||
class StringCoder extends bytes_js_1.DynamicBytesCoder {
|
||||
constructor(localName) {
|
||||
super("string", localName);
|
||||
}
|
||||
defaultValue() {
|
||||
return "";
|
||||
}
|
||||
encode(writer, _value) {
|
||||
return super.encode(writer, (0, utf8_js_1.toUtf8Bytes)(typed_js_1.Typed.dereference(_value, "string")));
|
||||
}
|
||||
decode(reader) {
|
||||
return (0, utf8_js_1.toUtf8String)(super.decode(reader));
|
||||
}
|
||||
}
|
||||
exports.StringCoder = StringCoder;
|
||||
//# sourceMappingURL=string.js.map
|
1
lib.commonjs/abi/coders/string.js.map
Normal file
1
lib.commonjs/abi/coders/string.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"string.js","sourceRoot":"","sources":["../../../src.ts/abi/coders/string.ts"],"names":[],"mappings":";;;AAAA,iDAAgE;AAEhE,0CAAoC;AACpC,yCAA+C;AAK/C,MAAa,WAAY,SAAQ,4BAAiB;IAE9C,YAAY,SAAiB;QACzB,KAAK,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IAC/B,CAAC;IAED,YAAY;QACR,OAAO,EAAE,CAAC;IACd,CAAC;IAED,MAAM,CAAC,MAAc,EAAE,MAAsB;QACzC,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,IAAA,qBAAW,EAAC,gBAAK,CAAC,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IAClF,CAAC;IAED,MAAM,CAAC,MAAc;QACjB,OAAO,IAAA,sBAAY,EAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9C,CAAC;CACJ;AAjBD,kCAiBC"}
|
64
lib.commonjs/abi/coders/tuple.js
Normal file
64
lib.commonjs/abi/coders/tuple.js
Normal file
@ -0,0 +1,64 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.TupleCoder = void 0;
|
||||
const properties_js_1 = require("../../utils/properties.js");
|
||||
const typed_js_1 = require("../typed.js");
|
||||
const abstract_coder_js_1 = require("./abstract-coder.js");
|
||||
const array_js_1 = require("./array.js");
|
||||
class TupleCoder extends abstract_coder_js_1.Coder {
|
||||
coders;
|
||||
constructor(coders, localName) {
|
||||
let dynamic = false;
|
||||
const types = [];
|
||||
coders.forEach((coder) => {
|
||||
if (coder.dynamic) {
|
||||
dynamic = true;
|
||||
}
|
||||
types.push(coder.type);
|
||||
});
|
||||
const type = ("tuple(" + types.join(",") + ")");
|
||||
super("tuple", type, localName, dynamic);
|
||||
(0, properties_js_1.defineProperties)(this, { coders: Object.freeze(coders.slice()) });
|
||||
}
|
||||
defaultValue() {
|
||||
const values = [];
|
||||
this.coders.forEach((coder) => {
|
||||
values.push(coder.defaultValue());
|
||||
});
|
||||
// We only output named properties for uniquely named coders
|
||||
const uniqueNames = this.coders.reduce((accum, coder) => {
|
||||
const name = coder.localName;
|
||||
if (name) {
|
||||
if (!accum[name]) {
|
||||
accum[name] = 0;
|
||||
}
|
||||
accum[name]++;
|
||||
}
|
||||
return accum;
|
||||
}, {});
|
||||
// Add named values
|
||||
this.coders.forEach((coder, index) => {
|
||||
let name = coder.localName;
|
||||
if (!name || uniqueNames[name] !== 1) {
|
||||
return;
|
||||
}
|
||||
if (name === "length") {
|
||||
name = "_length";
|
||||
}
|
||||
if (values[name] != null) {
|
||||
return;
|
||||
}
|
||||
values[name] = values[index];
|
||||
});
|
||||
return Object.freeze(values);
|
||||
}
|
||||
encode(writer, _value) {
|
||||
const value = typed_js_1.Typed.dereference(_value, "tuple");
|
||||
return (0, array_js_1.pack)(writer, this.coders, value);
|
||||
}
|
||||
decode(reader) {
|
||||
return (0, array_js_1.unpack)(reader, this.coders);
|
||||
}
|
||||
}
|
||||
exports.TupleCoder = TupleCoder;
|
||||
//# sourceMappingURL=tuple.js.map
|
1
lib.commonjs/abi/coders/tuple.js.map
Normal file
1
lib.commonjs/abi/coders/tuple.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"tuple.js","sourceRoot":"","sources":["../../../src.ts/abi/coders/tuple.ts"],"names":[],"mappings":";;;AAAA,6DAA6D;AAE7D,0CAAoC;AACpC,2DAA4C;AAE5C,yCAA0C;AAI1C,MAAa,UAAW,SAAQ,yBAAK;IACxB,MAAM,CAAwB;IAEvC,YAAY,MAAoB,EAAE,SAAiB;QAC/C,IAAI,OAAO,GAAG,KAAK,CAAC;QACpB,MAAM,KAAK,GAAkB,EAAE,CAAC;QAChC,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;YACrB,IAAI,KAAK,CAAC,OAAO,EAAE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AI,CAAC,KAAK,CAAC,EAAE;gBAAE,OAAO;aAAE;YAEjD,IAAI,IAAI,KAAK,QAAQ,EAAE;gBAAE,IAAI,GAAG,SAAS,CAAC;aAAE;YAE5C,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,IAAI,EAAE;gBAAE,OAAO;aAAE;YAErC,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QACjC,CAAC,CAAC,CAAC;QAEH,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACjC,CAAC;IAED,MAAM,CAAC,MAAc,EAAE,MAAsD;QACzE,MAAM,KAAK,GAAG,gBAAK,CAAC,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACjD,OAAO,IAAA,eAAI,EAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC5C,CAAC;IAED,MAAM,CAAC,MAAc;QACjB,OAAO,IAAA,iBAAM,EAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IACvC,CAAC;CACJ;AAvDD,gCAuDC"}
|
933
lib.commonjs/abi/fragments.js
Normal file
933
lib.commonjs/abi/fragments.js
Normal file
@ -0,0 +1,933 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.StructFragment = exports.FunctionFragment = exports.ConstructorFragment = exports.EventFragment = exports.ErrorFragment = exports.NamedFragment = exports.Fragment = exports.FragmentType = exports.ParamType = exports.lex = exports.TokenString = exports.FormatType = void 0;
|
||||
const logger_js_1 = require("../utils/logger.js");
|
||||
const index_js_1 = require("../utils/index.js");
|
||||
;
|
||||
var FormatType;
|
||||
(function (FormatType) {
|
||||
// Bare formatting, as is needed for computing a sighash of an event or function
|
||||
FormatType["sighash"] = "sighash";
|
||||
// Human-Readable with Minimal spacing and without names (compact human-readable)
|
||||
FormatType["minimal"] = "minimal";
|
||||
// Human-Readable with nice spacing, including all names
|
||||
FormatType["full"] = "full";
|
||||
// JSON-format a la Solidity
|
||||
FormatType["json"] = "json";
|
||||
})(FormatType = exports.FormatType || (exports.FormatType = {}));
|
||||
;
|
||||
// [ "a", "b" ] => { "a": 1, "b": 1 }
|
||||
function setify(items) {
|
||||
const result = new Set();
|
||||
items.forEach((k) => result.add(k));
|
||||
return Object.freeze(result);
|
||||
}
|
||||
// Visibility Keywords
|
||||
const _kwVisib = "constant external internal payable private public pure view";
|
||||
const KwVisib = setify(_kwVisib.split(" "));
|
||||
const _kwTypes = "constructor error event function struct";
|
||||
const KwTypes = setify(_kwTypes.split(" "));
|
||||
const _kwModifiers = "calldata memory storage payable indexed";
|
||||
const KwModifiers = setify(_kwModifiers.split(" "));
|
||||
const _kwOther = "tuple returns";
|
||||
// All Keywords
|
||||
const _keywords = [_kwTypes, _kwModifiers, _kwOther, _kwVisib].join(" ");
|
||||
const Keywords = setify(_keywords.split(" "));
|
||||
// Single character tokens
|
||||
const SimpleTokens = {
|
||||
"(": "OPEN_PAREN", ")": "CLOSE_PAREN",
|
||||
"[": "OPEN_BRACKET", "]": "CLOSE_BRACKET",
|
||||
",": "COMMA", "@": "AT"
|
||||
};
|
||||
// Parser regexes to consume the next token
|
||||
const regexWhitespace = new RegExp("^(\\s*)");
|
||||
const regexNumber = new RegExp("^([0-9]+)");
|
||||
const regexIdentifier = new RegExp("^([a-zA-Z$_][a-zA-Z0-9$_]*)");
|
||||
const regexType = new RegExp("^(address|bool|bytes([0-9]*)|string|u?int([0-9]*))");
|
||||
class TokenString {
|
||||
#offset;
|
||||
#tokens;
|
||||
get offset() { return this.#offset; }
|
||||
get length() { return this.#tokens.length - this.#offset; }
|
||||
constructor(tokens) {
|
||||
this.#offset = 0;
|
||||
this.#tokens = tokens.slice();
|
||||
}
|
||||
clone() { return new TokenString(this.#tokens); }
|
||||
reset() { this.#offset = 0; }
|
||||
#subTokenString(from = 0, to = 0) {
|
||||
return new TokenString(this.#tokens.slice(from, to).map((t) => {
|
||||
return Object.freeze(Object.assign({}, t, {
|
||||
match: (t.match - from),
|
||||
linkBack: (t.linkBack - from),
|
||||
linkNext: (t.linkNext - from),
|
||||
}));
|
||||
return t;
|
||||
}));
|
||||
}
|
||||
// Pops and returns the value of the next token, if it is a keyword in allowed; throws if out of tokens
|
||||
popKeyword(allowed) {
|
||||
const top = this.peek();
|
||||
if (top.type !== "KEYWORD" || !allowed.has(top.text)) {
|
||||
throw new Error(`expected keyword ${top.text}`);
|
||||
}
|
||||
return this.pop().text;
|
||||
}
|
||||
// Pops and returns the value of the next token if it is `type`; throws if out of tokens
|
||||
popType(type) {
|
||||
if (this.peek().type !== type) {
|
||||
throw new Error(`expected ${type}; got ${JSON.stringify(this.peek())}`);
|
||||
}
|
||||
return this.pop().text;
|
||||
}
|
||||
// Pops and returns a "(" TOKENS ")"
|
||||
popParen() {
|
||||
const top = this.peek();
|
||||
if (top.type !== "OPEN_PAREN") {
|
||||
throw new Error("bad start");
|
||||
}
|
||||
const result = this.#subTokenString(this.#offset + 1, top.match + 1);
|
||||
this.#offset = top.match + 1;
|
||||
return result;
|
||||
}
|
||||
// Pops and returns the items within "(" ITEM1 "," ITEM2 "," ... ")"
|
||||
popParams() {
|
||||
const top = this.peek();
|
||||
if (top.type !== "OPEN_PAREN") {
|
||||
throw new Error("bad start");
|
||||
}
|
||||
const result = [];
|
||||
while (this.#offset < top.match - 1) {
|
||||
const link = this.peek().linkNext;
|
||||
result.push(this.#subTokenString(this.#offset + 1, link));
|
||||
this.#offset = link;
|
||||
}
|
||||
this.#offset = top.match + 1;
|
||||
return result;
|
||||
}
|
||||
// Returns the top Token, throwing if out of tokens
|
||||
peek() {
|
||||
if (this.#offset >= this.#tokens.length) {
|
||||
throw new Error("out-of-bounds");
|
||||
}
|
||||
return this.#tokens[this.#offset];
|
||||
}
|
||||
// Returns the next value, if it is a keyword in `allowed`
|
||||
peekKeyword(allowed) {
|
||||
const top = this.peekType("KEYWORD");
|
||||
return (top != null && allowed.has(top)) ? top : null;
|
||||
}
|
||||
// Returns the value of the next token if it is `type`
|
||||
peekType(type) {
|
||||
if (this.length === 0) {
|
||||
return null;
|
||||
}
|
||||
const top = this.peek();
|
||||
return (top.type === type) ? top.text : null;
|
||||
}
|
||||
// Returns the next token; throws if out of tokens
|
||||
pop() {
|
||||
const result = this.peek();
|
||||
this.#offset++;
|
||||
return result;
|
||||
}
|
||||
toString() {
|
||||
const tokens = [];
|
||||
for (let i = this.#offset; i < this.#tokens.length; i++) {
|
||||
const token = this.#tokens[i];
|
||||
tokens.push(`${token.type}:${token.text}`);
|
||||
}
|
||||
return `<TokenString ${tokens.join(" ")}>`;
|
||||
}
|
||||
}
|
||||
exports.TokenString = TokenString;
|
||||
function lex(text) {
|
||||
const tokens = [];
|
||||
const throwError = (message) => {
|
||||
const token = (offset < text.length) ? JSON.stringify(text[offset]) : "$EOI";
|
||||
throw new Error(`invalid token ${token} at ${offset}: ${message}`);
|
||||
};
|
||||
let brackets = [];
|
||||
let commas = [];
|
||||
let offset = 0;
|
||||
while (offset < text.length) {
|
||||
// Strip off any leading whitespace
|
||||
let cur = text.substring(offset);
|
||||
let match = cur.match(regexWhitespace);
|
||||
if (match) {
|
||||
offset += match[1].length;
|
||||
cur = text.substring(offset);
|
||||
}
|
||||
const token = { depth: brackets.length, linkBack: -1, linkNext: -1, match: -1, type: "", text: "", offset, value: -1 };
|
||||
tokens.push(token);
|
||||
let type = (SimpleTokens[cur[0]] || "");
|
||||
if (type) {
|
||||
token.type = type;
|
||||
token.text = cur[0];
|
||||
offset++;
|
||||
if (type === "OPEN_PAREN") {
|
||||
brackets.push(tokens.length - 1);
|
||||
commas.push(tokens.length - 1);
|
||||
}
|
||||
else if (type == "CLOSE_PAREN") {
|
||||
if (brackets.length === 0) {
|
||||
throwError("no matching open bracket");
|
||||
}
|
||||
token.match = brackets.pop();
|
||||
(tokens[token.match]).match = tokens.length - 1;
|
||||
token.depth--;
|
||||
token.linkBack = commas.pop();
|
||||
(tokens[token.linkBack]).linkNext = tokens.length - 1;
|
||||
}
|
||||
else if (type === "COMMA") {
|
||||
token.linkBack = commas.pop();
|
||||
(tokens[token.linkBack]).linkNext = tokens.length - 1;
|
||||
commas.push(tokens.length - 1);
|
||||
}
|
||||
else if (type === "OPEN_BRACKET") {
|
||||
token.type = "BRACKET";
|
||||
}
|
||||
else if (type === "CLOSE_BRACKET") {
|
||||
// Remove the CLOSE_BRACKET
|
||||
let suffix = tokens.pop().text;
|
||||
if (tokens.length > 0 && tokens[tokens.length - 1].type === "NUMBER") {
|
||||
const value = tokens.pop().text;
|
||||
suffix = value + suffix;
|
||||
(tokens[tokens.length - 1]).value = logger_js_1.logger.getNumber(value);
|
||||
}
|
||||
if (tokens.length === 0 || tokens[tokens.length - 1].type !== "BRACKET") {
|
||||
throw new Error("missing opening bracket");
|
||||
}
|
||||
(tokens[tokens.length - 1]).text += suffix;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
match = cur.match(regexIdentifier);
|
||||
if (match) {
|
||||
token.text = match[1];
|
||||
offset += token.text.length;
|
||||
if (Keywords.has(token.text)) {
|
||||
token.type = "KEYWORD";
|
||||
continue;
|
||||
}
|
||||
if (token.text.match(regexType)) {
|
||||
token.type = "TYPE";
|
||||
continue;
|
||||
}
|
||||
token.type = "ID";
|
||||
continue;
|
||||
}
|
||||
match = cur.match(regexNumber);
|
||||
if (match) {
|
||||
token.text = match[1];
|
||||
token.type = "NUMBER";
|
||||
offset += token.text.length;
|
||||
continue;
|
||||
}
|
||||
throw new Error(`unexpected token ${JSON.stringify(cur[0])} at position ${offset}`);
|
||||
}
|
||||
return new TokenString(tokens.map((t) => Object.freeze(t)));
|
||||
}
|
||||
exports.lex = lex;
|
||||
// Check only one of `allowed` is in `set`
|
||||
function allowSingle(set, allowed) {
|
||||
let included = [];
|
||||
for (const key in allowed.keys()) {
|
||||
if (set.has(key)) {
|
||||
included.push(key);
|
||||
}
|
||||
}
|
||||
if (included.length > 1) {
|
||||
throw new Error(`conflicting types: ${included.join(", ")}`);
|
||||
}
|
||||
}
|
||||
// Functions to process a Solidity Signature TokenString from left-to-right for...
|
||||
// ...the name with an optional type, returning the name
|
||||
function consumeName(type, tokens) {
|
||||
if (tokens.peekKeyword(KwTypes)) {
|
||||
const keyword = tokens.pop().text;
|
||||
if (keyword !== type) {
|
||||
throw new Error(`expected ${type}, got ${keyword}`);
|
||||
}
|
||||
}
|
||||
return tokens.popType("ID");
|
||||
}
|
||||
// ...all keywords matching allowed, returning the keywords
|
||||
function consumeKeywords(tokens, allowed) {
|
||||
const keywords = new Set();
|
||||
while (true) {
|
||||
const keyword = tokens.peekType("KEYWORD");
|
||||
if (keyword == null || (allowed && !allowed.has(keyword))) {
|
||||
break;
|
||||
}
|
||||
tokens.pop();
|
||||
if (keywords.has(keyword)) {
|
||||
throw new Error(`duplicate keywords: ${JSON.stringify(keyword)}`);
|
||||
}
|
||||
keywords.add(keyword);
|
||||
}
|
||||
return Object.freeze(keywords);
|
||||
}
|
||||
// ...all visibility keywords, returning the coalesced mutability
|
||||
function consumeMutability(tokens) {
|
||||
let modifiers = consumeKeywords(tokens, KwVisib);
|
||||
// Detect conflicting modifiers
|
||||
allowSingle(modifiers, setify("constant payable nonpayable".split(" ")));
|
||||
allowSingle(modifiers, setify("pure view payable nonpayable".split(" ")));
|
||||
// Process mutability states
|
||||
if (modifiers.has("view")) {
|
||||
return "view";
|
||||
}
|
||||
if (modifiers.has("pure")) {
|
||||
return "pure";
|
||||
}
|
||||
if (modifiers.has("payable")) {
|
||||
return "payable";
|
||||
}
|
||||
if (modifiers.has("nonpayable")) {
|
||||
return "nonpayable";
|
||||
}
|
||||
// Process legacy `constant` last
|
||||
if (modifiers.has("constant")) {
|
||||
return "view";
|
||||
}
|
||||
return "nonpayable";
|
||||
}
|
||||
// ...a parameter list, returning the ParamType list
|
||||
function consumeParams(tokens, allowIndexed) {
|
||||
return tokens.popParams().map((t) => ParamType.fromTokens(t, allowIndexed));
|
||||
}
|
||||
// ...a gas limit, returning a BigNumber or null if none
|
||||
function consumeGas(tokens) {
|
||||
if (tokens.peekType("AT")) {
|
||||
tokens.pop();
|
||||
if (tokens.peekType("NUMBER")) {
|
||||
return logger_js_1.logger.getBigInt(tokens.pop().text);
|
||||
}
|
||||
throw new Error("invalid gas");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function consumeEoi(tokens) {
|
||||
if (tokens.length) {
|
||||
throw new Error(`unexpected tokens: ${tokens.toString()}`);
|
||||
}
|
||||
}
|
||||
const regexArrayType = new RegExp(/^(.*)\[([0-9]*)\]$/);
|
||||
function verifyBasicType(type) {
|
||||
const match = type.match(regexType);
|
||||
if (!match) {
|
||||
return logger_js_1.logger.throwArgumentError("invalid type", "type", type);
|
||||
}
|
||||
if (type === "uint") {
|
||||
return "uint256";
|
||||
}
|
||||
if (type === "int") {
|
||||
return "int256";
|
||||
}
|
||||
if (match[2]) {
|
||||
// bytesXX
|
||||
const length = parseInt(match[2]);
|
||||
if (length === 0 || length > 32) {
|
||||
logger_js_1.logger.throwArgumentError("invalid bytes length", "type", type);
|
||||
}
|
||||
}
|
||||
else if (match[3]) {
|
||||
// intXX or uintXX
|
||||
const size = parseInt(match[3]);
|
||||
if (size === 0 || size > 256 || size % 8) {
|
||||
logger_js_1.logger.throwArgumentError("invalid numeric width", "type", type);
|
||||
}
|
||||
}
|
||||
return type;
|
||||
}
|
||||
// Make the Fragment constructors effectively private
|
||||
const _guard = {};
|
||||
const internal = Symbol.for("_ethers_internal");
|
||||
const ParamTypeInternal = "_ParamTypeInternal";
|
||||
class ParamType {
|
||||
// The local name of the parameter (of "" if unbound)
|
||||
name;
|
||||
// The fully qualified type (e.g. "address", "tuple(address)", "uint256[3][]"
|
||||
type;
|
||||
// The base type (e.g. "address", "tuple", "array")
|
||||
baseType;
|
||||
// Indexable Paramters ONLY (otherwise null)
|
||||
indexed;
|
||||
// Tuples ONLY: (otherwise null)
|
||||
// - sub-components
|
||||
components;
|
||||
// Arrays ONLY: (otherwise null)
|
||||
// - length of the array (-1 for dynamic length)
|
||||
// - child type
|
||||
arrayLength;
|
||||
arrayChildren;
|
||||
constructor(guard, name, type, baseType, indexed, components, arrayLength, arrayChildren) {
|
||||
logger_js_1.logger.assertPrivate(guard, _guard, "ParamType");
|
||||
Object.defineProperty(this, internal, { value: ParamTypeInternal });
|
||||
if (components) {
|
||||
components = Object.freeze(components.slice());
|
||||
}
|
||||
if (baseType === "array") {
|
||||
if (arrayLength == null || arrayChildren == null) {
|
||||
throw new Error("");
|
||||
}
|
||||
}
|
||||
else if (arrayLength != null || arrayChildren != null) {
|
||||
throw new Error("");
|
||||
}
|
||||
if (baseType === "tuple") {
|
||||
if (components == null) {
|
||||
throw new Error("");
|
||||
}
|
||||
}
|
||||
else if (components != null) {
|
||||
throw new Error("");
|
||||
}
|
||||
(0, index_js_1.defineProperties)(this, {
|
||||
name, type, baseType, indexed, components, arrayLength, arrayChildren
|
||||
});
|
||||
}
|
||||
// Format the parameter fragment
|
||||
// - sighash: "(uint256,address)"
|
||||
// - minimal: "tuple(uint256,address) indexed"
|
||||
// - full: "tuple(uint256 foo, address bar) indexed baz"
|
||||
format(format = FormatType.sighash) {
|
||||
if (!FormatType[format]) {
|
||||
logger_js_1.logger.throwArgumentError("invalid format type", "format", format);
|
||||
}
|
||||
if (format === FormatType.json) {
|
||||
let result = {
|
||||
type: ((this.baseType === "tuple") ? "tuple" : this.type),
|
||||
name: (this.name || undefined)
|
||||
};
|
||||
if (typeof (this.indexed) === "boolean") {
|
||||
result.indexed = this.indexed;
|
||||
}
|
||||
if (this.isTuple()) {
|
||||
result.components = this.components.map((c) => JSON.parse(c.format(format)));
|
||||
}
|
||||
return JSON.stringify(result);
|
||||
}
|
||||
let result = "";
|
||||
// Array
|
||||
if (this.isArray()) {
|
||||
result += this.arrayChildren.format(format);
|
||||
result += `[${(this.arrayLength < 0 ? "" : String(this.arrayLength))}]`;
|
||||
}
|
||||
else {
|
||||
if (this.isTuple()) {
|
||||
if (format !== FormatType.sighash) {
|
||||
result += this.type;
|
||||
}
|
||||
result += "(" + this.components.map((comp) => comp.format(format)).join((format === FormatType.full) ? ", " : ",") + ")";
|
||||
}
|
||||
else {
|
||||
result += this.type;
|
||||
}
|
||||
}
|
||||
if (format !== FormatType.sighash) {
|
||||
if (this.indexed === true) {
|
||||
result += " indexed";
|
||||
}
|
||||
if (format === FormatType.full && this.name) {
|
||||
result += " " + this.name;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
static isArray(value) {
|
||||
return value && (value.baseType === "array");
|
||||
}
|
||||
isArray() {
|
||||
return (this.baseType === "array");
|
||||
}
|
||||
isTuple() {
|
||||
return (this.baseType === "tuple");
|
||||
}
|
||||
isIndexable() {
|
||||
return (this.indexed != null);
|
||||
}
|
||||
walk(value, process) {
|
||||
if (this.isArray()) {
|
||||
if (!Array.isArray(value)) {
|
||||
throw new Error("invlaid array value");
|
||||
}
|
||||
if (this.arrayLength !== -1 && value.length !== this.arrayLength) {
|
||||
throw new Error("array is wrong length");
|
||||
}
|
||||
return value.map((v) => (this.arrayChildren.walk(v, process)));
|
||||
}
|
||||
if (this.isTuple()) {
|
||||
if (!Array.isArray(value)) {
|
||||
throw new Error("invlaid tuple value");
|
||||
}
|
||||
if (value.length !== this.components.length) {
|
||||
throw new Error("array is wrong length");
|
||||
}
|
||||
return value.map((v, i) => (this.components[i].walk(v, process)));
|
||||
}
|
||||
return process(this.type, value);
|
||||
}
|
||||
#walkAsync(promises, value, process, setValue) {
|
||||
if (this.isArray()) {
|
||||
if (!Array.isArray(value)) {
|
||||
throw new Error("invlaid array value");
|
||||
}
|
||||
if (this.arrayLength !== -1 && value.length !== this.arrayLength) {
|
||||
throw new Error("array is wrong length");
|
||||
}
|
||||
const childType = this.arrayChildren;
|
||||
const result = value.slice();
|
||||
result.forEach((value, index) => {
|
||||
childType.#walkAsync(promises, value, process, (value) => {
|
||||
result[index] = value;
|
||||
});
|
||||
});
|
||||
setValue(result);
|
||||
return;
|
||||
}
|
||||
if (this.isTuple()) {
|
||||
const components = this.components;
|
||||
// Convert the object into an array
|
||||
let result;
|
||||
if (Array.isArray(value)) {
|
||||
result = value.slice();
|
||||
}
|
||||
else {
|
||||
if (value == null || typeof (value) !== "object") {
|
||||
throw new Error("invlaid tuple value");
|
||||
}
|
||||
result = components.map((param) => {
|
||||
if (!param.name) {
|
||||
throw new Error("cannot use object value with unnamed components");
|
||||
}
|
||||
if (!(param.name in value)) {
|
||||
throw new Error(`missing value for component ${param.name}`);
|
||||
}
|
||||
return value[param.name];
|
||||
});
|
||||
}
|
||||
if (value.length !== this.components.length) {
|
||||
throw new Error("array is wrong length");
|
||||
}
|
||||
result.forEach((value, index) => {
|
||||
components[index].#walkAsync(promises, value, process, (value) => {
|
||||
result[index] = value;
|
||||
});
|
||||
});
|
||||
setValue(result);
|
||||
return;
|
||||
}
|
||||
const result = process(this.type, value);
|
||||
if (result.then) {
|
||||
promises.push((async function () { setValue(await result); })());
|
||||
}
|
||||
else {
|
||||
setValue(result);
|
||||
}
|
||||
}
|
||||
async walkAsync(value, process) {
|
||||
const promises = [];
|
||||
const result = [value];
|
||||
this.#walkAsync(promises, value, process, (value) => {
|
||||
result[0] = value;
|
||||
});
|
||||
if (promises.length) {
|
||||
await Promise.all(promises);
|
||||
}
|
||||
return result[0];
|
||||
}
|
||||
static from(obj, allowIndexed) {
|
||||
if (ParamType.isParamType(obj)) {
|
||||
return obj;
|
||||
}
|
||||
if (typeof (obj) === "string") {
|
||||
return ParamType.fromTokens(lex(obj), allowIndexed);
|
||||
}
|
||||
if (obj instanceof TokenString) {
|
||||
return ParamType.fromTokens(obj, allowIndexed);
|
||||
}
|
||||
const name = obj.name;
|
||||
if (name && (typeof (name) !== "string" || !name.match(regexIdentifier))) {
|
||||
logger_js_1.logger.throwArgumentError("invalid name", "obj.name", name);
|
||||
}
|
||||
let indexed = obj.indexed;
|
||||
if (indexed != null) {
|
||||
if (!allowIndexed) {
|
||||
logger_js_1.logger.throwArgumentError("parameter cannot be indexed", "obj.indexed", obj.indexed);
|
||||
}
|
||||
indexed = !!indexed;
|
||||
}
|
||||
let type = obj.type;
|
||||
let arrayMatch = type.match(regexArrayType);
|
||||
if (arrayMatch) {
|
||||
const arrayLength = arrayMatch[2];
|
||||
const arrayChildren = ParamType.from({
|
||||
type: arrayMatch[1],
|
||||
components: obj.components
|
||||
});
|
||||
return new ParamType(_guard, name, type, "array", indexed, null, arrayLength, arrayChildren);
|
||||
}
|
||||
if (type.substring(0, 5) === "tuple(" || type[0] === "(") {
|
||||
const comps = (obj.components != null) ? obj.components.map((c) => ParamType.from(c)) : null;
|
||||
const tuple = new ParamType(_guard, name, type, "tuple", indexed, comps, null, null);
|
||||
// @TODO: use lexer to validate and normalize type
|
||||
return tuple;
|
||||
}
|
||||
type = verifyBasicType(obj.type);
|
||||
return new ParamType(_guard, name, type, type, indexed, null, null, null);
|
||||
}
|
||||
static fromObject(obj, allowIndexed) {
|
||||
throw new Error("@TODO");
|
||||
}
|
||||
static fromTokens(tokens, allowIndexed) {
|
||||
let type = "", baseType = "";
|
||||
let comps = null;
|
||||
if (consumeKeywords(tokens, setify(["tuple"])).has("tuple") || tokens.peekType("OPEN_PAREN")) {
|
||||
// Tuple
|
||||
baseType = "tuple";
|
||||
comps = tokens.popParams().map((t) => ParamType.from(t));
|
||||
type = `tuple(${comps.map((c) => c.format()).join(",")})`;
|
||||
}
|
||||
else {
|
||||
// Normal
|
||||
type = verifyBasicType(tokens.popType("TYPE"));
|
||||
baseType = type;
|
||||
}
|
||||
// Check for Array
|
||||
let arrayChildren = null;
|
||||
let arrayLength = null;
|
||||
while (tokens.length && tokens.peekType("BRACKET")) {
|
||||
const bracket = tokens.pop(); //arrays[i];
|
||||
arrayChildren = new ParamType(_guard, "", type, baseType, null, comps, arrayLength, arrayChildren);
|
||||
arrayLength = bracket.value;
|
||||
type += bracket.text;
|
||||
baseType = "array";
|
||||
comps = null;
|
||||
}
|
||||
let indexed = null;
|
||||
const keywords = consumeKeywords(tokens, KwModifiers);
|
||||
if (keywords.has("indexed")) {
|
||||
if (!allowIndexed) {
|
||||
throw new Error("");
|
||||
}
|
||||
indexed = true;
|
||||
}
|
||||
const name = (tokens.peekType("ID") ? tokens.pop().text : "");
|
||||
if (tokens.length) {
|
||||
throw new Error("leftover tokens");
|
||||
}
|
||||
return new ParamType(_guard, name, type, baseType, indexed, comps, arrayLength, arrayChildren);
|
||||
}
|
||||
static isParamType(value) {
|
||||
return (value && value[internal] === ParamTypeInternal);
|
||||
}
|
||||
}
|
||||
exports.ParamType = ParamType;
|
||||
var FragmentType;
|
||||
(function (FragmentType) {
|
||||
FragmentType["constructor"] = "constructor";
|
||||
FragmentType["error"] = "error";
|
||||
FragmentType["event"] = "event";
|
||||
FragmentType["function"] = "function";
|
||||
FragmentType["struct"] = "struct";
|
||||
})(FragmentType = exports.FragmentType || (exports.FragmentType = {}));
|
||||
;
|
||||
class Fragment {
|
||||
type;
|
||||
inputs;
|
||||
constructor(guard, type, inputs) {
|
||||
logger_js_1.logger.assertPrivate(guard, _guard, "Fragment");
|
||||
inputs = Object.freeze(inputs.slice());
|
||||
(0, index_js_1.defineProperties)(this, { type, inputs });
|
||||
}
|
||||
static from(obj) {
|
||||
if (typeof (obj) === "string") {
|
||||
return this.fromString(obj);
|
||||
}
|
||||
if (obj instanceof TokenString) {
|
||||
return this.fromTokens(obj);
|
||||
}
|
||||
if (typeof (obj) === "object") {
|
||||
return this.fromObject(obj);
|
||||
}
|
||||
throw new Error(`unsupported type: ${obj}`);
|
||||
}
|
||||
static fromObject(obj) {
|
||||
switch (obj.type) {
|
||||
case "constructor": return ConstructorFragment.fromObject(obj);
|
||||
case "error": return ErrorFragment.fromObject(obj);
|
||||
case "event": return EventFragment.fromObject(obj);
|
||||
case "function": return FunctionFragment.fromObject(obj);
|
||||
case "struct": return StructFragment.fromObject(obj);
|
||||
}
|
||||
throw new Error("not implemented yet");
|
||||
}
|
||||
static fromString(text) {
|
||||
try {
|
||||
Fragment.from(JSON.parse(text));
|
||||
}
|
||||
catch (e) { }
|
||||
return Fragment.fromTokens(lex(text));
|
||||
}
|
||||
static fromTokens(tokens) {
|
||||
const type = tokens.popKeyword(KwTypes);
|
||||
switch (type) {
|
||||
case "constructor": return ConstructorFragment.fromTokens(tokens);
|
||||
case "error": return ErrorFragment.fromTokens(tokens);
|
||||
case "event": return EventFragment.fromTokens(tokens);
|
||||
case "function": return FunctionFragment.fromTokens(tokens);
|
||||
case "struct": return StructFragment.fromTokens(tokens);
|
||||
}
|
||||
throw new Error(`unsupported type: ${type}`);
|
||||
}
|
||||
/*
|
||||
static fromTokens(tokens: TokenString): Fragment {
|
||||
const assertDone = () => {
|
||||
if (tokens.length) { throw new Error(`unexpected tokens: ${ tokens.toString() }`); }
|
||||
});
|
||||
|
||||
const type = (tokens.length && tokens.peek().type === "KEYWORD") ? tokens.peek().text: "unknown";
|
||||
|
||||
const name = consumeName("error", tokens);
|
||||
const inputs = consumeParams(tokens, type === "event");
|
||||
|
||||
switch (type) {
|
||||
case "event": case "struct":
|
||||
assertDone();
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
static isConstructor(value) {
|
||||
return (value && value.type === "constructor");
|
||||
}
|
||||
static isError(value) {
|
||||
return (value && value.type === "error");
|
||||
}
|
||||
static isEvent(value) {
|
||||
return (value && value.type === "event");
|
||||
}
|
||||
static isFunction(value) {
|
||||
return (value && value.type === "function");
|
||||
}
|
||||
static isStruct(value) {
|
||||
return (value && value.type === "struct");
|
||||
}
|
||||
}
|
||||
exports.Fragment = Fragment;
|
||||
class NamedFragment extends Fragment {
|
||||
name;
|
||||
constructor(guard, type, name, inputs) {
|
||||
super(guard, type, inputs);
|
||||
inputs = Object.freeze(inputs.slice());
|
||||
(0, index_js_1.defineProperties)(this, { name });
|
||||
}
|
||||
}
|
||||
exports.NamedFragment = NamedFragment;
|
||||
function joinParams(format, params) {
|
||||
return "(" + params.map((p) => p.format(format)).join((format === FormatType.full) ? ", " : ",") + ")";
|
||||
}
|
||||
class ErrorFragment extends NamedFragment {
|
||||
constructor(guard, name, inputs) {
|
||||
super(guard, FragmentType.error, name, inputs);
|
||||
}
|
||||
format(format = FormatType.sighash) {
|
||||
if (!FormatType[format]) {
|
||||
logger_js_1.logger.throwArgumentError("invalid format type", "format", format);
|
||||
}
|
||||
if (format === FormatType.json) {
|
||||
return JSON.stringify({
|
||||
type: "error",
|
||||
name: this.name,
|
||||
inputs: this.inputs.map((input) => JSON.parse(input.format(format))),
|
||||
});
|
||||
}
|
||||
const result = [];
|
||||
if (format !== FormatType.sighash) {
|
||||
result.push("error");
|
||||
}
|
||||
result.push(this.name + joinParams(format, this.inputs));
|
||||
return result.join(" ");
|
||||
}
|
||||
static fromString(text) {
|
||||
return ErrorFragment.fromTokens(lex(text));
|
||||
}
|
||||
static fromTokens(tokens) {
|
||||
const name = consumeName("error", tokens);
|
||||
const inputs = consumeParams(tokens);
|
||||
consumeEoi(tokens);
|
||||
return new ErrorFragment(_guard, name, inputs);
|
||||
}
|
||||
}
|
||||
exports.ErrorFragment = ErrorFragment;
|
||||
class EventFragment extends NamedFragment {
|
||||
anonymous;
|
||||
constructor(guard, name, inputs, anonymous) {
|
||||
super(guard, FragmentType.event, name, inputs);
|
||||
(0, index_js_1.defineProperties)(this, { anonymous });
|
||||
}
|
||||
format(format = FormatType.sighash) {
|
||||
if (!FormatType[format]) {
|
||||
logger_js_1.logger.throwArgumentError("invalid format type", "format", format);
|
||||
}
|
||||
if (format === FormatType.json) {
|
||||
return JSON.stringify({
|
||||
type: "event",
|
||||
anonymous: this.anonymous,
|
||||
name: this.name,
|
||||
inputs: this.inputs.map((i) => JSON.parse(i.format(format)))
|
||||
});
|
||||
}
|
||||
const result = [];
|
||||
if (format !== FormatType.sighash) {
|
||||
result.push("event");
|
||||
}
|
||||
result.push(this.name + joinParams(format, this.inputs));
|
||||
if (format !== FormatType.sighash && this.anonymous) {
|
||||
result.push("anonymous");
|
||||
}
|
||||
return result.join(" ");
|
||||
}
|
||||
static fromString(text) {
|
||||
return EventFragment.fromTokens(lex(text));
|
||||
}
|
||||
static fromTokens(tokens) {
|
||||
const name = consumeName("event", tokens);
|
||||
const inputs = consumeParams(tokens, true);
|
||||
const anonymous = !!consumeKeywords(tokens, setify(["anonymous"])).has("anonymous");
|
||||
consumeEoi(tokens);
|
||||
return new EventFragment(_guard, name, inputs, anonymous);
|
||||
}
|
||||
}
|
||||
exports.EventFragment = EventFragment;
|
||||
class ConstructorFragment extends Fragment {
|
||||
payable;
|
||||
gas;
|
||||
constructor(guard, type, inputs, payable, gas) {
|
||||
super(guard, type, inputs);
|
||||
(0, index_js_1.defineProperties)(this, { payable, gas });
|
||||
}
|
||||
format(format = FormatType.sighash) {
|
||||
if (!FormatType[format]) {
|
||||
logger_js_1.logger.throwArgumentError("invalid format type", "format", format);
|
||||
}
|
||||
if (format === FormatType.sighash) {
|
||||
logger_js_1.logger.throwError("cannot format a constructor for sighash", "UNSUPPORTED_OPERATION", {
|
||||
operation: "format(sighash)"
|
||||
});
|
||||
}
|
||||
if (format === FormatType.json) {
|
||||
return JSON.stringify({
|
||||
type: "constructor",
|
||||
stateMutability: (this.payable ? "payable" : "undefined"),
|
||||
payable: this.payable,
|
||||
gas: ((this.gas != null) ? this.gas : undefined),
|
||||
inputs: this.inputs.map((i) => JSON.parse(i.format(format)))
|
||||
});
|
||||
}
|
||||
const result = [`constructor${joinParams(format, this.inputs)}`];
|
||||
result.push((this.payable) ? "payable" : "nonpayable");
|
||||
if (this.gas != null) {
|
||||
result.push(`@${this.gas.toString()}`);
|
||||
}
|
||||
return result.join(" ");
|
||||
}
|
||||
static fromString(text) {
|
||||
return ConstructorFragment.fromTokens(lex(text));
|
||||
}
|
||||
static fromObject(obj) {
|
||||
throw new Error("TODO");
|
||||
}
|
||||
static fromTokens(tokens) {
|
||||
consumeKeywords(tokens, setify(["constructor"]));
|
||||
const inputs = consumeParams(tokens);
|
||||
const payable = !!consumeKeywords(tokens, setify(["payable"])).has("payable");
|
||||
const gas = consumeGas(tokens);
|
||||
consumeEoi(tokens);
|
||||
return new ConstructorFragment(_guard, FragmentType.constructor, inputs, payable, gas);
|
||||
}
|
||||
}
|
||||
exports.ConstructorFragment = ConstructorFragment;
|
||||
class FunctionFragment extends NamedFragment {
|
||||
constant;
|
||||
outputs;
|
||||
stateMutability;
|
||||
payable;
|
||||
gas;
|
||||
constructor(guard, name, stateMutability, inputs, outputs, gas) {
|
||||
super(guard, FragmentType.function, name, inputs);
|
||||
outputs = Object.freeze(outputs.slice());
|
||||
const constant = (stateMutability === "view" || stateMutability === "pure");
|
||||
const payable = (stateMutability === "payable");
|
||||
(0, index_js_1.defineProperties)(this, { constant, gas, outputs, payable, stateMutability });
|
||||
}
|
||||
format(format = FormatType.sighash) {
|
||||
if (!FormatType[format]) {
|
||||
logger_js_1.logger.throwArgumentError("invalid format type", "format", format);
|
||||
}
|
||||
if (format === FormatType.json) {
|
||||
return JSON.stringify({
|
||||
type: "function",
|
||||
name: this.name,
|
||||
constant: this.constant,
|
||||
stateMutability: ((this.stateMutability !== "nonpayable") ? this.stateMutability : undefined),
|
||||
payable: this.payable,
|
||||
gas: ((this.gas != null) ? this.gas : undefined),
|
||||
inputs: this.inputs.map((i) => JSON.parse(i.format(format))),
|
||||
outputs: this.outputs.map((o) => JSON.parse(o.format(format))),
|
||||
});
|
||||
}
|
||||
const result = [];
|
||||
if (format !== FormatType.sighash) {
|
||||
result.push("function");
|
||||
}
|
||||
result.push(this.name + joinParams(format, this.inputs));
|
||||
if (format !== FormatType.sighash) {
|
||||
if (this.stateMutability !== "nonpayable") {
|
||||
result.push(this.stateMutability);
|
||||
}
|
||||
if (this.outputs && this.outputs.length) {
|
||||
result.push("returns");
|
||||
result.push(joinParams(format, this.outputs));
|
||||
}
|
||||
if (this.gas != null) {
|
||||
result.push(`@${this.gas.toString()}`);
|
||||
}
|
||||
}
|
||||
return result.join(" ");
|
||||
}
|
||||
static fromString(text) {
|
||||
return FunctionFragment.fromTokens(lex(text));
|
||||
}
|
||||
static fromTokens(tokens) {
|
||||
const name = consumeName("function", tokens);
|
||||
const inputs = consumeParams(tokens);
|
||||
const mutability = consumeMutability(tokens);
|
||||
let outputs = [];
|
||||
if (consumeKeywords(tokens, setify(["returns"])).has("returns")) {
|
||||
outputs = consumeParams(tokens);
|
||||
}
|
||||
const gas = consumeGas(tokens);
|
||||
consumeEoi(tokens);
|
||||
return new FunctionFragment(_guard, name, mutability, inputs, outputs, gas);
|
||||
}
|
||||
}
|
||||
exports.FunctionFragment = FunctionFragment;
|
||||
class StructFragment extends NamedFragment {
|
||||
format() {
|
||||
throw new Error("@TODO");
|
||||
}
|
||||
static fromString(text) {
|
||||
return StructFragment.fromTokens(lex(text));
|
||||
}
|
||||
static fromTokens(tokens) {
|
||||
const name = consumeName("struct", tokens);
|
||||
const inputs = consumeParams(tokens);
|
||||
consumeEoi(tokens);
|
||||
return new StructFragment(_guard, FragmentType.struct, name, inputs);
|
||||
}
|
||||
}
|
||||
exports.StructFragment = StructFragment;
|
||||
//# sourceMappingURL=fragments.js.map
|
1
lib.commonjs/abi/fragments.js.map
Normal file
1
lib.commonjs/abi/fragments.js.map
Normal file
File diff suppressed because one or more lines are too long
26
lib.commonjs/abi/index.js
Normal file
26
lib.commonjs/abi/index.js
Normal file
@ -0,0 +1,26 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Typed = exports.TransactionDescription = exports.Result = exports.LogDescription = exports.Interface = exports.Indexed = exports.checkResultErrors = exports.ParamType = exports.FunctionFragment = exports.Fragment = exports.EventFragment = exports.ErrorFragment = exports.ConstructorFragment = exports.parseBytes32String = exports.formatBytes32String = exports.defaultAbiCoder = exports.AbiCoder = void 0;
|
||||
var abi_coder_js_1 = require("./abi-coder.js");
|
||||
Object.defineProperty(exports, "AbiCoder", { enumerable: true, get: function () { return abi_coder_js_1.AbiCoder; } });
|
||||
Object.defineProperty(exports, "defaultAbiCoder", { enumerable: true, get: function () { return abi_coder_js_1.defaultAbiCoder; } });
|
||||
var bytes32_js_1 = require("./bytes32.js");
|
||||
Object.defineProperty(exports, "formatBytes32String", { enumerable: true, get: function () { return bytes32_js_1.formatBytes32String; } });
|
||||
Object.defineProperty(exports, "parseBytes32String", { enumerable: true, get: function () { return bytes32_js_1.parseBytes32String; } });
|
||||
var fragments_js_1 = require("./fragments.js");
|
||||
Object.defineProperty(exports, "ConstructorFragment", { enumerable: true, get: function () { return fragments_js_1.ConstructorFragment; } });
|
||||
Object.defineProperty(exports, "ErrorFragment", { enumerable: true, get: function () { return fragments_js_1.ErrorFragment; } });
|
||||
Object.defineProperty(exports, "EventFragment", { enumerable: true, get: function () { return fragments_js_1.EventFragment; } });
|
||||
Object.defineProperty(exports, "Fragment", { enumerable: true, get: function () { return fragments_js_1.Fragment; } });
|
||||
Object.defineProperty(exports, "FunctionFragment", { enumerable: true, get: function () { return fragments_js_1.FunctionFragment; } });
|
||||
Object.defineProperty(exports, "ParamType", { enumerable: true, get: function () { return fragments_js_1.ParamType; } });
|
||||
var interface_js_1 = require("./interface.js");
|
||||
Object.defineProperty(exports, "checkResultErrors", { enumerable: true, get: function () { return interface_js_1.checkResultErrors; } });
|
||||
Object.defineProperty(exports, "Indexed", { enumerable: true, get: function () { return interface_js_1.Indexed; } });
|
||||
Object.defineProperty(exports, "Interface", { enumerable: true, get: function () { return interface_js_1.Interface; } });
|
||||
Object.defineProperty(exports, "LogDescription", { enumerable: true, get: function () { return interface_js_1.LogDescription; } });
|
||||
Object.defineProperty(exports, "Result", { enumerable: true, get: function () { return interface_js_1.Result; } });
|
||||
Object.defineProperty(exports, "TransactionDescription", { enumerable: true, get: function () { return interface_js_1.TransactionDescription; } });
|
||||
var typed_js_1 = require("./typed.js");
|
||||
Object.defineProperty(exports, "Typed", { enumerable: true, get: function () { return typed_js_1.Typed; } });
|
||||
//# sourceMappingURL=index.js.map
|
1
lib.commonjs/abi/index.js.map
Normal file
1
lib.commonjs/abi/index.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src.ts/abi/index.ts"],"names":[],"mappings":";;;AACA,+CAGwB;AAFpB,wGAAA,QAAQ,OAAA;AACR,+GAAA,eAAe,OAAA;AAGnB,2CAAuE;AAA9D,iHAAA,mBAAmB,OAAA;AAAE,gHAAA,kBAAkB,OAAA;AAEhD,+CAOwB;AANpB,mHAAA,mBAAmB,OAAA;AACnB,6GAAA,aAAa,OAAA;AACb,6GAAA,aAAa,OAAA;AACb,wGAAA,QAAQ,OAAA;AACR,gHAAA,gBAAgB,OAAA;AAChB,yGAAA,SAAS,OAAA;AAGb,+CAOwB;AANpB,iHAAA,iBAAiB,OAAA;AACjB,uGAAA,OAAO,OAAA;AACP,yGAAA,SAAS,OAAA;AACT,8GAAA,cAAc,OAAA;AACd,sGAAA,MAAM,OAAA;AACN,sHAAA,sBAAsB,OAAA;AAG1B,uCAAmC;AAA1B,iGAAA,KAAK,OAAA"}
|
817
lib.commonjs/abi/interface.js
Normal file
817
lib.commonjs/abi/interface.js
Normal file
@ -0,0 +1,817 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Interface = exports.Indexed = exports.ErrorDescription = exports.TransactionDescription = exports.LogDescription = exports.Result = exports.checkResultErrors = void 0;
|
||||
const data_js_1 = require("../utils/data.js");
|
||||
const index_js_1 = require("../crypto/index.js");
|
||||
const index_js_2 = require("../hash/index.js");
|
||||
const logger_js_1 = require("../utils/logger.js");
|
||||
const properties_js_1 = require("../utils/properties.js");
|
||||
const maths_js_1 = require("../utils/maths.js");
|
||||
const abi_coder_js_1 = require("./abi-coder.js");
|
||||
const abstract_coder_js_1 = require("./coders/abstract-coder.js");
|
||||
Object.defineProperty(exports, "checkResultErrors", { enumerable: true, get: function () { return abstract_coder_js_1.checkResultErrors; } });
|
||||
Object.defineProperty(exports, "Result", { enumerable: true, get: function () { return abstract_coder_js_1.Result; } });
|
||||
const fragments_js_1 = require("./fragments.js");
|
||||
const typed_js_1 = require("./typed.js");
|
||||
class LogDescription {
|
||||
fragment;
|
||||
name;
|
||||
signature;
|
||||
topic;
|
||||
args;
|
||||
constructor(fragment, topic, args) {
|
||||
const name = fragment.name, signature = fragment.format();
|
||||
(0, properties_js_1.defineProperties)(this, {
|
||||
fragment, name, signature, topic, args
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.LogDescription = LogDescription;
|
||||
class TransactionDescription {
|
||||
fragment;
|
||||
name;
|
||||
args;
|
||||
signature;
|
||||
selector;
|
||||
value;
|
||||
constructor(fragment, selector, args, value) {
|
||||
const name = fragment.name, signature = fragment.format();
|
||||
(0, properties_js_1.defineProperties)(this, {
|
||||
fragment, name, args, signature, selector, value
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.TransactionDescription = TransactionDescription;
|
||||
class ErrorDescription {
|
||||
fragment;
|
||||
name;
|
||||
args;
|
||||
signature;
|
||||
selector;
|
||||
constructor(fragment, selector, args) {
|
||||
const name = fragment.name, signature = fragment.format();
|
||||
(0, properties_js_1.defineProperties)(this, {
|
||||
fragment, name, args, signature, selector
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.ErrorDescription = ErrorDescription;
|
||||
class Indexed {
|
||||
hash;
|
||||
_isIndexed;
|
||||
static isIndexed(value) {
|
||||
return !!(value && value._isIndexed);
|
||||
}
|
||||
constructor(hash) {
|
||||
(0, properties_js_1.defineProperties)(this, { hash, _isIndexed: true });
|
||||
}
|
||||
}
|
||||
exports.Indexed = Indexed;
|
||||
// https://docs.soliditylang.org/en/v0.8.13/control-structures.html?highlight=panic#panic-via-assert-and-error-via-require
|
||||
const PanicReasons = {
|
||||
"0": "generic panic",
|
||||
"1": "assert(false)",
|
||||
"17": "arithmetic overflow",
|
||||
"18": "division or modulo by zero",
|
||||
"33": "enum overflow",
|
||||
"34": "invalid encoded storage byte array accessed",
|
||||
"49": "out-of-bounds array access; popping on an empty array",
|
||||
"50": "out-of-bounds access of an array or bytesN",
|
||||
"65": "out of memory",
|
||||
"81": "uninitialized function",
|
||||
};
|
||||
const BuiltinErrors = {
|
||||
"0x08c379a0": {
|
||||
signature: "Error(string)",
|
||||
name: "Error",
|
||||
inputs: ["string"],
|
||||
reason: (message) => {
|
||||
return `reverted with reason string ${JSON.stringify(message)}`;
|
||||
}
|
||||
},
|
||||
"0x4e487b71": {
|
||||
signature: "Panic(uint256)",
|
||||
name: "Panic",
|
||||
inputs: ["uint256"],
|
||||
reason: (code) => {
|
||||
let reason = "unknown panic code";
|
||||
if (code >= 0 && code <= 0xff && PanicReasons[code.toString()]) {
|
||||
reason = PanicReasons[code.toString()];
|
||||
}
|
||||
return `reverted with panic code 0x${code.toString(16)} (${reason})`;
|
||||
}
|
||||
}
|
||||
};
|
||||
class Interface {
|
||||
fragments;
|
||||
deploy;
|
||||
#errors;
|
||||
#events;
|
||||
#functions;
|
||||
// #structs: Map<string, StructFragment>;
|
||||
#abiCoder;
|
||||
constructor(fragments) {
|
||||
let abi = [];
|
||||
if (typeof (fragments) === "string") {
|
||||
abi = JSON.parse(fragments);
|
||||
}
|
||||
else {
|
||||
abi = fragments;
|
||||
}
|
||||
this.#functions = new Map();
|
||||
this.#errors = new Map();
|
||||
this.#events = new Map();
|
||||
// this.#structs = new Map();
|
||||
(0, properties_js_1.defineProperties)(this, {
|
||||
fragments: Object.freeze(abi.map((f) => fragments_js_1.Fragment.from(f)).filter((f) => (f != null))),
|
||||
});
|
||||
this.#abiCoder = this.getAbiCoder();
|
||||
// Add all fragments by their signature
|
||||
this.fragments.forEach((fragment) => {
|
||||
let bucket;
|
||||
switch (fragment.type) {
|
||||
case "constructor":
|
||||
if (this.deploy) {
|
||||
logger_js_1.logger.warn("duplicate definition - constructor");
|
||||
return;
|
||||
}
|
||||
//checkNames(fragment, "input", fragment.inputs);
|
||||
(0, properties_js_1.defineProperties)(this, { deploy: fragment });
|
||||
return;
|
||||
case "function":
|
||||
//checkNames(fragment, "input", fragment.inputs);
|
||||
//checkNames(fragment, "output", (<FunctionFragment>fragment).outputs);
|
||||
bucket = this.#functions;
|
||||
break;
|
||||
case "event":
|
||||
//checkNames(fragment, "input", fragment.inputs);
|
||||
bucket = this.#events;
|
||||
break;
|
||||
case "error":
|
||||
bucket = this.#errors;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
const signature = fragment.format();
|
||||
if (bucket.has(signature)) {
|
||||
logger_js_1.logger.warn("duplicate definition - " + signature);
|
||||
return;
|
||||
}
|
||||
bucket.set(signature, fragment);
|
||||
});
|
||||
// If we do not have a constructor add a default
|
||||
if (!this.deploy) {
|
||||
(0, properties_js_1.defineProperties)(this, {
|
||||
deploy: fragments_js_1.ConstructorFragment.fromString("constructor()")
|
||||
});
|
||||
}
|
||||
}
|
||||
// @TODO: multi sig?
|
||||
format(format) {
|
||||
if (!format) {
|
||||
format = fragments_js_1.FormatType.full;
|
||||
}
|
||||
if (format === fragments_js_1.FormatType.sighash) {
|
||||
logger_js_1.logger.throwArgumentError("interface does not support formatting sighash", "format", format);
|
||||
}
|
||||
const abi = this.fragments.map((f) => f.format(format));
|
||||
// We need to re-bundle the JSON fragments a bit
|
||||
if (format === fragments_js_1.FormatType.json) {
|
||||
return JSON.stringify(abi.map((j) => JSON.parse(j)));
|
||||
}
|
||||
return abi;
|
||||
}
|
||||
getAbiCoder() {
|
||||
return abi_coder_js_1.defaultAbiCoder;
|
||||
}
|
||||
//static getAddress(address: string): string {
|
||||
// return getAddress(address);
|
||||
//}
|
||||
//static getSelector(fragment: ErrorFragment | FunctionFragment): string {
|
||||
// return dataSlice(id(fragment.format()), 0, 4);
|
||||
//}
|
||||
//static getEventTopic(eventFragment: EventFragment): string {
|
||||
// return id(eventFragment.format());
|
||||
//}
|
||||
// Find a function definition by any means necessary (unless it is ambiguous)
|
||||
#getFunction(key, values, forceUnique) {
|
||||
// Selector
|
||||
if ((0, data_js_1.isHexString)(key)) {
|
||||
const selector = key.toLowerCase();
|
||||
for (const fragment of this.#functions.values()) {
|
||||
if (selector === this.getSelector(fragment)) {
|
||||
return fragment;
|
||||
}
|
||||
}
|
||||
logger_js_1.logger.throwArgumentError("no matching function", "selector", key);
|
||||
}
|
||||
// It is a bare name, look up the function (will return null if ambiguous)
|
||||
if (key.indexOf("(") === -1) {
|
||||
const matching = [];
|
||||
for (const [name, fragment] of this.#functions) {
|
||||
if (name.split("(" /* fix:) */)[0] === key) {
|
||||
matching.push(fragment);
|
||||
}
|
||||
}
|
||||
if (values) {
|
||||
const lastValue = (values.length > 0) ? values[values.length - 1] : null;
|
||||
let valueLength = values.length;
|
||||
let allowOptions = true;
|
||||
if (typed_js_1.Typed.isTyped(lastValue) && lastValue.type === "overrides") {
|
||||
allowOptions = false;
|
||||
valueLength--;
|
||||
}
|
||||
// Remove all matches that don't have a compatible length. The args
|
||||
// may contain an overrides, so the match may have n or n - 1 parameters
|
||||
for (let i = matching.length - 1; i >= 0; i--) {
|
||||
const inputs = matching[i].inputs.length;
|
||||
if (inputs !== valueLength && (!allowOptions || inputs !== valueLength - 1)) {
|
||||
matching.splice(i, 1);
|
||||
}
|
||||
}
|
||||
// Remove all matches that don't match the Typed signature
|
||||
for (let i = matching.length - 1; i >= 0; i--) {
|
||||
const inputs = matching[i].inputs;
|
||||
for (let j = 0; j < values.length; j++) {
|
||||
// Not a typed value
|
||||
if (!typed_js_1.Typed.isTyped(values[j])) {
|
||||
continue;
|
||||
}
|
||||
// We are past the inputs
|
||||
if (j >= inputs.length) {
|
||||
if (values[j].type === "overrides") {
|
||||
continue;
|
||||
}
|
||||
matching.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
// Make sure the value type matches the input type
|
||||
if (values[j].type !== inputs[j].baseType) {
|
||||
matching.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// We found a single matching signature with an overrides, but the
|
||||
// last value is something that cannot possibly be an options
|
||||
if (matching.length === 1 && values && values.length !== matching[0].inputs.length) {
|
||||
const lastArg = values[values.length - 1];
|
||||
if (lastArg == null || Array.isArray(lastArg) || typeof (lastArg) !== "object") {
|
||||
matching.splice(0, 1);
|
||||
}
|
||||
}
|
||||
if (matching.length === 0) {
|
||||
logger_js_1.logger.throwArgumentError("no matching function", "name", key);
|
||||
}
|
||||
else if (matching.length > 1 && forceUnique) {
|
||||
const matchStr = matching.map((m) => JSON.stringify(m.format())).join(", ");
|
||||
logger_js_1.logger.throwArgumentError(`multiple matching functions (i.e. ${matchStr})`, "name", key);
|
||||
}
|
||||
return matching[0];
|
||||
}
|
||||
// Normalize the signature and lookup the function
|
||||
const result = this.#functions.get(fragments_js_1.FunctionFragment.fromString(key).format());
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
return logger_js_1.logger.throwArgumentError("no matching function", "signature", key);
|
||||
}
|
||||
getFunctionName(key) {
|
||||
return (this.#getFunction(key, null, false)).name;
|
||||
}
|
||||
getFunction(key, values) {
|
||||
return this.#getFunction(key, values || null, true);
|
||||
}
|
||||
// Find an event definition by any means necessary (unless it is ambiguous)
|
||||
#getEvent(key, values, forceUnique) {
|
||||
// EventTopic
|
||||
if ((0, data_js_1.isHexString)(key)) {
|
||||
const eventTopic = key.toLowerCase();
|
||||
for (const fragment of this.#events.values()) {
|
||||
if (eventTopic === this.getEventTopic(fragment)) {
|
||||
return fragment;
|
||||
}
|
||||
}
|
||||
logger_js_1.logger.throwArgumentError("no matching event", "eventTopic", key);
|
||||
}
|
||||
// It is a bare name, look up the function (will return null if ambiguous)
|
||||
if (key.indexOf("(") === -1) {
|
||||
const matching = [];
|
||||
for (const [name, fragment] of this.#events) {
|
||||
if (name.split("(" /* fix:) */)[0] === key) {
|
||||
matching.push(fragment);
|
||||
}
|
||||
}
|
||||
if (values) {
|
||||
// Remove all matches that don't have a compatible length.
|
||||
for (let i = matching.length - 1; i >= 0; i--) {
|
||||
if (matching[i].inputs.length < values.length) {
|
||||
matching.splice(i, 1);
|
||||
}
|
||||
}
|
||||
// Remove all matches that don't match the Typed signature
|
||||
for (let i = matching.length - 1; i >= 0; i--) {
|
||||
const inputs = matching[i].inputs;
|
||||
for (let j = 0; j < values.length; j++) {
|
||||
// Not a typed value
|
||||
if (!typed_js_1.Typed.isTyped(values[j])) {
|
||||
continue;
|
||||
}
|
||||
// Make sure the value type matches the input type
|
||||
if (values[j].type !== inputs[j].baseType) {
|
||||
matching.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (matching.length === 0) {
|
||||
logger_js_1.logger.throwArgumentError("no matching event", "name", key);
|
||||
}
|
||||
else if (matching.length > 1 && forceUnique) {
|
||||
// @TODO: refine by Typed
|
||||
logger_js_1.logger.throwArgumentError("multiple matching events", "name", key);
|
||||
}
|
||||
return matching[0];
|
||||
}
|
||||
// Normalize the signature and lookup the function
|
||||
const result = this.#events.get(fragments_js_1.EventFragment.fromString(key).format());
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
return logger_js_1.logger.throwArgumentError("no matching event", "signature", key);
|
||||
}
|
||||
getEventName(key) {
|
||||
return (this.#getEvent(key, null, false)).name;
|
||||
}
|
||||
getEvent(key, values) {
|
||||
return this.#getEvent(key, values || null, true);
|
||||
}
|
||||
// Find a function definition by any means necessary (unless it is ambiguous)
|
||||
getError(key, values) {
|
||||
if ((0, data_js_1.isHexString)(key)) {
|
||||
const selector = key.toLowerCase();
|
||||
if (BuiltinErrors[selector]) {
|
||||
return fragments_js_1.ErrorFragment.fromString(BuiltinErrors[selector].signature);
|
||||
}
|
||||
for (const fragment of this.#errors.values()) {
|
||||
if (selector === this.getSelector(fragment)) {
|
||||
return fragment;
|
||||
}
|
||||
}
|
||||
logger_js_1.logger.throwArgumentError("no matching error", "selector", key);
|
||||
}
|
||||
// It is a bare name, look up the function (will return null if ambiguous)
|
||||
if (key.indexOf("(") === -1) {
|
||||
const matching = [];
|
||||
for (const [name, fragment] of this.#errors) {
|
||||
if (name.split("(" /* fix:) */)[0] === key) {
|
||||
matching.push(fragment);
|
||||
}
|
||||
}
|
||||
if (matching.length === 0) {
|
||||
if (key === "Error") {
|
||||
return fragments_js_1.ErrorFragment.fromString("error Error(string)");
|
||||
}
|
||||
if (key === "Panic") {
|
||||
return fragments_js_1.ErrorFragment.fromString("error Panic(uint256)");
|
||||
}
|
||||
logger_js_1.logger.throwArgumentError("no matching error", "name", key);
|
||||
}
|
||||
else if (matching.length > 1) {
|
||||
// @TODO: refine by Typed
|
||||
logger_js_1.logger.throwArgumentError("multiple matching errors", "name", key);
|
||||
}
|
||||
return matching[0];
|
||||
}
|
||||
// Normalize the signature and lookup the function
|
||||
key = fragments_js_1.ErrorFragment.fromString(key).format();
|
||||
if (key === "Error(string)") {
|
||||
return fragments_js_1.ErrorFragment.fromString("error Error(string)");
|
||||
}
|
||||
if (key === "Panic(uint256)") {
|
||||
return fragments_js_1.ErrorFragment.fromString("error Panic(uint256)");
|
||||
}
|
||||
const result = this.#errors.get(key);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
return logger_js_1.logger.throwArgumentError("no matching error", "signature", key);
|
||||
}
|
||||
// Get the 4-byte selector used by Solidity to identify a function
|
||||
getSelector(fragment) {
|
||||
/*
|
||||
if (typeof(fragment) === "string") {
|
||||
const matches: Array<Fragment> = [ ];
|
||||
|
||||
try { matches.push(this.getFunction(fragment)); } catch (error) { }
|
||||
try { matches.push(this.getError(<string>fragment)); } catch (_) { }
|
||||
|
||||
if (matches.length === 0) {
|
||||
logger.throwArgumentError("unknown fragment", "key", fragment);
|
||||
} else if (matches.length > 1) {
|
||||
logger.throwArgumentError("ambiguous fragment matches function and error", "key", fragment);
|
||||
}
|
||||
|
||||
fragment = matches[0];
|
||||
}
|
||||
*/
|
||||
return (0, data_js_1.dataSlice)((0, index_js_2.id)(fragment.format()), 0, 4);
|
||||
}
|
||||
// Get the 32-byte topic hash used by Solidity to identify an event
|
||||
getEventTopic(fragment) {
|
||||
//if (typeof(fragment) === "string") { fragment = this.getEvent(eventFragment); }
|
||||
return (0, index_js_2.id)(fragment.format());
|
||||
}
|
||||
_decodeParams(params, data) {
|
||||
return this.#abiCoder.decode(params, data);
|
||||
}
|
||||
_encodeParams(params, values) {
|
||||
return this.#abiCoder.encode(params, values);
|
||||
}
|
||||
encodeDeploy(values) {
|
||||
return this._encodeParams(this.deploy.inputs, values || []);
|
||||
}
|
||||
decodeErrorResult(fragment, data) {
|
||||
if (typeof (fragment) === "string") {
|
||||
fragment = this.getError(fragment);
|
||||
}
|
||||
if ((0, data_js_1.dataSlice)(data, 0, 4) !== this.getSelector(fragment)) {
|
||||
logger_js_1.logger.throwArgumentError(`data signature does not match error ${fragment.name}.`, "data", data);
|
||||
}
|
||||
return this._decodeParams(fragment.inputs, (0, data_js_1.dataSlice)(data, 4));
|
||||
}
|
||||
encodeErrorResult(fragment, values) {
|
||||
if (typeof (fragment) === "string") {
|
||||
fragment = this.getError(fragment);
|
||||
}
|
||||
return (0, data_js_1.concat)([
|
||||
this.getSelector(fragment),
|
||||
this._encodeParams(fragment.inputs, values || [])
|
||||
]);
|
||||
}
|
||||
// Decode the data for a function call (e.g. tx.data)
|
||||
decodeFunctionData(fragment, data) {
|
||||
if (typeof (fragment) === "string") {
|
||||
fragment = this.getFunction(fragment);
|
||||
}
|
||||
if ((0, data_js_1.dataSlice)(data, 0, 4) !== this.getSelector(fragment)) {
|
||||
logger_js_1.logger.throwArgumentError(`data signature does not match function ${fragment.name}.`, "data", data);
|
||||
}
|
||||
return this._decodeParams(fragment.inputs, (0, data_js_1.dataSlice)(data, 4));
|
||||
}
|
||||
// Encode the data for a function call (e.g. tx.data)
|
||||
encodeFunctionData(fragment, values) {
|
||||
if (typeof (fragment) === "string") {
|
||||
fragment = this.getFunction(fragment);
|
||||
}
|
||||
return (0, data_js_1.concat)([
|
||||
this.getSelector(fragment),
|
||||
this._encodeParams(fragment.inputs, values || [])
|
||||
]);
|
||||
}
|
||||
// Decode the result from a function call (e.g. from eth_call)
|
||||
decodeFunctionResult(fragment, data) {
|
||||
if (typeof (fragment) === "string") {
|
||||
fragment = this.getFunction(fragment);
|
||||
}
|
||||
let message = "invalid length for result data";
|
||||
const bytes = logger_js_1.logger.getBytesCopy(data);
|
||||
if ((bytes.length % 32) === 0) {
|
||||
try {
|
||||
return this.#abiCoder.decode(fragment.outputs, bytes);
|
||||
}
|
||||
catch (error) {
|
||||
message = "could not decode result data";
|
||||
}
|
||||
}
|
||||
// Call returned data with no error, but the data is junk
|
||||
return logger_js_1.logger.throwError(message, "BAD_DATA", {
|
||||
value: (0, data_js_1.hexlify)(bytes),
|
||||
info: { method: fragment.name, signature: fragment.format() }
|
||||
});
|
||||
}
|
||||
makeError(fragment, _data, tx) {
|
||||
if (typeof (fragment) === "string") {
|
||||
fragment = this.getFunction(fragment);
|
||||
}
|
||||
const data = logger_js_1.logger.getBytes(_data);
|
||||
let args = undefined;
|
||||
if (tx) {
|
||||
try {
|
||||
args = this.#abiCoder.decode(fragment.inputs, tx.data || "0x");
|
||||
}
|
||||
catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
let errorArgs = undefined;
|
||||
let errorName = undefined;
|
||||
let errorSignature = undefined;
|
||||
let reason = "unknown reason";
|
||||
if (data.length === 0) {
|
||||
reason = "missing error reason";
|
||||
}
|
||||
else if ((data.length % 32) === 4) {
|
||||
const selector = (0, data_js_1.hexlify)(data.slice(0, 4));
|
||||
const builtin = BuiltinErrors[selector];
|
||||
if (builtin) {
|
||||
try {
|
||||
errorName = builtin.name;
|
||||
errorSignature = builtin.signature;
|
||||
errorArgs = this.#abiCoder.decode(builtin.inputs, data.slice(4));
|
||||
reason = builtin.reason(...errorArgs);
|
||||
}
|
||||
catch (error) {
|
||||
console.log(error); // @TODO: remove
|
||||
}
|
||||
}
|
||||
else {
|
||||
reason = "unknown custom error";
|
||||
try {
|
||||
const error = this.getError(selector);
|
||||
errorName = error.name;
|
||||
errorSignature = error.format();
|
||||
reason = `custom error: ${errorSignature}`;
|
||||
try {
|
||||
errorArgs = this.#abiCoder.decode(error.inputs, data.slice(4));
|
||||
}
|
||||
catch (error) {
|
||||
reason = `custom error: ${errorSignature} (coult not decode error data)`;
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.log(error); // @TODO: remove
|
||||
}
|
||||
}
|
||||
}
|
||||
return logger_js_1.logger.makeError("call revert exception", "CALL_EXCEPTION", {
|
||||
data: (0, data_js_1.hexlify)(data), transaction: null,
|
||||
method: fragment.name, signature: fragment.format(), args,
|
||||
errorArgs, errorName, errorSignature, reason
|
||||
});
|
||||
}
|
||||
// Encode the result for a function call (e.g. for eth_call)
|
||||
encodeFunctionResult(functionFragment, values) {
|
||||
if (typeof (functionFragment) === "string") {
|
||||
functionFragment = this.getFunction(functionFragment);
|
||||
}
|
||||
return (0, data_js_1.hexlify)(this.#abiCoder.encode(functionFragment.outputs, values || []));
|
||||
}
|
||||
/*
|
||||
spelunk(inputs: Array<ParamType>, values: ReadonlyArray<any>, processfunc: (type: string, value: any) => Promise<any>): Promise<Array<any>> {
|
||||
const promises: Array<Promise<>> = [ ];
|
||||
const process = function(type: ParamType, value: any): any {
|
||||
if (type.baseType === "array") {
|
||||
return descend(type.child
|
||||
}
|
||||
if (type. === "address") {
|
||||
}
|
||||
};
|
||||
|
||||
const descend = function (inputs: Array<ParamType>, values: ReadonlyArray<any>) {
|
||||
if (inputs.length !== values.length) { throw new Error("length mismatch"); }
|
||||
|
||||
};
|
||||
|
||||
const result: Array<any> = [ ];
|
||||
values.forEach((value, index) => {
|
||||
if (value == null) {
|
||||
topics.push(null);
|
||||
} else if (param.baseType === "array" || param.baseType === "tuple") {
|
||||
logger.throwArgumentError("filtering with tuples or arrays not supported", ("contract." + param.name), value);
|
||||
} else if (Array.isArray(value)) {
|
||||
topics.push(value.map((value) => encodeTopic(param, value)));
|
||||
} else {
|
||||
topics.push(encodeTopic(param, value));
|
||||
}
|
||||
});
|
||||
}
|
||||
*/
|
||||
// Create the filter for the event with search criteria (e.g. for eth_filterLog)
|
||||
encodeFilterTopics(eventFragment, values) {
|
||||
if (typeof (eventFragment) === "string") {
|
||||
eventFragment = this.getEvent(eventFragment);
|
||||
}
|
||||
if (values.length > eventFragment.inputs.length) {
|
||||
logger_js_1.logger.throwError("too many arguments for " + eventFragment.format(), "UNEXPECTED_ARGUMENT", {
|
||||
count: values.length,
|
||||
expectedCount: eventFragment.inputs.length
|
||||
});
|
||||
}
|
||||
const topics = [];
|
||||
if (!eventFragment.anonymous) {
|
||||
topics.push(this.getEventTopic(eventFragment));
|
||||
}
|
||||
// @TODO: Use the coders for this; to properly support tuples, etc.
|
||||
const encodeTopic = (param, value) => {
|
||||
if (param.type === "string") {
|
||||
return (0, index_js_2.id)(value);
|
||||
}
|
||||
else if (param.type === "bytes") {
|
||||
return (0, index_js_1.keccak256)((0, data_js_1.hexlify)(value));
|
||||
}
|
||||
if (param.type === "bool" && typeof (value) === "boolean") {
|
||||
value = (value ? "0x01" : "0x00");
|
||||
}
|
||||
if (param.type.match(/^u?int/)) {
|
||||
value = (0, maths_js_1.toHex)(value);
|
||||
}
|
||||
// Check addresses are valid
|
||||
if (param.type === "address") {
|
||||
this.#abiCoder.encode(["address"], [value]);
|
||||
}
|
||||
return (0, data_js_1.zeroPadValue)((0, data_js_1.hexlify)(value), 32);
|
||||
//@TOOD should probably be return toHex(value, 32)
|
||||
};
|
||||
values.forEach((value, index) => {
|
||||
const param = eventFragment.inputs[index];
|
||||
if (!param.indexed) {
|
||||
if (value != null) {
|
||||
logger_js_1.logger.throwArgumentError("cannot filter non-indexed parameters; must be null", ("contract." + param.name), value);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (value == null) {
|
||||
topics.push(null);
|
||||
}
|
||||
else if (param.baseType === "array" || param.baseType === "tuple") {
|
||||
logger_js_1.logger.throwArgumentError("filtering with tuples or arrays not supported", ("contract." + param.name), value);
|
||||
}
|
||||
else if (Array.isArray(value)) {
|
||||
topics.push(value.map((value) => encodeTopic(param, value)));
|
||||
}
|
||||
else {
|
||||
topics.push(encodeTopic(param, value));
|
||||
}
|
||||
});
|
||||
// Trim off trailing nulls
|
||||
while (topics.length && topics[topics.length - 1] === null) {
|
||||
topics.pop();
|
||||
}
|
||||
return topics;
|
||||
}
|
||||
encodeEventLog(eventFragment, values) {
|
||||
if (typeof (eventFragment) === "string") {
|
||||
eventFragment = this.getEvent(eventFragment);
|
||||
}
|
||||
const topics = [];
|
||||
const dataTypes = [];
|
||||
const dataValues = [];
|
||||
if (!eventFragment.anonymous) {
|
||||
topics.push(this.getEventTopic(eventFragment));
|
||||
}
|
||||
if (values.length !== eventFragment.inputs.length) {
|
||||
logger_js_1.logger.throwArgumentError("event arguments/values mismatch", "values", values);
|
||||
}
|
||||
eventFragment.inputs.forEach((param, index) => {
|
||||
const value = values[index];
|
||||
if (param.indexed) {
|
||||
if (param.type === "string") {
|
||||
topics.push((0, index_js_2.id)(value));
|
||||
}
|
||||
else if (param.type === "bytes") {
|
||||
topics.push((0, index_js_1.keccak256)(value));
|
||||
}
|
||||
else if (param.baseType === "tuple" || param.baseType === "array") {
|
||||
// @TODO
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
else {
|
||||
topics.push(this.#abiCoder.encode([param.type], [value]));
|
||||
}
|
||||
}
|
||||
else {
|
||||
dataTypes.push(param);
|
||||
dataValues.push(value);
|
||||
}
|
||||
});
|
||||
return {
|
||||
data: this.#abiCoder.encode(dataTypes, dataValues),
|
||||
topics: topics
|
||||
};
|
||||
}
|
||||
// Decode a filter for the event and the search criteria
|
||||
decodeEventLog(eventFragment, data, topics) {
|
||||
if (typeof (eventFragment) === "string") {
|
||||
eventFragment = this.getEvent(eventFragment);
|
||||
}
|
||||
if (topics != null && !eventFragment.anonymous) {
|
||||
const eventTopic = this.getEventTopic(eventFragment);
|
||||
if (!(0, data_js_1.isHexString)(topics[0], 32) || topics[0].toLowerCase() !== eventTopic) {
|
||||
logger_js_1.logger.throwArgumentError("fragment/topic mismatch", "topics[0]", topics[0]);
|
||||
}
|
||||
topics = topics.slice(1);
|
||||
}
|
||||
const indexed = [];
|
||||
const nonIndexed = [];
|
||||
const dynamic = [];
|
||||
eventFragment.inputs.forEach((param, index) => {
|
||||
if (param.indexed) {
|
||||
if (param.type === "string" || param.type === "bytes" || param.baseType === "tuple" || param.baseType === "array") {
|
||||
indexed.push(fragments_js_1.ParamType.fromObject({ type: "bytes32", name: param.name }));
|
||||
dynamic.push(true);
|
||||
}
|
||||
else {
|
||||
indexed.push(param);
|
||||
dynamic.push(false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
nonIndexed.push(param);
|
||||
dynamic.push(false);
|
||||
}
|
||||
});
|
||||
const resultIndexed = (topics != null) ? this.#abiCoder.decode(indexed, (0, data_js_1.concat)(topics)) : null;
|
||||
const resultNonIndexed = this.#abiCoder.decode(nonIndexed, data, true);
|
||||
//const result: (Array<any> & { [ key: string ]: any }) = [ ];
|
||||
const values = [];
|
||||
const keys = [];
|
||||
let nonIndexedIndex = 0, indexedIndex = 0;
|
||||
eventFragment.inputs.forEach((param, index) => {
|
||||
let value = null;
|
||||
if (param.indexed) {
|
||||
if (resultIndexed == null) {
|
||||
value = new Indexed(null);
|
||||
}
|
||||
else if (dynamic[index]) {
|
||||
value = new Indexed(resultIndexed[indexedIndex++]);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
value = resultIndexed[indexedIndex++];
|
||||
}
|
||||
catch (error) {
|
||||
value = error;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
try {
|
||||
value = resultNonIndexed[nonIndexedIndex++];
|
||||
}
|
||||
catch (error) {
|
||||
value = error;
|
||||
}
|
||||
}
|
||||
values.push(value);
|
||||
keys.push(param.name || null);
|
||||
});
|
||||
return abstract_coder_js_1.Result.fromItems(values, keys);
|
||||
}
|
||||
// Given a transaction, find the matching function fragment (if any) and
|
||||
// determine all its properties and call parameters
|
||||
parseTransaction(tx) {
|
||||
const data = logger_js_1.logger.getBytes(tx.data, "tx.data");
|
||||
const value = logger_js_1.logger.getBigInt((tx.value != null) ? tx.value : 0, "tx.value");
|
||||
const fragment = this.getFunction((0, data_js_1.hexlify)(data.slice(0, 4)));
|
||||
if (!fragment) {
|
||||
return null;
|
||||
}
|
||||
const args = this.#abiCoder.decode(fragment.inputs, data.slice(4));
|
||||
return new TransactionDescription(fragment, this.getSelector(fragment), args, value);
|
||||
}
|
||||
// @TODO
|
||||
//parseCallResult(data: BytesLike): ??
|
||||
// Given an event log, find the matching event fragment (if any) and
|
||||
// determine all its properties and values
|
||||
parseLog(log) {
|
||||
const fragment = this.getEvent(log.topics[0]);
|
||||
if (!fragment || fragment.anonymous) {
|
||||
return null;
|
||||
}
|
||||
// @TODO: If anonymous, and the only method, and the input count matches, should we parse?
|
||||
// Probably not, because just because it is the only event in the ABI does
|
||||
// not mean we have the full ABI; maybe just a fragment?
|
||||
return new LogDescription(fragment, this.getEventTopic(fragment), this.decodeEventLog(fragment, log.data, log.topics));
|
||||
}
|
||||
parseError(data) {
|
||||
const hexData = (0, data_js_1.hexlify)(data);
|
||||
const fragment = this.getError((0, data_js_1.dataSlice)(hexData, 0, 4));
|
||||
if (!fragment) {
|
||||
return null;
|
||||
}
|
||||
const args = this.#abiCoder.decode(fragment.inputs, (0, data_js_1.dataSlice)(hexData, 4));
|
||||
return new ErrorDescription(fragment, this.getSelector(fragment), args);
|
||||
}
|
||||
static from(value) {
|
||||
// Already an Interface, which is immutable
|
||||
if (value instanceof Interface) {
|
||||
return value;
|
||||
}
|
||||
// JSON
|
||||
if (typeof (value) === "string") {
|
||||
return new Interface(JSON.parse(value));
|
||||
}
|
||||
// Maybe an interface from an older version, or from a symlinked copy
|
||||
if (typeof (value.format) === "function") {
|
||||
return new Interface(value.format(fragments_js_1.FormatType.json));
|
||||
}
|
||||
// Array of fragments
|
||||
return new Interface(value);
|
||||
}
|
||||
}
|
||||
exports.Interface = Interface;
|
||||
//# sourceMappingURL=interface.js.map
|
1
lib.commonjs/abi/interface.js.map
Normal file
1
lib.commonjs/abi/interface.js.map
Normal file
File diff suppressed because one or more lines are too long
216
lib.commonjs/abi/typed.js
Normal file
216
lib.commonjs/abi/typed.js
Normal file
@ -0,0 +1,216 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Typed = void 0;
|
||||
const properties_js_1 = require("../utils/properties.js");
|
||||
const _gaurd = {};
|
||||
function n(value, width) {
|
||||
let signed = false;
|
||||
if (width < 0) {
|
||||
signed = true;
|
||||
width *= -1;
|
||||
}
|
||||
// @TODO: Check range is valid for value
|
||||
return new Typed(_gaurd, `${signed ? "" : "u"}int${width}`, value, { signed, width });
|
||||
}
|
||||
function b(value, size) {
|
||||
// @TODO: Check range is valid for value
|
||||
return new Typed(_gaurd, `bytes${(size) ? size : ""}`, value, { size });
|
||||
}
|
||||
const _typedSymbol = Symbol.for("_ethers_typed");
|
||||
class Typed {
|
||||
type;
|
||||
value;
|
||||
#options;
|
||||
_typedSymbol;
|
||||
constructor(gaurd, type, value, options = null) {
|
||||
if (gaurd !== _gaurd) {
|
||||
throw new Error("private constructor");
|
||||
}
|
||||
(0, properties_js_1.defineProperties)(this, { _typedSymbol, type, value });
|
||||
this.#options = options;
|
||||
// Check the value is valid
|
||||
this.format();
|
||||
}
|
||||
format() {
|
||||
if (this.type === "array") {
|
||||
throw new Error("");
|
||||
}
|
||||
else if (this.type === "dynamicArray") {
|
||||
throw new Error("");
|
||||
}
|
||||
else if (this.type === "tuple") {
|
||||
return `tuple(${this.value.map((v) => v.format()).join(",")})`;
|
||||
}
|
||||
return this.type;
|
||||
}
|
||||
defaultValue() {
|
||||
return 0;
|
||||
}
|
||||
minValue() {
|
||||
return 0;
|
||||
}
|
||||
maxValue() {
|
||||
return 0;
|
||||
}
|
||||
isBigInt() {
|
||||
return !!(this.type.match(/^u?int[0-9]+$/));
|
||||
}
|
||||
isData() {
|
||||
return (this.type.substring(0, 5) === "bytes");
|
||||
}
|
||||
isString() {
|
||||
return (this.type === "string");
|
||||
}
|
||||
get tupleName() {
|
||||
if (this.type !== "tuple") {
|
||||
throw TypeError("not a tuple");
|
||||
}
|
||||
return this.#options;
|
||||
}
|
||||
// Returns the length of this type as an array
|
||||
// - `null` indicates the length is unforced, it could be dynamic
|
||||
// - `-1` indicates the length is dynamic
|
||||
// - any other value indicates it is a static array and is its length
|
||||
get arrayLength() {
|
||||
if (this.type !== "array") {
|
||||
throw TypeError("not an array");
|
||||
}
|
||||
if (this.#options === true) {
|
||||
return -1;
|
||||
}
|
||||
if (this.#options === false) {
|
||||
return (this.value).length;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
static from(type, value) {
|
||||
return new Typed(_gaurd, type, value);
|
||||
}
|
||||
static uint8(v) { return n(v, 8); }
|
||||
static uint16(v) { return n(v, 16); }
|
||||
static uint24(v) { return n(v, 24); }
|
||||
static uint32(v) { return n(v, 32); }
|
||||
static uint40(v) { return n(v, 40); }
|
||||
static uint48(v) { return n(v, 46); }
|
||||
static uint56(v) { return n(v, 56); }
|
||||
static uint64(v) { return n(v, 64); }
|
||||
static uint72(v) { return n(v, 72); }
|
||||
static uint80(v) { return n(v, 80); }
|
||||
static uint88(v) { return n(v, 88); }
|
||||
static uint96(v) { return n(v, 96); }
|
||||
static uint104(v) { return n(v, 104); }
|
||||
static uint112(v) { return n(v, 112); }
|
||||
static uint120(v) { return n(v, 120); }
|
||||
static uint128(v) { return n(v, 128); }
|
||||
static uint136(v) { return n(v, 136); }
|
||||
static uint144(v) { return n(v, 144); }
|
||||
static uint152(v) { return n(v, 152); }
|
||||
static uint160(v) { return n(v, 160); }
|
||||
static uint168(v) { return n(v, 168); }
|
||||
static uint176(v) { return n(v, 176); }
|
||||
static uint184(v) { return n(v, 184); }
|
||||
static uint192(v) { return n(v, 192); }
|
||||
static uint200(v) { return n(v, 200); }
|
||||
static uint208(v) { return n(v, 208); }
|
||||
static uint216(v) { return n(v, 216); }
|
||||
static uint224(v) { return n(v, 224); }
|
||||
static uint232(v) { return n(v, 232); }
|
||||
static uint240(v) { return n(v, 240); }
|
||||
static uint248(v) { return n(v, 248); }
|
||||
static uint256(v) { return n(v, 256); }
|
||||
static uint(v) { return n(v, 256); }
|
||||
static int8(v) { return n(v, -8); }
|
||||
static int16(v) { return n(v, -16); }
|
||||
static int24(v) { return n(v, -24); }
|
||||
static int32(v) { return n(v, -32); }
|
||||
static int40(v) { return n(v, -40); }
|
||||
static int48(v) { return n(v, -46); }
|
||||
static int56(v) { return n(v, -56); }
|
||||
static int64(v) { return n(v, -64); }
|
||||
static int72(v) { return n(v, -72); }
|
||||
static int80(v) { return n(v, -80); }
|
||||
static int88(v) { return n(v, -88); }
|
||||
static int96(v) { return n(v, -96); }
|
||||
static int104(v) { return n(v, -104); }
|
||||
static int112(v) { return n(v, -112); }
|
||||
static int120(v) { return n(v, -120); }
|
||||
static int128(v) { return n(v, -128); }
|
||||
static int136(v) { return n(v, -136); }
|
||||
static int144(v) { return n(v, -144); }
|
||||
static int152(v) { return n(v, -152); }
|
||||
static int160(v) { return n(v, -160); }
|
||||
static int168(v) { return n(v, -168); }
|
||||
static int176(v) { return n(v, -176); }
|
||||
static int184(v) { return n(v, -184); }
|
||||
static int192(v) { return n(v, -192); }
|
||||
static int200(v) { return n(v, -200); }
|
||||
static int208(v) { return n(v, -208); }
|
||||
static int216(v) { return n(v, -216); }
|
||||
static int224(v) { return n(v, -224); }
|
||||
static int232(v) { return n(v, -232); }
|
||||
static int240(v) { return n(v, -240); }
|
||||
static int248(v) { return n(v, -248); }
|
||||
static int256(v) { return n(v, -256); }
|
||||
static int(v) { return n(v, -256); }
|
||||
static bytes(v) { return b(v); }
|
||||
static bytes1(v) { return b(v, 1); }
|
||||
static bytes2(v) { return b(v, 2); }
|
||||
static bytes3(v) { return b(v, 3); }
|
||||
static bytes4(v) { return b(v, 4); }
|
||||
static bytes5(v) { return b(v, 5); }
|
||||
static bytes6(v) { return b(v, 6); }
|
||||
static bytes7(v) { return b(v, 7); }
|
||||
static bytes8(v) { return b(v, 8); }
|
||||
static bytes9(v) { return b(v, 9); }
|
||||
static bytes10(v) { return b(v, 10); }
|
||||
static bytes11(v) { return b(v, 11); }
|
||||
static bytes12(v) { return b(v, 12); }
|
||||
static bytes13(v) { return b(v, 13); }
|
||||
static bytes14(v) { return b(v, 14); }
|
||||
static bytes15(v) { return b(v, 15); }
|
||||
static bytes16(v) { return b(v, 16); }
|
||||
static bytes17(v) { return b(v, 17); }
|
||||
static bytes18(v) { return b(v, 18); }
|
||||
static bytes19(v) { return b(v, 19); }
|
||||
static bytes20(v) { return b(v, 20); }
|
||||
static bytes21(v) { return b(v, 21); }
|
||||
static bytes22(v) { return b(v, 22); }
|
||||
static bytes23(v) { return b(v, 23); }
|
||||
static bytes24(v) { return b(v, 24); }
|
||||
static bytes25(v) { return b(v, 25); }
|
||||
static bytes26(v) { return b(v, 26); }
|
||||
static bytes27(v) { return b(v, 27); }
|
||||
static bytes28(v) { return b(v, 28); }
|
||||
static bytes29(v) { return b(v, 29); }
|
||||
static bytes30(v) { return b(v, 30); }
|
||||
static bytes31(v) { return b(v, 31); }
|
||||
static bytes32(v) { return b(v, 32); }
|
||||
static address(v) { return new Typed(_gaurd, "address", v); }
|
||||
static bool(v) { return new Typed(_gaurd, "bool", !!v); }
|
||||
static string(v) { return new Typed(_gaurd, "string", v); }
|
||||
static array(v, dynamic) {
|
||||
throw new Error("not implemented yet");
|
||||
return new Typed(_gaurd, "array", v, dynamic);
|
||||
}
|
||||
static tuple(v, name) {
|
||||
throw new Error("not implemented yet");
|
||||
return new Typed(_gaurd, "tuple", v, name);
|
||||
}
|
||||
static overrides(v) {
|
||||
return new Typed(_gaurd, "overrides", Object.assign({}, v));
|
||||
}
|
||||
static isTyped(value) {
|
||||
return (value && value._typedSymbol === _typedSymbol);
|
||||
}
|
||||
static dereference(value, type) {
|
||||
if (Typed.isTyped(value)) {
|
||||
if (value.type !== type) {
|
||||
throw new Error(`invalid type: expecetd ${type}, got ${value.type}`);
|
||||
}
|
||||
return value.value;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
exports.Typed = Typed;
|
||||
//# sourceMappingURL=typed.js.map
|
1
lib.commonjs/abi/typed.js.map
Normal file
1
lib.commonjs/abi/typed.js.map
Normal file
File diff suppressed because one or more lines are too long
114
lib.commonjs/address/address.js
Normal file
114
lib.commonjs/address/address.js
Normal file
@ -0,0 +1,114 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getIcapAddress = exports.getAddress = void 0;
|
||||
const keccak_js_1 = require("../crypto/keccak.js");
|
||||
const logger_js_1 = require("../utils/logger.js");
|
||||
const BN_0 = BigInt(0);
|
||||
const BN_36 = BigInt(36);
|
||||
function getChecksumAddress(address) {
|
||||
// if (!isHexString(address, 20)) {
|
||||
// logger.throwArgumentError("invalid address", "address", address);
|
||||
// }
|
||||
address = address.toLowerCase();
|
||||
const chars = address.substring(2).split("");
|
||||
const expanded = new Uint8Array(40);
|
||||
for (let i = 0; i < 40; i++) {
|
||||
expanded[i] = chars[i].charCodeAt(0);
|
||||
}
|
||||
const hashed = logger_js_1.logger.getBytes((0, keccak_js_1.keccak256)(expanded));
|
||||
for (let i = 0; i < 40; i += 2) {
|
||||
if ((hashed[i >> 1] >> 4) >= 8) {
|
||||
chars[i] = chars[i].toUpperCase();
|
||||
}
|
||||
if ((hashed[i >> 1] & 0x0f) >= 8) {
|
||||
chars[i + 1] = chars[i + 1].toUpperCase();
|
||||
}
|
||||
}
|
||||
return "0x" + chars.join("");
|
||||
}
|
||||
// See: https://en.wikipedia.org/wiki/International_Bank_Account_Number
|
||||
// Create lookup table
|
||||
const ibanLookup = {};
|
||||
for (let i = 0; i < 10; i++) {
|
||||
ibanLookup[String(i)] = String(i);
|
||||
}
|
||||
for (let i = 0; i < 26; i++) {
|
||||
ibanLookup[String.fromCharCode(65 + i)] = String(10 + i);
|
||||
}
|
||||
// How many decimal digits can we process? (for 64-bit float, this is 15)
|
||||
// i.e. Math.floor(Math.log10(Number.MAX_SAFE_INTEGER));
|
||||
const safeDigits = 15;
|
||||
function ibanChecksum(address) {
|
||||
address = address.toUpperCase();
|
||||
address = address.substring(4) + address.substring(0, 2) + "00";
|
||||
let expanded = address.split("").map((c) => { return ibanLookup[c]; }).join("");
|
||||
// Javascript can handle integers safely up to 15 (decimal) digits
|
||||
while (expanded.length >= safeDigits) {
|
||||
let block = expanded.substring(0, safeDigits);
|
||||
expanded = parseInt(block, 10) % 97 + expanded.substring(block.length);
|
||||
}
|
||||
let checksum = String(98 - (parseInt(expanded, 10) % 97));
|
||||
while (checksum.length < 2) {
|
||||
checksum = "0" + checksum;
|
||||
}
|
||||
return checksum;
|
||||
}
|
||||
;
|
||||
const Base36 = (function () {
|
||||
;
|
||||
const result = {};
|
||||
for (let i = 0; i < 36; i++) {
|
||||
const key = "0123456789abcdefghijklmnopqrstuvwxyz"[i];
|
||||
result[key] = BigInt(i);
|
||||
}
|
||||
return result;
|
||||
})();
|
||||
function fromBase36(value) {
|
||||
value = value.toLowerCase();
|
||||
let result = BN_0;
|
||||
for (let i = 0; i < value.length; i++) {
|
||||
result = result * BN_36 + Base36[value[i]];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function getAddress(address) {
|
||||
if (typeof (address) !== "string") {
|
||||
logger_js_1.logger.throwArgumentError("invalid address", "address", address);
|
||||
}
|
||||
if (address.match(/^(0x)?[0-9a-fA-F]{40}$/)) {
|
||||
// Missing the 0x prefix
|
||||
if (address.substring(0, 2) !== "0x") {
|
||||
address = "0x" + address;
|
||||
}
|
||||
const result = getChecksumAddress(address);
|
||||
// It is a checksummed address with a bad checksum
|
||||
if (address.match(/([A-F].*[a-f])|([a-f].*[A-F])/) && result !== address) {
|
||||
logger_js_1.logger.throwArgumentError("bad address checksum", "address", address);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
// Maybe ICAP? (we only support direct mode)
|
||||
if (address.match(/^XE[0-9]{2}[0-9A-Za-z]{30,31}$/)) {
|
||||
// It is an ICAP address with a bad checksum
|
||||
if (address.substring(2, 4) !== ibanChecksum(address)) {
|
||||
logger_js_1.logger.throwArgumentError("bad icap checksum", "address", address);
|
||||
}
|
||||
let result = fromBase36(address.substring(4)).toString(16);
|
||||
while (result.length < 40) {
|
||||
result = "0" + result;
|
||||
}
|
||||
return getChecksumAddress("0x" + result);
|
||||
}
|
||||
return logger_js_1.logger.throwArgumentError("invalid address", "address", address);
|
||||
}
|
||||
exports.getAddress = getAddress;
|
||||
function getIcapAddress(address) {
|
||||
//let base36 = _base16To36(getAddress(address).substring(2)).toUpperCase();
|
||||
let base36 = BigInt(getAddress(address)).toString(36).toUpperCase();
|
||||
while (base36.length < 30) {
|
||||
base36 = "0" + base36;
|
||||
}
|
||||
return "XE" + ibanChecksum("XE00" + base36) + base36;
|
||||
}
|
||||
exports.getIcapAddress = getIcapAddress;
|
||||
//# sourceMappingURL=address.js.map
|
1
lib.commonjs/address/address.js.map
Normal file
1
lib.commonjs/address/address.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"address.js","sourceRoot":"","sources":["../../src.ts/address/address.ts"],"names":[],"mappings":";;;AAAA,mDAAgD;AAChD,kDAA4C;AAG5C,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;AACvB,MAAM,KAAK,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;AAEzB,SAAS,kBAAkB,CAAC,OAAe;IAC3C,sCAAsC;IACtC,2EAA2E;IAC3E,OAAO;IAEH,OAAO,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAEhC,MAAM,KAAK,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAE7C,MAAM,QAAQ,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;IACpC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE;QACzB,QAAQ,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;KACxC;IAED,MAAM,MAAM,GAAG,kBAAM,CAAC,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E;QAED,IAAI,MAAM,GAAG,UAAU,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QAC3D,OAAO,MAAM,CAAC,MAAM,GAAG,EAAE,EAAE;YAAE,MAAM,GAAG,GAAG,GAAG,MAAM,CAAC;SAAE;QACrD,OAAQ,kBAAkB,CAAC,IAAI,GAAG,MAAM,CAAC,CAAC;KAC7C;IAED,OAAO,kBAAM,CAAC,kBAAkB,CAAC,iBAAiB,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;AAC5E,CAAC;AAlCD,gCAkCC;AAED,SAAgB,cAAc,CAAC,OAAe;IAC1C,2EAA2E;IAC3E,IAAI,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;IACpE,OAAO,MAAM,CAAC,MAAM,GAAG,EAAE,EAAE;QAAE,MAAM,GAAG,GAAG,GAAG,MAAM,CAAC;KAAE;IACrD,OAAO,IAAI,GAAG,YAAY,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,MAAM,CAAC;AACzD,CAAC;AALD,wCAKC"}
|
52
lib.commonjs/address/checks.js
Normal file
52
lib.commonjs/address/checks.js
Normal file
@ -0,0 +1,52 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.resolveAddress = exports.isAddress = exports.isAddressable = void 0;
|
||||
const logger_js_1 = require("../utils/logger.js");
|
||||
const address_js_1 = require("./address.js");
|
||||
function isAddressable(value) {
|
||||
return (value && typeof (value.getAddress) === "function");
|
||||
}
|
||||
exports.isAddressable = isAddressable;
|
||||
function isAddress(value) {
|
||||
try {
|
||||
(0, address_js_1.getAddress)(value);
|
||||
return true;
|
||||
}
|
||||
catch (error) { }
|
||||
return false;
|
||||
}
|
||||
exports.isAddress = isAddress;
|
||||
async function checkAddress(target, promise) {
|
||||
const result = await promise;
|
||||
if (result == null || result === "0x0000000000000000000000000000000000000000") {
|
||||
if (typeof (target) === "string") {
|
||||
return logger_js_1.logger.throwError("unconfigured name", "UNCONFIGURED_NAME", { value: target });
|
||||
}
|
||||
return logger_js_1.logger.throwArgumentError("invalid AddressLike value; did not resolve to a value address", "target", target);
|
||||
}
|
||||
return (0, address_js_1.getAddress)(result);
|
||||
}
|
||||
// Resolves an Ethereum address, ENS name or Addressable object,
|
||||
// throwing if the result is null.
|
||||
function resolveAddress(target, resolver) {
|
||||
if (typeof (target) === "string") {
|
||||
if (target.match(/^0x[0-9a-f]{40}$/i)) {
|
||||
return (0, address_js_1.getAddress)(target);
|
||||
}
|
||||
if (resolver == null) {
|
||||
return logger_js_1.logger.throwError("ENS resolution requires a provider", "UNSUPPORTED_OPERATION", {
|
||||
operation: "resolveName",
|
||||
});
|
||||
}
|
||||
return checkAddress(target, resolver.resolveName(target));
|
||||
}
|
||||
else if (isAddressable(target)) {
|
||||
return checkAddress(target, target.getAddress());
|
||||
}
|
||||
else if (typeof (target.then) === "function") {
|
||||
return checkAddress(target, target);
|
||||
}
|
||||
return logger_js_1.logger.throwArgumentError("unsupported addressable value", "target", target);
|
||||
}
|
||||
exports.resolveAddress = resolveAddress;
|
||||
//# sourceMappingURL=checks.js.map
|
1
lib.commonjs/address/checks.js.map
Normal file
1
lib.commonjs/address/checks.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"checks.js","sourceRoot":"","sources":["../../src.ts/address/checks.ts"],"names":[],"mappings":";;;AAAA,kDAA4C;AAE5C,6CAA0C;AAK1C,SAAgB,aAAa,CAAC,KAAU;IACpC,OAAO,CAAC,KAAK,IAAI,OAAM,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,UAAU,CAAC,CAAC;AAC9D,CAAC;AAFD,sCAEC;AAED,SAAgB,SAAS,CAAC,KAAU;IAChC,IAAI;QACA,IAAA,uBAAU,EAAC,KAAK,CAAC,CAAC;QAClB,OAAO,IAAI,C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AU,EAAE;QAC3C,OAAO,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KACvC;IAED,OAAO,kBAAM,CAAC,kBAAkB,CAAC,+BAA+B,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;AACxF,CAAC;AArBD,wCAqBC"}
|
37
lib.commonjs/address/contract-address.js
Normal file
37
lib.commonjs/address/contract-address.js
Normal file
@ -0,0 +1,37 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getCreate2Address = exports.getCreateAddress = void 0;
|
||||
const keccak_js_1 = require("../crypto/keccak.js");
|
||||
const index_js_1 = require("../utils/index.js");
|
||||
const address_js_1 = require("./address.js");
|
||||
// http://ethereum.stackexchange.com/questions/760/how-is-the-address-of-an-ethereum-contract-computed
|
||||
function getCreateAddress(tx) {
|
||||
const from = (0, address_js_1.getAddress)(tx.from);
|
||||
const nonce = index_js_1.logger.getBigInt(tx.nonce, "tx.nonce");
|
||||
let nonceHex = nonce.toString(16);
|
||||
if (nonceHex === "0") {
|
||||
nonceHex = "0x";
|
||||
}
|
||||
else if (nonceHex.length % 2) {
|
||||
nonceHex = "0x0" + nonceHex;
|
||||
}
|
||||
else {
|
||||
nonceHex = "0x" + nonceHex;
|
||||
}
|
||||
return (0, address_js_1.getAddress)((0, index_js_1.dataSlice)((0, keccak_js_1.keccak256)((0, index_js_1.encodeRlp)([from, nonceHex])), 12));
|
||||
}
|
||||
exports.getCreateAddress = getCreateAddress;
|
||||
function getCreate2Address(_from, _salt, _initCodeHash) {
|
||||
const from = (0, address_js_1.getAddress)(_from);
|
||||
const salt = index_js_1.logger.getBytes(_salt, "salt");
|
||||
const initCodeHash = index_js_1.logger.getBytes(_initCodeHash, "initCodeHash");
|
||||
if (salt.length !== 32) {
|
||||
index_js_1.logger.throwArgumentError("salt must be 32 bytes", "salt", _salt);
|
||||
}
|
||||
if (initCodeHash.length !== 32) {
|
||||
index_js_1.logger.throwArgumentError("initCodeHash must be 32 bytes", "initCodeHash", _initCodeHash);
|
||||
}
|
||||
return (0, address_js_1.getAddress)((0, index_js_1.dataSlice)((0, keccak_js_1.keccak256)((0, index_js_1.concat)(["0xff", from, salt, initCodeHash])), 12));
|
||||
}
|
||||
exports.getCreate2Address = getCreate2Address;
|
||||
//# sourceMappingURL=contract-address.js.map
|
1
lib.commonjs/address/contract-address.js.map
Normal file
1
lib.commonjs/address/contract-address.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"contract-address.js","sourceRoot":"","sources":["../../src.ts/address/contract-address.ts"],"names":[],"mappings":";;;AAAA,mDAAgD;AAChD,gDAAyE;AAEzE,6CAA0C;AAK1C,sGAAsG;AACtG,SAAgB,gBAAgB,CAAC,EAAyC;IACtE,MAAM,IAAI,GAAG,IAAA,uBAAU,EAAC,EAAE,CAAC,IAAI,CAAC,CAAC;IACjC,MAAM,KAAK,GAAG,iBAAM,CAAC,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;IAErD,IAAI,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IAClC,IAAI,QAAQ,KAAK,GAAG,EAAE;QAClB,QAAQ,GAAG,IAAI,CAAC;KACnB;SAAM,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE;QAC5B,QAAQ,GAAG,KAAK,GAAG,QAAQ,CAAC;KAC/B;SAAM;QACH,QAAQ,GAAG,IAAI,GAAG,QAAQ,CAAC;KAC9B;IAED,OAAO,IAAA,uBAAU,EAAC,IAAA,oBAAS,EAAC,IAAA,qBAAS,EAAC,IAAA,oBAAS,EAAC,CAAE,IAAI,EAAE,QAAQ,CAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AAC/E,CAAC;AAdD,4CAcC;AAED,SAAgB,iBAAiB,CAAC,KAAa,EAAE,KAAgB,EAAE,aAAwB;IACvF,MAAM,IAAI,GAAG,IAAA,uBAAU,EAAC,KAAK,CAAC,CAAC;IAC/B,MAAM,IAAI,GAAG,iBAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC5C,MAAM,YAAY,GAAG,iBAAM,CAAC,QAAQ,CAAC,aAAa,EAAE,cAAc,CAAC,CAAC;IAEpE,IAAI,IAAI,CAAC,MAAM,KAAK,EAAE,EAAE;QACpB,iBAAM,CAAC,kBAAkB,CAAC,uBAAuB,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;KACrE;IAED,IAAI,YAAY,CAAC,MAAM,KAAK,EAAE,EAAE;QAC5B,iBAAM,CAAC,kBAAkB,CAAC,+BAA+B,EAAE,cAAc,EAAE,aAAa,CAAC,CAAC;KAC7F;IAED,OAAO,IAAA,uBAAU,EAAC,IAAA,oBAAS,EAAC,IAAA,qBAAS,EAAC,IAAA,iBAAM,EAAC,CAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,YAAY,CAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;AAC7F,CAAC;AAdD,8CAcC"}
|
14
lib.commonjs/address/index.js
Normal file
14
lib.commonjs/address/index.js
Normal file
@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.resolveAddress = exports.isAddress = exports.isAddressable = exports.getCreate2Address = exports.getCreateAddress = exports.getIcapAddress = exports.getAddress = void 0;
|
||||
var address_js_1 = require("./address.js");
|
||||
Object.defineProperty(exports, "getAddress", { enumerable: true, get: function () { return address_js_1.getAddress; } });
|
||||
Object.defineProperty(exports, "getIcapAddress", { enumerable: true, get: function () { return address_js_1.getIcapAddress; } });
|
||||
var contract_address_js_1 = require("./contract-address.js");
|
||||
Object.defineProperty(exports, "getCreateAddress", { enumerable: true, get: function () { return contract_address_js_1.getCreateAddress; } });
|
||||
Object.defineProperty(exports, "getCreate2Address", { enumerable: true, get: function () { return contract_address_js_1.getCreate2Address; } });
|
||||
var checks_js_1 = require("./checks.js");
|
||||
Object.defineProperty(exports, "isAddressable", { enumerable: true, get: function () { return checks_js_1.isAddressable; } });
|
||||
Object.defineProperty(exports, "isAddress", { enumerable: true, get: function () { return checks_js_1.isAddress; } });
|
||||
Object.defineProperty(exports, "resolveAddress", { enumerable: true, get: function () { return checks_js_1.resolveAddress; } });
|
||||
//# sourceMappingURL=index.js.map
|
1
lib.commonjs/address/index.js.map
Normal file
1
lib.commonjs/address/index.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src.ts/address/index.ts"],"names":[],"mappings":";;;AAUA,2CAA0D;AAAjD,wGAAA,UAAU,OAAA;AAAE,4GAAA,cAAc,OAAA;AAEnC,6DAA4E;AAAnE,uHAAA,gBAAgB,OAAA;AAAE,wHAAA,iBAAiB,OAAA;AAG5C,yCAAuE;AAA9D,0GAAA,aAAa,OAAA;AAAE,sGAAA,SAAS,OAAA;AAAE,2GAAA,cAAc,OAAA"}
|
8
lib.commonjs/constants/addresses.js
Normal file
8
lib.commonjs/constants/addresses.js
Normal file
@ -0,0 +1,8 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ZeroAddress = void 0;
|
||||
/**
|
||||
* A constant for the zero address.
|
||||
*/
|
||||
exports.ZeroAddress = "0x0000000000000000000000000000000000000000";
|
||||
//# sourceMappingURL=addresses.js.map
|
1
lib.commonjs/constants/addresses.js.map
Normal file
1
lib.commonjs/constants/addresses.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"addresses.js","sourceRoot":"","sources":["../../src.ts/constants/addresses.ts"],"names":[],"mappings":";;;AACA;;GAEG;AACU,QAAA,WAAW,GAAG,4CAA4C,CAAC"}
|
8
lib.commonjs/constants/hashes.js
Normal file
8
lib.commonjs/constants/hashes.js
Normal file
@ -0,0 +1,8 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ZeroHash = void 0;
|
||||
/**
|
||||
* A constant for the zero hash.
|
||||
*/
|
||||
exports.ZeroHash = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
||||
//# sourceMappingURL=hashes.js.map
|
1
lib.commonjs/constants/hashes.js.map
Normal file
1
lib.commonjs/constants/hashes.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"hashes.js","sourceRoot":"","sources":["../../src.ts/constants/hashes.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,QAAA,QAAQ,GAAG,oEAAoE,CAAC"}
|
21
lib.commonjs/constants/index.js
Normal file
21
lib.commonjs/constants/index.js
Normal file
@ -0,0 +1,21 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.MessagePrefix = exports.EtherSymbol = exports.MaxInt256 = exports.MinInt256 = exports.MaxUint256 = exports.WeiPerEther = exports.N = exports.Two = exports.One = exports.Zero = exports.NegativeOne = exports.ZeroHash = exports.ZeroAddress = void 0;
|
||||
var addresses_js_1 = require("./addresses.js");
|
||||
Object.defineProperty(exports, "ZeroAddress", { enumerable: true, get: function () { return addresses_js_1.ZeroAddress; } });
|
||||
var hashes_js_1 = require("./hashes.js");
|
||||
Object.defineProperty(exports, "ZeroHash", { enumerable: true, get: function () { return hashes_js_1.ZeroHash; } });
|
||||
var numbers_js_1 = require("./numbers.js");
|
||||
Object.defineProperty(exports, "NegativeOne", { enumerable: true, get: function () { return numbers_js_1.NegativeOne; } });
|
||||
Object.defineProperty(exports, "Zero", { enumerable: true, get: function () { return numbers_js_1.Zero; } });
|
||||
Object.defineProperty(exports, "One", { enumerable: true, get: function () { return numbers_js_1.One; } });
|
||||
Object.defineProperty(exports, "Two", { enumerable: true, get: function () { return numbers_js_1.Two; } });
|
||||
Object.defineProperty(exports, "N", { enumerable: true, get: function () { return numbers_js_1.N; } });
|
||||
Object.defineProperty(exports, "WeiPerEther", { enumerable: true, get: function () { return numbers_js_1.WeiPerEther; } });
|
||||
Object.defineProperty(exports, "MaxUint256", { enumerable: true, get: function () { return numbers_js_1.MaxUint256; } });
|
||||
Object.defineProperty(exports, "MinInt256", { enumerable: true, get: function () { return numbers_js_1.MinInt256; } });
|
||||
Object.defineProperty(exports, "MaxInt256", { enumerable: true, get: function () { return numbers_js_1.MaxInt256; } });
|
||||
var strings_js_1 = require("./strings.js");
|
||||
Object.defineProperty(exports, "EtherSymbol", { enumerable: true, get: function () { return strings_js_1.EtherSymbol; } });
|
||||
Object.defineProperty(exports, "MessagePrefix", { enumerable: true, get: function () { return strings_js_1.MessagePrefix; } });
|
||||
//# sourceMappingURL=index.js.map
|
1
lib.commonjs/constants/index.js.map
Normal file
1
lib.commonjs/constants/index.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src.ts/constants/index.ts"],"names":[],"mappings":";;;AAAA,+CAA6C;AAApC,2GAAA,WAAW,OAAA;AACpB,yCAAuC;AAA9B,qGAAA,QAAQ,OAAA;AACjB,2CAUsB;AATlB,yGAAA,WAAW,OAAA;AACX,kGAAA,IAAI,OAAA;AACJ,iGAAA,GAAG,OAAA;AACH,iGAAA,GAAG,OAAA;AACH,+FAAA,CAAC,OAAA;AACD,yGAAA,WAAW,OAAA;AACX,wGAAA,UAAU,OAAA;AACV,uGAAA,SAAS,OAAA;AACT,uGAAA,SAAS,OAAA;AAEb,2CAA0D;AAAjD,yGAAA,WAAW,OAAA;AAAE,2GAAA,aAAa,OAAA"}
|
49
lib.commonjs/constants/numbers.js
Normal file
49
lib.commonjs/constants/numbers.js
Normal file
@ -0,0 +1,49 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.MaxInt256 = exports.MinInt256 = exports.MaxUint256 = exports.WeiPerEther = exports.N = exports.Two = exports.One = exports.Zero = exports.NegativeOne = void 0;
|
||||
/**
|
||||
* A constant for the BigInt of -1.
|
||||
*/
|
||||
const NegativeOne = BigInt(-1);
|
||||
exports.NegativeOne = NegativeOne;
|
||||
/**
|
||||
* A constant for the BigInt of 0.
|
||||
*/
|
||||
const Zero = BigInt(0);
|
||||
exports.Zero = Zero;
|
||||
/**
|
||||
* A constant for the BigInt of 1.
|
||||
*/
|
||||
const One = BigInt(1);
|
||||
exports.One = One;
|
||||
/**
|
||||
* A constant for the BigInt of 2.
|
||||
*/
|
||||
const Two = BigInt(2);
|
||||
exports.Two = Two;
|
||||
/**
|
||||
* A constant for the order N for the secp256k1 curve.
|
||||
*/
|
||||
const N = BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141");
|
||||
exports.N = N;
|
||||
/**
|
||||
* A constant for the number of wei in a single ether.
|
||||
*/
|
||||
const WeiPerEther = BigInt("1000000000000000000");
|
||||
exports.WeiPerEther = WeiPerEther;
|
||||
/**
|
||||
* A constant for the maximum value for a ``uint256``.
|
||||
*/
|
||||
const MaxUint256 = BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
|
||||
exports.MaxUint256 = MaxUint256;
|
||||
/**
|
||||
* A constant for the minimum value for an ``int256``.
|
||||
*/
|
||||
const MinInt256 = BigInt("0x8000000000000000000000000000000000000000000000000000000000000000") * NegativeOne;
|
||||
exports.MinInt256 = MinInt256;
|
||||
/**
|
||||
* A constant for the maximum value for an ``int256``.
|
||||
*/
|
||||
const MaxInt256 = BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
|
||||
exports.MaxInt256 = MaxInt256;
|
||||
//# sourceMappingURL=numbers.js.map
|
1
lib.commonjs/constants/numbers.js.map
Normal file
1
lib.commonjs/constants/numbers.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"numbers.js","sourceRoot":"","sources":["../../src.ts/constants/numbers.ts"],"names":[],"mappings":";;;AACA;;GAEG;AACH,MAAM,WAAW,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AA2C3B,kCAAW;AAzCf;;GAEG;AACH,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;AAuCnB,oBAAI;AArCR;;GAEG;AACH,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;AAmClB,kBAAG;AAjCP;;GAEG;AACH,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;AA+BlB,kBAAG;AA7BP;;GAEG;AACH,MAAM,CAAC,GAAG,MAAM,CAAC,oEAAoE,CAAC,CAAC;AA2BnF,cAAC;AAzBL;;GAEG;AACH,MAAM,WAAW,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;AAuB9C,kCAAW;AArBf;;GAEG;AACH,MAAM,UAAU,GAAG,MAAM,CAAC,oEAAoE,CAAC,CAAC;AAmB5F,gCAAU;AAjBd;;GAEG;AACH,MAAM,SAAS,GAAG,MAAM,CAAC,oEAAoE,CAAC,GAAG,WAAW,CAAC;AAezG,8BAAS;AAbb;;GAEG;AACH,MAAM,SAAS,GAAG,MAAM,CAAC,oEAAoE,CAAC,CAAC;AAW3F,8BAAS"}
|
10
lib.commonjs/constants/strings.js
Normal file
10
lib.commonjs/constants/strings.js
Normal file
@ -0,0 +1,10 @@
|
||||
"use strict";
|
||||
// NFKC (composed) // (decomposed)
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.MessagePrefix = exports.EtherSymbol = void 0;
|
||||
/**
|
||||
* A constant for the ether symbol (normalized using NFKC).
|
||||
*/
|
||||
exports.EtherSymbol = "\u039e"; // "\uD835\uDF63";
|
||||
exports.MessagePrefix = "\x19Ethereum Signed Message:\n";
|
||||
//# sourceMappingURL=strings.js.map
|
1
lib.commonjs/constants/strings.js.map
Normal file
1
lib.commonjs/constants/strings.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"strings.js","sourceRoot":"","sources":["../../src.ts/constants/strings.ts"],"names":[],"mappings":";AAAA,8CAA8C;;;AAE9C;;GAEG;AACU,QAAA,WAAW,GAAG,QAAQ,CAAC,CAAE,kBAAkB;AAG3C,QAAA,aAAa,GAAG,gCAAgC,CAAC"}
|
649
lib.commonjs/contract/contract.js
Normal file
649
lib.commonjs/contract/contract.js
Normal file
@ -0,0 +1,649 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Contract = exports.BaseContract = exports.resolveArgs = exports.copyOverrides = void 0;
|
||||
const index_js_1 = require("../address/index.js");
|
||||
const index_js_2 = require("../abi/index.js");
|
||||
const index_js_3 = require("../utils/index.js");
|
||||
const index_js_4 = require("../providers/index.js");
|
||||
const wrappers_js_1 = require("./wrappers.js");
|
||||
function canCall(value) {
|
||||
return (value && typeof (value.call) === "function");
|
||||
}
|
||||
function canEstimate(value) {
|
||||
return (value && typeof (value.estimateGas) === "function");
|
||||
}
|
||||
function canResolve(value) {
|
||||
return (value && typeof (value.resolveName) === "function");
|
||||
}
|
||||
function canSend(value) {
|
||||
return (value && typeof (value.sendTransaction) === "function");
|
||||
}
|
||||
function concisify(items) {
|
||||
items = Array.from((new Set(items)).values());
|
||||
items.sort();
|
||||
return items;
|
||||
}
|
||||
class PreparedTopicFilter {
|
||||
#filter;
|
||||
fragment;
|
||||
constructor(contract, fragment, args) {
|
||||
(0, index_js_3.defineProperties)(this, { fragment });
|
||||
if (fragment.inputs.length < args.length) {
|
||||
throw new Error("too many arguments");
|
||||
}
|
||||
// Recursively descend into args and resolve any addresses
|
||||
const runner = getRunner(contract.runner, "resolveName");
|
||||
const resolver = canResolve(runner) ? runner : null;
|
||||
this.#filter = (async function () {
|
||||
const resolvedArgs = await Promise.all(fragment.inputs.map((param, index) => {
|
||||
return param.walkAsync(args[index], (type, value) => {
|
||||
if (type === "address") {
|
||||
return (0, index_js_1.resolveAddress)(value, resolver);
|
||||
}
|
||||
return value;
|
||||
});
|
||||
}));
|
||||
return contract.interface.encodeFilterTopics(fragment, resolvedArgs);
|
||||
})();
|
||||
}
|
||||
getTopicFilter() {
|
||||
return this.#filter;
|
||||
}
|
||||
}
|
||||
// A = Arguments passed in as a tuple
|
||||
// R = The result type of the call (i.e. if only one return type,
|
||||
// the qualified type, otherwise Result)
|
||||
// D = The type the default call will return (i.e. R for view/pure,
|
||||
// TransactionResponse otherwise)
|
||||
//export interface ContractMethod<A extends Array<any> = Array<any>, R = any, D extends R | ContractTransactionResponse = ContractTransactionResponse> {
|
||||
function _WrappedMethodBase() {
|
||||
return Function;
|
||||
}
|
||||
function getRunner(value, feature) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
if (typeof (value[feature]) === "function") {
|
||||
return value;
|
||||
}
|
||||
if (value.provider && typeof (value.provider[feature]) === "function") {
|
||||
return value.provider;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function getProvider(value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
return value.provider || null;
|
||||
}
|
||||
async function copyOverrides(arg) {
|
||||
// Create a shallow copy (we'll deep-ify anything needed during normalizing)
|
||||
const overrides = (0, index_js_4.copyRequest)(index_js_2.Typed.dereference(arg, "overrides"));
|
||||
// Some sanity checking; these are what these methods adds
|
||||
//if ((<any>overrides).to) {
|
||||
if (overrides.to) {
|
||||
index_js_3.logger.throwArgumentError("cannot override to", "overrides.to", overrides.to);
|
||||
}
|
||||
else if (overrides.data) {
|
||||
index_js_3.logger.throwArgumentError("cannot override data", "overrides.data", overrides.data);
|
||||
}
|
||||
// Resolve any from
|
||||
if (overrides.from) {
|
||||
overrides.from = await (0, index_js_1.resolveAddress)(overrides.from);
|
||||
}
|
||||
return overrides;
|
||||
}
|
||||
exports.copyOverrides = copyOverrides;
|
||||
async function resolveArgs(_runner, inputs, args) {
|
||||
// Recursively descend into args and resolve any addresses
|
||||
const runner = getRunner(_runner, "resolveName");
|
||||
const resolver = canResolve(runner) ? runner : null;
|
||||
return await Promise.all(inputs.map((param, index) => {
|
||||
return param.walkAsync(args[index], (type, value) => {
|
||||
if (type === "address") {
|
||||
return (0, index_js_1.resolveAddress)(value, resolver);
|
||||
}
|
||||
return value;
|
||||
});
|
||||
}));
|
||||
}
|
||||
exports.resolveArgs = resolveArgs;
|
||||
class WrappedMethod extends _WrappedMethodBase() {
|
||||
name = ""; // Investigate!
|
||||
_contract;
|
||||
_key;
|
||||
constructor(contract, key) {
|
||||
super();
|
||||
(0, index_js_3.defineProperties)(this, {
|
||||
name: contract.interface.getFunctionName(key),
|
||||
_contract: contract, _key: key
|
||||
});
|
||||
const proxy = new Proxy(this, {
|
||||
// Perform the default operation for this fragment type
|
||||
apply: async (target, thisArg, args) => {
|
||||
const fragment = target.getFragment(...args);
|
||||
if (fragment.constant) {
|
||||
return await target.staticCall(...args);
|
||||
}
|
||||
return await target.send(...args);
|
||||
},
|
||||
});
|
||||
return proxy;
|
||||
}
|
||||
// Only works on non-ambiguous keys (refined fragment is always non-ambiguous)
|
||||
get fragment() {
|
||||
return this._contract.interface.getFunction(this._key);
|
||||
}
|
||||
getFragment(...args) {
|
||||
return this._contract.interface.getFunction(this._key, args);
|
||||
}
|
||||
async populateTransaction(...args) {
|
||||
const fragment = this.getFragment(...args);
|
||||
// If an overrides was passed in, copy it and normalize the values
|
||||
let overrides = {};
|
||||
if (fragment.inputs.length + 1 === args.length) {
|
||||
overrides = await copyOverrides(args.pop());
|
||||
}
|
||||
if (fragment.inputs.length !== args.length) {
|
||||
throw new Error("internal error: fragment inputs doesn't match arguments; should not happen");
|
||||
}
|
||||
const resolvedArgs = await resolveArgs(this._contract.runner, fragment.inputs, args);
|
||||
return Object.assign({}, overrides, await (0, index_js_3.resolveProperties)({
|
||||
to: this._contract.getAddress(),
|
||||
data: this._contract.interface.encodeFunctionData(fragment, resolvedArgs)
|
||||
}));
|
||||
}
|
||||
async staticCall(...args) {
|
||||
const result = await this.staticCallResult(...args);
|
||||
if (result.length === 1) {
|
||||
return result[0];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
async send(...args) {
|
||||
const runner = this._contract.runner;
|
||||
if (!canSend(runner)) {
|
||||
return index_js_3.logger.throwError("contract runner does not support sending transactions", "UNSUPPORTED_OPERATION", {
|
||||
operation: "sendTransaction"
|
||||
});
|
||||
}
|
||||
const tx = await runner.sendTransaction(await this.populateTransaction(...args));
|
||||
const provider = getProvider(this._contract.runner);
|
||||
return new wrappers_js_1.ContractTransactionResponse(this._contract.interface, provider, tx);
|
||||
}
|
||||
async estimateGas(...args) {
|
||||
const runner = getRunner(this._contract.runner, "estimateGas");
|
||||
if (!canEstimate(runner)) {
|
||||
return index_js_3.logger.throwError("contract runner does not support gas estimation", "UNSUPPORTED_OPERATION", {
|
||||
operation: "estimateGas"
|
||||
});
|
||||
}
|
||||
return await runner.estimateGas(await this.populateTransaction(...args));
|
||||
}
|
||||
async staticCallResult(...args) {
|
||||
const runner = getRunner(this._contract.runner, "call");
|
||||
if (!canCall(runner)) {
|
||||
return index_js_3.logger.throwError("contract runner does not support calling", "UNSUPPORTED_OPERATION", {
|
||||
operation: "call"
|
||||
});
|
||||
}
|
||||
const fragment = this.getFragment(...args);
|
||||
const tx = await this.populateTransaction(...args);
|
||||
let result = "0x";
|
||||
try {
|
||||
result = await runner.call(tx);
|
||||
}
|
||||
catch (error) {
|
||||
if ((0, index_js_3.isCallException)(error)) {
|
||||
throw this._contract.interface.makeError(fragment, error.data, tx);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
return this._contract.interface.decodeFunctionResult(fragment, result);
|
||||
}
|
||||
}
|
||||
function _WrappedEventBase() {
|
||||
return Function;
|
||||
}
|
||||
class WrappedEvent extends _WrappedEventBase() {
|
||||
name = ""; // @TODO: investigate
|
||||
_contract;
|
||||
_key;
|
||||
constructor(contract, key) {
|
||||
super();
|
||||
(0, index_js_3.defineProperties)(this, {
|
||||
name: contract.interface.getEventName(key),
|
||||
_contract: contract, _key: key
|
||||
});
|
||||
return new Proxy(this, {
|
||||
// Perform the default operation for this fragment type
|
||||
apply: async (target, thisArg, args) => {
|
||||
return new PreparedTopicFilter(contract, target.getFragment(...args), args);
|
||||
},
|
||||
});
|
||||
}
|
||||
// Only works on non-ambiguous keys
|
||||
get fragment() {
|
||||
return this._contract.interface.getEvent(this._key);
|
||||
}
|
||||
getFragment(...args) {
|
||||
return this._contract.interface.getEvent(this._key, args);
|
||||
}
|
||||
}
|
||||
;
|
||||
// The combination of TypeScrype, Private Fields and Proxies makes
|
||||
// the world go boom; so we hide variables with some trickery keeping
|
||||
// a symbol attached to each BaseContract which its sub-class (even
|
||||
// via a Proxy) can reach and use to look up its internal values.
|
||||
const internal = Symbol.for("_ethersInternal_contract");
|
||||
const internalValues = new WeakMap();
|
||||
function setInternal(contract, values) {
|
||||
internalValues.set(contract[internal], values);
|
||||
}
|
||||
function getInternal(contract) {
|
||||
return internalValues.get(contract[internal]);
|
||||
}
|
||||
function isDeferred(value) {
|
||||
return (value && typeof (value) === "object" && ("getTopicFilter" in value) &&
|
||||
(typeof (value.getTopicFilter) === "function") && value.fragment);
|
||||
}
|
||||
async function getSubTag(contract, event) {
|
||||
let fragment;
|
||||
let topics;
|
||||
if (Array.isArray(event)) {
|
||||
// Topics; e.g. `[ "0x1234...89ab" ]`
|
||||
fragment = contract.interface.getEvent(event[0]);
|
||||
topics = event;
|
||||
}
|
||||
else if (typeof (event) === "string") {
|
||||
// Event name (name or signature); `"Transfer"`
|
||||
fragment = contract.interface.getEvent(event);
|
||||
topics = [contract.interface.getEventTopic(fragment)];
|
||||
}
|
||||
else if (isDeferred(event)) {
|
||||
// Deferred Topic Filter; e.g. `contract.filter.Transfer(from)`
|
||||
fragment = event.fragment;
|
||||
topics = await event.getTopicFilter();
|
||||
}
|
||||
else if ("fragment" in event) {
|
||||
// ContractEvent; e.g. `contract.filter.Transfer`
|
||||
fragment = event.fragment;
|
||||
topics = [contract.interface.getEventTopic(fragment)];
|
||||
}
|
||||
else {
|
||||
console.log(event);
|
||||
throw new Error("TODO");
|
||||
}
|
||||
// Normalize topics and sort TopicSets
|
||||
topics = topics.map((t) => {
|
||||
if (t == null) {
|
||||
return null;
|
||||
}
|
||||
if (Array.isArray(t)) {
|
||||
return concisify(t.map((t) => t.toLowerCase()));
|
||||
}
|
||||
return t.toLowerCase();
|
||||
});
|
||||
const tag = topics.map((t) => {
|
||||
if (t == null) {
|
||||
return "null";
|
||||
}
|
||||
if (Array.isArray(t)) {
|
||||
return t.join("|");
|
||||
}
|
||||
return t;
|
||||
}).join("&");
|
||||
return { fragment, tag, topics };
|
||||
}
|
||||
async function hasSub(contract, event) {
|
||||
const { subs } = getInternal(contract);
|
||||
return subs.get((await getSubTag(contract, event)).tag) || null;
|
||||
}
|
||||
async function getSub(contract, event) {
|
||||
// Make sure our runner can actually subscribe to events
|
||||
const provider = getProvider(contract.runner);
|
||||
if (!provider) {
|
||||
return index_js_3.logger.throwError("contract runner does not support subscribing", "UNSUPPORTED_OPERATION", {
|
||||
operation: "on"
|
||||
});
|
||||
}
|
||||
const { fragment, tag, topics } = await getSubTag(contract, event);
|
||||
const { addr, subs } = getInternal(contract);
|
||||
let sub = subs.get(tag);
|
||||
if (!sub) {
|
||||
const address = (addr ? addr : contract);
|
||||
const filter = { address, topics };
|
||||
const listener = (log) => {
|
||||
const payload = new wrappers_js_1.ContractEventPayload(contract, null, event, fragment, log);
|
||||
emit(contract, event, payload.args, payload);
|
||||
};
|
||||
let started = false;
|
||||
const start = () => {
|
||||
if (started) {
|
||||
return;
|
||||
}
|
||||
provider.on(filter, listener);
|
||||
started = true;
|
||||
};
|
||||
const stop = () => {
|
||||
if (!started) {
|
||||
return;
|
||||
}
|
||||
provider.off(filter, listener);
|
||||
started = false;
|
||||
};
|
||||
sub = { tag, listeners: [], start, stop };
|
||||
subs.set(tag, sub);
|
||||
}
|
||||
return sub;
|
||||
}
|
||||
// We use this to ensure one emit resolves before firing the next to
|
||||
// ensure correct ordering (note this cannot throw and just adds the
|
||||
// notice to the event queu using setTimeout).
|
||||
let lastEmit = Promise.resolve();
|
||||
async function _emit(contract, event, args, payload) {
|
||||
await lastEmit;
|
||||
const sub = await hasSub(contract, event);
|
||||
if (!sub) {
|
||||
return false;
|
||||
}
|
||||
const count = sub.listeners.length;
|
||||
sub.listeners = sub.listeners.filter(({ listener, once }) => {
|
||||
const passArgs = args.slice();
|
||||
if (payload) {
|
||||
passArgs.push(new wrappers_js_1.ContractEventPayload(contract, (once ? null : listener), event, payload.fragment, payload.log));
|
||||
}
|
||||
try {
|
||||
listener.call(contract, ...passArgs);
|
||||
}
|
||||
catch (error) { }
|
||||
return !once;
|
||||
});
|
||||
return (count > 0);
|
||||
}
|
||||
async function emit(contract, event, args, payload) {
|
||||
try {
|
||||
await lastEmit;
|
||||
}
|
||||
catch (error) { }
|
||||
const resultPromise = _emit(contract, event, args, payload);
|
||||
lastEmit = resultPromise;
|
||||
return await resultPromise;
|
||||
}
|
||||
const passProperties = ["then"];
|
||||
class BaseContract {
|
||||
target;
|
||||
interface;
|
||||
runner;
|
||||
filters;
|
||||
[internal];
|
||||
constructor(target, abi, runner = null, _deployTx) {
|
||||
const iface = index_js_2.Interface.from(abi);
|
||||
(0, index_js_3.defineProperties)(this, { target, runner, interface: iface });
|
||||
Object.defineProperty(this, internal, { value: {} });
|
||||
let addrPromise;
|
||||
let addr = null;
|
||||
let deployTx = null;
|
||||
if (_deployTx) {
|
||||
const provider = getProvider(runner);
|
||||
deployTx = new wrappers_js_1.ContractTransactionResponse(this.interface, provider, _deployTx);
|
||||
}
|
||||
let subs = new Map();
|
||||
// Resolve the target as the address
|
||||
if (typeof (target) === "string") {
|
||||
if ((0, index_js_3.isHexString)(target)) {
|
||||
addr = target;
|
||||
addrPromise = Promise.resolve(target);
|
||||
}
|
||||
else {
|
||||
const resolver = getRunner(runner, "resolveName");
|
||||
if (!canResolve(resolver)) {
|
||||
throw index_js_3.logger.makeError("contract runner does not support name resolution", "UNSUPPORTED_OPERATION", {
|
||||
operation: "resolveName"
|
||||
});
|
||||
}
|
||||
addrPromise = resolver.resolveName(target).then((addr) => {
|
||||
if (addr == null) {
|
||||
throw new Error("TODO");
|
||||
}
|
||||
getInternal(this).addr = addr;
|
||||
return addr;
|
||||
});
|
||||
}
|
||||
}
|
||||
else {
|
||||
addrPromise = target.getAddress().then((addr) => {
|
||||
if (addr == null) {
|
||||
throw new Error("TODO");
|
||||
}
|
||||
getInternal(this).addr = addr;
|
||||
return addr;
|
||||
});
|
||||
}
|
||||
// Set our private values
|
||||
setInternal(this, { addrPromise, addr, deployTx, subs });
|
||||
// Add the event filters
|
||||
const filters = new Proxy({}, {
|
||||
get: (target, _prop, receiver) => {
|
||||
// Pass important checks (like `then` for Promise) through
|
||||
if (passProperties.indexOf(_prop) >= 0) {
|
||||
return Reflect.get(target, _prop, receiver);
|
||||
}
|
||||
const prop = String(_prop);
|
||||
const result = this.getEvent(prop);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
throw new Error(`unknown contract event: ${prop}`);
|
||||
}
|
||||
});
|
||||
(0, index_js_3.defineProperties)(this, { filters });
|
||||
// Return a Proxy that will respond to functions
|
||||
return new Proxy(this, {
|
||||
get: (target, _prop, receiver) => {
|
||||
if (_prop in target || passProperties.indexOf(_prop) >= 0) {
|
||||
return Reflect.get(target, _prop, receiver);
|
||||
}
|
||||
const prop = String(_prop);
|
||||
const result = target.getFunction(prop);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
throw new Error(`unknown contract method: ${prop}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
async getAddress() { return await getInternal(this).addrPromise; }
|
||||
async getDeployedCode() {
|
||||
const provider = getProvider(this.runner);
|
||||
if (!provider) {
|
||||
return index_js_3.logger.throwError("runner does not support .provider", "UNSUPPORTED_OPERATION", {
|
||||
operation: "getDeployedCode"
|
||||
});
|
||||
}
|
||||
const code = await provider.getCode(await this.getAddress());
|
||||
if (code === "0x") {
|
||||
return null;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
async waitForDeployment() {
|
||||
// We have the deployement transaction; just use that (throws if deployement fails)
|
||||
const deployTx = this.deploymentTransaction();
|
||||
if (deployTx) {
|
||||
await deployTx.wait();
|
||||
return this;
|
||||
}
|
||||
// Check for code
|
||||
const code = await this.getDeployedCode();
|
||||
if (code != null) {
|
||||
return this;
|
||||
}
|
||||
// Make sure we can subscribe to a provider event
|
||||
const provider = getProvider(this.runner);
|
||||
if (provider == null) {
|
||||
return index_js_3.logger.throwError("contract runner does not support .provider", "UNSUPPORTED_OPERATION", {
|
||||
operation: "waitForDeployment"
|
||||
});
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
const checkCode = async () => {
|
||||
try {
|
||||
const code = await this.getDeployedCode();
|
||||
if (code != null) {
|
||||
return resolve(this);
|
||||
}
|
||||
provider.once("block", checkCode);
|
||||
}
|
||||
catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
};
|
||||
checkCode();
|
||||
});
|
||||
}
|
||||
deploymentTransaction() {
|
||||
return getInternal(this).deployTx;
|
||||
}
|
||||
getFunction(key) {
|
||||
if (typeof (key) !== "string") {
|
||||
key = key.format();
|
||||
}
|
||||
return (new WrappedMethod(this, key));
|
||||
}
|
||||
getEvent(key) {
|
||||
if (typeof (key) !== "string") {
|
||||
key = key.format();
|
||||
}
|
||||
return (new WrappedEvent(this, key));
|
||||
}
|
||||
async queryTransaction(hash) {
|
||||
// Is this useful?
|
||||
throw new Error("@TODO");
|
||||
}
|
||||
async queryFilter(event, fromBlock = 0, toBlock = "latest") {
|
||||
const { addr, addrPromise } = getInternal(this);
|
||||
const address = (addr ? addr : (await addrPromise));
|
||||
const { fragment, topics } = await getSubTag(this, event);
|
||||
const filter = { address, topics, fromBlock, toBlock };
|
||||
const provider = getProvider(this.runner);
|
||||
if (!provider) {
|
||||
return index_js_3.logger.throwError("contract runner does not have a provider", "UNSUPPORTED_OPERATION", {
|
||||
operation: "queryFilter"
|
||||
});
|
||||
}
|
||||
return (await provider.getLogs(filter)).map((log) => {
|
||||
return new wrappers_js_1.EventLog(log, this.interface, fragment);
|
||||
});
|
||||
}
|
||||
async on(event, listener) {
|
||||
const sub = await getSub(this, event);
|
||||
sub.listeners.push({ listener, once: false });
|
||||
sub.start();
|
||||
return this;
|
||||
}
|
||||
async once(event, listener) {
|
||||
const sub = await getSub(this, event);
|
||||
sub.listeners.push({ listener, once: true });
|
||||
sub.start();
|
||||
return this;
|
||||
}
|
||||
async emit(event, ...args) {
|
||||
return await emit(this, event, args, null);
|
||||
}
|
||||
async listenerCount(event) {
|
||||
if (event) {
|
||||
const sub = await hasSub(this, event);
|
||||
if (!sub) {
|
||||
return 0;
|
||||
}
|
||||
return sub.listeners.length;
|
||||
}
|
||||
const { subs } = getInternal(this);
|
||||
let total = 0;
|
||||
for (const { listeners } of subs.values()) {
|
||||
total += listeners.length;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
async listeners(event) {
|
||||
if (event) {
|
||||
const sub = await hasSub(this, event);
|
||||
if (!sub) {
|
||||
return [];
|
||||
}
|
||||
return sub.listeners.map(({ listener }) => listener);
|
||||
}
|
||||
const { subs } = getInternal(this);
|
||||
let result = [];
|
||||
for (const { listeners } of subs.values()) {
|
||||
result = result.concat(listeners.map(({ listener }) => listener));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
async off(event, listener) {
|
||||
const sub = await hasSub(this, event);
|
||||
if (!sub) {
|
||||
return this;
|
||||
}
|
||||
if (listener) {
|
||||
const index = sub.listeners.map(({ listener }) => listener).indexOf(listener);
|
||||
if (index >= 0) {
|
||||
sub.listeners.splice(index, 1);
|
||||
}
|
||||
}
|
||||
if (listener == null || sub.listeners.length === 0) {
|
||||
sub.stop();
|
||||
getInternal(this).subs.delete(sub.tag);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
async removeAllListeners(event) {
|
||||
if (event) {
|
||||
const sub = await hasSub(this, event);
|
||||
if (!sub) {
|
||||
return this;
|
||||
}
|
||||
sub.stop();
|
||||
getInternal(this).subs.delete(sub.tag);
|
||||
}
|
||||
else {
|
||||
const { subs } = getInternal(this);
|
||||
for (const { tag, stop } of subs.values()) {
|
||||
stop();
|
||||
subs.delete(tag);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
// Alias for "on"
|
||||
async addListener(event, listener) {
|
||||
return await this.on(event, listener);
|
||||
}
|
||||
// Alias for "off"
|
||||
async removeListener(event, listener) {
|
||||
return await this.off(event, listener);
|
||||
}
|
||||
static buildClass(abi) {
|
||||
class CustomContract extends BaseContract {
|
||||
constructor(address, runner = null) {
|
||||
super(address, abi, runner);
|
||||
}
|
||||
}
|
||||
return CustomContract;
|
||||
}
|
||||
;
|
||||
static from(target, abi, runner = null) {
|
||||
const contract = new this(target, abi, runner);
|
||||
return contract;
|
||||
}
|
||||
}
|
||||
exports.BaseContract = BaseContract;
|
||||
function _ContractBase() {
|
||||
return BaseContract;
|
||||
}
|
||||
class Contract extends _ContractBase() {
|
||||
}
|
||||
exports.Contract = Contract;
|
||||
//# sourceMappingURL=contract.js.map
|
1
lib.commonjs/contract/contract.js.map
Normal file
1
lib.commonjs/contract/contract.js.map
Normal file
File diff suppressed because one or more lines are too long
79
lib.commonjs/contract/factory.js
Normal file
79
lib.commonjs/contract/factory.js
Normal file
@ -0,0 +1,79 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ContractFactory = void 0;
|
||||
const index_js_1 = require("../abi/index.js");
|
||||
const index_js_2 = require("../address/index.js");
|
||||
const index_js_3 = require("../utils/index.js");
|
||||
const contract_js_1 = require("./contract.js");
|
||||
// A = Arguments to the constructor
|
||||
// I = Interface of deployed contracts
|
||||
class ContractFactory {
|
||||
interface;
|
||||
bytecode;
|
||||
runner;
|
||||
constructor(abi, bytecode, runner) {
|
||||
const iface = index_js_1.Interface.from(abi);
|
||||
// Dereference Solidity bytecode objects and allow a missing `0x`-prefix
|
||||
if (bytecode instanceof Uint8Array) {
|
||||
bytecode = (0, index_js_3.hexlify)(index_js_3.logger.getBytes(bytecode));
|
||||
}
|
||||
else {
|
||||
if (typeof (bytecode) === "object") {
|
||||
bytecode = bytecode.object;
|
||||
}
|
||||
if (bytecode.substring(0, 2) !== "0x") {
|
||||
bytecode = "0x" + bytecode;
|
||||
}
|
||||
bytecode = (0, index_js_3.hexlify)(index_js_3.logger.getBytes(bytecode));
|
||||
}
|
||||
(0, index_js_3.defineProperties)(this, {
|
||||
bytecode, interface: iface, runner: (runner || null)
|
||||
});
|
||||
}
|
||||
async getDeployTransaction(...args) {
|
||||
let overrides = {};
|
||||
const fragment = this.interface.deploy;
|
||||
if (fragment.inputs.length + 1 === args.length) {
|
||||
overrides = await (0, contract_js_1.copyOverrides)(args.pop());
|
||||
}
|
||||
if (fragment.inputs.length !== args.length) {
|
||||
throw new Error("incorrect number of arguments to constructor");
|
||||
}
|
||||
const resolvedArgs = await (0, contract_js_1.resolveArgs)(this.runner, fragment.inputs, args);
|
||||
const data = (0, index_js_3.concat)([this.bytecode, this.interface.encodeDeploy(resolvedArgs)]);
|
||||
return Object.assign({}, overrides, { data });
|
||||
}
|
||||
async deploy(...args) {
|
||||
const tx = await this.getDeployTransaction(...args);
|
||||
if (!this.runner || typeof (this.runner.sendTransaction) !== "function") {
|
||||
return index_js_3.logger.throwError("factory runner does not support sending transactions", "UNSUPPORTED_OPERATION", {
|
||||
operation: "sendTransaction"
|
||||
});
|
||||
}
|
||||
const sentTx = await this.runner.sendTransaction(tx);
|
||||
const address = (0, index_js_2.getCreateAddress)(sentTx);
|
||||
return new contract_js_1.BaseContract(address, this.interface, this.runner, sentTx);
|
||||
}
|
||||
connect(runner) {
|
||||
return new ContractFactory(this.interface, this.bytecode, runner);
|
||||
}
|
||||
static fromSolidity(output, runner) {
|
||||
if (output == null) {
|
||||
index_js_3.logger.throwArgumentError("bad compiler output", "output", output);
|
||||
}
|
||||
if (typeof (output) === "string") {
|
||||
output = JSON.parse(output);
|
||||
}
|
||||
const abi = output.abi;
|
||||
let bytecode = "";
|
||||
if (output.bytecode) {
|
||||
bytecode = output.bytecode;
|
||||
}
|
||||
else if (output.evm && output.evm.bytecode) {
|
||||
bytecode = output.evm.bytecode;
|
||||
}
|
||||
return new this(abi, bytecode, runner);
|
||||
}
|
||||
}
|
||||
exports.ContractFactory = ContractFactory;
|
||||
//# sourceMappingURL=factory.js.map
|
1
lib.commonjs/contract/factory.js.map
Normal file
1
lib.commonjs/contract/factory.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../src.ts/contract/factory.ts"],"names":[],"mappings":";;;AACA,8CAA4C;AAC5C,kDAAuD;AACvD,gDAA8E;AAE9E,+CAAyE;AAYzE,mCAAmC;AACnC,sCAAsC;AACtC,MAAa,eAAe;IACf,SAAS,CAAa;IACtB,QAAQ,CAAU;IAClB,MAAM,CAAyB;IAExC,YAAY,GAA6B,EAAE,QAAwC,EAAE,MAA8B;QAC/G,MAAM,KAAK,GAAG,oBAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAElC,wEAAwE;QACxE,IAAI,QAAQ,YAAY,UAAU,EAAE;YAChC,QAAQ,GAAG,IAAA,kBAAO,EAAC,iBAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;SACjD;aAAM;YACH,IAAI,OAAM,CAAC,QAAQ,CAAC,KAAK,QAAQ,EAAE;gBAAE,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC;aAAE;YAClE,IAAI,QAAQ,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,IAAI,EAAE;gBAAE,QAAQ,GAAG,IAAI,GAAG,QAAQ,CAAC;aAAE;YACtE,QAAQ,GAAG,IAAA,kBAAO,EAAC,iBAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;SACjD;QAED,IAAA,2BAAgB,EAAkB,IAAI,EAAE;YACpC,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,MAAM,IAAI,IAAI,CAAC;SACvD,CAAC,CAAC;IACP,CAAC;IAED,KAAK,CAAC,oBAAoB,CAAC,GAAG,IAA2B;QACrD,IAAI,SAAS,GAA4C,EAAG,CAAC;QAE7D,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,C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AAS,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjF,CAAC;IAED,OAAO,CAAC,MAA6B;QACjC,OAAO,IAAI,eAAe,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACtE,CAAC;IAED,MAAM,CAAC,YAAY,CAA2D,MAAW,EAAE,MAAuB;QAC9G,IAAI,MAAM,IAAI,IAAI,EAAE;YAChB,iBAAM,CAAC,kBAAkB,CAAC,qBAAqB,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;SACtE;QAED,IAAI,OAAM,CAAC,MAAM,CAAC,KAAK,QAAQ,EAAE;YAAE,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;SAAE;QAEjE,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC;QAEvB,IAAI,QAAQ,GAAG,EAAE,CAAC;QAClB,IAAI,MAAM,CAAC,QAAQ,EAAE;YACjB,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;SAC9B;aAAM,IAAI,MAAM,CAAC,GAAG,IAAI,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE;YAC1C,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;SAClC;QAED,OAAO,IAAI,IAAI,CAAC,GAAG,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC3C,CAAC;CACJ;AA7ED,0CA6EC"}
|
14
lib.commonjs/contract/index.js
Normal file
14
lib.commonjs/contract/index.js
Normal file
@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.EventLog = exports.ContractTransactionResponse = exports.ContractTransactionReceipt = exports.ContractEventPayload = exports.ContractFactory = exports.Contract = exports.BaseContract = void 0;
|
||||
var contract_js_1 = require("./contract.js");
|
||||
Object.defineProperty(exports, "BaseContract", { enumerable: true, get: function () { return contract_js_1.BaseContract; } });
|
||||
Object.defineProperty(exports, "Contract", { enumerable: true, get: function () { return contract_js_1.Contract; } });
|
||||
var factory_js_1 = require("./factory.js");
|
||||
Object.defineProperty(exports, "ContractFactory", { enumerable: true, get: function () { return factory_js_1.ContractFactory; } });
|
||||
var wrappers_js_1 = require("./wrappers.js");
|
||||
Object.defineProperty(exports, "ContractEventPayload", { enumerable: true, get: function () { return wrappers_js_1.ContractEventPayload; } });
|
||||
Object.defineProperty(exports, "ContractTransactionReceipt", { enumerable: true, get: function () { return wrappers_js_1.ContractTransactionReceipt; } });
|
||||
Object.defineProperty(exports, "ContractTransactionResponse", { enumerable: true, get: function () { return wrappers_js_1.ContractTransactionResponse; } });
|
||||
Object.defineProperty(exports, "EventLog", { enumerable: true, get: function () { return wrappers_js_1.EventLog; } });
|
||||
//# sourceMappingURL=index.js.map
|
1
lib.commonjs/contract/index.js.map
Normal file
1
lib.commonjs/contract/index.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src.ts/contract/index.ts"],"names":[],"mappings":";;;AACA,6CAEuB;AADnB,2GAAA,YAAY,OAAA;AAAE,uGAAA,QAAQ,OAAA;AAG1B,2CAEsB;AADlB,6GAAA,eAAe,OAAA;AAGnB,6CAGuB;AAFnB,mHAAA,oBAAoB,OAAA;AAAE,yHAAA,0BAA0B,OAAA;AAAE,0HAAA,2BAA2B,OAAA;AAC7E,uGAAA,QAAQ,OAAA"}
|
6
lib.commonjs/contract/types.js
Normal file
6
lib.commonjs/contract/types.js
Normal file
@ -0,0 +1,6 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
;
|
||||
;
|
||||
;
|
||||
//# sourceMappingURL=types.js.map
|
1
lib.commonjs/contract/types.js.map
Normal file
1
lib.commonjs/contract/types.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src.ts/contract/types.ts"],"names":[],"mappings":";;AAeC,CAAC;AAiBqE,CAAC;AAkDvE,CAAC"}
|
80
lib.commonjs/contract/wrappers.js
Normal file
80
lib.commonjs/contract/wrappers.js
Normal file
@ -0,0 +1,80 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ContractEventPayload = exports.ContractTransactionResponse = exports.ContractTransactionReceipt = exports.EventLog = void 0;
|
||||
const index_js_1 = require("../providers/index.js");
|
||||
const index_js_2 = require("../utils/index.js");
|
||||
class EventLog extends index_js_1.Log {
|
||||
interface;
|
||||
fragment;
|
||||
args;
|
||||
constructor(log, iface, fragment) {
|
||||
super(log, log.provider);
|
||||
const args = iface.decodeEventLog(fragment, log.data, log.topics);
|
||||
(0, index_js_2.defineProperties)(this, { args, fragment, interface: iface });
|
||||
}
|
||||
get eventName() { return this.fragment.name; }
|
||||
get eventSignature() { return this.fragment.format(); }
|
||||
}
|
||||
exports.EventLog = EventLog;
|
||||
class ContractTransactionReceipt extends index_js_1.TransactionReceipt {
|
||||
#interface;
|
||||
constructor(iface, provider, tx) {
|
||||
super(tx, provider);
|
||||
this.#interface = iface;
|
||||
}
|
||||
get logs() {
|
||||
return super.logs.map((log) => {
|
||||
const fragment = log.topics.length ? this.#interface.getEvent(log.topics[0]) : null;
|
||||
if (fragment) {
|
||||
return new EventLog(log, this.#interface, fragment);
|
||||
}
|
||||
else {
|
||||
return log;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.ContractTransactionReceipt = ContractTransactionReceipt;
|
||||
class ContractTransactionResponse extends index_js_1.TransactionResponse {
|
||||
#interface;
|
||||
constructor(iface, provider, tx) {
|
||||
super(tx, provider);
|
||||
this.#interface = iface;
|
||||
}
|
||||
async wait(confirms) {
|
||||
const receipt = await super.wait();
|
||||
if (receipt == null) {
|
||||
return null;
|
||||
}
|
||||
return new ContractTransactionReceipt(this.#interface, this.provider, receipt);
|
||||
}
|
||||
}
|
||||
exports.ContractTransactionResponse = ContractTransactionResponse;
|
||||
class ContractEventPayload extends index_js_2.EventPayload {
|
||||
fragment;
|
||||
log;
|
||||
args;
|
||||
constructor(contract, listener, filter, fragment, _log) {
|
||||
super(contract, listener, filter);
|
||||
const log = new EventLog(_log, contract.interface, fragment);
|
||||
const args = contract.interface.decodeEventLog(fragment, log.data, log.topics);
|
||||
(0, index_js_2.defineProperties)(this, { args, fragment, log });
|
||||
}
|
||||
get eventName() {
|
||||
return this.fragment.name;
|
||||
}
|
||||
get eventSignature() {
|
||||
return this.fragment.format();
|
||||
}
|
||||
async getBlock() {
|
||||
return await this.log.getBlock();
|
||||
}
|
||||
async getTransaction() {
|
||||
return await this.log.getTransaction();
|
||||
}
|
||||
async getTransactionReceipt() {
|
||||
return await this.log.getTransactionReceipt();
|
||||
}
|
||||
}
|
||||
exports.ContractEventPayload = ContractEventPayload;
|
||||
//# sourceMappingURL=wrappers.js.map
|
1
lib.commonjs/contract/wrappers.js.map
Normal file
1
lib.commonjs/contract/wrappers.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"wrappers.js","sourceRoot":"","sources":["../../src.ts/contract/wrappers.ts"],"names":[],"mappings":";;;AAAA,oDAE+B;AAC/B,gDAAmE;AAYnE,MAAa,QAAS,SAAQ,cAAG;IACpB,SAAS,CAAa;IACtB,QAAQ,CAAiB;IACzB,IAAI,CAAU;IAEvB,YAAY,GAAQ,EAAE,KAAgB,EAAE,QAAuB;QAC3D,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC;QACzB,MAAM,IAAI,GAAG,KAAK,CAAC,cAAc,CAAC,QAAQ,EAAE,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;QAClE,IAAA,2BAAgB,EAAW,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;IAC3E,CAAC;IAED,IAAI,SAAS,KAAa,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CA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