diff --git a/packages/siwe-parser/lib/abnf.ts b/packages/siwe-parser/lib/abnf.ts index f9295cc7..b1db5dc2 100644 --- a/packages/siwe-parser/lib/abnf.ts +++ b/packages/siwe-parser/lib/abnf.ts @@ -1,8 +1,6 @@ import { grammar } from "./siwe-grammar"; import { cb } from "./callbacks"; import apgLib from "apg-js/src/apg-lib/node-exports"; -// import * as fs from "node:fs"; -// import { cwd } from "node:process"; const grammarObj = new grammar(); export class ParsedMessage { @@ -30,7 +28,6 @@ export class ParsedMessage { }; // and display it on an HTML page. - // constructor(msg: string, doTrace = false) { constructor(msg: string) { const parser = new apgLib.parser(); parser.callbacks["sign-in-with-ethereum"] = cb.signInWithEtherium; @@ -102,25 +99,8 @@ export class ParsedMessage { fragment: undefined, }, }; - // if (doTrace === true) { - // parser.trace = new apgLib.trace(); - // parser.trace.filter.operators[""] = true; - // } + const result = parser.parse(grammarObj, 0, msg, elements); - // if (doTrace === true) { - // const html = parser.trace.toHtmlPage("ascii", "siwe-parser trace"); - // const dir = `${cwd()}/output`; - // const name = `${dir}/siwe-parser-trace.html`; - // try { - // fs.mkdirSync(dir); - // } catch (e) { - // if (e.code !== "EEXIST") { - // throw new Error(`fs.mkdir failed: ${e.message}`); - // } - // } - // fs.writeFileSync(name, html); - // console.log(`view "${name}" in any browser to display parser's trace`); - // } let throwMsg = ""; for (let i = 0; i < elements.errors.length; i += 1) { throwMsg += elements.errors[i] + "\n"; @@ -149,7 +129,6 @@ export class ParsedMessage { } } -// export const isUri = (uri: string, doTrace = false) => { export const isUri = (uri: string) => { const parser = new apgLib.parser(); parser.callbacks["IP-literal"] = cb.ipLiteral; @@ -162,25 +141,9 @@ export const isUri = (uri: string) => { parser.callbacks["h16cn"] = cb.h16; parser.callbacks["dec-octet"] = cb.decOctet; parser.callbacks["dec-digit"] = cb.decDigit; - // if (doTrace === true) { - // parser.trace = new apgLib.trace(); - // parser.trace.filter.operators[""] = true; - // } + const data = { errors: [] }; const result = parser.parse(grammarObj, "uri-r", uri, data); - // if (doTrace === true) { - // const html = parser.trace.toHtmlPage("ascii", "isUri trace"); - // const dir = `${cwd()}/output`; - // const name = `${dir}/isUri-trace.html`; - // try { - // fs.mkdirSync(dir); - // } catch (e) { - // if (e.code !== "EEXIST") { - // throw new Error(`fs.mkdir failed: ${e.message}`); - // } - // } - // fs.writeFileSync(name, html); - // console.log(`view "${name}" in any browser to display parser's trace`); - // } + return result.success; };