@metamask-previews/controller-utils 11.16.0-preview-a4b203f → 11.16.0-preview-102c9cee
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/dist/create-service-policy.cjs.map +1 -1
- package/dist/create-service-policy.mjs.map +1 -1
- package/dist/siwe.cjs +13 -10
- package/dist/siwe.cjs.map +1 -1
- package/dist/siwe.d.cts.map +1 -1
- package/dist/siwe.d.mts.map +1 -1
- package/dist/siwe.mjs +13 -10
- package/dist/siwe.mjs.map +1 -1
- package/dist/types.cjs +2 -0
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +2 -0
- package/dist/types.mjs.map +1 -1
- package/dist/util.cjs +35 -24
- package/dist/util.cjs.map +1 -1
- package/dist/util.d.cts +10 -10
- package/dist/util.d.cts.map +1 -1
- package/dist/util.d.mts +10 -10
- package/dist/util.d.mts.map +1 -1
- package/dist/util.mjs +35 -24
- package/dist/util.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-service-policy.cjs","sourceRoot":"","sources":["../src/create-service-policy.ts"],"names":[],"mappings":";;;AAAA,yCAYmB;AAYjB,mGAvBA,8BAAkB,OAuBA;AAElB,6FAxBA,wBAAY,OAwBA;AADZ,sGAtBgB,wBAAqB,OAsBhB;AAGrB,mGAvBA,8BAAkB,OAuBA;AADlB,gGArBA,2BAAe,OAqBA;AAEf,0FArBA,qBAAS,OAqBA;AACT,2FArBA,sBAAU,OAqBA;AAmHZ;;;;GAIG;AACH,MAAM,qBAAqB,GAAG;IAC5B,SAAS,EAAE,WAAW;IACtB,QAAQ,EAAE,UAAU;IACpB,WAAW,EAAE,aAAa;IAC1B,OAAO,EAAE,SAAS;CACV,CAAC;AAUX;;;GAGG;AACU,QAAA,mBAAmB,GAAG,CAAC,CAAC;AAErC;;;;;GAKG;AACU,QAAA,gC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AG,EAAE;QAC3B,OAAO,oBAAoB,CAAC,KAAK,CAAC;IACpC,CAAC,CAAC;IAEF,MAAM,KAAK,GAAG,GAAG,EAAE;QACjB,4EAA4E;QAC5E,MAAM,EAAE,OAAO,EAAE,GAAG,oBAAoB,CAAC,OAAO,EAAE,CAAC;QACnD,8BAA8B;QAC9B,OAAO,EAAE,CAAC;QAEV,2CAA2C;QAC3C,kBAAkB,CAAC,OAAO,EAAE,CAAC;QAE7B,2EAA2E;QAC3E,2DAA2D;QAC3D,kBAAkB,GAAG,qBAAqB,CAAC,OAAO,CAAC;IACrD,CAAC,CAAC;IAEF,OAAO;QACL,GAAG,MAAM;QACT,oBAAoB;QACpB,oBAAoB;QACpB,eAAe;QACf,+BAA+B;QAC/B,KAAK;QACL,WAAW;QACX,OAAO;QACP,UAAU;QACV,WAAW;QACX,OAAO;KACR,CAAC;AACJ,CAAC;AAtID,kDAsIC","sourcesContent":["import {\n BrokenCircuitError,\n CircuitState,\n EventEmitter as CockatielEventEmitter,\n ConsecutiveBreaker,\n ExponentialBackoff,\n ConstantBackoff,\n circuitBreaker,\n handleAll,\n handleWhen,\n retry,\n wrap,\n} from 'cockatiel';\nimport type {\n CircuitBreakerPolicy,\n Event as CockatielEvent,\n FailureReason,\n IBackoffFactory,\n IPolicy,\n Policy,\n RetryPolicy,\n} from 'cockatiel';\n\nexport {\n BrokenCircuitError,\n CockatielEventEmitter,\n CircuitState,\n ConstantBackoff,\n ExponentialBackoff,\n handleAll,\n handleWhen,\n};\n\nexport type { CockatielEvent, FailureReason as CockatielFailureReason };\n\n/**\n * The options for `createServicePolicy`.\n */\nexport type CreateServicePolicyOptions = {\n /**\n * The backoff strategy to use. Mainly useful for testing so that a constant\n * backoff can be used when mocking timers. Defaults to an instance of\n * ExponentialBackoff.\n */\n backoff?: IBackoffFactory<unknown>;\n /**\n * The length of time (in milliseconds) to pause retries of the action after\n * the number of failures reaches `maxConsecutiveFailures`.\n */\n circuitBreakDuration?: number;\n /**\n * The length of time (in milliseconds) that governs when the service is\n * regarded as degraded (affecting when `onDegraded` is called).\n */\n degradedThreshold?: number;\n /**\n * The maximum number of times that the service is allowed to fail before\n * pausing further retries.\n */\n maxConsecutiveFailures?: number;\n /**\n * The maximum number of times that a failing service should be re-invoked\n * before giving up.\n */\n maxRetries?: number;\n /**\n * The policy used to control when the service should be retried based on\n * either the result of the service or an error that it throws. For instance,\n * you could use this to retry only certain errors. See `handleWhen` and\n * friends from Cockatiel for more.\n */\n retryFilterPolicy?: Policy;\n};\n\n/**\n * The service policy object.\n */\nexport type ServicePolicy = IPolicy & {\n /**\n * The Cockatiel circuit breaker policy that the service policy uses\n * internally.\n */\n circuitBreakerPolicy: CircuitBreakerPolicy;\n /**\n * The amount of time to pause requests to the service if the number of\n * maximum consecutive failures is reached.\n */\n circuitBreakDuration: number;\n /**\n * @returns The state of the underlying circuit.\n */\n getCircuitState: () => CircuitState;\n /**\n * If the circuit is open and ongoing requests are paused, returns the number\n * of milliseconds before the requests will be attempted again. If the circuit\n * is not open, returns null.\n */\n getRemainingCircuitOpenDuration: () => number | null;\n /**\n * Resets the internal circuit breaker policy (if it is open, it will now be\n * closed).\n */\n reset: () => void;\n /**\n * The Cockatiel retry policy that the service policy uses internally.\n */\n retryPolicy: RetryPolicy;\n /**\n * A function which is called when the number of times that the service fails\n * in a row meets the set maximum number of consecutive failures.\n */\n onBreak: CircuitBreakerPolicy['onBreak'];\n /**\n * A function which is called in two circumstances: 1) when the service\n * succeeds before the maximum number of consecutive failures is reached, but\n * takes more time than the `degradedThreshold` to run, or 2) if the service\n * never succeeds before the retry policy gives up and before the maximum\n * number of consecutive failures has been reached.\n */\n onDegraded: CockatielEvent<FailureReason<unknown> | void>;\n /**\n * A function which is called when the service succeeds for the first time,\n * or when the service fails enough times to cause the circuit to break and\n * then recovers.\n */\n onAvailable: CockatielEvent<void>;\n /**\n * A function which will be called by the retry policy each time the service\n * fails and the policy kicks off a timer to re-run the service. This is\n * primarily useful in tests where we are mocking timers.\n */\n onRetry: RetryPolicy['onRetry'];\n};\n\n/**\n * Parts of the circuit breaker's internal and external state as necessary in\n * order to compute the time remaining before the circuit will reopen.\n */\ntype InternalCircuitState =\n | {\n state: CircuitState.Open;\n openedAt: number;\n }\n | { state: Exclude<CircuitState, CircuitState.Open> };\n\n/**\n * Availability statuses that the service can be in.\n *\n * Used to keep track of whether the `onAvailable` event should be fired.\n */\nconst AVAILABILITY_STATUSES = {\n Available: 'available',\n Degraded: 'degraded',\n Unavailable: 'unavailable',\n Unknown: 'unknown',\n} as const;\n\n/**\n * Availability statuses that the service can be in.\n *\n * Used to keep track of whether the `onAvailable` event should be fired.\n */\ntype AvailabilityStatus =\n (typeof AVAILABILITY_STATUSES)[keyof typeof AVAILABILITY_STATUSES];\n\n/**\n * The maximum number of times that a failing service should be re-run before\n * giving up.\n */\nexport const DEFAULT_MAX_RETRIES = 3;\n\n/**\n * The maximum number of times that the service is allowed to fail before\n * pausing further retries. This is set to a value such that if given a\n * service that continually fails, the policy needs to be executed 3 times\n * before further retries are paused.\n */\nexport const DEFAULT_MAX_CONSECUTIVE_FAILURES = (1 + DEFAULT_MAX_RETRIES) * 3;\n\n/**\n * The default length of time (in milliseconds) to temporarily pause retries of\n * the service after enough consecutive failures.\n */\nexport const DEFAULT_CIRCUIT_BREAK_DURATION = 30 * 60 * 1000;\n\n/**\n * The default length of time (in milliseconds) that governs when the service is\n * regarded as degraded (affecting when `onDegraded` is called).\n */\nexport const DEFAULT_DEGRADED_THRESHOLD = 5_000;\n\nconst isServiceFailure = (error: unknown) => {\n if (\n typeof error === 'object' &&\n error !== null &&\n 'httpStatus' in error &&\n typeof error.httpStatus === 'number'\n ) {\n return error.httpStatus >= 500;\n }\n\n // If the error is not an object, or doesn't have a numeric code property,\n // consider it a service failure (e.g., network errors, timeouts, etc.)\n return true;\n};\n\n/**\n * The circuit breaker policy inside of the Cockatiel library exposes some of\n * its state, but not all of it. Notably, the time that the circuit opened is\n * not publicly accessible. So we have to record this ourselves.\n *\n * This function therefore allows us to obtain the circuit breaker state that we\n * wish we could access.\n *\n * @param state - The public state of a circuit breaker policy.\n * @returns if the circuit is open, the state of the circuit breaker policy plus\n * the time that it opened, otherwise just the circuit state.\n */\nfunction getInternalCircuitState(state: CircuitState): InternalCircuitState {\n if (state === CircuitState.Open) {\n return { state, openedAt: Date.now() };\n }\n return { state };\n}\n\n/**\n * Constructs an object exposing an `execute` method which, given a function —\n * hereafter called the \"service\" — will retry that service with ever increasing\n * delays until it succeeds. If the policy detects too many consecutive\n * failures, it will block further retries until a designated time period has\n * passed; this particular behavior is primarily designed for services that wrap\n * API calls so as not to make needless HTTP requests when the API is down and\n * to be able to recover when the API comes back up. In addition, hooks allow\n * for responding to certain events, one of which can be used to detect when an\n * HTTP request is performing slowly.\n *\n * Internally, this function makes use of the retry and circuit breaker policies\n * from the [Cockatiel](https://www.npmjs.com/package/cockatiel) library; see\n * there for more.\n *\n * @param options - The options to this function. See\n * {@link CreateServicePolicyOptions}.\n * @returns The service policy.\n * @example\n * This function is designed to be used in the context of a service class like\n * this:\n * ``` ts\n * class Service {\n * constructor() {\n * this.#policy = createServicePolicy({\n * maxRetries: 3,\n * retryFilterPolicy: handleWhen((error) => {\n * return error.message.includes('oops');\n * }),\n * maxConsecutiveFailures: 3,\n * circuitBreakDuration: 5000,\n * degradedThreshold: 2000,\n * onBreak: () => {\n * console.log('Circuit broke');\n * },\n * onDegraded: () => {\n * console.log('Service is degraded');\n * },\n * });\n * }\n *\n * async fetch() {\n * return await this.#policy.execute(async () => {\n * const response = await fetch('https://some/url');\n * return await response.json();\n * });\n * }\n * }\n * ```\n */\nexport function createServicePolicy(\n options: CreateServicePolicyOptions = {},\n): ServicePolicy {\n const {\n maxRetries = DEFAULT_MAX_RETRIES,\n retryFilterPolicy = handleAll,\n maxConsecutiveFailures = DEFAULT_MAX_CONSECUTIVE_FAILURES,\n circuitBreakDuration = DEFAULT_CIRCUIT_BREAK_DURATION,\n degradedThreshold = DEFAULT_DEGRADED_THRESHOLD,\n backoff = new ExponentialBackoff(),\n } = options;\n\n let availabilityStatus: AvailabilityStatus = AVAILABILITY_STATUSES.Unknown;\n\n const retryPolicy = retry(retryFilterPolicy, {\n // Note that although the option here is called \"max attempts\", it's really\n // maximum number of *retries* (attempts past the initial attempt).\n maxAttempts: maxRetries,\n // Retries of the service will be executed following ever increasing delays,\n // determined by a backoff formula.\n backoff,\n });\n const onRetry = retryPolicy.onRetry.bind(retryPolicy);\n\n const consecutiveBreaker = new ConsecutiveBreaker(maxConsecutiveFailures);\n const circuitBreakerPolicy = circuitBreaker(handleWhen(isServiceFailure), {\n // While the circuit is open, any additional invocations of the service\n // passed to the policy (either via automatic retries or by manually\n // executing the policy again) will result in a BrokenCircuitError. This\n // will remain the case until `circuitBreakDuration` passes, after which the\n // service will be allowed to run again. If the service succeeds, the\n // circuit will close, otherwise it will remain open.\n halfOpenAfter: circuitBreakDuration,\n breaker: consecutiveBreaker,\n });\n\n let internalCircuitState: InternalCircuitState = getInternalCircuitState(\n circuitBreakerPolicy.state,\n );\n circuitBreakerPolicy.onStateChange((state) => {\n internalCircuitState = getInternalCircuitState(state);\n });\n\n circuitBreakerPolicy.onBreak(() => {\n availabilityStatus = AVAILABILITY_STATUSES.Unavailable;\n });\n const onBreak = circuitBreakerPolicy.onBreak.bind(circuitBreakerPolicy);\n\n const onDegradedEventEmitter =\n new CockatielEventEmitter<FailureReason<unknown> | void>();\n const onDegraded = onDegradedEventEmitter.addListener;\n\n const onAvailableEventEmitter = new CockatielEventEmitter<void>();\n const onAvailable = onAvailableEventEmitter.addListener;\n\n retryPolicy.onGiveUp((data) => {\n if (circuitBreakerPolicy.state === CircuitState.Closed) {\n availabilityStatus = AVAILABILITY_STATUSES.Degraded;\n onDegradedEventEmitter.emit(data);\n }\n });\n retryPolicy.onSuccess(({ duration }) => {\n if (circuitBreakerPolicy.state === CircuitState.Closed) {\n if (duration > degradedThreshold) {\n availabilityStatus = AVAILABILITY_STATUSES.Degraded;\n onDegradedEventEmitter.emit();\n } else if (availabilityStatus !== AVAILABILITY_STATUSES.Available) {\n availabilityStatus = AVAILABILITY_STATUSES.Available;\n onAvailableEventEmitter.emit();\n }\n }\n });\n\n // Every time the retry policy makes an attempt, it executes the circuit\n // breaker policy, which executes the service.\n //\n // Calling:\n //\n // policy.execute(() => {\n // // do what the service does\n // })\n //\n // is equivalent to:\n //\n // retryPolicy.execute(() => {\n // circuitBreakerPolicy.execute(() => {\n // // do what the service does\n // });\n // });\n //\n // So if the retry policy succeeds or fails, it is because the circuit breaker\n // policy succeeded or failed. And if there are any event listeners registered\n // on the retry policy, by the time they are called, the state of the circuit\n // breaker will have already changed.\n const policy = wrap(retryPolicy, circuitBreakerPolicy);\n\n const getRemainingCircuitOpenDuration = () => {\n if (internalCircuitState.state === CircuitState.Open) {\n return internalCircuitState.openedAt + circuitBreakDuration - Date.now();\n }\n return null;\n };\n\n const getCircuitState = () => {\n return circuitBreakerPolicy.state;\n };\n\n const reset = () => {\n // Set the state of the policy to \"isolated\" regardless of its current state\n const { dispose } = circuitBreakerPolicy.isolate();\n // Reset the state to \"closed\"\n dispose();\n\n // Reset the counter on the breaker as well\n consecutiveBreaker.success();\n\n // Re-initialize the availability status so that if the service is executed\n // successfully, onAvailable listeners will be called again\n availabilityStatus = AVAILABILITY_STATUSES.Unknown;\n };\n\n return {\n ...policy,\n circuitBreakerPolicy,\n circuitBreakDuration,\n getCircuitState,\n getRemainingCircuitOpenDuration,\n reset,\n retryPolicy,\n onBreak,\n onDegraded,\n onAvailable,\n onRetry,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"create-service-policy.cjs","sourceRoot":"","sources":["../src/create-service-policy.ts"],"names":[],"mappings":";;;AAAA,yCAYmB;AAYjB,mGAvBA,8BAAkB,OAuBA;AAElB,6FAxBA,wBAAY,OAwBA;AADZ,sGAtBgB,wBAAqB,OAsBhB;AAGrB,mGAvBA,8BAAkB,OAuBA;AADlB,gGArBA,2BAAe,OAqBA;AAEf,0FAr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AAC;IAEvD,MAAM,+BAA+B,GAAG,GAAkB,EAAE;QAC1D,IAAI,oBAAoB,CAAC,KAAK,KAAK,wBAAY,CAAC,IAAI,EAAE,CAAC;YACrD,OAAO,oBAAoB,CAAC,QAAQ,GAAG,oBAAoB,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC3E,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;IAEF,MAAM,eAAe,GAAG,GAAiB,EAAE;QACzC,OAAO,oBAAoB,CAAC,KAAK,CAAC;IACpC,CAAC,CAAC;IAEF,MAAM,KAAK,GAAG,GAAS,EAAE;QACvB,4EAA4E;QAC5E,MAAM,EAAE,OAAO,EAAE,GAAG,oBAAoB,CAAC,OAAO,EAAE,CAAC;QACnD,8BAA8B;QAC9B,OAAO,EAAE,CAAC;QAEV,2CAA2C;QAC3C,kBAAkB,CAAC,OAAO,EAAE,CAAC;QAE7B,2EAA2E;QAC3E,2DAA2D;QAC3D,kBAAkB,GAAG,qBAAqB,CAAC,OAAO,CAAC;IACrD,CAAC,CAAC;IAEF,OAAO;QACL,GAAG,MAAM;QACT,oBAAoB;QACpB,oBAAoB;QACpB,eAAe;QACf,+BAA+B;QAC/B,KAAK;QACL,WAAW;QACX,OAAO;QACP,UAAU;QACV,WAAW;QACX,OAAO;KACR,CAAC;AACJ,CAAC;AAtID,kDAsIC","sourcesContent":["import {\n BrokenCircuitError,\n CircuitState,\n EventEmitter as CockatielEventEmitter,\n ConsecutiveBreaker,\n ExponentialBackoff,\n ConstantBackoff,\n circuitBreaker,\n handleAll,\n handleWhen,\n retry,\n wrap,\n} from 'cockatiel';\nimport type {\n CircuitBreakerPolicy,\n Event as CockatielEvent,\n FailureReason,\n IBackoffFactory,\n IPolicy,\n Policy,\n RetryPolicy,\n} from 'cockatiel';\n\nexport {\n BrokenCircuitError,\n CockatielEventEmitter,\n CircuitState,\n ConstantBackoff,\n ExponentialBackoff,\n handleAll,\n handleWhen,\n};\n\nexport type { CockatielEvent, FailureReason as CockatielFailureReason };\n\n/**\n * The options for `createServicePolicy`.\n */\nexport type CreateServicePolicyOptions = {\n /**\n * The backoff strategy to use. Mainly useful for testing so that a constant\n * backoff can be used when mocking timers. Defaults to an instance of\n * ExponentialBackoff.\n */\n backoff?: IBackoffFactory<unknown>;\n /**\n * The length of time (in milliseconds) to pause retries of the action after\n * the number of failures reaches `maxConsecutiveFailures`.\n */\n circuitBreakDuration?: number;\n /**\n * The length of time (in milliseconds) that governs when the service is\n * regarded as degraded (affecting when `onDegraded` is called).\n */\n degradedThreshold?: number;\n /**\n * The maximum number of times that the service is allowed to fail before\n * pausing further retries.\n */\n maxConsecutiveFailures?: number;\n /**\n * The maximum number of times that a failing service should be re-invoked\n * before giving up.\n */\n maxRetries?: number;\n /**\n * The policy used to control when the service should be retried based on\n * either the result of the service or an error that it throws. For instance,\n * you could use this to retry only certain errors. See `handleWhen` and\n * friends from Cockatiel for more.\n */\n retryFilterPolicy?: Policy;\n};\n\n/**\n * The service policy object.\n */\nexport type ServicePolicy = IPolicy & {\n /**\n * The Cockatiel circuit breaker policy that the service policy uses\n * internally.\n */\n circuitBreakerPolicy: CircuitBreakerPolicy;\n /**\n * The amount of time to pause requests to the service if the number of\n * maximum consecutive failures is reached.\n */\n circuitBreakDuration: number;\n /**\n * @returns The state of the underlying circuit.\n */\n getCircuitState: () => CircuitState;\n /**\n * If the circuit is open and ongoing requests are paused, returns the number\n * of milliseconds before the requests will be attempted again. If the circuit\n * is not open, returns null.\n */\n getRemainingCircuitOpenDuration: () => number | null;\n /**\n * Resets the internal circuit breaker policy (if it is open, it will now be\n * closed).\n */\n reset: () => void;\n /**\n * The Cockatiel retry policy that the service policy uses internally.\n */\n retryPolicy: RetryPolicy;\n /**\n * A function which is called when the number of times that the service fails\n * in a row meets the set maximum number of consecutive failures.\n */\n onBreak: CircuitBreakerPolicy['onBreak'];\n /**\n * A function which is called in two circumstances: 1) when the service\n * succeeds before the maximum number of consecutive failures is reached, but\n * takes more time than the `degradedThreshold` to run, or 2) if the service\n * never succeeds before the retry policy gives up and before the maximum\n * number of consecutive failures has been reached.\n */\n onDegraded: CockatielEvent<FailureReason<unknown> | void>;\n /**\n * A function which is called when the service succeeds for the first time,\n * or when the service fails enough times to cause the circuit to break and\n * then recovers.\n */\n onAvailable: CockatielEvent<void>;\n /**\n * A function which will be called by the retry policy each time the service\n * fails and the policy kicks off a timer to re-run the service. This is\n * primarily useful in tests where we are mocking timers.\n */\n onRetry: RetryPolicy['onRetry'];\n};\n\n/**\n * Parts of the circuit breaker's internal and external state as necessary in\n * order to compute the time remaining before the circuit will reopen.\n */\ntype InternalCircuitState =\n | {\n state: CircuitState.Open;\n openedAt: number;\n }\n | { state: Exclude<CircuitState, CircuitState.Open> };\n\n/**\n * Availability statuses that the service can be in.\n *\n * Used to keep track of whether the `onAvailable` event should be fired.\n */\nconst AVAILABILITY_STATUSES = {\n Available: 'available',\n Degraded: 'degraded',\n Unavailable: 'unavailable',\n Unknown: 'unknown',\n} as const;\n\n/**\n * Availability statuses that the service can be in.\n *\n * Used to keep track of whether the `onAvailable` event should be fired.\n */\ntype AvailabilityStatus =\n (typeof AVAILABILITY_STATUSES)[keyof typeof AVAILABILITY_STATUSES];\n\n/**\n * The maximum number of times that a failing service should be re-run before\n * giving up.\n */\nexport const DEFAULT_MAX_RETRIES = 3;\n\n/**\n * The maximum number of times that the service is allowed to fail before\n * pausing further retries. This is set to a value such that if given a\n * service that continually fails, the policy needs to be executed 3 times\n * before further retries are paused.\n */\nexport const DEFAULT_MAX_CONSECUTIVE_FAILURES = (1 + DEFAULT_MAX_RETRIES) * 3;\n\n/**\n * The default length of time (in milliseconds) to temporarily pause retries of\n * the service after enough consecutive failures.\n */\nexport const DEFAULT_CIRCUIT_BREAK_DURATION = 30 * 60 * 1000;\n\n/**\n * The default length of time (in milliseconds) that governs when the service is\n * regarded as degraded (affecting when `onDegraded` is called).\n */\nexport const DEFAULT_DEGRADED_THRESHOLD = 5_000;\n\nconst isServiceFailure = (error: unknown): boolean => {\n if (\n typeof error === 'object' &&\n error !== null &&\n 'httpStatus' in error &&\n typeof error.httpStatus === 'number'\n ) {\n return error.httpStatus >= 500;\n }\n\n // If the error is not an object, or doesn't have a numeric code property,\n // consider it a service failure (e.g., network errors, timeouts, etc.)\n return true;\n};\n\n/**\n * The circuit breaker policy inside of the Cockatiel library exposes some of\n * its state, but not all of it. Notably, the time that the circuit opened is\n * not publicly accessible. So we have to record this ourselves.\n *\n * This function therefore allows us to obtain the circuit breaker state that we\n * wish we could access.\n *\n * @param state - The public state of a circuit breaker policy.\n * @returns if the circuit is open, the state of the circuit breaker policy plus\n * the time that it opened, otherwise just the circuit state.\n */\nfunction getInternalCircuitState(state: CircuitState): InternalCircuitState {\n if (state === CircuitState.Open) {\n return { state, openedAt: Date.now() };\n }\n return { state };\n}\n\n/**\n * Constructs an object exposing an `execute` method which, given a function —\n * hereafter called the \"service\" — will retry that service with ever increasing\n * delays until it succeeds. If the policy detects too many consecutive\n * failures, it will block further retries until a designated time period has\n * passed; this particular behavior is primarily designed for services that wrap\n * API calls so as not to make needless HTTP requests when the API is down and\n * to be able to recover when the API comes back up. In addition, hooks allow\n * for responding to certain events, one of which can be used to detect when an\n * HTTP request is performing slowly.\n *\n * Internally, this function makes use of the retry and circuit breaker policies\n * from the [Cockatiel](https://www.npmjs.com/package/cockatiel) library; see\n * there for more.\n *\n * @param options - The options to this function. See\n * {@link CreateServicePolicyOptions}.\n * @returns The service policy.\n * @example\n * This function is designed to be used in the context of a service class like\n * this:\n * ``` ts\n * class Service {\n * constructor() {\n * this.#policy = createServicePolicy({\n * maxRetries: 3,\n * retryFilterPolicy: handleWhen((error) => {\n * return error.message.includes('oops');\n * }),\n * maxConsecutiveFailures: 3,\n * circuitBreakDuration: 5000,\n * degradedThreshold: 2000,\n * onBreak: () => {\n * console.log('Circuit broke');\n * },\n * onDegraded: () => {\n * console.log('Service is degraded');\n * },\n * });\n * }\n *\n * async fetch() {\n * return await this.#policy.execute(async () => {\n * const response = await fetch('https://some/url');\n * return await response.json();\n * });\n * }\n * }\n * ```\n */\nexport function createServicePolicy(\n options: CreateServicePolicyOptions = {},\n): ServicePolicy {\n const {\n maxRetries = DEFAULT_MAX_RETRIES,\n retryFilterPolicy = handleAll,\n maxConsecutiveFailures = DEFAULT_MAX_CONSECUTIVE_FAILURES,\n circuitBreakDuration = DEFAULT_CIRCUIT_BREAK_DURATION,\n degradedThreshold = DEFAULT_DEGRADED_THRESHOLD,\n backoff = new ExponentialBackoff(),\n } = options;\n\n let availabilityStatus: AvailabilityStatus = AVAILABILITY_STATUSES.Unknown;\n\n const retryPolicy = retry(retryFilterPolicy, {\n // Note that although the option here is called \"max attempts\", it's really\n // maximum number of *retries* (attempts past the initial attempt).\n maxAttempts: maxRetries,\n // Retries of the service will be executed following ever increasing delays,\n // determined by a backoff formula.\n backoff,\n });\n const onRetry = retryPolicy.onRetry.bind(retryPolicy);\n\n const consecutiveBreaker = new ConsecutiveBreaker(maxConsecutiveFailures);\n const circuitBreakerPolicy = circuitBreaker(handleWhen(isServiceFailure), {\n // While the circuit is open, any additional invocations of the service\n // passed to the policy (either via automatic retries or by manually\n // executing the policy again) will result in a BrokenCircuitError. This\n // will remain the case until `circuitBreakDuration` passes, after which the\n // service will be allowed to run again. If the service succeeds, the\n // circuit will close, otherwise it will remain open.\n halfOpenAfter: circuitBreakDuration,\n breaker: consecutiveBreaker,\n });\n\n let internalCircuitState: InternalCircuitState = getInternalCircuitState(\n circuitBreakerPolicy.state,\n );\n circuitBreakerPolicy.onStateChange((state) => {\n internalCircuitState = getInternalCircuitState(state);\n });\n\n circuitBreakerPolicy.onBreak(() => {\n availabilityStatus = AVAILABILITY_STATUSES.Unavailable;\n });\n const onBreak = circuitBreakerPolicy.onBreak.bind(circuitBreakerPolicy);\n\n const onDegradedEventEmitter =\n new CockatielEventEmitter<FailureReason<unknown> | void>();\n const onDegraded = onDegradedEventEmitter.addListener;\n\n const onAvailableEventEmitter = new CockatielEventEmitter<void>();\n const onAvailable = onAvailableEventEmitter.addListener;\n\n retryPolicy.onGiveUp((data) => {\n if (circuitBreakerPolicy.state === CircuitState.Closed) {\n availabilityStatus = AVAILABILITY_STATUSES.Degraded;\n onDegradedEventEmitter.emit(data);\n }\n });\n retryPolicy.onSuccess(({ duration }) => {\n if (circuitBreakerPolicy.state === CircuitState.Closed) {\n if (duration > degradedThreshold) {\n availabilityStatus = AVAILABILITY_STATUSES.Degraded;\n onDegradedEventEmitter.emit();\n } else if (availabilityStatus !== AVAILABILITY_STATUSES.Available) {\n availabilityStatus = AVAILABILITY_STATUSES.Available;\n onAvailableEventEmitter.emit();\n }\n }\n });\n\n // Every time the retry policy makes an attempt, it executes the circuit\n // breaker policy, which executes the service.\n //\n // Calling:\n //\n // policy.execute(() => {\n // // do what the service does\n // })\n //\n // is equivalent to:\n //\n // retryPolicy.execute(() => {\n // circuitBreakerPolicy.execute(() => {\n // // do what the service does\n // });\n // });\n //\n // So if the retry policy succeeds or fails, it is because the circuit breaker\n // policy succeeded or failed. And if there are any event listeners registered\n // on the retry policy, by the time they are called, the state of the circuit\n // breaker will have already changed.\n const policy = wrap(retryPolicy, circuitBreakerPolicy);\n\n const getRemainingCircuitOpenDuration = (): number | null => {\n if (internalCircuitState.state === CircuitState.Open) {\n return internalCircuitState.openedAt + circuitBreakDuration - Date.now();\n }\n return null;\n };\n\n const getCircuitState = (): CircuitState => {\n return circuitBreakerPolicy.state;\n };\n\n const reset = (): void => {\n // Set the state of the policy to \"isolated\" regardless of its current state\n const { dispose } = circuitBreakerPolicy.isolate();\n // Reset the state to \"closed\"\n dispose();\n\n // Reset the counter on the breaker as well\n consecutiveBreaker.success();\n\n // Re-initialize the availability status so that if the service is executed\n // successfully, onAvailable listeners will be called again\n availabilityStatus = AVAILABILITY_STATUSES.Unknown;\n };\n\n return {\n ...policy,\n circuitBreakerPolicy,\n circuitBreakDuration,\n getCircuitState,\n getRemainingCircuitOpenDuration,\n reset,\n retryPolicy,\n onBreak,\n onDegraded,\n onAvailable,\n onRetry,\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-service-policy.mjs","sourceRoot":"","sources":["../src/create-service-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,YAAY,IAAI,qBAAqB,EACrC,kBAAkB,EAClB,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,SAAS,EACT,UAAU,EACV,KAAK,EACL,IAAI,EACL,kBAAkB;AAWnB,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,YAAY,EACZ,eAAe,EACf,kBAAkB,EAClB,SAAS,EACT,UAAU,EACX,CAAC;AAkHF;;;;GAIG;AACH,MAAM,qBAAqB,GAAG;IAC5B,SAAS,EAAE,WAAW;IACtB,QAAQ,EAAE,UAAU;IACpB,WAAW,EAAE,aAAa;IAC1B,OAAO,EAAE,SAAS;CACV,CAAC;AAUX;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAErC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,CAAC,CAAC,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC;AAE9E;;;GAGG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAE7D;;;GAGG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,IAAK,CAAC;AAEhD,MAAM,gBAAgB,GAAG,CAAC,KAAc,EAAE,EAAE;IAC1C,IACE,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,YAAY,IAAI,KAAK;QACrB,OAAO,KAAK,CAAC,UAAU,KAAK,QAAQ,EACpC,CAAC;QACD,OAAO,KAAK,CAAC,UAAU,IAAI,GAAG,CAAC;IACjC,CAAC;IAED,0EAA0E;IAC1E,uEAAuE;IACvE,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF;;;;;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cesContent":["import {\n BrokenCircuitError,\n CircuitState,\n EventEmitter as CockatielEventEmitter,\n ConsecutiveBreaker,\n ExponentialBackoff,\n ConstantBackoff,\n circuitBreaker,\n handleAll,\n handleWhen,\n retry,\n wrap,\n} from 'cockatiel';\nimport type {\n CircuitBreakerPolicy,\n Event as CockatielEvent,\n FailureReason,\n IBackoffFactory,\n IPolicy,\n Policy,\n RetryPolicy,\n} from 'cockatiel';\n\nexport {\n BrokenCircuitError,\n CockatielEventEmitter,\n CircuitState,\n ConstantBackoff,\n ExponentialBackoff,\n handleAll,\n handleWhen,\n};\n\nexport type { CockatielEvent, FailureReason as CockatielFailureReason };\n\n/**\n * The options for `createServicePolicy`.\n */\nexport type CreateServicePolicyOptions = {\n /**\n * The backoff strategy to use. Mainly useful for testing so that a constant\n * backoff can be used when mocking timers. Defaults to an instance of\n * ExponentialBackoff.\n */\n backoff?: IBackoffFactory<unknown>;\n /**\n * The length of time (in milliseconds) to pause retries of the action after\n * the number of failures reaches `maxConsecutiveFailures`.\n */\n circuitBreakDuration?: number;\n /**\n * The length of time (in milliseconds) that governs when the service is\n * regarded as degraded (affecting when `onDegraded` is called).\n */\n degradedThreshold?: number;\n /**\n * The maximum number of times that the service is allowed to fail before\n * pausing further retries.\n */\n maxConsecutiveFailures?: number;\n /**\n * The maximum number of times that a failing service should be re-invoked\n * before giving up.\n */\n maxRetries?: number;\n /**\n * The policy used to control when the service should be retried based on\n * either the result of the service or an error that it throws. For instance,\n * you could use this to retry only certain errors. See `handleWhen` and\n * friends from Cockatiel for more.\n */\n retryFilterPolicy?: Policy;\n};\n\n/**\n * The service policy object.\n */\nexport type ServicePolicy = IPolicy & {\n /**\n * The Cockatiel circuit breaker policy that the service policy uses\n * internally.\n */\n circuitBreakerPolicy: CircuitBreakerPolicy;\n /**\n * The amount of time to pause requests to the service if the number of\n * maximum consecutive failures is reached.\n */\n circuitBreakDuration: number;\n /**\n * @returns The state of the underlying circuit.\n */\n getCircuitState: () => CircuitState;\n /**\n * If the circuit is open and ongoing requests are paused, returns the number\n * of milliseconds before the requests will be attempted again. If the circuit\n * is not open, returns null.\n */\n getRemainingCircuitOpenDuration: () => number | null;\n /**\n * Resets the internal circuit breaker policy (if it is open, it will now be\n * closed).\n */\n reset: () => void;\n /**\n * The Cockatiel retry policy that the service policy uses internally.\n */\n retryPolicy: RetryPolicy;\n /**\n * A function which is called when the number of times that the service fails\n * in a row meets the set maximum number of consecutive failures.\n */\n onBreak: CircuitBreakerPolicy['onBreak'];\n /**\n * A function which is called in two circumstances: 1) when the service\n * succeeds before the maximum number of consecutive failures is reached, but\n * takes more time than the `degradedThreshold` to run, or 2) if the service\n * never succeeds before the retry policy gives up and before the maximum\n * number of consecutive failures has been reached.\n */\n onDegraded: CockatielEvent<FailureReason<unknown> | void>;\n /**\n * A function which is called when the service succeeds for the first time,\n * or when the service fails enough times to cause the circuit to break and\n * then recovers.\n */\n onAvailable: CockatielEvent<void>;\n /**\n * A function which will be called by the retry policy each time the service\n * fails and the policy kicks off a timer to re-run the service. This is\n * primarily useful in tests where we are mocking timers.\n */\n onRetry: RetryPolicy['onRetry'];\n};\n\n/**\n * Parts of the circuit breaker's internal and external state as necessary in\n * order to compute the time remaining before the circuit will reopen.\n */\ntype InternalCircuitState =\n | {\n state: CircuitState.Open;\n openedAt: number;\n }\n | { state: Exclude<CircuitState, CircuitState.Open> };\n\n/**\n * Availability statuses that the service can be in.\n *\n * Used to keep track of whether the `onAvailable` event should be fired.\n */\nconst AVAILABILITY_STATUSES = {\n Available: 'available',\n Degraded: 'degraded',\n Unavailable: 'unavailable',\n Unknown: 'unknown',\n} as const;\n\n/**\n * Availability statuses that the service can be in.\n *\n * Used to keep track of whether the `onAvailable` event should be fired.\n */\ntype AvailabilityStatus =\n (typeof AVAILABILITY_STATUSES)[keyof typeof AVAILABILITY_STATUSES];\n\n/**\n * The maximum number of times that a failing service should be re-run before\n * giving up.\n */\nexport const DEFAULT_MAX_RETRIES = 3;\n\n/**\n * The maximum number of times that the service is allowed to fail before\n * pausing further retries. This is set to a value such that if given a\n * service that continually fails, the policy needs to be executed 3 times\n * before further retries are paused.\n */\nexport const DEFAULT_MAX_CONSECUTIVE_FAILURES = (1 + DEFAULT_MAX_RETRIES) * 3;\n\n/**\n * The default length of time (in milliseconds) to temporarily pause retries of\n * the service after enough consecutive failures.\n */\nexport const DEFAULT_CIRCUIT_BREAK_DURATION = 30 * 60 * 1000;\n\n/**\n * The default length of time (in milliseconds) that governs when the service is\n * regarded as degraded (affecting when `onDegraded` is called).\n */\nexport const DEFAULT_DEGRADED_THRESHOLD = 5_000;\n\nconst isServiceFailure = (error: unknown) => {\n if (\n typeof error === 'object' &&\n error !== null &&\n 'httpStatus' in error &&\n typeof error.httpStatus === 'number'\n ) {\n return error.httpStatus >= 500;\n }\n\n // If the error is not an object, or doesn't have a numeric code property,\n // consider it a service failure (e.g., network errors, timeouts, etc.)\n return true;\n};\n\n/**\n * The circuit breaker policy inside of the Cockatiel library exposes some of\n * its state, but not all of it. Notably, the time that the circuit opened is\n * not publicly accessible. So we have to record this ourselves.\n *\n * This function therefore allows us to obtain the circuit breaker state that we\n * wish we could access.\n *\n * @param state - The public state of a circuit breaker policy.\n * @returns if the circuit is open, the state of the circuit breaker policy plus\n * the time that it opened, otherwise just the circuit state.\n */\nfunction getInternalCircuitState(state: CircuitState): InternalCircuitState {\n if (state === CircuitState.Open) {\n return { state, openedAt: Date.now() };\n }\n return { state };\n}\n\n/**\n * Constructs an object exposing an `execute` method which, given a function —\n * hereafter called the \"service\" — will retry that service with ever increasing\n * delays until it succeeds. If the policy detects too many consecutive\n * failures, it will block further retries until a designated time period has\n * passed; this particular behavior is primarily designed for services that wrap\n * API calls so as not to make needless HTTP requests when the API is down and\n * to be able to recover when the API comes back up. In addition, hooks allow\n * for responding to certain events, one of which can be used to detect when an\n * HTTP request is performing slowly.\n *\n * Internally, this function makes use of the retry and circuit breaker policies\n * from the [Cockatiel](https://www.npmjs.com/package/cockatiel) library; see\n * there for more.\n *\n * @param options - The options to this function. See\n * {@link CreateServicePolicyOptions}.\n * @returns The service policy.\n * @example\n * This function is designed to be used in the context of a service class like\n * this:\n * ``` ts\n * class Service {\n * constructor() {\n * this.#policy = createServicePolicy({\n * maxRetries: 3,\n * retryFilterPolicy: handleWhen((error) => {\n * return error.message.includes('oops');\n * }),\n * maxConsecutiveFailures: 3,\n * circuitBreakDuration: 5000,\n * degradedThreshold: 2000,\n * onBreak: () => {\n * console.log('Circuit broke');\n * },\n * onDegraded: () => {\n * console.log('Service is degraded');\n * },\n * });\n * }\n *\n * async fetch() {\n * return await this.#policy.execute(async () => {\n * const response = await fetch('https://some/url');\n * return await response.json();\n * });\n * }\n * }\n * ```\n */\nexport function createServicePolicy(\n options: CreateServicePolicyOptions = {},\n): ServicePolicy {\n const {\n maxRetries = DEFAULT_MAX_RETRIES,\n retryFilterPolicy = handleAll,\n maxConsecutiveFailures = DEFAULT_MAX_CONSECUTIVE_FAILURES,\n circuitBreakDuration = DEFAULT_CIRCUIT_BREAK_DURATION,\n degradedThreshold = DEFAULT_DEGRADED_THRESHOLD,\n backoff = new ExponentialBackoff(),\n } = options;\n\n let availabilityStatus: AvailabilityStatus = AVAILABILITY_STATUSES.Unknown;\n\n const retryPolicy = retry(retryFilterPolicy, {\n // Note that although the option here is called \"max attempts\", it's really\n // maximum number of *retries* (attempts past the initial attempt).\n maxAttempts: maxRetries,\n // Retries of the service will be executed following ever increasing delays,\n // determined by a backoff formula.\n backoff,\n });\n const onRetry = retryPolicy.onRetry.bind(retryPolicy);\n\n const consecutiveBreaker = new ConsecutiveBreaker(maxConsecutiveFailures);\n const circuitBreakerPolicy = circuitBreaker(handleWhen(isServiceFailure), {\n // While the circuit is open, any additional invocations of the service\n // passed to the policy (either via automatic retries or by manually\n // executing the policy again) will result in a BrokenCircuitError. This\n // will remain the case until `circuitBreakDuration` passes, after which the\n // service will be allowed to run again. If the service succeeds, the\n // circuit will close, otherwise it will remain open.\n halfOpenAfter: circuitBreakDuration,\n breaker: consecutiveBreaker,\n });\n\n let internalCircuitState: InternalCircuitState = getInternalCircuitState(\n circuitBreakerPolicy.state,\n );\n circuitBreakerPolicy.onStateChange((state) => {\n internalCircuitState = getInternalCircuitState(state);\n });\n\n circuitBreakerPolicy.onBreak(() => {\n availabilityStatus = AVAILABILITY_STATUSES.Unavailable;\n });\n const onBreak = circuitBreakerPolicy.onBreak.bind(circuitBreakerPolicy);\n\n const onDegradedEventEmitter =\n new CockatielEventEmitter<FailureReason<unknown> | void>();\n const onDegraded = onDegradedEventEmitter.addListener;\n\n const onAvailableEventEmitter = new CockatielEventEmitter<void>();\n const onAvailable = onAvailableEventEmitter.addListener;\n\n retryPolicy.onGiveUp((data) => {\n if (circuitBreakerPolicy.state === CircuitState.Closed) {\n availabilityStatus = AVAILABILITY_STATUSES.Degraded;\n onDegradedEventEmitter.emit(data);\n }\n });\n retryPolicy.onSuccess(({ duration }) => {\n if (circuitBreakerPolicy.state === CircuitState.Closed) {\n if (duration > degradedThreshold) {\n availabilityStatus = AVAILABILITY_STATUSES.Degraded;\n onDegradedEventEmitter.emit();\n } else if (availabilityStatus !== AVAILABILITY_STATUSES.Available) {\n availabilityStatus = AVAILABILITY_STATUSES.Available;\n onAvailableEventEmitter.emit();\n }\n }\n });\n\n // Every time the retry policy makes an attempt, it executes the circuit\n // breaker policy, which executes the service.\n //\n // Calling:\n //\n // policy.execute(() => {\n // // do what the service does\n // })\n //\n // is equivalent to:\n //\n // retryPolicy.execute(() => {\n // circuitBreakerPolicy.execute(() => {\n // // do what the service does\n // });\n // });\n //\n // So if the retry policy succeeds or fails, it is because the circuit breaker\n // policy succeeded or failed. And if there are any event listeners registered\n // on the retry policy, by the time they are called, the state of the circuit\n // breaker will have already changed.\n const policy = wrap(retryPolicy, circuitBreakerPolicy);\n\n const getRemainingCircuitOpenDuration = () => {\n if (internalCircuitState.state === CircuitState.Open) {\n return internalCircuitState.openedAt + circuitBreakDuration - Date.now();\n }\n return null;\n };\n\n const getCircuitState = () => {\n return circuitBreakerPolicy.state;\n };\n\n const reset = () => {\n // Set the state of the policy to \"isolated\" regardless of its current state\n const { dispose } = circuitBreakerPolicy.isolate();\n // Reset the state to \"closed\"\n dispose();\n\n // Reset the counter on the breaker as well\n consecutiveBreaker.success();\n\n // Re-initialize the availability status so that if the service is executed\n // successfully, onAvailable listeners will be called again\n availabilityStatus = AVAILABILITY_STATUSES.Unknown;\n };\n\n return {\n ...policy,\n circuitBreakerPolicy,\n circuitBreakDuration,\n getCircuitState,\n getRemainingCircuitOpenDuration,\n reset,\n retryPolicy,\n onBreak,\n onDegraded,\n onAvailable,\n onRetry,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"create-service-policy.mjs","sourceRoot":"","sources":["../src/create-service-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,YAAY,IAAI,qBAAqB,EACrC,kBAAkB,EAClB,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,SAAS,EACT,UAAU,EACV,KAAK,EACL,IAAI,EACL,kBAAkB;AAWnB,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,YAAY,EACZ,eAAe,EACf,kBAAkB,EAClB,SAAS,EACT,UAAU,EACX,CAAC;AAkHF;;;;GAIG;AACH,MAAM,qBAAqB,GAAG;IAC5B,SAAS,EAAE,WAAW;IACtB,QAAQ,EAAE,UAAU;IACpB,WAAW,EAAE,aAAa;IAC1B,OAAO,EAAE,SAAS;CACV,CAAC;AAUX;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAErC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,CAAC,CAAC,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC;AAE9E;;;GAGG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAE7D;;;GAGG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG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OAAO,EAAE,CAAC;QAEV,2CAA2C;QAC3C,kBAAkB,CAAC,OAAO,EAAE,CAAC;QAE7B,2EAA2E;QAC3E,2DAA2D;QAC3D,kBAAkB,GAAG,qBAAqB,CAAC,OAAO,CAAC;IACrD,CAAC,CAAC;IAEF,OAAO;QACL,GAAG,MAAM;QACT,oBAAoB;QACpB,oBAAoB;QACpB,eAAe;QACf,+BAA+B;QAC/B,KAAK;QACL,WAAW;QACX,OAAO;QACP,UAAU;QACV,WAAW;QACX,OAAO;KACR,CAAC;AACJ,CAAC","sourcesContent":["import {\n BrokenCircuitError,\n CircuitState,\n EventEmitter as CockatielEventEmitter,\n ConsecutiveBreaker,\n ExponentialBackoff,\n ConstantBackoff,\n circuitBreaker,\n handleAll,\n handleWhen,\n retry,\n wrap,\n} from 'cockatiel';\nimport type {\n CircuitBreakerPolicy,\n Event as CockatielEvent,\n FailureReason,\n IBackoffFactory,\n IPolicy,\n Policy,\n RetryPolicy,\n} from 'cockatiel';\n\nexport {\n BrokenCircuitError,\n CockatielEventEmitter,\n CircuitState,\n ConstantBackoff,\n ExponentialBackoff,\n handleAll,\n handleWhen,\n};\n\nexport type { CockatielEvent, FailureReason as CockatielFailureReason };\n\n/**\n * The options for `createServicePolicy`.\n */\nexport type CreateServicePolicyOptions = {\n /**\n * The backoff strategy to use. Mainly useful for testing so that a constant\n * backoff can be used when mocking timers. Defaults to an instance of\n * ExponentialBackoff.\n */\n backoff?: IBackoffFactory<unknown>;\n /**\n * The length of time (in milliseconds) to pause retries of the action after\n * the number of failures reaches `maxConsecutiveFailures`.\n */\n circuitBreakDuration?: number;\n /**\n * The length of time (in milliseconds) that governs when the service is\n * regarded as degraded (affecting when `onDegraded` is called).\n */\n degradedThreshold?: number;\n /**\n * The maximum number of times that the service is allowed to fail before\n * pausing further retries.\n */\n maxConsecutiveFailures?: number;\n /**\n * The maximum number of times that a failing service should be re-invoked\n * before giving up.\n */\n maxRetries?: number;\n /**\n * The policy used to control when the service should be retried based on\n * either the result of the service or an error that it throws. For instance,\n * you could use this to retry only certain errors. See `handleWhen` and\n * friends from Cockatiel for more.\n */\n retryFilterPolicy?: Policy;\n};\n\n/**\n * The service policy object.\n */\nexport type ServicePolicy = IPolicy & {\n /**\n * The Cockatiel circuit breaker policy that the service policy uses\n * internally.\n */\n circuitBreakerPolicy: CircuitBreakerPolicy;\n /**\n * The amount of time to pause requests to the service if the number of\n * maximum consecutive failures is reached.\n */\n circuitBreakDuration: number;\n /**\n * @returns The state of the underlying circuit.\n */\n getCircuitState: () => CircuitState;\n /**\n * If the circuit is open and ongoing requests are paused, returns the number\n * of milliseconds before the requests will be attempted again. If the circuit\n * is not open, returns null.\n */\n getRemainingCircuitOpenDuration: () => number | null;\n /**\n * Resets the internal circuit breaker policy (if it is open, it will now be\n * closed).\n */\n reset: () => void;\n /**\n * The Cockatiel retry policy that the service policy uses internally.\n */\n retryPolicy: RetryPolicy;\n /**\n * A function which is called when the number of times that the service fails\n * in a row meets the set maximum number of consecutive failures.\n */\n onBreak: CircuitBreakerPolicy['onBreak'];\n /**\n * A function which is called in two circumstances: 1) when the service\n * succeeds before the maximum number of consecutive failures is reached, but\n * takes more time than the `degradedThreshold` to run, or 2) if the service\n * never succeeds before the retry policy gives up and before the maximum\n * number of consecutive failures has been reached.\n */\n onDegraded: CockatielEvent<FailureReason<unknown> | void>;\n /**\n * A function which is called when the service succeeds for the first time,\n * or when the service fails enough times to cause the circuit to break and\n * then recovers.\n */\n onAvailable: CockatielEvent<void>;\n /**\n * A function which will be called by the retry policy each time the service\n * fails and the policy kicks off a timer to re-run the service. This is\n * primarily useful in tests where we are mocking timers.\n */\n onRetry: RetryPolicy['onRetry'];\n};\n\n/**\n * Parts of the circuit breaker's internal and external state as necessary in\n * order to compute the time remaining before the circuit will reopen.\n */\ntype InternalCircuitState =\n | {\n state: CircuitState.Open;\n openedAt: number;\n }\n | { state: Exclude<CircuitState, CircuitState.Open> };\n\n/**\n * Availability statuses that the service can be in.\n *\n * Used to keep track of whether the `onAvailable` event should be fired.\n */\nconst AVAILABILITY_STATUSES = {\n Available: 'available',\n Degraded: 'degraded',\n Unavailable: 'unavailable',\n Unknown: 'unknown',\n} as const;\n\n/**\n * Availability statuses that the service can be in.\n *\n * Used to keep track of whether the `onAvailable` event should be fired.\n */\ntype AvailabilityStatus =\n (typeof AVAILABILITY_STATUSES)[keyof typeof AVAILABILITY_STATUSES];\n\n/**\n * The maximum number of times that a failing service should be re-run before\n * giving up.\n */\nexport const DEFAULT_MAX_RETRIES = 3;\n\n/**\n * The maximum number of times that the service is allowed to fail before\n * pausing further retries. This is set to a value such that if given a\n * service that continually fails, the policy needs to be executed 3 times\n * before further retries are paused.\n */\nexport const DEFAULT_MAX_CONSECUTIVE_FAILURES = (1 + DEFAULT_MAX_RETRIES) * 3;\n\n/**\n * The default length of time (in milliseconds) to temporarily pause retries of\n * the service after enough consecutive failures.\n */\nexport const DEFAULT_CIRCUIT_BREAK_DURATION = 30 * 60 * 1000;\n\n/**\n * The default length of time (in milliseconds) that governs when the service is\n * regarded as degraded (affecting when `onDegraded` is called).\n */\nexport const DEFAULT_DEGRADED_THRESHOLD = 5_000;\n\nconst isServiceFailure = (error: unknown): boolean => {\n if (\n typeof error === 'object' &&\n error !== null &&\n 'httpStatus' in error &&\n typeof error.httpStatus === 'number'\n ) {\n return error.httpStatus >= 500;\n }\n\n // If the error is not an object, or doesn't have a numeric code property,\n // consider it a service failure (e.g., network errors, timeouts, etc.)\n return true;\n};\n\n/**\n * The circuit breaker policy inside of the Cockatiel library exposes some of\n * its state, but not all of it. Notably, the time that the circuit opened is\n * not publicly accessible. So we have to record this ourselves.\n *\n * This function therefore allows us to obtain the circuit breaker state that we\n * wish we could access.\n *\n * @param state - The public state of a circuit breaker policy.\n * @returns if the circuit is open, the state of the circuit breaker policy plus\n * the time that it opened, otherwise just the circuit state.\n */\nfunction getInternalCircuitState(state: CircuitState): InternalCircuitState {\n if (state === CircuitState.Open) {\n return { state, openedAt: Date.now() };\n }\n return { state };\n}\n\n/**\n * Constructs an object exposing an `execute` method which, given a function —\n * hereafter called the \"service\" — will retry that service with ever increasing\n * delays until it succeeds. If the policy detects too many consecutive\n * failures, it will block further retries until a designated time period has\n * passed; this particular behavior is primarily designed for services that wrap\n * API calls so as not to make needless HTTP requests when the API is down and\n * to be able to recover when the API comes back up. In addition, hooks allow\n * for responding to certain events, one of which can be used to detect when an\n * HTTP request is performing slowly.\n *\n * Internally, this function makes use of the retry and circuit breaker policies\n * from the [Cockatiel](https://www.npmjs.com/package/cockatiel) library; see\n * there for more.\n *\n * @param options - The options to this function. See\n * {@link CreateServicePolicyOptions}.\n * @returns The service policy.\n * @example\n * This function is designed to be used in the context of a service class like\n * this:\n * ``` ts\n * class Service {\n * constructor() {\n * this.#policy = createServicePolicy({\n * maxRetries: 3,\n * retryFilterPolicy: handleWhen((error) => {\n * return error.message.includes('oops');\n * }),\n * maxConsecutiveFailures: 3,\n * circuitBreakDuration: 5000,\n * degradedThreshold: 2000,\n * onBreak: () => {\n * console.log('Circuit broke');\n * },\n * onDegraded: () => {\n * console.log('Service is degraded');\n * },\n * });\n * }\n *\n * async fetch() {\n * return await this.#policy.execute(async () => {\n * const response = await fetch('https://some/url');\n * return await response.json();\n * });\n * }\n * }\n * ```\n */\nexport function createServicePolicy(\n options: CreateServicePolicyOptions = {},\n): ServicePolicy {\n const {\n maxRetries = DEFAULT_MAX_RETRIES,\n retryFilterPolicy = handleAll,\n maxConsecutiveFailures = DEFAULT_MAX_CONSECUTIVE_FAILURES,\n circuitBreakDuration = DEFAULT_CIRCUIT_BREAK_DURATION,\n degradedThreshold = DEFAULT_DEGRADED_THRESHOLD,\n backoff = new ExponentialBackoff(),\n } = options;\n\n let availabilityStatus: AvailabilityStatus = AVAILABILITY_STATUSES.Unknown;\n\n const retryPolicy = retry(retryFilterPolicy, {\n // Note that although the option here is called \"max attempts\", it's really\n // maximum number of *retries* (attempts past the initial attempt).\n maxAttempts: maxRetries,\n // Retries of the service will be executed following ever increasing delays,\n // determined by a backoff formula.\n backoff,\n });\n const onRetry = retryPolicy.onRetry.bind(retryPolicy);\n\n const consecutiveBreaker = new ConsecutiveBreaker(maxConsecutiveFailures);\n const circuitBreakerPolicy = circuitBreaker(handleWhen(isServiceFailure), {\n // While the circuit is open, any additional invocations of the service\n // passed to the policy (either via automatic retries or by manually\n // executing the policy again) will result in a BrokenCircuitError. This\n // will remain the case until `circuitBreakDuration` passes, after which the\n // service will be allowed to run again. If the service succeeds, the\n // circuit will close, otherwise it will remain open.\n halfOpenAfter: circuitBreakDuration,\n breaker: consecutiveBreaker,\n });\n\n let internalCircuitState: InternalCircuitState = getInternalCircuitState(\n circuitBreakerPolicy.state,\n );\n circuitBreakerPolicy.onStateChange((state) => {\n internalCircuitState = getInternalCircuitState(state);\n });\n\n circuitBreakerPolicy.onBreak(() => {\n availabilityStatus = AVAILABILITY_STATUSES.Unavailable;\n });\n const onBreak = circuitBreakerPolicy.onBreak.bind(circuitBreakerPolicy);\n\n const onDegradedEventEmitter =\n new CockatielEventEmitter<FailureReason<unknown> | void>();\n const onDegraded = onDegradedEventEmitter.addListener;\n\n const onAvailableEventEmitter = new CockatielEventEmitter<void>();\n const onAvailable = onAvailableEventEmitter.addListener;\n\n retryPolicy.onGiveUp((data) => {\n if (circuitBreakerPolicy.state === CircuitState.Closed) {\n availabilityStatus = AVAILABILITY_STATUSES.Degraded;\n onDegradedEventEmitter.emit(data);\n }\n });\n retryPolicy.onSuccess(({ duration }) => {\n if (circuitBreakerPolicy.state === CircuitState.Closed) {\n if (duration > degradedThreshold) {\n availabilityStatus = AVAILABILITY_STATUSES.Degraded;\n onDegradedEventEmitter.emit();\n } else if (availabilityStatus !== AVAILABILITY_STATUSES.Available) {\n availabilityStatus = AVAILABILITY_STATUSES.Available;\n onAvailableEventEmitter.emit();\n }\n }\n });\n\n // Every time the retry policy makes an attempt, it executes the circuit\n // breaker policy, which executes the service.\n //\n // Calling:\n //\n // policy.execute(() => {\n // // do what the service does\n // })\n //\n // is equivalent to:\n //\n // retryPolicy.execute(() => {\n // circuitBreakerPolicy.execute(() => {\n // // do what the service does\n // });\n // });\n //\n // So if the retry policy succeeds or fails, it is because the circuit breaker\n // policy succeeded or failed. And if there are any event listeners registered\n // on the retry policy, by the time they are called, the state of the circuit\n // breaker will have already changed.\n const policy = wrap(retryPolicy, circuitBreakerPolicy);\n\n const getRemainingCircuitOpenDuration = (): number | null => {\n if (internalCircuitState.state === CircuitState.Open) {\n return internalCircuitState.openedAt + circuitBreakDuration - Date.now();\n }\n return null;\n };\n\n const getCircuitState = (): CircuitState => {\n return circuitBreakerPolicy.state;\n };\n\n const reset = (): void => {\n // Set the state of the policy to \"isolated\" regardless of its current state\n const { dispose } = circuitBreakerPolicy.isolate();\n // Reset the state to \"closed\"\n dispose();\n\n // Reset the counter on the breaker as well\n consecutiveBreaker.success();\n\n // Re-initialize the availability status so that if the service is executed\n // successfully, onAvailable listeners will be called again\n availabilityStatus = AVAILABILITY_STATUSES.Unknown;\n };\n\n return {\n ...policy,\n circuitBreakerPolicy,\n circuitBreakDuration,\n getCircuitState,\n getRemainingCircuitOpenDuration,\n reset,\n retryPolicy,\n onBreak,\n onDegraded,\n onAvailable,\n onRetry,\n };\n}\n"]}
|
package/dist/siwe.cjs
CHANGED
|
@@ -21,18 +21,21 @@ function safeStripHexPrefix(str) {
|
|
|
21
21
|
/**
|
|
22
22
|
* This function converts a hex string to text if it's not a 32 byte hex string.
|
|
23
23
|
*
|
|
24
|
-
* @param
|
|
24
|
+
* @param hexValue - The hex string to convert to text
|
|
25
25
|
* @returns The text representation of the hex string
|
|
26
26
|
*/
|
|
27
|
-
function msgHexToText(
|
|
27
|
+
function msgHexToText(hexValue) {
|
|
28
28
|
try {
|
|
29
|
-
const stripped = safeStripHexPrefix(
|
|
29
|
+
const stripped = safeStripHexPrefix(hexValue);
|
|
30
|
+
// TODO: Use `@metamask/utils` version of this function to avoid Buffer
|
|
31
|
+
// usage here.
|
|
32
|
+
// eslint-disable-next-line no-restricted-globals
|
|
30
33
|
const buff = Buffer.from(stripped, 'hex');
|
|
31
|
-
return buff.length === 32 ?
|
|
34
|
+
return buff.length === 32 ? hexValue : buff.toString('utf8');
|
|
32
35
|
}
|
|
33
|
-
catch (
|
|
34
|
-
log(
|
|
35
|
-
return
|
|
36
|
+
catch (error) {
|
|
37
|
+
log(error);
|
|
38
|
+
return hexValue;
|
|
36
39
|
}
|
|
37
40
|
}
|
|
38
41
|
const DEFAULT_PORTS_BY_PROTOCOL = {
|
|
@@ -89,8 +92,8 @@ const isValidSIWEOrigin = (req) => {
|
|
|
89
92
|
}
|
|
90
93
|
return true;
|
|
91
94
|
}
|
|
92
|
-
catch (
|
|
93
|
-
log(
|
|
95
|
+
catch (error) {
|
|
96
|
+
log(error);
|
|
94
97
|
return false;
|
|
95
98
|
}
|
|
96
99
|
};
|
|
@@ -116,7 +119,7 @@ const detectSIWE = (msgParams) => {
|
|
|
116
119
|
parsedMessage,
|
|
117
120
|
};
|
|
118
121
|
}
|
|
119
|
-
catch
|
|
122
|
+
catch {
|
|
120
123
|
// ignore error, it's not a valid SIWE message
|
|
121
124
|
return {
|
|
122
125
|
isSIWEMessage: false,
|
package/dist/siwe.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"siwe.cjs","sourceRoot":"","sources":["../src/siwe.ts"],"names":[],"mappings":";;;AAAA,2CAA2C;AAC3C,uDAAsD;AAEtD,yCAA6D;AAE7D,MAAM,GAAG,GAAG,IAAA,2BAAkB,EAAC,sBAAa,EAAE,aAAa,CAAC,CAAC;AAE7D;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,GAAW;IACrC,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC5B,OAAO,GAAG,CAAC;IACb,CAAC;IACD,OAAO,IAAA,gBAAQ,EAAC,GAAG,CAAC,CAAC;AACvB,CAAC;AAED;;;;;GAKG;AACH,SAAS,YAAY,CAAC,
|
|
1
|
+
{"version":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AC,CAAC;AA5CW,QAAA,iBAAiB,qBA4C5B;AAaF;;;;;;;;;;GAUG;AACI,MAAM,UAAU,GAAG,CAAC,SAA2B,EAAe,EAAE;IACrE,IAAI,CAAC;QACH,MAAM,EAAE,IAAI,EAAE,GAAG,SAAS,CAAC;QAC3B,MAAM,OAAO,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;QACnC,MAAM,aAAa,GAAG,IAAI,2BAAa,CAAC,OAAO,CAAC,CAAC;QAEjD,OAAO;YACL,aAAa,EAAE,IAAI;YACnB,aAAa;SACd,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,8CAA8C;QAC9C,OAAO;YACL,aAAa,EAAE,KAAK;YACpB,aAAa,EAAE,IAAI;SACpB,CAAC;IACJ,CAAC;AACH,CAAC,CAAC;AAjBW,QAAA,UAAU,cAiBrB","sourcesContent":["import { remove0x } from '@metamask/utils';\nimport { ParsedMessage } from '@spruceid/siwe-parser';\n\nimport { projectLogger, createModuleLogger } from './logger';\n\nconst log = createModuleLogger(projectLogger, 'detect-siwe');\n\n/**\n * This function strips the hex prefix from a string if it has one.\n * If the input is not a string, return it unmodified.\n *\n * @param str - The string to check\n * @returns The string without the hex prefix\n */\nfunction safeStripHexPrefix(str: string): string {\n if (typeof str !== 'string') {\n return str;\n }\n return remove0x(str);\n}\n\n/**\n * This function converts a hex string to text if it's not a 32 byte hex string.\n *\n * @param hexValue - The hex string to convert to text\n * @returns The text representation of the hex string\n */\nfunction msgHexToText(hexValue: string): string {\n try {\n const stripped = safeStripHexPrefix(hexValue);\n // TODO: Use `@metamask/utils` version of this function to avoid Buffer\n // usage here.\n // eslint-disable-next-line no-restricted-globals\n const buff = Buffer.from(stripped, 'hex');\n return buff.length === 32 ? hexValue : buff.toString('utf8');\n } catch (error) {\n log(error);\n return hexValue;\n }\n}\n\n/**\n * @type WrappedSIWERequest\n *\n * Sign-In With Ethereum (SIWE)(EIP-4361) message with request metadata\n *\n * @property from - Subject account address\n * @property origin - The RFC 3986 originating authority of the signing request, including scheme\n * @property siwe - The data parsed from the message\n */\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface WrappedSIWERequest {\n from: string;\n origin: string;\n siwe: SIWEMessage;\n}\n\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\ninterface DomainParts {\n username?: string;\n hostname: string;\n port?: string;\n}\n\nconst DEFAULT_PORTS_BY_PROTOCOL = {\n 'http:': '80',\n 'https:': '443',\n} as Record<string, string>;\n\n/**\n * Parses parts from RFC 3986 authority from EIP-4361 `domain` field.\n *\n * @param domain - input string\n * @param originProtocol - implied protocol from origin\n * @returns parsed parts\n */\nexport const parseDomainParts = (\n domain: string,\n originProtocol: string,\n): DomainParts => {\n if (domain.match(/^[^/:]*:\\/\\//u)) {\n return new URL(domain);\n }\n return new URL(`${originProtocol}//${domain}`);\n};\n\n/**\n * Validates origin of a Sign-In With Ethereum (SIWE)(EIP-4361) request.\n * As per spec:\n * hostname must match.\n * port and username must match iff specified.\n * Protocol binding and full same-origin are currently not performed.\n *\n * @param req - Signature request\n * @returns true if origin matches domain; false otherwise\n */\nexport const isValidSIWEOrigin = (req: WrappedSIWERequest): boolean => {\n try {\n const { origin, siwe } = req;\n\n // origin = scheme://[user[:password]@]domain[:port]\n // origin is supplied by environment and must match domain claim in message\n if (!origin || !siwe?.parsedMessage?.domain) {\n return false;\n }\n\n const originParts = new URL(origin);\n const domainParts = parseDomainParts(\n siwe.parsedMessage.domain,\n originParts.protocol,\n );\n\n if (\n domainParts.hostname.localeCompare(originParts.hostname, undefined, {\n sensitivity: 'accent',\n }) !== 0\n ) {\n return false;\n }\n\n if (domainParts.port !== '' && domainParts.port !== originParts.port) {\n // If origin port is not specified, protocol default is implied\n return (\n originParts.port === '' &&\n domainParts.port === DEFAULT_PORTS_BY_PROTOCOL[originParts.protocol]\n );\n }\n\n if (\n domainParts.username !== '' &&\n domainParts.username !== originParts.username\n ) {\n return false;\n }\n\n return true;\n } catch (error) {\n log(error);\n return false;\n }\n};\n\n/**\n * A locally defined object used to provide data to identify a Sign-In With Ethereum (SIWE)(EIP-4361) message and provide the parsed message\n *\n * @typedef SIWEMessage\n * @param {boolean} isSIWEMessage - Does the intercepted message conform to the SIWE specification?\n * @param {ParsedMessage} parsedMessage - The data parsed out of the message\n */\nexport type SIWEMessage =\n | { isSIWEMessage: true; parsedMessage: ParsedMessage }\n | { isSIWEMessage: false; parsedMessage: null };\n\n/**\n * This function intercepts a sign message, detects if it's a\n * Sign-In With Ethereum (SIWE)(EIP-4361) message, and returns an object with\n * relevant SIWE data.\n *\n * {@see {@link https://eips.ethereum.org/EIPS/eip-4361}}\n *\n * @param msgParams - The params of the message to sign\n * @param msgParams.data - The data of the message to sign\n * @returns An object with the relevant SIWE data\n */\nexport const detectSIWE = (msgParams: { data: string }): SIWEMessage => {\n try {\n const { data } = msgParams;\n const message = msgHexToText(data);\n const parsedMessage = new ParsedMessage(message);\n\n return {\n isSIWEMessage: true,\n parsedMessage,\n };\n } catch {\n // ignore error, it's not a valid SIWE message\n return {\n isSIWEMessage: false,\n parsedMessage: null,\n };\n }\n};\n"]}
|
package/dist/siwe.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"siwe.d.cts","sourceRoot":"","sources":["../src/siwe.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,8BAA8B;
|
|
1
|
+
{"version":3,"file":"siwe.d.cts","sourceRoot":"","sources":["../src/siwe.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,8BAA8B;AAwCtD;;;;;;;;GAQG;AAIH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,WAAW,CAAC;CACnB;AAKD,UAAU,WAAW;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAOD;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,WACnB,MAAM,kBACE,MAAM,KACrB,WAKF,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,QAAS,kBAAkB,KAAG,OA4C3D,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,GACnB;IAAE,aAAa,EAAE,IAAI,CAAC;IAAC,aAAa,EAAE,aAAa,CAAA;CAAE,GACrD;IAAE,aAAa,EAAE,KAAK,CAAC;IAAC,aAAa,EAAE,IAAI,CAAA;CAAE,CAAC;AAElD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,UAAU,cAAe;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,KAAG,WAiBxD,CAAC"}
|
package/dist/siwe.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"siwe.d.mts","sourceRoot":"","sources":["../src/siwe.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,8BAA8B;
|
|
1
|
+
{"version":3,"file":"siwe.d.mts","sourceRoot":"","sources":["../src/siwe.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,8BAA8B;AAwCtD;;;;;;;;GAQG;AAIH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,WAAW,CAAC;CACnB;AAKD,UAAU,WAAW;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAOD;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,WACnB,MAAM,kBACE,MAAM,KACrB,WAKF,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,QAAS,kBAAkB,KAAG,OA4C3D,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,GACnB;IAAE,aAAa,EAAE,IAAI,CAAC;IAAC,aAAa,EAAE,aAAa,CAAA;CAAE,GACrD;IAAE,aAAa,EAAE,KAAK,CAAC;IAAC,aAAa,EAAE,IAAI,CAAA;CAAE,CAAC;AAElD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,UAAU,cAAe;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,KAAG,WAiBxD,CAAC"}
|
package/dist/siwe.mjs
CHANGED
|
@@ -18,18 +18,21 @@ function safeStripHexPrefix(str) {
|
|
|
18
18
|
/**
|
|
19
19
|
* This function converts a hex string to text if it's not a 32 byte hex string.
|
|
20
20
|
*
|
|
21
|
-
* @param
|
|
21
|
+
* @param hexValue - The hex string to convert to text
|
|
22
22
|
* @returns The text representation of the hex string
|
|
23
23
|
*/
|
|
24
|
-
function msgHexToText(
|
|
24
|
+
function msgHexToText(hexValue) {
|
|
25
25
|
try {
|
|
26
|
-
const stripped = safeStripHexPrefix(
|
|
26
|
+
const stripped = safeStripHexPrefix(hexValue);
|
|
27
|
+
// TODO: Use `@metamask/utils` version of this function to avoid Buffer
|
|
28
|
+
// usage here.
|
|
29
|
+
// eslint-disable-next-line no-restricted-globals
|
|
27
30
|
const buff = Buffer.from(stripped, 'hex');
|
|
28
|
-
return buff.length === 32 ?
|
|
31
|
+
return buff.length === 32 ? hexValue : buff.toString('utf8');
|
|
29
32
|
}
|
|
30
|
-
catch (
|
|
31
|
-
log(
|
|
32
|
-
return
|
|
33
|
+
catch (error) {
|
|
34
|
+
log(error);
|
|
35
|
+
return hexValue;
|
|
33
36
|
}
|
|
34
37
|
}
|
|
35
38
|
const DEFAULT_PORTS_BY_PROTOCOL = {
|
|
@@ -85,8 +88,8 @@ export const isValidSIWEOrigin = (req) => {
|
|
|
85
88
|
}
|
|
86
89
|
return true;
|
|
87
90
|
}
|
|
88
|
-
catch (
|
|
89
|
-
log(
|
|
91
|
+
catch (error) {
|
|
92
|
+
log(error);
|
|
90
93
|
return false;
|
|
91
94
|
}
|
|
92
95
|
};
|
|
@@ -111,7 +114,7 @@ export const detectSIWE = (msgParams) => {
|
|
|
111
114
|
parsedMessage,
|
|
112
115
|
};
|
|
113
116
|
}
|
|
114
|
-
catch
|
|
117
|
+
catch {
|
|
115
118
|
// ignore error, it's not a valid SIWE message
|
|
116
119
|
return {
|
|
117
120
|
isSIWEMessage: false,
|
package/dist/siwe.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"siwe.mjs","sourceRoot":"","sources":["../src/siwe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,wBAAwB;AAC3C,OAAO,EAAE,aAAa,EAAE,8BAA8B;AAEtD,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,qBAAiB;AAE7D,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;AAE7D;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,GAAW;IACrC,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC5B,OAAO,GAAG,CAAC;IACb,CAAC;IACD,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC;AACvB,CAAC;AAED;;;;;GAKG;AACH,SAAS,YAAY,CAAC,
|
|
1
|
+
{"version":3,"file":"siwe.mjs","sourceRoot":"","sources":["../src/siwe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,wBAAwB;AAC3C,OAAO,EAAE,aAAa,EAAE,8BAA8B;AAEtD,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,qBAAiB;AAE7D,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;AAE7D;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,GAAW;IACrC,IAAI,OAAO,GAAG,KAAK,QA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;YACL,aAAa,EAAE,IAAI;YACnB,aAAa;SACd,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,8CAA8C;QAC9C,OAAO;YACL,aAAa,EAAE,KAAK;YACpB,aAAa,EAAE,IAAI;SACpB,CAAC;IACJ,CAAC;AACH,CAAC,CAAC","sourcesContent":["import { remove0x } from '@metamask/utils';\nimport { ParsedMessage } from '@spruceid/siwe-parser';\n\nimport { projectLogger, createModuleLogger } from './logger';\n\nconst log = createModuleLogger(projectLogger, 'detect-siwe');\n\n/**\n * This function strips the hex prefix from a string if it has one.\n * If the input is not a string, return it unmodified.\n *\n * @param str - The string to check\n * @returns The string without the hex prefix\n */\nfunction safeStripHexPrefix(str: string): string {\n if (typeof str !== 'string') {\n return str;\n }\n return remove0x(str);\n}\n\n/**\n * This function converts a hex string to text if it's not a 32 byte hex string.\n *\n * @param hexValue - The hex string to convert to text\n * @returns The text representation of the hex string\n */\nfunction msgHexToText(hexValue: string): string {\n try {\n const stripped = safeStripHexPrefix(hexValue);\n // TODO: Use `@metamask/utils` version of this function to avoid Buffer\n // usage here.\n // eslint-disable-next-line no-restricted-globals\n const buff = Buffer.from(stripped, 'hex');\n return buff.length === 32 ? hexValue : buff.toString('utf8');\n } catch (error) {\n log(error);\n return hexValue;\n }\n}\n\n/**\n * @type WrappedSIWERequest\n *\n * Sign-In With Ethereum (SIWE)(EIP-4361) message with request metadata\n *\n * @property from - Subject account address\n * @property origin - The RFC 3986 originating authority of the signing request, including scheme\n * @property siwe - The data parsed from the message\n */\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface WrappedSIWERequest {\n from: string;\n origin: string;\n siwe: SIWEMessage;\n}\n\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\ninterface DomainParts {\n username?: string;\n hostname: string;\n port?: string;\n}\n\nconst DEFAULT_PORTS_BY_PROTOCOL = {\n 'http:': '80',\n 'https:': '443',\n} as Record<string, string>;\n\n/**\n * Parses parts from RFC 3986 authority from EIP-4361 `domain` field.\n *\n * @param domain - input string\n * @param originProtocol - implied protocol from origin\n * @returns parsed parts\n */\nexport const parseDomainParts = (\n domain: string,\n originProtocol: string,\n): DomainParts => {\n if (domain.match(/^[^/:]*:\\/\\//u)) {\n return new URL(domain);\n }\n return new URL(`${originProtocol}//${domain}`);\n};\n\n/**\n * Validates origin of a Sign-In With Ethereum (SIWE)(EIP-4361) request.\n * As per spec:\n * hostname must match.\n * port and username must match iff specified.\n * Protocol binding and full same-origin are currently not performed.\n *\n * @param req - Signature request\n * @returns true if origin matches domain; false otherwise\n */\nexport const isValidSIWEOrigin = (req: WrappedSIWERequest): boolean => {\n try {\n const { origin, siwe } = req;\n\n // origin = scheme://[user[:password]@]domain[:port]\n // origin is supplied by environment and must match domain claim in message\n if (!origin || !siwe?.parsedMessage?.domain) {\n return false;\n }\n\n const originParts = new URL(origin);\n const domainParts = parseDomainParts(\n siwe.parsedMessage.domain,\n originParts.protocol,\n );\n\n if (\n domainParts.hostname.localeCompare(originParts.hostname, undefined, {\n sensitivity: 'accent',\n }) !== 0\n ) {\n return false;\n }\n\n if (domainParts.port !== '' && domainParts.port !== originParts.port) {\n // If origin port is not specified, protocol default is implied\n return (\n originParts.port === '' &&\n domainParts.port === DEFAULT_PORTS_BY_PROTOCOL[originParts.protocol]\n );\n }\n\n if (\n domainParts.username !== '' &&\n domainParts.username !== originParts.username\n ) {\n return false;\n }\n\n return true;\n } catch (error) {\n log(error);\n return false;\n }\n};\n\n/**\n * A locally defined object used to provide data to identify a Sign-In With Ethereum (SIWE)(EIP-4361) message and provide the parsed message\n *\n * @typedef SIWEMessage\n * @param {boolean} isSIWEMessage - Does the intercepted message conform to the SIWE specification?\n * @param {ParsedMessage} parsedMessage - The data parsed out of the message\n */\nexport type SIWEMessage =\n | { isSIWEMessage: true; parsedMessage: ParsedMessage }\n | { isSIWEMessage: false; parsedMessage: null };\n\n/**\n * This function intercepts a sign message, detects if it's a\n * Sign-In With Ethereum (SIWE)(EIP-4361) message, and returns an object with\n * relevant SIWE data.\n *\n * {@see {@link https://eips.ethereum.org/EIPS/eip-4361}}\n *\n * @param msgParams - The params of the message to sign\n * @param msgParams.data - The data of the message to sign\n * @returns An object with the relevant SIWE data\n */\nexport const detectSIWE = (msgParams: { data: string }): SIWEMessage => {\n try {\n const { data } = msgParams;\n const message = msgHexToText(data);\n const parsedMessage = new ParsedMessage(message);\n\n return {\n isSIWEMessage: true,\n parsedMessage,\n };\n } catch {\n // ignore error, it's not a valid SIWE message\n return {\n isSIWEMessage: false,\n parsedMessage: null,\n };\n }\n};\n"]}
|
package/dist/types.cjs
CHANGED
|
@@ -112,6 +112,7 @@ exports.ChainId = {
|
|
|
112
112
|
[BuiltInNetworkName.PolygonMainnet]: '0x89', // toHex(137)
|
|
113
113
|
[BuiltInNetworkName.SeiMainnet]: '0x531', // toHex(1329)
|
|
114
114
|
};
|
|
115
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
115
116
|
var NetworksTicker;
|
|
116
117
|
(function (NetworksTicker) {
|
|
117
118
|
NetworksTicker["mainnet"] = "ETH";
|
|
@@ -140,6 +141,7 @@ var NetworksTicker;
|
|
|
140
141
|
NetworksTicker["sei-mainnet"] = "SEI";
|
|
141
142
|
NetworksTicker["rpc"] = "";
|
|
142
143
|
})(NetworksTicker || (exports.NetworksTicker = NetworksTicker = {}));
|
|
144
|
+
/* eslint-enable @typescript-eslint/naming-convention */
|
|
143
145
|
exports.BlockExplorerUrl = {
|
|
144
146
|
[BuiltInNetworkName.Mainnet]: 'https://etherscan.io',
|
|
145
147
|
[BuiltInNetworkName.Goerli]: 'https://goerli.etherscan.io',
|
package/dist/types.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,Q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E,qBAAqB;IACtD,CAAC,kBAAkB,CAAC,eAAe,CAAC,EAAE,iCAAiC;IACvE,CAAC,kBAAkB,CAAC,cAAc,CAAC,EAAE,yBAAyB;IAC9D,CAAC,kBAAkB,CAAC,UAAU,CAAC,EAAE,sBAAsB;CACF,CAAC;AAI3C,QAAA,eAAe,GAAG;IAC7B,CAAC,kBAAkB,CAAC,OAAO,CAAC,EAAE,kBAAkB;IAChD,CAAC,kBAAkB,CAAC,MAAM,CAAC,EAAE,QAAQ;IACrC,CAAC,kBAAkB,CAAC,OAAO,CAAC,EAAE,SAAS;IACvC,CAAC,kBAAkB,CAAC,WAAW,CAAC,EAAE,cAAc;IAChD,CAAC,kBAAkB,CAAC,YAAY,CAAC,EAAE,eAAe;IAClD,CAAC,kBAAkB,CAAC,YAAY,CAAC,EAAE,OAAO;IAC1C;;OAEG;IACH,CAAC,kBAAkB,CAAC,cAAc,CAAC,EAAE,cAAc;IACnD,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,EAAE,iBAAiB;IACxD,CAAC,kBAAkB,CAAC,YAAY,CAAC,EAAE,eAAe;IAClD,CAAC,kBAAkB,CAAC,WAAW,CAAC,EAAE,cAAc;IAChD,CAAC,kBAAkB,CAAC,WAAW,CAAC,EAAE,cAAc;IAChD,CAAC,kBAAkB,CAAC,UAAU,CAAC,EAAE,aAAa;IAC9C,CAAC,kBAAkB,CAAC,eAAe,CAAC,EAAE,kBAAkB;IACxD,CAAC,kBAAkB,CAAC,cAAc,CAAC,EAAE,iBAAiB;IACtD,CAAC,kBAAkB,CAAC,UAAU,CAAC,EAAE,aAAa;CACO,CAAC","sourcesContent":["/**\n * The names of built-in Infura networks\n */\nexport const InfuraNetworkType = {\n mainnet: 'mainnet',\n goerli: 'goerli',\n sepolia: 'sepolia',\n 'linea-goerli': 'linea-goerli',\n 'linea-sepolia': 'linea-sepolia',\n 'linea-mainnet': 'linea-mainnet',\n 'base-mainnet': 'base-mainnet',\n 'arbitrum-mainnet': 'arbitrum-mainnet',\n 'bsc-mainnet': 'bsc-mainnet',\n 'optimism-mainnet': 'optimism-mainnet',\n 'polygon-mainnet': 'polygon-mainnet',\n 'sei-mainnet': 'sei-mainnet',\n} as const;\n\nexport type InfuraNetworkType =\n (typeof InfuraNetworkType)[keyof typeof InfuraNetworkType];\n\n/**\n * Custom network types that are not part of Infura.\n */\nexport const CustomNetworkType = {\n /**\n * @deprecated `megaeth-testnet` is migrated to `megaeth-testnet-v2`.\n */\n 'megaeth-testnet': 'megaeth-testnet',\n 'megaeth-testnet-v2': 'megaeth-testnet-v2',\n 'monad-testnet': 'monad-testnet',\n} as const;\nexport type CustomNetworkType =\n (typeof CustomNetworkType)[keyof typeof CustomNetworkType];\n\n/**\n * Network types supported including both Infura networks and other networks.\n */\nexport type BuiltInNetworkType = InfuraNetworkType | CustomNetworkType;\n\n/**\n * The \"network type\"; either the name of a built-in network, or \"rpc\" for custom networks.\n */\nexport const NetworkType = {\n ...InfuraNetworkType,\n ...CustomNetworkType,\n rpc: 'rpc',\n} as const;\n\nexport type NetworkType = (typeof NetworkType)[keyof typeof NetworkType];\n\n/**\n * A helper to determine whether a given input is NetworkType.\n *\n * @param val - the value to check whether it is NetworkType or not.\n * @returns boolean indicating whether or not the argument is NetworkType.\n */\nexport function isNetworkType(val: string): val is NetworkType {\n return Object.values(NetworkType).includes(val as NetworkType);\n}\n\n/**\n * A type guard to determine whether the input is an InfuraNetworkType.\n *\n * @param value - The value to check.\n * @returns True if the given value is within the InfuraNetworkType enum,\n * false otherwise.\n */\nexport function isInfuraNetworkType(\n value: unknown,\n): value is InfuraNetworkType {\n const infuraNetworkTypes: unknown[] = Object.keys(InfuraNetworkType);\n return infuraNetworkTypes.includes(value);\n}\n\n/**\n * Names of networks built into the wallet.\n *\n * This includes both Infura and non-Infura networks.\n */\nexport enum BuiltInNetworkName {\n Mainnet = 'mainnet',\n Goerli = 'goerli',\n Sepolia = 'sepolia',\n LineaGoerli = 'linea-goerli',\n LineaSepolia = 'linea-sepolia',\n LineaMainnet = 'linea-mainnet',\n Aurora = 'aurora',\n /**\n * @deprecated `MegaETHTestnet` is migrated to `MegaETHTestnetV2`.\n */\n MegaETHTestnet = 'megaeth-testnet',\n MegaETHTestnetV2 = 'megaeth-testnet-v2',\n MonadTestnet = 'monad-testnet',\n BaseMainnet = 'base-mainnet',\n ArbitrumOne = 'arbitrum-mainnet',\n BscMainnet = 'bsc-mainnet',\n OptimismMainnet = 'optimism-mainnet',\n PolygonMainnet = 'polygon-mainnet',\n SeiMainnet = 'sei-mainnet',\n}\n\n/**\n * Decimal string chain IDs of built-in networks, by name.\n *\n * `toHex` not invoked to avoid cyclic dependency\n */\nexport const ChainId = {\n [BuiltInNetworkName.Mainnet]: '0x1', // toHex(1)\n [BuiltInNetworkName.Goerli]: '0x5', // toHex(5)\n [BuiltInNetworkName.Sepolia]: '0xaa36a7', // toHex(11155111)\n [BuiltInNetworkName.Aurora]: '0x4e454152', // toHex(1313161554)\n [BuiltInNetworkName.LineaGoerli]: '0xe704', // toHex(59140)\n [BuiltInNetworkName.LineaSepolia]: '0xe705', // toHex(59141)\n [BuiltInNetworkName.LineaMainnet]: '0xe708', // toHex(59144)\n /**\n * @deprecated `MegaETHTestnet` is migrated to `MegaETHTestnetV2`.\n */\n [BuiltInNetworkName.MegaETHTestnet]: '0x18c6', // toHex(6342)\n [BuiltInNetworkName.MegaETHTestnetV2]: '0x18c7', // toHex(6343)\n [BuiltInNetworkName.MonadTestnet]: '0x279f', // toHex(10143)\n [BuiltInNetworkName.BaseMainnet]: '0x2105', // toHex(8453)\n [BuiltInNetworkName.ArbitrumOne]: '0xa4b1', // toHex(42161)\n [BuiltInNetworkName.BscMainnet]: '0x38', // toHex(56)\n [BuiltInNetworkName.OptimismMainnet]: '0xa', // toHex(10)\n [BuiltInNetworkName.PolygonMainnet]: '0x89', // toHex(137)\n [BuiltInNetworkName.SeiMainnet]: '0x531', // toHex(1329)\n} as const;\nexport type ChainId = (typeof ChainId)[keyof typeof ChainId];\n\nexport enum NetworksTicker {\n mainnet = 'ETH',\n goerli = 'GoerliETH',\n sepolia = 'SepoliaETH',\n 'linea-goerli' = 'LineaETH',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'linea-sepolia' = 'LineaETH',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'linea-mainnet' = 'ETH',\n /**\n * @deprecated `megaeth-testnet` is migrated to `megaeth-testnet-v2`.\n */\n 'megaeth-testnet' = 'MegaETH',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'megaeth-testnet-v2' = 'MegaETH',\n 'monad-testnet' = 'MON',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'base-mainnet' = 'ETH',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'arbitrum-mainnet' = 'ETH',\n 'bsc-mainnet' = 'BNB',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'optimism-mainnet' = 'ETH',\n 'polygon-mainnet' = 'POL',\n 'sei-mainnet' = 'SEI',\n rpc = '',\n}\n\nexport const BlockExplorerUrl = {\n [BuiltInNetworkName.Mainnet]: 'https://etherscan.io',\n [BuiltInNetworkName.Goerli]: 'https://goerli.etherscan.io',\n [BuiltInNetworkName.Sepolia]: 'https://sepolia.etherscan.io',\n [BuiltInNetworkName.LineaGoerli]: 'https://goerli.lineascan.build',\n [BuiltInNetworkName.LineaSepolia]: 'https://sepolia.lineascan.build',\n [BuiltInNetworkName.LineaMainnet]: 'https://lineascan.build',\n /**\n * @deprecated `MegaETHTestnet` is migrated to `MegaETHTestnetV2`.\n */\n [BuiltInNetworkName.MegaETHTestnet]: 'https://megaexplorer.xyz',\n [BuiltInNetworkName.MegaETHTestnetV2]:\n 'https://megaeth-testnet-v2.blockscout.com',\n [BuiltInNetworkName.MonadTestnet]: 'https://testnet.monadexplorer.com',\n [BuiltInNetworkName.BaseMainnet]: 'https://basescan.org',\n [BuiltInNetworkName.ArbitrumOne]: 'https://arbiscan.io',\n [BuiltInNetworkName.BscMainnet]: 'https://bscscan.com',\n [BuiltInNetworkName.OptimismMainnet]: 'https://optimistic.etherscan.io',\n [BuiltInNetworkName.PolygonMainnet]: 'https://polygonscan.com',\n [BuiltInNetworkName.SeiMainnet]: 'https://seitrace.com',\n} as const satisfies Record<BuiltInNetworkType, string>;\nexport type BlockExplorerUrl =\n (typeof BlockExplorerUrl)[keyof typeof BlockExplorerUrl];\n\nexport const NetworkNickname = {\n [BuiltInNetworkName.Mainnet]: 'Ethereum Mainnet',\n [BuiltInNetworkName.Goerli]: 'Goerli',\n [BuiltInNetworkName.Sepolia]: 'Sepolia',\n [BuiltInNetworkName.LineaGoerli]: 'Linea Goerli',\n [BuiltInNetworkName.LineaSepolia]: 'Linea Sepolia',\n [BuiltInNetworkName.LineaMainnet]: 'Linea',\n /**\n * @deprecated `MegaETHTestnet` is migrated to `MegaETHTestnetV2`.\n */\n [BuiltInNetworkName.MegaETHTestnet]: 'Mega Testnet',\n [BuiltInNetworkName.MegaETHTestnetV2]: 'MegaETH Testnet',\n [BuiltInNetworkName.MonadTestnet]: 'Monad Testnet',\n [BuiltInNetworkName.BaseMainnet]: 'Base Mainnet',\n [BuiltInNetworkName.ArbitrumOne]: 'Arbitrum One',\n [BuiltInNetworkName.BscMainnet]: 'BSC Mainnet',\n [BuiltInNetworkName.OptimismMainnet]: 'Optimism Mainnet',\n [BuiltInNetworkName.PolygonMainnet]: 'Polygon Mainnet',\n [BuiltInNetworkName.SeiMainnet]: 'Sei Mainnet',\n} as const satisfies Record<BuiltInNetworkType, string>;\nexport type NetworkNickname =\n (typeof NetworkNickname)[keyof typeof NetworkNickname];\n\n/**\n * Makes a selection of keys in a Record optional.\n *\n * @template Type - The Record that you want to operate on.\n * @template Key - The union of keys you want to make optional.\n */\n// TODO: Move to @metamask/utils\nexport type Partialize<Type, Key extends keyof Type> = Omit<Type, Key> &\n Partial<Pick<Type, Key>>;\n\n/** A context in which to execute a trace, in order to generate nested timings. */\nexport type TraceContext = unknown;\n\n/** Request to trace an operation. */\nexport type TraceRequest = {\n /** Additional data to include in the trace. */\n data?: Record<string, number | string | boolean>;\n\n /** Name of the operation. */\n name: string;\n\n /**\n * Unique identifier for the trace.\n * Required if starting a trace and not providing a callback.\n */\n id?: string;\n\n /** Trace context in which to execute the operation. */\n parentContext?: TraceContext;\n\n /** Additional tags to include in the trace to filter results. */\n tags?: Record<string, number | string | boolean>;\n};\n\n/** Callback that traces the performance of an operation. */\nexport type TraceCallback = <ReturnType>(\n /** Request to trace the performance of an operation. */\n request: TraceRequest,\n\n /**\n * Callback to trace.\n * Thrown errors will not be caught, but the trace will still be recorded.\n *\n * @param context - The context in which the operation is running.\n */\n fn?: (context?: TraceContext) => ReturnType,\n) => Promise<ReturnType>;\n"]}
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,QAAA,iBAAiB,GAAG;IAC/B,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;IAClB,cAAc,EAAE,cAAc;IAC9B,eAAe,EAAE,eAAe;IAChC,eAAe,EAAE,eAAe;IAChC,cAAc,EAAE,cAAc;IAC9B,kBAAkB,EAAE,kBAAkB;IACtC,aAAa,EAAE,aAAa;IAC5B,kBAAkB,EAAE,kBAAkB;IACtC,iBAAiB,EAAE,iBAAiB;IACpC,aAAa,EAAE,aAAa;CACpB,CAAC;AAKX;;GAEG;AACU,QAAA,iBAAiB,GAAG;IAC/B;;OAEG;IACH,iBAAiB,EAAE,iBAAiB;IACpC,oBAAoB,EAAE,oBAAoB;IAC1C,eAAe,EAAE,eAAe;CACxB,CAAC;AASX;;GAEG;AACU,QAAA,WAAW,GAAG;IACzB,GAAG,yBAAiB;IACpB,GAAG,yBAAiB;IACpB,GAAG,EAAE,KAAK;CACF,CAAC;AAIX;;;;;GAKG;AACH,SAAgB,aAAa,CAAC,GAAW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AAC,EAAE,iBAAiB;IACxD,CAAC,kBAAkB,CAAC,YAAY,CAAC,EAAE,eAAe;IAClD,CAAC,kBAAkB,CAAC,WAAW,CAAC,EAAE,cAAc;IAChD,CAAC,kBAAkB,CAAC,WAAW,CAAC,EAAE,cAAc;IAChD,CAAC,kBAAkB,CAAC,UAAU,CAAC,EAAE,aAAa;IAC9C,CAAC,kBAAkB,CAAC,eAAe,CAAC,EAAE,kBAAkB;IACxD,CAAC,kBAAkB,CAAC,cAAc,CAAC,EAAE,iBAAiB;IACtD,CAAC,kBAAkB,CAAC,UAAU,CAAC,EAAE,aAAa;CACO,CAAC","sourcesContent":["/**\n * The names of built-in Infura networks\n */\nexport const InfuraNetworkType = {\n mainnet: 'mainnet',\n goerli: 'goerli',\n sepolia: 'sepolia',\n 'linea-goerli': 'linea-goerli',\n 'linea-sepolia': 'linea-sepolia',\n 'linea-mainnet': 'linea-mainnet',\n 'base-mainnet': 'base-mainnet',\n 'arbitrum-mainnet': 'arbitrum-mainnet',\n 'bsc-mainnet': 'bsc-mainnet',\n 'optimism-mainnet': 'optimism-mainnet',\n 'polygon-mainnet': 'polygon-mainnet',\n 'sei-mainnet': 'sei-mainnet',\n} as const;\n\nexport type InfuraNetworkType =\n (typeof InfuraNetworkType)[keyof typeof InfuraNetworkType];\n\n/**\n * Custom network types that are not part of Infura.\n */\nexport const CustomNetworkType = {\n /**\n * @deprecated `megaeth-testnet` is migrated to `megaeth-testnet-v2`.\n */\n 'megaeth-testnet': 'megaeth-testnet',\n 'megaeth-testnet-v2': 'megaeth-testnet-v2',\n 'monad-testnet': 'monad-testnet',\n} as const;\nexport type CustomNetworkType =\n (typeof CustomNetworkType)[keyof typeof CustomNetworkType];\n\n/**\n * Network types supported including both Infura networks and other networks.\n */\nexport type BuiltInNetworkType = InfuraNetworkType | CustomNetworkType;\n\n/**\n * The \"network type\"; either the name of a built-in network, or \"rpc\" for custom networks.\n */\nexport const NetworkType = {\n ...InfuraNetworkType,\n ...CustomNetworkType,\n rpc: 'rpc',\n} as const;\n\nexport type NetworkType = (typeof NetworkType)[keyof typeof NetworkType];\n\n/**\n * A helper to determine whether a given input is NetworkType.\n *\n * @param val - the value to check whether it is NetworkType or not.\n * @returns boolean indicating whether or not the argument is NetworkType.\n */\nexport function isNetworkType(val: string): val is NetworkType {\n return Object.values(NetworkType).includes(val as NetworkType);\n}\n\n/**\n * A type guard to determine whether the input is an InfuraNetworkType.\n *\n * @param value - The value to check.\n * @returns True if the given value is within the InfuraNetworkType enum,\n * false otherwise.\n */\nexport function isInfuraNetworkType(\n value: unknown,\n): value is InfuraNetworkType {\n const infuraNetworkTypes: unknown[] = Object.keys(InfuraNetworkType);\n return infuraNetworkTypes.includes(value);\n}\n\n/**\n * Names of networks built into the wallet.\n *\n * This includes both Infura and non-Infura networks.\n */\nexport enum BuiltInNetworkName {\n Mainnet = 'mainnet',\n Goerli = 'goerli',\n Sepolia = 'sepolia',\n LineaGoerli = 'linea-goerli',\n LineaSepolia = 'linea-sepolia',\n LineaMainnet = 'linea-mainnet',\n Aurora = 'aurora',\n /**\n * @deprecated `MegaETHTestnet` is migrated to `MegaETHTestnetV2`.\n */\n MegaETHTestnet = 'megaeth-testnet',\n MegaETHTestnetV2 = 'megaeth-testnet-v2',\n MonadTestnet = 'monad-testnet',\n BaseMainnet = 'base-mainnet',\n ArbitrumOne = 'arbitrum-mainnet',\n BscMainnet = 'bsc-mainnet',\n OptimismMainnet = 'optimism-mainnet',\n PolygonMainnet = 'polygon-mainnet',\n SeiMainnet = 'sei-mainnet',\n}\n\n/**\n * Decimal string chain IDs of built-in networks, by name.\n *\n * `toHex` not invoked to avoid cyclic dependency\n */\nexport const ChainId = {\n [BuiltInNetworkName.Mainnet]: '0x1', // toHex(1)\n [BuiltInNetworkName.Goerli]: '0x5', // toHex(5)\n [BuiltInNetworkName.Sepolia]: '0xaa36a7', // toHex(11155111)\n [BuiltInNetworkName.Aurora]: '0x4e454152', // toHex(1313161554)\n [BuiltInNetworkName.LineaGoerli]: '0xe704', // toHex(59140)\n [BuiltInNetworkName.LineaSepolia]: '0xe705', // toHex(59141)\n [BuiltInNetworkName.LineaMainnet]: '0xe708', // toHex(59144)\n /**\n * @deprecated `MegaETHTestnet` is migrated to `MegaETHTestnetV2`.\n */\n [BuiltInNetworkName.MegaETHTestnet]: '0x18c6', // toHex(6342)\n [BuiltInNetworkName.MegaETHTestnetV2]: '0x18c7', // toHex(6343)\n [BuiltInNetworkName.MonadTestnet]: '0x279f', // toHex(10143)\n [BuiltInNetworkName.BaseMainnet]: '0x2105', // toHex(8453)\n [BuiltInNetworkName.ArbitrumOne]: '0xa4b1', // toHex(42161)\n [BuiltInNetworkName.BscMainnet]: '0x38', // toHex(56)\n [BuiltInNetworkName.OptimismMainnet]: '0xa', // toHex(10)\n [BuiltInNetworkName.PolygonMainnet]: '0x89', // toHex(137)\n [BuiltInNetworkName.SeiMainnet]: '0x531', // toHex(1329)\n} as const;\nexport type ChainId = (typeof ChainId)[keyof typeof ChainId];\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport enum NetworksTicker {\n mainnet = 'ETH',\n goerli = 'GoerliETH',\n sepolia = 'SepoliaETH',\n 'linea-goerli' = 'LineaETH',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'linea-sepolia' = 'LineaETH',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'linea-mainnet' = 'ETH',\n /**\n * @deprecated `megaeth-testnet` is migrated to `megaeth-testnet-v2`.\n */\n 'megaeth-testnet' = 'MegaETH',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'megaeth-testnet-v2' = 'MegaETH',\n 'monad-testnet' = 'MON',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'base-mainnet' = 'ETH',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'arbitrum-mainnet' = 'ETH',\n 'bsc-mainnet' = 'BNB',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'optimism-mainnet' = 'ETH',\n 'polygon-mainnet' = 'POL',\n 'sei-mainnet' = 'SEI',\n rpc = '',\n}\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport const BlockExplorerUrl = {\n [BuiltInNetworkName.Mainnet]: 'https://etherscan.io',\n [BuiltInNetworkName.Goerli]: 'https://goerli.etherscan.io',\n [BuiltInNetworkName.Sepolia]: 'https://sepolia.etherscan.io',\n [BuiltInNetworkName.LineaGoerli]: 'https://goerli.lineascan.build',\n [BuiltInNetworkName.LineaSepolia]: 'https://sepolia.lineascan.build',\n [BuiltInNetworkName.LineaMainnet]: 'https://lineascan.build',\n /**\n * @deprecated `MegaETHTestnet` is migrated to `MegaETHTestnetV2`.\n */\n [BuiltInNetworkName.MegaETHTestnet]: 'https://megaexplorer.xyz',\n [BuiltInNetworkName.MegaETHTestnetV2]:\n 'https://megaeth-testnet-v2.blockscout.com',\n [BuiltInNetworkName.MonadTestnet]: 'https://testnet.monadexplorer.com',\n [BuiltInNetworkName.BaseMainnet]: 'https://basescan.org',\n [BuiltInNetworkName.ArbitrumOne]: 'https://arbiscan.io',\n [BuiltInNetworkName.BscMainnet]: 'https://bscscan.com',\n [BuiltInNetworkName.OptimismMainnet]: 'https://optimistic.etherscan.io',\n [BuiltInNetworkName.PolygonMainnet]: 'https://polygonscan.com',\n [BuiltInNetworkName.SeiMainnet]: 'https://seitrace.com',\n} as const satisfies Record<BuiltInNetworkType, string>;\nexport type BlockExplorerUrl =\n (typeof BlockExplorerUrl)[keyof typeof BlockExplorerUrl];\n\nexport const NetworkNickname = {\n [BuiltInNetworkName.Mainnet]: 'Ethereum Mainnet',\n [BuiltInNetworkName.Goerli]: 'Goerli',\n [BuiltInNetworkName.Sepolia]: 'Sepolia',\n [BuiltInNetworkName.LineaGoerli]: 'Linea Goerli',\n [BuiltInNetworkName.LineaSepolia]: 'Linea Sepolia',\n [BuiltInNetworkName.LineaMainnet]: 'Linea',\n /**\n * @deprecated `MegaETHTestnet` is migrated to `MegaETHTestnetV2`.\n */\n [BuiltInNetworkName.MegaETHTestnet]: 'Mega Testnet',\n [BuiltInNetworkName.MegaETHTestnetV2]: 'MegaETH Testnet',\n [BuiltInNetworkName.MonadTestnet]: 'Monad Testnet',\n [BuiltInNetworkName.BaseMainnet]: 'Base Mainnet',\n [BuiltInNetworkName.ArbitrumOne]: 'Arbitrum One',\n [BuiltInNetworkName.BscMainnet]: 'BSC Mainnet',\n [BuiltInNetworkName.OptimismMainnet]: 'Optimism Mainnet',\n [BuiltInNetworkName.PolygonMainnet]: 'Polygon Mainnet',\n [BuiltInNetworkName.SeiMainnet]: 'Sei Mainnet',\n} as const satisfies Record<BuiltInNetworkType, string>;\nexport type NetworkNickname =\n (typeof NetworkNickname)[keyof typeof NetworkNickname];\n\n/**\n * Makes a selection of keys in a Record optional.\n *\n * @template Type - The Record that you want to operate on.\n * @template Key - The union of keys you want to make optional.\n */\n// TODO: Move to @metamask/utils\nexport type Partialize<Type, Key extends keyof Type> = Omit<Type, Key> &\n Partial<Pick<Type, Key>>;\n\n/** A context in which to execute a trace, in order to generate nested timings. */\nexport type TraceContext = unknown;\n\n/** Request to trace an operation. */\nexport type TraceRequest = {\n /** Additional data to include in the trace. */\n data?: Record<string, number | string | boolean>;\n\n /** Name of the operation. */\n name: string;\n\n /**\n * Unique identifier for the trace.\n * Required if starting a trace and not providing a callback.\n */\n id?: string;\n\n /** Trace context in which to execute the operation. */\n parentContext?: TraceContext;\n\n /** Additional tags to include in the trace to filter results. */\n tags?: Record<string, number | string | boolean>;\n};\n\n/** Callback that traces the performance of an operation. */\nexport type TraceCallback = <ReturnType>(\n /** Request to trace the performance of an operation. */\n request: TraceRequest,\n\n /**\n * Callback to trace.\n * Thrown errors will not be caught, but the trace will still be recorded.\n *\n * @param context - The context in which the operation is running.\n */\n fn?: (context?: TraceContext) => ReturnType,\n) => Promise<ReturnType>;\n"]}
|
package/dist/types.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{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OAAO,EAAE,YAAY;AAErB;;;;;GAKG;AACH,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,YAAY,KAAK,UAAU,KACxC,OAAO,CAAC,UAAU,CAAC,CAAC"}
|
package/dist/types.mjs
CHANGED
|
@@ -107,6 +107,7 @@ export const ChainId = {
|
|
|
107
107
|
[BuiltInNetworkName.PolygonMainnet]: '0x89', // toHex(137)
|
|
108
108
|
[BuiltInNetworkName.SeiMainnet]: '0x531', // toHex(1329)
|
|
109
109
|
};
|
|
110
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
110
111
|
export var NetworksTicker;
|
|
111
112
|
(function (NetworksTicker) {
|
|
112
113
|
NetworksTicker["mainnet"] = "ETH";
|
|
@@ -135,6 +136,7 @@ export var NetworksTicker;
|
|
|
135
136
|
NetworksTicker["sei-mainnet"] = "SEI";
|
|
136
137
|
NetworksTicker["rpc"] = "";
|
|
137
138
|
})(NetworksTicker || (NetworksTicker = {}));
|
|
139
|
+
/* eslint-enable @typescript-eslint/naming-convention */
|
|
138
140
|
export const BlockExplorerUrl = {
|
|
139
141
|
[BuiltInNetworkName.Mainnet]: 'https://etherscan.io',
|
|
140
142
|
[BuiltInNetworkName.Goerli]: 'https://goerli.etherscan.io',
|
package/dist/types.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;IAClB,cAAc,EAAE,cAAc;IAC9B,eAAe,EAAE,eAAe;IAChC,eAAe,EAAE,eAAe;IAChC,cAAc,EAAE,cAAc;IAC9B,kBAAkB,EAAE,kBAAkB;IACtC,aAAa,EAAE,aAAa;IAC5B,kBAAkB,EAAE,kBAAkB;IACtC,iBAAiB,EAAE,iBAAiB;IACpC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,EAAE,kBAAkB;IAChD,CAAC,kBAAkB,CAAC,MAAM,CAAC,EAAE,QAAQ;IACrC,CAAC,kBAAkB,CAAC,OAAO,CAAC,EAAE,SAAS;IACvC,CAAC,kBAAkB,CAAC,WAAW,CAAC,EAAE,cAAc;IAChD,CAAC,kBAAkB,CAAC,YAAY,CAAC,EAAE,eAAe;IAClD,CAAC,kBAAkB,CAAC,YAAY,CAAC,EAAE,OAAO;IAC1C;;OAEG;IACH,CAAC,kBAAkB,CAAC,cAAc,CAAC,EAAE,cAAc;IACnD,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,EAAE,iBAAiB;IACxD,CAAC,kBAAkB,CAAC,YAAY,CAAC,EAAE,eAAe;IAClD,CAAC,kBAAkB,CAAC,WAAW,CAAC,EAAE,cAAc;IAChD,CAAC,kBAAkB,CAAC,WAAW,CAAC,EAAE,cAAc;IAChD,CAAC,kBAAkB,CAAC,UAAU,CAAC,EAAE,aAAa;IAC9C,CAAC,kBAAkB,CAAC,eAAe,CAAC,EAAE,kBAAkB;IACxD,CAAC,kBAAkB,CAAC,cAAc,CAAC,EAAE,iBAAiB;IACtD,CAAC,kBAAkB,CAAC,UAAU,CAAC,EAAE,aAAa;CACO,CAAC","sourcesContent":["/**\n * The names of built-in Infura networks\n */\nexport const InfuraNetworkType = {\n mainnet: 'mainnet',\n goerli: 'goerli',\n sepolia: 'sepolia',\n 'linea-goerli': 'linea-goerli',\n 'linea-sepolia': 'linea-sepolia',\n 'linea-mainnet': 'linea-mainnet',\n 'base-mainnet': 'base-mainnet',\n 'arbitrum-mainnet': 'arbitrum-mainnet',\n 'bsc-mainnet': 'bsc-mainnet',\n 'optimism-mainnet': 'optimism-mainnet',\n 'polygon-mainnet': 'polygon-mainnet',\n 'sei-mainnet': 'sei-mainnet',\n} as const;\n\nexport type InfuraNetworkType =\n (typeof InfuraNetworkType)[keyof typeof InfuraNetworkType];\n\n/**\n * Custom network types that are not part of Infura.\n */\nexport const CustomNetworkType = {\n /**\n * @deprecated `megaeth-testnet` is migrated to `megaeth-testnet-v2`.\n */\n 'megaeth-testnet': 'megaeth-testnet',\n 'megaeth-testnet-v2': 'megaeth-testnet-v2',\n 'monad-testnet': 'monad-testnet',\n} as const;\nexport type CustomNetworkType =\n (typeof CustomNetworkType)[keyof typeof CustomNetworkType];\n\n/**\n * Network types supported including both Infura networks and other networks.\n */\nexport type BuiltInNetworkType = InfuraNetworkType | CustomNetworkType;\n\n/**\n * The \"network type\"; either the name of a built-in network, or \"rpc\" for custom networks.\n */\nexport const NetworkType = {\n ...InfuraNetworkType,\n ...CustomNetworkType,\n rpc: 'rpc',\n} as const;\n\nexport type NetworkType = (typeof NetworkType)[keyof typeof NetworkType];\n\n/**\n * A helper to determine whether a given input is NetworkType.\n *\n * @param val - the value to check whether it is NetworkType or not.\n * @returns boolean indicating whether or not the argument is NetworkType.\n */\nexport function isNetworkType(val: string): val is NetworkType {\n return Object.values(NetworkType).includes(val as NetworkType);\n}\n\n/**\n * A type guard to determine whether the input is an InfuraNetworkType.\n *\n * @param value - The value to check.\n * @returns True if the given value is within the InfuraNetworkType enum,\n * false otherwise.\n */\nexport function isInfuraNetworkType(\n value: unknown,\n): value is InfuraNetworkType {\n const infuraNetworkTypes: unknown[] = Object.keys(InfuraNetworkType);\n return infuraNetworkTypes.includes(value);\n}\n\n/**\n * Names of networks built into the wallet.\n *\n * This includes both Infura and non-Infura networks.\n */\nexport enum BuiltInNetworkName {\n Mainnet = 'mainnet',\n Goerli = 'goerli',\n Sepolia = 'sepolia',\n LineaGoerli = 'linea-goerli',\n LineaSepolia = 'linea-sepolia',\n LineaMainnet = 'linea-mainnet',\n Aurora = 'aurora',\n /**\n * @deprecated `MegaETHTestnet` is migrated to `MegaETHTestnetV2`.\n */\n MegaETHTestnet = 'megaeth-testnet',\n MegaETHTestnetV2 = 'megaeth-testnet-v2',\n MonadTestnet = 'monad-testnet',\n BaseMainnet = 'base-mainnet',\n ArbitrumOne = 'arbitrum-mainnet',\n BscMainnet = 'bsc-mainnet',\n OptimismMainnet = 'optimism-mainnet',\n PolygonMainnet = 'polygon-mainnet',\n SeiMainnet = 'sei-mainnet',\n}\n\n/**\n * Decimal string chain IDs of built-in networks, by name.\n *\n * `toHex` not invoked to avoid cyclic dependency\n */\nexport const ChainId = {\n [BuiltInNetworkName.Mainnet]: '0x1', // toHex(1)\n [BuiltInNetworkName.Goerli]: '0x5', // toHex(5)\n [BuiltInNetworkName.Sepolia]: '0xaa36a7', // toHex(11155111)\n [BuiltInNetworkName.Aurora]: '0x4e454152', // toHex(1313161554)\n [BuiltInNetworkName.LineaGoerli]: '0xe704', // toHex(59140)\n [BuiltInNetworkName.LineaSepolia]: '0xe705', // toHex(59141)\n [BuiltInNetworkName.LineaMainnet]: '0xe708', // toHex(59144)\n /**\n * @deprecated `MegaETHTestnet` is migrated to `MegaETHTestnetV2`.\n */\n [BuiltInNetworkName.MegaETHTestnet]: '0x18c6', // toHex(6342)\n [BuiltInNetworkName.MegaETHTestnetV2]: '0x18c7', // toHex(6343)\n [BuiltInNetworkName.MonadTestnet]: '0x279f', // toHex(10143)\n [BuiltInNetworkName.BaseMainnet]: '0x2105', // toHex(8453)\n [BuiltInNetworkName.ArbitrumOne]: '0xa4b1', // toHex(42161)\n [BuiltInNetworkName.BscMainnet]: '0x38', // toHex(56)\n [BuiltInNetworkName.OptimismMainnet]: '0xa', // toHex(10)\n [BuiltInNetworkName.PolygonMainnet]: '0x89', // toHex(137)\n [BuiltInNetworkName.SeiMainnet]: '0x531', // toHex(1329)\n} as const;\nexport type ChainId = (typeof ChainId)[keyof typeof ChainId];\n\nexport enum NetworksTicker {\n mainnet = 'ETH',\n goerli = 'GoerliETH',\n sepolia = 'SepoliaETH',\n 'linea-goerli' = 'LineaETH',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'linea-sepolia' = 'LineaETH',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'linea-mainnet' = 'ETH',\n /**\n * @deprecated `megaeth-testnet` is migrated to `megaeth-testnet-v2`.\n */\n 'megaeth-testnet' = 'MegaETH',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'megaeth-testnet-v2' = 'MegaETH',\n 'monad-testnet' = 'MON',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'base-mainnet' = 'ETH',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'arbitrum-mainnet' = 'ETH',\n 'bsc-mainnet' = 'BNB',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'optimism-mainnet' = 'ETH',\n 'polygon-mainnet' = 'POL',\n 'sei-mainnet' = 'SEI',\n rpc = '',\n}\n\nexport const BlockExplorerUrl = {\n [BuiltInNetworkName.Mainnet]: 'https://etherscan.io',\n [BuiltInNetworkName.Goerli]: 'https://goerli.etherscan.io',\n [BuiltInNetworkName.Sepolia]: 'https://sepolia.etherscan.io',\n [BuiltInNetworkName.LineaGoerli]: 'https://goerli.lineascan.build',\n [BuiltInNetworkName.LineaSepolia]: 'https://sepolia.lineascan.build',\n [BuiltInNetworkName.LineaMainnet]: 'https://lineascan.build',\n /**\n * @deprecated `MegaETHTestnet` is migrated to `MegaETHTestnetV2`.\n */\n [BuiltInNetworkName.MegaETHTestnet]: 'https://megaexplorer.xyz',\n [BuiltInNetworkName.MegaETHTestnetV2]:\n 'https://megaeth-testnet-v2.blockscout.com',\n [BuiltInNetworkName.MonadTestnet]: 'https://testnet.monadexplorer.com',\n [BuiltInNetworkName.BaseMainnet]: 'https://basescan.org',\n [BuiltInNetworkName.ArbitrumOne]: 'https://arbiscan.io',\n [BuiltInNetworkName.BscMainnet]: 'https://bscscan.com',\n [BuiltInNetworkName.OptimismMainnet]: 'https://optimistic.etherscan.io',\n [BuiltInNetworkName.PolygonMainnet]: 'https://polygonscan.com',\n [BuiltInNetworkName.SeiMainnet]: 'https://seitrace.com',\n} as const satisfies Record<BuiltInNetworkType, string>;\nexport type BlockExplorerUrl =\n (typeof BlockExplorerUrl)[keyof typeof BlockExplorerUrl];\n\nexport const NetworkNickname = {\n [BuiltInNetworkName.Mainnet]: 'Ethereum Mainnet',\n [BuiltInNetworkName.Goerli]: 'Goerli',\n [BuiltInNetworkName.Sepolia]: 'Sepolia',\n [BuiltInNetworkName.LineaGoerli]: 'Linea Goerli',\n [BuiltInNetworkName.LineaSepolia]: 'Linea Sepolia',\n [BuiltInNetworkName.LineaMainnet]: 'Linea',\n /**\n * @deprecated `MegaETHTestnet` is migrated to `MegaETHTestnetV2`.\n */\n [BuiltInNetworkName.MegaETHTestnet]: 'Mega Testnet',\n [BuiltInNetworkName.MegaETHTestnetV2]: 'MegaETH Testnet',\n [BuiltInNetworkName.MonadTestnet]: 'Monad Testnet',\n [BuiltInNetworkName.BaseMainnet]: 'Base Mainnet',\n [BuiltInNetworkName.ArbitrumOne]: 'Arbitrum One',\n [BuiltInNetworkName.BscMainnet]: 'BSC Mainnet',\n [BuiltInNetworkName.OptimismMainnet]: 'Optimism Mainnet',\n [BuiltInNetworkName.PolygonMainnet]: 'Polygon Mainnet',\n [BuiltInNetworkName.SeiMainnet]: 'Sei Mainnet',\n} as const satisfies Record<BuiltInNetworkType, string>;\nexport type NetworkNickname =\n (typeof NetworkNickname)[keyof typeof NetworkNickname];\n\n/**\n * Makes a selection of keys in a Record optional.\n *\n * @template Type - The Record that you want to operate on.\n * @template Key - The union of keys you want to make optional.\n */\n// TODO: Move to @metamask/utils\nexport type Partialize<Type, Key extends keyof Type> = Omit<Type, Key> &\n Partial<Pick<Type, Key>>;\n\n/** A context in which to execute a trace, in order to generate nested timings. */\nexport type TraceContext = unknown;\n\n/** Request to trace an operation. */\nexport type TraceRequest = {\n /** Additional data to include in the trace. */\n data?: Record<string, number | string | boolean>;\n\n /** Name of the operation. */\n name: string;\n\n /**\n * Unique identifier for the trace.\n * Required if starting a trace and not providing a callback.\n */\n id?: string;\n\n /** Trace context in which to execute the operation. */\n parentContext?: TraceContext;\n\n /** Additional tags to include in the trace to filter results. */\n tags?: Record<string, number | string | boolean>;\n};\n\n/** Callback that traces the performance of an operation. */\nexport type TraceCallback = <ReturnType>(\n /** Request to trace the performance of an operation. */\n request: TraceRequest,\n\n /**\n * Callback to trace.\n * Thrown errors will not be caught, but the trace will still be recorded.\n *\n * @param context - The context in which the operation is running.\n */\n fn?: (context?: TraceContext) => ReturnType,\n) => Promise<ReturnType>;\n"]}
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;IAClB,cAAc,EAAE,cAAc;IAC9B,eAAe,EAAE,eAAe;IAChC,eAAe,EAAE,eAAe;IAChC,cAAc,EAAE,cAAc;IAC9B,kBAAkB,EAAE,kBAAkB;IACtC,aAAa,EAAE,aAAa;IAC5B,kBAAkB,EAAE,kBAAkB;IACtC,iBAAiB,EAAE,iBAAiB;IACpC,aAAa,EAAE,aAAa;CACpB,CAAC;AAKX;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B;;OAEG;IACH,iBAAiB,EAAE,iBAAiB;IACpC,oBAAoB,EAAE,oBAAoB;IAC1C,eAAe,EAAE,eAAe;CACxB,CAAC;AASX;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,GAAG,iBAAiB;IACpB,GAAG,iBAAiB;IACpB,GAAG,EAAE,KAAK;CACF,CAAC;AAIX;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,GAAW;IACvC,OAAO,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,QAAQ,CAAC,GAAkB,CAAC,CAAC;AACjE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CACjC,KAAc;IAEd,MAAM,kBAAkB,GAAc,MAAM,CAAC,IAAI,CAAC,iB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AChD,CAAC,kBAAkB,CAAC,UAAU,CAAC,EAAE,aAAa;IAC9C,CAAC,kBAAkB,CAAC,eAAe,CAAC,EAAE,kBAAkB;IACxD,CAAC,kBAAkB,CAAC,cAAc,CAAC,EAAE,iBAAiB;IACtD,CAAC,kBAAkB,CAAC,UAAU,CAAC,EAAE,aAAa;CACO,CAAC","sourcesContent":["/**\n * The names of built-in Infura networks\n */\nexport const InfuraNetworkType = {\n mainnet: 'mainnet',\n goerli: 'goerli',\n sepolia: 'sepolia',\n 'linea-goerli': 'linea-goerli',\n 'linea-sepolia': 'linea-sepolia',\n 'linea-mainnet': 'linea-mainnet',\n 'base-mainnet': 'base-mainnet',\n 'arbitrum-mainnet': 'arbitrum-mainnet',\n 'bsc-mainnet': 'bsc-mainnet',\n 'optimism-mainnet': 'optimism-mainnet',\n 'polygon-mainnet': 'polygon-mainnet',\n 'sei-mainnet': 'sei-mainnet',\n} as const;\n\nexport type InfuraNetworkType =\n (typeof InfuraNetworkType)[keyof typeof InfuraNetworkType];\n\n/**\n * Custom network types that are not part of Infura.\n */\nexport const CustomNetworkType = {\n /**\n * @deprecated `megaeth-testnet` is migrated to `megaeth-testnet-v2`.\n */\n 'megaeth-testnet': 'megaeth-testnet',\n 'megaeth-testnet-v2': 'megaeth-testnet-v2',\n 'monad-testnet': 'monad-testnet',\n} as const;\nexport type CustomNetworkType =\n (typeof CustomNetworkType)[keyof typeof CustomNetworkType];\n\n/**\n * Network types supported including both Infura networks and other networks.\n */\nexport type BuiltInNetworkType = InfuraNetworkType | CustomNetworkType;\n\n/**\n * The \"network type\"; either the name of a built-in network, or \"rpc\" for custom networks.\n */\nexport const NetworkType = {\n ...InfuraNetworkType,\n ...CustomNetworkType,\n rpc: 'rpc',\n} as const;\n\nexport type NetworkType = (typeof NetworkType)[keyof typeof NetworkType];\n\n/**\n * A helper to determine whether a given input is NetworkType.\n *\n * @param val - the value to check whether it is NetworkType or not.\n * @returns boolean indicating whether or not the argument is NetworkType.\n */\nexport function isNetworkType(val: string): val is NetworkType {\n return Object.values(NetworkType).includes(val as NetworkType);\n}\n\n/**\n * A type guard to determine whether the input is an InfuraNetworkType.\n *\n * @param value - The value to check.\n * @returns True if the given value is within the InfuraNetworkType enum,\n * false otherwise.\n */\nexport function isInfuraNetworkType(\n value: unknown,\n): value is InfuraNetworkType {\n const infuraNetworkTypes: unknown[] = Object.keys(InfuraNetworkType);\n return infuraNetworkTypes.includes(value);\n}\n\n/**\n * Names of networks built into the wallet.\n *\n * This includes both Infura and non-Infura networks.\n */\nexport enum BuiltInNetworkName {\n Mainnet = 'mainnet',\n Goerli = 'goerli',\n Sepolia = 'sepolia',\n LineaGoerli = 'linea-goerli',\n LineaSepolia = 'linea-sepolia',\n LineaMainnet = 'linea-mainnet',\n Aurora = 'aurora',\n /**\n * @deprecated `MegaETHTestnet` is migrated to `MegaETHTestnetV2`.\n */\n MegaETHTestnet = 'megaeth-testnet',\n MegaETHTestnetV2 = 'megaeth-testnet-v2',\n MonadTestnet = 'monad-testnet',\n BaseMainnet = 'base-mainnet',\n ArbitrumOne = 'arbitrum-mainnet',\n BscMainnet = 'bsc-mainnet',\n OptimismMainnet = 'optimism-mainnet',\n PolygonMainnet = 'polygon-mainnet',\n SeiMainnet = 'sei-mainnet',\n}\n\n/**\n * Decimal string chain IDs of built-in networks, by name.\n *\n * `toHex` not invoked to avoid cyclic dependency\n */\nexport const ChainId = {\n [BuiltInNetworkName.Mainnet]: '0x1', // toHex(1)\n [BuiltInNetworkName.Goerli]: '0x5', // toHex(5)\n [BuiltInNetworkName.Sepolia]: '0xaa36a7', // toHex(11155111)\n [BuiltInNetworkName.Aurora]: '0x4e454152', // toHex(1313161554)\n [BuiltInNetworkName.LineaGoerli]: '0xe704', // toHex(59140)\n [BuiltInNetworkName.LineaSepolia]: '0xe705', // toHex(59141)\n [BuiltInNetworkName.LineaMainnet]: '0xe708', // toHex(59144)\n /**\n * @deprecated `MegaETHTestnet` is migrated to `MegaETHTestnetV2`.\n */\n [BuiltInNetworkName.MegaETHTestnet]: '0x18c6', // toHex(6342)\n [BuiltInNetworkName.MegaETHTestnetV2]: '0x18c7', // toHex(6343)\n [BuiltInNetworkName.MonadTestnet]: '0x279f', // toHex(10143)\n [BuiltInNetworkName.BaseMainnet]: '0x2105', // toHex(8453)\n [BuiltInNetworkName.ArbitrumOne]: '0xa4b1', // toHex(42161)\n [BuiltInNetworkName.BscMainnet]: '0x38', // toHex(56)\n [BuiltInNetworkName.OptimismMainnet]: '0xa', // toHex(10)\n [BuiltInNetworkName.PolygonMainnet]: '0x89', // toHex(137)\n [BuiltInNetworkName.SeiMainnet]: '0x531', // toHex(1329)\n} as const;\nexport type ChainId = (typeof ChainId)[keyof typeof ChainId];\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport enum NetworksTicker {\n mainnet = 'ETH',\n goerli = 'GoerliETH',\n sepolia = 'SepoliaETH',\n 'linea-goerli' = 'LineaETH',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'linea-sepolia' = 'LineaETH',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'linea-mainnet' = 'ETH',\n /**\n * @deprecated `megaeth-testnet` is migrated to `megaeth-testnet-v2`.\n */\n 'megaeth-testnet' = 'MegaETH',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'megaeth-testnet-v2' = 'MegaETH',\n 'monad-testnet' = 'MON',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'base-mainnet' = 'ETH',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'arbitrum-mainnet' = 'ETH',\n 'bsc-mainnet' = 'BNB',\n // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values\n 'optimism-mainnet' = 'ETH',\n 'polygon-mainnet' = 'POL',\n 'sei-mainnet' = 'SEI',\n rpc = '',\n}\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport const BlockExplorerUrl = {\n [BuiltInNetworkName.Mainnet]: 'https://etherscan.io',\n [BuiltInNetworkName.Goerli]: 'https://goerli.etherscan.io',\n [BuiltInNetworkName.Sepolia]: 'https://sepolia.etherscan.io',\n [BuiltInNetworkName.LineaGoerli]: 'https://goerli.lineascan.build',\n [BuiltInNetworkName.LineaSepolia]: 'https://sepolia.lineascan.build',\n [BuiltInNetworkName.LineaMainnet]: 'https://lineascan.build',\n /**\n * @deprecated `MegaETHTestnet` is migrated to `MegaETHTestnetV2`.\n */\n [BuiltInNetworkName.MegaETHTestnet]: 'https://megaexplorer.xyz',\n [BuiltInNetworkName.MegaETHTestnetV2]:\n 'https://megaeth-testnet-v2.blockscout.com',\n [BuiltInNetworkName.MonadTestnet]: 'https://testnet.monadexplorer.com',\n [BuiltInNetworkName.BaseMainnet]: 'https://basescan.org',\n [BuiltInNetworkName.ArbitrumOne]: 'https://arbiscan.io',\n [BuiltInNetworkName.BscMainnet]: 'https://bscscan.com',\n [BuiltInNetworkName.OptimismMainnet]: 'https://optimistic.etherscan.io',\n [BuiltInNetworkName.PolygonMainnet]: 'https://polygonscan.com',\n [BuiltInNetworkName.SeiMainnet]: 'https://seitrace.com',\n} as const satisfies Record<BuiltInNetworkType, string>;\nexport type BlockExplorerUrl =\n (typeof BlockExplorerUrl)[keyof typeof BlockExplorerUrl];\n\nexport const NetworkNickname = {\n [BuiltInNetworkName.Mainnet]: 'Ethereum Mainnet',\n [BuiltInNetworkName.Goerli]: 'Goerli',\n [BuiltInNetworkName.Sepolia]: 'Sepolia',\n [BuiltInNetworkName.LineaGoerli]: 'Linea Goerli',\n [BuiltInNetworkName.LineaSepolia]: 'Linea Sepolia',\n [BuiltInNetworkName.LineaMainnet]: 'Linea',\n /**\n * @deprecated `MegaETHTestnet` is migrated to `MegaETHTestnetV2`.\n */\n [BuiltInNetworkName.MegaETHTestnet]: 'Mega Testnet',\n [BuiltInNetworkName.MegaETHTestnetV2]: 'MegaETH Testnet',\n [BuiltInNetworkName.MonadTestnet]: 'Monad Testnet',\n [BuiltInNetworkName.BaseMainnet]: 'Base Mainnet',\n [BuiltInNetworkName.ArbitrumOne]: 'Arbitrum One',\n [BuiltInNetworkName.BscMainnet]: 'BSC Mainnet',\n [BuiltInNetworkName.OptimismMainnet]: 'Optimism Mainnet',\n [BuiltInNetworkName.PolygonMainnet]: 'Polygon Mainnet',\n [BuiltInNetworkName.SeiMainnet]: 'Sei Mainnet',\n} as const satisfies Record<BuiltInNetworkType, string>;\nexport type NetworkNickname =\n (typeof NetworkNickname)[keyof typeof NetworkNickname];\n\n/**\n * Makes a selection of keys in a Record optional.\n *\n * @template Type - The Record that you want to operate on.\n * @template Key - The union of keys you want to make optional.\n */\n// TODO: Move to @metamask/utils\nexport type Partialize<Type, Key extends keyof Type> = Omit<Type, Key> &\n Partial<Pick<Type, Key>>;\n\n/** A context in which to execute a trace, in order to generate nested timings. */\nexport type TraceContext = unknown;\n\n/** Request to trace an operation. */\nexport type TraceRequest = {\n /** Additional data to include in the trace. */\n data?: Record<string, number | string | boolean>;\n\n /** Name of the operation. */\n name: string;\n\n /**\n * Unique identifier for the trace.\n * Required if starting a trace and not providing a callback.\n */\n id?: string;\n\n /** Trace context in which to execute the operation. */\n parentContext?: TraceContext;\n\n /** Additional tags to include in the trace to filter results. */\n tags?: Record<string, number | string | boolean>;\n};\n\n/** Callback that traces the performance of an operation. */\nexport type TraceCallback = <ReturnType>(\n /** Request to trace the performance of an operation. */\n request: TraceRequest,\n\n /**\n * Callback to trace.\n * Thrown errors will not be caught, but the trace will still be recorded.\n *\n * @param context - The context in which the operation is running.\n */\n fn?: (context?: TraceContext) => ReturnType,\n) => Promise<ReturnType>;\n"]}
|