@alchemy/common 0.0.0-alpha.0
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/LICENSE +21 -0
- package/dist/esm/actions/addBreadCrumb.d.ts +14 -0
- package/dist/esm/actions/addBreadCrumb.js +27 -0
- package/dist/esm/actions/addBreadCrumb.js.map +1 -0
- package/dist/esm/chains.d.ts +234 -0
- package/dist/esm/chains.js +113 -0
- package/dist/esm/chains.js.map +1 -0
- package/dist/esm/errors/AccountNotFoundError.d.ts +10 -0
- package/dist/esm/errors/AccountNotFoundError.js +19 -0
- package/dist/esm/errors/AccountNotFoundError.js.map +1 -0
- package/dist/esm/errors/BaseError.d.ts +23 -0
- package/dist/esm/errors/BaseError.js +40 -0
- package/dist/esm/errors/BaseError.js.map +1 -0
- package/dist/esm/errors/ChainNotFoundError.d.ts +11 -0
- package/dist/esm/errors/ChainNotFoundError.js +19 -0
- package/dist/esm/errors/ChainNotFoundError.js.map +1 -0
- package/dist/esm/errors/ConnectionConfigError.d.ts +13 -0
- package/dist/esm/errors/ConnectionConfigError.js +25 -0
- package/dist/esm/errors/ConnectionConfigError.js.map +1 -0
- package/dist/esm/errors/FetchError.d.ts +15 -0
- package/dist/esm/errors/FetchError.js +25 -0
- package/dist/esm/errors/FetchError.js.map +1 -0
- package/dist/esm/errors/InvalidRequestError.d.ts +13 -0
- package/dist/esm/errors/InvalidRequestError.js +22 -0
- package/dist/esm/errors/InvalidRequestError.js.map +1 -0
- package/dist/esm/errors/MethodUnsupportedError.d.ts +13 -0
- package/dist/esm/errors/MethodUnsupportedError.js +21 -0
- package/dist/esm/errors/MethodUnsupportedError.js.map +1 -0
- package/dist/esm/errors/ServerError.d.ts +15 -0
- package/dist/esm/errors/ServerError.js +25 -0
- package/dist/esm/errors/ServerError.js.map +1 -0
- package/dist/esm/index.d.ts +29 -0
- package/dist/esm/index.js +27 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/logging/config.d.ts +190 -0
- package/dist/esm/logging/config.js +279 -0
- package/dist/esm/logging/config.js.map +1 -0
- package/dist/esm/logging/index.d.ts +6 -0
- package/dist/esm/logging/index.js +5 -0
- package/dist/esm/logging/index.js.map +1 -0
- package/dist/esm/logging/local.d.ts +10 -0
- package/dist/esm/logging/local.js +35 -0
- package/dist/esm/logging/local.js.map +1 -0
- package/dist/esm/logging/logger.d.ts +80 -0
- package/dist/esm/logging/logger.js +111 -0
- package/dist/esm/logging/logger.js.map +1 -0
- package/dist/esm/logging/noop.d.ts +6 -0
- package/dist/esm/logging/noop.js +12 -0
- package/dist/esm/logging/noop.js.map +1 -0
- package/dist/esm/logging/sinks.d.ts +90 -0
- package/dist/esm/logging/sinks.js +111 -0
- package/dist/esm/logging/sinks.js.map +1 -0
- package/dist/esm/logging/types.d.ts +96 -0
- package/dist/esm/logging/types.js +2 -0
- package/dist/esm/logging/types.js.map +1 -0
- package/dist/esm/logging/utils.d.ts +7 -0
- package/dist/esm/logging/utils.js +21 -0
- package/dist/esm/logging/utils.js.map +1 -0
- package/dist/esm/rest/restClient.d.ts +34 -0
- package/dist/esm/rest/restClient.js +55 -0
- package/dist/esm/rest/restClient.js.map +1 -0
- package/dist/esm/rest/types.d.ts +24 -0
- package/dist/esm/rest/types.js +2 -0
- package/dist/esm/rest/types.js.map +1 -0
- package/dist/esm/tracing/traceHeader.d.ts +82 -0
- package/dist/esm/tracing/traceHeader.js +145 -0
- package/dist/esm/tracing/traceHeader.js.map +1 -0
- package/dist/esm/tracing/updateHeaders.d.ts +24 -0
- package/dist/esm/tracing/updateHeaders.js +61 -0
- package/dist/esm/tracing/updateHeaders.js.map +1 -0
- package/dist/esm/transport/alchemy.d.ts +110 -0
- package/dist/esm/transport/alchemy.js +164 -0
- package/dist/esm/transport/alchemy.js.map +1 -0
- package/dist/esm/transport/chainRegistry.d.ts +31 -0
- package/dist/esm/transport/chainRegistry.js +95 -0
- package/dist/esm/transport/chainRegistry.js.map +1 -0
- package/dist/esm/transport/connection.d.ts +20 -0
- package/dist/esm/transport/connection.js +2 -0
- package/dist/esm/transport/connection.js.map +1 -0
- package/dist/esm/transport/connectionSchema.d.ts +124 -0
- package/dist/esm/transport/connectionSchema.js +121 -0
- package/dist/esm/transport/connectionSchema.js.map +1 -0
- package/dist/esm/utils/assertNever.d.ts +8 -0
- package/dist/esm/utils/assertNever.js +12 -0
- package/dist/esm/utils/assertNever.js.map +1 -0
- package/dist/esm/utils/bigint.d.ts +24 -0
- package/dist/esm/utils/bigint.js +37 -0
- package/dist/esm/utils/bigint.js.map +1 -0
- package/dist/esm/utils/createEip1193HandlerFactory.d.ts +18 -0
- package/dist/esm/utils/createEip1193HandlerFactory.js +11 -0
- package/dist/esm/utils/createEip1193HandlerFactory.js.map +1 -0
- package/dist/esm/utils/headers.d.ts +7 -0
- package/dist/esm/utils/headers.js +29 -0
- package/dist/esm/utils/headers.js.map +1 -0
- package/dist/esm/utils/lowerAddress.d.ts +8 -0
- package/dist/esm/utils/lowerAddress.js +9 -0
- package/dist/esm/utils/lowerAddress.js.map +1 -0
- package/dist/esm/utils/raise.d.ts +8 -0
- package/dist/esm/utils/raise.js +14 -0
- package/dist/esm/utils/raise.js.map +1 -0
- package/dist/esm/utils/types.d.ts +10 -0
- package/dist/esm/utils/types.js +2 -0
- package/dist/esm/utils/types.js.map +1 -0
- package/dist/esm/version.d.ts +1 -0
- package/dist/esm/version.js +4 -0
- package/dist/esm/version.js.map +1 -0
- package/dist/types/actions/addBreadCrumb.d.ts +15 -0
- package/dist/types/actions/addBreadCrumb.d.ts.map +1 -0
- package/dist/types/chains.d.ts +235 -0
- package/dist/types/chains.d.ts.map +1 -0
- package/dist/types/errors/AccountNotFoundError.d.ts +11 -0
- package/dist/types/errors/AccountNotFoundError.d.ts.map +1 -0
- package/dist/types/errors/BaseError.d.ts +24 -0
- package/dist/types/errors/BaseError.d.ts.map +1 -0
- package/dist/types/errors/ChainNotFoundError.d.ts +12 -0
- package/dist/types/errors/ChainNotFoundError.d.ts.map +1 -0
- package/dist/types/errors/ConnectionConfigError.d.ts +14 -0
- package/dist/types/errors/ConnectionConfigError.d.ts.map +1 -0
- package/dist/types/errors/FetchError.d.ts +16 -0
- package/dist/types/errors/FetchError.d.ts.map +1 -0
- package/dist/types/errors/InvalidRequestError.d.ts +14 -0
- package/dist/types/errors/InvalidRequestError.d.ts.map +1 -0
- package/dist/types/errors/MethodUnsupportedError.d.ts +14 -0
- package/dist/types/errors/MethodUnsupportedError.d.ts.map +1 -0
- package/dist/types/errors/ServerError.d.ts +16 -0
- package/dist/types/errors/ServerError.d.ts.map +1 -0
- package/dist/types/index.d.ts +30 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/logging/config.d.ts +191 -0
- package/dist/types/logging/config.d.ts.map +1 -0
- package/dist/types/logging/index.d.ts +7 -0
- package/dist/types/logging/index.d.ts.map +1 -0
- package/dist/types/logging/local.d.ts +11 -0
- package/dist/types/logging/local.d.ts.map +1 -0
- package/dist/types/logging/logger.d.ts +81 -0
- package/dist/types/logging/logger.d.ts.map +1 -0
- package/dist/types/logging/noop.d.ts +7 -0
- package/dist/types/logging/noop.d.ts.map +1 -0
- package/dist/types/logging/sinks.d.ts +91 -0
- package/dist/types/logging/sinks.d.ts.map +1 -0
- package/dist/types/logging/types.d.ts +97 -0
- package/dist/types/logging/types.d.ts.map +1 -0
- package/dist/types/logging/utils.d.ts +8 -0
- package/dist/types/logging/utils.d.ts.map +1 -0
- package/dist/types/rest/restClient.d.ts +35 -0
- package/dist/types/rest/restClient.d.ts.map +1 -0
- package/dist/types/rest/types.d.ts +25 -0
- package/dist/types/rest/types.d.ts.map +1 -0
- package/dist/types/tracing/traceHeader.d.ts +83 -0
- package/dist/types/tracing/traceHeader.d.ts.map +1 -0
- package/dist/types/tracing/updateHeaders.d.ts +25 -0
- package/dist/types/tracing/updateHeaders.d.ts.map +1 -0
- package/dist/types/transport/alchemy.d.ts +111 -0
- package/dist/types/transport/alchemy.d.ts.map +1 -0
- package/dist/types/transport/chainRegistry.d.ts +32 -0
- package/dist/types/transport/chainRegistry.d.ts.map +1 -0
- package/dist/types/transport/connection.d.ts +21 -0
- package/dist/types/transport/connection.d.ts.map +1 -0
- package/dist/types/transport/connectionSchema.d.ts +125 -0
- package/dist/types/transport/connectionSchema.d.ts.map +1 -0
- package/dist/types/utils/assertNever.d.ts +9 -0
- package/dist/types/utils/assertNever.d.ts.map +1 -0
- package/dist/types/utils/bigint.d.ts +25 -0
- package/dist/types/utils/bigint.d.ts.map +1 -0
- package/dist/types/utils/createEip1193HandlerFactory.d.ts +19 -0
- package/dist/types/utils/createEip1193HandlerFactory.d.ts.map +1 -0
- package/dist/types/utils/headers.d.ts +8 -0
- package/dist/types/utils/headers.d.ts.map +1 -0
- package/dist/types/utils/lowerAddress.d.ts +9 -0
- package/dist/types/utils/lowerAddress.d.ts.map +1 -0
- package/dist/types/utils/raise.d.ts +9 -0
- package/dist/types/utils/raise.d.ts.map +1 -0
- package/dist/types/utils/types.d.ts +11 -0
- package/dist/types/utils/types.d.ts.map +1 -0
- package/dist/types/version.d.ts +2 -0
- package/dist/types/version.d.ts.map +1 -0
- package/package.json +67 -0
- package/src/actions/addBreadCrumb.ts +38 -0
- package/src/chains.ts +118 -0
- package/src/errors/AccountNotFoundError.ts +16 -0
- package/src/errors/BaseError.ts +51 -0
- package/src/errors/ChainNotFoundError.ts +15 -0
- package/src/errors/ConnectionConfigError.ts +22 -0
- package/src/errors/FetchError.ts +21 -0
- package/src/errors/InvalidRequestError.ts +19 -0
- package/src/errors/MethodUnsupportedError.ts +17 -0
- package/src/errors/ServerError.ts +21 -0
- package/src/index.ts +60 -0
- package/src/logging/config.ts +365 -0
- package/src/logging/index.ts +20 -0
- package/src/logging/local.ts +39 -0
- package/src/logging/logger.ts +194 -0
- package/src/logging/noop.ts +13 -0
- package/src/logging/sinks.ts +115 -0
- package/src/logging/types.ts +111 -0
- package/src/logging/utils.ts +31 -0
- package/src/rest/restClient.ts +64 -0
- package/src/rest/types.ts +42 -0
- package/src/tracing/traceHeader.ts +154 -0
- package/src/tracing/updateHeaders.ts +66 -0
- package/src/transport/alchemy.ts +242 -0
- package/src/transport/chainRegistry.ts +115 -0
- package/src/transport/connection.ts +19 -0
- package/src/transport/connectionSchema.ts +145 -0
- package/src/utils/assertNever.ts +12 -0
- package/src/utils/bigint.ts +58 -0
- package/src/utils/createEip1193HandlerFactory.ts +25 -0
- package/src/utils/headers.ts +48 -0
- package/src/utils/lowerAddress.ts +10 -0
- package/src/utils/raise.ts +14 -0
- package/src/utils/types.ts +14 -0
- package/src/version.ts +3 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* These are the headers that are used in the trace headers, could be found in the spec
|
|
3
|
+
*
|
|
4
|
+
* @see https://www.w3.org/TR/trace-context/#design-overview
|
|
5
|
+
*/
|
|
6
|
+
export declare const TRACE_HEADER_NAME = "traceparent";
|
|
7
|
+
/**
|
|
8
|
+
* These are the headers that are used in the trace headers, could be found in the spec
|
|
9
|
+
*
|
|
10
|
+
* @see https://www.w3.org/TR/trace-context/#design-overview
|
|
11
|
+
*/
|
|
12
|
+
export declare const TRACE_HEADER_STATE = "tracestate";
|
|
13
|
+
/**
|
|
14
|
+
* Some tools that are useful when dealing with the values
|
|
15
|
+
* of the trace header. Follows the W3C trace context standard.
|
|
16
|
+
*
|
|
17
|
+
* @see https://www.w3.org/TR/trace-context/
|
|
18
|
+
*/
|
|
19
|
+
export declare class TraceHeader {
|
|
20
|
+
readonly traceId: string;
|
|
21
|
+
readonly parentId: string;
|
|
22
|
+
readonly traceFlags: string;
|
|
23
|
+
readonly traceState: Record<string, string>;
|
|
24
|
+
/**
|
|
25
|
+
* Initializes a new instance with the provided trace identifiers and state information.
|
|
26
|
+
*
|
|
27
|
+
* @param {string} traceId The unique identifier for the trace
|
|
28
|
+
* @param {string} parentId The identifier of the parent trace
|
|
29
|
+
* @param {string} traceFlags Flags containing trace-related options
|
|
30
|
+
* @param {TraceHeader["traceState"]} traceState The trace state information for additional trace context
|
|
31
|
+
*/
|
|
32
|
+
constructor(traceId: string, parentId: string, traceFlags: string, traceState: TraceHeader["traceState"]);
|
|
33
|
+
/**
|
|
34
|
+
* Creating a default trace id that is a random setup for both trace id and parent id
|
|
35
|
+
*
|
|
36
|
+
* @example ```ts
|
|
37
|
+
* const traceHeader = TraceHeader.fromTraceHeader(headers) || TraceHeader.default();
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @returns {TraceHeader} A default trace header
|
|
41
|
+
*/
|
|
42
|
+
static default(): TraceHeader;
|
|
43
|
+
/**
|
|
44
|
+
* Should be able to consume a trace header from the headers of an http request
|
|
45
|
+
*
|
|
46
|
+
* @example ```ts
|
|
47
|
+
* const traceHeader = TraceHeader.fromTraceHeader(headers);
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @param {Record<string,string>} headers The headers from the http request
|
|
51
|
+
* @returns {TraceHeader | undefined} The trace header object, or nothing if not found
|
|
52
|
+
*/
|
|
53
|
+
static fromTraceHeader(headers: Record<string, string>): TraceHeader | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* Should be able to convert the trace header to the format that is used in the headers of an http request
|
|
56
|
+
*
|
|
57
|
+
* @example ```ts
|
|
58
|
+
* const traceHeader = TraceHeader.fromTraceHeader(headers) || TraceHeader.default();
|
|
59
|
+
* const headers = traceHeader.toTraceHeader();
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @returns {{traceparent: string, tracestate: string}} The trace header in the format of a record, used in our http client
|
|
63
|
+
*/
|
|
64
|
+
toTraceHeader(): {
|
|
65
|
+
readonly traceparent: `00-${string}-${string}-${string}`;
|
|
66
|
+
readonly tracestate: string;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Should be able to create a new trace header with a new event in the trace state,
|
|
70
|
+
* as the key of the eventName as breadcrumbs appending onto previous breadcrumbs with the - infix if exists. And the
|
|
71
|
+
* trace parent gets updated as according to the docs
|
|
72
|
+
*
|
|
73
|
+
* @example ```ts
|
|
74
|
+
* const traceHeader = TraceHeader.fromTraceHeader(headers) || TraceHeader.default();
|
|
75
|
+
* const newTraceHeader = traceHeader.withEvent("newEvent");
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* @param {string} eventName The key of the new event
|
|
79
|
+
* @returns {TraceHeader} The new trace header
|
|
80
|
+
*/
|
|
81
|
+
withEvent(eventName: string): TraceHeader;
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=traceHeader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traceHeader.d.ts","sourceRoot":"","sources":["../../../src/tracing/traceHeader.ts"],"names":[],"mappings":"AASA;;;;GAIG;AAEH,eAAO,MAAM,iBAAiB,gBAAgB,CAAC;AAC/C;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,eAAe,CAAC;AAG/C;;;;;GAKG;AACH,qBAAa,WAAW;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAE5C;;;;;;;OAOG;gBAED,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,WAAW,CAAC,YAAY,CAAC;IAQvC;;;;;;;;OAQG;IACH,MAAM,CAAC,OAAO;IAQd;;;;;;;;;OASG;IACH,MAAM,CAAC,eAAe,CACpB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC9B,WAAW,GAAG,SAAS;IA2B1B;;;;;;;;;OASG;IACH,aAAa;;;;IASb;;;;;;;;;;;;OAYG;IACH,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,WAAW;CAS1C"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remove the tracking headers. This is used in our split transport to ensure that we remove the headers that
|
|
3
|
+
* are not used by the other systems.
|
|
4
|
+
*
|
|
5
|
+
* @param {unknown} x The headers to remove the tracking headers from
|
|
6
|
+
*/
|
|
7
|
+
export declare function mutateRemoveTrackingHeaders(x?: unknown): void;
|
|
8
|
+
/**
|
|
9
|
+
* Update the headers with the trace header and breadcrumb.
|
|
10
|
+
*
|
|
11
|
+
* These trace headers are used in the imply ingestion pipeline to trace the request.
|
|
12
|
+
* And the breadcrumb is used to get finer grain details in the trace.
|
|
13
|
+
*
|
|
14
|
+
* Then there are the trace headers that are part of the W3C trace context standard.
|
|
15
|
+
*
|
|
16
|
+
* @param {string} crumb The crumb to add to the breadcrumb
|
|
17
|
+
* @returns {Function} A function that updates the headers
|
|
18
|
+
*/
|
|
19
|
+
export declare function headersUpdate(crumb: string): (x: Record<string, string>) => {
|
|
20
|
+
traceparent: `00-${string}-${string}-${string}`;
|
|
21
|
+
tracestate: string;
|
|
22
|
+
"X-Alchemy-Client-Breadcrumb": string;
|
|
23
|
+
"X-Alchemy-Client-Trace-Id": string;
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=updateHeaders.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updateHeaders.d.ts","sourceRoot":"","sources":["../../../src/tracing/updateHeaders.ts"],"names":[],"mappings":"AAqBA;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,CAAC,CAAC,EAAE,OAAO,QAQtD;AAMD;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,OACf,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;;;;;EAYjD"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { type Chain, type EIP1193RequestFn, type HttpTransportConfig, type RpcSchema, type Transport } from "viem";
|
|
2
|
+
/**
|
|
3
|
+
* Configuration options for the Alchemy transport.
|
|
4
|
+
* Extends viem's HttpTransportConfig with Alchemy-specific options while omitting
|
|
5
|
+
* options that are not relevant or supported by Alchemy.
|
|
6
|
+
*/
|
|
7
|
+
export interface AlchemyTransportConfig extends Omit<HttpTransportConfig, "batch" | "key" | "methods" | "name" | "raw"> {
|
|
8
|
+
/** API key for Alchemy authentication */
|
|
9
|
+
apiKey?: string;
|
|
10
|
+
/** JWT token for authentication */
|
|
11
|
+
jwt?: string;
|
|
12
|
+
/** Custom RPC URL (optional - defaults to chain's Alchemy URL, but can be used to override the chain's Alchemy URL) */
|
|
13
|
+
url?: string;
|
|
14
|
+
}
|
|
15
|
+
type AlchemyTransportBase<rpcSchema extends RpcSchema | undefined = undefined> = Transport<"alchemyHttp", {
|
|
16
|
+
alchemyRpcUrl: string;
|
|
17
|
+
fetchOptions: AlchemyTransportConfig["fetchOptions"];
|
|
18
|
+
config: AlchemyTransportConfig;
|
|
19
|
+
}, EIP1193RequestFn<rpcSchema>>;
|
|
20
|
+
export type AlchemyTransport<rpcSchema extends RpcSchema | undefined = undefined> = AlchemyTransportBase<rpcSchema> & {
|
|
21
|
+
updateHeaders(newHeaders: HeadersInit): void;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* A type guard for the transport to determine if it is an Alchemy transport.
|
|
25
|
+
* Used in cases where we would like to do switching depending on the transport.
|
|
26
|
+
*
|
|
27
|
+
* @param {Transport} transport The transport to check
|
|
28
|
+
* @param {Chain} chain Chain for the transport to run its function to return the transport config
|
|
29
|
+
* @returns {boolean} `true` if the transport is an Alchemy transport, otherwise `false`
|
|
30
|
+
*/
|
|
31
|
+
export declare function isAlchemyTransport(transport: Transport, chain: Chain): transport is AlchemyTransport;
|
|
32
|
+
/**
|
|
33
|
+
* Creates an Alchemy HTTP transport for connecting to Alchemy's services.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* Using API Key:
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { alchemyTransport } from "@alchemy/common";
|
|
39
|
+
*
|
|
40
|
+
* const transport = alchemyTransport({ apiKey: "your-api-key" });
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* Using JWT:
|
|
45
|
+
* ```ts
|
|
46
|
+
* import { alchemyTransport } from "@alchemy/common";
|
|
47
|
+
*
|
|
48
|
+
* const transport = alchemyTransport({ jwt: "your-jwt-token" });
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* Using URL directly:
|
|
53
|
+
* ```ts
|
|
54
|
+
* import { alchemyTransport } from "@alchemy/common";
|
|
55
|
+
*
|
|
56
|
+
* const transport = alchemyTransport({ url: "https://eth-mainnet.g.alchemy.com/v2/your-key" });
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* Using custom URL with API key:
|
|
61
|
+
* ```ts
|
|
62
|
+
* import { alchemyTransport } from "@alchemy/common";
|
|
63
|
+
*
|
|
64
|
+
* const transport = alchemyTransport({
|
|
65
|
+
* url: "https://custom-alchemy.com/v2",
|
|
66
|
+
* apiKey: "your-api-key"
|
|
67
|
+
* });
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* Using custom URL with JWT:
|
|
72
|
+
* ```ts
|
|
73
|
+
* import { alchemyTransport } from "@alchemy/common";
|
|
74
|
+
*
|
|
75
|
+
* const transport = alchemyTransport({
|
|
76
|
+
* url: "https://custom-alchemy.com/v2",
|
|
77
|
+
* jwt: "your-jwt-token"
|
|
78
|
+
* });
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* Using HTTP debugging options:
|
|
83
|
+
* ```ts
|
|
84
|
+
* import { alchemyTransport } from "@alchemy/common";
|
|
85
|
+
*
|
|
86
|
+
* const transport = alchemyTransport({
|
|
87
|
+
* apiKey: "your-api-key",
|
|
88
|
+
* onFetchRequest: (request) => console.log("Request:", request),
|
|
89
|
+
* onFetchResponse: (response) => console.log("Response:", response),
|
|
90
|
+
* timeout: 30000,
|
|
91
|
+
* retryCount: 3,
|
|
92
|
+
* retryDelay: 1000
|
|
93
|
+
* });
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* @param {AlchemyTransportConfig} config - The configuration object for the Alchemy transport (extends viem's HttpTransportConfig)
|
|
97
|
+
* @param {string} [config.apiKey] - API key for Alchemy authentication
|
|
98
|
+
* @param {string} [config.jwt] - JWT token for authentication
|
|
99
|
+
* @param {string} [config.url] - Direct URL to Alchemy endpoint or a proxy URL
|
|
100
|
+
* @param {Function} [config.onFetchRequest] - Callback for debugging outgoing requests
|
|
101
|
+
* @param {Function} [config.onFetchResponse] - Callback for debugging responses
|
|
102
|
+
* @param {number} [config.timeout] - Request timeout in milliseconds
|
|
103
|
+
* @param {number} [config.retryCount] - The number of retry attempts
|
|
104
|
+
* @param {number} [config.retryDelay] - The delay between retries, in milliseconds
|
|
105
|
+
* @param {object} [config.fetchOptions] - Optional fetch options for HTTP requests
|
|
106
|
+
* @param {object} [config.httpOptions] - HTTP transport options for debugging (onFetchRequest, onFetchResponse, timeout, batch)
|
|
107
|
+
* @returns {AlchemyTransport} The configured Alchemy transport function
|
|
108
|
+
*/
|
|
109
|
+
export declare function alchemyTransport<rpcSchema extends RpcSchema | undefined = undefined>(config: AlchemyTransportConfig): AlchemyTransport<rpcSchema>;
|
|
110
|
+
export {};
|
|
111
|
+
//# sourceMappingURL=alchemy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alchemy.d.ts","sourceRoot":"","sources":["../../../src/transport/alchemy.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,KAAK,EACV,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,KAAK,SAAS,EACd,KAAK,SAAS,EACf,MAAM,MAAM,CAAC;AAUd;;;;GAIG;AACH,MAAM,WAAW,sBACf,SAAQ,IAAI,CACV,mBAAmB,EACnB,OAAO,GAAG,KAAK,GAAG,SAAS,GAAG,MAAM,GAAG,KAAK,CAC7C;IACD,yCAAyC;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,mCAAmC;IACnC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,uHAAuH;IACvH,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,KAAK,oBAAoB,CAAC,SAAS,SAAS,SAAS,GAAG,SAAS,GAAG,SAAS,IAC3E,SAAS,CACP,aAAa,EACb;IACE,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,sBAAsB,CAAC,cAAc,CAAC,CAAC;IACrD,MAAM,EAAE,sBAAsB,CAAC;CAChC,EACD,gBAAgB,CAAC,SAAS,CAAC,CAC5B,CAAC;AAEJ,MAAM,MAAM,gBAAgB,CAC1B,SAAS,SAAS,SAAS,GAAG,SAAS,GAAG,SAAS,IACjD,oBAAoB,CAAC,SAAS,CAAC,GAAG;IACpC,aAAa,CAAC,UAAU,EAAE,WAAW,GAAG,IAAI,CAAC;CAC9C,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,KAAK,GACX,SAAS,IAAI,gBAAgB,CAE/B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4EG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,SAAS,SAAS,GAAG,SAAS,GAAG,SAAS,EACnD,MAAM,EAAE,sBAAsB,GAAG,gBAAgB,CAAC,SAAS,CAAC,CA8F7D"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal registry mapping chain IDs to Alchemy RPC base URLs.
|
|
3
|
+
* This replaces the need for custom chain exports with embedded Alchemy URLs.
|
|
4
|
+
*/
|
|
5
|
+
export declare const ALCHEMY_RPC_MAPPING: Record<number, string>;
|
|
6
|
+
/**
|
|
7
|
+
* Gets the Alchemy RPC base URL for a given chain ID.
|
|
8
|
+
*
|
|
9
|
+
* @param {number} chainId The chain ID to lookup
|
|
10
|
+
* @returns {string | undefined} The Alchemy RPC base URL or undefined if not supported
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const rpcUrl = getAlchemyRpcUrl(1); // "https://eth-mainnet.g.alchemy.com/v2"
|
|
15
|
+
* const customUrl = getAlchemyRpcUrl(999); // undefined
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function getAlchemyRpcUrl(chainId: number): string | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Checks if a chain ID is supported by the Alchemy RPC registry.
|
|
21
|
+
*
|
|
22
|
+
* @param {number} chainId The chain ID to check
|
|
23
|
+
* @returns {boolean} True if the chain is supported, false otherwise
|
|
24
|
+
*/
|
|
25
|
+
export declare function isChainSupported(chainId: number): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Gets all supported chain IDs from the registry.
|
|
28
|
+
*
|
|
29
|
+
* @returns {number[]} Array of supported chain IDs
|
|
30
|
+
*/
|
|
31
|
+
export declare function getSupportedChainIds(): number[];
|
|
32
|
+
//# sourceMappingURL=chainRegistry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chainRegistry.d.ts","sourceRoot":"","sources":["../../../src/transport/chainRegistry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CA2EtD,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAEpE;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAEzD;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,EAAE,CAE/C"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Never } from "../utils/types";
|
|
2
|
+
type AlchemyConnectionBaseConfig = {
|
|
3
|
+
proxyUrl: string;
|
|
4
|
+
apiKey?: never;
|
|
5
|
+
jwt?: never;
|
|
6
|
+
} | {
|
|
7
|
+
proxyUrl?: never;
|
|
8
|
+
apiKey: string;
|
|
9
|
+
jwt?: never;
|
|
10
|
+
} | {
|
|
11
|
+
proxyUrl?: never;
|
|
12
|
+
apiKey?: never;
|
|
13
|
+
jwt: string;
|
|
14
|
+
};
|
|
15
|
+
type AAOnlyChainConfig = {
|
|
16
|
+
alchemyConnection: AlchemyConnectionBaseConfig;
|
|
17
|
+
nodeRpcUrl: string;
|
|
18
|
+
};
|
|
19
|
+
export type AlchemyConnectionConfig = (AlchemyConnectionBaseConfig & Never<AAOnlyChainConfig>) | (AAOnlyChainConfig & Never<AlchemyConnectionBaseConfig>);
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=connection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../../src/transport/connection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAG5C,KAAK,2BAA2B,GAI5B;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,KAAK,CAAC;IAAC,GAAG,CAAC,EAAE,KAAK,CAAA;CAAE,GACjD;IAAE,QAAQ,CAAC,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,KAAK,CAAA;CAAE,GACjD;IAAE,QAAQ,CAAC,EAAE,KAAK,CAAC;IAAC,MAAM,CAAC,EAAE,KAAK,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AAEtD,KAAK,iBAAiB,GAAG;IACvB,iBAAiB,EAAE,2BAA2B,CAAC;IAC/C,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAC/B,CAAC,2BAA2B,GAAG,KAAK,CAAC,iBAAiB,CAAC,CAAC,GACxD,CAAC,iBAAiB,GAAG,KAAK,CAAC,2BAA2B,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Alchemy Connection Configuration Schema
|
|
4
|
+
*
|
|
5
|
+
* Provides three authentication options for connecting to Alchemy services:
|
|
6
|
+
*
|
|
7
|
+
* 1. **API Key**: Authenticate using your Alchemy API key
|
|
8
|
+
* 2. **JWT**: Authenticate using a JWT token
|
|
9
|
+
* 3. **URL**: Connect directly using a full RPC URL
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* Using API Key (uses chain's Alchemy URL):
|
|
13
|
+
* ```ts
|
|
14
|
+
* { apiKey: 'abc123' }
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* Using JWT (uses chain's Alchemy URL):
|
|
19
|
+
* ```ts
|
|
20
|
+
* { jwt: 'eyJhbGc...' }
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* Using direct URL only:
|
|
25
|
+
* ```ts
|
|
26
|
+
* { url: 'https://eth-mainnet.g.alchemy.com/v2/your-key' }
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* Using custom URL with API key:
|
|
31
|
+
* ```ts
|
|
32
|
+
* { url: 'https://custom-alchemy.com/v2', apiKey: 'abc123' }
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* Using custom URL with JWT:
|
|
37
|
+
* ```ts
|
|
38
|
+
* { url: 'https://custom-alchemy.com/v2', jwt: 'eyJhbGc...' }
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
/**
|
|
42
|
+
* Main connection configuration allowing flexible combinations.
|
|
43
|
+
* Can specify URL, auth method, or both together.
|
|
44
|
+
*/
|
|
45
|
+
export declare const AlchemyConnectionConfigSchema: z.ZodEffects<z.ZodEffects<z.ZodObject<{
|
|
46
|
+
/** API key for Alchemy authentication */
|
|
47
|
+
apiKey: z.ZodOptional<z.ZodString>;
|
|
48
|
+
/** JWT token for authentication */
|
|
49
|
+
jwt: z.ZodOptional<z.ZodString>;
|
|
50
|
+
/** Custom RPC URL (optional - defaults to chain's Alchemy URL) */
|
|
51
|
+
url: z.ZodOptional<z.ZodString>;
|
|
52
|
+
}, "strict", z.ZodTypeAny, {
|
|
53
|
+
apiKey?: string | undefined;
|
|
54
|
+
jwt?: string | undefined;
|
|
55
|
+
url?: string | undefined;
|
|
56
|
+
}, {
|
|
57
|
+
apiKey?: string | undefined;
|
|
58
|
+
jwt?: string | undefined;
|
|
59
|
+
url?: string | undefined;
|
|
60
|
+
}>, {
|
|
61
|
+
apiKey?: string | undefined;
|
|
62
|
+
jwt?: string | undefined;
|
|
63
|
+
url?: string | undefined;
|
|
64
|
+
}, {
|
|
65
|
+
apiKey?: string | undefined;
|
|
66
|
+
jwt?: string | undefined;
|
|
67
|
+
url?: string | undefined;
|
|
68
|
+
}>, {
|
|
69
|
+
apiKey?: string | undefined;
|
|
70
|
+
jwt?: string | undefined;
|
|
71
|
+
url?: string | undefined;
|
|
72
|
+
}, {
|
|
73
|
+
apiKey?: string | undefined;
|
|
74
|
+
jwt?: string | undefined;
|
|
75
|
+
url?: string | undefined;
|
|
76
|
+
}>;
|
|
77
|
+
/**
|
|
78
|
+
* TypeScript type derived from the schema for external consumption.
|
|
79
|
+
* This provides clean type inference without exposing Zod implementation details.
|
|
80
|
+
*/
|
|
81
|
+
export type AlchemyConnectionConfig = z.infer<typeof AlchemyConnectionConfigSchema>;
|
|
82
|
+
/**
|
|
83
|
+
* Validates an Alchemy connection configuration object.
|
|
84
|
+
*
|
|
85
|
+
* @param {unknown} config - The configuration object to validate
|
|
86
|
+
* @returns {AlchemyConnectionConfig} The validated configuration object
|
|
87
|
+
* @throws {ConnectionConfigError} If the configuration is invalid
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* try {
|
|
92
|
+
* const config = validateAlchemyConnectionConfig({
|
|
93
|
+
* apiKey: 'your-api-key'
|
|
94
|
+
* });
|
|
95
|
+
* // config is now typed as AlchemyConnectionConfig
|
|
96
|
+
* } catch (error) {
|
|
97
|
+
* if (error instanceof ConnectionConfigError) {
|
|
98
|
+
* console.error('Invalid config:', error.message);
|
|
99
|
+
* }
|
|
100
|
+
* }
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export declare function validateAlchemyConnectionConfig(config: unknown): AlchemyConnectionConfig;
|
|
104
|
+
/**
|
|
105
|
+
* Type guard to check if a value is a valid Alchemy connection config.
|
|
106
|
+
*
|
|
107
|
+
* @param {unknown} value - The value to check for validity
|
|
108
|
+
* @returns {boolean} True if the value is a valid Alchemy connection config
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* const maybeConfig: unknown = { apiKey: 'test' };
|
|
113
|
+
* if (isAlchemyConnectionConfig(maybeConfig)) {
|
|
114
|
+
* // TypeScript knows maybeConfig is AlchemyConnectionConfig here
|
|
115
|
+
* if (maybeConfig.apiKey) {
|
|
116
|
+
* console.log('Using API key:', maybeConfig.apiKey);
|
|
117
|
+
* }
|
|
118
|
+
* if (maybeConfig.url) {
|
|
119
|
+
* console.log('Using custom URL:', maybeConfig.url);
|
|
120
|
+
* }
|
|
121
|
+
* }
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
export declare function isAlchemyConnectionConfig(value: unknown): value is AlchemyConnectionConfig;
|
|
125
|
+
//# sourceMappingURL=connectionSchema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connectionSchema.d.ts","sourceRoot":"","sources":["../../../src/transport/connectionSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH;;;GAGG;AACH,eAAO,MAAM,6BAA6B;IAEtC,yCAAyC;;IAEzC,mCAAmC;;IAEnC,kEAAkE;;;;;;;;;;;;;;;;;;;;;;;;;;EAsBnE,CAAC;AAEJ;;;GAGG;AACH,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAC3C,OAAO,6BAA6B,CACrC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,+BAA+B,CAC7C,MAAM,EAAE,OAAO,GACd,uBAAuB,CAUzB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,uBAAuB,CAElC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asserts that a value is never.
|
|
3
|
+
*
|
|
4
|
+
* @param {never} _x - The value to assert.
|
|
5
|
+
* @param {string} msg - The message to throw if the value is not never.
|
|
6
|
+
* @returns {never} Always throws an error.
|
|
7
|
+
*/
|
|
8
|
+
export declare const assertNever: (_x: never, msg: string) => never;
|
|
9
|
+
//# sourceMappingURL=assertNever.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assertNever.d.ts","sourceRoot":"","sources":["../../../src/utils/assertNever.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GAAI,IAAI,KAAK,EAAE,KAAK,MAAM,KAAG,KAEpD,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BigNumberish represents values that can be converted to BigInt
|
|
3
|
+
*/
|
|
4
|
+
export type BigNumberish = string | number | bigint;
|
|
5
|
+
/**
|
|
6
|
+
* Multiplier configuration for bigint multiplication
|
|
7
|
+
*/
|
|
8
|
+
export type Multiplier = {
|
|
9
|
+
multiplier: number;
|
|
10
|
+
};
|
|
11
|
+
export declare enum RoundingMode {
|
|
12
|
+
ROUND_DOWN = 0,
|
|
13
|
+
ROUND_UP = 1
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Given a bigint and a number (which can be a float), returns the bigint value.
|
|
17
|
+
* Note: this function has loss and will round down to the nearest integer.
|
|
18
|
+
*
|
|
19
|
+
* @param {BigNumberish} base - the number to be multiplied
|
|
20
|
+
* @param {number} multiplier - the amount to multiply by
|
|
21
|
+
* @param {RoundingMode} roundingMode - the rounding mode to use when calculating the percent. defaults to ROUND_UP
|
|
22
|
+
* @returns {bigint} the bigint value of the multiplication with the number rounded by the rounding mode
|
|
23
|
+
*/
|
|
24
|
+
export declare const bigIntMultiply: (base: BigNumberish, multiplier: Multiplier["multiplier"], roundingMode?: RoundingMode) => bigint;
|
|
25
|
+
//# sourceMappingURL=bigint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bigint.d.ts","sourceRoot":"","sources":["../../../src/utils/bigint.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAEpD;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,oBAAY,YAAY;IACtB,UAAU,IAAI;IACd,QAAQ,IAAI;CACb;AAcD;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,GACzB,MAAM,YAAY,EAClB,YAAY,UAAU,CAAC,YAAY,CAAC,EACpC,eAAc,YAAoC,WAgBnD,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a typed handler factory for EIP1193 request methods.
|
|
3
|
+
* This helps with Viem's typing within custom EIP1193 request functions by
|
|
4
|
+
* automatically casting input params and ensuring the result matches what is required.
|
|
5
|
+
*
|
|
6
|
+
* @returns {(params: unknown) => unknown} A function that creates a handler factory for specific methods
|
|
7
|
+
*/
|
|
8
|
+
export declare const createEip1193HandlerFactory: <TMethods extends readonly {
|
|
9
|
+
Method: string;
|
|
10
|
+
Parameters?: unknown;
|
|
11
|
+
ReturnType?: unknown;
|
|
12
|
+
}[]>() => <TMethod extends TMethods[number]["Method"]>(handle: (params: Extract<TMethods[number], {
|
|
13
|
+
Method: TMethod;
|
|
14
|
+
}>["Parameters"]) => Promise<Extract<TMethods[number], {
|
|
15
|
+
Method: TMethod;
|
|
16
|
+
}>["ReturnType"]>) => (params: unknown) => Promise<Extract<TMethods[number], {
|
|
17
|
+
Method: TMethod;
|
|
18
|
+
}>["ReturnType"]>;
|
|
19
|
+
//# sourceMappingURL=createEip1193HandlerFactory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createEip1193HandlerFactory.d.ts","sourceRoot":"","sources":["../../../src/utils/createEip1193HandlerFactory.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,2BAA2B,GAEpC,QAAQ,SAAS,SAAS;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,EAAE,QAEJ,OAAO,SAAS,QAAQ,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,EACzC,QAAQ,CACN,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;IAAE,MAAM,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC,YAAY,CAAC,KACjE,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;IAAE,MAAM,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC,YAAY,CAAC,CAAC,MAE3E,QAAQ,OAAO;YAFmC,OAAO;iBAMzD,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type WithAlchemyHeadersParams = {
|
|
2
|
+
headers?: HeadersInit;
|
|
3
|
+
apiKey?: string;
|
|
4
|
+
jwt?: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function withAlchemyHeaders({ headers, apiKey, jwt, }: WithAlchemyHeadersParams): Record<string, string>;
|
|
7
|
+
export declare function convertHeadersToObject(headers?: HeadersInit): Record<string, string>;
|
|
8
|
+
//# sourceMappingURL=headers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"headers.d.ts","sourceRoot":"","sources":["../../../src/utils/headers.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,wBAAwB,GAAG;IACrC,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,EACjC,OAAO,EACP,MAAM,EACN,GAAG,GACJ,EAAE,wBAAwB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAOnD;AAED,wBAAgB,sBAAsB,CACpC,OAAO,CAAC,EAAE,WAAW,GACpB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAwBxB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Address } from "viem";
|
|
2
|
+
/**
|
|
3
|
+
* Lowercase an address
|
|
4
|
+
*
|
|
5
|
+
* @param {Address} addr - The address to lowercase
|
|
6
|
+
* @returns {Address} The lowercase address
|
|
7
|
+
*/
|
|
8
|
+
export declare const lowerAddress: (addr: Address) => Address;
|
|
9
|
+
//# sourceMappingURL=lowerAddress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lowerAddress.d.ts","sourceRoot":"","sources":["../../../src/utils/lowerAddress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,MAAM,CAAC;AAEpC;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAI,MAAM,OAAO,KAAG,OACd,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BaseError } from "viem";
|
|
2
|
+
/**
|
|
3
|
+
* Raises an error.
|
|
4
|
+
*
|
|
5
|
+
* @param {string | BaseError} err - The error to raise.
|
|
6
|
+
* @returns {never} Always throws an error.
|
|
7
|
+
*/
|
|
8
|
+
export declare const raise: (err: string | BaseError) => never;
|
|
9
|
+
//# sourceMappingURL=raise.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"raise.d.ts","sourceRoot":"","sources":["../../../src/utils/raise.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAEjC;;;;;GAKG;AACH,eAAO,MAAM,KAAK,GAAI,KAAK,MAAM,GAAG,SAAS,KAAG,KAK/C,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type Never<T> = T extends object ? {
|
|
2
|
+
[K in keyof T]?: never;
|
|
3
|
+
} : never;
|
|
4
|
+
export type ExtractRpcMethod<T extends readonly {
|
|
5
|
+
Method: string;
|
|
6
|
+
Parameters?: unknown;
|
|
7
|
+
ReturnType: unknown;
|
|
8
|
+
}[], M extends T[number]["Method"]> = Extract<T[number], {
|
|
9
|
+
Method: M;
|
|
10
|
+
}>;
|
|
11
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/utils/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,GACnC;KACG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK;CACvB,GACD,KAAK,CAAC;AAEV,MAAM,MAAM,gBAAgB,CAC1B,CAAC,SAAS,SAAS;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,UAAU,EAAE,OAAO,CAAC;CACrB,EAAE,EACH,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,IAC3B,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE;IAAE,MAAM,EAAE,CAAC,CAAA;CAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,OAAO,UAAU,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@alchemy/common",
|
|
3
|
+
"version": "0.0.0-alpha.0",
|
|
4
|
+
"description": "A collection of interfaces and utilities to be used by other Alchemy packages",
|
|
5
|
+
"author": "Alchemy",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"private": false,
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "./dist/esm/index.js",
|
|
10
|
+
"module": "./dist/esm/index.js",
|
|
11
|
+
"types": "./dist/types/index.d.ts",
|
|
12
|
+
"typings": "./dist/types/index.d.ts",
|
|
13
|
+
"sideEffects": false,
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"src/**/*.ts",
|
|
17
|
+
"!dist/**/*.tsbuildinfo",
|
|
18
|
+
"!vitest.config.ts",
|
|
19
|
+
"!.env",
|
|
20
|
+
"!src/**/*.test.ts",
|
|
21
|
+
"!src/**/*.test-d.ts",
|
|
22
|
+
"!src/__tests__/**/*"
|
|
23
|
+
],
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./dist/types/index.d.ts",
|
|
27
|
+
"import": "./dist/esm/index.js",
|
|
28
|
+
"default": "./dist/esm/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./chains": {
|
|
31
|
+
"types": "./dist/types/chains.d.ts",
|
|
32
|
+
"import": "./dist/esm/chains.js",
|
|
33
|
+
"default": "./dist/esm/chains.js"
|
|
34
|
+
},
|
|
35
|
+
"./package.json": "./package.json"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"prebuild": "tsx ./inject-version.ts",
|
|
39
|
+
"build": "yarn clean && yarn build:esm && yarn build:types",
|
|
40
|
+
"build:esm": "tsc --project tsconfig.build.json --outDir ./dist/esm",
|
|
41
|
+
"build:types": "tsc --project tsconfig.build.json --declarationDir ./dist/types --emitDeclarationOnly --declaration --declarationMap",
|
|
42
|
+
"clean": "rm -rf ./dist",
|
|
43
|
+
"test": "vitest",
|
|
44
|
+
"test:run": "vitest run"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"typescript-template": "*"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"@aa-sdk/core": "*",
|
|
51
|
+
"@account-kit/infra": "*",
|
|
52
|
+
"viem": "^2.32.0"
|
|
53
|
+
},
|
|
54
|
+
"publishConfig": {
|
|
55
|
+
"access": "public",
|
|
56
|
+
"registry": "https://registry.npmjs.org/"
|
|
57
|
+
},
|
|
58
|
+
"repository": {
|
|
59
|
+
"type": "git",
|
|
60
|
+
"url": "git+https://github.com/alchemyplatform/aa-sdk.git"
|
|
61
|
+
},
|
|
62
|
+
"bugs": {
|
|
63
|
+
"url": "https://github.com/alchemyplatform/aa-sdk/issues"
|
|
64
|
+
},
|
|
65
|
+
"homepage": "https://github.com/alchemyplatform/aa-sdk#readme",
|
|
66
|
+
"gitHead": "c0301f7bb5f4499fe35b5850293be6170057fae6"
|
|
67
|
+
}
|