@alchemy/wallet-apis 0.0.0-alpha.18 → 0.0.0-alpha.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/actions/formatSign.d.ts +12 -10
- package/dist/esm/actions/formatSign.js +18 -12
- package/dist/esm/actions/formatSign.js.map +1 -1
- package/dist/esm/actions/getCapabilities.d.ts +27 -0
- package/dist/esm/actions/getCapabilities.js +49 -0
- package/dist/esm/actions/getCapabilities.js.map +1 -0
- package/dist/esm/actions/grantPermissions.d.ts +12 -14
- package/dist/esm/actions/grantPermissions.js +22 -18
- package/dist/esm/actions/grantPermissions.js.map +1 -1
- package/dist/esm/actions/listAccounts.d.ts +7 -9
- package/dist/esm/actions/listAccounts.js +11 -7
- package/dist/esm/actions/listAccounts.js.map +1 -1
- package/dist/esm/actions/prepareCalls.d.ts +27 -13
- package/dist/esm/actions/prepareCalls.js +39 -22
- package/dist/esm/actions/prepareCalls.js.map +1 -1
- package/dist/esm/actions/prepareSign.d.ts +12 -11
- package/dist/esm/actions/prepareSign.js +18 -17
- package/dist/esm/actions/prepareSign.js.map +1 -1
- package/dist/esm/actions/requestAccount.d.ts +7 -12
- package/dist/esm/actions/requestAccount.js +10 -2
- package/dist/esm/actions/requestAccount.js.map +1 -1
- package/dist/esm/actions/sendCalls.d.ts +10 -8
- package/dist/esm/actions/sendCalls.js +11 -9
- package/dist/esm/actions/sendCalls.js.map +1 -1
- package/dist/esm/actions/sendPreparedCalls.d.ts +13 -12
- package/dist/esm/actions/sendPreparedCalls.js +21 -15
- package/dist/esm/actions/sendPreparedCalls.js.map +1 -1
- package/dist/esm/actions/signMessage.d.ts +4 -3
- package/dist/esm/actions/signMessage.js +7 -4
- package/dist/esm/actions/signMessage.js.map +1 -1
- package/dist/esm/actions/signPreparedCalls.d.ts +18 -2
- package/dist/esm/actions/signPreparedCalls.js +1 -1
- package/dist/esm/actions/signPreparedCalls.js.map +1 -1
- package/dist/esm/actions/signSignatureRequest.d.ts +3 -2
- package/dist/esm/actions/signSignatureRequest.js +4 -9
- package/dist/esm/actions/signSignatureRequest.js.map +1 -1
- package/dist/esm/actions/signTypedData.d.ts +3 -2
- package/dist/esm/actions/signTypedData.js +6 -3
- package/dist/esm/actions/signTypedData.js.map +1 -1
- package/dist/esm/client.d.ts +1 -1
- package/dist/esm/client.js +1 -1
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/decorators/smartWalletActions.d.ts +3 -2
- package/dist/esm/decorators/smartWalletActions.js +4 -3
- package/dist/esm/decorators/smartWalletActions.js.map +1 -1
- package/dist/esm/experimental/actions/requestQuoteV0.d.ts +17 -14
- package/dist/esm/experimental/actions/requestQuoteV0.js +25 -22
- package/dist/esm/experimental/actions/requestQuoteV0.js.map +1 -1
- package/dist/esm/exports/index.d.ts +2 -0
- package/dist/esm/exports/index.js +1 -0
- package/dist/esm/exports/index.js.map +1 -1
- package/dist/esm/types.d.ts +3 -2
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils/capabilities.d.ts +48 -2
- package/dist/esm/utils/capabilities.js +58 -11
- package/dist/esm/utils/capabilities.js.map +1 -1
- package/dist/esm/utils/resolve.d.ts +7 -0
- package/dist/esm/utils/resolve.js +4 -0
- package/dist/esm/utils/resolve.js.map +1 -0
- package/dist/esm/utils/schema.d.ts +24 -0
- package/dist/esm/utils/schema.js +7 -0
- package/dist/esm/utils/schema.js.map +1 -0
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/types/actions/formatSign.d.ts +12 -10
- package/dist/types/actions/formatSign.d.ts.map +1 -1
- package/dist/types/actions/getCapabilities.d.ts +28 -0
- package/dist/types/actions/getCapabilities.d.ts.map +1 -0
- package/dist/types/actions/grantPermissions.d.ts +12 -14
- package/dist/types/actions/grantPermissions.d.ts.map +1 -1
- package/dist/types/actions/listAccounts.d.ts +7 -9
- package/dist/types/actions/listAccounts.d.ts.map +1 -1
- package/dist/types/actions/prepareCalls.d.ts +27 -13
- package/dist/types/actions/prepareCalls.d.ts.map +1 -1
- package/dist/types/actions/prepareSign.d.ts +12 -11
- package/dist/types/actions/prepareSign.d.ts.map +1 -1
- package/dist/types/actions/requestAccount.d.ts +7 -12
- package/dist/types/actions/requestAccount.d.ts.map +1 -1
- package/dist/types/actions/sendCalls.d.ts +10 -8
- package/dist/types/actions/sendCalls.d.ts.map +1 -1
- package/dist/types/actions/sendPreparedCalls.d.ts +13 -12
- package/dist/types/actions/sendPreparedCalls.d.ts.map +1 -1
- package/dist/types/actions/signMessage.d.ts +4 -3
- package/dist/types/actions/signMessage.d.ts.map +1 -1
- package/dist/types/actions/signPreparedCalls.d.ts +18 -2
- package/dist/types/actions/signPreparedCalls.d.ts.map +1 -1
- package/dist/types/actions/signSignatureRequest.d.ts +3 -2
- package/dist/types/actions/signSignatureRequest.d.ts.map +1 -1
- package/dist/types/actions/signTypedData.d.ts +3 -2
- package/dist/types/actions/signTypedData.d.ts.map +1 -1
- package/dist/types/client.d.ts +1 -1
- package/dist/types/decorators/smartWalletActions.d.ts +3 -2
- package/dist/types/decorators/smartWalletActions.d.ts.map +1 -1
- package/dist/types/experimental/actions/requestQuoteV0.d.ts +17 -14
- package/dist/types/experimental/actions/requestQuoteV0.d.ts.map +1 -1
- package/dist/types/exports/index.d.ts +2 -0
- package/dist/types/exports/index.d.ts.map +1 -1
- package/dist/types/types.d.ts +3 -2
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/capabilities.d.ts +48 -2
- package/dist/types/utils/capabilities.d.ts.map +1 -1
- package/dist/types/utils/resolve.d.ts +8 -0
- package/dist/types/utils/resolve.d.ts.map +1 -0
- package/dist/types/utils/schema.d.ts +25 -0
- package/dist/types/utils/schema.d.ts.map +1 -0
- package/dist/types/version.d.ts +1 -1
- package/package.json +5 -5
- package/src/actions/formatSign.ts +34 -28
- package/src/actions/getCapabilities.ts +64 -0
- package/src/actions/grantPermissions.ts +38 -31
- package/src/actions/listAccounts.ts +27 -20
- package/src/actions/prepareCalls.ts +82 -38
- package/src/actions/prepareSign.ts +36 -35
- package/src/actions/requestAccount.ts +21 -16
- package/src/actions/sendCalls.ts +18 -12
- package/src/actions/sendPreparedCalls.ts +48 -27
- package/src/actions/signMessage.ts +9 -11
- package/src/actions/signPreparedCalls.ts +32 -12
- package/src/actions/signSignatureRequest.ts +9 -14
- package/src/actions/signTypedData.ts +8 -10
- package/src/client.ts +1 -1
- package/src/decorators/smartWalletActions.ts +9 -7
- package/src/experimental/actions/requestQuoteV0.ts +51 -39
- package/src/exports/index.ts +2 -0
- package/src/types.ts +6 -2
- package/src/utils/capabilities.ts +118 -17
- package/src/utils/resolve.ts +11 -0
- package/src/utils/schema.ts +32 -0
- package/src/version.ts +1 -1
- package/dist/esm/utils/viemDecode.d.ts +0 -8
- package/dist/esm/utils/viemDecode.js +0 -231
- package/dist/esm/utils/viemDecode.js.map +0 -1
- package/dist/esm/utils/viemEncode.d.ts +0 -40
- package/dist/esm/utils/viemEncode.js +0 -216
- package/dist/esm/utils/viemEncode.js.map +0 -1
- package/dist/types/utils/viemDecode.d.ts +0 -9
- package/dist/types/utils/viemDecode.d.ts.map +0 -1
- package/dist/types/utils/viemEncode.d.ts +0 -41
- package/dist/types/utils/viemEncode.d.ts.map +0 -1
- package/src/utils/viemDecode.ts +0 -313
- package/src/utils/viemEncode.ts +0 -345
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import {
|
|
4
|
-
type
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import type { Prettify } from "viem";
|
|
2
|
+
import type { DistributiveOmit, InnerWalletApiClient } from "../types.ts";
|
|
3
|
+
import { wallet_formatSign as MethodSchema } from "@alchemy/wallet-api-types/rpc";
|
|
4
|
+
import { type AccountParam } from "../utils/resolve.js";
|
|
5
|
+
import { type MethodParams, type MethodResponse } from "../utils/schema.js";
|
|
6
|
+
type BaseFormatSignParams = MethodParams<typeof MethodSchema>;
|
|
7
|
+
type FormatSignResponse = MethodResponse<typeof MethodSchema>;
|
|
8
|
+
export type FormatSignParams = Prettify<DistributiveOmit<BaseFormatSignParams, "from" | "chainId"> & {
|
|
9
|
+
account?: AccountParam;
|
|
10
|
+
chainId?: number;
|
|
8
11
|
}>;
|
|
9
|
-
export type
|
|
10
|
-
export type FormatSignResult = Prettify<RpcSchema["ReturnType"]>;
|
|
12
|
+
export type FormatSignResult = FormatSignResponse;
|
|
11
13
|
/**
|
|
12
14
|
* Formats a signature request for signing messages or transactions.
|
|
13
15
|
*
|
|
@@ -19,7 +21,7 @@ export type FormatSignResult = Prettify<RpcSchema["ReturnType"]>;
|
|
|
19
21
|
* ```ts
|
|
20
22
|
* // Formats a signature
|
|
21
23
|
* const result = await client.formatSign({
|
|
22
|
-
*
|
|
24
|
+
* account: "0x1234...",
|
|
23
25
|
* signature: {
|
|
24
26
|
* type: "ecdsa",
|
|
25
27
|
* data: "0xabcd..."
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AccountNotFoundError } from "@alchemy/common";
|
|
1
|
+
import { wallet_formatSign as MethodSchema } from "@alchemy/wallet-api-types/rpc";
|
|
3
2
|
import { LOGGER } from "../logger.js";
|
|
3
|
+
import { resolveAddress } from "../utils/resolve.js";
|
|
4
|
+
import { Value } from "typebox/value";
|
|
5
|
+
import { methodSchema, } from "../utils/schema.js";
|
|
6
|
+
const schema = methodSchema(MethodSchema);
|
|
4
7
|
/**
|
|
5
8
|
* Formats a signature request for signing messages or transactions.
|
|
6
9
|
*
|
|
@@ -12,7 +15,7 @@ import { LOGGER } from "../logger.js";
|
|
|
12
15
|
* ```ts
|
|
13
16
|
* // Formats a signature
|
|
14
17
|
* const result = await client.formatSign({
|
|
15
|
-
*
|
|
18
|
+
* account: "0x1234...",
|
|
16
19
|
* signature: {
|
|
17
20
|
* type: "ecdsa",
|
|
18
21
|
* data: "0xabcd..."
|
|
@@ -21,18 +24,21 @@ import { LOGGER } from "../logger.js";
|
|
|
21
24
|
* ```
|
|
22
25
|
*/
|
|
23
26
|
export async function formatSign(client, params) {
|
|
24
|
-
const from = params.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
27
|
+
const from = params.account
|
|
28
|
+
? resolveAddress(params.account)
|
|
29
|
+
: client.account.address;
|
|
28
30
|
LOGGER.debug("formatSign:start");
|
|
29
|
-
const
|
|
31
|
+
const { account: _, chainId: __, ...rest } = params;
|
|
32
|
+
const rpcParams = Value.Encode(schema.request, {
|
|
33
|
+
...rest,
|
|
34
|
+
from,
|
|
35
|
+
chainId: params.chainId ?? client.chain.id,
|
|
36
|
+
});
|
|
37
|
+
const rpcResp = await client.request({
|
|
30
38
|
method: "wallet_formatSign",
|
|
31
|
-
params: [
|
|
32
|
-
{ ...params, from, chainId: params.chainId ?? toHex(client.chain.id) },
|
|
33
|
-
],
|
|
39
|
+
params: [rpcParams],
|
|
34
40
|
});
|
|
35
41
|
LOGGER.debug("formatSign:done");
|
|
36
|
-
return
|
|
42
|
+
return Value.Decode(schema.response, rpcResp);
|
|
37
43
|
}
|
|
38
44
|
//# sourceMappingURL=formatSign.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatSign.js","sourceRoot":"","sources":["../../../src/actions/formatSign.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"formatSign.js","sourceRoot":"","sources":["../../../src/actions/formatSign.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAClF,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,cAAc,EAAqB,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EACL,YAAY,GAGb,MAAM,oBAAoB,CAAC;AAE5B,MAAM,MAAM,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;AAa1C;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,MAA4B,EAC5B,MAAwB;IAExB,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO;QACzB,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC;QAChC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;IAE3B,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;IAEjC,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;IACpD,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE;QAC7C,GAAG,IAAI;QACP,IAAI;QACJ,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE;KACZ,CAAC,CAAC;IAElC,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QACnC,MAAM,EAAE,mBAAmB;QAC3B,MAAM,EAAE,CAAC,SAAS,CAAC;KACpB,CAAC,CAAC;IAEH,MAAM,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;IAChC,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import type { Prettify } from \"viem\";\nimport type { DistributiveOmit, InnerWalletApiClient } from \"../types.ts\";\nimport { wallet_formatSign as MethodSchema } from \"@alchemy/wallet-api-types/rpc\";\nimport { LOGGER } from \"../logger.js\";\nimport { resolveAddress, type AccountParam } from \"../utils/resolve.js\";\nimport { Value } from \"typebox/value\";\nimport {\n methodSchema,\n type MethodParams,\n type MethodResponse,\n} from \"../utils/schema.js\";\n\nconst schema = methodSchema(MethodSchema);\ntype BaseFormatSignParams = MethodParams<typeof MethodSchema>;\ntype FormatSignResponse = MethodResponse<typeof MethodSchema>;\n\nexport type FormatSignParams = Prettify<\n DistributiveOmit<BaseFormatSignParams, \"from\" | \"chainId\"> & {\n account?: AccountParam;\n chainId?: number;\n }\n>;\n\nexport type FormatSignResult = FormatSignResponse;\n\n/**\n * Formats a signature request for signing messages or transactions.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {FormatSignParams} params - Parameters for formatting the signature\n * @returns {Promise<FormatSignResult>} A Promise that resolves to the formatSign result containing the formatted signature.\n *\n * @example\n * ```ts\n * // Formats a signature\n * const result = await client.formatSign({\n * account: \"0x1234...\",\n * signature: {\n * type: \"ecdsa\",\n * data: \"0xabcd...\"\n * },\n * });\n * ```\n */\nexport async function formatSign(\n client: InnerWalletApiClient,\n params: FormatSignParams,\n): Promise<FormatSignResult> {\n const from = params.account\n ? resolveAddress(params.account)\n : client.account.address;\n\n LOGGER.debug(\"formatSign:start\");\n\n const { account: _, chainId: __, ...rest } = params;\n const rpcParams = Value.Encode(schema.request, {\n ...rest,\n from,\n chainId: params.chainId ?? client.chain.id,\n } satisfies BaseFormatSignParams);\n\n const rpcResp = await client.request({\n method: \"wallet_formatSign\",\n params: [rpcParams],\n });\n\n LOGGER.debug(\"formatSign:done\");\n return Value.Decode(schema.response, rpcResp);\n}\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { InnerWalletApiClient } from "../types.js";
|
|
2
|
+
import { type AccountParam } from "../utils/resolve.js";
|
|
3
|
+
export type GetCapabilitiesParams = {
|
|
4
|
+
account?: AccountParam;
|
|
5
|
+
chainId?: number;
|
|
6
|
+
};
|
|
7
|
+
export type GetCapabilitiesResult = Record<string, unknown>;
|
|
8
|
+
/**
|
|
9
|
+
* Gets the capabilities supported by the wallet for the given account.
|
|
10
|
+
* Delegates to viem's `getCapabilities` and renames `paymasterService`
|
|
11
|
+
* to `paymaster` for consistency with the SDK's public API.
|
|
12
|
+
*
|
|
13
|
+
* @param {InnerWalletApiClient} client - The wallet API client to use for the request
|
|
14
|
+
* @param {GetCapabilitiesParams} [params] - Optional parameters
|
|
15
|
+
* @param {AccountParam} [params.account] - The account to query capabilities for. Can be an address string or an object with an `address` property. Defaults to the client's account.
|
|
16
|
+
* @param {number} [params.chainId] - Optional chain ID to filter capabilities for. Defaults to the client's chain ID.
|
|
17
|
+
* @returns {Promise<GetCapabilitiesResult>} The capabilities for the given chain
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* const capabilities = await client.getCapabilities({
|
|
22
|
+
* account: "0x1234...",
|
|
23
|
+
* });
|
|
24
|
+
* // { paymaster: { supported: true }, atomic: { status: "supported" } }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function getCapabilities(client: InnerWalletApiClient, params?: GetCapabilitiesParams): Promise<GetCapabilitiesResult>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { getCapabilities as viemGetCapabilities } from "viem/actions";
|
|
2
|
+
import { resolveAddress } from "../utils/resolve.js";
|
|
3
|
+
/**
|
|
4
|
+
* Gets the capabilities supported by the wallet for the given account.
|
|
5
|
+
* Delegates to viem's `getCapabilities` and renames `paymasterService`
|
|
6
|
+
* to `paymaster` for consistency with the SDK's public API.
|
|
7
|
+
*
|
|
8
|
+
* @param {InnerWalletApiClient} client - The wallet API client to use for the request
|
|
9
|
+
* @param {GetCapabilitiesParams} [params] - Optional parameters
|
|
10
|
+
* @param {AccountParam} [params.account] - The account to query capabilities for. Can be an address string or an object with an `address` property. Defaults to the client's account.
|
|
11
|
+
* @param {number} [params.chainId] - Optional chain ID to filter capabilities for. Defaults to the client's chain ID.
|
|
12
|
+
* @returns {Promise<GetCapabilitiesResult>} The capabilities for the given chain
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const capabilities = await client.getCapabilities({
|
|
17
|
+
* account: "0x1234...",
|
|
18
|
+
* });
|
|
19
|
+
* // { paymaster: { supported: true }, atomic: { status: "supported" } }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export async function getCapabilities(client, params) {
|
|
23
|
+
const account = params?.account
|
|
24
|
+
? resolveAddress(params.account)
|
|
25
|
+
: client.account.address;
|
|
26
|
+
const chainId = params?.chainId ?? client.chain.id;
|
|
27
|
+
// Don't pass chainId to viem — the Alchemy API keys capabilities by a
|
|
28
|
+
// generic identifier (0) rather than the actual chain ID, so viem's
|
|
29
|
+
// chainId-based lookup would return undefined.
|
|
30
|
+
const viemResult = await viemGetCapabilities(client, { account });
|
|
31
|
+
// Look for capabilities matching the requested chainId, falling back to
|
|
32
|
+
// the generic "0" key that the Alchemy API uses.
|
|
33
|
+
const chainCaps = viemResult[chainId] ?? viemResult[0];
|
|
34
|
+
if (!chainCaps)
|
|
35
|
+
return {};
|
|
36
|
+
const result = {};
|
|
37
|
+
for (const [key, value] of Object.entries(chainCaps)) {
|
|
38
|
+
// Our paymaster capability interface is non-standard, so we rename it
|
|
39
|
+
// from `paymasterService` to `paymaster` when used in our SDK client.
|
|
40
|
+
if (key === "paymasterService") {
|
|
41
|
+
result["paymaster"] = value;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
result[key] = value;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=getCapabilities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getCapabilities.js","sourceRoot":"","sources":["../../../src/actions/getCapabilities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,IAAI,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAEtE,OAAO,EAAE,cAAc,EAAqB,MAAM,qBAAqB,CAAC;AASxE;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,MAA4B,EAC5B,MAA8B;IAE9B,MAAM,OAAO,GAAG,MAAM,EAAE,OAAO;QAC7B,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC;QAChC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;IAE3B,MAAM,OAAO,GAAG,MAAM,EAAE,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;IAEnD,sEAAsE;IACtE,oEAAoE;IACpE,+CAA+C;IAC/C,MAAM,UAAU,GAAG,MAAM,mBAAmB,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;IAElE,wEAAwE;IACxE,iDAAiD;IACjD,MAAM,SAAS,GAAG,UAAU,CAAC,OAAO,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;IAEvD,IAAI,CAAC,SAAS;QAAE,OAAO,EAAE,CAAC;IAE1B,MAAM,MAAM,GAA4B,EAAE,CAAC;IAC3C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QACrD,sEAAsE;QACtE,sEAAsE;QACtE,IAAI,GAAG,KAAK,kBAAkB,EAAE,CAAC;YAC/B,MAAM,CAAC,WAAW,CAAC,GAAG,KAAK,CAAC;QAC9B,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACtB,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { getCapabilities as viemGetCapabilities } from \"viem/actions\";\nimport type { InnerWalletApiClient } from \"../types.js\";\nimport { resolveAddress, type AccountParam } from \"../utils/resolve.js\";\n\nexport type GetCapabilitiesParams = {\n account?: AccountParam;\n chainId?: number;\n};\n\nexport type GetCapabilitiesResult = Record<string, unknown>;\n\n/**\n * Gets the capabilities supported by the wallet for the given account.\n * Delegates to viem's `getCapabilities` and renames `paymasterService`\n * to `paymaster` for consistency with the SDK's public API.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {GetCapabilitiesParams} [params] - Optional parameters\n * @param {AccountParam} [params.account] - The account to query capabilities for. Can be an address string or an object with an `address` property. Defaults to the client's account.\n * @param {number} [params.chainId] - Optional chain ID to filter capabilities for. Defaults to the client's chain ID.\n * @returns {Promise<GetCapabilitiesResult>} The capabilities for the given chain\n *\n * @example\n * ```ts\n * const capabilities = await client.getCapabilities({\n * account: \"0x1234...\",\n * });\n * // { paymaster: { supported: true }, atomic: { status: \"supported\" } }\n * ```\n */\nexport async function getCapabilities(\n client: InnerWalletApiClient,\n params?: GetCapabilitiesParams,\n): Promise<GetCapabilitiesResult> {\n const account = params?.account\n ? resolveAddress(params.account)\n : client.account.address;\n\n const chainId = params?.chainId ?? client.chain.id;\n\n // Don't pass chainId to viem — the Alchemy API keys capabilities by a\n // generic identifier (0) rather than the actual chain ID, so viem's\n // chainId-based lookup would return undefined.\n const viemResult = await viemGetCapabilities(client, { account });\n\n // Look for capabilities matching the requested chainId, falling back to\n // the generic \"0\" key that the Alchemy API uses.\n const chainCaps = viemResult[chainId] ?? viemResult[0];\n\n if (!chainCaps) return {};\n\n const result: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(chainCaps)) {\n // Our paymaster capability interface is non-standard, so we rename it\n // from `paymasterService` to `paymaster` when used in our SDK client.\n if (key === \"paymasterService\") {\n result[\"paymaster\"] = value;\n } else {\n result[key] = value;\n }\n }\n\n return result;\n}\n"]}
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import type { InnerWalletApiClient } from "../types.ts";
|
|
3
|
-
import
|
|
4
|
-
import type
|
|
5
|
-
type
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export type GrantPermissionsParams = Prettify<OptionalChainId<Omit<RpcSchema["Request"]["params"][0], "account">> & {
|
|
11
|
-
account?: Address;
|
|
1
|
+
import { type Hex, type Prettify } from "viem";
|
|
2
|
+
import type { DistributiveOmit, InnerWalletApiClient } from "../types.ts";
|
|
3
|
+
import { wallet_createSession as MethodSchema } from "@alchemy/wallet-api-types/rpc";
|
|
4
|
+
import { type AccountParam } from "../utils/resolve.js";
|
|
5
|
+
import { type MethodParams } from "../utils/schema.js";
|
|
6
|
+
type BaseCreateSessionParams = MethodParams<typeof MethodSchema>;
|
|
7
|
+
export type GrantPermissionsParams = Prettify<DistributiveOmit<BaseCreateSessionParams, "account" | "chainId"> & {
|
|
8
|
+
account?: AccountParam;
|
|
9
|
+
chainId?: number;
|
|
12
10
|
}>;
|
|
13
11
|
export type GrantPermissionsResult = Prettify<{
|
|
14
12
|
context: Hex;
|
|
@@ -19,7 +17,7 @@ export type GrantPermissionsResult = Prettify<{
|
|
|
19
17
|
*
|
|
20
18
|
* @param {InnerWalletApiClient} client - The wallet API client to use for the request
|
|
21
19
|
* @param {GrantPermissionsParams} params - The parameters for granting permissions
|
|
22
|
-
* @param {
|
|
20
|
+
* @param {AccountParam} [params.account] - The account (required if client was not initialized with an account). Can be an address string or an object with an `address` property.
|
|
23
21
|
* @param {number} params.expirySec - Unix timestamp when the permissions expire
|
|
24
22
|
* @param {sessionKeyData} params.key - The session key information
|
|
25
23
|
* @param {string} params.key.publicKey - The public key of the session key
|
|
@@ -45,10 +43,10 @@ export type GrantPermissionsResult = Prettify<{
|
|
|
45
43
|
*
|
|
46
44
|
* // Use the permissions to prepare a call
|
|
47
45
|
* const preparedCalls = await client.prepareCalls({
|
|
48
|
-
* calls: [{ to: zeroAddress, value:
|
|
46
|
+
* calls: [{ to: zeroAddress, value: 0n }],
|
|
49
47
|
* from: account.address,
|
|
50
48
|
* capabilities: {
|
|
51
|
-
*
|
|
49
|
+
* paymaster: {
|
|
52
50
|
* policyId: "your-paymaster-policy-id",
|
|
53
51
|
* },
|
|
54
52
|
* permissions,
|
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { concatHex } from "viem";
|
|
2
|
+
import { wallet_createSession as MethodSchema } from "@alchemy/wallet-api-types/rpc";
|
|
2
3
|
import { signSignatureRequest } from "./signSignatureRequest.js";
|
|
3
|
-
import { AccountNotFoundError } from "@alchemy/common";
|
|
4
4
|
import { LOGGER } from "../logger.js";
|
|
5
|
+
import { Value } from "typebox/value";
|
|
6
|
+
import { resolveAddress } from "../utils/resolve.js";
|
|
7
|
+
import { methodSchema } from "../utils/schema.js";
|
|
8
|
+
const schema = methodSchema(MethodSchema);
|
|
5
9
|
/**
|
|
6
10
|
* Grants permissions to a smart account by creating a session.
|
|
7
11
|
* This allows another key to perform operations on behalf of the account.
|
|
8
12
|
*
|
|
9
13
|
* @param {InnerWalletApiClient} client - The wallet API client to use for the request
|
|
10
14
|
* @param {GrantPermissionsParams} params - The parameters for granting permissions
|
|
11
|
-
* @param {
|
|
15
|
+
* @param {AccountParam} [params.account] - The account (required if client was not initialized with an account). Can be an address string or an object with an `address` property.
|
|
12
16
|
* @param {number} params.expirySec - Unix timestamp when the permissions expire
|
|
13
17
|
* @param {sessionKeyData} params.key - The session key information
|
|
14
18
|
* @param {string} params.key.publicKey - The public key of the session key
|
|
@@ -34,10 +38,10 @@ import { LOGGER } from "../logger.js";
|
|
|
34
38
|
*
|
|
35
39
|
* // Use the permissions to prepare a call
|
|
36
40
|
* const preparedCalls = await client.prepareCalls({
|
|
37
|
-
* calls: [{ to: zeroAddress, value:
|
|
41
|
+
* calls: [{ to: zeroAddress, value: 0n }],
|
|
38
42
|
* from: account.address,
|
|
39
43
|
* capabilities: {
|
|
40
|
-
*
|
|
44
|
+
* paymaster: {
|
|
41
45
|
* policyId: "your-paymaster-policy-id",
|
|
42
46
|
* },
|
|
43
47
|
* permissions,
|
|
@@ -57,22 +61,22 @@ import { LOGGER } from "../logger.js";
|
|
|
57
61
|
* ```
|
|
58
62
|
*/
|
|
59
63
|
export async function grantPermissions(client, params) {
|
|
60
|
-
const account = params.account
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
throw new AccountNotFoundError();
|
|
64
|
-
}
|
|
64
|
+
const account = params.account
|
|
65
|
+
? resolveAddress(params.account)
|
|
66
|
+
: client.account.address;
|
|
65
67
|
LOGGER.debug("grantPermissions:start", { expirySec: params.expirySec });
|
|
66
|
-
const
|
|
68
|
+
const chainId = params.chainId ?? client.chain.id;
|
|
69
|
+
const { account: _, chainId: __, ...rest } = params;
|
|
70
|
+
const rpcParams = Value.Encode(schema.request, {
|
|
71
|
+
...rest,
|
|
72
|
+
account,
|
|
73
|
+
chainId,
|
|
74
|
+
});
|
|
75
|
+
const rpcResp = await client.request({
|
|
67
76
|
method: "wallet_createSession",
|
|
68
|
-
params: [
|
|
69
|
-
{
|
|
70
|
-
...params,
|
|
71
|
-
account,
|
|
72
|
-
chainId: params.chainId ?? toHex(client.chain.id),
|
|
73
|
-
},
|
|
74
|
-
],
|
|
77
|
+
params: [rpcParams],
|
|
75
78
|
});
|
|
79
|
+
const { sessionId, signatureRequest } = Value.Decode(schema.response, rpcResp);
|
|
76
80
|
const signature = await signSignatureRequest(client, signatureRequest);
|
|
77
81
|
const res = {
|
|
78
82
|
context: concatHex([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grantPermissions.js","sourceRoot":"","sources":["../../../src/actions/grantPermissions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"grantPermissions.js","sourceRoot":"","sources":["../../../src/actions/grantPermissions.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,SAAS,EAAE,MAAM,MAAM,CAAC;AAE1D,OAAO,EAAE,oBAAoB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AACrF,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,cAAc,EAAqB,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,YAAY,EAAqB,MAAM,oBAAoB,CAAC;AAErE,MAAM,MAAM,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;AAc1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,MAA4B,EAC5B,MAA8B;IAE9B,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO;QAC5B,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC;QAChC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;IAE3B,MAAM,CAAC,KAAK,CAAC,wBAAwB,EAAE,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC;IAExE,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;IAElD,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;IACpD,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE;QAC7C,GAAG,IAAI;QACP,OAAO;QACP,OAAO;KAC0B,CAAC,CAAC;IAErC,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QACnC,MAAM,EAAE,sBAAsB;QAC9B,MAAM,EAAE,CAAC,SAAS,CAAC;KACpB,CAAC,CAAC;IAEH,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE,GAAG,KAAK,CAAC,MAAM,CAClD,MAAM,CAAC,QAAQ,EACf,OAAO,CAIR,CAAC;IAEF,MAAM,SAAS,GAAG,MAAM,oBAAoB,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAEvE,MAAM,GAAG,GAAG;QACV,OAAO,EAAE,SAAS,CAAC;YACjB,MAAM,EAAE,eAAe;YACvB,SAAS;YACT,SAAS,CAAC,IAAI;SACf,CAAC;KACM,CAAC;IACX,MAAM,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;IACtC,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { type Hex, type Prettify, concatHex } from \"viem\";\nimport type { DistributiveOmit, InnerWalletApiClient } from \"../types.ts\";\nimport { wallet_createSession as MethodSchema } from \"@alchemy/wallet-api-types/rpc\";\nimport { signSignatureRequest } from \"./signSignatureRequest.js\";\nimport { LOGGER } from \"../logger.js\";\nimport { Value } from \"typebox/value\";\nimport { resolveAddress, type AccountParam } from \"../utils/resolve.js\";\nimport { methodSchema, type MethodParams } from \"../utils/schema.js\";\n\nconst schema = methodSchema(MethodSchema);\ntype BaseCreateSessionParams = MethodParams<typeof MethodSchema>;\n\nexport type GrantPermissionsParams = Prettify<\n DistributiveOmit<BaseCreateSessionParams, \"account\" | \"chainId\"> & {\n account?: AccountParam;\n chainId?: number;\n }\n>;\n\nexport type GrantPermissionsResult = Prettify<{\n context: Hex;\n}>;\n\n/**\n * Grants permissions to a smart account by creating a session.\n * This allows another key to perform operations on behalf of the account.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {GrantPermissionsParams} params - The parameters for granting permissions\n * @param {AccountParam} [params.account] - The account (required if client was not initialized with an account). Can be an address string or an object with an `address` property.\n * @param {number} params.expirySec - Unix timestamp when the permissions expire\n * @param {sessionKeyData} params.key - The session key information\n * @param {string} params.key.publicKey - The public key of the session key\n * @param {string} params.key.type - The type of the key (e.g., \"secp256k1\")\n * @param {Array} params.permissions - Array of permission objects defining what the session key can do\n * @returns {Promise<GrantPermissionsResult>} A Promise that resolves to the result containing a context identifier\n *\n * @example\n * ```ts\n * // Create a session key and grant root permissions\n * const sessionKey = LocalAccountSigner.generatePrivateKeySigner();\n * const account = await client.requestAccount();\n *\n * const permissions = await client.grantPermissions({\n * account: account.address,\n * expirySec: Math.floor(Date.now() / 1000) + 60 * 60, // 1 hour from now\n * key: {\n * publicKey: await sessionKey.getAddress(),\n * type: \"secp256k1\",\n * },\n * permissions: [{ type: \"root\" }],\n * });\n *\n * // Use the permissions to prepare a call\n * const preparedCalls = await client.prepareCalls({\n * calls: [{ to: zeroAddress, value: 0n }],\n * from: account.address,\n * capabilities: {\n * paymaster: {\n * policyId: \"your-paymaster-policy-id\",\n * },\n * permissions,\n * },\n * });\n *\n * // Sign with the session key\n * const signedCalls = await signPreparedCalls(sessionKey, preparedCalls);\n *\n * // Send the prepared call using the session key\n * const result = await client.sendPreparedCalls({\n * ...signedCalls,\n * capabilities: {\n * permissions,\n * },\n * });\n * ```\n */\nexport async function grantPermissions(\n client: InnerWalletApiClient,\n params: GrantPermissionsParams,\n): Promise<GrantPermissionsResult> {\n const account = params.account\n ? resolveAddress(params.account)\n : client.account.address;\n\n LOGGER.debug(\"grantPermissions:start\", { expirySec: params.expirySec });\n\n const chainId = params.chainId ?? client.chain.id;\n\n const { account: _, chainId: __, ...rest } = params;\n const rpcParams = Value.Encode(schema.request, {\n ...rest,\n account,\n chainId,\n } satisfies BaseCreateSessionParams);\n\n const rpcResp = await client.request({\n method: \"wallet_createSession\",\n params: [rpcParams],\n });\n\n const { sessionId, signatureRequest } = Value.Decode(\n schema.response,\n rpcResp,\n ) satisfies {\n sessionId: Hex;\n signatureRequest: Parameters<typeof signSignatureRequest>[1];\n };\n\n const signature = await signSignatureRequest(client, signatureRequest);\n\n const res = {\n context: concatHex([\n \"0x00\", // Remote mode.\n sessionId,\n signature.data,\n ]),\n } as const;\n LOGGER.debug(\"grantPermissions:done\");\n return res;\n}\n"]}
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import type { InnerWalletApiClient } from "../types.ts";
|
|
1
|
+
import type { DistributiveOmit, InnerWalletApiClient } from "../types.ts";
|
|
2
2
|
import type { Address, Prettify } from "viem";
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}>;
|
|
9
|
-
export type ListAccountsParams = Prettify<Omit<RpcSchema["Request"]["params"][0], "signerAddress" | "signerPublicKey"> & {
|
|
3
|
+
import { wallet_listAccounts as MethodSchema } from "@alchemy/wallet-api-types/rpc";
|
|
4
|
+
import { type MethodParams, type MethodResponse } from "../utils/schema.js";
|
|
5
|
+
type BaseListAccountsParams = MethodParams<typeof MethodSchema>;
|
|
6
|
+
type ListAccountsResponse = MethodResponse<typeof MethodSchema>;
|
|
7
|
+
export type ListAccountsParams = Prettify<DistributiveOmit<BaseListAccountsParams, "signerAddress" | "signerPublicKey"> & {
|
|
10
8
|
signerAddress?: Address;
|
|
11
9
|
signerPublicKey?: never;
|
|
12
10
|
}>;
|
|
13
|
-
export type ListAccountsResult =
|
|
11
|
+
export type ListAccountsResult = ListAccountsResponse;
|
|
14
12
|
/**
|
|
15
13
|
* Lists all smart accounts for a given signer using the wallet API client.
|
|
16
14
|
*
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { LOGGER } from "../logger.js";
|
|
2
|
+
import { wallet_listAccounts as MethodSchema } from "@alchemy/wallet-api-types/rpc";
|
|
2
3
|
import { isLocalAccount } from "../utils/assertions.js";
|
|
4
|
+
import { Value } from "typebox/value";
|
|
5
|
+
import { methodSchema, } from "../utils/schema.js";
|
|
6
|
+
const schema = methodSchema(MethodSchema);
|
|
3
7
|
/**
|
|
4
8
|
* Lists all smart accounts for a given signer using the wallet API client.
|
|
5
9
|
*
|
|
@@ -32,15 +36,15 @@ export async function listAccounts(client, params) {
|
|
|
32
36
|
? client.owner.address
|
|
33
37
|
: client.owner.account.address);
|
|
34
38
|
LOGGER.debug("listAccounts:start", { hasAfter: !!params.after });
|
|
35
|
-
const
|
|
39
|
+
const rpcParams = Value.Encode(schema.request, {
|
|
40
|
+
...params,
|
|
41
|
+
signerAddress,
|
|
42
|
+
});
|
|
43
|
+
const rpcResp = await client.request({
|
|
36
44
|
method: "wallet_listAccounts",
|
|
37
|
-
params: [
|
|
38
|
-
{
|
|
39
|
-
...params,
|
|
40
|
-
signerAddress,
|
|
41
|
-
},
|
|
42
|
-
],
|
|
45
|
+
params: [rpcParams],
|
|
43
46
|
});
|
|
47
|
+
const res = Value.Decode(schema.response, rpcResp);
|
|
44
48
|
LOGGER.debug("listAccounts:done", { count: res.accounts.length });
|
|
45
49
|
return res;
|
|
46
50
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listAccounts.js","sourceRoot":"","sources":["../../../src/actions/listAccounts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"listAccounts.js","sourceRoot":"","sources":["../../../src/actions/listAccounts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAE,mBAAmB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AACpF,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EACL,YAAY,GAGb,MAAM,oBAAoB,CAAC;AAE5B,MAAM,MAAM,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;AAgB1C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAA4B,EAC5B,MAA0B;IAE1B,MAAM,aAAa,GACjB,MAAM,CAAC,aAAa;QACpB,CAAC,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC;YAC3B,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO;YACtB,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAEpC,MAAM,CAAC,KAAK,CAAC,oBAAoB,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;IAEjE,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE;QAC7C,GAAG,MAAM;QACT,aAAa;KACmB,CAAC,CAAC;IAEpC,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QACnC,MAAM,EAAE,qBAAqB;QAC7B,MAAM,EAAE,CAAC,SAAS,CAAC;KACpB,CAAC,CAAC;IAEH,MAAM,GAAG,GAAG,KAAK,CAAC,MAAM,CACtB,MAAM,CAAC,QAAQ,EACf,OAAO,CACqB,CAAC;IAC/B,MAAM,CAAC,KAAK,CAAC,mBAAmB,EAAE,EAAE,KAAK,EAAE,GAAG,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IAElE,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import type { DistributiveOmit, InnerWalletApiClient } from \"../types.ts\";\nimport { LOGGER } from \"../logger.js\";\nimport type { Address, Prettify } from \"viem\";\nimport { wallet_listAccounts as MethodSchema } from \"@alchemy/wallet-api-types/rpc\";\nimport { isLocalAccount } from \"../utils/assertions.js\";\nimport { Value } from \"typebox/value\";\nimport {\n methodSchema,\n type MethodParams,\n type MethodResponse,\n} from \"../utils/schema.js\";\n\nconst schema = methodSchema(MethodSchema);\ntype BaseListAccountsParams = MethodParams<typeof MethodSchema>;\ntype ListAccountsResponse = MethodResponse<typeof MethodSchema>;\n\nexport type ListAccountsParams = Prettify<\n DistributiveOmit<\n BaseListAccountsParams,\n \"signerAddress\" | \"signerPublicKey\"\n > & {\n signerAddress?: Address;\n signerPublicKey?: never;\n }\n>;\n\nexport type ListAccountsResult = ListAccountsResponse;\n\n/**\n * Lists all smart accounts for a given signer using the wallet API client.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {ListAccountsParams} params - Parameters for listing accounts\n * @param {string} params.signerAddress - The address of the signer to list accounts for\n * @param {number} [params.limit] - Optional maximum number of accounts to return (default: 100, max: 100)\n * @param {string} [params.after] - Optional pagination cursor for fetching subsequent pages\n * @returns {Promise<ListAccountsResult>} A Promise that resolves to the list of accounts and pagination metadata\n *\n * @example\n * ```ts\n * // Fetch the first page of accounts\n * const firstPage = await client.listAccounts({\n * signerAddress: \"0x123...\",\n * limit: 10\n * });\n *\n * // If an 'after' cursor exists, use it to fetch the next page\n * const nextPage = await client.listAccounts({\n * signerAddress: \"0x123...\",\n * limit: 10,\n * after: firstPage.meta.after\n * });\n * ```\n */\nexport async function listAccounts(\n client: InnerWalletApiClient,\n params: ListAccountsParams,\n): Promise<ListAccountsResult> {\n const signerAddress =\n params.signerAddress ??\n (isLocalAccount(client.owner)\n ? client.owner.address\n : client.owner.account.address);\n\n LOGGER.debug(\"listAccounts:start\", { hasAfter: !!params.after });\n\n const rpcParams = Value.Encode(schema.request, {\n ...params,\n signerAddress,\n } satisfies BaseListAccountsParams);\n\n const rpcResp = await client.request({\n method: \"wallet_listAccounts\",\n params: [rpcParams],\n });\n\n const res = Value.Decode(\n schema.response,\n rpcResp,\n ) satisfies ListAccountsResult;\n LOGGER.debug(\"listAccounts:done\", { count: res.accounts.length });\n\n return res;\n}\n"]}
|
|
@@ -1,13 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
import type
|
|
4
|
-
type
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import type { Address, Prettify } from "viem";
|
|
2
|
+
import type { DistributiveOmit, InnerWalletApiClient } from "../types.ts";
|
|
3
|
+
import { type PrepareCallsCapabilities, type WithCapabilities } from "../utils/capabilities.js";
|
|
4
|
+
import { type AccountParam } from "../utils/resolve.js";
|
|
5
|
+
import { wallet_prepareCalls as MethodSchema } from "@alchemy/wallet-api-types/rpc";
|
|
6
|
+
import { type MethodParams, type MethodResponse } from "../utils/schema.js";
|
|
7
|
+
type BasePrepareCallsParams = MethodParams<typeof MethodSchema>;
|
|
8
|
+
type PrepareCallsResponse = MethodResponse<typeof MethodSchema>;
|
|
9
|
+
export type PrepareCallsParams = Prettify<WithCapabilities<DistributiveOmit<BasePrepareCallsParams, "from" | "chainId"> & {
|
|
10
|
+
account?: AccountParam;
|
|
11
|
+
chainId?: number;
|
|
12
|
+
}>>;
|
|
13
|
+
/** The modifiedRequest in client format: `account` instead of `from`, SDK capabilities. */
|
|
14
|
+
type ClientModifiedRequest = Prettify<Omit<BasePrepareCallsParams, "from" | "capabilities"> & {
|
|
15
|
+
account: Address;
|
|
16
|
+
capabilities?: PrepareCallsCapabilities;
|
|
8
17
|
}>;
|
|
9
|
-
export type
|
|
10
|
-
|
|
18
|
+
export type PrepareCallsResult = Exclude<PrepareCallsResponse, {
|
|
19
|
+
type: "paymaster-permit";
|
|
20
|
+
}> | (Omit<Extract<PrepareCallsResponse, {
|
|
21
|
+
type: "paymaster-permit";
|
|
22
|
+
}>, "modifiedRequest"> & {
|
|
23
|
+
modifiedRequest: ClientModifiedRequest;
|
|
24
|
+
});
|
|
11
25
|
/**
|
|
12
26
|
* Prepares a set of contract calls for execution by building a user operation.
|
|
13
27
|
* Returns the built user operation and a signature request that needs to be signed
|
|
@@ -18,8 +32,8 @@ export type PrepareCallsResult = Prettify<RpcSchema["ReturnType"]>;
|
|
|
18
32
|
*
|
|
19
33
|
* @param {InnerWalletApiClient} client - The wallet API client to use for the request
|
|
20
34
|
* @param {PrepareCallsParams} params - Parameters for preparing calls
|
|
21
|
-
* @param {Array<{to: Address, data?: Hex, value?:
|
|
22
|
-
* @param {
|
|
35
|
+
* @param {Array<{to: Address, data?: Hex, value?: bigint}>} params.calls - Array of contract calls to execute
|
|
36
|
+
* @param {AccountParam} [params.account] - The account to execute the calls from. Can be an address string or an object with an `address` property. Defaults to the client's account (signer address via EIP-7702).
|
|
23
37
|
* @param {object} [params.capabilities] - Optional capabilities to include with the request
|
|
24
38
|
* @returns {Promise<PrepareCallsResult>} A Promise that resolves to the prepared calls result containing
|
|
25
39
|
* the user operation data and signature request
|
|
@@ -31,10 +45,10 @@ export type PrepareCallsResult = Prettify<RpcSchema["ReturnType"]>;
|
|
|
31
45
|
* calls: [{
|
|
32
46
|
* to: "0x1234...",
|
|
33
47
|
* data: "0xabcdef...",
|
|
34
|
-
* value:
|
|
48
|
+
* value: 0n
|
|
35
49
|
* }],
|
|
36
50
|
* capabilities: {
|
|
37
|
-
*
|
|
51
|
+
* paymaster: { policyId: "your-policy-id" }
|
|
38
52
|
* }
|
|
39
53
|
* });
|
|
40
54
|
* ```
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { toHex } from "viem";
|
|
2
|
-
import { AccountNotFoundError } from "@alchemy/common";
|
|
3
1
|
import { LOGGER } from "../logger.js";
|
|
4
|
-
import { mergeClientCapabilities } from "../utils/capabilities.js";
|
|
2
|
+
import { fromRpcCapabilities, mergeClientCapabilities, toRpcCapabilities, } from "../utils/capabilities.js";
|
|
3
|
+
import { resolveAddress } from "../utils/resolve.js";
|
|
4
|
+
import { wallet_prepareCalls as MethodSchema } from "@alchemy/wallet-api-types/rpc";
|
|
5
|
+
import { Value } from "typebox/value";
|
|
6
|
+
import { methodSchema, } from "../utils/schema.js";
|
|
7
|
+
const schema = methodSchema(MethodSchema);
|
|
5
8
|
/**
|
|
6
9
|
* Prepares a set of contract calls for execution by building a user operation.
|
|
7
10
|
* Returns the built user operation and a signature request that needs to be signed
|
|
@@ -12,8 +15,8 @@ import { mergeClientCapabilities } from "../utils/capabilities.js";
|
|
|
12
15
|
*
|
|
13
16
|
* @param {InnerWalletApiClient} client - The wallet API client to use for the request
|
|
14
17
|
* @param {PrepareCallsParams} params - Parameters for preparing calls
|
|
15
|
-
* @param {Array<{to: Address, data?: Hex, value?:
|
|
16
|
-
* @param {
|
|
18
|
+
* @param {Array<{to: Address, data?: Hex, value?: bigint}>} params.calls - Array of contract calls to execute
|
|
19
|
+
* @param {AccountParam} [params.account] - The account to execute the calls from. Can be an address string or an object with an `address` property. Defaults to the client's account (signer address via EIP-7702).
|
|
17
20
|
* @param {object} [params.capabilities] - Optional capabilities to include with the request
|
|
18
21
|
* @returns {Promise<PrepareCallsResult>} A Promise that resolves to the prepared calls result containing
|
|
19
22
|
* the user operation data and signature request
|
|
@@ -25,37 +28,51 @@ import { mergeClientCapabilities } from "../utils/capabilities.js";
|
|
|
25
28
|
* calls: [{
|
|
26
29
|
* to: "0x1234...",
|
|
27
30
|
* data: "0xabcdef...",
|
|
28
|
-
* value:
|
|
31
|
+
* value: 0n
|
|
29
32
|
* }],
|
|
30
33
|
* capabilities: {
|
|
31
|
-
*
|
|
34
|
+
* paymaster: { policyId: "your-policy-id" }
|
|
32
35
|
* }
|
|
33
36
|
* });
|
|
34
37
|
* ```
|
|
35
38
|
*/
|
|
36
39
|
export async function prepareCalls(client, params) {
|
|
37
|
-
const from = params.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
40
|
+
const from = params.account
|
|
41
|
+
? resolveAddress(params.account)
|
|
42
|
+
: client.account.address;
|
|
43
|
+
const chainId = params.chainId ?? client.chain.id;
|
|
42
44
|
const capabilities = mergeClientCapabilities(client, params.capabilities);
|
|
43
45
|
LOGGER.debug("prepareCalls:start", {
|
|
44
46
|
callsCount: params.calls?.length,
|
|
45
47
|
hasCapabilities: !!params.capabilities,
|
|
46
48
|
});
|
|
47
|
-
const
|
|
49
|
+
const { account: _, chainId: __, ...rest } = params;
|
|
50
|
+
const rpcParams = Value.Encode(schema.request, {
|
|
51
|
+
...rest,
|
|
52
|
+
chainId,
|
|
53
|
+
from,
|
|
54
|
+
capabilities: toRpcCapabilities(capabilities),
|
|
55
|
+
});
|
|
56
|
+
const rpcResp = await client.request({
|
|
48
57
|
method: "wallet_prepareCalls",
|
|
49
|
-
params: [
|
|
50
|
-
{
|
|
51
|
-
...params,
|
|
52
|
-
chainId: params.chainId ?? toHex(client.chain.id),
|
|
53
|
-
from,
|
|
54
|
-
capabilities,
|
|
55
|
-
},
|
|
56
|
-
],
|
|
58
|
+
params: [rpcParams],
|
|
57
59
|
});
|
|
58
60
|
LOGGER.debug("prepareCalls:done");
|
|
59
|
-
|
|
61
|
+
const decoded = Value.Decode(schema.response, rpcResp);
|
|
62
|
+
// Transform paymaster-permit modifiedRequest from RPC format to client format:
|
|
63
|
+
// - `from` (RPC) → `account` (client)
|
|
64
|
+
// - `capabilities.paymasterService` (RPC) → `capabilities.paymaster` (client)
|
|
65
|
+
if (decoded.type === "paymaster-permit") {
|
|
66
|
+
const { from, capabilities, ...restModifiedRequest } = decoded.modifiedRequest;
|
|
67
|
+
return {
|
|
68
|
+
...decoded,
|
|
69
|
+
modifiedRequest: {
|
|
70
|
+
...restModifiedRequest,
|
|
71
|
+
account: from,
|
|
72
|
+
capabilities: fromRpcCapabilities(capabilities),
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return decoded;
|
|
60
77
|
}
|
|
61
78
|
//# sourceMappingURL=prepareCalls.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepareCalls.js","sourceRoot":"","sources":["../../../src/actions/prepareCalls.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prepareCalls.js","sourceRoot":"","sources":["../../../src/actions/prepareCalls.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EACL,mBAAmB,EACnB,uBAAuB,EACvB,iBAAiB,GAGlB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,cAAc,EAAqB,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,mBAAmB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AACpF,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EACL,YAAY,GAGb,MAAM,oBAAoB,CAAC;AAE5B,MAAM,MAAM,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;AA8B1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAA4B,EAC5B,MAA0B;IAE1B,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO;QACzB,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC;QAChC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;IAE3B,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;IAElD,MAAM,YAAY,GAAG,uBAAuB,CAAC,MAAM,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC;IAE1E,MAAM,CAAC,KAAK,CAAC,oBAAoB,EAAE;QACjC,UAAU,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM;QAChC,eAAe,EAAE,CAAC,CAAC,MAAM,CAAC,YAAY;KACvC,CAAC,CAAC;IAEH,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;IACpD,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE;QAC7C,GAAG,IAAI;QACP,OAAO;QACP,IAAI;QACJ,YAAY,EAAE,iBAAiB,CAAC,YAAY,CAAC;KACb,CAAC,CAAC;IAEpC,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QACnC,MAAM,EAAE,qBAAqB;QAC7B,MAAM,EAAE,CAAC,SAAS,CAAC;KACpB,CAAC,CAAC;IAEH,MAAM,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC;IAClC,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAEvD,+EAA+E;IAC/E,sCAAsC;IACtC,8EAA8E;IAC9E,IAAI,OAAO,CAAC,IAAI,KAAK,kBAAkB,EAAE,CAAC;QACxC,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,mBAAmB,EAAE,GAClD,OAAO,CAAC,eAAe,CAAC;QAC1B,OAAO;YACL,GAAG,OAAO;YACV,eAAe,EAAE;gBACf,GAAG,mBAAmB;gBACtB,OAAO,EAAE,IAAI;gBACb,YAAY,EAAE,mBAAmB,CAAC,YAAY,CAAC;aAChD;SACF,CAAC;IACJ,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type { Address, Prettify } from \"viem\";\nimport type { DistributiveOmit, InnerWalletApiClient } from \"../types.ts\";\nimport { LOGGER } from \"../logger.js\";\nimport {\n fromRpcCapabilities,\n mergeClientCapabilities,\n toRpcCapabilities,\n type PrepareCallsCapabilities,\n type WithCapabilities,\n} from \"../utils/capabilities.js\";\nimport { resolveAddress, type AccountParam } from \"../utils/resolve.js\";\nimport { wallet_prepareCalls as MethodSchema } from \"@alchemy/wallet-api-types/rpc\";\nimport { Value } from \"typebox/value\";\nimport {\n methodSchema,\n type MethodParams,\n type MethodResponse,\n} from \"../utils/schema.js\";\n\nconst schema = methodSchema(MethodSchema);\ntype BasePrepareCallsParams = MethodParams<typeof MethodSchema>;\ntype PrepareCallsResponse = MethodResponse<typeof MethodSchema>;\n\nexport type PrepareCallsParams = Prettify<\n WithCapabilities<\n DistributiveOmit<BasePrepareCallsParams, \"from\" | \"chainId\"> & {\n account?: AccountParam;\n chainId?: number;\n }\n >\n>;\n\n/** The modifiedRequest in client format: `account` instead of `from`, SDK capabilities. */\ntype ClientModifiedRequest = Prettify<\n Omit<BasePrepareCallsParams, \"from\" | \"capabilities\"> & {\n account: Address;\n capabilities?: PrepareCallsCapabilities;\n }\n>;\n\nexport type PrepareCallsResult =\n | Exclude<PrepareCallsResponse, { type: \"paymaster-permit\" }>\n | (Omit<\n Extract<PrepareCallsResponse, { type: \"paymaster-permit\" }>,\n \"modifiedRequest\"\n > & {\n modifiedRequest: ClientModifiedRequest;\n });\n\n/**\n * Prepares a set of contract calls for execution by building a user operation.\n * Returns the built user operation and a signature request that needs to be signed\n * before submitting to sendPreparedCalls.\n *\n * The client defaults to using EIP-7702 with the signer's address, so you can call\n * this directly without first calling `requestAccount`.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {PrepareCallsParams} params - Parameters for preparing calls\n * @param {Array<{to: Address, data?: Hex, value?: bigint}>} params.calls - Array of contract calls to execute\n * @param {AccountParam} [params.account] - The account to execute the calls from. Can be an address string or an object with an `address` property. Defaults to the client's account (signer address via EIP-7702).\n * @param {object} [params.capabilities] - Optional capabilities to include with the request\n * @returns {Promise<PrepareCallsResult>} A Promise that resolves to the prepared calls result containing\n * the user operation data and signature request\n *\n * @example\n * ```ts\n * // Prepare a sponsored user operation call (uses signer address via EIP-7702 by default)\n * const result = await client.prepareCalls({\n * calls: [{\n * to: \"0x1234...\",\n * data: \"0xabcdef...\",\n * value: 0n\n * }],\n * capabilities: {\n * paymaster: { policyId: \"your-policy-id\" }\n * }\n * });\n * ```\n */\nexport async function prepareCalls(\n client: InnerWalletApiClient,\n params: PrepareCallsParams,\n): Promise<PrepareCallsResult> {\n const from = params.account\n ? resolveAddress(params.account)\n : client.account.address;\n\n const chainId = params.chainId ?? client.chain.id;\n\n const capabilities = mergeClientCapabilities(client, params.capabilities);\n\n LOGGER.debug(\"prepareCalls:start\", {\n callsCount: params.calls?.length,\n hasCapabilities: !!params.capabilities,\n });\n\n const { account: _, chainId: __, ...rest } = params;\n const rpcParams = Value.Encode(schema.request, {\n ...rest,\n chainId,\n from,\n capabilities: toRpcCapabilities(capabilities),\n } satisfies BasePrepareCallsParams);\n\n const rpcResp = await client.request({\n method: \"wallet_prepareCalls\",\n params: [rpcParams],\n });\n\n LOGGER.debug(\"prepareCalls:done\");\n const decoded = Value.Decode(schema.response, rpcResp);\n\n // Transform paymaster-permit modifiedRequest from RPC format to client format:\n // - `from` (RPC) → `account` (client)\n // - `capabilities.paymasterService` (RPC) → `capabilities.paymaster` (client)\n if (decoded.type === \"paymaster-permit\") {\n const { from, capabilities, ...restModifiedRequest } =\n decoded.modifiedRequest;\n return {\n ...decoded,\n modifiedRequest: {\n ...restModifiedRequest,\n account: from,\n capabilities: fromRpcCapabilities(capabilities),\n },\n };\n }\n\n return decoded;\n}\n"]}
|