@alchemy/wallet-apis 0.0.0-alpha.19 → 0.0.0-alpha.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/actions/prepareCalls.d.ts +14 -3
- package/dist/esm/actions/prepareCalls.js +17 -2
- package/dist/esm/actions/prepareCalls.js.map +1 -1
- package/dist/esm/actions/sendCalls.js +2 -5
- package/dist/esm/actions/sendCalls.js.map +1 -1
- package/dist/esm/utils/capabilities.d.ts +14 -7
- package/dist/esm/utils/capabilities.js +3 -2
- package/dist/esm/utils/capabilities.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/prepareCalls.d.ts +14 -3
- package/dist/types/actions/prepareCalls.d.ts.map +1 -1
- package/dist/types/actions/sendCalls.d.ts.map +1 -1
- package/dist/types/utils/capabilities.d.ts +14 -7
- package/dist/types/utils/capabilities.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +4 -4
- package/src/actions/prepareCalls.ts +38 -3
- package/src/actions/sendCalls.ts +2 -8
- package/src/utils/capabilities.ts +23 -11
- package/src/version.ts +1 -1
|
@@ -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_prepareCalls as MethodSchema } from "@alchemy/wallet-api-types/rpc";
|
|
6
6
|
import { type MethodParams, type MethodResponse } from "../utils/schema.js";
|
|
@@ -10,7 +10,18 @@ export type PrepareCallsParams = Prettify<WithCapabilities<DistributiveOmit<Base
|
|
|
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<BasePrepareCallsParams, "from" | "capabilities"> & {
|
|
15
|
+
account: Address;
|
|
16
|
+
capabilities?: PrepareCallsCapabilities;
|
|
17
|
+
}>;
|
|
18
|
+
export type PrepareCallsResult = Exclude<PrepareCallsResponse, {
|
|
19
|
+
type: "paymaster-permit";
|
|
20
|
+
}> | (Omit<Extract<PrepareCallsResponse, {
|
|
21
|
+
type: "paymaster-permit";
|
|
22
|
+
}>, "modifiedRequest"> & {
|
|
23
|
+
modifiedRequest: ClientModifiedRequest;
|
|
24
|
+
});
|
|
14
25
|
/**
|
|
15
26
|
* Prepares a set of contract calls for execution by building a user operation.
|
|
16
27
|
* Returns the built user operation and a signature request that needs to be signed
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LOGGER } from "../logger.js";
|
|
2
|
-
import { mergeClientCapabilities, toRpcCapabilities, } from "../utils/capabilities.js";
|
|
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
5
|
import { Value } from "typebox/value";
|
|
@@ -58,6 +58,21 @@ export async function prepareCalls(client, params) {
|
|
|
58
58
|
params: [rpcParams],
|
|
59
59
|
});
|
|
60
60
|
LOGGER.debug("prepareCalls:done");
|
|
61
|
-
|
|
61
|
+
const decoded = Value.Decode(schema.response, rpcResp);
|
|
62
|
+
// Transform paymaster-permit modifiedRequest from RPC format to client format:
|
|
63
|
+
// - `from` (RPC) → `account` (client)
|
|
64
|
+
// - `capabilities.paymasterService` (RPC) → `capabilities.paymaster` (client)
|
|
65
|
+
if (decoded.type === "paymaster-permit") {
|
|
66
|
+
const { from, capabilities, ...restModifiedRequest } = decoded.modifiedRequest;
|
|
67
|
+
return {
|
|
68
|
+
...decoded,
|
|
69
|
+
modifiedRequest: {
|
|
70
|
+
...restModifiedRequest,
|
|
71
|
+
account: from,
|
|
72
|
+
capabilities: fromRpcCapabilities(capabilities),
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return decoded;
|
|
62
77
|
}
|
|
63
78
|
//# sourceMappingURL=prepareCalls.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepareCalls.js","sourceRoot":"","sources":["../../../src/actions/prepareCalls.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EACL,uBAAuB,EACvB,iBAAiB,
|
|
1
|
+
{"version":3,"file":"prepareCalls.js","sourceRoot":"","sources":["../../../src/actions/prepareCalls.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EACL,mBAAmB,EACnB,uBAAuB,EACvB,iBAAiB,GAGlB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,cAAc,EAAqB,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,mBAAmB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AACpF,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EACL,YAAY,GAGb,MAAM,oBAAoB,CAAC;AAE5B,MAAM,MAAM,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;AA8B1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAA4B,EAC5B,MAA0B;IAE1B,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO;QACzB,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC;QAChC,CAAC,CAAC,MAAM,CAAC,O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CAAC;aAChD;SACF,CAAC;IACJ,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type { Address, Prettify } from \"viem\";\nimport type { DistributiveOmit, InnerWalletApiClient } from \"../types.ts\";\nimport { LOGGER } from \"../logger.js\";\nimport {\n fromRpcCapabilities,\n mergeClientCapabilities,\n toRpcCapabilities,\n type PrepareCallsCapabilities,\n type WithCapabilities,\n} from \"../utils/capabilities.js\";\nimport { resolveAddress, type AccountParam } from \"../utils/resolve.js\";\nimport { wallet_prepareCalls as MethodSchema } from \"@alchemy/wallet-api-types/rpc\";\nimport { Value } from \"typebox/value\";\nimport {\n methodSchema,\n type MethodParams,\n type MethodResponse,\n} from \"../utils/schema.js\";\n\nconst schema = methodSchema(MethodSchema);\ntype BasePrepareCallsParams = MethodParams<typeof MethodSchema>;\ntype PrepareCallsResponse = MethodResponse<typeof MethodSchema>;\n\nexport type PrepareCallsParams = Prettify<\n WithCapabilities<\n DistributiveOmit<BasePrepareCallsParams, \"from\" | \"chainId\"> & {\n account?: AccountParam;\n chainId?: number;\n }\n >\n>;\n\n/** The modifiedRequest in client format: `account` instead of `from`, SDK capabilities. */\ntype ClientModifiedRequest = Prettify<\n Omit<BasePrepareCallsParams, \"from\" | \"capabilities\"> & {\n account: Address;\n capabilities?: PrepareCallsCapabilities;\n }\n>;\n\nexport type PrepareCallsResult =\n | Exclude<PrepareCallsResponse, { type: \"paymaster-permit\" }>\n | (Omit<\n Extract<PrepareCallsResponse, { type: \"paymaster-permit\" }>,\n \"modifiedRequest\"\n > & {\n modifiedRequest: ClientModifiedRequest;\n });\n\n/**\n * Prepares a set of contract calls for execution by building a user operation.\n * Returns the built user operation and a signature request that needs to be signed\n * before submitting to sendPreparedCalls.\n *\n * The client defaults to using EIP-7702 with the signer's address, so you can call\n * this directly without first calling `requestAccount`.\n *\n * @param {InnerWalletApiClient} client - The wallet API client to use for the request\n * @param {PrepareCallsParams} params - Parameters for preparing calls\n * @param {Array<{to: Address, data?: Hex, value?: bigint}>} params.calls - Array of contract calls to execute\n * @param {AccountParam} [params.account] - The account to execute the calls from. Can be an address string or an object with an `address` property. Defaults to the client's account (signer address via EIP-7702).\n * @param {object} [params.capabilities] - Optional capabilities to include with the request\n * @returns {Promise<PrepareCallsResult>} A Promise that resolves to the prepared calls result containing\n * the user operation data and signature request\n *\n * @example\n * ```ts\n * // Prepare a sponsored user operation call (uses signer address via EIP-7702 by default)\n * const result = await client.prepareCalls({\n * calls: [{\n * to: \"0x1234...\",\n * data: \"0xabcdef...\",\n * value: 0n\n * }],\n * capabilities: {\n * paymaster: { policyId: \"your-policy-id\" }\n * }\n * });\n * ```\n */\nexport async function prepareCalls(\n client: InnerWalletApiClient,\n params: PrepareCallsParams,\n): Promise<PrepareCallsResult> {\n const from = params.account\n ? resolveAddress(params.account)\n : client.account.address;\n\n const chainId = params.chainId ?? client.chain.id;\n\n const capabilities = mergeClientCapabilities(client, params.capabilities);\n\n LOGGER.debug(\"prepareCalls:start\", {\n callsCount: params.calls?.length,\n hasCapabilities: !!params.capabilities,\n });\n\n const { account: _, chainId: __, ...rest } = params;\n const rpcParams = Value.Encode(schema.request, {\n ...rest,\n chainId,\n from,\n capabilities: toRpcCapabilities(capabilities),\n } satisfies BasePrepareCallsParams);\n\n const rpcResp = await client.request({\n method: \"wallet_prepareCalls\",\n params: [rpcParams],\n });\n\n LOGGER.debug(\"prepareCalls:done\");\n const decoded = Value.Decode(schema.response, rpcResp);\n\n // Transform paymaster-permit modifiedRequest from RPC format to client format:\n // - `from` (RPC) → `account` (client)\n // - `capabilities.paymasterService` (RPC) → `capabilities.paymaster` (client)\n if (decoded.type === \"paymaster-permit\") {\n const { from, capabilities, ...restModifiedRequest } =\n decoded.modifiedRequest;\n return {\n ...decoded,\n modifiedRequest: {\n ...restModifiedRequest,\n account: from,\n capabilities: fromRpcCapabilities(capabilities),\n },\n };\n }\n\n return decoded;\n}\n"]}
|
|
@@ -3,7 +3,7 @@ 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 { extractCapabilitiesForSending
|
|
6
|
+
import { extractCapabilitiesForSending } from "../utils/capabilities.js";
|
|
7
7
|
/**
|
|
8
8
|
* Prepares, signs, and submits calls. This function internally calls `prepareCalls`, `signPreparedCalls`, and `sendPreparedCalls`.
|
|
9
9
|
*
|
|
@@ -52,10 +52,7 @@ export async function sendCalls(client, params) {
|
|
|
52
52
|
if (calls.type === "paymaster-permit") {
|
|
53
53
|
const signature = await signSignatureRequest(client, calls.signatureRequest);
|
|
54
54
|
const secondCallParams = {
|
|
55
|
-
|
|
56
|
-
calls: calls.modifiedRequest.calls,
|
|
57
|
-
chainId: calls.modifiedRequest.chainId,
|
|
58
|
-
capabilities: fromRpcCapabilities(calls.modifiedRequest.capabilities),
|
|
55
|
+
...calls.modifiedRequest,
|
|
59
56
|
// WebAuthn signatures are not supported for paymaster permits (throws above).
|
|
60
57
|
paymasterPermitSignature: signature,
|
|
61
58
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sendCalls.js","sourceRoot":"","sources":["../../../src/actions/sendCalls.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAA2B,MAAM,mBAAmB,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EACL,iBAAiB,GAElB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,
|
|
1
|
+
{"version":3,"file":"sendCalls.js","sourceRoot":"","sources":["../../../src/actions/sendCalls.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAA2B,MAAM,mBAAmB,CAAC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,CAAC;IAE3D,MAAM,6BAA6B,GAAG,6BAA6B,CACjE,MAAM,CAAC,YAAY,CACpB,CAAC;IAEF,MAAM,GAAG,GAAG,MAAM,iBAAiB,CAAC,MAAM,EAAE;QAC1C,GAAG,WAAW;QACd,GAAG,CAAC,6BAA6B,IAAI,IAAI;YACvC,CAAC,CAAC,EAAE,YAAY,EAAE,6BAA6B,EAAE;YACjD,CAAC,CAAC,EAAE,CAAC;KACR,CAAC,CAAC;IACH,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAC9B,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import type { Chain, Prettify } from \"viem\";\nimport type { DistributiveOmit, InnerWalletApiClient } from \"../types.js\";\nimport { prepareCalls, type PrepareCallsParams } from \"./prepareCalls.js\";\nimport { signPreparedCalls } from \"./signPreparedCalls.js\";\nimport {\n sendPreparedCalls,\n type SendPreparedCallsResult,\n} from \"./sendPreparedCalls.js\";\nimport { LOGGER } from \"../logger.js\";\nimport { signSignatureRequest } from \"./signSignatureRequest.js\";\nimport { extractCapabilitiesForSending } from \"../utils/capabilities.js\";\n\nexport type SendCallsParams = Prettify<\n DistributiveOmit<PrepareCallsParams, \"chainId\"> & {\n chain?: Pick<Chain, \"id\">;\n }\n>;\n\nexport type SendCallsResult = Prettify<SendPreparedCallsResult>;\n\n/**\n * Prepares, signs, and submits calls. This function internally calls `prepareCalls`, `signPreparedCalls`, and `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 {SendCallsParams} params - Parameters for sending 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<SendPreparedCallsResult>} A Promise that resolves to the result containing the call ID.\n *\n * @example\n * ```ts\n * // Send calls (uses signer address via EIP-7702 by default)\n * const result = await client.sendCalls({\n * calls: [{\n * to: \"0x1234...\",\n * data: \"0xabcdef...\",\n * value: 0n\n * }],\n * capabilities: {\n * paymaster: { policyId: \"your-policy-id\" }\n * }\n * });\n *\n * // The result contains the call ID\n * console.log(result.id);\n * ```\n * <Note>\n * If using this action with an ERC-20 paymaster in pre-operation mode with `autoPermit`, the contents of the permit will be hidden\n * from the user. It is recommended to use the `prepareCalls` action instead to manually handle the permit signature.\n * </Note>\n */\nexport async function sendCalls(\n client: InnerWalletApiClient,\n params: SendCallsParams,\n): Promise<SendCallsResult> {\n LOGGER.info(\"sendCalls:start\", {\n calls: params.calls?.length,\n hasCapabilities: !!params.capabilities,\n });\n const { chain, ...prepareCallsParams } = params;\n let calls = await prepareCalls(client, {\n ...prepareCallsParams,\n ...(chain != null ? { chainId: chain.id } : {}),\n });\n\n if (calls.type === \"paymaster-permit\") {\n const signature = await signSignatureRequest(\n client,\n calls.signatureRequest,\n );\n\n const secondCallParams = {\n ...calls.modifiedRequest,\n // WebAuthn signatures are not supported for paymaster permits (throws above).\n paymasterPermitSignature: signature as Exclude<\n typeof signature,\n { type: \"webauthn-p256\" }\n >,\n };\n\n calls = await prepareCalls(client, secondCallParams);\n }\n\n const signedCalls = await signPreparedCalls(client, calls);\n\n const sendPreparedCallsCapabilities = extractCapabilitiesForSending(\n params.capabilities,\n );\n\n const res = await sendPreparedCalls(client, {\n ...signedCalls,\n ...(sendPreparedCallsCapabilities != null\n ? { capabilities: sendPreparedCallsCapabilities }\n : {}),\n });\n LOGGER.info(\"sendCalls:done\");\n return res;\n}\n"]}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { PrepareCallsCapabilities as PrepareCallsCapabilitiesSchema, SendPreparedCallsCapabilities as SendPreparedCallsCapabilitiesSchema } from "@alchemy/wallet-api-types/capabilities";
|
|
2
|
+
import type { StaticDecode } from "typebox";
|
|
2
3
|
import type { InnerWalletApiClient } from "../types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Decoded capabilities matching the schema shape (uses `paymasterService` key).
|
|
6
|
+
* `ResolveCapabilities` renames this to `paymaster` for client-facing types.
|
|
7
|
+
*/
|
|
8
|
+
type DecodedPrepareCallsCaps = StaticDecode<typeof PrepareCallsCapabilitiesSchema>;
|
|
9
|
+
type DecodedSendPreparedCallsCaps = StaticDecode<typeof SendPreparedCallsCapabilitiesSchema>;
|
|
3
10
|
/**
|
|
4
11
|
* Renames `paymasterService` (RPC) to `paymaster` in a capabilities type. This
|
|
5
12
|
* is because our RPC schema's paymasterService capability does not exactly match
|
|
@@ -11,8 +18,8 @@ type ResolveCapabilities<T> = T extends {
|
|
|
11
18
|
} ? Omit<T, "paymasterService"> & {
|
|
12
19
|
paymaster?: P;
|
|
13
20
|
} : T;
|
|
14
|
-
export type PrepareCallsCapabilities = ResolveCapabilities<
|
|
15
|
-
export type SendPreparedCallsCapabilities = ResolveCapabilities<
|
|
21
|
+
export type PrepareCallsCapabilities = ResolveCapabilities<DecodedPrepareCallsCaps>;
|
|
22
|
+
export type SendPreparedCallsCapabilities = ResolveCapabilities<DecodedSendPreparedCallsCaps>;
|
|
16
23
|
/**
|
|
17
24
|
* Transforms a type so that any `capabilities` field uses `paymaster`
|
|
18
25
|
* instead of `paymasterService` (RPC).
|
|
@@ -27,17 +34,17 @@ export type WithCapabilities<T> = T extends {
|
|
|
27
34
|
* for use with Value.Encode before sending to the RPC.
|
|
28
35
|
*
|
|
29
36
|
* @param {PrepareCallsCapabilities | SendPreparedCallsCapabilities | undefined} capabilities - Capabilities object containing a `paymaster` field
|
|
30
|
-
* @returns {
|
|
37
|
+
* @returns {DecodedPrepareCallsCaps | DecodedSendPreparedCallsCaps | undefined} RPC capabilities with `paymasterService`, or undefined if input is undefined
|
|
31
38
|
*/
|
|
32
|
-
export declare function toRpcCapabilities(capabilities: PrepareCallsCapabilities | SendPreparedCallsCapabilities | undefined):
|
|
39
|
+
export declare function toRpcCapabilities(capabilities: PrepareCallsCapabilities | SendPreparedCallsCapabilities | undefined): DecodedPrepareCallsCaps | DecodedSendPreparedCallsCaps | undefined;
|
|
33
40
|
/**
|
|
34
41
|
* Converts RPC capabilities (with `paymasterService`) from Value.Decode
|
|
35
42
|
* to capabilities (with `paymaster`).
|
|
36
43
|
*
|
|
37
|
-
* @param {
|
|
44
|
+
* @param {DecodedPrepareCallsCaps | DecodedSendPreparedCallsCaps | undefined} capabilities - RPC capabilities object containing a `paymasterService` field
|
|
38
45
|
* @returns {PrepareCallsCapabilities | SendPreparedCallsCapabilities | undefined} Capabilities with `paymaster`, or undefined if input is undefined
|
|
39
46
|
*/
|
|
40
|
-
export declare function fromRpcCapabilities(capabilities:
|
|
47
|
+
export declare function fromRpcCapabilities(capabilities: DecodedPrepareCallsCaps | DecodedSendPreparedCallsCaps | undefined): PrepareCallsCapabilities | SendPreparedCallsCapabilities | undefined;
|
|
41
48
|
/**
|
|
42
49
|
* Merges client capabilities with capabilities from the request.
|
|
43
50
|
* Uses policyId (singular) when there's one policy, policyIds (array) when multiple.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PrepareCallsCapabilities as PrepareCallsCapabilitiesSchema, SendPreparedCallsCapabilities as SendPreparedCallsCapabilitiesSchema, } from "@alchemy/wallet-api-types/capabilities";
|
|
1
2
|
function hasNoPaymasterField(value) {
|
|
2
3
|
return !("paymaster" in value);
|
|
3
4
|
}
|
|
@@ -9,7 +10,7 @@ function hasNoPaymasterServiceField(value) {
|
|
|
9
10
|
* for use with Value.Encode before sending to the RPC.
|
|
10
11
|
*
|
|
11
12
|
* @param {PrepareCallsCapabilities | SendPreparedCallsCapabilities | undefined} capabilities - Capabilities object containing a `paymaster` field
|
|
12
|
-
* @returns {
|
|
13
|
+
* @returns {DecodedPrepareCallsCaps | DecodedSendPreparedCallsCaps | undefined} RPC capabilities with `paymasterService`, or undefined if input is undefined
|
|
13
14
|
*/
|
|
14
15
|
export function toRpcCapabilities(capabilities) {
|
|
15
16
|
if (!capabilities)
|
|
@@ -26,7 +27,7 @@ export function toRpcCapabilities(capabilities) {
|
|
|
26
27
|
* Converts RPC capabilities (with `paymasterService`) from Value.Decode
|
|
27
28
|
* to capabilities (with `paymaster`).
|
|
28
29
|
*
|
|
29
|
-
* @param {
|
|
30
|
+
* @param {DecodedPrepareCallsCaps | DecodedSendPreparedCallsCaps | undefined} capabilities - RPC capabilities object containing a `paymasterService` field
|
|
30
31
|
* @returns {PrepareCallsCapabilities | SendPreparedCallsCapabilities | undefined} Capabilities with `paymaster`, or undefined if input is undefined
|
|
31
32
|
*/
|
|
32
33
|
export function fromRpcCapabilities(capabilities) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capabilities.js","sourceRoot":"","sources":["../../../src/utils/capabilities.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"capabilities.js","sourceRoot":"","sources":["../../../src/utils/capabilities.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,IAAI,8BAA8B,EAC1D,6BAA6B,IAAI,mCAAmC,GACrE,MAAM,wCAAwC,CAAC;AA6ChD,SAAS,mBAAmB,CAC1B,KAAa;IAEb,OAAO,CAAC,CAAC,WAAW,IAAI,KAAK,CAAC,CAAC;AACjC,CAAC;AAED,SAAS,0BAA0B,CACjC,KAAa;IAEb,OAAO,CAAC,CAAC,kBAAkB,IAAI,KAAK,CAAC,CAAC;AACxC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAC/B,YAGa;IAEb,IAAI,CAAC,YAAY;QAAE,OAAO,SAAS,CAAC;IACpC,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,EAAE,GAAG,YAAY,CAAC;IAC5C,MAAM,MAAM,GACV,SAAS,KAAK,SAAS;QACrB,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,gBAAgB,EAAE,SAAS,EAAE;QAC1C,CAAC,CAAC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CAC3C,YAAkD,EACP,EAAE;IAC7C,IAAI,YAAY,EAAE,WAAW,IAAI,IAAI,IAAI,YAAY,EAAE,SAAS,IAAI,IAAI,EAAE,CAAC;QACzE,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,SAAS,GAAG,YAAY,CAAC,SAAS,CAAC;IAEzC,OAAO;QACL,WAAW,EAAE,YAAY,CAAC,WAAW;QACrC,SAAS,EACP,SAAS,IAAI,IAAI;YACf,CAAC,CAAC;gBACE,GAAG,CAAC,UAAU,IAAI,SAAS;oBACzB,CAAC,CAAC,EAAE,QAAQ,EAAE,SAAS,CAAC,QAAQ,EAAE;oBAClC,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,SAAS,EAAE,CAAC;gBACvC,WAAW,EAAE,SAAS,CAAC,WAAW;aACnC;YACH,CAAC,CAAC,SAAS;KAChB,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {\n PrepareCallsCapabilities as PrepareCallsCapabilitiesSchema,\n SendPreparedCallsCapabilities as SendPreparedCallsCapabilitiesSchema,\n} from \"@alchemy/wallet-api-types/capabilities\";\nimport type { StaticDecode } from \"typebox\";\nimport type { InnerWalletApiClient } from \"../types.js\";\n\n/**\n * Decoded capabilities matching the schema shape (uses `paymasterService` key).\n * `ResolveCapabilities` renames this to `paymaster` for client-facing types.\n */\ntype DecodedPrepareCallsCaps = StaticDecode<\n typeof PrepareCallsCapabilitiesSchema\n>;\ntype DecodedSendPreparedCallsCaps = StaticDecode<\n typeof SendPreparedCallsCapabilitiesSchema\n>;\n\n/**\n * Renames `paymasterService` (RPC) to `paymaster` in a capabilities type. This\n * is because our RPC schema's paymasterService capability does not exactly match\n * the shape of the new spec, so we want to use a different name in our client\n * types to avoid confusion and be compatible with Viem's types.\n */\ntype ResolveCapabilities<T> = T extends {\n paymasterService?: infer P;\n}\n ? Omit<T, \"paymasterService\"> & { paymaster?: P }\n : T;\n\nexport type PrepareCallsCapabilities =\n ResolveCapabilities<DecodedPrepareCallsCaps>;\n\nexport type SendPreparedCallsCapabilities =\n ResolveCapabilities<DecodedSendPreparedCallsCaps>;\n\n/**\n * Transforms a type so that any `capabilities` field uses `paymaster`\n * instead of `paymasterService` (RPC).\n */\nexport type WithCapabilities<T> = T extends {\n capabilities?: infer C;\n}\n ? Omit<T, \"capabilities\"> & {\n capabilities?: ResolveCapabilities<NonNullable<C>>;\n }\n : T;\n\nfunction hasNoPaymasterField(\n value: object,\n): value is DecodedPrepareCallsCaps | DecodedSendPreparedCallsCaps {\n return !(\"paymaster\" in value);\n}\n\nfunction hasNoPaymasterServiceField(\n value: object,\n): value is PrepareCallsCapabilities | SendPreparedCallsCapabilities {\n return !(\"paymasterService\" in value);\n}\n\n/**\n * Converts capabilities (with `paymaster`) to RPC capabilities (with `paymasterService`)\n * for use with Value.Encode before sending to the RPC.\n *\n * @param {PrepareCallsCapabilities | SendPreparedCallsCapabilities | undefined} capabilities - Capabilities object containing a `paymaster` field\n * @returns {DecodedPrepareCallsCaps | DecodedSendPreparedCallsCaps | undefined} RPC capabilities with `paymasterService`, or undefined if input is undefined\n */\nexport function toRpcCapabilities(\n capabilities:\n | PrepareCallsCapabilities\n | SendPreparedCallsCapabilities\n | undefined,\n): DecodedPrepareCallsCaps | DecodedSendPreparedCallsCaps | undefined {\n if (!capabilities) return undefined;\n const { paymaster, ...rest } = capabilities;\n const result =\n paymaster !== undefined\n ? { ...rest, paymasterService: paymaster }\n : { ...rest };\n if (hasNoPaymasterField(result)) return result;\n return undefined;\n}\n\n/**\n * Converts RPC capabilities (with `paymasterService`) from Value.Decode\n * to capabilities (with `paymaster`).\n *\n * @param {DecodedPrepareCallsCaps | DecodedSendPreparedCallsCaps | undefined} capabilities - RPC capabilities object containing a `paymasterService` field\n * @returns {PrepareCallsCapabilities | SendPreparedCallsCapabilities | undefined} Capabilities with `paymaster`, or undefined if input is undefined\n */\nexport function fromRpcCapabilities(\n capabilities:\n | DecodedPrepareCallsCaps\n | DecodedSendPreparedCallsCaps\n | undefined,\n): PrepareCallsCapabilities | SendPreparedCallsCapabilities | undefined {\n if (!capabilities) return undefined;\n if (\"paymasterService\" in capabilities) {\n const { paymasterService, ...rest } = capabilities;\n const result =\n paymasterService !== undefined\n ? { ...rest, paymaster: paymasterService }\n : { ...rest };\n if (hasNoPaymasterServiceField(result)) return result;\n return undefined;\n }\n if (hasNoPaymasterServiceField(capabilities)) return capabilities;\n return undefined;\n}\n\n/**\n * Merges client capabilities with capabilities from the request.\n * Uses policyId (singular) when there's one policy, policyIds (array) when multiple.\n *\n * @param {InnerWalletApiClient} client - The inner wallet API client (potentially including global capabilities like policy IDs)\n * @param {T | undefined} capabilities - Request capabilities to merge with, if any\n * @returns {T | undefined} The merged capabilities object, or original capabilities if no capability configuration exists on the client\n */\nexport const mergeClientCapabilities = <\n T extends PrepareCallsCapabilities | SendPreparedCallsCapabilities,\n>(\n client: InnerWalletApiClient,\n capabilities: T | undefined,\n): T | undefined => {\n if (!client.policyIds?.length || capabilities?.paymaster) {\n return capabilities;\n }\n\n return {\n ...capabilities,\n paymaster:\n client.policyIds.length === 1\n ? { policyId: client.policyIds[0] }\n : { policyIds: client.policyIds },\n } as T;\n};\n\n/**\n * Extracts capabilities from prepareCalls that are usable for sendPreparedCalls.\n * Only permissions and paymaster (policyId/policyIds & webhookData) are supported.\n *\n * @param {PrepareCallsCapabilities | undefined} capabilities - The prepareCalls capabilities\n * @returns {SendPreparedCallsCapabilities | undefined} The sendPreparedCalls capabilities, or undefined if no relevant capabilities exist\n */\nexport const extractCapabilitiesForSending = (\n capabilities: PrepareCallsCapabilities | undefined,\n): SendPreparedCallsCapabilities | undefined => {\n if (capabilities?.permissions == null && capabilities?.paymaster == null) {\n return undefined;\n }\n\n const paymaster = capabilities.paymaster;\n\n return {\n permissions: capabilities.permissions,\n paymaster:\n paymaster != null\n ? {\n ...(\"policyId\" in paymaster\n ? { policyId: paymaster.policyId }\n : { policyIds: paymaster.policyIds }),\n webhookData: paymaster.webhookData,\n }\n : undefined,\n };\n};\n"]}
|
package/dist/esm/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.0.0-alpha.
|
|
1
|
+
export declare const VERSION = "0.0.0-alpha.19";
|
package/dist/esm/version.js
CHANGED
package/dist/esm/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,yBAAyB;AACzB,MAAM,CAAC,MAAM,OAAO,GAAG,gBAAgB,CAAC","sourcesContent":["// This file is autogenerated by inject-version.ts. Any changes will be\n// overwritten on commit!\nexport const VERSION = \"0.0.0-alpha.
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,yBAAyB;AACzB,MAAM,CAAC,MAAM,OAAO,GAAG,gBAAgB,CAAC","sourcesContent":["// This file is autogenerated by inject-version.ts. Any changes will be\n// overwritten on commit!\nexport const VERSION = \"0.0.0-alpha.19\";\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_prepareCalls as MethodSchema } from "@alchemy/wallet-api-types/rpc";
|
|
6
6
|
import { type MethodParams, type MethodResponse } from "../utils/schema.js";
|
|
@@ -10,7 +10,18 @@ export type PrepareCallsParams = Prettify<WithCapabilities<DistributiveOmit<Base
|
|
|
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<BasePrepareCallsParams, "from" | "capabilities"> & {
|
|
15
|
+
account: Address;
|
|
16
|
+
capabilities?: PrepareCallsCapabilities;
|
|
17
|
+
}>;
|
|
18
|
+
export type PrepareCallsResult = Exclude<PrepareCallsResponse, {
|
|
19
|
+
type: "paymaster-permit";
|
|
20
|
+
}> | (Omit<Extract<PrepareCallsResponse, {
|
|
21
|
+
type: "paymaster-permit";
|
|
22
|
+
}>, "modifiedRequest"> & {
|
|
23
|
+
modifiedRequest: ClientModifiedRequest;
|
|
24
|
+
});
|
|
14
25
|
/**
|
|
15
26
|
* Prepares a set of contract calls for execution by building a user operation.
|
|
16
27
|
* Returns the built user operation and a signature request that needs to be signed
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepareCalls.d.ts","sourceRoot":"","sources":["../../../src/actions/prepareCalls.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"prepareCalls.d.ts","sourceRoot":"","sources":["../../../src/actions/prepareCalls.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC9C,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE1E,OAAO,EAIL,KAAK,wBAAwB,EAC7B,KAAK,gBAAgB,EACtB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,mBAAmB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAEpF,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,cAAc,EACpB,MAAM,oBAAoB,CAAC;AAG5B,KAAK,sBAAsB,GAAG,YAAY,CAAC,OAAO,YAAY,CAAC,CAAC;A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OAAO,EAEL,KAAK,uBAAuB,EAC7B,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"sendCalls.d.ts","sourceRoot":"","sources":["../../../src/actions/sendCalls.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAgB,KAAK,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAE1E,OAAO,EAEL,KAAK,uBAAuB,EAC7B,MAAM,wBAAwB,CAAC;AAKhC,MAAM,MAAM,eAAe,GAAG,QAAQ,CACpC,gBAAgB,CAAC,kBAAkB,EAAE,SAAS,CAAC,GAAG;IAChD,KAAK,CAAC,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;CAC3B,CACF,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC,uBAAuB,CAAC,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAsB,SAAS,CAC7B,MAAM,EAAE,oBAAoB,EAC5B,MAAM,EAAE,eAAe,GACtB,OAAO,CAAC,eAAe,CAAC,CA2C1B"}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { PrepareCallsCapabilities as PrepareCallsCapabilitiesSchema, SendPreparedCallsCapabilities as SendPreparedCallsCapabilitiesSchema } from "@alchemy/wallet-api-types/capabilities";
|
|
2
|
+
import type { StaticDecode } from "typebox";
|
|
2
3
|
import type { InnerWalletApiClient } from "../types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Decoded capabilities matching the schema shape (uses `paymasterService` key).
|
|
6
|
+
* `ResolveCapabilities` renames this to `paymaster` for client-facing types.
|
|
7
|
+
*/
|
|
8
|
+
type DecodedPrepareCallsCaps = StaticDecode<typeof PrepareCallsCapabilitiesSchema>;
|
|
9
|
+
type DecodedSendPreparedCallsCaps = StaticDecode<typeof SendPreparedCallsCapabilitiesSchema>;
|
|
3
10
|
/**
|
|
4
11
|
* Renames `paymasterService` (RPC) to `paymaster` in a capabilities type. This
|
|
5
12
|
* is because our RPC schema's paymasterService capability does not exactly match
|
|
@@ -11,8 +18,8 @@ type ResolveCapabilities<T> = T extends {
|
|
|
11
18
|
} ? Omit<T, "paymasterService"> & {
|
|
12
19
|
paymaster?: P;
|
|
13
20
|
} : T;
|
|
14
|
-
export type PrepareCallsCapabilities = ResolveCapabilities<
|
|
15
|
-
export type SendPreparedCallsCapabilities = ResolveCapabilities<
|
|
21
|
+
export type PrepareCallsCapabilities = ResolveCapabilities<DecodedPrepareCallsCaps>;
|
|
22
|
+
export type SendPreparedCallsCapabilities = ResolveCapabilities<DecodedSendPreparedCallsCaps>;
|
|
16
23
|
/**
|
|
17
24
|
* Transforms a type so that any `capabilities` field uses `paymaster`
|
|
18
25
|
* instead of `paymasterService` (RPC).
|
|
@@ -27,17 +34,17 @@ export type WithCapabilities<T> = T extends {
|
|
|
27
34
|
* for use with Value.Encode before sending to the RPC.
|
|
28
35
|
*
|
|
29
36
|
* @param {PrepareCallsCapabilities | SendPreparedCallsCapabilities | undefined} capabilities - Capabilities object containing a `paymaster` field
|
|
30
|
-
* @returns {
|
|
37
|
+
* @returns {DecodedPrepareCallsCaps | DecodedSendPreparedCallsCaps | undefined} RPC capabilities with `paymasterService`, or undefined if input is undefined
|
|
31
38
|
*/
|
|
32
|
-
export declare function toRpcCapabilities(capabilities: PrepareCallsCapabilities | SendPreparedCallsCapabilities | undefined):
|
|
39
|
+
export declare function toRpcCapabilities(capabilities: PrepareCallsCapabilities | SendPreparedCallsCapabilities | undefined): DecodedPrepareCallsCaps | DecodedSendPreparedCallsCaps | undefined;
|
|
33
40
|
/**
|
|
34
41
|
* Converts RPC capabilities (with `paymasterService`) from Value.Decode
|
|
35
42
|
* to capabilities (with `paymaster`).
|
|
36
43
|
*
|
|
37
|
-
* @param {
|
|
44
|
+
* @param {DecodedPrepareCallsCaps | DecodedSendPreparedCallsCaps | undefined} capabilities - RPC capabilities object containing a `paymasterService` field
|
|
38
45
|
* @returns {PrepareCallsCapabilities | SendPreparedCallsCapabilities | undefined} Capabilities with `paymaster`, or undefined if input is undefined
|
|
39
46
|
*/
|
|
40
|
-
export declare function fromRpcCapabilities(capabilities:
|
|
47
|
+
export declare function fromRpcCapabilities(capabilities: DecodedPrepareCallsCaps | DecodedSendPreparedCallsCaps | undefined): PrepareCallsCapabilities | SendPreparedCallsCapabilities | undefined;
|
|
41
48
|
/**
|
|
42
49
|
* Merges client capabilities with capabilities from the request.
|
|
43
50
|
* Uses policyId (singular) when there's one policy, policyIds (array) when multiple.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../../../src/utils/capabilities.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../../../src/utils/capabilities.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,IAAI,8BAA8B,EAC1D,6BAA6B,IAAI,mCAAmC,EACrE,MAAM,wCAAwC,CAAC;AAChD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAExD;;;GAGG;AACH,KAAK,uBAAuB,GAAG,YAAY,CACzC,OAAO,8BAA8B,CACtC,CAAC;AACF,KAAK,4BAA4B,GAAG,YAAY,CAC9C,OAAO,mCAAmC,CAC3C,CAAC;AAEF;;;;;GAKG;AACH,KAAK,mBAAmB,CAAC,CAAC,IAAI,CAAC,SAAS;IACtC,gBAAgB,CAAC,EAAE,MAAM,CAAC,CAAC;CAC5B,GACG,IAAI,CAAC,CAAC,EAAE,kBAAkB,CAAC,GAAG;IAAE,SAAS,CAAC,EAAE,CAAC,CAAA;CAAE,GAC/C,CAAC,CAAC;AAEN,MAAM,MAAM,wBAAwB,GAClC,mBAAmB,CAAC,uBAAuB,CAAC,CAAC;AAE/C,MAAM,MAAM,6BAA6B,GACvC,mBAAmB,CAAC,4BAA4B,CAAC,CAAC;AAEpD;;;GAGG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI,CAAC,SAAS;IAC1C,YAAY,CAAC,EAAE,MAAM,CAAC,CAAC;CACxB,GACG,IAAI,CAAC,CAAC,EAAE,cAAc,CAAC,GAAG;IACxB,YAAY,CAAC,EAAE,mBAAmB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;CACpD,GACD,CAAC,CAAC;AAcN;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,YAAY,EACR,wBAAwB,GACxB,6BAA6B,GAC7B,SAAS,GACZ,uBAAuB,GAAG,4BAA4B,GAAG,SAAS,CASpE;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,YAAY,EACR,uBAAuB,GACvB,4BAA4B,GAC5B,SAAS,GACZ,wBAAwB,GAAG,6BAA6B,GAAG,SAAS,CAatE;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,uBAAuB,GAClC,CAAC,SAAS,wBAAwB,GAAG,6BAA6B,EAElE,QAAQ,oBAAoB,EAC5B,cAAc,CAAC,GAAG,SAAS,KAC1B,CAAC,GAAG,SAYN,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,6BAA6B,GACxC,cAAc,wBAAwB,GAAG,SAAS,KACjD,6BAA6B,GAAG,SAmBlC,CAAC"}
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.0.0-alpha.
|
|
1
|
+
export declare const VERSION = "0.0.0-alpha.19";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alchemy/wallet-apis",
|
|
3
|
-
"version": "0.0.0-alpha.
|
|
3
|
+
"version": "0.0.0-alpha.20",
|
|
4
4
|
"description": "Alchemy Wallet APIs",
|
|
5
5
|
"author": "Alchemy",
|
|
6
6
|
"license": "MIT",
|
|
@@ -53,8 +53,8 @@
|
|
|
53
53
|
"typescript-template": "*"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@alchemy/common": "^0.0.0-alpha.
|
|
57
|
-
"@alchemy/wallet-api-types": "0.1.0-alpha.
|
|
56
|
+
"@alchemy/common": "^0.0.0-alpha.20",
|
|
57
|
+
"@alchemy/wallet-api-types": "0.1.0-alpha.25",
|
|
58
58
|
"deep-equal": "^2.2.3",
|
|
59
59
|
"ox": "^0.11.1",
|
|
60
60
|
"typebox": "^1.0.81",
|
|
@@ -72,5 +72,5 @@
|
|
|
72
72
|
"url": "https://github.com/alchemyplatform/aa-sdk/issues"
|
|
73
73
|
},
|
|
74
74
|
"homepage": "https://github.com/alchemyplatform/aa-sdk#readme",
|
|
75
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "b759d878f074f4d657d62d2a8e2ef4a5631ab209"
|
|
76
76
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import type { Prettify } from "viem";
|
|
1
|
+
import type { Address, Prettify } from "viem";
|
|
2
2
|
import type { DistributiveOmit, InnerWalletApiClient } from "../types.ts";
|
|
3
3
|
import { LOGGER } from "../logger.js";
|
|
4
4
|
import {
|
|
5
|
+
fromRpcCapabilities,
|
|
5
6
|
mergeClientCapabilities,
|
|
6
7
|
toRpcCapabilities,
|
|
8
|
+
type PrepareCallsCapabilities,
|
|
7
9
|
type WithCapabilities,
|
|
8
10
|
} from "../utils/capabilities.js";
|
|
9
11
|
import { resolveAddress, type AccountParam } from "../utils/resolve.js";
|
|
@@ -28,7 +30,22 @@ export type PrepareCallsParams = Prettify<
|
|
|
28
30
|
>
|
|
29
31
|
>;
|
|
30
32
|
|
|
31
|
-
|
|
33
|
+
/** The modifiedRequest in client format: `account` instead of `from`, SDK capabilities. */
|
|
34
|
+
type ClientModifiedRequest = Prettify<
|
|
35
|
+
Omit<BasePrepareCallsParams, "from" | "capabilities"> & {
|
|
36
|
+
account: Address;
|
|
37
|
+
capabilities?: PrepareCallsCapabilities;
|
|
38
|
+
}
|
|
39
|
+
>;
|
|
40
|
+
|
|
41
|
+
export type PrepareCallsResult =
|
|
42
|
+
| Exclude<PrepareCallsResponse, { type: "paymaster-permit" }>
|
|
43
|
+
| (Omit<
|
|
44
|
+
Extract<PrepareCallsResponse, { type: "paymaster-permit" }>,
|
|
45
|
+
"modifiedRequest"
|
|
46
|
+
> & {
|
|
47
|
+
modifiedRequest: ClientModifiedRequest;
|
|
48
|
+
});
|
|
32
49
|
|
|
33
50
|
/**
|
|
34
51
|
* Prepares a set of contract calls for execution by building a user operation.
|
|
@@ -92,5 +109,23 @@ export async function prepareCalls(
|
|
|
92
109
|
});
|
|
93
110
|
|
|
94
111
|
LOGGER.debug("prepareCalls:done");
|
|
95
|
-
|
|
112
|
+
const decoded = Value.Decode(schema.response, rpcResp);
|
|
113
|
+
|
|
114
|
+
// Transform paymaster-permit modifiedRequest from RPC format to client format:
|
|
115
|
+
// - `from` (RPC) → `account` (client)
|
|
116
|
+
// - `capabilities.paymasterService` (RPC) → `capabilities.paymaster` (client)
|
|
117
|
+
if (decoded.type === "paymaster-permit") {
|
|
118
|
+
const { from, capabilities, ...restModifiedRequest } =
|
|
119
|
+
decoded.modifiedRequest;
|
|
120
|
+
return {
|
|
121
|
+
...decoded,
|
|
122
|
+
modifiedRequest: {
|
|
123
|
+
...restModifiedRequest,
|
|
124
|
+
account: from,
|
|
125
|
+
capabilities: fromRpcCapabilities(capabilities),
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return decoded;
|
|
96
131
|
}
|
package/src/actions/sendCalls.ts
CHANGED
|
@@ -8,10 +8,7 @@ import {
|
|
|
8
8
|
} from "./sendPreparedCalls.js";
|
|
9
9
|
import { LOGGER } from "../logger.js";
|
|
10
10
|
import { signSignatureRequest } from "./signSignatureRequest.js";
|
|
11
|
-
import {
|
|
12
|
-
extractCapabilitiesForSending,
|
|
13
|
-
fromRpcCapabilities,
|
|
14
|
-
} from "../utils/capabilities.js";
|
|
11
|
+
import { extractCapabilitiesForSending } from "../utils/capabilities.js";
|
|
15
12
|
|
|
16
13
|
export type SendCallsParams = Prettify<
|
|
17
14
|
DistributiveOmit<PrepareCallsParams, "chainId"> & {
|
|
@@ -77,10 +74,7 @@ export async function sendCalls(
|
|
|
77
74
|
);
|
|
78
75
|
|
|
79
76
|
const secondCallParams = {
|
|
80
|
-
|
|
81
|
-
calls: calls.modifiedRequest.calls,
|
|
82
|
-
chainId: calls.modifiedRequest.chainId,
|
|
83
|
-
capabilities: fromRpcCapabilities(calls.modifiedRequest.capabilities),
|
|
77
|
+
...calls.modifiedRequest,
|
|
84
78
|
// WebAuthn signatures are not supported for paymaster permits (throws above).
|
|
85
79
|
paymasterPermitSignature: signature as Exclude<
|
|
86
80
|
typeof signature,
|
|
@@ -1,9 +1,21 @@
|
|
|
1
|
-
import
|
|
2
|
-
PrepareCallsCapabilities as
|
|
3
|
-
SendPreparedCallsCapabilities as
|
|
1
|
+
import {
|
|
2
|
+
PrepareCallsCapabilities as PrepareCallsCapabilitiesSchema,
|
|
3
|
+
SendPreparedCallsCapabilities as SendPreparedCallsCapabilitiesSchema,
|
|
4
4
|
} from "@alchemy/wallet-api-types/capabilities";
|
|
5
|
+
import type { StaticDecode } from "typebox";
|
|
5
6
|
import type { InnerWalletApiClient } from "../types.js";
|
|
6
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Decoded capabilities matching the schema shape (uses `paymasterService` key).
|
|
10
|
+
* `ResolveCapabilities` renames this to `paymaster` for client-facing types.
|
|
11
|
+
*/
|
|
12
|
+
type DecodedPrepareCallsCaps = StaticDecode<
|
|
13
|
+
typeof PrepareCallsCapabilitiesSchema
|
|
14
|
+
>;
|
|
15
|
+
type DecodedSendPreparedCallsCaps = StaticDecode<
|
|
16
|
+
typeof SendPreparedCallsCapabilitiesSchema
|
|
17
|
+
>;
|
|
18
|
+
|
|
7
19
|
/**
|
|
8
20
|
* Renames `paymasterService` (RPC) to `paymaster` in a capabilities type. This
|
|
9
21
|
* is because our RPC schema's paymasterService capability does not exactly match
|
|
@@ -17,10 +29,10 @@ type ResolveCapabilities<T> = T extends {
|
|
|
17
29
|
: T;
|
|
18
30
|
|
|
19
31
|
export type PrepareCallsCapabilities =
|
|
20
|
-
ResolveCapabilities<
|
|
32
|
+
ResolveCapabilities<DecodedPrepareCallsCaps>;
|
|
21
33
|
|
|
22
34
|
export type SendPreparedCallsCapabilities =
|
|
23
|
-
ResolveCapabilities<
|
|
35
|
+
ResolveCapabilities<DecodedSendPreparedCallsCaps>;
|
|
24
36
|
|
|
25
37
|
/**
|
|
26
38
|
* Transforms a type so that any `capabilities` field uses `paymaster`
|
|
@@ -36,7 +48,7 @@ export type WithCapabilities<T> = T extends {
|
|
|
36
48
|
|
|
37
49
|
function hasNoPaymasterField(
|
|
38
50
|
value: object,
|
|
39
|
-
): value is
|
|
51
|
+
): value is DecodedPrepareCallsCaps | DecodedSendPreparedCallsCaps {
|
|
40
52
|
return !("paymaster" in value);
|
|
41
53
|
}
|
|
42
54
|
|
|
@@ -51,14 +63,14 @@ function hasNoPaymasterServiceField(
|
|
|
51
63
|
* for use with Value.Encode before sending to the RPC.
|
|
52
64
|
*
|
|
53
65
|
* @param {PrepareCallsCapabilities | SendPreparedCallsCapabilities | undefined} capabilities - Capabilities object containing a `paymaster` field
|
|
54
|
-
* @returns {
|
|
66
|
+
* @returns {DecodedPrepareCallsCaps | DecodedSendPreparedCallsCaps | undefined} RPC capabilities with `paymasterService`, or undefined if input is undefined
|
|
55
67
|
*/
|
|
56
68
|
export function toRpcCapabilities(
|
|
57
69
|
capabilities:
|
|
58
70
|
| PrepareCallsCapabilities
|
|
59
71
|
| SendPreparedCallsCapabilities
|
|
60
72
|
| undefined,
|
|
61
|
-
):
|
|
73
|
+
): DecodedPrepareCallsCaps | DecodedSendPreparedCallsCaps | undefined {
|
|
62
74
|
if (!capabilities) return undefined;
|
|
63
75
|
const { paymaster, ...rest } = capabilities;
|
|
64
76
|
const result =
|
|
@@ -73,13 +85,13 @@ export function toRpcCapabilities(
|
|
|
73
85
|
* Converts RPC capabilities (with `paymasterService`) from Value.Decode
|
|
74
86
|
* to capabilities (with `paymaster`).
|
|
75
87
|
*
|
|
76
|
-
* @param {
|
|
88
|
+
* @param {DecodedPrepareCallsCaps | DecodedSendPreparedCallsCaps | undefined} capabilities - RPC capabilities object containing a `paymasterService` field
|
|
77
89
|
* @returns {PrepareCallsCapabilities | SendPreparedCallsCapabilities | undefined} Capabilities with `paymaster`, or undefined if input is undefined
|
|
78
90
|
*/
|
|
79
91
|
export function fromRpcCapabilities(
|
|
80
92
|
capabilities:
|
|
81
|
-
|
|
|
82
|
-
|
|
|
93
|
+
| DecodedPrepareCallsCaps
|
|
94
|
+
| DecodedSendPreparedCallsCaps
|
|
83
95
|
| undefined,
|
|
84
96
|
): PrepareCallsCapabilities | SendPreparedCallsCapabilities | undefined {
|
|
85
97
|
if (!capabilities) return undefined;
|
package/src/version.ts
CHANGED