@metamask-previews/controller-utils 12.3.0-preview-b13d916 → 12.3.0-preview-4f4c98e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/dist/{abi.d.mts → abi.d.ts} +3 -3
- package/dist/abi.d.ts.map +1 -0
- package/dist/{abi.mjs → abi.js} +3 -3
- package/dist/{abi.mjs.map → abi.js.map} +1 -1
- package/dist/{constants.d.cts → constants.d.ts} +3 -3
- package/dist/constants.d.ts.map +1 -0
- package/dist/{constants.mjs → constants.js} +2 -2
- package/dist/constants.js.map +1 -0
- package/dist/{create-service-policy.d.mts → create-service-policy.d.ts} +3 -3
- package/dist/create-service-policy.d.ts.map +1 -0
- package/dist/{create-service-policy.mjs → create-service-policy.js} +3 -3
- package/dist/create-service-policy.js.map +1 -0
- package/dist/{index.d.cts → index.d.ts} +9 -9
- package/dist/index.d.ts.map +1 -0
- package/dist/{index.mjs → index.js} +7 -7
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +4 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +4 -0
- package/dist/logger.js.map +1 -0
- package/dist/{siwe.d.mts → siwe.d.ts} +2 -2
- package/dist/siwe.d.ts.map +1 -0
- package/dist/{siwe.mjs → siwe.js} +4 -4
- package/dist/siwe.js.map +1 -0
- package/dist/{types.d.mts → types.d.ts} +98 -98
- package/dist/types.d.ts.map +1 -0
- package/dist/{types.mjs → types.js} +1 -1
- package/dist/types.js.map +1 -0
- package/dist/{util.d.cts → util.d.ts} +6 -6
- package/dist/util.d.ts.map +1 -0
- package/dist/{util.mjs → util.js} +8 -18
- package/dist/util.js.map +1 -0
- package/package.json +14 -18
- package/dist/abi.cjs +0 -58
- package/dist/abi.cjs.map +0 -1
- package/dist/abi.d.cts +0 -16
- package/dist/abi.d.cts.map +0 -1
- package/dist/abi.d.mts.map +0 -1
- package/dist/constants.cjs +0 -308
- package/dist/constants.cjs.map +0 -1
- package/dist/constants.d.cts.map +0 -1
- package/dist/constants.d.mts +0 -283
- package/dist/constants.d.mts.map +0 -1
- package/dist/constants.mjs.map +0 -1
- package/dist/create-service-policy.cjs +0 -250
- package/dist/create-service-policy.cjs.map +0 -1
- package/dist/create-service-policy.d.cts +0 -249
- package/dist/create-service-policy.d.cts.map +0 -1
- package/dist/create-service-policy.d.mts.map +0 -1
- package/dist/create-service-policy.mjs.map +0 -1
- package/dist/index.cjs +0 -102
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts +0 -9
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/logger.cjs +0 -7
- package/dist/logger.cjs.map +0 -1
- package/dist/logger.d.cts +0 -5
- package/dist/logger.d.cts.map +0 -1
- package/dist/logger.d.mts +0 -5
- package/dist/logger.d.mts.map +0 -1
- package/dist/logger.mjs +0 -4
- package/dist/logger.mjs.map +0 -1
- package/dist/siwe.cjs +0 -131
- package/dist/siwe.cjs.map +0 -1
- package/dist/siwe.d.cts +0 -69
- package/dist/siwe.d.cts.map +0 -1
- package/dist/siwe.d.mts.map +0 -1
- package/dist/siwe.mjs.map +0 -1
- package/dist/types.cjs +0 -232
- package/dist/types.cjs.map +0 -1
- package/dist/types.d.cts +0 -267
- package/dist/types.d.cts.map +0 -1
- package/dist/types.d.mts.map +0 -1
- package/dist/types.mjs.map +0 -1
- package/dist/util.cjs +0 -569
- package/dist/util.cjs.map +0 -1
- package/dist/util.d.cts.map +0 -1
- package/dist/util.d.mts +0 -261
- package/dist/util.d.mts.map +0 -1
- package/dist/util.mjs.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
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,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veBreaker,\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 /**\n * @deprecated This is deprecated and will be removed in a future major\n * version. Please use the equivalent type from `@metamask/base-data-service`.\n */\n BrokenCircuitError,\n /**\n * @deprecated This is deprecated and will be removed in a future major\n * version. Please use the equivalent type from `@metamask/base-data-service`.\n */\n CockatielEventEmitter,\n /**\n * @deprecated This is deprecated and will be removed in a future major\n * version. Please use the equivalent type from `@metamask/base-data-service`.\n */\n CircuitState,\n /**\n * @deprecated This is deprecated and will be removed in a future major\n * version. Please use the equivalent type from `@metamask/base-data-service`.\n */\n ConstantBackoff,\n /**\n * @deprecated This is deprecated and will be removed in a future major\n * version. Please use the equivalent type from `@metamask/base-data-service`.\n */\n ExponentialBackoff,\n /**\n * @deprecated This is deprecated and will be removed in a future major\n * version. Please use the equivalent function from\n * `@metamask/base-data-service`.\n */\n handleAll,\n /**\n * @deprecated This is deprecated and will be removed in a future major\n * version. Please use the equivalent function from\n * `@metamask/base-data-service`.\n */\n handleWhen,\n};\n\nexport type {\n /**\n * @deprecated This is deprecated and will be removed in a future major\n * version. Please use the equivalent type from `@metamask/base-data-service`.\n */\n CockatielEvent,\n /**\n * @deprecated This is deprecated and will be removed in a future major\n * version. Please use the equivalent type from `@metamask/base-data-service`.\n */\n FailureReason as CockatielFailureReason,\n};\n\n/**\n * The options for `createServicePolicy`.\n *\n * @deprecated This is deprecated and will be removed in a future major version.\n * Please use the equivalent type from `@metamask/base-data-service`.\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 * Predicate function for when an error should be considered a service failure.\n */\n isServiceFailure?: (error: unknown) => boolean;\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 *\n * @deprecated This is deprecated and will be removed in a future major\n * version. Please use the equivalent type from `@metamask/base-data-service`.\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> | { duration: number }>;\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 *\n * @deprecated This is deprecated and will be removed in a future major version.\n * Please use the equivalent variable from `@metamask/base-data-service`.\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 *\n * @deprecated This is deprecated and will be removed in a future major version.\n * Please use the equivalent variable from `@metamask/base-data-service`.\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 *\n * @deprecated This is deprecated and will be removed in a future major version.\n * Please use the equivalent variable from `@metamask/base-data-service`.\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 *\n * @deprecated This is deprecated and will be removed in a future major version.\n * Please use the equivalent variable from `@metamask/base-data-service`.\n */\nexport const DEFAULT_DEGRADED_THRESHOLD = 5_000;\n\nconst defaultIsServiceFailure = (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 httpStatus\n // property, consider it a service failure (e.g., network errors, timeouts,\n // 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 *\n * @deprecated This is deprecated and will be removed in a future major version.\n * Please use the equivalent function from `@metamask/base-data-service`.\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 isServiceFailure = defaultIsServiceFailure,\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 = new CockatielEventEmitter<\n FailureReason<unknown> | { duration: number }\n >();\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({ duration });\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/index.cjs
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.BNToHex = exports.CHAIN_IDS_WITH_NO_NATIVE_TOKEN = exports.NETWORKS_BYPASSING_VALIDATION = exports.DAYS = exports.DAY = exports.HOURS = exports.HOUR = exports.MINUTES = exports.MINUTE = exports.SECONDS = exports.SECOND = exports.CHAIN_ID_TO_ETHERS_NETWORK_NAME_MAP = exports.ApprovalType = exports.ORIGIN_METAMASK = exports.NFT_API_TIMEOUT = exports.NFT_API_VERSION = exports.NFT_API_BASE_URL = exports.OPENSEA_PROXY_URL = exports.BUILT_IN_NETWORKS = exports.BUILT_IN_CUSTOM_NETWORKS_RPC = exports.TESTNET_TICKER_SYMBOLS = exports.ASSET_TYPES = exports.GWEI = exports.ERC1155_TOKEN_RECEIVER_INTERFACE_ID = exports.ERC1155_METADATA_URI_INTERFACE_ID = exports.ERC1155_INTERFACE_ID = exports.ERC721_ENUMERABLE_INTERFACE_ID = exports.ERC721_METADATA_INTERFACE_ID = exports.ERC721_INTERFACE_ID = exports.ERC20 = exports.ERC1155 = exports.ERC721 = exports.MAX_SAFE_CHAIN_ID = exports.GANACHE_CHAIN_ID = exports.IPFS_DEFAULT_GATEWAY_URL = exports.FALL_BACK_VS_CURRENCY = exports.RPC = exports.handleWhen = exports.handleAll = exports.createServicePolicy = exports.ExponentialBackoff = exports.DEFAULT_MAX_RETRIES = exports.DEFAULT_MAX_CONSECUTIVE_FAILURES = exports.DEFAULT_DEGRADED_THRESHOLD = exports.DEFAULT_CIRCUIT_BREAK_DURATION = exports.ConstantBackoff = exports.CockatielEventEmitter = exports.CircuitState = exports.BrokenCircuitError = exports.encodeFunctionData = void 0;
|
|
18
|
-
exports.isEqualCaseInsensitive = exports.weiHexToGweiDec = exports.toHex = exports.toChecksumHexAddress = exports.timeoutFetch = exports.successfulFetch = exports.safelyExecuteWithTimeout = exports.safelyExecute = exports.query = exports.normalizeEnsName = exports.isValidHexAddress = exports.isValidJson = exports.isSmartContractCode = exports.isSafeDynamicKey = exports.isSafeChainId = exports.isPlainObject = exports.isNonEmptyArray = exports.HttpError = exports.hexToText = exports.hexToBN = exports.handleFetch = exports.gweiDecToWEIBN = exports.getBuyURL = exports.fromHex = exports.fractionBN = exports.fetchWithErrorHandling = exports.convertHexToDecimal = void 0;
|
|
19
|
-
var abi_js_1 = require("./abi.cjs");
|
|
20
|
-
Object.defineProperty(exports, "encodeFunctionData", { enumerable: true, get: function () { return abi_js_1.encodeFunctionData; } });
|
|
21
|
-
var create_service_policy_js_1 = require("./create-service-policy.cjs");
|
|
22
|
-
Object.defineProperty(exports, "BrokenCircuitError", { enumerable: true, get: function () { return create_service_policy_js_1.BrokenCircuitError; } });
|
|
23
|
-
Object.defineProperty(exports, "CircuitState", { enumerable: true, get: function () { return create_service_policy_js_1.CircuitState; } });
|
|
24
|
-
Object.defineProperty(exports, "CockatielEventEmitter", { enumerable: true, get: function () { return create_service_policy_js_1.CockatielEventEmitter; } });
|
|
25
|
-
Object.defineProperty(exports, "ConstantBackoff", { enumerable: true, get: function () { return create_service_policy_js_1.ConstantBackoff; } });
|
|
26
|
-
Object.defineProperty(exports, "DEFAULT_CIRCUIT_BREAK_DURATION", { enumerable: true, get: function () { return create_service_policy_js_1.DEFAULT_CIRCUIT_BREAK_DURATION; } });
|
|
27
|
-
Object.defineProperty(exports, "DEFAULT_DEGRADED_THRESHOLD", { enumerable: true, get: function () { return create_service_policy_js_1.DEFAULT_DEGRADED_THRESHOLD; } });
|
|
28
|
-
Object.defineProperty(exports, "DEFAULT_MAX_CONSECUTIVE_FAILURES", { enumerable: true, get: function () { return create_service_policy_js_1.DEFAULT_MAX_CONSECUTIVE_FAILURES; } });
|
|
29
|
-
Object.defineProperty(exports, "DEFAULT_MAX_RETRIES", { enumerable: true, get: function () { return create_service_policy_js_1.DEFAULT_MAX_RETRIES; } });
|
|
30
|
-
Object.defineProperty(exports, "ExponentialBackoff", { enumerable: true, get: function () { return create_service_policy_js_1.ExponentialBackoff; } });
|
|
31
|
-
Object.defineProperty(exports, "createServicePolicy", { enumerable: true, get: function () { return create_service_policy_js_1.createServicePolicy; } });
|
|
32
|
-
Object.defineProperty(exports, "handleAll", { enumerable: true, get: function () { return create_service_policy_js_1.handleAll; } });
|
|
33
|
-
Object.defineProperty(exports, "handleWhen", { enumerable: true, get: function () { return create_service_policy_js_1.handleWhen; } });
|
|
34
|
-
var constants_js_1 = require("./constants.cjs");
|
|
35
|
-
Object.defineProperty(exports, "RPC", { enumerable: true, get: function () { return constants_js_1.RPC; } });
|
|
36
|
-
Object.defineProperty(exports, "FALL_BACK_VS_CURRENCY", { enumerable: true, get: function () { return constants_js_1.FALL_BACK_VS_CURRENCY; } });
|
|
37
|
-
Object.defineProperty(exports, "IPFS_DEFAULT_GATEWAY_URL", { enumerable: true, get: function () { return constants_js_1.IPFS_DEFAULT_GATEWAY_URL; } });
|
|
38
|
-
Object.defineProperty(exports, "GANACHE_CHAIN_ID", { enumerable: true, get: function () { return constants_js_1.GANACHE_CHAIN_ID; } });
|
|
39
|
-
Object.defineProperty(exports, "MAX_SAFE_CHAIN_ID", { enumerable: true, get: function () { return constants_js_1.MAX_SAFE_CHAIN_ID; } });
|
|
40
|
-
Object.defineProperty(exports, "ERC721", { enumerable: true, get: function () { return constants_js_1.ERC721; } });
|
|
41
|
-
Object.defineProperty(exports, "ERC1155", { enumerable: true, get: function () { return constants_js_1.ERC1155; } });
|
|
42
|
-
Object.defineProperty(exports, "ERC20", { enumerable: true, get: function () { return constants_js_1.ERC20; } });
|
|
43
|
-
Object.defineProperty(exports, "ERC721_INTERFACE_ID", { enumerable: true, get: function () { return constants_js_1.ERC721_INTERFACE_ID; } });
|
|
44
|
-
Object.defineProperty(exports, "ERC721_METADATA_INTERFACE_ID", { enumerable: true, get: function () { return constants_js_1.ERC721_METADATA_INTERFACE_ID; } });
|
|
45
|
-
Object.defineProperty(exports, "ERC721_ENUMERABLE_INTERFACE_ID", { enumerable: true, get: function () { return constants_js_1.ERC721_ENUMERABLE_INTERFACE_ID; } });
|
|
46
|
-
Object.defineProperty(exports, "ERC1155_INTERFACE_ID", { enumerable: true, get: function () { return constants_js_1.ERC1155_INTERFACE_ID; } });
|
|
47
|
-
Object.defineProperty(exports, "ERC1155_METADATA_URI_INTERFACE_ID", { enumerable: true, get: function () { return constants_js_1.ERC1155_METADATA_URI_INTERFACE_ID; } });
|
|
48
|
-
Object.defineProperty(exports, "ERC1155_TOKEN_RECEIVER_INTERFACE_ID", { enumerable: true, get: function () { return constants_js_1.ERC1155_TOKEN_RECEIVER_INTERFACE_ID; } });
|
|
49
|
-
Object.defineProperty(exports, "GWEI", { enumerable: true, get: function () { return constants_js_1.GWEI; } });
|
|
50
|
-
Object.defineProperty(exports, "ASSET_TYPES", { enumerable: true, get: function () { return constants_js_1.ASSET_TYPES; } });
|
|
51
|
-
Object.defineProperty(exports, "TESTNET_TICKER_SYMBOLS", { enumerable: true, get: function () { return constants_js_1.TESTNET_TICKER_SYMBOLS; } });
|
|
52
|
-
Object.defineProperty(exports, "BUILT_IN_CUSTOM_NETWORKS_RPC", { enumerable: true, get: function () { return constants_js_1.BUILT_IN_CUSTOM_NETWORKS_RPC; } });
|
|
53
|
-
Object.defineProperty(exports, "BUILT_IN_NETWORKS", { enumerable: true, get: function () { return constants_js_1.BUILT_IN_NETWORKS; } });
|
|
54
|
-
Object.defineProperty(exports, "OPENSEA_PROXY_URL", { enumerable: true, get: function () { return constants_js_1.OPENSEA_PROXY_URL; } });
|
|
55
|
-
Object.defineProperty(exports, "NFT_API_BASE_URL", { enumerable: true, get: function () { return constants_js_1.NFT_API_BASE_URL; } });
|
|
56
|
-
Object.defineProperty(exports, "NFT_API_VERSION", { enumerable: true, get: function () { return constants_js_1.NFT_API_VERSION; } });
|
|
57
|
-
Object.defineProperty(exports, "NFT_API_TIMEOUT", { enumerable: true, get: function () { return constants_js_1.NFT_API_TIMEOUT; } });
|
|
58
|
-
Object.defineProperty(exports, "ORIGIN_METAMASK", { enumerable: true, get: function () { return constants_js_1.ORIGIN_METAMASK; } });
|
|
59
|
-
Object.defineProperty(exports, "ApprovalType", { enumerable: true, get: function () { return constants_js_1.ApprovalType; } });
|
|
60
|
-
Object.defineProperty(exports, "CHAIN_ID_TO_ETHERS_NETWORK_NAME_MAP", { enumerable: true, get: function () { return constants_js_1.CHAIN_ID_TO_ETHERS_NETWORK_NAME_MAP; } });
|
|
61
|
-
Object.defineProperty(exports, "SECOND", { enumerable: true, get: function () { return constants_js_1.SECOND; } });
|
|
62
|
-
Object.defineProperty(exports, "SECONDS", { enumerable: true, get: function () { return constants_js_1.SECONDS; } });
|
|
63
|
-
Object.defineProperty(exports, "MINUTE", { enumerable: true, get: function () { return constants_js_1.MINUTE; } });
|
|
64
|
-
Object.defineProperty(exports, "MINUTES", { enumerable: true, get: function () { return constants_js_1.MINUTES; } });
|
|
65
|
-
Object.defineProperty(exports, "HOUR", { enumerable: true, get: function () { return constants_js_1.HOUR; } });
|
|
66
|
-
Object.defineProperty(exports, "HOURS", { enumerable: true, get: function () { return constants_js_1.HOURS; } });
|
|
67
|
-
Object.defineProperty(exports, "DAY", { enumerable: true, get: function () { return constants_js_1.DAY; } });
|
|
68
|
-
Object.defineProperty(exports, "DAYS", { enumerable: true, get: function () { return constants_js_1.DAYS; } });
|
|
69
|
-
Object.defineProperty(exports, "NETWORKS_BYPASSING_VALIDATION", { enumerable: true, get: function () { return constants_js_1.NETWORKS_BYPASSING_VALIDATION; } });
|
|
70
|
-
Object.defineProperty(exports, "CHAIN_IDS_WITH_NO_NATIVE_TOKEN", { enumerable: true, get: function () { return constants_js_1.CHAIN_IDS_WITH_NO_NATIVE_TOKEN; } });
|
|
71
|
-
var util_js_1 = require("./util.cjs");
|
|
72
|
-
Object.defineProperty(exports, "BNToHex", { enumerable: true, get: function () { return util_js_1.BNToHex; } });
|
|
73
|
-
Object.defineProperty(exports, "convertHexToDecimal", { enumerable: true, get: function () { return util_js_1.convertHexToDecimal; } });
|
|
74
|
-
Object.defineProperty(exports, "fetchWithErrorHandling", { enumerable: true, get: function () { return util_js_1.fetchWithErrorHandling; } });
|
|
75
|
-
Object.defineProperty(exports, "fractionBN", { enumerable: true, get: function () { return util_js_1.fractionBN; } });
|
|
76
|
-
Object.defineProperty(exports, "fromHex", { enumerable: true, get: function () { return util_js_1.fromHex; } });
|
|
77
|
-
Object.defineProperty(exports, "getBuyURL", { enumerable: true, get: function () { return util_js_1.getBuyURL; } });
|
|
78
|
-
Object.defineProperty(exports, "gweiDecToWEIBN", { enumerable: true, get: function () { return util_js_1.gweiDecToWEIBN; } });
|
|
79
|
-
Object.defineProperty(exports, "handleFetch", { enumerable: true, get: function () { return util_js_1.handleFetch; } });
|
|
80
|
-
Object.defineProperty(exports, "hexToBN", { enumerable: true, get: function () { return util_js_1.hexToBN; } });
|
|
81
|
-
Object.defineProperty(exports, "hexToText", { enumerable: true, get: function () { return util_js_1.hexToText; } });
|
|
82
|
-
Object.defineProperty(exports, "HttpError", { enumerable: true, get: function () { return util_js_1.HttpError; } });
|
|
83
|
-
Object.defineProperty(exports, "isNonEmptyArray", { enumerable: true, get: function () { return util_js_1.isNonEmptyArray; } });
|
|
84
|
-
Object.defineProperty(exports, "isPlainObject", { enumerable: true, get: function () { return util_js_1.isPlainObject; } });
|
|
85
|
-
Object.defineProperty(exports, "isSafeChainId", { enumerable: true, get: function () { return util_js_1.isSafeChainId; } });
|
|
86
|
-
Object.defineProperty(exports, "isSafeDynamicKey", { enumerable: true, get: function () { return util_js_1.isSafeDynamicKey; } });
|
|
87
|
-
Object.defineProperty(exports, "isSmartContractCode", { enumerable: true, get: function () { return util_js_1.isSmartContractCode; } });
|
|
88
|
-
Object.defineProperty(exports, "isValidJson", { enumerable: true, get: function () { return util_js_1.isValidJson; } });
|
|
89
|
-
Object.defineProperty(exports, "isValidHexAddress", { enumerable: true, get: function () { return util_js_1.isValidHexAddress; } });
|
|
90
|
-
Object.defineProperty(exports, "normalizeEnsName", { enumerable: true, get: function () { return util_js_1.normalizeEnsName; } });
|
|
91
|
-
Object.defineProperty(exports, "query", { enumerable: true, get: function () { return util_js_1.query; } });
|
|
92
|
-
Object.defineProperty(exports, "safelyExecute", { enumerable: true, get: function () { return util_js_1.safelyExecute; } });
|
|
93
|
-
Object.defineProperty(exports, "safelyExecuteWithTimeout", { enumerable: true, get: function () { return util_js_1.safelyExecuteWithTimeout; } });
|
|
94
|
-
Object.defineProperty(exports, "successfulFetch", { enumerable: true, get: function () { return util_js_1.successfulFetch; } });
|
|
95
|
-
Object.defineProperty(exports, "timeoutFetch", { enumerable: true, get: function () { return util_js_1.timeoutFetch; } });
|
|
96
|
-
Object.defineProperty(exports, "toChecksumHexAddress", { enumerable: true, get: function () { return util_js_1.toChecksumHexAddress; } });
|
|
97
|
-
Object.defineProperty(exports, "toHex", { enumerable: true, get: function () { return util_js_1.toHex; } });
|
|
98
|
-
Object.defineProperty(exports, "weiHexToGweiDec", { enumerable: true, get: function () { return util_js_1.weiHexToGweiDec; } });
|
|
99
|
-
Object.defineProperty(exports, "isEqualCaseInsensitive", { enumerable: true, get: function () { return util_js_1.isEqualCaseInsensitive; } });
|
|
100
|
-
__exportStar(require("./types.cjs"), exports);
|
|
101
|
-
__exportStar(require("./siwe.cjs"), exports);
|
|
102
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,oCAA8C;AAArC,4GAAA,kBAAkB,OAAA;AAC3B,wEAaoC;AAZlC,8HAAA,kBAAkB,OAAA;AAClB,wHAAA,YAAY,OAAA;AACZ,iIAAA,qBAAqB,OAAA;AACrB,2HAAA,eAAe,OAAA;AACf,0IAAA,8BAA8B,OAAA;AAC9B,sIAAA,0BAA0B,OAAA;AAC1B,4IAAA,gCAAgC,OAAA;AAChC,+HAAA,mBAAmB,OAAA;AACnB,8HAAA,kBAAkB,OAAA;AAClB,+HAAA,mBAAmB,OAAA;AACnB,qHAAA,SAAS,OAAA;AACT,sHAAA,UAAU,OAAA;AAQZ,gDAqCwB;AApCtB,mGAAA,GAAG,OAAA;AACH,qHAAA,qBAAqB,OAAA;AACrB,wHAAA,wBAAwB,OAAA;AACxB,gHAAA,gBAAgB,OAAA;AAChB,iHAAA,iBAAiB,OAAA;AACjB,sGAAA,MAAM,OAAA;AACN,uGAAA,OAAO,OAAA;AACP,qG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,gBAAgB,OAAA;AAChB,gGAAA,KAAK,OAAA;AACL,wGAAA,aAAa,OAAA;AACb,mHAAA,wBAAwB,OAAA;AACxB,0GAAA,eAAe,OAAA;AACf,uGAAA,YAAY,OAAA;AACZ,+GAAA,oBAAoB,OAAA;AACpB,gGAAA,KAAK,OAAA;AACL,0GAAA,eAAe,OAAA;AACf,iHAAA,sBAAsB,OAAA;AAExB,8CAA2B;AAC3B,6CAA0B","sourcesContent":["export { encodeFunctionData } from './abi.js';\nexport {\n BrokenCircuitError,\n CircuitState,\n CockatielEventEmitter,\n ConstantBackoff,\n DEFAULT_CIRCUIT_BREAK_DURATION,\n DEFAULT_DEGRADED_THRESHOLD,\n DEFAULT_MAX_CONSECUTIVE_FAILURES,\n DEFAULT_MAX_RETRIES,\n ExponentialBackoff,\n createServicePolicy,\n handleAll,\n handleWhen,\n} from './create-service-policy.js';\nexport type {\n CockatielEvent,\n CreateServicePolicyOptions,\n CockatielFailureReason,\n ServicePolicy,\n} from './create-service-policy.js';\nexport {\n RPC,\n FALL_BACK_VS_CURRENCY,\n IPFS_DEFAULT_GATEWAY_URL,\n GANACHE_CHAIN_ID,\n MAX_SAFE_CHAIN_ID,\n ERC721,\n ERC1155,\n ERC20,\n ERC721_INTERFACE_ID,\n ERC721_METADATA_INTERFACE_ID,\n ERC721_ENUMERABLE_INTERFACE_ID,\n ERC1155_INTERFACE_ID,\n ERC1155_METADATA_URI_INTERFACE_ID,\n ERC1155_TOKEN_RECEIVER_INTERFACE_ID,\n GWEI,\n ASSET_TYPES,\n TESTNET_TICKER_SYMBOLS,\n BUILT_IN_CUSTOM_NETWORKS_RPC,\n BUILT_IN_NETWORKS,\n OPENSEA_PROXY_URL,\n NFT_API_BASE_URL,\n NFT_API_VERSION,\n NFT_API_TIMEOUT,\n ORIGIN_METAMASK,\n ApprovalType,\n CHAIN_ID_TO_ETHERS_NETWORK_NAME_MAP,\n SECOND,\n SECONDS,\n MINUTE,\n MINUTES,\n HOUR,\n HOURS,\n DAY,\n DAYS,\n NETWORKS_BYPASSING_VALIDATION,\n CHAIN_IDS_WITH_NO_NATIVE_TOKEN,\n} from './constants.js';\nexport type { NonEmptyArray } from './util.js';\nexport {\n BNToHex,\n convertHexToDecimal,\n fetchWithErrorHandling,\n fractionBN,\n fromHex,\n getBuyURL,\n gweiDecToWEIBN,\n handleFetch,\n hexToBN,\n hexToText,\n HttpError,\n isNonEmptyArray,\n isPlainObject,\n isSafeChainId,\n isSafeDynamicKey,\n isSmartContractCode,\n isValidJson,\n isValidHexAddress,\n normalizeEnsName,\n query,\n safelyExecute,\n safelyExecuteWithTimeout,\n successfulFetch,\n timeoutFetch,\n toChecksumHexAddress,\n toHex,\n weiHexToGweiDec,\n isEqualCaseInsensitive,\n} from './util.js';\nexport * from './types.js';\nexport * from './siwe.js';\n"]}
|
package/dist/index.d.cts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,kBAAiB;AAC9C,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,qBAAqB,EACrB,eAAe,EACf,8BAA8B,EAC9B,0BAA0B,EAC1B,gCAAgC,EAChC,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,SAAS,EACT,UAAU,GACX,oCAAmC;AACpC,YAAY,EACV,cAAc,EACd,0BAA0B,EAC1B,sBAAsB,EACtB,aAAa,GACd,oCAAmC;AACpC,OAAO,EACL,GAAG,EACH,qBAAqB,EACrB,wBAAwB,EACxB,gBAAgB,EAChB,iBAAiB,EACjB,MAAM,EACN,OAAO,EACP,KAAK,EACL,mBAAmB,EACnB,4BAA4B,EAC5B,8BAA8B,EAC9B,oBAAoB,EACpB,iCAAiC,EACjC,mCAAmC,EACnC,IAAI,EACJ,WAAW,EACX,sBAAsB,EACtB,4BAA4B,EAC5B,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,eAAe,EACf,YAAY,EACZ,mCAAmC,EACnC,MAAM,EACN,OAAO,EACP,MAAM,EACN,OAAO,EACP,IAAI,EACJ,KAAK,EACL,GAAG,EACH,IAAI,EACJ,6BAA6B,EAC7B,8BAA8B,GAC/B,wBAAuB;AACxB,YAAY,EAAE,aAAa,EAAE,mBAAkB;AAC/C,OAAO,EACL,OAAO,EACP,mBAAmB,EACnB,sBAAsB,EACtB,UAAU,EACV,OAAO,EACP,SAAS,EACT,cAAc,EACd,WAAW,EACX,OAAO,EACP,SAAS,EACT,SAAS,EACT,eAAe,EACf,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,mBAAmB,EACnB,WAAW,EACX,iBAAiB,EACjB,gBAAgB,EAChB,KAAK,EACL,aAAa,EACb,wBAAwB,EACxB,eAAe,EACf,YAAY,EACZ,oBAAoB,EACpB,KAAK,EACL,eAAe,EACf,sBAAsB,GACvB,mBAAkB;AACnB,4BAA2B;AAC3B,2BAA0B"}
|
package/dist/index.d.mts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export { encodeFunctionData } from "./abi.mjs";
|
|
2
|
-
export { BrokenCircuitError, CircuitState, CockatielEventEmitter, ConstantBackoff, DEFAULT_CIRCUIT_BREAK_DURATION, DEFAULT_DEGRADED_THRESHOLD, DEFAULT_MAX_CONSECUTIVE_FAILURES, DEFAULT_MAX_RETRIES, ExponentialBackoff, createServicePolicy, handleAll, handleWhen, } from "./create-service-policy.mjs";
|
|
3
|
-
export type { CockatielEvent, CreateServicePolicyOptions, CockatielFailureReason, ServicePolicy, } from "./create-service-policy.mjs";
|
|
4
|
-
export { RPC, FALL_BACK_VS_CURRENCY, IPFS_DEFAULT_GATEWAY_URL, GANACHE_CHAIN_ID, MAX_SAFE_CHAIN_ID, ERC721, ERC1155, ERC20, ERC721_INTERFACE_ID, ERC721_METADATA_INTERFACE_ID, ERC721_ENUMERABLE_INTERFACE_ID, ERC1155_INTERFACE_ID, ERC1155_METADATA_URI_INTERFACE_ID, ERC1155_TOKEN_RECEIVER_INTERFACE_ID, GWEI, ASSET_TYPES, TESTNET_TICKER_SYMBOLS, BUILT_IN_CUSTOM_NETWORKS_RPC, BUILT_IN_NETWORKS, OPENSEA_PROXY_URL, NFT_API_BASE_URL, NFT_API_VERSION, NFT_API_TIMEOUT, ORIGIN_METAMASK, ApprovalType, CHAIN_ID_TO_ETHERS_NETWORK_NAME_MAP, SECOND, SECONDS, MINUTE, MINUTES, HOUR, HOURS, DAY, DAYS, NETWORKS_BYPASSING_VALIDATION, CHAIN_IDS_WITH_NO_NATIVE_TOKEN, } from "./constants.mjs";
|
|
5
|
-
export type { NonEmptyArray } from "./util.mjs";
|
|
6
|
-
export { BNToHex, convertHexToDecimal, fetchWithErrorHandling, fractionBN, fromHex, getBuyURL, gweiDecToWEIBN, handleFetch, hexToBN, hexToText, HttpError, isNonEmptyArray, isPlainObject, isSafeChainId, isSafeDynamicKey, isSmartContractCode, isValidJson, isValidHexAddress, normalizeEnsName, query, safelyExecute, safelyExecuteWithTimeout, successfulFetch, timeoutFetch, toChecksumHexAddress, toHex, weiHexToGweiDec, isEqualCaseInsensitive, } from "./util.mjs";
|
|
7
|
-
export * from "./types.mjs";
|
|
8
|
-
export * from "./siwe.mjs";
|
|
9
|
-
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,kBAAiB;AAC9C,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,qBAAqB,EACrB,eAAe,EACf,8BAA8B,EAC9B,0BAA0B,EAC1B,gCAAgC,EAChC,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,SAAS,EACT,UAAU,GACX,oCAAmC;AACpC,YAAY,EACV,cAAc,EACd,0BAA0B,EAC1B,sBAAsB,EACtB,aAAa,GACd,oCAAmC;AACpC,OAAO,EACL,GAAG,EACH,qBAAqB,EACrB,wBAAwB,EACxB,gBAAgB,EAChB,iBAAiB,EACjB,MAAM,EACN,OAAO,EACP,KAAK,EACL,mBAAmB,EACnB,4BAA4B,EAC5B,8BAA8B,EAC9B,oBAAoB,EACpB,iCAAiC,EACjC,mCAAmC,EACnC,IAAI,EACJ,WAAW,EACX,sBAAsB,EACtB,4BAA4B,EAC5B,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,eAAe,EACf,YAAY,EACZ,mCAAmC,EACnC,MAAM,EACN,OAAO,EACP,MAAM,EACN,OAAO,EACP,IAAI,EACJ,KAAK,EACL,GAAG,EACH,IAAI,EACJ,6BAA6B,EAC7B,8BAA8B,GAC/B,wBAAuB;AACxB,YAAY,EAAE,aAAa,EAAE,mBAAkB;AAC/C,OAAO,EACL,OAAO,EACP,mBAAmB,EACnB,sBAAsB,EACtB,UAAU,EACV,OAAO,EACP,SAAS,EACT,cAAc,EACd,WAAW,EACX,OAAO,EACP,SAAS,EACT,SAAS,EACT,eAAe,EACf,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,mBAAmB,EACnB,WAAW,EACX,iBAAiB,EACjB,gBAAgB,EAChB,KAAK,EACL,aAAa,EACb,wBAAwB,EACxB,eAAe,EACf,YAAY,EACZ,oBAAoB,EACpB,KAAK,EACL,eAAe,EACf,sBAAsB,GACvB,mBAAkB;AACnB,4BAA2B;AAC3B,2BAA0B"}
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,kBAAiB;AAC9C,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,qBAAqB,EACrB,eAAe,EACf,8BAA8B,EAC9B,0BAA0B,EAC1B,gCAAgC,EAChC,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,SAAS,EACT,UAAU,EACX,oCAAmC;AAOpC,OAAO,EACL,GAAG,EACH,qBAAqB,EACrB,wBAAwB,EACxB,gBAAgB,EAChB,iBAAiB,EACjB,MAAM,EACN,OAAO,EACP,KAAK,EACL,mBAAmB,EACnB,4BAA4B,EAC5B,8BAA8B,EAC9B,oBAAoB,EACpB,iCAAiC,EACjC,mCAAmC,EACnC,IAAI,EACJ,WAAW,EACX,sBAAsB,EACtB,4BAA4B,EAC5B,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,eAAe,EACf,YAAY,EACZ,mCAAmC,EACnC,MAAM,EACN,OAAO,EACP,MAAM,EACN,OAAO,EACP,IAAI,EACJ,KAAK,EACL,GAAG,EACH,IAAI,EACJ,6BAA6B,EAC7B,8BAA8B,EAC/B,wBAAuB;AAExB,OAAO,EACL,OAAO,EACP,mBAAmB,EACnB,sBAAsB,EACtB,UAAU,EACV,OAAO,EACP,SAAS,EACT,cAAc,EACd,WAAW,EACX,OAAO,EACP,SAAS,EACT,SAAS,EACT,eAAe,EACf,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,mBAAmB,EACnB,WAAW,EACX,iBAAiB,EACjB,gBAAgB,EAChB,KAAK,EACL,aAAa,EACb,wBAAwB,EACxB,eAAe,EACf,YAAY,EACZ,oBAAoB,EACpB,KAAK,EACL,eAAe,EACf,sBAAsB,EACvB,mBAAkB;AACnB,4BAA2B;AAC3B,2BAA0B","sourcesContent":["export { encodeFunctionData } from './abi.js';\nexport {\n BrokenCircuitError,\n CircuitState,\n CockatielEventEmitter,\n ConstantBackoff,\n DEFAULT_CIRCUIT_BREAK_DURATION,\n DEFAULT_DEGRADED_THRESHOLD,\n DEFAULT_MAX_CONSECUTIVE_FAILURES,\n DEFAULT_MAX_RETRIES,\n ExponentialBackoff,\n createServicePolicy,\n handleAll,\n handleWhen,\n} from './create-service-policy.js';\nexport type {\n CockatielEvent,\n CreateServicePolicyOptions,\n CockatielFailureReason,\n ServicePolicy,\n} from './create-service-policy.js';\nexport {\n RPC,\n FALL_BACK_VS_CURRENCY,\n IPFS_DEFAULT_GATEWAY_URL,\n GANACHE_CHAIN_ID,\n MAX_SAFE_CHAIN_ID,\n ERC721,\n ERC1155,\n ERC20,\n ERC721_INTERFACE_ID,\n ERC721_METADATA_INTERFACE_ID,\n ERC721_ENUMERABLE_INTERFACE_ID,\n ERC1155_INTERFACE_ID,\n ERC1155_METADATA_URI_INTERFACE_ID,\n ERC1155_TOKEN_RECEIVER_INTERFACE_ID,\n GWEI,\n ASSET_TYPES,\n TESTNET_TICKER_SYMBOLS,\n BUILT_IN_CUSTOM_NETWORKS_RPC,\n BUILT_IN_NETWORKS,\n OPENSEA_PROXY_URL,\n NFT_API_BASE_URL,\n NFT_API_VERSION,\n NFT_API_TIMEOUT,\n ORIGIN_METAMASK,\n ApprovalType,\n CHAIN_ID_TO_ETHERS_NETWORK_NAME_MAP,\n SECOND,\n SECONDS,\n MINUTE,\n MINUTES,\n HOUR,\n HOURS,\n DAY,\n DAYS,\n NETWORKS_BYPASSING_VALIDATION,\n CHAIN_IDS_WITH_NO_NATIVE_TOKEN,\n} from './constants.js';\nexport type { NonEmptyArray } from './util.js';\nexport {\n BNToHex,\n convertHexToDecimal,\n fetchWithErrorHandling,\n fractionBN,\n fromHex,\n getBuyURL,\n gweiDecToWEIBN,\n handleFetch,\n hexToBN,\n hexToText,\n HttpError,\n isNonEmptyArray,\n isPlainObject,\n isSafeChainId,\n isSafeDynamicKey,\n isSmartContractCode,\n isValidJson,\n isValidHexAddress,\n normalizeEnsName,\n query,\n safelyExecute,\n safelyExecuteWithTimeout,\n successfulFetch,\n timeoutFetch,\n toChecksumHexAddress,\n toHex,\n weiHexToGweiDec,\n isEqualCaseInsensitive,\n} from './util.js';\nexport * from './types.js';\nexport * from './siwe.js';\n"]}
|
package/dist/logger.cjs
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createModuleLogger = exports.projectLogger = void 0;
|
|
4
|
-
const utils_1 = require("@metamask/utils");
|
|
5
|
-
Object.defineProperty(exports, "createModuleLogger", { enumerable: true, get: function () { return utils_1.createModuleLogger; } });
|
|
6
|
-
exports.projectLogger = (0, utils_1.createProjectLogger)('controller-utils');
|
|
7
|
-
//# sourceMappingURL=logger.cjs.map
|
package/dist/logger.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.cjs","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";;;AAAA,2CAA0E;AAIjE,mGAJqB,0BAAkB,OAIrB;AAFd,QAAA,aAAa,GAAG,IAAA,2BAAmB,EAAC,kBAAkB,CAAC,CAAC","sourcesContent":["import { createProjectLogger, createModuleLogger } from '@metamask/utils';\n\nexport const projectLogger = createProjectLogger('controller-utils');\n\nexport { createModuleLogger };\n"]}
|
package/dist/logger.d.cts
DELETED
package/dist/logger.d.cts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.cts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";AAAA,OAAO,EAAuB,kBAAkB,EAAE,wBAAwB;AAE1E,eAAO,MAAM,aAAa,0BAA0C,CAAC;AAErE,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
|
package/dist/logger.d.mts
DELETED
package/dist/logger.d.mts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.mts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";AAAA,OAAO,EAAuB,kBAAkB,EAAE,wBAAwB;AAE1E,eAAO,MAAM,aAAa,0BAA0C,CAAC;AAErE,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
|
package/dist/logger.mjs
DELETED
package/dist/logger.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.mjs","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,wBAAwB;AAE1E,MAAM,CAAC,MAAM,aAAa,GAAG,mBAAmB,CAAC,kBAAkB,CAAC,CAAC;AAErE,OAAO,EAAE,kBAAkB,EAAE,CAAC","sourcesContent":["import { createProjectLogger, createModuleLogger } from '@metamask/utils';\n\nexport const projectLogger = createProjectLogger('controller-utils');\n\nexport { createModuleLogger };\n"]}
|
package/dist/siwe.cjs
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.detectSIWE = exports.isValidSIWEOrigin = exports.parseDomainParts = void 0;
|
|
4
|
-
const utils_1 = require("@metamask/utils");
|
|
5
|
-
const siwe_parser_1 = require("@spruceid/siwe-parser");
|
|
6
|
-
const logger_js_1 = require("./logger.cjs");
|
|
7
|
-
const log = (0, logger_js_1.createModuleLogger)(logger_js_1.projectLogger, 'detect-siwe');
|
|
8
|
-
/**
|
|
9
|
-
* This function strips the hex prefix from a string if it has one.
|
|
10
|
-
* If the input is not a string, return it unmodified.
|
|
11
|
-
*
|
|
12
|
-
* @param str - The string to check
|
|
13
|
-
* @returns The string without the hex prefix
|
|
14
|
-
*/
|
|
15
|
-
function safeStripHexPrefix(str) {
|
|
16
|
-
if (typeof str !== 'string') {
|
|
17
|
-
return str;
|
|
18
|
-
}
|
|
19
|
-
return (0, utils_1.remove0x)(str);
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* This function converts a hex string to text if it's not a 32 byte hex string.
|
|
23
|
-
*
|
|
24
|
-
* @param hexValue - The hex string to convert to text
|
|
25
|
-
* @returns The text representation of the hex string
|
|
26
|
-
*/
|
|
27
|
-
function msgHexToText(hexValue) {
|
|
28
|
-
try {
|
|
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
|
|
33
|
-
const buff = Buffer.from(stripped, 'hex');
|
|
34
|
-
return buff.length === 32 ? hexValue : buff.toString('utf8');
|
|
35
|
-
}
|
|
36
|
-
catch (error) {
|
|
37
|
-
log(error);
|
|
38
|
-
return hexValue;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
const DEFAULT_PORTS_BY_PROTOCOL = {
|
|
42
|
-
'http:': '80',
|
|
43
|
-
'https:': '443',
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* Parses parts from RFC 3986 authority from EIP-4361 `domain` field.
|
|
47
|
-
*
|
|
48
|
-
* @param domain - input string
|
|
49
|
-
* @param originProtocol - implied protocol from origin
|
|
50
|
-
* @returns parsed parts
|
|
51
|
-
*/
|
|
52
|
-
const parseDomainParts = (domain, originProtocol) => {
|
|
53
|
-
if (domain.match(/^[^/:]*:\/\//u)) {
|
|
54
|
-
return new URL(domain);
|
|
55
|
-
}
|
|
56
|
-
return new URL(`${originProtocol}//${domain}`);
|
|
57
|
-
};
|
|
58
|
-
exports.parseDomainParts = parseDomainParts;
|
|
59
|
-
/**
|
|
60
|
-
* Validates origin of a Sign-In With Ethereum (SIWE)(EIP-4361) request.
|
|
61
|
-
* As per spec:
|
|
62
|
-
* hostname must match.
|
|
63
|
-
* port and username must match iff specified.
|
|
64
|
-
* Protocol binding and full same-origin are currently not performed.
|
|
65
|
-
*
|
|
66
|
-
* @param req - Signature request
|
|
67
|
-
* @returns true if origin matches domain; false otherwise
|
|
68
|
-
*/
|
|
69
|
-
const isValidSIWEOrigin = (req) => {
|
|
70
|
-
try {
|
|
71
|
-
const { origin, siwe } = req;
|
|
72
|
-
// origin = scheme://[user[:password]@]domain[:port]
|
|
73
|
-
// origin is supplied by environment and must match domain claim in message
|
|
74
|
-
if (!origin || !siwe?.parsedMessage?.domain) {
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
const originParts = new URL(origin);
|
|
78
|
-
const domainParts = (0, exports.parseDomainParts)(siwe.parsedMessage.domain, originParts.protocol);
|
|
79
|
-
if (domainParts.hostname.localeCompare(originParts.hostname, undefined, {
|
|
80
|
-
sensitivity: 'accent',
|
|
81
|
-
}) !== 0) {
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
if (domainParts.port !== '' && domainParts.port !== originParts.port) {
|
|
85
|
-
// If origin port is not specified, protocol default is implied
|
|
86
|
-
return (originParts.port === '' &&
|
|
87
|
-
domainParts.port === DEFAULT_PORTS_BY_PROTOCOL[originParts.protocol]);
|
|
88
|
-
}
|
|
89
|
-
if (domainParts.username !== '' &&
|
|
90
|
-
domainParts.username !== originParts.username) {
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
return true;
|
|
94
|
-
}
|
|
95
|
-
catch (error) {
|
|
96
|
-
log(error);
|
|
97
|
-
return false;
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
exports.isValidSIWEOrigin = isValidSIWEOrigin;
|
|
101
|
-
/**
|
|
102
|
-
* This function intercepts a sign message, detects if it's a
|
|
103
|
-
* Sign-In With Ethereum (SIWE)(EIP-4361) message, and returns an object with
|
|
104
|
-
* relevant SIWE data.
|
|
105
|
-
*
|
|
106
|
-
* {@see {@link https://eips.ethereum.org/EIPS/eip-4361}}
|
|
107
|
-
*
|
|
108
|
-
* @param msgParams - The params of the message to sign
|
|
109
|
-
* @param msgParams.data - The data of the message to sign
|
|
110
|
-
* @returns An object with the relevant SIWE data
|
|
111
|
-
*/
|
|
112
|
-
const detectSIWE = (msgParams) => {
|
|
113
|
-
try {
|
|
114
|
-
const { data } = msgParams;
|
|
115
|
-
const message = msgHexToText(data);
|
|
116
|
-
const parsedMessage = new siwe_parser_1.ParsedMessage(message);
|
|
117
|
-
return {
|
|
118
|
-
isSIWEMessage: true,
|
|
119
|
-
parsedMessage,
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
catch {
|
|
123
|
-
// ignore error, it's not a valid SIWE message
|
|
124
|
-
return {
|
|
125
|
-
isSIWEMessage: false,
|
|
126
|
-
parsedMessage: null,
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
exports.detectSIWE = detectSIWE;
|
|
131
|
-
//# sourceMappingURL=siwe.cjs.map
|
package/dist/siwe.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"siwe.cjs","sourceRoot":"","sources":["../src/siwe.ts"],"names":[],"mappings":";;;AAAA,2CAA2C;AAC3C,uDAAsD;AAEtD,4CAAgE;AAEhE,MAAM,GAAG,GAAG,IAAA,8BAAkB,EAAC,yBAAa,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,QAAgB;IACpC,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,kBAAkB,CAAC,QAAQ,CAAC,CAAC;QAC9C,uEAAuE;QACvE,cAAc;QACd,iDAAiD;QACjD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QAC1C,OAAO,IAAI,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC/D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,GAAG,CAAC,KAAK,CAAC,CAAC;QACX,OAAO,QAAQ,CAAC;IAClB,CAAC;AACH,CAAC;AA6BD,MAAM,yBAAyB,GAAG;I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W,CAAC,QAAQ,CAAC,CACrE,CAAC;QACJ,CAAC;QAED,IACE,WAAW,CAAC,QAAQ,KAAK,EAAE;YAC3B,WAAW,CAAC,QAAQ,KAAK,WAAW,CAAC,QAAQ,EAC7C,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,GAAG,CAAC,KAAK,CAAC,CAAC;QACX,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC,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.js';\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
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { ParsedMessage } from "@spruceid/siwe-parser";
|
|
2
|
-
/**
|
|
3
|
-
* @type WrappedSIWERequest
|
|
4
|
-
*
|
|
5
|
-
* Sign-In With Ethereum (SIWE)(EIP-4361) message with request metadata
|
|
6
|
-
*
|
|
7
|
-
* @property from - Subject account address
|
|
8
|
-
* @property origin - The RFC 3986 originating authority of the signing request, including scheme
|
|
9
|
-
* @property siwe - The data parsed from the message
|
|
10
|
-
*/
|
|
11
|
-
export interface WrappedSIWERequest {
|
|
12
|
-
from: string;
|
|
13
|
-
origin: string;
|
|
14
|
-
siwe: SIWEMessage;
|
|
15
|
-
}
|
|
16
|
-
interface DomainParts {
|
|
17
|
-
username?: string;
|
|
18
|
-
hostname: string;
|
|
19
|
-
port?: string;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Parses parts from RFC 3986 authority from EIP-4361 `domain` field.
|
|
23
|
-
*
|
|
24
|
-
* @param domain - input string
|
|
25
|
-
* @param originProtocol - implied protocol from origin
|
|
26
|
-
* @returns parsed parts
|
|
27
|
-
*/
|
|
28
|
-
export declare const parseDomainParts: (domain: string, originProtocol: string) => DomainParts;
|
|
29
|
-
/**
|
|
30
|
-
* Validates origin of a Sign-In With Ethereum (SIWE)(EIP-4361) request.
|
|
31
|
-
* As per spec:
|
|
32
|
-
* hostname must match.
|
|
33
|
-
* port and username must match iff specified.
|
|
34
|
-
* Protocol binding and full same-origin are currently not performed.
|
|
35
|
-
*
|
|
36
|
-
* @param req - Signature request
|
|
37
|
-
* @returns true if origin matches domain; false otherwise
|
|
38
|
-
*/
|
|
39
|
-
export declare const isValidSIWEOrigin: (req: WrappedSIWERequest) => boolean;
|
|
40
|
-
/**
|
|
41
|
-
* A locally defined object used to provide data to identify a Sign-In With Ethereum (SIWE)(EIP-4361) message and provide the parsed message
|
|
42
|
-
*
|
|
43
|
-
* @typedef SIWEMessage
|
|
44
|
-
* @param {boolean} isSIWEMessage - Does the intercepted message conform to the SIWE specification?
|
|
45
|
-
* @param {ParsedMessage} parsedMessage - The data parsed out of the message
|
|
46
|
-
*/
|
|
47
|
-
export type SIWEMessage = {
|
|
48
|
-
isSIWEMessage: true;
|
|
49
|
-
parsedMessage: ParsedMessage;
|
|
50
|
-
} | {
|
|
51
|
-
isSIWEMessage: false;
|
|
52
|
-
parsedMessage: null;
|
|
53
|
-
};
|
|
54
|
-
/**
|
|
55
|
-
* This function intercepts a sign message, detects if it's a
|
|
56
|
-
* Sign-In With Ethereum (SIWE)(EIP-4361) message, and returns an object with
|
|
57
|
-
* relevant SIWE data.
|
|
58
|
-
*
|
|
59
|
-
* {@see {@link https://eips.ethereum.org/EIPS/eip-4361}}
|
|
60
|
-
*
|
|
61
|
-
* @param msgParams - The params of the message to sign
|
|
62
|
-
* @param msgParams.data - The data of the message to sign
|
|
63
|
-
* @returns An object with the relevant SIWE data
|
|
64
|
-
*/
|
|
65
|
-
export declare const detectSIWE: (msgParams: {
|
|
66
|
-
data: string;
|
|
67
|
-
}) => SIWEMessage;
|
|
68
|
-
export {};
|
|
69
|
-
//# sourceMappingURL=siwe.d.cts.map
|
package/dist/siwe.d.cts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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,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ACf,GAAG,CAAC,KAAK,CAAC,CAAC;QACX,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC,CAAC;AAaF;;;;;;;;;;GAUG;AACH,MAAM,CAAC,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,aAAa,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","sourcesContent":["import { remove0x } from '@metamask/utils';\nimport { ParsedMessage } from '@spruceid/siwe-parser';\n\nimport { projectLogger, createModuleLogger } from './logger.js';\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"]}
|