@metamask-previews/snap-networks-utils 1.0.0-preview-8ff90d2f → 1.0.0-preview-e00d5bb
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/dist/index.cjs +19 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -10
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +13 -10
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +9 -7
- package/dist/index.mjs.map +1 -1
- package/dist/utils/async/async.cjs +95 -0
- package/dist/utils/async/async.cjs.map +1 -0
- package/dist/utils/async/async.d.cts +51 -0
- package/dist/utils/async/async.d.cts.map +1 -0
- package/dist/utils/async/async.d.mts +51 -0
- package/dist/utils/async/async.d.mts.map +1 -0
- package/dist/utils/async/async.mjs +88 -0
- package/dist/utils/async/async.mjs.map +1 -0
- package/dist/{buildUrl → utils/buildUrl}/buildUrl.cjs +1 -1
- package/dist/utils/buildUrl/buildUrl.cjs.map +1 -0
- package/dist/utils/buildUrl/buildUrl.d.cts.map +1 -0
- package/dist/utils/buildUrl/buildUrl.d.mts.map +1 -0
- package/dist/{buildUrl → utils/buildUrl}/buildUrl.mjs +1 -1
- package/dist/utils/buildUrl/buildUrl.mjs.map +1 -0
- package/dist/utils/dedupe/InFlightCoalescer.cjs.map +1 -0
- package/dist/utils/dedupe/InFlightCoalescer.d.cts.map +1 -0
- package/dist/utils/dedupe/InFlightCoalescer.d.mts.map +1 -0
- package/dist/utils/dedupe/InFlightCoalescer.mjs.map +1 -0
- package/dist/utils/logger/Logger.cjs.map +1 -0
- package/dist/utils/logger/Logger.d.cts.map +1 -0
- package/dist/utils/logger/Logger.d.mts.map +1 -0
- package/dist/utils/logger/Logger.mjs.map +1 -0
- package/dist/utils/originPermissions/createOriginPermissions.cjs.map +1 -0
- package/dist/utils/originPermissions/createOriginPermissions.d.cts.map +1 -0
- package/dist/utils/originPermissions/createOriginPermissions.d.mts.map +1 -0
- package/dist/utils/originPermissions/createOriginPermissions.mjs.map +1 -0
- package/dist/utils/originPermissions/validateOrigin.cjs.map +1 -0
- package/dist/utils/originPermissions/validateOrigin.d.cts.map +1 -0
- package/dist/utils/originPermissions/validateOrigin.d.mts.map +1 -0
- package/dist/utils/originPermissions/validateOrigin.mjs.map +1 -0
- package/dist/utils/safeMerge/safeMerge.cjs.map +1 -0
- package/dist/utils/safeMerge/safeMerge.d.cts.map +1 -0
- package/dist/utils/safeMerge/safeMerge.d.mts.map +1 -0
- package/dist/utils/safeMerge/safeMerge.mjs.map +1 -0
- package/dist/utils/sanitize/sanitize.cjs.map +1 -0
- package/dist/utils/sanitize/sanitize.d.cts.map +1 -0
- package/dist/utils/sanitize/sanitize.d.mts.map +1 -0
- package/dist/utils/sanitize/sanitize.mjs.map +1 -0
- package/dist/utils/serialization/serialization.cjs +73 -0
- package/dist/utils/serialization/serialization.cjs.map +1 -0
- package/dist/utils/serialization/serialization.d.cts +19 -0
- package/dist/utils/serialization/serialization.d.cts.map +1 -0
- package/dist/utils/serialization/serialization.d.mts +19 -0
- package/dist/utils/serialization/serialization.d.mts.map +1 -0
- package/dist/utils/serialization/serialization.mjs +69 -0
- package/dist/utils/serialization/serialization.mjs.map +1 -0
- package/dist/utils/serialization/types.cjs +3 -0
- package/dist/utils/serialization/types.cjs.map +1 -0
- package/dist/utils/serialization/types.d.cts +8 -0
- package/dist/utils/serialization/types.d.cts.map +1 -0
- package/dist/utils/serialization/types.d.mts +8 -0
- package/dist/utils/serialization/types.d.mts.map +1 -0
- package/dist/utils/serialization/types.mjs +2 -0
- package/dist/utils/serialization/types.mjs.map +1 -0
- package/dist/utils/urlStruct/urlStruct.cjs.map +1 -0
- package/dist/utils/urlStruct/urlStruct.d.cts.map +1 -0
- package/dist/utils/urlStruct/urlStruct.d.mts.map +1 -0
- package/dist/utils/urlStruct/urlStruct.mjs.map +1 -0
- package/package.json +13 -10
- package/dist/buildUrl/buildUrl.cjs.map +0 -1
- package/dist/buildUrl/buildUrl.d.cts.map +0 -1
- package/dist/buildUrl/buildUrl.d.mts.map +0 -1
- package/dist/buildUrl/buildUrl.mjs.map +0 -1
- package/dist/dedupe/InFlightCoalescer.cjs.map +0 -1
- package/dist/dedupe/InFlightCoalescer.d.cts.map +0 -1
- package/dist/dedupe/InFlightCoalescer.d.mts.map +0 -1
- package/dist/dedupe/InFlightCoalescer.mjs.map +0 -1
- package/dist/dedupe/index.cjs +0 -6
- package/dist/dedupe/index.cjs.map +0 -1
- package/dist/dedupe/index.d.cts +0 -2
- package/dist/dedupe/index.d.cts.map +0 -1
- package/dist/dedupe/index.d.mts +0 -2
- package/dist/dedupe/index.d.mts.map +0 -1
- package/dist/dedupe/index.mjs +0 -2
- package/dist/dedupe/index.mjs.map +0 -1
- package/dist/logger/Logger.cjs.map +0 -1
- package/dist/logger/Logger.d.cts.map +0 -1
- package/dist/logger/Logger.d.mts.map +0 -1
- package/dist/logger/Logger.mjs.map +0 -1
- package/dist/logger/index.cjs +0 -7
- package/dist/logger/index.cjs.map +0 -1
- package/dist/logger/index.d.cts +0 -3
- package/dist/logger/index.d.cts.map +0 -1
- package/dist/logger/index.d.mts +0 -3
- package/dist/logger/index.d.mts.map +0 -1
- package/dist/logger/index.mjs +0 -2
- package/dist/logger/index.mjs.map +0 -1
- package/dist/originPermissions/createOriginPermissions.cjs.map +0 -1
- package/dist/originPermissions/createOriginPermissions.d.cts.map +0 -1
- package/dist/originPermissions/createOriginPermissions.d.mts.map +0 -1
- package/dist/originPermissions/createOriginPermissions.mjs.map +0 -1
- package/dist/originPermissions/validateOrigin.cjs.map +0 -1
- package/dist/originPermissions/validateOrigin.d.cts.map +0 -1
- package/dist/originPermissions/validateOrigin.d.mts.map +0 -1
- package/dist/originPermissions/validateOrigin.mjs.map +0 -1
- package/dist/safeMerge/safeMerge.cjs.map +0 -1
- package/dist/safeMerge/safeMerge.d.cts.map +0 -1
- package/dist/safeMerge/safeMerge.d.mts.map +0 -1
- package/dist/safeMerge/safeMerge.mjs.map +0 -1
- package/dist/sanitize.cjs.map +0 -1
- package/dist/sanitize.d.cts.map +0 -1
- package/dist/sanitize.d.mts.map +0 -1
- package/dist/sanitize.mjs.map +0 -1
- package/dist/urlStruct/urlStruct.cjs.map +0 -1
- package/dist/urlStruct/urlStruct.d.cts.map +0 -1
- package/dist/urlStruct/urlStruct.d.mts.map +0 -1
- package/dist/urlStruct/urlStruct.mjs.map +0 -1
- /package/dist/{buildUrl → utils/buildUrl}/buildUrl.d.cts +0 -0
- /package/dist/{buildUrl → utils/buildUrl}/buildUrl.d.mts +0 -0
- /package/dist/{dedupe → utils/dedupe}/InFlightCoalescer.cjs +0 -0
- /package/dist/{dedupe → utils/dedupe}/InFlightCoalescer.d.cts +0 -0
- /package/dist/{dedupe → utils/dedupe}/InFlightCoalescer.d.mts +0 -0
- /package/dist/{dedupe → utils/dedupe}/InFlightCoalescer.mjs +0 -0
- /package/dist/{logger → utils/logger}/Logger.cjs +0 -0
- /package/dist/{logger → utils/logger}/Logger.d.cts +0 -0
- /package/dist/{logger → utils/logger}/Logger.d.mts +0 -0
- /package/dist/{logger → utils/logger}/Logger.mjs +0 -0
- /package/dist/{originPermissions → utils/originPermissions}/createOriginPermissions.cjs +0 -0
- /package/dist/{originPermissions → utils/originPermissions}/createOriginPermissions.d.cts +0 -0
- /package/dist/{originPermissions → utils/originPermissions}/createOriginPermissions.d.mts +0 -0
- /package/dist/{originPermissions → utils/originPermissions}/createOriginPermissions.mjs +0 -0
- /package/dist/{originPermissions → utils/originPermissions}/validateOrigin.cjs +0 -0
- /package/dist/{originPermissions → utils/originPermissions}/validateOrigin.d.cts +0 -0
- /package/dist/{originPermissions → utils/originPermissions}/validateOrigin.d.mts +0 -0
- /package/dist/{originPermissions → utils/originPermissions}/validateOrigin.mjs +0 -0
- /package/dist/{safeMerge → utils/safeMerge}/safeMerge.cjs +0 -0
- /package/dist/{safeMerge → utils/safeMerge}/safeMerge.d.cts +0 -0
- /package/dist/{safeMerge → utils/safeMerge}/safeMerge.d.mts +0 -0
- /package/dist/{safeMerge → utils/safeMerge}/safeMerge.mjs +0 -0
- /package/dist/{sanitize.cjs → utils/sanitize/sanitize.cjs} +0 -0
- /package/dist/{sanitize.d.cts → utils/sanitize/sanitize.d.cts} +0 -0
- /package/dist/{sanitize.d.mts → utils/sanitize/sanitize.d.mts} +0 -0
- /package/dist/{sanitize.mjs → utils/sanitize/sanitize.mjs} +0 -0
- /package/dist/{urlStruct → utils/urlStruct}/urlStruct.cjs +0 -0
- /package/dist/{urlStruct → utils/urlStruct}/urlStruct.d.cts +0 -0
- /package/dist/{urlStruct → utils/urlStruct}/urlStruct.d.mts +0 -0
- /package/dist/{urlStruct → utils/urlStruct}/urlStruct.mjs +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Logger.cjs","sourceRoot":"","sources":["../../../src/utils/logger/Logger.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uDAAsD;AAEtD;;GAEG;AACU,QAAA,QAAQ,GAAG;IACtB,MAAM,EAAE,QAAQ;IAChB,KAAK,EAAE,OAAO;IACd,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,OAAO;IACd,KAAK,EAAE,OAAO;CACN,CAAC;AAIX;;;;;;GAMG;AACH,MAAM,gBAAgB,GAAG;IACvB,CAAC,gBAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;IACpB,CAAC,gBAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;IACnB,CAAC,gBAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;IAClB,CAAC,gBAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;IAClB,CAAC,gBAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;IACnB,CAAC,gBAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;CACpB,CAAC;AAEF,MAAM,cAAc,GAAG,IAAA,mBAAK,EAAC,MAAM,CAAC,MAAM,CA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IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACjD,CAAC;IAED,KAAK,CAAC,GAAG,IAAe;QACtB,uBAAA,IAAI,wCAAO,MAAX,IAAI,EAAQ,gBAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACnD,CAAC;IAED,KAAK,CAAC,GAAG,IAAe;QACtB,uBAAA,IAAI,wCAAO,MAAX,IAAI,EAAQ,gBAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACnD,CAAC;CA6BF;AA1FD,wBA0FC;iMA3BkB,KAAmB;IAClC,OAAO,gBAAgB,CAAC,KAAK,CAAC,GAAG,gBAAgB,CAAC,uBAAA,IAAI,qBAAO,CAAC,CAAC;AACjE,CAAC,yCAGC,KAAmB,EACnB,cAA4C,EAC5C,IAAe;IAEf,IAAI,uBAAA,IAAI,kDAAiB,MAArB,IAAI,EAAkB,KAAK,CAAC,EAAE,CAAC;QACjC,OAAO;IACT,CAAC;IAED,MAAM,IAAI,GAAc,uBAAA,IAAI,sBAAQ;QAClC,CAAC,CAAC,CAAC,GAAG,QAAmB,EAAQ,EAAE,CAC/B,cAAc,CAAC,uBAAA,IAAI,sBAAQ,EAAE,GAAG,QAAQ,CAAC;QAC7C,CAAC,CAAC,cAAc,CAAC;IAEnB,MAAM,SAAS,GAAG,uBAAA,IAAI,0BAAY,EAAE,CAAC,KAAK,CAAC,CAAC;IAE5C,IAAI,SAAS,EAAE,CAAC;QACd,SAAS,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;QACzB,OAAO;IACT,CAAC;IAED,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;AAChB,CAAC","sourcesContent":["import { assert, enums } from '@metamask/superstruct';\n\n/**\n * The severity levels supported by {@link Logger}.\n */\nexport const LogLevel = {\n SILENT: 'silent',\n ERROR: 'error',\n WARN: 'warn',\n INFO: 'info',\n DEBUG: 'debug',\n TRACE: 'trace',\n} as const;\n\nexport type LogLevel = (typeof LogLevel)[keyof typeof LogLevel];\n\n/**\n * Defines the severity ordering used to filter log messages.\n *\n * Lower values are less verbose. Changing these numeric priorities changes\n * which messages are emitted for each configured {@link LogLevel}, including\n * in production.\n */\nconst logLevelPriority = {\n [LogLevel.SILENT]: 0,\n [LogLevel.ERROR]: 1,\n [LogLevel.WARN]: 2,\n [LogLevel.INFO]: 3,\n [LogLevel.DEBUG]: 4,\n [LogLevel.TRACE]: 5,\n};\n\nconst LogLevelStruct = enums(Object.values(LogLevel));\n\nexport type LoggerMethod = Exclude<LogLevel, typeof LogLevel.SILENT>;\n\nexport type LogMethod = (...args: unknown[]) => void;\n\n/**\n * A function that can add behavior around a logger method.\n *\n * Call `next` to forward a message through the logger's configured output.\n */\nexport type LogMethodDecorator = (next: LogMethod, ...args: unknown[]) => void;\n\nexport type LoggerDecorators = Partial<\n Record<LoggerMethod, LogMethodDecorator>\n>;\n\n/**\n * Configuration for a {@link Logger}.\n *\n * **Example: configure logging with `LOG_LEVEL`.**\n *\n * ```ts\n * const logger = new Logger({\n * level: process.env.LOG_LEVEL\n * });\n * ```\n */\nexport type LoggerOptions = {\n /**\n * The most verbose severity level that should be logged. Use\n * {@link LogLevel.SILENT} to disable logging.\n */\n level: LogLevel;\n /**\n * An optional prefix prepended to every message.\n *\n * Use {@link Logger.withPrefix} to add prefixes after construction.\n */\n prefix?: string;\n /**\n * Optional behavior to apply to individual log methods.\n *\n * Decorators receive `next`, which preserves this logger's configured level,\n * prefix, and console output.\n */\n decorators?: LoggerDecorators;\n};\n\n/**\n * Logs network Snap messages to the console at configurable severity levels.\n *\n * Disable output with {@link LogLevel.SILENT}.\n *\n * **Example: create an enabled logger.**\n *\n * ```ts\n * import { Logger } from '@metamask/snap-networks-utils';\n *\n * const logger = new Logger({ level: LogLevel.TRACE });\n * logger.info('Account synced');\n * ```\n *\n * **Example: add a Snap or component prefix.**\n *\n * ```ts\n * const rootLogger = new Logger({ level: LogLevel.TRACE });\n * const snapLogger = rootLogger.withPrefix('[tron-wallet-snap]');\n * const accountsLogger = snapLogger.withPrefix('[accounts]');\n *\n * accountsLogger.debug('Refreshing account balances');\n * ```\n *\n * **Example: decorate a method with Snap-specific behavior.**\n *\n * ```ts\n * const logger = new Logger({\n * level: LogLevel.TRACE,\n * decorators: {\n * error: (next, error) => {\n * const details = getSolanaErrorDetails(error);\n * next(details ?? error);\n * },\n * },\n * });\n * ```\n */\nexport class Logger {\n readonly #level: LogLevel;\n\n readonly #prefix?: string;\n\n readonly #decorators?: LoggerDecorators;\n\n constructor({ level, prefix, decorators }: LoggerOptions) {\n assert(level, LogLevelStruct);\n\n this.#level = level;\n this.#prefix = prefix;\n this.#decorators = decorators;\n }\n\n /**\n * Returns a logger with an additional prefix.\n *\n * The returned logger has the same log level and decorators as this one. Call\n * this method as many times as needed; each derived logger appends its prefix\n * to the existing prefix.\n *\n * @param prefix - The prefix to add to each message.\n * @returns A derived logger.\n */\n withPrefix(prefix: string): Logger {\n return new Logger({\n level: this.#level,\n prefix: this.#prefix ? `${this.#prefix} ${prefix}` : prefix,\n decorators: this.#decorators,\n });\n }\n\n error(...args: unknown[]): void {\n this.#write(LogLevel.ERROR, console.error, args);\n }\n\n warn(...args: unknown[]): void {\n this.#write(LogLevel.WARN, console.warn, args);\n }\n\n /**\n * Logs an informational message.\n *\n * @param args - The values to write to the console.\n * @deprecated Use {@link Logger.info} instead.\n */\n log(...args: unknown[]): void {\n this.info(...args);\n }\n\n info(...args: unknown[]): void {\n this.#write(LogLevel.INFO, console.info, args);\n }\n\n debug(...args: unknown[]): void {\n this.#write(LogLevel.DEBUG, console.debug, args);\n }\n\n trace(...args: unknown[]): void {\n this.#write(LogLevel.TRACE, console.trace, args);\n }\n\n #isLevelDisabled(level: LoggerMethod): boolean {\n return logLevelPriority[level] > logLevelPriority[this.#level];\n }\n\n #write(\n level: LoggerMethod,\n writeToConsole: (...args: unknown[]) => void,\n args: unknown[],\n ): void {\n if (this.#isLevelDisabled(level)) {\n return;\n }\n\n const next: LogMethod = this.#prefix\n ? (...nextArgs: unknown[]): void =>\n writeToConsole(this.#prefix, ...nextArgs)\n : writeToConsole;\n\n const decorator = this.#decorators?.[level];\n\n if (decorator) {\n decorator(next, ...args);\n return;\n }\n\n next(...args);\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Logger.d.cts","sourceRoot":"","sources":["../../../src/utils/logger/Logger.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,QAAQ;;;;;;;CAOX,CAAC;AAEX,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,QAAQ,CAAC,CAAC,MAAM,OAAO,QAAQ,CAAC,CAAC;AAoBhE,MAAM,MAAM,YAAY,GAAG,OAAO,CAAC,QAAQ,EAAE,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC;AAErE,MAAM,MAAM,SAAS,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;AAErD;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,IAAI,EAAE,SAAS,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;AAE/E,MAAM,MAAM,gBAAgB,GAAG,OAAO,CACpC,MAAM,CAAC,YAAY,EAAE,kBAAkB,CAAC,CACzC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B;;;OAGG;IACH,KAAK,EAAE,QAAQ,CAAC;IAChB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,gBAAgB,CAAC;CAC/B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,qBAAa,MAAM;;gBAOL,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,aAAa;IAQxD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,CAAC,CAAC;QACzB,OAAO;IACT,CAAC;IAED,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;AAChB,CAAC","sourcesContent":["import { assert, enums } from '@metamask/superstruct';\n\n/**\n * The severity levels supported by {@link Logger}.\n */\nexport const LogLevel = {\n SILENT: 'silent',\n ERROR: 'error',\n WARN: 'warn',\n INFO: 'info',\n DEBUG: 'debug',\n TRACE: 'trace',\n} as const;\n\nexport type LogLevel = (typeof LogLevel)[keyof typeof LogLevel];\n\n/**\n * Defines the severity ordering used to filter log messages.\n *\n * Lower values are less verbose. Changing these numeric priorities changes\n * which messages are emitted for each configured {@link LogLevel}, including\n * in production.\n */\nconst logLevelPriority = {\n [LogLevel.SILENT]: 0,\n [LogLevel.ERROR]: 1,\n [LogLevel.WARN]: 2,\n [LogLevel.INFO]: 3,\n [LogLevel.DEBUG]: 4,\n [LogLevel.TRACE]: 5,\n};\n\nconst LogLevelStruct = enums(Object.values(LogLevel));\n\nexport type LoggerMethod = Exclude<LogLevel, typeof LogLevel.SILENT>;\n\nexport type LogMethod = (...args: unknown[]) => void;\n\n/**\n * A function that can add behavior around a logger method.\n *\n * Call `next` to forward a message through the logger's configured output.\n */\nexport type LogMethodDecorator = (next: LogMethod, ...args: unknown[]) => void;\n\nexport type LoggerDecorators = Partial<\n Record<LoggerMethod, LogMethodDecorator>\n>;\n\n/**\n * Configuration for a {@link Logger}.\n *\n * **Example: configure logging with `LOG_LEVEL`.**\n *\n * ```ts\n * const logger = new Logger({\n * level: process.env.LOG_LEVEL\n * });\n * ```\n */\nexport type LoggerOptions = {\n /**\n * The most verbose severity level that should be logged. Use\n * {@link LogLevel.SILENT} to disable logging.\n */\n level: LogLevel;\n /**\n * An optional prefix prepended to every message.\n *\n * Use {@link Logger.withPrefix} to add prefixes after construction.\n */\n prefix?: string;\n /**\n * Optional behavior to apply to individual log methods.\n *\n * Decorators receive `next`, which preserves this logger's configured level,\n * prefix, and console output.\n */\n decorators?: LoggerDecorators;\n};\n\n/**\n * Logs network Snap messages to the console at configurable severity levels.\n *\n * Disable output with {@link LogLevel.SILENT}.\n *\n * **Example: create an enabled logger.**\n *\n * ```ts\n * import { Logger } from '@metamask/snap-networks-utils';\n *\n * const logger = new Logger({ level: LogLevel.TRACE });\n * logger.info('Account synced');\n * ```\n *\n * **Example: add a Snap or component prefix.**\n *\n * ```ts\n * const rootLogger = new Logger({ level: LogLevel.TRACE });\n * const snapLogger = rootLogger.withPrefix('[tron-wallet-snap]');\n * const accountsLogger = snapLogger.withPrefix('[accounts]');\n *\n * accountsLogger.debug('Refreshing account balances');\n * ```\n *\n * **Example: decorate a method with Snap-specific behavior.**\n *\n * ```ts\n * const logger = new Logger({\n * level: LogLevel.TRACE,\n * decorators: {\n * error: (next, error) => {\n * const details = getSolanaErrorDetails(error);\n * next(details ?? error);\n * },\n * },\n * });\n * ```\n */\nexport class Logger {\n readonly #level: LogLevel;\n\n readonly #prefix?: string;\n\n readonly #decorators?: LoggerDecorators;\n\n constructor({ level, prefix, decorators }: LoggerOptions) {\n assert(level, LogLevelStruct);\n\n this.#level = level;\n this.#prefix = prefix;\n this.#decorators = decorators;\n }\n\n /**\n * Returns a logger with an additional prefix.\n *\n * The returned logger has the same log level and decorators as this one. Call\n * this method as many times as needed; each derived logger appends its prefix\n * to the existing prefix.\n *\n * @param prefix - The prefix to add to each message.\n * @returns A derived logger.\n */\n withPrefix(prefix: string): Logger {\n return new Logger({\n level: this.#level,\n prefix: this.#prefix ? `${this.#prefix} ${prefix}` : prefix,\n decorators: this.#decorators,\n });\n }\n\n error(...args: unknown[]): void {\n this.#write(LogLevel.ERROR, console.error, args);\n }\n\n warn(...args: unknown[]): void {\n this.#write(LogLevel.WARN, console.warn, args);\n }\n\n /**\n * Logs an informational message.\n *\n * @param args - The values to write to the console.\n * @deprecated Use {@link Logger.info} instead.\n */\n log(...args: unknown[]): void {\n this.info(...args);\n }\n\n info(...args: unknown[]): void {\n this.#write(LogLevel.INFO, console.info, args);\n }\n\n debug(...args: unknown[]): void {\n this.#write(LogLevel.DEBUG, console.debug, args);\n }\n\n trace(...args: unknown[]): void {\n this.#write(LogLevel.TRACE, console.trace, args);\n }\n\n #isLevelDisabled(level: LoggerMethod): boolean {\n return logLevelPriority[level] > logLevelPriority[this.#level];\n }\n\n #write(\n level: LoggerMethod,\n writeToConsole: (...args: unknown[]) => void,\n args: unknown[],\n ): void {\n if (this.#isLevelDisabled(level)) {\n return;\n }\n\n const next: LogMethod = this.#prefix\n ? (...nextArgs: unknown[]): void =>\n writeToConsole(this.#prefix, ...nextArgs)\n : writeToConsole;\n\n const decorator = this.#decorators?.[level];\n\n if (decorator) {\n decorator(next, ...args);\n return;\n }\n\n next(...args);\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createOriginPermissions.cjs","sourceRoot":"","sources":["../../../src/utils/originPermissions/createOriginPermissions.ts"],"names":[],"mappings":";;;AAAa,QAAA,oBAAoB,GAAG,CAAC,+BAA+B,CAAU,CAAC;AAElE,QAAA,mBAAmB,GAAG,CAAC,uBAAuB,CAAU,CAAC;AAEzD,QAAA,uBAAuB,GAAG,UAAU,CAAC;AASlD;;;;;;;;;;;;GAYG;AACI,MAAM,uBAAuB,GAAG,CAAC,EACtC,WAAW,EACX,eAAe,EACf,OAAO,GAAG,2BAAmB,EAC7B,cAAc,GAAG,+BAAuB,GACV,EAA4B,EAAE;IAC5D,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAuB,CAAC;IACzD,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,WAAW,CAAC,CAAC;IAE7C,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,iBAAiB,CAAC,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IACjD,CAAC;IACD,iBAAiB,CAAC,GAAG,CAAC,cAAc,EAAE,IAAI,GAAG,CAAC,eAAe,CAAC,CAAC,CAAC;IAEhE,OAAO,iBAAiB,CAAC;AAC3B,CAAC,CAAC;AAfW,QAAA,uBAAuB,2BAelC","sourcesContent":["export const DEFAULT_PROD_ORIGINS = ['https://portfolio.metamask.io'] as const;\n\nexport const DEFAULT_DEV_ORIGINS = ['http://localhost:3000'] as const;\n\nexport const DEFAULT_METAMASK_ORIGIN = 'metamask';\n\nexport type CreateOriginPermissionsParams = {\n dappMethods: Iterable<string>;\n metamaskMethods: Iterable<string>;\n origins?: readonly string[];\n metamaskOrigin?: string;\n};\n\n/**\n * Builds the origin-to-method permission map used by network snaps.\n *\n * Those origins receive `dappMethods` as provided (pass an empty list to deny\n * dapp calls). The MetaMask origin always receives `metamaskMethods`.\n *\n * @param params - Origin and method lists for the snap.\n * @param params.dappMethods - Methods allowed for connected dapps.\n * @param params.metamaskMethods - Methods allowed for the MetaMask origin.\n * @param params.origins - Dapp origins to register. Defaults to localhost.\n * @param params.metamaskOrigin - Origin key for MetaMask. Defaults to `metamask`.\n * @returns A map of origin to allowed RPC methods.\n */\nexport const createOriginPermissions = ({\n dappMethods,\n metamaskMethods,\n origins = DEFAULT_DEV_ORIGINS,\n metamaskOrigin = DEFAULT_METAMASK_ORIGIN,\n}: CreateOriginPermissionsParams): Map<string, Set<string>> => {\n const originPermissions = new Map<string, Set<string>>();\n const dappPermissions = new Set(dappMethods);\n\n for (const origin of origins) {\n originPermissions.set(origin, dappPermissions);\n }\n originPermissions.set(metamaskOrigin, new Set(metamaskMethods));\n\n return originPermissions;\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createOriginPermissions.d.cts","sourceRoot":"","sources":["../../../src/utils/originPermissions/createOriginPermissions.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,4CAA6C,CAAC;AAE/E,eAAO,MAAM,mBAAmB,oCAAqC,CAAC;AAEtE,eAAO,MAAM,uBAAuB,aAAa,CAAC;AAElD,MAAM,MAAM,6BAA6B,GAAG;IAC1C,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC9B,eAAe,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAClC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,uBAAuB,GAAI,4DAKrC,6BAA6B,KAAG,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAUzD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createOriginPermissions.d.mts","sourceRoot":"","sources":["../../../src/utils/originPermissions/createOriginPermissions.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,4CAA6C,CAAC;AAE/E,eAAO,MAAM,mBAAmB,oCAAqC,CAAC;AAEtE,eAAO,MAAM,uBAAuB,aAAa,CAAC;AAElD,MAAM,MAAM,6BAA6B,GAAG;IAC1C,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC9B,eAAe,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAClC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,uBAAuB,GAAI,4DAKrC,6BAA6B,KAAG,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAUzD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createOriginPermissions.mjs","sourceRoot":"","sources":["../../../src/utils/originPermissions/createOriginPermissions.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,+BAA+B,CAAU,CAAC;AAE/E,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,uBAAuB,CAAU,CAAC;AAEtE,MAAM,CAAC,MAAM,uBAAuB,GAAG,UAAU,CAAC;AASlD;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,EACtC,WAAW,EACX,eAAe,EACf,OAAO,GAAG,mBAAmB,EAC7B,cAAc,GAAG,uBAAuB,GACV,EAA4B,EAAE;IAC5D,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAuB,CAAC;IACzD,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,WAAW,CAAC,CAAC;IAE7C,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,iBAAiB,CAAC,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IACjD,CAAC;IACD,iBAAiB,CAAC,GAAG,CAAC,cAAc,EAAE,IAAI,GAAG,CAAC,eAAe,CAAC,CAAC,CAAC;IAEhE,OAAO,iBAAiB,CAAC;AAC3B,CAAC,CAAC","sourcesContent":["export const DEFAULT_PROD_ORIGINS = ['https://portfolio.metamask.io'] as const;\n\nexport const DEFAULT_DEV_ORIGINS = ['http://localhost:3000'] as const;\n\nexport const DEFAULT_METAMASK_ORIGIN = 'metamask';\n\nexport type CreateOriginPermissionsParams = {\n dappMethods: Iterable<string>;\n metamaskMethods: Iterable<string>;\n origins?: readonly string[];\n metamaskOrigin?: string;\n};\n\n/**\n * Builds the origin-to-method permission map used by network snaps.\n *\n * Those origins receive `dappMethods` as provided (pass an empty list to deny\n * dapp calls). The MetaMask origin always receives `metamaskMethods`.\n *\n * @param params - Origin and method lists for the snap.\n * @param params.dappMethods - Methods allowed for connected dapps.\n * @param params.metamaskMethods - Methods allowed for the MetaMask origin.\n * @param params.origins - Dapp origins to register. Defaults to localhost.\n * @param params.metamaskOrigin - Origin key for MetaMask. Defaults to `metamask`.\n * @returns A map of origin to allowed RPC methods.\n */\nexport const createOriginPermissions = ({\n dappMethods,\n metamaskMethods,\n origins = DEFAULT_DEV_ORIGINS,\n metamaskOrigin = DEFAULT_METAMASK_ORIGIN,\n}: CreateOriginPermissionsParams): Map<string, Set<string>> => {\n const originPermissions = new Map<string, Set<string>>();\n const dappPermissions = new Set(dappMethods);\n\n for (const origin of origins) {\n originPermissions.set(origin, dappPermissions);\n }\n originPermissions.set(metamaskOrigin, new Set(metamaskMethods));\n\n return originPermissions;\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateOrigin.cjs","sourceRoot":"","sources":["../../../src/utils/originPermissions/validateOrigin.ts"],"names":[],"mappings":";;;AAAA,gHAAgH;AAChH,mDAAwD;AAExD;;;;;;;GAOG;AACI,MAAM,cAAc,GAAG,CAC5B,MAAc,EACd,MAAc,EACd,iBAA2C,EACrC,EAAE;IACR,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,6BAAiB,CAAC,kBAAkB,CAAC,CAAC;IAClD,CAAC;IACD,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;QAChD,MAAM,IAAI,6BAAiB,CAAC,mBAAmB,CAAC,CAAC;IACnD,CAAC;AACH,CAAC,CAAC;AAXW,QAAA,cAAc,kBAWzB","sourcesContent":["/* eslint-disable @typescript-eslint/only-throw-error -- UnauthorizedError is the JSON-RPC snap error surface */\nimport { UnauthorizedError } from '@metamask/snaps-sdk';\n\n/**\n * Validates that the origin is allowed to call the given method.\n *\n * @param origin - The origin of the request.\n * @param method - The RPC method of the request.\n * @param originPermissions - Map of origin to allowed methods.\n * @throws {UnauthorizedError} If the origin is missing or the method is not allowed.\n */\nexport const validateOrigin = (\n origin: string,\n method: string,\n originPermissions: Map<string, Set<string>>,\n): void => {\n if (!origin) {\n throw new UnauthorizedError('Origin not found');\n }\n if (!originPermissions.get(origin)?.has(method)) {\n throw new UnauthorizedError('Permission denied');\n }\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateOrigin.d.cts","sourceRoot":"","sources":["../../../src/utils/originPermissions/validateOrigin.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,GACzB,QAAQ,MAAM,EACd,QAAQ,MAAM,EACd,mBAAmB,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,KAC1C,IAOF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateOrigin.d.mts","sourceRoot":"","sources":["../../../src/utils/originPermissions/validateOrigin.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,GACzB,QAAQ,MAAM,EACd,QAAQ,MAAM,EACd,mBAAmB,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,KAC1C,IAOF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateOrigin.mjs","sourceRoot":"","sources":["../../../src/utils/originPermissions/validateOrigin.ts"],"names":[],"mappings":"AAAA,gHAAgH;AAChH,OAAO,EAAE,iBAAiB,EAAE,4BAA4B;AAExD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,MAAc,EACd,MAAc,EACd,iBAA2C,EACrC,EAAE;IACR,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,iBAAiB,CAAC,kBAAkB,CAAC,CAAC;IAClD,CAAC;IACD,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;QAChD,MAAM,IAAI,iBAAiB,CAAC,mBAAmB,CAAC,CAAC;IACnD,CAAC;AACH,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/only-throw-error -- UnauthorizedError is the JSON-RPC snap error surface */\nimport { UnauthorizedError } from '@metamask/snaps-sdk';\n\n/**\n * Validates that the origin is allowed to call the given method.\n *\n * @param origin - The origin of the request.\n * @param method - The RPC method of the request.\n * @param originPermissions - Map of origin to allowed methods.\n * @throws {UnauthorizedError} If the origin is missing or the method is not allowed.\n */\nexport const validateOrigin = (\n origin: string,\n method: string,\n originPermissions: Map<string, Set<string>>,\n): void => {\n if (!origin) {\n throw new UnauthorizedError('Origin not found');\n }\n if (!originPermissions.get(origin)?.has(method)) {\n throw new UnauthorizedError('Permission denied');\n }\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safeMerge.cjs","sourceRoot":"","sources":["../../../src/utils/safeMerge/safeMerge.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACI,MAAM,SAAS,GAAG,CACvB,SAAqB,EACrB,SAAqB,EACI,EAAE,CAAC,CAAC;IAC7B,GAAG,SAAS;IACZ,GAAI,MAAM,CAAC,WAAW,CACpB,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,MAAM,CAC9B,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAChB,KAAK,KAAK,SAAS;QACnB,KAAK,KAAK,IAAI;QACd,CAAC,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CACzE,CACa;CACjB,CAAC,CAAC;AAbU,QAAA,SAAS,aAanB","sourcesContent":["/**\n * Shallowly merges two objects at the top level, keeping values from the overridee object when the overrider's\n * corresponding top-level properties are undefined, null, or empty objects. Non-undefined values from the overrider\n * take precedence. Empty objects in the overrider are filtered out to preserve the overridee's values. Nested objects\n * are not merged recursively: if a nested property exists in the overrider, it replaces the overridee's value entirely.\n *\n * @param overridee - The object to override.\n * @param overrider - The object to override with.\n * @returns The merged object (using shallow, top-level merge semantics).\n * @example\n * const overridee = { name: 'John' };\n * const overrider = { name: undefined, age: 30 };\n * const merged = safeMerge(overridee, overrider);\n * // merged is { name: 'John', age: 30 }\n */\nexport const safeMerge = <TOverridee extends object, TOverrider extends object>(\n overridee: TOverridee,\n overrider: TOverrider,\n): TOverridee & TOverrider => ({\n ...overridee,\n ...(Object.fromEntries(\n Object.entries(overrider).filter(\n ([_key, value]) =>\n value !== undefined &&\n value !== null &&\n (!value || typeof value !== 'object' || Object.keys(value).length > 0),\n ),\n ) as TOverrider),\n});\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safeMerge.d.cts","sourceRoot":"","sources":["../../../src/utils/safeMerge/safeMerge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,SAAS,GAAI,UAAU,SAAS,MAAM,EAAE,UAAU,SAAS,MAAM,EAC5E,WAAW,UAAU,EACrB,WAAW,UAAU,KACpB,UAAU,GAAG,UAUd,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safeMerge.d.mts","sourceRoot":"","sources":["../../../src/utils/safeMerge/safeMerge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,SAAS,GAAI,UAAU,SAAS,MAAM,EAAE,UAAU,SAAS,MAAM,EAC5E,WAAW,UAAU,EACrB,WAAW,UAAU,KACpB,UAAU,GAAG,UAUd,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safeMerge.mjs","sourceRoot":"","sources":["../../../src/utils/safeMerge/safeMerge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,SAAqB,EACrB,SAAqB,EACI,EAAE,CAAC,CAAC;IAC7B,GAAG,SAAS;IACZ,GAAI,MAAM,CAAC,WAAW,CACpB,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,MAAM,CAC9B,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAChB,KAAK,KAAK,SAAS;QACnB,KAAK,KAAK,IAAI;QACd,CAAC,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CACzE,CACa;CACjB,CAAC,CAAC","sourcesContent":["/**\n * Shallowly merges two objects at the top level, keeping values from the overridee object when the overrider's\n * corresponding top-level properties are undefined, null, or empty objects. Non-undefined values from the overrider\n * take precedence. Empty objects in the overrider are filtered out to preserve the overridee's values. Nested objects\n * are not merged recursively: if a nested property exists in the overrider, it replaces the overridee's value entirely.\n *\n * @param overridee - The object to override.\n * @param overrider - The object to override with.\n * @returns The merged object (using shallow, top-level merge semantics).\n * @example\n * const overridee = { name: 'John' };\n * const overrider = { name: undefined, age: 30 };\n * const merged = safeMerge(overridee, overrider);\n * // merged is { name: 'John', age: 30 }\n */\nexport const safeMerge = <TOverridee extends object, TOverrider extends object>(\n overridee: TOverridee,\n overrider: TOverrider,\n): TOverridee & TOverrider => ({\n ...overridee,\n ...(Object.fromEntries(\n Object.entries(overrider).filter(\n ([_key, value]) =>\n value !== undefined &&\n value !== null &&\n (!value || typeof value !== 'object' || Object.keys(value).length > 0),\n ),\n ) as TOverrider),\n});\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitize.cjs","sourceRoot":"","sources":["../../../src/utils/sanitize/sanitize.ts"],"names":[],"mappings":";;AAMA,8DAQC;AAQD,kCAiBC;AAvCD;;;;;GAKG;AACH,SAAgB,yBAAyB,CAAC,KAAa;IACrD,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACxC,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,4CAA4C;IAC5C,4CAA4C;IAC5C,OAAO,KAAK,CAAC,OAAO,CAAC,sCAAsC,EAAE,EAAE,CAAC,CAAC;AACnE,CAAC;AAED;;;;;GAKG;AACH,SAAgB,WAAW,CAAC,GAAW;IACrC,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QACpC,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,SAAS,GAAG,yBAAyB,CAAC,GAAG,CAAC,CAAC;IAEjD,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC;QAC/B,MAAM,gBAAgB,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QAC9D,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,SAAS,CAAC,MAAM,GAAG,IAAI,EAAE,CAAC;YACxE,OAAO,EAAE,CAAC;QACZ,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC","sourcesContent":["/**\n * Removes control characters from a string.\n *\n * @param input - The string to sanitize.\n * @returns The sanitized string.\n */\nexport function sanitizeControlCharacters(input: string): string {\n if (!input || typeof input !== 'string') {\n return '';\n }\n\n // Remove all control characters except tab.\n // eslint-disable-next-line no-control-regex\n return input.replace(/[\\u0000-\\u0008\\u000A-\\u001F\\u007F]/gu, '');\n}\n\n/**\n * Validates and sanitizes a URI.\n *\n * @param uri - The URI to validate and sanitize.\n * @returns The sanitized URI or an empty string if invalid.\n */\nexport function sanitizeUri(uri: string): string {\n if (!uri || typeof uri !== 'string') {\n return '';\n }\n\n const sanitized = sanitizeControlCharacters(uri);\n\n try {\n const url = new URL(sanitized);\n const allowedProtocols = ['http:', 'https:', 'wss:', 'ipfs:'];\n if (!allowedProtocols.includes(url.protocol) || sanitized.length > 2048) {\n return '';\n }\n return sanitized;\n } catch {\n return '';\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitize.d.cts","sourceRoot":"","sources":["../../../src/utils/sanitize/sanitize.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAQ/D;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAiB/C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitize.d.mts","sourceRoot":"","sources":["../../../src/utils/sanitize/sanitize.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAQ/D;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAiB/C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitize.mjs","sourceRoot":"","sources":["../../../src/utils/sanitize/sanitize.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,yBAAyB,CAAC,KAAa;IACrD,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACxC,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,4CAA4C;IAC5C,4CAA4C;IAC5C,OAAO,KAAK,CAAC,OAAO,CAAC,sCAAsC,EAAE,EAAE,CAAC,CAAC;AACnE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,GAAW;IACrC,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QACpC,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,SAAS,GAAG,yBAAyB,CAAC,GAAG,CAAC,CAAC;IAEjD,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC;QAC/B,MAAM,gBAAgB,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QAC9D,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,SAAS,CAAC,MAAM,GAAG,IAAI,EAAE,CAAC;YACxE,OAAO,EAAE,CAAC;QACZ,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC","sourcesContent":["/**\n * Removes control characters from a string.\n *\n * @param input - The string to sanitize.\n * @returns The sanitized string.\n */\nexport function sanitizeControlCharacters(input: string): string {\n if (!input || typeof input !== 'string') {\n return '';\n }\n\n // Remove all control characters except tab.\n // eslint-disable-next-line no-control-regex\n return input.replace(/[\\u0000-\\u0008\\u000A-\\u001F\\u007F]/gu, '');\n}\n\n/**\n * Validates and sanitizes a URI.\n *\n * @param uri - The URI to validate and sanitize.\n * @returns The sanitized URI or an empty string if invalid.\n */\nexport function sanitizeUri(uri: string): string {\n if (!uri || typeof uri !== 'string') {\n return '';\n }\n\n const sanitized = sanitizeControlCharacters(uri);\n\n try {\n const url = new URL(sanitized);\n const allowedProtocols = ['http:', 'https:', 'wss:', 'ipfs:'];\n if (!allowedProtocols.includes(url.protocol) || sanitized.length > 2048) {\n return '';\n }\n return sanitized;\n } catch {\n return '';\n }\n}\n"]}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deserialize = exports.serialize = void 0;
|
|
4
|
+
const bignumber_js_1 = require("bignumber.js");
|
|
5
|
+
const lodash_1 = require("lodash");
|
|
6
|
+
/**
|
|
7
|
+
* Serializes the passed value to a JSON object so it can be stored in JSON-serializable storage like the snap state and interface context.
|
|
8
|
+
* It transforms non-JSON-serializable values into a specific JSON-serializable representation that can be deserialized later.
|
|
9
|
+
*
|
|
10
|
+
* @param value - The value to serialize.
|
|
11
|
+
* @returns The serialized value.
|
|
12
|
+
*/
|
|
13
|
+
const serialize = (value) => (0, lodash_1.cloneDeepWith)(value, (val) => {
|
|
14
|
+
if (val === undefined) {
|
|
15
|
+
return {
|
|
16
|
+
__type: 'undefined',
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
if (val instanceof bignumber_js_1.BigNumber) {
|
|
20
|
+
return {
|
|
21
|
+
__type: 'BigNumber',
|
|
22
|
+
value: val.toString(),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
if (typeof val === 'bigint') {
|
|
26
|
+
return {
|
|
27
|
+
__type: 'bigint',
|
|
28
|
+
value: val.toString(),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
if (val instanceof Uint8Array) {
|
|
32
|
+
const binaryString = Array.from(val, (byte) => String.fromCharCode(byte)).join('');
|
|
33
|
+
return {
|
|
34
|
+
__type: 'Uint8Array',
|
|
35
|
+
value: btoa(binaryString),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
// Return undefined to let lodash handle the cloning of other values
|
|
39
|
+
return undefined;
|
|
40
|
+
});
|
|
41
|
+
exports.serialize = serialize;
|
|
42
|
+
/**
|
|
43
|
+
* Deserializes the passed value from a JSON object back to its original values.
|
|
44
|
+
* It transforms the JSON-serializable representation of non-JSON-serializable values back into their original values.
|
|
45
|
+
*
|
|
46
|
+
* @param serializedValue - The value to deserialize.
|
|
47
|
+
* @returns The deserialized value.
|
|
48
|
+
*/
|
|
49
|
+
const deserialize = (serializedValue) => JSON.parse(JSON.stringify(serializedValue), (_key, value) => {
|
|
50
|
+
if (!value) {
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
if (value.__type === 'undefined') {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
if (value.__type === 'BigNumber') {
|
|
57
|
+
return new bignumber_js_1.BigNumber(value.value);
|
|
58
|
+
}
|
|
59
|
+
if (value.__type === 'bigint') {
|
|
60
|
+
return BigInt(value.value);
|
|
61
|
+
}
|
|
62
|
+
if (value.__type === 'Uint8Array') {
|
|
63
|
+
const binaryString = atob(value.value);
|
|
64
|
+
const bytes = new Uint8Array(binaryString.length);
|
|
65
|
+
for (let index = 0; index < binaryString.length; index++) {
|
|
66
|
+
bytes[index] = binaryString.charCodeAt(index);
|
|
67
|
+
}
|
|
68
|
+
return bytes;
|
|
69
|
+
}
|
|
70
|
+
return value;
|
|
71
|
+
});
|
|
72
|
+
exports.deserialize = deserialize;
|
|
73
|
+
//# sourceMappingURL=serialization.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialization.cjs","sourceRoot":"","sources":["../../../src/utils/serialization/serialization.ts"],"names":[],"mappings":";;;AACA,+CAAyC;AACzC,mCAAuC;AAIvC;;;;;;GAMG;AACI,MAAM,SAAS,GAAG,CAAC,KAAmB,EAAQ,EAAE,CACrD,IAAA,sBAAa,EAAC,KAAK,EAAE,CAAC,GAAY,EAAE,EAAE;IACpC,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACtB,OAAO;YACL,MAAM,EAAE,WAAW;SACpB,CAAC;IACJ,CAAC;IAED,IAAI,GAAG,YAAY,wBAAS,EAAE,CAAC;QAC7B,OAAO;YACL,MAAM,EAAE,WAAW;YACnB,KAAK,EAAE,GAAG,CAAC,QAAQ,EAAE;SACtB,CAAC;IACJ,CAAC;IAED,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC5B,OAAO;YACL,MAAM,EAAE,QAAQ;YAChB,KAAK,EAAE,GAAG,CAAC,QAAQ,EAAE;SACtB,CAAC;IACJ,CAAC;IAED,IAAI,GAAG,YAAY,UAAU,EAAE,CAAC;QAC9B,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAC5C,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,CAC1B,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACX,OAAO;YACL,MAAM,EAAE,YAAY;YACpB,KAAK,EAAE,IAAI,CAAC,YAAY,CAAC;SAC1B,CAAC;IACJ,CAAC;IAED,oEAAoE;IACpE,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC,CAAC;AAlCQ,QAAA,SAAS,aAkCjB;AAEL;;;;;;GAMG;AACI,MAAM,WAAW,GAAG,CAAC,eAAqB,EAAgB,EAAE,CACjE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;IAC1D,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,KAAK,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;QACjC,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,KAAK,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;QACjC,OAAO,IAAI,wBAAS,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;IAED,IAAI,KAAK,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC7B,CAAC;IAED,IAAI,KAAK,CAAC,MAAM,KAAK,YAAY,EAAE,CAAC;QAClC,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACvC,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QAClD,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,YAAY,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;YACzD,KAAK,CAAC,KAAK,CAAC,GAAG,YAAY,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAChD,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC,CAAC;AA5BQ,QAAA,WAAW,eA4BnB","sourcesContent":["import type { Json } from '@metamask/snaps-sdk';\nimport { BigNumber } from 'bignumber.js';\nimport { cloneDeepWith } from 'lodash';\n\nimport type { Serializable } from './types';\n\n/**\n * Serializes the passed value to a JSON object so it can be stored in JSON-serializable storage like the snap state and interface context.\n * It transforms non-JSON-serializable values into a specific JSON-serializable representation that can be deserialized later.\n *\n * @param value - The value to serialize.\n * @returns The serialized value.\n */\nexport const serialize = (value: Serializable): Json =>\n cloneDeepWith(value, (val: unknown) => {\n if (val === undefined) {\n return {\n __type: 'undefined',\n };\n }\n\n if (val instanceof BigNumber) {\n return {\n __type: 'BigNumber',\n value: val.toString(),\n };\n }\n\n if (typeof val === 'bigint') {\n return {\n __type: 'bigint',\n value: val.toString(),\n };\n }\n\n if (val instanceof Uint8Array) {\n const binaryString = Array.from(val, (byte) =>\n String.fromCharCode(byte),\n ).join('');\n return {\n __type: 'Uint8Array',\n value: btoa(binaryString),\n };\n }\n\n // Return undefined to let lodash handle the cloning of other values\n return undefined;\n });\n\n/**\n * Deserializes the passed value from a JSON object back to its original values.\n * It transforms the JSON-serializable representation of non-JSON-serializable values back into their original values.\n *\n * @param serializedValue - The value to deserialize.\n * @returns The deserialized value.\n */\nexport const deserialize = (serializedValue: Json): Serializable =>\n JSON.parse(JSON.stringify(serializedValue), (_key, value) => {\n if (!value) {\n return value;\n }\n\n if (value.__type === 'undefined') {\n return undefined;\n }\n\n if (value.__type === 'BigNumber') {\n return new BigNumber(value.value);\n }\n\n if (value.__type === 'bigint') {\n return BigInt(value.value);\n }\n\n if (value.__type === 'Uint8Array') {\n const binaryString = atob(value.value);\n const bytes = new Uint8Array(binaryString.length);\n for (let index = 0; index < binaryString.length; index++) {\n bytes[index] = binaryString.charCodeAt(index);\n }\n return bytes;\n }\n\n return value;\n });\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Json } from "@metamask/snaps-sdk";
|
|
2
|
+
import type { Serializable } from "./types.cjs";
|
|
3
|
+
/**
|
|
4
|
+
* Serializes the passed value to a JSON object so it can be stored in JSON-serializable storage like the snap state and interface context.
|
|
5
|
+
* It transforms non-JSON-serializable values into a specific JSON-serializable representation that can be deserialized later.
|
|
6
|
+
*
|
|
7
|
+
* @param value - The value to serialize.
|
|
8
|
+
* @returns The serialized value.
|
|
9
|
+
*/
|
|
10
|
+
export declare const serialize: (value: Serializable) => Json;
|
|
11
|
+
/**
|
|
12
|
+
* Deserializes the passed value from a JSON object back to its original values.
|
|
13
|
+
* It transforms the JSON-serializable representation of non-JSON-serializable values back into their original values.
|
|
14
|
+
*
|
|
15
|
+
* @param serializedValue - The value to deserialize.
|
|
16
|
+
* @returns The deserialized value.
|
|
17
|
+
*/
|
|
18
|
+
export declare const deserialize: (serializedValue: Json) => Serializable;
|
|
19
|
+
//# sourceMappingURL=serialization.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialization.d.cts","sourceRoot":"","sources":["../../../src/utils/serialization/serialization.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,4BAA4B;AAIhD,OAAO,KAAK,EAAE,YAAY,EAAE,oBAAgB;AAE5C;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GAAI,OAAO,YAAY,KAAG,IAkC5C,CAAC;AAEL;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GAAI,iBAAiB,IAAI,KAAG,YA4BhD,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Json } from "@metamask/snaps-sdk";
|
|
2
|
+
import type { Serializable } from "./types.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* Serializes the passed value to a JSON object so it can be stored in JSON-serializable storage like the snap state and interface context.
|
|
5
|
+
* It transforms non-JSON-serializable values into a specific JSON-serializable representation that can be deserialized later.
|
|
6
|
+
*
|
|
7
|
+
* @param value - The value to serialize.
|
|
8
|
+
* @returns The serialized value.
|
|
9
|
+
*/
|
|
10
|
+
export declare const serialize: (value: Serializable) => Json;
|
|
11
|
+
/**
|
|
12
|
+
* Deserializes the passed value from a JSON object back to its original values.
|
|
13
|
+
* It transforms the JSON-serializable representation of non-JSON-serializable values back into their original values.
|
|
14
|
+
*
|
|
15
|
+
* @param serializedValue - The value to deserialize.
|
|
16
|
+
* @returns The deserialized value.
|
|
17
|
+
*/
|
|
18
|
+
export declare const deserialize: (serializedValue: Json) => Serializable;
|
|
19
|
+
//# sourceMappingURL=serialization.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialization.d.mts","sourceRoot":"","sources":["../../../src/utils/serialization/serialization.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,4BAA4B;AAIhD,OAAO,KAAK,EAAE,YAAY,EAAE,oBAAgB;AAE5C;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GAAI,OAAO,YAAY,KAAG,IAkC5C,CAAC;AAEL;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GAAI,iBAAiB,IAAI,KAAG,YA4BhD,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
2
|
+
import $lodash from "lodash";
|
|
3
|
+
const { cloneDeepWith } = $lodash;
|
|
4
|
+
/**
|
|
5
|
+
* Serializes the passed value to a JSON object so it can be stored in JSON-serializable storage like the snap state and interface context.
|
|
6
|
+
* It transforms non-JSON-serializable values into a specific JSON-serializable representation that can be deserialized later.
|
|
7
|
+
*
|
|
8
|
+
* @param value - The value to serialize.
|
|
9
|
+
* @returns The serialized value.
|
|
10
|
+
*/
|
|
11
|
+
export const serialize = (value) => cloneDeepWith(value, (val) => {
|
|
12
|
+
if (val === undefined) {
|
|
13
|
+
return {
|
|
14
|
+
__type: 'undefined',
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
if (val instanceof BigNumber) {
|
|
18
|
+
return {
|
|
19
|
+
__type: 'BigNumber',
|
|
20
|
+
value: val.toString(),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
if (typeof val === 'bigint') {
|
|
24
|
+
return {
|
|
25
|
+
__type: 'bigint',
|
|
26
|
+
value: val.toString(),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
if (val instanceof Uint8Array) {
|
|
30
|
+
const binaryString = Array.from(val, (byte) => String.fromCharCode(byte)).join('');
|
|
31
|
+
return {
|
|
32
|
+
__type: 'Uint8Array',
|
|
33
|
+
value: btoa(binaryString),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
// Return undefined to let lodash handle the cloning of other values
|
|
37
|
+
return undefined;
|
|
38
|
+
});
|
|
39
|
+
/**
|
|
40
|
+
* Deserializes the passed value from a JSON object back to its original values.
|
|
41
|
+
* It transforms the JSON-serializable representation of non-JSON-serializable values back into their original values.
|
|
42
|
+
*
|
|
43
|
+
* @param serializedValue - The value to deserialize.
|
|
44
|
+
* @returns The deserialized value.
|
|
45
|
+
*/
|
|
46
|
+
export const deserialize = (serializedValue) => JSON.parse(JSON.stringify(serializedValue), (_key, value) => {
|
|
47
|
+
if (!value) {
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
50
|
+
if (value.__type === 'undefined') {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
if (value.__type === 'BigNumber') {
|
|
54
|
+
return new BigNumber(value.value);
|
|
55
|
+
}
|
|
56
|
+
if (value.__type === 'bigint') {
|
|
57
|
+
return BigInt(value.value);
|
|
58
|
+
}
|
|
59
|
+
if (value.__type === 'Uint8Array') {
|
|
60
|
+
const binaryString = atob(value.value);
|
|
61
|
+
const bytes = new Uint8Array(binaryString.length);
|
|
62
|
+
for (let index = 0; index < binaryString.length; index++) {
|
|
63
|
+
bytes[index] = binaryString.charCodeAt(index);
|
|
64
|
+
}
|
|
65
|
+
return bytes;
|
|
66
|
+
}
|
|
67
|
+
return value;
|
|
68
|
+
});
|
|
69
|
+
//# sourceMappingURL=serialization.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialization.mjs","sourceRoot":"","sources":["../../../src/utils/serialization/serialization.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EA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C;QACjC,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,KAAK,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;QACjC,OAAO,IAAI,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;IAED,IAAI,KAAK,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC7B,CAAC;IAED,IAAI,KAAK,CAAC,MAAM,KAAK,YAAY,EAAE,CAAC;QAClC,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACvC,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QAClD,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,YAAY,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;YACzD,KAAK,CAAC,KAAK,CAAC,GAAG,YAAY,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAChD,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC,CAAC","sourcesContent":["import type { Json } from '@metamask/snaps-sdk';\nimport { BigNumber } from 'bignumber.js';\nimport { cloneDeepWith } from 'lodash';\n\nimport type { Serializable } from './types';\n\n/**\n * Serializes the passed value to a JSON object so it can be stored in JSON-serializable storage like the snap state and interface context.\n * It transforms non-JSON-serializable values into a specific JSON-serializable representation that can be deserialized later.\n *\n * @param value - The value to serialize.\n * @returns The serialized value.\n */\nexport const serialize = (value: Serializable): Json =>\n cloneDeepWith(value, (val: unknown) => {\n if (val === undefined) {\n return {\n __type: 'undefined',\n };\n }\n\n if (val instanceof BigNumber) {\n return {\n __type: 'BigNumber',\n value: val.toString(),\n };\n }\n\n if (typeof val === 'bigint') {\n return {\n __type: 'bigint',\n value: val.toString(),\n };\n }\n\n if (val instanceof Uint8Array) {\n const binaryString = Array.from(val, (byte) =>\n String.fromCharCode(byte),\n ).join('');\n return {\n __type: 'Uint8Array',\n value: btoa(binaryString),\n };\n }\n\n // Return undefined to let lodash handle the cloning of other values\n return undefined;\n });\n\n/**\n * Deserializes the passed value from a JSON object back to its original values.\n * It transforms the JSON-serializable representation of non-JSON-serializable values back into their original values.\n *\n * @param serializedValue - The value to deserialize.\n * @returns The deserialized value.\n */\nexport const deserialize = (serializedValue: Json): Serializable =>\n JSON.parse(JSON.stringify(serializedValue), (_key, value) => {\n if (!value) {\n return value;\n }\n\n if (value.__type === 'undefined') {\n return undefined;\n }\n\n if (value.__type === 'BigNumber') {\n return new BigNumber(value.value);\n }\n\n if (value.__type === 'bigint') {\n return BigInt(value.value);\n }\n\n if (value.__type === 'Uint8Array') {\n const binaryString = atob(value.value);\n const bytes = new Uint8Array(binaryString.length);\n for (let index = 0; index < binaryString.length; index++) {\n bytes[index] = binaryString.charCodeAt(index);\n }\n return bytes;\n }\n\n return value;\n });\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../../src/utils/serialization/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Json } from '@metamask/snaps-sdk';\nimport type { BigNumber } from 'bignumber.js';\n\n/**\n * A primitive value that can be serialized to JSON using the `serialize` function.\n */\nexport type Serializable =\n | Json\n | undefined\n | null\n | bigint\n | BigNumber\n | Uint8Array\n | Serializable[]\n | {\n [prop: string]: Serializable;\n };\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Json } from "@metamask/snaps-sdk";
|
|
2
|
+
/**
|
|
3
|
+
* A primitive value that can be serialized to JSON using the `serialize` function.
|
|
4
|
+
*/
|
|
5
|
+
export type Serializable = Json | undefined | null | bigint | BigNumber | Uint8Array | Serializable[] | {
|
|
6
|
+
[prop: string]: Serializable;
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=types.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../../../src/utils/serialization/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,4BAA4B;AAGhD;;GAEG;AACH,MAAM,MAAM,YAAY,GACpB,IAAI,GACJ,SAAS,GACT,IAAI,GACJ,MAAM,GACN,SAAS,GACT,UAAU,GACV,YAAY,EAAE,GACd;IACE,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAAC;CAC9B,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Json } from "@metamask/snaps-sdk";
|
|
2
|
+
/**
|
|
3
|
+
* A primitive value that can be serialized to JSON using the `serialize` function.
|
|
4
|
+
*/
|
|
5
|
+
export type Serializable = Json | undefined | null | bigint | BigNumber | Uint8Array | Serializable[] | {
|
|
6
|
+
[prop: string]: Serializable;
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../../../src/utils/serialization/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,4BAA4B;AAGhD;;GAEG;AACH,MAAM,MAAM,YAAY,GACpB,IAAI,GACJ,SAAS,GACT,IAAI,GACJ,MAAM,GACN,SAAS,GACT,UAAU,GACV,YAAY,EAAE,GACd;IACE,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAAC;CAC9B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../../src/utils/serialization/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Json } from '@metamask/snaps-sdk';\nimport type { BigNumber } from 'bignumber.js';\n\n/**\n * A primitive value that can be serialized to JSON using the `serialize` function.\n */\nexport type Serializable =\n | Json\n | undefined\n | null\n | bigint\n | BigNumber\n | Uint8Array\n | Serializable[]\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AAwB,KAAe,CAAC,OAAO,EAAE,CAAC;IAC3D,CAAC;AACH,CAAC,CAAC,CAAC","sourcesContent":["import { refine, string } from '@metamask/superstruct';\n\n/**\n * Validates that a string is a valid and safe URL.\n *\n * It rejects:\n * - Non-HTTP/HTTPS/WSS protocols\n * - Malformed URL format or incorrect protocol format\n * - Invalid hostname format (must follow proper domain naming conventions)\n * - Protocol pollution attempts (backslashes, @ symbol, %2f@, %5c@)\n * - Invalid hostname characters (backslashes, @ symbol, forward slashes, encoded forward slashes)\n * - Directory traversal attempts (../, ..%2f, ..%2F)\n *\n * Dangerous patterns including:\n * - HTML tags.\n * - JavaScript protocol.\n * - Data URI scheme.\n * - Template injection (${...}, #{...}).\n * - Command injection (|, ;).\n * - CRLF injection.\n * - URL credential injection.\n * - SQL injection attempts.\n * - Open redirect parameters.\n * - Non-printable characters.\n */\nexport const UrlStruct = refine(string(), 'safe-url', (value) => {\n try {\n // Basic URL validation\n const url = new URL(value);\n\n // Protocol check\n const supportedProtocols = ['http:', 'https:', 'wss:'];\n if (!supportedProtocols.includes(url.protocol)) {\n return `URL must use one of the following protocols: ${supportedProtocols.join(', ')}`;\n }\n\n // Validate URL format\n if (!value.match(/^(https?|wss):\\/\\/[^/]+\\/?/u)) {\n return 'Malformed URL - incorrect protocol format';\n }\n\n // Validate hostname format. Accepts localhost and ports (needed for tests)\n const hostname = url.hostname.toLowerCase();\n if (\n hostname !== 'localhost' &&\n (!hostname.includes('.') ||\n !/^[a-z0-9]([a-z0-9-]*[a-z0-9])?(\\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$/u.test(\n hostname,\n ))\n ) {\n return 'Invalid hostname format';\n }\n\n // Check for protocol pollution in the entire URL\n const decodedValue = decodeURIComponent(value.toLowerCase());\n if (\n value.includes('\\\\') ||\n value.includes('@') ||\n decodedValue.includes('\\\\') ||\n decodedValue.includes('@') ||\n value.toLowerCase().includes('%2f@') ||\n value.toLowerCase().includes('%5c@')\n ) {\n return 'URL contains protocol pollution attempts';\n }\n\n // Check for directory traversal\n if (\n value.includes('../') ||\n value.includes('..%2f') ||\n value.includes('..%2F')\n ) {\n return 'Directory traversal attempts are not allowed';\n }\n\n // Check for dangerous patterns\n const dangerousPatterns = [\n /<[^>]*>/u, // HTML tags\n /javascript:/u, // JavaScript protocol\n /data:/u, // Data URI scheme\n /\\\\[@\\\\]/u, // Enhanced protocol pollution check\n /%2f@/u, // Protocol pollution\n /[^\\x20-\\x7E]/u, // Non-printable characters\n /\\$\\{.*?\\}/u, // Template injection\n /#\\{.*?\\}/u, // Template injection\n /[|;]/u, // Command injection\n /%0[acd]|%0[acd]/u, // CRLF injection\n /\\/\\/\\w+@/u, // URL credential injection\n // Enhanced SQL injection patterns\n /(?:[^a-z]|^)(?:union\\s+(?:all\\s+)?select|select\\s+(?:.*\\s+)?from|insert\\s+into|update\\s+.*\\s+set|delete\\s+from|drop\\s+table|alter\\s+table|create\\s+table|exec(?:ute)?|union|where\\s+[\\d\\w]\\s*=\\s*[\\d\\w]|\\bor\\b\\s*[\\d\\w]\\s*=\\s*[\\d\\w])/iu,\n /'.*?(?:OR|UNION|SELECT|FROM|WHERE).*?'/iu, // SQL injection\n /%27.*?(?:OR|UNION|SELECT|FROM|WHERE).*?(?:%27|')/iu, // URL-encoded SQL injection\n /%20(?:OR|UNION|SELECT|FROM|WHERE)%20/iu, // URL-encoded SQL keywords\n /[?&](?:url|redirect|next|return_to|return_url|goto|destination|continue|redirect_uri)=(?:[^&]*\\/\\/|https?:)/iu, // Open redirect parameters\n /[?&](?:url|redirect|next|return_to|return_url|goto|destination|continue|redirect_uri)=%(?:[^&]*\\/\\/|https?:)/iu, // URL-encoded open redirect parameters\n ];\n\n for (const patt of dangerousPatterns) {\n if (patt.test(decodedValue)) {\n return 'URL contains potentially malicious patterns';\n }\n }\n\n return true;\n } catch (error) {\n return `Invalid URL format: ${(error as Error).message}`;\n }\n});\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"urlStruct.d.cts","sourceRoot":"","sources":["../../../src/utils/urlStruct/urlStruct.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,SAAS,sDAkFpB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"urlStruct.d.mts","sourceRoot":"","sources":["../../../src/utils/urlStruct/urlStruct.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,SAAS,sDAkFpB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"urlStruct.mjs","sourceRoot":"","sources":["../../../src/utils/urlStruct/urlStruct.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,8BAA8B;AAEvD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,EAAE,UAAU,EAAE,CAAC,KAAK,EAAE,EAAE;IAC9D,IAAI,CAAC;QACH,uBAAuB;QACvB,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;QAE3B,iBAAiB;QACjB,MAAM,kBAAkB,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;QACvD,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC/C,OAAO,gDAAgD,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACzF,CAAC;QAED,sBAAsB;QACtB,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,6BAA6B,CAAC,EAAE,CAAC;YAChD,OAAO,2CAA2C,CAAC;QACrD,CAAC;QAED,2EAA2E;QAC3E,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC;QAC5C,IACE,QAAQ,KA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AA4B;YAClF,wCAAwC,EAAE,2BAA2B;YACrE,+GAA+G,EAAE,2BAA2B;YAC5I,gHAAgH,EAAE,uCAAuC;SAC1J,CAAC;QAEF,KAAK,MAAM,IAAI,IAAI,iBAAiB,EAAE,CAAC;YACrC,IAAI,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC;gBAC5B,OAAO,6CAA6C,CAAC;YACvD,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,uBAAwB,KAAe,CAAC,OAAO,EAAE,CAAC;IAC3D,CAAC;AACH,CAAC,CAAC,CAAC","sourcesContent":["import { refine, string } from '@metamask/superstruct';\n\n/**\n * Validates that a string is a valid and safe URL.\n *\n * It rejects:\n * - Non-HTTP/HTTPS/WSS protocols\n * - Malformed URL format or incorrect protocol format\n * - Invalid hostname format (must follow proper domain naming conventions)\n * - Protocol pollution attempts (backslashes, @ symbol, %2f@, %5c@)\n * - Invalid hostname characters (backslashes, @ symbol, forward slashes, encoded forward slashes)\n * - Directory traversal attempts (../, ..%2f, ..%2F)\n *\n * Dangerous patterns including:\n * - HTML tags.\n * - JavaScript protocol.\n * - Data URI scheme.\n * - Template injection (${...}, #{...}).\n * - Command injection (|, ;).\n * - CRLF injection.\n * - URL credential injection.\n * - SQL injection attempts.\n * - Open redirect parameters.\n * - Non-printable characters.\n */\nexport const UrlStruct = refine(string(), 'safe-url', (value) => {\n try {\n // Basic URL validation\n const url = new URL(value);\n\n // Protocol check\n const supportedProtocols = ['http:', 'https:', 'wss:'];\n if (!supportedProtocols.includes(url.protocol)) {\n return `URL must use one of the following protocols: ${supportedProtocols.join(', ')}`;\n }\n\n // Validate URL format\n if (!value.match(/^(https?|wss):\\/\\/[^/]+\\/?/u)) {\n return 'Malformed URL - incorrect protocol format';\n }\n\n // Validate hostname format. Accepts localhost and ports (needed for tests)\n const hostname = url.hostname.toLowerCase();\n if (\n hostname !== 'localhost' &&\n (!hostname.includes('.') ||\n !/^[a-z0-9]([a-z0-9-]*[a-z0-9])?(\\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$/u.test(\n hostname,\n ))\n ) {\n return 'Invalid hostname format';\n }\n\n // Check for protocol pollution in the entire URL\n const decodedValue = decodeURIComponent(value.toLowerCase());\n if (\n value.includes('\\\\') ||\n value.includes('@') ||\n decodedValue.includes('\\\\') ||\n decodedValue.includes('@') ||\n value.toLowerCase().includes('%2f@') ||\n value.toLowerCase().includes('%5c@')\n ) {\n return 'URL contains protocol pollution attempts';\n }\n\n // Check for directory traversal\n if (\n value.includes('../') ||\n value.includes('..%2f') ||\n value.includes('..%2F')\n ) {\n return 'Directory traversal attempts are not allowed';\n }\n\n // Check for dangerous patterns\n const dangerousPatterns = [\n /<[^>]*>/u, // HTML tags\n /javascript:/u, // JavaScript protocol\n /data:/u, // Data URI scheme\n /\\\\[@\\\\]/u, // Enhanced protocol pollution check\n /%2f@/u, // Protocol pollution\n /[^\\x20-\\x7E]/u, // Non-printable characters\n /\\$\\{.*?\\}/u, // Template injection\n /#\\{.*?\\}/u, // Template injection\n /[|;]/u, // Command injection\n /%0[acd]|%0[acd]/u, // CRLF injection\n /\\/\\/\\w+@/u, // URL credential injection\n // Enhanced SQL injection patterns\n /(?:[^a-z]|^)(?:union\\s+(?:all\\s+)?select|select\\s+(?:.*\\s+)?from|insert\\s+into|update\\s+.*\\s+set|delete\\s+from|drop\\s+table|alter\\s+table|create\\s+table|exec(?:ute)?|union|where\\s+[\\d\\w]\\s*=\\s*[\\d\\w]|\\bor\\b\\s*[\\d\\w]\\s*=\\s*[\\d\\w])/iu,\n /'.*?(?:OR|UNION|SELECT|FROM|WHERE).*?'/iu, // SQL injection\n /%27.*?(?:OR|UNION|SELECT|FROM|WHERE).*?(?:%27|')/iu, // URL-encoded SQL injection\n /%20(?:OR|UNION|SELECT|FROM|WHERE)%20/iu, // URL-encoded SQL keywords\n /[?&](?:url|redirect|next|return_to|return_url|goto|destination|continue|redirect_uri)=(?:[^&]*\\/\\/|https?:)/iu, // Open redirect parameters\n /[?&](?:url|redirect|next|return_to|return_url|goto|destination|continue|redirect_uri)=%(?:[^&]*\\/\\/|https?:)/iu, // URL-encoded open redirect parameters\n ];\n\n for (const patt of dangerousPatterns) {\n if (patt.test(decodedValue)) {\n return 'URL contains potentially malicious patterns';\n }\n }\n\n return true;\n } catch (error) {\n return `Invalid URL format: ${(error as Error).message}`;\n }\n});\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/snap-networks-utils",
|
|
3
|
-
"version": "1.0.0-preview-
|
|
3
|
+
"version": "1.0.0-preview-e00d5bb",
|
|
4
4
|
"description": "Shared utilities for MetaMask network snaps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|
|
@@ -34,22 +34,22 @@
|
|
|
34
34
|
},
|
|
35
35
|
"./dedupe": {
|
|
36
36
|
"import": {
|
|
37
|
-
"types": "./dist/dedupe/
|
|
38
|
-
"default": "./dist/dedupe/
|
|
37
|
+
"types": "./dist/utils/dedupe/InFlightCoalescer.d.mts",
|
|
38
|
+
"default": "./dist/utils/dedupe/InFlightCoalescer.mjs"
|
|
39
39
|
},
|
|
40
40
|
"require": {
|
|
41
|
-
"types": "./dist/dedupe/
|
|
42
|
-
"default": "./dist/dedupe/
|
|
41
|
+
"types": "./dist/utils/dedupe/InFlightCoalescer.d.cts",
|
|
42
|
+
"default": "./dist/utils/dedupe/InFlightCoalescer.cjs"
|
|
43
43
|
}
|
|
44
44
|
},
|
|
45
45
|
"./logger": {
|
|
46
46
|
"import": {
|
|
47
|
-
"types": "./dist/logger/
|
|
48
|
-
"default": "./dist/logger/
|
|
47
|
+
"types": "./dist/utils/logger/Logger.d.mts",
|
|
48
|
+
"default": "./dist/utils/logger/Logger.mjs"
|
|
49
49
|
},
|
|
50
50
|
"require": {
|
|
51
|
-
"types": "./dist/logger/
|
|
52
|
-
"default": "./dist/logger/
|
|
51
|
+
"types": "./dist/utils/logger/Logger.d.cts",
|
|
52
|
+
"default": "./dist/utils/logger/Logger.cjs"
|
|
53
53
|
}
|
|
54
54
|
},
|
|
55
55
|
"./package.json": "./package.json"
|
|
@@ -75,13 +75,16 @@
|
|
|
75
75
|
"@metamask/remote-feature-flag-controller": "^5.0.0",
|
|
76
76
|
"@metamask/snaps-sdk": "^11.2.0",
|
|
77
77
|
"@metamask/superstruct": "^3.4.1",
|
|
78
|
-
"@metamask/utils": "^11.11.0"
|
|
78
|
+
"@metamask/utils": "^11.11.0",
|
|
79
|
+
"bignumber.js": "^9.3.1",
|
|
80
|
+
"lodash": "^4.17.21"
|
|
79
81
|
},
|
|
80
82
|
"devDependencies": {
|
|
81
83
|
"@metamask/auto-changelog": "^6.1.1",
|
|
82
84
|
"@metamask/messenger": "^2.0.0",
|
|
83
85
|
"@ts-bridge/cli": "^0.6.4",
|
|
84
86
|
"@types/jest": "^30.0.0",
|
|
87
|
+
"@types/lodash": "^4.17.15",
|
|
85
88
|
"deepmerge": "^4.2.2",
|
|
86
89
|
"jest": "30.0.3",
|
|
87
90
|
"ts-jest": "^29.4.1",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"buildUrl.cjs","sourceRoot":"","sources":["../../src/buildUrl/buildUrl.ts"],"names":[],"mappings":";;AAmBA,4BAqDC;AAxED,uDAA+C;AAE/C,8CAAqE;AACrE,0DAAmD;AAUnD;;;;;GAKG;AACH,SAAgB,QAAQ,CAAC,MAAsB;IAC7C,MAAM,EACJ,OAAO,EACP,IAAI,EACJ,UAAU,EACV,WAAW,EACX,gBAAgB,GAAG,IAAI,GACxB,GAAG,MAAM,CAAC;IAEX,iCAAiC;IACjC,MAAM,gBAAgB,GAAG,IAAA,sBAAW,EAAC,OAAO,CAAC,CAAC;IAC9C,IAAI,gBAAgB,KAAK,EAAE,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,oBAAoB,C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AAE,EAAE;QACxB,IAAI,KAAK,EAAE,CAAC;YACV,+DAA+D;YAC/D,MAAM,cAAc,GAAG,IAAA,oCAAyB,EAAC,KAAK,CAAC,CAAC;YACxD,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC,CAAC,CAAC;IAEL,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC;IAChC,IAAA,oBAAM,EAAC,QAAQ,EAAE,qBAAS,CAAC,CAAC;IAC5B,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import { assert } from '@metamask/superstruct';\n\nimport { sanitizeControlCharacters, sanitizeUri } from '../sanitize';\nimport { UrlStruct } from '../urlStruct/urlStruct';\n\nexport type BuildUrlParams = {\n baseUrl: string;\n path: string;\n pathParams?: Record<string, string> | undefined;\n queryParams?: Record<string, string> | undefined;\n encodePathParams?: boolean;\n};\n\n/**\n * Builds a safe URL from a base URL, path, and optional parameters.\n *\n * @param params - The parameters to build the URL from.\n * @returns The validated, sanitized URL.\n */\nexport function buildUrl(params: BuildUrlParams): string {\n const {\n baseUrl,\n path,\n pathParams,\n queryParams,\n encodePathParams = true,\n } = params;\n\n // Validate and sanitize base URL\n const sanitizedBaseUrl = sanitizeUri(baseUrl);\n if (sanitizedBaseUrl === '') {\n throw new Error('Invalid URL format');\n }\n assert(sanitizedBaseUrl, UrlStruct);\n\n const pathWithParams = path.replace(/\\{(\\w+)\\}/gu, (_, key: string) => {\n const value = pathParams?.[key];\n if (value === undefined) {\n throw new Error(`Path parameter ${key} is undefined`);\n }\n // Sanitize path parameter values to remove control characters\n const sanitizedValue = sanitizeControlCharacters(value);\n return encodePathParams\n ? encodeURIComponent(sanitizedValue)\n : sanitizedValue;\n });\n\n const cleanPath = pathWithParams\n .replace(/^\\/+/u, '')\n .replace(/\\/+/gu, '/')\n .replace(/\\/+$/u, '');\n\n const normalizedBaseUrl = sanitizedBaseUrl.endsWith('/')\n ? sanitizedBaseUrl\n : `${sanitizedBaseUrl}/`;\n\n const url = new URL(cleanPath, normalizedBaseUrl);\n\n Object.entries(queryParams ?? {})\n .filter(([_, value]) => value !== undefined)\n .filter(([_, value]) => value !== null)\n .forEach(([key, value]) => {\n if (value) {\n // Sanitize query parameter values to remove control characters\n const sanitizedValue = sanitizeControlCharacters(value);\n url.searchParams.append(key, sanitizedValue);\n }\n });\n\n const builtUrl = url.toString();\n assert(builtUrl, UrlStruct);\n return builtUrl;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"buildUrl.d.cts","sourceRoot":"","sources":["../../src/buildUrl/buildUrl.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;IAChD,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;IACjD,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,CAqDvD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"buildUrl.d.mts","sourceRoot":"","sources":["../../src/buildUrl/buildUrl.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;IAChD,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;IACjD,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,CA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,CAAC,OAAO,EAAE,EAAE,CAAC;SACpB,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC;SACrB,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAExB,MAAM,iBAAiB,GAAG,gBAAgB,CAAC,QAAQ,CAAC,GAAG,CAAC;QACtD,CAAC,CAAC,gBAAgB;QAClB,CAAC,CAAC,GAAG,gBAAgB,GAAG,CAAC;IAE3B,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,SAAS,EAAE,iBAAiB,CAAC,CAAC;IAElD,MAAM,CAAC,OAAO,CAAC,WAAW,IAAI,EAAE,CAAC;SAC9B,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC;SAC3C,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC;SACtC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QACxB,IAAI,KAAK,EAAE,CAAC;YACV,+DAA+D;YAC/D,MAAM,cAAc,GAAG,yBAAyB,CAAC,KAAK,CAAC,CAAC;YACxD,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC,CAAC,CAAC;IAEL,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC;IAChC,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IAC5B,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import { assert } from '@metamask/superstruct';\n\nimport { sanitizeControlCharacters, sanitizeUri } from '../sanitize';\nimport { UrlStruct } from '../urlStruct/urlStruct';\n\nexport type BuildUrlParams = {\n baseUrl: string;\n path: string;\n pathParams?: Record<string, string> | undefined;\n queryParams?: Record<string, string> | undefined;\n encodePathParams?: boolean;\n};\n\n/**\n * Builds a safe URL from a base URL, path, and optional parameters.\n *\n * @param params - The parameters to build the URL from.\n * @returns The validated, sanitized URL.\n */\nexport function buildUrl(params: BuildUrlParams): string {\n const {\n baseUrl,\n path,\n pathParams,\n queryParams,\n encodePathParams = true,\n } = params;\n\n // Validate and sanitize base URL\n const sanitizedBaseUrl = sanitizeUri(baseUrl);\n if (sanitizedBaseUrl === '') {\n throw new Error('Invalid URL format');\n }\n assert(sanitizedBaseUrl, UrlStruct);\n\n const pathWithParams = path.replace(/\\{(\\w+)\\}/gu, (_, key: string) => {\n const value = pathParams?.[key];\n if (value === undefined) {\n throw new Error(`Path parameter ${key} is undefined`);\n }\n // Sanitize path parameter values to remove control characters\n const sanitizedValue = sanitizeControlCharacters(value);\n return encodePathParams\n ? encodeURIComponent(sanitizedValue)\n : sanitizedValue;\n });\n\n const cleanPath = pathWithParams\n .replace(/^\\/+/u, '')\n .replace(/\\/+/gu, '/')\n .replace(/\\/+$/u, '');\n\n const normalizedBaseUrl = sanitizedBaseUrl.endsWith('/')\n ? sanitizedBaseUrl\n : `${sanitizedBaseUrl}/`;\n\n const url = new URL(cleanPath, normalizedBaseUrl);\n\n Object.entries(queryParams ?? {})\n .filter(([_, value]) => value !== undefined)\n .filter(([_, value]) => value !== null)\n .forEach(([key, value]) => {\n if (value) {\n // Sanitize query parameter values to remove control characters\n const sanitizedValue = sanitizeControlCharacters(value);\n url.searchParams.append(key, sanitizedValue);\n }\n });\n\n const builtUrl = url.toString();\n assert(builtUrl, UrlStruct);\n return builtUrl;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"InFlightCoalescer.cjs","sourceRoot":"","sources":["../../src/dedupe/InFlightCoalescer.ts"],"names":[],"mappings":";;;;;;;;;AAAA;;;;;;GAMG;AACH,MAAa,iBAAiB;IAA9B;QACW,sCAAY,IAAI,GAAG,EAA4B,EAAC;IAiB3D,CAAC;IAfC,KAAK,CAAC,GAAG,CAAS,GAAW,EAAE,EAAyB;QACtD,MAAM,OAAO,GAAG,uBAAA,IAAI,mCAAU,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACxC,IAAI,OAAO,EAAE,CAAC;YACZ,OAAO,OAA0B,CAAC;QACpC,CAAC;QAED,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,EAAE;aAC3B,IAAI,CAAC,EAAE,CAAC;aACR,OAAO,CAAC,GAAG,EAAE;YACZ,uBAAA,IAAI,mCAAU,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC7B,CAAC,CAAC,CAAC;QACL,uBAAA,IAAI,mCAAU,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAE9B,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAlBD,8CAkBC","sourcesContent":["/**\n * Coalesces concurrent async operations by key: while a call for a key is in\n * flight, subsequent calls with the same key await the same promise instead of\n * starting duplicate work. Once a run settles, the next call starts a fresh one.\n *\n * Note that coalesced callers share the run's outcome, including rejections.\n */\nexport class InFlightCoalescer {\n readonly #inFlight = new Map<string, Promise<unknown>>();\n\n async run<Result>(key: string, fn: () => Promise<Result>): Promise<Result> {\n const pending = this.#inFlight.get(key);\n if (pending) {\n return pending as Promise<Result>;\n }\n\n const task = Promise.resolve()\n .then(fn)\n .finally(() => {\n this.#inFlight.delete(key);\n });\n this.#inFlight.set(key, task);\n\n return task;\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"InFlightCoalescer.d.cts","sourceRoot":"","sources":["../../src/dedupe/InFlightCoalescer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,qBAAa,iBAAiB;;IAGtB,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;CAe3E"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"InFlightCoalescer.d.mts","sourceRoot":"","sources":["../../src/dedupe/InFlightCoalescer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,qBAAa,iBAAiB;;IAGtB,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;CAe3E"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"InFlightCoalescer.mjs","sourceRoot":"","sources":["../../src/dedupe/InFlightCoalescer.ts"],"names":[],"mappings":";;;;;;AAAA;;;;;;GAMG;AACH,MAAM,OAAO,iBAAiB;IAA9B;QACW,sCAAY,IAAI,GAAG,EAA4B,EAAC;IAiB3D,CAAC;IAfC,KAAK,CAAC,GAAG,CAAS,GAAW,EAAE,EAAyB;QACtD,MAAM,OAAO,GAAG,uBAAA,IAAI,mCAAU,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACxC,IAAI,OAAO,EAAE,CAAC;YACZ,OAAO,OAA0B,CAAC;QACpC,CAAC;QAED,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,EAAE;aAC3B,IAAI,CAAC,EAAE,CAAC;aACR,OAAO,CAAC,GAAG,EAAE;YACZ,uBAAA,IAAI,mCAAU,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC7B,CAAC,CAAC,CAAC;QACL,uBAAA,IAAI,mCAAU,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAE9B,OAAO,IAAI,CAAC;IACd,CAAC;CACF","sourcesContent":["/**\n * Coalesces concurrent async operations by key: while a call for a key is in\n * flight, subsequent calls with the same key await the same promise instead of\n * starting duplicate work. Once a run settles, the next call starts a fresh one.\n *\n * Note that coalesced callers share the run's outcome, including rejections.\n */\nexport class InFlightCoalescer {\n readonly #inFlight = new Map<string, Promise<unknown>>();\n\n async run<Result>(key: string, fn: () => Promise<Result>): Promise<Result> {\n const pending = this.#inFlight.get(key);\n if (pending) {\n return pending as Promise<Result>;\n }\n\n const task = Promise.resolve()\n .then(fn)\n .finally(() => {\n this.#inFlight.delete(key);\n });\n this.#inFlight.set(key, task);\n\n return task;\n }\n}\n"]}
|
package/dist/dedupe/index.cjs
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InFlightCoalescer = void 0;
|
|
4
|
-
var InFlightCoalescer_1 = require("./InFlightCoalescer.cjs");
|
|
5
|
-
Object.defineProperty(exports, "InFlightCoalescer", { enumerable: true, get: function () { return InFlightCoalescer_1.InFlightCoalescer; } });
|
|
6
|
-
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/dedupe/index.ts"],"names":[],"mappings":";;;AAAA,6DAAwD;AAA/C,sHAAA,iBAAiB,OAAA","sourcesContent":["export { InFlightCoalescer } from './InFlightCoalescer';\n"]}
|
package/dist/dedupe/index.d.cts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/dedupe/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,gCAA4B"}
|
package/dist/dedupe/index.d.mts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/dedupe/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,gCAA4B"}
|