@alchemy/wallet-apis 0.0.0-alpha.17 → 0.0.0-alpha.19
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 +13 -15
- 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 +13 -17
- package/dist/esm/actions/grantPermissions.js +23 -26
- package/dist/esm/actions/grantPermissions.js.map +1 -1
- package/dist/esm/actions/listAccounts.d.ts +8 -17
- package/dist/esm/actions/listAccounts.js +16 -29
- package/dist/esm/actions/listAccounts.js.map +1 -1
- package/dist/esm/actions/prepareCalls.d.ts +24 -22
- package/dist/esm/actions/prepareCalls.js +30 -25
- package/dist/esm/actions/prepareCalls.js.map +1 -1
- package/dist/esm/actions/prepareSign.d.ts +13 -16
- package/dist/esm/actions/prepareSign.js +18 -17
- package/dist/esm/actions/prepareSign.js.map +1 -1
- package/dist/esm/actions/requestAccount.d.ts +21 -21
- package/dist/esm/actions/requestAccount.js +30 -46
- package/dist/esm/actions/requestAccount.js.map +1 -1
- package/dist/esm/actions/sendCalls.d.ts +18 -12
- package/dist/esm/actions/sendCalls.js +21 -17
- package/dist/esm/actions/sendCalls.js.map +1 -1
- package/dist/esm/actions/sendPreparedCalls.d.ts +14 -13
- package/dist/esm/actions/sendPreparedCalls.js +22 -16
- package/dist/esm/actions/sendPreparedCalls.js.map +1 -1
- package/dist/esm/actions/signMessage.d.ts +4 -3
- package/dist/esm/actions/signMessage.js +9 -12
- package/dist/esm/actions/signMessage.js.map +1 -1
- package/dist/esm/actions/signPreparedCalls.d.ts +18 -2
- package/dist/esm/actions/signPreparedCalls.js +2 -7
- package/dist/esm/actions/signPreparedCalls.js.map +1 -1
- package/dist/esm/actions/signSignatureRequest.d.ts +3 -9
- package/dist/esm/actions/signSignatureRequest.js +5 -36
- package/dist/esm/actions/signSignatureRequest.js.map +1 -1
- package/dist/esm/actions/signTypedData.d.ts +3 -2
- package/dist/esm/actions/signTypedData.js +8 -11
- package/dist/esm/actions/signTypedData.js.map +1 -1
- package/dist/esm/client.d.ts +18 -23
- package/dist/esm/client.js +20 -31
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/decorators/smartWalletActions.d.ts +10 -9
- package/dist/esm/decorators/smartWalletActions.js +5 -4
- package/dist/esm/decorators/smartWalletActions.js.map +1 -1
- package/dist/esm/experimental/actions/requestQuoteV0.d.ts +19 -20
- package/dist/esm/experimental/actions/requestQuoteV0.js +26 -23
- package/dist/esm/experimental/actions/requestQuoteV0.js.map +1 -1
- package/dist/esm/experimental/swapActionsDecorator.d.ts +4 -5
- package/dist/esm/experimental/swapActionsDecorator.js +1 -1
- package/dist/esm/experimental/swapActionsDecorator.js.map +1 -1
- package/dist/esm/exports/index.d.ts +6 -4
- package/dist/esm/exports/index.js +3 -2
- package/dist/esm/exports/index.js.map +1 -1
- package/dist/esm/exports/internal.d.ts +0 -4
- package/dist/esm/exports/internal.js +0 -2
- package/dist/esm/exports/internal.js.map +1 -1
- package/dist/esm/transport.d.ts +3 -0
- package/dist/esm/transport.js +8 -0
- package/dist/esm/transport.js.map +1 -0
- package/dist/esm/types.d.ts +12 -11
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils/assertions.d.ts +2 -4
- package/dist/esm/utils/assertions.js +0 -3
- package/dist/esm/utils/assertions.js.map +1 -1
- package/dist/esm/utils/capabilities.d.ts +41 -2
- package/dist/esm/utils/capabilities.js +57 -11
- package/dist/esm/utils/capabilities.js.map +1 -1
- package/dist/esm/utils/format.d.ts +1 -3
- package/dist/esm/utils/format.js +1 -11
- package/dist/esm/utils/format.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 +13 -15
- 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 +13 -17
- package/dist/types/actions/grantPermissions.d.ts.map +1 -1
- package/dist/types/actions/listAccounts.d.ts +8 -17
- package/dist/types/actions/listAccounts.d.ts.map +1 -1
- package/dist/types/actions/prepareCalls.d.ts +24 -22
- package/dist/types/actions/prepareCalls.d.ts.map +1 -1
- package/dist/types/actions/prepareSign.d.ts +13 -16
- package/dist/types/actions/prepareSign.d.ts.map +1 -1
- package/dist/types/actions/requestAccount.d.ts +21 -21
- package/dist/types/actions/requestAccount.d.ts.map +1 -1
- package/dist/types/actions/sendCalls.d.ts +18 -12
- package/dist/types/actions/sendCalls.d.ts.map +1 -1
- package/dist/types/actions/sendPreparedCalls.d.ts +14 -13
- 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 -9
- 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 +18 -23
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/decorators/smartWalletActions.d.ts +10 -9
- package/dist/types/decorators/smartWalletActions.d.ts.map +1 -1
- package/dist/types/experimental/actions/requestQuoteV0.d.ts +19 -20
- package/dist/types/experimental/actions/requestQuoteV0.d.ts.map +1 -1
- package/dist/types/experimental/swapActionsDecorator.d.ts +4 -5
- package/dist/types/experimental/swapActionsDecorator.d.ts.map +1 -1
- package/dist/types/exports/index.d.ts +6 -4
- package/dist/types/exports/index.d.ts.map +1 -1
- package/dist/types/exports/internal.d.ts +0 -4
- package/dist/types/exports/internal.d.ts.map +1 -1
- package/dist/types/transport.d.ts +4 -0
- package/dist/types/transport.d.ts.map +1 -0
- package/dist/types/types.d.ts +12 -11
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/assertions.d.ts +2 -4
- package/dist/types/utils/assertions.d.ts.map +1 -1
- package/dist/types/utils/capabilities.d.ts +41 -2
- package/dist/types/utils/capabilities.d.ts.map +1 -1
- package/dist/types/utils/format.d.ts +1 -3
- package/dist/types/utils/format.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 +6 -7
- package/src/actions/formatSign.ts +37 -32
- package/src/actions/getCapabilities.ts +64 -0
- package/src/actions/grantPermissions.ts +42 -57
- package/src/actions/listAccounts.ts +38 -54
- package/src/actions/prepareCalls.ts +56 -45
- package/src/actions/prepareSign.ts +38 -38
- package/src/actions/requestAccount.ts +49 -78
- package/src/actions/sendCalls.ts +33 -28
- package/src/actions/sendPreparedCalls.ts +49 -28
- package/src/actions/signMessage.ts +10 -26
- package/src/actions/signPreparedCalls.ts +33 -24
- package/src/actions/signSignatureRequest.ts +14 -78
- package/src/actions/signTypedData.ts +9 -24
- package/src/client.ts +34 -60
- package/src/decorators/smartWalletActions.ts +17 -21
- package/src/experimental/actions/requestQuoteV0.ts +55 -50
- package/src/experimental/swapActionsDecorator.ts +6 -11
- package/src/exports/index.ts +7 -7
- package/src/exports/internal.ts +0 -6
- package/src/transport.ts +16 -0
- package/src/types.ts +12 -17
- package/src/utils/assertions.ts +2 -9
- package/src/utils/capabilities.ts +105 -16
- package/src/utils/format.ts +1 -20
- package/src/utils/resolve.ts +11 -0
- package/src/utils/schema.ts +32 -0
- package/src/version.ts +1 -1
- package/dist/esm/provider.d.ts +0 -26
- package/dist/esm/provider.js +0 -191
- package/dist/esm/provider.js.map +0 -1
- package/dist/esm/testSetup.d.ts +0 -3
- package/dist/esm/testSetup.js +0 -18
- package/dist/esm/testSetup.js.map +0 -1
- package/dist/esm/utils/signer.d.ts +0 -10
- package/dist/esm/utils/signer.js +0 -28
- package/dist/esm/utils/signer.js.map +0 -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/provider.d.ts +0 -27
- package/dist/types/provider.d.ts.map +0 -1
- package/dist/types/testSetup.d.ts +0 -4
- package/dist/types/testSetup.d.ts.map +0 -1
- package/dist/types/utils/signer.d.ts +0 -11
- package/dist/types/utils/signer.d.ts.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/provider.ts +0 -261
- package/src/testSetup.ts +0 -24
- package/src/utils/signer.ts +0 -36
- package/src/utils/viemDecode.ts +0 -313
- package/src/utils/viemEncode.ts +0 -345
|
@@ -1,58 +1,63 @@
|
|
|
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 { 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
|
|
8
11
|
* before submitting to sendPreparedCalls.
|
|
9
12
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* @param {
|
|
13
|
+
* The client defaults to using EIP-7702 with the signer's address, so you can call
|
|
14
|
+
* this directly without first calling `requestAccount`.
|
|
15
|
+
*
|
|
16
|
+
* @param {InnerWalletApiClient} client - The wallet API client to use for the request
|
|
17
|
+
* @param {PrepareCallsParams} params - Parameters for preparing calls
|
|
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).
|
|
14
20
|
* @param {object} [params.capabilities] - Optional capabilities to include with the request
|
|
15
21
|
* @returns {Promise<PrepareCallsResult>} A Promise that resolves to the prepared calls result containing
|
|
16
22
|
* the user operation data and signature request
|
|
17
23
|
*
|
|
18
24
|
* @example
|
|
19
25
|
* ```ts
|
|
20
|
-
* // Prepare a sponsored user operation call
|
|
26
|
+
* // Prepare a sponsored user operation call (uses signer address via EIP-7702 by default)
|
|
21
27
|
* const result = await client.prepareCalls({
|
|
22
28
|
* calls: [{
|
|
23
29
|
* to: "0x1234...",
|
|
24
30
|
* data: "0xabcdef...",
|
|
25
|
-
* value:
|
|
31
|
+
* value: 0n
|
|
26
32
|
* }],
|
|
27
33
|
* capabilities: {
|
|
28
|
-
*
|
|
34
|
+
* paymaster: { policyId: "your-policy-id" }
|
|
29
35
|
* }
|
|
30
36
|
* });
|
|
31
37
|
* ```
|
|
32
38
|
*/
|
|
33
39
|
export async function prepareCalls(client, params) {
|
|
34
|
-
const from = params.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
40
|
+
const from = params.account
|
|
41
|
+
? resolveAddress(params.account)
|
|
42
|
+
: client.account.address;
|
|
43
|
+
const chainId = params.chainId ?? client.chain.id;
|
|
39
44
|
const capabilities = mergeClientCapabilities(client, params.capabilities);
|
|
40
45
|
LOGGER.debug("prepareCalls:start", {
|
|
41
46
|
callsCount: params.calls?.length,
|
|
42
47
|
hasCapabilities: !!params.capabilities,
|
|
43
48
|
});
|
|
44
|
-
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({
|
|
45
57
|
method: "wallet_prepareCalls",
|
|
46
|
-
params: [
|
|
47
|
-
{
|
|
48
|
-
...params,
|
|
49
|
-
chainId: params.chainId ?? toHex(client.chain.id),
|
|
50
|
-
from,
|
|
51
|
-
capabilities,
|
|
52
|
-
},
|
|
53
|
-
],
|
|
58
|
+
params: [rpcParams],
|
|
54
59
|
});
|
|
55
60
|
LOGGER.debug("prepareCalls:done");
|
|
56
|
-
return
|
|
61
|
+
return Value.Decode(schema.response, rpcResp);
|
|
57
62
|
}
|
|
58
63
|
//# 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,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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,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 { LOGGER } from \"../logger.js\";\nimport {\n mergeClientCapabilities,\n toRpcCapabilities,\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\nexport type PrepareCallsResult = PrepareCallsResponse;\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 return Value.Decode(schema.response, rpcResp);\n}\n"]}
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
3
|
-
import type
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
from?: never;
|
|
13
|
-
})>;
|
|
14
|
-
export type PrepareSignResult = Prettify<RpcSchema["ReturnType"]>;
|
|
1
|
+
import type { DistributiveOmit, InnerWalletApiClient } from "../types.ts";
|
|
2
|
+
import { wallet_prepareSign as MethodSchema } from "@alchemy/wallet-api-types/rpc";
|
|
3
|
+
import { type AccountParam } from "../utils/resolve.js";
|
|
4
|
+
import { type MethodParams, type MethodResponse } from "../utils/schema.js";
|
|
5
|
+
type BasePrepareSignParams = MethodParams<typeof MethodSchema>;
|
|
6
|
+
type PrepareSignResponse = MethodResponse<typeof MethodSchema>;
|
|
7
|
+
export type PrepareSignParams = DistributiveOmit<BasePrepareSignParams, "from" | "chainId"> & {
|
|
8
|
+
account?: AccountParam;
|
|
9
|
+
chainId?: number;
|
|
10
|
+
};
|
|
11
|
+
export type PrepareSignResult = PrepareSignResponse;
|
|
15
12
|
/**
|
|
16
13
|
* Prepares a signature request for signing messages or transactions.
|
|
17
14
|
*
|
|
@@ -23,11 +20,11 @@ export type PrepareSignResult = Prettify<RpcSchema["ReturnType"]>;
|
|
|
23
20
|
* ```ts
|
|
24
21
|
* // Prepare a message to be signed
|
|
25
22
|
* const result = await client.prepareSign({
|
|
26
|
-
*
|
|
23
|
+
* account: "0x1234...",
|
|
27
24
|
* type: "personal_sign",
|
|
28
25
|
* data: "Hello, world!",
|
|
29
26
|
* });
|
|
30
27
|
* ```
|
|
31
28
|
*/
|
|
32
|
-
export declare function prepareSign
|
|
29
|
+
export declare function prepareSign(client: InnerWalletApiClient, params: PrepareSignParams): Promise<PrepareSignResult>;
|
|
33
30
|
export {};
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AccountNotFoundError } from "@alchemy/common";
|
|
1
|
+
import { wallet_prepareSign 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
|
* Prepares a signature request for signing messages or transactions.
|
|
6
9
|
*
|
|
@@ -12,30 +15,28 @@ import { LOGGER } from "../logger.js";
|
|
|
12
15
|
* ```ts
|
|
13
16
|
* // Prepare a message to be signed
|
|
14
17
|
* const result = await client.prepareSign({
|
|
15
|
-
*
|
|
18
|
+
* account: "0x1234...",
|
|
16
19
|
* type: "personal_sign",
|
|
17
20
|
* data: "Hello, world!",
|
|
18
21
|
* });
|
|
19
22
|
* ```
|
|
20
23
|
*/
|
|
21
24
|
export async function prepareSign(client, params) {
|
|
22
|
-
const from = params.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
throw new AccountNotFoundError();
|
|
26
|
-
}
|
|
25
|
+
const from = params.account
|
|
26
|
+
? resolveAddress(params.account)
|
|
27
|
+
: client.account.address;
|
|
27
28
|
LOGGER.debug("prepareSign:start", { type: params.signatureRequest.type });
|
|
28
|
-
const
|
|
29
|
+
const { account: _, chainId: __, ...rest } = params;
|
|
30
|
+
const rpcParams = Value.Encode(schema.request, {
|
|
31
|
+
...rest,
|
|
32
|
+
from,
|
|
33
|
+
chainId: params.chainId ?? client.chain.id,
|
|
34
|
+
});
|
|
35
|
+
const rpcResp = await client.request({
|
|
29
36
|
method: "wallet_prepareSign",
|
|
30
|
-
params: [
|
|
31
|
-
{
|
|
32
|
-
...params,
|
|
33
|
-
from,
|
|
34
|
-
chainId: params.chainId ?? toHex(client.chain.id),
|
|
35
|
-
},
|
|
36
|
-
],
|
|
37
|
+
params: [rpcParams],
|
|
37
38
|
});
|
|
38
39
|
LOGGER.debug("prepareSign:done");
|
|
39
|
-
return
|
|
40
|
+
return Value.Decode(schema.response, rpcResp);
|
|
40
41
|
}
|
|
41
42
|
//# sourceMappingURL=prepareSign.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepareSign.js","sourceRoot":"","sources":["../../../src/actions/prepareSign.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"prepareSign.js","sourceRoot":"","sources":["../../../src/actions/prepareSign.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AACnF,OAAO,EAAE,MAAM,EAAE,MAAM,c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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 BasePrepareSignParams = MethodParams<typeof MethodSchema>;\ntype PrepareSignResponse = MethodResponse<typeof MethodSchema>;\n\nexport type PrepareSignParams = DistributiveOmit<\n BasePrepareSignParams,\n \"from\" | \"chainId\"\n> & {\n account?: AccountParam;\n chainId?: number;\n};\n\nexport type PrepareSignResult = PrepareSignResponse;\n\n/**\n * Prepares a signature request for signing messages or transactions.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {PrepareSignParams} params - Parameters for preparing the signature request\n * @returns {Promise<PrepareSignResult>} A Promise that resolves to the prepare sign result containing a signature request\n *\n * @example\n * ```ts\n * // Prepare a message to be signed\n * const result = await client.prepareSign({\n * account: \"0x1234...\",\n * type: \"personal_sign\",\n * data: \"Hello, world!\",\n * });\n * ```\n */\nexport async function prepareSign(\n client: InnerWalletApiClient,\n params: PrepareSignParams,\n): Promise<PrepareSignResult> {\n const from = params.account\n ? resolveAddress(params.account)\n : client.account.address;\n\n LOGGER.debug(\"prepareSign:start\", { type: params.signatureRequest.type });\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 BasePrepareSignParams);\n\n const rpcResp = await client.request({\n method: \"wallet_prepareSign\",\n params: [rpcParams],\n });\n\n LOGGER.debug(\"prepareSign:done\");\n return Value.Decode(schema.response, rpcResp);\n}\n"]}
|
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
import type { Address } from "abitype";
|
|
2
|
-
import { type Prettify } from "viem";
|
|
3
|
-
import
|
|
4
|
-
import type { InnerWalletApiClient } from "../types";
|
|
5
|
-
import type
|
|
6
|
-
type
|
|
7
|
-
|
|
8
|
-
method: "wallet_requestAccount";
|
|
9
|
-
};
|
|
10
|
-
}>;
|
|
11
|
-
export type RequestAccountParams = Prettify<Omit<Extract<RpcSchema["Request"]["params"][0], {
|
|
2
|
+
import { type JsonRpcAccount, type Prettify } from "viem";
|
|
3
|
+
import { wallet_requestAccount as MethodSchema } from "@alchemy/wallet-api-types/rpc";
|
|
4
|
+
import type { DistributiveOmit, InnerWalletApiClient } from "../types";
|
|
5
|
+
import { type MethodParams } from "../utils/schema.js";
|
|
6
|
+
type BaseRequestAccountParams = MethodParams<typeof MethodSchema>;
|
|
7
|
+
export type RequestAccountParams = Prettify<DistributiveOmit<Extract<BaseRequestAccountParams, {
|
|
12
8
|
signerAddress: Address;
|
|
9
|
+
}>, "signerAddress" | "includeCounterfactualInfo"> & ({
|
|
10
|
+
signerAddress?: Address;
|
|
11
|
+
accountAddress?: never;
|
|
13
12
|
} | {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
export type RequestAccountResult = Prettify<{
|
|
19
|
-
address: Address;
|
|
20
|
-
}>;
|
|
13
|
+
signerAddress?: never;
|
|
14
|
+
accountAddress: Address;
|
|
15
|
+
})>;
|
|
16
|
+
export type RequestAccountResult = JsonRpcAccount<Address>;
|
|
21
17
|
/**
|
|
22
|
-
* Requests
|
|
18
|
+
* Requests a smart account address for the provided signer using the wallet API client.
|
|
19
|
+
*
|
|
20
|
+
* Note: This is only needed for non-EIP-7702 accounts. The client defaults to using
|
|
21
|
+
* EIP-7702 with the signer's address, so you can call `prepareCalls` or `sendCalls`
|
|
22
|
+
* directly without first calling `requestAccount`.
|
|
23
|
+
*
|
|
23
24
|
* If an account already exists for the signer, it will always return that account unless a new ID is specified.
|
|
24
25
|
* If an account already exists, the creationHint will be ignored.
|
|
25
26
|
*
|
|
@@ -31,9 +32,8 @@ export type RequestAccountResult = Prettify<{
|
|
|
31
32
|
*
|
|
32
33
|
* @example
|
|
33
34
|
* ```ts
|
|
34
|
-
* // Request
|
|
35
|
-
* const
|
|
36
|
-
* const account = await client.requestAccount(signer);
|
|
35
|
+
* // Request a non-7702 smart account
|
|
36
|
+
* const account = await client.requestAccount();
|
|
37
37
|
* ```
|
|
38
38
|
*/
|
|
39
39
|
export declare function requestAccount(client: InnerWalletApiClient, params?: RequestAccountParams): Promise<RequestAccountResult>;
|
|
@@ -1,10 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isAddressEqual } from "viem";
|
|
2
|
+
import { wallet_requestAccount as MethodSchema } from "@alchemy/wallet-api-types/rpc";
|
|
2
3
|
import deepEqual from "deep-equal";
|
|
3
4
|
import { LOGGER } from "../logger.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
5
|
+
import { isLocalAccount } from "../utils/assertions.js";
|
|
6
|
+
import { Value } from "typebox/value";
|
|
7
|
+
import { methodSchema } from "../utils/schema.js";
|
|
8
|
+
const schema = methodSchema(MethodSchema);
|
|
6
9
|
/**
|
|
7
|
-
* Requests
|
|
10
|
+
* Requests a smart account address for the provided signer using the wallet API client.
|
|
11
|
+
*
|
|
12
|
+
* Note: This is only needed for non-EIP-7702 accounts. The client defaults to using
|
|
13
|
+
* EIP-7702 with the signer's address, so you can call `prepareCalls` or `sendCalls`
|
|
14
|
+
* directly without first calling `requestAccount`.
|
|
15
|
+
*
|
|
8
16
|
* If an account already exists for the signer, it will always return that account unless a new ID is specified.
|
|
9
17
|
* If an account already exists, the creationHint will be ignored.
|
|
10
18
|
*
|
|
@@ -16,9 +24,8 @@ import { getSignerAddressOrPublicKey } from "../utils/signer.js";
|
|
|
16
24
|
*
|
|
17
25
|
* @example
|
|
18
26
|
* ```ts
|
|
19
|
-
* // Request
|
|
20
|
-
* const
|
|
21
|
-
* const account = await client.requestAccount(signer);
|
|
27
|
+
* // Request a non-7702 smart account
|
|
28
|
+
* const account = await client.requestAccount();
|
|
22
29
|
* ```
|
|
23
30
|
*/
|
|
24
31
|
export async function requestAccount(client, params) {
|
|
@@ -26,63 +33,39 @@ export async function requestAccount(client, params) {
|
|
|
26
33
|
hasParams: !!params,
|
|
27
34
|
hasAccountOnClient: !!client.account,
|
|
28
35
|
});
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
// Non-webauthn signers do not support the "mav2-webauthn" account type.
|
|
38
|
-
if (creationHint.accountType === "mav2-webauthn") {
|
|
39
|
-
throw new BaseError("ECDSA (secp256k1) signers are not supported with mav2-webauthn account type");
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
const owner = getSignerAddressOrPublicKey(client.owner);
|
|
43
|
-
const args = (client.account && !params) || params?.accountAddress
|
|
36
|
+
const signerAddress = (params && "signerAddress" in params ? params.signerAddress : undefined) ??
|
|
37
|
+
(isLocalAccount(client.owner)
|
|
38
|
+
? client.owner.address
|
|
39
|
+
: client.owner.account.address);
|
|
40
|
+
const args = params && "accountAddress" in params && params.accountAddress
|
|
44
41
|
? {
|
|
45
|
-
accountAddress: params
|
|
42
|
+
accountAddress: params.accountAddress,
|
|
46
43
|
includeCounterfactualInfo: true,
|
|
47
44
|
}
|
|
48
45
|
: {
|
|
49
|
-
...
|
|
50
|
-
|
|
51
|
-
signerPublicKey: {
|
|
52
|
-
...owner.publicKey,
|
|
53
|
-
type: "webauthn-p256",
|
|
54
|
-
},
|
|
55
|
-
// Casts here are safe due to our checks above.
|
|
56
|
-
...(creationHint
|
|
57
|
-
? { creationHint: creationHint }
|
|
58
|
-
: {}),
|
|
59
|
-
}
|
|
60
|
-
: {
|
|
61
|
-
signerAddress: owner.address,
|
|
62
|
-
...(creationHint
|
|
63
|
-
? {
|
|
64
|
-
creationHint: creationHint,
|
|
65
|
-
}
|
|
66
|
-
: {}),
|
|
67
|
-
}),
|
|
46
|
+
...params,
|
|
47
|
+
signerAddress,
|
|
68
48
|
includeCounterfactualInfo: true,
|
|
69
49
|
};
|
|
70
50
|
const cachedAccount = client.internal?.getAccount();
|
|
71
51
|
if (cachedAccount &&
|
|
72
|
-
((
|
|
73
|
-
cachedAccount.address
|
|
52
|
+
((args.accountAddress &&
|
|
53
|
+
isAddressEqual(cachedAccount.address, args.accountAddress)) ||
|
|
74
54
|
deepEqual(cachedAccount.requestParams, args, { strict: true }))) {
|
|
75
55
|
LOGGER.debug("requestAccount:cache-hit", {
|
|
76
56
|
address: cachedAccount.address,
|
|
77
57
|
});
|
|
78
58
|
return {
|
|
79
59
|
address: cachedAccount.address,
|
|
60
|
+
type: "json-rpc",
|
|
80
61
|
};
|
|
81
62
|
}
|
|
82
|
-
const
|
|
63
|
+
const rpcParams = Value.Encode(schema.request, args);
|
|
64
|
+
const rpcResp = await client.request({
|
|
83
65
|
method: "wallet_requestAccount",
|
|
84
|
-
params: [
|
|
66
|
+
params: [rpcParams],
|
|
85
67
|
});
|
|
68
|
+
const resp = Value.Decode(schema.response, rpcResp);
|
|
86
69
|
client.internal?.setAccount({
|
|
87
70
|
address: resp.accountAddress,
|
|
88
71
|
requestParams: args,
|
|
@@ -90,6 +73,7 @@ export async function requestAccount(client, params) {
|
|
|
90
73
|
LOGGER.debug("requestAccount:done", { address: resp.accountAddress });
|
|
91
74
|
return {
|
|
92
75
|
address: resp.accountAddress,
|
|
76
|
+
type: "json-rpc",
|
|
93
77
|
};
|
|
94
78
|
}
|
|
95
79
|
//# sourceMappingURL=requestAccount.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requestAccount.js","sourceRoot":"","sources":["../../../src/actions/requestAccount.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"requestAccount.js","sourceRoot":"","sources":["../../../src/actions/requestAccount.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAsC,MAAM,MAAM,CAAC;AAC1E,OAAO,EAAE,qBAAqB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AACtF,OAA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,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;YAC3D,SAAS,CAAC,aAAa,CAAC,aAAa,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EACjE,CAAC;QACD,MAAM,CAAC,KAAK,CAAC,0BAA0B,EAAE;YACvC,OAAO,EAAE,aAAa,CAAC,OAAO;SAC/B,CAAC,CAAC;QACH,OAAO;YACL,OAAO,EAAE,aAAa,CAAC,OAAO;YAC9B,IAAI,EAAE,UAAU;SACjB,CAAC;IACJ,CAAC;IAED,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAC5B,MAAM,CAAC,OAAO,EACd,IAAuC,CACxC,CAAC;IAEF,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QACnC,MAAM,EAAE,uBAAuB;QAC/B,MAAM,EAAE,CAAC,SAAS,CAAC;KACpB,CAAC,CAAC;IAEH,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAEpD,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC;QAC1B,OAAO,EAAE,IAAI,CAAC,cAAc;QAC5B,aAAa,EAAE,IAAI;KACpB,CAAC,CAAC;IAEH,MAAM,CAAC,KAAK,CAAC,qBAAqB,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC;IAEtE,OAAO;QACL,OAAO,EAAE,IAAI,CAAC,cAAc;QAC5B,IAAI,EAAE,UAAU;KACjB,CAAC;AACJ,CAAC","sourcesContent":["import type { Address } from \"abitype\";\nimport { isAddressEqual, type JsonRpcAccount, type Prettify } from \"viem\";\nimport { wallet_requestAccount as MethodSchema } from \"@alchemy/wallet-api-types/rpc\";\nimport deepEqual from \"deep-equal\";\nimport type { DistributiveOmit, InnerWalletApiClient } from \"../types\";\nimport { LOGGER } from \"../logger.js\";\nimport { isLocalAccount } from \"../utils/assertions.js\";\nimport { Value } from \"typebox/value\";\nimport { methodSchema, type MethodParams } from \"../utils/schema.js\";\n\nconst schema = methodSchema(MethodSchema);\ntype BaseRequestAccountParams = MethodParams<typeof MethodSchema>;\n\nexport type RequestAccountParams = Prettify<\n DistributiveOmit<\n Extract<BaseRequestAccountParams, { signerAddress: Address }>,\n \"signerAddress\" | \"includeCounterfactualInfo\"\n > &\n (\n | { signerAddress?: Address; accountAddress?: never }\n | { signerAddress?: never; accountAddress: Address }\n )\n>;\n\nexport type RequestAccountResult = JsonRpcAccount<Address>;\n\n/**\n * Requests a smart account address for the provided signer using the wallet API client.\n *\n * Note: This is only needed for non-EIP-7702 accounts. The client defaults to using\n * EIP-7702 with the signer's address, so you can call `prepareCalls` or `sendCalls`\n * directly without first calling `requestAccount`.\n *\n * If an account already exists for the signer, it will always return that account unless a new ID is specified.\n * If an account already exists, the creationHint will be ignored.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {RequestAccountParams} [params] - Optional parameters for requesting a specific account\n * @param {string} [params.id] - Optional identifier for the account. If specified, a new account with this ID will be created even if one already exists for the signer\n * @param {object} [params.creationHint] - Optional hints to guide account creation. These are ignored if an account already exists\n * @returns {Promise<RequestAccountResult>} A Promise that resolves to an object containing a smart account address\n *\n * @example\n * ```ts\n * // Request a non-7702 smart account\n * const account = await client.requestAccount();\n * ```\n */\nexport async function requestAccount(\n client: InnerWalletApiClient,\n params?: RequestAccountParams,\n): Promise<RequestAccountResult> {\n LOGGER.debug(\"requestAccount:start\", {\n hasParams: !!params,\n hasAccountOnClient: !!client.account,\n });\n\n const signerAddress =\n (params && \"signerAddress\" in params ? params.signerAddress : undefined) ??\n (isLocalAccount(client.owner)\n ? client.owner.address\n : client.owner.account.address);\n\n const args =\n params && \"accountAddress\" in params && params.accountAddress\n ? {\n accountAddress: params.accountAddress,\n includeCounterfactualInfo: true,\n }\n : {\n ...params,\n signerAddress,\n includeCounterfactualInfo: true,\n };\n\n const cachedAccount = client.internal?.getAccount();\n\n if (\n cachedAccount &&\n ((args.accountAddress &&\n isAddressEqual(cachedAccount.address, args.accountAddress)) ||\n deepEqual(cachedAccount.requestParams, args, { strict: true }))\n ) {\n LOGGER.debug(\"requestAccount:cache-hit\", {\n address: cachedAccount.address,\n });\n return {\n address: cachedAccount.address,\n type: \"json-rpc\",\n };\n }\n\n const rpcParams = Value.Encode(\n schema.request,\n args satisfies BaseRequestAccountParams,\n );\n\n const rpcResp = await client.request({\n method: \"wallet_requestAccount\",\n params: [rpcParams],\n });\n\n const resp = Value.Decode(schema.response, rpcResp);\n\n client.internal?.setAccount({\n address: resp.accountAddress,\n requestParams: args,\n });\n\n LOGGER.debug(\"requestAccount:done\", { address: resp.accountAddress });\n\n return {\n address: resp.accountAddress,\n type: \"json-rpc\",\n };\n}\n"]}
|
|
@@ -1,38 +1,44 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { InnerWalletApiClient } from "../types.js";
|
|
1
|
+
import type { Chain, Prettify } from "viem";
|
|
2
|
+
import type { DistributiveOmit, InnerWalletApiClient } from "../types.js";
|
|
3
3
|
import { type PrepareCallsParams } from "./prepareCalls.js";
|
|
4
4
|
import { type SendPreparedCallsResult } from "./sendPreparedCalls.js";
|
|
5
|
-
export type SendCallsParams
|
|
5
|
+
export type SendCallsParams = Prettify<DistributiveOmit<PrepareCallsParams, "chainId"> & {
|
|
6
|
+
chain?: Pick<Chain, "id">;
|
|
7
|
+
}>;
|
|
6
8
|
export type SendCallsResult = Prettify<SendPreparedCallsResult>;
|
|
7
9
|
/**
|
|
8
10
|
* Prepares, signs, and submits calls. This function internally calls `prepareCalls`, `signPreparedCalls`, and `sendPreparedCalls`.
|
|
9
11
|
*
|
|
12
|
+
* The client defaults to using EIP-7702 with the signer's address, so you can call
|
|
13
|
+
* this directly without first calling `requestAccount`.
|
|
14
|
+
*
|
|
10
15
|
* @param {InnerWalletApiClient} client - The wallet API client to use for the request
|
|
11
|
-
* @param {
|
|
12
|
-
* @param {Array<{to: Address, data?: Hex, value?:
|
|
13
|
-
* @param {
|
|
16
|
+
* @param {SendCallsParams} params - Parameters for sending calls
|
|
17
|
+
* @param {Array<{to: Address, data?: Hex, value?: bigint}>} params.calls - Array of contract calls to execute
|
|
18
|
+
* @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).
|
|
14
19
|
* @param {object} [params.capabilities] - Optional capabilities to include with the request.
|
|
15
|
-
* @returns {Promise<SendPreparedCallsResult>} A Promise that resolves to the result containing the
|
|
20
|
+
* @returns {Promise<SendPreparedCallsResult>} A Promise that resolves to the result containing the call ID.
|
|
16
21
|
*
|
|
17
22
|
* @example
|
|
18
23
|
* ```ts
|
|
24
|
+
* // Send calls (uses signer address via EIP-7702 by default)
|
|
19
25
|
* const result = await client.sendCalls({
|
|
20
26
|
* calls: [{
|
|
21
27
|
* to: "0x1234...",
|
|
22
28
|
* data: "0xabcdef...",
|
|
23
|
-
* value:
|
|
29
|
+
* value: 0n
|
|
24
30
|
* }],
|
|
25
31
|
* capabilities: {
|
|
26
|
-
*
|
|
32
|
+
* paymaster: { policyId: "your-policy-id" }
|
|
27
33
|
* }
|
|
28
34
|
* });
|
|
29
35
|
*
|
|
30
|
-
* // The result contains the
|
|
31
|
-
* console.log(result.
|
|
36
|
+
* // The result contains the call ID
|
|
37
|
+
* console.log(result.id);
|
|
32
38
|
* ```
|
|
33
39
|
* <Note>
|
|
34
40
|
* If using this action with an ERC-20 paymaster in pre-operation mode with `autoPermit`, the contents of the permit will be hidden
|
|
35
41
|
* from the user. It is recommended to use the `prepareCalls` action instead to manually handle the permit signature.
|
|
36
42
|
* </Note>
|
|
37
43
|
*/
|
|
38
|
-
export declare function sendCalls
|
|
44
|
+
export declare function sendCalls(client: InnerWalletApiClient, params: SendCallsParams): Promise<SendCallsResult>;
|
|
@@ -3,34 +3,36 @@ import { signPreparedCalls } from "./signPreparedCalls.js";
|
|
|
3
3
|
import { sendPreparedCalls, } from "./sendPreparedCalls.js";
|
|
4
4
|
import { LOGGER } from "../logger.js";
|
|
5
5
|
import { signSignatureRequest } from "./signSignatureRequest.js";
|
|
6
|
-
import {
|
|
7
|
-
import { extractCapabilitiesForSending } from "../utils/capabilities.js";
|
|
8
|
-
import { BaseError } from "@alchemy/common";
|
|
6
|
+
import { extractCapabilitiesForSending, fromRpcCapabilities, } from "../utils/capabilities.js";
|
|
9
7
|
/**
|
|
10
8
|
* Prepares, signs, and submits calls. This function internally calls `prepareCalls`, `signPreparedCalls`, and `sendPreparedCalls`.
|
|
11
9
|
*
|
|
10
|
+
* The client defaults to using EIP-7702 with the signer's address, so you can call
|
|
11
|
+
* this directly without first calling `requestAccount`.
|
|
12
|
+
*
|
|
12
13
|
* @param {InnerWalletApiClient} client - The wallet API client to use for the request
|
|
13
|
-
* @param {
|
|
14
|
-
* @param {Array<{to: Address, data?: Hex, value?:
|
|
15
|
-
* @param {
|
|
14
|
+
* @param {SendCallsParams} params - Parameters for sending calls
|
|
15
|
+
* @param {Array<{to: Address, data?: Hex, value?: bigint}>} params.calls - Array of contract calls to execute
|
|
16
|
+
* @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).
|
|
16
17
|
* @param {object} [params.capabilities] - Optional capabilities to include with the request.
|
|
17
|
-
* @returns {Promise<SendPreparedCallsResult>} A Promise that resolves to the result containing the
|
|
18
|
+
* @returns {Promise<SendPreparedCallsResult>} A Promise that resolves to the result containing the call ID.
|
|
18
19
|
*
|
|
19
20
|
* @example
|
|
20
21
|
* ```ts
|
|
22
|
+
* // Send calls (uses signer address via EIP-7702 by default)
|
|
21
23
|
* const result = await client.sendCalls({
|
|
22
24
|
* calls: [{
|
|
23
25
|
* to: "0x1234...",
|
|
24
26
|
* data: "0xabcdef...",
|
|
25
|
-
* value:
|
|
27
|
+
* value: 0n
|
|
26
28
|
* }],
|
|
27
29
|
* capabilities: {
|
|
28
|
-
*
|
|
30
|
+
* paymaster: { policyId: "your-policy-id" }
|
|
29
31
|
* }
|
|
30
32
|
* });
|
|
31
33
|
*
|
|
32
|
-
* // The result contains the
|
|
33
|
-
* console.log(result.
|
|
34
|
+
* // The result contains the call ID
|
|
35
|
+
* console.log(result.id);
|
|
34
36
|
* ```
|
|
35
37
|
* <Note>
|
|
36
38
|
* If using this action with an ERC-20 paymaster in pre-operation mode with `autoPermit`, the contents of the permit will be hidden
|
|
@@ -42,16 +44,18 @@ export async function sendCalls(client, params) {
|
|
|
42
44
|
calls: params.calls?.length,
|
|
43
45
|
hasCapabilities: !!params.capabilities,
|
|
44
46
|
});
|
|
45
|
-
|
|
47
|
+
const { chain, ...prepareCallsParams } = params;
|
|
48
|
+
let calls = await prepareCalls(client, {
|
|
49
|
+
...prepareCallsParams,
|
|
50
|
+
...(chain != null ? { chainId: chain.id } : {}),
|
|
51
|
+
});
|
|
46
52
|
if (calls.type === "paymaster-permit") {
|
|
47
|
-
if (isWebAuthnAccount(client.owner)) {
|
|
48
|
-
throw new BaseError("WebAuthn signer is not currently supported for signing paymaster permit signatures");
|
|
49
|
-
}
|
|
50
53
|
const signature = await signSignatureRequest(client, calls.signatureRequest);
|
|
51
54
|
const secondCallParams = {
|
|
52
|
-
|
|
55
|
+
account: calls.modifiedRequest.from,
|
|
53
56
|
calls: calls.modifiedRequest.calls,
|
|
54
|
-
|
|
57
|
+
chainId: calls.modifiedRequest.chainId,
|
|
58
|
+
capabilities: fromRpcCapabilities(calls.modifiedRequest.capabilities),
|
|
55
59
|
// WebAuthn signatures are not supported for paymaster permits (throws above).
|
|
56
60
|
paymasterPermitSignature: signature,
|
|
57
61
|
};
|