diff --git a/lib.commonjs/README.md b/lib.commonjs/README.md new file mode 100644 index 00000000..8d396d78 --- /dev/null +++ b/lib.commonjs/README.md @@ -0,0 +1,16 @@ +CommonJS Files +============== + +The contents of this folder are for using `require` in CommonJS +projects. + + +Notes +----- + +The contents are generated via the `npm run build-commonjs` target +using `tsc` and the `/tsconfig.commonjs.json` configuration. + +Do not modify the files in this folder. They are deleted on `build-clean`. + +To modify this `README.md`, see the `/output/post-build/lib.commonjs`. diff --git a/lib.commonjs/package.json b/lib.commonjs/package.json new file mode 100644 index 00000000..0e211685 --- /dev/null +++ b/lib.commonjs/package.json @@ -0,0 +1,12 @@ +{ + "browser": { + "./crypto/crypto.js": "./crypto/crypto-browser.js", + "./providers/provider-ipcsocket.js": "./providers/provider-ipcsocket-browser.js", + "./providers/ws.js": "./providers/ws-browser.js", + "./utils/base64.js": "./utils/base64-browser.js", + "./utils/geturl.js": "./utils/geturl-browser.js", + "./wordlists/wordlists.js": "./wordlists/wordlists-browser.js" + }, + "sideEffects": false, + "type": "commonjs" +} diff --git a/lib.esm/README.md b/lib.esm/README.md new file mode 100644 index 00000000..ce8d3ba5 --- /dev/null +++ b/lib.esm/README.md @@ -0,0 +1,16 @@ +ESM Files +========= + +The contents of this folder are for using `import` in ESM +projects. + + +Notes +----- + +The contents are generated via the `npm run build` target +using `tsc` and the `/tsconfig.esm.json` configuration. + +Do not modify the files in this folder. They are deleted on `build-clean`. + +To modify this `README.md`, see the `/output/post-build/lib.esm`. diff --git a/lib.esm/_admin/create-release.d.ts b/lib.esm/_admin/create-release.d.ts new file mode 100644 index 00000000..9c0e2741 --- /dev/null +++ b/lib.esm/_admin/create-release.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=create-release.d.ts.map \ No newline at end of file diff --git a/lib.esm/_admin/create-release.d.ts.map b/lib.esm/_admin/create-release.d.ts.map new file mode 100644 index 00000000..5af33e35 --- /dev/null +++ b/lib.esm/_admin/create-release.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"create-release.d.ts","sourceRoot":"","sources":["../../src.ts/_admin/create-release.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/lib.esm/_admin/create-release.js b/lib.esm/_admin/create-release.js new file mode 100644 index 00000000..0a067940 --- /dev/null +++ b/lib.esm/_admin/create-release.js @@ -0,0 +1,38 @@ +import { getChanges } from "./utils/changelog.js"; +import { getDateTime } from "./utils/date.js"; +import { resolve } from "./utils/path.js"; +import { run } from "./utils/run.js"; +import { getVersions } from "./utils/npm.js"; +const version = process.argv[2] || null; +(async function () { + // Get the change from the CHANGELOG + const changes = getChanges(); + const change = version ? changes.filter((c) => (c.version === version))[0] : changes.shift(); + if (change == null) { + throw new Error(`version not found: ${version}`); + } + console.log(change); + // Find the gitHead and release date + const versions = await getVersions("quais"); + const ver = versions.filter((c) => (c.version === change.version))[0]; + if (ver == null) { + throw new Error(`no npm version found: ${change.version}`); + } + console.log(ver); + const title = `${change.title.split("(")[0].trim()} (${getDateTime(new Date(ver.date))})`; + const args = [ + "release", "create", `v${change.version}`, + // "--draft", // DEBUGGING + "--title", title, + "--target", ver.gitHead, + "--notes", change.body.join("\n"), + ]; + console.log(args); + const result = await run("gh", args, resolve(".")); + console.log("Published"); + console.log(`See: ${(result.stdout || "").trim()}`); +})().catch((e) => { + console.log("ERROR"); + console.log(e); +}); +//# sourceMappingURL=create-release.js.map \ No newline at end of file diff --git a/lib.esm/_admin/create-release.js.map b/lib.esm/_admin/create-release.js.map new file mode 100644 index 00000000..3feb5411 --- /dev/null +++ b/lib.esm/_admin/create-release.js.map @@ -0,0 +1 @@ +{"version":3,"file":"create-release.js","sourceRoot":"","sources":["../../src.ts/_admin/create-release.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,GA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AG;QACT,SAAS,EAAE,QAAQ,EAAE,IAAK,MAAM,CAAC,OAAQ,EAAE;QACnD,iCAAiC;QACzB,SAAS,EAAE,KAAK;QAChB,UAAU,EAAE,GAAG,CAAC,OAAO;QACvB,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;KACpC,CAAC;IACF,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAClB,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;IACnD,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IACzB,OAAO,CAAC,GAAG,CAAC,QAAS,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,IAAI,EAAG,EAAE,CAAC,CAAC;AAC1D,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;IACb,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACrB,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AACnB,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/lib.esm/_admin/generate-diffs.d.ts b/lib.esm/_admin/generate-diffs.d.ts new file mode 100644 index 00000000..35ddf437 --- /dev/null +++ b/lib.esm/_admin/generate-diffs.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=generate-diffs.d.ts.map \ No newline at end of file diff --git a/lib.esm/_admin/generate-diffs.d.ts.map b/lib.esm/_admin/generate-diffs.d.ts.map new file mode 100644 index 00000000..e1e2c9f7 --- /dev/null +++ b/lib.esm/_admin/generate-diffs.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"generate-diffs.d.ts","sourceRoot":"","sources":["../../src.ts/_admin/generate-diffs.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/lib.esm/_admin/generate-diffs.js b/lib.esm/_admin/generate-diffs.js new file mode 100644 index 00000000..d5ccf51f --- /dev/null +++ b/lib.esm/_admin/generate-diffs.js @@ -0,0 +1,25 @@ +import fs from "fs"; +import { getVersions } from "./utils/npm.js"; +import { resolve } from "./utils/path.js"; +import { getDiff } from "./utils/git.js"; +function escver(v) { + return v.replace(/\./, "-"); +} +(async function () { + let versions = await getVersions("quais"); + versions = versions.filter((h) => (h.version.match(/^6\.[0-9]+\.[0-9]+$/))); + fs.writeFileSync(resolve("misc/diffs/versions.txt"), versions.map((h) => h.version).join(",")); + for (let i = 0; i < versions.length; i++) { + for (let j = i + 1; j < versions.length; j++) { + const filename = resolve(`misc/diffs/diff-${escver(versions[i].version)}_${escver(versions[j].version)}.txt`); + if (fs.existsSync(filename)) { + continue; + } + const tag0 = versions[i].gitHead, tag1 = versions[j].gitHead; + const diff = await getDiff(resolve("src.ts"), tag0, tag1); + console.log({ diff }); + fs.writeFileSync(filename, diff); + } + } +})(); +//# sourceMappingURL=generate-diffs.js.map \ No newline at end of file diff --git a/lib.esm/_admin/generate-diffs.js.map b/lib.esm/_admin/generate-diffs.js.map new file mode 100644 index 00000000..7f64350c --- /dev/null +++ b/lib.esm/_admin/generate-diffs.js.map @@ -0,0 +1 @@ +{"version":3,"file":"generate-diffs.js","sourceRoot":"","sources":["../../src.ts/_admin/generate-diffs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzC,SAAS,MAAM,CAAC,CAAS;IACrB,OAAO,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AAChC,CAAC;AAED,CAAC,KAAK;IACF,IAAI,QAAQ,GAAG,MAAM,WAAW,CAAC,OAAO,CAAC,CAAC;IAC1C,QAAQ,GAAG,QAAQ,CAAC,MAAM,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00000000..bb35a67d --- /dev/null +++ b/lib.esm/_admin/test-browser.d.ts @@ -0,0 +1,32 @@ +/** + * + * + * Paths + * /index.js => dist/quais.js + * /tests/utils.js => in-memory hijack + * /static/* => output/* + * - index.html + * - assert.js + * /tests/* => lib.esm/_tests/* + */ +/// +import { WebSocket } from "ws"; +import { Server } from "http"; +export declare function getMime(filename: string): string; +export declare class CDPSession { + #private; + readonly websocket: WebSocket; + constructor(url: string); + get target(): string; + get ready(): Promise; + get done(): Promise; + send(method: string, params: any): Promise; + _send(method: string, params: any): Promise; + navigate(url: string): Promise; +} +export type Options = { + port?: number; + redirects?: Record; +}; +export declare function start(_root: string, options: Options): Promise; +//# sourceMappingURL=test-browser.d.ts.map \ No newline at end of file diff --git a/lib.esm/_admin/test-browser.d.ts.map b/lib.esm/_admin/test-browser.d.ts.map new file mode 100644 index 00000000..f90f6eab --- /dev/null +++ b/lib.esm/_admin/test-browser.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"test-browser.d.ts","sourceRoot":"","sources":["../../src.ts/_admin/test-browser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;;AAQH,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAE/B,OAAO,EAAgB,MAAM,EAAE,MAAM,MAAM,CAAC;AAuB5C,wBAAgB,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAShD;AAOD,qBAAa,UAAU;;IACnB,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;gBAclB,GAAG,EAAE,MAAM;IA4EvB,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,IAAI,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAKzB;IAED,IAAI,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAE1B;IAEK,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IAO/C,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IAahD,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAG7C;AAED,MAAM,MAAM,OAAO,GAAG;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC,CAAC;AAgCF,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAyGtE"} \ No newline at end of file diff --git a/lib.esm/_admin/test-browser.js b/lib.esm/_admin/test-browser.js new file mode 100644 index 00000000..5279548e --- /dev/null +++ b/lib.esm/_admin/test-browser.js @@ -0,0 +1,326 @@ +/** + * + * + * Paths + * /index.js => dist/quais.js + * /tests/utils.js => in-memory hijack + * /static/* => output/* + * - index.html + * - assert.js + * /tests/* => lib.esm/_tests/* + */ +// See: https://vanilla.aslushnikov.com/?Console +import fs from "fs"; +import child_process from "child_process"; +import zlib from "zlib"; +import { WebSocket } from "ws"; +import { createServer } from "http"; +import { join, resolve } from "path"; +const mimes = { + css: "text/css", + doctree: "application/x-doctree", + eot: "application/vnd.ms-fontobject", + gif: "image/gif", + html: "text/html", + ico: "image/x-icon", + js: "application/javascript", + jpg: "image/jpeg", + jpeg: "image/jpeg", + json: "application/json", + map: "application/json", + md: "text/markdown", + png: "image/png", + svg: "image/svg+xml", + ttf: "application/x-font-ttf", + txt: "text/plain", + woff: "application/font-woff" +}; +export function getMime(filename) { + const mime = mimes[(filename.split('.').pop() || "").toLowerCase()]; + if (mime == null) { + console.log(`WARN: NO MIME for ${filename}`); + return "application/octet-stream"; + } + return mime; +} +export class CDPSession { + websocket; + #id; + #resp; + #readyOpen; + #readyPage; + #target; + #session; + #done; + #exit; + constructor(url) { + this.websocket = new WebSocket(url); + this.#id = 1; + this.#resp = new Map(); + this.#exit = (status) => { }; + this.#done = new Promise((resolve) => { + this.#exit = resolve; + }); + this.#target = ""; + this.#session = ""; + const readyOpen = new Promise((resolve, reject) => { + this.websocket.onopen = async () => { resolve(); }; + }); + const readyPage = (async () => { + await readyOpen; + const target = await this._send("Target.getTargets", {}); + if (target.targetInfos.length) { + this.#target = target.targetInfos[0].targetId; + } + else { + const target = await this._send("Target.createTarget", { url: "" }); + this.#target = target.targetId; + } + const attached = await this._send("Target.attachToTarget", { + targetId: this.#target, + flatten: true + }); + this.#session = attached.sessionId; + })(); + this.#readyOpen = readyOpen; + this.#readyPage = readyPage; + this.websocket.onmessage = (_msg) => { + const msg = JSON.parse(_msg.data); + if (msg.id != null) { + const responder = this.#resp.get(msg.id); + this.#resp.delete(msg.id); + if (responder == null) { + console.log("WARN: unknown request ${ msg.id }"); + return; + } + if (msg.error) { + responder.reject(new Error(msg.error)); + } + else { + responder.resolve(msg.result); + } + } + else { + if (msg.method === "Console.messageAdded") { + const text = msg.params.message.text; + if (text.startsWith("#status")) { + this.#exit(parseInt(text.split("=").pop())); + } + console.log(text); + //console.log(msg.params.message.text, `${ msg.params.message.url }:${ msg.params.message.line }`); + } + else if (msg.method === "Target.attachedToTarget") { + } + else { + console.log(`WARN: Unhandled event - ${JSON.stringify(msg)}`); + } + } + }; + this.websocket.onerror = (error) => { + console.log(`WARN: WebSocket error - ${JSON.stringify(error)}`); + }; + } + get target() { + return this.#target; + } + get ready() { + return (async () => { + await this.#readyOpen; + await this.#readyPage; + })(); + } + get done() { + return this.#done; + } + async send(method, params) { + await this.#readyOpen; + await this.#readyPage; + return this._send(method, params); + } + async _send(method, params) { + const id = this.#id++; + const payload = { id, method, params }; + if (this.#session) { + payload.sessionId = this.#session; + } + this.websocket.send(JSON.stringify(payload)); + return new Promise((resolve, reject) => { + this.#resp.set(id, { resolve, reject }); + }); + } + async navigate(url) { + await this.send("Page.navigate", { url }); + } +} +const TestData = (function () { + function load(tag) { + const filename = resolve("testcases", tag + ".json.gz"); + const data = zlib.gunzipSync(fs.readFileSync(filename)); + return [String(data.length), zlib.deflateRawSync(data).toString("base64")].join(","); + } + let data = []; + data.push(`import { quais } from "/index.js";`); + data.push(`import { inflate } from "/static/tiny-inflate.js";`); + data.push(`const fs = new Map();`); + for (const filename of fs.readdirSync("testcases")) { + if (!filename.endsWith(".json.gz")) { + continue; + } + const tag = filename.split(".")[0]; + data.push(`fs.set(${JSON.stringify(tag)}, ${JSON.stringify(load(tag))});`); + } + data.push(`export function loadTests(tag) {`); + data.push(` const data = fs.get(tag);`); + data.push(` if (data == null) { throw new Error("missing tag: " + tag); }`); + data.push(` const comps = data.split(",");`); + data.push(` const result = new Uint8Array(parseInt(comps[0]));`); + data.push(` inflate(quais.decodeBase64(comps[1]), result);`); + data.push(` return JSON.parse(quais.toUtf8String(result))`); + data.push(`}`); + return data.join("\n"); +})(); +export function start(_root, options) { + if (options == null) { + options = {}; + } + if (options.port == null) { + options.port = 8000; + } + const server = createServer((req, resp) => { + const url = (req.url || "").split("?")[0]; + let transform = false; + let filename; + if (url === "/") { + filename = "./misc/test-browser/index.html"; + } + else if (url === "/quais.js" || url === "/index.js") { + filename = "./dist/quais.js"; + } + else if (url === "/quais.js.map") { + filename = "./dist/quais.js.map"; + } + else if (url.startsWith("/static/")) { + filename = "./misc/test-browser/" + url.substring(8); + } + else if (url === "/tests/utils.js") { + //console.log({ status: 200, content: `<>` }); + resp.writeHead(200, { + "Content-Length": TestData.length, + "Content-Type": getMime("testdata.js") + }); + resp.end(TestData); + return; + } + else if (url.startsWith("/tests/")) { + transform = true; + filename = join("./lib.esm/_tests", url.substring(7)); + } + else { + //console.log("FALLBACK"); + filename = url.substring(1); + } + // Make sure we aren't crawling out of our sandbox + if (url[0] !== "/" || filename.substring(0, filename.length) !== filename) { + //console.log({ status: 403, reason: "escaping" }); + resp.writeHead(403); + resp.end(); + return; + } + try { + const stat = fs.statSync(filename); + if (stat.isDirectory()) { + // Redirect bare directory to its path (i.e. "/foo" => "/foo/") + if (url[url.length - 1] !== "/") { + //console.log({ status: 301, location: (url + "/") }); + resp.writeHead(301, { Location: url + "/" }); + resp.end(); + return; + } + filename += "/index.html"; + } + let content = fs.readFileSync(filename); + if (transform) { + content = Buffer.from(content.toString().replace(/import ([^;]*) from "([^"]*)";/g, (all, names, filename) => { + switch (filename) { + case "assert": + //case "path": + //case "fs": + //case "zlib": + return `import ${names} from "/static/${filename}.js"`; + } + return all; + })); + } + //console.log({ status: 200, filename }); + resp.writeHead(200, { + "Content-Length": content.length, + "Content-Type": getMime(filename) + }); + resp.end(content); + return; + } + catch (error) { + if (error.code === "ENOENT") { + //console.log({ status: 404, filename }); + console.log(`WARN: Not found - ${filename}`); + resp.writeHead(404, {}); + resp.end(); + return; + } + //console.log({ status: 500, error: error.toString() }); + console.log(`WARN: Server error - ${error.toString()}`); + resp.writeHead(500, {}); + resp.end(); + return; + } + }); + return new Promise((resolve, reject) => { + server.listen(options.port, () => { + console.log(`Server running on: http://localhost:${options.port}`); + resolve(server); + }); + }); +} +(async function () { + await start(resolve("."), { port: 8000 }); + const cmds = [ + "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", + "/usr/bin/chromium" + ].filter((f) => { try { + fs.accessSync(f); + return true; + } + catch (error) { + return false; + } }); + if (cmds.length === 0) { + throw new Error("no installed browser found"); + } + const cmd = cmds[0]; + const args = ["--headless", "--disable-gpu", "--remote-debugging-port=8022"]; + const browser = child_process.spawn(cmd, args); + let url = await new Promise((resolve, reject) => { + browser.stdout.on("data", (data) => { + console.log("OUT", data.toString()); + }); + browser.stderr.on("data", (data) => { + const text = data.toString(); + for (const line of text.split("\n")) { + const match = line.match(/^DevTools listening on (.*)$/); + if (match) { + resolve(match[1]); + return; + } + } + }); + }); + console.log("URL:", url); + const session = new CDPSession(url); + await session.ready; + await session.send("Console.enable", {}); + await session.navigate("http:/\/localhost:8000"); + const status = await session.done; + console.log("STATUS:", status); + process.exit(status); +})(); +//# sourceMappingURL=test-browser.js.map \ No newline at end of file diff --git a/lib.esm/_admin/test-browser.js.map b/lib.esm/_admin/test-browser.js.map new file mode 100644 index 00000000..ccb61c5f --- /dev/null +++ b/lib.esm/_admin/test-browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"test-browser.js","sourceRoot":"","sources":["../../src.ts/_admin/test-browser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,gDAAgD;AAEhD,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,aAAa,MAAM,eAAe,CAAC;AAC1C,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAE/B,OAAO,EAAE,YAAY,EAAU,MAAM,MAAM,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAErC,MAAM,KAAK,GAA2B;IACpC,GAAG,EAAE,UAAU;IACf,OAAO,EAAE,uBAAuB;IAChC,GAAG,EAAE,+BAA+B;IACpC,GAAG,EAAE,WAAW;IAChB,IAAI,EAAE,WAAW;IACjB,GAAG,EAAE,cAAc;IACnB,EAAE,EAAE,wBAAwB;IAC5B,GAAG,EAAE,YAAY;IACjB,IAAI,EAAE,YAAY;IAClB,IAAI,EAAE,kBAAkB;IACxB,GAAG,EAAE,kBAAkB;IACvB,EAAE,EAAE,eAAe;IACnB,GAAG,EAAE,WAAW;IAChB,GAAG,EAAE,eAAe;IACpB,GAAG,EAAE,wBAAwB;IAC7B,GAAG,EAAE,YAAY;IACjB,IAAI,EAAE,uBAAuB;CAC9B,CAAC;AAEF,MAAM,UAAU,OAAO,CAAC,QAAgB;IACpC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;IAEpE,IAAI,IAAI,IAAI,IAAI,EAAE;QAChB,OAAO,CAAC,GAAG,CAAC,qBAAsB,QAAS,EAAE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AAM,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAAC,CAAC;IAEjD,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC;IAClC,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAC/B,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACzB,CAAC,CAAC,EAAE,CAAC"} \ No newline at end of file diff --git a/lib.esm/_admin/update-changelog.d.ts b/lib.esm/_admin/update-changelog.d.ts new file mode 100644 index 00000000..9559d610 --- /dev/null +++ b/lib.esm/_admin/update-changelog.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=update-changelog.d.ts.map \ No newline at end of file diff --git a/lib.esm/_admin/update-changelog.d.ts.map b/lib.esm/_admin/update-changelog.d.ts.map new file mode 100644 index 00000000..075e7b70 --- /dev/null +++ b/lib.esm/_admin/update-changelog.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"update-changelog.d.ts","sourceRoot":"","sources":["../../src.ts/_admin/update-changelog.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/lib.esm/_admin/update-changelog.js b/lib.esm/_admin/update-changelog.js new file mode 100644 index 00000000..c814c0f8 --- /dev/null +++ b/lib.esm/_admin/update-changelog.js @@ -0,0 +1,160 @@ +import fs from "fs"; +import { getLogs } from "./utils/git.js"; +import { loadJson } from "./utils/json.js"; +import { resolve } from "./utils/path.js"; +import { getVersions } from "./utils/npm.js"; +import { getDateTime } from "./utils/date.js"; +function repeat(c, length) { + if (c.length === 0) { + throw new Error("too short"); + } + while (c.length < length) { + c += c; + } + return c.substring(0, length); +} +async function getChanges(tag0, tag1) { + const result = []; + const logs = await getLogs(null, { tag0, tag1 }); + for (const log of logs) { + if (log.body.startsWith("admin:") || log.body.startsWith("docs:")) { + continue; + } + let message = log.body; + const issues = []; + message = message.replace(/\((([0-9#,]|\s)*)\)/g, (all, text) => { + text = text.replace(/#([0-9]+)/g, (all, issue) => { + issues.push(issue); + return ""; + }); + if (text.replace(/,/g, "").trim()) { + console.log(`WARNING: commit leftovers ${JSON.stringify(text)}`); + } + return ""; + }).replace(/\.+\s*$/, "").trim(); + result.push({ message, issues, commit: log.commit }); + } + return result; +} +(async function () { + // Get the already included versions in the CHANGELOG + const present = [{ version: "null", body: [] }]; + { + const content = fs.readFileSync(resolve("CHANGELOG.md")).toString(); + for (const line of content.split("\n")) { + let match = line.match(/^ethers\/v(\S+)\s/); + if (match) { + present.push({ version: match[1], body: [line] }); + } + else { + present[present.length - 1].body.push(line); + } + } + for (const { body } of present) { + while (body[body.length - 1].trim() === "") { + body.pop(); + } + } + } + // Get the remote versions (along with their date and gitHead) + let versions = await getVersions("ethers"); + versions = versions.filter((v) => (v.version.match(/^6\.[0-9]+\.[0-9]+$/))); + const entries = []; + const getPresent = (version) => { + const pres = present.filter((p) => (p.version === version)); + return pres.length ? pres[0] : null; + }; + // Add the first entry, which has no previous version to compare against + { + const pres = getPresent(versions[0].version); + if (pres) { + entries.push(pres); + } + else { + entries.push({ + date: getDateTime(new Date(versions[0].date)), + version: versions[0].version, + changes: [{ + message: "Initial release", + issues: [], + commit: versions[0].gitHead + }] + }); + } + } + // Add each version, with preference given to present entries, as + // they may have been updated manually + let lastVer = versions[0]; + for (let i = 1; i < versions.length; i++) { + const ver = versions[i]; + // Prefer present entries + const pres = getPresent(ver.version); + if (pres) { + entries.push(pres); + lastVer = ver; + continue; + } + // Get the entry info from git + const version = ver.version; + const date = getDateTime(new Date(ver.date)); + const changes = await getChanges(lastVer.gitHead, ver.gitHead); + entries.push({ date, version, changes }); + lastVer = ver; + } + // If this is a new version (not present in npm) add the changes + // from the lastest version until HEAD. + const curVer = loadJson(resolve("package.json")).version; + if (curVer !== lastVer) { + // Include any present entry, as it was placed here by a + // previous run of update-changelog and may have been + // modified manually + const pres = getPresent(curVer); + if (pres) { + console.log(`WARNING: existing entry for ${curVer}; duplicating`); + entries.push(pres); + } + // Also include theentry from git + const latest = await getChanges(lastVer.gitHead, "HEAD"); + if (latest.length) { + entries.push({ + date: getDateTime(new Date()), + version: curVer, + changes: latest + }); + } + } + // Gerenate the CHANGELOG.md output + const output = []; + output.push("Change Log"); + output.push("=========="); + output.push(""); + output.push("This change log is maintained by `src.ts/_admin/update-changelog.ts` but may also be manually updated."); + output.push(""); + for (const ver of entries.reverse()) { + // Present entry; include verbatim + if ("body" in ver) { + ver.body.forEach((line) => output.push(line)); + output.push(""); + continue; + } + // Entry from git; format it nicely + const title = `ethers/v${ver.version} (${ver.date})`; + output.push(title); + output.push(repeat("-", title.length)); + output.push(""); + for (const change of ver.changes) { + let line = ` - ${change.message} (`; + line += change.issues.map((i) => { + return `[#${i}](https:/\/github.com/ethers-io/ethers.js/issues/${i})`; + }).join(", "); + if (change.issues.length) { + line += "; "; + } + line += `[${change.commit.substring(0, 7)}](https:/\/github.com/ethers-io/ethers.js/commit/${change.commit})).`; + output.push(line); + } + output.push(""); + } + fs.writeFileSync(resolve("CHANGELOG.md"), output.join("\n")); +})(); +//# sourceMappingURL=update-changelog.js.map \ No newline at end of file diff --git a/lib.esm/_admin/update-changelog.js.map b/lib.esm/_admin/update-changelog.js.map new file mode 100644 index 00000000..03c820a0 --- /dev/null +++ b/lib.esm/_admin/update-changelog.js.map @@ -0,0 +1 @@ +{"version":3,"file":"update-changelog.js","sourceRoot":"","sources":["../../src.ts/_admin/update-changelog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,SAAS,MAAM,CAAC,CAAS,EAAE,MAAc;IACrC,IAAI,CAAC,CAA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3C,IAAI,IAAI,IAAK,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAE,oDAAqD,MAAM,CAAC,MAAO,KAAK,CAAC;YACpH,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;SACpB;QACD,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;KACnB;IAED,EAAE,CAAC,aAAa,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AACjE,CAAC,CAAC,EAAE,CAAC"} \ No newline at end of file diff --git a/lib.esm/_admin/update-version.d.ts b/lib.esm/_admin/update-version.d.ts new file mode 100644 index 00000000..933287ba --- /dev/null +++ b/lib.esm/_admin/update-version.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=update-version.d.ts.map \ No newline at end of file diff --git a/lib.esm/_admin/update-version.d.ts.map b/lib.esm/_admin/update-version.d.ts.map new file mode 100644 index 00000000..78fc2230 --- /dev/null +++ b/lib.esm/_admin/update-version.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"update-version.d.ts","sourceRoot":"","sources":["../../src.ts/_admin/update-version.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/lib.esm/_admin/update-version.js b/lib.esm/_admin/update-version.js new file mode 100644 index 00000000..3664058e --- /dev/null +++ b/lib.esm/_admin/update-version.js @@ -0,0 +1,100 @@ +import semver from "semver"; +import { FetchRequest } from "../utils/index.js"; +import { atomicWrite } from "./utils/fs.js"; +import { getLogs } from "./utils/git.js"; +import { loadJson, saveJson } from "./utils/json.js"; +import { resolve } from "./utils/path.js"; +const cache = {}; +async function getNpmPackage(name) { + if (!cache[name]) { + const resp = await (new FetchRequest("https:/\/registry.npmjs.org/" + name)).send(); + resp.assertOk(); + cache[name] = resp.bodyJson; + } + return cache[name] || null; +} +function writeVersion(version) { + const content = `/* Do NOT modify this file; see /src.ts/_admin/update-version.ts */\n\n/**\n * The current version of quais.\n */\nexport const version: string = "${version}";\n`; + atomicWrite(resolve("src.ts/_version.ts"), content); +} +(async function () { + // Local pkg + const pkgPath = resolve("package.json"); + const pkgInfo = loadJson(pkgPath); + const tag = pkgInfo.publishConfig.tag; + // Get the remote version that matches our dist-tag + const remoteInfo = await getNpmPackage(pkgInfo.name); + const remoteVersion = remoteInfo["dist-tags"][tag]; + // Remote pkg + const remotePkgInfo = remoteInfo.versions[remoteVersion]; + const remoteGitHead = remotePkgInfo.gitHead; + let gitHead = ""; + for (const log of await getLogs(["."])) { + if (log.body.startsWith("admin:")) { + continue; + } + if (log.body.startsWith("docs:")) { + continue; + } + if (log.body.startsWith("tests:")) { + continue; + } + gitHead = log.commit; + break; + } + if (gitHead === "") { + throw new Error("no meaningful commit found"); + } + // There are new commits, not reflected in the package + // published on npm; update the gitHead and version + if (gitHead !== remoteGitHead) { + // Bump the version from the remote version + if (tag.indexOf("beta") >= 0) { + // Still a beta branch; advance the beta version + const prerelease = semver.prerelease(remoteVersion); + if (prerelease == null || prerelease.length !== 2) { + throw new Error("no prerelease found"); + } + pkgInfo.version = semver.inc(remoteVersion, "prerelease", String(prerelease[0])); + } + else if (semver.minor(remoteVersion) == semver.minor(pkgInfo.version)) { + // If we want to bump the minor version, it was done explicitly in the pkg + pkgInfo.version = semver.inc(remoteVersion, "patch"); + } + pkgInfo.gitHead = gitHead; + // Save the package.json + const check = { "default": 1, "require": 1, "import": 1, "types": 1 }; + saveJson(pkgPath, pkgInfo, (path, a, b) => { + if ((path.startsWith("./") || path === ".") && check[a] && check[b]) { + const cmp = a.localeCompare(b); + if (cmp === 0) { + return cmp; + } + // Make sure require comes first; it has the types built-in + // so its ok + if (a === "require") { + return -1; + } + if (b === "require") { + return 1; + } + // Favour types the next-first and default for last + if (a === "types" || b === "default") { + return -1; + } + if (b === "types" || a === "default") { + return 1; + } + return cmp; + } + return a.localeCompare(b); + }); + // Save the src.ts/_version.ts + writeVersion(pkgInfo.version); + } +})().catch((error) => { + console.log("ERROR"); + console.log(error); + process.exit(1); +}); +//# sourceMappingURL=update-version.js.map \ No newline at end of file diff --git a/lib.esm/_admin/update-version.js.map b/lib.esm/_admin/update-version.js.map new file mode 100644 index 00000000..02ea1c37 --- /dev/null +++ b/lib.esm/_admin/update-version.js.map @@ -0,0 +1 @@ +{"version":3,"file":"update-version.js","sourceRoot":"","sources":["../../src.ts/_admin/update-version.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,MAAM,KAAK,GAAwB,EAAG,CAAC;AAEvC,KAAK,UAAU,aAAa,CAAC,IAAY;IACrC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE;QACd,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,YAAY,CAAC,8BAA8B,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QACpF,IAAI,CAAC,QAAQ,EAAE,CAAC;QAChB,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC;KAC/B;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC;AAC/B,CAAC;AAED,SAAS,YAAY,CAAC,OAAe;IACjC,MAAM,OAAO,GAAG,uJAAwJ,OAAQ,MAAM,CAAC;IACvL,WAAW,CAAC,OAAO,CAAC,oBAAoB,CAAC,EAAE,OAAO,CAAC,CAAC;AACxD,CAAC;AAED,CAAC,KAAK;IACF,YAAY;IACZ,MAAM,OAAO,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IACxC,MAAM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AAO,CAAC,CAAC,CAAC;iBAAE;gBACpD,IAAI,CAAC,KAAK,OAAO,IAAI,CAAC,KAAK,SAAS,EAAE;oBAAE,OAAO,CAAC,CAAC;iBAAE;gBACnD,OAAO,GAAG,CAAC;aACd;YACD,OAAO,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;QAC9B,CAAC,CAAC,CAAC;QAEH,8BAA8B;QAC9B,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;KACjC;AAEL,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACjB,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACrB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACnB,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/lib.esm/_admin/utils/changelog.d.ts b/lib.esm/_admin/utils/changelog.d.ts new file mode 100644 index 00000000..27d912fc --- /dev/null +++ b/lib.esm/_admin/utils/changelog.d.ts @@ -0,0 +1,7 @@ +export type ChangeVersion = { + version: string; + title: string; + body: Array; +}; +export declare function getChanges(): Array; +//# sourceMappingURL=changelog.d.ts.map \ No newline at end of file diff --git a/lib.esm/_admin/utils/changelog.d.ts.map b/lib.esm/_admin/utils/changelog.d.ts.map new file mode 100644 index 00000000..068233fd --- /dev/null +++ b/lib.esm/_admin/utils/changelog.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"changelog.d.ts","sourceRoot":"","sources":["../../../src.ts/_admin/utils/changelog.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,aAAa,GAAG;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CACvB,CAAC;AAEF,wBAAgB,UAAU,IAAI,KAAK,CAAC,aAAa,CAAC,CAqBjD"} \ No newline at end of file diff --git a/lib.esm/_admin/utils/changelog.js b/lib.esm/_admin/utils/changelog.js new file mode 100644 index 00000000..1cce85de --- /dev/null +++ b/lib.esm/_admin/utils/changelog.js @@ -0,0 +1,23 @@ +import fs from "fs"; +import { resolve } from "./path.js"; +export function getChanges() { + const changes = [ + { title: "", version: "null", body: [] } + ]; + const content = fs.readFileSync(resolve("CHANGELOG.md")).toString(); + for (const line of content.split("\n")) { + let match = line.match(/^quais\/v(\S+)\s/); + if (match) { + changes.push({ version: match[1], title: line.trim(), body: [] }); + } + else { + const l = line.trim(); + if (l && !l.match(/^-+$/)) { + changes[changes.length - 1].body.push(l); + } + } + } + changes.shift(); + return changes; +} +//# sourceMappingURL=changelog.js.map \ No newline at end of file diff --git a/lib.esm/_admin/utils/changelog.js.map b/lib.esm/_admin/utils/changelog.js.map new file mode 100644 index 00000000..8191c1b6 --- /dev/null +++ b/lib.esm/_admin/utils/changelog.js.map @@ -0,0 +1 @@ +{"version":3,"file":"changelog.js","sourceRoot":"","sources":["../../../src.ts/_admin/utils/changelog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAQpC,MAAM,UAAU,UAAU;IACtB,MAAM,OAAO,GAAyB;QAClC,EAAE,KAAK,EAAE,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,EAAG,EAAE;KAC5C,CAAC;IAEF,MAAM,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;IACpE,KAAK,MAAM,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE;QACpC,IAAI,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;QAC3C,IAAI,KAAK,EAAE;YACP,OAAO,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,EAAG,EAAE,CAAC,CAAC;SACtE;aAAM;YACH,MAAM,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;YACtB,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE;gBACvB,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;aAC5C;SACJ;KACJ;IAED,OAAO,CAAC,KAAK,EAAE,CAAC;IAEhB,OAAO,OAAO,CAAC;AACnB,CAAC"} \ No newline at end of file diff --git a/lib.esm/_admin/utils/date.d.ts b/lib.esm/_admin/utils/date.d.ts new file mode 100644 index 00000000..73e011d4 --- /dev/null +++ b/lib.esm/_admin/utils/date.d.ts @@ -0,0 +1,2 @@ +export declare function getDateTime(date: Date): string; +//# sourceMappingURL=date.d.ts.map \ No newline at end of file diff --git a/lib.esm/_admin/utils/date.d.ts.map b/lib.esm/_admin/utils/date.d.ts.map new file mode 100644 index 00000000..79066fb3 --- /dev/null +++ b/lib.esm/_admin/utils/date.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../../src.ts/_admin/utils/date.ts"],"names":[],"mappings":"AAqBA,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAK9C"} \ No newline at end of file diff --git a/lib.esm/_admin/utils/date.js b/lib.esm/_admin/utils/date.js new file mode 100644 index 00000000..e1e5f412 --- /dev/null +++ b/lib.esm/_admin/utils/date.js @@ -0,0 +1,30 @@ +function repeat(c, length) { + if (c.length === 0) { + throw new Error("too short"); + } + while (c.length < length) { + c += c; + } + return c.substring(0, length); +} +function zpad(value, length) { + if (length == null) { + length = 2; + } + const str = String(value); + return repeat("0", length - str.length) + str; +} +function getDate(date) { + return [ + date.getFullYear(), + zpad(date.getMonth() + 1), + zpad(date.getDate()) + ].join("-"); +} +export function getDateTime(date) { + return getDate(date) + " " + [ + zpad(date.getHours()), + zpad(date.getMinutes() + 1) + ].join(":"); +} +//# sourceMappingURL=date.js.map \ No newline at end of file diff --git a/lib.esm/_admin/utils/date.js.map b/lib.esm/_admin/utils/date.js.map new file mode 100644 index 00000000..4989b574 --- /dev/null +++ b/lib.esm/_admin/utils/date.js.map @@ -0,0 +1 @@ +{"version":3,"file":"date.js","sourceRoot":"","sources":["../../../src.ts/_admin/utils/date.ts"],"names":[],"mappings":"AACA,SAAS,MAAM,CAAC,CAAS,EAAE,MAAc;IACrC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,WAAW,CAAC,CAAC;KAAE;IACrD,OAAM,CAAC,CAAC,MAAM,GAAG,MAAM,EAAE;QAAE,CAAC,IAAI,CAAC,CAAC;KAAE;IACpC,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AAClC,CAAC;AAED,SAAS,IAAI,CAAC,KAAa,EAAE,MAAe;IACxC,IAAI,MAAM,IAAI,IAAI,EAAE;QAAE,MAAM,GAAG,CAAC,CAAC;KAAE;IACnC,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC1B,OAAO,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC;AAClD,CAAC;AAED,SAAS,OAAO,CAAC,IAAU;IACvB,OAAO;QACH,IAAI,CAAC,WAAW,EAAE;QAClB,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;QACzB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;KACvB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,IAAU;IAClC,OAAO,OAAO,CAAC,IAAI,CAAC,GAAG,GAAG,GAAG;QACzB,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACrB,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;KAC9B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAChB,CAAC"} \ No newline at end of file diff --git a/lib.esm/_admin/utils/fs.d.ts b/lib.esm/_admin/utils/fs.d.ts new file mode 100644 index 00000000..fc652971 --- /dev/null +++ b/lib.esm/_admin/utils/fs.d.ts @@ -0,0 +1,2 @@ +export declare function atomicWrite(path: string, value: string | Uint8Array): void; +//# sourceMappingURL=fs.d.ts.map \ No newline at end of file diff --git a/lib.esm/_admin/utils/fs.d.ts.map b/lib.esm/_admin/utils/fs.d.ts.map new file mode 100644 index 00000000..787ab509 --- /dev/null +++ b/lib.esm/_admin/utils/fs.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"fs.d.ts","sourceRoot":"","sources":["../../../src.ts/_admin/utils/fs.ts"],"names":[],"mappings":"AAIA,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI,CAI1E"} \ No newline at end of file diff --git a/lib.esm/_admin/utils/fs.js b/lib.esm/_admin/utils/fs.js new file mode 100644 index 00000000..61ed7f29 --- /dev/null +++ b/lib.esm/_admin/utils/fs.js @@ -0,0 +1,8 @@ +import fs from "fs"; +import { resolve } from "./path.js"; +export function atomicWrite(path, value) { + const tmp = resolve(".atomic-tmp"); + fs.writeFileSync(tmp, value); + fs.renameSync(tmp, path); +} +//# sourceMappingURL=fs.js.map \ No newline at end of file diff --git a/lib.esm/_admin/utils/fs.js.map b/lib.esm/_admin/utils/fs.js.map new file mode 100644 index 00000000..8c6507df --- /dev/null +++ b/lib.esm/_admin/utils/fs.js.map @@ -0,0 +1 @@ +{"version":3,"file":"fs.js","sourceRoot":"","sources":["../../../src.ts/_admin/utils/fs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,KAA0B;IAChE,MAAM,GAAG,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IACnC,EAAE,CAAC,aAAa,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC7B,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;AAC7B,CAAC"} \ No newline at end of file diff --git a/lib.esm/_admin/utils/git.d.ts b/lib.esm/_admin/utils/git.d.ts new file mode 100644 index 00000000..4fe7e806 --- /dev/null +++ b/lib.esm/_admin/utils/git.d.ts @@ -0,0 +1,15 @@ +export declare function getGitTag(filename: string): Promise; +export declare function getModifiedTime(filename: string): Promise; +export interface GitLog { + commit: string; + author: string; + date: string; + body: string; +} +export declare function getLogs(files?: null | Array, range?: null | { + tag0: string; + tag1: string; +}, limit?: null | number): Promise>; +export declare function getDiff(filename: string, tag0: string, tag1: string): Promise; +export declare function getTags(): Promise>; +//# sourceMappingURL=git.d.ts.map \ No newline at end of file diff --git a/lib.esm/_admin/utils/git.d.ts.map b/lib.esm/_admin/utils/git.d.ts.map new file mode 100644 index 00000000..a65a0912 --- /dev/null +++ b/lib.esm/_admin/utils/git.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"git.d.ts","sourceRoot":"","sources":["../../../src.ts/_admin/utils/git.ts"],"names":[],"mappings":"AASA,wBAAsB,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,MAAM,CAAC,CAUxE;AAED,wBAAsB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,MAAM,CAAC,CAiB9E;AACD,MAAM,WAAW,MAAM;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,wBAAsB,OAAO,CAAC,KAAK,CAAC,EAAE,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,EAAE,IAAI,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EAAE,KAAK,CAAC,EAAE,IAAI,GAAG,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAoCxJ;AAED,wBAAsB,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAI3F;AAED,wBAAsB,OAAO,IAAI,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAItD"} \ No newline at end of file diff --git a/lib.esm/_admin/utils/git.js b/lib.esm/_admin/utils/git.js new file mode 100644 index 00000000..de2b6c60 --- /dev/null +++ b/lib.esm/_admin/utils/git.js @@ -0,0 +1,94 @@ +import { dirname } from "path"; +import { fileURLToPath } from "url"; +import { run } from "./run.js"; +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); +// Returns the most recent git commit hash for a given filename +export async function getGitTag(filename) { + const result = await run("git", ["log", "-n", "1", "--", filename], __dirname); + if (!result.ok) { + throw new Error(`git log error`); + } + let log = result.stdout.trim(); + if (!log) { + return null; + } + const hashMatch = log.match(/^commit\s+([0-9a-f]{40})\n/i); + if (!hashMatch) { + return null; + } + return hashMatch[1]; +} +export async function getModifiedTime(filename) { + const result = await run("git", ["log", "-n", "1", "--", filename], __dirname); + if (!result.ok) { + throw new Error(`git log error`); + } + let log = result.stdout.trim(); + if (!log) { + return null; + } + for (let line of log.split("\n")) { + line = line.trim(); + if (!line) { + break; + } + const match = line.match(/^date:\s+(.*)$/i); + if (match) { + return (new Date(match[1].trim())).getTime(); + ; + } + } + return null; +} +export async function getLogs(files, range, limit) { + const args = ["log", "-n", String((limit != null) ? limit : 1)]; + if (range) { + args.push(`${range.tag0}..${range.tag1}`); + } + if (files) { + args.push("--"); + files.forEach((f) => args.push(f)); + } + const exec = await run("git", args); + const log = exec.stdout.trim(); + if (!log) { + return []; + } + const results = [{ commit: "", author: "", date: "", body: "" }]; + for (const line of log.split("\n")) { + const hashMatch = line.match(/^commit\s+([0-9a-f]{40})/i); + if (hashMatch) { + results.push({ commit: hashMatch[1], author: "", date: "", body: "" }); + } + else { + if (line.startsWith("Author:")) { + results[results.length - 1].author = line.substring(7).trim(); + } + else if (line.startsWith("Date:")) { + results[results.length - 1].date = line.substring(5).trim(); + } + else { + results[results.length - 1].body = (results[results.length - 1].body + " " + line).trim(); + } + } + } + // Nix the bootstrap entry + results.shift(); + return results; +} +export async function getDiff(filename, tag0, tag1) { + const result = await run("git", ["diff", `${tag0}..${tag1}`, "--", filename]); + if (!result.ok) { + throw new Error(`git log error`); + } + return result.stdout.trim(); +} +export async function getTags() { + const result = await run("git", ["tag"]); + if (!result.ok) { + throw new Error(`git log error`); + } + return result.stdout.trim().split("\n"); +} +//# sourceMappingURL=git.js.map \ No newline at end of file diff --git a/lib.esm/_admin/utils/git.js.map b/lib.esm/_admin/utils/git.js.map new file mode 100644 index 00000000..23dca130 --- /dev/null +++ b/lib.esm/_admin/utils/git.js.map @@ -0,0 +1 @@ +{"version":3,"file":"git.js","sourceRoot":"","sources":["../../../src.ts/_admin/utils/git.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAA;AAEnC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AACjD,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;AAErC,+DAA+D;AAC/D,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,QAAg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I,EAAE,CAAC;AAChC,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,OAAO;IACzB,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,KAAK,EAAE,CAAE,KAAK,CAAE,CAAC,CAAC;IAC3C,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;KAAE;IACrD,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AAC5C,CAAC"} \ No newline at end of file diff --git a/lib.esm/_admin/utils/json.d.ts b/lib.esm/_admin/utils/json.d.ts new file mode 100644 index 00000000..23d3a441 --- /dev/null +++ b/lib.esm/_admin/utils/json.d.ts @@ -0,0 +1,4 @@ +export declare function loadJson(path: string): any; +export type SortFunc = (parent: string, a: string, b: string) => number; +export declare function saveJson(filename: string, data: any, sort?: boolean | SortFunc): any; +//# sourceMappingURL=json.d.ts.map \ No newline at end of file diff --git a/lib.esm/_admin/utils/json.d.ts.map b/lib.esm/_admin/utils/json.d.ts.map new file mode 100644 index 00000000..0dd7f84b --- /dev/null +++ b/lib.esm/_admin/utils/json.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../../src.ts/_admin/utils/json.ts"],"names":[],"mappings":"AAKA,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,CAE1C;AAID,MAAM,MAAM,QAAQ,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;AAExE,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,GAAG,CA0BpF"} \ No newline at end of file diff --git a/lib.esm/_admin/utils/json.js b/lib.esm/_admin/utils/json.js new file mode 100644 index 00000000..511ee937 --- /dev/null +++ b/lib.esm/_admin/utils/json.js @@ -0,0 +1,32 @@ +import fs from "fs"; +import { atomicWrite } from "./fs.js"; +export function loadJson(path) { + return JSON.parse(fs.readFileSync(path).toString()); +} +export function saveJson(filename, data, sort) { + let replacer = undefined; + if (sort) { + replacer = (key, value) => { + if (Array.isArray(value)) { + // pass + } + else if (value && typeof (value) === "object") { + const keys = Object.keys(value); + let sortFunc; + if (typeof (sort) === "function") { + sortFunc = function (a, b) { + return sort(key, a, b); + }; + } + keys.sort(sortFunc); + return keys.reduce((accum, key) => { + accum[key] = value[key]; + return accum; + }, {}); + } + return value; + }; + } + atomicWrite(filename, JSON.stringify(data, replacer, 2) + "\n"); +} +//# sourceMappingURL=json.js.map \ No newline at end of file diff --git a/lib.esm/_admin/utils/json.js.map b/lib.esm/_admin/utils/json.js.map new file mode 100644 index 00000000..0b9c1093 --- /dev/null +++ b/lib.esm/_admin/utils/json.js.map @@ -0,0 +1 @@ +{"version":3,"file":"json.js","sourceRoot":"","sources":["../../../src.ts/_admin/utils/json.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAGtC,MAAM,UAAU,QAAQ,CAAC,IAAY;IACjC,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;AACxD,CAAC;AAMD,MAAM,UAAU,QAAQ,CAAC,QAAgB,EAAE,IAAS,EAAE,IAAyB;IAE3E,IAAI,QAAQ,GAA2B,SAAS,CAAC;IACjD,IAAI,IAAI,EAAE;QACN,QAAQ,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;YACtB,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;gBACtB,OAAO;aACV;iBAAM,IAAI,KAAK,IAAI,OAAM,CAAC,KAAK,CAAC,KAAK,QAAQ,EAAE;gBAC5C,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBAChC,IAAI,QAAwD,CAAC;gBAC7D,IAAI,OAAM,CAAC,IAAI,CAAC,KAAK,UAAU,EAAE;oBAC7B,QAAQ,GAAG,UAAS,CAAS,EAAE,CAAS;wBACpC,OAAO,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;oBAC3B,CAAC,CAAA;iBACJ;gBACD,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBACpB,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;oBAC9B,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;oBACxB,OAAO,KAAK,CAAC;gBACjB,CAAC,EAAuB,EAAE,CAAC,CAAC;aAC/B;YACD,OAAO,KAAK,CAAC;QACjB,CAAC,CAAC;KACL;IAED,WAAW,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;AACpE,CAAC"} \ No newline at end of file diff --git a/lib.esm/_admin/utils/npm.d.ts b/lib.esm/_admin/utils/npm.d.ts new file mode 100644 index 00000000..28b8b6b4 --- /dev/null +++ b/lib.esm/_admin/utils/npm.d.ts @@ -0,0 +1,8 @@ +export declare function _getNpmPackage(name: string): Promise; +export type Version = { + version: string; + gitHead: string; + date: string; +}; +export declare function getVersions(name: string): Promise>; +//# sourceMappingURL=npm.d.ts.map \ No newline at end of file diff --git a/lib.esm/_admin/utils/npm.d.ts.map b/lib.esm/_admin/utils/npm.d.ts.map new file mode 100644 index 00000000..fb3abe2d --- /dev/null +++ b/lib.esm/_admin/utils/npm.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"npm.d.ts","sourceRoot":"","sources":["../../../src.ts/_admin/utils/npm.ts"],"names":[],"mappings":"AAIA,wBAAsB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAQ/D;AAED,MAAM,MAAM,OAAO,GAAG;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAYvE"} \ No newline at end of file diff --git a/lib.esm/_admin/utils/npm.js b/lib.esm/_admin/utils/npm.js new file mode 100644 index 00000000..0b7bb499 --- /dev/null +++ b/lib.esm/_admin/utils/npm.js @@ -0,0 +1,106 @@ +import { FetchRequest } from "../../utils/index.js"; +const cache = {}; +export async function _getNpmPackage(name) { + if (!cache[name]) { + const resp = await (new FetchRequest("https:/\/registry.npmjs.org/" + name)).send(); + resp.assertOk(); + cache[name] = resp.bodyJson; + } + return cache[name] || null; +} +export async function getVersions(name) { + const result = []; + const pkg = await _getNpmPackage(name); + for (const version in pkg.versions) { + const gitHead = pkg.versions[version].gitHead; + const date = pkg.time[version]; + if (gitHead == null || date == null) { + continue; + } + result.push({ date, gitHead, version }); + } + return result; +} +/* +(async function() { + //console.log(await _getNpmPackage("quais")); + console.log(await getGitHeads("quais")); +})(); +*/ +/* +import semver from "semver"; + +import { FetchRequest } from "../../utils/index.js"; + +export type PackageInfo = { + dependencies: { [ name: string ]: string }; + devDependencies: { [ name: string ]: string }; + gitHead: string; + name: string; + version: string; + tarballHash: string; + location: "remote" | "local"; + _quais_nobuild: boolean; +}; + +export class Package { + readonly #info: PackageInfo; + + constructor(info: PackageInfo) { + this.#info = info; + } + + get name(): string { return this.#info.name; } + get version(): string { return this.#info.version; } + + get dependencies(): Record { return this.#info.dependencies; } + get devDependencies(): Record { return this.#info.devDependencies; } + + get gitHead(): string { return this.#info.gitHead; } + get tarballHash(): string { return this.#info.tarballHash; } + +} + + +const cache: Record = { }; + +async function getPackageInfo(name: string): Promise { + if (!cache[name]) { + const resp = await (new FetchRequest("https:/\/registry.npmjs.org/" + name)).send(); + resp.assertOk(); + cache[name] = resp.bodyJson(); + } + + return cache[name] || null; +} + +export async function getPackage(name: string, version?: string): Promise { + const infos = await getPackageInfo(name); + if (infos == null) { return null; } + + if (version == null) { + const versions = Object.keys(infos.versions); + versions.sort(semver.compare); + + // HACK: So v5 continues working while v6 is managed by reticulate + version = "6.0.0"; + while (version.indexOf("beta") >= 0 || semver.gte(version, "6.0.0")) { + version = versions.pop(); + } + } + + const info = infos.versions[version]; + + return new Package({ + dependencies: (info.dependencies || {}), + devDependencies: (info.devDependencies || {}), + gitHead: info.gitHead, + location: "remote", + name: info.name, + tarballHash: info.tarballHash, + version : info.version, + _quais_nobuild: !!info._quais_nobuild, + }); +} +*/ +//# sourceMappingURL=npm.js.map \ No newline at end of file diff --git a/lib.esm/_admin/utils/npm.js.map b/lib.esm/_admin/utils/npm.js.map new file mode 100644 index 00000000..26c0f558 --- /dev/null +++ b/lib.esm/_admin/utils/npm.js.map @@ -0,0 +1 @@ +{"version":3,"file":"npm.js","sourceRoot":"","sources":["../../../src.ts/_admin/utils/npm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,MAAM,KAAK,GAAwB,EAAG,CAAC;AAEvC,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,IAAY;IAC7C,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE;QACd,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,YAAY,CAAC,8BAA8B,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QACpF,IAAI,CAAC,QAAQ,EAAE,CAAC;QAChB,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC;KAC/B;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC;AAC/B,CAAC;AAQD,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,IAAY;IAC1C,MAAM,MAAM,GAAmB,EAAG,CAAC;IAEnC,MAAM,GAAG,GAAG,MAAM,cAAc,CAAC,IAAI,CAAC,CAAC;IACvC,KAAK,MAAM,OAAO,IAAI,GAAG,CAAC,QAAQ,EAAE;QAChC,MAAM,OAAO,GAAG,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC;QAC9C,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC/B,IAAI,OAAO,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,EAAE;YAAE,SAAS;SAAE;QAClD,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;KAC3C;IAED,OAAO,MAAM,CAAC;AAClB,CAAC;AACD;;;;;EAKE;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2EE"} \ No newline at end of file diff --git a/lib.esm/_admin/utils/path.d.ts b/lib.esm/_admin/utils/path.d.ts new file mode 100644 index 00000000..e146d5df --- /dev/null +++ b/lib.esm/_admin/utils/path.d.ts @@ -0,0 +1,3 @@ +export declare const ROOT: string; +export declare function resolve(...args: Array): string; +//# sourceMappingURL=path.d.ts.map \ No newline at end of file diff --git a/lib.esm/_admin/utils/path.d.ts.map b/lib.esm/_admin/utils/path.d.ts.map new file mode 100644 index 00000000..d7794f73 --- /dev/null +++ b/lib.esm/_admin/utils/path.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../../../src.ts/_admin/utils/path.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,IAAI,QAAmC,CAAC;AAErD,wBAAgB,OAAO,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM,CAItD"} \ No newline at end of file diff --git a/lib.esm/_admin/utils/path.js b/lib.esm/_admin/utils/path.js new file mode 100644 index 00000000..83310e29 --- /dev/null +++ b/lib.esm/_admin/utils/path.js @@ -0,0 +1,11 @@ +import { dirname, resolve as _resolve } from "path"; +import { fileURLToPath } from 'url'; +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); +export const ROOT = _resolve(__dirname, "../../../"); +export function resolve(...args) { + args = args.slice(); + args.unshift(ROOT); + return _resolve.apply(null, args); +} +//# sourceMappingURL=path.js.map \ No newline at end of file diff --git a/lib.esm/_admin/utils/path.js.map b/lib.esm/_admin/utils/path.js.map new file mode 100644 index 00000000..264db516 --- /dev/null +++ b/lib.esm/_admin/utils/path.js.map @@ -0,0 +1 @@ +{"version":3,"file":"path.js","sourceRoot":"","sources":["../../../src.ts/_admin/utils/path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAEtC,MAAM,CAAC,MAAM,IAAI,GAAG,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;AAErD,MAAM,UAAU,OAAO,CAAC,GAAG,IAAmB;IAC1C,IAAI,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;IACpB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AACtC,CAAC"} \ No newline at end of file diff --git a/lib.esm/_admin/utils/run.d.ts b/lib.esm/_admin/utils/run.d.ts new file mode 100644 index 00000000..393e7d44 --- /dev/null +++ b/lib.esm/_admin/utils/run.d.ts @@ -0,0 +1,15 @@ +/// +export declare class RunResult { + #private; + constructor(progname: string, args: Array, status: null | number, stdout: string | Buffer, stderr: string | Buffer); + get cmd(): string; + get stderr(): string | null; + get _stderr(): string | Buffer; + get stdout(): string; + get _stdout(): string | Buffer; + get status(): null | number; + get ok(): boolean; + assertOk(message?: string): void; +} +export declare function run(progname: string, args?: Array, currentWorkingDirectory?: string): RunResult; +//# sourceMappingURL=run.d.ts.map \ No newline at end of file diff --git a/lib.esm/_admin/utils/run.d.ts.map b/lib.esm/_admin/utils/run.d.ts.map new file mode 100644 index 00000000..839f4a9a --- /dev/null +++ b/lib.esm/_admin/utils/run.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src.ts/_admin/utils/run.ts"],"names":[],"mappings":";AAEA,qBAAa,SAAS;;gBAMN,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,GAAG,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM;IAO1H,IAAI,GAAG,IAAI,MAAM,CAAsB;IAEvC,IAAI,MAAM,IAAI,MAAM,GAAG,IAAI,CAE1B;IAED,IAAI,OAAO,IAAI,MAAM,GAAG,MAAM,CAE7B;IAED,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,IAAI,OAAO,IAAI,MAAM,GAAG,MAAM,CAE7B;IAED,IAAI,MAAM,IAAI,IAAI,GAAG,MAAM,CAAyB;IAEpD,IAAI,EAAE,IAAI,OAAO,CAEhB;IAED,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI;CAKnC;AAED,wBAAgB,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE,uBAAuB,CAAC,EAAE,MAAM,GAAG,SAAS,CAgBvG"} \ No newline at end of file diff --git a/lib.esm/_admin/utils/run.js b/lib.esm/_admin/utils/run.js new file mode 100644 index 00000000..98761524 --- /dev/null +++ b/lib.esm/_admin/utils/run.js @@ -0,0 +1,54 @@ +import { spawnSync } from "child_process"; +export class RunResult { + #cmd; + #status; + #stdout; + #stderr; + constructor(progname, args, status, stdout, stderr) { + this.#cmd = `${progname} ${args.map((a) => JSON.stringify(a))}`; + this.#status = status; + this.#stdout = stdout; + this.#stderr = stderr; + } + get cmd() { return this.#cmd; } + get stderr() { + return this._stderr.toString() || null; + } + get _stderr() { + return this.#stderr; + } + get stdout() { + return this._stdout.toString(); + } + get _stdout() { + return this.#stdout; + } + get status() { return this.#status; } + get ok() { + return (this.#stderr.length === 0 && this.#status === 0); + } + assertOk(message) { + if (!this.ok) { + throw new Error(message || `failed to run: ${this.#cmd}`); + } + } +} +; +export function run(progname, args, currentWorkingDirectory) { + if (args == null) { + args = []; + } + const options = {}; + if (currentWorkingDirectory) { + options.cwd = currentWorkingDirectory; + } + const child = spawnSync(progname, args, options); + const result = new RunResult(progname, args, child.status, child.stdout, child.stderr); + if (child.error) { + const error = child.error; + error.result = result; + throw error; + } + return result; +} +//# sourceMappingURL=run.js.map \ No newline at end of file diff --git a/lib.esm/_admin/utils/run.js.map b/lib.esm/_admin/utils/run.js.map new file mode 100644 index 00000000..75c8cc8f --- /dev/null +++ b/lib.esm/_admin/utils/run.js.map @@ -0,0 +1 @@ +{"version":3,"file":"run.js","sourceRoot":"","sources":["../../../src.ts/_admin/utils/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,MAAM,OAAO,SAAS;IACT,IAAI,CAAS;IACb,OAAO,CAAgB;IACvB,OAAO,CAAkB;IACzB,OAAO,CAAkB;IAElC,YAAY,QAAgB,EAAE,IAAmB,EAAE,MAAqB,EAAE,MAAuB,EAAE,MAAuB;QACtH,IAAI,CAAC,IAAI,GAAG,GAAI,QAAS,IAAK,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,E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IACvE,MAAM,KAAK,GAAG,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAEjD,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAEvF,IAAI,KAAK,CAAC,KAAK,EAAE;QACb,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;QACpB,KAAM,CAAC,MAAM,GAAG,MAAM,CAAC;QAC7B,MAAM,KAAK,CAAC;KACf;IAED,OAAO,MAAM,CAAC;AAClB,CAAC"} \ No newline at end of file diff --git a/lib.esm/_tests/blockchain-data.d.ts b/lib.esm/_tests/blockchain-data.d.ts new file mode 100644 index 00000000..1af3cb50 --- /dev/null +++ b/lib.esm/_tests/blockchain-data.d.ts @@ -0,0 +1,85 @@ +export type TestBlockchainNetwork = "mainnet" | "goerli"; +export interface TestBlockchainAddress { + test: string; + address: string; + code?: string; + nonce?: number; + name?: string; + balance?: bigint; + storage?: Record; +} +export interface TestBlockchainBlock { + test: string; + hash: string; + parentHash: string; + number: number; + timestamp: number; + nonce: string; + difficulty: bigint; + gasLimit: bigint; + gasUsed: bigint; + miner: string; + extraData: string; + transactions: Array; + baseFeePerGas?: bigint; +} +export interface TestBlockchainTransaction { + test: string; + hash: string; + blockHash: string; + blockNumber: number; + type: number; + from: string; + gasPrice: bigint; + gasLimit: bigint; + to: string; + value: bigint; + nonce: number; + data: string; + signature: { + r: string; + s: string; + yParity: 0 | 1; + v: number; + networkV: null | bigint; + }; + creates: null | string; + chainId: bigint; + accessList?: Array>>; + maxPriorityFeePerGas?: bigint; + maxFeePerGas?: bigint; +} +export interface TestBlockchainReceipt { + test: string; + blockHash: string; + blockNumber: number; + type: number; + contractAddress: null | string; + cumulativeGasUsed: bigint; + from: string; + gasUsed: bigint; + gasPrice: bigint; + logs: Array<{ + address: string; + blockHash: string; + blockNumber: number; + data: string; + index: number; + topics: Array; + transactionHash: string; + transactionIndex: number; + }>; + logsBloom: string; + root: null | string; + status: null | number; + to: string; + hash: string; + index: number; +} +export declare const testAddress: Record>; +export declare const testBlock: Record>; +export declare const testTransaction: Record>; +export declare const testReceipt: Record>; +export declare const networkNames: Array; +export declare function networkFeatureAtBlock(feature: string, block: number): boolean; +//# sourceMappingURL=blockchain-data.d.ts.map \ No newline at end of file diff --git a/lib.esm/_tests/blockchain-data.d.ts.map b/lib.esm/_tests/blockchain-data.d.ts.map new file mode 100644 index 00000000..1a30177f --- /dev/null +++ b/lib.esm/_tests/blockchain-data.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"blockchain-data.d.ts","sourceRoot":"","sources":["../../src.ts/_tests/blockchain-data.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,qBAAqB,GAC7B,SAAS,GAAG,QAAQ,CAAC;AAEzB,MAAM,WAAW,qBAAqB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACnC;AAED,MAAM,WAAW,mBAAmB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,KAAK,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E,KAAK,CAAC;QACR,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,MAAM,CAAC;QAClB,WAAW,EAAE,MAAM,CAAC;QACpB,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;QACtB,eAAe,EAAE,MAAM,CAAC;QACxB,gBAAgB,EAAE,MAAM,CAAC;KAC5B,CAAC,CAAA;IACF,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,IAAI,GAAG,MAAM,CAAC;IACpB,MAAM,EAAE,IAAI,GAAG,MAAM,CAAC;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAA;CAChB;AAED,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,qBAAqB,EAAE,KAAK,CAAC,qBAAqB,CAAC,CAuBnF,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,qBAAqB,EAAE,KAAK,CAAC,mBAAmB,CAAC,CA8D/E,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,qBAAqB,EAAE,KAAK,CAAC,yBAAyB,CAAC,CAwD3F,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,qBAAqB,EAAE,KAAK,CAAC,qBAAqB,CAAC,CAsFnF,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,qBAAqB,CAErD,CAAC;AACF,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAQ7E"} \ No newline at end of file diff --git a/lib.esm/_tests/blockchain-data.js b/lib.esm/_tests/blockchain-data.js new file mode 100644 index 00000000..9c6f8321 --- /dev/null +++ b/lib.esm/_tests/blockchain-data.js @@ -0,0 +1,241 @@ +; +export const testAddress = { + mainnet: [ + { + test: "old-account", + address: "0xAC1639CF97a3A46D431e6d1216f576622894cBB5", + balance: BigInt("4813414100000000"), + nonce: 3, + code: "0x" + }, { + test: "TheDAO-splitter-contract", + address: "0x3474627D4F63A678266BC17171D87f8570936622", + code: "0x606060405260e060020a60003504630b3ed5368114602e57806337b0574a14605257806356fa47f0146062575b005b602c6004356000546101009004600160a060020a03908116339091161460bb575b50565b60005460ff166060908152602090f35b602c60043560005460ff1615609657600160a060020a038116600034606082818181858883f193505050501515604f576002565b33600160a060020a0316600034606082818181858883f193505050501515604f576002565b600080546101009004600160a060020a03169082606082818181858883f193505050501515604f57600256", + storage: { + "0": "0x0000000000000000000000b2682160c482eb985ec9f3e364eec0a904c44c2300" + } + }, { + test: "ricmoo.firefly.eth", + address: "0x8ba1f109551bD432803012645Ac136ddd64DBA72", + name: "ricmoo.firefly.eth" + }, + ], + goerli: [] +}; +export const testBlock = { + mainnet: [ + { + test: "old-homestead-block", + hash: "0x3d6122660cc824376f11ee842f83addc3525e2dd6756b9bcf0affa6aa88cf741", + parentHash: "0xb495a1d7e6663152ae92708da4843337b958146015a2802f4193a410044698c9", + number: 3, + timestamp: 1438270048, + nonce: "0x2e9344e0cbde83ce", + difficulty: BigInt(17154715646), + gasLimit: BigInt("0x1388"), + gasUsed: BigInt("0"), + miner: "0x5088D623ba0fcf0131E0897a91734A4D83596AA0", + extraData: "0x476574682f76312e302e302d66633739643332642f6c696e75782f676f312e34", + transactions: [] + }, + { + test: "london-block", + number: 14413999, + hash: "0x6c79356d40ebb6ed63dc19f5d407f8f1c876047b59dc1a4598cce0e64dcabec5", + parentHash: "0xbf09b0e215f247a5066d19ece5b4c66960771d45fae62985e8d751fb1adcfe2f", + timestamp: 1647654576, + nonce: "0xb4bc9979af5369fe", + difficulty: BigInt("12841513359509721"), + gasLimit: BigInt("30087914"), + gasUsed: BigInt("2008910"), + miner: "0x2A20380DcA5bC24D052acfbf79ba23e988ad0050", + extraData: "0x706f6f6c696e2e636f6d21f7092f019bb92a76", + baseFeePerGas: BigInt("40911884304"), + transactions: [ + "0x1c3a398933db10634631f54b435c40c8805c13f12bbac7c3dab858ca44213fa2", + "0xd98947cbdd892cc7f679c903903e6d18a5c5afb19e94437beba79372ad71c347", + "0x4d66190deb55b5820cb0ce9adb972f646fa0f3e64eaeee674bbf3d054bf3d883", + "0x9db7bd5f4c91d6103c714bcbc35df3dc708daa668aaef7449b589dbd3be24dac", + "0x126a43ae4ade4b7fc5c8ac9ebd3dbcf7314f63c60f2804fb49aa25b5c7d80bb1", + "0x82a90aa4b3b1b7873b117c3ff1ca7165ae34b2fc0788cc0cbfd41805d588590d", + "0x7f694a6a9972457753ed3dec164f17272b1c8b1da4eab149df95e31a3e72f606", + "0xdce1cba1ff33f0c23881087d49de3b34fe84c8a6883f3edd75b04fc23e458aac", + "0xbe1c69f825279cebef42d1f0e07397dcddef7fb278b0195e295ede3e156836c4", + "0x1d2f007b3c0f894403973a30e5ffaa78589f873d963e9554c6bb1bd7a3127245", + "0x9c8c78191cf4ae9ae8eee1165153eabe24dbd8b9509b83d5f0caeea85251bb2f", + "0x42e956f4b3dd6535359b272a0d2dab995c364cb48baaf8d0a1981995f3f8c808", + "0xdc2c2e99393e24d5dc66e38665fa1d1ff007d92088ef3fd2549545fdbe862ef6", + "0xaad7be28fffd2e77e8e40bf57f2ac140aa8283ec93c7f3f61a82c79405602f53", + "0x4735f1421b7b30283e87e0799e82e54307d3e5ba14cd54ad8420b57577489a71", + "0x0b9d6aa23aa439b41e86595f2ad91f498adffa3e6e7cb26ac7d73252e59fd3de", + "0xcd93e19bd5d5c5a834fec613116fa01f46eddfd2faa20ef302271b874b9d812a", + "0x5bf1976574a637f5ac0b8bda1a792fa16cc7ce9624d32e9bd6bd9aa6a8f19d2f", + "0x2e778da4f66f10f7b681b605635c6599cdbeea167fc1c4396a097aef5d06de61", + "0xd5fd68eebc4c870ccda081786a74c75c250e9e2d8269b8935edb3adb11b80bb2", + "0x2aec42a11c1d8c1e5198d54aacbc6bebb09bcd5e78f6af81ea09d65c9064734a", + "0xbea2e364ea4959ec438d9ccc2d2f7120c7eaba3b177cc0d7df8ff65d866ef89f", + "0xf48bbb0f838353060da4126a555ce532abf497a9d1108001afffaac513a59ddf", + "0xf5664e4372cce62733a6610efb7701a4a0e552d81f8caa764d8474b3070c6617", + "0x9d3732ddbd20610008ff737da2f61120734a1cbfa864374bcbcf10051e6048cb", + "0xc4d0df5bc6fa51b34ac3c898866d779d4e51a6be4d13be1ec3084b7229b03b47", + "0x90c86ec98b8ad98049b4ee54cb3aa72c5ae743077b830e8a294aa5dc47a1fb18" + ] + } + ], + goerli: [], +}; +export const testTransaction = { + mainnet: [ + { + test: "legacy", + hash: "0xccc90ab97a74c952fb3376c4a3efb566a58a10df62eb4d44a61e106fcf10ec61", + blockHash: "0x9653f180a5720f3634816eb945a6d722adee52cc47526f6357ac10adaf368135", + blockNumber: 4097745, + // index: 18, + type: 0, + from: "0x32DEF047DeFd076DB21A2D759aff2A591c972248", + gasPrice: BigInt("0x4a817c800"), + gasLimit: BigInt("0x3d090"), + to: "0x6fC21092DA55B392b045eD78F4732bff3C580e2c", + value: BigInt("0x186cc6acd4b0000"), + nonce: 0, + data: "0xf2c298be000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000067269636d6f6f0000000000000000000000000000000000000000000000000000", + signature: { + r: "0x1e5605197a03e3f0a168f14749168dfeefc44c9228312dacbffdcbbb13263265", + s: "0x269c3e5b3558267ad91b0a887d51f9f10098771c67b82ea6cb74f29638754f54", + yParity: 1, + v: 28, + networkV: BigInt(38), + }, + creates: null, + chainId: BigInt(1) + }, + { + test: "EIP-1559", + hash: "0x8ff41d0ba5d239acc8c123ff12451a2c15721c838f657e583d355999af4a4349", + blockHash: '0x9d4c3bef68e119841281105da96beb1c7252f357340d7a3355236b3332b197b0', + blockNumber: 12966000, + // index: 185, + type: 2, + from: '0x5afFBa12E9332bbc0E221c8E7BEf7CB7cfB3F281', + to: '0x2258CcD34ae29E6B199b6CD64eb2aEF157df7CdE', + gasLimit: BigInt("21000"), + nonce: 2, + data: '0x', + value: BigInt("1100000000000000"), + gasPrice: BigInt("70578812137"), + maxPriorityFeePerGas: BigInt("1000000000"), + maxFeePerGas: BigInt("131115411100"), + chainId: BigInt(1), + signature: { + r: "0xdd26e5478d0aa84e334a0393d335ab24b83de8ecae9290305f15ab884ded246c", + s: "0x6494b4f61b0d9a5a82ecb86d72b301f859f404f0bec9682bbfff619903ecfbe2", + yParity: 1, + v: 28, + networkV: null + }, + creates: null, + accessList: [] + } + ], + goerli: [] +}; +export const testReceipt = { + mainnet: [ + { + test: "legacy", + //byzantium: false, + blockHash: "0x36b4af7f0538559e581c8588f16477df0f676439ea67fe8d7a2ae4abb20e2566", + blockNumber: 0x3c92b5, + type: 0, + contractAddress: null, + cumulativeGasUsed: BigInt(0x1cca2e), + from: "0x18C6045651826824FEBBD39d8560584078d1b247", + gasUsed: BigInt(0x14bb7), + gasPrice: BigInt(4100000000), + logs: [ + { + address: "0x314159265dD8dbb310642f98f50C066173C1259b", + blockHash: "0x36b4af7f0538559e581c8588f16477df0f676439ea67fe8d7a2ae4abb20e2566", + blockNumber: 0x3c92b5, + data: "0x00000000000000000000000018c6045651826824febbd39d8560584078d1b247", + index: 0x1a, + topics: [ + "0xce0457fe73731f824cc272376169235128c118b49d344817417c6d108d155e82", + "0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae", + "0xf0106919d12469348e14ad6a051d0656227e1aba2fefed41737fdf78421b20e1" + ], + transactionHash: "0xc6fcb7d00d536e659a4559d2de29afa9e364094438fef3e72ba80728ce1cb616", + transactionIndex: 0x39, + }, + { + address: "0x6090A6e47849629b7245Dfa1Ca21D94cd15878Ef", + blockHash: "0x36b4af7f0538559e581c8588f16477df0f676439ea67fe8d7a2ae4abb20e2566", + blockNumber: 0x3c92b5, + data: "0x000000000000000000000000000000000000000000000000002386f26fc1000000000000000000000000000000000000000000000000000000000000595a32ce", + index: 0x1b, + topics: [ + "0x0f0c27adfd84b60b6f456b0e87cdccb1e5fb9603991588d87fa99f5b6b61e670", + "0xf0106919d12469348e14ad6a051d0656227e1aba2fefed41737fdf78421b20e1", + "0x00000000000000000000000018c6045651826824febbd39d8560584078d1b247" + ], + transactionHash: "0xc6fcb7d00d536e659a4559d2de29afa9e364094438fef3e72ba80728ce1cb616", + transactionIndex: 0x39, + } + ], + logsBloom: "0x00000000000000040000000000100000010000000000000040000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000200000010000000004000000000000000000000000000000000002000000000000000000000000400000000020000000000000000000000000000000000000004000000000000000000000000000000000000000000000000801000000000000000000000020000000000040000000040000000000000000002000000004000000000000000000000000000000000000000000000010000000000000000000000000000000000200000000000000000", + root: "0x9b550a9a640ce50331b64504ef87aaa7e2aaf97344acb6ff111f879b319d2590", + // Should be null for pre-byzantium, but some nodes have backfilled it + status: 1, + to: "0x6090A6e47849629b7245Dfa1Ca21D94cd15878Ef", + hash: "0xc6fcb7d00d536e659a4559d2de29afa9e364094438fef3e72ba80728ce1cb616", + index: 0x39 + }, { + test: "byzantium", + //byzantium: true, + blockHash: "0x34e5a6cfbdbb84f7625df1de69d218ade4da72f4a2558064a156674e72e976c9", + blockNumber: 0x444f76, + type: 0, + contractAddress: null, + cumulativeGasUsed: BigInt(0x15bfe7), + from: "0x18C6045651826824FEBBD39d8560584078d1b247", + gasUsed: BigInt(0x1b968), + gasPrice: BigInt(1000000000), + logs: [ + { + address: "0xb90E64082D00437e65A76d4c8187596BC213480a", + blockHash: "0x34e5a6cfbdbb84f7625df1de69d218ade4da72f4a2558064a156674e72e976c9", + blockNumber: 0x444f76, + data: "0x", + index: 0x10, + topics: [ + "0x748d071d1992ee1bfe7a39058114d0a50d5798fe8eb3a9bfb4687f024629a2ce", + "0x5574aa58f7191ccab6de6cf75fe2ea0484f010b852fdd8c6b7ae151d6c2f4b83" + ], + transactionHash: "0x7f1c6a58dc880438236d0b0a4ae166e9e9a038dbea8ec074149bd8b176332cac", + transactionIndex: 0x1e, + } + ], + logsBloom: "0x00000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000200000000000000008000000000000000000000000000000000000000000000000000000000000000010000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000800000000000000000800000000000000000000000000000000000000", + root: null, + status: 1, + to: "0xb90E64082D00437e65A76d4c8187596BC213480a", + hash: "0x7f1c6a58dc880438236d0b0a4ae166e9e9a038dbea8ec074149bd8b176332cac", + index: 0x1e + } + ], + goerli: [] +}; +export const networkNames = [ + "mainnet", "goerli" +]; +export function networkFeatureAtBlock(feature, block) { + switch (feature) { + case "byzantium": + return block >= 4370000; + default: + break; + } + throw new Error(`unknown feature: ${feature}`); +} +//# sourceMappingURL=blockchain-data.js.map \ No newline at end of file diff --git a/lib.esm/_tests/blockchain-data.js.map b/lib.esm/_tests/blockchain-data.js.map new file mode 100644 index 00000000..e594fe23 --- /dev/null +++ b/lib.esm/_tests/blockchain-data.js.map @@ -0,0 +1 @@ +{"version":3,"file":"blockchain-data.js","sourceRoot":"","sources":["../../src.ts/_tests/blockchain-data.ts"],"names":[],"mappings":"AAuFC,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAgE;IACpF,OAAO,EAAE;QACL;YACI,IAAI,EAAE,aAAa;YACnB,OAAO,EAAE,4CAA4C;YACrD,OAAO,EAAE,MAAM,CAAC,kBAAkB,CAAC;YACnC,KAAK,EAAE,CAAC;YACR,IAAI,EAAE,IAAI;SACb,EAAE;YACC,IAAI,EAAE,0BAA0B;YAChC,OAAO,EAAE,4CAA4C;YACrD,IAAI,EAAE,kdAAkd;YACxd,OAAO,EAAE;gBACL,GAAG,EAAE,oEAAoE;aAC5E;SACJ,EAAE;YACC,IAAI,EAAE,oBAAoB;YAC1B,OAAO,EAAE,4CAA4C;YACrD,IAAI,EAAE,oBAAoB;SAC7B;KACJ;IACD,MAAM,EAAE,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rD,CAAC"} \ No newline at end of file diff --git a/lib.esm/_tests/contracts/QRC20.d.ts b/lib.esm/_tests/contracts/QRC20.d.ts new file mode 100644 index 00000000..503cb874 --- /dev/null +++ b/lib.esm/_tests/contracts/QRC20.d.ts @@ -0,0 +1,50 @@ +declare const QRC20: { + _format: string; + contractName: string; + sourceName: string; + abi: ({ + inputs: { + internalType: string; + name: string; + type: string; + }[]; + stateMutability: string; + type: string; + anonymous?: undefined; + name?: undefined; + outputs?: undefined; + } | { + anonymous: boolean; + inputs: { + indexed: boolean; + internalType: string; + name: string; + type: string; + }[]; + name: string; + type: string; + stateMutability?: undefined; + outputs?: undefined; + } | { + inputs: { + internalType: string; + name: string; + type: string; + }[]; + name: string; + outputs: { + internalType: string; + name: string; + type: string; + }[]; + stateMutability: string; + type: string; + anonymous?: undefined; + })[]; + bytecode: string; + deployedBytecode: string; + linkReferences: {}; + deployedLinkReferences: {}; +}; +export default QRC20; +//# sourceMappingURL=QRC20.d.ts.map \ No newline at end of file diff --git a/lib.esm/_tests/contracts/QRC20.d.ts.map b/lib.esm/_tests/contracts/QRC20.d.ts.map new file mode 100644 index 00000000..d2320201 --- /dev/null +++ b/lib.esm/_tests/contracts/QRC20.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"QRC20.d.ts","sourceRoot":"","sources":["../../../src.ts/_tests/contracts/QRC20.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4dV,CAAA;AAGD,eAAe,KAAK,CAAC"} \ No newline at end of file diff --git a/lib.esm/_tests/contracts/QRC20.js b/lib.esm/_tests/contracts/QRC20.js new file mode 100644 index 00000000..878d85c2 --- /dev/null +++ b/lib.esm/_tests/contracts/QRC20.js @@ -0,0 +1,479 @@ +const QRC20 = { + "_format": "hh-sol-artifact-1", + "contractName": "QRC20", + "sourceName": "contracts/QRC20.sol", + "abi": [ + { + "inputs": [ + { + "internalType": "string", + "name": "name_", + "type": "string" + }, + { + "internalType": "string", + "name": "symbol_", + "type": "string" + }, + { + "internalType": "uint256", + "name": "initialSupply_", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "ExternalTransfer", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "uint8[]", + "name": "chain", + "type": "uint8[]" + }, + { + "internalType": "address[]", + "name": "addr", + "type": "address[]" + } + ], + "name": "AddApprovedAddresses", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "ApprovedAddresses", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "Ranges", + "outputs": [ + { + "internalType": "uint8", + "name": "low", + "type": "uint8" + }, + { + "internalType": "uint8", + "name": "high", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "internalType": "address", + "name": "spender", + "type": "address" + } + ], + "name": "allowance", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "approve", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "balanceOf", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "gasLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minerTip", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "baseFee", + "type": "uint256" + } + ], + "name": "crossChainTransfer", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [], + "name": "decimals", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "subtractedValue", + "type": "uint256" + } + ], + "name": "decreaseAllowance", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "addr", + "type": "address" + } + ], + "name": "getAddressLocation", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "incomingTransfer", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "addedValue", + "type": "uint256" + } + ], + "name": "increaseAllowance", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "name", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "symbol", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "a", + "type": "address" + } + ], + "name": "toBytes", + "outputs": [ + { + "internalType": "bytes", + "name": "", + "type": "bytes" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [], + "name": "totalSupply", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "transfer", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "transferFrom", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + } + ], + "bytecode": "0x60806040523480156200001157600080fd5b5060405162001f7238038062001f72833981016040819052620000349162000325565b600f62000042848262000426565b50601062000051838262000426565b50601180546001600160a01b03191633908117909155819062000075908262000195565b505060408051808201825260008152601d60209182015260128054611d0061ffff199182161790915582518084018452601e8152603a90830152601380548216613a1e17905582518084018452603b815260579083015260148054821661573b17905582518084018452605881526073908301526015805482166173581790558251808401845260748152608f90830152601680548216618f74179055825180840184526090815260ab9083015260178054821661ab901790558251808401845260ac815260c79083015260188054821661c7ac1790558251808401845260c8815260e39083015260198054821661e3c8179055825180840190935260e4835260ff9290910191909152601a805490911661ffe4179055506200051a9050565b6001600160a01b038216620001f05760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015260640160405180910390fd5b80600e6000828254620002049190620004f2565b90915550506001600160a01b038216600081815260208181526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b505050565b634e487b7160e01b600052604160045260246000fd5b600082601f8301126200028857600080fd5b81516001600160401b0380821115620002a557620002a562000260565b604051601f8301601f19908116603f01168101908282118183101715620002d057620002d062000260565b81604052838152602092508683858801011115620002ed57600080fd5b600091505b83821015620003115785820183015181830184015290820190620002f2565b600093810190920192909252949350505050565b6000806000606084860312156200033b57600080fd5b83516001600160401b03808211156200035357600080fd5b620003618783880162000276565b945060208601519150808211156200037857600080fd5b50620003878682870162000276565b925050604084015190509250925092565b600181811c90821680620003ad57607f821691505b602082108103620003ce57634e487b7160e01b600052602260045260246000fd5b50919050565b601f8211156200025b57600081815260208120601f850160051c81016020861015620003fd5750805b601f850160051c820191505b818110156200041e5782815560010162000409565b505050505050565b81516001600160401b0381111562000442576200044262000260565b6200045a8162000453845462000398565b84620003d4565b602080601f831160018114620004925760008415620004795750858301515b600019600386901b1c1916600185901b1785556200041e565b600085815260208120601f198616915b82811015620004c357888601518255948401946001909101908401620004a2565b5085821015620004e25787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b808201808211156200051457634e487b7160e01b600052601160045260246000fd5b92915050565b611a48806200052a6000396000f3fe6080604052600436106101295760003560e01c8063593b79fe116100a5578063a457c2d711610074578063a9059cbb11610059578063a9059cbb14610375578063bc472aa314610395578063dd62ed3e146103cd57600080fd5b8063a457c2d714610335578063a534d9de1461035557600080fd5b8063593b79fe1461028657806370a08231146102d757806373cddab21461030d57806395d89b411461032057600080fd5b806323b872dd116100fc57806339509351116100e1578063395093511461020c578063399444bc1461022c578063429437bf1461024c57600080fd5b806323b872dd146101ca578063313ce567146101ea57600080fd5b806306fdde031461012e578063095ea7b31461015957806318160ddd1461018957806320e8dd93146101a8575b600080fd5b34801561013a57600080fd5b50610143610413565b60405161015091906115a8565b60405180910390f35b34801561016557600080fd5b506101796101743660046115de565b6104a5565b6040519015158152602001610150565b34801561019557600080fd5b50600e545b604051908152602001610150565b3480156101b457600080fd5b506101c86101c33660046115de565b6104bc565b005b3480156101d657600080fd5b506101796101e5366004611608565b61056d565b3480156101f657600080fd5b5060125b60405160ff9091168152602001610150565b34801561021857600080fd5b506101796102273660046115de565b61058f565b34801561023857600080fd5b506101fa610247366004611644565b6105ce565b34801561025857600080fd5b5061026c61026736600461165f565b6106e5565b6040805160ff938416815292909116602083015201610150565b34801561029257600080fd5b506101436102a1366004611644565b604051606082811b6bffffffffffffffffffffffff19166020830152906034016040516020818303038152906040529050919050565b3480156102e357600080fd5b5061019a6102f2366004611644565b6001600160a01b031660009081526020819052604090205490565b6101c861031b366004611678565b610708565b34801561032c57600080fd5b5061014361094c565b34801561034157600080fd5b506101796103503660046115de565b61095b565b34801561036157600080fd5b506101c8610370366004611706565b610a10565b34801561038157600080fd5b506101796103903660046115de565b610ce1565b3480156103a157600080fd5b506103b56103b036600461165f565b610cee565b6040516001600160a01b039091168152602001610150565b3480156103d957600080fd5b5061019a6103e8366004611772565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6060600f8054610422906117a5565b80601f016020809104026020016040519081016040528092919081815260200182805461044e906117a5565b801561049b5780601f106104705761010080835404028352916020019161049b565b820191906000526020600020905b81548152906001019060200180831161047e57829003601f168201915b5050505050905090565b60006104b2338484610d0e565b5060015b92915050565b3360026104c8826105ce565b60ff16600c81106104db576104db6117df565b01546040516bffffffffffffffffffffffff193360601b1660208201526001600160a01b03909116919091149060340160408051601f1981840301815290829052610528916020016117f5565b6040516020818303038152906040529061055e5760405162461bcd60e51b815260040161055591906115a8565b60405180910390fd5b506105698282610edc565b5050565b600061057a843384610f9b565b61058584848461102d565b5060019392505050565b3360008181526001602090815260408083206001600160a01b038716845290915281205490919061058590829086906105c9908790611877565b610d0e565b604080516bffffffffffffffffffffffff19606084901b1660208201528151601481830301815260349091019091526000908190600081518110610614576106146117df565b016020015160f81c905060005b60098160ff16101561069c5760128160ff16600d8110610643576106436117df565b015460ff9081169083161080159061067e575060128160ff16600d811061066c5761066c6117df565b015460ff610100909104811690831611155b1561068a579392505050565b806106948161188a565b915050610621565b5060405162461bcd60e51b815260206004820152601060248201527f496e76616c6964204c6f636174696f6e000000000000000000000000000000006044820152606401610555565b601281600d81106106f557600080fd5b015460ff80821692506101009091041682565b84f780156107585760405162461bcd60e51b815260206004820152601760248201527f41646472657373206973206e6f742065787465726e616c0000000000000000006044820152606401610555565b610762338661128f565b6000600261076f886105ce565b60ff16600c8110610782576107826117df565b01546001600160a01b03169050806108025760405162461bcd60e51b815260206004820152602f60248201527f546f6b656e206973206e6f7420617661696c61626c65206f6e2074686520646560448201527f7374696e6174696f6e20636861696e00000000000000000000000000000000006064820152608401610555565b60008561080f8686611877565b61081991906118a9565b905080341015610828826113f8565b60405160200161083891906118c0565b604051602081830303815290604052906108655760405162461bcd60e51b815260040161055591906115a8565b506040516001600160a01b03891660248201526044810188905260009060640160408051601f198184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f20e8dd930000000000000000000000000000000000000000000000000000000017815281519192506000918291829190898b8d858b81f69050896001600160a01b0316336001600160a01b03167fcf0ee562475620bbcd2f1b0675c8163317513271e4fdbbe9722436f247bd6d998b60405161093891815260200190565b60405180910390a350505050505050505050565b606060108054610422906117a5565b3360008181526001602090815260408083206001600160a01b0387168452909152812054909190838110156109f85760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f7760448201527f207a65726f0000000000000000000000000000000000000000000000000000006064820152608401610555565b610a058286868403610d0e565b506001949350505050565b6011546001600160a01b03163314610a6a5760405162461bcd60e51b815260206004820152601660248201527f53656e646572206973206e6f74206465706c6f796572000000000000000000006044820152606401610555565b828114610adf5760405162461bcd60e51b815260206004820152603060248201527f636861696e20616e64206164647265737320617272617973206d75737420626560448201527f207468652073616d65206c656e677468000000000000000000000000000000006064820152608401610555565b60005b60ff8116841115610cda57600985858360ff16818110610b0457610b046117df565b9050602002016020810190610b199190611952565b60ff1610610b695760405162461bcd60e51b815260206004820152600b60248201527f4d61782039207a6f6e65730000000000000000000000000000000000000000006044820152606401610555565b60006002868660ff8516818110610b8257610b826117df565b9050602002016020810190610b979190611952565b60ff16600c8110610baa57610baa6117df565b01546001600160a01b031614610c285760405162461bcd60e51b815260206004820152603160248201527f54686520617070726f766564206164647265737320666f722074686973207a6f60448201527f6e6520616c7265616479206578697374730000000000000000000000000000006064820152608401610555565b82828260ff16818110610c3d57610c3d6117df565b9050602002016020810190610c529190611644565b600286868460ff16818110610c6957610c696117df565b9050602002016020810190610c7e9190611952565b60ff16600c8110610c9157610c916117df565b0180547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b039290921691909117905580610cd28161188a565b915050610ae2565b5050505050565b60006104b233848461102d565b600281600c8110610cfe57600080fd5b01546001600160a01b0316905081565b81f780610d835760405162461bcd60e51b815260206004820152603f60248201527f5370656e64657220616464726573732069732065787465726e616c2e2055736560448201527f2063726f73732d636861696e207472616e736665722066756e6374696f6e2e006064820152608401610555565b6001600160a01b038416610dfe5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f2061646460448201527f72657373000000000000000000000000000000000000000000000000000000006064820152608401610555565b6001600160a01b038316610e7a5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f20616464726560448201527f73730000000000000000000000000000000000000000000000000000000000006064820152608401610555565b6001600160a01b0384811660008181526001602090815260408083209488168084529482529182902086905590518581527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a350505050565b6001600160a01b038216610f325760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610555565b80600e6000828254610f449190611877565b90915550506001600160a01b038216600081815260208181526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b6001600160a01b038381166000908152600160209081526040808320938616835292905220546000198114611027578181101561101a5760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606401610555565b6110278484848403610d0e565b50505050565b81f7806110a25760405162461bcd60e51b815260206004820152603760248201527f416464726573732069732065787465726e616c2e205573652063726f73732d6360448201527f6861696e207472616e736665722066756e6374696f6e2e0000000000000000006064820152608401610555565b6001600160a01b03841661111e5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f20616460448201527f64726573730000000000000000000000000000000000000000000000000000006064820152608401610555565b6001600160a01b03831661119a5760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201527f65737300000000000000000000000000000000000000000000000000000000006064820152608401610555565b6001600160a01b038416600090815260208190526040902054828110156112295760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e742065786365656473206260448201527f616c616e636500000000000000000000000000000000000000000000000000006064820152608401610555565b6001600160a01b03858116600081815260208181526040808320888703905593881680835291849020805488019055925186815290927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a3610cda565b6001600160a01b03821661130b5760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f2061646472657360448201527f73000000000000000000000000000000000000000000000000000000000000006064820152608401610555565b6001600160a01b0382166000908152602081905260409020548181101561139a5760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e60448201527f63650000000000000000000000000000000000000000000000000000000000006064820152608401610555565b6001600160a01b0383166000818152602081815260408083208686039055600e80548790039055518581529192917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a3505050565b60608160000361143b57505060408051808201909152600181527f3000000000000000000000000000000000000000000000000000000000000000602082015290565b8160005b8115611465578061144f81611975565b915061145e9050600a8361198e565b915061143f565b60008167ffffffffffffffff811115611480576114806119b0565b6040519080825280601f01601f1916602001820160405280156114aa576020820181803683370190505b509050815b851561154f576114c06001826119c6565b905060006114cf600a8861198e565b6114da90600a6118a9565b6114e490886119c6565b6114ef9060306119d9565b905060008160f81b90508084848151811061150c5761150c6117df565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350611546600a8961198e565b975050506114af565b50949350505050565b60005b8381101561157357818101518382015260200161155b565b50506000910152565b60008151808452611594816020860160208601611558565b601f01601f19169290920160200192915050565b6020815260006115bb602083018461157c565b9392505050565b80356001600160a01b03811681146115d957600080fd5b919050565b600080604083850312156115f157600080fd5b6115fa836115c2565b946020939093013593505050565b60008060006060848603121561161d57600080fd5b611626846115c2565b9250611634602085016115c2565b9150604084013590509250925092565b60006020828403121561165657600080fd5b6115bb826115c2565b60006020828403121561167157600080fd5b5035919050565b600080600080600060a0868803121561169057600080fd5b611699866115c2565b97602087013597506040870135966060810135965060800135945092505050565b60008083601f8401126116cc57600080fd5b50813567ffffffffffffffff8111156116e457600080fd5b6020830191508360208260051b85010111156116ff57600080fd5b9250929050565b6000806000806040858703121561171c57600080fd5b843567ffffffffffffffff8082111561173457600080fd5b611740888389016116ba565b9096509450602087013591508082111561175957600080fd5b50611766878288016116ba565b95989497509550505050565b6000806040838503121561178557600080fd5b61178e836115c2565b915061179c602084016115c2565b90509250929050565b600181811c908216806117b957607f821691505b6020821081036117d957634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052603260045260246000fd5b7f53656e646572200000000000000000000000000000000000000000000000000081526000825161182d816007850160208701611558565b7f206e6f7420617070726f766564000000000000000000000000000000000000006007939091019283015250601401919050565b634e487b7160e01b600052601160045260246000fd5b808201808211156104b6576104b6611861565b600060ff821660ff81036118a0576118a0611861565b60010192915050565b80820281158282048414176104b6576104b6611861565b7f4e6f7420656e6f756768206761732073656e742c206e656564206174206c656181527f737420000000000000000000000000000000000000000000000000000000000060208201526000825161191e816023850160208701611558565b7f20776569000000000000000000000000000000000000000000000000000000006023939091019283015250602701919050565b60006020828403121561196457600080fd5b813560ff811681146115bb57600080fd5b60006001820161198757611987611861565b5060010190565b6000826119ab57634e487b7160e01b600052601260045260246000fd5b500490565b634e487b7160e01b600052604160045260246000fd5b818103818111156104b6576104b6611861565b60ff81811683821601908111156104b6576104b661186156fea26469706673582212204c6dd8a18c56cd6389a7fc7f0bf473d092abcc9aec3ae408859c35bbcc52713e64736f6c637822302e382e31392d646576656c6f702b636f6d6d69742e63383866343066642e6d6f640053", + "deployedBytecode": "0x6080604052600436106101295760003560e01c8063593b79fe116100a5578063a457c2d711610074578063a9059cbb11610059578063a9059cbb14610375578063bc472aa314610395578063dd62ed3e146103cd57600080fd5b8063a457c2d714610335578063a534d9de1461035557600080fd5b8063593b79fe1461028657806370a08231146102d757806373cddab21461030d57806395d89b411461032057600080fd5b806323b872dd116100fc57806339509351116100e1578063395093511461020c578063399444bc1461022c578063429437bf1461024c57600080fd5b806323b872dd146101ca578063313ce567146101ea57600080fd5b806306fdde031461012e578063095ea7b31461015957806318160ddd1461018957806320e8dd93146101a8575b600080fd5b34801561013a57600080fd5b50610143610413565b60405161015091906115a8565b60405180910390f35b34801561016557600080fd5b506101796101743660046115de565b6104a5565b6040519015158152602001610150565b34801561019557600080fd5b50600e545b604051908152602001610150565b3480156101b457600080fd5b506101c86101c33660046115de565b6104bc565b005b3480156101d657600080fd5b506101796101e5366004611608565b61056d565b3480156101f657600080fd5b5060125b60405160ff9091168152602001610150565b34801561021857600080fd5b506101796102273660046115de565b61058f565b34801561023857600080fd5b506101fa610247366004611644565b6105ce565b34801561025857600080fd5b5061026c61026736600461165f565b6106e5565b6040805160ff938416815292909116602083015201610150565b34801561029257600080fd5b506101436102a1366004611644565b604051606082811b6bffffffffffffffffffffffff19166020830152906034016040516020818303038152906040529050919050565b3480156102e357600080fd5b5061019a6102f2366004611644565b6001600160a01b031660009081526020819052604090205490565b6101c861031b366004611678565b610708565b34801561032c57600080fd5b5061014361094c565b34801561034157600080fd5b506101796103503660046115de565b61095b565b34801561036157600080fd5b506101c8610370366004611706565b610a10565b34801561038157600080fd5b506101796103903660046115de565b610ce1565b3480156103a157600080fd5b506103b56103b036600461165f565b610cee565b6040516001600160a01b039091168152602001610150565b3480156103d957600080fd5b5061019a6103e8366004611772565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6060600f8054610422906117a5565b80601f016020809104026020016040519081016040528092919081815260200182805461044e906117a5565b801561049b5780601f106104705761010080835404028352916020019161049b565b820191906000526020600020905b81548152906001019060200180831161047e57829003601f168201915b5050505050905090565b60006104b2338484610d0e565b5060015b92915050565b3360026104c8826105ce565b60ff16600c81106104db576104db6117df565b01546040516bffffffffffffffffffffffff193360601b1660208201526001600160a01b03909116919091149060340160408051601f1981840301815290829052610528916020016117f5565b6040516020818303038152906040529061055e5760405162461bcd60e51b815260040161055591906115a8565b60405180910390fd5b506105698282610edc565b5050565b600061057a843384610f9b565b61058584848461102d565b5060019392505050565b3360008181526001602090815260408083206001600160a01b038716845290915281205490919061058590829086906105c9908790611877565b610d0e565b604080516bffffffffffffffffffffffff19606084901b1660208201528151601481830301815260349091019091526000908190600081518110610614576106146117df565b016020015160f81c905060005b60098160ff16101561069c5760128160ff16600d8110610643576106436117df565b015460ff9081169083161080159061067e575060128160ff16600d811061066c5761066c6117df565b015460ff610100909104811690831611155b1561068a579392505050565b806106948161188a565b915050610621565b5060405162461bcd60e51b815260206004820152601060248201527f496e76616c6964204c6f636174696f6e000000000000000000000000000000006044820152606401610555565b601281600d81106106f557600080fd5b015460ff80821692506101009091041682565b84f780156107585760405162461bcd60e51b815260206004820152601760248201527f41646472657373206973206e6f742065787465726e616c0000000000000000006044820152606401610555565b610762338661128f565b6000600261076f886105ce565b60ff16600c8110610782576107826117df565b01546001600160a01b03169050806108025760405162461bcd60e51b815260206004820152602f60248201527f546f6b656e206973206e6f7420617661696c61626c65206f6e2074686520646560448201527f7374696e6174696f6e20636861696e00000000000000000000000000000000006064820152608401610555565b60008561080f8686611877565b61081991906118a9565b905080341015610828826113f8565b60405160200161083891906118c0565b604051602081830303815290604052906108655760405162461bcd60e51b815260040161055591906115a8565b506040516001600160a01b03891660248201526044810188905260009060640160408051601f198184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f20e8dd930000000000000000000000000000000000000000000000000000000017815281519192506000918291829190898b8d858b81f69050896001600160a01b0316336001600160a01b03167fcf0ee562475620bbcd2f1b0675c8163317513271e4fdbbe9722436f247bd6d998b60405161093891815260200190565b60405180910390a350505050505050505050565b606060108054610422906117a5565b3360008181526001602090815260408083206001600160a01b0387168452909152812054909190838110156109f85760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f7760448201527f207a65726f0000000000000000000000000000000000000000000000000000006064820152608401610555565b610a058286868403610d0e565b506001949350505050565b6011546001600160a01b03163314610a6a5760405162461bcd60e51b815260206004820152601660248201527f53656e646572206973206e6f74206465706c6f796572000000000000000000006044820152606401610555565b828114610adf5760405162461bcd60e51b815260206004820152603060248201527f636861696e20616e64206164647265737320617272617973206d75737420626560448201527f207468652073616d65206c656e677468000000000000000000000000000000006064820152608401610555565b60005b60ff8116841115610cda57600985858360ff16818110610b0457610b046117df565b9050602002016020810190610b199190611952565b60ff1610610b695760405162461bcd60e51b815260206004820152600b60248201527f4d61782039207a6f6e65730000000000000000000000000000000000000000006044820152606401610555565b60006002868660ff8516818110610b8257610b826117df565b9050602002016020810190610b979190611952565b60ff16600c8110610baa57610baa6117df565b01546001600160a01b031614610c285760405162461bcd60e51b815260206004820152603160248201527f54686520617070726f766564206164647265737320666f722074686973207a6f60448201527f6e6520616c7265616479206578697374730000000000000000000000000000006064820152608401610555565b82828260ff16818110610c3d57610c3d6117df565b9050602002016020810190610c529190611644565b600286868460ff16818110610c6957610c696117df565b9050602002016020810190610c7e9190611952565b60ff16600c8110610c9157610c916117df565b0180547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b039290921691909117905580610cd28161188a565b915050610ae2565b5050505050565b60006104b233848461102d565b600281600c8110610cfe57600080fd5b01546001600160a01b0316905081565b81f780610d835760405162461bcd60e51b815260206004820152603f60248201527f5370656e64657220616464726573732069732065787465726e616c2e2055736560448201527f2063726f73732d636861696e207472616e736665722066756e6374696f6e2e006064820152608401610555565b6001600160a01b038416610dfe5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f2061646460448201527f72657373000000000000000000000000000000000000000000000000000000006064820152608401610555565b6001600160a01b038316610e7a5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f20616464726560448201527f73730000000000000000000000000000000000000000000000000000000000006064820152608401610555565b6001600160a01b0384811660008181526001602090815260408083209488168084529482529182902086905590518581527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a350505050565b6001600160a01b038216610f325760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610555565b80600e6000828254610f449190611877565b90915550506001600160a01b038216600081815260208181526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b6001600160a01b038381166000908152600160209081526040808320938616835292905220546000198114611027578181101561101a5760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606401610555565b6110278484848403610d0e565b50505050565b81f7806110a25760405162461bcd60e51b815260206004820152603760248201527f416464726573732069732065787465726e616c2e205573652063726f73732d6360448201527f6861696e207472616e736665722066756e6374696f6e2e0000000000000000006064820152608401610555565b6001600160a01b03841661111e5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f20616460448201527f64726573730000000000000000000000000000000000000000000000000000006064820152608401610555565b6001600160a01b03831661119a5760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201527f65737300000000000000000000000000000000000000000000000000000000006064820152608401610555565b6001600160a01b038416600090815260208190526040902054828110156112295760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e742065786365656473206260448201527f616c616e636500000000000000000000000000000000000000000000000000006064820152608401610555565b6001600160a01b03858116600081815260208181526040808320888703905593881680835291849020805488019055925186815290927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a3610cda565b6001600160a01b03821661130b5760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f2061646472657360448201527f73000000000000000000000000000000000000000000000000000000000000006064820152608401610555565b6001600160a01b0382166000908152602081905260409020548181101561139a5760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e60448201527f63650000000000000000000000000000000000000000000000000000000000006064820152608401610555565b6001600160a01b0383166000818152602081815260408083208686039055600e80548790039055518581529192917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a3505050565b60608160000361143b57505060408051808201909152600181527f3000000000000000000000000000000000000000000000000000000000000000602082015290565b8160005b8115611465578061144f81611975565b915061145e9050600a8361198e565b915061143f565b60008167ffffffffffffffff811115611480576114806119b0565b6040519080825280601f01601f1916602001820160405280156114aa576020820181803683370190505b509050815b851561154f576114c06001826119c6565b905060006114cf600a8861198e565b6114da90600a6118a9565b6114e490886119c6565b6114ef9060306119d9565b905060008160f81b90508084848151811061150c5761150c6117df565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350611546600a8961198e565b975050506114af565b50949350505050565b60005b8381101561157357818101518382015260200161155b565b50506000910152565b60008151808452611594816020860160208601611558565b601f01601f19169290920160200192915050565b6020815260006115bb602083018461157c565b9392505050565b80356001600160a01b03811681146115d957600080fd5b919050565b600080604083850312156115f157600080fd5b6115fa836115c2565b946020939093013593505050565b60008060006060848603121561161d57600080fd5b611626846115c2565b9250611634602085016115c2565b9150604084013590509250925092565b60006020828403121561165657600080fd5b6115bb826115c2565b60006020828403121561167157600080fd5b5035919050565b600080600080600060a0868803121561169057600080fd5b611699866115c2565b97602087013597506040870135966060810135965060800135945092505050565b60008083601f8401126116cc57600080fd5b50813567ffffffffffffffff8111156116e457600080fd5b6020830191508360208260051b85010111156116ff57600080fd5b9250929050565b6000806000806040858703121561171c57600080fd5b843567ffffffffffffffff8082111561173457600080fd5b611740888389016116ba565b9096509450602087013591508082111561175957600080fd5b50611766878288016116ba565b95989497509550505050565b6000806040838503121561178557600080fd5b61178e836115c2565b915061179c602084016115c2565b90509250929050565b600181811c908216806117b957607f821691505b6020821081036117d957634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052603260045260246000fd5b7f53656e646572200000000000000000000000000000000000000000000000000081526000825161182d816007850160208701611558565b7f206e6f7420617070726f766564000000000000000000000000000000000000006007939091019283015250601401919050565b634e487b7160e01b600052601160045260246000fd5b808201808211156104b6576104b6611861565b600060ff821660ff81036118a0576118a0611861565b60010192915050565b80820281158282048414176104b6576104b6611861565b7f4e6f7420656e6f756768206761732073656e742c206e656564206174206c656181527f737420000000000000000000000000000000000000000000000000000000000060208201526000825161191e816023850160208701611558565b7f20776569000000000000000000000000000000000000000000000000000000006023939091019283015250602701919050565b60006020828403121561196457600080fd5b813560ff811681146115bb57600080fd5b60006001820161198757611987611861565b5060010190565b6000826119ab57634e487b7160e01b600052601260045260246000fd5b500490565b634e487b7160e01b600052604160045260246000fd5b818103818111156104b6576104b6611861565b60ff81811683821601908111156104b6576104b661186156fea26469706673582212204c6dd8a18c56cd6389a7fc7f0bf473d092abcc9aec3ae408859c35bbcc52713e64736f6c637822302e382e31392d646576656c6f702b636f6d6d69742e63383866343066642e6d6f640053", + "linkReferences": {}, + "deployedLinkReferences": {} +}; +export default QRC20; +//# sourceMappingURL=QRC20.js.map \ No newline at end of file diff --git a/lib.esm/_tests/contracts/QRC20.js.map b/lib.esm/_tests/contracts/QRC20.js.map new file mode 100644 index 00000000..8ad2e590 --- /dev/null +++ b/lib.esm/_tests/contracts/QRC20.js.map @@ -0,0 +1 @@ +{"version":3,"file":"QRC20.js","sourceRoot":"","sources":["../../../src.ts/_tests/contracts/QRC20.ts"],"names":[],"mappings":"AAAA,MAAM,KAAK,GAAG;IACZ,SAAS,EAAE,mBAAmB;IAC9B,cAAc,EAAE,OAAO;IACvB,YAAY,EAAE,qBAAqB;IACnC,KAAK,EAAE;QACL;YACE,QAAQ,EAAE;gBACR;oBACE,cAAc,EAAE,QAAQ;oBACxB,MAAM,EAAE,OAAO;oBACf,MAAM,EAAE,QAAQ;iBACjB;gBACD;oBACE,cAAc,EAAE,QAAQ;oBACxB,MAAM,EAAE,SAAS;oBACjB,MAAM,EAAE,QAAQ;iBACjB;gBACD;oBACE,cAAc,EAAE,SAAS;oBACzB,MAAM,EAAE,gBAAgB;oBACxB,MAAM,EAAE,SAAS;iBAClB;aACF;YACD,iBAAiB,EAAE,YAAY;YAC/B,MAAM,EAAE,aAAa;SACtB;QACD;YACE,WAAW,EAAE,KAAK;YAClB,QAAQ,EAAE;gBACR;oBACE,SAAS,EAAE,IAAI;oBACf,cAAc,EAAE,SAAS;oBACzB,MAAM,EAAE,OAAO;oBACf,MAAM,EAAE,SAAS;iBAClB;gBACD;oBACE,SAAS,EAAE,IAAI;oBACf,cAAc,EAAE,SAAS;oBACzB,MAAM,EAAE,SAAS;oBACjB,MAAM,EAAE,SAAS;iBAClB;gBACD;oBACE,SAAS,EAAE,KAAK;oBAChB,cAAc,EAAE,SA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oBACV,MAAM,EAAE,SAAS;iBAClB;aACF;YACD,iBAAiB,EAAE,MAAM;YACzB,MAAM,EAAE,UAAU;SACnB;QACD;YACE,QAAQ,EAAE;gBACR;oBACE,cAAc,EAAE,SAAS;oBACzB,MAAM,EAAE,IAAI;oBACZ,MAAM,EAAE,SAAS;iBAClB;gBACD;oBACE,cAAc,EAAE,SAAS;oBACzB,MAAM,EAAE,QAAQ;oBAChB,MAAM,EAAE,SAAS;iBAClB;aACF;YACD,MAAM,EAAE,UAAU;YAClB,SAAS,EAAE;gBACT;oBACE,cAAc,EAAE,MAAM;oBACtB,MAAM,EAAE,EAAE;oBACV,MAAM,EAAE,MAAM;iBACf;aACF;YACD,iBAAiB,EAAE,YAAY;YAC/B,MAAM,EAAE,UAAU;SACnB;QACD;YACE,QAAQ,EAAE;gBACR;oBACE,cAAc,EAAE,SAAS;oBACzB,MAAM,EAAE,MAAM;oBACd,MAAM,EAAE,SAAS;iBAClB;gBACD;oBACE,cAAc,EAAE,SAAS;oBACzB,MAAM,EAAE,IAAI;oBACZ,MAAM,EAAE,SAAS;iBAClB;gBACD;oBACE,cAAc,EAAE,SAAS;oBACzB,MAAM,EAAE,QAAQ;oBAChB,MAAM,EAAE,SAAS;iBAClB;aACF;YACD,MAAM,EAAE,cAAc;YACtB,SAAS,EAAE;gBACT;oBACE,cAAc,EAAE,MAAM;oBACtB,MAAM,EAAE,EAAE;oBACV,MAAM,EAAE,MAAM;iBACf;aACF;YACD,iBAAiB,EAAE,YAAY;YAC/B,MAAM,EAAE,UAAU;SACnB;KACF;IACD,UAAU,EAAE,wufAAwuf;IACpvf,kBAAkB,EAAE,opaAAopa;IACxqa,gBAAgB,EAAE,EAAE;IACpB,wBAAwB,EAAE,EAAE;CAC7B,CAAA;AAGD,eAAe,KAAK,CAAC"} \ No newline at end of file diff --git a/lib.esm/_tests/contracts/TestContract.d.ts b/lib.esm/_tests/contracts/TestContract.d.ts new file mode 100644 index 00000000..c42d178a --- /dev/null +++ b/lib.esm/_tests/contracts/TestContract.d.ts @@ -0,0 +1,50 @@ +declare const TestContract: { + _format: string; + contractName: string; + sourceName: string; + abi: ({ + inputs: { + internalType: string; + name: string; + type: string; + }[]; + name: string; + type: string; + anonymous?: undefined; + outputs?: undefined; + stateMutability?: undefined; + } | { + anonymous: boolean; + inputs: { + indexed: boolean; + internalType: string; + name: string; + type: string; + }[]; + name: string; + type: string; + outputs?: undefined; + stateMutability?: undefined; + } | { + inputs: { + internalType: string; + name: string; + type: string; + }[]; + name: string; + outputs: { + internalType: string; + name: string; + type: string; + }[]; + stateMutability: string; + type: string; + anonymous?: undefined; + })[]; + bytecode: string; + deployedBytecode: string; + linkReferences: {}; + deployedLinkReferences: {}; +}; +export default TestContract; +//# sourceMappingURL=TestContract.d.ts.map \ No newline at end of file diff --git a/lib.esm/_tests/contracts/TestContract.d.ts.map b/lib.esm/_tests/contracts/TestContract.d.ts.map new file mode 100644 index 00000000..3f1bd915 --- /dev/null +++ b/lib.esm/_tests/contracts/TestContract.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"TestContract.d.ts","sourceRoot":"","sources":["../../../src.ts/_tests/contracts/TestContract.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0MjB,CAAA;AAED,eAAe,YAAY,CAAC"} \ No newline at end of file diff --git a/lib.esm/_tests/contracts/TestContract.js b/lib.esm/_tests/contracts/TestContract.js new file mode 100644 index 00000000..8d293317 --- /dev/null +++ b/lib.esm/_tests/contracts/TestContract.js @@ -0,0 +1,205 @@ +const TestContract = { + "_format": "hh-sol-artifact-1", + "contractName": "TestContract", + "sourceName": "contracts/Test.sol", + "abi": [ + { + "inputs": [ + { + "internalType": "uint256", + "name": "code", + "type": "uint256" + }, + { + "internalType": "string", + "name": "message", + "type": "string" + } + ], + "name": "CustomError1", + "type": "error" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "value", + "type": "address" + } + ], + "name": "EventAddress", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "bytes", + "name": "value", + "type": "bytes" + } + ], + "name": "EventBytes", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "string", + "name": "value", + "type": "string" + } + ], + "name": "EventString", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "EventUint256", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "a", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "b", + "type": "uint256" + } + ], + "name": "testCallAdd", + "outputs": [ + { + "internalType": "uint256", + "name": "result", + "type": "uint256" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bool", + "name": "pass", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "code", + "type": "uint256" + }, + { + "internalType": "string", + "name": "message", + "type": "string" + } + ], + "name": "testCustomError1", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bool", + "name": "pass", + "type": "bool" + }, + { + "internalType": "string", + "name": "message", + "type": "string" + } + ], + "name": "testErrorString", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "valueUint256", + "type": "uint256" + }, + { + "internalType": "address", + "name": "valueAddress", + "type": "address" + }, + { + "internalType": "string", + "name": "valueString", + "type": "string" + }, + { + "internalType": "bytes", + "name": "valueBytes", + "type": "bytes" + } + ], + "name": "testEvent", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "code", + "type": "uint256" + } + ], + "name": "testPanic", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "pure", + "type": "function" + } + ], + "bytecode": "0x608060405234801561001057600080fd5b5061058d806100206000396000f3fe608060405234801561001057600080fd5b50600436106100675760003560e01c8063c8d6fda711610050578063c8d6fda7146100a4578063db734248146100b9578063f24684e5146100cc57600080fd5b80633da613681461006c578063b206699b14610091575b600080fd5b61007f61007a3660046102aa565b6100df565b60405190815260200160405180910390f35b61007f61009f366004610321565b61013a565b6100b76100b2366004610374565b610167565b005b61007f6100c7366004610419565b61024d565b61007f6100da366004610473565b610295565b6000816000036101365760405162461bcd60e51b815260206004820152601360248201527f50616e69633a20636f6465206973207a65726f0000000000000000000000000060448201526064015b60405180910390fd5b5090565b600082828561015d5760405162461bcd60e51b815260040161012d9291906104be565b5091949350505050565b60405186907f85c55bbb820e6d71c71f4894e57751de334b38c421f9c170b0e66d32eafea33790600090a260405173ffffffffffffffffffffffffffffffffffffffff8616907f52cb491081609a3d8c50cb8d5c1395de748f65789fc66e140e795decadd86c3090600090a27f7240e2f75cccc64acf37f699b7cc2726ccd9c0ed8afeafdbf7911af78d077bad84846040516102049291906104be565b60405180910390a17f06e852ba9138ee18ce13f482908b8634bc29d809282ea568cf505aca412b195e828260405161023d9291906104be565b60405180910390a1505050505050565b60008461028c578383836040517f180c751a00000000000000000000000000000000000000000000000000000000815260040161012d939291906104da565b50919392505050565b60006102a182846104fd565b90505b92915050565b6000602082840312156102bc57600080fd5b5035919050565b803580151581146102d357600080fd5b919050565b60008083601f8401126102ea57600080fd5b50813567ffffffffffffffff81111561030257600080fd5b60208301915083602082850101111561031a57600080fd5b9250929050565b60008060006040848603121561033657600080fd5b61033f846102c3565b9250602084013567ffffffffffffffff81111561035b57600080fd5b610367868287016102d8565b9497909650939450505050565b6000806000806000806080878903121561038d57600080fd5b86359550602087013573ffffffffffffffffffffffffffffffffffffffff811681146103b857600080fd5b9450604087013567ffffffffffffffff808211156103d557600080fd5b6103e18a838b016102d8565b909650945060608901359150808211156103fa57600080fd5b5061040789828a016102d8565b979a9699509497509295939492505050565b6000806000806060858703121561042f57600080fd5b610438856102c3565b935060208501359250604085013567ffffffffffffffff81111561045b57600080fd5b610467878288016102d8565b95989497509550505050565b6000806040838503121561048657600080fd5b50508035926020909101359150565b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b6020815260006104d2602083018486610495565b949350505050565b8381526040602082015260006104f4604083018486610495565b95945050505050565b808201808211156102a4577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fdfea2646970667358221220aa52c22ce2f4a856b56d32ae58c6b41a9dba4c7aed43a0872ffa898f157e67b564736f6c637822302e382e31392d646576656c6f702b636f6d6d69742e63383866343066642e6d6f640053", + "deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100675760003560e01c8063c8d6fda711610050578063c8d6fda7146100a4578063db734248146100b9578063f24684e5146100cc57600080fd5b80633da613681461006c578063b206699b14610091575b600080fd5b61007f61007a3660046102aa565b6100df565b60405190815260200160405180910390f35b61007f61009f366004610321565b61013a565b6100b76100b2366004610374565b610167565b005b61007f6100c7366004610419565b61024d565b61007f6100da366004610473565b610295565b6000816000036101365760405162461bcd60e51b815260206004820152601360248201527f50616e69633a20636f6465206973207a65726f0000000000000000000000000060448201526064015b60405180910390fd5b5090565b600082828561015d5760405162461bcd60e51b815260040161012d9291906104be565b5091949350505050565b60405186907f85c55bbb820e6d71c71f4894e57751de334b38c421f9c170b0e66d32eafea33790600090a260405173ffffffffffffffffffffffffffffffffffffffff8616907f52cb491081609a3d8c50cb8d5c1395de748f65789fc66e140e795decadd86c3090600090a27f7240e2f75cccc64acf37f699b7cc2726ccd9c0ed8afeafdbf7911af78d077bad84846040516102049291906104be565b60405180910390a17f06e852ba9138ee18ce13f482908b8634bc29d809282ea568cf505aca412b195e828260405161023d9291906104be565b60405180910390a1505050505050565b60008461028c578383836040517f180c751a00000000000000000000000000000000000000000000000000000000815260040161012d939291906104da565b50919392505050565b60006102a182846104fd565b90505b92915050565b6000602082840312156102bc57600080fd5b5035919050565b803580151581146102d357600080fd5b919050565b60008083601f8401126102ea57600080fd5b50813567ffffffffffffffff81111561030257600080fd5b60208301915083602082850101111561031a57600080fd5b9250929050565b60008060006040848603121561033657600080fd5b61033f846102c3565b9250602084013567ffffffffffffffff81111561035b57600080fd5b610367868287016102d8565b9497909650939450505050565b6000806000806000806080878903121561038d57600080fd5b86359550602087013573ffffffffffffffffffffffffffffffffffffffff811681146103b857600080fd5b9450604087013567ffffffffffffffff808211156103d557600080fd5b6103e18a838b016102d8565b909650945060608901359150808211156103fa57600080fd5b5061040789828a016102d8565b979a9699509497509295939492505050565b6000806000806060858703121561042f57600080fd5b610438856102c3565b935060208501359250604085013567ffffffffffffffff81111561045b57600080fd5b610467878288016102d8565b95989497509550505050565b6000806040838503121561048657600080fd5b50508035926020909101359150565b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b6020815260006104d2602083018486610495565b949350505050565b8381526040602082015260006104f4604083018486610495565b95945050505050565b808201808211156102a4577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fdfea2646970667358221220aa52c22ce2f4a856b56d32ae58c6b41a9dba4c7aed43a0872ffa898f157e67b564736f6c637822302e382e31392d646576656c6f702b636f6d6d69742e63383866343066642e6d6f640053", + "linkReferences": {}, + "deployedLinkReferences": {} +}; +export default TestContract; +//# sourceMappingURL=TestContract.js.map \ No newline at end of file diff --git a/lib.esm/_tests/contracts/TestContract.js.map b/lib.esm/_tests/contracts/TestContract.js.map new file mode 100644 index 00000000..4a60df9d --- /dev/null +++ b/lib.esm/_tests/contracts/TestContract.js.map @@ -0,0 +1 @@ +{"version":3,"file":"TestContract.js","sourceRoot":"","sources":["../../../src.ts/_tests/contracts/TestContract.ts"],"names":[],"mappings":"AAAA,MAAM,YAAY,GAAG;IACnB,SAAS,EAAE,mBAAmB;IAC9B,cAAc,EAAE,cAAc;IAC9B,YAAY,EAAE,oBAAoB;IAClC,KAAK,EAAE;QACL;YACE,QAAQ,EAAE;gBACR;oBACE,cAAc,E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oBACE,cAAc,EAAE,SAAS;oBACzB,MAAM,EAAE,cAAc;oBACtB,MAAM,EAAE,SAAS;iBAClB;gBACD;oBACE,cAAc,EAAE,QAAQ;oBACxB,MAAM,EAAE,aAAa;oBACrB,MAAM,EAAE,QAAQ;iBACjB;gBACD;oBACE,cAAc,EAAE,OAAO;oBACvB,MAAM,EAAE,YAAY;oBACpB,MAAM,EAAE,OAAO;iBAChB;aACF;YACD,MAAM,EAAE,WAAW;YACnB,SAAS,EAAE,EAAE;YACb,iBAAiB,EAAE,YAAY;YAC/B,MAAM,EAAE,UAAU;SACnB;QACD;YACE,QAAQ,EAAE;gBACR;oBACE,cAAc,EAAE,SAAS;oBACzB,MAAM,EAAE,MAAM;oBACd,MAAM,EAAE,SAAS;iBAClB;aACF;YACD,MAAM,EAAE,WAAW;YACnB,SAAS,EAAE;gBACT;oBACE,cAAc,EAAE,SAAS;oBACzB,MAAM,EAAE,EAAE;oBACV,MAAM,EAAE,SAAS;iBAClB;aACF;YACD,iBAAiB,EAAE,MAAM;YACzB,MAAM,EAAE,UAAU;SACnB;KACF;IACD,UAAU,EAAE,81FAA81F;IAC12F,kBAAkB,EAAE,8xFAA8xF;IAClzF,gBAAgB,EAAE,EAAE;IACpB,wBAAwB,EAAE,EAAE;CAC7B,CAAA;AAED,eAAe,YAAY,CAAC"} \ No newline at end of file diff --git a/lib.esm/_tests/contracts/TypedContract.d.ts b/lib.esm/_tests/contracts/TypedContract.d.ts new file mode 100644 index 00000000..01194bde --- /dev/null +++ b/lib.esm/_tests/contracts/TypedContract.d.ts @@ -0,0 +1,26 @@ +declare const TypedContract: { + _format: string; + contractName: string; + sourceName: string; + abi: { + inputs: { + internalType: string; + name: string; + type: string; + }[]; + name: string; + outputs: { + internalType: string; + name: string; + type: string; + }[]; + stateMutability: string; + type: string; + }[]; + bytecode: string; + deployedBytecode: string; + linkReferences: {}; + deployedLinkReferences: {}; +}; +export default TypedContract; +//# sourceMappingURL=TypedContract.d.ts.map \ No newline at end of file diff --git a/lib.esm/_tests/contracts/TypedContract.d.ts.map b/lib.esm/_tests/contracts/TypedContract.d.ts.map new file mode 100644 index 00000000..101393e4 --- /dev/null +++ b/lib.esm/_tests/contracts/TypedContract.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"TypedContract.d.ts","sourceRoot":"","sources":["../../../src.ts/_tests/contracts/TypedContract.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;CAs3DlB,CAAA;AAKD,eAAe,aAAa,CAAC"} \ No newline at end of file diff --git a/lib.esm/_tests/contracts/TypedContract.js b/lib.esm/_tests/contracts/TypedContract.js new file mode 100644 index 00000000..d78dc70f --- /dev/null +++ b/lib.esm/_tests/contracts/TypedContract.js @@ -0,0 +1,1913 @@ +const TypedContract = { + "_format": "hh-sol-artifact-1", + "contractName": "TypedContract", + "sourceName": "contracts/TestTyped.sol", + "abi": [ + { + "inputs": [ + { + "internalType": "uint32", + "name": "", + "type": "uint32" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes24", + "name": "", + "type": "bytes24" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int208", + "name": "", + "type": "int208" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint176", + "name": "", + "type": "uint176" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes4", + "name": "", + "type": "bytes4" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes9", + "name": "", + "type": "bytes9" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int72", + "name": "", + "type": "int72" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint200", + "name": "", + "type": "uint200" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes20", + "name": "", + "type": "bytes20" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int32", + "name": "", + "type": "int32" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint216", + "name": "", + "type": "uint216" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint184", + "name": "", + "type": "uint184" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint152", + "name": "", + "type": "uint152" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int248", + "name": "", + "type": "int248" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint80", + "name": "", + "type": "uint80" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes28", + "name": "", + "type": "bytes28" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes30", + "name": "", + "type": "bytes30" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int120", + "name": "", + "type": "int120" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes21", + "name": "", + "type": "bytes21" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint104", + "name": "", + "type": "uint104" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int96", + "name": "", + "type": "int96" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint224", + "name": "", + "type": "uint224" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int168", + "name": "", + "type": "int168" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int200", + "name": "", + "type": "int200" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int184", + "name": "", + "type": "int184" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes14", + "name": "", + "type": "bytes14" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint192", + "name": "", + "type": "uint192" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes2", + "name": "", + "type": "bytes2" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint24", + "name": "", + "type": "uint24" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int112", + "name": "", + "type": "int112" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes6", + "name": "", + "type": "bytes6" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint16", + "name": "", + "type": "uint16" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes3", + "name": "", + "type": "bytes3" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes17", + "name": "", + "type": "bytes17" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int224", + "name": "", + "type": "int224" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int128", + "name": "", + "type": "int128" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes18", + "name": "", + "type": "bytes18" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int104", + "name": "", + "type": "int104" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes7", + "name": "", + "type": "bytes7" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes25", + "name": "", + "type": "bytes25" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint40", + "name": "", + "type": "uint40" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint120", + "name": "", + "type": "uint120" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint168", + "name": "", + "type": "uint168" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int136", + "name": "", + "type": "int136" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint248", + "name": "", + "type": "uint248" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes8", + "name": "", + "type": "bytes8" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int192", + "name": "", + "type": "int192" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int216", + "name": "", + "type": "int216" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes", + "name": "", + "type": "bytes" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint240", + "name": "", + "type": "uint240" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint112", + "name": "", + "type": "uint112" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes29", + "name": "", + "type": "bytes29" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int80", + "name": "", + "type": "int80" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int176", + "name": "", + "type": "int176" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes31", + "name": "", + "type": "bytes31" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint208", + "name": "", + "type": "uint208" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint88", + "name": "", + "type": "uint88" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes10", + "name": "", + "type": "bytes10" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes16", + "name": "", + "type": "bytes16" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int88", + "name": "", + "type": "int88" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint64", + "name": "", + "type": "uint64" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes12", + "name": "", + "type": "bytes12" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes27", + "name": "", + "type": "bytes27" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int64", + "name": "", + "type": "int64" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint136", + "name": "", + "type": "uint136" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint232", + "name": "", + "type": "uint232" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes26", + "name": "", + "type": "bytes26" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes5", + "name": "", + "type": "bytes5" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint48", + "name": "", + "type": "uint48" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int40", + "name": "", + "type": "int40" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint96", + "name": "", + "type": "uint96" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint160", + "name": "", + "type": "uint160" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int8", + "name": "", + "type": "int8" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint72", + "name": "", + "type": "uint72" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int232", + "name": "", + "type": "int232" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int16", + "name": "", + "type": "int16" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes15", + "name": "", + "type": "bytes15" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint56", + "name": "", + "type": "uint56" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes23", + "name": "", + "type": "bytes23" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int240", + "name": "", + "type": "int240" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int160", + "name": "", + "type": "int160" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint128", + "name": "", + "type": "uint128" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int48", + "name": "", + "type": "int48" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes13", + "name": "", + "type": "bytes13" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes22", + "name": "", + "type": "bytes22" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int256", + "name": "", + "type": "int256" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes19", + "name": "", + "type": "bytes19" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int152", + "name": "", + "type": "int152" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint144", + "name": "", + "type": "uint144" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int24", + "name": "", + "type": "int24" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes11", + "name": "", + "type": "bytes11" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int56", + "name": "", + "type": "int56" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int144", + "name": "", + "type": "int144" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes1", + "name": "", + "type": "bytes1" + } + ], + "name": "testTyped", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + } + ], + "bytecode": "0x608060405234801561001057600080fd5b506134a7806100206000396000f3fe608060405234801561001057600080fd5b506004361061065c5760003560e01c8063a202e8c011610345578063cec31ded116101bd578063e96add8c11610104578063f3164597116100ad578063f85a090311610087578063f85a0903146120b7578063fa4d99c9146120fd578063fbf3e13a14612143578063fd1652cb1461218957600080fd5b8063f316459714611fe5578063f44076171461202b578063f7b0e3d51461207157600080fd5b8063eecd1129116100de578063eecd112914611f13578063ef4483be14611f59578063f0fb21ff14611f9f57600080fd5b8063e96add8c14611e41578063e9da42ca14611e87578063eb01940114611ecd57600080fd5b8063d92e6c0611610166578063e0fa6ea111610140578063e0fa6ea114611d6f578063e137fb7014611db5578063e8fb922314611dfb57600080fd5b8063d92e6c0614611c9d578063dad2ef4f14611ce3578063dafbc72414611d2957600080fd5b8063d4b789d811610197578063d4b789d814611bcb578063d4c0c48614611c11578063d7d7398414611c5757600080fd5b8063cec31ded14611af9578063d0e03b0714611b3f578063d20f679a14611b8557600080fd5b8063bbeb25e01161028c578063c233fd3311610235578063c84ad5801161020f578063c84ad580146119e1578063c8ddda4a14611a27578063cc69cf9714611a6d578063ccd94f9814611ab357600080fd5b8063c233fd331461190f578063c639604b14611955578063c847fe3b1461199b57600080fd5b8063c081607b11610266578063c081607b1461183d578063c1397e9914611883578063c1847bee146118c957600080fd5b8063bbeb25e01461176b578063bccdc9c4146117b1578063bf01c7f9146117f757600080fd5b8063ad87e2e1116102ee578063b860f47f116102c8578063b860f47f14611699578063ba607fac146116df578063bb73447f1461172557600080fd5b8063ad87e2e1146115c7578063b429b23c1461160d578063b7bab2861461165357600080fd5b8063a925e7621161031f578063a925e762146114f5578063a95d606e1461153b578063aa8de9461461158157600080fd5b8063a202e8c014611423578063a3ab9e7a14611469578063a6496f62146114af57600080fd5b806351e0489a116104d85780637c9affcb1161041f578063891a099d116103c85780639df2391c116103a25780639df2391c1461130b5780639faf388f146113515780639fcbede614611397578063a178b800146113dd57600080fd5b8063891a099d146112395780638e4884d11461127f5780639ded4e2b146112c557600080fd5b806381c4b4cc116103f957806381c4b4cc146111675780638275b290146111ad57806387ad7515146111f357600080fd5b80637c9affcb146110955780637fcc3d5d146110db578063803bf56d1461112157600080fd5b80636913a82b11610481578063769008e41161045b578063769008e414610fc35780637a3058c1146110095780637bc705c11461104f57600080fd5b80636913a82b14610ef15780636a678a7514610f3757806375b5533714610f7d57600080fd5b80636357d3b7116104b25780636357d3b714610e1f578063659665f914610e65578063679b530214610eab57600080fd5b806351e0489a14610d4d57806357301b0214610d935780635793d40814610dd957600080fd5b80632a0caa6a116105a7578063429545a4116105505780634961a7ce1161052a5780634961a7ce14610c355780634a3ccd5f14610c7b5780634fb7d4bd14610cc157806350fbcfb614610d0757600080fd5b8063429545a414610b6357806343c84f3314610ba957806346d79d1314610bef57600080fd5b806333c064151161058157806333c0641514610a9157806334bdbab714610ad75780634029cdee14610b1d57600080fd5b80632a0caa6a146109bf5780632a97dfbf14610a055780632f0d528b14610a4b57600080fd5b80631b46fa941161060957806325cb6b9a116105e357806325cb6b9a146108ed57806326888cda1461093357806328b01d811461097957600080fd5b80631b46fa941461081b5780631eb765fd1461086157806325bc2c82146108a757600080fd5b8063107810d51161063a578063107810d5146107495780631400a02f1461078f5780631a762a3a146107d557600080fd5b806303290450146106615780630e9ba011146106bd5780630f84821114610703575b600080fd5b6106a761066f3660046121cf565b5060408051808201909152600681527f75696e7433320000000000000000000000000000000000000000000000000000602082015290565b6040516106b491906121fc565b60405180910390f35b6106a76106cb36600461224a565b5060408051808201909152600781527f6279746573323400000000000000000000000000000000000000000000000000602082015290565b6106a7610711366004612275565b5060408051808201909152600681527f696e743230380000000000000000000000000000000000000000000000000000602082015290565b6106a7610757366004612298565b5060408051808201909152600781527f75696e7431373600000000000000000000000000000000000000000000000000602082015290565b6106a761079d3660046122d0565b5060408051808201909152600681527f6279746573340000000000000000000000000000000000000000000000000000602082015290565b6106a76107e3366004612312565b5060408051808201909152600681527f6279746573390000000000000000000000000000000000000000000000000000602082015290565b6106a7610829366004612354565b5060408051808201909152600581527f696e743732000000000000000000000000000000000000000000000000000000602082015290565b6106a761086f366004612377565b5060408051808201909152600781527f75696e7432303000000000000000000000000000000000000000000000000000602082015290565b6106a76108b53660046123b2565b5060408051808201909152600781527f6279746573323000000000000000000000000000000000000000000000000000602082015290565b6106a76108fb3660046123e1565b5060408051808201909152600581527f696e743332000000000000000000000000000000000000000000000000000000602082015290565b6106a7610941366004612404565b5060408051808201909152600781527f75696e7432313600000000000000000000000000000000000000000000000000602082015290565b6106a7610987366004612441565b5060408051808201909152600781527f75696e7431383400000000000000000000000000000000000000000000000000602082015290565b6106a76109cd36600461247a565b5060408051808201909152600781527f75696e7431353200000000000000000000000000000000000000000000000000602082015290565b6106a7610a133660046124af565b5060408051808201909152600681527f696e743234380000000000000000000000000000000000000000000000000000602082015290565b6106a7610a593660046124d2565b5060408051808201909152600681527f75696e7438300000000000000000000000000000000000000000000000000000602082015290565b6106a7610a9f3660046124fe565b5060408051808201909152600781527f6279746573323800000000000000000000000000000000000000000000000000602082015290565b6106a7610ae5366004612525565b5060408051808201909152600781527f6279746573333000000000000000000000000000000000000000000000000000602082015290565b6106a7610b2b36600461254a565b5060408051808201909152600681527f696e743132300000000000000000000000000000000000000000000000000000602082015290565b6106a7610b7136600461256d565b5060408051808201909152600781527f6279746573323100000000000000000000000000000000000000000000000000602082015290565b6106a7610bb736600461259b565b5060408051808201909152600781527f75696e7431303400000000000000000000000000000000000000000000000000602082015290565b6106a7610bfd3660046125ca565b5060408051808201909152600581527f696e743936000000000000000000000000000000000000000000000000000000602082015290565b6106a7610c433660046125ed565b5060408051808201909152600781527f75696e7432323400000000000000000000000000000000000000000000000000602082015290565b6106a7610c8936600461262b565b5060408051808201909152600681527f696e743136380000000000000000000000000000000000000000000000000000602082015290565b6106a7610ccf36600461264e565b5060408051808201909152600681527f696e743230300000000000000000000000000000000000000000000000000000602082015290565b6106a7610d15366004612671565b5060408051808201909152600681527f696e743138340000000000000000000000000000000000000000000000000000602082015290565b6106a7610d5b366004612694565b5060408051808201909152600781527f6279746573313400000000000000000000000000000000000000000000000000602082015290565b6106a7610da13660046126d6565b5060408051808201909152600781527f75696e7431393200000000000000000000000000000000000000000000000000602082015290565b6106a7610de7366004612710565b5060408051808201909152600681527f6279746573320000000000000000000000000000000000000000000000000000602082015290565b6106a7610e2d366004612752565b5060408051808201909152600681527f75696e7432340000000000000000000000000000000000000000000000000000602082015290565b6106a7610e73366004612777565b5060408051808201909152600681527f696e743131320000000000000000000000000000000000000000000000000000602082015290565b6106a7610eb936600461279a565b5060408051808201909152600681527f6279746573360000000000000000000000000000000000000000000000000000602082015290565b6106a7610eff3660046127dc565b5060408051808201909152600681527f75696e7431360000000000000000000000000000000000000000000000000000602082015290565b6106a7610f45366004612800565b5060408051808201909152600681527f6279746573330000000000000000000000000000000000000000000000000000602082015290565b6106a7610f8b366004612842565b5060408051808201909152600781527f6279746573313700000000000000000000000000000000000000000000000000602082015290565b6106a7610fd1366004612874565b5060408051808201909152600681527f696e743232340000000000000000000000000000000000000000000000000000602082015290565b6106a7611017366004612897565b5060408051808201909152600681527f696e743132380000000000000000000000000000000000000000000000000000602082015290565b6106a761105d3660046128ba565b5060408051808201909152600781527f6279746573313800000000000000000000000000000000000000000000000000602082015290565b6106a76110a33660046128eb565b5060408051808201909152600681527f696e743130340000000000000000000000000000000000000000000000000000602082015290565b6106a76110e936600461290e565b5060408051808201909152600681527f6279746573370000000000000000000000000000000000000000000000000000602082015290565b6106a761112f366004612950565b5060408051808201909152600781527f6279746573323500000000000000000000000000000000000000000000000000602082015290565b6106a761117536600461297a565b5060408051808201909152600681527f75696e7434300000000000000000000000000000000000000000000000000000602082015290565b6106a76111bb3660046129a1565b5060408051808201909152600781527f75696e7431323000000000000000000000000000000000000000000000000000602082015290565b6106a76112013660046129d2565b5060408051808201909152600781527f75696e7431363800000000000000000000000000000000000000000000000000602082015290565b6106a7611247366004612a09565b5060408051808201909152600681527f696e743133360000000000000000000000000000000000000000000000000000602082015290565b6106a761128d366004612a2c565b5060408051808201909152600781527f75696e7432343800000000000000000000000000000000000000000000000000602082015290565b6106a76112d3366004612a6d565b5060408051808201909152600681527f6279746573380000000000000000000000000000000000000000000000000000602082015290565b6106a7611319366004612aaf565b5060408051808201909152600681527f696e743139320000000000000000000000000000000000000000000000000000602082015290565b6106a761135f366004612ad2565b5060408051808201909152600681527f696e743231360000000000000000000000000000000000000000000000000000602082015290565b6106a76113a5366004612b9a565b5060408051808201909152600581527f6279746573000000000000000000000000000000000000000000000000000000602082015290565b6106a76113eb366004612beb565b5060408051808201909152600781527f75696e7432343000000000000000000000000000000000000000000000000000602082015290565b6106a7611431366004612c2b565b5060408051808201909152600781527f75696e7431313200000000000000000000000000000000000000000000000000602082015290565b6106a7611477366004612c5b565b5060408051808201909152600781527f6279746573323900000000000000000000000000000000000000000000000000602082015290565b6106a76114bd366004612c81565b5060408051808201909152600581527f696e743830000000000000000000000000000000000000000000000000000000602082015290565b6106a7611503366004612ca4565b5060408051808201909152600681527f696e743137360000000000000000000000000000000000000000000000000000602082015290565b6106a7611549366004612cc7565b5060408051808201909152600781527f6279746573333100000000000000000000000000000000000000000000000000602082015290565b6106a761158f366004612ceb565b5060408051808201909152600581527f75696e7438000000000000000000000000000000000000000000000000000000602082015290565b6106a76115d5366004612d0e565b5060408051808201909152600781527f75696e7432303800000000000000000000000000000000000000000000000000602082015290565b6106a761161b366004612d4a565b5060408051808201909152600681527f75696e7438380000000000000000000000000000000000000000000000000000602082015290565b6106a7611661366004612d77565b5060408051808201909152600781527f6279746573313000000000000000000000000000000000000000000000000000602082015290565b6106a76116a7366004612db9565b5060408051808201909152600781527f6279746573313600000000000000000000000000000000000000000000000000602082015290565b6106a76116ed366004612dfb565b5060408051808201909152600581527f696e743838000000000000000000000000000000000000000000000000000000602082015290565b6106a7611733366004612e1e565b5060408051808201909152600681527f75696e7436340000000000000000000000000000000000000000000000000000602082015290565b6106a7611779366004612e6d565b5060408051808201909152600781527f6164647265737300000000000000000000000000000000000000000000000000602082015290565b6106a76117bf366004612e8a565b5060408051808201909152600781527f6279746573313200000000000000000000000000000000000000000000000000602082015290565b6106a7611805366004612ecc565b5060408051808201909152600781527f6279746573323700000000000000000000000000000000000000000000000000602082015290565b6106a761184b366004612ef4565b5060408051808201909152600581527f696e743634000000000000000000000000000000000000000000000000000000602082015290565b6106a7611891366004612f17565b5060408051808201909152600781527f75696e7431333600000000000000000000000000000000000000000000000000602082015290565b6106a76118d7366004612f4a565b5060408051808201909152600781527f75696e7432333200000000000000000000000000000000000000000000000000602082015290565b6106a761191d366004612f89565b5060408051808201909152600781527f6279746573323600000000000000000000000000000000000000000000000000602082015290565b6106a7611963366004612fb2565b5060408051808201909152600681527f6279746573350000000000000000000000000000000000000000000000000000602082015290565b6106a76119a9366004612ff4565b5060408051808201909152600681527f75696e7434380000000000000000000000000000000000000000000000000000602082015290565b6106a76119ef36600461301c565b5060408051808201909152600581527f696e743430000000000000000000000000000000000000000000000000000000602082015290565b6106a7611a3536600461303f565b5060408051808201909152600681527f75696e7439360000000000000000000000000000000000000000000000000000602082015290565b6106a7611a7b366004612e6d565b5060408051808201909152600781527f75696e7431363000000000000000000000000000000000000000000000000000602082015290565b6106a7611ac136600461306d565b5060408051808201909152600481527f696e743800000000000000000000000000000000000000000000000000000000602082015290565b6106a7611b07366004613090565b5060408051808201909152600681527f75696e7437320000000000000000000000000000000000000000000000000000602082015290565b6106a7611b4d3660046130bb565b5060408051808201909152600681527f696e743233320000000000000000000000000000000000000000000000000000602082015290565b6106a7611b933660046130de565b5060408051808201909152600781527f6279746573333200000000000000000000000000000000000000000000000000602082015290565b6106a7611bd93660046130de565b5060408051808201909152600781527f75696e7432353600000000000000000000000000000000000000000000000000602082015290565b6106a7611c1f3660046130f7565b5060408051808201909152600581527f696e743136000000000000000000000000000000000000000000000000000000602082015290565b6106a7611c6536600461311a565b5060408051808201909152600781527f6279746573313500000000000000000000000000000000000000000000000000602082015290565b6106a7611cab36600461315c565b5060408051808201909152600681527f75696e7435360000000000000000000000000000000000000000000000000000602082015290565b6106a7611cf1366004613185565b5060408051808201909152600781527f6279746573323300000000000000000000000000000000000000000000000000602082015290565b6106a7611d373660046131b1565b5060408051808201909152600681527f696e743234300000000000000000000000000000000000000000000000000000602082015290565b6106a7611d7d3660046131d4565b5060408051808201909152600681527f696e743136300000000000000000000000000000000000000000000000000000602082015290565b6106a7611dc33660046131f7565b5060408051808201909152600781527f75696e7431323800000000000000000000000000000000000000000000000000602082015290565b6106a7611e09366004613229565b5060408051808201909152600581527f696e743438000000000000000000000000000000000000000000000000000000602082015290565b6106a7611e4f36600461324c565b5060408051808201909152600481527f626f6f6c00000000000000000000000000000000000000000000000000000000602082015290565b6106a7611e9536600461326e565b5060408051808201909152600781527f6279746573313300000000000000000000000000000000000000000000000000602082015290565b6106a7611edb3660046132b0565b5060408051808201909152600781527f6279746573323200000000000000000000000000000000000000000000000000602082015290565b6106a7611f213660046130de565b5060408051808201909152600681527f696e743235360000000000000000000000000000000000000000000000000000602082015290565b6106a7611f673660046132dd565b5060408051808201909152600781527f6279746573313900000000000000000000000000000000000000000000000000602082015290565b6106a7611fad36600461330d565b5060408051808201909152600681527f696e743135320000000000000000000000000000000000000000000000000000602082015290565b6106a7611ff3366004613330565b5060408051808201909152600781527f75696e7431343400000000000000000000000000000000000000000000000000602082015290565b6106a7612039366004612b9a565b5060408051808201909152600681527f737472696e670000000000000000000000000000000000000000000000000000602082015290565b6106a761207f366004613364565b5060408051808201909152600581527f696e743234000000000000000000000000000000000000000000000000000000602082015290565b6106a76120c5366004613387565b5060408051808201909152600781527f6279746573313100000000000000000000000000000000000000000000000000602082015290565b6106a761210b3660046133c9565b5060408051808201909152600581527f696e743536000000000000000000000000000000000000000000000000000000602082015290565b6106a76121513660046133ec565b5060408051808201909152600681527f696e743134340000000000000000000000000000000000000000000000000000602082015290565b6106a761219736600461340f565b5060408051808201909152600681527f6279746573310000000000000000000000000000000000000000000000000000602082015290565b6000602082840312156121e157600080fd5b813563ffffffff811681146121f557600080fd5b9392505050565b600060208083528351808285015260005b818110156122295785810183015185820160400152820161220d565b506000604082860101526040601f19601f8301168501019250505092915050565b60006020828403121561225c57600080fd5b813567ffffffffffffffff19811681146121f557600080fd5b60006020828403121561228757600080fd5b81358060190b81146121f557600080fd5b6000602082840312156122aa57600080fd5b813575ffffffffffffffffffffffffffffffffffffffffffff811681146121f557600080fd5b6000602082840312156122e257600080fd5b81357fffffffff00000000000000000000000000000000000000000000000000000000811681146121f557600080fd5b60006020828403121561232457600080fd5b81357fffffffffffffffffff0000000000000000000000000000000000000000000000811681146121f557600080fd5b60006020828403121561236657600080fd5b81358060080b81146121f557600080fd5b60006020828403121561238957600080fd5b813578ffffffffffffffffffffffffffffffffffffffffffffffffff811681146121f557600080fd5b6000602082840312156123c457600080fd5b81356bffffffffffffffffffffffff19811681146121f557600080fd5b6000602082840312156123f357600080fd5b81358060030b81146121f557600080fd5b60006020828403121561241657600080fd5b81357affffffffffffffffffffffffffffffffffffffffffffffffffffff811681146121f557600080fd5b60006020828403121561245357600080fd5b813576ffffffffffffffffffffffffffffffffffffffffffffff811681146121f557600080fd5b60006020828403121561248c57600080fd5b813572ffffffffffffffffffffffffffffffffffffff811681146121f557600080fd5b6000602082840312156124c157600080fd5b813580601e0b81146121f557600080fd5b6000602082840312156124e457600080fd5b813569ffffffffffffffffffff811681146121f557600080fd5b60006020828403121561251057600080fd5b813563ffffffff19811681146121f557600080fd5b60006020828403121561253757600080fd5b813561ffff19811681146121f557600080fd5b60006020828403121561255c57600080fd5b813580600e0b81146121f557600080fd5b60006020828403121561257f57600080fd5b81356affffffffffffffffffffff19811681146121f557600080fd5b6000602082840312156125ad57600080fd5b81356cffffffffffffffffffffffffff811681146121f557600080fd5b6000602082840312156125dc57600080fd5b813580600b0b81146121f557600080fd5b6000602082840312156125ff57600080fd5b81357bffffffffffffffffffffffffffffffffffffffffffffffffffffffff811681146121f557600080fd5b60006020828403121561263d57600080fd5b81358060140b81146121f557600080fd5b60006020828403121561266057600080fd5b81358060180b81146121f557600080fd5b60006020828403121561268357600080fd5b81358060160b81146121f557600080fd5b6000602082840312156126a657600080fd5b81357fffffffffffffffffffffffffffff000000000000000000000000000000000000811681146121f557600080fd5b6000602082840312156126e857600080fd5b813577ffffffffffffffffffffffffffffffffffffffffffffffff811681146121f557600080fd5b60006020828403121561272257600080fd5b81357fffff000000000000000000000000000000000000000000000000000000000000811681146121f557600080fd5b60006020828403121561276457600080fd5b813562ffffff811681146121f557600080fd5b60006020828403121561278957600080fd5b813580600d0b81146121f557600080fd5b6000602082840312156127ac57600080fd5b81357fffffffffffff0000000000000000000000000000000000000000000000000000811681146121f557600080fd5b6000602082840312156127ee57600080fd5b813561ffff811681146121f557600080fd5b60006020828403121561281257600080fd5b81357fffffff0000000000000000000000000000000000000000000000000000000000811681146121f557600080fd5b60006020828403121561285457600080fd5b81356effffffffffffffffffffffffffffff19811681146121f557600080fd5b60006020828403121561288657600080fd5b813580601b0b81146121f557600080fd5b6000602082840312156128a957600080fd5b813580600f0b81146121f557600080fd5b6000602082840312156128cc57600080fd5b81356dffffffffffffffffffffffffffff19811681146121f557600080fd5b6000602082840312156128fd57600080fd5b813580600c0b81146121f557600080fd5b60006020828403121561292057600080fd5b81357fffffffffffffff00000000000000000000000000000000000000000000000000811681146121f557600080fd5b60006020828403121561296257600080fd5b813566ffffffffffffff19811681146121f557600080fd5b60006020828403121561298c57600080fd5b813564ffffffffff811681146121f557600080fd5b6000602082840312156129b357600080fd5b81356effffffffffffffffffffffffffffff811681146121f557600080fd5b6000602082840312156129e457600080fd5b813574ffffffffffffffffffffffffffffffffffffffffff811681146121f557600080fd5b600060208284031215612a1b57600080fd5b81358060100b81146121f557600080fd5b600060208284031215612a3e57600080fd5b81357effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff811681146121f557600080fd5b600060208284031215612a7f57600080fd5b81357fffffffffffffffff000000000000000000000000000000000000000000000000811681146121f557600080fd5b600060208284031215612ac157600080fd5b81358060170b81146121f557600080fd5b600060208284031215612ae457600080fd5b813580601a0b81146121f557600080fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600067ffffffffffffffff80841115612b3f57612b3f612af5565b604051601f8501601f19908116603f01168101908282118183101715612b6757612b67612af5565b81604052809350858152868686011115612b8057600080fd5b858560208301376000602087830101525050509392505050565b600060208284031215612bac57600080fd5b813567ffffffffffffffff811115612bc357600080fd5b8201601f81018413612bd457600080fd5b612be384823560208401612b24565b949350505050565b600060208284031215612bfd57600080fd5b81357dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff811681146121f557600080fd5b600060208284031215612c3d57600080fd5b81356dffffffffffffffffffffffffffff811681146121f557600080fd5b600060208284031215612c6d57600080fd5b813562ffffff19811681146121f557600080fd5b600060208284031215612c9357600080fd5b81358060090b81146121f557600080fd5b600060208284031215612cb657600080fd5b81358060150b81146121f557600080fd5b600060208284031215612cd957600080fd5b813560ff19811681146121f557600080fd5b600060208284031215612cfd57600080fd5b813560ff811681146121f557600080fd5b600060208284031215612d2057600080fd5b813579ffffffffffffffffffffffffffffffffffffffffffffffffffff811681146121f557600080fd5b600060208284031215612d5c57600080fd5b81356affffffffffffffffffffff811681146121f557600080fd5b600060208284031215612d8957600080fd5b81357fffffffffffffffffffff00000000000000000000000000000000000000000000811681146121f557600080fd5b600060208284031215612dcb57600080fd5b81357fffffffffffffffffffffffffffffffff00000000000000000000000000000000811681146121f557600080fd5b600060208284031215612e0d57600080fd5b813580600a0b81146121f557600080fd5b600060208284031215612e3057600080fd5b813567ffffffffffffffff811681146121f557600080fd5b73ffffffffffffffffffffffffffffffffffffffff81168114612e6a57600080fd5b50565b600060208284031215612e7f57600080fd5b81356121f581612e48565b600060208284031215612e9c57600080fd5b81357fffffffffffffffffffffffff0000000000000000000000000000000000000000811681146121f557600080fd5b600060208284031215612ede57600080fd5b813564ffffffffff19811681146121f557600080fd5b600060208284031215612f0657600080fd5b81358060070b81146121f557600080fd5b600060208284031215612f2957600080fd5b813570ffffffffffffffffffffffffffffffffff811681146121f557600080fd5b600060208284031215612f5c57600080fd5b81357cffffffffffffffffffffffffffffffffffffffffffffffffffffffffff811681146121f557600080fd5b600060208284031215612f9b57600080fd5b813565ffffffffffff19811681146121f557600080fd5b600060208284031215612fc457600080fd5b81357fffffffffff000000000000000000000000000000000000000000000000000000811681146121f557600080fd5b60006020828403121561300657600080fd5b813565ffffffffffff811681146121f557600080fd5b60006020828403121561302e57600080fd5b81358060040b81146121f557600080fd5b60006020828403121561305157600080fd5b81356bffffffffffffffffffffffff811681146121f557600080fd5b60006020828403121561307f57600080fd5b81358060000b81146121f557600080fd5b6000602082840312156130a257600080fd5b813568ffffffffffffffffff811681146121f557600080fd5b6000602082840312156130cd57600080fd5b813580601c0b81146121f557600080fd5b6000602082840312156130f057600080fd5b5035919050565b60006020828403121561310957600080fd5b81358060010b81146121f557600080fd5b60006020828403121561312c57600080fd5b81357fffffffffffffffffffffffffffffff0000000000000000000000000000000000811681146121f557600080fd5b60006020828403121561316e57600080fd5b813566ffffffffffffff811681146121f557600080fd5b60006020828403121561319757600080fd5b813568ffffffffffffffffff19811681146121f557600080fd5b6000602082840312156131c357600080fd5b813580601d0b81146121f557600080fd5b6000602082840312156131e657600080fd5b81358060130b81146121f557600080fd5b60006020828403121561320957600080fd5b81356fffffffffffffffffffffffffffffffff811681146121f557600080fd5b60006020828403121561323b57600080fd5b81358060050b81146121f557600080fd5b60006020828403121561325e57600080fd5b813580151581146121f557600080fd5b60006020828403121561328057600080fd5b81357fffffffffffffffffffffffffff00000000000000000000000000000000000000811681146121f557600080fd5b6000602082840312156132c257600080fd5b813569ffffffffffffffffffff19811681146121f557600080fd5b6000602082840312156132ef57600080fd5b81356cffffffffffffffffffffffffff19811681146121f557600080fd5b60006020828403121561331f57600080fd5b81358060120b81146121f557600080fd5b60006020828403121561334257600080fd5b813571ffffffffffffffffffffffffffffffffffff811681146121f557600080fd5b60006020828403121561337657600080fd5b81358060020b81146121f557600080fd5b60006020828403121561339957600080fd5b81357fffffffffffffffffffffff000000000000000000000000000000000000000000811681146121f557600080fd5b6000602082840312156133db57600080fd5b81358060060b81146121f557600080fd5b6000602082840312156133fe57600080fd5b81358060110b81146121f557600080fd5b60006020828403121561342157600080fd5b81357fff00000000000000000000000000000000000000000000000000000000000000811681146121f557600080fdfea2646970667358221220c03630ca6910d46ede5cae5ed1f6ae9571e1ccb99a0b3b83f560d5c9079c96db64736f6c637822302e382e31392d646576656c6f702b636f6d6d69742e63383866343066642e6d6f640053", + "deployedBytecode": "0x608060405234801561001057600080fd5b506004361061065c5760003560e01c8063a202e8c011610345578063cec31ded116101bd578063e96add8c11610104578063f3164597116100ad578063f85a090311610087578063f85a0903146120b7578063fa4d99c9146120fd578063fbf3e13a14612143578063fd1652cb1461218957600080fd5b8063f316459714611fe5578063f44076171461202b578063f7b0e3d51461207157600080fd5b8063eecd1129116100de578063eecd112914611f13578063ef4483be14611f59578063f0fb21ff14611f9f57600080fd5b8063e96add8c14611e41578063e9da42ca14611e87578063eb01940114611ecd57600080fd5b8063d92e6c0611610166578063e0fa6ea111610140578063e0fa6ea114611d6f578063e137fb7014611db5578063e8fb922314611dfb57600080fd5b8063d92e6c0614611c9d578063dad2ef4f14611ce3578063dafbc72414611d2957600080fd5b8063d4b789d811610197578063d4b789d814611bcb578063d4c0c48614611c11578063d7d7398414611c5757600080fd5b8063cec31ded14611af9578063d0e03b0714611b3f578063d20f679a14611b8557600080fd5b8063bbeb25e01161028c578063c233fd3311610235578063c84ad5801161020f578063c84ad580146119e1578063c8ddda4a14611a27578063cc69cf9714611a6d578063ccd94f9814611ab357600080fd5b8063c233fd331461190f578063c639604b14611955578063c847fe3b1461199b57600080fd5b8063c081607b11610266578063c081607b1461183d578063c1397e9914611883578063c1847bee146118c957600080fd5b8063bbeb25e01461176b578063bccdc9c4146117b1578063bf01c7f9146117f757600080fd5b8063ad87e2e1116102ee578063b860f47f116102c8578063b860f47f14611699578063ba607fac146116df578063bb73447f1461172557600080fd5b8063ad87e2e1146115c7578063b429b23c1461160d578063b7bab2861461165357600080fd5b8063a925e7621161031f578063a925e762146114f5578063a95d606e1461153b578063aa8de9461461158157600080fd5b8063a202e8c014611423578063a3ab9e7a14611469578063a6496f62146114af57600080fd5b806351e0489a116104d85780637c9affcb1161041f578063891a099d116103c85780639df2391c116103a25780639df2391c1461130b5780639faf388f146113515780639fcbede614611397578063a178b800146113dd57600080fd5b8063891a099d146112395780638e4884d11461127f5780639ded4e2b146112c557600080fd5b806381c4b4cc116103f957806381c4b4cc146111675780638275b290146111ad57806387ad7515146111f357600080fd5b80637c9affcb146110955780637fcc3d5d146110db578063803bf56d1461112157600080fd5b80636913a82b11610481578063769008e41161045b578063769008e414610fc35780637a3058c1146110095780637bc705c11461104f57600080fd5b80636913a82b14610ef15780636a678a7514610f3757806375b5533714610f7d57600080fd5b80636357d3b7116104b25780636357d3b714610e1f578063659665f914610e65578063679b530214610eab57600080fd5b806351e0489a14610d4d57806357301b0214610d935780635793d40814610dd957600080fd5b80632a0caa6a116105a7578063429545a4116105505780634961a7ce1161052a5780634961a7ce14610c355780634a3ccd5f14610c7b5780634fb7d4bd14610cc157806350fbcfb614610d0757600080fd5b8063429545a414610b6357806343c84f3314610ba957806346d79d1314610bef57600080fd5b806333c064151161058157806333c0641514610a9157806334bdbab714610ad75780634029cdee14610b1d57600080fd5b80632a0caa6a146109bf5780632a97dfbf14610a055780632f0d528b14610a4b57600080fd5b80631b46fa941161060957806325cb6b9a116105e357806325cb6b9a146108ed57806326888cda1461093357806328b01d811461097957600080fd5b80631b46fa941461081b5780631eb765fd1461086157806325bc2c82146108a757600080fd5b8063107810d51161063a578063107810d5146107495780631400a02f1461078f5780631a762a3a146107d557600080fd5b806303290450146106615780630e9ba011146106bd5780630f84821114610703575b600080fd5b6106a761066f3660046121cf565b5060408051808201909152600681527f75696e7433320000000000000000000000000000000000000000000000000000602082015290565b6040516106b491906121fc565b60405180910390f35b6106a76106cb36600461224a565b5060408051808201909152600781527f6279746573323400000000000000000000000000000000000000000000000000602082015290565b6106a7610711366004612275565b5060408051808201909152600681527f696e743230380000000000000000000000000000000000000000000000000000602082015290565b6106a7610757366004612298565b5060408051808201909152600781527f75696e7431373600000000000000000000000000000000000000000000000000602082015290565b6106a761079d3660046122d0565b5060408051808201909152600681527f6279746573340000000000000000000000000000000000000000000000000000602082015290565b6106a76107e3366004612312565b5060408051808201909152600681527f6279746573390000000000000000000000000000000000000000000000000000602082015290565b6106a7610829366004612354565b5060408051808201909152600581527f696e743732000000000000000000000000000000000000000000000000000000602082015290565b6106a761086f366004612377565b5060408051808201909152600781527f75696e7432303000000000000000000000000000000000000000000000000000602082015290565b6106a76108b53660046123b2565b5060408051808201909152600781527f6279746573323000000000000000000000000000000000000000000000000000602082015290565b6106a76108fb3660046123e1565b5060408051808201909152600581527f696e743332000000000000000000000000000000000000000000000000000000602082015290565b6106a7610941366004612404565b5060408051808201909152600781527f75696e7432313600000000000000000000000000000000000000000000000000602082015290565b6106a7610987366004612441565b5060408051808201909152600781527f75696e7431383400000000000000000000000000000000000000000000000000602082015290565b6106a76109cd36600461247a565b5060408051808201909152600781527f75696e7431353200000000000000000000000000000000000000000000000000602082015290565b6106a7610a133660046124af565b5060408051808201909152600681527f696e743234380000000000000000000000000000000000000000000000000000602082015290565b6106a7610a593660046124d2565b5060408051808201909152600681527f75696e7438300000000000000000000000000000000000000000000000000000602082015290565b6106a7610a9f3660046124fe565b5060408051808201909152600781527f6279746573323800000000000000000000000000000000000000000000000000602082015290565b6106a7610ae5366004612525565b5060408051808201909152600781527f6279746573333000000000000000000000000000000000000000000000000000602082015290565b6106a7610b2b36600461254a565b5060408051808201909152600681527f696e743132300000000000000000000000000000000000000000000000000000602082015290565b6106a7610b7136600461256d565b5060408051808201909152600781527f6279746573323100000000000000000000000000000000000000000000000000602082015290565b6106a7610bb736600461259b565b5060408051808201909152600781527f75696e7431303400000000000000000000000000000000000000000000000000602082015290565b6106a7610bfd3660046125ca565b5060408051808201909152600581527f696e743936000000000000000000000000000000000000000000000000000000602082015290565b6106a7610c433660046125ed565b5060408051808201909152600781527f75696e7432323400000000000000000000000000000000000000000000000000602082015290565b6106a7610c8936600461262b565b5060408051808201909152600681527f696e743136380000000000000000000000000000000000000000000000000000602082015290565b6106a7610ccf36600461264e565b5060408051808201909152600681527f696e743230300000000000000000000000000000000000000000000000000000602082015290565b6106a7610d15366004612671565b5060408051808201909152600681527f696e743138340000000000000000000000000000000000000000000000000000602082015290565b6106a7610d5b366004612694565b5060408051808201909152600781527f6279746573313400000000000000000000000000000000000000000000000000602082015290565b6106a7610da13660046126d6565b5060408051808201909152600781527f75696e7431393200000000000000000000000000000000000000000000000000602082015290565b6106a7610de7366004612710565b5060408051808201909152600681527f6279746573320000000000000000000000000000000000000000000000000000602082015290565b6106a7610e2d366004612752565b5060408051808201909152600681527f75696e7432340000000000000000000000000000000000000000000000000000602082015290565b6106a7610e73366004612777565b5060408051808201909152600681527f696e743131320000000000000000000000000000000000000000000000000000602082015290565b6106a7610eb936600461279a565b5060408051808201909152600681527f6279746573360000000000000000000000000000000000000000000000000000602082015290565b6106a7610eff3660046127dc565b5060408051808201909152600681527f75696e7431360000000000000000000000000000000000000000000000000000602082015290565b6106a7610f45366004612800565b5060408051808201909152600681527f6279746573330000000000000000000000000000000000000000000000000000602082015290565b6106a7610f8b366004612842565b5060408051808201909152600781527f6279746573313700000000000000000000000000000000000000000000000000602082015290565b6106a7610fd1366004612874565b5060408051808201909152600681527f696e743232340000000000000000000000000000000000000000000000000000602082015290565b6106a7611017366004612897565b5060408051808201909152600681527f696e743132380000000000000000000000000000000000000000000000000000602082015290565b6106a761105d3660046128ba565b5060408051808201909152600781527f6279746573313800000000000000000000000000000000000000000000000000602082015290565b6106a76110a33660046128eb565b5060408051808201909152600681527f696e743130340000000000000000000000000000000000000000000000000000602082015290565b6106a76110e936600461290e565b5060408051808201909152600681527f6279746573370000000000000000000000000000000000000000000000000000602082015290565b6106a761112f366004612950565b5060408051808201909152600781527f6279746573323500000000000000000000000000000000000000000000000000602082015290565b6106a761117536600461297a565b5060408051808201909152600681527f75696e7434300000000000000000000000000000000000000000000000000000602082015290565b6106a76111bb3660046129a1565b5060408051808201909152600781527f75696e7431323000000000000000000000000000000000000000000000000000602082015290565b6106a76112013660046129d2565b5060408051808201909152600781527f75696e7431363800000000000000000000000000000000000000000000000000602082015290565b6106a7611247366004612a09565b5060408051808201909152600681527f696e743133360000000000000000000000000000000000000000000000000000602082015290565b6106a761128d366004612a2c565b5060408051808201909152600781527f75696e7432343800000000000000000000000000000000000000000000000000602082015290565b6106a76112d3366004612a6d565b5060408051808201909152600681527f6279746573380000000000000000000000000000000000000000000000000000602082015290565b6106a7611319366004612aaf565b5060408051808201909152600681527f696e743139320000000000000000000000000000000000000000000000000000602082015290565b6106a761135f366004612ad2565b5060408051808201909152600681527f696e743231360000000000000000000000000000000000000000000000000000602082015290565b6106a76113a5366004612b9a565b5060408051808201909152600581527f6279746573000000000000000000000000000000000000000000000000000000602082015290565b6106a76113eb366004612beb565b5060408051808201909152600781527f75696e7432343000000000000000000000000000000000000000000000000000602082015290565b6106a7611431366004612c2b565b5060408051808201909152600781527f75696e7431313200000000000000000000000000000000000000000000000000602082015290565b6106a7611477366004612c5b565b5060408051808201909152600781527f6279746573323900000000000000000000000000000000000000000000000000602082015290565b6106a76114bd366004612c81565b5060408051808201909152600581527f696e743830000000000000000000000000000000000000000000000000000000602082015290565b6106a7611503366004612ca4565b5060408051808201909152600681527f696e743137360000000000000000000000000000000000000000000000000000602082015290565b6106a7611549366004612cc7565b5060408051808201909152600781527f6279746573333100000000000000000000000000000000000000000000000000602082015290565b6106a761158f366004612ceb565b5060408051808201909152600581527f75696e7438000000000000000000000000000000000000000000000000000000602082015290565b6106a76115d5366004612d0e565b5060408051808201909152600781527f75696e7432303800000000000000000000000000000000000000000000000000602082015290565b6106a761161b366004612d4a565b5060408051808201909152600681527f75696e7438380000000000000000000000000000000000000000000000000000602082015290565b6106a7611661366004612d77565b5060408051808201909152600781527f6279746573313000000000000000000000000000000000000000000000000000602082015290565b6106a76116a7366004612db9565b5060408051808201909152600781527f6279746573313600000000000000000000000000000000000000000000000000602082015290565b6106a76116ed366004612dfb565b5060408051808201909152600581527f696e743838000000000000000000000000000000000000000000000000000000602082015290565b6106a7611733366004612e1e565b5060408051808201909152600681527f75696e7436340000000000000000000000000000000000000000000000000000602082015290565b6106a7611779366004612e6d565b5060408051808201909152600781527f6164647265737300000000000000000000000000000000000000000000000000602082015290565b6106a76117bf366004612e8a565b5060408051808201909152600781527f6279746573313200000000000000000000000000000000000000000000000000602082015290565b6106a7611805366004612ecc565b5060408051808201909152600781527f6279746573323700000000000000000000000000000000000000000000000000602082015290565b6106a761184b366004612ef4565b5060408051808201909152600581527f696e743634000000000000000000000000000000000000000000000000000000602082015290565b6106a7611891366004612f17565b5060408051808201909152600781527f75696e7431333600000000000000000000000000000000000000000000000000602082015290565b6106a76118d7366004612f4a565b5060408051808201909152600781527f75696e7432333200000000000000000000000000000000000000000000000000602082015290565b6106a761191d366004612f89565b5060408051808201909152600781527f6279746573323600000000000000000000000000000000000000000000000000602082015290565b6106a7611963366004612fb2565b5060408051808201909152600681527f6279746573350000000000000000000000000000000000000000000000000000602082015290565b6106a76119a9366004612ff4565b5060408051808201909152600681527f75696e7434380000000000000000000000000000000000000000000000000000602082015290565b6106a76119ef36600461301c565b5060408051808201909152600581527f696e743430000000000000000000000000000000000000000000000000000000602082015290565b6106a7611a3536600461303f565b5060408051808201909152600681527f75696e7439360000000000000000000000000000000000000000000000000000602082015290565b6106a7611a7b366004612e6d565b5060408051808201909152600781527f75696e7431363000000000000000000000000000000000000000000000000000602082015290565b6106a7611ac136600461306d565b5060408051808201909152600481527f696e743800000000000000000000000000000000000000000000000000000000602082015290565b6106a7611b07366004613090565b5060408051808201909152600681527f75696e7437320000000000000000000000000000000000000000000000000000602082015290565b6106a7611b4d3660046130bb565b5060408051808201909152600681527f696e743233320000000000000000000000000000000000000000000000000000602082015290565b6106a7611b933660046130de565b5060408051808201909152600781527f6279746573333200000000000000000000000000000000000000000000000000602082015290565b6106a7611bd93660046130de565b5060408051808201909152600781527f75696e7432353600000000000000000000000000000000000000000000000000602082015290565b6106a7611c1f3660046130f7565b5060408051808201909152600581527f696e743136000000000000000000000000000000000000000000000000000000602082015290565b6106a7611c6536600461311a565b5060408051808201909152600781527f6279746573313500000000000000000000000000000000000000000000000000602082015290565b6106a7611cab36600461315c565b5060408051808201909152600681527f75696e7435360000000000000000000000000000000000000000000000000000602082015290565b6106a7611cf1366004613185565b5060408051808201909152600781527f6279746573323300000000000000000000000000000000000000000000000000602082015290565b6106a7611d373660046131b1565b5060408051808201909152600681527f696e743234300000000000000000000000000000000000000000000000000000602082015290565b6106a7611d7d3660046131d4565b5060408051808201909152600681527f696e743136300000000000000000000000000000000000000000000000000000602082015290565b6106a7611dc33660046131f7565b5060408051808201909152600781527f75696e7431323800000000000000000000000000000000000000000000000000602082015290565b6106a7611e09366004613229565b5060408051808201909152600581527f696e743438000000000000000000000000000000000000000000000000000000602082015290565b6106a7611e4f36600461324c565b5060408051808201909152600481527f626f6f6c00000000000000000000000000000000000000000000000000000000602082015290565b6106a7611e9536600461326e565b5060408051808201909152600781527f6279746573313300000000000000000000000000000000000000000000000000602082015290565b6106a7611edb3660046132b0565b5060408051808201909152600781527f6279746573323200000000000000000000000000000000000000000000000000602082015290565b6106a7611f213660046130de565b5060408051808201909152600681527f696e743235360000000000000000000000000000000000000000000000000000602082015290565b6106a7611f673660046132dd565b5060408051808201909152600781527f6279746573313900000000000000000000000000000000000000000000000000602082015290565b6106a7611fad36600461330d565b5060408051808201909152600681527f696e743135320000000000000000000000000000000000000000000000000000602082015290565b6106a7611ff3366004613330565b5060408051808201909152600781527f75696e7431343400000000000000000000000000000000000000000000000000602082015290565b6106a7612039366004612b9a565b5060408051808201909152600681527f737472696e670000000000000000000000000000000000000000000000000000602082015290565b6106a761207f366004613364565b5060408051808201909152600581527f696e743234000000000000000000000000000000000000000000000000000000602082015290565b6106a76120c5366004613387565b5060408051808201909152600781527f6279746573313100000000000000000000000000000000000000000000000000602082015290565b6106a761210b3660046133c9565b5060408051808201909152600581527f696e743536000000000000000000000000000000000000000000000000000000602082015290565b6106a76121513660046133ec565b5060408051808201909152600681527f696e743134340000000000000000000000000000000000000000000000000000602082015290565b6106a761219736600461340f565b5060408051808201909152600681527f6279746573310000000000000000000000000000000000000000000000000000602082015290565b6000602082840312156121e157600080fd5b813563ffffffff811681146121f557600080fd5b9392505050565b600060208083528351808285015260005b818110156122295785810183015185820160400152820161220d565b506000604082860101526040601f19601f8301168501019250505092915050565b60006020828403121561225c57600080fd5b813567ffffffffffffffff19811681146121f557600080fd5b60006020828403121561228757600080fd5b81358060190b81146121f557600080fd5b6000602082840312156122aa57600080fd5b813575ffffffffffffffffffffffffffffffffffffffffffff811681146121f557600080fd5b6000602082840312156122e257600080fd5b81357fffffffff00000000000000000000000000000000000000000000000000000000811681146121f557600080fd5b60006020828403121561232457600080fd5b81357fffffffffffffffffff0000000000000000000000000000000000000000000000811681146121f557600080fd5b60006020828403121561236657600080fd5b81358060080b81146121f557600080fd5b60006020828403121561238957600080fd5b813578ffffffffffffffffffffffffffffffffffffffffffffffffff811681146121f557600080fd5b6000602082840312156123c457600080fd5b81356bffffffffffffffffffffffff19811681146121f557600080fd5b6000602082840312156123f357600080fd5b81358060030b81146121f557600080fd5b60006020828403121561241657600080fd5b81357affffffffffffffffffffffffffffffffffffffffffffffffffffff811681146121f557600080fd5b60006020828403121561245357600080fd5b813576ffffffffffffffffffffffffffffffffffffffffffffff811681146121f557600080fd5b60006020828403121561248c57600080fd5b813572ffffffffffffffffffffffffffffffffffffff811681146121f557600080fd5b6000602082840312156124c157600080fd5b813580601e0b81146121f557600080fd5b6000602082840312156124e457600080fd5b813569ffffffffffffffffffff811681146121f557600080fd5b60006020828403121561251057600080fd5b813563ffffffff19811681146121f557600080fd5b60006020828403121561253757600080fd5b813561ffff19811681146121f557600080fd5b60006020828403121561255c57600080fd5b813580600e0b81146121f557600080fd5b60006020828403121561257f57600080fd5b81356affffffffffffffffffffff19811681146121f557600080fd5b6000602082840312156125ad57600080fd5b81356cffffffffffffffffffffffffff811681146121f557600080fd5b6000602082840312156125dc57600080fd5b813580600b0b81146121f557600080fd5b6000602082840312156125ff57600080fd5b81357bffffffffffffffffffffffffffffffffffffffffffffffffffffffff811681146121f557600080fd5b60006020828403121561263d57600080fd5b81358060140b81146121f557600080fd5b60006020828403121561266057600080fd5b81358060180b81146121f557600080fd5b60006020828403121561268357600080fd5b81358060160b81146121f557600080fd5b6000602082840312156126a657600080fd5b81357fffffffffffffffffffffffffffff000000000000000000000000000000000000811681146121f557600080fd5b6000602082840312156126e857600080fd5b813577ffffffffffffffffffffffffffffffffffffffffffffffff811681146121f557600080fd5b60006020828403121561272257600080fd5b81357fffff000000000000000000000000000000000000000000000000000000000000811681146121f557600080fd5b60006020828403121561276457600080fd5b813562ffffff811681146121f557600080fd5b60006020828403121561278957600080fd5b813580600d0b81146121f557600080fd5b6000602082840312156127ac57600080fd5b81357fffffffffffff0000000000000000000000000000000000000000000000000000811681146121f557600080fd5b6000602082840312156127ee57600080fd5b813561ffff811681146121f557600080fd5b60006020828403121561281257600080fd5b81357fffffff0000000000000000000000000000000000000000000000000000000000811681146121f557600080fd5b60006020828403121561285457600080fd5b81356effffffffffffffffffffffffffffff19811681146121f557600080fd5b60006020828403121561288657600080fd5b813580601b0b81146121f557600080fd5b6000602082840312156128a957600080fd5b813580600f0b81146121f557600080fd5b6000602082840312156128cc57600080fd5b81356dffffffffffffffffffffffffffff19811681146121f557600080fd5b6000602082840312156128fd57600080fd5b813580600c0b81146121f557600080fd5b60006020828403121561292057600080fd5b81357fffffffffffffff00000000000000000000000000000000000000000000000000811681146121f557600080fd5b60006020828403121561296257600080fd5b813566ffffffffffffff19811681146121f557600080fd5b60006020828403121561298c57600080fd5b813564ffffffffff811681146121f557600080fd5b6000602082840312156129b357600080fd5b81356effffffffffffffffffffffffffffff811681146121f557600080fd5b6000602082840312156129e457600080fd5b813574ffffffffffffffffffffffffffffffffffffffffff811681146121f557600080fd5b600060208284031215612a1b57600080fd5b81358060100b81146121f557600080fd5b600060208284031215612a3e57600080fd5b81357effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff811681146121f557600080fd5b600060208284031215612a7f57600080fd5b81357fffffffffffffffff000000000000000000000000000000000000000000000000811681146121f557600080fd5b600060208284031215612ac157600080fd5b81358060170b81146121f557600080fd5b600060208284031215612ae457600080fd5b813580601a0b81146121f557600080fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600067ffffffffffffffff80841115612b3f57612b3f612af5565b604051601f8501601f19908116603f01168101908282118183101715612b6757612b67612af5565b81604052809350858152868686011115612b8057600080fd5b858560208301376000602087830101525050509392505050565b600060208284031215612bac57600080fd5b813567ffffffffffffffff811115612bc357600080fd5b8201601f81018413612bd457600080fd5b612be384823560208401612b24565b949350505050565b600060208284031215612bfd57600080fd5b81357dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff811681146121f557600080fd5b600060208284031215612c3d57600080fd5b81356dffffffffffffffffffffffffffff811681146121f557600080fd5b600060208284031215612c6d57600080fd5b813562ffffff19811681146121f557600080fd5b600060208284031215612c9357600080fd5b81358060090b81146121f557600080fd5b600060208284031215612cb657600080fd5b81358060150b81146121f557600080fd5b600060208284031215612cd957600080fd5b813560ff19811681146121f557600080fd5b600060208284031215612cfd57600080fd5b813560ff811681146121f557600080fd5b600060208284031215612d2057600080fd5b813579ffffffffffffffffffffffffffffffffffffffffffffffffffff811681146121f557600080fd5b600060208284031215612d5c57600080fd5b81356affffffffffffffffffffff811681146121f557600080fd5b600060208284031215612d8957600080fd5b81357fffffffffffffffffffff00000000000000000000000000000000000000000000811681146121f557600080fd5b600060208284031215612dcb57600080fd5b81357fffffffffffffffffffffffffffffffff00000000000000000000000000000000811681146121f557600080fd5b600060208284031215612e0d57600080fd5b813580600a0b81146121f557600080fd5b600060208284031215612e3057600080fd5b813567ffffffffffffffff811681146121f557600080fd5b73ffffffffffffffffffffffffffffffffffffffff81168114612e6a57600080fd5b50565b600060208284031215612e7f57600080fd5b81356121f581612e48565b600060208284031215612e9c57600080fd5b81357fffffffffffffffffffffffff0000000000000000000000000000000000000000811681146121f557600080fd5b600060208284031215612ede57600080fd5b813564ffffffffff19811681146121f557600080fd5b600060208284031215612f0657600080fd5b81358060070b81146121f557600080fd5b600060208284031215612f2957600080fd5b813570ffffffffffffffffffffffffffffffffff811681146121f557600080fd5b600060208284031215612f5c57600080fd5b81357cffffffffffffffffffffffffffffffffffffffffffffffffffffffffff811681146121f557600080fd5b600060208284031215612f9b57600080fd5b813565ffffffffffff19811681146121f557600080fd5b600060208284031215612fc457600080fd5b81357fffffffffff000000000000000000000000000000000000000000000000000000811681146121f557600080fd5b60006020828403121561300657600080fd5b813565ffffffffffff811681146121f557600080fd5b60006020828403121561302e57600080fd5b81358060040b81146121f557600080fd5b60006020828403121561305157600080fd5b81356bffffffffffffffffffffffff811681146121f557600080fd5b60006020828403121561307f57600080fd5b81358060000b81146121f557600080fd5b6000602082840312156130a257600080fd5b813568ffffffffffffffffff811681146121f557600080fd5b6000602082840312156130cd57600080fd5b813580601c0b81146121f557600080fd5b6000602082840312156130f057600080fd5b5035919050565b60006020828403121561310957600080fd5b81358060010b81146121f557600080fd5b60006020828403121561312c57600080fd5b81357fffffffffffffffffffffffffffffff0000000000000000000000000000000000811681146121f557600080fd5b60006020828403121561316e57600080fd5b813566ffffffffffffff811681146121f557600080fd5b60006020828403121561319757600080fd5b813568ffffffffffffffffff19811681146121f557600080fd5b6000602082840312156131c357600080fd5b813580601d0b81146121f557600080fd5b6000602082840312156131e657600080fd5b81358060130b81146121f557600080fd5b60006020828403121561320957600080fd5b81356fffffffffffffffffffffffffffffffff811681146121f557600080fd5b60006020828403121561323b57600080fd5b81358060050b81146121f557600080fd5b60006020828403121561325e57600080fd5b813580151581146121f557600080fd5b60006020828403121561328057600080fd5b81357fffffffffffffffffffffffffff00000000000000000000000000000000000000811681146121f557600080fd5b6000602082840312156132c257600080fd5b813569ffffffffffffffffffff19811681146121f557600080fd5b6000602082840312156132ef57600080fd5b81356cffffffffffffffffffffffffff19811681146121f557600080fd5b60006020828403121561331f57600080fd5b81358060120b81146121f557600080fd5b60006020828403121561334257600080fd5b813571ffffffffffffffffffffffffffffffffffff811681146121f557600080fd5b60006020828403121561337657600080fd5b81358060020b81146121f557600080fd5b60006020828403121561339957600080fd5b81357fffffffffffffffffffffff000000000000000000000000000000000000000000811681146121f557600080fd5b6000602082840312156133db57600080fd5b81358060060b81146121f557600080fd5b6000602082840312156133fe57600080fd5b81358060110b81146121f557600080fd5b60006020828403121561342157600080fd5b81357fff00000000000000000000000000000000000000000000000000000000000000811681146121f557600080fdfea2646970667358221220c03630ca6910d46ede5cae5ed1f6ae9571e1ccb99a0b3b83f560d5c9079c96db64736f6c637822302e382e31392d646576656c6f702b636f6d6d69742e63383866343066642e6d6f640053", + "linkReferences": {}, + "deployedLinkReferences": {} +}; +export default TypedContract; +//# sourceMappingURL=TypedContract.js.map \ No newline at end of file diff --git a/lib.esm/_tests/contracts/TypedContract.js.map b/lib.esm/_tests/contracts/TypedContract.js.map new file mode 100644 index 00000000..2ee01c4a --- /dev/null +++ b/lib.esm/_tests/contracts/TypedContract.js.map @@ -0,0 +1 @@ +{"version":3,"file":"TypedContract.js","sourceRoot":"","sources":["../../../src.ts/_tests/contracts/TypedContract.ts"],"names":[],"mappings":"AAAA,MAAM,aAAa,GAAG;IACpB,SAAS,EAAE,mBAAmB;IAC9B,cAAc,EAAE,eAAe;IAC/B,YAAY,EAAE,yBAAyB;IACvC,KAAK,EAAE;QACL;YACE,QAAQ,EAAE;gBACR;oBACE,cAAc,EAAE,QAAQ;oBACxB,MAAM,EAAE,EAAE;oBACV,MAAM,EAAE,QAAQ;iBACjB;aACF;YACD,MAAM,EAAE,WAAW;YACnB,SAAS,EAAE;gBACT;oBACE,cAAc,EAAE,QAAQ;oBACxB,MAAM,EAAE,EAAE;oBACV,MAAM,EAAE,QAAQ;iBACjB;aACF;YACD,iBAAiB,EAAE,MAAM;YACzB,MAAM,EAAE,UAAU;SACnB;QACD;YACE,QAAQ,EAAE;gBACR;oBACE,cAAc,EAAE,SAAS;oBACzB,MAAM,EAAE,EAAE;oBACV,MAAM,EAAE,SAAS;iBAClB;aACF;YACD,MAAM,EAAE,WAAW;YACnB,SAAS,EAAE;gBACT;oBACE,cAAc,EAAE,QAAQ;oBACxB,MAAM,EAAE,EAAE;oBACV,MAAM,EAAE,QAAQ;iBACjB;aACF;YACD,iBAAiB,EAAE,MAAM;YACzB,MAAM,EAAE,UAAU;SACnB;QACD;YACE,QAAQ,EAAE;gBACR;oBACE,cAAc,EAAE,QAAQ;oBACxB,MAAM,EAAE,EAAE;oBACV,MAAM,EAAE,QAAQ;iBACjB;aACF;YACD,MAAM,EAAE,WAAW;YACnB,SAAS,EAAE;gBACT;oBACE,cAAc,EAAE,QAAQ;oBACxB,MAAM,EAAE,EAAE;oBACV,MAAM,EAAE,QAAQ;iBACjB;aACF;YACD,iBAAiB,EAAE,MAAM;YACzB,MAAM,EAAE,UAAU;SACnB;QACD;YACE,QAAQ,EAAE;gBACR;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M,EAAE,UAAU;SACnB;KACF;IACD,UAAU,EAAE,k50BAAk50B;IAC950B,kBAAkB,EAAE,k10BAAk10B;IACt20B,gBAAgB,EAAE,EAAE;IACpB,wBAAwB,EAAE,EAAE;CAC7B,CAAA;AAKD,eAAe,aAAa,CAAC"} \ No newline at end of file diff --git a/lib.esm/_tests/create-provider.d.ts b/lib.esm/_tests/create-provider.d.ts new file mode 100644 index 00000000..ef373e81 --- /dev/null +++ b/lib.esm/_tests/create-provider.d.ts @@ -0,0 +1,8 @@ +import type { AbstractProvider } from "../index.js"; +export declare function setupProviders(): void; +export declare const providerNames: readonly string[]; +export declare function getProviderNetworks(provider: string): Array; +export declare function getProvider(provider: string, network: string): null | AbstractProvider; +export declare function checkProvider(provider: string, network: string): boolean; +export declare function connect(network: string): AbstractProvider; +//# sourceMappingURL=create-provider.d.ts.map \ No newline at end of file diff --git a/lib.esm/_tests/create-provider.d.ts.map b/lib.esm/_tests/create-provider.d.ts.map new file mode 100644 index 00000000..3e7a7376 --- /dev/null +++ b/lib.esm/_tests/create-provider.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"create-provider.d.ts","sourceRoot":"","sources":["../../src.ts/_tests/create-provider.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAyBpD,wBAAgB,cAAc,IAAI,IAAI,CAKrC;AAED,eAAO,MAAM,aAAa,mBAAuD,CAAC;AAQlF,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAInE;AAED,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,gBAAgB,CAetF;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAGxE;AAED,wBAAgB,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,CAIzD"} \ No newline at end of file diff --git a/lib.esm/_tests/create-provider.js b/lib.esm/_tests/create-provider.js new file mode 100644 index 00000000..b93fd7b9 --- /dev/null +++ b/lib.esm/_tests/create-provider.js @@ -0,0 +1,72 @@ +import { isError, JsonRpcProvider, } from "../index.js"; +import dotenv from "dotenv"; +dotenv.config(); +; +const quaiNetworks = ["colosseum"]; +const ProviderCreators = [ + { + name: "JsonRpcProvider", + networks: quaiNetworks, + create: function (network) { + return new JsonRpcProvider(process.env.RPC_URL, network); + } + }, +]; +let setup = false; +const cleanup = []; +export function setupProviders() { + after(function () { + for (const func of cleanup) { + func(); + } + }); + setup = true; +} +export const providerNames = Object.freeze(ProviderCreators.map((c) => (c.name))); +function getCreator(provider) { + const creators = ProviderCreators.filter((c) => (c.name === provider)); + if (creators.length === 1) { + return creators[0]; + } + return null; +} +export function getProviderNetworks(provider) { + const creator = getCreator(provider); + if (creator) { + return creator.networks; + } + return []; +} +export function getProvider(provider, network) { + if (setup == false) { + throw new Error("MUST CALL setupProviders in root context"); + } + const creator = getCreator(provider); + try { + if (creator) { + const provider = creator.create(network); + if (provider) { + cleanup.push(() => { provider.destroy(); }); + } + return provider; + } + } + catch (error) { + if (!isError(error, "INVALID_ARGUMENT")) { + throw error; + } + } + return null; +} +export function checkProvider(provider, network) { + const creator = getCreator(provider); + return (creator != null); +} +export function connect(network) { + const provider = getProvider("JsonRpcProvider", network); + if (provider == null) { + throw new Error(`could not connect to ${network}`); + } + return provider; +} +//# sourceMappingURL=create-provider.js.map \ No newline at end of file diff --git a/lib.esm/_tests/create-provider.js.map b/lib.esm/_tests/create-provider.js.map new file mode 100644 index 00000000..9c56620d --- /dev/null +++ b/lib.esm/_tests/create-provider.js.map @@ -0,0 +1 @@ +{"version":3,"file":"create-provider.js","sourceRoot":"","sources":["../../src.ts/_tests/create-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,OAAO,EACP,eAAe,GAClB,MAAM,aAAa,CAAC;AAGrB,OAAO,MAAM,MAAM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OAAO,EAAG,CAAC;AACf,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,QAAgB,EAAE,OAAe;IACzD,IAAI,KAAK,IAAI,KAAK,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;KAAE;IACpF,MAAM,OAAO,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC;IACrC,IAAI;QACA,IAAI,OAAO,EAAE;YACT,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YACzC,IAAI,QAAQ,EAAE;gBACV,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;aAC/C;YACD,OAAO,QAAQ,CAAC;SACnB;KACJ;IAAC,OAAO,KAAK,EAAE;QACZ,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,kBAAkB,CAAC,EAAE;YAAE,MAAM,KAAK,CAAC;SAAE;KAC5D;IACD,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,QAAgB,EAAE,OAAe;IAC3D,MAAM,OAAO,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC;IACrC,OAAO,CAAC,OAAO,IAAI,IAAI,CAAC,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,OAAe;IACnC,MAAM,QAAQ,GAAG,WAAW,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAC;IACzD,IAAI,QAAQ,IAAI,IAAI,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,wBAAyB,OAAQ,EAAE,CAAC,CAAC;KAAE;IAC/E,OAAO,QAAQ,CAAC;AACpB,CAAC"} \ No newline at end of file diff --git a/lib.esm/_tests/index.d.ts b/lib.esm/_tests/index.d.ts new file mode 100644 index 00000000..2fa3fd57 --- /dev/null +++ b/lib.esm/_tests/index.d.ts @@ -0,0 +1,21 @@ +import "./test-abi.js"; +import "./test-address.js"; +import "./test-contract.js"; +import "./test-crypto.js"; +import "./test-hash.js"; +import "./test-hash-typeddata.js"; +import "./test-providers-avatar.js"; +import "./test-providers-ccip.js"; +import "./test-providers-wildcard.js"; +import "./test-rlp.js"; +import "./test-transaction.js"; +import "./test-utils-maths.js"; +import "./test-utils-misc.js"; +import "./test-utils-units.js"; +import "./test-utils-utf8.js"; +import "./test-wallet.js"; +import "./test-wallet-hd.js"; +import "./test-wallet-json.js"; +import "./test-wallet-mnemonic.js"; +import "./test-wordlists.js"; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/lib.esm/_tests/index.d.ts.map b/lib.esm/_tests/index.d.ts.map new file mode 100644 index 00000000..96135825 --- /dev/null +++ b/lib.esm/_tests/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src.ts/_tests/index.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC;AACvB,OAAO,mBAAmB,CAAA;AAC1B,OAAO,oBAAoB,CAAC;AAC5B,OAAO,kBAAkB,CAAC;AAC1B,OAAO,gBAAgB,CAAC;AACxB,OAAO,0BAA0B,CAAC;AAClC,OAAO,4BAA4B,CAAC;AACpC,OAAO,0BAA0B,CAAC;AAClC,OAAO,8BAA8B,CAAC;AACtC,OAAO,eAAe,CAAA;AACtB,OAAO,uBAAuB,CAAC;AAC/B,OAAO,uBAAuB,CAAC;AAC/B,OAAO,sBAAsB,CAAC;AAC9B,OAAO,uBAAuB,CAAC;AAC/B,OAAO,sBAAsB,CAAC;AAC9B,OAAO,kBAAkB,CAAC;AAC1B,OAAO,qBAAqB,CAAC;AAC7B,OAAO,uBAAuB,CAAC;AAC/B,OAAO,2BAA2B,CAAC;AACnC,OAAO,qBAAqB,CAAC"} \ No newline at end of file diff --git a/lib.esm/_tests/index.js b/lib.esm/_tests/index.js new file mode 100644 index 00000000..a1c99773 --- /dev/null +++ b/lib.esm/_tests/index.js @@ -0,0 +1,29 @@ +import "./test-abi.js"; +import "./test-address.js"; +import "./test-contract.js"; +import "./test-crypto.js"; +import "./test-hash.js"; +import "./test-hash-typeddata.js"; +import "./test-providers-avatar.js"; +import "./test-providers-ccip.js"; +import "./test-providers-wildcard.js"; +import "./test-rlp.js"; +import "./test-transaction.js"; +import "./test-utils-maths.js"; +import "./test-utils-misc.js"; +import "./test-utils-units.js"; +import "./test-utils-utf8.js"; +import "./test-wallet.js"; +import "./test-wallet-hd.js"; +import "./test-wallet-json.js"; +import "./test-wallet-mnemonic.js"; +import "./test-wordlists.js"; +////import "./test-contract-integ.js"; +////import "./test-providers-data.js"; +//import "./test-providers-errors.js"; +////import "./test-providers-extra.js"; +////import "./test-providers-send.js"; +/* +test-crypto-algoswap.ts +*/ +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib.esm/_tests/index.js.map b/lib.esm/_tests/index.js.map new file mode 100644 index 00000000..46ac6512 --- /dev/null +++ b/lib.esm/_tests/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src.ts/_tests/index.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC;AACvB,OAAO,mBAAmB,CAAA;AAC1B,OAAO,oBAAoB,CAAC;AAC5B,OAAO,kBAAkB,CAAC;AAC1B,OAAO,gBAAgB,CAAC;AACxB,OAAO,0BAA0B,CAAC;AAClC,OAAO,4BAA4B,CAAC;AACpC,OAAO,0BAA0B,CAAC;AAClC,OAAO,8BAA8B,CAAC;AACtC,OAAO,eAAe,CAAA;AACtB,OAAO,uBAAuB,CAAC;AAC/B,OAAO,uBAAuB,CAAC;AAC/B,OAAO,sBAAsB,CAAC;AAC9B,OAAO,uBAAuB,CAAC;AAC/B,OAAO,sBAAsB,CAAC;AAC9B,OAAO,kBAAkB,CAAC;AAC1B,OAAO,qBAAqB,CAAC;AAC7B,OAAO,uBAAuB,CAAC;AAC/B,OAAO,2BAA2B,CAAC;AACnC,OAAO,qBAAqB,CAAC;AAE7B,sCAAsC;AAEtC,sCAAsC;AACtC,sCAAsC;AACtC,uCAAuC;AACvC,sCAAsC;AAEtC;;EAEE"} \ No newline at end of file diff --git a/lib.esm/_tests/test-abi.d.ts b/lib.esm/_tests/test-abi.d.ts new file mode 100644 index 00000000..5a0731b4 --- /dev/null +++ b/lib.esm/_tests/test-abi.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=test-abi.d.ts.map \ No newline at end of file diff --git a/lib.esm/_tests/test-abi.d.ts.map b/lib.esm/_tests/test-abi.d.ts.map new file mode 100644 index 00000000..23df12e3 --- /dev/null +++ b/lib.esm/_tests/test-abi.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"test-abi.d.ts","sourceRoot":"","sources":["../../src.ts/_tests/test-abi.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/lib.esm/_tests/test-abi.js b/lib.esm/_tests/test-abi.js new file mode 100644 index 00000000..42dc08d2 --- /dev/null +++ b/lib.esm/_tests/test-abi.js @@ -0,0 +1,281 @@ +import assert from "assert"; +import { loadTests } from "./utils.js"; +import { AbiCoder, Interface, decodeBytes32String, encodeBytes32String } from "../index.js"; +function equal(actual, expected) { + switch (expected.type) { + case "address": + case "boolean": + case "hexstring": + case "string": + assert.equal(actual, expected.value); + return; + case "number": + assert.equal(actual, BigInt(expected.value)); + return; + case "array": + case "object": + assert.ok(Array.isArray(actual), "!array"); + assert.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 = loadTests("abi"); + for (const test of tests) { + it(`tests ABI encoding: (${test.name})`, function () { + const encoded = AbiCoder.defaultAbiCoder().encode([test.type], [test.value]); + assert.equal(encoded, test.encoded, "encoded"); + }); + } + for (const test of tests) { + it(`tests ABI decoding: (${test.name})`, function () { + const decoded = AbiCoder.defaultAbiCoder().decode([test.type], test.encoded)[0]; + equal(decoded, test.verbose); + }); + } +}); +describe("Test Bytes32 strings", function () { + const tests = [ + { + name: "ricmoo.firefly.eth", + str: "ricmoo.firefly.eth", + expected: '0x7269636d6f6f2e66697265666c792e6574680000000000000000000000000000' + }, + { + name: "empty string", + str: "", + expected: '0x0000000000000000000000000000000000000000000000000000000000000000' + } + ]; + for (const { name, str, expected } of tests) { + it(`encodes and decodes Bytes32 strings: ${name}`, function () { + const bytes32 = encodeBytes32String(str); + const decoded = decodeBytes32String(bytes32); + assert.equal(bytes32, expected, 'formatted correctly'); + assert.equal(decoded, str, "parsed correctly"); + }); + } +}); +describe("Test Interface", function () { + const iface = new Interface([ + "function balanceOf(address owner) returns (uint)", + "event Transfer(address indexed from, address indexed to, uint amount)", + // #4244 + "event RedemptionRequested(bytes20 indexed walletPubKeyHash, bytes redeemerOutputScript, address indexed redeemer, uint64 requestedAmount, uint64 treasuryFee, uint64 txMaxFee)" + ]); + it("does interface stuff; @TODO expand this", function () { + const addr = "0x8ba1f109551bD432803012645Ac136ddd64DBA72"; + const addr2 = "0xAC1639CF97a3A46D431e6d1216f576622894cBB5"; + const data = iface.encodeFunctionData("balanceOf", [addr]); + assert.equal(data, "0x70a082310000000000000000000000008ba1f109551bd432803012645ac136ddd64dba72", "encoded"); + const decoded = iface.decodeFunctionData("balanceOf", data); + assert.equal(decoded.length, 1, "decoded.length"); + assert.equal(decoded[0], addr, "decoded[0]"); + const tx = iface.parseTransaction({ data, value: 10 }); + assert.ok(tx != null, "tx == null"); + assert.equal(tx.name, "balanceOf", "tx.balanceOf"); + assert.equal(tx.signature, "balanceOf(address)", "tx.balanceOf"); + assert.equal(tx.args.length, 1, "tx.args.length"); + assert.equal(tx.args[0], addr, "tx.args[0]"); + assert.equal(tx.selector, "0x70a08231", "tx.selector"); + assert.equal(tx.value, BigInt(10), "tx.value"); + const result = iface.encodeFunctionResult("balanceOf", [123]); + assert.equal(result, "0x000000000000000000000000000000000000000000000000000000000000007b", "result"); + const value = iface.decodeFunctionResult("balanceOf", result); + assert.equal(value.length, 1, "result.length"); + assert.equal(value[0], BigInt(123), "result.value[0]"); + // @TODO: parseResult + const filter = iface.encodeFilterTopics("Transfer", [addr, addr2]); + assert.equal(filter.length, 3); + assert.equal(filter[0], "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"); + assert.equal(filter[1], "0x0000000000000000000000008ba1f109551bd432803012645ac136ddd64dba72"); + assert.equal(filter[2], "0x000000000000000000000000ac1639cf97a3a46d431e6d1216f576622894cbb5"); + // See: #4244 + // https://goerli.quaiscan.io/tx/0xe61cef4cd706db8e23114717a207d76cc6b0df0b74ec52805551c4d1bf347a27#eventlog + // See `RedemptionRequested` event. + { + const walletPubKeyHash = "0x03b74d6893ad46dfdd01b9e0e3b3385f4fce2d1e"; + const redeemer = "0x086813525A7dC7dafFf015Cdf03896Fd276eab60"; + const filterWithBytes20 = iface.encodeFilterTopics("RedemptionRequested", [walletPubKeyHash, undefined, redeemer]); + assert.equal(filterWithBytes20.length, 3); + assert.equal(filterWithBytes20[0], "0x97a0199072f487232635d50ab75860891afe0b91c976ed2fc76502c4d82d0d95"); + assert.equal(filterWithBytes20[1], "0x03b74d6893ad46dfdd01b9e0e3b3385f4fce2d1e000000000000000000000000"); + assert.equal(filterWithBytes20[2], "0x000000000000000000000000086813525a7dc7dafff015cdf03896fd276eab60"); + } + const eventLog = iface.encodeEventLog("Transfer", [addr, addr2, 234]); + assert.equal(eventLog.data, "0x00000000000000000000000000000000000000000000000000000000000000ea"); + assert.deepEqual(eventLog.topics, [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x0000000000000000000000008ba1f109551bd432803012645ac136ddd64dba72", + "0x000000000000000000000000ac1639cf97a3a46d431e6d1216f576622894cbb5" + ]); + const values = iface.decodeEventLog("Transfer", eventLog.data, eventLog.topics); + assert.equal(values.length, 3); + assert.equal(values[0], addr); + assert.equal(values[1], addr2); + assert.equal(values[2], BigInt(234)); + const log = iface.parseLog(eventLog); + assert.ok(log != null); + assert.equal(log.name, "Transfer"); + assert.equal(log.signature, "Transfer(address,address,uint256)"); + assert.equal(log.topic, "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"); + assert.equal(log.args.length, 3); + assert.equal(log.args[0], "0x8ba1f109551bD432803012645Ac136ddd64DBA72"); + assert.equal(log.args[1], "0xAC1639CF97a3A46D431e6d1216f576622894cBB5"); + assert.equal(log.args[2], BigInt(234)); + }); + // See #4248 + it("formats JSON ABI parameters with default empty string for `name` key", function () { + assert.deepEqual(JSON.parse(iface.getFunction("balanceOf").format('json')), { + constant: false, + inputs: [ + { name: "owner", type: "address" } + ], + name: "balanceOf", + outputs: [ + { name: "", type: "uint256" } + ], + payable: false, + type: "function", + }); + }); +}); +describe("Tests Legacy ABI formats", function () { + // See: #3932 + const iface = new Interface([ + { + name: "implicitView", + outputs: [], + inputs: [ + { type: "int128", name: "arg0" } + ], + "constant": true, + "payable": false, + "type": "function" + }, + { + name: "implicitSendNonpay", + outputs: [], + inputs: [ + { type: "int128", name: "arg0" } + ], + "constant": false, + "payable": false, + "type": "function" + }, + { + name: "implicitSendPay", + outputs: [], + inputs: [ + { type: "int128", name: "arg0" } + ], + "constant": false, + "payable": true, + "type": "function" + }, + { + name: "implicitSendImplicitPay", + outputs: [], + inputs: [ + { type: "int128", name: "arg0" } + ], + "constant": false, + "type": "function" + }, + { + name: "implicitSendExplicitPay", + outputs: [], + inputs: [ + { type: "int128", name: "arg0" } + ], + payable: true, + type: "function" + }, + { + name: "implicitSendExplicitNonpay", + outputs: [], + inputs: [ + { type: "int128", name: "arg0" } + ], + payable: false, + type: "function" + }, + { + name: "implicitAll", + outputs: [], + inputs: [ + { type: "int128", name: "arg0" } + ], + "type": "function" + }, + { + name: "explicitView", + outputs: [], + inputs: [ + { type: "int128", name: "arg0" } + ], + "stateMutability": "view", + "constant": true, + "payable": false, + "type": "function" + }, + { + name: "explicitPure", + outputs: [], + inputs: [ + { type: "int128", name: "arg0" } + ], + "stateMutability": "pure", + "constant": true, + "payable": false, + "type": "function" + }, + { + name: "explicitPay", + outputs: [], + inputs: [ + { type: "int128", name: "arg0" } + ], + "stateMutability": "payable", + "constant": true, + "payable": true, + "type": "function" + }, + { + name: "explicitNonpay", + outputs: [], + inputs: [ + { type: "int128", name: "arg0" } + ], + "stateMutability": "nonpayable", + "constant": true, + "payable": false, + "type": "function" + }, + ]); + function test(name, isConst, payable, stateMutability) { + it(`tests ABI configuration: ${name}`, function () { + const f = iface.getFunction(name); + assert.ok(!!f, `missing ${name}`); + assert.equal(f.constant, isConst, `${name}.constant`); + assert.equal(f.stateMutability, stateMutability, `${name}.stateMutability`); + assert.equal(f.payable, payable, `${name}.payable`); + }); + } + test("explicitView", true, false, "view"); + test("explicitPure", true, false, "pure"); + test("explicitPay", false, true, "payable"); + test("explicitNonpay", false, false, "nonpayable"); + test("implicitView", true, false, "view"); + test("implicitSendNonpay", false, false, "nonpayable"); + test("implicitSendPay", false, true, "payable"); + test("implicitSendImplicitPay", false, true, "payable"); + test("implicitSendExplicitPay", false, true, "payable"); + test("implicitSendExplicitNonpay", false, false, "nonpayable"); + test("implicitAll", false, true, "payable"); +}); +//# sourceMappingURL=test-abi.js.map \ No newline at end of file diff --git a/lib.esm/_tests/test-abi.js.map b/lib.esm/_tests/test-abi.js.map new file mode 100644 index 00000000..27dcf26c --- /dev/null +++ b/lib.esm/_tests/test-abi.js.map @@ -0,0 +1 @@ +{"version":3,"file":"test-abi.js","sourceRoot":"","sources":["../../src.ts/_tests/test-abi.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAIvC,OAAO,EACH,QAAQ,EAAE,SAAS,EACnB,mBAAmB,EAAE,mBAAmB,EAC3C,MAAM,aAAa,CAAC;AAErB,SAAS,KAAK,CAAC,MAAW,EAAE,QAA4B;IACpD,QAAQ,QAAQ,CAAC,I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aAAa,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC;AAChD,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/lib.esm/_tests/test-address.d.ts b/lib.esm/_tests/test-address.d.ts new file mode 100644 index 00000000..afa579d8 --- /dev/null +++ b/lib.esm/_tests/test-address.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=test-address.d.ts.map \ No newline at end of file diff --git a/lib.esm/_tests/test-address.d.ts.map b/lib.esm/_tests/test-address.d.ts.map new file mode 100644 index 00000000..a5475c06 --- /dev/null +++ b/lib.esm/_tests/test-address.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"test-address.d.ts","sourceRoot":"","sources":["../../src.ts/_tests/test-address.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/lib.esm/_tests/test-address.js b/lib.esm/_tests/test-address.js new file mode 100644 index 00000000..ed3e4202 --- /dev/null +++ b/lib.esm/_tests/test-address.js @@ -0,0 +1,109 @@ +import assert from "assert"; +import { loadTests } from "./utils.js"; +import { getAddress, getCreateAddress, getCreate2Address } from "../index.js"; +describe("computes checksum address", function () { + const tests = loadTests("accounts"); + for (const test of tests) { + it(`computes the checksum address: ${test.name}`, function () { + assert.equal(getAddress(test.address), test.address); + assert.equal(getAddress(test.icap), test.address); + assert.equal(getAddress(test.address.substring(2)), test.address); + assert.equal(getAddress(test.address.toLowerCase()), test.address); + assert.equal(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(`correctly fails on invalid address: ${name}`, function () { + assert.throws(function () { + getAddress(value); + }, function (error) { + return (error.code === "INVALID_ARGUMENT" && + error.message.match(/^invalid address/) && + error.argument === "address" && + error.value === value); + }); + }); + }); + it("correctly fails on invalid checksum", function () { + const value = "0x8ba1f109551bD432803012645Ac136ddd64DBa72"; + assert.throws(function () { + getAddress(value); + }, function (error) { + return (error.code === "INVALID_ARGUMENT" && + error.message.match(/^bad address checksum/) && + error.argument === "address" && + error.value === value); + }); + }); + it("correctly fails on invalid IBAN checksum", function () { + const value = "XE65GB6LDNXYOFTX0NSV3FUWKOWIXAMJK37"; + assert.throws(function () { + 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 = loadTests("accounts"); + for (const test of tests) { + it(`computes the ICAP address: ${test.name}`, function () { + assert.equal(getAddress(test.address.toLowerCase()), test.address); + assert.equal(getAddress("0x" + test.address.substring(2).toUpperCase()), test.address); + }); + } +}); +describe("computes create address", function () { + const tests = loadTests("create"); + for (const { sender, creates } of tests) { + for (const { name, nonce, address } of creates) { + it(`computes the create address: ${name}`, function () { + assert.equal(getCreateAddress({ from: sender, nonce }), address); + }); + } + } +}); +describe("computes create2 address", function () { + const tests = loadTests("create2"); + for (const { sender, creates } of tests) { + for (const { name, salt, initCodeHash, address } of creates) { + it(`computes the create2 address: ${name}`, function () { + assert.equal(getCreate2Address(sender, salt, initCodeHash), address); + }); + } + } + const sender = "0x8ba1f109551bD432803012645Ac136ddd64DBA72"; + const salt = "0x1c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac8"; + const initCodeHash = "0x8452c9b9140222b08593a26daa782707297be9f7b3e8281d7b4974769f19afd0"; + it("correctly fails on invalid salt", function () { + const badSalt = "0x1c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36dea"; + assert.throws(function () { + getCreate2Address(sender, badSalt, initCodeHash); + }, function (error) { + return (error.code === "INVALID_ARGUMENT" && + error.argument === "salt" && + error.value === badSalt); + }); + }); + it("correctly fails on invalid initCodeHash", function () { + const badInitCodeHash = "0x8452c9b9140222b08593a26daa782707297be9f7b3e8281d7b4974769f19af"; + assert.throws(function () { + getCreate2Address(sender, salt, badInitCodeHash); + }, function (error) { + return (error.code === "INVALID_ARGUMENT" && + error.argument === "initCodeHash" && + error.value === badInitCodeHash); + }); + }); +}); +//# sourceMappingURL=test-address.js.map \ No newline at end of file diff --git a/lib.esm/_tests/test-address.js.map b/lib.esm/_tests/test-address.js.map new file mode 100644 index 00000000..97eac0f5 --- /dev/null +++ b/lib.esm/_tests/test-address.js.map @@ -0,0 +1 @@ +{"version":3,"file":"test-address.js","sourceRoot":"","sources":["../../src.ts/_tests/test-address.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAQvC,OAAO,EACH,UAAU,EACV,gBAAgB,EAAE,iBAAiB,EACtC,MAAM,aAAa,CAAC;AAGrB,QAAQ,CAAC,2BAA2B,EAAE;IAClC,MAAM,KAAK,GAAG,SAAS,CAAkB,UAAU,CAAC,CAAC;IACrD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;QACtB,EAAE,CAAC,kCAAmC,IAAI,CAAC,IAAK,EAAE,EAAE;YAChD,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;YACrD,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;YAClD,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;YAClE,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;YACnE,MAAM,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CAAC,KAAK,KAAK,OAAO,CAAC,CAAC;QACjC,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yCAAyC,EAAE;QAC1C,MAAM,eAAe,GAAG,kEAAkE,CAAC;QAC3F,MAAM,CAAC,MAAM,CAAC;YACV,iBAAiB,CAAC,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"} \ No newline at end of file diff --git a/lib.esm/_tests/test-contract-integ.d.ts b/lib.esm/_tests/test-contract-integ.d.ts new file mode 100644 index 00000000..404e7e48 --- /dev/null +++ b/lib.esm/_tests/test-contract-integ.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=test-contract-integ.d.ts.map \ No newline at end of file diff --git a/lib.esm/_tests/test-contract-integ.d.ts.map b/lib.esm/_tests/test-contract-integ.d.ts.map new file mode 100644 index 00000000..66f4bade --- /dev/null +++ b/lib.esm/_tests/test-contract-integ.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"test-contract-integ.d.ts","sourceRoot":"","sources":["../../src.ts/_tests/test-contract-integ.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/lib.esm/_tests/test-contract-integ.js b/lib.esm/_tests/test-contract-integ.js new file mode 100644 index 00000000..fe347d0b --- /dev/null +++ b/lib.esm/_tests/test-contract-integ.js @@ -0,0 +1,86 @@ +import assert from "assert"; +import { quais } from "../index.js"; +import dotenv from "dotenv"; +import QRC20 from "./contracts/QRC20.js"; +import { stall } from "./utils.js"; +dotenv.config(); +describe("Tests contract integration", function () { + const provider = new quais.JsonRpcProvider(process.env.RPC_URL); + const wallet = new quais.Wallet(process.env.FAUCET_PRIVATEKEY || '', provider); + const abi = QRC20.abi; + const bytecode = QRC20.bytecode; + const constructorArgs = { + name: 'Testing', + symbol: 'Test', + totalSupply: Math.pow(10, 3), + }; + let contract; + let address; + before(async function () { + this.timeout(100000); + const factory = new quais.ContractFactory(abi, bytecode, wallet); + contract = await factory.deploy(constructorArgs.name, constructorArgs.symbol, constructorArgs.totalSupply, { + gasLimit: 5000000 + }); + address = await contract.getAddress(); + console.log('Contract deployed to:', address); + let tries = 0; + const POLLING_TRIES = 10; // define POLLING_TRIES if not defined elsewhere + let deployed = false; + let code = await provider.getCode(address); + while (tries < POLLING_TRIES && !deployed) { + code = await provider.getCode(address); + if (code != "0x") { + deployed = true; + } + tries += 1; + await stall(10000); // Ensure stall is defined or use a different delay mechanism + } + if (!deployed) { + throw new Error("Contract deployment failed"); + } + }); + it("confirms the contract deployment", function () { + assert.ok(address, "Contract address should be available"); + assert.ok(contract, "Contract instance should be available"); + }); + it("runs contract operations", async function () { + this.timeout(120000); + assert.ok(address != null); + const CustomContract = quais.BaseContract.buildClass(abi); + const contract = new CustomContract(address, wallet); //quais.Contract.from(address, abi, signer); + await stall(30000); + // Test implicit staticCall (i.e. view/pure) + { + const supply0 = await contract.totalSupply(); + assert.equal(supply0, BigInt(1000), "initial supply 0; default"); + } + // Test explicit staticCall + { + const supply0 = await contract.totalSupply.staticCall(); + assert.equal(supply0, BigInt(1000), "initial supply 0; staticCall"); + } + // Test staticCallResult (positional and named) + { + const supply0 = await contract.totalSupply.staticCallResult(); + assert.equal(supply0[0], BigInt(1000), "initial supply 0; staticCallResult"); + } + const reciever = '0x0047f9CEa7662C567188D58640ffC48901cde02a'; + // Test transfer (default) + const tx = await contract.transfer(reciever, BigInt(1)); + await stall(60000); + const receipt = await provider.getTransactionReceipt(tx.hash); + console.log('Receipt: ', receipt); + await stall(10000); + assert.ok(receipt, "receipt not null"); + const contractAddr = await contract.getAddress(); + // Check the receipt has parsed the events + assert.equal(receipt.logs.length, 1, "logs.length"); + assert.ok(receipt instanceof quais.TransactionReceipt, "receipt typeof"); + assert.ok(receipt.logs[0] instanceof quais.Log, "receipt.log typeof"); + assert.equal(receipt.logs[0].address, contractAddr, "Proper target address"); + // Check the state has been adjusted + assert.equal(await contract.balanceOf(reciever), BigInt(1), "balanceOf(signer)"); + }); +}); +//# sourceMappingURL=test-contract-integ.js.map \ No newline at end of file diff --git a/lib.esm/_tests/test-contract-integ.js.map b/lib.esm/_tests/test-contract-integ.js.map new file mode 100644 index 00000000..dfeb7d00 --- /dev/null +++ b/lib.esm/_tests/test-contract-integ.js.map @@ -0,0 +1 @@ +{"version":3,"file":"test-contract-integ.js","sourceRoot":"","sources":["../../src.ts/_tests/test-contract-integ.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,KAAK,EAAY,MAAM,aAAa,CAAC;AAC9C,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,KAAK,MAAM,sBAAsB,CAAA;AACxC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,MAAM,CAAC,MAAM,EAAE,CAAC;AAShB,QAAQ,CAAC,4BAA4B,EAAE;IACnC,MAAM,QAAQ,GAAG,IAAI,KAAK,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAChE,MAAM,MAAM,GAAG,IAAI,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,IAAI,EAAE,EAAE,QAAQ,CAAC,CAAC;IAC/E,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC;IACtB,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;IAChC,MAAM,eAAe,GAAG;QACpB,IAAI,EAAE,SAAS;QACf,MAAM,EAAE,MAAM;QACd,WAAW,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;KAC/B,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AAQ,CAAC,qBAAqB,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;QAC9D,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,OAAO,CAAC,CAAA;QAClC,MAAM,KAAK,CAAC,KAAK,CAAC,CAAA;QAClB,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,kBAAkB,CAAC,CAAC;QAEvC,MAAM,YAAY,GAAG,MAAM,QAAQ,CAAC,UAAU,EAAE,CAAA;QAChD,0CAA0C;QAE1C,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,aAAa,CAAC,CAAC;QACpD,MAAM,CAAC,EAAE,CAAC,OAAO,YAAY,KAAK,CAAC,kBAAkB,EAAE,gBAAgB,CAAC,CAAC;QACzE,MAAM,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,KAAK,CAAC,GAAG,EAAE,oBAAoB,CAAC,CAAC;QACtE,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,YAAY,EAAE,uBAAuB,CAAC,CAAC;QAE7E,oCAAoC;QACpC,MAAM,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,mBAAmB,CAAC,CAAC;IACrF,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/lib.esm/_tests/test-contract.d.ts b/lib.esm/_tests/test-contract.d.ts new file mode 100644 index 00000000..1427a869 --- /dev/null +++ b/lib.esm/_tests/test-contract.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=test-contract.d.ts.map \ No newline at end of file diff --git a/lib.esm/_tests/test-contract.d.ts.map b/lib.esm/_tests/test-contract.d.ts.map new file mode 100644 index 00000000..fb6a18b4 --- /dev/null +++ b/lib.esm/_tests/test-contract.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"test-contract.d.ts","sourceRoot":"","sources":["../../src.ts/_tests/test-contract.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/lib.esm/_tests/test-contract.js b/lib.esm/_tests/test-contract.js new file mode 100644 index 00000000..a3687e87 --- /dev/null +++ b/lib.esm/_tests/test-contract.js @@ -0,0 +1,352 @@ +import assert from "assert"; +import { getProvider, setupProviders } from "./create-provider.js"; +import { Contract, ContractFactory, isError, Typed, } from "../index.js"; +import TestContract from "./contracts/TestContract.js"; +import TypedContract from "./contracts/TypedContract.js"; +import { quais } from "../index.js"; +import { stall } from "./utils.js"; +setupProviders(); +describe("Test Contract", function () { + const provider = new quais.JsonRpcProvider(process.env.RPC_URL); + const wallet = new quais.Wallet(process.env.FAUCET_PRIVATEKEY || '', provider); + const abi = TestContract.abi; + const bytecode = TestContract.bytecode; + let contract; + let addr; + before(async function () { + this.timeout(60000); + await stall(10000); + const factory = new ContractFactory(abi, bytecode, wallet); + contract = await factory.deploy({ gasLimit: 5000000, maxFeePerGas: quais.parseUnits('10', 'gwei'), maxPriorityFeePerGas: quais.parseUnits('3', 'gwei') }); + addr = await contract.getAddress(); + console.log("Contract deployed to: ", addr); + await stall(30000); + }); + it("tests contract calls", async function () { + this.timeout(10000); + assert.equal(await contract.testCallAdd(4, 5), BigInt(9), "testCallAdd(4, 5)"); + assert.equal(await contract.testCallAdd(6, 0), BigInt(6), "testCallAdd(6, 0)"); + }); + //Awaiting Quai subscrigbe functionality + // it("tests events", async function() { + // this.timeout(60000); + // assert.ok(provider) + // const vUint256 = 42; + // const vAddrName = "quais.eth"; + // const vAddr = "0x228568EA92aC5Bc281c1E30b1893735c60a139F1"; + // const vString = "Hello"; + // const vBytes = "0x12345678"; + // let hash: null | string = null; + // // Test running a listener for a specific event + // const specificEvent = new Promise((resolve, reject) => { + // contract.on("EventUint256", async (value, event) => { + // // Triggered by someone else + // if (hash == null || hash !== event.log.transactionHash) { return; } + // try { + // assert.equal(event.filter, "EventUint256", "event.filter"); + // assert.equal(event.fragment.name, "EventUint256", "event.fragment.name"); + // assert.equal(event.log.address, addr, "event.log.address"); + // assert.equal(event.args.length, 1, "event.args.length"); + // assert.equal(event.args[0], BigInt(42), "event.args[0]"); + // const count = await contract.listenerCount("EventUint256"); + // await event.removeListener(); + // assert.equal(await contract.listenerCount("EventUint256"), count - 1, "decrement event count"); + // resolve(null); + // } catch (e) { + // event.removeListener(); + // reject(e); + // } + // }); + // }); + // // Test running a listener on all (i.e. "*") events + // const allEvents = new Promise((resolve, reject) => { + // const waitingFor: Record = { + // EventUint256: vUint256, + // EventAddress: vAddr, + // EventString: vString, + // EventBytes: vBytes + // }; + // contract.on("*", (event: ContractEventPayload) => { + // // Triggered by someone else + // if (hash == null || hash !== event.log.transactionHash) { return; } + // try { + // const name = event.eventName; + // assert.equal(event.args[0], waitingFor[name], `${ name }`); + // delete waitingFor[name]; + // if (Object.keys(waitingFor).length === 0) { + // event.removeListener(); + // resolve(null); + // } + // } catch (error) { + // reject(error); + // } + // }); + // }); + // // Send a transaction to trigger some events + // const tx = await contractSigner.testEvent(vUint256, vAddr, vString, vBytes); + // hash = tx.hash; + // const checkEvent = (filter: ContractEventName, event: EventLog | Log) => { + // const values: Record = { + // EventUint256: vUint256, + // EventString: vString, + // EventAddress: vAddr, + // EventBytes: vBytes + // }; + // assert.ok(event instanceof EventLog, `queryFilter(${ filter }):isEventLog`); + // const name = event.eventName; + // assert.equal(event.address, addr, `queryFilter(${ filter }):address`); + // assert.equal(event.args[0], values[name], `queryFilter(${ filter }):args[0]`); + // }; + // const checkEventFilter = async (filter: ContractEventName) => { + // const events = (await contract.queryFilter(filter, -10)).filter((e) => (e.transactionHash === hash)); + // assert.equal(events.length, 1, `queryFilter(${ filter }).length`); + // checkEvent(filter, events[0]); + // return events[0]; + // }; + // const receipt = await tx.wait(); + // // Check the logs in the receipt + // for (const log of receipt.logs) { checkEvent("receipt", log); } + // // Various options for queryFilter + // await checkEventFilter("EventUint256"); + // await checkEventFilter([ "EventUint256" ]); + // await checkEventFilter([ [ "EventUint256" ] ]); + // await checkEventFilter("EventUint256(uint)"); + // await checkEventFilter([ "EventUint256(uint)" ]); + // await checkEventFilter([ [ "EventUint256(uint)" ] ]); + // await checkEventFilter([ [ "EventUint256", "EventUint256(uint)" ] ]); + // await checkEventFilter("0x85c55bbb820e6d71c71f4894e57751de334b38c421f9c170b0e66d32eafea337"); + // // Query by Event + // await checkEventFilter(contract.filters.EventUint256); + // // Query by Deferred Topic Filter; address + // await checkEventFilter(contract.filters.EventUint256(vUint256)); + // // Query by Deferred Topic Filter; address + // await checkEventFilter(contract.filters.EventAddress(vAddr)); + // // Query by Deferred Topic Filter; ENS name => address + // await checkEventFilter(contract.filters.EventAddress(vAddrName)); + // // Multiple Methods + // { + // const filter = [ [ "EventUint256", "EventString" ] ]; + // const events = (await contract.queryFilter(filter, -10)).filter((e) => (e.transactionHash === hash)); + // assert.equal(events.length, 2, `queryFilter(${ filter }).length`); + // for (const event of events) { checkEvent(filter, event); } + // } + // await specificEvent; + // await allEvents; + // }); + it("tests the _in_ operator for functions", function () { + const contract = new Contract(addr, abi); + assert.equal("testCallAdd" in contract, true, "has(testCallAdd)"); + assert.equal("nonExist" in contract, false, "has(nonExist)"); + { + const sig = "function testCallAdd(uint256 a, uint256 b) pure returns (uint256 result)"; + assert.equal(sig in contract, true, `has(${sig})`); + assert.equal("function nonExist()" in contract, false, "has(function nonExist())"); + } + assert.equal("0xf24684e5" in contract, true, "has(0xf24684e5)"); + assert.equal("0xbad01234" in contract, false, "has(0xbad01234)"); + }); + it("tests the _in_ operator for events", function () { + const contract = new Contract(addr, abi); + assert.equal("EventUint256" in contract.filters, true, "has(EventUint256)"); + assert.equal("NonExist" in contract.filters, false, "has(NonExist)"); + { + const sig = "event EventUint256(uint256 indexed value)"; + assert.equal(sig in contract.filters, true, `has(${sig})`); + assert.equal("event NonExist()" in contract.filters, false, "has(event NonExist())"); + } + { + const hash = "0x85c55bbb820e6d71c71f4894e57751de334b38c421f9c170b0e66d32eafea337"; + const badHash = "0xbad01234567890ffbad01234567890ffbad01234567890ffbad01234567890ff"; + assert.equal(hash in contract.filters, true, `has(${hash})`); + assert.equal(badHash in contract.filters, false, `has(${badHash})`); + } + }); +}); +describe("Test Typed Contract Interaction", function () { + const tests = [ + { + types: ["uint8", "uint16", "uint24", "uint32", "uint40", "uint48", "uint56", "uint64", "uint72", "uint80", "uint88", "uint96", "uint104", "uint112", "uint120", "uint128", "uint136", "uint144", "uint152", "uint160", "uint168", "uint176", "uint184", "uint192", "uint200", "uint208", "uint216", "uint224", "uint232", "uint240", "uint248", "uint256", "int8", "int16", "int24", "int32", "int40", "int48", "int56", "int64", "int72", "int80", "int88", "int96", "int104", "int112", "int120", "int128", "int136", "int144", "int152", "int160", "int168", "int176", "int184", "int192", "int200", "int208", "int216", "int224", "int232", "int240", "int248", "int256"], + valueFunc: (type) => { return 42; } + }, + { + types: [ + "bytes1", "bytes2", "bytes3", "bytes4", "bytes5", "bytes6", "bytes7", "bytes8", "bytes9", "bytes10", "bytes11", "bytes12", "bytes13", "bytes14", "bytes15", "bytes16", "bytes17", "bytes18", "bytes19", "bytes20", "bytes21", "bytes22", "bytes23", "bytes24", "bytes25", "bytes26", "bytes27", "bytes28", "bytes29", "bytes30", "bytes31", "bytes32", + "bytes" + ], + valueFunc: (type) => { + const length = type.substring(5); + if (length) { + const value = new Uint8Array(parseInt(length)); + value.fill(42); + return value; + } + return "0x123456"; + } + }, { + types: ["bool"], + valueFunc: (type) => { return true; } + }, { + types: ["address"], + valueFunc: (type) => { return "0x643aA0A61eADCC9Cc202D1915D942d35D005400C"; } + }, { + types: ["string"], + valueFunc: (type) => { return "someString"; } + } + ]; + const abi = TypedContract.abi; + const provider = new quais.JsonRpcProvider(process.env.RPC_URL); + const wallet = new quais.Wallet(process.env.FAUCET_PRIVATEKEY || '', provider); + const bytecode = TypedContract.bytecode; + let contract; + let addr; + before(async function () { + this.timeout(120000); + const factory = new ContractFactory(abi, bytecode, wallet); + contract = await factory.deploy({ gasLimit: 5000000, maxFeePerGas: quais.parseUnits('10', 'gwei'), maxPriorityFeePerGas: quais.parseUnits('3', 'gwei'), }); + addr = await contract.getAddress(); + console.log("Contract deployed to: ", addr); + await stall(50000); + }); + for (const { types, valueFunc } of tests) { + for (const type of types) { + const value = valueFunc(type); + it(`tests typed value: Typed.from(${type})`, async function () { + this.timeout(10000); + const v = Typed.from(type, value); + const result = await contract.testTyped(v); + assert.equal(result, type); + }); + it(`tests typed value: Typed.${type}()`, async function () { + this.timeout(10000); + const v = Typed[type](value); + const result = await contract.testTyped(v); + assert.equal(result, type); + }); + } + } +}); +describe("Test Contract Fallback", function () { + const tests = [ + { + name: "none", + address: "0x0ccdace3d8353fed9b87a2d63c40452923ccdae5", + abi: [], + sendNone: { error: "no fallback" }, + sendData: { error: "no fallback" }, + sendValue: { error: "no fallback" }, + sendDataAndValue: { error: "no fallback" }, + }, + { + name: "non-payable fallback", + address: "0x3f10193f79a639b11ec9d2ab42a25a4a905a8870", + abi: [ + "fallback()" + ], + sendNone: { data: "0x" }, + sendData: { data: "0x1234" }, + sendValue: { error: "overrides.value" }, + sendDataAndValue: { error: "overrides.value" }, + }, + { + name: "payable fallback", + address: "0xe2de6b97c5eb9fee8a47ca6c0fa642331e0b6330", + abi: [ + "fallback() payable" + ], + sendNone: { data: "0x" }, + sendData: { data: "0x1234" }, + sendValue: { data: "0x" }, + sendDataAndValue: { data: "0x1234" }, + }, + { + name: "receive-only", + address: "0xf8f2afbbe37f6a4520e4db7f99495655aa31229b", + abi: [ + "receive()" + ], + sendNone: { data: "0x" }, + sendData: { error: "overrides.data" }, + sendValue: { data: "0x" }, + sendDataAndValue: { error: "overrides.data" }, + }, + { + name: "receive and payable fallback", + address: "0x7d97ca5d9dea1cd0364f1d493252006a3c4e18a0", + abi: [ + "fallback() payable", + "receive()" + ], + sendNone: { data: "0x" }, + sendData: { data: "0x1234" }, + sendValue: { data: "0x" }, + sendDataAndValue: { data: "0x1234" }, + }, + { + name: "receive and non-payable fallback", + address: "0x5b59d934f0d22b15e73b5d6b9ae83486b70df67e", + abi: [ + "fallback()", + "receive()" + ], + sendNone: { data: "0x" }, + sendData: { data: "0x" }, + sendValue: { data: "0x" }, + sendDataAndValue: { error: "overrides" }, + }, + ]; + const provider = getProvider("InfuraProvider", "goerli"); + const testGroups = [ + { + group: "sendNone", + tx: {} + }, + { + group: "sendData", + tx: { data: "0x1234" } + }, + { + group: "sendValue", + tx: { value: 123 } + }, + { + group: "sendDataAndValue", + tx: { data: "0x1234", value: 123 } + }, + ]; + for (const { group, tx } of testGroups) { + for (const test of tests) { + const { name, address, abi } = test; + const send = test[group]; + const contract = new Contract(address, abi, provider); + it(`test contract fallback checks: ${group} - ${name}`, async function () { + const func = async function () { + if (abi.length === 0) { + throw new Error("no fallback"); + } + assert.ok(contract.fallback); + return await contract.fallback.populateTransaction(tx); + }; + if ("data" in send) { + await func(); + //const result = await func(); + //@TODO: Test for the correct populated tx + //console.log(result); + assert.ok(true); + } + else { + await assert.rejects(func, function (error) { + if (error.message === send.error) { + return true; + } + if (isError(error, "INVALID_ARGUMENT")) { + return error.argument === send.error; + } + console.log("EE", error); + return true; + }); + } + }); + } + } +}); +//# sourceMappingURL=test-contract.js.map \ No newline at end of file diff --git a/lib.esm/_tests/test-contract.js.map b/lib.esm/_tests/test-contract.js.map new file mode 100644 index 00000000..a1940dce --- /dev/null +++ b/lib.esm/_tests/test-contract.js.map @@ -0,0 +1 @@ +{"version":3,"file":"test-contract.js","sourceRoot":"","sources":["../../src.ts/_tests/test-contract.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEnE,OAAO,EACH,QAAQ,EAAE,eAAe,EAAE,OAAO,EAAE,KAAK,GAC5C,MAAM,aAAa,CAAC;AACrB,OAAO,YAAY,MAAM,6BAA6B,CAAA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AAC;iBACN;YACL,CAAC,CAAC,CAAC;SACN;KACJ;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/lib.esm/_tests/test-crypto-algoswap.d.ts b/lib.esm/_tests/test-crypto-algoswap.d.ts new file mode 100644 index 00000000..8c2f71dc --- /dev/null +++ b/lib.esm/_tests/test-crypto-algoswap.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=test-crypto-algoswap.d.ts.map \ No newline at end of file diff --git a/lib.esm/_tests/test-crypto-algoswap.d.ts.map b/lib.esm/_tests/test-crypto-algoswap.d.ts.map new file mode 100644 index 00000000..6b75dde0 --- /dev/null +++ b/lib.esm/_tests/test-crypto-algoswap.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"test-crypto-algoswap.d.ts","sourceRoot":"","sources":["../../src.ts/_tests/test-crypto-algoswap.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/lib.esm/_tests/test-crypto-algoswap.js b/lib.esm/_tests/test-crypto-algoswap.js new file mode 100644 index 00000000..3fa1bb09 --- /dev/null +++ b/lib.esm/_tests/test-crypto-algoswap.js @@ -0,0 +1,96 @@ +import assert from "assert"; +import { lock, computeHmac, keccak256, ripemd160, sha256, sha512, pbkdf2, scrypt, scryptSync, randomBytes } from "../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: keccak256 + }, + { + name: "sha256", + params: ["0x"], + hijackTag: 'hijacked sha256: [{}]', + algorithm: sha256 + }, + { + name: "sha512", + params: ["0x"], + hijackTag: 'hijacked sha512: [{}]', + algorithm: sha512 + }, + { + name: "ripemd160", + params: ["0x"], + hijackTag: 'hijacked ripemd160: [{}]', + algorithm: ripemd160 + }, + { + name: "pbkdf2", + params: ["0x", "0x", 1024, 32, "sha256"], + hijackTag: 'hijacked pbkdf2: [{},{},1024,32,"sha256"]', + algorithm: pbkdf2 + }, + { + name: "scryptSync", + params: ["0x", "0x", 1024, 8, 1, 32], + hijackTag: 'hijacked scryptSync: [{},{},1024,8,1,32]', + algorithm: scryptSync + }, + { + name: "scrypt", + params: ["0x", "0x", 1024, 8, 1, 32], + hijackTag: 'hijacked scrypt: [{},{},1024,8,1,32,null]', + algorithm: scrypt + }, + { + name: "computeHmac", + params: ["sha256", "0x", "0x"], + hijackTag: 'hijacked computeHmac: ["sha256",{},{}]', + algorithm: computeHmac + }, + { + name: "randomBytes", + params: [32], + hijackTag: "hijacked randomBytes: [32]", + algorithm: randomBytes, + postCheck: (value) => { + return (value instanceof Uint8Array && value.length === 32); + } + } + ]; + tests.forEach(({ name, params, hijackTag, algorithm, postCheck }) => { + it(`swaps in hijacked callback: ${name}`, async function () { + const initial = await algorithm(...params); + algorithm.register(getHijack(name)); + assert.equal(await algorithm(...params), "0x42"); + assert.equal(hijack, hijackTag); + algorithm.register(algorithm._); + if (postCheck) { + assert.ok(postCheck(await algorithm(...params))); + } + else { + assert.equal(await algorithm(...params), initial); + } + }); + }); + it("prevents swapping after locked", function () { + lock(); + tests.forEach(({ name, params, hijackTag, algorithm }) => { + assert.throws(function () { + algorithm.register(getHijack("test")); + }, function (error) { + return (error.message === `${name} is locked`); + }); + }); + }); +}); +//# sourceMappingURL=test-crypto-algoswap.js.map \ No newline at end of file diff --git a/lib.esm/_tests/test-crypto-algoswap.js.map b/lib.esm/_tests/test-crypto-algoswap.js.map new file mode 100644 index 00000000..1e0fea5a --- /dev/null +++ b/lib.esm/_tests/test-crypto-algoswap.js.map @@ -0,0 +1 @@ +{"version":3,"file":"test-crypto-algoswap.js","sourceRoot":"","sources":["../../src.ts/_tests/test-crypto-algoswap.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EACH,IAAI,EACJ,WAAW,EACX,SAAS,EAAE,SAAS,EAAE,MAAM,EAA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,MAAM,CAAC,KAAK,CAAC,MAAM,SAAS,CAAC,GAAG,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC;aACrD;QACL,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,gCAAgC,EAAE;QACjC,IAAI,EAAE,CAAC;QAEP,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,EAAE;YACrD,MAAM,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"} \ No newline at end of file diff --git a/lib.esm/_tests/test-crypto.d.ts b/lib.esm/_tests/test-crypto.d.ts new file mode 100644 index 00000000..5e2048d9 --- /dev/null +++ b/lib.esm/_tests/test-crypto.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=test-crypto.d.ts.map \ No newline at end of file diff --git a/lib.esm/_tests/test-crypto.d.ts.map b/lib.esm/_tests/test-crypto.d.ts.map new file mode 100644 index 00000000..bac9d8b0 --- /dev/null +++ b/lib.esm/_tests/test-crypto.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"test-crypto.d.ts","sourceRoot":"","sources":["../../src.ts/_tests/test-crypto.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/lib.esm/_tests/test-crypto.js b/lib.esm/_tests/test-crypto.js new file mode 100644 index 00000000..87712ba0 --- /dev/null +++ b/lib.esm/_tests/test-crypto.js @@ -0,0 +1,475 @@ +import assert from "assert"; +import { loadTests } from "./utils.js"; +import { getBytes } from "../index.js"; +import { computeHmac, keccak256, ripemd160, sha256, sha512, pbkdf2, scrypt, scryptSync, SigningKey } from "../index.js"; +describe("test hashing", function () { + const tests = loadTests("hashes"); + tests.forEach((test) => { + it(`computes sha2-256: ${test.name}`, function () { + assert.equal(sha256(test.data), test.sha256); + }); + }); + tests.forEach((test) => { + it(`computes sha2-512: ${test.name}`, function () { + assert.equal(sha512(test.data), test.sha512); + }); + }); + tests.forEach((test) => { + it(`computes ripemd160: ${test.name}`, function () { + assert.equal(ripemd160(test.data), test.ripemd160); + }); + }); + tests.forEach((test) => { + it(`computes keccak256: ${test.name}`, function () { + assert.equal(keccak256(test.data), test.keccak256); + }); + }); +}); +describe("test password-based key derivation", function () { + const tests = loadTests("pbkdf"); + tests.forEach((test) => { + it(`computes pbkdf2: ${test.name}`, function () { + const password = getBytes(test.password); + const salt = getBytes(test.salt); + const { iterations, algorithm, key } = test.pbkdf2; + const result = pbkdf2(password, salt, iterations, test.dkLen, algorithm); + assert.equal(result, key); + }); + }); + tests.forEach((test) => { + it(`computes scrypt (sync): ${test.name}`, function () { + this.timeout(1000); + const password = getBytes(test.password); + const salt = getBytes(test.salt); + const { N, r, p, key } = test.scrypt; + const result = scryptSync(password, salt, N, r, p, test.dkLen); + assert.equal(result, key); + }); + }); + tests.forEach((test) => { + it(`computes scrypt (async): ${test.name}`, async function () { + this.timeout(1000); + const password = getBytes(test.password); + const salt = getBytes(test.salt); + const { N, r, p, key } = test.scrypt; + let progressCount = 0, progressOk = true, lastProgress = -1; + const result = await scrypt(password, salt, N, r, p, test.dkLen, (progress) => { + if (progress < lastProgress) { + progressOk = false; + } + lastProgress = progress; + progressCount++; + }); + assert.ok(progressOk, "progress was not monotonically increasing"); + assert.ok(progressCount > 100, "progress callback was called at leat 100 times"); + assert.equal(result, key); + }); + }); +}); +describe("test hmac", function () { + const tests = loadTests("hmac"); + tests.forEach((test) => { + it(`computes hmac: ${test.name}`, async function () { + const { algorithm, key, data } = test; + assert.equal(computeHmac(algorithm, key, data), test.hmac); + }); + }); +}); +describe("tests ECDH shared secret", function () { + const tests = [ + { + "name": "test-0", + "keyA": "0xb484f7e25b06a887c3a01c97db40b5d96a1bd1ce69f342442a8395bfc995c34c", + "keyB": "0x407f75dc7d9f420c54bcc51189a16841b75aab53827d3ed54d5548448136f577", + "shared": "0x04131c0361e18fbdfb1575b06763225e8e7d4b6d33a6b6f369f20ff05bb6bb79cf6f510154615774f14a68ec405244fc8cba9fecdf012d22988575bf7f72f55cea" + }, + { + "name": "test-1", + "keyA": "0x953287b3e32f93c3ae8974d380b88f9a6d89ce2969c4b589cf4d068ec719c885", + "keyB": "0xf92ec8bea281236772a90219e9c661d475c6dd457dbf71f3076e9f136a7dee2b", + "shared": "0x04b0d910de1a56e19a300e4cf7d8946fab088da26bad0be01b3139af7f61633387c110d00a9f4059a75808c7471665242996b0999677bfef0f8c9b2eb9cb7ff3f0" + }, + { + "name": "test-2", + "keyA": "0xe47de7c043683a3facabbd72097c5c1c9148fc2d66854dfc32df924bfdb45a13", + "keyB": "0x5bfe0ef6a3c40797a4b013d01bbc02dfb150c46cb04c85a52be5d5d370d1f60a", + "shared": "0x04abcb75054302b210ac0ab42d412e47cc08bfc0d29298edc3a1c0f11d88c49240a8f922ca57dfbc003e6655337c75d5598b704ea91546206d9495aa61213aa96a" + }, + { + "name": "test-3", + "keyA": "0x3f0b65deb1a95ec280649e81b933ef382441fdc875f6280d782e45628f0dccd7", + "keyB": "0x3aeb016c64f23b276f816aa5494a2cec07361d2a4a0d4992a5b99764127e8f9e", + "shared": "0x04de883e02e1842f87796a83790b646615902e2a0612477bc63002f23a94d700c15632660cf6018f10a81785a9f294dd100309e397e88e7d1b7d70f601a4cf3b1b" + }, + { + "name": "test-4", + "keyA": "0xb9f059a915d6421848ae4344c64f1803342a7991c1fd567d61238aaaab583a5a", + "keyB": "0x0beb07549d6496d635c45152673455268f4beb89c07ff049c6e269dfa867ac2c", + "shared": "0x0411f59f62bd3033dba981f23fac5cc0718737dabeea9f060d0fd572383007402b539dd60b23b936c7842fcf16f4fb0524cc07ab02a06c3be8b33113a20f3d47d0" + }, + { + "name": "test-5", + "keyA": "0xb48da3af696d7893c818b5e38ff682ab77818dccb80599f36b5108ad25214cf0", + "keyB": "0xac732d7e814ef45ef8a7acf31c4f04eef30247c992b558c8523f4894e599e772", + "shared": "0x0499778f55f0e87e28d72991c380a2ea5147f0336f5bc7d7ef6a1b2ef25e8949d05e3a5e60a1d605abe69427daf321a118f648c4b4da2529843b5409df921fb927" + }, + { + "name": "test-6", + "keyA": "0x90b5123740bf282e9622ff8a2511692e0abc897bd61a64f49c2497967cb45dd5", + "keyB": "0x471e8f4b20e3328d4a25c20dad734e0bdc160c6c3dd3709858ca6ba6ce74d24b", + "shared": "0x04428de953d7409c419a6f11622c4a4d087082b54bc8207c514534ecf7901723c1f58359631ba94e95c05d934a2eedcecd705bbb61dd8f57cbb08572dc69e6a782" + }, + { + "name": "test-7", + "keyA": "0x9f7f6431c1318481003fd21871b4b8a86ca779caaef10fec2209479b5072ea15", + "keyB": "0xb6be68f448ac1092a704613f3a75324b5c58157f3595c48a3825a0089d7f9d3c", + "shared": "0x0468218704c8c364d4d1838c7f66ccab205797eab0b02b93b75cf4e4437dbe13e7d9d0830971758b3a65e75eab577954b42f6721c104e4b876b77b8db63d23d43d" + }, + { + "name": "test-8", + "keyA": "0xb9113e35ac2f7ba2a315e9f4301275cf561b91860f612d14a351273e38c04966", + "keyB": "0x00c3101f5d3d6272299180fd426dc1554854cb06dc911bc85fa97327d4fa3f21", + "shared": "0x04532cc9a89b735f0a11a0dbbbd40b05460dcf8e41e9da8359c727336a245d5d9babcca050434b81c01a6c70bd27692123f99377f22c0651bc0b01ae9871624894" + }, + { + "name": "test-9", + "keyA": "0xf569179eccaaf12c837a7362b7fbe41976dbf760270fa759e3dff18ae2bbe5fd", + "keyB": "0xc8654bad899f2e827d581f45db8b7f295a0dcfe5253577d8604c08d589180527", + "shared": "0x04d3568b0d1203d09cf9d1707c3ed1a44eb0230d2169c19c89433df8330010160885e6e626ce4505ac6ce7dda68bd57d2ddaa07a5ef5a4685c6a4e3784b8ad9184" + }, + { + "name": "test-10", + "keyA": "0x0ffd74c78276a1bcffe332b0545400e5992c87f2a2f91caa71ad76215ed2b229", + "keyB": "0x47dcfdf847d5b572784d546e0c5048aa4e613e74936fcc5438b75370d5f5525a", + "shared": "0x040fc7a5c5a7f9bfb98b596d698dbb0a87e1dcd50457544644acfb09ee3802835bbadc7717d06f4cc19af3bd308755eedfb162055b08134d63a49231ef9a38e503" + }, + { + "name": "test-11", + "keyA": "0x9777dd28dd62dbf7b17244b8e7b49b3cb673b81ef9dabbb196c23ccd3d0b22e6", + "keyB": "0xbc1f73ca7cdc51e1264429d6f6b581c75b3a5986cb993f09ab779156764ae1b1", + "shared": "0x04493d9be34f59077b11f56f8f883bb1f9ff247500f482f3ff6c1adcee9860442529b957a92ddc3a40391859e3b853b95c8e2159cf2dcfcf70ad4d6b7b55386f37" + }, + { + "name": "test-12", + "keyA": "0xd0ae54b6b72ddc5b8ed416251671bb488f9bd18e63fc60ed10dbcd12920d2f65", + "keyB": "0x2bcfd3837358a43cb181613ebdb152d72efc9fe7dada0c6bc44eb84d61070e2a", + "shared": "0x049f2d2eb2a6ba4937ab44c8ab1769c4b64b74b4d187f965c5ec1272cbe53d79858c8bcadfc17a37d95633da3881fb0e2900a1dfd1ac7160d67fa3dbd81b3de268" + }, + { + "name": "test-13", + "keyA": "0x14dbcd45b32a3ece2adb1691352096d395354928f7ceb5197c85cfe95b4e23eb", + "keyB": "0x111ed2f1a9fafbe021cb07033f0a1d45084fbb6b2facd008fe1d89e7ad029ae8", + "shared": "0x0441389bf60228a087c317d6a07b41ce9da09a4749c6b595ba5d8deef7eb7d8c21d266450b3df6a2a2d29ed149e909b3381604c74b5154da7cdcb9bb26336a6aa5" + }, + { + "name": "test-14", + "keyA": "0x3e7d474097eb34d76c38d4bc586f9cefc3bed6d8c172e4e5fea4016e0f820e1c", + "keyB": "0x3d8c224427a5cc554fd064020017c20f655c347f344afa68d133b1e3b8bfb0d6", + "shared": "0x04acd1f4ff562dd474f6ecda6f94b9d6eac65c497f0b103f1b6bcf03fd306f82505d5c5aa9de302f9c0577e479392795eaa13d68e2c6fe665ed7dc249d5a9ca7bd" + }, + { + "name": "test-15", + "keyA": "0xa79deef7a811761554cc019967eeb15ad61b6a69b266e3a091c1e00d3bcd2057", + "keyB": "0x43fcca9678c66d1ef35617ade47cf015f75da19d1b7189144a0be0c1631a4a00", + "shared": "0x0470131669ac84dc65ada0c23469b39cc42a54df3482577427a7aab58bddaf13dc05469397717be0882fa7c37b8b7bbfbf49b500d1f17a3b6fe8c7f233eb2ac2b1" + }, + { + "name": "test-16", + "keyA": "0x1945930000f6a3bdf339d5b632c3864f9ce8a0370243dd2bdcf805aa8f9e80e8", + "keyB": "0xa97c423f9cc5827730b33ba804d15c8c97406f154a71561e3ed263299781e591", + "shared": "0x0414fca0eb5db9d0b52f64b5e7b794659e87f2ee6816e83076d1e16446f5e9646fb1dd042027eee659363958d472f4a38f9bc400556dd85c7802eb1b87d4250581" + }, + { + "name": "test-17", + "keyA": "0x5f6e300343975539ba132a6bf26c2b3fa827ee558bb6698c86bbc84ea8a71577", + "keyB": "0xc015b1dddc249815a81d9c7f54f4676b10a3ec321d9d0ddd35b800557fed6431", + "shared": "0x0476371203edee28e291a2b0fabccdf1018c395b090a8ffff2feec116d3cd103e6d3fa1ea02ddecdbd392dc076ea959c318abf2d69c06e35a92e4f09249d4d73b6" + }, + { + "name": "test-18", + "keyA": "0x3f4f0a728833e864f96e202060239743ceb1150cc75094195e6bd4f53e7bf62a", + "keyB": "0x5a7b89392da6f39464967d315ecfbe8822b75062d68f3a43cc2a928a6abf2993", + "shared": "0x04959db3cb80d503579bc587399d09b043778c66115d1354ce449e060d3599bf2faa4adcf7da0419aa0af732ab5b82fe3ed68e5e5860dd2f6610f3f4f2ca7351eb" + }, + { + "name": "test-19", + "keyA": "0xc3106be0925e0d69703e4ea6d3dbee7903a8b8bb293ae59b2f90b0efdb0b3a1a", + "keyB": "0x44cf9575f03af5afc03c36f62433ebd52579d894c759cab76d29a4b9d0bae083", + "shared": "0x04a980b037da455ec856a7e3a9f63e8b9daf73f8e1e929f3f10e2c4b603b5bca48264c057ce04a25f5f48d87d27a43f7192aaac3340d7d5972e2ad3efc5de20c13" + }, + { + "name": "test-20", + "keyA": "0xb6c7bd2ba0d2b30d3e56d038398c2c937fb5cae348accdc060fb882903312008", + "keyB": "0x9ed8d5fb02fa0e825e7e095cfd32f9e817e8cd030c4363470f55d17e37cf73ef", + "shared": "0x042aa9b64ce873f5a3005a8eaee54e823f17633eec0a808ce0e24286f3c169485c2b7145f10deee39073056ce69c7d8bbbd2ff693b33b8749ae2b2f47e2e342397" + }, + { + "name": "test-21", + "keyA": "0x9f44756603bca7e87e2dd718ef2323f12854056aae86dc9e31715f97c0b3dc12", + "keyB": "0xd1ae23664d6320f9989b031cd7357fe346e207ffe73ed51de7c485754b8f1578", + "shared": "0x04037ab94245dad8282b4fabfec79ae5ca26367db2f45a183eb4c0f0c9ab7bf0d2b33503981159468f660711fb956eb730675b1e34f1e7d0aca07b936b64c47d56" + }, + { + "name": "test-22", + "keyA": "0x4c6307b149f1052290dc0140d6d597c25ddd23bc0ca826a9f44215009d13dad5", + "keyB": "0x9845254fdb40c7c74d0f9f3c6f73ce97a27f4306368685448b1f72dfbb3dd5d9", + "shared": "0x04f0ea5528a2efa16d424dbc07d49d3d2943e842289c6472f1cdeded965438326af76bb47449b417ef3b82130096f3c019d0ae3ffc3c9631f065a3285ba8539bfd" + }, + { + "name": "test-23", + "keyA": "0xab6ac9d67466cae30d31584104970e1093ebda6690dc9bf7bea1f66f07ddfcb7", + "keyB": "0xc0f58e549e7984e780cbc307b2a6b4c4863302474d271637586fa7cc0e389df8", + "shared": "0x045d5fd0d76d168b746462231a5bfb07fc175f43b206622781614e3df3491ba4c3738c4d3ae2d7f18ab0570c86aeb139778219fcc57cac3d42726de0f38d31b52a" + }, + { + "name": "test-24", + "keyA": "0x5b0e950974450f38dba31e01379814f0ed1b0f983cfda62dfecff5cd3e8db391", + "keyB": "0x4739f9e168dee9af2c8a9107b18738c9e3335115af8a431810ecce5269fba577", + "shared": "0x04da8ab5cf841804f0b5845f36e46e3463dfa3d6d9e7a306962062b729c680b2e8fdbf2b3eb2bdcc90d2884b9217dbdb3ad3620cd844982f19920e5d4f59353504" + }, + { + "name": "test-25", + "keyA": "0x9f3583cffcbe992d4a537defb5d8479c2bfa96a39a3f33fcf40123854bc96ea4", + "keyB": "0x42fe9367ef668babd70d4f5e836627cc78990b8a1738a56adf23baebf9410b48", + "shared": "0x0414edfdae5d2db370a51b5cf45ee6049621f52dd15eb5136c795ed364221c0a5c0f32e9ebbc9211b121ccc06516756e9280b210abe5b1a8f6c658dc69c39341f5" + }, + { + "name": "test-26", + "keyA": "0x289406a24a7794b04469a4acf9846e905ed4cae37349101db835f90e25d09605", + "keyB": "0xb2d58cdc470106c12f538b4516559d8ecaad0bcae063848a44f8639168453b93", + "shared": "0x04a9a80e466ea54aa0651eccde081e47637d2c142e1aaaf42572ee0753a49f7667c94b99f5bc2bf632b1330e3ffef95d009560e61084cbc07aab020282af5721f9" + }, + { + "name": "test-27", + "keyA": "0xd9bcf36ef585f59e1570904784f0a3df6435c798bec7e1c406e922d51f98b510", + "keyB": "0x40244928c9d371a427a0ce96530120deee3d31af086db679ee6bd8c1a7773030", + "shared": "0x04ac55594d87dfdd8af303c5f92745d49fba6ff15afb628212bc5d432d97bbd909938873c298fb93c851d901bf178e14ef1d590ff0dca7f7ead5613e97e3a824db" + }, + { + "name": "test-28", + "keyA": "0x301b79d85431a2c8bc21236cc58e1221eeb0862d3e3cfb29534423e6992e7591", + "keyB": "0xe6a62f0c49971b7b11477fc964d777de92267ab09f1465520ca31edcd7abaffe", + "shared": "0x049b7326b33eacc5ee3c102cae791d1835219253b70596f6a36892f2bb35fda1aebd661c781ac38b2461ac67b80ea1c18cd0230d024712a4e1826a6c5463874b0f" + }, + { + "name": "test-29", + "keyA": "0x49542517ff2bd70e851405cf285cf2280f84af838e2b0a68ed779f96d0ce62eb", + "keyB": "0x48ffc78034851d2f4e610bc11b97c21d42f5d7bbada2415ee8f03f6b643c92b7", + "shared": "0x04dc12a233b08ff25ee7806cfede3565dedd663e0cd25108ad233b6c5c8f8c25fe82d4b2820fa44e0ef86d51d0eada0033854a1199644204f9233887e457775bb0" + }, + { + "name": "test-30", + "keyA": "0x6597a9b39b58bd47561fd4058894ee327368fdd8b8b267efa0596793c3852ed8", + "keyB": "0xbcab19f22f0cca9fc791f998a5717bc4c81853ff4f1c974a7dde7ecef41b4802", + "shared": "0x043d622a7f3255437c9f6459e68d5e3333d377b76ac053a50affbdf88c555508c42000b092dbb07b72ecf5887766ebb2e47afdb3d8324b7938d9255171d971b1a8" + }, + { + "name": "test-31", + "keyA": "0x4127797885e7b8b7c882fec5cf38be273f42de47261e8ea4aab49769d606dd01", + "keyB": "0xc82a9b18f2f060adaf4f7cf56f29a2f4859d12a452b8b9f079f8850423fba666", + "shared": "0x045e7b62ced9cebd94d2115b11f2e9ca6f9a66119a17296613a60439d2960747f927c305822fe15582bb62f48c574aa7c89e7b2c8e5d4affc86f097e794bdf029d" + }, + { + "name": "test-32", + "keyA": "0xf5ffbd9bf88dd867ace131df25fc9bd9ab87b7834d91786f110f40eb2e7b73b2", + "keyB": "0x203fe0bd83081d65fe45f194c373dd84c61fcdcfd4783d18e0e060f56efde038", + "shared": "0x04cddff70996f116a874442da0a33ac3df0e99f063bd1066644e6ca88442bda15d5b46fe8c6de7467a13c65febf4a6d258ffae99784c21fa61fa8a3b384b666154" + }, + { + "name": "test-33", + "keyA": "0x5073d19c09be03d0c41cef0b950e13b85ee87c4c1642061addbdfd34c3258618", + "keyB": "0x37cf3617c1728e613c738c9b61fc84b76490128b3a584a861862416b1bb5ca60", + "shared": "0x046234004e627b076d7bb6b6aedae341ab755f5f3dbca295fb2a70ae3206f26543c8f031605764e7dfb377a12c0be3a61df6983707ba62955487cc36ba8e8c0812" + }, + { + "name": "test-34", + "keyA": "0x0378dd63bb9f1fd4b0b7c266239ca574c7f6f7ca62645b3e9edcf763918eb110", + "keyB": "0xfd144b5e82bb6dbbcc9e9b714d64e283b748e85ba93b0113727fc1670251c6dc", + "shared": "0x0481f04971c2282e9850ee373aba6ec92390e3ff12b95d86d339dfce7dfa592f012ef71875aba27adec232a90f209f420c6e7c73fd40f165ba9b6196a10ca5e82b" + }, + { + "name": "test-35", + "keyA": "0xfa99235e06ec83c103ab50653ff5af505b085892781a6e743c7398219562ffe4", + "keyB": "0x6a8850083fdf6ecb9f9bdb613f1c6706fe233e2e74fad460f7c650751bf999e9", + "shared": "0x0407117676960073ab08890efd07eb6222584b2c8ad9a1eb64f9e610138c10a4d59f4ca496910ac35a1fad24e56fc08020ffac2dfabb2d79bbcc041e70dffb203c" + }, + { + "name": "test-36", + "keyA": "0x3abcf36699a174e462196891e49e72759f707d7f82ae5e64a49f1273927802ae", + "keyB": "0x44212cd650066f2371908cc6ba520061745db823c64b8b99dae535e364fe7034", + "shared": "0x04c354916600479cbbf9d91f5b851ee075f0aac99befa434f3f3b30fa887a0a7af71129ea47b388ac41538a71f9e52f68473ccc2611ace7cdd999ee036bc43b459" + }, + { + "name": "test-37", + "keyA": "0x858512678a61f3d286fd1a90cb8fb8960d8cffaa31686706d0a879d66acabc7f", + "keyB": "0x490e29655cb5da0dcd2f60e4583cb41b7ad9a801fbc00a2927968f06b0c14852", + "shared": "0x040dde94c952ec15bcba15d773ba0dfa9cb5ed7731cda1b7f8110fa91f843173f83d577f601b61f2df21b9f7cbf2b1d54792a6f9403c2446a480af7b69e23b8d21" + }, + { + "name": "test-38", + "keyA": "0xaeb4d6c2a817e5882f991f0c3c81d0f6f2d3d8854d472511a211cae67adae695", + "keyB": "0x72c297384a02544ba9719c0ce1f0ad3cb4e89b57536880f65c0462d1f058a55f", + "shared": "0x041a61bd828eacb1aaacbbb3b0291d691f5fc1462f16fc55f828b1f28e73342957de6b718501e66c3a1885ce16e124adb600457095ba770f58be012d0b69ca949a" + }, + { + "name": "test-39", + "keyA": "0xb0fc529ff1bb4a7985663d54b279cbf4a597ec922a810ca16b87697ef3ef0dd3", + "keyB": "0xaf6019921bc7db54c334102a766d32d3ff06fd68ed08efe8ca2a35ce5074dcd0", + "shared": "0x04b49b24610350fde84bf067affc1d9f7ac549b3c4c05fa963aade41e65d6645cf867466f6c87e11298cb433f45f65eec4c5d88e76acdd5515a92802ded42c6e0a" + }, + { + "name": "test-40", + "keyA": "0x160fdb84df11195fb0d33335e593499c3505cadce25ffdf6cdd8af0cb78d400c", + "keyB": "0xb37568a52ead1debcb2d402fa3d58f212a37321aae2cea1b90b263a3276bfdce", + "shared": "0x04091c2e14e517d9990425bb5d0a9e48f3bfe27a1cb673182fe1f7dc27bd6a56043a7745c9d27052e60ce72a1d82357f6675fadf9994add784c45821f52f2b094e" + }, + { + "name": "test-41", + "keyA": "0x253ca7443d94998bab1f508e3424c662831c6be6ec5d387e97c79f078087ff15", + "keyB": "0x38102245618fddf8a1bd7de152c6fa630523223b89a1649d5f2fa5f9e47ffe4a", + "shared": "0x04046754be94d9ad925f67b1bc80fe32cd6920f9f80327cdc83f68e95d999b1d8ab7b41844db1c1ea66662b42737169daefc675c9364583565e3982b674d8a30dd" + }, + { + "name": "test-42", + "keyA": "0xef558874b5b1d5915c83e3c1e4554d73de1e9943af445eba3f6516b731cc0126", + "keyB": "0x956e32c2e87263215b8c31c7f2e7311d6acad863f3c428b0625c9376cbc405cd", + "shared": "0x047e9265334e20ad8747098147b0eabb6d01c8ab12722cf0bbede05c1beaa67e8e770e04e19cf6035f48289fbe85cd4b9496a9ca5a90d088f8e75a0c1c6c7f1cc8" + }, + { + "name": "test-43", + "keyA": "0x32c00e0d3a2ba3db6685058e1327dcee6425068190890439391fdb95857f27b0", + "keyB": "0x8b39021f7ad57a101534977d323c0349cecc8405d93286c6e71a441f4cc16c86", + "shared": "0x04c8095c862e64f6866fd3c177ed898fa3ca5da2d585c60ea4646d8f2cb9f332dbd54ca9d3b2a9e852a15189a0eb97a8edfaa114a01277418aa2ecfdfb3770caa0" + }, + { + "name": "test-44", + "keyA": "0x40627c6987e20c07014833e23a0b9304bbaf66525a59b892e224944b56d3117a", + "keyB": "0xe23607bff98d5699816836f65e5405f2e60d4fe2449979acd43ee2b3e9bfc218", + "shared": "0x04be3ec3c188e7c74944d42beddf19003aeb0ccf8cccf8532b220dc666520f277e8b98b87ee694e8c76256e51ebf69433479c69a4ccef3032e9cb550632db539f8" + }, + { + "name": "test-45", + "keyA": "0x46c25bcd7d2f8ce6d27148a11f18e0314046260433f8cc6421be4dcd72a6e088", + "keyB": "0xf29022ca90a60d455d0b1470034d1c7fbba27a9997b1940a9373a97d092f965e", + "shared": "0x041f5fd1dd02afa8ce5d2877a05ce92a4db5aef022a8203551590343352c1bd6e71cad811974a74f49d140949aa091dc4262cf7da0b48bdfa26939cf4b9c461f52" + }, + { + "name": "test-46", + "keyA": "0x6d6b69d4f9fafd986e5b1a9c36f3021aae9ce64c027f1bf9bd9e9e12d86a276b", + "keyB": "0xeed0cabb4ae5a696e762c98e6d697bd88a89d9a0b38458c6e696f0748e404fe6", + "shared": "0x04f2f9c8fa945577d7188292f5c4a4fad80bdcc3db44d6d5c15bda5a23971ac7046cb8af44bb5864a9e0e82c921805663c539a22f8c5ef22187062564f1359f4d2" + }, + { + "name": "test-47", + "keyA": "0xf6b6d733b8c473a562f7a23c7cbb23f40273d809d13aeb308149ad709c674300", + "keyB": "0xd873a7d24c1f498a43c181f566f265cda248f9e2df8a825e69a73aeb1437dad9", + "shared": "0x0495f669c1c7271be4c8e628017ef570a0cb903887c3ea4897f09cc9ecd2a4f6b043e1fa41d1ddbf8f01e60368bc95e81ae2a8bf4922374294b0836ff7e43ad2ab" + }, + { + "name": "test-48", + "keyA": "0x28410a640558a5da5b7746a46a9cdefc704ba2944f23699d3767f6505a97eb78", + "keyB": "0xfd1a548275be4d922cc294276d7b059cea0fbbcb629be29bb8072de597a96597", + "shared": "0x04fca25ec051c8532f664fe2c2e213d1bd3e298422232dd34e821245256e0bff4ff80fb1f03524fd57d1d4a6effc076899cc21dde0be10d60016c20c33b7524d00" + }, + { + "name": "test-49", + "keyA": "0x89e51abd416ad4579d523bed183da74b991c589decb982649a0abedfe6061c0f", + "keyB": "0x22b4cad2ade397b86756c2457516cd23d0858700b0597fdb2433e891efa435e3", + "shared": "0x049316e68898db5d7c987fbfa371b1fbd6a56d585bde1017a825d1dfaad406b428a505e773e63ddd0244b0e25ddc1b08dda6dd9968673f7b10c40d8fe8a1e1d55f" + }, + { + "name": "test-50", + "keyA": "0x2c645e1abac8e5848617067e6c3d739a6f126484d27f73bc8fdfdc9f0ac3ff04", + "keyB": "0x71252585fb806d9273c0103dcf642b419e7632ef3aeba3efc6c71863b50ae177", + "shared": "0x04886ec11347e30fc5e68a353201d702c4425358791ea6a6213c444c7489e38103c953fe13f4238dbe769f0d6208f693e356f81e7037977cf8a5b04661e37d2569" + }, + { + "name": "test-51", + "keyA": "0x572a1ce3adfc10ca3afc39262d36c329ba44d7cfa6ca5c62d2e882ac25480d47", + "keyB": "0x2b9081d499417315277663c86e25dd7898ea67e969b632dd11e80d29e92b557f", + "shared": "0x0424c5ae82f447c156d97ed31c83f36cf3416cb4a72666bb4e8a61687a4ba4ae22b42f7d18579ff204f7974af9f8dcc51d8f9eabc45c720f607478ba78c2b2921c" + }, + { + "name": "test-52", + "keyA": "0x60ba350fb7e0729ad992f53a314eacce65da6897856e362d2ef0959e890b9e99", + "keyB": "0x6a9629c655cf4f8b8816e95df1c14f769cb946431c6da17a04423ceef8979ee1", + "shared": "0x04831e236ece1bde7db14b819c06e0a17964b88b5fc4e8253a8dc316d613fad8ffdb5117eb920f34ce838d6861caa0e885e3c20d37cfd20e19d1092d52976e0f91" + }, + { + "name": "test-53", + "keyA": "0x32eb6769ade64560a016e080f5e16ea97b2d0cb96b730e9c5c809bfd19a002c4", + "keyB": "0x7dff2eb8455b0e9c0fd38838db3d3de96067a6efc05d21d1bb303ca0bd52d87d", + "shared": "0x04b0cf54b0590546e434a5e3d2071c3c022d4b3b571660b359cee7d199e525965e9f38d12436affda7741d5b752e0b430149a1ec6d7835a6999e64b3ea324e91c6" + }, + { + "name": "test-54", + "keyA": "0x70446e5ede6e26b96d3cecfe8afc35055a0a90f83c7db4d1b8a819d5cddb6642", + "keyB": "0x2df217bf6e92875e35af50bfa301059b2ddf593c0694b70116a8c87ee27ef4c9", + "shared": "0x0458e1554b06a40b9508d86d5cedeb3dccb82053881393306b1894d198412500dc0efa4dad2265d7532e59d06f71cf33f3d48728b4707434a5c722eea8d9a9acbc" + }, + { + "name": "test-55", + "keyA": "0x64e16f672ec5aba6be5a4965d44bd7224aae65d444ceee6dd58690e527b36186", + "keyB": "0xefb054ff4222e8e493cb667f56129dc1b6a3437581280a3f984ff0ea09ec3029", + "shared": "0x04c806576fb79b4d7d38d00a3ee2c2896dfb1b29ef3a42ac72a82c7bf7626f2073a79aec8ee2c3c101845ce5171b27a9f23075ed74ccdae088956e3dcdbae74e7d" + }, + { + "name": "test-56", + "keyA": "0x284a5592ab3fa9b8df2bf927761a667118697cd7413c255ef3cce9e9de76c321", + "keyB": "0x52d0033d83fbdeb0b7c8d21b475ec637fabfcc7c2593494d7e846ecd974083af", + "shared": "0x04e092613c7552c3180bdb041c32b9763804e6703c2c116009f1012526002472b5b627a85cb50c90942fe177bd36e2d4fbd8e9d835c72a607ee07ffead29cf12eb" + }, + { + "name": "test-57", + "keyA": "0x488e6c2d97fe0ff3f5357254658ae487ade54bdf7bf871ffdfe27079cbeff103", + "keyB": "0x00f8632a6982d58c25236ce1952c19052f6b08edad61edd166570a8679a98f5c", + "shared": "0x048f02436bb55798561a6a78aacbeec67f0acd8ba88e99af6ec1b7b5152d9a5d7691a905c11fe26c2ba3d72be918f6ee7c3e66115a31a7f199f33073f6f5087181" + }, + { + "name": "test-58", + "keyA": "0x0067fd2eec16c7ddf9a364f591d47394bfc12fd2b3ccff1bf1013e92e969f6f0", + "keyB": "0x76f1e3f4abfb237ec3ac6e72a56f25bfa06e7561bc5fdc4823282f9db40c49d4", + "shared": "0x04975e88ffcd670b06e7752d3d375613d0cd614f2b3a812e684342dcc16be6de336af2bb30ab25da0362ecf43752b477b412081d723f5c6840ea78deacd5f76b4a" + }, + { + "name": "test-59", + "keyA": "0x4ff02743564c317a3578c08f7961a204d48e511e31688ba069037f6090235b37", + "keyB": "0xcf22489e1b9058b4a645e38504eaa32e031dea44e1465eb1122e14e4847c9744", + "shared": "0x04e584b571a9f99087bc6cb7818741cfc3b630ec412f64da1ada72de17279afa60258c5844cc2c7c1416548497b083f2aeb035c8945c0aa03a25b97bad7870c136" + }, + { + "name": "test-60", + "keyA": "0xd140deee768594cea37e2eb5c89c60228083f93866ebd62c7c07a1a9f8a9bf58", + "keyB": "0xc9f2edf7ccd6db9f21ef5a3966ee11694dec652d60ef21a540802db8b990c370", + "shared": "0x0451b4a54b1fcdcbe4f5b97b3003bce3cc91f362cf2baa696ad0abca3cd21b12d4e4f3d1b0dc1c18599917f5fc9be7825d23999769d3811edf61a7ecc34525b403" + }, + { + "name": "test-61", + "keyA": "0x63dcf1d3db0d89a37df3734e88f601412a184030f15474a0d9687e3105361161", + "keyB": "0x5370bec049bcd28507f4078783d9378cd84b8e05230089e8987d3a485c945b08", + "shared": "0x04e27e5ec5eb72fa6bda376f832b4730d6f7b9104594fa191ac87198f0d4aeed47c79568cf8f59fae0e43e8bf0931c491eda0cce1f19efc4153aacde94e673ba7f" + }, + { + "name": "test-62", + "keyA": "0x465d0d758d8c7664d9e1bfa46fb5fb8e27265cb4bc28c0f7752d596910545028", + "keyB": "0xeff55416a21e627ec4c55a08c9a3f7378ae2953fd5bf0926bde15965cf6b4d5d", + "shared": "0x0487b20dbad3b5443594fc66470559206c37440a01ef91c24c38a51bc7bcf7676409789c6bc214087947ab8d0359927080422b2ecbd23e765bf6a79e4bbb456796" + }, + { + "name": "test-63", + "keyA": "0x28469aab3ebc9efdec35b19e7c42a26311c649267ac92ae2ef2f5c8880eb517c", + "keyB": "0x786e828e92abb73818380b37395c67dcb6a72f3e0a440bdf1f5f132a0621fc78", + "shared": "0x046bfff91c9b31abb6df020018b66734c7f9fc4f7294c809c706b76c308982e5d75c10200fbdf67d75ba4b154223f591bfe3504006ba69634d4025c57b9af4ab73" + } + ]; + for (const { name, keyA, keyB, shared } of tests) { + it(`tests shared secrets match: ${name}`, function () { + const signA = new SigningKey(keyA); + const signB = new SigningKey(keyB); + assert.equal(signA.computeSharedSecret(signB.publicKey), shared, "privA + pubB"); + assert.equal(signB.computeSharedSecret(signA.publicKey), shared, "pubA + privB"); + assert.equal(signA.computeSharedSecret(signB.privateKey), shared, "privA + privB"); + }); + } +}); +//# sourceMappingURL=test-crypto.js.map \ No newline at end of file diff --git a/lib.esm/_tests/test-crypto.js.map b/lib.esm/_tests/test-crypto.js.map new file mode 100644 index 00000000..fd92acaf --- /dev/null +++ b/lib.esm/_tests/test-crypto.js.map @@ -0,0 +1 @@ +{"version":3,"file":"test-crypto.js","sourceRoot":"","sources":["../../src.ts/_tests/test-crypto.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAIvC,OAAO,EACH,WAAW,EACX,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EACpC,MAAM,EAAE,MAAM,EAAE,UAAU,EAC1B,UAAU,EACb,MAAM,aAAa,CAAC;AAGrB,QAAQ,CAAC,cAAc,EAAE;IACrB,MAAM,KAAK,GAAG,SAAS,CAAe,QAAQ,CAAC,CAAC;IAEhD,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACnB,EAAE,CAAC,sBAAuB,IAAI,CAAC,IAAK,EAAE,EAAE;YACpC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE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,EAAE,SAAS;YACjB,MAAM,EAAE,oEAAoE;YAC5E,MAAM,EAAE,oEAAoE;YAC5E,QAAQ,EAAE,sIAAsI;SACnJ;QACD;YACI,MAAM,EAAE,SAAS;YACjB,MAAM,EAAE,oEAAoE;YAC5E,MAAM,EAAE,oEAAoE;YAC5E,QAAQ,EAAE,sIAAsI;SACnJ;KACJ,CAAC;IAEF,KAAK,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,KAAK,EAAE;QAC9C,EAAE,CAAC,+BAAgC,IAAK,EAAE,EAAE;YACxC,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;YACnC,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;YAEnC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,mBAAmB,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,cAAc,CAAC,CAAC;YACjF,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,mBAAmB,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,cAAc,CAAC,CAAC;YACjF,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,mBAAmB,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,eAAe,CAAC,CAAC;QACvF,CAAC,CAAC,CAAC;KACN;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/lib.esm/_tests/test-hash-typeddata.d.ts b/lib.esm/_tests/test-hash-typeddata.d.ts new file mode 100644 index 00000000..ff782691 --- /dev/null +++ b/lib.esm/_tests/test-hash-typeddata.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=test-hash-typeddata.d.ts.map \ No newline at end of file diff --git a/lib.esm/_tests/test-hash-typeddata.d.ts.map b/lib.esm/_tests/test-hash-typeddata.d.ts.map new file mode 100644 index 00000000..b415412a --- /dev/null +++ b/lib.esm/_tests/test-hash-typeddata.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"test-hash-typeddata.d.ts","sourceRoot":"","sources":["../../src.ts/_tests/test-hash-typeddata.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/lib.esm/_tests/test-hash-typeddata.js b/lib.esm/_tests/test-hash-typeddata.js new file mode 100644 index 00000000..a590b0dd --- /dev/null +++ b/lib.esm/_tests/test-hash-typeddata.js @@ -0,0 +1,16 @@ +import assert from "assert"; +import { loadTests } from "./utils.js"; +import { TypedDataEncoder } from "../index.js"; +describe("Tests Typed Data (EIP-712)", function () { + const tests = loadTests("typed-data"); + for (const test of tests) { + it(`tests encoding typed-data: ${test.name}`, function () { + const encoder = TypedDataEncoder.from(test.types); + assert.equal(encoder.primaryType, test.primaryType, "primaryType"); + assert.equal(encoder.encode(test.data), test.encoded, "encoded"); + assert.equal(TypedDataEncoder.getPrimaryType(test.types), test.primaryType, "primaryType"); + assert.equal(TypedDataEncoder.hash(test.domain, test.types, test.data), test.digest, "digest"); + }); + } +}); +//# sourceMappingURL=test-hash-typeddata.js.map \ No newline at end of file diff --git a/lib.esm/_tests/test-hash-typeddata.js.map b/lib.esm/_tests/test-hash-typeddata.js.map new file mode 100644 index 00000000..0e7cd1f5 --- /dev/null +++ b/lib.esm/_tests/test-hash-typeddata.js.map @@ -0,0 +1 @@ +{"version":3,"file":"test-hash-typeddata.js","sourceRoot":"","sources":["../../src.ts/_tests/test-hash-typeddata.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAGvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAG/C,QAAQ,CAAC,4BAA4B,EAAE;IACnC,MAAM,KAAK,GAAG,SAAS,CAAoB,YAAY,CAAC,CAAC;IACzD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;QACtB,EAAE,CAAC,8BAA+B,IAAI,CAAC,IAAK,EAAE,EAAE;YAC5C,MAAM,OAAO,GAAG,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAClD,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;YACnE,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;YAEjE,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;YAC3F,MAAM,CAAC,KAAK,CAAC,gBAAgB,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"} \ No newline at end of file diff --git a/lib.esm/_tests/test-hash.d.ts b/lib.esm/_tests/test-hash.d.ts new file mode 100644 index 00000000..ca5de7ae --- /dev/null +++ b/lib.esm/_tests/test-hash.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=test-hash.d.ts.map \ No newline at end of file diff --git a/lib.esm/_tests/test-hash.d.ts.map b/lib.esm/_tests/test-hash.d.ts.map new file mode 100644 index 00000000..4edc9d4b --- /dev/null +++ b/lib.esm/_tests/test-hash.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"test-hash.d.ts","sourceRoot":"","sources":["../../src.ts/_tests/test-hash.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/lib.esm/_tests/test-hash.js b/lib.esm/_tests/test-hash.js new file mode 100644 index 00000000..4b5e8d5c --- /dev/null +++ b/lib.esm/_tests/test-hash.js @@ -0,0 +1,177 @@ +import assert from "assert"; +import { hashMessage, namehash, isValidName, solidityPacked, solidityPackedKeccak256, solidityPackedSha256, isError } from "../index.js"; +import { loadTests } from "./utils.js"; +//import { dnsEncode, isValidName, namehash } from "../index.js"; +describe("Tests Namehash", function () { + const tests = loadTests("namehash"); + for (const test of tests) { + if (!test.error) { + it(`hashes ENS name: ${JSON.stringify(test.name)}`, 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"); + } + }); + } + } + for (const test of tests) { + if (test.error) { + it(`correctly fails to hash ENS name: ${test.error} ${JSON.stringify(test.name)}`, function () { + assert.throws(function () { + const actual = namehash(test.ensName); + console.log("Failed to throw", actual); + }, (error) => { + return (isError(error, "INVALID_ARGUMENT") && + error.argument === "name" && error.value === test.ensName); + }); + // 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); + }); + }); + } + +}); +*/ +describe("Test EIP-191 Personal Message Hash", function () { + const tests = [ + { + test: "hello-world", + message: "Hello World", + hash: "0xca6464b285e602e01f3261caa151da2bd35fe19cb3532f7acd0d594ca0d810c5" + }, + { + test: "binary-message", + message: new Uint8Array([0x42, 0x43]), + hash: "0xd2ca8706bdbb1255b510b6acf42339faabf95bb8192cc7c562a6019ad8463c60" + }, + { + test: "hex-looking-string", + message: "0x4243", + hash: "0xcfe58e0f243f48080feeeb86f9b27e35f65955d3b39a644478c376b2733d9804" + } + ]; + for (const test of tests) { + it(`tests hashMessage: ${test.test}`, function () { + assert.equal(hashMessage(test.message), test.hash); + }); + } +}); +describe("Test Solidity Hash functions", function () { + const tests = loadTests("solidity-hashes"); + for (const test of tests) { + it(`computes the solidity keccak256: ${test.name}`, function () { + assert.equal(solidityPackedKeccak256(test.types, test.values), test.keccak256); + }); + } + for (const test of tests) { + it(`computes the solidity sha256: ${test.name}`, function () { + assert.equal(solidityPackedSha256(test.types, test.values), test.sha256); + }); + } + const badTypes = [ + { types: ["uint5"], values: [1] }, + { types: ["bytes0"], values: ["0x"] }, + { types: ["blorb"], values: [false] }, + ]; + for (const { types, values } of badTypes) { + it("correctly fails on invalid type", function () { + assert.throws(function () { + const result = solidityPacked(types, values); + console.log(result); + }, function (error) { + return (isError(error, "INVALID_ARGUMENT") && error.argument === "type"); + }); + }); + } +}); +//# sourceMappingURL=test-hash.js.map \ No newline at end of file diff --git a/lib.esm/_tests/test-hash.js.map b/lib.esm/_tests/test-hash.js.map new file mode 100644 index 00000000..e3ee6b48 --- /dev/null +++ b/lib.esm/_tests/test-hash.js.map @@ -0,0 +1 @@ +{"version":3,"file":"test-hash.js","sourceRoot":"","sources":["../../src.ts/_tests/test-hash.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EACH,WAAW,EACX,QAAQ,EAAE,WAAW,EACrB,cAAc,EAAE,uBAAuB,EAAE,oBAAoB,EAC7D,OAAO,EACV,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAKtC,iEAAiE;AAEjE,QAAQ,CAAC,gBAAgB,EAAE;IACvB,MAAM,KAAK,GAAG,SAAS,CAAmB,UAAU,CAAC,CAAC;IAEtD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;QACtB,IAAI,CAAC,IAAI,CAAC,KA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,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QAC7E,CAAC,CAAC,CAAC;KACN;IAED,MAAM,QAAQ,GAAG;QACb,EAAE,KAAK,EAAE,CAAE,OAAO,CAAE,EAAE,MAAM,EAAE,CAAE,CAAC,CAAE,EAAE;QACrC,EAAE,KAAK,EAAE,CAAE,QAAQ,CAAE,EAAE,MAAM,EAAE,CAAE,IAAI,CAAE,EAAE;QACzC,EAAE,KAAK,EAAE,CAAE,OAAO,CAAE,EAAE,MAAM,EAAE,CAAE,KAAK,CAAE,EAAE;KAC5C,CAAC;IAEF,KAAK,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,QAAQ,EAAE;QACtC,EAAE,CAAC,iCAAiC,EAAE;YAClC,MAAM,CAAC,MAAM,CAAC;gBACV,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;gBAC7C,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YACxB,CAAC,EAAE,UAAU,KAAK;gBACd,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,kBAAkB,CAAC,IAAI,KAAK,CAAC,QAAQ,KAAK,MAAM,CAAC,CAAC;YAC7E,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;KACN;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/lib.esm/_tests/test-provider-jsonrpc.d.ts b/lib.esm/_tests/test-provider-jsonrpc.d.ts new file mode 100644 index 00000000..ea8edddb --- /dev/null +++ b/lib.esm/_tests/test-provider-jsonrpc.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=test-provider-jsonrpc.d.ts.map \ No newline at end of file diff --git a/lib.esm/_tests/test-provider-jsonrpc.d.ts.map b/lib.esm/_tests/test-provider-jsonrpc.d.ts.map new file mode 100644 index 00000000..f7049a2a --- /dev/null +++ b/lib.esm/_tests/test-provider-jsonrpc.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"test-provider-jsonrpc.d.ts","sourceRoot":"","sources":["../../src.ts/_tests/test-provider-jsonrpc.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/lib.esm/_tests/test-provider-jsonrpc.js b/lib.esm/_tests/test-provider-jsonrpc.js new file mode 100644 index 00000000..8dab0428 --- /dev/null +++ b/lib.esm/_tests/test-provider-jsonrpc.js @@ -0,0 +1,159 @@ +import assert from "assert"; +import { id, isError, makeError, toUtf8Bytes, toUtf8String, FetchRequest, JsonRpcProvider, Transaction, Wallet } from "../index.js"; +const StatusMessages = { + 200: "OK", + 400: "BAD REQUEST", + 500: "SERVER ERROR", +}; +const wallet = new Wallet(id("test")); +function createProvider(testFunc) { + let blockNumber = 1; + const ticker = setInterval(() => { blockNumber++; }, 100); + if (ticker.unref) { + ticker.unref(); + } + const processReq = (req) => { + let result = testFunc(req.method, req.params, blockNumber); + if (result === undefined) { + switch (req.method) { + case "quai_blockNumber": + result = blockNumber; + break; + case "quai_chainId": + result = "0x1337"; + break; + case "quai_accounts": + result = [wallet.address]; + break; + default: + console.log("****", req); + return { id, error: "unsupported", jsonrpc: "2.0" }; + } + } + return { id: req.id, result, jsonrpc: "2.0" }; + }; + const req = new FetchRequest("http:/\/localhost:8082/"); + req.getUrlFunc = async (_req, signal) => { + const req = JSON.parse(_req.hasBody() ? toUtf8String(_req.body) : ""); + let statusCode = 200; + const headers = {}; + let resp; + try { + if (Array.isArray(req)) { + resp = req.map((r) => processReq(r)); + } + else { + resp = processReq(req); + } + } + catch (error) { + statusCode = 500; + resp = error.message; + } + const body = toUtf8Bytes(JSON.stringify(resp)); + return { + statusCode, + statusMessage: StatusMessages[statusCode], + headers, body + }; + }; + return new JsonRpcProvider(req, undefined, { cacheTimeout: -1 }); +} +describe("Ensure Catchable Errors", function () { + it("Can catch bad broadcast replies", async function () { + this.timeout(15000); + const txInfo = { + chainId: 1337, + gasLimit: 100000, + maxFeePerGas: 2000000000, + maxPriorityFeePerGas: 1000000000, + to: wallet.address, + from: wallet.address, + value: 1, + }; + const txSign = await wallet.signTransaction(txInfo); + const txObj = Transaction.from(txSign); + let count = 0; + const provider = createProvider((method, params, blockNumber) => { + switch (method) { + case "quai_sendTransaction": + return txObj.hash; + case "quai_getTransactionByHash": { + count++; + // First time; fail! + if (count === 1) { + throw makeError("Faux Error", "SERVER_ERROR", { + request: ({}) + }); + } + // Second time; return null + if (count === 2) { + return null; + } + // Return a valid tx... + const result = Object.assign({}, txObj.toJSON(), txObj.signature.toJSON(), { hash: txObj.hash, from: wallet.address }); + // ...eventually mined + if (count > 4) { + result.blockNumber = blockNumber; + result.blockHash = id("test"); + } + return result; + } + } + return undefined; + }); + const signer = await provider.getSigner(); + const tx = await signer.sendTransaction(txInfo); + assert(tx); + }); + it("Missing v is recovered", async function () { + this.timeout(15000); + const txInfo = { + chainId: 1337, + gasLimit: 100000, + maxFeePerGas: 2000000000, + maxPriorityFeePerGas: 1000000000, + to: wallet.address, + from: wallet.address, + value: 1, + }; + const txSign = await wallet.signTransaction(txInfo); + const txObj = Transaction.from(txSign); + let count = 0; + // A provider which is mocked to return a "missing v" + // in getTransaction + const provider = createProvider((method, params, blockNumber) => { + switch (method) { + case "quai_sendTransaction": + return txObj.hash; + case "quai_getTransactionByHash": { + count++; + // The fully valid tx response + const result = Object.assign({}, txObj.toJSON(), txObj.signature.toJSON(), { hash: txObj.hash, from: wallet.address, sig: null }); + // First time; fail with a missing v! + if (count < 2) { + delete result.v; + } + // Debug + result._count = count; + return result; + } + } + return undefined; + }); + // Track any "missing v" error + let missingV = null; + provider.on("error", (e) => { + if (isError(e, "UNKNOWN_ERROR") && isError(e.error, "INVALID_ARGUMENT")) { + if (e.error.argument === "signature" && e.error.shortMessage === "missing v") { + missingV = e.error; + } + } + }); + const signer = await provider.getSigner(); + const tx = await signer.sendTransaction(txInfo); + assert.ok(!!tx, "we got a transaction"); + assert.ok(!!missingV, "missing v error present"); + }); +}); +//# sourceMappingURL=test-provider-jsonrpc.js.map \ No newline at end of file diff --git a/lib.esm/_tests/test-provider-jsonrpc.js.map b/lib.esm/_tests/test-provider-jsonrpc.js.map new file mode 100644 index 00000000..42887247 --- /dev/null +++ b/lib.esm/_tests/test-provider-jsonrpc.js.map @@ -0,0 +1 @@ +{"version":3,"file":"test-provider-jsonrpc.js","sourceRoot":"","sources":["../../src.ts/_tests/test-provider-jsonrpc.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EACH,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EACjD,YAAY,EACZ,eAAe,EAAE,WAAW,EAAE,MAAM,EACvC,MAAM,aAAa,CAAC;AAErB,MAAM,cAAc,GAA2B;IAC7C,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,aAAa;IAClB,GAAG,EAAE,cAAc;CACpB,CAAC;AAMF,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;AAEtC,SAAS,cAAc,CAAC,QAAwB;IAE5C,IAAI,WAAW,GAAG,CAAC,CAAC;IACpB,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,WAAW,EAAE,CAAA,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACzD,IAAI,MAAM,CAAC,KAAK,EAAE;QAAE,MAAM,CAAC,KAAK,EAAE,CAAC;KAAE;IAErC,MAAM,UAAU,GAAG,CAAC,GAAuD,EAAE,EAAE;QAE3E,IAAI,MAAM,GAAG,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;QAC3D,IAAI,MAAM,KAAK,SAAS,EAAE;YACtB,QAAQ,GAAG,CAAC,MAAM,EAAE;gBAChB,KAAK,kBAAkB;oBACnB,MAAM,GAAG,WAAW,CAAC;oBACrB,MAAM;gBACV,KAAK,cAAc;oBACf,MAAM,G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M,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;QAChD,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,sBAAsB,CAAC,CAAC;QACxC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,yBAAyB,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/lib.esm/_tests/test-providers-data.d.ts b/lib.esm/_tests/test-providers-data.d.ts new file mode 100644 index 00000000..c9920ec8 --- /dev/null +++ b/lib.esm/_tests/test-providers-data.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=test-providers-data.d.ts.map \ No newline at end of file diff --git a/lib.esm/_tests/test-providers-data.d.ts.map b/lib.esm/_tests/test-providers-data.d.ts.map new file mode 100644 index 00000000..6e857143 --- /dev/null +++ b/lib.esm/_tests/test-providers-data.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"test-providers-data.d.ts","sourceRoot":"","sources":["../../src.ts/_tests/test-providers-data.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/lib.esm/_tests/test-providers-data.js b/lib.esm/_tests/test-providers-data.js new file mode 100644 index 00000000..3d74effd --- /dev/null +++ b/lib.esm/_tests/test-providers-data.js @@ -0,0 +1,326 @@ +import assert from "assert"; +// import { +// checkProvider, getProvider, providerNames +// } from "./create-provider.js"; +// import { retryIt } from "./utils.js"; +//import type { Provider } from "../index.js"; +import { getTxType, quais } from "../index.js"; +import axios from 'axios'; +import { stall } from "./utils.js"; +// import { +// networkFeatureAtBlock, networkNames, +// testAddress, testBlock, testReceipt, testTransaction +// } from "./blockchain-data.js"; +// import type { TestBlockchainNetwork } from "./blockchain-data.js"; +//setupProviders(); +const providerC1 = new quais.JsonRpcProvider(process.env.RPC_URL); +const wallet = new quais.Wallet(process.env.FAUCET_PRIVATEKEY || '', providerC1); +const destinationC1 = '0x0047f9CEa7662C567188D58640ffC48901cde02a'; +const destinationC2 = '0x011ae0a1Bd5B71b4F16F8FdD3AEF278C3D042449'; +function equals(name, actual, expected) { + if (expected && expected.eq) { + if (actual == null) { + assert.ok(false, name + " - actual big number null"); + } + expected = BigInt(expected); + actual = BigInt(actual); + assert.ok(expected.eq(actual), name + " matches"); + } + else if (Array.isArray(expected)) { + if (actual == null) { + assert.ok(false, name + " - actual array null"); + } + assert.equal(actual.length, expected.length, name + " array lengths match"); + for (let i = 0; i < expected.length; i++) { + equals("(" + name + " - item " + i + ")", actual[i], expected[i]); + } + } + else if (typeof (expected) === "object") { + if (actual == null) { + if (expected === actual) { + return; + } + assert.ok(false, name + " - actual object null"); + } + let keys = {}; + Object.keys(expected).forEach((key) => { keys[key] = true; }); + Object.keys(actual).forEach((key) => { keys[key] = true; }); + Object.keys(keys).forEach((key) => { + if (typeof actual[key] === "string" && actual[key].toLowerCase && key === "type") { + actual[key] = actual[key].toLowerCase(); + } + equals("(" + name + " - key + " + key + ")", actual[key], expected[key]); + }); + } + else { + if (actual == null) { + assert.ok(false, name + " - actual null"); + } + // Modify this part for case-insensitive comparison for string values + if (typeof actual === 'string' && typeof expected === 'string') { + assert.equal(actual.toLowerCase(), expected.toLowerCase(), name + " matches (case-insensitive)"); + } + else { + assert.equal(actual, expected, name + " matches"); + } + } +} +async function getRPCGasPrice(url) { + try { + let response; + do { + response = await axios.post(url || "http://localhost:8610", { + jsonrpc: "2.0", + method: "quai_gasPrice", + params: [], + id: 1 + }); + } while (response.data.result == null); + return response.data.result; + } + catch (error) { + throw new Error(`Error fetching block: ${error.message}`); + } +} +async function sendTransaction(to) { + let txResponse; + let typeValue; + try { + console.log("Nonce: ", await providerC1.getTransactionCount(wallet.address, 'latest')); + do { + typeValue = getTxType(wallet.address, to); + const gas = await getRPCGasPrice(process.env.RPC_URL); + let tx = { + from: wallet.address, + to, + value: quais.parseEther("0.1"), + gasPrice: gas * 2, + maxFeePerGas: quais.parseUnits('20', 'gwei'), + maxPriorityFeePerGas: quais.parseUnits('20', 'gwei'), + nonce: await providerC1.getTransactionCount(wallet.address, 'latest'), + data: '', + type: typeValue, + gasLimit: typeValue == 0 ? 21000 : 42000, + chainId: Number(process.env.CHAIN_ID || 1337), + }; + txResponse = await wallet.sendTransaction(tx); + console.log(txResponse); + await stall(15000); + } while (txResponse.hash == null); + console.log(`Transaction hash for type ${typeValue}: `, txResponse.hash); + return txResponse; + } + catch (error) { + console.error('Failed to send Transaction: ', error); + return null; + } +} +async function fetchRPCBlock(blockNumber) { + try { + let response; + do { + response = await axios.post(process.env.RPC_URL || "http://localhost:8610", { + jsonrpc: "2.0", + method: "quai_getBlockByNumber", + params: [ + blockNumber || '0xA', + false + ], + id: 1 + }); + } while (response.data.result.hash == null); + return response.data.result; + } + catch (error) { + throw error; + } +} +async function fetchRPCBalance(address, url) { + try { + let response; + do { + response = await axios.post(url, { + jsonrpc: "2.0", + method: "quai_getBalance", + params: [ + address, + 'latest' + ], + id: 1 + }); + } while (response.data.result == null); + return response.data.result; + } + catch (error) { + throw new Error(`Error fetching block: ${error.message}`); + } +} +async function fetchRPCTxReceipt(hash, url) { + try { + let response; + do { + response = await axios.post(url, { + jsonrpc: "2.0", + method: "quai_getTransactionReceipt", + params: [ + hash + ], + id: 1 + }); + await stall(5000); + } while (response.data.result.blockHash == null); + return response.data.result; + } + catch (error) { + throw new Error(`Error fetching block: ${error.message}`); + } +} +describe("Test Provider Block operations", function () { + let block; + before(async () => { + const rpcBlock = await fetchRPCBlock('0xA'); + block = { + hash: rpcBlock.hash, + number: rpcBlock.number.map((stringNumber) => Number(stringNumber)), + transactions: rpcBlock.transactions, + parentHash: rpcBlock.parentHash, + parentEntropy: rpcBlock.parentEntropy.map((entropy) => BigInt(entropy)), + extTransactions: rpcBlock.extTransactions, + timestamp: Number(rpcBlock.timestamp), + nonce: rpcBlock.nonce, + difficulty: BigInt(rpcBlock.difficulty), + gasLimit: BigInt(rpcBlock.gasLimit), + gasUsed: BigInt(rpcBlock.gasUsed), + miner: rpcBlock.miner, + extraData: rpcBlock.extraData, + transactionsRoot: rpcBlock.transactionsRoot, + evmRoot: rpcBlock.stateRoot, + utxoRoot: rpcBlock.utxoRoot, + receiptsRoot: rpcBlock.receiptsRoot, + baseFeePerGas: BigInt(rpcBlock.baseFeePerGas), + extRollupRoot: rpcBlock.extRollupRoot, + extTransactionsRoot: rpcBlock.extTransactionsRoot, + location: rpcBlock.location, + manifestHash: rpcBlock.manifestHash, + mixHash: rpcBlock.mixHash, + order: rpcBlock.order, + parentDeltaS: rpcBlock.parentDeltaS.map((delta) => BigInt(delta)), + sha3Uncles: rpcBlock.sha3Uncles, + size: BigInt(rpcBlock.size), + uncles: rpcBlock.uncles, + subManifest: rpcBlock.subManifest, + totalEntropy: BigInt(rpcBlock.totalEntropy), + }; + }); + it('should fetch block by number', async function () { + let responseBlock = await providerC1.getBlock('0,0', '0xA'); + assert.ok(responseBlock != null, "block != null"); + let { provider, ...formatBlock } = { + ...responseBlock, + transactions: responseBlock.transactions, + extTransactions: responseBlock.extTransactions + }; + equals("Block by Number", formatBlock, block); + }); + it('should fetch block by hash', async function () { + assert.ok(block.hash != null, 'block.hash != null'); + let responseBlock = await providerC1.getBlock('0,0', block.hash); + assert.ok(responseBlock != null, "block != null"); + let { provider, ...formatBlock } = { + ...responseBlock, + transactions: responseBlock.transactions, + extTransactions: responseBlock.extTransactions + }; + equals("Block by Hash", formatBlock, block); + }); +}); +describe("Test Transaction operations", function () { + let internalTx; + let internalToExternalTx; + it('should fetch balance after internal tx', async function () { + this.timeout(60000); + const oldBal = await fetchRPCBalance(destinationC1, process.env.RPC_URL || "http://localhost:8610"); + internalTx = await sendTransaction(destinationC1); + await stall(30000); + const expectedBal = BigInt(internalTx.value); + const balance = await providerC1.getBalance(destinationC1); + const actualBal = Number(balance) - Number(oldBal); + assert.equal(actualBal, Number(expectedBal)); + }); + it('should get transaction receipt for internal tx', async function () { + this.timeout(60000); + const receipt = await fetchRPCTxReceipt(internalTx.hash, process.env.RPC_URL || "http://localhost:8610"); + const expectedReceipt = { + blockHash: receipt.blockHash, + contractAddress: receipt.contractAddress || null, + blockNumber: Number(receipt.blockNumber), + cumulativeGasUsed: BigInt(receipt.cumulativeGasUsed), + gasPrice: BigInt(receipt.effectiveGasPrice), + etxs: receipt.etxs, + gasUsed: BigInt(receipt.gasUsed), + logs: receipt.logs, + logsBloom: receipt.logsBloom, + status: Number(receipt.status), + to: receipt.to, + from: receipt.from, + hash: receipt.transactionHash, + index: Number(receipt.transactionIndex), + type: receipt.type, + }; + const receiptResponse = await providerC1.getTransactionReceipt(internalTx.hash); + let { provider, ...receiptResult } = { + ...receiptResponse, + logs: receiptResponse?.logs + }; + equals("Internal Tx Receipt", receiptResult, expectedReceipt); + }); + it("should fetch transaction receipt for internal to external tx", async function () { + this.timeout(120000); + internalToExternalTx = await sendTransaction(destinationC2); + await stall(60000); + const receipt = await fetchRPCTxReceipt(internalToExternalTx.hash, process.env.RPC_URL || "http://localhost:8610"); + await stall(30000); + const etx = receipt.etxs[0]; + const expectedReceipt = { + blockHash: receipt.blockHash, + blockNumber: Number(receipt.blockNumber), + contractAddress: receipt.contractAddress || null, + cumulativeGasUsed: BigInt(receipt.cumulativeGasUsed), + gasPrice: BigInt(receipt.effectiveGasPrice), + etxs: [ + { + type: Number(etx.type), + nonce: Number(etx.nonce), + maxPriorityFeePerGas: BigInt(etx.maxPriorityFeePerGas), + maxFeePerGas: BigInt(etx.maxFeePerGas), + gas: BigInt(etx.gas), + value: BigInt(etx.value), + input: etx.input, + to: etx.to, + from: etx.sender, + hash: etx.hash, + chainId: Number(etx.chainId), + accessList: etx.accessList, + } + ], + gasUsed: BigInt(receipt.gasUsed), + logs: receipt.logs, + logsBloom: receipt.logsBloom, + status: Number(receipt.status), + to: receipt.to, + from: receipt.from, + hash: receipt.transactionHash, + index: Number(receipt.transactionIndex), + type: Number(receipt.type), + }; + const receiptResponse = await providerC1.getTransactionReceipt(internalToExternalTx.hash); + let { provider, ...receiptResult } = { + ...receiptResponse, + logs: receiptResponse?.logs + }; + console.log(receiptResult); + console.log(expectedReceipt); + equals("Internal to External Tx Receipt", receiptResult, expectedReceipt); + }); +}); +//# sourceMappingURL=test-providers-data.js.map \ No newline at end of file diff --git a/lib.esm/_tests/test-providers-data.js.map b/lib.esm/_tests/test-providers-data.js.map new file mode 100644 index 00000000..e046003c --- /dev/null +++ b/lib.esm/_tests/test-providers-data.js.map @@ -0,0 +1 @@ +{"version":3,"file":"test-providers-data.js","sourceRoot":"","sources":["../../src.ts/_tests/test-providers-data.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,WAAW;AACX,gDAAgD;AAChD,iCAAiC;AACjC,wCAAwC;AAExC,8CAA8C;AAC9C,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,WAAW;AACX,2CAA2C;AAC3C,2DAA2D;AAC3D,iCAAiC;AAEjC,qEAAqE;AAGrE,mBAAmB;AAGnB,MAAM,UAAU,GAAG,IAAI,KAAK,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AAClE,MAAM,MAAM,GAAG,IAAI,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,IAAI,EAAE,EAAE,UAAU,CAAC,CAAC;AACjF,MAAM,aAAa,GAAG,4CAA4C,CAAA;AAClE,MAAM,aAAa,GAAG,4CAA4C,CAAA;AAElE,SAAS,MAAM,CAAC,IAAY,EAAE,MAAW,EAAE,QAAa;IACpD,IAAI,QAAQ,IAAI,QAAQ,CAAC,EAAE,EAAE;QACzB,IAAI,MAAM,IAAI,IAAI,EAAE;YAAE,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,GAAG,2BAA2B,CAAC,CAAC;SAAE;QAC7E,QAAQ,GAAG,MAAM,CAAC,QAAQ,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,IAAI,EAAE,QAAQ,EAAE,GAAG,aAAa,EAAE,GAAG;YACjC,GAAG,eAAe;YAClB,IAAI,EAAE,eAAe,EAAE,IAAI;SAC9B,CAAC;QACF,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;QAC3B,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAA;QAC5B,MAAM,CAAC,iCAAiC,EAAE,aAAa,EAAE,eAAe,CAAC,CAAC;IAC9E,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAA"} \ No newline at end of file diff --git a/lib.esm/_tests/test-providers-errors.d.ts b/lib.esm/_tests/test-providers-errors.d.ts new file mode 100644 index 00000000..c179d1a2 --- /dev/null +++ b/lib.esm/_tests/test-providers-errors.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=test-providers-errors.d.ts.map \ No newline at end of file diff --git a/lib.esm/_tests/test-providers-errors.d.ts.map b/lib.esm/_tests/test-providers-errors.d.ts.map new file mode 100644 index 00000000..efb4ac1b --- /dev/null +++ b/lib.esm/_tests/test-providers-errors.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"test-providers-errors.d.ts","sourceRoot":"","sources":["../../src.ts/_tests/test-providers-errors.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/lib.esm/_tests/test-providers-errors.js b/lib.esm/_tests/test-providers-errors.js new file mode 100644 index 00000000..89270625 --- /dev/null +++ b/lib.esm/_tests/test-providers-errors.js @@ -0,0 +1,232 @@ +import assert from "assert"; +import { concat, dataSlice, id, toBeArray, zeroPadValue, isCallException, isError, Wallet } from "../index.js"; +import { getProvider, setupProviders, providerNames } from "./create-provider.js"; +import { stall } from "./utils.js"; +//require('dotenv').config(); +import dotenv from "dotenv"; +dotenv.config(); +setupProviders(); +describe("Tests Provider Call Exception", function () { + const panics = [ + //{ code: 0x00, reason: "GENERIC_PANIC" }, + { code: 0x01, reason: "ASSERT_FALSE" }, + { code: 0x11, reason: "OVERFLOW" }, + { code: 0x12, reason: "DIVIDE_BY_ZERO" }, + //{ code: 0x21, reason: "ENUM_RANGE_ERROR" }, + //{ code: 0x22, reason: "BAD_STORAGE_DATA" }, + { code: 0x31, reason: "STACK_UNDERFLOW" }, + { code: 0x32, reason: "ARRAY_RANGE_ERROR" }, + //{ code: 0x41, reason: "OUT_OF_MEMORY" }, + //{ code: 0x51, reason: "UNINITIALIZED_FUNCTION_CALL" }, + ]; + const testAddr = "0x0aff86a125b29b25a9e418c2fb64f1753532c0ca"; //Cyprus1 + const testAddr2 = "0x0aff86a125b29b25a9e418c2fb64f1753532c0ca"; //Cyprus1 + const networkName = "colosseum"; + for (const { code, reason } of panics) { + for (const method of ["call", "estimateGas"]) { + for (const providerName of providerNames) { + const provider = getProvider(providerName, networkName); + if (provider == null) { + continue; + } + it(`tests panic code: ${providerName}.${method}.${reason}`, async function () { + this.timeout(10000); + const data = concat([ + dataSlice(id("testPanic(uint256)"), 0, 4), + zeroPadValue(toBeArray(code), 32) + ]); + await stall(1000); + const tx = { to: testAddr, from: testAddr2, data }; + try { + const result = await (method === "call" ? provider.call(tx) : provider.estimateGas(tx)); + console.log(result); + assert.ok(false, "panic call did not throw"); + } + catch (error) { + assert.ok(isCallException(error), "isCallException"); + // Check some basics + assert.equal(error.action, method, `error.action == ${method}`); + assert.equal(error.reason, `Panic due to ${reason}(${code})`, "error.reason"); + // Check the transaciton + assert.equal(error.transaction.to, tx.to, `error.transaction.to`); + assert.equal(error.transaction.data, tx.data, `error.transaction.data`); + // We have no invocation data + assert.equal(error.invocation, null, `error.invocation != null`); + // Check the revert + assert.ok(error.revert != null, "error.revert == null"); + assert.equal(error.revert.name, "Panic", `error.revert.name`); + assert.equal(error.revert.signature, "Panic(uint256)", `error.revert.signature`); + assert.equal(error.revert.args.length, 1, `error.revert.args.length`); + assert.equal(error.revert.args[0], code, `error.revert.args[0]`); + } + }); + } + } + } + const customErrors = [ + { + name: "CustomError1", + signature: "testCustomError1(bool,uint256,string)", + data: "0xdb7342480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000b68656c6c6f20776f726c64000000000000000000000000000000000000000000", + //data: "0x852d0c740000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000b48656c6c6f20576f726c64000000000000000000000000000000000000000000", + message: `execution reverted (unknown custom error)`, + reason: null, + revert: null, + }, + { + name: "Error", + signature: "testErrorString(bool,string)", + data: "0xb206699b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000b68656c6c6f20776f726c64000000000000000000000000000000000000000000", + //data: "0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000b48656c6c6f20576f726c64000000000000000000000000000000000000000000" + message: `execution reverted: "hello world"`, + reason: "hello world", + revert: { + signature: "Error(string)", + name: "Error", + args: ['hello world'] + } + }, + ]; + for (const { data, message, name, reason, revert } of customErrors) { + for (const method of ["call", "estimateGas"]) { + const tx = { to: testAddr, from: testAddr2, data }; + for (const providerName of providerNames) { + const provider = getProvider(providerName, networkName); + if (provider == null) { + continue; + } + it(`tests custom errors: ${providerName}.${method}.${name}`, async function () { + this.timeout(10000); + try { + const result = await (method === "call" ? provider.call(tx) : provider.estimateGas(tx)); + console.log(result); + assert.ok(false, "panic call did not throw"); + } + catch (error) { + assert.ok(isCallException(error), "isCallException"); + // Check some basics + assert.equal(error.action, method, `error.action == ${method}`); + assert.ok(error.message.startsWith(message), "error.message == message"); + if (reason) { + assert.equal(error.reason, reason, "error.reason"); + } + else { + assert.ok(error.reason == null, "error.reason != null"); + } + if (revert) { + assert.ok(error.revert != null, "error.revert == null"); + assert.equal(error.revert.name, revert.name, "error.revert.name"); + assert.equal(error.revert.signature, revert.signature, "error.revert.signature"); + assert.equal(error.revert.args.length, revert.args.length, "error.revert.args.length"); + for (let i = 0; i < revert.args.length; i++) { + assert.equal(error.revert.args[i], revert.args[i], `error.revert.args[${i}]`); + } + } + else { + assert.ok(error.revert == null, "error.revert != null"); + } + } + }); + } + } + } +}); +describe("Test Provider Blockchain Errors", function () { + const wallet = new Wallet((process.env.FAUCET_PRIVATEKEY)); + const wallet2 = new Wallet((process.env.FAUCET_PRIVATEKEY)); + const networkName = "colosseum"; + for (const providerName of providerNames) { + const provider = getProvider(providerName, networkName); + if (provider == null) { + continue; + } + // The CI runs multiple tests at once; minimize colliding with + // the initial tx by using a random value, so we can detect + // replacements we didn't do. + const value = Math.trunc(Math.random() * 2048) + 2; + it(`tests underpriced replacement transaction: ${providerName}`, async function () { + this.timeout(60000); + const w = wallet.connect(provider); + let tx1 = null; + let nonce = null; + ; + for (let i = 0; i < 10; i++) { + nonce = await w.getNonce("pending"); + try { + tx1 = await w.sendTransaction({ + nonce, to: wallet, from: wallet2, value + }); + } + catch (error) { + // Another CI host beat us to this nonce + if (isError(error, "REPLACEMENT_UNDERPRICED") || isError(error, "NONCE_EXPIRED")) { + await stall(1000); + continue; + } + console.log("EE-tx1", nonce, value, error); + throw error; + } + break; + } + if (tx1 == null || nonce == null) { + throw new Error("could not send initial tx"); + } + const rejection = assert.rejects(async function () { + // Send another tx with the same nonce + const tx2 = await w.sendTransaction({ + nonce, to: wallet, from: wallet2, value: 1 + }); + console.log({ tx1, tx2 }); + }, (error) => { + return isError(error, "REPLACEMENT_UNDERPRICED"); + }); + // Wait for the first tx to get mined so we start with a + // clean slate on the next provider + await tx1.wait(); + // This should have already happened + await rejection; + }); + } + for (const providerName of providerNames) { + const provider = getProvider(providerName, networkName); + if (provider == null) { + continue; + } + it(`tests insufficient funds: ${providerName}`, async function () { + this.timeout(60000); + const w = Wallet.createRandom("m/44'/60'/0'/0/0").connect(provider); + await assert.rejects(async function () { + const tx = await w.sendTransaction({ + to: wallet, from: wallet2, value: 1 + }); + console.log(tx); + }, (error) => { + return (isError(error, "INSUFFICIENT_FUNDS") && + typeof (error.transaction.from) === "string" && + error.transaction.from.toLowerCase() === w.address.toLowerCase()); + }); + }); + } + for (const providerName of providerNames) { + const provider = getProvider(providerName, networkName); + if (provider == null) { + continue; + } + it(`tests nonce expired: ${providerName}`, async function () { + this.timeout(60000); + const w = wallet.connect(provider); + await assert.rejects(async function () { + const tx = await w.sendTransaction({ + to: wallet, from: wallet2, value: 1 + }); + console.log(tx); + }, (error) => { + if (!isError(error, "NONCE_EXPIRED")) { + console.log(error); + } + return isError(error, "NONCE_EXPIRED"); + }); + }); + } +}); +//# sourceMappingURL=test-providers-errors.js.map \ No newline at end of file diff --git a/lib.esm/_tests/test-providers-errors.js.map b/lib.esm/_tests/test-providers-errors.js.map new file mode 100644 index 00000000..ef79323f --- /dev/null +++ b/lib.esm/_tests/test-providers-errors.js.map @@ -0,0 +1 @@ +{"version":3,"file":"test-providers-errors.js","sourceRoot":"","sources":["../../src.ts/_tests/test-providers-errors.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EACH,MAAM,EAAE,SAAS,EAAE,EAAE,EAAE,SAAS,EAAE,YAAY,EAC9C,eAAe,EAAE,OAAO,EACxB,MAAM,EACT,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAClF,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAGnC,6BAA6B;AAC7B,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,MAAM,CAAC,MAAM,EAAE,CAAC;AAehB,cAAc,EAAE,CAAC;AAEjB,QAAQ,CAAC,+BAA+B,EAAE;IAEtC,MAAM,MAAM,GAA4C;QACpD,0CAA0C;QAC1C,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,cAAc,EAAE;QACtC,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE;QAClC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,EAAE,CAAC,CAAC;YAC1E,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;KACN;IAED,KAAK,MAAM,YAAY,IAAI,aAAa,EAAE;QAEtC,MAAM,QAAQ,GAAG,WAAW,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC;QACxD,IAAI,QAAQ,IAAI,IAAI,EAAE;YAAE,SAAS;SAAE;QAEnC,EAAE,CAAC,wBAAyB,YAAa,EAAE,EAAE,KAAK;YAC9C,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAEpB,MAAM,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YAEnC,MAAM,MAAM,CAAC,OAAO,CAAC,KAAK;gBACtB,MAAM,EAAE,GAAG,MAAM,CAAC,CAAC,eAAe,CAAC;oBAC/B,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;iBACtC,CAAC,CAAC;gBACH,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YACpB,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE;gBACT,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,eAAe,CAAC,EAAE;oBAClC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;iBACtB;gBACD,OAAO,OAAO,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC;YAC3C,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;KACN;AAEL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/lib.esm/_tests/test-providers-fallback.d.ts b/lib.esm/_tests/test-providers-fallback.d.ts new file mode 100644 index 00000000..6b3b554a --- /dev/null +++ b/lib.esm/_tests/test-providers-fallback.d.ts @@ -0,0 +1,10 @@ +import { AbstractProvider, Network } from "../index.js"; +import type { PerformActionRequest } from "../index.js"; +export type Performer = (req: PerformActionRequest) => Promise; +export declare class MockProvider extends AbstractProvider { + readonly _perform: Performer; + constructor(perform: Performer); + _detectNetwork(): Promise; + perform(req: PerformActionRequest): Promise; +} +//# sourceMappingURL=test-providers-fallback.d.ts.map \ No newline at end of file diff --git a/lib.esm/_tests/test-providers-fallback.d.ts.map b/lib.esm/_tests/test-providers-fallback.d.ts.map new file mode 100644 index 00000000..b3469193 --- /dev/null +++ b/lib.esm/_tests/test-providers-fallback.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"test-providers-fallback.d.ts","sourceRoot":"","sources":["../../src.ts/_tests/test-providers-fallback.ts"],"names":[],"mappings":"AAEA,OAAO,EAGH,gBAAgB,EAAoB,OAAO,EAC9C,MAAM,aAAa,CAAC;AAErB,OAAO,KAAK,EACR,oBAAoB,EACvB,MAAM,aAAa,CAAC;AAWrB,MAAM,MAAM,SAAS,GAAG,CAAC,GAAG,EAAE,oBAAoB,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;AAEpE,qBAAa,YAAa,SAAQ,gBAAgB;IAC9C,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;gBAEjB,OAAO,EAAE,SAAS;IAKxB,cAAc,IAAI,OAAO,CAAC,OAAO,CAAC;IAElC,OAAO,CAAC,GAAG,EAAE,oBAAoB,GAAG,OAAO,CAAC,GAAG,CAAC;CAGzD"} \ No newline at end of file diff --git a/lib.esm/_tests/test-providers-fallback.js b/lib.esm/_tests/test-providers-fallback.js new file mode 100644 index 00000000..0f1f5acc --- /dev/null +++ b/lib.esm/_tests/test-providers-fallback.js @@ -0,0 +1,64 @@ +import assert from "assert"; +import { isError, makeError, AbstractProvider, FallbackProvider, Network } from "../index.js"; +const network = Network.from("mainnet"); +function stall(duration) { + return new Promise((resolve) => { setTimeout(resolve, duration); }); +} +export class MockProvider extends AbstractProvider { + _perform; + constructor(perform) { + super(network, { cacheTimeout: -1 }); + this._perform = perform; + } + async _detectNetwork() { return network; } + async perform(req) { + return await this._perform(req); + } +} +describe("Test Fallback broadcast", function () { + const txHash = "0xe9fb92945282cf04f7bb3027d690fdaab6d601c99a7cdd0a5eb41d1a5c0893d5"; + async function test(actions) { + const tx = "0x00f8788223288202898504a817c8008504a817c800825208940aff86a125b29b25a9e418c2fb64f1753532c0ca88016345785d8a000080c001a0711d47f0f6828721f336430ca87277534d0134de5f04ce3629085f8d5371c129a061c4838dec40c296cfad6fe771d502c26e209089124e6f702c64353b3ca195c1"; + const providers = actions.map(({ timeout, error }) => { + return new MockProvider(async (r) => { + if (r.method === "getBlockNumber") { + return 1; + } + if (r.method === "broadcastTransaction") { + await stall(timeout); + if (error) { + throw error; + } + return txHash; + } + throw new Error(`unhandled method: ${r.method}`); + }); + }); + ; + const provider = new FallbackProvider(providers); + return await provider.broadcastTransaction('0,1', tx); + } + it("picks late non-failed broadcasts", async function () { + const result = await test([ + { timeout: 200, error: makeError("already seen", "UNKNOWN_ERROR") }, + { timeout: 4000, error: makeError("already seen", "UNKNOWN_ERROR") }, + { timeout: 400 }, + ]); + assert(result.hash === txHash, "result.hash === txHash"); + }); + it("insufficient funds short-circuit broadcast", async function () { + await assert.rejects(async function () { + const result = await test([ + { timeout: 200, error: makeError("is broke", "INSUFFICIENT_FUNDS") }, + { timeout: 400, error: makeError("is broke", "INSUFFICIENT_FUNDS") }, + { timeout: 800 }, + { timeout: 1000 }, + ]); + console.log(result); + }, function (error) { + assert(isError(error, "INSUFFICIENT_FUNDS")); + return true; + }); + }); +}); +//# sourceMappingURL=test-providers-fallback.js.map \ No newline at end of file diff --git a/lib.esm/_tests/test-providers-fallback.js.map b/lib.esm/_tests/test-providers-fallback.js.map new file mode 100644 index 00000000..980cc260 --- /dev/null +++ b/lib.esm/_tests/test-providers-fallback.js.map @@ -0,0 +1 @@ +{"version":3,"file":"test-providers-fallback.js","sourceRoot":"","sources":["../../src.ts/_tests/test-providers-fallback.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EACH,OAAO,EAAE,SAAS,EAElB,gBAAgB,EAAE,gBAAgB,EAAE,OAAO,EAC9C,MAAM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CAAC,CAAC;YAC7C,OAAO,IAAI,CAAC;QAChB,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/lib.esm/_tests/test-rlp.d.ts b/lib.esm/_tests/test-rlp.d.ts new file mode 100644 index 00000000..2a353b71 --- /dev/null +++ b/lib.esm/_tests/test-rlp.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=test-rlp.d.ts.map \ No newline at end of file diff --git a/lib.esm/_tests/test-rlp.d.ts.map b/lib.esm/_tests/test-rlp.d.ts.map new file mode 100644 index 00000000..106a294c --- /dev/null +++ b/lib.esm/_tests/test-rlp.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"test-rlp.d.ts","sourceRoot":"","sources":["../../src.ts/_tests/test-rlp.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/src.ts/_tests/test-rlp.ts b/lib.esm/_tests/test-rlp.js similarity index 72% rename from src.ts/_tests/test-rlp.ts rename to lib.esm/_tests/test-rlp.js index 9c02dbda..d83e3b5e 100644 --- a/src.ts/_tests/test-rlp.ts +++ b/lib.esm/_tests/test-rlp.js @@ -1,90 +1,76 @@ import assert from "assert"; - import { loadTests } from "./utils.js"; - import { decodeRlp, encodeRlp, hexlify } from "../index.js"; - -import type { TestCaseRlp } from "./types.js"; - -describe("Test RLP Coder", function() { - - const tests = loadTests("rlp"); - +describe("Test RLP Coder", function () { + const tests = loadTests("rlp"); tests.forEach(({ name, encoded, decoded }) => { - it(`encodes RLP: ${ name }`, function() { + it(`encodes RLP: ${name}`, function () { assert.equal(encodeRlp(decoded), encoded); }); }); - tests.forEach(({ name, encoded, decoded }) => { - it(`decodes RLP: ${ name }`, function() { + it(`decodes RLP: ${name}`, function () { assert.deepEqual(decodeRlp(encoded), decoded); }); }); }); - -describe("Test bad RLP Data", function() { - it("correctly fails encoding data with invalid values", function() { +describe("Test bad RLP Data", function () { + it("correctly fails encoding data with invalid values", function () { assert.throws(() => { - encodeRlp([ "0x1234", 1234 ]); - }, (error: any) => { + encodeRlp(["0x1234", 1234]); + }, (error) => { return (error.code === "INVALID_ARGUMENT" && error.argument === "object" && - error.value === 1234) + error.value === 1234); }); }); - - it("correctlyfails decoding data with trailing junk", function() { + it("correctlyfails decoding data with trailing junk", function () { assert.throws(() => { // Zeros_1 decodeRlp("0x0042"); - }, (error: any) => { + }, (error) => { return (error.code === "INVALID_ARGUMENT" && error.message.match(/^unexpected junk after rlp payload/) && error.argument === "data" && - error.value === "0x0042") + error.value === "0x0042"); }); }); - - it ("correctlyfails decoding short data", function() { + it("correctlyfails decoding short data", function () { assert.throws(() => { decodeRlp("0x"); - }, (error: any) => { + }, (error) => { return (error.code === "BUFFER_OVERRUN" && error.message.match(/^data too short/) && hexlify(error.buffer) === "0x" && error.offset === 1 && - error.length === 0) + error.length === 0); }); }); - - it ("correctlyfails decoding short data in child", function() { + it("correctlyfails decoding short data in child", function () { assert.throws(() => { decodeRlp("0xc8880102030405060708"); - }, (error: any) => { + }, (error) => { return (error.code === "BUFFER_OVERRUN" && error.message.match(/^child data too short/) && hexlify(error.buffer) === "0xc8880102030405060708" && error.offset === 0 && - error.length === 8) + error.length === 8); }); }); - - it ("correctlyfails decoding short segment data", function() { + it("correctlyfails decoding short segment data", function () { assert.throws(() => { // [["0x4243"], ["0x3145"]] = 0xc8 c3 82 4243 c3 82 3145 // XXXX decodeRlp("0xc8c382c3823145"); - }, (error: any) => { + }, (error) => { return (error.code === "BUFFER_OVERRUN" && error.message.match(/^data short segment too short/) && hexlify(error.buffer) === "0xc8c382c3823145" && error.offset === 9 && - error.length === 7) + error.length === 7); }); }); }); - /* utils.RLP.encode([["0x4243"], ["0x3145"]]) @@ -99,3 +85,4 @@ describe("Test bad RLP Data", function() { "encoded": "0xd8 8b 48656c6c6f20576f726c64 8b 48656c6c6f20576f726c64" }, */ +//# sourceMappingURL=test-rlp.js.map \ No newline at end of file diff --git a/lib.esm/_tests/test-rlp.js.map b/lib.esm/_tests/test-rlp.js.map new file mode 100644 index 00000000..7a00597b --- /dev/null +++ b/lib.esm/_tests/test-rlp.js.map @@ -0,0 +1 @@ +{"version":3,"file":"test-rlp.js","sourceRoot":"","sources":["../../src.ts/_tests/test-rlp.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAI5D,QAAQ,CAAC,gBAAgB,EAAE;IAEvB,MAAM,KAAK,GAAG,SAAS,CAAc,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,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,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,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC;QAClD,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,mBAAmB,EAAE;IAC1B,EAAE,CAAC,mDAAmD,EAAE;QACpD,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE;YACf,SAAS,CAAC,CAAE,QAAQ,EAAmB,IAAI,CAAE,CAAC,CAAC;QACnD,CAAC,EAAE,CAAC,KAAU,EAAE,EAAE;YACd,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,kBAAkB;gB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K,CAAC,uBAAuB,CAAC;gBAC5C,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,wBAAwB;gBAClD,KAAK,CAAC,MAAM,KAAK,CAAC;gBAClB,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAA;QAC3B,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,EAAE,CAAE,4CAA4C,EAAE;QAC9C,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE;YACf,wDAAwD;YACxD,6CAA6C;YAC7C,SAAS,CAAC,kBAAkB,CAAC,CAAC;QAClC,CAAC,EAAE,CAAC,KAAU,EAAE,EAAE;YACd,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,gBAAgB;gBACnC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,+BAA+B,CAAC;gBACpD,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,kBAAkB;gBAC5C,KAAK,CAAC,MAAM,KAAK,CAAC;gBAClB,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAA;QAC3B,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC;AAEH;;;;;;;;;;;;;EAaE"} \ No newline at end of file diff --git a/lib.esm/_tests/test-transaction.d.ts b/lib.esm/_tests/test-transaction.d.ts new file mode 100644 index 00000000..5da54786 --- /dev/null +++ b/lib.esm/_tests/test-transaction.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=test-transaction.d.ts.map \ No newline at end of file diff --git a/lib.esm/_tests/test-transaction.d.ts.map b/lib.esm/_tests/test-transaction.d.ts.map new file mode 100644 index 00000000..0570265f --- /dev/null +++ b/lib.esm/_tests/test-transaction.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"test-transaction.d.ts","sourceRoot":"","sources":["../../src.ts/_tests/test-transaction.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/lib.esm/_tests/test-transaction.js b/lib.esm/_tests/test-transaction.js new file mode 100644 index 00000000..652bcef5 --- /dev/null +++ b/lib.esm/_tests/test-transaction.js @@ -0,0 +1,167 @@ +import assert from "assert"; +import { loadTests } from "./utils.js"; +import { isError, Transaction } from "../index.js"; +const BN_0 = BigInt(0); +describe("Tests Unsigned Transaction Serializing", function () { + const tests = loadTests("transactions"); + 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 = Transaction.from(txData); + assert.equal(tx.unsignedSerialized, test.unsignedEip155, "unsignedEip155"); + }); + } +}); +describe("Tests Signed Transaction Serializing", function () { + const tests = loadTests("transactions"); + 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: [], + maxFeePerGas: 0, + maxPriorityFeePerGas: 0, + signature: test.signatureEip155 + }); + const tx = Transaction.from(txData); + assert.equal(tx.serialized, test.signedEip155, "signedEip155"); + }); + } +}); +function assertTxUint(actual, _expected, name) { + const expected = (_expected != null ? BigInt(_expected) : null); + assert.equal(actual, expected, name); +} +function assertTxEqual(actual, expected) { + assert.equal(actual.to, expected.to, "to"); + assert.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.equal(actual.data, expected.data, "data"); + assertTxUint(actual.value, expected.value, "value"); + if (expected.accessList) { + assert.equal(JSON.stringify(actual.accessList), JSON.stringify(expected.accessList), "accessList"); + } + else { + assert.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, "maxFeePerGas", BN_0); + addDefault(tx, "maxPriorityFeePerGas", BN_0); + addDefault(tx, "value", 0); + addDefault(tx, "data", "0x"); + addDefault(tx, "accessList", []); + addDefault(tx, "chainId", BN_0); + return tx; +} +describe("Tests Unsigned Transaction Parsing", function () { + const tests = loadTests("transactions"); + for (const test of tests) { + if (!test.unsignedEip155) { + continue; + } + it(`parses unsigned EIP-155 transaction: ${test.name}`, function () { + const tx = Transaction.from(test.unsignedEip155); + const expected = addDefaults(test.transaction); + expected.maxFeePerGas = 0; + expected.maxPriorityFeePerGas = 0; + expected.accessList = []; + assertTxEqual(tx, expected); + }); + } +}); +describe("Tests Signed Transaction Parsing", function () { + const tests = loadTests("transactions"); + for (const test of tests) { + if (!test.unsignedEip155) { + continue; + } + it(`parses signed EIP-155 transaction: ${test.name}`, function () { + let tx = Transaction.from(test.signedEip155); + const expected = addDefaults(test.transaction); + expected.maxFeePerGas = 0; + expected.maxPriorityFeePerGas = 0; + expected.accessList = []; + for (let i = 0; i < 2; i++) { + assertTxEqual(tx, expected); + assert.ok(!!tx.signature, "signature:!null"); + assert.equal(tx.signature.r, test.signatureEip155.r, "signature.r"); + assert.equal(tx.signature.s, test.signatureEip155.s, "signature.s"); + tx = tx.clone(); + } + }); + } +}); +describe("Tests Transaction Parameters", function () { + const badData = [ + { + name: "accessList=0x09", + data: "0x00c9010203040580070809", + message: "invalid access list", + argument: "accessList" + }, + { + name: "accessList=[0x09]", + data: "0x00ca0102030405800708c109", + message: "invalid address-slot set", + argument: "accessList" + }, + { + name: "accessList=[0x09,0x10]", + data: "0x00cb0102030405800708c20910", + message: "invalid address-slot set", + argument: "accessList" + }, + { + name: "accessList=[0x09,[HASH]] (bad address)", + data: "0x00ed0102030405800708e4e309e1a024412927c99a717115f5308c0ebd11136659b3cb6291abb4a8f87e9856a12538", + message: "invalid address", + argument: "accessList" + }, + { + name: "accessList=[ADDR,[0x09]] (bad slot)", + data: "0x00e10102030405800708d8d794939d33ff01840e9eeeb67525ec2f7035af41a4b1c109", + message: "invalid slot", + argument: "accessList" + } + ]; + for (const { name, data, argument, message } of badData) { + it(`correctly fails on bad accessList: ${name}`, function () { + assert.throws(() => { + // The access list is a single value: 0x09 instead of + // structured data + const result = Transaction.from(data); + console.log(result); + }, (error) => { + return (isError(error, "INVALID_ARGUMENT") && + error.argument === argument && + (message == null || error.message.startsWith(message))); + }); + }); + } +}); +//# sourceMappingURL=test-transaction.js.map \ No newline at end of file diff --git a/lib.esm/_tests/test-transaction.js.map b/lib.esm/_tests/test-transaction.js.map new file mode 100644 index 00000000..9bbcabfc --- /dev/null +++ b/lib.esm/_tests/test-transaction.js.map @@ -0,0 +1 @@ +{"version":3,"file":"test-transaction.js","sourceRoot":"","sources":["../../src.ts/_tests/test-transaction.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAGvC,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAGnD,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;AAEvB,QAAQ,CAAC,wCAAwC,EAAE;IAC/C,MAAM,KAAK,GAAG,SAAS,CAAsB,cAAc,CAAC,CAAA;IAE5D,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;QACtB,gEAAgE;QAChE,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE;YAAE,SAAS;SAAE;QACvC,EAAE,CAAC,4CAA6C,IAAI,CAAC,IAAK,EAAE,EAAE;YAC1D,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,EAAG,EAAE,IAAI,C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AC3B,CAAC,OAAO,IAAI,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YAChE,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;KAEN;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/lib.esm/_tests/test-utils-maths.d.ts b/lib.esm/_tests/test-utils-maths.d.ts new file mode 100644 index 00000000..af3decaf --- /dev/null +++ b/lib.esm/_tests/test-utils-maths.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=test-utils-maths.d.ts.map \ No newline at end of file diff --git a/lib.esm/_tests/test-utils-maths.d.ts.map b/lib.esm/_tests/test-utils-maths.d.ts.map new file mode 100644 index 00000000..b8c57056 --- /dev/null +++ b/lib.esm/_tests/test-utils-maths.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"test-utils-maths.d.ts","sourceRoot":"","sources":["../../src.ts/_tests/test-utils-maths.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/lib.esm/_tests/test-utils-maths.js b/lib.esm/_tests/test-utils-maths.js new file mode 100644 index 00000000..b237c1a2 --- /dev/null +++ b/lib.esm/_tests/test-utils-maths.js @@ -0,0 +1,189 @@ +import assert from "assert"; +import { isError, fromTwos, toTwos, getBigInt, getNumber, toBeArray, toBeHex, toQuantity, } from "../index.js"; +describe("Tests Quantity Functions", function () { + const quantities = [ + { + name: "zero number", + value: 0, + expected: "0x0" + }, + { + name: "zero single hex", + value: "0x0", + expected: "0x0" + }, + { + name: "zero double hex", + value: "0x00", + expected: "0x0" + }, + { + name: "zero array(0)", + value: new Uint8Array([]), + expected: "0x0" + }, + { + name: "zero array(1)", + value: new Uint8Array([0]), + expected: "0x0" + }, + { + name: "single hex digit", + value: 0x5, + expected: "0x5" + }, + { + name: "double hex digit", + value: 0x42, + expected: "0x42" + }, + { + name: "big array, odd output", + value: new Uint8Array([0x0f, 254, 253, 252]), + expected: "0xffefdfc" + }, + { + name: "big array, even output", + value: new Uint8Array([255, 254, 253, 252]), + expected: "0xfffefdfc" + }, + ]; + for (const { name, value, expected } of quantities) { + it(`computes quantity: ${name}`, function () { + assert.equal(toQuantity(value), expected); + }); + } +}); +describe("Tests Bad Math Values", function () { + const badBigInts = [ + { + name: "empty string", + value: "", + error: "invalid BigNumberish string" + }, + { + name: "non-numeric string", + value: "foobar", + error: "invalid BigNumberish string" + }, + { + name: "double negative sign", + value: "--42", + error: "invalid BigNumberish string" + }, + { + name: "non-numeric thing", + value: true, + error: "invalid BigNumberish value" + }, + ]; + for (const { name, value, error } of badBigInts) { + it(`correctly fails on bad bigint: ${name}`, function () { + assert.throws(() => { + const result = getBigInt(value); + console.log(result); + }, (e) => { + return (isError(e, "INVALID_ARGUMENT") && + e.message.startsWith(error)); + }); + }); + } + const badNumbers = [ + { + name: "empty string", + value: "", + error: "invalid numeric string" + }, + { + name: "non-numeric string", + value: "foobar", + error: "invalid numeric string" + }, + { + name: "double negative sign", + value: "--42", + error: "invalid numeric string" + }, + { + name: "non-numeric thing", + value: true, + error: "invalid numeric value" + }, + { + name: "too big", + value: Number.MAX_SAFE_INTEGER + 10, + error: "overflow" + }, + { + name: "too small", + value: -Number.MAX_SAFE_INTEGER - 10, + error: "overflow" + }, + ]; + for (const { name, value, error } of badNumbers) { + it(`correctly fails on bad numeric: ${name}`, function () { + assert.throws(() => { + const result = getNumber(value); + console.log(result); + }, (e) => { + return (isError(e, "INVALID_ARGUMENT") && + e.message.startsWith(error)); + }); + }); + } + const badHex = [ + { + name: "negative value", + value: -4, + error: "unsigned value cannot be negative" + }, + { + name: "width too short", + value: 0x123456, + width: 2, + error: "value exceeds width" + }, + ]; + for (const { name, value, error, width } of badHex) { + it(`correctly fails on bad toBeHex values: ${name}`, function () { + assert.throws(() => { + const result = toBeHex(value, width); + console.log(result); + }, (e) => { + return (isError(e, "NUMERIC_FAULT") && e.fault === "overflow" && + e.message.startsWith(error)); + }); + }); + } + it(`correctly fails on nad toBeArray values: negative value`, function () { + assert.throws(() => { + const result = toBeArray(-4); + console.log(result); + }, (e) => { + return (isError(e, "NUMERIC_FAULT") && e.fault === "overflow" && + e.message.startsWith("unsigned value cannot be negative")); + }); + }); +}); +describe("Tests Twos Compliemnts Functions", function () { + const tests = [ + { width: 8, value: 0, twos: 0 }, + { width: 8, value: 1, twos: 1 }, + { width: 8, value: -1, twos: 0xff }, + { width: 8, value: 127, twos: 127 }, + { width: 8, value: -128, twos: 0x80 }, + ]; + for (const { twos, width, value } of tests) { + it(`computes twos compliment values: ${value}[${width} bits]`, function () { + const result = toTwos(value, width); + assert.equal(result, twos); + }); + } + for (const { twos, width, value } of tests) { + it(`computes values from twos compliment: ${value}[${width} bits]`, function () { + const result = fromTwos(twos, width); + assert.equal(result, value); + }); + } +}); +//# sourceMappingURL=test-utils-maths.js.map \ No newline at end of file diff --git a/lib.esm/_tests/test-utils-maths.js.map b/lib.esm/_tests/test-utils-maths.js.map new file mode 100644 index 00000000..c9274912 --- /dev/null +++ b/lib.esm/_tests/test-utils-maths.js.map @@ -0,0 +1 @@ +{"version":3,"file":"test-utils-maths.js","sourceRoot":"","sources":["../../src.ts/_tests/test-utils-maths.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EACH,OAAO,EACP,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,GACvD,MAAM,aAAa,CAAC;AAErB,QAAQ,CAAC,0BAA0B,EAAE;IACjC,MAAM,UAAU,GAA0D;QACtE;YACI,IAAI,EAAE,aAAa;YACnB,KAAK,EAAE,CAAC;YACR,QAAQ,EAAE,KAAK;SAClB;QACD;YACI,IAAI,EAAE,iBAAiB;YACvB,KAAK,EAAE,KAAK;YACZ,QAAQ,EAAE,KAAK;SAClB;QACD;YACI,IAAI,EAAE,iBAAiB;YACvB,KAAK,EAAE,MAAM;YACb,QAAQ,EAAE,KAAK;SAClB;QACD;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,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAC/B,CAAC,CAAC,CAAC;KACN;IAED,KAAK,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,KAAK,EAAE;QACxC,EAAE,CAAC,yCAA0C,KAAM,IAAK,KAAM,QAAQ,EAAE;YACpE,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;YACrC,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAChC,CAAC,CAAC,CAAC;KACN;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/lib.esm/_tests/test-utils-misc.d.ts b/lib.esm/_tests/test-utils-misc.d.ts new file mode 100644 index 00000000..db713523 --- /dev/null +++ b/lib.esm/_tests/test-utils-misc.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=test-utils-misc.d.ts.map \ No newline at end of file diff --git a/lib.esm/_tests/test-utils-misc.d.ts.map b/lib.esm/_tests/test-utils-misc.d.ts.map new file mode 100644 index 00000000..4bc46ddc --- /dev/null +++ b/lib.esm/_tests/test-utils-misc.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"test-utils-misc.d.ts","sourceRoot":"","sources":["../../src.ts/_tests/test-utils-misc.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/lib.esm/_tests/test-utils-misc.js b/lib.esm/_tests/test-utils-misc.js new file mode 100644 index 00000000..0fd005e2 --- /dev/null +++ b/lib.esm/_tests/test-utils-misc.js @@ -0,0 +1,62 @@ +import assert from "assert"; +import { decodeBase64, encodeBase64, defineProperties, isError, toUtf8Bytes } from "../index.js"; +describe("Base64 Coding", function () { + const tests = [ + { + name: "wikipedia", + plaintext: toUtf8Bytes("Many hands make light work."), + encoded: "TWFueSBoYW5kcyBtYWtlIGxpZ2h0IHdvcmsu" + } + ]; + for (const test of tests) { + it(`encodes base64: ${test.name}`, function () { + assert.equal(encodeBase64(test.plaintext), test.encoded); + }); + } + for (const test of tests) { + it(`decodes base64: ${test.name}`, function () { + const decoded = decodeBase64(test.encoded); + assert.equal(decoded.length, test.plaintext.length, "data.length"); + for (let i = 0; i < decoded.length; i++) { + assert.equal(decoded[i], test.plaintext[i]); + } + }); + } +}); +describe("Test Minor Features", function () { + it("checks types in defineProperties", function () { + const any = {}; + const values = { + vAny: any, + vBigint: BigInt(60), + vBoolean: true, + vNumber: 42, + vString: "some string", + }; + const item = {}; + defineProperties(item, values, { + vAny: "any", + vBigint: "bigint", + vBoolean: "boolean", + vNumber: "number", + vString: "string" + }); + assert.equal(item.vAny, any, "vAny"); + assert.equal(item.vBoolean, true, "vBoolenay"); + assert.equal(item.vNumber, 42, "nNumber"); + assert.equal(item.vString, "some string", "any"); + }); + it("correctly throws if defineProperty type mismatch", function () { + assert.throws(() => { + const item = {}; + const values = { vBoolean: 42 }; + defineProperties(item, values, { vBoolean: "boolean" }); + console.log(values); + }, (error) => { + return (isError(error, "INVALID_ARGUMENT") && + error.argument === "value.vBoolean" && + error.value === 42); + }); + }); +}); +//# sourceMappingURL=test-utils-misc.js.map \ No newline at end of file diff --git a/lib.esm/_tests/test-utils-misc.js.map b/lib.esm/_tests/test-utils-misc.js.map new file mode 100644 index 00000000..1ab62bba --- /dev/null +++ b/lib.esm/_tests/test-utils-misc.js.map @@ -0,0 +1 @@ +{"version":3,"file":"test-utils-misc.js","sourceRoot":"","sources":["../../src.ts/_tests/test-utils-misc.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EACH,YAAY,EAAE,YAAY,EAC1B,gBAAgB,EAAE,OAAO,EACzB,WAAW,EACd,MAAM,aAAa,CAAC;AAGrB,QAAQ,CAAC,eAAe,EAAE;IACtB,MAAM,KAAK,GAAG;QACV;YACI,IAAI,EAAE,WAAW;YACjB,SAAS,EAAE,WAAW,CAAC,6BAA6B,CAAC;YACrD,OAAO,EAAE,sCAAsC;S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E,QAAQ;YACjB,OAAO,EAAE,QAAQ;SACpB,CAAC,CAAC;QAEH,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;QACrC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;QAC/C,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,EAAE,SAAS,CAAC,CAAC;QAC1C,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,aAAa,EAAE,KAAK,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,kDAAkD,EAAE;QACnD,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE;YACf,MAAM,IAAI,GAAQ,EAAG,CAAC;YAEtB,MAAM,MAAM,GAAG,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;YAChC,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAC;YAExD,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACxB,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE;YACT,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,kBAAkB,CAAC;gBACtC,KAAK,CAAC,QAAQ,KAAK,gBAAgB;gBACnC,KAAK,CAAC,KAAK,KAAK,EAAE,CAAC,CAAC;QAC5B,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/lib.esm/_tests/test-utils-units.d.ts b/lib.esm/_tests/test-utils-units.d.ts new file mode 100644 index 00000000..989039c0 --- /dev/null +++ b/lib.esm/_tests/test-utils-units.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=test-utils-units.d.ts.map \ No newline at end of file diff --git a/lib.esm/_tests/test-utils-units.d.ts.map b/lib.esm/_tests/test-utils-units.d.ts.map new file mode 100644 index 00000000..4d2654fd --- /dev/null +++ b/lib.esm/_tests/test-utils-units.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"test-utils-units.d.ts","sourceRoot":"","sources":["../../src.ts/_tests/test-utils-units.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/lib.esm/_tests/test-utils-units.js b/lib.esm/_tests/test-utils-units.js new file mode 100644 index 00000000..114a1e03 --- /dev/null +++ b/lib.esm/_tests/test-utils-units.js @@ -0,0 +1,63 @@ +import assert from "assert"; +import { loadTests } from "./utils.js"; +import { formatEther, formatUnits, parseEther, parseUnits } from "../index.js"; +describe("Tests unit conversion", function () { + const tests = loadTests("units"); + const units = [ + { unit: "ether", format: "ether_format", decimals: 18 }, + { unit: "kwei", format: "kwei_format", decimals: 3 }, + { unit: "mwei", format: "mwei_format", decimals: 6 }, + { unit: "gwei", format: "gwei_format", decimals: 9 }, + { unit: "szabo", format: "szabo_format", decimals: 12 }, + { unit: "finney", format: "finney_format", decimals: 15 }, + ]; + for (const { unit, format, decimals } of units) { + for (const test of tests) { + const str = (test[format]); + if (str == null) { + continue; + } + it(`converts wei to ${unit} string: ${test.name}`, function () { + const wei = BigInt(test.wei); + if (decimals === 18) { + assert.equal(formatEther(wei), str, "formatEther"); + assert.equal(formatUnits(wei), str, "formatUnits"); + } + assert.equal(formatUnits(wei, unit), str, `formatUnits(${unit})`); + assert.equal(formatUnits(wei, decimals), str, `formatUnits(${decimals})`); + }); + } + for (const test of tests) { + const str = (test[format]); + if (str == null) { + continue; + } + it(`converts ${format} string to wei: ${test.name}`, function () { + const wei = BigInt(test.wei); + if (decimals === 18) { + assert.equal(parseEther(str), wei, "parseEther"); + assert.equal(parseUnits(str), wei, "parseUnits"); + } + assert.equal(parseUnits(str, unit), wei, `parseUnits(${unit})`); + assert.equal(parseUnits(str, decimals), wei, `parseUnits(${decimals})`); + }); + } + } +}); +describe("Tests bad unit conversion", function () { + it("correctly fails to convert non-string value", function () { + assert.throws(() => { + parseUnits(3, "ether"); + }, (error) => { + return error.message.startsWith("value must be a string"); + }); + }); + it("correctly fails to convert unknown unit", function () { + assert.throws(() => { + parseUnits("3", "foobar"); + }, (error) => { + return error.message.startsWith("invalid unit"); + }); + }); +}); +//# sourceMappingURL=test-utils-units.js.map \ No newline at end of file diff --git a/lib.esm/_tests/test-utils-units.js.map b/lib.esm/_tests/test-utils-units.js.map new file mode 100644 index 00000000..91609190 --- /dev/null +++ b/lib.esm/_tests/test-utils-units.js.map @@ -0,0 +1 @@ +{"version":3,"file":"test-utils-units.js","sourceRoot":"","sources":["../../src.ts/_tests/test-utils-units.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAK/E,QAAQ,CAAC,uBAAuB,EAAE;IAC9B,MAAM,KAAK,GAAG,SAAS,CAAe,OAAO,CAAC,CAAC;IAE/C,MAAM,KAAK,GAAG;QACV,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,EAAE,EAAE;QACvD,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,EAAE;QACpD,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,EAAE;QACpD,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,EAAE;QACpD,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,EAAE,EAAE;QACvD,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,eAAe,EAAE,QAAQ,EAAE,EAAE,EAAE;KAC5D,CAAC;IAE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AAK,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,YAAY,CAAC,CAAC;oBACjD,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,YAAY,CAAC,CAAC;iBACpD;gBACD,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,cAAe,IAAK,GAAG,CAAC,CAAC;gBAClE,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,QAAQ,CAAC,EAAE,GAAG,EAAE,cAAe,QAAS,GAAG,CAAC,CAAC;YAC9E,CAAC,CAAC,CAAC;SACN;KAEJ;AACL,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,2BAA2B,EAAE;IAClC,EAAE,CAAC,6CAA6C,EAAE;QAC9C,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE;YACf,UAAU,CAAM,CAAC,EAAE,OAAO,CAAC,CAAC;QAChC,CAAC,EAAE,CAAC,KAAU,EAAE,EAAE;YACd,OAAO,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,wBAAwB,CAAC,CAAC;QAC9D,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yCAAyC,EAAE;QAC1C,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE;YACf,UAAU,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;QAC9B,CAAC,EAAE,CAAC,KAAU,EAAE,EAAE;YACd,OAAO,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/lib.esm/_tests/test-utils-utf8.d.ts b/lib.esm/_tests/test-utils-utf8.d.ts new file mode 100644 index 00000000..04d7c492 --- /dev/null +++ b/lib.esm/_tests/test-utils-utf8.d.ts @@ -0,0 +1,13 @@ +export type TestCaseBadString = { + name: string; + bytes: Uint8Array; + ignore: string; + replace: string; + error: string; +}; +export type TestCaseCodePoints = { + name: string; + text: string; + codepoints: Array; +}; +//# sourceMappingURL=test-utils-utf8.d.ts.map \ No newline at end of file diff --git a/lib.esm/_tests/test-utils-utf8.d.ts.map b/lib.esm/_tests/test-utils-utf8.d.ts.map new file mode 100644 index 00000000..9dca561a --- /dev/null +++ b/lib.esm/_tests/test-utils-utf8.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"test-utils-utf8.d.ts","sourceRoot":"","sources":["../../src.ts/_tests/test-utils-utf8.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,iBAAiB,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,UAAU,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAA;CAChB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CAC7B,CAAC"} \ No newline at end of file diff --git a/lib.esm/_tests/test-utils-utf8.js b/lib.esm/_tests/test-utils-utf8.js new file mode 100644 index 00000000..eb53d787 --- /dev/null +++ b/lib.esm/_tests/test-utils-utf8.js @@ -0,0 +1,126 @@ +import assert from "assert"; +import { toUtf8Bytes, toUtf8CodePoints, toUtf8String, Utf8ErrorFuncs } from "../index.js"; +describe("Tests UTF-8 bad strings", function () { + const tests = [ + { + name: "unexpected continue", + bytes: new Uint8Array([0x41, 0x80, 0x42, 0x43]), + ignore: "ABC", + replace: "A\ufffdBC", + error: "UNEXPECTED_CONTINUE" + }, + { + name: "bad prefix", + bytes: new Uint8Array([0x41, 0xf8, 0x42, 0x43]), + ignore: "ABC", + replace: "A\ufffdBC", + error: "BAD_PREFIX" + }, + { + name: "bad prefix (multiple)", + bytes: new Uint8Array([0x41, 0xf8, 0x88, 0x88, 0x42, 0x43]), + ignore: "ABC", + replace: "A\ufffdBC", + error: "BAD_PREFIX" + }, + { + name: "OVERRUN", + bytes: new Uint8Array([0x41, 0x42, 0xe2, 0x82 /* 0xac */]), + ignore: "AB", + replace: "AB\ufffd", + error: "OVERRUN" + }, + { + name: "missing continue", + bytes: new Uint8Array([0x41, 0x42, 0xe2, 0xe2, 0x82, 0xac, 0x43]), + ignore: "AB\u20acC", + replace: "AB\ufffd\u20acC", + error: "MISSING_CONTINUE" + }, + { + name: "out-of-range", + bytes: new Uint8Array([0x41, 0x42, 0xf7, 0xbf, 0xbf, 0xbf, 0x43]), + ignore: "ABC", + replace: "AB\ufffdC", + error: "OUT_OF_RANGE" + }, + { + name: "UTF-16 surrogate (low)", + bytes: new Uint8Array([0x41, 0x42, 0xed, 0xa0, 0x80, 0x43]), + ignore: "ABC", + replace: "AB\ufffdC", + error: "UTF16_SURROGATE" + }, + { + name: "UTF-16 surrogate (high)", + bytes: new Uint8Array([0x41, 0x42, 0xed, 0xbf, 0xbf, 0x43]), + ignore: "ABC", + replace: "AB\ufffdC", + error: "UTF16_SURROGATE" + }, + { + name: "overlong", + bytes: new Uint8Array([0xf0, 0x82, 0x82, 0xac]), + ignore: "", + replace: "\u20ac", + error: "OVERLONG" + } + ]; + for (const { name, bytes, ignore, replace, error } of tests) { + it(`correctly handles ${name}: replace strategy`, function () { + const result = toUtf8String(bytes, Utf8ErrorFuncs.replace); + assert.equal(result, replace); + }); + it(`correctly handles ${name}: ignore strategy`, function () { + const result = toUtf8String(bytes, Utf8ErrorFuncs.ignore); + assert.equal(result, ignore); + }); + it(`correctly handles ${name}: error strategy`, function () { + assert.throws(() => { + const result = toUtf8String(bytes); + console.log(result); + }, (e) => { + return (e.message.indexOf(error) >= 0); + }); + }); + } + it("correctly fails to get UTF-8 bytes from incomplete surrogate", function () { + assert.throws(() => { + const text = String.fromCharCode(0xd800); + ; + const result = toUtf8Bytes(text); + console.log(result); + }, (error) => { + return (error.message.startsWith("invalid surrogate pair")); + }); + }); + it("correctly fails to get UTF-8 bytes from invalid surrogate pair", function () { + assert.throws(() => { + const text = String.fromCharCode(0xd800, 0xdbff); + ; + const result = toUtf8Bytes(text); + console.log(result); + }, (error) => { + return (error.message.startsWith("invalid surrogate pair")); + }); + }); +}); +describe("Tests UTF-8 bad strings", function () { + const tests = [ + { + name: "the Euro symbol", + text: "AB\u20acC", + codepoints: [0x41, 0x42, 0x20ac, 0x43] + }, + ]; + for (const { name, text, codepoints } of tests) { + it(`expands strings to codepoints: ${name}`, function () { + const result = toUtf8CodePoints(text); + assert.equal(result.length, codepoints.length, "codepoints.length"); + for (let i = 0; i < result.length; i++) { + assert.equal(result[i], codepoints[i], `codepoints[${i}]`); + } + }); + } +}); +//# sourceMappingURL=test-utils-utf8.js.map \ No newline at end of file diff --git a/lib.esm/_tests/test-utils-utf8.js.map b/lib.esm/_tests/test-utils-utf8.js.map new file mode 100644 index 00000000..70f34fda --- /dev/null +++ b/lib.esm/_tests/test-utils-utf8.js.map @@ -0,0 +1 @@ +{"version":3,"file":"test-utils-utf8.js","sourceRoot":"","sources":["../../src.ts/_tests/test-utils-utf8.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EACH,WAAW,EAAE,gBAAgB,EAAE,YAAY,EAC3C,cAAc,EACjB,MAAM,aAAa,CAAC;AAgBrB,QAAQ,CAAC,yBAAyB,EAAE;IAEhC,MAAM,KAAK,GAA6B;QACpC;YACI,IAAI,EAAE,qBAAqB;YAC3B,KAAK,EAAE,IAAI,UAAU,CAAC,CAAE,IAAI,EAAG,IAAI,EAAG,IAAI,EAAG,IAAI,CAAE,CAAC;YACpD,MAAM,EAAE,KAAK;YACb,OAAO,EAAE,WAAW;YACpB,KAAK,EAAE,qBAAqB;SAC/B;QACD;YACI,IAAI,EAAE,YAAY;YAClB,KAAK,EAAE,IAAI,UAAU,CA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MAAM,EAAE,IAAI,CAAE;SAC3C;KACJ,CAAC;IAEF,KAAK,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,KAAK,EAAE;QAC5C,EAAE,CAAC,kCAAmC,IAAK,EAAE,EAAE;YAC3C,MAAM,MAAM,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;YACtC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;YACpE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;gBACpC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,cAAe,CAAE,GAAG,CAAC,CAAC;aAChE;QACL,CAAC,CAAC,CAAC;KACN;AAEL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/lib.esm/_tests/test-utxo-coinselection.d.ts b/lib.esm/_tests/test-utxo-coinselection.d.ts new file mode 100644 index 00000000..c1dd221a --- /dev/null +++ b/lib.esm/_tests/test-utxo-coinselection.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=test-utxo-coinselection.d.ts.map \ No newline at end of file diff --git a/lib.esm/_tests/test-utxo-coinselection.d.ts.map b/lib.esm/_tests/test-utxo-coinselection.d.ts.map new file mode 100644 index 00000000..a0513c5c --- /dev/null +++ b/lib.esm/_tests/test-utxo-coinselection.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"test-utxo-coinselection.d.ts","sourceRoot":"","sources":["../../src.ts/_tests/test-utxo-coinselection.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/lib.esm/_tests/test-utxo-coinselection.js b/lib.esm/_tests/test-utxo-coinselection.js new file mode 100644 index 00000000..98879c90 --- /dev/null +++ b/lib.esm/_tests/test-utxo-coinselection.js @@ -0,0 +1,98 @@ +import assert from "assert"; +import { FewestCoinSelector } from "../transaction/coinselector-fewest"; +import { denominations } from "../transaction/utxo"; +const TEST_SPEND_ADDRESS = "0x00539bc2CE3eD0FD039c582CB700EF5398bB0491"; +const TEST_RECEIVE_ADDRESS = "0x02b9B1D30B6cCdc7d908B82739ce891463c3FA19"; +// Utility function to create UTXOs (adjust as necessary) +function createUTXOs(denominations) { + return denominations.map(denomination => ({ + denomination, + address: TEST_SPEND_ADDRESS + })); +} +describe("FewestCoinSelector", function () { + describe("Selecting valid UTXOs", function () { + it("selects a single UTXO that exactly matches the target amount", function () { + const availableUTXOs = createUTXOs([denominations[1], denominations[2], denominations[3]]); // .065 Qi + const targetSpend = { value: denominations[3], address: TEST_RECEIVE_ADDRESS }; // .05 Qi + const selector = new FewestCoinSelector(availableUTXOs); + const result = selector.performSelection(targetSpend); + // A single 0.05 Qi UTXO should have been selected + assert.strictEqual(result.inputs.length, 1); + assert.strictEqual(result.inputs[0].denomination, denominations[3]); + // A single new 0.05 Qi UTXO should have been outputed + assert.strictEqual(result.spendOutputs.length, 1); + assert.strictEqual(result.spendOutputs[0].denomination, denominations[3]); + // No change should be returned + assert.strictEqual(result.changeOutputs.length, 0); + }); + it("selects multiple UTXOs whose combined value meets the target amount", function () { + const availableUTXOs = createUTXOs([denominations[1], denominations[2], denominations[2], denominations[3]]); // .075 Qi + const targetSpend = { value: denominations[2] + denominations[3], address: TEST_RECEIVE_ADDRESS }; // .06 Qi + const selector = new FewestCoinSelector(availableUTXOs); + const result = selector.performSelection(targetSpend); + // 2 UTXOs should have been selected for a total of .06 Qi + assert.strictEqual(result.inputs.length, 2); + const inputValue = result.inputs[0].denomination + result.inputs[1].denomination; + assert.strictEqual(inputValue, denominations[2] + denominations[3]); + // 2 new UTxOs should have been outputed for a total of .06 Qi + assert.strictEqual(result.spendOutputs.length, 2); + const spendValue = result.spendOutputs[0].denomination + result.spendOutputs[1].denomination; + assert.strictEqual(spendValue, denominations[2] + denominations[3]); + // No change should be returned + assert.strictEqual(result.changeOutputs.length, 0); + }); + it("selects a single UTXO that is larger than the target amount, ensuring change is correctly calculated", function () { + const availableUTXOs = createUTXOs([denominations[2], denominations[4]]); // .11 Qi + const targetSpend = { value: denominations[3], address: TEST_RECEIVE_ADDRESS }; // .05 Qi + const selector = new FewestCoinSelector(availableUTXOs); + const result = selector.performSelection(targetSpend); + // A single 0.1 Qi UTXO should have been selected + assert.strictEqual(result.inputs.length, 1); + assert.strictEqual(result.inputs[0].denomination, denominations[4]); + // A single new 0.05 Qi UTXO should have been outputed + assert.strictEqual(result.spendOutputs.length, 1); + assert.strictEqual(result.spendOutputs[0].denomination, denominations[3]); + // 0.05 Qi should be returned in change + assert.strictEqual(result.changeOutputs.length, 1); + assert.strictEqual(result.changeOutputs[0].denomination, denominations[3]); + }); + it("selects multiple UTXOs where the total exceeds the target amount, ensuring change is correctly calculated", function () { + const availableUTXOs = createUTXOs([ + denominations[2], + denominations[4], + denominations[4], + denominations[4], + denominations[5] + ]); // .56 Qi + const targetSpend = { value: denominations[6], address: TEST_RECEIVE_ADDRESS }; // .5 Qi + const selector = new FewestCoinSelector(availableUTXOs); + const result = selector.performSelection(targetSpend); + // 4 UTXOs should have been selected for a total of .55 Qi + assert.strictEqual(result.inputs.length, 4); + const inputValue = result.inputs[0].denomination + result.inputs[1].denomination + result.inputs[2].denomination + result.inputs[3].denomination; + assert.strictEqual(inputValue, denominations[4] + denominations[4] + denominations[4] + denominations[5]); + // A single new 0.5 Qi UTXO should have been outputed + assert.strictEqual(result.spendOutputs.length, 1); + assert.strictEqual(result.spendOutputs[0].denomination, denominations[6]); + // 0.05 Qi should be returned in change + assert.strictEqual(result.changeOutputs.length, 1); + assert.strictEqual(result.changeOutputs[0].denomination, denominations[3]); + }); + }); + describe("Selecting valid UTXOs", function () { + it("throws an error when there are insufficient funds", function () { + const selector = new FewestCoinSelector(createUTXOs([denominations[0], denominations[0]])); + assert.throws(() => selector.performSelection({ value: denominations[3], address: TEST_RECEIVE_ADDRESS }), /Insufficient funds/); + }); + it("throws an error when no UTXOs are available", function () { + const selector = new FewestCoinSelector([]); + assert.throws(() => selector.performSelection({ value: denominations[2], address: TEST_RECEIVE_ADDRESS }), /No UTXOs available/); + }); + it("throws an error when the target amount is negative", function () { + const selector = new FewestCoinSelector(createUTXOs([denominations[2], denominations[2]])); + assert.throws(() => selector.performSelection({ value: -denominations[1], address: TEST_RECEIVE_ADDRESS }), /Target amount must be greater than 0/); + }); + }); +}); +//# sourceMappingURL=test-utxo-coinselection.js.map \ No newline at end of file diff --git a/lib.esm/_tests/test-utxo-coinselection.js.map b/lib.esm/_tests/test-utxo-coinselection.js.map new file mode 100644 index 00000000..0c56d7cb --- /dev/null +++ b/lib.esm/_tests/test-utxo-coinselection.js.map @@ -0,0 +1 @@ +{"version":3,"file":"test-utxo-coinselection.js","sourceRoot":"","sources":["../../src.ts/_tests/test-utxo-coinselection.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AACxE,OAAO,EAAY,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAE9D,MAAM,kBAAkB,GAAG,4CAA4C,CAAC;AACxE,MAAM,oBAAoB,GAAG,4CAA4C,CAAC;AAE1E,yDAAyD;AACzD,SAAS,WAAW,CAAC,aAAuB;IACxC,OAAO,aAAa,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;QACtC,YAAY;QACZ,OAAO,EAAE,kBAAkB;KAC9B,CAAC,CAAC,CAAC;AACR,CAAC;AAED,QAAQ,CAAC,oBAAoB,EAAE;IAC3B,QAAQ,CAAC,uBAAuB,EAAE;QAC9B,EAAE,CAAC,8DAA8D,EAAE;YAC/D,MAAM,cAAc,GAAG,WAAW,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAA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AAC,CAAC,CAAC,CAAC,CAAC;YAC3F,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,oBAAoB,EAAE,CAAC,EAAE,oBAAoB,CAAC,CAAC;QACrI,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,6CAA6C,EAAE;YAC9C,MAAM,QAAQ,GAAG,IAAI,kBAAkB,CAAC,EAAE,CAAC,CAAC;YAC5C,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,oBAAoB,EAAE,CAAC,EAAE,oBAAoB,CAAC,CAAC;QACrI,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,oDAAoD,EAAE;YACrD,MAAM,QAAQ,GAAG,IAAI,kBAAkB,CAAC,WAAW,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC3F,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,KAAK,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,oBAAoB,EAAE,CAAC,EAAE,sCAAsC,CAAC,CAAC;QACxJ,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/lib.esm/_tests/test-wallet-hd.d.ts b/lib.esm/_tests/test-wallet-hd.d.ts new file mode 100644 index 00000000..da7ceeb0 --- /dev/null +++ b/lib.esm/_tests/test-wallet-hd.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=test-wallet-hd.d.ts.map \ No newline at end of file diff --git a/lib.esm/_tests/test-wallet-hd.d.ts.map b/lib.esm/_tests/test-wallet-hd.d.ts.map new file mode 100644 index 00000000..f42ecbbc --- /dev/null +++ b/lib.esm/_tests/test-wallet-hd.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"test-wallet-hd.d.ts","sourceRoot":"","sources":["../../src.ts/_tests/test-wallet-hd.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/lib.esm/_tests/test-wallet-hd.js b/lib.esm/_tests/test-wallet-hd.js new file mode 100644 index 00000000..a4b1ba62 --- /dev/null +++ b/lib.esm/_tests/test-wallet-hd.js @@ -0,0 +1,119 @@ +import assert from "assert"; +import { loadTests } from "./utils.js"; +import { getBytes, wordlists, HDNodeWallet, HDNodeVoidWallet, Mnemonic } from "../index.js"; +const decoder = new TextDecoder(); +function fromHex(hex) { + const data = getBytes(hex); + return decoder.decode(data); +} +describe("Test HDWallets", function () { + function checkWallet(wallet, test) { + assert.equal(wallet.chainCode, test.chainCode, "chainCode"); + assert.equal(wallet.depth, test.depth, "depth"); + assert.equal(wallet.index, test.index, "index"); + assert.equal(wallet.fingerprint, test.fingerprint, "fingerprint"); + assert.equal(wallet.accountFingerprint, test.parentFingerprint, "parentFingerprint"); + assert.equal(wallet.publicKey, test.publicKey, "publicKey"); + if (wallet instanceof HDNodeWallet) { + assert.equal(wallet.extendedKey, test.xpriv, "xpriv"); + assert.equal(wallet.privateKey, test.privateKey, "privateKey"); + assert.equal(wallet.neuter().extendedKey, test.xpub, "xpub"); + } + else if (wallet instanceof HDNodeVoidWallet) { + assert.equal(wallet.extendedKey, test.xpub, "xpub"); + } + } + const tests = 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[test.locale]; + if (wordlist == null) { + it(`tests ${test.name}`, function () { + this.skip(); + }); + return; + } + const mnemonic = Mnemonic.fromPhrase(phrase, password, wordlist); + function checkMnemonic(actual) { + assert.equal(actual.phrase, phrase, "phrase"); + assert.equal(actual.password, password, "password"); + assert.equal(actual.wordlist.locale, test.locale, "locale"); + assert.equal(actual.entropy, mnemonic.entropy, "entropy"); + assert.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 = HDNodeWallet.fromPhrase(phrase, password, subtest.path, wordlist); + assert.ok(w instanceof HDNodeWallet, "instanceof HDNodeWallet"); + assert.equal(w.path, subtest.path, "path"); + checkWallet(w, subtest); + assert.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 = HDNodeWallet.fromSeed(test.seed); + for (const subtest of test.nodes) { + const w = seedRoot.derivePath(subtest.path); + assert.ok(w instanceof HDNodeWallet, "instanceof HDNodeWallet"); + assert.equal(w.path, subtest.path, "path"); + checkWallet(w, subtest); + assert.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 = HDNodeWallet.fromExtendedKey(subtest.xpriv); + assert.ok(w instanceof HDNodeWallet, "instanceof HDNodeWallet"); + checkWallet(w, subtest); + assert.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 = HDNodeWallet.fromPhrase(phrase, password, "m", wordlist).neuter(); + for (const subtest of test.nodes) { + if (subtest.path.indexOf("'") >= 0) { + assert.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.ok(w instanceof HDNodeVoidWallet, "instanceof HDNodeVoidWallet"); + assert.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 = HDNodeWallet.fromExtendedKey(subtest.xpub); + assert.ok(w instanceof HDNodeVoidWallet, "instanceof HDNodeVoidWallet"); + checkWallet(w, subtest); + } + }); + } +}); +//# sourceMappingURL=test-wallet-hd.js.map \ No newline at end of file diff --git a/lib.esm/_tests/test-wallet-hd.js.map b/lib.esm/_tests/test-wallet-hd.js.map new file mode 100644 index 00000000..764a6700 --- /dev/null +++ b/lib.esm/_tests/test-wallet-hd.js.map @@ -0,0 +1 @@ +{"version":3,"file":"test-wallet-hd.js","sourceRoot":"","sources":["../../src.ts/_tests/test-wallet-hd.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EACH,QAAQ,EAAE,SAAS,EACnB,YAAY,EAAE,gBAAgB,EAAE,QAAQ,EAC3C,MAAM,aAAa,CAAC;AAOrB,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAClC,SAAS,OAAO,CAAC,GAAW;IACxB,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;IAC3B,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAChC,CAAC;AAWD,QAAQ,CAAC,gBAAgB,EAAE;IACvB,SAAS,WAAW,CAAC,MAAuC,EAAE,IAA0B;QACpF,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;QAC5D,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAChD,MAAM,CAAC,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UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;oBACxC,MAAM,CAAC,EAAE,CAAC,CAAC,YAAY,gBAAgB,EAAE,6BAA6B,CAAC,CAAC;oBACxE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;oBAC1C,WAAW,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;iBAC3B;aACJ;QACL,CAAC,CAAC,CAAC;KACN;IAED,KAAK,MAAM,EAAE,IAAI,EAAE,IAAI,MAAM,EAAE;QAC3B,EAAE,CAAC,0DAA2D,IAAI,CAAC,IAAK,EAAE,EAAE;YACxE,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,KAAK,EAAE;gBAC9B,MAAM,CAAC,GAAG,YAAY,CAAC,eAAe,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;gBACrD,MAAM,CAAC,EAAE,CAAC,CAAC,YAAY,gBAAgB,EAAE,6BAA6B,CAAC,CAAC;gBACxE,WAAW,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;aAC3B;QACL,CAAC,CAAC,CAAC;KACN;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/lib.esm/_tests/test-wallet-json.d.ts b/lib.esm/_tests/test-wallet-json.d.ts new file mode 100644 index 00000000..f6b292db --- /dev/null +++ b/lib.esm/_tests/test-wallet-json.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=test-wallet-json.d.ts.map \ No newline at end of file diff --git a/lib.esm/_tests/test-wallet-json.d.ts.map b/lib.esm/_tests/test-wallet-json.d.ts.map new file mode 100644 index 00000000..d0e81890 --- /dev/null +++ b/lib.esm/_tests/test-wallet-json.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"test-wallet-json.d.ts","sourceRoot":"","sources":["../../src.ts/_tests/test-wallet-json.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/lib.esm/_tests/test-wallet-json.js b/lib.esm/_tests/test-wallet-json.js new file mode 100644 index 00000000..d3d1ccf1 --- /dev/null +++ b/lib.esm/_tests/test-wallet-json.js @@ -0,0 +1,164 @@ +import assert from "assert"; +import { loadTests } from "./utils.js"; +import { isError, getBytes, decryptCrowdsaleJson, decryptKeystoreJson, decryptKeystoreJsonSync, encryptKeystoreJson, encryptKeystoreJsonSync, isCrowdsaleJson, HDNodeWallet, Wallet } from "../index.js"; +describe("Tests JSON Wallet Formats", function () { + const tests = loadTests("wallets"); + tests.forEach((test) => { + if (test.type !== "crowdsale") { + return; + } + it(`tests decrypting Crowdsale JSON: ${test.name}`, async function () { + const password = getBytes(test.password); + const account = decryptCrowdsaleJson(test.content, password); + assert.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 = getBytes(test.password); + const account = decryptKeystoreJsonSync(test.content, password); + //console.log(account); + assert.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 = getBytes(test.password); + const account = await decryptKeystoreJson(test.content, password); + //console.log(account); + assert.equal(account.address, test.address, "address"); + }); + }); + tests.forEach((test) => { + it(`tests decrypting JSON (sync): ${test.name}`, function () { + this.timeout(20000); + const password = getBytes(test.password); + const wallet = Wallet.fromEncryptedJsonSync(test.content, password); + //console.log(wallet); + assert.equal(wallet.address, test.address, "address"); + }); + }); + tests.forEach((test) => { + it(`tests decrypting JSON (async): ${test.name}`, async function () { + this.timeout(20000); + const password = getBytes(test.password); + const wallet = await Wallet.fromEncryptedJson(test.content, password); + //console.log(wallet); + assert.equal(wallet.address, test.address, "address"); + }); + }); + it("tests encrypting wallet with mnemonic", function () { + this.timeout(20000); + const wallet = HDNodeWallet.createRandom("m/44'/60'/0'/0/0"); + assert.ok(wallet.mnemonic, "mnemonic"); + const phrase = wallet.mnemonic.phrase; + const json = wallet.encryptSync("foobar"); + const wallet2 = Wallet.fromEncryptedJsonSync(json, "foobar"); + assert.ok(wallet2 instanceof HDNodeWallet && wallet2.mnemonic); + assert.equal(wallet2.mnemonic.phrase, phrase, "phrase"); + assert.equal(wallet2.address, wallet.address, "address"); + }); +}); +describe("Tests Extra JSON Wallet Functions", function () { + const badCrowdsales = [ + { + name: "undefined", + value: undefined + }, + { + name: "junk string", + value: "junk!" + }, + { + name: "non-string", + value: 42 + }, + { + name: "JSON without encseed", + value: JSON.stringify({ foo: "bar" }) + }, + ]; + for (const { name, value } of badCrowdsales) { + it(`tests the invalid isCrowdsale wallet: ${name}`, function () { + assert.equal(isCrowdsaleJson(value), false); + }); + } + const badKeystoreOptions = [ + { + name: "invalid salt type", + options: { salt: 42 }, + error: "invalid BytesLike value" + }, + { + name: "invalid uuid type", + options: { uuid: 42 }, + error: "invalid BytesLike value" + }, + { + name: "invalid uuid length", + options: { uuid: "0x1234" }, + error: "invalid options.uuid" + }, + { + name: "invalid iv type", + options: { iv: 42 }, + error: "invalid BytesLike value" + }, + { + name: "invalid iv length", + options: { iv: "0x1234" }, + error: "invalid options.iv" + }, + { + name: "invalid scrypt N (non-one-hot-encoded)", + options: { scrypt: { N: 1023 } }, + error: "invalid scrypt N parameter" + }, + { + name: "invalid scrypt N (non-integer)", + options: { scrypt: { N: 1.5 } }, + error: "invalid scrypt N parameter" + }, + { + name: "invalid scrypt r", + options: { scrypt: { r: 1.5 } }, + error: "invalid scrypt r parameter" + }, + { + name: "invalid scrypt p", + options: { scrypt: { p: 1.5 } }, + error: "invalid scrypt p parameter" + }, + ]; + const wallet = Wallet.createRandom("m/44'/994'/0'/0"); + const account = { address: wallet.address, privateKey: wallet.privateKey }; + const password = "foobar"; + for (const { name, options, error } of badKeystoreOptions) { + it(`tests bad keystore options: ${name}`, function () { + assert.throws(() => { + const result = encryptKeystoreJsonSync(account, password, options); + console.log(result); + }, (e) => { + return (isError(e, "INVALID_ARGUMENT") && + e.message.startsWith(error)); + }); + }); + } + // Mainly to round out weird edge cases in coverage + it("tests encryption with options (sync)", function () { + assert.ok(encryptKeystoreJsonSync(account, password)); + }); + // Mainly to round out weird edge cases in coverage + it("tests encryption with options (async)", async function () { + assert.ok(await encryptKeystoreJson(account, password)); + }); +}); +//# sourceMappingURL=test-wallet-json.js.map \ No newline at end of file diff --git a/lib.esm/_tests/test-wallet-json.js.map b/lib.esm/_tests/test-wallet-json.js.map new file mode 100644 index 00000000..5c07918c --- /dev/null +++ b/lib.esm/_tests/test-wallet-json.js.map @@ -0,0 +1 @@ +{"version":3,"file":"test-wallet-json.js","sourceRoot":"","sources":["../../src.ts/_tests/test-wallet-json.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAIvC,OAAO,EACH,OAAO,EACP,QAAQ,EAER,oBAAoB,EAAE,mBAAmB,EAAE,uBAAuB,EAClE,mBAAmB,EAAE,uBAAuB,EAC5C,eAAe,EACf,YAAY,EAAE,MAAM,EACvB,MAAM,aAAa,CAAC;AAGrB,QAAQ,CAAC,2BAA2B,EAAE;IACjC,MAAM,KAAK,GAAG,SAAS,CAAiB,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,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACzC,MAAM,OAAO,GAAG,oBAAoB,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;YAC7D,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QA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AAE,EAAE;YACxC,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE;gBACf,MAAM,MAAM,GAAG,uBAAuB,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;gBACnE,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YACxB,CAAC,EAAE,CAAC,CAAM,EAAE,EAAE;gBACV,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,kBAAkB,CAAC;oBAClC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;YACrC,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;KACN;IAED,mDAAmD;IACnD,EAAE,CAAC,sCAAsC,EAAE;QACvC,MAAM,CAAC,EAAE,CAAC,uBAAuB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;IAEH,mDAAmD;IACnD,EAAE,CAAC,uCAAuC,EAAE,KAAK;QAC7C,MAAM,CAAC,EAAE,CAAC,MAAM,mBAAmB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;AAEP,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/lib.esm/_tests/test-wallet-mnemonic.d.ts b/lib.esm/_tests/test-wallet-mnemonic.d.ts new file mode 100644 index 00000000..7b51aeda --- /dev/null +++ b/lib.esm/_tests/test-wallet-mnemonic.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=test-wallet-mnemonic.d.ts.map \ No newline at end of file diff --git a/lib.esm/_tests/test-wallet-mnemonic.d.ts.map b/lib.esm/_tests/test-wallet-mnemonic.d.ts.map new file mode 100644 index 00000000..ebe4e424 --- /dev/null +++ b/lib.esm/_tests/test-wallet-mnemonic.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"test-wallet-mnemonic.d.ts","sourceRoot":"","sources":["../../src.ts/_tests/test-wallet-mnemonic.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/lib.esm/_tests/test-wallet-mnemonic.js b/lib.esm/_tests/test-wallet-mnemonic.js new file mode 100644 index 00000000..e27d082f --- /dev/null +++ b/lib.esm/_tests/test-wallet-mnemonic.js @@ -0,0 +1,118 @@ +import assert from "assert"; +import { getBytes, sha256, toUtf8Bytes, Mnemonic, wordlists, } from "../index.js"; +import { loadTests } from "./utils.js"; +const decoder = new TextDecoder(); +function fromHex(hex) { + const data = getBytes(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 = loadTests("mnemonics"); + function runTest(phrase, mnemonic, test) { + assert.ok(Mnemonic.isValidMnemonic(phrase, mnemonic.wordlist), "isValidMnemonic"); + if (test.locale === "en") { + assert.ok(Mnemonic.isValidMnemonic(phrase), "isValidMnemonic (default)"); + } + assert.equal(mnemonic.wordlist.locale, test.locale, "locale"); + assert.equal(mnemonic.entropy, test.entropy, "entropy"); + assert.equal(mnemonic.computeSeed(), test.seed, "seed"); + assert.equal(sha256(toUtf8Bytes(phrase)), test.phraseHash, "phraseHash"); + } + for (const test of tests) { + const wordlist = 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 = Mnemonic.fromPhrase(phrase, password, wordlist); + runTest(phrase, mnemonic, test); + }); + } + for (const test of tests) { + const wordlist = 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 = 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(`correctly fails on invalid mnemonic length: ${_phrase.length}`, function () { + assert.ok(!Mnemonic.isValidMnemonic(phrase)); + assert.throws(function () { + Mnemonic.fromPhrase(phrase); + }, function (error) { + return (error.code === "INVALID_ARGUMENT" && + error.message.match(/^invalid mnemonic length/) && + error.argument === "mnemonic" && + error.value === "[ REDACTED ]"); + }); + }); + } + it("correctly fails on invalid mnemonic word", function () { + const phrase = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon wagmi"; + assert.ok(!Mnemonic.isValidMnemonic(phrase)); + assert.throws(function () { + 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("correctly fails on invalid mnemonic checksum", function () { + const phrase = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon"; + assert.ok(!Mnemonic.isValidMnemonic(phrase)); + assert.throws(function () { + 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(`correctly fails on invalid entropy length: ${_entropy.length}`, function () { + assert.throws(function () { + 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 \ No newline at end of file diff --git a/lib.esm/_tests/test-wallet-mnemonic.js.map b/lib.esm/_tests/test-wallet-mnemonic.js.map new file mode 100644 index 00000000..bf35663b --- /dev/null +++ b/lib.esm/_tests/test-wallet-mnemonic.js.map @@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CAA+C,QAAQ,CAAC,MAAO,EAAE,EAAE;YAClE,MAAM,CAAC,MAAM,CAAC;gBACV,QAAQ,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"} \ No newline at end of file diff --git a/lib.esm/_tests/test-wallet.d.ts b/lib.esm/_tests/test-wallet.d.ts new file mode 100644 index 00000000..918eb2f0 --- /dev/null +++ b/lib.esm/_tests/test-wallet.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=test-wallet.d.ts.map \ No newline at end of file diff --git a/lib.esm/_tests/test-wallet.d.ts.map b/lib.esm/_tests/test-wallet.d.ts.map new file mode 100644 index 00000000..c63929ce --- /dev/null +++ b/lib.esm/_tests/test-wallet.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"test-wallet.d.ts","sourceRoot":"","sources":["../../src.ts/_tests/test-wallet.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/lib.esm/_tests/test-wallet.js b/lib.esm/_tests/test-wallet.js new file mode 100644 index 00000000..067c4d3d --- /dev/null +++ b/lib.esm/_tests/test-wallet.js @@ -0,0 +1,70 @@ +import assert from "assert"; +import { loadTests } from "./utils.js"; +import { hexlify, randomBytes, Wallet } from "../index.js"; +describe("Test Private Key Wallet", function () { + const tests = loadTests("accounts"); + tests.forEach(({ name, privateKey, address }) => { + it(`creates wallet: ${name}`, function () { + const wallet = new Wallet(privateKey); + assert.equal(wallet.privateKey, privateKey); + assert.equal(wallet.address, address); + }); + }); +}); +describe("Test Transaction Signing", function () { + const tests = loadTests("transactions"); + for (const test of tests) { + if (!test.signedEip155) { + continue; + } + it(`tests signing an EIP-155 transaction: ${test.name}`, async function () { + const wallet = new Wallet(test.privateKey); + const txData = Object.assign({}, test.transaction, { type: 0, accessList: [], maxFeePerGas: 0, maxPriorityFeePerGas: 0 }); + const signed = await wallet.signTransaction(txData); + // let parsed = Transaction.from(signed); + // // console.log('txData: ', JSON.stringify(parsed)) + // // console.log('EXPECTED: ', test.signedEip155) + // // console.log("ACTUAL: ", signed) + assert.equal(signed, test.signedEip155, "signedEip155"); + }); + } +}); +describe("Test Message Signing (EIP-191)", function () { +}); +describe("Test Typed-Data Signing (EIP-712)", function () { + const tests = 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 Wallet(privateKey); + const sig = await wallet.signTypedData(test.domain, test.types, test.data); + assert.equal(sig, signature, "signature"); + }); + } +}); +describe("Test Wallet Encryption", function () { + const password = "foobar"; + // Loop: + // 1 : random wallet (uses HDNodeWallet under the hood) + // 2 : Wallet using private key (uses Wallet explicitly) + for (let i = 0; i < 2; i++) { + let wallet = Wallet.createRandom("m/44'/994'/0'/0"); + it("encrypts a random wallet: sync", function () { + this.timeout(30000); + const json = wallet.encryptSync(password); + const decrypted = Wallet.fromEncryptedJsonSync(json, password); + assert.equal(decrypted.address, wallet.address, "address"); + }); + it("encrypts a random wallet: async", async function () { + this.timeout(30000); + const json = await wallet.encrypt(password); + const decrypted = await Wallet.fromEncryptedJson(json, password); + assert.equal(decrypted.address, wallet.address, "address"); + }); + wallet = new Wallet(hexlify(randomBytes(32))); + } +}); +//# sourceMappingURL=test-wallet.js.map \ No newline at end of file diff --git a/lib.esm/_tests/test-wallet.js.map b/lib.esm/_tests/test-wallet.js.map new file mode 100644 index 00000000..ab550703 --- /dev/null +++ b/lib.esm/_tests/test-wallet.js.map @@ -0,0 +1 @@ +{"version":3,"file":"test-wallet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,CAAC,YAAY,CAAC,iBAAiB,CAAC,CAAC;QAE3E,EAAE,CAAC,gCAAgC,EAAE;YACjC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YACpB,MAAM,IAAI,GAAG,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;YAC1C,MAAM,SAAS,GAAG,MAAM,CAAC,qBAAqB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;YAC/D,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QAC/D,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,iCAAiC,EAAE,KAAK;YACvC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YACpB,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YAC5C,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,iBAAiB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;YACjE,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QAC/D,CAAC,CAAC,CAAC;QAEH,MAAM,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;KACjD;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/lib.esm/_tests/test-wordlists.d.ts b/lib.esm/_tests/test-wordlists.d.ts new file mode 100644 index 00000000..ea3f51d4 --- /dev/null +++ b/lib.esm/_tests/test-wordlists.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=test-wordlists.d.ts.map \ No newline at end of file diff --git a/lib.esm/_tests/test-wordlists.d.ts.map b/lib.esm/_tests/test-wordlists.d.ts.map new file mode 100644 index 00000000..244454d5 --- /dev/null +++ b/lib.esm/_tests/test-wordlists.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"test-wordlists.d.ts","sourceRoot":"","sources":["../../src.ts/_tests/test-wordlists.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/lib.esm/_tests/test-wordlists.js b/lib.esm/_tests/test-wordlists.js new file mode 100644 index 00000000..7c451644 --- /dev/null +++ b/lib.esm/_tests/test-wordlists.js @@ -0,0 +1,66 @@ +import assert from "assert"; +import { wordlists } from "../index.js"; +import { loadTests } from "./utils.js"; +describe('Check Wordlists', function () { + const tests = loadTests("wordlists"); + tests.forEach((test) => { + let wordlist = 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.equal(word, words[i]); + assert.equal(wordlist.getWordIndex(word), i); + } + assert.equal(check, test.content); + }); + }); + tests.forEach((test) => { + let wordlist = 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.deepEqual(words2, words, "split words"); + assert.deepEqual(phrase2, phrase, "re-joined words"); + }); + }); + tests.forEach((test) => { + let wordlist = wordlists[test.locale]; + if (wordlist == null) { + return; + } + it(`handles out-of-range values: ${test.locale}`, function () { + assert.equal(wordlist.getWordIndex("foobar"), -1); + assert.throws(() => { + wordlist.getWord(-1); + }, (error) => { + return (error.code === "INVALID_ARGUMENT" && + error.message.match(/^invalid word index/) && + error.argument === "index" && + error.value === -1); + }); + assert.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 \ No newline at end of file diff --git a/lib.esm/_tests/test-wordlists.js.map b/lib.esm/_tests/test-wordlists.js.map new file mode 100644 index 00000000..53e07fb8 --- /dev/null +++ b/lib.esm/_tests/test-wordlists.js.map @@ -0,0 +1 @@ +{"version":3,"file":"test-wordlists.js","sourceRoot":"","sources":["../../src.ts/_tests/test-wordlists.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAKvC,QAAQ,CAAC,iBAAiB,EAAE;IACxB,MAAM,KAAK,GAAG,SAAS,CAAmB,WAAW,CAAC,CAAC;IAEvD,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACnB,IAAI,QAAQ,GAAG,SAAS,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,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC7B,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;aAChD;YAED,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QACtC,CA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MAAM,CAAC,GAAG,EAAE;gBACf,QAAQ,CAAC,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,MAAM,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"} \ No newline at end of file diff --git a/lib.esm/_tests/types.d.ts b/lib.esm/_tests/types.d.ts new file mode 100644 index 00000000..fcd151ca --- /dev/null +++ b/lib.esm/_tests/types.d.ts @@ -0,0 +1,218 @@ +export type TestCaseAbiVerbose = { + type: "address" | "hexstring" | "number" | "string"; + value: string; +} | { + type: "boolean"; + value: boolean; +} | { + type: "array"; + value: Array; +} | { + type: "object"; + value: Array; +}; +export interface TestCaseAbi { + name: string; + type: string; + value: any; + verbose: TestCaseAbiVerbose; + bytecode: string; + encoded: string; +} +export interface TestCaseAccount { + name: string; + privateKey: string; + address: string; + icap: string; +} +export type TestCaseCreate = { + sender: string; + creates: Array<{ + name: string; + nonce: number; + address: string; + }>; +}; +export type TestCaseCreate2 = { + sender: string; + creates: Array<{ + name: string; + salt: string; + initCode: string; + initCodeHash: string; + address: string; + }>; +}; +export interface TestCaseHash { + name: string; + data: string; + sha256: string; + sha512: string; + ripemd160: string; + keccak256: string; +} +export interface TestCasePbkdf { + name: string; + password: string; + salt: string; + dkLen: number; + pbkdf2: { + iterations: number; + algorithm: "sha256" | "sha512"; + key: string; + }; + scrypt: { + N: number; + r: number; + p: number; + key: string; + }; +} +export interface TestCaseHmac { + name: string; + data: string; + key: string; + algorithm: "sha256" | "sha512"; + hmac: string; +} +export interface TestCaseHash { + name: string; + data: string; + sha256: string; + sha512: string; + ripemd160: string; + keccak256: string; +} +export interface TestCaseNamehash { + name: string; + ensName: string; + error?: string; + namehash?: string; +} +export interface TestCaseTypedDataDomain { + name?: string; + version?: string; + chainId?: number; + verifyingContract?: string; + salt?: string; +} +export interface TestCaseTypedDataType { + name: string; + type: string; +} +export interface TestCaseTypedData { + name: string; + domain: TestCaseTypedDataDomain; + primaryType: string; + types: Record>; + data: any; + encoded: string; + digest: string; + privateKey?: string; + signature?: string; +} +export interface TestCaseSolidityHash { + name: string; + types: Array; + keccak256: string; + ripemd160: string; + sha256: string; + values: Array; +} +export interface TestCaseUnit { + name: string; + wei: string; + quais: string; + ether_format: string; + kwei?: string; + mwei?: string; + gwei?: string; + szabo?: string; + finney?: string; + finney_format?: string; + szabo_format?: string; + gwei_format?: string; + mwei_format?: string; + kwei_format?: string; +} +export type NestedHexString = string | Array; +export interface TestCaseRlp { + name: string; + encoded: string; + decoded: NestedHexString; +} +export interface TestCaseTransactionTx { + to?: string; + from: string; + nonce?: number; + gasLimit?: string; + gasPrice?: string; + maxFeePerGas?: string; + maxPriorityFeePerGas?: string; + data?: string; + value?: string; + accessList?: Array<{ + address: string; + storageKeys: Array; + }>; + chainId?: string; +} +export interface TestCaseTransactionSig { + r: string; + s: string; + v: string; +} +export interface TestCaseTransaction { + name: string; + transaction: TestCaseTransactionTx; + privateKey: string; + unsignedLegacy: string; + signedLegacy: string; + unsignedEip155: string; + signedEip155: string; + unsignedBerlin: string; + signedBerlin: string; + unsignedLondon: string; + signedLondon: string; + signatureLegacy: TestCaseTransactionSig; + signatureEip155: TestCaseTransactionSig; + signatureBerlin: TestCaseTransactionSig; + signatureLondon: TestCaseTransactionSig; +} +export interface TestCaseMnemonicNode { + path: string; + chainCode: string; + depth: number; + index: number; + parentFingerprint: string; + fingerprint: string; + publicKey: string; + privateKey: string; + xpriv: string; + xpub: string; +} +export interface TestCaseMnemonic { + name: string; + phrase: string; + phraseHash: string; + password: string; + locale: string; + entropy: string; + seed: string; + nodes: Array; +} +export interface TestCaseWallet { + name: string; + filename: string; + type: string; + address: string; + password: string; + content: string; +} +export interface TestCaseWordlist { + name: string; + filename: string; + locale: string; + content: string; +} +//# sourceMappingURL=types.d.ts.map \ No newline at end of file diff --git a/lib.esm/_tests/types.d.ts.map b/lib.esm/_tests/types.d.ts.map new file mode 100644 index 00000000..53aa7770 --- /dev/null +++ b/lib.esm/_tests/types.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src.ts/_tests/types.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,kBAAkB,GAAG;IAC7B,IAAI,EAAE,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,QAAQ,CAAC;IACpD,KAAK,EAAE,MAAM,CAAA;CAChB,GAAG;IACA,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,OAAO,CAAA;CACjB,GAAG;IACA,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,KAAK,CAAC,kBAAkB,CAAC,CAAA;CACnC,GAAG;IACA,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,KAAK,CAAC,kBAAkB,CAAC,CAAA;CACnC,CAAA;AAED,MAAM,WAAW,WAAW;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,GAAG,CAAC;IACX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E,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,gBAAgB;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,KAAK,CAAC,oBAAoB,CAAC,CAAC;CACtC;AAED,MAAM,WAAW,cAAc;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACnB;AAKD,MAAM,WAAW,gBAAgB;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACnB"} \ No newline at end of file diff --git a/lib.esm/_tests/types.js b/lib.esm/_tests/types.js new file mode 100644 index 00000000..4f418f71 --- /dev/null +++ b/lib.esm/_tests/types.js @@ -0,0 +1,3 @@ +; +export {}; +//# sourceMappingURL=types.js.map \ No newline at end of file diff --git a/lib.esm/_tests/types.js.map b/lib.esm/_tests/types.js.map new file mode 100644 index 00000000..68216b0f --- /dev/null +++ b/lib.esm/_tests/types.js.map @@ -0,0 +1 @@ +{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src.ts/_tests/types.ts"],"names":[],"mappings":"AA6PC,CAAC"} \ No newline at end of file diff --git a/lib.esm/_tests/utils.d.ts b/lib.esm/_tests/utils.d.ts new file mode 100644 index 00000000..4621f777 --- /dev/null +++ b/lib.esm/_tests/utils.d.ts @@ -0,0 +1,9 @@ +export declare function loadTests(tag: string): Array; +export declare function log(context: any, text: string): void; +export declare function stall(duration: number): Promise; +export interface MochaRunnable { + timeout: (value: number) => void; + skip: () => void; +} +export declare function retryIt(name: string, func: (this: MochaRunnable) => Promise): Promise; +//# sourceMappingURL=utils.d.ts.map \ No newline at end of file diff --git a/lib.esm/_tests/utils.d.ts.map b/lib.esm/_tests/utils.d.ts.map new file mode 100644 index 00000000..16e81ace --- /dev/null +++ b/lib.esm/_tests/utils.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src.ts/_tests/utils.ts"],"names":[],"mappings":"AAoBA,wBAAgB,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,CAGlD;AAED,wBAAgB,GAAG,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAMpD;AAED,wBAAsB,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE3D;AAED,MAAM,WAAW,aAAa;IAC1B,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC,IAAI,EAAE,MAAM,IAAI,CAAC;CACpB;AAGD,wBAAsB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAoCvG"} \ No newline at end of file diff --git a/lib.esm/_tests/utils.js b/lib.esm/_tests/utils.js new file mode 100644 index 00000000..e579f4bb --- /dev/null +++ b/lib.esm/_tests/utils.js @@ -0,0 +1,125 @@ +import fs from "fs"; +import path from "path"; +import zlib from "zlib"; +// Find the package root (based on the nyc output/ folder) +const root = (function () { + let root = process.cwd(); + while (true) { + if (fs.existsSync(path.join(root, "output"))) { + return root; + } + const parent = path.join(root, ".."); + if (parent === root) { + break; + } + root = parent; + } + throw new Error("could not find root"); +})(); +// Load the tests +export function loadTests(tag) { + const filename = path.resolve(root, "testcases", tag + ".json.gz"); + return JSON.parse(zlib.gunzipSync(fs.readFileSync(filename)).toString()); +} +export function log(context, text) { + if (context && context.test && typeof (context.test._quaisLog) === "function") { + context.test._quaisLog(text); + } + else { + console.log(text); + } +} +export async function stall(duration) { + return new Promise((resolve) => { setTimeout(resolve, duration); }); +} +const ATTEMPTS = 5; +export async function retryIt(name, func) { + //const errors: Array = [ ]; + it(name, async function () { + this.timeout(ATTEMPTS * 5000); + for (let i = 0; i < ATTEMPTS; i++) { + try { + await func.call(this); + return; + } + catch (error) { + if (error.message === "sync skip; aborting execution") { + // Skipping a test; let mocha handle it + throw error; + } + else if (error.code === "ERR_ASSERTION") { + // Assertion error; let mocha scold us + throw error; + } + else { + //errors.push(error); + if (i === ATTEMPTS - 1) { + throw error; + //stats.pushRetry(i, name, error); + } + else { + await stall(500 * (1 << i)); + //stats.pushRetry(i, name, null); + } + } + } + } + // All hope is lost. + throw new Error(`Failed after ${ATTEMPTS} attempts; ${name}`); + }); +} +/* +export interface StatSet { + name: string; + retries: Array<{ message: string, error: null | Error }>; +} + +const _guard = { }; + +export class Stats { +// #stats: Array; + + constructor(guard: any) { + if (guard !== _guard) { throw new Error("private constructor"); } +// this.#stats = [ ]; + } + + #currentStats(): StatSet { + if (this.#stats.length === 0) { throw new Error("no active stats"); } + return this.#stats[this.#stats.length - 1]; + } + + pushRetry(attempt: number, line: string, error: null | Error): void { + const { retries } = this.#currentStats(); + + if (attempt > 0) { retries.pop(); } + if (retries.length < 100) { + retries.push({ + message: `${ attempt + 1 } failures: ${ line }`, + error + }); + } + } + + start(name: string): void { + this.#stats.push({ name, retries: [ ] }); + } + + end(context?: any): void { + let log = console.log.bind(console); + if (context && typeof(context._quaisLog) === "function") { + log = context._quaisLog; + } + const { name, retries } = this.#currentStats(); + if (retries.length === 0) { return; } + log(`Warning: The following tests required retries (${ name })`); + retries.forEach(({ error, message }) => { + log(" " + message); + if (error) { log(error); } + }); + } +} + +export const stats = new Stats(_guard); +*/ +//# sourceMappingURL=utils.js.map \ No newline at end of file diff --git a/lib.esm/_tests/utils.js.map b/lib.esm/_tests/utils.js.map new file mode 100644 index 00000000..1c0d2f86 --- /dev/null +++ b/lib.esm/_tests/utils.js.map @@ -0,0 +1 @@ +{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src.ts/_tests/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,0DAA0D;AAC1D,MAAM,IAAI,GAAG,CAAC;IACV,IAAI,IAAI,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAEzB,OAAO,IAAI,EAAE;QACT,IAAI,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,EAAE;YAAE,OAAO,IAAI,CAAC;SAAE;QAC9D,MAAM,MAAM,GAAG,IAAI,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,MAAM,UAAU,SAAS,CAAI,GAAW;IACrC,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,GAAG,UAAU,CAAC,CAAC;IACnE,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;AAC5E,CAAC;AAED,MAAM,UAAU,GAAG,CAAC,OAA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C,IAAI,CAAC,CAAC,CAAC,CAAC;wBAC5B,iCAAiC;qBACpC;iBACJ;aACJ;SACJ;QAED,oBAAoB;QACpB,MAAM,IAAI,KAAK,CAAC,gBAAiB,QAAS,cAAe,IAAK,EAAE,CAAC,CAAC;IACtE,CAAC,CAAC,CAAC;AACP,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqDE"} \ No newline at end of file diff --git a/lib.esm/_version.d.ts b/lib.esm/_version.d.ts new file mode 100644 index 00000000..fa420f81 --- /dev/null +++ b/lib.esm/_version.d.ts @@ -0,0 +1,5 @@ +/** + * The current version of quais. + */ +export declare const version: string; +//# sourceMappingURL=_version.d.ts.map \ No newline at end of file diff --git a/lib.esm/_version.d.ts.map b/lib.esm/_version.d.ts.map new file mode 100644 index 00000000..502b731b --- /dev/null +++ b/lib.esm/_version.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"_version.d.ts","sourceRoot":"","sources":["../src.ts/_version.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,OAAO,EAAE,MAAgB,CAAC"} \ No newline at end of file diff --git a/lib.esm/_version.js b/lib.esm/_version.js new file mode 100644 index 00000000..08ec83bf --- /dev/null +++ b/lib.esm/_version.js @@ -0,0 +1,6 @@ +/* Do NOT modify this file; see /src.ts/_admin/update-version.ts */ +/** + * The current version of quais. + */ +export const version = "0.0.1"; +//# sourceMappingURL=_version.js.map \ No newline at end of file diff --git a/lib.esm/_version.js.map b/lib.esm/_version.js.map new file mode 100644 index 00000000..360ba34f --- /dev/null +++ b/lib.esm/_version.js.map @@ -0,0 +1 @@ +{"version":3,"file":"_version.js","sourceRoot":"","sources":["../src.ts/_version.ts"],"names":[],"mappings":"AAAA,mEAAmE;AAEnE;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAW,OAAO,CAAC"} \ No newline at end of file diff --git a/lib.esm/abi/abi-coder.d.ts b/lib.esm/abi/abi-coder.d.ts new file mode 100644 index 00000000..106f2166 --- /dev/null +++ b/lib.esm/abi/abi-coder.d.ts @@ -0,0 +1,61 @@ +/** + * When sending values to or receiving values from a [[Contract]], the + * data is generally encoded using the [ABI standard](link-solc-abi). + * + * The AbiCoder provides a utility to encode values to ABI data and + * decode values from ABI data. + * + * Most of the time, developers should favour the [[Contract]] class, + * which further abstracts a lot of the finer details of ABI data. + * + * @_section api/abi/abi-coder:ABI Encoding + */ +import { Result } from "./coders/abstract-coder.js"; +import { ParamType } from "./fragments.js"; +import type { BytesLike, CallExceptionAction, CallExceptionError } from "../utils/index.js"; +/** + * The **AbiCoder** is a low-level class responsible for encoding JavaScript + * values into binary data and decoding binary data into JavaScript values. + */ +export declare class AbiCoder { + #private; + /** + * Get the default values for the given %%types%%. + * + * For example, a ``uint`` is by default ``0`` and ``bool`` + * is by default ``false``. + */ + getDefaultValue(types: ReadonlyArray): Result; + /** + * Encode the %%values%% as the %%types%% into ABI data. + * + * @returns DataHexstring + */ + encode(types: ReadonlyArray, values: ReadonlyArray): string; + /** + * Decode the ABI %%data%% as the %%types%% into values. + * + * If %%loose%% decoding is enabled, then strict padding is + * not enforced. Some older versions of Solidity incorrectly + * padded event data emitted from ``external`` functions. + */ + decode(types: ReadonlyArray, data: BytesLike, loose?: boolean): Result; + static _setDefaultMaxInflation(value: number): void; + /** + * Returns the shared singleton instance of a default [[AbiCoder]]. + * + * On the first call, the instance is created internally. + */ + static defaultAbiCoder(): AbiCoder; + /** + * Returns an quais-compatible [[CallExceptionError]] Error for the given + * result %%data%% for the [[CallExceptionAction]] %%action%% against + * the Transaction %%tx%%. + */ + static getBuiltinCallException(action: CallExceptionAction, tx: { + to?: null | string; + from?: null | string; + data?: string; + }, data: null | BytesLike): CallExceptionError; +} +//# sourceMappingURL=abi-coder.d.ts.map \ No newline at end of file diff --git a/lib.esm/abi/abi-coder.d.ts.map b/lib.esm/abi/abi-coder.d.ts.map new file mode 100644 index 00000000..0a0c483e --- /dev/null +++ b/lib.esm/abi/abi-coder.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"abi-coder.d.ts","sourceRoot":"","sources":["../../src.ts/abi/abi-coder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAMH,OAAO,EAAiB,MAAM,EAAU,MAAM,4BAA4B,CAAC;AAU3E,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAK3C,OAAO,KAAK,EACR,SAAS,EACT,mBAAmB,EAAE,kBAAkB,EAC1C,MAAM,mBAAmB,CAAC;AAuF3B;;;GAGG;AACH,qBAAa,QAAQ;;IA4CjB;;;;;OAKG;IACH,eAAe,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,GAAG,SAAS,CAAC,GAAG,MAAM;IAMjE;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,GAAG,CAAC,GAAG,MAAM;IAWpF;;;;;;OAMG;IACH,MAAM,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM;IAM1F,MAAM,CAAC,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAKnD;;;;OAIG;IACH,MAAM,CAAC,eAAe,IAAI,QAAQ;IAOlC;;;;OAIG;IACH,MAAM,CAAC,uBAAuB,CAAC,MAAM,EAAE,mBAAmB,EAAE,EAAE,EAAE;QAAE,EAAE,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,IAAI,EAAE,IAAI,GAAG,SAAS,GAAG,kBAAkB;CAG3K"} \ No newline at end of file diff --git a/lib.esm/abi/abi-coder.js b/lib.esm/abi/abi-coder.js new file mode 100644 index 00000000..4276f444 --- /dev/null +++ b/lib.esm/abi/abi-coder.js @@ -0,0 +1,206 @@ +/** + * When sending values to or receiving values from a [[Contract]], the + * data is generally encoded using the [ABI standard](link-solc-abi). + * + * The AbiCoder provides a utility to encode values to ABI data and + * decode values from ABI data. + * + * Most of the time, developers should favour the [[Contract]] class, + * which further abstracts a lot of the finer details of ABI data. + * + * @_section api/abi/abi-coder:ABI Encoding + */ +// See: https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI +import { assertArgumentCount, assertArgument } from "../utils/index.js"; +import { Reader, Writer } from "./coders/abstract-coder.js"; +import { AddressCoder } from "./coders/address.js"; +import { ArrayCoder } from "./coders/array.js"; +import { BooleanCoder } from "./coders/boolean.js"; +import { BytesCoder } from "./coders/bytes.js"; +import { FixedBytesCoder } from "./coders/fixed-bytes.js"; +import { NullCoder } from "./coders/null.js"; +import { NumberCoder } from "./coders/number.js"; +import { StringCoder } from "./coders/string.js"; +import { TupleCoder } from "./coders/tuple.js"; +import { ParamType } from "./fragments.js"; +import { getAddress } from "../address/index.js"; +import { getBytes, hexlify, makeError } from "../utils/index.js"; +// https://docs.soliditylang.org/en/v0.8.17/control-structures.html +const PanicReasons = new Map(); +PanicReasons.set(0x00, "GENERIC_PANIC"); +PanicReasons.set(0x01, "ASSERT_FALSE"); +PanicReasons.set(0x11, "OVERFLOW"); +PanicReasons.set(0x12, "DIVIDE_BY_ZERO"); +PanicReasons.set(0x21, "ENUM_RANGE_ERROR"); +PanicReasons.set(0x22, "BAD_STORAGE_DATA"); +PanicReasons.set(0x31, "STACK_UNDERFLOW"); +PanicReasons.set(0x32, "ARRAY_RANGE_ERROR"); +PanicReasons.set(0x41, "OUT_OF_MEMORY"); +PanicReasons.set(0x51, "UNINITIALIZED_FUNCTION_CALL"); +const paramTypeBytes = new RegExp(/^bytes([0-9]*)$/); +const paramTypeNumber = new RegExp(/^(u?int)([0-9]*)$/); +let defaultCoder = null; +let defaultMaxInflation = 1024; +function getBuiltinCallException(action, tx, data, abiCoder) { + let message = "missing revert data"; + let reason = null; + const invocation = null; + let revert = null; + if (data) { + message = "execution reverted"; + const bytes = getBytes(data); + data = hexlify(data); + if (bytes.length === 0) { + message += " (no data present; likely require(false) occurred"; + reason = "require(false)"; + } + else if (bytes.length % 32 !== 4) { + message += " (could not decode reason; invalid data length)"; + } + else if (hexlify(bytes.slice(0, 4)) === "0x08c379a0") { + // Error(string) + try { + reason = abiCoder.decode(["string"], bytes.slice(4))[0]; + revert = { + signature: "Error(string)", + name: "Error", + args: [reason] + }; + message += `: ${JSON.stringify(reason)}`; + } + catch (error) { + message += " (could not decode reason; invalid string data)"; + } + } + else if (hexlify(bytes.slice(0, 4)) === "0x4e487b71") { + // Panic(uint256) + try { + const code = Number(abiCoder.decode(["uint256"], bytes.slice(4))[0]); + revert = { + signature: "Panic(uint256)", + name: "Panic", + args: [code] + }; + reason = `Panic due to ${PanicReasons.get(code) || "UNKNOWN"}(${code})`; + message += `: ${reason}`; + } + catch (error) { + message += " (could not decode panic code)"; + } + } + else { + message += " (unknown custom error)"; + } + } + const transaction = { + to: (tx.to ? getAddress(tx.to) : null), + data: (tx.data || "0x") + }; + if (tx.from) { + transaction.from = getAddress(tx.from); + } + return makeError(message, "CALL_EXCEPTION", { + action, data, reason, transaction, invocation, revert + }); +} +/** + * The **AbiCoder** is a low-level class responsible for encoding JavaScript + * values into binary data and decoding binary data into JavaScript values. + */ +export class AbiCoder { + #getCoder(param) { + if (param.isArray()) { + return new ArrayCoder(this.#getCoder(param.arrayChildren), param.arrayLength, param.name); + } + if (param.isTuple()) { + return new TupleCoder(param.components.map((c) => this.#getCoder(c)), param.name); + } + switch (param.baseType) { + case "address": + return new AddressCoder(param.name); + case "bool": + return new BooleanCoder(param.name); + case "string": + return new StringCoder(param.name); + case "bytes": + return new BytesCoder(param.name); + case "": + return new NullCoder(param.name); + } + // u?int[0-9]* + let match = param.type.match(paramTypeNumber); + if (match) { + let size = parseInt(match[2] || "256"); + assertArgument(size !== 0 && size <= 256 && (size % 8) === 0, "invalid " + match[1] + " bit length", "param", param); + return new NumberCoder(size / 8, (match[1] === "int"), param.name); + } + // bytes[0-9]+ + match = param.type.match(paramTypeBytes); + if (match) { + let size = parseInt(match[1]); + assertArgument(size !== 0 && size <= 32, "invalid bytes length", "param", param); + return new FixedBytesCoder(size, param.name); + } + assertArgument(false, "invalid type", "type", param.type); + } + /** + * Get the default values for the given %%types%%. + * + * For example, a ``uint`` is by default ``0`` and ``bool`` + * is by default ``false``. + */ + getDefaultValue(types) { + const coders = types.map((type) => this.#getCoder(ParamType.from(type))); + const coder = new TupleCoder(coders, "_"); + return coder.defaultValue(); + } + /** + * Encode the %%values%% as the %%types%% into ABI data. + * + * @returns DataHexstring + */ + encode(types, values) { + assertArgumentCount(values.length, types.length, "types/values length mismatch"); + const coders = types.map((type) => this.#getCoder(ParamType.from(type))); + const coder = (new TupleCoder(coders, "_")); + const writer = new Writer(); + coder.encode(writer, values); + return writer.data; + } + /** + * Decode the ABI %%data%% as the %%types%% into values. + * + * If %%loose%% decoding is enabled, then strict padding is + * not enforced. Some older versions of Solidity incorrectly + * padded event data emitted from ``external`` functions. + */ + decode(types, data, loose) { + const coders = types.map((type) => this.#getCoder(ParamType.from(type))); + const coder = new TupleCoder(coders, "_"); + return coder.decode(new Reader(data, loose, defaultMaxInflation)); + } + static _setDefaultMaxInflation(value) { + assertArgument(typeof (value) === "number" && Number.isInteger(value), "invalid defaultMaxInflation factor", "value", value); + defaultMaxInflation = value; + } + /** + * Returns the shared singleton instance of a default [[AbiCoder]]. + * + * On the first call, the instance is created internally. + */ + static defaultAbiCoder() { + if (defaultCoder == null) { + defaultCoder = new AbiCoder(); + } + return defaultCoder; + } + /** + * Returns an quais-compatible [[CallExceptionError]] Error for the given + * result %%data%% for the [[CallExceptionAction]] %%action%% against + * the Transaction %%tx%%. + */ + static getBuiltinCallException(action, tx, data) { + return getBuiltinCallException(action, tx, data, AbiCoder.defaultAbiCoder()); + } +} +//# sourceMappingURL=abi-coder.js.map \ No newline at end of file diff --git a/lib.esm/abi/abi-coder.js.map b/lib.esm/abi/abi-coder.js.map new file mode 100644 index 00000000..db43966e --- /dev/null +++ b/lib.esm/abi/abi-coder.js.map @@ -0,0 +1 @@ +{"version":3,"file":"abi-coder.js","sourceRoot":"","sources":["../../src.ts/abi/abi-coder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,mEAAmE;AAEnE,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAExE,OAAO,EAAS,MAAM,EAAU,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAOjE,mEAAmE;AACnE,MAAM,YAAY,GAAwB,IAAI,GAAG,EAAE,CAAC;AACpD,YAAY,CAAC,GAAG,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;AACxC,YAAY,CAAC,GAAG,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;AACvC,YAAY,CAAC,GA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AAC;IACtE,CAAC;IAED,MAAM,CAAC,uBAAuB,CAAC,KAAa;QACxC,cAAc,CAAC,OAAM,CAAC,KAAK,CAAC,KAAK,QAAQ,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,oCAAoC,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;QAC5H,mBAAmB,GAAG,KAAK,CAAC;IAChC,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,eAAe;QAClB,IAAI,YAAY,IAAI,IAAI,EAAE;YACtB,YAAY,GAAG,IAAI,QAAQ,EAAE,CAAC;SACjC;QACD,OAAO,YAAY,CAAC;IACxB,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,uBAAuB,CAAC,MAA2B,EAAE,EAA+D,EAAE,IAAsB;QAC/I,OAAO,uBAAuB,CAAC,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,CAAC,eAAe,EAAE,CAAC,CAAC;IACjF,CAAC;CACJ"} \ No newline at end of file diff --git a/lib.esm/abi/bytes32.d.ts b/lib.esm/abi/bytes32.d.ts new file mode 100644 index 00000000..73455cb5 --- /dev/null +++ b/lib.esm/abi/bytes32.d.ts @@ -0,0 +1,15 @@ +/** + * About bytes32 strings... + * + * @_docloc: api/utils:Bytes32 Strings + */ +import type { BytesLike } from "../utils/index.js"; +/** + * Encodes %%text%% as a Bytes32 string. + */ +export declare function encodeBytes32String(text: string): string; +/** + * Encodes the Bytes32-encoded %%bytes%% into a string. + */ +export declare function decodeBytes32String(_bytes: BytesLike): string; +//# sourceMappingURL=bytes32.d.ts.map \ No newline at end of file diff --git a/lib.esm/abi/bytes32.d.ts.map b/lib.esm/abi/bytes32.d.ts.map new file mode 100644 index 00000000..1d56cd6f --- /dev/null +++ b/lib.esm/abi/bytes32.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"bytes32.d.ts","sourceRoot":"","sources":["../../src.ts/abi/bytes32.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAUxD;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,CAa7D"} \ No newline at end of file diff --git a/lib.esm/abi/bytes32.js b/lib.esm/abi/bytes32.js new file mode 100644 index 00000000..20d586bf --- /dev/null +++ b/lib.esm/abi/bytes32.js @@ -0,0 +1,40 @@ +/** + * About bytes32 strings... + * + * @_docloc: api/utils:Bytes32 Strings + */ +import { getBytes, toUtf8Bytes, toUtf8String, zeroPadBytes } from "../utils/index.js"; +/** + * Encodes %%text%% as a Bytes32 string. + */ +export function encodeBytes32String(text) { + // Get the bytes + const bytes = 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 zeroPadBytes(bytes, 32); +} +/** + * Encodes the Bytes32-encoded %%bytes%% into a string. + */ +export function decodeBytes32String(_bytes) { + const data = 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 toUtf8String(data.slice(0, length)); +} +//# sourceMappingURL=bytes32.js.map \ No newline at end of file diff --git a/lib.esm/abi/bytes32.js.map b/lib.esm/abi/bytes32.js.map new file mode 100644 index 00000000..98e8316f --- /dev/null +++ b/lib.esm/abi/bytes32.js.map @@ -0,0 +1 @@ +{"version":3,"file":"bytes32.js","sourceRoot":"","sources":["../../src.ts/abi/bytes32.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACH,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EACpD,MAAM,mBAAmB,CAAC;AAI3B;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAY;IAE5C,gBAAgB;IAChB,MAAM,KAAK,GAAG,WAAW,CAAC,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,YAAY,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AACnC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAiB;IACjD,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEvC,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,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;AAC/C,CAAC"} \ No newline at end of file diff --git a/lib.esm/abi/coders/abstract-coder.d.ts b/lib.esm/abi/coders/abstract-coder.d.ts new file mode 100644 index 00000000..3eaa07c2 --- /dev/null +++ b/lib.esm/abi/coders/abstract-coder.d.ts @@ -0,0 +1,121 @@ +import type { BigNumberish, BytesLike } from "../../utils/index.js"; +/** + * @_ignore: + */ +export declare const WordSize: number; +/** + * A [[Result]] is a sub-class of Array, which allows accessing any + * of its values either positionally by its index or, if keys are + * provided by its name. + * + * @_docloc: api/abi + */ +export declare class Result extends Array { + #private; + [K: string | number]: any; + /** + * @private + */ + constructor(...args: Array); + /** + * Returns the Result as a normal Array. + * + * This will throw if there are any outstanding deferred + * errors. + */ + toArray(): Array; + /** + * Returns the Result as an Object with each name-value pair. + * + * This will throw if any value is unnamed, or if there are + * any outstanding deferred errors. + */ + toObject(): Record; + /** + * @_ignore + */ + slice(start?: number | undefined, end?: number | undefined): Result; + /** + * @_ignore + */ + filter(callback: (el: any, index: number, array: Result) => boolean, thisArg?: any): Result; + /** + * @_ignore + */ + map(callback: (el: any, index: number, array: Result) => T, thisArg?: any): Array; + /** + * Returns the value for %%name%%. + * + * Since it is possible to have a key whose name conflicts with + * a method on a [[Result]] or its superclass Array, or any + * JavaScript keyword, this ensures all named values are still + * accessible by name. + */ + getValue(name: string): any; + /** + * Creates a new [[Result]] for %%items%% with each entry + * also accessible by its corresponding name in %%keys%%. + */ + static fromItems(items: Array, keys?: Array): Result; +} +/** + * Returns all errors found in a [[Result]]. + * + * Since certain errors encountered when creating a [[Result]] do + * not impact the ability to continue parsing data, they are + * deferred until they are actually accessed. Hence a faulty string + * in an Event that is never used does not impact the program flow. + * + * However, sometimes it may be useful to access, identify or + * validate correctness of a [[Result]]. + * + * @_docloc api/abi + */ +export declare function checkResultErrors(result: Result): Array<{ + path: Array; + error: Error; +}>; +/** + * @_ignore + */ +export declare abstract class Coder { + readonly name: string; + readonly type: string; + readonly localName: string; + readonly dynamic: boolean; + constructor(name: string, type: string, localName: string, dynamic: boolean); + _throwError(message: string, value: any): never; + abstract encode(writer: Writer, value: any): number; + abstract decode(reader: Reader): any; + abstract defaultValue(): any; +} +/** + * @_ignore + */ +export declare class Writer { + #private; + constructor(); + get data(): string; + get length(): number; + appendWriter(writer: Writer): number; + writeBytes(value: BytesLike): number; + writeValue(value: BigNumberish): number; + writeUpdatableValue(): (value: BigNumberish) => void; +} +/** + * @_ignore + */ +export declare class Reader { + #private; + readonly allowLoose: boolean; + constructor(data: BytesLike, allowLoose?: boolean, maxInflation?: number); + get data(): string; + get dataLength(): number; + get consumed(): number; + get bytes(): Uint8Array; + subReader(offset: number): Reader; + readBytes(length: number, loose?: boolean): Uint8Array; + readValue(): bigint; + readIndex(): number; +} +//# sourceMappingURL=abstract-coder.d.ts.map \ No newline at end of file diff --git a/lib.esm/abi/coders/abstract-coder.d.ts.map b/lib.esm/abi/coders/abstract-coder.d.ts.map new file mode 100644 index 00000000..4e4cc78c --- /dev/null +++ b/lib.esm/abi/coders/abstract-coder.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"abstract-coder.d.ts","sourceRoot":"","sources":["../../../src.ts/abi/coders/abstract-coder.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEpE;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,MAAW,CAAC;AAenC;;;;;;GAMG;AACH,qBAAa,MAAO,SAAQ,KAAK,CAAC,GAAG,CAAC;;IAGlC,CAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAI,GAAG,CAAA;IAE3B;;OAEG;gBACS,GAAG,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC;IAyF/B;;;;;OAKG;IACH,OAAO,IAAI,KAAK,CAAC,GAAG,CAAC;IASrB;;;;;OAKG;IACH,QAAQ,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAe/B;;OAEG;IACH,KAAK,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM;IAuBnE;;OAEG;IACH,MAAM,CAAC,QAAQ,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,MAAM;IAiB3F;;OAEG;IACH,GAAG,CAAC,CAAC,SA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AAI,IAAI,MAAM,CAEjB;IACD,IAAI,MAAM,IAAI,MAAM,CAA6B;IAQjD,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IAKpC,UAAU,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM;IAUpC,UAAU,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM;IAMvC,mBAAmB,IAAI,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI;CAQvD;AAED;;GAEG;AACH,qBAAa,MAAM;;IAKf,QAAQ,CAAC,UAAU,EAAG,OAAO,CAAC;gBASlB,IAAI,EAAE,SAAS,EAAE,UAAU,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,EAAE,MAAM;IAWxE,IAAI,IAAI,IAAI,MAAM,CAAgC;IAClD,IAAI,UAAU,IAAI,MAAM,CAA8B;IACtD,IAAI,QAAQ,IAAI,MAAM,CAAyB;IAC/C,IAAI,KAAK,IAAI,UAAU,CAAuC;IAkC9D,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IAOjC,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,UAAU;IAStD,SAAS,IAAI,MAAM;IAInB,SAAS,IAAI,MAAM;CAGtB"} \ No newline at end of file diff --git a/lib.esm/abi/coders/abstract-coder.js b/lib.esm/abi/coders/abstract-coder.js new file mode 100644 index 00000000..fcfb5845 --- /dev/null +++ b/lib.esm/abi/coders/abstract-coder.js @@ -0,0 +1,422 @@ +import { defineProperties, concat, getBytesCopy, getNumber, hexlify, toBeArray, toBigInt, toNumber, assert, assertArgument } from "../../utils/index.js"; +/** + * @_ignore: + */ +export const WordSize = 32; +const Padding = new Uint8Array(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 = {}; +function throwError(name, error) { + const wrapped = new Error(`deferred error during ABI decoding triggered accessing ${name}`); + wrapped.error = error; + throw wrapped; +} +/** + * A [[Result]] is a sub-class of Array, which allows accessing any + * of its values either positionally by its index or, if keys are + * provided by its name. + * + * @_docloc: api/abi + */ +export class Result extends Array { + #names; + /** + * @private + */ + constructor(...args) { + // To properly sub-class Array so the other built-in + // functions work, the constructor has to behave fairly + // well. So, in the event we are created via fromItems() + // we build the read-only Result object we want, but on + // any other input, we use the default constructor + // constructor(guard: any, items: Array, keys?: Array); + const guard = args[0]; + let items = args[1]; + let names = (args[2] || []).slice(); + let wrap = true; + if (guard !== _guard) { + items = args; + names = []; + wrap = false; + } + // Can't just pass in ...items since an array of length 1 + // is a special case in the super. + super(items.length); + items.forEach((item, index) => { this[index] = item; }); + // Find all unique keys + const nameCounts = names.reduce((accum, name) => { + if (typeof (name) === "string") { + accum.set(name, (accum.get(name) || 0) + 1); + } + return accum; + }, (new Map())); + // Remove any key thats not unique + this.#names = Object.freeze(items.map((item, index) => { + const name = names[index]; + if (name != null && nameCounts.get(name) === 1) { + return name; + } + return null; + })); + if (!wrap) { + return; + } + // A wrapped Result is immutable + Object.freeze(this); + // Proxy indices and names so we can trap deferred errors + return new Proxy(this, { + get: (target, prop, receiver) => { + if (typeof (prop) === "string") { + // Index accessor + if (prop.match(/^[0-9]+$/)) { + const index = getNumber(prop, "%index"); + if (index < 0 || index >= this.length) { + throw new RangeError("out of result range"); + } + const item = target[index]; + if (item instanceof Error) { + throwError(`index ${index}`, item); + } + return item; + } + // Pass important checks (like `then` for Promise) through + if (passProperties.indexOf(prop) >= 0) { + return Reflect.get(target, prop, receiver); + } + const value = target[prop]; + if (value instanceof Function) { + // Make sure functions work with private variables + // See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy#no_private_property_forwarding + return function (...args) { + return value.apply((this === receiver) ? target : this, args); + }; + } + else if (!(prop in target)) { + // Possible name accessor + return target.getValue.apply((this === receiver) ? target : this, [prop]); + } + } + return Reflect.get(target, prop, receiver); + } + }); + } + /** + * Returns the Result as a normal Array. + * + * This will throw if there are any outstanding deferred + * errors. + */ + toArray() { + const result = []; + this.forEach((item, index) => { + if (item instanceof Error) { + throwError(`index ${index}`, item); + } + result.push(item); + }); + return result; + } + /** + * Returns the Result as an Object with each name-value pair. + * + * This will throw if any value is unnamed, or if there are + * any outstanding deferred errors. + */ + toObject() { + return this.#names.reduce((accum, name, index) => { + assert(name != null, "value at index ${ index } unnamed", "UNSUPPORTED_OPERATION", { + operation: "toObject()" + }); + // Add values for names that don't conflict + if (!(name in accum)) { + accum[name] = this.getValue(name); + } + return accum; + }, {}); + } + /** + * @_ignore + */ + slice(start, end) { + if (start == null) { + start = 0; + } + if (start < 0) { + start += this.length; + if (start < 0) { + start = 0; + } + } + if (end == null) { + end = this.length; + } + if (end < 0) { + end += this.length; + if (end < 0) { + end = 0; + } + } + if (end > this.length) { + end = this.length; + } + const result = [], names = []; + for (let i = start; i < end; i++) { + result.push(this[i]); + names.push(this.#names[i]); + } + return new Result(_guard, result, names); + } + /** + * @_ignore + */ + filter(callback, thisArg) { + const result = [], names = []; + for (let i = 0; i < this.length; i++) { + const item = this[i]; + if (item instanceof Error) { + throwError(`index ${i}`, item); + } + if (callback.call(thisArg, item, i, this)) { + result.push(item); + names.push(this.#names[i]); + } + } + return new Result(_guard, result, names); + } + /** + * @_ignore + */ + map(callback, thisArg) { + const result = []; + for (let i = 0; i < this.length; i++) { + const item = this[i]; + if (item instanceof Error) { + throwError(`index ${i}`, item); + } + result.push(callback.call(thisArg, item, i, this)); + } + return result; + } + /** + * Returns the value for %%name%%. + * + * Since it is possible to have a key whose name conflicts with + * a method on a [[Result]] or its superclass Array, or any + * JavaScript keyword, this ensures all named values are still + * accessible by name. + */ + getValue(name) { + const index = this.#names.indexOf(name); + if (index === -1) { + return undefined; + } + const value = this[index]; + if (value instanceof Error) { + throwError(`property ${JSON.stringify(name)}`, value.error); + } + return value; + } + /** + * Creates a new [[Result]] for %%items%% with each entry + * also accessible by its corresponding name in %%keys%%. + */ + static fromItems(items, keys) { + return new Result(_guard, items, keys); + } +} +/** + * Returns all errors found in a [[Result]]. + * + * Since certain errors encountered when creating a [[Result]] do + * not impact the ability to continue parsing data, they are + * deferred until they are actually accessed. Hence a faulty string + * in an Event that is never used does not impact the program flow. + * + * However, sometimes it may be useful to access, identify or + * validate correctness of a [[Result]]. + * + * @_docloc api/abi + */ +export 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; +} +function getValue(value) { + let bytes = toBeArray(value); + assert(bytes.length <= WordSize, "value out-of-bounds", "BUFFER_OVERRUN", { buffer: bytes, length: WordSize, offset: bytes.length }); + if (bytes.length !== WordSize) { + bytes = getBytesCopy(concat([Padding.slice(bytes.length % WordSize), bytes])); + } + return bytes; +} +/** + * @_ignore + */ +export 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) { + defineProperties(this, { name, type, localName, dynamic }, { + name: "string", type: "string", localName: "string", dynamic: "boolean" + }); + } + _throwError(message, value) { + assertArgument(false, message, this.localName, value); + } +} +/** + * @_ignore + */ +export class Writer { + // An array of WordSize lengthed objects to concatenation + #data; + #dataLength; + constructor() { + this.#data = []; + this.#dataLength = 0; + } + get data() { + return 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(getBytesCopy(writer.data)); + } + // Arrayish item; pad on the right to *nearest* WordSize + writeBytes(value) { + let bytes = getBytesCopy(value); + const paddingOffset = bytes.length % WordSize; + if (paddingOffset) { + bytes = getBytesCopy(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 += WordSize; + return (value) => { + this.#data[offset] = getValue(value); + }; + } +} +/** + * @_ignore + */ +export 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; + #bytesRead; + #parent; + #maxInflation; + constructor(data, allowLoose, maxInflation) { + defineProperties(this, { allowLoose: !!allowLoose }); + this.#data = getBytesCopy(data); + this.#bytesRead = 0; + this.#parent = null; + this.#maxInflation = (maxInflation != null) ? maxInflation : 1024; + this.#offset = 0; + } + get data() { return hexlify(this.#data); } + get dataLength() { return this.#data.length; } + get consumed() { return this.#offset; } + get bytes() { return new Uint8Array(this.#data); } + #incrementBytesRead(count) { + if (this.#parent) { + return this.#parent.#incrementBytesRead(count); + } + this.#bytesRead += count; + // Check for excessive inflation (see: #4537) + assert(this.#maxInflation < 1 || this.#bytesRead <= this.#maxInflation * this.dataLength, `compressed ABI data exceeds inflation ratio of ${this.#maxInflation} ( see: https:/\/github.com/ethers-io/ethers.js/issues/4537 )`, "BUFFER_OVERRUN", { + buffer: getBytesCopy(this.#data), offset: this.#offset, + length: count, info: { + bytesRead: this.#bytesRead, + dataLength: this.dataLength + } + }); + } + #peekBytes(offset, length, loose) { + let alignedLength = Math.ceil(length / WordSize) * WordSize; + if (this.#offset + alignedLength > this.#data.length) { + if (this.allowLoose && loose && this.#offset + length <= this.#data.length) { + alignedLength = length; + } + else { + assert(false, "data out-of-bounds", "BUFFER_OVERRUN", { + buffer: 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) { + const reader = new Reader(this.#data.slice(this.#offset + offset), this.allowLoose, this.#maxInflation); + reader.#parent = this; + return reader; + } + // Read bytes + readBytes(length, loose) { + let bytes = this.#peekBytes(0, length, !!loose); + this.#incrementBytesRead(length); + 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 toBigInt(this.readBytes(WordSize)); + } + readIndex() { + return toNumber(this.readBytes(WordSize)); + } +} +//# sourceMappingURL=abstract-coder.js.map \ No newline at end of file diff --git a/lib.esm/abi/coders/abstract-coder.js.map b/lib.esm/abi/coders/abstract-coder.js.map new file mode 100644 index 00000000..5be124dd --- /dev/null +++ b/lib.esm/abi/coders/abstract-coder.js.map @@ -0,0 +1 @@ +{"version":3,"file":"abstract-coder.js","sourceRoot":"","sources":["../../../src.ts/abi/coders/abstract-coder.ts"],"names":[],"mappings":"AACA,OAAO,EACH,gBAAgB,EAAE,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,OAAO,EAC1D,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAC7B,MAAM,EAAE,cAAc,EACzB,MAAM,sBAAsB,CAAC;AAI9B;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAW,EAAE,CAAC;AACnC,MAAM,OAAO,GAAG,IAAI,UAAU,CAAC,QAAQ,CAAC,CAAC;AAEzC,qEAAqE;AACrE,iEAAiE;AACjE,MAAM,cAAc,GAAG,CAAE,MAAM,CAAE,CAAC;AAElC,MAAM,MAAM,GAAG,EAAG,CAAC;AAEnB,SAAS,UAAU,CAAC,IAAY,EAAE,KAAY;IAC1C,MAAM,OAAO,GAAG,IAAI,KAAK,CAAC,0DAA2D,IAAK,EAAE,CAAC,CAAC;IACxF,OAAQ,CAAC,KAAK,GAAG,KAAK,CAAC;IAC7B,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EAAE,IAAI,CAAC,OAAO,GAAG,aAAa;iBACvC,CAAC,CAAC;aACN;SACJ;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,GAAG,aAAa,CAAC,CAAA;IACvE,CAAC;IAED,gEAAgE;IAChE,SAAS,CAAC,MAAc;QACpB,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QACxG,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC;QACtB,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,aAAa;IACb,SAAS,CAAC,MAAc,EAAE,KAAe;QACrC,IAAI,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC;QAChD,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC;QACjC,IAAI,CAAC,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC;QAC7B,oDAAoD;QACpD,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IAClC,CAAC;IAED,wBAAwB;IACxB,SAAS;QACL,OAAO,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC9C,CAAC;IAED,SAAS;QACL,OAAO,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC9C,CAAC;CACJ"} \ No newline at end of file diff --git a/lib.esm/abi/coders/address.d.ts b/lib.esm/abi/coders/address.d.ts new file mode 100644 index 00000000..8befac03 --- /dev/null +++ b/lib.esm/abi/coders/address.d.ts @@ -0,0 +1,13 @@ +import { Typed } from "../typed.js"; +import { Coder } from "./abstract-coder.js"; +import type { Reader, Writer } from "./abstract-coder.js"; +/** + * @_ignore + */ +export declare class AddressCoder extends Coder { + constructor(localName: string); + defaultValue(): string; + encode(writer: Writer, _value: string | Typed): number; + decode(reader: Reader): any; +} +//# sourceMappingURL=address.d.ts.map \ No newline at end of file diff --git a/lib.esm/abi/coders/address.d.ts.map b/lib.esm/abi/coders/address.d.ts.map new file mode 100644 index 00000000..f86c8f18 --- /dev/null +++ b/lib.esm/abi/coders/address.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../../src.ts/abi/coders/address.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAG1D;;GAEG;AACH,qBAAa,YAAa,SAAQ,KAAK;gBAEvB,SAAS,EAAE,MAAM;IAI7B,YAAY,IAAI,MAAM;IAItB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,KAAK,GAAG,MAAM;IAUtD,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG;CAG9B"} \ No newline at end of file diff --git a/lib.esm/abi/coders/address.js b/lib.esm/abi/coders/address.js new file mode 100644 index 00000000..445029c9 --- /dev/null +++ b/lib.esm/abi/coders/address.js @@ -0,0 +1,29 @@ +import { getAddress } from "../../address/index.js"; +import { toBeHex } from "../../utils/maths.js"; +import { Typed } from "../typed.js"; +import { Coder } from "./abstract-coder.js"; +/** + * @_ignore + */ +export class AddressCoder extends Coder { + constructor(localName) { + super("address", "address", localName, false); + } + defaultValue() { + return "0x0000000000000000000000000000000000000000"; + } + encode(writer, _value) { + let value = Typed.dereference(_value, "string"); + try { + value = getAddress(value); + } + catch (error) { + return this._throwError(error.message, _value); + } + return writer.writeValue(value); + } + decode(reader) { + return getAddress(toBeHex(reader.readValue(), 20)); + } +} +//# sourceMappingURL=address.js.map \ No newline at end of file diff --git a/lib.esm/abi/coders/address.js.map b/lib.esm/abi/coders/address.js.map new file mode 100644 index 00000000..4d5cae70 --- /dev/null +++ b/lib.esm/abi/coders/address.js.map @@ -0,0 +1 @@ +{"version":3,"file":"address.js","sourceRoot":"","sources":["../../../src.ts/abi/coders/address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAK5C;;GAEG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;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,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QAChD,IAAI;YACA,KAAK,GAAG,UAAU,CAAC,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,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;IACvD,CAAC;CACJ"} \ No newline at end of file diff --git a/lib.esm/abi/coders/anonymous.d.ts b/lib.esm/abi/coders/anonymous.d.ts new file mode 100644 index 00000000..554bf03f --- /dev/null +++ b/lib.esm/abi/coders/anonymous.d.ts @@ -0,0 +1,15 @@ +import { Coder } from "./abstract-coder.js"; +import type { Reader, Writer } from "./abstract-coder.js"; +/** + * Clones the functionality of an existing Coder, but without a localName + * + * @_ignore + */ +export declare class AnonymousCoder extends Coder { + private coder; + constructor(coder: Coder); + defaultValue(): any; + encode(writer: Writer, value: any): number; + decode(reader: Reader): any; +} +//# sourceMappingURL=anonymous.d.ts.map \ No newline at end of file diff --git a/lib.esm/abi/coders/anonymous.d.ts.map b/lib.esm/abi/coders/anonymous.d.ts.map new file mode 100644 index 00000000..f150f060 --- /dev/null +++ b/lib.esm/abi/coders/anonymous.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"anonymous.d.ts","sourceRoot":"","sources":["../../../src.ts/abi/coders/anonymous.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE1D;;;;GAIG;AACH,qBAAa,cAAe,SAAQ,KAAK;IACrC,OAAO,CAAC,KAAK,CAAQ;gBAET,KAAK,EAAE,KAAK;IAKxB,YAAY,IAAI,GAAG;IAInB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,MAAM;IAI1C,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG;CAG9B"} \ No newline at end of file diff --git a/lib.esm/abi/coders/anonymous.js b/lib.esm/abi/coders/anonymous.js new file mode 100644 index 00000000..b6d95326 --- /dev/null +++ b/lib.esm/abi/coders/anonymous.js @@ -0,0 +1,23 @@ +import { Coder } from "./abstract-coder.js"; +/** + * Clones the functionality of an existing Coder, but without a localName + * + * @_ignore + */ +export class AnonymousCoder extends 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); + } +} +//# sourceMappingURL=anonymous.js.map \ No newline at end of file diff --git a/lib.esm/abi/coders/anonymous.js.map b/lib.esm/abi/coders/anonymous.js.map new file mode 100644 index 00000000..ac81d99b --- /dev/null +++ b/lib.esm/abi/coders/anonymous.js.map @@ -0,0 +1 @@ +{"version":3,"file":"anonymous.js","sourceRoot":"","sources":["../../../src.ts/abi/coders/anonymous.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAI5C;;;;GAIG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK;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"} \ No newline at end of file diff --git a/lib.esm/abi/coders/array.d.ts b/lib.esm/abi/coders/array.d.ts new file mode 100644 index 00000000..954c4e17 --- /dev/null +++ b/lib.esm/abi/coders/array.d.ts @@ -0,0 +1,25 @@ +import { Typed } from "../typed.js"; +import { Coder, Result, Writer } from "./abstract-coder.js"; +import type { Reader } from "./abstract-coder.js"; +/** + * @_ignore + */ +export declare function pack(writer: Writer, coders: ReadonlyArray, values: Array | { + [name: string]: any; +}): number; +/** + * @_ignore + */ +export declare function unpack(reader: Reader, coders: ReadonlyArray): Result; +/** + * @_ignore + */ +export declare class ArrayCoder extends Coder { + readonly coder: Coder; + readonly length: number; + constructor(coder: Coder, length: number, localName: string); + defaultValue(): Array; + encode(writer: Writer, _value: Array | Typed): number; + decode(reader: Reader): any; +} +//# sourceMappingURL=array.d.ts.map \ No newline at end of file diff --git a/lib.esm/abi/coders/array.d.ts.map b/lib.esm/abi/coders/array.d.ts.map new file mode 100644 index 00000000..c3a6d622 --- /dev/null +++ b/lib.esm/abi/coders/array.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../../src.ts/abi/coders/array.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,OAAO,EAAE,KAAK,EAAE,MAAM,EAAY,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAGtE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAElD;;GAEG;AACH,wBAAgB,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG;IAAE,CAAE,IAAI,EAAE,MAAM,GAAI,GAAG,CAAA;CAAE,GAAG,MAAM,CA2DzH;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,CAAC,KAAK,CAAC,GAAG,MAAM,CAoD3E;AAED;;GAEG;AACH,qBAAa,UAAW,SAAQ,KAAK;IACjC,QAAQ,CAAC,KAAK,EAAG,KAAK,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAG,MAAM,CAAC;gBAEb,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;IAO3D,YAAY,IAAI,KAAK,CAAC,GAAG,CAAC;IAW1B,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,GAAG,MAAM;IAsB1D,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG;CAkB9B"} \ No newline at end of file diff --git a/lib.esm/abi/coders/array.js b/lib.esm/abi/coders/array.js new file mode 100644 index 00000000..576f40f1 --- /dev/null +++ b/lib.esm/abi/coders/array.js @@ -0,0 +1,159 @@ +import { defineProperties, isError, assert, assertArgument, assertArgumentCount } from "../../utils/index.js"; +import { Typed } from "../typed.js"; +import { Coder, Result, WordSize, Writer } from "./abstract-coder.js"; +import { AnonymousCoder } from "./anonymous.js"; +/** + * @_ignore + */ +export 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; + assert(name, "cannot encode object for signature with missing names", "INVALID_ARGUMENT", { argument: "values", info: { coder }, value: values }); + assert(!unique[name], "cannot encode object for signature with duplicate names", "INVALID_ARGUMENT", { argument: "values", info: { coder }, value: values }); + unique[name] = true; + return values[name]; + }); + } + else { + assertArgument(false, "invalid tuple value", "tuple", values); + } + assertArgument(coders.length === arrayValues.length, "types/value length mismatch", "tuple", values); + let staticWriter = new Writer(); + let dynamicWriter = new 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; +} +/** + * @_ignore + */ +export 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 (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 (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 Result.fromItems(values, keys); +} +/** + * @_ignore + */ +export class ArrayCoder extends 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); + 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.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); + } + 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. + assert(count * WordSize <= reader.dataLength, "insufficient data length", "BUFFER_OVERRUN", { buffer: reader.bytes, offset: count * WordSize, length: reader.dataLength }); + } + let coders = []; + for (let i = 0; i < count; i++) { + coders.push(new AnonymousCoder(this.coder)); + } + return unpack(reader, coders); + } +} +//# sourceMappingURL=array.js.map \ No newline at end of file diff --git a/lib.esm/abi/coders/array.js.map b/lib.esm/abi/coders/array.js.map new file mode 100644 index 00000000..5cab086f --- /dev/null +++ b/lib.esm/abi/coders/array.js.map @@ -0,0 +1 @@ +{"version":3,"file":"array.js","sourceRoot":"","sources":["../../../src.ts/abi/coders/array.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,gBAAgB,EAAE,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,mBAAmB,EACzE,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAIhD;;GAEG;AACH,MAAM,UAAU,IAAI,CAAC,MAAc,EAAE,MAA4B,EAAE,MAA8C;IAC7G,IAAI,WAAW,GAAe,EAAG,CAAC;IAElC,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QACxB,WAAW,GAAG,MAAM,CAAC;KAEvB;SAAM,IAAI,MAAM,IAAI,OAAM,CAAC,MAAM,CAAC,KAAK,QAAQ,EAAE;QAC9C,IAAI,MAAM,GAAkC,EAAG,CAAC;QAEhD,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;YAC/B,MAAM,IAAI,GAAG,KAAK,CAAC,SAAS,CAAC;YAC7B,MAAM,CAAC,IAAI,EAAE,uDAAuD,EAChE,kBAAkB,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;YAEhF,MAAM,CAAC,CA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;IAED,MAAM,CAAC,MAAc;QACjB,IAAI,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC;QACxB,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE;YACd,KAAK,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;YAE3B,sDAAsD;YACtD,wDAAwD;YACxD,yDAAyD;YACzD,sDAAsD;YACtD,4DAA4D;YAC5D,MAAM,CAAC,KAAK,GAAG,QAAQ,IAAI,MAAM,CAAC,UAAU,EAAE,0BAA0B,EACpE,gBAAgB,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,GAAG,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;SACxG;QACD,IAAI,MAAM,GAAiB,EAAE,CAAC;QAC9B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE;YAAE,MAAM,CAAC,IAAI,CAAC,IAAI,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;SAAE;QAEhF,OAAO,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,CAAC;CACJ"} \ No newline at end of file diff --git a/lib.esm/abi/coders/boolean.d.ts b/lib.esm/abi/coders/boolean.d.ts new file mode 100644 index 00000000..f073e37e --- /dev/null +++ b/lib.esm/abi/coders/boolean.d.ts @@ -0,0 +1,13 @@ +import { Typed } from "../typed.js"; +import { Coder } from "./abstract-coder.js"; +import type { Reader, Writer } from "./abstract-coder.js"; +/** + * @_ignore + */ +export declare class BooleanCoder extends Coder { + constructor(localName: string); + defaultValue(): boolean; + encode(writer: Writer, _value: boolean | Typed): number; + decode(reader: Reader): any; +} +//# sourceMappingURL=boolean.d.ts.map \ No newline at end of file diff --git a/lib.esm/abi/coders/boolean.d.ts.map b/lib.esm/abi/coders/boolean.d.ts.map new file mode 100644 index 00000000..b1b5811e --- /dev/null +++ b/lib.esm/abi/coders/boolean.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"boolean.d.ts","sourceRoot":"","sources":["../../../src.ts/abi/coders/boolean.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE1D;;GAEG;AACH,qBAAa,YAAa,SAAQ,KAAK;gBAEvB,SAAS,EAAE,MAAM;IAI7B,YAAY,IAAI,OAAO;IAIvB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,KAAK,GAAG,MAAM;IAKvD,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG;CAG9B"} \ No newline at end of file diff --git a/lib.esm/abi/coders/boolean.js b/lib.esm/abi/coders/boolean.js new file mode 100644 index 00000000..3992319f --- /dev/null +++ b/lib.esm/abi/coders/boolean.js @@ -0,0 +1,21 @@ +import { Typed } from "../typed.js"; +import { Coder } from "./abstract-coder.js"; +/** + * @_ignore + */ +export class BooleanCoder extends Coder { + constructor(localName) { + super("bool", "bool", localName, false); + } + defaultValue() { + return false; + } + encode(writer, _value) { + const value = Typed.dereference(_value, "bool"); + return writer.writeValue(value ? 1 : 0); + } + decode(reader) { + return !!reader.readValue(); + } +} +//# sourceMappingURL=boolean.js.map \ No newline at end of file diff --git a/lib.esm/abi/coders/boolean.js.map b/lib.esm/abi/coders/boolean.js.map new file mode 100644 index 00000000..52b0ce29 --- /dev/null +++ b/lib.esm/abi/coders/boolean.js.map @@ -0,0 +1 @@ +{"version":3,"file":"boolean.js","sourceRoot":"","sources":["../../../src.ts/abi/coders/boolean.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAI5C;;GAEG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;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,KAAK,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"} \ No newline at end of file diff --git a/lib.esm/abi/coders/bytes.d.ts b/lib.esm/abi/coders/bytes.d.ts new file mode 100644 index 00000000..1e554582 --- /dev/null +++ b/lib.esm/abi/coders/bytes.d.ts @@ -0,0 +1,19 @@ +import { Coder } from "./abstract-coder.js"; +import type { Reader, Writer } from "./abstract-coder.js"; +/** + * @_ignore + */ +export declare class DynamicBytesCoder extends Coder { + constructor(type: string, localName: string); + defaultValue(): string; + encode(writer: Writer, value: any): number; + decode(reader: Reader): any; +} +/** + * @_ignore + */ +export declare class BytesCoder extends DynamicBytesCoder { + constructor(localName: string); + decode(reader: Reader): any; +} +//# sourceMappingURL=bytes.d.ts.map \ No newline at end of file diff --git a/lib.esm/abi/coders/bytes.d.ts.map b/lib.esm/abi/coders/bytes.d.ts.map new file mode 100644 index 00000000..f1696167 --- /dev/null +++ b/lib.esm/abi/coders/bytes.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"bytes.d.ts","sourceRoot":"","sources":["../../../src.ts/abi/coders/bytes.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAG1D;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;gBAC5B,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;IAI3C,YAAY,IAAI,MAAM;IAItB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,MAAM;IAO1C,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG;CAG9B;AAED;;GAEG;AACH,qBAAa,UAAW,SAAQ,iBAAiB;gBACjC,SAAS,EAAE,MAAM;IAI7B,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG;CAG9B"} \ No newline at end of file diff --git a/lib.esm/abi/coders/bytes.js b/lib.esm/abi/coders/bytes.js new file mode 100644 index 00000000..01aad879 --- /dev/null +++ b/lib.esm/abi/coders/bytes.js @@ -0,0 +1,34 @@ +import { getBytesCopy, hexlify } from "../../utils/index.js"; +import { Coder } from "./abstract-coder.js"; +/** + * @_ignore + */ +export class DynamicBytesCoder extends Coder { + constructor(type, localName) { + super(type, type, localName, true); + } + defaultValue() { + return "0x"; + } + encode(writer, value) { + value = getBytesCopy(value); + let length = writer.writeValue(value.length); + length += writer.writeBytes(value); + return length; + } + decode(reader) { + return reader.readBytes(reader.readIndex(), true); + } +} +/** + * @_ignore + */ +export class BytesCoder extends DynamicBytesCoder { + constructor(localName) { + super("bytes", localName); + } + decode(reader) { + return hexlify(super.decode(reader)); + } +} +//# sourceMappingURL=bytes.js.map \ No newline at end of file diff --git a/lib.esm/abi/coders/bytes.js.map b/lib.esm/abi/coders/bytes.js.map new file mode 100644 index 00000000..d3462ecf --- /dev/null +++ b/lib.esm/abi/coders/bytes.js.map @@ -0,0 +1 @@ +{"version":3,"file":"bytes.js","sourceRoot":"","sources":["../../../src.ts/abi/coders/bytes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE7D,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAK5C;;GAEG;AACH,MAAM,OAAO,iBAAkB,SAAQ,KAAK;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,YAAY,CAAC,KAAK,CAAC,CAAC;QAC5B,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;AAED;;GAEG;AACH,MAAM,OAAO,UAAW,SAAQ,iBAAiB;IAC7C,YAAY,SAAiB;QACzB,KAAK,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IAC9B,CAAC;IAED,MAAM,CAAC,MAAc;QACjB,OAAO,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;IACzC,CAAC;CACJ"} \ No newline at end of file diff --git a/lib.esm/abi/coders/fixed-bytes.d.ts b/lib.esm/abi/coders/fixed-bytes.d.ts new file mode 100644 index 00000000..5c485fef --- /dev/null +++ b/lib.esm/abi/coders/fixed-bytes.d.ts @@ -0,0 +1,15 @@ +import { Typed } from "../typed.js"; +import { Coder } from "./abstract-coder.js"; +import type { BytesLike } from "../../utils/index.js"; +import type { Reader, Writer } from "./abstract-coder.js"; +/** + * @_ignore + */ +export declare class FixedBytesCoder extends Coder { + readonly size: number; + constructor(size: number, localName: string); + defaultValue(): string; + encode(writer: Writer, _value: BytesLike | Typed): number; + decode(reader: Reader): any; +} +//# sourceMappingURL=fixed-bytes.d.ts.map \ No newline at end of file diff --git a/lib.esm/abi/coders/fixed-bytes.d.ts.map b/lib.esm/abi/coders/fixed-bytes.d.ts.map new file mode 100644 index 00000000..fcf0893d --- /dev/null +++ b/lib.esm/abi/coders/fixed-bytes.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"fixed-bytes.d.ts","sourceRoot":"","sources":["../../../src.ts/abi/coders/fixed-bytes.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAG1D;;GAEG;AACH,qBAAa,eAAgB,SAAQ,KAAK;IACtC,QAAQ,CAAC,IAAI,EAAG,MAAM,CAAC;gBAEX,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;IAM3C,YAAY,IAAI,MAAM;IAItB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,GAAG,KAAK,GAAG,MAAM;IAMzD,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG;CAG9B"} \ No newline at end of file diff --git a/lib.esm/abi/coders/fixed-bytes.js b/lib.esm/abi/coders/fixed-bytes.js new file mode 100644 index 00000000..08dd20b6 --- /dev/null +++ b/lib.esm/abi/coders/fixed-bytes.js @@ -0,0 +1,28 @@ +import { defineProperties, getBytesCopy, hexlify } from "../../utils/index.js"; +import { Typed } from "../typed.js"; +import { Coder } from "./abstract-coder.js"; +/** + * @_ignore + */ +export class FixedBytesCoder extends Coder { + size; + constructor(size, localName) { + let name = "bytes" + String(size); + super(name, name, localName, false); + defineProperties(this, { size }, { size: "number" }); + } + defaultValue() { + return ("0x0000000000000000000000000000000000000000000000000000000000000000").substring(0, 2 + this.size * 2); + } + encode(writer, _value) { + let data = getBytesCopy(Typed.dereference(_value, this.type)); + if (data.length !== this.size) { + this._throwError("incorrect data length", _value); + } + return writer.writeBytes(data); + } + decode(reader) { + return hexlify(reader.readBytes(this.size)); + } +} +//# sourceMappingURL=fixed-bytes.js.map \ No newline at end of file diff --git a/lib.esm/abi/coders/fixed-bytes.js.map b/lib.esm/abi/coders/fixed-bytes.js.map new file mode 100644 index 00000000..bb22c492 --- /dev/null +++ b/lib.esm/abi/coders/fixed-bytes.js.map @@ -0,0 +1 @@ +{"version":3,"file":"fixed-bytes.js","sourceRoot":"","sources":["../../../src.ts/abi/coders/fixed-bytes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/E,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAO5C;;GAEG;AACH,MAAM,OAAO,eAAgB,SAAQ,KAAK;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,gBAAgB,CAAkB,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,YAAY,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAC9D,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,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAChD,CAAC;CACJ"} \ No newline at end of file diff --git a/lib.esm/abi/coders/null.d.ts b/lib.esm/abi/coders/null.d.ts new file mode 100644 index 00000000..5df5da34 --- /dev/null +++ b/lib.esm/abi/coders/null.d.ts @@ -0,0 +1,12 @@ +import { Coder } from "./abstract-coder.js"; +import type { Reader, Writer } from "./abstract-coder.js"; +/** + * @_ignore + */ +export declare class NullCoder extends Coder { + constructor(localName: string); + defaultValue(): null; + encode(writer: Writer, value: any): number; + decode(reader: Reader): any; +} +//# sourceMappingURL=null.d.ts.map \ No newline at end of file diff --git a/lib.esm/abi/coders/null.d.ts.map b/lib.esm/abi/coders/null.d.ts.map new file mode 100644 index 00000000..4c87b845 --- /dev/null +++ b/lib.esm/abi/coders/null.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"null.d.ts","sourceRoot":"","sources":["../../../src.ts/abi/coders/null.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAI1D;;GAEG;AACH,qBAAa,SAAU,SAAQ,KAAK;gBAEpB,SAAS,EAAE,MAAM;IAI7B,YAAY,IAAI,IAAI;IAIpB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,MAAM;IAK1C,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG;CAI9B"} \ No newline at end of file diff --git a/lib.esm/abi/coders/null.js b/lib.esm/abi/coders/null.js new file mode 100644 index 00000000..5b7d867a --- /dev/null +++ b/lib.esm/abi/coders/null.js @@ -0,0 +1,24 @@ +import { Coder } from "./abstract-coder.js"; +const Empty = new Uint8Array([]); +/** + * @_ignore + */ +export class NullCoder extends 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; + } +} +//# sourceMappingURL=null.js.map \ No newline at end of file diff --git a/lib.esm/abi/coders/null.js.map b/lib.esm/abi/coders/null.js.map new file mode 100644 index 00000000..6afd520c --- /dev/null +++ b/lib.esm/abi/coders/null.js.map @@ -0,0 +1 @@ +{"version":3,"file":"null.js","sourceRoot":"","sources":["../../../src.ts/abi/coders/null.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAG5C,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,EAAG,CAAC,CAAC;AAElC;;GAEG;AACH,MAAM,OAAO,SAAU,SAAQ,KAAK;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"} \ No newline at end of file diff --git a/lib.esm/abi/coders/number.d.ts b/lib.esm/abi/coders/number.d.ts new file mode 100644 index 00000000..822cc6df --- /dev/null +++ b/lib.esm/abi/coders/number.d.ts @@ -0,0 +1,16 @@ +import { Typed } from "../typed.js"; +import { Coder } from "./abstract-coder.js"; +import type { BigNumberish } from "../../utils/index.js"; +import type { Reader, Writer } from "./abstract-coder.js"; +/** + * @_ignore + */ +export declare class NumberCoder extends Coder { + readonly size: number; + readonly signed: boolean; + constructor(size: number, signed: boolean, localName: string); + defaultValue(): number; + encode(writer: Writer, _value: BigNumberish | Typed): number; + decode(reader: Reader): any; +} +//# sourceMappingURL=number.d.ts.map \ No newline at end of file diff --git a/lib.esm/abi/coders/number.d.ts.map b/lib.esm/abi/coders/number.d.ts.map new file mode 100644 index 00000000..a02820f6 --- /dev/null +++ b/lib.esm/abi/coders/number.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../../../src.ts/abi/coders/number.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,KAAK,EAAY,MAAM,qBAAqB,CAAC;AAEtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAO1D;;GAEG;AACH,qBAAa,WAAY,SAAQ,KAAK;IAClC,QAAQ,CAAC,IAAI,EAAG,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAG,OAAO,CAAC;gBAEd,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM;IAO5D,YAAY,IAAI,MAAM;IAItB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,GAAG,KAAK,GAAG,MAAM;IAkB5D,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG;CAS9B"} \ No newline at end of file diff --git a/lib.esm/abi/coders/number.js b/lib.esm/abi/coders/number.js new file mode 100644 index 00000000..52f5a46b --- /dev/null +++ b/lib.esm/abi/coders/number.js @@ -0,0 +1,45 @@ +import { defineProperties, fromTwos, getBigInt, mask, toTwos } from "../../utils/index.js"; +import { Typed } from "../typed.js"; +import { Coder, WordSize } from "./abstract-coder.js"; +const BN_0 = BigInt(0); +const BN_1 = BigInt(1); +const BN_MAX_UINT256 = BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); +/** + * @_ignore + */ +export class NumberCoder extends Coder { + size; + signed; + constructor(size, signed, localName) { + const name = ((signed ? "int" : "uint") + (size * 8)); + super(name, name, localName, false); + defineProperties(this, { size, signed }, { size: "number", signed: "boolean" }); + } + defaultValue() { + return 0; + } + encode(writer, _value) { + let value = getBigInt(Typed.dereference(_value, this.type)); + // Check bounds are safe for encoding + let maxUintValue = mask(BN_MAX_UINT256, WordSize * 8); + if (this.signed) { + let bounds = mask(maxUintValue, (this.size * 8) - 1); + if (value > bounds || value < -(bounds + BN_1)) { + this._throwError("value out-of-bounds", _value); + } + value = toTwos(value, 8 * WordSize); + } + else if (value < BN_0 || value > mask(maxUintValue, this.size * 8)) { + this._throwError("value out-of-bounds", _value); + } + return writer.writeValue(value); + } + decode(reader) { + let value = mask(reader.readValue(), this.size * 8); + if (this.signed) { + value = fromTwos(value, this.size * 8); + } + return value; + } +} +//# sourceMappingURL=number.js.map \ No newline at end of file diff --git a/lib.esm/abi/coders/number.js.map b/lib.esm/abi/coders/number.js.map new file mode 100644 index 00000000..5ecd80d4 --- /dev/null +++ b/lib.esm/abi/coders/number.js.map @@ -0,0 +1 @@ +{"version":3,"file":"number.js","sourceRoot":"","sources":["../../../src.ts/abi/coders/number.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,gBAAgB,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EACtD,MAAM,sB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,KAAK,GAAG,MAAM,IAAI,KAAK,GAAG,CAAC,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE;gBAC5C,IAAI,CAAC,WAAW,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;aACnD;YACD,KAAK,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC;SACvC;aAAM,IAAI,KAAK,GAAG,IAAI,IAAI,KAAK,GAAG,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,EAAE;YAClE,IAAI,CAAC,WAAW,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;SACnD;QAED,OAAO,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;IAED,MAAM,CAAC,MAAc;QACjB,IAAI,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC;QAEpD,IAAI,IAAI,CAAC,MAAM,EAAE;YACb,KAAK,GAAG,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC;SAC1C;QAED,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ"} \ No newline at end of file diff --git a/lib.esm/abi/coders/string.d.ts b/lib.esm/abi/coders/string.d.ts new file mode 100644 index 00000000..8e1c6359 --- /dev/null +++ b/lib.esm/abi/coders/string.d.ts @@ -0,0 +1,13 @@ +import { Typed } from "../typed.js"; +import { DynamicBytesCoder } from "./bytes.js"; +import type { Reader, Writer } from "./abstract-coder.js"; +/** + * @_ignore + */ +export declare class StringCoder extends DynamicBytesCoder { + constructor(localName: string); + defaultValue(): string; + encode(writer: Writer, _value: string | Typed): number; + decode(reader: Reader): any; +} +//# sourceMappingURL=string.d.ts.map \ No newline at end of file diff --git a/lib.esm/abi/coders/string.d.ts.map b/lib.esm/abi/coders/string.d.ts.map new file mode 100644 index 00000000..8141f2ea --- /dev/null +++ b/lib.esm/abi/coders/string.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../../src.ts/abi/coders/string.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE/C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAG1D;;GAEG;AACH,qBAAa,WAAY,SAAQ,iBAAiB;gBAElC,SAAS,EAAE,MAAM;IAI7B,YAAY,IAAI,MAAM;IAItB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,KAAK,GAAG,MAAM;IAItD,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG;CAG9B"} \ No newline at end of file diff --git a/lib.esm/abi/coders/string.js b/lib.esm/abi/coders/string.js new file mode 100644 index 00000000..cd8c4bd5 --- /dev/null +++ b/lib.esm/abi/coders/string.js @@ -0,0 +1,21 @@ +import { toUtf8Bytes, toUtf8String } from "../../utils/utf8.js"; +import { Typed } from "../typed.js"; +import { DynamicBytesCoder } from "./bytes.js"; +/** + * @_ignore + */ +export class StringCoder extends DynamicBytesCoder { + constructor(localName) { + super("string", localName); + } + defaultValue() { + return ""; + } + encode(writer, _value) { + return super.encode(writer, toUtf8Bytes(Typed.dereference(_value, "string"))); + } + decode(reader) { + return toUtf8String(super.decode(reader)); + } +} +//# sourceMappingURL=string.js.map \ No newline at end of file diff --git a/lib.esm/abi/coders/string.js.map b/lib.esm/abi/coders/string.js.map new file mode 100644 index 00000000..f0a168f9 --- /dev/null +++ b/lib.esm/abi/coders/string.js.map @@ -0,0 +1 @@ +{"version":3,"file":"string.js","sourceRoot":"","sources":["../../../src.ts/abi/coders/string.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEhE,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAK/C;;GAEG;AACH,MAAM,OAAO,WAAY,SAAQ,iBAAiB;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,WAAW,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IAClF,CAAC;IAED,MAAM,CAAC,MAAc;QACjB,OAAO,YAAY,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9C,CAAC;CACJ"} \ No newline at end of file diff --git a/lib.esm/abi/coders/tuple.d.ts b/lib.esm/abi/coders/tuple.d.ts new file mode 100644 index 00000000..fe3ec032 --- /dev/null +++ b/lib.esm/abi/coders/tuple.d.ts @@ -0,0 +1,16 @@ +import { Typed } from "../typed.js"; +import { Coder } from "./abstract-coder.js"; +import type { Reader, Writer } from "./abstract-coder.js"; +/** + * @_ignore + */ +export declare class TupleCoder extends Coder { + readonly coders: ReadonlyArray; + constructor(coders: Array, localName: string); + defaultValue(): any; + encode(writer: Writer, _value: Array | { + [name: string]: any; + } | Typed): number; + decode(reader: Reader): any; +} +//# sourceMappingURL=tuple.d.ts.map \ No newline at end of file diff --git a/lib.esm/abi/coders/tuple.d.ts.map b/lib.esm/abi/coders/tuple.d.ts.map new file mode 100644 index 00000000..a7a22ec0 --- /dev/null +++ b/lib.esm/abi/coders/tuple.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"tuple.d.ts","sourceRoot":"","sources":["../../../src.ts/abi/coders/tuple.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAI5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE1D;;GAEG;AACH,qBAAa,UAAW,SAAQ,KAAK;IACjC,QAAQ,CAAC,MAAM,EAAG,aAAa,CAAC,KAAK,CAAC,CAAC;gBAE3B,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,MAAM;IAanD,YAAY,IAAI,GAAG;IA+BnB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG;QAAE,CAAE,IAAI,EAAE,MAAM,GAAI,GAAG,CAAA;KAAE,GAAG,KAAK,GAAG,MAAM;IAKtF,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG;CAG9B"} \ No newline at end of file diff --git a/lib.esm/abi/coders/tuple.js b/lib.esm/abi/coders/tuple.js new file mode 100644 index 00000000..9215603f --- /dev/null +++ b/lib.esm/abi/coders/tuple.js @@ -0,0 +1,63 @@ +import { defineProperties } from "../../utils/properties.js"; +import { Typed } from "../typed.js"; +import { Coder } from "./abstract-coder.js"; +import { pack, unpack } from "./array.js"; +/** + * @_ignore + */ +export class TupleCoder extends 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); + 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.dereference(_value, "tuple"); + return pack(writer, this.coders, value); + } + decode(reader) { + return unpack(reader, this.coders); + } +} +//# sourceMappingURL=tuple.js.map \ No newline at end of file diff --git a/lib.esm/abi/coders/tuple.js.map b/lib.esm/abi/coders/tuple.js.map new file mode 100644 index 00000000..a9be35f2 --- /dev/null +++ b/lib.esm/abi/coders/tuple.js.map @@ -0,0 +1 @@ +{"version":3,"file":"tuple.js","sourceRoot":"","sources":["../../../src.ts/abi/coders/tuple.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7D,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5C,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAI1C;;GAEG;AACH,MAAM,OAAO,UAAW,SAAQ,KAAK;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;gBAAE,OAAO,GAAG,IAAI,CAAC;aAAE;YACtC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC3B,CAAC,CAAC,CAAC;QACH,MAAM,IAAI,GAAG,CAAC,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC;QAEhD,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;QACzC,gBAAgB,CA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,MAAM,CAAC,CAAC;IACjC,CAAC;IAED,MAAM,CAAC,MAAc,EAAE,MAAsD;QACzE,MAAM,KAAK,GAAG,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACjD,OAAO,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC5C,CAAC;IAED,MAAM,CAAC,MAAc;QACjB,OAAO,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IACvC,CAAC;CACJ"} \ No newline at end of file diff --git a/lib.esm/abi/fragments.d.ts b/lib.esm/abi/fragments.d.ts new file mode 100644 index 00000000..26058058 --- /dev/null +++ b/lib.esm/abi/fragments.d.ts @@ -0,0 +1,466 @@ +/** + * A fragment is a single item from an ABI, which may represent any of: + * + * - [Functions](FunctionFragment) + * - [Events](EventFragment) + * - [Constructors](ConstructorFragment) + * - Custom [Errors](ErrorFragment) + * - [Fallback or Receive](FallbackFragment) functions + * + * @_subsection api/abi/abi-coder:Fragments [about-fragments] + */ +/** + * A Type description in a [JSON ABI format](link-solc-jsonabi). + */ +export interface JsonFragmentType { + /** + * The parameter name. + */ + readonly name?: string; + /** + * If the parameter is indexed. + */ + readonly indexed?: boolean; + /** + * The type of the parameter. + */ + readonly type?: string; + /** + * The internal Solidity type. + */ + readonly internalType?: string; + /** + * The components for a tuple. + */ + readonly components?: ReadonlyArray; +} +/** + * A fragment for a method, event or error in a [JSON ABI format](link-solc-jsonabi). + */ +export interface JsonFragment { + /** + * The name of the error, event, function, etc. + */ + readonly name?: string; + /** + * The type of the fragment (e.g. ``event``, ``"function"``, etc.) + */ + readonly type?: string; + /** + * If the event is anonymous. + */ + readonly anonymous?: boolean; + /** + * If the function is payable. + */ + readonly payable?: boolean; + /** + * If the function is constant. + */ + readonly constant?: boolean; + /** + * The mutability state of the function. + */ + readonly stateMutability?: string; + /** + * The input parameters. + */ + readonly inputs?: ReadonlyArray; + /** + * The output parameters. + */ + readonly outputs?: ReadonlyArray; + /** + * The gas limit to use when sending a transaction for this function. + */ + readonly gas?: string; +} +/** + * The format to serialize the output as. + * + * **``"sighash"``** - the bare formatting, used to compute the selector + * or topic hash; this format cannot be reversed (as it discards ``indexed``) + * so cannot by used to export an [[Interface]]. + * + * **``"minimal"``** - Human-Readable ABI with minimal spacing and without + * names, so it is compact, but will result in Result objects that cannot + * be accessed by name. + * + * **``"full"``** - Full Human-Readable ABI, with readable spacing and names + * intact; this is generally the recommended format. + * + * **``"json"``** - The [JSON ABI format](link-solc-jsonabi). + */ +export type FormatType = "sighash" | "minimal" | "full" | "json"; +/** + * When [walking](ParamType-walk) a [[ParamType]], this is called + * on each component. + */ +export type ParamTypeWalkFunc = (type: string, value: any) => any; +/** + * When [walking asynchronously](ParamType-walkAsync) a [[ParamType]], + * this is called on each component. + */ +export type ParamTypeWalkAsyncFunc = (type: string, value: any) => any | Promise; +/** + * Each input and output of a [[Fragment]] is an Array of **ParamType**. + */ +export declare class ParamType { + #private; + /** + * The local name of the parameter (or ``""`` if unbound) + */ + readonly name: string; + /** + * The fully qualified type (e.g. ``"address"``, ``"tuple(address)"``, + * ``"uint256[3][]"``) + */ + readonly type: string; + /** + * The base type (e.g. ``"address"``, ``"tuple"``, ``"array"``) + */ + readonly baseType: string; + /** + * True if the parameters is indexed. + * + * For non-indexable types this is ``null``. + */ + readonly indexed: null | boolean; + /** + * The components for the tuple. + * + * For non-tuple types this is ``null``. + */ + readonly components: null | ReadonlyArray; + /** + * The array length, or ``-1`` for dynamic-lengthed arrays. + * + * For non-array types this is ``null``. + */ + readonly arrayLength: null | number; + /** + * The type of each child in the array. + * + * For non-array types this is ``null``. + */ + readonly arrayChildren: null | ParamType; + /** + * @private + */ + constructor(guard: any, name: string, type: string, baseType: string, indexed: null | boolean, components: null | ReadonlyArray, arrayLength: null | number, arrayChildren: null | ParamType); + /** + * Return a string representation of this type. + * + * For example, + * + * ``sighash" => "(uint256,address)"`` + * + * ``"minimal" => "tuple(uint256,address) indexed"`` + * + * ``"full" => "tuple(uint256 foo, address bar) indexed baz"`` + */ + format(format?: FormatType): string; + /** + * Returns true if %%this%% is an Array type. + * + * This provides a type gaurd ensuring that [[arrayChildren]] + * and [[arrayLength]] are non-null. + */ + isArray(): this is (ParamType & { + arrayChildren: ParamType; + arrayLength: number; + }); + /** + * Returns true if %%this%% is a Tuple type. + * + * This provides a type gaurd ensuring that [[components]] + * is non-null. + */ + isTuple(): this is (ParamType & { + components: ReadonlyArray; + }); + /** + * Returns true if %%this%% is an Indexable type. + * + * This provides a type gaurd ensuring that [[indexed]] + * is non-null. + */ + isIndexable(): this is (ParamType & { + indexed: boolean; + }); + /** + * Walks the **ParamType** with %%value%%, calling %%process%% + * on each type, destructing the %%value%% recursively. + */ + walk(value: any, process: ParamTypeWalkFunc): any; + /** + * Walks the **ParamType** with %%value%%, asynchronously calling + * %%process%% on each type, destructing the %%value%% recursively. + * + * This can be used to resolve ENS naes by walking and resolving each + * ``"address"`` type. + */ + walkAsync(value: any, process: ParamTypeWalkAsyncFunc): Promise; + /** + * Creates a new **ParamType** for %%obj%%. + * + * If %%allowIndexed%% then the ``indexed`` keyword is permitted, + * otherwise the ``indexed`` keyword will throw an error. + */ + static from(obj: any, allowIndexed?: boolean): ParamType; + /** + * Returns true if %%value%% is a **ParamType**. + */ + static isParamType(value: any): value is ParamType; +} +/** + * The type of a [[Fragment]]. + */ +export type FragmentType = "constructor" | "error" | "event" | "fallback" | "function" | "struct"; +/** + * An abstract class to represent An individual fragment from a parse ABI. + */ +export declare abstract class Fragment { + /** + * The type of the fragment. + */ + readonly type: FragmentType; + /** + * The inputs for the fragment. + */ + readonly inputs: ReadonlyArray; + /** + * @private + */ + constructor(guard: any, type: FragmentType, inputs: ReadonlyArray); + /** + * Returns a string representation of this fragment as %%format%%. + */ + abstract format(format?: FormatType): string; + /** + * Creates a new **Fragment** for %%obj%%, wich can be any supported + * ABI frgament type. + */ + static from(obj: any): Fragment; + /** + * Returns true if %%value%% is a [[ConstructorFragment]]. + */ + static isConstructor(value: any): value is ConstructorFragment; + /** + * Returns true if %%value%% is an [[ErrorFragment]]. + */ + static isError(value: any): value is ErrorFragment; + /** + * Returns true if %%value%% is an [[EventFragment]]. + */ + static isEvent(value: any): value is EventFragment; + /** + * Returns true if %%value%% is a [[FunctionFragment]]. + */ + static isFunction(value: any): value is FunctionFragment; + /** + * Returns true if %%value%% is a [[StructFragment]]. + */ + static isStruct(value: any): value is StructFragment; +} +/** + * An abstract class to represent An individual fragment + * which has a name from a parse ABI. + */ +export declare abstract class NamedFragment extends Fragment { + /** + * The name of the fragment. + */ + readonly name: string; + /** + * @private + */ + constructor(guard: any, type: FragmentType, name: string, inputs: ReadonlyArray); +} +/** + * A Fragment which represents a //Custom Error//. + */ +export declare class ErrorFragment extends NamedFragment { + /** + * @private + */ + constructor(guard: any, name: string, inputs: ReadonlyArray); + /** + * The Custom Error selector. + */ + get selector(): string; + /** + * Returns a string representation of this fragment as %%format%%. + */ + format(format?: FormatType): string; + /** + * Returns a new **ErrorFragment** for %%obj%%. + */ + static from(obj: any): ErrorFragment; + /** + * Returns ``true`` and provides a type guard if %%value%% is an + * **ErrorFragment**. + */ + static isFragment(value: any): value is ErrorFragment; +} +/** + * A Fragment which represents an Event. + */ +export declare class EventFragment extends NamedFragment { + /** + * Whether this event is anonymous. + */ + readonly anonymous: boolean; + /** + * @private + */ + constructor(guard: any, name: string, inputs: ReadonlyArray, anonymous: boolean); + /** + * The Event topic hash. + */ + get topicHash(): string; + /** + * Returns a string representation of this event as %%format%%. + */ + format(format?: FormatType): string; + /** + * Return the topic hash for an event with %%name%% and %%params%%. + */ + static getTopicHash(name: string, params?: Array): string; + /** + * Returns a new **EventFragment** for %%obj%%. + */ + static from(obj: any): EventFragment; + /** + * Returns ``true`` and provides a type guard if %%value%% is an + * **EventFragment**. + */ + static isFragment(value: any): value is EventFragment; +} +/** + * A Fragment which represents a constructor. + */ +export declare class ConstructorFragment extends Fragment { + /** + * Whether the constructor can receive an endowment. + */ + readonly payable: boolean; + /** + * The recommended gas limit for deployment or ``null``. + */ + readonly gas: null | bigint; + /** + * @private + */ + constructor(guard: any, type: FragmentType, inputs: ReadonlyArray, payable: boolean, gas: null | bigint); + /** + * Returns a string representation of this constructor as %%format%%. + */ + format(format?: FormatType): string; + /** + * Returns a new **ConstructorFragment** for %%obj%%. + */ + static from(obj: any): ConstructorFragment; + /** + * Returns ``true`` and provides a type guard if %%value%% is a + * **ConstructorFragment**. + */ + static isFragment(value: any): value is ConstructorFragment; +} +/** + * A Fragment which represents a method. + */ +export declare class FallbackFragment extends Fragment { + /** + * If the function can be sent value during invocation. + */ + readonly payable: boolean; + constructor(guard: any, inputs: ReadonlyArray, payable: boolean); + /** + * Returns a string representation of this fallback as %%format%%. + */ + format(format?: FormatType): string; + /** + * Returns a new **FallbackFragment** for %%obj%%. + */ + static from(obj: any): FallbackFragment; + /** + * Returns ``true`` and provides a type guard if %%value%% is a + * **FallbackFragment**. + */ + static isFragment(value: any): value is FallbackFragment; +} +/** + * A Fragment which represents a method. + */ +export declare class FunctionFragment extends NamedFragment { + /** + * If the function is constant (e.g. ``pure`` or ``view`` functions). + */ + readonly constant: boolean; + /** + * The returned types for the result of calling this function. + */ + readonly outputs: ReadonlyArray; + /** + * The state mutability (e.g. ``payable``, ``nonpayable``, ``view`` + * or ``pure``) + */ + readonly stateMutability: "payable" | "nonpayable" | "view" | "pure"; + /** + * If the function can be sent value during invocation. + */ + readonly payable: boolean; + /** + * The recommended gas limit to send when calling this function. + */ + readonly gas: null | bigint; + /** + * @private + */ + constructor(guard: any, name: string, stateMutability: "payable" | "nonpayable" | "view" | "pure", inputs: ReadonlyArray, outputs: ReadonlyArray, gas: null | bigint); + /** + * The Function selector. + */ + get selector(): string; + /** + * Returns a string representation of this function as %%format%%. + */ + format(format?: FormatType): string; + /** + * Return the selector for a function with %%name%% and %%params%%. + */ + static getSelector(name: string, params?: Array): string; + /** + * Returns a new **FunctionFragment** for %%obj%%. + */ + static from(obj: any): FunctionFragment; + /** + * Returns ``true`` and provides a type guard if %%value%% is a + * **FunctionFragment**. + */ + static isFragment(value: any): value is FunctionFragment; +} +/** + * A Fragment which represents a structure. + */ +export declare class StructFragment extends NamedFragment { + /** + * @private + */ + constructor(guard: any, name: string, inputs: ReadonlyArray); + /** + * Returns a string representation of this struct as %%format%%. + */ + format(): string; + /** + * Returns a new **StructFragment** for %%obj%%. + */ + static from(obj: any): StructFragment; + /** + * Returns ``true`` and provides a type guard if %%value%% is a + * **StructFragment**. + */ + static isFragment(value: any): value is FunctionFragment; +} +//# sourceMappingURL=fragments.d.ts.map \ No newline at end of file diff --git a/lib.esm/abi/fragments.d.ts.map b/lib.esm/abi/fragments.d.ts.map new file mode 100644 index 00000000..44e68b3c --- /dev/null +++ b/lib.esm/abi/fragments.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"fragments.d.ts","sourceRoot":"","sources":["../../src.ts/abi/fragments.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAQH;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC7B;;OAEG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAEvB;;OAEG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAE3B;;OAEG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAEvB;;OAEG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAE/B;;OAEG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,aAAa,CAAC,gBAAgB,CAAC,CAAC;CACzD;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IACzB;;OAEG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAEvB;;OAEG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAEvB;;OAEG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;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AI,EAAE,MAAM,EAAE,eAAe,EAAE,SAAS,GAAG,YAAY,GAAG,MAAM,GAAG,MAAM,EAAE,MAAM,EAAE,aAAa,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,aAAa,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,IAAI,GAAG,MAAM;IAS1L;;OAEG;IACH,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED;;OAEG;IACH,MAAM,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG,MAAM;IAoCnC;;OAEG;IACH,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,MAAM;IAM7D;;OAEG;IACH,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,gBAAgB;IAuDvC;;;OAGG;IACH,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,gBAAgB;CAG3D;AAED;;GAEG;AACH,qBAAa,cAAe,SAAQ,aAAa;IAE7C;;OAEG;gBACS,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,CAAC,SAAS,CAAC;IAKtE;;OAEG;IACH,MAAM,IAAI,MAAM;IAIhB;;OAEG;IACH,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,cAAc;IAmBrC;;;OAGG;IACH,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,gBAAgB;CAG3D"} \ No newline at end of file diff --git a/lib.esm/abi/fragments.js b/lib.esm/abi/fragments.js new file mode 100644 index 00000000..80da4761 --- /dev/null +++ b/lib.esm/abi/fragments.js @@ -0,0 +1,1318 @@ +/** + * A fragment is a single item from an ABI, which may represent any of: + * + * - [Functions](FunctionFragment) + * - [Events](EventFragment) + * - [Constructors](ConstructorFragment) + * - Custom [Errors](ErrorFragment) + * - [Fallback or Receive](FallbackFragment) functions + * + * @_subsection api/abi/abi-coder:Fragments [about-fragments] + */ +import { defineProperties, getBigInt, getNumber, assert, assertPrivate, assertArgument } from "../utils/index.js"; +import { id } from "../hash/index.js"; +; +// [ "a", "b" ] => { "a": 1, "b": 1 } +function setify(items) { + const result = new Set(); + items.forEach((k) => result.add(k)); + return Object.freeze(result); +} +const _kwVisibDeploy = "external public payable"; +const KwVisibDeploy = setify(_kwVisibDeploy.split(" ")); +// Visibility Keywords +const _kwVisib = "constant external internal payable private public pure view"; +const KwVisib = setify(_kwVisib.split(" ")); +const _kwTypes = "constructor error event fallback function receive 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 regexWhitespacePrefix = new RegExp("^(\\s*)"); +const regexNumberPrefix = new RegExp("^([0-9]+)"); +const regexIdPrefix = new RegExp("^([a-zA-Z$_][a-zA-Z0-9$_]*)"); +// Parser regexs to check validity +const regexId = 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), + })); + })); + } + // 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 ``; + } +} +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(regexWhitespacePrefix); + 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 = 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(regexIdPrefix); + 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(regexNumberPrefix); + 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))); +} +// 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.from(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 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); + assertArgument(match, "invalid type", "type", type); + if (type === "uint") { + return "uint256"; + } + if (type === "int") { + return "int256"; + } + if (match[2]) { + // bytesXX + const length = parseInt(match[2]); + assertArgument(length !== 0 && length <= 32, "invalid bytes length", "type", type); + } + else if (match[3]) { + // intXX or uintXX + const size = parseInt(match[3]); + assertArgument(size !== 0 && size <= 256 && (size % 8) === 0, "invalid numeric width", "type", type); + } + return type; +} +// Make the Fragment constructors effectively private +const _guard = {}; +const internal = Symbol.for("_quais_internal"); +const ParamTypeInternal = "_ParamTypeInternal"; +const ErrorFragmentInternal = "_ErrorInternal"; +const EventFragmentInternal = "_EventInternal"; +const ConstructorFragmentInternal = "_ConstructorInternal"; +const FallbackFragmentInternal = "_FallbackInternal"; +const FunctionFragmentInternal = "_FunctionInternal"; +const StructFragmentInternal = "_StructInternal"; +/** + * Each input and output of a [[Fragment]] is an Array of **ParamType**. + */ +export class ParamType { + /** + * The local name of the parameter (or ``""`` if unbound) + */ + name; + /** + * The fully qualified type (e.g. ``"address"``, ``"tuple(address)"``, + * ``"uint256[3][]"``) + */ + type; + /** + * The base type (e.g. ``"address"``, ``"tuple"``, ``"array"``) + */ + baseType; + /** + * True if the parameters is indexed. + * + * For non-indexable types this is ``null``. + */ + indexed; + /** + * The components for the tuple. + * + * For non-tuple types this is ``null``. + */ + components; + /** + * The array length, or ``-1`` for dynamic-lengthed arrays. + * + * For non-array types this is ``null``. + */ + arrayLength; + /** + * The type of each child in the array. + * + * For non-array types this is ``null``. + */ + arrayChildren; + /** + * @private + */ + constructor(guard, name, type, baseType, indexed, components, arrayLength, arrayChildren) { + 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(""); + } + defineProperties(this, { + name, type, baseType, indexed, components, arrayLength, arrayChildren + }); + } + /** + * Return a string representation of this type. + * + * For example, + * + * ``sighash" => "(uint256,address)"`` + * + * ``"minimal" => "tuple(uint256,address) indexed"`` + * + * ``"full" => "tuple(uint256 foo, address bar) indexed baz"`` + */ + format(format) { + if (format == null) { + format = "sighash"; + } + if (format === "json") { + const name = this.name || ""; + if (this.isArray()) { + const result = JSON.parse(this.arrayChildren.format("json")); + result.name = name; + result.type += `[${(this.arrayLength < 0 ? "" : String(this.arrayLength))}]`; + return JSON.stringify(result); + } + const result = { + type: ((this.baseType === "tuple") ? "tuple" : this.type), + name + }; + 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()) { + result += "(" + this.components.map((comp) => comp.format(format)).join((format === "full") ? ", " : ",") + ")"; + } + else { + result += this.type; + } + } + if (format !== "sighash") { + if (this.indexed === true) { + result += " indexed"; + } + if (format === "full" && this.name) { + result += " " + this.name; + } + } + return result; + } + /** + * Returns true if %%this%% is an Array type. + * + * This provides a type gaurd ensuring that [[arrayChildren]] + * and [[arrayLength]] are non-null. + */ + isArray() { + return (this.baseType === "array"); + } + /** + * Returns true if %%this%% is a Tuple type. + * + * This provides a type gaurd ensuring that [[components]] + * is non-null. + */ + isTuple() { + return (this.baseType === "tuple"); + } + /** + * Returns true if %%this%% is an Indexable type. + * + * This provides a type gaurd ensuring that [[indexed]] + * is non-null. + */ + isIndexable() { + return (this.indexed != null); + } + /** + * Walks the **ParamType** with %%value%%, calling %%process%% + * on each type, destructing the %%value%% recursively. + */ + walk(value, process) { + if (this.isArray()) { + if (!Array.isArray(value)) { + throw new Error("invalid array value"); + } + if (this.arrayLength !== -1 && value.length !== this.arrayLength) { + throw new Error("array is wrong length"); + } + const _this = this; + return value.map((v) => (_this.arrayChildren.walk(v, process))); + } + if (this.isTuple()) { + if (!Array.isArray(value)) { + throw new Error("invalid tuple value"); + } + if (value.length !== this.components.length) { + throw new Error("array is wrong length"); + } + const _this = this; + 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("invalid 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("invalid 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 (result.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); + } + } + /** + * Walks the **ParamType** with %%value%%, asynchronously calling + * %%process%% on each type, destructing the %%value%% recursively. + * + * This can be used to resolve ENS naes by walking and resolving each + * ``"address"`` type. + */ + 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]; + } + /** + * Creates a new **ParamType** for %%obj%%. + * + * If %%allowIndexed%% then the ``indexed`` keyword is permitted, + * otherwise the ``indexed`` keyword will throw an error. + */ + static from(obj, allowIndexed) { + if (ParamType.isParamType(obj)) { + return obj; + } + if (typeof (obj) === "string") { + try { + return ParamType.from(lex(obj), allowIndexed); + } + catch (error) { + assertArgument(false, "invalid param type", "obj", obj); + } + } + else if (obj instanceof TokenString) { + let type = "", baseType = ""; + let comps = null; + if (consumeKeywords(obj, setify(["tuple"])).has("tuple") || obj.peekType("OPEN_PAREN")) { + // Tuple + baseType = "tuple"; + comps = obj.popParams().map((t) => ParamType.from(t)); + type = `tuple(${comps.map((c) => c.format()).join(",")})`; + } + else { + // Normal + type = verifyBasicType(obj.popType("TYPE")); + baseType = type; + } + // Check for Array + let arrayChildren = null; + let arrayLength = null; + while (obj.length && obj.peekType("BRACKET")) { + const bracket = obj.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(obj, KwModifiers); + if (keywords.has("indexed")) { + if (!allowIndexed) { + throw new Error(""); + } + indexed = true; + } + const name = (obj.peekType("ID") ? obj.pop().text : ""); + if (obj.length) { + throw new Error("leftover tokens"); + } + return new ParamType(_guard, name, type, baseType, indexed, comps, arrayLength, arrayChildren); + } + const name = obj.name; + assertArgument(!name || (typeof (name) === "string" && name.match(regexId)), "invalid name", "obj.name", name); + let indexed = obj.indexed; + if (indexed != null) { + assertArgument(allowIndexed, "parameter cannot be indexed", "obj.indexed", obj.indexed); + indexed = !!indexed; + } + let type = obj.type; + let arrayMatch = type.match(regexArrayType); + if (arrayMatch) { + const arrayLength = parseInt(arrayMatch[2] || "-1"); + const arrayChildren = ParamType.from({ + type: arrayMatch[1], + components: obj.components + }); + return new ParamType(_guard, name || "", type, "array", indexed, null, arrayLength, arrayChildren); + } + if (type === "tuple" || type.startsWith("tuple(" /* fix: ) */) || type.startsWith("(" /* fix: ) */)) { + 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); + } + /** + * Returns true if %%value%% is a **ParamType**. + */ + static isParamType(value) { + return (value && value[internal] === ParamTypeInternal); + } +} +/** + * An abstract class to represent An individual fragment from a parse ABI. + */ +export class Fragment { + /** + * The type of the fragment. + */ + type; + /** + * The inputs for the fragment. + */ + inputs; + /** + * @private + */ + constructor(guard, type, inputs) { + assertPrivate(guard, _guard, "Fragment"); + inputs = Object.freeze(inputs.slice()); + defineProperties(this, { type, inputs }); + } + /** + * Creates a new **Fragment** for %%obj%%, wich can be any supported + * ABI frgament type. + */ + static from(obj) { + if (typeof (obj) === "string") { + // Try parsing JSON... + try { + Fragment.from(JSON.parse(obj)); + } + catch (e) { } + // ...otherwise, use the human-readable lexer + return Fragment.from(lex(obj)); + } + if (obj instanceof TokenString) { + // Human-readable ABI (already lexed) + const type = obj.peekKeyword(KwTypes); + switch (type) { + case "constructor": return ConstructorFragment.from(obj); + case "error": return ErrorFragment.from(obj); + case "event": return EventFragment.from(obj); + case "fallback": + case "receive": + return FallbackFragment.from(obj); + case "function": return FunctionFragment.from(obj); + case "struct": return StructFragment.from(obj); + } + } + else if (typeof (obj) === "object") { + // JSON ABI + switch (obj.type) { + case "constructor": return ConstructorFragment.from(obj); + case "error": return ErrorFragment.from(obj); + case "event": return EventFragment.from(obj); + case "fallback": + case "receive": + return FallbackFragment.from(obj); + case "function": return FunctionFragment.from(obj); + case "struct": return StructFragment.from(obj); + } + assert(false, `unsupported type: ${obj.type}`, "UNSUPPORTED_OPERATION", { + operation: "Fragment.from" + }); + } + assertArgument(false, "unsupported frgament object", "obj", obj); + } + /** + * Returns true if %%value%% is a [[ConstructorFragment]]. + */ + static isConstructor(value) { + return ConstructorFragment.isFragment(value); + } + /** + * Returns true if %%value%% is an [[ErrorFragment]]. + */ + static isError(value) { + return ErrorFragment.isFragment(value); + } + /** + * Returns true if %%value%% is an [[EventFragment]]. + */ + static isEvent(value) { + return EventFragment.isFragment(value); + } + /** + * Returns true if %%value%% is a [[FunctionFragment]]. + */ + static isFunction(value) { + return FunctionFragment.isFragment(value); + } + /** + * Returns true if %%value%% is a [[StructFragment]]. + */ + static isStruct(value) { + return StructFragment.isFragment(value); + } +} +/** + * An abstract class to represent An individual fragment + * which has a name from a parse ABI. + */ +export class NamedFragment extends Fragment { + /** + * The name of the fragment. + */ + name; + /** + * @private + */ + constructor(guard, type, name, inputs) { + super(guard, type, inputs); + assertArgument(typeof (name) === "string" && name.match(regexId), "invalid identifier", "name", name); + inputs = Object.freeze(inputs.slice()); + defineProperties(this, { name }); + } +} +function joinParams(format, params) { + return "(" + params.map((p) => p.format(format)).join((format === "full") ? ", " : ",") + ")"; +} +/** + * A Fragment which represents a //Custom Error//. + */ +export class ErrorFragment extends NamedFragment { + /** + * @private + */ + constructor(guard, name, inputs) { + super(guard, "error", name, inputs); + Object.defineProperty(this, internal, { value: ErrorFragmentInternal }); + } + /** + * The Custom Error selector. + */ + get selector() { + return id(this.format("sighash")).substring(0, 10); + } + /** + * Returns a string representation of this fragment as %%format%%. + */ + format(format) { + if (format == null) { + format = "sighash"; + } + if (format === "json") { + return JSON.stringify({ + type: "error", + name: this.name, + inputs: this.inputs.map((input) => JSON.parse(input.format(format))), + }); + } + const result = []; + if (format !== "sighash") { + result.push("error"); + } + result.push(this.name + joinParams(format, this.inputs)); + return result.join(" "); + } + /** + * Returns a new **ErrorFragment** for %%obj%%. + */ + static from(obj) { + if (ErrorFragment.isFragment(obj)) { + return obj; + } + if (typeof (obj) === "string") { + return ErrorFragment.from(lex(obj)); + } + else if (obj instanceof TokenString) { + const name = consumeName("error", obj); + const inputs = consumeParams(obj); + consumeEoi(obj); + return new ErrorFragment(_guard, name, inputs); + } + return new ErrorFragment(_guard, obj.name, obj.inputs ? obj.inputs.map(ParamType.from) : []); + } + /** + * Returns ``true`` and provides a type guard if %%value%% is an + * **ErrorFragment**. + */ + static isFragment(value) { + return (value && value[internal] === ErrorFragmentInternal); + } +} +/** + * A Fragment which represents an Event. + */ +export class EventFragment extends NamedFragment { + /** + * Whether this event is anonymous. + */ + anonymous; + /** + * @private + */ + constructor(guard, name, inputs, anonymous) { + super(guard, "event", name, inputs); + Object.defineProperty(this, internal, { value: EventFragmentInternal }); + defineProperties(this, { anonymous }); + } + /** + * The Event topic hash. + */ + get topicHash() { + return id(this.format("sighash")); + } + /** + * Returns a string representation of this event as %%format%%. + */ + format(format) { + if (format == null) { + format = "sighash"; + } + if (format === "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 !== "sighash") { + result.push("event"); + } + result.push(this.name + joinParams(format, this.inputs)); + if (format !== "sighash" && this.anonymous) { + result.push("anonymous"); + } + return result.join(" "); + } + /** + * Return the topic hash for an event with %%name%% and %%params%%. + */ + static getTopicHash(name, params) { + params = (params || []).map((p) => ParamType.from(p)); + const fragment = new EventFragment(_guard, name, params, false); + return fragment.topicHash; + } + /** + * Returns a new **EventFragment** for %%obj%%. + */ + static from(obj) { + if (EventFragment.isFragment(obj)) { + return obj; + } + if (typeof (obj) === "string") { + try { + return EventFragment.from(lex(obj)); + } + catch (error) { + assertArgument(false, "invalid event fragment", "obj", obj); + } + } + else if (obj instanceof TokenString) { + const name = consumeName("event", obj); + const inputs = consumeParams(obj, true); + const anonymous = !!consumeKeywords(obj, setify(["anonymous"])).has("anonymous"); + consumeEoi(obj); + return new EventFragment(_guard, name, inputs, anonymous); + } + return new EventFragment(_guard, obj.name, obj.inputs ? obj.inputs.map((p) => ParamType.from(p, true)) : [], !!obj.anonymous); + } + /** + * Returns ``true`` and provides a type guard if %%value%% is an + * **EventFragment**. + */ + static isFragment(value) { + return (value && value[internal] === EventFragmentInternal); + } +} +/** + * A Fragment which represents a constructor. + */ +export class ConstructorFragment extends Fragment { + /** + * Whether the constructor can receive an endowment. + */ + payable; + /** + * The recommended gas limit for deployment or ``null``. + */ + gas; + /** + * @private + */ + constructor(guard, type, inputs, payable, gas) { + super(guard, type, inputs); + Object.defineProperty(this, internal, { value: ConstructorFragmentInternal }); + defineProperties(this, { payable, gas }); + } + /** + * Returns a string representation of this constructor as %%format%%. + */ + format(format) { + assert(format != null && format !== "sighash", "cannot format a constructor for sighash", "UNSUPPORTED_OPERATION", { operation: "format(sighash)" }); + if (format === "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)}`]; + if (this.payable) { + result.push("payable"); + } + if (this.gas != null) { + result.push(`@${this.gas.toString()}`); + } + return result.join(" "); + } + /** + * Returns a new **ConstructorFragment** for %%obj%%. + */ + static from(obj) { + if (ConstructorFragment.isFragment(obj)) { + return obj; + } + if (typeof (obj) === "string") { + try { + return ConstructorFragment.from(lex(obj)); + } + catch (error) { + assertArgument(false, "invalid constuctor fragment", "obj", obj); + } + } + else if (obj instanceof TokenString) { + consumeKeywords(obj, setify(["constructor"])); + const inputs = consumeParams(obj); + const payable = !!consumeKeywords(obj, KwVisibDeploy).has("payable"); + const gas = consumeGas(obj); + consumeEoi(obj); + return new ConstructorFragment(_guard, "constructor", inputs, payable, gas); + } + return new ConstructorFragment(_guard, "constructor", obj.inputs ? obj.inputs.map(ParamType.from) : [], !!obj.payable, (obj.gas != null) ? obj.gas : null); + } + /** + * Returns ``true`` and provides a type guard if %%value%% is a + * **ConstructorFragment**. + */ + static isFragment(value) { + return (value && value[internal] === ConstructorFragmentInternal); + } +} +/** + * A Fragment which represents a method. + */ +export class FallbackFragment extends Fragment { + /** + * If the function can be sent value during invocation. + */ + payable; + constructor(guard, inputs, payable) { + super(guard, "fallback", inputs); + Object.defineProperty(this, internal, { value: FallbackFragmentInternal }); + defineProperties(this, { payable }); + } + /** + * Returns a string representation of this fallback as %%format%%. + */ + format(format) { + const type = ((this.inputs.length === 0) ? "receive" : "fallback"); + if (format === "json") { + const stateMutability = (this.payable ? "payable" : "nonpayable"); + return JSON.stringify({ type, stateMutability }); + } + return `${type}()${this.payable ? " payable" : ""}`; + } + /** + * Returns a new **FallbackFragment** for %%obj%%. + */ + static from(obj) { + if (FallbackFragment.isFragment(obj)) { + return obj; + } + if (typeof (obj) === "string") { + try { + return FallbackFragment.from(lex(obj)); + } + catch (error) { + assertArgument(false, "invalid fallback fragment", "obj", obj); + } + } + else if (obj instanceof TokenString) { + const errorObj = obj.toString(); + const topIsValid = obj.peekKeyword(setify(["fallback", "receive"])); + assertArgument(topIsValid, "type must be fallback or receive", "obj", errorObj); + const type = obj.popKeyword(setify(["fallback", "receive"])); + // receive() + if (type === "receive") { + const inputs = consumeParams(obj); + assertArgument(inputs.length === 0, `receive cannot have arguments`, "obj.inputs", inputs); + consumeKeywords(obj, setify(["payable"])); + consumeEoi(obj); + return new FallbackFragment(_guard, [], true); + } + // fallback() [payable] + // fallback(bytes) [payable] returns (bytes) + let inputs = consumeParams(obj); + if (inputs.length) { + assertArgument(inputs.length === 1 && inputs[0].type === "bytes", "invalid fallback inputs", "obj.inputs", inputs.map((i) => i.format("minimal")).join(", ")); + } + else { + inputs = [ParamType.from("bytes")]; + } + const mutability = consumeMutability(obj); + assertArgument(mutability === "nonpayable" || mutability === "payable", "fallback cannot be constants", "obj.stateMutability", mutability); + if (consumeKeywords(obj, setify(["returns"])).has("returns")) { + const outputs = consumeParams(obj); + assertArgument(outputs.length === 1 && outputs[0].type === "bytes", "invalid fallback outputs", "obj.outputs", outputs.map((i) => i.format("minimal")).join(", ")); + } + consumeEoi(obj); + return new FallbackFragment(_guard, inputs, mutability === "payable"); + } + if (obj.type === "receive") { + return new FallbackFragment(_guard, [], true); + } + if (obj.type === "fallback") { + const inputs = [ParamType.from("bytes")]; + const payable = (obj.stateMutability === "payable"); + return new FallbackFragment(_guard, inputs, payable); + } + assertArgument(false, "invalid fallback description", "obj", obj); + } + /** + * Returns ``true`` and provides a type guard if %%value%% is a + * **FallbackFragment**. + */ + static isFragment(value) { + return (value && value[internal] === FallbackFragmentInternal); + } +} +/** + * A Fragment which represents a method. + */ +export class FunctionFragment extends NamedFragment { + /** + * If the function is constant (e.g. ``pure`` or ``view`` functions). + */ + constant; + /** + * The returned types for the result of calling this function. + */ + outputs; + /** + * The state mutability (e.g. ``payable``, ``nonpayable``, ``view`` + * or ``pure``) + */ + stateMutability; + /** + * If the function can be sent value during invocation. + */ + payable; + /** + * The recommended gas limit to send when calling this function. + */ + gas; + /** + * @private + */ + constructor(guard, name, stateMutability, inputs, outputs, gas) { + super(guard, "function", name, inputs); + Object.defineProperty(this, internal, { value: FunctionFragmentInternal }); + outputs = Object.freeze(outputs.slice()); + const constant = (stateMutability === "view" || stateMutability === "pure"); + const payable = (stateMutability === "payable"); + defineProperties(this, { constant, gas, outputs, payable, stateMutability }); + } + /** + * The Function selector. + */ + get selector() { + return id(this.format("sighash")).substring(0, 10); + } + /** + * Returns a string representation of this function as %%format%%. + */ + format(format) { + if (format == null) { + format = "sighash"; + } + if (format === "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 !== "sighash") { + result.push("function"); + } + result.push(this.name + joinParams(format, this.inputs)); + if (format !== "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(" "); + } + /** + * Return the selector for a function with %%name%% and %%params%%. + */ + static getSelector(name, params) { + params = (params || []).map((p) => ParamType.from(p)); + const fragment = new FunctionFragment(_guard, name, "view", params, [], null); + return fragment.selector; + } + /** + * Returns a new **FunctionFragment** for %%obj%%. + */ + static from(obj) { + if (FunctionFragment.isFragment(obj)) { + return obj; + } + if (typeof (obj) === "string") { + try { + return FunctionFragment.from(lex(obj)); + } + catch (error) { + assertArgument(false, "invalid function fragment", "obj", obj); + } + } + else if (obj instanceof TokenString) { + const name = consumeName("function", obj); + const inputs = consumeParams(obj); + const mutability = consumeMutability(obj); + let outputs = []; + if (consumeKeywords(obj, setify(["returns"])).has("returns")) { + outputs = consumeParams(obj); + } + const gas = consumeGas(obj); + consumeEoi(obj); + return new FunctionFragment(_guard, name, mutability, inputs, outputs, gas); + } + let stateMutability = obj.stateMutability; + // Use legacy Solidity ABI logic if stateMutability is missing + if (stateMutability == null) { + stateMutability = "payable"; + if (typeof (obj.constant) === "boolean") { + stateMutability = "view"; + if (!obj.constant) { + stateMutability = "payable"; + if (typeof (obj.payable) === "boolean" && !obj.payable) { + stateMutability = "nonpayable"; + } + } + } + else if (typeof (obj.payable) === "boolean" && !obj.payable) { + stateMutability = "nonpayable"; + } + } + // @TODO: verifyState for stateMutability (e.g. throw if + // payable: false but stateMutability is "nonpayable") + return new FunctionFragment(_guard, obj.name, stateMutability, obj.inputs ? obj.inputs.map(ParamType.from) : [], obj.outputs ? obj.outputs.map(ParamType.from) : [], (obj.gas != null) ? obj.gas : null); + } + /** + * Returns ``true`` and provides a type guard if %%value%% is a + * **FunctionFragment**. + */ + static isFragment(value) { + return (value && value[internal] === FunctionFragmentInternal); + } +} +/** + * A Fragment which represents a structure. + */ +export class StructFragment extends NamedFragment { + /** + * @private + */ + constructor(guard, name, inputs) { + super(guard, "struct", name, inputs); + Object.defineProperty(this, internal, { value: StructFragmentInternal }); + } + /** + * Returns a string representation of this struct as %%format%%. + */ + format() { + throw new Error("@TODO"); + } + /** + * Returns a new **StructFragment** for %%obj%%. + */ + static from(obj) { + if (typeof (obj) === "string") { + try { + return StructFragment.from(lex(obj)); + } + catch (error) { + assertArgument(false, "invalid struct fragment", "obj", obj); + } + } + else if (obj instanceof TokenString) { + const name = consumeName("struct", obj); + const inputs = consumeParams(obj); + consumeEoi(obj); + return new StructFragment(_guard, name, inputs); + } + return new StructFragment(_guard, obj.name, obj.inputs ? obj.inputs.map(ParamType.from) : []); + } + // @TODO: fix this return type + /** + * Returns ``true`` and provides a type guard if %%value%% is a + * **StructFragment**. + */ + static isFragment(value) { + return (value && value[internal] === StructFragmentInternal); + } +} +//# sourceMappingURL=fragments.js.map \ No newline at end of file diff --git a/lib.esm/abi/fragments.js.map b/lib.esm/abi/fragments.js.map new file mode 100644 index 00000000..21a436d8 --- /dev/null +++ b/lib.esm/abi/fragments.js.map @@ -0,0 +1 @@ +{"version":3,"file":"fragments.js","sourceRoot":"","sources":["../../src.ts/abi/fragments.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EACH,gBAAgB,EAAE,SAAS,EAAE,SAAS,EACtC,MAAM,EAAE,aAAa,EAAE,cAAc,EACxC,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAgFrC,CAAC;AAoBF,qCAAqC;AACrC,SAAS,MAAM,CAAC,KAAoB;IAChC,MAAM,MAAM,GAAgB,IAAI,GAAG,EAAE,CAAC;IACtC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACpC,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AACjC,CAAC;AAED,MAAM,cAAc,GAAG,yBAAyB,CAAC;AACjD,MAAM,aAAa,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;AAExD,sBAAsB;AACtB,MAAM,QAAQ,GAAG,6DAA6D,CAAC;AAC/E,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;AAE5C,MAAM,QAAQ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AAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA,CAAC,CAAC,EAAG,CAAC,CAAC;IAClG,CAAC;IAEL,8BAA8B;IAC1B;;;OAGG;IACH,MAAM,CAAC,UAAU,CAAC,KAAU;QACxB,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,sBAAsB,CAAC,CAAC;IACjE,CAAC;CACJ"} \ No newline at end of file diff --git a/lib.esm/abi/index.d.ts b/lib.esm/abi/index.d.ts new file mode 100644 index 00000000..2bf39932 --- /dev/null +++ b/lib.esm/abi/index.d.ts @@ -0,0 +1,18 @@ +/** + * The Application Binary Interface (ABI) describes how method input + * parameters should be encoded, their results decoded, and how to + * decode events and errors. + * + * See [About ABIs](docs-abi) for more details how they are used. + * + * @_section api/abi:Application Binary Interface [about-abi] + * @_navTitle: ABI + */ +export { AbiCoder } from "./abi-coder.js"; +export { decodeBytes32String, encodeBytes32String } from "./bytes32.js"; +export { ConstructorFragment, ErrorFragment, EventFragment, FallbackFragment, Fragment, FunctionFragment, NamedFragment, ParamType, StructFragment, } from "./fragments.js"; +export { checkResultErrors, Indexed, Interface, ErrorDescription, LogDescription, TransactionDescription, Result } from "./interface.js"; +export { Typed } from "./typed.js"; +export type { JsonFragment, JsonFragmentType, FormatType, FragmentType, ParamTypeWalkAsyncFunc, ParamTypeWalkFunc } from "./fragments.js"; +export type { InterfaceAbi, } from "./interface.js"; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/lib.esm/abi/index.d.ts.map b/lib.esm/abi/index.d.ts.map new file mode 100644 index 00000000..0d99c19b --- /dev/null +++ b/lib.esm/abi/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src.ts/abi/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAExE,OAAO,EACH,mBAAmB,EAAE,aAAa,EAAE,aAAa,EAAE,gBAAgB,EACnE,QAAQ,EAAE,gBAAgB,EAAE,aAAa,EAAE,SAAS,EAAE,cAAc,GACvE,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACH,iBAAiB,EACjB,OAAO,EACP,SAAS,EACT,gBAAgB,EAAE,cAAc,EAAE,sBAAsB,EACxD,MAAM,EACT,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,YAAY,EACR,YAAY,EAAE,gBAAgB,EAC9B,UAAU,EAAE,YAAY,EAAE,sBAAsB,EAAE,iBAAiB,EACtE,MAAM,gBAAgB,CAAC;AAExB,YAAY,EACR,YAAY,GACf,MAAM,gBAAgB,CAAC"} \ No newline at end of file diff --git a/lib.esm/abi/index.js b/lib.esm/abi/index.js new file mode 100644 index 00000000..312d4d10 --- /dev/null +++ b/lib.esm/abi/index.js @@ -0,0 +1,17 @@ +/** + * The Application Binary Interface (ABI) describes how method input + * parameters should be encoded, their results decoded, and how to + * decode events and errors. + * + * See [About ABIs](docs-abi) for more details how they are used. + * + * @_section api/abi:Application Binary Interface [about-abi] + * @_navTitle: ABI + */ +////// +export { AbiCoder } from "./abi-coder.js"; +export { decodeBytes32String, encodeBytes32String } from "./bytes32.js"; +export { ConstructorFragment, ErrorFragment, EventFragment, FallbackFragment, Fragment, FunctionFragment, NamedFragment, ParamType, StructFragment, } from "./fragments.js"; +export { checkResultErrors, Indexed, Interface, ErrorDescription, LogDescription, TransactionDescription, Result } from "./interface.js"; +export { Typed } from "./typed.js"; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib.esm/abi/index.js.map b/lib.esm/abi/index.js.map new file mode 100644 index 00000000..e4533c50 --- /dev/null +++ b/lib.esm/abi/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src.ts/abi/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,MAAM;AACN,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAExE,OAAO,EACH,mBAAmB,EAAE,aAAa,EAAE,aAAa,EAAE,gBAAgB,EACnE,QAAQ,EAAE,gBAAgB,EAAE,aAAa,EAAE,SAAS,EAAE,cAAc,GACvE,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACH,iBAAiB,EACjB,OAAO,EACP,SAAS,EACT,gBAAgB,EAAE,cAAc,EAAE,sBAAsB,EACxD,MAAM,EACT,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC"} \ No newline at end of file diff --git a/lib.esm/abi/interface.d.ts b/lib.esm/abi/interface.d.ts new file mode 100644 index 00000000..1412d7fb --- /dev/null +++ b/lib.esm/abi/interface.d.ts @@ -0,0 +1,382 @@ +/** + * The Interface class is a low-level class that accepts an + * ABI and provides all the necessary functionality to encode + * and decode paramaters to and results from methods, events + * and errors. + * + * It also provides several convenience methods to automatically + * search and find matching transactions and events to parse them. + * + * @_subsection api/abi:Interfaces [interfaces] + */ +import { AbiCoder } from "./abi-coder.js"; +import { checkResultErrors, Result } from "./coders/abstract-coder.js"; +import { ConstructorFragment, ErrorFragment, EventFragment, FallbackFragment, Fragment, FunctionFragment, ParamType } from "./fragments.js"; +import { Typed } from "./typed.js"; +import type { BigNumberish, BytesLike, CallExceptionError, CallExceptionTransaction } from "../utils/index.js"; +import type { JsonFragment } from "./fragments.js"; +export { checkResultErrors, Result }; +/** + * When using the [[Interface-parseLog]] to automatically match a Log to its event + * for parsing, a **LogDescription** is returned. + */ +export declare class LogDescription { + /** + * The matching fragment for the ``topic0``. + */ + readonly fragment: EventFragment; + /** + * The name of the Event. + */ + readonly name: string; + /** + * The full Event signature. + */ + readonly signature: string; + /** + * The topic hash for the Event. + */ + readonly topic: string; + /** + * The arguments passed into the Event with ``emit``. + */ + readonly args: Result; + /** + * @_ignore: + */ + constructor(fragment: EventFragment, topic: string, args: Result); +} +/** + * When using the [[Interface-parseTransaction]] to automatically match + * a transaction data to its function for parsing, + * a **TransactionDescription** is returned. + */ +export declare class TransactionDescription { + /** + * The matching fragment from the transaction ``data``. + */ + readonly fragment: FunctionFragment; + /** + * The name of the Function from the transaction ``data``. + */ + readonly name: string; + /** + * The arguments passed to the Function from the transaction ``data``. + */ + readonly args: Result; + /** + * The full Function signature from the transaction ``data``. + */ + readonly signature: string; + /** + * The selector for the Function from the transaction ``data``. + */ + readonly selector: string; + /** + * The ``value`` (in wei) from the transaction. + */ + readonly value: bigint; + /** + * @_ignore: + */ + constructor(fragment: FunctionFragment, selector: string, args: Result, value: bigint); +} +/** + * When using the [[Interface-parseError]] to automatically match an + * error for a call result for parsing, an **ErrorDescription** is returned. + */ +export declare class ErrorDescription { + /** + * The matching fragment. + */ + readonly fragment: ErrorFragment; + /** + * The name of the Error. + */ + readonly name: string; + /** + * The arguments passed to the Error with ``revert``. + */ + readonly args: Result; + /** + * The full Error signature. + */ + readonly signature: string; + /** + * The selector for the Error. + */ + readonly selector: string; + /** + * @_ignore: + */ + constructor(fragment: ErrorFragment, selector: string, args: Result); +} +/** + * An **Indexed** is used as a value when a value that does not + * fit within a topic (i.e. not a fixed-length, 32-byte type). It + * is the ``keccak256`` of the value, and used for types such as + * arrays, tuples, bytes and strings. + */ +export declare class Indexed { + /** + * The ``keccak256`` of the value logged. + */ + readonly hash: null | string; + /** + * @_ignore: + */ + readonly _isIndexed: boolean; + /** + * Returns ``true`` if %%value%% is an **Indexed**. + * + * This provides a Type Guard for property access. + */ + static isIndexed(value: any): value is Indexed; + /** + * @_ignore: + */ + constructor(hash: null | string); +} +/** + * An **InterfaceAbi** may be any supported ABI format. + * + * A string is expected to be a JSON string, which will be parsed + * using ``JSON.parse``. This means that the value **must** be a valid + * JSON string, with no stray commas, etc. + * + * An array may contain any combination of: + * - Human-Readable fragments + * - Parsed JSON fragment + * - [[Fragment]] instances + * + * A **Human-Readable Fragment** is a string which resembles a Solidity + * signature and is introduced in [this blog entry](link-ricmoo-humanreadableabi). + * For example, ``function balanceOf(address) view returns (uint)``. + * + * A **Parsed JSON Fragment** is a JavaScript Object desribed in the + * [Solidity documentation](link-solc-jsonabi). + */ +export type InterfaceAbi = string | ReadonlyArray; +/** + * An Interface abstracts many of the low-level details for + * encoding and decoding the data on the blockchain. + * + * An ABI provides information on how to encode data to send to + * a Contract, how to decode the results and events and how to + * interpret revert errors. + * + * The ABI can be specified by [any supported format](InterfaceAbi). + */ +export declare class Interface { + #private; + /** + * All the Contract ABI members (i.e. methods, events, errors, etc). + */ + readonly fragments: ReadonlyArray; + /** + * The Contract constructor. + */ + readonly deploy: ConstructorFragment; + /** + * The Fallback method, if any. + */ + readonly fallback: null | FallbackFragment; + /** + * If receiving ether is supported. + */ + readonly receive: boolean; + /** + * Create a new Interface for the %%fragments%%. + */ + constructor(fragments: InterfaceAbi); + /** + * Returns the entire Human-Readable ABI, as an array of + * signatures, optionally as %%minimal%% strings, which + * removes parameter names and unneceesary spaces. + */ + format(minimal?: boolean): Array; + /** + * Return the JSON-encoded ABI. This is the format Solidiy + * returns. + */ + formatJson(): string; + /** + * The ABI coder that will be used to encode and decode binary + * data. + */ + getAbiCoder(): AbiCoder; + /** + * Get the function name for %%key%%, which may be a function selector, + * function name or function signature that belongs to the ABI. + */ + getFunctionName(key: string): string; + /** + * Returns true if %%key%% (a function selector, function name or + * function signature) is present in the ABI. + * + * In the case of a function name, the name may be ambiguous, so + * accessing the [[FunctionFragment]] may require refinement. + */ + hasFunction(key: string): boolean; + /** + * Get the [[FunctionFragment]] for %%key%%, which may be a function + * selector, function name or function signature that belongs to the ABI. + * + * If %%values%% is provided, it will use the Typed API to handle + * ambiguous cases where multiple functions match by name. + * + * If the %%key%% and %%values%% do not refine to a single function in + * the ABI, this will throw. + */ + getFunction(key: string, values?: Array): null | FunctionFragment; + /** + * Iterate over all functions, calling %%callback%%, sorted by their name. + */ + forEachFunction(callback: (func: FunctionFragment, index: number) => void): void; + /** + * Get the event name for %%key%%, which may be a topic hash, + * event name or event signature that belongs to the ABI. + */ + getEventName(key: string): string; + /** + * Returns true if %%key%% (an event topic hash, event name or + * event signature) is present in the ABI. + * + * In the case of an event name, the name may be ambiguous, so + * accessing the [[EventFragment]] may require refinement. + */ + hasEvent(key: string): boolean; + /** + * Get the [[EventFragment]] for %%key%%, which may be a topic hash, + * event name or event signature that belongs to the ABI. + * + * If %%values%% is provided, it will use the Typed API to handle + * ambiguous cases where multiple events match by name. + * + * If the %%key%% and %%values%% do not refine to a single event in + * the ABI, this will throw. + */ + getEvent(key: string, values?: Array): null | EventFragment; + /** + * Iterate over all events, calling %%callback%%, sorted by their name. + */ + forEachEvent(callback: (func: EventFragment, index: number) => void): void; + /** + * Get the [[ErrorFragment]] for %%key%%, which may be an error + * selector, error name or error signature that belongs to the ABI. + * + * If %%values%% is provided, it will use the Typed API to handle + * ambiguous cases where multiple errors match by name. + * + * If the %%key%% and %%values%% do not refine to a single error in + * the ABI, this will throw. + */ + getError(key: string, values?: Array): null | ErrorFragment; + /** + * Iterate over all errors, calling %%callback%%, sorted by their name. + */ + forEachError(callback: (func: ErrorFragment, index: number) => void): void; + _decodeParams(params: ReadonlyArray, data: BytesLike): Result; + _encodeParams(params: ReadonlyArray, values: ReadonlyArray): string; + /** + * Encodes a ``tx.data`` object for deploying the Contract with + * the %%values%% as the constructor arguments. + */ + encodeDeploy(values?: ReadonlyArray): string; + /** + * Decodes the result %%data%% (e.g. from an ``quai_call``) for the + * specified error (see [[getError]] for valid values for + * %%key%%). + * + * Most developers should prefer the [[parseCallResult]] method instead, + * which will automatically detect a ``CALL_EXCEPTION`` and throw the + * corresponding error. + */ + decodeErrorResult(fragment: ErrorFragment | string, data: BytesLike): Result; + /** + * Encodes the transaction revert data for a call result that + * reverted from the the Contract with the sepcified %%error%% + * (see [[getError]] for valid values for %%fragment%%) with the %%values%%. + * + * This is generally not used by most developers, unless trying to mock + * a result from a Contract. + */ + encodeErrorResult(fragment: ErrorFragment | string, values?: ReadonlyArray): string; + /** + * Decodes the %%data%% from a transaction ``tx.data`` for + * the function specified (see [[getFunction]] for valid values + * for %%fragment%%). + * + * Most developers should prefer the [[parseTransaction]] method + * instead, which will automatically detect the fragment. + */ + decodeFunctionData(fragment: FunctionFragment | string, data: BytesLike): Result; + /** + * Encodes the ``tx.data`` for a transaction that calls the function + * specified (see [[getFunction]] for valid values for %%fragment%%) with + * the %%values%%. + */ + encodeFunctionData(fragment: FunctionFragment | string, values?: ReadonlyArray): string; + /** + * Decodes the result %%data%% (e.g. from an ``quai_call``) for the + * specified function (see [[getFunction]] for valid values for + * %%key%%). + * + * Most developers should prefer the [[parseCallResult]] method instead, + * which will automatically detect a ``CALL_EXCEPTION`` and throw the + * corresponding error. + */ + decodeFunctionResult(fragment: FunctionFragment | string, data: BytesLike): Result; + makeError(_data: BytesLike, tx: CallExceptionTransaction): CallExceptionError; + /** + * Encodes the result data (e.g. from an ``quai_call``) for the + * specified function (see [[getFunction]] for valid values + * for %%fragment%%) with %%values%%. + * + * This is generally not used by most developers, unless trying to mock + * a result from a Contract. + */ + encodeFunctionResult(fragment: FunctionFragment | string, values?: ReadonlyArray): string; + encodeFilterTopics(fragment: EventFragment | string, values: ReadonlyArray): Array>; + encodeEventLog(fragment: EventFragment | string, values: ReadonlyArray): { + data: string; + topics: Array; + }; + decodeEventLog(fragment: EventFragment | string, data: BytesLike, topics?: ReadonlyArray): Result; + /** + * Parses a transaction, finding the matching function and extracts + * the parameter values along with other useful function details. + * + * If the matching function cannot be found, return null. + */ + parseTransaction(tx: { + data: string; + value?: BigNumberish; + }): null | TransactionDescription; + parseCallResult(data: BytesLike): Result; + /** + * Parses a receipt log, finding the matching event and extracts + * the parameter values along with other useful event details. + * + * If the matching event cannot be found, returns null. + */ + parseLog(log: { + topics: Array; + data: string; + }): null | LogDescription; + /** + * Parses a revert data, finding the matching error and extracts + * the parameter values along with other useful error details. + * + * If the matching error cannot be found, returns null. + */ + parseError(data: BytesLike): null | ErrorDescription; + /** + * Creates a new [[Interface]] from the ABI %%value%%. + * + * The %%value%% may be provided as an existing [[Interface]] object, + * a JSON-encoded ABI or any Human-Readable ABI format. + */ + static from(value: InterfaceAbi | Interface): Interface; +} +//# sourceMappingURL=interface.d.ts.map \ No newline at end of file diff --git a/lib.esm/abi/interface.d.ts.map b/lib.esm/abi/interface.d.ts.map new file mode 100644 index 00000000..e88d9350 --- /dev/null +++ b/lib.esm/abi/interface.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../src.ts/abi/interface.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAUH,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,EACH,mBAAmB,EAAE,aAAa,EAAE,aAAa,EAAE,gBAAgB,EACnE,QAAQ,EAAE,gBAAgB,EAAE,SAAS,EACxC,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAE/G,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAGnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,CAAC;AAErC;;;GAGG;AACH,qBAAa,cAAc;IACvB;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAG,aAAa,CAAC;IAElC;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAG,MAAM,CAAC;IAEvB;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAG,MAAM,CAAC;IAE5B;;OAEG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AAE,KAAK,CAAC,MAAM,CAAC,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAC,GAAG,IAAI,GAAG,cAAc;IAa5E;;;;;OAKG;IACH,UAAU,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI,GAAG,gBAAgB;IAWpD;;;;;OAKG;IACH,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,YAAY,GAAG,SAAS,GAAG,SAAS;CAe1D"} \ No newline at end of file diff --git a/lib.esm/abi/interface.js b/lib.esm/abi/interface.js new file mode 100644 index 00000000..d0cd034c --- /dev/null +++ b/lib.esm/abi/interface.js @@ -0,0 +1,1097 @@ +/** + * The Interface class is a low-level class that accepts an + * ABI and provides all the necessary functionality to encode + * and decode paramaters to and results from methods, events + * and errors. + * + * It also provides several convenience methods to automatically + * search and find matching transactions and events to parse them. + * + * @_subsection api/abi:Interfaces [interfaces] + */ +import { keccak256 } from "../crypto/index.js"; +import { id } from "../hash/index.js"; +import { concat, dataSlice, getBigInt, getBytes, getBytesCopy, hexlify, zeroPadBytes, zeroPadValue, isHexString, defineProperties, assertArgument, toBeHex, assert } from "../utils/index.js"; +import { AbiCoder } from "./abi-coder.js"; +import { checkResultErrors, Result } from "./coders/abstract-coder.js"; +import { ConstructorFragment, ErrorFragment, EventFragment, Fragment, FunctionFragment, ParamType } from "./fragments.js"; +import { Typed } from "./typed.js"; +export { checkResultErrors, Result }; +/** + * When using the [[Interface-parseLog]] to automatically match a Log to its event + * for parsing, a **LogDescription** is returned. + */ +export class LogDescription { + /** + * The matching fragment for the ``topic0``. + */ + fragment; + /** + * The name of the Event. + */ + name; + /** + * The full Event signature. + */ + signature; + /** + * The topic hash for the Event. + */ + topic; + /** + * The arguments passed into the Event with ``emit``. + */ + args; + /** + * @_ignore: + */ + constructor(fragment, topic, args) { + const name = fragment.name, signature = fragment.format(); + defineProperties(this, { + fragment, name, signature, topic, args + }); + } +} +/** + * When using the [[Interface-parseTransaction]] to automatically match + * a transaction data to its function for parsing, + * a **TransactionDescription** is returned. + */ +export class TransactionDescription { + /** + * The matching fragment from the transaction ``data``. + */ + fragment; + /** + * The name of the Function from the transaction ``data``. + */ + name; + /** + * The arguments passed to the Function from the transaction ``data``. + */ + args; + /** + * The full Function signature from the transaction ``data``. + */ + signature; + /** + * The selector for the Function from the transaction ``data``. + */ + selector; + /** + * The ``value`` (in wei) from the transaction. + */ + value; + /** + * @_ignore: + */ + constructor(fragment, selector, args, value) { + const name = fragment.name, signature = fragment.format(); + defineProperties(this, { + fragment, name, args, signature, selector, value + }); + } +} +/** + * When using the [[Interface-parseError]] to automatically match an + * error for a call result for parsing, an **ErrorDescription** is returned. + */ +export class ErrorDescription { + /** + * The matching fragment. + */ + fragment; + /** + * The name of the Error. + */ + name; + /** + * The arguments passed to the Error with ``revert``. + */ + args; + /** + * The full Error signature. + */ + signature; + /** + * The selector for the Error. + */ + selector; + /** + * @_ignore: + */ + constructor(fragment, selector, args) { + const name = fragment.name, signature = fragment.format(); + defineProperties(this, { + fragment, name, args, signature, selector + }); + } +} +/** + * An **Indexed** is used as a value when a value that does not + * fit within a topic (i.e. not a fixed-length, 32-byte type). It + * is the ``keccak256`` of the value, and used for types such as + * arrays, tuples, bytes and strings. + */ +export class Indexed { + /** + * The ``keccak256`` of the value logged. + */ + hash; + /** + * @_ignore: + */ + _isIndexed; + /** + * Returns ``true`` if %%value%% is an **Indexed**. + * + * This provides a Type Guard for property access. + */ + static isIndexed(value) { + return !!(value && value._isIndexed); + } + /** + * @_ignore: + */ + constructor(hash) { + defineProperties(this, { hash, _isIndexed: true }); + } +} +// 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})`; + } + } +}; +/** + * An Interface abstracts many of the low-level details for + * encoding and decoding the data on the blockchain. + * + * An ABI provides information on how to encode data to send to + * a Contract, how to decode the results and events and how to + * interpret revert errors. + * + * The ABI can be specified by [any supported format](InterfaceAbi). + */ +export class Interface { + /** + * All the Contract ABI members (i.e. methods, events, errors, etc). + */ + fragments; + /** + * The Contract constructor. + */ + deploy; + /** + * The Fallback method, if any. + */ + fallback; + /** + * If receiving ether is supported. + */ + receive; + #errors; + #events; + #functions; + // #structs: Map; + #abiCoder; + /** + * Create a new Interface for the %%fragments%%. + */ + 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(); + const frags = []; + for (const a of abi) { + try { + frags.push(Fragment.from(a)); + } + catch (error) { + console.log("EE", error); + } + } + defineProperties(this, { + fragments: Object.freeze(frags) + }); + let fallback = null; + let receive = false; + this.#abiCoder = this.getAbiCoder(); + // Add all fragments by their signature + this.fragments.forEach((fragment, index) => { + let bucket; + switch (fragment.type) { + case "constructor": + if (this.deploy) { + console.log("duplicate definition - constructor"); + return; + } + //checkNames(fragment, "input", fragment.inputs); + defineProperties(this, { deploy: fragment }); + return; + case "fallback": + if (fragment.inputs.length === 0) { + receive = true; + } + else { + assertArgument(!fallback || fragment.payable !== fallback.payable, "conflicting fallback fragments", `fragments[${index}]`, fragment); + fallback = fragment; + receive = fallback.payable; + } + return; + case "function": + //checkNames(fragment, "input", fragment.inputs); + //checkNames(fragment, "output", (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; + } + // Two identical entries; ignore it + const signature = fragment.format(); + if (bucket.has(signature)) { + return; + } + bucket.set(signature, fragment); + }); + // If we do not have a constructor add a default + if (!this.deploy) { + defineProperties(this, { + deploy: ConstructorFragment.from("constructor()") + }); + } + defineProperties(this, { fallback, receive }); + } + /** + * Returns the entire Human-Readable ABI, as an array of + * signatures, optionally as %%minimal%% strings, which + * removes parameter names and unneceesary spaces. + */ + format(minimal) { + const format = (minimal ? "minimal" : "full"); + const abi = this.fragments.map((f) => f.format(format)); + return abi; + } + /** + * Return the JSON-encoded ABI. This is the format Solidiy + * returns. + */ + formatJson() { + const abi = this.fragments.map((f) => f.format("json")); + // We need to re-bundle the JSON fragments a bit + return JSON.stringify(abi.map((j) => JSON.parse(j))); + } + /** + * The ABI coder that will be used to encode and decode binary + * data. + */ + getAbiCoder() { + return AbiCoder.defaultAbiCoder(); + } + // Find a function definition by any means necessary (unless it is ambiguous) + #getFunction(key, values, forceUnique) { + // Selector + if (isHexString(key)) { + const selector = key.toLowerCase(); + for (const fragment of this.#functions.values()) { + if (selector === fragment.selector) { + return fragment; + } + } + return null; + } + // 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.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.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) { + return null; + } + if (matching.length > 1 && forceUnique) { + const matchStr = matching.map((m) => JSON.stringify(m.format())).join(", "); + assertArgument(false, `ambiguous function description (i.e. matches ${matchStr})`, "key", key); + } + return matching[0]; + } + // Normalize the signature and lookup the function + const result = this.#functions.get(FunctionFragment.from(key).format()); + if (result) { + return result; + } + return null; + } + /** + * Get the function name for %%key%%, which may be a function selector, + * function name or function signature that belongs to the ABI. + */ + getFunctionName(key) { + const fragment = this.#getFunction(key, null, false); + assertArgument(fragment, "no matching function", "key", key); + return fragment.name; + } + /** + * Returns true if %%key%% (a function selector, function name or + * function signature) is present in the ABI. + * + * In the case of a function name, the name may be ambiguous, so + * accessing the [[FunctionFragment]] may require refinement. + */ + hasFunction(key) { + return !!this.#getFunction(key, null, false); + } + /** + * Get the [[FunctionFragment]] for %%key%%, which may be a function + * selector, function name or function signature that belongs to the ABI. + * + * If %%values%% is provided, it will use the Typed API to handle + * ambiguous cases where multiple functions match by name. + * + * If the %%key%% and %%values%% do not refine to a single function in + * the ABI, this will throw. + */ + getFunction(key, values) { + return this.#getFunction(key, values || null, true); + } + /** + * Iterate over all functions, calling %%callback%%, sorted by their name. + */ + forEachFunction(callback) { + const names = Array.from(this.#functions.keys()); + names.sort((a, b) => a.localeCompare(b)); + for (let i = 0; i < names.length; i++) { + const name = names[i]; + callback((this.#functions.get(name)), i); + } + } + // Find an event definition by any means necessary (unless it is ambiguous) + #getEvent(key, values, forceUnique) { + // EventTopic + if (isHexString(key)) { + const eventTopic = key.toLowerCase(); + for (const fragment of this.#events.values()) { + if (eventTopic === fragment.topicHash) { + return fragment; + } + } + return null; + } + // 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.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) { + return null; + } + if (matching.length > 1 && forceUnique) { + const matchStr = matching.map((m) => JSON.stringify(m.format())).join(", "); + assertArgument(false, `ambiguous event description (i.e. matches ${matchStr})`, "key", key); + } + return matching[0]; + } + // Normalize the signature and lookup the function + const result = this.#events.get(EventFragment.from(key).format()); + if (result) { + return result; + } + return null; + } + /** + * Get the event name for %%key%%, which may be a topic hash, + * event name or event signature that belongs to the ABI. + */ + getEventName(key) { + const fragment = this.#getEvent(key, null, false); + assertArgument(fragment, "no matching event", "key", key); + return fragment.name; + } + /** + * Returns true if %%key%% (an event topic hash, event name or + * event signature) is present in the ABI. + * + * In the case of an event name, the name may be ambiguous, so + * accessing the [[EventFragment]] may require refinement. + */ + hasEvent(key) { + return !!this.#getEvent(key, null, false); + } + /** + * Get the [[EventFragment]] for %%key%%, which may be a topic hash, + * event name or event signature that belongs to the ABI. + * + * If %%values%% is provided, it will use the Typed API to handle + * ambiguous cases where multiple events match by name. + * + * If the %%key%% and %%values%% do not refine to a single event in + * the ABI, this will throw. + */ + getEvent(key, values) { + return this.#getEvent(key, values || null, true); + } + /** + * Iterate over all events, calling %%callback%%, sorted by their name. + */ + forEachEvent(callback) { + const names = Array.from(this.#events.keys()); + names.sort((a, b) => a.localeCompare(b)); + for (let i = 0; i < names.length; i++) { + const name = names[i]; + callback((this.#events.get(name)), i); + } + } + /** + * Get the [[ErrorFragment]] for %%key%%, which may be an error + * selector, error name or error signature that belongs to the ABI. + * + * If %%values%% is provided, it will use the Typed API to handle + * ambiguous cases where multiple errors match by name. + * + * If the %%key%% and %%values%% do not refine to a single error in + * the ABI, this will throw. + */ + getError(key, values) { + if (isHexString(key)) { + const selector = key.toLowerCase(); + if (BuiltinErrors[selector]) { + return ErrorFragment.from(BuiltinErrors[selector].signature); + } + for (const fragment of this.#errors.values()) { + if (selector === fragment.selector) { + return fragment; + } + } + return null; + } + // 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 ErrorFragment.from("error Error(string)"); + } + if (key === "Panic") { + return ErrorFragment.from("error Panic(uint256)"); + } + return null; + } + else if (matching.length > 1) { + const matchStr = matching.map((m) => JSON.stringify(m.format())).join(", "); + assertArgument(false, `ambiguous error description (i.e. ${matchStr})`, "name", key); + } + return matching[0]; + } + // Normalize the signature and lookup the function + key = ErrorFragment.from(key).format(); + if (key === "Error(string)") { + return ErrorFragment.from("error Error(string)"); + } + if (key === "Panic(uint256)") { + return ErrorFragment.from("error Panic(uint256)"); + } + const result = this.#errors.get(key); + if (result) { + return result; + } + return null; + } + /** + * Iterate over all errors, calling %%callback%%, sorted by their name. + */ + forEachError(callback) { + const names = Array.from(this.#errors.keys()); + names.sort((a, b) => a.localeCompare(b)); + for (let i = 0; i < names.length; i++) { + const name = names[i]; + callback((this.#errors.get(name)), i); + } + } + // Get the 4-byte selector used by Solidity to identify a function + /* +getSelector(fragment: ErrorFragment | FunctionFragment): string { + if (typeof(fragment) === "string") { + const matches: Array = [ ]; + + try { matches.push(this.getFunction(fragment)); } catch (error) { } + try { matches.push(this.getError(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 dataSlice(id(fragment.format()), 0, 4); +} + */ + // Get the 32-byte topic hash used by Solidity to identify an event + /* + getEventTopic(fragment: EventFragment): string { + //if (typeof(fragment) === "string") { fragment = this.getEvent(eventFragment); } + return id(fragment.format()); + } + */ + _decodeParams(params, data) { + return this.#abiCoder.decode(params, data); + } + _encodeParams(params, values) { + return this.#abiCoder.encode(params, values); + } + /** + * Encodes a ``tx.data`` object for deploying the Contract with + * the %%values%% as the constructor arguments. + */ + encodeDeploy(values) { + return this._encodeParams(this.deploy.inputs, values || []); + } + /** + * Decodes the result %%data%% (e.g. from an ``quai_call``) for the + * specified error (see [[getError]] for valid values for + * %%key%%). + * + * Most developers should prefer the [[parseCallResult]] method instead, + * which will automatically detect a ``CALL_EXCEPTION`` and throw the + * corresponding error. + */ + decodeErrorResult(fragment, data) { + if (typeof (fragment) === "string") { + const f = this.getError(fragment); + assertArgument(f, "unknown error", "fragment", fragment); + fragment = f; + } + assertArgument(dataSlice(data, 0, 4) === fragment.selector, `data signature does not match error ${fragment.name}.`, "data", data); + return this._decodeParams(fragment.inputs, dataSlice(data, 4)); + } + /** + * Encodes the transaction revert data for a call result that + * reverted from the the Contract with the sepcified %%error%% + * (see [[getError]] for valid values for %%fragment%%) with the %%values%%. + * + * This is generally not used by most developers, unless trying to mock + * a result from a Contract. + */ + encodeErrorResult(fragment, values) { + if (typeof (fragment) === "string") { + const f = this.getError(fragment); + assertArgument(f, "unknown error", "fragment", fragment); + fragment = f; + } + return concat([ + fragment.selector, + this._encodeParams(fragment.inputs, values || []) + ]); + } + /** + * Decodes the %%data%% from a transaction ``tx.data`` for + * the function specified (see [[getFunction]] for valid values + * for %%fragment%%). + * + * Most developers should prefer the [[parseTransaction]] method + * instead, which will automatically detect the fragment. + */ + decodeFunctionData(fragment, data) { + if (typeof (fragment) === "string") { + const f = this.getFunction(fragment); + assertArgument(f, "unknown function", "fragment", fragment); + fragment = f; + } + assertArgument(dataSlice(data, 0, 4) === fragment.selector, `data signature does not match function ${fragment.name}.`, "data", data); + return this._decodeParams(fragment.inputs, dataSlice(data, 4)); + } + /** + * Encodes the ``tx.data`` for a transaction that calls the function + * specified (see [[getFunction]] for valid values for %%fragment%%) with + * the %%values%%. + */ + encodeFunctionData(fragment, values) { + if (typeof (fragment) === "string") { + const f = this.getFunction(fragment); + assertArgument(f, "unknown function", "fragment", fragment); + fragment = f; + } + return concat([ + fragment.selector, + this._encodeParams(fragment.inputs, values || []) + ]); + } + /** + * Decodes the result %%data%% (e.g. from an ``quai_call``) for the + * specified function (see [[getFunction]] for valid values for + * %%key%%). + * + * Most developers should prefer the [[parseCallResult]] method instead, + * which will automatically detect a ``CALL_EXCEPTION`` and throw the + * corresponding error. + */ + decodeFunctionResult(fragment, data) { + if (typeof (fragment) === "string") { + const f = this.getFunction(fragment); + assertArgument(f, "unknown function", "fragment", fragment); + fragment = f; + } + let message = "invalid length for result data"; + const bytes = 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 + assert(false, message, "BAD_DATA", { + value: hexlify(bytes), + info: { method: fragment.name, signature: fragment.format() } + }); + } + makeError(_data, tx) { + const data = getBytes(_data, "data"); + const error = AbiCoder.getBuiltinCallException("call", tx, data); + // Not a built-in error; try finding a custom error + const customPrefix = "execution reverted (unknown custom error)"; + if (error.message.startsWith(customPrefix)) { + const selector = hexlify(data.slice(0, 4)); + const ef = this.getError(selector); + if (ef) { + try { + const args = this.#abiCoder.decode(ef.inputs, data.slice(4)); + error.revert = { + name: ef.name, signature: ef.format(), args + }; + error.reason = error.revert.signature; + error.message = `execution reverted: ${error.reason}`; + } + catch (e) { + error.message = `execution reverted (coult not decode custom error)`; + } + } + } + // Add the invocation, if available + const parsed = this.parseTransaction(tx); + if (parsed) { + error.invocation = { + method: parsed.name, + signature: parsed.signature, + args: parsed.args + }; + } + return error; + } + /** + * Encodes the result data (e.g. from an ``quai_call``) for the + * specified function (see [[getFunction]] for valid values + * for %%fragment%%) with %%values%%. + * + * This is generally not used by most developers, unless trying to mock + * a result from a Contract. + */ + encodeFunctionResult(fragment, values) { + if (typeof (fragment) === "string") { + const f = this.getFunction(fragment); + assertArgument(f, "unknown function", "fragment", fragment); + fragment = f; + } + return hexlify(this.#abiCoder.encode(fragment.outputs, values || [])); + } + /* + spelunk(inputs: Array, values: ReadonlyArray, processfunc: (type: string, value: any) => Promise): Promise> { + const promises: Array> = [ ]; + const process = function(type: ParamType, value: any): any { + if (type.baseType === "array") { + return descend(type.child + } + if (type. === "address") { + } + }; + + const descend = function (inputs: Array, values: ReadonlyArray) { + if (inputs.length !== values.length) { throw new Error("length mismatch"); } + + }; + + const result: Array = [ ]; + 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 quai_filterLog) + encodeFilterTopics(fragment, values) { + if (typeof (fragment) === "string") { + const f = this.getEvent(fragment); + assertArgument(f, "unknown event", "eventFragment", fragment); + fragment = f; + } + assert(values.length <= fragment.inputs.length, `too many arguments for ${fragment.format()}`, "UNEXPECTED_ARGUMENT", { count: values.length, expectedCount: fragment.inputs.length }); + const topics = []; + if (!fragment.anonymous) { + topics.push(fragment.topicHash); + } + // @TODO: Use the coders for this; to properly support tuples, etc. + const encodeTopic = (param, value) => { + if (param.type === "string") { + return id(value); + } + else if (param.type === "bytes") { + return keccak256(hexlify(value)); + } + if (param.type === "bool" && typeof (value) === "boolean") { + value = (value ? "0x01" : "0x00"); + } + else if (param.type.match(/^u?int/)) { + value = toBeHex(value); // @TODO: Should this toTwos?? + } + else if (param.type.match(/^bytes/)) { + value = zeroPadBytes(value, 32); + } + else if (param.type === "address") { + // Check addresses are valid + this.#abiCoder.encode(["address"], [value]); + } + return zeroPadValue(hexlify(value), 32); + }; + values.forEach((value, index) => { + const param = fragment.inputs[index]; + if (!param.indexed) { + assertArgument(value == null, "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") { + assertArgument(false, "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(fragment, values) { + if (typeof (fragment) === "string") { + const f = this.getEvent(fragment); + assertArgument(f, "unknown event", "eventFragment", fragment); + fragment = f; + } + const topics = []; + const dataTypes = []; + const dataValues = []; + if (!fragment.anonymous) { + topics.push(fragment.topicHash); + } + assertArgument(values.length === fragment.inputs.length, "event arguments/values mismatch", "values", values); + fragment.inputs.forEach((param, index) => { + const value = values[index]; + if (param.indexed) { + if (param.type === "string") { + topics.push(id(value)); + } + else if (param.type === "bytes") { + topics.push(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(fragment, data, topics) { + if (typeof (fragment) === "string") { + const f = this.getEvent(fragment); + assertArgument(f, "unknown event", "eventFragment", fragment); + fragment = f; + } + if (topics != null && !fragment.anonymous) { + const eventTopic = fragment.topicHash; + assertArgument(isHexString(topics[0], 32) && topics[0].toLowerCase() === eventTopic, "fragment/topic mismatch", "topics[0]", topics[0]); + topics = topics.slice(1); + } + const indexed = []; + const nonIndexed = []; + const dynamic = []; + fragment.inputs.forEach((param, index) => { + if (param.indexed) { + if (param.type === "string" || param.type === "bytes" || param.baseType === "tuple" || param.baseType === "array") { + indexed.push(ParamType.from({ 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, concat(topics)) : null; + const resultNonIndexed = this.#abiCoder.decode(nonIndexed, data, true); + //const result: (Array & { [ key: string ]: any }) = [ ]; + const values = []; + const keys = []; + let nonIndexedIndex = 0, indexedIndex = 0; + fragment.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 Result.fromItems(values, keys); + } + /** + * Parses a transaction, finding the matching function and extracts + * the parameter values along with other useful function details. + * + * If the matching function cannot be found, return null. + */ + parseTransaction(tx) { + const data = getBytes(tx.data, "tx.data"); + const value = getBigInt((tx.value != null) ? tx.value : 0, "tx.value"); + const fragment = this.getFunction(hexlify(data.slice(0, 4))); + if (!fragment) { + return null; + } + const args = this.#abiCoder.decode(fragment.inputs, data.slice(4)); + return new TransactionDescription(fragment, fragment.selector, args, value); + } + parseCallResult(data) { + throw new Error("@TODO"); + } + /** + * Parses a receipt log, finding the matching event and extracts + * the parameter values along with other useful event details. + * + * If the matching event cannot be found, returns null. + */ + 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, fragment.topicHash, this.decodeEventLog(fragment, log.data, log.topics)); + } + /** + * Parses a revert data, finding the matching error and extracts + * the parameter values along with other useful error details. + * + * If the matching error cannot be found, returns null. + */ + parseError(data) { + const hexData = hexlify(data); + const fragment = this.getError(dataSlice(hexData, 0, 4)); + if (!fragment) { + return null; + } + const args = this.#abiCoder.decode(fragment.inputs, dataSlice(hexData, 4)); + return new ErrorDescription(fragment, fragment.selector, args); + } + /** + * Creates a new [[Interface]] from the ABI %%value%%. + * + * The %%value%% may be provided as an existing [[Interface]] object, + * a JSON-encoded ABI or any Human-Readable ABI format. + */ + 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("json")); + } + // Array of fragments + return new Interface(value); + } +} +//# sourceMappingURL=interface.js.map \ No newline at end of file diff --git a/lib.esm/abi/interface.js.map b/lib.esm/abi/interface.js.map new file mode 100644 index 00000000..08b6d906 --- /dev/null +++ b/lib.esm/abi/interface.js.map @@ -0,0 +1 @@ +{"version":3,"file":"interface.js","sourceRoot":"","sources":["../../src.ts/abi/interface.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAA;AACrC,OAAO,EACH,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY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YAAE,OAAO,IAAI,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;SAAE;QAE5E,qEAAqE;QACrE,IAAI,OAAM,CAAO,KAAM,CAAC,MAAM,CAAC,KAAK,UAAU,EAAE;YAC5C,OAAO,IAAI,SAAS,CAAO,KAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;SACrD;QAED,qBAAqB;QACrB,OAAO,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC;CACJ"} \ No newline at end of file diff --git a/lib.esm/abi/typed.d.ts b/lib.esm/abi/typed.d.ts new file mode 100644 index 00000000..8707a62f --- /dev/null +++ b/lib.esm/abi/typed.d.ts @@ -0,0 +1,570 @@ +/** + * A Typed object allows a value to have its type explicitly + * specified. + * + * For example, in Solidity, the value ``45`` could represent a + * ``uint8`` or a ``uint256``. The value ``0x1234`` could represent + * a ``bytes2`` or ``bytes``. + * + * Since JavaScript has no meaningful way to explicitly inform any + * APIs which what the type is, this allows transparent interoperation + * with Soldity. + * + * @_subsection: api/abi:Typed Values + */ +import type { Addressable } from "../address/index.js"; +import type { BigNumberish, BytesLike } from "../utils/index.js"; +import type { Result } from "./coders/abstract-coder.js"; +/** + * @_ignore: + */ +export interface TypedNumber extends Typed { + value: number; + defaultValue(): number; + minValue(): number; + maxValue(): number; +} +/** + * A **Typed** that represents a numeric value. + */ +export interface TypedBigInt extends Typed { + /** + * The value. + */ + value: bigint; + /** + * The default value for all numeric types is ``0``. + */ + defaultValue(): bigint; + /** + * The minimum value for this type, accounting for bit-width and signed-ness. + */ + minValue(): bigint; + /** + * The minimum value for this type, accounting for bit-width. + */ + maxValue(): bigint; +} +/** + * A **Typed** that represents a binary sequence of data as bytes. + */ +export interface TypedData extends Typed { + /** + * The value. + */ + value: string; + /** + * The default value for this type. + */ + defaultValue(): string; +} +/** + * A **Typed** that represents a UTF-8 sequence of bytes. + */ +export interface TypedString extends Typed { + /** + * The value. + */ + value: string; + /** + * The default value for the string type is the empty string (i.e. ``""``). + */ + defaultValue(): string; +} +/** + * The **Typed** class to wrap values providing explicit type information. + */ +export declare class Typed { + #private; + /** + * The type, as a Solidity-compatible type. + */ + readonly type: string; + /** + * The actual value. + */ + readonly value: any; + /** + * @_ignore: + */ + readonly _typedSymbol: Symbol; + /** + * @_ignore: + */ + constructor(gaurd: any, type: string, value: any, options?: any); + /** + * Format the type as a Human-Readable type. + */ + format(): string; + /** + * The default value returned by this type. + */ + defaultValue(): string | number | bigint | Result; + /** + * The minimum value for numeric types. + */ + minValue(): string | number | bigint; + /** + * The maximum value for numeric types. + */ + maxValue(): string | number | bigint; + /** + * Returns ``true`` and provides a type guard is this is a [[TypedBigInt]]. + */ + isBigInt(): this is TypedBigInt; + /** + * Returns ``true`` and provides a type guard is this is a [[TypedData]]. + */ + isData(): this is TypedData; + /** + * Returns ``true`` and provides a type guard is this is a [[TypedString]]. + */ + isString(): this is TypedString; + /** + * Returns the tuple name, if this is a tuple. Throws otherwise. + */ + get tupleName(): null | string; + /** + * Returns the length of the array type or ``-1`` if it is dynamic. + * + * Throws if the type is not an array. + */ + get arrayLength(): null | number; + /** + * Returns a new **Typed** of %%type%% with the %%value%%. + */ + static from(type: string, value: any): Typed; + /** + * Return a new ``uint8`` type for %%v%%. + */ + static uint8(v: BigNumberish): Typed; + /** + * Return a new ``uint16`` type for %%v%%. + */ + static uint16(v: BigNumberish): Typed; + /** + * Return a new ``uint24`` type for %%v%%. + */ + static uint24(v: BigNumberish): Typed; + /** + * Return a new ``uint32`` type for %%v%%. + */ + static uint32(v: BigNumberish): Typed; + /** + * Return a new ``uint40`` type for %%v%%. + */ + static uint40(v: BigNumberish): Typed; + /** + * Return a new ``uint48`` type for %%v%%. + */ + static uint48(v: BigNumberish): Typed; + /** + * Return a new ``uint56`` type for %%v%%. + */ + static uint56(v: BigNumberish): Typed; + /** + * Return a new ``uint64`` type for %%v%%. + */ + static uint64(v: BigNumberish): Typed; + /** + * Return a new ``uint72`` type for %%v%%. + */ + static uint72(v: BigNumberish): Typed; + /** + * Return a new ``uint80`` type for %%v%%. + */ + static uint80(v: BigNumberish): Typed; + /** + * Return a new ``uint88`` type for %%v%%. + */ + static uint88(v: BigNumberish): Typed; + /** + * Return a new ``uint96`` type for %%v%%. + */ + static uint96(v: BigNumberish): Typed; + /** + * Return a new ``uint104`` type for %%v%%. + */ + static uint104(v: BigNumberish): Typed; + /** + * Return a new ``uint112`` type for %%v%%. + */ + static uint112(v: BigNumberish): Typed; + /** + * Return a new ``uint120`` type for %%v%%. + */ + static uint120(v: BigNumberish): Typed; + /** + * Return a new ``uint128`` type for %%v%%. + */ + static uint128(v: BigNumberish): Typed; + /** + * Return a new ``uint136`` type for %%v%%. + */ + static uint136(v: BigNumberish): Typed; + /** + * Return a new ``uint144`` type for %%v%%. + */ + static uint144(v: BigNumberish): Typed; + /** + * Return a new ``uint152`` type for %%v%%. + */ + static uint152(v: BigNumberish): Typed; + /** + * Return a new ``uint160`` type for %%v%%. + */ + static uint160(v: BigNumberish): Typed; + /** + * Return a new ``uint168`` type for %%v%%. + */ + static uint168(v: BigNumberish): Typed; + /** + * Return a new ``uint176`` type for %%v%%. + */ + static uint176(v: BigNumberish): Typed; + /** + * Return a new ``uint184`` type for %%v%%. + */ + static uint184(v: BigNumberish): Typed; + /** + * Return a new ``uint192`` type for %%v%%. + */ + static uint192(v: BigNumberish): Typed; + /** + * Return a new ``uint200`` type for %%v%%. + */ + static uint200(v: BigNumberish): Typed; + /** + * Return a new ``uint208`` type for %%v%%. + */ + static uint208(v: BigNumberish): Typed; + /** + * Return a new ``uint216`` type for %%v%%. + */ + static uint216(v: BigNumberish): Typed; + /** + * Return a new ``uint224`` type for %%v%%. + */ + static uint224(v: BigNumberish): Typed; + /** + * Return a new ``uint232`` type for %%v%%. + */ + static uint232(v: BigNumberish): Typed; + /** + * Return a new ``uint240`` type for %%v%%. + */ + static uint240(v: BigNumberish): Typed; + /** + * Return a new ``uint248`` type for %%v%%. + */ + static uint248(v: BigNumberish): Typed; + /** + * Return a new ``uint256`` type for %%v%%. + */ + static uint256(v: BigNumberish): Typed; + /** + * Return a new ``uint256`` type for %%v%%. + */ + static uint(v: BigNumberish): Typed; + /** + * Return a new ``int8`` type for %%v%%. + */ + static int8(v: BigNumberish): Typed; + /** + * Return a new ``int16`` type for %%v%%. + */ + static int16(v: BigNumberish): Typed; + /** + * Return a new ``int24`` type for %%v%%. + */ + static int24(v: BigNumberish): Typed; + /** + * Return a new ``int32`` type for %%v%%. + */ + static int32(v: BigNumberish): Typed; + /** + * Return a new ``int40`` type for %%v%%. + */ + static int40(v: BigNumberish): Typed; + /** + * Return a new ``int48`` type for %%v%%. + */ + static int48(v: BigNumberish): Typed; + /** + * Return a new ``int56`` type for %%v%%. + */ + static int56(v: BigNumberish): Typed; + /** + * Return a new ``int64`` type for %%v%%. + */ + static int64(v: BigNumberish): Typed; + /** + * Return a new ``int72`` type for %%v%%. + */ + static int72(v: BigNumberish): Typed; + /** + * Return a new ``int80`` type for %%v%%. + */ + static int80(v: BigNumberish): Typed; + /** + * Return a new ``int88`` type for %%v%%. + */ + static int88(v: BigNumberish): Typed; + /** + * Return a new ``int96`` type for %%v%%. + */ + static int96(v: BigNumberish): Typed; + /** + * Return a new ``int104`` type for %%v%%. + */ + static int104(v: BigNumberish): Typed; + /** + * Return a new ``int112`` type for %%v%%. + */ + static int112(v: BigNumberish): Typed; + /** + * Return a new ``int120`` type for %%v%%. + */ + static int120(v: BigNumberish): Typed; + /** + * Return a new ``int128`` type for %%v%%. + */ + static int128(v: BigNumberish): Typed; + /** + * Return a new ``int136`` type for %%v%%. + */ + static int136(v: BigNumberish): Typed; + /** + * Return a new ``int144`` type for %%v%%. + */ + static int144(v: BigNumberish): Typed; + /** + * Return a new ``int52`` type for %%v%%. + */ + static int152(v: BigNumberish): Typed; + /** + * Return a new ``int160`` type for %%v%%. + */ + static int160(v: BigNumberish): Typed; + /** + * Return a new ``int168`` type for %%v%%. + */ + static int168(v: BigNumberish): Typed; + /** + * Return a new ``int176`` type for %%v%%. + */ + static int176(v: BigNumberish): Typed; + /** + * Return a new ``int184`` type for %%v%%. + */ + static int184(v: BigNumberish): Typed; + /** + * Return a new ``int92`` type for %%v%%. + */ + static int192(v: BigNumberish): Typed; + /** + * Return a new ``int200`` type for %%v%%. + */ + static int200(v: BigNumberish): Typed; + /** + * Return a new ``int208`` type for %%v%%. + */ + static int208(v: BigNumberish): Typed; + /** + * Return a new ``int216`` type for %%v%%. + */ + static int216(v: BigNumberish): Typed; + /** + * Return a new ``int224`` type for %%v%%. + */ + static int224(v: BigNumberish): Typed; + /** + * Return a new ``int232`` type for %%v%%. + */ + static int232(v: BigNumberish): Typed; + /** + * Return a new ``int240`` type for %%v%%. + */ + static int240(v: BigNumberish): Typed; + /** + * Return a new ``int248`` type for %%v%%. + */ + static int248(v: BigNumberish): Typed; + /** + * Return a new ``int256`` type for %%v%%. + */ + static int256(v: BigNumberish): Typed; + /** + * Return a new ``int256`` type for %%v%%. + */ + static int(v: BigNumberish): Typed; + /** + * Return a new ``bytes1`` type for %%v%%. + */ + static bytes1(v: BytesLike): Typed; + /** + * Return a new ``bytes2`` type for %%v%%. + */ + static bytes2(v: BytesLike): Typed; + /** + * Return a new ``bytes3`` type for %%v%%. + */ + static bytes3(v: BytesLike): Typed; + /** + * Return a new ``bytes4`` type for %%v%%. + */ + static bytes4(v: BytesLike): Typed; + /** + * Return a new ``bytes5`` type for %%v%%. + */ + static bytes5(v: BytesLike): Typed; + /** + * Return a new ``bytes6`` type for %%v%%. + */ + static bytes6(v: BytesLike): Typed; + /** + * Return a new ``bytes7`` type for %%v%%. + */ + static bytes7(v: BytesLike): Typed; + /** + * Return a new ``bytes8`` type for %%v%%. + */ + static bytes8(v: BytesLike): Typed; + /** + * Return a new ``bytes9`` type for %%v%%. + */ + static bytes9(v: BytesLike): Typed; + /** + * Return a new ``bytes10`` type for %%v%%. + */ + static bytes10(v: BytesLike): Typed; + /** + * Return a new ``bytes11`` type for %%v%%. + */ + static bytes11(v: BytesLike): Typed; + /** + * Return a new ``bytes12`` type for %%v%%. + */ + static bytes12(v: BytesLike): Typed; + /** + * Return a new ``bytes13`` type for %%v%%. + */ + static bytes13(v: BytesLike): Typed; + /** + * Return a new ``bytes14`` type for %%v%%. + */ + static bytes14(v: BytesLike): Typed; + /** + * Return a new ``bytes15`` type for %%v%%. + */ + static bytes15(v: BytesLike): Typed; + /** + * Return a new ``bytes16`` type for %%v%%. + */ + static bytes16(v: BytesLike): Typed; + /** + * Return a new ``bytes17`` type for %%v%%. + */ + static bytes17(v: BytesLike): Typed; + /** + * Return a new ``bytes18`` type for %%v%%. + */ + static bytes18(v: BytesLike): Typed; + /** + * Return a new ``bytes19`` type for %%v%%. + */ + static bytes19(v: BytesLike): Typed; + /** + * Return a new ``bytes20`` type for %%v%%. + */ + static bytes20(v: BytesLike): Typed; + /** + * Return a new ``bytes21`` type for %%v%%. + */ + static bytes21(v: BytesLike): Typed; + /** + * Return a new ``bytes22`` type for %%v%%. + */ + static bytes22(v: BytesLike): Typed; + /** + * Return a new ``bytes23`` type for %%v%%. + */ + static bytes23(v: BytesLike): Typed; + /** + * Return a new ``bytes24`` type for %%v%%. + */ + static bytes24(v: BytesLike): Typed; + /** + * Return a new ``bytes25`` type for %%v%%. + */ + static bytes25(v: BytesLike): Typed; + /** + * Return a new ``bytes26`` type for %%v%%. + */ + static bytes26(v: BytesLike): Typed; + /** + * Return a new ``bytes27`` type for %%v%%. + */ + static bytes27(v: BytesLike): Typed; + /** + * Return a new ``bytes28`` type for %%v%%. + */ + static bytes28(v: BytesLike): Typed; + /** + * Return a new ``bytes29`` type for %%v%%. + */ + static bytes29(v: BytesLike): Typed; + /** + * Return a new ``bytes30`` type for %%v%%. + */ + static bytes30(v: BytesLike): Typed; + /** + * Return a new ``bytes31`` type for %%v%%. + */ + static bytes31(v: BytesLike): Typed; + /** + * Return a new ``bytes32`` type for %%v%%. + */ + static bytes32(v: BytesLike): Typed; + /** + * Return a new ``address`` type for %%v%%. + */ + static address(v: string | Addressable): Typed; + /** + * Return a new ``bool`` type for %%v%%. + */ + static bool(v: any): Typed; + /** + * Return a new ``bytes`` type for %%v%%. + */ + static bytes(v: BytesLike): Typed; + /** + * Return a new ``string`` type for %%v%%. + */ + static string(v: string): Typed; + /** + * Return a new ``array`` type for %%v%%, allowing %%dynamic%% length. + */ + static array(v: Array, dynamic?: null | boolean): Typed; + /** + * Return a new ``tuple`` type for %%v%%, with the optional %%name%%. + */ + static tuple(v: Array | Record, name?: string): Typed; + /** + * Return a new ``uint8`` type for %%v%%. + */ + static overrides(v: Record): Typed; + /** + * Returns true only if %%value%% is a [[Typed]] instance. + */ + static isTyped(value: any): value is Typed; + /** + * If the value is a [[Typed]] instance, validates the underlying value + * and returns it, otherwise returns value directly. + * + * This is useful for functions that with to accept either a [[Typed]] + * object or values. + */ + static dereference(value: Typed | T, type: string): T; +} +//# sourceMappingURL=typed.d.ts.map \ No newline at end of file diff --git a/lib.esm/abi/typed.d.ts.map b/lib.esm/abi/typed.d.ts.map new file mode 100644 index 00000000..d7d2b42a --- /dev/null +++ b/lib.esm/abi/typed.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"typed.d.ts","sourceRoot":"","sources":["../../src.ts/abi/typed.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEjE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAqBzD;;GAEG;AACH,MAAM,WAAW,WAAY,SAAQ,KAAK;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,IAAI,MAAM,CAAC;IACvB,QAAQ,IAAI,MAAM,CAAC;IACnB,QAAQ,IAAI,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,WAAY,SAA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9C;;OAEG;IACH,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,GAAG,GAAG,KAAK;IAE1B;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,GAAG,KAAK;IAEjC;;OAEG;IACH,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,KAAK;IAG/B;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,GAAG,KAAK,CAAC,EAAE,OAAO,CAAC,EAAE,IAAI,GAAG,OAAO,GAAG,KAAK;IAMpE;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,GAAG,KAAK,CAAC,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,KAAK;IAMvF;;OAEG;IACH,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,KAAK;IAI/C;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,KAAK;IAO1C;;;;;;OAMG;IACH,MAAM,CAAC,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,GAAG,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC;CAS3D"} \ No newline at end of file diff --git a/lib.esm/abi/typed.js b/lib.esm/abi/typed.js new file mode 100644 index 00000000..2a53017a --- /dev/null +++ b/lib.esm/abi/typed.js @@ -0,0 +1,602 @@ +/** + * A Typed object allows a value to have its type explicitly + * specified. + * + * For example, in Solidity, the value ``45`` could represent a + * ``uint8`` or a ``uint256``. The value ``0x1234`` could represent + * a ``bytes2`` or ``bytes``. + * + * Since JavaScript has no meaningful way to explicitly inform any + * APIs which what the type is, this allows transparent interoperation + * with Soldity. + * + * @_subsection: api/abi:Typed Values + */ +import { assertPrivate, defineProperties } from "../utils/index.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("_quais_typed"); +/** + * The **Typed** class to wrap values providing explicit type information. + */ +export class Typed { + /** + * The type, as a Solidity-compatible type. + */ + type; + /** + * The actual value. + */ + value; + #options; + /** + * @_ignore: + */ + _typedSymbol; + /** + * @_ignore: + */ + constructor(gaurd, type, value, options) { + if (options == null) { + options = null; + } + assertPrivate(_gaurd, gaurd, "Typed"); + defineProperties(this, { _typedSymbol, type, value }); + this.#options = options; + // Check the value is valid + this.format(); + } + /** + * Format the type as a Human-Readable type. + */ + 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; + } + /** + * The default value returned by this type. + */ + defaultValue() { + return 0; + } + /** + * The minimum value for numeric types. + */ + minValue() { + return 0; + } + /** + * The maximum value for numeric types. + */ + maxValue() { + return 0; + } + /** + * Returns ``true`` and provides a type guard is this is a [[TypedBigInt]]. + */ + isBigInt() { + return !!(this.type.match(/^u?int[0-9]+$/)); + } + /** + * Returns ``true`` and provides a type guard is this is a [[TypedData]]. + */ + isData() { + return this.type.startsWith("bytes"); + } + /** + * Returns ``true`` and provides a type guard is this is a [[TypedString]]. + */ + isString() { + return (this.type === "string"); + } + /** + * Returns the tuple name, if this is a tuple. Throws otherwise. + */ + 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 + /** + * Returns the length of the array type or ``-1`` if it is dynamic. + * + * Throws if the type is not an array. + */ + 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; + } + /** + * Returns a new **Typed** of %%type%% with the %%value%%. + */ + static from(type, value) { + return new Typed(_gaurd, type, value); + } + /** + * Return a new ``uint8`` type for %%v%%. + */ + static uint8(v) { return n(v, 8); } + /** + * Return a new ``uint16`` type for %%v%%. + */ + static uint16(v) { return n(v, 16); } + /** + * Return a new ``uint24`` type for %%v%%. + */ + static uint24(v) { return n(v, 24); } + /** + * Return a new ``uint32`` type for %%v%%. + */ + static uint32(v) { return n(v, 32); } + /** + * Return a new ``uint40`` type for %%v%%. + */ + static uint40(v) { return n(v, 40); } + /** + * Return a new ``uint48`` type for %%v%%. + */ + static uint48(v) { return n(v, 48); } + /** + * Return a new ``uint56`` type for %%v%%. + */ + static uint56(v) { return n(v, 56); } + /** + * Return a new ``uint64`` type for %%v%%. + */ + static uint64(v) { return n(v, 64); } + /** + * Return a new ``uint72`` type for %%v%%. + */ + static uint72(v) { return n(v, 72); } + /** + * Return a new ``uint80`` type for %%v%%. + */ + static uint80(v) { return n(v, 80); } + /** + * Return a new ``uint88`` type for %%v%%. + */ + static uint88(v) { return n(v, 88); } + /** + * Return a new ``uint96`` type for %%v%%. + */ + static uint96(v) { return n(v, 96); } + /** + * Return a new ``uint104`` type for %%v%%. + */ + static uint104(v) { return n(v, 104); } + /** + * Return a new ``uint112`` type for %%v%%. + */ + static uint112(v) { return n(v, 112); } + /** + * Return a new ``uint120`` type for %%v%%. + */ + static uint120(v) { return n(v, 120); } + /** + * Return a new ``uint128`` type for %%v%%. + */ + static uint128(v) { return n(v, 128); } + /** + * Return a new ``uint136`` type for %%v%%. + */ + static uint136(v) { return n(v, 136); } + /** + * Return a new ``uint144`` type for %%v%%. + */ + static uint144(v) { return n(v, 144); } + /** + * Return a new ``uint152`` type for %%v%%. + */ + static uint152(v) { return n(v, 152); } + /** + * Return a new ``uint160`` type for %%v%%. + */ + static uint160(v) { return n(v, 160); } + /** + * Return a new ``uint168`` type for %%v%%. + */ + static uint168(v) { return n(v, 168); } + /** + * Return a new ``uint176`` type for %%v%%. + */ + static uint176(v) { return n(v, 176); } + /** + * Return a new ``uint184`` type for %%v%%. + */ + static uint184(v) { return n(v, 184); } + /** + * Return a new ``uint192`` type for %%v%%. + */ + static uint192(v) { return n(v, 192); } + /** + * Return a new ``uint200`` type for %%v%%. + */ + static uint200(v) { return n(v, 200); } + /** + * Return a new ``uint208`` type for %%v%%. + */ + static uint208(v) { return n(v, 208); } + /** + * Return a new ``uint216`` type for %%v%%. + */ + static uint216(v) { return n(v, 216); } + /** + * Return a new ``uint224`` type for %%v%%. + */ + static uint224(v) { return n(v, 224); } + /** + * Return a new ``uint232`` type for %%v%%. + */ + static uint232(v) { return n(v, 232); } + /** + * Return a new ``uint240`` type for %%v%%. + */ + static uint240(v) { return n(v, 240); } + /** + * Return a new ``uint248`` type for %%v%%. + */ + static uint248(v) { return n(v, 248); } + /** + * Return a new ``uint256`` type for %%v%%. + */ + static uint256(v) { return n(v, 256); } + /** + * Return a new ``uint256`` type for %%v%%. + */ + static uint(v) { return n(v, 256); } + /** + * Return a new ``int8`` type for %%v%%. + */ + static int8(v) { return n(v, -8); } + /** + * Return a new ``int16`` type for %%v%%. + */ + static int16(v) { return n(v, -16); } + /** + * Return a new ``int24`` type for %%v%%. + */ + static int24(v) { return n(v, -24); } + /** + * Return a new ``int32`` type for %%v%%. + */ + static int32(v) { return n(v, -32); } + /** + * Return a new ``int40`` type for %%v%%. + */ + static int40(v) { return n(v, -40); } + /** + * Return a new ``int48`` type for %%v%%. + */ + static int48(v) { return n(v, -48); } + /** + * Return a new ``int56`` type for %%v%%. + */ + static int56(v) { return n(v, -56); } + /** + * Return a new ``int64`` type for %%v%%. + */ + static int64(v) { return n(v, -64); } + /** + * Return a new ``int72`` type for %%v%%. + */ + static int72(v) { return n(v, -72); } + /** + * Return a new ``int80`` type for %%v%%. + */ + static int80(v) { return n(v, -80); } + /** + * Return a new ``int88`` type for %%v%%. + */ + static int88(v) { return n(v, -88); } + /** + * Return a new ``int96`` type for %%v%%. + */ + static int96(v) { return n(v, -96); } + /** + * Return a new ``int104`` type for %%v%%. + */ + static int104(v) { return n(v, -104); } + /** + * Return a new ``int112`` type for %%v%%. + */ + static int112(v) { return n(v, -112); } + /** + * Return a new ``int120`` type for %%v%%. + */ + static int120(v) { return n(v, -120); } + /** + * Return a new ``int128`` type for %%v%%. + */ + static int128(v) { return n(v, -128); } + /** + * Return a new ``int136`` type for %%v%%. + */ + static int136(v) { return n(v, -136); } + /** + * Return a new ``int144`` type for %%v%%. + */ + static int144(v) { return n(v, -144); } + /** + * Return a new ``int52`` type for %%v%%. + */ + static int152(v) { return n(v, -152); } + /** + * Return a new ``int160`` type for %%v%%. + */ + static int160(v) { return n(v, -160); } + /** + * Return a new ``int168`` type for %%v%%. + */ + static int168(v) { return n(v, -168); } + /** + * Return a new ``int176`` type for %%v%%. + */ + static int176(v) { return n(v, -176); } + /** + * Return a new ``int184`` type for %%v%%. + */ + static int184(v) { return n(v, -184); } + /** + * Return a new ``int92`` type for %%v%%. + */ + static int192(v) { return n(v, -192); } + /** + * Return a new ``int200`` type for %%v%%. + */ + static int200(v) { return n(v, -200); } + /** + * Return a new ``int208`` type for %%v%%. + */ + static int208(v) { return n(v, -208); } + /** + * Return a new ``int216`` type for %%v%%. + */ + static int216(v) { return n(v, -216); } + /** + * Return a new ``int224`` type for %%v%%. + */ + static int224(v) { return n(v, -224); } + /** + * Return a new ``int232`` type for %%v%%. + */ + static int232(v) { return n(v, -232); } + /** + * Return a new ``int240`` type for %%v%%. + */ + static int240(v) { return n(v, -240); } + /** + * Return a new ``int248`` type for %%v%%. + */ + static int248(v) { return n(v, -248); } + /** + * Return a new ``int256`` type for %%v%%. + */ + static int256(v) { return n(v, -256); } + /** + * Return a new ``int256`` type for %%v%%. + */ + static int(v) { return n(v, -256); } + /** + * Return a new ``bytes1`` type for %%v%%. + */ + static bytes1(v) { return b(v, 1); } + /** + * Return a new ``bytes2`` type for %%v%%. + */ + static bytes2(v) { return b(v, 2); } + /** + * Return a new ``bytes3`` type for %%v%%. + */ + static bytes3(v) { return b(v, 3); } + /** + * Return a new ``bytes4`` type for %%v%%. + */ + static bytes4(v) { return b(v, 4); } + /** + * Return a new ``bytes5`` type for %%v%%. + */ + static bytes5(v) { return b(v, 5); } + /** + * Return a new ``bytes6`` type for %%v%%. + */ + static bytes6(v) { return b(v, 6); } + /** + * Return a new ``bytes7`` type for %%v%%. + */ + static bytes7(v) { return b(v, 7); } + /** + * Return a new ``bytes8`` type for %%v%%. + */ + static bytes8(v) { return b(v, 8); } + /** + * Return a new ``bytes9`` type for %%v%%. + */ + static bytes9(v) { return b(v, 9); } + /** + * Return a new ``bytes10`` type for %%v%%. + */ + static bytes10(v) { return b(v, 10); } + /** + * Return a new ``bytes11`` type for %%v%%. + */ + static bytes11(v) { return b(v, 11); } + /** + * Return a new ``bytes12`` type for %%v%%. + */ + static bytes12(v) { return b(v, 12); } + /** + * Return a new ``bytes13`` type for %%v%%. + */ + static bytes13(v) { return b(v, 13); } + /** + * Return a new ``bytes14`` type for %%v%%. + */ + static bytes14(v) { return b(v, 14); } + /** + * Return a new ``bytes15`` type for %%v%%. + */ + static bytes15(v) { return b(v, 15); } + /** + * Return a new ``bytes16`` type for %%v%%. + */ + static bytes16(v) { return b(v, 16); } + /** + * Return a new ``bytes17`` type for %%v%%. + */ + static bytes17(v) { return b(v, 17); } + /** + * Return a new ``bytes18`` type for %%v%%. + */ + static bytes18(v) { return b(v, 18); } + /** + * Return a new ``bytes19`` type for %%v%%. + */ + static bytes19(v) { return b(v, 19); } + /** + * Return a new ``bytes20`` type for %%v%%. + */ + static bytes20(v) { return b(v, 20); } + /** + * Return a new ``bytes21`` type for %%v%%. + */ + static bytes21(v) { return b(v, 21); } + /** + * Return a new ``bytes22`` type for %%v%%. + */ + static bytes22(v) { return b(v, 22); } + /** + * Return a new ``bytes23`` type for %%v%%. + */ + static bytes23(v) { return b(v, 23); } + /** + * Return a new ``bytes24`` type for %%v%%. + */ + static bytes24(v) { return b(v, 24); } + /** + * Return a new ``bytes25`` type for %%v%%. + */ + static bytes25(v) { return b(v, 25); } + /** + * Return a new ``bytes26`` type for %%v%%. + */ + static bytes26(v) { return b(v, 26); } + /** + * Return a new ``bytes27`` type for %%v%%. + */ + static bytes27(v) { return b(v, 27); } + /** + * Return a new ``bytes28`` type for %%v%%. + */ + static bytes28(v) { return b(v, 28); } + /** + * Return a new ``bytes29`` type for %%v%%. + */ + static bytes29(v) { return b(v, 29); } + /** + * Return a new ``bytes30`` type for %%v%%. + */ + static bytes30(v) { return b(v, 30); } + /** + * Return a new ``bytes31`` type for %%v%%. + */ + static bytes31(v) { return b(v, 31); } + /** + * Return a new ``bytes32`` type for %%v%%. + */ + static bytes32(v) { return b(v, 32); } + /** + * Return a new ``address`` type for %%v%%. + */ + static address(v) { return new Typed(_gaurd, "address", v); } + /** + * Return a new ``bool`` type for %%v%%. + */ + static bool(v) { return new Typed(_gaurd, "bool", !!v); } + /** + * Return a new ``bytes`` type for %%v%%. + */ + static bytes(v) { return new Typed(_gaurd, "bytes", v); } + /** + * Return a new ``string`` type for %%v%%. + */ + static string(v) { return new Typed(_gaurd, "string", v); } + /** + * Return a new ``array`` type for %%v%%, allowing %%dynamic%% length. + */ + static array(v, dynamic) { + throw new Error("not implemented yet"); + return new Typed(_gaurd, "array", v, dynamic); + } + /** + * Return a new ``tuple`` type for %%v%%, with the optional %%name%%. + */ + static tuple(v, name) { + throw new Error("not implemented yet"); + return new Typed(_gaurd, "tuple", v, name); + } + /** + * Return a new ``uint8`` type for %%v%%. + */ + static overrides(v) { + return new Typed(_gaurd, "overrides", Object.assign({}, v)); + } + /** + * Returns true only if %%value%% is a [[Typed]] instance. + */ + static isTyped(value) { + return (value + && typeof (value) === "object" + && "_typedSymbol" in value + && value._typedSymbol === _typedSymbol); + } + /** + * If the value is a [[Typed]] instance, validates the underlying value + * and returns it, otherwise returns value directly. + * + * This is useful for functions that with to accept either a [[Typed]] + * object or values. + */ + 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; + } +} +//# sourceMappingURL=typed.js.map \ No newline at end of file diff --git a/lib.esm/abi/typed.js.map b/lib.esm/abi/typed.js.map new file mode 100644 index 00000000..04384f2d --- /dev/null +++ b/lib.esm/abi/typed.js.map @@ -0,0 +1 @@ +{"version":3,"file":"typed.js","sourceRoot":"","sources":["../../src.ts/abi/typed.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAOpE,MAAM,MAAM,GAAG,EAAG,CAAC;AAEnB,SAAS,CAAC,CAAC,KAAmB,EAAE,KAAa;IACzC,IAAI,MAAM,GAAG,KAAK,CAAC;IACnB,IAAI,KAAK,GAAG,CAAC,EAAE;QACX,MAAM,GAAG,IAAI,CAAC;QACd,KAAK,IAAI,CAAC,CAAC,CAAC;KACf;IAED,wCAAwC;IACxC,OAAO,IAAI,KAAK,CAAC,MAAM,EAAE,GAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAA,CAAC,CAAC,GAAI,MAAO,KAAM,EAAE,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;AAC7F,CAAC;AAED,SAAS,CAAC,CAAC,KAAgB,EAAE,IAAa;IACtC,wCAAwC;IACxC,OAAO,IAAI,KAAK,CAAC,MAAM,EAAE,QAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA,CAAC,CAAC,EAAG,EAAE,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;AAC7E,CAAC;AAoED,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC,CAA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;QACnC,OAAO,IAAI,KAAK,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,EAAG,EAAE,CAAC,CAAC,CAAC,CAAC;IACjE,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,KAAU;QACrB,OAAO,CAAC,KAAK;eACN,OAAM,CAAC,KAAK,CAAC,KAAK,QAAQ;eAC1B,cAAc,IAAI,KAAK;eACvB,KAAK,CAAC,YAAY,KAAK,YAAY,CAAC,CAAC;IAChD,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,WAAW,CAAI,KAAgB,EAAE,IAAY;QAChD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YACtB,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI,EAAE;gBACrB,MAAM,IAAI,KAAK,CAAC,0BAA2B,IAAK,SAAU,KAAK,CAAC,IAAK,EAAE,CAAC,CAAC;aAC5E;YACD,OAAO,KAAK,CAAC,KAAK,CAAC;SACtB;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ"} \ No newline at end of file diff --git a/lib.esm/address/address.d.ts b/lib.esm/address/address.d.ts new file mode 100644 index 00000000..87efe465 --- /dev/null +++ b/lib.esm/address/address.d.ts @@ -0,0 +1,39 @@ +import { BytesLike, BigNumberish } from "../utils/index.js"; +/** + * Returns a normalized and checksumed address for %%address%%. + * This accepts non-checksum addresses, checksum addresses and + * [[getIcapAddress]] formats. + * + * The checksum in Ethereum uses the capitalization (upper-case + * vs lower-case) of the characters within an address to encode + * its checksum, which offers, on average, a checksum of 15-bits. + * + * If %%address%% contains both upper-case and lower-case, it is + * assumed to already be a checksum address and its checksum is + * validated, and if the address fails its expected checksum an + * error is thrown. + * + * If you wish the checksum of %%address%% to be ignore, it should + * be converted to lower-case (i.e. ``.toLowercase()``) before + * being passed in. This should be a very rare situation though, + * that you wish to bypass the safegaurds in place to protect + * against an address that has been incorrectly copied from another + * source. + * + * @example: + * // Adds the checksum (via upper-casing specific letters) + * getAddress("0x8ba1f109551bd432803012645ac136ddd64dba72") + * //_result: + * + * // Converts ICAP address and adds checksum + * getAddress("XE65GB6LDNXYOFTX0NSV3FUWKOWIXAMJK36"); + * //_result: + * + * // Throws an error if an address contains mixed case, + * // but the checksum fails + * getAddress("0x8Ba1f109551bD432803012645Ac136ddd64DBA72") + * //_error: + */ +export declare function getAddress(address: string): string; +export declare function getContractAddress(from: string, nonce: BigNumberish, data: BytesLike): string; +//# sourceMappingURL=address.d.ts.map \ No newline at end of file diff --git a/lib.esm/address/address.d.ts.map b/lib.esm/address/address.d.ts.map new file mode 100644 index 00000000..1c0aaec1 --- /dev/null +++ b/lib.esm/address/address.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../src.ts/address/address.ts"],"names":[],"mappings":"AACA,OAAO,EAA4B,SAAS,EAAmC,YAAY,EAAqC,MAAM,mBAAmB,CAAC;AA8B1J;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAmBlD;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,GAAG,MAAM,CAG7F"} \ No newline at end of file diff --git a/lib.esm/address/address.js b/lib.esm/address/address.js new file mode 100644 index 00000000..d7c904df --- /dev/null +++ b/lib.esm/address/address.js @@ -0,0 +1,77 @@ +import { keccak256 } from "../crypto/index.js"; +import { getBytes, assertArgument, concat, zeroPadValue, dataSlice, toBigInt, toBeHex, stripZerosLeft } from "../utils/index.js"; +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 = getBytes(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(""); +} +/** + * Returns a normalized and checksumed address for %%address%%. + * This accepts non-checksum addresses, checksum addresses and + * [[getIcapAddress]] formats. + * + * The checksum in Ethereum uses the capitalization (upper-case + * vs lower-case) of the characters within an address to encode + * its checksum, which offers, on average, a checksum of 15-bits. + * + * If %%address%% contains both upper-case and lower-case, it is + * assumed to already be a checksum address and its checksum is + * validated, and if the address fails its expected checksum an + * error is thrown. + * + * If you wish the checksum of %%address%% to be ignore, it should + * be converted to lower-case (i.e. ``.toLowercase()``) before + * being passed in. This should be a very rare situation though, + * that you wish to bypass the safegaurds in place to protect + * against an address that has been incorrectly copied from another + * source. + * + * @example: + * // Adds the checksum (via upper-casing specific letters) + * getAddress("0x8ba1f109551bd432803012645ac136ddd64dba72") + * //_result: + * + * // Converts ICAP address and adds checksum + * getAddress("XE65GB6LDNXYOFTX0NSV3FUWKOWIXAMJK36"); + * //_result: + * + * // Throws an error if an address contains mixed case, + * // but the checksum fails + * getAddress("0x8Ba1f109551bD432803012645Ac136ddd64DBA72") + * //_error: + */ +export function getAddress(address) { + assertArgument(typeof (address) === "string", "invalid address", "address", address); + if (address.match(/^(0x)?[0-9a-fA-F]{40}$/)) { + // Missing the 0x prefix + if (!address.startsWith("0x")) { + address = "0x" + address; + } + const result = getChecksumAddress(address); + // It is a checksummed address with a bad checksum + assertArgument(!address.match(/([A-F].*[a-f])|([a-f].*[A-F])/) || result === address, "bad address checksum", "address", address); + return result; + } + assertArgument(false, "invalid address", "address", address); +} +export function getContractAddress(from, nonce, data) { + const nonceBytes = zeroPadValue(toBeHex(toBigInt(nonce)), 8); + return getAddress(dataSlice(keccak256(concat([getAddress(from), nonceBytes, stripZerosLeft(data)])), 12)); +} +//# sourceMappingURL=address.js.map \ No newline at end of file diff --git a/lib.esm/address/address.js.map b/lib.esm/address/address.js.map new file mode 100644 index 00000000..e9342db0 --- /dev/null +++ b/lib.esm/address/address.js.map @@ -0,0 +1 @@ +{"version":3,"file":"address.js","sourceRoot":"","sources":["../../src.ts/address/address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAa,MAAM,EAAE,YAAY,EAAE,SAAS,EAAgB,QAAQ,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAE1J,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,QAAQ,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;IAE7C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE;QAC5B,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE;YAC5B,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;SACrC;QACD,IAAI,CAAC,MAAM,CAAC,C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AAE,cAAc,CAAC,IAAI,CAAC,CAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;AAC9G,CAAC"} \ No newline at end of file diff --git a/lib.esm/address/checks.d.ts b/lib.esm/address/checks.d.ts new file mode 100644 index 00000000..cf18c0e3 --- /dev/null +++ b/lib.esm/address/checks.d.ts @@ -0,0 +1,81 @@ +import type { Addressable, AddressLike } from "./index.js"; +/** + * Returns true if %%value%% is an object which implements the + * [[Addressable]] interface. + * + * @example: + * // Wallets and AbstractSigner sub-classes + * isAddressable(Wallet.createRandom()) + * //_result: + * + * // Contracts + * contract = new Contract("dai.tokens.quais.eth", [ ], provider) + * isAddressable(contract) + * //_result: + */ +export declare function isAddressable(value: any): value is Addressable; +/** + * Returns true if %%value%% is a valid address. + * + * @example: + * // Valid address + * isAddress("0x8ba1f109551bD432803012645Ac136ddd64DBA72") + * //_result: + * + * // Valid ICAP address + * isAddress("XE65GB6LDNXYOFTX0NSV3FUWKOWIXAMJK36") + * //_result: + * + * // Invalid checksum + * isAddress("0x8Ba1f109551bD432803012645Ac136ddd64DBa72") + * //_result: + * + * // Invalid ICAP checksum + * isAddress("0x8Ba1f109551bD432803012645Ac136ddd64DBA72") + * //_result: + * + * // Not an address (an ENS name requires a provided and an + * // asynchronous API to access) + * isAddress("ricmoo.eth") + * //_result: + */ +export declare function isAddress(value: any): value is string; +/** + * Resolves to an address for the %%target%%, which may be any + * supported address type, an [[Addressable]] or a Promise which + * resolves to an address. + * + * If an ENS name is provided, but that name has not been correctly + * configured a [[UnconfiguredNameError]] is thrown. + * + * @example: + * addr = "0x6B175474E89094C44Da98b954EedeAC495271d0F" + * + * // Addresses are return synchronously + * resolveAddress(addr, provider) + * //_result: + * + * // Address promises are resolved asynchronously + * resolveAddress(Promise.resolve(addr)) + * //_result: + * + * // ENS names are resolved asynchronously + * resolveAddress("dai.tokens.quais.eth", provider) + * //_result: + * + * // Addressable objects are resolved asynchronously + * contract = new Contract(addr, [ ]) + * resolveAddress(contract, provider) + * //_result: + * + * // Unconfigured ENS names reject + * resolveAddress("nothing-here.ricmoo.eth", provider) + * //_error: + * + * // ENS names require a NameResolver object passed in + * // (notice the provider was omitted) + * resolveAddress("nothing-here.ricmoo.eth") + * //_error: + */ +export declare function resolveAddress(target: AddressLike): string | Promise; +//# sourceMappingURL=checks.d.ts.map \ No newline at end of file diff --git a/lib.esm/address/checks.d.ts.map b/lib.esm/address/checks.d.ts.map new file mode 100644 index 00000000..71acded0 --- /dev/null +++ b/lib.esm/address/checks.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"checks.d.ts","sourceRoot":"","sources":["../../src.ts/address/checks.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAG3D;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,WAAW,CAE9D;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,MAAM,CAMrD;AAUD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAa5E"} \ No newline at end of file diff --git a/lib.esm/address/checks.js b/lib.esm/address/checks.js new file mode 100644 index 00000000..f272bd08 --- /dev/null +++ b/lib.esm/address/checks.js @@ -0,0 +1,111 @@ +import { assertArgument } from "../utils/index.js"; +import { getAddress } from "./address.js"; +/** + * Returns true if %%value%% is an object which implements the + * [[Addressable]] interface. + * + * @example: + * // Wallets and AbstractSigner sub-classes + * isAddressable(Wallet.createRandom()) + * //_result: + * + * // Contracts + * contract = new Contract("dai.tokens.quais.eth", [ ], provider) + * isAddressable(contract) + * //_result: + */ +export function isAddressable(value) { + return (value && typeof (value.getAddress) === "function"); +} +/** + * Returns true if %%value%% is a valid address. + * + * @example: + * // Valid address + * isAddress("0x8ba1f109551bD432803012645Ac136ddd64DBA72") + * //_result: + * + * // Valid ICAP address + * isAddress("XE65GB6LDNXYOFTX0NSV3FUWKOWIXAMJK36") + * //_result: + * + * // Invalid checksum + * isAddress("0x8Ba1f109551bD432803012645Ac136ddd64DBa72") + * //_result: + * + * // Invalid ICAP checksum + * isAddress("0x8Ba1f109551bD432803012645Ac136ddd64DBA72") + * //_result: + * + * // Not an address (an ENS name requires a provided and an + * // asynchronous API to access) + * isAddress("ricmoo.eth") + * //_result: + */ +export function isAddress(value) { + try { + getAddress(value); + return true; + } + catch (error) { } + return false; +} +async function checkAddress(target, promise) { + const result = await promise; + if (result == null || result === "0x0000000000000000000000000000000000000000") { + assertArgument(false, "invalid AddressLike value; did not resolve to a value address", "target", target); + } + return getAddress(result); +} +/** + * Resolves to an address for the %%target%%, which may be any + * supported address type, an [[Addressable]] or a Promise which + * resolves to an address. + * + * If an ENS name is provided, but that name has not been correctly + * configured a [[UnconfiguredNameError]] is thrown. + * + * @example: + * addr = "0x6B175474E89094C44Da98b954EedeAC495271d0F" + * + * // Addresses are return synchronously + * resolveAddress(addr, provider) + * //_result: + * + * // Address promises are resolved asynchronously + * resolveAddress(Promise.resolve(addr)) + * //_result: + * + * // ENS names are resolved asynchronously + * resolveAddress("dai.tokens.quais.eth", provider) + * //_result: + * + * // Addressable objects are resolved asynchronously + * contract = new Contract(addr, [ ]) + * resolveAddress(contract, provider) + * //_result: + * + * // Unconfigured ENS names reject + * resolveAddress("nothing-here.ricmoo.eth", provider) + * //_error: + * + * // ENS names require a NameResolver object passed in + * // (notice the provider was omitted) + * resolveAddress("nothing-here.ricmoo.eth") + * //_error: + */ +export function resolveAddress(target) { + if (typeof (target) === "string") { + if (target.match(/^0x[0-9a-f]{40}$/i)) { + return getAddress(target); + } + } + else if (isAddressable(target)) { + return checkAddress(target, target.getAddress()); + } + else if (target && typeof (target.then) === "function") { + return checkAddress(target, target); + } + assertArgument(false, "unsupported addressable value", "target", target); +} +//# sourceMappingURL=checks.js.map \ No newline at end of file diff --git a/lib.esm/address/checks.js.map b/lib.esm/address/checks.js.map new file mode 100644 index 00000000..fcc87da3 --- /dev/null +++ b/lib.esm/address/checks.js.map @@ -0,0 +1 @@ +{"version":3,"file":"checks.js","sourceRoot":"","sources":["../../src.ts/address/checks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAK1C;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,aAAa,CAAC,KAAU;IACpC,OAAO,CAAC,KAAK,IAAI,OAAM,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,UAAU,CAAC,CAAC;AAC9D,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,SAAS,CAAC,KAAU;IAChC,IAAI;QACA,UAAU,CAAC,KAAK,CAAC,CAAC;QAClB,OAAO,IAAI,CAAC;KACf;IAAC,OAAO,KAAK,EAAE,GAAG;IACnB,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,KAAK,UAAU,YAAY,CAAC,MAAW,EAAE,OAA+B;IACpE,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC;IAC7B,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM,KAAK,4CAA4C,EAAE;QAC3E,cAAc,CAAC,KAAK,EAAE,+DAA+D,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;KAC5G;IACD,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC;AAC9B,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAM,UAAU,cAAc,CAAC,MAAmB;IAE9C,IAAI,OAAM,CAAC,MAAM,CAAC,KAAK,QAAQ,EAAE;QAC7B,IAAI,MAAM,CAAC,KAAK,CAAC,mBAAmB,CAAC,EAAE;YAAE,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC;SAAE;KAExE;SAAM,IAAI,aAAa,CAAC,MAAM,CAAC,EAAE;QAC9B,OAAO,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;KAEpD;SAAM,IAAI,MAAM,IAAI,OAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,UAAU,EAAE;QACrD,OAAO,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KACvC;IAED,cAAc,CAAC,KAAK,EAAE,+BAA+B,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;AAC7E,CAAC"} \ No newline at end of file diff --git a/lib.esm/address/contract-address.d.ts b/lib.esm/address/contract-address.d.ts new file mode 100644 index 00000000..42b36f7f --- /dev/null +++ b/lib.esm/address/contract-address.d.ts @@ -0,0 +1,48 @@ +import type { BigNumberish, BytesLike } from "../utils/index.js"; +/** + * Returns the address that would result from a ``CREATE`` for %%tx%%. + * + * This can be used to compute the address a contract will be + * deployed to by an EOA when sending a deployment transaction (i.e. + * when the ``to`` address is ``null``). + * + * This can also be used to compute the address a contract will be + * deployed to by a contract, by using the contract's address as the + * ``to`` and the contract's nonce. + * + * @example + * from = "0x8ba1f109551bD432803012645Ac136ddd64DBA72"; + * nonce = 5; + * + * getCreateAddress({ from, nonce }); + * //_result: + */ +export declare function getCreateAddress(tx: { + from: string; + nonce: BigNumberish; +}): string; +/** + * Returns the address that would result from a ``CREATE2`` operation + * with the given %%from%%, %%salt%% and %%initCodeHash%%. + * + * To compute the %%initCodeHash%% from a contract's init code, use + * the [[keccak256]] function. + * + * For a quick overview and example of ``CREATE2``, see [[link-ricmoo-wisps]]. + * + * @example + * // The address of the contract + * from = "0x8ba1f109551bD432803012645Ac136ddd64DBA72" + * + * // The salt + * salt = id("HelloWorld") + * + * // The hash of the initCode + * initCode = "0x6394198df16000526103ff60206004601c335afa6040516060f3"; + * initCodeHash = keccak256(initCode) + * + * getCreate2Address(from, salt, initCodeHash) + * //_result: + */ +export declare function getCreate2Address(_from: string, _salt: BytesLike, _initCodeHash: BytesLike): string; +//# sourceMappingURL=contract-address.d.ts.map \ No newline at end of file diff --git a/lib.esm/address/contract-address.d.ts.map b/lib.esm/address/contract-address.d.ts.map new file mode 100644 index 00000000..624f8426 --- /dev/null +++ b/lib.esm/address/contract-address.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"contract-address.d.ts","sourceRoot":"","sources":["../../src.ts/address/contract-address.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAKjE;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,YAAY,CAAA;CAAE,GAAG,MAAM,CAclF;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,SAAS,GAAG,MAAM,CAUnG"} \ No newline at end of file diff --git a/lib.esm/address/contract-address.js b/lib.esm/address/contract-address.js new file mode 100644 index 00000000..a8cd679f --- /dev/null +++ b/lib.esm/address/contract-address.js @@ -0,0 +1,69 @@ +import { keccak256 } from "../crypto/index.js"; +import { concat, dataSlice, getBigInt, getBytes, assertArgument, encodeProto } from "../utils/index.js"; +import { getAddress } from "./address.js"; +// http://ethereum.stackexchange.com/questions/760/how-is-the-address-of-an-ethereum-contract-computed +/** + * Returns the address that would result from a ``CREATE`` for %%tx%%. + * + * This can be used to compute the address a contract will be + * deployed to by an EOA when sending a deployment transaction (i.e. + * when the ``to`` address is ``null``). + * + * This can also be used to compute the address a contract will be + * deployed to by a contract, by using the contract's address as the + * ``to`` and the contract's nonce. + * + * @example + * from = "0x8ba1f109551bD432803012645Ac136ddd64DBA72"; + * nonce = 5; + * + * getCreateAddress({ from, nonce }); + * //_result: + */ +export function getCreateAddress(tx) { + const from = getAddress(tx.from); + const nonce = 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 getAddress(dataSlice(keccak256(encodeProto([from, nonceHex])), 12)); +} +/** + * Returns the address that would result from a ``CREATE2`` operation + * with the given %%from%%, %%salt%% and %%initCodeHash%%. + * + * To compute the %%initCodeHash%% from a contract's init code, use + * the [[keccak256]] function. + * + * For a quick overview and example of ``CREATE2``, see [[link-ricmoo-wisps]]. + * + * @example + * // The address of the contract + * from = "0x8ba1f109551bD432803012645Ac136ddd64DBA72" + * + * // The salt + * salt = id("HelloWorld") + * + * // The hash of the initCode + * initCode = "0x6394198df16000526103ff60206004601c335afa6040516060f3"; + * initCodeHash = keccak256(initCode) + * + * getCreate2Address(from, salt, initCodeHash) + * //_result: + */ +export function getCreate2Address(_from, _salt, _initCodeHash) { + const from = getAddress(_from); + const salt = getBytes(_salt, "salt"); + const initCodeHash = getBytes(_initCodeHash, "initCodeHash"); + assertArgument(salt.length === 32, "salt must be 32 bytes", "salt", _salt); + assertArgument(initCodeHash.length === 32, "initCodeHash must be 32 bytes", "initCodeHash", _initCodeHash); + return getAddress(dataSlice(keccak256(concat(["0xff", from, salt, initCodeHash])), 12)); +} +//# sourceMappingURL=contract-address.js.map \ No newline at end of file diff --git a/lib.esm/address/contract-address.js.map b/lib.esm/address/contract-address.js.map new file mode 100644 index 00000000..8a17e864 --- /dev/null +++ b/lib.esm/address/contract-address.js.map @@ -0,0 +1 @@ +{"version":3,"file":"contract-address.js","sourceRoot":"","sources":["../../src.ts/address/contract-address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EACH,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,Q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+BAA+B,EAAE,cAAc,EAAE,aAAa,CAAC,CAAC;IAE3G,OAAO,UAAU,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,CAAC,CAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,YAAY,CAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;AAC7F,CAAC"} \ No newline at end of file diff --git a/lib.esm/address/index.d.ts b/lib.esm/address/index.d.ts new file mode 100644 index 00000000..5f90df4f --- /dev/null +++ b/lib.esm/address/index.d.ts @@ -0,0 +1,36 @@ +/** + * Addresses are a fundamental part of interacting with Ethereum. They + * represent the gloabal identity of Externally Owned Accounts (accounts + * backed by a private key) and contracts. + * + * The Ethereum Naming Service (ENS) provides an interconnected ecosystem + * of contracts, standards and libraries which enable looking up an + * address for an ENS name. + * + * These functions help convert between various formats, validate + * addresses and safely resolve ENS names. + * + * @_section: api/address:Addresses [about-addresses] + */ +/** + * An interface for objects which have an address, and can + * resolve it asyncronously. + * + * This allows objects such as [[Signer]] or [[Contract]] to + * be used most places an address can be, for example getting + * the [balance](Provider-getBalance). + */ +export interface Addressable { + /** + * Get the object address. + */ + getAddress(): Promise; +} +/** + * Anything that can be used to return or resolve an address. + */ +export type AddressLike = string | Promise | Addressable; +export { getAddress } from "./address.js"; +export { getCreateAddress, getCreate2Address } from "./contract-address.js"; +export { isAddressable, isAddress, resolveAddress } from "./checks.js"; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/lib.esm/address/index.d.ts.map b/lib.esm/address/index.d.ts.map new file mode 100644 index 00000000..39267153 --- /dev/null +++ b/lib.esm/address/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src.ts/address/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH;;;;;;;GAOG;AACH,MAAM,WAAW,WAAW;IACxB;;OAEG;IACH,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CACjC;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,WAAW,CAAC;AAEjE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAG5E,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC"} \ No newline at end of file diff --git a/lib.esm/address/index.js b/lib.esm/address/index.js new file mode 100644 index 00000000..82db321a --- /dev/null +++ b/lib.esm/address/index.js @@ -0,0 +1,19 @@ +/** + * Addresses are a fundamental part of interacting with Ethereum. They + * represent the gloabal identity of Externally Owned Accounts (accounts + * backed by a private key) and contracts. + * + * The Ethereum Naming Service (ENS) provides an interconnected ecosystem + * of contracts, standards and libraries which enable looking up an + * address for an ENS name. + * + * These functions help convert between various formats, validate + * addresses and safely resolve ENS names. + * + * @_section: api/address:Addresses [about-addresses] + */ +null; +export { getAddress } from "./address.js"; +export { getCreateAddress, getCreate2Address } from "./contract-address.js"; +export { isAddressable, isAddress, resolveAddress } from "./checks.js"; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib.esm/address/index.js.map b/lib.esm/address/index.js.map new file mode 100644 index 00000000..e32236c2 --- /dev/null +++ b/lib.esm/address/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src.ts/address/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,IAAI,CAAC;AAsBL,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAG5E,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC"} \ No newline at end of file diff --git a/lib.esm/constants/addresses.d.ts b/lib.esm/constants/addresses.d.ts new file mode 100644 index 00000000..a32d6be0 --- /dev/null +++ b/lib.esm/constants/addresses.d.ts @@ -0,0 +1,7 @@ +/** + * A constant for the zero address. + * + * (**i.e.** ``"0x0000000000000000000000000000000000000000"``) + */ +export declare const ZeroAddress: string; +//# sourceMappingURL=addresses.d.ts.map \ No newline at end of file diff --git a/lib.esm/constants/addresses.d.ts.map b/lib.esm/constants/addresses.d.ts.map new file mode 100644 index 00000000..35a5c221 --- /dev/null +++ b/lib.esm/constants/addresses.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"addresses.d.ts","sourceRoot":"","sources":["../../src.ts/constants/addresses.ts"],"names":[],"mappings":"AACA;;;;GAIG;AACH,eAAO,MAAM,WAAW,EAAE,MAAqD,CAAC"} \ No newline at end of file diff --git a/lib.esm/constants/addresses.js b/lib.esm/constants/addresses.js new file mode 100644 index 00000000..45345cb6 --- /dev/null +++ b/lib.esm/constants/addresses.js @@ -0,0 +1,7 @@ +/** + * A constant for the zero address. + * + * (**i.e.** ``"0x0000000000000000000000000000000000000000"``) + */ +export const ZeroAddress = "0x0000000000000000000000000000000000000000"; +//# sourceMappingURL=addresses.js.map \ No newline at end of file diff --git a/lib.esm/constants/addresses.js.map b/lib.esm/constants/addresses.js.map new file mode 100644 index 00000000..9fb48ce8 --- /dev/null +++ b/lib.esm/constants/addresses.js.map @@ -0,0 +1 @@ +{"version":3,"file":"addresses.js","sourceRoot":"","sources":["../../src.ts/constants/addresses.ts"],"names":[],"mappings":"AACA;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAW,4CAA4C,CAAC"} \ No newline at end of file diff --git a/lib.esm/constants/hashes.d.ts b/lib.esm/constants/hashes.d.ts new file mode 100644 index 00000000..784df715 --- /dev/null +++ b/lib.esm/constants/hashes.d.ts @@ -0,0 +1,7 @@ +/** + * A constant for the zero hash. + * + * (**i.e.** ``"0x0000000000000000000000000000000000000000000000000000000000000000"``) + */ +export declare const ZeroHash: string; +//# sourceMappingURL=hashes.d.ts.map \ No newline at end of file diff --git a/lib.esm/constants/hashes.d.ts.map b/lib.esm/constants/hashes.d.ts.map new file mode 100644 index 00000000..23f5213c --- /dev/null +++ b/lib.esm/constants/hashes.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"hashes.d.ts","sourceRoot":"","sources":["../../src.ts/constants/hashes.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,QAAQ,EAAE,MAA6E,CAAC"} \ No newline at end of file diff --git a/lib.esm/constants/hashes.js b/lib.esm/constants/hashes.js new file mode 100644 index 00000000..95bca98a --- /dev/null +++ b/lib.esm/constants/hashes.js @@ -0,0 +1,7 @@ +/** + * A constant for the zero hash. + * + * (**i.e.** ``"0x0000000000000000000000000000000000000000000000000000000000000000"``) + */ +export const ZeroHash = "0x0000000000000000000000000000000000000000000000000000000000000000"; +//# sourceMappingURL=hashes.js.map \ No newline at end of file diff --git a/lib.esm/constants/hashes.js.map b/lib.esm/constants/hashes.js.map new file mode 100644 index 00000000..b198ca1b --- /dev/null +++ b/lib.esm/constants/hashes.js.map @@ -0,0 +1 @@ +{"version":3,"file":"hashes.js","sourceRoot":"","sources":["../../src.ts/constants/hashes.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAW,oEAAoE,CAAC"} \ No newline at end of file diff --git a/lib.esm/constants/index.d.ts b/lib.esm/constants/index.d.ts new file mode 100644 index 00000000..13668c61 --- /dev/null +++ b/lib.esm/constants/index.d.ts @@ -0,0 +1,11 @@ +/** + * Some common constants useful for Ethereum. + * + * @_section: api/constants: Constants [about-constants] + */ +export { ZeroAddress } from "./addresses.js"; +export { ZeroHash } from "./hashes.js"; +export { N, WeiPerEther, MaxUint256, MinInt256, MaxInt256 } from "./numbers.js"; +export { quaisymbol, MessagePrefix } from "./strings.js"; +export { ShardData } from "./shards.js"; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/lib.esm/constants/index.d.ts.map b/lib.esm/constants/index.d.ts.map new file mode 100644 index 00000000..799432a6 --- /dev/null +++ b/lib.esm/constants/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src.ts/constants/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EACH,CAAC,EACD,WAAW,EACX,UAAU,EACV,SAAS,EACT,SAAS,EACZ,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"} \ No newline at end of file diff --git a/lib.esm/constants/index.js b/lib.esm/constants/index.js new file mode 100644 index 00000000..c1977869 --- /dev/null +++ b/lib.esm/constants/index.js @@ -0,0 +1,11 @@ +/** + * Some common constants useful for Ethereum. + * + * @_section: api/constants: Constants [about-constants] + */ +export { ZeroAddress } from "./addresses.js"; +export { ZeroHash } from "./hashes.js"; +export { N, WeiPerEther, MaxUint256, MinInt256, MaxInt256 } from "./numbers.js"; +export { quaisymbol, MessagePrefix } from "./strings.js"; +export { ShardData } from "./shards.js"; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib.esm/constants/index.js.map b/lib.esm/constants/index.js.map new file mode 100644 index 00000000..303e90da --- /dev/null +++ b/lib.esm/constants/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src.ts/constants/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EACH,CAAC,EACD,WAAW,EACX,UAAU,EACV,SAAS,EACT,SAAS,EACZ,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"} \ No newline at end of file diff --git a/lib.esm/constants/numbers.d.ts b/lib.esm/constants/numbers.d.ts new file mode 100644 index 00000000..7c84eaa6 --- /dev/null +++ b/lib.esm/constants/numbers.d.ts @@ -0,0 +1,31 @@ +/** + * A constant for the order N for the secp256k1 curve. + * + * (**i.e.** ``0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n``) + */ +export declare const N: bigint; +/** + * A constant for the number of wei in a single ether. + * + * (**i.e.** ``1000000000000000000n``) + */ +export declare const WeiPerEther: bigint; +/** + * A constant for the maximum value for a ``uint256``. + * + * (**i.e.** ``0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn``) + */ +export declare const MaxUint256: bigint; +/** + * A constant for the minimum value for an ``int256``. + * + * (**i.e.** ``-8000000000000000000000000000000000000000000000000000000000000000n``) + */ +export declare const MinInt256: bigint; +/** + * A constant for the maximum value for an ``int256``. + * + * (**i.e.** ``0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn``) + */ +export declare const MaxInt256: bigint; +//# sourceMappingURL=numbers.d.ts.map \ No newline at end of file diff --git a/lib.esm/constants/numbers.d.ts.map b/lib.esm/constants/numbers.d.ts.map new file mode 100644 index 00000000..6391e1fd --- /dev/null +++ b/lib.esm/constants/numbers.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"numbers.d.ts","sourceRoot":"","sources":["../../src.ts/constants/numbers.ts"],"names":[],"mappings":"AACA;;;;GAIG;AACH,eAAO,MAAM,CAAC,EAAE,MAAqF,CAAC;AAEtG;;;;GAIG;AACH,eAAO,MAAM,WAAW,EAAE,MAAsC,CAAC;AAEjE;;;;GAIG;AACH,eAAO,MAAM,UAAU,EAAE,MAAqF,CAAC;AAE/G;;;;GAIG;AACH,eAAO,MAAM,SAAS,EAAE,MAAkG,CAAC;AAE3H;;;;GAIG;AACH,eAAO,MAAM,SAAS,EAAE,MAAqF,CAAC"} \ No newline at end of file diff --git a/lib.esm/constants/numbers.js b/lib.esm/constants/numbers.js new file mode 100644 index 00000000..753e9fb9 --- /dev/null +++ b/lib.esm/constants/numbers.js @@ -0,0 +1,31 @@ +/** + * A constant for the order N for the secp256k1 curve. + * + * (**i.e.** ``0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n``) + */ +export const N = BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"); +/** + * A constant for the number of wei in a single ether. + * + * (**i.e.** ``1000000000000000000n``) + */ +export const WeiPerEther = BigInt("1000000000000000000"); +/** + * A constant for the maximum value for a ``uint256``. + * + * (**i.e.** ``0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn``) + */ +export const MaxUint256 = BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); +/** + * A constant for the minimum value for an ``int256``. + * + * (**i.e.** ``-8000000000000000000000000000000000000000000000000000000000000000n``) + */ +export const MinInt256 = BigInt("0x8000000000000000000000000000000000000000000000000000000000000000") * BigInt(-1); +/** + * A constant for the maximum value for an ``int256``. + * + * (**i.e.** ``0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn``) + */ +export const MaxInt256 = BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); +//# sourceMappingURL=numbers.js.map \ No newline at end of file diff --git a/lib.esm/constants/numbers.js.map b/lib.esm/constants/numbers.js.map new file mode 100644 index 00000000..8e868180 --- /dev/null +++ b/lib.esm/constants/numbers.js.map @@ -0,0 +1 @@ +{"version":3,"file":"numbers.js","sourceRoot":"","sources":["../../src.ts/constants/numbers.ts"],"names":[],"mappings":"AACA;;;;GAIG;AACH,MAAM,CAAC,MAAM,CAAC,GAAW,MAAM,CAAC,oEAAoE,CAAC,CAAC;AAEtG;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAW,MAAM,CAAC,qBAAqB,CAAC,CAAC;AAEjE;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAW,MAAM,CAAC,oEAAoE,CAAC,CAAC;AAE/G;;;;GAIG;AACH,MAAM,CAAC,MAAM,SAAS,GAAW,MAAM,CAAC,oEAAoE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAE3H;;;;GAIG;AACH,MAAM,CAAC,MAAM,SAAS,GAAW,MAAM,CAAC,oEAAoE,CAAC,CAAC"} \ No newline at end of file diff --git a/lib.esm/constants/shards.d.ts b/lib.esm/constants/shards.d.ts new file mode 100644 index 00000000..f23153aa --- /dev/null +++ b/lib.esm/constants/shards.d.ts @@ -0,0 +1,8 @@ +export declare const ShardData: { + name: string; + nickname: string; + shard: string; + context: number; + byte: string; +}[]; +//# sourceMappingURL=shards.d.ts.map \ No newline at end of file diff --git a/lib.esm/constants/shards.d.ts.map b/lib.esm/constants/shards.d.ts.map new file mode 100644 index 00000000..09ab3283 --- /dev/null +++ b/lib.esm/constants/shards.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"shards.d.ts","sourceRoot":"","sources":["../../src.ts/constants/shards.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS;;;;;;GAuErB,CAAC"} \ No newline at end of file diff --git a/lib.esm/constants/shards.js b/lib.esm/constants/shards.js new file mode 100644 index 00000000..3fca26af --- /dev/null +++ b/lib.esm/constants/shards.js @@ -0,0 +1,73 @@ +export const ShardData = [ + { + name: "Cyprus One", + nickname: 'cyprus1', + shard: "zone-0-0", + context: 2, + byte: "0x00" //0000 0000 region-0 zone-0 + }, + { + name: "Cyprus Two", + nickname: 'cyprus2', + shard: "zone-0-1", + context: 2, + byte: "0x01" // 0000 0001 region-0 zone-1 + }, + { + name: "Cyprus Three", + nickname: 'cyprus3', + shard: "zone-0-2", + context: 2, + byte: "0x02" // 0000 0010 region-0 zone-2 + }, + { + name: "Paxos One", + nickname: 'paxos1', + shard: "zone-1-0", + context: 2, + byte: "0x10" // 0001 0000 region-1 zone-0 + }, + { + name: "Paxos Two", + nickname: 'paxos2', + shard: "zone-1-1", + context: 2, + byte: "0x11" // 0001 0001 region-1 zone-1 + }, + { + name: "Paxos Three", + nickname: 'paxos3', + shard: "zone-1-2", + context: 2, + byte: "0x12" // 0001 0010 region-1 zone-2 + }, + { + name: "Hydra One", + nickname: 'hydra1', + shard: "zone-2-0", + context: 2, + byte: "0x20" // 0010 0000 region-2 zone-0 + }, + { + name: "Hydra Two", + nickname: 'hydra2', + shard: "zone-2-1", + context: 2, + byte: "0x21" // 0010 0001 region-2 zone-1 + }, + { + name: "Hydra Three", + nickname: 'hydra3', + shard: "zone-2-2", + context: 2, + byte: "0x22" // 0010 0010 region-2 zone-2 + }, + { + name: "Prime", + nickname: 'prime', + shard: "prime", + context: 2, + byte: "0x" + } +]; +//# sourceMappingURL=shards.js.map \ No newline at end of file diff --git a/lib.esm/constants/shards.js.map b/lib.esm/constants/shards.js.map new file mode 100644 index 00000000..941d338e --- /dev/null +++ b/lib.esm/constants/shards.js.map @@ -0,0 +1 @@ +{"version":3,"file":"shards.js","sourceRoot":"","sources":["../../src.ts/constants/shards.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB;QACI,IAAI,EAAE,YAAY;QAClB,QAAQ,EAAE,SAAS;QACnB,KAAK,EAAE,UAAU;QACjB,OAAO,EAAE,CAAC;QACV,IAAI,EAAE,MAAM,CAAC,2BAA2B;KAC3C;IACD;QACI,IAAI,EAAE,YAAY;QAClB,QAAQ,EAAE,SAAS;QACnB,KAAK,EAAE,UAAU;QACjB,OAAO,EAAE,CAAC;QACV,IAAI,EAAE,MAAM,CAAC,4BAA4B;KAC5C;IACD;QACI,IAAI,EAAE,cAAc;QACpB,QAAQ,EAAE,SAAS;QACnB,KAAK,EAAE,UAAU;QACjB,OAAO,EAAE,CAAC;QACV,IAAI,EAAE,MAAM,CAAC,4BAA4B;KAC5C;IACD;QACI,IAAI,EAAE,WAAW;QACjB,QAAQ,EAAE,QAAQ;QAClB,KAAK,EAAE,UAAU;QACjB,OAAO,EAAE,CAAC;QACV,IAAI,EAAE,MAAM,CAAC,4BAA4B;KAC5C;IACD;QACI,IAAI,EAAE,WAAW;QACjB,QAAQ,EAAE,QAAQ;QAClB,KAAK,EAAE,UAAU;QACjB,OAAO,EAAE,CAAC;QACV,IAAI,EAAE,MAAM,CAAC,4BAA4B;KAC5C;IACD;QACI,IAAI,EAAE,aAAa;QACnB,QAAQ,EAAE,QAAQ;QAClB,KAAK,EAAE,UAAU;QACjB,OAAO,EAAE,CAAC;QACV,IAAI,EAAE,MAAM,CAAC,4BAA4B;KAC5C;IACD;QACI,IAAI,EAAE,WAAW;QACjB,QAAQ,EAAE,QAAQ;QAClB,KAAK,EAAE,UAAU;QACjB,OAAO,EAAE,CAAC;QACV,IAAI,EAAE,MAAM,CAAC,4BAA4B;KAC5C;IACD;QACI,IAAI,EAAE,WAAW;QACjB,QAAQ,EAAE,QAAQ;QAClB,KAAK,EAAE,UAAU;QACjB,OAAO,EAAE,CAAC;QACV,IAAI,EAAE,MAAM,CAAC,4BAA4B;KAC5C;IACD;QACI,IAAI,EAAE,aAAa;QACnB,QAAQ,EAAE,QAAQ;QAClB,KAAK,EAAE,UAAU;QACjB,OAAO,EAAE,CAAC;QACV,IAAI,EAAE,MAAM,CAAC,4BAA4B;KAC5C;IACD;QACI,IAAI,EAAE,OAAO;QACb,QAAQ,EAAE,OAAO;QACjB,KAAK,EAAE,OAAO;QACd,OAAO,EAAE,CAAC;QACV,IAAI,EAAE,IAAI;KACb;CACF,CAAC"} \ No newline at end of file diff --git a/lib.esm/constants/strings.d.ts b/lib.esm/constants/strings.d.ts new file mode 100644 index 00000000..f6a232bb --- /dev/null +++ b/lib.esm/constants/strings.d.ts @@ -0,0 +1,13 @@ +/** + * A constant for the ether symbol (normalized using NFKC). + * + * (**i.e.** ``"\\u039e"``) + */ +export declare const quaisymbol: string; +/** + * A constant for the [[link-eip-191]] personal message prefix. + * + * (**i.e.** ``"\\x19Ethereum Signed Message:\\n"``) + */ +export declare const MessagePrefix: string; +//# sourceMappingURL=strings.d.ts.map \ No newline at end of file diff --git a/lib.esm/constants/strings.d.ts.map b/lib.esm/constants/strings.d.ts.map new file mode 100644 index 00000000..86f37410 --- /dev/null +++ b/lib.esm/constants/strings.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"strings.d.ts","sourceRoot":"","sources":["../../src.ts/constants/strings.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,UAAU,EAAE,MAAiB,CAAC;AAG3C;;;;GAIG;AACH,eAAO,MAAM,aAAa,EAAE,MAAqC,CAAC"} \ No newline at end of file diff --git a/lib.esm/constants/strings.js b/lib.esm/constants/strings.js new file mode 100644 index 00000000..7ad47320 --- /dev/null +++ b/lib.esm/constants/strings.js @@ -0,0 +1,14 @@ +// NFKC (composed) // (decomposed) +/** + * A constant for the ether symbol (normalized using NFKC). + * + * (**i.e.** ``"\\u039e"``) + */ +export const quaisymbol = "\u039e"; // "\uD835\uDF63"; +/** + * A constant for the [[link-eip-191]] personal message prefix. + * + * (**i.e.** ``"\\x19Ethereum Signed Message:\\n"``) + */ +export const MessagePrefix = "\x19Quai Signed Message:\n"; +//# sourceMappingURL=strings.js.map \ No newline at end of file diff --git a/lib.esm/constants/strings.js.map b/lib.esm/constants/strings.js.map new file mode 100644 index 00000000..3e5e0146 --- /dev/null +++ b/lib.esm/constants/strings.js.map @@ -0,0 +1 @@ +{"version":3,"file":"strings.js","sourceRoot":"","sources":["../../src.ts/constants/strings.ts"],"names":[],"mappings":"AAAA,8CAA8C;AAE9C;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAW,QAAQ,CAAC,CAAE,kBAAkB;AAG/D;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAW,4BAA4B,CAAC"} \ No newline at end of file diff --git a/lib.esm/contract/contract.d.ts b/lib.esm/contract/contract.d.ts new file mode 100644 index 00000000..72b82bbf --- /dev/null +++ b/lib.esm/contract/contract.d.ts @@ -0,0 +1,168 @@ +import { Interface } from "../abi/index.js"; +import { Log, TransactionResponse } from "../providers/provider.js"; +import { ContractTransactionResponse, EventLog } from "./wrappers.js"; +import type { EventFragment, FunctionFragment, InterfaceAbi, ParamType } from "../abi/index.js"; +import type { Addressable } from "../address/index.js"; +import type { EventEmitterable, Listener } from "../utils/index.js"; +import type { BlockTag, ContractRunner } from "../providers/index.js"; +import type { ContractEventName, ContractInterface, ContractMethod, ContractEvent, ContractTransaction, WrappedFallback } from "./types.js"; +/** + * @_ignore: + */ +export declare function copyOverrides(arg: any, allowed?: Array): Promise>; +/** + * @_ignore: + */ +export declare function resolveArgs(_runner: null | ContractRunner, inputs: ReadonlyArray, args: Array): Promise>; +declare const internal: unique symbol; +export declare class BaseContract implements Addressable, EventEmitterable { + /** + * The target to connect to. + * + * This can be an address, ENS name or any [[Addressable]], such as + * another contract. To get the resovled address, use the ``getAddress`` + * method. + */ + readonly target: string | Addressable; + /** + * The contract Interface. + */ + readonly interface: Interface; + /** + * The connected runner. This is generally a [[Provider]] or a + * [[Signer]], which dictates what operations are supported. + * + * For example, a **Contract** connected to a [[Provider]] may + * only execute read-only operations. + */ + readonly runner: null | ContractRunner; + /** + * All the Events available on this contract. + */ + readonly filters: Record; + /** + * @_ignore: + */ + readonly [internal]: any; + /** + * The fallback or receive function if any. + */ + readonly fallback: null | WrappedFallback; + /** + * Creates a new contract connected to %%target%% with the %%abi%% and + * optionally connected to a %%runner%% to perform operations on behalf + * of. + */ + constructor(target: string | Addressable, abi: Interface | InterfaceAbi, runner?: null | ContractRunner, _deployTx?: null | TransactionResponse); + /** + * Return a new Contract instance with the same target and ABI, but + * a different %%runner%%. + */ + connect(runner: null | ContractRunner): BaseContract; + /** + * Return a new Contract instance with the same ABI and runner, but + * a different %%target%%. + */ + attach(target: string | Addressable): BaseContract; + /** + * Return the resolved address of this Contract. + */ + getAddress(): Promise; + /** + * Return the deployed bytecode or null if no bytecode is found. + */ + getDeployedCode(): Promise; + /** + * Resolve to this Contract once the bytecode has been deployed, or + * resolve immediately if already deployed. + */ + waitForDeployment(): Promise; + /** + * Return the transaction used to deploy this contract. + * + * This is only available if this instance was returned from a + * [[ContractFactory]]. + */ + deploymentTransaction(): null | ContractTransactionResponse; + /** + * Return the function for a given name. This is useful when a contract + * method name conflicts with a JavaScript name such as ``prototype`` or + * when using a Contract programatically. + */ + getFunction(key: string | FunctionFragment): T; + /** + * Return the event for a given name. This is useful when a contract + * event name conflicts with a JavaScript name such as ``prototype`` or + * when using a Contract programatically. + */ + getEvent(key: string | EventFragment): ContractEvent; + /** + * @_ignore: + */ + queryTransaction(hash: string): Promise>; + /** + * Provide historic access to event data for %%event%% in the range + * %%fromBlock%% (default: ``0``) to %%toBlock%% (default: ``"latest"``) + * inclusive. + */ + queryFilter(shard: string, event: ContractEventName, fromBlock?: BlockTag, toBlock?: BlockTag): Promise>; + /** + * Add an event %%listener%% for the %%event%%. + */ + on(event: ContractEventName, listener: Listener): Promise; + /** + * Add an event %%listener%% for the %%event%%, but remove the listener + * after it is fired once. + */ + once(event: ContractEventName, listener: Listener): Promise; + /** + * Emit an %%event%% calling all listeners with %%args%%. + * + * Resolves to ``true`` if any listeners were called. + */ + emit(event: ContractEventName, ...args: Array): Promise; + /** + * Resolves to the number of listeners of %%event%% or the total number + * of listeners if unspecified. + */ + listenerCount(event?: ContractEventName): Promise; + /** + * Resolves to the listeners subscribed to %%event%% or all listeners + * if unspecified. + */ + listeners(event?: ContractEventName): Promise>; + /** + * Remove the %%listener%% from the listeners for %%event%% or remove + * all listeners if unspecified. + */ + off(event: ContractEventName, listener?: Listener): Promise; + /** + * Remove all the listeners for %%event%% or remove all listeners if + * unspecified. + */ + removeAllListeners(event?: ContractEventName): Promise; + /** + * Alias for [on]. + */ + addListener(event: ContractEventName, listener: Listener): Promise; + /** + * Alias for [off]. + */ + removeListener(event: ContractEventName, listener: Listener): Promise; + /** + * Create a new Class for the %%abi%%. + */ + static buildClass(abi: Interface | InterfaceAbi): new (target: string, runner?: null | ContractRunner) => BaseContract & Omit; + /** + * Create a new BaseContract with a specified Interface. + */ + static from(target: string, abi: Interface | InterfaceAbi, runner?: null | ContractRunner): BaseContract & Omit; +} +declare const Contract_base: new (target: string, abi: InterfaceAbi | Interface, runner?: ContractRunner | null | undefined) => BaseContract & Omit; +/** + * A [[BaseContract]] with no type guards on its methods or events. + */ +export declare class Contract extends Contract_base { +} +export {}; +//# sourceMappingURL=contract.d.ts.map \ No newline at end of file diff --git a/lib.esm/contract/contract.d.ts.map b/lib.esm/contract/contract.d.ts.map new file mode 100644 index 00000000..6f86a294 --- /dev/null +++ b/lib.esm/contract/contract.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../src.ts/contract/contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAS,MAAM,iBAAiB,CAAC;AAInD,OAAO,EAAe,GAAG,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAMjF,OAAO,EAEH,2BAA2B,EAC3B,QAAQ,EACX,MAAM,eAAe,CAAC;AAEvB,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,YAAY,EAAE,SAAS,EAAU,MAAM,iBAAiB,CAAC;AACxG,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,KAAK,EACR,QAAQ,EAAE,cAAc,EAC3B,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAER,iBAAiB,EACjB,iBAAiB,EAEjB,cAAc,EAEd,aAAa,EACb,mBAAmB,EAEnB,eAAe,EAClB,MAAM,YAAY,CAAC;AAqFpB;;GAEG;AACH,wBAAsB,aAAa,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,IA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AAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAgBpE;;;OAGG;IACG,GAAG,CAAC,KAAK,EAAE,iBAAiB,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBvE;;;OAGG;IACG,kBAAkB,CAAC,KAAK,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBlE;;OAEG;IACG,WAAW,CAAC,KAAK,EAAE,iBAAiB,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAI9E;;OAEG;IACG,cAAc,CAAC,KAAK,EAAE,iBAAiB,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAIjF;;OAEG;IACH,MAAM,CAAC,UAAU,CAAC,CAAC,GAAG,iBAAiB,EAAE,GAAG,EAAE,SAAS,GAAG,YAAY,GAAG,KAAK,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,IAAI,GAAG,cAAc,KAAK,YAAY,GAAG,IAAI,CAAC,CAAC,EAAE,MAAM,YAAY,CAAC;IAS3K;;OAEG;IACH,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,iBAAiB,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,GAAG,YAAY,EAAE,MAAM,CAAC,EAAE,IAAI,GAAG,cAAc,GAAG,YAAY,GAAG,IAAI,CAAC,CAAC,EAAE,MAAM,YAAY,CAAC;CAKhK;;AAMD;;GAEG;AACH,qBAAa,QAAS,SAAQ,aAAe;CAAI"} \ No newline at end of file diff --git a/lib.esm/contract/contract.js b/lib.esm/contract/contract.js new file mode 100644 index 00000000..610e55fc --- /dev/null +++ b/lib.esm/contract/contract.js @@ -0,0 +1,921 @@ +import { Interface, Typed } from "../abi/index.js"; +import { isAddressable, resolveAddress } from "../address/index.js"; +// import from provider.ts instead of index.ts to prevent circular dep +// from quaiscanProvider +import { copyRequest, Log } from "../providers/provider.js"; +import { defineProperties, getBigInt, isCallException, isHexString, resolveProperties, isError, assert, assertArgument } from "../utils/index.js"; +import { ContractEventPayload, ContractUnknownEventPayload, ContractTransactionResponse, EventLog, UndecodedEventLog } from "./wrappers.js"; +const BN_0 = BigInt(0); +function canCall(value) { + return (value && typeof (value.call) === "function"); +} +function canEstimate(value) { + return (value && typeof (value.estimateGas) === "function"); +} +function canSend(value) { + return (value && typeof (value.sendTransaction) === "function"); +} +class PreparedTopicFilter { + #filter; + fragment; + constructor(contract, fragment, args) { + defineProperties(this, { fragment }); + if (fragment.inputs.length < args.length) { + throw new Error("too many arguments"); + } + this.#filter = (async function () { + const resolvedArgs = await Promise.all(fragment.inputs.map((param, index) => { + const arg = args[index]; + if (arg == null) { + return null; + } + return param.walkAsync(args[index], (type, value) => { + if (type === "address") { + if (Array.isArray(value)) { + return Promise.all(value.map((v) => resolveAddress(v))); + } + return resolveAddress(value); + } + 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 = Array, R = any, D extends R | ContractTransactionResponse = ContractTransactionResponse> { +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; +} +/** + * @_ignore: + */ +export async function copyOverrides(arg, allowed) { + // Make sure the overrides passed in are a valid overrides object + const _overrides = Typed.dereference(arg, "overrides"); + assertArgument(typeof (_overrides) === "object", "invalid overrides parameter", "overrides", arg); + // Create a shallow copy (we'll deep-ify anything needed during normalizing) + const overrides = copyRequest(_overrides); + assertArgument(overrides.to == null || (allowed || []).indexOf("to") >= 0, "cannot override to", "overrides.to", overrides.to); + assertArgument(overrides.data == null || (allowed || []).indexOf("data") >= 0, "cannot override data", "overrides.data", overrides.data); + // Resolve any from + if (overrides.from) { + overrides.from = overrides.from; + } + return overrides; +} +/** + * @_ignore: + */ +export async function resolveArgs(_runner, inputs, args) { + // Recursively descend into args and resolve any addresses + return await Promise.all(inputs.map((param, index) => { + return param.walkAsync(args[index], (type, value) => { + value = Typed.dereference(value, type); + if (type === "address") { + return resolveAddress(value); + } + return value; + }); + })); +} +function buildWrappedFallback(contract) { + const populateTransaction = async function (overrides) { + // If an overrides was passed in, copy it and normalize the values + const tx = (await copyOverrides(overrides, ["data"])); + tx.to = await contract.getAddress(); + if (tx.from) { + tx.from = await resolveAddress(tx.from); + } + const iface = contract.interface; + const noValue = (getBigInt((tx.value || BN_0), "overrides.value") === BN_0); + const noData = ((tx.data || "0x") === "0x"); + if (iface.fallback && !iface.fallback.payable && iface.receive && !noData && !noValue) { + assertArgument(false, "cannot send data to receive or send value to non-payable fallback", "overrides", overrides); + } + assertArgument(iface.fallback || noData, "cannot send data to receive-only contract", "overrides.data", tx.data); + // Only allow payable contracts to set non-zero value + const payable = iface.receive || (iface.fallback && iface.fallback.payable); + assertArgument(payable || noValue, "cannot send value to non-payable fallback", "overrides.value", tx.value); + // Only allow fallback contracts to set non-empty data + assertArgument(iface.fallback || noData, "cannot send data to receive-only contract", "overrides.data", tx.data); + return tx; + }; + const staticCall = async function (overrides) { + const runner = getRunner(contract.runner, "call"); + assert(canCall(runner), "contract runner does not support calling", "UNSUPPORTED_OPERATION", { operation: "call" }); + const tx = await populateTransaction(overrides); + try { + return await runner.call(tx); + } + catch (error) { + if (isCallException(error) && error.data) { + throw contract.interface.makeError(error.data, tx); + } + throw error; + } + }; + const send = async function (overrides) { + const runner = contract.runner; + assert(canSend(runner), "contract runner does not support sending transactions", "UNSUPPORTED_OPERATION", { operation: "sendTransaction" }); + const tx = await runner.sendTransaction(await populateTransaction(overrides)); + const provider = getProvider(contract.runner); + // @TODO: the provider can be null; make a custom dummy provider that will throw a + // meaningful error + return new ContractTransactionResponse(contract.interface, provider, tx); + }; + const estimateGas = async function (overrides) { + const runner = getRunner(contract.runner, "estimateGas"); + assert(canEstimate(runner), "contract runner does not support gas estimation", "UNSUPPORTED_OPERATION", { operation: "estimateGas" }); + return await runner.estimateGas(await populateTransaction(overrides)); + }; + const method = async (overrides) => { + return await send(overrides); + }; + defineProperties(method, { + _contract: contract, + estimateGas, + populateTransaction, + send, staticCall + }); + return method; +} +function buildWrappedMethod(contract, key) { + const getFragment = function (...args) { + const fragment = contract.interface.getFunction(key, args); + assert(fragment, "no matching fragment", "UNSUPPORTED_OPERATION", { + operation: "fragment", + info: { key, args } + }); + return fragment; + }; + const populateTransaction = async function (...args) { + const fragment = 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()); + const resolvedArgs = await resolveArgs(contract.runner, fragment.inputs, args); + return Object.assign({}, overrides, await resolveProperties({ + to: contract.getAddress(), + data: contract.interface.encodeFunctionData(fragment, resolvedArgs) + })); + // if (overrides.from) { + // overrides.from = await resolveAddress(overrides.from, getResolver(contract.runner)); + // } + } + if (fragment.inputs.length !== args.length) { + throw new Error("internal error: fragment inputs doesn't match arguments; should not happen"); + } + const resolvedArgs = await resolveArgs(contract.runner, fragment.inputs, args); + return await resolveProperties({ + to: contract.getAddress(), + from: args.pop().from, + data: contract.interface.encodeFunctionData(fragment, resolvedArgs) + }); + }; + const staticCall = async function (...args) { + const result = await staticCallResult(...args); + if (result.length === 1) { + return result[0]; + } + return result; + }; + const send = async function (...args) { + const runner = contract.runner; + assert(canSend(runner), "contract runner does not support sending transactions", "UNSUPPORTED_OPERATION", { operation: "sendTransaction" }); + const tx = await runner.sendTransaction(await populateTransaction(...args)); + const provider = getProvider(contract.runner); + // @TODO: the provider can be null; make a custom dummy provider that will throw a + // meaningful error + return new ContractTransactionResponse(contract.interface, provider, tx); + }; + const estimateGas = async function (...args) { + const runner = getRunner(contract.runner, "estimateGas"); + assert(canEstimate(runner), "contract runner does not support gas estimation", "UNSUPPORTED_OPERATION", { operation: "estimateGas" }); + return await runner.estimateGas(await populateTransaction(...args)); + }; + const staticCallResult = async function (...args) { + const runner = getRunner(contract.runner, "call"); + assert(canCall(runner), "contract runner does not support calling", "UNSUPPORTED_OPERATION", { operation: "call" }); + const tx = await populateTransaction(...args); + let result = "0x"; + try { + result = await runner.call(tx); + } + catch (error) { + if (isCallException(error) && error.data) { + throw contract.interface.makeError(error.data, tx); + } + throw error; + } + const fragment = getFragment(...args); + return contract.interface.decodeFunctionResult(fragment, result); + }; + const method = async (...args) => { + const fragment = getFragment(...args); + if (fragment.constant) { + return await staticCall(...args); + } + return await send(...args); + }; + defineProperties(method, { + name: contract.interface.getFunctionName(key), + _contract: contract, _key: key, + getFragment, + estimateGas, + populateTransaction, + send, staticCall, staticCallResult, + }); + // Only works on non-ambiguous keys (refined fragment is always non-ambiguous) + Object.defineProperty(method, "fragment", { + configurable: false, + enumerable: true, + get: () => { + const fragment = contract.interface.getFunction(key); + assert(fragment, "no matching fragment", "UNSUPPORTED_OPERATION", { + operation: "fragment", + info: { key } + }); + return fragment; + } + }); + return method; +} +function buildWrappedEvent(contract, key) { + const getFragment = function (...args) { + const fragment = contract.interface.getEvent(key, args); + assert(fragment, "no matching fragment", "UNSUPPORTED_OPERATION", { + operation: "fragment", + info: { key, args } + }); + return fragment; + }; + const method = function (...args) { + return new PreparedTopicFilter(contract, getFragment(...args), args); + }; + defineProperties(method, { + name: contract.interface.getEventName(key), + _contract: contract, _key: key, + getFragment + }); + // Only works on non-ambiguous keys (refined fragment is always non-ambiguous) + Object.defineProperty(method, "fragment", { + configurable: false, + enumerable: true, + get: () => { + const fragment = contract.interface.getEvent(key); + assert(fragment, "no matching fragment", "UNSUPPORTED_OPERATION", { + operation: "fragment", + info: { key } + }); + return fragment; + } + }); + return method; +} +// 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("_quaisInternal_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 getSubInfo(contract, event) { + let topics; + let fragment = null; + // Convert named events to topicHash and get the fragment for + // events which need deconstructing. + if (Array.isArray(event)) { + const topicHashify = function (name) { + if (isHexString(name, 32)) { + return name; + } + const fragment = contract.interface.getEvent(name); + assertArgument(fragment, "unknown fragment", "name", name); + return fragment.topicHash; + }; + // Array of Topics and Names; e.g. `[ "0x1234...89ab", "Transfer(address)" ]` + topics = event.map((e) => { + if (e == null) { + return null; + } + if (Array.isArray(e)) { + return e.map(topicHashify); + } + return topicHashify(e); + }); + } + else if (event === "*") { + topics = [null]; + } + else if (typeof (event) === "string") { + if (isHexString(event, 32)) { + // Topic Hash + topics = [event]; + } + else { + // Name or Signature; e.g. `"Transfer", `"Transfer(address)"` + fragment = contract.interface.getEvent(event); + assertArgument(fragment, "unknown fragment", "event", event); + topics = [fragment.topicHash]; + } + } + else if (isDeferred(event)) { + // Deferred Topic Filter; e.g. `contract.filter.Transfer(from)` + topics = await event.getTopicFilter(); + } + else if ("fragment" in event) { + // ContractEvent; e.g. `contract.filter.Transfer` + fragment = event.fragment; + topics = [fragment.topicHash]; + } + else { + assertArgument(false, "unknown event name", "event", event); + } + // Normalize topics and sort TopicSets + topics = topics.map((t) => { + if (t == null) { + return null; + } + if (Array.isArray(t)) { + const items = Array.from(new Set(t.map((t) => t.toLowerCase())).values()); + if (items.length === 1) { + return items[0]; + } + items.sort(); + return items; + } + 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 getSubInfo(contract, event)).tag) || null; +} +async function getSub(contract, operation, event) { + // Make sure our runner can actually subscribe to events + const provider = getProvider(contract.runner); + assert(provider, "contract runner does not support subscribing", "UNSUPPORTED_OPERATION", { operation }); + const { fragment, tag, topics } = await getSubInfo(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) => { + let foundFragment = fragment; + if (foundFragment == null) { + try { + foundFragment = contract.interface.getEvent(log.topics[0]); + } + catch (error) { } + } + // If fragment is null, we do not deconstruct the args to emit + if (foundFragment) { + const _foundFragment = foundFragment; + const args = fragment ? contract.interface.decodeEventLog(fragment, log.data, log.topics) : []; + emit(contract, event, args, (listener) => { + return new ContractEventPayload(contract, listener, event, _foundFragment, log); + }); + } + else { + emit(contract, event, [], (listener) => { + return new ContractUnknownEventPayload(contract, listener, event, log); + }); + } + }; + let starting = []; + const start = () => { + if (starting.length) { + return; + } + starting.push(provider.on(filter, listener)); + }; + const stop = async () => { + if (starting.length == 0) { + return; + } + let started = starting; + starting = []; + await Promise.all(started); + provider.off(filter, listener); + }; + 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, payloadFunc) { + 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 = Array.from(args); + if (payloadFunc) { + passArgs.push(payloadFunc(once ? null : listener)); + } + try { + listener.call(contract, ...passArgs); + } + catch (error) { } + return !once; + }); + if (sub.listeners.length === 0) { + sub.stop(); + getInternal(contract).subs.delete(sub.tag); + } + return (count > 0); +} +async function emit(contract, event, args, payloadFunc) { + try { + await lastEmit; + } + catch (error) { } + const resultPromise = _emit(contract, event, args, payloadFunc); + lastEmit = resultPromise; + return await resultPromise; +} +const passProperties = ["then"]; +export class BaseContract { + /** + * The target to connect to. + * + * This can be an address, ENS name or any [[Addressable]], such as + * another contract. To get the resovled address, use the ``getAddress`` + * method. + */ + target; + /** + * The contract Interface. + */ + interface; + /** + * The connected runner. This is generally a [[Provider]] or a + * [[Signer]], which dictates what operations are supported. + * + * For example, a **Contract** connected to a [[Provider]] may + * only execute read-only operations. + */ + runner; + /** + * All the Events available on this contract. + */ + filters; + /** + * @_ignore: + */ + [internal]; + /** + * The fallback or receive function if any. + */ + fallback; + /** + * Creates a new contract connected to %%target%% with the %%abi%% and + * optionally connected to a %%runner%% to perform operations on behalf + * of. + */ + constructor(target, abi, runner, _deployTx) { + assertArgument(typeof (target) === "string" || isAddressable(target), "invalid value for Contract target", "target", target); + if (runner == null) { + runner = null; + } + const iface = Interface.from(abi); + 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); + // @TODO: the provider can be null; make a custom dummy provider that will throw a + // meaningful error + deployTx = new ContractTransactionResponse(this.interface, provider, _deployTx); + } + let subs = new Map(); + // Resolve the target as the address + if (typeof (target) === "string") { + addr = target; + addrPromise = Promise.resolve(target); + } + 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 (typeof (prop) === "symbol" || passProperties.indexOf(prop) >= 0) { + return Reflect.get(target, prop, receiver); + } + try { + return this.getEvent(prop); + } + catch (error) { + if (!isError(error, "INVALID_ARGUMENT") || error.argument !== "key") { + throw error; + } + } + return undefined; + }, + has: (target, prop) => { + // Pass important checks (like `then` for Promise) through + if (passProperties.indexOf(prop) >= 0) { + return Reflect.has(target, prop); + } + return Reflect.has(target, prop) || this.interface.hasEvent(String(prop)); + } + }); + defineProperties(this, { filters }); + defineProperties(this, { + fallback: ((iface.receive || iface.fallback) ? (buildWrappedFallback(this)) : null) + }); + // Return a Proxy that will respond to functions + return new Proxy(this, { + get: (target, prop, receiver) => { + if (typeof (prop) === "symbol" || prop in target || passProperties.indexOf(prop) >= 0) { + return Reflect.get(target, prop, receiver); + } + // Undefined properties should return undefined + try { + return target.getFunction(prop); + } + catch (error) { + if (!isError(error, "INVALID_ARGUMENT") || error.argument !== "key") { + throw error; + } + } + return undefined; + }, + has: (target, prop) => { + if (typeof (prop) === "symbol" || prop in target || passProperties.indexOf(prop) >= 0) { + return Reflect.has(target, prop); + } + return target.interface.hasFunction(prop); + } + }); + } + /** + * Return a new Contract instance with the same target and ABI, but + * a different %%runner%%. + */ + connect(runner) { + return new BaseContract(this.target, this.interface, runner); + } + /** + * Return a new Contract instance with the same ABI and runner, but + * a different %%target%%. + */ + attach(target) { + return new BaseContract(target, this.interface, this.runner); + } + /** + * Return the resolved address of this Contract. + */ + async getAddress() { return await getInternal(this).addrPromise; } + /** + * Return the deployed bytecode or null if no bytecode is found. + */ + async getDeployedCode() { + const provider = getProvider(this.runner); + assert(provider, "runner does not support .provider", "UNSUPPORTED_OPERATION", { operation: "getDeployedCode" }); + const code = await provider.getCode(await this.getAddress()); + if (code === "0x") { + return null; + } + return code; + } + /** + * Resolve to this Contract once the bytecode has been deployed, or + * resolve immediately if already deployed. + */ + 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); + assert(provider != null, "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(); + }); + } + /** + * Return the transaction used to deploy this contract. + * + * This is only available if this instance was returned from a + * [[ContractFactory]]. + */ + deploymentTransaction() { + return getInternal(this).deployTx; + } + /** + * Return the function for a given name. This is useful when a contract + * method name conflicts with a JavaScript name such as ``prototype`` or + * when using a Contract programatically. + */ + getFunction(key) { + if (typeof (key) !== "string") { + key = key.format(); + } + const func = buildWrappedMethod(this, key); + return func; + } + /** + * Return the event for a given name. This is useful when a contract + * event name conflicts with a JavaScript name such as ``prototype`` or + * when using a Contract programatically. + */ + getEvent(key) { + if (typeof (key) !== "string") { + key = key.format(); + } + return buildWrappedEvent(this, key); + } + /** + * @_ignore: + */ + async queryTransaction(hash) { + throw new Error("@TODO"); + } + /* + // @TODO: this is a non-backwards compatible change, but will be added + // in v7 and in a potential SmartContract class in an upcoming + // v6 release + async getTransactionReceipt(hash: string): Promise { + const provider = getProvider(this.runner); + assert(provider, "contract runner does not have a provider", + "UNSUPPORTED_OPERATION", { operation: "queryTransaction" }); + + const receipt = await provider.getTransactionReceipt(hash); + if (receipt == null) { return null; } + + return new ContractTransactionReceipt(this.interface, provider, receipt); + } + */ + /** + * Provide historic access to event data for %%event%% in the range + * %%fromBlock%% (default: ``0``) to %%toBlock%% (default: ``"latest"``) + * inclusive. + */ + async queryFilter(shard, event, fromBlock, toBlock) { + if (fromBlock == null) { + fromBlock = 0; + } + if (toBlock == null) { + toBlock = "latest"; + } + const { addr, addrPromise } = getInternal(this); + const address = (addr ? addr : (await addrPromise)); + const { fragment, topics } = await getSubInfo(this, event); + const filter = { address, topics, fromBlock, toBlock, shard: shard }; + const provider = getProvider(this.runner); + assert(provider, "contract runner does not have a provider", "UNSUPPORTED_OPERATION", { operation: "queryFilter" }); + return (await provider.getLogs(filter)).map((log) => { + let foundFragment = fragment; + if (foundFragment == null) { + try { + foundFragment = this.interface.getEvent(log.topics[0]); + } + catch (error) { } + } + if (foundFragment) { + try { + return new EventLog(log, this.interface, foundFragment); + } + catch (error) { + return new UndecodedEventLog(log, error); + } + } + return new Log(log, provider); + }); + } + /** + * Add an event %%listener%% for the %%event%%. + */ + async on(event, listener) { + const sub = await getSub(this, "on", event); + sub.listeners.push({ listener, once: false }); + sub.start(); + return this; + } + /** + * Add an event %%listener%% for the %%event%%, but remove the listener + * after it is fired once. + */ + async once(event, listener) { + const sub = await getSub(this, "once", event); + sub.listeners.push({ listener, once: true }); + sub.start(); + return this; + } + /** + * Emit an %%event%% calling all listeners with %%args%%. + * + * Resolves to ``true`` if any listeners were called. + */ + async emit(event, ...args) { + return await emit(this, event, args, null); + } + /** + * Resolves to the number of listeners of %%event%% or the total number + * of listeners if unspecified. + */ + 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; + } + /** + * Resolves to the listeners subscribed to %%event%% or all listeners + * if unspecified. + */ + 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; + } + /** + * Remove the %%listener%% from the listeners for %%event%% or remove + * all listeners if unspecified. + */ + 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; + } + /** + * Remove all the listeners for %%event%% or remove all listeners if + * unspecified. + */ + 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); + } + /** + * Create a new Class for the %%abi%%. + */ + static buildClass(abi) { + class CustomContract extends BaseContract { + constructor(address, runner = null) { + super(address, abi, runner); + } + } + return CustomContract; + } + ; + /** + * Create a new BaseContract with a specified Interface. + */ + static from(target, abi, runner) { + if (runner == null) { + runner = null; + } + const contract = new this(target, abi, runner); + return contract; + } +} +function _ContractBase() { + return BaseContract; +} +/** + * A [[BaseContract]] with no type guards on its methods or events. + */ +export class Contract extends _ContractBase() { +} +//# sourceMappingURL=contract.js.map \ No newline at end of file diff --git a/lib.esm/contract/contract.js.map b/lib.esm/contract/contract.js.map new file mode 100644 index 00000000..b43a131b --- /dev/null +++ b/lib.esm/contract/contract.js.map @@ -0,0 +1 @@ +{"version":3,"file":"contract.js","sourceRoot":"","sources":["../../src.ts/contract/contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACpE,sEAAsE;AACtE,wBAAwB;AACxB,OAAO,EAAE,WAAW,EAAE,GAAG,EAAuB,MAAM,0BAA0B,CAAC;AACjF,OAAO,EACH,gBAAgB,EAAE,SAAS,EAAE,eAAe,EAAE,WAAW,EAAE,iBAAiB,EAC5E,OAAO,EAAE,MAAM,EAAE,cAAc,EAClC,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACH,oBAAoB,EAAE,2BAA2B,EACjD,2BAA2B,EAC3B,QAAQ,EAAE,iBAAiB,EAC9B,MAAM,eAAe,CAAC;AAsBvB,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;AAcvB,SAAS,OAAO,CAAC,KAAU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A6B;QAClE,MAAM,cAAe,SAAQ,YAAY;YACrC,YAAY,OAAe,EAAE,SAAgC,IAAI;gBAC7D,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;YAChC,CAAC;SACJ;QACD,OAAO,cAAqB,CAAC;IACjC,CAAC;IAAA,CAAC;IAEF;;OAEG;IACH,MAAM,CAAC,IAAI,CAAwB,MAAc,EAAE,GAA6B,EAAE,MAA8B;QAC5G,IAAI,MAAM,IAAI,IAAI,EAAE;YAAE,MAAM,GAAG,IAAI,CAAC;SAAE;QACtC,MAAM,QAAQ,GAAG,IAAI,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,CAAE,CAAC;QAChD,OAAO,QAAe,CAAC;IAC3B,CAAC;CACJ;AAED,SAAS,aAAa;IAClB,OAAO,YAAmB,CAAC;AAC/B,CAAC;AAED;;GAEG;AACH,MAAM,OAAO,QAAS,SAAQ,aAAa,EAAE;CAAI"} \ No newline at end of file diff --git a/lib.esm/contract/factory.d.ts b/lib.esm/contract/factory.d.ts new file mode 100644 index 00000000..6b57a135 --- /dev/null +++ b/lib.esm/contract/factory.d.ts @@ -0,0 +1,68 @@ +import { Interface } from "../abi/index.js"; +import { BaseContract } from "./contract.js"; +import type { InterfaceAbi } from "../abi/index.js"; +import type { Addressable } from "../address/index.js"; +import type { ContractRunner, TransactionRequest } from "../providers/index.js"; +import type { BytesLike } from "../utils/index.js"; +import type { ContractInterface, ContractMethodArgs, ContractDeployTransaction } from "./types.js"; +import type { ContractTransactionResponse } from "./wrappers.js"; +/** + * A **ContractFactory** is used to deploy a Contract to the blockchain. + */ +export declare class ContractFactory = Array, I = BaseContract> { + /** + * The Contract Interface. + */ + readonly interface: Interface; + /** + * The Contract deployment bytecode. Often called the initcode. + */ + readonly bytecode: string; + /** + * The ContractRunner to deploy the Contract as. + */ + readonly runner: null | ContractRunner; + /** + * Create a new **ContractFactory** with %%abi%% and %%bytecode%%, + * optionally connected to %%runner%%. + * + * The %%bytecode%% may be the ``bytecode`` property within the + * standard Solidity JSON output. + */ + constructor(abi: Interface | InterfaceAbi, bytecode: BytesLike | { + object: string; + }, runner?: null | ContractRunner); + attach(target: string | Addressable): BaseContract & Omit; + /** + * Resolves to the transaction to deploy the contract, passing %%args%% + * into the constructor. + */ + getDeployTransaction(...args: ContractMethodArgs): Promise; + /** + * Resolves to the Contract deployed by passing %%args%% into the + * constructor. + * + * This will resovle to the Contract before it has been deployed to the + * network, so the [[BaseContract-waitForDeployment]] should be used before + * sending any transactions to it. + */ + deploy(...args: ContractMethodArgs): Promise>; + static getContractAddress(transaction: { + from: string; + nonce: bigint; + data: BytesLike; + }): string; + grindContractAddress(tx: TransactionRequest): Promise; + /** + * Return a new **ContractFactory** with the same ABI and bytecode, + * but connected to %%runner%%. + */ + connect(runner: null | ContractRunner): ContractFactory; + /** + * Create a new **ContractFactory** from the standard Solidity JSON output. + */ + static fromSolidity = Array, I = ContractInterface>(output: any, runner?: ContractRunner): ContractFactory; +} +//# sourceMappingURL=factory.d.ts.map \ No newline at end of file diff --git a/lib.esm/contract/factory.d.ts.map b/lib.esm/contract/factory.d.ts.map new file mode 100644 index 00000000..6cba74a2 --- /dev/null +++ b/lib.esm/contract/factory.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src.ts/contract/factory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAM5C,OAAO,EAAE,YAAY,EAA8B,MAAM,eAAe,CAAC;AAEzE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,KAAK,EACR,iBAAiB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kB,CAAC;IAwBhC;;;OAGG;IACH,OAAO,CAAC,MAAM,EAAE,IAAI,GAAG,cAAc,GAAG,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC;IAI7D;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,CAAC,SAAS,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,iBAAiB,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,cAAc,GAAG,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC;CAgB7I"} \ No newline at end of file diff --git a/lib.esm/contract/factory.js b/lib.esm/contract/factory.js new file mode 100644 index 00000000..bf1b9233 --- /dev/null +++ b/lib.esm/contract/factory.js @@ -0,0 +1,194 @@ +import { Interface } from "../abi/index.js"; +import { concat, defineProperties, getBytes, hexlify, assert, assertArgument } from "../utils/index.js"; +import { BaseContract, copyOverrides, resolveArgs } from "./contract.js"; +import { getShardForAddress, isUTXOAddress } from "../utils/index.js"; +import { Wallet, randomBytes } from "../quais.js"; +import { getContractAddress } from "../address/address.js"; +import { getStatic } from "../utils/properties.js"; +// A = Arguments to the constructor +// I = Interface of deployed contracts +/** + * A **ContractFactory** is used to deploy a Contract to the blockchain. + */ +export class ContractFactory { + /** + * The Contract Interface. + */ + interface; + /** + * The Contract deployment bytecode. Often called the initcode. + */ + bytecode; + /** + * The ContractRunner to deploy the Contract as. + */ + runner; + /** + * Create a new **ContractFactory** with %%abi%% and %%bytecode%%, + * optionally connected to %%runner%%. + * + * The %%bytecode%% may be the ``bytecode`` property within the + * standard Solidity JSON output. + */ + constructor(abi, bytecode, runner) { + const iface = Interface.from(abi); + // Dereference Solidity bytecode objects and allow a missing `0x`-prefix + if (bytecode instanceof Uint8Array) { + bytecode = hexlify(getBytes(bytecode)); + } + else { + if (typeof (bytecode) === "object") { + bytecode = bytecode.object; + } + if (!bytecode.startsWith("0x")) { + bytecode = "0x" + bytecode; + } + bytecode = hexlify(getBytes(bytecode)); + } + defineProperties(this, { + bytecode, interface: iface, runner: (runner || null) + }); + } + attach(target) { + return new BaseContract(target, this.interface, this.runner); + } + /** + * Resolves to the transaction to deploy the contract, passing %%args%% + * into the constructor. + */ + async getDeployTransaction(...args) { + let overrides; + const fragment = this.interface.deploy; + if (fragment.inputs.length + 1 === args.length) { + overrides = await copyOverrides(args.pop()); + const resolvedArgs = await resolveArgs(this.runner, fragment.inputs, args); + const data = concat([this.bytecode, this.interface.encodeDeploy(resolvedArgs)]); + return Object.assign({}, overrides, { data }); + } + if (fragment.inputs.length !== args.length) { + throw new Error("incorrect number of arguments to constructor"); + } + const resolvedArgs = await resolveArgs(this.runner, fragment.inputs, args); + const data = concat([this.bytecode, this.interface.encodeDeploy(resolvedArgs)]); + return Object.assign({}, args.pop().from, { data }); + } + // getDeployTransaction3(...args: Array): TransactionRequest { + // let tx: TransactionRequest = {}; + // // If we have 1 additional argument, we allow transaction overrides + // if ( + // args.length === this.interface.deploy.inputs.length + 1 && + // typeof args[args.length - 1] === "object" + // ) { + // //tx = shallowCopy(args.pop()); + // tx = copyOverrides(args.pop()); + // for (const key in tx) { + // if (!allowedTransactionKeys[key]) { + // throw new Error("unknown transaction override " + key); + // } + // } + // } + // // Do not allow these to be overridden in a deployment transaction + // ["data", "from", "to"].forEach((key) => { + // if ((tx)[key] == null) { + // return; + // } + // assertArgument(false, "cannot override " + key, key, (tx)[key]); + // }); + // if (tx.value) { + // const value = Number(tx.value) + // if ( value != 0 && !this.interface.deploy.payable) { + // assertArgument( + // false, + // "non-zero value provided to non-payable (or constructor) function", + // "value", value + // ); + // } + // } + // // // Make sure the call matches the constructor signature + // // logger.checkArgumentCount( + // // args.length, + // // this.interface.deploy.inputs.length, + // // " in Contract constructor" + // // ); + // // Set the data to the bytecode + the encoded constructor arguments + // tx.data = hexlify( + // concat([this.bytecode, this.interface.encodeDeploy(args)]) + // ); + // return tx; + // } + /** + * Resolves to the Contract deployed by passing %%args%% into the + * constructor. + * + * This will resovle to the Contract before it has been deployed to the + * network, so the [[BaseContract-waitForDeployment]] should be used before + * sending any transactions to it. + */ + async deploy(...args) { + const tx = await this.getDeployTransaction(...args); + assert(this.runner && typeof (this.runner.sendTransaction) === "function", "factory runner does not support sending transactions", "UNSUPPORTED_OPERATION", { + operation: "sendTransaction" + }); + if (this.runner instanceof Wallet) { + tx.from = this.runner.address; + } + const grindedTx = await this.grindContractAddress(tx); + console.log("grindedTx", grindedTx); + const sentTx = await this.runner.sendTransaction(grindedTx); + const address = getStatic(this.constructor, "getContractAddress")?.(tx); + //const address = getCreateAddress(sentTx); + return new BaseContract(address, this.interface, this.runner, sentTx); + } + static getContractAddress(transaction) { + return getContractAddress(transaction.from, BigInt(transaction.nonce), // Fix: Convert BigInt to bigint + transaction.data); + } + async grindContractAddress(tx) { + if (tx.nonce == null && tx.from) { + tx.nonce = await this.runner?.provider?.getTransactionCount(tx.from); + } + const sender = String(tx.from); + const toShard = getShardForAddress(sender); + var i = 0; + var startingData = tx.data; + while (i < 10000) { + var contractAddress = getContractAddress(sender, BigInt(tx.nonce || 0), tx.data || ''); + var contractShard = getShardForAddress(contractAddress); + console.log("contractAddress ", contractAddress); + var utxo = isUTXOAddress(contractAddress); + if (contractShard === toShard && !utxo) { + return tx; + } + var salt = randomBytes(32); + tx.data = hexlify(concat([String(startingData), salt])); + i++; + } + return tx; + } + /** + * Return a new **ContractFactory** with the same ABI and bytecode, + * but connected to %%runner%%. + */ + connect(runner) { + return new ContractFactory(this.interface, this.bytecode, runner); + } + /** + * Create a new **ContractFactory** from the standard Solidity JSON output. + */ + static fromSolidity(output, runner) { + assertArgument(output != null, "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); + } +} +//# sourceMappingURL=factory.js.map \ No newline at end of file diff --git a/lib.esm/contract/factory.js.map b/lib.esm/contract/factory.js.map new file mode 100644 index 00000000..3d37fa88 --- /dev/null +++ b/lib.esm/contract/factory.js.map @@ -0,0 +1 @@ +{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../src.ts/contract/factory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EACH,MAAM,EAAE,gBAAgB,EAAE,QAAQ,EAAE,OAAO,EAC3C,MAAM,EAAE,cAAc,EACzB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAMzE,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAKtE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAGnD,mCAAmC;AACnC,sCAAsC;AAEtC;;GAEG;AACH,MAAM,OAAO,eAAe;IAExB;;OAEG;IACM,SAAS,CAAa;IAE/B;;OAEG;IACM,QAAQ,CAAU;IAE3B;;OAEG;IACM,MAAM,CAAyB;IAExC;;;;;;OAMG;IACH,YAAY,GAA6B,EAAE,QAAwC,EAAE,MAA8B;QAC/G,MAAM,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAGlC,wEAAwE;QACxE,IAAI,QAAQ,YAAY,UAAU,EAAE;YAChC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;SAC1C;aAAM;YACH,IAAI,OAAM,CAAC,QAAQ,CAAC,KAAK,QAAQ,EAAE;gBAAE,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC;aAAE;YAClE,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CA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AC,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"} \ No newline at end of file diff --git a/lib.esm/contract/index.d.ts b/lib.esm/contract/index.d.ts new file mode 100644 index 00000000..b7f2c818 --- /dev/null +++ b/lib.esm/contract/index.d.ts @@ -0,0 +1,13 @@ +/** + * A **Contract** object is a meta-class (a class whose definition is + * defined at runtime), which communicates with a deployed smart contract + * on the blockchain and provides a simple JavaScript interface to call + * methods, send transaction, query historic logs and listen for its events. + * + * @_section: api/contract:Contracts [about-contracts] + */ +export { BaseContract, Contract } from "./contract.js"; +export { ContractFactory } from "./factory.js"; +export { ContractEventPayload, ContractUnknownEventPayload, ContractTransactionReceipt, ContractTransactionResponse, EventLog, UndecodedEventLog } from "./wrappers.js"; +export type { BaseContractMethod, ConstantContractMethod, PostfixOverrides, ContractEvent, ContractEventArgs, ContractEventName, ContractDeployTransaction, ContractInterface, ContractMethod, ContractMethodArgs, ContractTransaction, DeferredTopicFilter, Overrides, WrappedFallback } from "./types.js"; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/lib.esm/contract/index.d.ts.map b/lib.esm/contract/index.d.ts.map new file mode 100644 index 00000000..aad3d029 --- /dev/null +++ b/lib.esm/contract/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src.ts/contract/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EACH,YAAY,EAAE,QAAQ,EACzB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACH,eAAe,EAClB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACH,oBAAoB,EAAE,2BAA2B,EACjD,0BAA0B,EAAE,2BAA2B,EACvD,QAAQ,EAAE,iBAAiB,EAC9B,MAAM,eAAe,CAAC;AAEvB,YAAY,EACR,kBAAkB,EAAE,sBAAsB,EAC1C,gBAAgB,EAChB,aAAa,EAAE,iBAAiB,EAAE,iBAAiB,EACnD,yBAAyB,EACzB,iBAAiB,EAAE,cAAc,EAAE,kBAAkB,EAAE,mBAAmB,EAC1E,mBAAmB,EAAE,SAAS,EAC9B,eAAe,EAClB,MAAM,YAAY,CAAC"} \ No newline at end of file diff --git a/lib.esm/contract/index.js b/lib.esm/contract/index.js new file mode 100644 index 00000000..e7699343 --- /dev/null +++ b/lib.esm/contract/index.js @@ -0,0 +1,12 @@ +/** + * A **Contract** object is a meta-class (a class whose definition is + * defined at runtime), which communicates with a deployed smart contract + * on the blockchain and provides a simple JavaScript interface to call + * methods, send transaction, query historic logs and listen for its events. + * + * @_section: api/contract:Contracts [about-contracts] + */ +export { BaseContract, Contract } from "./contract.js"; +export { ContractFactory } from "./factory.js"; +export { ContractEventPayload, ContractUnknownEventPayload, ContractTransactionReceipt, ContractTransactionResponse, EventLog, UndecodedEventLog } from "./wrappers.js"; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib.esm/contract/index.js.map b/lib.esm/contract/index.js.map new file mode 100644 index 00000000..93010046 --- /dev/null +++ b/lib.esm/contract/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src.ts/contract/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EACH,YAAY,EAAE,QAAQ,EACzB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACH,eAAe,EAClB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACH,oBAAoB,EAAE,2BAA2B,EACjD,0BAA0B,EAAE,2BAA2B,EACvD,QAAQ,EAAE,iBAAiB,EAC9B,MAAM,eAAe,CAAC"} \ No newline at end of file diff --git a/lib.esm/contract/types.d.ts b/lib.esm/contract/types.d.ts new file mode 100644 index 00000000..be2d954d --- /dev/null +++ b/lib.esm/contract/types.d.ts @@ -0,0 +1,193 @@ +import type { EventFragment, FunctionFragment, Result, Typed } from "../abi/index.js"; +import type { TransactionRequest, PreparedTransactionRequest, TopicFilter } from "../providers/index.js"; +import type { ContractTransactionResponse } from "./wrappers.js"; +/** + * The name for an event used for subscribing to Contract events. + * + * **``string``** - An event by name. The event must be non-ambiguous. + * The parameters will be dereferenced when passed into the listener. + * + * [[ContractEvent]] - A filter from the ``contract.filters``, which will + * pass only the EventPayload as a single parameter, which includes a + * ``.signature`` property that can be used to further filter the event. + * + * [[TopicFilter]] - A filter defined using the standard Ethereum API + * which provides the specific topic hash or topic hashes to watch for along + * with any additional values to filter by. This will only pass a single + * parameter to the listener, the EventPayload which will include additional + * details to refine by, such as the event name and signature. + * + * [[DeferredTopicFilter]] - A filter created by calling a [[ContractEvent]] + * with parameters, which will create a filter for a specific event + * signautre and dereference each parameter when calling the listener. + */ +export type ContractEventName = string | ContractEvent | TopicFilter | DeferredTopicFilter; +/** + * A Contract with no method constraints. + */ +export interface ContractInterface { + [name: string]: BaseContractMethod; +} +/** + * When creating a filter using the ``contract.filters``, this is returned. + */ +export interface DeferredTopicFilter { + getTopicFilter(): Promise; + fragment: EventFragment; +} +/** + * When populating a transaction this type is returned. + */ +export interface ContractTransaction extends PreparedTransactionRequest { + /** + * The target address. + */ + to: string; + /** + * The transaction data. + */ + data: string; + /** + * The from address, if any. + */ + from: string; +} +/** + * A deployment transaction for a contract. + */ +export interface ContractDeployTransaction extends Omit { +} +/** + * The overrides for a contract transaction. + */ +export interface Overrides extends Omit { +} +/** + * Arguments to a Contract method can always include an additional and + * optional overrides parameter. + * + * @_ignore: + */ +export type PostfixOverrides> = A | [...A, Overrides]; +/** + * Arguments to a Contract method can always include an additional and + * optional overrides parameter, and each parameter can optionally be + * [[Typed]]. + * + * @_ignore: + */ +export type ContractMethodArgs> = PostfixOverrides<{ + [I in keyof A]-?: A[I] | Typed; +}>; +/** + * A Contract method can be called directly, or used in various ways. + */ +export interface BaseContractMethod = Array, R = any, D extends R | ContractTransactionResponse = R | ContractTransactionResponse> { + (...args: ContractMethodArgs): Promise; + /** + * The name of the Contract method. + */ + name: string; + /** + * The fragment of the Contract method. This will throw on ambiguous + * method names. + */ + fragment: FunctionFragment; + /** + * Returns the fragment constrained by %%args%%. This can be used to + * resolve ambiguous method names. + */ + getFragment(...args: ContractMethodArgs): FunctionFragment; + /** + * Returns a populated transaction that can be used to perform the + * contract method with %%args%%. + */ + populateTransaction(...args: ContractMethodArgs): Promise; + /** + * Call the contract method with %%args%% and return the value. + * + * If the return value is a single type, it will be dereferenced and + * returned directly, otherwise the full Result will be returned. + */ + staticCall(...args: ContractMethodArgs): Promise; + /** + * Send a transaction for the contract method with %%args%%. + */ + send(...args: ContractMethodArgs): Promise; + /** + * Estimate the gas to send the contract method with %%args%%. + */ + estimateGas(...args: ContractMethodArgs): Promise; + /** + * Call the contract method with %%args%% and return the Result + * without any dereferencing. + */ + staticCallResult(...args: ContractMethodArgs): Promise; +} +/** + * A contract method on a Contract. + */ +export interface ContractMethod = Array, R = any, D extends R | ContractTransactionResponse = R | ContractTransactionResponse> extends BaseContractMethod { +} +/** + * A pure of view method on a Contract. + */ +export interface ConstantContractMethod, R = any> extends ContractMethod { +} +/** + * Each argument of an event is nullable (to indicate matching //any//. + * + * @_ignore: + */ +export type ContractEventArgs> = { + [I in keyof A]?: A[I] | Typed | null; +}; +export interface ContractEvent = Array> { + (...args: ContractEventArgs): DeferredTopicFilter; + /** + * The name of the Contract event. + */ + name: string; + /** + * The fragment of the Contract event. This will throw on ambiguous + * method names. + */ + fragment: EventFragment; + /** + * Returns the fragment constrained by %%args%%. This can be used to + * resolve ambiguous event names. + */ + getFragment(...args: ContractEventArgs): EventFragment; +} +/** + * A Fallback or Receive function on a Contract. + */ +export interface WrappedFallback { + (overrides?: Omit): Promise; + /** + * Returns a populated transaction that can be used to perform the + * fallback method. + * + * For non-receive fallback, ``data`` may be overridden. + */ + populateTransaction(overrides?: Omit): Promise; + /** + * Call the contract fallback and return the result. + * + * For non-receive fallback, ``data`` may be overridden. + */ + staticCall(overrides?: Omit): Promise; + /** + * Send a transaction to the contract fallback. + * + * For non-receive fallback, ``data`` may be overridden. + */ + send(overrides?: Omit): Promise; + /** + * Estimate the gas to send a transaction to the contract fallback. + * + * For non-receive fallback, ``data`` may be overridden. + */ + estimateGas(overrides?: Omit): Promise; +} +//# sourceMappingURL=types.d.ts.map \ No newline at end of file diff --git a/lib.esm/contract/types.d.ts.map b/lib.esm/contract/types.d.ts.map new file mode 100644 index 00000000..8c805861 --- /dev/null +++ b/lib.esm/contract/types.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src.ts/contract/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,aAAa,EAAE,gBAAgB,EAAE,MAAM,EAAE,KAAK,EACjD,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EACR,kBAAkB,EAAE,0BAA0B,EAAE,WAAW,EAC9D,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAGjE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,aAAa,GAAG,WAAW,GAAG,mBAAmB,CAAC;AAE3F;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAC9B,CAAE,IAAI,EAAE,MAAM,GAAI,kBAAkB,CAAC;CACxC;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAChC,cAAc,IAAI,OAAO,CAAC,WAAW,CAAC,CAAC;IACvC,QAAQ,EAAE,aAAa,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,mBAAoB,SAAQ,0BAA0B;IACnE;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;OA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,CAAC,CAAC,CAAC,GAAG,mBAAmB,CAAC;IAErD;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,QAAQ,EAAE,aAAa,CAAC;IAExB;;;OAGG;IACH,WAAW,CAAC,GAAG,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC;CAC7D;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC5B,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC,kBAAkB,EAAE,IAAI,CAAC,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAAC;IAEnF;;;;;OAKG;IACH,mBAAmB,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC,kBAAkB,EAAE,IAAI,CAAC,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAE9F;;;;OAIG;IACH,UAAU,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC,kBAAkB,EAAE,IAAI,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAExE;;;;OAIG;IACH,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC,kBAAkB,EAAE,IAAI,CAAC,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAAC;IAEvF;;;;OAIG;IACH,WAAW,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC,kBAAkB,EAAE,IAAI,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC5E"} \ No newline at end of file diff --git a/lib.esm/contract/types.js b/lib.esm/contract/types.js new file mode 100644 index 00000000..14353c78 --- /dev/null +++ b/lib.esm/contract/types.js @@ -0,0 +1,5 @@ +; +; +; +export {}; +//# sourceMappingURL=types.js.map \ No newline at end of file diff --git a/lib.esm/contract/types.js.map b/lib.esm/contract/types.js.map new file mode 100644 index 00000000..d88f0d6d --- /dev/null +++ b/lib.esm/contract/types.js.map @@ -0,0 +1 @@ +{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src.ts/contract/types.ts"],"names":[],"mappings":"AAqCC,CAAC;AAuC4E,CAAC;AA4H9E,CAAC"} \ No newline at end of file diff --git a/lib.esm/contract/wrappers.d.ts b/lib.esm/contract/wrappers.d.ts new file mode 100644 index 00000000..e5af484f --- /dev/null +++ b/lib.esm/contract/wrappers.d.ts @@ -0,0 +1,143 @@ +import { Block, Log, TransactionReceipt, TransactionResponse } from "../providers/provider.js"; +import { EventPayload } from "../utils/index.js"; +import type { EventFragment, Interface, Result } from "../abi/index.js"; +import type { Listener } from "../utils/index.js"; +import type { Provider } from "../providers/index.js"; +import type { BaseContract } from "./contract.js"; +import type { ContractEventName } from "./types.js"; +/** + * An **EventLog** contains additional properties parsed from the [[Log]]. + */ +export declare class EventLog extends Log { + /** + * The Contract Interface. + */ + readonly interface: Interface; + /** + * The matching event. + */ + readonly fragment: EventFragment; + /** + * The parsed arguments passed to the event by ``emit``. + */ + readonly args: Result; + /** + * @_ignore: + */ + constructor(log: Log, iface: Interface, fragment: EventFragment); + /** + * The name of the event. + */ + get eventName(): string; + /** + * The signature of the event. + */ + get eventSignature(): string; +} +/** + * An **EventLog** contains additional properties parsed from the [[Log]]. + */ +export declare class UndecodedEventLog extends Log { + /** + * The error encounted when trying to decode the log. + */ + readonly error: Error; + /** + * @_ignore: + */ + constructor(log: Log, error: Error); +} +/** + * A **ContractTransactionReceipt** includes the parsed logs from a + * [[TransactionReceipt]]. + */ +export declare class ContractTransactionReceipt extends TransactionReceipt { + #private; + /** + * @_ignore: + */ + constructor(iface: Interface, provider: Provider, tx: TransactionReceipt); + /** + * The parsed logs for any [[Log]] which has a matching event in the + * Contract ABI. + */ + get logs(): Array; +} +/** + * A **ContractTransactionResponse** will return a + * [[ContractTransactionReceipt]] when waited on. + */ +export declare class ContractTransactionResponse extends TransactionResponse { + #private; + /** + * @_ignore: + */ + constructor(iface: Interface, provider: Provider, tx: TransactionResponse); + /** + * Resolves once this transaction has been mined and has + * %%confirms%% blocks including it (default: ``1``) with an + * optional %%timeout%%. + * + * This can resolve to ``null`` only if %%confirms%% is ``0`` + * and the transaction has not been mined, otherwise this will + * wait until enough confirmations have completed. + */ + wait(confirms?: number): Promise; +} +/** + * A **ContractUnknownEventPayload** is included as the last parameter to + * Contract Events when the event does not match any events in the ABI. + */ +export declare class ContractUnknownEventPayload extends EventPayload { + /** + * The log with no matching events. + */ + readonly log: Log; + /** + * @_event: + */ + constructor(contract: BaseContract, listener: null | Listener, filter: ContractEventName, log: Log); + /** + * Resolves to the block the event occured in. + */ + getBlock(shard: string): Promise; + /** + * Resolves to the transaction the event occured in. + */ + getTransaction(): Promise; + /** + * Resolves to the transaction receipt the event occured in. + */ + getTransactionReceipt(): Promise; +} +/** + * A **ContractEventPayload** is included as the last parameter to + * Contract Events when the event is known. + */ +export declare class ContractEventPayload extends ContractUnknownEventPayload { + /** + * The matching event. + */ + readonly fragment: EventFragment; + /** + * The log, with parsed properties. + */ + readonly log: EventLog; + /** + * The parsed arguments passed to the event by ``emit``. + */ + readonly args: Result; + /** + * @_ignore: + */ + constructor(contract: BaseContract, listener: null | Listener, filter: ContractEventName, fragment: EventFragment, _log: Log); + /** + * The event name. + */ + get eventName(): string; + /** + * The event signature. + */ + get eventSignature(): string; +} +//# sourceMappingURL=wrappers.d.ts.map \ No newline at end of file diff --git a/lib.esm/contract/wrappers.d.ts.map b/lib.esm/contract/wrappers.d.ts.map new file mode 100644 index 00000000..cd3ccc0d --- /dev/null +++ b/lib.esm/contract/wrappers.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"wrappers.d.ts","sourceRoot":"","sources":["../../src.ts/contract/wrappers.ts"],"names":[],"mappings":"AAEA,OAAO,EACH,KAAK,EAAE,GAAG,EAAE,kBAAkB,EAAE,mBAAmB,EACtD,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAoB,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEnE,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACxE,OAAO,KAAK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,OAAO,CAAC,IAAI,GAAG,0BAA0B,CAAC;CAK5E;AAED;;;GAGG;AACH,qBAAc,2BAA4B,SAAQ,YAAY,CAAC,iBAAiB,CAAC;IAC7E;;OAEG;IACH,QAAQ,CAAC,GAAG,EAAG,GAAG,CAAC;IAEnB;;OAEG;gBACS,QAAQ,EAAE,YAAY,EAAE,QAAQ,EAAE,IAAI,GAAG,QAAQ,EAAE,MAAM,EAAE,iBAAiB,EAAE,GAAG,EAAE,GAAG;IAKlG;;OAEG;IACG,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IAI7C;;OAEG;IACG,cAAc,IAAI,OAAO,CAAC,mBAAmB,CAAC;IAIpD;;OAEG;IACG,qBAAqB,IAAI,OAAO,CAAC,kBAAkB,CAAC;CAG7D;AAED;;;GAGG;AACH,qBAAa,oBAAqB,SAAQ,2BAA2B;IAEjE;;OAEG;IACH,SAAiB,QAAQ,EAAE,aAAa,CAAC;IAEzC;;OAEG;IACH,SAAiB,GAAG,EAAE,QAAQ,CAAC;IAE/B;;OAEG;IACH,SAAiB,IAAI,EAAE,MAAM,CAAC;IAE9B;;OAEG;gBACS,QAAQ,EAAE,YAAY,EAAE,QAAQ,EAAE,IAAI,GAAG,QAAQ,EAAE,MAAM,EAAE,iBAAiB,EAAE,QAAQ,EAAE,aAAa,EAAE,IAAI,EAAE,GAAG;IAM5H;;OAEG;IACH,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED;;OAEG;IACH,IAAI,cAAc,IAAI,MAAM,CAE3B;CACJ"} \ No newline at end of file diff --git a/lib.esm/contract/wrappers.js b/lib.esm/contract/wrappers.js new file mode 100644 index 00000000..e3c705a0 --- /dev/null +++ b/lib.esm/contract/wrappers.js @@ -0,0 +1,177 @@ +// import from provider.ts instead of index.ts to prevent circular dep +// from quaiscanProvider +import { Log, TransactionReceipt, TransactionResponse } from "../providers/provider.js"; +import { defineProperties, EventPayload } from "../utils/index.js"; +/** + * An **EventLog** contains additional properties parsed from the [[Log]]. + */ +export class EventLog extends Log { + /** + * The Contract Interface. + */ + interface; + /** + * The matching event. + */ + fragment; + /** + * The parsed arguments passed to the event by ``emit``. + */ + args; + /** + * @_ignore: + */ + constructor(log, iface, fragment) { + super(log, log.provider); + const args = iface.decodeEventLog(fragment, log.data, log.topics); + defineProperties(this, { args, fragment, interface: iface }); + } + /** + * The name of the event. + */ + get eventName() { return this.fragment.name; } + /** + * The signature of the event. + */ + get eventSignature() { return this.fragment.format(); } +} +/** + * An **EventLog** contains additional properties parsed from the [[Log]]. + */ +export class UndecodedEventLog extends Log { + /** + * The error encounted when trying to decode the log. + */ + error; + /** + * @_ignore: + */ + constructor(log, error) { + super(log, log.provider); + defineProperties(this, { error }); + } +} +/** + * A **ContractTransactionReceipt** includes the parsed logs from a + * [[TransactionReceipt]]. + */ +export class ContractTransactionReceipt extends TransactionReceipt { + #iface; + /** + * @_ignore: + */ + constructor(iface, provider, tx) { + super(tx, provider); + this.#iface = iface; + } + /** + * The parsed logs for any [[Log]] which has a matching event in the + * Contract ABI. + */ + get logs() { + return super.logs.map((log) => { + const fragment = log.topics.length ? this.#iface.getEvent(log.topics[0]) : null; + if (fragment) { + try { + return new EventLog(log, this.#iface, fragment); + } + catch (error) { + return new UndecodedEventLog(log, error); + } + } + return log; + }); + } +} +/** + * A **ContractTransactionResponse** will return a + * [[ContractTransactionReceipt]] when waited on. + */ +export class ContractTransactionResponse extends TransactionResponse { + #iface; + /** + * @_ignore: + */ + constructor(iface, provider, tx) { + super(tx, provider); + this.#iface = iface; + } + /** + * Resolves once this transaction has been mined and has + * %%confirms%% blocks including it (default: ``1``) with an + * optional %%timeout%%. + * + * This can resolve to ``null`` only if %%confirms%% is ``0`` + * and the transaction has not been mined, otherwise this will + * wait until enough confirmations have completed. + */ + async wait(confirms) { + const receipt = await super.wait(confirms); + if (receipt == null) { + return null; + } + return new ContractTransactionReceipt(this.#iface, this.provider, receipt); + } +} +/** + * A **ContractUnknownEventPayload** is included as the last parameter to + * Contract Events when the event does not match any events in the ABI. + */ +export class ContractUnknownEventPayload extends EventPayload { + /** + * The log with no matching events. + */ + log; + /** + * @_event: + */ + constructor(contract, listener, filter, log) { + super(contract, listener, filter); + defineProperties(this, { log }); + } + /** + * Resolves to the block the event occured in. + */ + async getBlock(shard) { + return await this.log.getBlock(shard); + } + /** + * Resolves to the transaction the event occured in. + */ + async getTransaction() { + return await this.log.getTransaction(); + } + /** + * Resolves to the transaction receipt the event occured in. + */ + async getTransactionReceipt() { + return await this.log.getTransactionReceipt(); + } +} +/** + * A **ContractEventPayload** is included as the last parameter to + * Contract Events when the event is known. + */ +export class ContractEventPayload extends ContractUnknownEventPayload { + /** + * @_ignore: + */ + constructor(contract, listener, filter, fragment, _log) { + super(contract, listener, filter, new EventLog(_log, contract.interface, fragment)); + const args = contract.interface.decodeEventLog(fragment, this.log.data, this.log.topics); + defineProperties(this, { args, fragment }); + } + /** + * The event name. + */ + get eventName() { + return this.fragment.name; + } + /** + * The event signature. + */ + get eventSignature() { + return this.fragment.format(); + } +} +//# sourceMappingURL=wrappers.js.map \ No newline at end of file diff --git a/lib.esm/contract/wrappers.js.map b/lib.esm/contract/wrappers.js.map new file mode 100644 index 00000000..3b210e05 --- /dev/null +++ b/lib.esm/contract/wrappers.js.map @@ -0,0 +1 @@ +{"version":3,"file":"wrappers.js","sourceRoot":"","sources":["../../src.ts/contract/wrappers.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,wBAAwB;AACxB,OAAO,EACI,GAAG,EAAE,kBAAkB,EAAE,mBAAmB,EACtD,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAWnE;;GAEG;AACH,MAAM,OAAO,QAAS,SAAQ,GAAG;IAC7B;;OAEG;IACM,SAAS,CAAa;IAE/B;;OAEG;IACM,QAAQ,CAAiB;IAElC;;OAEG;IACM,IAAI,CAAU;IAEvB;;OAEG;IACH,YAAY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;OAEG;IACH,KAAK,CAAC,QAAQ,CAAC,KAAa;QACxB,OAAO,MAAM,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC1C,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,cAAc;QAChB,OAAO,MAAM,IAAI,CAAC,GAAG,CAAC,cAAc,EAAE,CAAC;IAC3C,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,qBAAqB;QACvB,OAAO,MAAM,IAAI,CAAC,GAAG,CAAC,qBAAqB,EAAE,CAAC;IAClD,CAAC;CACJ;AAED;;;GAGG;AACH,MAAM,OAAO,oBAAqB,SAAQ,2BAA2B;IAiBjE;;OAEG;IACH,YAAY,QAAsB,EAAE,QAAyB,EAAE,MAAyB,EAAE,QAAuB,EAAE,IAAS;QACxH,KAAK,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC;QACpF,MAAM,IAAI,GAAG,QAAQ,CAAC,SAAS,CAAC,cAAc,CAAC,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACzF,gBAAgB,CAAuB,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;IACrE,CAAC;IAED;;OAEG;IACH,IAAI,SAAS;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,IAAI,cAAc;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;IAClC,CAAC;CACJ"} \ No newline at end of file diff --git a/lib.esm/crypto/crypto-browser.d.ts b/lib.esm/crypto/crypto-browser.d.ts new file mode 100644 index 00000000..ba0bbf19 --- /dev/null +++ b/lib.esm/crypto/crypto-browser.d.ts @@ -0,0 +1,15 @@ +declare global { + interface Window { + } + const window: Window; + const self: Window; +} +export interface CryptoHasher { + update(data: Uint8Array): CryptoHasher; + digest(): Uint8Array; +} +export declare function createHash(algo: string): CryptoHasher; +export declare function createHmac(_algo: string, key: Uint8Array): CryptoHasher; +export declare function pbkdf2Sync(password: Uint8Array, salt: Uint8Array, iterations: number, keylen: number, _algo: "sha256" | "sha512"): Uint8Array; +export declare function randomBytes(length: number): Uint8Array; +//# sourceMappingURL=crypto-browser.d.ts.map \ No newline at end of file diff --git a/lib.esm/crypto/crypto-browser.d.ts.map b/lib.esm/crypto/crypto-browser.d.ts.map new file mode 100644 index 00000000..b6950c78 --- /dev/null +++ b/lib.esm/crypto/crypto-browser.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"crypto-browser.d.ts","sourceRoot":"","sources":["../../src.ts/crypto/crypto-browser.ts"],"names":[],"mappings":"AAUA,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,MAAM;KAAI;IAEpB,MAAM,MAAM,EAAE,MAAM,CAAC;IACrB,MAAM,IAAI,EAAE,MAAM,CAAC;CACtB;AAcD,MAAM,WAAW,YAAY;IACzB,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,YAAY,CAAC;IACvC,MAAM,IAAI,UAAU,CAAC;CACxB;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAMrD;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,GAAG,YAAY,CAIvE;AAED,wBAAgB,UAAU,CAAC,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,GAAG,QAAQ,GAAG,UAAU,CAI7I;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAStD"} \ No newline at end of file diff --git a/lib.esm/crypto/crypto-browser.js b/lib.esm/crypto/crypto-browser.js new file mode 100644 index 00000000..8d95b6fa --- /dev/null +++ b/lib.esm/crypto/crypto-browser.js @@ -0,0 +1,48 @@ +/* Browser Crypto Shims */ +import { hmac } from "@noble/hashes/hmac"; +import { pbkdf2 } from "@noble/hashes/pbkdf2"; +import { sha256 } from "@noble/hashes/sha256"; +import { sha512 } from "@noble/hashes/sha512"; +import { assert, assertArgument } from "../utils/index.js"; +function getGlobal() { + if (typeof self !== 'undefined') { + return self; + } + if (typeof window !== 'undefined') { + return window; + } + if (typeof global !== 'undefined') { + return global; + } + throw new Error('unable to locate global object'); +} +; +const anyGlobal = getGlobal(); +const crypto = anyGlobal.crypto || anyGlobal.msCrypto; +export function createHash(algo) { + switch (algo) { + case "sha256": return sha256.create(); + case "sha512": return sha512.create(); + } + assertArgument(false, "invalid hashing algorithm name", "algorithm", algo); +} +export function createHmac(_algo, key) { + const algo = ({ sha256, sha512 }[_algo]); + assertArgument(algo != null, "invalid hmac algorithm", "algorithm", _algo); + return hmac.create(algo, key); +} +export function pbkdf2Sync(password, salt, iterations, keylen, _algo) { + const algo = ({ sha256, sha512 }[_algo]); + assertArgument(algo != null, "invalid pbkdf2 algorithm", "algorithm", _algo); + return pbkdf2(algo, password, salt, { c: iterations, dkLen: keylen }); +} +export function randomBytes(length) { + assert(crypto != null, "platform does not support secure random numbers", "UNSUPPORTED_OPERATION", { + operation: "randomBytes" + }); + assertArgument(Number.isInteger(length) && length > 0 && length <= 1024, "invalid length", "length", length); + const result = new Uint8Array(length); + crypto.getRandomValues(result); + return result; +} +//# sourceMappingURL=crypto-browser.js.map \ No newline at end of file diff --git a/lib.esm/crypto/crypto-browser.js.map b/lib.esm/crypto/crypto-browser.js.map new file mode 100644 index 00000000..28134d2b --- /dev/null +++ b/lib.esm/crypto/crypto-browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"crypto-browser.js","sourceRoot":"","sources":["../../src.ts/crypto/crypto-browser.ts"],"names":[],"mappings":"AAAA,0BAA0B;AAE1B,OAAO,EAAE,IAAI,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AAE,GAAG,CAAC,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,QAAoB,EAAE,IAAgB,EAAE,UAAkB,EAAE,MAAc,EAAE,KAA0B;IAC7H,MAAM,IAAI,GAAG,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IACzC,cAAc,CAAC,IAAI,IAAI,IAAI,EAAE,0BAA0B,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;IAC7E,OAAO,MAAM,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,CAAC,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;AAC1E,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,MAAc;IACtC,MAAM,CAAC,MAAM,IAAI,IAAI,EAAE,iDAAiD,EAAE,uBAAuB,EAAE;QAC/F,SAAS,EAAE,aAAa;KAAE,CAAC,CAAC;IAEhC,cAAc,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC,IAAI,MAAM,IAAI,IAAI,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;IAE7G,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;IACtC,MAAM,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;IAC/B,OAAO,MAAM,CAAC;AAClB,CAAC"} \ No newline at end of file diff --git a/lib.esm/crypto/crypto.d.ts b/lib.esm/crypto/crypto.d.ts new file mode 100644 index 00000000..e9c555de --- /dev/null +++ b/lib.esm/crypto/crypto.d.ts @@ -0,0 +1,2 @@ +export { createHash, createHmac, pbkdf2Sync, randomBytes } from "crypto"; +//# sourceMappingURL=crypto.d.ts.map \ No newline at end of file diff --git a/lib.esm/crypto/crypto.d.ts.map b/lib.esm/crypto/crypto.d.ts.map new file mode 100644 index 00000000..c417228d --- /dev/null +++ b/lib.esm/crypto/crypto.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../src.ts/crypto/crypto.ts"],"names":[],"mappings":"AACA,OAAO,EACH,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAClD,MAAM,QAAQ,CAAC"} \ No newline at end of file diff --git a/lib.esm/crypto/crypto.js b/lib.esm/crypto/crypto.js new file mode 100644 index 00000000..05475e30 --- /dev/null +++ b/lib.esm/crypto/crypto.js @@ -0,0 +1,2 @@ +export { createHash, createHmac, pbkdf2Sync, randomBytes } from "crypto"; +//# sourceMappingURL=crypto.js.map \ No newline at end of file diff --git a/lib.esm/crypto/crypto.js.map b/lib.esm/crypto/crypto.js.map new file mode 100644 index 00000000..1ff179cf --- /dev/null +++ b/lib.esm/crypto/crypto.js.map @@ -0,0 +1 @@ +{"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../src.ts/crypto/crypto.ts"],"names":[],"mappings":"AACA,OAAO,EACH,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAClD,MAAM,QAAQ,CAAC"} \ No newline at end of file diff --git a/lib.esm/crypto/hmac.d.ts b/lib.esm/crypto/hmac.d.ts new file mode 100644 index 00000000..4c5e3227 --- /dev/null +++ b/lib.esm/crypto/hmac.d.ts @@ -0,0 +1,25 @@ +import type { BytesLike } from "../utils/index.js"; +/** + * Return the HMAC for %%data%% using the %%key%% key with the underlying + * %%algo%% used for compression. + * + * @example: + * key = id("some-secret") + * + * // Compute the HMAC + * computeHmac("sha256", key, "0x1337") + * //_result: + * + * // To compute the HMAC of UTF-8 data, the data must be + * // converted to UTF-8 bytes + * computeHmac("sha256", key, toUtf8Bytes("Hello World")) + * //_result: + * + */ +export declare function computeHmac(algorithm: "sha256" | "sha512", _key: BytesLike, _data: BytesLike): string; +export declare namespace computeHmac { + var _: (algorithm: "sha256" | "sha512", key: Uint8Array, data: Uint8Array) => BytesLike; + var lock: () => void; + var register: (func: (algorithm: "sha256" | "sha512", key: Uint8Array, data: Uint8Array) => BytesLike) => void; +} +//# sourceMappingURL=hmac.d.ts.map \ No newline at end of file diff --git a/lib.esm/crypto/hmac.d.ts.map b/lib.esm/crypto/hmac.d.ts.map new file mode 100644 index 00000000..aa56a49f --- /dev/null +++ b/lib.esm/crypto/hmac.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"hmac.d.ts","sourceRoot":"","sources":["../../src.ts/crypto/hmac.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAWnD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,WAAW,CAAC,SAAS,EAAE,QAAQ,GAAG,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,GAAG,MAAM,CAIrG;yBAJe,WAAW"} \ No newline at end of file diff --git a/lib.esm/crypto/hmac.js b/lib.esm/crypto/hmac.js new file mode 100644 index 00000000..944c6651 --- /dev/null +++ b/lib.esm/crypto/hmac.js @@ -0,0 +1,47 @@ +/** + * An **HMAC** enables verification that a given key was used + * to authenticate a payload. + * + * See: [[link-wiki-hmac]] + * + * @_subsection: api/crypto:HMAC [about-hmac] + */ +import { createHmac } from "./crypto.js"; +import { getBytes, hexlify } from "../utils/index.js"; +let locked = false; +const _computeHmac = function (algorithm, key, data) { + return createHmac(algorithm, key).update(data).digest(); +}; +let __computeHmac = _computeHmac; +/** + * Return the HMAC for %%data%% using the %%key%% key with the underlying + * %%algo%% used for compression. + * + * @example: + * key = id("some-secret") + * + * // Compute the HMAC + * computeHmac("sha256", key, "0x1337") + * //_result: + * + * // To compute the HMAC of UTF-8 data, the data must be + * // converted to UTF-8 bytes + * computeHmac("sha256", key, toUtf8Bytes("Hello World")) + * //_result: + * + */ +export function computeHmac(algorithm, _key, _data) { + const key = getBytes(_key, "key"); + const data = getBytes(_data, "data"); + return hexlify(__computeHmac(algorithm, key, data)); +} +computeHmac._ = _computeHmac; +computeHmac.lock = function () { locked = true; }; +computeHmac.register = function (func) { + if (locked) { + throw new Error("computeHmac is locked"); + } + __computeHmac = func; +}; +Object.freeze(computeHmac); +//# sourceMappingURL=hmac.js.map \ No newline at end of file diff --git a/lib.esm/crypto/hmac.js.map b/lib.esm/crypto/hmac.js.map new file mode 100644 index 00000000..6e0c8ea2 --- /dev/null +++ b/lib.esm/crypto/hmac.js.map @@ -0,0 +1 @@ +{"version":3,"file":"hmac.js","sourceRoot":"","sources":["../../src.ts/crypto/hmac.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAKtD,IAAI,MAAM,GAAG,KAAK,CAAC;AAEnB,MAAM,YAAY,GAAG,UAAS,SAA8B,EAAE,GAAe,EAAE,IAAgB;IAC3F,OAAO,UAAU,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;AAC5D,CAAC,CAAA;AAED,IAAI,aAAa,GAAG,YAAY,CAAC;AAEjC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,WAAW,CAAC,SAA8B,EAAE,IAAe,EAAE,KAAgB;IACzF,MAAM,GAAG,GAAG,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAClC,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACrC,OAAO,OAAO,CAAC,aAAa,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;AACxD,CAAC;AACD,WAAW,CAAC,CAAC,GAAG,YAAY,CAAC;AAC7B,WAAW,CAAC,IAAI,GAAI,cAAa,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;AACjD,WAAW,CAAC,QAAQ,GAAG,UAAS,IAAsF;IAClH,IAAI,MAAM,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;KAAE;IACzD,aAAa,GAAG,IAAI,CAAC;AACzB,CAAC,CAAA;AACD,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC"} \ No newline at end of file diff --git a/lib.esm/crypto/index.d.ts b/lib.esm/crypto/index.d.ts new file mode 100644 index 00000000..8d6bc562 --- /dev/null +++ b/lib.esm/crypto/index.d.ts @@ -0,0 +1,25 @@ +/** + * A fundamental building block of Ethereum is the underlying + * cryptographic primitives. + * + * @_section: api/crypto:Cryptographic Functions [about-crypto] + */ +import { computeHmac } from "./hmac.js"; +import { keccak256 } from "./keccak.js"; +import { ripemd160 } from "./ripemd160.js"; +import { pbkdf2 } from "./pbkdf2.js"; +import { randomBytes } from "./random.js"; +import { scrypt, scryptSync } from "./scrypt.js"; +import { sha256, sha512 } from "./sha2.js"; +export { computeHmac, randomBytes, keccak256, ripemd160, sha256, sha512, pbkdf2, scrypt, scryptSync }; +export { SigningKey } from "./signing-key.js"; +export { Signature } from "./signature.js"; +/** + * Once called, prevents any future change to the underlying cryptographic + * primitives using the ``.register`` feature for hooks. + */ +declare function lock(): void; +export { lock }; +export type { ProgressCallback } from "./scrypt.js"; +export type { SignatureLike } from "./signature.js"; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/lib.esm/crypto/index.d.ts.map b/lib.esm/crypto/index.d.ts.map new file mode 100644 index 00000000..4f8d3c46 --- /dev/null +++ b/lib.esm/crypto/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src.ts/crypto/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAE3C,OAAO,EACH,WAAW,EAEX,WAAW,EAEX,SAAS,EACT,SAAS,EACT,MAAM,EAAE,MAAM,EAEd,MAAM,EACN,MAAM,EAAE,UAAU,EACrB,CAAC;AAEF,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C;;;GAGG;AACH,iBAAS,IAAI,IAAI,IAAI,CAWpB;AAED,OAAO,EAAE,IAAI,EAAE,CAAC;AAKhB,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC"} \ No newline at end of file diff --git a/lib.esm/crypto/index.js b/lib.esm/crypto/index.js new file mode 100644 index 00000000..a8608024 --- /dev/null +++ b/lib.esm/crypto/index.js @@ -0,0 +1,36 @@ +/** + * A fundamental building block of Ethereum is the underlying + * cryptographic primitives. + * + * @_section: api/crypto:Cryptographic Functions [about-crypto] + */ +null; +// We import all these so we can export lock() +import { computeHmac } from "./hmac.js"; +import { keccak256 } from "./keccak.js"; +import { ripemd160 } from "./ripemd160.js"; +import { pbkdf2 } from "./pbkdf2.js"; +import { randomBytes } from "./random.js"; +import { scrypt, scryptSync } from "./scrypt.js"; +import { sha256, sha512 } from "./sha2.js"; +export { computeHmac, randomBytes, keccak256, ripemd160, sha256, sha512, pbkdf2, scrypt, scryptSync }; +export { SigningKey } from "./signing-key.js"; +export { Signature } from "./signature.js"; +/** + * Once called, prevents any future change to the underlying cryptographic + * primitives using the ``.register`` feature for hooks. + */ +function lock() { + computeHmac.lock(); + keccak256.lock(); + pbkdf2.lock(); + randomBytes.lock(); + ripemd160.lock(); + scrypt.lock(); + scryptSync.lock(); + sha256.lock(); + sha512.lock(); + randomBytes.lock(); +} +export { lock }; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib.esm/crypto/index.js.map b/lib.esm/crypto/index.js.map new file mode 100644 index 00000000..8723de8b --- /dev/null +++ b/lib.esm/crypto/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src.ts/crypto/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,IAAI,CAAA;AAEJ,8CAA8C;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAE3C,OAAO,EACH,WAAW,EAEX,WAAW,EAEX,SAAS,EACT,SAAS,EACT,MAAM,EAAE,MAAM,EAEd,MAAM,EACN,MAAM,EAAE,UAAU,EACrB,CAAC;AAEF,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C;;;GAGG;AACH,SAAS,IAAI;IACT,WAAW,CAAC,IAAI,EAAE,CAAC;IACnB,SAAS,CAAC,IAAI,EAAE,CAAC;IACjB,MAAM,CAAC,IAAI,EAAE,CAAC;IACd,WAAW,CAAC,IAAI,EAAE,CAAC;IACnB,SAAS,CAAC,IAAI,EAAE,CAAC;IACjB,MAAM,CAAC,IAAI,EAAE,CAAC;IACd,UAAU,CAAC,IAAI,EAAE,CAAC;IAClB,MAAM,CAAC,IAAI,EAAE,CAAC;IACd,MAAM,CAAC,IAAI,EAAE,CAAC;IACd,WAAW,CAAC,IAAI,EAAE,CAAC;AACvB,CAAC;AAED,OAAO,EAAE,IAAI,EAAE,CAAC"} \ No newline at end of file diff --git a/lib.esm/crypto/keccak.d.ts b/lib.esm/crypto/keccak.d.ts new file mode 100644 index 00000000..533f46dc --- /dev/null +++ b/lib.esm/crypto/keccak.d.ts @@ -0,0 +1,35 @@ +/** + * Cryptographic hashing functions + * + * @_subsection: api/crypto:Hash Functions [about-crypto-hashing] + */ +import type { BytesLike } from "../utils/index.js"; +/** + * Compute the cryptographic KECCAK256 hash of %%data%%. + * + * The %%data%% **must** be a data representation, to compute the + * hash of UTF-8 data use the [[id]] function. + * + * @returns DataHexstring + * @example: + * keccak256("0x") + * //_result: + * + * keccak256("0x1337") + * //_result: + * + * keccak256(new Uint8Array([ 0x13, 0x37 ])) + * //_result: + * + * // Strings are assumed to be DataHexString, otherwise it will + * // throw. To hash UTF-8 data, see the note above. + * keccak256("Hello World") + * //_error: + */ +export declare function keccak256(_data: BytesLike): string; +export declare namespace keccak256 { + var _: (data: Uint8Array) => Uint8Array; + var lock: () => void; + var register: (func: (data: Uint8Array) => BytesLike) => void; +} +//# sourceMappingURL=keccak.d.ts.map \ No newline at end of file diff --git a/lib.esm/crypto/keccak.d.ts.map b/lib.esm/crypto/keccak.d.ts.map new file mode 100644 index 00000000..a0064495 --- /dev/null +++ b/lib.esm/crypto/keccak.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"keccak.d.ts","sourceRoot":"","sources":["../../src.ts/crypto/keccak.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAWnD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,CAGlD;yBAHe,SAAS"} \ No newline at end of file diff --git a/lib.esm/crypto/keccak.js b/lib.esm/crypto/keccak.js new file mode 100644 index 00000000..a5914c9d --- /dev/null +++ b/lib.esm/crypto/keccak.js @@ -0,0 +1,48 @@ +/** + * Cryptographic hashing functions + * + * @_subsection: api/crypto:Hash Functions [about-crypto-hashing] + */ +import { keccak_256 } from "@noble/hashes/sha3"; +import { getBytes, hexlify } from "../utils/index.js"; +let locked = false; +const _keccak256 = function (data) { + return keccak_256(data); +}; +let __keccak256 = _keccak256; +/** + * Compute the cryptographic KECCAK256 hash of %%data%%. + * + * The %%data%% **must** be a data representation, to compute the + * hash of UTF-8 data use the [[id]] function. + * + * @returns DataHexstring + * @example: + * keccak256("0x") + * //_result: + * + * keccak256("0x1337") + * //_result: + * + * keccak256(new Uint8Array([ 0x13, 0x37 ])) + * //_result: + * + * // Strings are assumed to be DataHexString, otherwise it will + * // throw. To hash UTF-8 data, see the note above. + * keccak256("Hello World") + * //_error: + */ +export function keccak256(_data) { + const data = getBytes(_data, "data"); + return hexlify(__keccak256(data)); +} +keccak256._ = _keccak256; +keccak256.lock = function () { locked = true; }; +keccak256.register = function (func) { + if (locked) { + throw new TypeError("keccak256 is locked"); + } + __keccak256 = func; +}; +Object.freeze(keccak256); +//# sourceMappingURL=keccak.js.map \ No newline at end of file diff --git a/lib.esm/crypto/keccak.js.map b/lib.esm/crypto/keccak.js.map new file mode 100644 index 00000000..02837e9f --- /dev/null +++ b/lib.esm/crypto/keccak.js.map @@ -0,0 +1 @@ +{"version":3,"file":"keccak.js","sourceRoot":"","sources":["../../src.ts/crypto/keccak.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAKtD,IAAI,MAAM,GAAG,KAAK,CAAC;AAEnB,MAAM,UAAU,GAAG,UAAS,IAAgB;IACxC,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC;AAC5B,CAAC,CAAA;AAED,IAAI,WAAW,GAAoC,UAAU,CAAC;AAE9D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,SAAS,CAAC,KAAgB;IACtC,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACrC,OAAO,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;AACtC,CAAC;AACD,SAAS,CAAC,CAAC,GAAG,UAAU,CAAC;AACzB,SAAS,CAAC,IAAI,GAAG,cAAmB,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;AACpD,SAAS,CAAC,QAAQ,GAAG,UAAS,IAAqC;IAC/D,IAAI,MAAM,EAAE;QAAE,MAAM,IAAI,SAAS,CAAC,qBAAqB,CAAC,CAAC;KAAE;IAC3D,WAAW,GAAG,IAAI,CAAC;AACvB,CAAC,CAAA;AACD,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC"} \ No newline at end of file diff --git a/lib.esm/crypto/pbkdf2.d.ts b/lib.esm/crypto/pbkdf2.d.ts new file mode 100644 index 00000000..400e9744 --- /dev/null +++ b/lib.esm/crypto/pbkdf2.d.ts @@ -0,0 +1,35 @@ +/** + * A **Password-Based Key-Derivation Function** is designed to create + * a sequence of bytes suitible as a **key** from a human-rememberable + * password. + * + * @_subsection: api/crypto:Passwords [about-pbkdf] + */ +import type { BytesLike } from "../utils/index.js"; +/** + * Return the [[link-pbkdf2]] for %%keylen%% bytes for %%password%% using + * the %%salt%% and using %%iterations%% of %%algo%%. + * + * This PBKDF is outdated and should not be used in new projects, but is + * required to decrypt older files. + * + * @example: + * // The password must be converted to bytes, and it is generally + * // best practices to ensure the string has been normalized. Many + * // formats explicitly indicate the normalization form to use. + * password = "hello" + * passwordBytes = toUtf8Bytes(password, "NFKC") + * + * salt = id("some-salt") + * + * // Compute the PBKDF2 + * pbkdf2(passwordBytes, salt, 1024, 16, "sha256") + * //_result: + */ +export declare function pbkdf2(_password: BytesLike, _salt: BytesLike, iterations: number, keylen: number, algo: "sha256" | "sha512"): string; +export declare namespace pbkdf2 { + var _: (password: Uint8Array, salt: Uint8Array, iterations: number, keylen: number, algo: "sha256" | "sha512") => BytesLike; + var lock: () => void; + var register: (func: (password: Uint8Array, salt: Uint8Array, iterations: number, keylen: number, algo: "sha256" | "sha512") => BytesLike) => void; +} +//# sourceMappingURL=pbkdf2.d.ts.map \ No newline at end of file diff --git a/lib.esm/crypto/pbkdf2.d.ts.map b/lib.esm/crypto/pbkdf2.d.ts.map new file mode 100644 index 00000000..f869e13c --- /dev/null +++ b/lib.esm/crypto/pbkdf2.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"pbkdf2.d.ts","sourceRoot":"","sources":["../../src.ts/crypto/pbkdf2.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAWnD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,MAAM,CAAC,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAIpI;yBAJe,MAAM"} \ No newline at end of file diff --git a/lib.esm/crypto/pbkdf2.js b/lib.esm/crypto/pbkdf2.js new file mode 100644 index 00000000..be6178e1 --- /dev/null +++ b/lib.esm/crypto/pbkdf2.js @@ -0,0 +1,49 @@ +/** + * A **Password-Based Key-Derivation Function** is designed to create + * a sequence of bytes suitible as a **key** from a human-rememberable + * password. + * + * @_subsection: api/crypto:Passwords [about-pbkdf] + */ +import { pbkdf2Sync } from "./crypto.js"; +import { getBytes, hexlify } from "../utils/index.js"; +let locked = false; +const _pbkdf2 = function (password, salt, iterations, keylen, algo) { + return pbkdf2Sync(password, salt, iterations, keylen, algo); +}; +let __pbkdf2 = _pbkdf2; +/** + * Return the [[link-pbkdf2]] for %%keylen%% bytes for %%password%% using + * the %%salt%% and using %%iterations%% of %%algo%%. + * + * This PBKDF is outdated and should not be used in new projects, but is + * required to decrypt older files. + * + * @example: + * // The password must be converted to bytes, and it is generally + * // best practices to ensure the string has been normalized. Many + * // formats explicitly indicate the normalization form to use. + * password = "hello" + * passwordBytes = toUtf8Bytes(password, "NFKC") + * + * salt = id("some-salt") + * + * // Compute the PBKDF2 + * pbkdf2(passwordBytes, salt, 1024, 16, "sha256") + * //_result: + */ +export function pbkdf2(_password, _salt, iterations, keylen, algo) { + const password = getBytes(_password, "password"); + const salt = getBytes(_salt, "salt"); + return hexlify(__pbkdf2(password, salt, iterations, keylen, algo)); +} +pbkdf2._ = _pbkdf2; +pbkdf2.lock = function () { locked = true; }; +pbkdf2.register = function (func) { + if (locked) { + throw new Error("pbkdf2 is locked"); + } + __pbkdf2 = func; +}; +Object.freeze(pbkdf2); +//# sourceMappingURL=pbkdf2.js.map \ No newline at end of file diff --git a/lib.esm/crypto/pbkdf2.js.map b/lib.esm/crypto/pbkdf2.js.map new file mode 100644 index 00000000..59df8bca --- /dev/null +++ b/lib.esm/crypto/pbkdf2.js.map @@ -0,0 +1 @@ +{"version":3,"file":"pbkdf2.js","sourceRoot":"","sources":["../../src.ts/crypto/pbkdf2.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAKtD,IAAI,MAAM,GAAG,KAAK,CAAC;AAEnB,MAAM,OAAO,GAAG,UAAS,QAAoB,EAAE,IAAgB,EAAE,UAAkB,EAAE,MAAc,EAAE,IAAyB;IAC1H,OAAO,UAAU,CAAC,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;AAChE,CAAC,CAAA;AAED,IAAI,QAAQ,GAAG,OAAO,CAAC;AAEvB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,MAAM,CAAC,SAAoB,EAAE,KAAgB,EAAE,UAAkB,EAAE,MAAc,EAAE,IAAyB;IACxH,MAAM,QAAQ,GAAG,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IACjD,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACrC,OAAO,OAAO,CAAC,QAAQ,CAAC,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;AACvE,CAAC;AACD,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC;AACnB,MAAM,CAAC,IAAI,GAAG,cAAmB,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;AACjD,MAAM,CAAC,QAAQ,GAAG,UAAS,IAA0H;IACjJ,IAAI,MAAM,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;KAAE;IACpD,QAAQ,GAAG,IAAI,CAAC;AACpB,CAAC,CAAA;AACD,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC"} \ No newline at end of file diff --git a/lib.esm/crypto/random.d.ts b/lib.esm/crypto/random.d.ts new file mode 100644 index 00000000..fd937800 --- /dev/null +++ b/lib.esm/crypto/random.d.ts @@ -0,0 +1,14 @@ +/** + * Return %%length%% bytes of cryptographically secure random data. + * + * @example: + * randomBytes(8) + * //_result: + */ +export declare function randomBytes(length: number): Uint8Array; +export declare namespace randomBytes { + var _: (length: number) => Uint8Array; + var lock: () => void; + var register: (func: (length: number) => Uint8Array) => void; +} +//# sourceMappingURL=random.d.ts.map \ No newline at end of file diff --git a/lib.esm/crypto/random.d.ts.map b/lib.esm/crypto/random.d.ts.map new file mode 100644 index 00000000..a907fd7e --- /dev/null +++ b/lib.esm/crypto/random.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../../src.ts/crypto/random.ts"],"names":[],"mappings":"AAkBA;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAEtD;yBAFe,WAAW"} \ No newline at end of file diff --git a/lib.esm/crypto/random.js b/lib.esm/crypto/random.js new file mode 100644 index 00000000..206a822f --- /dev/null +++ b/lib.esm/crypto/random.js @@ -0,0 +1,34 @@ +/** + * A **Cryptographically Secure Random Value** is one that has been + * generated with additional care take to prevent side-channels + * from allowing others to detect it and prevent others from through + * coincidence generate the same values. + * + * @_subsection: api/crypto:Random Values [about-crypto-random] + */ +import { randomBytes as crypto_random } from "./crypto.js"; +let locked = false; +const _randomBytes = function (length) { + return new Uint8Array(crypto_random(length)); +}; +let __randomBytes = _randomBytes; +/** + * Return %%length%% bytes of cryptographically secure random data. + * + * @example: + * randomBytes(8) + * //_result: + */ +export function randomBytes(length) { + return __randomBytes(length); +} +randomBytes._ = _randomBytes; +randomBytes.lock = function () { locked = true; }; +randomBytes.register = function (func) { + if (locked) { + throw new Error("randomBytes is locked"); + } + __randomBytes = func; +}; +Object.freeze(randomBytes); +//# sourceMappingURL=random.js.map \ No newline at end of file diff --git a/lib.esm/crypto/random.js.map b/lib.esm/crypto/random.js.map new file mode 100644 index 00000000..f857d174 --- /dev/null +++ b/lib.esm/crypto/random.js.map @@ -0,0 +1 @@ +{"version":3,"file":"random.js","sourceRoot":"","sources":["../../src.ts/crypto/random.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,WAAW,IAAI,aAAa,EAAE,MAAM,aAAa,CAAC;AAE3D,IAAI,MAAM,GAAG,KAAK,CAAC;AAEnB,MAAM,YAAY,GAAG,UAAS,MAAc;IACxC,OAAO,IAAI,UAAU,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;AACjD,CAAC,CAAA;AAED,IAAI,aAAa,GAAG,YAAY,CAAC;AAEjC;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,MAAc;IACtC,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC;AACjC,CAAC;AAED,WAAW,CAAC,CAAC,GAAG,YAAY,CAAC;AAC7B,WAAW,CAAC,IAAI,GAAG,cAAmB,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;AACtD,WAAW,CAAC,QAAQ,GAAG,UAAS,IAAoC;IAChE,IAAI,MAAM,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;KAAE;IACzD,aAAa,GAAG,IAAI,CAAC;AACzB,CAAC,CAAA;AACD,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC"} \ No newline at end of file diff --git a/lib.esm/crypto/ripemd160.d.ts b/lib.esm/crypto/ripemd160.d.ts new file mode 100644 index 00000000..27b7b4a1 --- /dev/null +++ b/lib.esm/crypto/ripemd160.d.ts @@ -0,0 +1,25 @@ +import type { BytesLike } from "../utils/index.js"; +/** + * Compute the cryptographic RIPEMD-160 hash of %%data%%. + * + * @_docloc: api/crypto:Hash Functions + * @returns DataHexstring + * + * @example: + * ripemd160("0x") + * //_result: + * + * ripemd160("0x1337") + * //_result: + * + * ripemd160(new Uint8Array([ 0x13, 0x37 ])) + * //_result: + * + */ +export declare function ripemd160(_data: BytesLike): string; +export declare namespace ripemd160 { + var _: (data: Uint8Array) => Uint8Array; + var lock: () => void; + var register: (func: (data: Uint8Array) => BytesLike) => void; +} +//# sourceMappingURL=ripemd160.d.ts.map \ No newline at end of file diff --git a/lib.esm/crypto/ripemd160.d.ts.map b/lib.esm/crypto/ripemd160.d.ts.map new file mode 100644 index 00000000..03f10806 --- /dev/null +++ b/lib.esm/crypto/ripemd160.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"ripemd160.d.ts","sourceRoot":"","sources":["../../src.ts/crypto/ripemd160.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAWnD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,CAGlD;yBAHe,SAAS"} \ No newline at end of file diff --git a/lib.esm/crypto/ripemd160.js b/lib.esm/crypto/ripemd160.js new file mode 100644 index 00000000..b305569e --- /dev/null +++ b/lib.esm/crypto/ripemd160.js @@ -0,0 +1,38 @@ +import { ripemd160 as noble_ripemd160 } from "@noble/hashes/ripemd160"; +import { getBytes, hexlify } from "../utils/index.js"; +let locked = false; +const _ripemd160 = function (data) { + return noble_ripemd160(data); +}; +let __ripemd160 = _ripemd160; +/** + * Compute the cryptographic RIPEMD-160 hash of %%data%%. + * + * @_docloc: api/crypto:Hash Functions + * @returns DataHexstring + * + * @example: + * ripemd160("0x") + * //_result: + * + * ripemd160("0x1337") + * //_result: + * + * ripemd160(new Uint8Array([ 0x13, 0x37 ])) + * //_result: + * + */ +export function ripemd160(_data) { + const data = getBytes(_data, "data"); + return hexlify(__ripemd160(data)); +} +ripemd160._ = _ripemd160; +ripemd160.lock = function () { locked = true; }; +ripemd160.register = function (func) { + if (locked) { + throw new TypeError("ripemd160 is locked"); + } + __ripemd160 = func; +}; +Object.freeze(ripemd160); +//# sourceMappingURL=ripemd160.js.map \ No newline at end of file diff --git a/lib.esm/crypto/ripemd160.js.map b/lib.esm/crypto/ripemd160.js.map new file mode 100644 index 00000000..f9961fe3 --- /dev/null +++ b/lib.esm/crypto/ripemd160.js.map @@ -0,0 +1 @@ +{"version":3,"file":"ripemd160.js","sourceRoot":"","sources":["../../src.ts/crypto/ripemd160.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAEvE,OAAO,EAAE,QAAQ,EAAG,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAKvD,IAAI,MAAM,GAAG,KAAK,CAAC;AAEnB,MAAM,UAAU,GAAG,UAAS,IAAgB;IACxC,OAAO,eAAe,CAAC,IAAI,CAAC,CAAC;AACjC,CAAC,CAAA;AAED,IAAI,WAAW,GAAoC,UAAU,CAAC;AAE9D;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,SAAS,CAAC,KAAgB;IACtC,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACrC,OAAO,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;AACtC,CAAC;AACD,SAAS,CAAC,CAAC,GAAG,UAAU,CAAC;AACzB,SAAS,CAAC,IAAI,GAAG,cAAmB,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;AACpD,SAAS,CAAC,QAAQ,GAAG,UAAS,IAAqC;IAC/D,IAAI,MAAM,EAAE;QAAE,MAAM,IAAI,SAAS,CAAC,qBAAqB,CAAC,CAAC;KAAE;IAC3D,WAAW,GAAG,IAAI,CAAC;AACvB,CAAC,CAAA;AACD,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC"} \ No newline at end of file diff --git a/lib.esm/crypto/scrypt.d.ts b/lib.esm/crypto/scrypt.d.ts new file mode 100644 index 00000000..b0e678f5 --- /dev/null +++ b/lib.esm/crypto/scrypt.d.ts @@ -0,0 +1,82 @@ +import type { BytesLike } from "../utils/index.js"; +/** + * A callback during long-running operations to update any + * UI or provide programatic access to the progress. + * + * The %%percent%% is a value between ``0`` and ``1``. + * + * @_docloc: api/crypto:Passwords + */ +export type ProgressCallback = (percent: number) => void; +/** + * The [[link-wiki-scrypt]] uses a memory and cpu hard method of + * derivation to increase the resource cost to brute-force a password + * for a given key. + * + * This means this algorithm is intentionally slow, and can be tuned to + * become slower. As computation and memory speed improve over time, + * increasing the difficulty maintains the cost of an attacker. + * + * For example, if a target time of 5 seconds is used, a legitimate user + * which knows their password requires only 5 seconds to unlock their + * account. A 6 character password has 68 billion possibilities, which + * would require an attacker to invest over 10,000 years of CPU time. This + * is of course a crude example (as password generally aren't random), + * but demonstrates to value of imposing large costs to decryption. + * + * For this reason, if building a UI which involved decrypting or + * encrypting datsa using scrypt, it is recommended to use a + * [[ProgressCallback]] (as event short periods can seem lik an eternity + * if the UI freezes). Including the phrase //"decrypting"// in the UI + * can also help, assuring the user their waiting is for a good reason. + * + * @_docloc: api/crypto:Passwords + * + * @example: + * // The password must be converted to bytes, and it is generally + * // best practices to ensure the string has been normalized. Many + * // formats explicitly indicate the normalization form to use. + * password = "hello" + * passwordBytes = toUtf8Bytes(password, "NFKC") + * + * salt = id("some-salt") + * + * // Compute the scrypt + * scrypt(passwordBytes, salt, 1024, 8, 1, 16) + * //_result: + */ +export declare function scrypt(_passwd: BytesLike, _salt: BytesLike, N: number, r: number, p: number, dkLen: number, progress?: ProgressCallback): Promise; +export declare namespace scrypt { + var _: (passwd: Uint8Array, salt: Uint8Array, N: number, r: number, p: number, dkLen: number, onProgress?: ProgressCallback | undefined) => Promise; + var lock: () => void; + var register: (func: (passwd: Uint8Array, salt: Uint8Array, N: number, r: number, p: number, dkLen: number, progress?: ProgressCallback | undefined) => Promise) => void; +} +/** + * Provides a synchronous variant of [[scrypt]]. + * + * This will completely lock up and freeze the UI in a browser and will + * prevent any event loop from progressing. For this reason, it is + * preferred to use the [async variant](scrypt). + * + * @_docloc: api/crypto:Passwords + * + * @example: + * // The password must be converted to bytes, and it is generally + * // best practices to ensure the string has been normalized. Many + * // formats explicitly indicate the normalization form to use. + * password = "hello" + * passwordBytes = toUtf8Bytes(password, "NFKC") + * + * salt = id("some-salt") + * + * // Compute the scrypt + * scryptSync(passwordBytes, salt, 1024, 8, 1, 16) + * //_result: + */ +export declare function scryptSync(_passwd: BytesLike, _salt: BytesLike, N: number, r: number, p: number, dkLen: number): string; +export declare namespace scryptSync { + var _: (passwd: Uint8Array, salt: Uint8Array, N: number, r: number, p: number, dkLen: number) => Uint8Array; + var lock: () => void; + var register: (func: (passwd: Uint8Array, salt: Uint8Array, N: number, r: number, p: number, dkLen: number) => BytesLike) => void; +} +//# sourceMappingURL=scrypt.d.ts.map \ No newline at end of file diff --git a/lib.esm/crypto/scrypt.d.ts.map b/lib.esm/crypto/scrypt.d.ts.map new file mode 100644 index 00000000..af193f1a --- /dev/null +++ b/lib.esm/crypto/scrypt.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"scrypt.d.ts","sourceRoot":"","sources":["../../src.ts/crypto/scrypt.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD;;;;;;;GAOG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;AAgBzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAsB,MAAM,CAAC,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,CAI/J;yBAJqB,MAAM;;;;;AAa5B;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAIvH;yBAJe,UAAU"} \ No newline at end of file diff --git a/lib.esm/crypto/scrypt.js b/lib.esm/crypto/scrypt.js new file mode 100644 index 00000000..61cad403 --- /dev/null +++ b/lib.esm/crypto/scrypt.js @@ -0,0 +1,99 @@ +import { scrypt as _nobleSync, scryptAsync as _nobleAsync } from "@noble/hashes/scrypt"; +import { getBytes, hexlify as H } from "../utils/index.js"; +let lockedSync = false, lockedAsync = false; +const _scryptAsync = async function (passwd, salt, N, r, p, dkLen, onProgress) { + return await _nobleAsync(passwd, salt, { N, r, p, dkLen, onProgress }); +}; +const _scryptSync = function (passwd, salt, N, r, p, dkLen) { + return _nobleSync(passwd, salt, { N, r, p, dkLen }); +}; +let __scryptAsync = _scryptAsync; +let __scryptSync = _scryptSync; +/** + * The [[link-wiki-scrypt]] uses a memory and cpu hard method of + * derivation to increase the resource cost to brute-force a password + * for a given key. + * + * This means this algorithm is intentionally slow, and can be tuned to + * become slower. As computation and memory speed improve over time, + * increasing the difficulty maintains the cost of an attacker. + * + * For example, if a target time of 5 seconds is used, a legitimate user + * which knows their password requires only 5 seconds to unlock their + * account. A 6 character password has 68 billion possibilities, which + * would require an attacker to invest over 10,000 years of CPU time. This + * is of course a crude example (as password generally aren't random), + * but demonstrates to value of imposing large costs to decryption. + * + * For this reason, if building a UI which involved decrypting or + * encrypting datsa using scrypt, it is recommended to use a + * [[ProgressCallback]] (as event short periods can seem lik an eternity + * if the UI freezes). Including the phrase //"decrypting"// in the UI + * can also help, assuring the user their waiting is for a good reason. + * + * @_docloc: api/crypto:Passwords + * + * @example: + * // The password must be converted to bytes, and it is generally + * // best practices to ensure the string has been normalized. Many + * // formats explicitly indicate the normalization form to use. + * password = "hello" + * passwordBytes = toUtf8Bytes(password, "NFKC") + * + * salt = id("some-salt") + * + * // Compute the scrypt + * scrypt(passwordBytes, salt, 1024, 8, 1, 16) + * //_result: + */ +export async function scrypt(_passwd, _salt, N, r, p, dkLen, progress) { + const passwd = getBytes(_passwd, "passwd"); + const salt = getBytes(_salt, "salt"); + return H(await __scryptAsync(passwd, salt, N, r, p, dkLen, progress)); +} +scrypt._ = _scryptAsync; +scrypt.lock = function () { lockedAsync = true; }; +scrypt.register = function (func) { + if (lockedAsync) { + throw new Error("scrypt is locked"); + } + __scryptAsync = func; +}; +Object.freeze(scrypt); +/** + * Provides a synchronous variant of [[scrypt]]. + * + * This will completely lock up and freeze the UI in a browser and will + * prevent any event loop from progressing. For this reason, it is + * preferred to use the [async variant](scrypt). + * + * @_docloc: api/crypto:Passwords + * + * @example: + * // The password must be converted to bytes, and it is generally + * // best practices to ensure the string has been normalized. Many + * // formats explicitly indicate the normalization form to use. + * password = "hello" + * passwordBytes = toUtf8Bytes(password, "NFKC") + * + * salt = id("some-salt") + * + * // Compute the scrypt + * scryptSync(passwordBytes, salt, 1024, 8, 1, 16) + * //_result: + */ +export function scryptSync(_passwd, _salt, N, r, p, dkLen) { + const passwd = getBytes(_passwd, "passwd"); + const salt = getBytes(_salt, "salt"); + return H(__scryptSync(passwd, salt, N, r, p, dkLen)); +} +scryptSync._ = _scryptSync; +scryptSync.lock = function () { lockedSync = true; }; +scryptSync.register = function (func) { + if (lockedSync) { + throw new Error("scryptSync is locked"); + } + __scryptSync = func; +}; +Object.freeze(scryptSync); +//# sourceMappingURL=scrypt.js.map \ No newline at end of file diff --git a/lib.esm/crypto/scrypt.js.map b/lib.esm/crypto/scrypt.js.map new file mode 100644 index 00000000..49df708d --- /dev/null +++ b/lib.esm/crypto/scrypt.js.map @@ -0,0 +1 @@ +{"version":3,"file":"scrypt.js","sourceRoot":"","sources":["../../src.ts/crypto/scrypt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,WAAW,IAAI,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAExF,OAAO,EAAE,QAAQ,EAAE,OAAO,IAAI,CAAC,EAAE,MAAM,mBAAmB,CAAC;AAe3D,IAAI,UAAU,GAAG,KAAK,EAAE,WAAW,GAAG,KAAK,CAAC;AAE5C,MAAM,YAAY,GAAG,KAAK,WAAU,MAAkB,EAAE,IAAgB,EAAE,CAAS,EAAE,CAAS,EAAE,CAAS,EAAE,KAAa,EAAE,UAA6B;IACnJ,OAAO,MAAM,WAAW,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,CAAC;AAC3E,CAAC,CAAA;AACD,MAAM,WAAW,GAAG,UAAS,MAAkB,EAAE,IAAgB,EAAE,CAAS,EAAE,CAAS,EAAE,CAAS,EAAE,KAAa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C,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACrC,OAAO,CAAC,CAAC,YAAY,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;AACzD,CAAC;AACD,UAAU,CAAC,CAAC,GAAG,WAAW,CAAC;AAC3B,UAAU,CAAC,IAAI,GAAG,cAAmB,UAAU,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;AACzD,UAAU,CAAC,QAAQ,GAAG,UAAS,IAAyG;IACpI,IAAI,UAAU,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;KAAE;IAC5D,YAAY,GAAG,IAAI,CAAC;AACxB,CAAC,CAAA;AACD,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC"} \ No newline at end of file diff --git a/lib.esm/crypto/sha2.d.ts b/lib.esm/crypto/sha2.d.ts new file mode 100644 index 00000000..348ccdc7 --- /dev/null +++ b/lib.esm/crypto/sha2.d.ts @@ -0,0 +1,47 @@ +import type { BytesLike } from "../utils/index.js"; +/** + * Compute the cryptographic SHA2-256 hash of %%data%%. + * + * @_docloc: api/crypto:Hash Functions + * @returns DataHexstring + * + * @example: + * sha256("0x") + * //_result: + * + * sha256("0x1337") + * //_result: + * + * sha256(new Uint8Array([ 0x13, 0x37 ])) + * //_result: + * + */ +export declare function sha256(_data: BytesLike): string; +export declare namespace sha256 { + var _: (data: Uint8Array) => Uint8Array; + var lock: () => void; + var register: (func: (data: Uint8Array) => BytesLike) => void; +} +/** + * Compute the cryptographic SHA2-512 hash of %%data%%. + * + * @_docloc: api/crypto:Hash Functions + * @returns DataHexstring + * + * @example: + * sha512("0x") + * //_result: + * + * sha512("0x1337") + * //_result: + * + * sha512(new Uint8Array([ 0x13, 0x37 ])) + * //_result: + */ +export declare function sha512(_data: BytesLike): string; +export declare namespace sha512 { + var _: (data: Uint8Array) => Uint8Array; + var lock: () => void; + var register: (func: (data: Uint8Array) => BytesLike) => void; +} +//# sourceMappingURL=sha2.d.ts.map \ No newline at end of file diff --git a/lib.esm/crypto/sha2.d.ts.map b/lib.esm/crypto/sha2.d.ts.map new file mode 100644 index 00000000..9e42678e --- /dev/null +++ b/lib.esm/crypto/sha2.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"sha2.d.ts","sourceRoot":"","sources":["../../src.ts/crypto/sha2.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAiBnD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,CAG/C;yBAHe,MAAM;;;;;AAatB;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,CAG/C;yBAHe,MAAM"} \ No newline at end of file diff --git a/lib.esm/crypto/sha2.js b/lib.esm/crypto/sha2.js new file mode 100644 index 00000000..f84145b4 --- /dev/null +++ b/lib.esm/crypto/sha2.js @@ -0,0 +1,71 @@ +import { createHash } from "./crypto.js"; +import { getBytes, hexlify } from "../utils/index.js"; +const _sha256 = function (data) { + return createHash("sha256").update(data).digest(); +}; +const _sha512 = function (data) { + return createHash("sha512").update(data).digest(); +}; +let __sha256 = _sha256; +let __sha512 = _sha512; +let locked256 = false, locked512 = false; +/** + * Compute the cryptographic SHA2-256 hash of %%data%%. + * + * @_docloc: api/crypto:Hash Functions + * @returns DataHexstring + * + * @example: + * sha256("0x") + * //_result: + * + * sha256("0x1337") + * //_result: + * + * sha256(new Uint8Array([ 0x13, 0x37 ])) + * //_result: + * + */ +export function sha256(_data) { + const data = getBytes(_data, "data"); + return hexlify(__sha256(data)); +} +sha256._ = _sha256; +sha256.lock = function () { locked256 = true; }; +sha256.register = function (func) { + if (locked256) { + throw new Error("sha256 is locked"); + } + __sha256 = func; +}; +Object.freeze(sha256); +/** + * Compute the cryptographic SHA2-512 hash of %%data%%. + * + * @_docloc: api/crypto:Hash Functions + * @returns DataHexstring + * + * @example: + * sha512("0x") + * //_result: + * + * sha512("0x1337") + * //_result: + * + * sha512(new Uint8Array([ 0x13, 0x37 ])) + * //_result: + */ +export function sha512(_data) { + const data = getBytes(_data, "data"); + return hexlify(__sha512(data)); +} +sha512._ = _sha512; +sha512.lock = function () { locked512 = true; }; +sha512.register = function (func) { + if (locked512) { + throw new Error("sha512 is locked"); + } + __sha512 = func; +}; +Object.freeze(sha256); +//# sourceMappingURL=sha2.js.map \ No newline at end of file diff --git a/lib.esm/crypto/sha2.js.map b/lib.esm/crypto/sha2.js.map new file mode 100644 index 00000000..674e5889 --- /dev/null +++ b/lib.esm/crypto/sha2.js.map @@ -0,0 +1 @@ +{"version":3,"file":"sha2.js","sourceRoot":"","sources":["../../src.ts/crypto/sha2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAKtD,MAAM,OAAO,GAAG,UAAS,IAAgB;IACrC,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;AACtD,CAAC,CAAA;AAED,MAAM,OAAO,GAAG,UAAS,IAAgB;IACrC,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;AACtD,CAAC,CAAA;AAED,IAAI,QAAQ,GAAoC,OAAO,CAAC;AACxD,IAAI,QAAQ,GAAoC,OAAO,CAAC;AAExD,IAAI,SAAS,GAAG,KAAK,EAAE,SAAS,GAAG,KAAK,CAAC;AAGzC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,MAAM,CAAC,KAAgB;IACnC,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACrC,OAAO,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;AACnC,CAAC;AACD,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC;AACnB,MAAM,CAAC,IAAI,GAAG,cAAmB,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;AACpD,MAAM,CAAC,QAAQ,GAAG,UAAS,IAAqC;IAC5D,IAAI,SAAS,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;KAAE;IACvD,QAAQ,GAAG,IAAI,CAAC;AACpB,CAAC,CAAA;AACD,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAGtB;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,MAAM,CAAC,KAAgB;IACnC,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACrC,OAAO,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;AACnC,CAAC;AACD,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC;AACnB,MAAM,CAAC,IAAI,GAAG,cAAmB,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;AACpD,MAAM,CAAC,QAAQ,GAAG,UAAS,IAAqC;IAC5D,IAAI,SAAS,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;KAAE;IACvD,QAAQ,GAAG,IAAI,CAAC;AACpB,CAAC,CAAA;AACD,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC"} \ No newline at end of file diff --git a/lib.esm/crypto/signature.d.ts b/lib.esm/crypto/signature.d.ts new file mode 100644 index 00000000..8cfe9666 --- /dev/null +++ b/lib.esm/crypto/signature.d.ts @@ -0,0 +1,158 @@ +import type { BigNumberish, BytesLike } from "../utils/index.js"; +/** + * A SignatureLike + * + * @_docloc: api/crypto:Signing + */ +export type SignatureLike = Signature | string | { + r: string; + s: string; + v: BigNumberish; + yParity?: 0 | 1; + yParityAndS?: string; +} | { + r: string; + yParityAndS: string; + yParity?: 0 | 1; + s?: string; + v?: number; +} | { + r: string; + s: string; + yParity: 0 | 1; + v?: BigNumberish; + yParityAndS?: string; +}; +/** + * A Signature @TODO + * + * + * @_docloc: api/crypto:Signing + */ +export declare class Signature { + #private; + /** + * The ``r`` value for a signautre. + * + * This represents the ``x`` coordinate of a "reference" or + * challenge point, from which the ``y`` can be computed. + */ + get r(): string; + set r(value: BytesLike); + /** + * The ``s`` value for a signature. + */ + get s(): string; + set s(_value: BytesLike); + /** + * The ``v`` value for a signature. + * + * Since a given ``x`` value for ``r`` has two possible values for + * its correspondin ``y``, the ``v`` indicates which of the two ``y`` + * values to use. + * + * It is normalized to the values ``27`` or ``28`` for legacy + * purposes. + */ + get v(): 27 | 28; + set v(value: BigNumberish); + /** + * The EIP-155 ``v`` for legacy transactions. For non-legacy + * transactions, this value is ``null``. + */ + get networkV(): null | bigint; + /** + * The chain ID for EIP-155 legacy transactions. For non-legacy + * transactions, this value is ``null``. + */ + get legacyChainId(): null | bigint; + /** + * The ``yParity`` for the signature. + * + * See ``v`` for more details on how this value is used. + */ + get yParity(): 0 | 1; + /** + * The [[link-eip-2098]] compact representation of the ``yParity`` + * and ``s`` compacted into a single ``bytes32``. + */ + get yParityAndS(): string; + /** + * The [[link-eip-2098]] compact representation. + */ + get compactSerialized(): string; + /** + * The serialized representation. + */ + get serialized(): string; + /** + * @private + */ + constructor(guard: any, r: string, s: string, v: 27 | 28); + /** + * Returns a new identical [[Signature]]. + */ + clone(): Signature; + /** + * Returns a representation that is compatible with ``JSON.stringify``. + */ + toJSON(): any; + /** + * Compute the chain ID from the ``v`` in a legacy EIP-155 transactions. + * + * @example: + * Signature.getChainId(45) + * //_result: + * + * Signature.getChainId(46) + * //_result: + */ + static getChainId(v: BigNumberish): bigint; + /** + * Compute the ``v`` for a chain ID for a legacy EIP-155 transactions. + * + * Legacy transactions which use [[link-eip-155]] hijack the ``v`` + * property to include the chain ID. + * + * @example: + * Signature.getChainIdV(5, 27) + * //_result: + * + * Signature.getChainIdV(5, 28) + * //_result: + * + */ + static getChainIdV(chainId: BigNumberish, v: 27 | 28): bigint; + /** + * Compute the normalized legacy transaction ``v`` from a ``yParirty``, + * a legacy transaction ``v`` or a legacy [[link-eip-155]] transaction. + * + * @example: + * // The values 0 and 1 imply v is actually yParity + * Signature.getNormalizedV(0) + * //_result: + * + * // Legacy non-EIP-1559 transaction (i.e. 27 or 28) + * Signature.getNormalizedV(27) + * //_result: + * + * // Legacy EIP-155 transaction (i.e. >= 35) + * Signature.getNormalizedV(46) + * //_result: + * + * // Invalid values throw + * Signature.getNormalizedV(5) + * //_error: + */ + static getNormalizedV(v: BigNumberish): 27 | 28; + /** + * Creates a new [[Signature]]. + * + * If no %%sig%% is provided, a new [[Signature]] is created + * with default values. + * + * If %%sig%% is a string, it is parsed. + */ + static from(sig?: SignatureLike): Signature; +} +//# sourceMappingURL=signature.d.ts.map \ No newline at end of file diff --git a/lib.esm/crypto/signature.d.ts.map b/lib.esm/crypto/signature.d.ts.map new file mode 100644 index 00000000..a049cf5e --- /dev/null +++ b/lib.esm/crypto/signature.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"signature.d.ts","sourceRoot":"","sources":["../../src.ts/crypto/signature.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACR,YAAY,EAAE,SAAS,EAC1B,MAAM,mBAAmB,CAAC;AAgB3B;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,MAAM,GAAG;IAC7C,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,YAAY,CAAC;IAChB,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB,GAAG;IACA,CAAC,EAAE,MAAM,CAAC;IACV,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EA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AE,YAAY,GAAG,MAAM;IAY1C;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,YAAY,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,MAAM;IAI7D;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,MAAM,CAAC,cAAc,CAAC,CAAC,EAAE,YAAY,GAAG,EAAE,GAAG,EAAE;IAY/C;;;;;;;OAOG;IACH,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,aAAa,GAAG,SAAS;CAuF9C"} \ No newline at end of file diff --git a/lib.esm/crypto/signature.js b/lib.esm/crypto/signature.js new file mode 100644 index 00000000..5e91b7b6 --- /dev/null +++ b/lib.esm/crypto/signature.js @@ -0,0 +1,301 @@ +import { ZeroHash } from "../constants/index.js"; +import { concat, dataLength, getBigInt, getBytes, getNumber, hexlify, toBeArray, isHexString, zeroPadValue, assertArgument, assertPrivate } from "../utils/index.js"; +// Constants +const BN_0 = BigInt(0); +const BN_1 = BigInt(1); +const BN_2 = BigInt(2); +const BN_27 = BigInt(27); +const BN_28 = BigInt(28); +const BN_35 = BigInt(35); +const _guard = {}; +function toUint256(value) { + return zeroPadValue(toBeArray(value), 32); +} +/** + * A Signature @TODO + * + * + * @_docloc: api/crypto:Signing + */ +export class Signature { + #r; + #s; + #v; + #networkV; + /** + * The ``r`` value for a signautre. + * + * This represents the ``x`` coordinate of a "reference" or + * challenge point, from which the ``y`` can be computed. + */ + get r() { return this.#r; } + set r(value) { + assertArgument(dataLength(value) === 32, "invalid r", "value", value); + this.#r = hexlify(value); + } + /** + * The ``s`` value for a signature. + */ + get s() { return this.#s; } + set s(_value) { + assertArgument(dataLength(_value) === 32, "invalid s", "value", _value); + const value = hexlify(_value); + assertArgument(parseInt(value.substring(0, 3)) < 8, "non-canonical s", "value", value); + this.#s = value; + } + /** + * The ``v`` value for a signature. + * + * Since a given ``x`` value for ``r`` has two possible values for + * its correspondin ``y``, the ``v`` indicates which of the two ``y`` + * values to use. + * + * It is normalized to the values ``27`` or ``28`` for legacy + * purposes. + */ + get v() { return this.#v; } + set v(value) { + const v = getNumber(value, "value"); + assertArgument(v === 27 || v === 28, "invalid v", "v", value); + this.#v = v; + } + /** + * The EIP-155 ``v`` for legacy transactions. For non-legacy + * transactions, this value is ``null``. + */ + get networkV() { return this.#networkV; } + /** + * The chain ID for EIP-155 legacy transactions. For non-legacy + * transactions, this value is ``null``. + */ + get legacyChainId() { + const v = this.networkV; + if (v == null) { + return null; + } + return Signature.getChainId(v); + } + /** + * The ``yParity`` for the signature. + * + * See ``v`` for more details on how this value is used. + */ + get yParity() { + return (this.v === 27) ? 0 : 1; + } + /** + * The [[link-eip-2098]] compact representation of the ``yParity`` + * and ``s`` compacted into a single ``bytes32``. + */ + get yParityAndS() { + // The EIP-2098 compact representation + const yParityAndS = getBytes(this.s); + if (this.yParity) { + yParityAndS[0] |= 0x80; + } + return hexlify(yParityAndS); + } + /** + * The [[link-eip-2098]] compact representation. + */ + get compactSerialized() { + return concat([this.r, this.yParityAndS]); + } + /** + * The serialized representation. + */ + get serialized() { + return concat([this.r, this.s, (this.yParity ? "0x1c" : "0x1b")]); + } + /** + * @private + */ + constructor(guard, r, s, v) { + assertPrivate(guard, _guard, "Signature"); + this.#r = r; + this.#s = s; + this.#v = v; + this.#networkV = null; + } + [Symbol.for('nodejs.util.inspect.custom')]() { + return `Signature { r: "${this.r}", s: "${this.s}", yParity: ${this.yParity}, networkV: ${this.networkV} }`; + } + /** + * Returns a new identical [[Signature]]. + */ + clone() { + const clone = new Signature(_guard, this.r, this.s, this.v); + if (this.networkV) { + clone.#networkV = this.networkV; + } + return clone; + } + /** + * Returns a representation that is compatible with ``JSON.stringify``. + */ + toJSON() { + const networkV = this.networkV; + return { + _type: "signature", + networkV: ((networkV != null) ? networkV.toString() : null), + r: this.r, s: this.s, v: this.v, + }; + } + /** + * Compute the chain ID from the ``v`` in a legacy EIP-155 transactions. + * + * @example: + * Signature.getChainId(45) + * //_result: + * + * Signature.getChainId(46) + * //_result: + */ + static getChainId(v) { + const bv = getBigInt(v, "v"); + // The v is not an EIP-155 v, so it is the unspecified chain ID + if ((bv == BN_27) || (bv == BN_28)) { + return BN_0; + } + // Bad value for an EIP-155 v + assertArgument(bv >= BN_35, "invalid EIP-155 v", "v", v); + return (bv - BN_35) / BN_2; + } + /** + * Compute the ``v`` for a chain ID for a legacy EIP-155 transactions. + * + * Legacy transactions which use [[link-eip-155]] hijack the ``v`` + * property to include the chain ID. + * + * @example: + * Signature.getChainIdV(5, 27) + * //_result: + * + * Signature.getChainIdV(5, 28) + * //_result: + * + */ + static getChainIdV(chainId, v) { + return (getBigInt(chainId) * BN_2) + BigInt(35 + v - 27); + } + /** + * Compute the normalized legacy transaction ``v`` from a ``yParirty``, + * a legacy transaction ``v`` or a legacy [[link-eip-155]] transaction. + * + * @example: + * // The values 0 and 1 imply v is actually yParity + * Signature.getNormalizedV(0) + * //_result: + * + * // Legacy non-EIP-1559 transaction (i.e. 27 or 28) + * Signature.getNormalizedV(27) + * //_result: + * + * // Legacy EIP-155 transaction (i.e. >= 35) + * Signature.getNormalizedV(46) + * //_result: + * + * // Invalid values throw + * Signature.getNormalizedV(5) + * //_error: + */ + static getNormalizedV(v) { + const bv = getBigInt(v); + if (bv === BN_0 || bv === BN_27) { + return 27; + } + if (bv === BN_1 || bv === BN_28) { + return 28; + } + assertArgument(bv >= BN_35, "invalid v", "v", v); + // Otherwise, EIP-155 v means odd is 27 and even is 28 + return (bv & BN_1) ? 27 : 28; + } + /** + * Creates a new [[Signature]]. + * + * If no %%sig%% is provided, a new [[Signature]] is created + * with default values. + * + * If %%sig%% is a string, it is parsed. + */ + static from(sig) { + function assertError(check, message) { + assertArgument(check, message, "signature", sig); + } + ; + if (sig == null) { + return new Signature(_guard, ZeroHash, ZeroHash, 27); + } + if (typeof (sig) === "string") { + const bytes = getBytes(sig, "signature"); + if (bytes.length === 64) { + const r = hexlify(bytes.slice(0, 32)); + const s = bytes.slice(32, 64); + const v = (s[0] & 0x80) ? 28 : 27; + s[0] &= 0x7f; + return new Signature(_guard, r, hexlify(s), v); + } + if (bytes.length === 65) { + const r = hexlify(bytes.slice(0, 32)); + const s = bytes.slice(32, 64); + assertError((s[0] & 0x80) === 0, "non-canonical s"); + const v = Signature.getNormalizedV(bytes[64]); + return new Signature(_guard, r, hexlify(s), v); + } + assertError(false, "invalid raw signature length"); + } + if (sig instanceof Signature) { + return sig.clone(); + } + // Get r + const _r = sig.r; + assertError(_r != null, "missing r"); + const r = toUint256(_r); + // Get s; by any means necessary (we check consistency below) + const s = (function (s, yParityAndS) { + if (s != null) { + return toUint256(s); + } + if (yParityAndS != null) { + assertError(isHexString(yParityAndS, 32), "invalid yParityAndS"); + const bytes = getBytes(yParityAndS); + bytes[0] &= 0x7f; + return hexlify(bytes); + } + assertError(false, "missing s"); + })(sig.s, sig.yParityAndS); + assertError((getBytes(s)[0] & 0x80) == 0, "non-canonical s"); + // Get v; by any means necessary (we check consistency below) + const { networkV, v } = (function (_v, yParityAndS, yParity) { + if (_v != null) { + const v = getBigInt(_v); + return { + networkV: ((v >= BN_35) ? v : undefined), + v: Signature.getNormalizedV(v) + }; + } + if (yParityAndS != null) { + assertError(isHexString(yParityAndS, 32), "invalid yParityAndS"); + return { v: ((getBytes(yParityAndS)[0] & 0x80) ? 28 : 27) }; + } + if (yParity != null) { + switch (yParity) { + case 0: return { v: 27 }; + case 1: return { v: 28 }; + } + assertError(false, "invalid yParity"); + } + assertError(false, "missing v"); + })(sig.v, sig.yParityAndS, sig.yParity); + const result = new Signature(_guard, r, s, v); + if (networkV) { + result.#networkV = networkV; + } + // If multiple of v, yParity, yParityAndS we given, check they match + assertError(!("yParity" in sig && sig.yParity !== result.yParity), "yParity mismatch"); + assertError(!("yParityAndS" in sig && sig.yParityAndS !== result.yParityAndS), "yParityAndS mismatch"); + return result; + } +} +//# sourceMappingURL=signature.js.map \ No newline at end of file diff --git a/lib.esm/crypto/signature.js.map b/lib.esm/crypto/signature.js.map new file mode 100644 index 00000000..f11a5bd2 --- /dev/null +++ b/lib.esm/crypto/signature.js.map @@ -0,0 +1 @@ +{"version":3,"file":"signature.js","sourceRoot":"","sources":["../../src.ts/crypto/signature.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EACH,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAC3D,SAAS,EAAE,WAAW,EAAE,YAAY,EACpC,cAAc,EAAE,aAAa,EAChC,MAAM,mBAAmB,CAAC;AAO3B,YAAY;AACZ,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;AACvB,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;AACvB,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;AACvB,MAAM,KAAK,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;AACzB,MAAM,KAAK,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;AACzB,MAAM,KAAK,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;AAGzB,MAAM,MAAM,GAAG,EAAG,CAAC;AA6BnB,SAAS,SAAS,CAAC,KAAmB;IAClC,OAAO,YAAY,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;AAC9C,CAAC;AAED;;;;;GAKG;AACH,MAAM,OAAO,SAAS;IAClB,EAAE,CAAS;IACX,EAAE,CAAS;IACX,EAAE,CAAU;IACZ,SAAS,CAAgB;IAEzB;;;;;OAKG;IACH,IAAI,CAAC,KAAa,OAAO,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;IACnC,IAAI,CAAC,CAAC,KAAgB;QAClB,cAAc,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,EAAE,EAAE,WAAW,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;QACtE,IAAI,CAAC,EAAE,GAAG,O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ED,IAAI,OAAO,IAAI,IAAI,EAAE;gBACjB,QAAQ,OAAO,EAAE;oBACb,KAAK,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC;oBACzB,KAAK,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC;iBAC5B;gBACD,WAAW,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC;aACzC;YAED,WAAW,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;QACpC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,WAAW,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;QAExC,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAC9C,IAAI,QAAQ,EAAE;YAAE,MAAM,CAAC,SAAS,GAAI,QAAQ,CAAC;SAAE;QAE/C,oEAAoE;QACpE,WAAW,CAAC,CAAC,CAAC,SAAS,IAAI,GAAG,IAAI,GAAG,CAAC,OAAO,KAAK,MAAM,CAAC,OAAO,CAAC,EAAE,kBAAkB,CAAC,CAAC;QACvF,WAAW,CAAC,CAAC,CAAC,aAAa,IAAI,GAAG,IAAI,GAAG,CAAC,WAAW,KAAK,MAAM,CAAC,WAAW,CAAC,EAAE,sBAAsB,CAAC,CAAC;QAEvG,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ"} \ No newline at end of file diff --git a/lib.esm/crypto/signing-key.d.ts b/lib.esm/crypto/signing-key.d.ts new file mode 100644 index 00000000..0864d3b8 --- /dev/null +++ b/lib.esm/crypto/signing-key.d.ts @@ -0,0 +1,122 @@ +/** + * Add details about signing here. + * + * @_subsection: api/crypto:Signing [about-signing] + */ +import { Signature } from "./signature.js"; +import type { BytesLike } from "../utils/index.js"; +import type { SignatureLike } from "./index.js"; +/** + * A **SigningKey** provides high-level access to the elliptic curve + * cryptography (ECC) operations and key management. + */ +export declare class SigningKey { + #private; + /** + * Creates a new **SigningKey** for %%privateKey%%. + */ + constructor(privateKey: BytesLike); + /** + * The private key. + */ + get privateKey(): string; + /** + * The uncompressed public key. + * + * This will always begin with the prefix ``0x04`` and be 132 + * characters long (the ``0x`` prefix and 130 hexadecimal nibbles). + */ + get publicKey(): string; + /** + * The compressed public key. + * + * This will always begin with either the prefix ``0x02`` or ``0x03`` + * and be 68 characters long (the ``0x`` prefix and 33 hexadecimal + * nibbles) + */ + get compressedPublicKey(): string; + /** + * Return the signature of the signed %%digest%%. + */ + sign(digest: BytesLike): Signature; + /** + * Returns the [[link-wiki-ecdh]] shared secret between this + * private key and the %%other%% key. + * + * The %%other%% key may be any type of key, a raw public key, + * a compressed/uncompressed pubic key or aprivate key. + * + * Best practice is usually to use a cryptographic hash on the + * returned value before using it as a symetric secret. + * + * @example: + * sign1 = new SigningKey(id("some-secret-1")) + * sign2 = new SigningKey(id("some-secret-2")) + * + * // Notice that privA.computeSharedSecret(pubB)... + * sign1.computeSharedSecret(sign2.publicKey) + * //_result: + * + * // ...is equal to privB.computeSharedSecret(pubA). + * sign2.computeSharedSecret(sign1.publicKey) + * //_result: + */ + computeSharedSecret(other: BytesLike): string; + /** + * Compute the public key for %%key%%, optionally %%compressed%%. + * + * The %%key%% may be any type of key, a raw public key, a + * compressed/uncompressed public key or private key. + * + * @example: + * sign = new SigningKey(id("some-secret")); + * + * // Compute the uncompressed public key for a private key + * SigningKey.computePublicKey(sign.privateKey) + * //_result: + * + * // Compute the compressed public key for a private key + * SigningKey.computePublicKey(sign.privateKey, true) + * //_result: + * + * // Compute the uncompressed public key + * SigningKey.computePublicKey(sign.publicKey, false); + * //_result: + * + * // Compute the Compressed a public key + * SigningKey.computePublicKey(sign.publicKey, true); + * //_result: + */ + static computePublicKey(key: BytesLike, compressed?: boolean): string; + /** + * Returns the public key for the private key which produced the + * %%signature%% for the given %%digest%%. + * + * @example: + * key = new SigningKey(id("some-secret")) + * digest = id("hello world") + * sig = key.sign(digest) + * + * // Notice the signer public key... + * key.publicKey + * //_result: + * + * // ...is equal to the recovered public key + * SigningKey.recoverPublicKey(digest, sig) + * //_result: + * + */ + static recoverPublicKey(digest: BytesLike, signature: SignatureLike): string; + /** + * Returns the point resulting from adding the ellipic curve points + * %%p0%% and %%p1%%. + * + * This is not a common function most developers should require, but + * can be useful for certain privacy-specific techniques. + * + * For example, it is used by [[HDNodeWallet]] to compute child + * addresses from parent public keys and chain codes. + */ + static addPoints(p0: BytesLike, p1: BytesLike, compressed?: boolean): string; +} +//# sourceMappingURL=signing-key.d.ts.map \ No newline at end of file diff --git a/lib.esm/crypto/signing-key.d.ts.map b/lib.esm/crypto/signing-key.d.ts.map new file mode 100644 index 00000000..6ce11800 --- /dev/null +++ b/lib.esm/crypto/signing-key.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"signing-key.d.ts","sourceRoot":"","sources":["../../src.ts/crypto/signing-key.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AASH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGhD;;;GAGG;AACH,qBAAa,UAAU;;IAGnB;;OAEG;gBACS,UAAU,EAAE,SAAS;IAKjC;;OAEG;IACH,IAAI,UAAU,IAAI,MAAM,CAA6B;IAErD;;;;;OAKG;IACH,IAAI,SAAS,IAAI,MAAM,CAA0D;IAEjF;;;;;;OAMG;IACH,IAAI,mBAAmB,IAAI,MAAM,CAAgE;IAEjG;;OAEG;IACH,IAAI,CAAC,MAAM,EAAE,SAAS,GAAG,SAAS;IAclC;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,mBAAmB,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM;IAK7C;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,MAAM,CAAC,gBAAgB,CAAC,GAAG,EAAE,SAAS,EAAE,UAAU,CAAC,EAAE,OAAO,GAAG,MAAM;IAqBrE;;;;;;;;;;;;;;;;;OAiBG;IACH,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,aAAa,GAAG,MAAM;IAc5E;;;;;;;;;OASG;IACH,MAAM,CAAC,SAAS,CAAC,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,SAAS,EAAE,UAAU,CAAC,EAAE,OAAO,GAAG,MAAM;CAK/E"} \ No newline at end of file diff --git a/lib.esm/crypto/signing-key.js b/lib.esm/crypto/signing-key.js new file mode 100644 index 00000000..36ca61e3 --- /dev/null +++ b/lib.esm/crypto/signing-key.js @@ -0,0 +1,166 @@ +/** + * Add details about signing here. + * + * @_subsection: api/crypto:Signing [about-signing] + */ +import { secp256k1 } from "@noble/curves/secp256k1"; +import { concat, dataLength, getBytes, getBytesCopy, hexlify, toBeHex, assertArgument } from "../utils/index.js"; +import { Signature } from "./signature.js"; +/** + * A **SigningKey** provides high-level access to the elliptic curve + * cryptography (ECC) operations and key management. + */ +export class SigningKey { + #privateKey; + /** + * Creates a new **SigningKey** for %%privateKey%%. + */ + constructor(privateKey) { + assertArgument(dataLength(privateKey) === 32, "invalid private key", "privateKey", "[REDACTED]"); + this.#privateKey = hexlify(privateKey); + } + /** + * The private key. + */ + get privateKey() { return this.#privateKey; } + /** + * The uncompressed public key. + * + * This will always begin with the prefix ``0x04`` and be 132 + * characters long (the ``0x`` prefix and 130 hexadecimal nibbles). + */ + get publicKey() { return SigningKey.computePublicKey(this.#privateKey); } + /** + * The compressed public key. + * + * This will always begin with either the prefix ``0x02`` or ``0x03`` + * and be 68 characters long (the ``0x`` prefix and 33 hexadecimal + * nibbles) + */ + get compressedPublicKey() { return SigningKey.computePublicKey(this.#privateKey, true); } + /** + * Return the signature of the signed %%digest%%. + */ + sign(digest) { + assertArgument(dataLength(digest) === 32, "invalid digest length", "digest", digest); + const sig = secp256k1.sign(getBytesCopy(digest), getBytesCopy(this.#privateKey), { + lowS: true + }); + return Signature.from({ + r: toBeHex("0x" + sig.r.toString(16), 32), + s: toBeHex("0x" + sig.s.toString(16), 32), + v: (sig.recovery ? 0x1c : 0x1b) + }); + } + /** + * Returns the [[link-wiki-ecdh]] shared secret between this + * private key and the %%other%% key. + * + * The %%other%% key may be any type of key, a raw public key, + * a compressed/uncompressed pubic key or aprivate key. + * + * Best practice is usually to use a cryptographic hash on the + * returned value before using it as a symetric secret. + * + * @example: + * sign1 = new SigningKey(id("some-secret-1")) + * sign2 = new SigningKey(id("some-secret-2")) + * + * // Notice that privA.computeSharedSecret(pubB)... + * sign1.computeSharedSecret(sign2.publicKey) + * //_result: + * + * // ...is equal to privB.computeSharedSecret(pubA). + * sign2.computeSharedSecret(sign1.publicKey) + * //_result: + */ + computeSharedSecret(other) { + const pubKey = SigningKey.computePublicKey(other); + return hexlify(secp256k1.getSharedSecret(getBytesCopy(this.#privateKey), getBytes(pubKey), false)); + } + /** + * Compute the public key for %%key%%, optionally %%compressed%%. + * + * The %%key%% may be any type of key, a raw public key, a + * compressed/uncompressed public key or private key. + * + * @example: + * sign = new SigningKey(id("some-secret")); + * + * // Compute the uncompressed public key for a private key + * SigningKey.computePublicKey(sign.privateKey) + * //_result: + * + * // Compute the compressed public key for a private key + * SigningKey.computePublicKey(sign.privateKey, true) + * //_result: + * + * // Compute the uncompressed public key + * SigningKey.computePublicKey(sign.publicKey, false); + * //_result: + * + * // Compute the Compressed a public key + * SigningKey.computePublicKey(sign.publicKey, true); + * //_result: + */ + static computePublicKey(key, compressed) { + let bytes = getBytes(key, "key"); + // private key + if (bytes.length === 32) { + const pubKey = secp256k1.getPublicKey(bytes, !!compressed); + return hexlify(pubKey); + } + // raw public key; use uncompressed key with 0x04 prefix + if (bytes.length === 64) { + const pub = new Uint8Array(65); + pub[0] = 0x04; + pub.set(bytes, 1); + bytes = pub; + } + const point = secp256k1.ProjectivePoint.fromHex(bytes); + return hexlify(point.toRawBytes(compressed)); + } + /** + * Returns the public key for the private key which produced the + * %%signature%% for the given %%digest%%. + * + * @example: + * key = new SigningKey(id("some-secret")) + * digest = id("hello world") + * sig = key.sign(digest) + * + * // Notice the signer public key... + * key.publicKey + * //_result: + * + * // ...is equal to the recovered public key + * SigningKey.recoverPublicKey(digest, sig) + * //_result: + * + */ + static recoverPublicKey(digest, signature) { + assertArgument(dataLength(digest) === 32, "invalid digest length", "digest", digest); + const sig = Signature.from(signature); + let secpSig = secp256k1.Signature.fromCompact(getBytesCopy(concat([sig.r, sig.s]))); + secpSig = secpSig.addRecoveryBit(sig.yParity); + const pubKey = secpSig.recoverPublicKey(getBytesCopy(digest)); + assertArgument(pubKey != null, "invalid signautre for digest", "signature", signature); + return "0x" + pubKey.toHex(false); + } + /** + * Returns the point resulting from adding the ellipic curve points + * %%p0%% and %%p1%%. + * + * This is not a common function most developers should require, but + * can be useful for certain privacy-specific techniques. + * + * For example, it is used by [[HDNodeWallet]] to compute child + * addresses from parent public keys and chain codes. + */ + static addPoints(p0, p1, compressed) { + const pub0 = secp256k1.ProjectivePoint.fromHex(SigningKey.computePublicKey(p0).substring(2)); + const pub1 = secp256k1.ProjectivePoint.fromHex(SigningKey.computePublicKey(p1).substring(2)); + return "0x" + pub0.add(pub1).toHex(!!compressed); + } +} +//# sourceMappingURL=signing-key.js.map \ No newline at end of file diff --git a/lib.esm/crypto/signing-key.js.map b/lib.esm/crypto/signing-key.js.map new file mode 100644 index 00000000..0087baa2 --- /dev/null +++ b/lib.esm/crypto/signing-key.js.map @@ -0,0 +1 @@ +{"version":3,"file":"signing-key.js","sourceRoot":"","sources":["../../src.ts/crypto/signing-key.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EACH,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,EAC5D,cAAc,EACjB,MAAM,mBAAmB,CAAC;AA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ts new file mode 100644 index 00000000..8d5e0579 --- /dev/null +++ b/lib.esm/hash/id.d.ts @@ -0,0 +1,13 @@ +/** + * A simple hashing function which operates on UTF-8 strings to + * compute an 32-byte identifier. + * + * This simply computes the [UTF-8 bytes](toUtf8Bytes) and computes + * the [[keccak256]]. + * + * @example: + * id("hello world") + * //_result: + */ +export declare function id(value: string): string; +//# sourceMappingURL=id.d.ts.map \ No newline at end of file diff --git a/lib.esm/hash/id.d.ts.map b/lib.esm/hash/id.d.ts.map new file mode 100644 index 00000000..713788d8 --- /dev/null +++ b/lib.esm/hash/id.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"id.d.ts","sourceRoot":"","sources":["../../src.ts/hash/id.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;GAUG;AACH,wBAAgB,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAExC"} \ No newline at end of file diff --git a/lib.esm/hash/id.js b/lib.esm/hash/id.js new file mode 100644 index 00000000..1c0289fb --- /dev/null +++ b/lib.esm/hash/id.js @@ -0,0 +1,17 @@ +import { keccak256 } from "../crypto/index.js"; +import { toUtf8Bytes } from "../utils/index.js"; +/** + * A simple hashing function which operates on UTF-8 strings to + * compute an 32-byte identifier. + * + * This simply computes the [UTF-8 bytes](toUtf8Bytes) and computes + * the [[keccak256]]. + * + * @example: + * id("hello world") + * //_result: + */ +export function id(value) { + return keccak256(toUtf8Bytes(value)); +} +//# sourceMappingURL=id.js.map \ No newline at end of file diff --git a/lib.esm/hash/id.js.map b/lib.esm/hash/id.js.map new file mode 100644 index 00000000..36737c51 --- /dev/null +++ b/lib.esm/hash/id.js.map @@ -0,0 +1 @@ +{"version":3,"file":"id.js","sourceRoot":"","sources":["../../src.ts/hash/id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,EAAE,CAAC,KAAa;IAC5B,OAAO,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;AACzC,CAAC"} \ No newline at end of file diff --git a/lib.esm/hash/index.d.ts b/lib.esm/hash/index.d.ts new file mode 100644 index 00000000..0b165fdf --- /dev/null +++ b/lib.esm/hash/index.d.ts @@ -0,0 +1,13 @@ +/** + * Utilities for common tasks involving hashing. Also see + * [cryptographic hashing](about-crypto-hashing). + * + * @_section: api/hashing:Hashing Utilities [about-hashing] + */ +export { id } from "./id.js"; +export { ensNormalize, isValidName, namehash, dnsEncode } from "./namehash.js"; +export { hashMessage, verifyMessage } from "./message.js"; +export { solidityPacked, solidityPackedKeccak256, solidityPackedSha256 } from "./solidity.js"; +export { TypedDataEncoder, verifyTypedData } from "./typed-data.js"; +export type { TypedDataDomain, TypedDataField } from "./typed-data.js"; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/lib.esm/hash/index.d.ts.map b/lib.esm/hash/index.d.ts.map new file mode 100644 index 00000000..1c3368d4 --- /dev/null +++ b/lib.esm/hash/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src.ts/hash/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/E,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EACH,cAAc,EAAE,uBAAuB,EAAE,oBAAoB,EAChE,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEpE,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC"} \ No newline at end of file diff --git a/lib.esm/hash/index.js b/lib.esm/hash/index.js new file mode 100644 index 00000000..99ab2a01 --- /dev/null +++ b/lib.esm/hash/index.js @@ -0,0 +1,12 @@ +/** + * Utilities for common tasks involving hashing. Also see + * [cryptographic hashing](about-crypto-hashing). + * + * @_section: api/hashing:Hashing Utilities [about-hashing] + */ +export { id } from "./id.js"; +export { ensNormalize, isValidName, namehash, dnsEncode } from "./namehash.js"; +export { hashMessage, verifyMessage } from "./message.js"; +export { solidityPacked, solidityPackedKeccak256, solidityPackedSha256 } from "./solidity.js"; +export { TypedDataEncoder, verifyTypedData } from "./typed-data.js"; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib.esm/hash/index.js.map b/lib.esm/hash/index.js.map new file mode 100644 index 00000000..a7bbd3f5 --- /dev/null +++ b/lib.esm/hash/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src.ts/hash/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/E,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EACH,cAAc,EAAE,uBAAuB,EAAE,oBAAoB,EAChE,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC"} \ No newline at end of file diff --git a/lib.esm/hash/message.d.ts b/lib.esm/hash/message.d.ts new file mode 100644 index 00000000..9e088beb --- /dev/null +++ b/lib.esm/hash/message.d.ts @@ -0,0 +1,36 @@ +import type { SignatureLike } from "../crypto/index.js"; +/** + * Computes the [[link-eip-191]] personal-sign message digest to sign. + * + * This prefixes the message with [[MessagePrefix]] and the decimal length + * of %%message%% and computes the [[keccak256]] digest. + * + * If %%message%% is a string, it is converted to its UTF-8 bytes + * first. To compute the digest of a [[DataHexString]], it must be converted + * to [bytes](getBytes). + * + * @example: + * hashMessage("Hello World") + * //_result: + * + * // Hashes the SIX (6) string characters, i.e. + * // [ "0", "x", "4", "2", "4", "3" ] + * hashMessage("0x4243") + * //_result: + * + * // Hashes the TWO (2) bytes [ 0x42, 0x43 ]... + * hashMessage(getBytes("0x4243")) + * //_result: + * + * // ...which is equal to using data + * hashMessage(new Uint8Array([ 0x42, 0x43 ])) + * //_result: + * + */ +export declare function hashMessage(message: Uint8Array | string): string; +/** + * Return the address of the private key that produced + * the signature %%sig%% during signing for %%message%%. + */ +export declare function verifyMessage(message: Uint8Array | string, sig: SignatureLike): string; +//# sourceMappingURL=message.d.ts.map \ No newline at end of file diff --git a/lib.esm/hash/message.d.ts.map b/lib.esm/hash/message.d.ts.map new file mode 100644 index 00000000..d57b1223 --- /dev/null +++ b/lib.esm/hash/message.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../src.ts/hash/message.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM,GAAG,MAAM,CAOhE;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM,EAAE,GAAG,EAAE,aAAa,GAAG,MAAM,CAGtF"} \ No newline at end of file diff --git a/lib.esm/hash/message.js b/lib.esm/hash/message.js new file mode 100644 index 00000000..00c99949 --- /dev/null +++ b/lib.esm/hash/message.js @@ -0,0 +1,51 @@ +import { keccak256 } from "../crypto/index.js"; +import { MessagePrefix } from "../constants/index.js"; +import { recoverAddress } from "../transaction/index.js"; +import { concat, toUtf8Bytes } from "../utils/index.js"; +/** + * Computes the [[link-eip-191]] personal-sign message digest to sign. + * + * This prefixes the message with [[MessagePrefix]] and the decimal length + * of %%message%% and computes the [[keccak256]] digest. + * + * If %%message%% is a string, it is converted to its UTF-8 bytes + * first. To compute the digest of a [[DataHexString]], it must be converted + * to [bytes](getBytes). + * + * @example: + * hashMessage("Hello World") + * //_result: + * + * // Hashes the SIX (6) string characters, i.e. + * // [ "0", "x", "4", "2", "4", "3" ] + * hashMessage("0x4243") + * //_result: + * + * // Hashes the TWO (2) bytes [ 0x42, 0x43 ]... + * hashMessage(getBytes("0x4243")) + * //_result: + * + * // ...which is equal to using data + * hashMessage(new Uint8Array([ 0x42, 0x43 ])) + * //_result: + * + */ +export function hashMessage(message) { + if (typeof (message) === "string") { + message = toUtf8Bytes(message); + } + return keccak256(concat([ + toUtf8Bytes(MessagePrefix), + toUtf8Bytes(String(message.length)), + message + ])); +} +/** + * Return the address of the private key that produced + * the signature %%sig%% during signing for %%message%%. + */ +export function verifyMessage(message, sig) { + const digest = hashMessage(message); + return recoverAddress(digest, sig); +} +//# sourceMappingURL=message.js.map \ No newline at end of file diff --git a/lib.esm/hash/message.js.map b/lib.esm/hash/message.js.map new file mode 100644 index 00000000..ff2ca461 --- /dev/null +++ b/lib.esm/hash/message.js.map @@ -0,0 +1 @@ +{"version":3,"file":"message.js","sourceRoot":"","sources":["../../src.ts/hash/message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGxD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,UAAU,WAAW,CAAC,OAA4B;IACpD,IAAI,OAAM,CAAC,OAAO,CAAC,KAAK,QAAQ,EAAE;QAAE,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;KAAE;IACrE,OAAO,SAAS,CAAC,MAAM,CAAC;QACpB,WAAW,CAAC,aAAa,CAAC;QAC1B,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACnC,OAAO;KACV,CAAC,CAAC,CAAC;AACR,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,OAA4B,EAAE,GAAkB;IAC1E,MAAM,MAAM,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;IACpC,OAAO,cAAc,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AACvC,CAAC"} \ No newline at end of file diff --git a/lib.esm/hash/namehash.d.ts b/lib.esm/hash/namehash.d.ts new file mode 100644 index 00000000..1f3937b2 --- /dev/null +++ b/lib.esm/hash/namehash.d.ts @@ -0,0 +1,20 @@ +/** + * Returns the ENS %%name%% normalized. + */ +export declare function ensNormalize(name: string): string; +/** + * Returns ``true`` if %%name%% is a valid ENS name. + */ +export declare function isValidName(name: string): name is string; +/** + * Returns the [[link-namehash]] for %%name%%. + */ +export declare function namehash(name: string): string; +/** + * Returns the DNS encoded %%name%%. + * + * This is used for various parts of ENS name resolution, such + * as the wildcard resolution. + */ +export declare function dnsEncode(name: string): string; +//# sourceMappingURL=namehash.d.ts.map \ No newline at end of file diff --git a/lib.esm/hash/namehash.d.ts.map b/lib.esm/hash/namehash.d.ts.map new file mode 100644 index 00000000..5a1a9b43 --- /dev/null +++ b/lib.esm/hash/namehash.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"namehash.d.ts","sourceRoot":"","sources":["../../src.ts/hash/namehash.ts"],"names":[],"mappings":"AAyCA;;GAEG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAOjD;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,MAAM,CAKxD;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAa7C;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAa9C"} \ No newline at end of file diff --git a/lib.esm/hash/namehash.js b/lib.esm/hash/namehash.js new file mode 100644 index 00000000..b73e2d91 --- /dev/null +++ b/lib.esm/hash/namehash.js @@ -0,0 +1,85 @@ +import { keccak256 } from "../crypto/index.js"; +import { concat, hexlify, assertArgument, toUtf8Bytes } from "../utils/index.js"; +import { ens_normalize } from "@adraffy/ens-normalize"; +const Zeros = new Uint8Array(32); +Zeros.fill(0); +function checkComponent(comp) { + assertArgument(comp.length !== 0, "invalid ENS name; empty component", "comp", comp); + return comp; +} +function ensNameSplit(name) { + const bytes = toUtf8Bytes(ensNormalize(name)); + const comps = []; + if (name.length === 0) { + return comps; + } + let last = 0; + for (let i = 0; i < bytes.length; i++) { + const d = bytes[i]; + // A separator (i.e. "."); copy this component + if (d === 0x2e) { + comps.push(checkComponent(bytes.slice(last, i))); + last = i + 1; + } + } + // There was a stray separator at the end of the name + assertArgument(last < bytes.length, "invalid ENS name; empty component", "name", name); + comps.push(checkComponent(bytes.slice(last))); + return comps; +} +/** + * Returns the ENS %%name%% normalized. + */ +export function ensNormalize(name) { + try { + if (name.length === 0) { + throw new Error("empty label"); + } + return ens_normalize(name); + } + catch (error) { + assertArgument(false, `invalid ENS name (${error.message})`, "name", name); + } +} +/** + * Returns ``true`` if %%name%% is a valid ENS name. + */ +export function isValidName(name) { + try { + return (ensNameSplit(name).length !== 0); + } + catch (error) { } + return false; +} +/** + * Returns the [[link-namehash]] for %%name%%. + */ +export function namehash(name) { + assertArgument(typeof (name) === "string", "invalid ENS name; not a string", "name", name); + assertArgument(name.length, `invalid ENS name (empty label)`, "name", name); + let result = Zeros; + const comps = ensNameSplit(name); + while (comps.length) { + result = keccak256(concat([result, keccak256((comps.pop()))])); + } + return hexlify(result); +} +/** + * Returns the DNS encoded %%name%%. + * + * This is used for various parts of ENS name resolution, such + * as the wildcard resolution. + */ +export function dnsEncode(name) { + return hexlify(concat(ensNameSplit(name).map((comp) => { + // DNS does not allow components over 63 bytes in length + if (comp.length > 63) { + throw new Error("invalid DNS encoded entry; length exceeds 63 bytes"); + } + const bytes = new Uint8Array(comp.length + 1); + bytes.set(comp, 1); + bytes[0] = bytes.length - 1; + return bytes; + }))) + "00"; +} +//# sourceMappingURL=namehash.js.map \ No newline at end of file diff --git a/lib.esm/hash/namehash.js.map b/lib.esm/hash/namehash.js.map new file mode 100644 index 00000000..350a9f14 --- /dev/null +++ b/lib.esm/hash/namehash.js.map @@ -0,0 +1 @@ +{"version":3,"file":"namehash.js","sourceRoot":"","sources":["../../src.ts/hash/namehash.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EACH,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,WAAW,EAC/C,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;AACjC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAEd,SAAS,cAAc,CAAC,IAAgB;IACpC,cAAc,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,mCAAmC,EAAE,MAAM,EAAE,IAAI,CAAC,CAAA;IACpF,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,SAAS,YAAY,CAAC,IAAY;IAC9B,MAAM,KAAK,GAAG,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC;IAC9C,MAAM,KAAK,GAAsB,EAAG,CAAC;IAErC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;QAAE,OAAO,KAAK,CAAC;KAAE;IAExC,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACnC,MAAM,CA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AC,IAAI,CAAC,MAAM,EAAE,gCAAgC,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IAE5E,IAAI,MAAM,GAAwB,KAAK,CAAC;IAExC,MAAM,KAAK,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;IACjC,OAAO,KAAK,CAAC,MAAM,EAAE;QACjB,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,CAAE,MAAM,EAAE,SAAS,CAAa,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAE,CAAC,CAAC;KAChF;IAED,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;AAC3B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,IAAY;IAClC,OAAO,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QAClD,wDAAwD;QACxD,IAAI,IAAI,CAAC,MAAM,GAAG,EAAE,EAAE;YAClB,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;SACzE;QAED,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAC9C,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;QACnB,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;QAC5B,OAAO,KAAK,CAAC;IAEjB,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;AAChB,CAAC"} \ No newline at end of file diff --git a/lib.esm/hash/solidity.d.ts b/lib.esm/hash/solidity.d.ts new file mode 100644 index 00000000..9b8035eb --- /dev/null +++ b/lib.esm/hash/solidity.d.ts @@ -0,0 +1,31 @@ +/** + * Computes the [[link-solc-packed]] representation of %%values%% + * respectively to their %%types%%. + * + * @example: + * addr = "0x8ba1f109551bd432803012645ac136ddd64dba72" + * solidityPacked([ "address", "uint" ], [ addr, 45 ]); + * //_result: + */ +export declare function solidityPacked(types: ReadonlyArray, values: ReadonlyArray): string; +/** + * Computes the [[link-solc-packed]] [[keccak256]] hash of %%values%% + * respectively to their %%types%%. + * + * @example: + * addr = "0x8ba1f109551bd432803012645ac136ddd64dba72" + * solidityPackedKeccak256([ "address", "uint" ], [ addr, 45 ]); + * //_result: + */ +export declare function solidityPackedKeccak256(types: ReadonlyArray, values: ReadonlyArray): string; +/** + * Computes the [[link-solc-packed]] [[sha256]] hash of %%values%% + * respectively to their %%types%%. + * + * @example: + * addr = "0x8ba1f109551bd432803012645ac136ddd64dba72" + * solidityPackedSha256([ "address", "uint" ], [ addr, 45 ]); + * //_result: + */ +export declare function solidityPackedSha256(types: ReadonlyArray, values: ReadonlyArray): string; +//# sourceMappingURL=solidity.d.ts.map \ No newline at end of file diff --git a/lib.esm/hash/solidity.d.ts.map b/lib.esm/hash/solidity.d.ts.map new file mode 100644 index 00000000..742707df --- /dev/null +++ b/lib.esm/hash/solidity.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"solidity.d.ts","sourceRoot":"","sources":["../../src.ts/hash/solidity.ts"],"names":[],"mappings":"AAyEA;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,GAAG,CAAC,GAAG,MAAM,CAQ/F;AAED;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,GAAG,CAAC,GAAG,MAAM,CAExG;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,GAAG,CAAC,GAAG,MAAM,CAErG"} \ No newline at end of file diff --git a/lib.esm/hash/solidity.js b/lib.esm/hash/solidity.js new file mode 100644 index 00000000..8d20e54b --- /dev/null +++ b/lib.esm/hash/solidity.js @@ -0,0 +1,103 @@ +import { getAddress } from "../address/index.js"; +import { keccak256 as _keccak256, sha256 as _sha256 } from "../crypto/index.js"; +import { concat, dataLength, getBytes, hexlify, toBeArray, toTwos, toUtf8Bytes, zeroPadBytes, zeroPadValue, assertArgument } from "../utils/index.js"; +const regexBytes = new RegExp("^bytes([0-9]+)$"); +const regexNumber = new RegExp("^(u?int)([0-9]*)$"); +const regexArray = new RegExp("^(.*)\\[([0-9]*)\\]$"); +function _pack(type, value, isArray) { + switch (type) { + case "address": + if (isArray) { + return getBytes(zeroPadValue(value, 32)); + } + return getBytes(getAddress(value)); + case "string": + return toUtf8Bytes(value); + case "bytes": + return getBytes(value); + case "bool": + value = (!!value ? "0x01" : "0x00"); + if (isArray) { + return getBytes(zeroPadValue(value, 32)); + } + return getBytes(value); + } + let match = type.match(regexNumber); + if (match) { + let signed = (match[1] === "int"); + let size = parseInt(match[2] || "256"); + assertArgument((!match[2] || match[2] === String(size)) && (size % 8 === 0) && size !== 0 && size <= 256, "invalid number type", "type", type); + if (isArray) { + size = 256; + } + if (signed) { + value = toTwos(value, size); + } + return getBytes(zeroPadValue(toBeArray(value), size / 8)); + } + match = type.match(regexBytes); + if (match) { + const size = parseInt(match[1]); + assertArgument(String(size) === match[1] && size !== 0 && size <= 32, "invalid bytes type", "type", type); + assertArgument(dataLength(value) === size, `invalid value for ${type}`, "value", value); + if (isArray) { + return getBytes(zeroPadBytes(value, 32)); + } + return value; + } + match = type.match(regexArray); + if (match && Array.isArray(value)) { + const baseType = match[1]; + const count = parseInt(match[2] || String(value.length)); + assertArgument(count === value.length, `invalid array length for ${type}`, "value", value); + const result = []; + value.forEach(function (value) { + result.push(_pack(baseType, value, true)); + }); + return getBytes(concat(result)); + } + assertArgument(false, "invalid type", "type", type); +} +// @TODO: Array Enum +/** + * Computes the [[link-solc-packed]] representation of %%values%% + * respectively to their %%types%%. + * + * @example: + * addr = "0x8ba1f109551bd432803012645ac136ddd64dba72" + * solidityPacked([ "address", "uint" ], [ addr, 45 ]); + * //_result: + */ +export function solidityPacked(types, values) { + assertArgument(types.length === values.length, "wrong number of values; expected ${ types.length }", "values", values); + const tight = []; + types.forEach(function (type, index) { + tight.push(_pack(type, values[index])); + }); + return hexlify(concat(tight)); +} +/** + * Computes the [[link-solc-packed]] [[keccak256]] hash of %%values%% + * respectively to their %%types%%. + * + * @example: + * addr = "0x8ba1f109551bd432803012645ac136ddd64dba72" + * solidityPackedKeccak256([ "address", "uint" ], [ addr, 45 ]); + * //_result: + */ +export function solidityPackedKeccak256(types, values) { + return _keccak256(solidityPacked(types, values)); +} +/** + * Computes the [[link-solc-packed]] [[sha256]] hash of %%values%% + * respectively to their %%types%%. + * + * @example: + * addr = "0x8ba1f109551bd432803012645ac136ddd64dba72" + * solidityPackedSha256([ "address", "uint" ], [ addr, 45 ]); + * //_result: + */ +export function solidityPackedSha256(types, values) { + return _sha256(solidityPacked(types, values)); +} +//# sourceMappingURL=solidity.js.map \ No newline at end of file diff --git a/lib.esm/hash/solidity.js.map b/lib.esm/hash/solidity.js.map new file mode 100644 index 00000000..8b315fde --- /dev/null +++ b/lib.esm/hash/solidity.js.map @@ -0,0 +1 @@ +{"version":3,"file":"solidity.js","sourceRoot":"","sources":["../../src.ts/hash/solidity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EACH,SAAS,IAAI,UAAU,EAAE,MAAM,IAAI,OAAO,EAC7C,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACH,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EACjG,cAAc,EACjB,MAAM,mBAAmB,CAAC;AAG3B,MAAM,UAAU,GAAG,IAAI,MAAM,CAAC,iBAAiB,CAAC,CAAC;AACjD,MAAM,WAAW,GAAG,IAAI,MAAM,CAAC,m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.d.ts b/lib.esm/hash/typed-data.d.ts new file mode 100644 index 00000000..def99894 --- /dev/null +++ b/lib.esm/hash/typed-data.d.ts @@ -0,0 +1,142 @@ +import type { SignatureLike } from "../crypto/index.js"; +import type { BigNumberish, BytesLike } from "../utils/index.js"; +/** + * The domain for an [[link-eip-712]] payload. + */ +export interface TypedDataDomain { + /** + * The human-readable name of the signing domain. + */ + name?: null | string; + /** + * The major version of the signing domain. + */ + version?: null | string; + /** + * The chain ID of the signing domain. + */ + chainId?: null | BigNumberish; + /** + * The the address of the contract that will verify the signature. + */ + verifyingContract?: null | string; + /** + * A salt used for purposes decided by the specific domain. + */ + salt?: null | BytesLike; +} +/** + * A specific field of a structured [[link-eip-712]] type. + */ +export interface TypedDataField { + /** + * The field name. + */ + name: string; + /** + * The type of the field. + */ + type: string; +} +/** + * A **TypedDataEncode** prepares and encodes [[link-eip-712]] payloads + * for signed typed data. + * + * This is useful for those that wish to compute various components of a + * typed data hash, primary types, or sub-components, but generally the + * higher level [[Signer-signTypedData]] is more useful. + */ +export declare class TypedDataEncoder { + #private; + /** + * The primary type for the structured [[types]]. + * + * This is derived automatically from the [[types]], since no + * recursion is possible, once the DAG for the types is consturcted + * internally, the primary type must be the only remaining type with + * no parent nodes. + */ + readonly primaryType: string; + /** + * The types. + */ + get types(): Record>; + /** + * Create a new **TypedDataEncoder** for %%types%%. + * + * This performs all necessary checking that types are valid and + * do not violate the [[link-eip-712]] structural constraints as + * well as computes the [[primaryType]]. + */ + constructor(types: Record>); + /** + * Returnthe encoder for the specific %%type%%. + */ + getEncoder(type: string): (value: any) => string; + /** + * Return the full type for %%name%%. + */ + encodeType(name: string): string; + /** + * Return the encoded %%value%% for the %%type%%. + */ + encodeData(type: string, value: any): string; + /** + * Returns the hash of %%value%% for the type of %%name%%. + */ + hashStruct(name: string, value: Record): string; + /** + * Return the fulled encoded %%value%% for the [[types]]. + */ + encode(value: Record): string; + /** + * Return the hash of the fully encoded %%value%% for the [[types]]. + */ + hash(value: Record): string; + /** + * @_ignore: + */ + _visit(type: string, value: any, callback: (type: string, data: any) => any): any; + /** + * Call %%calback%% for each value in %%value%%, passing the type and + * component within %%value%%. + * + * This is useful for replacing addresses or other transformation that + * may be desired on each component, based on its type. + */ + visit(value: Record, callback: (type: string, data: any) => any): any; + /** + * Create a new **TypedDataEncoder** for %%types%%. + */ + static from(types: Record>): TypedDataEncoder; + /** + * Return the primary type for %%types%%. + */ + static getPrimaryType(types: Record>): string; + /** + * Return the hashed struct for %%value%% using %%types%% and %%name%%. + */ + static hashStruct(name: string, types: Record>, value: Record): string; + /** + * Return the domain hash for %%domain%%. + */ + static hashDomain(domain: TypedDataDomain): string; + /** + * Return the fully encoded [[link-eip-712]] %%value%% for %%types%% with %%domain%%. + */ + static encode(domain: TypedDataDomain, types: Record>, value: Record): string; + /** + * Return the hash of the fully encoded [[link-eip-712]] %%value%% for %%types%% with %%domain%%. + */ + static hash(domain: TypedDataDomain, types: Record>, value: Record): string; + /** + * Returns the JSON-encoded payload expected by nodes which implement + * the JSON-RPC [[link-eip-712]] method. + */ + static getPayload(domain: TypedDataDomain, types: Record>, value: Record): any; +} +/** + * Compute the address used to sign the typed data for the %%signature%%. + */ +export declare function verifyTypedData(domain: TypedDataDomain, types: Record>, value: Record, signature: SignatureLike): string; +//# sourceMappingURL=typed-data.d.ts.map \ No newline at end of file diff --git a/lib.esm/hash/typed-data.d.ts.map b/lib.esm/hash/typed-data.d.ts.map new file mode 100644 index 00000000..0388850c --- /dev/null +++ b/lib.esm/hash/typed-data.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"typed-data.d.ts","sourceRoot":"","sources":["../../src.ts/hash/typed-data.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAajE;;GAEG;AACH,MAAM,WAAW,eAAe;IAC5B;;OAEG;IACH,IAA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M,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM;IAItH;;;OAGG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG;CAuD5H;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,SAAS,EAAE,aAAa,GAAG,MAAM,CAEnK"} \ No newline at end of file diff --git a/lib.esm/hash/typed-data.js b/lib.esm/hash/typed-data.js new file mode 100644 index 00000000..acf77fba --- /dev/null +++ b/lib.esm/hash/typed-data.js @@ -0,0 +1,442 @@ +//import { TypedDataDomain, TypedDataField } from "@quaisproject/providerabstract-signer"; +import { getAddress } from "../address/index.js"; +import { keccak256 } from "../crypto/index.js"; +import { recoverAddress } from "../transaction/index.js"; +import { concat, defineProperties, getBigInt, getBytes, hexlify, mask, toBeHex, toQuantity, toTwos, zeroPadValue, assertArgument } from "../utils/index.js"; +import { id } from "./id.js"; +const padding = new Uint8Array(32); +padding.fill(0); +const BN__1 = BigInt(-1); +const BN_0 = BigInt(0); +const BN_1 = BigInt(1); +const BN_MAX_UINT256 = BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); +; +; +function hexPadRight(value) { + const bytes = getBytes(value); + const padOffset = bytes.length % 32; + if (padOffset) { + return concat([bytes, padding.slice(padOffset)]); + } + return hexlify(bytes); +} +const hexTrue = toBeHex(BN_1, 32); +const hexFalse = toBeHex(BN_0, 32); +const domainFieldTypes = { + name: "string", + version: "string", + chainId: "uint256", + verifyingContract: "address", + salt: "bytes32" +}; +const domainFieldNames = [ + "name", "version", "chainId", "verifyingContract", "salt" +]; +function checkString(key) { + return function (value) { + assertArgument(typeof (value) === "string", `invalid domain value for ${JSON.stringify(key)}`, `domain.${key}`, value); + return value; + }; +} +const domainChecks = { + name: checkString("name"), + version: checkString("version"), + chainId: function (_value) { + const value = getBigInt(_value, "domain.chainId"); + assertArgument(value >= 0, "invalid chain ID", "domain.chainId", _value); + if (Number.isSafeInteger(value)) { + return Number(value); + } + return toQuantity(value); + }, + verifyingContract: function (value) { + try { + return getAddress(value).toLowerCase(); + } + catch (error) { } + assertArgument(false, `invalid domain value "verifyingContract"`, "domain.verifyingContract", value); + }, + salt: function (value) { + const bytes = getBytes(value, "domain.salt"); + assertArgument(bytes.length === 32, `invalid domain value "salt"`, "domain.salt", value); + return hexlify(bytes); + } +}; +function getBaseEncoder(type) { + // intXX and uintXX + { + const match = type.match(/^(u?)int(\d*)$/); + if (match) { + const signed = (match[1] === ""); + const width = parseInt(match[2] || "256"); + assertArgument(width % 8 === 0 && width !== 0 && width <= 256 && (match[2] == null || match[2] === String(width)), "invalid numeric width", "type", type); + const boundsUpper = mask(BN_MAX_UINT256, signed ? (width - 1) : width); + const boundsLower = signed ? ((boundsUpper + BN_1) * BN__1) : BN_0; + return function (_value) { + const value = getBigInt(_value, "value"); + assertArgument(value >= boundsLower && value <= boundsUpper, `value out-of-bounds for ${type}`, "value", value); + return toBeHex(signed ? toTwos(value, 256) : value, 32); + }; + } + } + // bytesXX + { + const match = type.match(/^bytes(\d+)$/); + if (match) { + const width = parseInt(match[1]); + assertArgument(width !== 0 && width <= 32 && match[1] === String(width), "invalid bytes width", "type", type); + return function (value) { + const bytes = getBytes(value); + assertArgument(bytes.length === width, `invalid length for ${type}`, "value", value); + return hexPadRight(value); + }; + } + } + switch (type) { + case "address": return function (value) { + return zeroPadValue(getAddress(value), 32); + }; + case "bool": return function (value) { + return ((!value) ? hexFalse : hexTrue); + }; + case "bytes": return function (value) { + return keccak256(value); + }; + case "string": return function (value) { + return id(value); + }; + } + return null; +} +function encodeType(name, fields) { + return `${name}(${fields.map(({ name, type }) => (type + " " + name)).join(",")})`; +} +/** + * A **TypedDataEncode** prepares and encodes [[link-eip-712]] payloads + * for signed typed data. + * + * This is useful for those that wish to compute various components of a + * typed data hash, primary types, or sub-components, but generally the + * higher level [[Signer-signTypedData]] is more useful. + */ +export class TypedDataEncoder { + /** + * The primary type for the structured [[types]]. + * + * This is derived automatically from the [[types]], since no + * recursion is possible, once the DAG for the types is consturcted + * internally, the primary type must be the only remaining type with + * no parent nodes. + */ + primaryType; + #types; + /** + * The types. + */ + get types() { + return JSON.parse(this.#types); + } + #fullTypes; + #encoderCache; + /** + * Create a new **TypedDataEncoder** for %%types%%. + * + * This performs all necessary checking that types are valid and + * do not violate the [[link-eip-712]] structural constraints as + * well as computes the [[primaryType]]. + */ + constructor(types) { + this.#types = JSON.stringify(types); + this.#fullTypes = new Map(); + this.#encoderCache = new Map(); + // Link struct types to their direct child structs + const links = new Map(); + // Link structs to structs which contain them as a child + const parents = new Map(); + // Link all subtypes within a given struct + const subtypes = new Map(); + Object.keys(types).forEach((type) => { + links.set(type, new Set()); + parents.set(type, []); + subtypes.set(type, new Set()); + }); + for (const name in types) { + const uniqueNames = new Set(); + for (const field of types[name]) { + // Check each field has a unique name + assertArgument(!uniqueNames.has(field.name), `duplicate variable name ${JSON.stringify(field.name)} in ${JSON.stringify(name)}`, "types", types); + uniqueNames.add(field.name); + // Get the base type (drop any array specifiers) + const baseType = (field.type.match(/^([^\x5b]*)(\x5b|$)/))[1] || null; + assertArgument(baseType !== name, `circular type reference to ${JSON.stringify(baseType)}`, "types", types); + // Is this a base encoding type? + const encoder = getBaseEncoder(baseType); + if (encoder) { + continue; + } + assertArgument(parents.has(baseType), `unknown type ${JSON.stringify(baseType)}`, "types", types); + // Add linkage + parents.get(baseType).push(name); + links.get(name).add(baseType); + } + } + // Deduce the primary type + const primaryTypes = Array.from(parents.keys()).filter((n) => (parents.get(n).length === 0)); + assertArgument(primaryTypes.length !== 0, "missing primary type", "types", types); + assertArgument(primaryTypes.length === 1, `ambiguous primary types or unused types: ${primaryTypes.map((t) => (JSON.stringify(t))).join(", ")}`, "types", types); + defineProperties(this, { primaryType: primaryTypes[0] }); + // Check for circular type references + function checkCircular(type, found) { + assertArgument(!found.has(type), `circular type reference to ${JSON.stringify(type)}`, "types", types); + found.add(type); + for (const child of links.get(type)) { + if (!parents.has(child)) { + continue; + } + // Recursively check children + checkCircular(child, found); + // Mark all ancestors as having this decendant + for (const subtype of found) { + subtypes.get(subtype).add(child); + } + } + found.delete(type); + } + checkCircular(this.primaryType, new Set()); + // Compute each fully describe type + for (const [name, set] of subtypes) { + const st = Array.from(set); + st.sort(); + this.#fullTypes.set(name, encodeType(name, types[name]) + st.map((t) => encodeType(t, types[t])).join("")); + } + } + /** + * Returnthe encoder for the specific %%type%%. + */ + getEncoder(type) { + let encoder = this.#encoderCache.get(type); + if (!encoder) { + encoder = this.#getEncoder(type); + this.#encoderCache.set(type, encoder); + } + return encoder; + } + #getEncoder(type) { + // Basic encoder type (address, bool, uint256, etc) + { + const encoder = getBaseEncoder(type); + if (encoder) { + return encoder; + } + } + // Array + const match = type.match(/^(.*)(\x5b(\d*)\x5d)$/); + if (match) { + const subtype = match[1]; + const subEncoder = this.getEncoder(subtype); + return (value) => { + assertArgument(!match[3] || parseInt(match[3]) === value.length, `array length mismatch; expected length ${parseInt(match[3])}`, "value", value); + let result = value.map(subEncoder); + if (this.#fullTypes.has(subtype)) { + result = result.map(keccak256); + } + return keccak256(concat(result)); + }; + } + // Struct + const fields = this.types[type]; + if (fields) { + const encodedType = id(this.#fullTypes.get(type)); + return (value) => { + const values = fields.map(({ name, type }) => { + const result = this.getEncoder(type)(value[name]); + if (this.#fullTypes.has(type)) { + return keccak256(result); + } + return result; + }); + values.unshift(encodedType); + return concat(values); + }; + } + assertArgument(false, `unknown type: ${type}`, "type", type); + } + /** + * Return the full type for %%name%%. + */ + encodeType(name) { + const result = this.#fullTypes.get(name); + assertArgument(result, `unknown type: ${JSON.stringify(name)}`, "name", name); + return result; + } + /** + * Return the encoded %%value%% for the %%type%%. + */ + encodeData(type, value) { + return this.getEncoder(type)(value); + } + /** + * Returns the hash of %%value%% for the type of %%name%%. + */ + hashStruct(name, value) { + return keccak256(this.encodeData(name, value)); + } + /** + * Return the fulled encoded %%value%% for the [[types]]. + */ + encode(value) { + return this.encodeData(this.primaryType, value); + } + /** + * Return the hash of the fully encoded %%value%% for the [[types]]. + */ + hash(value) { + return this.hashStruct(this.primaryType, value); + } + /** + * @_ignore: + */ + _visit(type, value, callback) { + // Basic encoder type (address, bool, uint256, etc) + { + const encoder = getBaseEncoder(type); + if (encoder) { + return callback(type, value); + } + } + // Array + const match = type.match(/^(.*)(\x5b(\d*)\x5d)$/); + if (match) { + assertArgument(!match[3] || parseInt(match[3]) === value.length, `array length mismatch; expected length ${parseInt(match[3])}`, "value", value); + return value.map((v) => this._visit(match[1], v, callback)); + } + // Struct + const fields = this.types[type]; + if (fields) { + return fields.reduce((accum, { name, type }) => { + accum[name] = this._visit(type, value[name], callback); + return accum; + }, {}); + } + assertArgument(false, `unknown type: ${type}`, "type", type); + } + /** + * Call %%calback%% for each value in %%value%%, passing the type and + * component within %%value%%. + * + * This is useful for replacing addresses or other transformation that + * may be desired on each component, based on its type. + */ + visit(value, callback) { + return this._visit(this.primaryType, value, callback); + } + /** + * Create a new **TypedDataEncoder** for %%types%%. + */ + static from(types) { + return new TypedDataEncoder(types); + } + /** + * Return the primary type for %%types%%. + */ + static getPrimaryType(types) { + return TypedDataEncoder.from(types).primaryType; + } + /** + * Return the hashed struct for %%value%% using %%types%% and %%name%%. + */ + static hashStruct(name, types, value) { + return TypedDataEncoder.from(types).hashStruct(name, value); + } + /** + * Return the domain hash for %%domain%%. + */ + static hashDomain(domain) { + const domainFields = []; + for (const name in domain) { + if (domain[name] == null) { + continue; + } + const type = domainFieldTypes[name]; + assertArgument(type, `invalid typed-data domain key: ${JSON.stringify(name)}`, "domain", domain); + domainFields.push({ name, type }); + } + domainFields.sort((a, b) => { + return domainFieldNames.indexOf(a.name) - domainFieldNames.indexOf(b.name); + }); + return TypedDataEncoder.hashStruct("EIP712Domain", { EIP712Domain: domainFields }, domain); + } + /** + * Return the fully encoded [[link-eip-712]] %%value%% for %%types%% with %%domain%%. + */ + static encode(domain, types, value) { + return concat([ + "0x1901", + TypedDataEncoder.hashDomain(domain), + TypedDataEncoder.from(types).hash(value) + ]); + } + /** + * Return the hash of the fully encoded [[link-eip-712]] %%value%% for %%types%% with %%domain%%. + */ + static hash(domain, types, value) { + return keccak256(TypedDataEncoder.encode(domain, types, value)); + } + /** + * Returns the JSON-encoded payload expected by nodes which implement + * the JSON-RPC [[link-eip-712]] method. + */ + static getPayload(domain, types, value) { + // Validate the domain fields + TypedDataEncoder.hashDomain(domain); + // Derive the EIP712Domain Struct reference type + const domainValues = {}; + const domainTypes = []; + domainFieldNames.forEach((name) => { + const value = domain[name]; + if (value == null) { + return; + } + domainValues[name] = domainChecks[name](value); + domainTypes.push({ name, type: domainFieldTypes[name] }); + }); + const encoder = TypedDataEncoder.from(types); + const typesWithDomain = Object.assign({}, types); + assertArgument(typesWithDomain.EIP712Domain == null, "types must not contain EIP712Domain type", "types.EIP712Domain", types); + typesWithDomain.EIP712Domain = domainTypes; + // Validate the data structures and types + encoder.encode(value); + return { + types: typesWithDomain, + domain: domainValues, + primaryType: encoder.primaryType, + message: encoder.visit(value, (type, value) => { + // bytes + if (type.match(/^bytes(\d*)/)) { + return hexlify(getBytes(value)); + } + // uint or int + if (type.match(/^u?int/)) { + return getBigInt(value).toString(); + } + switch (type) { + case "address": + return value.toLowerCase(); + case "bool": + return !!value; + case "string": + assertArgument(typeof (value) === "string", "invalid string", "value", value); + return value; + } + assertArgument(false, "unsupported type", "type", type); + }) + }; + } +} +/** + * Compute the address used to sign the typed data for the %%signature%%. + */ +export function verifyTypedData(domain, types, value, signature) { + return recoverAddress(TypedDataEncoder.hash(domain, types, value), signature); +} +//# sourceMappingURL=typed-data.js.map \ No newline at end of file diff --git a/lib.esm/hash/typed-data.js.map b/lib.esm/hash/typed-data.js.map new file mode 100644 index 00000000..6738680d --- /dev/null +++ b/lib.esm/hash/typed-data.js.map @@ -0,0 +1 @@ +{"version":3,"file":"typed-data.js","sourceRoot":"","sources":["../../src.ts/hash/typed-data.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EACH,MAAM,EAAE,gBAAgB,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,EACvG,cAAc,EACjB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAM7B,MAAM,OAAO,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;AACnC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAEhB,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AACzB,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;AAgCnG,CAAC;AAeD,CAAC;AAEF,SAAS,WAAW,CAAC,KAAgB;IACjC,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC9B,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,GAAG,EAAE,CAAA;IACnC,IAAI,SAAS,EAAE;QACX,OAAO,MAAM,CAAC,CAAE,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAA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,OAAO,EAAE,KAAK,CAAC,CAAC;wBAC7E,OAAO,KAAK,CAAC;iBACpB;gBAED,cAAc,CAAC,KAAK,EAAE,kBAAkB,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;YAC5D,CAAC,CAAC;SACL,CAAC;IACN,CAAC;CACJ;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,MAAuB,EAAE,KAA4C,EAAE,KAA0B,EAAE,SAAwB;IACvJ,OAAO,cAAc,CAAC,gBAAgB,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,EAAE,SAAS,CAAC,CAAC;AAClF,CAAC"} \ No newline at end of file diff --git a/lib.esm/index.d.ts b/lib.esm/index.d.ts new file mode 100644 index 00000000..e580562e --- /dev/null +++ b/lib.esm/index.d.ts @@ -0,0 +1,11 @@ +/** + * The Application Programming Interface (API) is the collection of + * functions, classes and types offered by the quais library. + * + * @_section: api:Application Programming Interface [about-api] + * @_navTitle: API + */ +import * as quais from "./quais.js"; +export { quais }; +export * from "./quais.js"; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/lib.esm/index.d.ts.map b/lib.esm/index.d.ts.map new file mode 100644 index 00000000..3e481408 --- /dev/null +++ b/lib.esm/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src.ts/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AAEpC,OAAO,EAAE,KAAK,EAAE,CAAC;AAEjB,cAAc,YAAY,CAAC"} \ No newline at end of file diff --git a/lib.esm/index.js b/lib.esm/index.js new file mode 100644 index 00000000..b5b16b24 --- /dev/null +++ b/lib.esm/index.js @@ -0,0 +1,11 @@ +/** + * The Application Programming Interface (API) is the collection of + * functions, classes and types offered by the quais library. + * + * @_section: api:Application Programming Interface [about-api] + * @_navTitle: API + */ +import * as quais from "./quais.js"; +export { quais }; +export * from "./quais.js"; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib.esm/index.js.map b/lib.esm/index.js.map new file mode 100644 index 00000000..08b048b5 --- /dev/null +++ b/lib.esm/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../src.ts/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AAEpC,OAAO,EAAE,KAAK,EAAE,CAAC;AAEjB,cAAc,YAAY,CAAC"} \ No newline at end of file diff --git a/lib.esm/package.json b/lib.esm/package.json new file mode 100644 index 00000000..04a5cfd6 --- /dev/null +++ b/lib.esm/package.json @@ -0,0 +1,12 @@ +{ + "browser": { + "./crypto/crypto.js": "./crypto/crypto-browser.js", + "./providers/provider-ipcsocket.js": "./providers/provider-ipcsocket-browser.js", + "./providers/ws.js": "./providers/ws-browser.js", + "./utils/base64.js": "./utils/base64-browser.js", + "./utils/geturl.js": "./utils/geturl-browser.js", + "./wordlists/wordlists.js": "./wordlists/wordlists-browser.js" + }, + "sideEffects": false, + "type": "module" +} diff --git a/lib.esm/providers/abstract-provider.d.ts b/lib.esm/providers/abstract-provider.d.ts new file mode 100644 index 00000000..73b57952 --- /dev/null +++ b/lib.esm/providers/abstract-provider.d.ts @@ -0,0 +1,493 @@ +/** + * The available providers should suffice for most developers purposes, + * but the [[AbstractProvider]] class has many features which enable + * sub-classing it for specific purposes. + * + * @_section: api/providers/abstract-provider: Subclassing Provider [abstract-provider] + */ +import { FetchRequest } from "../utils/index.js"; +import { Network } from "./network.js"; +import { Block, FeeData, Log, TransactionReceipt, TransactionResponse } from "./provider.js"; +import type { AddressLike } from "../address/index.js"; +import type { BigNumberish } from "../utils/index.js"; +import type { Listener } from "../utils/index.js"; +import type { Networkish } from "./network.js"; +import type { BlockParams, LogParams, TransactionReceiptParams, TransactionResponseParams } from "./formatting.js"; +import type { BlockTag, EventFilter, Filter, FilterByBlockHash, OrphanFilter, PreparedTransactionRequest, Provider, ProviderEvent, TransactionRequest } from "./provider.js"; +/** + * The types of additional event values that can be emitted for the + * ``"debug"`` event. + */ +export type DebugEventAbstractProvider = { + action: "sendCcipReadFetchRequest"; + request: FetchRequest; + index: number; + urls: Array; +} | { + action: "receiveCcipReadFetchResult"; + request: FetchRequest; + result: any; +} | { + action: "receiveCcipReadFetchError"; + request: FetchRequest; + result: any; +} | { + action: "sendCcipReadCall"; + transaction: { + to: string; + data: string; + }; +} | { + action: "receiveCcipReadCallResult"; + transaction: { + to: string; + data: string; + }; + result: string; +} | { + action: "receiveCcipReadCallError"; + transaction: { + to: string; + data: string; + }; + error: Error; +}; +/** + * The value passed to the [[AbstractProvider-_getSubscriber]] method. + * + * Only developers sub-classing [[AbstractProvider[[ will care about this, + * if they are modifying a low-level feature of how subscriptions operate. + */ +export type Subscription = { + type: "block" | "close" | "debug" | "error" | "finalized" | "network" | "pending" | "safe"; + tag: string; +} | { + type: "transaction"; + tag: string; + hash: string; +} | { + type: "event"; + tag: string; + filter: EventFilter; +} | { + type: "orphan"; + tag: string; + filter: OrphanFilter; +}; +/** + * A **Subscriber** manages a subscription. + * + * Only developers sub-classing [[AbstractProvider[[ will care about this, + * if they are modifying a low-level feature of how subscriptions operate. + */ +export interface Subscriber { + /** + * Called initially when a subscriber is added the first time. + */ + start(): void; + /** + * Called when there are no more subscribers to the event. + */ + stop(): void; + /** + * Called when the subscription should pause. + * + * If %%dropWhilePaused%%, events that occur while paused should not + * be emitted [[resume]]. + */ + pause(dropWhilePaused?: boolean): void; + /** + * Resume a paused subscriber. + */ + resume(): void; + /** + * The frequency (in ms) to poll for events, if polling is used by + * the subscriber. + * + * For non-polling subscribers, this must return ``undefined``. + */ + pollingInterval?: number; +} +/** + * An **UnmanagedSubscriber** is useful for events which do not require + * any additional management, such as ``"debug"`` which only requires + * emit in synchronous event loop triggered calls. + */ +export declare class UnmanagedSubscriber implements Subscriber { + /** + * The name fof the event. + */ + name: string; + /** + * Create a new UnmanagedSubscriber with %%name%%. + */ + constructor(name: string); + start(): void; + stop(): void; + pause(dropWhilePaused?: boolean): void; + resume(): void; +} +/** + * An **AbstractPlugin** is used to provide additional internal services + * to an [[AbstractProvider]] without adding backwards-incompatible changes + * to method signatures or other internal and complex logic. + */ +export interface AbstractProviderPlugin { + /** + * The reverse domain notation of the plugin. + */ + readonly name: string; + /** + * Creates a new instance of the plugin, connected to %%provider%%. + */ + connect(provider: AbstractProvider): AbstractProviderPlugin; +} +/** + * A normalized filter used for [[PerformActionRequest]] objects. + */ +export type PerformActionFilter = { + address?: string | Array; + topics?: Array>; + fromBlock?: BlockTag; + toBlock?: BlockTag; + shard: string; +} | { + address?: string | Array; + topics?: Array>; + blockHash?: string; + shard: string; +}; +/** + * A normalized transactions used for [[PerformActionRequest]] objects. + */ +export interface PerformActionTransaction extends PreparedTransactionRequest { + /** + * The ``to`` address of the transaction. + */ + to?: string; + /** + * The sender of the transaction. + */ + from: string; +} +/** + * The [[AbstractProvider]] methods will normalize all values and pass this + * type to [[AbstractProvider-_perform]]. + */ +export type PerformActionRequest = { + method: "broadcastTransaction"; + signedTransaction: string; + shard: string; +} | { + method: "call"; + transaction: PerformActionTransaction; + blockTag: BlockTag; + shard?: string; +} | { + method: "chainId"; + shard?: string; +} | { + method: "estimateGas"; + transaction: PerformActionTransaction; + shard?: string; +} | { + method: "getBalance"; + address: string; + blockTag: BlockTag; + shard: string; +} | { + method: "getBlock"; + blockTag: BlockTag; + includeTransactions: boolean; + shard: string; +} | { + method: "getBlock"; + blockHash: string; + includeTransactions: boolean; + shard: string; +} | { + method: "getBlockNumber"; + shard?: string; +} | { + method: "getCode"; + address: string; + blockTag: BlockTag; + shard: string; +} | { + method: "getGasPrice"; + txType: boolean; + shard?: string; +} | { + method: "getLogs"; + filter: PerformActionFilter; + shard: string; +} | { + method: "getMaxPriorityFeePerGas"; + shard?: string; +} | { + method: "getStorage"; + address: string; + position: bigint; + blockTag: BlockTag; + shard: string; +} | { + method: "getTransaction"; + hash: string; + shard: string; +} | { + method: "getTransactionCount"; + address: string; + blockTag: BlockTag; + shard: string; +} | { + method: "getTransactionReceipt"; + hash: string; + shard: string; +} | { + method: "getTransactionResult"; + hash: string; + shard: string; +} | { + method: "getRunningLocations"; + shard?: string; +} | { + method: "getProtocolTrieExpansionCount"; + shard: string; +} | { + method: "getQiRateAtBlock"; + blockTag: BlockTag; + amt: number; + shard: string; +} | { + method: "getQuaiRateAtBlock"; + blockTag: BlockTag; + amt: number; + shard: string; +} | { + method: "getProtocolExpansionNumber"; +}; +/** + * Options for configuring some internal aspects of an [[AbstractProvider]]. + * + * **``cacheTimeout``** - how long to cache a low-level ``_perform`` + * for, based on input parameters. This reduces the number of calls + * to getChainId and getBlockNumber, but may break test chains which + * can perform operations (internally) synchronously. Use ``-1`` to + * disable, ``0`` will only buffer within the same event loop and + * any other value is in ms. (default: ``250``) + */ +export type AbstractProviderOptions = { + cacheTimeout?: number; + pollingInterval?: number; +}; +/** + * An **AbstractProvider** provides a base class for other sub-classes to + * implement the [[Provider]] API by normalizing input arguments and + * formatting output results as well as tracking events for consistent + * behaviour on an eventually-consistent network. + */ +export declare class AbstractProvider implements Provider { + #private; + _urlMap: Map; + /** + * Create a new **AbstractProvider** connected to %%network%%, or + * use the various network detection capabilities to discover the + * [[Network]] if necessary. + */ + constructor(_network?: "any" | Networkish, options?: AbstractProviderOptions); + initUrlMap(urls: string[] | FetchRequest): Promise; + shardBytes(shard: string): string; + get connect(): FetchRequest[]; + shardFromAddress(_address: AddressLike): Promise; + shardFromHash(hash: string): string; + getLatestQuaiRate(shard: string, amt?: number): Promise; + getQuaiRateAtBlock(shard: string, blockTag: BlockTag, amt?: number): Promise; + getProtocolExpansionNumber(): Promise; + getLatestQiRate(shard: string, amt?: number): Promise; + getQiRateAtBlock(shard: string, blockTag: BlockTag, amt?: number): Promise; + get pollingInterval(): number; + /** + * Returns ``this``, to allow an **AbstractProvider** to implement + * the [[ContractRunner]] interface. + */ + get provider(): this; + /** + * Returns all the registered plug-ins. + */ + get plugins(): Array; + /** + * Attach a new plug-in. + */ + attachPlugin(plugin: AbstractProviderPlugin): this; + /** + * Get a plugin by name. + */ + getPlugin(name: string): null | T; + /** + * Prevent any CCIP-read operation, regardless of whether requested + * in a [[call]] using ``enableCcipRead``. + */ + get disableCcipRead(): boolean; + set disableCcipRead(value: boolean); + /** + * Provides the opportunity for a sub-class to wrap a block before + * returning it, to add additional properties or an alternate + * sub-class of [[Block]]. + */ + _wrapBlock(value: BlockParams, network: Network): Block; + /** + * Provides the opportunity for a sub-class to wrap a log before + * returning it, to add additional properties or an alternate + * sub-class of [[Log]]. + */ + _wrapLog(value: LogParams, network: Network): Log; + /** + * Provides the opportunity for a sub-class to wrap a transaction + * receipt before returning it, to add additional properties or an + * alternate sub-class of [[TransactionReceipt]]. + */ + _wrapTransactionReceipt(value: TransactionReceiptParams, network: Network): TransactionReceipt; + /** + * Provides the opportunity for a sub-class to wrap a transaction + * response before returning it, to add additional properties or an + * alternate sub-class of [[TransactionResponse]]. + */ + _wrapTransactionResponse(tx: TransactionResponseParams, network: Network): TransactionResponse; + /** + * Resolves to the Network, forcing a network detection using whatever + * technique the sub-class requires. + * + * Sub-classes **must** override this. + */ + _detectNetwork(shard?: string): Promise; + /** + * Sub-classes should use this to perform all built-in operations. All + * methods sanitizes and normalizes the values passed into this. + * + * Sub-classes **must** override this. + */ + _perform(req: PerformActionRequest): Promise; + getBlockNumber(shard?: string): Promise; + /** + * Returns or resolves to the address for %%address%%, resolving ENS + * names and [[Addressable]] objects and returning if already an + * address. + */ + _getAddress(address: AddressLike): string | Promise; + /** + * Returns or resolves to a valid block tag for %%blockTag%%, resolving + * negative values and returning if already a valid block tag. + */ + _getBlockTag(shard?: string, blockTag?: BlockTag): string | Promise; + /** + * Returns or resolves to a filter for %%filter%%, resolving any ENS + * names or [[Addressable]] object and returning if already a valid + * filter. + */ + _getFilter(filter: Filter | FilterByBlockHash): PerformActionFilter | Promise; + /** + * Returns or resovles to a transaction for %%request%%, resolving + * any ENS names or [[Addressable]] and returning if already a valid + * transaction. + */ + _getTransactionRequest(_request: TransactionRequest): PerformActionTransaction | Promise; + getNetwork(shard?: string): Promise; + getRunningLocations(shard?: string): Promise; + getProtocolTrieExpansionCount(shard: string): Promise; + getFeeData(shard?: string, txType?: boolean): Promise; + estimateGas(_tx: TransactionRequest): Promise; + call(_tx: TransactionRequest): Promise; + getBalance(address: AddressLike, blockTag?: BlockTag): Promise; + getTransactionCount(address: AddressLike, blockTag?: BlockTag): Promise; + getCode(address: AddressLike, blockTag?: BlockTag): Promise; + getStorage(address: AddressLike, _position: BigNumberish, blockTag?: BlockTag): Promise; + broadcastTransaction(shard: string, signedTx: string): Promise; + getBlock(shard: string, block: BlockTag | string, prefetchTxs?: boolean): Promise; + getTransaction(hash: string): Promise; + getTransactionReceipt(hash: string): Promise; + getTransactionResult(hash: string): Promise; + getLogs(_filter: Filter | FilterByBlockHash): Promise>; + _getProvider(chainId: number): AbstractProvider; + waitForTransaction(hash: string, _confirms?: null | number, timeout?: null | number): Promise; + waitForBlock(shard: string, blockTag?: BlockTag): Promise; + /** + * Clear a timer created using the [[_setTimeout]] method. + */ + _clearTimeout(timerId: number): void; + /** + * Create a timer that will execute %%func%% after at least %%timeout%% + * (in ms). If %%timeout%% is unspecified, then %%func%% will execute + * in the next event loop. + * + * [Pausing](AbstractProvider-paused) the provider will pause any + * associated timers. + */ + _setTimeout(_func: () => void, timeout?: number): number; + /** + * Perform %%func%% on each subscriber. + */ + _forEachSubscriber(func: (s: Subscriber) => void): void; + /** + * Sub-classes may override this to customize subscription + * implementations. + */ + _getSubscriber(sub: Subscription): Subscriber; + /** + * If a [[Subscriber]] fails and needs to replace itself, this + * method may be used. + * + * For example, this is used for providers when using the + * ``eth_getFilterChanges`` method, which can return null if state + * filters are not supported by the backend, allowing the Subscriber + * to swap in a [[PollingEventSubscriber]]. + */ + _recoverSubscriber(oldSub: Subscriber, newSub: Subscriber): void; + on(event: ProviderEvent, listener: Listener): Promise; + once(event: ProviderEvent, listener: Listener): Promise; + emit(event: ProviderEvent, ...args: Array): Promise; + listenerCount(event?: ProviderEvent): Promise; + listeners(event?: ProviderEvent): Promise>; + off(event: ProviderEvent, listener?: Listener): Promise; + removeAllListeners(event?: ProviderEvent): Promise; + addListener(event: ProviderEvent, listener: Listener): Promise; + removeListener(event: ProviderEvent, listener: Listener): Promise; + /** + * If this provider has been destroyed using the [[destroy]] method. + * + * Once destroyed, all resources are reclaimed, internal event loops + * and timers are cleaned up and no further requests may be sent to + * the provider. + */ + get destroyed(): boolean; + /** + * Sub-classes may use this to shutdown any sockets or release their + * resources and reject any pending requests. + * + * Sub-classes **must** call ``super.destroy()``. + */ + destroy(): void; + /** + * Whether the provider is currently paused. + * + * A paused provider will not emit any events, and generally should + * not make any requests to the network, but that is up to sub-classes + * to manage. + * + * Setting ``paused = true`` is identical to calling ``.pause(false)``, + * which will buffer any events that occur while paused until the + * provider is unpaused. + */ + get paused(): boolean; + set paused(pause: boolean); + /** + * Pause the provider. If %%dropWhilePaused%%, any events that occur + * while paused are dropped, otherwise all events will be emitted once + * the provider is unpaused. + */ + pause(dropWhilePaused?: boolean): void; + /** + * Resume the provider. + */ + resume(): void; +} +//# sourceMappingURL=abstract-provider.d.ts.map \ No newline at end of file diff --git a/lib.esm/providers/abstract-provider.d.ts.map b/lib.esm/providers/abstract-provider.d.ts.map new file mode 100644 index 00000000..92268c99 --- /dev/null +++ b/lib.esm/providers/abstract-provider.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"abstract-provider.d.ts","sourceRoot":"","sources":["../../src.ts/providers/abstract-provider.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAaH,OAAO,EAIH,YAAY,EAGf,MAAM,mBAAmB,CAAC;AAK3B,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAe,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAE1G,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,CAAC,QAAQ,CAAC,CAAC;IAa1D,GAAG,CAAC,KAAK,EAAE,aAAa,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAiB7D,kBAAkB,CAAC,KAAK,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAexD,WAAW,CAAC,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAKpE,cAAc,CAAC,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAI7E;;;;;;OAMG;IACH,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED;;;;;OAKG;IACH,OAAO,IAAI,IAAI;IAYf;;;;;;;;;;OAUG;IACH,IAAI,MAAM,IAAI,OAAO,CAAwC;IAC7D,IAAI,MAAM,CAAC,KAAK,EAAE,OAAO,EAQxB;IAED;;;;OAIG;IACH,KAAK,CAAC,eAAe,CAAC,EAAE,OAAO,GAAG,IAAI;IAsBtC;;OAEG;IACH,MAAM,IAAI,IAAI;CAiBjB"} \ No newline at end of file diff --git a/lib.esm/providers/abstract-provider.js b/lib.esm/providers/abstract-provider.js new file mode 100644 index 00000000..8ad643a8 --- /dev/null +++ b/lib.esm/providers/abstract-provider.js @@ -0,0 +1,1378 @@ +/** + * The available providers should suffice for most developers purposes, + * but the [[AbstractProvider]] class has many features which enable + * sub-classing it for specific purposes. + * + * @_section: api/providers/abstract-provider: Subclassing Provider [abstract-provider] + */ +// @TODO +// Event coalescence +// When we register an event with an async value (e.g. address is a Signer +// or ENS name), we need to add it immeidately for the Event API, but also +// need time to resolve the address. Upon resolving the address, we need to +// migrate the listener to the static event. We also need to maintain a map +// of Signer/ENS name to address so we can sync respond to listenerCount. +import { resolveAddress } from "../address/index.js"; +import { ShardData } from "../constants/index.js"; +import { Transaction } from "../transaction/index.js"; +import { hexlify, isHexString, getBigInt, getNumber, makeError, assert, assertArgument, FetchRequest, toQuantity, defineProperties, EventPayload, resolveProperties, } from "../utils/index.js"; +import { formatBlock, formatLog, formatTransactionReceipt, formatTransactionResponse } from "./format.js"; +import { Network } from "./network.js"; +import { copyRequest, Block, FeeData, Log, TransactionReceipt, TransactionResponse } from "./provider.js"; +// Constants +const BN_2 = BigInt(2); +function isPromise(value) { + return (value && typeof (value.then) === "function"); +} +function getTag(prefix, value) { + return prefix + ":" + JSON.stringify(value, (k, v) => { + if (v == null) { + return "null"; + } + if (typeof (v) === "bigint") { + return `bigint:${v.toString()}`; + } + if (typeof (v) === "string") { + return v.toLowerCase(); + } + // Sort object keys + if (typeof (v) === "object" && !Array.isArray(v)) { + const keys = Object.keys(v); + keys.sort(); + return keys.reduce((accum, key) => { + accum[key] = v[key]; + return accum; + }, {}); + } + return v; + }); +} +/** + * An **UnmanagedSubscriber** is useful for events which do not require + * any additional management, such as ``"debug"`` which only requires + * emit in synchronous event loop triggered calls. + */ +export class UnmanagedSubscriber { + /** + * The name fof the event. + */ + name; + /** + * Create a new UnmanagedSubscriber with %%name%%. + */ + constructor(name) { defineProperties(this, { name }); } + start() { } + stop() { } + pause(dropWhilePaused) { } + resume() { } +} +function copy(value) { + return JSON.parse(JSON.stringify(value)); +} +function concisify(items) { + items = Array.from((new Set(items)).values()); + items.sort(); + return items; +} +async function getSubscription(_event, provider) { + if (_event == null) { + throw new Error("invalid event"); + } + // Normalize topic array info an EventFilter + if (Array.isArray(_event)) { + _event = { topics: _event }; + } + if (typeof (_event) === "string") { + switch (_event) { + case "block": + case "debug": + case "error": + case "finalized": + case "network": + case "pending": + case "safe": { + return { type: _event, tag: _event }; + } + } + } + if (isHexString(_event, 32)) { + const hash = _event.toLowerCase(); + return { type: "transaction", tag: getTag("tx", { hash }), hash }; + } + if (_event.orphan) { + const event = _event; + // @TODO: Should lowercase and whatnot things here instead of copy... + return { type: "orphan", tag: getTag("orphan", event), filter: copy(event) }; + } + if ((_event.address || _event.topics)) { + const event = _event; + const filter = { + topics: ((event.topics || []).map((t) => { + if (t == null) { + return null; + } + if (Array.isArray(t)) { + return concisify(t.map((t) => t.toLowerCase())); + } + return t.toLowerCase(); + })) + }; + if (event.address) { + const addresses = []; + const promises = []; + const addAddress = (addr) => { + if (isHexString(addr)) { + addresses.push(addr); + } + else { + promises.push((async () => { + addresses.push(await resolveAddress(addr)); + })()); + } + }; + if (Array.isArray(event.address)) { + event.address.forEach(addAddress); + } + else { + addAddress(event.address); + } + if (promises.length) { + await Promise.all(promises); + } + filter.address = concisify(addresses.map((a) => a.toLowerCase())); + } + return { filter, tag: getTag("event", filter), type: "event" }; + } + assertArgument(false, "unknown ProviderEvent", "event", _event); +} +function getTime() { return (new Date()).getTime(); } +const defaultOptions = { + cacheTimeout: 250, + pollingInterval: 4000 +}; +// type CcipArgs = { +// sender: string; +// urls: Array; +// calldata: string; +// selector: string; +// extraData: string; +// errorArgs: Array +// }; +/** + * An **AbstractProvider** provides a base class for other sub-classes to + * implement the [[Provider]] API by normalizing input arguments and + * formatting output results as well as tracking events for consistent + * behaviour on an eventually-consistent network. + */ +export class AbstractProvider { + _urlMap; + #connect; + #subs; + #plugins; + // null=unpaused, true=paused+dropWhilePaused, false=paused + #pausedState; + #destroyed; + #networkPromise; + #anyNetwork; + #performCache; + // The most recent block number if running an event or -1 if no "block" event + #lastBlockNumber; + #nextTimer; + #timers; + #disableCcipRead; + #options; + /** + * Create a new **AbstractProvider** connected to %%network%%, or + * use the various network detection capabilities to discover the + * [[Network]] if necessary. + */ + constructor(_network, options) { + this.#options = Object.assign({}, defaultOptions, options || {}); + if (_network === "any") { + this.#anyNetwork = true; + this.#networkPromise = null; + } + else if (_network) { + const network = Network.from(_network); + this.#anyNetwork = false; + this.#networkPromise = Promise.resolve(network); + setTimeout(() => { this.emit("network", network, null); }, 0); + } + else { + this.#anyNetwork = false; + this.#networkPromise = null; + } + this.#lastBlockNumber = -1; + this.#performCache = new Map(); + this.#subs = new Map(); + this.#plugins = new Map(); + this.#pausedState = null; + this.#destroyed = false; + this.#nextTimer = 1; + this.#timers = new Map(); + this.#disableCcipRead = false; + this.#connect = []; + this._urlMap = new Map(); + } + async initUrlMap(urls) { + if (urls instanceof FetchRequest) { + const primeUrl = urls.url.split(":")[0] + ":" + urls.url.split(":")[1] + ":9001"; + this._urlMap.set('0x', primeUrl); + urls.url = primeUrl; + this.#connect.push(urls); + const shards = await this.getRunningLocations(); + shards.forEach((shard) => { + const port = 9100 + 20 * shard[0] + shard[1]; + this._urlMap.set(`0x${shard[0].toString(16)}${shard[1].toString(16)}`, urls.url.split(":")[0] + ":" + urls.url.split(":")[1] + ":" + port); + }); + return; + } + for (const url of urls) { + const primeUrl = url.split(":")[0] + ":" + url.split(":")[1] + ":9001"; + this._urlMap.set('0x', primeUrl); + this.#connect.push(new FetchRequest(primeUrl)); + const shards = await this.getRunningLocations(); // Now waits for the previous to complete + shards.forEach((shard) => { + const port = 9100 + 20 * shard[0] + shard[1]; + this._urlMap.set(`0x${shard[0].toString(16)}${shard[1].toString(16)}`, url.split(":")[0] + ":" + url.split(":")[1] + ":" + port); + }); + } + } + shardBytes(shard) { + return ShardData.find(it => it.name == shard || + it.byte == shard || + it.nickname == shard || + it.shard == shard)?.byte || ''; + } + get connect() { return this.#connect; } + async shardFromAddress(_address) { + let address = this._getAddress(_address); + return (await address).slice(0, 4); + } + shardFromHash(hash) { + return hash.slice(0, 4); + } + async getLatestQuaiRate(shard, amt = 1) { + const blockNumber = await this.getBlockNumber(shard); + return this.getQuaiRateAtBlock(shard, blockNumber, amt); + } + async getQuaiRateAtBlock(shard, blockTag, amt = 1) { + let resolvedBlockTag = this._getBlockTag(shard, blockTag); + if (typeof resolvedBlockTag !== "string") { + resolvedBlockTag = await resolvedBlockTag; + } + return await this.#perform({ + method: "getQuaiRateAtBlock", + blockTag: resolvedBlockTag, + amt, + shard: shard + }); + } + async getProtocolExpansionNumber() { + return await this.#perform({ + method: "getProtocolExpansionNumber" + }); + } + async getLatestQiRate(shard, amt = 1) { + const blockNumber = await this.getBlockNumber(shard); + return this.getQiRateAtBlock(shard, blockNumber, amt); + } + async getQiRateAtBlock(shard, blockTag, amt = 1) { + let resolvedBlockTag = this._getBlockTag(shard, blockTag); + if (typeof resolvedBlockTag !== "string") { + resolvedBlockTag = await resolvedBlockTag; + } + return await this.#perform({ + method: "getQiRateAtBlock", + blockTag: resolvedBlockTag, + amt, + shard: shard + }); + } + get pollingInterval() { return this.#options.pollingInterval; } + /** + * Returns ``this``, to allow an **AbstractProvider** to implement + * the [[ContractRunner]] interface. + */ + get provider() { return this; } + /** + * Returns all the registered plug-ins. + */ + get plugins() { + return Array.from(this.#plugins.values()); + } + /** + * Attach a new plug-in. + */ + attachPlugin(plugin) { + if (this.#plugins.get(plugin.name)) { + throw new Error(`cannot replace existing plugin: ${plugin.name} `); + } + this.#plugins.set(plugin.name, plugin.connect(this)); + return this; + } + /** + * Get a plugin by name. + */ + getPlugin(name) { + return (this.#plugins.get(name)) || null; + } + /** + * Prevent any CCIP-read operation, regardless of whether requested + * in a [[call]] using ``enableCcipRead``. + */ + get disableCcipRead() { return this.#disableCcipRead; } + set disableCcipRead(value) { this.#disableCcipRead = !!value; } + // Shares multiple identical requests made during the same 250ms + async #perform(req) { + const timeout = this.#options.cacheTimeout; + // Caching disabled + if (timeout < 0) { + return await this._perform(req); + } + // Create a tag + const tag = getTag(req.method, req); + let perform = this.#performCache.get(tag); + if (!perform) { + perform = this._perform(req); + this.#performCache.set(tag, perform); + setTimeout(() => { + if (this.#performCache.get(tag) === perform) { + this.#performCache.delete(tag); + } + }, timeout); + } + return await perform; + } + /** + * Provides the opportunity for a sub-class to wrap a block before + * returning it, to add additional properties or an alternate + * sub-class of [[Block]]. + */ + _wrapBlock(value, network) { + return new Block(formatBlock(value), this); + } + /** + * Provides the opportunity for a sub-class to wrap a log before + * returning it, to add additional properties or an alternate + * sub-class of [[Log]]. + */ + _wrapLog(value, network) { + return new Log(formatLog(value), this); + } + /** + * Provides the opportunity for a sub-class to wrap a transaction + * receipt before returning it, to add additional properties or an + * alternate sub-class of [[TransactionReceipt]]. + */ + _wrapTransactionReceipt(value, network) { + return new TransactionReceipt(formatTransactionReceipt(value), this); + } + /** + * Provides the opportunity for a sub-class to wrap a transaction + * response before returning it, to add additional properties or an + * alternate sub-class of [[TransactionResponse]]. + */ + _wrapTransactionResponse(tx, network) { + return new TransactionResponse(formatTransactionResponse(tx), this); + } + /** + * Resolves to the Network, forcing a network detection using whatever + * technique the sub-class requires. + * + * Sub-classes **must** override this. + */ + _detectNetwork(shard) { + assert(false, "sub-classes must implement this", "UNSUPPORTED_OPERATION", { + operation: "_detectNetwork" + }); + } + /** + * Sub-classes should use this to perform all built-in operations. All + * methods sanitizes and normalizes the values passed into this. + * + * Sub-classes **must** override this. + */ + async _perform(req) { + assert(false, `unsupported method: ${req.method}`, "UNSUPPORTED_OPERATION", { + operation: req.method, + info: req + }); + } + // State + async getBlockNumber(shard) { + const blockNumber = getNumber(await this.#perform({ method: "getBlockNumber", shard: shard }), "%response"); + if (this.#lastBlockNumber >= 0) { + this.#lastBlockNumber = blockNumber; + } + return blockNumber; + } + /** + * Returns or resolves to the address for %%address%%, resolving ENS + * names and [[Addressable]] objects and returning if already an + * address. + */ + _getAddress(address) { + return resolveAddress(address); + } + /** + * Returns or resolves to a valid block tag for %%blockTag%%, resolving + * negative values and returning if already a valid block tag. + */ + _getBlockTag(shard, blockTag) { + if (blockTag == null) { + return "latest"; + } + switch (blockTag) { + case "earliest": + return "0x0"; + case "finalized": + case "latest": + case "pending": + case "safe": + return blockTag; + } + if (isHexString(blockTag)) { + if (isHexString(blockTag, 32)) { + return blockTag; + } + return toQuantity(blockTag); + } + if (typeof (blockTag) === "bigint") { + blockTag = getNumber(blockTag, "blockTag"); + } + if (typeof (blockTag) === "number") { + if (blockTag >= 0) { + return toQuantity(blockTag); + } + if (this.#lastBlockNumber >= 0) { + return toQuantity(this.#lastBlockNumber + blockTag); + } + return this.getBlockNumber(shard).then((b) => toQuantity(b + blockTag)); + } + assertArgument(false, "invalid blockTag", "blockTag", blockTag); + } + /** + * Returns or resolves to a filter for %%filter%%, resolving any ENS + * names or [[Addressable]] object and returning if already a valid + * filter. + */ + _getFilter(filter) { + // Create a canonical representation of the topics + const topics = (filter.topics || []).map((t) => { + if (t == null) { + return null; + } + if (Array.isArray(t)) { + return concisify(t.map((t) => t.toLowerCase())); + } + return t.toLowerCase(); + }); + const blockHash = ("blockHash" in filter) ? filter.blockHash : undefined; + const resolve = (_address, fromBlock, toBlock, shard) => { + let address = undefined; + switch (_address.length) { + case 0: break; + case 1: + address = _address[0]; + break; + default: + _address.sort(); + address = _address; + } + if (blockHash) { + if (fromBlock != null || toBlock != null) { + throw new Error("invalid filter"); + } + } + const filter = {}; + if (address) { + filter.address = address; + } + if (topics.length) { + filter.topics = topics; + } + if (fromBlock) { + filter.fromBlock = fromBlock; + } + if (toBlock) { + filter.toBlock = toBlock; + } + if (blockHash) { + filter.blockHash = blockHash; + } + if (shard) { + filter.shard = shard; + } + return filter; + }; + // Addresses could be async (ENS names or Addressables) + let address = []; + if (filter.address) { + if (Array.isArray(filter.address)) { + for (const addr of filter.address) { + address.push(this._getAddress(addr)); + } + } + else { + address.push(this._getAddress(filter.address)); + } + } + let fromBlock = undefined; + if ("fromBlock" in filter) { + fromBlock = this._getBlockTag(filter.shard, filter.fromBlock); + } + let toBlock = undefined; + if ("toBlock" in filter) { + toBlock = this._getBlockTag(filter.shard, filter.toBlock); + } + const shard = filter.shard; + if (address.filter((a) => (typeof (a) !== "string")).length || + (fromBlock != null && typeof (fromBlock) !== "string") || + (toBlock != null && typeof (toBlock) !== "string")) { + return Promise.all([Promise.all(address), fromBlock, toBlock, shard]).then((result) => { + return resolve(result[0], result[1], result[2]); + }); + } + return resolve(address, fromBlock, toBlock, shard); + } + /** + * Returns or resovles to a transaction for %%request%%, resolving + * any ENS names or [[Addressable]] and returning if already a valid + * transaction. + */ + _getTransactionRequest(_request) { + const request = copyRequest(_request); + const promises = []; + ["to", "from"].forEach((key) => { + if (request[key] == null) { + return; + } + const addr = resolveAddress(request[key]); + if (isPromise(addr)) { + promises.push((async function () { request[key] = await addr; })()); + } + else { + request[key] = addr; + } + }); + if (request.blockTag != null) { + const blockTag = this._getBlockTag(request.chainId?.toString(), request.blockTag); + if (isPromise(blockTag)) { + promises.push((async function () { request.blockTag = await blockTag; })()); + } + else { + request.blockTag = blockTag; + } + } + if (promises.length) { + return (async function () { + await Promise.all(promises); + return request; + })(); + } + return request; + } + async getNetwork(shard = 'prime') { + // No explicit network was set and this is our first time + if (this.#networkPromise == null) { + // Detect the current network (shared with all calls) + const detectNetwork = (async () => { + try { + const network = await this._detectNetwork(shard); + this.emit("network", network, null); + return network; + } + catch (error) { + if (this.#networkPromise === detectNetwork) { + this.#networkPromise = null; + } + throw error; + } + })(); + this.#networkPromise = detectNetwork; + return (await detectNetwork).clone(); + } + const networkPromise = this.#networkPromise; + const [expected, actual] = await Promise.all([ + networkPromise, + this._detectNetwork(shard) // The actual connected network + ]); + if (expected.chainId !== actual.chainId) { + if (this.#anyNetwork) { + // The "any" network can change, so notify listeners + this.emit("network", actual, expected); + // Update the network if something else hasn't already changed it + if (this.#networkPromise === networkPromise) { + this.#networkPromise = Promise.resolve(actual); + } + } + else { + // Otherwise, we do not allow changes to the underlying network + assert(false, `network changed: ${expected.chainId} => ${actual.chainId} `, "NETWORK_ERROR", { + event: "changed" + }); + } + } + return expected.clone(); + } + async getRunningLocations(shard) { + return await this.#perform(shard ? { method: "getRunningLocations", shard: shard } : { method: "getRunningLocations" }); + } + async getProtocolTrieExpansionCount(shard) { + return await this.#perform({ method: "getProtocolTrieExpansionCount", shard: shard }); + } + async getFeeData(shard, txType = true) { + const network = await this.getNetwork(); + const getFeeDataFunc = async () => { + const { gasPrice, priorityFee } = await resolveProperties({ + gasPrice: ((async () => { + try { + const value = await this.#perform({ method: "getGasPrice", txType, shard: shard }); + return getBigInt(value, "%response"); + } + catch (error) { } + return null; + })()), + priorityFee: ((async () => { + try { + const value = txType ? await this.#perform({ method: "getMaxPriorityFeePerGas", shard: shard }) : 0; + return getBigInt(value, "%response"); + } + catch (error) { } + return null; + })()) + }); + if (gasPrice == null) { + throw new Error("could not determine gasPrice"); + } + let maxFeePerGas = null; + let maxPriorityFeePerGas = null; + // These are the recommended EIP-1559 heuristics for fee data + maxPriorityFeePerGas = (priorityFee != null) ? priorityFee : BigInt("1000000000"); + maxFeePerGas = (gasPrice * BN_2) + maxPriorityFeePerGas; + return new FeeData(gasPrice, maxFeePerGas, maxPriorityFeePerGas); + }; + // Check for a FeeDataNetWorkPlugin + const plugin = network.getPlugin("org.quais.plugins.network.FetchUrlFeeDataPlugin"); + if (plugin) { + const req = new FetchRequest(plugin.url); + const feeData = await plugin.processFunc(getFeeDataFunc, this, req); + return new FeeData(feeData.gasPrice, feeData.maxFeePerGas, feeData.maxPriorityFeePerGas); + } + return await getFeeDataFunc(); + } + async estimateGas(_tx) { + let tx = this._getTransactionRequest(_tx); + if (isPromise(tx)) { + tx = await tx; + } + const shard = await this.shardFromAddress(tx.from); + return getBigInt(await this.#perform({ + method: "estimateGas", transaction: tx, shard: shard + }), "%response"); + } + async #call(tx, blockTag, attempt) { + // This came in as a PerformActionTransaction, so to/from are safe; we can cast + const transaction = copyRequest(tx); + try { + return hexlify(await this._perform({ method: "call", transaction, blockTag })); + } + catch (error) { + // CCIP Read OffchainLookup + // if (!this.disableCcipRead && isCallException(error) && error.data && attempt >= 0 && blockTag === "latest" && transaction.to != null && dataSlice(error.data, 0, 4) === "0x556f1830") { + // const data = error.data; + // const txSender = await resolveAddress(transaction.to, this); + // // Parse the CCIP Read Arguments + // let ccipArgs: CcipArgs; + // try { + // ccipArgs = parseOffchainLookup(dataSlice(error.data, 4)); + // } catch (error: any) { + // assert(false, error.message, "OFFCHAIN_FAULT", { + // reason: "BAD_DATA", transaction, info: { data } }); + // } + // // Check the sender of the OffchainLookup matches the transaction + // assert(ccipArgs.sender.toLowerCase() === txSender.toLowerCase(), + // "CCIP Read sender mismatch", "CALL_EXCEPTION", { + // action: "call", + // data, + // reason: "OffchainLookup", + // transaction: transaction, // @TODO: populate data? + // invocation: null, + // revert: { + // signature: "OffchainLookup(address,string[],bytes,bytes4,bytes)", + // name: "OffchainLookup", + // args: ccipArgs.errorArgs + // } + // }); + // const ccipResult = await this.ccipReadFetch(transaction, ccipArgs.calldata, ccipArgs.urls); + // assert(ccipResult != null, "CCIP Read failed to fetch data", "OFFCHAIN_FAULT", { + // reason: "FETCH_FAILED", transaction, info: { data: error.data, errorArgs: ccipArgs.errorArgs } }); + // const tx = { + // to: txSender, + // data: concat([ ccipArgs.selector, encodeBytes([ ccipResult, ccipArgs.extraData ]) ]) + // }; + // this.emit("debug", { action: "sendCcipReadCall", transaction: tx }); + // try { + // const result = await this.#call(tx, blockTag, attempt + 1); + // this.emit("debug", { action: "receiveCcipReadCallResult", transaction: Object.assign({ }, tx), result }); + // return result; + // } catch (error) { + // this.emit("debug", { action: "receiveCcipReadCallError", transaction: Object.assign({ }, tx), error }); + // throw error; + // } + // } + throw error; + } + } + async #checkNetwork(promise, shard) { + const { value } = await resolveProperties({ + network: this.getNetwork(), + value: promise + }); + return value; + } + async call(_tx) { + const shard = await this.shardFromAddress(_tx.from); + const { tx, blockTag } = await resolveProperties({ + tx: this._getTransactionRequest(_tx), + blockTag: this._getBlockTag(shard, _tx.blockTag) + }); + return await this.#checkNetwork(this.#call(tx, blockTag, -1), shard); + } + // Account + async #getAccountValue(request, _address, _blockTag) { + let address = this._getAddress(_address); + const shard = await this.shardFromAddress(_address); + let blockTag = this._getBlockTag(shard, _blockTag); + if (typeof (address) !== "string" || typeof (blockTag) !== "string") { + [address, blockTag] = await Promise.all([address, blockTag]); + } + return await this.#checkNetwork(this.#perform(Object.assign(request, { address, blockTag, shard: shard })), shard); + } + async getBalance(address, blockTag) { + return getBigInt(await this.#getAccountValue({ method: "getBalance" }, address, blockTag), "%response"); + } + async getTransactionCount(address, blockTag) { + return getNumber(await this.#getAccountValue({ method: "getTransactionCount" }, address, blockTag), "%response"); + } + async getCode(address, blockTag) { + return hexlify(await this.#getAccountValue({ method: "getCode" }, address, blockTag)); + } + async getStorage(address, _position, blockTag) { + const position = getBigInt(_position, "position"); + return hexlify(await this.#getAccountValue({ method: "getStorage", position }, address, blockTag)); + } + //TODO: Provider method which gets unspent utxos for an address + // Write + async broadcastTransaction(shard, signedTx) { + const { blockNumber, hash, network } = await resolveProperties({ + blockNumber: this.getBlockNumber(shard), + hash: this._perform({ + method: "broadcastTransaction", + signedTransaction: signedTx, + shard: shard + }), + network: this.getNetwork() + }); + const tx = Transaction.from(signedTx); + this.#validateTransactionHash(tx.hash || '', hash); + tx.hash = hash; + return this._wrapTransactionResponse(tx, network).replaceableTransaction(blockNumber); + } + async #validateTransactionHash(computedHash, nodehash) { + if (computedHash.substring(0, 4) !== nodehash.substring(0, 4)) + throw new Error("Transaction hash mismatch in origin Zone"); + if (computedHash.substring(6, 8) !== nodehash.substring(6, 8)) + throw new Error("Transaction hash mismatch in destination Zone"); + if (parseInt(computedHash[4], 16) < 8 !== parseInt(nodehash[4], 16) < 8) + throw new Error("Transaction ledger mismatch in origin Zone"); + if (parseInt(computedHash[8], 16) < 8 !== parseInt(nodehash[8], 16) < 8) + throw new Error("Transaction ledger mismatch in destination Zone"); + } + async #getBlock(shard, block, includeTransactions) { + // @TODO: Add CustomBlockPlugin check + if (isHexString(block, 32)) { + return await this.#perform({ + method: "getBlock", blockHash: block, includeTransactions, shard: shard + }); + } + let blockTag = this._getBlockTag(shard, block); + if (typeof (blockTag) !== "string") { + blockTag = await blockTag; + } + return await this.#perform({ + method: "getBlock", blockTag, includeTransactions, shard: shard + }); + } + // Queries + async getBlock(shard, block, prefetchTxs) { + const { network, params } = await resolveProperties({ + network: this.getNetwork(), + params: this.#getBlock(shard, block, !!prefetchTxs) + }); + if (params == null) { + return null; + } + return this._wrapBlock(params, network); + } + async getTransaction(hash) { + const shard = this.shardFromHash(hash); + const { network, params } = await resolveProperties({ + network: this.getNetwork(), + params: this.#perform({ method: "getTransaction", hash, shard: shard }) + }); + if (params == null) { + return null; + } + return this._wrapTransactionResponse(params, network); + } + async getTransactionReceipt(hash) { + const shard = this.shardFromHash(hash); + const { network, params } = await resolveProperties({ + network: this.getNetwork(), + params: this.#perform({ method: "getTransactionReceipt", hash, shard: shard }) + }); + if (params == null) { + return null; + } + // Some backends did not backfill the effectiveGasPrice in to old transactions + // in the receipt, so we look it up manually and inject it. + if (params.gasPrice == null && params.effectiveGasPrice == null) { + const tx = await this.#perform({ method: "getTransaction", hash, shard: shard }); + if (tx == null) { + throw new Error("report this; could not find tx or effectiveGasPrice"); + } + params.effectiveGasPrice = tx.gasPrice; + } + return this._wrapTransactionReceipt(params, network); + } + async getTransactionResult(hash) { + const shard = this.shardFromHash(hash); + const { result } = await resolveProperties({ + network: this.getNetwork(), + result: this.#perform({ method: "getTransactionResult", hash, shard: shard }) + }); + if (result == null) { + return null; + } + return hexlify(result); + } + // Bloom-filter Queries + async getLogs(_filter) { + let filter = this._getFilter(_filter); + if (isPromise(filter)) { + filter = await filter; + } + const shard = filter.shard; + const { network, params } = await resolveProperties({ + network: this.getNetwork(), + params: this.#perform({ method: "getLogs", filter, shard: shard }) + }); + return params.map((p) => this._wrapLog(p, network)); + } + // ENS + _getProvider(chainId) { + assert(false, "provider cannot connect to target network", "UNSUPPORTED_OPERATION", { + operation: "_getProvider()" + }); + } + async waitForTransaction(hash, _confirms, timeout) { + const shard = this.shardFromHash(hash); + const confirms = (_confirms != null) ? _confirms : 1; + if (confirms === 0) { + return this.getTransactionReceipt(hash); + } + return new Promise(async (resolve, reject) => { + let timer = null; + const listener = (async (blockNumber) => { + try { + const receipt = await this.getTransactionReceipt(hash); + if (receipt != null) { + if (blockNumber - receipt.blockNumber + 1 >= confirms) { + resolve(receipt); + //this.off("block", listener); + if (timer) { + clearTimeout(timer); + timer = null; + } + return; + } + } + } + catch (error) { + console.log("EEE", error); + } + this.once("block", listener); + }); + if (timeout != null) { + timer = setTimeout(() => { + if (timer == null) { + return; + } + timer = null; + this.off("block", listener); + reject(makeError("timeout", "TIMEOUT", { reason: "timeout" })); + }, timeout); + } + listener(await this.getBlockNumber(shard)); + }); + } + async waitForBlock(shard, blockTag) { + assert(false, "not implemented yet", "NOT_IMPLEMENTED", { + operation: "waitForBlock" + }); + } + /** + * Clear a timer created using the [[_setTimeout]] method. + */ + _clearTimeout(timerId) { + const timer = this.#timers.get(timerId); + if (!timer) { + return; + } + if (timer.timer) { + clearTimeout(timer.timer); + } + this.#timers.delete(timerId); + } + /** + * Create a timer that will execute %%func%% after at least %%timeout%% + * (in ms). If %%timeout%% is unspecified, then %%func%% will execute + * in the next event loop. + * + * [Pausing](AbstractProvider-paused) the provider will pause any + * associated timers. + */ + _setTimeout(_func, timeout) { + if (timeout == null) { + timeout = 0; + } + const timerId = this.#nextTimer++; + const func = () => { + this.#timers.delete(timerId); + _func(); + }; + if (this.paused) { + this.#timers.set(timerId, { timer: null, func, time: timeout }); + } + else { + const timer = setTimeout(func, timeout); + this.#timers.set(timerId, { timer, func, time: getTime() }); + } + return timerId; + } + /** + * Perform %%func%% on each subscriber. + */ + _forEachSubscriber(func) { + for (const sub of this.#subs.values()) { + func(sub.subscriber); + } + } + /** + * Sub-classes may override this to customize subscription + * implementations. + */ + _getSubscriber(sub) { + switch (sub.type) { + case "debug": + case "error": + case "network": + return new UnmanagedSubscriber(sub.type); + } + throw new Error("HTTP polling not supported. This method should be implemented by subclasses."); + } + /** + * If a [[Subscriber]] fails and needs to replace itself, this + * method may be used. + * + * For example, this is used for providers when using the + * ``eth_getFilterChanges`` method, which can return null if state + * filters are not supported by the backend, allowing the Subscriber + * to swap in a [[PollingEventSubscriber]]. + */ + _recoverSubscriber(oldSub, newSub) { + for (const sub of this.#subs.values()) { + if (sub.subscriber === oldSub) { + if (sub.started) { + sub.subscriber.stop(); + } + sub.subscriber = newSub; + if (sub.started) { + newSub.start(); + } + if (this.#pausedState != null) { + newSub.pause(this.#pausedState); + } + break; + } + } + } + async #hasSub(event, emitArgs) { + let sub = await getSubscription(event, this); + // This is a log that is removing an existing log; we actually want + // to emit an orphan event for the removed log + if (sub.type === "event" && emitArgs && emitArgs.length > 0 && emitArgs[0].removed === true) { + sub = await getSubscription({ orphan: "drop-log", log: emitArgs[0] }, this); + } + return this.#subs.get(sub.tag) || null; + } + async #getSub(event) { + const subscription = await getSubscription(event, this); + // Prevent tampering with our tag in any subclass' _getSubscriber + const tag = subscription.tag; + let sub = this.#subs.get(tag); + if (!sub) { + const subscriber = this._getSubscriber(subscription); + const addressableMap = new WeakMap(); + const nameMap = new Map(); + sub = { subscriber, tag, addressableMap, nameMap, started: false, listeners: [] }; + this.#subs.set(tag, sub); + } + return sub; + } + async on(event, listener) { + const sub = await this.#getSub(event); + sub.listeners.push({ listener, once: false }); + if (!sub.started) { + sub.subscriber.start(); + sub.started = true; + if (this.#pausedState != null) { + sub.subscriber.pause(this.#pausedState); + } + } + return this; + } + async once(event, listener) { + const sub = await this.#getSub(event); + sub.listeners.push({ listener, once: true }); + if (!sub.started) { + sub.subscriber.start(); + sub.started = true; + if (this.#pausedState != null) { + sub.subscriber.pause(this.#pausedState); + } + } + return this; + } + async emit(event, ...args) { + const sub = await this.#hasSub(event, args); + // If there is not subscription or if a recent emit removed + // the last of them (which also deleted the sub) do nothing + if (!sub || sub.listeners.length === 0) { + return false; + } + ; + const count = sub.listeners.length; + sub.listeners = sub.listeners.filter(({ listener, once }) => { + const payload = new EventPayload(this, (once ? null : listener), event); + try { + listener.call(this, ...args, payload); + } + catch (error) { } + return !once; + }); + if (sub.listeners.length === 0) { + if (sub.started) { + sub.subscriber.stop(); + } + this.#subs.delete(sub.tag); + } + return (count > 0); + } + async listenerCount(event) { + if (event) { + const sub = await this.#hasSub(event); + if (!sub) { + return 0; + } + return sub.listeners.length; + } + let total = 0; + for (const { listeners } of this.#subs.values()) { + total += listeners.length; + } + return total; + } + async listeners(event) { + if (event) { + const sub = await this.#hasSub(event); + if (!sub) { + return []; + } + return sub.listeners.map(({ listener }) => listener); + } + let result = []; + for (const { listeners } of this.#subs.values()) { + result = result.concat(listeners.map(({ listener }) => listener)); + } + return result; + } + async off(event, listener) { + const sub = await this.#hasSub(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 || sub.listeners.length === 0) { + if (sub.started) { + sub.subscriber.stop(); + } + this.#subs.delete(sub.tag); + } + return this; + } + async removeAllListeners(event) { + if (event) { + const { tag, started, subscriber } = await this.#getSub(event); + if (started) { + subscriber.stop(); + } + this.#subs.delete(tag); + } + else { + for (const [tag, { started, subscriber }] of this.#subs) { + if (started) { + subscriber.stop(); + } + this.#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 this.off(event, listener); + } + /** + * If this provider has been destroyed using the [[destroy]] method. + * + * Once destroyed, all resources are reclaimed, internal event loops + * and timers are cleaned up and no further requests may be sent to + * the provider. + */ + get destroyed() { + return this.#destroyed; + } + /** + * Sub-classes may use this to shutdown any sockets or release their + * resources and reject any pending requests. + * + * Sub-classes **must** call ``super.destroy()``. + */ + destroy() { + // Stop all listeners + this.removeAllListeners(); + // Shut down all tiemrs + for (const timerId of this.#timers.keys()) { + this._clearTimeout(timerId); + } + this.#destroyed = true; + } + /** + * Whether the provider is currently paused. + * + * A paused provider will not emit any events, and generally should + * not make any requests to the network, but that is up to sub-classes + * to manage. + * + * Setting ``paused = true`` is identical to calling ``.pause(false)``, + * which will buffer any events that occur while paused until the + * provider is unpaused. + */ + get paused() { return (this.#pausedState != null); } + set paused(pause) { + if (!!pause === this.paused) { + return; + } + if (this.paused) { + this.resume(); + } + else { + this.pause(false); + } + } + /** + * Pause the provider. If %%dropWhilePaused%%, any events that occur + * while paused are dropped, otherwise all events will be emitted once + * the provider is unpaused. + */ + pause(dropWhilePaused) { + this.#lastBlockNumber = -1; + if (this.#pausedState != null) { + if (this.#pausedState == !!dropWhilePaused) { + return; + } + assert(false, "cannot change pause type; resume first", "UNSUPPORTED_OPERATION", { + operation: "pause" + }); + } + this._forEachSubscriber((s) => s.pause(dropWhilePaused)); + this.#pausedState = !!dropWhilePaused; + for (const timer of this.#timers.values()) { + // Clear the timer + if (timer.timer) { + clearTimeout(timer.timer); + } + // Remaining time needed for when we become unpaused + timer.time = getTime() - timer.time; + } + } + /** + * Resume the provider. + */ + resume() { + if (this.#pausedState == null) { + return; + } + this._forEachSubscriber((s) => s.resume()); + this.#pausedState = null; + for (const timer of this.#timers.values()) { + // Remaining time when we were paused + let timeout = timer.time; + if (timeout < 0) { + timeout = 0; + } + // Start time (in cause paused, so we con compute remaininf time) + timer.time = getTime(); + // Start the timer + setTimeout(timer.func, timeout); + } + } +} +// function _parseString(result: string, start: number): null | string { +// try { +// const bytes = _parseBytes(result, start); +// if (bytes) { return toUtf8String(bytes); } +// } catch(error) { } +// return null; +// } +// function _parseBytes(result: string, start: number): null | string { +// if (result === "0x") { return null; } +// try { +// const offset = getNumber(dataSlice(result, start, start + 32)); +// const length = getNumber(dataSlice(result, offset, offset + 32)); +// +// return dataSlice(result, offset + 32, offset + 32 + length); +// } catch (error) { } +// return null; +// } +// function numPad(value: number): Uint8Array { +// const result = toBeArray(value); +// if (result.length > 32) { throw new Error("internal; should not happen"); } +// +// const padded = new Uint8Array(32); +// padded.set(result, 32 - result.length); +// return padded; +// } +// function bytesPad(value: Uint8Array): Uint8Array { +// if ((value.length % 32) === 0) { return value; } +// +// const result = new Uint8Array(Math.ceil(value.length / 32) * 32); +// result.set(value); +// return result; +// } +// const empty: Uint8Array = new Uint8Array([ ]); +// ABI Encodes a series of (bytes, bytes, ...) +// function encodeBytes(datas: Array): string { +// const result: Array = [ ]; +// +// let byteCount = 0; +// +// // Add place-holders for pointers as we add items +// for (let i = 0; i < datas.length; i++) { +// result.push(empty); +// byteCount += 32; +// } +// +// for (let i = 0; i < datas.length; i++) { +// const data = getBytes(datas[i]); +// +// // Update the bytes offset +// result[i] = numPad(byteCount); +// +// // The length and padded value of data +// result.push(numPad(data.length)); +// result.push(bytesPad(data)); +// byteCount += 32 + Math.ceil(data.length / 32) * 32; +// } +// +// return concat(result); +// } +// const zeros = "0x0000000000000000000000000000000000000000000000000000000000000000" +// function parseOffchainLookup(data: string): CcipArgs { +// const result: CcipArgs = { +// sender: "", urls: [ ], calldata: "", selector: "", extraData: "", errorArgs: [ ] +// }; +// +// assert(dataLength(data) >= 5 * 32, "insufficient OffchainLookup data", "OFFCHAIN_FAULT", { +// reason: "insufficient OffchainLookup data" +// }); +// +// const sender = dataSlice(data, 0, 32); +// assert(dataSlice(sender, 0, 12) === dataSlice(zeros, 0, 12), "corrupt OffchainLookup sender", "OFFCHAIN_FAULT", { +// reason: "corrupt OffchainLookup sender" +// }); +// result.sender = dataSlice(sender, 12); +// +// // Read the URLs from the response +// try { +// const urls: Array = []; +// const urlsOffset = getNumber(dataSlice(data, 32, 64)); +// const urlsLength = getNumber(dataSlice(data, urlsOffset, urlsOffset + 32)); +// const urlsData = dataSlice(data, urlsOffset + 32); +// for (let u = 0; u < urlsLength; u++) { +// const url = _parseString(urlsData, u * 32); +// if (url == null) { throw new Error("abort"); } +// urls.push(url); +// } +// result.urls = urls; +// } catch (error) { +// assert(false, "corrupt OffchainLookup urls", "OFFCHAIN_FAULT", { +// reason: "corrupt OffchainLookup urls" +// }); +// } +// +// // Get the CCIP calldata to forward +// try { +// const calldata = _parseBytes(data, 64); +// if (calldata == null) { throw new Error("abort"); } +// result.calldata = calldata; +// } catch (error) { +// assert(false, "corrupt OffchainLookup calldata", "OFFCHAIN_FAULT", { +// reason: "corrupt OffchainLookup calldata" +// }); +// } +// +// // Get the callbackSelector (bytes4) +// assert(dataSlice(data, 100, 128) === dataSlice(zeros, 0, 28), "corrupt OffchainLookup callbaackSelector", "OFFCHAIN_FAULT", { +// reason: "corrupt OffchainLookup callbaackSelector" +// }); +// result.selector = dataSlice(data, 96, 100); +// +// // Get the extra data to send back to the contract as context +// try { +// const extraData = _parseBytes(data, 128); +// if (extraData == null) { throw new Error("abort"); } +// result.extraData = extraData; +// } catch (error) { +// assert(false, "corrupt OffchainLookup extraData", "OFFCHAIN_FAULT", { +// reason: "corrupt OffchainLookup extraData" +// }); +// } +// +// result.errorArgs = "sender,urls,calldata,selector,extraData".split(/,/).map((k) => (result)[k]) +// +// return result; +// } +//# sourceMappingURL=abstract-provider.js.map \ No newline at end of file diff --git a/lib.esm/providers/abstract-provider.js.map b/lib.esm/providers/abstract-provider.js.map new file mode 100644 index 00000000..a97ac0ea --- /dev/null +++ b/lib.esm/providers/abstract-provider.js.map @@ -0,0 +1 @@ +{"version":3,"file":"abstract-provider.js","sourceRoot":"","sources":["../../src.ts/providers/abstract-provider.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,QAAQ;AACR,oBAAoB;AACpB,4EAA4E;AAC5E,4EAA4E;AAC5E,6EAA6E;AAC7E,6EAA6E;AAC7E,2EAA2E;AAE3E,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EACH,OAAO,EAAE,WAAW,EACpB,SAAS,EAAE,SAAS,EACpB,SAAS,EAAE,MAAM,EAAE,cAAc,EACjC,YAAY,EACZ,UAAU,EACV,gBAAgB,EAAE,YAAY,EAAE,iBAAiB,GACpD,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACH,WAAW,EAAE,SAAS,EAAE,wBAAwB,EAAE,yBAAyB,EAC9E,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,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,kDAAkD;AAClD,EAAE;AACF,oEAAoE;AACpE,YAAY;AACZ,oDAAoD;AACpD,+DAA+D;AAC/D,wCAAwC;AACxC,wBAAwB;AACxB,gFAAgF;AAChF,yDAAyD;AACzD,cAAc;AACd,QAAQ;AACR,EAAE;AACF,2GAA2G;AAC3G,EAAE;AACF,qBAAqB;AACrB,IAAI"} \ No newline at end of file diff --git a/lib.esm/providers/abstract-signer.d.ts b/lib.esm/providers/abstract-signer.d.ts new file mode 100644 index 00000000..a315ea6f --- /dev/null +++ b/lib.esm/providers/abstract-signer.d.ts @@ -0,0 +1,77 @@ +/** + * Generally the [[Wallet]] and [[JsonRpcSigner]] and their sub-classes + * are sufficent for most developers, but this is provided to + * fascilitate more complex Signers. + * + * @_section: api/providers/abstract-signer: Subclassing Signer [abstract-signer] + */ +import { AddressLike } from "../address/index.js"; +import type { TypedDataDomain, TypedDataField } from "../hash/index.js"; +import type { TransactionLike } from "../transaction/index.js"; +import type { BlockTag, Provider, TransactionRequest, TransactionResponse } from "./provider.js"; +import type { Signer } from "./signer.js"; +/** + * An **AbstractSigner** includes most of teh functionality required + * to get a [[Signer]] working as expected, but requires a few + * Signer-specific methods be overridden. + * + */ +export declare abstract class AbstractSigner

implements Signer { + /** + * The provider this signer is connected to. + */ + readonly provider: P; + /** + * Creates a new Signer connected to %%provider%%. + */ + constructor(provider?: P); + /** + * Resolves to the Signer address. + */ + abstract getAddress(): Promise; + _getAddress(address: AddressLike): string | Promise; + shardFromAddress(_address: AddressLike): Promise; + /** + * Returns the signer connected to %%provider%%. + * + * This may throw, for example, a Signer connected over a Socket or + * to a specific instance of a node may not be transferrable. + */ + abstract connect(provider: null | Provider): Signer; + getNonce(blockTag?: BlockTag): Promise; + populateCall(tx: TransactionRequest): Promise>; + populateTransaction(tx: TransactionRequest): Promise>; + populateUTXOTransaction(tx: TransactionRequest): Promise>; + estimateGas(tx: TransactionRequest): Promise; + call(tx: TransactionRequest): Promise; + sendTransaction(tx: TransactionRequest): Promise; + abstract signTransaction(tx: TransactionRequest): Promise; + abstract signMessage(message: string | Uint8Array): Promise; + abstract signTypedData(domain: TypedDataDomain, types: Record>, value: Record): Promise; +} +/** + * A **VoidSigner** is a class deisgned to allow an address to be used + * in any API which accepts a Signer, but for which there are no + * credentials available to perform any actual signing. + * + * This for example allow impersonating an account for the purpose of + * static calls or estimating gas, but does not allow sending transactions. + */ +export declare class VoidSigner extends AbstractSigner { + #private; + /** + * The signer address. + */ + readonly address: string; + /** + * Creates a new **VoidSigner** with %%address%% attached to + * %%provider%%. + */ + constructor(address: string, provider?: null | Provider); + getAddress(): Promise; + connect(provider: null | Provider): VoidSigner; + signTransaction(tx: TransactionRequest): Promise; + signMessage(message: string | Uint8Array): Promise; + signTypedData(domain: TypedDataDomain, types: Record>, value: Record): Promise; +} +//# sourceMappingURL=abstract-signer.d.ts.map \ No newline at end of file diff --git a/lib.esm/providers/abstract-signer.d.ts.map b/lib.esm/providers/abstract-signer.d.ts.map new file mode 100644 index 00000000..68c12402 --- /dev/null +++ b/lib.esm/providers/abstract-signer.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"abstract-signer.d.ts","sourceRoot":"","sources":["../../src.ts/providers/abstract-signer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAC,WAAW,EAAiB,MAAM,qBAAqB,CAAC;AAQhE,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE/D,OAAO,KAAK,EACR,QAAQ,EAAE,QAAQ,EAAE,kBAAkB,EAAE,mBAAmB,EAC9D,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AA+B1C;;;;;GAKG;AACH,8BAAsB,cAAc,CAAC,CAAC,SAAS,IAAI,GAAG,QAAQ,GAAG,IAAI,GAAG,QAAQ,CAAE,YAAW,MAAM;IA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AAE,KAAK,CAAC,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;CAC7I;AAED;;;;;;;GAOG;AACH,qBAAa,UAAW,SAAQ,cAAc;;IAC1C;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAG,MAAM,CAAC;IAE1B;;;OAGG;gBACS,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,IAAI,GAAG,QAAQ;IAKjD,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAEnC,OAAO,CAAC,QAAQ,EAAE,IAAI,GAAG,QAAQ,GAAG,UAAU;IAQxC,eAAe,CAAC,EAAE,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC;IAIxD,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC;IAI1D,aAAa,CAAC,MAAM,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;CAG1I"} \ No newline at end of file diff --git a/lib.esm/providers/abstract-signer.js b/lib.esm/providers/abstract-signer.js new file mode 100644 index 00000000..0f4d9556 --- /dev/null +++ b/lib.esm/providers/abstract-signer.js @@ -0,0 +1,189 @@ +/** + * Generally the [[Wallet]] and [[JsonRpcSigner]] and their sub-classes + * are sufficent for most developers, but this is provided to + * fascilitate more complex Signers. + * + * @_section: api/providers/abstract-signer: Subclassing Signer [abstract-signer] + */ +import { resolveAddress } from "../address/index.js"; +import { Transaction } from "../transaction/index.js"; +import { defineProperties, getBigInt, resolveProperties, assert, assertArgument, isUTXOAddress } from "../utils/index.js"; +import { copyRequest } from "./provider.js"; +import { getTxType } from "../utils/index.js"; +function checkProvider(signer, operation) { + if (signer.provider) { + return signer.provider; + } + assert(false, "missing provider", "UNSUPPORTED_OPERATION", { operation }); +} +async function populate(signer, tx) { + let pop = copyRequest(tx); + if (pop.to != null) { + pop.to = resolveAddress(pop.to); + } + if (pop.from != null) { + const from = pop.from; + pop.from = Promise.all([ + signer.getAddress(), + resolveAddress(from) + ]).then(([address, from]) => { + assertArgument(address.toLowerCase() === from.toLowerCase(), "transaction from mismatch", "tx.from", from); + return address; + }); + } + else { + pop.from = signer.getAddress(); + } + return await resolveProperties(pop); +} +/** + * An **AbstractSigner** includes most of teh functionality required + * to get a [[Signer]] working as expected, but requires a few + * Signer-specific methods be overridden. + * + */ +export class AbstractSigner { + /** + * The provider this signer is connected to. + */ + provider; + /** + * Creates a new Signer connected to %%provider%%. + */ + constructor(provider) { + defineProperties(this, { provider: (provider || null) }); + } + _getAddress(address) { + return resolveAddress(address); + } + async shardFromAddress(_address) { + let address = this._getAddress(_address); + return (await address).slice(0, 4); + } + async getNonce(blockTag) { + return checkProvider(this, "getTransactionCount").getTransactionCount(await this.getAddress(), blockTag); + } + async populateCall(tx) { + const pop = await populate(this, tx); + return pop; + } + // async populateQiTransaction(tx: TransactionRequest): Promise> { + // } + async populateTransaction(tx) { + const provider = checkProvider(this, "populateTransaction"); + const shard = await this.shardFromAddress(tx.from); + const pop = await populate(this, tx); + if (pop.type == null) { + pop.type = await getTxType(pop.from ?? null, pop.to ?? null); + } + if (pop.nonce == null) { + pop.nonce = await this.getNonce("pending"); + } + if (pop.gasLimit == null) { + if (pop.type == 0) + pop.gasLimit = await this.estimateGas(pop); + else { + //Special cases for type 2 tx to bypass address out of scope in the node + let temp = pop.to; + pop.to = "0x0000000000000000000000000000000000000000"; + pop.gasLimit = getBigInt(2 * Number(await this.estimateGas(pop))); + pop.to = temp; + } + } + // Populate the chain ID + const network = await (this.provider).getNetwork(); + if (pop.chainId != null) { + const chainId = getBigInt(pop.chainId); + assertArgument(chainId === network.chainId, "transaction chainId mismatch", "tx.chainId", shard); + } + else { + pop.chainId = network.chainId; + } + if (pop.maxFeePerGas == null || pop.maxPriorityFeePerGas == null) { + const feeData = await provider.getFeeData(shard); + if (pop.maxFeePerGas == null) { + pop.maxFeePerGas = feeData.maxFeePerGas; + } + if (pop.maxPriorityFeePerGas == null) { + pop.maxPriorityFeePerGas = feeData.maxPriorityFeePerGas; + } + } + //@TOOD: Don't await all over the place; save them up for + // the end for better batching + return await resolveProperties(pop); + } + async populateUTXOTransaction(tx) { + const pop = { + inputsUTXO: tx.inputs, + outputsUTXO: tx.outputs, + type: 2, + from: String(tx.from) + }; + //@TOOD: Don't await all over the place; save them up for + // the end for better batching + return await resolveProperties(pop); + } + async estimateGas(tx) { + return checkProvider(this, "estimateGas").estimateGas(await this.populateCall(tx)); + } + async call(tx) { + return checkProvider(this, "call").call(await this.populateCall(tx)); + } + async sendTransaction(tx) { + const provider = checkProvider(this, "sendTransaction"); + let sender = await this.getAddress(); + tx.from = sender; + const shard = await this.shardFromAddress(tx.from); + let pop; + if (isUTXOAddress(sender)) { + pop = await this.populateUTXOTransaction(tx); + } + else { + pop = await this.populateTransaction(tx); + } + // delete pop.from; + const txObj = Transaction.from(pop); + const signedTx = await this.signTransaction(txObj); + // console.log("signedTX: ", JSON.stringify(txObj)) + return await provider.broadcastTransaction(shard, signedTx); + } +} +/** + * A **VoidSigner** is a class deisgned to allow an address to be used + * in any API which accepts a Signer, but for which there are no + * credentials available to perform any actual signing. + * + * This for example allow impersonating an account for the purpose of + * static calls or estimating gas, but does not allow sending transactions. + */ +export class VoidSigner extends AbstractSigner { + /** + * The signer address. + */ + address; + /** + * Creates a new **VoidSigner** with %%address%% attached to + * %%provider%%. + */ + constructor(address, provider) { + super(provider); + defineProperties(this, { address }); + } + async getAddress() { return this.address; } + connect(provider) { + return new VoidSigner(this.address, provider); + } + #throwUnsupported(suffix, operation) { + assert(false, `VoidSigner cannot sign ${suffix}`, "UNSUPPORTED_OPERATION", { operation }); + } + async signTransaction(tx) { + this.#throwUnsupported("transactions", "signTransaction"); + } + async signMessage(message) { + this.#throwUnsupported("messages", "signMessage"); + } + async signTypedData(domain, types, value) { + this.#throwUnsupported("typed-data", "signTypedData"); + } +} +//# sourceMappingURL=abstract-signer.js.map \ No newline at end of file diff --git a/lib.esm/providers/abstract-signer.js.map b/lib.esm/providers/abstract-signer.js.map new file mode 100644 index 00000000..672affb9 --- /dev/null +++ b/lib.esm/providers/abstract-signer.js.map @@ -0,0 +1 @@ +{"version":3,"file":"abstract-signer.js","sourceRoot":"","sources":["../../src.ts/providers/abstract-signer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAc,cAAc,EAAC,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EACH,gBAAgB,EAAE,SAAS,EAAE,iBAAiB,EAC9C,MAAM,EAAE,cAAc,EAAE,aAAa,EACxC,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAS5C,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,SAAS,aAAa,CAAC,MAAsB,EAAE,SAAiB;IAC5D,IAAI,MAAM,CAAC,QAAQ,EAAE;QAAE,OAAO,MAAM,CAAC,QAAQ,CAAC;KAAE;IAChD,MAAM,CAAC,KAAK,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;AAC9E,CAAC;AAED,KAAK,UAAU,QAAQ,CAAC,MAAsB,EAAE,EAAsB;IAClE,IAAI,GAAG,GAAQ,WAAW,CAAC,EAAE,CAAC,CAAC;IAE/B,IAAI,GAAG,CAAC,EAAE,IAAI,IAAI,EAAE;QAAE,GAAG,CAAC,EAAE,GAAG,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;KAAE;IAExD,IAAI,GAAG,CAAC,IAAI,IAAI,IAAI,EAAE;QAClB,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI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E,EAAE,OAAO,EAAE,CAAC,CAAC;IACpD,CAAC;IAED,KAAK,CAAC,UAAU,KAAsB,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAE5D,OAAO,CAAC,QAAyB;QAC7B,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAClD,CAAC;IAED,iBAAiB,CAAC,MAAc,EAAE,SAAiB;QAC/C,MAAM,CAAC,KAAK,EAAE,0BAA2B,MAAO,EAAE,EAAE,uBAAuB,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;IAChG,CAAC;IAED,KAAK,CAAC,eAAe,CAAC,EAAsB;QACxC,IAAI,CAAC,iBAAiB,CAAC,cAAc,EAAE,iBAAiB,CAAC,CAAC;IAC9D,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,OAA4B;QAC1C,IAAI,CAAC,iBAAiB,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,MAAuB,EAAE,KAA4C,EAAE,KAA0B;QACjH,IAAI,CAAC,iBAAiB,CAAC,YAAY,EAAE,eAAe,CAAC,CAAC;IAC1D,CAAC;CACJ"} \ No newline at end of file diff --git a/lib.esm/providers/community.d.ts b/lib.esm/providers/community.d.ts new file mode 100644 index 00000000..f9ee4935 --- /dev/null +++ b/lib.esm/providers/community.d.ts @@ -0,0 +1,29 @@ +/** + * There are many awesome community services that provide Ethereum + * nodes both for developers just starting out and for large-scale + * communities. + * + * @_section: api/providers/thirdparty: Community Providers [thirdparty] + */ +/** + * Providers which offer community credentials should extend this + * to notify any interested consumers whether community credentials + * are in-use. + */ +export interface CommunityResourcable { + /** + * Returns true of the instance is connected using the community + * credentials. + */ + isCommunityResource(): boolean; +} +/** + * Displays a warning in tht console when the community resource is + * being used too heavily by the app, recommending the developer + * acquire their own credentials instead of using the community + * credentials. + * + * The notification will only occur once per service. + */ +export declare function showThrottleMessage(service: string): void; +//# sourceMappingURL=community.d.ts.map \ No newline at end of file diff --git a/lib.esm/providers/community.d.ts.map b/lib.esm/providers/community.d.ts.map new file mode 100644 index 00000000..ffecbb46 --- /dev/null +++ b/lib.esm/providers/community.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"community.d.ts","sourceRoot":"","sources":["../../src.ts/providers/community.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACjC;;;OAGG;IACH,mBAAmB,IAAI,OAAO,CAAC;CAClC;AAKD;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAgBzD"} \ No newline at end of file diff --git a/lib.esm/providers/community.js b/lib.esm/providers/community.js new file mode 100644 index 00000000..47dfd930 --- /dev/null +++ b/lib.esm/providers/community.js @@ -0,0 +1,36 @@ +/** + * There are many awesome community services that provide Ethereum + * nodes both for developers just starting out and for large-scale + * communities. + * + * @_section: api/providers/thirdparty: Community Providers [thirdparty] + */ +// Show the throttle message only once per service +const shown = new Set(); +/** + * Displays a warning in tht console when the community resource is + * being used too heavily by the app, recommending the developer + * acquire their own credentials instead of using the community + * credentials. + * + * The notification will only occur once per service. + */ +export function showThrottleMessage(service) { + if (shown.has(service)) { + return; + } + shown.add(service); + console.log("========= NOTICE ========="); + console.log(`Request-Rate Exceeded for ${service} (this message will not be repeated)`); + console.log(""); + console.log("The default API keys for each service are provided as a highly-throttled,"); + console.log("community resource for low-traffic projects and early prototyping."); + console.log(""); + console.log("While your application will continue to function, we highly recommended"); + console.log("signing up for your own API keys to improve performance, increase your"); + console.log("request rate/limit and enable other perks, such as metrics and advanced APIs."); + console.log(""); + console.log("For more details: https:/\/docs.quais.org/api-keys/"); + console.log("=========================="); +} +//# sourceMappingURL=community.js.map \ No newline at end of file diff --git a/lib.esm/providers/community.js.map b/lib.esm/providers/community.js.map new file mode 100644 index 00000000..5fbf5f28 --- /dev/null +++ b/lib.esm/providers/community.js.map @@ -0,0 +1 @@ +{"version":3,"file":"community.js","sourceRoot":"","sources":["../../src.ts/providers/community.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAeH,kDAAkD;AAClD,MAAM,KAAK,GAAgB,IAAI,GAAG,EAAE,CAAC;AAErC;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAe;IAC/C,IAAI,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE;QAAE,OAAO;KAAE;IACnC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAEnB,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAA;IACzC,OAAO,CAAC,GAAG,CAAC,6BAA8B,OAAQ,sCAAsC,CAAC,CAAC;IAC1F,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChB,OAAO,CAAC,GAAG,CAAC,2EAA2E,CAAC,CAAC;IACzF,OAAO,CAAC,GAAG,CAAC,oEAAoE,CAAC,CAAC;IAClF,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChB,OAAO,CAAC,GAAG,CAAC,yEAAyE,CAAC,CAAC;IACvF,OAAO,CAAC,GAAG,CAAC,wEAAwE,CAAC,CAAC;IACtF,OAAO,CAAC,GAAG,CAAC,+EAA+E,CAAC,CAAC;IAC7F,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChB,OAAO,CAAC,GAAG,CAAC,qDAAqD,CAAC,CAAC;IACnE,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;AAC9C,CAAC"} \ No newline at end of file diff --git a/lib.esm/providers/contracts.d.ts b/lib.esm/providers/contracts.d.ts new file mode 100644 index 00000000..168b454f --- /dev/null +++ b/lib.esm/providers/contracts.d.ts @@ -0,0 +1,32 @@ +import type { Provider, TransactionRequest, TransactionResponse } from "./provider.js"; +/** + * A **ContractRunner** is a generic interface which defines an object + * capable of interacting with a Contract on the network. + * + * The more operations supported, the more utility it is capable of. + * + * The most common ContractRunners are [Providers](Provider) which enable + * read-only access and [Signers](Signer) which enable write-access. + */ +export interface ContractRunner { + /** + * The provider used for necessary state querying operations. + * + * This can also point to the **ContractRunner** itself, in the + * case of an [[AbstractProvider]]. + */ + provider: null | Provider; + /** + * Required to estimate gas. + */ + estimateGas?: (tx: TransactionRequest) => Promise; + /** + * Required for pure, view or static calls to contracts. + */ + call?: (tx: TransactionRequest) => Promise; + /** + * Required for state mutating calls + */ + sendTransaction?: (tx: TransactionRequest) => Promise; +} +//# sourceMappingURL=contracts.d.ts.map \ No newline at end of file diff --git a/lib.esm/providers/contracts.d.ts.map b/lib.esm/providers/contracts.d.ts.map new file mode 100644 index 00000000..0a25e76c --- /dev/null +++ b/lib.esm/providers/contracts.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"contracts.d.ts","sourceRoot":"","sources":["../../src.ts/providers/contracts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,QAAQ,EAAE,kBAAkB,EAAE,mBAAmB,EACpD,MAAM,eAAe,CAAC;AAEvB;;;;;;;;GAQG;AACH,MAAM,WAAW,cAAc;IAC3B;;;;;OAKG;IACH,QAAQ,EAAE,IAAI,GAAG,QAAQ,CAAC;IAE1B;;OAEG;IACH,WAAW,CAAC,EAAE,CAAC,EAAE,EAAE,kBAAkB,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAE1D;;OAEG;IACH,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,kBAAkB,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAEnD;;OAEG;IACH,eAAe,CAAC,EAAE,CAAC,EAAE,EAAE,kBAAkB,KAAK,OAAO,CAAC,mBAAmB,CAAC,CAAC;CAC9E"} \ No newline at end of file diff --git a/lib.esm/providers/contracts.js b/lib.esm/providers/contracts.js new file mode 100644 index 00000000..202a39eb --- /dev/null +++ b/lib.esm/providers/contracts.js @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=contracts.js.map \ No newline at end of file diff --git a/lib.esm/providers/contracts.js.map b/lib.esm/providers/contracts.js.map new file mode 100644 index 00000000..42ac4de8 --- /dev/null +++ b/lib.esm/providers/contracts.js.map @@ -0,0 +1 @@ +{"version":3,"file":"contracts.js","sourceRoot":"","sources":["../../src.ts/providers/contracts.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/lib.esm/providers/default-provider.d.ts b/lib.esm/providers/default-provider.d.ts new file mode 100644 index 00000000..a869dc5c --- /dev/null +++ b/lib.esm/providers/default-provider.d.ts @@ -0,0 +1,48 @@ +import type { AbstractProvider } from "./abstract-provider.js"; +import type { Networkish } from "./network.js"; +import { WebSocketLike } from "./provider-websocket.js"; +/** + * Returns a default provider for %%network%%. + * + * If %%network%% is a [[WebSocketLike]] or string that begins with + * ``"ws:"`` or ``"wss:"``, a [[WebSocketProvider]] is returned backed + * by that WebSocket or URL. + * + * If %%network%% is a string that begins with ``"HTTP:"`` or ``"HTTPS:"``, + * a [[JsonRpcProvider]] is returned connected to that URL. + * + * Otherwise, a default provider is created backed by well-known public + * Web3 backends (such as [[link-infura]]) using community-provided API + * keys. + * + * The %%options%% allows specifying custom API keys per backend (setting + * an API key to ``"-"`` will omit that provider) and ``options.exclusive`` + * can be set to either a backend name or and array of backend names, which + * will whitelist **only** those backends. + * + * Current backend strings supported are: + * - ``"alchemy"`` + * - ``"ankr"`` + * - ``"cloudflare"`` + * - ``"quaiscan"`` + * - ``"infura"`` + * - ``"publicPolygon"`` + * - ``"quicknode"`` + * + * @example: + * // Connect to a local Geth node + * provider = getDefaultProvider("http://localhost:8545/"); + * + * // Connect to Ethereum mainnet with any current and future + * // third-party services available + * provider = getDefaultProvider("mainnet"); + * + * // Connect to Polygon, but only allow quaiscan and + * // INFURA and use "MY_API_KEY" in calls to quaiscan. + * provider = getDefaultProvider("matic", { + * quaiscan: "MY_API_KEY", + * exclusive: [ "quaiscan", "infura" ] + * }); + */ +export declare function getDefaultProvider(network: string | string[] | Networkish | WebSocketLike, options?: any): AbstractProvider; +//# sourceMappingURL=default-provider.d.ts.map \ No newline at end of file diff --git a/lib.esm/providers/default-provider.d.ts.map b/lib.esm/providers/default-provider.d.ts.map new file mode 100644 index 00000000..a4680d53 --- /dev/null +++ b/lib.esm/providers/default-provider.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"default-provider.d.ts","sourceRoot":"","sources":["../../src.ts/providers/default-provider.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AASxD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,UAAU,GAAG,aAAa,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,gBAAgB,CAsF3H"} \ No newline at end of file diff --git a/lib.esm/providers/default-provider.js b/lib.esm/providers/default-provider.js new file mode 100644 index 00000000..56260918 --- /dev/null +++ b/lib.esm/providers/default-provider.js @@ -0,0 +1,138 @@ +import { assert } from "../utils/index.js"; +import { FallbackProvider } from "./provider-fallback.js"; +import { JsonRpcProvider } from "./provider-jsonrpc.js"; +import { Network } from "./network.js"; +import { WebSocketProvider } from "./provider-websocket.js"; +function isWebSocketLike(value) { + return (value && typeof (value.send) === "function" && + typeof (value.close) === "function"); +} +const Testnets = "goerli kovan sepolia classicKotti optimism-goerli arbitrum-goerli matic-mumbai bnbt".split(" "); +/** + * Returns a default provider for %%network%%. + * + * If %%network%% is a [[WebSocketLike]] or string that begins with + * ``"ws:"`` or ``"wss:"``, a [[WebSocketProvider]] is returned backed + * by that WebSocket or URL. + * + * If %%network%% is a string that begins with ``"HTTP:"`` or ``"HTTPS:"``, + * a [[JsonRpcProvider]] is returned connected to that URL. + * + * Otherwise, a default provider is created backed by well-known public + * Web3 backends (such as [[link-infura]]) using community-provided API + * keys. + * + * The %%options%% allows specifying custom API keys per backend (setting + * an API key to ``"-"`` will omit that provider) and ``options.exclusive`` + * can be set to either a backend name or and array of backend names, which + * will whitelist **only** those backends. + * + * Current backend strings supported are: + * - ``"alchemy"`` + * - ``"ankr"`` + * - ``"cloudflare"`` + * - ``"quaiscan"`` + * - ``"infura"`` + * - ``"publicPolygon"`` + * - ``"quicknode"`` + * + * @example: + * // Connect to a local Geth node + * provider = getDefaultProvider("http://localhost:8545/"); + * + * // Connect to Ethereum mainnet with any current and future + * // third-party services available + * provider = getDefaultProvider("mainnet"); + * + * // Connect to Polygon, but only allow quaiscan and + * // INFURA and use "MY_API_KEY" in calls to quaiscan. + * provider = getDefaultProvider("matic", { + * quaiscan: "MY_API_KEY", + * exclusive: [ "quaiscan", "infura" ] + * }); + */ +export function getDefaultProvider(network, options) { + if (options == null) { + options = {}; + } + const allowService = (name) => { + if (options[name] === "-") { + return false; + } + if (typeof (options.exclusive) === "string") { + return (name === options.exclusive); + } + if (Array.isArray(options.exclusive)) { + return (options.exclusive.indexOf(name) !== -1); + } + return true; + }; + if (typeof (network) === "string" && network.match(/^https?:/)) { + return new JsonRpcProvider(network); + } + if (Array.isArray(network) && network[0].match(/^https?:/)) { + return new JsonRpcProvider(network); + } + if (typeof (network) === "string" && network.match(/^wss?:/) || isWebSocketLike(network)) { + return new WebSocketProvider(network); + } + if (Array.isArray(network) && (network[0].match(/^wss?:/) || isWebSocketLike(network[0]))) { + return new WebSocketProvider(network[0]); + } + if (Array.isArray(network)) { + assert(false, "unsupported default network", "UNSUPPORTED_OPERATION", { + operation: "getDefaultProvider" + }); + } + // Get the network and name, if possible + let staticNetwork = null; + try { + staticNetwork = Network.from(network); + } + catch (error) { } + const providers = []; + if (allowService("publicPolygon") && staticNetwork) { + if (staticNetwork.name === "matic") { + providers.push(new JsonRpcProvider("https:/\/polygon-rpc.com/", staticNetwork, { staticNetwork })); + } + } + /* + if (options.pocket !== "-") { + try { + let appId = options.pocket; + let secretKey: undefined | string = undefined; + let loadBalancer: undefined | boolean = undefined; + if (typeof(appId) === "object") { + loadBalancer = !!appId.loadBalancer; + secretKey = appId.secretKey; + appId = appId.appId; + } + providers.push(new PocketProvider(network, appId, secretKey, loadBalancer)); + } catch (error) { console.log(error); } + } + */ + assert(providers.length, "unsupported default network", "UNSUPPORTED_OPERATION", { + operation: "getDefaultProvider" + }); + // No need for a FallbackProvider + if (providers.length === 1) { + return providers[0]; + } + // We use the floor because public third-party providers can be unreliable, + // so a low number of providers with a large quorum will fail too often + let quorum = Math.floor(providers.length / 2); + if (quorum > 2) { + quorum = 2; + } + // Testnets don't need as strong a security gaurantee and speed is + // more useful during testing + if (staticNetwork && Testnets.indexOf(staticNetwork.name) !== -1) { + quorum = 1; + } + // Provided override qorum takes priority + if (options && options.quorum) { + quorum = options.quorum; + } + return new FallbackProvider(providers, undefined, { quorum }); +} +//# sourceMappingURL=default-provider.js.map \ No newline at end of file diff --git a/lib.esm/providers/default-provider.js.map b/lib.esm/providers/default-provider.js.map new file mode 100644 index 00000000..fdb2549f --- /dev/null +++ b/lib.esm/providers/default-provider.js.map @@ -0,0 +1 @@ +{"version":3,"file":"default-provider.js","sourceRoot":"","sources":["../../src.ts/providers/default-provider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAM5D,SAAS,eAAe,CAAC,KAAU;IAC/B,OAAO,CAAC,KAAK,IAAI,OAAM,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,UAAU;QAC9C,OAAM,CAAC,KAAK,CAAC,KAAK,CAAC,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AAC,CAAC,CAAC;IAC9C,IAAI,MAAM,GAAG,CAAC,EAAE;QAAE,MAAM,GAAG,CAAC,CAAC;KAAE;IAE/B,kEAAkE;IAClE,6BAA6B;IAC7B,IAAI,aAAa,IAAI,QAAQ,CAAC,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE;QAAE,MAAM,GAAG,CAAC,CAAC;KAAE;IAEjF,yCAAyC;IACzC,IAAI,OAAO,IAAI,OAAO,CAAC,MAAM,EAAE;QAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;KAAE;IAE3D,OAAO,IAAI,gBAAgB,CAAC,SAAS,EAAE,SAAS,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;AAClE,CAAC"} \ No newline at end of file diff --git a/lib.esm/providers/ens-resolver.d.ts b/lib.esm/providers/ens-resolver.d.ts new file mode 100644 index 00000000..7019a6fd --- /dev/null +++ b/lib.esm/providers/ens-resolver.d.ts @@ -0,0 +1,147 @@ +/** + * ENS is a service which allows easy-to-remember names to map to + * network addresses. + * + * @_section: api/providers/ens-resolver:ENS Resolver [about-ens-rsolver] + */ +import type { BytesLike } from "../utils/index.js"; +import type { AbstractProvider, AbstractProviderPlugin } from "./abstract-provider.js"; +import type { Provider } from "./provider.js"; +/** + * The type of data found during a steip during avatar resolution. + */ +export type AvatarLinkageType = "name" | "avatar" | "!avatar" | "url" | "data" | "ipfs" | "erc721" | "erc1155" | "!erc721-caip" | "!erc1155-caip" | "!owner" | "owner" | "!balance" | "balance" | "metadata-url-base" | "metadata-url-expanded" | "metadata-url" | "!metadata-url" | "!metadata" | "metadata" | "!imageUrl" | "imageUrl-ipfs" | "imageUrl" | "!imageUrl-ipfs"; +/** + * An individual record for each step during avatar resolution. + */ +export interface AvatarLinkage { + /** + * The type of linkage. + */ + type: AvatarLinkageType; + /** + * The linkage value. + */ + value: string; +} +/** + * When resolving an avatar for an ENS name, there are many + * steps involved, fetching metadata, validating results, et cetera. + * + * Some applications may wish to analyse this data, or use this data + * to diagnose promblems, so an **AvatarResult** provides details of + * each completed step during avatar resolution. + */ +export interface AvatarResult { + /** + * How the [[url]] was arrived at, resolving the many steps required + * for an avatar URL. + */ + linkage: Array; + /** + * The avatar URL or null if the avatar was not set, or there was + * an issue during validation (such as the address not owning the + * avatar or a metadata error). + */ + url: null | string; +} +/** + * A provider plugin super-class for processing multicoin address types. + */ +export declare abstract class MulticoinProviderPlugin implements AbstractProviderPlugin { + /** + * The name. + */ + readonly name: string; + /** + * Creates a new **MulticoinProviderPluing** for %%name%%. + */ + constructor(name: string); + connect(proivder: Provider): MulticoinProviderPlugin; + /** + * Returns ``true`` if %%coinType%% is supported by this plugin. + */ + supportsCoinType(coinType: number): boolean; + /** + * Resovles to the encoded %%address%% for %%coinType%%. + */ + encodeAddress(coinType: number, address: string): Promise; + /** + * Resovles to the decoded %%data%% for %%coinType%%. + */ + decodeAddress(coinType: number, data: BytesLike): Promise; +} +/** + * A **BasicMulticoinProviderPlugin** provides service for common + * coin types, which do not require additional libraries to encode or + * decode. + */ +export declare class BasicMulticoinProviderPlugin extends MulticoinProviderPlugin { + /** + * Creates a new **BasicMulticoinProviderPlugin**. + */ + constructor(); +} +/** + * A connected object to a resolved ENS name resolver, which can be + * used to query additional details. + */ +export declare class EnsResolver { + #private; + /** + * The connected provider. + */ + provider: AbstractProvider; + /** + * The address of the resolver. + */ + address: string; + /** + * The name this resolver was resolved against. + */ + name: string; + constructor(provider: AbstractProvider, address: string, name: string); + /** + * Resolves to true if the resolver supports wildcard resolution. + */ + supportsWildcard(): Promise; + /** + * Resolves to the address for %%coinType%% or null if the + * provided %%coinType%% has not been configured. + */ + getAddress(coinType?: number): Promise; + /** + * Resolves to the EIP-634 text record for %%key%%, or ``null`` + * if unconfigured. + */ + getText(key: string): Promise; + /** + * Rsolves to the content-hash or ``null`` if unconfigured. + */ + getContentHash(): Promise; + /** + * Resolves to the avatar url or ``null`` if the avatar is either + * unconfigured or incorrectly configured (e.g. references an NFT + * not owned by the address). + * + * If diagnosing issues with configurations, the [[_getAvatar]] + * method may be useful. + */ + getAvatar(): Promise; + /** + * When resolving an avatar, there are many steps involved, such + * fetching metadata and possibly validating ownership of an + * NFT. + * + * This method can be used to examine each step and the value it + * was working from. + */ + _getAvatar(): Promise; + static getEnsAddress(provider: Provider): Promise; + /** + * Resolve to the ENS resolver for %%name%% using %%provider%% or + * ``null`` if unconfigured. + */ + static fromName(provider: AbstractProvider, name: string): Promise; +} +//# sourceMappingURL=ens-resolver.d.ts.map \ No newline at end of file diff --git a/lib.esm/providers/ens-resolver.d.ts.map b/lib.esm/providers/ens-resolver.d.ts.map new file mode 100644 index 00000000..5bbaa89f --- /dev/null +++ b/lib.esm/providers/ens-resolver.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"ens-resolver.d.ts","sourceRoot":"","sources":["../../src.ts/providers/ens-resolver.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAeH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAEvF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAgB9C;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,GACnF,QAAQ,GAAG,SAAS,GAAG,cAAc,GAAG,eAAe,GACvD,QAAQ,GAAG,OAAO,GAAG,UAAU,GAAG,SAAS,GAC3C,mBAAmB,GAAG,uBAAuB,GAAG,cAAc,GAAG,eAAe,GAChF,WAAW,GAAG,UAAU,GACxB,WAAW,GAAG,eAAe,GAAG,UAAU,GAAG,gBAAgB,CAAC;AAElE;;GAEG;AACH,MAAM,WAAW,aAAa;IAC1B;;OAEG;IACH,IAAI,EAAE,iBAAiB,CAAC;IAExB;;OAEG;IACH,KAAK,EAAE,MAAM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OAEG;IACG,cAAc,IAAI,OAAO,CAAC,IAAI,GAAG,MAAM,CAAC;IA6B9C;;;;;;;OAOG;IACG,SAAS,IAAI,OAAO,CAAC,IAAI,GAAG,MAAM,CAAC;IAKzC;;;;;;;OAOG;IACG,UAAU,IAAI,OAAO,CAAC,YAAY,CAAC;WAgK5B,aAAa,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC;IAoC/D;;;OAGG;WACU,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,WAAW,CAAC;CA2B/F"} \ No newline at end of file diff --git a/lib.esm/providers/ens-resolver.js b/lib.esm/providers/ens-resolver.js new file mode 100644 index 00000000..579ba8e6 --- /dev/null +++ b/lib.esm/providers/ens-resolver.js @@ -0,0 +1,496 @@ +/** + * ENS is a service which allows easy-to-remember names to map to + * network addresses. + * + * @_section: api/providers/ens-resolver:ENS Resolver [about-ens-rsolver] + */ +import { getAddress } from "../address/index.js"; +import { ZeroAddress } from "../constants/index.js"; +import { Contract } from "../contract/index.js"; +import { dnsEncode, namehash } from "../hash/index.js"; +import { hexlify, isHexString, toBeHex, defineProperties, encodeBase58, assert, assertArgument, isError, FetchRequest } from "../utils/index.js"; +// @TODO: This should use the fetch-data:ipfs gateway +// Trim off the ipfs:// prefix and return the default gateway URL +function getIpfsLink(link) { + if (link.match(/^ipfs:\/\/ipfs\//i)) { + link = link.substring(12); + } + else if (link.match(/^ipfs:\/\//i)) { + link = link.substring(7); + } + else { + assertArgument(false, "unsupported IPFS format", "link", link); + } + return `https:/\/gateway.ipfs.io/ipfs/${link}`; +} +; +; +/** + * A provider plugin super-class for processing multicoin address types. + */ +export class MulticoinProviderPlugin { + /** + * The name. + */ + name; + /** + * Creates a new **MulticoinProviderPluing** for %%name%%. + */ + constructor(name) { + defineProperties(this, { name }); + } + connect(proivder) { + return this; + } + /** + * Returns ``true`` if %%coinType%% is supported by this plugin. + */ + supportsCoinType(coinType) { + return false; + } + /** + * Resovles to the encoded %%address%% for %%coinType%%. + */ + async encodeAddress(coinType, address) { + throw new Error("unsupported coin"); + } + /** + * Resovles to the decoded %%data%% for %%coinType%%. + */ + async decodeAddress(coinType, data) { + throw new Error("unsupported coin"); + } +} +const BasicMulticoinPluginId = "org.quais.plugins.provider.BasicMulticoin"; +/** + * A **BasicMulticoinProviderPlugin** provides service for common + * coin types, which do not require additional libraries to encode or + * decode. + */ +export class BasicMulticoinProviderPlugin extends MulticoinProviderPlugin { + /** + * Creates a new **BasicMulticoinProviderPlugin**. + */ + constructor() { + super(BasicMulticoinPluginId); + } +} +const matcherIpfs = new RegExp("^(ipfs):/\/(.*)$", "i"); +const matchers = [ + new RegExp("^(https):/\/(.*)$", "i"), + new RegExp("^(data):(.*)$", "i"), + matcherIpfs, + new RegExp("^eip155:[0-9]+/(erc[0-9]+):(.*)$", "i"), +]; +/** + * A connected object to a resolved ENS name resolver, which can be + * used to query additional details. + */ +export class EnsResolver { + /** + * The connected provider. + */ + provider; + /** + * The address of the resolver. + */ + address; + /** + * The name this resolver was resolved against. + */ + name; + // For EIP-2544 names, the ancestor that provided the resolver + #supports2544; + #resolver; + constructor(provider, address, name) { + defineProperties(this, { provider, address, name }); + this.#supports2544 = null; + this.#resolver = new Contract(address, [ + "function supportsInterface(bytes4) view returns (bool)", + "function resolve(bytes, bytes) view returns (bytes)", + "function addr(bytes32) view returns (address)", + "function addr(bytes32, uint) view returns (bytes)", + "function text(bytes32, string) view returns (string)", + "function contenthash(bytes32) view returns (bytes)", + ], provider); + } + /** + * Resolves to true if the resolver supports wildcard resolution. + */ + async supportsWildcard() { + if (this.#supports2544 == null) { + this.#supports2544 = (async () => { + try { + return await this.#resolver.supportsInterface("0x9061b923"); + } + catch (error) { + // Wildcard resolvers must understand supportsInterface + // and return true. + if (isError(error, "CALL_EXCEPTION")) { + return false; + } + // Let future attempts try again... + this.#supports2544 = null; + throw error; + } + })(); + } + return await this.#supports2544; + } + async #fetch(funcName, params) { + params = (params || []).slice(); + const iface = this.#resolver.interface; + // The first parameters is always the nodehash + params.unshift(namehash(this.name)); + let fragment = null; + if (await this.supportsWildcard()) { + fragment = iface.getFunction(funcName); + assert(fragment, "missing fragment", "UNKNOWN_ERROR", { + info: { funcName } + }); + params = [ + dnsEncode(this.name), + iface.encodeFunctionData(fragment, params) + ]; + funcName = "resolve(bytes,bytes)"; + } + params.push({ + enableCcipRead: true + }); + try { + const result = await this.#resolver[funcName](...params); + if (fragment) { + return iface.decodeFunctionResult(fragment, result)[0]; + } + return result; + } + catch (error) { + if (!isError(error, "CALL_EXCEPTION")) { + throw error; + } + } + return null; + } + /** + * Resolves to the address for %%coinType%% or null if the + * provided %%coinType%% has not been configured. + */ + async getAddress(coinType) { + if (coinType == null) { + coinType = 60; + } + if (coinType === 60) { + try { + const result = await this.#fetch("addr(bytes32)"); + // No address + if (result == null || result === ZeroAddress) { + return null; + } + return result; + } + catch (error) { + if (isError(error, "CALL_EXCEPTION")) { + return null; + } + throw error; + } + } + // Try decoding its EVM canonical chain as an EVM chain address first + if (coinType >= 0 && coinType < 0x80000000) { + let ethCoinType = coinType + 0x80000000; + const data = await this.#fetch("addr(bytes32,uint)", [ethCoinType]); + if (isHexString(data, 20)) { + return getAddress(data); + } + } + let coinPlugin = null; + for (const plugin of this.provider.plugins) { + if (!(plugin instanceof MulticoinProviderPlugin)) { + continue; + } + if (plugin.supportsCoinType(coinType)) { + coinPlugin = plugin; + break; + } + } + if (coinPlugin == null) { + return null; + } + // keccak256("addr(bytes32,uint256") + const data = await this.#fetch("addr(bytes32,uint)", [coinType]); + // No address + if (data == null || data === "0x") { + return null; + } + // Compute the address + const address = await coinPlugin.decodeAddress(coinType, data); + if (address != null) { + return address; + } + assert(false, `invalid coin data`, "UNSUPPORTED_OPERATION", { + operation: `getAddress(${coinType})`, + info: { coinType, data } + }); + } + /** + * Resolves to the EIP-634 text record for %%key%%, or ``null`` + * if unconfigured. + */ + async getText(key) { + const data = await this.#fetch("text(bytes32,string)", [key]); + if (data == null || data === "0x") { + return null; + } + return data; + } + /** + * Rsolves to the content-hash or ``null`` if unconfigured. + */ + async getContentHash() { + // keccak256("contenthash()") + const data = await this.#fetch("contenthash(bytes32)"); + // No contenthash + if (data == null || data === "0x") { + return null; + } + // IPFS (CID: 1, Type: 70=DAG-PB, 72=libp2p-key) + const ipfs = data.match(/^0x(e3010170|e5010172)(([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f]*))$/); + if (ipfs) { + const scheme = (ipfs[1] === "e3010170") ? "ipfs" : "ipns"; + const length = parseInt(ipfs[4], 16); + if (ipfs[5].length === length * 2) { + return `${scheme}:/\/${encodeBase58("0x" + ipfs[2])}`; + } + } + // Swarm (CID: 1, Type: swarm-manifest; hash/length hard-coded to keccak256/32) + const swarm = data.match(/^0xe40101fa011b20([0-9a-f]*)$/); + if (swarm && swarm[1].length === 64) { + return `bzz:/\/${swarm[1]}`; + } + assert(false, `invalid or unsupported content hash data`, "UNSUPPORTED_OPERATION", { + operation: "getContentHash()", + info: { data } + }); + } + /** + * Resolves to the avatar url or ``null`` if the avatar is either + * unconfigured or incorrectly configured (e.g. references an NFT + * not owned by the address). + * + * If diagnosing issues with configurations, the [[_getAvatar]] + * method may be useful. + */ + async getAvatar() { + const avatar = await this._getAvatar(); + return avatar.url; + } + /** + * When resolving an avatar, there are many steps involved, such + * fetching metadata and possibly validating ownership of an + * NFT. + * + * This method can be used to examine each step and the value it + * was working from. + */ + async _getAvatar() { + const linkage = [{ type: "name", value: this.name }]; + try { + // test data for ricmoo.eth + //const avatar = "eip155:1/erc721:0x265385c7f4132228A0d54EB1A9e7460b91c0cC68/29233"; + const avatar = await this.getText("avatar"); + if (avatar == null) { + linkage.push({ type: "!avatar", value: "" }); + return { url: null, linkage }; + } + linkage.push({ type: "avatar", value: avatar }); + for (let i = 0; i < matchers.length; i++) { + const match = avatar.match(matchers[i]); + if (match == null) { + continue; + } + const scheme = match[1].toLowerCase(); + switch (scheme) { + case "https": + case "data": + linkage.push({ type: "url", value: avatar }); + return { linkage, url: avatar }; + case "ipfs": { + const url = getIpfsLink(avatar); + linkage.push({ type: "ipfs", value: avatar }); + linkage.push({ type: "url", value: url }); + return { linkage, url }; + } + case "erc721": + case "erc1155": { + // Depending on the ERC type, use tokenURI(uint256) or url(uint256) + const selector = (scheme === "erc721") ? "tokenURI(uint256)" : "uri(uint256)"; + linkage.push({ type: scheme, value: avatar }); + // The owner of this name + const owner = await this.getAddress(); + if (owner == null) { + linkage.push({ type: "!owner", value: "" }); + return { url: null, linkage }; + } + const comps = (match[2] || "").split("/"); + if (comps.length !== 2) { + linkage.push({ type: `!${scheme}caip`, value: (match[2] || "") }); + return { url: null, linkage }; + } + const tokenId = comps[1]; + const contract = new Contract(comps[0], [ + // ERC-721 + "function tokenURI(uint) view returns (string)", + "function ownerOf(uint) view returns (address)", + // ERC-1155 + "function uri(uint) view returns (string)", + "function balanceOf(address, uint256) view returns (uint)" + ], this.provider); + // Check that this account owns the token + if (scheme === "erc721") { + const tokenOwner = await contract.ownerOf(tokenId); + if (owner !== tokenOwner) { + linkage.push({ type: "!owner", value: tokenOwner }); + return { url: null, linkage }; + } + linkage.push({ type: "owner", value: tokenOwner }); + } + else if (scheme === "erc1155") { + const balance = await contract.balanceOf(owner, tokenId); + if (!balance) { + linkage.push({ type: "!balance", value: "0" }); + return { url: null, linkage }; + } + linkage.push({ type: "balance", value: balance.toString() }); + } + // Call the token contract for the metadata URL + let metadataUrl = await contract[selector](tokenId); + if (metadataUrl == null || metadataUrl === "0x") { + linkage.push({ type: "!metadata-url", value: "" }); + return { url: null, linkage }; + } + linkage.push({ type: "metadata-url-base", value: metadataUrl }); + // ERC-1155 allows a generic {id} in the URL + if (scheme === "erc1155") { + metadataUrl = metadataUrl.replace("{id}", toBeHex(tokenId, 32).substring(2)); + linkage.push({ type: "metadata-url-expanded", value: metadataUrl }); + } + // Transform IPFS metadata links + if (metadataUrl.match(/^ipfs:/i)) { + metadataUrl = getIpfsLink(metadataUrl); + } + linkage.push({ type: "metadata-url", value: metadataUrl }); + // Get the token metadata + let metadata = {}; + const response = await (new FetchRequest(metadataUrl)).send(); + response.assertOk(); + try { + metadata = response.bodyJson; + } + catch (error) { + try { + linkage.push({ type: "!metadata", value: response.bodyText }); + } + catch (error) { + const bytes = response.body; + if (bytes) { + linkage.push({ type: "!metadata", value: hexlify(bytes) }); + } + return { url: null, linkage }; + } + return { url: null, linkage }; + } + if (!metadata) { + linkage.push({ type: "!metadata", value: "" }); + return { url: null, linkage }; + } + linkage.push({ type: "metadata", value: JSON.stringify(metadata) }); + // Pull the image URL out + let imageUrl = metadata.image; + if (typeof (imageUrl) !== "string") { + linkage.push({ type: "!imageUrl", value: "" }); + return { url: null, linkage }; + } + if (imageUrl.match(/^(https:\/\/|data:)/i)) { + // Allow + } + else { + // Transform IPFS link to gateway + const ipfs = imageUrl.match(matcherIpfs); + if (ipfs == null) { + linkage.push({ type: "!imageUrl-ipfs", value: imageUrl }); + return { url: null, linkage }; + } + linkage.push({ type: "imageUrl-ipfs", value: imageUrl }); + imageUrl = getIpfsLink(imageUrl); + } + linkage.push({ type: "url", value: imageUrl }); + return { linkage, url: imageUrl }; + } + } + } + } + catch (error) { } + return { linkage, url: null }; + } + static async getEnsAddress(provider) { + const network = await provider.getNetwork(); + const ensPlugin = network.getPlugin("org.quais.plugins.network.Ens"); + // No ENS... + assert(ensPlugin, "network does not support ENS", "UNSUPPORTED_OPERATION", { + operation: "getEnsAddress", info: { network } + }); + return ensPlugin.address; + } + static async #getResolver(provider, name) { + const ensAddr = await EnsResolver.getEnsAddress(provider); + try { + const contract = new Contract(ensAddr, [ + "function resolver(bytes32) view returns (address)" + ], provider); + const addr = await contract.resolver(namehash(name), { + enableCcipRead: true + }); + if (addr === ZeroAddress) { + return null; + } + return addr; + } + catch (error) { + // ENS registry cannot throw errors on resolver(bytes32), + // so probably a link error + throw error; + } + return null; + } + /** + * Resolve to the ENS resolver for %%name%% using %%provider%% or + * ``null`` if unconfigured. + */ + static async fromName(provider, name) { + let currentName = name; + while (true) { + if (currentName === "" || currentName === ".") { + return null; + } + // Optimization since the eth node cannot change and does + // not have a wildcard resolver + if (name !== "eth" && currentName === "eth") { + return null; + } + // Check the current node for a resolver + const addr = await EnsResolver.#getResolver(provider, currentName); + // Found a resolver! + if (addr != null) { + const resolver = new EnsResolver(provider, addr, name); + // Legacy resolver found, using EIP-2544 so it isn't safe to use + if (currentName !== name && !(await resolver.supportsWildcard())) { + return null; + } + return resolver; + } + // Get the parent node + currentName = currentName.split(".").slice(1).join("."); + } + } +} +//# sourceMappingURL=ens-resolver.js.map \ No newline at end of file diff --git a/lib.esm/providers/ens-resolver.js.map b/lib.esm/providers/ens-resolver.js.map new file mode 100644 index 00000000..89fbbd25 --- /dev/null +++ b/lib.esm/providers/ens-resolver.js.map @@ -0,0 +1 @@ +{"version":3,"file":"ens-resolver.js","sourceRoot":"","sources":["../../src.ts/providers/ens-resolver.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EACH,OAAO,EAAE,WAAW,EAAE,OAAO,EAC7B,gBAAgB,EAAE,YAAY,EAC9B,MAAM,EAAE,cAAc,EAAE,OAAO,EAC/B,YAAY,EACf,MAAM,mBAAmB,CAAC;AAU3B,qDAAqD;AACrD,iEAAiE;AACjE,SAAS,WAAW,CAAC,IAAY;IAC7B,IAAI,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC,EAAE;QACjC,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;KAC7B;SAAM,IAAI,IAAI,CAAC,KAAK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,KAAK,GAAG,EAAE;gBAAE,OAAO,IAAI,CAAC;aAAE;YAE/D,yDAAyD;YACzD,+BAA+B;YAC/B,IAAI,IAAI,KAAK,KAAK,IAAI,WAAW,KAAK,KAAK,EAAE;gBAAE,OAAO,IAAI,CAAC;aAAE;YAE7D,wCAAwC;YACxC,MAAM,IAAI,GAAG,MAAM,WAAW,CAAC,YAAY,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;YAEnE,oBAAoB;YACpB,IAAI,IAAI,IAAI,IAAI,EAAE;gBACd,MAAM,QAAQ,GAAG,IAAI,WAAW,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;gBAEvD,gEAAgE;gBAChE,IAAI,WAAW,KAAK,IAAI,IAAI,CAAC,CAAC,MAAM,QAAQ,CAAC,gBAAgB,EAAE,CAAC,EAAE;oBAAE,OAAO,IAAI,CAAC;iBAAE;gBAElF,OAAO,QAAQ,CAAC;aACnB;YAED,sBAAsB;YACtB,WAAW,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;SAC3D;IACL,CAAC;CACJ"} \ No newline at end of file diff --git a/lib.esm/providers/format.d.ts b/lib.esm/providers/format.d.ts new file mode 100644 index 00000000..9a171ef9 --- /dev/null +++ b/lib.esm/providers/format.d.ts @@ -0,0 +1,16 @@ +import type { BlockParams, LogParams, TransactionReceiptParams, TransactionResponseParams, EtxParams } from "./formatting.js"; +export type FormatFunc = (value: any) => any; +export declare function allowNull(format: FormatFunc, nullValue?: any): FormatFunc; +export declare function arrayOf(format: FormatFunc): FormatFunc; +export declare function object(format: Record, altNames?: Record>): FormatFunc; +export declare function formatBoolean(value: any): boolean; +export declare function formatData(value: string): string; +export declare function formatHash(value: any): string; +export declare function formatUint256(value: any): string; +export declare function formatLog(value: any): LogParams; +export declare function formatBlock(value: any): BlockParams; +export declare function formatReceiptLog(value: any): LogParams; +export declare function formatEtx(value: any): EtxParams; +export declare function formatTransactionReceipt(value: any): TransactionReceiptParams; +export declare function formatTransactionResponse(value: any): TransactionResponseParams; +//# sourceMappingURL=format.d.ts.map \ No newline at end of file diff --git a/lib.esm/providers/format.d.ts.map b/lib.esm/providers/format.d.ts.map new file mode 100644 index 00000000..105a5279 --- /dev/null +++ b/lib.esm/providers/format.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src.ts/providers/format.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EACR,WAAW,EAAE,SAAS,EACtB,wBAAwB,EAAE,yBAAyB,EAAE,SAAS,EACjE,MAAM,iBAAiB,CAAC;AAKzB,MAAM,MAAM,UAAU,GAAG,CAAC,KAAK,EAAE,GAAG,KAAK,GAAG,CAAC;AAE7C,wBAAgB,SAAS,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,CAAC,EAAE,GAAG,GAAG,UAAU,CAKzE;AAED,wBAAgB,OAAO,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAKtD;AAKD,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,UAAU,CAwB/G;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO,CAQjD;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAGhD;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,GAAG,GAAG,MAAM,CAG7C;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,GAAG,GAAG,MAAM,CAKhD;AAgBD,wBAAgB,SAAS,CAAC,KAAK,EAAE,GAAG,GAAG,SAAS,CAE/C;AAwCD,wBAAgB,WAAW,CAAC,KAAK,EAAE,GAAG,GAAG,WAAW,CAWnD;AAeD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,GAAG,GAAG,SAAS,CAEtD;AAoBD,wBAAgB,SAAS,CAAC,KAAK,EAAE,GAAG,GAAG,SAAS,CAE/C;AAyBD,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,GAAG,GAAG,wBAAwB,CAG7E;AAED,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,GAAG,GAAG,yBAAyB,CA4G/E"} \ No newline at end of file diff --git a/lib.esm/providers/format.js b/lib.esm/providers/format.js new file mode 100644 index 00000000..35e0fe47 --- /dev/null +++ b/lib.esm/providers/format.js @@ -0,0 +1,302 @@ +/** + * @_ignore + */ +import { getAddress, getCreateAddress } from "../address/index.js"; +import { Signature } from "../crypto/index.js"; +import { accessListify } from "../transaction/index.js"; +import { getBigInt, getNumber, isHexString, zeroPadValue, assert, assertArgument } from "../utils/index.js"; +const BN_0 = BigInt(0); +export function allowNull(format, nullValue) { + return (function (value) { + if (value == null) { + return nullValue; + } + return format(value); + }); +} +export function arrayOf(format) { + return ((array) => { + if (!Array.isArray(array)) { + throw new Error("not an array"); + } + return array.map((i) => format(i)); + }); +} +// Requires an object which matches a fleet of other formatters +// Any FormatFunc may return `undefined` to have the value omitted +// from the result object. Calls preserve `this`. +export function object(format, altNames) { + return ((value) => { + const result = {}; + for (const key in format) { + let srcKey = key; + if (altNames && key in altNames && !(srcKey in value)) { + for (const altKey of altNames[key]) { + if (altKey in value) { + srcKey = altKey; + break; + } + } + } + try { + const nv = format[key](value[srcKey]); + if (nv !== undefined) { + result[key] = nv; + } + } + catch (error) { + const message = (error instanceof Error) ? error.message : "not-an-error"; + assert(false, `invalid value for value.${key} (${message})`, "BAD_DATA", { value }); + } + } + return result; + }); +} +export function formatBoolean(value) { + switch (value) { + case true: + case "true": + return true; + case false: + case "false": + return false; + } + assertArgument(false, `invalid boolean; ${JSON.stringify(value)}`, "value", value); +} +export function formatData(value) { + assertArgument(isHexString(value, true), "invalid data", "value", value); + return value; +} +export function formatHash(value) { + assertArgument(isHexString(value, 32), "invalid hash", "value", value); + return value; +} +export function formatUint256(value) { + if (!isHexString(value)) { + throw new Error("invalid uint256"); + } + return zeroPadValue(value, 32); +} +const _formatLog = object({ + address: getAddress, + blockHash: formatHash, + blockNumber: getNumber, + data: formatData, + index: getNumber, + removed: allowNull(formatBoolean, false), + topics: arrayOf(formatHash), + transactionHash: formatHash, + transactionIndex: getNumber, +}, { + index: ["logIndex"] +}); +export function formatLog(value) { + return _formatLog(value); +} +const _formatBlock = object({ + hash: allowNull(formatHash), + parentHash: arrayOf(formatHash), + number: arrayOf(getNumber), + timestamp: getNumber, + nonce: allowNull(formatData), + difficulty: getBigInt, + gasLimit: getBigInt, + gasUsed: getBigInt, + miner: allowNull(getAddress), + extraData: formatData, + baseFeePerGas: allowNull(getBigInt), + extRollupRoot: formatHash, + // extTransactions: arrayOf(formatTransaction), + extTransactionsRoot: formatHash, + // transactions: + transactionsRoot: formatHash, + manifestHash: arrayOf(formatHash), + location: formatData, + parentDeltaS: arrayOf(getBigInt), + parentEntropy: arrayOf(getBigInt), + order: getNumber, + subManifest: arrayOf(formatData), + totalEntropy: getBigInt, + mixHash: formatHash, + receiptsRoot: formatHash, + sha3Uncles: formatHash, + size: getBigInt, + evmRoot: formatHash, + utxoRoot: formatHash, + uncles: arrayOf(formatHash), +}); +export function formatBlock(value) { + const result = _formatBlock(value); + result.transactions = value.transactions.map((tx) => { + if (typeof (tx) === "string") { + return tx; + } + return formatTransactionResponse(tx); + }); + result.extTransactions = value.extTransactions.map((tx) => { + if (typeof (tx) === "string") { + return tx; + } + return formatTransactionResponse(tx); + }); + return result; +} +const _formatReceiptLog = object({ + transactionIndex: getNumber, + blockNumber: getNumber, + transactionHash: formatHash, + address: getAddress, + topics: arrayOf(formatHash), + data: formatData, + index: getNumber, + blockHash: formatHash, +}, { + index: ["logIndex"] +}); +export function formatReceiptLog(value) { + return _formatReceiptLog(value); +} +const _formatEtx = object({ + type: allowNull(getNumber, 0), + nonce: getNumber, + gasPrice: allowNull(getBigInt), + maxPriorityFeePerGas: getBigInt, + maxFeePerGas: getBigInt, + gas: getBigInt, + value: allowNull(getBigInt, BN_0), + input: formatData, + to: allowNull(getAddress, null), + accessList: allowNull(accessListify, null), + chainId: allowNull(getBigInt, null), + from: allowNull(getAddress, null), + hash: formatHash, +}, { + from: ["sender"], +}); +export function formatEtx(value) { + return _formatEtx(value); +} +const _formatTransactionReceipt = object({ + to: allowNull(getAddress, null), + from: allowNull(getAddress, null), + contractAddress: allowNull(getAddress, null), + // should be allowNull(hash), but broken-EIP-658 support is handled in receipt + index: getNumber, + gasUsed: getBigInt, + logsBloom: allowNull(formatData), + blockHash: formatHash, + hash: formatHash, + logs: arrayOf(formatReceiptLog), + blockNumber: getNumber, + //confirmations: allowNull(getNumber, null), + cumulativeGasUsed: getBigInt, + effectiveGasPrice: allowNull(getBigInt), + status: allowNull(getNumber), + type: allowNull(getNumber, 0), + etxs: arrayOf(formatEtx), +}, { + hash: ["transactionHash"], + index: ["transactionIndex"], +}); +export function formatTransactionReceipt(value) { + const result = _formatTransactionReceipt(value); + return result; +} +export function formatTransactionResponse(value) { + // Some clients (TestRPC) do strange things like return 0x0 for the + // 0 address; correct this to be a real address + if (value.to && getBigInt(value.to) === BN_0) { + value.to = "0x0000000000000000000000000000000000000000"; + } + if (value.type === "0x1") + value.from = value.sender; + const result = object({ + hash: formatHash, + type: (value) => { + if (value === "0x" || value == null) { + return 0; + } + return getNumber(value); + }, + accessList: allowNull(accessListify, null), + blockHash: allowNull(formatHash, null), + blockNumber: allowNull(getNumber, null), + index: allowNull(getNumber, null), + //confirmations: allowNull(getNumber, null), + from: getAddress, + maxPriorityFeePerGas: allowNull(getBigInt), + maxFeePerGas: allowNull(getBigInt), + gasLimit: getBigInt, + to: allowNull(getAddress, null), + value: getBigInt, + nonce: getNumber, + creates: allowNull(getAddress, null), + chainId: allowNull(getBigInt, null), + }, { + data: ["input"], + gasLimit: ["gas"], + index: ["transactionIndex"], + })(value); + // If to and creates are empty, populate the creates from the value + if (result.to == null && result.creates == null) { + result.creates = getCreateAddress(result); + } + // Add an access list to supported transaction types + if ((value.type === 1 || value.type === 2) && value.accessList == null) { + result.accessList = []; + } + // Compute the signature + if (value.signature) { + result.signature = Signature.from(value.signature); + } + else { + result.signature = Signature.from(value); + } + // Some backends omit ChainId on legacy transactions, but we can compute it + if (result.chainId == null) { + const chainId = result.signature.legacyChainId; + if (chainId != null) { + result.chainId = chainId; + } + } + // @TODO: check chainID + /* + if (value.chainId != null) { + let chainId = value.chainId; + + if (isHexString(chainId)) { + chainId = BigNumber.from(chainId).toNumber(); + } + + result.chainId = chainId; + + } else { + let chainId = value.networkId; + + // geth-etc returns chainId + if (chainId == null && result.v == null) { + chainId = value.chainId; + } + + if (isHexString(chainId)) { + chainId = BigNumber.from(chainId).toNumber(); + } + + if (typeof(chainId) !== "number" && result.v != null) { + chainId = (result.v - 35) / 2; + if (chainId < 0) { chainId = 0; } + chainId = parseInt(chainId); + } + + if (typeof(chainId) !== "number") { chainId = 0; } + + result.chainId = chainId; + } + */ + // 0x0000... should actually be null + if (result.blockHash && getBigInt(result.blockHash) === BN_0) { + result.blockHash = null; + } + return result; +} +//# sourceMappingURL=format.js.map \ No newline at end of file diff --git a/lib.esm/providers/format.js.map b/lib.esm/providers/format.js.map new file mode 100644 index 00000000..0e693bcd --- /dev/null +++ b/lib.esm/providers/format.js.map @@ -0,0 +1 @@ +{"version":3,"file":"format.js","sourceRoot":"","sources":["../../src.ts/providers/format.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EACH,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAC/C,MAAM,EAAE,cAAc,EACzB,MAAM,mBAAmB,CAAC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,IAAI,OAAO,IAAI,IAAI,EAAE;YAAE,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC;SAAE;KACrD;IAGD,uBAAuB;IACvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAgCE;IAEF,oCAAoC;IACpC,IAAI,MAAM,CAAC,SAAS,IAAI,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,IAAI,EAAE;QAC1D,MAAM,CAAC,SAAS,GAAG,IAAI,CAAC;KAC3B;IAED,OAAO,MAAM,CAAC;AAClB,CAAC"} \ No newline at end of file diff --git a/lib.esm/providers/formatting.d.ts b/lib.esm/providers/formatting.d.ts new file mode 100644 index 00000000..0579bbef --- /dev/null +++ b/lib.esm/providers/formatting.d.ts @@ -0,0 +1,293 @@ +/** + * About provider formatting? + * + * @_section: api/providers/formatting:Formatting [provider-formatting] + */ +import type { Signature } from "../crypto/index.js"; +import type { AccessList } from "../transaction/index.js"; +import type { UTXOTransactionInput, UTXOTransactionOutput } from "../transaction/utxo.js"; +/** + * a **BlockParams** encodes the minimal required properties for a + * formatted block. + */ +export interface BlockParams { + /** + * The block hash. + */ + hash?: null | string; + /** + * The block number. + */ + number: Array | number; + /** + * The timestamp for this block, which is the number of seconds + * since epoch that this block was included. + */ + timestamp: number; + /** + * The hash of the previous block in the blockchain. The genesis block + * has the parentHash of the [[ZeroHash]]. + */ + parentHash: Array | string; + /** + * A random sequence provided during the mining process for + * proof-of-work networks. + */ + nonce: string; + /** + * For proof-of-work networks, the difficulty target is used to + * adjust the difficulty in mining to ensure a expected block rate. + */ + difficulty: bigint; + /** + * The maximum amount of gas a block can consume. + */ + gasLimit: bigint; + /** + * The amount of gas a block consumed. + */ + gasUsed: bigint; + /** + * The miner (or author) of a block. + */ + miner: string; + /** + * Additional data the miner choose to include. + */ + extraData: string; + /** + * The protocol-defined base fee per gas in an [[link-eip-1559]] + * block. + */ + baseFeePerGas: null | bigint; + manifestHash: Array; + location: bigint; + parentDeltaS: Array; + parentEntropy: Array; + order: number; + subManifest: Array | null; + totalEntropy: bigint; + mixHash: string; + receiptsRoot: string; + sha3Uncles: string; + size: bigint; + evmRoot: string; + utxoRoot: string; + uncles: Array | null; + /** + * The list of transactions in the block. + */ + transactions: ReadonlyArray; + transactionsRoot: string; + extRollupRoot: string; + extTransactions: ReadonlyArray; + extTransactionsRoot: string; +} +/** + * a **LogParams** encodes the minimal required properties for a + * formatted log. + */ +export interface LogParams { + /** + * The transaction hash for the transaxction the log occurred in. + */ + transactionHash: string; + /** + * The block hash of the block that included the transaction for this + * log. + */ + blockHash: string; + /** + * The block number of the block that included the transaction for this + * log. + */ + blockNumber: number; + /** + * Whether this log was removed due to the transaction it was included + * in being removed dur to an orphaned block. + */ + removed: boolean; + /** + * The address of the contract that emitted this log. + */ + address: string; + /** + * The data emitted with this log. + */ + data: string; + /** + * The topics emitted with this log. + */ + topics: ReadonlyArray; + /** + * The index of this log. + */ + index: number; + /** + * The transaction index of this log. + */ + transactionIndex: number; +} +export interface EtxParams { + type: number; + nonce: number; + gasPrice: null | bigint; + maxPriorityFeePerGas: bigint; + maxFeePerGas: bigint; + gas: bigint; + value: bigint; + input: string; + to: null | string; + accessList: null | AccessList; + chainId: null | bigint; + from: null | string; + hash: string; +} +/** + * a **TransactionReceiptParams** encodes the minimal required properties + * for a formatted transaction receipt. + */ +export interface TransactionReceiptParams { + /** + * The target of the transaction. If null, the transaction was trying + * to deploy a transaction with the ``data`` as the initi=code. + */ + to: null | string; + /** + * The sender of the transaction. + */ + from: string; + /** + * If the transaction was directly deploying a contract, the [[to]] + * will be null, the ``data`` will be initcode and if successful, this + * will be the address of the contract deployed. + */ + contractAddress: null | string; + /** + * The transaction hash. + */ + hash: string; + /** + * The transaction index. + */ + index: number; + /** + * The block hash of the block that included this transaction. + */ + blockHash: string; + /** + * The block number of the block that included this transaction. + */ + blockNumber: number; + /** + * The bloom filter for the logs emitted during execution of this + * transaction. + */ + logsBloom: string; + /** + * The logs emitted during the execution of this transaction. + */ + logs: ReadonlyArray; + /** + * The amount of gas consumed executing this transaciton. + */ + gasUsed: bigint; + /** + * The total amount of gas consumed during the entire block up to + * and including this transaction. + */ + cumulativeGasUsed: bigint; + /** + * The actual gas price per gas charged for this transaction. + */ + gasPrice?: null | bigint; + /** + * The actual gas price per gas charged for this transaction. + */ + effectiveGasPrice?: null | bigint; + /** + * The [[link-eip-2718]] envelope type. + */ + type: number; + /** + * The status of the transaction execution. If ``1`` then the + * the transaction returned success, if ``0`` then the transaction + * was reverted. For pre-byzantium blocks, this is usually null, but + * some nodes may have backfilled this data. + */ + status: null | number; + etxs: ReadonlyArray; +} +/** + * a **TransactionResponseParams** encodes the minimal required properties + * for a formatted transaction response. + */ +export interface TransactionResponseParams { + /** + * The block number of the block that included this transaction. + */ + blockNumber: null | number; + /** + * The block hash of the block that included this transaction. + */ + blockHash: null | string; + /** + * The transaction hash. + */ + hash: string; + /** + * The transaction index. + */ + index: bigint; + type: number; + /** + * The target of the transaction. If ``null``, the ``data`` is initcode + * and this transaction is a deployment transaction. + */ + to: null | string; + /** + * The sender of the transaction. + */ + from: string; + /** + * The nonce of the transaction, used for replay protection. + */ + nonce: number; + /** + * The maximum amount of gas this transaction is authorized to consume. + */ + gasLimit: bigint; + /** + * For [[link-eip-1559]] transactions, this is the maximum priority + * fee to allow a producer to claim. + */ + maxPriorityFeePerGas: null | bigint; + /** + * For [[link-eip-1559]] transactions, this is the maximum fee that + * will be paid. + */ + maxFeePerGas: null | bigint; + /** + * The transaction data. + */ + data: string; + /** + * The transaction value (in wei). + */ + value: bigint; + /** + * The chain ID this transaction is valid on. + */ + chainId: bigint; + /** + * The signature of the transaction. + */ + signature: Signature; + /** + * The transaction access list. + */ + accessList: null | AccessList; + outputsUTXO?: UTXOTransactionOutput[]; + inputsUTXO?: UTXOTransactionInput[]; +} +//# sourceMappingURL=formatting.d.ts.map \ No newline at end of file diff --git a/lib.esm/providers/formatting.d.ts.map b/lib.esm/providers/formatting.d.ts.map new file mode 100644 index 00000000..33769f58 --- /dev/null +++ b/lib.esm/providers/formatting.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"formatting.d.ts","sourceRoot":"","sources":["../../src.ts/providers/formatting.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAK1F;;;GAGG;AACH,MAAM,WAAW,WAAW;IACxB;;OAEG;IACH,IAAI,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;IAErB;;OAEG;IACH,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;IAE/B;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;IAEnC;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,aAAa,EAAE,IAAI,GAAG,MAAM,CAAC;IAE7B,YAAY,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAE5B,QAAQ,EAAE,MAAM,CAAC;IAEjB,YAAY,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAE5B,aAAa,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAE7B,KAAK,EAAE,MAAM,CAAC;IAEd,WAAW,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;IAElC,YAAY,EAAE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AM,CAAC;IAEb;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAGd,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,EAAE,EAAE,IAAI,GAAG,MAAM,CAAC;IAElB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,oBAAoB,EAAE,IAAI,GAAG,MAAM,CAAC;IAEpC;;;OAGG;IACH,YAAY,EAAE,IAAI,GAAG,MAAM,CAAC;IAE5B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,SAAS,EAAE,SAAS,CAAC;IAErB;;OAEG;IACH,UAAU,EAAE,IAAI,GAAG,UAAU,CAAC;IAE9B,WAAY,CAAC,EAAE,qBAAqB,EAAE,CAAC;IAEvC,UAAW,CAAC,EAAE,oBAAoB,EAAE,CAAC;CACxC"} \ No newline at end of file diff --git a/lib.esm/providers/formatting.js b/lib.esm/providers/formatting.js new file mode 100644 index 00000000..5c662d20 --- /dev/null +++ b/lib.esm/providers/formatting.js @@ -0,0 +1,9 @@ +/** + * About provider formatting? + * + * @_section: api/providers/formatting:Formatting [provider-formatting] + */ +; +; +export {}; +//# sourceMappingURL=formatting.js.map \ No newline at end of file diff --git a/lib.esm/providers/formatting.js.map b/lib.esm/providers/formatting.js.map new file mode 100644 index 00000000..3dce2e0c --- /dev/null +++ b/lib.esm/providers/formatting.js.map @@ -0,0 +1 @@ +{"version":3,"file":"formatting.js","sourceRoot":"","sources":["../../src.ts/providers/formatting.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAkHF,CAAC;AA6QD,CAAC"} \ No newline at end of file diff --git a/lib.esm/providers/index.d.ts b/lib.esm/providers/index.d.ts new file mode 100644 index 00000000..a51e0c7d --- /dev/null +++ b/lib.esm/providers/index.d.ts @@ -0,0 +1,39 @@ +/** + * A **Provider** provides a connection to the blockchain, whch can be + * used to query its current state, simulate execution and send transactions + * to update the state. + * + * It is one of the most fundamental components of interacting with a + * blockchain application, and there are many ways to connect, such as over + * HTTP, WebSockets or injected providers such as [MetaMask](link-metamask). + * + * @_section: api/providers:Providers [about-providers] + */ +export { AbstractProvider, UnmanagedSubscriber } from "./abstract-provider.js"; +export { AbstractSigner, VoidSigner, } from "./abstract-signer.js"; +export { showThrottleMessage } from "./community.js"; +export { getDefaultProvider } from "./default-provider.js"; +export { Network } from "./network.js"; +export { NonceManager } from "./signer-noncemanager.js"; +export { NetworkPlugin, GasCostPlugin, EnsPlugin, FeeDataNetworkPlugin, FetchUrlFeeDataNetworkPlugin, } from "./plugins-network.js"; +export { Block, FeeData, Log, TransactionReceipt, TransactionResponse, copyRequest, } from "./provider.js"; +export { FallbackProvider } from "./provider-fallback.js"; +export { JsonRpcApiProvider, JsonRpcProvider, JsonRpcSigner } from "./provider-jsonrpc.js"; +export { BrowserProvider } from "./provider-browser.js"; +import { IpcSocketProvider } from "./provider-ipcsocket.js"; +export { IpcSocketProvider }; +export { SocketProvider } from "./provider-socket.js"; +export { WebSocketProvider } from "./provider-websocket.js"; +export { SocketSubscriber, SocketBlockSubscriber, SocketPendingSubscriber, SocketEventSubscriber } from "./provider-socket.js"; +export type { AbstractProviderOptions, Subscription, Subscriber, AbstractProviderPlugin, PerformActionFilter, PerformActionTransaction, PerformActionRequest, } from "./abstract-provider.js"; +export type { ContractRunner } from "./contracts.js"; +export type { BlockParams, LogParams, TransactionReceiptParams, TransactionResponseParams, } from "./formatting.js"; +export type { Networkish } from "./network.js"; +export type { GasCostParameters } from "./plugins-network.js"; +export type { BlockTag, TransactionRequest, PreparedTransactionRequest, EventFilter, Filter, FilterByBlockHash, OrphanFilter, ProviderEvent, TopicFilter, Provider, MinedBlock, MinedTransactionResponse } from "./provider.js"; +export type { DebugEventBrowserProvider, Eip1193Provider } from "./provider-browser.js"; +export type { FallbackProviderOptions } from "./provider-fallback.js"; +export type { JsonRpcPayload, JsonRpcResult, JsonRpcError, JsonRpcApiProviderOptions, JsonRpcTransactionRequest, } from "./provider-jsonrpc.js"; +export type { WebSocketCreator, WebSocketLike } from "./provider-websocket.js"; +export type { Signer } from "./signer.js"; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/lib.esm/providers/index.d.ts.map b/lib.esm/providers/index.d.ts.map new file mode 100644 index 00000000..4947c29e --- /dev/null +++ b/lib.esm/providers/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src.ts/providers/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EACH,gBAAgB,EAAE,mBAAmB,EACxC,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACH,cAAc,EACd,UAAU,GACb,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACH,mBAAmB,EACtB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE3D,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD,OAAO,EACH,aAAa,EACb,aAAa,EACb,SAAS,EACT,oBAAoB,EACpB,4BAA4B,GAC/B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACH,KAAK,EACL,OAAO,EACP,GAAG,EACH,kBAAkB,EAClB,mBAAmB,EAEnB,WAAW,GAEd,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAE1F,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,OAAO,EAAE,iB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index.js new file mode 100644 index 00000000..f33e1dd6 --- /dev/null +++ b/lib.esm/providers/index.js @@ -0,0 +1,30 @@ +/** + * A **Provider** provides a connection to the blockchain, whch can be + * used to query its current state, simulate execution and send transactions + * to update the state. + * + * It is one of the most fundamental components of interacting with a + * blockchain application, and there are many ways to connect, such as over + * HTTP, WebSockets or injected providers such as [MetaMask](link-metamask). + * + * @_section: api/providers:Providers [about-providers] + */ +export { AbstractProvider, UnmanagedSubscriber } from "./abstract-provider.js"; +export { AbstractSigner, VoidSigner, } from "./abstract-signer.js"; +export { showThrottleMessage } from "./community.js"; +export { getDefaultProvider } from "./default-provider.js"; +export { Network } from "./network.js"; +export { NonceManager } from "./signer-noncemanager.js"; +export { NetworkPlugin, GasCostPlugin, EnsPlugin, FeeDataNetworkPlugin, FetchUrlFeeDataNetworkPlugin, } from "./plugins-network.js"; +export { Block, FeeData, Log, TransactionReceipt, TransactionResponse, copyRequest, +//resolveTransactionRequest, + } from "./provider.js"; +export { FallbackProvider } from "./provider-fallback.js"; +export { JsonRpcApiProvider, JsonRpcProvider, JsonRpcSigner } from "./provider-jsonrpc.js"; +export { BrowserProvider } from "./provider-browser.js"; +import { IpcSocketProvider } from "./provider-ipcsocket.js"; /*-browser*/ +export { IpcSocketProvider }; +export { SocketProvider } from "./provider-socket.js"; +export { WebSocketProvider } from "./provider-websocket.js"; +export { SocketSubscriber, SocketBlockSubscriber, SocketPendingSubscriber, SocketEventSubscriber } from "./provider-socket.js"; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib.esm/providers/index.js.map b/lib.esm/providers/index.js.map new file mode 100644 index 00000000..e8e491c1 --- /dev/null +++ b/lib.esm/providers/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src.ts/providers/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EACH,gBAAgB,EAAE,mBAAmB,EACxC,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACH,cAAc,EACd,UAAU,GACb,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACH,mBAAmB,EACtB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE3D,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD,OAAO,EACH,aAAa,EACb,aAAa,EACb,SAAS,EACT,oBAAoB,EACpB,4BAA4B,GAC/B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACH,KAAK,EACL,OAAO,EACP,GAAG,EACH,kBAAkB,EAClB,mBAAmB,EAEnB,WAAW;AACX,4BAA4B;EAC/B,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAE1F,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC,CAAC,YAAY;AACzE,OAAO,EAAE,iBAAiB,EAAE,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,OAAO,EACH,gBAAgB,EAAE,qBAAqB,EAAE,uBAAuB,EAChE,qBAAqB,EACxB,MAAM,sBAAsB,CAAC"} \ No newline at end of file diff --git a/lib.esm/providers/network.d.ts b/lib.esm/providers/network.d.ts new file mode 100644 index 00000000..2355df44 --- /dev/null +++ b/lib.esm/providers/network.d.ts @@ -0,0 +1,99 @@ +/** + * A **Network** encapsulates the various properties required to + * interact with a specific chain. + * + * @_subsection: api/providers:Networks [networks] + */ +import type { BigNumberish } from "../utils/index.js"; +import type { TransactionLike } from "../transaction/index.js"; +import type { NetworkPlugin } from "./plugins-network.js"; +/** + * A Networkish can be used to allude to a Network, by specifing: + * - a [[Network]] object + * - a well-known (or registered) network name + * - a well-known (or registered) chain ID + * - an object with sufficient details to describe a network + */ +export type Networkish = Network | number | bigint | string | { + name?: string; + chainId?: number; + ensAddress?: string; + ensNetwork?: number; +}; +/** + * A **Network** provides access to a chain's properties and allows + * for plug-ins to extend functionality. + */ +export declare class Network { + #private; + /** + * Creates a new **Network** for %%name%% and %%chainId%%. + */ + constructor(name: string, chainId: BigNumberish); + /** + * Returns a JSON-compatible representation of a Network. + */ + toJSON(): any; + /** + * The network common name. + * + * This is the canonical name, as networks migh have multiple + * names. + */ + get name(): string; + set name(value: string); + /** + * The network chain ID. + */ + get chainId(): bigint; + set chainId(value: BigNumberish); + /** + * Returns true if %%other%% matches this network. Any chain ID + * must match, and if no chain ID is present, the name must match. + * + * This method does not currently check for additional properties, + * such as ENS address or plug-in compatibility. + */ + matches(other: Networkish): boolean; + /** + * Returns the list of plugins currently attached to this Network. + */ + get plugins(): Array; + /** + * Attach a new %%plugin%% to this Network. The network name + * must be unique, excluding any fragment. + */ + attachPlugin(plugin: NetworkPlugin): this; + /** + * Return the plugin, if any, matching %%name%% exactly. Plugins + * with fragments will not be returned unless %%name%% includes + * a fragment. + */ + getPlugin(name: string): null | T; + /** + * Gets a list of all plugins that match %%name%%, with otr without + * a fragment. + */ + getPlugins(basename: string): Array; + /** + * Create a copy of this Network. + */ + clone(): Network; + /** + * Compute the intrinsic gas required for a transaction. + * + * A GasCostPlugin can be attached to override the default + * values. + */ + computeIntrinsicGas(tx: TransactionLike): number; + /** + * Returns a new Network for the %%network%% name or chainId. + */ + static from(network?: Networkish): Network; + /** + * Register %%nameOrChainId%% with a function which returns + * an instance of a Network representing that chain. + */ + static register(nameOrChainId: string | number | bigint, networkFunc: () => Network): void; +} +//# sourceMappingURL=network.d.ts.map \ No newline at end of file diff --git a/lib.esm/providers/network.d.ts.map b/lib.esm/providers/network.d.ts.map new file mode 100644 index 00000000..b849aebb --- /dev/null +++ b/lib.esm/providers/network.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../src.ts/providers/network.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE/D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAG1D;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG;IAC1D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAA;CACtB,CAAC;AA2BF;;;GAGG;AACH,qBAAa,OAAO;;IAMhB;;OAEG;gBACS,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY;IAM/C;;OAEG;IACH,MAAM,IAAI,GAAG;IAIb;;;;;OAKG;IACH,IAAI,IAAI,IAAI,MAAM,CAAuB;IACzC,IAAI,IAAI,CAAC,KAAK,EAAE,MAAM,EAA0B;IAEhD;;OAEG;IACH,IAAI,OAAO,IAAI,MAAM,CAA0B;IAC/C,IAAI,OAAO,CAAC,KAAK,EAAE,YAAY,EAAkD;IAEjF;;;;;;OAMG;IACH,OAAO,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO;IAiCnC;;OAEG;IACH,IAAI,OAAO,IAAI,KAAK,CAAC,aAAa,CAAC,CAElC;IAED;;;OAGG;IACH,YAAY,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI;IAQzC;;;;OAIG;IACH,SAAS,CAAC,CAAC,SAAS,aAAa,GAAG,aAAa,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,CAAC;IAI1E;;;OAGG;IACH,UAAU,CAAC,CAAC,SAAS,aAAa,GAAG,aAAa,EAAE,QAAQ,EAAE,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC;IAI/E;;OAEG;IACH,KAAK,IAAI,OAAO;IAQhB;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,EAAE,eAAe,GAAG,MAAM;IAyBhD;;OAEG;IACH,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,UAAU,GAAG,OAAO;IA+C1C;;;OAGG;IACH,MAAM,CAAC,QAAQ,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,WAAW,EAAE,MAAM,OAAO,GAAG,IAAI;CAQ7F"} \ No newline at end of file diff --git a/lib.esm/providers/network.js b/lib.esm/providers/network.js new file mode 100644 index 00000000..ade8b0a5 --- /dev/null +++ b/lib.esm/providers/network.js @@ -0,0 +1,358 @@ +/** + * A **Network** encapsulates the various properties required to + * interact with a specific chain. + * + * @_subsection: api/providers:Networks [networks] + */ +import { accessListify } from "../transaction/index.js"; +import { getBigInt, assert, assertArgument } from "../utils/index.js"; +import { EnsPlugin, FetchUrlFeeDataNetworkPlugin, GasCostPlugin } from "./plugins-network.js"; +/* * * * +// Networks which operation against an L2 can use this plugin to +// specify how to access L1, for the purpose of resolving ENS, +// for example. +export class LayerOneConnectionPlugin extends NetworkPlugin { + readonly provider!: Provider; +// @TODO: Rename to ChainAccess and allow for connecting to any chain + constructor(provider: Provider) { + super("org.quais.plugins.layer-one-connection"); + defineProperties(this, { provider }); + } + + clone(): LayerOneConnectionPlugin { + return new LayerOneConnectionPlugin(this.provider); + } +} +*/ +const Networks = new Map(); +/** + * A **Network** provides access to a chain's properties and allows + * for plug-ins to extend functionality. + */ +export class Network { + #name; + #chainId; + #plugins; + /** + * Creates a new **Network** for %%name%% and %%chainId%%. + */ + constructor(name, chainId) { + this.#name = name; + this.#chainId = getBigInt(chainId); + this.#plugins = new Map(); + } + /** + * Returns a JSON-compatible representation of a Network. + */ + toJSON() { + return { name: this.name, chainId: String(this.chainId) }; + } + /** + * The network common name. + * + * This is the canonical name, as networks migh have multiple + * names. + */ + get name() { return this.#name; } + set name(value) { this.#name = value; } + /** + * The network chain ID. + */ + get chainId() { return this.#chainId; } + set chainId(value) { this.#chainId = getBigInt(value, "chainId"); } + /** + * Returns true if %%other%% matches this network. Any chain ID + * must match, and if no chain ID is present, the name must match. + * + * This method does not currently check for additional properties, + * such as ENS address or plug-in compatibility. + */ + matches(other) { + if (other == null) { + return false; + } + if (typeof (other) === "string") { + try { + return (this.chainId === getBigInt(other)); + } + catch (error) { } + return (this.name === other); + } + if (typeof (other) === "number" || typeof (other) === "bigint") { + try { + return (this.chainId === getBigInt(other)); + } + catch (error) { } + return false; + } + if (typeof (other) === "object") { + if (other.chainId != null) { + try { + return (this.chainId === getBigInt(other.chainId)); + } + catch (error) { } + return false; + } + if (other.name != null) { + return (this.name === other.name); + } + return false; + } + return false; + } + /** + * Returns the list of plugins currently attached to this Network. + */ + get plugins() { + return Array.from(this.#plugins.values()); + } + /** + * Attach a new %%plugin%% to this Network. The network name + * must be unique, excluding any fragment. + */ + attachPlugin(plugin) { + if (this.#plugins.get(plugin.name)) { + throw new Error(`cannot replace existing plugin: ${plugin.name} `); + } + this.#plugins.set(plugin.name, plugin.clone()); + return this; + } + /** + * Return the plugin, if any, matching %%name%% exactly. Plugins + * with fragments will not be returned unless %%name%% includes + * a fragment. + */ + getPlugin(name) { + return (this.#plugins.get(name)) || null; + } + /** + * Gets a list of all plugins that match %%name%%, with otr without + * a fragment. + */ + getPlugins(basename) { + return (this.plugins.filter((p) => (p.name.split("#")[0] === basename))); + } + /** + * Create a copy of this Network. + */ + clone() { + const clone = new Network(this.name, this.chainId); + this.plugins.forEach((plugin) => { + clone.attachPlugin(plugin.clone()); + }); + return clone; + } + /** + * Compute the intrinsic gas required for a transaction. + * + * A GasCostPlugin can be attached to override the default + * values. + */ + computeIntrinsicGas(tx) { + const costs = this.getPlugin("org.quais.plugins.network.GasCost") || (new GasCostPlugin()); + let gas = costs.txBase; + if (tx.to == null) { + gas += costs.txCreate; + } + if (tx.data) { + for (let i = 2; i < tx.data.length; i += 2) { + if (tx.data.substring(i, i + 2) === "00") { + gas += costs.txDataZero; + } + else { + gas += costs.txDataNonzero; + } + } + } + if (tx.accessList) { + const accessList = accessListify(tx.accessList); + for (const addr in accessList) { + gas += costs.txAccessListAddress + costs.txAccessListStorageKey * accessList[addr].storageKeys.length; + } + } + return gas; + } + /** + * Returns a new Network for the %%network%% name or chainId. + */ + static from(network) { + injectCommonNetworks(); + // Default network + if (network == null) { + return Network.from("mainnet"); + } + // Canonical name or chain ID + if (typeof (network) === "number") { + network = BigInt(network); + } + if (typeof (network) === "string" || typeof (network) === "bigint") { + const networkFunc = Networks.get(network); + if (networkFunc) { + return networkFunc(); + } + if (typeof (network) === "bigint") { + return new Network("unknown", network); + } + assertArgument(false, "unknown network", "network", network); + } + // Clonable with network-like abilities + if (typeof (network.clone) === "function") { + const clone = network.clone(); + //if (typeof(network.name) !== "string" || typeof(network.chainId) !== "number") { + //} + return clone; + } + // Networkish + if (typeof (network) === "object") { + assertArgument(typeof (network.name) === "string" && typeof (network.chainId) === "number", "invalid network object name or chainId", "network", network); + const custom = new Network((network.name), (network.chainId)); + if (network.ensAddress || network.ensNetwork != null) { + custom.attachPlugin(new EnsPlugin(network.ensAddress, network.ensNetwork)); + } + //if ((network).layerOneConnection) { + // custom.attachPlugin(new LayerOneConnectionPlugin((network).layerOneConnection)); + //} + return custom; + } + assertArgument(false, "invalid network", "network", network); + } + /** + * Register %%nameOrChainId%% with a function which returns + * an instance of a Network representing that chain. + */ + static register(nameOrChainId, networkFunc) { + if (typeof (nameOrChainId) === "number") { + nameOrChainId = BigInt(nameOrChainId); + } + const existing = Networks.get(nameOrChainId); + if (existing) { + assertArgument(false, `conflicting network for ${JSON.stringify(existing.name)}`, "nameOrChainId", nameOrChainId); + } + Networks.set(nameOrChainId, networkFunc); + } +} +// We don't want to bring in formatUnits because it is backed by +// FixedNumber and we want to keep Networks tiny. The values +// included by the Gas Stations are also IEEE 754 with lots of +// rounding issues and exceed the strict checks formatUnits has. +function parseUnits(_value, decimals) { + const value = String(_value); + if (!value.match(/^[0-9.]+$/)) { + throw new Error(`invalid gwei value: ${_value}`); + } + // Break into [ whole, fraction ] + const comps = value.split("."); + if (comps.length === 1) { + comps.push(""); + } + // More than 1 decimal point or too many fractional positions + if (comps.length !== 2) { + throw new Error(`invalid gwei value: ${_value}`); + } + // Pad the fraction to 9 decimalplaces + while (comps[1].length < decimals) { + comps[1] += "0"; + } + // Too many decimals and some non-zero ending, take the ceiling + if (comps[1].length > 9) { + let frac = BigInt(comps[1].substring(0, 9)); + if (!comps[1].substring(9).match(/^0+$/)) { + frac++; + } + comps[1] = frac.toString(); + } + return BigInt(comps[0] + comps[1]); +} +// Used by Polygon to use a gas station for fee data +function getGasStationPlugin(url) { + return new FetchUrlFeeDataNetworkPlugin(url, async (fetchFeeData, provider, request) => { + // Prevent Cloudflare from blocking our request in node.js + request.setHeader("User-Agent", "quais"); + let response; + try { + const [_response, _feeData] = await Promise.all([ + request.send(), fetchFeeData() + ]); + response = _response; + const payload = response.bodyJson.standard; + const feeData = { + gasPrice: _feeData.gasPrice, + maxFeePerGas: parseUnits(payload.maxFee, 9), + maxPriorityFeePerGas: parseUnits(payload.maxPriorityFee, 9), + }; + return feeData; + } + catch (error) { + assert(false, `error encountered with polygon gas station (${JSON.stringify(request.url)})`, "SERVER_ERROR", { request, response, error }); + } + }); +} +// See: https://chainlist.org +let injected = false; +function injectCommonNetworks() { + if (injected) { + return; + } + injected = true; + /// Register popular Ethereum networks + function registerEth(name, chainId, options) { + const func = function () { + const network = new Network(name, chainId); + // We use 0 to disable ENS + if (options.ensNetwork != null) { + network.attachPlugin(new EnsPlugin(null, options.ensNetwork)); + } + network.attachPlugin(new GasCostPlugin()); + (options.plugins || []).forEach((plugin) => { + network.attachPlugin(plugin); + }); + return network; + }; + // Register the network by name and chain ID + Network.register(name, func); + Network.register(chainId, func); + if (options.altNames) { + options.altNames.forEach((name) => { + Network.register(name, func); + }); + } + } + registerEth("mainnet", 1, { ensNetwork: 1, altNames: ["homestead"] }); + registerEth("ropsten", 3, { ensNetwork: 3 }); + registerEth("rinkeby", 4, { ensNetwork: 4 }); + registerEth("goerli", 5, { ensNetwork: 5 }); + registerEth("kovan", 42, { ensNetwork: 42 }); + registerEth("sepolia", 11155111, { ensNetwork: 11155111 }); + registerEth("classic", 61, {}); + registerEth("classicKotti", 6, {}); + registerEth("arbitrum", 42161, { + ensNetwork: 1, + }); + registerEth("arbitrum-goerli", 421613, {}); + registerEth("base", 8453, { ensNetwork: 1 }); + registerEth("base-goerli", 84531, {}); + registerEth("base-sepolia", 84532, {}); + registerEth("bnb", 56, { ensNetwork: 1 }); + registerEth("bnbt", 97, {}); + registerEth("linea", 59144, { ensNetwork: 1 }); + registerEth("linea-goerli", 59140, {}); + registerEth("matic", 137, { + ensNetwork: 1, + plugins: [ + getGasStationPlugin("https:/\/gasstation.polygon.technology/v2") + ] + }); + registerEth("matic-mumbai", 80001, { + altNames: ["maticMumbai", "maticmum"], + plugins: [ + getGasStationPlugin("https:/\/gasstation-testnet.polygon.technology/v2") + ] + }); + registerEth("optimism", 10, { + ensNetwork: 1, + plugins: [] + }); + registerEth("optimism-goerli", 420, {}); + registerEth("xdai", 100, { ensNetwork: 1 }); +} +//# sourceMappingURL=network.js.map \ No newline at end of file diff --git a/lib.esm/providers/network.js.map b/lib.esm/providers/network.js.map new file mode 100644 index 00000000..2dfe72ef --- /dev/null +++ b/lib.esm/providers/network.js.map @@ -0,0 +1 @@ +{"version":3,"file":"network.js","sourceRoot":"","sources":["../../src.ts/providers/network.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEtE,OAAO,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AAC,2CAA2C,CAAC;SACnE;KACJ,CAAC,CAAC;IACH,WAAW,CAAC,cAAc,EAAE,KAAK,EAAE;QAC/B,QAAQ,EAAE,CAAE,aAAa,EAAE,UAAU,CAAE;QACvC,OAAO,EAAE;YACL,mBAAmB,CAAC,mDAAmD,CAAC;SAC3E;KACJ,CAAC,CAAC;IAEH,WAAW,CAAC,UAAU,EAAE,EAAE,EAAE;QACxB,UAAU,EAAE,CAAC;QACb,OAAO,EAAE,EAAG;KACf,CAAC,CAAC;IACH,WAAW,CAAC,iBAAiB,EAAE,GAAG,EAAE,EAAG,CAAC,CAAC;IAEzC,WAAW,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC,CAAC;AAChD,CAAC"} \ No newline at end of file diff --git a/lib.esm/providers/pagination.d.ts b/lib.esm/providers/pagination.d.ts new file mode 100644 index 00000000..a772a85c --- /dev/null +++ b/lib.esm/providers/pagination.d.ts @@ -0,0 +1,6 @@ +export interface PaginationResult extends Array { + next(): Promise>; + totalResults: null | number; + done: boolean; +} +//# sourceMappingURL=pagination.d.ts.map \ No newline at end of file diff --git a/lib.esm/providers/pagination.d.ts.map b/lib.esm/providers/pagination.d.ts.map new file mode 100644 index 00000000..083dedb3 --- /dev/null +++ b/lib.esm/providers/pagination.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"pagination.d.ts","sourceRoot":"","sources":["../../src.ts/providers/pagination.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB,CAAC,CAAC,CAAE,SAAQ,KAAK,CAAC,CAAC,CAAC;IACjD,IAAI,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC;IAGrC,YAAY,EAAE,IAAI,GAAG,MAAM,CAAC;IAE5B,IAAI,EAAE,OAAO,CAAC;CACjB"} \ No newline at end of file diff --git a/lib.esm/providers/pagination.js b/lib.esm/providers/pagination.js new file mode 100644 index 00000000..dad94f2f --- /dev/null +++ b/lib.esm/providers/pagination.js @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=pagination.js.map \ No newline at end of file diff --git a/lib.esm/providers/pagination.js.map b/lib.esm/providers/pagination.js.map new file mode 100644 index 00000000..d08e925c --- /dev/null +++ b/lib.esm/providers/pagination.js.map @@ -0,0 +1 @@ +{"version":3,"file":"pagination.js","sourceRoot":"","sources":["../../src.ts/providers/pagination.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/lib.esm/providers/plugin-fallback.d.ts b/lib.esm/providers/plugin-fallback.d.ts new file mode 100644 index 00000000..0128e8b7 --- /dev/null +++ b/lib.esm/providers/plugin-fallback.d.ts @@ -0,0 +1,13 @@ +import { AbstractProviderPlugin } from "./abstract-provider.js"; +import type { AbstractProvider, PerformActionRequest } from "./abstract-provider.js"; +export declare const PluginIdFallbackProvider = "org.quais.plugins.provider.QualifiedPlugin"; +export declare class CheckQualifiedPlugin implements AbstractProviderPlugin { + name: string; + constructor(); + connect(provider: AbstractProvider): CheckQualifiedPlugin; + isQualified(action: PerformActionRequest, result: any): boolean; +} +export declare class PossiblyPrunedTransactionPlugin extends CheckQualifiedPlugin { + isQualified(action: PerformActionRequest, result: any): boolean; +} +//# sourceMappingURL=plugin-fallback.d.ts.map \ No newline at end of file diff --git a/lib.esm/providers/plugin-fallback.d.ts.map b/lib.esm/providers/plugin-fallback.d.ts.map new file mode 100644 index 00000000..484b434a --- /dev/null +++ b/lib.esm/providers/plugin-fallback.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"plugin-fallback.d.ts","sourceRoot":"","sources":["../../src.ts/providers/plugin-fallback.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAGhE,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAGrF,eAAO,MAAM,wBAAwB,+CAA+C,CAAC;AAErF,qBAAa,oBAAqB,YAAW,sBAAsB;IACvD,IAAI,EAAE,MAAM,CAAC;;IAMrB,OAAO,CAAC,QAAQ,EAAE,gBAAgB,GAAG,oBAAoB;IAMzD,WAAW,CAAC,MAAM,EAAE,oBAAoB,EAAE,MAAM,EAAE,GAAG,GAAG,OAAO;CAGlE;AAED,qBAAa,+BAAgC,SAAQ,oBAAoB;IACrE,WAAW,CAAC,MAAM,EAAE,oBAAoB,EAAE,MAAM,EAAE,GAAG,GAAG,OAAO;CAMlE"} \ No newline at end of file diff --git a/lib.esm/providers/plugin-fallback.js b/lib.esm/providers/plugin-fallback.js new file mode 100644 index 00000000..e9789c47 --- /dev/null +++ b/lib.esm/providers/plugin-fallback.js @@ -0,0 +1,26 @@ +import { defineProperties } from "../utils/index.js"; +export const PluginIdFallbackProvider = "org.quais.plugins.provider.QualifiedPlugin"; +export class CheckQualifiedPlugin { + constructor() { + defineProperties(this, { name: PluginIdFallbackProvider }); + } + connect(provider) { + return this; + } + // Retruns true if this value should be considered qualified for + // inclusion in the quorum. + isQualified(action, result) { + return true; + } +} +export class PossiblyPrunedTransactionPlugin extends CheckQualifiedPlugin { + isQualified(action, result) { + if (action.method === "getTransaction" || action.method === "getTransactionReceipt") { + if (result == null) { + return false; + } + } + return super.isQualified(action, result); + } +} +//# sourceMappingURL=plugin-fallback.js.map \ No newline at end of file diff --git a/lib.esm/providers/plugin-fallback.js.map b/lib.esm/providers/plugin-fallback.js.map new file mode 100644 index 00000000..fec22626 --- /dev/null +++ b/lib.esm/providers/plugin-fallback.js.map @@ -0,0 +1 @@ +{"version":3,"file":"plugin-fallback.js","sourceRoot":"","sources":["../../src.ts/providers/plugin-fallback.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAKrD,MAAM,CAAC,MAAM,wBAAwB,GAAG,4CAA4C,CAAC;AAErF,MAAM,OAAO,oBAAoB;IAG7B;QACI,gBAAgB,CAAuB,IAAI,EAAE,EAAE,IAAI,EAAE,wBAAwB,EAAE,CAAC,CAAC;IACrF,CAAC;IAED,OAAO,CAAC,QAA0B;QAC9B,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,gEAAgE;IAChE,2BAA2B;IAC3B,WAAW,CAAC,MAA4B,EAAE,MAAW;QACjD,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AAED,MAAM,OAAO,+BAAgC,SAAQ,oBAAoB;IACrE,WAAW,CAAC,MAA4B,EAAE,MAAW;QACjD,IAAI,MAAM,CAAC,MAAM,KAAK,gBAAgB,IAAI,MAAM,CAAC,MAAM,KAAK,uBAAuB,EAAE;YACjF,IAAI,MAAM,IAAI,IAAI,EAAE;gBAAE,OAAO,KAAK,CAAC;aAAE;SACxC;QACD,OAAO,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7C,CAAC;CACJ"} \ No newline at end of file diff --git a/lib.esm/providers/plugins-network.d.ts b/lib.esm/providers/plugins-network.d.ts new file mode 100644 index 00000000..73857820 --- /dev/null +++ b/lib.esm/providers/plugins-network.d.ts @@ -0,0 +1,170 @@ +import type { FeeData, Provider } from "./provider.js"; +import type { FetchRequest } from "../utils/fetch.js"; +/** + * A **NetworkPlugin** provides additional functionality on a [[Network]]. + */ +export declare class NetworkPlugin { + /** + * The name of the plugin. + * + * It is recommended to use reverse-domain-notation, which permits + * unique names with a known authority as well as hierarchal entries. + */ + readonly name: string; + /** + * Creates a new **NetworkPlugin**. + */ + constructor(name: string); + /** + * Creates a copy of this plugin. + */ + clone(): NetworkPlugin; +} +/** + * The gas cost parameters for a [[GasCostPlugin]]. + */ +export type GasCostParameters = { + /** + * The transactions base fee. + */ + txBase?: number; + /** + * The fee for creating a new account. + */ + txCreate?: number; + /** + * The fee per zero-byte in the data. + */ + txDataZero?: number; + /** + * The fee per non-zero-byte in the data. + */ + txDataNonzero?: number; + /** + * The fee per storage key in the [[link-eip-2930]] access list. + */ + txAccessListStorageKey?: number; + /** + * The fee per address in the [[link-eip-2930]] access list. + */ + txAccessListAddress?: number; +}; +/** + * A **GasCostPlugin** allows a network to provide alternative values when + * computing the intrinsic gas required for a transaction. + */ +export declare class GasCostPlugin extends NetworkPlugin implements GasCostParameters { + /** + * The block number to treat these values as valid from. + * + * This allows a hardfork to have updated values included as well as + * mulutiple hardforks to be supported. + */ + readonly effectiveBlock: number; + /** + * The transactions base fee. + */ + readonly txBase: number; + /** + * The fee for creating a new account. + */ + readonly txCreate: number; + /** + * The fee per zero-byte in the data. + */ + readonly txDataZero: number; + /** + * The fee per non-zero-byte in the data. + */ + readonly txDataNonzero: number; + /** + * The fee per storage key in the [[link-eip-2930]] access list. + */ + readonly txAccessListStorageKey: number; + /** + * The fee per address in the [[link-eip-2930]] access list. + */ + readonly txAccessListAddress: number; + /** + * Creates a new GasCostPlugin from %%effectiveBlock%% until the + * latest block or another GasCostPlugin supercedes that block number, + * with the associated %%costs%%. + */ + constructor(effectiveBlock?: number, costs?: GasCostParameters); + clone(): GasCostPlugin; +} +/** + * An **EnsPlugin** allows a [[Network]] to specify the ENS Registry + * Contract address and the target network to use when using that + * contract. + * + * Various testnets have their own instance of the contract to use, but + * in general, the mainnet instance supports multi-chain addresses and + * should be used. + */ +export declare class EnsPlugin extends NetworkPlugin { + /** + * The ENS Registrty Contract address. + */ + readonly address: string; + /** + * The chain ID that the ENS contract lives on. + */ + readonly targetNetwork: number; + /** + * Creates a new **EnsPlugin** connected to %%address%% on the + * %%targetNetwork%%. The default ENS address and mainnet is used + * if unspecified. + */ + constructor(address?: null | string, targetNetwork?: null | number); + clone(): EnsPlugin; +} +/** + * A **FeeDataNetworkPlugin** allows a network to provide and alternate + * means to specify its fee data. + * + * For example, a network which does not support [[link-eip-1559]] may + * choose to use a Gas Station site to approximate the gas price. + */ +export declare class FeeDataNetworkPlugin extends NetworkPlugin { + #private; + /** + * The fee data function provided to the constructor. + */ + get feeDataFunc(): (provider: Provider) => Promise; + /** + * Creates a new **FeeDataNetworkPlugin**. + */ + constructor(feeDataFunc: (provider: Provider) => Promise); + /** + * Resolves to the fee data. + */ + getFeeData(provider: Provider): Promise; + clone(): FeeDataNetworkPlugin; +} +export declare class FetchUrlFeeDataNetworkPlugin extends NetworkPlugin { + #private; + /** + * The URL to initialize the FetchRequest with in %%processFunc%%. + */ + get url(): string; + /** + * The callback to use when computing the FeeData. + */ + get processFunc(): (f: () => Promise, p: Provider, r: FetchRequest) => Promise<{ + gasPrice?: null | bigint; + maxFeePerGas?: null | bigint; + maxPriorityFeePerGas?: null | bigint; + }>; + /** + * Creates a new **FetchUrlFeeDataNetworkPlugin** which will + * be used when computing the fee data for the network. + */ + constructor(url: string, processFunc: (f: () => Promise, p: Provider, r: FetchRequest) => Promise<{ + gasPrice?: null | bigint; + maxFeePerGas?: null | bigint; + maxPriorityFeePerGas?: null | bigint; + }>); + clone(): FetchUrlFeeDataNetworkPlugin; +} +//# sourceMappingURL=plugins-network.d.ts.map \ No newline at end of file diff --git a/lib.esm/providers/plugins-network.d.ts.map b/lib.esm/providers/plugins-network.d.ts.map new file mode 100644 index 00000000..77938545 --- /dev/null +++ b/lib.esm/providers/plugins-network.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"plugins-network.d.ts","sourceRoot":"","sources":["../../src.ts/providers/plugins-network.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAKtD;;GAEG;AACH,qBAAa,aAAa;IACtB;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,EAAG,MAAM,CAAC;IAEvB;;OAEG;gBACS,IAAI,EAAE,MAAM;IAIxB;;OAEG;IACH,KAAK,IAAI,aAAa;CAOzB;AAGD;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC5B;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,U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gBACS,WAAW,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,OAAO,CAAC,OAAO,CAAC;IAKjE;;OAEG;IACG,UAAU,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;IAItD,KAAK,IAAI,oBAAoB;CAGhC;AAED,qBAAa,4BAA6B,SAAQ,aAAa;;IAI3D;;OAEG;IACH,IAAI,GAAG,IAAI,MAAM,CAAsB;IAEvC;;OAEG;IACH,IAAI,WAAW,IAAI,CAAC,CAAC,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,YAAY,KAAK,OAAO,CAAC;QAAE,QAAQ,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;QAAC,oBAAoB,CAAC,EAAE,IAAI,GAAG,MAAM,CAAA;KAAE,CAAC,CAA8B;IAEvN;;;OAGG;gBACS,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC,CAAC,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,YAAY,KAAK,OAAO,CAAC;QAAE,QAAQ,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;QAAC,oBAAoB,CAAC,EAAE,IAAI,GAAG,MAAM,CAAA;KAAE,CAAC;IAO5M,KAAK,IAAI,4BAA4B;CACxC"} \ No newline at end of file diff --git a/lib.esm/providers/plugins-network.js b/lib.esm/providers/plugins-network.js new file mode 100644 index 00000000..d9fd4b20 --- /dev/null +++ b/lib.esm/providers/plugins-network.js @@ -0,0 +1,208 @@ +import { defineProperties } from "../utils/properties.js"; +import { assertArgument } from "../utils/index.js"; +const EnsAddress = "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"; +/** + * A **NetworkPlugin** provides additional functionality on a [[Network]]. + */ +export class NetworkPlugin { + /** + * The name of the plugin. + * + * It is recommended to use reverse-domain-notation, which permits + * unique names with a known authority as well as hierarchal entries. + */ + name; + /** + * Creates a new **NetworkPlugin**. + */ + constructor(name) { + defineProperties(this, { name }); + } + /** + * Creates a copy of this plugin. + */ + clone() { + return new NetworkPlugin(this.name); + } +} +/** + * A **GasCostPlugin** allows a network to provide alternative values when + * computing the intrinsic gas required for a transaction. + */ +export class GasCostPlugin extends NetworkPlugin { + /** + * The block number to treat these values as valid from. + * + * This allows a hardfork to have updated values included as well as + * mulutiple hardforks to be supported. + */ + effectiveBlock; + /** + * The transactions base fee. + */ + txBase; + /** + * The fee for creating a new account. + */ + txCreate; + /** + * The fee per zero-byte in the data. + */ + txDataZero; + /** + * The fee per non-zero-byte in the data. + */ + txDataNonzero; + /** + * The fee per storage key in the [[link-eip-2930]] access list. + */ + txAccessListStorageKey; + /** + * The fee per address in the [[link-eip-2930]] access list. + */ + txAccessListAddress; + /** + * Creates a new GasCostPlugin from %%effectiveBlock%% until the + * latest block or another GasCostPlugin supercedes that block number, + * with the associated %%costs%%. + */ + constructor(effectiveBlock, costs) { + if (effectiveBlock == null) { + effectiveBlock = 0; + } + super(`org.quais.network.plugins.GasCost#${(effectiveBlock || 0)}`); + const props = { effectiveBlock }; + function set(name, nullish) { + let value = (costs || {})[name]; + if (value == null) { + value = nullish; + } + assertArgument(typeof (value) === "number", `invalud value for ${name}`, "costs", costs); + props[name] = value; + } + set("txBase", 21000); + set("txCreate", 32000); + set("txDataZero", 4); + set("txDataNonzero", 16); + set("txAccessListStorageKey", 1900); + set("txAccessListAddress", 2400); + defineProperties(this, props); + } + clone() { + return new GasCostPlugin(this.effectiveBlock, this); + } +} +/** + * An **EnsPlugin** allows a [[Network]] to specify the ENS Registry + * Contract address and the target network to use when using that + * contract. + * + * Various testnets have their own instance of the contract to use, but + * in general, the mainnet instance supports multi-chain addresses and + * should be used. + */ +export class EnsPlugin extends NetworkPlugin { + /** + * The ENS Registrty Contract address. + */ + address; + /** + * The chain ID that the ENS contract lives on. + */ + targetNetwork; + /** + * Creates a new **EnsPlugin** connected to %%address%% on the + * %%targetNetwork%%. The default ENS address and mainnet is used + * if unspecified. + */ + constructor(address, targetNetwork) { + super("org.quais.plugins.network.Ens"); + defineProperties(this, { + address: (address || EnsAddress), + targetNetwork: ((targetNetwork == null) ? 1 : targetNetwork) + }); + } + clone() { + return new EnsPlugin(this.address, this.targetNetwork); + } +} +/** + * A **FeeDataNetworkPlugin** allows a network to provide and alternate + * means to specify its fee data. + * + * For example, a network which does not support [[link-eip-1559]] may + * choose to use a Gas Station site to approximate the gas price. + */ +export class FeeDataNetworkPlugin extends NetworkPlugin { + #feeDataFunc; + /** + * The fee data function provided to the constructor. + */ + get feeDataFunc() { + return this.#feeDataFunc; + } + /** + * Creates a new **FeeDataNetworkPlugin**. + */ + constructor(feeDataFunc) { + super("org.quais.plugins.network.FeeData"); + this.#feeDataFunc = feeDataFunc; + } + /** + * Resolves to the fee data. + */ + async getFeeData(provider) { + return await this.#feeDataFunc(provider); + } + clone() { + return new FeeDataNetworkPlugin(this.#feeDataFunc); + } +} +export class FetchUrlFeeDataNetworkPlugin extends NetworkPlugin { + #url; + #processFunc; + /** + * The URL to initialize the FetchRequest with in %%processFunc%%. + */ + get url() { return this.#url; } + /** + * The callback to use when computing the FeeData. + */ + get processFunc() { return this.#processFunc; } + /** + * Creates a new **FetchUrlFeeDataNetworkPlugin** which will + * be used when computing the fee data for the network. + */ + constructor(url, processFunc) { + super("org.quais.plugins.network.FetchUrlFeeDataPlugin"); + this.#url = url; + this.#processFunc = processFunc; + } + // We are immutable, so we can serve as our own clone + clone() { return this; } +} +/* +export class CustomBlockNetworkPlugin extends NetworkPlugin { + readonly #blockFunc: (provider: Provider, block: BlockParams) => Block; + readonly #blockWithTxsFunc: (provider: Provider, block: BlockParams) => Block; + + constructor(blockFunc: (provider: Provider, block: BlockParams) => Block, blockWithTxsFunc: (provider: Provider, block: BlockParams) => Block) { + super("org.quais.network-plugins.custom-block"); + this.#blockFunc = blockFunc; + this.#blockWithTxsFunc = blockWithTxsFunc; + } + + async getBlock(provider: Provider, block: BlockParams): Promise> { + return await this.#blockFunc(provider, block); + } + + async getBlockions(provider: Provider, block: BlockParams): Promise> { + return await this.#blockWithTxsFunc(provider, block); + } + + clone(): CustomBlockNetworkPlugin { + return new CustomBlockNetworkPlugin(this.#blockFunc, this.#blockWithTxsFunc); + } +} +*/ +//# sourceMappingURL=plugins-network.js.map \ No newline at end of file diff --git a/lib.esm/providers/plugins-network.js.map b/lib.esm/providers/plugins-network.js.map new file mode 100644 index 00000000..b8d9c885 --- /dev/null +++ b/lib.esm/providers/plugins-network.js.map @@ -0,0 +1 @@ +{"version":3,"file":"plugins-network.js","sourceRoot":"","sources":["../../src.ts/providers/plugins-network.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAMnD,MAAM,UAAU,GAAG,4CAA4C,CAAC;AAEhE;;GAEG;AACH,MAAM,OAAO,aAAa;IACtB;;;;;OAKG;IACM,IAAI,CAAU;IAEvB;;OAEG;IACH,YAAY,IAAY;QACpB,gBAAgB,CAAgB,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;IACpD,CAAC;IAED;;OAEG;IACH,KAAK;QACD,OAAO,IAAI,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACxC,CAAC;CAKJ;AAsCD;;;GAGG;AACH,MAAM,OAAO,aAAc,SAAQ,aAAa;IAC5C;;;;;OAKG;IACM,cAAc,CAAU;IAEjC;;OAEG;IACM,MAAM,CAAU;IAEzB;;OAEG;IACM,QAAQ,CAAU;IAE3B;;OAEG;IACM,UAAU,CAAU;IAE7B;;OAEG;IACM,aAAa,CAAU;IAEhC;;OAEG;IACM,sBAAsB,CAAU;IAEzC;;OAEG;IACM,mBAAmB,CAAU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AG,CAAC;QAChB,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;IACpC,CAAC;IAED,qDAAqD;IACrD,KAAK,KAAmC,OAAO,IAAI,CAAC,CAAC,CAAC;CACzD;AAED;;;;;;;;;;;;;;;;;;;;;;;EAuBE"} \ No newline at end of file diff --git a/lib.esm/providers/provider-browser.d.ts b/lib.esm/providers/provider-browser.d.ts new file mode 100644 index 00000000..0b693451 --- /dev/null +++ b/lib.esm/providers/provider-browser.d.ts @@ -0,0 +1,56 @@ +import { JsonRpcApiProvider } from "./provider-jsonrpc.js"; +import type { JsonRpcError, JsonRpcPayload, JsonRpcResult, JsonRpcSigner } from "./provider-jsonrpc.js"; +import type { Networkish } from "./network.js"; +/** + * The interface to an [[link-eip-1193]] provider, which is a standard + * used by most injected providers, which the [[BrowserProvider]] accepts + * and exposes the API of. + */ +export interface Eip1193Provider { + /** + * See [[link-eip-1193]] for details on this method. + */ + request(request: { + method: string; + params?: Array | Record; + }): Promise; +} +/** + * The possible additional events dispatched when using the ``"debug"`` + * event on a [[BrowserProvider]]. + */ +export type DebugEventBrowserProvider = { + action: "sendEip1193Payload"; + payload: { + method: string; + params: Array; + }; +} | { + action: "receiveEip1193Result"; + result: any; +} | { + action: "receiveEip1193Error"; + error: Error; +}; +/** + * A **BrowserProvider** is intended to wrap an injected provider which + * adheres to the [[link-eip-1193]] standard, which most (if not all) + * currently do. + */ +export declare class BrowserProvider extends JsonRpcApiProvider { + #private; + /** + * Connnect to the %%ethereum%% provider, optionally forcing the + * %%network%%. + */ + constructor(ethereum: Eip1193Provider, network?: Networkish); + send(method: string, params: Array | Record): Promise; + _send(payload: JsonRpcPayload | Array): Promise>; + getRpcError(payload: JsonRpcPayload, error: JsonRpcError): Error; + /** + * Resolves to ``true`` if the provider manages the %%address%%. + */ + hasSigner(address: number | string): Promise; + getSigner(address?: number | string): Promise; +} +//# sourceMappingURL=provider-browser.d.ts.map \ No newline at end of file diff --git a/lib.esm/providers/provider-browser.d.ts.map b/lib.esm/providers/provider-browser.d.ts.map new file mode 100644 index 00000000..c83c5ec5 --- /dev/null +++ b/lib.esm/providers/provider-browser.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"provider-browser.d.ts","sourceRoot":"","sources":["../../src.ts/providers/provider-browser.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE3D,OAAO,KAAK,EACR,YAAY,EAAE,cAAc,EAAE,aAAa,EAC3C,aAAa,EAChB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC5B;;OAEG;IACH,OAAO,CAAC,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;KAAE,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;CACjG;AAED;;;GAGG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACpC,MAAM,EAAE,oBAAoB,CAAC;IAC7B,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;KAAE,CAAA;CAClD,GAAG;IACA,MAAM,EAAE,sBAAsB,CAAC;IAC/B,MAAM,EAAE,GAAG,CAAA;CACd,GAAG;IACA,MAAM,EAAE,qBAAqB,CAAC;IAC9B,KAAK,EAAE,KAAK,CAAA;CACf,CAAC;AAGF;;;;GAIG;AACH,qBAAa,eAAgB,SAAQ,kBAAkB;;IAGnD;;;OAGG;gBACS,QAAQ,EAAE,eAAe,EAAE,OAAO,CAAC,EAAE,UAAU;IAqBrD,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC;IAM5E,KAAK,CAAC,OAAO,EAAE,cAAc,GAAG,KAAK,CAAC,cAAc,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,aAAa,GAAG,YAAY,CAAC,CAAC;IAc1G,WAAW,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,GAAG,KAAK;IAkBhE;;OAEG;IACG,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAYrD,SAAS,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;CAiBrE"} \ No newline at end of file diff --git a/lib.esm/providers/provider-browser.js b/lib.esm/providers/provider-browser.js new file mode 100644 index 00000000..afbddba3 --- /dev/null +++ b/lib.esm/providers/provider-browser.js @@ -0,0 +1,98 @@ +import { assertArgument } from "../utils/index.js"; +import { JsonRpcApiProvider } from "./provider-jsonrpc.js"; +; +/** + * A **BrowserProvider** is intended to wrap an injected provider which + * adheres to the [[link-eip-1193]] standard, which most (if not all) + * currently do. + */ +export class BrowserProvider extends JsonRpcApiProvider { + #request; + /** + * Connnect to the %%ethereum%% provider, optionally forcing the + * %%network%%. + */ + constructor(ethereum, network) { + super(network, { batchMaxCount: 1 }); + this.#request = async (method, params) => { + const payload = { method, params }; + this.emit("debug", { action: "sendEip1193Request", payload }); + try { + const result = await ethereum.request(payload); + this.emit("debug", { action: "receiveEip1193Result", result }); + return result; + } + catch (e) { + const error = new Error(e.message); + error.code = e.code; + error.data = e.data; + error.payload = payload; + this.emit("debug", { action: "receiveEip1193Error", error }); + throw error; + } + }; + } + async send(method, params) { + await this._start(); + return await super.send(method, params); + } + async _send(payload) { + assertArgument(!Array.isArray(payload), "EIP-1193 does not support batch request", "payload", payload); + try { + const result = await this.#request(payload.method, payload.params || []); + return [{ id: payload.id, result }]; + } + catch (e) { + return [{ + id: payload.id, + error: { code: e.code, data: e.data, message: e.message } + }]; + } + } + getRpcError(payload, error) { + error = JSON.parse(JSON.stringify(error)); + // EIP-1193 gives us some machine-readable error codes, so rewrite + // them into + switch (error.error.code || -1) { + case 4001: + error.error.message = `quais-user-denied: ${error.error.message}`; + break; + case 4200: + error.error.message = `quais-unsupported: ${error.error.message}`; + break; + } + return super.getRpcError(payload, error); + } + /** + * Resolves to ``true`` if the provider manages the %%address%%. + */ + async hasSigner(address) { + if (address == null) { + address = 0; + } + const accounts = await this.send("quai_accounts", []); + if (typeof (address) === "number") { + return (accounts.length > address); + } + address = address.toLowerCase(); + return accounts.filter((a) => (a.toLowerCase() === address)).length !== 0; + } + async getSigner(address) { + if (address == null) { + address = 0; + } + if (!(await this.hasSigner(address))) { + try { + //const resp = + await this.#request("quai_requestAccounts", []); + //console.log("RESP", resp); + } + catch (error) { + const payload = error.payload; + throw this.getRpcError(payload, { id: payload.id, error }); + } + } + return await super.getSigner(address); + } +} +//# sourceMappingURL=provider-browser.js.map \ No newline at end of file diff --git a/lib.esm/providers/provider-browser.js.map b/lib.esm/providers/provider-browser.js.map new file mode 100644 index 00000000..a28c6d51 --- /dev/null +++ b/lib.esm/providers/provider-browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"provider-browser.js","sourceRoot":"","sources":["../../src.ts/providers/provider-browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAkB1D,CAAC;AAkBF;;;;GAIG;AACH,MAAM,OAAO,eAAgB,SAAQ,kBAAkB;IACnD,QAAQ,CAA6E;IAErF;;;OAGG;IACH,YAAY,QAAyB,EAAE,OAAoB;QACvD,KAAK,CAAC,OAAO,EAAE,EAAE,aAAa,EAAE,CAAC,EAAE,CAAC,CAAC;QAErC,IAAI,CAAC,QAAQ,GAAG,KAAK,EAAE,MAAc,EAAE,MAAwC,EAAE,EAAE;YAC/E,MAAM,OAAO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,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;QAChC,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,KAAK,OAAO,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;IACtF,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,OAAyB;QACrC,IAAI,OAAO,IAAI,IAAI,EAAE;YAAE,OAAO,GAAG,CAAC,CAAC;SAAE;QAErC,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,EAAE;YAClC,IAAI;gBACA,eAAe;gBACf,MAAM,IAAI,CAAC,QAAQ,CAAC,sBAAsB,EAAE,EAAG,CAAC,CAAC;gBACjD,4BAA4B;aAE/B;YAAC,OAAO,KAAU,EAAE;gBACjB,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;gBAC9B,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,EAAE,EAAE,EAAE,OAAO,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;aAC9D;SACJ;QAED,OAAO,MAAM,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC;CACJ"} \ No newline at end of file diff --git a/lib.esm/providers/provider-fallback.d.ts b/lib.esm/providers/provider-fallback.d.ts new file mode 100644 index 00000000..eaba0251 --- /dev/null +++ b/lib.esm/providers/provider-fallback.d.ts @@ -0,0 +1,115 @@ +import { AbstractProvider } from "./abstract-provider.js"; +import { Network } from "./network.js"; +import type { PerformActionRequest } from "./abstract-provider.js"; +import type { Networkish } from "./network.js"; +/** + * A configuration entry for how to use a [[Provider]]. + */ +export interface FallbackProviderConfig { + /** + * The provider. + */ + provider: AbstractProvider; + /** + * The amount of time to wait before kicking off the next provider. + * + * Any providers that have not responded can still respond and be + * counted, but this ensures new providers start. + */ + stallTimeout?: number; + /** + * The priority. Lower priority providers are dispatched first. + */ + priority?: number; + /** + * The amount of weight a provider is given against the quorum. + */ + weight?: number; +} +/** + * The statistics and state maintained for a [[Provider]]. + */ +export interface FallbackProviderState extends Required { + /** + * The most recent blockNumber this provider has reported (-2 if none). + */ + blockNumber: number; + /** + * The number of total requests ever sent to this provider. + */ + requests: number; + /** + * The number of responses that errored. + */ + errorResponses: number; + /** + * The number of responses that occured after the result resolved. + */ + lateResponses: number; + /** + * How many times syncing was required to catch up the expected block. + */ + outOfSync: number; + /** + * The number of requests which reported unsupported operation. + */ + unsupportedEvents: number; + /** + * A rolling average (5% current duration) for response time. + */ + rollingDuration: number; + /** + * The ratio of quorum-agreed results to total. + */ + score: number; +} +/** + * Additional options to configure a [[FallbackProvider]]. + */ +export type FallbackProviderOptions = { + quorum?: number; + eventQuorum?: number; + eventWorkers?: number; + cacheTimeout?: number; + pollingInterval?: number; +}; +/** + * A **FallbackProvider** manages several [[Providers]] providing + * resiliance by switching between slow or misbehaving nodes, security + * by requiring multiple backends to aggree and performance by allowing + * faster backends to respond earlier. + * + */ +export declare class FallbackProvider extends AbstractProvider { + #private; + /** + * The number of backends that must agree on a value before it is + * accpeted. + */ + readonly quorum: number; + /** + * @_ignore: + */ + readonly eventQuorum: number; + /** + * @_ignore: + */ + readonly eventWorkers: number; + /** + * Creates a new **FallbackProvider** with %%providers%% connected to + * %%network%%. + * + * If a [[Provider]] is included in %%providers%%, defaults are used + * for the configuration. + */ + constructor(providers: Array, network?: Networkish, options?: FallbackProviderOptions); + get providerConfigs(): Array; + _detectNetwork(): Promise; + /** + * Transforms a %%req%% into the correct method call on %%provider%%. + */ + _translatePerform(provider: AbstractProvider, req: PerformActionRequest): Promise; + _perform(req: PerformActionRequest): Promise; + destroy(): Promise; +} +//# sourceMappingURL=provider-fallback.d.ts.map \ No newline at end of file diff --git a/lib.esm/providers/provider-fallback.d.ts.map b/lib.esm/providers/provider-fallback.d.ts.map new file mode 100644 index 00000000..28a8b459 --- /dev/null +++ b/lib.esm/providers/provider-fallback.d.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AAC;AAwKF;;;;;;GAMG;AACH,qBAAa,gBAAiB,SAAQ,gBAAgB;;IAElD;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB;;OAEG;IACH,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAE7B;;OAEG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAO9B;;;;;;OAMG;gBACS,SAAS,EAAE,KAAK,CAAC,gBAAgB,GAAG,sBAAsB,CAAC,EAAE,OAAO,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,uBAAuB;IA8BhI,IAAI,eAAe,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAQlD;IAEK,cAAc,IAAI,OAAO,CAAC,OAAO,CAAC;IASxC;;OAEG;IACG,iBAAiB,CAAC,QAAQ,EAAE,gBAAgB,EAAE,GAAG,EAAE,oBAAoB,GAAG,OAAO,CAAC,GAAG,CAAC;IA+QtF,QAAQ,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,oBAAoB,GAAG,OAAO,CAAC,CAAC,CAAC;IA8ExD,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAMjC"} \ No newline at end of file diff --git a/lib.esm/providers/provider-fallback.js b/lib.esm/providers/provider-fallback.js new file mode 100644 index 00000000..beb5ea92 --- /dev/null +++ b/lib.esm/providers/provider-fallback.js @@ -0,0 +1,613 @@ +/** + * A **FallbackProvider** providers resiliance, security and performatnce + * in a way that is customizable and configurable. + * + * @_section: api/providers/fallback-provider:Fallback Provider [about-fallback-provider] + */ +import { assert, assertArgument, getBigInt, getNumber, isError } from "../utils/index.js"; +import { AbstractProvider } from "./abstract-provider.js"; +import { Network } from "./network.js"; +const BN_1 = BigInt("1"); +const BN_2 = BigInt("2"); +function shuffle(array) { + for (let i = array.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + const tmp = array[i]; + array[i] = array[j]; + array[j] = tmp; + } +} +function stall(duration) { + return new Promise((resolve) => { setTimeout(resolve, duration); }); +} +function getTime() { return (new Date()).getTime(); } +function stringify(value) { + return JSON.stringify(value, (key, value) => { + if (typeof (value) === "bigint") { + return { type: "bigint", value: value.toString() }; + } + return value; + }); +} +; +const defaultConfig = { stallTimeout: 400, priority: 1, weight: 1 }; +const defaultState = { + blockNumber: -2, requests: 0, lateResponses: 0, errorResponses: 0, + outOfSync: -1, unsupportedEvents: 0, rollingDuration: 0, score: 0, + _network: null, _updateNumber: null, _totalTime: 0, + _lastFatalError: null, _lastFatalErrorTimestamp: 0 +}; +async function waitForSync(config, blockNumber) { + while (config.blockNumber < 0 || config.blockNumber < blockNumber) { + if (!config._updateNumber) { + config._updateNumber = (async () => { + try { + const blockNumber = await config.provider.getBlockNumber(); + if (blockNumber > config.blockNumber) { + config.blockNumber = blockNumber; + } + } + catch (error) { + config.blockNumber = -2; + config._lastFatalError = error; + config._lastFatalErrorTimestamp = getTime(); + } + config._updateNumber = null; + })(); + } + await config._updateNumber; + config.outOfSync++; + if (config._lastFatalError) { + break; + } + } +} +function _normalize(value) { + if (value == null) { + return "null"; + } + if (Array.isArray(value)) { + return "[" + (value.map(_normalize)).join(",") + "]"; + } + if (typeof (value) === "object" && typeof (value.toJSON) === "function") { + return _normalize(value.toJSON()); + } + switch (typeof (value)) { + case "boolean": + case "symbol": + return value.toString(); + case "bigint": + case "number": + return BigInt(value).toString(); + case "string": + return JSON.stringify(value); + case "object": { + const keys = Object.keys(value); + keys.sort(); + return "{" + keys.map((k) => `${JSON.stringify(k)}:${_normalize(value[k])}`).join(",") + "}"; + } + } + console.log("Could not serialize", value); + throw new Error("Hmm..."); +} +function normalizeResult(value) { + if ("error" in value) { + const error = value.error; + return { tag: _normalize(error), value: error }; + } + const result = value.result; + return { tag: _normalize(result), value: result }; +} +// This strategy picks the highest weight result, as long as the weight is +// equal to or greater than quorum +function checkQuorum(quorum, results) { + const tally = new Map(); + for (const { value, tag, weight } of results) { + const t = tally.get(tag) || { value, weight: 0 }; + t.weight += weight; + tally.set(tag, t); + } + let best = null; + for (const r of tally.values()) { + if (r.weight >= quorum && (!best || r.weight > best.weight)) { + best = r; + } + } + if (best) { + return best.value; + } + return undefined; +} +function getMedian(quorum, results) { + let resultWeight = 0; + const errorMap = new Map(); + let bestError = null; + const values = []; + for (const { value, tag, weight } of results) { + if (value instanceof Error) { + const e = errorMap.get(tag) || { value, weight: 0 }; + e.weight += weight; + errorMap.set(tag, e); + if (bestError == null || e.weight > bestError.weight) { + bestError = e; + } + } + else { + values.push(BigInt(value)); + resultWeight += weight; + } + } + if (resultWeight < quorum) { + // We have quorum for an error + if (bestError && bestError.weight >= quorum) { + return bestError.value; + } + // We do not have quorum for a result + return undefined; + } + // Get the sorted values + values.sort((a, b) => ((a < b) ? -1 : (b > a) ? 1 : 0)); + const mid = Math.floor(values.length / 2); + // Odd-length; take the middle value + if (values.length % 2) { + return values[mid]; + } + // Even length; take the ceiling of the mean of the center two values + return (values[mid - 1] + values[mid] + BN_1) / BN_2; +} +function getAnyResult(quorum, results) { + // If any value or error meets quorum, that is our preferred result + const result = checkQuorum(quorum, results); + if (result !== undefined) { + return result; + } + // Otherwise, do we have any result? + for (const r of results) { + if (r.value) { + return r.value; + } + } + // Nope! + return undefined; +} +function getFuzzyMode(quorum, results) { + if (quorum === 1) { + return getNumber(getMedian(quorum, results), "%internal"); + } + const tally = new Map(); + const add = (result, weight) => { + const t = tally.get(result) || { result, weight: 0 }; + t.weight += weight; + tally.set(result, t); + }; + for (const { weight, value } of results) { + const r = getNumber(value); + add(r - 1, weight); + add(r, weight); + add(r + 1, weight); + } + let bestWeight = 0; + let bestResult = undefined; + for (const { weight, result } of tally.values()) { + // Use this result, if this result meets quorum and has either: + // - a better weight + // - or equal weight, but the result is larger + if (weight >= quorum && (weight > bestWeight || (bestResult != null && weight === bestWeight && result > bestResult))) { + bestWeight = weight; + bestResult = result; + } + } + return bestResult; +} +/** + * A **FallbackProvider** manages several [[Providers]] providing + * resiliance by switching between slow or misbehaving nodes, security + * by requiring multiple backends to aggree and performance by allowing + * faster backends to respond earlier. + * + */ +export class FallbackProvider extends AbstractProvider { + /** + * The number of backends that must agree on a value before it is + * accpeted. + */ + quorum; + /** + * @_ignore: + */ + eventQuorum; + /** + * @_ignore: + */ + eventWorkers; + #configs; + #height; + #initialSyncPromise; + /** + * Creates a new **FallbackProvider** with %%providers%% connected to + * %%network%%. + * + * If a [[Provider]] is included in %%providers%%, defaults are used + * for the configuration. + */ + constructor(providers, network, options) { + super(network, options); + this.#configs = providers.map((p) => { + if (p instanceof AbstractProvider) { + return Object.assign({ provider: p }, defaultConfig, defaultState); + } + else { + return Object.assign({}, defaultConfig, p, defaultState); + } + }); + this.#height = -2; + this.#initialSyncPromise = null; + if (options && options.quorum != null) { + this.quorum = options.quorum; + } + else { + this.quorum = Math.ceil(this.#configs.reduce((accum, config) => { + accum += config.weight; + return accum; + }, 0) / 2); + } + this.eventQuorum = 1; + this.eventWorkers = 1; + assertArgument(this.quorum <= this.#configs.reduce((a, c) => (a + c.weight), 0), "quorum exceed provider wieght", "quorum", this.quorum); + } + get providerConfigs() { + return this.#configs.map((c) => { + const result = Object.assign({}, c); + for (const key in result) { + if (key[0] === "_") { + delete result[key]; + } + } + return result; + }); + } + async _detectNetwork() { + return Network.from(getBigInt(await this._perform({ method: "chainId" }))); + } + // @TODO: Add support to select providers to be the event subscriber + //_getSubscriber(sub: Subscription): Subscriber { + // throw new Error("@TODO"); + //} + /** + * Transforms a %%req%% into the correct method call on %%provider%%. + */ + async _translatePerform(provider, req) { + switch (req.method) { + case "broadcastTransaction": + return await provider.broadcastTransaction(req.shard, req.signedTransaction); + case "call": + return await provider.call(Object.assign({}, req.transaction, { blockTag: req.blockTag })); + case "chainId": + return (await provider.getNetwork()).chainId; + case "estimateGas": + return await provider.estimateGas(req.transaction); + case "getBalance": + return await provider.getBalance(req.address, req.blockTag); + case "getBlock": { + const block = ("blockHash" in req) ? req.blockHash : req.blockTag; + return await provider.getBlock(req.shard, block, req.includeTransactions); + } + case "getBlockNumber": + return await provider.getBlockNumber(); + case "getCode": + return await provider.getCode(req.address, req.blockTag); + case "getGasPrice": + return (await provider.getFeeData()).gasPrice; + case "getMaxPriorityFeePerGas": + return (await provider.getFeeData()).maxPriorityFeePerGas; + case "getLogs": + return await provider.getLogs(req.filter); + case "getStorage": + return await provider.getStorage(req.address, req.position, req.blockTag); + case "getTransaction": + return await provider.getTransaction(req.hash); + case "getTransactionCount": + return await provider.getTransactionCount(req.address, req.blockTag); + case "getTransactionReceipt": + return await provider.getTransactionReceipt(req.hash); + case "getTransactionResult": + return await provider.getTransactionResult(req.hash); + case "getProtocolExpansionNumber": + return await provider.getProtocolExpansionNumber(); + } + } + // Grab the next (random) config that is not already part of + // the running set + #getNextConfig(running) { + // @TODO: Maybe do a check here to favour (heavily) providers that + // do not require waitForSync and disfavour providers that + // seem down-ish or are behaving slowly + const configs = Array.from(running).map((r) => r.config); + // Shuffle the states, sorted by priority + const allConfigs = this.#configs.slice(); + shuffle(allConfigs); + allConfigs.sort((a, b) => (a.priority - b.priority)); + for (const config of allConfigs) { + if (config._lastFatalError) { + continue; + } + if (configs.indexOf(config) === -1) { + return config; + } + } + return null; + } + // Adds a new runner (if available) to running. + #addRunner(running, req) { + const config = this.#getNextConfig(running); + // No runners available + if (config == null) { + return null; + } + // Create a new runner + const runner = { + config, result: null, didBump: false, + perform: null, staller: null + }; + const now = getTime(); + // Start performing this operation + runner.perform = (async () => { + try { + config.requests++; + const result = await this._translatePerform(config.provider, req); + runner.result = { result }; + } + catch (error) { + config.errorResponses++; + runner.result = { error }; + } + const dt = (getTime() - now); + config._totalTime += dt; + config.rollingDuration = 0.95 * config.rollingDuration + 0.05 * dt; + runner.perform = null; + })(); + // Start a staller; when this times out, it's time to force + // kicking off another runner because we are taking too long + runner.staller = (async () => { + await stall(config.stallTimeout); + runner.staller = null; + })(); + running.add(runner); + return runner; + } + // Initializes the blockNumber and network for each runner and + // blocks until initialized + async #initialSync() { + let initialSync = this.#initialSyncPromise; + if (!initialSync) { + const promises = []; + this.#configs.forEach((config) => { + promises.push((async () => { + await waitForSync(config, 0); + if (!config._lastFatalError) { + config._network = await config.provider.getNetwork(); + } + })()); + }); + this.#initialSyncPromise = initialSync = (async () => { + // Wait for all providers to have a block number and network + await Promise.all(promises); + // Check all the networks match + let chainId = null; + for (const config of this.#configs) { + if (config._lastFatalError) { + continue; + } + const network = (config._network); + if (chainId == null) { + chainId = network.chainId; + } + else if (network.chainId !== chainId) { + assert(false, "cannot mix providers on different networks", "UNSUPPORTED_OPERATION", { + operation: "new FallbackProvider" + }); + } + } + })(); + } + await initialSync; + } + async #checkQuorum(running, req) { + // Get all the result objects + const results = []; + for (const runner of running) { + if (runner.result != null) { + const { tag, value } = normalizeResult(runner.result); + results.push({ tag, value, weight: runner.config.weight }); + } + } + // Are there enough results to event meet quorum? + if (results.reduce((a, r) => (a + r.weight), 0) < this.quorum) { + return undefined; + } + switch (req.method) { + case "getBlockNumber": { + // We need to get the bootstrap block height + if (this.#height === -2) { + this.#height = Math.ceil(getNumber(getMedian(this.quorum, this.#configs.filter((c) => (!c._lastFatalError)).map((c) => ({ + value: c.blockNumber, + tag: getNumber(c.blockNumber).toString(), + weight: c.weight + }))))); + } + // Find the mode across all the providers, allowing for + // a little drift between block heights + const mode = getFuzzyMode(this.quorum, results); + if (mode === undefined) { + return undefined; + } + if (mode > this.#height) { + this.#height = mode; + } + return this.#height; + } + case "getGasPrice": + case "getMaxPriorityFeePerGas": + case "estimateGas": + return getMedian(this.quorum, results); + case "getBlock": + // Pending blocks are in the mempool and already + // quite untrustworthy; just grab anything + if ("blockTag" in req && req.blockTag === "pending") { + return getAnyResult(this.quorum, results); + } + return checkQuorum(this.quorum, results); + case "call": + case "chainId": + case "getBalance": + case "getTransactionCount": + case "getCode": + case "getStorage": + case "getTransaction": + case "getTransactionReceipt": + case "getLogs": + return checkQuorum(this.quorum, results); + case "broadcastTransaction": + return getAnyResult(this.quorum, results); + } + assert(false, "unsupported method", "UNSUPPORTED_OPERATION", { + operation: `_perform(${stringify(req.method)})` + }); + } + async #waitForQuorum(running, req) { + if (running.size === 0) { + throw new Error("no runners?!"); + } + // Any promises that are interesting to watch for; an expired stall + // or a successful perform + const interesting = []; + let newRunners = 0; + for (const runner of running) { + // No responses, yet; keep an eye on it + if (runner.perform) { + interesting.push(runner.perform); + } + // Still stalling... + if (runner.staller) { + interesting.push(runner.staller); + continue; + } + // This runner has already triggered another runner + if (runner.didBump) { + continue; + } + // Got a response (result or error) or stalled; kick off another runner + runner.didBump = true; + newRunners++; + } + // Check if we have reached quorum on a result (or error) + const value = await this.#checkQuorum(running, req); + if (value !== undefined) { + if (value instanceof Error) { + throw value; + } + return value; + } + // Add any new runners, because a staller timed out or a result + // or error response came in. + for (let i = 0; i < newRunners; i++) { + this.#addRunner(running, req); + } + // All providers have returned, and we have no result + assert(interesting.length > 0, "quorum not met", "SERVER_ERROR", { + request: "%sub-requests", + info: { request: req, results: Array.from(running).map((r) => stringify(r.result)) } + }); + // Wait for someone to either complete its perform or stall out + await Promise.race(interesting); + // This is recursive, but at worst case the depth is 2x the + // number of providers (each has a perform and a staller) + return await this.#waitForQuorum(running, req); + } + async _perform(req) { + // Broadcasting a transaction is rare (ish) and already incurs + // a cost on the user, so spamming is safe-ish. Just send it to + // every backend. + if (req.method === "broadcastTransaction") { + // Once any broadcast provides a positive result, use it. No + // need to wait for anyone else + const results = this.#configs.map((c) => null); + const broadcasts = this.#configs.map(async ({ provider, weight }, index) => { + try { + const result = await provider._perform(req); + results[index] = Object.assign(normalizeResult({ result }), { weight }); + } + catch (error) { + results[index] = Object.assign(normalizeResult({ error }), { weight }); + } + }); + // As each promise finishes... + while (true) { + // Check for a valid broadcast result + const done = results.filter((r) => (r != null)); + for (const { value } of done) { + if (!(value instanceof Error)) { + return value; + } + } + // Check for a legit broadcast error (one which we cannot + // recover from; some nodes may return the following red + // herring events: + // - alredy seend (UNKNOWN_ERROR) + // - NONCE_EXPIRED + // - REPLACEMENT_UNDERPRICED + const result = checkQuorum(this.quorum, results.filter((r) => (r != null))); + if (isError(result, "INSUFFICIENT_FUNDS")) { + throw result; + } + // Kick off the next provider (if any) + const waiting = broadcasts.filter((b, i) => (results[i] == null)); + if (waiting.length === 0) { + break; + } + await Promise.race(waiting); + } + // Use standard quorum results; any result was returned above, + // so this will find any error that met quorum if any + const result = getAnyResult(this.quorum, results); + assert(result !== undefined, "problem multi-broadcasting", "SERVER_ERROR", { + request: "%sub-requests", + info: { request: req, results: results.map(stringify) } + }); + if (result instanceof Error) { + throw result; + } + return result; + } + await this.#initialSync(); + // Bootstrap enough runners to meet quorum + const running = new Set(); + let inflightQuorum = 0; + while (true) { + const runner = this.#addRunner(running, req); + if (runner == null) { + break; + } + inflightQuorum += runner.config.weight; + if (inflightQuorum >= this.quorum) { + break; + } + } + const result = await this.#waitForQuorum(running, req); + // Track requests sent to a provider that are still + // outstanding after quorum has been otherwise found + for (const runner of running) { + if (runner.perform && runner.result == null) { + runner.config.lateResponses++; + } + } + return result; + } + async destroy() { + for (const { provider } of this.#configs) { + provider.destroy(); + } + super.destroy(); + } +} +//# sourceMappingURL=provider-fallback.js.map \ No newline at end of file diff --git a/lib.esm/providers/provider-fallback.js.map b/lib.esm/providers/provider-fallback.js.map new file mode 100644 index 00000000..4ac2cff7 --- /dev/null +++ b/lib.esm/providers/provider-fallback.js.map @@ -0,0 +1 @@ +{"version":3,"file":"provider-fallback.js","sourceRoot":"","sources":["../../src.ts/providers/provider-fallback.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EACH,MAAM,EAAE,cAAc,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EACxD,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAKtC,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;AACzB,MAAM,IAAI,G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ACvB,OAAO,IAAI,EAAE;YACT,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;YAC7C,IAAI,MAAM,IAAI,IAAI,EAAE;gBAAE,MAAM;aAAE;YAC9B,cAAc,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;YACvC,IAAI,cAAc,IAAI,IAAI,CAAC,MAAM,EAAE;gBAAE,MAAM;aAAE;SAChD;QAED,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QAEvD,mDAAmD;QACnD,oDAAoD;QACpD,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;YAC1B,IAAI,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,MAAM,IAAI,IAAI,EAAE;gBACzC,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC;aACjC;SACJ;QAED,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,KAAK,CAAC,OAAO;QACT,KAAK,MAAM,EAAE,QAAQ,EAAE,IAAI,IAAI,CAAC,QAAQ,EAAE;YACtC,QAAQ,CAAC,OAAO,EAAE,CAAC;SACtB;QACD,KAAK,CAAC,OAAO,EAAE,CAAC;IACpB,CAAC;CACJ"} \ No newline at end of file diff --git a/lib.esm/providers/provider-ipcsocket-browser.d.ts b/lib.esm/providers/provider-ipcsocket-browser.d.ts new file mode 100644 index 00000000..6aae787d --- /dev/null +++ b/lib.esm/providers/provider-ipcsocket-browser.d.ts @@ -0,0 +1,3 @@ +declare const IpcSocketProvider: undefined; +export { IpcSocketProvider }; +//# sourceMappingURL=provider-ipcsocket-browser.d.ts.map \ No newline at end of file diff --git a/lib.esm/providers/provider-ipcsocket-browser.d.ts.map b/lib.esm/providers/provider-ipcsocket-browser.d.ts.map new file mode 100644 index 00000000..e49cd58d --- /dev/null +++ b/lib.esm/providers/provider-ipcsocket-browser.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"provider-ipcsocket-browser.d.ts","sourceRoot":"","sources":["../../src.ts/providers/provider-ipcsocket-browser.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,iBAAiB,WAAY,CAAC;AAEpC,OAAO,EAAE,iBAAiB,EAAE,CAAC"} \ No newline at end of file diff --git a/lib.esm/providers/provider-ipcsocket-browser.js b/lib.esm/providers/provider-ipcsocket-browser.js new file mode 100644 index 00000000..d94074ea --- /dev/null +++ b/lib.esm/providers/provider-ipcsocket-browser.js @@ -0,0 +1,3 @@ +const IpcSocketProvider = undefined; +export { IpcSocketProvider }; +//# sourceMappingURL=provider-ipcsocket-browser.js.map \ No newline at end of file diff --git a/lib.esm/providers/provider-ipcsocket-browser.js.map b/lib.esm/providers/provider-ipcsocket-browser.js.map new file mode 100644 index 00000000..1df6d95a --- /dev/null +++ b/lib.esm/providers/provider-ipcsocket-browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"provider-ipcsocket-browser.js","sourceRoot":"","sources":["../../src.ts/providers/provider-ipcsocket-browser.ts"],"names":[],"mappings":"AAAA,MAAM,iBAAiB,GAAG,SAAS,CAAC;AAEpC,OAAO,EAAE,iBAAiB,EAAE,CAAC"} \ No newline at end of file diff --git a/lib.esm/providers/provider-ipcsocket.d.ts b/lib.esm/providers/provider-ipcsocket.d.ts new file mode 100644 index 00000000..23d1f2f6 --- /dev/null +++ b/lib.esm/providers/provider-ipcsocket.d.ts @@ -0,0 +1,21 @@ +/// +import { SocketProvider } from "./provider-socket.js"; +import type { Socket } from "net"; +import type { JsonRpcApiProviderOptions } from "./provider-jsonrpc.js"; +import type { Networkish } from "./network.js"; +/** + * An **IpcSocketProvider** connects over an IPC socket on the host + * which provides fast access to the node, but requires the node and + * the script run on the same machine. + */ +export declare class IpcSocketProvider extends SocketProvider { + #private; + /** + * The connected socket. + */ + get socket(): Socket; + constructor(path: string, network?: Networkish, options?: JsonRpcApiProviderOptions); + destroy(): void; + _write(message: string): Promise; +} +//# sourceMappingURL=provider-ipcsocket.d.ts.map \ No newline at end of file diff --git a/lib.esm/providers/provider-ipcsocket.d.ts.map b/lib.esm/providers/provider-ipcsocket.d.ts.map new file mode 100644 index 00000000..60e29ef4 --- /dev/null +++ b/lib.esm/providers/provider-ipcsocket.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"provider-ipcsocket.d.ts","sourceRoot":"","sources":["../../src.ts/providers/provider-ipcsocket.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AAElC,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAmB/C;;;;GAIG;AACH,qBAAa,iBAAkB,SAAQ,cAAc;;IAGjD;;OAEG;IACH,IAAI,MAAM,IAAI,MAAM,CAAyB;gBAEjC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,yBAAyB;IA8BnF,OAAO,IAAI,IAAI;IAOT,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAG/C"} \ No newline at end of file diff --git a/lib.esm/providers/provider-ipcsocket.js b/lib.esm/providers/provider-ipcsocket.js new file mode 100644 index 00000000..d132ba00 --- /dev/null +++ b/lib.esm/providers/provider-ipcsocket.js @@ -0,0 +1,65 @@ +import { connect } from "net"; +import { SocketProvider } from "./provider-socket.js"; +// @TODO: Is this sufficient? Is this robust? Will newlines occur between +// all payloads and only between payloads? +function splitBuffer(data) { + const messages = []; + let lastStart = 0; + while (true) { + const nl = data.indexOf(10, lastStart); + if (nl === -1) { + break; + } + messages.push(data.subarray(lastStart, nl).toString().trim()); + lastStart = nl + 1; + } + return { messages, remaining: data.subarray(lastStart) }; +} +/** + * An **IpcSocketProvider** connects over an IPC socket on the host + * which provides fast access to the node, but requires the node and + * the script run on the same machine. + */ +export class IpcSocketProvider extends SocketProvider { + #socket; + /** + * The connected socket. + */ + get socket() { return this.#socket; } + constructor(path, network, options) { + super(network, options); + this.#socket = connect(path); + this.socket.on("ready", async () => { + try { + await this._start(); + } + catch (error) { + console.log("failed to start IpcSocketProvider", error); + // @TODO: Now what? Restart? + } + }); + let response = Buffer.alloc(0); + this.socket.on("data", (data) => { + response = Buffer.concat([response, data]); + const { messages, remaining } = splitBuffer(response); + messages.forEach((message) => { + this._processMessage(message); + }); + response = remaining; + }); + this.socket.on("end", () => { + this.emit("close"); + this.socket.destroy(); + this.socket.end(); + }); + } + destroy() { + this.socket.destroy(); + this.socket.end(); + super.destroy(); + } + async _write(message) { + this.socket.write(message); + } +} +//# sourceMappingURL=provider-ipcsocket.js.map \ No newline at end of file diff --git a/lib.esm/providers/provider-ipcsocket.js.map b/lib.esm/providers/provider-ipcsocket.js.map new file mode 100644 index 00000000..4a061d68 --- /dev/null +++ b/lib.esm/providers/provider-ipcsocket.js.map @@ -0,0 +1 @@ +{"version":3,"file":"provider-ipcsocket.js","sourceRoot":"","sources":["../../src.ts/providers/provider-ipcsocket.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAQtD,yEAAyE;AACzE,0CAA0C;AAC1C,SAAS,WAAW,CAAC,IAAY;IAC7B,MAAM,QAAQ,GAAkB,EAAG,CAAC;IAEpC,IAAI,SAAS,GAAG,CAAC,CAAC;IAClB,OAAO,IAAI,EAAE;QACT,MAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC;QACvC,IAAI,EAAE,KAAK,CAAC,CAAC,EAAE;YAAE,MAAM;SAAE;QACzB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,QAAQ,EAAE,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;QACzB,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;YACvB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACnB,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACtB,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;QACtB,CAAC,CAAC,CAAC;IACP,CAAC;IAED,OAAO;QACH,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACtB,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;QAElB,KAAK,CAAC,OAAO,EAAE,CAAC;IACpB,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,OAAe;QACxB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC/B,CAAC;CACJ"} \ No newline at end of file diff --git a/lib.esm/providers/provider-jsonrpc.d.ts b/lib.esm/providers/provider-jsonrpc.d.ts new file mode 100644 index 00000000..4db114aa --- /dev/null +++ b/lib.esm/providers/provider-jsonrpc.d.ts @@ -0,0 +1,336 @@ +/** + * One of the most common ways to interact with the blockchain is + * by a node running a JSON-RPC interface which can be connected to, + * based on the transport, using: + * + * - HTTP or HTTPS - [[JsonRpcProvider]] + * - WebSocket - [[WebSocketProvider]] + * - IPC - [[IpcSocketProvider]] + * + * @_section: api/providers/jsonrpc:JSON-RPC Provider [about-jsonrpcProvider] + */ +import { FetchRequest } from "../utils/index.js"; +import { AbstractProvider } from "./abstract-provider.js"; +import { AbstractSigner } from "./abstract-signer.js"; +import { Network } from "./network.js"; +import type { TypedDataDomain, TypedDataField } from "../hash/index.js"; +import type { TransactionLike } from "../transaction/index.js"; +import type { PerformActionRequest, Subscriber, Subscription } from "./abstract-provider.js"; +import type { Networkish } from "./network.js"; +import type { Provider, TransactionRequest, TransactionResponse } from "./provider.js"; +import type { Signer } from "./signer.js"; +/** + * A JSON-RPC payload, which are sent to a JSON-RPC server. + */ +export type JsonRpcPayload = { + /** + * The JSON-RPC request ID. + */ + id: number; + /** + * The JSON-RPC request method. + */ + method: string; + /** + * The JSON-RPC request parameters. + */ + params: Array | Record; + /** + * A required constant in the JSON-RPC specification. + */ + jsonrpc: "2.0"; +}; +/** + * A JSON-RPC result, which are returned on success from a JSON-RPC server. + */ +export type JsonRpcResult = { + /** + * The response ID to match it to the relevant request. + */ + id: number; + /** + * The response result. + */ + result: any; +}; +/** + * A JSON-RPC error, which are returned on failure from a JSON-RPC server. + */ +export type JsonRpcError = { + /** + * The response ID to match it to the relevant request. + */ + id: number; + /** + * The response error. + */ + error: { + code: number; + message?: string; + data?: any; + }; +}; +/** + * When subscribing to the ``"debug"`` event, the [[Listener]] will + * receive this object as the first parameter. + */ +export type DebugEventJsonRpcApiProvider = { + action: "sendRpcPayload"; + payload: JsonRpcPayload | Array; +} | { + action: "receiveRpcResult"; + result: Array; +} | { + action: "receiveRpcError"; + error: Error; +}; +/** + * Options for configuring a [[JsonRpcApiProvider]]. Much of this + * is targetted towards sub-classes, which often will not expose + * any of these options to their consumers. + * + * **``polling``** - use the polling strategy is used immediately + * for events; otherwise, attempt to use filters and fall back onto + * polling (default: ``false``) + * + * **``staticNetwork``** - do not request chain ID on requests to + * validate the underlying chain has not changed (default: ``null``) + * + * This should **ONLY** be used if it is **certain** that the network + * cannot change, such as when using INFURA (since the URL dictates the + * network). If the network is assumed static and it does change, this + * can have tragic consequences. For example, this **CANNOT** be used + * with MetaMask, since the used can select a new network from the + * drop-down at any time. + * + * **``batchStallTime``** - how long (ms) to aggregate requests into a + * single batch. ``0`` indicates batching will only encompass the current + * event loop. If ``batchMaxCount = 1``, this is ignored. (default: ``10``) + * + * **``batchMaxSize``** - target maximum size (bytes) to allow per batch + * request (default: 1Mb) + * + * **``batchMaxCount``** - maximum number of requests to allow in a batch. + * If ``batchMaxCount = 1``, then batching is disabled. (default: ``100``) + * + * **``cacheTimeout``** - passed as [[AbstractProviderOptions]]. + */ +export type JsonRpcApiProviderOptions = { + staticNetwork?: null | Network | boolean; + batchStallTime?: number; + batchMaxSize?: number; + batchMaxCount?: number; + cacheTimeout?: number; +}; +/** + * A **JsonRpcTransactionRequest** is formatted as needed by the JSON-RPC + * Ethereum API specification. + */ +export interface JsonRpcTransactionRequest { + /** + * The sender address to use when signing. + */ + from?: string; + /** + * The target address. + */ + to?: string; + /** + * The transaction data. + */ + data?: string; + /** + * The chain ID the transaction is valid on. + */ + chainId?: string; + /** + * The [[link-eip-2718]] transaction type. + */ + type?: string; + /** + * The maximum amount of gas to allow a transaction to consume. + * + * In most other places in quais, this is called ``gasLimit`` which + * differs from the JSON-RPC Ethereum API specification. + */ + gas?: string; + /** + * The gas price per wei for transactions prior to [[link-eip-1559]]. + */ + gasPrice?: string; + /** + * The maximum fee per gas for [[link-eip-1559]] transactions. + */ + maxFeePerGas?: string; + /** + * The maximum priority fee per gas for [[link-eip-1559]] transactions. + */ + maxPriorityFeePerGas?: string; + /** + * The nonce for the transaction. + */ + nonce?: string; + /** + * The transaction value (in wei). + */ + value?: string; + /** + * The transaction access list. + */ + accessList?: Array<{ + address: string; + storageKeys: Array; + }>; +} +export declare class JsonRpcSigner extends AbstractSigner { + address: string; + constructor(provider: JsonRpcApiProvider, address: string); + connect(provider: null | Provider): Signer; + getAddress(): Promise; + populateTransaction(tx: TransactionRequest): Promise>; + sendUncheckedTransaction(_tx: TransactionRequest): Promise; + sendTransaction(tx: TransactionRequest): Promise; + signTransaction(_tx: TransactionRequest): Promise; + signMessage(_message: string | Uint8Array): Promise; + signTypedData(domain: TypedDataDomain, types: Record>, _value: Record): Promise; + unlock(password: string): Promise; + _legacySignMessage(_message: string | Uint8Array): Promise; +} +/** + * The JsonRpcApiProvider is an abstract class and **MUST** be + * sub-classed. + * + * It provides the base for all JSON-RPC-based Provider interaction. + * + * Sub-classing Notes: + * - a sub-class MUST override _send + * - a sub-class MUST call the `_start()` method once connected + */ +export declare abstract class JsonRpcApiProvider extends AbstractProvider { + #private; + initPromise?: Promise; + constructor(network?: Networkish, options?: JsonRpcApiProviderOptions); + /** + * Returns the value associated with the option %%key%%. + * + * Sub-classes can use this to inquire about configuration options. + */ + _getOption(key: K): JsonRpcApiProviderOptions[K]; + /** + * Gets the [[Network]] this provider has committed to. On each call, the network + * is detected, and if it has changed, the call will reject. + */ + get _network(): Network; + /** + * Sends a JSON-RPC %%payload%% (or a batch) to the underlying channel. + * + * Sub-classes **MUST** override this. + */ + abstract _send(payload: JsonRpcPayload | Array, shard?: string): Promise>; + /** + * Resolves to the non-normalized value by performing %%req%%. + * + * Sub-classes may override this to modify behavior of actions, + * and should generally call ``super._perform`` as a fallback. + */ + _perform(req: PerformActionRequest): Promise; + /** + * Sub-classes may override this; it detects the *actual* network that + * we are **currently** connected to. + * + * Keep in mind that [[send]] may only be used once [[ready]], otherwise the + * _send primitive must be used instead. + */ + _detectNetwork(): Promise; + /** + * Sub-classes **MUST** call this. Until [[_start]] has been called, no calls + * will be passed to [[_send]] from [[send]]. If it is overridden, then + * ``super._start()`` **MUST** be called. + * + * Calling it multiple times is safe and has no effect. + */ + _start(): void; + /** + * Resolves once the [[_start]] has been called. This can be used in + * sub-classes to defer sending data until the connection has been + * established. + */ + _waitUntilReady(): Promise; + /** + * Return a Subscriber that will manage the %%sub%%. + * + * Sub-classes may override this to modify the behavior of + * subscription management. + */ + _getSubscriber(sub: Subscription): Subscriber; + /** + * Returns true only if the [[_start]] has been called. + */ + get ready(): boolean; + /** + * Returns %%tx%% as a normalized JSON-RPC transaction request, + * which has all values hexlified and any numeric values converted + * to Quantity values. + */ + getRpcTransaction(tx: TransactionRequest): JsonRpcTransactionRequest; + /** + * Returns the request method and arguments required to perform + * %%req%%. + */ + getRpcRequest(req: PerformActionRequest): null | { + method: string; + args: Array; + }; + /** + * Returns an quais-style Error for the given JSON-RPC error + * %%payload%%, coalescing the various strings and error shapes + * that different nodes return, coercing them into a machine-readable + * standardized error. + */ + getRpcError(payload: JsonRpcPayload, _error: JsonRpcError): Error; + /** + * Requests the %%method%% with %%params%% via the JSON-RPC protocol + * over the underlying channel. This can be used to call methods + * on the backend that do not have a high-level API within the Provider + * API. + * + * This method queues requests according to the batch constraints + * in the options, assigns the request a unique ID. + * + * **Do NOT override** this method in sub-classes; instead + * override [[_send]] or force the options values in the + * call to the constructor to modify this method's behavior. + */ + send(method: string, params: Array | Record, shard?: string): Promise; + /** + * Resolves to the [[Signer]] account for %%address%% managed by + * the client. + * + * If the %%address%% is a number, it is used as an index in the + * the accounts from [[listAccounts]]. + * + * This can only be used on clients which manage accounts (such as + * Geth with imported account or MetaMask). + * + * Throws if the account doesn't exist. + */ + getSigner(address?: number | string): Promise; + listAccounts(): Promise>; + destroy(): void; +} +/** + * The JsonRpcProvider is one of the most common Providers, + * which performs all operations over HTTP (or HTTPS) requests. + * + * Events are processed by polling the backend for the current block + * number; when it advances, all block-base events are then checked + * for updates. + */ +export declare class JsonRpcProvider extends JsonRpcApiProvider { + constructor(urls?: string | string[] | FetchRequest, network?: Networkish, options?: JsonRpcApiProviderOptions); + _getSubscriber(sub: Subscription): Subscriber; + _getConnection(shard?: string): FetchRequest; + send(method: string, params: Array | Record, shard?: string): Promise; + _send(payload: JsonRpcPayload | Array, shard?: string): Promise>; +} +//# sourceMappingURL=provider-jsonrpc.d.ts.map \ No newline at end of file diff --git a/lib.esm/providers/provider-jsonrpc.d.ts.map b/lib.esm/providers/provider-jsonrpc.d.ts.map new file mode 100644 index 00000000..162c4345 --- /dev/null +++ b/lib.esm/providers/provider-jsonrpc.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"provider-jsonrpc.d.ts","sourceRoot":"","sources":["../../src.ts/providers/provider-jsonrpc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAWH,OAAO,EAGH,YAAY,EACf,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,gBAAgB,EAAuB,MAAM,wBAAwB,CAAC;AAC/E,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAA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AO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IA4B5D,YAAY,IAAI,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;IAKnD,OAAO,IAAI,IAAI;CAmBlB;AAED;;;;;;;GAOG;AACH,qBAAa,eAAgB,SAAQ,kBAAkB;gBAEvC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,YAAY,EAAE,OAAO,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,yBAAyB;IAa9G,cAAc,CAAC,GAAG,EAAE,YAAY,GAAG,UAAU;IAK7C,cAAc,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,YAAY;IAStC,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAU5F,KAAK,CAAC,OAAO,EAAE,cAAc,GAAG,KAAK,CAAC,cAAc,CAAC,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;CAa9G"} \ No newline at end of file diff --git a/lib.esm/providers/provider-jsonrpc.js b/lib.esm/providers/provider-jsonrpc.js new file mode 100644 index 00000000..9b0e1471 --- /dev/null +++ b/lib.esm/providers/provider-jsonrpc.js @@ -0,0 +1,960 @@ +/** + * One of the most common ways to interact with the blockchain is + * by a node running a JSON-RPC interface which can be connected to, + * based on the transport, using: + * + * - HTTP or HTTPS - [[JsonRpcProvider]] + * - WebSocket - [[WebSocketProvider]] + * - IPC - [[IpcSocketProvider]] + * + * @_section: api/providers/jsonrpc:JSON-RPC Provider [about-jsonrpcProvider] + */ +// @TODO: +// - Add the batching API +// https://playground.open-rpc.org/?schemaUrl=https://raw.githubusercontent.com/ethereum/eth1.0-apis/assembled-spec/openrpc.json&uiSchema%5BappBar%5D%5Bui:splitView%5D=true&uiSchema%5BappBar%5D%5Bui:input%5D=false&uiSchema%5BappBar%5D%5Bui:examplesDropdown%5D=false +import { AbiCoder } from "../abi/index.js"; +import { getAddress, resolveAddress } from "../address/index.js"; +import { TypedDataEncoder } from "../hash/index.js"; +import { accessListify } from "../transaction/index.js"; +import { defineProperties, getBigInt, hexlify, isHexString, toQuantity, toUtf8Bytes, isError, makeError, assert, assertArgument, resolveProperties } from "../utils/index.js"; +import { AbstractProvider, UnmanagedSubscriber } from "./abstract-provider.js"; +import { AbstractSigner } from "./abstract-signer.js"; +import { Network } from "./network.js"; +import { FilterIdEventSubscriber, FilterIdPendingSubscriber } from "./subscriber-filterid.js"; +const Primitive = "bigint,boolean,function,number,string,symbol".split(/,/g); +//const Methods = "getAddress,then".split(/,/g); +function deepCopy(value) { + if (value == null || Primitive.indexOf(typeof (value)) >= 0) { + return value; + } + // Keep any Addressable + if (typeof (value.getAddress) === "function") { + return value; + } + if (Array.isArray(value)) { + return (value.map(deepCopy)); + } + if (typeof (value) === "object") { + return Object.keys(value).reduce((accum, key) => { + accum[key] = value[key]; + return accum; + }, {}); + } + throw new Error(`should not happen: ${value} (${typeof (value)})`); +} +function stall(duration) { + return new Promise((resolve) => { setTimeout(resolve, duration); }); +} +function getLowerCase(value) { + if (value) { + return value.toLowerCase(); + } + return value; +} +const defaultOptions = { + staticNetwork: null, + batchStallTime: 10, + batchMaxSize: (1 << 20), + batchMaxCount: 100, + cacheTimeout: 250 +}; +// @TODO: Unchecked Signers +export class JsonRpcSigner extends AbstractSigner { + address; + constructor(provider, address) { + super(provider); + address = getAddress(address); + defineProperties(this, { address }); + } + connect(provider) { + assert(false, "cannot reconnect JsonRpcSigner", "UNSUPPORTED_OPERATION", { + operation: "signer.connect" + }); + } + async getAddress() { + return this.address; + } + // JSON-RPC will automatially fill in nonce, etc. so we just check from + async populateTransaction(tx) { + return await this.populateCall(tx); + } + // Returns just the hash of the transaction after sent, which is what + // the bare JSON-RPC API does; + async sendUncheckedTransaction(_tx) { + const tx = deepCopy(_tx); + const promises = []; + // Make sure the from matches the sender + if (tx.from) { + const _from = tx.from; + promises.push((async () => { + const from = await resolveAddress(_from); + assertArgument(from != null && from.toLowerCase() === this.address.toLowerCase(), "from address mismatch", "transaction", _tx); + tx.from = from; + })()); + } + else { + tx.from = this.address; + } + // The JSON-RPC for quai_sendTransaction uses 90000 gas; if the user + // wishes to use this, it is easy to specify explicitly, otherwise + // we look it up for them. + if (tx.gasLimit == null) { + promises.push((async () => { + tx.gasLimit = await this.provider.estimateGas({ ...tx, from: this.address }); + })()); + } + // The address may be an ENS name or Addressable + if (tx.to != null) { + const _to = tx.to; + promises.push((async () => { + tx.to = await resolveAddress(_to); + })()); + } + // Wait until all of our properties are filled in + if (promises.length) { + await Promise.all(promises); + } + const hexTx = this.provider.getRpcTransaction(tx); + return this.provider.send("quai_sendTransaction", [hexTx]); + } + async sendTransaction(tx) { + // This cannot be mined any earlier than any recent block + const shard = await this.shardFromAddress(tx.from); + const blockNumber = await this.provider.getBlockNumber(shard); + // Send the transaction + const hash = await this.sendUncheckedTransaction(tx); + // Unfortunately, JSON-RPC only provides and opaque transaction hash + // for a response, and we need the actual transaction, so we poll + // for it; it should show up very quickly + return await (new Promise((resolve, reject) => { + const timeouts = [1000, 100]; + let invalids = 0; + const checkTx = async () => { + try { + // Try getting the transaction + const tx = await this.provider.getTransaction(hash); + if (tx != null) { + resolve(tx.replaceableTransaction(blockNumber)); + return; + } + } + catch (error) { + // If we were cancelled: stop polling. + // If the data is bad: the node returns bad transactions + // If the network changed: calling again will also fail + // If unsupported: likely destroyed + if (isError(error, "CANCELLED") || isError(error, "BAD_DATA") || + isError(error, "NETWORK_ERROR" || isError(error, "UNSUPPORTED_OPERATION"))) { + if (error.info == null) { + error.info = {}; + } + error.info.sendTransactionHash = hash; + reject(error); + return; + } + // Stop-gap for misbehaving backends; see #4513 + if (isError(error, "INVALID_ARGUMENT")) { + invalids++; + if (error.info == null) { + error.info = {}; + } + error.info.sendTransactionHash = hash; + if (invalids > 10) { + reject(error); + return; + } + } + // Notify anyone that cares; but we will try again, since + // it is likely an intermittent service error + this.provider.emit("error", makeError("failed to fetch transation after sending (will try again)", "UNKNOWN_ERROR", { error })); + } + // Wait another 4 seconds + this.provider._setTimeout(() => { checkTx(); }, timeouts.pop() || 4000); + }; + checkTx(); + })); + } + async signTransaction(_tx) { + const tx = deepCopy(_tx); + // Make sure the from matches the sender + if (tx.from) { + const from = await resolveAddress(tx.from); + assertArgument(from != null && from.toLowerCase() === this.address.toLowerCase(), "from address mismatch", "transaction", _tx); + tx.from = from; + } + else { + tx.from = this.address; + } + const hexTx = this.provider.getRpcTransaction(tx); + return await this.provider.send("quai_signTransaction", [hexTx]); + } + async signMessage(_message) { + const message = ((typeof (_message) === "string") ? toUtf8Bytes(_message) : _message); + return await this.provider.send("personal_sign", [ + hexlify(message), this.address.toLowerCase() + ]); + } + async signTypedData(domain, types, _value) { + const value = deepCopy(_value); + return await this.provider.send("quai_signTypedData_v4", [ + this.address.toLowerCase(), + JSON.stringify(TypedDataEncoder.getPayload(domain, types, value)) + ]); + } + async unlock(password) { + return this.provider.send("personal_unlockAccount", [ + this.address.toLowerCase(), password, null + ]); + } + // https://github.com/ethereum/wiki/wiki/JSON-RPC#quai_sign + async _legacySignMessage(_message) { + const message = ((typeof (_message) === "string") ? toUtf8Bytes(_message) : _message); + return await this.provider.send("quai_sign", [ + this.address.toLowerCase(), hexlify(message) + ]); + } +} +/** + * The JsonRpcApiProvider is an abstract class and **MUST** be + * sub-classed. + * + * It provides the base for all JSON-RPC-based Provider interaction. + * + * Sub-classing Notes: + * - a sub-class MUST override _send + * - a sub-class MUST call the `_start()` method once connected + */ +export class JsonRpcApiProvider extends AbstractProvider { + #options; + // The next ID to use for the JSON-RPC ID field + #nextId; + // Payloads are queued and triggered in batches using the drainTimer + #payloads; + #drainTimer; + #notReady; + #network; + #pendingDetectNetwork; + initPromise; + #scheduleDrain() { + if (this.#drainTimer) { + return; + } + // If we aren't using batching, no harm in sending it immediately + const stallTime = (this._getOption("batchMaxCount") === 1) ? 0 : this._getOption("batchStallTime"); + this.#drainTimer = setTimeout(() => { + this.#drainTimer = null; + const payloads = this.#payloads; + this.#payloads = []; + while (payloads.length) { + // Create payload batches that satisfy our batch constraints + const batch = [(payloads.shift())]; + while (payloads.length) { + if (batch.length === this.#options.batchMaxCount) { + break; + } + batch.push((payloads.shift())); + const bytes = JSON.stringify(batch.map((p) => p.payload)); + if (bytes.length > this.#options.batchMaxSize) { + payloads.unshift((batch.pop())); + break; + } + } + // Process the result to each payload + (async () => { + const payloadMap = new Map(); + for (let i = 0; i < batch.length; i++) { + if (!payloadMap.has(batch[i].shard)) { + if (batch[i].payload != null) { + payloadMap.set(batch[i].shard, [batch[i].payload]); + } + ; + } + else { + payloadMap.get(batch[i].shard)?.push(batch[i].payload); + } + } + let rawResult = []; + await Promise.all(Array.from(payloadMap).map(async ([key, value]) => { + const payload = value.length === 1 ? value[0] : value; + const shard = key; + this.emit("debug", { action: "sendRpcPayload", payload }); + rawResult.push(await this._send(payload, shard)); + this.emit("debug", { action: "receiveRpcResult", payload }); + })); + const result = rawResult.flat(); + try { + // Process results in batch order + for (const { resolve, reject, payload } of batch) { + if (this.destroyed) { + reject(makeError("provider destroyed; cancelled request", "UNSUPPORTED_OPERATION", { operation: payload.method })); + continue; + } + // Find the matching result + const resp = result.filter((r) => (r.id === payload.id))[0]; + // No result; the node failed us in unexpected ways + if (resp == null) { + const error = makeError("missing response for request", "BAD_DATA", { + value: result, info: { payload } + }); + this.emit("error", error); + reject(error); + continue; + } + // The response is an error + if ("error" in resp) { + reject(this.getRpcError(payload, resp)); + continue; + } + // All good; send the result + resolve(resp.result); + } + } + catch (error) { + this.emit("debug", { action: "receiveRpcError", error }); + for (const { reject } of batch) { + // @TODO: augment the error with the payload + reject(error); + } + } + })(); + } + }, stallTime); + } + constructor(network, options) { + super(network, options); + this.#nextId = 1; + this.#options = Object.assign({}, defaultOptions, options || {}); + this.#payloads = []; + this.#drainTimer = null; + this.#network = null; + this.#pendingDetectNetwork = null; + { + let resolve = null; + const promise = new Promise((_resolve) => { + resolve = _resolve; + }); + this.#notReady = { promise, resolve }; + } + const staticNetwork = this._getOption("staticNetwork"); + if (typeof (staticNetwork) === "boolean") { + assertArgument(!staticNetwork || network !== "any", "staticNetwork cannot be used on special network 'any'", "options", options); + if (staticNetwork && network != null) { + this.#network = Network.from(network); + } + } + else if (staticNetwork) { + // Make sure any static network is compatbile with the provided netwrok + assertArgument(network == null || staticNetwork.matches(network), "staticNetwork MUST match network object", "options", options); + this.#network = staticNetwork; + } + } + /** + * Returns the value associated with the option %%key%%. + * + * Sub-classes can use this to inquire about configuration options. + */ + _getOption(key) { + return this.#options[key]; + } + /** + * Gets the [[Network]] this provider has committed to. On each call, the network + * is detected, and if it has changed, the call will reject. + */ + get _network() { + assert(this.#network, "network is not available yet", "NETWORK_ERROR"); + return this.#network; + } + /** + * Resolves to the non-normalized value by performing %%req%%. + * + * Sub-classes may override this to modify behavior of actions, + * and should generally call ``super._perform`` as a fallback. + */ + async _perform(req) { + // Legacy networks do not like the type field being passed along (which + // is fair), so we delete type if it is 0 and a non-EIP-1559 network + await this.initPromise; + if (req.method === "call" || req.method === "estimateGas") { + let tx = req.transaction; + if (tx && tx.type != null && getBigInt(tx.type)) { + // If there are no EIP-1559 properties, it might be non-EIP-a559 + if (tx.maxFeePerGas == null && tx.maxPriorityFeePerGas == null) { + const feeData = await this.getFeeData(req.shard); + if (feeData.maxFeePerGas == null && feeData.maxPriorityFeePerGas == null) { + // Network doesn't know about EIP-1559 (and hence type) + req = Object.assign({}, req, { + transaction: Object.assign({}, tx, { type: undefined }) + }); + } + } + } + } + const request = this.getRpcRequest(req); + if (request != null) { + const shard = 'shard' in req ? req.shard : undefined; + return await this.send(request.method, request.args, shard); + } + return super._perform(req); + } + /** + * Sub-classes may override this; it detects the *actual* network that + * we are **currently** connected to. + * + * Keep in mind that [[send]] may only be used once [[ready]], otherwise the + * _send primitive must be used instead. + */ + async _detectNetwork() { + const network = this._getOption("staticNetwork"); + if (network) { + if (network === true) { + if (this.#network) { + return this.#network; + } + } + else { + return network; + } + } + if (this.#pendingDetectNetwork) { + return await this.#pendingDetectNetwork; + } + // If we are ready, use ``send``, which enabled requests to be batched + if (this.ready) { + this.#pendingDetectNetwork = (async () => { + try { + const result = Network.from(getBigInt(await this.send("quai_chainId", []))); + this.#pendingDetectNetwork = null; + return result; + } + catch (error) { + this.#pendingDetectNetwork = null; + throw error; + } + })(); + return await this.#pendingDetectNetwork; + } + // We are not ready yet; use the primitive _send + this.#pendingDetectNetwork = (async () => { + const payload = { + id: this.#nextId++, method: "quai_chainId", params: [], jsonrpc: "2.0" + }; + this.emit("debug", { action: "sendRpcPayload", payload }); + let result; + try { + result = (await this._send(payload))[0]; + this.#pendingDetectNetwork = null; + } + catch (error) { + this.#pendingDetectNetwork = null; + this.emit("debug", { action: "receiveRpcError", error }); + throw error; + } + this.emit("debug", { action: "receiveRpcResult", result }); + if ("result" in result) { + return Network.from(getBigInt(result.result)); + } + throw this.getRpcError(payload, result); + })(); + return await this.#pendingDetectNetwork; + } + /** + * Sub-classes **MUST** call this. Until [[_start]] has been called, no calls + * will be passed to [[_send]] from [[send]]. If it is overridden, then + * ``super._start()`` **MUST** be called. + * + * Calling it multiple times is safe and has no effect. + */ + _start() { + if (this.#notReady == null || this.#notReady.resolve == null) { + return; + } + this.#notReady.resolve(); + this.#notReady = null; + (async () => { + // Bootstrap the network + while (this.#network == null && !this.destroyed) { + try { + this.#network = await this._detectNetwork(); + } + catch (error) { + if (this.destroyed) { + break; + } + console.log("JsonRpcProvider failed to detect network and cannot start up; retry in 1s (perhaps the URL is wrong or the node is not started)"); + this.emit("error", makeError("failed to bootstrap network detection", "NETWORK_ERROR", { event: "initial-network-discovery", info: { error } })); + await stall(1000); + } + } + // Start dispatching requests + this.#scheduleDrain(); + })(); + } + /** + * Resolves once the [[_start]] has been called. This can be used in + * sub-classes to defer sending data until the connection has been + * established. + */ + async _waitUntilReady() { + if (this.#notReady == null) { + return; + } + return await this.#notReady.promise; + } + /** + * Return a Subscriber that will manage the %%sub%%. + * + * Sub-classes may override this to modify the behavior of + * subscription management. + */ + _getSubscriber(sub) { + // Pending Filters aren't availble via polling + if (sub.type === "pending") { + return new FilterIdPendingSubscriber(this); + } + if (sub.type === "event") { + return new FilterIdEventSubscriber(this, sub.filter); + } + // Orphaned Logs are handled automatically, by the filter, since + // logs with removed are emitted by it + if (sub.type === "orphan" && sub.filter.orphan === "drop-log") { + return new UnmanagedSubscriber("orphan"); + } + return super._getSubscriber(sub); + } + /** + * Returns true only if the [[_start]] has been called. + */ + get ready() { return this.#notReady == null; } + /** + * Returns %%tx%% as a normalized JSON-RPC transaction request, + * which has all values hexlified and any numeric values converted + * to Quantity values. + */ + getRpcTransaction(tx) { + const result = {}; + // JSON-RPC now requires numeric values to be "quantity" values + ["chainId", "gasLimit", "gasPrice", "type", "maxFeePerGas", "maxPriorityFeePerGas", "nonce", "value"].forEach((key) => { + if (tx[key] == null) { + return; + } + let dstKey = key; + if (key === "gasLimit") { + dstKey = "gas"; + } + result[dstKey] = toQuantity(getBigInt(tx[key], `tx.${key}`)); + }); + // Make sure addresses and data are lowercase + ["from", "to", "data"].forEach((key) => { + if (tx[key] == null) { + return; + } + result[key] = hexlify(tx[key]); + }); + // Normalize the access list object + if (tx.accessList) { + result["accessList"] = accessListify(tx.accessList); + } + return result; + } + /** + * Returns the request method and arguments required to perform + * %%req%%. + */ + getRpcRequest(req) { + switch (req.method) { + case "chainId": + return { method: "quai_chainId", args: [] }; + case "getBlockNumber": + return { method: "quai_blockNumber", args: [] }; + case "getGasPrice": + return { + method: "quai_baseFee", + args: [req.txType] + }; + case "getMaxPriorityFeePerGas": + return { method: "quai_maxPriorityFeePerGas", args: [] }; + case "getBalance": + return { + method: "quai_getBalance", + args: [getLowerCase(req.address), req.blockTag] + }; + case "getTransactionCount": + return { + method: "quai_getTransactionCount", + args: [getLowerCase(req.address), req.blockTag] + }; + case "getCode": + return { + method: "quai_getCode", + args: [getLowerCase(req.address), req.blockTag] + }; + case "getStorage": + return { + method: "quai_getStorageAt", + args: [ + getLowerCase(req.address), + ("0x" + req.position.toString(16)), + req.blockTag + ] + }; + case "broadcastTransaction": + return { + method: "quai_sendRawTransaction", + args: [req.signedTransaction] + }; + case "getBlock": + if ("blockTag" in req) { + return { + method: "quai_getBlockByNumber", + args: [req.blockTag, !!req.includeTransactions] + }; + } + else if ("blockHash" in req) { + return { + method: "quai_getBlockByHash", + args: [req.blockHash, !!req.includeTransactions] + }; + } + break; + case "getTransaction": + return { + method: "quai_getTransactionByHash", + args: [req.hash] + }; + case "getTransactionReceipt": + return { + method: "quai_getTransactionReceipt", + args: [req.hash] + }; + case "call": + return { + method: "quai_call", + args: [this.getRpcTransaction(req.transaction), req.blockTag] + }; + case "estimateGas": { + return { + method: "quai_estimateGas", + args: [this.getRpcTransaction(req.transaction)] + }; + } + case "getRunningLocations": { + return { + method: "quai_listRunningChains", + args: [] + }; + } + case "getProtocolTrieExpansionCount": { + return { + method: "quai_getProtocolExpansionNumber", + args: [] + }; + } + case "getProtocolExpansionNumber": { + return { + method: "quai_getProtocolExpansionNumber", + args: [] + }; + } + case "getQiRateAtBlock": { + return { + method: "quai_qiRateAtBlock", + args: [req.blockTag, req.amt] + }; + } + case "getQuaiRateAtBlock": { + return { + method: "quai_quaiRateAtBlock", + args: [req.blockTag, req.amt] + }; + } + case "getLogs": + if (req.filter && req.filter.address != null) { + if (Array.isArray(req.filter.address)) { + req.filter.address = req.filter.address.map(getLowerCase); + } + else { + req.filter.address = getLowerCase(req.filter.address); + } + } + return { method: "quai_getLogs", args: [req.filter] }; + } + return null; + } + /** + * Returns an quais-style Error for the given JSON-RPC error + * %%payload%%, coalescing the various strings and error shapes + * that different nodes return, coercing them into a machine-readable + * standardized error. + */ + getRpcError(payload, _error) { + const { method } = payload; + const { error } = _error; + if (method === "quai_estimateGas" && error.message) { + const msg = error.message; + if (!msg.match(/revert/i) && msg.match(/insufficient funds/i)) { + return makeError("insufficient funds", "INSUFFICIENT_FUNDS", { + transaction: (payload.params[0]), + info: { payload, error } + }); + } + } + if (method === "quai_call" || method === "quai_estimateGas") { + const result = spelunkData(error); + const e = AbiCoder.getBuiltinCallException((method === "quai_call") ? "call" : "estimateGas", (payload.params[0]), (result ? result.data : null)); + e.info = { error, payload }; + return e; + } + // Only estimateGas and call can return arbitrary contract-defined text, so now we + // we can process text safely. + const message = JSON.stringify(spelunkMessage(error)); + if (typeof (error.message) === "string" && error.message.match(/user denied|quais-user-denied/i)) { + const actionMap = { + quai_sign: "signMessage", + personal_sign: "signMessage", + quai_signTypedData_v4: "signTypedData", + quai_signTransaction: "signTransaction", + quai_sendTransaction: "sendTransaction", + quai_requestAccounts: "requestAccess", + wallet_requestAccounts: "requestAccess", + }; + return makeError(`user rejected action`, "ACTION_REJECTED", { + action: (actionMap[method] || "unknown"), + reason: "rejected", + info: { payload, error } + }); + } + if (method === "quai_sendRawTransaction" || method === "quai_sendTransaction") { + const transaction = (payload.params[0]); + if (message.match(/insufficient funds|base fee exceeds gas limit/i)) { + return makeError("insufficient funds for intrinsic transaction cost", "INSUFFICIENT_FUNDS", { + transaction, info: { error } + }); + } + if (message.match(/nonce/i) && message.match(/too low/i)) { + return makeError("nonce has already been used", "NONCE_EXPIRED", { transaction, info: { error } }); + } + // "replacement transaction underpriced" + if (message.match(/replacement transaction/i) && message.match(/underpriced/i)) { + return makeError("replacement fee too low", "REPLACEMENT_UNDERPRICED", { transaction, info: { error } }); + } + if (message.match(/only replay-protected/i)) { + return makeError("legacy pre-eip-155 transactions not supported", "UNSUPPORTED_OPERATION", { + operation: method, info: { transaction, info: { error } } + }); + } + } + let unsupported = !!message.match(/the method .* does not exist/i); + if (!unsupported) { + if (error && error.details && error.details.startsWith("Unauthorized method:")) { + unsupported = true; + } + } + if (unsupported) { + return makeError("unsupported operation", "UNSUPPORTED_OPERATION", { + operation: payload.method, info: { error, payload } + }); + } + return makeError("could not coalesce error", "UNKNOWN_ERROR", { error, payload }); + } + /** + * Requests the %%method%% with %%params%% via the JSON-RPC protocol + * over the underlying channel. This can be used to call methods + * on the backend that do not have a high-level API within the Provider + * API. + * + * This method queues requests according to the batch constraints + * in the options, assigns the request a unique ID. + * + * **Do NOT override** this method in sub-classes; instead + * override [[_send]] or force the options values in the + * call to the constructor to modify this method's behavior. + */ + send(method, params, shard) { + // @TODO: cache chainId?? purge on switch_networks + // We have been destroyed; no operations are supported anymore + if (this.destroyed) { + return Promise.reject(makeError("provider destroyed; cancelled request", "UNSUPPORTED_OPERATION", { operation: method })); + } + const id = this.#nextId++; + const promise = new Promise((resolve, reject) => { + this.#payloads.push({ + resolve, reject, + payload: { method, params, id, jsonrpc: "2.0" }, + shard: shard + }); + }); + // If there is not a pending drainTimer, set one + this.#scheduleDrain(); + return promise; + } + /** + * Resolves to the [[Signer]] account for %%address%% managed by + * the client. + * + * If the %%address%% is a number, it is used as an index in the + * the accounts from [[listAccounts]]. + * + * This can only be used on clients which manage accounts (such as + * Geth with imported account or MetaMask). + * + * Throws if the account doesn't exist. + */ + // Works only if using a local node or browser wallet for this, otherwise cannot get accounts + async getSigner(address) { + if (address == null) { + address = 0; + } + const accountsPromise = this.send("quai_accounts", []); + // Account index + if (typeof (address) === "number") { + const accounts = (await accountsPromise); + if (address >= accounts.length) { + throw new Error("no such account"); + } + return new JsonRpcSigner(this, accounts[address]); + } + const { accounts } = await resolveProperties({ + network: this.getNetwork(), + accounts: accountsPromise + }); + // Account address + address = getAddress(address); + for (const account of accounts) { + if (getAddress(account) === address) { + return new JsonRpcSigner(this, address); + } + } + throw new Error("invalid account"); + } + async listAccounts() { + const accounts = await this.send("quai_accounts", []); + return accounts.map((a) => new JsonRpcSigner(this, a)); + } + destroy() { + // Stop processing requests + if (this.#drainTimer) { + clearTimeout(this.#drainTimer); + this.#drainTimer = null; + } + // Cancel all pending requests + for (const { payload, reject } of this.#payloads) { + reject(makeError("provider destroyed; cancelled request", "UNSUPPORTED_OPERATION", { operation: payload.method })); + } + this.#payloads = []; + // Parent clean-up + super.destroy(); + } +} +/** + * The JsonRpcProvider is one of the most common Providers, + * which performs all operations over HTTP (or HTTPS) requests. + * + * Events are processed by polling the backend for the current block + * number; when it advances, all block-base events are then checked + * for updates. + */ +export class JsonRpcProvider extends JsonRpcApiProvider { + constructor(urls, network, options) { + if (urls == null) { + urls = ["http:/\/localhost:8545"]; + } + super(network, options); + if (Array.isArray(urls)) { + this.initPromise = this.initUrlMap(urls); + } + else if (typeof urls === "string") { + this.initPromise = this.initUrlMap([urls]); + } + else { + this.initPromise = this.initUrlMap(urls.clone()); + } + } + _getSubscriber(sub) { + const subscriber = super._getSubscriber(sub); + return subscriber; + } + _getConnection(shard) { + const connection = this.connect[this.connect.length - 1].clone(); + if (typeof shard === "string") { + const shardBytes = this.shardBytes(shard); + connection.url = this._urlMap.get(shardBytes) ?? connection.url; + } + return connection; + } + async send(method, params, shard) { + // All requests are over HTTP, so we can just start handling requests + // We do this here rather than the constructor so that we don't send any + // requests to the network (i.e. quai_chainId) until we absolutely have to. + // await this.initPromise; + await this._start(); + return await super.send(method, params, shard); + } + async _send(payload, shard) { + // Configure a POST connection for the requested method + const request = this._getConnection(shard); + request.body = JSON.stringify(payload); + request.setHeader("content-type", "application/json"); + const response = await request.send(); + response.assertOk(); + let resp = response.bodyJson; + if (!Array.isArray(resp)) { + resp = [resp]; + } + return resp; + } +} +function spelunkData(value) { + if (value == null) { + return null; + } + // These *are* the droids we're looking for. + if (typeof (value.message) === "string" && value.message.match(/revert/i) && isHexString(value.data)) { + return { message: value.message, data: value.data }; + } + // Spelunk further... + if (typeof (value) === "object") { + for (const key in value) { + const result = spelunkData(value[key]); + if (result) { + return result; + } + } + return null; + } + // Might be a JSON string we can further descend... + if (typeof (value) === "string") { + try { + return spelunkData(JSON.parse(value)); + } + catch (error) { } + } + return null; +} +function _spelunkMessage(value, result) { + if (value == null) { + return; + } + // These *are* the droids we're looking for. + if (typeof (value.message) === "string") { + result.push(value.message); + } + // Spelunk further... + if (typeof (value) === "object") { + for (const key in value) { + _spelunkMessage(value[key], result); + } + } + // Might be a JSON string we can further descend... + if (typeof (value) === "string") { + try { + return _spelunkMessage(JSON.parse(value), result); + } + catch (error) { } + } +} +function spelunkMessage(value) { + const result = []; + _spelunkMessage(value, result); + return result; +} +//# sourceMappingURL=provider-jsonrpc.js.map \ No newline at end of file diff --git a/lib.esm/providers/provider-jsonrpc.js.map b/lib.esm/providers/provider-jsonrpc.js.map new file mode 100644 index 00000000..80c021ad --- /dev/null +++ b/lib.esm/providers/provider-jsonrpc.js.map @@ -0,0 +1 @@ +{"version":3,"file":"provider-jsonrpc.js","sourceRoot":"","sources":["../../src.ts/providers/provider-jsonrpc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,SAAS;AACT,yBAAyB;AAEzB,yQAAyQ;AAEzQ,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EACH,gBAAgB,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAC1E,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,cAAc,EAC5B,iBAAiB,EAClC,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC/E,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,uBAAuB,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AAa9F,MAA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AC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,CAAC;SACrD;QAAC,OAAO,KAAK,EAAE,GAAG;KACtB;AACL,CAAC;AAED,SAAS,cAAc,CAAC,KAAU;IAC9B,MAAM,MAAM,GAAkB,EAAG,CAAC;IAClC,eAAe,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC/B,OAAO,MAAM,CAAC;AAClB,CAAC"} \ No newline at end of file diff --git a/lib.esm/providers/provider-socket.d.ts b/lib.esm/providers/provider-socket.d.ts new file mode 100644 index 00000000..41c58fc0 --- /dev/null +++ b/lib.esm/providers/provider-socket.d.ts @@ -0,0 +1,113 @@ +/** + * Generic long-lived socket provider. + * + * Sub-classing notes + * - a sub-class MUST call the `_start()` method once connected + * - a sub-class MUST override the `_write(string)` method + * - a sub-class MUST call `_processMessage(string)` for each message + * + * @_subsection: api/providers/abstract-provider:Socket Providers [about-socketProvider] + */ +import { JsonRpcApiProvider } from "./provider-jsonrpc.js"; +import type { Subscriber, Subscription } from "./abstract-provider.js"; +import type { EventFilter } from "./provider.js"; +import type { JsonRpcApiProviderOptions, JsonRpcError, JsonRpcPayload, JsonRpcResult } from "./provider-jsonrpc.js"; +import type { Networkish } from "./network.js"; +/** + * A **SocketSubscriber** uses a socket transport to handle events and + * should use [[_emit]] to manage the events. + */ +export declare class SocketSubscriber implements Subscriber { + #private; + /** + * The filter. + */ + get filter(): Array; + /** + * Creates a new **SocketSubscriber** attached to %%provider%% listening + * to %%filter%%. + */ + constructor(provider: SocketProvider, filter: Array); + start(): void; + stop(): void; + pause(dropWhilePaused?: boolean): void; + resume(): void; + /** + * @_ignore: + */ + _handleMessage(message: any): void; + /** + * Sub-classes **must** override this to emit the events on the + * provider. + */ + _emit(provider: SocketProvider, message: any): Promise; +} +/** + * A **SocketBlockSubscriber** listens for ``newHeads`` events and emits + * ``"block"`` events. + */ +export declare class SocketBlockSubscriber extends SocketSubscriber { + /** + * @_ignore: + */ + constructor(provider: SocketProvider); + _emit(provider: SocketProvider, message: any): Promise; +} +/** + * A **SocketPendingSubscriber** listens for pending transacitons and emits + * ``"pending"`` events. + */ +export declare class SocketPendingSubscriber extends SocketSubscriber { + /** + * @_ignore: + */ + constructor(provider: SocketProvider); + _emit(provider: SocketProvider, message: any): Promise; +} +/** + * A **SocketEventSubscriber** listens for event logs. + */ +export declare class SocketEventSubscriber extends SocketSubscriber { + #private; + /** + * The filter. + */ + get logFilter(): EventFilter; + /** + * @_ignore: + */ + constructor(provider: SocketProvider, filter: EventFilter); + _emit(provider: SocketProvider, message: any): Promise; +} +/** + * A **SocketProvider** is backed by a long-lived connection over a + * socket, which can subscribe and receive real-time messages over + * its communication channel. + */ +export declare class SocketProvider extends JsonRpcApiProvider { + #private; + /** + * Creates a new **SocketProvider** connected to %%network%%. + * + * If unspecified, the network will be discovered. + */ + constructor(network?: Networkish, _options?: JsonRpcApiProviderOptions); + _getSubscriber(sub: Subscription): Subscriber; + /** + * Register a new subscriber. This is used internalled by Subscribers + * and generally is unecessary unless extending capabilities. + */ + _register(filterId: number | string, subscriber: SocketSubscriber): void; + _send(payload: JsonRpcPayload | Array): Promise>; + /** + * Sub-classes **must** call this with messages received over their + * transport to be processed and dispatched. + */ + _processMessage(message: string): Promise; + /** + * Sub-classes **must** override this to send %%message%% over their + * transport. + */ + _write(message: string): Promise; +} +//# sourceMappingURL=provider-socket.d.ts.map \ No newline at end of file diff --git a/lib.esm/providers/provider-socket.d.ts.map b/lib.esm/providers/provider-socket.d.ts.map new file mode 100644 index 00000000..616f5589 --- /dev/null +++ b/lib.esm/providers/provider-socket.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"provider-socket.d.ts","sourceRoot":"","sources":["../../src.ts/providers/provider-socket.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE3D,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,wBAAwB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AE,MAAM,EAAE,WAAW;IAKnD,KAAK,CAAC,QAAQ,EAAE,cAAc,EAAE,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;CAGrE;AAED;;;;GAIG;AACH,qBAAa,cAAe,SAAQ,kBAAkB;;IAUlD;;;;OAIG;gBACS,OAAO,CAAC,EAAE,UAAU,EAAE,QAAQ,CAAC,EAAE,yBAAyB;IAgCtE,cAAc,CAAC,GAAG,EAAE,YAAY,GAAG,UAAU;IAoB7C;;;OAGG;IACH,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,UAAU,EAAE,gBAAgB,GAAG,IAAI;IAWlE,KAAK,CAAC,OAAO,EAAE,cAAc,GAAG,KAAK,CAAC,cAAc,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,aAAa,GAAG,YAAY,CAAC,CAAC;IAmC1G;;;OAGG;IACG,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAuCrD;;;OAGG;IACG,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAG/C"} \ No newline at end of file diff --git a/lib.esm/providers/provider-socket.js b/lib.esm/providers/provider-socket.js new file mode 100644 index 00000000..8a4b0c45 --- /dev/null +++ b/lib.esm/providers/provider-socket.js @@ -0,0 +1,298 @@ +/** + * Generic long-lived socket provider. + * + * Sub-classing notes + * - a sub-class MUST call the `_start()` method once connected + * - a sub-class MUST override the `_write(string)` method + * - a sub-class MUST call `_processMessage(string)` for each message + * + * @_subsection: api/providers/abstract-provider:Socket Providers [about-socketProvider] + */ +import { UnmanagedSubscriber } from "./abstract-provider.js"; +import { assert, assertArgument, makeError } from "../utils/index.js"; +import { JsonRpcApiProvider } from "./provider-jsonrpc.js"; +/** + * A **SocketSubscriber** uses a socket transport to handle events and + * should use [[_emit]] to manage the events. + */ +export class SocketSubscriber { + #provider; + #filter; + /** + * The filter. + */ + get filter() { return JSON.parse(this.#filter); } + #filterId; + #paused; + #emitPromise; + /** + * Creates a new **SocketSubscriber** attached to %%provider%% listening + * to %%filter%%. + */ + constructor(provider, filter) { + this.#provider = provider; + this.#filter = JSON.stringify(filter); + this.#filterId = null; + this.#paused = null; + this.#emitPromise = null; + } + start() { + this.#filterId = this.#provider.send("quai_subscribe", this.filter).then((filterId) => { + ; + this.#provider._register(filterId, this); + return filterId; + }); + } + stop() { + (this.#filterId).then((filterId) => { + this.#provider.send("quai_unsubscribe", [filterId]); + }); + this.#filterId = null; + } + // @TODO: pause should trap the current blockNumber, unsub, and on resume use getLogs + // and resume + pause(dropWhilePaused) { + assert(dropWhilePaused, "preserve logs while paused not supported by SocketSubscriber yet", "UNSUPPORTED_OPERATION", { operation: "pause(false)" }); + this.#paused = !!dropWhilePaused; + } + resume() { + this.#paused = null; + } + /** + * @_ignore: + */ + _handleMessage(message) { + if (this.#filterId == null) { + return; + } + if (this.#paused === null) { + let emitPromise = this.#emitPromise; + if (emitPromise == null) { + emitPromise = this._emit(this.#provider, message); + } + else { + emitPromise = emitPromise.then(async () => { + await this._emit(this.#provider, message); + }); + } + this.#emitPromise = emitPromise.then(() => { + if (this.#emitPromise === emitPromise) { + this.#emitPromise = null; + } + }); + } + } + /** + * Sub-classes **must** override this to emit the events on the + * provider. + */ + async _emit(provider, message) { + throw new Error("sub-classes must implemente this; _emit"); + } +} +/** + * A **SocketBlockSubscriber** listens for ``newHeads`` events and emits + * ``"block"`` events. + */ +export class SocketBlockSubscriber extends SocketSubscriber { + /** + * @_ignore: + */ + constructor(provider) { + super(provider, ["newHeads"]); + } + async _emit(provider, message) { + provider.emit("block", parseInt(message.number)); + } +} +/** + * A **SocketPendingSubscriber** listens for pending transacitons and emits + * ``"pending"`` events. + */ +export class SocketPendingSubscriber extends SocketSubscriber { + /** + * @_ignore: + */ + constructor(provider) { + super(provider, ["newPendingTransactions"]); + } + async _emit(provider, message) { + provider.emit("pending", message); + } +} +/** + * A **SocketEventSubscriber** listens for event logs. + */ +export class SocketEventSubscriber extends SocketSubscriber { + #logFilter; + /** + * The filter. + */ + get logFilter() { return JSON.parse(this.#logFilter); } + /** + * @_ignore: + */ + constructor(provider, filter) { + super(provider, ["logs", filter]); + this.#logFilter = JSON.stringify(filter); + } + async _emit(provider, message) { + provider.emit(this.logFilter, provider._wrapLog(message, provider._network)); + } +} +/** + * A **SocketProvider** is backed by a long-lived connection over a + * socket, which can subscribe and receive real-time messages over + * its communication channel. + */ +export class SocketProvider extends JsonRpcApiProvider { + #callbacks; + // Maps each filterId to its subscriber + #subs; + // If any events come in before a subscriber has finished + // registering, queue them + #pending; + /** + * Creates a new **SocketProvider** connected to %%network%%. + * + * If unspecified, the network will be discovered. + */ + constructor(network, _options) { + // Copy the options + const options = Object.assign({}, (_options != null) ? _options : {}); + // Support for batches is generally not supported for + // connection-base providers; if this changes in the future + // the _send should be updated to reflect this + assertArgument(options.batchMaxCount == null || options.batchMaxCount === 1, "sockets-based providers do not support batches", "options.batchMaxCount", _options); + options.batchMaxCount = 1; + // Socket-based Providers (generally) cannot change their network, + // since they have a long-lived connection; but let people override + // this if they have just cause. + if (options.staticNetwork == null) { + options.staticNetwork = true; + } + super(network, options); + this.#callbacks = new Map(); + this.#subs = new Map(); + this.#pending = new Map(); + } + // This value is only valid after _start has been called + /* + get _network(): Network { + if (this.#network == null) { + throw new Error("this shouldn't happen"); + } + return this.#network.clone(); + } + */ + _getSubscriber(sub) { + switch (sub.type) { + case "close": + return new UnmanagedSubscriber("close"); + case "block": + return new SocketBlockSubscriber(this); + case "pending": + return new SocketPendingSubscriber(this); + case "event": + return new SocketEventSubscriber(this, sub.filter); + case "orphan": + // Handled auto-matically within AbstractProvider + // when the log.removed = true + if (sub.filter.orphan === "drop-log") { + return new UnmanagedSubscriber("drop-log"); + } + } + return super._getSubscriber(sub); + } + /** + * Register a new subscriber. This is used internalled by Subscribers + * and generally is unecessary unless extending capabilities. + */ + _register(filterId, subscriber) { + this.#subs.set(filterId, subscriber); + const pending = this.#pending.get(filterId); + if (pending) { + for (const message of pending) { + subscriber._handleMessage(message); + } + this.#pending.delete(filterId); + } + } + async _send(payload) { + // WebSocket provider doesn't accept batches + assertArgument(!Array.isArray(payload), "WebSocket does not support batch send", "payload", payload); + // @TODO: stringify payloads here and store to prevent mutations + // Prepare a promise to respond to + const promise = new Promise((resolve, reject) => { + this.#callbacks.set(payload.id, { payload, resolve, reject }); + }); + // Wait until the socket is connected before writing to it + await this._waitUntilReady(); + // Write the request to the socket + await this._write(JSON.stringify(payload)); + return [await promise]; + } + // Sub-classes must call this once they are connected + /* + async _start(): Promise { + if (this.#ready) { return; } + + for (const { payload } of this.#callbacks.values()) { + await this._write(JSON.stringify(payload)); + } + + this.#ready = (async function() { + await super._start(); + })(); + } + */ + /** + * Sub-classes **must** call this with messages received over their + * transport to be processed and dispatched. + */ + async _processMessage(message) { + const result = (JSON.parse(message)); + if (result && typeof (result) === "object" && "id" in result) { + const callback = this.#callbacks.get(result.id); + if (callback == null) { + this.emit("error", makeError("received result for unknown id", "UNKNOWN_ERROR", { + reasonCode: "UNKNOWN_ID", + result + })); + return; + } + this.#callbacks.delete(result.id); + callback.resolve(result); + } + else if (result && result.method === "quai_subscription") { + const filterId = result.params.subscription; + const subscriber = this.#subs.get(filterId); + if (subscriber) { + subscriber._handleMessage(result.params.result); + } + else { + let pending = this.#pending.get(filterId); + if (pending == null) { + pending = []; + this.#pending.set(filterId, pending); + } + pending.push(result.params.result); + } + } + else { + this.emit("error", makeError("received unexpected message", "UNKNOWN_ERROR", { + reasonCode: "UNEXPECTED_MESSAGE", + result + })); + return; + } + } + /** + * Sub-classes **must** override this to send %%message%% over their + * transport. + */ + async _write(message) { + throw new Error("sub-classes must override this"); + } +} +//# sourceMappingURL=provider-socket.js.map \ No newline at end of file diff --git a/lib.esm/providers/provider-socket.js.map b/lib.esm/providers/provider-socket.js.map new file mode 100644 index 00000000..b34bc067 --- /dev/null +++ b/lib.esm/providers/provider-socket.js.map @@ -0,0 +1 @@ +{"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QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;gBAC1C,IAAI,OAAO,IAAI,IAAI,EAAE;oBACjB,OAAO,GAAG,EAAG,CAAC;oBACd,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;iBACxC;gBACD,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;aACtC;SAEJ;aAAM;YACH,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC,6BAA6B,EAAE,eAAe,EAAE;gBACzE,UAAU,EAAE,oBAAoB;gBAChC,MAAM;aACT,CAAC,CAAC,CAAC;YACJ,OAAO;SACV;IACL,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,MAAM,CAAC,OAAe;QACxB,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACtD,CAAC;CACJ"} \ No newline at end of file diff --git a/lib.esm/providers/provider-websocket.d.ts b/lib.esm/providers/provider-websocket.d.ts new file mode 100644 index 00000000..b34c9842 --- /dev/null +++ b/lib.esm/providers/provider-websocket.d.ts @@ -0,0 +1,37 @@ +import { SocketProvider } from "./provider-socket.js"; +import type { JsonRpcApiProviderOptions } from "./provider-jsonrpc.js"; +import type { Networkish } from "./network.js"; +/** + * A generic interface to a Websocket-like object. + */ +export interface WebSocketLike { + onopen: null | ((...args: Array) => any); + onmessage: null | ((...args: Array) => any); + onerror: null | ((...args: Array) => any); + readyState: number; + send(payload: any): void; + close(code?: number, reason?: string): void; +} +/** + * A function which can be used to re-create a WebSocket connection + * on disconnect. + */ +export type WebSocketCreator = () => WebSocketLike; +/** + * A JSON-RPC provider which is backed by a WebSocket. + * + * WebSockets are often preferred because they retain a live connection + * to a server, which permits more instant access to events. + * + * However, this incurs higher server infrasturture costs, so additional + * resources may be required to host your own WebSocket nodes and many + * third-party services charge additional fees for WebSocket endpoints. + */ +export declare class WebSocketProvider extends SocketProvider { + #private; + get websocket(): WebSocketLike; + constructor(url: string | WebSocketLike | WebSocketCreator, network?: Networkish, options?: JsonRpcApiProviderOptions); + _write(message: string): Promise; + destroy(): Promise; +} +//# sourceMappingURL=provider-websocket.d.ts.map \ No newline at end of file diff --git a/lib.esm/providers/provider-websocket.d.ts.map b/lib.esm/providers/provider-websocket.d.ts.map new file mode 100644 index 00000000..886b1976 --- /dev/null +++ b/lib.esm/providers/provider-websocket.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"provider-websocket.d.ts","sourceRoot":"","sources":["../../src.ts/providers/provider-websocket.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,KAAK,EAAE,yBAAyB,EAAC,MAAM,uBAAuB,CAAC;AACtE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C;;GAEG;AACH,MAAM,WAAW,aAAa;IAC1B,MAAM,EAAE,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC;IAC9C,SAAS,EAAE,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC;IACjD,OAAO,EAAE,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC;IAE/C,UAAU,EAAE,MAAM,CAAC;IAEnB,IAAI,CAAC,OAAO,EAAE,GAAG,GAAG,IAAI,CAAC;IACzB,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/C;AAED;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,aAAa,CAAC;AAEnD;;;;;;;;;GASG;AACH,qBAAa,iBAAkB,SAAQ,cAAc;;IAIjD,IAAI,SAAS,IAAI,aAAa,CAG7B;gBAEW,GAAG,EAAE,MAAM,GAAG,aAAa,GAAG,gBAAgB,EAAE,OAAO,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,yBAAyB;IA2C/G,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAItC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAOjC"} \ No newline at end of file diff --git a/lib.esm/providers/provider-websocket.js b/lib.esm/providers/provider-websocket.js new file mode 100644 index 00000000..2f4fb2e5 --- /dev/null +++ b/lib.esm/providers/provider-websocket.js @@ -0,0 +1,76 @@ +import { WebSocket as _WebSocket } from "./ws.js"; /*-browser*/ +import { SocketProvider } from "./provider-socket.js"; +/** + * A JSON-RPC provider which is backed by a WebSocket. + * + * WebSockets are often preferred because they retain a live connection + * to a server, which permits more instant access to events. + * + * However, this incurs higher server infrasturture costs, so additional + * resources may be required to host your own WebSocket nodes and many + * third-party services charge additional fees for WebSocket endpoints. + */ +export class WebSocketProvider extends SocketProvider { + #connect; + #websocket; + get websocket() { + if (this.#websocket == null) { + throw new Error("websocket closed"); + } + return this.#websocket; + } + constructor(url, network, options) { + super(network, options); + if (typeof (url) === "string") { + this.#connect = () => { return new _WebSocket(url); }; + this.#websocket = this.#connect(); + } + else if (typeof (url) === "function") { + this.#connect = url; + this.#websocket = url(); + } + else { + this.#connect = null; + this.#websocket = url; + } + this.websocket.onopen = async () => { + try { + await this._start(); + this.resume(); + } + catch (error) { + console.log("failed to start WebsocketProvider", error); + // @TODO: now what? Attempt reconnect? + } + }; + this.websocket.onmessage = (message) => { + this._processMessage(message.data); + }; + /* + this.websocket.onclose = (event) => { + // @TODO: What event.code should we reconnect on? + const reconnect = false; + if (reconnect) { + this.pause(true); + if (this.#connect) { + this.#websocket = this.#connect(); + this.#websocket.onopen = ... + // @TODO: this requires the super class to rebroadcast; move it there + } + this._reconnect(); + } + }; + */ + } + async _write(message) { + this.websocket.send(message); + } + async destroy() { + if (this.#websocket != null) { + this.#websocket.close(); + this.#websocket = null; + } + super.destroy(); + } +} +//# sourceMappingURL=provider-websocket.js.map \ No newline at end of file diff --git a/lib.esm/providers/provider-websocket.js.map b/lib.esm/providers/provider-websocket.js.map new file mode 100644 index 00000000..42a83b53 --- /dev/null +++ b/lib.esm/providers/provider-websocket.js.map @@ -0,0 +1 @@ +{"version":3,"file":"provider-websocket.js","sourceRoot":"","sources":["../../src.ts/providers/provider-websocket.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC,CAAC,YAAY;AAE/D,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAyBtD;;;;;;;;;GASG;AACH,MAAM,OAAO,iBAAkB,SAAQ,cAAc;IACjD,QAAQ,CAA0B;IAElC,UAAU,CAAuB;IACjC,IAAI,SAAS;QACT,IAAI,IAAI,CAAC,UAAU,IAAI,IAAI,EAAE;YAAE,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;SAAE;QACrE,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;IAED,YAAY,GAA8C,EAAE,OAAoB,EAAE,OAAmC;QACjH,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,OAAM,CAAC,GAAG,CAAC,KAAK,QAAQ,EAAE;YAC1B,IAAI,CAAC,QAAQ,GAAG,GAAG,EAAE,GAAG,OAAO,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YACtD,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;SACrC;aAAM,IAAI,OAAM,CAAC,GAAG,CAAC,KAAK,UAAU,EAAE;YACnC,IAAI,CAAC,QAAQ,GAAG,GAAG,CAAC;YACpB,IAAI,CAAC,UAAU,GAAG,GAAG,EAAE,CAAC;SAC3B;aAAM;YACH,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;YACrB,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC;SACzB;QAED,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,KAAK,IAAI,EAAE;YAC/B,IAAI;gBACA,MAAM,IAAI,CAAC,MAAM,EAAE,CAAA;gBACnB,IAAI,CAAC,MAAM,EAAE,CAAC;aACjB;YAAC,OAAO,KAAK,EAAE;gBACZ,OAAO,CAAC,GAAG,CAAC,mCAAmC,EAAE,KAAK,CAAC,CAAC;gBACxD,sCAAsC;aACzC;QACL,CAAC,CAAC;QAEF,IAAI,CAAC,SAAS,CAAC,SAAS,GAAG,CAAC,OAAyB,EAAE,EAAE;YACrD,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACvC,CAAC,CAAC;QACV;;;;;;;;;;;;;;UAcE;IACE,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,OAAe;QACxB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACjC,CAAC;IAED,KAAK,CAAC,OAAO;QACT,IAAI,IAAI,CAAC,UAAU,IAAI,IAAI,EAAE;YACzB,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;YACxB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;SAC1B;QACD,KAAK,CAAC,OAAO,EAAE,CAAC;IACpB,CAAC;CACJ"} \ No newline at end of file diff --git a/lib.esm/providers/provider.d.ts b/lib.esm/providers/provider.d.ts new file mode 100644 index 00000000..20d62807 --- /dev/null +++ b/lib.esm/providers/provider.d.ts @@ -0,0 +1,1075 @@ +import type { AddressLike } from "../address/index.js"; +import type { BigNumberish, EventEmitterable } from "../utils/index.js"; +import type { Signature } from "../crypto/index.js"; +import type { AccessList, AccessListish, TransactionLike } from "../transaction/index.js"; +import type { ContractRunner } from "./contracts.js"; +import type { Network } from "./network.js"; +import type { UTXOEntry, UTXOTransactionOutput } from "../transaction/utxo.js"; +/** + * A **BlockTag** specifies a specific block. + * + * **numeric value** - specifies the block height, where + * the genesis block is block 0; many operations accept a negative + * value which indicates the block number should be deducted from + * the most recent block. A numeric value may be a ``number``, ``bigint``, + * or a decimal of hex string. + * + * **blockhash** - specifies a specific block by its blockhash; this allows + * potentially orphaned blocks to be specifed, without ambiguity, but many + * backends do not support this for some operations. + */ +export type BlockTag = BigNumberish | string; +import { BlockParams, LogParams, TransactionReceiptParams, TransactionResponseParams } from "./formatting.js"; +/** + * A **FeeData** wraps all the fee-related values associated with + * the network. + */ +export declare class FeeData { + /** + * The gas price for legacy networks. + */ + readonly gasPrice: null | bigint; + /** + * The maximum fee to pay per gas. + * + * The base fee per gas is defined by the network and based on + * congestion, increasing the cost during times of heavy load + * and lowering when less busy. + * + * The actual fee per gas will be the base fee for the block + * and the priority fee, up to the max fee per gas. + * + * This will be ``null`` on legacy networks (i.e. [pre-EIP-1559](link-eip-1559)) + */ + readonly maxFeePerGas: null | bigint; + /** + * The additional amout to pay per gas to encourage a validator + * to include the transaction. + * + * The purpose of this is to compensate the validator for the + * adjusted risk for including a given transaction. + * + * This will be ``null`` on legacy networks (i.e. [pre-EIP-1559](link-eip-1559)) + */ + readonly maxPriorityFeePerGas: null | bigint; + /** + * Creates a new FeeData for %%gasPrice%%, %%maxFeePerGas%% and + * %%maxPriorityFeePerGas%%. + */ + constructor(gasPrice?: null | bigint, maxFeePerGas?: null | bigint, maxPriorityFeePerGas?: null | bigint); + /** + * Returns a JSON-friendly value. + */ + toJSON(): any; +} +/** + * A **TransactionRequest** is a transactions with potentially various + * properties not defined, or with less strict types for its values. + * + * This is used to pass to various operations, which will internally + * coerce any types and populate any necessary values. + */ +export interface TransactionRequest { + /** + * The transaction type. + */ + type?: null | number; + /** + * The target of the transaction. + */ + to?: null | AddressLike; + /** + * The sender of the transaction. + */ + from: AddressLike; + /** + * The nonce of the transaction, used to prevent replay attacks. + */ + nonce?: null | number; + /** + * The maximum amount of gas to allow this transaction to consime. + */ + gasLimit?: null | BigNumberish; + /** + * The gas price to use for legacy transactions or transactions on + * legacy networks. + * + * Most of the time the ``max*FeePerGas`` is preferred. + */ + gasPrice?: null | BigNumberish; + /** + * The [[link-eip-1559]] maximum priority fee to pay per gas. + */ + maxPriorityFeePerGas?: null | BigNumberish; + /** + * The [[link-eip-1559]] maximum total fee to pay per gas. The actual + * value used is protocol enforced to be the block's base fee. + */ + maxFeePerGas?: null | BigNumberish; + /** + * The transaction data. + */ + data?: null | string; + /** + * The transaction value (in wei). + */ + value?: null | BigNumberish; + /** + * The chain ID for the network this transaction is valid on. + */ + chainId?: null | BigNumberish; + /** + * The [[link-eip-2930]] access list. Storage slots included in the access + * list are //warmed// by pre-loading them, so their initial cost to + * fetch is guaranteed, but then each additional access is cheaper. + */ + accessList?: null | AccessListish; + /** + * A custom object, which can be passed along for network-specific + * values. + */ + customData?: any; + /** + * When using ``call`` or ``estimateGas``, this allows a specific + * block to be queried. Many backends do not support this and when + * unsupported errors are silently squelched and ``"latest"`` is used. + */ + blockTag?: BlockTag; + inputs?: null | Array; + outputs?: null | Array; +} +/** + * A **PreparedTransactionRequest** is identical to a [[TransactionRequest]] + * except all the property types are strictly enforced. + */ +export interface PreparedTransactionRequest { + /** + * The transaction type. + */ + type?: number; + /** + * The target of the transaction. + */ + to?: AddressLike; + /** + * The sender of the transaction. + */ + from: AddressLike; + /** + * The nonce of the transaction, used to prevent replay attacks. + */ + nonce?: number; + /** + * The maximum amount of gas to allow this transaction to consime. + */ + gasLimit?: bigint; + /** + * The gas price to use for legacy transactions or transactions on + * legacy networks. + * + * Most of the time the ``max*FeePerGas`` is preferred. + */ + gasPrice?: bigint; + /** + * The [[link-eip-1559]] maximum priority fee to pay per gas. + */ + maxPriorityFeePerGas?: bigint; + /** + * The [[link-eip-1559]] maximum total fee to pay per gas. The actual + * value used is protocol enforced to be the block's base fee. + */ + maxFeePerGas?: bigint; + /** + * The transaction data. + */ + data?: string; + /** + * The transaction value (in wei). + */ + value?: bigint; + /** + * The chain ID for the network this transaction is valid on. + */ + chainId?: bigint; + /** + * The [[link-eip-2930]] access list. Storage slots included in the access + * list are //warmed// by pre-loading them, so their initial cost to + * fetch is guaranteed, but then each additional access is cheaper. + */ + accessList?: AccessList; + /** + * A custom object, which can be passed along for network-specific + * values. + */ + customData?: any; + /** + * When using ``call`` or ``estimateGas``, this allows a specific + * block to be queried. Many backends do not support this and when + * unsupported errors are silently squelched and ``"latest"`` is used. + */ + blockTag?: BlockTag; + inputs?: null | Array; + outputs?: null | Array; +} +/** + * Returns a copy of %%req%% with all properties coerced to their strict + * types. + */ +export declare function copyRequest(req: TransactionRequest): PreparedTransactionRequest; +/** + * An Interface to indicate a [[Block]] has been included in the + * blockchain. This asserts a Type Guard that necessary properties + * are non-null. + * + * Before a block is included, it is a //pending// block. + */ +export interface MinedBlock extends Block { + /** + * The block number also known as the block height. + */ + readonly number: number; + /** + * The block hash. + */ + readonly hash: string; + /** + * The block timestamp, in seconds from epoch. + */ + readonly timestamp: number; + /** + * The block date, created from the [[timestamp]]. + */ + readonly date: Date; + /** + * The miner of the block, also known as the ``author`` or + * block ``producer``. + */ + readonly miner: string; +} +/** + * A **Block** represents the data associated with a full block on + * Ethereum. + */ +export declare class Block implements BlockParams, Iterable { + #private; + /** + * The provider connected to the block used to fetch additional details + * if necessary. + */ + readonly provider: Provider; + /** + * The block number, sometimes called the block height. This is a + * sequential number that is one higher than the parent block. + */ + readonly number: Array | number; + /** + * The block hash. + * + * This hash includes all properties, so can be safely used to identify + * an exact set of block properties. + */ + readonly hash: null | string; + /** + * The timestamp for this block, which is the number of seconds since + * epoch that this block was included. + */ + readonly timestamp: number; + /** + * The block hash of the parent block. + */ + readonly parentHash: Array | string; + /** + * The nonce. + * + * On legacy networks, this is the random number inserted which + * permitted the difficulty target to be reached. + */ + readonly nonce: string; + /** + * The difficulty target. + * + * On legacy networks, this is the proof-of-work target required + * for a block to meet the protocol rules to be included. + * + * On modern networks, this is a random number arrived at using + * randao. @TODO: Find links? + */ + readonly difficulty: bigint; + /** + * The total gas limit for this block. + */ + readonly gasLimit: bigint; + /** + * The total gas used in this block. + */ + readonly gasUsed: bigint; + /** + * The miner coinbase address, wihch receives any subsidies for + * including this block. + */ + readonly miner: string; + /** + * Any extra data the validator wished to include. + */ + readonly extraData: string; + /** + * The base fee per gas that all transactions in this block were + * charged. + * + * This adjusts after each block, depending on how congested the network + * is. + */ + readonly baseFeePerGas: null | bigint; + readonly manifestHash: Array; + readonly location: bigint; + readonly parentDeltaS: Array; + readonly parentEntropy: Array; + readonly order: number; + readonly subManifest: Array | null; + readonly totalEntropy: bigint; + readonly mixHash: string; + readonly receiptsRoot: string; + readonly sha3Uncles: string; + readonly size: bigint; + readonly evmRoot: string; + readonly utxoRoot: string; + readonly uncles: Array | null; + readonly transactionsRoot: string; + readonly extRollupRoot: string; + readonly extTransactionsRoot: string; + /** + * Create a new **Block** object. + * + * This should generally not be necessary as the unless implementing a + * low-level library. + */ + constructor(block: BlockParams, provider: Provider); + /** + * Returns the list of transaction hashes, in the order + * they were executed within the block. + */ + get transactions(): ReadonlyArray; + get extTransactions(): ReadonlyArray; + /** + * Returns the complete transactions, in the order they + * were executed within the block. + * + * This is only available for blocks which prefetched + * transactions, by passing ``true`` to %%prefetchTxs%% + * into [[Provider-getBlock]]. + */ + get prefetchedTransactions(): Array; + get prefetchedExtTransactions(): Array; + /** + * Returns a JSON-friendly value. + */ + toJSON(): any; + [Symbol.iterator](): Iterator; + /** + * The number of transactions in this block. + */ + get length(): number; + /** + * The [[link-js-date]] this block was included at. + */ + get date(): null | Date; + /** + * Get the transaction at %%indexe%% within this block. + */ + getTransaction(indexOrHash: number | string): Promise; + getExtTransaction(indexOrHash: number | string): Promise; + /** + * If a **Block** was fetched with a request to include the transactions + * this will allow synchronous access to those transactions. + * + * If the transactions were not prefetched, this will throw. + */ + getPrefetchedTransaction(indexOrHash: number | string): TransactionResponse; + /** + * Returns true if this block been mined. This provides a type guard + * for all properties on a [[MinedBlock]]. + */ + isMined(): this is MinedBlock; + /** + * @_ignore: + */ + orphanedEvent(): OrphanFilter; +} +/** + * A **Log** in Ethereum represents an event that has been included in a + * transaction using the ``LOG*`` opcodes, which are most commonly used by + * Solidity's emit for announcing events. + */ +export declare class Log implements LogParams { + /** + * The provider connected to the log used to fetch additional details + * if necessary. + */ + readonly provider: Provider; + /** + * The transaction hash of the transaction this log occurred in. Use the + * [[Log-getTransaction]] to get the [[TransactionResponse]]. + */ + readonly transactionHash: string; + /** + * The block hash of the block this log occurred in. Use the + * [[Log-getBlock]] to get the [[Block]]. + */ + readonly blockHash: string; + /** + * The block number of the block this log occurred in. It is preferred + * to use the [[Block-hash]] when fetching the related [[Block]], + * since in the case of an orphaned block, the block at that height may + * have changed. + */ + readonly blockNumber: number; + /** + * If the **Log** represents a block that was removed due to an orphaned + * block, this will be true. + * + * This can only happen within an orphan event listener. + */ + readonly removed: boolean; + /** + * The address of the contract that emitted this log. + */ + readonly address: string; + /** + * The data included in this log when it was emitted. + */ + readonly data: string; + /** + * The indexed topics included in this log when it was emitted. + * + * All topics are included in the bloom filters, so they can be + * efficiently filtered using the [[Provider-getLogs]] method. + */ + readonly topics: ReadonlyArray; + /** + * The index within the block this log occurred at. This is generally + * not useful to developers, but can be used with the various roots + * to proof inclusion within a block. + */ + readonly index: number; + /** + * The index within the transaction of this log. + */ + readonly transactionIndex: number; + /** + * @_ignore: + */ + constructor(log: LogParams, provider: Provider); + /** + * Returns a JSON-compatible object. + */ + toJSON(): any; + /** + * Returns the block that this log occurred in. + */ + getBlock(shard: string): Promise; + /** + * Returns the transaction that this log occurred in. + */ + getTransaction(): Promise; + /** + * Returns the transaction receipt fot the transaction that this + * log occurred in. + */ + getTransactionReceipt(): Promise; + /** + * @_ignore: + */ + removedEvent(): OrphanFilter; +} +export declare function shardFromHash(hash: string): string; +/** + * A **TransactionReceipt** includes additional information about a + * transaction that is only available after it has been mined. + */ +export declare class TransactionReceipt implements TransactionReceiptParams, Iterable { + #private; + /** + * The provider connected to the log used to fetch additional details + * if necessary. + */ + readonly provider: Provider; + /** + * The address the transaction was sent to. + */ + readonly to: null | string; + /** + * The sender of the transaction. + */ + readonly from: string; + /** + * The address of the contract if the transaction was directly + * responsible for deploying one. + * + * This is non-null **only** if the ``to`` is empty and the ``data`` + * was successfully executed as initcode. + */ + readonly contractAddress: null | string; + /** + * The transaction hash. + */ + readonly hash: string; + /** + * The index of this transaction within the block transactions. + */ + readonly index: number; + /** + * The block hash of the [[Block]] this transaction was included in. + */ + readonly blockHash: string; + /** + * The block number of the [[Block]] this transaction was included in. + */ + readonly blockNumber: number; + /** + * The bloom filter bytes that represent all logs that occurred within + * this transaction. This is generally not useful for most developers, + * but can be used to validate the included logs. + */ + readonly logsBloom: string; + /** + * The actual amount of gas used by this transaction. + * + * When creating a transaction, the amount of gas that will be used can + * only be approximated, but the sender must pay the gas fee for the + * entire gas limit. After the transaction, the difference is refunded. + */ + readonly gasUsed: bigint; + /** + * The amount of gas used by all transactions within the block for this + * and all transactions with a lower ``index``. + * + * This is generally not useful for developers but can be used to + * validate certain aspects of execution. + */ + readonly cumulativeGasUsed: bigint; + /** + * The actual gas price used during execution. + * + * Due to the complexity of [[link-eip-1559]] this value can only + * be caluclated after the transaction has been mined, snce the base + * fee is protocol-enforced. + */ + readonly gasPrice: bigint; + /** + * The [[link-eip-2718]] transaction type. + */ + readonly type: number; + /** + * The status of this transaction, indicating success (i.e. ``1``) or + * a revert (i.e. ``0``). + * + * This is available in post-byzantium blocks, but some backends may + * backfill this value. + */ + readonly status: null | number; + readonly etxs: ReadonlyArray; + /** + * @_ignore: + */ + constructor(tx: TransactionReceiptParams, provider: Provider); + /** + * The logs for this transaction. + */ + get logs(): ReadonlyArray; + /** + * Returns a JSON-compatible representation. + */ + toJSON(): any; + /** + * @_ignore: + */ + get length(): number; + [Symbol.iterator](): Iterator; + /** + * The total fee for this transaction, in wei. + */ + get fee(): bigint; + /** + * Resolves to the block this transaction occurred in. + */ + getBlock(shard: string): Promise; + /** + * Resolves to the transaction this transaction occurred in. + */ + getTransaction(): Promise; + /** + * Resolves to the return value of the execution of this transaction. + * + * Support for this feature is limited, as it requires an archive node + * with the ``debug_`` or ``trace_`` API enabled. + */ + getResult(): Promise; + /** + * Resolves to the number of confirmations this transaction has. + */ + confirmations(): Promise; + /** + * @_ignore: + */ + removedEvent(): OrphanFilter; + /** + * @_ignore: + */ + reorderedEvent(other?: TransactionResponse): OrphanFilter; +} +/** + * A **MinedTransactionResponse** is an interface representing a + * transaction which has been mined and allows for a type guard for its + * property values being defined. + */ +export interface MinedTransactionResponse extends TransactionResponse { + /** + * The block number this transaction occurred in. + */ + blockNumber: number; + /** + * The block hash this transaction occurred in. + */ + blockHash: string; + /** + * The date this transaction occurred on. + */ + date: Date; +} +/** + * A **TransactionResponse** includes all properties about a transaction + * that was sent to the network, which may or may not be included in a + * block. + * + * The [[TransactionResponse-isMined]] can be used to check if the + * transaction has been mined as well as type guard that the otherwise + * possibly ``null`` properties are defined. + */ +export declare class TransactionResponse implements TransactionLike, TransactionResponseParams { + #private; + /** + * The provider this is connected to, which will influence how its + * methods will resolve its async inspection methods. + */ + readonly provider: Provider; + /** + * The block number of the block that this transaction was included in. + * + * This is ``null`` for pending transactions. + */ + readonly blockNumber: null | number; + /** + * The blockHash of the block that this transaction was included in. + * + * This is ``null`` for pending transactions. + */ + readonly blockHash: null | string; + /** + * The index within the block that this transaction resides at. + */ + readonly index: bigint; + /** + * The transaction hash. + */ + readonly hash: string; + /** + * The [[link-eip-2718]] transaction envelope type. This is + * ``0`` for legacy transactions types. + */ + readonly type: number; + /** + * The receiver of this transaction. + * + * If ``null``, then the transaction is an initcode transaction. + * This means the result of executing the [[data]] will be deployed + * as a new contract on chain (assuming it does not revert) and the + * address may be computed using [[getCreateAddress]]. + */ + readonly to: null | string; + /** + * The sender of this transaction. It is implicitly computed + * from the transaction pre-image hash (as the digest) and the + * [[signature]] using ecrecover. + */ + readonly from: string; + /** + * The nonce, which is used to prevent replay attacks and offer + * a method to ensure transactions from a given sender are explicitly + * ordered. + * + * When sending a transaction, this must be equal to the number of + * transactions ever sent by [[from]]. + */ + readonly nonce: number; + /** + * The maximum units of gas this transaction can consume. If execution + * exceeds this, the entries transaction is reverted and the sender + * is charged for the full amount, despite not state changes being made. + */ + readonly gasLimit: bigint; + /** + * The maximum priority fee (per unit of gas) to allow a + * validator to charge the sender. This is inclusive of the + * [[maxFeeFeePerGas]]. + */ + readonly maxPriorityFeePerGas: null | bigint; + /** + * The maximum fee (per unit of gas) to allow this transaction + * to charge the sender. + */ + readonly maxFeePerGas: null | bigint; + /** + * The data. + */ + readonly data: string; + /** + * The value, in wei. Use [[formatEther]] to format this value + * as ether. + */ + readonly value: bigint; + /** + * The chain ID. + */ + readonly chainId: bigint; + /** + * The signature. + */ + readonly signature: Signature; + /** + * The [[link-eip-2930]] access list for transaction types that + * support it, otherwise ``null``. + */ + readonly accessList: null | AccessList; + readonly inputs?: Array; + readonly outputs?: Array; + /** + * @_ignore: + */ + constructor(tx: TransactionResponseParams, provider: Provider); + /** + * Returns a JSON-compatible representation of this transaction. + */ + toJSON(): any; + /** + * Resolves to the Block that this transaction was included in. + * + * This will return null if the transaction has not been included yet. + */ + getBlock(shard: string): Promise; + /** + * Resolves to this transaction being re-requested from the + * provider. This can be used if you have an unmined transaction + * and wish to get an up-to-date populated instance. + */ + getTransaction(): Promise; + /** + * Resolve to the number of confirmations this transaction has. + */ + confirmations(): Promise; + /** + * Resolves once this transaction has been mined and has + * %%confirms%% blocks including it (default: ``1``) with an + * optional %%timeout%%. + * + * This can resolve to ``null`` only if %%confirms%% is ``0`` + * and the transaction has not been mined, otherwise this will + * wait until enough confirmations have completed. + */ + wait(_confirms?: number, _timeout?: number): Promise; + /** + * Returns ``true`` if this transaction has been included. + * + * This is effective only as of the time the TransactionResponse + * was instantiated. To get up-to-date information, use + * [[getTransaction]]. + * + * This provides a Type Guard that this transaction will have + * non-null property values for properties that are null for + * unmined transactions. + */ + isMined(): this is MinedTransactionResponse; + /** + * Returns a filter which can be used to listen for orphan events + * that evict this transaction. + */ + removedEvent(): OrphanFilter; + /** + * Returns a filter which can be used to listen for orphan events + * that re-order this event against %%other%%. + */ + reorderedEvent(other?: TransactionResponse): OrphanFilter; + /** + * Returns a new TransactionResponse instance which has the ability to + * detect (and throw an error) if the transaction is replaced, which + * will begin scanning at %%startBlock%%. + * + * This should generally not be used by developers and is intended + * primarily for internal use. Setting an incorrect %%startBlock%% can + * have devastating performance consequences if used incorrectly. + */ + replaceableTransaction(startBlock: number): TransactionResponse; +} +/** + * An Orphan Filter allows detecting when an orphan block has + * resulted in dropping a block or transaction or has resulted + * in transactions changing order. + * + * Not currently fully supported. + */ +export type OrphanFilter = { + orphan: "drop-block"; + hash: string; + number: number; +} | { + orphan: "drop-transaction"; + tx: { + hash: string; + blockHash: string; + blockNumber: number; + }; + other?: { + hash: string; + blockHash: string; + blockNumber: number; + }; +} | { + orphan: "reorder-transaction"; + tx: { + hash: string; + blockHash: string; + blockNumber: number; + }; + other?: { + hash: string; + blockHash: string; + blockNumber: number; + }; +} | { + orphan: "drop-log"; + log: { + transactionHash: string; + blockHash: string; + blockNumber: number; + address: string; + data: string; + topics: ReadonlyArray; + index: number; + }; +}; +/** + * A **TopicFilter** provides a struture to define bloom-filter + * queries. + * + * Each field that is ``null`` matches **any** value, a field that is + * a ``string`` must match exactly that value and and ``array`` is + * effectively an ``OR``-ed set, where any one of those values must + * match. + */ +export type TopicFilter = Array>; +/** + * An **EventFilter** allows efficiently filtering logs (also known as + * events) using bloom filters included within blocks. + */ +export interface EventFilter { + address?: AddressLike | Array; + topics?: TopicFilter; +} +/** + * A **Filter** allows searching a specific range of blocks for mathcing + * logs. + */ +export interface Filter extends EventFilter { + /** + * The start block for the filter (inclusive). + */ + fromBlock?: BlockTag; + /** + * The end block for the filter (inclusive). + */ + toBlock?: BlockTag; + shard: string; +} +/** + * A **FilterByBlockHash** allows searching a specific block for mathcing + * logs. + */ +export interface FilterByBlockHash extends EventFilter { + /** + * The blockhash of the specific block for the filter. + */ + blockHash?: string; + shard: string; +} +/** + * A **ProviderEvent** provides the types of events that can be subscribed + * to on a [[Provider]]. + * + * Each provider may include additional possible events it supports, but + * the most commonly supported are: + * + * **``"block"``** - calls the listener with the current block number on each + * new block. + * + * **``"error"``** - calls the listener on each async error that occurs during + * the event loop, with the error. + * + * **``"debug"``** - calls the listener on debug events, which can be used to + * troubleshoot network errors, provider problems, etc. + * + * **``transaction hash``** - calls the listener on each block after the + * transaction has been mined; generally ``.once`` is more appropriate for + * this event. + * + * **``Array``** - calls the listener on each log that matches the filter. + * + * [[EventFilter]] - calls the listener with each matching log + */ +export type ProviderEvent = string | Array> | EventFilter | OrphanFilter; +/** + * A **Provider** is the primary method to interact with the read-only + * content on Ethereum. + * + * It allows access to details about accounts, blocks and transactions + * and the ability to query event logs and simulate contract execution. + * + * Account data includes the [balance](getBalance), + * [transaction count](getTransactionCount), [code](getCode) and + * [state trie storage](getStorage). + * + * Simulating execution can be used to [call](call), + * [estimate gas](estimateGas) and + * [get transaction results](getTransactionResult). + * + * The [[broadcastTransaction]] is the only method which allows updating + * the blockchain, but it is usually accessed by a [[Signer]], since a + * private key must be used to sign the transaction before it can be + * broadcast. + */ +export interface Provider extends ContractRunner, EventEmitterable { + /** + * The provider iteself. + * + * This is part of the necessary API for executing a contract, as + * it provides a common property on any [[ContractRunner]] that + * can be used to access the read-only portion of the runner. + */ + provider: this; + /** + * Shutdown any resources this provider is using. No additional + * calls should be made to this provider after calling this. + */ + destroy(): void; + /** + * Get the current block number. + */ + getBlockNumber(shard: string): Promise; + /** + * Get the connected [[Network]]. + */ + getNetwork(shard?: string): Promise; + /** + * Get the best guess at the recommended [[FeeData]]. + */ + getFeeData(shard: string): Promise; + /** + * Get the account balance (in wei) of %%address%%. If %%blockTag%% + * is specified and the node supports archive access for that + * %%blockTag%%, the balance is as of that [[BlockTag]]. + * + * @note On nodes without archive access enabled, the %%blockTag%% may be + * **silently ignored** by the node, which may cause issues if relied on. + */ + getBalance(address: AddressLike, blockTag?: BlockTag): Promise; + /** + * Get the number of transactions ever sent for %%address%%, which + * is used as the ``nonce`` when sending a transaction. If + * %%blockTag%% is specified and the node supports archive access + * for that %%blockTag%%, the transaction count is as of that + * [[BlockTag]]. + * + * @note On nodes without archive access enabled, the %%blockTag%% may be + * **silently ignored** by the node, which may cause issues if relied on. + */ + getTransactionCount(address: AddressLike, blockTag?: BlockTag): Promise; + /** + * Get the bytecode for %%address%%. + * + * @note On nodes without archive access enabled, the %%blockTag%% may be + * **silently ignored** by the node, which may cause issues if relied on. + */ + getCode(address: AddressLike, blockTag?: BlockTag): Promise; + /** + * Get the storage slot value for %%address%% at slot %%position%%. + * + * @note On nodes without archive access enabled, the %%blockTag%% may be + * **silently ignored** by the node, which may cause issues if relied on. + */ + getStorage(address: AddressLike, position: BigNumberish, blockTag?: BlockTag): Promise; + /** + * Estimates the amount of gas required to executre %%tx%%. + */ + estimateGas(tx: TransactionRequest): Promise; + /** + * Simulate the execution of %%tx%%. If the call reverts, it will + * throw a [[CallExceptionError]] which includes the revert data. + */ + call(tx: TransactionRequest): Promise; + /** + * Broadcasts the %%signedTx%% to the network, adding it to the + * memory pool of any node for which the transaction meets the + * rebroadcast requirements. + */ + broadcastTransaction(shard: string, signedTx: string): Promise; + /** + * Resolves to the block for %%blockHashOrBlockTag%%. + * + * If %%prefetchTxs%%, and the backend supports including transactions + * with block requests, all transactions will be included and the + * [[Block]] object will not need to make remote calls for getting + * transactions. + */ + getBlock(shard: string, blockHashOrBlockTag: BlockTag | string, prefetchTxs?: boolean): Promise; + /** + * Resolves to the transaction for %%hash%%. + * + * If the transaction is unknown or on pruning nodes which + * discard old transactions this resolves to ``null``. + */ + getTransaction(hash: string): Promise; + /** + * Resolves to the transaction receipt for %%hash%%, if mined. + * + * If the transaction has not been mined, is unknown or on + * pruning nodes which discard old transactions this resolves to + * ``null``. + */ + getTransactionReceipt(hash: string): Promise; + /** + * Resolves to the result returned by the executions of %%hash%%. + * + * This is only supported on nodes with archive access and with + * the necessary debug APIs enabled. + */ + getTransactionResult(hash: string): Promise; + /** + * Resolves to the list of Logs that match %%filter%% + */ + getLogs(filter: Filter | FilterByBlockHash): Promise>; + /** + * Waits until the transaction %%hash%% is mined and has %%confirms%% + * confirmations. + */ + waitForTransaction(hash: string, confirms?: number, timeout?: number): Promise; + /** + * Resolves to the block at %%blockTag%% once it has been mined. + * + * This can be useful for waiting some number of blocks by using + * the ``currentBlockNumber + N``. + */ + waitForBlock(shard: string, blockTag?: BlockTag): Promise; + /** + * Resolves to the number indicating the size of the network + */ + getProtocolExpansionNumber(): Promise; +} +//# sourceMappingURL=provider.d.ts.map \ No newline at end of file diff --git a/lib.esm/providers/provider.d.ts.map b/lib.esm/providers/provider.d.ts.map new file mode 100644 index 00000000..72c50680 --- /dev/null +++ b/lib.esm/providers/provider.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src.ts/providers/provider.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE1F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAI/E;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,QAAQ,GAAG,YAAY,GAAG,MAAM,CAAC;AAE7C,OAAO,EACH,WAAW,EAAE,SAAS,EAAE,wBAAwB,EAChD,yBAAyB,EAC5B,MAAM,iBAAiB,CAAC;AAgBzB;;;GAGG;AACH,qBAAa,OA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,KAAK,CAAC,CAAC;IAE9G;;;;;OAKG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,mBAAmB,CAAC,CAAC;IAElE;;;;;;OAMG;IACH,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,kBAAkB,CAAC,CAAC;IAExE;;;;;OAKG;IACH,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,MAAM,CAAC,CAAC;IAM3D;;OAEG;IACH,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,iBAAiB,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;IAEjE;;;OAGG;IACH,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,kBAAkB,CAAC,CAAC;IAE1G;;;;;OAKG;IACH,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;IAEjE;;OAEG;IACH,0BAA0B,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CACjD"} \ No newline at end of file diff --git a/lib.esm/providers/provider.js b/lib.esm/providers/provider.js new file mode 100644 index 00000000..5bd64412 --- /dev/null +++ b/lib.esm/providers/provider.js @@ -0,0 +1,1291 @@ +//import { resolveAddress } from "@quaisproject/address"; +import { defineProperties, getBigInt, getNumber, hexlify, resolveProperties, assert, assertArgument, isError, makeError } from "../utils/index.js"; +import { accessListify } from "../transaction/index.js"; +const BN_0 = BigInt(0); +// ----------------------- +function getValue(value) { + if (value == null) { + return null; + } + return value; +} +function toJson(value) { + if (value == null) { + return null; + } + return value.toString(); +} +// @TODO? implements Required +/** + * A **FeeData** wraps all the fee-related values associated with + * the network. + */ +export class FeeData { + /** + * The gas price for legacy networks. + */ + gasPrice; + /** + * The maximum fee to pay per gas. + * + * The base fee per gas is defined by the network and based on + * congestion, increasing the cost during times of heavy load + * and lowering when less busy. + * + * The actual fee per gas will be the base fee for the block + * and the priority fee, up to the max fee per gas. + * + * This will be ``null`` on legacy networks (i.e. [pre-EIP-1559](link-eip-1559)) + */ + maxFeePerGas; + /** + * The additional amout to pay per gas to encourage a validator + * to include the transaction. + * + * The purpose of this is to compensate the validator for the + * adjusted risk for including a given transaction. + * + * This will be ``null`` on legacy networks (i.e. [pre-EIP-1559](link-eip-1559)) + */ + maxPriorityFeePerGas; + /** + * Creates a new FeeData for %%gasPrice%%, %%maxFeePerGas%% and + * %%maxPriorityFeePerGas%%. + */ + constructor(gasPrice, maxFeePerGas, maxPriorityFeePerGas) { + defineProperties(this, { + gasPrice: getValue(gasPrice), + maxFeePerGas: getValue(maxFeePerGas), + maxPriorityFeePerGas: getValue(maxPriorityFeePerGas) + }); + } + /** + * Returns a JSON-friendly value. + */ + toJSON() { + const { gasPrice, maxFeePerGas, maxPriorityFeePerGas } = this; + return { + _type: "FeeData", + gasPrice: toJson(gasPrice), + maxFeePerGas: toJson(maxFeePerGas), + maxPriorityFeePerGas: toJson(maxPriorityFeePerGas), + }; + } +} +; +/** + * Returns a copy of %%req%% with all properties coerced to their strict + * types. + */ +export function copyRequest(req) { + const result = {}; + // These could be addresses, ENS names or Addressables + if (req.to) { + result.to = req.to; + } + if (req.from) { + result.from = req.from; + } + if (req.data) { + result.data = hexlify(req.data); + } + const bigIntKeys = "chainId,gasLimit,gasPrice,maxFeePerGas,maxPriorityFeePerGas,value".split(/,/); + for (const key of bigIntKeys) { + if (!(key in req) || req[key] == null) { + continue; + } + result[key] = getBigInt(req[key], `request.${key}`); + } + const numberKeys = "type,nonce".split(/,/); + for (const key of numberKeys) { + if (!(key in req) || req[key] == null) { + continue; + } + result[key] = getNumber(req[key], `request.${key}`); + } + if (req.accessList) { + result.accessList = accessListify(req.accessList); + } + if ("blockTag" in req) { + result.blockTag = req.blockTag; + } + if ("enableCcipRead" in req) { + result.enableCcipRead = !!req.enableCcipRead; + } + if ("customData" in req) { + result.customData = req.customData; + } + return result; +} +/** + * A **Block** represents the data associated with a full block on + * Ethereum. + */ +export class Block { + /** + * The provider connected to the block used to fetch additional details + * if necessary. + */ + provider; + /** + * The block number, sometimes called the block height. This is a + * sequential number that is one higher than the parent block. + */ + number; + /** + * The block hash. + * + * This hash includes all properties, so can be safely used to identify + * an exact set of block properties. + */ + hash; + /** + * The timestamp for this block, which is the number of seconds since + * epoch that this block was included. + */ + timestamp; + /** + * The block hash of the parent block. + */ + parentHash; + /** + * The nonce. + * + * On legacy networks, this is the random number inserted which + * permitted the difficulty target to be reached. + */ + nonce; + /** + * The difficulty target. + * + * On legacy networks, this is the proof-of-work target required + * for a block to meet the protocol rules to be included. + * + * On modern networks, this is a random number arrived at using + * randao. @TODO: Find links? + */ + difficulty; + /** + * The total gas limit for this block. + */ + gasLimit; + /** + * The total gas used in this block. + */ + gasUsed; + /** + * The miner coinbase address, wihch receives any subsidies for + * including this block. + */ + miner; + /** + * Any extra data the validator wished to include. + */ + extraData; + /** + * The base fee per gas that all transactions in this block were + * charged. + * + * This adjusts after each block, depending on how congested the network + * is. + */ + baseFeePerGas; + manifestHash; + location; + parentDeltaS; + parentEntropy; + order; + subManifest; + totalEntropy; + mixHash; + receiptsRoot; + sha3Uncles; + size; + evmRoot; + utxoRoot; + uncles; + #transactions; + transactionsRoot; + extRollupRoot; + #extTransactions; + extTransactionsRoot; + /** + * Create a new **Block** object. + * + * This should generally not be necessary as the unless implementing a + * low-level library. + */ + constructor(block, provider) { + this.#transactions = block.transactions.map((tx) => { + if (typeof (tx) !== "string") { + return new TransactionResponse(tx, provider); + } + return tx; + }); + this.#extTransactions = block.extTransactions.map((tx) => { + if (typeof (tx) !== "string") { + return new TransactionResponse(tx, provider); + } + return tx; + }); + this.transactionsRoot = block.transactionsRoot; + this.extRollupRoot = block.extRollupRoot; + this.extTransactionsRoot = block.extTransactionsRoot; + defineProperties(this, { + provider, + hash: getValue(block.hash), + number: block.number, + timestamp: block.timestamp, + parentHash: block.parentHash, + nonce: block.nonce, + difficulty: block.difficulty, + gasLimit: block.gasLimit, + gasUsed: block.gasUsed, + miner: block.miner, + extraData: block.extraData, + baseFeePerGas: getValue(block.baseFeePerGas), + manifestHash: block.manifestHash, + location: block.location, + parentDeltaS: block.parentDeltaS, + parentEntropy: block.parentEntropy, + order: block.order, + subManifest: block.subManifest, + totalEntropy: block.totalEntropy, + mixHash: block.mixHash, + receiptsRoot: block.receiptsRoot, + sha3Uncles: block.sha3Uncles, + size: block.size, + evmRoot: block.evmRoot, + utxoRoot: block.utxoRoot, + uncles: block.uncles, + transactionsRoot: block.transactionsRoot, + extRollupRoot: block.extRollupRoot, + extTransactionsRoot: block.extTransactionsRoot, + }); + } + /** + * Returns the list of transaction hashes, in the order + * they were executed within the block. + */ + get transactions() { + return this.#transactions.map((tx) => { + if (typeof (tx) === "string") { + return tx; + } + return tx.hash; + }); + } + get extTransactions() { + return this.#extTransactions.map((tx) => { + if (typeof (tx) === "string") { + return tx; + } + return tx.hash; + }); + } + /** + * Returns the complete transactions, in the order they + * were executed within the block. + * + * This is only available for blocks which prefetched + * transactions, by passing ``true`` to %%prefetchTxs%% + * into [[Provider-getBlock]]. + */ + get prefetchedTransactions() { + const txs = this.#transactions.slice(); + // Doesn't matter... + if (txs.length === 0) { + return []; + } + // Make sure we prefetched the transactions + assert(typeof (txs[0]) === "object", "transactions were not prefetched with block request", "UNSUPPORTED_OPERATION", { + operation: "transactionResponses()" + }); + return txs; + } + get prefetchedExtTransactions() { + const txs = this.#extTransactions.slice(); + // Doesn't matter... + if (txs.length === 0) { + return []; + } + // Make sure we prefetched the transactions + assert(typeof (txs[0]) === "object", "transactions were not prefetched with block request", "UNSUPPORTED_OPERATION", { + operation: "transactionResponses()" + }); + return txs; + } + /** + * Returns a JSON-friendly value. + */ + toJSON() { + const { baseFeePerGas, difficulty, extraData, gasLimit, gasUsed, hash, miner, nonce, number, parentHash, timestamp, manifestHash, location, parentDeltaS, parentEntropy, order, subManifest, totalEntropy, mixHash, receiptsRoot, sha3Uncles, size, evmRoot, utxoRoot, uncles, transactionsRoot, extRollupRoot, extTransactionsRoot } = this; + // Using getters to retrieve the transactions and extTransactions + const transactions = this.transactions; + const extTransactions = this.extTransactions; + return { + _type: "Block", + baseFeePerGas: toJson(baseFeePerGas), + difficulty: toJson(difficulty), + extraData, + gasLimit: toJson(gasLimit), + gasUsed: toJson(gasUsed), + hash, + miner, + nonce, + number, + parentHash, + timestamp, + manifestHash, + location, + parentDeltaS, + parentEntropy, + order, + subManifest, + totalEntropy, + mixHash, + receiptsRoot, + sha3Uncles, + size, + evmRoot, + utxoRoot, + uncles, + transactionsRoot, + extRollupRoot, + extTransactionsRoot, + transactions, + extTransactions // Includes the extended transaction hashes or full transactions based on the prefetched data + }; + } + [Symbol.iterator]() { + let index = 0; + const txs = this.transactions; + return { + next: () => { + if (index < this.length) { + return { + value: txs[index++], done: false + }; + } + return { value: undefined, done: true }; + } + }; + } + /** + * The number of transactions in this block. + */ + get length() { return this.#transactions.length; } + /** + * The [[link-js-date]] this block was included at. + */ + get date() { + if (this.timestamp == null) { + return null; + } + return new Date(this.timestamp * 1000); + } + /** + * Get the transaction at %%indexe%% within this block. + */ + async getTransaction(indexOrHash) { + // Find the internal value by its index or hash + let tx = undefined; + if (typeof (indexOrHash) === "number") { + tx = this.#transactions[indexOrHash]; + } + else { + const hash = indexOrHash.toLowerCase(); + for (const v of this.#transactions) { + if (typeof (v) === "string") { + if (v !== hash) { + continue; + } + tx = v; + break; + } + else { + if (v.hash === hash) { + continue; + } + tx = v; + break; + } + } + } + if (tx == null) { + throw new Error("no such tx"); + } + if (typeof (tx) === "string") { + return (await this.provider.getTransaction(tx)); + } + else { + return tx; + } + } + async getExtTransaction(indexOrHash) { + // Find the internal value by its index or hash + let tx = undefined; + if (typeof (indexOrHash) === "number") { + tx = this.#extTransactions[indexOrHash]; + } + else { + const hash = indexOrHash.toLowerCase(); + for (const v of this.#extTransactions) { + if (typeof (v) === "string") { + if (v !== hash) { + continue; + } + tx = v; + break; + } + else { + if (v.hash === hash) { + continue; + } + tx = v; + break; + } + } + } + if (tx == null) { + throw new Error("no such tx"); + } + if (typeof (tx) === "string") { + return (await this.provider.getTransaction(tx)); + } + else { + return tx; + } + } + /** + * If a **Block** was fetched with a request to include the transactions + * this will allow synchronous access to those transactions. + * + * If the transactions were not prefetched, this will throw. + */ + getPrefetchedTransaction(indexOrHash) { + const txs = this.prefetchedTransactions; + if (typeof (indexOrHash) === "number") { + return txs[indexOrHash]; + } + indexOrHash = indexOrHash.toLowerCase(); + for (const tx of txs) { + if (tx.hash === indexOrHash) { + return tx; + } + } + assertArgument(false, "no matching transaction", "indexOrHash", indexOrHash); + } + /** + * Returns true if this block been mined. This provides a type guard + * for all properties on a [[MinedBlock]]. + */ + isMined() { return !!this.hash; } + /** + * @_ignore: + */ + orphanedEvent() { + if (!this.isMined()) { + throw new Error(""); + } + return createOrphanedBlockFilter(this); + } +} +////////////////////// +// Log +/** + * A **Log** in Ethereum represents an event that has been included in a + * transaction using the ``LOG*`` opcodes, which are most commonly used by + * Solidity's emit for announcing events. + */ +export class Log { + /** + * The provider connected to the log used to fetch additional details + * if necessary. + */ + provider; + /** + * The transaction hash of the transaction this log occurred in. Use the + * [[Log-getTransaction]] to get the [[TransactionResponse]]. + */ + transactionHash; + /** + * The block hash of the block this log occurred in. Use the + * [[Log-getBlock]] to get the [[Block]]. + */ + blockHash; + /** + * The block number of the block this log occurred in. It is preferred + * to use the [[Block-hash]] when fetching the related [[Block]], + * since in the case of an orphaned block, the block at that height may + * have changed. + */ + blockNumber; + /** + * If the **Log** represents a block that was removed due to an orphaned + * block, this will be true. + * + * This can only happen within an orphan event listener. + */ + removed; + /** + * The address of the contract that emitted this log. + */ + address; + /** + * The data included in this log when it was emitted. + */ + data; + /** + * The indexed topics included in this log when it was emitted. + * + * All topics are included in the bloom filters, so they can be + * efficiently filtered using the [[Provider-getLogs]] method. + */ + topics; + /** + * The index within the block this log occurred at. This is generally + * not useful to developers, but can be used with the various roots + * to proof inclusion within a block. + */ + index; + /** + * The index within the transaction of this log. + */ + transactionIndex; + /** + * @_ignore: + */ + constructor(log, provider) { + this.provider = provider; + const topics = Object.freeze(log.topics.slice()); + defineProperties(this, { + transactionHash: log.transactionHash, + blockHash: log.blockHash, + blockNumber: log.blockNumber, + removed: log.removed, + address: log.address, + data: log.data, + topics, + index: log.index, + transactionIndex: log.transactionIndex, + }); + } + /** + * Returns a JSON-compatible object. + */ + toJSON() { + const { address, blockHash, blockNumber, data, index, removed, topics, transactionHash, transactionIndex } = this; + return { + _type: "log", + address, blockHash, blockNumber, data, index, + removed, topics, transactionHash, transactionIndex + }; + } + /** + * Returns the block that this log occurred in. + */ + async getBlock(shard) { + const block = await this.provider.getBlock(shard, this.blockHash); + assert(!!block, "failed to find transaction", "UNKNOWN_ERROR", {}); + return block; + } + /** + * Returns the transaction that this log occurred in. + */ + async getTransaction() { + const tx = await this.provider.getTransaction(this.transactionHash); + assert(!!tx, "failed to find transaction", "UNKNOWN_ERROR", {}); + return tx; + } + /** + * Returns the transaction receipt fot the transaction that this + * log occurred in. + */ + async getTransactionReceipt() { + const receipt = await this.provider.getTransactionReceipt(this.transactionHash); + assert(!!receipt, "failed to find transaction receipt", "UNKNOWN_ERROR", {}); + return receipt; + } + /** + * @_ignore: + */ + removedEvent() { + return createRemovedLogFilter(this); + } +} +////////////////////// +// Transaction Receipt +export function shardFromHash(hash) { + return hash.slice(0, 4); +} +/** + * A **TransactionReceipt** includes additional information about a + * transaction that is only available after it has been mined. + */ +export class TransactionReceipt { + /** + * The provider connected to the log used to fetch additional details + * if necessary. + */ + provider; + /** + * The address the transaction was sent to. + */ + to; + /** + * The sender of the transaction. + */ + from; + /** + * The address of the contract if the transaction was directly + * responsible for deploying one. + * + * This is non-null **only** if the ``to`` is empty and the ``data`` + * was successfully executed as initcode. + */ + contractAddress; + /** + * The transaction hash. + */ + hash; + /** + * The index of this transaction within the block transactions. + */ + index; + /** + * The block hash of the [[Block]] this transaction was included in. + */ + blockHash; + /** + * The block number of the [[Block]] this transaction was included in. + */ + blockNumber; + /** + * The bloom filter bytes that represent all logs that occurred within + * this transaction. This is generally not useful for most developers, + * but can be used to validate the included logs. + */ + logsBloom; + /** + * The actual amount of gas used by this transaction. + * + * When creating a transaction, the amount of gas that will be used can + * only be approximated, but the sender must pay the gas fee for the + * entire gas limit. After the transaction, the difference is refunded. + */ + gasUsed; + /** + * The amount of gas used by all transactions within the block for this + * and all transactions with a lower ``index``. + * + * This is generally not useful for developers but can be used to + * validate certain aspects of execution. + */ + cumulativeGasUsed; + /** + * The actual gas price used during execution. + * + * Due to the complexity of [[link-eip-1559]] this value can only + * be caluclated after the transaction has been mined, snce the base + * fee is protocol-enforced. + */ + gasPrice; + /** + * The [[link-eip-2718]] transaction type. + */ + type; + //readonly byzantium!: boolean; + /** + * The status of this transaction, indicating success (i.e. ``1``) or + * a revert (i.e. ``0``). + * + * This is available in post-byzantium blocks, but some backends may + * backfill this value. + */ + status; + /** + * The root hash of this transaction. + * + * This is no present and was only included in pre-byzantium blocks, but + * could be used to validate certain parts of the receipt. + */ + #logs; + etxs; + /** + * @_ignore: + */ + constructor(tx, provider) { + this.#logs = Object.freeze(tx.logs.map((log) => { + return new Log(log, provider); + })); + let gasPrice = BN_0; + if (tx.effectiveGasPrice != null) { + gasPrice = tx.effectiveGasPrice; + } + else if (tx.gasPrice != null) { + gasPrice = tx.gasPrice; + } + defineProperties(this, { + provider, + to: tx.to, + from: tx.from, + contractAddress: tx.contractAddress, + hash: tx.hash, + index: tx.index, + blockHash: tx.blockHash, + blockNumber: tx.blockNumber, + logsBloom: tx.logsBloom, + gasUsed: tx.gasUsed, + cumulativeGasUsed: tx.cumulativeGasUsed, + gasPrice, + etxs: tx.etxs, + type: tx.type, + //byzantium: tx.byzantium, + status: tx.status, + }); + } + /** + * The logs for this transaction. + */ + get logs() { return this.#logs; } + /** + * Returns a JSON-compatible representation. + */ + toJSON() { + const { to, from, contractAddress, hash, index, blockHash, blockNumber, logsBloom, logs, //byzantium, + status } = this; + return { + _type: "TransactionReceipt", + blockHash, blockNumber, + //byzantium, + contractAddress, + cumulativeGasUsed: toJson(this.cumulativeGasUsed), + from, + gasPrice: toJson(this.gasPrice), + gasUsed: toJson(this.gasUsed), + hash, index, logs, logsBloom, status, to + }; + } + /** + * @_ignore: + */ + get length() { return this.logs.length; } + [Symbol.iterator]() { + let index = 0; + return { + next: () => { + if (index < this.length) { + return { value: this.logs[index++], done: false }; + } + return { value: undefined, done: true }; + } + }; + } + /** + * The total fee for this transaction, in wei. + */ + get fee() { + return this.gasUsed * this.gasPrice; + } + /** + * Resolves to the block this transaction occurred in. + */ + async getBlock(shard) { + const block = await this.provider.getBlock(shard, this.blockHash); + if (block == null) { + throw new Error("TODO"); + } + return block; + } + /** + * Resolves to the transaction this transaction occurred in. + */ + async getTransaction() { + const tx = await this.provider.getTransaction(this.hash); + if (tx == null) { + throw new Error("TODO"); + } + return tx; + } + /** + * Resolves to the return value of the execution of this transaction. + * + * Support for this feature is limited, as it requires an archive node + * with the ``debug_`` or ``trace_`` API enabled. + */ + async getResult() { + return (await this.provider.getTransactionResult(this.hash)); + } + /** + * Resolves to the number of confirmations this transaction has. + */ + async confirmations() { + const shard = shardFromHash(this.hash); + return (await this.provider.getBlockNumber(shard)) - this.blockNumber + 1; + } + /** + * @_ignore: + */ + removedEvent() { + return createRemovedTransactionFilter(this); + } + /** + * @_ignore: + */ + reorderedEvent(other) { + assert(!other || other.isMined(), "unmined 'other' transction cannot be orphaned", "UNSUPPORTED_OPERATION", { operation: "reorderedEvent(other)" }); + return createReorderedTransactionFilter(this, other); + } +} +/** + * A **TransactionResponse** includes all properties about a transaction + * that was sent to the network, which may or may not be included in a + * block. + * + * The [[TransactionResponse-isMined]] can be used to check if the + * transaction has been mined as well as type guard that the otherwise + * possibly ``null`` properties are defined. + */ +export class TransactionResponse { + /** + * The provider this is connected to, which will influence how its + * methods will resolve its async inspection methods. + */ + provider; + /** + * The block number of the block that this transaction was included in. + * + * This is ``null`` for pending transactions. + */ + blockNumber; + /** + * The blockHash of the block that this transaction was included in. + * + * This is ``null`` for pending transactions. + */ + blockHash; + /** + * The index within the block that this transaction resides at. + */ + index; + /** + * The transaction hash. + */ + hash; + /** + * The [[link-eip-2718]] transaction envelope type. This is + * ``0`` for legacy transactions types. + */ + type; + /** + * The receiver of this transaction. + * + * If ``null``, then the transaction is an initcode transaction. + * This means the result of executing the [[data]] will be deployed + * as a new contract on chain (assuming it does not revert) and the + * address may be computed using [[getCreateAddress]]. + */ + to; + /** + * The sender of this transaction. It is implicitly computed + * from the transaction pre-image hash (as the digest) and the + * [[signature]] using ecrecover. + */ + from; + /** + * The nonce, which is used to prevent replay attacks and offer + * a method to ensure transactions from a given sender are explicitly + * ordered. + * + * When sending a transaction, this must be equal to the number of + * transactions ever sent by [[from]]. + */ + nonce; + /** + * The maximum units of gas this transaction can consume. If execution + * exceeds this, the entries transaction is reverted and the sender + * is charged for the full amount, despite not state changes being made. + */ + gasLimit; + /** + * The maximum priority fee (per unit of gas) to allow a + * validator to charge the sender. This is inclusive of the + * [[maxFeeFeePerGas]]. + */ + maxPriorityFeePerGas; + /** + * The maximum fee (per unit of gas) to allow this transaction + * to charge the sender. + */ + maxFeePerGas; + /** + * The data. + */ + data; + /** + * The value, in wei. Use [[formatEther]] to format this value + * as ether. + */ + value; + /** + * The chain ID. + */ + chainId; + /** + * The signature. + */ + signature; + /** + * The [[link-eip-2930]] access list for transaction types that + * support it, otherwise ``null``. + */ + accessList; + inputs; + outputs; + #startBlock; + /** + * @_ignore: + */ + constructor(tx, provider) { + this.provider = provider; + this.blockNumber = (tx.blockNumber != null) ? tx.blockNumber : null; + this.blockHash = (tx.blockHash != null) ? tx.blockHash : null; + this.hash = tx.hash; + this.index = tx.index; + this.type = tx.type; + this.from = tx.from; + this.to = tx.to || null; + this.gasLimit = tx.gasLimit; + this.nonce = tx.nonce; + this.data = tx.data; + this.value = tx.value; + this.maxPriorityFeePerGas = (tx.maxPriorityFeePerGas != null) ? tx.maxPriorityFeePerGas : null; + this.maxFeePerGas = (tx.maxFeePerGas != null) ? tx.maxFeePerGas : null; + this.chainId = tx.chainId; + this.signature = tx.signature; + this.accessList = (tx.accessList != null) ? tx.accessList : null; + this.#startBlock = -1; + } + /** + * Returns a JSON-compatible representation of this transaction. + */ + toJSON() { + const { blockNumber, blockHash, index, hash, type, to, from, nonce, data, signature, accessList, } = this; + let result = { + _type: "TransactionReceipt", + accessList, blockNumber, blockHash, + chainId: toJson(this.chainId), + data, from, + gasLimit: toJson(this.gasLimit), + hash, + maxFeePerGas: toJson(this.maxFeePerGas), + maxPriorityFeePerGas: toJson(this.maxPriorityFeePerGas), + nonce, signature, to, index, type, + value: toJson(this.value), + }; + return result; + } + /** + * Resolves to the Block that this transaction was included in. + * + * This will return null if the transaction has not been included yet. + */ + async getBlock(shard) { + let blockNumber = this.blockNumber; + if (blockNumber == null) { + const tx = await this.getTransaction(); + if (tx) { + blockNumber = tx.blockNumber; + } + } + if (blockNumber == null) { + return null; + } + const block = this.provider.getBlock(shard, blockNumber); + if (block == null) { + throw new Error("TODO"); + } + return block; + } + /** + * Resolves to this transaction being re-requested from the + * provider. This can be used if you have an unmined transaction + * and wish to get an up-to-date populated instance. + */ + async getTransaction() { + return this.provider.getTransaction(this.hash); + } + /** + * Resolve to the number of confirmations this transaction has. + */ + async confirmations() { + const shard = shardFromHash(this.hash); + if (this.blockNumber == null) { + const { tx, blockNumber } = await resolveProperties({ + tx: this.getTransaction(), + blockNumber: this.provider.getBlockNumber(shard) + }); + // Not mined yet... + if (tx == null || tx.blockNumber == null) { + return 0; + } + return blockNumber - tx.blockNumber + 1; + } + const blockNumber = await this.provider.getBlockNumber(shard); + return blockNumber - this.blockNumber + 1; + } + /** + * Resolves once this transaction has been mined and has + * %%confirms%% blocks including it (default: ``1``) with an + * optional %%timeout%%. + * + * This can resolve to ``null`` only if %%confirms%% is ``0`` + * and the transaction has not been mined, otherwise this will + * wait until enough confirmations have completed. + */ + async wait(_confirms, _timeout) { + const confirms = (_confirms == null) ? 1 : _confirms; + const timeout = (_timeout == null) ? 0 : _timeout; + let startBlock = this.#startBlock; + let nextScan = -1; + let stopScanning = (startBlock === -1) ? true : false; + const shard = shardFromHash(this.hash); + const checkReplacement = async () => { + // Get the current transaction count for this sender + if (stopScanning) { + return null; + } + const { blockNumber, nonce } = await resolveProperties({ + blockNumber: this.provider.getBlockNumber(shard), + nonce: this.provider.getTransactionCount(this.from) + }); + // No transaction or our nonce has not been mined yet; but we + // can start scanning later when we do start + if (nonce < this.nonce) { + startBlock = blockNumber; + return; + } + // We were mined; no replacement + if (stopScanning) { + return null; + } + const mined = await this.getTransaction(); + if (mined && mined.blockNumber != null) { + return; + } + // We were replaced; start scanning for that transaction + // Starting to scan; look back a few extra blocks for safety + if (nextScan === -1) { + nextScan = startBlock - 3; + if (nextScan < this.#startBlock) { + nextScan = this.#startBlock; + } + } + while (nextScan <= blockNumber) { + // Get the next block to scan + if (stopScanning) { + return null; + } + const block = await this.provider.getBlock(shard, nextScan, true); + // This should not happen; but we'll try again shortly + if (block == null) { + return; + } + // We were mined; no replacement + for (const hash of block) { + if (hash === this.hash) { + return; + } + } + // Search for the transaction that replaced us + for (let i = 0; i < block.length; i++) { + const tx = await block.getTransaction(i); + if (tx.from === this.from && tx.nonce === this.nonce) { + // Get the receipt + if (stopScanning) { + return null; + } + const receipt = await this.provider.getTransactionReceipt(tx.hash); + // This should not happen; but we'll try again shortly + if (receipt == null) { + return; + } + // We will retry this on the next block (this case could be optimized) + if ((blockNumber - receipt.blockNumber + 1) < confirms) { + return; + } + // The reason we were replaced + let reason = "replaced"; + if (tx.data === this.data && tx.to === this.to && tx.value === this.value) { + reason = "repriced"; + } + else if (tx.data === "0x" && tx.from === tx.to && tx.value === BN_0) { + reason = "cancelled"; + } + assert(false, "transaction was replaced", "TRANSACTION_REPLACED", { + cancelled: (reason === "replaced" || reason === "cancelled"), + reason, + replacement: tx.replaceableTransaction(startBlock), + hash: tx.hash, + receipt + }); + } + } + nextScan++; + } + return; + }; + const checkReceipt = (receipt) => { + if (receipt == null || receipt.status !== 0) { + return receipt; + } + assert(false, "transaction execution reverted", "CALL_EXCEPTION", { + action: "sendTransaction", + data: null, reason: null, invocation: null, revert: null, + transaction: { + to: receipt.to, + from: receipt.from, + data: "" // @TODO: in v7, split out sendTransaction properties + }, receipt + }); + }; + const receipt = await this.provider.getTransactionReceipt(this.hash); + if (confirms === 0) { + return checkReceipt(receipt); + } + if (receipt) { + if ((await receipt.confirmations()) >= confirms) { + return checkReceipt(receipt); + } + } + else { + // Check for a replacement; throws if a replacement was found + await checkReplacement(); + // Allow null only when the confirms is 0 + if (confirms === 0) { + return null; + } + } + const waiter = new Promise((resolve, reject) => { + // List of things to cancel when we have a result (one way or the other) + const cancellers = []; + const cancel = () => { cancellers.forEach((c) => c()); }; + // On cancel, stop scanning for replacements + cancellers.push(() => { stopScanning = true; }); + // Set up any timeout requested + if (timeout > 0) { + const timer = setTimeout(() => { + cancel(); + reject(makeError("wait for transaction timeout", "TIMEOUT")); + }, timeout); + cancellers.push(() => { clearTimeout(timer); }); + } + const txListener = async (receipt) => { + // Done; return it! + if ((await receipt.confirmations()) >= confirms) { + cancel(); + try { + resolve(checkReceipt(receipt)); + } + catch (error) { + reject(error); + } + } + }; + cancellers.push(() => { this.provider.off(this.hash, txListener); }); + this.provider.on(this.hash, txListener); + // We support replacement detection; start checking + if (startBlock >= 0) { + const replaceListener = async () => { + try { + // Check for a replacement; this throws only if one is found + await checkReplacement(); + } + catch (error) { + // We were replaced (with enough confirms); re-throw the error + if (isError(error, "TRANSACTION_REPLACED")) { + cancel(); + reject(error); + return; + } + } + // Rescheudle a check on the next block + if (!stopScanning) { + this.provider.once("block", replaceListener); + } + }; + cancellers.push(() => { this.provider.off("block", replaceListener); }); + this.provider.once("block", replaceListener); + } + }); + return await waiter; + } + /** + * Returns ``true`` if this transaction has been included. + * + * This is effective only as of the time the TransactionResponse + * was instantiated. To get up-to-date information, use + * [[getTransaction]]. + * + * This provides a Type Guard that this transaction will have + * non-null property values for properties that are null for + * unmined transactions. + */ + isMined() { + return (this.blockHash != null); + } + /** + * Returns a filter which can be used to listen for orphan events + * that evict this transaction. + */ + removedEvent() { + assert(this.isMined(), "unmined transaction canot be orphaned", "UNSUPPORTED_OPERATION", { operation: "removeEvent()" }); + return createRemovedTransactionFilter(this); + } + /** + * Returns a filter which can be used to listen for orphan events + * that re-order this event against %%other%%. + */ + reorderedEvent(other) { + assert(this.isMined(), "unmined transaction canot be orphaned", "UNSUPPORTED_OPERATION", { operation: "removeEvent()" }); + assert(!other || other.isMined(), "unmined 'other' transaction canot be orphaned", "UNSUPPORTED_OPERATION", { operation: "removeEvent()" }); + return createReorderedTransactionFilter(this, other); + } + /** + * Returns a new TransactionResponse instance which has the ability to + * detect (and throw an error) if the transaction is replaced, which + * will begin scanning at %%startBlock%%. + * + * This should generally not be used by developers and is intended + * primarily for internal use. Setting an incorrect %%startBlock%% can + * have devastating performance consequences if used incorrectly. + */ + replaceableTransaction(startBlock) { + assertArgument(Number.isInteger(startBlock) && startBlock >= 0, "invalid startBlock", "startBlock", startBlock); + const tx = new TransactionResponse(this, this.provider); + tx.#startBlock = startBlock; + return tx; + } +} +function createOrphanedBlockFilter(block) { + return { orphan: "drop-block", hash: block.hash, number: block.number }; +} +function createReorderedTransactionFilter(tx, other) { + return { orphan: "reorder-transaction", tx, other }; +} +function createRemovedTransactionFilter(tx) { + return { orphan: "drop-transaction", tx }; +} +function createRemovedLogFilter(log) { + return { orphan: "drop-log", log: { + transactionHash: log.transactionHash, + blockHash: log.blockHash, + blockNumber: log.blockNumber, + address: log.address, + data: log.data, + topics: Object.freeze(log.topics.slice()), + index: log.index + } }; +} +//# sourceMappingURL=provider.js.map \ No newline at end of file diff --git a/lib.esm/providers/provider.js.map b/lib.esm/providers/provider.js.map new file mode 100644 index 00000000..ec5e0e07 --- /dev/null +++ b/lib.esm/providers/provider.js.map @@ -0,0 +1 @@ +{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src.ts/providers/provider.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,OAAO,EACH,gBAAgB,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,iBAAiB,EAClE,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,SAAS,EAC7C,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAWxD,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;AAsBvB,0BAA0B;AAE1B,SAAS,QAAQ,CAAI,KAA2B;IAC5C,IAAI,KAAK,IAAI,IAAI,EAAE;QAAE,OAAO,IAAI,CAAC;KAAE;IACnC,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,SAAS,MAAM,CAAC,KAAoB;IAChC,IAAI,KAAK,IAAI,IAAI,EAAE;QAAE,OAAO,IAAI,CAAC;KAAE;IACnC,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;AAC5B,CAAC;AAED,0DAA0D;AAE1D;;;GAGG;AACH,MAAM,OAAO,OAAO;IAChB;;OAEG;IACM,QAAQ,CAAiB;IAElC;;;;;;;;;;;OAWG;IACM,YAAY,CAAiB;IAEtC;;;;;;;;OAQG;IACM,oBAAoB,CAAiB;IAE9C;;;OAGG;IACH,YAAY,QAAwB,EAAE,YAA4B,EAAE,oBAAoC;QACpG,gBAAgB,CAAU,IAAI,EAAE;YAC5B,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC;YAC5B,YAAY,EAAE,QAAQ,CAAC,YAAY,CAAC;YACpC,oBAAoB,EAAE,QAAQ,CAAC,oBAAoB,CAAC;SACvD,CAAC,CAAC;IACP,CAAC;IAED;;OAEG;IACH,MAAM;QACF,MAAM,EACF,QAAQ,EAAE,YAAY,EAAE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AAE,YAAY,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC;AAC5E,CAAC;AAED,SAAS,gCAAgC,CAAC,EAA4D,EAAE,KAAgE;IACpK,OAAO,EAAE,MAAM,EAAE,qBAAqB,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC;AACxD,CAAC;AAED,SAAS,8BAA8B,CAAC,EAA4D;IAChG,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,EAAE,EAAE,CAAC;AAC9C,CAAC;AAED,SAAS,sBAAsB,CAAC,GAAqJ;IACjL,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE;YAC9B,eAAe,EAAE,GAAG,CAAC,eAAe;YACpC,SAAS,EAAE,GAAG,CAAC,SAAS;YACxB,WAAW,EAAE,GAAG,CAAC,WAAW;YAC5B,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;YACzC,KAAK,EAAE,GAAG,CAAC,KAAK;SACnB,EAAE,CAAC;AACR,CAAC"} \ No newline at end of file diff --git a/lib.esm/providers/signer-noncemanager.d.ts b/lib.esm/providers/signer-noncemanager.d.ts new file mode 100644 index 00000000..4224b601 --- /dev/null +++ b/lib.esm/providers/signer-noncemanager.d.ts @@ -0,0 +1,38 @@ +import { AbstractSigner } from "./abstract-signer.js"; +import type { TypedDataDomain, TypedDataField } from "../hash/index.js"; +import type { BlockTag, Provider, TransactionRequest, TransactionResponse } from "./provider.js"; +import type { Signer } from "./signer.js"; +/** + * A **NonceManager** wraps another [[Signer]] and automatically manages + * the nonce, ensuring serialized and sequential nonces are used during + * transaction. + */ +export declare class NonceManager extends AbstractSigner { + #private; + /** + * The Signer being managed. + */ + signer: Signer; + /** + * Creates a new **NonceManager** to manage %%signer%%. + */ + constructor(signer: Signer); + getAddress(): Promise; + connect(provider: null | Provider): NonceManager; + getNonce(blockTag?: BlockTag): Promise; + /** + * Manually increment the nonce. This may be useful when managng + * offline transactions. + */ + increment(): void; + /** + * Resets the nonce, causing the **NonceManager** to reload the current + * nonce from the blockchain on the next transaction. + */ + reset(): void; + sendTransaction(tx: TransactionRequest): Promise; + signTransaction(tx: TransactionRequest): Promise; + signMessage(message: string | Uint8Array): Promise; + signTypedData(domain: TypedDataDomain, types: Record>, value: Record): Promise; +} +//# sourceMappingURL=signer-noncemanager.d.ts.map \ No newline at end of file diff --git a/lib.esm/providers/signer-noncemanager.d.ts.map b/lib.esm/providers/signer-noncemanager.d.ts.map new file mode 100644 index 00000000..7142ec44 --- /dev/null +++ b/lib.esm/providers/signer-noncemanager.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"signer-noncemanager.d.ts","sourceRoot":"","sources":["../../src.ts/providers/signer-noncemanager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAExE,OAAO,KAAK,EACR,QAAQ,EAAE,QAAQ,EAAE,kBAAkB,EAAE,mBAAmB,EAC9D,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAG1C;;;;GAIG;AACH,qBAAa,YAAa,SAAQ,cAAc;;IAC5C;;OAEG;IACH,MAAM,EAAG,MAAM,CAAC;IAKhB;;OAEG;gBACS,MAAM,EAAE,MAAM;IAQpB,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAInC,OAAO,CAAC,QAAQ,EAAE,IAAI,GAAG,QAAQ,GAAG,YAAY;IAI1C,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC;IAapD;;;OAGG;IACH,SAAS,IAAI,IAAI;IAIjB;;;OAGG;IACH,KAAK,IAAI,IAAI;IAKP,eAAe,CAAC,EAAE,EAAE,kBAAkB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAY3E,eAAe,CAAC,EAAE,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC;IAIxD,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC;IAI1D,aAAa,CAAC,MAAM,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;CAGpI"} \ No newline at end of file diff --git a/lib.esm/providers/signer-noncemanager.js b/lib.esm/providers/signer-noncemanager.js new file mode 100644 index 00000000..710e8f4a --- /dev/null +++ b/lib.esm/providers/signer-noncemanager.js @@ -0,0 +1,74 @@ +import { defineProperties } from "../utils/index.js"; +import { AbstractSigner } from "./abstract-signer.js"; +/** + * A **NonceManager** wraps another [[Signer]] and automatically manages + * the nonce, ensuring serialized and sequential nonces are used during + * transaction. + */ +export class NonceManager extends AbstractSigner { + /** + * The Signer being managed. + */ + signer; + #noncePromise; + #delta; + /** + * Creates a new **NonceManager** to manage %%signer%%. + */ + constructor(signer) { + super(signer.provider); + defineProperties(this, { signer }); + this.#noncePromise = null; + this.#delta = 0; + } + async getAddress() { + return this.signer.getAddress(); + } + connect(provider) { + return new NonceManager(this.signer.connect(provider)); + } + async getNonce(blockTag) { + if (blockTag === "pending") { + if (this.#noncePromise == null) { + this.#noncePromise = super.getNonce("pending"); + } + const delta = this.#delta; + return (await this.#noncePromise) + delta; + } + return super.getNonce(blockTag); + } + /** + * Manually increment the nonce. This may be useful when managng + * offline transactions. + */ + increment() { + this.#delta++; + } + /** + * Resets the nonce, causing the **NonceManager** to reload the current + * nonce from the blockchain on the next transaction. + */ + reset() { + this.#delta = 0; + this.#noncePromise = null; + } + async sendTransaction(tx) { + const noncePromise = this.getNonce("pending"); + this.increment(); + tx = await this.signer.populateTransaction(tx); + tx.nonce = await noncePromise; + // @TODO: Maybe handle interesting/recoverable errors? + // Like don't increment if the tx was certainly not sent + return await this.signer.sendTransaction(tx); + } + signTransaction(tx) { + return this.signer.signTransaction(tx); + } + signMessage(message) { + return this.signer.signMessage(message); + } + signTypedData(domain, types, value) { + return this.signer.signTypedData(domain, types, value); + } +} +//# sourceMappingURL=signer-noncemanager.js.map \ No newline at end of file diff --git a/lib.esm/providers/signer-noncemanager.js.map b/lib.esm/providers/signer-noncemanager.js.map new file mode 100644 index 00000000..c2d71528 --- /dev/null +++ b/lib.esm/providers/signer-noncemanager.js.map @@ -0,0 +1 @@ +{"version":3,"file":"signer-noncemanager.js","sourceRoot":"","sources":["../../src.ts/providers/signer-noncemanager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAUtD;;;;GAIG;AACH,MAAM,OAAO,YAAa,SAAQ,cAAc;IAC5C;;OAEG;IACH,MAAM,CAAU;IAEhB,aAAa,CAAyB;IACtC,MAAM,CAAS;IAEf;;OAEG;IACH,YAAY,MAAc;QACtB,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACvB,gBAAgB,CAAe,IAAI,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;QAEjD,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;QAC1B,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;IACpB,CAAC;IAED,KAAK,CAAC,UAAU;QACZ,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;IACpC,CAAC;IAED,OAAO,CAAC,QAAyB;QAC7B,OAAO,IAAI,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC3D,CAAC;IA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G,OAAO,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IAC3D,CAAC;CACJ"} \ No newline at end of file diff --git a/lib.esm/providers/signer.d.ts b/lib.esm/providers/signer.d.ts new file mode 100644 index 00000000..10638c18 --- /dev/null +++ b/lib.esm/providers/signer.d.ts @@ -0,0 +1,114 @@ +import type { Addressable } from "../address/index.js"; +import type { TypedDataDomain, TypedDataField } from "../hash/index.js"; +import type { TransactionLike } from "../transaction/index.js"; +import type { ContractRunner } from "./contracts.js"; +import type { BlockTag, Provider, TransactionRequest, TransactionResponse } from "./provider.js"; +/** + * A Signer represents an account on the Ethereum Blockchain, and is most often + * backed by a private key represented by a mnemonic or residing on a Hardware Wallet. + * + * The API remains abstract though, so that it can deal with more advanced exotic + * Signing entities, such as Smart Contract Wallets or Virtual Wallets (where the + * private key may not be known). + */ +export interface Signer extends Addressable, ContractRunner { + /** + * The [[Provider]] attached to this Signer (if any). + */ + provider: null | Provider; + /** + * Returns a new instance of this Signer connected to //provider// or detached + * from any Provider if null. + */ + connect(provider: null | Provider): Signer; + /** + * Get the address of the Signer. + */ + getAddress(): Promise; + /** + * Gets the next nonce required for this Signer to send a transaction. + * + * @param blockTag - The blocktag to base the transaction count on, keep in mind + * many nodes do not honour this value and silently ignore it [default: ``"latest"``] + */ + getNonce(blockTag?: BlockTag): Promise; + /** + * Prepares a {@link TransactionRequest} for calling: + * - resolves ``to`` and ``from`` addresses + * - if ``from`` is specified , check that it matches this Signer + * + * @param tx - The call to prepare + */ + populateCall(tx: TransactionRequest): Promise>; + /** + * Prepares a {@link TransactionRequest} for sending to the network by + * populating any missing properties: + * - resolves ``to`` and ``from`` addresses + * - if ``from`` is specified , check that it matches this Signer + * - populates ``nonce`` via ``signer.getNonce("pending")`` + * - populates ``gasLimit`` via ``signer.estimateGas(tx)`` + * - populates ``chainId`` via ``signer.provider.getNetwork()`` + * - populates ``type`` and relevant fee data for that type (``gasPrice`` + * for legacy transactions, ``maxFeePerGas`` for EIP-1559, etc) + * + * @note Some Signer implementations may skip populating properties that + * are populated downstream; for example JsonRpcSigner defers to the + * node to populate the nonce and fee data. + * + * @param tx - The call to prepare + */ + populateTransaction(tx: TransactionRequest): Promise>; + /** + * Estimates the required gas required to execute //tx// on the Blockchain. This + * will be the expected amount a transaction will require as its ``gasLimit`` + * to successfully run all the necessary computations and store the needed state + * that the transaction intends. + * + * Keep in mind that this is **best efforts**, since the state of the Blockchain + * is in flux, which could affect transaction gas requirements. + * + * @throws UNPREDICTABLE_GAS_LIMIT A transaction that is believed by the node to likely + * fail will throw an error during gas estimation. This could indicate that it + * will actually fail or that the circumstances are simply too complex for the + * node to take into account. In these cases, a manually determined ``gasLimit`` + * will need to be made. + */ + estimateGas(tx: TransactionRequest): Promise; + /** + * Evaluates the //tx// by running it against the current Blockchain state. This + * cannot change state and has no cost in ether, as it is effectively simulating + * execution. + * + * This can be used to have the Blockchain perform computations based on its state + * (e.g. running a Contract's getters) or to simulate the effect of a transaction + * before actually performing an operation. + */ + call(tx: TransactionRequest): Promise; + /** + * Signs %%tx%%, returning the fully signed transaction. This does not + * populate any additional properties within the transaction. + */ + signTransaction(tx: TransactionRequest): Promise; + /** + * Sends %%tx%% to the Network. The ``signer.populateTransaction(tx)`` + * is called first to ensure all necessary properties for the + * transaction to be valid have been popualted first. + */ + sendTransaction(tx: TransactionRequest): Promise; + /** + * Signs an [[link-eip-191]] prefixed personal message. + * + * If the %%message%% is a string, it is signed as UTF-8 encoded bytes. It is **not** + * interpretted as a [[BytesLike]]; so the string ``"0x1234"`` is signed as six + * characters, **not** two bytes. + * + * To sign that example as two bytes, the Uint8Array should be used + * (i.e. ``new Uint8Array([ 0x12, 0x34 ])``). + */ + signMessage(message: string | Uint8Array): Promise; + /** + * Signs the [[link-eip-712]] typed data. + */ + signTypedData(domain: TypedDataDomain, types: Record>, value: Record): Promise; +} +//# sourceMappingURL=signer.d.ts.map \ No newline at end of file diff --git a/lib.esm/providers/signer.d.ts.map b/lib.esm/providers/signer.d.ts.map new file mode 100644 index 00000000..0ce0e397 --- /dev/null +++ b/lib.esm/providers/signer.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../../src.ts/providers/signer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEjG;;;;;;;GAOG;AACH,MAAM,WAAW,MAAO,SAAQ,WAAW,EAAE,cAAc;IAEvD;;OAEG;IACH,QAAQ,EAAE,IAAI,GAAG,QAAQ,CAAC;IAE1B;;;OAGG;IACH,OAAO,CAAC,QAAQ,EAAE,IAAI,GAAG,QAAQ,GAAG,MAAM,CAAC;IAM3C;;OAEG;IACH,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAE9B;;;;;OAKG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAM/C;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,EAAE,kBAAkB,GAAG,OAAO,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC;IAEvE;;;;;;;;;;;;;;;;OAgBG;IACH,mBAAmB,CAAC,EAAE,EAAE,kBAAkB,GAAG,OAAO,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC;IAM9E;;;;;;;;;;;;;;OAcG;IACH,WAAW,CAAC,EAAE,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAErD;;;;;;;;OAQG;IACH,IAAI,CAAC,EAAE,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAK9C;;;OAGG;IACH,eAAe,CAAC,EAAE,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEzD;;;;OAIG;IACH,eAAe,CAAC,EAAE,EAAE,kBAAkB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAEtE;;;;;;;;;OASG;IACH,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAE3D;;OAEG;IACH,aAAa,CAAC,MAAM,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACrI"} \ No newline at end of file diff --git a/lib.esm/providers/signer.js b/lib.esm/providers/signer.js new file mode 100644 index 00000000..7c8f9901 --- /dev/null +++ b/lib.esm/providers/signer.js @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=signer.js.map \ No newline at end of file diff --git a/lib.esm/providers/signer.js.map b/lib.esm/providers/signer.js.map new file mode 100644 index 00000000..68d48a83 --- /dev/null +++ b/lib.esm/providers/signer.js.map @@ -0,0 +1 @@ +{"version":3,"file":"signer.js","sourceRoot":"","sources":["../../src.ts/providers/signer.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/lib.esm/providers/subscriber-connection.d.ts b/lib.esm/providers/subscriber-connection.d.ts new file mode 100644 index 00000000..b235e3b4 --- /dev/null +++ b/lib.esm/providers/subscriber-connection.d.ts @@ -0,0 +1,25 @@ +import type { Subscriber } from "./abstract-provider.js"; +import type { Provider } from "./provider.js"; +/** + * @TODO + * + * @_docloc: api/providers/abstract-provider + */ +export interface ConnectionRpcProvider extends Provider { + _subscribe(param: Array, processFunc: (result: any) => void): number; + _unsubscribe(filterId: number): void; +} +/** + * @TODO + * + * @_docloc: api/providers/abstract-provider + */ +export declare class BlockConnectionSubscriber implements Subscriber { + #private; + constructor(provider: ConnectionRpcProvider); + start(): void; + stop(): void; + pause(dropWhilePaused?: boolean): void; + resume(): void; +} +//# sourceMappingURL=subscriber-connection.d.ts.map \ No newline at end of file diff --git a/lib.esm/providers/subscriber-connection.d.ts.map b/lib.esm/providers/subscriber-connection.d.ts.map new file mode 100644 index 00000000..a1d8c3e7 --- /dev/null +++ b/lib.esm/providers/subscriber-connection.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"subscriber-connection.d.ts","sourceRoot":"","sources":["../../src.ts/providers/subscriber-connection.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAIzD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C;;;;GAIG;AACH,MAAM,WAAW,qBAAsB,SAAQ,QAAQ;IAEnD,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,WAAW,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,GAAG,MAAM,CAAC;IAC1E,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACxC;AAED;;;;GAIG;AACH,qBAAa,yBAA0B,YAAW,UAAU;;gBAQ5C,QAAQ,EAAE,qBAAqB;IAO3C,KAAK,IAAI,IAAI;IAcb,IAAI,IAAI,IAAI;IAUZ,KAAK,CAAC,eAAe,CAAC,EAAE,OAAO,GAAG,IAAI;IAKtC,MAAM,IAAI,IAAI;CAGjB"} \ No newline at end of file diff --git a/lib.esm/providers/subscriber-connection.js b/lib.esm/providers/subscriber-connection.js new file mode 100644 index 00000000..bd873833 --- /dev/null +++ b/lib.esm/providers/subscriber-connection.js @@ -0,0 +1,52 @@ +import { getNumber } from "../utils/index.js"; +/** + * @TODO + * + * @_docloc: api/providers/abstract-provider + */ +export class BlockConnectionSubscriber { + #provider; + #blockNumber; + #running; + #filterId; + constructor(provider) { + this.#provider = provider; + this.#blockNumber = -2; + this.#running = false; + this.#filterId = null; + } + start() { + if (this.#running) { + return; + } + this.#running = true; + this.#filterId = this.#provider._subscribe(["newHeads"], (result) => { + const blockNumber = getNumber(result.number); + const initial = (this.#blockNumber === -2) ? blockNumber : (this.#blockNumber + 1); + for (let b = initial; b <= blockNumber; b++) { + this.#provider.emit("block", b); + } + this.#blockNumber = blockNumber; + }); + } + stop() { + if (!this.#running) { + return; + } + this.#running = false; + if (this.#filterId != null) { + this.#provider._unsubscribe(this.#filterId); + this.#filterId = null; + } + } + pause(dropWhilePaused) { + if (dropWhilePaused) { + this.#blockNumber = -2; + } + this.stop(); + } + resume() { + this.start(); + } +} +//# sourceMappingURL=subscriber-connection.js.map \ No newline at end of file diff --git a/lib.esm/providers/subscriber-connection.js.map b/lib.esm/providers/subscriber-connection.js.map new file mode 100644 index 00000000..21a64289 --- /dev/null +++ b/lib.esm/providers/subscriber-connection.js.map @@ -0,0 +1 @@ +{"version":3,"file":"subscriber-connection.js","sourceRoot":"","sources":["../../src.ts/providers/subscriber-connection.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAmB9C;;;;GAIG;AACH,MAAM,OAAO,yBAAyB;IAClC,SAAS,CAAwB;IACjC,YAAY,CAAS;IAErB,QAAQ,CAAU;IAElB,SAAS,CAAgB;IAEzB,YAAY,QAA+B;QACvC,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC;QACvB,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QACtB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IAC1B,CAAC;IAED,KAAK;QACD,IAAI,IAAI,CAAC,QAAQ,EAAE;YAAE,OAAO;SAAE;QAC9B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QAErB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAE,UAAU,CAAE,EAAE,CAAC,MAAW,EAAE,EAAE;YACvE,MAAM,WAAW,GAAG,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAC7C,MAAM,OAAO,GAAG,CAAC,IAAI,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,CAAA,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC,CAAA;YACjF,KAAK,IAAI,CAAC,GAAG,OAAO,EAAE,CAAC,IAAI,WAAW,EAAE,CAAC,EAAE,EAAE;gBACzC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;aACnC;YACD,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;QACpC,CAAC,CAAC,CAAC;IACP,CAAC;IAED,IAAI;QACA,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;YAAE,OAAO;SAAE;QAC/B,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QAEtB,IAAI,IAAI,CAAC,SAAS,IAAI,IAAI,EAAE;YACxB,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAC5C,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;SACzB;IACL,CAAC;IAED,KAAK,CAAC,eAAyB;QAC3B,IAAI,eAAe,EAAE;YAAE,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC;SAAE;QAChD,IAAI,CAAC,IAAI,EAAE,CAAC;IAChB,CAAC;IAED,MAAM;QACF,IAAI,CAAC,KAAK,EAAE,CAAC;IACjB,CAAC;CACJ"} \ No newline at end of file diff --git a/lib.esm/providers/subscriber-filterid.d.ts b/lib.esm/providers/subscriber-filterid.d.ts new file mode 100644 index 00000000..721d6284 --- /dev/null +++ b/lib.esm/providers/subscriber-filterid.d.ts @@ -0,0 +1,64 @@ +import type { AbstractProvider, Subscriber } from "./abstract-provider.js"; +import type { EventFilter } from "./provider.js"; +import type { JsonRpcApiProvider } from "./provider-jsonrpc.js"; +/** + * Some backends support subscribing to events using a Filter ID. + * + * When subscribing with this technique, the node issues a unique + * //Filter ID//. At this point the node dedicates resources to + * the filter, so that periodic calls to follow up on the //Filter ID// + * will receive any events since the last call. + * + * @_docloc: api/providers/abstract-provider + */ +export declare class FilterIdSubscriber implements Subscriber { + #private; + /** + * Creates a new **FilterIdSubscriber** which will used [[_subscribe]] + * and [[_emitResults]] to setup the subscription and provide the event + * to the %%provider%%. + */ + constructor(provider: JsonRpcApiProvider); + /** + * Sub-classes **must** override this to begin the subscription. + */ + _subscribe(provider: JsonRpcApiProvider): Promise; + /** + * Sub-classes **must** override this handle the events. + */ + _emitResults(provider: AbstractProvider, result: Array): Promise; + /** + * Sub-classes **must** override this handle recovery on errors. + */ + _recover(provider: AbstractProvider): Subscriber; + start(): void; + stop(): void; + pause(dropWhilePaused?: boolean): void; + resume(): void; +} +/** + * A **FilterIdSubscriber** for receiving contract events. + * + * @_docloc: api/providers/abstract-provider + */ +export declare class FilterIdEventSubscriber extends FilterIdSubscriber { + #private; + /** + * Creates a new **FilterIdEventSubscriber** attached to %%provider%% + * listening for %%filter%%. + */ + constructor(provider: JsonRpcApiProvider, filter: EventFilter); + _recover(provider: AbstractProvider): Subscriber; + _subscribe(provider: JsonRpcApiProvider): Promise; + _emitResults(provider: JsonRpcApiProvider, results: Array): Promise; +} +/** + * A **FilterIdSubscriber** for receiving pending transactions events. + * + * @_docloc: api/providers/abstract-provider + */ +export declare class FilterIdPendingSubscriber extends FilterIdSubscriber { + _subscribe(provider: JsonRpcApiProvider): Promise; + _emitResults(provider: JsonRpcApiProvider, results: Array): Promise; +} +//# sourceMappingURL=subscriber-filterid.d.ts.map \ No newline at end of file diff --git a/lib.esm/providers/subscriber-filterid.d.ts.map b/lib.esm/providers/subscriber-filterid.d.ts.map new file mode 100644 index 00000000..74d56f4f --- /dev/null +++ b/lib.esm/providers/subscriber-filterid.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"subscriber-filterid.d.ts","sourceRoot":"","sources":["../../src.ts/providers/subscriber-filterid.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAE3E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAMhE;;;;;;;;;GASG;AACH,qBAAa,kBAAmB,YAAW,UAAU;;IAYjD;;;;OAIG;gBACS,QAAQ,EAAE,kBAAkB;IAaxC;;OAEG;IACH,UAAU,CAAC,QAAQ,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC;IAIzD;;OAEG;IACH,YAAY,CAAC,QAAQ,EAAE,gBAAgB,EAAE,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAI3E;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,GAAG,UAAU;IAuDhD,KAAK,IAAI,IAAI;IAOb,IAAI,IAAI,IAAI;IASZ,KAAK,CAAC,eAAe,CAAC,EAAE,OAAO,GAAG,IAAI;IAKtC,MAAM,IAAI,IAAI;CACjB;AAED;;;;GAIG;AACH,qBAAa,uBAAwB,SAAQ,kBAAkB;;IAG3D;;;OAGG;gBACS,QAAQ,EAAE,kBAAkB,EAAE,MAAM,EAAE,WAAW;IAK7D,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,GAAG,UAAU;IAI1C,UAAU,CAAC,QAAQ,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC;IAKzD,YAAY,CAAC,QAAQ,EAAE,kBAAkB,EAAE,OAAO,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;CAKvF;AAED;;;;GAIG;AACH,qBAAa,yBAA0B,SAAQ,kBAAkB;IACvD,UAAU,CAAC,QAAQ,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC;IAIzD,YAAY,CAAC,QAAQ,EAAE,kBAAkB,EAAE,OAAO,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;CAKvF"} \ No newline at end of file diff --git a/lib.esm/providers/subscriber-filterid.js b/lib.esm/providers/subscriber-filterid.js new file mode 100644 index 00000000..725fa73d --- /dev/null +++ b/lib.esm/providers/subscriber-filterid.js @@ -0,0 +1,171 @@ +import { isError } from "../utils/index.js"; +import { PollingEventSubscriber } from "./subscriber-polling.js"; +function copy(obj) { + return JSON.parse(JSON.stringify(obj)); +} +/** + * Some backends support subscribing to events using a Filter ID. + * + * When subscribing with this technique, the node issues a unique + * //Filter ID//. At this point the node dedicates resources to + * the filter, so that periodic calls to follow up on the //Filter ID// + * will receive any events since the last call. + * + * @_docloc: api/providers/abstract-provider + */ +export class FilterIdSubscriber { + #provider; + #filterIdPromise; + #poller; + #running; + #network; + #hault; + /** + * Creates a new **FilterIdSubscriber** which will used [[_subscribe]] + * and [[_emitResults]] to setup the subscription and provide the event + * to the %%provider%%. + */ + constructor(provider) { + this.#provider = provider; + this.#filterIdPromise = null; + this.#poller = this.#poll.bind(this); + this.#running = false; + this.#network = null; + this.#hault = false; + } + /** + * Sub-classes **must** override this to begin the subscription. + */ + _subscribe(provider) { + throw new Error("subclasses must override this"); + } + /** + * Sub-classes **must** override this handle the events. + */ + _emitResults(provider, result) { + throw new Error("subclasses must override this"); + } + /** + * Sub-classes **must** override this handle recovery on errors. + */ + _recover(provider) { + throw new Error("subclasses must override this"); + } + async #poll(blockNumber) { + try { + // Subscribe if necessary + if (this.#filterIdPromise == null) { + this.#filterIdPromise = this._subscribe(this.#provider); + } + // Get the Filter ID + let filterId = null; + try { + filterId = await this.#filterIdPromise; + } + catch (error) { + if (!isError(error, "UNSUPPORTED_OPERATION") || error.operation !== "quai_newFilter") { + throw error; + } + } + // The backend does not support Filter ID; downgrade to + // polling + if (filterId == null) { + this.#filterIdPromise = null; + this.#provider._recoverSubscriber(this, this._recover(this.#provider)); + return; + } + const network = await this.#provider.getNetwork(); + if (!this.#network) { + this.#network = network; + } + if (this.#network.chainId !== network.chainId) { + throw new Error("chaid changed"); + } + if (this.#hault) { + return; + } + const result = await this.#provider.send("quai_getFilterChanges", [filterId]); + await this._emitResults(this.#provider, result); + } + catch (error) { + console.log("@TODO", error); + } + this.#provider.once("block", this.#poller); + } + #teardown() { + const filterIdPromise = this.#filterIdPromise; + if (filterIdPromise) { + this.#filterIdPromise = null; + filterIdPromise.then((filterId) => { + this.#provider.send("quai_uninstallFilter", [filterId]); + }); + } + } + start() { + if (this.#running) { + return; + } + this.#running = true; + this.#poll(-2); + } + stop() { + if (!this.#running) { + return; + } + this.#running = false; + this.#hault = true; + this.#teardown(); + this.#provider.off("block", this.#poller); + } + pause(dropWhilePaused) { + if (dropWhilePaused) { + this.#teardown(); + } + this.#provider.off("block", this.#poller); + } + resume() { this.start(); } +} +/** + * A **FilterIdSubscriber** for receiving contract events. + * + * @_docloc: api/providers/abstract-provider + */ +export class FilterIdEventSubscriber extends FilterIdSubscriber { + #event; + /** + * Creates a new **FilterIdEventSubscriber** attached to %%provider%% + * listening for %%filter%%. + */ + constructor(provider, filter) { + super(provider); + this.#event = copy(filter); + } + _recover(provider) { + return new PollingEventSubscriber(provider, this.#event); + } + async _subscribe(provider) { + const filterId = await provider.send("quai_newFilter", [this.#event]); + return filterId; + } + async _emitResults(provider, results) { + for (const result of results) { + provider.emit(this.#event, provider._wrapLog(result, provider._network)); + } + } +} +/** + * A **FilterIdSubscriber** for receiving pending transactions events. + * + * @_docloc: api/providers/abstract-provider + */ +export class FilterIdPendingSubscriber extends FilterIdSubscriber { + async _subscribe(provider) { + return await provider.send("quai_newPendingTransactionFilter", []); + } + async _emitResults(provider, results) { + for (const result of results) { + provider.emit("pending", result); + } + } +} +//# sourceMappingURL=subscriber-filterid.js.map \ No newline at end of file diff --git a/lib.esm/providers/subscriber-filterid.js.map b/lib.esm/providers/subscriber-filterid.js.map new file mode 100644 index 00000000..0809972f --- /dev/null +++ b/lib.esm/providers/subscriber-filterid.js.map @@ -0,0 +1 @@ +{"version":3,"file":"subscriber-filterid.js","sourceRoot":"","sources":["../../src.ts/providers/subscriber-filterid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAOjE,SAAS,IAAI,CAAC,GAAQ;IAClB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;AAC3C,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,OAAO,kBAAkB;IAC3B,SAAS,CAAqB;IAE9B,gBAAgB,CAAyB;IACzC,OAAO,CAA+B;IAEtC,QAAQ,CAAU;IAElB,QAAQ,CAAiB;IAEzB,MAAM,CAAU;IAEhB;;;;OAIG;IACH,YAAY,QAA4B;QACpC,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAE1B,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAErC,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QAEtB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QAErB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,UAAU,CAAC,QAA4B;QACnC,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;IACrD,CAAC;IAED;;OAEG;IACH,YAAY,CAAC,QAA0B,EAAE,MAAkB;QACvD,MAAM,IAAI,KAAK,CAAC,+BA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EAAE;YAC1B,QAAQ,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;SACpC;IACL,CAAC;CACJ"} \ No newline at end of file diff --git a/lib.esm/providers/subscriber-polling.d.ts b/lib.esm/providers/subscriber-polling.d.ts new file mode 100644 index 00000000..c32aaa3b --- /dev/null +++ b/lib.esm/providers/subscriber-polling.d.ts @@ -0,0 +1,94 @@ +import type { AbstractProvider, Subscriber } from "./abstract-provider.js"; +import type { EventFilter, OrphanFilter, ProviderEvent } from "./provider.js"; +/** + * Return the polling subscriber for common events. + * + * @_docloc: api/providers/abstract-provider + */ +export declare function getPollingSubscriber(provider: AbstractProvider, event: ProviderEvent): Subscriber; +/** + * A **PollingBlockSubscriber** polls at a regular interval for a change + * in the block number. + * + * @_docloc: api/providers/abstract-provider + */ +export declare class PollingBlockSubscriber implements Subscriber { + #private; + /** + * Create a new **PollingBlockSubscriber** attached to %%provider%%. + */ + constructor(provider: AbstractProvider); + /** + * The polling interval. + */ + get pollingInterval(): number; + set pollingInterval(value: number); + start(): void; + stop(): void; + pause(dropWhilePaused?: boolean): void; + resume(): void; +} +/** + * An **OnBlockSubscriber** can be sub-classed, with a [[_poll]] + * implmentation which will be called on every new block. + * + * @_docloc: api/providers/abstract-provider + */ +export declare class OnBlockSubscriber implements Subscriber { + #private; + /** + * Create a new **OnBlockSubscriber** attached to %%provider%%. + */ + constructor(provider: AbstractProvider); + /** + * Called on every new block. + */ + _poll(blockNumber: number, provider: AbstractProvider): Promise; + start(): void; + stop(): void; + pause(dropWhilePaused?: boolean): void; + resume(): void; +} +/** + * @_ignore: + * + * @_docloc: api/providers/abstract-provider + */ +export declare class PollingOrphanSubscriber extends OnBlockSubscriber { + #private; + constructor(provider: AbstractProvider, filter: OrphanFilter); + _poll(blockNumber: number, provider: AbstractProvider): Promise; +} +/** + * A **PollingTransactionSubscriber** will poll for a given transaction + * hash for its receipt. + * + * @_docloc: api/providers/abstract-provider + */ +export declare class PollingTransactionSubscriber extends OnBlockSubscriber { + #private; + /** + * Create a new **PollingTransactionSubscriber** attached to + * %%provider%%, listening for %%hash%%. + */ + constructor(provider: AbstractProvider, hash: string); + _poll(blockNumber: number, provider: AbstractProvider): Promise; +} +/** + * A **PollingEventSubscriber** will poll for a given filter for its logs. + * + * @_docloc: api/providers/abstract-provider + */ +export declare class PollingEventSubscriber implements Subscriber { + #private; + /** + * Create a new **PollingTransactionSubscriber** attached to + * %%provider%%, listening for %%filter%%. + */ + constructor(provider: AbstractProvider, filter: EventFilter); + start(): void; + stop(): void; + pause(dropWhilePaused?: boolean): void; + resume(): void; +} +//# sourceMappingURL=subscriber-polling.d.ts.map \ No newline at end of file diff --git a/lib.esm/providers/subscriber-polling.d.ts.map b/lib.esm/providers/subscriber-polling.d.ts.map new file mode 100644 index 00000000..010b21d3 --- /dev/null +++ b/lib.esm/providers/subscriber-polling.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"subscriber-polling.d.ts","sourceRoot":"","sources":["../../src.ts/providers/subscriber-polling.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAC3E,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAM9E;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,gBAAgB,EAAE,KAAK,EAAE,aAAa,GAAG,UAAU,CAOjG;AAID;;;;;GAKG;AACH,qBAAa,sBAAuB,YAAW,UAAU;;IAUrD;;OAEG;gBACS,QAAQ,EAAE,gBAAgB;IAQtC;;OAEG;IACH,IAAI,eAAe,IAAI,MAAM,CAA2B;IACxD,IAAI,eAAe,CAAC,KAAK,EAAE,MAAM,EAA6B;IAqC9D,KAAK,IAAI,IAAI;IAMb,IAAI,IAAI,IAAI;IAMZ,KAAK,CAAC,eAAe,CAAC,EAAE,OAAO,GAAG,IAAI;IAKtC,MAAM,IAAI,IAAI;CAGjB;AAED;;;;;GAKG;AACH,qBAAa,iBAAkB,YAAW,UAAU;;IAKhD;;OAEG;gBACS,QAAQ,EAAE,gBAAgB;IAQtC;;OAEG;IACG,KAAK,CAAC,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAI3E,KAAK,IAAI,IAAI;IAQb,IAAI,IAAI,IAAI;IAOZ,KAAK,CAAC,eAAe,CAAC,EAAE,OAAO,GAAG,IAAI;IACtC,MAAM,IAAI,IAAI;CACjB;AAED;;;;GAIG;AACH,qBAAa,uBAAwB,SAAQ,iBAAiB;;gBAG9C,QAAQ,EAAE,gBAAgB,EAAE,MAAM,EAAE,YAAY;IAKtD,KAAK,CAAC,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;CAI9E;AAED;;;;;GAKG;AACH,qBAAa,4BAA6B,SAAQ,iBAAiB;;IAG/D;;;OAGG;gBACS,QAAQ,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM;IAK9C,KAAK,CAAC,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;CAI9E;AAED;;;;GAIG;AACH,qBAAa,sBAAuB,YAAW,UAAU;;IAWrD;;;OAGG;gBACS,QAAQ,EAAE,gBAAgB,EAAE,MAAM,EAAE,WAAW;IAqC3D,KAAK,IAAI,IAAI;IAYb,IAAI,IAAI,IAAI;IAOZ,KAAK,CAAC,eAAe,CAAC,EAAE,OAAO,GAAG,IAAI;IAKtC,MAAM,IAAI,IAAI;CAGjB"} \ No newline at end of file diff --git a/lib.esm/providers/subscriber-polling.js b/lib.esm/providers/subscriber-polling.js new file mode 100644 index 00000000..930c9229 --- /dev/null +++ b/lib.esm/providers/subscriber-polling.js @@ -0,0 +1,265 @@ +import { assert, isHexString } from "../utils/index.js"; +function copy(obj) { + return JSON.parse(JSON.stringify(obj)); +} +/** + * Return the polling subscriber for common events. + * + * @_docloc: api/providers/abstract-provider + */ +export function getPollingSubscriber(provider, event) { + if (event === "block") { + return new PollingBlockSubscriber(provider); + } + if (isHexString(event, 32)) { + return new PollingTransactionSubscriber(provider, event); + } + assert(false, "unsupported polling event", "UNSUPPORTED_OPERATION", { + operation: "getPollingSubscriber", info: { event } + }); +} +// @TODO: refactor this +/** + * A **PollingBlockSubscriber** polls at a regular interval for a change + * in the block number. + * + * @_docloc: api/providers/abstract-provider + */ +export class PollingBlockSubscriber { + #provider; + #poller; + #interval; + // The most recent block we have scanned for events. The value -2 + // indicates we still need to fetch an initial block number + #blockNumber; + /** + * Create a new **PollingBlockSubscriber** attached to %%provider%%. + */ + constructor(provider) { + this.#provider = provider; + this.#poller = null; + this.#interval = 4000; + this.#blockNumber = -2; + } + /** + * The polling interval. + */ + get pollingInterval() { return this.#interval; } + set pollingInterval(value) { this.#interval = value; } + async #poll() { + try { + const blockNumber = await this.#provider.getBlockNumber(); + // Bootstrap poll to setup our initial block number + if (this.#blockNumber === -2) { + this.#blockNumber = blockNumber; + return; + } + // @TODO: Put a cap on the maximum number of events per loop? + if (blockNumber !== this.#blockNumber) { + for (let b = this.#blockNumber + 1; b <= blockNumber; b++) { + // We have been stopped + if (this.#poller == null) { + return; + } + await this.#provider.emit("block", b); + } + this.#blockNumber = blockNumber; + } + } + catch (error) { + // @TODO: Minor bump, add an "error" event to let subscribers + // know things went awry. + //console.log(error); + } + // We have been stopped + if (this.#poller == null) { + return; + } + this.#poller = this.#provider._setTimeout(this.#poll.bind(this), this.#interval); + } + start() { + if (this.#poller) { + return; + } + this.#poller = this.#provider._setTimeout(this.#poll.bind(this), this.#interval); + this.#poll(); + } + stop() { + if (!this.#poller) { + return; + } + this.#provider._clearTimeout(this.#poller); + this.#poller = null; + } + pause(dropWhilePaused) { + this.stop(); + if (dropWhilePaused) { + this.#blockNumber = -2; + } + } + resume() { + this.start(); + } +} +/** + * An **OnBlockSubscriber** can be sub-classed, with a [[_poll]] + * implmentation which will be called on every new block. + * + * @_docloc: api/providers/abstract-provider + */ +export class OnBlockSubscriber { + #provider; + #poll; + #running; + /** + * Create a new **OnBlockSubscriber** attached to %%provider%%. + */ + constructor(provider) { + this.#provider = provider; + this.#running = false; + this.#poll = (blockNumber) => { + this._poll(blockNumber, this.#provider); + }; + } + /** + * Called on every new block. + */ + async _poll(blockNumber, provider) { + throw new Error("sub-classes must override this"); + } + start() { + if (this.#running) { + return; + } + this.#running = true; + this.#poll(-2); + this.#provider.on("block", this.#poll); + } + stop() { + if (!this.#running) { + return; + } + this.#running = false; + this.#provider.off("block", this.#poll); + } + pause(dropWhilePaused) { this.stop(); } + resume() { this.start(); } +} +/** + * @_ignore: + * + * @_docloc: api/providers/abstract-provider + */ +export class PollingOrphanSubscriber extends OnBlockSubscriber { + #filter; + constructor(provider, filter) { + super(provider); + this.#filter = copy(filter); + } + async _poll(blockNumber, provider) { + throw new Error("@TODO"); + console.log(this.#filter); + } +} +/** + * A **PollingTransactionSubscriber** will poll for a given transaction + * hash for its receipt. + * + * @_docloc: api/providers/abstract-provider + */ +export class PollingTransactionSubscriber extends OnBlockSubscriber { + #hash; + /** + * Create a new **PollingTransactionSubscriber** attached to + * %%provider%%, listening for %%hash%%. + */ + constructor(provider, hash) { + super(provider); + this.#hash = hash; + } + async _poll(blockNumber, provider) { + const tx = await provider.getTransactionReceipt(this.#hash); + if (tx) { + provider.emit(this.#hash, tx); + } + } +} +/** + * A **PollingEventSubscriber** will poll for a given filter for its logs. + * + * @_docloc: api/providers/abstract-provider + */ +export class PollingEventSubscriber { + #provider; + #filter; + #poller; + #running; + // The most recent block we have scanned for events. The value -2 + // indicates we still need to fetch an initial block number + #blockNumber; + /** + * Create a new **PollingTransactionSubscriber** attached to + * %%provider%%, listening for %%filter%%. + */ + constructor(provider, filter) { + this.#provider = provider; + this.#filter = copy(filter); + this.#poller = this.#poll.bind(this); + this.#running = false; + this.#blockNumber = -2; + } + async #poll(blockNumber) { + // The initial block hasn't been determined yet + if (this.#blockNumber === -2) { + return; + } + const filter = copy(this.#filter); + filter.fromBlock = this.#blockNumber + 1; + filter.toBlock = blockNumber; + const logs = await this.#provider.getLogs(filter); + // No logs could just mean the node has not indexed them yet, + // so we keep a sliding window of 60 blocks to keep scanning + if (logs.length === 0) { + if (this.#blockNumber < blockNumber - 60) { + this.#blockNumber = blockNumber - 60; + } + return; + } + for (const log of logs) { + this.#provider.emit(this.#filter, log); + // Only advance the block number when logs were found to + // account for networks (like BNB and Polygon) which may + // sacrifice event consistency for block event speed + this.#blockNumber = log.blockNumber; + } + } + start() { + if (this.#running) { + return; + } + this.#running = true; + if (this.#blockNumber === -2) { + this.#provider.getBlockNumber().then((blockNumber) => { + this.#blockNumber = blockNumber; + }); + } + this.#provider.on("block", this.#poller); + } + stop() { + if (!this.#running) { + return; + } + this.#running = false; + this.#provider.off("block", this.#poller); + } + pause(dropWhilePaused) { + this.stop(); + if (dropWhilePaused) { + this.#blockNumber = -2; + } + } + resume() { + this.start(); + } +} +//# sourceMappingURL=subscriber-polling.js.map \ No newline at end of file diff --git a/lib.esm/providers/subscriber-polling.js.map b/lib.esm/providers/subscriber-polling.js.map new file mode 100644 index 00000000..c8526171 --- /dev/null +++ b/lib.esm/providers/subscriber-polling.js.map @@ -0,0 +1 @@ +{"version":3,"file":"subscriber-polling.js","sourceRoot":"","sources":["../../src.ts/providers/subscriber-polling.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAKxD,SAAS,IAAI,CAAC,GAAQ;IAClB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;AAC3C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,QAA0B,EAAE,KAAoB;IACjF,IAAI,KAAK,KAAK,OAAO,EAAE;QAAE,OAAO,IAAI,sBAAsB,CAAC,QAAQ,CAAC,CAAC;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AAO,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IAC7C,CAAC;IAED,IAAI;QACA,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;YAAE,OAAO;SAAE;QAC/B,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QAEtB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IAC9C,CAAC;IAED,KAAK,CAAC,eAAyB;QAC3B,IAAI,CAAC,IAAI,EAAE,CAAC;QACZ,IAAI,eAAe,EAAE;YAAE,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC;SAAE;IACpD,CAAC;IAED,MAAM;QACF,IAAI,CAAC,KAAK,EAAE,CAAC;IACjB,CAAC;CACJ"} \ No newline at end of file diff --git a/lib.esm/providers/ws-browser.d.ts b/lib.esm/providers/ws-browser.d.ts new file mode 100644 index 00000000..d9272042 --- /dev/null +++ b/lib.esm/providers/ws-browser.d.ts @@ -0,0 +1,3 @@ +declare const _WebSocket: any; +export { _WebSocket as WebSocket }; +//# sourceMappingURL=ws-browser.d.ts.map \ No newline at end of file diff --git a/lib.esm/providers/ws-browser.d.ts.map b/lib.esm/providers/ws-browser.d.ts.map new file mode 100644 index 00000000..f549c4b0 --- /dev/null +++ b/lib.esm/providers/ws-browser.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"ws-browser.d.ts","sourceRoot":"","sources":["../../src.ts/providers/ws-browser.ts"],"names":[],"mappings":"AAQA,QAAA,MAAM,UAAU,KAAwB,CAAC;AAEzC,OAAO,EAAE,UAAU,IAAI,SAAS,EAAE,CAAC"} \ No newline at end of file diff --git a/lib.esm/providers/ws-browser.js b/lib.esm/providers/ws-browser.js new file mode 100644 index 00000000..df9584d2 --- /dev/null +++ b/lib.esm/providers/ws-browser.js @@ -0,0 +1,16 @@ +function getGlobal() { + if (typeof self !== 'undefined') { + return self; + } + if (typeof window !== 'undefined') { + return window; + } + if (typeof global !== 'undefined') { + return global; + } + throw new Error('unable to locate global object'); +} +; +const _WebSocket = getGlobal().WebSocket; +export { _WebSocket as WebSocket }; +//# sourceMappingURL=ws-browser.js.map \ No newline at end of file diff --git a/lib.esm/providers/ws-browser.js.map b/lib.esm/providers/ws-browser.js.map new file mode 100644 index 00000000..e23187e8 --- /dev/null +++ b/lib.esm/providers/ws-browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"ws-browser.js","sourceRoot":"","sources":["../../src.ts/providers/ws-browser.ts"],"names":[],"mappings":"AACA,SAAS,SAAS;IAChB,IAAI,OAAO,IAAI,KAAK,WAAW,EAAE;QAAE,OAAO,IAAI,CAAC;KAAE;IACjD,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;QAAE,OAAO,MAAM,CAAC;KAAE;IACrD,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;QAAE,OAAO,MAAM,CAAC;KAAE;IACrD,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;AACpD,CAAC;AAAA,CAAC;AAEF,MAAM,UAAU,GAAG,SAAS,EAAE,CAAC,SAAS,CAAC;AAEzC,OAAO,EAAE,UAAU,IAAI,SAAS,EAAE,CAAC"} \ No newline at end of file diff --git a/lib.esm/providers/ws.d.ts b/lib.esm/providers/ws.d.ts new file mode 100644 index 00000000..75d53b7d --- /dev/null +++ b/lib.esm/providers/ws.d.ts @@ -0,0 +1,2 @@ +export { WebSocket } from "ws"; +//# sourceMappingURL=ws.d.ts.map \ No newline at end of file diff --git a/lib.esm/providers/ws.d.ts.map b/lib.esm/providers/ws.d.ts.map new file mode 100644 index 00000000..c424f8d8 --- /dev/null +++ b/lib.esm/providers/ws.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"ws.d.ts","sourceRoot":"","sources":["../../src.ts/providers/ws.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC"} \ No newline at end of file diff --git a/lib.esm/providers/ws.js b/lib.esm/providers/ws.js new file mode 100644 index 00000000..3fcc8f78 --- /dev/null +++ b/lib.esm/providers/ws.js @@ -0,0 +1,2 @@ +export { WebSocket } from "ws"; +//# sourceMappingURL=ws.js.map \ No newline at end of file diff --git a/lib.esm/providers/ws.js.map b/lib.esm/providers/ws.js.map new file mode 100644 index 00000000..717e091c --- /dev/null +++ b/lib.esm/providers/ws.js.map @@ -0,0 +1 @@ +{"version":3,"file":"ws.js","sourceRoot":"","sources":["../../src.ts/providers/ws.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC"} \ No newline at end of file diff --git a/lib.esm/quais.d.ts b/lib.esm/quais.d.ts new file mode 100644 index 00000000..e2100a2b --- /dev/null +++ b/lib.esm/quais.d.ts @@ -0,0 +1,22 @@ +export { version } from "./_version.js"; +export { decodeBytes32String, encodeBytes32String, AbiCoder, ConstructorFragment, ErrorFragment, EventFragment, Fragment, FallbackFragment, FunctionFragment, NamedFragment, ParamType, StructFragment, checkResultErrors, ErrorDescription, Indexed, Interface, LogDescription, Result, TransactionDescription, Typed, } from "./abi/index.js"; +export { getAddress, getCreateAddress, getCreate2Address, isAddressable, isAddress, resolveAddress } from "./address/index.js"; +export { ZeroAddress, WeiPerEther, MaxUint256, MinInt256, MaxInt256, N, ZeroHash, quaisymbol, MessagePrefix } from "./constants/index.js"; +export { BaseContract, Contract, ContractFactory, ContractEventPayload, ContractTransactionReceipt, ContractTransactionResponse, ContractUnknownEventPayload, EventLog, UndecodedEventLog } from "./contract/index.js"; +export { computeHmac, randomBytes, keccak256, ripemd160, sha256, sha512, pbkdf2, scrypt, scryptSync, lock, Signature, SigningKey } from "./crypto/index.js"; +export { id, ensNormalize, isValidName, namehash, dnsEncode, hashMessage, verifyMessage, solidityPacked, solidityPackedKeccak256, solidityPackedSha256, TypedDataEncoder, verifyTypedData } from "./hash/index.js"; +export { getDefaultProvider, Block, FeeData, Log, TransactionReceipt, TransactionResponse, AbstractSigner, NonceManager, VoidSigner, AbstractProvider, FallbackProvider, JsonRpcApiProvider, JsonRpcProvider, JsonRpcSigner, BrowserProvider, IpcSocketProvider, SocketProvider, WebSocketProvider, Network, EnsPlugin, FeeDataNetworkPlugin, FetchUrlFeeDataNetworkPlugin, GasCostPlugin, NetworkPlugin, SocketBlockSubscriber, SocketEventSubscriber, SocketPendingSubscriber, SocketSubscriber, UnmanagedSubscriber, copyRequest, showThrottleMessage } from "./providers/index.js"; +export { accessListify, computeAddress, recoverAddress, Transaction, FewestCoinSelector } from "./transaction/index.js"; +export { decodeBase58, encodeBase58, decodeBase64, encodeBase64, concat, dataLength, dataSlice, getBytes, getBytesCopy, hexlify, isHexString, isBytesLike, stripZerosLeft, zeroPadBytes, zeroPadValue, defineProperties, resolveProperties, assert, assertArgument, assertArgumentCount, assertNormalize, assertPrivate, makeError, isCallException, isError, EventPayload, FetchRequest, FetchResponse, FetchCancelSignal, FixedNumber, getBigInt, getNumber, getUint, toBeArray, toBigInt, toBeHex, toNumber, toQuantity, fromTwos, toTwos, mask, formatQuai, parseQuai, formatEther, parseEther, formatUnits, parseUnits, toUtf8Bytes, toUtf8CodePoints, toUtf8String, Utf8ErrorFuncs, uuidV4, getTxType, getShardForAddress, getAddressDetails, isUTXOAddress, } from "./utils/index.js"; +export { Mnemonic, BaseWallet, HDNodeWallet, HDNodeVoidWallet, Wallet, getAccountPath, getIndexedAccountPath, isCrowdsaleJson, isKeystoreJson, decryptCrowdsaleJson, decryptKeystoreJsonSync, decryptKeystoreJson, encryptKeystoreJson, encryptKeystoreJsonSync, quaiHDAccountPath, qiHDAccountPath, } from "./wallet/index.js"; +export { Wordlist, LangEn, LangEs, WordlistOwl, WordlistOwlA, wordlists } from "./wordlists/index.js"; +export type { JsonFragment, JsonFragmentType, FormatType, FragmentType, InterfaceAbi, ParamTypeWalkFunc, ParamTypeWalkAsyncFunc } from "./abi/index.js"; +export type { Addressable, AddressLike } from "./address/index.js"; +export type { ConstantContractMethod, ContractEvent, ContractEventArgs, ContractEventName, ContractInterface, ContractMethod, ContractMethodArgs, ContractTransaction, DeferredTopicFilter, Overrides, BaseContractMethod, ContractDeployTransaction, PostfixOverrides, WrappedFallback } from "./contract/index.js"; +export type { ProgressCallback, SignatureLike } from "./crypto/index.js"; +export type { TypedDataDomain, TypedDataField } from "./hash/index.js"; +export type { Provider, Signer, AbstractProviderOptions, FallbackProviderOptions, AbstractProviderPlugin, BlockParams, BlockTag, ContractRunner, DebugEventBrowserProvider, Eip1193Provider, EventFilter, Filter, FilterByBlockHash, GasCostParameters, JsonRpcApiProviderOptions, JsonRpcError, JsonRpcPayload, JsonRpcResult, JsonRpcTransactionRequest, LogParams, MinedBlock, MinedTransactionResponse, Networkish, OrphanFilter, PerformActionFilter, PerformActionRequest, PerformActionTransaction, PreparedTransactionRequest, ProviderEvent, Subscriber, Subscription, TopicFilter, TransactionReceiptParams, TransactionRequest, TransactionResponseParams, WebSocketCreator, WebSocketLike } from "./providers/index.js"; +export type { AccessList, AccessListish, AccessListEntry, TransactionLike } from "./transaction/index.js"; +export type { BytesLike, BigNumberish, Numeric, ErrorCode, FixedFormat, Utf8ErrorFunc, UnicodeNormalizationForm, Utf8ErrorReason, GetUrlResponse, FetchPreflightFunc, FetchProcessFunc, FetchRetryFunc, FetchGatewayFunc, FetchGetUrlFunc, quaisError, UnknownError, NotImplementedError, UnsupportedOperationError, NetworkError, ServerError, TimeoutError, BadDataError, CancelledError, BufferOverrunError, NumericFaultError, InvalidArgumentError, MissingArgumentError, UnexpectedArgumentError, CallExceptionError, InsufficientFundsError, NonceExpiredError, ReplacementUnderpricedError, TransactionReplacedError, ActionRejectedError, CodedquaisError, CallExceptionAction, CallExceptionTransaction, EventEmitterable, Listener } from "./utils/index.js"; +export type { CrowdsaleAccount, KeystoreAccount, EncryptOptions } from "./wallet/index.js"; +//# sourceMappingURL=quais.d.ts.map \ No newline at end of file diff --git a/lib.esm/quais.d.ts.map b/lib.esm/quais.d.ts.map new file mode 100644 index 00000000..ef91d1da --- /dev/null +++ b/lib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,EAAE,aAAa,EACtE,yBAAyB,EAAE,SAAS,EAAE,UAAU,EAAE,wBAAwB,EAAE,UAAU,EACtF,YAAY,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,wBAAwB,EACjF,0BAA0B,EAAE,aAAa,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAChF,wBAAwB,EAAE,kBAAkB,EAAE,yBAAyB,EACvE,gBAAgB,EAAE,aAAa,EAClC,MAAM,sBAAsB,CAAC;AAE9B,YAAY,EACR,UAAU,EAAE,aAAa,EAAE,eAAe,EAC1C,eAAe,EAClB,MAAM,wBAAwB,CAAC;AAEhC,YAAY,EACR,SAAS,EACT,YAAY,EAAE,OAAO,EACrB,SAAS,EACT,WAAW,EACX,aAAa,EAAE,wBAAwB,EAAE,eAAe,EAExD,cAAc,EACd,kBAAkB,EAAE,gBAAgB,EAAE,cAAc,EACpD,gBAAgB,EAAE,eAAe,EAEjC,UAAU,EAAE,YAAY,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,YAAY,EACtF,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,kBAAkB,EAC3E,iBAAiB,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,uBAAuB,EACtF,kBAAkB,EAAE,sBAAsB,EAAE,iBAAiB,EAC7D,2BAA2B,EAAE,wBAAwB,EACrD,mBAAmB,EACnB,eAAe,EAEf,mBAAmB,EAAE,wBAAwB,EAC7C,gBAAgB,EAAE,QAAQ,EAC7B,MAAM,kBAAkB,CAAC;AAE1B,YAAY,EACR,gBAAgB,EAAE,eAAe,EAAE,cAAc,EACpD,MAAM,mBAAmB,CAAC"} \ No newline at end of file diff --git a/lib.esm/quais.js b/lib.esm/quais.js new file mode 100644 index 00000000..8f6223f4 --- /dev/null +++ b/lib.esm/quais.js @@ -0,0 +1,15 @@ +///////////////////////////// +// +export { version } from "./_version.js"; +export { decodeBytes32String, encodeBytes32String, AbiCoder, ConstructorFragment, ErrorFragment, EventFragment, Fragment, FallbackFragment, FunctionFragment, NamedFragment, ParamType, StructFragment, checkResultErrors, ErrorDescription, Indexed, Interface, LogDescription, Result, TransactionDescription, Typed, } from "./abi/index.js"; +export { getAddress, getCreateAddress, getCreate2Address, isAddressable, isAddress, resolveAddress } from "./address/index.js"; +export { ZeroAddress, WeiPerEther, MaxUint256, MinInt256, MaxInt256, N, ZeroHash, quaisymbol, MessagePrefix } from "./constants/index.js"; +export { BaseContract, Contract, ContractFactory, ContractEventPayload, ContractTransactionReceipt, ContractTransactionResponse, ContractUnknownEventPayload, EventLog, UndecodedEventLog } from "./contract/index.js"; +export { computeHmac, randomBytes, keccak256, ripemd160, sha256, sha512, pbkdf2, scrypt, scryptSync, lock, Signature, SigningKey } from "./crypto/index.js"; +export { id, ensNormalize, isValidName, namehash, dnsEncode, hashMessage, verifyMessage, solidityPacked, solidityPackedKeccak256, solidityPackedSha256, TypedDataEncoder, verifyTypedData } from "./hash/index.js"; +export { getDefaultProvider, Block, FeeData, Log, TransactionReceipt, TransactionResponse, AbstractSigner, NonceManager, VoidSigner, AbstractProvider, FallbackProvider, JsonRpcApiProvider, JsonRpcProvider, JsonRpcSigner, BrowserProvider, IpcSocketProvider, SocketProvider, WebSocketProvider, Network, EnsPlugin, FeeDataNetworkPlugin, FetchUrlFeeDataNetworkPlugin, GasCostPlugin, NetworkPlugin, SocketBlockSubscriber, SocketEventSubscriber, SocketPendingSubscriber, SocketSubscriber, UnmanagedSubscriber, copyRequest, showThrottleMessage } from "./providers/index.js"; +export { accessListify, computeAddress, recoverAddress, Transaction, FewestCoinSelector } from "./transaction/index.js"; +export { decodeBase58, encodeBase58, decodeBase64, encodeBase64, concat, dataLength, dataSlice, getBytes, getBytesCopy, hexlify, isHexString, isBytesLike, stripZerosLeft, zeroPadBytes, zeroPadValue, defineProperties, resolveProperties, assert, assertArgument, assertArgumentCount, assertNormalize, assertPrivate, makeError, isCallException, isError, EventPayload, FetchRequest, FetchResponse, FetchCancelSignal, FixedNumber, getBigInt, getNumber, getUint, toBeArray, toBigInt, toBeHex, toNumber, toQuantity, fromTwos, toTwos, mask, formatQuai, parseQuai, formatEther, parseEther, formatUnits, parseUnits, toUtf8Bytes, toUtf8CodePoints, toUtf8String, Utf8ErrorFuncs, uuidV4, getTxType, getShardForAddress, getAddressDetails, isUTXOAddress, } from "./utils/index.js"; +export { Mnemonic, BaseWallet, HDNodeWallet, HDNodeVoidWallet, Wallet, getAccountPath, getIndexedAccountPath, isCrowdsaleJson, isKeystoreJson, decryptCrowdsaleJson, decryptKeystoreJsonSync, decryptKeystoreJson, encryptKeystoreJson, encryptKeystoreJsonSync, quaiHDAccountPath, qiHDAccountPath, } from "./wallet/index.js"; +export { Wordlist, LangEn, LangEs, WordlistOwl, WordlistOwlA, wordlists } from "./wordlists/index.js"; +//# sourceMappingURL=quais.js.map \ No newline at end of file diff --git a/lib.esm/quais.js.map b/lib.esm/quais.js.map new file mode 100644 index 00000000..dc7447e2 --- /dev/null +++ b/lib.esm/quais.js.map @@ -0,0 +1 @@ +{"version":3,"file":"quais.js","sourceRoot":"","sources":["../src.ts/quais.ts"],"names":[],"mappings":"AAAA,6BAA6B;AAC7B,EAAE;AAEF,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,OAAO,EACH,mBAAmB,EAAE,mBAAmB,EAExC,QAAQ,EACR,mBAAmB,EAAE,aAAa,EAAE,aAAa,EAAE,QAAQ,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,aAAa,EAAE,SAAS,EAAE,cAAc,EAEzI,iBAAiB,EAAE,gBAAgB,EAAE,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,EAAE,sBAAsB,EACvG,KAAK,GACR,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACH,UAAU,EACV,gBAAgB,EAAE,iBAAiB,EACnC,aAAa,EAAE,SAAS,EAAE,cAAc,EAC3C,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACH,WAAW,EACX,WAAW,EAAE,UAAU,EAAE,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E,YAAY,EAC1B,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,OAAO,EAC9D,WAAW,EAAE,WAAW,EAAE,cAAc,EAAE,YAAY,EAAE,YAAY,EACpE,gBAAgB,EAAE,iBAAiB,EACnC,MAAM,EAAE,cAAc,EAAE,mBAAmB,EAAE,eAAe,EAAE,aAAa,EAC3E,SAAS,EACT,eAAe,EAAE,OAAO,EACxB,YAAY,EACZ,YAAY,EAAE,aAAa,EAAE,iBAAiB,EAC9C,WAAW,EACX,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,EACjF,QAAQ,EAAE,MAAM,EAAE,IAAI,EACtB,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EACvE,WAAW,EAAE,gBAAgB,EAAE,YAAY,EAC3C,cAAc,EACd,MAAM,EAAE,SAAS,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,aAAa,GAC1E,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACH,QAAQ,EACR,UAAU,EAAE,YAAY,EAAE,gBAAgB,EAC1C,MAAM,EAGN,cAAc,EAAE,qBAAqB,EACrC,eAAe,EAAE,cAAc,EAE/B,oBAAoB,EAAE,uBAAuB,EAAE,mBAAmB,EAClE,mBAAmB,EAAE,uBAAuB,EAE5C,iBAAiB,EAAE,eAAe,GACrC,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACH,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,SAAS,EACjE,MAAM,sBAAsB,CAAC"} \ No newline at end of file diff --git a/lib.esm/transaction/abstract-coinselector.d.ts b/lib.esm/transaction/abstract-coinselector.d.ts new file mode 100644 index 00000000..83d5ca56 --- /dev/null +++ b/lib.esm/transaction/abstract-coinselector.d.ts @@ -0,0 +1,50 @@ +import { UTXO, UTXOEntry, UTXOLike } from "./utxo.js"; +export type SpendTarget = { + address: string; + value: bigint; +}; +export type SelectedCoinsResult = { + inputs: UTXO[]; + spendOutputs: UTXO[]; + changeOutputs: UTXO[]; +}; +/** + * An **AbstractCoinSelector** provides a base class for other sub-classes to + * implement the functionality for selecting UTXOs for a spend and to properly + * handle spend and change outputs. + * + * This class is abstract and should not be used directly. Sub-classes should + * implement the [[performSelection]] method to provide the actual coin + * selection logic. + * + * @abstract + */ +export declare abstract class AbstractCoinSelector { + #private; + get availableUXTOs(): UTXO[]; + set availableUXTOs(value: UTXOLike[]); + get spendOutputs(): UTXO[]; + set spendOutputs(value: UTXOLike[]); + get changeOutputs(): UTXO[]; + set changeOutputs(value: UTXOLike[]); + /** + * Constructs a new AbstractCoinSelector instance with an empty UTXO array. + */ + constructor(availableUXTOs?: UTXOEntry[]); + /** + * This method should be implemented by sub-classes to provide the actual + * coin selection logic. It should select UTXOs from the available UTXOs + * that sum to the target amount and return the selected UTXOs as well as + * the spend and change outputs. + * @param target The target amount to select UTXOs for. + */ + abstract performSelection(target: SpendTarget): SelectedCoinsResult; + /** + * Validates the provided UTXO instance. In order to be valid for coin + * selection, the UTXO must have a valid address and denomination. + * @param utxo The UTXO instance to validate. + * @throws An error if the UTXO instance is invalid. + */ + protected _validateUTXO(utxo: UTXO): void; +} +//# sourceMappingURL=abstract-coinselector.d.ts.map \ No newline at end of file diff --git a/lib.esm/transaction/abstract-coinselector.d.ts.map b/lib.esm/transaction/abstract-coinselector.d.ts.map new file mode 100644 index 00000000..70bd68d6 --- /dev/null +++ b/lib.esm/transaction/abstract-coinselector.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"abstract-coinselector.d.ts","sourceRoot":"","sources":["../../src.ts/transaction/abstract-coinselector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAEtD,MAAM,MAAM,WAAW,GAAG;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAC9B,MAAM,EAAE,IAAI,EAAE,CAAC;IACf,YAAY,EAAE,IAAI,EAAE,CAAC;IACrB,aAAa,EAAE,IAAI,EAAE,CAAC;CACzB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,8BAAsB,oBAAoB;;IAKtC,IAAI,cAAc,IAAI,IAAI,EAAE,CAAiC;IAC7D,IAAI,cAAc,CAAC,KAAK,EAAE,QAAQ,EAAE,EAMnC;IAED,IAAI,YAAY,IAAI,IAAI,EAAE,CAA+B;IACzD,IAAI,YAAY,CAAC,KAAK,EAAE,QAAQ,EAAE,EAEjC;IAED,IAAI,aAAa,IAAI,IAAI,EAAE,CAAgC;IAC3D,IAAI,aAAa,CAAC,KAAK,EAAE,QAAQ,EAAE,EAElC;IAED;;OAEG;gBACS,cAAc,GAAE,SAAS,EAAO;IAU5C;;;;;;OAMG;IACH,QAAQ,CAAC,gBAAgB,CAAC,MAAM,EAAE,WAAW,GAAG,mBAAmB;IAEnE;;;;;OAKG;IACH,SAAS,CAAC,aAAa,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;CAY5C"} \ No newline at end of file diff --git a/lib.esm/transaction/abstract-coinselector.js b/lib.esm/transaction/abstract-coinselector.js new file mode 100644 index 00000000..a3c8dc34 --- /dev/null +++ b/lib.esm/transaction/abstract-coinselector.js @@ -0,0 +1,60 @@ +import { UTXO } from "./utxo.js"; +/** + * An **AbstractCoinSelector** provides a base class for other sub-classes to + * implement the functionality for selecting UTXOs for a spend and to properly + * handle spend and change outputs. + * + * This class is abstract and should not be used directly. Sub-classes should + * implement the [[performSelection]] method to provide the actual coin + * selection logic. + * + * @abstract + */ +export class AbstractCoinSelector { + #availableUXTOs; + #spendOutputs; + #changeOutputs; + get availableUXTOs() { return this.#availableUXTOs; } + set availableUXTOs(value) { + this.#availableUXTOs = value.map((val) => { + const utxo = UTXO.from(val); + this._validateUTXO(utxo); + return utxo; + }); + } + get spendOutputs() { return this.#spendOutputs; } + set spendOutputs(value) { + this.#spendOutputs = value.map((utxo) => UTXO.from(utxo)); + } + get changeOutputs() { return this.#changeOutputs; } + set changeOutputs(value) { + this.#changeOutputs = value.map((utxo) => UTXO.from(utxo)); + } + /** + * Constructs a new AbstractCoinSelector instance with an empty UTXO array. + */ + constructor(availableUXTOs = []) { + this.#availableUXTOs = availableUXTOs.map((val) => { + const utxo = UTXO.from(val); + this._validateUTXO(utxo); + return utxo; + }); + this.#spendOutputs = []; + this.#changeOutputs = []; + } + /** + * Validates the provided UTXO instance. In order to be valid for coin + * selection, the UTXO must have a valid address and denomination. + * @param utxo The UTXO instance to validate. + * @throws An error if the UTXO instance is invalid. + */ + _validateUTXO(utxo) { + if (utxo.address == null) { + throw new Error("UTXO address is required"); + } + if (utxo.denomination == null) { + throw new Error("UTXO denomination is required"); + } + } +} +//# sourceMappingURL=abstract-coinselector.js.map \ No newline at end of file diff --git a/lib.esm/transaction/abstract-coinselector.js.map b/lib.esm/transaction/abstract-coinselector.js.map new file mode 100644 index 00000000..aed97e33 --- /dev/null +++ b/lib.esm/transaction/abstract-coinselector.js.map @@ -0,0 +1 @@ +{"version":3,"file":"abstract-coinselector.js","sourceRoot":"","sources":["../../src.ts/transaction/abstract-coinselector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAuB,MAAM,WAAW,CAAC;AAatD;;;;;;;;;;GAUG;AACH,MAAM,OAAgB,oBAAoB;IACtC,eAAe,CAAS;IACxB,aAAa,CAAS;IACtB,cAAc,CAAS;IAEvB,IAAI,cAAc,KAAa,OAAO,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC;IAC7D,IAAI,cAAc,CAAC,KAAiB;QAChC,IAAI,CAAC,eAAe,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,GAAa,EAAE,EAAE;YAC/C,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC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CAAC;CAIJ"} \ No newline at end of file diff --git a/lib.esm/transaction/accesslist.d.ts b/lib.esm/transaction/accesslist.d.ts new file mode 100644 index 00000000..793637e4 --- /dev/null +++ b/lib.esm/transaction/accesslist.d.ts @@ -0,0 +1,6 @@ +import type { AccessList, AccessListish } from "./index.js"; +/** + * Returns a [[AccessList]] from any quais-supported access-list structure. + */ +export declare function accessListify(value: AccessListish): AccessList; +//# sourceMappingURL=accesslist.d.ts.map \ No newline at end of file diff --git a/lib.esm/transaction/accesslist.d.ts.map b/lib.esm/transaction/accesslist.d.ts.map new file mode 100644 index 00000000..6516681e --- /dev/null +++ b/lib.esm/transaction/accesslist.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"accesslist.d.ts","sourceRoot":"","sources":["../../src.ts/transaction/accesslist.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAa5D;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,aAAa,GAAG,UAAU,CAuB9D"} \ No newline at end of file diff --git a/lib.esm/transaction/accesslist.js b/lib.esm/transaction/accesslist.js new file mode 100644 index 00000000..723e96e1 --- /dev/null +++ b/lib.esm/transaction/accesslist.js @@ -0,0 +1,37 @@ +import { getAddress } from "../address/index.js"; +import { assertArgument, isHexString } from "../utils/index.js"; +function accessSetify(addr, storageKeys) { + return { + address: getAddress(addr), + storageKeys: storageKeys.map((storageKey, index) => { + assertArgument(isHexString(storageKey, 32), "invalid slot", `storageKeys[${index}]`, storageKey); + return storageKey.toLowerCase(); + }) + }; +} +/** + * Returns a [[AccessList]] from any quais-supported access-list structure. + */ +export function accessListify(value) { + if (Array.isArray(value)) { + return value.map((set, index) => { + if (Array.isArray(set)) { + assertArgument(set.length === 2, "invalid slot set", `value[${index}]`, set); + return accessSetify(set[0], set[1]); + } + assertArgument(set != null && typeof (set) === "object", "invalid address-slot set", "value", value); + return accessSetify(set.address, set.storageKeys); + }); + } + assertArgument(value != null && typeof (value) === "object", "invalid access list", "value", value); + const result = Object.keys(value).map((addr) => { + const storageKeys = value[addr].reduce((accum, storageKey) => { + accum[storageKey] = true; + return accum; + }, {}); + return accessSetify(addr, Object.keys(storageKeys).sort()); + }); + result.sort((a, b) => (a.address.localeCompare(b.address))); + return result; +} +//# sourceMappingURL=accesslist.js.map \ No newline at end of file diff --git a/lib.esm/transaction/accesslist.js.map b/lib.esm/transaction/accesslist.js.map new file mode 100644 index 00000000..a74e82dd --- /dev/null +++ b/lib.esm/transaction/accesslist.js.map @@ -0,0 +1 @@ +{"version":3,"file":"accesslist.js","sourceRoot":"","sources":["../../src.ts/transaction/accesslist.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAKhE,SAAS,YAAY,CAAC,IAAY,EAAE,WAA0B;IAC1D,OAAO;QACH,OAAO,EAAE,UAAU,CAAC,IAAI,CAAC;QACzB,WAAW,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,KAAK,EAAE,EAAE;YAC/C,cAAc,CAAC,WAAW,CAAC,UAAU,EAAE,EAAE,CAAC,EAAE,cAAc,EAAE,eAAgB,KAAM,GAAG,EAAE,UAAU,CAAC,CAAC;YACnG,OAAO,UAAU,CAAC,WAAW,EAAE,CAAC;QACpC,CAAC,CAAC;KACL,CAAC;AACN,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,KAAoB;IAC9C,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QACtB,OAA0F,KAAM,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;YAChH,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;gBACpB,cAAc,CAAC,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,kBAAkB,EAAE,SAAU,KAAM,GAAG,EAAE,GAAG,CAAC,CAAC;gBAC/E,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;aACtC;YACD,cAAc,CAAC,GAAG,IAAI,IAAI,IAAI,OAAM,CAAC,GAAG,CAAC,KAAK,QAAQ,EAAE,0BAA0B,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;YACpG,OAAO,YAAY,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;QACtD,CAAC,CAAC,CAAC;KACN;IAED,cAAc,CAAC,KAAK,IAAI,IAAI,IAAI,OAAM,CAAC,KAAK,CAAC,KAAK,QAAQ,EAAE,qBAAqB,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;IAEnG,MAAM,MAAM,GAA2D,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACnG,MAAM,WAAW,GAAyB,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE;YAC/E,KAAK,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC;YACzB,OAAO,KAAK,CAAC;QACjB,CAAC,EAAwB,EAAG,CAAC,CAAC;QAC9B,OAAO,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,CAAC,CAAA;IAC9D,CAAC,CAAC,CAAC;IACH,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAC5D,OAAO,MAAM,CAAC;AAClB,CAAC"} \ No newline at end of file diff --git a/lib.esm/transaction/address.d.ts b/lib.esm/transaction/address.d.ts new file mode 100644 index 00000000..0b86944f --- /dev/null +++ b/lib.esm/transaction/address.d.ts @@ -0,0 +1,15 @@ +import { SigningKey } from "../crypto/index.js"; +import type { SignatureLike } from "../crypto/index.js"; +import type { BytesLike } from "../utils/index.js"; +/** + * Returns the address for the %%key%%. + * + * The key may be any standard form of public key or a private key. + */ +export declare function computeAddress(key: string | SigningKey): string; +/** + * Returns the recovered address for the private key that was + * used to sign %%digest%% that resulted in %%signature%%. + */ +export declare function recoverAddress(digest: BytesLike, signature: SignatureLike): string; +//# sourceMappingURL=address.d.ts.map \ No newline at end of file diff --git a/lib.esm/transaction/address.d.ts.map b/lib.esm/transaction/address.d.ts.map new file mode 100644 index 00000000..83e6f094 --- /dev/null +++ b/lib.esm/transaction/address.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../src.ts/transaction/address.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAE3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,MAAM,CAQ/D;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,aAAa,GAAG,MAAM,CAElF"} \ No newline at end of file diff --git a/lib.esm/transaction/address.js b/lib.esm/transaction/address.js new file mode 100644 index 00000000..48ea3c7b --- /dev/null +++ b/lib.esm/transaction/address.js @@ -0,0 +1,25 @@ +import { getAddress } from "../address/index.js"; +import { keccak256, SigningKey } from "../crypto/index.js"; +/** + * Returns the address for the %%key%%. + * + * The key may be any standard form of public key or a private key. + */ +export function computeAddress(key) { + let pubkey; + if (typeof (key) === "string") { + pubkey = SigningKey.computePublicKey(key, false); + } + else { + pubkey = key.publicKey; + } + return getAddress(keccak256("0x" + pubkey.substring(4)).substring(26)); +} +/** + * Returns the recovered address for the private key that was + * used to sign %%digest%% that resulted in %%signature%%. + */ +export function recoverAddress(digest, signature) { + return computeAddress(SigningKey.recoverPublicKey(digest, signature)); +} +//# sourceMappingURL=address.js.map \ No newline at end of file diff --git a/lib.esm/transaction/address.js.map b/lib.esm/transaction/address.js.map new file mode 100644 index 00000000..014d2da6 --- /dev/null +++ b/lib.esm/transaction/address.js.map @@ -0,0 +1 @@ +{"version":3,"file":"address.js","sourceRoot":"","sources":["../../src.ts/transaction/address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAK3D;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,GAAwB;IACnD,IAAI,MAAc,CAAC;IACnB,IAAI,OAAM,CAAC,GAAG,CAAC,KAAK,QAAQ,EAAE;QAC1B,MAAM,GAAG,UAAU,CAAC,gBAAgB,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;KACpD;SAAM;QACH,MAAM,GAAG,GAAG,CAAC,SAAS,CAAC;KAC1B;IACD,OAAO,UAAU,CAAC,SAAS,CAAC,IAAI,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC;AAC3E,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,MAAiB,EAAE,SAAwB;IACtE,OAAO,cAAc,CAAC,UAAU,CAAC,gBAAgB,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;AAC1E,CAAC"} \ No newline at end of file diff --git a/lib.esm/transaction/coinselector-fewest.d.ts b/lib.esm/transaction/coinselector-fewest.d.ts new file mode 100644 index 00000000..8b597438 --- /dev/null +++ b/lib.esm/transaction/coinselector-fewest.d.ts @@ -0,0 +1,24 @@ +import { AbstractCoinSelector, SelectedCoinsResult, SpendTarget } from "./abstract-coinselector.js"; +/** + * The FewestCoinSelector class provides a coin selection algorithm that selects + * the fewest UTXOs required to meet the target amount. This algorithm is useful + * for minimizing the size of the transaction and the fees associated with it. + * + * This class is a sub-class of [[AbstractCoinSelector]] and implements the + * [[performSelection]] method to provide the actual coin selection logic. + */ +export declare class FewestCoinSelector extends AbstractCoinSelector { + /** + * The largest first coin selection algorithm. + * + * This algorithm selects the largest UTXOs first, and continues to select UTXOs until the + * target amount is reached. If the total value of the selected UTXOs is greater than the + * target amount, the remaining value is returned as a change output. + * @param target The target amount to select UTXOs for. + */ + performSelection(target: SpendTarget): SelectedCoinsResult; + private sortUTXOsByDenomination; + private validateTarget; + private validateUTXOs; +} +//# sourceMappingURL=coinselector-fewest.d.ts.map \ No newline at end of file diff --git a/lib.esm/transaction/coinselector-fewest.d.ts.map b/lib.esm/transaction/coinselector-fewest.d.ts.map new file mode 100644 index 00000000..d6100187 --- /dev/null +++ b/lib.esm/transaction/coinselector-fewest.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"coinselector-fewest.d.ts","sourceRoot":"","sources":["../../src.ts/transaction/coinselector-fewest.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAIpG;;;;;;;GAOG;AACH,qBAAa,kBAAmB,SAAQ,oBAAoB;IAExD;;;;;;;OAOG;IACH,gBAAgB,CAAC,MAAM,EAAE,WAAW,GAAG,mBAAmB;IA8G1D,OAAO,CAAC,uBAAuB;IAa/B,OAAO,CAAC,cAAc;IAMtB,OAAO,CAAC,aAAa;CAMxB"} \ No newline at end of file diff --git a/lib.esm/transaction/coinselector-fewest.js b/lib.esm/transaction/coinselector-fewest.js new file mode 100644 index 00000000..b76a92a0 --- /dev/null +++ b/lib.esm/transaction/coinselector-fewest.js @@ -0,0 +1,139 @@ +import { bigIntAbs } from "../utils/maths.js"; +import { AbstractCoinSelector } from "./abstract-coinselector.js"; +import { UTXO, denominate } from "./utxo.js"; +/** + * The FewestCoinSelector class provides a coin selection algorithm that selects + * the fewest UTXOs required to meet the target amount. This algorithm is useful + * for minimizing the size of the transaction and the fees associated with it. + * + * This class is a sub-class of [[AbstractCoinSelector]] and implements the + * [[performSelection]] method to provide the actual coin selection logic. + */ +export class FewestCoinSelector extends AbstractCoinSelector { + /** + * The largest first coin selection algorithm. + * + * This algorithm selects the largest UTXOs first, and continues to select UTXOs until the + * target amount is reached. If the total value of the selected UTXOs is greater than the + * target amount, the remaining value is returned as a change output. + * @param target The target amount to select UTXOs for. + */ + performSelection(target) { + this.validateTarget(target); + this.validateUTXOs(); + const sortedUTXOs = this.sortUTXOsByDenomination(this.availableUXTOs, "desc"); + let totalValue = BigInt(0); + let selectedUTXOs = []; + // Get UTXOs that meets or exceeds the target value + const UTXOsEqualOrGreaterThanTarget = sortedUTXOs.filter(utxo => utxo.denomination && utxo.denomination >= target.value); + if (UTXOsEqualOrGreaterThanTarget.length > 0) { + // Find the smallest UTXO that meets or exceeds the target value + const optimalUTXO = UTXOsEqualOrGreaterThanTarget.reduce((minDenominationUTXO, currentUTXO) => { + if (!currentUTXO.denomination) + return minDenominationUTXO; + return currentUTXO.denomination < minDenominationUTXO.denomination ? currentUTXO : minDenominationUTXO; + }, UTXOsEqualOrGreaterThanTarget[0]); // Initialize with the first UTXO in the list + selectedUTXOs.push(optimalUTXO); + totalValue += optimalUTXO.denomination; + } + else { + // If no single UTXO meets or exceeds the target, aggregate smaller denominations + // until the target is met/exceeded or there are no more UTXOs to aggregate + while (sortedUTXOs.length > 0 && totalValue < target.value) { + const nextOptimalUTXO = sortedUTXOs.reduce((closest, utxo) => { + if (!utxo.denomination) + return closest; + // Prioritize UTXOs that bring totalValue closer to target.value + const absThisDiff = bigIntAbs(target.value - (totalValue + utxo.denomination)); + const currentClosestDiff = closest && closest.denomination + ? bigIntAbs(target.value - (totalValue + closest.denomination)) + : BigInt(Infinity); + return absThisDiff < currentClosestDiff ? utxo : closest; + }, sortedUTXOs[0]); + // Add the selected UTXO to the selection and update totalValue + selectedUTXOs.push(nextOptimalUTXO); + totalValue += nextOptimalUTXO.denomination; + // Remove the selected UTXO from the list of available UTXOs + const index = sortedUTXOs.findIndex(utxo => utxo.denomination === nextOptimalUTXO.denomination && utxo.address === nextOptimalUTXO.address); + sortedUTXOs.splice(index, 1); + } + } + // Check if the selected UTXOs meet or exceed the target amount + if (totalValue < target.value) { + throw new Error("Insufficient funds"); + } + // // Check if any denominations can be removed from the input set and it still remain valid + selectedUTXOs = this.sortUTXOsByDenomination(selectedUTXOs, "asc"); + let runningTotal = totalValue; + let lastRemovableIndex = -1; // Index of the last UTXO that can be removed + // Iterate through selectedUTXOs to find the last removable UTXO + for (let i = 0; i < selectedUTXOs.length; i++) { + const utxo = selectedUTXOs[i]; + if (utxo.denomination) { + if (runningTotal - utxo.denomination >= target.value) { + runningTotal -= utxo.denomination; + lastRemovableIndex = i; + } + else { + // Once a UTXO makes the total less than target.value, stop the loop + break; + } + } + } + if (lastRemovableIndex >= 0) { + totalValue -= selectedUTXOs[lastRemovableIndex].denomination; + selectedUTXOs.splice(lastRemovableIndex, 1); + } + // Break down the total spend into properly denominatated UTXOs + const spendDenominations = denominate(target.value); + this.spendOutputs = spendDenominations.map(denomination => { + const utxo = new UTXO(); + utxo.denomination = denomination; + utxo.address = target.address; + return utxo; + }); + // Calculate change to be returned + const change = totalValue - target.value; + // If there's change, break it down into properly denominatated UTXOs + if (change > BigInt(0)) { + const changeDenominations = denominate(change); + this.changeOutputs = changeDenominations.map(denomination => { + const utxo = new UTXO(); + utxo.denomination = denomination; + // We do not have access to change addresses here so leave it null + return utxo; + }); + } + else { + this.changeOutputs = []; + } + return { + inputs: selectedUTXOs, + spendOutputs: this.spendOutputs, + changeOutputs: this.changeOutputs, + }; + } + sortUTXOsByDenomination(utxos, direction) { + if (direction === "asc") { + return [...utxos].sort((a, b) => { + const diff = (a.denomination ?? BigInt(0)) - (b.denomination ?? BigInt(0)); + return diff > 0 ? 1 : diff < 0 ? -1 : 0; + }); + } + return [...utxos].sort((a, b) => { + const diff = (b.denomination ?? BigInt(0)) - (a.denomination ?? BigInt(0)); + return diff > 0 ? 1 : diff < 0 ? -1 : 0; + }); + } + validateTarget(target) { + if (target.value <= BigInt(0)) { + throw new Error("Target amount must be greater than 0"); + } + } + validateUTXOs() { + if (this.availableUXTOs.length === 0) { + throw new Error("No UTXOs available"); + } + } +} +//# sourceMappingURL=coinselector-fewest.js.map \ No newline at end of file diff --git a/lib.esm/transaction/coinselector-fewest.js.map b/lib.esm/transaction/coinselector-fewest.js.map new file mode 100644 index 00000000..bcb304f2 --- /dev/null +++ b/lib.esm/transaction/coinselector-fewest.js.map @@ -0,0 +1 @@ +{"version":3,"file":"coinselector-fewest.js","sourceRoot":"","sources":["../../src.ts/transaction/coinselector-fewest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAoC,MAAM,4BAA4B,CAAC;AACpG,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAG7C;;;;;;;GAOG;AACH,MAAM,OAAO,kBAAmB,SAAQ,oBAAoB;IAExD;;;;;;;OAOG;IACH,gBAAgB,CAAC,MAAmB;QAChC,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;QAC5B,IAAI,CAAC,aAAa,EAAE,CAAC;QAErB,MAAM,WAAW,GAAG,IAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;QAE9E,IAAI,UAAU,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QAC3B,IAAI,aAAa,GAAW,EAAE,CAAC;QAE/B,mDAAmD;QACnD,MAAM,6BAA6B,GAAG,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,YAAY,IAAI,MAAM,CAA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,EAAE;gBAC5B,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,YAAY,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,YAAY,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC3E,OAAO,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC5C,CAAC,CAAC,CAAC;SACN;QACD,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;YAC5B,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,YAAY,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,YAAY,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;YAC3E,OAAO,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5C,CAAC,CAAC,CAAC;IACP,CAAC;IAEO,cAAc,CAAC,MAAmB;QACtC,IAAI,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE;YAC3B,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;SAC3D;IACL,CAAC;IAEO,aAAa;QACjB,IAAI,IAAI,CAAC,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE;YAClC,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;SACzC;IACL,CAAC;CAEJ"} \ No newline at end of file diff --git a/lib.esm/transaction/index.d.ts b/lib.esm/transaction/index.d.ts new file mode 100644 index 00000000..c86ad3b1 --- /dev/null +++ b/lib.esm/transaction/index.d.ts @@ -0,0 +1,26 @@ +/** + * Each state-changing operation on Ethereum requires a transaction. + * + * @_section api/transaction:Transactions [about-transactions] + */ +/** + * A single [[AccessList]] entry of storage keys (slots) for an address. + */ +export type AccessListEntry = { + address: string; + storageKeys: Array; +}; +/** + * An ordered collection of [[AccessList]] entries. + */ +export type AccessList = Array; +/** + * Any quais-supported access list structure. + */ +export type AccessListish = AccessList | Array<[string, Array]> | Record>; +export { accessListify } from "./accesslist.js"; +export { computeAddress, recoverAddress } from "./address.js"; +export { Transaction } from "./transaction.js"; +export { FewestCoinSelector } from "./coinselector-fewest.js"; +export type { TransactionLike } from "./transaction.js"; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/lib.esm/transaction/index.d.ts.map b/lib.esm/transaction/index.d.ts.map new file mode 100644 index 00000000..771ebb37 --- /dev/null +++ b/lib.esm/transaction/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src.ts/transaction/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;CAAE,CAAC;AAE9E;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,eAAe,CAAC,CAAC;AAEhD;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,UAAU,GACV,KAAK,CAAC,CAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAE,CAAC,GAChC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;AAG1D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D,YAAY,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC"} \ No newline at end of file diff --git a/lib.esm/transaction/index.js b/lib.esm/transaction/index.js new file mode 100644 index 00000000..5bb094f4 --- /dev/null +++ b/lib.esm/transaction/index.js @@ -0,0 +1,11 @@ +/** + * Each state-changing operation on Ethereum requires a transaction. + * + * @_section api/transaction:Transactions [about-transactions] + */ +null; +export { accessListify } from "./accesslist.js"; +export { computeAddress, recoverAddress } from "./address.js"; +export { Transaction } from "./transaction.js"; +export { FewestCoinSelector } from "./coinselector-fewest.js"; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib.esm/transaction/index.js.map b/lib.esm/transaction/index.js.map new file mode 100644 index 00000000..202e1c57 --- /dev/null +++ b/lib.esm/transaction/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src.ts/transaction/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,IAAI,CAAC;AAoBL,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC"} \ No newline at end of file diff --git a/lib.esm/transaction/transaction.d.ts b/lib.esm/transaction/transaction.d.ts new file mode 100644 index 00000000..37fd227b --- /dev/null +++ b/lib.esm/transaction/transaction.d.ts @@ -0,0 +1,233 @@ +import { Signature } from "../crypto/index.js"; +import type { BigNumberish, BytesLike } from "../utils/index.js"; +import type { SignatureLike } from "../crypto/index.js"; +import type { AccessList, AccessListish } from "./index.js"; +import type { UTXOEntry, UTXOTransactionOutput } from "./utxo.js"; +export interface TransactionLike { + /** + * The type. + */ + type?: null | number; + /** + * The recipient address or ``null`` for an ``init`` transaction. + */ + to?: null | A; + /** + * The sender. + */ + from: A; + /** + * The nonce. + */ + nonce?: null | number; + /** + * The maximum amount of gas that can be used. + */ + gasLimit?: null | BigNumberish; + /** + * The gas price for legacy and berlin transactions. + */ + gasPrice?: null | BigNumberish; + /** + * The maximum priority fee per gas for london transactions. + */ + maxPriorityFeePerGas?: null | BigNumberish; + /** + * The maximum total fee per gas for london transactions. + */ + maxFeePerGas?: null | BigNumberish; + /** + * The data. + */ + data?: null | string; + /** + * The value (in wei) to send. + */ + value?: null | BigNumberish; + /** + * The chain ID the transaction is valid on. + */ + chainId?: null | BigNumberish; + /** + * The transaction hash. + */ + hash?: null | string; + /** + * The signature provided by the sender. + */ + signature?: null | SignatureLike; + /** + * The access list for berlin and london transactions. + */ + accessList?: null | AccessListish; + inputsUTXO?: null | Array; + outputsUTXO?: null | Array; +} +/** + * A **Transaction** describes an operation to be executed on + * Ethereum by an Externally Owned Account (EOA). It includes + * who (the [[to]] address), what (the [[data]]) and how much (the + * [[value]] in ether) the operation should entail. + * + * @example: + * tx = new Transaction() + * //_result: + * + * tx.data = "0x1234"; + * //_result: + */ +export declare class Transaction implements TransactionLike { + #private; + from: string; + /** + * The transaction type. + * + * If null, the type will be automatically inferred based on + * explicit properties. + */ + get type(): null | number; + set type(value: null | number | string); + /** + * The name of the transaction type. + */ + get typeName(): null | string; + /** + * The ``to`` address for the transaction or ``null`` if the + * transaction is an ``init`` transaction. + */ + get to(): null | string; + set to(value: null | string); + /** + * The transaction nonce. + */ + get nonce(): number; + set nonce(value: BigNumberish); + /** + * The gas limit. + */ + get gasLimit(): bigint; + set gasLimit(value: BigNumberish); + /** + * The gas price. + * + * On legacy networks this defines the fee that will be paid. On + * EIP-1559 networks, this should be ``null``. + */ + get gasPrice(): null | bigint; + set gasPrice(value: null | BigNumberish); + /** + * The maximum priority fee per unit of gas to pay. On legacy + * networks this should be ``null``. + */ + get maxPriorityFeePerGas(): null | bigint; + set maxPriorityFeePerGas(value: null | BigNumberish); + /** + * The maximum total fee per unit of gas to pay. On legacy + * networks this should be ``null``. + */ + get maxFeePerGas(): null | bigint; + set maxFeePerGas(value: null | BigNumberish); + /** + * The transaction data. For ``init`` transactions this is the + * deployment code. + */ + get data(): string; + set data(value: BytesLike); + /** + * The amount of ether to send in this transactions. + */ + get value(): bigint; + set value(value: BigNumberish); + /** + * The chain ID this transaction is valid on. + */ + get chainId(): bigint; + set chainId(value: BigNumberish); + /** + * If signed, the signature for this transaction. + */ + get signature(): null | Signature; + set signature(value: null | SignatureLike); + /** + * The access list. + * + * An access list permits discounted (but pre-paid) access to + * bytecode and state variable access within contract execution. + */ + get accessList(): null | AccessList; + set accessList(value: null | AccessListish); + get inputsUTXO(): null | UTXOEntry[]; + set inputsUTXO(value: null | UTXOEntry[]); + get outputsUTXO(): null | UTXOTransactionOutput[]; + set outputsUTXO(value: null | UTXOTransactionOutput[]); + /** + * Creates a new Transaction with default values. + */ + constructor(from: string); + /** + * The transaction hash, if signed. Otherwise, ``null``. + */ + get hash(): null | string; + set hash(value: null | string); + /** + * The pre-image hash of this transaction. + * + * This is the digest that a [[Signer]] must sign to authorize + * this transaction. + */ + get unsignedHash(): string; + /** + * The public key of the sender, if signed. Otherwise, ``null``. + */ + get fromPublicKey(): null | string; + /** + * Returns true if signed. + * + * This provides a Type Guard that properties requiring a signed + * transaction are non-null. + */ + isSigned(): this is (Transaction & { + type: number; + typeName: string; + from: string; + signature: Signature; + }); + /** + * The serialized transaction. + * + * This throws if the transaction is unsigned. For the pre-image, + * use [[unsignedSerialized]]. + */ + get serialized(): string; + /** + * The transaction pre-image. + * + * The hash of this is the digest which needs to be signed to + * authorize this transaction. + */ + get unsignedSerialized(): string; + /** + * Return the most "likely" type; currently the highest + * supported transaction type. + */ + inferType(): number; + /** + * Validates the explicit properties and returns a list of compatible + * transaction types. + */ + inferTypes(): Array; + /** + * Create a copy of this transaciton. + */ + clone(): Transaction; + /** + * Return a JSON-friendly object. + */ + toJSON(): any; + /** + * Create a **Transaction** from a serialized transaction or a + * Transaction-like object. + */ + static from(tx: string | TransactionLike): Transaction; +} +//# sourceMappingURL=transaction.d.ts.map \ No newline at end of file diff --git a/lib.esm/transaction/transaction.d.ts.map b/lib.esm/transaction/transaction.d.ts.map new file mode 100644 index 00000000..73367fe1 --- /dev/null +++ b/lib.esm/transaction/transaction.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../src.ts/transaction/transaction.ts"],"names":[],"mappings":"AAEA,OAAO,EAAa,SAAS,EAAc,MAAM,oBAAoB,CAAC;AAStE,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,KAAK,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAElE,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,MAAM;IACvC;;OAEG;IACH,IAAI,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;IAErB;;OAEG;IACH,EAAE,CAAC,EAAE,IAAI,GAAG,CAAC,CAAC;IAEd;;OAEG;IACH,IAAI,EAAE,CAAC,CAAC;IACR;;OAEG;IACH,KAAK,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;IAEtB;;OAEG;IACH,QAAQ,CAAC,EAAE,IAAI,GAAG,YAAY,CAAC;IAE/B;;OAEG;IACH,QAAQ,CAAC,EAAE,IAAI,GAAG,YAAY,CAAC;IAE/B;;OAEG;IACH,oBAAoB,CAAC,EAAE,IAAI,GAAG,YAAY,CAAC;IAE3C;;OAEG;IACH,YAAY,CAAC,EAAE,IAAI,GAAG,YAAY,CAAC;IAEnC;;OAEG;IACH,IAAI,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;IAErB;;OAEG;IACH,KAAK,CAAC,EAAE,IAAI,GAAG,YAAY,CAAC;IAE5B;;OAEG;IACH,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G;IACH,QAAQ,IAAI,IAAI,IAAI,CAAC,WAAW,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,SAAS,CAAA;KAAE,CAAC;IAK1G;;;;;OAKG;IACH,IAAI,UAAU,IAAI,MAAM,CAIvB;IAED;;;;;OAKG;IACH,IAAI,kBAAkB,IAAI,MAAM,CAE/B;IAED;;;OAGG;IACH,SAAS,IAAI,MAAM;IAInB;;;OAGG;IACH,UAAU,IAAI,KAAK,CAAC,MAAM,CAAC;IA6B3B;;OAEG;IACH,KAAK,IAAI,WAAW;IAIpB;;OAEG;IACH,MAAM,IAAI,GAAG;IAkCb;;;OAGG;IACH,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,eAAe,CAAC,MAAM,CAAC,GAAG,WAAW;CAmCjE"} \ No newline at end of file diff --git a/lib.esm/transaction/transaction.js b/lib.esm/transaction/transaction.js new file mode 100644 index 00000000..450c734b --- /dev/null +++ b/lib.esm/transaction/transaction.js @@ -0,0 +1,490 @@ +import { getAddress } from "../address/index.js"; +import { keccak256, Signature, SigningKey } from "../crypto/index.js"; +import { getBytes, getBigInt, getNumber, hexlify, assert, assertArgument, toBeArray, zeroPadValue, encodeProto, decodeProto, toBigInt, getShardForAddress, isUTXOAddress } from "../utils/index.js"; +import { accessListify } from "./accesslist.js"; +import { computeAddress, recoverAddress } from "./address.js"; +function handleNumber(_value, param) { + if (_value === "0x") { + return 0; + } + return getNumber(_value, param); +} +function formatNumber(_value, name) { + const value = getBigInt(_value, "value"); + const result = toBeArray(value); + assertArgument(result.length <= 32, `value too large`, `tx.${name}`, value); + return result; +} +function _parseSignature(tx, fields) { + let yParity; + try { + yParity = handleNumber(fields[0], "yParity"); + if (yParity !== 0 && yParity !== 1) { + throw new Error("bad yParity"); + } + } + catch (error) { + assertArgument(false, "invalid yParity", "yParity", fields[0]); + } + const r = zeroPadValue(fields[1], 32); + const s = zeroPadValue(fields[2], 32); + const signature = Signature.from({ r, s, yParity }); + tx.signature = signature; +} +function _parse(data) { + const decodedTx = decodeProto(getBytes(data)); + const tx = { + type: decodedTx.type, + from: decodedTx.from, + chainId: toBigInt(decodedTx.chain_id), + nonce: decodedTx.nonce, + maxPriorityFeePerGas: toBigInt(decodedTx.gas_tip_cap), + maxFeePerGas: toBigInt(decodedTx.gas_fee_cap), + gasLimit: toBigInt(decodedTx.gas), + to: hexlify(decodedTx.to), + value: toBigInt(decodedTx.value), + data: hexlify(decodedTx.data), + accessList: decodedTx.access_list.access_tuples, + }; + const signatureFields = [ + hexlify(decodedTx.v), + hexlify(decodedTx.r), + hexlify(decodedTx.s), + ]; + _parseSignature(tx, signatureFields); + tx.hash = getTransactionHash(tx, data); + // Compute the sender address since it's not included in the transaction + tx.from = recoverAddress(tx.hash, tx.signature); + return tx; +} +function getTransactionHash(tx, data) { + const destShardbyte = getShardForAddress(tx.to || "")?.byte.slice(2); + const destUtxo = isUTXOAddress(tx.to || ""); + const pubKey = Transaction.from(tx).fromPublicKey; + const senderAddr = computeAddress(pubKey || ""); + const originShardByte = getShardForAddress(senderAddr)?.byte.slice(2); + const originUtxo = isUTXOAddress(senderAddr); + if (!destShardbyte || !originShardByte) { + throw new Error("Invalid Shard for from or to address"); + } + if (destShardbyte !== originShardByte && destUtxo !== originUtxo) { + throw new Error("Cross-shard & cross-ledger transactions are not supported"); + } + let hash = keccak256(data); + hash = '0x' + originShardByte + (originUtxo ? 'F' : '1') + hash.charAt(5) + originShardByte + (destUtxo ? 'F' : '1') + hash.slice(9); + //TODO alter comparison + return hash; +} +function _serialize(tx, sig) { + const formattedTx = { + chain_id: formatNumber(tx.chainId || 0, "chainId"), + nonce: (tx.nonce || 0), + gas_tip_cap: formatNumber(tx.maxPriorityFeePerGas || 0, "maxPriorityFeePerGas"), + gas_fee_cap: formatNumber(tx.maxFeePerGas || 0, "maxFeePerGas"), + gas: Number(tx.gasLimit || 0), + to: tx.to != null ? getBytes(tx.to) : "0x", + value: formatNumber(tx.value || 0, "value"), + data: getBytes(tx.data || "0x"), + access_list: { access_tuples: tx.accessList || [] }, + type: (tx.type || 0), + }; + if (tx.type == 2) { + formattedTx.tx_ins = tx.inputsUTXO; + formattedTx.tx_outs = tx.outputsUTXO; + } + if (sig) { + formattedTx.v = formatNumber(sig.yParity, "yParity"), + formattedTx.r = toBeArray(sig.r), + formattedTx.s = toBeArray(sig.s); + } + return encodeProto(formattedTx); +} +/** + * A **Transaction** describes an operation to be executed on + * Ethereum by an Externally Owned Account (EOA). It includes + * who (the [[to]] address), what (the [[data]]) and how much (the + * [[value]] in ether) the operation should entail. + * + * @example: + * tx = new Transaction() + * //_result: + * + * tx.data = "0x1234"; + * //_result: + */ +export class Transaction { + #type; + #to; + #data; + #nonce; + #gasLimit; + #gasPrice; + #maxPriorityFeePerGas; + #maxFeePerGas; + #value; + #chainId; + #sig; + #accessList; + #hash; + #inputsUTXO; + #outputsUTXO; + from; + /** + * The transaction type. + * + * If null, the type will be automatically inferred based on + * explicit properties. + */ + get type() { return this.#type; } + set type(value) { + switch (value) { + case null: + this.#type = null; + break; + case 0: + case "standard": + this.#type = 0; + break; + // case 1: case "external": + // this.#type = 1; + // break; + case 2: + case "utxo": + this.#type = 2; + break; + default: + assertArgument(false, "unsupported transaction type", "type", value); + } + } + /** + * The name of the transaction type. + */ + get typeName() { + switch (this.type) { + case 0: return "standard"; + case 1: return "external"; + case 2: return "utxo"; + } + return null; + } + /** + * The ``to`` address for the transaction or ``null`` if the + * transaction is an ``init`` transaction. + */ + get to() { return this.#to; } + set to(value) { + this.#to = (value == null) ? null : getAddress(value); + } + /** + * The transaction nonce. + */ + get nonce() { return this.#nonce; } + set nonce(value) { this.#nonce = getNumber(value, "value"); } + /** + * The gas limit. + */ + get gasLimit() { return this.#gasLimit; } + set gasLimit(value) { this.#gasLimit = getBigInt(value); } + /** + * The gas price. + * + * On legacy networks this defines the fee that will be paid. On + * EIP-1559 networks, this should be ``null``. + */ + get gasPrice() { + const value = this.#gasPrice; + return value; + } + set gasPrice(value) { + this.#gasPrice = (value == null) ? null : getBigInt(value, "gasPrice"); + } + /** + * The maximum priority fee per unit of gas to pay. On legacy + * networks this should be ``null``. + */ + get maxPriorityFeePerGas() { + const value = this.#maxPriorityFeePerGas; + if (value == null) { + return null; + } + return value; + } + set maxPriorityFeePerGas(value) { + this.#maxPriorityFeePerGas = (value == null) ? null : getBigInt(value, "maxPriorityFeePerGas"); + } + /** + * The maximum total fee per unit of gas to pay. On legacy + * networks this should be ``null``. + */ + get maxFeePerGas() { + const value = this.#maxFeePerGas; + if (value == null) { + return null; + } + return value; + } + set maxFeePerGas(value) { + this.#maxFeePerGas = (value == null) ? null : getBigInt(value, "maxFeePerGas"); + } + /** + * The transaction data. For ``init`` transactions this is the + * deployment code. + */ + get data() { return this.#data; } + set data(value) { this.#data = hexlify(value); } + /** + * The amount of ether to send in this transactions. + */ + get value() { return this.#value; } + set value(value) { + this.#value = getBigInt(value, "value"); + } + /** + * The chain ID this transaction is valid on. + */ + get chainId() { return this.#chainId; } + set chainId(value) { this.#chainId = getBigInt(value); } + /** + * If signed, the signature for this transaction. + */ + get signature() { return this.#sig || null; } + set signature(value) { + this.#sig = (value == null) ? null : Signature.from(value); + } + /** + * The access list. + * + * An access list permits discounted (but pre-paid) access to + * bytecode and state variable access within contract execution. + */ + get accessList() { + const value = this.#accessList || null; + if (value == null) { + return null; + } + return value; + } + set accessList(value) { + this.#accessList = (value == null) ? null : accessListify(value); + } + get inputsUTXO() { return this.#inputsUTXO; } + set inputsUTXO(value) { this.#inputsUTXO = value; } + get outputsUTXO() { return this.#outputsUTXO; } + set outputsUTXO(value) { this.#outputsUTXO = value; } + /** + * Creates a new Transaction with default values. + */ + constructor(from) { + this.#type = null; + this.#to = null; + this.#nonce = 0; + this.#gasLimit = BigInt(0); + this.#gasPrice = null; + this.#maxPriorityFeePerGas = null; + this.#maxFeePerGas = null; + this.#data = "0x"; + this.#value = BigInt(0); + this.#chainId = BigInt(0); + this.#sig = null; + this.#accessList = null; + this.#hash = null; + this.#inputsUTXO = null; + this.#outputsUTXO = null; + this.from = from; + } + /** + * The transaction hash, if signed. Otherwise, ``null``. + */ + get hash() { + if (this.signature == null) { + return null; + } + if (this.#hash) { + return this.#hash; + } + return keccak256(this.serialized); + } + set hash(value) { + this.#hash = value; + } + /** + * The pre-image hash of this transaction. + * + * This is the digest that a [[Signer]] must sign to authorize + * this transaction. + */ + get unsignedHash() { + return keccak256(this.unsignedSerialized); + } + /** + * The public key of the sender, if signed. Otherwise, ``null``. + */ + get fromPublicKey() { + if (this.signature == null) { + return null; + } + return SigningKey.recoverPublicKey(this.unsignedHash, this.signature); + } + /** + * Returns true if signed. + * + * This provides a Type Guard that properties requiring a signed + * transaction are non-null. + */ + isSigned() { + //isSigned(): this is SignedTransaction { + return this.signature != null; + } + /** + * The serialized transaction. + * + * This throws if the transaction is unsigned. For the pre-image, + * use [[unsignedSerialized]]. + */ + get serialized() { + assert(this.signature != null, "cannot serialize unsigned transaction; maybe you meant .unsignedSerialized", "UNSUPPORTED_OPERATION", { operation: ".serialized" }); + return _serialize(this, this.signature); + } + /** + * The transaction pre-image. + * + * The hash of this is the digest which needs to be signed to + * authorize this transaction. + */ + get unsignedSerialized() { + return _serialize(this); + } + /** + * Return the most "likely" type; currently the highest + * supported transaction type. + */ + inferType() { + return (this.inferTypes().pop()); + } + /** + * Validates the explicit properties and returns a list of compatible + * transaction types. + */ + inferTypes() { + if (this.maxFeePerGas != null && this.maxPriorityFeePerGas != null) { + assert(this.maxFeePerGas >= this.maxPriorityFeePerGas, "priorityFee cannot be more than maxFee", "BAD_DATA", { value: this }); + } + //if (this.type === 2 && hasGasPrice) { + // throw new Error("eip-1559 transaction cannot have gasPrice"); + //} + assert((this.type !== 0 && this.type !== 1), "transaction type cannot have externalGasLimit, externalGasTip, externalGasPrice, externalData, or externalAccessList", "BAD_DATA", { value: this }); + const types = []; + // Explicit type + if (this.type != null) { + types.push(this.type); + } + else { + types.push(0); + } + types.sort(); + return types; + } + /** + * Create a copy of this transaciton. + */ + clone() { + return Transaction.from(this); + } + /** + * Return a JSON-friendly object. + */ + toJSON() { + const s = (v) => { + if (v == null) { + return null; + } + return v.toString(); + }; + // Adjusted function to specifically handle the conversion of 'denomination' fields in array items + const processArrayWithBigInt = (arr) => { + return arr.map(item => ({ + address: item.address, + denomination: s(item.denomination) // Convert 'denomination' to string + })); + }; + return { + type: this.type, + to: this.to, + //from: this.from, + data: this.data, + nonce: this.nonce, + gasLimit: s(this.gasLimit), + gasPrice: s(this.gasPrice), + maxPriorityFeePerGas: s(this.maxPriorityFeePerGas), + maxFeePerGas: s(this.maxFeePerGas), + value: s(this.value), + chainId: s(this.chainId), + sig: this.signature ? this.signature.toJSON() : null, + accessList: this.accessList, + inputsUTXO: processArrayWithBigInt(this.inputsUTXO || []), + outputsUTXO: processArrayWithBigInt(this.outputsUTXO || []), + }; + } + /** + * Create a **Transaction** from a serialized transaction or a + * Transaction-like object. + */ + static from(tx) { + // if (tx == null) { return new Transaction(); } + if (typeof (tx) === "string") { + const payload = getBytes(tx); + return Transaction.from(_parse(payload)); + } + const result = new Transaction(tx.from); + if (tx.type != null) { + result.type = tx.type; + } + if (tx.to != null) { + result.to = tx.to; + } + if (tx.nonce != null) { + result.nonce = tx.nonce; + } + if (tx.gasLimit != null) { + result.gasLimit = tx.gasLimit; + } + if (tx.maxPriorityFeePerGas != null) { + result.maxPriorityFeePerGas = tx.maxPriorityFeePerGas; + } + if (tx.maxFeePerGas != null) { + result.maxFeePerGas = tx.maxFeePerGas; + } + if (tx.data != null) { + result.data = tx.data; + } + if (tx.value != null) { + result.value = tx.value; + } + if (tx.chainId != null) { + result.chainId = tx.chainId; + } + if (tx.signature != null) { + result.signature = Signature.from(tx.signature); + } + if (tx.accessList != null) { + result.accessList = tx.accessList; + } + if (tx.inputsUTXO != null) { + result.inputsUTXO = tx.inputsUTXO; + } + if (tx.outputsUTXO != null) { + result.outputsUTXO = tx.outputsUTXO; + } + if (tx.hash != null) { + assertArgument(result.isSigned(), "unsigned transaction cannot define hash", "tx", tx); + result.hash = tx.hash; + } + if (tx.from != null) { + // assertArgument(result.isSigned(), "unsigned transaction cannot define from", "tx", tx); + assertArgument(result.from.toLowerCase() === (tx.from || "").toLowerCase(), "from mismatch", "tx", tx); + result.from = tx.from; + } + return result; + } +} +//# sourceMappingURL=transaction.js.map \ No newline at end of file diff --git a/lib.esm/transaction/transaction.js.map b/lib.esm/transaction/transaction.js.map new file mode 100644 index 00000000..13addf80 --- /dev/null +++ b/lib.esm/transaction/transaction.js.map @@ -0,0 +1 @@ +{"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../src.ts/transaction/transaction.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,UAAU,EAAC,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EACH,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EACvC,MAAM,EAAE,cAAc,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,kBAAkB,EAAE,aAAa,EACzH,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAmF9D,SAAS,YAAY,CAAC,MAAc,EAAE,KAAa;IAC/C,IAAI,MAAM,KAAK,IAAI,EAAE;QAAE,OAAO,CAAC,CAAC;KAAE;IAClC,OAAO,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AACpC,CAAC;AAED,SAAS,YAAY,CAAC,MAAoB,EAAE,IAAY;IACpD,MAAM,KAAK,GAAG,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzC,MAAM,MAAM,GAAG,S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,EAAE,CAAC,IAAI,IAAI,IAAI,EAAE;YACjB,cAAc,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,yCAAyC,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;YACvF,MAAM,CAAC,IAAI,GAAG,EAAE,CAAC,IAAI,CAAC;SACzB;QAED,IAAI,EAAE,CAAC,IAAI,IAAI,IAAI,EAAE;YAC7B,sGAAsG;YAC1F,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,EAAE,eAAe,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;YACvG,MAAM,CAAC,IAAI,GAAG,EAAE,CAAC,IAAI,CAAC;SACzB;QACD,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ"} \ No newline at end of file diff --git a/lib.esm/transaction/utxo.d.ts b/lib.esm/transaction/utxo.d.ts new file mode 100644 index 00000000..7fa6146b --- /dev/null +++ b/lib.esm/transaction/utxo.d.ts @@ -0,0 +1,58 @@ +import type { BigNumberish } from "../utils/index"; +export type OutPoint = { + txhash: string; + index: number; +}; +export type UTXOTransactionInput = { + previousOutPoint: OutPoint; + pubKey: Uint8Array; +}; +export interface UTXOEntry { + denomination: null | bigint; + address: null | string; +} +export type UTXOTransactionOutput = UTXOEntry; +export type UTXOTransaction = { + chainId: bigint; + inputs: UTXOTransactionInput[]; + outputs: UTXOTransactionOutput[]; + signature?: Uint8Array; +}; +export interface UTXOLike extends UTXOEntry { + txhash?: null | string; + index?: null | number; +} +export declare const denominations: bigint[]; +/** + * Given a value, returns an array of supported denominations that sum to the value. + * @param value The value to denominate. + * @returns Array of supported denominations that sum to the value. + */ +export declare function denominate(value: bigint): bigint[]; +export declare class UTXO implements UTXOLike { + #private; + get txhash(): null | string; + set txhash(value: null | string); + get index(): null | number; + set index(value: null | number); + get address(): null | string; + set address(value: null | string); + get denomination(): null | bigint; + set denomination(value: null | BigNumberish); + /** + * Constructs a new UTXO instance with null properties. + */ + constructor(); + /** + * Converts the UTXO instance to a JSON object. + * @returns A JSON representation of the UTXO instance. + */ + toJSON(): any; + /** + * Creates a UTXO instance from a UTXOLike object. + * @param utxo The UTXOLike object to create the UTXO instance from. + * @returns A new UTXO instance. + */ + static from(utxo: UTXOLike): UTXO; +} +//# sourceMappingURL=utxo.d.ts.map \ No newline at end of file diff --git a/lib.esm/transaction/utxo.d.ts.map b/lib.esm/transaction/utxo.d.ts.map new file mode 100644 index 00000000..d22529c2 --- /dev/null +++ b/lib.esm/transaction/utxo.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"utxo.d.ts","sourceRoot":"","sources":["../../src.ts/transaction/utxo.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEnD,MAAM,MAAM,QAAQ,GAAG;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IAC/B,gBAAgB,EAAE,QAAQ,CAAC;IAC3B,MAAM,EAAE,UAAU,CAAC;CACtB,CAAC;AAEF,MAAM,WAAW,SAAS;IACtB,YAAY,EAAE,IAAI,GAAG,MAAM,CAAC;IAC5B,OAAO,EAAE,IAAI,GAAG,MAAM,CAAC;CAC1B;AAED,MAAM,MAAM,qBAAqB,GAAG,SAAS,CAAC;AAE9C,MAAM,MAAM,eAAe,GAAG;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,oBAAoB,EAAE,CAAC;IAC/B,OAAO,EAAE,qBAAqB,EAAE,CAAC;IACjC,SAAS,CAAC,EAAE,UAAU,CAAC;CAC1B,CAAC;AAEF,MAAM,WAAW,QAAS,SAAQ,SAAS;IACvC,MAAM,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;CACzB;AAED,eAAO,MAAM,aAAa,EAAE,MAAM,EAkBjC,CAAC;AAsBF;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CA0BlD;AAED,qBAAa,IAAK,YAAW,QAAQ;;IAMjC,IAAI,MAAM,IAAI,IAAI,GAAG,MAAM,CAAyB;IACpD,IAAI,MAAM,CAAC,KAAK,EAAE,IAAI,GAAG,MAAM,EAE9B;IAED,IAAI,KAAK,IAAI,IAAI,GAAG,MAAM,CAAwB;IAClD,IAAI,KAAK,CAAC,KAAK,EAAE,IAAI,GAAG,MAAM,EAE7B;IAED,IAAI,OAAO,IAAI,IAAI,GAAG,MAAM,CAA0B;IACtD,IAAI,OAAO,CAAC,KAAK,EAAE,IAAI,GAAG,MAAM,EAE/B;IAED,IAAI,YAAY,IAAI,IAAI,GAAG,MAAM,CAA+B;IAChE,IAAI,YAAY,CAAC,KAAK,EAAE,IAAI,GAAG,YAAY,EAY1C;IAED;;OAEG;;IAQH;;;OAGG;IACH,MAAM,IAAI,GAAG;IASb;;;;OAIG;IACH,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,GAAG,IAAI;CAWpC"} \ No newline at end of file diff --git a/lib.esm/transaction/utxo.js b/lib.esm/transaction/utxo.js new file mode 100644 index 00000000..9faf735f --- /dev/null +++ b/lib.esm/transaction/utxo.js @@ -0,0 +1,143 @@ +import { getAddress } from "../address/index"; +import { getBigInt } from "../utils/index"; +; +export const denominations = [ + BigInt(1), + BigInt(5), + BigInt(10), + BigInt(50), + BigInt(100), + BigInt(250), + BigInt(500), + BigInt(1000), + BigInt(5000), + BigInt(10000), + BigInt(20000), + BigInt(50000), + BigInt(100000), + BigInt(1000000), + BigInt(10000000), + BigInt(100000000), + BigInt(1000000000), // 1000000 Qi +]; +/** + * Checks if the provided denomination is valid. + * @param denomination The denomination to check. + * @returns True if the denomination is valid, false otherwise. + */ +function isValidDenomination(denomination) { + return denominations.includes(denomination); +} +/** + * Handles conversion of string to bigint, specifically for transaction parameters. + * @param value The string value to convert. + * @param param The parameter name for error context. + * @returns The bigint representation of the input string. + */ +function handleBigInt(value, param) { + if (value === "0x") { + return BigInt(0); + } + return getBigInt(value, param); +} +/** + * Given a value, returns an array of supported denominations that sum to the value. + * @param value The value to denominate. + * @returns Array of supported denominations that sum to the value. + */ +export function denominate(value) { + if (value <= BigInt(0)) { + throw new Error("Value must be greater than 0"); + } + const result = []; + let remainingValue = value; + // Iterate through denominations in descending order + for (let i = denominations.length - 1; i >= 0; i--) { + const denomination = denominations[i]; + // Add the denomination to the result array as many times as possible + while (remainingValue >= denomination) { + result.push(denomination); + remainingValue -= denomination; + } + } + if (remainingValue > 0) { + throw new Error("Unable to match the value with available denominations"); + } + return result; +} +export class UTXO { + #txhash; + #index; + #address; + #denomination; + get txhash() { return this.#txhash; } + set txhash(value) { + this.#txhash = value; + } + get index() { return this.#index; } + set index(value) { + this.#index = value; + } + get address() { return this.#address; } + set address(value) { + this.#address = (value == null) ? null : getAddress(value); + } + get denomination() { return this.#denomination; } + set denomination(value) { + if (value == null) { + this.#denomination = null; + return; + } + const denominationBigInt = handleBigInt(value.toString(), "denomination"); + if (!isValidDenomination(denominationBigInt)) { + throw new Error("Invalid denomination value"); + } + this.#denomination = denominationBigInt; + } + /** + * Constructs a new UTXO instance with null properties. + */ + constructor() { + this.#txhash = null; + this.#index = null; + this.#address = null; + this.#denomination = null; + } + /** + * Converts the UTXO instance to a JSON object. + * @returns A JSON representation of the UTXO instance. + */ + toJSON() { + return { + txhash: this.txhash, + index: this.index, + address: this.address, + denomination: this.denomination, + }; + } + /** + * Creates a UTXO instance from a UTXOLike object. + * @param utxo The UTXOLike object to create the UTXO instance from. + * @returns A new UTXO instance. + */ + static from(utxo) { + if (utxo === null) { + return new UTXO(); + } + const result = utxo instanceof UTXO ? utxo : new UTXO(); + if (utxo.txhash != null) { + result.txhash = utxo.txhash; + } + if (utxo.index != null) { + result.index = utxo.index; + } + if (utxo.address != null) { + result.address = utxo.address; + } + if (utxo.denomination != null) { + result.denomination = utxo.denomination; + } + return result; + } +} +//# sourceMappingURL=utxo.js.map \ No newline at end of file diff --git a/lib.esm/transaction/utxo.js.map b/lib.esm/transaction/utxo.js.map new file mode 100644 index 00000000..3a3d55bc --- /dev/null +++ b/lib.esm/transaction/utxo.js.map @@ -0,0 +1 @@ +{"version":3,"file":"utxo.js","sourceRoot":"","sources":["../../src.ts/transaction/utxo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAgB1C,CAAC;AAgBF,MAAM,CAAC,MAAM,aAAa,GAAa;IACnC,MAAM,CAAC,CAAC,CAAC;IACT,MAAM,CAAC,CAAC,CAAC;IACT,MAAM,CAAC,EAAE,CAAC;IACV,MAAM,CAAC,EAAE,CAAC;IACV,MAAM,CAAC,GAAG,CAAC;IACX,MAAM,CAAC,GAAG,CAAC;IACX,MAAM,CAAC,GAAG,CAAC;IACX,MAAM,CAAC,IAAI,CAAC;IACZ,MAAM,CAAC,IAAI,CAAC;IACZ,MAAM,CAAC,KAAK,CAAC;IACb,MAAM,CAAC,KAAK,CAAC;IACb,MAAM,CAAC,KAAK,CAAC;IACb,MAAM,CAAC,MAAM,CAAC;IACd,MAAM,CAAC,OAAO,CAAC;IACf,MAAM,CAAC,QAAQ,CAAC;IAChB,MAAM,CAAC,SAAS,CAAC;IACjB,MAAM,CAAC,UAAU,CAAC,EAAG,aAAa;CACrC,CAAC;AAEF;;;;GAIG;AACH,SAAS,mBAAmB,CAAC,YAAoB;IAC7C,OAAO,aAAa,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;AAChD,CAAC;AAED;;;;;GAKG;AACH,SAAS,YAAY,CAAC,KAAa,EAAE,KAAa;IAC9C,IAAI,KAAK,KAAK,IAAI,EAAE;QAAE,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;KAAE;IACzC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AAI,EAAE,CAAC;QACxD,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,EAAE;YAAE,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;SAAE;QACzD,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,EAAE;YAAE,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;SAAE;QACtD,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,EAAE;YAAE,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;SAAE;QAC5D,IAAI,IAAI,CAAC,YAAY,IAAI,IAAI,EAAE;YAAE,MAAM,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC;SAAE;QAE3E,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ"} \ No newline at end of file diff --git a/lib.esm/utils/ProtoBuf/proto_block.d.ts b/lib.esm/utils/ProtoBuf/proto_block.d.ts new file mode 100644 index 00000000..37779453 --- /dev/null +++ b/lib.esm/utils/ProtoBuf/proto_block.d.ts @@ -0,0 +1,1809 @@ +/** + * Generated by the protoc-gen-ts. DO NOT EDIT! + * compiler version: 4.25.3 + * source: proto_block.proto + * git: https://github.com/thesayyn/protoc-gen-ts */ +import * as dependency_1 from "./proto_common"; +import * as pb_1 from "google-protobuf"; +export declare namespace block { + class ProtoBlock extends pb_1.Message { + #private; + constructor(data?: any[] | ({} & (({ + header?: ProtoHeader; + }) | ({ + body?: ProtoBody; + })))); + get header(): ProtoHeader; + set header(value: ProtoHeader); + get has_header(): boolean; + get body(): ProtoBody; + set body(value: ProtoBody); + get has_body(): boolean; + get _header(): "none" | "header"; + get _body(): "none" | "body"; + static fromObject(data: { + header?: ReturnType; + body?: ReturnType; + }): ProtoBlock; + toObject(): { + header?: { + parent_hash?: { + value?: Uint8Array | undefined; + }[] | undefined; + uncle_hash?: { + value?: Uint8Array | undefined; + } | undefined; + coinbase?: Uint8Array | undefined; + evm_root?: { + value?: Uint8Array | undefined; + } | undefined; + tx_hash?: { + value?: Uint8Array | undefined; + } | undefined; + etx_hash?: { + value?: Uint8Array | undefined; + } | undefined; + etx_rollup_hash?: { + value?: Uint8Array | undefined; + } | undefined; + manifest_hash?: { + value?: Uint8Array | undefined; + }[] | undefined; + receipt_hash?: { + value?: Uint8Array | undefined; + } | undefined; + difficulty?: Uint8Array | undefined; + parent_entropy?: Uint8Array[] | undefined; + parent_delta_s?: Uint8Array[] | undefined; + number?: Uint8Array[] | undefined; + gas_limit?: number | undefined; + gas_used?: number | undefined; + base_fee?: Uint8Array | undefined; + location?: { + value?: Uint8Array | undefined; + } | undefined; + time?: number | undefined; + extra?: Uint8Array | undefined; + mix_hash?: { + value?: Uint8Array | undefined; + } | undefined; + nonce?: number | undefined; + utxo_root?: { + value?: Uint8Array | undefined; + } | undefined; + etx_set_hash?: { + value?: Uint8Array | undefined; + } | undefined; + } | undefined; + body?: { + txs?: { + transactions?: { + type?: number | undefined; + to?: Uint8Array | undefined; + nonce?: number | undefined; + value?: Uint8Array | undefined; + gas?: number | undefined; + data?: Uint8Array | undefined; + chain_id?: Uint8Array | undefined; + gas_fee_cap?: Uint8Array | undefined; + gas_tip_cap?: Uint8Array | undefined; + access_list?: { + access_tuples?: { + address?: Uint8Array | undefined; + storage_key?: { + value?: Uint8Array | undefined; + }[] | undefined; + }[] | undefined; + } | undefined; + v?: Uint8Array | undefined; + r?: Uint8Array | undefined; + s?: Uint8Array | undefined; + originating_tx_hash?: { + value?: Uint8Array | undefined; + } | undefined; + etx_index?: number | undefined; + tx_ins?: { + tx_ins?: { + previous_out_point?: { + hash?: { + value?: Uint8Array | undefined; + } | undefined; + index?: number | undefined; + } | undefined; + pub_key?: Uint8Array | undefined; + }[] | undefined; + } | undefined; + tx_outs?: { + tx_outs?: { + denomination?: number | undefined; + address?: Uint8Array | undefined; + }[] | undefined; + } | undefined; + signature?: Uint8Array | undefined; + etx_sender?: Uint8Array | undefined; + }[] | undefined; + } | undefined; + uncles?: { + headers?: { + parent_hash?: { + value?: Uint8Array | undefined; + }[] | undefined; + uncle_hash?: { + value?: Uint8Array | undefined; + } | undefined; + coinbase?: Uint8Array | undefined; + evm_root?: { + value?: Uint8Array | undefined; + } | undefined; + tx_hash?: { + value?: Uint8Array | undefined; + } | undefined; + etx_hash?: { + value?: Uint8Array | undefined; + } | undefined; + etx_rollup_hash?: { + value?: Uint8Array | undefined; + } | undefined; + manifest_hash?: { + value?: Uint8Array | undefined; + }[] | undefined; + receipt_hash?: { + value?: Uint8Array | undefined; + } | undefined; + difficulty?: Uint8Array | undefined; + parent_entropy?: Uint8Array[] | undefined; + parent_delta_s?: Uint8Array[] | undefined; + number?: Uint8Array[] | undefined; + gas_limit?: number | undefined; + gas_used?: number | undefined; + base_fee?: Uint8Array | undefined; + location?: { + value?: Uint8Array | undefined; + } | undefined; + time?: number | undefined; + extra?: Uint8Array | undefined; + mix_hash?: { + value?: Uint8Array | undefined; + } | undefined; + nonce?: number | undefined; + utxo_root?: { + value?: Uint8Array | undefined; + } | undefined; + etx_set_hash?: { + value?: Uint8Array | undefined; + } | undefined; + }[] | undefined; + } | undefined; + etxs?: { + transactions?: { + type?: number | undefined; + to?: Uint8Array | undefined; + nonce?: number | undefined; + value?: Uint8Array | undefined; + gas?: number | undefined; + data?: Uint8Array | undefined; + chain_id?: Uint8Array | undefined; + gas_fee_cap?: Uint8Array | undefined; + gas_tip_cap?: Uint8Array | undefined; + access_list?: { + access_tuples?: { + address?: Uint8Array | undefined; + storage_key?: { + value?: Uint8Array | undefined; + }[] | undefined; + }[] | undefined; + } | undefined; + v?: Uint8Array | undefined; + r?: Uint8Array | undefined; + s?: Uint8Array | undefined; + originating_tx_hash?: { + value?: Uint8Array | undefined; + } | undefined; + etx_index?: number | undefined; + tx_ins?: { + tx_ins?: { + previous_out_point?: { + hash?: { + value?: Uint8Array | undefined; + } | undefined; + index?: number | undefined; + } | undefined; + pub_key?: Uint8Array | undefined; + }[] | undefined; + } | undefined; + tx_outs?: { + tx_outs?: { + denomination?: number | undefined; + address?: Uint8Array | undefined; + }[] | undefined; + } | undefined; + signature?: Uint8Array | undefined; + etx_sender?: Uint8Array | undefined; + }[] | undefined; + } | undefined; + manifest?: { + manifest?: { + value?: Uint8Array | undefined; + }[] | undefined; + } | undefined; + } | undefined; + }; + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): ProtoBlock; + serializeBinary(): Uint8Array; + static deserializeBinary(bytes: Uint8Array): ProtoBlock; + } + class ProtoBody extends pb_1.Message { + #private; + constructor(data?: any[] | ({} & (({ + txs?: ProtoTransactions; + }) | ({ + uncles?: ProtoHeaders; + }) | ({ + etxs?: ProtoTransactions; + }) | ({ + manifest?: ProtoManifest; + })))); + get txs(): ProtoTransactions; + set txs(value: ProtoTransactions); + get has_txs(): boolean; + get uncles(): ProtoHeaders; + set uncles(value: ProtoHeaders); + get has_uncles(): boolean; + get etxs(): ProtoTransactions; + set etxs(value: ProtoTransactions); + get has_etxs(): boolean; + get manifest(): ProtoManifest; + set manifest(value: ProtoManifest); + get has_manifest(): boolean; + get _txs(): "none" | "txs"; + get _uncles(): "none" | "uncles"; + get _etxs(): "none" | "etxs"; + get _manifest(): "none" | "manifest"; + static fromObject(data: { + txs?: ReturnType; + uncles?: ReturnType; + etxs?: ReturnType; + manifest?: ReturnType; + }): ProtoBody; + toObject(): { + txs?: { + transactions?: { + type?: number | undefined; + to?: Uint8Array | undefined; + nonce?: number | undefined; + value?: Uint8Array | undefined; + gas?: number | undefined; + data?: Uint8Array | undefined; + chain_id?: Uint8Array | undefined; + gas_fee_cap?: Uint8Array | undefined; + gas_tip_cap?: Uint8Array | undefined; + access_list?: { + access_tuples?: { + address?: Uint8Array | undefined; + storage_key?: { + value?: Uint8Array | undefined; + }[] | undefined; + }[] | undefined; + } | undefined; + v?: Uint8Array | undefined; + r?: Uint8Array | undefined; + s?: Uint8Array | undefined; + originating_tx_hash?: { + value?: Uint8Array | undefined; + } | undefined; + etx_index?: number | undefined; + tx_ins?: { + tx_ins?: { + previous_out_point?: { + hash?: { + value?: Uint8Array | undefined; + } | undefined; + index?: number | undefined; + } | undefined; + pub_key?: Uint8Array | undefined; + }[] | undefined; + } | undefined; + tx_outs?: { + tx_outs?: { + denomination?: number | undefined; + address?: Uint8Array | undefined; + }[] | undefined; + } | undefined; + signature?: Uint8Array | undefined; + etx_sender?: Uint8Array | undefined; + }[] | undefined; + } | undefined; + uncles?: { + headers?: { + parent_hash?: { + value?: Uint8Array | undefined; + }[] | undefined; + uncle_hash?: { + value?: Uint8Array | undefined; + } | undefined; + coinbase?: Uint8Array | undefined; + evm_root?: { + value?: Uint8Array | undefined; + } | undefined; + tx_hash?: { + value?: Uint8Array | undefined; + } | undefined; + etx_hash?: { + value?: Uint8Array | undefined; + } | undefined; + etx_rollup_hash?: { + value?: Uint8Array | undefined; + } | undefined; + manifest_hash?: { + value?: Uint8Array | undefined; + }[] | undefined; + receipt_hash?: { + value?: Uint8Array | undefined; + } | undefined; + difficulty?: Uint8Array | undefined; + parent_entropy?: Uint8Array[] | undefined; + parent_delta_s?: Uint8Array[] | undefined; + number?: Uint8Array[] | undefined; + gas_limit?: number | undefined; + gas_used?: number | undefined; + base_fee?: Uint8Array | undefined; + location?: { + value?: Uint8Array | undefined; + } | undefined; + time?: number | undefined; + extra?: Uint8Array | undefined; + mix_hash?: { + value?: Uint8Array | undefined; + } | undefined; + nonce?: number | undefined; + utxo_root?: { + value?: Uint8Array | undefined; + } | undefined; + etx_set_hash?: { + value?: Uint8Array | undefined; + } | undefined; + }[] | undefined; + } | undefined; + etxs?: { + transactions?: { + type?: number | undefined; + to?: Uint8Array | undefined; + nonce?: number | undefined; + value?: Uint8Array | undefined; + gas?: number | undefined; + data?: Uint8Array | undefined; + chain_id?: Uint8Array | undefined; + gas_fee_cap?: Uint8Array | undefined; + gas_tip_cap?: Uint8Array | undefined; + access_list?: { + access_tuples?: { + address?: Uint8Array | undefined; + storage_key?: { + value?: Uint8Array | undefined; + }[] | undefined; + }[] | undefined; + } | undefined; + v?: Uint8Array | undefined; + r?: Uint8Array | undefined; + s?: Uint8Array | undefined; + originating_tx_hash?: { + value?: Uint8Array | undefined; + } | undefined; + etx_index?: number | undefined; + tx_ins?: { + tx_ins?: { + previous_out_point?: { + hash?: { + value?: Uint8Array | undefined; + } | undefined; + index?: number | undefined; + } | undefined; + pub_key?: Uint8Array | undefined; + }[] | undefined; + } | undefined; + tx_outs?: { + tx_outs?: { + denomination?: number | undefined; + address?: Uint8Array | undefined; + }[] | undefined; + } | undefined; + signature?: Uint8Array | undefined; + etx_sender?: Uint8Array | undefined; + }[] | undefined; + } | undefined; + manifest?: { + manifest?: { + value?: Uint8Array | undefined; + }[] | undefined; + } | undefined; + }; + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): ProtoBody; + serializeBinary(): Uint8Array; + static deserializeBinary(bytes: Uint8Array): ProtoBody; + } + class ProtoHeader extends pb_1.Message { + #private; + constructor(data?: any[] | ({ + parent_hash?: dependency_1.common.ProtoHash[]; + manifest_hash?: dependency_1.common.ProtoHash[]; + parent_entropy?: Uint8Array[]; + parent_delta_s?: Uint8Array[]; + number?: Uint8Array[]; + } & (({ + uncle_hash?: dependency_1.common.ProtoHash; + }) | ({ + coinbase?: Uint8Array; + }) | ({ + evm_root?: dependency_1.common.ProtoHash; + }) | ({ + tx_hash?: dependency_1.common.ProtoHash; + }) | ({ + etx_hash?: dependency_1.common.ProtoHash; + }) | ({ + etx_rollup_hash?: dependency_1.common.ProtoHash; + }) | ({ + receipt_hash?: dependency_1.common.ProtoHash; + }) | ({ + difficulty?: Uint8Array; + }) | ({ + gas_limit?: number; + }) | ({ + gas_used?: number; + }) | ({ + base_fee?: Uint8Array; + }) | ({ + location?: dependency_1.common.ProtoLocation; + }) | ({ + time?: number; + }) | ({ + extra?: Uint8Array; + }) | ({ + mix_hash?: dependency_1.common.ProtoHash; + }) | ({ + nonce?: number; + }) | ({ + utxo_root?: dependency_1.common.ProtoHash; + }) | ({ + etx_set_hash?: dependency_1.common.ProtoHash; + })))); + get parent_hash(): dependency_1.common.ProtoHash[]; + set parent_hash(value: dependency_1.common.ProtoHash[]); + get uncle_hash(): dependency_1.common.ProtoHash; + set uncle_hash(value: dependency_1.common.ProtoHash); + get has_uncle_hash(): boolean; + get coinbase(): Uint8Array; + set coinbase(value: Uint8Array); + get has_coinbase(): boolean; + get evm_root(): dependency_1.common.ProtoHash; + set evm_root(value: dependency_1.common.ProtoHash); + get has_evm_root(): boolean; + get tx_hash(): dependency_1.common.ProtoHash; + set tx_hash(value: dependency_1.common.ProtoHash); + get has_tx_hash(): boolean; + get etx_hash(): dependency_1.common.ProtoHash; + set etx_hash(value: dependency_1.common.ProtoHash); + get has_etx_hash(): boolean; + get etx_rollup_hash(): dependency_1.common.ProtoHash; + set etx_rollup_hash(value: dependency_1.common.ProtoHash); + get has_etx_rollup_hash(): boolean; + get manifest_hash(): dependency_1.common.ProtoHash[]; + set manifest_hash(value: dependency_1.common.ProtoHash[]); + get receipt_hash(): dependency_1.common.ProtoHash; + set receipt_hash(value: dependency_1.common.ProtoHash); + get has_receipt_hash(): boolean; + get difficulty(): Uint8Array; + set difficulty(value: Uint8Array); + get has_difficulty(): boolean; + get parent_entropy(): Uint8Array[]; + set parent_entropy(value: Uint8Array[]); + get parent_delta_s(): Uint8Array[]; + set parent_delta_s(value: Uint8Array[]); + get number(): Uint8Array[]; + set number(value: Uint8Array[]); + get gas_limit(): number; + set gas_limit(value: number); + get has_gas_limit(): boolean; + get gas_used(): number; + set gas_used(value: number); + get has_gas_used(): boolean; + get base_fee(): Uint8Array; + set base_fee(value: Uint8Array); + get has_base_fee(): boolean; + get location(): dependency_1.common.ProtoLocation; + set location(value: dependency_1.common.ProtoLocation); + get has_location(): boolean; + get time(): number; + set time(value: number); + get has_time(): boolean; + get extra(): Uint8Array; + set extra(value: Uint8Array); + get has_extra(): boolean; + get mix_hash(): dependency_1.common.ProtoHash; + set mix_hash(value: dependency_1.common.ProtoHash); + get has_mix_hash(): boolean; + get nonce(): number; + set nonce(value: number); + get has_nonce(): boolean; + get utxo_root(): dependency_1.common.ProtoHash; + set utxo_root(value: dependency_1.common.ProtoHash); + get has_utxo_root(): boolean; + get etx_set_hash(): dependency_1.common.ProtoHash; + set etx_set_hash(value: dependency_1.common.ProtoHash); + get has_etx_set_hash(): boolean; + get _uncle_hash(): "none" | "uncle_hash"; + get _coinbase(): "none" | "coinbase"; + get _evm_root(): "none" | "evm_root"; + get _tx_hash(): "none" | "tx_hash"; + get _etx_hash(): "none" | "etx_hash"; + get _etx_rollup_hash(): "none" | "etx_rollup_hash"; + get _receipt_hash(): "none" | "receipt_hash"; + get _difficulty(): "none" | "difficulty"; + get _gas_limit(): "none" | "gas_limit"; + get _gas_used(): "none" | "gas_used"; + get _base_fee(): "none" | "base_fee"; + get _location(): "none" | "location"; + get _time(): "none" | "time"; + get _extra(): "none" | "extra"; + get _mix_hash(): "none" | "mix_hash"; + get _nonce(): "none" | "nonce"; + get _utxo_root(): "none" | "utxo_root"; + get _etx_set_hash(): "none" | "etx_set_hash"; + static fromObject(data: { + parent_hash?: ReturnType[]; + uncle_hash?: ReturnType; + coinbase?: Uint8Array; + evm_root?: ReturnType; + tx_hash?: ReturnType; + etx_hash?: ReturnType; + etx_rollup_hash?: ReturnType; + manifest_hash?: ReturnType[]; + receipt_hash?: ReturnType; + difficulty?: Uint8Array; + parent_entropy?: Uint8Array[]; + parent_delta_s?: Uint8Array[]; + number?: Uint8Array[]; + gas_limit?: number; + gas_used?: number; + base_fee?: Uint8Array; + location?: ReturnType; + time?: number; + extra?: Uint8Array; + mix_hash?: ReturnType; + nonce?: number; + utxo_root?: ReturnType; + etx_set_hash?: ReturnType; + }): ProtoHeader; + toObject(): { + parent_hash?: { + value?: Uint8Array | undefined; + }[] | undefined; + uncle_hash?: { + value?: Uint8Array | undefined; + } | undefined; + coinbase?: Uint8Array | undefined; + evm_root?: { + value?: Uint8Array | undefined; + } | undefined; + tx_hash?: { + value?: Uint8Array | undefined; + } | undefined; + etx_hash?: { + value?: Uint8Array | undefined; + } | undefined; + etx_rollup_hash?: { + value?: Uint8Array | undefined; + } | undefined; + manifest_hash?: { + value?: Uint8Array | undefined; + }[] | undefined; + receipt_hash?: { + value?: Uint8Array | undefined; + } | undefined; + difficulty?: Uint8Array | undefined; + parent_entropy?: Uint8Array[] | undefined; + parent_delta_s?: Uint8Array[] | undefined; + number?: Uint8Array[] | undefined; + gas_limit?: number | undefined; + gas_used?: number | undefined; + base_fee?: Uint8Array | undefined; + location?: { + value?: Uint8Array | undefined; + } | undefined; + time?: number | undefined; + extra?: Uint8Array | undefined; + mix_hash?: { + value?: Uint8Array | undefined; + } | undefined; + nonce?: number | undefined; + utxo_root?: { + value?: Uint8Array | undefined; + } | undefined; + etx_set_hash?: { + value?: Uint8Array | undefined; + } | undefined; + }; + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): ProtoHeader; + serializeBinary(): Uint8Array; + static deserializeBinary(bytes: Uint8Array): ProtoHeader; + } + class ProtoTransaction extends pb_1.Message { + #private; + constructor(data?: any[] | ({} & (({ + type?: number; + }) | ({ + to?: Uint8Array; + }) | ({ + nonce?: number; + }) | ({ + value?: Uint8Array; + }) | ({ + gas?: number; + }) | ({ + data?: Uint8Array; + }) | ({ + chain_id?: Uint8Array; + }) | ({ + gas_fee_cap?: Uint8Array; + }) | ({ + gas_tip_cap?: Uint8Array; + }) | ({ + access_list?: ProtoAccessList; + }) | ({ + v?: Uint8Array; + }) | ({ + r?: Uint8Array; + }) | ({ + s?: Uint8Array; + }) | ({ + originating_tx_hash?: dependency_1.common.ProtoHash; + }) | ({ + etx_index?: number; + }) | ({ + tx_ins?: ProtoTxIns; + }) | ({ + tx_outs?: ProtoTxOuts; + }) | ({ + signature?: Uint8Array; + }) | ({ + etx_sender?: Uint8Array; + })))); + get type(): number; + set type(value: number); + get has_type(): boolean; + get to(): Uint8Array; + set to(value: Uint8Array); + get has_to(): boolean; + get nonce(): number; + set nonce(value: number); + get has_nonce(): boolean; + get value(): Uint8Array; + set value(value: Uint8Array); + get has_value(): boolean; + get gas(): number; + set gas(value: number); + get has_gas(): boolean; + get data(): Uint8Array; + set data(value: Uint8Array); + get has_data(): boolean; + get chain_id(): Uint8Array; + set chain_id(value: Uint8Array); + get has_chain_id(): boolean; + get gas_fee_cap(): Uint8Array; + set gas_fee_cap(value: Uint8Array); + get has_gas_fee_cap(): boolean; + get gas_tip_cap(): Uint8Array; + set gas_tip_cap(value: Uint8Array); + get has_gas_tip_cap(): boolean; + get access_list(): ProtoAccessList; + set access_list(value: ProtoAccessList); + get has_access_list(): boolean; + get v(): Uint8Array; + set v(value: Uint8Array); + get has_v(): boolean; + get r(): Uint8Array; + set r(value: Uint8Array); + get has_r(): boolean; + get s(): Uint8Array; + set s(value: Uint8Array); + get has_s(): boolean; + get originating_tx_hash(): dependency_1.common.ProtoHash; + set originating_tx_hash(value: dependency_1.common.ProtoHash); + get has_originating_tx_hash(): boolean; + get etx_index(): number; + set etx_index(value: number); + get has_etx_index(): boolean; + get tx_ins(): ProtoTxIns; + set tx_ins(value: ProtoTxIns); + get has_tx_ins(): boolean; + get tx_outs(): ProtoTxOuts; + set tx_outs(value: ProtoTxOuts); + get has_tx_outs(): boolean; + get signature(): Uint8Array; + set signature(value: Uint8Array); + get has_signature(): boolean; + get etx_sender(): Uint8Array; + set etx_sender(value: Uint8Array); + get has_etx_sender(): boolean; + get _type(): "none" | "type"; + get _to(): "none" | "to"; + get _nonce(): "none" | "nonce"; + get _value(): "none" | "value"; + get _gas(): "none" | "gas"; + get _data(): "none" | "data"; + get _chain_id(): "none" | "chain_id"; + get _gas_fee_cap(): "none" | "gas_fee_cap"; + get _gas_tip_cap(): "none" | "gas_tip_cap"; + get _access_list(): "none" | "access_list"; + get _v(): "none" | "v"; + get _r(): "none" | "r"; + get _s(): "none" | "s"; + get _originating_tx_hash(): "none" | "originating_tx_hash"; + get _etx_index(): "none" | "etx_index"; + get _tx_ins(): "none" | "tx_ins"; + get _tx_outs(): "none" | "tx_outs"; + get _signature(): "none" | "signature"; + get _etx_sender(): "none" | "etx_sender"; + static fromObject(data: { + type?: number; + to?: Uint8Array; + nonce?: number; + value?: Uint8Array; + gas?: number; + data?: Uint8Array; + chain_id?: Uint8Array; + gas_fee_cap?: Uint8Array; + gas_tip_cap?: Uint8Array; + access_list?: ReturnType; + v?: Uint8Array; + r?: Uint8Array; + s?: Uint8Array; + originating_tx_hash?: ReturnType; + etx_index?: number; + tx_ins?: ReturnType; + tx_outs?: ReturnType; + signature?: Uint8Array; + etx_sender?: Uint8Array; + }): ProtoTransaction; + toObject(): { + type?: number | undefined; + to?: Uint8Array | undefined; + nonce?: number | undefined; + value?: Uint8Array | undefined; + gas?: number | undefined; + data?: Uint8Array | undefined; + chain_id?: Uint8Array | undefined; + gas_fee_cap?: Uint8Array | undefined; + gas_tip_cap?: Uint8Array | undefined; + access_list?: { + access_tuples?: { + address?: Uint8Array | undefined; + storage_key?: { + value?: Uint8Array | undefined; + }[] | undefined; + }[] | undefined; + } | undefined; + v?: Uint8Array | undefined; + r?: Uint8Array | undefined; + s?: Uint8Array | undefined; + originating_tx_hash?: { + value?: Uint8Array | undefined; + } | undefined; + etx_index?: number | undefined; + tx_ins?: { + tx_ins?: { + previous_out_point?: { + hash?: { + value?: Uint8Array | undefined; + } | undefined; + index?: number | undefined; + } | undefined; + pub_key?: Uint8Array | undefined; + }[] | undefined; + } | undefined; + tx_outs?: { + tx_outs?: { + denomination?: number | undefined; + address?: Uint8Array | undefined; + }[] | undefined; + } | undefined; + signature?: Uint8Array | undefined; + etx_sender?: Uint8Array | undefined; + }; + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): ProtoTransaction; + serializeBinary(): Uint8Array; + static deserializeBinary(bytes: Uint8Array): ProtoTransaction; + } + class ProtoTransactions extends pb_1.Message { + #private; + constructor(data?: any[] | { + transactions?: ProtoTransaction[]; + }); + get transactions(): ProtoTransaction[]; + set transactions(value: ProtoTransaction[]); + static fromObject(data: { + transactions?: ReturnType[]; + }): ProtoTransactions; + toObject(): { + transactions?: { + type?: number | undefined; + to?: Uint8Array | undefined; + nonce?: number | undefined; + value?: Uint8Array | undefined; + gas?: number | undefined; + data?: Uint8Array | undefined; + chain_id?: Uint8Array | undefined; + gas_fee_cap?: Uint8Array | undefined; + gas_tip_cap?: Uint8Array | undefined; + access_list?: { + access_tuples?: { + address?: Uint8Array | undefined; + storage_key?: { + value?: Uint8Array | undefined; + }[] | undefined; + }[] | undefined; + } | undefined; + v?: Uint8Array | undefined; + r?: Uint8Array | undefined; + s?: Uint8Array | undefined; + originating_tx_hash?: { + value?: Uint8Array | undefined; + } | undefined; + etx_index?: number | undefined; + tx_ins?: { + tx_ins?: { + previous_out_point?: { + hash?: { + value?: Uint8Array | undefined; + } | undefined; + index?: number | undefined; + } | undefined; + pub_key?: Uint8Array | undefined; + }[] | undefined; + } | undefined; + tx_outs?: { + tx_outs?: { + denomination?: number | undefined; + address?: Uint8Array | undefined; + }[] | undefined; + } | undefined; + signature?: Uint8Array | undefined; + etx_sender?: Uint8Array | undefined; + }[] | undefined; + }; + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): ProtoTransactions; + serializeBinary(): Uint8Array; + static deserializeBinary(bytes: Uint8Array): ProtoTransactions; + } + class ProtoHeaders extends pb_1.Message { + #private; + constructor(data?: any[] | { + headers?: ProtoHeader[]; + }); + get headers(): ProtoHeader[]; + set headers(value: ProtoHeader[]); + static fromObject(data: { + headers?: ReturnType[]; + }): ProtoHeaders; + toObject(): { + headers?: { + parent_hash?: { + value?: Uint8Array | undefined; + }[] | undefined; + uncle_hash?: { + value?: Uint8Array | undefined; + } | undefined; + coinbase?: Uint8Array | undefined; + evm_root?: { + value?: Uint8Array | undefined; + } | undefined; + tx_hash?: { + value?: Uint8Array | undefined; + } | undefined; + etx_hash?: { + value?: Uint8Array | undefined; + } | undefined; + etx_rollup_hash?: { + value?: Uint8Array | undefined; + } | undefined; + manifest_hash?: { + value?: Uint8Array | undefined; + }[] | undefined; + receipt_hash?: { + value?: Uint8Array | undefined; + } | undefined; + difficulty?: Uint8Array | undefined; + parent_entropy?: Uint8Array[] | undefined; + parent_delta_s?: Uint8Array[] | undefined; + number?: Uint8Array[] | undefined; + gas_limit?: number | undefined; + gas_used?: number | undefined; + base_fee?: Uint8Array | undefined; + location?: { + value?: Uint8Array | undefined; + } | undefined; + time?: number | undefined; + extra?: Uint8Array | undefined; + mix_hash?: { + value?: Uint8Array | undefined; + } | undefined; + nonce?: number | undefined; + utxo_root?: { + value?: Uint8Array | undefined; + } | undefined; + etx_set_hash?: { + value?: Uint8Array | undefined; + } | undefined; + }[] | undefined; + }; + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): ProtoHeaders; + serializeBinary(): Uint8Array; + static deserializeBinary(bytes: Uint8Array): ProtoHeaders; + } + class ProtoManifest extends pb_1.Message { + #private; + constructor(data?: any[] | { + manifest?: dependency_1.common.ProtoHash[]; + }); + get manifest(): dependency_1.common.ProtoHash[]; + set manifest(value: dependency_1.common.ProtoHash[]); + static fromObject(data: { + manifest?: ReturnType[]; + }): ProtoManifest; + toObject(): { + manifest?: { + value?: Uint8Array | undefined; + }[] | undefined; + }; + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): ProtoManifest; + serializeBinary(): Uint8Array; + static deserializeBinary(bytes: Uint8Array): ProtoManifest; + } + class ProtoAccessList extends pb_1.Message { + #private; + constructor(data?: any[] | { + access_tuples?: ProtoAccessTuple[]; + }); + get access_tuples(): ProtoAccessTuple[]; + set access_tuples(value: ProtoAccessTuple[]); + static fromObject(data: { + access_tuples?: ReturnType[]; + }): ProtoAccessList; + toObject(): { + access_tuples?: { + address?: Uint8Array | undefined; + storage_key?: { + value?: Uint8Array | undefined; + }[] | undefined; + }[] | undefined; + }; + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): ProtoAccessList; + serializeBinary(): Uint8Array; + static deserializeBinary(bytes: Uint8Array): ProtoAccessList; + } + class ProtoAccessTuple extends pb_1.Message { + #private; + constructor(data?: any[] | { + address?: Uint8Array; + storage_key?: dependency_1.common.ProtoHash[]; + }); + get address(): Uint8Array; + set address(value: Uint8Array); + get storage_key(): dependency_1.common.ProtoHash[]; + set storage_key(value: dependency_1.common.ProtoHash[]); + static fromObject(data: { + address?: Uint8Array; + storage_key?: ReturnType[]; + }): ProtoAccessTuple; + toObject(): { + address?: Uint8Array | undefined; + storage_key?: { + value?: Uint8Array | undefined; + }[] | undefined; + }; + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): ProtoAccessTuple; + serializeBinary(): Uint8Array; + static deserializeBinary(bytes: Uint8Array): ProtoAccessTuple; + } + class ProtoReceiptForStorage extends pb_1.Message { + #private; + constructor(data?: any[] | { + post_state_or_status?: Uint8Array; + cumulative_gas_used?: number; + tx_hash?: dependency_1.common.ProtoHash; + contract_address?: dependency_1.common.ProtoAddress; + logs?: ProtoLogsForStorage; + etxs?: ProtoTransactions; + gas_used?: number; + }); + get post_state_or_status(): Uint8Array; + set post_state_or_status(value: Uint8Array); + get cumulative_gas_used(): number; + set cumulative_gas_used(value: number); + get tx_hash(): dependency_1.common.ProtoHash; + set tx_hash(value: dependency_1.common.ProtoHash); + get has_tx_hash(): boolean; + get contract_address(): dependency_1.common.ProtoAddress; + set contract_address(value: dependency_1.common.ProtoAddress); + get has_contract_address(): boolean; + get logs(): ProtoLogsForStorage; + set logs(value: ProtoLogsForStorage); + get has_logs(): boolean; + get etxs(): ProtoTransactions; + set etxs(value: ProtoTransactions); + get has_etxs(): boolean; + get gas_used(): number; + set gas_used(value: number); + static fromObject(data: { + post_state_or_status?: Uint8Array; + cumulative_gas_used?: number; + tx_hash?: ReturnType; + contract_address?: ReturnType; + logs?: ReturnType; + etxs?: ReturnType; + gas_used?: number; + }): ProtoReceiptForStorage; + toObject(): { + post_state_or_status?: Uint8Array | undefined; + cumulative_gas_used?: number | undefined; + tx_hash?: { + value?: Uint8Array | undefined; + } | undefined; + contract_address?: { + value?: Uint8Array | undefined; + } | undefined; + logs?: { + logs?: { + address?: { + value?: Uint8Array | undefined; + } | undefined; + topics?: { + value?: Uint8Array | undefined; + }[] | undefined; + data?: Uint8Array | undefined; + }[] | undefined; + } | undefined; + etxs?: { + transactions?: { + type?: number | undefined; + to?: Uint8Array | undefined; + nonce?: number | undefined; + value?: Uint8Array | undefined; + gas?: number | undefined; + data?: Uint8Array | undefined; + chain_id?: Uint8Array | undefined; + gas_fee_cap?: Uint8Array | undefined; + gas_tip_cap?: Uint8Array | undefined; + access_list?: { + access_tuples?: { + address?: Uint8Array | undefined; + storage_key?: { + value?: Uint8Array | undefined; + }[] | undefined; + }[] | undefined; + } | undefined; + v?: Uint8Array | undefined; + r?: Uint8Array | undefined; + s?: Uint8Array | undefined; + originating_tx_hash?: { + value?: Uint8Array | undefined; + } | undefined; + etx_index?: number | undefined; + tx_ins?: { + tx_ins?: { + previous_out_point?: { + hash?: { + value?: Uint8Array | undefined; + } | undefined; + index?: number | undefined; + } | undefined; + pub_key?: Uint8Array | undefined; + }[] | undefined; + } | undefined; + tx_outs?: { + tx_outs?: { + denomination?: number | undefined; + address?: Uint8Array | undefined; + }[] | undefined; + } | undefined; + signature?: Uint8Array | undefined; + etx_sender?: Uint8Array | undefined; + }[] | undefined; + } | undefined; + gas_used?: number | undefined; + }; + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): ProtoReceiptForStorage; + serializeBinary(): Uint8Array; + static deserializeBinary(bytes: Uint8Array): ProtoReceiptForStorage; + } + class ProtoReceiptsForStorage extends pb_1.Message { + #private; + constructor(data?: any[] | { + receipts?: ProtoReceiptForStorage[]; + }); + get receipts(): ProtoReceiptForStorage[]; + set receipts(value: ProtoReceiptForStorage[]); + static fromObject(data: { + receipts?: ReturnType[]; + }): ProtoReceiptsForStorage; + toObject(): { + receipts?: { + post_state_or_status?: Uint8Array | undefined; + cumulative_gas_used?: number | undefined; + tx_hash?: { + value?: Uint8Array | undefined; + } | undefined; + contract_address?: { + value?: Uint8Array | undefined; + } | undefined; + logs?: { + logs?: { + address?: { + value?: Uint8Array | undefined; + } | undefined; + topics?: { + value?: Uint8Array | undefined; + }[] | undefined; + data?: Uint8Array | undefined; + }[] | undefined; + } | undefined; + etxs?: { + transactions?: { + type?: number | undefined; + to?: Uint8Array | undefined; + nonce?: number | undefined; + value?: Uint8Array | undefined; + gas?: number | undefined; + data?: Uint8Array | undefined; + chain_id?: Uint8Array | undefined; + gas_fee_cap?: Uint8Array | undefined; + gas_tip_cap?: Uint8Array | undefined; + access_list?: { + access_tuples?: { + address?: Uint8Array | undefined; + storage_key?: { + value?: Uint8Array | undefined; + }[] | undefined; + }[] | undefined; + } | undefined; + v?: Uint8Array | undefined; + r?: Uint8Array | undefined; + s?: Uint8Array | undefined; + originating_tx_hash?: { + value?: Uint8Array | undefined; + } | undefined; + etx_index?: number | undefined; + tx_ins?: { + tx_ins?: { + previous_out_point?: { + hash?: { + value?: Uint8Array | undefined; + } | undefined; + index?: number | undefined; + } | undefined; + pub_key?: Uint8Array | undefined; + }[] | undefined; + } | undefined; + tx_outs?: { + tx_outs?: { + denomination?: number | undefined; + address?: Uint8Array | undefined; + }[] | undefined; + } | undefined; + signature?: Uint8Array | undefined; + etx_sender?: Uint8Array | undefined; + }[] | undefined; + } | undefined; + gas_used?: number | undefined; + }[] | undefined; + }; + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): ProtoReceiptsForStorage; + serializeBinary(): Uint8Array; + static deserializeBinary(bytes: Uint8Array): ProtoReceiptsForStorage; + } + class ProtoLogForStorage extends pb_1.Message { + #private; + constructor(data?: any[] | { + address?: dependency_1.common.ProtoAddress; + topics?: dependency_1.common.ProtoHash[]; + data?: Uint8Array; + }); + get address(): dependency_1.common.ProtoAddress; + set address(value: dependency_1.common.ProtoAddress); + get has_address(): boolean; + get topics(): dependency_1.common.ProtoHash[]; + set topics(value: dependency_1.common.ProtoHash[]); + get data(): Uint8Array; + set data(value: Uint8Array); + static fromObject(data: { + address?: ReturnType; + topics?: ReturnType[]; + data?: Uint8Array; + }): ProtoLogForStorage; + toObject(): { + address?: { + value?: Uint8Array | undefined; + } | undefined; + topics?: { + value?: Uint8Array | undefined; + }[] | undefined; + data?: Uint8Array | undefined; + }; + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): ProtoLogForStorage; + serializeBinary(): Uint8Array; + static deserializeBinary(bytes: Uint8Array): ProtoLogForStorage; + } + class ProtoLogsForStorage extends pb_1.Message { + #private; + constructor(data?: any[] | { + logs?: ProtoLogForStorage[]; + }); + get logs(): ProtoLogForStorage[]; + set logs(value: ProtoLogForStorage[]); + static fromObject(data: { + logs?: ReturnType[]; + }): ProtoLogsForStorage; + toObject(): { + logs?: { + address?: { + value?: Uint8Array | undefined; + } | undefined; + topics?: { + value?: Uint8Array | undefined; + }[] | undefined; + data?: Uint8Array | undefined; + }[] | undefined; + }; + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): ProtoLogsForStorage; + serializeBinary(): Uint8Array; + static deserializeBinary(bytes: Uint8Array): ProtoLogsForStorage; + } + class ProtoPendingHeader extends pb_1.Message { + #private; + constructor(data?: any[] | ({} & (({ + header?: ProtoHeader; + }) | ({ + termini?: ProtoTermini; + })))); + get header(): ProtoHeader; + set header(value: ProtoHeader); + get has_header(): boolean; + get termini(): ProtoTermini; + set termini(value: ProtoTermini); + get has_termini(): boolean; + get _header(): "none" | "header"; + get _termini(): "none" | "termini"; + static fromObject(data: { + header?: ReturnType; + termini?: ReturnType; + }): ProtoPendingHeader; + toObject(): { + header?: { + parent_hash?: { + value?: Uint8Array | undefined; + }[] | undefined; + uncle_hash?: { + value?: Uint8Array | undefined; + } | undefined; + coinbase?: Uint8Array | undefined; + evm_root?: { + value?: Uint8Array | undefined; + } | undefined; + tx_hash?: { + value?: Uint8Array | undefined; + } | undefined; + etx_hash?: { + value?: Uint8Array | undefined; + } | undefined; + etx_rollup_hash?: { + value?: Uint8Array | undefined; + } | undefined; + manifest_hash?: { + value?: Uint8Array | undefined; + }[] | undefined; + receipt_hash?: { + value?: Uint8Array | undefined; + } | undefined; + difficulty?: Uint8Array | undefined; + parent_entropy?: Uint8Array[] | undefined; + parent_delta_s?: Uint8Array[] | undefined; + number?: Uint8Array[] | undefined; + gas_limit?: number | undefined; + gas_used?: number | undefined; + base_fee?: Uint8Array | undefined; + location?: { + value?: Uint8Array | undefined; + } | undefined; + time?: number | undefined; + extra?: Uint8Array | undefined; + mix_hash?: { + value?: Uint8Array | undefined; + } | undefined; + nonce?: number | undefined; + utxo_root?: { + value?: Uint8Array | undefined; + } | undefined; + etx_set_hash?: { + value?: Uint8Array | undefined; + } | undefined; + } | undefined; + termini?: { + dom_termini?: { + value?: Uint8Array | undefined; + }[] | undefined; + sub_termini?: { + value?: Uint8Array | undefined; + }[] | undefined; + } | undefined; + }; + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): ProtoPendingHeader; + serializeBinary(): Uint8Array; + static deserializeBinary(bytes: Uint8Array): ProtoPendingHeader; + } + class ProtoTermini extends pb_1.Message { + #private; + constructor(data?: any[] | { + dom_termini?: dependency_1.common.ProtoHash[]; + sub_termini?: dependency_1.common.ProtoHash[]; + }); + get dom_termini(): dependency_1.common.ProtoHash[]; + set dom_termini(value: dependency_1.common.ProtoHash[]); + get sub_termini(): dependency_1.common.ProtoHash[]; + set sub_termini(value: dependency_1.common.ProtoHash[]); + static fromObject(data: { + dom_termini?: ReturnType[]; + sub_termini?: ReturnType[]; + }): ProtoTermini; + toObject(): { + dom_termini?: { + value?: Uint8Array | undefined; + }[] | undefined; + sub_termini?: { + value?: Uint8Array | undefined; + }[] | undefined; + }; + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): ProtoTermini; + serializeBinary(): Uint8Array; + static deserializeBinary(bytes: Uint8Array): ProtoTermini; + } + class ProtoEtxSet extends pb_1.Message { + #private; + constructor(data?: any[] | ({} & (({ + etx_hashes?: Uint8Array; + })))); + get etx_hashes(): Uint8Array; + set etx_hashes(value: Uint8Array); + get has_etx_hashes(): boolean; + get _etx_hashes(): "none" | "etx_hashes"; + static fromObject(data: { + etx_hashes?: Uint8Array; + }): ProtoEtxSet; + toObject(): { + etx_hashes?: Uint8Array | undefined; + }; + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): ProtoEtxSet; + serializeBinary(): Uint8Array; + static deserializeBinary(bytes: Uint8Array): ProtoEtxSet; + } + class ProtoPendingEtxs extends pb_1.Message { + #private; + constructor(data?: any[] | ({} & (({ + header?: ProtoHeader; + }) | ({ + etxs?: ProtoTransactions; + })))); + get header(): ProtoHeader; + set header(value: ProtoHeader); + get has_header(): boolean; + get etxs(): ProtoTransactions; + set etxs(value: ProtoTransactions); + get has_etxs(): boolean; + get _header(): "none" | "header"; + get _etxs(): "none" | "etxs"; + static fromObject(data: { + header?: ReturnType; + etxs?: ReturnType; + }): ProtoPendingEtxs; + toObject(): { + header?: { + parent_hash?: { + value?: Uint8Array | undefined; + }[] | undefined; + uncle_hash?: { + value?: Uint8Array | undefined; + } | undefined; + coinbase?: Uint8Array | undefined; + evm_root?: { + value?: Uint8Array | undefined; + } | undefined; + tx_hash?: { + value?: Uint8Array | undefined; + } | undefined; + etx_hash?: { + value?: Uint8Array | undefined; + } | undefined; + etx_rollup_hash?: { + value?: Uint8Array | undefined; + } | undefined; + manifest_hash?: { + value?: Uint8Array | undefined; + }[] | undefined; + receipt_hash?: { + value?: Uint8Array | undefined; + } | undefined; + difficulty?: Uint8Array | undefined; + parent_entropy?: Uint8Array[] | undefined; + parent_delta_s?: Uint8Array[] | undefined; + number?: Uint8Array[] | undefined; + gas_limit?: number | undefined; + gas_used?: number | undefined; + base_fee?: Uint8Array | undefined; + location?: { + value?: Uint8Array | undefined; + } | undefined; + time?: number | undefined; + extra?: Uint8Array | undefined; + mix_hash?: { + value?: Uint8Array | undefined; + } | undefined; + nonce?: number | undefined; + utxo_root?: { + value?: Uint8Array | undefined; + } | undefined; + etx_set_hash?: { + value?: Uint8Array | undefined; + } | undefined; + } | undefined; + etxs?: { + transactions?: { + type?: number | undefined; + to?: Uint8Array | undefined; + nonce?: number | undefined; + value?: Uint8Array | undefined; + gas?: number | undefined; + data?: Uint8Array | undefined; + chain_id?: Uint8Array | undefined; + gas_fee_cap?: Uint8Array | undefined; + gas_tip_cap?: Uint8Array | undefined; + access_list?: { + access_tuples?: { + address?: Uint8Array | undefined; + storage_key?: { + value?: Uint8Array | undefined; + }[] | undefined; + }[] | undefined; + } | undefined; + v?: Uint8Array | undefined; + r?: Uint8Array | undefined; + s?: Uint8Array | undefined; + originating_tx_hash?: { + value?: Uint8Array | undefined; + } | undefined; + etx_index?: number | undefined; + tx_ins?: { + tx_ins?: { + previous_out_point?: { + hash?: { + value?: Uint8Array | undefined; + } | undefined; + index?: number | undefined; + } | undefined; + pub_key?: Uint8Array | undefined; + }[] | undefined; + } | undefined; + tx_outs?: { + tx_outs?: { + denomination?: number | undefined; + address?: Uint8Array | undefined; + }[] | undefined; + } | undefined; + signature?: Uint8Array | undefined; + etx_sender?: Uint8Array | undefined; + }[] | undefined; + } | undefined; + }; + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): ProtoPendingEtxs; + serializeBinary(): Uint8Array; + static deserializeBinary(bytes: Uint8Array): ProtoPendingEtxs; + } + class ProtoPendingEtxsRollup extends pb_1.Message { + #private; + constructor(data?: any[] | ({} & (({ + header?: ProtoHeader; + }) | ({ + etxs_rollup?: ProtoTransactions; + })))); + get header(): ProtoHeader; + set header(value: ProtoHeader); + get has_header(): boolean; + get etxs_rollup(): ProtoTransactions; + set etxs_rollup(value: ProtoTransactions); + get has_etxs_rollup(): boolean; + get _header(): "none" | "header"; + get _etxs_rollup(): "none" | "etxs_rollup"; + static fromObject(data: { + header?: ReturnType; + etxs_rollup?: ReturnType; + }): ProtoPendingEtxsRollup; + toObject(): { + header?: { + parent_hash?: { + value?: Uint8Array | undefined; + }[] | undefined; + uncle_hash?: { + value?: Uint8Array | undefined; + } | undefined; + coinbase?: Uint8Array | undefined; + evm_root?: { + value?: Uint8Array | undefined; + } | undefined; + tx_hash?: { + value?: Uint8Array | undefined; + } | undefined; + etx_hash?: { + value?: Uint8Array | undefined; + } | undefined; + etx_rollup_hash?: { + value?: Uint8Array | undefined; + } | undefined; + manifest_hash?: { + value?: Uint8Array | undefined; + }[] | undefined; + receipt_hash?: { + value?: Uint8Array | undefined; + } | undefined; + difficulty?: Uint8Array | undefined; + parent_entropy?: Uint8Array[] | undefined; + parent_delta_s?: Uint8Array[] | undefined; + number?: Uint8Array[] | undefined; + gas_limit?: number | undefined; + gas_used?: number | undefined; + base_fee?: Uint8Array | undefined; + location?: { + value?: Uint8Array | undefined; + } | undefined; + time?: number | undefined; + extra?: Uint8Array | undefined; + mix_hash?: { + value?: Uint8Array | undefined; + } | undefined; + nonce?: number | undefined; + utxo_root?: { + value?: Uint8Array | undefined; + } | undefined; + etx_set_hash?: { + value?: Uint8Array | undefined; + } | undefined; + } | undefined; + etxs_rollup?: { + transactions?: { + type?: number | undefined; + to?: Uint8Array | undefined; + nonce?: number | undefined; + value?: Uint8Array | undefined; + gas?: number | undefined; + data?: Uint8Array | undefined; + chain_id?: Uint8Array | undefined; + gas_fee_cap?: Uint8Array | undefined; + gas_tip_cap?: Uint8Array | undefined; + access_list?: { + access_tuples?: { + address?: Uint8Array | undefined; + storage_key?: { + value?: Uint8Array | undefined; + }[] | undefined; + }[] | undefined; + } | undefined; + v?: Uint8Array | undefined; + r?: Uint8Array | undefined; + s?: Uint8Array | undefined; + originating_tx_hash?: { + value?: Uint8Array | undefined; + } | undefined; + etx_index?: number | undefined; + tx_ins?: { + tx_ins?: { + previous_out_point?: { + hash?: { + value?: Uint8Array | undefined; + } | undefined; + index?: number | undefined; + } | undefined; + pub_key?: Uint8Array | undefined; + }[] | undefined; + } | undefined; + tx_outs?: { + tx_outs?: { + denomination?: number | undefined; + address?: Uint8Array | undefined; + }[] | undefined; + } | undefined; + signature?: Uint8Array | undefined; + etx_sender?: Uint8Array | undefined; + }[] | undefined; + } | undefined; + }; + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): ProtoPendingEtxsRollup; + serializeBinary(): Uint8Array; + static deserializeBinary(bytes: Uint8Array): ProtoPendingEtxsRollup; + } + class ProtoTxIns extends pb_1.Message { + #private; + constructor(data?: any[] | { + tx_ins?: ProtoTxIn[]; + }); + get tx_ins(): ProtoTxIn[]; + set tx_ins(value: ProtoTxIn[]); + static fromObject(data: { + tx_ins?: ReturnType[]; + }): ProtoTxIns; + toObject(): { + tx_ins?: { + previous_out_point?: { + hash?: { + value?: Uint8Array | undefined; + } | undefined; + index?: number | undefined; + } | undefined; + pub_key?: Uint8Array | undefined; + }[] | undefined; + }; + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): ProtoTxIns; + serializeBinary(): Uint8Array; + static deserializeBinary(bytes: Uint8Array): ProtoTxIns; + } + class ProtoTxOuts extends pb_1.Message { + #private; + constructor(data?: any[] | { + tx_outs?: ProtoTxOut[]; + }); + get tx_outs(): ProtoTxOut[]; + set tx_outs(value: ProtoTxOut[]); + static fromObject(data: { + tx_outs?: ReturnType[]; + }): ProtoTxOuts; + toObject(): { + tx_outs?: { + denomination?: number | undefined; + address?: Uint8Array | undefined; + }[] | undefined; + }; + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): ProtoTxOuts; + serializeBinary(): Uint8Array; + static deserializeBinary(bytes: Uint8Array): ProtoTxOuts; + } + class ProtoTxIn extends pb_1.Message { + #private; + constructor(data?: any[] | ({} & (({ + previous_out_point?: ProtoOutPoint; + }) | ({ + pub_key?: Uint8Array; + })))); + get previous_out_point(): ProtoOutPoint; + set previous_out_point(value: ProtoOutPoint); + get has_previous_out_point(): boolean; + get pub_key(): Uint8Array; + set pub_key(value: Uint8Array); + get has_pub_key(): boolean; + get _previous_out_point(): "none" | "previous_out_point"; + get _pub_key(): "none" | "pub_key"; + static fromObject(data: { + previous_out_point?: ReturnType; + pub_key?: Uint8Array; + }): ProtoTxIn; + toObject(): { + previous_out_point?: { + hash?: { + value?: Uint8Array | undefined; + } | undefined; + index?: number | undefined; + } | undefined; + pub_key?: Uint8Array | undefined; + }; + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): ProtoTxIn; + serializeBinary(): Uint8Array; + static deserializeBinary(bytes: Uint8Array): ProtoTxIn; + } + class ProtoOutPoint extends pb_1.Message { + #private; + constructor(data?: any[] | ({} & (({ + hash?: dependency_1.common.ProtoHash; + }) | ({ + index?: number; + })))); + get hash(): dependency_1.common.ProtoHash; + set hash(value: dependency_1.common.ProtoHash); + get has_hash(): boolean; + get index(): number; + set index(value: number); + get has_index(): boolean; + get _hash(): "none" | "hash"; + get _index(): "index" | "none"; + static fromObject(data: { + hash?: ReturnType; + index?: number; + }): ProtoOutPoint; + toObject(): { + hash?: { + value?: Uint8Array | undefined; + } | undefined; + index?: number | undefined; + }; + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): ProtoOutPoint; + serializeBinary(): Uint8Array; + static deserializeBinary(bytes: Uint8Array): ProtoOutPoint; + } + class ProtoTxOut extends pb_1.Message { + #private; + constructor(data?: any[] | ({} & (({ + denomination?: number; + }) | ({ + address?: Uint8Array; + })))); + get denomination(): number; + set denomination(value: number); + get has_denomination(): boolean; + get address(): Uint8Array; + set address(value: Uint8Array); + get has_address(): boolean; + get _denomination(): "none" | "denomination"; + get _address(): "none" | "address"; + static fromObject(data: { + denomination?: number; + address?: Uint8Array; + }): ProtoTxOut; + toObject(): { + denomination?: number | undefined; + address?: Uint8Array | undefined; + }; + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): ProtoTxOut; + serializeBinary(): Uint8Array; + static deserializeBinary(bytes: Uint8Array): ProtoTxOut; + } +} +//# sourceMappingURL=proto_block.d.ts.map \ No newline at end of file diff --git a/lib.esm/utils/ProtoBuf/proto_block.d.ts.map b/lib.esm/utils/ProtoBuf/proto_block.d.ts.map new file mode 100644 index 00000000..dafb23c6 --- /dev/null +++ b/lib.esm/utils/ProtoBuf/proto_block.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"proto_block.d.ts","sourceRoot":"","sources":["../../../src.ts/utils/ProtoBuf/proto_block.ts"],"names":[],"mappings":"AAAA;;;;oDAIoD;AACpD,OAAO,KAAK,YAAY,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AACxC,yBAAiB,KAAK,CAAC;IACnB,MAAa,UAAW,SAAQ,IAAI,CAAC,OAAO;;oBAE5B,IAAI,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,GAAG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AAI,QAAQ,uBAQX;QACD,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE;YACpB,YAAY,CAAC,EAAE,MAAM,CAAC;YACtB,OAAO,CAAC,EAAE,UAAU,CAAC;SACxB,GAAG,UAAU;QAUd,QAAQ;;;;QAaR,SAAS,IAAI,UAAU;QACvB,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,YAAY,GAAG,IAAI;QAUrC,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC,YAAY,GAAG,UAAU;QAiBrE,eAAe,IAAI,UAAU;QAG7B,MAAM,CAAC,iBAAiB,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU;KAG1D;CACJ"} \ No newline at end of file diff --git a/lib.esm/utils/ProtoBuf/proto_block.js b/lib.esm/utils/ProtoBuf/proto_block.js new file mode 100644 index 00000000..ee55a0af --- /dev/null +++ b/lib.esm/utils/ProtoBuf/proto_block.js @@ -0,0 +1,3166 @@ +/** + * Generated by the protoc-gen-ts. DO NOT EDIT! + * compiler version: 4.25.3 + * source: proto_block.proto + * git: https://github.com/thesayyn/protoc-gen-ts */ +import * as dependency_1 from "./proto_common"; +import * as pb_1 from "google-protobuf"; +export var block; +(function (block) { + class ProtoBlock extends pb_1.Message { + #one_of_decls = [[1], [2]]; + constructor(data) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("header" in data && data.header != undefined) { + this.header = data.header; + } + if ("body" in data && data.body != undefined) { + this.body = data.body; + } + } + } + get header() { + return pb_1.Message.getWrapperField(this, ProtoHeader, 1); + } + set header(value) { + pb_1.Message.setOneofWrapperField(this, 1, this.#one_of_decls[0], value); + } + get has_header() { + return pb_1.Message.getField(this, 1) != null; + } + get body() { + return pb_1.Message.getWrapperField(this, ProtoBody, 2); + } + set body(value) { + pb_1.Message.setOneofWrapperField(this, 2, this.#one_of_decls[1], value); + } + get has_body() { + return pb_1.Message.getField(this, 2) != null; + } + get _header() { + const cases = { + 0: "none", + 1: "header" + }; + return cases[pb_1.Message.computeOneofCase(this, [1])]; + } + get _body() { + const cases = { + 0: "none", + 2: "body" + }; + return cases[pb_1.Message.computeOneofCase(this, [2])]; + } + static fromObject(data) { + const message = new ProtoBlock({}); + if (data.header != null) { + message.header = ProtoHeader.fromObject(data.header); + } + if (data.body != null) { + message.body = ProtoBody.fromObject(data.body); + } + return message; + } + toObject() { + const data = {}; + if (this.header != null) { + data.header = this.header.toObject(); + } + if (this.body != null) { + data.body = this.body.toObject(); + } + return data; + } + serialize(w) { + const writer = w || new pb_1.BinaryWriter(); + if (this.has_header) + writer.writeMessage(1, this.header, () => this.header.serialize(writer)); + if (this.has_body) + writer.writeMessage(2, this.body, () => this.body.serialize(writer)); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes) { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new ProtoBlock(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + reader.readMessage(message.header, () => message.header = ProtoHeader.deserialize(reader)); + break; + case 2: + reader.readMessage(message.body, () => message.body = ProtoBody.deserialize(reader)); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary() { + return this.serialize(); + } + static deserializeBinary(bytes) { + return ProtoBlock.deserialize(bytes); + } + } + block.ProtoBlock = ProtoBlock; + class ProtoBody extends pb_1.Message { + #one_of_decls = [[1], [2], [3], [4]]; + constructor(data) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("txs" in data && data.txs != undefined) { + this.txs = data.txs; + } + if ("uncles" in data && data.uncles != undefined) { + this.uncles = data.uncles; + } + if ("etxs" in data && data.etxs != undefined) { + this.etxs = data.etxs; + } + if ("manifest" in data && data.manifest != undefined) { + this.manifest = data.manifest; + } + } + } + get txs() { + return pb_1.Message.getWrapperField(this, ProtoTransactions, 1); + } + set txs(value) { + pb_1.Message.setOneofWrapperField(this, 1, this.#one_of_decls[0], value); + } + get has_txs() { + return pb_1.Message.getField(this, 1) != null; + } + get uncles() { + return pb_1.Message.getWrapperField(this, ProtoHeaders, 2); + } + set uncles(value) { + pb_1.Message.setOneofWrapperField(this, 2, this.#one_of_decls[1], value); + } + get has_uncles() { + return pb_1.Message.getField(this, 2) != null; + } + get etxs() { + return pb_1.Message.getWrapperField(this, ProtoTransactions, 3); + } + set etxs(value) { + pb_1.Message.setOneofWrapperField(this, 3, this.#one_of_decls[2], value); + } + get has_etxs() { + return pb_1.Message.getField(this, 3) != null; + } + get manifest() { + return pb_1.Message.getWrapperField(this, ProtoManifest, 4); + } + set manifest(value) { + pb_1.Message.setOneofWrapperField(this, 4, this.#one_of_decls[3], value); + } + get has_manifest() { + return pb_1.Message.getField(this, 4) != null; + } + get _txs() { + const cases = { + 0: "none", + 1: "txs" + }; + return cases[pb_1.Message.computeOneofCase(this, [1])]; + } + get _uncles() { + const cases = { + 0: "none", + 2: "uncles" + }; + return cases[pb_1.Message.computeOneofCase(this, [2])]; + } + get _etxs() { + const cases = { + 0: "none", + 3: "etxs" + }; + return cases[pb_1.Message.computeOneofCase(this, [3])]; + } + get _manifest() { + const cases = { + 0: "none", + 4: "manifest" + }; + return cases[pb_1.Message.computeOneofCase(this, [4])]; + } + static fromObject(data) { + const message = new ProtoBody({}); + if (data.txs != null) { + message.txs = ProtoTransactions.fromObject(data.txs); + } + if (data.uncles != null) { + message.uncles = ProtoHeaders.fromObject(data.uncles); + } + if (data.etxs != null) { + message.etxs = ProtoTransactions.fromObject(data.etxs); + } + if (data.manifest != null) { + message.manifest = ProtoManifest.fromObject(data.manifest); + } + return message; + } + toObject() { + const data = {}; + if (this.txs != null) { + data.txs = this.txs.toObject(); + } + if (this.uncles != null) { + data.uncles = this.uncles.toObject(); + } + if (this.etxs != null) { + data.etxs = this.etxs.toObject(); + } + if (this.manifest != null) { + data.manifest = this.manifest.toObject(); + } + return data; + } + serialize(w) { + const writer = w || new pb_1.BinaryWriter(); + if (this.has_txs) + writer.writeMessage(1, this.txs, () => this.txs.serialize(writer)); + if (this.has_uncles) + writer.writeMessage(2, this.uncles, () => this.uncles.serialize(writer)); + if (this.has_etxs) + writer.writeMessage(3, this.etxs, () => this.etxs.serialize(writer)); + if (this.has_manifest) + writer.writeMessage(4, this.manifest, () => this.manifest.serialize(writer)); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes) { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new ProtoBody(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + reader.readMessage(message.txs, () => message.txs = ProtoTransactions.deserialize(reader)); + break; + case 2: + reader.readMessage(message.uncles, () => message.uncles = ProtoHeaders.deserialize(reader)); + break; + case 3: + reader.readMessage(message.etxs, () => message.etxs = ProtoTransactions.deserialize(reader)); + break; + case 4: + reader.readMessage(message.manifest, () => message.manifest = ProtoManifest.deserialize(reader)); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary() { + return this.serialize(); + } + static deserializeBinary(bytes) { + return ProtoBody.deserialize(bytes); + } + } + block.ProtoBody = ProtoBody; + class ProtoHeader extends pb_1.Message { + #one_of_decls = [[2], [3], [4], [5], [6], [7], [9], [10], [14], [15], [16], [17], [18], [19], [20], [21], [22], [23]]; + constructor(data) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [1, 8, 11, 12, 13], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("parent_hash" in data && data.parent_hash != undefined) { + this.parent_hash = data.parent_hash; + } + if ("uncle_hash" in data && data.uncle_hash != undefined) { + this.uncle_hash = data.uncle_hash; + } + if ("coinbase" in data && data.coinbase != undefined) { + this.coinbase = data.coinbase; + } + if ("evm_root" in data && data.evm_root != undefined) { + this.evm_root = data.evm_root; + } + if ("tx_hash" in data && data.tx_hash != undefined) { + this.tx_hash = data.tx_hash; + } + if ("etx_hash" in data && data.etx_hash != undefined) { + this.etx_hash = data.etx_hash; + } + if ("etx_rollup_hash" in data && data.etx_rollup_hash != undefined) { + this.etx_rollup_hash = data.etx_rollup_hash; + } + if ("manifest_hash" in data && data.manifest_hash != undefined) { + this.manifest_hash = data.manifest_hash; + } + if ("receipt_hash" in data && data.receipt_hash != undefined) { + this.receipt_hash = data.receipt_hash; + } + if ("difficulty" in data && data.difficulty != undefined) { + this.difficulty = data.difficulty; + } + if ("parent_entropy" in data && data.parent_entropy != undefined) { + this.parent_entropy = data.parent_entropy; + } + if ("parent_delta_s" in data && data.parent_delta_s != undefined) { + this.parent_delta_s = data.parent_delta_s; + } + if ("number" in data && data.number != undefined) { + this.number = data.number; + } + if ("gas_limit" in data && data.gas_limit != undefined) { + this.gas_limit = data.gas_limit; + } + if ("gas_used" in data && data.gas_used != undefined) { + this.gas_used = data.gas_used; + } + if ("base_fee" in data && data.base_fee != undefined) { + this.base_fee = data.base_fee; + } + if ("location" in data && data.location != undefined) { + this.location = data.location; + } + if ("time" in data && data.time != undefined) { + this.time = data.time; + } + if ("extra" in data && data.extra != undefined) { + this.extra = data.extra; + } + if ("mix_hash" in data && data.mix_hash != undefined) { + this.mix_hash = data.mix_hash; + } + if ("nonce" in data && data.nonce != undefined) { + this.nonce = data.nonce; + } + if ("utxo_root" in data && data.utxo_root != undefined) { + this.utxo_root = data.utxo_root; + } + if ("etx_set_hash" in data && data.etx_set_hash != undefined) { + this.etx_set_hash = data.etx_set_hash; + } + } + } + get parent_hash() { + return pb_1.Message.getRepeatedWrapperField(this, dependency_1.common.ProtoHash, 1); + } + set parent_hash(value) { + pb_1.Message.setRepeatedWrapperField(this, 1, value); + } + get uncle_hash() { + return pb_1.Message.getWrapperField(this, dependency_1.common.ProtoHash, 2); + } + set uncle_hash(value) { + pb_1.Message.setOneofWrapperField(this, 2, this.#one_of_decls[0], value); + } + get has_uncle_hash() { + return pb_1.Message.getField(this, 2) != null; + } + get coinbase() { + return pb_1.Message.getFieldWithDefault(this, 3, new Uint8Array(0)); + } + set coinbase(value) { + pb_1.Message.setOneofField(this, 3, this.#one_of_decls[1], value); + } + get has_coinbase() { + return pb_1.Message.getField(this, 3) != null; + } + get evm_root() { + return pb_1.Message.getWrapperField(this, dependency_1.common.ProtoHash, 4); + } + set evm_root(value) { + pb_1.Message.setOneofWrapperField(this, 4, this.#one_of_decls[2], value); + } + get has_evm_root() { + return pb_1.Message.getField(this, 4) != null; + } + get tx_hash() { + return pb_1.Message.getWrapperField(this, dependency_1.common.ProtoHash, 5); + } + set tx_hash(value) { + pb_1.Message.setOneofWrapperField(this, 5, this.#one_of_decls[3], value); + } + get has_tx_hash() { + return pb_1.Message.getField(this, 5) != null; + } + get etx_hash() { + return pb_1.Message.getWrapperField(this, dependency_1.common.ProtoHash, 6); + } + set etx_hash(value) { + pb_1.Message.setOneofWrapperField(this, 6, this.#one_of_decls[4], value); + } + get has_etx_hash() { + return pb_1.Message.getField(this, 6) != null; + } + get etx_rollup_hash() { + return pb_1.Message.getWrapperField(this, dependency_1.common.ProtoHash, 7); + } + set etx_rollup_hash(value) { + pb_1.Message.setOneofWrapperField(this, 7, this.#one_of_decls[5], value); + } + get has_etx_rollup_hash() { + return pb_1.Message.getField(this, 7) != null; + } + get manifest_hash() { + return pb_1.Message.getRepeatedWrapperField(this, dependency_1.common.ProtoHash, 8); + } + set manifest_hash(value) { + pb_1.Message.setRepeatedWrapperField(this, 8, value); + } + get receipt_hash() { + return pb_1.Message.getWrapperField(this, dependency_1.common.ProtoHash, 9); + } + set receipt_hash(value) { + pb_1.Message.setOneofWrapperField(this, 9, this.#one_of_decls[6], value); + } + get has_receipt_hash() { + return pb_1.Message.getField(this, 9) != null; + } + get difficulty() { + return pb_1.Message.getFieldWithDefault(this, 10, new Uint8Array(0)); + } + set difficulty(value) { + pb_1.Message.setOneofField(this, 10, this.#one_of_decls[7], value); + } + get has_difficulty() { + return pb_1.Message.getField(this, 10) != null; + } + get parent_entropy() { + return pb_1.Message.getFieldWithDefault(this, 11, []); + } + set parent_entropy(value) { + pb_1.Message.setField(this, 11, value); + } + get parent_delta_s() { + return pb_1.Message.getFieldWithDefault(this, 12, []); + } + set parent_delta_s(value) { + pb_1.Message.setField(this, 12, value); + } + get number() { + return pb_1.Message.getFieldWithDefault(this, 13, []); + } + set number(value) { + pb_1.Message.setField(this, 13, value); + } + get gas_limit() { + return pb_1.Message.getFieldWithDefault(this, 14, 0); + } + set gas_limit(value) { + pb_1.Message.setOneofField(this, 14, this.#one_of_decls[8], value); + } + get has_gas_limit() { + return pb_1.Message.getField(this, 14) != null; + } + get gas_used() { + return pb_1.Message.getFieldWithDefault(this, 15, 0); + } + set gas_used(value) { + pb_1.Message.setOneofField(this, 15, this.#one_of_decls[9], value); + } + get has_gas_used() { + return pb_1.Message.getField(this, 15) != null; + } + get base_fee() { + return pb_1.Message.getFieldWithDefault(this, 16, new Uint8Array(0)); + } + set base_fee(value) { + pb_1.Message.setOneofField(this, 16, this.#one_of_decls[10], value); + } + get has_base_fee() { + return pb_1.Message.getField(this, 16) != null; + } + get location() { + return pb_1.Message.getWrapperField(this, dependency_1.common.ProtoLocation, 17); + } + set location(value) { + pb_1.Message.setOneofWrapperField(this, 17, this.#one_of_decls[11], value); + } + get has_location() { + return pb_1.Message.getField(this, 17) != null; + } + get time() { + return pb_1.Message.getFieldWithDefault(this, 18, 0); + } + set time(value) { + pb_1.Message.setOneofField(this, 18, this.#one_of_decls[12], value); + } + get has_time() { + return pb_1.Message.getField(this, 18) != null; + } + get extra() { + return pb_1.Message.getFieldWithDefault(this, 19, new Uint8Array(0)); + } + set extra(value) { + pb_1.Message.setOneofField(this, 19, this.#one_of_decls[13], value); + } + get has_extra() { + return pb_1.Message.getField(this, 19) != null; + } + get mix_hash() { + return pb_1.Message.getWrapperField(this, dependency_1.common.ProtoHash, 20); + } + set mix_hash(value) { + pb_1.Message.setOneofWrapperField(this, 20, this.#one_of_decls[14], value); + } + get has_mix_hash() { + return pb_1.Message.getField(this, 20) != null; + } + get nonce() { + return pb_1.Message.getFieldWithDefault(this, 21, 0); + } + set nonce(value) { + pb_1.Message.setOneofField(this, 21, this.#one_of_decls[15], value); + } + get has_nonce() { + return pb_1.Message.getField(this, 21) != null; + } + get utxo_root() { + return pb_1.Message.getWrapperField(this, dependency_1.common.ProtoHash, 22); + } + set utxo_root(value) { + pb_1.Message.setOneofWrapperField(this, 22, this.#one_of_decls[16], value); + } + get has_utxo_root() { + return pb_1.Message.getField(this, 22) != null; + } + get etx_set_hash() { + return pb_1.Message.getWrapperField(this, dependency_1.common.ProtoHash, 23); + } + set etx_set_hash(value) { + pb_1.Message.setOneofWrapperField(this, 23, this.#one_of_decls[17], value); + } + get has_etx_set_hash() { + return pb_1.Message.getField(this, 23) != null; + } + get _uncle_hash() { + const cases = { + 0: "none", + 2: "uncle_hash" + }; + return cases[pb_1.Message.computeOneofCase(this, [2])]; + } + get _coinbase() { + const cases = { + 0: "none", + 3: "coinbase" + }; + return cases[pb_1.Message.computeOneofCase(this, [3])]; + } + get _evm_root() { + const cases = { + 0: "none", + 4: "evm_root" + }; + return cases[pb_1.Message.computeOneofCase(this, [4])]; + } + get _tx_hash() { + const cases = { + 0: "none", + 5: "tx_hash" + }; + return cases[pb_1.Message.computeOneofCase(this, [5])]; + } + get _etx_hash() { + const cases = { + 0: "none", + 6: "etx_hash" + }; + return cases[pb_1.Message.computeOneofCase(this, [6])]; + } + get _etx_rollup_hash() { + const cases = { + 0: "none", + 7: "etx_rollup_hash" + }; + return cases[pb_1.Message.computeOneofCase(this, [7])]; + } + get _receipt_hash() { + const cases = { + 0: "none", + 9: "receipt_hash" + }; + return cases[pb_1.Message.computeOneofCase(this, [9])]; + } + get _difficulty() { + const cases = { + 0: "none", + 10: "difficulty" + }; + return cases[pb_1.Message.computeOneofCase(this, [10])]; + } + get _gas_limit() { + const cases = { + 0: "none", + 14: "gas_limit" + }; + return cases[pb_1.Message.computeOneofCase(this, [14])]; + } + get _gas_used() { + const cases = { + 0: "none", + 15: "gas_used" + }; + return cases[pb_1.Message.computeOneofCase(this, [15])]; + } + get _base_fee() { + const cases = { + 0: "none", + 16: "base_fee" + }; + return cases[pb_1.Message.computeOneofCase(this, [16])]; + } + get _location() { + const cases = { + 0: "none", + 17: "location" + }; + return cases[pb_1.Message.computeOneofCase(this, [17])]; + } + get _time() { + const cases = { + 0: "none", + 18: "time" + }; + return cases[pb_1.Message.computeOneofCase(this, [18])]; + } + get _extra() { + const cases = { + 0: "none", + 19: "extra" + }; + return cases[pb_1.Message.computeOneofCase(this, [19])]; + } + get _mix_hash() { + const cases = { + 0: "none", + 20: "mix_hash" + }; + return cases[pb_1.Message.computeOneofCase(this, [20])]; + } + get _nonce() { + const cases = { + 0: "none", + 21: "nonce" + }; + return cases[pb_1.Message.computeOneofCase(this, [21])]; + } + get _utxo_root() { + const cases = { + 0: "none", + 22: "utxo_root" + }; + return cases[pb_1.Message.computeOneofCase(this, [22])]; + } + get _etx_set_hash() { + const cases = { + 0: "none", + 23: "etx_set_hash" + }; + return cases[pb_1.Message.computeOneofCase(this, [23])]; + } + static fromObject(data) { + const message = new ProtoHeader({}); + if (data.parent_hash != null) { + message.parent_hash = data.parent_hash.map(item => dependency_1.common.ProtoHash.fromObject(item)); + } + if (data.uncle_hash != null) { + message.uncle_hash = dependency_1.common.ProtoHash.fromObject(data.uncle_hash); + } + if (data.coinbase != null) { + message.coinbase = data.coinbase; + } + if (data.evm_root != null) { + message.evm_root = dependency_1.common.ProtoHash.fromObject(data.evm_root); + } + if (data.tx_hash != null) { + message.tx_hash = dependency_1.common.ProtoHash.fromObject(data.tx_hash); + } + if (data.etx_hash != null) { + message.etx_hash = dependency_1.common.ProtoHash.fromObject(data.etx_hash); + } + if (data.etx_rollup_hash != null) { + message.etx_rollup_hash = dependency_1.common.ProtoHash.fromObject(data.etx_rollup_hash); + } + if (data.manifest_hash != null) { + message.manifest_hash = data.manifest_hash.map(item => dependency_1.common.ProtoHash.fromObject(item)); + } + if (data.receipt_hash != null) { + message.receipt_hash = dependency_1.common.ProtoHash.fromObject(data.receipt_hash); + } + if (data.difficulty != null) { + message.difficulty = data.difficulty; + } + if (data.parent_entropy != null) { + message.parent_entropy = data.parent_entropy; + } + if (data.parent_delta_s != null) { + message.parent_delta_s = data.parent_delta_s; + } + if (data.number != null) { + message.number = data.number; + } + if (data.gas_limit != null) { + message.gas_limit = data.gas_limit; + } + if (data.gas_used != null) { + message.gas_used = data.gas_used; + } + if (data.base_fee != null) { + message.base_fee = data.base_fee; + } + if (data.location != null) { + message.location = dependency_1.common.ProtoLocation.fromObject(data.location); + } + if (data.time != null) { + message.time = data.time; + } + if (data.extra != null) { + message.extra = data.extra; + } + if (data.mix_hash != null) { + message.mix_hash = dependency_1.common.ProtoHash.fromObject(data.mix_hash); + } + if (data.nonce != null) { + message.nonce = data.nonce; + } + if (data.utxo_root != null) { + message.utxo_root = dependency_1.common.ProtoHash.fromObject(data.utxo_root); + } + if (data.etx_set_hash != null) { + message.etx_set_hash = dependency_1.common.ProtoHash.fromObject(data.etx_set_hash); + } + return message; + } + toObject() { + const data = {}; + if (this.parent_hash != null) { + data.parent_hash = this.parent_hash.map((item) => item.toObject()); + } + if (this.uncle_hash != null) { + data.uncle_hash = this.uncle_hash.toObject(); + } + if (this.coinbase != null) { + data.coinbase = this.coinbase; + } + if (this.evm_root != null) { + data.evm_root = this.evm_root.toObject(); + } + if (this.tx_hash != null) { + data.tx_hash = this.tx_hash.toObject(); + } + if (this.etx_hash != null) { + data.etx_hash = this.etx_hash.toObject(); + } + if (this.etx_rollup_hash != null) { + data.etx_rollup_hash = this.etx_rollup_hash.toObject(); + } + if (this.manifest_hash != null) { + data.manifest_hash = this.manifest_hash.map((item) => item.toObject()); + } + if (this.receipt_hash != null) { + data.receipt_hash = this.receipt_hash.toObject(); + } + if (this.difficulty != null) { + data.difficulty = this.difficulty; + } + if (this.parent_entropy != null) { + data.parent_entropy = this.parent_entropy; + } + if (this.parent_delta_s != null) { + data.parent_delta_s = this.parent_delta_s; + } + if (this.number != null) { + data.number = this.number; + } + if (this.gas_limit != null) { + data.gas_limit = this.gas_limit; + } + if (this.gas_used != null) { + data.gas_used = this.gas_used; + } + if (this.base_fee != null) { + data.base_fee = this.base_fee; + } + if (this.location != null) { + data.location = this.location.toObject(); + } + if (this.time != null) { + data.time = this.time; + } + if (this.extra != null) { + data.extra = this.extra; + } + if (this.mix_hash != null) { + data.mix_hash = this.mix_hash.toObject(); + } + if (this.nonce != null) { + data.nonce = this.nonce; + } + if (this.utxo_root != null) { + data.utxo_root = this.utxo_root.toObject(); + } + if (this.etx_set_hash != null) { + data.etx_set_hash = this.etx_set_hash.toObject(); + } + return data; + } + serialize(w) { + const writer = w || new pb_1.BinaryWriter(); + if (this.parent_hash.length) + writer.writeRepeatedMessage(1, this.parent_hash, (item) => item.serialize(writer)); + if (this.has_uncle_hash) + writer.writeMessage(2, this.uncle_hash, () => this.uncle_hash.serialize(writer)); + if (this.has_coinbase) + writer.writeBytes(3, this.coinbase); + if (this.has_evm_root) + writer.writeMessage(4, this.evm_root, () => this.evm_root.serialize(writer)); + if (this.has_tx_hash) + writer.writeMessage(5, this.tx_hash, () => this.tx_hash.serialize(writer)); + if (this.has_etx_hash) + writer.writeMessage(6, this.etx_hash, () => this.etx_hash.serialize(writer)); + if (this.has_etx_rollup_hash) + writer.writeMessage(7, this.etx_rollup_hash, () => this.etx_rollup_hash.serialize(writer)); + if (this.manifest_hash.length) + writer.writeRepeatedMessage(8, this.manifest_hash, (item) => item.serialize(writer)); + if (this.has_receipt_hash) + writer.writeMessage(9, this.receipt_hash, () => this.receipt_hash.serialize(writer)); + if (this.has_difficulty) + writer.writeBytes(10, this.difficulty); + if (this.parent_entropy.length) + writer.writeRepeatedBytes(11, this.parent_entropy); + if (this.parent_delta_s.length) + writer.writeRepeatedBytes(12, this.parent_delta_s); + if (this.number.length) + writer.writeRepeatedBytes(13, this.number); + if (this.has_gas_limit) + writer.writeUint64(14, this.gas_limit); + if (this.has_gas_used) + writer.writeUint64(15, this.gas_used); + if (this.has_base_fee) + writer.writeBytes(16, this.base_fee); + if (this.has_location) + writer.writeMessage(17, this.location, () => this.location.serialize(writer)); + if (this.has_time) + writer.writeUint64(18, this.time); + if (this.has_extra) + writer.writeBytes(19, this.extra); + if (this.has_mix_hash) + writer.writeMessage(20, this.mix_hash, () => this.mix_hash.serialize(writer)); + if (this.has_nonce) + writer.writeUint64(21, this.nonce); + if (this.has_utxo_root) + writer.writeMessage(22, this.utxo_root, () => this.utxo_root.serialize(writer)); + if (this.has_etx_set_hash) + writer.writeMessage(23, this.etx_set_hash, () => this.etx_set_hash.serialize(writer)); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes) { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new ProtoHeader(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + reader.readMessage(message.parent_hash, () => pb_1.Message.addToRepeatedWrapperField(message, 1, dependency_1.common.ProtoHash.deserialize(reader), dependency_1.common.ProtoHash)); + break; + case 2: + reader.readMessage(message.uncle_hash, () => message.uncle_hash = dependency_1.common.ProtoHash.deserialize(reader)); + break; + case 3: + message.coinbase = reader.readBytes(); + break; + case 4: + reader.readMessage(message.evm_root, () => message.evm_root = dependency_1.common.ProtoHash.deserialize(reader)); + break; + case 5: + reader.readMessage(message.tx_hash, () => message.tx_hash = dependency_1.common.ProtoHash.deserialize(reader)); + break; + case 6: + reader.readMessage(message.etx_hash, () => message.etx_hash = dependency_1.common.ProtoHash.deserialize(reader)); + break; + case 7: + reader.readMessage(message.etx_rollup_hash, () => message.etx_rollup_hash = dependency_1.common.ProtoHash.deserialize(reader)); + break; + case 8: + reader.readMessage(message.manifest_hash, () => pb_1.Message.addToRepeatedWrapperField(message, 8, dependency_1.common.ProtoHash.deserialize(reader), dependency_1.common.ProtoHash)); + break; + case 9: + reader.readMessage(message.receipt_hash, () => message.receipt_hash = dependency_1.common.ProtoHash.deserialize(reader)); + break; + case 10: + message.difficulty = reader.readBytes(); + break; + case 11: + pb_1.Message.addToRepeatedField(message, 11, reader.readBytes()); + break; + case 12: + pb_1.Message.addToRepeatedField(message, 12, reader.readBytes()); + break; + case 13: + pb_1.Message.addToRepeatedField(message, 13, reader.readBytes()); + break; + case 14: + message.gas_limit = reader.readUint64(); + break; + case 15: + message.gas_used = reader.readUint64(); + break; + case 16: + message.base_fee = reader.readBytes(); + break; + case 17: + reader.readMessage(message.location, () => message.location = dependency_1.common.ProtoLocation.deserialize(reader)); + break; + case 18: + message.time = reader.readUint64(); + break; + case 19: + message.extra = reader.readBytes(); + break; + case 20: + reader.readMessage(message.mix_hash, () => message.mix_hash = dependency_1.common.ProtoHash.deserialize(reader)); + break; + case 21: + message.nonce = reader.readUint64(); + break; + case 22: + reader.readMessage(message.utxo_root, () => message.utxo_root = dependency_1.common.ProtoHash.deserialize(reader)); + break; + case 23: + reader.readMessage(message.etx_set_hash, () => message.etx_set_hash = dependency_1.common.ProtoHash.deserialize(reader)); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary() { + return this.serialize(); + } + static deserializeBinary(bytes) { + return ProtoHeader.deserialize(bytes); + } + } + block.ProtoHeader = ProtoHeader; + class ProtoTransaction extends pb_1.Message { + #one_of_decls = [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14], [15], [16], [17], [18], [19]]; + constructor(data) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("type" in data && data.type != undefined) { + this.type = data.type; + } + if ("to" in data && data.to != undefined) { + this.to = data.to; + } + if ("nonce" in data && data.nonce != undefined) { + this.nonce = data.nonce; + } + if ("value" in data && data.value != undefined) { + this.value = data.value; + } + if ("gas" in data && data.gas != undefined) { + this.gas = data.gas; + } + if ("data" in data && data.data != undefined) { + this.data = data.data; + } + if ("chain_id" in data && data.chain_id != undefined) { + this.chain_id = data.chain_id; + } + if ("gas_fee_cap" in data && data.gas_fee_cap != undefined) { + this.gas_fee_cap = data.gas_fee_cap; + } + if ("gas_tip_cap" in data && data.gas_tip_cap != undefined) { + this.gas_tip_cap = data.gas_tip_cap; + } + if ("access_list" in data && data.access_list != undefined) { + this.access_list = data.access_list; + } + if ("v" in data && data.v != undefined) { + this.v = data.v; + } + if ("r" in data && data.r != undefined) { + this.r = data.r; + } + if ("s" in data && data.s != undefined) { + this.s = data.s; + } + if ("originating_tx_hash" in data && data.originating_tx_hash != undefined) { + this.originating_tx_hash = data.originating_tx_hash; + } + if ("etx_index" in data && data.etx_index != undefined) { + this.etx_index = data.etx_index; + } + if ("tx_ins" in data && data.tx_ins != undefined) { + this.tx_ins = data.tx_ins; + } + if ("tx_outs" in data && data.tx_outs != undefined) { + this.tx_outs = data.tx_outs; + } + if ("signature" in data && data.signature != undefined) { + this.signature = data.signature; + } + if ("etx_sender" in data && data.etx_sender != undefined) { + this.etx_sender = data.etx_sender; + } + } + } + get type() { + return pb_1.Message.getFieldWithDefault(this, 1, 0); + } + set type(value) { + pb_1.Message.setOneofField(this, 1, this.#one_of_decls[0], value); + } + get has_type() { + return pb_1.Message.getField(this, 1) != null; + } + get to() { + return pb_1.Message.getFieldWithDefault(this, 2, new Uint8Array(0)); + } + set to(value) { + pb_1.Message.setOneofField(this, 2, this.#one_of_decls[1], value); + } + get has_to() { + return pb_1.Message.getField(this, 2) != null; + } + get nonce() { + return pb_1.Message.getFieldWithDefault(this, 3, 0); + } + set nonce(value) { + pb_1.Message.setOneofField(this, 3, this.#one_of_decls[2], value); + } + get has_nonce() { + return pb_1.Message.getField(this, 3) != null; + } + get value() { + return pb_1.Message.getFieldWithDefault(this, 4, new Uint8Array(0)); + } + set value(value) { + pb_1.Message.setOneofField(this, 4, this.#one_of_decls[3], value); + } + get has_value() { + return pb_1.Message.getField(this, 4) != null; + } + get gas() { + return pb_1.Message.getFieldWithDefault(this, 5, 0); + } + set gas(value) { + pb_1.Message.setOneofField(this, 5, this.#one_of_decls[4], value); + } + get has_gas() { + return pb_1.Message.getField(this, 5) != null; + } + get data() { + return pb_1.Message.getFieldWithDefault(this, 6, new Uint8Array(0)); + } + set data(value) { + pb_1.Message.setOneofField(this, 6, this.#one_of_decls[5], value); + } + get has_data() { + return pb_1.Message.getField(this, 6) != null; + } + get chain_id() { + return pb_1.Message.getFieldWithDefault(this, 7, new Uint8Array(0)); + } + set chain_id(value) { + pb_1.Message.setOneofField(this, 7, this.#one_of_decls[6], value); + } + get has_chain_id() { + return pb_1.Message.getField(this, 7) != null; + } + get gas_fee_cap() { + return pb_1.Message.getFieldWithDefault(this, 8, new Uint8Array(0)); + } + set gas_fee_cap(value) { + pb_1.Message.setOneofField(this, 8, this.#one_of_decls[7], value); + } + get has_gas_fee_cap() { + return pb_1.Message.getField(this, 8) != null; + } + get gas_tip_cap() { + return pb_1.Message.getFieldWithDefault(this, 9, new Uint8Array(0)); + } + set gas_tip_cap(value) { + pb_1.Message.setOneofField(this, 9, this.#one_of_decls[8], value); + } + get has_gas_tip_cap() { + return pb_1.Message.getField(this, 9) != null; + } + get access_list() { + return pb_1.Message.getWrapperField(this, ProtoAccessList, 10); + } + set access_list(value) { + pb_1.Message.setOneofWrapperField(this, 10, this.#one_of_decls[9], value); + } + get has_access_list() { + return pb_1.Message.getField(this, 10) != null; + } + get v() { + return pb_1.Message.getFieldWithDefault(this, 11, new Uint8Array(0)); + } + set v(value) { + pb_1.Message.setOneofField(this, 11, this.#one_of_decls[10], value); + } + get has_v() { + return pb_1.Message.getField(this, 11) != null; + } + get r() { + return pb_1.Message.getFieldWithDefault(this, 12, new Uint8Array(0)); + } + set r(value) { + pb_1.Message.setOneofField(this, 12, this.#one_of_decls[11], value); + } + get has_r() { + return pb_1.Message.getField(this, 12) != null; + } + get s() { + return pb_1.Message.getFieldWithDefault(this, 13, new Uint8Array(0)); + } + set s(value) { + pb_1.Message.setOneofField(this, 13, this.#one_of_decls[12], value); + } + get has_s() { + return pb_1.Message.getField(this, 13) != null; + } + get originating_tx_hash() { + return pb_1.Message.getWrapperField(this, dependency_1.common.ProtoHash, 14); + } + set originating_tx_hash(value) { + pb_1.Message.setOneofWrapperField(this, 14, this.#one_of_decls[13], value); + } + get has_originating_tx_hash() { + return pb_1.Message.getField(this, 14) != null; + } + get etx_index() { + return pb_1.Message.getFieldWithDefault(this, 15, 0); + } + set etx_index(value) { + pb_1.Message.setOneofField(this, 15, this.#one_of_decls[14], value); + } + get has_etx_index() { + return pb_1.Message.getField(this, 15) != null; + } + get tx_ins() { + return pb_1.Message.getWrapperField(this, ProtoTxIns, 16); + } + set tx_ins(value) { + pb_1.Message.setOneofWrapperField(this, 16, this.#one_of_decls[15], value); + } + get has_tx_ins() { + return pb_1.Message.getField(this, 16) != null; + } + get tx_outs() { + return pb_1.Message.getWrapperField(this, ProtoTxOuts, 17); + } + set tx_outs(value) { + pb_1.Message.setOneofWrapperField(this, 17, this.#one_of_decls[16], value); + } + get has_tx_outs() { + return pb_1.Message.getField(this, 17) != null; + } + get signature() { + return pb_1.Message.getFieldWithDefault(this, 18, new Uint8Array(0)); + } + set signature(value) { + pb_1.Message.setOneofField(this, 18, this.#one_of_decls[17], value); + } + get has_signature() { + return pb_1.Message.getField(this, 18) != null; + } + get etx_sender() { + return pb_1.Message.getFieldWithDefault(this, 19, new Uint8Array(0)); + } + set etx_sender(value) { + pb_1.Message.setOneofField(this, 19, this.#one_of_decls[18], value); + } + get has_etx_sender() { + return pb_1.Message.getField(this, 19) != null; + } + get _type() { + const cases = { + 0: "none", + 1: "type" + }; + return cases[pb_1.Message.computeOneofCase(this, [1])]; + } + get _to() { + const cases = { + 0: "none", + 2: "to" + }; + return cases[pb_1.Message.computeOneofCase(this, [2])]; + } + get _nonce() { + const cases = { + 0: "none", + 3: "nonce" + }; + return cases[pb_1.Message.computeOneofCase(this, [3])]; + } + get _value() { + const cases = { + 0: "none", + 4: "value" + }; + return cases[pb_1.Message.computeOneofCase(this, [4])]; + } + get _gas() { + const cases = { + 0: "none", + 5: "gas" + }; + return cases[pb_1.Message.computeOneofCase(this, [5])]; + } + get _data() { + const cases = { + 0: "none", + 6: "data" + }; + return cases[pb_1.Message.computeOneofCase(this, [6])]; + } + get _chain_id() { + const cases = { + 0: "none", + 7: "chain_id" + }; + return cases[pb_1.Message.computeOneofCase(this, [7])]; + } + get _gas_fee_cap() { + const cases = { + 0: "none", + 8: "gas_fee_cap" + }; + return cases[pb_1.Message.computeOneofCase(this, [8])]; + } + get _gas_tip_cap() { + const cases = { + 0: "none", + 9: "gas_tip_cap" + }; + return cases[pb_1.Message.computeOneofCase(this, [9])]; + } + get _access_list() { + const cases = { + 0: "none", + 10: "access_list" + }; + return cases[pb_1.Message.computeOneofCase(this, [10])]; + } + get _v() { + const cases = { + 0: "none", + 11: "v" + }; + return cases[pb_1.Message.computeOneofCase(this, [11])]; + } + get _r() { + const cases = { + 0: "none", + 12: "r" + }; + return cases[pb_1.Message.computeOneofCase(this, [12])]; + } + get _s() { + const cases = { + 0: "none", + 13: "s" + }; + return cases[pb_1.Message.computeOneofCase(this, [13])]; + } + get _originating_tx_hash() { + const cases = { + 0: "none", + 14: "originating_tx_hash" + }; + return cases[pb_1.Message.computeOneofCase(this, [14])]; + } + get _etx_index() { + const cases = { + 0: "none", + 15: "etx_index" + }; + return cases[pb_1.Message.computeOneofCase(this, [15])]; + } + get _tx_ins() { + const cases = { + 0: "none", + 16: "tx_ins" + }; + return cases[pb_1.Message.computeOneofCase(this, [16])]; + } + get _tx_outs() { + const cases = { + 0: "none", + 17: "tx_outs" + }; + return cases[pb_1.Message.computeOneofCase(this, [17])]; + } + get _signature() { + const cases = { + 0: "none", + 18: "signature" + }; + return cases[pb_1.Message.computeOneofCase(this, [18])]; + } + get _etx_sender() { + const cases = { + 0: "none", + 19: "etx_sender" + }; + return cases[pb_1.Message.computeOneofCase(this, [19])]; + } + static fromObject(data) { + const message = new ProtoTransaction({}); + if (data.type != null) { + message.type = data.type; + } + if (data.to != null) { + message.to = data.to; + } + if (data.nonce != null) { + message.nonce = data.nonce; + } + if (data.value != null) { + message.value = data.value; + } + if (data.gas != null) { + message.gas = data.gas; + } + if (data.data != null) { + message.data = data.data; + } + if (data.chain_id != null) { + message.chain_id = data.chain_id; + } + if (data.gas_fee_cap != null) { + message.gas_fee_cap = data.gas_fee_cap; + } + if (data.gas_tip_cap != null) { + message.gas_tip_cap = data.gas_tip_cap; + } + if (data.access_list != null) { + message.access_list = ProtoAccessList.fromObject(data.access_list); + } + if (data.v != null) { + message.v = data.v; + } + if (data.r != null) { + message.r = data.r; + } + if (data.s != null) { + message.s = data.s; + } + if (data.originating_tx_hash != null) { + message.originating_tx_hash = dependency_1.common.ProtoHash.fromObject(data.originating_tx_hash); + } + if (data.etx_index != null) { + message.etx_index = data.etx_index; + } + if (data.tx_ins != null) { + message.tx_ins = ProtoTxIns.fromObject(data.tx_ins); + } + if (data.tx_outs != null) { + message.tx_outs = ProtoTxOuts.fromObject(data.tx_outs); + } + if (data.signature != null) { + message.signature = data.signature; + } + if (data.etx_sender != null) { + message.etx_sender = data.etx_sender; + } + return message; + } + toObject() { + const data = {}; + if (this.type != null) { + data.type = this.type; + } + if (this.to != null) { + data.to = this.to; + } + if (this.nonce != null) { + data.nonce = this.nonce; + } + if (this.value != null) { + data.value = this.value; + } + if (this.gas != null) { + data.gas = this.gas; + } + if (this.data != null) { + data.data = this.data; + } + if (this.chain_id != null) { + data.chain_id = this.chain_id; + } + if (this.gas_fee_cap != null) { + data.gas_fee_cap = this.gas_fee_cap; + } + if (this.gas_tip_cap != null) { + data.gas_tip_cap = this.gas_tip_cap; + } + if (this.access_list != null) { + data.access_list = this.access_list.toObject(); + } + if (this.v != null) { + data.v = this.v; + } + if (this.r != null) { + data.r = this.r; + } + if (this.s != null) { + data.s = this.s; + } + if (this.originating_tx_hash != null) { + data.originating_tx_hash = this.originating_tx_hash.toObject(); + } + if (this.etx_index != null) { + data.etx_index = this.etx_index; + } + if (this.tx_ins != null) { + data.tx_ins = this.tx_ins.toObject(); + } + if (this.tx_outs != null) { + data.tx_outs = this.tx_outs.toObject(); + } + if (this.signature != null) { + data.signature = this.signature; + } + if (this.etx_sender != null) { + data.etx_sender = this.etx_sender; + } + return data; + } + serialize(w) { + const writer = w || new pb_1.BinaryWriter(); + if (this.has_type) + writer.writeUint64(1, this.type); + if (this.has_to) + writer.writeBytes(2, this.to); + if (this.has_nonce) + writer.writeUint64(3, this.nonce); + if (this.has_value) + writer.writeBytes(4, this.value); + if (this.has_gas) + writer.writeUint64(5, this.gas); + if (this.has_data) + writer.writeBytes(6, this.data); + if (this.has_chain_id) + writer.writeBytes(7, this.chain_id); + if (this.has_gas_fee_cap) + writer.writeBytes(8, this.gas_fee_cap); + if (this.has_gas_tip_cap) + writer.writeBytes(9, this.gas_tip_cap); + if (this.has_access_list) + writer.writeMessage(10, this.access_list, () => this.access_list.serialize(writer)); + if (this.has_v) + writer.writeBytes(11, this.v); + if (this.has_r) + writer.writeBytes(12, this.r); + if (this.has_s) + writer.writeBytes(13, this.s); + if (this.has_originating_tx_hash) + writer.writeMessage(14, this.originating_tx_hash, () => this.originating_tx_hash.serialize(writer)); + if (this.has_etx_index) + writer.writeUint32(15, this.etx_index); + if (this.has_tx_ins) + writer.writeMessage(16, this.tx_ins, () => this.tx_ins.serialize(writer)); + if (this.has_tx_outs) + writer.writeMessage(17, this.tx_outs, () => this.tx_outs.serialize(writer)); + if (this.has_signature) + writer.writeBytes(18, this.signature); + if (this.has_etx_sender) + writer.writeBytes(19, this.etx_sender); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes) { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new ProtoTransaction(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + message.type = reader.readUint64(); + break; + case 2: + message.to = reader.readBytes(); + break; + case 3: + message.nonce = reader.readUint64(); + break; + case 4: + message.value = reader.readBytes(); + break; + case 5: + message.gas = reader.readUint64(); + break; + case 6: + message.data = reader.readBytes(); + break; + case 7: + message.chain_id = reader.readBytes(); + break; + case 8: + message.gas_fee_cap = reader.readBytes(); + break; + case 9: + message.gas_tip_cap = reader.readBytes(); + break; + case 10: + reader.readMessage(message.access_list, () => message.access_list = ProtoAccessList.deserialize(reader)); + break; + case 11: + message.v = reader.readBytes(); + break; + case 12: + message.r = reader.readBytes(); + break; + case 13: + message.s = reader.readBytes(); + break; + case 14: + reader.readMessage(message.originating_tx_hash, () => message.originating_tx_hash = dependency_1.common.ProtoHash.deserialize(reader)); + break; + case 15: + message.etx_index = reader.readUint32(); + break; + case 16: + reader.readMessage(message.tx_ins, () => message.tx_ins = ProtoTxIns.deserialize(reader)); + break; + case 17: + reader.readMessage(message.tx_outs, () => message.tx_outs = ProtoTxOuts.deserialize(reader)); + break; + case 18: + message.signature = reader.readBytes(); + break; + case 19: + message.etx_sender = reader.readBytes(); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary() { + return this.serialize(); + } + static deserializeBinary(bytes) { + return ProtoTransaction.deserialize(bytes); + } + } + block.ProtoTransaction = ProtoTransaction; + class ProtoTransactions extends pb_1.Message { + #one_of_decls = []; + constructor(data) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [1], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("transactions" in data && data.transactions != undefined) { + this.transactions = data.transactions; + } + } + } + get transactions() { + return pb_1.Message.getRepeatedWrapperField(this, ProtoTransaction, 1); + } + set transactions(value) { + pb_1.Message.setRepeatedWrapperField(this, 1, value); + } + static fromObject(data) { + const message = new ProtoTransactions({}); + if (data.transactions != null) { + message.transactions = data.transactions.map(item => ProtoTransaction.fromObject(item)); + } + return message; + } + toObject() { + const data = {}; + if (this.transactions != null) { + data.transactions = this.transactions.map((item) => item.toObject()); + } + return data; + } + serialize(w) { + const writer = w || new pb_1.BinaryWriter(); + if (this.transactions.length) + writer.writeRepeatedMessage(1, this.transactions, (item) => item.serialize(writer)); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes) { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new ProtoTransactions(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + reader.readMessage(message.transactions, () => pb_1.Message.addToRepeatedWrapperField(message, 1, ProtoTransaction.deserialize(reader), ProtoTransaction)); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary() { + return this.serialize(); + } + static deserializeBinary(bytes) { + return ProtoTransactions.deserialize(bytes); + } + } + block.ProtoTransactions = ProtoTransactions; + class ProtoHeaders extends pb_1.Message { + #one_of_decls = []; + constructor(data) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [1], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("headers" in data && data.headers != undefined) { + this.headers = data.headers; + } + } + } + get headers() { + return pb_1.Message.getRepeatedWrapperField(this, ProtoHeader, 1); + } + set headers(value) { + pb_1.Message.setRepeatedWrapperField(this, 1, value); + } + static fromObject(data) { + const message = new ProtoHeaders({}); + if (data.headers != null) { + message.headers = data.headers.map(item => ProtoHeader.fromObject(item)); + } + return message; + } + toObject() { + const data = {}; + if (this.headers != null) { + data.headers = this.headers.map((item) => item.toObject()); + } + return data; + } + serialize(w) { + const writer = w || new pb_1.BinaryWriter(); + if (this.headers.length) + writer.writeRepeatedMessage(1, this.headers, (item) => item.serialize(writer)); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes) { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new ProtoHeaders(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + reader.readMessage(message.headers, () => pb_1.Message.addToRepeatedWrapperField(message, 1, ProtoHeader.deserialize(reader), ProtoHeader)); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary() { + return this.serialize(); + } + static deserializeBinary(bytes) { + return ProtoHeaders.deserialize(bytes); + } + } + block.ProtoHeaders = ProtoHeaders; + class ProtoManifest extends pb_1.Message { + #one_of_decls = []; + constructor(data) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [1], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("manifest" in data && data.manifest != undefined) { + this.manifest = data.manifest; + } + } + } + get manifest() { + return pb_1.Message.getRepeatedWrapperField(this, dependency_1.common.ProtoHash, 1); + } + set manifest(value) { + pb_1.Message.setRepeatedWrapperField(this, 1, value); + } + static fromObject(data) { + const message = new ProtoManifest({}); + if (data.manifest != null) { + message.manifest = data.manifest.map(item => dependency_1.common.ProtoHash.fromObject(item)); + } + return message; + } + toObject() { + const data = {}; + if (this.manifest != null) { + data.manifest = this.manifest.map((item) => item.toObject()); + } + return data; + } + serialize(w) { + const writer = w || new pb_1.BinaryWriter(); + if (this.manifest.length) + writer.writeRepeatedMessage(1, this.manifest, (item) => item.serialize(writer)); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes) { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new ProtoManifest(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + reader.readMessage(message.manifest, () => pb_1.Message.addToRepeatedWrapperField(message, 1, dependency_1.common.ProtoHash.deserialize(reader), dependency_1.common.ProtoHash)); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary() { + return this.serialize(); + } + static deserializeBinary(bytes) { + return ProtoManifest.deserialize(bytes); + } + } + block.ProtoManifest = ProtoManifest; + class ProtoAccessList extends pb_1.Message { + #one_of_decls = []; + constructor(data) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [1], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("access_tuples" in data && data.access_tuples != undefined) { + this.access_tuples = data.access_tuples; + } + } + } + get access_tuples() { + return pb_1.Message.getRepeatedWrapperField(this, ProtoAccessTuple, 1); + } + set access_tuples(value) { + pb_1.Message.setRepeatedWrapperField(this, 1, value); + } + static fromObject(data) { + const message = new ProtoAccessList({}); + if (data.access_tuples != null) { + message.access_tuples = data.access_tuples.map(item => ProtoAccessTuple.fromObject(item)); + } + return message; + } + toObject() { + const data = {}; + if (this.access_tuples != null) { + data.access_tuples = this.access_tuples.map((item) => item.toObject()); + } + return data; + } + serialize(w) { + const writer = w || new pb_1.BinaryWriter(); + if (this.access_tuples.length) + writer.writeRepeatedMessage(1, this.access_tuples, (item) => item.serialize(writer)); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes) { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new ProtoAccessList(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + reader.readMessage(message.access_tuples, () => pb_1.Message.addToRepeatedWrapperField(message, 1, ProtoAccessTuple.deserialize(reader), ProtoAccessTuple)); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary() { + return this.serialize(); + } + static deserializeBinary(bytes) { + return ProtoAccessList.deserialize(bytes); + } + } + block.ProtoAccessList = ProtoAccessList; + class ProtoAccessTuple extends pb_1.Message { + #one_of_decls = []; + constructor(data) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [2], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("address" in data && data.address != undefined) { + this.address = data.address; + } + if ("storage_key" in data && data.storage_key != undefined) { + this.storage_key = data.storage_key; + } + } + } + get address() { + return pb_1.Message.getFieldWithDefault(this, 1, new Uint8Array(0)); + } + set address(value) { + pb_1.Message.setField(this, 1, value); + } + get storage_key() { + return pb_1.Message.getRepeatedWrapperField(this, dependency_1.common.ProtoHash, 2); + } + set storage_key(value) { + pb_1.Message.setRepeatedWrapperField(this, 2, value); + } + static fromObject(data) { + const message = new ProtoAccessTuple({}); + if (data.address != null) { + message.address = data.address; + } + if (data.storage_key != null) { + message.storage_key = data.storage_key.map(item => dependency_1.common.ProtoHash.fromObject(item)); + } + return message; + } + toObject() { + const data = {}; + if (this.address != null) { + data.address = this.address; + } + if (this.storage_key != null) { + data.storage_key = this.storage_key.map((item) => item.toObject()); + } + return data; + } + serialize(w) { + const writer = w || new pb_1.BinaryWriter(); + if (this.address.length) + writer.writeBytes(1, this.address); + if (this.storage_key.length) + writer.writeRepeatedMessage(2, this.storage_key, (item) => item.serialize(writer)); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes) { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new ProtoAccessTuple(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + message.address = reader.readBytes(); + break; + case 2: + reader.readMessage(message.storage_key, () => pb_1.Message.addToRepeatedWrapperField(message, 2, dependency_1.common.ProtoHash.deserialize(reader), dependency_1.common.ProtoHash)); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary() { + return this.serialize(); + } + static deserializeBinary(bytes) { + return ProtoAccessTuple.deserialize(bytes); + } + } + block.ProtoAccessTuple = ProtoAccessTuple; + class ProtoReceiptForStorage extends pb_1.Message { + #one_of_decls = []; + constructor(data) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("post_state_or_status" in data && data.post_state_or_status != undefined) { + this.post_state_or_status = data.post_state_or_status; + } + if ("cumulative_gas_used" in data && data.cumulative_gas_used != undefined) { + this.cumulative_gas_used = data.cumulative_gas_used; + } + if ("tx_hash" in data && data.tx_hash != undefined) { + this.tx_hash = data.tx_hash; + } + if ("contract_address" in data && data.contract_address != undefined) { + this.contract_address = data.contract_address; + } + if ("logs" in data && data.logs != undefined) { + this.logs = data.logs; + } + if ("etxs" in data && data.etxs != undefined) { + this.etxs = data.etxs; + } + if ("gas_used" in data && data.gas_used != undefined) { + this.gas_used = data.gas_used; + } + } + } + get post_state_or_status() { + return pb_1.Message.getFieldWithDefault(this, 1, new Uint8Array(0)); + } + set post_state_or_status(value) { + pb_1.Message.setField(this, 1, value); + } + get cumulative_gas_used() { + return pb_1.Message.getFieldWithDefault(this, 2, 0); + } + set cumulative_gas_used(value) { + pb_1.Message.setField(this, 2, value); + } + get tx_hash() { + return pb_1.Message.getWrapperField(this, dependency_1.common.ProtoHash, 3); + } + set tx_hash(value) { + pb_1.Message.setWrapperField(this, 3, value); + } + get has_tx_hash() { + return pb_1.Message.getField(this, 3) != null; + } + get contract_address() { + return pb_1.Message.getWrapperField(this, dependency_1.common.ProtoAddress, 4); + } + set contract_address(value) { + pb_1.Message.setWrapperField(this, 4, value); + } + get has_contract_address() { + return pb_1.Message.getField(this, 4) != null; + } + get logs() { + return pb_1.Message.getWrapperField(this, ProtoLogsForStorage, 5); + } + set logs(value) { + pb_1.Message.setWrapperField(this, 5, value); + } + get has_logs() { + return pb_1.Message.getField(this, 5) != null; + } + get etxs() { + return pb_1.Message.getWrapperField(this, ProtoTransactions, 6); + } + set etxs(value) { + pb_1.Message.setWrapperField(this, 6, value); + } + get has_etxs() { + return pb_1.Message.getField(this, 6) != null; + } + get gas_used() { + return pb_1.Message.getFieldWithDefault(this, 7, 0); + } + set gas_used(value) { + pb_1.Message.setField(this, 7, value); + } + static fromObject(data) { + const message = new ProtoReceiptForStorage({}); + if (data.post_state_or_status != null) { + message.post_state_or_status = data.post_state_or_status; + } + if (data.cumulative_gas_used != null) { + message.cumulative_gas_used = data.cumulative_gas_used; + } + if (data.tx_hash != null) { + message.tx_hash = dependency_1.common.ProtoHash.fromObject(data.tx_hash); + } + if (data.contract_address != null) { + message.contract_address = dependency_1.common.ProtoAddress.fromObject(data.contract_address); + } + if (data.logs != null) { + message.logs = ProtoLogsForStorage.fromObject(data.logs); + } + if (data.etxs != null) { + message.etxs = ProtoTransactions.fromObject(data.etxs); + } + if (data.gas_used != null) { + message.gas_used = data.gas_used; + } + return message; + } + toObject() { + const data = {}; + if (this.post_state_or_status != null) { + data.post_state_or_status = this.post_state_or_status; + } + if (this.cumulative_gas_used != null) { + data.cumulative_gas_used = this.cumulative_gas_used; + } + if (this.tx_hash != null) { + data.tx_hash = this.tx_hash.toObject(); + } + if (this.contract_address != null) { + data.contract_address = this.contract_address.toObject(); + } + if (this.logs != null) { + data.logs = this.logs.toObject(); + } + if (this.etxs != null) { + data.etxs = this.etxs.toObject(); + } + if (this.gas_used != null) { + data.gas_used = this.gas_used; + } + return data; + } + serialize(w) { + const writer = w || new pb_1.BinaryWriter(); + if (this.post_state_or_status.length) + writer.writeBytes(1, this.post_state_or_status); + if (this.cumulative_gas_used != 0) + writer.writeUint64(2, this.cumulative_gas_used); + if (this.has_tx_hash) + writer.writeMessage(3, this.tx_hash, () => this.tx_hash.serialize(writer)); + if (this.has_contract_address) + writer.writeMessage(4, this.contract_address, () => this.contract_address.serialize(writer)); + if (this.has_logs) + writer.writeMessage(5, this.logs, () => this.logs.serialize(writer)); + if (this.has_etxs) + writer.writeMessage(6, this.etxs, () => this.etxs.serialize(writer)); + if (this.gas_used != 0) + writer.writeUint64(7, this.gas_used); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes) { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new ProtoReceiptForStorage(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + message.post_state_or_status = reader.readBytes(); + break; + case 2: + message.cumulative_gas_used = reader.readUint64(); + break; + case 3: + reader.readMessage(message.tx_hash, () => message.tx_hash = dependency_1.common.ProtoHash.deserialize(reader)); + break; + case 4: + reader.readMessage(message.contract_address, () => message.contract_address = dependency_1.common.ProtoAddress.deserialize(reader)); + break; + case 5: + reader.readMessage(message.logs, () => message.logs = ProtoLogsForStorage.deserialize(reader)); + break; + case 6: + reader.readMessage(message.etxs, () => message.etxs = ProtoTransactions.deserialize(reader)); + break; + case 7: + message.gas_used = reader.readUint64(); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary() { + return this.serialize(); + } + static deserializeBinary(bytes) { + return ProtoReceiptForStorage.deserialize(bytes); + } + } + block.ProtoReceiptForStorage = ProtoReceiptForStorage; + class ProtoReceiptsForStorage extends pb_1.Message { + #one_of_decls = []; + constructor(data) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [1], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("receipts" in data && data.receipts != undefined) { + this.receipts = data.receipts; + } + } + } + get receipts() { + return pb_1.Message.getRepeatedWrapperField(this, ProtoReceiptForStorage, 1); + } + set receipts(value) { + pb_1.Message.setRepeatedWrapperField(this, 1, value); + } + static fromObject(data) { + const message = new ProtoReceiptsForStorage({}); + if (data.receipts != null) { + message.receipts = data.receipts.map(item => ProtoReceiptForStorage.fromObject(item)); + } + return message; + } + toObject() { + const data = {}; + if (this.receipts != null) { + data.receipts = this.receipts.map((item) => item.toObject()); + } + return data; + } + serialize(w) { + const writer = w || new pb_1.BinaryWriter(); + if (this.receipts.length) + writer.writeRepeatedMessage(1, this.receipts, (item) => item.serialize(writer)); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes) { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new ProtoReceiptsForStorage(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + reader.readMessage(message.receipts, () => pb_1.Message.addToRepeatedWrapperField(message, 1, ProtoReceiptForStorage.deserialize(reader), ProtoReceiptForStorage)); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary() { + return this.serialize(); + } + static deserializeBinary(bytes) { + return ProtoReceiptsForStorage.deserialize(bytes); + } + } + block.ProtoReceiptsForStorage = ProtoReceiptsForStorage; + class ProtoLogForStorage extends pb_1.Message { + #one_of_decls = []; + constructor(data) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [2], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("address" in data && data.address != undefined) { + this.address = data.address; + } + if ("topics" in data && data.topics != undefined) { + this.topics = data.topics; + } + if ("data" in data && data.data != undefined) { + this.data = data.data; + } + } + } + get address() { + return pb_1.Message.getWrapperField(this, dependency_1.common.ProtoAddress, 1); + } + set address(value) { + pb_1.Message.setWrapperField(this, 1, value); + } + get has_address() { + return pb_1.Message.getField(this, 1) != null; + } + get topics() { + return pb_1.Message.getRepeatedWrapperField(this, dependency_1.common.ProtoHash, 2); + } + set topics(value) { + pb_1.Message.setRepeatedWrapperField(this, 2, value); + } + get data() { + return pb_1.Message.getFieldWithDefault(this, 3, new Uint8Array(0)); + } + set data(value) { + pb_1.Message.setField(this, 3, value); + } + static fromObject(data) { + const message = new ProtoLogForStorage({}); + if (data.address != null) { + message.address = dependency_1.common.ProtoAddress.fromObject(data.address); + } + if (data.topics != null) { + message.topics = data.topics.map(item => dependency_1.common.ProtoHash.fromObject(item)); + } + if (data.data != null) { + message.data = data.data; + } + return message; + } + toObject() { + const data = {}; + if (this.address != null) { + data.address = this.address.toObject(); + } + if (this.topics != null) { + data.topics = this.topics.map((item) => item.toObject()); + } + if (this.data != null) { + data.data = this.data; + } + return data; + } + serialize(w) { + const writer = w || new pb_1.BinaryWriter(); + if (this.has_address) + writer.writeMessage(1, this.address, () => this.address.serialize(writer)); + if (this.topics.length) + writer.writeRepeatedMessage(2, this.topics, (item) => item.serialize(writer)); + if (this.data.length) + writer.writeBytes(3, this.data); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes) { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new ProtoLogForStorage(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + reader.readMessage(message.address, () => message.address = dependency_1.common.ProtoAddress.deserialize(reader)); + break; + case 2: + reader.readMessage(message.topics, () => pb_1.Message.addToRepeatedWrapperField(message, 2, dependency_1.common.ProtoHash.deserialize(reader), dependency_1.common.ProtoHash)); + break; + case 3: + message.data = reader.readBytes(); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary() { + return this.serialize(); + } + static deserializeBinary(bytes) { + return ProtoLogForStorage.deserialize(bytes); + } + } + block.ProtoLogForStorage = ProtoLogForStorage; + class ProtoLogsForStorage extends pb_1.Message { + #one_of_decls = []; + constructor(data) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [1], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("logs" in data && data.logs != undefined) { + this.logs = data.logs; + } + } + } + get logs() { + return pb_1.Message.getRepeatedWrapperField(this, ProtoLogForStorage, 1); + } + set logs(value) { + pb_1.Message.setRepeatedWrapperField(this, 1, value); + } + static fromObject(data) { + const message = new ProtoLogsForStorage({}); + if (data.logs != null) { + message.logs = data.logs.map(item => ProtoLogForStorage.fromObject(item)); + } + return message; + } + toObject() { + const data = {}; + if (this.logs != null) { + data.logs = this.logs.map((item) => item.toObject()); + } + return data; + } + serialize(w) { + const writer = w || new pb_1.BinaryWriter(); + if (this.logs.length) + writer.writeRepeatedMessage(1, this.logs, (item) => item.serialize(writer)); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes) { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new ProtoLogsForStorage(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + reader.readMessage(message.logs, () => pb_1.Message.addToRepeatedWrapperField(message, 1, ProtoLogForStorage.deserialize(reader), ProtoLogForStorage)); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary() { + return this.serialize(); + } + static deserializeBinary(bytes) { + return ProtoLogsForStorage.deserialize(bytes); + } + } + block.ProtoLogsForStorage = ProtoLogsForStorage; + class ProtoPendingHeader extends pb_1.Message { + #one_of_decls = [[1], [2]]; + constructor(data) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("header" in data && data.header != undefined) { + this.header = data.header; + } + if ("termini" in data && data.termini != undefined) { + this.termini = data.termini; + } + } + } + get header() { + return pb_1.Message.getWrapperField(this, ProtoHeader, 1); + } + set header(value) { + pb_1.Message.setOneofWrapperField(this, 1, this.#one_of_decls[0], value); + } + get has_header() { + return pb_1.Message.getField(this, 1) != null; + } + get termini() { + return pb_1.Message.getWrapperField(this, ProtoTermini, 2); + } + set termini(value) { + pb_1.Message.setOneofWrapperField(this, 2, this.#one_of_decls[1], value); + } + get has_termini() { + return pb_1.Message.getField(this, 2) != null; + } + get _header() { + const cases = { + 0: "none", + 1: "header" + }; + return cases[pb_1.Message.computeOneofCase(this, [1])]; + } + get _termini() { + const cases = { + 0: "none", + 2: "termini" + }; + return cases[pb_1.Message.computeOneofCase(this, [2])]; + } + static fromObject(data) { + const message = new ProtoPendingHeader({}); + if (data.header != null) { + message.header = ProtoHeader.fromObject(data.header); + } + if (data.termini != null) { + message.termini = ProtoTermini.fromObject(data.termini); + } + return message; + } + toObject() { + const data = {}; + if (this.header != null) { + data.header = this.header.toObject(); + } + if (this.termini != null) { + data.termini = this.termini.toObject(); + } + return data; + } + serialize(w) { + const writer = w || new pb_1.BinaryWriter(); + if (this.has_header) + writer.writeMessage(1, this.header, () => this.header.serialize(writer)); + if (this.has_termini) + writer.writeMessage(2, this.termini, () => this.termini.serialize(writer)); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes) { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new ProtoPendingHeader(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + reader.readMessage(message.header, () => message.header = ProtoHeader.deserialize(reader)); + break; + case 2: + reader.readMessage(message.termini, () => message.termini = ProtoTermini.deserialize(reader)); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary() { + return this.serialize(); + } + static deserializeBinary(bytes) { + return ProtoPendingHeader.deserialize(bytes); + } + } + block.ProtoPendingHeader = ProtoPendingHeader; + class ProtoTermini extends pb_1.Message { + #one_of_decls = []; + constructor(data) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [1, 2], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("dom_termini" in data && data.dom_termini != undefined) { + this.dom_termini = data.dom_termini; + } + if ("sub_termini" in data && data.sub_termini != undefined) { + this.sub_termini = data.sub_termini; + } + } + } + get dom_termini() { + return pb_1.Message.getRepeatedWrapperField(this, dependency_1.common.ProtoHash, 1); + } + set dom_termini(value) { + pb_1.Message.setRepeatedWrapperField(this, 1, value); + } + get sub_termini() { + return pb_1.Message.getRepeatedWrapperField(this, dependency_1.common.ProtoHash, 2); + } + set sub_termini(value) { + pb_1.Message.setRepeatedWrapperField(this, 2, value); + } + static fromObject(data) { + const message = new ProtoTermini({}); + if (data.dom_termini != null) { + message.dom_termini = data.dom_termini.map(item => dependency_1.common.ProtoHash.fromObject(item)); + } + if (data.sub_termini != null) { + message.sub_termini = data.sub_termini.map(item => dependency_1.common.ProtoHash.fromObject(item)); + } + return message; + } + toObject() { + const data = {}; + if (this.dom_termini != null) { + data.dom_termini = this.dom_termini.map((item) => item.toObject()); + } + if (this.sub_termini != null) { + data.sub_termini = this.sub_termini.map((item) => item.toObject()); + } + return data; + } + serialize(w) { + const writer = w || new pb_1.BinaryWriter(); + if (this.dom_termini.length) + writer.writeRepeatedMessage(1, this.dom_termini, (item) => item.serialize(writer)); + if (this.sub_termini.length) + writer.writeRepeatedMessage(2, this.sub_termini, (item) => item.serialize(writer)); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes) { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new ProtoTermini(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + reader.readMessage(message.dom_termini, () => pb_1.Message.addToRepeatedWrapperField(message, 1, dependency_1.common.ProtoHash.deserialize(reader), dependency_1.common.ProtoHash)); + break; + case 2: + reader.readMessage(message.sub_termini, () => pb_1.Message.addToRepeatedWrapperField(message, 2, dependency_1.common.ProtoHash.deserialize(reader), dependency_1.common.ProtoHash)); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary() { + return this.serialize(); + } + static deserializeBinary(bytes) { + return ProtoTermini.deserialize(bytes); + } + } + block.ProtoTermini = ProtoTermini; + class ProtoEtxSet extends pb_1.Message { + #one_of_decls = [[1]]; + constructor(data) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("etx_hashes" in data && data.etx_hashes != undefined) { + this.etx_hashes = data.etx_hashes; + } + } + } + get etx_hashes() { + return pb_1.Message.getFieldWithDefault(this, 1, new Uint8Array(0)); + } + set etx_hashes(value) { + pb_1.Message.setOneofField(this, 1, this.#one_of_decls[0], value); + } + get has_etx_hashes() { + return pb_1.Message.getField(this, 1) != null; + } + get _etx_hashes() { + const cases = { + 0: "none", + 1: "etx_hashes" + }; + return cases[pb_1.Message.computeOneofCase(this, [1])]; + } + static fromObject(data) { + const message = new ProtoEtxSet({}); + if (data.etx_hashes != null) { + message.etx_hashes = data.etx_hashes; + } + return message; + } + toObject() { + const data = {}; + if (this.etx_hashes != null) { + data.etx_hashes = this.etx_hashes; + } + return data; + } + serialize(w) { + const writer = w || new pb_1.BinaryWriter(); + if (this.has_etx_hashes) + writer.writeBytes(1, this.etx_hashes); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes) { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new ProtoEtxSet(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + message.etx_hashes = reader.readBytes(); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary() { + return this.serialize(); + } + static deserializeBinary(bytes) { + return ProtoEtxSet.deserialize(bytes); + } + } + block.ProtoEtxSet = ProtoEtxSet; + class ProtoPendingEtxs extends pb_1.Message { + #one_of_decls = [[1], [2]]; + constructor(data) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("header" in data && data.header != undefined) { + this.header = data.header; + } + if ("etxs" in data && data.etxs != undefined) { + this.etxs = data.etxs; + } + } + } + get header() { + return pb_1.Message.getWrapperField(this, ProtoHeader, 1); + } + set header(value) { + pb_1.Message.setOneofWrapperField(this, 1, this.#one_of_decls[0], value); + } + get has_header() { + return pb_1.Message.getField(this, 1) != null; + } + get etxs() { + return pb_1.Message.getWrapperField(this, ProtoTransactions, 2); + } + set etxs(value) { + pb_1.Message.setOneofWrapperField(this, 2, this.#one_of_decls[1], value); + } + get has_etxs() { + return pb_1.Message.getField(this, 2) != null; + } + get _header() { + const cases = { + 0: "none", + 1: "header" + }; + return cases[pb_1.Message.computeOneofCase(this, [1])]; + } + get _etxs() { + const cases = { + 0: "none", + 2: "etxs" + }; + return cases[pb_1.Message.computeOneofCase(this, [2])]; + } + static fromObject(data) { + const message = new ProtoPendingEtxs({}); + if (data.header != null) { + message.header = ProtoHeader.fromObject(data.header); + } + if (data.etxs != null) { + message.etxs = ProtoTransactions.fromObject(data.etxs); + } + return message; + } + toObject() { + const data = {}; + if (this.header != null) { + data.header = this.header.toObject(); + } + if (this.etxs != null) { + data.etxs = this.etxs.toObject(); + } + return data; + } + serialize(w) { + const writer = w || new pb_1.BinaryWriter(); + if (this.has_header) + writer.writeMessage(1, this.header, () => this.header.serialize(writer)); + if (this.has_etxs) + writer.writeMessage(2, this.etxs, () => this.etxs.serialize(writer)); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes) { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new ProtoPendingEtxs(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + reader.readMessage(message.header, () => message.header = ProtoHeader.deserialize(reader)); + break; + case 2: + reader.readMessage(message.etxs, () => message.etxs = ProtoTransactions.deserialize(reader)); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary() { + return this.serialize(); + } + static deserializeBinary(bytes) { + return ProtoPendingEtxs.deserialize(bytes); + } + } + block.ProtoPendingEtxs = ProtoPendingEtxs; + class ProtoPendingEtxsRollup extends pb_1.Message { + #one_of_decls = [[1], [2]]; + constructor(data) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("header" in data && data.header != undefined) { + this.header = data.header; + } + if ("etxs_rollup" in data && data.etxs_rollup != undefined) { + this.etxs_rollup = data.etxs_rollup; + } + } + } + get header() { + return pb_1.Message.getWrapperField(this, ProtoHeader, 1); + } + set header(value) { + pb_1.Message.setOneofWrapperField(this, 1, this.#one_of_decls[0], value); + } + get has_header() { + return pb_1.Message.getField(this, 1) != null; + } + get etxs_rollup() { + return pb_1.Message.getWrapperField(this, ProtoTransactions, 2); + } + set etxs_rollup(value) { + pb_1.Message.setOneofWrapperField(this, 2, this.#one_of_decls[1], value); + } + get has_etxs_rollup() { + return pb_1.Message.getField(this, 2) != null; + } + get _header() { + const cases = { + 0: "none", + 1: "header" + }; + return cases[pb_1.Message.computeOneofCase(this, [1])]; + } + get _etxs_rollup() { + const cases = { + 0: "none", + 2: "etxs_rollup" + }; + return cases[pb_1.Message.computeOneofCase(this, [2])]; + } + static fromObject(data) { + const message = new ProtoPendingEtxsRollup({}); + if (data.header != null) { + message.header = ProtoHeader.fromObject(data.header); + } + if (data.etxs_rollup != null) { + message.etxs_rollup = ProtoTransactions.fromObject(data.etxs_rollup); + } + return message; + } + toObject() { + const data = {}; + if (this.header != null) { + data.header = this.header.toObject(); + } + if (this.etxs_rollup != null) { + data.etxs_rollup = this.etxs_rollup.toObject(); + } + return data; + } + serialize(w) { + const writer = w || new pb_1.BinaryWriter(); + if (this.has_header) + writer.writeMessage(1, this.header, () => this.header.serialize(writer)); + if (this.has_etxs_rollup) + writer.writeMessage(2, this.etxs_rollup, () => this.etxs_rollup.serialize(writer)); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes) { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new ProtoPendingEtxsRollup(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + reader.readMessage(message.header, () => message.header = ProtoHeader.deserialize(reader)); + break; + case 2: + reader.readMessage(message.etxs_rollup, () => message.etxs_rollup = ProtoTransactions.deserialize(reader)); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary() { + return this.serialize(); + } + static deserializeBinary(bytes) { + return ProtoPendingEtxsRollup.deserialize(bytes); + } + } + block.ProtoPendingEtxsRollup = ProtoPendingEtxsRollup; + class ProtoTxIns extends pb_1.Message { + #one_of_decls = []; + constructor(data) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [1], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("tx_ins" in data && data.tx_ins != undefined) { + this.tx_ins = data.tx_ins; + } + } + } + get tx_ins() { + return pb_1.Message.getRepeatedWrapperField(this, ProtoTxIn, 1); + } + set tx_ins(value) { + pb_1.Message.setRepeatedWrapperField(this, 1, value); + } + static fromObject(data) { + const message = new ProtoTxIns({}); + if (data.tx_ins != null) { + message.tx_ins = data.tx_ins.map(item => ProtoTxIn.fromObject(item)); + } + return message; + } + toObject() { + const data = {}; + if (this.tx_ins != null) { + data.tx_ins = this.tx_ins.map((item) => item.toObject()); + } + return data; + } + serialize(w) { + const writer = w || new pb_1.BinaryWriter(); + if (this.tx_ins.length) + writer.writeRepeatedMessage(1, this.tx_ins, (item) => item.serialize(writer)); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes) { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new ProtoTxIns(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + reader.readMessage(message.tx_ins, () => pb_1.Message.addToRepeatedWrapperField(message, 1, ProtoTxIn.deserialize(reader), ProtoTxIn)); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary() { + return this.serialize(); + } + static deserializeBinary(bytes) { + return ProtoTxIns.deserialize(bytes); + } + } + block.ProtoTxIns = ProtoTxIns; + class ProtoTxOuts extends pb_1.Message { + #one_of_decls = []; + constructor(data) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [1], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("tx_outs" in data && data.tx_outs != undefined) { + this.tx_outs = data.tx_outs; + } + } + } + get tx_outs() { + return pb_1.Message.getRepeatedWrapperField(this, ProtoTxOut, 1); + } + set tx_outs(value) { + pb_1.Message.setRepeatedWrapperField(this, 1, value); + } + static fromObject(data) { + const message = new ProtoTxOuts({}); + if (data.tx_outs != null) { + message.tx_outs = data.tx_outs.map(item => ProtoTxOut.fromObject(item)); + } + return message; + } + toObject() { + const data = {}; + if (this.tx_outs != null) { + data.tx_outs = this.tx_outs.map((item) => item.toObject()); + } + return data; + } + serialize(w) { + const writer = w || new pb_1.BinaryWriter(); + if (this.tx_outs.length) + writer.writeRepeatedMessage(1, this.tx_outs, (item) => item.serialize(writer)); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes) { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new ProtoTxOuts(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + reader.readMessage(message.tx_outs, () => pb_1.Message.addToRepeatedWrapperField(message, 1, ProtoTxOut.deserialize(reader), ProtoTxOut)); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary() { + return this.serialize(); + } + static deserializeBinary(bytes) { + return ProtoTxOuts.deserialize(bytes); + } + } + block.ProtoTxOuts = ProtoTxOuts; + class ProtoTxIn extends pb_1.Message { + #one_of_decls = [[1], [2]]; + constructor(data) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("previous_out_point" in data && data.previous_out_point != undefined) { + this.previous_out_point = data.previous_out_point; + } + if ("pub_key" in data && data.pub_key != undefined) { + this.pub_key = data.pub_key; + } + } + } + get previous_out_point() { + return pb_1.Message.getWrapperField(this, ProtoOutPoint, 1); + } + set previous_out_point(value) { + pb_1.Message.setOneofWrapperField(this, 1, this.#one_of_decls[0], value); + } + get has_previous_out_point() { + return pb_1.Message.getField(this, 1) != null; + } + get pub_key() { + return pb_1.Message.getFieldWithDefault(this, 2, new Uint8Array(0)); + } + set pub_key(value) { + pb_1.Message.setOneofField(this, 2, this.#one_of_decls[1], value); + } + get has_pub_key() { + return pb_1.Message.getField(this, 2) != null; + } + get _previous_out_point() { + const cases = { + 0: "none", + 1: "previous_out_point" + }; + return cases[pb_1.Message.computeOneofCase(this, [1])]; + } + get _pub_key() { + const cases = { + 0: "none", + 2: "pub_key" + }; + return cases[pb_1.Message.computeOneofCase(this, [2])]; + } + static fromObject(data) { + const message = new ProtoTxIn({}); + if (data.previous_out_point != null) { + message.previous_out_point = ProtoOutPoint.fromObject(data.previous_out_point); + } + if (data.pub_key != null) { + message.pub_key = data.pub_key; + } + return message; + } + toObject() { + const data = {}; + if (this.previous_out_point != null) { + data.previous_out_point = this.previous_out_point.toObject(); + } + if (this.pub_key != null) { + data.pub_key = this.pub_key; + } + return data; + } + serialize(w) { + const writer = w || new pb_1.BinaryWriter(); + if (this.has_previous_out_point) + writer.writeMessage(1, this.previous_out_point, () => this.previous_out_point.serialize(writer)); + if (this.has_pub_key) + writer.writeBytes(2, this.pub_key); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes) { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new ProtoTxIn(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + reader.readMessage(message.previous_out_point, () => message.previous_out_point = ProtoOutPoint.deserialize(reader)); + break; + case 2: + message.pub_key = reader.readBytes(); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary() { + return this.serialize(); + } + static deserializeBinary(bytes) { + return ProtoTxIn.deserialize(bytes); + } + } + block.ProtoTxIn = ProtoTxIn; + class ProtoOutPoint extends pb_1.Message { + #one_of_decls = [[1], [2]]; + constructor(data) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("hash" in data && data.hash != undefined) { + this.hash = data.hash; + } + if ("index" in data && data.index != undefined) { + this.index = data.index; + } + } + } + get hash() { + return pb_1.Message.getWrapperField(this, dependency_1.common.ProtoHash, 1); + } + set hash(value) { + pb_1.Message.setOneofWrapperField(this, 1, this.#one_of_decls[0], value); + } + get has_hash() { + return pb_1.Message.getField(this, 1) != null; + } + get index() { + return pb_1.Message.getFieldWithDefault(this, 2, 0); + } + set index(value) { + pb_1.Message.setOneofField(this, 2, this.#one_of_decls[1], value); + } + get has_index() { + return pb_1.Message.getField(this, 2) != null; + } + get _hash() { + const cases = { + 0: "none", + 1: "hash" + }; + return cases[pb_1.Message.computeOneofCase(this, [1])]; + } + get _index() { + const cases = { + 0: "none", + 2: "index" + }; + return cases[pb_1.Message.computeOneofCase(this, [2])]; + } + static fromObject(data) { + const message = new ProtoOutPoint({}); + if (data.hash != null) { + message.hash = dependency_1.common.ProtoHash.fromObject(data.hash); + } + if (data.index != null) { + message.index = data.index; + } + return message; + } + toObject() { + const data = {}; + if (this.hash != null) { + data.hash = this.hash.toObject(); + } + if (this.index != null) { + data.index = this.index; + } + return data; + } + serialize(w) { + const writer = w || new pb_1.BinaryWriter(); + if (this.has_hash) + writer.writeMessage(1, this.hash, () => this.hash.serialize(writer)); + if (this.has_index) + writer.writeUint32(2, this.index); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes) { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new ProtoOutPoint(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + reader.readMessage(message.hash, () => message.hash = dependency_1.common.ProtoHash.deserialize(reader)); + break; + case 2: + message.index = reader.readUint32(); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary() { + return this.serialize(); + } + static deserializeBinary(bytes) { + return ProtoOutPoint.deserialize(bytes); + } + } + block.ProtoOutPoint = ProtoOutPoint; + class ProtoTxOut extends pb_1.Message { + #one_of_decls = [[1], [2]]; + constructor(data) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("denomination" in data && data.denomination != undefined) { + this.denomination = data.denomination; + } + if ("address" in data && data.address != undefined) { + this.address = data.address; + } + } + } + get denomination() { + return pb_1.Message.getFieldWithDefault(this, 1, 0); + } + set denomination(value) { + pb_1.Message.setOneofField(this, 1, this.#one_of_decls[0], value); + } + get has_denomination() { + return pb_1.Message.getField(this, 1) != null; + } + get address() { + return pb_1.Message.getFieldWithDefault(this, 2, new Uint8Array(0)); + } + set address(value) { + pb_1.Message.setOneofField(this, 2, this.#one_of_decls[1], value); + } + get has_address() { + return pb_1.Message.getField(this, 2) != null; + } + get _denomination() { + const cases = { + 0: "none", + 1: "denomination" + }; + return cases[pb_1.Message.computeOneofCase(this, [1])]; + } + get _address() { + const cases = { + 0: "none", + 2: "address" + }; + return cases[pb_1.Message.computeOneofCase(this, [2])]; + } + static fromObject(data) { + const message = new ProtoTxOut({}); + if (data.denomination != null) { + message.denomination = data.denomination; + } + if (data.address != null) { + message.address = data.address; + } + return message; + } + toObject() { + const data = {}; + if (this.denomination != null) { + data.denomination = this.denomination; + } + if (this.address != null) { + data.address = this.address; + } + return data; + } + serialize(w) { + const writer = w || new pb_1.BinaryWriter(); + if (this.has_denomination) + writer.writeUint32(1, this.denomination); + if (this.has_address) + writer.writeBytes(2, this.address); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes) { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new ProtoTxOut(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + message.denomination = reader.readUint32(); + break; + case 2: + message.address = reader.readBytes(); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary() { + return this.serialize(); + } + static deserializeBinary(bytes) { + return ProtoTxOut.deserialize(bytes); + } + } + block.ProtoTxOut = ProtoTxOut; +})(block || (block = {})); +//# sourceMappingURL=proto_block.js.map \ No newline at end of file diff --git a/lib.esm/utils/ProtoBuf/proto_block.js.map b/lib.esm/utils/ProtoBuf/proto_block.js.map new file mode 100644 index 00000000..2ca4edee --- /dev/null +++ b/lib.esm/utils/ProtoBuf/proto_block.js.map @@ -0,0 +1 @@ +{"version":3,"file":"proto_block.js","sourceRoot":"","sources":["../../../src.ts/utils/ProtoBuf/proto_block.ts"],"names":[],"mappings":"AAAA;;;;oDAIoD;AACpD,OAAO,KAAK,YAAY,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AACxC,MAAM,KAAW,KAAK,CAukHrB;AAvkHD,WAAiB,KAAK;IAClB,MAAa,UAAW,SAAQ,IAAI,CAAC,OAAO;QACxC,aAAa,GAAe,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QACvC,YAAY,IAIR;YACA,KAAK,EAAE,CAAC;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,MAAM,CAAC,UAAU,EAAE,CAAC;wBAC3C,MAAM;oBACV,KAAK,CAAC;wBACF,OAAO,CAAC,OAAO,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;wBACrC,MAAM;oBACV,OAAO,CAAC,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;iBAC/B;aACJ;YACD,OAAO,OAAO,CAAC;QACnB,CAAC;QACD,eAAe;YACX,OAAO,IAAI,CAAC,SAAS,EAAE,CAAC;QAC5B,CAAC;QACD,MAAM,CAAC,iBAAiB,CAAC,KAAiB;YACtC,OAAO,UAAU,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QACzC,CAAC;KACJ;IAlHY,gBAAU,aAkHtB,CAAA;AACL,CAAC,EAvkHgB,KAAK,KAAL,KAAK,QAukHrB"} \ No newline at end of file diff --git a/lib.esm/utils/ProtoBuf/proto_common.d.ts b/lib.esm/utils/ProtoBuf/proto_common.d.ts new file mode 100644 index 00000000..4191729b --- /dev/null +++ b/lib.esm/utils/ProtoBuf/proto_common.d.ts @@ -0,0 +1,87 @@ +/** + * Generated by the protoc-gen-ts. DO NOT EDIT! + * compiler version: 4.25.3 + * source: proto_common.proto + * git: https://github.com/thesayyn/protoc-gen-ts */ +import * as pb_1 from "google-protobuf"; +export declare namespace common { + class ProtoLocation extends pb_1.Message { + #private; + constructor(data?: any[] | { + value?: Uint8Array; + }); + get value(): Uint8Array; + set value(value: Uint8Array); + static fromObject(data: { + value?: Uint8Array; + }): ProtoLocation; + toObject(): { + value?: Uint8Array | undefined; + }; + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): ProtoLocation; + serializeBinary(): Uint8Array; + static deserializeBinary(bytes: Uint8Array): ProtoLocation; + } + class ProtoHash extends pb_1.Message { + #private; + constructor(data?: any[] | { + value?: Uint8Array; + }); + get value(): Uint8Array; + set value(value: Uint8Array); + static fromObject(data: { + value?: Uint8Array; + }): ProtoHash; + toObject(): { + value?: Uint8Array | undefined; + }; + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): ProtoHash; + serializeBinary(): Uint8Array; + static deserializeBinary(bytes: Uint8Array): ProtoHash; + } + class ProtoHashes extends pb_1.Message { + #private; + constructor(data?: any[] | { + hashes?: ProtoHash[]; + }); + get hashes(): ProtoHash[]; + set hashes(value: ProtoHash[]); + static fromObject(data: { + hashes?: ReturnType[]; + }): ProtoHashes; + toObject(): { + hashes?: { + value?: Uint8Array | undefined; + }[] | undefined; + }; + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): ProtoHashes; + serializeBinary(): Uint8Array; + static deserializeBinary(bytes: Uint8Array): ProtoHashes; + } + class ProtoAddress extends pb_1.Message { + #private; + constructor(data?: any[] | { + value?: Uint8Array; + }); + get value(): Uint8Array; + set value(value: Uint8Array); + static fromObject(data: { + value?: Uint8Array; + }): ProtoAddress; + toObject(): { + value?: Uint8Array | undefined; + }; + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): ProtoAddress; + serializeBinary(): Uint8Array; + static deserializeBinary(bytes: Uint8Array): ProtoAddress; + } +} +//# sourceMappingURL=proto_common.d.ts.map \ No newline at end of file diff --git a/lib.esm/utils/ProtoBuf/proto_common.d.ts.map b/lib.esm/utils/ProtoBuf/proto_common.d.ts.map new file mode 100644 index 00000000..d3230783 --- /dev/null +++ b/lib.esm/utils/ProtoBuf/proto_common.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"proto_common.d.ts","sourceRoot":"","sources":["../../../src.ts/utils/ProtoBuf/proto_common.ts"],"names":[],"mappings":"AAAA;;;;oDAIoD;AACpD,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AACxC,yBAAiB,MAAM,CAAC;IACpB,MAAa,aAAc,SAAQ,IAAI,CAAC,OAA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ils/ProtoBuf/proto_common.js new file mode 100644 index 00000000..480f21f0 --- /dev/null +++ b/lib.esm/utils/ProtoBuf/proto_common.js @@ -0,0 +1,250 @@ +/** + * Generated by the protoc-gen-ts. DO NOT EDIT! + * compiler version: 4.25.3 + * source: proto_common.proto + * git: https://github.com/thesayyn/protoc-gen-ts */ +import * as pb_1 from "google-protobuf"; +export var common; +(function (common) { + class ProtoLocation extends pb_1.Message { + #one_of_decls = []; + constructor(data) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("value" in data && data.value != undefined) { + this.value = data.value; + } + } + } + get value() { + return pb_1.Message.getFieldWithDefault(this, 1, new Uint8Array(0)); + } + set value(value) { + pb_1.Message.setField(this, 1, value); + } + static fromObject(data) { + const message = new ProtoLocation({}); + if (data.value != null) { + message.value = data.value; + } + return message; + } + toObject() { + const data = {}; + if (this.value != null) { + data.value = this.value; + } + return data; + } + serialize(w) { + const writer = w || new pb_1.BinaryWriter(); + if (this.value.length) + writer.writeBytes(1, this.value); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes) { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new ProtoLocation(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + message.value = reader.readBytes(); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary() { + return this.serialize(); + } + static deserializeBinary(bytes) { + return ProtoLocation.deserialize(bytes); + } + } + common.ProtoLocation = ProtoLocation; + class ProtoHash extends pb_1.Message { + #one_of_decls = []; + constructor(data) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("value" in data && data.value != undefined) { + this.value = data.value; + } + } + } + get value() { + return pb_1.Message.getFieldWithDefault(this, 1, new Uint8Array(0)); + } + set value(value) { + pb_1.Message.setField(this, 1, value); + } + static fromObject(data) { + const message = new ProtoHash({}); + if (data.value != null) { + message.value = data.value; + } + return message; + } + toObject() { + const data = {}; + if (this.value != null) { + data.value = this.value; + } + return data; + } + serialize(w) { + const writer = w || new pb_1.BinaryWriter(); + if (this.value.length) + writer.writeBytes(1, this.value); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes) { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new ProtoHash(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + message.value = reader.readBytes(); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary() { + return this.serialize(); + } + static deserializeBinary(bytes) { + return ProtoHash.deserialize(bytes); + } + } + common.ProtoHash = ProtoHash; + class ProtoHashes extends pb_1.Message { + #one_of_decls = []; + constructor(data) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [1], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("hashes" in data && data.hashes != undefined) { + this.hashes = data.hashes; + } + } + } + get hashes() { + return pb_1.Message.getRepeatedWrapperField(this, ProtoHash, 1); + } + set hashes(value) { + pb_1.Message.setRepeatedWrapperField(this, 1, value); + } + static fromObject(data) { + const message = new ProtoHashes({}); + if (data.hashes != null) { + message.hashes = data.hashes.map(item => ProtoHash.fromObject(item)); + } + return message; + } + toObject() { + const data = {}; + if (this.hashes != null) { + data.hashes = this.hashes.map((item) => item.toObject()); + } + return data; + } + serialize(w) { + const writer = w || new pb_1.BinaryWriter(); + if (this.hashes.length) + writer.writeRepeatedMessage(1, this.hashes, (item) => item.serialize(writer)); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes) { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new ProtoHashes(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + reader.readMessage(message.hashes, () => pb_1.Message.addToRepeatedWrapperField(message, 1, ProtoHash.deserialize(reader), ProtoHash)); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary() { + return this.serialize(); + } + static deserializeBinary(bytes) { + return ProtoHashes.deserialize(bytes); + } + } + common.ProtoHashes = ProtoHashes; + class ProtoAddress extends pb_1.Message { + #one_of_decls = []; + constructor(data) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("value" in data && data.value != undefined) { + this.value = data.value; + } + } + } + get value() { + return pb_1.Message.getFieldWithDefault(this, 1, new Uint8Array(0)); + } + set value(value) { + pb_1.Message.setField(this, 1, value); + } + static fromObject(data) { + const message = new ProtoAddress({}); + if (data.value != null) { + message.value = data.value; + } + return message; + } + toObject() { + const data = {}; + if (this.value != null) { + data.value = this.value; + } + return data; + } + serialize(w) { + const writer = w || new pb_1.BinaryWriter(); + if (this.value.length) + writer.writeBytes(1, this.value); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes) { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new ProtoAddress(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + message.value = reader.readBytes(); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary() { + return this.serialize(); + } + static deserializeBinary(bytes) { + return ProtoAddress.deserialize(bytes); + } + } + common.ProtoAddress = ProtoAddress; +})(common || (common = {})); +//# sourceMappingURL=proto_common.js.map \ No newline at end of file diff --git a/lib.esm/utils/ProtoBuf/proto_common.js.map b/lib.esm/utils/ProtoBuf/proto_common.js.map new file mode 100644 index 00000000..300b555f --- /dev/null +++ b/lib.esm/utils/ProtoBuf/proto_common.js.map @@ -0,0 +1 @@ +{"version":3,"file":"proto_common.js","sourceRoot":"","sources":["../../../src.ts/utils/ProtoBuf/proto_common.ts"],"names":[],"mappings":"AAAA;;;;oDAIoD;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diff --git a/lib.esm/utils/base58.d.ts b/lib.esm/utils/base58.d.ts new file mode 100644 index 00000000..8b377936 --- /dev/null +++ b/lib.esm/utils/base58.d.ts @@ -0,0 +1,23 @@ +/** + * The [Base58 Encoding](link-base58) scheme allows a **numeric** value + * to be encoded as a compact string using a radix of 58 using only + * alpha-numeric characters. Confusingly similar characters are omitted + * (i.e. ``"l0O"``). + * + * Note that Base58 encodes a **numeric** value, not arbitrary bytes, + * since any zero-bytes on the left would get removed. To mitigate this + * issue most schemes that use Base58 choose specific high-order values + * to ensure non-zero prefixes. + * + * @_subsection: api/utils:Base58 Encoding [about-base58] + */ +import type { BytesLike } from "./index.js"; +/** + * Encode %%value%% as a Base58-encoded string. + */ +export declare function encodeBase58(_value: BytesLike): string; +/** + * Decode the Base58-encoded %%value%%. + */ +export declare function decodeBase58(value: string): bigint; +//# sourceMappingURL=base58.d.ts.map \ No newline at end of file diff --git a/lib.esm/utils/base58.d.ts.map b/lib.esm/utils/base58.d.ts.map new file mode 100644 index 00000000..a20c8167 --- /dev/null +++ b/lib.esm/utils/base58.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"base58.d.ts","sourceRoot":"","sources":["../../src.ts/utils/base58.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAMH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAsB5C;;GAEG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,CAiBtD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAOlD"} \ No newline at end of file diff --git a/lib.esm/utils/base58.js b/lib.esm/utils/base58.js new file mode 100644 index 00000000..6e8f27cb --- /dev/null +++ b/lib.esm/utils/base58.js @@ -0,0 +1,63 @@ +/** + * The [Base58 Encoding](link-base58) scheme allows a **numeric** value + * to be encoded as a compact string using a radix of 58 using only + * alpha-numeric characters. Confusingly similar characters are omitted + * (i.e. ``"l0O"``). + * + * Note that Base58 encodes a **numeric** value, not arbitrary bytes, + * since any zero-bytes on the left would get removed. To mitigate this + * issue most schemes that use Base58 choose specific high-order values + * to ensure non-zero prefixes. + * + * @_subsection: api/utils:Base58 Encoding [about-base58] + */ +import { getBytes } from "./data.js"; +import { assertArgument } from "./errors.js"; +import { toBigInt } from "./maths.js"; +const Alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; +let Lookup = null; +function getAlpha(letter) { + if (Lookup == null) { + Lookup = {}; + for (let i = 0; i < Alphabet.length; i++) { + Lookup[Alphabet[i]] = BigInt(i); + } + } + const result = Lookup[letter]; + assertArgument(result != null, `invalid base58 value`, "letter", letter); + return result; +} +const BN_0 = BigInt(0); +const BN_58 = BigInt(58); +/** + * Encode %%value%% as a Base58-encoded string. + */ +export function encodeBase58(_value) { + const bytes = getBytes(_value); + let value = toBigInt(bytes); + let result = ""; + while (value) { + result = Alphabet[Number(value % BN_58)] + result; + value /= BN_58; + } + // Account for leading padding zeros + for (let i = 0; i < bytes.length; i++) { + if (bytes[i]) { + break; + } + result = Alphabet[0] + result; + } + return result; +} +/** + * Decode the Base58-encoded %%value%%. + */ +export function decodeBase58(value) { + let result = BN_0; + for (let i = 0; i < value.length; i++) { + result *= BN_58; + result += getAlpha(value[i]); + } + return result; +} +//# sourceMappingURL=base58.js.map \ No newline at end of file diff --git a/lib.esm/utils/base58.js.map b/lib.esm/utils/base58.js.map new file mode 100644 index 00000000..942d56a7 --- /dev/null +++ b/lib.esm/utils/base58.js.map @@ -0,0 +1 @@ +{"version":3,"file":"base58.js","sourceRoot":"","sources":["../../src.ts/utils/base58.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAKt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AAC;KACjC;IAED,OAAO,MAAM,CAAC;AAClB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,KAAa;IACtC,IAAI,MAAM,GAAG,IAAI,CAAC;IAClB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACnC,MAAM,IAAI,KAAK,CAAC;QAChB,MAAM,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;KAChC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC"} \ No newline at end of file diff --git a/lib.esm/utils/base64-browser.d.ts b/lib.esm/utils/base64-browser.d.ts new file mode 100644 index 00000000..ea96c442 --- /dev/null +++ b/lib.esm/utils/base64-browser.d.ts @@ -0,0 +1,4 @@ +import type { BytesLike } from "./data.js"; +export declare function decodeBase64(textData: string): Uint8Array; +export declare function encodeBase64(_data: BytesLike): string; +//# sourceMappingURL=base64-browser.d.ts.map \ No newline at end of file diff --git a/lib.esm/utils/base64-browser.d.ts.map b/lib.esm/utils/base64-browser.d.ts.map new file mode 100644 index 00000000..0adb8e7b --- /dev/null +++ b/lib.esm/utils/base64-browser.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"base64-browser.d.ts","sourceRoot":"","sources":["../../src.ts/utils/base64-browser.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAG3C,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,CAOzD;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,CAOrD"} \ No newline at end of file diff --git a/lib.esm/utils/base64-browser.js b/lib.esm/utils/base64-browser.js new file mode 100644 index 00000000..b9b98a35 --- /dev/null +++ b/lib.esm/utils/base64-browser.js @@ -0,0 +1,19 @@ +// utils/base64-browser +import { getBytes } from "./data.js"; +export function decodeBase64(textData) { + textData = atob(textData); + const data = new Uint8Array(textData.length); + for (let i = 0; i < textData.length; i++) { + data[i] = textData.charCodeAt(i); + } + return getBytes(data); +} +export function encodeBase64(_data) { + const data = getBytes(_data); + let textData = ""; + for (let i = 0; i < data.length; i++) { + textData += String.fromCharCode(data[i]); + } + return btoa(textData); +} +//# sourceMappingURL=base64-browser.js.map \ No newline at end of file diff --git a/lib.esm/utils/base64-browser.js.map b/lib.esm/utils/base64-browser.js.map new file mode 100644 index 00000000..5ece25ed --- /dev/null +++ b/lib.esm/utils/base64-browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"base64-browser.js","sourceRoot":"","sources":["../../src.ts/utils/base64-browser.ts"],"names":[],"mappings":"AACA,uBAAuB;AAEvB,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAKrC,MAAM,UAAU,YAAY,CAAC,QAAgB;IACzC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC1B,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC7C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACtC,IAAI,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;KACpC;IACD,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAAgB;IACzC,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC7B,IAAI,QAAQ,GAAG,EAAE,CAAC;IAClB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QAClC,QAAQ,IAAI,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;KAC5C;IACD,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC;AAC1B,CAAC"} \ No newline at end of file diff --git a/lib.esm/utils/base64.d.ts b/lib.esm/utils/base64.d.ts new file mode 100644 index 00000000..0cab5328 --- /dev/null +++ b/lib.esm/utils/base64.d.ts @@ -0,0 +1,40 @@ +import type { BytesLike } from "./data.js"; +/** + * Decodes the base-64 encoded %%value%%. + * + * @example: + * // The decoded value is always binary data... + * result = decodeBase64("SGVsbG8gV29ybGQhIQ==") + * //_result: + * + * // ...use toUtf8String to convert it to a string. + * toUtf8String(result) + * //_result: + * + * // Decoding binary data + * decodeBase64("EjQ=") + * //_result: + */ +export declare function decodeBase64(value: string): Uint8Array; +/** + * Encodes %%data%% as a base-64 encoded string. + * + * @example: + * // Encoding binary data as a hexstring + * encodeBase64("0x1234") + * //_result: + * + * // Encoding binary data as a Uint8Array + * encodeBase64(new Uint8Array([ 0x12, 0x34 ])) + * //_result: + * + * // The input MUST be data... + * encodeBase64("Hello World!!") + * //_error: + * + * // ...use toUtf8Bytes for this. + * encodeBase64(toUtf8Bytes("Hello World!!")) + * //_result: + */ +export declare function encodeBase64(data: BytesLike): string; +//# sourceMappingURL=base64.d.ts.map \ No newline at end of file diff --git a/lib.esm/utils/base64.d.ts.map b/lib.esm/utils/base64.d.ts.map new file mode 100644 index 00000000..90ad51c1 --- /dev/null +++ b/lib.esm/utils/base64.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"base64.d.ts","sourceRoot":"","sources":["../../src.ts/utils/base64.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAG3C;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAEtD;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,CAEpD"} \ No newline at end of file diff --git a/lib.esm/utils/base64.js b/lib.esm/utils/base64.js new file mode 100644 index 00000000..8ac4416b --- /dev/null +++ b/lib.esm/utils/base64.js @@ -0,0 +1,53 @@ +/** + * [Base64 encoding](link-wiki-base64) using 6-bit words to encode + * arbitrary bytes into a string using 65 printable symbols, the + * upper-case and lower-case alphabet, the digits ``0`` through ``9``, + * ``"+"`` and ``"/"`` with the ``"="`` used for padding. + * + * @_subsection: api/utils:Base64 Encoding [about-base64] + */ +import { getBytes, getBytesCopy } from "./data.js"; +/** + * Decodes the base-64 encoded %%value%%. + * + * @example: + * // The decoded value is always binary data... + * result = decodeBase64("SGVsbG8gV29ybGQhIQ==") + * //_result: + * + * // ...use toUtf8String to convert it to a string. + * toUtf8String(result) + * //_result: + * + * // Decoding binary data + * decodeBase64("EjQ=") + * //_result: + */ +export function decodeBase64(value) { + return getBytesCopy(Buffer.from(value, "base64")); +} +; +/** + * Encodes %%data%% as a base-64 encoded string. + * + * @example: + * // Encoding binary data as a hexstring + * encodeBase64("0x1234") + * //_result: + * + * // Encoding binary data as a Uint8Array + * encodeBase64(new Uint8Array([ 0x12, 0x34 ])) + * //_result: + * + * // The input MUST be data... + * encodeBase64("Hello World!!") + * //_error: + * + * // ...use toUtf8Bytes for this. + * encodeBase64(toUtf8Bytes("Hello World!!")) + * //_result: + */ +export function encodeBase64(data) { + return Buffer.from(getBytes(data)).toString("base64"); +} +//# sourceMappingURL=base64.js.map \ No newline at end of file diff --git a/lib.esm/utils/base64.js.map b/lib.esm/utils/base64.js.map new file mode 100644 index 00000000..e24e6606 --- /dev/null +++ b/lib.esm/utils/base64.js.map @@ -0,0 +1 @@ +{"version":3,"file":"base64.js","sourceRoot":"","sources":["../../src.ts/utils/base64.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAKnD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,YAAY,CAAC,KAAa;IACtC,OAAO,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC;AACtD,CAAC;AAAA,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,YAAY,CAAC,IAAe;IACxC,OAAO,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAC1D,CAAC"} \ No newline at end of file diff --git a/lib.esm/utils/data.d.ts b/lib.esm/utils/data.d.ts new file mode 100644 index 00000000..59f4fc0e --- /dev/null +++ b/lib.esm/utils/data.d.ts @@ -0,0 +1,93 @@ +/** + * A [[HexString]] whose length is even, which ensures it is a valid + * representation of binary data. + */ +export type DataHexString = string; +/** + * A string which is prefixed with ``0x`` and followed by any number + * of case-agnostic hexadecimal characters. + * + * It must match the regular expression ``/0x[0-9A-Fa-f]*\/``. + */ +export type HexString = string; +/** + * An object that can be used to represent binary data. + */ +export type BytesLike = DataHexString | Uint8Array; +/** + * Get a typed Uint8Array for %%value%%. If already a Uint8Array + * the original %%value%% is returned; if a copy is required use + * [[getBytesCopy]]. + * + * @see: getBytesCopy + */ +export declare function getBytes(value: BytesLike, name?: string): Uint8Array; +/** + * Get a typed Uint8Array for %%value%%, creating a copy if necessary + * to prevent any modifications of the returned value from being + * reflected elsewhere. + * + * @see: getBytes + */ +export declare function getBytesCopy(value: BytesLike, name?: string): Uint8Array; +/** + * Returns true if %%value%% is a valid [[HexString]]. + * + * If %%length%% is ``true`` or a //number//, it also checks that + * %%value%% is a valid [[DataHexString]] of %%length%% (if a //number//) + * bytes of data (e.g. ``0x1234`` is 2 bytes). + */ +export declare function isHexString(value: any, length?: number | boolean): value is `0x${string}`; +/** + * Returns true if %%value%% is a valid representation of arbitrary + * data (i.e. a valid [[DataHexString]] or a Uint8Array). + */ +export declare function isBytesLike(value: any): value is BytesLike; +/** + * Returns a [[DataHexString]] representation of %%data%%. + */ +export declare function hexlify(data: BytesLike): string; +/** + * Returns a [[DataHexString]] by concatenating all values + * within %%data%%. + */ +export declare function concat(datas: ReadonlyArray): string; +/** + * Returns the length of %%data%%, in bytes. + */ +export declare function dataLength(data: BytesLike): number; +/** + * Returns a [[DataHexString]] by slicing %%data%% from the %%start%% + * offset to the %%end%% offset. + * + * By default %%start%% is 0 and %%end%% is the length of %%data%%. + */ +export declare function dataSlice(data: BytesLike, start?: number, end?: number): string; +/** + * Return the [[DataHexString]] result by stripping all **leading** + ** zero bytes from %%data%%. + */ +export declare function stripZerosLeft(data: BytesLike): string; +/** + * Return the [[DataHexString]] of %%data%% padded on the **left** + * to %%length%% bytes. + * + * If %%data%% already exceeds %%length%%, a [[BufferOverrunError]] is + * thrown. + * + * This pads data the same as **values** are in Solidity + * (e.g. ``uint128``). + */ +export declare function zeroPadValue(data: BytesLike, length: number): string; +/** + * Return the [[DataHexString]] of %%data%% padded on the **right** + * to %%length%% bytes. + * + * If %%data%% already exceeds %%length%%, a [[BufferOverrunError]] is + * thrown. + * + * This pads data the same as **bytes** are in Solidity + * (e.g. ``bytes16``). + */ +export declare function zeroPadBytes(data: BytesLike, length: number): string; +//# sourceMappingURL=data.d.ts.map \ No newline at end of file diff --git a/lib.esm/utils/data.d.ts.map b/lib.esm/utils/data.d.ts.map new file mode 100644 index 00000000..b488d824 --- /dev/null +++ b/lib.esm/utils/data.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../src.ts/utils/data.ts"],"names":[],"mappings":"AAQA;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC;AAEnC;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC;AAE/B;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG,UAAU,CAAC;AAqBnD;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,CAEpE;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,CAExE;AAGD;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,KAAK,IAAI,KAAM,MAAO,EAAE,CAS3F;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,SAAS,CAE1D;AAID;;GAEG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,CAS/C;AAED;;;GAGG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,aAAa,CAAC,SAAS,CAAC,GAAG,MAAM,CAE9D;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,CAGlD;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAQ/E;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,CAItD;AAqBD;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAEpE;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAEpE"} \ No newline at end of file diff --git a/lib.esm/utils/data.js b/lib.esm/utils/data.js new file mode 100644 index 00000000..69dc85f2 --- /dev/null +++ b/lib.esm/utils/data.js @@ -0,0 +1,170 @@ +/** + * Some data helpers. + * + * + * @_subsection api/utils:Data Helpers [about-data] + */ +import { assert, assertArgument } from "./errors.js"; +function _getBytes(value, name, copy) { + if (value instanceof Uint8Array) { + if (copy) { + return new Uint8Array(value); + } + return value; + } + if (typeof (value) === "string" && value.match(/^0x([0-9a-f][0-9a-f])*$/i)) { + const result = new Uint8Array((value.length - 2) / 2); + let offset = 2; + for (let i = 0; i < result.length; i++) { + result[i] = parseInt(value.substring(offset, offset + 2), 16); + offset += 2; + } + return result; + } + assertArgument(false, "invalid BytesLike value", name || "value", value); +} +/** + * Get a typed Uint8Array for %%value%%. If already a Uint8Array + * the original %%value%% is returned; if a copy is required use + * [[getBytesCopy]]. + * + * @see: getBytesCopy + */ +export function getBytes(value, name) { + return _getBytes(value, name, false); +} +/** + * Get a typed Uint8Array for %%value%%, creating a copy if necessary + * to prevent any modifications of the returned value from being + * reflected elsewhere. + * + * @see: getBytes + */ +export function getBytesCopy(value, name) { + return _getBytes(value, name, true); +} +/** + * Returns true if %%value%% is a valid [[HexString]]. + * + * If %%length%% is ``true`` or a //number//, it also checks that + * %%value%% is a valid [[DataHexString]] of %%length%% (if a //number//) + * bytes of data (e.g. ``0x1234`` is 2 bytes). + */ +export function isHexString(value, length) { + if (typeof (value) !== "string" || !value.match(/^0x[0-9A-Fa-f]*$/)) { + return false; + } + if (typeof (length) === "number" && value.length !== 2 + 2 * length) { + return false; + } + if (length === true && (value.length % 2) !== 0) { + return false; + } + return true; +} +/** + * Returns true if %%value%% is a valid representation of arbitrary + * data (i.e. a valid [[DataHexString]] or a Uint8Array). + */ +export function isBytesLike(value) { + return (isHexString(value, true) || (value instanceof Uint8Array)); +} +const HexCharacters = "0123456789abcdef"; +/** + * Returns a [[DataHexString]] representation of %%data%%. + */ +export function hexlify(data) { + const bytes = getBytes(data); + let result = "0x"; + for (let i = 0; i < bytes.length; i++) { + const v = bytes[i]; + result += HexCharacters[(v & 0xf0) >> 4] + HexCharacters[v & 0x0f]; + } + return result; +} +/** + * Returns a [[DataHexString]] by concatenating all values + * within %%data%%. + */ +export function concat(datas) { + return "0x" + datas.map((d) => hexlify(d).substring(2)).join(""); +} +/** + * Returns the length of %%data%%, in bytes. + */ +export function dataLength(data) { + if (isHexString(data, true)) { + return (data.length - 2) / 2; + } + return getBytes(data).length; +} +/** + * Returns a [[DataHexString]] by slicing %%data%% from the %%start%% + * offset to the %%end%% offset. + * + * By default %%start%% is 0 and %%end%% is the length of %%data%%. + */ +export function dataSlice(data, start, end) { + const bytes = getBytes(data); + if (end != null && end > bytes.length) { + assert(false, "cannot slice beyond data bounds", "BUFFER_OVERRUN", { + buffer: bytes, length: bytes.length, offset: end + }); + } + return hexlify(bytes.slice((start == null) ? 0 : start, (end == null) ? bytes.length : end)); +} +/** + * Return the [[DataHexString]] result by stripping all **leading** + ** zero bytes from %%data%%. + */ +export function stripZerosLeft(data) { + let bytes = hexlify(data).substring(2); + while (bytes.startsWith("00")) { + bytes = bytes.substring(2); + } + return "0x" + bytes; +} +function zeroPad(data, length, left) { + const bytes = getBytes(data); + assert(length >= bytes.length, "padding exceeds data length", "BUFFER_OVERRUN", { + buffer: new Uint8Array(bytes), + length: length, + offset: length + 1 + }); + const result = new Uint8Array(length); + result.fill(0); + if (left) { + result.set(bytes, length - bytes.length); + } + else { + result.set(bytes, 0); + } + return hexlify(result); +} +/** + * Return the [[DataHexString]] of %%data%% padded on the **left** + * to %%length%% bytes. + * + * If %%data%% already exceeds %%length%%, a [[BufferOverrunError]] is + * thrown. + * + * This pads data the same as **values** are in Solidity + * (e.g. ``uint128``). + */ +export function zeroPadValue(data, length) { + return zeroPad(data, length, true); +} +/** + * Return the [[DataHexString]] of %%data%% padded on the **right** + * to %%length%% bytes. + * + * If %%data%% already exceeds %%length%%, a [[BufferOverrunError]] is + * thrown. + * + * This pads data the same as **bytes** are in Solidity + * (e.g. ``bytes16``). + */ +export function zeroPadBytes(data, length) { + return zeroPad(data, length, false); +} +//# sourceMappingURL=data.js.map \ No newline at end of file diff --git a/lib.esm/utils/data.js.map b/lib.esm/utils/data.js.map new file mode 100644 index 00000000..03821099 --- /dev/null +++ b/lib.esm/utils/data.js.map @@ -0,0 +1 @@ +{"version":3,"file":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,CAAC,IAAI,CAAC,EAAE;QAAE,KAAK,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;KAAE;IAC9D,OAAO,IAAI,GAAG,KAAK,CAAC;AACxB,CAAC;AAED,SAAS,OAAO,CAAC,IAAe,EAAE,MAAc,EAAE,IAAa;IAC3D,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC7B,MAAM,CAAC,MAAM,IAAI,KAAK,CAAC,MAAM,EAAE,6BAA6B,EAAE,gBAAgB,EAAE;QAC5E,MAAM,EAAE,IAAI,UAAU,CAAC,KAAK,CAAC;QAC7B,MAAM,EAAE,MAAM;QACd,MAAM,EAAE,MAAM,GAAG,CAAC;KACrB,CAAC,CAAC;IAEH,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;IACtC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACf,IAAI,IAAI,EAAE;QACN,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;KAC5C;SAAM;QACH,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;KACxB;IAED,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;AAC3B,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,YAAY,CAAC,IAAe,EAAE,MAAc;IACxD,OAAO,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;AACvC,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,YAAY,CAAC,IAAe,EAAE,MAAc;IACxD,OAAO,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;AACxC,CAAC"} \ No newline at end of file diff --git a/lib.esm/utils/errors.d.ts b/lib.esm/utils/errors.d.ts new file mode 100644 index 00000000..e03735a9 --- /dev/null +++ b/lib.esm/utils/errors.d.ts @@ -0,0 +1,485 @@ +/** + * All errors in quais include properties to ensure they are both + * human-readable (i.e. ``.message``) and machine-readable (i.e. ``.code``). + * + * The [[isError]] function can be used to check the error ``code`` and + * provide a type guard for the properties present on that error interface. + * + * @_section: api/utils/errors:Errors [about-errors] + */ +import type { TransactionRequest, TransactionReceipt, TransactionResponse } from "../providers/index.js"; +import type { FetchRequest, FetchResponse } from "./fetch.js"; +/** + * An error may contain additional properties, but those must not + * conflict with any implicit properties. + */ +export type ErrorInfo = Omit & { + shortMessage?: string; +}; +/** + * All errors emitted by quais have an **ErrorCode** to help + * identify and coalesce errors to simplify programmatic analysis. + * + * Each **ErrorCode** is the %%code%% proerty of a coresponding + * [[quaisError]]. + * + * **Generic Errors** + * + * **``"UNKNOWN_ERROR"``** - see [[UnknownError]] + * + * **``"NOT_IMPLEMENTED"``** - see [[NotImplementedError]] + * + * **``"UNSUPPORTED_OPERATION"``** - see [[UnsupportedOperationError]] + * + * **``"NETWORK_ERROR"``** - see [[NetworkError]] + * + * **``"SERVER_ERROR"``** - see [[ServerError]] + * + * **``"TIMEOUT"``** - see [[TimeoutError]] + * + * **``"BAD_DATA"``** - see [[BadDataError]] + * + * **``"CANCELLED"``** - see [[CancelledError]] + * + * **Operational Errors** + * + * **``"BUFFER_OVERRUN"``** - see [[BufferOverrunError]] + * + * **``"NUMERIC_FAULT"``** - see [[NumericFaultError]] + * + * **Argument Errors** + * + * **``"INVALID_ARGUMENT"``** - see [[InvalidArgumentError]] + * + * **``"MISSING_ARGUMENT"``** - see [[MissingArgumentError]] + * + * **``"UNEXPECTED_ARGUMENT"``** - see [[UnexpectedArgumentError]] + * + * **``"VALUE_MISMATCH"``** - //unused// + * + * **Blockchain Errors** + * + * **``"CALL_EXCEPTION"``** - see [[CallExceptionError]] + * + * **``"INSUFFICIENT_FUNDS"``** - see [[InsufficientFundsError]] + * + * **``"NONCE_EXPIRED"``** - see [[NonceExpiredError]] + * + * **``"REPLACEMENT_UNDERPRICED"``** - see [[ReplacementUnderpricedError]] + * + * **``"TRANSACTION_REPLACED"``** - see [[TransactionReplacedError]] + * + * **``"UNCONFIGURED_NAME"``** - see [[UnconfiguredNameError]] + * + * **``"OFFCHAIN_FAULT"``** - see [[OffchainFaultError]] + * + * **User Interaction Errors** + * + * **``"ACTION_REJECTED"``** - see [[ActionRejectedError]] + */ +export type ErrorCode = "UNKNOWN_ERROR" | "NOT_IMPLEMENTED" | "UNSUPPORTED_OPERATION" | "NETWORK_ERROR" | "SERVER_ERROR" | "TIMEOUT" | "BAD_DATA" | "CANCELLED" | "BUFFER_OVERRUN" | "NUMERIC_FAULT" | "INVALID_ARGUMENT" | "MISSING_ARGUMENT" | "UNEXPECTED_ARGUMENT" | "VALUE_MISMATCH" | "CALL_EXCEPTION" | "INSUFFICIENT_FUNDS" | "NONCE_EXPIRED" | "REPLACEMENT_UNDERPRICED" | "TRANSACTION_REPLACED" | "UNCONFIGURED_NAME" | "OFFCHAIN_FAULT" | "ACTION_REJECTED"; +/** + * All errors in quais include properties to assist in + * machine-readable errors. + */ +export interface quaisError extends Error { + /** + * The string error code. + */ + code: ErrorCode; + /** + * A short message describing the error, with minimal additional + * details. + */ + shortMessage: string; + /** + * Additional info regarding the error that may be useful. + * + * This is generally helpful mostly for human-based debugging. + */ + info?: Record; + /** + * Any related error. + */ + error?: Error; +} +/** + * This Error is a catch-all for when there is no way for quais to + * know what the underlying problem is. + */ +export interface UnknownError extends quaisError<"UNKNOWN_ERROR"> { + [key: string]: any; +} +/** + * This Error is mostly used as a stub for functionality that is + * intended for the future, but is currently not implemented. + */ +export interface NotImplementedError extends quaisError<"NOT_IMPLEMENTED"> { + /** + * The attempted operation. + */ + operation: string; +} +/** + * This Error indicates that the attempted operation is not supported. + * + * This could range from a specific JSON-RPC end-point not supporting + * a feature to a specific configuration of an object prohibiting the + * operation. + * + * For example, a [[Wallet]] with no connected [[Provider]] is unable + * to send a transaction. + */ +export interface UnsupportedOperationError extends quaisError<"UNSUPPORTED_OPERATION"> { + /** + * The attempted operation. + */ + operation: string; +} +/** + * This Error indicates a problem connecting to a network. + */ +export interface NetworkError extends quaisError<"NETWORK_ERROR"> { + /** + * The network event. + */ + event: string; +} +/** + * This Error indicates there was a problem fetching a resource from + * a server. + */ +export interface ServerError extends quaisError<"SERVER_ERROR"> { + /** + * The requested resource. + */ + request: FetchRequest | string; + /** + * The response received from the server, if available. + */ + response?: FetchResponse; +} +/** + * This Error indicates that the timeout duration has expired and + * that the operation has been implicitly cancelled. + * + * The side-effect of the operation may still occur, as this + * generally means a request has been sent and there has simply + * been no response to indicate whether it was processed or not. + */ +export interface TimeoutError extends quaisError<"TIMEOUT"> { + /** + * The attempted operation. + */ + operation: string; + /** + * The reason. + */ + reason: string; + /** + * The resource request, if available. + */ + request?: FetchRequest; +} +/** + * This Error indicates that a provided set of data cannot + * be correctly interpreted. + */ +export interface BadDataError extends quaisError<"BAD_DATA"> { + /** + * The data. + */ + value: any; +} +/** + * This Error indicates that the operation was cancelled by a + * programmatic call, for example to ``cancel()``. + */ +export interface CancelledError extends quaisError<"CANCELLED"> { +} +/** + * This Error indicates an attempt was made to read outside the bounds + * of protected data. + * + * Most operations in quais are protected by bounds checks, to mitigate + * exploits when parsing data. + */ +export interface BufferOverrunError extends quaisError<"BUFFER_OVERRUN"> { + /** + * The buffer that was overrun. + */ + buffer: Uint8Array; + /** + * The length of the buffer. + */ + length: number; + /** + * The offset that was requested. + */ + offset: number; +} +/** + * This Error indicates an operation which would result in incorrect + * arithmetic output has occurred. + * + * For example, trying to divide by zero or using a ``uint8`` to store + * a negative value. + */ +export interface NumericFaultError extends quaisError<"NUMERIC_FAULT"> { + /** + * The attempted operation. + */ + operation: string; + /** + * The fault reported. + */ + fault: string; + /** + * The value the operation was attempted against. + */ + value: any; +} +/** + * This Error indicates an incorrect type or value was passed to + * a function or method. + */ +export interface InvalidArgumentError extends quaisError<"INVALID_ARGUMENT"> { + /** + * The name of the argument. + */ + argument: string; + /** + * The value that was provided. + */ + value: any; + info?: Record; +} +/** + * This Error indicates there were too few arguments were provided. + */ +export interface MissingArgumentError extends quaisError<"MISSING_ARGUMENT"> { + /** + * The number of arguments received. + */ + count: number; + /** + * The number of arguments expected. + */ + expectedCount: number; +} +/** + * This Error indicates too many arguments were provided. + */ +export interface UnexpectedArgumentError extends quaisError<"UNEXPECTED_ARGUMENT"> { + /** + * The number of arguments received. + */ + count: number; + /** + * The number of arguments expected. + */ + expectedCount: number; +} +/** + * The action that resulted in the call exception. + */ +export type CallExceptionAction = "call" | "estimateGas" | "getTransactionResult" | "sendTransaction" | "unknown"; +/** + * The related transaction that caused the error. + */ +export type CallExceptionTransaction = { + to: null | string; + from?: string; + data: string; +}; +/** + * This **Error** indicates a transaction reverted. + */ +export interface CallExceptionError extends quaisError<"CALL_EXCEPTION"> { + /** + * The action being performed when the revert was encountered. + */ + action: CallExceptionAction; + /** + * The revert data returned. + */ + data: null | string; + /** + * A human-readable representation of data, if possible. + */ + reason: null | string; + /** + * The transaction that triggered the exception. + */ + transaction: CallExceptionTransaction; + /** + * The contract invocation details, if available. + */ + invocation: null | { + method: string; + signature: string; + args: Array; + }; + /** + * The built-in or custom revert error, if available + */ + revert: null | { + signature: string; + name: string; + args: Array; + }; + /** + * If the error occurred in a transaction that was mined + * (with a status of ``0``), this is the receipt. + */ + receipt?: TransactionReceipt; +} +/** + * The sending account has insufficient funds to cover the + * entire transaction cost. + */ +export interface InsufficientFundsError extends quaisError<"INSUFFICIENT_FUNDS"> { + /** + * The transaction. + */ + transaction: TransactionRequest; +} +/** + * The sending account has already used this nonce in a + * transaction that has been included. + */ +export interface NonceExpiredError extends quaisError<"NONCE_EXPIRED"> { + /** + * The transaction. + */ + transaction: TransactionRequest; +} +/** + * An attempt was made to replace a transaction, but with an + * insufficient additional fee to afford evicting the old + * transaction from the memory pool. + */ +export interface ReplacementUnderpricedError extends quaisError<"REPLACEMENT_UNDERPRICED"> { + /** + * The transaction. + */ + transaction: TransactionRequest; +} +/** + * A pending transaction was replaced by another. + */ +export interface TransactionReplacedError extends quaisError<"TRANSACTION_REPLACED"> { + /** + * If the transaction was cancelled, such that the original + * effects of the transaction cannot be assured. + */ + cancelled: boolean; + /** + * The reason the transaction was replaced. + */ + reason: "repriced" | "cancelled" | "replaced"; + /** + * The hash of the replaced transaction. + */ + hash: string; + /** + * The transaction that replaced the transaction. + */ + replacement: TransactionResponse; + /** + * The receipt of the transaction that replace the transaction. + */ + receipt: TransactionReceipt; +} +/** + * This Error indicates a request was rejected by the user. + * + * In most clients (such as MetaMask), when an operation requires user + * authorization (such as ``signer.sendTransaction``), the client + * presents a dialog box to the user. If the user denies the request + * this error is thrown. + */ +export interface ActionRejectedError extends quaisError<"ACTION_REJECTED"> { + /** + * The requested action. + */ + action: "requestAccess" | "sendTransaction" | "signMessage" | "signTransaction" | "signTypedData" | "unknown"; + /** + * The reason the action was rejected. + * + * If there is already a pending request, some clients may indicate + * there is already a ``"pending"`` action. This prevents an app + * from spamming the user. + */ + reason: "expired" | "rejected" | "pending"; +} +/** + * A conditional type that transforms the [[ErrorCode]] T into + * its quaisError type. + * + * @flatworm-skip-docs + */ +export type CodedquaisError = T extends "UNKNOWN_ERROR" ? UnknownError : T extends "NOT_IMPLEMENTED" ? NotImplementedError : T extends "UNSUPPORTED_OPERATION" ? UnsupportedOperationError : T extends "NETWORK_ERROR" ? NetworkError : T extends "SERVER_ERROR" ? ServerError : T extends "TIMEOUT" ? TimeoutError : T extends "BAD_DATA" ? BadDataError : T extends "CANCELLED" ? CancelledError : T extends "BUFFER_OVERRUN" ? BufferOverrunError : T extends "NUMERIC_FAULT" ? NumericFaultError : T extends "INVALID_ARGUMENT" ? InvalidArgumentError : T extends "MISSING_ARGUMENT" ? MissingArgumentError : T extends "UNEXPECTED_ARGUMENT" ? UnexpectedArgumentError : T extends "CALL_EXCEPTION" ? CallExceptionError : T extends "INSUFFICIENT_FUNDS" ? InsufficientFundsError : T extends "NONCE_EXPIRED" ? NonceExpiredError : T extends "REPLACEMENT_UNDERPRICED" ? ReplacementUnderpricedError : T extends "TRANSACTION_REPLACED" ? TransactionReplacedError : T extends "ACTION_REJECTED" ? ActionRejectedError : never; +/** + * Returns true if the %%error%% matches an error thrown by quais + * that matches the error %%code%%. + * + * In TypeScript environments, this can be used to check that %%error%% + * matches an quaisError type, which means the expected properties will + * be set. + * + * @See [ErrorCodes](api:ErrorCode) + * @example + * try { + * // code.... + * } catch (e) { + * if (isError(e, "CALL_EXCEPTION")) { + * // The Type Guard has validated this object + * console.log(e.data); + * } + * } + */ +export declare function isError>(error: any, code: K): error is T; +/** + * Returns true if %%error%% is a [[CallExceptionError]. + */ +export declare function isCallException(error: any): error is CallExceptionError; +/** + * Returns a new Error configured to the format quais emits errors, with + * the %%message%%, [[api:ErrorCode]] %%code%% and additional properties + * for the corresponding quaisError. + * + * Each error in quais includes the version of quais, a + * machine-readable [[ErrorCode]], and depending on %%code%%, additional + * required properties. The error message will also include the %%message%%, + * quais version, %%code%% and all additional properties, serialized. + */ +export declare function makeError>(message: string, code: K, info?: ErrorInfo): T; +/** + * Throws an quaisError with %%message%%, %%code%% and additional error + * %%info%% when %%check%% is falsish.. + * + * @see [[api:makeError]] + */ +export declare function assert>(check: unknown, message: string, code: K, info?: ErrorInfo): asserts check; +/** + * A simple helper to simply ensuring provided arguments match expected + * constraints, throwing if not. + * + * In TypeScript environments, the %%check%% has been asserted true, so + * any further code does not need additional compile-time checks. + */ +export declare function assertArgument(check: unknown, message: string, name: string, value: unknown): asserts check; +export declare function assertArgumentCount(count: number, expectedCount: number, message?: string): void; +/** + * Throws if the normalization %%form%% is not supported. + */ +export declare function assertNormalize(form: string): void; +/** + * Many classes use file-scoped values to guard the constructor, + * making it effectively private. This facilitates that pattern + * by ensuring the %%givenGaurd%% matches the file-scoped %%guard%%, + * throwing if not, indicating the %%className%% if provided. + */ +export declare function assertPrivate(givenGuard: any, guard: any, className?: string): void; +//# sourceMappingURL=errors.d.ts.map \ No newline at end of file diff --git a/lib.esm/utils/errors.d.ts.map b/lib.esm/utils/errors.d.ts.map new file mode 100644 index 00000000..aeba8c7f --- /dev/null +++ b/lib.esm/utils/errors.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src.ts/utils/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH,OAAO,KAAK,EACR,kBAAkB,EAAE,kBAAkB,EAAE,mBAAmB,EAC9D,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE9D;;;GAGG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,cAAc,CAAC,GAAG;IAAE,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AA2C7G;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AACH,MAAM,MAAM,SAAS,GAGjB,eAAe,GAAG,iBAAiB,GAAG,uBAAuB,GAC7D,eAAe,GAAG,cAAc,GAAG,SAAS,GAAG,UAAU,GACzD,WAAW,GAGX,gBAAgB,GAAI,eAAe,GAGnC,kBAAkB,GAAG,kBAAkB,GAAG,qBAAqB,GAC/D,gBAAgB,GAGhB,gBAAgB,GAAG,oBAAoB,GAAG,eAAe,GACzD,yBAAyB,GAAG,sBAAsB,GAClD,mBAAmB,GAAG,gBAAgB,GAGtC,iBAAiB,CACpB;AAED;;;GAGG;AACH,MAAM,WAAW,UAAU,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS,CAAE,SAAQ,KAAK;IACtE;;OAEG;IACH,IAAI,EAAE,SAAS,CAAC;IAEhB;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAE3B;;OAEG;IACH,KAAK,CAAC,EAAE,KA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,KAAK,IAAI,CAAC,CAE1G;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,kBAAkB,CAEvE;AAED;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,SAAS,EAAE,CAAC,SAAS,eAAe,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAkD7H;AAED;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,CAAC,SAAS,SAAS,EAAE,CAAC,SAAS,eAAe,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,KAAK,CAEtJ;AAGD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,CAE3G;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAahG;AAuBD;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAIlD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,UAAU,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAYnF"} \ No newline at end of file diff --git a/lib.esm/utils/errors.js b/lib.esm/utils/errors.js new file mode 100644 index 00000000..6c60b749 --- /dev/null +++ b/lib.esm/utils/errors.js @@ -0,0 +1,224 @@ +/** + * All errors in quais include properties to ensure they are both + * human-readable (i.e. ``.message``) and machine-readable (i.e. ``.code``). + * + * The [[isError]] function can be used to check the error ``code`` and + * provide a type guard for the properties present on that error interface. + * + * @_section: api/utils/errors:Errors [about-errors] + */ +import { version } from "../_version.js"; +import { defineProperties } from "./properties.js"; +function stringify(value) { + if (value == null) { + return "null"; + } + if (Array.isArray(value)) { + return "[ " + (value.map(stringify)).join(", ") + " ]"; + } + if (value instanceof Uint8Array) { + const HEX = "0123456789abcdef"; + let result = "0x"; + for (let i = 0; i < value.length; i++) { + result += HEX[value[i] >> 4]; + result += HEX[value[i] & 0xf]; + } + return result; + } + if (typeof (value) === "object" && typeof (value.toJSON) === "function") { + return stringify(value.toJSON()); + } + switch (typeof (value)) { + case "boolean": + case "symbol": + return value.toString(); + case "bigint": + return BigInt(value).toString(); + case "number": + return (value).toString(); + case "string": + return JSON.stringify(value); + case "object": { + const keys = Object.keys(value); + keys.sort(); + return "{ " + keys.map((k) => `${stringify(k)}: ${stringify(value[k])}`).join(", ") + " }"; + } + } + return `[ COULD NOT SERIALIZE ]`; +} +/** + * Returns true if the %%error%% matches an error thrown by quais + * that matches the error %%code%%. + * + * In TypeScript environments, this can be used to check that %%error%% + * matches an quaisError type, which means the expected properties will + * be set. + * + * @See [ErrorCodes](api:ErrorCode) + * @example + * try { + * // code.... + * } catch (e) { + * if (isError(e, "CALL_EXCEPTION")) { + * // The Type Guard has validated this object + * console.log(e.data); + * } + * } + */ +export function isError(error, code) { + return (error && error.code === code); +} +/** + * Returns true if %%error%% is a [[CallExceptionError]. + */ +export function isCallException(error) { + return isError(error, "CALL_EXCEPTION"); +} +/** + * Returns a new Error configured to the format quais emits errors, with + * the %%message%%, [[api:ErrorCode]] %%code%% and additional properties + * for the corresponding quaisError. + * + * Each error in quais includes the version of quais, a + * machine-readable [[ErrorCode]], and depending on %%code%%, additional + * required properties. The error message will also include the %%message%%, + * quais version, %%code%% and all additional properties, serialized. + */ +export function makeError(message, code, info) { + let shortMessage = message; + { + const details = []; + if (info) { + if ("message" in info || "code" in info || "name" in info) { + throw new Error(`value will overwrite populated values: ${stringify(info)}`); + } + for (const key in info) { + if (key === "shortMessage") { + continue; + } + const value = (info[key]); + // try { + details.push(key + "=" + stringify(value)); + // } catch (error: any) { + // console.log("MMM", error.message); + // details.push(key + "=[could not serialize object]"); + // } + } + } + details.push(`code=${code}`); + details.push(`version=${version}`); + if (details.length) { + message += " (" + details.join(", ") + ")"; + } + } + let error; + switch (code) { + case "INVALID_ARGUMENT": + error = new TypeError(message); + break; + case "NUMERIC_FAULT": + case "BUFFER_OVERRUN": + error = new RangeError(message); + break; + default: + error = new Error(message); + } + defineProperties(error, { code }); + if (info) { + Object.assign(error, info); + } + if (error.shortMessage == null) { + defineProperties(error, { shortMessage }); + } + return error; +} +/** + * Throws an quaisError with %%message%%, %%code%% and additional error + * %%info%% when %%check%% is falsish.. + * + * @see [[api:makeError]] + */ +export function assert(check, message, code, info) { + if (!check) { + throw makeError(message, code, info); + } +} +/** + * A simple helper to simply ensuring provided arguments match expected + * constraints, throwing if not. + * + * In TypeScript environments, the %%check%% has been asserted true, so + * any further code does not need additional compile-time checks. + */ +export function assertArgument(check, message, name, value) { + assert(check, message, "INVALID_ARGUMENT", { argument: name, value: value }); +} +export function assertArgumentCount(count, expectedCount, message) { + if (message == null) { + message = ""; + } + if (message) { + message = ": " + message; + } + assert(count >= expectedCount, "missing arguemnt" + message, "MISSING_ARGUMENT", { + count: count, + expectedCount: expectedCount + }); + assert(count <= expectedCount, "too many arguemnts" + message, "UNEXPECTED_ARGUMENT", { + count: count, + expectedCount: expectedCount + }); +} +const _normalizeForms = ["NFD", "NFC", "NFKD", "NFKC"].reduce((accum, form) => { + try { + // General test for normalize + /* c8 ignore start */ + if ("test".normalize(form) !== "test") { + throw new Error("bad"); + } + ; + /* c8 ignore stop */ + if (form === "NFD") { + const check = String.fromCharCode(0xe9).normalize("NFD"); + const expected = String.fromCharCode(0x65, 0x0301); + /* c8 ignore start */ + if (check !== expected) { + throw new Error("broken"); + } + /* c8 ignore stop */ + } + accum.push(form); + } + catch (error) { } + return accum; +}, []); +/** + * Throws if the normalization %%form%% is not supported. + */ +export function assertNormalize(form) { + assert(_normalizeForms.indexOf(form) >= 0, "platform missing String.prototype.normalize", "UNSUPPORTED_OPERATION", { + operation: "String.prototype.normalize", info: { form } + }); +} +/** + * Many classes use file-scoped values to guard the constructor, + * making it effectively private. This facilitates that pattern + * by ensuring the %%givenGaurd%% matches the file-scoped %%guard%%, + * throwing if not, indicating the %%className%% if provided. + */ +export function assertPrivate(givenGuard, guard, className) { + if (className == null) { + className = ""; + } + if (givenGuard !== guard) { + let method = className, operation = "new"; + if (className) { + method += "."; + operation += " " + className; + } + assert(false, `private constructor; use ${method}from* methods`, "UNSUPPORTED_OPERATION", { + operation + }); + } +} +//# sourceMappingURL=errors.js.map \ No newline at end of file diff --git a/lib.esm/utils/errors.js.map b/lib.esm/utils/errors.js.map new file mode 100644 index 00000000..79da6d57 --- /dev/null +++ b/lib.esm/utils/errors.js.map @@ -0,0 +1 @@ +{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src.ts/utils/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAenD,SAAS,SAAS,CAAC,KAAU;IACzB,IAAI,KAAK,IAAI,IAAI,EAAE;QAAE,OAAO,MAAM,CAAC;KAAE;IAErC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QACtB,OAAO,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;KAC1D;IAED,IAAI,KAAK,YAAY,UAAU,EAAE;QAC7B,MAAM,GAAG,GAAG,kBAAkB,CAAC;QAC/B,IAAI,MAAM,GAAG,IAAI,CAAC;QACl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I,CAAC,IAAI,CAAC,EAAE,6CAA6C,EAAE,uBAAuB,EAAE;QAC/G,SAAS,EAAE,4BAA4B,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE;KAC1D,CAAC,CAAC;AACP,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,UAAe,EAAE,KAAU,EAAE,SAAkB;IACzE,IAAI,SAAS,IAAI,IAAI,EAAE;QAAE,SAAS,GAAG,EAAE,CAAC;KAAE;IAC1C,IAAI,UAAU,KAAK,KAAK,EAAE;QACtB,IAAI,MAAM,GAAG,SAAS,EAAE,SAAS,GAAG,KAAK,CAAC;QAC1C,IAAI,SAAS,EAAE;YACX,MAAM,IAAI,GAAG,CAAC;YACd,SAAS,IAAI,GAAG,GAAG,SAAS,CAAC;SAChC;QACD,MAAM,CAAC,KAAK,EAAE,4BAA6B,MAAO,eAAe,EAAE,uBAAuB,EAAE;YACxF,SAAS;SACZ,CAAC,CAAC;KACN;AACL,CAAC"} \ No newline at end of file diff --git a/lib.esm/utils/events.d.ts b/lib.esm/utils/events.d.ts new file mode 100644 index 00000000..5da08892 --- /dev/null +++ b/lib.esm/utils/events.d.ts @@ -0,0 +1,77 @@ +/** + * A callback function called when a an event is triggered. + */ +export type Listener = (...args: Array) => void; +/** + * An **EventEmitterable** behaves similar to an EventEmitter + * except provides async access to its methods. + * + * An EventEmitter implements the observer pattern. + */ +export interface EventEmitterable { + /** + * Registers a %%listener%% that is called whenever the + * %%event%% occurs until unregistered. + */ + on(event: T, listener: Listener): Promise; + /** + * Registers a %%listener%% that is called the next time + * %%event%% occurs. + */ + once(event: T, listener: Listener): Promise; + /** + * Triggers each listener for %%event%% with the %%args%%. + */ + emit(event: T, ...args: Array): Promise; + /** + * Resolves to the number of listeners for %%event%%. + */ + listenerCount(event?: T): Promise; + /** + * Resolves to the listeners for %%event%%. + */ + listeners(event?: T): Promise>; + /** + * Unregister the %%listener%% for %%event%%. If %%listener%% + * is unspecified, all listeners are unregistered. + */ + off(event: T, listener?: Listener): Promise; + /** + * Unregister all listeners for %%event%%. + */ + removeAllListeners(event?: T): Promise; + /** + * Alias for [[on]]. + */ + addListener(event: T, listener: Listener): Promise; + /** + * Alias for [[off]]. + */ + removeListener(event: T, listener: Listener): Promise; +} +/** + * When an [[EventEmitterable]] triggers a [[Listener]], the + * callback always ahas one additional argument passed, which is + * an **EventPayload**. + */ +export declare class EventPayload { + #private; + /** + * The event filter. + */ + readonly filter: T; + /** + * The **EventEmitterable**. + */ + readonly emitter: EventEmitterable; + /** + * Create a new **EventPayload** for %%emitter%% with + * the %%listener%% and for %%filter%%. + */ + constructor(emitter: EventEmitterable, listener: null | Listener, filter: T); + /** + * Unregister the triggered listener for future events. + */ + removeListener(): Promise; +} +//# sourceMappingURL=events.d.ts.map \ No newline at end of file diff --git a/lib.esm/utils/events.d.ts.map b/lib.esm/utils/events.d.ts.map new file mode 100644 index 00000000..645e81ff --- /dev/null +++ b/lib.esm/utils/events.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src.ts/utils/events.ts"],"names":[],"mappings":"AASA;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC;AAErD;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB,CAAC,CAAC;IAC/B;;;OAGG;IACH,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEhD;;;OAGG;IACH,IAAI,CAAC,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAElD;;OAEG;IACH,IAAI,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAEtD;;OAEG;IACH,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAE1C;;OAEG;IACH,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;IAE/C;;;OAGG;IACH,GAAG,CAAC,KAAK,EAAE,CAAC,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAElD;;OAEG;IACH,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE7C;;OAEG;IACH,WAAW,CAAC,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzD;;OAEG;IACH,cAAc,CAAC,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/D;AAED;;;;GAIG;AACH,qBAAa,YAAY,CAAC,CAAC;;IACvB;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAG,CAAC,CAAC;IAEpB;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAIvC;;;OAGG;gBACS,OAAO,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,GAAG,QAAQ,EAAE,MAAM,EAAE,CAAC;IAK9E;;OAEG;IACG,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;CAIxC"} \ No newline at end of file diff --git a/lib.esm/utils/events.js b/lib.esm/utils/events.js new file mode 100644 index 00000000..41ca7272 --- /dev/null +++ b/lib.esm/utils/events.js @@ -0,0 +1,42 @@ +/** + * Events allow for applications to use the observer pattern, which + * allows subscribing and publishing events, outside the normal + * execution paths. + * + * @_section api/utils/events:Events [about-events] + */ +import { defineProperties } from "./properties.js"; +/** + * When an [[EventEmitterable]] triggers a [[Listener]], the + * callback always ahas one additional argument passed, which is + * an **EventPayload**. + */ +export class EventPayload { + /** + * The event filter. + */ + filter; + /** + * The **EventEmitterable**. + */ + emitter; + #listener; + /** + * Create a new **EventPayload** for %%emitter%% with + * the %%listener%% and for %%filter%%. + */ + constructor(emitter, listener, filter) { + this.#listener = listener; + defineProperties(this, { emitter, filter }); + } + /** + * Unregister the triggered listener for future events. + */ + async removeListener() { + if (this.#listener == null) { + return; + } + await this.emitter.off(this.filter, this.#listener); + } +} +//# sourceMappingURL=events.js.map \ No newline at end of file diff --git a/lib.esm/utils/events.js.map b/lib.esm/utils/events.js.map new file mode 100644 index 00000000..fc78d150 --- /dev/null +++ b/lib.esm/utils/events.js.map @@ -0,0 +1 @@ +{"version":3,"file":"events.js","sourceRoot":"","sources":["../../src.ts/utils/events.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AA+DnD;;;;GAIG;AACH,MAAM,OAAO,YAAY;IACrB;;OAEG;IACM,MAAM,CAAK;IAEpB;;OAEG;IACM,OAAO,CAAuB;IAE9B,SAAS,CAAkB;IAEpC;;;OAGG;IACH,YAAY,OAA4B,EAAE,QAAyB,EAAE,MAAS;QAC1E,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,gBAAgB,CAAoB,IAAI,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;IACnE,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,cAAc;QAChB,IAAI,IAAI,CAAC,SAAS,IAAI,IAAI,EAAE;YAAE,OAAO;SAAE;QACvC,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IACxD,CAAC;CACJ"} \ No newline at end of file diff --git a/lib.esm/utils/fetch.d.ts b/lib.esm/utils/fetch.d.ts new file mode 100644 index 00000000..d1257928 --- /dev/null +++ b/lib.esm/utils/fetch.d.ts @@ -0,0 +1,363 @@ +/** + * An environment's implementation of ``getUrl`` must return this type. + */ +export type GetUrlResponse = { + statusCode: number; + statusMessage: string; + headers: Record; + body: null | Uint8Array; +}; +/** + * This can be used to control how throttling is handled in + * [[FetchRequest-setThrottleParams]]. + */ +export type FetchThrottleParams = { + maxAttempts?: number; + slotInterval?: number; +}; +/** + * Called before any network request, allowing updated headers (e.g. Bearer tokens), etc. + */ +export type FetchPreflightFunc = (req: FetchRequest) => Promise; +/** + * Called on the response, allowing client-based throttling logic or post-processing. + */ +export type FetchProcessFunc = (req: FetchRequest, resp: FetchResponse) => Promise; +/** + * Called prior to each retry; return true to retry, false to abort. + */ +export type FetchRetryFunc = (req: FetchRequest, resp: FetchResponse, attempt: number) => Promise; +/** + * Called on Gateway URLs. + */ +export type FetchGatewayFunc = (url: string, signal?: FetchCancelSignal) => Promise; +/** + * Used to perform a fetch; use this to override the underlying network + * fetch layer. In NodeJS, the default uses the "http" and "https" libraries + * and in the browser ``fetch`` is used. If you wish to use Axios, this is + * how you would register it. + */ +export type FetchGetUrlFunc = (req: FetchRequest, signal?: FetchCancelSignal) => Promise; +/** + * @_ignore + */ +export declare class FetchCancelSignal { + #private; + constructor(request: FetchRequest); + addListener(listener: () => void): void; + get cancelled(): boolean; + checkSignal(): void; +} +/** + * Represents a request for a resource using a URI. + * + * By default, the supported schemes are ``HTTP``, ``HTTPS``, ``data:``, + * and ``IPFS:``. + * + * Additional schemes can be added globally using [[registerGateway]]. + * + * @example: + * req = new FetchRequest("https://www.ricmoo.com") + * resp = await req.send() + * resp.body.length + * //_result: + */ +export declare class FetchRequest implements Iterable<[key: string, value: string]> { + #private; + /** + * The fetch URL to request. + */ + get url(): string; + set url(url: string); + /** + * The fetch body, if any, to send as the request body. //(default: null)// + * + * When setting a body, the intrinsic ``Content-Type`` is automatically + * set and will be used if **not overridden** by setting a custom + * header. + * + * If %%body%% is null, the body is cleared (along with the + * intrinsic ``Content-Type``). + * + * If %%body%% is a string, the intrinsic ``Content-Type`` is set to + * ``text/plain``. + * + * If %%body%% is a Uint8Array, the intrinsic ``Content-Type`` is set to + * ``application/octet-stream``. + * + * If %%body%% is any other object, the intrinsic ``Content-Type`` is + * set to ``application/json``. + */ + get body(): null | Uint8Array; + set body(body: null | string | Readonly | Readonly); + /** + * Returns true if the request has a body. + */ + hasBody(): this is (FetchRequest & { + body: Uint8Array; + }); + /** + * The HTTP method to use when requesting the URI. If no method + * has been explicitly set, then ``GET`` is used if the body is + * null and ``POST`` otherwise. + */ + get method(): string; + set method(method: null | string); + /** + * The headers that will be used when requesting the URI. All + * keys are lower-case. + * + * This object is a copy, so any changes will **NOT** be reflected + * in the ``FetchRequest``. + * + * To set a header entry, use the ``setHeader`` method. + */ + get headers(): Record; + /** + * Get the header for %%key%%, ignoring case. + */ + getHeader(key: string): string; + /** + * Set the header for %%key%% to %%value%%. All values are coerced + * to a string. + */ + setHeader(key: string, value: string | number): void; + /** + * Clear all headers, resetting all intrinsic headers. + */ + clearHeaders(): void; + [Symbol.iterator](): Iterator<[key: string, value: string]>; + /** + * The value that will be sent for the ``Authorization`` header. + * + * To set the credentials, use the ``setCredentials`` method. + */ + get credentials(): null | string; + /** + * Sets an ``Authorization`` for %%username%% with %%password%%. + */ + setCredentials(username: string, password: string): void; + /** + * Enable and request gzip-encoded responses. The response will + * automatically be decompressed. //(default: true)// + */ + get allowGzip(): boolean; + set allowGzip(value: boolean); + /** + * Allow ``Authentication`` credentials to be sent over insecure + * channels. //(default: false)// + */ + get allowInsecureAuthentication(): boolean; + set allowInsecureAuthentication(value: boolean); + /** + * The timeout (in milliseconds) to wait for a complete response. + * //(default: 5 minutes)// + */ + get timeout(): number; + set timeout(timeout: number); + /** + * This function is called prior to each request, for example + * during a redirection or retry in case of server throttling. + * + * This offers an opportunity to populate headers or update + * content before sending a request. + */ + get preflightFunc(): null | FetchPreflightFunc; + set preflightFunc(preflight: null | FetchPreflightFunc); + /** + * This function is called after each response, offering an + * opportunity to provide client-level throttling or updating + * response data. + * + * Any error thrown in this causes the ``send()`` to throw. + * + * To schedule a retry attempt (assuming the maximum retry limit + * has not been reached), use [[response.throwThrottleError]]. + */ + get processFunc(): null | FetchProcessFunc; + set processFunc(process: null | FetchProcessFunc); + /** + * This function is called on each retry attempt. + */ + get retryFunc(): null | FetchRetryFunc; + set retryFunc(retry: null | FetchRetryFunc); + /** + * This function is called to fetch content from HTTP and + * HTTPS URLs and is platform specific (e.g. nodejs vs + * browsers). + * + * This is by default the currently registered global getUrl + * function, which can be changed using [[registerGetUrl]]. + * If this has been set, setting is to ``null`` will cause + * this FetchRequest (and any future clones) to revert back to + * using the currently registered global getUrl function. + * + * Setting this is generally not necessary, but may be useful + * for developers that wish to intercept requests or to + * configurege a proxy or other agent. + */ + get getUrlFunc(): FetchGetUrlFunc; + set getUrlFunc(value: null | FetchGetUrlFunc); + /** + * Create a new FetchRequest instance with default values. + * + * Once created, each property may be set before issuing a + * ``.send()`` to make the request. + */ + constructor(url: string); + toString(): string; + /** + * Update the throttle parameters used to determine maximum + * attempts and exponential-backoff properties. + */ + setThrottleParams(params: FetchThrottleParams): void; + /** + * Resolves to the response by sending the request. + */ + send(): Promise; + /** + * Cancels the inflight response, causing a ``CANCELLED`` + * error to be rejected from the [[send]]. + */ + cancel(): void; + /** + * Returns a new [[FetchRequest]] that represents the redirection + * to %%location%%. + */ + redirect(location: string): FetchRequest; + /** + * Create a new copy of this request. + */ + clone(): FetchRequest; + /** + * Locks all static configuration for gateways and FetchGetUrlFunc + * registration. + */ + static lockConfig(): void; + /** + * Get the current Gateway function for %%scheme%%. + */ + static getGateway(scheme: string): null | FetchGatewayFunc; + /** + * Use the %%func%% when fetching URIs using %%scheme%%. + * + * This method affects all requests globally. + * + * If [[lockConfig]] has been called, no change is made and this + * throws. + */ + static registerGateway(scheme: string, func: FetchGatewayFunc): void; + /** + * Use %%getUrl%% when fetching URIs over HTTP and HTTPS requests. + * + * This method affects all requests globally. + * + * If [[lockConfig]] has been called, no change is made and this + * throws. + */ + static registerGetUrl(getUrl: FetchGetUrlFunc): void; + /** + * Creates a getUrl function that fetches content from HTTP and + * HTTPS URLs. + * + * The available %%options%% are dependent on the platform + * implementation of the default getUrl function. + * + * This is not generally something that is needed, but is useful + * when trying to customize simple behaviour when fetching HTTP + * content. + */ + static createGetUrlFunc(options?: Record): FetchGetUrlFunc; + /** + * Creates a function that can "fetch" data URIs. + * + * Note that this is automatically done internally to support + * data URIs, so it is not necessary to register it. + * + * This is not generally something that is needed, but may + * be useful in a wrapper to perfom custom data URI functionality. + */ + static createDataGateway(): FetchGatewayFunc; + /** + * Creates a function that will fetch IPFS (unvalidated) from + * a custom gateway baseUrl. + * + * The default IPFS gateway used internally is + * ``"https:/\/gateway.ipfs.io/ipfs/"``. + */ + static createIpfsGatewayFunc(baseUrl: string): FetchGatewayFunc; +} +/** + * The response for a FetchRequest. + */ +export declare class FetchResponse implements Iterable<[key: string, value: string]> { + #private; + toString(): string; + /** + * The response status code. + */ + get statusCode(): number; + /** + * The response status message. + */ + get statusMessage(): string; + /** + * The response headers. All keys are lower-case. + */ + get headers(): Record; + /** + * The response body, or ``null`` if there was no body. + */ + get body(): null | Readonly; + /** + * The response body as a UTF-8 encoded string, or the empty + * string (i.e. ``""``) if there was no body. + * + * An error is thrown if the body is invalid UTF-8 data. + */ + get bodyText(): string; + /** + * The response body, decoded as JSON. + * + * An error is thrown if the body is invalid JSON-encoded data + * or if there was no body. + */ + get bodyJson(): any; + [Symbol.iterator](): Iterator<[key: string, value: string]>; + constructor(statusCode: number, statusMessage: string, headers: Readonly>, body: null | Uint8Array, request?: FetchRequest); + /** + * Return a Response with matching headers and body, but with + * an error status code (i.e. 599) and %%message%% with an + * optional %%error%%. + */ + makeServerError(message?: string, error?: Error): FetchResponse; + /** + * If called within a [request.processFunc](FetchRequest-processFunc) + * call, causes the request to retry as if throttled for %%stall%% + * milliseconds. + */ + throwThrottleError(message?: string, stall?: number): never; + /** + * Get the header value for %%key%%, ignoring case. + */ + getHeader(key: string): string; + /** + * Returns true if the response has a body. + */ + hasBody(): this is (FetchResponse & { + body: Uint8Array; + }); + /** + * The request made for this response. + */ + get request(): null | FetchRequest; + /** + * Returns true if this response was a success statusCode. + */ + ok(): boolean; + /** + * Throws a ``SERVER_ERROR`` if this response is not ok. + */ + assertOk(): void; +} +//# sourceMappingURL=fetch.d.ts.map \ No newline at end of file diff --git a/lib.esm/utils/fetch.d.ts.map b/lib.esm/utils/fetch.d.ts.map new file mode 100644 index 00000000..6cdba28f --- /dev/null +++ b/lib.esm/utils/fetch.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src.ts/utils/fetch.ts"],"names":[],"mappings":"AA2BA;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,IAAI,EAAE,IAAI,GAAG,UAAU,CAAA;CAC1B,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,GAAG,EAAE,YAAY,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;AAE9E;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,aAAa,KAAK,OAAO,CAAC,aAAa,CAAC,CAAC;AAElG;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAE3G;;GAEG;AACH,MAAM,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IAEnF;;OAEG;IACH,IAAI,IAAI,IAAI,IAAI,GAAG,QAAQ,CAAC,UAAU,CAAC,CAEtC;IAED;;;;;OAKG;IACH,IAAI,QAAQ,IAAI,MAAM,CAQrB;IAED;;;;;OAKG;IACH,IAAI,QAAQ,IAAI,GAAG,CAQlB;IAED,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,CAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAE,CAAC;gBAiBjD,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,GAAG,UAAU,EAAE,OAAO,CAAC,EAAE,YAAY;IAajJ;;;;OAIG;IACH,eAAe,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,GAAG,aAAa;IAc/D;;;;OAIG;IACH,kBAAkB,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK;IAc3D;;OAEG;IACH,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAI9B;;OAEG;IACH,OAAO,IAAI,IAAI,IAAI,CAAC,aAAa,GAAG;QAAE,IAAI,EAAE,UAAU,CAAA;KAAE,CAAC;IAIzD;;OAEG;IACH,IAAI,OAAO,IAAI,IAAI,GAAG,YAAY,CAA0B;IAE5D;;OAEG;IACH,EAAE,IAAI,OAAO;IAIb;;OAEG;IACH,QAAQ,IAAI,IAAI;CAUnB"} \ No newline at end of file diff --git a/lib.esm/utils/fetch.js b/lib.esm/utils/fetch.js new file mode 100644 index 00000000..d558d15c --- /dev/null +++ b/lib.esm/utils/fetch.js @@ -0,0 +1,836 @@ +/** + * Fetching content from the web is environment-specific, so quais + * provides an abstraction that each environment can implement to provide + * this service. + * + * On [Node.js](link-node), the ``http`` and ``https`` libs are used to + * create a request object, register event listeners and process data + * and populate the [[FetchResponse]]. + * + * In a browser, the [DOM fetch](link-js-fetch) is used, and the resulting + * ``Promise`` is waited on to retrieve the payload. + * + * The [[FetchRequest]] is responsible for handling many common situations, + * such as redirects, server throttling, authentication, etc. + * + * It also handles common gateways, such as IPFS and data URIs. + * + * @_section api/utils/fetching:Fetching Web Content [about-fetch] + */ +import { decodeBase64, encodeBase64 } from "./base64.js"; +import { hexlify } from "./data.js"; +import { assert, assertArgument } from "./errors.js"; +import { defineProperties } from "./properties.js"; +import { toUtf8Bytes, toUtf8String } from "./utf8.js"; +import { createGetUrl } from "./geturl.js"; +const MAX_ATTEMPTS = 12; +const SLOT_INTERVAL = 250; +// The global FetchGetUrlFunc implementation. +let defaultGetUrlFunc = createGetUrl(); +const reData = new RegExp("^data:([^;:]*)?(;base64)?,(.*)$", "i"); +const reIpfs = new RegExp("^ipfs:/\/(ipfs/)?(.*)$", "i"); +// If locked, new Gateways cannot be added +let locked = false; +// https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs +async function dataGatewayFunc(url, signal) { + try { + const match = url.match(reData); + if (!match) { + throw new Error("invalid data"); + } + return new FetchResponse(200, "OK", { + "content-type": (match[1] || "text/plain"), + }, (match[2] ? decodeBase64(match[3]) : unpercent(match[3]))); + } + catch (error) { + return new FetchResponse(599, "BAD REQUEST (invalid data: URI)", {}, null, new FetchRequest(url)); + } +} +/** + * Returns a [[FetchGatewayFunc]] for fetching content from a standard + * IPFS gateway hosted at %%baseUrl%%. + */ +function getIpfsGatewayFunc(baseUrl) { + async function gatewayIpfs(url, signal) { + try { + const match = url.match(reIpfs); + if (!match) { + throw new Error("invalid link"); + } + return new FetchRequest(`${baseUrl}${match[2]}`); + } + catch (error) { + return new FetchResponse(599, "BAD REQUEST (invalid IPFS URI)", {}, null, new FetchRequest(url)); + } + } + return gatewayIpfs; +} +const Gateways = { + "data": dataGatewayFunc, + "ipfs": getIpfsGatewayFunc("https:/\/gateway.ipfs.io/ipfs/") +}; +const fetchSignals = new WeakMap(); +/** + * @_ignore + */ +export class FetchCancelSignal { + #listeners; + #cancelled; + constructor(request) { + this.#listeners = []; + this.#cancelled = false; + fetchSignals.set(request, () => { + if (this.#cancelled) { + return; + } + this.#cancelled = true; + for (const listener of this.#listeners) { + setTimeout(() => { listener(); }, 0); + } + this.#listeners = []; + }); + } + addListener(listener) { + assert(!this.#cancelled, "singal already cancelled", "UNSUPPORTED_OPERATION", { + operation: "fetchCancelSignal.addCancelListener" + }); + this.#listeners.push(listener); + } + get cancelled() { return this.#cancelled; } + checkSignal() { + assert(!this.cancelled, "cancelled", "CANCELLED", {}); + } +} +// Check the signal, throwing if it is cancelled +function checkSignal(signal) { + if (signal == null) { + throw new Error("missing signal; should not happen"); + } + signal.checkSignal(); + return signal; +} +/** + * Represents a request for a resource using a URI. + * + * By default, the supported schemes are ``HTTP``, ``HTTPS``, ``data:``, + * and ``IPFS:``. + * + * Additional schemes can be added globally using [[registerGateway]]. + * + * @example: + * req = new FetchRequest("https://www.ricmoo.com") + * resp = await req.send() + * resp.body.length + * //_result: + */ +export class FetchRequest { + #allowInsecure; + #gzip; + #headers; + #method; + #timeout; + #url; + #body; + #bodyType; + #creds; + // Hooks + #preflight; + #process; + #retry; + #signal; + #throttle; + #getUrlFunc; + /** + * The fetch URL to request. + */ + get url() { return this.#url; } + set url(url) { + this.#url = String(url); + } + /** + * The fetch body, if any, to send as the request body. //(default: null)// + * + * When setting a body, the intrinsic ``Content-Type`` is automatically + * set and will be used if **not overridden** by setting a custom + * header. + * + * If %%body%% is null, the body is cleared (along with the + * intrinsic ``Content-Type``). + * + * If %%body%% is a string, the intrinsic ``Content-Type`` is set to + * ``text/plain``. + * + * If %%body%% is a Uint8Array, the intrinsic ``Content-Type`` is set to + * ``application/octet-stream``. + * + * If %%body%% is any other object, the intrinsic ``Content-Type`` is + * set to ``application/json``. + */ + get body() { + if (this.#body == null) { + return null; + } + return new Uint8Array(this.#body); + } + set body(body) { + if (body == null) { + this.#body = undefined; + this.#bodyType = undefined; + } + else if (typeof (body) === "string") { + this.#body = toUtf8Bytes(body); + this.#bodyType = "text/plain"; + } + else if (body instanceof Uint8Array) { + this.#body = body; + this.#bodyType = "application/octet-stream"; + } + else if (typeof (body) === "object") { + this.#body = toUtf8Bytes(JSON.stringify(body)); + this.#bodyType = "application/json"; + } + else { + throw new Error("invalid body"); + } + } + /** + * Returns true if the request has a body. + */ + hasBody() { + return (this.#body != null); + } + /** + * The HTTP method to use when requesting the URI. If no method + * has been explicitly set, then ``GET`` is used if the body is + * null and ``POST`` otherwise. + */ + get method() { + if (this.#method) { + return this.#method; + } + if (this.hasBody()) { + return "POST"; + } + return "GET"; + } + set method(method) { + if (method == null) { + method = ""; + } + this.#method = String(method).toUpperCase(); + } + /** + * The headers that will be used when requesting the URI. All + * keys are lower-case. + * + * This object is a copy, so any changes will **NOT** be reflected + * in the ``FetchRequest``. + * + * To set a header entry, use the ``setHeader`` method. + */ + get headers() { + const headers = Object.assign({}, this.#headers); + if (this.#creds) { + headers["authorization"] = `Basic ${encodeBase64(toUtf8Bytes(this.#creds))}`; + } + ; + if (this.allowGzip) { + headers["accept-encoding"] = "gzip"; + } + if (headers["content-type"] == null && this.#bodyType) { + headers["content-type"] = this.#bodyType; + } + if (this.body) { + headers["content-length"] = String(this.body.length); + } + return headers; + } + /** + * Get the header for %%key%%, ignoring case. + */ + getHeader(key) { + return this.headers[key.toLowerCase()]; + } + /** + * Set the header for %%key%% to %%value%%. All values are coerced + * to a string. + */ + setHeader(key, value) { + this.#headers[String(key).toLowerCase()] = String(value); + } + /** + * Clear all headers, resetting all intrinsic headers. + */ + clearHeaders() { + this.#headers = {}; + } + [Symbol.iterator]() { + const headers = this.headers; + const keys = Object.keys(headers); + let index = 0; + return { + next: () => { + if (index < keys.length) { + const key = keys[index++]; + return { + value: [key, headers[key]], done: false + }; + } + return { value: undefined, done: true }; + } + }; + } + /** + * The value that will be sent for the ``Authorization`` header. + * + * To set the credentials, use the ``setCredentials`` method. + */ + get credentials() { + return this.#creds || null; + } + /** + * Sets an ``Authorization`` for %%username%% with %%password%%. + */ + setCredentials(username, password) { + assertArgument(!username.match(/:/), "invalid basic authentication username", "username", "[REDACTED]"); + this.#creds = `${username}:${password}`; + } + /** + * Enable and request gzip-encoded responses. The response will + * automatically be decompressed. //(default: true)// + */ + get allowGzip() { + return this.#gzip; + } + set allowGzip(value) { + this.#gzip = !!value; + } + /** + * Allow ``Authentication`` credentials to be sent over insecure + * channels. //(default: false)// + */ + get allowInsecureAuthentication() { + return !!this.#allowInsecure; + } + set allowInsecureAuthentication(value) { + this.#allowInsecure = !!value; + } + /** + * The timeout (in milliseconds) to wait for a complete response. + * //(default: 5 minutes)// + */ + get timeout() { return this.#timeout; } + set timeout(timeout) { + assertArgument(timeout >= 0, "timeout must be non-zero", "timeout", timeout); + this.#timeout = timeout; + } + /** + * This function is called prior to each request, for example + * during a redirection or retry in case of server throttling. + * + * This offers an opportunity to populate headers or update + * content before sending a request. + */ + get preflightFunc() { + return this.#preflight || null; + } + set preflightFunc(preflight) { + this.#preflight = preflight; + } + /** + * This function is called after each response, offering an + * opportunity to provide client-level throttling or updating + * response data. + * + * Any error thrown in this causes the ``send()`` to throw. + * + * To schedule a retry attempt (assuming the maximum retry limit + * has not been reached), use [[response.throwThrottleError]]. + */ + get processFunc() { + return this.#process || null; + } + set processFunc(process) { + this.#process = process; + } + /** + * This function is called on each retry attempt. + */ + get retryFunc() { + return this.#retry || null; + } + set retryFunc(retry) { + this.#retry = retry; + } + /** + * This function is called to fetch content from HTTP and + * HTTPS URLs and is platform specific (e.g. nodejs vs + * browsers). + * + * This is by default the currently registered global getUrl + * function, which can be changed using [[registerGetUrl]]. + * If this has been set, setting is to ``null`` will cause + * this FetchRequest (and any future clones) to revert back to + * using the currently registered global getUrl function. + * + * Setting this is generally not necessary, but may be useful + * for developers that wish to intercept requests or to + * configurege a proxy or other agent. + */ + get getUrlFunc() { + return this.#getUrlFunc || defaultGetUrlFunc; + } + set getUrlFunc(value) { + this.#getUrlFunc = value; + } + /** + * Create a new FetchRequest instance with default values. + * + * Once created, each property may be set before issuing a + * ``.send()`` to make the request. + */ + constructor(url) { + this.#url = String(url); + this.#allowInsecure = false; + this.#gzip = true; + this.#headers = {}; + this.#method = ""; + this.#timeout = 300000; + this.#throttle = { + slotInterval: SLOT_INTERVAL, + maxAttempts: MAX_ATTEMPTS + }; + this.#getUrlFunc = null; + } + toString() { + return ``; + } + /** + * Update the throttle parameters used to determine maximum + * attempts and exponential-backoff properties. + */ + setThrottleParams(params) { + if (params.slotInterval != null) { + this.#throttle.slotInterval = params.slotInterval; + } + if (params.maxAttempts != null) { + this.#throttle.maxAttempts = params.maxAttempts; + } + } + async #send(attempt, expires, delay, _request, _response) { + if (attempt >= this.#throttle.maxAttempts) { + return _response.makeServerError("exceeded maximum retry limit"); + } + assert(getTime() <= expires, "timeout", "TIMEOUT", { + operation: "request.send", reason: "timeout", request: _request + }); + if (delay > 0) { + await wait(delay); + } + let req = this.clone(); + const scheme = (req.url.split(":")[0] || "").toLowerCase(); + // Process any Gateways + if (scheme in Gateways) { + const result = await Gateways[scheme](req.url, checkSignal(_request.#signal)); + if (result instanceof FetchResponse) { + let response = result; + if (this.processFunc) { + checkSignal(_request.#signal); + try { + response = await this.processFunc(req, response); + } + catch (error) { + // Something went wrong during processing; throw a 5xx server error + if (error.throttle == null || typeof (error.stall) !== "number") { + response.makeServerError("error in post-processing function", error).assertOk(); + } + // Ignore throttling + } + } + return response; + } + req = result; + } + // We have a preflight function; update the request + if (this.preflightFunc) { + req = await this.preflightFunc(req); + } + const resp = await this.getUrlFunc(req, checkSignal(_request.#signal)); + let response = new FetchResponse(resp.statusCode, resp.statusMessage, resp.headers, resp.body, _request); + if (response.statusCode === 301 || response.statusCode === 302) { + // Redirect + try { + const location = response.headers.location || ""; + return req.redirect(location).#send(attempt + 1, expires, 0, _request, response); + } + catch (error) { } + // Things won't get any better on another attempt; abort + return response; + } + else if (response.statusCode === 429) { + // Throttle + if (this.retryFunc == null || (await this.retryFunc(req, response, attempt))) { + const retryAfter = response.headers["retry-after"]; + let delay = this.#throttle.slotInterval * Math.trunc(Math.random() * Math.pow(2, attempt)); + if (typeof (retryAfter) === "string" && retryAfter.match(/^[1-9][0-9]*$/)) { + delay = parseInt(retryAfter); + } + return req.clone().#send(attempt + 1, expires, delay, _request, response); + } + } + if (this.processFunc) { + checkSignal(_request.#signal); + try { + response = await this.processFunc(req, response); + } + catch (error) { + // Something went wrong during processing; throw a 5xx server error + if (error.throttle == null || typeof (error.stall) !== "number") { + response.makeServerError("error in post-processing function", error).assertOk(); + } + // Throttle + let delay = this.#throttle.slotInterval * Math.trunc(Math.random() * Math.pow(2, attempt)); + ; + if (error.stall >= 0) { + delay = error.stall; + } + return req.clone().#send(attempt + 1, expires, delay, _request, response); + } + } + return response; + } + /** + * Resolves to the response by sending the request. + */ + send() { + assert(this.#signal == null, "request already sent", "UNSUPPORTED_OPERATION", { operation: "fetchRequest.send" }); + this.#signal = new FetchCancelSignal(this); + return this.#send(0, getTime() + this.timeout, 0, this, new FetchResponse(0, "", {}, null, this)); + } + /** + * Cancels the inflight response, causing a ``CANCELLED`` + * error to be rejected from the [[send]]. + */ + cancel() { + assert(this.#signal != null, "request has not been sent", "UNSUPPORTED_OPERATION", { operation: "fetchRequest.cancel" }); + const signal = fetchSignals.get(this); + if (!signal) { + throw new Error("missing signal; should not happen"); + } + signal(); + } + /** + * Returns a new [[FetchRequest]] that represents the redirection + * to %%location%%. + */ + redirect(location) { + // Redirection; for now we only support absolute locations + const current = this.url.split(":")[0].toLowerCase(); + const target = location.split(":")[0].toLowerCase(); + // Don't allow redirecting: + // - non-GET requests + // - downgrading the security (e.g. https => http) + // - to non-HTTP (or non-HTTPS) protocols [this could be relaxed?] + assert(this.method === "GET" && (current !== "https" || target !== "http") && location.match(/^https?:/), `unsupported redirect`, "UNSUPPORTED_OPERATION", { + operation: `redirect(${this.method} ${JSON.stringify(this.url)} => ${JSON.stringify(location)})` + }); + // Create a copy of this request, with a new URL + const req = new FetchRequest(location); + req.method = "GET"; + req.allowGzip = this.allowGzip; + req.timeout = this.timeout; + req.#headers = Object.assign({}, this.#headers); + if (this.#body) { + req.#body = new Uint8Array(this.#body); + } + req.#bodyType = this.#bodyType; + // Do not forward credentials unless on the same domain; only absolute + //req.allowInsecure = false; + // paths are currently supported; may want a way to specify to forward? + //setStore(req.#props, "creds", getStore(this.#pros, "creds")); + return req; + } + /** + * Create a new copy of this request. + */ + clone() { + const clone = new FetchRequest(this.url); + // Preserve "default method" (i.e. null) + clone.#method = this.#method; + // Preserve "default body" with type, copying the Uint8Array is present + if (this.#body) { + clone.#body = this.#body; + } + clone.#bodyType = this.#bodyType; + // Preserve "default headers" + clone.#headers = Object.assign({}, this.#headers); + // Credentials is readonly, so we copy internally + clone.#creds = this.#creds; + if (this.allowGzip) { + clone.allowGzip = true; + } + clone.timeout = this.timeout; + if (this.allowInsecureAuthentication) { + clone.allowInsecureAuthentication = true; + } + clone.#preflight = this.#preflight; + clone.#process = this.#process; + clone.#retry = this.#retry; + clone.#getUrlFunc = this.#getUrlFunc; + return clone; + } + /** + * Locks all static configuration for gateways and FetchGetUrlFunc + * registration. + */ + static lockConfig() { + locked = true; + } + /** + * Get the current Gateway function for %%scheme%%. + */ + static getGateway(scheme) { + return Gateways[scheme.toLowerCase()] || null; + } + /** + * Use the %%func%% when fetching URIs using %%scheme%%. + * + * This method affects all requests globally. + * + * If [[lockConfig]] has been called, no change is made and this + * throws. + */ + static registerGateway(scheme, func) { + scheme = scheme.toLowerCase(); + if (scheme === "http" || scheme === "https") { + throw new Error(`cannot intercept ${scheme}; use registerGetUrl`); + } + if (locked) { + throw new Error("gateways locked"); + } + Gateways[scheme] = func; + } + /** + * Use %%getUrl%% when fetching URIs over HTTP and HTTPS requests. + * + * This method affects all requests globally. + * + * If [[lockConfig]] has been called, no change is made and this + * throws. + */ + static registerGetUrl(getUrl) { + if (locked) { + throw new Error("gateways locked"); + } + defaultGetUrlFunc = getUrl; + } + /** + * Creates a getUrl function that fetches content from HTTP and + * HTTPS URLs. + * + * The available %%options%% are dependent on the platform + * implementation of the default getUrl function. + * + * This is not generally something that is needed, but is useful + * when trying to customize simple behaviour when fetching HTTP + * content. + */ + static createGetUrlFunc(options) { + return createGetUrl(options); + } + /** + * Creates a function that can "fetch" data URIs. + * + * Note that this is automatically done internally to support + * data URIs, so it is not necessary to register it. + * + * This is not generally something that is needed, but may + * be useful in a wrapper to perfom custom data URI functionality. + */ + static createDataGateway() { + return dataGatewayFunc; + } + /** + * Creates a function that will fetch IPFS (unvalidated) from + * a custom gateway baseUrl. + * + * The default IPFS gateway used internally is + * ``"https:/\/gateway.ipfs.io/ipfs/"``. + */ + static createIpfsGatewayFunc(baseUrl) { + return getIpfsGatewayFunc(baseUrl); + } +} +; +/** + * The response for a FetchRequest. + */ +export class FetchResponse { + #statusCode; + #statusMessage; + #headers; + #body; + #request; + #error; + toString() { + return ``; + } + /** + * The response status code. + */ + get statusCode() { return this.#statusCode; } + /** + * The response status message. + */ + get statusMessage() { return this.#statusMessage; } + /** + * The response headers. All keys are lower-case. + */ + get headers() { return Object.assign({}, this.#headers); } + /** + * The response body, or ``null`` if there was no body. + */ + get body() { + return (this.#body == null) ? null : new Uint8Array(this.#body); + } + /** + * The response body as a UTF-8 encoded string, or the empty + * string (i.e. ``""``) if there was no body. + * + * An error is thrown if the body is invalid UTF-8 data. + */ + get bodyText() { + try { + return (this.#body == null) ? "" : toUtf8String(this.#body); + } + catch (error) { + assert(false, "response body is not valid UTF-8 data", "UNSUPPORTED_OPERATION", { + operation: "bodyText", info: { response: this } + }); + } + } + /** + * The response body, decoded as JSON. + * + * An error is thrown if the body is invalid JSON-encoded data + * or if there was no body. + */ + get bodyJson() { + try { + return JSON.parse(this.bodyText); + } + catch (error) { + assert(false, "response body is not valid JSON", "UNSUPPORTED_OPERATION", { + operation: "bodyJson", info: { response: this } + }); + } + } + [Symbol.iterator]() { + const headers = this.headers; + const keys = Object.keys(headers); + let index = 0; + return { + next: () => { + if (index < keys.length) { + const key = keys[index++]; + return { + value: [key, headers[key]], done: false + }; + } + return { value: undefined, done: true }; + } + }; + } + constructor(statusCode, statusMessage, headers, body, request) { + this.#statusCode = statusCode; + this.#statusMessage = statusMessage; + this.#headers = Object.keys(headers).reduce((accum, k) => { + accum[k.toLowerCase()] = String(headers[k]); + return accum; + }, {}); + this.#body = ((body == null) ? null : new Uint8Array(body)); + this.#request = (request || null); + this.#error = { message: "" }; + } + /** + * Return a Response with matching headers and body, but with + * an error status code (i.e. 599) and %%message%% with an + * optional %%error%%. + */ + makeServerError(message, error) { + let statusMessage; + if (!message) { + message = `${this.statusCode} ${this.statusMessage}`; + statusMessage = `CLIENT ESCALATED SERVER ERROR (${message})`; + } + else { + statusMessage = `CLIENT ESCALATED SERVER ERROR (${this.statusCode} ${this.statusMessage}; ${message})`; + } + const response = new FetchResponse(599, statusMessage, this.headers, this.body, this.#request || undefined); + response.#error = { message, error }; + return response; + } + /** + * If called within a [request.processFunc](FetchRequest-processFunc) + * call, causes the request to retry as if throttled for %%stall%% + * milliseconds. + */ + throwThrottleError(message, stall) { + if (stall == null) { + stall = -1; + } + else { + assertArgument(Number.isInteger(stall) && stall >= 0, "invalid stall timeout", "stall", stall); + } + const error = new Error(message || "throttling requests"); + defineProperties(error, { stall, throttle: true }); + throw error; + } + /** + * Get the header value for %%key%%, ignoring case. + */ + getHeader(key) { + return this.headers[key.toLowerCase()]; + } + /** + * Returns true if the response has a body. + */ + hasBody() { + return (this.#body != null); + } + /** + * The request made for this response. + */ + get request() { return this.#request; } + /** + * Returns true if this response was a success statusCode. + */ + ok() { + return (this.#error.message === "" && this.statusCode >= 200 && this.statusCode < 300); + } + /** + * Throws a ``SERVER_ERROR`` if this response is not ok. + */ + assertOk() { + if (this.ok()) { + return; + } + let { message, error } = this.#error; + if (message === "") { + message = `server response ${this.statusCode} ${this.statusMessage}`; + } + assert(false, message, "SERVER_ERROR", { + request: (this.request || "unknown request"), response: this, error + }); + } +} +function getTime() { return (new Date()).getTime(); } +function unpercent(value) { + return toUtf8Bytes(value.replace(/%([0-9a-f][0-9a-f])/gi, (all, code) => { + return String.fromCharCode(parseInt(code, 16)); + })); +} +function wait(delay) { + return new Promise((resolve) => setTimeout(resolve, delay)); +} +//# sourceMappingURL=fetch.js.map \ No newline at end of file diff --git a/lib.esm/utils/fetch.js.map b/lib.esm/utils/fetch.js.map new file mode 100644 index 00000000..57b3fa40 --- /dev/null +++ b/lib.esm/utils/fetch.js.map @@ -0,0 +1 @@ +{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../src.ts/utils/fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEtD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAkD3C,MAAM,YAAY,GAAG,EAAE,CAAC;AACxB,MAAM,aAAa,GAAG,GAAG,CAAC;AAE1B,6CAA6C;AAC7C,IAAI,iBAAiB,GAAoB,YAAY,EAAE,CAAC;AAExD,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,iCAAiC,EAAE,GAAG,CAAC,CAAC;AAClE,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,wBAAwB,EAAE,GAAG,CAAC,CAAC;AAEzD,0CAA0C;AAC1C,IAAI,MAAM,GAAG,KAAK,CAAC;AAEnB,6EAA6E;AAC7E,KAAK,UAAU,eAAe,CAAC,GAAW,EAAE,MAA0B;IAClE,IAAI;QACA,MAAM,KAAK,GAA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C,UAAU,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;AAChE,CAAC"} \ No newline at end of file diff --git a/lib.esm/utils/fixednumber.d.ts b/lib.esm/utils/fixednumber.d.ts new file mode 100644 index 00000000..901dd9b1 --- /dev/null +++ b/lib.esm/utils/fixednumber.d.ts @@ -0,0 +1,252 @@ +import type { BigNumberish, BytesLike, Numeric } from "./index.js"; +/** + * A description of a fixed-point arithmetic field. + * + * When specifying the fixed format, the values override the default of + * a ``fixed128x18``, which implies a signed 128-bit value with 18 + * decimals of precision. + * + * The alias ``fixed`` and ``ufixed`` can be used for ``fixed128x18`` and + * ``ufixed128x18`` respectively. + * + * When a fixed format string begins with a ``u``, it indicates the field + * is unsigned, so any negative values will overflow. The first number + * indicates the bit-width and the second number indicates the decimal + * precision. + * + * When a ``number`` is used for a fixed format, it indicates the number + * of decimal places, and the default width and signed-ness will be used. + * + * The bit-width must be byte aligned and the decimals can be at most 80. + */ +export type FixedFormat = number | string | { + signed?: boolean; + width?: number; + decimals?: number; +}; +/** + * A FixedNumber represents a value over its [[FixedFormat]] + * arithmetic field. + * + * A FixedNumber can be used to perform math, losslessly, on + * values which have decmial places. + * + * A FixedNumber has a fixed bit-width to store values in, and stores all + * values internally by multiplying the value by 10 raised to the power of + * %%decimals%%. + * + * If operations are performed that cause a value to grow too high (close to + * positive infinity) or too low (close to negative infinity), the value + * is said to //overflow//. + * + * For example, an 8-bit signed value, with 0 decimals may only be within + * the range ``-128`` to ``127``; so ``-128 - 1`` will overflow and become + * ``127``. Likewise, ``127 + 1`` will overflow and become ``-127``. + * + * Many operation have a normal and //unsafe// variant. The normal variant + * will throw a [[NumericFaultError]] on any overflow, while the //unsafe// + * variant will silently allow overflow, corrupting its value value. + * + * If operations are performed that cause a value to become too small + * (close to zero), the value loses precison and is said to //underflow//. + * + * For example, an value with 1 decimal place may store a number as small + * as ``0.1``, but the value of ``0.1 / 2`` is ``0.05``, which cannot fit + * into 1 decimal place, so underflow occurs which means precision is lost + * and the value becomes ``0``. + * + * Some operations have a normal and //signalling// variant. The normal + * variant will silently ignore underflow, while the //signalling// variant + * will thow a [[NumericFaultError]] on underflow. + */ +export declare class FixedNumber { + #private; + /** + * The specific fixed-point arithmetic field for this value. + */ + readonly format: string; + /** + * This is a property so console.log shows a human-meaningful value. + * + * @private + */ + readonly _value: string; + /** + * @private + */ + constructor(guard: any, value: bigint, format: any); + /** + * If true, negative values are permitted, otherwise only + * positive values and zero are allowed. + */ + get signed(): boolean; + /** + * The number of bits available to store the value. + */ + get width(): number; + /** + * The number of decimal places in the fixed-point arithment field. + */ + get decimals(): number; + /** + * The value as an integer, based on the smallest unit the + * [[decimals]] allow. + */ + get value(): bigint; + /** + * Returns a new [[FixedNumber]] with the result of %%this%% added + * to %%other%%, ignoring overflow. + */ + addUnsafe(other: FixedNumber): FixedNumber; + /** + * Returns a new [[FixedNumber]] with the result of %%this%% added + * to %%other%%. A [[NumericFaultError]] is thrown if overflow + * occurs. + */ + add(other: FixedNumber): FixedNumber; + /** + * Returns a new [[FixedNumber]] with the result of %%other%% subtracted + * from %%this%%, ignoring overflow. + */ + subUnsafe(other: FixedNumber): FixedNumber; + /** + * Returns a new [[FixedNumber]] with the result of %%other%% subtracted + * from %%this%%. A [[NumericFaultError]] is thrown if overflow + * occurs. + */ + sub(other: FixedNumber): FixedNumber; + /** + * Returns a new [[FixedNumber]] with the result of %%this%% multiplied + * by %%other%%, ignoring overflow and underflow (precision loss). + */ + mulUnsafe(other: FixedNumber): FixedNumber; + /** + * Returns a new [[FixedNumber]] with the result of %%this%% multiplied + * by %%other%%. A [[NumericFaultError]] is thrown if overflow + * occurs. + */ + mul(other: FixedNumber): FixedNumber; + /** + * Returns a new [[FixedNumber]] with the result of %%this%% multiplied + * by %%other%%. A [[NumericFaultError]] is thrown if overflow + * occurs or if underflow (precision loss) occurs. + */ + mulSignal(other: FixedNumber): FixedNumber; + /** + * Returns a new [[FixedNumber]] with the result of %%this%% divided + * by %%other%%, ignoring underflow (precision loss). A + * [[NumericFaultError]] is thrown if overflow occurs. + */ + divUnsafe(other: FixedNumber): FixedNumber; + /** + * Returns a new [[FixedNumber]] with the result of %%this%% divided + * by %%other%%, ignoring underflow (precision loss). A + * [[NumericFaultError]] is thrown if overflow occurs. + */ + div(other: FixedNumber): FixedNumber; + /** + * Returns a new [[FixedNumber]] with the result of %%this%% divided + * by %%other%%. A [[NumericFaultError]] is thrown if underflow + * (precision loss) occurs. + */ + divSignal(other: FixedNumber): FixedNumber; + /** + * Returns a comparison result between %%this%% and %%other%%. + * + * This is suitable for use in sorting, where ``-1`` implies %%this%% + * is smaller, ``1`` implies %%this%% is larger and ``0`` implies + * both are equal. + */ + cmp(other: FixedNumber): number; + /** + * Returns true if %%other%% is equal to %%this%%. + */ + eq(other: FixedNumber): boolean; + /** + * Returns true if %%other%% is less than to %%this%%. + */ + lt(other: FixedNumber): boolean; + /** + * Returns true if %%other%% is less than or equal to %%this%%. + */ + lte(other: FixedNumber): boolean; + /** + * Returns true if %%other%% is greater than to %%this%%. + */ + gt(other: FixedNumber): boolean; + /** + * Returns true if %%other%% is greater than or equal to %%this%%. + */ + gte(other: FixedNumber): boolean; + /** + * Returns a new [[FixedNumber]] which is the largest **integer** + * that is less than or equal to %%this%%. + * + * The decimal component of the result will always be ``0``. + */ + floor(): FixedNumber; + /** + * Returns a new [[FixedNumber]] which is the smallest **integer** + * that is greater than or equal to %%this%%. + * + * The decimal component of the result will always be ``0``. + */ + ceiling(): FixedNumber; + /** + * Returns a new [[FixedNumber]] with the decimal component + * rounded up on ties at %%decimals%% places. + */ + round(decimals?: number): FixedNumber; + /** + * Returns true if %%this%% is equal to ``0``. + */ + isZero(): boolean; + /** + * Returns true if %%this%% is less than ``0``. + */ + isNegative(): boolean; + /** + * Returns the string representation of %%this%%. + */ + toString(): string; + /** + * Returns a float approximation. + * + * Due to IEEE 754 precission (or lack thereof), this function + * can only return an approximation and most values will contain + * rounding errors. + */ + toUnsafeFloat(): number; + /** + * Return a new [[FixedNumber]] with the same value but has had + * its field set to %%format%%. + * + * This will throw if the value cannot fit into %%format%%. + */ + toFormat(format: FixedFormat): FixedNumber; + /** + * Creates a new [[FixedNumber]] for %%value%% divided by + * %%decimal%% places with %%format%%. + * + * This will throw a [[NumericFaultError]] if %%value%% (once adjusted + * for %%decimals%%) cannot fit in %%format%%, either due to overflow + * or underflow (precision loss). + */ + static fromValue(_value: BigNumberish, _decimals?: Numeric, _format?: FixedFormat): FixedNumber; + /** + * Creates a new [[FixedNumber]] for %%value%% with %%format%%. + * + * This will throw a [[NumericFaultError]] if %%value%% cannot fit + * in %%format%%, either due to overflow or underflow (precision loss). + */ + static fromString(_value: string, _format?: FixedFormat): FixedNumber; + /** + * Creates a new [[FixedNumber]] with the big-endian representation + * %%value%% with %%format%%. + * + * This will throw a [[NumericFaultError]] if %%value%% cannot fit + * in %%format%% due to overflow. + */ + static fromBytes(_value: BytesLike, _format?: FixedFormat): FixedNumber; +} +//# sourceMappingURL=fixednumber.d.ts.map \ No newline at end of file diff --git a/lib.esm/utils/fixednumber.d.ts.map b/lib.esm/utils/fixednumber.d.ts.map new file mode 100644 index 00000000..b34cc64f --- /dev/null +++ b/lib.esm/utils/fixednumber.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"fixednumber.d.ts","sourceRoot":"","sources":["../../src.ts/utils/fixednumber.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AA2CnE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG;IACxC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAA;CACpB,CAAC;AAwGF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,qBAAa,WAAW;;IAEpB;;OAEG;IAC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GAAG,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO;IAEjC;;OAEG;IACF,EAAE,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO;IAEhC;;OAEG;IACF,GAAG,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO;IAEjC;;;;;OAKG;IACH,KAAK,IAAI,WAAW;IAOpB;;;;;OAKG;IACH,OAAO,IAAI,WAAW;IAOtB;;;OAGG;IACH,KAAK,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,WAAW;IAkBrC;;OAEG;IACH,MAAM,IAAI,OAAO;IAEjB;;OAEG;IACH,UAAU,IAAI,OAAO;IAErB;;OAEG;IACH,QAAQ,IAAI,MAAM;IAElB;;;;;;OAMG;IACH,aAAa,IAAI,MAAM;IAEvB;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,EAAE,WAAW,GAAG,WAAW;IAI1C;;;;;;;OAOG;IACH,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,YAAY,EAAE,SAAS,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,WAAW;IAqB/F;;;;;OAKG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,WAAW;IA0BrE;;;;;;OAMG;IACH,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,WAAW;CAU1E"} \ No newline at end of file diff --git a/lib.esm/utils/fixednumber.js b/lib.esm/utils/fixednumber.js new file mode 100644 index 00000000..5856b392 --- /dev/null +++ b/lib.esm/utils/fixednumber.js @@ -0,0 +1,526 @@ +/** + * The **FixedNumber** class permits using values with decimal places, + * using fixed-pont math. + * + * Fixed-point math is still based on integers under-the-hood, but uses an + * internal offset to store fractional components below, and each operation + * corrects for this after each operation. + * + * @_section: api/utils/fixed-point-math:Fixed-Point Maths [about-fixed-point-math] + */ +import { getBytes } from "./data.js"; +import { assert, assertArgument, assertPrivate } from "./errors.js"; +import { getBigInt, getNumber, fromTwos, mask, toBigInt } from "./maths.js"; +import { defineProperties } from "./properties.js"; +const BN_N1 = BigInt(-1); +const BN_0 = BigInt(0); +const BN_1 = BigInt(1); +const BN_5 = BigInt(5); +const _guard = {}; +// Constant to pull zeros from for multipliers +let Zeros = "0000"; +while (Zeros.length < 80) { + Zeros += Zeros; +} +// Returns a string "1" followed by decimal "0"s +function getTens(decimals) { + let result = Zeros; + while (result.length < decimals) { + result += result; + } + return BigInt("1" + result.substring(0, decimals)); +} +function checkValue(val, format, safeOp) { + const width = BigInt(format.width); + if (format.signed) { + const limit = (BN_1 << (width - BN_1)); + assert(safeOp == null || (val >= -limit && val < limit), "overflow", "NUMERIC_FAULT", { + operation: safeOp, fault: "overflow", value: val + }); + if (val > BN_0) { + val = fromTwos(mask(val, width), width); + } + else { + val = -fromTwos(mask(-val, width), width); + } + } + else { + const limit = (BN_1 << width); + assert(safeOp == null || (val >= 0 && val < limit), "overflow", "NUMERIC_FAULT", { + operation: safeOp, fault: "overflow", value: val + }); + val = (((val % limit) + limit) % limit) & (limit - BN_1); + } + return val; +} +function getFormat(value) { + if (typeof (value) === "number") { + value = `fixed128x${value}`; + } + let signed = true; + let width = 128; + let decimals = 18; + if (typeof (value) === "string") { + // Parse the format string + if (value === "fixed") { + // defaults... + } + else if (value === "ufixed") { + signed = false; + } + else { + const match = value.match(/^(u?)fixed([0-9]+)x([0-9]+)$/); + assertArgument(match, "invalid fixed format", "format", value); + signed = (match[1] !== "u"); + width = parseInt(match[2]); + decimals = parseInt(match[3]); + } + } + else if (value) { + // Extract the values from the object + const v = value; + const check = (key, type, defaultValue) => { + if (v[key] == null) { + return defaultValue; + } + assertArgument(typeof (v[key]) === type, "invalid fixed format (" + key + " not " + type + ")", "format." + key, v[key]); + return v[key]; + }; + signed = check("signed", "boolean", signed); + width = check("width", "number", width); + decimals = check("decimals", "number", decimals); + } + assertArgument((width % 8) === 0, "invalid FixedNumber width (not byte aligned)", "format.width", width); + assertArgument(decimals <= 80, "invalid FixedNumber decimals (too large)", "format.decimals", decimals); + const name = (signed ? "" : "u") + "fixed" + String(width) + "x" + String(decimals); + return { signed, width, decimals, name }; +} +function toString(val, decimals) { + let negative = ""; + if (val < BN_0) { + negative = "-"; + val *= BN_N1; + } + let str = val.toString(); + // No decimal point for whole values + if (decimals === 0) { + return (negative + str); + } + // Pad out to the whole component (including a whole digit) + while (str.length <= decimals) { + str = Zeros + str; + } + // Insert the decimal point + const index = str.length - decimals; + str = str.substring(0, index) + "." + str.substring(index); + // Trim the whole component (leaving at least one 0) + while (str[0] === "0" && str[1] !== ".") { + str = str.substring(1); + } + // Trim the decimal component (leaving at least one 0) + while (str[str.length - 1] === "0" && str[str.length - 2] !== ".") { + str = str.substring(0, str.length - 1); + } + return (negative + str); +} +/** + * A FixedNumber represents a value over its [[FixedFormat]] + * arithmetic field. + * + * A FixedNumber can be used to perform math, losslessly, on + * values which have decmial places. + * + * A FixedNumber has a fixed bit-width to store values in, and stores all + * values internally by multiplying the value by 10 raised to the power of + * %%decimals%%. + * + * If operations are performed that cause a value to grow too high (close to + * positive infinity) or too low (close to negative infinity), the value + * is said to //overflow//. + * + * For example, an 8-bit signed value, with 0 decimals may only be within + * the range ``-128`` to ``127``; so ``-128 - 1`` will overflow and become + * ``127``. Likewise, ``127 + 1`` will overflow and become ``-127``. + * + * Many operation have a normal and //unsafe// variant. The normal variant + * will throw a [[NumericFaultError]] on any overflow, while the //unsafe// + * variant will silently allow overflow, corrupting its value value. + * + * If operations are performed that cause a value to become too small + * (close to zero), the value loses precison and is said to //underflow//. + * + * For example, an value with 1 decimal place may store a number as small + * as ``0.1``, but the value of ``0.1 / 2`` is ``0.05``, which cannot fit + * into 1 decimal place, so underflow occurs which means precision is lost + * and the value becomes ``0``. + * + * Some operations have a normal and //signalling// variant. The normal + * variant will silently ignore underflow, while the //signalling// variant + * will thow a [[NumericFaultError]] on underflow. + */ +export class FixedNumber { + /** + * The specific fixed-point arithmetic field for this value. + */ + format; + #format; + // The actual value (accounting for decimals) + #val; + // A base-10 value to multiple values by to maintain the magnitude + #tens; + /** + * This is a property so console.log shows a human-meaningful value. + * + * @private + */ + _value; + // Use this when changing this file to get some typing info, + // but then switch to any to mask the internal type + //constructor(guard: any, value: bigint, format: _FixedFormat) { + /** + * @private + */ + constructor(guard, value, format) { + assertPrivate(guard, _guard, "FixedNumber"); + this.#val = value; + this.#format = format; + const _value = toString(value, format.decimals); + defineProperties(this, { format: format.name, _value }); + this.#tens = getTens(format.decimals); + } + /** + * If true, negative values are permitted, otherwise only + * positive values and zero are allowed. + */ + get signed() { return this.#format.signed; } + /** + * The number of bits available to store the value. + */ + get width() { return this.#format.width; } + /** + * The number of decimal places in the fixed-point arithment field. + */ + get decimals() { return this.#format.decimals; } + /** + * The value as an integer, based on the smallest unit the + * [[decimals]] allow. + */ + get value() { return this.#val; } + #checkFormat(other) { + assertArgument(this.format === other.format, "incompatible format; use fixedNumber.toFormat", "other", other); + } + #checkValue(val, safeOp) { + /* + const width = BigInt(this.width); + if (this.signed) { + const limit = (BN_1 << (width - BN_1)); + assert(safeOp == null || (val >= -limit && val < limit), "overflow", "NUMERIC_FAULT", { + operation: safeOp, fault: "overflow", value: val + }); + + if (val > BN_0) { + val = fromTwos(mask(val, width), width); + } else { + val = -fromTwos(mask(-val, width), width); + } + + } else { + const masked = mask(val, width); + assert(safeOp == null || (val >= 0 && val === masked), "overflow", "NUMERIC_FAULT", { + operation: safeOp, fault: "overflow", value: val + }); + val = masked; + } + */ + val = checkValue(val, this.#format, safeOp); + return new FixedNumber(_guard, val, this.#format); + } + #add(o, safeOp) { + this.#checkFormat(o); + return this.#checkValue(this.#val + o.#val, safeOp); + } + /** + * Returns a new [[FixedNumber]] with the result of %%this%% added + * to %%other%%, ignoring overflow. + */ + addUnsafe(other) { return this.#add(other); } + /** + * Returns a new [[FixedNumber]] with the result of %%this%% added + * to %%other%%. A [[NumericFaultError]] is thrown if overflow + * occurs. + */ + add(other) { return this.#add(other, "add"); } + #sub(o, safeOp) { + this.#checkFormat(o); + return this.#checkValue(this.#val - o.#val, safeOp); + } + /** + * Returns a new [[FixedNumber]] with the result of %%other%% subtracted + * from %%this%%, ignoring overflow. + */ + subUnsafe(other) { return this.#sub(other); } + /** + * Returns a new [[FixedNumber]] with the result of %%other%% subtracted + * from %%this%%. A [[NumericFaultError]] is thrown if overflow + * occurs. + */ + sub(other) { return this.#sub(other, "sub"); } + #mul(o, safeOp) { + this.#checkFormat(o); + return this.#checkValue((this.#val * o.#val) / this.#tens, safeOp); + } + /** + * Returns a new [[FixedNumber]] with the result of %%this%% multiplied + * by %%other%%, ignoring overflow and underflow (precision loss). + */ + mulUnsafe(other) { return this.#mul(other); } + /** + * Returns a new [[FixedNumber]] with the result of %%this%% multiplied + * by %%other%%. A [[NumericFaultError]] is thrown if overflow + * occurs. + */ + mul(other) { return this.#mul(other, "mul"); } + /** + * Returns a new [[FixedNumber]] with the result of %%this%% multiplied + * by %%other%%. A [[NumericFaultError]] is thrown if overflow + * occurs or if underflow (precision loss) occurs. + */ + mulSignal(other) { + this.#checkFormat(other); + const value = this.#val * other.#val; + assert((value % this.#tens) === BN_0, "precision lost during signalling mul", "NUMERIC_FAULT", { + operation: "mulSignal", fault: "underflow", value: this + }); + return this.#checkValue(value / this.#tens, "mulSignal"); + } + #div(o, safeOp) { + assert(o.#val !== BN_0, "division by zero", "NUMERIC_FAULT", { + operation: "div", fault: "divide-by-zero", value: this + }); + this.#checkFormat(o); + return this.#checkValue((this.#val * this.#tens) / o.#val, safeOp); + } + /** + * Returns a new [[FixedNumber]] with the result of %%this%% divided + * by %%other%%, ignoring underflow (precision loss). A + * [[NumericFaultError]] is thrown if overflow occurs. + */ + divUnsafe(other) { return this.#div(other); } + /** + * Returns a new [[FixedNumber]] with the result of %%this%% divided + * by %%other%%, ignoring underflow (precision loss). A + * [[NumericFaultError]] is thrown if overflow occurs. + */ + div(other) { return this.#div(other, "div"); } + /** + * Returns a new [[FixedNumber]] with the result of %%this%% divided + * by %%other%%. A [[NumericFaultError]] is thrown if underflow + * (precision loss) occurs. + */ + divSignal(other) { + assert(other.#val !== BN_0, "division by zero", "NUMERIC_FAULT", { + operation: "div", fault: "divide-by-zero", value: this + }); + this.#checkFormat(other); + const value = (this.#val * this.#tens); + assert((value % other.#val) === BN_0, "precision lost during signalling div", "NUMERIC_FAULT", { + operation: "divSignal", fault: "underflow", value: this + }); + return this.#checkValue(value / other.#val, "divSignal"); + } + /** + * Returns a comparison result between %%this%% and %%other%%. + * + * This is suitable for use in sorting, where ``-1`` implies %%this%% + * is smaller, ``1`` implies %%this%% is larger and ``0`` implies + * both are equal. + */ + cmp(other) { + let a = this.value, b = other.value; + // Coerce a and b to the same magnitude + const delta = this.decimals - other.decimals; + if (delta > 0) { + b *= getTens(delta); + } + else if (delta < 0) { + a *= getTens(-delta); + } + // Comnpare + if (a < b) { + return -1; + } + if (a > b) { + return 1; + } + return 0; + } + /** + * Returns true if %%other%% is equal to %%this%%. + */ + eq(other) { return this.cmp(other) === 0; } + /** + * Returns true if %%other%% is less than to %%this%%. + */ + lt(other) { return this.cmp(other) < 0; } + /** + * Returns true if %%other%% is less than or equal to %%this%%. + */ + lte(other) { return this.cmp(other) <= 0; } + /** + * Returns true if %%other%% is greater than to %%this%%. + */ + gt(other) { return this.cmp(other) > 0; } + /** + * Returns true if %%other%% is greater than or equal to %%this%%. + */ + gte(other) { return this.cmp(other) >= 0; } + /** + * Returns a new [[FixedNumber]] which is the largest **integer** + * that is less than or equal to %%this%%. + * + * The decimal component of the result will always be ``0``. + */ + floor() { + let val = this.#val; + if (this.#val < BN_0) { + val -= this.#tens - BN_1; + } + val = (this.#val / this.#tens) * this.#tens; + return this.#checkValue(val, "floor"); + } + /** + * Returns a new [[FixedNumber]] which is the smallest **integer** + * that is greater than or equal to %%this%%. + * + * The decimal component of the result will always be ``0``. + */ + ceiling() { + let val = this.#val; + if (this.#val > BN_0) { + val += this.#tens - BN_1; + } + val = (this.#val / this.#tens) * this.#tens; + return this.#checkValue(val, "ceiling"); + } + /** + * Returns a new [[FixedNumber]] with the decimal component + * rounded up on ties at %%decimals%% places. + */ + round(decimals) { + if (decimals == null) { + decimals = 0; + } + // Not enough precision to not already be rounded + if (decimals >= this.decimals) { + return this; + } + const delta = this.decimals - decimals; + const bump = BN_5 * getTens(delta - 1); + let value = this.value + bump; + const tens = getTens(delta); + value = (value / tens) * tens; + checkValue(value, this.#format, "round"); + return new FixedNumber(_guard, value, this.#format); + } + /** + * Returns true if %%this%% is equal to ``0``. + */ + isZero() { return (this.#val === BN_0); } + /** + * Returns true if %%this%% is less than ``0``. + */ + isNegative() { return (this.#val < BN_0); } + /** + * Returns the string representation of %%this%%. + */ + toString() { return this._value; } + /** + * Returns a float approximation. + * + * Due to IEEE 754 precission (or lack thereof), this function + * can only return an approximation and most values will contain + * rounding errors. + */ + toUnsafeFloat() { return parseFloat(this.toString()); } + /** + * Return a new [[FixedNumber]] with the same value but has had + * its field set to %%format%%. + * + * This will throw if the value cannot fit into %%format%%. + */ + toFormat(format) { + return FixedNumber.fromString(this.toString(), format); + } + /** + * Creates a new [[FixedNumber]] for %%value%% divided by + * %%decimal%% places with %%format%%. + * + * This will throw a [[NumericFaultError]] if %%value%% (once adjusted + * for %%decimals%%) cannot fit in %%format%%, either due to overflow + * or underflow (precision loss). + */ + static fromValue(_value, _decimals, _format) { + const decimals = (_decimals == null) ? 0 : getNumber(_decimals); + const format = getFormat(_format); + let value = getBigInt(_value, "value"); + const delta = decimals - format.decimals; + if (delta > 0) { + const tens = getTens(delta); + assert((value % tens) === BN_0, "value loses precision for format", "NUMERIC_FAULT", { + operation: "fromValue", fault: "underflow", value: _value + }); + value /= tens; + } + else if (delta < 0) { + value *= getTens(-delta); + } + checkValue(value, format, "fromValue"); + return new FixedNumber(_guard, value, format); + } + /** + * Creates a new [[FixedNumber]] for %%value%% with %%format%%. + * + * This will throw a [[NumericFaultError]] if %%value%% cannot fit + * in %%format%%, either due to overflow or underflow (precision loss). + */ + static fromString(_value, _format) { + const match = _value.match(/^(-?)([0-9]*)\.?([0-9]*)$/); + assertArgument(match && (match[2].length + match[3].length) > 0, "invalid FixedNumber string value", "value", _value); + const format = getFormat(_format); + let whole = (match[2] || "0"), decimal = (match[3] || ""); + // Pad out the decimals + while (decimal.length < format.decimals) { + decimal += Zeros; + } + // Check precision is safe + assert(decimal.substring(format.decimals).match(/^0*$/), "too many decimals for format", "NUMERIC_FAULT", { + operation: "fromString", fault: "underflow", value: _value + }); + // Remove extra padding + decimal = decimal.substring(0, format.decimals); + const value = BigInt(match[1] + whole + decimal); + checkValue(value, format, "fromString"); + return new FixedNumber(_guard, value, format); + } + /** + * Creates a new [[FixedNumber]] with the big-endian representation + * %%value%% with %%format%%. + * + * This will throw a [[NumericFaultError]] if %%value%% cannot fit + * in %%format%% due to overflow. + */ + static fromBytes(_value, _format) { + let value = toBigInt(getBytes(_value, "value")); + const format = getFormat(_format); + if (format.signed) { + value = fromTwos(value, format.width); + } + checkValue(value, format, "fromBytes"); + return new FixedNumber(_guard, value, format); + } +} +//const f1 = FixedNumber.fromString("12.56", "fixed16x2"); +//const f2 = FixedNumber.fromString("0.3", "fixed16x2"); +//console.log(f1.divSignal(f2)); +//const BUMP = FixedNumber.from("0.5"); +//# sourceMappingURL=fixednumber.js.map \ No newline at end of file diff --git a/lib.esm/utils/fixednumber.js.map b/lib.esm/utils/fixednumber.js.map new file mode 100644 index 00000000..b70aeeff --- /dev/null +++ b/lib.esm/utils/fixednumber.js.map @@ -0,0 +1 @@ +{"version":3,"file":"fixednumber.js","sourceRoot":"","sources":["../../src.ts/utils/fixednumber.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACpE,OAAO,EACH,SAAS,EAAE,SAAS,EAAE,QAAQ,E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GAAG,OAAO,CAAC,CAAA;QAEhD,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC;QAExC,OAAO,IAAI,WAAW,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;IAClD,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,SAAS,CAAC,MAAiB,EAAE,OAAqB;QACrD,IAAI,KAAK,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;QAChD,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC;QAElC,IAAI,MAAM,CAAC,MAAM,EAAE;YAAE,KAAK,GAAG,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;SAAE;QAE7D,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;QAEvC,OAAO,IAAI,WAAW,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;IAClD,CAAC;CACJ;AAED,0DAA0D;AAC1D,wDAAwD;AACxD,gCAAgC;AAChC,uCAAuC"} \ No newline at end of file diff --git a/lib.esm/utils/geturl-browser.d.ts b/lib.esm/utils/geturl-browser.d.ts new file mode 100644 index 00000000..eea23c26 --- /dev/null +++ b/lib.esm/utils/geturl-browser.d.ts @@ -0,0 +1,22 @@ +import type { FetchGetUrlFunc, FetchRequest, FetchCancelSignal, GetUrlResponse } from "./fetch.js"; +declare global { + class Headers { + constructor(values: Array<[string, string]>); + forEach(func: (v: string, k: string) => void): void; + } + class Response { + status: number; + statusText: string; + headers: Headers; + arrayBuffer(): Promise; + } + type FetchInit = { + method?: string; + headers?: Headers; + body?: Uint8Array; + }; + function fetch(url: string, init: FetchInit): Promise; +} +export declare function createGetUrl(options?: Record): FetchGetUrlFunc; +export declare function getUrl(req: FetchRequest, _signal?: FetchCancelSignal): Promise; +//# sourceMappingURL=geturl-browser.d.ts.map \ No newline at end of file diff --git a/lib.esm/utils/geturl-browser.d.ts.map b/lib.esm/utils/geturl-browser.d.ts.map new file mode 100644 index 00000000..b2e929cc --- /dev/null +++ b/lib.esm/utils/geturl-browser.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"geturl-browser.d.ts","sourceRoot":"","sources":["../../src.ts/utils/geturl-browser.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACR,eAAe,EAAE,YAAY,EAAE,iBAAiB,EAAE,cAAc,EACnE,MAAM,YAAY,CAAC;AAGpB,OAAO,CAAC,MAAM,CAAC;IACX,MAAM,OAAO;oBACG,MAAM,EAAE,KAAK,CAAC,CAAE,MAAM,EAAE,MAAM,CAAE,CAAC;QAC7C,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI;KACtD;IAED,MAAM,QAAQ;QACV,MAAM,EAAE,MAAM,CAAC;QACf,UAAU,EAAE,MAAM,CAAC;QACnB,OAAO,EAAE,OAAO,CAAC;QACjB,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC;KACtC;IAED,KAAK,SAAS,GAAG;QACb,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,IAAI,CAAC,EAAE,UAAU,CAAA;KACpB,CAAC;IAEF,SAAS,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CACnE;AAID,wBAAgB,YAAY,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,eAAe,CA8C3E;AAKD,wBAAsB,MAAM,CAAC,GAAG,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,cAAc,CAAC,CAEpG"} \ No newline at end of file diff --git a/lib.esm/utils/geturl-browser.js b/lib.esm/utils/geturl-browser.js new file mode 100644 index 00000000..253fdeee --- /dev/null +++ b/lib.esm/utils/geturl-browser.js @@ -0,0 +1,45 @@ +import { assert } from "./errors.js"; +// @TODO: timeout is completely ignored; start a Promise.any with a reject? +export function createGetUrl(options) { + async function getUrl(req, _signal) { + const protocol = req.url.split(":")[0].toLowerCase(); + assert(protocol === "http" || protocol === "https", `unsupported protocol ${protocol}`, "UNSUPPORTED_OPERATION", { + info: { protocol }, + operation: "request" + }); + assert(protocol === "https" || !req.credentials || req.allowInsecureAuthentication, "insecure authorized connections unsupported", "UNSUPPORTED_OPERATION", { + operation: "request" + }); + let signal = undefined; + if (_signal) { + const controller = new AbortController(); + signal = controller.signal; + _signal.addListener(() => { controller.abort(); }); + } + const init = { + method: req.method, + headers: new Headers(Array.from(req)), + body: req.body || undefined, + signal + }; + const resp = await fetch(req.url, init); + const headers = {}; + resp.headers.forEach((value, key) => { + headers[key.toLowerCase()] = value; + }); + const respBody = await resp.arrayBuffer(); + const body = (respBody == null) ? null : new Uint8Array(respBody); + return { + statusCode: resp.status, + statusMessage: resp.statusText, + headers, body + }; + } + return getUrl; +} +// @TODO: remove in v7; provided for backwards compat +const defaultGetUrl = createGetUrl({}); +export async function getUrl(req, _signal) { + return defaultGetUrl(req, _signal); +} +//# sourceMappingURL=geturl-browser.js.map \ No newline at end of file diff --git a/lib.esm/utils/geturl-browser.js.map b/lib.esm/utils/geturl-browser.js.map new file mode 100644 index 00000000..be744e9b --- /dev/null +++ b/lib.esm/utils/geturl-browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"geturl-browser.js","sourceRoot":"","sources":["../../src.ts/utils/geturl-browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AA6BrC,2EAA2E;AAE3E,MAAM,UAAU,YAAY,CAAC,OAA6B;IAEtD,KAAK,UAAU,MAAM,CAAC,GAAiB,EAAE,OAA2B;QAChE,MAAM,QAAQ,GAAG,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,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AC1C,MAAM,IAAI,GAAG,CAAC,QAAQ,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA,CAAC,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,CAAC;QAEjE,OAAO;YACH,UAAU,EAAE,IAAI,CAAC,MAAM;YACvB,aAAa,EAAE,IAAI,CAAC,UAAU;YAC9B,OAAO,EAAE,IAAI;SAChB,CAAC;IACN,CAAC;IAED,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,qDAAqD;AACrD,MAAM,aAAa,GAAoB,YAAY,CAAC,EAAG,CAAC,CAAC;AAEzD,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,GAAiB,EAAE,OAA2B;IACvE,OAAO,aAAa,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AACvC,CAAC"} \ No newline at end of file diff --git a/lib.esm/utils/geturl.d.ts b/lib.esm/utils/geturl.d.ts new file mode 100644 index 00000000..8d0d9783 --- /dev/null +++ b/lib.esm/utils/geturl.d.ts @@ -0,0 +1,10 @@ +import type { FetchGetUrlFunc, FetchRequest, FetchCancelSignal, GetUrlResponse } from "./fetch.js"; +/** + * @_ignore: + */ +export declare function createGetUrl(options?: Record): FetchGetUrlFunc; +/** + * @_ignore: + */ +export declare function getUrl(req: FetchRequest, signal?: FetchCancelSignal): Promise; +//# sourceMappingURL=geturl.d.ts.map \ No newline at end of file diff --git a/lib.esm/utils/geturl.d.ts.map b/lib.esm/utils/geturl.d.ts.map new file mode 100644 index 00000000..a7923b9b --- /dev/null +++ b/lib.esm/utils/geturl.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"geturl.d.ts","sourceRoot":"","sources":["../../src.ts/utils/geturl.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACR,eAAe,EAAE,YAAY,EAAE,iBAAiB,EAAE,cAAc,EACnE,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,wBAAgB,YAAY,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,eAAe,CA0F3E;AAKD;;GAEG;AACH,wBAAsB,MAAM,CAAC,GAAG,EAAE,YAAY,EAAE,MAAM,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,cAAc,CAAC,CAEnG"} \ No newline at end of file diff --git a/lib.esm/utils/geturl.js b/lib.esm/utils/geturl.js new file mode 100644 index 00000000..d2d29c20 --- /dev/null +++ b/lib.esm/utils/geturl.js @@ -0,0 +1,94 @@ +import http from "http"; +import https from "https"; +import { gunzipSync } from "zlib"; +import { assert } from "./errors.js"; +import { getBytes } from "./data.js"; +/** + * @_ignore: + */ +export function createGetUrl(options) { + async function getUrl(req, signal) { + const protocol = req.url.split(":")[0].toLowerCase(); + assert(protocol === "http" || protocol === "https", `unsupported protocol ${protocol}`, "UNSUPPORTED_OPERATION", { + info: { protocol }, + operation: "request" + }); + assert(protocol === "https" || !req.credentials || req.allowInsecureAuthentication, "insecure authorized connections unsupported", "UNSUPPORTED_OPERATION", { + operation: "request" + }); + const method = req.method; + const headers = Object.assign({}, req.headers); + const reqOptions = { method, headers }; + if (options) { + if (options.agent) { + reqOptions.agent = options.agent; + } + } + const request = ((protocol === "http") ? http : https).request(req.url, reqOptions); + request.setTimeout(req.timeout); + const body = req.body; + if (body) { + request.write(Buffer.from(body)); + } + request.end(); + return new Promise((resolve, reject) => { + // @TODO: Node 15 added AbortSignal; once we drop support for + // Node14, we can add that in here too + request.once("response", (resp) => { + const statusCode = resp.statusCode || 0; + const statusMessage = resp.statusMessage || ""; + const headers = Object.keys(resp.headers || {}).reduce((accum, name) => { + let value = resp.headers[name] || ""; + if (Array.isArray(value)) { + value = value.join(", "); + } + accum[name] = value; + return accum; + }, {}); + let body = null; + //resp.setEncoding("utf8"); + resp.on("data", (chunk) => { + if (signal) { + try { + signal.checkSignal(); + } + catch (error) { + return reject(error); + } + } + if (body == null) { + body = chunk; + } + else { + const newBody = new Uint8Array(body.length + chunk.length); + newBody.set(body, 0); + newBody.set(chunk, body.length); + body = newBody; + } + }); + resp.on("end", () => { + if (headers["content-encoding"] === "gzip" && body) { + body = getBytes(gunzipSync(body)); + } + resolve({ statusCode, statusMessage, headers, body }); + }); + resp.on("error", (error) => { + //@TODO: Should this just return nornal response with a server error? + error.response = { statusCode, statusMessage, headers, body }; + reject(error); + }); + }); + request.on("error", (error) => { reject(error); }); + }); + } + return getUrl; +} +// @TODO: remove in v7; provided for backwards compat +const defaultGetUrl = createGetUrl({}); +/** + * @_ignore: + */ +export async function getUrl(req, signal) { + return defaultGetUrl(req, signal); +} +//# sourceMappingURL=geturl.js.map \ No newline at end of file diff --git a/lib.esm/utils/geturl.js.map b/lib.esm/utils/geturl.js.map new file mode 100644 index 00000000..39173f6b --- /dev/null +++ b/lib.esm/utils/geturl.js.map @@ -0,0 +1 @@ +{"version":3,"file":"geturl.js","sourceRoot":"","sources":["../../src.ts/utils/geturl.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAElC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAMrC;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,OAA6B;IAEtD,KAAK,UAAU,MAAM,CAAC,GAAiB,EAAE,MAA0B;QAE/D,MAAM,QAAQ,GAAG,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;QAErD,MAAM,CAAC,QAAQ,KAAK,MAAM,IAAI,QAAQ,KAAK,OAAO,EAAE,wBAAyB,QAAS,EAAE,EAAE,uBAAuB,EAAE;YAC/G,IAAI,EAAE,EAAE,QAAQ,EAAE;YAClB,SAAS,EAAE,SAAS;SACvB,CAAC,CAAC;QAEH,MAAM,CAAC,QAAQ,KAAK,O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AC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;qBACrC;oBAED,OAAO,CAAC,EAAE,UAAU,EAAE,aAAa,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;gBAC1D,CAAC,CAAC,CAAC;gBAEH,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;oBAC3B,qEAAqE;oBAC3D,KAAM,CAAC,QAAQ,GAAG,EAAE,UAAU,EAAE,aAAa,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;oBACrE,MAAM,CAAC,KAAK,CAAC,CAAC;gBAClB,CAAC,CAAC,CAAC;YACP,CAAC,CAAC,CAAC;YAEH,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACvD,CAAC,CAAC,CAAC;IACP,CAAC;IAED,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,qDAAqD;AACrD,MAAM,aAAa,GAAoB,YAAY,CAAC,EAAG,CAAC,CAAC;AAEzD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,GAAiB,EAAE,MAA0B;IACtE,OAAO,aAAa,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;AACtC,CAAC"} \ No newline at end of file diff --git a/lib.esm/utils/index.d.ts b/lib.esm/utils/index.d.ts new file mode 100644 index 00000000..0e36172c --- /dev/null +++ b/lib.esm/utils/index.d.ts @@ -0,0 +1,30 @@ +/** + * There are many simple utilities required to interact with + * Ethereum and to simplify the library, without increasing + * the library dependencies for simple functions. + * + * @_section api/utils:Utilities [about-utils] + */ +export { decodeBase58, encodeBase58 } from "./base58.js"; +export { decodeBase64, encodeBase64 } from "./base64.js"; +export { getBytes, getBytesCopy, isHexString, isBytesLike, hexlify, concat, dataLength, dataSlice, stripZerosLeft, zeroPadValue, zeroPadBytes } from "./data.js"; +export { isCallException, isError, assert, assertArgument, assertArgumentCount, assertPrivate, assertNormalize, makeError } from "./errors.js"; +export { EventPayload } from "./events.js"; +export { FetchRequest, FetchResponse, FetchCancelSignal, } from "./fetch.js"; +export { FixedNumber } from "./fixednumber.js"; +export { fromTwos, toTwos, mask, getBigInt, getNumber, getUint, toBigInt, toNumber, toBeHex, toBeArray, toQuantity } from "./maths.js"; +export { resolveProperties, defineProperties } from "./properties.js"; +export { encodeProto } from "./proto-encode.js"; +export { decodeProto } from "./proto-decode.js"; +export { formatQuai, parseQuai, formatEther, parseEther, formatUnits, parseUnits } from "./units.js"; +export { toUtf8Bytes, toUtf8CodePoints, toUtf8String, Utf8ErrorFuncs, } from "./utf8.js"; +export { uuidV4 } from "./uuid.js"; +export { getTxType, getShardForAddress, getAddressDetails, isUTXOAddress } from "./shards.js"; +export type { BytesLike } from "./data.js"; +export type { ErrorCode, quaisError, UnknownError, NotImplementedError, UnsupportedOperationError, NetworkError, ServerError, TimeoutError, BadDataError, CancelledError, BufferOverrunError, NumericFaultError, InvalidArgumentError, MissingArgumentError, UnexpectedArgumentError, CallExceptionError, InsufficientFundsError, NonceExpiredError, ReplacementUnderpricedError, TransactionReplacedError, ActionRejectedError, CallExceptionAction, CallExceptionTransaction, CodedquaisError } from "./errors.js"; +export type { EventEmitterable, Listener } from "./events.js"; +export type { GetUrlResponse, FetchPreflightFunc, FetchProcessFunc, FetchRetryFunc, FetchGatewayFunc, FetchGetUrlFunc } from "./fetch.js"; +export type { FixedFormat } from "./fixednumber.js"; +export type { BigNumberish, Numeric } from "./maths.js"; +export type { Utf8ErrorFunc, UnicodeNormalizationForm, Utf8ErrorReason } from "./utf8.js"; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/lib.esm/utils/index.d.ts.map b/lib.esm/utils/index.d.ts.map new file mode 100644 index 00000000..235c091b --- /dev/null +++ b/lib.esm/utils/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src.ts/utils/index.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,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAK9F,YAAY,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,YAAY,EAKR,SAAS,EAET,UAAU,EAAE,YAAY,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,YAAY,EACtF,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,kBAAkB,EAC3E,iBAAiB,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,uBAAuB,EACtF,kBAAkB,EAAE,sBAAsB,EAAE,iBAAiB,EAC7D,2BAA2B,EAAE,wBAAwB,EACrD,mBAAmB,EAEnB,mBAAmB,EAAE,wBAAwB,EAE7C,eAAe,EAClB,MAAM,aAAa,CAAA;AAEpB,YAAY,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE9D,YAAY,EACR,cAAc,EACd,kBAAkB,EAAE,gBAAgB,EAAE,cAAc,EACpD,gBAAgB,EAAE,eAAe,EACpC,MAAM,YAAY,CAAC;AAEpB,YAAY,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAEnD,YAAY,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAExD,YAAY,EACR,aAAa,EACb,wBAAwB,EACxB,eAAe,EAClB,MAAM,WAAW,CAAC"} \ No newline at end of file diff --git a/lib.esm/utils/index.js b/lib.esm/utils/index.js new file mode 100644 index 00000000..fd759f3d --- /dev/null +++ b/lib.esm/utils/index.js @@ -0,0 +1,23 @@ +/** + * There are many simple utilities required to interact with + * Ethereum and to simplify the library, without increasing + * the library dependencies for simple functions. + * + * @_section api/utils:Utilities [about-utils] + */ +export { decodeBase58, encodeBase58 } from "./base58.js"; +export { decodeBase64, encodeBase64 } from "./base64.js"; +export { getBytes, getBytesCopy, isHexString, isBytesLike, hexlify, concat, dataLength, dataSlice, stripZerosLeft, zeroPadValue, zeroPadBytes } from "./data.js"; +export { isCallException, isError, assert, assertArgument, assertArgumentCount, assertPrivate, assertNormalize, makeError } from "./errors.js"; +export { EventPayload } from "./events.js"; +export { FetchRequest, FetchResponse, FetchCancelSignal, } from "./fetch.js"; +export { FixedNumber } from "./fixednumber.js"; +export { fromTwos, toTwos, mask, getBigInt, getNumber, getUint, toBigInt, toNumber, toBeHex, toBeArray, toQuantity } from "./maths.js"; +export { resolveProperties, defineProperties } from "./properties.js"; +export { encodeProto } from "./proto-encode.js"; +export { decodeProto } from "./proto-decode.js"; +export { formatQuai, parseQuai, formatEther, parseEther, formatUnits, parseUnits } from "./units.js"; +export { toUtf8Bytes, toUtf8CodePoints, toUtf8String, Utf8ErrorFuncs, } from "./utf8.js"; +export { uuidV4 } from "./uuid.js"; +export { getTxType, getShardForAddress, getAddressDetails, isUTXOAddress } from "./shards.js"; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib.esm/utils/index.js.map b/lib.esm/utils/index.js.map new file mode 100644 index 00000000..f4641e5b --- /dev/null +++ b/lib.esm/utils/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src.ts/utils/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEzD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEzD,OAAO,EACH,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EACxF,cAAc,EAAE,YAAY,EAAE,YAAY,EAC7C,MAAM,WAAW,CAAC;AAEnB,OAAO,EACH,eAAe,EAAE,OAAO,EACxB,MAAM,EAAE,cAAc,EAAE,mBAAmB,EAAE,aAAa,EAAE,eAAe,EAAE,SAAS,EACzF,MAAM,aAAa,CAAA;AAEpB,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EACH,YAAY,EAAE,aAAa,EAAE,iBAAiB,GACjD,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAE9C,OAAO,EACH,QAAQ,EAAE,MAAM,EAAE,IAAI,EACtB,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EACpF,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEtE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAErG,OAAO,EACH,WAAW,EACX,gBAAgB,EAChB,YAAY,EAEZ,cAAc,GACjB,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"} \ No newline at end of file diff --git a/lib.esm/utils/maths.d.ts b/lib.esm/utils/maths.d.ts new file mode 100644 index 00000000..676f5294 --- /dev/null +++ b/lib.esm/utils/maths.d.ts @@ -0,0 +1,70 @@ +import type { BytesLike } from "./data.js"; +/** + * Any type that can be used where a numeric value is needed. + */ +export type Numeric = number | bigint; +/** + * Any type that can be used where a big number is needed. + */ +export type BigNumberish = string | Numeric; +/** + * Convert %%value%% from a twos-compliment representation of %%width%% + * bits to its value. + * + * If the highest bit is ``1``, the result will be negative. + */ +export declare function fromTwos(_value: BigNumberish, _width: Numeric): bigint; +/** + * Convert %%value%% to a twos-compliment representation of + * %%width%% bits. + * + * The result will always be positive. + */ +export declare function toTwos(_value: BigNumberish, _width: Numeric): bigint; +/** + * Mask %%value%% with a bitmask of %%bits%% ones. + */ +export declare function mask(_value: BigNumberish, _bits: Numeric): bigint; +/** + * Gets a BigInt from %%value%%. If it is an invalid value for + * a BigInt, then an ArgumentError will be thrown for %%name%%. + */ +export declare function getBigInt(value: BigNumberish, name?: string): bigint; +/** + * Returns absolute value of bigint %%value%%. + */ +export declare function bigIntAbs(value: BigNumberish): bigint; +/** + * Returns %%value%% as a bigint, validating it is valid as a bigint + * value and that it is positive. + */ +export declare function getUint(value: BigNumberish, name?: string): bigint; +export declare function toBigInt(value: BigNumberish | Uint8Array): bigint; +/** + * Gets a //number// from %%value%%. If it is an invalid value for + * a //number//, then an ArgumentError will be thrown for %%name%%. + */ +export declare function getNumber(value: BigNumberish, name?: string): number; +/** + * Converts %%value%% to a number. If %%value%% is a Uint8Array, it + * is treated as Big Endian data. Throws if the value is not safe. + */ +export declare function toNumber(value: BigNumberish | Uint8Array): number; +/** + * Converts %%value%% to a Big Endian hexstring, optionally padded to + * %%width%% bytes. + */ +export declare function toBeHex(_value: BigNumberish, _width?: Numeric): string; +/** + * Converts %%value%% to a Big Endian Uint8Array. + */ +export declare function toBeArray(_value: BigNumberish): Uint8Array; +/** + * Returns a [[HexString]] for %%value%% safe to use as a //Quantity//. + * + * A //Quantity// does not have and leading 0 values unless the value is + * the literal value `0x0`. This is most commonly used for JSSON-RPC + * numeric values. + */ +export declare function toQuantity(value: BytesLike | BigNumberish): string; +//# sourceMappingURL=maths.d.ts.map \ No newline at end of file diff --git a/lib.esm/utils/maths.d.ts.map b/lib.esm/utils/maths.d.ts.map new file mode 100644 index 00000000..f544e6fb --- /dev/null +++ b/lib.esm/utils/maths.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"maths.d.ts","sourceRoot":"","sources":["../../src.ts/utils/maths.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C;;GA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S,GAAG,YAAY,GAAG,MAAM,CAKlE"} \ No newline at end of file diff --git a/lib.esm/utils/maths.js b/lib.esm/utils/maths.js new file mode 100644 index 00000000..9d37bb87 --- /dev/null +++ b/lib.esm/utils/maths.js @@ -0,0 +1,226 @@ +/** + * Some mathematic operations. + * + * @_subsection: api/utils:Math Helpers [about-maths] + */ +import { hexlify, isBytesLike } from "./data.js"; +import { assert, assertArgument } from "./errors.js"; +const BN_0 = BigInt(0); +const BN_1 = BigInt(1); +//const BN_Max256 = (BN_1 << BigInt(256)) - BN_1; +// IEEE 754 support 53-bits of mantissa +const maxValue = 0x1fffffffffffff; +/** + * Convert %%value%% from a twos-compliment representation of %%width%% + * bits to its value. + * + * If the highest bit is ``1``, the result will be negative. + */ +export function fromTwos(_value, _width) { + const value = getUint(_value, "value"); + const width = BigInt(getNumber(_width, "width")); + assert((value >> width) === BN_0, "overflow", "NUMERIC_FAULT", { + operation: "fromTwos", fault: "overflow", value: _value + }); + // Top bit set; treat as a negative value + if (value >> (width - BN_1)) { + const mask = (BN_1 << width) - BN_1; + return -(((~value) & mask) + BN_1); + } + return value; +} +/** + * Convert %%value%% to a twos-compliment representation of + * %%width%% bits. + * + * The result will always be positive. + */ +export function toTwos(_value, _width) { + let value = getBigInt(_value, "value"); + const width = BigInt(getNumber(_width, "width")); + const limit = (BN_1 << (width - BN_1)); + if (value < BN_0) { + value = -value; + assert(value <= limit, "too low", "NUMERIC_FAULT", { + operation: "toTwos", fault: "overflow", value: _value + }); + const mask = (BN_1 << width) - BN_1; + return ((~value) & mask) + BN_1; + } + else { + assert(value < limit, "too high", "NUMERIC_FAULT", { + operation: "toTwos", fault: "overflow", value: _value + }); + } + return value; +} +/** + * Mask %%value%% with a bitmask of %%bits%% ones. + */ +export function mask(_value, _bits) { + const value = getUint(_value, "value"); + const bits = BigInt(getNumber(_bits, "bits")); + return value & ((BN_1 << bits) - BN_1); +} +/** + * Gets a BigInt from %%value%%. If it is an invalid value for + * a BigInt, then an ArgumentError will be thrown for %%name%%. + */ +export function getBigInt(value, name) { + switch (typeof (value)) { + case "bigint": return value; + case "number": + assertArgument(Number.isInteger(value), "underflow", name || "value", value); + assertArgument(value >= -maxValue && value <= maxValue, "overflow", name || "value", value); + return BigInt(value); + case "string": + try { + if (value === "") { + throw new Error("empty string"); + } + if (value[0] === "-" && value[1] !== "-") { + return -BigInt(value.substring(1)); + } + return BigInt(value); + } + catch (e) { + assertArgument(false, `invalid BigNumberish string: ${e.message}`, name || "value", value); + } + } + assertArgument(false, "invalid BigNumberish value", name || "value", value); +} +/** + * Returns absolute value of bigint %%value%%. + */ +export function bigIntAbs(value) { + value = getBigInt(value); + // if value is negative (including -0), return -value, else return value + if (value === -BN_0 || value < BN_0) { + return -value; + } + return value; +} +/** + * Returns %%value%% as a bigint, validating it is valid as a bigint + * value and that it is positive. + */ +export function getUint(value, name) { + const result = getBigInt(value, name); + assert(result >= BN_0, "unsigned value cannot be negative", "NUMERIC_FAULT", { + fault: "overflow", operation: "getUint", value + }); + return result; +} +const Nibbles = "0123456789abcdef"; +/* + * Converts %%value%% to a BigInt. If %%value%% is a Uint8Array, it + * is treated as Big Endian data. + */ +export function toBigInt(value) { + if (value instanceof Uint8Array) { + let result = "0x0"; + for (const v of value) { + result += Nibbles[v >> 4]; + result += Nibbles[v & 0x0f]; + } + return BigInt(result); + } + return getBigInt(value); +} +/** + * Gets a //number// from %%value%%. If it is an invalid value for + * a //number//, then an ArgumentError will be thrown for %%name%%. + */ +export function getNumber(value, name) { + switch (typeof (value)) { + case "bigint": + assertArgument(value >= -maxValue && value <= maxValue, "overflow", name || "value", value); + return Number(value); + case "number": + assertArgument(Number.isInteger(value), "underflow", name || "value", value); + assertArgument(value >= -maxValue && value <= maxValue, "overflow", name || "value", value); + return value; + case "string": + try { + if (value === "") { + throw new Error("empty string"); + } + return getNumber(BigInt(value), name); + } + catch (e) { + assertArgument(false, `invalid numeric string: ${e.message}`, name || "value", value); + } + } + assertArgument(false, "invalid numeric value", name || "value", value); +} +/** + * Converts %%value%% to a number. If %%value%% is a Uint8Array, it + * is treated as Big Endian data. Throws if the value is not safe. + */ +export function toNumber(value) { + return getNumber(toBigInt(value)); +} +/** + * Converts %%value%% to a Big Endian hexstring, optionally padded to + * %%width%% bytes. + */ +export function toBeHex(_value, _width) { + const value = getUint(_value, "value"); + let result = value.toString(16); + if (_width == null) { + // Ensure the value is of even length + if (result.length % 2) { + result = "0" + result; + } + } + else { + const width = getNumber(_width, "width"); + assert(width * 2 >= result.length, `value exceeds width (${width} bytes)`, "NUMERIC_FAULT", { + operation: "toBeHex", + fault: "overflow", + value: _value + }); + // Pad the value to the required width + while (result.length < (width * 2)) { + result = "0" + result; + } + } + return "0x" + result; +} +/** + * Converts %%value%% to a Big Endian Uint8Array. + */ +export function toBeArray(_value) { + const value = getUint(_value, "value"); + if (value === BN_0) { + return new Uint8Array([]); + } + let hex = value.toString(16); + if (hex.length % 2) { + hex = "0" + hex; + } + const result = new Uint8Array(hex.length / 2); + for (let i = 0; i < result.length; i++) { + const offset = i * 2; + result[i] = parseInt(hex.substring(offset, offset + 2), 16); + } + return result; +} +/** + * Returns a [[HexString]] for %%value%% safe to use as a //Quantity//. + * + * A //Quantity// does not have and leading 0 values unless the value is + * the literal value `0x0`. This is most commonly used for JSSON-RPC + * numeric values. + */ +export function toQuantity(value) { + let result = hexlify(isBytesLike(value) ? value : toBeArray(value)).substring(2); + while (result.startsWith("0")) { + result = result.substring(1); + } + if (result === "") { + result = "0"; + } + return "0x" + result; +} +//# sourceMappingURL=maths.js.map \ No newline at end of file diff --git a/lib.esm/utils/maths.js.map b/lib.esm/utils/maths.js.map new file mode 100644 index 00000000..87b3491a --- /dev/null +++ b/lib.esm/utils/maths.js.map @@ -0,0 +1 @@ +{"version":3,"file":"maths.js","sourceRoot":"","sources":["../../src.ts/utils/maths.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACjD,O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esm/utils/properties.d.ts b/lib.esm/utils/properties.d.ts new file mode 100644 index 00000000..e8517a7f --- /dev/null +++ b/lib.esm/utils/properties.d.ts @@ -0,0 +1,24 @@ +/** + * Property helper functions. + * + * @_subsection api/utils:Properties [about-properties] + */ +/** + * Resolves to a new object that is a copy of %%value%%, but with all + * values resolved. + */ +export declare function resolveProperties(value: { + [P in keyof T]: T[P] | Promise; +}): Promise; +export declare function getStatic(ctor: any, key: string): T | null; +/** + * Assigns the %%values%% to %%target%% as read-only values. + * + * It %%types%% is specified, the values are checked. + */ +export declare function defineProperties(target: T, values: { + [K in keyof T]?: T[K]; +}, types?: { + [K in keyof T]?: string; +}): void; +//# sourceMappingURL=properties.d.ts.map \ No newline at end of file diff --git a/lib.esm/utils/properties.d.ts.map b/lib.esm/utils/properties.d.ts.map new file mode 100644 index 00000000..65c1e49f --- /dev/null +++ b/lib.esm/utils/properties.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"properties.d.ts","sourceRoot":"","sources":["../../src.ts/utils/properties.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAwBH;;;GAGG;AACH,wBAAsB,iBAAiB,CAAC,CAAC,EAAE,KAAK,EAAE;KAAI,CAAC,IAAI,MAAM,CAAC,GAAI,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAOvG;AAGD,wBAAgB,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI,CAO7D;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EACjC,MAAM,EAAE,CAAC,EACT,MAAM,EAAE;KAAI,CAAC,IAAI,MAAM,CAAC,CAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;CAAE,EACnC,KAAK,CAAC,EAAE;KAAI,CAAC,IAAI,MAAM,CAAC,CAAE,CAAC,EAAE,MAAM;CAAE,GAAG,IAAI,CAU5C"} \ No newline at end of file diff --git a/lib.esm/utils/properties.js b/lib.esm/utils/properties.js new file mode 100644 index 00000000..50f92418 --- /dev/null +++ b/lib.esm/utils/properties.js @@ -0,0 +1,67 @@ +/** + * Property helper functions. + * + * @_subsection api/utils:Properties [about-properties] + */ +function checkType(value, type, name) { + const types = type.split("|").map(t => t.trim()); + for (let i = 0; i < types.length; i++) { + switch (type) { + case "any": + return; + case "bigint": + case "boolean": + case "number": + case "string": + if (typeof (value) === type) { + return; + } + } + } + const error = new Error(`invalid value for type ${type}`); + error.code = "INVALID_ARGUMENT"; + error.argument = `value.${name}`; + error.value = value; + throw error; +} +/** + * Resolves to a new object that is a copy of %%value%%, but with all + * values resolved. + */ +export async function resolveProperties(value) { + const keys = Object.keys(value); + const results = await Promise.all(keys.map((k) => Promise.resolve(value[k]))); + return results.reduce((accum, v, index) => { + accum[keys[index]] = v; + return accum; + }, {}); +} +// Crawl up the constructor chain to find a static method +export function getStatic(ctor, key) { + for (let i = 0; i < 32; i++) { + if (ctor[key]) { + return ctor[key]; + } + if (!ctor.prototype || typeof (ctor.prototype) !== "object") { + break; + } + ctor = Object.getPrototypeOf(ctor.prototype).constructor; + } + return null; +} +/** + * Assigns the %%values%% to %%target%% as read-only values. + * + * It %%types%% is specified, the values are checked. + */ +export function defineProperties(target, values, types) { + for (let key in values) { + let value = values[key]; + const type = (types ? types[key] : null); + if (type) { + checkType(value, type, key); + } + Object.defineProperty(target, key, { enumerable: true, value, writable: false }); + } +} +//# sourceMappingURL=properties.js.map \ No newline at end of file diff --git a/lib.esm/utils/properties.js.map b/lib.esm/utils/properties.js.map new file mode 100644 index 00000000..8b91d396 --- /dev/null +++ b/lib.esm/utils/properties.js.map @@ -0,0 +1 @@ +{"version":3,"file":"properties.js","sourceRoot":"","sources":["../../src.ts/utils/properties.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,SAAS,SAAS,CAAC,KAAU,EAAE,IAAY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AA6B,EAAG,CAAC,CAAC;AACvC,CAAC;AAED,yDAAyD;AACzD,MAAM,UAAU,SAAS,CAAI,IAAS,EAAE,GAAW;IAC/C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE;QACzB,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE;YAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;SAAE;QACpC,IAAI,CAAC,IAAI,CAAC,SAAS,IAAI,OAAM,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,QAAQ,EAAE;YAAE,MAAM;SAAE;QACtE,IAAI,GAAG,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,WAAW,CAAC;KAC5D;IACD,OAAO,IAAI,CAAC;AAChB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAC/B,MAAS,EACT,MAAmC,EACnC,KAAqC;IAElC,KAAK,IAAI,GAAG,IAAI,MAAM,EAAE;QACpB,IAAI,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;QAExB,MAAM,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA,CAAC,CAAC,IAAI,CAAC,CAAC;QACxC,IAAI,IAAI,EAAE;YAAE,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;SAAE;QAE1C,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC;KACpF;AACL,CAAC"} \ No newline at end of file diff --git a/lib.esm/utils/proto-decode.d.ts b/lib.esm/utils/proto-decode.d.ts new file mode 100644 index 00000000..8a079d76 --- /dev/null +++ b/lib.esm/utils/proto-decode.d.ts @@ -0,0 +1,2 @@ +export declare function decodeProto(object: Uint8Array): string; +//# sourceMappingURL=proto-decode.d.ts.map \ No newline at end of file diff --git a/lib.esm/utils/proto-decode.d.ts.map b/lib.esm/utils/proto-decode.d.ts.map new file mode 100644 index 00000000..0021044d --- /dev/null +++ b/lib.esm/utils/proto-decode.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"proto-decode.d.ts","sourceRoot":"","sources":["../../src.ts/utils/proto-decode.ts"],"names":[],"mappings":"AAQA,wBAAgB,WAAW,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAGtD"} \ No newline at end of file diff --git a/lib.esm/utils/proto-decode.js b/lib.esm/utils/proto-decode.js new file mode 100644 index 00000000..042af416 --- /dev/null +++ b/lib.esm/utils/proto-decode.js @@ -0,0 +1,11 @@ +import * as Proto from "./ProtoBuf/proto_block"; +function _decode(object) { + const tx = Proto.block.ProtoTransaction.deserialize(object); + const result = tx.toObject(); + return result; +} +export function decodeProto(object) { + // console.log('Test decode') + return _decode(object); +} +//# sourceMappingURL=proto-decode.js.map \ No newline at end of file diff --git a/lib.esm/utils/proto-decode.js.map b/lib.esm/utils/proto-decode.js.map new file mode 100644 index 00000000..f6a9c053 --- /dev/null +++ b/lib.esm/utils/proto-decode.js.map @@ -0,0 +1 @@ +{"version":3,"file":"proto-decode.js","sourceRoot":"","sources":["../../src.ts/utils/proto-decode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,wBAAwB,CAAA;AAE/C,SAAS,OAAO,CAAC,MAAW;IACxB,MAAM,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,gBAAgB,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IAC5D,MAAM,MAAM,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC;IAC7B,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,MAAkB;IAC1C,6BAA6B;IAC7B,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;AAC3B,CAAC"} \ No newline at end of file diff --git a/lib.esm/utils/proto-encode.d.ts b/lib.esm/utils/proto-encode.d.ts new file mode 100644 index 00000000..20476911 --- /dev/null +++ b/lib.esm/utils/proto-encode.d.ts @@ -0,0 +1,2 @@ +export declare function encodeProto(object: any): string; +//# sourceMappingURL=proto-encode.d.ts.map \ No newline at end of file diff --git a/lib.esm/utils/proto-encode.d.ts.map b/lib.esm/utils/proto-encode.d.ts.map new file mode 100644 index 00000000..33b3346f --- /dev/null +++ b/lib.esm/utils/proto-encode.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"proto-encode.d.ts","sourceRoot":"","sources":["../../src.ts/utils/proto-encode.ts"],"names":[],"mappings":"AASA,wBAAgB,WAAW,CAAC,MAAM,EAAE,GAAG,GAAG,MAAM,CAE/C"} \ No newline at end of file diff --git a/lib.esm/utils/proto-encode.js b/lib.esm/utils/proto-encode.js new file mode 100644 index 00000000..e4817cd8 --- /dev/null +++ b/lib.esm/utils/proto-encode.js @@ -0,0 +1,11 @@ +import { hexlify } from "./data"; +import * as Proto from "./ProtoBuf/proto_block"; +function _encode(object) { + const tx = Proto.block.ProtoTransaction.fromObject(object); + const result = tx.serialize(); + return result; +} +export function encodeProto(object) { + return hexlify(_encode(object)); +} +//# sourceMappingURL=proto-encode.js.map \ No newline at end of file diff --git a/lib.esm/utils/proto-encode.js.map b/lib.esm/utils/proto-encode.js.map new file mode 100644 index 00000000..8ac4bdf6 --- /dev/null +++ b/lib.esm/utils/proto-encode.js.map @@ -0,0 +1 @@ +{"version":3,"file":"proto-encode.js","sourceRoot":"","sources":["../../src.ts/utils/proto-encode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACjC,OAAO,KAAK,KAAK,MAAM,wBAAwB,CAAA;AAE/C,SAAS,OAAO,CAAC,MAAW;IACxB,MAAM,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,gBAAgB,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IAC3D,MAAM,MAAM,GAAG,EAAE,CAAC,SAAS,EAAE,CAAC;IAC9B,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,MAAW;IACnC,OAAO,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;AACpC,CAAC"} \ No newline at end of file diff --git a/lib.esm/utils/proto.d.ts b/lib.esm/utils/proto.d.ts new file mode 100644 index 00000000..09bff3c4 --- /dev/null +++ b/lib.esm/utils/proto.d.ts @@ -0,0 +1,3 @@ +export { encodeProto } from "./proto-encode.js"; +export { decodeProto } from "./proto-decode.js"; +//# sourceMappingURL=proto.d.ts.map \ No newline at end of file diff --git a/lib.esm/utils/proto.d.ts.map b/lib.esm/utils/proto.d.ts.map new file mode 100644 index 00000000..e9fcbb65 --- /dev/null +++ b/lib.esm/utils/proto.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"proto.d.ts","sourceRoot":"","sources":["../../src.ts/utils/proto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC"} \ No newline at end of file diff --git a/lib.esm/utils/proto.js b/lib.esm/utils/proto.js new file mode 100644 index 00000000..12a0e075 --- /dev/null +++ b/lib.esm/utils/proto.js @@ -0,0 +1,3 @@ +export { encodeProto } from "./proto-encode.js"; +export { decodeProto } from "./proto-decode.js"; +//# sourceMappingURL=proto.js.map \ No newline at end of file diff --git a/lib.esm/utils/proto.js.map b/lib.esm/utils/proto.js.map new file mode 100644 index 00000000..06369aaf --- /dev/null +++ b/lib.esm/utils/proto.js.map @@ -0,0 +1 @@ +{"version":3,"file":"proto.js","sourceRoot":"","sources":["../../src.ts/utils/proto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC"} \ No newline at end of file diff --git a/lib.esm/utils/rlp-decode.d.ts b/lib.esm/utils/rlp-decode.d.ts new file mode 100644 index 00000000..b77b08b9 --- /dev/null +++ b/lib.esm/utils/rlp-decode.d.ts @@ -0,0 +1,6 @@ +import type { BytesLike, RlpStructuredData } from "./index.js"; +/** + * Decodes %%data%% into the structured data it represents. + */ +export declare function decodeRlp(_data: BytesLike): RlpStructuredData; +//# sourceMappingURL=rlp-decode.d.ts.map \ No newline at end of file diff --git a/lib.esm/utils/rlp-decode.d.ts.map b/lib.esm/utils/rlp-decode.d.ts.map new file mode 100644 index 00000000..458795aa --- /dev/null +++ b/lib.esm/utils/rlp-decode.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"rlp-decode.d.ts","sourceRoot":"","sources":["../../src.ts/utils/rlp-decode.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAwF/D;;GAEG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,GAAG,iBAAiB,CAK7D"} \ No newline at end of file diff --git a/src.ts/utils/rlp-decode.ts b/lib.esm/utils/rlp-decode.js similarity index 73% rename from src.ts/utils/rlp-decode.ts rename to lib.esm/utils/rlp-decode.js index 330ba5cf..c483ce3b 100644 --- a/src.ts/utils/rlp-decode.ts +++ b/lib.esm/utils/rlp-decode.js @@ -1,104 +1,79 @@ //See: https://github.com/ethereum/wiki/wiki/RLP - import { hexlify } from "./data.js"; import { assert, assertArgument } from "./errors.js"; import { getBytes } from "./data.js"; - -import type { BytesLike, RlpStructuredData } from "./index.js"; - - -function hexlifyByte(value: number): string { +function hexlifyByte(value) { let result = value.toString(16); - while (result.length < 2) { result = "0" + result; } + while (result.length < 2) { + result = "0" + result; + } return "0x" + result; } - -function unarrayifyInteger(data: Uint8Array, offset: number, length: number): number { +function unarrayifyInteger(data, offset, length) { let result = 0; for (let i = 0; i < length; i++) { result = (result * 256) + data[offset + i]; } return result; } - -type Decoded = { - result: any; - consumed: number; -}; - -function _decodeChildren(data: Uint8Array, offset: number, childOffset: number, length: number): Decoded { - const result: Array = []; - +function _decodeChildren(data, offset, childOffset, length) { + const result = []; while (childOffset < offset + 1 + length) { const decoded = _decode(data, childOffset); - result.push(decoded.result); - childOffset += decoded.consumed; assert(childOffset <= offset + 1 + length, "child data too short", "BUFFER_OVERRUN", { buffer: data, length, offset }); } - - return {consumed: (1 + length), result: result}; + return { consumed: (1 + length), result: result }; } - // returns { consumed: number, result: Object } -function _decode(data: Uint8Array, offset: number): { consumed: number, result: any } { +function _decode(data, offset) { assert(data.length !== 0, "data too short", "BUFFER_OVERRUN", { buffer: data, length: 0, offset: 1 }); - - const checkOffset = (offset: number) => { + const checkOffset = (offset) => { assert(offset <= data.length, "data short segment too short", "BUFFER_OVERRUN", { buffer: data, length: data.length, offset }); }; - // Array with extra length prefix if (data[offset] >= 0xf8) { const lengthLength = data[offset] - 0xf7; checkOffset(offset + 1 + lengthLength); - const length = unarrayifyInteger(data, offset + 1, lengthLength); checkOffset(offset + 1 + lengthLength + length); - return _decodeChildren(data, offset, offset + 1 + lengthLength, lengthLength + length); - - } else if (data[offset] >= 0xc0) { + } + else if (data[offset] >= 0xc0) { const length = data[offset] - 0xc0; checkOffset(offset + 1 + length); - return _decodeChildren(data, offset, offset + 1, length); - - } else if (data[offset] >= 0xb8) { + } + else if (data[offset] >= 0xb8) { const lengthLength = data[offset] - 0xb7; checkOffset(offset + 1 + lengthLength); - const length = unarrayifyInteger(data, offset + 1, lengthLength); checkOffset(offset + 1 + lengthLength + length); - const result = hexlify(data.slice(offset + 1 + lengthLength, offset + 1 + lengthLength + length)); - return { consumed: (1 + lengthLength + length), result: result } - - } else if (data[offset] >= 0x80) { + return { consumed: (1 + lengthLength + length), result: result }; + } + else if (data[offset] >= 0x80) { const length = data[offset] - 0x80; checkOffset(offset + 1 + length); - const result = hexlify(data.slice(offset + 1, offset + 1 + length)); - return { consumed: (1 + length), result: result } + return { consumed: (1 + length), result: result }; } - return { consumed: 1, result: hexlifyByte(data[offset]) }; } - /** * Decodes %%data%% into the structured data it represents. */ -export function decodeRlp(_data: BytesLike): RlpStructuredData { +export function decodeRlp(_data) { const data = getBytes(_data, "data"); const decoded = _decode(data, 0); assertArgument(decoded.consumed === data.length, "unexpected junk after rlp payload", "data", _data); return decoded.result; } - +//# sourceMappingURL=rlp-decode.js.map \ No newline at end of file diff --git a/lib.esm/utils/rlp-decode.js.map b/lib.esm/utils/rlp-decode.js.map new file mode 100644 index 00000000..fa129b9a --- /dev/null +++ b/lib.esm/utils/rlp-decode.js.map @@ -0,0 +1 @@ +{"version":3,"file":"rlp-decode.js","sourceRoot":"","sources":["../../src.ts/utils/rlp-decode.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAEhD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAKrC,SAAS,WAAW,CAAC,KAAa;IAC9B,IAAI,MAAM,GAAG,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IAChC,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;QAAE,MAAM,GAAG,GAAG,GAAG,MAAM,CAAC;KAAE;IACpD,OAAO,IAAI,GAAG,MAAM,CAAC;AACzB,CAAC;AAED,SAAS,iBAAiB,CAAC,IAAgB,EAAE,MAAc,EAAE,MAAc;IACvE,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE;QAC7B,MAAM,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;KAC9C;IACD,OAAO,MAAM,CAAC;AAClB,CAAC;AAOD,SAAS,eAAe,CAAC,IAAgB,EAAE,MAAc,EAAE,WAAmB,EAAE,MAAc;IAC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MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;QACnC,WAAW,CAAC,MAAM,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC;QAEjC,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,MAAM,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;QACpE,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAA;KACpD;IAED,OAAO,EAAE,QAAQ,EAAE,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC;AAC9D,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,KAAgB;IACtC,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACrC,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IACjC,cAAc,CAAC,OAAO,CAAC,QAAQ,KAAK,IAAI,CAAC,MAAM,EAAE,mCAAmC,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IACrG,OAAO,OAAO,CAAC,MAAM,CAAC;AAC1B,CAAC"} \ No newline at end of file diff --git a/lib.esm/utils/rlp-encode.d.ts b/lib.esm/utils/rlp-encode.d.ts new file mode 100644 index 00000000..089b1c3e --- /dev/null +++ b/lib.esm/utils/rlp-encode.d.ts @@ -0,0 +1,6 @@ +import type { RlpStructuredDataish } from "./rlp.js"; +/** + * Encodes %%object%% as an RLP-encoded [[DataHexString]]. + */ +export declare function encodeRlp(object: RlpStructuredDataish): string; +//# sourceMappingURL=rlp-encode.d.ts.map \ No newline at end of file diff --git a/lib.esm/utils/rlp-encode.d.ts.map b/lib.esm/utils/rlp-encode.d.ts.map new file mode 100644 index 00000000..319163b8 --- /dev/null +++ b/lib.esm/utils/rlp-encode.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"rlp-encode.d.ts","sourceRoot":"","sources":["../../src.ts/utils/rlp-encode.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAiDrD;;GAEG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,oBAAoB,GAAG,MAAM,CAO9D"} \ No newline at end of file diff --git a/src.ts/utils/rlp-encode.ts b/lib.esm/utils/rlp-encode.js similarity index 64% rename from src.ts/utils/rlp-encode.ts rename to lib.esm/utils/rlp-encode.js index a823cbbc..7d6d797d 100644 --- a/src.ts/utils/rlp-encode.ts +++ b/lib.esm/utils/rlp-encode.js @@ -1,60 +1,44 @@ //See: https://github.com/ethereum/wiki/wiki/RLP - import { getBytes } from "./data.js"; - -import type { RlpStructuredDataish } from "./rlp.js"; - - -function arrayifyInteger(value: number): Array { - const result: Array = []; +function arrayifyInteger(value) { + const result = []; while (value) { result.unshift(value & 0xff); value >>= 8; } return result; } - -function _encode(object: Array | string | Uint8Array): Array { +function _encode(object) { if (Array.isArray(object)) { - let payload: Array = []; - object.forEach(function(child) { + let payload = []; + object.forEach(function (child) { payload = payload.concat(_encode(child)); }); - if (payload.length <= 55) { - payload.unshift(0xc0 + payload.length) + payload.unshift(0xc0 + payload.length); return payload; } - const length = arrayifyInteger(payload.length); length.unshift(0xf7 + length.length); - return length.concat(payload); - } - - const data: Array = Array.prototype.slice.call(getBytes(object, "object")); - + const data = Array.prototype.slice.call(getBytes(object, "object")); if (data.length === 1 && data[0] <= 0x7f) { return data; - - } else if (data.length <= 55) { + } + else if (data.length <= 55) { data.unshift(0x80 + data.length); return data; } - const length = arrayifyInteger(data.length); length.unshift(0xb7 + length.length); - return length.concat(data); } - const nibbles = "0123456789abcdef"; - /** * Encodes %%object%% as an RLP-encoded [[DataHexString]]. */ -export function encodeRlp(object: RlpStructuredDataish): string { +export function encodeRlp(object) { let result = "0x"; for (const v of _encode(object)) { result += nibbles[v >> 4]; @@ -62,3 +46,4 @@ export function encodeRlp(object: RlpStructuredDataish): string { } return result; } +//# sourceMappingURL=rlp-encode.js.map \ No newline at end of file diff --git a/lib.esm/utils/rlp-encode.js.map b/lib.esm/utils/rlp-encode.js.map new file mode 100644 index 00000000..3dd6434c --- /dev/null +++ b/lib.esm/utils/rlp-encode.js.map @@ -0,0 +1 @@ +{"version":3,"file":"rlp-encode.js","sourceRoot":"","sources":["../../src.ts/utils/rlp-encode.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAEhD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAKrC,SAAS,eAAe,CAAC,KAAa;IAClC,MAAM,MAAM,GAAkB,EAAE,CAAC;IACjC,OAAO,KAAK,EAAE;QACV,MAAM,CAAC,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;QAC7B,KAAK,KAAK,CAAC,CAAC;KACf;IACD,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,SAAS,OAAO,CAAC,MAAwC;IACrD,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QACvB,IAAI,OAAO,GAAkB,EAAE,CAAC;QAChC,MAAM,CAAC,OAAO,CAAC,UAAS,KAAK;YACzB,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;QAC7C,CAAC,CAAC,CAAC;QAEH,IAAI,OAAO,CAAC,MAAM,IAAI,EAAE,EAAE;YACtB,OAAO,CAAC,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;YACtC,OAAO,OAAO,CAAC;SAClB;QAED,MAAM,MAAM,GAAG,eAAe,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC/C,MAAM,CAAC,OAAO,CAAC,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;QAErC,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;KAEjC;IAED,MAAM,IAAI,GAAkB,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;IAEnF,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE;QACtC,OAAO,IAAI,CAAC;KAEf;SAAM,IAAI,IAAI,CAAC,MAAM,IAAI,EAAE,EAAE;QAC1B,IAAI,CAAC,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;QACjC,OAAO,IAAI,CAAC;KACf;IAED,MAAM,MAAM,GAAG,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC5C,MAAM,CAAC,OAAO,CAAC,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IAErC,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAC/B,CAAC;AAED,MAAM,OAAO,GAAG,kBAAkB,CAAC;AAEnC;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,MAA4B;IAClD,IAAI,MAAM,GAAG,IAAI,CAAC;IAClB,KAAK,MAAM,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,EAAE;QAC7B,MAAM,IAAI,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;QAC1B,MAAM,IAAI,OAAO,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC;KAC9B;IACD,OAAO,MAAM,CAAC;AAClB,CAAC"} \ No newline at end of file diff --git a/src.ts/utils/rlp.ts b/lib.esm/utils/rlp.d.ts similarity index 94% rename from src.ts/utils/rlp.ts rename to lib.esm/utils/rlp.d.ts index 5c6551c4..bdc7e828 100644 --- a/src.ts/utils/rlp.ts +++ b/lib.esm/utils/rlp.d.ts @@ -4,17 +4,14 @@ * * @_subsection api/utils:Recursive-Length Prefix [about-rlp] */ - export { decodeRlp } from "./rlp-decode.js"; export { encodeRlp } from "./rlp-encode.js"; - /** * An RLP-encoded structure. */ export type RlpStructuredData = string | Array; - /** * An RLP-encoded structure, which allows Uint8Array. */ export type RlpStructuredDataish = string | Uint8Array | Array; - +//# sourceMappingURL=rlp.d.ts.map \ No newline at end of file diff --git a/lib.esm/utils/rlp.d.ts.map b/lib.esm/utils/rlp.d.ts.map new file mode 100644 index 00000000..287f5705 --- /dev/null +++ b/lib.esm/utils/rlp.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"rlp.d.ts","sourceRoot":"","sources":["../../src.ts/utils/rlp.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,KAAK,CAAC,iBAAiB,CAAC,CAAC;AAElE;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,MAAM,GAAG,UAAU,GAAG,KAAK,CAAC,oBAAoB,CAAC,CAAC"} \ No newline at end of file diff --git a/lib.esm/utils/rlp.js b/lib.esm/utils/rlp.js new file mode 100644 index 00000000..cffd9f60 --- /dev/null +++ b/lib.esm/utils/rlp.js @@ -0,0 +1,9 @@ +/** + * The [[link-rlp]] (RLP) encoding is used throughout Ethereum + * to serialize nested structures of Arrays and data. + * + * @_subsection api/utils:Recursive-Length Prefix [about-rlp] + */ +export { decodeRlp } from "./rlp-decode.js"; +export { encodeRlp } from "./rlp-encode.js"; +//# sourceMappingURL=rlp.js.map \ No newline at end of file diff --git a/lib.esm/utils/rlp.js.map b/lib.esm/utils/rlp.js.map new file mode 100644 index 00000000..6ad8eda8 --- /dev/null +++ b/lib.esm/utils/rlp.js.map @@ -0,0 +1 @@ +{"version":3,"file":"rlp.js","sourceRoot":"","sources":["../../src.ts/utils/rlp.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC"} \ No newline at end of file diff --git a/lib.esm/utils/shards.d.ts b/lib.esm/utils/shards.d.ts new file mode 100644 index 00000000..23fc8227 --- /dev/null +++ b/lib.esm/utils/shards.d.ts @@ -0,0 +1,57 @@ +/** + * Retrieves the shard information for a given address based on its byte prefix. + * The function parses the address to extract its byte prefix, then filters the ShardData + * to find a matching shard entry. If no matching shard is found, it returns null. + * + * @param {string} address - The blockchain address to be analyzed. The address should + * start with "0x" followed by the hexadecimal representation. + * + * @returns {Object|null} The shard data object corresponding to the address's byte prefix, + * or null if no matching shard is found. + */ +export declare function getShardForAddress(address: string): { + name: string; + nickname: string; + shard: string; + context: number; + byte: string; +} | null; +/** + * Extracts both shard and UTXO information from a given blockchain address. This function + * first determines the address's shard by its byte prefix, then checks the 9th bit of the + * address to ascertain if it's a UTXO or non-UTXO address. + * + * @param {string} address - The blockchain address to be analyzed, expected to start with + * "0x" followed by its hexadecimal representation. + * + * @returns {Object|null} An object containing the shard data and a boolean indicating + * whether the address is a UTXO address, or null if the shard cannot be determined. + */ +export declare function getAddressDetails(address: string): { + shard: { + name: string; + nickname: string; + shard: string; + context: number; + byte: string; + }; + isUTXO: boolean; +} | null; +/** + * @param from address + * @param to adress + * @returns txtype + */ +export declare function getTxType(from: string | null, to: string | null): number; +/** +* Checks whether a given blockchain address is a UTXO address based on the 9th bit of +* the address. This function extracts the second byte of the address and checks its +* first bit to determine the UTXO status. +* +* @param {string} address - The blockchain address to be analyzed, expected to start with +* "0x" followed by its hexadecimal representation. +* +* @returns {boolean} True if the address is a UTXO address, false otherwise. +*/ +export declare function isUTXOAddress(address: string): boolean; +//# sourceMappingURL=shards.d.ts.map \ No newline at end of file diff --git a/lib.esm/utils/shards.d.ts.map b/lib.esm/utils/shards.d.ts.map new file mode 100644 index 00000000..d09f218e --- /dev/null +++ b/lib.esm/utils/shards.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"shards.d.ts","sourceRoot":"","sources":["../../src.ts/utils/shards.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM;;;;;;SAUjD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM;;;;;;;;;SAY9C;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,EAAE,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAaxE;AAGD;;;;;;;;;EASC;AACD,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,WAM9C"} \ No newline at end of file diff --git a/lib.esm/utils/shards.js b/lib.esm/utils/shards.js new file mode 100644 index 00000000..b40aa4c9 --- /dev/null +++ b/lib.esm/utils/shards.js @@ -0,0 +1,80 @@ +import { ShardData } from "../constants/shards.js"; +/** + * Retrieves the shard information for a given address based on its byte prefix. + * The function parses the address to extract its byte prefix, then filters the ShardData + * to find a matching shard entry. If no matching shard is found, it returns null. + * + * @param {string} address - The blockchain address to be analyzed. The address should + * start with "0x" followed by the hexadecimal representation. + * + * @returns {Object|null} The shard data object corresponding to the address's byte prefix, + * or null if no matching shard is found. + */ +export function getShardForAddress(address) { + const addressByte = address.substring(2, 4); + const filteredShards = ShardData.filter((obj) => { + return parseInt(addressByte, 16) === parseInt(obj.byte, 16); + }); + if (filteredShards.length === 0) { + return null; + } + return filteredShards[0]; +} +/** + * Extracts both shard and UTXO information from a given blockchain address. This function + * first determines the address's shard by its byte prefix, then checks the 9th bit of the + * address to ascertain if it's a UTXO or non-UTXO address. + * + * @param {string} address - The blockchain address to be analyzed, expected to start with + * "0x" followed by its hexadecimal representation. + * + * @returns {Object|null} An object containing the shard data and a boolean indicating + * whether the address is a UTXO address, or null if the shard cannot be determined. + */ +export function getAddressDetails(address) { + const addressByte = address.substring(2, 4); + const isUTXO = (parseInt(address.substring(4, 5), 16) & 0x1) === 1; + const filteredShards = ShardData.filter((obj) => { + return parseInt(addressByte, 16) === parseInt(obj.byte, 16); + }); + if (filteredShards.length === 0) { + return null; + } + return { shard: filteredShards[0], isUTXO }; +} +/** + * @param from address + * @param to adress + * @returns txtype + */ +export function getTxType(from, to) { + if (from === null || to === null) + return 0; + const fromUTXO = isUTXOAddress(from); + const toUTXO = isUTXOAddress(to); + switch (true) { + case fromUTXO && toUTXO: + return 2; + case fromUTXO && !toUTXO: + return 2; + default: + return 0; + } +} +/** +* Checks whether a given blockchain address is a UTXO address based on the 9th bit of +* the address. This function extracts the second byte of the address and checks its +* first bit to determine the UTXO status. +* +* @param {string} address - The blockchain address to be analyzed, expected to start with +* "0x" followed by its hexadecimal representation. +* +* @returns {boolean} True if the address is a UTXO address, false otherwise. +*/ +export function isUTXOAddress(address) { + const secondByte = address.substring(4, 6); + const binaryString = parseInt(secondByte, 16).toString(2).padStart(8, '0'); + const isUTXO = binaryString[0] === '1'; + return isUTXO; +} +//# sourceMappingURL=shards.js.map \ No newline at end of file diff --git a/lib.esm/utils/shards.js.map b/lib.esm/utils/shards.js.map new file mode 100644 index 00000000..ec348a62 --- /dev/null +++ b/lib.esm/utils/shards.js.map @@ -0,0 +1 @@ +{"version":3,"file":"shards.js","sourceRoot":"","sources":["../../src.ts/utils/shards.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAe;IAChD,MAAM,WAAW,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC5C,MAAM,cAAc,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE;QAC5C,OAAO,QAAQ,CAAC,WAAW,EAAE,EAAE,CAAC,KAAK,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAChE,CAAC,CAAC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;AACH,CAAC;AAGD;;;;;;;;;EASC;AACD,MAAM,UAAU,aAAa,CAAC,OAAe;IAC3C,MAAM,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC3C,MAAM,YAAY,GAAG,QAAQ,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAC3E,MAAM,MAAM,GAAG,YAAY,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC;IAEvC,OAAO,MAAM,CAAC;AAClB,CAAC"} \ No newline at end of file diff --git a/lib.esm/utils/units.d.ts b/lib.esm/utils/units.d.ts new file mode 100644 index 00000000..0b57e032 --- /dev/null +++ b/lib.esm/utils/units.d.ts @@ -0,0 +1,34 @@ +import type { BigNumberish, Numeric } from "../utils/index.js"; +/** + * Converts %%value%% into a //decimal string//, assuming %%unit%% decimal + * places. The %%unit%% may be the number of decimal places or the name of + * a unit (e.g. ``"gwei"`` for 9 decimal places). + * + */ +export declare function formatUnits(value: BigNumberish, unit?: string | Numeric): string; +/** + * Converts the //decimal string// %%value%% to a BigInt, assuming + * %%unit%% decimal places. The %%unit%% may the number of decimal places + * or the name of a unit (e.g. ``"gwei"`` for 9 decimal places). + */ +export declare function parseUnits(value: string, unit?: string | Numeric): bigint; +/** + * Converts %%value%% into a //decimal string// using 18 decimal places. + */ +export declare function formatQuai(wei: BigNumberish): string; +/** + * Converts %%value%% into a //decimal string// using 3 decimal places. + */ +export declare function formatQi(value: BigNumberish): string; +/** + * Converts the //decimal string// %%quai%% to a BigInt, using 18 + * decimal places. + */ +export declare function parseQuai(ether: string): bigint; +/** + * Converts %%value%% into a //decimal string// using 3 decimal places. + */ +export declare function parseQi(value: string): bigint; +export declare const formatEther: typeof formatQuai; +export declare const parseEther: typeof parseQuai; +//# sourceMappingURL=units.d.ts.map \ No newline at end of file diff --git a/lib.esm/utils/units.d.ts.map b/lib.esm/utils/units.d.ts.map new file mode 100644 index 00000000..90834098 --- /dev/null +++ b/lib.esm/utils/units.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"units.d.ts","sourceRoot":"","sources":["../../src.ts/utils/units.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAa/D;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,YAAY,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM,CAWhF;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM,CAazE;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAEpD;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CAEpD;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7C;AAGD,eAAO,MAAM,WAAW,mBAAa,CAAC;AACtC,eAAO,MAAM,UAAU,kBAAY,CAAC"} \ No newline at end of file diff --git a/lib.esm/utils/units.js b/lib.esm/utils/units.js new file mode 100644 index 00000000..8c23ac0b --- /dev/null +++ b/lib.esm/utils/units.js @@ -0,0 +1,98 @@ +/** + * Most interactions with Ethereum requires integer values, which use + * the smallest magnitude unit. + * + * For example, imagine dealing with dollars and cents. Since dollars + * are divisible, non-integer values are possible, such as ``$10.77``. + * By using the smallest indivisible unit (i.e. cents), the value can + * be kept as the integer ``1077``. + * + * When receiving decimal input from the user (as a decimal string), + * the value should be converted to an integer and when showing a user + * a value, the integer value should be converted to a decimal string. + * + * This creates a clear distinction, between values to be used by code + * (integers) and values used for display logic to users (decimals). + * + * The native unit in Ethereum, //ether// is divisible to 18 decimal places, + * where each individual unit is called a //wei//. + * + * @_subsection api/utils:Unit Conversion [about-units] + */ +import { assertArgument } from "./errors.js"; +import { FixedNumber } from "./fixednumber.js"; +import { getNumber } from "./maths.js"; +const names = [ + "wei", + "kwei", + "mwei", + "gwei", + "szabo", + "finney", + "ether", +]; +/** + * Converts %%value%% into a //decimal string//, assuming %%unit%% decimal + * places. The %%unit%% may be the number of decimal places or the name of + * a unit (e.g. ``"gwei"`` for 9 decimal places). + * + */ +export function formatUnits(value, unit) { + let decimals = 18; + if (typeof (unit) === "string") { + const index = names.indexOf(unit); + assertArgument(index >= 0, "invalid unit", "unit", unit); + decimals = 3 * index; + } + else if (unit != null) { + decimals = getNumber(unit, "unit"); + } + return FixedNumber.fromValue(value, decimals, { decimals, width: 512 }).toString(); +} +/** + * Converts the //decimal string// %%value%% to a BigInt, assuming + * %%unit%% decimal places. The %%unit%% may the number of decimal places + * or the name of a unit (e.g. ``"gwei"`` for 9 decimal places). + */ +export function parseUnits(value, unit) { + assertArgument(typeof (value) === "string", "value must be a string", "value", value); + let decimals = 18; + if (typeof (unit) === "string") { + const index = names.indexOf(unit); + assertArgument(index >= 0, "invalid unit", "unit", unit); + decimals = 3 * index; + } + else if (unit != null) { + decimals = getNumber(unit, "unit"); + } + return FixedNumber.fromString(value, { decimals, width: 512 }).value; +} +/** + * Converts %%value%% into a //decimal string// using 18 decimal places. + */ +export function formatQuai(wei) { + return formatUnits(wei, 18); +} +/** + * Converts %%value%% into a //decimal string// using 3 decimal places. + */ +export function formatQi(value) { + return formatUnits(value, 3); +} +/** + * Converts the //decimal string// %%quai%% to a BigInt, using 18 + * decimal places. + */ +export function parseQuai(ether) { + return parseUnits(ether, 18); +} +/** + * Converts %%value%% into a //decimal string// using 3 decimal places. + */ +export function parseQi(value) { + return parseUnits(value, 3); +} +// Aliases to maintain backwards compatibility. These will be removed in the future. +export const formatEther = formatQuai; +export const parseEther = parseQuai; +//# sourceMappingURL=units.js.map \ No newline at end of file diff --git a/lib.esm/utils/units.js.map b/lib.esm/utils/units.js.map new file mode 100644 index 00000000..51595a51 --- /dev/null +++ b/lib.esm/utils/units.js.map @@ -0,0 +1 @@ +{"version":3,"file":"units.js","sourceRoot":"","sources":["../../src.ts/utils/units.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAKvC,MAAM,KAAK,GAAG;IACV,KAAK;IACL,MAAM;IACN,MAAM;IACN,MAAM;IACN,OAAO;IACP,QAAQ;IACR,OAAO;CACV,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,KAAmB,EAAE,IAAuB;IACpE,IAAI,QAAQ,GAAG,EAAE,CAAC;IAClB,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,QAAQ,EAAE;QAC5B,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAClC,cAAc,CAAC,KAAK,IAAI,CAAC,EAAE,cAAc,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;QACzD,QAAQ,GAAG,CAAC,GAAG,KAAK,CAAC;KACxB;SAAM,IAAI,IAAI,IAAI,IAAI,EAAE;QACrB,QAAQ,GAAG,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;KACtC;IAED,OAAO,WAAW,CAAC,SAAS,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;AACvF,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,KAAa,EAAE,IAAuB;IAC7D,cAAc,CAAC,OAAO,CAAC,KAAK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644 index 00000000..7bb87cc7 --- /dev/null +++ b/lib.esm/utils/utf8.d.ts @@ -0,0 +1,96 @@ +import type { BytesLike } from "./index.js"; +/** + * The stanard normalization forms. + */ +export type UnicodeNormalizationForm = "NFC" | "NFD" | "NFKC" | "NFKD"; +/** + * When using the UTF-8 error API the following errors can be intercepted + * and processed as the %%reason%% passed to the [[Utf8ErrorFunc]]. + * + * **``"UNEXPECTED_CONTINUE"``** - a continuation byte was present where there + * was nothing to continue. + * + * **``"BAD_PREFIX"``** - an invalid (non-continuation) byte to start a + * UTF-8 codepoint was found. + * + * **``"OVERRUN"``** - the string is too short to process the expected + * codepoint length. + * + * **``"MISSING_CONTINUE"``** - a missing continuation byte was expected but + * not found. The %%offset%% indicates the index the continuation byte + * was expected at. + * + * **``"OUT_OF_RANGE"``** - the computed code point is outside the range + * for UTF-8. The %%badCodepoint%% indicates the computed codepoint, which was + * outside the valid UTF-8 range. + * + * **``"UTF16_SURROGATE"``** - the UTF-8 strings contained a UTF-16 surrogate + * pair. The %%badCodepoint%% is the computed codepoint, which was inside the + * UTF-16 surrogate range. + * + * **``"OVERLONG"``** - the string is an overlong representation. The + * %%badCodepoint%% indicates the computed codepoint, which has already + * been bounds checked. + * + * + * @returns string + */ +export type Utf8ErrorReason = "UNEXPECTED_CONTINUE" | "BAD_PREFIX" | "OVERRUN" | "MISSING_CONTINUE" | "OUT_OF_RANGE" | "UTF16_SURROGATE" | "OVERLONG"; +/** + * A callback that can be used with [[toUtf8String]] to analysis or + * recovery from invalid UTF-8 data. + * + * Parsing UTF-8 data is done through a simple Finite-State Machine (FSM) + * which calls the ``Utf8ErrorFunc`` if a fault is detected. + * + * The %%reason%% indicates where in the FSM execution the fault + * occurred and the %%offset%% indicates where the input failed. + * + * The %%bytes%% represents the raw UTF-8 data that was provided and + * %%output%% is the current array of UTF-8 code-points, which may + * be updated by the ``Utf8ErrorFunc``. + * + * The value of the %%badCodepoint%% depends on the %%reason%%. See + * [[Utf8ErrorReason]] for details. + * + * The function should return the number of bytes that should be skipped + * when control resumes to the FSM. + */ +export type Utf8ErrorFunc = (reason: Utf8ErrorReason, offset: number, bytes: Uint8Array, output: Array, badCodepoint?: number) => number; +/** + * A handful of popular, built-in UTF-8 error handling strategies. + * + * **``"error"``** - throws on ANY illegal UTF-8 sequence or + * non-canonical (overlong) codepoints (this is the default) + * + * **``"ignore"``** - silently drops any illegal UTF-8 sequence + * and accepts non-canonical (overlong) codepoints + * + * **``"replace"``** - replace any illegal UTF-8 sequence with the + * UTF-8 replacement character (i.e. ``"\\ufffd"``) and accepts + * non-canonical (overlong) codepoints + * + * @returns: Record<"error" | "ignore" | "replace", Utf8ErrorFunc> + */ +export declare const Utf8ErrorFuncs: Readonly>; +/** + * Returns the UTF-8 byte representation of %%str%%. + * + * If %%form%% is specified, the string is normalized. + */ +export declare function toUtf8Bytes(str: string, form?: UnicodeNormalizationForm): Uint8Array; +/** + * Returns the string represented by the UTF-8 data %%bytes%%. + * + * When %%onError%% function is specified, it is called on UTF-8 + * errors allowing recovery using the [[Utf8ErrorFunc]] API. + * (default: [error](Utf8ErrorFuncs)) + */ +export declare function toUtf8String(bytes: BytesLike, onError?: Utf8ErrorFunc): string; +/** + * Returns the UTF-8 code-points for %%str%%. + * + * If %%form%% is specified, the string is normalized. + */ +export declare function toUtf8CodePoints(str: string, form?: UnicodeNormalizationForm): Array; +//# sourceMappingURL=utf8.d.ts.map \ No newline at end of file diff --git a/lib.esm/utils/utf8.d.ts.map b/lib.esm/utils/utf8.d.ts.map new file mode 100644 index 00000000..650820bd --- /dev/null +++ b/lib.esm/utils/utf8.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"utf8.d.ts","sourceRoot":"","sources":["../../src.ts/utils/utf8.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAK5C;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC;AAEvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,MAAM,eAAe,GAAG,qBAAqB,GAAG,YAAY,GAAG,SAAS,GAC1E,kBAAkB,GAAG,cAAc,GAAG,iBAAiB,GAAG,UAAU,CAAC;AAGzE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE,YAAY,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;AA6CjJ;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC,MAAM,CAAC,OAAO,GAAG,QAAQ,GAAG,SAAS,EAAE,aAAa,CAAC,CAIzF,CAAC;AAsGH;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,wBAAwB,GAAG,UAAU,CAwCpF;AAgBD;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,MAAM,CAE9E;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,wBAAwB,GAAG,KAAK,CAAC,MAAM,CAAC,CAE5F"} \ No newline at end of file diff --git a/lib.esm/utils/utf8.js b/lib.esm/utils/utf8.js new file mode 100644 index 00000000..1adceee4 --- /dev/null +++ b/lib.esm/utils/utf8.js @@ -0,0 +1,220 @@ +/** + * Using strings in Ethereum (or any security-basd system) requires + * additional care. These utilities attempt to mitigate some of the + * safety issues as well as provide the ability to recover and analyse + * strings. + * + * @_subsection api/utils:Strings and UTF-8 [about-strings] + */ +import { getBytes } from "./data.js"; +import { assertArgument, assertNormalize } from "./errors.js"; +function errorFunc(reason, offset, bytes, output, badCodepoint) { + assertArgument(false, `invalid codepoint at offset ${offset}; ${reason}`, "bytes", bytes); +} +function ignoreFunc(reason, offset, bytes, output, badCodepoint) { + // If there is an invalid prefix (including stray continuation), skip any additional continuation bytes + if (reason === "BAD_PREFIX" || reason === "UNEXPECTED_CONTINUE") { + let i = 0; + for (let o = offset + 1; o < bytes.length; o++) { + if (bytes[o] >> 6 !== 0x02) { + break; + } + i++; + } + return i; + } + // This byte runs us past the end of the string, so just jump to the end + // (but the first byte was read already read and therefore skipped) + if (reason === "OVERRUN") { + return bytes.length - offset - 1; + } + // Nothing to skip + return 0; +} +function replaceFunc(reason, offset, bytes, output, badCodepoint) { + // Overlong representations are otherwise "valid" code points; just non-deistingtished + if (reason === "OVERLONG") { + assertArgument(typeof (badCodepoint) === "number", "invalid bad code point for replacement", "badCodepoint", badCodepoint); + output.push(badCodepoint); + return 0; + } + // Put the replacement character into the output + output.push(0xfffd); + // Otherwise, process as if ignoring errors + return ignoreFunc(reason, offset, bytes, output, badCodepoint); +} +/** + * A handful of popular, built-in UTF-8 error handling strategies. + * + * **``"error"``** - throws on ANY illegal UTF-8 sequence or + * non-canonical (overlong) codepoints (this is the default) + * + * **``"ignore"``** - silently drops any illegal UTF-8 sequence + * and accepts non-canonical (overlong) codepoints + * + * **``"replace"``** - replace any illegal UTF-8 sequence with the + * UTF-8 replacement character (i.e. ``"\\ufffd"``) and accepts + * non-canonical (overlong) codepoints + * + * @returns: Record<"error" | "ignore" | "replace", Utf8ErrorFunc> + */ +export const Utf8ErrorFuncs = Object.freeze({ + error: errorFunc, + ignore: ignoreFunc, + replace: replaceFunc +}); +// http://stackoverflow.com/questions/13356493/decode-utf-8-with-javascript#13691499 +function getUtf8CodePoints(_bytes, onError) { + if (onError == null) { + onError = Utf8ErrorFuncs.error; + } + const bytes = getBytes(_bytes, "bytes"); + const result = []; + let i = 0; + // Invalid bytes are ignored + while (i < bytes.length) { + const c = bytes[i++]; + // 0xxx xxxx + if (c >> 7 === 0) { + result.push(c); + continue; + } + // Multibyte; how many bytes left for this character? + let extraLength = null; + let overlongMask = null; + // 110x xxxx 10xx xxxx + if ((c & 0xe0) === 0xc0) { + extraLength = 1; + overlongMask = 0x7f; + // 1110 xxxx 10xx xxxx 10xx xxxx + } + else if ((c & 0xf0) === 0xe0) { + extraLength = 2; + overlongMask = 0x7ff; + // 1111 0xxx 10xx xxxx 10xx xxxx 10xx xxxx + } + else if ((c & 0xf8) === 0xf0) { + extraLength = 3; + overlongMask = 0xffff; + } + else { + if ((c & 0xc0) === 0x80) { + i += onError("UNEXPECTED_CONTINUE", i - 1, bytes, result); + } + else { + i += onError("BAD_PREFIX", i - 1, bytes, result); + } + continue; + } + // Do we have enough bytes in our data? + if (i - 1 + extraLength >= bytes.length) { + i += onError("OVERRUN", i - 1, bytes, result); + continue; + } + // Remove the length prefix from the char + let res = c & ((1 << (8 - extraLength - 1)) - 1); + for (let j = 0; j < extraLength; j++) { + let nextChar = bytes[i]; + // Invalid continuation byte + if ((nextChar & 0xc0) != 0x80) { + i += onError("MISSING_CONTINUE", i, bytes, result); + res = null; + break; + } + ; + res = (res << 6) | (nextChar & 0x3f); + i++; + } + // See above loop for invalid continuation byte + if (res === null) { + continue; + } + // Maximum code point + if (res > 0x10ffff) { + i += onError("OUT_OF_RANGE", i - 1 - extraLength, bytes, result, res); + continue; + } + // Reserved for UTF-16 surrogate halves + if (res >= 0xd800 && res <= 0xdfff) { + i += onError("UTF16_SURROGATE", i - 1 - extraLength, bytes, result, res); + continue; + } + // Check for overlong sequences (more bytes than needed) + if (res <= overlongMask) { + i += onError("OVERLONG", i - 1 - extraLength, bytes, result, res); + continue; + } + result.push(res); + } + return result; +} +// http://stackoverflow.com/questions/18729405/how-to-convert-utf8-string-to-byte-array +/** + * Returns the UTF-8 byte representation of %%str%%. + * + * If %%form%% is specified, the string is normalized. + */ +export function toUtf8Bytes(str, form) { + if (form != null) { + assertNormalize(form); + str = str.normalize(form); + } + let result = []; + for (let i = 0; i < str.length; i++) { + const c = str.charCodeAt(i); + if (c < 0x80) { + result.push(c); + } + else if (c < 0x800) { + result.push((c >> 6) | 0xc0); + result.push((c & 0x3f) | 0x80); + } + else if ((c & 0xfc00) == 0xd800) { + i++; + const c2 = str.charCodeAt(i); + assertArgument(i < str.length && ((c2 & 0xfc00) === 0xdc00), "invalid surrogate pair", "str", str); + // Surrogate Pair + const pair = 0x10000 + ((c & 0x03ff) << 10) + (c2 & 0x03ff); + result.push((pair >> 18) | 0xf0); + result.push(((pair >> 12) & 0x3f) | 0x80); + result.push(((pair >> 6) & 0x3f) | 0x80); + result.push((pair & 0x3f) | 0x80); + } + else { + result.push((c >> 12) | 0xe0); + result.push(((c >> 6) & 0x3f) | 0x80); + result.push((c & 0x3f) | 0x80); + } + } + return new Uint8Array(result); +} +; +//export +function _toUtf8String(codePoints) { + return codePoints.map((codePoint) => { + if (codePoint <= 0xffff) { + return String.fromCharCode(codePoint); + } + codePoint -= 0x10000; + return String.fromCharCode((((codePoint >> 10) & 0x3ff) + 0xd800), ((codePoint & 0x3ff) + 0xdc00)); + }).join(""); +} +/** + * Returns the string represented by the UTF-8 data %%bytes%%. + * + * When %%onError%% function is specified, it is called on UTF-8 + * errors allowing recovery using the [[Utf8ErrorFunc]] API. + * (default: [error](Utf8ErrorFuncs)) + */ +export function toUtf8String(bytes, onError) { + return _toUtf8String(getUtf8CodePoints(bytes, onError)); +} +/** + * Returns the UTF-8 code-points for %%str%%. + * + * If %%form%% is specified, the string is normalized. + */ +export function toUtf8CodePoints(str, form) { + return getUtf8CodePoints(toUtf8Bytes(str, form)); +} +//# sourceMappingURL=utf8.js.map \ No newline at end of file diff --git a/lib.esm/utils/utf8.js.map b/lib.esm/utils/utf8.js.map new file mode 100644 index 00000000..5d1c6190 --- /dev/null +++ b/lib.esm/utils/utf8.js.map @@ -0,0 +1 @@ +{"version":3,"file":"utf8.js","sourceRoot":"","sources":["../../src.ts/utils/utf8.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAC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IAAI,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;YAC9B,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;YACtC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;SAClC;KACJ;IAED,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;AAClC,CAAC;AAAA,CAAC;AAEF,SAAS;AACT,SAAS,aAAa,CAAC,UAAyB;IAC5C,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE;QAChC,IAAI,SAAS,IAAI,MAAM,EAAE;YACrB,OAAO,MAAM,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;SACzC;QACD,SAAS,IAAI,OAAO,CAAC;QACrB,OAAO,MAAM,CAAC,YAAY,CACtB,CAAC,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,GAAG,KAAK,CAAC,GAAG,MAAM,CAAC,EACtC,CAAC,CAAC,SAAS,GAAG,KAAK,CAAC,GAAG,MAAM,CAAC,CACjC,CAAC;IACN,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAChB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,KAAgB,EAAE,OAAuB;IAClE,OAAO,aAAa,CAAC,iBAAiB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;AAC5D,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAW,EAAE,IAA+B;IACzE,OAAO,iBAAiB,CAAC,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;AACrD,CAAC"} \ No newline at end of file diff --git a/lib.esm/utils/uuid.d.ts b/lib.esm/utils/uuid.d.ts new file mode 100644 index 00000000..7b746515 --- /dev/null +++ b/lib.esm/utils/uuid.d.ts @@ -0,0 +1,8 @@ +import type { BytesLike } from "./index.js"; +/** + * Returns the version 4 [[link-uuid]] for the %%randomBytes%%. + * + * @see: https://www.ietf.org/rfc/rfc4122.txt (Section 4.4) + */ +export declare function uuidV4(randomBytes: BytesLike): string; +//# sourceMappingURL=uuid.d.ts.map \ No newline at end of file diff --git a/lib.esm/utils/uuid.d.ts.map b/lib.esm/utils/uuid.d.ts.map new file mode 100644 index 00000000..f3cf307c --- /dev/null +++ b/lib.esm/utils/uuid.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"uuid.d.ts","sourceRoot":"","sources":["../../src.ts/utils/uuid.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,WAAW,EAAE,SAAS,GAAG,MAAM,CAqBrD"} \ No newline at end of file diff --git a/lib.esm/utils/uuid.js b/lib.esm/utils/uuid.js new file mode 100644 index 00000000..a6a45955 --- /dev/null +++ b/lib.esm/utils/uuid.js @@ -0,0 +1,30 @@ +/** + * Explain UUID and link to RFC here. + * + * @_subsection: api/utils:UUID [about-uuid] + */ +import { getBytes, hexlify } from "./data.js"; +/** + * Returns the version 4 [[link-uuid]] for the %%randomBytes%%. + * + * @see: https://www.ietf.org/rfc/rfc4122.txt (Section 4.4) + */ +export function uuidV4(randomBytes) { + const bytes = getBytes(randomBytes, "randomBytes"); + // Section: 4.1.3: + // - time_hi_and_version[12:16] = 0b0100 + bytes[6] = (bytes[6] & 0x0f) | 0x40; + // Section 4.4 + // - clock_seq_hi_and_reserved[6] = 0b0 + // - clock_seq_hi_and_reserved[7] = 0b1 + bytes[8] = (bytes[8] & 0x3f) | 0x80; + const value = hexlify(bytes); + return [ + value.substring(2, 10), + value.substring(10, 14), + value.substring(14, 18), + value.substring(18, 22), + value.substring(22, 34), + ].join("-"); +} +//# sourceMappingURL=uuid.js.map \ No newline at end of file diff --git a/lib.esm/utils/uuid.js.map b/lib.esm/utils/uuid.js.map new file mode 100644 index 00000000..cd02033b --- /dev/null +++ b/lib.esm/utils/uuid.js.map @@ -0,0 +1 @@ +{"version":3,"file":"uuid.js","sourceRoot":"","sources":["../../src.ts/utils/uuid.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAI9C;;;;GAIG;AACH,MAAM,UAAU,MAAM,CAAC,WAAsB;IACzC,MAAM,KAAK,GAAG,QAAQ,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;IAEnD,kBAAkB;IAClB,wCAAwC;IACxC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;IAEpC,cAAc;IACd,uCAAuC;IACvC,uCAAuC;IACvC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;IAEpC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;IAE7B,OAAO;QACJ,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC;QACtB,KAAK,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,CAAC;QACvB,KAAK,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,CAAC;QACvB,KAAK,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,CAAC;QACvB,KAAK,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,CAAC;KACzB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAChB,CAAC"} \ No newline at end of file diff --git a/lib.esm/wallet/base-crypto.d.ts b/lib.esm/wallet/base-crypto.d.ts new file mode 100644 index 00000000..f2245a4c --- /dev/null +++ b/lib.esm/wallet/base-crypto.d.ts @@ -0,0 +1,14 @@ +export declare function readScalar(bytes: Uint8Array): bigint; +export declare function readSecret(bytes: Uint8Array): bigint; +export declare function isPoint(p: Uint8Array): boolean; +export declare function isXOnlyPoint(p: Uint8Array): boolean; +export declare function scalarAdd(a: Uint8Array, b: Uint8Array): Uint8Array; +export declare function scalarMultiply(a: Uint8Array, b: Uint8Array): Uint8Array; +export declare function scalarNegate(a: Uint8Array): Uint8Array; +export declare function scalarMod(a: Uint8Array): Uint8Array; +export declare function isScalar(t: Uint8Array): boolean; +export declare function isSecret(s: Uint8Array): boolean; +export declare function pointNegate(p: Uint8Array): Uint8Array; +export declare function pointX(p: Uint8Array): Uint8Array; +export declare function hasEvenY(p: Uint8Array): boolean; +//# sourceMappingURL=base-crypto.d.ts.map \ No newline at end of file diff --git a/lib.esm/wallet/base-crypto.d.ts.map b/lib.esm/wallet/base-crypto.d.ts.map new file mode 100644 index 00000000..88f48984 --- /dev/null +++ b/lib.esm/wallet/base-crypto.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"base-crypto.d.ts","sourceRoot":"","sources":["../../src.ts/wallet/base-crypto.ts"],"names":[],"mappings":"AA0CA,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAIpD;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAIpD;AAkCD,wBAAgB,OAAO,CAAC,CAAC,EAAE,UAAU,GAAG,OAAO,CAqB9C;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,UAAU,GAAG,OAAO,CAOnD;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,UAAU,CAKlE;AAED,wBAAgB,cAAc,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,UAAU,CAKvE;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,UAAU,GAAG,UAAU,CAItD;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,UAAU,GAAG,UAAU,CAInD;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,UAAU,GAAG,OAAO,CAO/C;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,UAAU,GAAG,OAAO,CAO/C;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,UAAU,GAAG,UAAU,CAcrD;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,UAAU,GAAG,UAAU,CAIhD;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,UAAU,GAAG,OAAO,CAW/C"} \ No newline at end of file diff --git a/lib.esm/wallet/base-crypto.js b/lib.esm/wallet/base-crypto.js new file mode 100644 index 00000000..478442a8 --- /dev/null +++ b/lib.esm/wallet/base-crypto.js @@ -0,0 +1,198 @@ +// BigInt / Uint8Array versions of Crypto functions that do not require point +// math. If your JS interpreter has BigInt, you can use all of these. If not, +// you'll need to either shim it in or override more of these functions. +// Idea from noble-secp256k1, be nice to bad JS parsers +const _0n = BigInt(0); +const _1n = BigInt(1); +const _2n = BigInt(2); +const _3n = BigInt(3); +const _5n = BigInt(5); +const _7n = BigInt(7); +const _64n = BigInt(64); +const _64mask = BigInt('0xFFFFFFFFFFFFFFFF'); +const CURVE = { + b: BigInt(7), + P: BigInt('0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F'), + n: BigInt('0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141'), +}; +// Big Endian +function read32b(bytes) { + if (bytes.length !== 32) + throw new Error(`Expected 32-bytes, not ${bytes.length}`); + const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.length); + let b = view.getBigUint64(0); + for (let offs = 8; offs < bytes.length; offs += 8) { + b <<= _64n; + b += view.getBigUint64(offs); + } + return b; +} +function write32b(num, dest = new Uint8Array(32)) { + // All input values are modulo P or n, so no bounds checking needed + const view = new DataView(dest.buffer, dest.byteOffset, dest.length); + for (let offs = 24; offs >= 0; offs -= 8) { + view.setBigUint64(offs, num & _64mask); + num >>= _64n; + } + return dest; +} +export function readScalar(bytes) { + const a = read32b(bytes); + if (a >= CURVE.n) + throw new Error('Expected value mod n'); + return a; +} +export function readSecret(bytes) { + const a = readScalar(bytes); + if (a === 0n) + throw new Error('Expected non-zero'); + return a; +} +// The short Weierstrass form curve equation simplifes to y^2 = x^3 + 7. +function secp256k1Right(x) { + const x2 = (x * x) % CURVE.P; + const x3 = (x2 * x) % CURVE.P; + return (x3 + CURVE.b) % CURVE.P; +} +// For prime P, the Jacobi Symbol of 'a' is 1 if and only if 'a' is a quadratic +// residue mod P, ie. there exists a value 'x' for whom x^2 = a. +function jacobiSymbol(a) { + if (a === _0n) + return 0; // Vanishingly improbable + let p = CURVE.P; + let sign = 1; + // This algorithm is fairly heavily optimized, so don't simplify it w/o benchmarking + for (;;) { + let and3; + // Handle runs of zeros efficiently w/o flipping sign each time + for (and3 = a & _3n; and3 === _0n; a >>= _2n, and3 = a & _3n) + ; + // If there's one more zero, shift it off and flip the sign + if (and3 === _2n) { + a >>= _1n; + const pand7 = p & _7n; + if (pand7 === _3n || pand7 === _5n) + sign = -sign; + } + if (a === _1n) + break; + if ((_3n & a) === _3n && (_3n & p) === _3n) + sign = -sign; + [a, p] = [p % a, a]; + } + return sign > 0 ? 1 : -1; +} +export function isPoint(p) { + if (p.length < 33) + return false; + const t = p[0]; + if (p.length === 33) { + return (t === 0x02 || t === 0x03) && isXOnlyPoint(p.subarray(1)); + } + if (t !== 0x04 || p.length !== 65) + return false; + const x = read32b(p.subarray(1, 33)); + if (x === _0n) + return false; + if (x >= CURVE.P) + return false; + const y = read32b(p.subarray(33)); + if (y === _0n) + return false; + if (y >= CURVE.P) + return false; + const left = (y * y) % CURVE.P; + const right = secp256k1Right(x); + return left === right; +} +export function isXOnlyPoint(p) { + if (p.length !== 32) + return false; + const x = read32b(p); + if (x === _0n) + return false; + if (x >= CURVE.P) + return false; + const y2 = secp256k1Right(x); + return jacobiSymbol(y2) === 1; // If sqrt(y^2) exists, x is on the curve. +} +export function scalarAdd(a, b) { + const aN = readScalar(a); + const bN = readScalar(b); + const sum = (aN + bN) % CURVE.n; + return write32b(sum); +} +export function scalarMultiply(a, b) { + const aN = readScalar(a); + const bN = readScalar(b); + const product = (aN * bN) % CURVE.n; + return write32b(product); +} +export function scalarNegate(a) { + const aN = readScalar(a); + const negated = aN === _0n ? _0n : CURVE.n - aN; + return write32b(negated); +} +export function scalarMod(a) { + const aN = read32b(a); + const remainder = aN % CURVE.n; + return write32b(remainder); +} +export function isScalar(t) { + try { + readScalar(t); + return true; + } + catch { + return false; + } +} +export function isSecret(s) { + try { + readSecret(s); + return true; + } + catch { + return false; + } +} +export function pointNegate(p) { + // hasEvenY does basic structure check, so start there + const even = hasEvenY(p); + // `from` because node.Buffer.slice doesn't copy but looks like a Uint8Array + const negated = Uint8Array.from(p); + if (p.length === 33) { + negated[0] = even ? 3 : 2; + } + else if (p.length === 65) { + const y = read32b(p.subarray(33)); + if (y >= CURVE.P) + throw new Error('Expected Y coordinate mod P'); + const minusY = y === _0n ? _0n : CURVE.P - y; + write32b(minusY, negated.subarray(33)); + } + return negated; +} +export function pointX(p) { + if (p.length === 32) + return p; + hasEvenY(p); // hasEvenY throws if not well structured + return p.slice(1, 33); +} +export function hasEvenY(p) { + if (p.length === 33) { + if (p[0] === 2) + return true; + else if (p[0] === 3) + return false; + else + throw new Error('Wrong first byte to be a point'); + } + if (p.length === 65) { + if (p[0] !== 4) + throw new Error('Wrong first byte to be point'); + return p[64] % 2 === 0; + } + throw new Error('Wrong length to be a point'); +} +//# sourceMappingURL=base-crypto.js.map \ No newline at end of file diff --git a/lib.esm/wallet/base-crypto.js.map b/lib.esm/wallet/base-crypto.js.map new file mode 100644 index 00000000..fd04ace2 --- /dev/null +++ b/lib.esm/wallet/base-crypto.js.map @@ -0,0 +1 @@ +{"version":3,"file":"base-crypto.js","sourceRoot":"","sources":["../../src.ts/wallet/base-crypto.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,6EAA6E;AAC7E,wEAA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AC,CAAC,CAAC,CAAC,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;aACvB,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;;YAC7B,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;KACxD;IACD,IAAI,CAAC,CAAC,MAAM,KAAK,EAAE,EAAE;QACnB,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;QAChE,OAAO,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;KACxB;IACD,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;AAChD,CAAC"} \ No newline at end of file diff --git a/lib.esm/wallet/base-wallet.d.ts b/lib.esm/wallet/base-wallet.d.ts new file mode 100644 index 00000000..9b44701c --- /dev/null +++ b/lib.esm/wallet/base-wallet.d.ts @@ -0,0 +1,48 @@ +import { AbstractSigner } from "../providers/index.js"; +import type { SigningKey } from "../crypto/index.js"; +import type { TypedDataDomain, TypedDataField } from "../hash/index.js"; +import type { Provider, TransactionRequest } from "../providers/index.js"; +/** + * The **BaseWallet** is a stream-lined implementation of a + * [[Signer]] that operates with a private key. + * + * It is preferred to use the [[Wallet]] class, as it offers + * additional functionality and simplifies loading a variety + * of JSON formats, Mnemonic Phrases, etc. + * + * This class may be of use for those attempting to implement + * a minimal Signer. + */ +export declare class BaseWallet extends AbstractSigner { + #private; + /** + * Creates a new BaseWallet for %%privateKey%%, optionally + * connected to %%provider%%. + * + * If %%provider%% is not specified, only offline methods can + * be used. + */ + constructor(privateKey: SigningKey, provider?: null | Provider); + /** + * The address of this wallet. + */ + get address(): string; + /** + * The [[SigningKey]] used for signing payloads. + */ + get signingKey(): SigningKey; + /** + * The private key for this wallet. + */ + get privateKey(): string; + getAddress(): Promise; + connect(provider: null | Provider): BaseWallet; + signTransaction(tx: TransactionRequest): Promise; + signMessage(message: string | Uint8Array): Promise; + /** + * Returns the signature for %%message%% signed with this wallet. + */ + signMessageSync(message: string | Uint8Array): string; + signTypedData(domain: TypedDataDomain, types: Record>, value: Record): Promise; +} +//# sourceMappingURL=base-wallet.d.ts.map \ No newline at end of file diff --git a/lib.esm/wallet/base-wallet.d.ts.map b/lib.esm/wallet/base-wallet.d.ts.map new file mode 100644 index 00000000..d8255ef7 --- /dev/null +++ b/lib.esm/wallet/base-wallet.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"base-wallet.d.ts","sourceRoot":"","sources":["../../src.ts/wallet/base-wallet.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAMvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,KAAK,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAG1E;;;;;;;;;;GAUG;AACH,qBAAa,UAAW,SAAQ,cAAc;;IAQ1C;;;;;;OAMG;gBACS,UAAU,EAAE,UAAU,EAAE,QAAQ,CAAC,EAAE,IAAI,GAAG,QAAQ;IAa9D;;OAEG;IACH,IAAI,OAAO,IAAI,MAAM,CAA0B;IAG/C;;OAEG;IACH,IAAI,UAAU,IAAI,UAAU,CAA6B;IAEzD;;OAEG;IACH,IAAI,UAAU,IAAI,MAAM,CAAuC;IAEzD,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAEnC,OAAO,CAAC,QAAQ,EAAE,IAAI,GAAG,QAAQ,GAAG,UAAU;IAIxC,eAAe,CAAC,EAAE,EAAE,kBAAkB,GAAI,OAAO,CAAC,MAAM,CAAC;IAwBzD,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC;IAMhE;;OAEG;IACH,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,GAAG,MAAM;IAI/C,aAAa,CAAC,MAAM,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;CAG1I"} \ No newline at end of file diff --git a/lib.esm/wallet/base-wallet.js b/lib.esm/wallet/base-wallet.js new file mode 100644 index 00000000..e4813217 --- /dev/null +++ b/lib.esm/wallet/base-wallet.js @@ -0,0 +1,90 @@ +import { getAddress, resolveAddress } from "../address/index.js"; +import { hashMessage, TypedDataEncoder } from "../hash/index.js"; +import { AbstractSigner } from "../providers/index.js"; +import { computeAddress, Transaction } from "../transaction/index.js"; +import { resolveProperties, assertArgument } from "../utils/index.js"; +/** + * The **BaseWallet** is a stream-lined implementation of a + * [[Signer]] that operates with a private key. + * + * It is preferred to use the [[Wallet]] class, as it offers + * additional functionality and simplifies loading a variety + * of JSON formats, Mnemonic Phrases, etc. + * + * This class may be of use for those attempting to implement + * a minimal Signer. + */ +export class BaseWallet extends AbstractSigner { + /** + * The wallet address. + */ + #address; + #signingKey; + /** + * Creates a new BaseWallet for %%privateKey%%, optionally + * connected to %%provider%%. + * + * If %%provider%% is not specified, only offline methods can + * be used. + */ + constructor(privateKey, provider) { + super(provider); + assertArgument(privateKey && typeof (privateKey.sign) === "function", "invalid private key", "privateKey", "[ REDACTED ]"); + this.#signingKey = privateKey; + this.#address = computeAddress(this.signingKey.publicKey); + } + // Store private values behind getters to reduce visibility + // in console.log + /** + * The address of this wallet. + */ + get address() { return this.#address; } + /** + * The [[SigningKey]] used for signing payloads. + */ + get signingKey() { return this.#signingKey; } + /** + * The private key for this wallet. + */ + get privateKey() { return this.signingKey.privateKey; } + async getAddress() { return this.#address; } + connect(provider) { + return new BaseWallet(this.#signingKey, provider); + } + async signTransaction(tx) { + // Replace any Addressable or ENS name with an address + const { to, from } = await resolveProperties({ + to: (tx.to ? resolveAddress(tx.to) : undefined), + from: (tx.from ? resolveAddress(tx.from) : undefined) + }); + if (to != null) { + tx.to = to; + } + if (from != null) { + tx.from = from; + } + if (tx.from != null) { + assertArgument(getAddress((tx.from)) === this.#address, "transaction from address mismatch", "tx.from", tx.from); + // delete tx.from; + } + // Build the transaction + const btx = Transaction.from(tx); + btx.signature = this.signingKey.sign(btx.unsignedHash); + return btx.serialized; + } + async signMessage(message) { + return this.signMessageSync(message); + } + // @TODO: Add a secialized signTx and signTyped sync that enforces + // all parameters are known? + /** + * Returns the signature for %%message%% signed with this wallet. + */ + signMessageSync(message) { + return this.signingKey.sign(hashMessage(message)).serialized; + } + async signTypedData(domain, types, value) { + return this.signingKey.sign(TypedDataEncoder.hash(domain, types, value)).serialized; + } +} +//# sourceMappingURL=base-wallet.js.map \ No newline at end of file diff --git a/lib.esm/wallet/base-wallet.js.map b/lib.esm/wallet/base-wallet.js.map new file mode 100644 index 00000000..653fc1d7 --- /dev/null +++ b/lib.esm/wallet/base-wallet.js.map @@ -0,0 +1 @@ +{"version":3,"file":"base-wallet.js","sourceRoot":"","sources":["../../src.ts/wallet/base-wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,EACF,iBAAiB,EAAE,cAAc,EACrC,MAAM,mBAAmB,CAAC;AAO3B;;;;;;;;;;GAUG;AACH,MAAM,OAAO,UAAW,SAAQ,cAAc;IAC1C;;OAEG;IACM,QAAQ,CAAU;IAElB,WAAW,CAAa;IAEjC;;;;;;OAMG;IACH,YAAY,UAAsB,EAAE,QAA0B;QAC1D,KAAK,C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AAC;SAAE;QAC/B,IAAI,IAAI,IAAI,IAAI,EAAE;YAAE,EAAE,CAAC,IAAI,GAAG,IAAI,CAAC;SAAE;QAErC,IAAI,EAAE,CAAC,IAAI,IAAI,IAAI,EAAE;YACjB,cAAc,CAAC,UAAU,CAAS,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC,QAAQ,EAC1D,mCAAmC,EAAE,SAAS,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;YACzE,6BAA6B;SACpB;QAED,wBAAwB;QACxB,MAAM,GAAG,GAAG,WAAW,CAAC,IAAI,CAA0B,EAAE,CAAC,CAAC;QAC1D,GAAG,CAAC,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QAEvD,OAAO,GAAG,CAAC,UAAU,CAAC;IAC1B,CAAC;IAGD,KAAK,CAAC,WAAW,CAAC,OAA4B;QAC1C,OAAO,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC;IAED,kEAAkE;IAClE,4BAA4B;IAC5B;;OAEG;IACH,eAAe,CAAC,OAA4B;QACxC,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC;IACjE,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,MAAuB,EAAE,KAA4C,EAAE,KAA0B;QACjH,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC;IACxF,CAAC;CACJ"} \ No newline at end of file diff --git a/lib.esm/wallet/hdwallet.d.ts b/lib.esm/wallet/hdwallet.d.ts new file mode 100644 index 00000000..24d029b1 --- /dev/null +++ b/lib.esm/wallet/hdwallet.d.ts @@ -0,0 +1,268 @@ +/** + * Explain HD Wallets.. + * + * @_subsection: api/wallet:HD Wallets [hd-wallets] + */ +import { SigningKey } from "../crypto/index.js"; +import { VoidSigner } from "../providers/index.js"; +import { BaseWallet } from "./base-wallet.js"; +import { Mnemonic } from "./mnemonic.js"; +import type { ProgressCallback } from "../crypto/index.js"; +import type { Provider } from "../providers/index.js"; +import type { BytesLike, Numeric } from "../utils/index.js"; +import type { Wordlist } from "../wordlists/index.js"; +/** + * An **HDNodeWallet** is a [[Signer]] backed by the private key derived + * from an HD Node using the [[link-bip-32]] stantard. + * + * An HD Node forms a hierarchal structure with each HD Node having a + * private key and the ability to derive child HD Nodes, defined by + * a path indicating the index of each child. + */ +export declare class HDNodeWallet extends BaseWallet { + #private; + /** + * The fingerprint. + * + * A fingerprint allows quick qay to detect parent and child nodes, + * but developers should be prepared to deal with collisions as it + * is only 4 bytes. + */ + readonly fingerprint: string; + /** + * The parent fingerprint. + */ + readonly accountFingerprint: string; + /** + * The mnemonic used to create this HD Node, if available. + * + * Sources such as extended keys do not encode the mnemonic, in + * which case this will be ``null``. + */ + readonly mnemonic: null | Mnemonic; + /** + * The chaincode, which is effectively a public key used + * to derive children. + */ + readonly chainCode: string; + /** + * The derivation path of this wallet. + * + * Since extended keys do not provider full path details, this + * may be ``null``, if instantiated from a source that does not + * enocde it. + */ + readonly path: null | string; + /** + * The child index of this wallet. Values over ``2 *\* 31`` indicate + * the node is hardened. + */ + readonly index: number; + /** + * The depth of this wallet, which is the number of components + * in its path. + */ + readonly depth: number; + coinType?: number; + /** + * @private + */ + constructor(guard: any, signingKey: SigningKey, accountFingerprint: string, chainCode: string, path: null | string, index: number, depth: number, mnemonic: null | Mnemonic, provider: null | Provider); + connect(provider: null | Provider): HDNodeWallet; + /** + * Resolves to a [JSON Keystore Wallet](json-wallets) encrypted with + * %%password%%. + * + * If %%progressCallback%% is specified, it will receive periodic + * updates as the encryption process progreses. + */ + encrypt(password: Uint8Array | string, progressCallback?: ProgressCallback): Promise; + /** + * Returns a [JSON Keystore Wallet](json-wallets) encryped with + * %%password%%. + * + * It is preferred to use the [async version](encrypt) instead, + * which allows a [[ProgressCallback]] to keep the user informed. + * + * This method will block the event loop (freezing all UI) until + * it is complete, which may be a non-trivial duration. + */ + encryptSync(password: Uint8Array | string): string; + /** + * The extended key. + * + * This key will begin with the prefix ``xpriv`` and can be used to + * reconstruct this HD Node to derive its children. + */ + get extendedKey(): string; + /** + * Gets the current publicKey + */ + get publicKey(): string; + /** + * Returns true if this wallet has a path, providing a Type Guard + * that the path is non-null. + */ + hasPath(): this is { + path: string; + }; + /** + * Returns a neutered HD Node, which removes the private details + * of an HD Node. + * + * A neutered node has no private key, but can be used to derive + * child addresses and other public data about the HD Node. + */ + neuter(): HDNodeVoidWallet; + /** + * Return the child for %%index%%. + */ + deriveChild(_index: Numeric): HDNodeWallet; + /** + * Return the HDNode for %%path%% from this node. + */ + derivePath(path: string): HDNodeWallet; + setCoinType(): void; + /** + * Creates a new HD Node from %%extendedKey%%. + * + * If the %%extendedKey%% will either have a prefix or ``xpub`` or + * ``xpriv``, returning a neutered HD Node ([[HDNodeVoidWallet]]) + * or full HD Node ([[HDNodeWallet) respectively. + */ + static fromExtendedKey(extendedKey: string): HDNodeWallet | HDNodeVoidWallet; + /** + * Creates a new random HDNode. + */ + static createRandom(path: string, password?: string, wordlist?: Wordlist): HDNodeWallet; + /** + * Create an HD Node from %%mnemonic%%. + */ + static fromMnemonic(mnemonic: Mnemonic, path: string): HDNodeWallet; + /** + * Creates an HD Node from a mnemonic %%phrase%%. + */ + static fromPhrase(phrase: string, path: string, password?: string, wordlist?: Wordlist): HDNodeWallet; + /** + * Checks if the provided BIP44 path is valid and limited to the change level. + * @param path The BIP44 path to check. + * @returns true if the path is valid and does not include the address_index; false otherwise. + */ + static isValidPath(path: string): boolean; + /** + * Creates an HD Node from a %%seed%%. + */ + static fromSeed(seed: BytesLike): HDNodeWallet; + /** + * Derives address by incrementing address_index according to BIP44 + */ + deriveAddress(index: number, zone?: string): HDNodeWallet; +} +/** + * A **HDNodeVoidWallet** cannot sign, but provides access to + * the children nodes of a [[link-bip-32]] HD wallet addresses. + * + * The can be created by using an extended ``xpub`` key to + * [[HDNodeWallet_fromExtendedKey]] or by + * [nuetering](HDNodeWallet-neuter) a [[HDNodeWallet]]. + */ +export declare class HDNodeVoidWallet extends VoidSigner { + /** + * The compressed public key. + */ + readonly publicKey: string; + /** + * The fingerprint. + * + * A fingerprint allows quick qay to detect parent and child nodes, + * but developers should be prepared to deal with collisions as it + * is only 4 bytes. + */ + readonly fingerprint: string; + /** + * The parent node fingerprint. + */ + readonly accountFingerprint: string; + /** + * The chaincode, which is effectively a public key used + * to derive children. + */ + readonly chainCode: string; + /** + * The derivation path of this wallet. + * + * Since extended keys do not provider full path details, this + * may be ``null``, if instantiated from a source that does not + * enocde it. + */ + readonly path: null | string; + /** + * The child index of this wallet. Values over ``2 *\* 31`` indicate + * the node is hardened. + */ + readonly index: number; + /** + * The depth of this wallet, which is the number of components + * in its path. + */ + readonly depth: number; + /** + * @private + */ + constructor(guard: any, address: string, publicKey: string, accountFingerprint: string, chainCode: string, path: null | string, index: number, depth: number, provider: null | Provider); + connect(provider: null | Provider): HDNodeVoidWallet; + /** + * The extended key. + * + * This key will begin with the prefix ``xpub`` and can be used to + * reconstruct this neutered key to derive its children addresses. + */ + get extendedKey(): string; + /** + * Returns true if this wallet has a path, providing a Type Guard + * that the path is non-null. + */ + hasPath(): this is { + path: string; + }; + /** + * Return the child for %%index%%. + */ + deriveChild(_index: Numeric): HDNodeVoidWallet; + /** + * Return the signer for %%path%% from this node. + */ + derivePath(path: string): HDNodeVoidWallet; +} +/** + * Returns the [[link-bip-32]] path for the account at %%index%%. + * + * This is the pattern used by wallets like Ledger. + * + * There is also an [alternate pattern](getIndexedAccountPath) used by + * some software. + */ +export declare function getAccountPath(_index: Numeric): string; +/** + * Returns the path using an alternative pattern for deriving accounts, + * at %%index%%. + * + * This derivation path uses the //index// component rather than the + * //account// component to derive sequential accounts. + * + * This is the pattern used by wallets like MetaMask. + */ +export declare function getIndexedAccountPath(_index: Numeric): string; +/** + * Returns a derivation path for a Qi blockchain account. + * @param {number} account - The account index (defaults to 0). + * @returns {string} The BIP44 derivation path for the specified account on the Qi blockchain. + */ +export declare function qiHDAccountPath(account?: number, change?: boolean): string; +/** + * Returns a derivation path for a Quai blockchain account. + * @param {number} account - The account index (defaults to 0). + * @returns {string} The BIP44 derivation path for the specified account on the Quai blockchain. + */ +export declare function quaiHDAccountPath(account?: number): string; +//# sourceMappingURL=hdwallet.d.ts.map \ No newline at end of file diff --git a/lib.esm/wallet/hdwallet.d.ts.map b/lib.esm/wallet/hdwallet.d.ts.map new file mode 100644 index 00000000..55ba3807 --- /dev/null +++ b/lib.esm/wallet/hdwallet.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"hdwallet.d.ts","sourceRoot":"","sources":["../../src.ts/wallet/hdwallet.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAuC,UAAU,EAAU,MAAM,oBAAoB,CAAC;AAC7F,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAQnD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAMzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAMtD;;;;;;;GAOG;AACH,qBAAa,YAAa,SAAQ,UAAU;;IAMxC;;;;;;OAMG;IACH,QAAQ,CAAC,WAAW,EAAG,MAAM,CAAC;IAE9B;;OAEG;IACH,QAAQ,CAAC,kBAAkB,EAAG,MAAM,CAAC;IAErC;;;;;OAKG;IACH,QAAQ,CAAC,QAAQ,EAAG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;gBACS,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,GAAG,QAAQ;IAYvL,OAAO,CAAC,QAAQ,EAAE,IAAI,GAAG,QAAQ,GAAG,gBAAgB;IAKpD;;;;;OAKG;IACH,IAAI,WAAW,IAAI,MAAM,CAiBxB;IAED;;;OAGG;IACH,OAAO,IAAI,IAAI,IAAI;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE;IAEnC;;OAEG;IACH,WAAW,CAAC,MAAM,EAAE,OAAO,GAAG,gBAAgB;IAoB9C;;OAEG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB;CAG7C;AAmBD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAItD;AAED;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAI7D;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,OAAO,GAAE,MAAU,EAAE,MAAM,GAAE,OAAe,UAE3E;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,MAAU,UAEpD"} \ No newline at end of file diff --git a/lib.esm/wallet/hdwallet.js b/lib.esm/wallet/hdwallet.js new file mode 100644 index 00000000..fc63766d --- /dev/null +++ b/lib.esm/wallet/hdwallet.js @@ -0,0 +1,503 @@ +/** + * Explain HD Wallets.. + * + * @_subsection: api/wallet:HD Wallets [hd-wallets] + */ +import { computeHmac, randomBytes, ripemd160, SigningKey, sha256 } from "../crypto/index.js"; +import { VoidSigner } from "../providers/index.js"; +import { computeAddress } from "../transaction/index.js"; +import { concat, dataSlice, decodeBase58, defineProperties, getBytes, hexlify, isBytesLike, getNumber, toBeArray, toBigInt, toBeHex, assertPrivate, assert, assertArgument } from "../utils/index.js"; +import { BaseWallet } from "./base-wallet.js"; +import { Mnemonic } from "./mnemonic.js"; +import { encryptKeystoreJson, encryptKeystoreJsonSync, } from "./json-keystore.js"; +import { N, ShardData } from "../constants/index.js"; +import { getShardForAddress, isUTXOAddress } from "../utils/index.js"; +import { encodeBase58Check, zpad, HardenedBit, ser_I, derivePath, MasterSecret } from "./utils.js"; +const _guard = {}; +/** + * An **HDNodeWallet** is a [[Signer]] backed by the private key derived + * from an HD Node using the [[link-bip-32]] stantard. + * + * An HD Node forms a hierarchal structure with each HD Node having a + * private key and the ability to derive child HD Nodes, defined by + * a path indicating the index of each child. + */ +export class HDNodeWallet extends BaseWallet { + /** + * The compressed public key. + */ + #publicKey; + /** + * The fingerprint. + * + * A fingerprint allows quick qay to detect parent and child nodes, + * but developers should be prepared to deal with collisions as it + * is only 4 bytes. + */ + fingerprint; + /** + * The parent fingerprint. + */ + accountFingerprint; + /** + * The mnemonic used to create this HD Node, if available. + * + * Sources such as extended keys do not encode the mnemonic, in + * which case this will be ``null``. + */ + mnemonic; + /** + * The chaincode, which is effectively a public key used + * to derive children. + */ + chainCode; + /** + * The derivation path of this wallet. + * + * Since extended keys do not provider full path details, this + * may be ``null``, if instantiated from a source that does not + * enocde it. + */ + path; + /** + * The child index of this wallet. Values over ``2 *\* 31`` indicate + * the node is hardened. + */ + index; + /** + * The depth of this wallet, which is the number of components + * in its path. + */ + depth; + coinType; + /** + * @private + */ + constructor(guard, signingKey, accountFingerprint, chainCode, path, index, depth, mnemonic, provider) { + super(signingKey, provider); + assertPrivate(guard, _guard); + this.#publicKey = signingKey.compressedPublicKey; + const fingerprint = dataSlice(ripemd160(sha256(this.#publicKey)), 0, 4); + defineProperties(this, { + accountFingerprint, fingerprint, + chainCode, path, index, depth + }); + defineProperties(this, { mnemonic }); + } + connect(provider) { + return new HDNodeWallet(_guard, this.signingKey, this.accountFingerprint, this.chainCode, this.path, this.index, this.depth, this.mnemonic, provider); + } + #account() { + const account = { address: this.address, privateKey: this.privateKey }; + const m = this.mnemonic; + if (this.path && m && m.wordlist.locale === "en" && m.password === "") { + account.mnemonic = { + path: this.path, + locale: "en", + entropy: m.entropy + }; + } + return account; + } + /** + * Resolves to a [JSON Keystore Wallet](json-wallets) encrypted with + * %%password%%. + * + * If %%progressCallback%% is specified, it will receive periodic + * updates as the encryption process progreses. + */ + async encrypt(password, progressCallback) { + return await encryptKeystoreJson(this.#account(), password, { progressCallback }); + } + /** + * Returns a [JSON Keystore Wallet](json-wallets) encryped with + * %%password%%. + * + * It is preferred to use the [async version](encrypt) instead, + * which allows a [[ProgressCallback]] to keep the user informed. + * + * This method will block the event loop (freezing all UI) until + * it is complete, which may be a non-trivial duration. + */ + encryptSync(password) { + return encryptKeystoreJsonSync(this.#account(), password); + } + /** + * The extended key. + * + * This key will begin with the prefix ``xpriv`` and can be used to + * reconstruct this HD Node to derive its children. + */ + get extendedKey() { + // We only support the mainnet values for now, but if anyone needs + // testnet values, let me know. I believe current sentiment is that + // we should always use mainnet, and use BIP-44 to derive the network + // - Mainnet: public=0x0488B21E, private=0x0488ADE4 + // - Testnet: public=0x043587CF, private=0x04358394 + assert(this.depth < 256, "Depth too deep", "UNSUPPORTED_OPERATION", { operation: "extendedKey" }); + return encodeBase58Check(concat([ + "0x0488ADE4", zpad(this.depth, 1), this.accountFingerprint ?? '', + zpad(this.index, 4), this.chainCode, + concat(["0x00", this.privateKey]) + ])); + } + /** + * Gets the current publicKey + */ + get publicKey() { + return this.#publicKey; + } + /** + * Returns true if this wallet has a path, providing a Type Guard + * that the path is non-null. + */ + hasPath() { return (this.path != null); } + /** + * Returns a neutered HD Node, which removes the private details + * of an HD Node. + * + * A neutered node has no private key, but can be used to derive + * child addresses and other public data about the HD Node. + */ + neuter() { + return new HDNodeVoidWallet(_guard, this.address, this.#publicKey, this.accountFingerprint ?? '', this.chainCode, this.path ?? '', this.index, this.depth, this.provider); + } + /** + * Return the child for %%index%%. + */ + deriveChild(_index) { + const index = getNumber(_index, "index"); + assertArgument(index <= 0xffffffff, "invalid index", "index", index); + // Base path + let newDepth = this.depth + 1; + let path = this.path; + if (path) { + let pathFields = path.split("/"); + if (pathFields.length == 6) { + pathFields.pop(); + path = pathFields.join("/"); + newDepth--; + } + path += "/" + (index & ~HardenedBit); + if (index & HardenedBit) { + path += "'"; + } + } + const { IR, IL } = ser_I(index, this.chainCode, this.#publicKey, this.privateKey); + const ki = new SigningKey(toBeHex((toBigInt(IL) + BigInt(this.privateKey)) % N, 32)); + //BIP44 if we are at the account depth get that fingerprint, otherwise continue with the current one + let newFingerprint = this.depth == 3 ? this.fingerprint : this.accountFingerprint; + return new HDNodeWallet(_guard, ki, newFingerprint, hexlify(IR), path, index, newDepth, this.mnemonic, this.provider); + } + /** + * Return the HDNode for %%path%% from this node. + */ + derivePath(path) { + return derivePath(this, path); + } + setCoinType() { + this.coinType = Number(this.path?.split("/")[2].replace("'", "")); + } + static #fromSeed(_seed, mnemonic) { + assertArgument(isBytesLike(_seed), "invalid seed", "seed", "[REDACTED]"); + const seed = getBytes(_seed, "seed"); + assertArgument(seed.length >= 16 && seed.length <= 64, "invalid seed", "seed", "[REDACTED]"); + const I = getBytes(computeHmac("sha512", MasterSecret, seed)); + const signingKey = new SigningKey(hexlify(I.slice(0, 32))); + const result = new HDNodeWallet(_guard, signingKey, "0x00000000", hexlify(I.slice(32)), "m", 0, 0, mnemonic, null); + return result; + } + /** + * Creates a new HD Node from %%extendedKey%%. + * + * If the %%extendedKey%% will either have a prefix or ``xpub`` or + * ``xpriv``, returning a neutered HD Node ([[HDNodeVoidWallet]]) + * or full HD Node ([[HDNodeWallet) respectively. + */ + static fromExtendedKey(extendedKey) { + const bytes = toBeArray(decodeBase58(extendedKey)); // @TODO: redact + assertArgument(bytes.length === 82 || encodeBase58Check(bytes.slice(0, 78)) === extendedKey, "invalid extended key", "extendedKey", "[ REDACTED ]"); + const depth = bytes[4]; + const accountFingerprint = hexlify(bytes.slice(5, 9)); + const index = parseInt(hexlify(bytes.slice(9, 13)).substring(2), 16); + const chainCode = hexlify(bytes.slice(13, 45)); + const key = bytes.slice(45, 78); + switch (hexlify(bytes.slice(0, 4))) { + // Public Key + case "0x0488b21e": + case "0x043587cf": { + const publicKey = hexlify(key); + return new HDNodeVoidWallet(_guard, computeAddress(publicKey), publicKey, accountFingerprint, chainCode, null, index, depth, null); + } + // Private Key + case "0x0488ade4": + case "0x04358394 ": + if (key[0] !== 0) { + break; + } + return new HDNodeWallet(_guard, new SigningKey(key.slice(1)), accountFingerprint, chainCode, null, index, depth, null, null); + } + assertArgument(false, "invalid extended key prefix", "extendedKey", "[ REDACTED ]"); + } + /** + * Creates a new random HDNode. + */ + static createRandom(path, password, wordlist) { + if (path == null || !this.isValidPath(path)) { + throw new Error('Invalid path: ' + path); + } + const mnemonic = Mnemonic.fromEntropy(randomBytes(16), password, wordlist); + return HDNodeWallet.#fromSeed(mnemonic.computeSeed(), mnemonic).derivePath(path); + } + /** + * Create an HD Node from %%mnemonic%%. + */ + static fromMnemonic(mnemonic, path) { + if (path == null || !this.isValidPath(path)) { + throw new Error('Invalid path: ' + path); + } + return HDNodeWallet.#fromSeed(mnemonic.computeSeed(), mnemonic).derivePath(path); + } + /** + * Creates an HD Node from a mnemonic %%phrase%%. + */ + static fromPhrase(phrase, path, password, wordlist) { + if (path == null || !this.isValidPath(path)) { + throw new Error('Invalid path: ' + path); + } + const mnemonic = Mnemonic.fromPhrase(phrase, password, wordlist); + return HDNodeWallet.#fromSeed(mnemonic.computeSeed(), mnemonic).derivePath(path); + } + /** + * Checks if the provided BIP44 path is valid and limited to the change level. + * @param path The BIP44 path to check. + * @returns true if the path is valid and does not include the address_index; false otherwise. + */ + static isValidPath(path) { + // BIP44 path regex pattern for up to the 'change' level, excluding 'address_index' + // This pattern matches paths like "m/44'/0'/0'/0" and "m/44'/60'/0'/1", but not "m/44'/60'/0'/0/0" + const pathRegex = /^m\/44'\/\d+'\/\d+'\/[01]$/; + return pathRegex.test(path); + } + /** + * Creates an HD Node from a %%seed%%. + */ + static fromSeed(seed) { + return HDNodeWallet.#fromSeed(seed, null); + } + /** + * Derives address by incrementing address_index according to BIP44 + */ + deriveAddress(index, zone) { + if (!this.path) + throw new Error("Missing Path"); + //Case for a non quai/qi wallet where zone is not needed + if (!zone) { + if (this.coinType == 994 || this.coinType == 969) { + //Zone not provided but wallet cointype is quai/qi + throw new Error("No zone provided for a Quai / Qi wallet"); + } + //Return address for any other cointype with no + return this.derivePath(this.path + "/" + index.toString()); + } + zone = zone.toLowerCase(); + // Check if zone is valid + const shard = ShardData.find(shard => shard.name.toLowerCase() === zone || shard.nickname.toLowerCase() === zone || shard.byte.toLowerCase() === zone); + if (!shard) { + throw new Error("Invalid zone"); + } + let newWallet; + let addrIndex = 0; + let zoneIndex = index + 1; + do { + newWallet = this.derivePath(addrIndex.toString()); + if (getShardForAddress(newWallet.address) == shard && ((newWallet.coinType == 969) == isUTXOAddress(newWallet.address))) + zoneIndex--; + addrIndex++; + } while (zoneIndex > 0); + return newWallet; + } +} +// // In crements the address_ index according to BIP-44 +// function incrementPathIndex(path: string): string { +// const parts = path.split('/'); +// const lastIndex = parseInt(parts[parts.length - 1], 10); +// parts[parts.length - 1] = (lastIndex + 1).toString(); +// return parts.join('/'); +// } +/** + * A **HDNodeVoidWallet** cannot sign, but provides access to + * the children nodes of a [[link-bip-32]] HD wallet addresses. + * + * The can be created by using an extended ``xpub`` key to + * [[HDNodeWallet_fromExtendedKey]] or by + * [nuetering](HDNodeWallet-neuter) a [[HDNodeWallet]]. + */ +export class HDNodeVoidWallet extends VoidSigner { + /** + * The compressed public key. + */ + publicKey; + /** + * The fingerprint. + * + * A fingerprint allows quick qay to detect parent and child nodes, + * but developers should be prepared to deal with collisions as it + * is only 4 bytes. + */ + fingerprint; + /** + * The parent node fingerprint. + */ + accountFingerprint; + /** + * The chaincode, which is effectively a public key used + * to derive children. + */ + chainCode; + /** + * The derivation path of this wallet. + * + * Since extended keys do not provider full path details, this + * may be ``null``, if instantiated from a source that does not + * enocde it. + */ + path; + /** + * The child index of this wallet. Values over ``2 *\* 31`` indicate + * the node is hardened. + */ + index; + /** + * The depth of this wallet, which is the number of components + * in its path. + */ + depth; + /** + * @private + */ + constructor(guard, address, publicKey, accountFingerprint, chainCode, path, index, depth, provider) { + super(address, provider); + assertPrivate(guard, _guard, "HDNodeVoidWallet"); + defineProperties(this, { publicKey }); + const fingerprint = dataSlice(ripemd160(sha256(publicKey)), 0, 4); + defineProperties(this, { + publicKey, fingerprint, accountFingerprint, chainCode, path, index, depth + }); + } + connect(provider) { + return new HDNodeVoidWallet(_guard, this.address, this.publicKey, this.accountFingerprint ?? '', this.chainCode, this.path, this.index, this.depth, provider); + } + /** + * The extended key. + * + * This key will begin with the prefix ``xpub`` and can be used to + * reconstruct this neutered key to derive its children addresses. + */ + get extendedKey() { + // We only support the mainnet values for now, but if anyone needs + // testnet values, let me know. I believe current sentiment is that + // we should always use mainnet, and use BIP-44 to derive the network + // - Mainnet: public=0x0488B21E, private=0x0488ADE4 + // - Testnet: public=0x043587CF, private=0x04358394 + assert(this.depth < 256, "Depth too deep", "UNSUPPORTED_OPERATION", { operation: "extendedKey" }); + return encodeBase58Check(concat([ + "0x0488B21E", + zpad(this.depth, 1), + this.accountFingerprint ?? '', + zpad(this.index, 4), + this.chainCode, + this.publicKey, + ])); + } + /** + * Returns true if this wallet has a path, providing a Type Guard + * that the path is non-null. + */ + hasPath() { return (this.path != null); } + /** + * Return the child for %%index%%. + */ + deriveChild(_index) { + const index = getNumber(_index, "index"); + assertArgument(index <= 0xffffffff, "invalid index", "index", index); + // Base path + let path = this.path; + if (path) { + path += "/" + (index & ~HardenedBit); + if (index & HardenedBit) { + path += "'"; + } + } + const { IR, IL } = ser_I(index, this.chainCode, this.publicKey, null); + const Ki = SigningKey.addPoints(IL, this.publicKey, true); + const address = computeAddress(Ki); + return new HDNodeVoidWallet(_guard, address, Ki, this.fingerprint, hexlify(IR), path, index, this.depth + 1, this.provider); + } + /** + * Return the signer for %%path%% from this node. + */ + derivePath(path) { + return derivePath(this, path); + } +} +/* +export class HDNodeWalletManager { + #root: HDNodeWallet; + + constructor(phrase: string, password?: null | string, path?: null | string, locale?: null | Wordlist) { + if (password == null) { password = ""; } + if (path == null) { path = "m/44'/60'/0'/0"; } + if (locale == null) { locale = LangEn.wordlist(); } + this.#root = HDNodeWallet.fromPhrase(phrase, password, path, locale); + } + + getSigner(index?: number): HDNodeWallet { + return this.#root.deriveChild((index == null) ? 0: index); + } +} +*/ +/** + * Returns the [[link-bip-32]] path for the account at %%index%%. + * + * This is the pattern used by wallets like Ledger. + * + * There is also an [alternate pattern](getIndexedAccountPath) used by + * some software. + */ +export function getAccountPath(_index) { + const index = getNumber(_index, "index"); + assertArgument(index >= 0 && index < HardenedBit, "invalid account index", "index", index); + return `m/44'/60'/${index}'/0/0`; +} +/** + * Returns the path using an alternative pattern for deriving accounts, + * at %%index%%. + * + * This derivation path uses the //index// component rather than the + * //account// component to derive sequential accounts. + * + * This is the pattern used by wallets like MetaMask. + */ +export function getIndexedAccountPath(_index) { + const index = getNumber(_index, "index"); + assertArgument(index >= 0 && index < HardenedBit, "invalid account index", "index", index); + return `m/44'/60'/0'/0/${index}`; +} +/** + * Returns a derivation path for a Qi blockchain account. + * @param {number} account - The account index (defaults to 0). + * @returns {string} The BIP44 derivation path for the specified account on the Qi blockchain. + */ +export function qiHDAccountPath(account = 0, change = false) { + return `m/44'/969'/${account}'/${change ? 1 : 0}`; +} +/** + * Returns a derivation path for a Quai blockchain account. + * @param {number} account - The account index (defaults to 0). + * @returns {string} The BIP44 derivation path for the specified account on the Quai blockchain. + */ +export function quaiHDAccountPath(account = 0) { + return `m/44'/994'/${account}'/0`; +} +//# sourceMappingURL=hdwallet.js.map \ No newline at end of file diff --git a/lib.esm/wallet/hdwallet.js.map b/lib.esm/wallet/hdwallet.js.map new file mode 100644 index 00000000..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CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACtD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,UAAkB,CAAC;IACjD,OAAO,cAAc,OAAO,KAAK,CAAC;AACtC,CAAC"} \ No newline at end of file diff --git a/lib.esm/wallet/index.d.ts b/lib.esm/wallet/index.d.ts new file mode 100644 index 00000000..afcce13c --- /dev/null +++ b/lib.esm/wallet/index.d.ts @@ -0,0 +1,27 @@ +/** + * When interacting with Ethereum, it is necessary to use a private + * key authenticate actions by signing a payload. + * + * Wallets are the simplest way to expose the concept of an + * //Externally Owner Account// (EOA) as it wraps a private key + * and supports high-level methods to sign common types of interaction + * and send transactions. + * + * The class most developers will want to use is [[Wallet]], which + * can load a private key directly or from any common wallet format. + * + * The [[HDNodeWallet]] can be used when it is necessary to access + * low-level details of how an HD wallets are derived, exported + * or imported. + * + * @_section: api/wallet:Wallets [about-wallets] + */ +export { BaseWallet } from "./base-wallet.js"; +export { getAccountPath, getIndexedAccountPath, quaiHDAccountPath, qiHDAccountPath, HDNodeWallet, HDNodeVoidWallet, } from "./hdwallet.js"; +export { isCrowdsaleJson, decryptCrowdsaleJson } from "./json-crowdsale.js"; +export { isKeystoreJson, decryptKeystoreJsonSync, decryptKeystoreJson, encryptKeystoreJson, encryptKeystoreJsonSync } from "./json-keystore.js"; +export { Mnemonic } from "./mnemonic.js"; +export { Wallet } from "./wallet.js"; +export type { CrowdsaleAccount } from "./json-crowdsale.js"; +export type { KeystoreAccount, EncryptOptions } from "./json-keystore.js"; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/lib.esm/wallet/index.d.ts.map b/lib.esm/wallet/index.d.ts.map new file mode 100644 index 00000000..c59e2ed8 --- /dev/null +++ b/lib.esm/wallet/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src.ts/wallet/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EAEH,cAAc,EAAE,qBAAqB,EACrC,iBAAiB,EAAE,eAAe,EAClC,YAAY,EACZ,gBAAgB,GACnB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAE5E,OAAO,EACH,cAAc,EACd,uBAAuB,EAAE,mBAAmB,EAC5C,mBAAmB,EAAE,uBAAuB,EAC/C,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAGrC,YAAY,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,YAAY,EACR,eAAe,EAAE,cAAc,EAClC,MAAM,oBAAoB,CAAA"} \ No newline at end of file diff --git a/lib.esm/wallet/index.js b/lib.esm/wallet/index.js new file mode 100644 index 00000000..b1c364c6 --- /dev/null +++ b/lib.esm/wallet/index.js @@ -0,0 +1,25 @@ +/** + * When interacting with Ethereum, it is necessary to use a private + * key authenticate actions by signing a payload. + * + * Wallets are the simplest way to expose the concept of an + * //Externally Owner Account// (EOA) as it wraps a private key + * and supports high-level methods to sign common types of interaction + * and send transactions. + * + * The class most developers will want to use is [[Wallet]], which + * can load a private key directly or from any common wallet format. + * + * The [[HDNodeWallet]] can be used when it is necessary to access + * low-level details of how an HD wallets are derived, exported + * or imported. + * + * @_section: api/wallet:Wallets [about-wallets] + */ +export { BaseWallet } from "./base-wallet.js"; +export { getAccountPath, getIndexedAccountPath, quaiHDAccountPath, qiHDAccountPath, HDNodeWallet, HDNodeVoidWallet, } from "./hdwallet.js"; +export { isCrowdsaleJson, decryptCrowdsaleJson } from "./json-crowdsale.js"; +export { isKeystoreJson, decryptKeystoreJsonSync, decryptKeystoreJson, encryptKeystoreJson, encryptKeystoreJsonSync } from "./json-keystore.js"; +export { Mnemonic } from "./mnemonic.js"; +export { Wallet } from "./wallet.js"; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib.esm/wallet/index.js.map b/lib.esm/wallet/index.js.map new file mode 100644 index 00000000..55c5f761 --- /dev/null +++ b/lib.esm/wallet/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src.ts/wallet/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EAEH,cAAc,EAAE,qBAAqB,EACrC,iBAAiB,EAAE,eAAe,EAClC,YAAY,EACZ,gBAAgB,GACnB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAE5E,OAAO,EACH,cAAc,EACd,uBAAuB,EAAE,mBAAmB,EAC5C,mBAAmB,EAAE,uBAAuB,EAC/C,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC"} \ No newline at end of file diff --git a/lib.esm/wallet/json-crowdsale.d.ts b/lib.esm/wallet/json-crowdsale.d.ts new file mode 100644 index 00000000..3d7f4a2b --- /dev/null +++ b/lib.esm/wallet/json-crowdsale.d.ts @@ -0,0 +1,27 @@ +/** + * @_subsection: api/wallet:JSON Wallets [json-wallets] + */ +/** + * The data stored within a JSON Crowdsale wallet is fairly + * minimal. + */ +export type CrowdsaleAccount = { + privateKey: string; + address: string; +}; +/** + * Returns true if %%json%% is a valid JSON Crowdsale wallet. + */ +export declare function isCrowdsaleJson(json: string): boolean; +/** + * Before Ethereum launched, it was necessary to create a wallet + * format for backers to use, which would be used to receive ether + * as a reward for contributing to the project. + * + * The [[link-crowdsale]] format is now obsolete, but it is still + * useful to support and the additional code is fairly trivial as + * all the primitives required are used through core portions of + * the library. + */ +export declare function decryptCrowdsaleJson(json: string, _password: string | Uint8Array): CrowdsaleAccount; +//# sourceMappingURL=json-crowdsale.d.ts.map \ No newline at end of file diff --git a/lib.esm/wallet/json-crowdsale.d.ts.map b/lib.esm/wallet/json-crowdsale.d.ts.map new file mode 100644 index 00000000..a569abcd --- /dev/null +++ b/lib.esm/wallet/json-crowdsale.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"json-crowdsale.d.ts","sourceRoot":"","sources":["../../src.ts/wallet/json-crowdsale.ts"],"names":[],"mappings":"AAAA;;GAEG;AAYH;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;CACnB,CAAA;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAMrD;AAID;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,UAAU,GAAG,gBAAgB,CA2BnG"} \ No newline at end of file diff --git a/lib.esm/wallet/json-crowdsale.js b/lib.esm/wallet/json-crowdsale.js new file mode 100644 index 00000000..a9121188 --- /dev/null +++ b/lib.esm/wallet/json-crowdsale.js @@ -0,0 +1,55 @@ +/** + * @_subsection: api/wallet:JSON Wallets [json-wallets] + */ +import { CBC, pkcs7Strip } from "aes-js"; +import { getAddress } from "../address/index.js"; +import { pbkdf2 } from "../crypto/index.js"; +import { id } from "../hash/index.js"; +import { getBytes, assertArgument } from "../utils/index.js"; +import { getPassword, looseArrayify, spelunk } from "./utils.js"; +/** + * Returns true if %%json%% is a valid JSON Crowdsale wallet. + */ +export function isCrowdsaleJson(json) { + try { + const data = JSON.parse(json); + if (data.encseed) { + return true; + } + } + catch (error) { } + return false; +} +// See: https://github.com/ethereum/pyethsaletool +/** + * Before Ethereum launched, it was necessary to create a wallet + * format for backers to use, which would be used to receive ether + * as a reward for contributing to the project. + * + * The [[link-crowdsale]] format is now obsolete, but it is still + * useful to support and the additional code is fairly trivial as + * all the primitives required are used through core portions of + * the library. + */ +export function decryptCrowdsaleJson(json, _password) { + const data = JSON.parse(json); + const password = getPassword(_password); + // Ethereum Address + const address = getAddress(spelunk(data, "ethaddr:string!")); + // Encrypted Seed + const encseed = looseArrayify(spelunk(data, "encseed:string!")); + assertArgument(encseed && (encseed.length % 16) === 0, "invalid encseed", "json", json); + const key = getBytes(pbkdf2(password, password, 2000, 32, "sha256")).slice(0, 16); + const iv = encseed.slice(0, 16); + const encryptedSeed = encseed.slice(16); + // Decrypt the seed + const aesCbc = new CBC(key, iv); + const seed = pkcs7Strip(getBytes(aesCbc.decrypt(encryptedSeed))); + // This wallet format is weird... Convert the binary encoded hex to a string. + let seedHex = ""; + for (let i = 0; i < seed.length; i++) { + seedHex += String.fromCharCode(seed[i]); + } + return { address, privateKey: id(seedHex) }; +} +//# sourceMappingURL=json-crowdsale.js.map \ No newline at end of file diff --git a/lib.esm/wallet/json-crowdsale.js.map b/lib.esm/wallet/json-crowdsale.js.map new file mode 100644 index 00000000..2281cca9 --- /dev/null +++ b/lib.esm/wallet/json-crowdsale.js.map @@ -0,0 +1 @@ +{"version":3,"file":"json-crowdsale.js","sourceRoot":"","sources":["../../src.ts/wallet/json-crowdsale.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEzC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAE7D,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAY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UAAU,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IAEjE,6EAA6E;IAC7E,IAAI,OAAO,GAAG,EAAE,CAAC;IACjB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QAClC,OAAO,IAAI,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;KAC3C;IAED,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC;AAChD,CAAC"} \ No newline at end of file diff --git a/lib.esm/wallet/json-keystore.d.ts b/lib.esm/wallet/json-keystore.d.ts new file mode 100644 index 00000000..c01076fe --- /dev/null +++ b/lib.esm/wallet/json-keystore.d.ts @@ -0,0 +1,89 @@ +/** + * The JSON Wallet formats allow a simple way to store the private + * keys needed in Ethereum along with related information and allows + * for extensible forms of encryption. + * + * These utilities facilitate decrypting and encrypting the most common + * JSON Wallet formats. + * + * @_subsection: api/wallet:JSON Wallets [json-wallets] + */ +import type { ProgressCallback } from "../crypto/index.js"; +import type { BytesLike } from "../utils/index.js"; +/** + * The contents of a JSON Keystore Wallet. + */ +export type KeystoreAccount = { + address: string; + privateKey: string; + mnemonic?: { + path?: string; + locale?: string; + entropy: string; + }; +}; +/** + * The parameters to use when encrypting a JSON Keystore Wallet. + */ +export type EncryptOptions = { + progressCallback?: ProgressCallback; + iv?: BytesLike; + entropy?: BytesLike; + client?: string; + salt?: BytesLike; + uuid?: string; + scrypt?: { + N?: number; + r?: number; + p?: number; + }; +}; +/** + * Returns true if %%json%% is a valid JSON Keystore Wallet. + */ +export declare function isKeystoreJson(json: string): boolean; +/** + * Returns the account details for the JSON Keystore Wallet %%json%% + * using %%password%%. + * + * It is preferred to use the [async version](decryptKeystoreJson) + * instead, which allows a [[ProgressCallback]] to keep the user informed + * as to the decryption status. + * + * This method will block the event loop (freezing all UI) until decryption + * is complete, which can take quite some time, depending on the wallet + * paramters and platform. + */ +export declare function decryptKeystoreJsonSync(json: string, _password: string | Uint8Array): KeystoreAccount; +/** + * Resolves to the decrypted JSON Keystore Wallet %%json%% using the + * %%password%%. + * + * If provided, %%progress%% will be called periodically during the + * decrpytion to provide feedback, and if the function returns + * ``false`` will halt decryption. + * + * The %%progressCallback%% will **always** receive ``0`` before + * decryption begins and ``1`` when complete. + */ +export declare function decryptKeystoreJson(json: string, _password: string | Uint8Array, progress?: ProgressCallback): Promise; +/** + * Return the JSON Keystore Wallet for %%account%% encrypted with + * %%password%%. + * + * The %%options%% can be used to tune the password-based key + * derivation function parameters, explicitly set the random values + * used. Any provided [[ProgressCallback]] is ignord. + */ +export declare function encryptKeystoreJsonSync(account: KeystoreAccount, password: string | Uint8Array, options?: EncryptOptions): string; +/** + * Resolved to the JSON Keystore Wallet for %%account%% encrypted + * with %%password%%. + * + * The %%options%% can be used to tune the password-based key + * derivation function parameters, explicitly set the random values + * used and provide a [[ProgressCallback]] to receive periodic updates + * on the completion status.. + */ +export declare function encryptKeystoreJson(account: KeystoreAccount, password: string | Uint8Array, options?: EncryptOptions): Promise; +//# sourceMappingURL=json-keystore.d.ts.map \ No newline at end of file diff --git a/lib.esm/wallet/json-keystore.d.ts.map b/lib.esm/wallet/json-keystore.d.ts.map new file mode 100644 index 00000000..2ce64555 --- /dev/null +++ b/lib.esm/wallet/json-keystore.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"json-keystore.d.ts","sourceRoot":"","sources":["../../src.ts/wallet/json-keystore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAaH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAOnD;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,M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AAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAO5I"} \ No newline at end of file diff --git a/lib.esm/wallet/json-keystore.js b/lib.esm/wallet/json-keystore.js new file mode 100644 index 00000000..1ae2574f --- /dev/null +++ b/lib.esm/wallet/json-keystore.js @@ -0,0 +1,287 @@ +/** + * The JSON Wallet formats allow a simple way to store the private + * keys needed in Ethereum along with related information and allows + * for extensible forms of encryption. + * + * These utilities facilitate decrypting and encrypting the most common + * JSON Wallet formats. + * + * @_subsection: api/wallet:JSON Wallets [json-wallets] + */ +import { CTR } from "aes-js"; +import { getAddress } from "../address/index.js"; +import { keccak256, pbkdf2, randomBytes, scrypt, scryptSync } from "../crypto/index.js"; +import { computeAddress } from "../transaction/index.js"; +import { concat, getBytes, hexlify, uuidV4, assert, assertArgument } from "../utils/index.js"; +import { getPassword, spelunk, zpad } from "./utils.js"; +import { version } from "../_version.js"; +const defaultPath = "m/44'/994'/0'/0/0"; +/** + * Returns true if %%json%% is a valid JSON Keystore Wallet. + */ +export function isKeystoreJson(json) { + try { + const data = JSON.parse(json); + const version = ((data.version != null) ? parseInt(data.version) : 0); + if (version === 3) { + return true; + } + } + catch (error) { } + return false; +} +function decrypt(data, key, ciphertext) { + const cipher = spelunk(data, "crypto.cipher:string"); + if (cipher === "aes-128-ctr") { + const iv = spelunk(data, "crypto.cipherparams.iv:data!"); + const aesCtr = new CTR(key, iv); + return hexlify(aesCtr.decrypt(ciphertext)); + } + assert(false, "unsupported cipher", "UNSUPPORTED_OPERATION", { + operation: "decrypt" + }); +} +function getAccount(data, _key) { + const key = getBytes(_key); + const ciphertext = spelunk(data, "crypto.ciphertext:data!"); + const computedMAC = hexlify(keccak256(concat([key.slice(16, 32), ciphertext]))).substring(2); + assertArgument(computedMAC === spelunk(data, "crypto.mac:string!").toLowerCase(), "incorrect password", "password", "[ REDACTED ]"); + const privateKey = decrypt(data, key.slice(0, 16), ciphertext); + const address = computeAddress(privateKey); + if (data.address) { + let check = data.address.toLowerCase(); + if (!check.startsWith("0x")) { + check = "0x" + check; + } + assertArgument(getAddress(check) === address, "keystore address/privateKey mismatch", "address", data.address); + } + const account = { address, privateKey }; + // Version 0.1 x-quais metadata must contain an encrypted mnemonic phrase + const version = spelunk(data, "x-quais.version:string"); + if (version === "0.1") { + const mnemonicKey = key.slice(32, 64); + const mnemonicCiphertext = spelunk(data, "x-quais.mnemonicCiphertext:data!"); + const mnemonicIv = spelunk(data, "x-quais.mnemonicCounter:data!"); + const mnemonicAesCtr = new CTR(mnemonicKey, mnemonicIv); + account.mnemonic = { + path: (spelunk(data, "x-quais.path:string") || defaultPath), + locale: (spelunk(data, "x-quais.locale:string") || "en"), + entropy: hexlify(getBytes(mnemonicAesCtr.decrypt(mnemonicCiphertext))) + }; + } + return account; +} +function getDecryptKdfParams(data) { + const kdf = spelunk(data, "crypto.kdf:string"); + if (kdf && typeof (kdf) === "string") { + if (kdf.toLowerCase() === "scrypt") { + const salt = spelunk(data, "crypto.kdfparams.salt:data!"); + const N = spelunk(data, "crypto.kdfparams.n:int!"); + const r = spelunk(data, "crypto.kdfparams.r:int!"); + const p = spelunk(data, "crypto.kdfparams.p:int!"); + // Make sure N is a power of 2 + assertArgument(N > 0 && (N & (N - 1)) === 0, "invalid kdf.N", "kdf.N", N); + assertArgument(r > 0 && p > 0, "invalid kdf", "kdf", kdf); + const dkLen = spelunk(data, "crypto.kdfparams.dklen:int!"); + assertArgument(dkLen === 32, "invalid kdf.dklen", "kdf.dflen", dkLen); + return { name: "scrypt", salt, N, r, p, dkLen: 64 }; + } + else if (kdf.toLowerCase() === "pbkdf2") { + const salt = spelunk(data, "crypto.kdfparams.salt:data!"); + const prf = spelunk(data, "crypto.kdfparams.prf:string!"); + const algorithm = prf.split("-").pop(); + assertArgument(algorithm === "sha256" || algorithm === "sha512", "invalid kdf.pdf", "kdf.pdf", prf); + const count = spelunk(data, "crypto.kdfparams.c:int!"); + const dkLen = spelunk(data, "crypto.kdfparams.dklen:int!"); + assertArgument(dkLen === 32, "invalid kdf.dklen", "kdf.dklen", dkLen); + return { name: "pbkdf2", salt, count, dkLen, algorithm }; + } + } + assertArgument(false, "unsupported key-derivation function", "kdf", kdf); +} +/** + * Returns the account details for the JSON Keystore Wallet %%json%% + * using %%password%%. + * + * It is preferred to use the [async version](decryptKeystoreJson) + * instead, which allows a [[ProgressCallback]] to keep the user informed + * as to the decryption status. + * + * This method will block the event loop (freezing all UI) until decryption + * is complete, which can take quite some time, depending on the wallet + * paramters and platform. + */ +export function decryptKeystoreJsonSync(json, _password) { + const data = JSON.parse(json); + const password = getPassword(_password); + const params = getDecryptKdfParams(data); + if (params.name === "pbkdf2") { + const { salt, count, dkLen, algorithm } = params; + const key = pbkdf2(password, salt, count, dkLen, algorithm); + return getAccount(data, key); + } + assert(params.name === "scrypt", "cannot be reached", "UNKNOWN_ERROR", { params }); + const { salt, N, r, p, dkLen } = params; + const key = scryptSync(password, salt, N, r, p, dkLen); + return getAccount(data, key); +} +function stall(duration) { + return new Promise((resolve) => { setTimeout(() => { resolve(); }, duration); }); +} +/** + * Resolves to the decrypted JSON Keystore Wallet %%json%% using the + * %%password%%. + * + * If provided, %%progress%% will be called periodically during the + * decrpytion to provide feedback, and if the function returns + * ``false`` will halt decryption. + * + * The %%progressCallback%% will **always** receive ``0`` before + * decryption begins and ``1`` when complete. + */ +export async function decryptKeystoreJson(json, _password, progress) { + const data = JSON.parse(json); + const password = getPassword(_password); + const params = getDecryptKdfParams(data); + if (params.name === "pbkdf2") { + if (progress) { + progress(0); + await stall(0); + } + const { salt, count, dkLen, algorithm } = params; + const key = pbkdf2(password, salt, count, dkLen, algorithm); + if (progress) { + progress(1); + await stall(0); + } + return getAccount(data, key); + } + assert(params.name === "scrypt", "cannot be reached", "UNKNOWN_ERROR", { params }); + const { salt, N, r, p, dkLen } = params; + const key = await scrypt(password, salt, N, r, p, dkLen, progress); + return getAccount(data, key); +} +function getEncryptKdfParams(options) { + // Check/generate the salt + const salt = (options.salt != null) ? getBytes(options.salt, "options.salt") : randomBytes(32); + // Override the scrypt password-based key derivation function parameters + let N = (1 << 17), r = 8, p = 1; + if (options.scrypt) { + if (options.scrypt.N) { + N = options.scrypt.N; + } + if (options.scrypt.r) { + r = options.scrypt.r; + } + if (options.scrypt.p) { + p = options.scrypt.p; + } + } + assertArgument(typeof (N) === "number" && N > 0 && Number.isSafeInteger(N) && (BigInt(N) & BigInt(N - 1)) === BigInt(0), "invalid scrypt N parameter", "options.N", N); + assertArgument(typeof (r) === "number" && r > 0 && Number.isSafeInteger(r), "invalid scrypt r parameter", "options.r", r); + assertArgument(typeof (p) === "number" && p > 0 && Number.isSafeInteger(p), "invalid scrypt p parameter", "options.p", p); + return { name: "scrypt", dkLen: 32, salt, N, r, p }; +} +function _encryptKeystore(key, kdf, account, options) { + const privateKey = getBytes(account.privateKey, "privateKey"); + // Override initialization vector + const iv = (options.iv != null) ? getBytes(options.iv, "options.iv") : randomBytes(16); + assertArgument(iv.length === 16, "invalid options.iv length", "options.iv", options.iv); + // Override the uuid + const uuidRandom = (options.uuid != null) ? getBytes(options.uuid, "options.uuid") : randomBytes(16); + assertArgument(uuidRandom.length === 16, "invalid options.uuid length", "options.uuid", options.iv); + // This will be used to encrypt the wallet (as per Web3 secret storage) + // - 32 bytes As normal for the Web3 secret storage (derivedKey, macPrefix) + // - 32 bytes AES key to encrypt mnemonic with (required here to be quais Wallet) + const derivedKey = key.slice(0, 16); + const macPrefix = key.slice(16, 32); + // Encrypt the private key + const aesCtr = new CTR(derivedKey, iv); + const ciphertext = getBytes(aesCtr.encrypt(privateKey)); + // Compute the message authentication code, used to check the password + const mac = keccak256(concat([macPrefix, ciphertext])); + // See: https://github.com/ethereum/wiki/wiki/Web3-Secret-Storage-Definition + const data = { + address: account.address.substring(2).toLowerCase(), + id: uuidV4(uuidRandom), + version: 3, + Crypto: { + cipher: "aes-128-ctr", + cipherparams: { + iv: hexlify(iv).substring(2), + }, + ciphertext: hexlify(ciphertext).substring(2), + kdf: "scrypt", + kdfparams: { + salt: hexlify(kdf.salt).substring(2), + n: kdf.N, + dklen: 32, + p: kdf.p, + r: kdf.r + }, + mac: mac.substring(2) + } + }; + // If we have a mnemonic, encrypt it into the JSON wallet + if (account.mnemonic) { + const client = (options.client != null) ? options.client : `quais/${version}`; + const path = account.mnemonic.path || defaultPath; + const locale = account.mnemonic.locale || "en"; + const mnemonicKey = key.slice(32, 64); + const entropy = getBytes(account.mnemonic.entropy, "account.mnemonic.entropy"); + const mnemonicIv = randomBytes(16); + const mnemonicAesCtr = new CTR(mnemonicKey, mnemonicIv); + const mnemonicCiphertext = getBytes(mnemonicAesCtr.encrypt(entropy)); + const now = new Date(); + const timestamp = (now.getUTCFullYear() + "-" + + zpad(now.getUTCMonth() + 1, 2) + "-" + + zpad(now.getUTCDate(), 2) + "T" + + zpad(now.getUTCHours(), 2) + "-" + + zpad(now.getUTCMinutes(), 2) + "-" + + zpad(now.getUTCSeconds(), 2) + ".0Z"); + const gethFilename = ("UTC--" + timestamp + "--" + data.address); + data["x-quais"] = { + client, gethFilename, path, locale, + mnemonicCounter: hexlify(mnemonicIv).substring(2), + mnemonicCiphertext: hexlify(mnemonicCiphertext).substring(2), + version: "0.1" + }; + } + return JSON.stringify(data); +} +/** + * Return the JSON Keystore Wallet for %%account%% encrypted with + * %%password%%. + * + * The %%options%% can be used to tune the password-based key + * derivation function parameters, explicitly set the random values + * used. Any provided [[ProgressCallback]] is ignord. + */ +export function encryptKeystoreJsonSync(account, password, options) { + if (options == null) { + options = {}; + } + const passwordBytes = getPassword(password); + const kdf = getEncryptKdfParams(options); + const key = scryptSync(passwordBytes, kdf.salt, kdf.N, kdf.r, kdf.p, 64); + return _encryptKeystore(getBytes(key), kdf, account, options); +} +/** + * Resolved to the JSON Keystore Wallet for %%account%% encrypted + * with %%password%%. + * + * The %%options%% can be used to tune the password-based key + * derivation function parameters, explicitly set the random values + * used and provide a [[ProgressCallback]] to receive periodic updates + * on the completion status.. + */ +export async function encryptKeystoreJson(account, password, options) { + if (options == null) { + options = {}; + } + const passwordBytes = getPassword(password); + const kdf = getEncryptKdfParams(options); + const key = await scrypt(passwordBytes, kdf.salt, kdf.N, kdf.r, kdf.p, 64, options.progressCallback); + return _encryptKeystore(getBytes(key), kdf, account, options); +} +//# sourceMappingURL=json-keystore.js.map \ No newline at end of file diff --git a/lib.esm/wallet/json-keystore.js.map b/lib.esm/wallet/json-keystore.js.map new file mode 100644 index 00000000..1dfbb8b7 --- /dev/null +++ b/lib.esm/wallet/json-keystore.js.map @@ -0,0 +1 @@ +{"version":3,"file":"json-keystore.js","sourceRoot":"","sources":["../../src.ts/wallet/json-keystore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAE7B,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACxF,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EACH,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,EAC5D,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAKxD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAGzC,MAAM,WAAW,GAAG,mBAAmB,CAAC;AAgCxC;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,IAAY;IACvC,IAAI;QACA,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC9B,MAAM,OAAO,GAAG,CAAC,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA,CAAC,CAAC,CAAC,CAAC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AAC,GAAG,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AAClE,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,OAAwB,EAAE,QAA6B,EAAE,OAAwB;IACvH,IAAI,OAAO,IAAI,IAAI,EAAE;QAAE,OAAO,GAAG,EAAG,CAAC;KAAE;IAEvC,MAAM,aAAa,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC;IAC5C,MAAM,GAAG,GAAG,mBAAmB,CAAC,OAAO,CAAC,CAAC;IACzC,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,aAAa,EAAE,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC;IACrG,OAAO,gBAAgB,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AAClE,CAAC"} \ No newline at end of file diff --git a/lib.esm/wallet/mnemonic.d.ts b/lib.esm/wallet/mnemonic.d.ts new file mode 100644 index 00000000..b1601122 --- /dev/null +++ b/lib.esm/wallet/mnemonic.d.ts @@ -0,0 +1,65 @@ +import type { BytesLike } from "../utils/index.js"; +import type { Wordlist } from "../wordlists/index.js"; +/** + * A **Mnemonic** wraps all properties required to compute [[link-bip-39]] + * seeds and convert between phrases and entropy. + */ +export declare class Mnemonic { + /** + * The mnemonic phrase of 12, 15, 18, 21 or 24 words. + * + * Use the [[wordlist]] ``split`` method to get the individual words. + */ + readonly phrase: string; + /** + * The password used for this mnemonic. If no password is used this + * is the empty string (i.e. ``""``) as per the specification. + */ + readonly password: string; + /** + * The wordlist for this mnemonic. + */ + readonly wordlist: Wordlist; + /** + * The underlying entropy which the mnemonic encodes. + */ + readonly entropy: string; + /** + * @private + */ + constructor(guard: any, entropy: string, phrase: string, password?: null | string, wordlist?: null | Wordlist); + /** + * Returns the seed for the mnemonic. + */ + computeSeed(): string; + /** + * Creates a new Mnemonic for the %%phrase%%. + * + * The default %%password%% is the empty string and the default + * wordlist is the [English wordlists](LangEn). + */ + static fromPhrase(phrase: string, password?: null | string, wordlist?: null | Wordlist): Mnemonic; + /** + * Create a new **Mnemonic** from the %%entropy%%. + * + * The default %%password%% is the empty string and the default + * wordlist is the [English wordlists](LangEn). + */ + static fromEntropy(_entropy: BytesLike, password?: null | string, wordlist?: null | Wordlist): Mnemonic; + /** + * Returns the phrase for %%mnemonic%%. + */ + static entropyToPhrase(_entropy: BytesLike, wordlist?: null | Wordlist): string; + /** + * Returns the entropy for %%phrase%%. + */ + static phraseToEntropy(phrase: string, wordlist?: null | Wordlist): string; + /** + * Returns true if %%phrase%% is a valid [[link-bip-39]] phrase. + * + * This checks all the provided words belong to the %%wordlist%%, + * that the length is valid and the checksum is correct. + */ + static isValidMnemonic(phrase: string, wordlist?: null | Wordlist): boolean; +} +//# sourceMappingURL=mnemonic.d.ts.map \ No newline at end of file diff --git a/lib.esm/wallet/mnemonic.d.ts.map b/lib.esm/wallet/mnemonic.d.ts.map new file mode 100644 index 00000000..4366dba8 --- /dev/null +++ b/lib.esm/wallet/mnemonic.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"mnemonic.d.ts","sourceRoot":"","sources":["../../src.ts/wallet/mnemonic.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAgGtD;;;GAGG;AACH,qBAAa,QAAQ;IACjB;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAG,MAAM,CAAC;IAEzB;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAG,MAAM,CAAC;IAE3B;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAG,QAAQ,CAAC;IAE7B;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAG,MAAM,CAAC;IAE1B;;OAEG;gBACS,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,IAAI,GAAG,MAAM,EAAE,QAAQ,CAAC,EAAE,IAAI,GAAG,QAAQ;IAO7G;;OAEG;IACH,WAAW,IAAI,MAAM;IAKrB;;;;;OAKG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,IAAI,GAAG,MAAM,EAAE,QAAQ,CAAC,EAAE,IAAI,GAAG,QAAQ,GAAG,QAAQ;IASjG;;;;;OAKG;IACH,MAAM,CAAC,WAAW,CAAC,QAAQ,EAAE,SAAS,EAAE,QAAQ,CAAC,EAAE,IAAI,GAAG,MAAM,EAAE,QAAQ,CAAC,EAAE,IAAI,GAAG,QAAQ,GAAG,QAAQ;IAQvG;;OAEG;IACH,MAAM,CAAC,eAAe,CAAC,QAAQ,EAAE,SAAS,EAAE,QAAQ,CAAC,EAAE,IAAI,GAAG,QAAQ,GAAG,MAAM;IAK/E;;OAEG;IACH,MAAM,CAAC,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,IAAI,GAAG,QAAQ,GAAG,MAAM;IAI1E;;;;;OAKG;IACH,MAAM,CAAC,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,IAAI,GAAG,QAAQ,GAAG,OAAO;CAO9E"} \ No newline at end of file diff --git a/lib.esm/wallet/mnemonic.js b/lib.esm/wallet/mnemonic.js new file mode 100644 index 00000000..56e9fc57 --- /dev/null +++ b/lib.esm/wallet/mnemonic.js @@ -0,0 +1,177 @@ +import { pbkdf2, sha256 } from "../crypto/index.js"; +import { defineProperties, getBytes, hexlify, assertNormalize, assertPrivate, assertArgument, toUtf8Bytes } from "../utils/index.js"; +import { LangEn } from "../wordlists/lang-en.js"; +// Returns a byte with the MSB bits set +function getUpperMask(bits) { + return ((1 << bits) - 1) << (8 - bits) & 0xff; +} +// Returns a byte with the LSB bits set +function getLowerMask(bits) { + return ((1 << bits) - 1) & 0xff; +} +function mnemonicToEntropy(mnemonic, wordlist) { + assertNormalize("NFKD"); + if (wordlist == null) { + wordlist = LangEn.wordlist(); + } + const words = wordlist.split(mnemonic); + assertArgument((words.length % 3) === 0 && words.length >= 12 && words.length <= 24, "invalid mnemonic length", "mnemonic", "[ REDACTED ]"); + const entropy = new Uint8Array(Math.ceil(11 * words.length / 8)); + let offset = 0; + for (let i = 0; i < words.length; i++) { + let index = wordlist.getWordIndex(words[i].normalize("NFKD")); + assertArgument(index >= 0, `invalid mnemonic word at index ${i}`, "mnemonic", "[ REDACTED ]"); + for (let bit = 0; bit < 11; bit++) { + if (index & (1 << (10 - bit))) { + entropy[offset >> 3] |= (1 << (7 - (offset % 8))); + } + offset++; + } + } + const entropyBits = 32 * words.length / 3; + const checksumBits = words.length / 3; + const checksumMask = getUpperMask(checksumBits); + const checksum = getBytes(sha256(entropy.slice(0, entropyBits / 8)))[0] & checksumMask; + assertArgument(checksum === (entropy[entropy.length - 1] & checksumMask), "invalid mnemonic checksum", "mnemonic", "[ REDACTED ]"); + return hexlify(entropy.slice(0, entropyBits / 8)); +} +function entropyToMnemonic(entropy, wordlist) { + assertArgument((entropy.length % 4) === 0 && entropy.length >= 16 && entropy.length <= 32, "invalid entropy size", "entropy", "[ REDACTED ]"); + if (wordlist == null) { + wordlist = LangEn.wordlist(); + } + const indices = [0]; + let remainingBits = 11; + for (let i = 0; i < entropy.length; i++) { + // Consume the whole byte (with still more to go) + if (remainingBits > 8) { + indices[indices.length - 1] <<= 8; + indices[indices.length - 1] |= entropy[i]; + remainingBits -= 8; + // This byte will complete an 11-bit index + } + else { + indices[indices.length - 1] <<= remainingBits; + indices[indices.length - 1] |= entropy[i] >> (8 - remainingBits); + // Start the next word + indices.push(entropy[i] & getLowerMask(8 - remainingBits)); + remainingBits += 3; + } + } + // Compute the checksum bits + const checksumBits = entropy.length / 4; + const checksum = parseInt(sha256(entropy).substring(2, 4), 16) & getUpperMask(checksumBits); + // Shift the checksum into the word indices + indices[indices.length - 1] <<= checksumBits; + indices[indices.length - 1] |= (checksum >> (8 - checksumBits)); + return wordlist.join(indices.map((index) => wordlist.getWord(index))); +} +const _guard = {}; +/** + * A **Mnemonic** wraps all properties required to compute [[link-bip-39]] + * seeds and convert between phrases and entropy. + */ +export class Mnemonic { + /** + * The mnemonic phrase of 12, 15, 18, 21 or 24 words. + * + * Use the [[wordlist]] ``split`` method to get the individual words. + */ + phrase; + /** + * The password used for this mnemonic. If no password is used this + * is the empty string (i.e. ``""``) as per the specification. + */ + password; + /** + * The wordlist for this mnemonic. + */ + wordlist; + /** + * The underlying entropy which the mnemonic encodes. + */ + entropy; + /** + * @private + */ + constructor(guard, entropy, phrase, password, wordlist) { + if (password == null) { + password = ""; + } + if (wordlist == null) { + wordlist = LangEn.wordlist(); + } + assertPrivate(guard, _guard, "Mnemonic"); + defineProperties(this, { phrase, password, wordlist, entropy }); + } + /** + * Returns the seed for the mnemonic. + */ + computeSeed() { + const salt = toUtf8Bytes("mnemonic" + this.password, "NFKD"); + return pbkdf2(toUtf8Bytes(this.phrase, "NFKD"), salt, 2048, 64, "sha512"); + } + /** + * Creates a new Mnemonic for the %%phrase%%. + * + * The default %%password%% is the empty string and the default + * wordlist is the [English wordlists](LangEn). + */ + static fromPhrase(phrase, password, wordlist) { + // Normalize the case and space; throws if invalid + if (wordlist == null) { + wordlist = LangEn.wordlist(); + } + if (password == null) { + password = ""; + } + const entropy = mnemonicToEntropy(phrase, wordlist); + phrase = entropyToMnemonic(getBytes(entropy), wordlist); + return new Mnemonic(_guard, entropy, phrase, password, wordlist); + } + /** + * Create a new **Mnemonic** from the %%entropy%%. + * + * The default %%password%% is the empty string and the default + * wordlist is the [English wordlists](LangEn). + */ + static fromEntropy(_entropy, password, wordlist) { + if (wordlist == null) { + wordlist = LangEn.wordlist(); + } + if (password == null) { + password = ""; + } + const entropy = getBytes(_entropy, "entropy"); + const phrase = entropyToMnemonic(entropy, wordlist); + return new Mnemonic(_guard, hexlify(entropy), phrase, password, wordlist); + } + /** + * Returns the phrase for %%mnemonic%%. + */ + static entropyToPhrase(_entropy, wordlist) { + const entropy = getBytes(_entropy, "entropy"); + return entropyToMnemonic(entropy, wordlist); + } + /** + * Returns the entropy for %%phrase%%. + */ + static phraseToEntropy(phrase, wordlist) { + return mnemonicToEntropy(phrase, wordlist); + } + /** + * Returns true if %%phrase%% is a valid [[link-bip-39]] phrase. + * + * This checks all the provided words belong to the %%wordlist%%, + * that the length is valid and the checksum is correct. + */ + static isValidMnemonic(phrase, wordlist) { + try { + mnemonicToEntropy(phrase, wordlist); + return true; + } + catch (error) { } + return false; + } +} +//# sourceMappingURL=mnemonic.js.map \ No newline at end of file diff --git a/lib.esm/wallet/mnemonic.js.map b/lib.esm/wallet/mnemonic.js.map new file mode 100644 index 00000000..224ff530 --- /dev/null +++ b/lib.esm/wallet/mnemonic.js.map @@ -0,0 +1 @@ +{"version":3,"file":"mnemonic.js","sourceRoot":"","sources":["../../src.ts/wallet/mnemonic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EACH,gBAAgB,EAAE,QAAQ,EAAE,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,cAAc,EAAE,WAAW,EACnG,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAMjD,uCAAuC;AACvC,SAAS,YAAY,CAAC,IAAY;IAC/B,OAAO,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;AACjD,CAAC;AAED,uCAAuC;AACvC,SAAS,YAAY,CAAC,IAAY;IAC/B,OAAO,CAAC,CAAC,C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QACnB,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ"} \ No newline at end of file diff --git a/lib.esm/wallet/musig-crypto.d.ts b/lib.esm/wallet/musig-crypto.d.ts new file mode 100644 index 00000000..72b47676 --- /dev/null +++ b/lib.esm/wallet/musig-crypto.d.ts @@ -0,0 +1,25 @@ +export declare const nobleCrypto: { + pointMultiplyUnsafe: (p: Uint8Array, a: Uint8Array, compress: boolean) => Uint8Array | null; + pointMultiplyAndAddUnsafe: (p1: Uint8Array, a: Uint8Array, p2: Uint8Array, compress: boolean) => Uint8Array | null; + pointAdd: (a: Uint8Array, b: Uint8Array, compress: boolean) => Uint8Array | null; + pointAddTweak: (p: Uint8Array, tweak: Uint8Array, compress: boolean) => Uint8Array | null; + pointCompress: (p: Uint8Array, compress?: boolean) => Uint8Array; + liftX: (p: Uint8Array) => Uint8Array | null; + getPublicKey: (s: Uint8Array, compress: boolean) => Uint8Array | null; + taggedHash: (tag: string, ...messages: Uint8Array[]) => Uint8Array; + sha256: (...messages: Uint8Array[]) => Uint8Array; + readScalar(bytes: Uint8Array): bigint; + readSecret(bytes: Uint8Array): bigint; + isPoint(p: Uint8Array): boolean; + isXOnlyPoint(p: Uint8Array): boolean; + scalarAdd(a: Uint8Array, b: Uint8Array): Uint8Array; + scalarMultiply(a: Uint8Array, b: Uint8Array): Uint8Array; + scalarNegate(a: Uint8Array): Uint8Array; + scalarMod(a: Uint8Array): Uint8Array; + isScalar(t: Uint8Array): boolean; + isSecret(s: Uint8Array): boolean; + pointNegate(p: Uint8Array): Uint8Array; + pointX(p: Uint8Array): Uint8Array; + hasEvenY(p: Uint8Array): boolean; +}; +//# sourceMappingURL=musig-crypto.d.ts.map \ No newline at end of file diff --git a/lib.esm/wallet/musig-crypto.d.ts.map b/lib.esm/wallet/musig-crypto.d.ts.map new file mode 100644 index 00000000..5f2c4ce4 --- /dev/null +++ b/lib.esm/wallet/musig-crypto.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"musig-crypto.d.ts","sourceRoot":"","sources":["../../src.ts/wallet/musig-crypto.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,WAAW;6BAEG,UAAU,KAAK,UAAU,YAAY,OAAO,KAAG,UAAU,GAAG,IAAI;oCAcnF,UAAU,KACX,UAAU,MACT,UAAU,YACJ,OAAO,KAChB,UAAU,GAAG,IAAI;kBAcN,UAAU,KAAK,UAAU,YAAY,OAAO,KAAG,UAAU,GAAG,IAAI;uBAS3D,UAAU,SAAS,UAAU,YAAY,OAAO,KAAG,UAAU,GAAG,IAAI;uBAWpE,UAAU,yBAAoB,UAAU;eAEhD,UAAU,KAAG,UAAU,GAAG,IAAI;sBAOvB,UAAU,YAAY,OAAO,KAAG,UAAU,GAAG,IAAI;;0BAQ7C,UAAU,EAAE,KAAG,UAAU;;;;;;;;;;;;;;CAKhD,CAAC"} \ No newline at end of file diff --git a/lib.esm/wallet/musig-crypto.js b/lib.esm/wallet/musig-crypto.js new file mode 100644 index 00000000..4fa67402 --- /dev/null +++ b/lib.esm/wallet/musig-crypto.js @@ -0,0 +1,77 @@ +import { sha256 } from '@noble/hashes/sha256'; +import { secp256k1, schnorr } from '@noble/curves/secp256k1'; +import * as baseCrypto from './base-crypto'; +export const nobleCrypto = { + ...baseCrypto, + pointMultiplyUnsafe: (p, a, compress) => { + try { + const product = secp256k1.ProjectivePoint.fromHex(p).multiplyAndAddUnsafe(secp256k1.ProjectivePoint.ZERO, BigInt(`0x${Buffer.from(a).toString('hex')}`), BigInt(1)); + if (!product) + return null; + return product.toRawBytes(compress); + } + catch { + return null; + } + }, + pointMultiplyAndAddUnsafe: (p1, a, p2, compress) => { + try { + const p2p = secp256k1.ProjectivePoint.fromHex(p2); + const p = secp256k1.ProjectivePoint.fromHex(p1).multiplyAndAddUnsafe(p2p, BigInt(`0x${Buffer.from(a).toString('hex')}`), BigInt(1)); + if (!p) + return null; + return p.toRawBytes(compress); + } + catch { + return null; + } + }, + pointAdd: (a, b, compress) => { + try { + return secp256k1.ProjectivePoint.fromHex(a) + .add(secp256k1.ProjectivePoint.fromHex(b)) + .toRawBytes(compress); + } + catch { + return null; + } + }, + pointAddTweak: (p, tweak, compress) => { + try { + const P = secp256k1.ProjectivePoint.fromHex(p); + const t = baseCrypto.readSecret(tweak); + const Q = secp256k1.ProjectivePoint.BASE.multiplyAndAddUnsafe(P, t, 1n); + if (!Q) + throw new Error('Tweaked point at infinity'); + return Q.toRawBytes(compress); + } + catch { + return null; + } + }, + pointCompress: (p, compress = true) => secp256k1.ProjectivePoint.fromHex(p).toRawBytes(compress), + liftX: (p) => { + try { + return secp256k1.ProjectivePoint.fromHex(p).toRawBytes(false); + } + catch { + return null; + } + }, + getPublicKey: (s, compress) => { + try { + return secp256k1.getPublicKey(s, compress); + } + catch { + return null; + } + }, + taggedHash: schnorr.utils.taggedHash, + sha256: (...messages) => { + const h = sha256.create(); + for (const message of messages) + h.update(message); + return h.digest(); + }, +}; +//# sourceMappingURL=musig-crypto.js.map \ No newline at end of file diff --git a/lib.esm/wallet/musig-crypto.js.map b/lib.esm/wallet/musig-crypto.js.map new file mode 100644 index 00000000..2d61d3db --- /dev/null +++ b/lib.esm/wallet/musig-crypto.js.map @@ -0,0 +1 @@ +{"version":3,"file":"musig-crypto.js","sourceRoot":"","sources":["../../src.ts/wallet/musig-crypto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,KAAK,UAAU,MAAM,eAAe,CAAC;AAG5C,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,GAAG,UAAU;IACb,mBAAmB,EAAE,CAAC,CAAa,EAAE,CAAa,EAAE,QAAiB,EAAqB,EAAE;QAC1F,IAAI;YACF,MAAM,OAAO,GAAG,SAAS,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,oBAAoB,CACvE,SAAS,CAAC,eAAe,CAAC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Q;YAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAClD,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC;IACpB,CAAC;CACF,CAAC"} \ No newline at end of file diff --git a/lib.esm/wallet/utils.d.ts b/lib.esm/wallet/utils.d.ts new file mode 100644 index 00000000..a2f6a1ff --- /dev/null +++ b/lib.esm/wallet/utils.d.ts @@ -0,0 +1,26 @@ +/** + * @_ignore + */ +import { BytesLike } from "../utils/index.js"; +export declare function looseArrayify(hexString: string): Uint8Array; +export declare function getPassword(password: string | Uint8Array): Uint8Array; +export declare function spelunk(object: any, _path: string): T; +export declare const MasterSecret: Uint8Array; +export declare const HardenedBit = 2147483648; +export declare const N: bigint; +export declare const Nibbles = "0123456789abcdef"; +export declare function zpad(value: string | number, length: number): string; +export declare function encodeBase58Check(_value: BytesLike): string; +export declare function ser_I(index: number, chainCode: string, publicKey: string, privateKey: null | string): { + IL: Uint8Array; + IR: Uint8Array; +}; +type HDNodeLike = { + coinType?: number; + depth: number; + deriveChild: (i: number) => T; + setCoinType?: () => void; +}; +export declare function derivePath>(node: T, path: string): T; +export {}; +//# sourceMappingURL=utils.d.ts.map \ No newline at end of file diff --git a/lib.esm/wallet/utils.d.ts.map b/lib.esm/wallet/utils.d.ts.map new file mode 100644 index 00000000..f762fda4 --- /dev/null +++ b/lib.esm/wallet/utils.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src.ts/wallet/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EACwC,SAAS,EACvD,MAAM,mBAAmB,CAAC;AAE3B,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,UAAU,CAK3D;AAED,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,GAAG,UAAU,CAKrE;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,CA8DxD;AAMD,eAAO,MAAM,YAAY,YAA8E,CAAC;AAExG,eAAO,MAAM,WAAW,aAAa,CAAC;AAEtC,eAAO,MAAM,CAAC,QAA+E,CAAC;AAE9F,eAAO,MAAM,OAAO,qBAAqB,CAAC;AAE1C,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAmBnE;AAID,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,CAK3D;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,GAAG,MAAM,GAAG;IAAE,EAAE,EAAE,UAAU,CAAC;IAAC,EAAE,EAAE,UAAU,CAAA;CAAE,CAqBxI;AAED,KAAK,UAAU,CAAC,CAAC,IAAI;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,CAAC,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,IAAI,CAAA;CAC5F,CAAC;AAEF,wBAAgB,UAAU,CAAC,CAAC,SAAS,UAAU,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,CA4B5E"} \ No newline at end of file diff --git a/lib.esm/wallet/utils.js b/lib.esm/wallet/utils.js new file mode 100644 index 00000000..ca999ba1 --- /dev/null +++ b/lib.esm/wallet/utils.js @@ -0,0 +1,214 @@ +/** + * @_ignore + */ +import { assert, computeHmac, sha256 } from "../quais.js"; +import { getBytesCopy, assertArgument, toUtf8Bytes, concat, dataSlice, encodeBase58, getBytes } from "../utils/index.js"; +export function looseArrayify(hexString) { + if (typeof (hexString) === "string" && !hexString.startsWith("0x")) { + hexString = "0x" + hexString; + } + return getBytesCopy(hexString); +} +export function getPassword(password) { + if (typeof (password) === 'string') { + return toUtf8Bytes(password, "NFKC"); + } + return getBytesCopy(password); +} +export function spelunk(object, _path) { + const match = _path.match(/^([a-z0-9$_.-]*)(:([a-z]+))?(!)?$/i); + assertArgument(match != null, "invalid path", "path", _path); + const path = match[1]; + const type = match[3]; + const reqd = (match[4] === "!"); + let cur = object; + for (const comp of path.toLowerCase().split('.')) { + // Search for a child object with a case-insensitive matching key + if (Array.isArray(cur)) { + if (!comp.match(/^[0-9]+$/)) { + break; + } + cur = cur[parseInt(comp)]; + } + else if (typeof (cur) === "object") { + let found = null; + for (const key in cur) { + if (key.toLowerCase() === comp) { + found = cur[key]; + break; + } + } + cur = found; + } + else { + cur = null; + } + if (cur == null) { + break; + } + } + assertArgument(!reqd || cur != null, "missing required value", "path", path); + if (type && cur != null) { + if (type === "int") { + if (typeof (cur) === "string" && cur.match(/^-?[0-9]+$/)) { + return parseInt(cur); + } + else if (Number.isSafeInteger(cur)) { + return cur; + } + } + if (type === "number") { + if (typeof (cur) === "string" && cur.match(/^-?[0-9.]*$/)) { + return parseFloat(cur); + } + } + if (type === "data") { + if (typeof (cur) === "string") { + return looseArrayify(cur); + } + } + if (type === "array" && Array.isArray(cur)) { + return cur; + } + if (type === typeof (cur)) { + return cur; + } + assertArgument(false, `wrong type found for ${type} `, "path", path); + } + return cur; +} +// HDNODEWallet and UTXO Wallet util methods +// "Bitcoin seed" +export const MasterSecret = new Uint8Array([66, 105, 116, 99, 111, 105, 110, 32, 115, 101, 101, 100]); +export const HardenedBit = 0x80000000; +export const N = BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"); +export const Nibbles = "0123456789abcdef"; +export function zpad(value, length) { + // Determine if the value is hexadecimal + const isHex = typeof value === "string" && value.startsWith("0x"); + // Handle hexadecimal values + if (isHex) { + let hexValue = value.substring(2); // Remove the "0x" prefix + while (hexValue.length < length * 2) { // Hexadecimal characters count double + hexValue = "0" + hexValue; + } + return "0x" + hexValue; + } + // Handle numbers or non-hexadecimal strings + let result = String(value); + while (result.length < length) { + result = '0' + result; + } + return result; +} +export function encodeBase58Check(_value) { + const value = getBytes(_value); + const check = dataSlice(sha256(sha256(value)), 0, 4); + const bytes = concat([value, check]); + return encodeBase58(bytes); +} +export function ser_I(index, chainCode, publicKey, privateKey) { + const data = new Uint8Array(37); + if (index & HardenedBit) { + assert(privateKey != null, "cannot derive child of neutered node", "UNSUPPORTED_OPERATION", { + operation: "deriveChild" + }); + // Data = 0x00 || ser_256(k_par) + data.set(getBytes(privateKey), 1); + } + else { + // Data = ser_p(point(k_par)) + data.set(getBytes(publicKey)); + } + // Data += ser_32(i) + for (let i = 24; i >= 0; i -= 8) { + data[33 + (i >> 3)] = ((index >> (24 - i)) & 0xff); + } + const I = getBytes(computeHmac("sha512", chainCode, data)); + return { IL: I.slice(0, 32), IR: I.slice(32) }; +} +export function derivePath(node, path) { + const components = path.split("/"); + assertArgument(components.length > 0 && (components[0] === "m" || node.depth > 0), "invalid path", "path", path); + if (components[0] === "m") { + components.shift(); + } + let result = node; + for (let i = 0; i < components.length; i++) { + const component = components[i]; + if (component.match(/^[0-9]+'$/)) { + const index = parseInt(component.substring(0, component.length - 1)); + assertArgument(index < HardenedBit, "invalid path index", `path[${i}]`, component); + result = result.deriveChild(HardenedBit + index); + } + else if (component.match(/^[0-9]+$/)) { + const index = parseInt(component); + assertArgument(index < HardenedBit, "invalid path index", `path[${i}]`, component); + result = result.deriveChild(index); + } + else { + assertArgument(false, "invalid path component", `path[${i}]`, component); + } + } + // Extract the coin type from the path and set it on the node + if (result.setCoinType) + result.setCoinType(); + return result; +} +/* +export function follow(object: any, path: string): null | string { + let currentChild = object; + + for (const comp of path.toLowerCase().split('/')) { + + // Search for a child object with a case-insensitive matching key + let matchingChild = null; + for (const key in currentChild) { + if (key.toLowerCase() === comp) { + matchingChild = currentChild[key]; + break; + } + } + + if (matchingChild === null) { return null; } + + currentChild = matchingChild; + } + + return currentChild; +} + +// "path/to/something:type!" +export function followRequired(data: any, path: string): string { + const value = follow(data, path); + if (value != null) { return value; } + return logger.throwArgumentError("invalid value", `data:${ path }`, + JSON.stringify(data)); +} +*/ +// See: https://www.ietf.org/rfc/rfc4122.txt (Section 4.4) +/* +export function uuidV4(randomBytes: BytesLike): string { + const bytes = getBytes(randomBytes, "randomBytes"); + + // Section: 4.1.3: + // - time_hi_and_version[12:16] = 0b0100 + bytes[6] = (bytes[6] & 0x0f) | 0x40; + + // Section 4.4 + // - clock_seq_hi_and_reserved[6] = 0b0 + // - clock_seq_hi_and_reserved[7] = 0b1 + bytes[8] = (bytes[8] & 0x3f) | 0x80; + + const value = hexlify(bytes); + + return [ + value.substring(2, 10), + value.substring(10, 14), + value.substring(14, 18), + value.substring(18, 22), + value.substring(22, 34), + ].join("-"); +} +*/ +//# sourceMappingURL=utils.js.map \ No newline at end of file diff --git a/lib.esm/wallet/utils.js.map b/lib.esm/wallet/utils.js.map new file mode 100644 index 00000000..44541750 --- /dev/null +++ b/lib.esm/wallet/utils.js.map @@ -0,0 +1 @@ +{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src.ts/wallet/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EACH,YAAY,EAAE,cAAc,EAAE,WAAW,EAAa,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,QAAQ,EAClG,MAAM,mBAAmB,CAAC;AAE3B,MAAM,UAAU,aAAa,CAAC,SAAiB;IAC3C,IAAI,OAAM,CAAC,SAAS,CAAC,KAAK,QAAQ,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QAC/D,SAAS,GAAG,IAAI,GAAG,SAAS,CAAC;KAChC;IACD,OAAO,YAAY,CAAC,SAAS,CAAC,CAAC;AACnC,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,QAA6B;IACrD,IAAI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AAM,CAAC,WAAW;QAAE,MAAM,CAAC,WAAW,EAAE,CAAC;IAC7C,OAAO,MAAM,CAAC;AAClB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8BE;AACF,0DAA0D;AAC1D;;;;;;;;;;;;;;;;;;;;;;;EAuBE"} \ No newline at end of file diff --git a/lib.esm/wallet/utxohdwallet.d.ts b/lib.esm/wallet/utxohdwallet.d.ts new file mode 100644 index 00000000..957f9e53 --- /dev/null +++ b/lib.esm/wallet/utxohdwallet.d.ts @@ -0,0 +1,97 @@ +import { SigningKey } from "../crypto/index.js"; +import { Numeric, Provider, TransactionRequest, Wordlist } from '../quais.js'; +import { Mnemonic } from './mnemonic.js'; +import { BaseWallet } from "./base-wallet.js"; +interface UTXOAddress { + pubKey: string; + privKey: string; +} +export declare class UTXOHDWallet extends BaseWallet { + #private; + /** + * The fingerprint. + * + * A fingerprint allows quick qay to detect parent and child nodes, + * but developers should be prepared to deal with collisions as it + * is only 4 bytes. + */ + readonly fingerprint: string; + /** + * The parent fingerprint. + */ + readonly accountFingerprint: string; + /** + * The mnemonic used to create this HD Node, if available. + * + * Sources such as extended keys do not encode the mnemonic, in + * which case this will be ``null``. + */ + readonly mnemonic: null | Mnemonic; + /** + * The chaincode, which is effectively a public key used + * to derive children. + */ + readonly chainCode: string; + /** + * The derivation path of this wallet. + * + * Since extended keys do not provider full path details, this + * may be ``null``, if instantiated from a source that does not + * enocde it. + */ + readonly path: null | string; + /** + * The child index of this wallet. Values over ``2 *\* 31`` indicate + * the node is hardened. + */ + readonly index: number; + /** + * The depth of this wallet, which is the number of components + * in its path. + */ + readonly depth: number; + coinType?: number; + get utxoAddresses(): UTXOAddress[]; + set utxoAddresses(addresses: UTXOAddress[]); + /** + * Gets the current publicKey + */ + get publicKey(): string; + /** + * @private + */ + constructor(guard: any, signingKey: SigningKey, accountFingerprint: string, chainCode: string, path: null | string, index: number, depth: number, mnemonic: null | Mnemonic, provider: null | Provider); + connect(provider: null | Provider): UTXOHDWallet; + derivePath(path: string): UTXOHDWallet; + setCoinType(): void; + /** + * Creates a new random HDNode. + */ + static createRandom(path: string, password?: string, wordlist?: Wordlist): UTXOHDWallet; + /** + * Create an HD Node from %%mnemonic%%. + */ + static fromMnemonic(mnemonic: Mnemonic, path: string): UTXOHDWallet; + /** + * Creates an HD Node from a mnemonic %%phrase%%. + */ + static fromPhrase(phrase: string, path: string, password?: string, wordlist?: Wordlist): UTXOHDWallet; + /** + * Checks if the provided BIP44 path is valid and limited to the change level. + * @param path The BIP44 path to check. + * @returns true if the path is valid and does not include the address_index; false otherwise. + */ + static isValidPath(path: string): boolean; + /** + * Return the child for %%index%%. + */ + deriveChild(_index: Numeric): UTXOHDWallet; + generateUTXOs(zone: string, gap?: number): Promise; + /** + * Derives address by incrementing address_index according to BIP44 + */ + deriveAddress(index: number, zone?: string): UTXOHDWallet; + signTransaction(tx: TransactionRequest): Promise; +} +export {}; +//# sourceMappingURL=utxohdwallet.d.ts.map \ No newline at end of file diff --git a/lib.esm/wallet/utxohdwallet.d.ts.map b/lib.esm/wallet/utxohdwallet.d.ts.map new file mode 100644 index 00000000..b4d6cc3a --- /dev/null +++ b/lib.esm/wallet/utxohdwallet.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"utxohdwallet.d.ts","sourceRoot":"","sources":["../../src.ts/wallet/utxohdwallet.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAa,OAAO,EAAE,QAAQ,EAAgC,kBAAkB,EAAE,QAAQ,EAA4M,MAAM,aAAa,CAAC;AACjU,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAM9C,UAAU,WAAW;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACnB;AAKD,qBAAa,YAAa,SAAQ,UAAU;;IAMvC;;;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I,EAAE,MAAM,GAAG,YAAY;IAKnE;;OAEG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,YAAY;IAMrG;;;;OAIG;IACH,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAOzC;;OAEG;IACH,WAAW,CAAC,MAAM,EAAE,OAAO,GAAG,YAAY;IA6BpC,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,GAAE,MAAW;IAoClD;;OAEG;IACH,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,YAAY;IA4BnD,eAAe,CAAC,EAAE,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC;CAsDjE"} \ No newline at end of file diff --git a/lib.esm/wallet/utxohdwallet.js b/lib.esm/wallet/utxohdwallet.js new file mode 100644 index 00000000..e209d4f6 --- /dev/null +++ b/lib.esm/wallet/utxohdwallet.js @@ -0,0 +1,274 @@ +import { N, ShardData } from '../constants'; +import { SigningKey } from "../crypto/index.js"; +import { Transaction, assertArgument, assertPrivate, computeHmac, dataSlice, defineProperties, getBytes, getNumber, getShardForAddress, hexlify, isBytesLike, isUTXOAddress, randomBytes, ripemd160, sha256, toBeHex, toBigInt } from '../quais.js'; +import { Mnemonic } from './mnemonic.js'; +import { HardenedBit, derivePath, ser_I } from './utils.js'; +import { BaseWallet } from "./base-wallet.js"; +import { MuSigFactory } from "@brandonblack/musig"; +import { nobleCrypto } from "./musig-crypto.js"; +import { schnorr } from "@noble/curves/secp256k1"; +import { keccak_256 } from "@noble/hashes/sha3"; +const MasterSecret = new Uint8Array([66, 105, 116, 99, 111, 105, 110, 32, 115, 101, 101, 100]); +const _guard = {}; +export class UTXOHDWallet extends BaseWallet { + /** + * The compressed public key. + */ + #publicKey; + /** + * The fingerprint. + * + * A fingerprint allows quick qay to detect parent and child nodes, + * but developers should be prepared to deal with collisions as it + * is only 4 bytes. + */ + fingerprint; + /** + * The parent fingerprint. + */ + accountFingerprint; + /** + * The mnemonic used to create this HD Node, if available. + * + * Sources such as extended keys do not encode the mnemonic, in + * which case this will be ``null``. + */ + mnemonic; + /** + * The chaincode, which is effectively a public key used + * to derive children. + */ + chainCode; + /** + * The derivation path of this wallet. + * + * Since extended keys do not provider full path details, this + * may be ``null``, if instantiated from a source that does not + * enocde it. + */ + path; + /** + * The child index of this wallet. Values over ``2 *\* 31`` indicate + * the node is hardened. + */ + index; + /** + * The depth of this wallet, which is the number of components + * in its path. + */ + depth; + coinType; + /** + * array of addresses/priv keys this current wallet is aware of that were + * generated by incrementing addressindex in bip44 until specified gap rule + */ + #utxoAddresses = []; + get utxoAddresses() { + return this.#utxoAddresses; + } + set utxoAddresses(addresses) { + this.#utxoAddresses = addresses; + } + /** + * Gets the current publicKey + */ + get publicKey() { + return this.#publicKey; + } + /** + * @private + */ + constructor(guard, signingKey, accountFingerprint, chainCode, path, index, depth, mnemonic, provider) { + super(signingKey, provider); + assertPrivate(guard, _guard); + this.#publicKey = signingKey.compressedPublicKey; + const fingerprint = dataSlice(ripemd160(sha256(this.#publicKey)), 0, 4); + defineProperties(this, { + accountFingerprint, fingerprint, + chainCode, path, index, depth + }); + defineProperties(this, { mnemonic }); + } + connect(provider) { + return new UTXOHDWallet(_guard, this.signingKey, this.accountFingerprint, this.chainCode, this.path, this.index, this.depth, this.mnemonic, provider); + } + derivePath(path) { + return derivePath(this, path); + } + static #fromSeed(_seed, mnemonic) { + assertArgument(isBytesLike(_seed), "invalid seed", "seed", "[REDACTED]"); + const seed = getBytes(_seed, "seed"); + assertArgument(seed.length >= 16 && seed.length <= 64, "invalid seed", "seed", "[REDACTED]"); + const I = getBytes(computeHmac("sha512", MasterSecret, seed)); + const signingKey = new SigningKey(hexlify(I.slice(0, 32))); + const result = new UTXOHDWallet(_guard, signingKey, "0x00000000", hexlify(I.slice(32)), "m", 0, 0, mnemonic, null); + return result; + } + setCoinType() { + this.coinType = Number(this.path?.split("/")[2].replace("'", "")); + } + /** + * Creates a new random HDNode. + */ + static createRandom(path, password, wordlist) { + if (path == null || !this.isValidPath(path)) { + throw new Error('Invalid path: ' + path); + } + const mnemonic = Mnemonic.fromEntropy(randomBytes(16), password, wordlist); + return UTXOHDWallet.#fromSeed(mnemonic.computeSeed(), mnemonic).derivePath(path); + } + /** + * Create an HD Node from %%mnemonic%%. + */ + static fromMnemonic(mnemonic, path) { + if (path == null || !this.isValidPath(path)) { + throw new Error('Invalid path: ' + path); + } + return UTXOHDWallet.#fromSeed(mnemonic.computeSeed(), mnemonic).derivePath(path); + } + /** + * Creates an HD Node from a mnemonic %%phrase%%. + */ + static fromPhrase(phrase, path, password, wordlist) { + if (path == null || !this.isValidPath(path)) { + throw new Error('Invalid path: ' + path); + } + const mnemonic = Mnemonic.fromPhrase(phrase, password, wordlist); + return UTXOHDWallet.#fromSeed(mnemonic.computeSeed(), mnemonic).derivePath(path); + } + /** + * Checks if the provided BIP44 path is valid and limited to the change level. + * @param path The BIP44 path to check. + * @returns true if the path is valid and does not include the address_index; false otherwise. + */ + static isValidPath(path) { + // BIP44 path regex pattern for up to the 'change' level, excluding 'address_index' + // This pattern matches paths like "m/44'/0'/0'/0" and "m/44'/60'/0'/1", but not "m/44'/60'/0'/0/0" + const pathRegex = /^m\/44'\/\d+'\/\d+'\/[01]$/; + return pathRegex.test(path); + } + /** + * Return the child for %%index%%. + */ + deriveChild(_index) { + const index = getNumber(_index, "index"); + assertArgument(index <= 0xffffffff, "invalid index", "index", index); + // Base path + let newDepth = this.depth + 1; + let path = this.path; + if (path) { + let pathFields = path.split("/"); + if (pathFields.length == 6) { + pathFields.pop(); + path = pathFields.join("/"); + newDepth--; + } + path += "/" + (index & ~HardenedBit); + if (index & HardenedBit) { + path += "'"; + } + } + const { IR, IL } = ser_I(index, this.chainCode, this.#publicKey, this.privateKey); + const ki = new SigningKey(toBeHex((toBigInt(IL) + BigInt(this.privateKey)) % N, 32)); + //BIP44 if we are at the account depth get that fingerprint, otherwise continue with the current one + let newFingerprint = this.depth == 3 ? this.fingerprint : this.accountFingerprint; + return new UTXOHDWallet(_guard, ki, newFingerprint, hexlify(IR), path, index, newDepth, this.mnemonic, this.provider); + } + async generateUTXOs(zone, gap = 20) { + zone = zone.toLowerCase(); + // Check if zone is valid + const shard = ShardData.find(shard => shard.name.toLowerCase() === zone || shard.nickname.toLowerCase() === zone || shard.byte.toLowerCase() === zone); + if (!shard) { + throw new Error("Invalid zone"); + } + /* + generate addresses by incrementing address index in bip44 + check each address for utxos and add to utxoAddresses + until we have had gap limit number of addresses with no utxos + */ + let currentUtxoAddresses = []; + let empty = 0; + let accIndex = 0; + while (empty < gap) { + const wallet = this.deriveAddress(accIndex, zone); + const pubKey = wallet.address; + const privKey = wallet.privateKey; + /*check available utxos throught node JSONRPC call + if we have utxos at this address add it to currentUtxoAddresses + */ + currentUtxoAddresses.push({ pubKey, privKey }); + //reset empty = 0 + //else increment empty untill we have gap amount + empty++; + //increment addrIndex in bip44 always + accIndex++; + } + this.utxoAddresses = currentUtxoAddresses; + } + /** + * Derives address by incrementing address_index according to BIP44 + */ + deriveAddress(index, zone) { + if (!this.path) + throw new Error("Missing Path"); + //Case for a non quai/qi wallet where zone is not needed + if (!zone) { + return this.derivePath(this.path + "/" + index.toString()); + } + zone = zone.toLowerCase(); + // Check if zone is valid + const shard = ShardData.find(shard => shard.name.toLowerCase() === zone || shard.nickname.toLowerCase() === zone || shard.byte.toLowerCase() === zone); + if (!shard) { + throw new Error("Invalid zone"); + } + let newWallet; + let addrIndex = 0; + let zoneIndex = index + 1; + do { + newWallet = this.derivePath(addrIndex.toString()); + if (getShardForAddress(newWallet.address) == shard && ((newWallet.coinType == 969) == isUTXOAddress(newWallet.address))) + zoneIndex--; + addrIndex++; + } while (zoneIndex > 0); + return newWallet; + } + async signTransaction(tx) { + const txobj = Transaction.from(tx); + if (!txobj.inputsUTXO || !txobj.outputsUTXO) + throw new Error('Invalid UTXO transaction, missing inputs or outputs'); + const hash = keccak_256(txobj.unsignedSerialized); + const musig = MuSigFactory(nobleCrypto); + if (txobj.inputsUTXO.length == 1) { + const pubKey = txobj.inputsUTXO[0].address; + const privKey = this.utxoAddresses.find(utxoAddr => utxoAddr.pubKey === pubKey)?.privKey; + if (!privKey) + throw new Error(`Missing private key for ${pubKey}`); + const signature = schnorr.sign(hash, BigInt(privKey)); + return hexlify(signature); + } + else { + const privKeys = txobj.inputsUTXO.map(input => { + const utxoAddrObj = this.utxoAddresses.find(utxoAddr => utxoAddr.pubKey === input.address); + return utxoAddrObj ? utxoAddrObj.privKey : null; + }).filter(privKey => privKey !== null); + const pubKeys = privKeys.map(privKey => nobleCrypto.getPublicKey(getBytes(privKey), true)).filter(pubKey => pubKey !== null); + //const aggPublicKey = musig.getPlainPubkey(musig.keyAgg(pubKeys)); + const nonces = pubKeys.map(pk => musig.nonceGen({ publicKey: getBytes(pk) })); + const aggNonce = musig.nonceAgg(nonces); + const signingSession = musig.startSigningSession(aggNonce, hash, pubKeys); + //Each signer creates a partial signature + const partialSignatures = privKeys.map((sk, index) => musig.partialSign({ + secretKey: getBytes(sk || ''), + publicNonce: nonces[index], + sessionKey: signingSession, + verify: true + })); + // Aggregate the partial signatures into a final aggregated signature + const finalSignature = musig.signAgg(partialSignatures, signingSession); + // //Verify signature using schnorr + // const isValid = schnorr.verify(finalSignature, hash, aggPublicKey); + return hexlify(finalSignature); + } + } +} +//# sourceMappingURL=utxohdwallet.js.map \ No newline at end of file diff --git a/lib.esm/wallet/utxohdwallet.js.map b/lib.esm/wallet/utxohdwallet.js.map new file mode 100644 index 00000000..80c9d9b7 --- /dev/null +++ b/lib.esm/wallet/utxohdwallet.js.map @@ -0,0 +1 @@ +{"version":3,"file":"utxohdwallet.js","sourceRoot":"","sources":["../../src.ts/wallet/utxohdwallet.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CA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CAAC;YAEvC,MAAM,OAAO,GAAiB,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,WAAW,CAAC,YAAY,CAAC,QAAQ,CAAC,OAAQ,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,KAAK,IAAI,CAAiB,CAAC;YAE5J,mEAAmE;YAEnE,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAC,SAAS,EAAE,QAAQ,CAAC,EAAG,CAAC,EAAC,CAAC,CAAC,CAAC;YAC7E,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;YAExC,MAAM,cAAc,GAAG,KAAK,CAAC,mBAAmB,CAC5C,QAAQ,EACR,IAAI,EACJ,OAAO,CACV,CAAC;YAEF,yCAAyC;YACzC,MAAM,iBAAiB,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE,CACjD,KAAK,CAAC,WAAW,CAAC;gBACd,SAAS,EAAE,QAAQ,CAAC,EAAE,IAAI,EAAE,CAAC;gBAC7B,WAAW,EAAE,MAAM,CAAC,KAAK,CAAC;gBAC1B,UAAU,EAAE,cAAc;gBAC1B,MAAM,EAAE,IAAI;aACf,CAAC,CACL,CAAC;YAEF,qEAAqE;YACrE,MAAM,cAAc,GAAG,KAAK,CAAC,OAAO,CAAC,iBAAiB,EAAE,cAAc,CAAC,CAAC;YAExE,mCAAmC;YACnC,sEAAsE;YACrE,OAAO,OAAO,CAAC,cAAc,CAAC,CAAC;SACnC;IACL,CAAC;CACJ"} \ No newline at end of file diff --git a/lib.esm/wallet/wallet.d.ts b/lib.esm/wallet/wallet.d.ts new file mode 100644 index 00000000..9f7a44ef --- /dev/null +++ b/lib.esm/wallet/wallet.d.ts @@ -0,0 +1,73 @@ +import { SigningKey } from "../crypto/index.js"; +import { BaseWallet } from "./base-wallet.js"; +import { HDNodeWallet } from "./hdwallet.js"; +import type { ProgressCallback } from "../crypto/index.js"; +import type { Provider } from "../providers/index.js"; +import type { Wordlist } from "../quais.js"; +import { UTXOHDWallet } from "./utxohdwallet.js"; +/** + * A **Wallet** manages a single private key which is used to sign + * transactions, messages and other common payloads. + * + * This class is generally the main entry point for developers + * that wish to use a private key directly, as it can create + * instances from a large variety of common sources, including + * raw private key, [[link-bip-39]] mnemonics and encrypte JSON + * wallets. + */ +export declare class Wallet extends BaseWallet { + #private; + /** + * Create a new wallet for the private %%key%%, optionally connected + * to %%provider%%. + */ + constructor(key: string | SigningKey, provider?: null | Provider); + connect(provider: null | Provider): Wallet; + /** + * Resolves to a [JSON Keystore Wallet](json-wallets) encrypted with + * %%password%%. + * + * If %%progressCallback%% is specified, it will receive periodic + * updates as the encryption process progreses. + */ + encrypt(password: Uint8Array | string, progressCallback?: ProgressCallback): Promise; + /** + * Returns a [JSON Keystore Wallet](json-wallets) encryped with + * %%password%%. + * + * It is preferred to use the [async version](encrypt) instead, + * which allows a [[ProgressCallback]] to keep the user informed. + * + * This method will block the event loop (freezing all UI) until + * it is complete, which may be a non-trivial duration. + */ + encryptSync(password: Uint8Array | string): string; + /** + * Creates (asynchronously) a **Wallet** by decrypting the %%json%% + * with %%password%%. + * + * If %%progress%% is provided, it is called periodically during + * decryption so that any UI can be updated. + */ + static fromEncryptedJson(json: string, password: Uint8Array | string, progress?: ProgressCallback): Promise; + /** + * Creates a **Wallet** by decrypting the %%json%% with %%password%%. + * + * The [[fromEncryptedJson]] method is preferred, as this method + * will lock up and freeze the UI during decryption, which may take + * some time. + */ + static fromEncryptedJsonSync(json: string, password: Uint8Array | string): HDNodeWallet | Wallet; + /** + * Creates a new random [[HDNodeWallet]] using the available + * [cryptographic random source](randomBytes). + * + * If there is no crytographic random source, this will throw. + */ + static createRandom(path: string, provider?: null | Provider): HDNodeWallet; + /**"m/44'/60'/0'/0/0" + * Creates a [[HDNodeWallet]] for %%phrase%%. + */ + static fromPhrase(phrase: string, path: string, provider?: Provider, wordlist?: Wordlist): HDNodeWallet | UTXOHDWallet; +} +//# sourceMappingURL=wallet.d.ts.map \ No newline at end of file diff --git a/lib.esm/wallet/wallet.d.ts.map b/lib.esm/wallet/wallet.d.ts.map new file mode 100644 index 00000000..acf35113 --- /dev/null +++ b/lib.esm/wallet/wallet.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src.ts/wallet/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGhD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAS7C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAG5C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAOjD;;;;;;;;;GASG;AACH,qBAAa,MAAO,SAAQ,UAAU;;IAElC;;;OAGG;gBACS,GAAG,EAAE,MAAM,GAAG,UAAU,EAAE,QAAQ,CAAC,EAAE,IAAI,GAAG,QAAQ;IAShE,OAAO,CAAC,QAAQ,EAAE,IAAI,GAAG,QAAQ,GAAG,MAAM;IAI1C;;;;;;OAMG;IACG,OAAO,CAAC,QAAQ,EAAE,UAAU,GAAG,MAAM,EAAE,gBAAgB,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC;IAKlG;;;;;;;;;OASG;IACH,WAAW,CAAC,QAAQ,EAAE,UAAU,GAAG,MAAM,GAAG,MAAM;IAyBlD;;;;;;OAMG;WACU,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,GAAG,MAAM,EAAE,QAAQ,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,YAAY,GAAG,MAAM,CAAC;IAexI;;;;;;OAMG;IACH,MAAM,CAAC,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,GAAG,MAAM,GAAG,YAAY,GAAG,MAAM;IAahG;;;;;OAKG;IACH,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,IAAI,GAAG,QAAQ,GAAG,YAAY;IAM3E;;OAEG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,YAAY,GAAG,YAAY;CAqBzH"} \ No newline at end of file diff --git a/lib.esm/wallet/wallet.js b/lib.esm/wallet/wallet.js new file mode 100644 index 00000000..8c321049 --- /dev/null +++ b/lib.esm/wallet/wallet.js @@ -0,0 +1,163 @@ +import { SigningKey } from "../crypto/index.js"; +import { assertArgument } from "../utils/index.js"; +import { BaseWallet } from "./base-wallet.js"; +import { HDNodeWallet } from "./hdwallet.js"; +import { decryptCrowdsaleJson, isCrowdsaleJson } from "./json-crowdsale.js"; +import { decryptKeystoreJson, decryptKeystoreJsonSync, encryptKeystoreJson, encryptKeystoreJsonSync, isKeystoreJson } from "./json-keystore.js"; +import { Mnemonic } from "./mnemonic.js"; +import { UTXOHDWallet } from "./utxohdwallet.js"; +function stall(duration) { + return new Promise((resolve) => { setTimeout(() => { resolve(); }, duration); }); +} +/** + * A **Wallet** manages a single private key which is used to sign + * transactions, messages and other common payloads. + * + * This class is generally the main entry point for developers + * that wish to use a private key directly, as it can create + * instances from a large variety of common sources, including + * raw private key, [[link-bip-39]] mnemonics and encrypte JSON + * wallets. + */ +export class Wallet extends BaseWallet { + /** + * Create a new wallet for the private %%key%%, optionally connected + * to %%provider%%. + */ + constructor(key, provider) { + if (typeof (key) === "string" && !key.startsWith("0x")) { + key = "0x" + key; + } + let signingKey = (typeof (key) === "string") ? new SigningKey(key) : key; + super(signingKey, provider); + } + connect(provider) { + return new Wallet(this.signingKey, provider); + } + /** + * Resolves to a [JSON Keystore Wallet](json-wallets) encrypted with + * %%password%%. + * + * If %%progressCallback%% is specified, it will receive periodic + * updates as the encryption process progreses. + */ + async encrypt(password, progressCallback) { + const account = { address: this.address, privateKey: this.privateKey }; + return await encryptKeystoreJson(account, password, { progressCallback }); + } + /** + * Returns a [JSON Keystore Wallet](json-wallets) encryped with + * %%password%%. + * + * It is preferred to use the [async version](encrypt) instead, + * which allows a [[ProgressCallback]] to keep the user informed. + * + * This method will block the event loop (freezing all UI) until + * it is complete, which may be a non-trivial duration. + */ + encryptSync(password) { + const account = { address: this.address, privateKey: this.privateKey }; + return encryptKeystoreJsonSync(account, password); + } + static #fromAccount(account) { + assertArgument(account, "invalid JSON wallet", "json", "[ REDACTED ]"); + if ("mnemonic" in account && account.mnemonic && account.mnemonic.locale === "en") { + const mnemonic = Mnemonic.fromEntropy(account.mnemonic.entropy); + const wallet = HDNodeWallet.fromMnemonic(mnemonic, account.mnemonic.path || ''); // Add a check for undefined path + if (wallet.address === account.address && wallet.privateKey === account.privateKey) { + return wallet; + } + console.log("WARNING: JSON mismatch address/privateKey != mnemonic; fallback onto private key"); + } + const wallet = new Wallet(account.privateKey); + assertArgument(wallet.address === account.address, "address/privateKey mismatch", "json", "[ REDACTED ]"); + return wallet; + } + /** + * Creates (asynchronously) a **Wallet** by decrypting the %%json%% + * with %%password%%. + * + * If %%progress%% is provided, it is called periodically during + * decryption so that any UI can be updated. + */ + static async fromEncryptedJson(json, password, progress) { + let account = null; + if (isKeystoreJson(json)) { + account = await decryptKeystoreJson(json, password, progress); + } + else if (isCrowdsaleJson(json)) { + if (progress) { + progress(0); + await stall(0); + } + account = decryptCrowdsaleJson(json, password); + if (progress) { + progress(1); + await stall(0); + } + } + return Wallet.#fromAccount(account); + } + /** + * Creates a **Wallet** by decrypting the %%json%% with %%password%%. + * + * The [[fromEncryptedJson]] method is preferred, as this method + * will lock up and freeze the UI during decryption, which may take + * some time. + */ + static fromEncryptedJsonSync(json, password) { + let account = null; + if (isKeystoreJson(json)) { + account = decryptKeystoreJsonSync(json, password); + } + else if (isCrowdsaleJson(json)) { + account = decryptCrowdsaleJson(json, password); + } + else { + assertArgument(false, "invalid JSON wallet", "json", "[ REDACTED ]"); + } + return Wallet.#fromAccount(account); + } + /** + * Creates a new random [[HDNodeWallet]] using the available + * [cryptographic random source](randomBytes). + * + * If there is no crytographic random source, this will throw. + */ + static createRandom(path, provider) { + const wallet = HDNodeWallet.createRandom(path); + if (provider) { + return wallet.connect(provider); + } + return wallet; + } + /**"m/44'/60'/0'/0/0" + * Creates a [[HDNodeWallet]] for %%phrase%%. + */ + static fromPhrase(phrase, path, provider, wordlist) { + const splitPath = path.split('/'); + if (splitPath.length < 3) + throw new Error(`Incomplete path for wallet derivation ${path}`); + let coinTypeStr = splitPath[2]; + coinTypeStr = coinTypeStr.replace("'", ""); + const coinType = parseInt(coinTypeStr); + let wallet; + switch (coinType) { + case 994: + wallet = HDNodeWallet.fromPhrase(phrase, path, undefined, wordlist); + if (provider) { + return wallet.connect(provider); + } + return wallet; + case 969: + wallet = UTXOHDWallet.fromPhrase(phrase, path, undefined, wordlist); + if (provider) { + return wallet.connect(provider); + } + return wallet; + default: + throw new Error(`Unsupported cointype ${coinType} for HD wallet derivation`); + } + } +} +//# sourceMappingURL=wallet.js.map \ No newline at end of file diff --git a/lib.esm/wallet/wallet.js.map b/lib.esm/wallet/wallet.js.map new file mode 100644 index 00000000..dcc668d1 --- /dev/null +++ b/lib.esm/wallet/wallet.js.map @@ -0,0 +1 @@ +{"version":3,"file":"wallet.js","sourceRoot":"","sources":["../../src.ts/wallet/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,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MAAM,CAAC;YAClB;gBACI,MAAM,IAAI,KAAK,CAAC,wBAAwB,QAAQ,2BAA2B,CAAC,CAAC;SACpF;IACL,CAAC;CACJ"} \ No newline at end of file diff --git a/lib.esm/wordlists/bit-reader.d.ts b/lib.esm/wordlists/bit-reader.d.ts new file mode 100644 index 00000000..1aa84953 --- /dev/null +++ b/lib.esm/wordlists/bit-reader.d.ts @@ -0,0 +1,5 @@ +/** + * @_ignore + */ +export declare function decodeBits(width: number, data: string): Array; +//# sourceMappingURL=bit-reader.d.ts.map \ No newline at end of file diff --git a/lib.esm/wordlists/bit-reader.d.ts.map b/lib.esm/wordlists/bit-reader.d.ts.map new file mode 100644 index 00000000..c088a746 --- /dev/null +++ b/lib.esm/wordlists/bit-reader.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"bit-reader.d.ts","sourceRoot":"","sources":["../../src.ts/wordlists/bit-reader.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CA6BrE"} \ No newline at end of file diff --git a/lib.esm/wordlists/bit-reader.js b/lib.esm/wordlists/bit-reader.js new file mode 100644 index 00000000..bf530314 --- /dev/null +++ b/lib.esm/wordlists/bit-reader.js @@ -0,0 +1,32 @@ +const Base64 = ")!@#$%^&*(ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_"; +/** + * @_ignore + */ +export function decodeBits(width, data) { + const maxValue = (1 << width) - 1; + const result = []; + let accum = 0, bits = 0, flood = 0; + for (let i = 0; i < data.length; i++) { + // Accumulate 6 bits of data + accum = ((accum << 6) | Base64.indexOf(data[i])); + bits += 6; + // While we have enough for a word... + while (bits >= width) { + // ...read the word + const value = (accum >> (bits - width)); + accum &= (1 << (bits - width)) - 1; + bits -= width; + // A value of 0 indicates we exceeded maxValue, it + // floods over into the next value + if (value === 0) { + flood += maxValue; + } + else { + result.push(value + flood); + flood = 0; + } + } + } + return result; +} +//# sourceMappingURL=bit-reader.js.map \ No newline at end of file diff --git a/lib.esm/wordlists/bit-reader.js.map b/lib.esm/wordlists/bit-reader.js.map new file mode 100644 index 00000000..79f3e876 --- /dev/null +++ b/lib.esm/wordlists/bit-reader.js.map @@ -0,0 +1 @@ +{"version":3,"file":"bit-reader.js","sourceRoot":"","sources":["../../src.ts/wordlists/bit-reader.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,kEAAkE,CAAC;AAElF;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,KAAa,EAAE,IAAY;IAClD,MAAM,QAAQ,GAAG,CAAC,CAAC,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;IAClC,MAAM,MAAM,GAAkB,EAAG,CAAC;IAClC,IAAI,KAAK,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC;IACnC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QAElC,4BAA4B;QAC5B,KAAK,GAAG,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACjD,IAAI,IAAI,CAAC,CAAC;QAEV,qCAAqC;QACrC,OAAO,IAAI,IAAI,KAAK,EAAE;YAClB,mBAAmB;YACnB,MAAM,KAAK,GAAG,CAAC,KAAK,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC;YACxC,KAAK,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC;YACnC,IAAI,IAAI,KAAK,CAAC;YAEd,kDAAkD;YAClD,kCAAkC;YAClC,IAAI,KAAK,KAAK,CAAC,EAAE;gBACb,KAAK,IAAI,QAAQ,CAAC;aACrB;iBAAM;gBACH,MAAM,CAAC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC;gBAC3B,KAAK,GAAG,CAAC,CAAC;aACb;SACJ;KACJ;IAED,OAAO,MAAM,CAAC;AAClB,CAAC"} \ No newline at end of file diff --git a/lib.esm/wordlists/decode-owl.d.ts b/lib.esm/wordlists/decode-owl.d.ts new file mode 100644 index 00000000..8822086b --- /dev/null +++ b/lib.esm/wordlists/decode-owl.d.ts @@ -0,0 +1,9 @@ +/** + * @_ignore + */ +export declare function decode(data: string, subs: string): Array; +/** + * @_ignore + */ +export declare function decodeOwl(data: string): Array; +//# sourceMappingURL=decode-owl.d.ts.map \ No newline at end of file diff --git a/lib.esm/wordlists/decode-owl.d.ts.map b/lib.esm/wordlists/decode-owl.d.ts.map new file mode 100644 index 00000000..aa692891 --- /dev/null +++ b/lib.esm/wordlists/decode-owl.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"decode-owl.d.ts","sourceRoot":"","sources":["../../src.ts/wordlists/decode-owl.ts"],"names":[],"mappings":"AAqBA;;GAEG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAsBhE;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAMrD"} \ No newline at end of file diff --git a/lib.esm/wordlists/decode-owl.js b/lib.esm/wordlists/decode-owl.js new file mode 100644 index 00000000..fe636fde --- /dev/null +++ b/lib.esm/wordlists/decode-owl.js @@ -0,0 +1,55 @@ +import { assertArgument } from "../utils/index.js"; +const subsChrs = " !#$%&'()*+,-./<=>?@[]^_`{|}~"; +const Word = /^[a-z]*$/i; +function unfold(words, sep) { + let initial = 97; + return words.reduce((accum, word) => { + if (word === sep) { + initial++; + } + else if (word.match(Word)) { + accum.push(String.fromCharCode(initial) + word); + } + else { + initial = 97; + accum.push(word); + } + return accum; + }, []); +} +/** + * @_ignore + */ +export function decode(data, subs) { + // Replace all the substitutions with their expanded form + for (let i = subsChrs.length - 1; i >= 0; i--) { + data = data.split(subsChrs[i]).join(subs.substring(2 * i, 2 * i + 2)); + } + // Get all tle clumps; each suffix, first-increment and second-increment + const clumps = []; + const leftover = data.replace(/(:|([0-9])|([A-Z][a-z]*))/g, (all, item, semi, word) => { + if (semi) { + for (let i = parseInt(semi); i >= 0; i--) { + clumps.push(";"); + } + } + else { + clumps.push(item.toLowerCase()); + } + return ""; + }); + /* c8 ignore start */ + if (leftover) { + throw new Error(`leftovers: ${JSON.stringify(leftover)}`); + } + /* c8 ignore stop */ + return unfold(unfold(clumps, ";"), ":"); +} +/** + * @_ignore + */ +export function decodeOwl(data) { + assertArgument(data[0] === "0", "unsupported auwl data", "data", data); + return decode(data.substring(1 + 2 * subsChrs.length), data.substring(1, 1 + 2 * subsChrs.length)); +} +//# sourceMappingURL=decode-owl.js.map \ No newline at end of file diff --git a/lib.esm/wordlists/decode-owl.js.map b/lib.esm/wordlists/decode-owl.js.map new file mode 100644 index 00000000..e5c66d76 --- /dev/null +++ b/lib.esm/wordlists/decode-owl.js.map @@ -0,0 +1 @@ +{"version":3,"file":"decode-owl.js","sourceRoot":"","sources":["../../src.ts/wordlists/decode-owl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGnD,MAAM,QAAQ,GAAG,+BAA+B,CAAC;AACjD,MAAM,IAAI,GAAG,WAAW,CAAC;AAEzB,SAAS,MAAM,CAAC,KAAoB,EAAE,GAAW;IAC7C,IAAI,OAAO,GAAG,EAAE,CAAC;IACjB,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;QAChC,IAAI,IAAI,KAAK,GAAG,EAAE;YACd,OAAO,EAAE,CAAC;SACb;aAAM,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE;YACzB,KAAK,CAAC,IAAI,CAAC,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E,oBAAoB;IAEpB,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;AAC5C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,IAAY;IAClC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,uBAAuB,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IAEvE,OAAO,MAAM,CACT,IAAI,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC,EACvC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;AACpD,CAAC"} \ No newline at end of file diff --git a/lib.esm/wordlists/decode-owla.d.ts b/lib.esm/wordlists/decode-owla.d.ts new file mode 100644 index 00000000..479e6c54 --- /dev/null +++ b/lib.esm/wordlists/decode-owla.d.ts @@ -0,0 +1,5 @@ +/** + * @_ignore + */ +export declare function decodeOwlA(data: string, accents: string): Array; +//# sourceMappingURL=decode-owla.d.ts.map \ No newline at end of file diff --git a/lib.esm/wordlists/decode-owla.d.ts.map b/lib.esm/wordlists/decode-owla.d.ts.map new file mode 100644 index 00000000..bb3d5696 --- /dev/null +++ b/lib.esm/wordlists/decode-owla.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"decode-owla.d.ts","sourceRoot":"","sources":["../../src.ts/wordlists/decode-owla.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAwBvE"} \ No newline at end of file diff --git a/lib.esm/wordlists/decode-owla.js b/lib.esm/wordlists/decode-owla.js new file mode 100644 index 00000000..0bae6acf --- /dev/null +++ b/lib.esm/wordlists/decode-owla.js @@ -0,0 +1,28 @@ +import { assertArgument } from "../utils/index.js"; +import { decodeBits } from "./bit-reader.js"; +import { decodeOwl } from "./decode-owl.js"; +/** + * @_ignore + */ +export function decodeOwlA(data, accents) { + let words = decodeOwl(data).join(","); + // Inject the accents + accents.split(/,/g).forEach((accent) => { + const match = accent.match(/^([a-z]*)([0-9]+)([0-9])(.*)$/); + assertArgument(match !== null, "internal error parsing accents", "accents", accents); + let posOffset = 0; + const positions = decodeBits(parseInt(match[3]), match[4]); + const charCode = parseInt(match[2]); + const regex = new RegExp(`([${match[1]}])`, "g"); + words = words.replace(regex, (all, letter) => { + const rem = --positions[posOffset]; + if (rem === 0) { + letter = String.fromCharCode(letter.charCodeAt(0), charCode); + posOffset++; + } + return letter; + }); + }); + return words.split(","); +} +//# sourceMappingURL=decode-owla.js.map \ No newline at end of file diff --git a/lib.esm/wordlists/decode-owla.js.map b/lib.esm/wordlists/decode-owla.js.map new file mode 100644 index 00000000..98fc88b1 --- /dev/null +++ b/lib.esm/wordlists/decode-owla.js.map @@ -0,0 +1 @@ +{"version":3,"file":"decode-owla.js","sourceRoot":"","sources":["../../src.ts/wordlists/decode-owla.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,IAAY,EAAE,OAAe;IACpD,IAAI,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAEtC,qBAAqB;IACrB,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;QAEnC,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC;QAC5D,cAAc,CAAC,KAAK,KAAK,IAAI,EAAE,gCAAgC,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;QAErF,IAAI,SAAS,GAAG,CAAC,CAAC;QAClB,MAAM,SAAS,GAAG,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAC3D,MAAM,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACpC,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,KAAM,KAAK,CAAC,CAAC,CAAE,IAAI,EAAE,GAAG,CAAC,CAAC;QACnD,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE;YACzC,MAAM,GAAG,GAAG,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;YACnC,IAAI,GAAG,KAAK,CAAC,EAAE;gBACX,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;gBAC7D,SAAS,EAAE,CAAC;aACf;YACD,OAAO,MAAM,CAAC;QAClB,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AAC5B,CAAC"} \ No newline at end of file diff --git a/lib.esm/wordlists/generation/encode-latin.d.ts b/lib.esm/wordlists/generation/encode-latin.d.ts new file mode 100644 index 00000000..a646e824 --- /dev/null +++ b/lib.esm/wordlists/generation/encode-latin.d.ts @@ -0,0 +1,25 @@ +export declare class BitWriter { + #private; + readonly width: number; + constructor(width: number); + write(value: number): void; + get length(): number; + get data(): string; +} +export interface AccentSet { + accent: number; + follows: string; + positions: Array; + positionsLength: number; + positionData: string; + positionDataLength: number; +} +export declare function extractAccents(words: Array): { + accents: Array; + words: Array; +}; +export declare function encodeOwl(words: Array): { + subs: string; + data: string; +}; +//# sourceMappingURL=encode-latin.d.ts.map \ No newline at end of file diff --git a/lib.esm/wordlists/generation/encode-latin.d.ts.map b/lib.esm/wordlists/generation/encode-latin.d.ts.map new file mode 100644 index 00000000..3aef4135 --- /dev/null +++ b/lib.esm/wordlists/generation/encode-latin.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"encode-latin.d.ts","sourceRoot":"","sources":["../../../src.ts/wordlists/generation/encode-latin.ts"],"names":[],"mappings":"AAuIA,qBAAa,SAAS;;IAClB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;gBAKX,KAAK,EAAE,MAAM;IAMzB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAW1B,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,IAAI,IAAI,IAAI,MAAM,CA4BjB;CACJ;AAED,MAAM,WAAW,SAAS;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACzB,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,kBAAkB,EAAE,MAAM,CAAC;CAC9B;AAWD,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG;IAAE,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;IAAC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;CAAE,CAyExG;AAGD,wBAAgB,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CA4C9E"} \ No newline at end of file diff --git a/lib.esm/wordlists/generation/encode-latin.js b/lib.esm/wordlists/generation/encode-latin.js new file mode 100644 index 00000000..ecd8dbed --- /dev/null +++ b/lib.esm/wordlists/generation/encode-latin.js @@ -0,0 +1,344 @@ +// OWL Data Format +// +// The Official WordList data format exported by this encoder +// encodes sorted latin-1 words (letters only) based on the +// fact that sorted words have prefixes with substantial +// overlap. +// +// For example, the words: +// [ Another, Apple, Apricot, Bread ] +// could be folded once with a single special character, such +// as ":" to yield: +// [ nother, pple, pricot, :, read ]. +// The First letter has been removed, but can be inferred by +// starting at A and incrementing to the next letter when ":" +// is encountered. +// +// The fold operation can be repeated for large sets as even within +// each folded set, there is substatial overlap in prefix. With the +// second special symbol ";", we get: +// [ ; x 13, other, :, ple, ricot, :, ; x 18, ead ] +// which can be further compressed by using numbers instead of the +// special character: +// [ 13, other, :, ple, ricot, :, 18, ead ] +// and to keep all values within a single byte, we only allow a +// maximum value of 10 (using 0 through 9 to represent 1 through 10), +// we get: +// [ 9, 2, other, :, ple, ricot, :, 9, 7, ead ] +// and we use camel-case to imply the bounrary, giving the final string: +// "92Other:PleRicot:97Ead" +// +// Once the entire latin-1 set has been collapsed, we use the remaining +// printable characters (except " and \, which require 2 bytes to represent +// in string) to substiture for the most common 2-letter pairs of letters +// in the string. +// +// OWLA Accent Format +// +// OWLA first removes all accents, and encodes that data using the OWL +// data format and encodes the accents as a base-64 series of 6-bit +// packed bits representing the distance from one followed letter to the +// next. +// +// For example, the acute accent in a given language may follow either +// a or e, in which case the follow-set is "ae". Each letter in the entire +// set is indexed, so the set of words with the accents: +// "thisA/ppleDoe/sNotMa/tterToMe/" +// " 1^ 2^ 3^ 4^ 5^ 6^ " <-- follow-set members, ALL a's and e's +// which gives the positions: +// [ 0, 2, 3, 4, 6 ] +// which then reduce to the distances +// [ 0, 2, 1, 1, 2 ] +// each of which fit into a 2-bit value, so this can be encoded as the +// base-64 encoded string: +// 00 10 01 01 10 = 001001 1010xx +// +// The base-64 set used has all number replaced with their +// shifted-counterparts to prevent comflicting with the numbers used in +// the fold operation to indicate the number of ";". +import fs from "fs"; +import { id } from "../../hash/id.js"; +import { decodeOwl } from "../decode-owl.js"; +import { decodeOwlA } from "../decode-owla.js"; +const subsChrs = " !#$%&'()*+,-./<=>?@[]^_`{|}~"; +const Word = /^[a-z'`]*$/i; +function fold(words, sep) { + const output = []; + let initial = 97; + for (const word of words) { + if (word.match(Word)) { + while (initial < word.charCodeAt(0)) { + initial++; + output.push(sep); + } + output.push(word.substring(1)); + } + else { + initial = 97; + output.push(word); + } + } + return output; +} +function camelcase(words) { + return words.map((word) => { + if (word.match(Word)) { + return word[0].toUpperCase() + word.substring(1); + } + else { + return word; + } + }).join(""); +} +//let cc = 0, ce = 0; +/* +function getChar(c: string): string { + //if (c === "e") { ce++; } + if (c >= 'a' && c <= 'z') { return c; } + if (c.charCodeAt(1)) { + throw new Error(`bad char: "${ c }"`); + } + //cc++; + return ""; + if (c.charCodeAt(0) === 768) { return "`"; } + if (c.charCodeAt(0) === 769) { return "'"; } + if (c.charCodeAt(0) === 771) { return "~"; } + throw new Error(`Unsupported character: ${ c } (${ c.charCodeAt(0) }, ${ c.charCodeAt(1) })`); +} +function mangle(text: string): { word: string, special: string } { + const result: Array = [ ]; + for (let i = 0; i < text.length; i++) { + const c = getChar(text[i]); + result.push(c); + } + + const word = result.join(""); + if (word[1] >= 'a' && word[1] <= 'z') { return { word, special: " " }; } + return { word: word[0] + word.substring(2), special: word[1] }; +} +*/ +/* + Store: [ accent ][ targets ][ rle data; base64-tail ] + ` ae 3, 100 = (63, 37), 15 + ~ n 63, 64 = (63, 1), 27 +*/ +const Base64 = ")!@#$%^&*(ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_"; +export class BitWriter { + width; + #data; + #bitLength; + constructor(width) { + this.width = width; + this.#data = []; + this.#bitLength = 0; + } + write(value) { + const maxValue = ((1 << this.width) - 1); + while (value > maxValue) { + this.#data.push(0); + this.#bitLength += this.width; + value -= maxValue; + } + this.#data.push(value); + this.#bitLength += this.width; + } + get length() { + return 1 + Math.trunc((this.#bitLength + 5) / 6); + } + get data() { + let result = String(this.width); + let bits = 0; + let accum = 0; + const data = this.#data.slice(); + let bitMod = this.#bitLength % 6; + while (bitMod !== 0 && bitMod < 6) { + data.push(0); + bitMod += this.width; + } + for (const value of data) { + accum <<= this.width; + accum |= value; + bits += this.width; + if (bits < 6) { + continue; + } + result += Base64[accum >> (bits - 6)]; + bits -= 6; + accum &= ((1 << bits) - 1); + } + if (result.length !== this.length) { + throw new Error(`Hmm: ${this.length} ${result.length} ${result}`); + } + return result; + } +} +; +function sorted(text) { + const letters = text.split(""); + letters.sort(); + return letters.join(""); +} +// if (c.charCodeAt(0) === 768) { return "`"; } +// if (c.charCodeAt(0) === 769) { return "'"; } +// if (c.charCodeAt(0) === 771) { return "~"; } +export function extractAccents(words) { + // Build a list that maps accents to the letters it can follow + const followsMap = new Map(); + for (const word of words) { + for (let i = 0; i < word.length; i++) { + const c = word[i]; + if (c >= 'a' && c <= 'z') { + continue; + } + // Make sure this positions and codepoint make sense + if (c.charCodeAt(1)) { + throw new Error(`unsupported codepoint: "${c}"`); + } + if (i === 0) { + throw new Error(`unmatched accent: ${c}`); + } + const ac = c.charCodeAt(0), lastLetter = word[i - 1]; + ; + const follows = (followsMap.get(ac) || ""); + if (follows.indexOf(lastLetter) === -1) { + followsMap.set(ac, sorted(follows + lastLetter)); + } + } + } + // Build the positions of each follow-set for those accents + const positionsMap = new Map(); + for (const [accent, follows] of followsMap) { + let count = 0; + for (const word of words) { + for (let i = 0; i < word.length; i++) { + const c = word[i], ac = c.charCodeAt(0); + if (follows.indexOf(c) >= 0) { + count++; + } + if (ac === accent) { + const pos = positionsMap.get(ac) || []; + pos.push(count); + positionsMap.set(ac, pos); + } + } + } + } + const accents = []; + for (const [accent, follows] of followsMap) { + let last = -1; + const positions = (positionsMap.get(accent) || []).map((value, index) => { + const delta = value - last; + last = value; + if (index === 0) { + return value; + } + return delta; + }); + // Find the best encoding of the position data + let positionData = ""; + for (let i = 2; i < 7; i++) { + const bitWriter = new BitWriter(i); + for (const p of positions) { + bitWriter.write(p); + } + if (positionData === "" || bitWriter.length < positionData.length) { + positionData = bitWriter.data; + } + } + const positionsLength = positions.length; + const positionDataLength = positionData.length; + accents.push({ accent, follows, positions, positionsLength, positionData, positionDataLength }); + } + words = words.map((word) => { + let result = ""; + for (let i = 0; i < word.length; i++) { + const c = word[i]; + if (c >= 'a' && c <= 'z') { + result += c; + } + } + return result; + }); + return { accents, words }; +} +// Encode Official WordList +export function encodeOwl(words) { + // Fold the sorted words by indicating delta for the first 2 letters + let data = camelcase(fold(fold(words, ":"), ";")); + // Replace semicolons with counts (e.g. ";;;" with "3") + data = data.replace(/(;+)/g, (all, semis) => { + let result = ""; + while (semis.length) { + let count = semis.length; + if (count > 10) { + count = 10; + } + result += String(count - 1); + semis = semis.substring(count); + } + return result; + }); + // Finds the best option for a shortcut replacement using the + // unused ascii7 characters + function findBest() { + const tally = {}; + const l = 2; + for (let i = l; i < data.length; i++) { + const key = data.substring(i - l, i); + tally[key] = (tally[key] || 0) + 1; + } + const sorted = Object.keys(tally).map((text) => { + return { text, count: tally[text], save: (tally[text] * (text.length - 1)) }; + }); + sorted.sort((a, b) => (b.save - a.save)); + return sorted[0].text; + } + // Make substitutions + let subs = ""; + for (let i = 0; i < subsChrs.length; i++) { + const n = subsChrs[i], o = findBest(); + subs += o; + data = data.split(o).join(n); + } + return { data, subs }; +} +// Returns either: +// - OWL data for accent-free latin-1: { data, accentds: "" } +// - OWLA data for accented latin-1: { data, accents } +function encodeWords(_words) { + const { accents, words } = extractAccents(_words); + const { data, subs } = encodeOwl(words); + const accentData = accents.map(({ accent, follows, positionData }) => { + return `${follows}${accent}${positionData}`; + }).join(","); + return { + data: `0${subs}${data}`, + accents: accentData + }; +} +// CLI +const content = fs.readFileSync(process.argv[2]).toString(); +const words = content.split("\n").filter(Boolean); +const { data, accents } = encodeWords(words); +if (accents) { + const rec = decodeOwlA(data, accents); + console.log("DATA: ", JSON.stringify(data)); + console.log("ACCENTS: ", JSON.stringify(accents)); + console.log("LENGTH: ", data.length); + console.log("CHECKSUM: ", id(content)); + console.log("RATIO: ", Math.trunc(100 * data.length / content.length) + "%"); + if (rec.join("\n") !== words.join("\n")) { + throw new Error("no match!"); + } +} +else { + const rec = decodeOwl(data); + console.log("DATA: ", JSON.stringify(data)); + console.log("LENGTH: ", data.length); + console.log("CHECKSUM: ", id(content)); + console.log("RATIO: ", Math.trunc(100 * data.length / content.length) + "%"); + if (rec.join("\n") !== words.join("\n")) { + throw new Error("no match!"); + } +} +//# sourceMappingURL=encode-latin.js.map \ No newline at end of file diff --git a/lib.esm/wordlists/generation/encode-latin.js.map b/lib.esm/wordlists/generation/encode-latin.js.map new file mode 100644 index 00000000..9ed5652c --- /dev/null +++ b/lib.esm/wordlists/generation/encode-latin.js.map @@ -0,0 +1 @@ +{"version":3,"file":"encode-latin.js","sourceRoot":"","sources":["../../../src.ts/wordlists/generation/encode-latin.ts"],"names":[],"mappings":"AACA,kBAAkB;AAClB,EAAE;AACF,6DAA6D;AAC7D,2DAA2D;AAC3D,wDAAwD;AACxD,WAAW;AACX,EAAE;AACF,0BAA0B;AAC1B,uCAAuC;AACvC,6DAA6D;AAC7D,mBAAmB;AACnB,uCAAuC;AACvC,4DAA4D;AAC5D,6DAA6D;AAC7D,kBAAkB;AAClB,EAAE;AACF,mEAAmE;AACnE,mEAAmE;AACnE,qCAAqC;AACrC,qDAAqD;AACrD,kEAAkE;AAClE,qBAAqB;AACrB,6CAA6C;AAC7C,+DAA+D;AAC/D,qEAAqE;AACrE,UAAU;AACV,iDAAiD;AACjD,wEAAwE;AACxE,6BAA6B;AAC7B,EAAE;AACF,uEAAuE;AACvE,2EAA2E;AAC3E,yEAAyE;AACzE,iBAAiB;AACjB,EAAE;AACF,qBAAqB;AACrB,EAAE;AACF,sEAAsE;AACtE,mEAAmE;AACnE,wEAAwE;AACxE,QAAQ;AACR,EAAE;AACF,sEAAsE;AACtE,0EAA0E;AAC1E,wDAAwD;AACxD,qCAAqC;AACrC,6EAA6E;AAC7E,6BAA6B;AAC7B,sBAAsB;AACtB,qCAAqC;AACrC,sBAAsB;AACtB,sEAAsE;AACtE,0BAA0B;AAC1B,qCAAqC;AACrC,EA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at end of file diff --git a/lib.esm/wordlists/index.d.ts b/lib.esm/wordlists/index.d.ts new file mode 100644 index 00000000..ec999e0e --- /dev/null +++ b/lib.esm/wordlists/index.d.ts @@ -0,0 +1,26 @@ +/** + * A Wordlist is a set of 2048 words used to encode private keys + * (or other binary data) that is easier for humans to write down, + * transcribe and dictate. + * + * The [[link-bip-39]] standard includes several checksum bits, + * depending on the size of the mnemonic phrase. + * + * A mnemonic phrase may be 12, 15, 18, 21 or 24 words long. For + * most purposes 12 word mnemonics should be used, as including + * additional words increases the difficulty and potential for + * mistakes and does not offer any effective improvement on security. + * + * There are a variety of [[link-bip39-wordlists]] for different + * languages, but for maximal compatibility, the + * [English Wordlist](LangEn) is recommended. + * + * @_section: api/wordlists:Wordlists [about-wordlists] + */ +export { Wordlist } from "./wordlist.js"; +export { LangEn } from "./lang-en.js"; +export { LangEs } from "./lang-es.js"; +export { WordlistOwl } from "./wordlist-owl.js"; +export { WordlistOwlA } from "./wordlist-owla.js"; +export { wordlists } from "./wordlists.js"; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/lib.esm/wordlists/index.d.ts.map b/lib.esm/wordlists/index.d.ts.map new file mode 100644 index 00000000..02ab26c7 --- /dev/null +++ b/lib.esm/wordlists/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src.ts/wordlists/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC"} \ No newline at end of file diff --git a/lib.esm/wordlists/index.js b/lib.esm/wordlists/index.js new file mode 100644 index 00000000..17643433 --- /dev/null +++ b/lib.esm/wordlists/index.js @@ -0,0 +1,26 @@ +/** + * A Wordlist is a set of 2048 words used to encode private keys + * (or other binary data) that is easier for humans to write down, + * transcribe and dictate. + * + * The [[link-bip-39]] standard includes several checksum bits, + * depending on the size of the mnemonic phrase. + * + * A mnemonic phrase may be 12, 15, 18, 21 or 24 words long. For + * most purposes 12 word mnemonics should be used, as including + * additional words increases the difficulty and potential for + * mistakes and does not offer any effective improvement on security. + * + * There are a variety of [[link-bip39-wordlists]] for different + * languages, but for maximal compatibility, the + * [English Wordlist](LangEn) is recommended. + * + * @_section: api/wordlists:Wordlists [about-wordlists] + */ +export { Wordlist } from "./wordlist.js"; +export { LangEn } from "./lang-en.js"; +export { LangEs } from "./lang-es.js"; +export { WordlistOwl } from "./wordlist-owl.js"; +export { WordlistOwlA } from "./wordlist-owla.js"; +export { wordlists } from "./wordlists.js"; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib.esm/wordlists/index.js.map b/lib.esm/wordlists/index.js.map new file mode 100644 index 00000000..19c70be8 --- /dev/null +++ b/lib.esm/wordlists/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src.ts/wordlists/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC"} \ No newline at end of file diff --git a/lib.esm/wordlists/lang-cz.d.ts b/lib.esm/wordlists/lang-cz.d.ts new file mode 100644 index 00000000..c199d4fa --- /dev/null +++ b/lib.esm/wordlists/lang-cz.d.ts @@ -0,0 +1,23 @@ +import { WordlistOwl } from "./wordlist-owl.js"; +/** + * The [[link-bip39-cz]] for [mnemonic phrases](link-bip-39). + * + * @_docloc: api/wordlists + */ +export declare class LangCz extends WordlistOwl { + /** + * Creates a new instance of the Czech language Wordlist. + * + * Using the constructor should be unnecessary, instead use the + * [[wordlist]] singleton method. + * + * @_ignore: + */ + constructor(); + /** + * Returns a singleton instance of a ``LangCz``, creating it + * if this is the first time being called. + */ + static wordlist(): LangCz; +} +//# sourceMappingURL=lang-cz.d.ts.map \ No newline at end of file diff --git a/lib.esm/wordlists/lang-cz.d.ts.map b/lib.esm/wordlists/lang-cz.d.ts.map new file mode 100644 index 00000000..975a36b5 --- /dev/null +++ b/lib.esm/wordlists/lang-cz.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"lang-cz.d.ts","sourceRoot":"","sources":["../../src.ts/wordlists/lang-cz.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAOhD;;;;GAIG;AACH,qBAAa,MAAO,SAAQ,WAAW;IAEnC;;;;;;;OAOG;;IAGH;;;OAGG;IACH,MAAM,CAAC,QAAQ,IAAI,MAAM;CAI5B"} \ No newline at end of file diff --git a/lib.esm/wordlists/lang-cz.js b/lib.esm/wordlists/lang-cz.js new file mode 100644 index 00000000..ed473dbd --- /dev/null +++ b/lib.esm/wordlists/lang-cz.js @@ -0,0 +1,31 @@ +import { WordlistOwl } from "./wordlist-owl.js"; +const words = "0itatkastcenaovo$taouleraeki&chor*teci%enbalodaeladet'!Chn=0Di#%E%^1Resa2Rese3CeT'#0EjKohol0Pu)%0A&sDul#Ekdo)Ke)Ti#Ul|3}aOgan%0FaltI$@tPi,%TmaTronom0LasL{i#Ol0Tobus4Yl:B#}R'?TaUb_U/!U^U+Ur!Xer2A^v#Ambo,An#AtrEp)Ike)KoLohOnzOskevUn{#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ed~EnkuEs_aOnR!Uk'odYk"; +const checksum = "0x25f44555f4af25b51a711136e1c7d6e50ce9f8917d39d6b1f076b2bb4d2fac1a"; +let wordlist = null; +/** + * The [[link-bip39-cz]] for [mnemonic phrases](link-bip-39). + * + * @_docloc: api/wordlists + */ +export class LangCz extends WordlistOwl { + /** + * Creates a new instance of the Czech language Wordlist. + * + * Using the constructor should be unnecessary, instead use the + * [[wordlist]] singleton method. + * + * @_ignore: + */ + constructor() { super("cz", words, checksum); } + /** + * Returns a singleton instance of a ``LangCz``, creating it + * if this is the first time being called. + */ + static wordlist() { + if (wordlist == null) { + wordlist = new LangCz(); + } + return wordlist; + } +} +//# sourceMappingURL=lang-cz.js.map \ No newline at end of file diff --git a/lib.esm/wordlists/lang-cz.js.map b/lib.esm/wordlists/lang-cz.js.map new file mode 100644 index 00000000..b05fe8ae --- /dev/null +++ b/lib.esm/wordlists/lang-cz.js.map @@ -0,0 +1 @@ +{"version":3,"file":"lang-cz.js","sourceRoot":"","sources":["../../src.ts/wordlists/lang-cz.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,KAAK,GAAG,q9NAAq9N,CAAC;AACp+N,MAAM,QAAQ,GAAG,oEAAoE,CAAC;AAEtF,IAAI,QAAQ,GAAkB,IAAI,CAAC;AAEnC;;;;GAIG;AACH,MAAM,OAAO,MAAO,SAAQ,WAAW;IAEnC;;;;;;;OAOG;IACH,gBAAgB,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IAE/C;;;OAGG;IACH,MAAM,CAAC,QAAQ;QACX,IAAI,QAAQ,IAAI,IAAI,EAAE;YAAE,QAAQ,GAAG,IAAI,MAAM,EAAE,CAAC;SAAE;QAClD,OAAO,QAAQ,CAAC;IACpB,CAAC;CACJ"} \ No newline at end of file diff --git a/lib.esm/wordlists/lang-en.d.ts b/lib.esm/wordlists/lang-en.d.ts new file mode 100644 index 00000000..87a3234b --- /dev/null +++ b/lib.esm/wordlists/lang-en.d.ts @@ -0,0 +1,23 @@ +import { WordlistOwl } from "./wordlist-owl.js"; +/** + * The [[link-bip39-en]] for [mnemonic phrases](link-bip-39). + * + * @_docloc: api/wordlists + */ +export declare class LangEn extends WordlistOwl { + /** + * Creates a new instance of the English language Wordlist. + * + * This should be unnecessary most of the time as the exported + * [[langEn]] should suffice. + * + * @_ignore: + */ + constructor(); + /** + * Returns a singleton instance of a ``LangEn``, creating it + * if this is the first time being called. + */ + static wordlist(): LangEn; +} +//# sourceMappingURL=lang-en.d.ts.map \ No newline at end of file diff --git a/lib.esm/wordlists/lang-en.d.ts.map b/lib.esm/wordlists/lang-en.d.ts.map new file mode 100644 index 00000000..1a3bf42a --- /dev/null +++ b/lib.esm/wordlists/lang-en.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"lang-en.d.ts","sourceRoot":"","sources":["../../src.ts/wordlists/lang-en.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAOhD;;;;GAIG;AACH,qBAAa,MAAO,SAAQ,WAAW;IAEnC;;;;;;;OAOG;;IAGH;;;OAGG;IACH,MAAM,CAAC,QAAQ,IAAI,MAAM;CAI5B"} \ No newline at end of file diff --git a/lib.esm/wordlists/lang-en.js b/lib.esm/wordlists/lang-en.js new file mode 100644 index 00000000..142bea39 --- /dev/null +++ b/lib.esm/wordlists/lang-en.js @@ -0,0 +1,31 @@ +import { WordlistOwl } from "./wordlist-owl.js"; +const words = "0erleonalorenseinceregesticitStanvetearctssi#ch2Athck&tneLl0And#Il.yLeOutO=S|S%b/ra@SurdU'0Ce[Cid|CountCu'Hie=IdOu,-Qui*Ro[TT]T%T*[Tu$0AptDD-tD*[Ju,M.UltV<)Vi)0Rob-0FairF%dRaid0A(EEntRee0Ead0MRRp%tS!_rmBumCoholErtI&LLeyLowMo,O}PhaReadySoT Ways0A>urAz(gOngOuntU'd0Aly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GidNgOtPp!SkTu$V$V 5AdA,BotBu,CketM<)OfOkieOmSeTa>UghUndU>Y$5Bb DeGLeNNwayR$:DDd!D}[FeIlLadLm#L#LtLu>MeMp!NdTisfyToshiU)Usa+VeY1A!AnA*Att E}HemeHoolI&)I[%sOrp]OutRapRe&RiptRub1AAr^As#AtC#dC*tCt]Cur.yEdEkGm|Le@~M(?Ni%N'Nt&)RiesRvi)Ss]Tt!TupV&_dowAftAllowA*EdEllEriffIeldIftI}IpIv O{OeOotOpOrtOuld O=RimpRugUff!Y0Bl(gCkDeE+GhtGnL|Lk~yLv Mil?Mp!N)NgR&/ Tua>XZe1A>Et^IIllInIrtUll0AbAmEepEnd I)IdeIghtImOgAyEakEelEmEpE*oI{IllIngO{Oma^O}OolOryO=Ra>gyReetRikeR#gRugg!Ud|UffUmb!Y!0Bje@Bm.BwayC)[ChDd&Ff G?G+,ItMm NNnyN'tP PplyP*meReRfa)R+Rpri'RroundR=ySpe@/a(1AllowAmpApArmE?EetIftImIngIt^Ord1MbolMptomRup/em:B!Ck!GIlL|LkNkPeR+tSk/eTtooXi3A^Am~NNGradeHoldOnP Set1BOng::Rd3Ar~ow9UUngU`:3BraRo9NeO"; +const checksum = "0x3c8acc1e7b08d8e76f9fda015ef48dc8c710a73cb7e0f77b2c18a9b5a7adde60"; +let wordlist = null; +/** + * The [[link-bip39-en]] for [mnemonic phrases](link-bip-39). + * + * @_docloc: api/wordlists + */ +export class LangEn extends WordlistOwl { + /** + * Creates a new instance of the English language Wordlist. + * + * This should be unnecessary most of the time as the exported + * [[langEn]] should suffice. + * + * @_ignore: + */ + constructor() { super("en", words, checksum); } + /** + * Returns a singleton instance of a ``LangEn``, creating it + * if this is the first time being called. + */ + static wordlist() { + if (wordlist == null) { + wordlist = new LangEn(); + } + return wordlist; + } +} +//# sourceMappingURL=lang-en.js.map \ No newline at end of file diff --git a/lib.esm/wordlists/lang-en.js.map b/lib.esm/wordlists/lang-en.js.map new file mode 100644 index 00000000..6703337b --- /dev/null +++ b/lib.esm/wordlists/lang-en.js.map @@ -0,0 +1 @@ +{"version":3,"file":"lang-en.js","sourceRoot":"","sources":["../../src.ts/wordlists/lang-en.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,KAAK,GAAG,u3LAAu3L,CAAC;AACt4L,MAAM,QAAQ,GAAG,oEAAoE,CAAC;AAEtF,IAAI,QAAQ,GAAkB,IAAI,CAAC;AAEnC;;;;GAIG;AACH,MAAM,OAAO,MAAO,SAAQ,WAAW;IAEnC;;;;;;;OAOG;IACH,gBAAgB,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IAE/C;;;OAGG;IACH,MAAM,CAAC,QAAQ;QACX,IAAI,QAAQ,IAAI,IAAI,EAAE;YAAE,QAAQ,GAAG,IAAI,MAAM,EAAE,CAAC;SAAE;QAClD,OAAO,QAAQ,CAAC;IACpB,CAAC;CACJ"} \ No newline at end of file diff --git a/lib.esm/wordlists/lang-es.d.ts b/lib.esm/wordlists/lang-es.d.ts new file mode 100644 index 00000000..7e51683e --- /dev/null +++ b/lib.esm/wordlists/lang-es.d.ts @@ -0,0 +1,23 @@ +import { WordlistOwlA } from "./wordlist-owla.js"; +/** + * The [[link-bip39-es]] for [mnemonic phrases](link-bip-39). + * + * @_docloc: api/wordlists + */ +export declare class LangEs extends WordlistOwlA { + /** + * Creates a new instance of the Spanish language Wordlist. + * + * This should be unnecessary most of the time as the exported + * [[langEs]] should suffice. + * + * @_ignore: + */ + constructor(); + /** + * Returns a singleton instance of a ``LangEs``, creating it + * if this is the first time being called. + */ + static wordlist(): LangEs; +} +//# sourceMappingURL=lang-es.d.ts.map \ No newline at end of file diff --git a/lib.esm/wordlists/lang-es.d.ts.map b/lib.esm/wordlists/lang-es.d.ts.map new file mode 100644 index 00000000..074d92d8 --- /dev/null +++ b/lib.esm/wordlists/lang-es.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"lang-es.d.ts","sourceRoot":"","sources":["../../src.ts/wordlists/lang-es.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAQlD;;;;GAIG;AACH,qBAAa,MAAO,SAAQ,YAAY;IAEpC;;;;;;;OAOG;;IAGH;;;OAGG;IACH,MAAM,CAAC,QAAQ,IAAI,MAAM;CAI5B"} \ No newline at end of file diff --git a/lib.esm/wordlists/lang-es.js b/lib.esm/wordlists/lang-es.js new file mode 100644 index 00000000..3160c40f --- /dev/null +++ b/lib.esm/wordlists/lang-es.js @@ -0,0 +1,32 @@ +import { WordlistOwlA } from "./wordlist-owla.js"; +const words = "0arertoiotadonoaRteirroenaNonaLsolocoiliaralaorrenadaChoN$n0A>Dom,EjaI!#Oga&O'Or#RazoR*Ue=U<0Ab Adem@CeLe%OmoRa!RozUn0DazD$GeLaM,#S,)T^0AlAnceA+EEl]`E`EstruzI.I<2ErU{U'0Af[nArO)Uc Uf_Ul:BaB^|eH@IleJ Lanz/c.LdeMbuN>Nd-oRb(>RnizR+Scu]S#nSu[Tal]T!@T*Tu%UlZ 3BeBid/=S SoSt@3|oEnNgo2An>OqueUsa2ABi`BoCaCi`DaDegaIn//!oLsaMb-{dNi#N}saiRdeRr SqueTeTinVe{Zal2AvoAzoEchaEveIl=In>IsaOcaOmaOnceO)UjaUs>U#2CeoCleE'EyFan{F.HoIt_L#Rbuj(l(+Sc TacaZ.:Bal=BezaBi`B[CaoDav!D,aErFeI{ImanJaJ.LLam Lc$L&Li{dLleLm/^LvoMaMb$Mel=Mi'Mp}c!Nd?Nel-gu+Nic-#N-.ObaOsPazPi%nPo)Pt Puch((b.RcelRe%Rg(i'RneRpe%R+R%SaS>S!oSpaS#rT^ceT_U{lUsaZo3Bol]D!D+Ld/eb_LoAmpuAnc]ApaAr]I>Is)IvoOqueOzaUle%Up 0Cl.EgoE=EnEr#F[G +M->NeN%P_sR>Rue]SneTaU{d2Am^An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{dIrIv!; + join(words: Array): string; + /** + * Returns a singleton instance of a ``LangJa``, creating it + * if this is the first time being called. + */ + static wordlist(): LangJa; +} +//# sourceMappingURL=lang-ja.d.ts.map \ No newline at end of file diff --git a/lib.esm/wordlists/lang-ja.d.ts.map b/lib.esm/wordlists/lang-ja.d.ts.map new file mode 100644 index 00000000..a1ed9546 --- /dev/null +++ b/lib.esm/wordlists/lang-ja.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"lang-ja.d.ts","sourceRoot":"","sources":["../../src.ts/wordlists/lang-ja.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAkIzC;;;;GAIG;AACH,qBAAa,MAAO,SAAQ,QAAQ;IAEhC;;;;;;;OAOG;;IAGH,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAO9B,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAIlC,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;IAKpC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM;IAIlC;;;OAGG;IACH,MAAM,CAAC,QAAQ,IAAI,MAAM;CAI5B"} \ No newline at end of file diff --git a/lib.esm/wordlists/lang-ja.js b/lib.esm/wordlists/lang-ja.js new file mode 100644 index 00000000..7ad4aea3 --- /dev/null +++ b/lib.esm/wordlists/lang-ja.js @@ -0,0 +1,154 @@ +import { id } from "../hash/index.js"; +import { hexlify, assertArgument, toUtf8Bytes, toUtf8String } from "../utils/index.js"; +import { Wordlist } from "./wordlist.js"; +const data = [ + // 4-kana words + "AQRASRAGBAGUAIRAHBAghAURAdBAdcAnoAMEAFBAFCBKFBQRBSFBCXBCDBCHBGFBEQBpBBpQBIkBHNBeOBgFBVCBhBBhNBmOBmRBiHBiFBUFBZDBvFBsXBkFBlcBjYBwDBMBBTBBTRBWBBWXXaQXaRXQWXSRXCFXYBXpHXOQX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DGJRLiJEJfXEqEJFEJPEFpBEJYJBZJFYBwXUJYiJMEBYJZJyTYTONJXpQMFXFpeGIDdpJFstXpJFcPDLBVSJRLHQJqXLJFZJFIJBNJDIJBUqXIBkFDJIJEJPTIYJGWRIJeQPDIJeEfHIJFsJXOqGDSFHXEJqXgJCsJCgGQJqXgdQYJEgFMFNBgJFcqDVJwXUJVJFZJchIgJCCxOEJqXxOwXUJyDJBVRuscisciJBiJBieUtqXiJFDJkiFsJXQUGEZJcUJFsJXZtXIrXZDZJDrZJFNJDZJFstXvJFQqXvJFCJEsJXQJqkhkNGBbDJdTRbYJMEBlDwXUJMEFiJFcfXNJDRcNJWMTBLJXC", + // 8-kana words + "BraFUtHBFSJFdbNBLJXVJQoYJNEBSJBEJfHSJHwXUJCJdAZJMGjaFVJXEJPNJBlEJfFiJFpFbFEJqIJBVJCrIBdHiJhOPFChvJVJZJNJWxGFNIFLueIBQJqUHEJfUFstOZJDrlXEASJRlXVJXSFwVJNJWD", + // 9-kana words + "QJEJNNJDQJEJIBSFQJEJxegBQJEJfHEPSJBmXEJFSJCDEJqXLXNJFQqXIcQsFNJFIFEJqXUJgFsJXIJBUJEJfHNFvJxEqXNJnXUJFQqD", + // 10-kana words + "IJBEJqXZJ" +]; +// Maps each character into its kana value (the index) +const mapping = "~~AzB~X~a~KN~Q~D~S~C~G~E~Y~p~L~I~O~eH~g~V~hxyumi~~U~~Z~~v~~s~~dkoblPjfnqwMcRTr~W~~~F~~~~~Jt"; +let _wordlist = null; +function hex(word) { + return hexlify(toUtf8Bytes(word)); +} +const KiYoKu = "0xe3818de38284e3818f"; +const KyoKu = "0xe3818de38283e3818f"; +function toString(data) { + return toUtf8String(new Uint8Array(data)); +} +function loadWords() { + if (_wordlist !== null) { + return _wordlist; + } + const wordlist = []; + // Transforms for normalizing (sort is a not quite UTF-8) + const transform = {}; + // Delete the diacritic marks + transform[toString([227, 130, 154])] = false; + transform[toString([227, 130, 153])] = false; + // Some simple transforms that sort out most of the order + transform[toString([227, 130, 133])] = toString([227, 130, 134]); + transform[toString([227, 129, 163])] = toString([227, 129, 164]); + transform[toString([227, 130, 131])] = toString([227, 130, 132]); + transform[toString([227, 130, 135])] = toString([227, 130, 136]); + // Normalize words using the transform + function normalize(word) { + let result = ""; + for (let i = 0; i < word.length; i++) { + let kana = word[i]; + const target = transform[kana]; + if (target === false) { + continue; + } + if (target) { + kana = target; + } + result += kana; + } + return result; + } + // Sort how the Japanese list is sorted + function sortJapanese(a, b) { + a = normalize(a); + b = normalize(b); + if (a < b) { + return -1; + } + if (a > b) { + return 1; + } + return 0; + } + // Load all the words + for (let length = 3; length <= 9; length++) { + const d = data[length - 3]; + for (let offset = 0; offset < d.length; offset += length) { + const word = []; + for (let i = 0; i < length; i++) { + const k = mapping.indexOf(d[offset + i]); + word.push(227); + word.push((k & 0x40) ? 130 : 129); + word.push((k & 0x3f) + 128); + } + wordlist.push(toString(word)); + } + } + wordlist.sort(sortJapanese); + // For some reason kyoku and kiyoku are flipped in node (!!). + // The order SHOULD be: + // - kyoku + // - kiyoku + // This should ignore "if", but that doesn't work here?? + /* c8 ignore start */ + if (hex(wordlist[442]) === KiYoKu && hex(wordlist[443]) === KyoKu) { + const tmp = wordlist[442]; + wordlist[442] = wordlist[443]; + wordlist[443] = tmp; + } + /* c8 ignore stop */ + // Verify the computed list matches the official list + /* istanbul ignore if */ + const checksum = id(wordlist.join("\n") + "\n"); + /* c8 ignore start */ + if (checksum !== "0xcb36b09e6baa935787fd762ce65e80b0c6a8dabdfbc3a7f86ac0e2c4fd111600") { + throw new Error("BIP39 Wordlist for ja (Japanese) FAILED"); + } + /* c8 ignore stop */ + _wordlist = wordlist; + return wordlist; +} +let wordlist = null; +/** + * The [[link-bip39-ja]] for [mnemonic phrases](link-bip-39). + * + * @_docloc: api/wordlists + */ +export class LangJa extends Wordlist { + /** + * Creates a new instance of the Japanese language Wordlist. + * + * This should be unnecessary most of the time as the exported + * [[langJa]] should suffice. + * + * @_ignore: + */ + constructor() { super("ja"); } + getWord(index) { + const words = loadWords(); + assertArgument(index >= 0 && index < words.length, `invalid word index: ${index}`, "index", index); + return words[index]; + } + getWordIndex(word) { + return loadWords().indexOf(word); + } + split(phrase) { + //logger.assertNormalize(); + return phrase.split(/(?:\u3000| )+/g); + } + join(words) { + return words.join("\u3000"); + } + /** + * Returns a singleton instance of a ``LangJa``, creating it + * if this is the first time being called. + */ + static wordlist() { + if (wordlist == null) { + wordlist = new LangJa(); + } + return wordlist; + } +} +//# sourceMappingURL=lang-ja.js.map \ No newline at end of file diff --git a/lib.esm/wordlists/lang-ja.js.map b/lib.esm/wordlists/lang-ja.js.map new file mode 100644 index 00000000..f72046b7 --- /dev/null +++ b/lib.esm/wordlists/lang-ja.js.map @@ -0,0 +1 @@ +{"version":3,"file":"lang-ja.js","sourceRoot":"","sources":["../../src.ts/wordlists/lang-ja.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AACtC,OAAO,EACH,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,YAAY,EACrD,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC,MAAM,IAAI,GAAG;IAET,eAAe;IACf,orEAAorE;IAEprE,eAAe;IACf,ssGAAssG;IAEtsG,eAAe;IACf,4uDAA4uD;IAE5uD,eAAe;IACf,olBAAolB;IAEplB,eAAe;IACf,4JAA4J;IAE5J,eAAe;IACf,0GAA0G;IAE1G,gBAAgB;IAChB,WAAW;CACd,CAAC;AAEF,sDAAsD;AACtD,MAAM,OAAO,GAAG,6FAA6F,CAAA;AAE7G,IAAI,SAAS,GAAyB,IAAI,CAAC;AAE3C,SAAS,GAAG,CAAC,IAAY;IACrB,OAAO,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;AACtC,CAAC;AAED,MAAM,MAAM,GAAG,sBAAsB,CAAC;AACtC,MAAM,KAAK,GAAG,sBAAsB,C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;IACH,gBAAgB,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAE9B,OAAO,CAAC,KAAa;QACjB,MAAM,KAAK,GAAG,SAAS,EAAE,CAAC;QAC1B,cAAc,CAAC,KAAK,IAAI,CAAC,IAAI,KAAK,GAAG,KAAK,CAAC,MAAM,EAC7C,uBAAwB,KAAM,EAAE,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;QACtD,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC;IACxB,CAAC;IAED,YAAY,CAAC,IAAY;QACrB,OAAO,SAAS,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IAED,KAAK,CAAC,MAAc;QAChB,2BAA2B;QAC3B,OAAO,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;IAC1C,CAAC;IAED,IAAI,CAAC,KAAoB;QACrB,OAAO,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAChC,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,QAAQ;QACX,IAAI,QAAQ,IAAI,IAAI,EAAE;YAAE,QAAQ,GAAG,IAAI,MAAM,EAAE,CAAC;SAAE;QAClD,OAAO,QAAQ,CAAC;IACpB,CAAC;CACJ"} \ No newline at end of file diff --git a/lib.esm/wordlists/lang-ko.d.ts b/lib.esm/wordlists/lang-ko.d.ts new file mode 100644 index 00000000..4329e055 --- /dev/null +++ b/lib.esm/wordlists/lang-ko.d.ts @@ -0,0 +1,25 @@ +import { Wordlist } from "./wordlist.js"; +/** + * The [[link-bip39-ko]] for [mnemonic phrases](link-bip-39). + * + * @_docloc: api/wordlists + */ +export declare class LangKo extends Wordlist { + /** + * Creates a new instance of the Korean language Wordlist. + * + * This should be unnecessary most of the time as the exported + * [[langKo]] should suffice. + * + * @_ignore: + */ + constructor(); + getWord(index: number): string; + getWordIndex(word: string): number; + /** + * Returns a singleton instance of a ``LangKo``, creating it + * if this is the first time being called. + */ + static wordlist(): LangKo; +} +//# sourceMappingURL=lang-ko.d.ts.map \ No newline at end of file diff --git a/lib.esm/wordlists/lang-ko.d.ts.map b/lib.esm/wordlists/lang-ko.d.ts.map new file mode 100644 index 00000000..71fbbcdf --- /dev/null +++ b/lib.esm/wordlists/lang-ko.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"lang-ko.d.ts","sourceRoot":"","sources":["../../src.ts/wordlists/lang-ko.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AA8DzC;;;;GAIG;AACH,qBAAa,MAAO,SAAQ,QAAQ;IAEhC;;;;;;;OAOG;;IAKH,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAO9B,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAIlC;;;OAGG;IACH,MAAM,CAAC,QAAQ,IAAI,MAAM;CAI5B"} \ No newline at end of file diff --git a/lib.esm/wordlists/lang-ko.js b/lib.esm/wordlists/lang-ko.js new file mode 100644 index 00000000..d575f874 --- /dev/null +++ b/lib.esm/wordlists/lang-ko.js @@ -0,0 +1,89 @@ +import { id } from "../hash/index.js"; +import { assertArgument, toUtf8String } from "../utils/index.js"; +import { Wordlist } from "./wordlist.js"; +const data = [ + "OYAa", + "ATAZoATBl3ATCTrATCl8ATDloATGg3ATHT8ATJT8ATJl3ATLlvATLn4ATMT8ATMX8ATMboATMgoAToLbAToMTATrHgATvHnAT3AnAT3JbAT3MTAT8DbAT8JTAT8LmAT8MYAT8MbAT#LnAUHT8AUHZvAUJXrAUJX8AULnrAXJnvAXLUoAXLgvAXMn6AXRg3AXrMbAX3JTAX3QbAYLn3AZLgvAZrSUAZvAcAZ8AaAZ8AbAZ8AnAZ8HnAZ8LgAZ8MYAZ8MgAZ8OnAaAboAaDTrAaFTrAaJTrAaJboAaLVoAaMXvAaOl8AaSeoAbAUoAbAg8AbAl4AbGnrAbMT8AbMXrAbMn4AbQb8AbSV8AbvRlAb8AUAb8AnAb8HgAb8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gGnCk3Mg8JbAnLX4QYvFYHnMXrRUoJnGnvFnRlvFTJlQnoSTrBXHXrLYSUJgLfoMT8Se8DTrHbDb", + "AbDl8SToJU8An3RbAb8ST8DUSTrGnrAgoLbFU6Db8LTrMg8AaHT8Jb8ObDl8SToJU8Pb3RlvFYoJl" +]; +const codes = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*"; +function getHangul(code) { + if (code >= 40) { + code = code + 168 - 40; + } + else if (code >= 19) { + code = code + 97 - 19; + } + return toUtf8String(new Uint8Array([225, (code >> 6) + 132, (code & 0x3f) + 128])); +} +let _wordlist = null; +function loadWords() { + if (_wordlist != null) { + return _wordlist; + } + const wordlist = []; + data.forEach((data, length) => { + length += 4; + for (let i = 0; i < data.length; i += length) { + let word = ""; + for (let j = 0; j < length; j++) { + word += getHangul(codes.indexOf(data[i + j])); + } + wordlist.push(word); + } + }); + wordlist.sort(); + // Verify the computed list matches the official list + /* istanbul ignore if */ + const checksum = id(wordlist.join("\n") + "\n"); + /* c8 ignore start */ + if (checksum !== "0xf9eddeace9c5d3da9c93cf7d3cd38f6a13ed3affb933259ae865714e8a3ae71a") { + throw new Error("BIP39 Wordlist for ko (Korean) FAILED"); + } + /* c8 ignore stop */ + _wordlist = wordlist; + return wordlist; +} +let wordlist = null; +/** + * The [[link-bip39-ko]] for [mnemonic phrases](link-bip-39). + * + * @_docloc: api/wordlists + */ +export class LangKo extends Wordlist { + /** + * Creates a new instance of the Korean language Wordlist. + * + * This should be unnecessary most of the time as the exported + * [[langKo]] should suffice. + * + * @_ignore: + */ + constructor() { + super("ko"); + } + getWord(index) { + const words = loadWords(); + assertArgument(index >= 0 && index < words.length, `invalid word index: ${index}`, "index", index); + return words[index]; + } + getWordIndex(word) { + return loadWords().indexOf(word); + } + /** + * Returns a singleton instance of a ``LangKo``, creating it + * if this is the first time being called. + */ + static wordlist() { + if (wordlist == null) { + wordlist = new LangKo(); + } + return wordlist; + } +} +//# sourceMappingURL=lang-ko.js.map \ No newline at end of file diff --git a/lib.esm/wordlists/lang-ko.js.map b/lib.esm/wordlists/lang-ko.js.map new file mode 100644 index 00000000..bee4337b --- /dev/null +++ b/lib.esm/wordlists/lang-ko.js.map @@ -0,0 +1 @@ +{"version":3,"file":"lang-ko.js","sourceRoot":"","sources":["../../src.ts/wordlists/lang-ko.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC,MAAM,IAAI,GAAG;IACT,MAAM;IACN,y5JAAy5J;IACz5J,8lIAA8lI;IAC9lI,i8BAAi8B;IACj8B,koCAAkoC;IACloC,yaAAya;IACza,gHAAgH;IAChH,+EAA+E;CAClF,CAAA;AAED,MAAM,KAAK,GAAG,wEAAwE,CAAA;AAEtF,SAAS,SAAS,CAAC,IAAY;IAC3B,IAAI,IAAI,IAAI,EAAE,EAAE;QACZ,IAAI,GAAG,IAAI,GAAG,GAAG,GAAG,EAAE,CAAC;KAC1B;SAAM,IAAI,IAAI,IAAI,EAAE,EAAE;QACnB,IAAI,GAAG,IAAI,GAAG,EAAE,GAAG,EAAE,CAAC;KACzB;IAED,OAAO,YAAY,CAAC,IAAI,UAAU,CAAC,CAAE,GAAG,EAAE,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;AACxF,CAAC;AAED,IAAI,SAAS,GAAyB,IAAI,CAAC;AAE3C,SAAS,SAAS;IACd,IAAI,SAAS,IAAI,IAAI,EAAE;QAAE,OAAO,SAAS,CAAC;KAAE;IAE5C,MAAM,QAAQ,GAAkB,EAAG,CAAC;IAEpC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,M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;IACxB,CAAC;IAED,YAAY,CAAC,IAAY;QACrB,OAAO,SAAS,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,QAAQ;QACX,IAAI,QAAQ,IAAI,IAAI,EAAE;YAAE,QAAQ,GAAG,IAAI,MAAM,EAAE,CAAC;SAAE;QAClD,OAAO,QAAQ,CAAC;IACpB,CAAC;CACJ"} \ No newline at end of file diff --git a/lib.esm/wordlists/lang-pt.d.ts b/lib.esm/wordlists/lang-pt.d.ts new file mode 100644 index 00000000..f218013c --- /dev/null +++ b/lib.esm/wordlists/lang-pt.d.ts @@ -0,0 +1,23 @@ +import { WordlistOwl } from "./wordlist-owl.js"; +/** + * The [[link-bip39-pt]] for [mnemonic phrases](link-bip-39). + * + * @_docloc: api/wordlists + */ +export declare class LangPt extends WordlistOwl { + /** + * Creates a new instance of the Portuguese language Wordlist. + * + * This should be unnecessary most of the time as the exported + * [[langPt]] should suffice. + * + * @_ignore: + */ + constructor(); + /** + * Returns a singleton instance of a ``LangPt``, creating it + * if this is the first time being called. + */ + static wordlist(): LangPt; +} +//# sourceMappingURL=lang-pt.d.ts.map \ No newline at end of file diff --git a/lib.esm/wordlists/lang-pt.d.ts.map b/lib.esm/wordlists/lang-pt.d.ts.map new file mode 100644 index 00000000..68f390d5 --- /dev/null +++ b/lib.esm/wordlists/lang-pt.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"lang-pt.d.ts","sourceRoot":"","sources":["../../src.ts/wordlists/lang-pt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAOhD;;;;GAIG;AACH,qBAAa,MAAO,SAAQ,WAAW;IAEnC;;;;;;;OAOG;;IAGH;;;OAGG;IACH,MAAM,CAAC,QAAQ,IAAI,MAAM;CAI5B"} \ No newline at end of file diff --git a/lib.esm/wordlists/lang-pt.js b/lib.esm/wordlists/lang-pt.js new file mode 100644 index 00000000..a76cc595 --- /dev/null +++ b/lib.esm/wordlists/lang-pt.js @@ -0,0 +1,31 @@ +import { WordlistOwl } from "./wordlist-owl.js"; +const words = "0arad!ototealirertainrasoent hoandoaR#riareha!aroele'oronul0Aca%AixoAl A%rDuz'El]Er$IsmoO$ Rum S-&T(i&TigoVo[=0F&.Il#P' S?S* So&/Sun$Tr&0Ac#Adu+Al/A[f E End(Er_EuIng'Ir?IvoOl{oRac Revi=RizU&Um0Di$rM-.R>o+TismoT|@Tu 0Ali An%Ar@Ent&Es,I?Is Ul,1Ila1Ar E=Ei%Ulejo:B BosaC&]uCh `C@GagemI+c>~/Se#S)n%Ta)Te=rTidaTomTuc Unil]3B(IjoIr^IsebolLd!eLezaLgaLisc Ndi$Ng&aNz(RimbauRl*d>_Sou_XigaZ(_3CoCu=En&Foc&Furc G|naLhe%Mest[Mo$rOlog@OmboOsf(aPol Rr-$Scoi$Sne$SpoSsex$TolaZ _2Ind#OcoOque 2A$BagemC#CejoChec]Ico.L^LetimL]LoMb{oNdeNecoNi)Rb~h>d>e&R+c]V*oXe?2AncoAsaAvezaEuIgaIl/Inc OaOchu+Onze O$Uxo2C]DismoF LeRacoScaS$Z*a:Bimb Rn{oRpe%R['>)zRv&/SacoScaSeb[S%loS~oT a)Tiv UleUs?U%l V&oV(na3BolaDil]G}]Lebr L~ Nou+N,N%ioRc Rr#R%'oRvejaTimV^2Aco)Al{aAm#Ap^ArmeAticeAveEfeEg^E'oEqueIco%If[In`oOc&/Ov(UmboU.Uva0CatrizCl}eD!eD['aEn%Gcui$Rurg@T 2A[zaE_Ic OneUbe2A=Ag'Ba@B($rBr C^El/Ent_E,Gum`oIb'IfaIo%L L{aLh(Lid'Lme@L}oLunaM<=Mb* M-.MitivaMov(MplexoMumNc]N=rNec.Nfu,Ng` Nhec(Njug Nsum'Nt+$Nvi%Op( P{oPi?PoQue%lRagemRdi&Rne)R}h>p|&R[ioR%joRuj>voSs-oS%laT}e%U_UveVilZ*]2A%+AvoEc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Ref>j>+xaTuagemUr*oXativoXis)3Atr&C(Ci=Cl#Dio,IaIm Lef}eLh#Mp(oN-%N,rN.Rm&RnoRr-oSeSou+St#ToXtu+Xugo3A+G`aJoloMbr MidezNgi=N%'oRagemT~ 5Al]C]L( LiceM^Mil/N`Ntu+Pe%R>ci=RneioRqueRr!>$S.UcaUp{aX*a2Ab&/Acej Adu$rAfeg Aje$AmaAnc ApoAs{oAt?Av E*oEm(Epid EvoIagemIboIcicloId-%Ilog@Ind!eIploItur Iunf&Oc Ombe)OvaUnfoUque2B~ CquesaT` T|i&:7V 3Bigo0HaId!eIf|me3Olog@SoTigaUbu0A=InaUfru':C*aDi G o,I=,LaL-%Lid!eLo[sN)gemQu{oRe)Rr(Sc~ Sil]S,u+Z Zio3A=D Ge.Ic~ L{oLhiceLu=Nce=rNdav&N( Nt[Rb&Rd!eRe?Rg}h>m`/RnizRs R%n%SpaSti=T|i&3Adu$AgemAj Atu+Br?D{aDr @ElaGaG-%Gi G| L ejoNcoNhe)NilOle)R!>tudeSi.S$Tr&V{oZ*/5A=rArG&L<%LeibolL)gemLumo,Nt!e5L$Vuz`a::D[zRope3QueRe.Rife3Ng ::Ng#Rp 3BuL?9Mb Olog@5Mbi="; +const checksum = "0x2219000926df7b50d8aa0a3d495826b988287df4657fbd100e6fe596c8f737ac"; +let wordlist = null; +/** + * The [[link-bip39-pt]] for [mnemonic phrases](link-bip-39). + * + * @_docloc: api/wordlists + */ +export class LangPt extends WordlistOwl { + /** + * Creates a new instance of the Portuguese language Wordlist. + * + * This should be unnecessary most of the time as the exported + * [[langPt]] should suffice. + * + * @_ignore: + */ + constructor() { super("pt", words, checksum); } + /** + * Returns a singleton instance of a ``LangPt``, creating it + * if this is the first time being called. + */ + static wordlist() { + if (wordlist == null) { + wordlist = new LangPt(); + } + return wordlist; + } +} +//# sourceMappingURL=lang-pt.js.map \ No newline at end of file diff --git a/lib.esm/wordlists/lang-pt.js.map b/lib.esm/wordlists/lang-pt.js.map new file mode 100644 index 00000000..c77ff409 --- /dev/null +++ b/lib.esm/wordlists/lang-pt.js.map @@ -0,0 +1 @@ +{"version":3,"file":"lang-pt.js","sourceRoot":"","sources":["../../src.ts/wordlists/lang-pt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,KAAK,GAAG,s0OAAs0O,CAAC;AACr1O,MAAM,QAAQ,GAAG,oEAAoE,CAAC;AAEtF,IAAI,QAAQ,GAAkB,IAAI,CAAC;AAEnC;;;;GAIG;AACH,MAAM,OAAO,MAAO,SAAQ,WAAW;IAEnC;;;;;;;OAOG;IACH,gBAAgB,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IAE/C;;;OAGG;IACH,MAAM,CAAC,QAAQ;QACX,IAAI,QAAQ,IAAI,IAAI,EAAE;YAAE,QAAQ,GAAG,IAAI,MAAM,EAAE,CAAC;SAAE;QAClD,OAAO,QAAQ,CAAC;IACpB,CAAC;CACJ"} \ No newline at end of file diff --git a/lib.esm/wordlists/lang-zh.d.ts b/lib.esm/wordlists/lang-zh.d.ts new file mode 100644 index 00000000..5d0c14c7 --- /dev/null +++ b/lib.esm/wordlists/lang-zh.d.ts @@ -0,0 +1,32 @@ +import { Wordlist } from "./wordlist.js"; +/** + * The [[link-bip39-zh_cn]] and [[link-bip39-zh_tw]] for + * [mnemonic phrases](link-bip-39). + * + * @_docloc: api/wordlists + */ +export declare class LangZh extends Wordlist { + /** + * Creates a new instance of the Chinese language Wordlist for + * the %%dialect%%, either ``"cn"`` or ``"tw"`` for simplified + * or traditional, respectively. + * + * This should be unnecessary most of the time as the exported + * [[langZhCn]] and [[langZhTw]] should suffice. + * + * @_ignore: + */ + constructor(dialect: string); + getWord(index: number): string; + getWordIndex(word: string): number; + split(phrase: string): Array; + /** + * Returns a singleton instance of a ``LangZh`` for %%dialect%%, + * creating it if this is the first time being called. + * + * Use the %%dialect%% ``"cn"`` or ``"tw"`` for simplified or + * traditional, respectively. + */ + static wordlist(dialect: string): LangZh; +} +//# sourceMappingURL=lang-zh.d.ts.map \ No newline at end of file diff --git a/lib.esm/wordlists/lang-zh.d.ts.map b/lib.esm/wordlists/lang-zh.d.ts.map new file mode 100644 index 00000000..7b96b48e --- /dev/null +++ b/lib.esm/wordlists/lang-zh.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"lang-zh.d.ts","sourceRoot":"","sources":["../../src.ts/wordlists/lang-zh.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AA2DzC;;;;;GAKG;AACH,qBAAa,MAAO,SAAQ,QAAQ;IAEhC;;;;;;;;;OASG;gBACS,OAAO,EAAE,MAAM;IAE3B,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAO9B,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAIlC,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;IAKpC;;;;;;OAMG;IACH,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;CAM3C"} \ No newline at end of file diff --git a/lib.esm/wordlists/lang-zh.js b/lib.esm/wordlists/lang-zh.js new file mode 100644 index 00000000..cabbca27 --- /dev/null +++ b/lib.esm/wordlists/lang-zh.js @@ -0,0 +1,92 @@ +import { id } from "../hash/index.js"; +import { assertArgument, toUtf8String } from "../utils/index.js"; +import { Wordlist } from "./wordlist.js"; +const data = "}aE#4A=Yv&co#4N#6G=cJ&SM#66|/Z#4t&kn~46#4K~4q%b9=IR#7l,mB#7W_X2*dl}Uo~7s}Uf&Iw#9c&cw~6O&H6&wx&IG%v5=IQ~8a&Pv#47$PR&50%Ko&QM&3l#5f,D9#4L|/H&tQ;v0~6n]nN> 2), + 128 + codes.indexOf(data[i * 3 + 1]), + 128 + codes.indexOf(data[i * 3 + 2]), + ]; + if (locale === "zh_tw") { + const common = s % 4; + for (let i = common; i < 3; i++) { + bytes[i] = codes.indexOf(deltaData[deltaOffset++]) + ((i == 0) ? 228 : 128); + } + } + wordlist.push(toUtf8String(new Uint8Array(bytes))); + } + // Verify the computed list matches the official list + const checksum = id(wordlist.join("\n") + "\n"); + /* c8 ignore start */ + if (checksum !== Checks[locale]) { + throw new Error(`BIP39 Wordlist for ${locale} (Chinese) FAILED`); + } + /* c8 ignore stop */ + _wordlist[locale] = wordlist; + return wordlist; +} +const wordlists = {}; +/** + * The [[link-bip39-zh_cn]] and [[link-bip39-zh_tw]] for + * [mnemonic phrases](link-bip-39). + * + * @_docloc: api/wordlists + */ +export class LangZh extends Wordlist { + /** + * Creates a new instance of the Chinese language Wordlist for + * the %%dialect%%, either ``"cn"`` or ``"tw"`` for simplified + * or traditional, respectively. + * + * This should be unnecessary most of the time as the exported + * [[langZhCn]] and [[langZhTw]] should suffice. + * + * @_ignore: + */ + constructor(dialect) { super("zh_" + dialect); } + getWord(index) { + const words = loadWords(this.locale); + assertArgument(index >= 0 && index < words.length, `invalid word index: ${index}`, "index", index); + return words[index]; + } + getWordIndex(word) { + return loadWords(this.locale).indexOf(word); + } + split(phrase) { + phrase = phrase.replace(/(?:\u3000| )+/g, ""); + return phrase.split(""); + } + /** + * Returns a singleton instance of a ``LangZh`` for %%dialect%%, + * creating it if this is the first time being called. + * + * Use the %%dialect%% ``"cn"`` or ``"tw"`` for simplified or + * traditional, respectively. + */ + static wordlist(dialect) { + if (wordlists[dialect] == null) { + wordlists[dialect] = new LangZh(dialect); + } + return wordlists[dialect]; + } +} +//# sourceMappingURL=lang-zh.js.map \ No newline at end of file diff --git a/lib.esm/wordlists/lang-zh.js.map b/lib.esm/wordlists/lang-zh.js.map new file mode 100644 index 00000000..22ba9a07 --- /dev/null +++ b/lib.esm/wordlists/lang-zh.js.map @@ -0,0 +1 @@ +{"version":3,"file":"lang-zh.js","sourceRoot":"","sources":["../../src.ts/wordlists/lang-zh.ts"],"names":[],"mappings":"AAAA,O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AC;IAED,YAAY,CAAC,IAAY;QACrB,OAAO,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,CAAC;IAED,KAAK,CAAC,MAAc;QAChB,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAC;QAC9C,OAAO,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAC5B,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,QAAQ,CAAC,OAAe;QAC3B,IAAI,SAAS,CAAC,OAAO,CAAC,IAAI,IAAI,EAAE;YAC5B,SAAS,CAAC,OAAO,CAAC,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC;SAC5C;QACD,OAAO,SAAS,CAAC,OAAO,CAAC,CAAC;IAC9B,CAAC;CACJ"} \ No newline at end of file diff --git a/lib.esm/wordlists/wordlist-owl.d.ts b/lib.esm/wordlists/wordlist-owl.d.ts new file mode 100644 index 00000000..c4d1efc0 --- /dev/null +++ b/lib.esm/wordlists/wordlist-owl.d.ts @@ -0,0 +1,32 @@ +import { Wordlist } from "./wordlist.js"; +/** + * An OWL format Wordlist is an encoding method that exploits + * the general locality of alphabetically sorted words to + * achieve a simple but effective means of compression. + * + * This class is generally not useful to most developers as + * it is used mainly internally to keep Wordlists for languages + * based on ASCII-7 small. + * + * If necessary, there are tools within the ``generation/`` folder + * to create the necessary data. + */ +export declare class WordlistOwl extends Wordlist { + #private; + /** + * Creates a new Wordlist for %%locale%% using the OWL %%data%% + * and validated against the %%checksum%%. + */ + constructor(locale: string, data: string, checksum: string); + /** + * The OWL-encoded data. + */ + get _data(): string; + /** + * Decode all the words for the wordlist. + */ + _decodeWords(): Array; + getWord(index: number): string; + getWordIndex(word: string): number; +} +//# sourceMappingURL=wordlist-owl.d.ts.map \ No newline at end of file diff --git a/lib.esm/wordlists/wordlist-owl.d.ts.map b/lib.esm/wordlists/wordlist-owl.d.ts.map new file mode 100644 index 00000000..fe49ddf8 --- /dev/null +++ b/lib.esm/wordlists/wordlist-owl.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"wordlist-owl.d.ts","sourceRoot":"","sources":["../../src.ts/wordlists/wordlist-owl.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC;;;;;;;;;;;GAWG;AACH,qBAAa,WAAY,SAAQ,QAAQ;;IAIrC;;;OAGG;gBACS,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IAO1D;;OAEG;IACH,IAAI,KAAK,IAAI,MAAM,CAAuB;IAE1C;;OAEG;IACH,YAAY,IAAI,KAAK,CAAC,MAAM,CAAC;IAsB7B,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAM9B,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;CAGrC"} \ No newline at end of file diff --git a/lib.esm/wordlists/wordlist-owl.js b/lib.esm/wordlists/wordlist-owl.js new file mode 100644 index 00000000..eb3e6be0 --- /dev/null +++ b/lib.esm/wordlists/wordlist-owl.js @@ -0,0 +1,66 @@ +// Use the encode-latin.js script to create the necessary +// data files to be consumed by this class +import { id } from "../hash/index.js"; +import { assertArgument } from "../utils/index.js"; +import { decodeOwl } from "./decode-owl.js"; +import { Wordlist } from "./wordlist.js"; +/** + * An OWL format Wordlist is an encoding method that exploits + * the general locality of alphabetically sorted words to + * achieve a simple but effective means of compression. + * + * This class is generally not useful to most developers as + * it is used mainly internally to keep Wordlists for languages + * based on ASCII-7 small. + * + * If necessary, there are tools within the ``generation/`` folder + * to create the necessary data. + */ +export class WordlistOwl extends Wordlist { + #data; + #checksum; + /** + * Creates a new Wordlist for %%locale%% using the OWL %%data%% + * and validated against the %%checksum%%. + */ + constructor(locale, data, checksum) { + super(locale); + this.#data = data; + this.#checksum = checksum; + this.#words = null; + } + /** + * The OWL-encoded data. + */ + get _data() { return this.#data; } + /** + * Decode all the words for the wordlist. + */ + _decodeWords() { + return decodeOwl(this.#data); + } + #words; + #loadWords() { + if (this.#words == null) { + const words = this._decodeWords(); + // Verify the computed list matches the official list + const checksum = id(words.join("\n") + "\n"); + /* c8 ignore start */ + if (checksum !== this.#checksum) { + throw new Error(`BIP39 Wordlist for ${this.locale} FAILED`); + } + /* c8 ignore stop */ + this.#words = words; + } + return this.#words; + } + getWord(index) { + const words = this.#loadWords(); + assertArgument(index >= 0 && index < words.length, `invalid word index: ${index}`, "index", index); + return words[index]; + } + getWordIndex(word) { + return this.#loadWords().indexOf(word); + } +} +//# sourceMappingURL=wordlist-owl.js.map \ No newline at end of file diff --git a/lib.esm/wordlists/wordlist-owl.js.map b/lib.esm/wordlists/wordlist-owl.js.map new file mode 100644 index 00000000..a7bda021 --- /dev/null +++ b/lib.esm/wordlists/wordlist-owl.js.map @@ -0,0 +1 @@ +{"version":3,"file":"wordlist-owl.js","sourceRoot":"","sources":["../../src.ts/wordlists/wordlist-owl.ts"],"names":[],"mappings":"AACA,yDAAyD;AACzD,0CAA0C;AAE1C,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,WAAY,SAAQ,QAAQ;IACrC,KAAK,CAAS;IACd,SAAS,CAAS;IAElB;;;OAGG;IACH,YAAY,MAAc,EAAE,IAAY,EAAE,QAAgB;QACtD,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,IAAI,KAAK,KAAa,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAE1C;;OAEG;IACH,YAAY;QACR,OAAO,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;IAED,MAAM,CAAuB;IAC7B,UAAU;QACN,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,EAAE;YACrB,MAAM,KAAK,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;YAElC,qDAAqD;YACrD,MAAM,QAAQ,GAAG,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;YAC7C,qBAAqB;YACrB,IAAI,QAAQ,KAAK,IAAI,CAAC,SAAS,EAAE;gBAC7B,MAAM,IAAI,KAAK,CAAC,sBAAuB,IAAI,CAAC,MAAO,SAAS,CAAC,CAAC;aACjE;YACD,oBAAoB;YAEpB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;SACvB;QACD,OAAO,IAAI,CAAC,MAAM,CAAC;IACvB,CAAC;IAED,OAAO,CAAC,KAAa;QACjB,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QAChC,cAAc,CAAC,KAAK,IAAI,CAAC,IAAI,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,uBAAwB,KAAM,EAAE,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;QACrG,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC;IACxB,CAAC;IAED,YAAY,CAAC,IAAY;QACrB,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3C,CAAC;CACJ"} \ No newline at end of file diff --git a/lib.esm/wordlists/wordlist-owla.d.ts b/lib.esm/wordlists/wordlist-owla.d.ts new file mode 100644 index 00000000..c87022df --- /dev/null +++ b/lib.esm/wordlists/wordlist-owla.d.ts @@ -0,0 +1,30 @@ +import { WordlistOwl } from "./wordlist-owl.js"; +/** + * An OWL-A format Wordlist extends the OWL format to add an + * overlay onto an OWL format Wordlist to support diacritic + * marks. + * + * This class is generally not useful to most developers as + * it is used mainly internally to keep Wordlists for languages + * based on latin-1 small. + * + * If necessary, there are tools within the ``generation/`` folder + * to create the necessary data. + */ +export declare class WordlistOwlA extends WordlistOwl { + #private; + /** + * Creates a new Wordlist for %%locale%% using the OWLA %%data%% + * and %%accent%% data and validated against the %%checksum%%. + */ + constructor(locale: string, data: string, accent: string, checksum: string); + /** + * The OWLA-encoded accent data. + */ + get _accent(): string; + /** + * Decode all the words for the wordlist. + */ + _decodeWords(): Array; +} +//# sourceMappingURL=wordlist-owla.d.ts.map \ No newline at end of file diff --git a/lib.esm/wordlists/wordlist-owla.d.ts.map b/lib.esm/wordlists/wordlist-owla.d.ts.map new file mode 100644 index 00000000..97ed583b --- /dev/null +++ b/lib.esm/wordlists/wordlist-owla.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"wordlist-owla.d.ts","sourceRoot":"","sources":["../../src.ts/wordlists/wordlist-owla.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhD;;;;;;;;;;;GAWG;AACH,qBAAa,YAAa,SAAQ,WAAW;;IAIzC;;;OAGG;gBACS,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IAK1E;;OAEG;IACH,IAAI,OAAO,IAAI,MAAM,CAAyB;IAE9C;;OAEG;IACH,YAAY,IAAI,KAAK,CAAC,MAAM,CAAC;CAGhC"} \ No newline at end of file diff --git a/lib.esm/wordlists/wordlist-owla.js b/lib.esm/wordlists/wordlist-owla.js new file mode 100644 index 00000000..9764a698 --- /dev/null +++ b/lib.esm/wordlists/wordlist-owla.js @@ -0,0 +1,36 @@ +import { WordlistOwl } from "./wordlist-owl.js"; +import { decodeOwlA } from "./decode-owla.js"; +/** + * An OWL-A format Wordlist extends the OWL format to add an + * overlay onto an OWL format Wordlist to support diacritic + * marks. + * + * This class is generally not useful to most developers as + * it is used mainly internally to keep Wordlists for languages + * based on latin-1 small. + * + * If necessary, there are tools within the ``generation/`` folder + * to create the necessary data. + */ +export class WordlistOwlA extends WordlistOwl { + #accent; + /** + * Creates a new Wordlist for %%locale%% using the OWLA %%data%% + * and %%accent%% data and validated against the %%checksum%%. + */ + constructor(locale, data, accent, checksum) { + super(locale, data, checksum); + this.#accent = accent; + } + /** + * The OWLA-encoded accent data. + */ + get _accent() { return this.#accent; } + /** + * Decode all the words for the wordlist. + */ + _decodeWords() { + return decodeOwlA(this._data, this._accent); + } +} +//# sourceMappingURL=wordlist-owla.js.map \ No newline at end of file diff --git a/lib.esm/wordlists/wordlist-owla.js.map b/lib.esm/wordlists/wordlist-owla.js.map new file mode 100644 index 00000000..58c7bd67 --- /dev/null +++ b/lib.esm/wordlists/wordlist-owla.js.map @@ -0,0 +1 @@ +{"version":3,"file":"wordlist-owla.js","sourceRoot":"","sources":["../../src.ts/wordlists/wordlist-owla.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,YAAa,SAAQ,WAAW;IACzC,OAAO,CAAS;IAGhB;;;OAGG;IACH,YAAY,MAAc,EAAE,IAAY,EAAE,MAAc,EAAE,QAAgB;QACtE,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;QAC9B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,IAAI,OAAO,KAAa,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAE9C;;OAEG;IACH,YAAY;QACR,OAAO,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IAChD,CAAC;CACJ"} \ No newline at end of file diff --git a/lib.esm/wordlists/wordlist.d.ts b/lib.esm/wordlists/wordlist.d.ts new file mode 100644 index 00000000..cb843f3e --- /dev/null +++ b/lib.esm/wordlists/wordlist.d.ts @@ -0,0 +1,47 @@ +/** + * A Wordlist represents a collection of language-specific + * words used to encode and devoce [[link-bip-39]] encoded data + * by mapping words to 11-bit values and vice versa. + */ +export declare abstract class Wordlist { + locale: string; + /** + * Creates a new Wordlist instance. + * + * Sub-classes MUST call this if they provide their own constructor, + * passing in the locale string of the language. + * + * Generally there is no need to create instances of a Wordlist, + * since each language-specific Wordlist creates an instance and + * there is no state kept internally, so they are safe to share. + */ + constructor(locale: string); + /** + * Sub-classes may override this to provide a language-specific + * method for spliting %%phrase%% into individual words. + * + * By default, %%phrase%% is split using any sequences of + * white-space as defined by regular expressions (i.e. ``/\s+/``). + */ + split(phrase: string): Array; + /** + * Sub-classes may override this to provider a language-specific + * method for joining %%words%% into a phrase. + * + * By default, %%words%% are joined by a single space. + */ + join(words: Array): string; + /** + * Maps an 11-bit value into its coresponding word in the list. + * + * Sub-classes MUST override this. + */ + abstract getWord(index: number): string; + /** + * Maps a word to its corresponding 11-bit value. + * + * Sub-classes MUST override this. + */ + abstract getWordIndex(word: string): number; +} +//# sourceMappingURL=wordlist.d.ts.map \ No newline at end of file diff --git a/lib.esm/wordlists/wordlist.d.ts.map b/lib.esm/wordlists/wordlist.d.ts.map new file mode 100644 index 00000000..6ba6025d --- /dev/null +++ b/lib.esm/wordlists/wordlist.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"wordlist.d.ts","sourceRoot":"","sources":["../../src.ts/wordlists/wordlist.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,8BAAsB,QAAQ;IAC1B,MAAM,EAAG,MAAM,CAAC;IAEhB;;;;;;;;;OASG;gBACS,MAAM,EAAE,MAAM;IAI1B;;;;;;OAMG;IACH,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;IAIpC;;;;;OAKG;IACH,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM;IAIlC;;;;OAIG;IACH,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAEvC;;;;OAIG;IACH,QAAQ,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;CAC9C"} \ No newline at end of file diff --git a/lib.esm/wordlists/wordlist.js b/lib.esm/wordlists/wordlist.js new file mode 100644 index 00000000..6327a49d --- /dev/null +++ b/lib.esm/wordlists/wordlist.js @@ -0,0 +1,42 @@ +import { defineProperties } from "../utils/index.js"; +/** + * A Wordlist represents a collection of language-specific + * words used to encode and devoce [[link-bip-39]] encoded data + * by mapping words to 11-bit values and vice versa. + */ +export class Wordlist { + locale; + /** + * Creates a new Wordlist instance. + * + * Sub-classes MUST call this if they provide their own constructor, + * passing in the locale string of the language. + * + * Generally there is no need to create instances of a Wordlist, + * since each language-specific Wordlist creates an instance and + * there is no state kept internally, so they are safe to share. + */ + constructor(locale) { + defineProperties(this, { locale }); + } + /** + * Sub-classes may override this to provide a language-specific + * method for spliting %%phrase%% into individual words. + * + * By default, %%phrase%% is split using any sequences of + * white-space as defined by regular expressions (i.e. ``/\s+/``). + */ + split(phrase) { + return phrase.toLowerCase().split(/\s+/g); + } + /** + * Sub-classes may override this to provider a language-specific + * method for joining %%words%% into a phrase. + * + * By default, %%words%% are joined by a single space. + */ + join(words) { + return words.join(" "); + } +} +//# sourceMappingURL=wordlist.js.map \ No newline at end of file diff --git a/lib.esm/wordlists/wordlist.js.map b/lib.esm/wordlists/wordlist.js.map new file mode 100644 index 00000000..9ee157a9 --- /dev/null +++ b/lib.esm/wordlists/wordlist.js.map @@ -0,0 +1 @@ +{"version":3,"file":"wordlist.js","sourceRoot":"","sources":["../../src.ts/wordlists/wordlist.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErD;;;;GAIG;AACH,MAAM,OAAgB,QAAQ;IAC1B,MAAM,CAAU;IAEhB;;;;;;;;;OASG;IACH,YAAY,MAAc;QACtB,gBAAgB,CAAW,IAAI,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IACjD,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,MAAc;QAChB,OAAO,MAAM,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;IAC7C,CAAC;IAED;;;;;OAKG;IACH,IAAI,CAAC,KAAoB;QACrB,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;CAeJ"} \ No newline at end of file diff --git a/lib.esm/wordlists/wordlists-browser.d.ts b/lib.esm/wordlists/wordlists-browser.d.ts new file mode 100644 index 00000000..d0dbd19c --- /dev/null +++ b/lib.esm/wordlists/wordlists-browser.d.ts @@ -0,0 +1,3 @@ +import type { Wordlist } from "./wordlist.js"; +export declare const wordlists: Record; +//# sourceMappingURL=wordlists-browser.d.ts.map \ No newline at end of file diff --git a/lib.esm/wordlists/wordlists-browser.d.ts.map b/lib.esm/wordlists/wordlists-browser.d.ts.map new file mode 100644 index 00000000..1d6074e1 --- /dev/null +++ b/lib.esm/wordlists/wordlists-browser.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"wordlists-browser.d.ts","sourceRoot":"","sources":["../../src.ts/wordlists/wordlists-browser.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAG9C,CAAC"} \ No newline at end of file diff --git a/lib.esm/wordlists/wordlists-browser.js b/lib.esm/wordlists/wordlists-browser.js new file mode 100644 index 00000000..045ae76f --- /dev/null +++ b/lib.esm/wordlists/wordlists-browser.js @@ -0,0 +1,7 @@ +import { LangEn } from "./lang-en.js"; +import { LangEs } from "./lang-es.js"; +export const wordlists = { + en: LangEn.wordlist(), + es: LangEs.wordlist(), +}; +//# sourceMappingURL=wordlists-browser.js.map \ No newline at end of file diff --git a/lib.esm/wordlists/wordlists-browser.js.map b/lib.esm/wordlists/wordlists-browser.js.map new file mode 100644 index 00000000..3225a5dc --- /dev/null +++ b/lib.esm/wordlists/wordlists-browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"wordlists-browser.js","sourceRoot":"","sources":["../../src.ts/wordlists/wordlists-browser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAItC,MAAM,CAAC,MAAM,SAAS,GAA6B;IACjD,EAAE,EAAE,MAAM,CAAC,QAAQ,EAAE;IACrB,EAAE,EAAE,MAAM,CAAC,QAAQ,EAAE;CACtB,CAAC"} \ No newline at end of file diff --git a/lib.esm/wordlists/wordlists-extra.d.ts b/lib.esm/wordlists/wordlists-extra.d.ts new file mode 100644 index 00000000..7e15a233 --- /dev/null +++ b/lib.esm/wordlists/wordlists-extra.d.ts @@ -0,0 +1,9 @@ +export { LangCz } from "./lang-cz.js"; +export { LangEs } from "./lang-es.js"; +export { LangFr } from "./lang-fr.js"; +export { LangJa } from "./lang-ja.js"; +export { LangKo } from "./lang-ko.js"; +export { LangIt } from "./lang-it.js"; +export { LangPt } from "./lang-pt.js"; +export { LangZh } from "./lang-zh.js"; +//# sourceMappingURL=wordlists-extra.d.ts.map \ No newline at end of file diff --git a/lib.esm/wordlists/wordlists-extra.d.ts.map b/lib.esm/wordlists/wordlists-extra.d.ts.map new file mode 100644 index 00000000..6003081c --- /dev/null +++ b/lib.esm/wordlists/wordlists-extra.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"wordlists-extra.d.ts","sourceRoot":"","sources":["../../src.ts/wordlists/wordlists-extra.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC"} \ No newline at end of file diff --git a/lib.esm/wordlists/wordlists-extra.js b/lib.esm/wordlists/wordlists-extra.js new file mode 100644 index 00000000..47e509eb --- /dev/null +++ b/lib.esm/wordlists/wordlists-extra.js @@ -0,0 +1,9 @@ +export { LangCz } from "./lang-cz.js"; +export { LangEs } from "./lang-es.js"; +export { LangFr } from "./lang-fr.js"; +export { LangJa } from "./lang-ja.js"; +export { LangKo } from "./lang-ko.js"; +export { LangIt } from "./lang-it.js"; +export { LangPt } from "./lang-pt.js"; +export { LangZh } from "./lang-zh.js"; +//# sourceMappingURL=wordlists-extra.js.map \ No newline at end of file diff --git a/lib.esm/wordlists/wordlists-extra.js.map b/lib.esm/wordlists/wordlists-extra.js.map new file mode 100644 index 00000000..9d9e4e52 --- /dev/null +++ b/lib.esm/wordlists/wordlists-extra.js.map @@ -0,0 +1 @@ +{"version":3,"file":"wordlists-extra.js","sourceRoot":"","sources":["../../src.ts/wordlists/wordlists-extra.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC"} \ No newline at end of file diff --git a/lib.esm/wordlists/wordlists.d.ts b/lib.esm/wordlists/wordlists.d.ts new file mode 100644 index 00000000..ab8b0308 --- /dev/null +++ b/lib.esm/wordlists/wordlists.d.ts @@ -0,0 +1,16 @@ +import type { Wordlist } from "./wordlist.js"; +/** + * The available Wordlists by their + * [ISO 639-1 Language Code](link-wiki-iso639). + * + * (**i.e.** [cz](LangCz), [en](LangEn), [es](LangEs), [fr](LangFr), + * [ja](LangJa), [ko](LangKo), [it](LangIt), [pt](LangPt), + * [zh_cn](LangZh), [zh_tw](LangZh)) + * + * The dist files (in the ``/dist`` folder) have had all languages + * except English stripped out, which reduces the library size by + * about 80kb. If required, they are available by importing the + * included ``wordlists-extra.min.js`` file. + */ +export declare const wordlists: Record; +//# sourceMappingURL=wordlists.d.ts.map \ No newline at end of file diff --git a/lib.esm/wordlists/wordlists.d.ts.map b/lib.esm/wordlists/wordlists.d.ts.map new file mode 100644 index 00000000..6e459b7c --- /dev/null +++ b/lib.esm/wordlists/wordlists.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"wordlists.d.ts","sourceRoot":"","sources":["../../src.ts/wordlists/wordlists.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAW9C,CAAC"} \ No newline at end of file diff --git a/lib.esm/wordlists/wordlists.js b/lib.esm/wordlists/wordlists.js new file mode 100644 index 00000000..45fd2d71 --- /dev/null +++ b/lib.esm/wordlists/wordlists.js @@ -0,0 +1,35 @@ +import { LangCz } from "./lang-cz.js"; +import { LangEn } from "./lang-en.js"; +import { LangEs } from "./lang-es.js"; +import { LangFr } from "./lang-fr.js"; +import { LangJa } from "./lang-ja.js"; +import { LangKo } from "./lang-ko.js"; +import { LangIt } from "./lang-it.js"; +import { LangPt } from "./lang-pt.js"; +import { LangZh } from "./lang-zh.js"; +/** + * The available Wordlists by their + * [ISO 639-1 Language Code](link-wiki-iso639). + * + * (**i.e.** [cz](LangCz), [en](LangEn), [es](LangEs), [fr](LangFr), + * [ja](LangJa), [ko](LangKo), [it](LangIt), [pt](LangPt), + * [zh_cn](LangZh), [zh_tw](LangZh)) + * + * The dist files (in the ``/dist`` folder) have had all languages + * except English stripped out, which reduces the library size by + * about 80kb. If required, they are available by importing the + * included ``wordlists-extra.min.js`` file. + */ +export const wordlists = { + cz: LangCz.wordlist(), + en: LangEn.wordlist(), + es: LangEs.wordlist(), + fr: LangFr.wordlist(), + it: LangIt.wordlist(), + pt: LangPt.wordlist(), + ja: LangJa.wordlist(), + ko: LangKo.wordlist(), + zh_cn: LangZh.wordlist("cn"), + zh_tw: LangZh.wordlist("tw"), +}; +//# sourceMappingURL=wordlists.js.map \ No newline at end of file diff --git a/lib.esm/wordlists/wordlists.js.map b/lib.esm/wordlists/wordlists.js.map new file mode 100644 index 00000000..bc54711c --- /dev/null +++ b/lib.esm/wordlists/wordlists.js.map @@ -0,0 +1 @@ +{"version":3,"file":"wordlists.js","sourceRoot":"","sources":["../../src.ts/wordlists/wordlists.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAItC;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,SAAS,GAA6B;IACjD,EAAE,EAAE,MAAM,CAAC,QAAQ,EAAE;IACrB,EAAE,EAAE,MAAM,CAAC,QAAQ,EAAE;IACrB,EAAE,EAAE,MAAM,CAAC,QAAQ,EAAE;IACrB,EAAE,EAAE,MAAM,CAAC,QAAQ,EAAE;IACrB,EAAE,EAAE,MAAM,CAAC,QAAQ,EAAE;IACrB,EAAE,EAAE,MAAM,CAAC,QAAQ,EAAE;IACrB,EAAE,EAAE,MAAM,CAAC,QAAQ,EAAE;IACrB,EAAE,EAAE,MAAM,CAAC,QAAQ,EAAE;IACrB,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;IAC5B,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;CAC7B,CAAC"} \ No newline at end of file diff --git a/src.ts/address/contract-address.ts b/src.ts/address/contract-address.ts index 6d8aebe2..eec0ea6b 100644 --- a/src.ts/address/contract-address.ts +++ b/src.ts/address/contract-address.ts @@ -1,6 +1,6 @@ import { keccak256 } from "../crypto/index.js"; import { - concat, dataSlice, getBigInt, getBytes, encodeRlp, assertArgument + concat, dataSlice, getBigInt, getBytes, assertArgument, encodeProto } from "../utils/index.js"; import { getAddress } from "./address.js"; @@ -41,7 +41,7 @@ export function getCreateAddress(tx: { from: string, nonce: BigNumberish }): str nonceHex = "0x" + nonceHex; } - return getAddress(dataSlice(keccak256(encodeRlp([ from, nonceHex ])), 12)); + return getAddress(dataSlice(keccak256(encodeProto([ from, nonceHex ])), 12)); } /** diff --git a/src.ts/quais.ts b/src.ts/quais.ts index ac1a0853..7fa0df93 100644 --- a/src.ts/quais.ts +++ b/src.ts/quais.ts @@ -104,7 +104,6 @@ export { formatQuai, parseQuai, formatEther, parseEther, formatUnits, parseUnits, toUtf8Bytes, toUtf8CodePoints, toUtf8String, Utf8ErrorFuncs, - decodeRlp, encodeRlp, uuidV4, getTxType, getShardForAddress, getAddressDetails, isUTXOAddress, } from "./utils/index.js"; @@ -181,7 +180,6 @@ export type { ErrorCode, FixedFormat, Utf8ErrorFunc, UnicodeNormalizationForm, Utf8ErrorReason, - RlpStructuredData, RlpStructuredDataish, GetUrlResponse, FetchPreflightFunc, FetchProcessFunc, FetchRetryFunc, diff --git a/src.ts/utils/index.ts b/src.ts/utils/index.ts index 95f095f6..891b7c25 100644 --- a/src.ts/utils/index.ts +++ b/src.ts/utils/index.ts @@ -35,8 +35,6 @@ export { export { resolveProperties, defineProperties } from "./properties.js"; -export { decodeRlp } from "./rlp-decode.js"; -export { encodeRlp } from "./rlp-encode.js"; export { encodeProto } from "./proto-encode.js"; export { decodeProto } from "./proto-decode.js"; @@ -90,8 +88,6 @@ export type { FixedFormat } from "./fixednumber.js" export type { BigNumberish, Numeric } from "./maths.js"; -export type { RlpStructuredData, RlpStructuredDataish } from "./rlp.js"; - export type { Utf8ErrorFunc, UnicodeNormalizationForm,