@alchemy/wallet-apis 0.0.0-alpha.20 → 0.0.0-alpha.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +30 -0
- package/dist/esm/actions/formatSign.js +3 -4
- package/dist/esm/actions/formatSign.js.map +1 -1
- package/dist/esm/actions/grantPermissions.js +3 -4
- package/dist/esm/actions/grantPermissions.js.map +1 -1
- package/dist/esm/actions/listAccounts.js +3 -4
- package/dist/esm/actions/listAccounts.js.map +1 -1
- package/dist/esm/actions/prepareCalls.js +3 -4
- package/dist/esm/actions/prepareCalls.js.map +1 -1
- package/dist/esm/actions/prepareSign.js +3 -4
- package/dist/esm/actions/prepareSign.js.map +1 -1
- package/dist/esm/actions/requestAccount.js +3 -4
- package/dist/esm/actions/requestAccount.js.map +1 -1
- package/dist/esm/actions/sendPreparedCalls.js +3 -4
- package/dist/esm/actions/sendPreparedCalls.js.map +1 -1
- package/dist/esm/actions/signTypedData.d.ts +0 -1
- package/dist/esm/actions/signTypedData.js +0 -1
- package/dist/esm/actions/signTypedData.js.map +1 -1
- package/dist/esm/experimental/actions/requestQuoteV0.d.ts +16 -3
- package/dist/esm/experimental/actions/requestQuoteV0.js +19 -5
- package/dist/esm/experimental/actions/requestQuoteV0.js.map +1 -1
- package/dist/esm/utils/schema.d.ts +3 -1
- package/dist/esm/utils/schema.js +58 -0
- package/dist/esm/utils/schema.js.map +1 -1
- 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.map +1 -1
- package/dist/types/actions/grantPermissions.d.ts.map +1 -1
- package/dist/types/actions/listAccounts.d.ts.map +1 -1
- package/dist/types/actions/prepareCalls.d.ts.map +1 -1
- package/dist/types/actions/prepareSign.d.ts.map +1 -1
- package/dist/types/actions/requestAccount.d.ts.map +1 -1
- package/dist/types/actions/sendPreparedCalls.d.ts.map +1 -1
- package/dist/types/actions/signTypedData.d.ts +0 -1
- package/dist/types/actions/signTypedData.d.ts.map +1 -1
- package/dist/types/experimental/actions/requestQuoteV0.d.ts +16 -3
- package/dist/types/experimental/actions/requestQuoteV0.d.ts.map +1 -1
- package/dist/types/utils/schema.d.ts +3 -1
- package/dist/types/utils/schema.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +3 -3
- package/src/actions/formatSign.ts +5 -4
- package/src/actions/grantPermissions.ts +9 -11
- package/src/actions/listAccounts.ts +5 -7
- package/src/actions/prepareCalls.ts +5 -4
- package/src/actions/prepareSign.ts +5 -4
- package/src/actions/requestAccount.ts +8 -7
- package/src/actions/sendPreparedCalls.ts +4 -6
- package/src/actions/signTypedData.ts +0 -1
- package/src/experimental/actions/requestQuoteV0.ts +48 -6
- package/src/utils/schema.ts +79 -1
- package/src/version.ts +1 -1
package/LICENSE
CHANGED
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# @alchemy/wallet-apis
|
|
2
|
+
|
|
3
|
+
High-level viem-style client for Alchemy's Smart Wallet APIs. Provides EIP-7702 smart wallet support with signing, transaction preparation, and call sending.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @alchemy/wallet-apis @alchemy/common viem
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Key Exports
|
|
12
|
+
|
|
13
|
+
- **`createSmartWalletClient`** - Factory to create a `SmartWalletClient` (viem client extended with smart wallet actions)
|
|
14
|
+
- **`alchemyWalletTransport`** - Alchemy transport pre-configured for the Wallet API gateway
|
|
15
|
+
- **`smartWalletActions`** - Client decorator attaching all wallet API actions
|
|
16
|
+
|
|
17
|
+
### Actions
|
|
18
|
+
|
|
19
|
+
- **Signing** - `signMessage`, `signTypedData`, `prepareSign`, `signPreparedCalls`, `signSignatureRequest`
|
|
20
|
+
- **Transactions** - `prepareCalls`, `sendCalls`, `sendPreparedCalls`
|
|
21
|
+
- **Account management** - `getCapabilities`, `listAccounts`, `requestAccount`
|
|
22
|
+
- **Permissions** - `grantPermissions`
|
|
23
|
+
|
|
24
|
+
### Experimental (`@alchemy/wallet-apis/experimental`)
|
|
25
|
+
|
|
26
|
+
- `requestQuoteV0`, `swapActions` - Pre-release swap functionality
|
|
27
|
+
|
|
28
|
+
## License
|
|
29
|
+
|
|
30
|
+
MIT
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { wallet_formatSign as MethodSchema } from "@alchemy/wallet-api-types/rpc";
|
|
2
2
|
import { LOGGER } from "../logger.js";
|
|
3
3
|
import { resolveAddress } from "../utils/resolve.js";
|
|
4
|
-
import {
|
|
5
|
-
import { methodSchema, } from "../utils/schema.js";
|
|
4
|
+
import { methodSchema, encode, decode, } from "../utils/schema.js";
|
|
6
5
|
const schema = methodSchema(MethodSchema);
|
|
7
6
|
/**
|
|
8
7
|
* Formats a signature request for signing messages or transactions.
|
|
@@ -29,7 +28,7 @@ export async function formatSign(client, params) {
|
|
|
29
28
|
: client.account.address;
|
|
30
29
|
LOGGER.debug("formatSign:start");
|
|
31
30
|
const { account: _, chainId: __, ...rest } = params;
|
|
32
|
-
const rpcParams =
|
|
31
|
+
const rpcParams = encode(schema.request, {
|
|
33
32
|
...rest,
|
|
34
33
|
from,
|
|
35
34
|
chainId: params.chainId ?? client.chain.id,
|
|
@@ -39,6 +38,6 @@ export async function formatSign(client, params) {
|
|
|
39
38
|
params: [rpcParams],
|
|
40
39
|
});
|
|
41
40
|
LOGGER.debug("formatSign:done");
|
|
42
|
-
return
|
|
41
|
+
return decode(schema.response, rpcResp);
|
|
43
42
|
}
|
|
44
43
|
//# sourceMappingURL=formatSign.js.map
|
|
@@ -1 +1 @@
|
|
|
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;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CAAC,iBAAiB,CAAC,CAAC;IAChC,OAAO,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AAC1C,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 {\n methodSchema,\n encode,\n decode,\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 = encode(schema.request, {\n ...rest,\n from,\n chainId: params.chainId ?? client.chain.id,\n });\n\n const rpcResp = await client.request({\n method: \"wallet_formatSign\",\n params: [rpcParams],\n });\n\n LOGGER.debug(\"formatSign:done\");\n return decode(schema.response, rpcResp);\n}\n"]}
|
|
@@ -2,9 +2,8 @@ import { concatHex } from "viem";
|
|
|
2
2
|
import { wallet_createSession as MethodSchema } from "@alchemy/wallet-api-types/rpc";
|
|
3
3
|
import { signSignatureRequest } from "./signSignatureRequest.js";
|
|
4
4
|
import { LOGGER } from "../logger.js";
|
|
5
|
-
import { Value } from "typebox/value";
|
|
6
5
|
import { resolveAddress } from "../utils/resolve.js";
|
|
7
|
-
import { methodSchema } from "../utils/schema.js";
|
|
6
|
+
import { methodSchema, encode, decode, } from "../utils/schema.js";
|
|
8
7
|
const schema = methodSchema(MethodSchema);
|
|
9
8
|
/**
|
|
10
9
|
* Grants permissions to a smart account by creating a session.
|
|
@@ -67,7 +66,7 @@ export async function grantPermissions(client, params) {
|
|
|
67
66
|
LOGGER.debug("grantPermissions:start", { expirySec: params.expirySec });
|
|
68
67
|
const chainId = params.chainId ?? client.chain.id;
|
|
69
68
|
const { account: _, chainId: __, ...rest } = params;
|
|
70
|
-
const rpcParams =
|
|
69
|
+
const rpcParams = encode(schema.request, {
|
|
71
70
|
...rest,
|
|
72
71
|
account,
|
|
73
72
|
chainId,
|
|
@@ -76,7 +75,7 @@ export async function grantPermissions(client, params) {
|
|
|
76
75
|
method: "wallet_createSession",
|
|
77
76
|
params: [rpcParams],
|
|
78
77
|
});
|
|
79
|
-
const { sessionId, signatureRequest } =
|
|
78
|
+
const { sessionId, signatureRequest } = decode(schema.response, rpcResp);
|
|
80
79
|
const signature = await signSignatureRequest(client, signatureRequest);
|
|
81
80
|
const res = {
|
|
82
81
|
context: concatHex([
|
|
@@ -1 +1 @@
|
|
|
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,E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C;IAEH,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,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAEzE,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 { resolveAddress, type AccountParam } from \"../utils/resolve.js\";\nimport {\n methodSchema,\n encode,\n decode,\n type MethodParams,\n} 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 = encode(schema.request, {\n ...rest,\n account,\n chainId,\n });\n\n const rpcResp = await client.request({\n method: \"wallet_createSession\",\n params: [rpcParams],\n });\n\n const { sessionId, signatureRequest } = decode(schema.response, rpcResp);\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,8 +1,7 @@
|
|
|
1
1
|
import { LOGGER } from "../logger.js";
|
|
2
2
|
import { wallet_listAccounts as MethodSchema } from "@alchemy/wallet-api-types/rpc";
|
|
3
3
|
import { isLocalAccount } from "../utils/assertions.js";
|
|
4
|
-
import {
|
|
5
|
-
import { methodSchema, } from "../utils/schema.js";
|
|
4
|
+
import { methodSchema, encode, decode, } from "../utils/schema.js";
|
|
6
5
|
const schema = methodSchema(MethodSchema);
|
|
7
6
|
/**
|
|
8
7
|
* Lists all smart accounts for a given signer using the wallet API client.
|
|
@@ -36,7 +35,7 @@ export async function listAccounts(client, params) {
|
|
|
36
35
|
? client.owner.address
|
|
37
36
|
: client.owner.account.address);
|
|
38
37
|
LOGGER.debug("listAccounts:start", { hasAfter: !!params.after });
|
|
39
|
-
const rpcParams =
|
|
38
|
+
const rpcParams = encode(schema.request, {
|
|
40
39
|
...params,
|
|
41
40
|
signerAddress,
|
|
42
41
|
});
|
|
@@ -44,7 +43,7 @@ export async function listAccounts(client, params) {
|
|
|
44
43
|
method: "wallet_listAccounts",
|
|
45
44
|
params: [rpcParams],
|
|
46
45
|
});
|
|
47
|
-
const res =
|
|
46
|
+
const res = decode(schema.response, rpcResp);
|
|
48
47
|
LOGGER.debug("listAccounts:done", { count: res.accounts.length });
|
|
49
48
|
return res;
|
|
50
49
|
}
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
1
|
+
{"version":3,"file":"listAccounts.js","sourceRoot":"","sources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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 {\n methodSchema,\n encode,\n decode,\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 = encode(schema.request, {\n ...params,\n signerAddress,\n });\n\n const rpcResp = await client.request({\n method: \"wallet_listAccounts\",\n params: [rpcParams],\n });\n\n const res = decode(schema.response, rpcResp);\n LOGGER.debug(\"listAccounts:done\", { count: res.accounts.length });\n\n return res;\n}\n"]}
|
|
@@ -2,8 +2,7 @@ import { LOGGER } from "../logger.js";
|
|
|
2
2
|
import { fromRpcCapabilities, mergeClientCapabilities, toRpcCapabilities, } from "../utils/capabilities.js";
|
|
3
3
|
import { resolveAddress } from "../utils/resolve.js";
|
|
4
4
|
import { wallet_prepareCalls as MethodSchema } from "@alchemy/wallet-api-types/rpc";
|
|
5
|
-
import {
|
|
6
|
-
import { methodSchema, } from "../utils/schema.js";
|
|
5
|
+
import { methodSchema, encode, decode, } from "../utils/schema.js";
|
|
7
6
|
const schema = methodSchema(MethodSchema);
|
|
8
7
|
/**
|
|
9
8
|
* Prepares a set of contract calls for execution by building a user operation.
|
|
@@ -47,7 +46,7 @@ export async function prepareCalls(client, params) {
|
|
|
47
46
|
hasCapabilities: !!params.capabilities,
|
|
48
47
|
});
|
|
49
48
|
const { account: _, chainId: __, ...rest } = params;
|
|
50
|
-
const rpcParams =
|
|
49
|
+
const rpcParams = encode(schema.request, {
|
|
51
50
|
...rest,
|
|
52
51
|
chainId,
|
|
53
52
|
from,
|
|
@@ -58,7 +57,7 @@ export async function prepareCalls(client, params) {
|
|
|
58
57
|
params: [rpcParams],
|
|
59
58
|
});
|
|
60
59
|
LOGGER.debug("prepareCalls:done");
|
|
61
|
-
const decoded =
|
|
60
|
+
const decoded = decode(schema.response, rpcResp);
|
|
62
61
|
// Transform paymaster-permit modifiedRequest from RPC format to client format:
|
|
63
62
|
// - `from` (RPC) → `account` (client)
|
|
64
63
|
// - `capabilities.paymasterService` (RPC) → `capabilities.paymaster` (client)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepareCalls.js","sourceRoot":"","sources":["../../../src/actions/prepareCalls.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,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,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,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE;QACvC,GAAG,IAAI;QACP,OAAO;QACP,IAAI;QACJ,YAAY,EAAE,iBAAiB,CAAC,YAAY,CAAC;KAC9C,CAAC,CAAC;IAEH,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,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAEjD,+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 {\n methodSchema,\n encode,\n decode,\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 = encode(schema.request, {\n ...rest,\n chainId,\n from,\n capabilities: toRpcCapabilities(capabilities),\n });\n\n const rpcResp = await client.request({\n method: \"wallet_prepareCalls\",\n params: [rpcParams],\n });\n\n LOGGER.debug(\"prepareCalls:done\");\n const decoded = 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"]}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { wallet_prepareSign as MethodSchema } from "@alchemy/wallet-api-types/rpc";
|
|
2
2
|
import { LOGGER } from "../logger.js";
|
|
3
3
|
import { resolveAddress } from "../utils/resolve.js";
|
|
4
|
-
import {
|
|
5
|
-
import { methodSchema, } from "../utils/schema.js";
|
|
4
|
+
import { methodSchema, encode, decode, } from "../utils/schema.js";
|
|
6
5
|
const schema = methodSchema(MethodSchema);
|
|
7
6
|
/**
|
|
8
7
|
* Prepares a signature request for signing messages or transactions.
|
|
@@ -27,7 +26,7 @@ export async function prepareSign(client, params) {
|
|
|
27
26
|
: client.account.address;
|
|
28
27
|
LOGGER.debug("prepareSign:start", { type: params.signatureRequest.type });
|
|
29
28
|
const { account: _, chainId: __, ...rest } = params;
|
|
30
|
-
const rpcParams =
|
|
29
|
+
const rpcParams = encode(schema.request, {
|
|
31
30
|
...rest,
|
|
32
31
|
from,
|
|
33
32
|
chainId: params.chainId ?? client.chain.id,
|
|
@@ -37,6 +36,6 @@ export async function prepareSign(client, params) {
|
|
|
37
36
|
params: [rpcParams],
|
|
38
37
|
});
|
|
39
38
|
LOGGER.debug("prepareSign:done");
|
|
40
|
-
return
|
|
39
|
+
return decode(schema.response, rpcResp);
|
|
41
40
|
}
|
|
42
41
|
//# sourceMappingURL=prepareSign.js.map
|
|
@@ -1 +1 @@
|
|
|
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,cAAc,CAAC;AACtC,OAAO,EAAE,cAAc,EAAqB,MAAM,qBAAqB,CAAC;AACxE,OAAO,
|
|
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,cAAc,CAAC;AACtC,OAAO,EAAE,cAAc,EAAqB,MAAM,qBAAqB,CAAC;AACxE,OAAO,EACL,YAAY,EACZ,MAAM,EACN,MAAM,GAGP,MAAM,oBAAoB,CAAC;AAE5B,MAAM,MAAM,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;AAc1C;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,MAA4B,EAC5B,MAAyB;IAEzB,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,mBAAmB,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAC;IAE1E,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;IACpD,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE;QACvC,GAAG,IAAI;QACP,IAAI;QACJ,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE;KAC3C,CAAC,CAAC;IAEH,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QACnC,MAAM,EAAE,oBAAoB;QAC5B,MAAM,EAAE,CAAC,SAAS,CAAC;KACpB,CAAC,CAAC;IAEH,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACjC,OAAO,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AAC1C,CAAC","sourcesContent":["import type { DistributiveOmit, InnerWalletApiClient } from \"../types.ts\";\nimport { wallet_prepareSign as MethodSchema } from \"@alchemy/wallet-api-types/rpc\";\nimport { LOGGER } from \"../logger.js\";\nimport { resolveAddress, type AccountParam } from \"../utils/resolve.js\";\nimport {\n methodSchema,\n encode,\n decode,\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 = encode(schema.request, {\n ...rest,\n from,\n chainId: params.chainId ?? client.chain.id,\n });\n\n const rpcResp = await client.request({\n method: \"wallet_prepareSign\",\n params: [rpcParams],\n });\n\n LOGGER.debug(\"prepareSign:done\");\n return decode(schema.response, rpcResp);\n}\n"]}
|
|
@@ -3,8 +3,7 @@ import { wallet_requestAccount as MethodSchema } from "@alchemy/wallet-api-types
|
|
|
3
3
|
import deepEqual from "deep-equal";
|
|
4
4
|
import { LOGGER } from "../logger.js";
|
|
5
5
|
import { isLocalAccount } from "../utils/assertions.js";
|
|
6
|
-
import {
|
|
7
|
-
import { methodSchema } from "../utils/schema.js";
|
|
6
|
+
import { methodSchema, encode, decode, } from "../utils/schema.js";
|
|
8
7
|
const schema = methodSchema(MethodSchema);
|
|
9
8
|
/**
|
|
10
9
|
* Requests a smart account address for the provided signer using the wallet API client.
|
|
@@ -60,12 +59,12 @@ export async function requestAccount(client, params) {
|
|
|
60
59
|
type: "json-rpc",
|
|
61
60
|
};
|
|
62
61
|
}
|
|
63
|
-
const rpcParams =
|
|
62
|
+
const rpcParams = encode(schema.request, args);
|
|
64
63
|
const rpcResp = await client.request({
|
|
65
64
|
method: "wallet_requestAccount",
|
|
66
65
|
params: [rpcParams],
|
|
67
66
|
});
|
|
68
|
-
const resp =
|
|
67
|
+
const resp = decode(schema.response, rpcResp);
|
|
69
68
|
client.internal?.setAccount({
|
|
70
69
|
address: resp.accountAddress,
|
|
71
70
|
requestParams: args,
|
|
@@ -1 +1 @@
|
|
|
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,OAAO,SAAS,MAAM,YAAY,CAAC;AAEnC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,
|
|
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,OAAO,SAAS,MAAM,YAAY,CAAC;AAEnC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EACL,YAAY,EACZ,MAAM,EACN,MAAM,GAEP,MAAM,oBAAoB,CAAC;AAE5B,MAAM,MAAM,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;AAgB1C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,MAA4B,EAC5B,MAA6B;IAE7B,MAAM,CAAC,KAAK,CAAC,sBAAsB,EAAE;QACnC,SAAS,EAAE,CAAC,CAAC,MAAM;QACnB,kBAAkB,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO;KACrC,CAAC,CAAC;IAEH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ACpB,CAAC,CAAC;IAEH,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAE9C,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 {\n methodSchema,\n encode,\n decode,\n type MethodParams,\n} 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 = encode(schema.request, args);\n\n const rpcResp = await client.request({\n method: \"wallet_requestAccount\",\n params: [rpcParams],\n });\n\n const resp = 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,8 +1,7 @@
|
|
|
1
1
|
import { LOGGER } from "../logger.js";
|
|
2
2
|
import { mergeClientCapabilities, toRpcCapabilities, } from "../utils/capabilities.js";
|
|
3
3
|
import { wallet_sendPreparedCalls as MethodSchema } from "@alchemy/wallet-api-types/rpc";
|
|
4
|
-
import {
|
|
5
|
-
import { methodSchema, } from "../utils/schema.js";
|
|
4
|
+
import { methodSchema, encode, decode, } from "../utils/schema.js";
|
|
6
5
|
const schema = methodSchema(MethodSchema);
|
|
7
6
|
/**
|
|
8
7
|
* Sends prepared calls by submitting a signed user operation.
|
|
@@ -47,12 +46,12 @@ export async function sendPreparedCalls(client, params) {
|
|
|
47
46
|
chainId,
|
|
48
47
|
capabilities: toRpcCapabilities(capabilities),
|
|
49
48
|
};
|
|
50
|
-
const rpcParams =
|
|
49
|
+
const rpcParams = encode(schema.request, fullParams);
|
|
51
50
|
const rpcResp = await client.request({
|
|
52
51
|
method: "wallet_sendPreparedCalls",
|
|
53
52
|
params: [rpcParams],
|
|
54
53
|
});
|
|
55
54
|
LOGGER.debug("sendPreparedCalls:done");
|
|
56
|
-
return
|
|
55
|
+
return decode(schema.response, rpcResp);
|
|
57
56
|
}
|
|
58
57
|
//# sourceMappingURL=sendPreparedCalls.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sendPreparedCalls.js","sourceRoot":"","sources":["../../../src/actions/sendPreparedCalls.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EACL,uBAAuB,EACvB,iBAAiB,GAElB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,wBAAwB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AACzF,OAAO,
|
|
1
|
+
{"version":3,"file":"sendPreparedCalls.js","sourceRoot":"","sources":["../../../src/actions/sendPreparedCalls.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EACL,uBAAuB,EACvB,iBAAiB,GAElB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,wBAAwB,IAAI,YAAY,EA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nerWalletApiClient } from \"../types.ts\";\nimport { LOGGER } from \"../logger.js\";\nimport {\n mergeClientCapabilities,\n toRpcCapabilities,\n type WithCapabilities,\n} from \"../utils/capabilities.js\";\nimport { wallet_sendPreparedCalls as MethodSchema } from \"@alchemy/wallet-api-types/rpc\";\nimport {\n methodSchema,\n encode,\n decode,\n type MethodParams,\n type MethodResponse,\n} from \"../utils/schema.js\";\n\nconst schema = methodSchema(MethodSchema);\ntype BaseSendPreparedCallsParams = MethodParams<typeof MethodSchema>;\ntype SendPreparedCallsResponse = MethodResponse<typeof MethodSchema>;\n\nexport type SendPreparedCallsParams = Prettify<\n WithCapabilities<\n DistributiveOmit<BaseSendPreparedCallsParams, \"chainId\"> & {\n chainId?: number;\n }\n >\n>;\n\nexport type SendPreparedCallsResult = SendPreparedCallsResponse;\n\n/**\n * Sends prepared calls by submitting a signed user operation.\n * This method is used after signing the signature request returned from prepareCalls.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {SendPreparedCallsParams} params - Parameters for sending prepared calls\n * @returns {Promise<SendPreparedCallsResult>} A Promise that resolves to the result containing the call ID\n *\n * @example\n * ```ts\n * // First prepare the calls\n * const preparedCalls = 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 * // Then sign the calls\n * const signedCalls = await client.signPreparedCalls(preparedCalls);\n *\n * // Then send the prepared calls with the signature\n * const result = await client.sendPreparedCalls({\n * signedCalls,\n * });\n * ```\n */\nexport async function sendPreparedCalls(\n client: InnerWalletApiClient,\n params: SendPreparedCallsParams,\n): Promise<SendPreparedCallsResult> {\n const capabilities = mergeClientCapabilities(client, params.capabilities);\n\n LOGGER.debug(\"sendPreparedCalls:start\", { type: params.type });\n\n const { chainId: rawChainId, ...restParams } = params;\n const chainId = rawChainId ?? client.chain.id;\n\n const fullParams =\n restParams.type === \"array\"\n ? { ...restParams, capabilities: toRpcCapabilities(capabilities) }\n : {\n ...restParams,\n chainId,\n capabilities: toRpcCapabilities(capabilities),\n };\n\n const rpcParams = encode(schema.request, fullParams);\n\n const rpcResp = await client.request({\n method: \"wallet_sendPreparedCalls\",\n params: [rpcParams],\n });\n\n LOGGER.debug(\"sendPreparedCalls:done\");\n return decode(schema.response, rpcResp);\n}\n"]}
|
|
@@ -10,7 +10,6 @@ export type SignTypedDataResult = Prettify<Hex>;
|
|
|
10
10
|
* This method requests the account associated with the signer and uses it to sign the typed data.
|
|
11
11
|
*
|
|
12
12
|
* @param {InnerWalletApiClient} client - The wallet API client to use for the request
|
|
13
|
-
* @param {SignerClient} signerClient - The wallet client to use for signing
|
|
14
13
|
* @param {TypedDataDefinition} params - The typed data to sign, following EIP-712 format
|
|
15
14
|
* @returns {Promise<SignTypedDataResult>} A Promise that resolves to the signature as a hex string
|
|
16
15
|
*
|
|
@@ -10,7 +10,6 @@ import { resolveAddress } from "../utils/resolve.js";
|
|
|
10
10
|
* This method requests the account associated with the signer and uses it to sign the typed data.
|
|
11
11
|
*
|
|
12
12
|
* @param {InnerWalletApiClient} client - The wallet API client to use for the request
|
|
13
|
-
* @param {SignerClient} signerClient - The wallet client to use for signing
|
|
14
13
|
* @param {TypedDataDefinition} params - The typed data to sign, following EIP-712 format
|
|
15
14
|
* @returns {Promise<SignTypedDataResult>} A Promise that resolves to the signature as a hex string
|
|
16
15
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signTypedData.js","sourceRoot":"","sources":["../../../src/actions/signTypedData.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqD,MAAM,MAAM,CAAC;AAEzE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,o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,gBAAgB,CAAC,CAAC;IAE7E,MAAM,SAAS,GAAG,MAAM,UAAU,CAAC,MAAM,EAAE;QACzC,OAAO,EAAE,cAAc;QACvB,SAAS,EAAE;YACT,IAAI,EAAE,OAAO;YACb,IAAI,EAAE,MAAM,CAAC,IAAI;SAClB;KACF,CAAC,CAAC;IACH,MAAM,CAAC,KAAK,CAAC,oBAAoB,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC,CAAC;IAC7D,OAAO,SAAS,CAAC,SAAS,CAAC;AAC7B,CAAC","sourcesContent":["import { type Hex, type Prettify, type TypedDataDefinition } from \"viem\";\nimport type { InnerWalletApiClient } from \"../types.ts\";\nimport { prepareSign } from \"./prepareSign.js\";\nimport { signSignatureRequest } from \"./signSignatureRequest.js\";\nimport { formatSign } from \"./formatSign.js\";\nimport { typedDataToJsonSafe } from \"../utils/format.js\";\nimport { LOGGER } from \"../logger.js\";\nimport { resolveAddress, type AccountParam } from \"../utils/resolve.js\";\n\nexport type SignTypedDataParams = Prettify<\n TypedDataDefinition & {\n account?: AccountParam;\n }\n>;\n\nexport type SignTypedDataResult = Prettify<Hex>;\n\n/**\n * Signs typed data (EIP-712) using the smart account.\n * This method requests the account associated with the signer and uses it to sign the typed data.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {TypedDataDefinition} params - The typed data to sign, following EIP-712 format\n * @returns {Promise<SignTypedDataResult>} A Promise that resolves to the signature as a hex string\n *\n * @example\n * ```ts\n * // Sign typed data\n * const signature = await client.signTypedData({\n * domain: {\n * name: 'Example DApp',\n * version: '1',\n * chainId: 1,\n * verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC'\n * },\n * types: {\n * Person: [\n * { name: 'name', type: 'string' },\n * { name: 'wallet', type: 'address' }\n * ]\n * },\n * primaryType: 'Person',\n * message: {\n * name: 'John Doe',\n * wallet: '0xAaAaAaAaAaAaAaAaAaAAAAAAAAaaaAaAaAaaAaAa'\n * }\n * });\n * ```\n */\n\nexport async function signTypedData(\n client: InnerWalletApiClient,\n params: SignTypedDataParams,\n): Promise<SignTypedDataResult> {\n LOGGER.debug(\"signTypedData:start\", {\n hasExplicitAccount: params.account != null,\n primaryType: params.primaryType,\n });\n const accountAddress = params.account\n ? resolveAddress(params.account)\n : client.account.address;\n\n const prepared = await prepareSign(client, {\n account: accountAddress,\n signatureRequest: {\n type: \"eth_signTypedData_v4\",\n data: typedDataToJsonSafe(params),\n },\n });\n\n const signed = await signSignatureRequest(client, prepared.signatureRequest);\n\n const formatted = await formatSign(client, {\n account: accountAddress,\n signature: {\n type: \"ecdsa\",\n data: signed.data,\n },\n });\n LOGGER.debug(\"signTypedData:done\", { from: accountAddress });\n return formatted.signature;\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Prettify } from "viem";
|
|
1
|
+
import type { Address, Prettify } from "viem";
|
|
2
2
|
import type { DistributiveOmit, InnerWalletApiClient } from "../../types.ts";
|
|
3
|
-
import { type WithCapabilities } from "../../utils/capabilities.js";
|
|
3
|
+
import { type PrepareCallsCapabilities, type WithCapabilities } from "../../utils/capabilities.js";
|
|
4
4
|
import { type AccountParam } from "../../utils/resolve.js";
|
|
5
5
|
import { wallet_requestQuote_v0 as MethodSchema } from "@alchemy/wallet-api-types/rpc";
|
|
6
6
|
import { type MethodParams, type MethodResponse } from "../../utils/schema.js";
|
|
@@ -10,7 +10,20 @@ export type RequestQuoteV0Params = Prettify<WithCapabilities<DistributiveOmit<Ba
|
|
|
10
10
|
account?: AccountParam;
|
|
11
11
|
chainId?: number;
|
|
12
12
|
}>>;
|
|
13
|
-
|
|
13
|
+
/** The modifiedRequest in client format: `account` instead of `from`, SDK capabilities. */
|
|
14
|
+
type ClientModifiedRequest = Prettify<Omit<Extract<RequestQuoteV0Response, {
|
|
15
|
+
type: "paymaster-permit";
|
|
16
|
+
}>["modifiedRequest"], "from" | "capabilities"> & {
|
|
17
|
+
account: Address;
|
|
18
|
+
capabilities?: PrepareCallsCapabilities;
|
|
19
|
+
}>;
|
|
20
|
+
export type RequestQuoteV0Result = Exclude<RequestQuoteV0Response, {
|
|
21
|
+
type: "paymaster-permit";
|
|
22
|
+
}> | (Omit<Extract<RequestQuoteV0Response, {
|
|
23
|
+
type: "paymaster-permit";
|
|
24
|
+
}>, "modifiedRequest"> & {
|
|
25
|
+
modifiedRequest: ClientModifiedRequest;
|
|
26
|
+
});
|
|
14
27
|
/**
|
|
15
28
|
* Requests a quote for a token swap, returning either prepared calls for smart wallets
|
|
16
29
|
* or raw calls for EOA wallets depending on the returnRawCalls parameter.
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { mergeClientCapabilities, toRpcCapabilities, } from "../../utils/capabilities.js";
|
|
1
|
+
import { fromRpcCapabilities, mergeClientCapabilities, toRpcCapabilities, } from "../../utils/capabilities.js";
|
|
2
2
|
import { resolveAddress } from "../../utils/resolve.js";
|
|
3
3
|
import { wallet_requestQuote_v0 as MethodSchema } from "@alchemy/wallet-api-types/rpc";
|
|
4
|
-
import {
|
|
5
|
-
import { methodSchema, } from "../../utils/schema.js";
|
|
4
|
+
import { methodSchema, encode, decode, } from "../../utils/schema.js";
|
|
6
5
|
const schema = methodSchema(MethodSchema);
|
|
7
6
|
/**
|
|
8
7
|
* Requests a quote for a token swap, returning either prepared calls for smart wallets
|
|
@@ -50,7 +49,7 @@ export async function requestQuoteV0(client, params) {
|
|
|
50
49
|
? undefined
|
|
51
50
|
: mergeClientCapabilities(client, "capabilities" in params ? params.capabilities : undefined);
|
|
52
51
|
const { account: _, chainId: __, ...rest } = params;
|
|
53
|
-
const rpcParams =
|
|
52
|
+
const rpcParams = encode(schema.request, {
|
|
54
53
|
...rest,
|
|
55
54
|
chainId: params.chainId ?? client.chain.id,
|
|
56
55
|
from,
|
|
@@ -60,6 +59,21 @@ export async function requestQuoteV0(client, params) {
|
|
|
60
59
|
method: "wallet_requestQuote_v0",
|
|
61
60
|
params: [rpcParams],
|
|
62
61
|
});
|
|
63
|
-
|
|
62
|
+
const decoded = decode(schema.response, rpcResp);
|
|
63
|
+
// Transform paymaster-permit modifiedRequest from RPC format to client format:
|
|
64
|
+
// - `from` (RPC) → `account` (client)
|
|
65
|
+
// - `capabilities.paymasterService` (RPC) → `capabilities.paymaster` (client)
|
|
66
|
+
if ("type" in decoded && decoded.type === "paymaster-permit") {
|
|
67
|
+
const { from, capabilities, ...restModifiedRequest } = decoded.modifiedRequest;
|
|
68
|
+
return {
|
|
69
|
+
...decoded,
|
|
70
|
+
modifiedRequest: {
|
|
71
|
+
...restModifiedRequest,
|
|
72
|
+
account: from,
|
|
73
|
+
capabilities: fromRpcCapabilities(capabilities),
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
return decoded;
|
|
64
78
|
}
|
|
65
79
|
//# sourceMappingURL=requestQuoteV0.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requestQuoteV0.js","sourceRoot":"","sources":["../../../../src/experimental/actions/requestQuoteV0.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,uBAAuB,EACvB,iBAAiB,
|
|
1
|
+
{"version":3,"file":"requestQuoteV0.js","sourceRoot":"","sources":["../../../../src/experimental/actions/requestQuoteV0.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,mBAAmB,EACnB,uBAAuB,EACvB,iBAAiB,GAGlB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,cAAc,EAAqB,MAAM,wBAAwB,CAAC;AAC3E,OAAO,EAAE,sBAAsB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AACvF,OAAO,EACL,YAAY,EACZ,MAAM,EACN,MAAM,GAGP,MAAM,uBAAuB,CAAC;AAE/B,MAAM,MAAM,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;AAoC1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,MAA4B,EA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Ae,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 {\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_requestQuote_v0 as MethodSchema } from \"@alchemy/wallet-api-types/rpc\";\nimport {\n methodSchema,\n encode,\n decode,\n type MethodParams,\n type MethodResponse,\n} from \"../../utils/schema.js\";\n\nconst schema = methodSchema(MethodSchema);\ntype BaseRequestQuoteV0Params = MethodParams<typeof MethodSchema>;\ntype RequestQuoteV0Response = MethodResponse<typeof MethodSchema>;\n\nexport type RequestQuoteV0Params = Prettify<\n WithCapabilities<\n DistributiveOmit<BaseRequestQuoteV0Params, \"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<\n Extract<\n RequestQuoteV0Response,\n { type: \"paymaster-permit\" }\n >[\"modifiedRequest\"],\n \"from\" | \"capabilities\"\n > & {\n account: Address;\n capabilities?: PrepareCallsCapabilities;\n }\n>;\n\nexport type RequestQuoteV0Result =\n | Exclude<RequestQuoteV0Response, { type: \"paymaster-permit\" }>\n | (Omit<\n Extract<RequestQuoteV0Response, { type: \"paymaster-permit\" }>,\n \"modifiedRequest\"\n > & {\n modifiedRequest: ClientModifiedRequest;\n });\n\n/**\n * Requests a quote for a token swap, returning either prepared calls for smart wallets\n * or raw calls for EOA wallets depending on the returnRawCalls parameter.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {RequestQuoteV0Params} params - Parameters for requesting a swap quote\n * @param {Address} params.fromToken - The address of the token to swap from\n * @param {Address} params.toToken - The address of the token to swap to\n * @param {Hex} [params.fromAmount] - The amount to swap from (mutually exclusive with minimumToAmount)\n * @param {Hex} [params.minimumToAmount] - The minimum amount to receive (mutually exclusive with fromAmount)\n * @param {AccountParam} [params.account] - The account to execute the swap 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 {Hex} [params.slippage] - The maximum acceptable slippage percentage\n * @param {boolean} [params.returnRawCalls] - Whether to return raw calls for EOA wallets (defaults to false for smart wallets)\n * @param {object} [params.capabilities] - Optional capabilities to include with the request (only available when returnRawCalls is false)\n * @param {Array<{to: Address, data?: Hex, value?: Hex}>} [params.postCalls] - Optional calls to execute after the swap\n * @returns {Promise<RequestQuoteV0Result>} A Promise that resolves to either prepared calls or raw calls depending on returnRawCalls\n *\n * @example\n * ```ts twoslash\n * // Request a quote for smart wallet (prepared calls)\n * const quote = await client.requestQuoteV0({\n * fromToken: \"0xA0b86a33E6441e1d6a8E8C7a8E8E8E8E8E8E8E8E\",\n * toToken: \"0xB0b86a33E6441e1d6a8E8C7a8E8E8E8E8E8E8E8E\",\n * fromAmount: 1000000000000000000n, // 1 ETH\n * capabilities: {\n * paymaster: { policyId: \"your-policy-id\" }\n * }\n * });\n *\n * // Request a quote for EOA wallet (raw calls)\n * const rawQuote = await client.requestQuoteV0({\n * fromToken: \"0xA0b86a33E6441e1d6a8E8C7a8E8E8E8E8E8E8E8E\",\n * toToken: \"0xB0b86a33E6441e1d6a8E8C7a8E8E8E8E8E8E8E8E\",\n * fromAmount: 1000000000000000000n,\n * returnRawCalls: true\n * });\n * ```\n */\nexport async function requestQuoteV0(\n client: InnerWalletApiClient,\n params: RequestQuoteV0Params,\n): Promise<RequestQuoteV0Result> {\n const from = params.account\n ? resolveAddress(params.account)\n : client.account.address;\n\n const capabilities =\n \"returnRawCalls\" in params && params.returnRawCalls\n ? undefined\n : mergeClientCapabilities(\n client,\n \"capabilities\" in params ? params.capabilities : undefined,\n );\n\n const { account: _, chainId: __, ...rest } = params;\n const rpcParams = encode(schema.request, {\n ...rest,\n chainId: params.chainId ?? client.chain.id,\n from,\n ...(capabilities && { capabilities: toRpcCapabilities(capabilities) }),\n });\n\n const rpcResp = await client.request({\n method: \"wallet_requestQuote_v0\",\n params: [rpcParams],\n });\n\n const decoded = 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 (\"type\" in decoded && 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"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { TObject, TSchema, TTuple, StaticDecode } from "typebox";
|
|
1
|
+
import type { TObject, TSchema, TTuple, StaticDecode, StaticEncode } from "typebox";
|
|
2
2
|
/** Constraint for RPC method schemas from `@alchemy/wallet-api-types/rpc`. */
|
|
3
3
|
type RpcMethodSchema = TObject<{
|
|
4
4
|
Request: TObject<{
|
|
@@ -21,4 +21,6 @@ export declare function methodSchema<TReq extends TSchema, TRes extends TSchema>
|
|
|
21
21
|
export type MethodParams<T extends RpcMethodSchema> = StaticDecode<T["properties"]["Request"]["properties"]["params"]["items"][0]>;
|
|
22
22
|
/** Extracts the decoded response type from a method schema. */
|
|
23
23
|
export type MethodResponse<T extends RpcMethodSchema> = StaticDecode<T["properties"]["ReturnType"]>;
|
|
24
|
+
export declare function encode<const T extends TSchema>(schema: T, value: StaticDecode<T>): StaticEncode<T>;
|
|
25
|
+
export declare function decode<const T extends TSchema>(schema: T, value: StaticEncode<T>): StaticDecode<T>;
|
|
24
26
|
export {};
|